Files
HotLunches/switch-database.php
2026-10-19 15:22:52 -07:00

115 lines
3.8 KiB
PHP

<?php
require_once("include/globals.php");
if (SessionActive() != 1 || ! UserLoggedIn()) {
header("Location: /");
exit;
}
// Start the template and output buffering
startTemplate();
$templatePageTitle = getLanguageText('TEXT-SWITCH-DATABASE');
echo("<br>\n");
date_default_timezone_set("Canada/Pacific");
$Time1 = time() - 60 * 60 * 25;
$Time2 = time() - 60 * 60 * (24 * 2 + 1);
$Time3 = time() - 60 * 60 * (24 * 3 + 1);
$Time4 = time() - 60 * 60 * (24 * 4 + 1);
$Time5 = time() - 60 * 60 * (24 * 5 + 1);
$Time6 = time() - 60 * 60 * (24 * 6 + 1);
$Previous1 = date("Ymd",$Time1);
$Previous2 = date("Ymd",$Time2);
$Previous3 = date("Ymd",$Time3);
$Previous4 = date("Ymd",$Time4);
$Previous5 = date("Ymd",$Time5);
$Previous6 = date("Ymd",$Time6);
$DB1 = "hotlunch_" . $Previous1;
$DB2 = "hotlunch_" . $Previous2;
$DB3 = "hotlunch_" . $Previous3;
$DB4 = "hotlunch_" . $Previous4;
$DB5 = "hotlunch_" . $Previous5;
$DB6 = "hotlunch_" . $Previous6;
$DataBases = array(array($DB1,"Previous",date("F j, Y",$Time1)),
array($DB2,"Previous2",date("F j, Y",$Time2)),
array($DB3,"Previous3",date("F j, Y",$Time3)),
array($DB4,"Previous4",date("F j, Y",$Time4)),
);
// if ($_SESSION['UserInfo']['userid'] == 'superuser') $DataBases[] = array("hotlunch_20260214","","February 14, 2026");
if ($_SESSION['UserInfo']['userid'] == 'superuser') $DataBases[] = array($DB5,"Previous5",date("F j, Y",$Time5));
if ($_SESSION['UserInfo']['userid'] == 'superuser') $DataBases[] = array($DB6,"Previous6",date("F j, Y",$Time6));
$DataBases[] = array();
$DataBases[] = array("hotlunch_20260701","","July 1, 2026");
$DataBases[] = array("hotlunch_20260615","","June 15, 2026");
$DataBases[] = array("hotlunch_20260601","","June 1, 2026");
$DataBases[] = array("hotlunch_20251131","","November 31, 2025");
$DataBases[] = array("hotlunch_20250716","","July 15, 2025");
$DataBases[] = array("hotlunch_20250715","","July 14, 2025");
$DataBases[] = array("hotlunch_20250712","","July 11, 2025");
$DataBases[] = array("hotlunch_20250711","","July 10, 2025");
$DataBases[] = array("hotlunch_20250701","","June 30, 2025");
$DataBases[] = array("hotlunch_20250526","","May 26, 2025");
$DataBases[] = array();
date_default_timezone_set($school_record['timezone']);
$message_width = 500;
include "form.messages.php";
?>
<table width='400' class='content-table'>
<tr>
<td align='center' class='heading'><?php displayLanguageText('TEXT-SWITCH-DATABASE') ?></td>
</tr>
<td align='left'>
<blockquote>
<p><b><?php displayLanguageText('TEXT-ACTIVE-DATABASE'); ?>: <?php echo($currentDBMode) ?></b></p>
<p><a href='/?db_mode=Current'><?php displayLanguageText('TEXT-CURRENT-DB'); ?></a></p>
<br>
<?php
for ($i = 0; $i < count($DataBases); $i++) {
if (count($DataBases[$i]) > 1) {
$db_name = $DataBases[$i][0];
$mode = $DataBases[$i][1];
$date = $DataBases[$i][2];
echo("<!-- $db_name -->\n");
if (strlen($mode) == 0) $mode = str_replace('hotlunch_','',$db_name);
if (!is_file("databases/$db_name")) continue;
echo("<!-- $db_name -->\n");
echo("\n");
db_query("USE $db_name");
if (db_tableExists("schools")) {
$query = "SELECT * FROM schools WHERE record_num = $school_num";
$results = db_query($query);
if (db_num_rows($results)) echo(" <p><a href='/?db_mode=$mode'>$date</a> ($db_name)</p>\n");
else echo("<!-- $db_name: $query -->\n");
}
}
else echo("<br>");
}
db_query("USE hotlunch");
?>
</blockquote>
</td>
<tr>
<td align='right'></td>
</tr>
</table>
<br>
<?php
endTemplate();
?>