<?php

#############################################################################
#                              Site@School
# Site@School is a website management system designed for schools.
#
# About Site@School:
# Original Idea: Mark de Haan (mark@starwave.nl)
# PHP coding & Design: Mark de Haan (mark@starwave.nl)
# Comissioned by: Stadsdeel de Baarsjes, Amsterdam, Netherlands
############################################################################
# admin.php: last changed 07/09/2005  version 2.4
#              by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: admin.php,v 1.1 2006/10/03 09:15:53 fstuurman Exp $
############################################################################
#                        LICENSE INFORMATION
# Copyright (C) 2002 - 2005 Municipality of Amsterdam, City District
#  'de Baarsjes', Amsterdam, the Netherlands.
#
# 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['deletepost']))
{
	$deletepost = $_GET['deletepost'];
}
if (IsSet ($_GET['publishpost']))
{
	$publishpost = $_GET['publishpost'];
}
if (IsSet ($_GET['modoption']))
{
	$modoption = $_GET['modoption'];
}
if (IsSet ($_POST['gbook_email']))
{
	$gbook_email = $_POST['gbook_email'];
}
if (IsSet ($_POST['gbook_publish']))
{
	$gbook_publish = $_POST['gbook_publish'];
}
if (IsSet ($_POST['gbook_max_items']))
{
	$gbook_max_items = $_POST['gbook_max_items'];
}
if (IsSet ($_GET[b]))
{
	$b = $_GET[b];
}
if (IsSet ($_GET[l]))
{
	$l = $_GET[l];
}

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

load_language('', 'sn_gbook'); //load language file
//if(file_exists("languages/".$language."/sn_gbook/".$language.".php")) 
//{
//include("languages/".$language."/sn_gbook/".$language.".php");
//} 
//else 
//{
//include("languages/EN/sn_gbook/EN.php");
//}

include ("interface/header.inc.php");
include ("interface/menubar.inc.php");
include ("interface/menustart.inc.php");
print "<span class=heading>" . $sas_lang['filemanager_menu'] . "</span><p>";
print "<span class=link><a href=index.php?option=modulemanager&module=$module>" . $sas_lang['manage'] . "</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");

$query = "SELECT name FROM $table_modules WHERE id='$module'";
$result = mysql_query($query) or die_script($query, mysql_error());
$modulename = mysql_result($result, 0);
unset ($query);
unset ($result);

$query = "SELECT dbtables FROM $table_modules WHERE location='sn_gbook'"; // getting the table names
$result = mysql_query($query) or die_script($query, mysql_error());
$moduletables = mysql_result($result, 0);
unset ($query);
unset ($result);
$moduletables = explode(",", $moduletables);
$table_gbook = "$moduletables[0]";

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

if (IsSet ($publishpost))
{
	mysql_query("UPDATE $table_gbook SET initial = '1' WHERE id='$publishpost'");
}

if ($modoption == "saveconfig")
{
	mysql_query("UPDATE $table_configuration SET config_value='$welcometext' WHERE config_key='gbook_welcome_text'");
	mysql_query("UPDATE $table_configuration SET config_value='$gbook_email' WHERE config_key='gbook_email'");
	mysql_query("UPDATE $table_configuration SET config_value='$gbook_max_items' WHERE config_key='gbook_max_items'");
	mysql_query("UPDATE $table_configuration SET config_value='$gbook_publish' WHERE config_key='gbook_check_before_post'");

	print "<span class=\"heading\">$modulename " . $sas_lang['configuration'] . "<br><br></span>";
	print $sas_lang['gbook_module_saved'] . "";
	exit;
}

if ($modoption == "configuration")
{
	$gbook_email = $sas_config['gbook_email'];
	$gbook_max_items = $sas_config['gbook_max_items'];

	print "<span class=\"heading\">$modulename " . $sas_lang['configuration'] . "<br><br></span>";
	print "<FORM METHOD=\"POST\" ACTION=\"index.php?option=modulemanager&module=$module&modoption=saveconfig\">
			<br><span class=\"text\">" . $sas_lang['gbook_module_welcome_text'] . "<br>";
	print "<textarea cols=\"70\" rows=\"8\" name=\"welcometext\">" . $sas_config['gbook_welcome_text'] . "</textarea><br><br>\n";
	print "</select>";

	print "<span class=\"text\">" . $sas_lang['gbook_module_email_alert'] . "&nbsp;";
	print "<input type=\"text\" size=35 class=\"textfield\" name=\"gbook_email\" value=\"" . $sas_config['gbook_email'] . "\"><br><br>";
	print "<span class=\"text\">" . $sas_lang['gbook_module_max_items'] . ":&nbsp;";
	print "<input type=\"text\" size=5 class=\"textfield\" name=\"gbook_max_items\" value=\"" . $sas_config['gbook_max_items'] . "\"><br><br>";
	//print "<span class=\"text\">".$sas_lang['gbook_module_publish_directly'].":&nbsp;";

	//print "<span class=text>".$sas_lang['yes']."</span>&nbsp;";
	//	if($sas_config['gbook_check_before_post'] == "0")
	//	{
	//		print "<input type=\"radio\" value=\"0\" name=\"gbook_publish\" checked>&nbsp;";
	//		print "<span class=text>&nbsp;&nbsp;&nbsp; ".$sas_lang['no']."</span>&nbsp;";
	//		print "<input type=\"radio\" name=\"gbook_publish\" value=\"1\"><br><br>";
	//	}
	//	else
	//	{
	//		print "<input type=\"radio\" value=\"0\" name=\"gbook_publish\">&nbsp;";
	//		print "<span class=text>&nbsp;&nbsp;&nbsp; ".$sas_lang['no']."</span>&nbsp;";
	//		print "<input type=\"radio\" name=\"gbook_publish\" value=\"1\" checked><br><br>";
	//	}

	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>";
}
else
{
	print "<span class=\"heading\">$modulename<br><br></span>";

	if ($b == "")
	{
		$b = 1;
		$l = $sas_config['gbook_max_items'];
	}

	$result = mysql_query("SELECT * FROM $table_gbook");
	$aantal = mysql_num_rows($result); //number of gbook entries
	$limit_begin = $b -1;

	$query = "SELECT id, name, email, homepage, date, date_format(date, '%d-%m-%Y  %H:%i') AS Readable_Date, message, initial FROM $table_gbook ORDER BY date DESC LIMIT $limit_begin,$sas_config[gbook_max_items]";
	$result = mysql_query($query) or die_script($query, mysql_error());

	$pagtot = ceil($aantal / $sas_config['gbook_max_items']); //number of pages
	if ($b == 1)
	{
		$pag = 1;
	} //page 1
	else
	{
		$pag = $l / $sas_config['gbook_max_items']; //different as page 1
	}

	if ($aantal < $l)
	{
		$l = $aantal;
	} //less records than the number per page

	$low = $b - $sas_config['gbook_max_items'];

	if ($b > $sas_config['gbook_max_items']) //we have more than one page
	{
		$high = $b -1;
		$previous_page = "<a STYLE=\"color: blue ; font-size: 12\" href=\"index.php?option=modulemanager&module=$module&b=$low&l=$high\">" .
		$sas_lang['gbook_module_previous_page'] . "</a>";
	}
	else
	{
		$previous_page = ''; //no previous page
	}

	if ($aantal > $l) //number of records biggter than $l
	{
		$low = $b + $sas_config['gbook_max_items']; //$b + number per page
		$high = $l + $sas_config['gbook_max_items']; //$l + number per page
		$next_page = "<a STYLE=\"color: blue ; font-size: 12\" href=\"index.php?option=modulemanager&module=$module&b=$low&l=$high\">" .
		$sas_lang['gbook_module_next_page'] . "</a>";
	}
	else
	{
		$next_page = ''; //no next page
	}

	while ($gbook_list = mysql_fetch_array($result))
	{
		$gbook_message = str_replace("\n", "<br>\n", "$gbook_list[6]");
		$string = htmlentities($gbook_message);

		print "<table width=100% border=\"0\"><span class=text><tr>
					<td width='10%'><font size=2> <b>" . $sas_lang['gbook_module_name'] . " </b></td>
					<td><font size=2> $gbook_list[1]<br></td>
					</tr><tr>
					<td><font size=2> <b>" . $sas_lang['email'] . ": </b></td>
					<td><font size=2> <a href=mailto:$gbook_list[2]>$gbook_list[2]</a><br></td>
					</tr><tr>
					<td><font size=2> <b>" . $sas_lang['gbook_module_website'] . " </b></td>
					<td><font size=2> <a href=$gbook_list[3]>$gbook_list[3]</a><br></td>
					</tr><tr>
					<td><font size=2> <b>" . $sas_lang['gbook_module_date'] . " </b></td>
					<td><font size=2> $gbook_list[5]<br></td>
					</tr><tr>
					<td valign=\"top\"><font size=2> <b>" . $sas_lang['gbook_module_text'] . "</b></td>
					<td><font size=2> $string<br></td>
					</tr><tr>
					<td><font size=2> <a href=index.php?option=modulemanager&module=$module&deletepost=$gbook_list[0]>
					<font color=blue><b>[" . $sas_lang['delete'] . "]</a></font></b><br></td>";

		//if($gbook_list[7] == 0)
		//{
		//print "	<td><font size=2> <a href=index.php?option=modulemanager&module=$module&publishpost=$gbook_list[0]>
		//	<font color=blue><b>[".$sas_lang['gbook_module_publish']."]</a></font></b></td>";
		//}
		print "</tr></table><hr></span>";
	}

	print "<table width='600' border=\"0\"><tr>
	       <td width='28%' align=\"left\">$previous_page&nbsp;</td>
	       <td width='44%' align=\"center\">&nbsp;</td>
	       <td width='28%' align=\"right\">&nbsp$next_page</td>
	       </tr></table>";

	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");
?>
