Repair csv splitting

This commit is contained in:
arman 2025-02-15 23:13:35 +00:00
parent 55753f0bec
commit 76f2d5c214

View File

@ -49,64 +49,71 @@ if (get_value_from_array($_POST, 'action') == 'import') {
// okay it looks like we have something.. lets dump the current stuff
if ($_POST['emptycurrent'] == 1) {
echo happy(i18n('Old school data erased'));
$stmt = $pdo->prepare("DELETE FROM schools WHERE year=?");
$stmt = $pdo->prepare('DELETE FROM schools WHERE year=?');
$stmt->execute([$config['FAIRYEAR']]);
}
$loaded = 0;
foreach ($CSVP->data AS $row) {
foreach ($CSVP->data AS $raw_row) {
$row = explode(',', $raw_row[0]);
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[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);
}
// $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);
// }
$stmt = $pdo->prepare('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
(:school, :schoollang, :schoollevel, :board, :district, :phone, :fax, :address, :city, :province_code, :postalcode, :schoolemail, :accesscode, :registration_password, :projectlimit, :projectlimitper, :year, :principal_uid, :sciencehead_uid)');
$stmt->bindParam(':school', $row[0]);
$stmt->bindParam(':schoollang', $row[1]);
$stmt->bindParam(':schoollevel', $row[2]);
$stmt->bindParam(':board', $row[3]);
$stmt->bindParam(':district', $row[4]);
$stmt->bindParam(':phone', $row[5]);
$stmt->bindParam(':fax', $row[6]);
$stmt->bindParam(':address', $row[7]);
$stmt->bindParam(':city', $row[8]);
$stmt->bindParam(':province_code', $row[9]);
$stmt->bindParam(':postalcode', $row[10]);
$stmt->bindParam(':schoolemail', $row[11]);
$stmt->bindParam(':accesscode', $row[12]);
$stmt->bindParam(':registration_password', $row[13]);
$stmt->bindParam(':projectlimit', $row[14]);
$stmt->bindParam(':projectlimitper', $row[15]);
$stmt->bindParam(':year', $row[16]);
$stmt->bindParam(':principal_uid', $principal['uid']);
$stmt->bindParam(':sciencehead_uid', $scienceHead['uid']);
$stmt = $pdo->prepare("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 (
'" . stripslashes($row[0]) . "',
'" . stripslashes($row[1]) . "',
'" . stripslashes($row[2]) . "',
'" . stripslashes($row[3]) . "',
'" . stripslashes($row[4]) . "',
'" . stripslashes($row[5]) . "',
'" . stripslashes($row[6]) . "',
'" . stripslashes($row[7]) . "',
'" . stripslashes($row[8]) . "',
'" . stripslashes($row[9]) . "',
'" . stripslashes($row[10]) . "',
'" . stripslashes($row[14]) . "',
'" . stripslashes($row[18]) . "',
'" . stripslashes($row[19]) . "',
'" . stripslashes($row[20]) . "',
'" . stripslashes($row[21]) . "',
'" . $config['FAIRYEAR'] . "',
'" . $principal['uid'] . "',
'" . $scienceHead['uid'] . "')");
$stmt->execute();
if (!$pdo->errorInfo())