<?php

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

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

$table_message = $dbprefix . "m_message";

$date_format = $sas_config['dateformat'];

print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";

if ($_SESSION['site'] == "protected")
{
$query = "SELECT id, name, message, date_format(date, '%d-%m-%Y'), days AS Readable_Date 
			FROM $table_message 
			WHERE (todate >= current_date() OR days = 0)  AND public = 1
			ORDER BY date DESC";	
print "<td>" . $sas_config['message_view_text_prot'] . "</td>";
}
else
{
$query = "SELECT id, name, message, date_format(date, '%d-%m-%Y'), days AS Readable_Date 
			FROM $table_message 
			WHERE (todate >= current_date() OR days = 0)  AND public = 0
			ORDER BY date DESC";
print "<td>" . $sas_config['message_view_text'] . "</td>";
}

$result = mysql_query($query) or die_script($query, mysql_error());

mysql_query("DELETE from $table_message WHERE todate < current_date() AND days > 0"); //delete old entries

print "</table>";

$bgcolor = "E7E7EF";
print "<table border=\"0\" cellpadding=\"1\" cellspacing=\"2\" width=\"100%\">";
print "<tr>
           <td width=2%>&nbsp;</td>
           <td width=16%><b>&nbsp;" . $sas_lang['message_module_date'] . ":</b></td>
           <td width=59%><b>&nbsp;" . $sas_lang['message_module_text'] . ":</b></td>
           <td width=21%><b>" . $sas_lang['message_module_owner'] . ":</b></td>
       </tr>";
print "</table><br>";

while ($message_list = mysql_fetch_array($result))
{
	print "<table border=\"0\" cellpadding=\"1\" cellspacing=\"2\" width=\"100%\">";

	$date1 = strftime($date_format, $message_list[3]);

	print "<tr bgcolor=\"$bgcolor\">
	           <td width=2% align=center valign=top><img src='starnet/graphics/logfile.gif'></span></td>
	           <td width=16% valign=top>&nbsp;$message_list[3]";

	if ($message_list[4] > 0)
	{
		print "&nbsp;&nbsp;($message_list[4])";
	}

	print "</b></td>
	           <td width=59% valign=top>$message_list[2]</td>
	           <td width=21% valign=top>$message_list[1]</td>
	       </tr>";

	if ($bgcolor == "#FFFFFF")
	{
		$bgcolor = "#E7E7EF";
	}
	else
	{
		$bgcolor = "#FFFFFF";
	}
	print "</table>";
}
?>

