From 1b426bcf691213f5c8acf69d84925cd62989e619 Mon Sep 17 00:00:00 2001 From: jacob Date: Thu, 8 Dec 2011 22:41:49 +0000 Subject: [PATCH] Updated admin/schoolsimport.php to properly handle v2.3 shool imports. Replace some deprecated PHP functions with their appropriate equivalents --- admin/schoolsimport.php | 47 +++++++++++++++++++++++++++++++++-------- common.inc.php | 2 +- schoolaccess.php | 2 +- user.inc.php | 4 ++-- 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/admin/schoolsimport.php b/admin/schoolsimport.php index 54fb25c0..10a079b8 100644 --- a/admin/schoolsimport.php +++ b/admin/schoolsimport.php @@ -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 "
"; echo "
"; - 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 "
"; echo "
"; diff --git a/common.inc.php b/common.inc.php index 84755280..3c2e62e6 100644 --- a/common.inc.php +++ b/common.inc.php @@ -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; diff --git a/schoolaccess.php b/schoolaccess.php index 7a22d612..de1e6da8 100644 --- a/schoolaccess.php +++ b/schoolaccess.php @@ -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 diff --git a/user.inc.php b/user.inc.php index e21ca25a..7ee86eb3 100644 --- a/user.inc.php +++ b/user.inc.php @@ -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; }