<?php

#############################################################################
#           			                   Site@School
# Site@School is a website management system designed for primary schools.
#
# About Site@School:
# Comissioned by: City District 'de Baarsjes', Amsterdam, Netherlands
# Original idea, coding (version 1.0) and design : Mark de Haan (mark@starwave.nl)
# Ideas, improvements, expansions (version 1.1 - 2.3): Fred Stuurman 
# Current coder & maintainer: Fred Stuurman (fc.stuurman@hccnet.nl)
############################################################################
# con_environment.php: last changed 30/11/2004  , version: 2.3
#                      by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: con_configuration.inc.php,v 1.1 2006/10/03 08:33:55 fstuurman Exp $
############################################################################
#                        LICENSE INFORMATION
# Copyright (C) 2002, 2003, 2004 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");
}

include ("interface/header.inc.php");
include ("interface/menubar.inc.php");
include ("interface/menustart.inc.php");
include ("interface/menuend.inc.php");
include ("interface/pagestart.inc.php");
if (IsSet ($_GET['modoption']))
{
	$modoption = $_GET['modoption'];
}
if (IsSet ($_GET['theme']))
{
	$theme = $_GET['theme'];
}
if (IsSet ($_POST['content']))
{
	$content = $_POST['content'];
}

if (substr("$access", 4, 1) == "0") //bit 5 off the accessrights
{
	print "<span class=\"heading\">" . $sas_lang['noaccess'] . "<br></span>";
	print "<span class=\"text\">" . $sas_lang['noaccess_introduction'] . "</span><br><br><br>";
	include ("interface/pageend.inc.php");
	include ("interface/footer.inc.php");
	exit;
}

if ($modoption == "savecss")
{
	$filename = "themes/$theme/style.css";
	$handle = fopen($filename, "w");
	fwrite($handle, $content);
	fclose($handle);
}

if ($modoption == "editcss")
{
	$editor_rows = $sas_config['htmlarea_editor_rows'];

	print "<FORM METHOD=\"POST\" ACTION=\"index.php?option=configuration&suboption=configuration&modoption=savecss&theme=$theme\">
	<TABLE class=\"ToolBar\" id=\"idToolbar\" cellSpacing=\"0\" cellPadding=\"0\"  width=\"600\" border=\"1\">
	<TBODY>
	<TR style=\"background:ButtonFace\">
	<TD colSpan=18 height=\"28\" align=\"center\">";

	$filename = "themes/$theme/style.css";
	$handle = fopen($filename, "r");
	$contents = fread($handle, filesize($filename));
	fclose($handle);

	print "<span class=text>CSS Editor for theme: $theme/style.css</span>
			</TR><TR vAlign=center><td>";

	print "<textarea id=\"content\"  style=\"font-family:courier; width:825;\" name=\"content\" rows=\"$editor_rows\">";
	print wordwrap("$contents");
	print "</textarea></td><tr></table>
	       <br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['cancel'] . "\" name=\"backbutton\" onClick=\"javascript:parent.location='index.php?option=configuration&suboption=configuration';\" class=\"backbutton\">";
	print "&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['save'] . "\" name=\"savebutton\" class=\"savebutton\"><br><br></form>";

	include ("interface/pageend.inc.php");
	include ("interface/footer.inc.php");
	exit;
}

print "<span class=\"heading\">" . $sas_lang['configuration2'] . "<br></span>";
print "<span class=\"text\">" . $sas_lang['settings_introduction'] . "</span><br><br>";
print "<FORM METHOD=\"POST\" NAME=\"form\" ACTION=\"index.php?option=configuration&save=configuration\"><span class=\"text\">";

$theme = $sas_config['theme'];

$custompath = $serverpath . "/themes";
if (is_dir($custompath))
{
	print "" . $sas_lang['theme'] . "<br><select size=\"1\" name=\"newtheme\">\n";
	$dir_handle = @ opendir($custompath);
	while ($file = readdir($dir_handle))
	{
		if ($file != ".." AND $file != "." AND $file != "/")
		{
			if ($file == $theme)
			{
				echo "<option selected value=\"$file\">$file</option>";
			}
			else
			{
				echo "<option value=\"$file\">$file</option>";
			}
		}

	}
	closedir($dir_handle);
	print "</select>";
	if (file_exists("themes/$theme/style.css"))
	{
		print "&nbsp;&nbsp;<input type=\"button\" name=\"button\" onClick=\"javascript:parent.location='index.php?option=configuration&suboption=configuration&modoption=editcss&theme=$theme';\" name=\"button\" value=\"Edit CSS\">";
	}
	print "&nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['theme_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"><p>";
}
else
{
	print "<input type=\"hidden\" name=\"newtheme\" value=\"$theme\">
			 <span class=\"error\">Unable to open $custompath</span><p>";
}

$prot_theme = $sas_config['protected_theme'];
$serverpath2 = $sas_config['user_path'];
$serverpath1 = $sas_config['serverpath'];
$siteemail = $sas_config['email'];

if (is_dir($custompath))
{
	print "" . $sas_lang['theme'] . " " . $sas_lang['protected_area'] . "<br><select size=\"1\" name=\"new_prot_theme\">\n";
	$dir_handle = @ opendir($custompath);
	while ($file = readdir($dir_handle))
	{
		if ($file != ".." AND $file != "." AND $file != "/")
		{
			if ($file == $prot_theme)
			{
				echo "<option selected value=\"$file\">$file</option>";
			}
			else
			{
				echo "<option value=\"$file\">$file</option>";
			}
		}

	}
	closedir($dir_handle);
	print "</select>";
	if (file_exists("themes/$prot_theme/style.css"))
	{
		print "&nbsp;&nbsp;<input type=\"button\" onClick=\"javascript:parent.location='index.php?option=configuration&suboption=configuration&modoption=editcss&theme=$prot_theme';\" name=\"button\" value=\"Edit CSS\">";
	}
	print "&nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['theme_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\">";

}
else
{
	print "<input type=\"hidden\" name=\"new_prot_theme\" value=\"$prot_theme\">";
}

print "<p>" . $sas_lang['sitetitle'] . "<br><input tabindex=\"1\" type=text size=60 class=\"textfield\" name=\"newsitename\" value=\"$sitename\">
	&nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['sitetitle_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\">";
print "<p>" . $sas_lang['site_email'] . "<br><input tabindex=\"1\" type=text size=60 class=\"textfield\" name=\"newsiteemail\" value=\"$siteemail\">
	&nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['email_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"><br><br>";

$query = "SELECT id FROM $table_modules WHERE location = 'sn_newsletter'";
$result = mysql_query($query) or die_script($query, mysql_error()); //Do we have newsletter module installed.
$RecordCount = mysql_num_rows($result);
if ($RecordCount > 0)
{
	$query = "SELECT config_value FROM $table_configuration WHERE config_key='newsletter_admin_email'";
	$result = mysql_query($query) or die_script($query, mysql_error());
	$admin_email = mysql_result($result, 0);
	unset ($query);
	unset ($result);
	if (file_exists("languages/" . $language . "/sn_newsletter/" . $language . ".php"))
	{
		include ("languages/" . $language . "/sn_newsletter/" . $language . ".php");
	}
	else
	{
		include ("languages/EN/sn_newsletter/EN.php");
	}
	print "<span class=text>" . $sas_lang['newsletter_module_email_admin'] . " (" . $sas_lang['newsletter_module_newsletter'] . ")</span><br>
				 <input type=\"text\" name=\"newsletter_email\" size=\"60\" value=\"$admin_email\" class=\"textfield\">
				 &nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['email_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"><br><br>";
}

print "" . $sas_lang['startsection'] . "<br><select tabindex=\"2\" size=\"1\" name=\"startsection\">\n"; // WYSIWYG editor selection

$query = "SELECT id, name FROM $table_sections WHERE invisible != 'yes'";
$result = mysql_query($query) or die_script($query, mysql_error());
while ($startsection_list = mysql_fetch_array($result))
{
	if ($startsection_list[0] == $sas_config['startsection'])
	{
		print "<option selected value=\"$startsection_list[0]\">$startsection_list[1]</option>\n";
	}
	else
	{
		print "<option value=\"$startsection_list[0]\">$startsection_list[1]</option>\n";
	}
}
print "</select>&nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['startsection_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"><br><br>";
print "" . $sas_lang['sessioncode'] . "<br><input tabindex=\"3\" type=text size=40 class=\"textfield\" name=\"sessioncode\" value=\"$check_sessioncode\">&nbsp;
		<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['sessioncode_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"><br><br>";
print "" . $sas_lang['URL_location'] . "<br><input tabindex=\"4\" type=text size=60 class=\"textfield\" name=\"siteurl\" value=\"$site_url\">&nbsp;	
		<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['URL_location_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"><br><br>";
print $sas_lang['serverpath'] . "<br><input tabindex=\"5\" type=text size=60 class=\"textfield\" name=\"serverpath\" value=\"$serverpath1\">
       <input tabindex=\"5\" type=text size=20 class=\"textfield\" name=\"userpath\" value=\"$serverpath2\">
       &nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('$sas_lang[serverpath_tip]','CCDAEC')\"; ONMOUSEOUT=\"kill()\"><br><br>";
print "<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['cancel'] . "\" name=\"backbutton\" 
		onClick=\"javascript:parent.location='index.php?option=configuration';\" class=\"backbutton\">";
print "&nbsp;<input tabindex=\"6\" type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['save'] . "\" name=\"savebutton\" class=\"savebutton\">";
print "</form>";

include ("interface/pageend.inc.php");
include ("interface/footer.inc.php");
?>
