ajax.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /* Copyright (C) 2001-2004 Andreu Bisquerra <jove@bisquerra.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/takepos/ajax.php
  19. * \brief Ajax search component for TakePos. It search products of a category.
  20. */
  21. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
  22. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
  23. if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  24. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
  25. if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
  26. if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');
  27. if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
  28. if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
  29. if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
  30. require '../main.inc.php'; // Load $user and permissions
  31. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  32. $category = GETPOST('category','alpha');
  33. $action = GETPOST('action','alpha');
  34. $term = GETPOST('term','alpha');
  35. /*
  36. * View
  37. */
  38. if ($action=="getProducts"){
  39. $object = new Categorie($db);
  40. $result=$object->fetch($category);
  41. $prods = $object->getObjectsInCateg("product");
  42. echo json_encode($prods);
  43. }
  44. if ($action=="search"){
  45. $sql = 'SELECT * FROM '.MAIN_DB_PREFIX.'product';
  46. $sql.= ' WHERE entity IN ('.getEntity('product').')';
  47. $sql .= natural_search(array('label','barcode'), $term);
  48. $resql = $db->query($sql);
  49. $rows = array();
  50. while($row = $db->fetch_array ($resql)){
  51. $rows[] = $row;
  52. }
  53. echo json_encode($rows);
  54. }