First Commit
This commit is contained in:
1 parent
5eb9dd037d
commit
2e62c0e60b
11877 files changed
+2035312
No files matched your search
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
$ValidAccess = 2010;
|
||||
$sessionName = 'hotlunch';
|
||||
session_name($sessionName);
|
||||
session_start();
|
||||
require_once("include/globals.php");
|
||||
|
||||
|
||||
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
||||
logExit("Session is not active\n");
|
||||
exit;
|
||||
}
|
||||
|
||||
include "include/ajax.csrfToken.php";
|
||||
|
||||
|
||||
|
||||
// Set default timezone
|
||||
date_default_timezone_set("Canada/Pacific");
|
||||
$now = date("Y-m-d H:i:s",time());
|
||||
|
||||
$return_data = array();
|
||||
|
||||
$moduleName = "ajax.SearchDBFields.php";
|
||||
startLog($moduleName);
|
||||
|
||||
|
||||
// Get parameters
|
||||
if (array_key_exists('table_name', $_GET)) $table_name = db_escape_string($_GET['table_name']);
|
||||
if (array_key_exists('field_names', $_GET)) $field_names = db_escape_string($_GET['field_names']);
|
||||
if (array_key_exists('term', $_GET)) $term = db_escape_string($_GET['term']);
|
||||
|
||||
|
||||
// Ensure parameters are valid
|
||||
if (!is_numeric($school_num)) logExit("School num is not numeric\n");
|
||||
if ($school_num == 0) logExit("school_num is zero\n");
|
||||
if (!isset($table_name)) logExit("ajax.SearchDBFields.php - table_name is not set");
|
||||
if (!isset($field_names)) logExit("ajax.SearchDBFields.php - field_names is not set");
|
||||
|
||||
writeLog("table_name: $table_name\n");
|
||||
writeLog("field_names: $field_names\n");
|
||||
writeLog("term: $term\n");
|
||||
|
||||
$fields = explode(',', $field_names);
|
||||
$where = "";
|
||||
|
||||
for ($i = 0; $i < count($fields); $i++) {
|
||||
$field = $fields[$i];
|
||||
if (strlen($where)) $where .= "OR ";
|
||||
$where .= "$field LIKE '%$term%' ";
|
||||
}
|
||||
|
||||
$query = "SELECT * FROM $table_name WHERE school_num = $school_num AND ($where)";
|
||||
writeLog($query);
|
||||
$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)) {
|
||||
$text = "";
|
||||
for ($i = 0; $i < count($fields); $i++) {
|
||||
$field = $fields[$i];
|
||||
$text .= $row[$field].' ';
|
||||
}
|
||||
|
||||
$text = trim($text);
|
||||
$record_num = $row['record_num'];
|
||||
|
||||
$return_data[] = array(
|
||||
"value" => $text,
|
||||
"record_num" => $record_num
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
writeLog("completed\n");
|
||||
echo(json_encode($return_data));
|
||||
?>
|
||||
Reference in new issue
Block a user