<?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_teachers.inc.php: last changed 04/10/2006  2.4.10                                      
#                       by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: con_teachers.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 ;
    }
  return true ;
}
</script>
<?php


if (IsSet ($_GET['deleteteacher']))
{
	$deleteteacher = $_GET['deleteteacher'];
}
if (IsSet ($_GET['saveteacher']))
{
	$saveteacher = $_GET['saveteacher'];
}
if (IsSet ($_GET['newteacher']))
{
	$newteacher = $_GET['newteacher'];
}
if (IsSet ($_GET['teacher']))
{
	$teacher = $_GET['teacher'];
}
if (IsSet ($_GET['prevuser']))
{
	$prevuser = $_GET['prevuser'];
}
if (IsSet ($_GET['casetype']))
{
	$casetype = $_GET['casetype'];
} //added by Alain Riffart

if (IsSet ($_POST['fullname']))
{
	$fullname = $_POST['fullname'];
}
if (IsSet ($_POST['teacherclass']))
{
	$teacherclass = $_POST['teacherclass'];
}
if (IsSet ($_POST['username']))
{
	$username = $_POST['username'];
}
if (IsSet ($_POST['password']))
{
	$password = $_POST['password'];
}
if (IsSet ($_POST['project']))
{
	$project = $_POST['project'];
}
if (IsSet ($_POST['class']))
{
	$class = $_POST['class'];
}
if (IsSet ($_POST['type']))
{
	$type = $_POST['type'];
}
if (IsSet ($_POST['email']))
{
	$email = $_POST['email'];
}
if (IsSet ($_POST['check']))
{
	$check = $_POST['check'];
}
if (IsSet ($_POST['choiceuser']))
{
	$choiceuser = $_POST['choiceuser'];
} //added by Alain Riffart
if (IsSet ($_GET['modoption']))
{
	$modoption = $_GET['modoption'];
}
else
{
	$modoption = "teachers_list";
}

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

if (substr("$access", 7, 1) == "0") //bit 8 off the accessrights
{
	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['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 (IsSet ($deleteteacher))
{
	if ($casetype)
		//Added by Alain Riffart
	{ // Update type 
		$type = 20;
		mysql_query("UPDATE $table_users SET type='$type' WHERE id='$deleteteacher'");
		mysql_query("UPDATE $table_users SET class=NULL WHERE id='$deleteteacher'"); // last change 19/03/05 Alain Riffart
	}
	else
	{ //End 
		mysql_query("DELETE from $table_users WHERE id = '$deleteteacher'");
	}
	mysql_query("DELETE FROM $table_studentpages WHERE dir_number='$deleteteacher'"); //delete the teacherpage

	if (IsSet ($_GET['delete_teacher_files']))
	{
		$delete_teacher_files = $_GET['delete_teacher_files'];
	}
	else
	{
		$delete_teacher_files = "";
	}

	$teacher_path = $sas_config['serverpath'] . $sas_config['user_path'] . "/studentpages/" . $deleteteacher . "/";

	if (file_exists($teacher_path)) //first check if the teacher directory exists
	{
		delete_files($deleteteacher); //delete all the file in the teachers directory
		rmdir($teacher_path); //delete the pupils root directory

		//return to the teachers  view
		print "<script language='javascript'>
				  window.location = 'index.php?option=configuration&suboption=teachers'
				  </script>";
	}
}

if (IsSet ($saveteacher))
{
	if (count($project) == 0)
	{
		$comma_separated_project = "";
	}
	else
	{
		$comma_separated_project = implode(",", $project);
	}
	if (count($class) == 0)
	{
		$comma_separated_class = "";
	}
	else
	{
		$comma_separated_class = implode(",", $class);
	}

	if ($check == "1") //teacher is also a normal user.             
	{
		$type = 22;
	}
	else
	{
		$type = "2";
	}

	if ($saveteacher == "new")
	{

		$query = mysql_query("SELECT username FROM $table_users WHERE username = '$username'");
		$results = mysql_num_rows($query);
		if ($results != '0')
		{
			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, type, class, access, highvisibility, project) 
			           VALUES ('$fullname', '$username',  '$password',  '$email', '$type', '$comma_separated_class', '000000000000,000000000000', '0', '$comma_separated_project')");
		}
		//Lines added by Alain Riffart
	}
	elseif (IsSet ($choiceuser))
	{
		mysql_query("UPDATE $table_users SET type='$type' WHERE id='$choiceuser'");
		mysql_query("UPDATE $table_users SET class='$teacherclass' WHERE id='$choiceuser'");
		//End
	}
	else
	{
		$query = mysql_query("SELECT username FROM $table_users WHERE username = '$username' AND id != '$saveteacher'");
		$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=$saveteacher' ;	
					   //-->
					   </script>"; //return to the user edit window.
		}
		else
		{
			mysql_query("UPDATE $table_users SET name='$fullname', 
														   username='$username',  
														   email='$email', 
														   class='$comma_separated_class', 
														   type='$type',
														   project = '$comma_separated_project'
														   WHERE id='$saveteacher'");
			if (($password != "") AND ($password != "********")) //only save password when not empty.
			{
				mysql_query("UPDATE $table_users SET password='$password' WHERE id='$saveteacher'");
			}
		}
	}
}
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=configuration&suboption=teachers&modoption=teachers_list>" . $sas_lang['teachers'] . "</a><p>
<a href=index.php?option=configuration&suboption=teachers&modoption=import>" . $sas_lang['import_import'] . "</a><br></span>";
include ("interface/menuend.inc.php");
include ("interface/pagestart.inc.php");

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

//lines added by Alain Riffart

if (IsSet ($prevuser))
{
	$result = mysql_query("SELECT id, name FROM $table_users WHERE type = '20'");
	if (mysql_num_rows($result) > 0)
	{
		print "<span class=text>" . $sas_lang['userasteacher'] . "</span><br/><br/>";
		print "<FORM METHOD=\"POST\" NAME=\"form\" ACTION=\"index.php?option=configuration&suboption=teachers&saveteacher=1\">\n";
		print "<span class=text>" . $sas_lang['username'] . ": </span><SELECT name=\"choiceuser\" size=\"1\">\n";
		$i = 0;
		while ($row = mysql_fetch_array($result))
		{
			print "<OPTION value=\"$row[0]\">$row[1]</OPTION>\n";
			$i++;
		}
		print "</SELECT><br/><br/>\n";
		print "<span class=text>" . $sas_lang['class'] . ":&nbsp;&nbsp;</span>";
		print "<select class=\"text\" size=\"1\" name=\"teacherclass\">";
		mysql_free_result($result);
		$query = "SELECT id, name FROM $table_classes ORDER BY name";
		$result = mysql_query($query) or die_script($query, mysql_error());
		while ($class_list = mysql_fetch_array($result))
		{
			$class_list[1] = stripslashes($class_list[1]);
			print "<option value=\"$class_list[0]\">$class_list[1]</option>\n";
		}
		print "</select>&nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['class_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\">";
		mysql_free_result($result);
		print "\n<input type=\"hidden\" name=\"check\" value=\"1\"><br/><br/>";
		print "\n<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['goback'] . "\" name=\"backbutton\" onClick=\"javascript:parent.location='index.php?option=configuration&suboption=teachers';\" class=\"backbutton\">";
		print "&nbsp;<input tabindex=\"6\" type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['save'] . "\" name=\"savebutton\" class=\"savebutton\">";
		print "</form>";
	}
	else
	{
		print $sas_lang['no_userasteacher'] . "<br/>";
		print "\n<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['goback'] . "\" name=\"backbutton\" onClick=\"javascript:history.go(-1)\" class=\"backbutton\">";
	}
	exit;
}

//End 

if (IsSet ($newteacher))
{
	print "<span class=\"text\">" . $sas_lang['newteacher'] . ":</span><p>";
	print "<FORM METHOD=\"POST\" NAME=\"form\" ACTION=\"index.php?option=configuration&suboption=teachers&saveteacher=new\" onsubmit=\"return checkinput(this);\">";
	print "<table cellpadding=\"5\" cellspacing=\"2\"><tr><td>
	        <span class=text><b>" . $sas_lang['fullname'] . ":</b> (*)</span></td>
	        <td><input tabindex=\"1\" 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\"><b>" . $sas_lang['username'] . ":</b> (*)</span></td>
	        <td><input tabindex=\"2\" 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\"><b>" . $sas_lang['password'] . ":</b> (*)</span></td>
	        <td><input tabindex=\"3\" type=\"text\" name=\"password\" size=\"20\" class=\"textfield\">&nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['password_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";
	print "<tr><td><span class=\"text\"><b>" . $sas_lang['email'] . ":</b></span></td>
	        <td><input tabindex=\"4\" 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>&nbsp;</td><td><span class=\"text\">" . $sas_lang['required_fields'] . "</td></tr>";
	$query = "SELECT id, name FROM $table_classes WHERE project = 0 ORDER BY name";
	$result = mysql_query($query) or die_script($query, mysql_error());
	print "<tr><td colspan=\"2\"><table width=\"100%\">\n";
	print "<tr><td colspan=\"6\"><br><span class=text><b>" . $sas_lang['class'] . ":</b>&nbsp;&nbsp;
	<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['class_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>"; //classes
	$i = 0;
	$j = 0;
	while ($class_list = mysql_fetch_array($result))
	{
		$class_name = stripslashes($class_list[1]);

		print "<td width=\"25%\"><span class=text><b>$class_name</b></span></td>
				<td><input type=\"checkbox\" value=\"$class_list[0]\" name=\"class[$j]\"></td><td width=\"10%\">&nbsp;</td>\n";
		if ($i == 2)
		{
			print "</tr><tr>";
			$i = 0;
		}
		else
		{
			$i++;
		}
		$j++;
	}

	print "<tr><td colspan=\"6\"><br><span class=text><b>" . $sas_lang['student_projects'] . ":&nbsp;&nbsp;
	<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['student_project_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";

	$query = "SELECT id, name FROM $table_classes WHERE project = 1 ORDER BY name";
	$result = mysql_query($query) or die_script($query, mysql_error());
	//print "<tr><td colspan=\"2\"><table width=\"100%\"><tr>\n";
	print "<tr>";
	$i = 0;
	$j = 0;
	while ($project_list = mysql_fetch_array($result))
	{
		$project_name = stripslashes($project_list[1]);

		print "<td width=\"25%\"><span class=text><b>$project_name</b></span></td>
				<td><input type=\"checkbox\" value=\"$project_list[0]\" name=\"project[$j]\"></td><td width=\"10%\">&nbsp;</td>\n";
		if ($i == 2)
		{
			print "</tr><tr>";
			$i = 0;
		}
		else
		{
			$i++;
		}
		$j++;
	}
	print "</table></td></tr>";
	print "</table>";
	print "<table><tr><td>&nbsp;</td></tr><tr><td><span class=text>" . $sas_lang['teacher_is_user'] . " </span></td>";
	print "<td><span class=text>" . $sas_lang['yes'] . "</span></td>";
	print "<td><input type=\"radio\" value=\"1\" name=\"check\"></td>";
	print "<td><span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span></td>";
	print "<td><input type=\"radio\" name=\"check\" value=\"0\" checked></td>";
	print "</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 tabindex=\"6\" type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['save'] . "\" name=\"savebutton\" class=\"savebutton\">";
	print "</form>";
	exit;
}

if (IsSet ($teacher))
{
	$query = "SELECT name, username, password, email, type, class, project FROM $table_users WHERE id = '$teacher'";
	$result = mysql_query($query) or die_script($query, mysql_error());
	$fullname = mysql_result($result, 0, name); // getting the teachers name
	$email = mysql_result($result, 0, email); // getting the teachers email
	$username = mysql_result($result, 0, username); // getting the teachers username
	$password = mysql_result($result, 0, password); // getting the teachers password
	$user_type = mysql_result($result, 0, type); // getting the teachers type
	$project = mysql_result($result, 0, project); // getting the teachers projects
	$class = mysql_result($result, 0, 5); // getting the teachers classes
	unset ($query);
	unset ($result);

	$project_array = explode(",", $project); //create an array
	$class_array = explode(",", $class); //create an array

	$query = "SELECT class FROM $table_users WHERE id = '$teacher'"; // getting the teachers class
	$result = mysql_query($query) or die_script($query, mysql_error());
	$teacherclass = mysql_result($result, 0);
	unset ($query);
	unset ($result);

	print "<span class=\"text\">" . $sas_lang['modifyuser_introduction'] . "</span><p>";
	print "<FORM METHOD=\"POST\" NAME=\"form\" ACTION=\"index.php?option=configuration&suboption=teachers&saveteacher=" . $_GET['teacher'] . "\">";
	print "<table cellpadding=\"5\" cellspacing=\"2\"><tr>
	       <td><span class=text><b>" . $sas_lang['fullname'] . ":</b></td>
	       <td><input tabindex=\"1\" 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><b>" . $sas_lang['username'] . ":</b></td>
	       <td><input tabindex=\"2\" 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><b>" . $sas_lang['password'] . ":</b></td>";

	if ($sas_config[use_encryption] == 1) //passwords are encrypted
	{
		print "<td><input type=\"text\" name=\"password\" size=\"20\" value=\"********\" class=\"textfield\" tabindex=\"3\">&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\" tabindex=\"3\">&nbsp;
			<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['password_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";
	}

	print "<tr><td><span class=text><b>" . $sas_lang['email'] . ":</b></td>
	       <td><input tabindex=\"4\" 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>";

	$query = "SELECT id, name FROM $table_classes WHERE project = 0 ORDER BY name";
	$result = mysql_query($query) or die_script($query, mysql_error());
	print "<tr><td colspan=\"2\"><table width=\"100%\"><tr>\n";
	print "<tr><td colspan=\"6\"><br><span class=text><b>" . $sas_lang['class'] . ":</b>&nbsp;&nbsp;
	<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['class_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>"; //classes
	$i = 0;
	$j = 0;
	while ($class_list = mysql_fetch_array($result))
	{
		$class_name = stripslashes($class_list[1]);

		if (in_array($class_list[0], $class_array))
		{
			print "<td width=\"25%\"><span class=text><b>$class_name</b></span></td>
						<td><input type=\"checkbox\" value=\"$class_list[0]\" name=\"class[$j]\" checked></td><td width=\"10%\">&nbsp;&nbsp;</td>\n";
		}
		else
		{
			print "<td width=\"25%\"><span class=text><b>$class_name</b></span></td>
						<td><input type=\"checkbox\" value=\"$class_list[0]\" name=\"class[$j]\"></td><td width=\"10%\">&nbsp;&nbsp;</td>\n";
		}
		if ($i == 2)
		{
			print "</tr><tr>";
			$i = 0;
		}
		else
		{
			$i++;
		}
		$j++;
	}
	//print "</table></td></tr>";
	//print "&nbsp;<img src=graphics/help.gif ONMOUSEOVER=\"popup('".$sas_lang['class_tip']."','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";
	print "<tr><td colspan=\"6\"><br><span class=text><b>" . $sas_lang['student_projects'] . ":&nbsp;&nbsp;
	<img src=graphics/help.gif ONMOUSEOVER=\"popup('" . $sas_lang['student_project_tip'] . "','CCDAEC')\"; ONMOUSEOUT=\"kill()\"></td></tr>";

	$query = "SELECT id, name FROM $table_classes WHERE project = 1 ORDER BY name";
	$result = mysql_query($query) or die_script($query, mysql_error());

	print "<tr>";
	$i = 0;
	$j = 0;
	while ($project_list = mysql_fetch_array($result))
	{
		$project_name = stripslashes($project_list[1]);

		if (in_array($project_list[0], $project_array))
		{
			print "<td width=\"25%\"><span class=text><b>$project_name</b></span></td>
						<td><input type=\"checkbox\" value=\"$project_list[0]\" name=\"project[$j]\" checked></td><td width=\"10%\">&nbsp;&nbsp;</td>\n";
		}
		else
		{
			print "<td width=\"25%\"><span class=text><b>$project_name</b></span></td>
						<td><input type=\"checkbox\" value=\"$project_list[0]\" name=\"project[$j]\"></td><td width=\"10%\">&nbsp;&nbsp;</td>\n";
		}
		if ($i == 2)
		{
			print "</tr><tr>";
			$i = 0;
		}
		else
		{
			$i++;
		}
		$j++;
	}
	print "</table></td></tr>";
	print "<table><tr><td colspan=\"5\">&nbsp;</td></tr>
			<tr><td><span class=text>" . $sas_lang['teacher_is_user'] . " </span></td>";
	print "<td><span class=text>&nbsp;" . $sas_lang['yes'] . "</span></td>";
	if ($user_type == "22")
	{
		print "<td><input type=\"radio\" value=\"1\" name=\"check\" checked></td>";
		print "<td><span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span></td>";
		print "<td><input type=\"radio\" name=\"check\" value=\"0\"></td>";
	}
	else
	{
		print "<td><input type=\"radio\" value=\"1\" name=\"check\"></td>";
		print "<td><span class=text>&nbsp;&nbsp;&nbsp; " . $sas_lang['no'] . "</span></td>";
		print "<td><input type=\"radio\" name=\"check\" value=\"0\" checked></td>";
	}
	print "</tr>";
	$query3 = "SELECT id, name FROM $table_modules WHERE location = 'sn_studentpages'";
	$result3 = mysql_query($query3) or die_script($query3, mysql_error());
	$module_id = mysql_result($result3, 0, 0); //get the module id for the link
	$module_name = mysql_result($result3, 0, 1); //get the module name for the link

	print "<tr><td colspan=\"5\"><span class=text>" . $sas_lang['student_directory'] . " 
			<b>$teacher</b></span>&nbsp;<span class=link>
			<a href=\"index.php?option=modulemanager&module=$module_id&viewclass=$class\">(" . $module_name . ")</a></span></td></tr></table><br>";
	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&suboption=teachers';\" class=\"backbutton\">";
	print "&nbsp;<input tabindex=\"6\" type=\"submit\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['save'] . "\" name=\"savebutton\" class=\"savebutton\">";
	print "</form>";
	exit;
}

if ($modoption == "import")
{
	print "<span class=\"text\">" . $sas_lang['import_import'] . "</span><br><br>";

	require "janitor/functions.php";
	require "janitor/janitor.conf.php";
	require "janitor/config.php";

	// globals
	$Message = "";
	//overide the defaults because the teachers file has a different layout
	$edex_defaults = array (
			0 => 1, // default fileformat: 1=Fixed Record Length
	1 => array (
			71,
			4,
			1
			), // unique key
	2 => array (
			51,
			20,
			2
			), // first name
	3 => array (
			41,
			10,
			3
			), // infix
	4 => array (
			1,
			40,
			4
		)
	); // last name

	// Dispatcher; see what they want
	$action = $_REQUEST[PARAM_ACTION];
	$tgt = strval(intval($_REQUEST[PARAM_TGT]));
	$src = strval(intval($_REQUEST[PARAM_SRC]));
	include_once "janitor/edex.php";
	edex_screen($tgt, 2);
}
elseif ($modoption == "teachers_list")
{
	print "<span class=\"text\">" . $sas_lang['teachers_introduction'] . "</span><br><br><br>";

	print "<table border=\"0\">
	       <tr><td>&nbsp;</td><td width=\"200\"><span class=\"text\">" . $sas_lang['teachers'] . ":</span></td>
		   <td width=\"30\">&nbsp;</td><td><span class=\"text\">" . $sas_lang['username'] . ":</span></td>
		   <td width=\"30\">&nbsp;</td><td><span class=\"text\">" . $sas_lang['email'] . ":</span></td>
	       <td width=\"30\">&nbsp;</td><td><span class=\"text\">" . $sas_lang['class'] . ":</span></td>
	       <td width=\"30\">&nbsp;</td><td><span class=\"text\">" . $sas_lang['student_projects'] . ":</span></td></tr>";

	$query = "SELECT id, name, class, type, project, username, email FROM $table_users WHERE type = 22 OR type = 2 ORDER BY username";
	$result = mysql_query($query) or die_script($query, mysql_error());
	if ($result)
	{
		while ($users_list = mysql_fetch_array($result))
		{
			$teacherclass = "";
			$teacher_project = " ";
			if ($users_list[3] == 22)
			{
				$casetype[$case] = 1;
			} // Added
			else
			{
				$casetype[$case] = 0;
			}

			$class_list = explode(",", $users_list[2]);
			foreach ($class_list as $value)
			{
				$query2 = "SELECT name FROM $table_classes WHERE id = '$value'"; // getting the teachers classes
				$result2 = mysql_query($query2) or die_script($query2, mysql_error());
				if (mysql_num_rows($result2) == 1)
				{
					$teacherclass .= stripslashes(mysql_result($result2, 0)) . "<br>";
				}
				else
				{
					$teacherclass = " ";
				}
			}
			unset ($query2);
			unset ($result2);
			$project_list = explode(",", $users_list[4]);
			foreach ($project_list as $value)
			{
				$query2 = "SELECT name FROM $table_classes WHERE id = '$value'"; // getting the teachers proejcts
				$result2 = mysql_query($query2) or die_script($query2, mysql_error());
				if (mysql_num_rows($result2) == 1)
				{
					$teacher_project .= stripslashes(mysql_result($result2, 0)) . "<br>";
				}
				else
				{
					$teacher_project = " ";
				}
			}
			unset ($query2);
			unset ($result2);
			print "<tr>
			               <td height=\"25\" valign=\"top\">";
			if ($highvisibility == "1")
			{
				print "<a href=\"index.php?option=configuration&suboption=teachers&deleteteacher=$users_list[0]&casetype=$casetype[$case]\"\" 
				        onClick=\"return confirm('" . $sas_lang['teacher_delete_confirm'] . "')\">[" . $sas_lang['delete'] . "]</a>";
			}
			else
			{
				print "<a href=\"index.php?option=configuration&suboption=teachers&deleteteacher=$users_list[0]&casetype=$casetype[$case]\"\"
				                onClick=\"return confirm('" . $sas_lang['teacher_delete_confirm'] . "')\"><img border=\"0\" src=\"graphics/delete.gif\" alt=\"" . $sas_lang['delete'] . "\" width=\"16\" height=\"16\"></a> ";
			}
			print "</td><td valign=\"top\">";
			if ($highvisibility == "1")
			{
				print "<a href=\"index.php?option=configuration&suboption=teachers&teacher=$users_list[0]\">[" . $sas_lang['edit'] . "]</a><span class=link> $users_list[1]</span>
				              </td><td>&nbsp;</td><td valign=\"top\"><span class=\"text\"><b>$teacherclass</b></span>";
			}
			else
			{
				print "     <span class=link><a href=index.php?option=configuration&suboption=teachers&teacher=$users_list[0]>
				                    <img border=\"0\" src=\"graphics/edit.gif\" alt=\"" . $sas_lang['edit'] . "\" width=\"16\" height=\"16\" onClick=\"parent.location='index.php?option=configuration&suboption=teachers&teacher=$users_list[0]';\">
				                    $users_list[1]</a></span>
									<td>&nbsp;</td><td valign=\"top\"><span class=text><b>$users_list[5]</b></span></td>
									<td>&nbsp;</td><td valign=\"top\"><span class=text><b>$users_list[6]</b></span></td>
				                    </td><td>&nbsp;</td><td valign=\"top\"><span class=\"text\"><b>$teacherclass</b></span>";
			}
			print "       </td><td>&nbsp;</td><td valign=\"top\"><span class=\"text\"><b>$teacher_project</b></span></td>
			                  </tr>";
		}
	}
	print "<tr>
	           <td colspan=\"6\" height=\"18\"></td>
	       </tr>
	       <tr>
	           <td height=\"18\"></td>
	           <td colspan=\"4\"><img src=graphics/folder_closed.gif alt=\"" . $sas_lang['newteacher'] . "\">
	           <span class=link><a href=index.php?option=configuration&suboption=teachers&newteacher=1>" . $sas_lang['newteacher'] . "</a></span>
	           </td>
	        </tr>";
	//linesadded by Alain Riffart
	print "<tr>
				<td height=\"18\"></td>
				<td colspan=\"4\"><img src=graphics/folder_closed.gif alt=\"" . $sas_lang['newteacher_prev_user'] . "\">
				<span class=link><a href=index.php?option=configuration&suboption=teachers&prevuser=1>" . $sas_lang['newteacher_prev_user'] . "</a></span>
				</td>
			</tr>";
	//End
	print "</table>";
	print "\n<br><input type=\"button\" value=\"&nbsp;&nbsp;&nbsp;" . $sas_lang['goback'] . "\" name=\"backbutton\" onClick=\"parent.location='index.php?option=configuration'\" class=\"backbutton\">";
}
?>