77 lines
2.2 KiB
PHP
77 lines
2.2 KiB
PHP
<?php
|
|
$ValidAccess = 2010;
|
|
require_once("include/globals.php");
|
|
|
|
|
|
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";
|
|
|
|
|
|
$moduleName = "ajax.studentSearch.php";
|
|
// startLog($moduleName);
|
|
|
|
|
|
// Get search text
|
|
$text = trim(strtolower($_GET['term']));
|
|
$words = explode(' ',$text);
|
|
writeLog("text: $text\n");
|
|
|
|
|
|
// Format where clause
|
|
$uwhere = "";
|
|
for ($i = 0; $i < count($words); $i++) {
|
|
$word = db_escape_string($words[$i]);
|
|
$uwhere .= "AND (people.first_name LIKE '$word%' " .
|
|
"OR people.last_name LIKE '$word%') ";
|
|
}
|
|
|
|
// Get matching user records
|
|
$query = "SELECT DISTINCT people.first_name,people.last_name,user_num,people.record_num,users.first_name AS parent_first_name,users.last_name AS parent_last_name FROM people,users " .
|
|
"WHERE people.school_num = $school_num " .
|
|
"AND users.school_num = $school_num " .
|
|
"AND people.user_num = users.record_num " .
|
|
$uwhere .
|
|
"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);
|
|
$num = db_getVal("SELECT count(*) FROM hotlunch_order_header WHERE school_num = $school_num AND ordered_by_num = $record_num AND status NOT IN ('Pending','Deleted')");
|
|
$return_data[] = array("value" => "$first_name $last_name ($num) - $parent_first_name $parent_last_name",
|
|
"student_num" => $record_num);
|
|
}
|
|
}
|
|
|
|
|
|
writeLog("completed\n");
|
|
echo(json_encode($return_data));
|
|
return false;
|
|
|
|
?>
|