94 lines
2.8 KiB
PHP
94 lines
2.8 KiB
PHP
<?php
|
|
$ValidAccess = 2010;
|
|
require_once("include/globals.php");
|
|
|
|
|
|
$moduleName = "ajax.StudentSearch.php";
|
|
// startLog($moduleName);
|
|
|
|
|
|
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
|
logExit("Session is not active",$moduleName);
|
|
exit();
|
|
}
|
|
|
|
// Set userType
|
|
$userType = "Parent";
|
|
if (array_key_exists('type', $_SESSION['UserInfo']) && in_array($_SESSION['UserInfo']['type'],$AllAdminUserTypes)) $userType = "Admin";
|
|
if ($userType != 'Admin') return;
|
|
|
|
|
|
// Ensure that only valid user types have access to this module
|
|
if ($userType != 'Admin') {
|
|
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
|
|
logExit($error_message);
|
|
exit;
|
|
}
|
|
|
|
|
|
// CSRF token validation
|
|
include "include/ajax.csrfToken.php";
|
|
|
|
|
|
|
|
// Get search text
|
|
$text = trim(strtolower($_GET['term']));
|
|
$words = explode(' ',$text);
|
|
writeLog("text: $text\n");
|
|
|
|
|
|
// Format where clause
|
|
$swhere = "";
|
|
for ($i = 0; $i < count($words); $i++) {
|
|
$word = db_escape_string($words[$i]);
|
|
$swhere .= "AND (st.first_name LIKE '$word%' " .
|
|
"OR st.last_name LIKE '$word%' " .
|
|
"OR st.email LIKE '$word%' " .
|
|
"OR u.userid LIKE '$word%' " .
|
|
"OR student_number LIKE '$word%' " .
|
|
"OR label_note LIKE '%$word%' " .
|
|
"OR cust_phone LIKE '%$word%' " .
|
|
"OR cust_phone LIKE '%$word%' " .
|
|
"OR cust_address LIKE '%$word%' " .
|
|
"OR st.notes LIKE '%$word%') ";
|
|
}
|
|
|
|
// Get matching user records
|
|
$query = "SELECT st.* FROM people AS st, users AS u " .
|
|
"WHERE st.school_num = $base_school_num " .
|
|
"AND u.school_num = $base_school_num " .
|
|
"AND st.user_num = u.record_num " .
|
|
$swhere .
|
|
"ORDER BY last_name,first_name";
|
|
writeLog("query: $query\n");
|
|
$results = db_query($query);
|
|
|
|
// Format data for return
|
|
$return_data = array();
|
|
$num_records = db_num_rows($results);
|
|
if ($num_records > 0) {
|
|
writeLog("records: $num_records\n");
|
|
$return_data[] = array();
|
|
while ($row = db_fetch_assoc($results)) {
|
|
extract($row);
|
|
$query = "SELECT count(*) FROM hotlunch_order_header AS hloh, hotlunch_schedules AS hls " .
|
|
"WHERE hloh.school_num = $school_num " .
|
|
"AND hls.school_num = $school_num " .
|
|
"AND hloh.schedule_num = hls.record_num " .
|
|
"AND hls.status IN ('Pending','Active') " .
|
|
"AND ordered_by_num = $record_num";
|
|
$num = db_getVal($query);
|
|
$class_info = $people_type;
|
|
if ($school_record['participant_grouping'] != 'None') $class_info = getClassInfo($class_num);
|
|
$return_data[] = array("value" => "$first_name $last_name ($num) - $class_info",
|
|
"student_num" => $record_num);
|
|
}
|
|
}
|
|
|
|
|
|
writeLog("completed\n");
|
|
echo(json_encode($return_data));
|
|
return false;
|
|
|
|
?>
|