<?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)  {

		$main_m = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `main_module` FROM `".TABLE_MAIN."`"));
		$main_module = stripslashes($main_m['main_module']);
		$mid         = $GLOBALS['db']->XMFnum($mid);
		$row         = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_MODULES."` WHERE `mid`='$mid'"));
     		$groups      = $GLOBALS['db']->XMFnum($row['groups']);
       	        $title       = stripslashes($row['title']);
		$custom_title= stripslashes($row['custom_title']);
		$view        = $GLOBALS['db']->XMFnum($row['view']);
		$inmenu      = $GLOBALS['db']->XMFnum($row['inmenu']);
		$mod_group   = $GLOBALS['db']->XMFnum($row['mod_group']);
		incoh();
		title("" . _MODULEEDIT . "");
		Max_OpenTable();
	$sel1 = $sel2 = $sel3 = $sel4 = $sel5 = "";
    if ($view == 0) {
	$sel1 = "selected";
    } elseif ($view == 1) {
	$sel2 = "selected";
    } elseif ($view == 2) {
	$sel3 = "selected";
    } elseif ($view == 3) {
	$sel4 = "selected";
    } elseif ($view > 3) {
        $sel5 = "selected";
    }

		if ($title == $main_module) {
			$a = " - " . _INHOME . "";
		} else {
			$a = "";
		}
		if ($inmenu == 1) {
			$insel1 = "checked";
			$insel2 = "";
		} elseif ($inmenu == 0) {
			$insel1 = "";
			$insel2 = "checked";
		}
		echo "<center><b>" . _CHANGEMODNAME . "</b><br />($title$a)</center><br /><br />"
		."<form action=\"".$admin_file.".php\" method=\"post\">"
		."<table border=\"0\"><tr><td>"
		."" . _CUSTOMMODNAME . "</td><td>"
		."<input type=\"text\" name=\"custom_title\" value=\"$custom_title\" size=\"50\" /></td></tr>";
		if ($title == $main_module) {
			echo "<input type=\"hidden\" name=\"view\" value=\"0\" />"
			."<input type=\"hidden\" name=\"inmenu\" value=\"$inmenu\" />"
			."</table><br /><br />";
		} else {
			echo "<tr><td>" . _VIEWPRIV . "</td><td><select name=\"view\">"
	    ."<option value=\"0\" $sel1>" . _MVALL . "</option>"
	    ."<option value=\"1\" $sel2>" . _MVUSERS . "</option>"
	    ."<option value=\"2\" $sel3>" . _MVADMIN . "</option>"
	    ."<option value=\"3\" $sel4>" . _SUBUSERS . "</option>"
            ."<option value=\"4\" $sel5>"._MVGROUPS."</option>"
	    ."</select></td></tr>";
        echo "<tr><td valign='top'><b>"._WHATGROUPS.":</b></td><td><font class='tiny'>"._WHATGRDESC."</font><br /><select name='groups[]' multiple size='5'>";
        $ingroups = explode("-",$groups);
        $groupsResult = $GLOBALS['db']->sql_query("select gid, gname from ".TABLE_NSNGR_GROUPS."");
        while(list($gid, $gname) = $GLOBALS['db']->sql_fetchrow($groupsResult)) {
            if(in_array($gid,$ingroups)) { $sel = " selected"; } else { $sel = ""; }
            echo "<OPTION VALUE='$gid'$sel>$gname</option>";
        }
        echo "</select></td></tr>";
			$numrow = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT * FROM " . $prefix . "_groups"));
			if ($numrow > 0) {
				echo "<tr><td>" . _UGROUP . "</td><td><select name=\"mod_group\">";
				$result2 = $GLOBALS['db']->sql_query("SELECT `id`, `name` FROM `" . $prefix . "_groups`");
				while ($row2 = $GLOBALS['db']->sql_fetchrow($result2)) {
					if ($GLOBALS['db']->XMFnum($row2['id']) == $mod_group) { $gsel = "selected"; } else { $gsel = ""; }
					if ($dummy != 1) {
						if ($mod_group == 0) { $ggsel = "selected"; } else { $ggsel = ""; }
						echo "<option value=\"0\" $ggsel>" . _NONE . "</option>";
						$dummy = 1;
					}
					echo "<option value=\"$row2[id]\" $gsel>$row2[name]</option>";
					$gsel = "";
				}
				echo "</select>&nbsp;<i>(" . _VALIDIFREG . ")</i></td></tr>";
			} else {
				echo "<input type=\"hidden\" name=\"mod_group\" value=\"0\" />";
			}
			echo "<tr><td>"._SHOWINMENU."</td><td>"
			."<input type=\"radio\" name=\"inmenu\" value=\"1\" $insel1 /> " . _YES . " &nbsp;&nbsp; <input type=\"radio\" name=\"inmenu\" value=\"0\" $insel2 /> " . _NO . ""
			."</td></tr></table><br /><br />";
		}
		if ($title != $main_module) {

		}
		echo "<input type=\"hidden\" name=\"mid\" value=\"$mid\" />"
		."<input type=\"hidden\" name=\"op\" value=\"module_edit_save\" />"
		."<input type=\"submit\" value=\"" . _SAVECHANGES . "\" />"
		."</form>"
		."<br /><br /><center>" . _GOBACK . "</center>";
		Max_CloseTable();
		incof();

}
} else {
	echo "Access Denied";
}