'committee_main.php', 'SFIAB Configuration' => 'config/index.php') ,"rollover_fiscal_year" ); draw_body(); send_footer(); exit; 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, $pdo; $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 = $pdo->prepare("SELECT $fields FROM fundraising_campaigns WHERE fiscalyear = $oldYear"); $q->execute(); while($pdo->errorInfo() == null && $r = $q->fetch(PDO::FETCH_ASSOC)){ 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] = $val; } $query = "INSERT INTO fundraising_campaigns (`" . implode("`,`", $fields) . "`) VALUES('" . implode("','", $values) . "')"; $stmt = $pdo->prepare($query); $stmt->execute(); } // next we'll hit findraising_donor_levels $fields = "`level`,`min`,`max`,`description`"; if($pdo->errorInfo() == null) $q = $pdo->prepare("SELECT $fields FROM fundraising_donor_levels WHERE fiscalyear = $oldYear"); $q->execute(); while($pdo->errorInfo() == null && $r = $q->fetch(PDO::FETCH_ASSOC)){ $r['fiscalyear'] = $newYear; $fields = array_keys($r); $values = array_values($r); foreach($values as $idx => $val){ $values[$idx] = $val; } $query = "INSERT INTO fundraising_donor_levels (`" . implode("`,`", $fields) . "`) VALUES('" . implode("','", $values) . "')"; $stmt = $pdo->prepare($query); $stmt->execute(); } // and now we'll do findraising_goals $fields = "`goal`,`name`,`description`,`system`,`budget`,`deadline`"; if($pdo->errorInfo() == null){ $q = $pdo->prepare("SELECT $fields FROM fundraising_goals WHERE fiscalyear = $oldYear"); $q->execute(); } while($pdo->errorInfo() == null && $r = $q->fetch(PDO::FETCH_ASSOC)){ $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] = $val; } $query = "INSERT INTO fundraising_goals (`" . implode("`,`", $fields) . "`) VALUES('" . implode("','", $values) . "')"; $stmt = $pdo->prepare($query); $stmt->execute(); } // finally, let's update the fiscal year itself: if($pdo->errorInfo() == null){ $stmt = $pdo->prepare("UPDATE config SET val='$newYear' WHERE var='FISCALYEAR'"); $stmt->execute(); } if($pdo->errorInfo() == null){ $config['FISCALYEAR'] = $newYear; echo happy(i18n("Fiscal year has been rolled over from %1 to %2", array($oldYear, $newYear))); }else{ echo error($pdo->errorInfo()); } }