73 lines
1.9 KiB
PHP
73 lines
1.9 KiB
PHP
<?php
|
|
$ValidAccess = 2010;
|
|
$sessionName = 'hotlunch';
|
|
session_name($sessionName);
|
|
session_start();
|
|
require_once("include/globals.php");
|
|
|
|
|
|
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
|
logExit("Session is not active",$moduleName);
|
|
exit;
|
|
}
|
|
|
|
// CSRF token validation
|
|
include "include/ajax.csrfToken.php";
|
|
|
|
|
|
|
|
$moduleName = "ajax.supplierSearch.php";
|
|
// startLog($moduleName);
|
|
|
|
|
|
// 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]);
|
|
$num = 0;
|
|
if (is_numeric($word)) $num = intval($word);
|
|
$swhere .= "AND (school_name LIKE '%$word%' " .
|
|
"OR suppliers.supplier_name LIKE '%$word%' " .
|
|
"OR suppliers.city LIKE '$word%' " .
|
|
"OR suppliers.contact_name LIKE '%$word%' " .
|
|
"OR suppliers.province LIKE '%$word%') ";
|
|
}
|
|
|
|
// Get matching records
|
|
$query = "SELECT DISTINCT supplier_name,suppliers.contact_name,suppliers.city,suppliers.province,school_name,suppliers.record_num " .
|
|
"FROM suppliers,schools " .
|
|
"WHERE suppliers.status = 'Active' " .
|
|
"AND suppliers.school_num = schools.record_num " .
|
|
$swhere .
|
|
"ORDER BY supplier_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");
|
|
while ($row = db_fetch_assoc($results)) {
|
|
extract($row);
|
|
$name = "$supplier_name, $city, $province - $school_name";
|
|
$return_data[] = array("value" => $name,
|
|
"supplier_name" => $supplier_name,
|
|
"supplier_num" => $record_num);
|
|
}
|
|
}
|
|
|
|
|
|
writeLog("completed\n");
|
|
echo(json_encode($return_data));
|
|
return false;
|
|
|
|
?>
|