Updated admin/schoolsimport.php to properly handle v2.3 shool imports.

Replace some deprecated PHP functions with their appropriate equivalents
This commit is contained in:
jacob 2011-12-08 22:41:49 +00:00
parent dbf4c71e1f
commit 1b426bcf69
4 changed files with 42 additions and 13 deletions

@ -55,7 +55,38 @@
$loaded=0;
foreach($CSVP->data AS $row)
{
mysql_query("INSERT INTO schools (school,schoollang,schoollevel,board,district,phone,fax,address,city,province_code,postalcode,principal,schoolemail,sciencehead,scienceheademail,scienceheadphone,accesscode,registration_password,projectlimit,projectlimitper,year) VALUES (
for($n = 0; $n < count($row); $n++){
$row[$n] = trim($row[$n]);
}
$email = $row[16];
if($email != ''){
$scienceHead = user_load_by_email($email);
if(!$scienceHead){
$scienceHead = user_create('teacher', $email);
$scienceHead['email'] = $email;
}
list($first, $last) = explode(' ', $row[15], 2);
$scienceHead['firstname'] = $first;
$scienceHead['lastname'] = $last;
$scienceHead['phonework'] = $row[17];
user_save($scienceHead);
}
$email = $row[12];
if($email != ''){
$principal = user_load_by_email($email);
if(!$principal){
$principal = user_create('principal', $email);
$principal['email'] = $email;
}
list($first, $last) = explode(' ', $row[11], 2);
$principal['firstname'] = $first;
$principal['lastname'] = $last;
$principal['phonework'] = $row[13];
user_save($principal);
}
mysql_query("INSERT INTO schools (school,schoollang,schoollevel,board,district,phone,fax,address,city,province_code,postalcode,schoolemail,accesscode,registration_password,projectlimit,projectlimitper,year,principal_uid,sciencehead_uid) VALUES (
'".mysql_escape_string(stripslashes($row[0]))."',
'".mysql_escape_string(stripslashes($row[1]))."',
'".mysql_escape_string(stripslashes($row[2]))."',
@ -67,16 +98,14 @@
'".mysql_escape_string(stripslashes($row[8]))."',
'".mysql_escape_string(stripslashes($row[9]))."',
'".mysql_escape_string(stripslashes($row[10]))."',
'".mysql_escape_string(stripslashes($row[11]))."',
'".mysql_escape_string(stripslashes($row[12]))."',
'".mysql_escape_string(stripslashes($row[13]))."',
'".mysql_escape_string(stripslashes($row[14]))."',
'".mysql_escape_string(stripslashes($row[15]))."',
'".mysql_escape_string(stripslashes($row[16]))."',
'".mysql_escape_string(stripslashes($row[17]))."',
'".mysql_escape_string(stripslashes($row[18]))."',
'".mysql_escape_string(stripslashes($row[19]))."',
'".$config['FAIRYEAR']."')");
'".mysql_escape_string(stripslashes($row[20]))."',
'".mysql_escape_string(stripslashes($row[21]))."',
'".$config['FAIRYEAR']."',
'".$principal['uid']."',
'".$scienceHead['uid']."')");
if(!mysql_Error())
$loaded++;
else
@ -104,7 +133,7 @@
echo i18n("Choose the CSV file containing the school information. The COLUMNS of the file must contain the following information, in this exact order, separated by comma's (,) with fields optionally enclosed by quotes (\"):");
echo "<br />";
echo "<br />";
echo i18n("School Name, School Lang, School Level, Board, District, Phone, Fax, Address, City, %1, %2, Principal, School Email, Science Head, Science Head Email, Science Head Phone, Access Code, Registration Password, Project Limit, Project Limit Per(total or agecategory)",array(i18n($config['provincestate']),i18n($config['postalzip'])));
echo i18n("School Name, School Lang, School Level, Board, District, Phone, Fax, Address, City, %1, %2, Principal, Principal Email, Principal Phone, School Email, Science Head, Science Head Email, Science Head Phone, Access Code, Registration Password, Project Limit, Project Limit Per(total or agecategory)",array(i18n($config['provincestate']),i18n($config['postalzip'])));
echo "<br />";
echo "<br />";

@ -921,7 +921,7 @@ function outputStatus($status)
//returns true if its a valid email address, false if its not
function isEmailAddress($str) {
if(eregi('^[+a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$', $str))
if(preg_match('/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$/i', $str))
return true;
else
return false;

@ -36,7 +36,7 @@ if($_SESSION['schoolid'] && $_SESSION['schoolaccesscode'])
/* Get info about science head */
$sciencehead_update = '';
list($first, $last) = split(' ', $_POST['sciencehead'], 2);
list($first, $last) = explode(' ', $_POST['sciencehead'], 2);
$em = $_POST['scienceheademail'];
if($em == '' && ($first != '' || $last != '')) $em = "*$first$last".user_generate_password();
/* Load existing record, or create new if there's something

@ -237,7 +237,7 @@ function user_load($user, $uid = false)
if( ($ret['firstname'] || $ret['lastname']) && $ret['email']) {
//use their full name if we have it
//if the name contains anything non-standard, we need to quote it.
if(eregi("[^a-z0-9 ]",$ret['name']))
if(preg_match("/[^a-z0-9 ]/i",$ret['name']))
$ret['emailrecipient']="\"{$ret['name']}\" <{$ret['email']}>";
else
$ret['emailrecipient']="{$ret['name']} <{$ret['email']}>";
@ -806,7 +806,7 @@ function user_valid_password($pass)
/* A more strict version of isEmailAddress() */
function user_valid_email($str)
{
if(eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$', $str))
if(preg_match('/^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$/i', $str))
return true;
return false;
}