From e730a5ab055ae07af9a4dcc9cc95475a2fc15d2c Mon Sep 17 00:00:00 2001 From: jacob Date: Thu, 18 Nov 2010 16:38:12 +0000 Subject: [PATCH] Added the rollover for the fiscal year, and removed the rollover for the fair year --- db/db.code.version.txt | 2 +- db/db.update.222.sql | 1 + super/index.php | 1 - super/rollover.php | 336 ------------------------ super/rolloverfiscal.php | 155 +++++++++-- theme/icons_default/icons.php | 2 +- theme/icons_default/rollover_fiscal.png | Bin 0 -> 2606 bytes 7 files changed, 138 insertions(+), 359 deletions(-) create mode 100644 db/db.update.222.sql delete mode 100644 super/rollover.php create mode 100644 theme/icons_default/rollover_fiscal.png diff --git a/db/db.code.version.txt b/db/db.code.version.txt index 7b47338..c200906 100644 --- a/db/db.code.version.txt +++ b/db/db.code.version.txt @@ -1 +1 @@ -221 +222 diff --git a/db/db.update.222.sql b/db/db.update.222.sql new file mode 100644 index 0000000..9808d33 --- /dev/null +++ b/db/db.update.222.sql @@ -0,0 +1 @@ +ALTER TABLE `conferences` CHANGE `status` `status` ENUM( 'pending', 'running', 'ended', 'deleted' ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL; diff --git a/super/index.php b/super/index.php index 201b678..1f02b3e 100644 --- a/super/index.php +++ b/super/index.php @@ -52,7 +52,6 @@ echo "
"; echo ""; echo " "; - echo " "; echo " "; echo " "; echo " \n"; diff --git a/super/rollover.php b/super/rollover.php deleted file mode 100644 index 4ce8dcd..0000000 --- a/super/rollover.php +++ /dev/null @@ -1,336 +0,0 @@ - - Copyright (C) 2005-2009 James Grant - - 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. -*/ -?> - 'committee_main.php', - 'System Setup' => 'super/index.php') - ,"rollover_fair_year" - ); - ?> - - - "; - config_update_variables($newfairyear, $currentfairyear); - - //now the dates - echo i18n("Rolling dates")."
"; - $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")."
"; - $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")."
"; - //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")."
"; - //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")."
"; - //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")."
"; - //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")."
"; - //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")."
"; - //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("  Rolling award prizes")."
"; - roll($cy, $ny, 'award_prizes', "award_awards_id='{$r->id}'", - array('award_awards_id' => $award_awards_id)); - } - - echo i18n("Rolling award types")."
"; - //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")."
"; - //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")."
"; - $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")."
"; - roll($cy, $ny, 'regfee_items'); - - //volunteer positions - echo i18n('Rolling volunteer positions')."
"; - roll($cy, $ny, 'volunteer_positions'); - - //timeslots and rounds - echo i18n('Rolling judging timeslots and rounds')."
"; - $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 "

"; - 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 "
"; - echo "".i18n("You should consider making a database backup before rolling over, just in case!")."
\n"; - echo "
"; - echo "
"; - echo ""; - echo i18n("Current Fair Year").": ".$config['FAIRYEAR']."
"; - $nextfairyear=$config['FAIRYEAR']+1; - echo i18n("Next Fair Year").": "; - echo "
"; - echo ""; - echo ""; - - send_footer(); -?> diff --git a/super/rolloverfiscal.php b/super/rolloverfiscal.php index 531ff71..90fad98 100644 --- a/super/rolloverfiscal.php +++ b/super/rolloverfiscal.php @@ -1,28 +1,143 @@ "; - roll($currentfairyear, $newfairyear, "fundraising", - array("type","name","description","system","goal")); - - echo i18n("Rolling sponsorship levels")."
"; - roll($currentfairyear, $newfairyear, "sponsorships_levels", - array("level","min","max","description")); - - echo i18n("Rolling sponsorships")."
"; - 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; ?> + + +"; + echo "".i18n("You should consider making a database backup before rolling over, just in case!")."
\n"; + echo "
"; + echo "
"; + echo i18n("Current Fiscal Year").": ".$config['FISCALYEAR']."
"; + $nextfiscalyear = $config['FISCALYEAR'] + 1; + echo i18n("Next Fiscal Year").": "; + echo "
"; + echo ""; + echo ""; + echo "
"; +} + +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()); + } + +} diff --git a/theme/icons_default/icons.php b/theme/icons_default/icons.php index 1454313..6a71190 100644 --- a/theme/icons_default/icons.php +++ b/theme/icons_default/icons.php @@ -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"; ?> diff --git a/theme/icons_default/rollover_fiscal.png b/theme/icons_default/rollover_fiscal.png new file mode 100644 index 0000000000000000000000000000000000000000..639493881e39a5089111c1f2620e98b43a06a39d GIT binary patch literal 2606 zcmV+}3eok6P)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2igk} z7Aqyi+hXnj012*1L_t(o!;P0|Y+ThDhM#lpy)*aT**xPJPaMY^PC|&Y5E7QqK+0Cu zKw2c!sue1W_yt03MOzgLrN3xtOH-;+0a5{h%34vvBA`g2BtXKF1OwR}$9C*E8GFXF zc$T}I{HFoBAdI;>wLzIoB=z;THf7 zjMzN#`~v3B$*}&c1btb76#`9ylpp{hnz2#fEAV_MRN(n-_1aULO2bnnZ-Y|m0q@^) zzZOKS+jy08{o)_#pS|qCXL`s@c5?B`G@WTlz5-);n3#r%AAcroVCv0t~1(1iyQDK6bd5)%`IFRd{O)3?8Y2 zHwk_ffrljp3OHlDO^ zRsbOcAh`eWE~Mxqm58uyzt8Bz6q?Ghu)D;i=N#rX_j~XN{Ntw&p-_w+i?Drn8#{NW z37Z|HV`;V@f*psTD+Rg^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p4nz|=TB3uMz2_nf3%ezQ-I76?F{*xuLM_N^O@ixsOzhgoBR7Ba6=%ZZ$5svi zPXg}&oeGuYJtA!2Hj1#muLIu)Gc0*`IE$6cV8>gDr8^0wI#5;;M~0D_hV%nBSF%)rhkn7?=tb|Qn_(vEIr@r^iD*T543 z)e!g!bX{Zdxj*LKchbDE=VR8k`#S760YEhY>Oi6Sdm4zMh_NfUDVq)>1hl10;`vtk zm-nMvNtBVmA<9f6j91ezTtUMLa!d%&G|9qMSF-0o4?EtGp0;Xv#C!iY75#)BEO7mq zW+Y00fx>1mID}-=CIaZlTEs@8boO@QX)&se5S6-tqa>Omf(E8(?;Q7??ODb#vsI5w zJh!c~@{V=00nmhSgL5zvs6DuB!A$oRS^G#XI9aEY2BsCl*P`f#jr28Wh~rwOCl_tu027&_F6-5Dp2-H4Q^)RO^Z( zM+yubI>z|nQSuYR6!TN)p#-L;h>63E_dl)wtXgw-0{gt}e>^gK7MvIj05@z%)!JfU zhJqDFY#l4)@t5EK6+_es$vR!BI*YPJ)-5PAe~p7KA)ojqBLh!P4}W-H=B0OVPUsE4 zVHYhQ{#DDdWHJ?UeI)>NDU^?fq4^m4?60Xhx@?43lqUE6bKWf*aA&*ce~#V)7sgi; Q_y7O^07*qoM6N<$f&?
".theme_icon("rollover_fair_year")."
".i18n("Rollover Fair Year")."
".theme_icon("rollover_fiscal_year")."
".i18n("Rollover Fiscal Year")."
".theme_icon("backup_restore")."
".i18n("Database Backup/Restore")."