<?php


#############################################################################
#                              Site@School
# Site@School is a website management system designed for schools.
#
# About Site@School:
#
# Comissioned by: Stadsdeel de Baarsjes, Amsterdam, Netherlands
#############################################################################
# message.php: last changed 09/10/2006  , version: 2.4.10
#              by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: message.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 ($_GET['add']))
{
	$add = $_GET['add'];
}

if (IsSet ($_POST['message']))
{
	$message = sql_addslashes($_POST['message']);
	$message = htmlspecialchars(strip_tags($message)); //remove html tags
}
if (IsSet ($_POST['name']))
{
	$name = sql_addslashes($_POST['name']);
	$name = htmlspecialchars(strip_tags($name)); //remove html tags
}
if (IsSet ($_POST['days']))
{
	$days = sql_addslashes($_POST['days']);
	$days = htmlspecialchars(strip_tags($days)); //remove html tags
}
if (IsSet ($_POST['public']))
{
	$public = $_POST['public'];
}
else
{
	$public = 0 ;
}

load_language($cmsdir . '/', 'sn_message'); //load language file

$table_message = $dbprefix . "m_message";
$date_format = $sas_config['dateformat'];
$error = 0;
$date = date("d-m-Y", mktime(0, 0, 0, date("m"), date("d") + $table_message[days], date("Y")));

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

	if ($message == "")
	{
		print stripslashes($sas_lang['message_module_nomessage']); //Error message when no message
		$error = 1;
	}
	elseif ($name == "")
	{
		print stripslashes($sas_lang['message_module_noname']); //Error message when no name
		$error = 1;
	}
	if ($error == 0)
	{
		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')");
		// 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'");

		print $sas_lang['message_module_added'];
	}
	print "<br><br><input type=\"button\" value=\"$sas_lang[goback]\" name=\"backbutton\" onClick=\"javascript:history.go(-1)\" class=\"backbutton\">";
}

else
{
	print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#00000\" width=\"100%\">";
	print "<td><center>" . $sas_config['message_add_text'] . "</center></td>";
	print "</table>";

	print "<TABLE align=\"center\" height=\"100\" cellspacing=\"0\" cellpadding=\"2\" id=\"dashed\" width=\"750\">
		<TR>
			<TD valign=\"top\">$welcometext
			<form name=\"mainform\" ACTION=\"index.php?section=$section&page=$page&add=yes\" METHOD=\"post\">
		<br>
		
		<TABLE cellspacing=\"0\" cellpadding=\"4\" border=\"0\">
		<TR>
			<TD width=25% id=\"text\" valign=\"top\" align=\"right\"><B>" . $sas_lang['message_module_text'] . ":</B></font></TD>
			<TD><TEXTAREA NAME=\"message\" ROWS=\"6\" COLS=\"50\" id=\"input\"></TEXTAREA></TD>
		</TR>
		<TR>
			<TD valign=center width=25% id=\"text\" valign=\"top\" align=\"right\"><B>" . $sas_lang['message_module_owner'] . ":</B></font></TD>
			<TD><INPUT TYPE=\"text\" NAME=\"name\" id=\"input\" size=\"40\"></TD>
		</TR>
		<TR>
			<TD valign=center width=25% id=\"text\" valign=\"top\" align=\"right\"><B>" . $sas_lang['message_module_days'] . ":</B></TD>
			<TD><INPUT TYPE=\"text\" NAME=\"days\" id=\"input\" size=\"10\"></TD>
		</TR>
		
		</TABLE>";

	if ($_SESSION['site'] == "protected")
	{
		print "<p><b>" . $sas_lang['message_module_is_public'] . "</b>  &nbsp;" . $sas_lang['yes'] . "";
		print "<input type=\"radio\" value=\"1\" name=\"public\" checked>";
		print "&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] ;
		print "<input type=\"radio\" name=\"public\" value=\"0\">";
	}

	print "	<br>
			<center>
			<INPUT TYPE=\"submit\" id=\"input\" value=\"" . $sas_lang['save'] . "\">
			</center>		
			</form>
		</TD>
	</TR>
	</TABLE>";
}
?>

