Simple PHP api for SnipeIT app. Not maintained anymore; check out BinStack instead: https://source.netsyms.com/Business/BinStack and https://netsyms.biz/binstack
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

search.php 820B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. /**
  3. * Search for a given term (q=) in a given category (from=) and spit out JSON.
  4. */
  5. require 'required.php';
  6. require 'dieifnotloggedin.php';
  7. $q = $_GET['q'];
  8. $from = $_GET['from'];
  9. require 'readfrom.php';
  10. if (is_empty($q)) {
  11. die(json_encode(['status' => 'OK', 'results' => []]));
  12. }
  13. $results;
  14. // If you want to search through more/different fields, just add them.
  15. if ($from == 'assets') {
  16. $results = $database->select($from, '*', ['OR' => ['name[~]' => $q, 'asset_tag[~]' => $q, 'serial[~]' => $q, 'order_number[~]' => $q]]);
  17. } else {
  18. $results = $database->select($from, '*', ['OR' => ['name[~]' => $q, 'order_number[~]' => $q]]);
  19. }
  20. if ($results == false) {
  21. $results = [];
  22. }
  23. //var_dump($database->error());
  24. //var_dump($results);
  25. die(json_encode(['status' => 'OK', 'results' => $results]));