dolibarr 18.0.6
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 *
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
26if (!defined('NOTOKENRENEWAL')) {
27 define('NOTOKENRENEWAL', 1); // Disables token renewal
28}
29if (!defined('NOREQUIREMENU')) {
30 define('NOREQUIREMENU', '1');
31}
32if (!defined('NOREQUIREHTML')) {
33 define('NOREQUIREHTML', '1');
34}
35if (!defined('NOREQUIREAJAX')) {
36 define('NOREQUIREAJAX', '1');
37}
38if (!defined('NOREQUIRESOC')) {
39 define('NOREQUIRESOC', '1');
40}
41
42// Load Dolibarr environment
43require '../../main.inc.php';
44require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
45
46// Security check
47if (!isModEnabled('incoterm')) {
48 httponly_accessforbidden("Module incoterm not enabled"); // This includes the exit.
49}
50// There is no other permission on this component. Everybody connected can read content of the incoterm table
51
52
53/*
54 * View
55 */
56
57// Ajout directives pour resoudre bug IE
58//header('Cache-Control: Public, must-revalidate');
59//header('Pragma: public');
60
61//top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
63
64//print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
65
66dol_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));
67//var_dump($_GET);
68
69// Generation of list of zip-town
70if (GETPOST('location_incoterms')) {
71 $return_arr = array();
72
73 // Define filter on text typed
74 $location_incoterms = GETPOST('location_incoterms');
75
76 if (!empty($conf->global->MAIN_USE_LOCATION_INCOTERMS_DICTIONNARY)) { // Use location_incoterms
77 $sql = "SELECT z.location as location_incoterms, z.label as label";
78 $sql .= " FROM ".MAIN_DB_PREFIX."c_location_incoterms as z";
79 $sql .= " WHERE z.active = 1 AND z.location LIKE '%".$db->escape($db->escapeforlike($location_incoterms))."%'";
80 $sql .= " ORDER BY z.location";
81 $sql .= $db->plimit(100); // Avoid pb with bad criteria
82 } else { // Use table of sale orders
83 $sql = "SELECT DISTINCT s.location_incoterms FROM ".MAIN_DB_PREFIX.'commande as s';
84 $sql .= " WHERE s.location_incoterms LIKE '%".$db->escape($db->escapeforlike($location_incoterms))."%'";
85
86 //Todo: merge with data from table of supplier order
87 /* $sql .=" UNION";
88 $sql .= " SELECT DISTINCT p.location_incoterms FROM ".MAIN_DB_PREFIX.'commande_fournisseur as p';
89 $sql .= " WHERE UPPER(p.location_incoterms) LIKE UPPER('%".$db->escape($location_incoterms)."%')";
90 */
91 $sql .= " ORDER BY s.location_incoterms";
92 $sql .= $db->plimit(100); // Avoid pb with bad criteria
93 }
94
95 //print $sql;
96 $resql = $db->query($sql);
97 //var_dump($db);
98 if ($resql) {
99 while ($row = $db->fetch_array($resql)) {
100 $row_array['label'] = $row['location_incoterms'].($row['label']?' - '.$row['label'] : '');
101 if ($location_incoterms) {
102 $row_array['value'] = $row['location_incoterms'];
103 }
104 // TODO Use a cache here to avoid to make select_state in each pass (this make a SQL and lot of logs)
105
106 array_push($return_arr, $row_array);
107 }
108 }
109
110 echo json_encode($return_arr);
111}
112
113$db->close();
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.