<?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();
		$mid = $db->XMFnum($mid);
		if ( $wysiwyg == 'fck' ) {
   		 include_once('FCKeditor/fckeditor.php');
   		 }
		Max_OpenTable();
		echo "<center><font class='title'><b>" . _MESSAGESADMIN . "</b></font></center>";
		Max_CloseTable();
		br('1');
		$row = $db->sql_fetchrow($db->sql_query("SELECT * FROM `".TABLE_MESSAGE."` WHERE `mid`='$mid'"));
        	$groups    = $db->XMFnum($row['groups']);
        	$title     = stripslashes($row['title']);
		$content   = stripslashes($row['content']);
		$mdate     = stripslashes($row['date']);
		$expire    = $db->XMFnum($row['expire']);
		$active    = $db->XMFnum($row['active']);
		$view      = $db->XMFnum($row['view']);
		$mlanguage = $db->XMFlang($row['mlanguage']);
		Max_OpenTable();
		echo "<center><font class='title'><b>" . _EDITMSG . "</b></font></center>";
		if ($active == 1) {
			$asel1 = "checked";
			$asel2 = "";
		} elseif ($active == 0) {
			$asel1 = "";
			$asel2 = "checked";
		}
	$sel1 = $sel2 = $sel3 = $sel4 = $sel5 = $sel6 = "";
    if ($view == 1) {
	$sel1 = "selected";
    } elseif ($view == 2) {
	$sel2 = "selected";
    } elseif ($view == 3) {
	$sel3 = "selected";
    } elseif ($view == 4) {
	$sel4 = "selected";
    } elseif ($view == 5) {
	$sel5 = "selected";
    } elseif ($view > 5) {
	$sel6 = "selected";
    }

		if ($expire == 86400) {
			$esel1 = "selected";
			$esel2 = "";
			$esel3 = "";
			$esel4 = "";
			$esel5 = "";
			$esel6 = "";
		} elseif ($expire == 172800) {
			$esel1 = "";
			$esel2 = "selected";
			$esel3 = "";
			$esel4 = "";
			$esel5 = "";
			$esel6 = "";
		} elseif ($expire == 432000) {
			$esel1 = "";
			$esel2 = "";
			$esel3 = "selected";
			$esel4 = "";
			$esel5 = "";
			$esel6 = "";
		} elseif ($expire == 1296000) {
			$esel1 = "";
			$esel2 = "";
			$esel3 = "";
			$esel4 = "selected";
			$esel5 = "";
			$esel6 = "";
		} elseif ($expire == 2592000) {
			$esel1 = "";
			$esel2 = "";
			$esel3 = "";
			$esel4 = "";
			$esel5 = "selected";
			$esel6 = "";
		} elseif ($expire == 0) {
			$esel1 = "";
			$esel2 = "";
			$esel3 = "";
			$esel4 = "";
			$esel5 = "";
			$esel6 = "selected";
		}
		echo "<form action=\"".$admin_file.".php\" method=\"post\">"
		."<br /><b>" . _MESSAGETITLE . ":</b><br />"
		."<input type=\"text\" name=\"title\" value=\"$title\" size=\"50\" maxlength=\"100\"><br /><br />"
		."<b>" . _MESSAGECONTENT . ":</b><br />";
if ( $wysiwyg == 'fck' ) {
$oFCKeditor = new FCKeditor(content) ;
$oFCKeditor->InstanceName = "content" ;
$oFCKeditor->Value = "$content" ;
$oFCKeditor->Create() ;
} else {
echo  "<textarea name=\"content\" rows=\"15\" wrap=\"virtual\" cols=\"70\">$content</textarea>";
}
br('2');
		if ($multilingual == 1) {
			echo "<b>" . _LANGUAGE . ": </b>"
			."<select name=\"mlanguage\">";
			$handle=opendir('language');
			while ($file = readdir($handle)) {
				if (preg_match("/^lang\-(.+)\.php/", $file, $matches)) {
					$langFound = $matches[1];
					$languageslist .= "$langFound ";
				}
			}
			closedir($handle);
			$languageslist = explode(" ", $languageslist);
			sort($languageslist);
			for ($i=0; $i < sizeof($languageslist); $i++) {
				if($languageslist[$i]!="") {
					echo "<option value=\"$languageslist[$i]\" ";
					if($languageslist[$i]==$mlanguage) echo "selected";
					echo ">".ucfirst($languageslist[$i])."</option>\n";
				}
			}
			if ($mlanguage == "") {
				$sellang = "selected";
			} else {
				$sellang = "";
			}
			echo "<option value=\"\" $sellang>" . _ALL . "</option></select><br /><br />";
		} else {
			echo "<input type=\"hidden\" name=\"mlanguage\" value=\"\">";
		}
		echo "<b>" . _EXPIRATION . ":</b> <select name=\"expire\">"
		."<option name=\"expire\" value=\"86400\" $esel1>1 " . _DAY . "</option>"
		."<option name=\"expire\" value=\"172800\" $esel2>2 " . _DAYS . "</option>"
		."<option name=\"expire\" value=\"432000\" $esel3>5 " . _DAYS . "</option>"
		."<option name=\"expire\" value=\"1296000\" $esel4>15 " . _DAYS . "</option>"
		."<option name=\"expire\" value=\"2592000\" $esel5>30 " . _DAYS . "</option>"
		."<option name=\"expire\" value=\"0\" $esel6>" . _UNLIMITED . "</option>"
		."</select><br /><br />"
		."<b>"._ACTIVE."?</b> <input type=\"radio\" name=\"active\" value=\"1\" $asel1>" . _YES . " "
		."<input type=\"radio\" name=\"active\" value=\"0\" $asel2>" . _NO . "";
		if ($active == 1) {
			echo "<br /><br /><b>" . _CHANGEDATE . "</b>"
			."<input type=\"radio\" name=\"chng_date\" value=\"1\">" . _YES . " "
			."<input type=\"radio\" name=\"chng_date\" value=\"0\" checked>" . _NO . "<br /><br />";
		} elseif ($active == 0) {
			echo "<br /><font class=\"tiny\">" . _IFYOUACTIVE . "</font><br /><br />"
			."<input type=\"hidden\" name=\"chng_date\" value=\"1\">";
		}
		echo "<b>" . _VIEWPRIV . "</b> <select name=\"view\">"
		."<option name=\"view\" value=\"1\" $sel1>" . _MVALL . "</option>"
	    ."<option name=\"view\" value=\"2\" $sel2>" . _MVANON . "</option>"
	    ."<option name=\"view\" value=\"3\" $sel3>" . _MVUSERS . "</option>"
	    ."<option name=\"view\" value=\"4\" $sel4>" . _MVADMIN . "</option>"
	    ."<option name=\"view\" value=\"5\" $sel5>" . _SUBUSERS . "</option>"
        ."<option name=\"view\" value=\"6\" $sel6>"._MVGROUPS."</option>"
	    ."</select><br /><br />"
        ."<font class='tiny'>"._WHATGRDESC."</font><br /><b>"._WHATGROUPS."</b> <select name='groups[]' multiple size='5'>";
    $ingroups = explode("-",$groups);
    $groupsResult = $db->sql_query("SELECT `gid`, `gname` FROM `".TABLE_NSNGR_GROUPS."`");
    while(list($gid, $gname) = $db->sql_fetchrow($groupsResult)) {
        if(in_array($gid,$ingroups) AND $view > 5) { $sel = " selected"; } else { $sel = ""; }
        echo "<option value='$gid'$sel>$gname</option>";
    }
    echo "</select><br /><br />"
        ."<input type=\"hidden\" name=\"mdate\" value=\"$mdate\">"
		."<input type=\"hidden\" name=\"mid\" value=\"$mid\">"
		."<input type=\"hidden\" name=\"op\" value=\"savemsg\">"
		."<input type=\"submit\" value=\"" . _SAVECHANGES . "\">"
		."</form>";
		Max_CloseTable();
		incof();
}
}else {
	echo "Access Denied";
}