0 && $school_record['participant_grouping'] != 'None' && (intval($class_num) == 0 || strlen($class_num) == 0)) { $error_message = getLanguageText('ERRORMSG-NO-CLASS'); $_POST['naction'] = 'add'; $args = encodeArray($_POST); $args .= "&error_message=" . urlencode($error_message); header("Location: $FormTarget?$args"); exit(); } if (strlen(trim($first_name)) == 0 || strlen(trim($last_name)) == 0) { $error_message = getLanguageText('ERRORMSG-FIRST-LAST-NAME-REQUIRED'); $_POST['naction'] = 'add'; $args = encodeArray($_POST); $args .= "&error_message=" . urlencode($error_message); header("Location: $FormTarget?$args"); exit(); } if (in_array($_SESSION['UserInfo']['type'],array('Parent','Staff')) || $mode == 'parent') { $user_num = intval($_SESSION['UserInfo']['record_num']); } else { // Check that there is a user_num if ($user_num == 0 || strlen($user_num) == 0) { $error_message = getLanguageText('ERRORMSG-NO-ACCOUNT'); $_POST['naction'] = 'add'; $args = encodeArray($_POST); $args .= "&error_message=" . urlencode($error_message); header("Location: $FormTarget?$args"); exit(); } $user_type = db_getVal("SELECT type FROM users WHERE school_num = $base_school_num AND record_num = $user_num"); if (!$user_type) { $error_message = getLanguageText('ERRORMSG-INVALID-ACCOUNT'); $_POST['naction'] = 'add'; $args = encodeArray($_POST); $args .= "&error_message=" . urlencode($error_message); header("Location: $FormTarget?$args"); exit(); } if (!in_array($user_type,array('Parent','Administration Team','Schedule Team','Staff'))) { $error_message = getLanguageText('ERRORMSG-INVALID-ACCOUNT'); $_POST['naction'] = 'add'; $args = encodeArray($_POST); $args .= "&error_message=" . urlencode($error_message); header("Location: $FormTarget?$args"); exit(); } } // Check that there is a valid class_num if (isset($menu_price_category)) writeLog("menu_price_category: $menu_price_category"); writeLog("numClasses: $numClasses"); if ($numClasses > 0) { if (!array_key_exists('menu_price_category',$_POST) || strlen($_POST['menu_price_category']) == 0) { $class_results = db_query("SELECT * FROM classes WHERE school_num = $school_num AND record_num = $class_num"); $class = db_fetch_assoc($class_results); if (array_key_exists('default_price_category', $class) && strlen($class['default_price_category'])) $menu_price_category = $class['default_price_category']; writeLog("class['default_price_category']: ".$class['default_price_category']); if (isset($menu_price_category)) writeLog("menu_price_category: $menu_price_category"); } } else { $class_num = 1; $meal_location = 1; $menu_price_category = 'Regular'; } writeLog("menu_price_category: $menu_price_category"); if ($_SESSION['UserInfo']['type'] == 'Parent') $status = $school_record['default_student_status']; if ($_SESSION['UserInfo']['type'] == 'Staff') $status = 'Verified'; $added_date = date("Y-m-d",time()); $people_type = 'Student'; if (!isset($display) || strlen($display) == 0) $display = 'N'; // Reformat the student name if required if ($first_name == strtolower($first_name) || $first_name == strtoupper($first_name) || $last_name == strtolower($last_name) || $last_name == strtoupper($last_name)) { $first_name = ucwords(strtolower($first_name)); $last_name = ucwords(strtolower($last_name)); } // Check if this student exists already in this account if ($_SESSION['UserInfo']['type'] == 'Parent') { $query = "select * from people " . "where school_num = $base_school_num " . "and user_num = $user_num " . "and people_type = '$people_type' " . "and first_name = '" . db_escape_string($first_name) . "' " . "and last_name = '" . db_escape_string($last_name) . "' " . "and status != 'Inactive'"; $results = db_query($query); if (db_num_rows($results) > 0) { $error_message = $GlobalText['ErrorStudentExists']; $error_message .= ": " . $school_record['support_email'] . ""; $_POST['naction'] = 'add'; $args = encodeArray($_POST); $args .= "&error_message=" . urlencode($error_message); header("Location: $FormTarget?$args"); exit(); } } // Check if this student exists already in this class if ($school_record['allow_duplicate_students'] != 'Y') { $cwhere = ""; if ($numClasses > 0 && $class_num > 0) $cwhere = "and class_num = $class_num "; $query = "select * from people " . "where school_num = $base_school_num " . $cwhere . "and people_type = '$people_type' " . "and first_name = '" . db_escape_string($first_name) . "' " . "and last_name = '" . db_escape_string($last_name) . "' " . "and status != 'Inactive'"; $results = db_query($query); // db_query_log($query,"student-class check: " . db_num_rows($results)); if (db_num_rows($results) > 0) { if ($_SESSION['UserInfo']['type'] == 'Parent') { $error_message = $GlobalText['ErrorStudentExists']; $error_message .= ": " . $school_record['support_email'] . ""; $_POST['naction'] = 'add'; $args = encodeArray($_POST); $args .= "&error_message=" . urlencode($error_message); header("Location: $FormTarget?$args"); exit(); } else { $error_message = getLanguageText('WARNING-STUDENT-EXISTS'); } } } // Save the new student $school_num = $base_school_num; $GLOBALS['school_num'] = $base_school_num; if (!isset($menu_price_category) || strlen($menu_price_category) == 0) $menu_price_category = 'Regular'; // Format birthdate if provided if (isset($birthdate) && strlen($birthdate)) $birthdate = date("Y-m-d",strtotime($birthdate)); if (!isset($active)) $active = 'Y'; $table = new Table("$CurrentTable"); $student = array(); $cols = $table->column_names; for ($i = 0; $i < count($cols); $i++) { $col = $cols[$i]; if ($col == "record_num") continue; if (isset($col)) $student[$col] = $$col; } $student["school_num"] = $base_school_num; $query = $table->BuildInsert($student); db_query($query); $record_num = db_insert_id(); $school_num = $school_record['record_num']; $GLOBALS['school_num'] = $school_record['record_num']; // Handle any student categories if (count($student_categories)) { for ($i = 0; $i < count($student_categories); $i++) { $cnum = intval($student_categories[$i]); db_query("insert into people_categories values($base_school_num,$record_num,$cnum)"); } } // Handle any allergy entries $allergens = db_query("select * from allergens where school_num = $base_school_num order by sequence"); if (db_num_rows($allergens) > 0) { while ($row = db_fetch_array($allergens)) { $allergen_num = $row['record_num']; if (array_key_exists("allergen_$allergen_num", $_POST) && $_POST["allergen_$allergen_num"] == 'Y') { db_query("insert into allergies values($base_school_num,$record_num,$allergen_num)"); } } } $next_naction = 'search'; if ($action == 'account-students') { $next_naction = 'display'; $action .= "&uid=$user_num"; } if ($action == 'class-students') { $next_naction = 'display'; $action .= "¤t_class_num=$current_class_num"; } if (in_array($_SESSION['UserInfo']['type'],array('Parent','Staff'))) $next_naction = 'display'; $form_message = getLanguageText('RECORD-INSERTED-MSG'); header("Location: $FormTarget?action=$action&naction=$next_naction&mode=$mode&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message)); exit(); case "edit": $next_naction = "update"; // Get current record $record_num = intval($_GET['record_num']); $uwhere = ""; if (in_array($_SESSION['UserInfo']['type'],array('Parent','Staff')) || $_SESSION['mode'] == 'parent') { $uwhere = "and user_num = " . $_SESSION['UserInfo']['record_num'] . " "; } $query = "select * from $CurrentTable " . "where school_num = $base_school_num " . $uwhere . "and record_num = $record_num"; $results = db_query($query); if (db_num_rows($results) == 1) { $row = db_fetch_array($results); extract($row); include $FormFile; } else { $error_message = getLanguageText('ERRORMSG-NOT-FOUND'); include 'students.display.php'; } break; case "update": extract($_POST); $first_name = trim($first_name); $last_name = trim($last_name); $people_type = trim($people_type); $user_num = intval($selected_user_num); $class_num = intval($class_num); if (!isset($meal_location)) $meal_location = $class_num; else $meal_location = intval($meal_location); $record_num = intval($record_num); if ($people_type == 'Student' && ($school_record['participant_grouping'] != 'None' && (intval($class_num) == 0 || strlen($class_num) == 0))) { $error_message = getLanguageText('ERRORMSG-NO-CLASS'); $_POST['naction'] = 'edit'; $args = encodeArray($_POST); $args .= "&error_message=" . urlencode($error_message); header("Location: $FormTarget?$args"); exit(); } if (strlen(trim($first_name)) == 0 || strlen(trim($last_name)) == 0) { $error_message = getLanguageText('ERRORMSG-FIRST-LAST-NAME-REQUIRED'); $_POST['naction'] = 'add'; $args = encodeArray($_POST); $args .= "&error_message=" . urlencode($error_message); header("Location: $FormTarget?$args"); exit(); } // Verify the form data $results = db_query("SELECT * FROM classes WHERE school_num = $base_school_num"); $numClasses = db_num_rows($results); if ($numClasses > 0) { if (!isset($menu_price_category) || strlen($menu_price_category) == 0) { $class = db_fetch_assoc($results); if (array_key_exists('default_price_category', $class) && strlen($class['default_price_category'])) $menu_price_category = $class['default_price_category']; } } else { $class_num = 1; $meal_location = 1; } if (in_array($_SESSION['UserInfo']['type'],array('Parent','Staff'))) { $user_num = intval($_SESSION['UserInfo']['record_num']); if ($_SESSION['UserInfo']['type'] == 'Staff') $status = 'Verified'; } else { // Check that there is a user_num if ($user_num == 0 || strlen($user_num) == 0) { $error_message = getLanguageText('ERRORMSG-NO-ACCOUNT'); $_POST['naction'] = 'add'; $args = encodeArray($_POST); $args .= "&error_message=" . urlencode($error_message); header("Location: $FormTarget?$args"); exit(); } $user_type = db_getVal("SELECT type FROM users WHERE school_num = $base_school_num AND record_num = $user_num"); if (!$user_type) { $error_message = getLanguageText('ERRORMSG-INVALID-ACCOUNT'); $_POST['naction'] = 'add'; $args = encodeArray($_POST); $args .= "&error_message=" . urlencode($error_message); header("Location: $FormTarget?$args"); exit(); } if (!in_array($user_type,array('Parent','Administration Team','Schedule Team','Staff','Guest'))) { $error_message = getLanguageText('ERRORMSG-INVALID-ACCOUNT'); $_POST['naction'] = 'add'; $args = encodeArray($_POST); $args .= "&error_message=" . urlencode($error_message); header("Location: $FormTarget?$args"); exit(); } } $uid = $user_num; // Get original user_num $orig_user_num = db_getVal("SELECT user_num FROM people WHERE record_num = $record_num"); // Reformat first name if required if ($first_name == strtolower($first_name) || $first_name == strtoupper($first_name)) { $first_name = ucwords(strtolower($first_name)); } // Reformat last name if required if ($last_name == strtolower($last_name) || $last_name == strtoupper($last_name)) { $last_name = ucwords(strtolower($last_name)); if (strpos($last_name,"Mc") === 0) { $last_name[2] = $entered_last_name[2]; } if (strpos($last_name,"Mac")) { $last_name[3] = $entered_last_name[3]; } } // Update the student record $school_num = $base_school_num; $GLOBALS['school_num'] = $base_school_num; if (!isset($menu_price_category) || strlen($menu_price_category) == 0) $menu_price_category = 'Regular'; if ($class_num == 1) $people_type = 'Customer'; // Format birthdate if provided if (isset($birthdate) && strlen($birthdate)) $birthdate = date("Y-m-d",strtotime($birthdate)); if (!isset($active)) $active = 'Y'; $table = new Table("$CurrentTable"); $query = $table->BuildUpdate(); db_query($query); $school_num = $school_record['record_num']; $GLOBALS['school_num'] = $school_record['record_num']; // Handle any student categories db_query("delete from people_categories where school_num = $base_school_num and people_num = $record_num"); if (count($student_categories)) { for ($i = 0; $i < count($student_categories); $i++) { $cnum = intval($student_categories[$i]); db_query("insert into people_categories values($base_school_num,$record_num,$cnum)"); } } // Handle any allergy entries $allergens = db_query("select * from allergens where school_num = $base_school_num order by sequence"); if (db_num_rows($allergens) > 0) { db_query("delete from allergies where school_num = $base_school_num and people_num = $record_num"); while ($row = db_fetch_array($allergens)) { $allergen_num = $row['record_num']; if (array_key_exists("allergen_$allergen_num", $_POST) && $_POST["allergen_$allergen_num"] == 'Y') { db_query("insert into allergies values($base_school_num,$record_num,$allergen_num)"); } } } // If the user_num was changed then move any order transactions to the new user_num if ($user_num != $orig_user_num) { db_query("UPDATE user_account SET user_num = $user_num WHERE people_num = $record_num"); } if (isset($override_naction)) $naction = $override_naction; $next_naction = 'search'; if ($action == 'account-students') { $next_naction = 'display'; $action .= "&uid=$user_num"; } if ($action == 'class-students') { $next_naction = 'display'; $action .= "¤t_class_num=$current_class_num"; } if (in_array($_SESSION['UserInfo']['type'],array('Parent','Staff'))) { $next_naction = 'display'; } $form_message = getLanguageText('RECORD-UPDATED-MSG'); header("Location: $FormTarget?action=$action&naction=$next_naction&mode=$mode&form_message=" . urlencode($form_message)); exit(); case "update-status": $sids = $_POST['sids']; for ($i = 0; $i < count($sids); $i++) { $snum = $sids[$i]; $status = $_POST["status_$snum"]; $query = "update people set status = '$status' " . "where school_num = $base_school_num " . "and people_type = 'Student' " . "and record_num = $snum"; db_query($query); } $next_naction = 'search'; $form_message = getLanguageText('TEXT-STUDENT-STATUS-UPDATED'); header("Location: $FormTarget?action=$action&naction=$next_naction&mode=$mode&form_message=" . urlencode($form_message)); exit(); case "student-lookup": include "students.lookup.php"; break; case "student-lookup-search": $search_text = db_escape_string($_POST['search_text']); if (strlen($search_text) < 2) { header("Location: /?action=users&naction=search"); exit(); } $sTextB = "'%25" . $search_text . "%25'"; $sText = "'" . $search_text . "%25'"; $lookup_where = "AND (st.first_name LIKE $sText " . "OR st.last_name LIKE $sText " . "OR u.last_name LIKE $sTextB " . "OR u.home_phone LIKE $sTextB)"; $naction = "list"; header("Location: /?action=$action&naction=$naction&lookup_where=" . urlencode($lookup_where)); break; case "show-info": include "students.info.php"; break; case "delete-confirmed": extract($_GET); $student_num = intval($record_num); $uwhere = ""; if ($_SESSION['UserInfo']['type'] == 'Parent' || $_SESSION['mode'] == 'parent') { $uwhere = "and user_num = " . $_SESSION['UserInfo']['record_num'] . " "; } $query = "select * from $CurrentTable " . "where school_num = $base_school_num " . $uwhere . "and record_num = $student_num"; $results = db_query($query); $numStudents = db_num_rows($results); // Check if this student has orders that are not Inactive if ($numStudents != 1) { $error_message = getLanguageText('ERRORMSG-NOT-FOUND'); header("Location: $FormTarget?action=$action&naction=display&show_status=$show_status&show_type=$show_type&uid=$uid&mode=$mode&error_message=" . urlencode($error_message)); exit(); } $row = db_fetch_array($results); extract($row); $snums = $school_record['linked_sites']; $numOrders = db_getVal("SELECT count(*) FROM hotlunch_order_header " . "WHERE school_num IN ($snums) " . "AND ordered_by_num = $student_num " . "AND status IN ('Unpaid','Pending','Paid','Complimentary')"); if ($numOrders > 0) { $error_message = getLanguageText('ERRORMSG-NO-DELETE-ORDERS'); header("Location: $FormTarget?action=$action&naction=display&show_status=$show_status&show_type=$show_type&uid=$uid&mode=$mode&error_message=" . urlencode($error_message)); exit(); } // Delete the current record $query = "delete from $CurrentTable where school_num = $base_school_num and record_num = $record_num"; db_query($query); // Delete any orders logOrderChange($record_num, "STUDENT DELETED", "students.php"); $query = "delete from hotlunch_order_header where school_num = $school_num and ordered_by_num = $record_num"; db_query($query); $query = "delete from hotlunch_order_items where school_num = $school_num and ordered_by_num = $record_num"; db_query($query); // Delete any allergies entries db_query("DELETE FROM allergies WHERE school_num = $base_school_num AND people_num = $record_num"); // Delete user account entries $query = "delete from user_account where school_num = $base_school_num and people_num = $record_num"; db_query($query); // Update user balance_owing updateUserBalance($user_num,$school_num); $form_message = getLanguageText('RECORD-DELETED-MSG'); $next_naction = 'search'; header("Location: $FormTarget?action=$action&naction=$next_naction&mode=$mode&form_message=" . urlencode($form_message)); exit(); case "verified": case "unverified": if ($_SESSION['UserInfo']['type'] == 'Parent') { include 'students.display.php'; break; } // Update student status $status = 'Verified'; if ($naction == 'unverified') $status = 'Unverified'; $query = "update people set status = '$status' " . "where school_num = $base_school_num " . "and record_num = $record_num"; db_query($query); $form_message = getLanguageText('TEXT-STUDENT-STATUS-UPDATED'); include 'students.display.php'; break; case "verify-all": if ($_SESSION['UserInfo']['type'] == 'Parent') { include 'students.display.php'; break; } // Update student status $status = 'Verified'; $query = "update people set status = '$status' " . "where school_num = $base_school_num " . "and class_num = $current_class_num"; db_query($query); $form_message = getLanguageText('TEXT-STUDENT-VERIFY-ALL'); include 'students.display.php'; break; case "update-verified": if ($_SESSION['UserInfo']['type'] == 'Parent') { include 'students.display.php'; break; } // Update student status $status = 'Verified'; $query = "update people set status = '$status' " . "where school_num = $base_school_num"; db_query($query); $form_message = getLanguageText('TEXT-STUDENT-VERIFY-ALL'); $action = "students"; $naction = "list-unverified"; include 'students.display.php'; break; case "update-unverified": if ($_SESSION['UserInfo']['type'] == 'Parent') { include 'students.display.php'; break; } // Update student status $status = 'Unverified'; $query = "update people set status = '$status' " . "where school_num = $base_school_num"; db_query($query); $form_message = getLanguageText('RECORDS-UPDATED-MSG'); $action = "students"; $naction = "search"; include 'students.display.php'; break; case "set-price-cat": if ($_SESSION['UserInfo']['type'] == 'Parent') { include 'students.display.php'; break; } // Update student price category $category = db_escape_string($_GET['price_category']); if (isset($current_class_num) && $current_class_num > 0) { $query = "update people set menu_price_category = '$category' " . "where school_num = $base_school_num " . "and class_num = $current_class_num"; } else { $query = "update people set menu_price_category = '$category' " . "where school_num = $base_school_num"; } db_query($query); $form_message = getLanguageText('RECORDS-UPDATED-MSG'); include 'students.display.php'; break; case "search": default: if ($userType == 'Parent' || $mode == 'parent') { include 'students.display.php'; break; } // Student Lookup Form include "students.lookup.php"; $ChoosePagination = 'Y'; $next_naction = "lookup"; // include $FormFile; break; case "lookup": extract($_POST); if ($people_type == 'Parent') { $people_type = 'Customer'; $class_num = 2; } $user_num = $selected_user_num; $school_num = $base_school_num; $table = new Table("$CurrentTable"); $lookup_query = $table->BuildQuery("","","st."); $school_num = $school_record['record_num']; $lookup_where = ""; if (strpos($lookup_query,"where ")) { $lookup_where = strstr($lookup_query," where"); $lookup_where = str_replace(" where"," and",$lookup_where); } if (strpos(strtolower($lookup_where),"order by ")) $lookup_where = preg_replace("/order by .*/i","",$lookup_where); $lookup_where .= " "; $naction = "list"; $TitleText = getLanguageText('RECORD-LOOKUP'); if (isset($user_num) && $user_num > 0) { $query = "select * from users where record_num = $user_num"; $results = db_query($query); $row = db_fetch_array($results); $userid = $row['userid']; $name = $row['first_name'] . ' ' . $row['last_name']; $PageTitle = getLanguageText('TEXT-STUDENT-ACCOUNT-LIST') . "
$name ($userid)"; } include 'students.display.php'; break; case "fetch": if ($_SESSION['UserInfo']['type'] == 'Parent') { include 'students.display.php'; break; } $lookup_where = "where school.record_num = $record_num"; $naction = "list"; $TitleText = getLanguageText('RECORD-LOOKUP'); break; case "edit-verified": case "edit-unverified": case "edit-all": if ($_SESSION['UserInfo']['type'] == 'Parent') { include 'students.display.php'; break; } $title = "Edit Students"; $swhere = ""; $grouping = "All"; if ($naction == "edit-verified") { $swhere .= "AND status = 'Verified' "; $title = "Edit Verified Students"; $grouping = "Verified"; } if ($naction == "edit-unverified") { $swhere .= "AND status = 'Unverified' "; $title = "Edit Unverified Students"; $grouping = "Unverified"; } if (isset($current_class_num) && $current_class_num > 0) { $swhere .= "AND class_num = $current_class_num "; $title = "Edit $grouping Class Students"; } $results = db_query("SELECT * FROM people WHERE school_num = $base_school_num AND people_type IN ('Student','Customer') $swhere ORDER BY last_name,first_name"); if (db_num_rows($results)) { $num = db_num_rows($results); include "students.edit-all.php"; } break; case "update-all": $grouping = $_POST['grouping']; $swhere = ""; if ($grouping == 'Verified') $swhere = "AND status = 'Verified' "; if ($grouping == 'Unverified') $swhere = "AND status = 'Unverified' "; if (array_key_exists('current_class_num',$_POST) && $_POST['current_class_num'] > 0) $swhere .= "AND class_num = " . $_POST['current_class_num'] . " "; $results = db_query("SELECT * FROM people WHERE school_num = $base_school_num AND people_type IN ('Student','Customer') $swhere ORDER BY last_name,first_name"); while ($row = db_fetch_array($results)) { $rnum = $row['record_num']; if (isset($_POST["class$rnum"]) && $_POST["class$rnum"] > 0) { $class_num = intval($_POST["class$rnum"]); $status = db_escape_string($_POST["status$rnum"]); $display = db_escape_string($_POST["display$rnum"]); if ($school_record['user_defined_values'] == 'Y') { $user_defined_value = $_POST["user_val$rnum"]; db_query("UPDATE people SET class_num = $class_num,status = '$status',display = '$display',user_defined_value = '$user_defined_value' WHERE record_num = $rnum"); } else { db_query("UPDATE people SET class_num = $class_num,status = '$status',display = '$display' WHERE record_num = $rnum"); } } } $form_message = getLanguageText('MSG-STUDENTS-UPDATED'); unset($class_num); unset($status); unset($display); unset($user_defined_value); $naction = "lookup"; $next_naction = "lookup"; break; case "reset-meal-locations": db_query("UPDATE people SET meal_location = class_num WHERE school_num = $base_school_num AND people_type IN ('Student','Customer','Staff')"); case "edit-meal-locations": if ($_SESSION['UserInfo']['type'] == 'Parent') { include 'students.display.php'; break; } $title = getLanguageText('TEXT-ALTERNATE-LOCATION'); $results = db_query("SELECT * FROM people WHERE school_num = $base_school_num AND people_type IN ('Student','Customer') ORDER BY last_name,first_name"); if (db_num_rows($results)) { $num = db_num_rows($results); include "students.edit-meal-locations.php"; } break; case "update-meal-locations": $results = db_query("SELECT * FROM people WHERE school_num = $base_school_num AND people_type IN ('Student','Customer') ORDER BY last_name,first_name"); while ($row = db_fetch_array($results)) { $rnum = $row['record_num']; $meal_location = intval($_POST['meal_location_'.$rnum]); db_query("UPDATE people SET meal_location = $meal_location WHERE record_num = $rnum"); } $form_message = getLanguageText('MSG-STUDENTS-UPDATED'); unset($class_num); unset($status); unset($display); unset($user_defined_value); $results = db_query("SELECT * FROM people WHERE school_num = $base_school_num AND people_type IN ('Student','Customer') ORDER BY last_name,first_name"); if (db_num_rows($results)) { $num = db_num_rows($results); include "students.edit-meal-locations.php"; } break; case "upload-form": include "students.upload.form.php"; break; case "upload": $num_fields = $_POST['num_fields']; $fields = explode(",",$_POST['fields']); // Get and process the data file $temp_name = $_FILES['filename']['tmp_name']; $file_name = str_replace(' ','_',$_FILES['filename']['name']); if (strlen($file_name) == 0) { $error_message = getLanguageText('MSG-NO-SOURCE-DATA-FILE'); $naction = "upload-form"; header("Location: /?action=$action&naction=$naction&error_message=".urlencode($error_message)); exit(); } // Validate the file type $finfo = finfo_open(FILEINFO_MIME_TYPE); $ftype = finfo_file($finfo,$temp_name); if ($ftype != "text/plain") { $error_message = getLanguageText('ERRORMSG-INVALID-FILE-FORMAT'); $naction = "upload-form"; header("Location: /?action=$action&naction=$naction&error_message=".urlencode($error_message)); exit(); } // Move file to temp folder if (!move_uploaded_file($temp_name,"temp/$school_num.students.csv")) { $error_message = getLanguageText('MSG-ZERO-UPLOADED'); $new_naction = "upload-form"; break; } // Open and process the data file $fp = fopen("temp/$school_num.students.csv","r"); $records = 0; $class_data = $_POST['class_data']; $userid_source = $_POST['userid_source']; $password_source = $_POST['password_source']; // Characters for generated password $CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $charsLength = strlen($CHARS) - 1; // Delete existing if required if (array_key_exists('delete_existing', $_POST) && $_POST['delete_existing'] == 'Y') { $linked_sites = $school_record['linked_sites']; db_query("delete from users where school_num = $school_num and type in ('Parent','Administration Team','Schedule Team','Volunteer Administrator')"); db_query("delete from user_account where school_num IN ($linked_sites)"); db_query("DELETE FROM user_account_detail WHERE school_num IN ($linked_sites)"); db_query("delete from user_online_payments where school_num IN ($linked_sites)"); db_query("delete from user_paypal_transactions where school_num IN ($linked_sites)"); db_query("delete from user_exact_transactions where school_num IN ($linked_sites)"); db_query("delete from user_merchant_account_transactions where school_num IN ($linked_sites)"); db_query("delete from people where school_num = $school_num and people_type = 'Student'"); db_query("delete from people where school_num = $school_num and people_type = 'Customer'"); } $user_count = 0; $class_count = 0; $student_count = 0; $error_count = 0; $skipped_count = 0; // delete existing entries db_query("DELETE FROM people_csv WHERE school_num = $school_num"); // Setup defaults for student insert $people_csv = new Table("people_csv"); $people = new Table("people"); $users = new Table("users"); $ua = new Table("user_account"); $added_date = date("Y-m-d",time()); $date_added = date("Y-m-d",time()); $people_type = "Student"; $status = "Verified"; $display = 'N'; $menu_price_category = "Regular"; $create_flag = 'N'; $created = 'N'; $errors = array(); $dataset_num = 1; $prev_snum = 0; $sequence = 1; $count = 0; if ($skip_first_row == 'Y') $count = 1; $row_num = 0; $country = $school_record['country']; db_query("DELETE FROM upload_columns WHERE school_num = $school_num AND action = '$action'"); $row_processed = false; if (array_key_exists('date_format',$_POST)) { $date_format = $_POST['date_format']; db_query("INSERT INTO upload_columns (school_num, action, field, value) VALUES ($school_num,'$action','date_format','$date_format')"); } if (array_key_exists('skip_first_row',$_POST)) { $skip_first_row = $_POST['skip_first_row']; db_query("INSERT INTO upload_columns (school_num, action, field, value) VALUES ($school_num,'$action','skip_first_row','$skip_first_row')"); } if (array_key_exists('userid_source',$_POST)) { $userid_source = $_POST['userid_source']; db_query("INSERT INTO upload_columns (school_num, action, field, value) VALUES ($school_num,'$action','userid_source','$userid_source')"); } if (array_key_exists('password_source',$_POST)) { $password_source = $_POST['password_source']; db_query("INSERT INTO upload_columns (school_num, action, field, value) VALUES ($school_num,'$action','password_source','$password_source')"); } while (($data = fgetcsv($fp,10000,",")) !== FALSE) { $row_num++; if ($row_num == 1 && $skip_first_row == 'Y') continue; $numDataFields = count($data); if ($numDataFields == 0) continue; $count++; // Set defaults $balance = 0.00; $note = ''; // Parse the data from the record for ($i = 0; $i < count($fields); $i++) { $fname = $fields[$i]; unset($$fname); // Update upload column entry $col = $_POST[$fname]; if (!$row_processed) db_query("INSERT INTO upload_columns (school_num, action, field, column_num) VALUES ($school_num,'$action','$fname',$col) ON DUPLICATE KEY UPDATE column_num = $col"); if (array_key_exists($fname, $_POST) && strlen($_POST[$fname]) > 0) { $col = $_POST[$fname] - 1; $$fname = preg_replace('/\$/','',trim($data[$col])); // Format birthdate if ($fname == "birthdate") { if (array_key_exists('date_format',$_POST)) { $birthdate = formatDate($birthdate,$_POST['date_format']); } else { $birthdate = date("Y-m-d",strtotime($date)); } } // Set gender/sex field if ($fname == "sex") { switch ($sex) { case 'F': $sex = 'Female'; break; case 'M': default: $sex = 'Male'; break; } } // Set account balance if required if ($fname == "balance") { $balance = number_format(floatval($data[$col]),2); } if ($fname == "email") $email = strtolower($email); if ($fname == "email2") $email2 = strtolower($email2); if ($fname == "email3") $email3 = strtolower($email3); if ($fname == "email4") $email4 = strtolower($email4); } } $row_processed = true; // Check for duplicate email addresses $emails = array(); if (strlen($email)) $emails[] = $email; if (strlen($email2) && !in_array($email2,$emails)) $emails[] = $email2; if (strlen($email3) && !in_array($email3,$emails)) $emails[] = $email3; if (strlen($email4) && !in_array($email4,$emails)) $emails[] = $email4; unset($email); unset($email2); unset($email3); unset($email4); switch (count($emails)) { case 3: $email3 = $emails[2]; case 2: $email2 = $emails[1]; case 1: $email = $emails[0]; default: break; } // Ensure that there is at least a student name if (strlen($first_name) == 0 || strlen($last_name) == 0) { $error_count++; $errors[] = array($count, getLanguageText('ERRORMSG-FIRST-LAST-NAME-REQUIRED'), $first_name, $last_name); continue; } // Ensure there is a student number if (strlen($student_number) == 0) { $error_count++; $errors[] = array($count, getLanguageText('ERRORMSG-STUDENT-NUMBER-REQUIRED'), $first_name, $last_name); continue; } // Check for an existing entry $query = "SELECT * FROM people WHERE school_num = $school_num AND student_number = '".db_escape_string($student_number)."'"; echo("\n"); $results = db_query($query); if (db_num_rows($results)) { $skipped_count++; echo("\n"); continue; } // Ensure there is a grade or division value if (strlen($division) == 0) unset($division); if (strlen($grade) == 0) unset($grade); if (!isset($division) && !isset($grade)) { $error_count++; $errors[] = array($count, getLanguageText('ERRORMSG-CLASS-DATA-MISSING'), $first_name, $last_name); continue; } // Update sequence for individual students if ($student_number == $prev_snum) $sequence++; else { $sequence = 1; // Get student class number unset($class_num); // Check using division field if set if (!isset($class_num) && isset($division)) { $results = db_query("SELECT record_num FROM classes WHERE school_num = $school_num AND division = '$division'"); if (db_num_rows($results)) { $row = db_fetch_assoc($results); $class_num = $row['record_num']; } } // Check using grade field if set if (!isset($class_num) && isset($grade)) { $results = db_query("SELECT * FROM classes WHERE school_num = $school_num AND grade = '$grade'"); if (db_num_rows($results)) { $row = db_fetch_assoc($results); $class_num = $row['record_num']; $menu_price_category = $row['default_price_category']; } } // Create class if not found if (!isset($class_num)) { $class_sequence = db_getVal("SELECT max(sequence) FROM classes WHERE school_num = $base_school_num") + 0; $class_sequence++; if (isset($grade)) { if (isset($division)) { echo("\n"); db_query("INSERT INTO classes (school_num,grade,division,sequence,default_price_category) VALUES($school_num,'$grade','$division',$class_sequence,'Regular')"); } else { echo("\n"); db_query("INSERT INTO classes (school_num,grade,sequence,default_price_category) VALUES($school_num,'$grade',$class_sequence,'Regular')"); } } else { echo("\n"); db_query("INSERT INTO classes (school_num,division,sequence,default_price_category) VALUES($school_num,'$division',$class_sequence,'Regular')"); } $class_num = db_insert_id(); $menu_price_category = 'Regular'; } } // Format phone numbers if ($school_record['country'] == 'Canada' || $school_record['country'] == 'USA') { if (strlen($home_phone)) { $home_phone = preg_replace("/[^0-9]/","",$home_phone); $home_phone = "(" . substr($home_phone,0,3) . ")" . substr($home_phone,3,3) . "-" . substr($home_phone,6); } if (strlen($daytime_phone)) { $daytime_phone = preg_replace("/[^0-9]/","",$daytime_phone); $daytime_phone = "(" . substr($daytime_phone,0,3) . ")" . substr($daytime_phone,3,3) . "-" . substr($daytime_phone,6); } if (strlen($cell_phone)) { $cell_phone = preg_replace("/[^0-9]/","",$cell_phone); $cell_phone = "(" . substr($cell_phone,0,3) . ")" . substr($cell_phone,3,3) . "-" . substr($cell_phone,6); } } // Format parent names if required if (strlen($parent_name) && strlen($parent_first_name) == 0 && strlen($parent_last_name) == 0) { list($parent_first_name,$parent_last_name) = explode(" ",$parent_name,2); } if (strlen($parent_name2) && strlen($parent_first_name2) == 0 && strlen($parent_last_name2) == 0) { list($parent_first_name2,$parent_last_name2) = explode(" ",$parent_name2,2); } // Ensure date format is correct if (isset($birthdate) && strlen($birthdate)) { $birthdate = date("Y-m-d",strtotime($birthdate)); } $prev_snum = $student_number; // Save record $query = $people_csv->BuildInsert(); echo("\n"); db_query($query); $records++; } // if ($_SESSION['UserInfo']['type'] == 'SuperUser') exit(); // Check for relationships table entries $numRelationships = db_getVal("SELECT count(*) FROM people_relationships WHERE school_num = $school_num"); $numStudentRelationships = db_getVal("SELECT count(*) FROM people_csv WHERE school_num = $school_num AND length(relationship) > 0"); $useRelationships = false; if ($numRelationships > 0 && $numStudentRelationships > 0) $useRelationships = true; // Create students and parents entries $query = "SELECT DISTINCT student_number FROM people_csv WHERE school_num = $school_num ORDER BY student_number"; $snums = db_query($query); // Identify which entry to use for account while ($row = db_fetch_assoc($snums)) { $snum = $row['student_number']; // Get student's entries in csv table if ($useRelationships) { $Squery = "SELECT pc.*,pr.sequence AS rsequence FROM people_csv AS pc, people_relationships AS pr " . "WHERE pc.school_num = $school_num " . "AND pr.school_num = $school_num " . "AND pc.relationship = pr.relationship " . "AND pc.student_number = '$snum' " . "ORDER BY rsequence, sequence"; } else { $Squery = "SELECT * FROM people_csv WHERE school_num = $school_num AND student_number = '$snum' ORDER BY sequence"; } $create_flag = 'N'; $entries = db_query($Squery); if (db_num_rows($entries)) { // Get all entries for this student into an array $studentEntries = array(); while ($row = db_fetch_assoc($entries)) { $studentEntries[] = $row; } for ($i = 0; $create_flag == 'N' && $i < count($studentEntries); $i++) { extract($studentEntries[$i]); $match = 0; if (strlen($userid) == 0 && strlen($email) && str_match('@',$email)) { if ($userid_source == 'Email Address') $userid = db_escape_string($email); if ($userid_source == 'Parent First Name and Last Name') { $fname = str_replace('.','',str_replace("'",'',str_replace(' ','',$parent_first_name))); $lname = str_replace('.','',str_replace("'",'',str_replace(' ','',$parent_last_name))); $userid = db_escape_string(strtolower($fname.'.'.$lname)); } if ($userid_source == 'Student Number') $userid = db_escape_string($student_number); $match = 1; } if (strlen($userid) == 0 && strlen($email2) && str_match('@',$email2)) { if ($userid_source == 'Email Address') $userid = db_escape_string($email2); if ($userid_source == 'Parent First Name and Last Name') { $fname = str_replace('.','',str_replace("'",'',str_replace(' ','',$parent_first_name2))); $lname = str_replace('.','',str_replace("'",'',str_replace(' ','',$parent_last_name2))); $userid = db_escape_string(strtolower($fname.'.'.$lname)); } $match = 2; } if (strlen($userid)) { // Set password switch ($password_source) { case 'Email Address': if ($match == 1) $password = db_escape_string($email); if ($match == 2) $password = db_escape_string($email2); break; case 'Parent First Name and Last Name': if ($match == 1) { $fname = str_replace('.','',str_replace("'",'',str_replace(' ','',$parent_first_name))); $lname = str_replace('.','',str_replace("'",'',str_replace(' ','',$parent_last_name))); $password = db_escape_string(strtolower($fname.'.'.$lname)); } if ($match == 2) { $fname = str_replace('.','',str_replace("'",'',str_replace(' ','',$parent_first_name2))); $lname = str_replace('.','',str_replace("'",'',str_replace(' ','',$parent_last_name2))); $password = db_escape_string(strtolower($fname.'.'.$lname)); } break; case 'Home Phone': $password = preg_replace("/[^0-9]/","",$home_phone); break; case 'User ID': $password = $userid; break; case 'Initials and Student Number': $password = substr($parent_first_name,0,1).substr($parent_last_name,0,1).$student_number; echo("\n"); break; case 'Random Password': $password = ""; while (strlen($password) < 10) { $c = rand(0,$charsLength); $password .= substr($CHARS,$c,1); } break; } if (strlen($password) == 0) $password = $userid; // Update entry to flag it for use as user account db_query("UPDATE people_csv SET create_flag = 'Y', userid = '$userid', password = '$password' WHERE school_num = $school_num AND record_num = $record_num"); $create_flag = 'Y'; // Check for a second email address $i++; if (array_key_exists('save_second_email_address', $_POST) && $_POST['save_second_email_address'] == 'Y' && strlen($email2) == 0 && count($studentEntries) > $i) { for ($j = $i; $j < count($studentEntries); $j++) { $email2 = $studentEntries[$j]['email']; if (strlen($email2) && str_match('@',$email2)) { $first_name2 = db_escape_string($studentEntries[$j]['parent_first_name']); $last_name2 = db_escape_string($studentEntries[$j]['parent_last_name']); $email2 = db_escape_string($email2); db_query("UPDATE people_csv SET parent_first_name2 = '$first_name2', parent_last_name2 = '$last_name2', email2 = '$email2' WHERE school_num = $school_num AND record_num = $record_num"); $j = count($studentEntries); } } } } } // If no entry with email address was found then use the first entry for the student if ($create_flag == 'N') { $results = db_query($query); $row = db_fetch_assoc($results); extract($row); // Set userid if (strlen($userid) == 0) { if (strlen($parent_first_name) && strlen($parent_last_name)) $userid = db_escape_string(strtolower($parent_first_name.'.'.$parent_last_name)); if (strlen($userid) == 0 && strlen($parent_first_name)) $userid = db_escape_string(strtolower($parent_first_name)); if (strlen($userid) == 0 && strlen($parent_last_name)) $userid = db_escape_string(strtolower($parent_last_name)); if (strlen($userid) == 0) { if (strlen($parent_first_name2) && strlen($parent_last_name2)) $userid = db_escape_string(strtolower($parent_first_name2.'.'.$parent_last_name2)); if (strlen($userid) == 0 && strlen($parent_first_name2)) $userid = db_escape_string(strtolower($parent_first_name2)); if (strlen($userid) == 0 && strlen($parent_last_name2)) $userid = db_escape_string(strtolower($parent_last_name2)); } if (strlen($userid) == 0) $userid = "no.parent.info"; $userid = str_replace(" ","",$userid); } // Set password switch ($password_source) { case 'Email Address': $password = db_escape_string(strtolower($email)); break; case 'Parent First Name and Last Name': $password = db_escape_string(strtolower($parent_first_name.'.'.$parent_last_name)); $password = str_replace(" ","",$password); break; case 'Home Phone': $password = preg_replace("/[^0-9]/","",$home_phone); break; case 'User ID': $password = $userid; break; } if (strlen($password) == 0) $password = $userid; db_query("UPDATE people_csv SET create_flag = 'Y', userid = '$userid', password = '$password' WHERE school_num = $school_num AND record_num = $record_num"); } } } $create_log = array(); $query = "SELECT * FROM people_csv WHERE school_num = $school_num AND create_flag = 'Y' ORDER BY student_number"; $entries = db_query($query); while ($row = db_fetch_assoc($entries)) { extract($row); // Check if this student is in the system already $results = db_query("SELECT * FROM people WHERE school_num = $school_num AND student_number = '$student_number'"); if (db_num_rows($results)) { $create_log[] = array($student_number, $first_name, $last_name, '', '', '', getLanguageText('TEXT-DUPLICATE-ENTRY')); continue; } else { // Check if there is a user account already $userRecord = array(); $userRecord['school_num'] = $school_num; $userRecord['first_name'] = db_escape_string($parent_first_name); $userRecord['last_name'] = db_escape_string($parent_last_name); $userRecord['first_name2'] = db_escape_string($parent_first_name2); $userRecord['last_name2'] = db_escape_string($parent_last_name2); $userRecord['userid'] = db_escape_string($userid); $userRecord['password'] = db_escape_string($password); $userRecord['email'] = db_escape_string($email); $userRecord['email2'] = db_escape_string($email2); $userRecord['home_phone'] = db_escape_string($home_phone); $userRecord['daytime_phone'] = db_escape_string($daytime_phone); $userRecord['cell_phone'] = db_escape_string($cell_phone); $userRecord['type'] = 'Parent'; $userRecord['status'] = 'Active'; $userRecord['date_added'] = $date_added; $userRecord['can_order'] = 'Yes'; $userRecord['has_order'] = 'N'; $userRecord['num_orders'] = 0; $userRecord['balance_owing'] = 0.00; $userRecord['account_balance'] = 0.00; $userRecord['receive_emails'] = 'Y'; $userRecord['email_reminders'] = 'Y'; $userRecord['email_flag'] = 'Y'; $userRecord['language'] = $school_record['default_language']; $userRecord['added_time'] = time(); $results = db_query("SELECT * FROM users WHERE school_num = $base_school_num AND userid = '" . db_escape_string($userid) . "'"); // Get user_num if record found if (db_num_rows($results) == 1) { $row = db_fetch_array($results); $user_num = $row['record_num']; $status = getLanguageText('TEXT-USER-ACCOUNT-FOUND'); if ($parent_first_name != $row['first_name']) $status .= " (" . getLanguageText('TEXT-PARENT-FIRST-NAME') . ")"; if ($parent_last_name != $row['last_name']) $status .= " (" . getLanguageText('TEXT-PARENT-LAST-NAME') . ")"; if ($home_phone != $row['home_phone']) $status .= " (" . getLanguageText('TEXT-HOME-PHONE') . ")"; $create_log[] = array($student_number, $first_name, $last_name, $userid, $parent_first_name, $parent_last_name, getLanguageText('TEXT-USER-ACCOUNT-FOUND')); } else { if (strlen($userRecord['email']) == 0 && strlen($userRecord['email2']) > 0) { $userRecord['email'] = $userRecord['email2']; $userRecord['email2'] = ""; } $userRecord['password_crypt'] = encrypt_password($password); // Create user account if not found $query = $users->BuildInsert($userRecord); echo("\n"); db_query($query); $user_num = db_insert_id(); $user_count++; // Create balance forward entry if there is a balance amount if ($balance != 0.00) { $transaction_type = 'Charge Adjustment'; if ($balance < 0) $transaction_type = 'Credit Adjustment'; if (strlen($note) == 0) $note = $school_record['previous_balances_post_message']; else $note = $school_record['previous_balances_post_message'] . ": $note"; $transaction_amount = $balance; $entered_time = time(); $transaction_datetime = date("Y-m-d H:i:s",$entered_time); // Create a new transaction $query = $ua->BuildInsert(); echo("\n"); db_query($query); } $create_log[] = array($student_number, $first_name, $last_name, $userid, $parent_first_name, $parent_last_name, getLanguageText('TEXT-USER-ACCOUNT-CREATED')); } // Insert student record $status = 'Verified'; $display = 'Y'; $active = 'Y'; $query = $people->BuildInsert(); echo("\n"); db_query($query); $student_count++; } } $data = array(); $data[] = array(getLanguageText('TEXT-CLASSES'),$class_count); $data[] = array(getLanguageText('TEXT-PARENTS'),$user_count); $data[] = array(getLanguageText('TEXT-STUDENTS'),$student_count); $data[] = array(getLanguageText('TEXT-ERRORS'),$error_count); $data[] = array(getLanguageText('TEXT-SKIPPED'),$skipped_count); $columnHeaders = array(getLanguageText('TEXT-RESULT'),getLanguageText('TEXT-NUMBER')); $columnAlign = array('center','center'); $TableWidth = 450; listDataCustom($data,$columnHeaders,'',array(),'N',$columnAlign); echo("
"); $columnHeaders = array(getLanguageText('TEXT-STUDENT-NUMBER'), getLanguageText('TEXT-FIRST-NAME'), getLanguageText('TEXT-LAST-NAME'), getLanguageText('TEXT-USER-ID'), getLanguageText('TEXT-PARENT-FIRST-NAME'), getLanguageText('TEXT-PARENT-LAST-NAME'), getLanguageText('TEXT-STATUS')); $columnAlign = array('center','center','center','center','center','center','center'); unset($TableWidth); listDataCustom($create_log,$columnHeaders,'',array(),'N',$columnAlign); if ($error_count > 0) { $columnHeaders = array("Row","Error","First Name","Last Name"); $columnAlign = array('left','left','left','left'); unset($TableWidth); listDataCustom($errors,$columnHeaders,'',array(),'N',$columnAlign); } break; case "students-update-form": include "students.update.form.php"; break; case "students-update-upload": $num_fields = $_POST['num_fields']; $fields = explode(",",$_POST['fields']); // Get and process the data file $temp_name = $_FILES['filename']['tmp_name']; $file_name = str_replace(' ','_',$_FILES['filename']['name']); if (!isset($file_name) || strlen($file_name) == 0) { $error_message = getLanguageText('MSG-NO-SOURCE-DATA-FILE'); $naction = "upload-form"; header("Location: /?action=$action&naction=$naction&error_message=".urlencode($error_message)); exit(); } // Validate the file type $finfo = finfo_open(FILEINFO_MIME_TYPE); $ftype = finfo_file($finfo,$temp_name); if ($ftype != "text/plain") { $error_message = getLanguageText('ERRORMSG-INVALID-FILE-FORMAT'); $naction = "upload-form"; header("Location: /?action=$action&naction=$naction&error_message=".urlencode($error_message)); exit(); } // Move file to temp folder if (!move_uploaded_file($temp_name,"temp/$school_num.students.csv")) { $error_message = getLanguageText('MSG-ZERO-UPLOADED'); $new_naction = "upload-form"; break; } // Open and process the data file $fp = fopen("temp/$school_num.students.csv","r"); $records = 0; $student_count = 0; $error_count = 0; $skipped_count = 0; $count = 0; if ($skip_first_row == 'Y') $count = 1; $row_num = 0; $uaction = "students-update"; db_query("DELETE FROM upload_columns WHERE school_num = $school_num AND action = '$uaction'"); $row_processed = false; if (array_key_exists('skip_first_row',$_POST)) { $skip_first_row = $_POST['skip_first_row']; db_query("INSERT INTO upload_columns (school_num, action, field, value) VALUES ($school_num,'$uaction','skip_first_row','$skip_first_row')"); } while (($data = fgetcsv($fp,10000,",")) !== FALSE) { $row_num++; if ($row_num == 1 && $skip_first_row == 'Y') continue; $numDataFields = count($data); if ($numDataFields == 0) continue; $count++; // Parse the data from the record for ($i = 0; $i < count($fields); $i++) { $fname = $fields[$i]; unset($$fname); // Update upload column entry $col = $_POST[$fname]; if (!$row_processed) db_query("INSERT INTO upload_columns (school_num, action, field, column_num) VALUES ($school_num,'$uaction','$fname',$col) ON DUPLICATE KEY UPDATE column_num = $col"); if (array_key_exists($fname, $_POST) && strlen($_POST[$fname]) > 0) { $col = $_POST[$fname] - 1; $$fname = preg_replace('/\$/','',trim($data[$col])); } } // Ensure there is a student number if (strlen($student_number) == 0) { $error_count++; $errors[] = array($count, getLanguageText('ERRORMSG-STUDENT-NUMBER-REQUIRED')); continue; } // Check for an existing entry $query = "SELECT * FROM people WHERE school_num = $school_num AND student_number = '".db_escape_string($student_number)."'"; $results = db_query($query); if (db_num_rows($results) == 0) { $error_count++; $errors[] = array($count, getLanguageText('ERRORMSG-STUDENT-NOT-FOUND'),$student_number); continue; } $row = db_fetch_assoc($results); $rnum = $row['record_num']; $query = "UPDATE people SET school_grade = '" . db_escape_string($grade) . "' WHERE record_num = $rnum"; $student_count++; } $data = array(); $data[] = array(getLanguageText('TEXT-STUDENTS'),$student_count); $data[] = array(getLanguageText('TEXT-ERRORS'),$error_count); $data[] = array(getLanguageText('TEXT-SKIPPED'),$skipped_count); $columnHeaders = array(getLanguageText('TEXT-RESULT'),getLanguageText('TEXT-NUMBER')); $columnAlign = array('center','center'); $TableWidth = 450; listDataCustom($data,$columnHeaders,'',array(),'N',$columnAlign); if ($error_count > 0) { $columnHeaders = array("Row","Error"); $columnAlign = array('left','left'); listDataCustom($errors,$columnHeaders,'',array(),'N',$columnAlign); } break; case "view-added-dates": $query = "SELECT added_date,count(*) AS num FROM people " . "WHERE school_num = $school_num " . "AND people_type = 'Student' " . "GROUP BY 1 " . "ORDER BY 1"; $results = db_query($query); $data = array(); while ($row = db_fetch_assoc($results)) { extract($row); $data[] = array($added_date,"" . $num . ""); } $columnHeaders = array(getLanguageText('TEXT-DATE-ADDED'),getLanguageText('TEXT-COUNT')); $columnAlign = array('center','center'); $TableWidth = 400; listDataCustom($data,$columnHeaders,'',array(),'N',$columnAlign); break; case "view-added-dates-list": $added_date = db_escape_string($_GET['added_date']); $query = "SELECT p.first_name,p.last_name,p.student_number,u.userid,p.added_date,user_num FROM people AS p, users AS u " . "WHERE p.school_num = $school_num " . "AND u.school_num = $school_num " . "AND p.people_type = 'Student' " . "AND p.added_date = '$added_date' " . "AND p.user_num = u.record_num " . "ORDER BY p.last_name,p.first_name"; $results = db_query($query); $data = array(); while ($row = db_fetch_assoc($results)) { extract($row); $data[] = array($first_name,$last_name,$student_number,"".$userid."",$added_date); } $columnHeaders = array(getLanguageText('TEXT-FIRST-NAME'), getLanguageText('TEXT-LAST-NAME'), getLanguageText('TEXT-STUDENT-NUMBER'), getLanguageText('TEXT-USER-ID'), getLanguageText('TEXT-DATE-ADDED')); $columnAlign = array('left','left','left','left'); $TableWidth = 700; listDataCustom($data,$columnHeaders,'',array(),'N',$columnAlign); break; case "copy-to-lockers": $lschool_num = intval($school_record['locker_school_num']); if ($lschool_num == 0) break; // Get student records $query = "SELECT p.*,c.grade FROM people AS p, classes AS c " . "WHERE p.school_num = $school_num " . "AND c.school_num = $school_num " . "AND p.class_num = c.record_num " . "AND people_type = 'Student' " . "AND student_number IS NOT NULL " . "AND student_number > ''"; $results = db_query($query); if (db_num_rows($results)) { $students = array(); while ($row = db_fetch_assoc($results)) { $students[] = $row; } // Characters for generated password $CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $charsLength = strlen($CHARS) - 1; $date_added = date("Y-m-d",time()); $added_time = date("Y-m-d H:i:s",time()); db_close($_DB); $_DB = mysql_connect("web3-db",$db_uname,$db_pass); db_query("USE locker_assignment"); $users = new Table("users"); $user_count = 0; for ($i = 0; $i < count($students); $i++) { $entry = $students[$i]; $student_number = $entry['student_number']; // Check if this student exists in locker system already $query = "SELECT * FROM users WHERE school_num = $lschool_num AND userid = '$student_number'"; $results = db_query($query); if (db_num_rows($results) == 0) { // Generate the password $password = ""; while (strlen($password) < 10) { $c = rand(0,$charsLength); $password .= substr($CHARS,$c,1); } $entry['school_num'] = $lschool_num; $entry['userid'] = $student_number; $entry['password'] = $password; $entry['status'] = 'Active'; $entry['type'] = 'Student'; $entry['date_added'] = $date_added; $entry['added_time'] = $added_time; $query = $users->BuildInsert($entry); db_query($query); $user_count++; } } } db_close($_DB); $_DB = mysql_connect("localhost",$db_uname,$db_pass); db_query("USE hotlunch"); $form_message = getLanguageText('TEXT-USER-ACCOUNTS-CREATED') . ": $user_count"; $error_message = ""; header("Location: $FormTarget?action=students&naction=search&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message)); exit(); case "display": case "list": case "list-class": case "list-unverified": case "list-inactive": case "students-without-class-number": case "students-without-student-number": writeLog("students.display.php"); include 'students.display.php'; break; } // // Display search screen if required // if ($userType != 'Parent' && $mode != 'parent' && $naction == 'lookup') { // Student Lookup Form include "students.lookup.php"; $ChoosePagination = 'Y'; $next_naction = "lookup"; include $FormFile; } if (intval($school_record['locker_school_num']) > 0) { echo("

Copy to Lockers

\n"); } endTemplate(); ?>