<?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_user.inc.php: last changed 04/10/2006 2.4.10
#                   by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: con_users.inc.php,v 1.2 2006/10/15 19:08:53 fstuurman Exp $
############################################################################
#                        LICENSE INFORMATION
# Copyright (C) 2002 - 2006 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");
}
?>
<script language="JavaScript" type="text/javascript">
function checkinput ( form )
{
    if (form.fullname.value == "") 
	{
    alert( "<?php echo $sas_lang['input_error'] ?>" );
    form.fullname.focus();
    return false ;
    }
    if (form.username.value == "") 
	{
    alert( "<?php echo $sas_lang['input_error'] ?>" );
    form.username.focus();
    return false ;
    }
    if (form.password.value == "") 
	{
    alert( "<?php echo $sas_lang['input_error'] ?>" );
    form.password.focus();
    return false ;
    }
  return true ;
}

function resetform(form)
{
    for(var i=0; i < form.elements.length; i++)
    {
     var elementType = form.elements[i].type;
       if(elementType != 'button' && elementType != 'submit' && elementType != 'radio' && elementType != 'select-multiple')
        form.elements[i].value = '';
       else if(elementType == 'radio')
        form.elements[i].checked = false;
    }
}

</script>
<?php

if (IsSet ($_GET['deleteuser']))
{
	$deleteuser = $_GET['deleteuser'];
}
if (IsSet ($_GET['saveuser']))
{
	$saveuser = $_GET['saveuser'];
}
if (IsSet ($_GET['copyuser']))
{
	$copyuser = $_GET['copyuser'];
}
if (IsSet ($_GET['newuser']))
{
	$newuser = $_GET['newuser'];
}
if (IsSet ($_GET['user']))
{
	$user = $_GET['user'];
}

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['editor']))
{
	$editor = $_POST['editor'];
}
if (IsSet ($_POST['highvisibility']))
{
	$highvisibility = $_POST['highvisibility'];
}
if (IsSet ($_POST['m_access']))
{
	$m_access = $_POST['m_access'];
}
if (IsSet ($_POST['sections']))
{
	$sections = $_POST['sections'];
}

if (($sas_config[use_encryption] == 1) AND ($password != "") AND ($password != "********")) //passwords are encrypted and not blank
{
	$password = md5($password);
}

if (IsSet ($_POST['access_1']))
{
	$new_access = $_POST['access_1'] . $_POST['access_2'] . $_POST['access_3'] . $_POST['access_4'] . $_POST['access_5'] . $_POST['access_6'] . $_POST['access_7'] . $_POST['access_8'] . $_POST['access_9'] . $_POST['access_10'] . $_POST['access_11'] . $_POST['access_12'] . $_POST['access_13'] . $_POST['access_14'] . ",";
}

if (IsSet ($access_1))
{
	$new_access = "$access_1" . "$access_2" . "$access_3" . "$access_4" . "$access_5" . "$access_6" . "$access_7" . "$access_8" . "$access_9" . "$access_10" . "$access_11" . "$access_12" . "$access_13" . "$access_14" . ",";
}
$i = 0;
while ($i < count($m_access)) //loop through the module access bits
{
	$new_access .= $m_access[$i];
	$i++;
}

if (IsSet ($deleteuser))
{
	$result = mysql_query("SELECT username from $table_users WHERE id = '$deleteuser'");
	$username_to_delete = mysql_result($result, 0);
	$result = mysql_query("SELECT username FROM $table_users WHERE id = '$_SESSION[userid]'");
	$user_loggedin = mysql_result($result, 0);
	if ($user_loggedin != $username_to_delete)
	{
		mysql_query("DELETE from $table_users WHERE id = '$deleteuser'");
	}
	else
	{
		print "<script language=\"Javascript\">
					   <!--
					   alert (\"" . $sas_lang['user_delete_error'] . "\")
					   //-->
					   </script>";
	}
}

if (IsSet ($saveuser))
{

	if ($saveuser == "copy")
	{
		$result = mysql_query("SELECT access, highvisibility, editor, sections FROM $table_users WHERE id = '$username'");
		$user_list = mysql_fetch_array($result);
		mysql_query("INSERT INTO $table_users (access, highvisibility, editor, type, sections) 
					VALUES ('$user_list[0]', '$user_list[1]', '$user_list[2]', '20', '$user_list[3]')");
		$user = mysql_insert_id();
	}
	elseif ($saveuser == "new")
	{
		$query = mysql_query("SELECT username FROM $table_users WHERE username = '$username'");
		$results = mysql_num_rows($query);

		if ($results != '0') //username already exists, give error   
		{
			print "<script language=\"Javascript\">
						   <!--
						   alert (\"" . $sas_lang['student_name_exists'] . "\");
						   history.go(-1) ;
						   //-->
						   </script>";
		}
		else
		{
			mysql_query("INSERT INTO $table_users (name, username, password, email, access, highvisibility, editor, type, sections) 
									 VALUES ('$fullname', '$username',  '$password',  '$email', '$new_access', '$highvisibility', '$editor', '20', '$sections')");
		}
	}
	else
	{
		$query = mysql_query("SELECT username FROM $table_users WHERE username = '$username' AND id != '$saveuser'");
		$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=users&user=$saveuser' ;	
						   //-->
						   </script>"; //return to the user edit window.
		}
		else
		{
			mysql_query("UPDATE $table_users SET name='$fullname' WHERE id='$saveuser'");
			mysql_query("UPDATE $table_users SET username='$username' WHERE id='$saveuser'");
			if (($password != "") AND ($password != "********")) //only save password when not empty.
			{
				mysql_query("UPDATE $table_users SET password='$password' WHERE id='$saveuser'");
			}
			mysql_query("UPDATE $table_users SET email='$email' WHERE id='$saveuser'");
			mysql_query("UPDATE $table_users SET access='$new_access' WHERE id='$saveuser'");
			mysql_query("UPDATE $table_users SET editor='$editor' WHERE id='$saveuser'");
			mysql_query("UPDATE $table_users SET highvisibility='$highvisibility' WHERE id='$saveuser'");
			mysql_query("UPDATE $table_users SET sections='$sections' WHERE id='$saveuser'");
		}
	}
}

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 (substr("$access", 6, 1) == "0") //bit 7 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;
}

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

if (IsSet ($copyuser))
{
	print "<span class=\"text\">" . $sas_lang['copyuser_introduction'] . "</span><br><br>";
	print "<FORM METHOD=\"POST\" NAME=\"form\" ACTION=\"index.php?option=configuration&suboption=users&saveuser=copy\" onsubmit=\"return checkinput(this);\">";

	$query = "SELECT id, name FROM $table_users WHERE type > 19 ORDER BY name";
	$result = mysql_query($query) or die_script($query, mysql_error());
	print "<select class=\"text\" name=\"username\">\n";
	while ($users_list = mysql_fetch_array($result))
	{
		print "<option value=\"$users_list[0]\">$users_list[1]</option>\n";
	}
	print "</select>\n<p><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['goback'] . "\" name=\"backbutton\" 
			onClick=\"javascript:history.go(-1)\" class=\"backbutton\">";
	print "&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['copyuser'] . "\" name=\"savebutton\" class=\"savebutton\">";
	print "</form>";
	exit;
}

if (IsSet ($newuser))
{
	print "<span class=\"text\">" . $sas_lang['newuser_introduction'] . "</span><br><br>";
	print "<FORM METHOD=\"POST\" NAME=\"form\" ACTION=\"index.php?option=configuration&suboption=users&saveuser=new\" onsubmit=\"return checkinput(this);\">";
	print "<table cellpadding=\"5\" cellspacing=\"2\"><tr><td>
	       <span class=text>" . $sas_lang['fullname'] . ": (*)</span></td>
	       <td><input type=\"text\" name=\"fullname\" size=\"40\" class=\"textfield\">&nbsp;
		   <img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['fullname_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";
	print "<tr><td><span class=\"text\">" . $sas_lang['username'] . ": (*)</span></td>
	        <td><input type=\"text\" name=\"username\" size=\"20\" class=\"textfield\">&nbsp;
			<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['username_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";
	print "<tr><td><span class=\"text\">" . $sas_lang['password'] . ": (*)</span></td>
	        <td><input type=\"text\" name=\"password\" size=\"20\" class=\"textfield\">&nbsp;
			<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['password_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\">
	        <span class=\"text\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $sas_lang['required_fields'] . "</span></td></tr>";
	print "<tr><td><span class=\"text\">" . $sas_lang['email'] . ":</span></td>
	        <td><input type=\"text\" name=\"email\" size=\"60\" class=\"textfield\">&nbsp;
			<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['email_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";
	print "<tr><td><span class=\"text\">" . $sas_lang['editor'] . ":</span></td>
	       <td><span class=\"text\"><select size=\"1\" name=\"editor\">"; // WYSIWYG editor selection
	$query = "SELECT id, name FROM $table_editors";
	$result = mysql_query($query) or die_script($query, mysql_error());
	while ($editor_list = mysql_fetch_array($result))
	{
		if ($editor_list[0] == $_SESSION['editor'])
		{
			print "<option selected value=\"$editor_list[0]\">$editor_list[1]</option>\n";
		}
		else
		{
			print "<option value=\"$editor_list[0]\">$editor_list[1]</option>\n";
		}
	}

	print "</select>&nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['editor_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";

	print "<tr><td><span class=\"text\">" . $sas_lang['high_visibility'] . ":</span></td>";
	print "<td><span class=\"text\">" . $sas_lang['yes'];
	if ($highvisibility == "1")
	{
		print "<input type=\"radio\" value=\"1\" name=\"highvisibility\" checked>";
		print "&nbsp;&nbsp;&nbsp; " . $sas_lang['no'];
		print "<input type=\"radio\" name=\"highvisibility\" value=\"0\">";
	}
	else
	{
		print "<input type=\"radio\" value=\"1\" name=\"highvisibility\">";
		print "&nbsp;&nbsp;&nbsp; " . $sas_lang['no'];
		print "<input type=\"radio\" name=\"highvisibility\" value=\"0\" checked>";
	}
	print "</span>&nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['high_visibility_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";
	print "<tr><td><span class=text>" . $sas_lang['alert_sections'] . ": </td>
	       <td><input type=\"text\" name=\"sections\" size=\"20\" value=\"$sections\" class=\"textfield\">&nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['sections_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";
	print "</table>";

	print "<br><table border=\"0\">
	<tr><td><span class=\"text\">" . $sas_lang['accessrights'] . ":</span></td><td>&nbsp;</td><td><span class=\"text\">" . $sas_lang['installed_modules'] . "</span></td></tr>
	<tr><td valign=\"top\"><table border=\"0\">
	<tr bgcolor=\"E7E7EF\">
	  <td><span class=text>" . $sas_lang['filemanager'] . "&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_1\" ></td>
	  <td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_1\" checked></td>
	</tr>
	<tr>
	  <td><span class=text>" . $sas_lang['pagemanager'] . " S@S&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_2\"></td>
	  <td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_2\" checked></td>
	</tr>
	<tr bgcolor=\"E7E7EF\">
	  <td><span class=text>" . $sas_lang['protected_area'] . "&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_13\"></td>
	  <td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_13\" checked></td>
	</tr>
	<tr>
	  <td><span class=text>" . $sas_lang['modulemanager'] . "&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_3\"></td>
	  <td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_3\" checked></td>
	</tr>
	<tr bgcolor=\"E7E7EF\">
	  <td><span class=text>" . $sas_lang['stats'] . "&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_4\"></td>
	  <td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_4\" checked></td>
	</tr>
	<tr>
	  <td><span class=text>" . $sas_lang['configuration2'] . "&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_5\"></td>
	  <td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_5\" checked></td>
	</tr>
	<tr bgcolor=\"E7E7EF\">
	  <td><span class=text>" . $sas_lang['environment'] . "&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_6\"></td>
	  <td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_6\" checked></td>
	</tr>
	<tr>
	  <td><span class=text>" . $sas_lang['users'] . "&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_7\"></td>
	  <td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_7\" checked></td>
	</tr>
	<tr bgcolor=\"E7E7EF\">
	  <td><span class=text>" . $sas_lang['teachers'] . "&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_8\"></td>
	  <td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_8\" checked></td>
	</tr>
	<tr>
	  <td><span class=text>" . $sas_lang['students'] . "&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_9\"></td>
	  <td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_9\" checked></td>
	</tr>
	<tr bgcolor=\"E7E7EF\">
	  <td><span class=text>alerts&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_10\"></td>
	  <td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_10\" checked></td>
	</tr>
	<tr>
	  <td><span class=text>" . $sas_lang['database_backup'] . "&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_11\"></td>
	  <td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_11\" checked></td>
	</tr>
	<tr bgcolor=\"E7E7EF\">
	  <td><span class=text>" . $sas_lang['translation'] . "&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_12\"></td>
	  <td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_12\" checked></td>
	</tr>
	<tr>
	  <td><span class=text>" . $sas_lang['replace_tool'] . "&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_14\"></td>
	  <td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_14\" checked></td>
	</tr>
	</table>";

	$query = "SELECT id,name FROM $table_modules"; //get all installed modules names               
	$result = mysql_query($query) or die_script($query, mysql_error());
	$bgcolor = "#E7E7EF";
	print "<td width=\"25\">&nbsp;</td><td valign=\"top\">             
	       <table border=\"0\">";
	$i = 0;
	while ($module_list = mysql_fetch_array($result))
	{
		print "<tr bgcolor=\"$bgcolor\"><td><span class=text>$module_list[1]&nbsp;&nbsp;</span></td>
		       <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"m_access[$i]\"></td>";

		print "<td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"m_access[$i]\" checked></td>
		       </tr>";
		$i++;
		if ($bgcolor == "#FFFFFF")
		{
			$bgcolor = "#E7E7EF";
		}
		else
		{
			$bgcolor = "#FFFFFF";
		}
	}
	print "</table>
	       </td></tr></table>";
	print "\n<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['goback'] . "\" name=\"backbutton\" onClick=\"javascript:history.go(-1)\" class=\"backbutton\">";
	print "&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['save'] . "\" name=\"savebutton\" class=\"savebutton\">";
	print "</form>";
	exit;
}

if (IsSet ($user))
{
	$query = "SELECT name, email, username, password, editor, access, sections FROM $table_users WHERE id = '$user'";
	$result = mysql_query($query) or die_script($query, mysql_error());
	$fullname = mysql_result($result, 0, 0);
	$email = mysql_result($result, 0, 1);
	$username = mysql_result($result, 0, 2);
	$password = mysql_result($result, 0, 3);
	$usereditor = mysql_result($result, 0, 4);
	$access = mysql_result($result, 0, 5);
	$sections = mysql_result($result, 0, 6);
	unset ($query);
	unset ($result);

	$m_access = substr($access, strrpos($access, ',') + 1); //access bits module after comma
	$access = preg_split('//', $access, -1, PREG_SPLIT_NO_EMPTY); //access bits S@S
	$m_access = preg_split('//', $m_access, -1, PREG_SPLIT_NO_EMPTY); //access bits modules

	print "<span class=\"text\">" . $sas_lang['modifyuser_introduction'] . "<br><br></span>";
	print "<FORM METHOD=\"POST\" NAME=\"form\" ACTION=\"index.php?option=configuration&suboption=users&saveuser=" . $user . "\">";
	print "<table cellpadding=\"5\" cellspacing=\"2\"><tr><td>
	       <span class=text>" . $sas_lang['fullname'] . ":</td>
	       <td><input type=\"text\" name=\"fullname\" size=\"40\" value=\"$fullname\" class=\"textfield\">&nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['fullname_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";
	print "<tr><td><span class=text>" . $sas_lang['username'] . ": </td>
	       <td><input type=\"text\" name=\"username\" size=\"20\" value=\"$username\" class=\"textfield\">&nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['username_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";
	print "<tr><td><span class=text>" . $sas_lang['password'] . ": </td>";
	if ($sas_config[use_encryption] == 1) //passwords are encrypted
	{
		print "<td><input type=\"text\" name=\"password\" size=\"20\" class=\"textfield\" value=\"********\">&nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['password_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";
	}
	else
	{
		print "<td><input type=\"text\" name=\"password\" size=\"20\" value=\"$password\" class=\"textfield\">&nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['password_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";
	}
	print "<td><span class=text>" . $sas_lang['email'] . ": </td>
	       <td><input type=\"text\" name=\"email\" size=\"60\" value=\"$email\" class=\"textfield\">&nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['email_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";
	print "<td><span class=text>" . $sas_lang['editor'] . ": </td>
	      <td><span class=\"text\"><select size=\"1\" name=\"editor\">"; // WYSIWYG editor selection

	$query = "SELECT id, name FROM $table_editors";
	$result = mysql_query($query) or die_script($query, mysql_error());
	while ($editor_list = mysql_fetch_array($result))
	{
		if ($editor_list[0] == $usereditor)
		{
			print "<option selected value=\"$editor_list[0]\">$editor_list[1]</option>\n";
		}
		else
		{
			print "<option value=\"$editor_list[0]\">$editor_list[1]</option>\n";
		}
	}

	print "</span></select>&nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['editor_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";

	print "<tr><td><span class=\"text\">" . $sas_lang['high_visibility'] . ":</span></td>";
	print "<td><span class=\"text\">" . $sas_lang['yes'];
	if ($highvisibility == "1")
	{
		print "<input type=\"radio\" value=\"1\" name=\"highvisibility\" checked>";
		print "&nbsp;&nbsp;&nbsp; " . $sas_lang['no'];
		print "<input type=\"radio\" name=\"highvisibility\" value=\"0\">";
	}
	else
	{
		print "<input type=\"radio\" value=\"1\" name=\"highvisibility\">";
		print "&nbsp;&nbsp;&nbsp; " . $sas_lang['no'];
		print "<input type=\"radio\" name=\"highvisibility\" value=\"0\" checked>";
	}
	print "&nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['high_visibility_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></span></td></tr>";

	print "<tr><td><span class=text>" . $sas_lang['alert_sections'] . ": </td>
	       <td><input type=\"text\" name=\"sections\" size=\"20\" value=\"$sections\" class=\"textfield\">&nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['sections_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";
	print "</table>";
	print "<br><table border=\"0\">
		  <tr><td><span class=\"text\">" . $sas_lang['accessrights'] . ":</span></td><td>&nbsp;</td><td><span class=\"text\">" . $sas_lang['installed_modules'] . "</span></td></tr>
		  <tr><td valign=\"top\">
		  <table border=\"0\">
		  <tr bgcolor=\"E7E7EF\">
		  <td><span class=text>" . $sas_lang['filemanager'] . "&nbsp;&nbsp;</span></td>
		  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_1\"";
	if ($access[0] == "1")
		print " checked";
	print ">";
	print "</td>
	  <td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_1\"";
	if ($access[0] == "0")
		print " checked";
	print "></td>
	</tr>
	<tr>
	  <td><span class=text>" . $sas_lang['pagemanager'] . " S@S&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_2\"";
	if ($access[1] == "1")
		print " checked";
	print "></td>
	  <td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_2\"";
	if ($access[1] == "0")
		print " checked";
	print "></td>
	</tr>
	<tr bgcolor=\"E7E7EF\">
	  <td><span class=text>" . $sas_lang['protected_area'] . "&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_13\"";
	if ($access[12] == "1")
		print " checked";
	print "></td>
	  <td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_13\"";
	if ($access[12] == "0")
		print " checked";
	print "></td>
	</tr>
	<tr>
	  <td><span class=text>" . $sas_lang['modulemanager'] . "&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_3\"";
	if ($access[2] == "1")
		print " checked";
	print "></td>
	  <td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_3\"";
	if ($access[2] == "0")
		print " checked";
	print "></td>
	</tr>
	<tr bgcolor=\"E7E7EF\">
	  <td><span class=text>" . $sas_lang['stats'] . "&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_4\"";
	if ($access[3] == "1")
		print " checked";
	print "></td>
	  <td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_4\"";
	if ($access[3] == "0")
		print " checked";
	print "></td>
	</tr>
	<tr>
	  <td><span class=text>" . $sas_lang['configuration2'] . "&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_5\"";
	if ($access[4] == "1")
		print " checked";
	print "></td>
	  <td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_5\"";
	if ($access[4] == "0")
		print " checked";
	print "></td>
	</tr>
	<tr bgcolor=\"E7E7EF\">
	  <td><span class=text>" . $sas_lang['environment'] . "&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_6\"";
	if ($access[5] == "1")
		print " checked";
	print "></td>
	  <td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_6\"";
	if ($access[5] == "0")
		print " checked";
	print "></td>
	</tr>
	<tr>
	  <td><span class=text>" . $sas_lang['users'] . "&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_7\"";
	if ($access[6] == "1")
		print " checked";
	print "></td>
	<td>
	<span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_7\"";
	if ($access[6] == "0")
		print " checked";
	print "></td>
	</tr>
	<tr bgcolor=\"E7E7EF\">
	  <td><span class=text>" . $sas_lang['teachers'] . "&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_8\"";
	if ($access[7] == "1")
		print " checked";
	print "></td>
	<td>
	<span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_8\"";
	if ($access[7] == "0")
		print " checked";
	print "></td>
	</tr>
	<tr>
	  <td><span class=text>" . $sas_lang['students'] . "&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_9\"";
	if ($access[8] == "1")
		print " checked";
	print "></td>
	<td>
	<span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_9\"";
	if ($access[8] == "0")
		print " checked";
	print "></td>
	</tr>
	<tr bgcolor=\"E7E7EF\">
	  <td><span class=text>Alerts&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_10\"";
	if ($access[9] == "1")
		print " checked";
	print "></td>
	<td>
	<span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_10\"";
	if ($access[9] == "0")
		print " checked";
	print "></td>
	</tr>
	<tr>
	  <td><span class=text>" . $sas_lang['database_backup'] . "&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_11\"";
	if ($access[10] == "1")
		print " checked";
	print "></td>
	<td>
	<span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_11\"";
	if ($access[10] == "0")
		print " checked";
	print "></td>
	</tr>
	<tr bgcolor=\"E7E7EF\">
	  <td><span class=text>" . $sas_lang['translation'] . "&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_12\"";
	if ($access[11] == "1")
		print " checked";
	print "></td>
	  <td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_12\"";
	if ($access[11] == "0")
		print " checked";
	print "></td>
	</tr>
	<tr>
	  <td><span class=text>" . $sas_lang['replace_tool'] . "&nbsp;&nbsp;</span></td>
	  <td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"access_14\"";
	if ($access[13] == "1")
		print " checked";
	print "></td>
	<td>
	<span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"access_14\"";
	if ($access[13] == "0")
		print " checked";
	print "></td>
	</tr>
	</table></td>";

	$query = "SELECT id,name FROM $table_modules"; //get all installed modules names               
	$result = mysql_query($query) or die_script($query, mysql_error());
	$bgcolor = "#E7E7EF";
	print "<td width=\"25\">&nbsp;</td><td valign=\"top\">             
	       <table border=\"0\">";
	$i = 0;
	while ($module_list = mysql_fetch_array($result))
	{
		print "<tr bgcolor=\"$bgcolor\"><td><span class=text>$module_list[1]&nbsp;&nbsp;</span></td>
				<td><span class=text>" . $sas_lang['yes'] . "<input type=\"radio\" value=\"1\" name=\"m_access[$i]\"";
		if ($m_access[$i] == "1")
			print " checked";
		print "></td>";

		print "<td><span class=text>" . $sas_lang['no'] . "<input type=\"radio\" value=\"0\" name=\"m_access[$i]\" ";
		if (($m_access[$i] == "0") or ($m_access[$i] == ""))
			print " checked";
		print "></td>
					   </tr>";
		$i++;
		if ($bgcolor == "#FFFFFF")
		{
			$bgcolor = "#E7E7EF";
		}
		else
		{
			$bgcolor = "#FFFFFF";
		}
	}
	print "</table>
	       </td></tr></table>";

	print "\n<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['goback'] . "\" name=\"backbutton\" 
			onClick=\"parent.location='index.php?option=configuration&suboption=users'\" class=\"backbutton\">";
	print "&nbsp;<input type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['save'] . "\" name=\"savebutton\" class=\"savebutton\">";
	print "</form>";
}
else
{
	print "<span class=\"text\">" . $sas_lang['users_introduction'] . "</span><br><br><br>";
	print "<table>";

	$query = "SELECT id, name FROM $table_users WHERE type > 19 ORDER BY name";
	$result = mysql_query($query) or die_script($query, mysql_error());
	while ($users_list = mysql_fetch_array($result))
	{
		print "    <tr>
		           <td height=\"18\">";
		if ($highvisibility == "1")
		{
			print "<a href=\"index.php?option=configuration&suboption=users&deleteuser=$users_list[0]\">[" . $sas_lang['delete'] . "]</a>";
		}
		else
		{
			print "<a href=\"index.php?option=configuration&suboption=users&deleteuser=$users_list[0]\" 
							onClick=\"return confirm('" . $sas_lang['deleteuser_confirmation'] . "')\">
						<img border=\"0\" src=\"graphics/delete.gif\" alt=\"" . $sas_lang['delete'] . "\" title=\"" . $sas_lang['delete'] . "\" width=\"16\" height=\"16\" ></a>";
		}
		print "       </td>
		              <td>";
		if ($highvisibility == "1")
		{
			print "<a href=\"index.php?option=configuration&suboption=users&user=$users_list[0]\">[" . $sas_lang['edit'] . "]</a><span class=link> $users_list[1]</span>";
		}
		else
		{
			print "<a href=index.php?option=configuration&suboption=users&user=$users_list[0]>
			          <img border=\"0\" src=\"graphics/edit.gif\" alt=\"" . $sas_lang['edit'] . "\" title=\"" . $sas_lang['edit'] . "\" width=\"16\" height=\"16\" >
					  <span class=link> $users_list[1]</a></span>";
		}
		print "       </td>
		              </tr>";
	}
	print "<tr>
	           <td height=\"18\">
	              </td>
	              <td height=\"18\">
	              </td>
	              <td>
	              </td>
	              </tr>
	              <tr>
	           <td height=\"18\">
	              </td>
	              <td><img src=graphics/folder_closed.gif alt=\"" . $sas_lang['newuser'] . "\">
	              <a href=index.php?option=configuration&suboption=users&newuser=1><span class=link>" . $sas_lang['newuser'] . "</a></span>&nbsp;&nbsp;
	              <img src=graphics/folder_closed.gif alt=\"" . $sas_lang['copyuser'] . "\">
	              <a href=index.php?option=configuration&suboption=users&copyuser=1><span class=link>" . $sas_lang['copyuser'] . "</a></span>
	              </td>
	              </tr>";
	print "</table>";
	print "\n<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['goback'] . "\" name=\"backbutton\" 
			onClick=\"javascript:parent.location='index.php?option=configuration'\" class=\"backbutton\">";

}
?>
