2005-11-21 19:36:48 +00:00
< ?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website : http :// www . sfiab . ca
Copyright ( C ) 2005 Sci - Tech Ontario Inc < info @ scitechontario . org >
Copyright ( C ) 2005 James Grant < james @ lightbox . org >
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 " );
2007-11-21 17:04:35 +00:00
require_once ( " ../user.inc.php " );
2007-11-25 19:53:15 +00:00
require_once ( " ../config_editor.inc.php " );
2007-11-19 00:33:38 +00:00
user_auth_required ( 'committee' , 'config' );
send_header ( " Year Rollover " ,
array ( 'Committee Main' => 'committee_main.php' ,
'SFIAB Configuration' => 'config/index.php' )
2008-08-22 20:34:38 +00:00
, " rollover_fair_year "
2007-11-19 00:33:38 +00:00
);
2005-11-21 19:36:48 +00:00
?>
< script language = " javascript " type = " text/javascript " >
function confirmYearRollover ()
{
var currentyear =< ? = $config [ 'FAIRYEAR' ] ?> ;
var nextyear = document . forms . rollover . nextfairyear . value ;
if ( nextyear < currentyear )
alert ( 'You cannot roll backwards in years!' );
else if ( nextyear == currentyear )
alert ( 'You cannot roll to the same year!' );
else
{
var okay = confirm ( 'Are you sure you want to roll the FAIRYEAR from ' + currentyear + ' to ' + nextyear + '? This can not be undone and should only be done if you are absolutely sure!' );
if ( okay )
return true ;
}
return false ;
}
</ script >
< ?
if ( $_POST [ 'action' ] == " rollover " && $_POST [ 'nextfairyear' ])
{
$newfairyear = $_POST [ 'nextfairyear' ];
$currentfairyear = $config [ 'FAIRYEAR' ];
if ( $newfairyear < $currentfairyear )
echo error ( i18n ( " You cannot roll backwards in years! " ));
else if ( $newfairyear == $currentfairyear )
echo error ( i18n ( " You cannot roll to the same year! " ));
else
{
//okay here we go! this is going to get to be a pretty big script me thinks!
//first, lets do all of the configuration variables
echo i18n ( " Rolling configuration variables " ) . " <br /> " ;
2007-11-25 19:53:15 +00:00
config_update_variables ( $newfairyear , $currentfairyear );
2005-11-21 19:36:48 +00:00
//now the dates
echo i18n ( " Rolling dates " ) . " <br /> " ;
$q = mysql_query ( " SELECT DATE_ADD(date,INTERVAL 365 DAY) AS newdate,name,description FROM dates WHERE year=' $currentfairyear ' " );
echo mysql_error ();
while ( $r = mysql_fetch_object ( $q ))
mysql_query ( " INSERT INTO dates (date,name,description,year) VALUES (
'".mysql_escape_string($r->newdate)."' ,
'".mysql_escape_string($r->name)."' ,
'".mysql_escape_string($r->description)."' ,
'".mysql_escape_string($newfairyear)."' ) " );
//page text
echo i18n ( " Rolling page texts " ) . " <br /> " ;
$q = mysql_query ( " SELECT * FROM pagetext WHERE year=' $currentfairyear ' " );
echo mysql_error ();
while ( $r = mysql_fetch_object ( $q ))
2008-08-27 20:01:07 +00:00
mysql_query ( " INSERT INTO pagetext (textname,textdescription,text,lastupdate,year,lang) VALUES (
2005-11-21 19:36:48 +00:00
'".mysql_escape_string($r->textname)."' ,
2008-08-27 19:33:56 +00:00
'".mysql_escape_string($r->textdescription)."' ,
2005-11-21 19:36:48 +00:00
'".mysql_escape_string($r->text)."' ,
2008-08-27 20:01:07 +00:00
'".mysql_escape_string($r->lastupdate)."' ,
2008-08-27 19:33:56 +00:00
'".mysql_escape_string($newfairyear)."' ,
'".mysql_escape_string($r->lang)."' ) " );
2005-11-21 19:36:48 +00:00
echo i18n ( " Rolling project categories " ) . " <br /> " ;
//project categories
$q = mysql_query ( " SELECT * FROM projectcategories WHERE year=' $currentfairyear ' " );
echo mysql_error ();
while ( $r = mysql_fetch_object ( $q ))
2008-08-27 19:33:56 +00:00
mysql_query ( " INSERT INTO projectcategories (id,category,category_shortform,mingrade,maxgrade,year) VALUES (
2005-11-21 19:36:48 +00:00
'".mysql_escape_string($r->id)."' ,
'".mysql_escape_string($r->category)."' ,
2008-08-27 19:33:56 +00:00
'".mysql_escape_string($r->category_shortform)."' ,
2005-11-21 19:36:48 +00:00
'".mysql_escape_string($r->mingrade)."' ,
'".mysql_escape_string($r->maxgrade)."' ,
'".mysql_escape_string($newfairyear)."' ) " );
echo i18n ( " Rolling project divisions " ) . " <br /> " ;
//project divisions
$q = mysql_query ( " SELECT * FROM projectdivisions WHERE year=' $currentfairyear ' " );
echo mysql_error ();
while ( $r = mysql_fetch_object ( $q ))
2008-08-27 19:33:56 +00:00
mysql_query ( " INSERT INTO projectdivisions (id,division,division_shortform,cwsfdivisionid,year) VALUES (
2005-11-21 19:36:48 +00:00
'".mysql_escape_string($r->id)."' ,
'".mysql_escape_string($r->division)."' ,
'".mysql_escape_string($r->division_shortform)."' ,
2008-08-27 19:33:56 +00:00
'".mysql_escape_string($r->cwsfdivisionid)."' ,
2005-11-21 19:36:48 +00:00
'".mysql_escape_string($newfairyear)."' ) " );
2007-12-07 22:12:16 +00:00
echo i18n ( " Rolling project category-division links " ) . " <br /> " ;
//project categories divisions links
$q = mysql_query ( " SELECT * FROM projectcategoriesdivisions_link WHERE year=' $currentfairyear ' " );
echo mysql_error ();
while ( $r = mysql_fetch_object ( $q ))
mysql_query ( " INSERT INTO projectcategoriesdivisions_link (projectdivisions_id,projectcategories_id,year) VALUES (
'".mysql_escape_string($r->projectdivisions_id)."' ,
'".mysql_escape_string($r->projectcategories_id)."' ,
'".mysql_escape_string($newfairyear)."' ) " );
2005-11-21 19:36:48 +00:00
echo i18n ( " Rolling project sub-divisions " ) . " <br /> " ;
//project subdivisions
$q = mysql_query ( " SELECT * FROM projectsubdivisions WHERE year=' $currentfairyear ' " );
echo mysql_error ();
while ( $r = mysql_fetch_object ( $q ))
mysql_query ( " INSERT INTO projectsubdivisions (id,projectdivisions_id,subdivision,year) VALUES (
'".mysql_escape_string($r->id)."' ,
'".mysql_escape_string($r->projectsubdivisions_id)."' ,
'".mysql_escape_string($r->subdivision)."' ,
'".mysql_escape_string($newfairyear)."' ) " );
echo i18n ( " Rolling safety questions " ) . " <br /> " ;
//safety questions
$q = mysql_query ( " SELECT * FROM safetyquestions WHERE year=' $currentfairyear ' " );
echo mysql_error ();
while ( $r = mysql_fetch_object ( $q ))
mysql_query ( " INSERT INTO safetyquestions (question,type,required,ord,year) VALUES (
'".mysql_escape_string($r->question)."' ,
'".mysql_escape_string($r->type)."' ,
'".mysql_escape_string($r->required)."' ,
'".mysql_escape_string($r->ord)."' ,
'".mysql_escape_string($newfairyear)."' ) " );
2006-07-26 14:38:21 +00:00
echo i18n ( " Unconfirming award sponsors " ) . " <br /> " ;
mysql_query ( " UPDATE award_sponsors SET confirmed='no' " );
2005-11-21 19:36:48 +00:00
echo i18n ( " Rolling awards " ) . " <br /> " ;
//awards
$q = mysql_query ( " SELECT * FROM award_awards WHERE year=' $currentfairyear ' " );
echo mysql_error ();
while ( $r = mysql_fetch_object ( $q ))
{
2007-11-29 18:25:56 +00:00
mysql_query ( " INSERT INTO award_awards (award_sponsors_id,award_types_id,name,criteria,description,presenter,`order`,year,excludefromac,cwsfaward,external_identifier,external_postback,award_sources_id) VALUES (
2005-11-21 19:36:48 +00:00
'".mysql_escape_string($r->award_sponsors_id)."' ,
'".mysql_escape_string($r->award_types_id)."' ,
'".mysql_escape_string($r->name)."' ,
'".mysql_escape_string($r->criteria)."' ,
2007-11-23 21:25:52 +00:00
'".mysql_escape_string($r->description)."' ,
2005-11-21 19:36:48 +00:00
'".mysql_escape_string($r->presenter)."' ,
'".mysql_escape_string($r->order)."' ,
2006-10-25 01:16:48 +00:00
'".mysql_escape_string($newfairyear)."' ,
'".mysql_escape_string($r->excludefromac)."' ,
2007-11-29 18:25:56 +00:00
'".mysql_escape_string($r->cwsfaward)."' ,
'".mysql_escape_string($r->external_identifier)."' ,
'".mysql_escape_string($r->external_postaback)."' ,
'".mysql_escape_string($r->award_sources_id)."'
) " );
2005-11-21 19:36:48 +00:00
$award_awards_id = mysql_insert_id ();
$q2 = mysql_query ( " SELECT * FROM award_awards_projectcategories WHERE year=' $currentfairyear ' AND award_awards_id=' $r->id ' " );
echo mysql_error ();
while ( $r2 = mysql_fetch_object ( $q2 ))
{
mysql_query ( " INSERT INTO award_awards_projectcategories (award_awards_id,projectcategories_id,year) VALUES (
'".mysql_escape_string($award_awards_id)."' ,
'".mysql_escape_string($r2->projectcategories_id)."' ,
'".mysql_escape_string($newfairyear)."' ) " );
}
$q2 = mysql_query ( " SELECT * FROM award_awards_projectdivisions WHERE year=' $currentfairyear ' AND award_awards_id=' $r->id ' " );
echo mysql_error ();
while ( $r2 = mysql_fetch_object ( $q2 ))
{
mysql_query ( " INSERT INTO award_awards_projectdivisions (award_awards_id,projectdivisions_id,year) VALUES (
'".mysql_escape_string($award_awards_id)."' ,
'".mysql_escape_string($r2->projectdivisions_id)."' ,
'".mysql_escape_string($newfairyear)."' ) " );
}
2006-07-26 14:38:21 +00:00
echo i18n ( " Rolling award prizes " ) . " <br /> " ;
2005-11-21 19:36:48 +00:00
$q2 = mysql_query ( " SELECT * FROM award_prizes WHERE year=' $currentfairyear ' AND award_awards_id=' $r->id ' " );
echo mysql_error ();
while ( $r2 = mysql_fetch_object ( $q2 ))
{
2007-11-29 18:25:56 +00:00
mysql_query ( " INSERT INTO award_prizes (award_awards_id,cash,scholarship,`value`,prize,number,`order`,year,excludefromac,trophystudentkeeper,trophystudentreturn,trophyschoolkeeper,trophyschoolreturn,external_identifier) VALUES (
2005-11-21 19:36:48 +00:00
'".mysql_escape_string($award_awards_id)."' ,
'".mysql_escape_string($r2->cash)."' ,
'".mysql_escape_string($r2->scholarship)."' ,
2006-10-25 01:16:48 +00:00
'".mysql_escape_string($r2->value)."' ,
2005-11-21 19:36:48 +00:00
'".mysql_escape_string($r2->prize)."' ,
'".mysql_escape_string($r2->number)."' ,
'".mysql_escape_string($r2->order)."' ,
2006-10-25 01:16:48 +00:00
'".mysql_escape_string($newfairyear)."' ,
2007-11-23 21:25:52 +00:00
'".mysql_escape_string($r2->excludefromac)."' ,
'".mysql_escape_string($r2->trophystudentkeeper)."' ,
'".mysql_escape_string($r2->trophystudentreturn)."' ,
'".mysql_escape_string($r2->trophyschoolkeeper)."' ,
2007-11-29 18:25:56 +00:00
'".mysql_escape_string($r2->trophyschoolreturn)."' ,
'".mysql_escape_string($r2->external_identifier)."'
2007-11-23 21:25:52 +00:00
) " );
2005-11-21 19:36:48 +00:00
}
}
echo i18n ( " Rolling award contacts " ) . " <br /> " ;
//award contacts
$q = mysql_query ( " SELECT * FROM award_contacts WHERE year=' $currentfairyear ' " );
echo mysql_error ();
while ( $r = mysql_fetch_object ( $q ))
2006-10-25 01:16:48 +00:00
mysql_query ( " INSERT INTO award_contacts (award_sponsors_id,salutation,firstname,lastname,position,email,phonehome,phonework,phonecell,fax,notes,year) VALUES (
2005-11-21 19:36:48 +00:00
'".mysql_escape_string($r->award_sponsors_id)."' ,
2006-10-25 01:16:48 +00:00
'".mysql_escape_string($r->salutation)."' ,
2005-11-21 19:36:48 +00:00
'".mysql_escape_string($r->firstname)."' ,
'".mysql_escape_string($r->lastname)."' ,
2006-10-25 01:16:48 +00:00
'".mysql_escape_string($r->position)."' ,
2005-11-21 19:36:48 +00:00
'".mysql_escape_string($r->email)."' ,
'".mysql_escape_string($r->phonehome)."' ,
'".mysql_escape_string($r->phonework)."' ,
'".mysql_escape_string($r->phonecell)."' ,
'".mysql_escape_string($r->fax)."' ,
'".mysql_escape_string($r->notes)."' ,
'".mysql_escape_string($newfairyear)."' ) " );
echo i18n ( " Rolling award types " ) . " <br /> " ;
//award types
$q = mysql_query ( " SELECT * FROM award_types WHERE year=' $currentfairyear ' " );
echo mysql_error ();
while ( $r = mysql_fetch_object ( $q ))
mysql_query ( " INSERT INTO award_types (id,type,`order`,year) VALUES (
'".mysql_escape_string($r->id)."' ,
'".mysql_escape_string($r->type)."' ,
'".mysql_escape_string($r->order)."' ,
'".mysql_escape_string($newfairyear)."' ) " );
2005-11-24 20:12:43 +00:00
echo i18n ( " Rolling schools " ) . " <br /> " ;
//award types
$q = mysql_query ( " SELECT * FROM schools WHERE year=' $currentfairyear ' " );
echo mysql_error ();
while ( $r = mysql_fetch_object ( $q ))
2006-10-25 01:16:48 +00:00
mysql_query ( " INSERT INTO schools (school,schoollang,schoollevel,board,district,phone,fax,address,city,province_code,postalcode,principal,schoolemail,sciencehead,scienceheademail,scienceheadphone,accesscode,lastlogin,junior,intermediate,senior,registration_password,projectlimit,projectlimitper,year) VALUES (
2005-11-24 20:12:43 +00:00
'".mysql_escape_string($r->school)."' ,
2006-10-25 01:16:48 +00:00
'".mysql_escape_string($r->schoollang)."' ,
'".mysql_escape_string($r->schoollevel)."' ,
2006-07-26 14:51:30 +00:00
'".mysql_escape_string($r->board)."' ,
'".mysql_escape_string($r->district)."' ,
2005-11-24 20:12:43 +00:00
'".mysql_escape_string($r->phone)."' ,
'".mysql_escape_string($r->fax)."' ,
'".mysql_escape_string($r->address)."' ,
'".mysql_escape_string($r->city)."' ,
'".mysql_escape_string($r->province_code)."' ,
'".mysql_escape_string($r->postalcode)."' ,
2006-10-25 01:16:48 +00:00
'".mysql_escape_string($r->principal)."' ,
'".mysql_escape_string($r->schoolemail)."' ,
2005-11-24 20:12:43 +00:00
'".mysql_escape_string($r->sciencehead)."' ,
'".mysql_escape_string($r->scienceheademail)."' ,
'".mysql_escape_string($r->scienceheadphone)."' ,
'".mysql_escape_string($r->accesscode)."' ,
NULL ,
'".mysql_escape_string($r->junior)."' ,
'".mysql_escape_string($r->intermediate)."' ,
'".mysql_escape_string($r->senior)."' ,
'".mysql_escape_string($r->registration_password)."' ,
2006-07-26 14:51:30 +00:00
'".mysql_escape_string($r->projectlimit)."' ,
'".mysql_escape_string($r->projectlimitper)."' ,
2005-11-24 20:12:43 +00:00
'".mysql_escape_string($newfairyear)."' ) " );
2006-07-11 20:22:42 +00:00
echo i18n ( " Rolling questions " ) . " <br /> " ;
$q = mysql_query ( " SELECT * FROM questions WHERE year=' $currentfairyear ' " );
while ( $r = mysql_fetch_object ( $q ))
mysql_query ( " INSERT INTO questions (id,year,section,db_heading,question,type,required,ord) VALUES (
'' ,
'$newfairyear' ,
'".mysql_escape_string($r->section)."' ,
'".mysql_escape_string($r->db_heading)."' ,
'".mysql_escape_string($r->question)."' ,
'".mysql_escape_string($r->type)."' ,
'".mysql_escape_string($r->required)."' ,
'".mysql_escape_string($r->ord)."' ) " );
2008-01-23 18:40:59 +00:00
echo i18n ( " Rolling registration fee items " ) . " <br /> " ;
2008-01-23 19:00:26 +00:00
//regfee items
2008-01-23 18:40:59 +00:00
$q = mysql_query ( " SELECT * FROM regfee_items WHERE year=' $currentfairyear ' " );
echo mysql_error ();
while ( $r = mysql_fetch_object ( $q ))
mysql_query ( " INSERT INTO regfee_items (`year`,`name`,`description`,`cost`,`per`) VALUES (
'$newfairyear' ,
'".mysql_escape_string($r->name)."' ,
'".mysql_escape_string($r->description)."' ,
'".mysql_escape_string($r->cost)."' ,
'".mysql_escape_string($r->per)."' ) " );
2005-11-21 19:36:48 +00:00
echo " <br /> " ;
echo " <br /> " ;
mysql_query ( " UPDATE config SET val=' $newfairyear ' WHERE var='FAIRYEAR' AND year=0 " );
echo happy ( i18n ( " Fair year has been rolled over from %1 to %2 " , array ( $currentfairyear , $newfairyear )));
2005-11-21 21:30:10 +00:00
send_footer ();
exit ;
2005-11-21 19:36:48 +00:00
}
}
echo " <br /> " ;
echo " <form name= \" rollover \" method= \" post \" action= \" rollover.php \" onsubmit= \" return confirmYearRollover() \" > " ;
echo " <input type= \" hidden \" name= \" action \" value= \" rollover \" /> " ;
echo i18n ( " Current Fair Year " ) . " : <b> " . $config [ 'FAIRYEAR' ] . " </b><br /> " ;
$nextfairyear = $config [ 'FAIRYEAR' ] + 1 ;
echo i18n ( " Next Fair Year " ) . " : <input size= \" 8 \" type= \" text \" name= \" nextfairyear \" value= \" $nextfairyear\ " /> " ;
echo " <br /> " ;
echo " <input type= \" submit \" value= \" " . i18n ( " Rollover Fair Year " ) . " \" /> " ;
echo " </form> " ;
send_footer ();
?>