<?php
// ------------------------------------------------------------------------- //
//                XOOPS - PHP Content Management System                      //
//                       <http://www.xoops.org/>                             //
// ------------------------------------------------------------------------- //
// Based on:								     //
// myPHPNUKE Web Portal System - http://myphpnuke.com/	  		     //
// PHP-NUKE Web Portal System - http://phpnuke.org/	  		     //
// Thatware - http://thatware.org/					     //
// ------------------------------------------------------------------------- //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
// ------------------------------------------------------------------------- //

if (isset($HTTP_POST_VARS['fct'])) { 
	$fct = $HTTP_POST_VARS['fct'];
}
if (isset($HTTP_GET_VARS['fct'])) { 
	$fct = $HTTP_GET_VARS['fct'];
}
if ( isset($fct) && $fct == "users" ) {
	$xoopsOption['pagetype'] = "user";
}
include("../../mainfile.php");
include(XOOPS_ROOT_PATH."/include/cp_functions.php");
if ( file_exists(XOOPS_ROOT_PATH."/modules/system/language/".$xoopsConfig['language']."/admin.php") ) {
	include(XOOPS_ROOT_PATH."/modules/system/language/".$xoopsConfig['language']."/admin.php");
} else {
	include(XOOPS_ROOT_PATH."/modules/system/language/english/admin.php");
}
include_once(XOOPS_ROOT_PATH."/class/xoopsmodule.php");
/*********************************************************/
/* Admin Authentication                                  */
/*********************************************************/

$admintest = 0;

if ( $xoopsUser ) {
	$xoopsModule = XoopsModule::getByDirname("system");
	if ( !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
		redirect_header(XOOPS_URL."/",3,_NOPERM);
		exit();
	}
	$admintest=1;
} else {
	redirect_header(XOOPS_URL."/",3,_NOPERM);
	exit();
}

if ( $admintest == 1 ) {
	if ( $fct != "" ) { 
		if ( file_exists(XOOPS_ROOT_PATH."/modules/system/admin/".$fct."/main.php") ) {
			if ( file_exists(XOOPS_ROOT_PATH."/modules/system/language/".$xoopsConfig['language']."/admin/".$fct.".php") ) {
				include(XOOPS_ROOT_PATH."/modules/system/language/".$xoopsConfig['language']."/admin/".$fct.".php");
			} elseif ( file_exists(XOOPS_ROOT_PATH."/modules/system/language/english/admin/".$fct.".php") ) {
				include(XOOPS_ROOT_PATH."/modules/system/language/english/admin/".$fct.".php");
			}
			include(XOOPS_ROOT_PATH."/modules/system/admin/".$fct."/main.php");
		} else {
			xoops_cp_header();
			system_menu();
    			xoops_cp_footer();
		}
	} else {
		xoops_cp_header();
		system_menu();
    		xoops_cp_footer();
	}
} 

/*********************************************************/
/* Core Menu Functions                                   */
/*********************************************************/

function system_menu_item($folder, $modversion) {
	global $xoopsConfig;

	//if ( $xoopsConfig['admingraphic'] ) {
	//	echo "<a href='".XOOPS_URL."/modules/system/admin.php?fct=".$folder."'><img src='".XOOPS_URL."/modules/system/admin/".$folder."/".$modversion['image']."' alt='".$modversion['name']."' border='0' /><br /><b>" .trim($modversion['name'])."</b></a>\n";
	//} else {
		echo "<a href='".XOOPS_URL."/modules/system/admin.php?fct=".$folder."'><b>" .trim($modversion['name'])."</b></a>\n";
	//}
}

function system_menu() {
	global $xoopsConfig, $xoopsUser, $xoopsModule;
	OpenTable();
	echo "<table border='0' cellpadding='1' align='center'>";
	echo "<tr>";
	$i = 0;
	$admin_dir = XOOPS_ROOT_PATH."/modules/system/admin";
	$handle=opendir($admin_dir);
	$counter = 0;
	while ($file = readdir($handle)) {
		if ( !ereg('[.]',$file) ) {
			include($admin_dir."/".$file."/xoops_version.php");
			if ( $modversion['hasAdmin'] ) {
				echo "<td align='center' valign='bottom' width='19%'>";
				system_menu_item($file, $modversion);
				echo "</td>";
				$counter++;
			}
			if ( $counter > 4 ) {
				$counter = 0;
				echo "</tr>";
				echo "<tr>";
			}
		}
		unset($modversion);
	}
		
	echo "</tr>";
	echo "</table>";
	CloseTable();
}
?>