<?php
// $Id: admin.php,v 1.1 2004/07/11 10:28:49 Farsus Exp $
// -------------------------------------------------------------------------//
//			       RUNCMS                                                   //
//                                                                          //
//	 reliable - Unique - Nocost &  Simplicity & ease off use                //
//                       < http://www.runcms.org >                          //
// -------------------------------------------------------------------------//
// Original Author: Kazumi Ono
// Author Website : http://www.mywebaddons.com/ , http://www.myweb.ne.jp
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //

$fct = !empty($HTTP_POST_VARS['fct']) ? $HTTP_POST_VARS['fct'] : $HTTP_GET_VARS['fct'];

if ($fct == "users") {
	$xoopsOption['pagetype'] = "user";
}

include_once("../../mainfile.php");
include_once(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");
	}

/*********************************************************/
/* 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 ( !empty($fct) ) {
		if ( @file_exists(XOOPS_ROOT_PATH."/modules/system/admin/".$fct."/main.php") ) {
			if ( @file_exists(XOOPS_ROOT_PATH."/modules/system/admin/".$fct."/language/".$xoopsConfig['language']."/".$fct.".php") ) {
				include(XOOPS_ROOT_PATH."/modules/system/admin/".$fct."/language/".$xoopsConfig['language']."/".$fct.".php");
			} elseif ( @file_exists(XOOPS_ROOT_PATH."/modules/system/admin/".$fct."/language/english/".$fct.".php") ) {
				include(XOOPS_ROOT_PATH."/modules/system/admin/".$fct."/language/english/".$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                                   */
/*********************************************************/

//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function system_menu_item($folder, $modversion) {
global $xoopsConfig;

echo "<a href='".XOOPS_URL."/modules/system/admin.php?fct=".$folder."'><b>".trim($modversion['name'])."</b></a>";
}

//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function system_menu() {
global $xoopsConfig, $xoopsUser, $xoopsModule;

OpenTable();
echo "<table border='0' cellpadding='1' align='center'><tr>";

$admin_dir = XOOPS_ROOT_PATH."/modules/system/admin";
$handle    = @opendir($admin_dir);
$counter   = 0;

while (false !== ($file = readdir($handle))) {
	if ( $file != '.' && $file != '..' && @file_exists($admin_dir."/".$file."/xoops_version.php") ) {
		include_once($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><tr>";
		}
	}

unset($modversion);
}

echo "</tr></table>";
CloseTable();
}
?>
