forked from science-ation/science-ation
1b426bcf69
Replace some deprecated PHP functions with their appropriate equivalents
152 lines
5.5 KiB
PHP
152 lines
5.5 KiB
PHP
<?
|
|
/*
|
|
This file is part of the 'Science Fair In A Box' project
|
|
SFIAB Website: http://www.sfiab.ca
|
|
|
|
Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
|
|
Copyright (C) 2005 James Grant <james@lightbox.org>
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU General Public
|
|
License as published by the Free Software Foundation, version 2.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; see the file COPYING. If not, write to
|
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
Boston, MA 02111-1307, USA.
|
|
*/
|
|
?>
|
|
<?
|
|
require("../common.inc.php");
|
|
require_once("../user.inc.php");
|
|
require("../csvimport.inc.php");
|
|
|
|
user_auth_required('committee', 'admin');
|
|
|
|
send_header("Schools Import",
|
|
array('Committee Main' => 'committee_main.php',
|
|
'Administration' => 'admin/index.php',
|
|
'School Management' => 'admin/schools.php')
|
|
);
|
|
|
|
$showform=true;
|
|
|
|
if($_POST['action']=="import")
|
|
{
|
|
if(!$_FILES['schools']['error'] && $_FILES['schools']['size']>0)
|
|
{
|
|
$showform=false;
|
|
$CSVP=new CSVParser();
|
|
$CSVP->parseFile($_FILES['schools']['tmp_name']);
|
|
if(count($CSVP->data)>0)
|
|
{
|
|
//okay it looks like we have something.. lets dump the current stuff
|
|
if($_POST['emptycurrent']==1)
|
|
{
|
|
echo happy(i18n("Old school data erased"));
|
|
mysql_query("DELETE FROM schools WHERE year='".$config['FAIRYEAR']."'");
|
|
}
|
|
|
|
$loaded=0;
|
|
foreach($CSVP->data AS $row)
|
|
{
|
|
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]))."',
|
|
'".mysql_escape_string(stripslashes($row[3]))."',
|
|
'".mysql_escape_string(stripslashes($row[4]))."',
|
|
'".mysql_escape_string(stripslashes($row[5]))."',
|
|
'".mysql_escape_string(stripslashes($row[6]))."',
|
|
'".mysql_escape_string(stripslashes($row[7]))."',
|
|
'".mysql_escape_string(stripslashes($row[8]))."',
|
|
'".mysql_escape_string(stripslashes($row[9]))."',
|
|
'".mysql_escape_string(stripslashes($row[10]))."',
|
|
'".mysql_escape_string(stripslashes($row[14]))."',
|
|
'".mysql_escape_string(stripslashes($row[18]))."',
|
|
'".mysql_escape_string(stripslashes($row[19]))."',
|
|
'".mysql_escape_string(stripslashes($row[20]))."',
|
|
'".mysql_escape_string(stripslashes($row[21]))."',
|
|
'".$config['FAIRYEAR']."',
|
|
'".$principal['uid']."',
|
|
'".$scienceHead['uid']."')");
|
|
if(!mysql_Error())
|
|
$loaded++;
|
|
else
|
|
echo mysql_error();
|
|
}
|
|
echo happy(i18n("Successfully loaded %1 schools",array($loaded)));
|
|
echo "<a href=\"schools.php\">".i18n("School Management")."</a> <br />";
|
|
}
|
|
else
|
|
{
|
|
echo error(i18n("Found no CSV data in the uploaded file"));
|
|
}
|
|
print_r($data);
|
|
}
|
|
else
|
|
{
|
|
echo error(i18n("Please choose a valid CSV file to upload"));
|
|
$showform=true;
|
|
}
|
|
}
|
|
|
|
if($showform)
|
|
{
|
|
echo "<br />";
|
|
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, 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 />";
|
|
echo "<form enctype=\"multipart/form-data\" action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">";
|
|
echo "<input type=\"hidden\" name=\"action\" value=\"import\">";
|
|
echo "<input type=\"checkbox\" name=\"emptycurrent\" value=\"1\">".i18n("Empty all current school information before importing?")."<br />";
|
|
echo "<input type=\"file\" name=\"schools\">";
|
|
echo "<input type=\"submit\" value=\"".i18n("Upload School CSV")."\">\n";
|
|
echo "</form>";
|
|
|
|
}
|
|
|
|
send_footer();
|
|
|
|
?>
|