Add function to copy schools from a different conference.

fix the user_load_by_uid calls, but im not sure if simply replacing them with user_load() is the 'right' fix.. but at least the page loads now :p
This commit is contained in:
james 2011-01-11 20:10:51 +00:00
parent 9230b559db
commit 97076cbe32

View File

@ -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 "<tr><td>".i18n("Fax")."</td><td><input type=\"text\" name=\"fax\" value=\"".htmlspecialchars($r->fax)."\" size=\"16\" maxlength=\"16\" /></td></tr>\n";
if($r->principal_uid > 0)
$pl = user_load_by_uid($r->principal_uid);
$pl = user_load($r->principal_uid);
else
$pl = array();
echo "<tr><td>".i18n("Principal")."</td><td><input type=\"text\" name=\"principal\" value=\"".htmlspecialchars($pl['name'])."\" size=\"60\" maxlength=\"64\" /></td></tr>\n";
@ -263,7 +295,7 @@
echo "<tr><td>".i18n("Access Code")."</td><td><input type=\"text\" name=\"accesscode\" value=\"".htmlspecialchars($r->accesscode)."\" size=\"32\" maxlength=\"32\" /></td></tr>\n";
echo "<tr><td colspan=2><br /><b>".i18n("Science head/teacher or science fair contact at school")."</b></td></tr>";
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 "</form>\n";
}
else
{
else if($_GET['action']=="copy") {
send_header("School Management",
array('Committee Main' => 'committee_main.php',
'Administration' => 'admin/index.php'),
"schools_management"
);
echo "<form method=\"post\" action=\"schools.php\">";
echo "<input type=\"hidden\" name=\"action\" value=\"copy\">\n";
echo i18n("Choose a conference to copy schools from");
echo "<br />";
$q=mysql_query("SELECT * FROM conferences WHERE id!='{$conference['id']}' ORDER BY id DESC");
echo mysql_error();
echo "<select name=\"copyconference\">";
echo "<option value=\"\">".i18n("Choose a Conference")."</option>\n";
while($r=mysql_fetch_object($q)) {
$numq=mysql_query("SELECT COUNT(*) AS c FROM schools WHERE conferences_id='{$r->id}'");
$numr=mysql_fetch_object($numq);
echo "<option value=\"{$r->id}\">{$r->name} ($numr->c schools)</option>\n";
}
echo "</select>\n";
echo "<input type=\"submit\" value=\"".i18n("Copy Schools")."\">";
echo "</form>\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 "<br />";
echo "<a href=\"schools.php?action=add\">".i18n("Add new school")."</a>\n";
echo "<br />";
echo "<a href=\"schools.php?action=copy\">".i18n("Copy schools from a difference conference")."</a>\n";
echo "<br />";
echo "<a href=\"schoolsimport.php?action=add\">".i18n("Import schools from CSV")."</a>\n";
echo "<br />";
echo "<a href=\"schools.php?action=makeaccesscodes\">".i18n("Create Access Code for any school without one")."</a>\n";
@ -413,10 +473,9 @@
echo " <td>$r->school</td>\n";
echo " <td>$r->address, $r->city, $r->postalcode</td>\n";
echo " <td>$r->phone</td>\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 " <td>$sciencehead</td>\n";