2009-10-11 19:49:21 +00:00
|
|
|
<?
|
2025-01-29 03:30:48 +00:00
|
|
|
require_once ('db.update.146.user.inc.php');
|
2009-10-11 19:49:21 +00:00
|
|
|
|
2025-01-29 03:30:48 +00:00
|
|
|
function db_update_146_pre() {}
|
2009-10-11 19:49:21 +00:00
|
|
|
|
|
|
|
function db_update_146_handle($name, $email, $phone, $type)
|
|
|
|
{
|
|
|
|
$un = $email;
|
|
|
|
list($first, $last) = split(' ', $name, 2);
|
|
|
|
|
|
|
|
/* Find the user */
|
2025-01-29 03:30:48 +00:00
|
|
|
if ($email != '') {
|
2009-10-22 16:20:17 +00:00
|
|
|
$u = db146_user_load_by_email($email);
|
2009-10-11 19:49:21 +00:00
|
|
|
} else {
|
|
|
|
$u = false;
|
|
|
|
/* Random username */
|
2025-01-29 03:30:48 +00:00
|
|
|
$un = "$first$last" . db146_user_generate_password();
|
2009-10-11 19:49:21 +00:00
|
|
|
}
|
|
|
|
|
2025-01-29 03:30:48 +00:00
|
|
|
if ($u != false) {
|
2009-10-11 19:49:21 +00:00
|
|
|
/* Found the user */
|
|
|
|
$u['types'][] = $type;
|
|
|
|
} else {
|
|
|
|
/* Create the user */
|
2009-10-22 16:20:17 +00:00
|
|
|
$u = db146_user_create($type, db146_user_generate_password());
|
2009-10-11 19:49:21 +00:00
|
|
|
$u['firstname'] = $first;
|
|
|
|
$u['lastname'] = $last;
|
|
|
|
$u['email'] = $email;
|
|
|
|
$u['username'] = $un;
|
|
|
|
$u['phone'] = $phone;
|
|
|
|
}
|
|
|
|
/* Save the user */
|
|
|
|
$uid = $u['uid'];
|
2009-10-22 16:20:17 +00:00
|
|
|
db146_user_save($u);
|
2009-10-11 19:49:21 +00:00
|
|
|
return $u;
|
|
|
|
}
|
|
|
|
|
2025-01-29 03:30:48 +00:00
|
|
|
function db_update_146_post()
|
2009-10-11 19:49:21 +00:00
|
|
|
{
|
2025-01-29 03:30:48 +00:00
|
|
|
global $config, $pdo;
|
2025-02-09 17:24:37 +00:00
|
|
|
$q = $pdo->prepare("SELECT * FROM schools WHERE year=?");
|
|
|
|
$q->execute([$config['FAIRYEAR']]);
|
2025-01-29 03:30:48 +00:00
|
|
|
while ($s = $q->fetch(PDO::FETCH_ASSOC)) {
|
2009-10-11 19:49:21 +00:00
|
|
|
/* Science head */
|
2025-01-29 03:30:48 +00:00
|
|
|
if (trim($s['sciencehead']) != '') {
|
2009-10-11 19:49:21 +00:00
|
|
|
$u = db_update_146_handle($s['sciencehead'],
|
2025-01-29 03:30:48 +00:00
|
|
|
$s['scienceheademail'],
|
|
|
|
$s['scienceheadphone'],
|
|
|
|
'teacher');
|
|
|
|
if ($u != false) {
|
2025-02-09 17:24:37 +00:00
|
|
|
$stmt = $pdo->prepare("UPDATE schools SET sciencehead_uid=? WHERE id=?");
|
|
|
|
$stmt->execute([$u['uid'],$s['id']]);
|
2009-10-11 19:49:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now the principal */
|
2025-01-29 03:30:48 +00:00
|
|
|
if (trim($s['principal']) != '') {
|
2009-10-11 19:49:21 +00:00
|
|
|
$u = db_update_146_handle($s['principal'],
|
2025-01-29 03:30:48 +00:00
|
|
|
$s['schoolemail'],
|
|
|
|
$s['phone'],
|
|
|
|
'principal');
|
|
|
|
if ($u != false) {
|
2025-02-09 17:24:37 +00:00
|
|
|
$stmt = $pdo->prepare("UPDATE schools SET principal_uid=? WHERE id=?");
|
|
|
|
$stmt->execute([$u['uid'],$s['id']]);
|
2025-01-29 03:30:48 +00:00
|
|
|
}
|
2009-10-11 19:49:21 +00:00
|
|
|
}
|
2025-01-29 03:30:48 +00:00
|
|
|
}
|
2009-10-11 19:49:21 +00:00
|
|
|
}
|
|
|
|
?>
|
|
|
|
|