forked from science-ation/science-ation
Fixes for import and display
This commit is contained in:
parent
7074f1db1d
commit
ec5697662a
@ -98,7 +98,7 @@ if (get_value_from_array($_POST, 'save') == 'edit' || get_value_from_array($_POS
|
||||
|
||||
/* Get info about science head */
|
||||
// FIX ME
|
||||
$split = explode(' ', get_value_from_array($_POST, 'principal') ?? '', 2);
|
||||
$split = explode(' ', get_value_from_array($_POST, 'principal', ''), 2);
|
||||
|
||||
if (count($split) === 2) {
|
||||
list($first, $last) = $split;
|
||||
@ -239,6 +239,7 @@ if (get_value_from_array($_GET, 'action') == 'edit' || get_value_from_array($_GE
|
||||
echo '<option value="">' . i18n('Choose') . "</option>\n";
|
||||
|
||||
foreach ($config['languages'] AS $k => $l) {
|
||||
$sel = ($r->schoollang == $k) ? 'selected="selected"' : '';
|
||||
echo "<option $sel value=\"$k\">" . i18n($l) . "</option>\n";
|
||||
}
|
||||
echo '</select>';
|
||||
|
@ -49,77 +49,84 @@ 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]);
|
||||
$row[$n] = trim(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', $config['FAIRYEAR']);
|
||||
$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())
|
||||
if ($pdo->errorInfo() != '00000') {
|
||||
$loaded++;
|
||||
else
|
||||
} else {
|
||||
show_pdo_errors_if_any($pdo);
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user