diff --git a/admin/schools.php b/admin/schools.php index a8f15f5..3fade4c 100644 --- a/admin/schools.php +++ b/admin/schools.php @@ -56,7 +56,7 @@ /* Load existing entry if it exists, else make an entry if * there is data, else, do nothing */ if($i['principal_uid'] > 0) - $pl = user_load_by_uid($i['principal_uid']); + $pl = user_load_($i['principal_uid']); else if($first != '' && $last != '') { $pl = user_create('principal', "*$first$last".user_generate_password()); $principal_update = "principal_uid='{$pl['uid']}',"; @@ -85,7 +85,7 @@ * to insert */ $sh = false; if($i['sciencehead_uid'] > 0) { - $sh = user_load_by_uid($i['sciencehead_uid']); + $sh = user_load($i['sciencehead_uid']); /* It's possile for sh to be false now, happens when the user is * deleted outside the school editor, this condition needs to be * fixed. If we let it go, the saving the teacher info will @@ -167,21 +167,55 @@ mysql_query("UPDATE schools SET include_olympics = TRUE WHERE id IN $olympicString"); mysql_query("UPDATE schools SET include_olympics = FALSE WHERE id NOT IN $olympicString"); } + else if($_POST['action']=="copy") { + $oldConfId=intval($_POST['copyconference']); + $newConfId=intval($conference['id']); + if($oldConfId && $newConfId) { - if($_GET['action']=="delete" && $_GET['delete']) - { + $q=mysql_query("SELECT * FROM schools WHERE conferences_id=$oldConfId"); + + while($r=mysql_fetch_object($q)) { + $puid = ($r->principal_uid == null) ? 'NULL' : ("'".intval($r->principal_uid)."'"); + $shuid = ($r->sciencehead_uid == null) ? 'NULL' : ("'".intval($r->sciencehead_uid)."'"); + + mysql_query("INSERT INTO schools (school,schoollang,schoollevel,board,district,phone,fax,address,city,province_code,postalcode,principal_uid,schoolemail,sciencehead_uid,accesscode,lastlogin,junior,intermediate,senior,registration_password,projectlimit,projectlimitper,conferences_id) VALUES ( + '".mysql_real_escape_string($r->school)."', + '".mysql_real_escape_string($r->schoollang)."', + '".mysql_real_escape_string($r->schoollevel)."', + '".mysql_real_escape_string($r->board)."', + '".mysql_real_escape_string($r->district)."', + '".mysql_real_escape_string($r->phone)."', + '".mysql_real_escape_string($r->fax)."', + '".mysql_real_escape_string($r->address)."', + '".mysql_real_escape_string($r->city)."', + '".mysql_real_escape_string($r->province_code)."', + '".mysql_real_escape_string($r->postalcode)."',$puid, + '".mysql_real_escape_string($r->schoolemail)."',$shuid, + '".mysql_real_escape_string($r->accesscode)."', + NULL, + '".mysql_real_escape_string($r->junior)."', + '".mysql_real_escape_string($r->intermediate)."', + '".mysql_real_escape_string($r->senior)."', + '".mysql_real_escape_string($r->registration_password)."', + '".mysql_real_escape_string($r->projectlimit)."', + '".mysql_real_escape_string($r->projectlimitper)."', + '".mysql_real_escape_string($newConfId)."')"); + } + $notice="copied"; + } + } + + if($_GET['action']=="delete" && $_GET['delete']) { mysql_query("DELETE FROM schools WHERE id='".$_GET['delete']."'"); $notice = 'deleted'; } - if($_GET['action']=="clearaccesscodes") - { + if($_GET['action']=="clearaccesscodes") { mysql_query("UPDATE schools SET accesscode=NULL WHERE conferences_id='{$conference['id']}'"); $notice = 'clearaccess'; } - if($_GET['action']=="makeaccesscodes") - { + if($_GET['action']=="makeaccesscodes") { $q=mysql_query("SELECT id FROM schools WHERE conferences_id='{$conference['id']}' AND (accesscode IS NULL OR accesscode='')"); while($r=mysql_fetch_object($q)) { @@ -192,9 +226,7 @@ $notice = 'makeaccess'; } - if($_GET['action']=="edit" || $_GET['action']=="add") - { - + if($_GET['action']=="edit" || $_GET['action']=="add") { send_header(($_GET['action']=='edit') ? "Edit School" : "Add New School", array('Committee Main' => 'committee_main.php', 'Administration' => 'admin/index.php', @@ -255,7 +287,7 @@ echo "".i18n("Fax")."fax)."\" size=\"16\" maxlength=\"16\" />\n"; if($r->principal_uid > 0) - $pl = user_load_by_uid($r->principal_uid); + $pl = user_load($r->principal_uid); else $pl = array(); echo "".i18n("Principal")."\n"; @@ -263,7 +295,7 @@ echo "".i18n("Access Code")."accesscode)."\" size=\"32\" maxlength=\"32\" />\n"; echo "
".i18n("Science head/teacher or science fair contact at school").""; if($r->sciencehead_uid > 0) - $sh = user_load_by_uid($r->sciencehead_uid); + $sh = user_load($r->sciencehead_uid); else $sh = array(); /* Don't show autogenerated emails */ @@ -313,7 +345,6 @@ } - else if($_GET['action'] == 'participation') { send_header( @@ -353,8 +384,32 @@ echo "\n"; } - else - { + else if($_GET['action']=="copy") { + send_header("School Management", + array('Committee Main' => 'committee_main.php', + 'Administration' => 'admin/index.php'), + "schools_management" + ); + echo "
"; + echo "\n"; + echo i18n("Choose a conference to copy schools from"); + echo "
"; + $q=mysql_query("SELECT * FROM conferences WHERE id!='{$conference['id']}' ORDER BY id DESC"); + echo mysql_error(); + echo "\n"; + echo ""; + echo "
\n"; + + } + + else { send_header("School Management", array('Committee Main' => 'committee_main.php', 'Administration' => 'admin/index.php'), @@ -363,25 +418,30 @@ switch($notice) { case 'added': - echo happy("School successfully added"); + echo happy(i18n("School successfully added")); break; case 'saved': - echo happy("Successfully saved changes to school"); + echo happy(i18n("Successfully saved changes to school")); break; case 'deleted': - echo happy("School successfully deleted"); + echo happy(i18n("School successfully deleted")); break; case 'clearaccess': - echo happy("Access Codes successfully cleared from all schools"); + echo happy(i18n("Access Codes successfully cleared from all schools")); break; case 'makeaccess': - echo happy("Access Codes successfully set for schools that didn't have one"); + echo happy(i18n("Access Codes successfully set for schools that didn't have one")); + break; + case 'copied': + echo happy(i18n("Schools successfully copied from other conference")); break; } echo "
"; echo "".i18n("Add new school")."\n"; echo "
"; + echo "".i18n("Copy schools from a difference conference")."\n"; + echo "
"; echo "".i18n("Import schools from CSV")."\n"; echo "
"; echo "".i18n("Create Access Code for any school without one")."\n"; @@ -413,10 +473,9 @@ echo " $r->school\n"; echo " $r->address, $r->city, $r->postalcode\n"; echo " $r->phone\n"; - $sciencehead = ''; if($r->sciencehead_uid > 0) { - $sh = user_load_by_uid($r->sciencehead_uid); + $sh = user_load($r->sciencehead_uid); $sciencehead = $sh['name']; } echo " $sciencehead\n";