<?php
// www.bcoos.net 2006-09 1.0.2 GPL
// $Id: main.php,v 1.11 2003/07/10 18:29:58 half-dead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: Kazumi Ono
// Author Website : http://www.mywebaddons.com/ , http://www.myweb.ne.jp
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
if ( !preg_match("/admin\.php/i", _PHP_SELF) ) {
	exit();
	}
include_once(XOOPS_ROOT_PATH."/modules/system/admin/modulesadmin/modulesadmin.php");
$op = "list";
if ( isset($_POST) ) {
	foreach ( $_POST as $k => $v ) {
		$$k = $v;
  	}
}
if ( $op == "list" ) {
	module_list();
}
if ( $op == "confirm" ) {
	xoops_cp_header();
	OpenTable();
	$error = array();
	if ( @!is_writable(XOOPS_ROOT_PATH."/modules/system/cache/adminmenu.php") ) {
		if ( @!chmod(XOOPS_ROOT_PATH."/modules/system/cache/adminmenu.php", 0666) ) {
			$error[] = sprintf(_MUSTWABLE, "<b>".XOOPS_ROOT_PATH."/modules/system/cache/adminmenu.php</b>");
		}
	}
	if ( count($error) > 0 ) {
		foreach ( $error as $er ) {
			echo $er."<br />";
		}
		echo "<p><a href='admin.php?fct=modulesadmin'>"._MD_AM_BTOMADMIN."</a></p>";
		CloseTable();
		xoops_cp_footer();
		exit();
	}
	echo "<h4 style='text-align:left;'>"._MD_AM_PCMFM."</h4>
	<form action='admin.php' method='post'>
	<input type='hidden' name='fct' value='modulesadmin' />
	<input type='hidden' name='op' value='submit' />
	<table border='0' cellpadding='0' cellspacing='0' valign='top' width='50%'><tr><td class='bg2'>
	<table width='100%' border='0' cellpadding='4' cellspacing='1'>
	<tr valign='middle' class='bg3' align='center'><td><b>"._MD_AM_MODULE."</b></td><td><b>"._MD_AM_ACTION."</b></td><td><b>"._MD_AM_ORDER."</b></td></tr>";
	$size = count($module);
	for ( $i = 0 ; $i < $size; $i++ ) {
		echo "<tr class='bg1'><td>".$name[$i]."</td><td align='center'>";
		if ( $newstatus[$i] != "nochange" ) {
			switch ($newstatus[$i]) {
				case "deactivate":
					$statustext = _DEACTIVATE;
					break;
				case "activate":
					$statustext = _ACTIVATE;
					break;
				case "install":
					$statustext = _INSTALL;
					break;
				case "uninstall":
					$statustext = _UNINSTALL;
					break;
				case "update":
					$statustext = _UPDATE;
					break;
			}
			echo "<span style='color:#ff0000;font-weight:bold;'>".$statustext."</span>";
		} else {
			echo _MD_AM_NOCHANGE;
		}
		echo "</td><td align='center'>";
		if ( $oldweight[$i] != $weight[$i] ) {
			echo "<span style='color:#ff0000;font-weight:bold;'>".$weight[$i]."</span>";
		} else {
			echo $weight[$i];
		}
		echo "
		<input type='hidden' name='module[]' value='".$module[$i]."' />
		<input type='hidden' name='oldstatus[]' value='".$oldstatus[$i]."' />
		<input type='hidden' name='newstatus[]' value='".$newstatus[$i]."' />
		<input type='hidden' name='oldweight[]' value='".intval($oldweight[$i])."' />
		<input type='hidden' name='weight[]' value='".intval($weight[$i])."' />
		</td></tr>";
	}
	echo "
	<tr class='bg3' align='center'><td colspan='3'><input type='submit' class='button' value='"._SUBMIT."' />&nbsp;<input type='button' class='button' value='"._CANCEL."' onclick='location=\"admin.php?fct=modulesadmin\"' /></td></tr>
	</table>
	</td></tr></table>
	</form>";
	CloseTable();
	xoops_cp_footer();
}
if ( $op == "submit" ) {
	$size = count($newstatus);
	$ret = array();
	$write = false;
	for ( $i = 0 ; $i < $size; $i++ ) {
		$reorder = true;
		switch ($newstatus[$i]) {
			case "install":
				$ret[] = module_install($module[$i]);
				$write = true;
				break;
			case "activate":
				$ret[] = module_activate($module[$i]);
				$write = true;
				break;
			case "deactivate":
				$ret[] = module_deactivate($module[$i]);
				$write = true;
				break;
			case "update":
				$ret[] = module_update($module[$i]);
				$write = true;
				break;
			case "uninstall":
				$ret[] = module_uninstall($module[$i]);
				$reorder = false;
				$write = true;
				break;
			default:
				break;
		}
		if ( $oldstatus[$i] == 0 && $newstatus[$i] != "install" ) {
			$reorder = false;
		}
		if ( $reorder == true && $oldweight[$i] != $weight[$i] ) {
			$ret[] = module_order($module[$i], $weight[$i]);
			$write = true;
		}
	}
	if ( $write ) {
		$contents = get_module_admin_menu();
		if (!write_module_admin_menu($contents)) {
			$ret[] = "<p>"._MD_AM_FAILWRITE."</p>";
		}
	}
	xoops_cp_header();
	OpenTable();
	if ( count($ret) > 0 ) {
		foreach ($ret as $msg) {
			echo $msg;
		}
	}
	echo "<li><a href='admin.php?fct=modulesadmin'>"._MD_AM_BTOMADMIN."</a></li>";
	echo "<br /><br />";
	echo "<li><a href='admin.php?fct=groups'>"._MD_AM_EDITACCESS."</a></li>";
	CloseTable();
	xoops_cp_footer();
}
?>
