Added the rollover for the fiscal year, and removed the rollover for the fair year

This commit is contained in:
jacob 2010-11-18 16:38:12 +00:00
parent f6eee9666a
commit e730a5ab05
7 changed files with 138 additions and 359 deletions

View File

@ -1 +1 @@
221
222

1
db/db.update.222.sql Normal file
View File

@ -0,0 +1 @@
ALTER TABLE `conferences` CHANGE `status` `status` ENUM( 'pending', 'running', 'ended', 'deleted' ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;

View File

@ -52,7 +52,6 @@
echo "<hr />";
echo "<table class=\"adminconfigtable\">";
echo " <tr>";
echo " <td><a href=\"rollover.php\">".theme_icon("rollover_fair_year")."<br />".i18n("Rollover Fair Year")."</a></td>";
echo " <td><a href=\"rolloverfiscal.php\">".theme_icon("rollover_fiscal_year")."<br />".i18n("Rollover Fiscal Year")."</a></td>";
echo " <td><a href=\"backuprestore.php\">".theme_icon("backup_restore")."<br />".i18n("Database Backup/Restore")."</a></td>";
echo " <td></td>\n";

View File

@ -1,336 +0,0 @@
<?
/*
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-2009 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");
require_once("../user.inc.php");
require_once("../config_editor.inc.php");
superuser_required();
send_header("Year Rollover",
array('Committee Main' => 'committee_main.php',
'System Setup' => 'super/index.php')
,"rollover_fair_year"
);
?>
<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>
<?
function roll($currentfairyear, $newfairyear, $table, $where='', $replace=array())
{
/* Field Type Null Key Default Extra
* id int(10) unsigned NO PRI NULL auto_increment
* sponsors_id int(10) unsigned NO MUL 0
* award_source_fairs_id int(10) unsigned YES NULL
*/
/* Get field list for this table */
$q = mysql_query("SHOW COLUMNS IN `$table`");
while(($c = mysql_fetch_assoc($q))) {
$col[$c['Field']] = $c;
}
/* Record fields we care about */
$fields = array();
$keys = array_keys($col);
foreach($keys as $k) {
/* Skip id field */
if($col[$k]['Extra'] == 'auto_increment') continue;
/* Skip year field */
if($k == 'year') continue;
$fields[] = $k;
}
if($where == '') $where='1';
/* Get data */
$q=mysql_query("SELECT * FROM $table WHERE year='$currentfairyear' AND $where");
echo mysql_error();
$names = '`'.join('`,`', $fields).'`';
/* Process data */
while($r=mysql_fetch_assoc($q)) {
$vals = '';
foreach($fields as $f) {
if(array_key_exists($f, $replace))
$vals .= ",'".mysql_real_escape_string($replace[$f])."'";
else if($col[$f]['Null'] == 'YES' && $r[$f] == NULL)
$vals .= ',NULL';
else
$vals .= ",'".mysql_real_escape_string($r[$f])."'";
}
mysql_query("INSERT INTO `$table`(`year`,$names) VALUES ('$newfairyear'$vals)");
echo mysql_error();
}
}
if($_POST['action']=="rollover" && $_POST['nextfairyear'])
{
$newfairyear=intval($_POST['nextfairyear']);
$currentfairyear=intval($config['FAIRYEAR']);
$cy = $currentfairyear;
$ny = $newfairyear;
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 />";
config_update_variables($newfairyear, $currentfairyear);
//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_real_escape_string($r->newdate)."',
'".mysql_real_escape_string($r->name)."',
'".mysql_real_escape_string($r->description)."',
'".mysql_real_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))
mysql_query("INSERT INTO pagetext (textname,textdescription,text,lastupdate,year,lang) VALUES (
'".mysql_real_escape_string($r->textname)."',
'".mysql_real_escape_string($r->textdescription)."',
'".mysql_real_escape_string($r->text)."',
'".mysql_real_escape_string($r->lastupdate)."',
'".mysql_real_escape_string($newfairyear)."',
'".mysql_real_escape_string($r->lang)."')");
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))
mysql_query("INSERT INTO projectcategories (id,category,category_shortform,mingrade,maxgrade,year) VALUES (
'".mysql_real_escape_string($r->id)."',
'".mysql_real_escape_string($r->category)."',
'".mysql_real_escape_string($r->category_shortform)."',
'".mysql_real_escape_string($r->mingrade)."',
'".mysql_real_escape_string($r->maxgrade)."',
'".mysql_real_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))
mysql_query("INSERT INTO projectdivisions (id,division,division_shortform,cwsfdivisionid,year) VALUES (
'".mysql_real_escape_string($r->id)."',
'".mysql_real_escape_string($r->division)."',
'".mysql_real_escape_string($r->division_shortform)."',
'".mysql_real_escape_string($r->cwsfdivisionid)."',
'".mysql_real_escape_string($newfairyear)."')");
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_real_escape_string($r->projectdivisions_id)."',
'".mysql_real_escape_string($r->projectcategories_id)."',
'".mysql_real_escape_string($newfairyear)."')");
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_real_escape_string($r->id)."',
'".mysql_real_escape_string($r->projectsubdivisions_id)."',
'".mysql_real_escape_string($r->subdivision)."',
'".mysql_real_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_real_escape_string($r->question)."',
'".mysql_real_escape_string($r->type)."',
'".mysql_real_escape_string($r->required)."',
'".mysql_real_escape_string($r->ord)."',
'".mysql_real_escape_string($newfairyear)."')");
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)) {
/* Roll the one award */
roll($cy, $ny, 'award_awards', "id='{$r->id}'");
$award_awards_id=mysql_insert_id();
roll($cy, $ny, 'award_awards_projectcategories', "award_awards_id='{$r->id}'",
array('award_awards_id' => $award_awards_id));
roll($cy, $ny, 'award_awards_projectdivisions', "award_awards_id='{$r->id}'",
array('award_awards_id' => $award_awards_id));
echo i18n("&nbsp; Rolling award prizes")."<br />";
roll($cy, $ny, 'award_prizes', "award_awards_id='{$r->id}'",
array('award_awards_id' => $award_awards_id));
}
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_real_escape_string($r->id)."',
'".mysql_real_escape_string($r->type)."',
'".mysql_real_escape_string($r->order)."',
'".mysql_real_escape_string($newfairyear)."')");
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)) {
$puid = ($r->principal_uid == null) ? 'NULL' : ("'".intval($r->principal_uid)."'");
$shuid = ($r->sciencehead_uid == null) ? 'NULL' : ("'".intval($r->sciencehead_uid)."'");
mysql_query("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 (
'".mysql_real_escape_string($r->school)."',
'".mysql_real_escape_string($r->schoollang)."',
'".mysql_real_escape_string($r->schoollevel)."',
'".mysql_real_escape_string($r->board)."',
'".mysql_real_escape_string($r->district)."',
'".mysql_real_escape_string($r->phone)."',
'".mysql_real_escape_string($r->fax)."',
'".mysql_real_escape_string($r->address)."',
'".mysql_real_escape_string($r->city)."',
'".mysql_real_escape_string($r->province_code)."',
'".mysql_real_escape_string($r->postalcode)."',$puid,
'".mysql_real_escape_string($r->schoolemail)."',$shuid,
'".mysql_real_escape_string($r->accesscode)."',
NULL,
'".mysql_real_escape_string($r->junior)."',
'".mysql_real_escape_string($r->intermediate)."',
'".mysql_real_escape_string($r->senior)."',
'".mysql_real_escape_string($r->registration_password)."',
'".mysql_real_escape_string($r->projectlimit)."',
'".mysql_real_escape_string($r->projectlimitper)."',
'".mysql_real_escape_string($newfairyear)."')");
}
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_real_escape_string($r->section)."',
'".mysql_real_escape_string($r->db_heading)."',
'".mysql_real_escape_string($r->question)."',
'".mysql_real_escape_string($r->type)."',
'".mysql_real_escape_string($r->required)."',
'".mysql_real_escape_string($r->ord)."')");
//regfee items
echo i18n("Rolling registration fee items")."<br />";
roll($cy, $ny, 'regfee_items');
//volunteer positions
echo i18n('Rolling volunteer positions')."<br />";
roll($cy, $ny, 'volunteer_positions');
//timeslots and rounds
echo i18n('Rolling judging timeslots and rounds')."<br />";
$q=mysql_query("SELECT * FROM judges_timeslots WHERE year='$currentfairyear' AND round_id='0'");
echo mysql_error();
while($r=mysql_fetch_assoc($q)) {
$d = $newfairyear - $currentfairyear;
mysql_query("INSERT INTO judges_timeslots (`year`,`round_id`,`type`,`date`,`starttime`,`endtime`,`name`)
VALUES ('$newfairyear','0','{$r['type']}',DATE_ADD('{$r['date']}', INTERVAL $d YEAR),
'{$r['starttime']}','{$r['endtime']}','{$r['name']}')");
echo mysql_error();
$round_id = mysql_insert_id();
$qq = mysql_query("SELECT * FROM judges_timeslots WHERE round_id='{$r['id']}'");
echo mysql_error();
while($rr=mysql_fetch_assoc($qq)) {
mysql_query("INSERT INTO judges_timeslots (`year`,`round_id`,`type`,`date`,`starttime`,`endtime`)
VALUES ('$newfairyear','$round_id','timeslot',DATE_ADD('{$rr['date']}', INTERVAL $d YEAR),
'{$rr['starttime']}','{$rr['endtime']}')");
}
}
echo "<br /><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)));
send_footer();
exit;
}
}
echo "<br />";
echo "<a href=\"backuprestore.php\">".i18n("You should consider making a database backup before rolling over, just in case!")."</a><br />\n";
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();
?>

View File

@ -1,28 +1,143 @@
<?
//FIXME: I just ripped these out of the fair year rollover since they are no longer tied to the fair year, they are now tied to the FISCAL year, we'll need to implement a new fiscal year rollover mechanism similar to the fairyear rollover
//FIXME: The table names are also wrong since i've now renamed htem all, will fix when the fiscal rollover is implemented
include "../common.inc.php";
if(array_key_exists('action', $_POST)){
switch($_POST['action']){
case 'rollover':
// error check the data that's getting posted
$year = $_POST['year'];
if(!is_numeric($year)){
error_("Not a valid year");
break;
}
if($year <= $config['FISCALYEAR']){
error_("The new fiscal year must be after the current one");
break;
}
// ok, the request checks out, let's go ahead and do the rollover
echo rolloverfiscalyear($year);
break;
default:
}
exit;
}
send_header("Fiscal Rollover");
echo "not implemented yet";
//echo "not implemented yet";
draw_body();
send_footer();
exit;
echo i18n("Rolling fundraising goals")." <br />";
roll($currentfairyear, $newfairyear, "fundraising",
array("type","name","description","system","goal"));
echo i18n("Rolling sponsorship levels")." <br />";
roll($currentfairyear, $newfairyear, "sponsorships_levels",
array("level","min","max","description"));
echo i18n("Rolling sponsorships")." <br />";
roll($currentfairyear, $newfairyear, "sponsorships",
array("sponsors_id","fundraising_type","value")); //no need to roll status or probability, because we're about to reset them..
mysql_query("UPDATE sponsorships SET status='pending', probability=25 WHERE year='$newfairyear'");
$q=mysql_query("SELECT * FROM sponsorships WHERE year='$newfairyear'");
while($r=mysql_fetch_object($q)) {
mysql_query("INSERT INTO sponsors_logs (sponsors_id,dt,users_id,log) VALUES ('$r->sponsors_id',NOW(),'{$_SESSION['auth_user_id']}','Fair year rollover - reset status=pending, probability=25\%')");
}
function draw_body(){
global $config;
?>
<script language="javascript" type="text/javascript">
function confirmYearRollover(){
var currentyear = <?=$config['FISCALYEAR']?>;
var nextyear = document.forms.rollover.nextfiscalyear.value;
var okay=confirm('Are you sure you want to roll the FISCALYEAR from '+currentyear+' to '+nextyear+'? This can not be undone and should only be done if you are absolutely sure!');
if(okay){
$.post('rolloverfiscal.php', {'action':'rollover', 'year':$('#nextfiscalyear').val()}, function(result){
$('#results').html(result);
});
}
return false;
}
</script>
<?
echo "<br />";
echo "<a href=\"backuprestore.php\">".i18n("You should consider making a database backup before rolling over, just in case!")."</a><br />\n";
echo "<br />";
echo "<form name=\"rollover\" method=\"post\" action=\"rolloverfiscal.php\" onsubmit=\"return confirmYearRollover()\">";
echo i18n("Current Fiscal Year").": <b>".$config['FISCALYEAR']."</b><br />";
$nextfiscalyear = $config['FISCALYEAR'] + 1;
echo i18n("Next Fiscal Year").": <input size=\"8\" type=\"text\" id=\"nextfiscalyear\" value=\"$nextfiscalyear\" />";
echo "<br />";
echo "<input type=\"submit\" value=\"".i18n("Rollover Fiscal Year")."\" />";
echo "</form>";
echo "<div id=\"results\"></div>";
}
function rolloverfiscalyear($newYear){
global $config;
$oldYear = $config['FISCALYEAR'];
$yearDiff = $newYear - $oldYear;
// first we'll roll over fundraising_campaigns:
$fields = "`name`,`type`,`startdate`,`enddate`,`followupdate`,`active`,`target`,`fundraising_goal`,`filterparameters`";
$q = mysql_query("SELECT $fields FROM fundraising_campaigns WHERE fiscalyear = $oldYear");
while(mysql_error() == null && $r = mysql_fetch_assoc($q)){
foreach(array('startdate','enddate','followupdate') as $dateField){
$dateval = $r[$dateField];
$parts = explode('-', $dateval);
if($parts[0] != '0000')
$parts[0] += $yearDiff;
$r[$dateField] = implode('-', $parts);
}
$r['fiscalyear'] = $newYear;
$fields = array_keys($r);
$values = array_values($r);
foreach($values as $idx => $val){
$values[$idx] = mysql_real_escape_string($val);
}
$query = "INSERT INTO fundraising_campaigns (`" . implode("`,`", $fields) . "`) VALUES('" . implode("','", $values) . "')";
mysql_query($query);
}
// next we'll hit findraising_donor_levels
$fields = "`level`,`min`,`max`,`description`";
if(mysql_error() == null)
$q = mysql_query("SELECT $fields FROM fundraising_donor_levels WHERE fiscalyear = $oldYear");
while(mysql_error() == null && $r = mysql_fetch_assoc($q)){
$r['fiscalyear'] = $newYear;
$fields = array_keys($r);
$values = array_values($r);
foreach($values as $idx => $val){
$values[$idx] = mysql_real_escape_string($val);
}
$query = "INSERT INTO fundraising_donor_levels (`" . implode("`,`", $fields) . "`) VALUES('" . implode("','", $values) . "')";
mysql_query($query);
}
// and now we'll do findraising_goals
$fields = "`goal`,`name`,`description`,`system`,`budget`,`deadline`";
if(mysql_error() == null){
$q = mysql_query("SELECT $fields FROM fundraising_goals WHERE fiscalyear = $oldYear");
}
while(mysql_error() == null && $r = mysql_fetch_assoc($q)){
$dateval = $r['deadline'];
$parts = explode('-', $dateval);
if($parts[0] != '0000')
$parts[0] += $yearDiff;
$r['deadline'] = implode('-', $parts);
$r['fiscalyear'] = $newYear;
$fields = array_keys($r);
$values = array_values($r);
foreach($values as $idx => $val){
$values[$idx] = mysql_real_escape_string($val);
}
$query = "INSERT INTO fundraising_goals (`" . implode("`,`", $fields) . "`) VALUES('" . implode("','", $values) . "')";
mysql_query($query);
}
// finally, let's update the fiscal year itself:
if(mysql_error() == null){
mysql_query("UPDATE config SET val='$newYear' WHERE var='FISCALYEAR'");
}
if(mysql_error() == null){
$config['FISCALYEAR'] = $newYear;
echo happy(i18n("Fiscal year has been rolled over from %1 to %2", array($oldYear, $newYear)));
}else{
echo error(mysql_error());
}
}

View File

@ -70,7 +70,7 @@
$theme_icons['icons']['external_award_sources']="ark.png";
$theme_icons['icons']['language_pack_installer']="kanagram.png";
$theme_icons['icons']['new_version_checker']="numbers.png";
$theme_icons['icons']['rollover_fair_year']="svn_switch.png";
$theme_icons['icons']['rollover_fiscal_year']="rollover_fiscal.png";
$theme_icons['icons']['backup_restore']="rebuild.png";
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB