<?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: Fred Stuurman (fc.stuurman@hccnet.nl)
# Comissioned by: Stadsdeel de Baarsjes, Amsterdam, Netherlands
#############################################################################
# admin.php: last changed 27/04/2005  , version: 2.3
#              by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: admin.php,v 1.1 2006/10/03 09:17:55 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['email']))
{
	$email = $_POST['email'];
}
if (IsSet ($_POST['email_text']))
{
	$email_text = $_POST['email_text'];
}
if (IsSet ($_POST['email_picture']))
{
	$email_picture = $_POST['email_picture'];
}
if (IsSet ($_POST['email_thankyou_text']))
{
	$email_thankyou_text = $_POST['email_thankyou_text'];
}
if (IsSet ($_POST['name']))
{
	$name = $_POST['name'];
}
if (IsSet ($_POST['sort']))
{
	$sort = $_POST['sort'];
}
if (IsSet ($_POST['description']))
{
	$description = $_POST['description'];
}
if (IsSet ($_POST['email_max_days']))
{
	$email_max_days = $_POST['email_max_days'];
}
if (IsSet ($_GET['edit_address']))
{
	$edit_address = $_GET['edit_address'];
}
if (IsSet ($_GET['save_address']))
{
	$save_address = $_GET['save_address'];
}
if (IsSet ($_GET['delete_address']))
{
	$delete_address = $_GET['delete_address'];
}
if (IsSet ($_GET['delete_email']))
{
	$delete_email = $_GET['delete_email'];
}

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

load_language('', 'sn_mailpage'); //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['email_module_addressees'] . "</a></span><p>";
print "<span class=link><a href=index.php?option=modulemanager&module=$module&modoption=config>" . $sas_lang['configuration'] . "</a></span><br><br>";
include ("interface/menuend.inc.php");
include ("interface/pagestart.inc.php");

$table_email_addresses = $dbprefix . "m_mail_address";
$table_email_message = $dbprefix . "m_mail_message"; // database voor opslaan mail

$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);

print "<span class=\"heading\">$modulename<br><br></span>";

if ($modoption == "saveconfig")
{
	mysql_query("UPDATE $table_configuration SET config_value='$email' WHERE config_key='email'");
	mysql_query("UPDATE $table_configuration SET config_value='$email_text' WHERE config_key='email_text'");
	mysql_query("UPDATE $table_configuration SET config_value='$email_thankyou_text' WHERE config_key='email_thankyou_text'");
	mysql_query("UPDATE $table_configuration SET config_value='$email_picture' WHERE config_key='email_picture'");
	print "<span class=\"heading\">$modulename<br><br></span>";
	print "<span class=\"text\">" . $sas_lang['email_module_saved'] . "</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\">";
	exit;
}

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

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

if (IsSet ($save_address))
{
	if ($save_address == "new")
	{
		mysql_query("INSERT INTO $table_email_addresses (id, name, description, email, welcometext, thankyoutext, sort)
			VALUES (NULL, '$name', '$description', '$email', '$email_text', '$email_thankyou_text', '$sort')");
	}
	else
	{
		mysql_query("UPDATE $table_email_addresses 
			SET email='$email' ,
			name='$name' ,
			description='$description' ,
			welcometext='$email_text' ,
			thankyoutext='$email_thankyou_text',
			sort='$sort'
			WHERE id='$save_address'");
	}
}

if (IsSet ($edit_address))
{
	print "<span class=\"text\">" . $sas_lang['email_module_change'] . "<p></span>";
	$query = "SELECT id, name, description, email, welcometext, thankyoutext, sort FROM $table_email_addresses WHERE id=$edit_address";
	$result = mysql_query($query) or die_script($query, mysql_error());
	$address_list = mysql_fetch_array($result);
	print "<FORM METHOD=\"POST\" NAME=\"form\" ACTION=\"index.php?option=modulemanager&module=$module&save_address=$edit_address\">
	         <table border=\"0\" cellpadding=\"2\">";
	print "  <tr><td><span class=text>" . $sas_lang['email_module_name'] . " </span></td></tr>
	         <tr><td><input type=\"text\" name=\"name\" size=\"40\" value=\"$address_list[1]\" class=\"textfield\"></td></tr>
	         <tr><td><span class=text>" . $sas_lang['email_module_email'] . " </span></td></tr>
	         <tr><td><input type=\"text\" name=\"email\" size=\"40\" value=\"$address_list[3]\" class=\"textfield\"></td></tr>
	         <tr><td><span class=text>" . $sas_lang['email_module_description'] . ":</span></td></tr>
	         <tr><td><input type=\"text\" name=\"description\" size=\"40\" value=\"$address_list[2]\" class=\"textfield\"></td></tr>
	         <tr><td><span class=text>" . $sas_lang['email_module_welcome_text'] . ":</span></td></tr>
	         <tr><td><textarea cols=\"70\" rows=\"4\" name=\"email_text\">" . $address_list[4] . "</textarea></td></tr>
	         <tr><td><span class=text>" . $sas_lang['email_module_thankyou_text'] . ":</span></td></tr>
	         <tr><td><textarea cols=\"70\" rows=\"4\" name=\"email_thankyou_text\">" . $address_list[5] . "</textarea></td></tr>
	         <tr><td><span class=text>" . $sas_lang['email_module_sort'] . " </span></td></tr>
	         <tr><td><input type=\"text\" name=\"sort\" size=\"4\" value=\"$address_list[6]\" class=\"textfield\"></td></tr>";
	print "</table>";
	print "\n<br><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 ($modoption == "add_address")
{
	print "<span class=\"text\">" . $sas_lang['email_module_add'] . "<p></span>";
	print "<FORM METHOD=\"POST\" NAME=\"form\" ACTION=\"index.php?option=modulemanager&module=$module&save_address=new\">
	         <table border=\"0\" cellpadding=\"2\">";
	print "  <tr><td><span class=text>" . $sas_lang['email_module_name'] . " </span></td></tr>
	         <tr><td><input type=\"text\" name=\"name\" size=\"40\" class=\"textfield\"></td></tr>
	         <tr><td><span class=text>" . $sas_lang['email_module_email'] . " </span></td></tr>
	         <tr><td><input type=\"text\" name=\"email\" size=\"40\" class=\"textfield\"></td></tr>
	         <tr><td><span class=text>" . $sas_lang['email_module_description'] . ":</span></td></tr>
	         <tr><td><input type=\"text\" name=\"description\" size=\"40\" class=\"textfield\"></td></tr>
	         <tr><td><span class=text>" . $sas_lang['email_module_welcome_text'] . ":</span></td></tr>
	         <tr><td><textarea cols=\"70\" rows=\"4\" name=\"email_text\"></textarea></tr>
	         <tr><td><span class=text>" . $sas_lang['email_module_thankyou_text'] . ":</span></td></tr>
	         <tr><td><textarea cols=\"70\" rows=\"4\" name=\"email_thankyou_text\"></textarea></tr>
	         <tr><td><span class=text>" . $sas_lang['email_module_sort'] . " </span></td></tr>
	         <tr><td><input type=\"text\" name=\"sort\" size=\"4\" class=\"textfield\"></td></tr>";
	print "</table>";
	print "\n<br><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 ($modoption == "config")
{
	$email_max_days = $sas_config['email_expiration_days'];

	print "<FORM METHOD=\"POST\" ACTION=\"index.php?option=modulemanager&module=$module&modoption=saveconfig\">";
	print "<span class=\"text\">" . $sas_lang['email_module_config'] . "<br><br>";
	//print $sas_lang['email_module_email']."</span><br><input type=text size=45 class=\"textfield\" name=\"email\" value=\"".$sas_config['email']."\"><br><br></span>";
	print "<span class=\"text\">" . $sas_lang['email_module_welcome_text'] . "<br>";
	print "<textarea cols=\"70\" rows=\"4\" name=\"email_text\">" . $sas_config['email_text'] . "</textarea><br><br>\n";
	print "<span class=\"text\">" . $sas_lang['email_module_thankyou_text'] . "<br>";
	print "<textarea cols=\"70\" rows=\"4\" name=\"email_thankyou_text\">" . $sas_config['email_thankyou_text'] . "</textarea><br><br>\n";
	print "</select>";
	print "<span class=\"text\">" . $sas_lang['email_module_picture'] . "<br>";
	print "<input type=text size=\"60\" class=\"textfield\" name=\"email_picture\" value=\"" . $sas_config['email_picture'] . "\"><p>";

	print "\n<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sas_lang[goback]\" name=\"backbutton\" 
			onClick=\"javascript:parent.location='index.php?option=modulemanager';\" class=\"backbutton\">";
	print "\n&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['save'] . "\" name=\"savebutton\" class=\"savebutton\">";
	print "</form>";
}
else
{
	print "<span class=\"text\">" . $sas_lang['email_module_header'] . "<br><br>";
	print "<p><table border=\"0\">
	       <tr>
	           <td width=\"55\" colspan=\"2\">&nbsp;</td>
	           <td width=\"200\" class=\"text\"><b>" . $sas_lang['email_module_name'] . "</b></td>
	           <td width=\"250\" class=\"text\"><b>" . $sas_lang['email_module_email'] . "</b></td>
	           <td class=\"text\"><b>" . $sas_lang['email_module_sort'] . "</b></td>
	       </tr>";
	$query = "SELECT id, name, description, email, sort FROM $table_email_addresses ORDER BY sort";
	$result = mysql_query($query) or die_script($query, mysql_error());
	while ($address_list = mysql_fetch_array($result))
	{
		print "<tr bgcolor=\"$bgcolor\">
					 <td><img border=\"0\" src=\"graphics/delete.gif\" alt=\"$sas_lang[delete]\" title=\"$sas_lang[delete]\" width=\"16\" height=\"16\" 
					 onClick=\"if(confirm('" . $sas_lang['email_module_delete'] . $address_list[1] . "')) parent.location='index.php?option=modulemanager&module=$module&delete_address=$address_list[0]';\"></td>
					 <td><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_address=$address_list[0]';\"></td>";

		print "<td class=\"text\"><a href=\"index.php?option=modulemanager&module=$module&edit_address=$address_list[0]\">$address_list[1]</a></td>
				 <td class=\"text\">$address_list[3]</td>
				 <td class=\"text\">$address_list[4]</td>
				 </tr>";
	}

	print "</table>";
	print "<p><img src=graphics/folder_closed.gif alt=\"" . $sas_lang['email_module_add'] . "\">
			<a href=$PHP_SELF?option=modulemanager&module=$module&modoption=add_address><span class=link>&nbsp;" . $sas_lang['email_module_add'] . "</span></a><br><br>";
	print "\n<br><input type=\"button\" value=\"&nbsp;&nbsp;&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");
?>
