science-ation/scripts/rolloverschools.php

90 lines
3.0 KiB
PHP

<?
/*
* This file is part of the Science-ation project
* Science-ation Website: https://science-ation.ca
*
* This file was part of the 'Science Fair In A Box' project
*
*
* Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
* Copyright (C) 2005 James Grant <james@lightbox.org>
* Copyright (C) 2024 AlgoLibre Inc. <science-ation@algolibre.io>
*
* 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_once ('../config_editor.inc.php');
function roll($currentfairyear, $newfairyear, $table, $fields)
{
global $pdo;
$q = $pdo->prepare("SELECT * FROM $table WHERE year=?");
$q->execute([$currentfairyear]);
show_pdo_errors_if_any($pdo);
$names = '`' . join('`,`', $fields) . '`';
while ($r = $q->fetch(PDO::FETCH_ASSOC)) {
$vals = '';
foreach ($fields as $f) {
$vals .= ",'" . $r[$f] . "'";
}
$stmt = $pdo->prepare("INSERT INTO $table(`year`,?) VALUES (?,?)");
$stmt->execute([$names,$newfairyear,$vals]);
show_pdo_errors_if_any($pdo);
}
}
$currentfairyear = 2009;
$newfairyear = 2010;
echo i18n('Rolling schools') . '<br />';
// award types
$q = $pdo->prepare("SELECT * FROM schools WHERE year=?");
$q->execute([$currentfairyear]);
show_pdo_errors_if_any($pdo);
while ($r = $q->fetch(PDO::FETCH_OBJ)) {
$puid = ($r->principal_uid == null) ? 'NULL' : ("'" . intval($r->principal_uid) . "'");
$shuid = ($r->sciencehead_uid == null) ? 'NULL' : ("'" . intval($r->sciencehead_uid) . "'");
$stmt = $pdo->prepare("INSERT INTO schools (school,schoollang,schoollevel,board,district,phone,fax,address,city,province_code,postalcode,principal_uid,schoolemail,sciencehead_uid,accesscode,lastlogin,junior,intermediate,senior,registration_password,projectlimit,projectlimitper,year) VALUES (
'" . $r->school . "',
'" . $r->schoollang . "',
'" . $r->schoollevel . "',
'" . $r->board . "',
'" . $r->district . "',
'" . $r->phone . "',
'" . $r->fax . "',
'" . $r->address . "',
'" . $r->city . "',
'" . $r->province_code . "',
'" . $r->postalcode . "',$puid,
'" . $r->schoolemail . "',$shuid,
'" . $r->accesscode . "',
NULL,
'" . $r->junior . "',
'" . $r->intermediate . "',
'" . $r->senior . "',
'" . $r->registration_password . "',
'" . $r->projectlimit . "',
'" . $r->projectlimitper . "',
'" . $newfairyear . "')");
$stmt->execute();
}
?>