First Commit
This commit is contained in:
1 parent
5eb9dd037d
commit
2e62c0e60b
11877 files changed
+2035312
No files matched your search
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
include "../db.php";
|
||||
include "table.php";
|
||||
include "../include/initForm.php";
|
||||
include "../include/functions.php";
|
||||
|
||||
|
||||
// Get schools data
|
||||
$query = "SELECT * FROM nb_schools";
|
||||
$nbSchools = db_query($query);
|
||||
|
||||
$Schools = array();
|
||||
while ($row = db_fetch_assoc($nbSchools)) {
|
||||
$url = $row['url'];
|
||||
$school_code = $row['school_code'];
|
||||
echo("$school_code: $url\n");
|
||||
|
||||
$query = "SELECT * FROM schools WHERE url = '$url'";
|
||||
$results = db_query($query);
|
||||
|
||||
if (db_num_rows($results) == 0) {
|
||||
echo("ERROR: $url not found\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
$row = db_fetch_assoc($results);
|
||||
$row['nb_school_code'] = $school_code;
|
||||
$Schools[$school_code] = $row;
|
||||
}
|
||||
|
||||
|
||||
$cSchool = '1930';
|
||||
$SRCfile = "School_Lunch_Program_-_teachers_list_-_ASD-S_-_2026-09-07.csv";
|
||||
$fp = fopen($SRCfile, "r");
|
||||
|
||||
|
||||
$users = new Table("users");
|
||||
$people = new Table("people");
|
||||
$classes = new Table("classes");
|
||||
$nbTable = new Table('nb_schools');
|
||||
|
||||
$now = time();
|
||||
$changed = date("Y-m-d H:i:s", $now);
|
||||
$added = date("Y-m-d", $now);
|
||||
|
||||
$count = 0;
|
||||
$class_sequence = 1;
|
||||
$pschool = '';
|
||||
|
||||
while (($data = fgetcsv($fp,10000,",",'"',"\\")) !== FALSE) {
|
||||
$numFields = count($data);
|
||||
if (strlen($data[0]) == 0) continue;
|
||||
$count++;
|
||||
if ($count == 1) continue;
|
||||
|
||||
$values = array();
|
||||
|
||||
$name = $data[0].' '.$data[1];
|
||||
$school_code = $data[5];
|
||||
$school_code = sprintf("%04d", $school_code);
|
||||
|
||||
$school_name = $data[6];
|
||||
|
||||
if (!array_key_exists($school_code, $Schools)) {
|
||||
echo("Not Found: $school_name\n");
|
||||
$entry = array();
|
||||
$entry['school_name'] = $school_name;
|
||||
$entry['city'] = $data[7];
|
||||
$entry['url'] = '';
|
||||
$entry['school_code'] = $school_code;
|
||||
$entry['school_num'] = 0;
|
||||
|
||||
$query = $nbTable->BuildInsert($entry);
|
||||
db_query($query);
|
||||
|
||||
$entry['record_num'] = 0;
|
||||
$Schools[$school_code] = $entry;
|
||||
}
|
||||
|
||||
if ($school_code != $cSchool) continue;
|
||||
|
||||
if (array_key_exists($school_code, $Schools)) {
|
||||
$school_num = $Schools[$school_code]['record_num'];
|
||||
if ($school_num == 0) {
|
||||
echo("School not defined in nb_schools\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($school_code != $pschool) {
|
||||
$class_sequence = 1;
|
||||
|
||||
// echo("Deleting data\n");
|
||||
db_query("DELETE FROM users WHERE school_num = $school_num AND type = 'Staff'");
|
||||
db_query("DELETE FROM people WHERE school_num = $school_num AND people_type = 'Staff'");
|
||||
db_query("DELETE FROM classes WHERE school_num = $school_num");
|
||||
}
|
||||
$pschool = $school_code;
|
||||
|
||||
//
|
||||
// Setup user data
|
||||
//
|
||||
$values['first_name'] = $data[0];
|
||||
$values['last_name'] = $data[1];
|
||||
$values['grade'] = $data[3];
|
||||
$values['email'] = $data[4];
|
||||
$values['school_code'] = $data[5];
|
||||
|
||||
$name = $values['first_name'].' '.$values['last_name'];
|
||||
$grades = $values['grade'];
|
||||
echo("$count : $name\n");
|
||||
|
||||
$values['type'] = 'Staff';
|
||||
$values['people_type'] = 'Staff';
|
||||
$values['change_datetime'] = $changed;
|
||||
$values['email1_verified'] = 'Y';
|
||||
$values['status'] = 'Active';
|
||||
$values['date_added'] = $added;
|
||||
|
||||
$userid = strtolower($data[4]);
|
||||
$userid = str_replace("@nbed.nb.ca","",$userid);
|
||||
$values['userid'] = $userid;
|
||||
$values['password_crypt'] = encrypt_password($userid);
|
||||
|
||||
$school_num = $Schools[$school_code]['record_num'];
|
||||
$values['school_num'] = $school_num;
|
||||
|
||||
$entry = initializeTableArray("users", $values);
|
||||
|
||||
// Create user and get user_num
|
||||
$query = $users->BuildInsert($entry);
|
||||
db_query($query);
|
||||
$user_num = db_insert_id();
|
||||
|
||||
|
||||
//
|
||||
// Setup people data record linked to teacher user
|
||||
//
|
||||
$values['user_num'] = $user_num;
|
||||
$values['status'] = 'Verified';
|
||||
|
||||
$entry = initializeTableArray("people", $values);
|
||||
|
||||
// Create people entry linked to user
|
||||
$query = $people->BuildInsert($entry);
|
||||
// echo("$query\n");
|
||||
db_query($query);
|
||||
$pnum = db_insert_id();
|
||||
|
||||
|
||||
//
|
||||
// Setup class record linked to teacher person
|
||||
//
|
||||
$values['teacher1'] = $pnum;
|
||||
|
||||
$values['entry_type'] = 'Class';
|
||||
$values['division'] = '';
|
||||
$values['description'] = "$name: $grades";
|
||||
$values['label_description'] = $values['last_name'].": $grades";
|
||||
$values['default_price_category'] = 'Regular';
|
||||
$values['sequence'] = $class_sequence;
|
||||
|
||||
$entry = initializeTableArray("classes", $values);
|
||||
|
||||
// Create class for this teacher
|
||||
$query = $classes->BuildInsert($entry);
|
||||
db_query($query);
|
||||
$pnum = db_insert_id();
|
||||
|
||||
echo("Inserted: $school_name - $name\n");
|
||||
|
||||
$class_sequence++;
|
||||
}
|
||||
else {
|
||||
echo("School Code Not Found: $school_code - $name\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
Reference in new issue
Block a user