<?php

	/*
	*	Gekko - Open Source Web Development Framework
	*	------------------------------------------------------------------------
	*	Copyright (C) 2004-2005, J. Carlos Nieto <xiam@users.sourceforge.net>
	*	This program is Free Software.
	*
	*	@package	Gekko
	*	@license	http://www.gnu.org/copyleft/gpl.html GNU/GPL License 2.0
	*	@author		J. Carlos Nieto <xiam@users.sf.net>
	*	@version	CVS: $Id:$
	*	@link		http://gekkoware.sourceforge.net
	*/

	if (!defined("IN-GEKKO")) die("Get a life!");

	if (gauth("#")) {

		# /admin/module
		$module = _ext("module", 1);

		if ($module) {
			if ($mc->check($module, false)) {

				$db->query("SELECT auth_Manage FROM ".db_table("module")." WHERE
				MODULE = '$module'", __FILE__, __LINE__);
				$row = $db->fetch_row();

				$is_admin = gauth($row["auth_Manage"]);

				$modinc = GEKKO_ROOT."modules/$module/admin.inc.php";
				if (file_exists($modinc)) {
					$Lang->Load($module);

					title_attach(_l("M_".strtoupper($module).""));

					if (!$is_admin) $mc->save("<div class=\"info\">"._l("L_READ_ONLY_ACCESS")."</div>\n");
					include $modinc;
				} else {
					$mcBuff = _l("E_NOT_AN_ADMIN_MODULE");
				}

			}
		} else {
			title_attach(_l("L_ADMIN_PANEL"));

			$adm_mod = Array();
			$db->query("SELECT Module FROM ".db_table("module")."
			WHERE Hidden = '0'", __FILE__, __LINE__);
			while ($row = $db->fetch_row()) {
				$adm_mod[$row["Module"]] = true;
			}

			$Panel = new Panel(_l("L_ADMIN_PANEL"), "admin.png");

			$moddir = opendir(GEKKO_ROOT."modules");

			while (($module = readdir($moddir)) !== false) {

				if ($module != "." && $module != "..") {

					$modpath = GEKKO_ROOT."modules/$module";
					/*
						Checking for admin.inc.php file, this means that module has
						administration functions.
					*/
					if (file_exists($modpath."/admin.inc.php") && isset($adm_mod[$module])) {
						/*
							Now, checking for admin.panel.php, if exists includes it,
							if not, we create a default icon.
							If you dont want an Icon showed in this panel, you
							can just make an empty admin.panel.php file
						*/
						if (file_exists($modpath."/admin.panel.php")) {
							include $modpath."/admin.panel.php";
						} else {
							$Panel->AddIcon(
								$Panel->Icon("$module.png", "index.php/admin/$module", _l("M_".strtoupper($module))),
								_l("L_ADMINISTRATION_TASKS")
							);

						}
					}
				}
			}
			closedir($moddir);

			$mcBuff .= $Panel->make();
		}

	} else {
		$mcBuff = draw_message("error", _l("E_ACCESS_DENIED"));
	}

	$mc->save($mcBuff);
?>