<?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 08:57:05 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['ads_email']))
{
	$ads_email = $_POST['ads_email'];
}
if (IsSet ($_POST['ads_max_days']))
{
	$ads_max_days = $_POST['ads_max_days'];
}
if (IsSet ($_POST['ads_publish']))
{
	$ads_publish = $_POST['ads_publish'];
}
if (IsSet ($_GET['modoption']))
{
	$modoption = $_GET['modoption'];
}
if (IsSet ($_GET['deletepost']))
{
	$deletepost = $_GET['deletepost'];
}
if (IsSet ($_GET['publishpost']))
{
	$publishpost = $_GET['publishpost'];
}

load_language('', 'sn_ads'); //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['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_ads'"; // 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_adtext = "$moduletables[0]";

$date_format = $sas_config['dateformat'];

if (IsSet ($deletepost))
{
	mysql_query("DELETE from $table_adtext WHERE ad_id='$deletepost'");
}

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

if ($modoption == "saveconfig")
{
	if (!get_magic_quotes_gpc())
	{
		$welcometext = addslashes($_POST['welcometext']);
	}
	else
	{
		$welcometext = $_POST['welcometext'];
	}
	if (!get_magic_quotes_gpc())
	{
		$disclaimer = addslashes($_POST['disclaimer']);
	}
	else
	{
		$disclaimer = $_POST['disclaimer'];
	}
	mysql_query("UPDATE $table_configuration SET config_value='$welcometext' WHERE config_key='ads_welcome_text'");
	mysql_query("UPDATE $table_configuration SET config_value='$disclaimer' WHERE config_key='ads_disclaimer'");
	mysql_query("UPDATE $table_configuration SET config_value='$ads_email' WHERE config_key='ads_email'");
	mysql_query("UPDATE $table_configuration SET config_value='$ads_max_days' WHERE config_key='ads_expiration_days'");
	mysql_query("UPDATE $table_configuration SET config_value='$ads_publish' WHERE config_key='ads_check_before_post'");
	print "<span class=\"heading\">$modulename $sas_lang[configuration]<br><br></span>";
	print "$sas_lang[ads_module_saved]";
	exit;
}

if ($modoption == "configuration")
{
	$welcometext = $sas_config['ads_welcome_text'];
	$disclaimer = $sas_config['ads_disclaimer'];
	$ads_email = $sas_config['ads_email'];
	$ads_max_days = $sas_config['ads_expiration_days'];

	print "<span class=\"heading\">$modulename " . $sas_lang['configuration'] . "<br><br></span>";
	print "<FORM METHOD=\"POST\" ACTION=\"index.php?option=modulemanager&module=$module&modoption=saveconfig\">
		 <span class=\"text\">" . $sas_lang['ads_module_header2'] . "<br>";
	print "<textarea cols=\"70\" rows=\"8\" name=\"welcometext\">$welcometext</textarea><br><br>\n";
	print "</select>";
	print $sas_lang['ads_module_header1'] . "<br><textarea cols=\"70\" rows=\"8\" name=\"disclaimer\">$disclaimer</textarea><br>\n";
	print "</select><br>";
	print "<span class=\"text\">" . $sas_lang['ads_module_email_alert'] . "&nbsp;";
	print "<input type=\"text\" size=60 class=\"textfield\" name=\"ads_email\" value=\"$ads_email\"><p>";
	print "<span class=\"text\">" . $sas_lang['ads_module_expiration_days'] . "&nbsp;";
	print "<input type=\"text\" size=5 class=\"textfield\" name=\"ads_max_days\" value=\"$ads_max_days\"><p>";
	//print "<span class=\"text\">".$sas_lang['ads_module_publish_directly'].":&nbsp;";

	//print "<span class=text>".$sas_lang['yes']."</span>&nbsp;";

	//	if($sas_config['ads_check_before_post'] == "0")
	//	{
	//		print "<input type=\"radio\" value=\"0\" name=\"ads_publish\" checked>&nbsp;";
	//		print "<span class=text>&nbsp;&nbsp;&nbsp; ".$sas_lang['no']."</span>&nbsp;";
	//		print "<input type=\"radio\" name=\"ads_publish\" value=\"1\"><br><br>";
	//	}
	//	else
	//	{
	//		print "<input type=\"radio\" value=\"0\" name=\"ads_publish\">&nbsp;";
	//		print "<span class=text>&nbsp;&nbsp;&nbsp; ".$sas_lang['no']."</span>&nbsp;";
	//		print "<input type=\"radio\" name=\"ads_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\">" . $sas_lang['manage'] . " $modulename<br><br></span>";
	$query = "SELECT ad_id, email, ad_text, UNIX_TIMESTAMP(date), name, initial FROM $table_adtext ORDER BY date DESC";
	$result = mysql_query($query) or die_script($query, mysql_error());

	while ($ads_list = mysql_fetch_array($result))
	{
		$ads_message = str_replace("\n", "<br>\n", "$ads_list[2]");
		$date1 = strftime($date_format, $ads_list[3]);

		print "<table width=100% border=\"0\"><span class=text><tr>
			   <td width='10%'><font size=2> <b>" . $sas_lang['ads_module_name'] . "</b></td>
			   <td><font size=2>$ads_list[4]<br></td>
			   </tr><tr>
			   <td><font size=2> <b>" . $sas_lang['ads_module_email'] . "</b></td>
			   <td><font size=2>$ads_list[1]<br></td>
			   </tr>
			   <tr>
			
			   <td><font size=2> <b>" . $sas_lang['date'] . "</b></td>
			   <td><font size=2>$date1<br></td>
			   </tr>
			   <tr>
			   <td valign=top><font size=2> <b>" . $sas_lang['ads_module_text'] . "</b></td>
			   <td><font size=2>$ads_message<br></td>
			   </tr>
			   <td><font size=2> <a href=index.php?option=modulemanager&module=$module&deletepost=$ads_list[0]>
			   <font color=blue><b>[" . $sas_lang['delete'] . "]</a></font></b><br></td>";

		//if($ads_list[5] == 0)
		//{
		//print "	<td><font size=2> <a href=index.php?option=modulemanager&module=$module&publishpost=$ads_list[0]>
		//	<font color=blue><b>[".$sas_lang['ads_module_publish']."]</a></font></b></td>";
		//}
		print "</tr></table><hr></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");
?>
