dolibarr 21.0.0-beta
locationincoterms.php
Go to the documentation of this file.
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27if (!defined('NOTOKENRENEWAL')) {
28 define('NOTOKENRENEWAL', 1); // Disables token renewal
29}
30if (!defined('NOREQUIREMENU')) {
31 define('NOREQUIREMENU', '1');
32}
33if (!defined('NOREQUIREHTML')) {
34 define('NOREQUIREHTML', '1');
35}
36if (!defined('NOREQUIREAJAX')) {
37 define('NOREQUIREAJAX', '1');
38}
39if (!defined('NOREQUIRESOC')) {
40 define('NOREQUIRESOC', '1');
41}
42
43// Load Dolibarr environment
44require '../../main.inc.php';
45require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
46
55// Security check
56if (!isModEnabled('incoterm')) {
57 httponly_accessforbidden("Module incoterm not enabled"); // This includes the exit.
58}
59
60// There is no other permission on this component. Everybody connected can read content of the incoterm dictionary table
61
62
63/*
64 * View
65 */
66
67// Ajout directives pour resoudre bug IE
68//header('Cache-Control: Public, must-revalidate');
69//header('Pragma: public');
70
71//top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
73
74//print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
75
76dol_syslog('location_incoterms call with MAIN_USE_LOCATION_INCOTERMS_DICTIONNARY='.getDolGlobalString('MAIN_USE_LOCATION_INCOTERMS_DICTIONNARY', ''));
77
78// Generation of list of zip-town
79if (GETPOST('location_incoterms')) {
80 $return_arr = array();
81
82 // Define filter on text typed
83 $location_incoterms = GETPOST('location_incoterms');
84
85 if (getDolGlobalString('MAIN_USE_LOCATION_INCOTERMS_DICTIONNARY')) { // Use location_incoterms
86 $sql = "SELECT z.location as location_incoterms, z.label as label";
87 $sql .= " FROM ".MAIN_DB_PREFIX."c_location_incoterms as z";
88 $sql .= " WHERE z.active = 1 AND z.location LIKE '%".$db->escape($db->escapeforlike($location_incoterms))."%'";
89 $sql .= " ORDER BY z.location";
90 $sql .= $db->plimit(1000); // Avoid pb with bad criteria
91 } else { // Use table of sale orders
92 $sql = "SELECT DISTINCT s.location_incoterms FROM ".MAIN_DB_PREFIX.'commande as s';
93 $sql .= " WHERE s.location_incoterms LIKE '%".$db->escape($db->escapeforlike($location_incoterms))."%'";
94
95 //Todo: merge with data from table of supplier order
96 /* $sql .=" UNION";
97 $sql .= " SELECT DISTINCT p.location_incoterms FROM ".MAIN_DB_PREFIX.'commande_fournisseur as p';
98 $sql .= " WHERE UPPER(p.location_incoterms) LIKE UPPER('%".$db->escape($location_incoterms)."%')";
99 */
100 $sql .= " ORDER BY s.location_incoterms";
101 $sql .= $db->plimit(100); // Avoid pb with bad criteria
102 }
103
104 //print $sql;
105 $resql = $db->query($sql);
106 //var_dump($db);
107 if ($resql) {
108 $row_array = array();
109 while ($row = $db->fetch_array($resql)) {
110 $row_array['label'] = $row['location_incoterms'].($row['label'] ? ' - '.$row['label'] : '');
111 if ($location_incoterms) {
112 $row_array['value'] = $row['location_incoterms'];
113 }
114 // TODO Use a cache here to avoid to make select_state in each pass (this make a SQL and lot of logs)
115
116 array_push($return_arr, $row_array);
117 }
118 }
119
120 echo json_encode($return_arr);
121}
122
123$db->close();
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.