<?php


#############################################################################
#                              Site@School
# Site@School is a website management system designed for schools.
#
# About Site@School:
#
# Comissioned by: Stadsdeel de Baarsjes, Amsterdam, Netherlands
############################################################################
# admin.php: last changed 09/10/2006  , version: 2.4.10
#              by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: admin.php,v 1.2 2006/10/15 19:08:54 fstuurman Exp $
############################################################################
#                        LICENSE INFORMATION
#
# 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, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
##############################################################################
if (!defined('IN_SAS'))
{
	die("Hacking attempt");
}
if (IsSet ($_POST['message_add_text']))
{
	$message_add_text = sql_addslashes($_POST['message_add_text']);
}
if (IsSet ($_POST['message_view_text']))
{
	$message_view_text = sql_addslashes($_POST['message_view_text']);
}
if (IsSet ($_POST['message_view_text']))
{
	$message_view_text_prot = sql_addslashes($_POST['message_view_text_prot']);
}
if (IsSet ($_POST['message']))
{
	$message = sql_addslashes($_POST['message']);
}
if (IsSet ($_POST['date']))
{
	$date = $_POST['date'];
}
if (IsSet ($_POST['name']))
{
	$name = sql_addslashes($_POST['name']);
}
if (IsSet ($_POST['days']))
{
	$days = $_POST['days'];
}
if (IsSet ($_POST['public']))
{
	$public = $_POST['public'];
}
if (IsSet ($_GET['edit_message']))
{
	$edit_message = $_GET['edit_message'];
}
if (IsSet ($_GET['save_message']))
{
	$save_message = $_GET['save_message'];
}
if (IsSet ($_GET['delete_message']))
{
	$delete_message = $_GET['delete_message'];
}
if (IsSet ($_GET['add_message']))
{
	$add_message = $_GET['add_message'];
}

load_language('', 'sn_message'); //load language file

include ("interface/header.inc.php");
include ("interface/menubar.inc.php");
include ("interface/menustart.inc.php");
print "<span class=heading>" . $sas_lang['filemanager_menu'] . "</span><br><br>";
print "<span class=link><a href=index.php?option=modulemanager&module=$module>" . $sas_lang['public_area'] . "</a><p>
<a href=index.php?option=modulemanager&module=$module&modoption=protected>" . $sas_lang['protected_area'] . "</a><p>
<a href=index.php?option=modulemanager&module=$module&modoption=configuration>" . $sas_lang['configuration'] . "</a><br></span>";
include ("interface/menuend.inc.php");
include ("interface/pagestart.inc.php");

$table_message = $dbprefix . "m_message";

$date_format = $sas_config['dateformat'];

if ($modoption == "saveconfig")
{
	if (!get_magic_quotes_gpc())
	{
		$welcometext = addslashes($_POST['welcometext']);
	}
	else
	{
		$welcometext = $_POST['welcometext'];
	}

	mysql_query("UPDATE $table_message SET config_value='$days' WHERE config_key='days'");
	mysql_query("UPDATE $table_configuration SET config_value='$message_add_text' WHERE config_key='message_add_text'");
	mysql_query("UPDATE $table_configuration SET config_value='$message_view_text' WHERE config_key='message_view_text'");
	mysql_query("UPDATE $table_configuration SET config_value='$message_view_text_prot' WHERE config_key='message_view_text_prot'");
	print "<span class=\"heading\">$modulename $sas_lang[configuration]<br><br></span>";
	print "$sas_lang[message_module_saved]";
	exit;
}

if ($modoption == "configuration")
{
	//   $days = $table_message['days'];
	$message_add_text = $sas_config['message_add_text'];
	$message_view_text = $sas_config['message_view_text'];
	$message_view_text_prot = $sas_config['message_view_text_prot'];

	print "<span class=\"heading\">$modulename " . $sas_lang['configuration'] . "&nbsp;" . $sas_lang['message_module_module'] . "<br><br></span>";
	print "<FORM METHOD=\"POST\" ACTION=\"index.php?option=modulemanager&module=$module&modoption=saveconfig\">";

	print "<b>" . $sas_lang['message_module_header1'] . "</b><br><textarea cols=\"70\" rows=\"3\" name=\"message_view_text\">$message_view_text</textarea><br><br><br>\n";
	print "<b>" . $sas_lang['message_module_header3'] . "</b><br><textarea cols=\"70\" rows=\"3\" name=\"message_view_text_prot\">$message_view_text_prot</textarea><br><br><br>\n";
	print "<b>" . $sas_lang['message_module_header2'] . "</b><br><textarea cols=\"70\" rows=\"3\" name=\"message_add_text\">$message_add_text</textarea><br><br><br>\n";
	
	print "\n<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['cancel'] . "\" name=\"backbutton\" 
					         onClick=\"javascript:parent.location='index.php?option=modulemanager&module=$module';\" class=\"cancelbutton\">";
	print "\n&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['save'] . "\" name=\"savebutton\" class=\"savebutton\">";
	print "</span></form>";
	exit;
}

if (IsSet ($save_message))
{
	$days = intval($days);

	if ($save_message == "new")
	{
		mysql_query("INSERT INTO $table_message (id, message, date, name, days, todate, public)
							VALUES (NULL, '$message', NOW(), '$name', '$days', DATE_ADD(NOW(),INTERVAL $days DAY), '$public')");
	}
	else
	{
		mysql_query("UPDATE $table_message
											SET message='$message' ,
											date='$date' ,
											name='$name' ,
										    days='$days',
											todate=DATE_ADD('$date',INTERVAL $days DAY),
											public='$public'
											WHERE id='$save_message'");
	}
	// set the last update date for the page
	$date1 = date("Y-m-d H:i:s");
	mysql_query("UPDATE $table_pages SET lastupdate='$date1' WHERE module='sn_message/view_message.php'");
}

if (IsSet ($delete_message))
{
	mysql_query("DELETE FROM $table_message WHERE id = '$delete_message'");
}

if (IsSet ($edit_message))
{
	print "<span class=\"heading\">" . $sas_lang['message_module_change'] . "</span><p>";
	$query = "SELECT id, message, date, name, days, public FROM $table_message WHERE id=$edit_message";
	$result = mysql_query($query) or die_script($query, mysql_error());
	$message_list = mysql_fetch_array($result);
	print "<FORM METHOD=\"POST\" NAME=\"form\" ACTION=\"index.php?option=modulemanager&module=$module&save_message=$edit_message&modoption=$modoption\">
					         <table border=\"0\" cellpadding=\"2\">";
	print "  <tr><td width=20%><span class=text><b>" . $sas_lang['message_module_owner'] . " :</b></span></td>
					         <td><input type=\"text\" name=\"name\" size=\"40\" value=\"$message_list[3]\" class=\"textfield\"></td></tr>
					         <tr><td><span class=text><b>" . $sas_lang['message_module_date'] . " :</b></span></td>
					         <td><input type=\"text\" name=\"date\" size=\"40\" value=\"$message_list[2]\" class=\"textfield\"></td></tr>
					         <tr><td valign=top><span class=text><b>" . $sas_lang['message_module_message'] . " :</b></span></td>
					         <td><textarea cols=\"70\" rows=\"6\" name=\"message\">$message_list[1]</textarea></tr></td>
					         <tr><td><span class=text><b>" . $sas_lang['message_module_days'] . " :</b></span></td>
					         <td><input type=\"text\" name=\"days\" size=\"5\" value=\"$message_list[4]\" class=\"textfield\"></td></tr>";
	print "</table>";
	print "<p><span class=text><b>" . $sas_lang['message_module_is_public'] . "  :&nbsp;" . $sas_lang['yes'] . "</b></span>";

	if ($message_list[5] == "1")
	{
		print "<input type=\"radio\" value=\"1\" name=\"public\" checked>";
		print "<span class=text><b>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</b></span>";
		print "<input type=\"radio\" name=\"public\" value=\"0\">";
	}
	else
	{
		print "<input type=\"radio\" value=\"1\" name=\"public\">";
		print "<span class=text><b>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</b></span>";
		print "<input type=\"radio\" name=\"public\" value=\"0\" checked>";
	}

	print "\n<p><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sas_lang[goback]\" name=\"backbutton\"
							onClick=\"javascript:parent.location='index.php?option=modulemanager&module=$module';\" class=\"backbutton\">";
	print "&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;$sas_lang[save]\" name=\"savebutton\" class=\"savebutton\">";
	print "</form>";
	exit;
}

if (IsSet ($add_message))
{
	print "<span class=\"heading\"><b>&nbsp;$sas_lang[message_module_add]</b></center></span><p>";
	print "<FORM METHOD=\"POST\" NAMEe=\"message\" ACTION=\"index.php?option=modulemanager&module=$module&save_message=new\"
					       onsubmit=\"return checkinput(this);\"><table>\n";
	print "<TR><TD valign=top><font size=\"2\"><b>$sas_lang[message_module_message]:&nbsp;</b></font></TD></TR>
					       <TR><TD><TEXTAREA cols=50 rows=\"6\" name=\"message\"></TEXTAREA><br>&nbsp;</TD></TR>
					       <TR><TD valign=top><font size=\"2\"><b>$sas_lang[message_module_owner]:&nbsp;</b></font></TD></TR>
					       <TR><TD><INPUT class=\"textfield\" size=\"40\" name=\"name\"><br>&nbsp;</TD></TR>
					       <TR><TD valign=top><font size=\"2\"><b>$sas_lang[message_module_days]:&nbsp;</b></font></TD></TR>
					       <TR><TD><INPUT class=\"textfield\" size=\"5\" name=\"days\"><br>&nbsp;</TD></TR>";
	print "</table>";
	print "<p><span class=text><b>" . $sas_lang['message_module_is_public'] . "  :&nbsp;" . $sas_lang['yes'] . "</b></span>";
	if ($public == "1")
	{
		print "<input type=\"radio\" value=\"1\" name=\"public\" checked>";
		print "<span class=text><b>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</b></span>";
		print "<input type=\"radio\" name=\"public\" value=\"0\">";
	}
	else
	{
		print "<input type=\"radio\" value=\"1\" name=\"public\">";
		print "<span class=text><b>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</b></span>";
		print "<input type=\"radio\" name=\"public\" value=\"0\" checked>";
	}
	print "<p><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;$sas_lang[goback]\" name=\"backbutton\"
					       onClick=\"javascript:parent.location='index.php?option=modulemanager&module=$module';\" class=\"backbutton\">";
	print "&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;$sas_lang[save]\" name=\"savebutton\" class=\"savebutton\">";
	print "</span></form>";
	exit;
}

if ($modoption == "protected")
{
	print "<span class=\"heading\">" . $sas_lang['message_module_protected'] . " $modulename " . $sas_lang['message_module_module'] . "<br><br></span>";
	$query = "SELECT id, name, message, date_format(date, '%d-%m-%Y'), days AS Readable_Date, public FROM $table_message WHERE public = 1 order by date DESC";
	$result = mysql_query($query) or die_script($query, mysql_error());
}
else
{
	print "<span class=\"heading\">" . $sas_lang['manage'] . " $modulename " . $sas_lang['message_module_module'] . "<br><br></span>";
	$query = "SELECT id, name, message, date_format(date, '%d-%m-%Y'), days AS Readable_Date, public FROM $table_message WHERE public = 0 order by date DESC";
	$result = mysql_query($query) or die_script($query, mysql_error());
}

while ($message_list = mysql_fetch_array($result))
{
	print "<table width=100% border=\"0\"><span class=text><tr>";
	$msg = str_replace("%date%", $message_list[3], $sas_lang['message_module_delete']);
	print "<tr bgcolor=\"$bgcolor\">
									 <td width=2%><img border=\"0\" src=\"graphics/delete.gif\" alt=\"$sas_lang[delete]\" title=\"$sas_lang[delete]\" width=\"16\" height=\"16\"
							 		 onClick=\"if(confirm('" . $msg . "')) parent.location='index.php?option=modulemanager&module=$module&delete_message=$message_list[0]';\"></td>
									 <td width=2%><img border=\"0\" src=\"graphics/edit.gif\" alt=\"$sas_lang[edit]\"  title=\"$sas_lang[edit]\"width=\"16\" height=\"16\"
									 onClick=\"parent.location='index.php?option=modulemanager&module=$module&edit_message=$message_list[0]';\"></td>
						             <td valign=top width='15%'><font size=2> <b>" . $sas_lang['message_module_date'] . " </b></td>
						             <td valign=top width='1%'>: </td>
						             <td valign=top><font size=2>$message_list[3]<br></td>
						             </tr>
						             <tr> <td width=2%></td><td width=2%></td>
						             <td valign=top width='15%'><font size=2> <b>" . $sas_lang['message_module_owner'] . " </b></td>
						             <td valign=top width='1%'>: </td>
						             <td valign=top><font size=2>$message_list[1]<br></td>
						             </tr>
						             <tr> <td width=2%></td><td width=2%></td>
						             <td valign=top width='15%'><font size=2> <b>" . $sas_lang['message_module_message'] . " </b></td>
						             <td valign=top width='1%'>: </td>
						             <td valign=top><font size=2>$message_list[2]<br></td>
						             </tr>
						             <tr><td width=2%></td><td width=2%></td>
						             <td valign=top width='15%' valign=top><font size=2> <b>" . $sas_lang['message_module_days'] . " </b></td>
						             <td valign=top width='1%'>: </td>
						             <td valign=top><font size=2>$message_list[4]<br></td>
						             </tr>
						             <tr><td width=2%></td><td width=2%></td>
					             <td width='12%' valign=top><span class=text><b>" . $sas_lang['message_module_is_public'] . "</b></span></td>
					             <td valign=top width='1%'>: </td>";

	if ($message_list[5] == "1")
	{
		print "<td valign=top><span class=text>" . $sas_lang['yes'] . "<br></td>";
	}
	else
	{
		print "<td valign=top><span class=text>" . $sas_lang['no'] . "<br></td>";
	}
	print "</tr>
					             </table><hr> ";
}

print "<p><img border=\"0\" src=\"graphics/document.gif\">
       <span class=\"link\"><a href=\"index.php?option=modulemanager&module=$module&add_message=1\">$sas_lang[message_module_add]</a></span>";

print "\n<p><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['goback'] . "\" name=\"backbutton\" onClick=\"javascript:parent.location='index.php?option=modulemanager';\" class=\"backbutton\">";
include ("interface/pageend.inc.php");
include ("interface/footer.inc.php");
?>
