First Commit

This commit is contained in:
mark committed 2026-10-19 15:22:52 -07:00
1 parent 5eb9dd037d
commit 2e62c0e60b
11877 files changed
+2035312

No files matched your search

+80
View File
@@ -0,0 +1,80 @@
<?php
include "../db.php";
include "table.php";
// $fp = fopen("NB_Schools_V02.csv", "r");
$fp = fopen("NB_Schools_-_2026-09-09.csv", "r");
$table = new Table("nb_schools");
$count = 0;
while (($data = fgetcsv($fp,10000,",",'"',"\\")) !== FALSE) {
$count++;
$numFields = count($data);
if (strlen($data[0]) == 0) continue;
if ($data[3] == 'URL') continue;
$entry = array();
$entry['school_name'] = $data[0];
$entry['city'] = $data[1];
$entry['url'] = $data[3];
$school_code = $data[4];
$entry['school_code'] = sprintf("%04d", $school_code);
$school_code = $data[4];
$url = db_escape_string($entry['url']);
// Check if the URL is in the table
// $query = "SELECT * FROM nb_schools WHERE url = '$url'";
// $results = db_query($query);
// if (db_num_rows($results) > 0) {
// echo("$url exists in nb_schools table already");
// continue;
// }
// Check that the URL is valid
$query = "SELECT * FROM schools WHERE url = '$url' AND status = 'Active'";
$results = db_query($query);
if (db_num_rows($results) > 0) {
$school = db_fetch_assoc($results);
$school_name = $school['school_name'];
$school_num = $school['record_num'];
if (strlen($entry['school_name']) == 0) $entry['school_name'] = $school_name;
$entry['school_num'] = $school_num;
$query = "SELECT min(added_date) FROM people WHERE school_num = $school_num AND people_type = 'Staff' AND added_date > '2026-08-27'";
$uDate = db_getVal($query);
if (is_string($uDate) && strlen($uDate)) {
$entry['upload_date'] = $uDate;
}
$query = "SELECT count(*) FROM people WHERE school_num = $school_num AND people_type = 'Student' AND class_num > 0";
$nStudents = db_getVal($query);
$entry['num_students'] = $nStudents;
$query = "SELECT * FROM nb_schools WHERE school_code = '$school_code'";
$results = db_query($query);
if (db_num_rows($results) > 0) {
$row = db_fetch_assoc($results);
$entry['record_num'] = $row['record_num'];
$query = $table->BuildUpdate($entry);
echo("$query\n");
// db_query($query);
}
else {
$query = $table->BuildInsert($entry);
echo("$query\n");
db_query($query);
}
}
else {
echo($entry['school_name'].": $url - invalid URL\n");
}
}
?>