142 lines
5.0 KiB
PHP
142 lines
5.0 KiB
PHP
<?php
|
|
include "db.php";
|
|
include "table.php";
|
|
|
|
$people = new Table("people");
|
|
|
|
$school_num = 403;
|
|
|
|
$people_type = 'Student';
|
|
$status = 'Unverified';
|
|
$display = 'N';
|
|
$menu_price_category = 'Regular';
|
|
$added_date = date("Y-m-d",time());
|
|
|
|
// $added_date = '2013-10-11';
|
|
// db_query("DELETE FROM people WHERE school_num = $school_num AND people_type = 'Student' AND added_date = '$added_date'");
|
|
// db_query("DELETE FROM users WHERE school_num = $school_num AND type = 'Parent' AND date_added = '$added_date'");
|
|
// db_query("UPDATE people_csv SET created_flag = 'N'");
|
|
|
|
|
|
$query = "SELECT * FROM people_csv WHERE school_num = $school_num AND created_flag = 'N' ORDER BY student_number, create_flag";
|
|
$students = db_query($query);
|
|
$numStudents = db_num_rows($students);
|
|
echo("Students: $numStudents\n");
|
|
|
|
$prev_student = "";
|
|
$count = 0;
|
|
while ($row = db_fetch_assoc($students)) {
|
|
extract($row);
|
|
|
|
if ($prev_student != $student_number) {
|
|
$prev_student = $student_number;
|
|
$count = 1;
|
|
if ($create_flag == 'Y') {
|
|
if ($created_flag == 'N') {
|
|
// Create user account if required
|
|
$fname = db_escape_string($parent_first_name);
|
|
$lname = db_escape_string($parent_last_name);
|
|
if (strlen($email)) {
|
|
$results = db_query("SELECT * FROM users WHERE school_num = $school_num AND email = '$email'");
|
|
}
|
|
else {
|
|
$results = db_query("SELECT * FROM users WHERE school_num = $school_num AND first_name = '$fname' AND last_name = '$lname'");
|
|
}
|
|
|
|
if (db_num_rows($results) == 0) {
|
|
$user_num = createUser($school_num, $parent_first_name, $parent_last_name, $email, $phone);
|
|
}
|
|
else {
|
|
$user = db_fetch_assoc($results);
|
|
$user_num = $user['record_num'];
|
|
}
|
|
|
|
extract($row);
|
|
|
|
// Create student entry
|
|
$results = db_query("SELECT * FROM people WHERE school_num = $school_num AND student_number = '$student_number'");
|
|
if (db_num_rows($results) == 0) {
|
|
$class_num = db_getVal("SELECT record_num FROM classes WHERE school_num = $school_num AND grade = '$school_grade'");
|
|
$added_date = date("Y-m-d",time());
|
|
$query = $people->BuildInsert();
|
|
db_query($query);
|
|
echo("CREATED: $student_number - $first_name $last_name\n");
|
|
|
|
$snum = db_insert_id();
|
|
db_query("UPDATE people_csv SET created_flag = 'Y' WHERE student_number = '$student_number'");
|
|
}
|
|
else {
|
|
echo("$student_number - $first_name $last_name - Student Exists\n");
|
|
$student = db_fetch_assoc($results);
|
|
$snum = $student['record_num'];
|
|
db_query("UPDATE people SET user_num = $user_num WHERE school_num = $school_num AND record_num = $snum");
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
echo("$student_number - $first_name $last_name\n");
|
|
}
|
|
}
|
|
else {
|
|
if ($create_flag == 'Y') echo("$student_number - $first_name $last_name - Duplicate create flag\n");
|
|
|
|
if ($user_num > 0 && strlen($email)) {
|
|
$count++;
|
|
switch ($count) {
|
|
case 2:
|
|
db_query("UPDATE users SET email2 = '$email' WHERE school_num = $school_num AND record_num = $user_num");
|
|
break;
|
|
|
|
case 3:
|
|
db_query("UPDATE users SET email3 = '$email' WHERE school_num = $school_num AND record_num = $user_num");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
function createUser($school_num, $first_name, $last_name, $email, $phone) {
|
|
$users = new Table("users");
|
|
|
|
if (strlen($phone) < 13) $phone = "";
|
|
|
|
// $userid = $email;
|
|
$userid = trim(strtolower(str_replace("'",'',str_replace(' ','',$first_name . "." . $last_name))));
|
|
|
|
$GLOBALS['first_name'] = $first_name;
|
|
$GLOBALS['last_name'] = $last_name;
|
|
$GLOBALS['email'] = $email;
|
|
$GLOBALS['phone'] = $phone;
|
|
$GLOBALS['userid'] = $userid;
|
|
$GLOBALS['password'] = trim(strtolower(str_replace("'",'',str_replace(' ','',($last_name)))));
|
|
$GLOBALS['include_email1_on_list'] = 'Y';
|
|
$GLOBALS['include_email2_on_list'] = 'Y';
|
|
$GLOBALS['include_email3_on_list'] = 'Y';
|
|
$GLOBALS['email1_verified'] = 'N';
|
|
$GLOBALS['email2_verified'] = 'N';
|
|
$GLOBALS['email3_verified'] = 'N';
|
|
$GLOBALS['type'] = 'Parent';
|
|
$GLOBALS['status'] = 'Active';
|
|
$GLOBALS['date_added'] = date("Y-m-d",time());
|
|
$GLOBALS['can_order'] = 'Yes';
|
|
$GLOBALS['has_order'] = 'N';
|
|
$GLOBALS['num_orders'] = 0;
|
|
$GLOBALS['balance_owing'] = 0.00;
|
|
$GLOBALS['account_balance'] = 0.00;
|
|
$GLOBALS['receive_emails'] = 'Y';
|
|
$GLOBALS['email_reminders'] = 'N';
|
|
$GLOBALS['email_flag'] = 'N';
|
|
$GLOBALS['available_to_volunteer'] = 'N';
|
|
$GLOBALS['class_parent'] = 'N';
|
|
$GLOBALS['language'] = 'English';
|
|
$GLOBALS['home_phone'] = $phone;
|
|
|
|
$query = $users->BuildInsert();
|
|
db_query($query);
|
|
$user_num = db_insert_id();
|
|
return($user_num);
|
|
}
|
|
|
|
?>
|