Files
HotLunches/school-stats.php
2026-10-19 15:22:52 -07:00

47 lines
1.5 KiB
PHP

<?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";
$query = "SELECT * FROM schools WHERE status = 'Active' AND reseller = 'hotlunch' ORDER BY school_name";
$schools = db_query($query);
while ($row = db_fetch_assoc($schools)) {
extract($row);
$school_num = $record_num;
$school_name = $school_name;
// Get linked sites
$linked_sites = db_query("SELECT record_num FROM schools WHERE linked_site = $school_num");
$snums = $school_num;
if (db_num_rows($linked_sites) > 0) {
while ($row = db_fetch_array($linked_sites)) {
$snums .= "," . $row['record_num'];
}
}
$numParents = db_getVal("SELECT count(*) FROM users WHERE school_num = $base_school_num AND type = 'Parent'");
if ($numParents < 10) continue;
$numStudents = db_getVal("SELECT count(*) FROM people WHERE school_num = $base_school_num AND people_type = 'Student'");
$numLogins = db_getVal("SELECT count(*) FROM login_log WHERE school_num IN ($snums)");
$avgLogins = $numLogins / $numParents;
printf("%s,%d,%d,%d,%0.2f\n",$school_name,$numParents,$numStudents,$numLogins,$avgLogins);
}
?>