2016-05-16 15:43:49 -06:00
|
|
|
<?php
|
2016-05-19 00:41:51 -06:00
|
|
|
/**
|
|
|
|
* Search for a given term (q=) in a given category (from=) and spit out JSON.
|
|
|
|
*/
|
2016-05-16 15:43:49 -06:00
|
|
|
require 'required.php';
|
|
|
|
|
|
|
|
require 'dieifnotloggedin.php';
|
|
|
|
|
|
|
|
$q = $_GET['q'];
|
2016-05-17 03:23:46 -06:00
|
|
|
$from = $_GET['from'];
|
2016-05-16 15:43:49 -06:00
|
|
|
require 'readfrom.php';
|
|
|
|
|
|
|
|
if (is_empty($q)) {
|
|
|
|
die(json_encode(['status' => 'OK', 'results' => []]));
|
|
|
|
}
|
|
|
|
|
|
|
|
$results;
|
2016-05-19 00:41:51 -06:00
|
|
|
// If you want to search through more/different fields, just add them.
|
2016-05-16 15:43:49 -06:00
|
|
|
if ($from == 'assets') {
|
|
|
|
$results = $database->select($from, '*', ['OR' => ['name[~]' => $q, 'asset_tag[~]' => $q, 'serial[~]' => $q, 'order_number[~]' => $q]]);
|
|
|
|
} else {
|
|
|
|
$results = $database->select($from, '*', ['OR' => ['name[~]' => $q, 'order_number[~]' => $q]]);
|
|
|
|
}
|
|
|
|
|
2016-05-18 14:48:32 -06:00
|
|
|
if ($results == false) {
|
|
|
|
$results = [];
|
|
|
|
}
|
|
|
|
|
2016-05-16 15:43:49 -06:00
|
|
|
//var_dump($database->error());
|
|
|
|
//var_dump($results);
|
|
|
|
|
2016-05-18 14:48:32 -06:00
|
|
|
die(json_encode(['status' => 'OK', 'results' => $results]));
|