locationincoterms.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. if (!defined('NOCSRFCHECK')) {
  40. define('NOCSRFCHECK', '1');
  41. }
  42. require '../../main.inc.php';
  43. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  44. /*
  45. * View
  46. */
  47. // Ajout directives pour resoudre bug IE
  48. //header('Cache-Control: Public, must-revalidate');
  49. //header('Pragma: public');
  50. //top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
  51. top_httphead();
  52. //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
  53. 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));
  54. //var_dump($_GET);
  55. // Generation of list of zip-town
  56. if (GETPOST('location_incoterms')) {
  57. $return_arr = array();
  58. // Define filter on text typed
  59. $location_incoterms = GETPOST('location_incoterms');
  60. if (!empty($conf->global->MAIN_USE_LOCATION_INCOTERMS_DICTIONNARY)) { // Use location_incoterms
  61. $sql = "SELECT z.location as location_incoterms, z.label as label";
  62. $sql .= " FROM ".MAIN_DB_PREFIX."c_location_incoterms as z";
  63. $sql .= " WHERE z.active = 1 AND UPPER(z.location) LIKE UPPER('%".$db->escape($location_incoterms)."%')";
  64. $sql .= " ORDER BY z.location";
  65. $sql .= $db->plimit(100); // Avoid pb with bad criteria
  66. } else // Use table of commande
  67. {
  68. $sql = "SELECT DISTINCT s.location_incoterms FROM ".MAIN_DB_PREFIX.'commande as s';
  69. $sql .= " WHERE UPPER(s.location_incoterms) LIKE UPPER('%".$db->escape($location_incoterms)."%')";
  70. //Todo: merge with data from table of supplier order
  71. /* $sql .=" UNION";
  72. $sql .= " SELECT DISTINCT p.location_incoterms FROM ".MAIN_DB_PREFIX.'commande_fournisseur as p';
  73. $sql .= " WHERE UPPER(p.location_incoterms) LIKE UPPER('%".$db->escape($location_incoterms)."%')";
  74. */
  75. $sql .= " ORDER BY s.location_incoterms";
  76. $sql .= $db->plimit(100); // Avoid pb with bad criteria
  77. }
  78. //print $sql;
  79. $resql = $db->query($sql);
  80. //var_dump($db);
  81. if ($resql) {
  82. while ($row = $db->fetch_array($resql)) {
  83. $row_array['label'] = $row['location_incoterms'].($row['label']?' - '.$row['label'] : '');
  84. if ($location_incoterms) {
  85. $row_array['value'] = $row['location_incoterms'];
  86. }
  87. // TODO Use a cache here to avoid to make select_state in each pass (this make a SQL and lot of logs)
  88. array_push($return_arr, $row_array);
  89. }
  90. }
  91. echo json_encode($return_arr);
  92. }
  93. $db->close();