<?php
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2006                                            */
/* http://www.php-maximus.fr                                            */
/* dev@php-maximus.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.       */
/************************************************************************/
/* Based on PHP-NUKE: Web Portal System                                 */
/************************************************************************/
if (!defined('ADMIN_ALLOW') && !defined('ADMIN_MAX')) {
	die ("Access Denied");
}
if ($acces == 1) {
if($admintest && $adminsecu)  {

		incoh();
		if (is_file('kernel/tabs/tabwindow.php')) {
		include_once ('kernel/tabs/tabwindow.php');
		}
		$currentTabs=new Tabs("modules1");
		$currentTabs->StartTabWindow();
		$currentTabs->AddTab(""._INSTALLED."");
		Max_OpenTable();
		echo "<center><font class='title'><b>" . _MODULESADMIN . "</b></font></center>";
		Max_CloseTable();
		$handle=opendir('modules');
		while ($file = readdir($handle)) {
			if ( (!ereg("[.]",$file)) ) {
				$modlist .= "$file ";
			}
		}
		closedir($handle);
		$modlist = explode(" ", $modlist);
		sort($modlist);
		for ($i=0; $i < sizeof($modlist); $i++) {
			if($modlist[$i] != "") {
		$row = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `mid` from `".TABLE_MODULES."` WHERE `title`='$modlist[$i]' "));
		$mid = $GLOBALS['db']->XMFnum($row['mid']);
		if ($mid == "") {
		$GLOBALS['db']->sql_query("INSERT INTO `".TABLE_MODULES."` VALUES (NULL, '$modlist[$i]', '$modlist[$i]', '0', '0', '', '1', '0', '','0')");
				}
			}
		}
		$GLOBALS['db']->sql_query("UPDATE `".TABLE_MODULES."` SET `active`='1', `view`='0', `inmenu`='1', `install`='1' WHERE `title`='Copyrights'");
		$result2 = $GLOBALS['db']->sql_query("SELECT `title` from `".TABLE_MODULES."`");
		while ($row2 = $GLOBALS['db']->sql_fetchrow($result2)) {
			$title = stripslashes($row2['title']);
			$a = 0;
			$handle=opendir('modules');
			while ($file = readdir($handle)) {
				if ($file == $title) {
					$a = 1;
				}
			}
			closedir($handle);
			if ($a == 0) {
				$GLOBALS['db']->sql_query("DELETE FROM `".TABLE_MODULES."` WHERE `title`='$title'");
			}
		}
		br('1');
		Max_OpenTable();
		echo "<br /><center><font class=\"option\">" . _MODULESADDONS . "</font><br /><br />"
		."<font class=\"content\">" . _MODULESACTIVATION . "</font><br /><br />"
		."" . _MODULEHOMENOTE . "<br /><br />" . _NOTINMENU . "<br /><br />"
		."<form action=\"".$admin_file.".php\" method=\"post\">"
		."<table border=\"1\" align=\"center\" width=\"90%\"><tr><td align=\"center\" bgcolor=\"$bgcolor2\">"
		."<b>"._TITLE."</b></td><td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._CUSTOMTITLE."</b></td><td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._STATUS."</b></td><td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._VIEW."</b></td><td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._GROUP."</b></td><td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._FUNCTIONS."</b></td></tr>";
		$main_m = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT main_module from ".TABLE_MAIN.""));
		$main_module = stripslashes($main_m['main_module']);
		$result3 = $GLOBALS['db']->sql_query("SELECT `mid`, `title`, `custom_title`, `active`, `view`, `groups`, `inmenu`, `mod_group` from `".TABLE_MODULES."` WHERE `install`='1' ORDER BY `title` ASC");
		while ($row3 = $GLOBALS['db']->sql_fetchrow($result3)) {
			$mid          = $GLOBALS['db']->XMFnum($row3['mid']);
			$title        = stripslashes($row3['title']);
			$title2       = $title;
			$custom_title = stripslashes($row3['custom_title']);
			$active       = $GLOBALS['db']->XMFnum($row3['active']);
			$view         = $GLOBALS['db']->XMFnum($row3['view']);
			$group_id     = $GLOBALS['db']->XMFnum($row3['groups']);
			$inmenu       = $GLOBALS['db']->XMFnum($row3['inmenu']);
			$mod_group    = $GLOBALS['db']->XMFnum($row3['mod_group']);
			if ($custom_title == "") {
				$custom_title = ereg_replace("_"," ",$title);
				$GLOBALS['db']->sql_query("UPDATE `".TABLE_MODULES."` SET `custom_title`='$custom_title' WHERE `mid`='$mid'");
			}
			if ($active == 1) {
				$active = "<img src=\"images/active.gif\" alt=\""._ACTIVE."\" title=\""._ACTIVE."\" border=\"0\" width=\"16\" height=\"16\" />";
				$change = "<img src=\"images/inactive.gif\" alt=\""._DEACTIVATE."\" title=\""._DEACTIVATE."\" border=\"0\" width=\"16\" height=\"16\" />";
				$act = 0;
			} else {
				$active = "<img src=\"images/inactive.gif\" alt=\""._INACTIVE."\" title=\""._INACTIVE."\" border=\"0\" width=\"16\" height=\"16\" />";
				$change = "<img src=\"images/active.gif\" alt=\""._ACTIVATE."\" title=\""._ACTIVATE."\" border=\"0\" width=\"16\" height=\"16\" />";
				$act = 1;
			}
			if ($custom_title == "") {
				$custom_title = ereg_replace("_", " ", $title);
			}
			if ($view == 0) {
				$who_view = _MVALL;
			} elseif ($view == 1) {
				$who_view = _MVUSERS;
			} elseif ($view == 2) {
				$who_view = _MVADMIN;
			} elseif ($view == 3) {
				$who_view = _SUBUSERS;
			} elseif ($view > 3) {
            		$who_view = _MVGROUPS;
			}
			$titledestall = $title;
			if ($title != $main_module AND $inmenu == 0) {

				$title = "[ <big><strong>&middot;</strong></big> ] $title";

			}

if (file_exists("modules/$titledestall/max_sql/".$titledestall."-deinstall.php") && file_exists("modules/$titledestall/credits.php")) {
$destall = "<a href=\"".$admin_file.".php?op=moduledeinstall&mid=$mid&install=0&moduledeinstall=$titledestall&ok=0\"><img src=\"images/trashmini.png\" alt=\""._DESTALL."\" title=\""._DESTALL."\" border=\"0\" width=\"17\" height=\"17\" /></a>";
} else {
$destall = "<img src=\"images/trashmini_x.png\" alt=\""._DESTALLIMPOSSIBLE."\" title=\""._DESTALLIMPOSSIBLE."\" border=\"0\" width=\"17\" height=\"17\">";
}

			if ($title == $main_module) {
				$title = "<b>$title</b>";
				$custom_title = "<b>$custom_title</b>";
				$active = "$active <img src=\"images/key.gif\" alt=\""._INHOME."\" title=\""._INHOME."\" border=\"0\" width=\"17\" height=\"17\" />";
				$who_view = "<b>$who_view</b>";
				$puthome = "<img src=\"images/key_x.gif\" alt=\""._INHOME."\" title=\""._INHOME."\" border=\"0\" width=\"17\" height=\"17\" />";
				$change_status = "$change";
				$background = "bgcolor=\"$bgcolor2\"";
			} else {
				$puthome = "<a href=\"".$admin_file.".php?op=home_module&mid=$mid\"><img src=\"images/key.gif\" alt=\""._PUTINHOME."\" title=\""._PUTINHOME."\" border=\"0\" width=\"17\" height=\"17\" /></a>";
				$change_status = "<a href=\"".$admin_file.".php?op=module_status&mid=$mid&active=$act&xmodule=$title2\">$change</a>";
				$background = "";
			}
			if ($view == 4) {
				$grp = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT gname FROM ".TABLE_NSNGR_GROUPS."  WHERE gid='$group_id'"));
				$mod_group = stripslashes($grp['gname']);
			} else {
				$mod_group = _NONE;
}
			echo "<tr><td $background>&nbsp;$title</td><td align=\"center\" $background>$custom_title</td><td align=\"center\" $background>$active</td><td align=\"center\" $background>$who_view</td><td align=\"center\" $background>$mod_group</td><td align=\"center\" $background nowrap>";
			if ($title != "Copyrights") { echo "&nbsp; <a href=\"".$admin_file.".php?op=module_edit&mid=$mid\"><img src=\"images/edit.gif\" alt=\""._EDIT."\" title=\""._EDIT."\" border=\"0\" width=\"17\" height=\"17\" /></a>$change_status $puthome $destall&nbsp;";}
			echo "</td></tr>";
		}
		echo "</table></form></center>";
		Max_CloseTable();


// DESINSTALLATION
		$currentTabs->AddTab(""._NOT_INSTALLED."");
	Max_OpenTable();
	echo "<center><font class='title'><b>" . _MODULESADMIN . "</b></font></center>";
	Max_CloseTable();
	br('1');
		Max_OpenTable();
		echo "<br /><center><font class=\"option\">" . _MODULESADDONS . "</font><br /><br />"
		."<font class=\"content\">" . _MODULESACTIVATION . "</font><br /><br />"
		."" . _MODULEHOMENOTE2 . "<br />"
		."<form action=\"".$admin_file.".php\" method=\"post\">"
		."<table border=\"1\" align=\"center\" width=\"90%\"><tr><td align=\"center\" bgcolor=\"$bgcolor2\">"
		."<b>"._TITLE."</b></td><td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._CUSTOMTITLE."</b></td><td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._STATUS."</b></td><td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._VIEW."</b></td><td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._GROUP."</b></td><td align=\"center\" bgcolor=\"$bgcolor2\"><b>"._FUNCTIONS."</b></td></tr>";

		$result4 = $GLOBALS['db']->sql_query("SELECT `mid`, `title`, `custom_title`, `active`, `view`, `groups`, `inmenu`, `mod_group` FROM `".TABLE_MODULES."` WHERE `install`='0' ORDER BY `title` ASC");
		while ($row4 = $GLOBALS['db']->sql_fetchrow($result4)) {
			$mid          = $GLOBALS['db']->XMFnum($row4['mid']);
			$title        = stripslashes($row4['title']);
			$custom_title = stripslashes($row4['custom_title']);
			$active       = $GLOBALS['db']->XMFnum($row4['active']);
			$view         = $GLOBALS['db']->XMFnum($row4['view']);
			$group_id     = $GLOBALS['db']->XMFnum($row4['groups']);
			$inmenu       = $GLOBALS['db']->XMFnum($row4['inmenu']);
			$mod_group    = $GLOBALS['db']->XMFnum($row4['mod_group']);
			if ($custom_title == "") {
				$custom_title = ereg_replace("_"," ",$title);
				$GLOBALS['db']->sql_query("UPDATE `".TABLE_MODULES."` SET `custom_title`='$custom_title' WHERE `mid`='$mid'");
			}
			if ($active == 1) {
				$active = "<img src=\"images/active.gif\" alt=\""._ACTIVE."\" title=\""._ACTIVE."\" border=\"0\" width=\"16\" height=\"16\" />";
				$change = "<img src=\"images/inactive.gif\" alt=\""._DEACTIVATE."\" title=\""._DEACTIVATE."\" border=\"0\" width=\"16\" height=\"16\" />";
				$act = 0;
			} else {
				$active = "<img src=\"images/inactive.gif\" alt=\""._INACTIVE."\" title=\""._INACTIVE."\" border=\"0\" width=\"16\" height=\"16\" />";
				$change = "<img src=\"images/active.gif\" alt=\""._ACTIVATE."\" title=\""._ACTIVATE."\" border=\"0\" width=\"16\" height=\"16\" />";
				$act = 1;
			}
			if ($custom_title == "") {
				$custom_title = ereg_replace("_", " ", $title);
			}
			if ($view == 0) {
				$who_view = _MVALL;
			} elseif ($view == 1) {
				$who_view = _MVUSERS;
			} elseif ($view == 2) {
				$who_view = _MVADMIN;
			} elseif ($view == 3) {
				$who_view = _SUBUSERS;
			} elseif ($view > 3) {
            $who_view = _MVGROUPS;

			}
$install = "<a href=\"".$admin_file.".php?op=moduleinstall&mid=$mid&moduleinstall=$title&ok=0\">"._INSTALL."</a>";

			if ($view == 4) {
				$grp = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `gname` FROM `".TABLE_NSNGR_GROUPS."`  WHERE `gid`='$group_id'"));
				$mod_group = stripslashes($grp['gname']);
			} else {
				$mod_group = _NONE;
			}
			echo "<tr><td $background>&nbsp;$title</td><td align=\"center\" $background>$custom_title</td><td align=\"center\" $background>$active</td><td align=\"center\" $background>$who_view</td><td align=\"center\" $background>$mod_group</td><td align=\"center\" $background nowrap>&nbsp; $install&nbsp;</td></tr>";
		}
		echo "</table></form></center>";
		Max_CloseTable();
		$currentTabs->EndTabWindow();
		incof();

	}
} else {
	echo "Access Denied";
}