Files
HotLunches/schools.csv.php
2026-10-19 15:22:52 -07:00

55 lines
1.5 KiB
PHP

<pre>
<?php
// Initialize the spreadsheet document type
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false);
header("Content-type: application/octet-stream; charset=utf-8");
header("Content-Disposition: attachment; filename=school-stats.csv");
header('Content-Transfer-Encoding: text');
echo("\xEF\xBB\xBF");
include "db.php";
$mode = "detail";
$mode = "summary";
$earliest_date = db_getVal("SELECT min(start_date) FROM schools WHERE status = 'Active'");
$latest_date = db_getVal("SELECT max(start_date) FROM schools WHERE status = 'Active'");
$first_month = substr($earliest_date,0,7);
$last_month = substr($latest_date,0,7);
$currMonth = $first_month;
$Year = substr($currMonth,0,4);
$Month = substr($currMonth,5,2);
$total = 0;
while ($currMonth <= $last_month) {
$numSchools = db_getVal("SELECT count(*) FROM schools WHERE status = 'Active' AND start_date LIKE '$currMonth%'");
$total += $numSchools;
printf("%s,%d,%d\n",$currMonth,$numSchools,$total);
if ($mode == "detail") {
$results = db_query("SELECT school_name, city, province, country, referred_by FROM schools WHERE status = 'Active' AND start_date LIKE '$currMonth%'");
while ($row = db_fetch_assoc($results)) {
extract($row);
printf("%s\n",$school_name . " - $city, $province");
}
}
$Month++;
if ($Month > 12) {
$Month = 1;
$Year++;
}
$currMonth = sprintf("%d-%02d",$Year,$Month);
}
echo("Total,$total\n");
?>