<?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.4): Fred Stuurman 
# Current coder & maintainer: Fred Stuurman (fc.stuurman@hccnet.nl)
############################################################################
# con_start.inc.php: last changed 21/08/2006 , version: 2.4.03
#                    by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: con_start.inc.php,v 1.1 2006/10/03 08:33:55 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['save']))
{
	$save = $_GET['save'];
}
if (IsSet ($_POST['fullname']))
{
	$fullname = $_POST['fullname'];
}
if (IsSet ($_POST['username']))
{
	$username = $_POST['username'];
}
if (IsSet ($_POST['password']))
{
	$password = $_POST['password'];
}
if (IsSet ($_POST['email']))
{
	$email = $_POST['email'];
}
if (IsSet ($_POST['newsiteemail']))
{
	$siteemail = $_POST['newsiteemail'];
}
if (IsSet ($_POST['neweditor']))
{
	$neweditor = $_POST['neweditor'];
}
if (IsSet ($_POST['newhighvisibility']))
{
	$newhighvisibility = $_POST['newhighvisibility'];
}
if (IsSet ($_POST['newtheme']))
{
	$newtheme = $_POST['newtheme'];
}
if (IsSet ($_POST['new_prot_theme']))
{
	$new_prot_theme = $_POST['new_prot_theme'];
}
if (IsSet ($_POST['newsitename']))
{
	$newsitename = $_POST['newsitename'];
}
if (IsSet ($_POST['startsection']))
{
	$startsection = $_POST['startsection'];
}
if (IsSet ($_POST['sessioncode']))
{
	$sessioncode = $_POST['sessioncode'];
}
if (IsSet ($_POST['siteurl']))
{
	$siteurl = $_POST['siteurl'];
}
if (IsSet ($_POST['serverpath']))
{
	$serverpath = $_POST['serverpath'];
}
if (IsSet ($_POST['userpath']))
{
	$userpath = $_POST['userpath'];
}
if (IsSet ($_POST['newlanguage']))
{
	$newlanguage = $_POST['newlanguage'];
}

if (IsSet ($_POST['newdateformat']))
{
	$newdateformat = $_POST['newdateformat'];
}
if (IsSet ($_POST['editor_rows']))
{
	$editor_rows = $_POST['editor_rows'];
}
if (IsSet ($_POST['num_pages']))
{
	$num_pages = $_POST['num_pages'];
}
if (IsSet ($_POST['file_permissions']))
{
	$file_permissions = $_POST['file_permissions'];
}

if (IsSet ($save))
{
	if ($save == "configuration")
	{
		mysql_query("UPDATE $table_configuration SET config_value='$newtheme' WHERE config_key='theme'");
		mysql_query("UPDATE $table_configuration SET config_value='$new_prot_theme' WHERE config_key='protected_theme'");
		mysql_query("UPDATE $table_configuration SET config_value='$newsitename' WHERE config_key='sitename'");
		mysql_query("UPDATE $table_configuration SET config_value='$startsection' WHERE config_key='startsection'");
		mysql_query("UPDATE $table_configuration SET config_value='$siteemail' WHERE config_key='email'");
		mysql_query("UPDATE $table_configuration SET config_value='$sessioncode' WHERE config_key='sessioncode'");
		if (IsSet ($_POST['newsletter_email']))
		{
			$newsletter_email = $_POST['newsletter_email']; //save the admin email addres of the newsletter module.
			mysql_query("UPDATE $table_configuration SET config_value='$newsletter_email' WHERE config_key='newsletter_admin_email'");
		}
		if (strrpos($siteurl, '/') != strlen($siteurl) - 1)
		{
			$siteurl .= '/';
		} //add last slash if not present
		mysql_query("UPDATE $table_configuration SET config_value='$siteurl' WHERE config_key='url'");
		mysql_query("UPDATE $table_configuration SET config_value='$serverpath' WHERE config_key='serverpath'");
		mysql_query("UPDATE $table_configuration SET config_value='$userpath' WHERE config_key='user_path'");
	}
	if ($save == "environment")
	{
		mysql_query("UPDATE $table_configuration SET config_value='$newlanguage' WHERE config_key='language'");
		//mysql_query("UPDATE $table_configuration SET config_value='$newsecuritymethod' WHERE config_key='securitymethod'");
		mysql_query("UPDATE $table_configuration SET config_value='$newdateformat' WHERE config_key='dateformat'");
		mysql_query("UPDATE $table_configuration SET config_value='$editor_rows' WHERE config_key='htmlarea_editor_rows'");
		mysql_query("UPDATE $table_configuration SET config_value='$num_pages' WHERE config_key='number_pupilpages'");
		mysql_query("UPDATE $table_configuration SET config_value='$file_permissions' WHERE config_key='file_permissions'");
	}
	if ($save == "personal")
	{
		$query = mysql_query("SELECT username FROM $table_users WHERE username = '$username' AND id != '$userid'");
		$results = mysql_num_rows($query);
		if ($results != '0') //an other user with this username exists, give error
		{
			print "<script language=\"Javascript\">
					   <!--
					   alert (\"" . $sas_lang['student_name_exists'] . "\");
					   window.location = 'index.php?option=configuration&suboption=personal' ;	
					   //-->
					   </script>"; //return to the user edit window.
		}
		else
		{
			if (($sas_config[use_encryption] == 1) AND ($password != "") AND ($password != "********")) //passwords are encrypted and not blank
			{
				$password = md5($password);
			}

			if (($password != "") AND ($password != "********")) //only save password when not empty.
			{
				mysql_query("UPDATE $table_users SET password='$password' WHERE id='$userid'");
			}

			mysql_query("UPDATE $table_users SET name='$fullname' WHERE id='$userid'");
			mysql_query("UPDATE $table_users SET username='$username' WHERE id='$userid'");
			mysql_query("UPDATE $table_users SET email='$email' WHERE id='$userid'");
			mysql_query("UPDATE $table_users SET editor='$neweditor' WHERE id='$userid'");
			mysql_query("UPDATE $table_users SET highvisibility='$newhighvisibility' WHERE id='$userid'");
		}
	}
}

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

print "<span class=\"heading\">" . $sas_lang['configuration'] . "<br></span>";
print "<span class=\"text\">" . $sas_lang['configuration_introduction'] . "</span>";

print "<p><table border=\"0\" width=\"100%\" cellpadding=\"4\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\">
            <tr>
              <td width=\"33%\" align=\"center\" valign=\"top\">
              <a href=\"index.php?option=configuration&suboption=configuration\"><img border=\"0\" src=\"graphics/cfg-settings.gif\" width=\"48\" height=\"48\"></a><br>
              <span class=link><a href=\"index.php?option=configuration&suboption=configuration\">" . $sas_lang['configuration2'] . "</a></span></td>
              <td width=\"33%\" align=\"center\" valign=\"top\">
              <a href=\"index.php?option=configuration&suboption=environment\"><img border=\"0\" src=\"graphics/cfg-environment.gif\" width=\"48\" height=\"48\"></a><br>
              <span class=link><a href=\"index.php?option=configuration&suboption=environment\">" . $sas_lang['environment'] . "</span></td>
              <td width=\"33%\" align=\"center\" valign=\"top\">
              <a href=\"index.php?option=configuration&suboption=personal\"><img border=\"0\" src=\"graphics/cfg-personal.gif\" width=\"48\" height=\"48\"></a><br>
              <span class=link><a href=\"index.php?option=configuration&suboption=personal\">" . $sas_lang['personalsettings'] . "</a></span></td>
            </tr>
            <tr>
              <td width=\"100%\" align=\"left\" valign=\"top\" colspan=\"3\"><br></td>
            </tr>
            <tr>
              <td width=\"33%\" align=\"center\" valign=\"top\">
              <a href=\"index.php?option=configuration&suboption=users\"><img border=\"0\" src=\"graphics/cfg-users.gif\" width=\"48\" height=\"48\"></a><br>
              <span class=link><a href=\"index.php?option=configuration&suboption=users\">" . $sas_lang['users'] . "</a></span></td>
              <td width=\"33%\" align=\"center\" valign=\"top\">
              <a href=\"index.php?option=configuration&suboption=teachers\"><img border=\"0\" src=\"graphics/cfg-teachers.gif\" width=\"48\" height=\"48\"></a><br>
              <span class=link><a href=\"index.php?option=configuration&suboption=teachers\">" . $sas_lang['teachers'] . "</span></td>
              <td width=\"33%\" align=\"center\" valign=\"top\">
              <a href=\"index.php?option=configuration&suboption=students\"><img border=\"0\" src=\"graphics/cfg-students.gif\" width=\"48\" height=\"48\"></a><br>
              <span class=link><a href=\"index.php?option=configuration&suboption=students\">" . $sas_lang['students'] . "</a></span></td>           
            </tr>
            <tr>
              <td width=\"100%\" align=\"left\" valign=\"top\" colspan=\"3\"><br></td>
            </tr>
            <tr>          
              <td width=\"33%\" align=\"center\" valign=\"top\">
              <a href=\"index.php?option=configuration&suboption=projects\"><img border=\"0\" src=\"graphics/projects.gif\" width=\"48\" height=\"48\"></a><br>
              <span class=link><a href=\"index.php?option=configuration&suboption=projects\">" . $sas_lang['student_projects'] . "</a></span></td>
              <td width=\"33%\" align=\"center\" valign=\"top\">
              <a href=\"index.php?option=configuration&suboption=alerts\"><img border=\"0\" src=\"graphics/cfg-alerts.gif\"></a><br>
              <span class=link><a href=\"index.php?option=configuration&suboption=alerts\">" . $sas_lang['alerts'] . "</a></span></td>
              <td width=\"33%\" align=\"center\" valign=\"top\">&nbsp;</td>
            </tr>
</table>";

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