locationincoterms.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /* Copyright (C) 2010 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2011-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2021 Henry Guo <henrynopo@homtail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/core/ajax/locationincoterms.php
  21. * \ingroup core
  22. * \brief File to return Ajax response on location_incoterms request
  23. */
  24. if (!defined('NOTOKENRENEWAL')) {
  25. define('NOTOKENRENEWAL', 1); // Disables token renewal
  26. }
  27. if (!defined('NOREQUIREMENU')) {
  28. define('NOREQUIREMENU', '1');
  29. }
  30. if (!defined('NOREQUIREHTML')) {
  31. define('NOREQUIREHTML', '1');
  32. }
  33. if (!defined('NOREQUIREAJAX')) {
  34. define('NOREQUIREAJAX', '1');
  35. }
  36. if (!defined('NOREQUIRESOC')) {
  37. define('NOREQUIRESOC', '1');
  38. }
  39. // Load Dolibarr environment
  40. require '../../main.inc.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  42. /*
  43. * View
  44. */
  45. // Ajout directives pour resoudre bug IE
  46. //header('Cache-Control: Public, must-revalidate');
  47. //header('Pragma: public');
  48. //top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
  49. top_httphead();
  50. //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
  51. dol_syslog('location_incoterms call with MAIN_USE_LOCATION_INCOTERMS_DICTIONNARY='.(empty($conf->global->MAIN_USE_LOCATION_INCOTERMS_DICTIONNARY) ? '' : $conf->global->MAIN_USE_LOCATION_INCOTERMS_DICTIONNARY));
  52. //var_dump($_GET);
  53. // Generation of list of zip-town
  54. if (GETPOST('location_incoterms')) {
  55. $return_arr = array();
  56. // Define filter on text typed
  57. $location_incoterms = GETPOST('location_incoterms');
  58. if (!empty($conf->global->MAIN_USE_LOCATION_INCOTERMS_DICTIONNARY)) { // Use location_incoterms
  59. $sql = "SELECT z.location as location_incoterms, z.label as label";
  60. $sql .= " FROM ".MAIN_DB_PREFIX."c_location_incoterms as z";
  61. $sql .= " WHERE z.active = 1 AND UPPER(z.location) LIKE UPPER('%".$db->escape($location_incoterms)."%')";
  62. $sql .= " ORDER BY z.location";
  63. $sql .= $db->plimit(100); // Avoid pb with bad criteria
  64. } else // Use table of commande
  65. {
  66. $sql = "SELECT DISTINCT s.location_incoterms FROM ".MAIN_DB_PREFIX.'commande as s';
  67. $sql .= " WHERE UPPER(s.location_incoterms) LIKE UPPER('%".$db->escape($location_incoterms)."%')";
  68. //Todo: merge with data from table of supplier order
  69. /* $sql .=" UNION";
  70. $sql .= " SELECT DISTINCT p.location_incoterms FROM ".MAIN_DB_PREFIX.'commande_fournisseur as p';
  71. $sql .= " WHERE UPPER(p.location_incoterms) LIKE UPPER('%".$db->escape($location_incoterms)."%')";
  72. */
  73. $sql .= " ORDER BY s.location_incoterms";
  74. $sql .= $db->plimit(100); // Avoid pb with bad criteria
  75. }
  76. //print $sql;
  77. $resql = $db->query($sql);
  78. //var_dump($db);
  79. if ($resql) {
  80. while ($row = $db->fetch_array($resql)) {
  81. $row_array['label'] = $row['location_incoterms'].($row['label']?' - '.$row['label'] : '');
  82. if ($location_incoterms) {
  83. $row_array['value'] = $row['location_incoterms'];
  84. }
  85. // TODO Use a cache here to avoid to make select_state in each pass (this make a SQL and lot of logs)
  86. array_push($return_arr, $row_array);
  87. }
  88. }
  89. echo json_encode($return_arr);
  90. }
  91. $db->close();