<?php
require_once('common.inc.php');
require_once('user.inc.php');

user_auth_required("teacher");
$schoolid=user_field_required("schools_id","user_edit.php?tab=school");

send_header("School Details");
if($_POST['action']=="save") {
	// load the school info so we know which one we're saving
	$q=mysql_query("SELECT * FROM schools WHERE id='$schoolid'");
	$school=mysql_fetch_object($q);

	mysql_query("UPDATE schools SET
		school='".mysql_real_escape_string($_POST['school'])."',
		address='".mysql_real_escape_string($_POST['address'])."',
		city='".mysql_real_escape_string($_POST['city'])."',
		province_code='".mysql_real_escape_string($_POST['province_code'])."',
		postalcode='".mysql_real_escape_string($_POST['postalcode'])."',
		phone='".mysql_real_escape_string($_POST['phone'])."',
		fax='".mysql_real_escape_string($_POST['fax'])."'
		WHERE id='$school->id'");

	echo mysql_error();
	if(mysql_error())
		echo error(i18n("An Error occured trying to save the school information"));
	else
		echo happy(i18n("School information successfully updated"));

}
// load the school info
$q=mysql_query("SELECT * FROM schools WHERE id='$schoolid'");
$school=mysql_fetch_object($q);

draw_page();
send_footer();

function draw_page(){
	global $config, $school, $sh_email, $sh_email, $sh;
	echo i18n("Please note, as a teacher you are editing the MASTER RECORD for %1.  If you have switched schools you should switch your school under your account profile.  Only edit the information below if the details for the school have changed.",array($school->school));
	echo "<br />";
	echo "<br />";
	echo "<h2>$school->school</h2>";

	echo "<form method=\"post\" action=\"schoolinfo.php\">";
	echo "<input type=\"hidden\" name=\"action\" value=\"save\">";
	echo "<table border=0 cellspacing=0 cellpadding=3>";
	echo "<tr><td>".i18n("School Name")."</td><td><input value=\"$school->school\" type=\"text\" name=\"school\" size=\"40\"></td></tr>";
//	echo "<tr><td>Registration Password</td><td><input value=\"$school->registration_password\" type=text name=\"registration_password\" size=\"20\"></td></tr>";
	echo "<tr><td>".i18n("Address")."</td><td><input value=\"$school->address\" type=text name=address size=40></td></tr>";
	echo "<tr><td>".i18n("City")."</td><td><input value=\"$school->city\" type=text name=city size=30></td></tr>";
	echo "<tr><td>".i18n($config['provincestate'])."</td><td>";
	emit_province_selector("province_code",$school->province_code);
	echo "</td></tr>\n";
	echo "<tr><td>".i18n($config['postalzip'])."</td><td><input value=\"$school->postalcode\"  type=text name=postalcode size=10></td></tr>";
	echo "<tr><td>".i18n("Phone Number")."</td><td><input value=\"$school->phone\" type=text name=phone size=30></td></tr>";
	echo "<tr><td>".i18n("Fax Number")."</td><td><input value=\"$school->fax\" type=text name=fax size=30></td></tr>";
	
	/*
	echo "<tr><td>".i18n("Science Teacher")."</td><td><input value=\"{$sh['name']}\" type=text name=sciencehead size=40></td></tr>";
	echo "<tr><td>".i18n("Science Teacher Email")."</td><td><input value=\"$sh_email\" type=text name=scienceheademail size=40></td></tr>";
	echo "<tr><td>".i18n("Science Teacher Phone")."<br><font size=1>(".i18n("If different than above").")</font></td><td><input value=\"{$sh['phonework']}\" type=text name=scienceheadphone size=30></td></tr>";
	*/
	echo "</table>";
	echo "<input type=submit value=\"".i18n("Save Changes")."\">";
	echo "</form>";
	echo "<br>";
}

?>