2007-09-20 17:26:18 +00:00
< ?
2025-01-29 03:30:48 +00:00
/*
* 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 >
2025-02-10 19:54:20 +00:00
* Copyright ( C ) 2024 AlgoLibre Inc . < science - ation @ algolibre . io >
2025-01-29 03:30:48 +00:00
*
* 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 .
*/
2007-09-20 17:26:18 +00:00
2025-01-29 03:30:48 +00:00
// THIS FILE IS NEEDED to fix a bug in the rollover script that some people might have already used
// the prizes werent properly rolled over, so if it detects that there are no prizes this year but there were
// prizes last year, it re-rolls the prizes over properly.
// it only does this if the number of awards matchces exactly (aka hasnt been modified yet since the rollover)
// it is safe to include this script at any point, since it does all the checks required.
// this file will eventually be deleted
2007-09-20 17:31:43 +00:00
2025-01-29 03:30:48 +00:00
// we know the years needed, so hardcode them in
$currentfairyear = 2007 ;
$newfairyear = 2008 ;
// first make sure they have indeed done the rollover...
if ( $config [ 'FAIRYEAR' ] == 2008 ) {
// make sure the number of awards are identical (aka they havent added any new ones)
$nq1 = $pdo -> prepare ( " SELECT * FROM award_awards WHERE year=' $newfairyear ' " );
2024-12-08 02:42:00 -05:00
$nq1 -> execute ();
2025-01-29 03:30:48 +00:00
$nq2 = $pdo -> prepare ( " SELECT * FROM award_awards WHERE year=' $currentfairyear ' " );
2024-12-08 02:42:00 -05:00
$nq2 -> execute ();
2025-01-29 03:30:48 +00:00
if ( $nq1 -> rowCount () == $nq2 -> rowcount ()) {
$npq1 = $pdo -> prepare ( " SELECT * FROM award_prizes WHERE year=' $newfairyear ' " );
2024-12-08 02:42:00 -05:00
$npq1 -> execute ();
2025-01-29 03:30:48 +00:00
$npq2 = $pdo -> prepare ( " SELECT * FROM award_prizes WHERE year=' $currentfairyear ' " );
2024-12-08 02:42:00 -05:00
$npq2 -> execute ();
2007-09-20 17:26:18 +00:00
2025-01-29 03:30:48 +00:00
if ( $npq2 -> rowCount () > 0 && $npq1 -> rowCount () == 0 ) {
echo '<br />' ;
echo notice ( i18n ( 'A BUG WAS IDENTIFIED IN YOUR PREVIOUS YEAR ROLLOVER WHICH CAUSED AWARD PRIZES TO NOT BE ROLLED OVER PROPERLY. THEY ARE NOW BEING RE-ROLLED OVER WITH THE PROPER PRIZE INFORMATION. THIS WILL ONLY HAPPEN ONCE.' )) . '<br />' ;
$stmt = $pdo -> prepare ( " DELETE FROM award_awards WHERE year=' $newfairyear ' " );
$stmt -> execute ();
$stmt = $pdo -> prepare ( " DELETE FROM award_prizes WHERE year=' $newfairyear ' " );
$stmt -> execute ();
$stmt = $pdo -> prepare ( " DELETE FROM award_contacts WHERE year=' $newfairyear ' " );
$stmt -> execute ();
$stmt = $pdo -> prepare ( " DELETE FROM award_types WHERE year=' $newfairyear ' " );
$stmt -> execute ();
$stmt = $pdo -> prepare ( " DELETE FROM award_awards_projectcategories WHERE year=' $newfairyear ' " );
$stmt -> execute ();
$stmt = $pdo -> prepare ( " DELETE FROM award_awards_projectdivisions WHERE year=' $newfairyear ' " );
$stmt -> execute ();
2007-09-20 17:26:18 +00:00
2025-01-29 03:30:48 +00:00
echo i18n ( 'Rolling awards' ) . '<br />' ;
// awards
$q = $pdo -> prepare ( " SELECT * FROM award_awards WHERE year=' $currentfairyear ' " );
$q -> execute ();
2025-01-03 15:15:13 -05:00
show_pdo_errors_if_any ( $pdo );
2025-01-29 03:30:48 +00:00
while ( $r = $q -> fetch ( PDO :: FETCH_OBJ )) {
$stmt = $pdo -> prepare ( " INSERT INTO award_awards (award_sponsors_id,award_types_id,name,criteria,presenter,`order`,year,excludefromac,cwsfaward) VALUES (
'" . $r->award_sponsors_id . "' ,
'" . $r->award_types_i . "' ,
'" . $r->name . "' ,
'" . $r->criteria . "' ,
'" . $r->presenter . "' ,
'" . $r->order . "' ,
'" . $newfairyear . "' ,
'" . $r->excludefromac . "' ,
'" . $r->cwsfaward . "' ) " );
$award_awards_id = $pdo -> lastInsertId ();
2007-09-20 17:26:18 +00:00
2025-01-29 03:30:48 +00:00
$q2 = $pdo -> prepare ( " SELECT * FROM award_awards_projectcategories WHERE year=' $currentfairyear ' AND award_awards_id=' $r->id ' " );
$q2 -> execute ();
show_pdo_errors_if_any ( $pdo );
while ( $r2 = $q2 -> fetch ( PDO :: FETCH_OBJ )) {
$stmt = $pdo -> prepare ( " INSERT INTO award_awards_projectcategories (award_awards_id,projectcategories_id,year) VALUES (
'" . $award_awards_id . "' ,
'" . $r2->projectcategories_id . "' ,
'" . $newfairyear . "' ) " );
$stmt -> execute ();
}
2007-09-20 17:26:18 +00:00
2025-01-29 03:30:48 +00:00
$q2 = $pdo -> prepare ( " SELECT * FROM award_awards_projectdivisions WHERE year=' $currentfairyear ' AND award_awards_id=' $r->id ' " );
$q2 -> execute ();
show_pdo_errors_if_any ( $pdo );
while ( $r2 = $q2 -> fetch ( PDO :: FETCH_OBJ )) {
$stmt = $pdo -> prepare ( " INSERT INTO award_awards_projectdivisions (award_awards_id,projectdivisions_id,year) VALUES (
'" . $award_awards_id . "' ,
'" . $r2->projectdivisions_id . "' ,
'" . $newfairyear . "' ) " );
$stmt -> execute ();
}
2007-09-20 17:26:18 +00:00
2025-01-29 03:30:48 +00:00
echo i18n ( ' Rolling award prizes' ) . '<br />' ;
$q2 = $pdo -> prepare ( " SELECT * FROM award_prizes WHERE year=' $currentfairyear ' AND award_awards_id=' $r->id ' " );
$q2 -> execute ();
show_pdo_errors_if_any ( $pdo );
while ( $r2 = $q2 -> fetch ( PDO :: FETCH_OBJ )) {
$stmt = $pdo -> prepare ( " INSERT INTO award_prizes (award_awards_id,cash,scholarship,`value`,prize,number,`order`,year,excludefromac) VALUES (
'" . $award_awards_id . "' ,
'" . $r2->cash . "' ,
'" . $r2->scholarship . "' ,
'" . $r2->value . "' ,
'" . $r2->prize . "' ,
'" . $r2->number . "' ,
'" . $r2->order . "' ,
'" . $newfairyear . "' ,
'" . $r2->excludefromac . "' ) " );
}
2007-09-20 17:26:18 +00:00
}
2025-01-29 03:30:48 +00:00
echo i18n ( 'Rolling award contacts' ) . '<br />' ;
// award contacts
$q = $pdo -> prepare ( " SELECT * FROM award_contacts WHERE year=' $currentfairyear ' " );
$q -> execute ();
2025-01-03 15:15:13 -05:00
show_pdo_errors_if_any ( $pdo );
2025-01-29 03:30:48 +00:00
while ( $r = $q -> fetch ( PDO :: FETCH_OBJ ))
$stmt = $pdo -> prepare ( " INSERT INTO award_contacts (award_sponsors_id,salutation,firstname,lastname,position,email,phonehome,phonework,phonecell,fax,notes,year) VALUES (
'" . $r->award_sponsors_id . "' ,
'" . $r->salutation . "' ,
'" . $r->firstname . "' ,
'" . $r->lastname . "' ,
'" . $r->position . "' ,
'" . $r->email . "' ,
'" . $r->phonehome . "' ,
'" . $r->phonework . "' ,
'" . $r->phonecell . "' ,
'" . $r->fax . "' ,
'" . $r->notes . "' ,
'" . $newfairyear . "' ) " );
2007-09-20 17:26:18 +00:00
2025-01-29 03:30:48 +00:00
echo i18n ( 'Rolling award types' ) . '<br />' ;
// award types
$q = $pdo -> prepare ( " SELECT * FROM award_types WHERE year=' $currentfairyear ' " );
$q -> execute ();
show_pdo_errors_if_any ( $pdo );
while ( $r = $q -> fetch ( PDO :: FETCH_OBJ ))
$stmt = $pdo -> prepare ( " INSERT INTO award_types (id,type,`order`,year) VALUES (
'" . $r->id . "' ,
'" . $r->type . "' ,
'" . $r->order . "' ,
'" . $newfairyear . "' ) " );
2024-12-08 02:42:00 -05:00
$stmt -> execute ();
2007-09-20 17:26:18 +00:00
}
}
2025-01-29 03:30:48 +00:00
}