dolibarr  17.0.3
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 
26 if (!defined('NOTOKENRENEWAL')) {
27  define('NOTOKENRENEWAL', 1); // Disables token renewal
28 }
29 if (!defined('NOREQUIREMENU')) {
30  define('NOREQUIREMENU', '1');
31 }
32 if (!defined('NOREQUIREHTML')) {
33  define('NOREQUIREHTML', '1');
34 }
35 if (!defined('NOREQUIREAJAX')) {
36  define('NOREQUIREAJAX', '1');
37 }
38 if (!defined('NOREQUIRESOC')) {
39  define('NOREQUIRESOC', '1');
40 }
41 
42 // Load Dolibarr environment
43 require '../../main.inc.php';
44 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
45 
46 
47 /*
48  * View
49  */
50 
51 // Ajout directives pour resoudre bug IE
52 //header('Cache-Control: Public, must-revalidate');
53 //header('Pragma: public');
54 
55 //top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
56 top_httphead();
57 
58 //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
59 
60 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));
61 //var_dump($_GET);
62 
63 // Generation of list of zip-town
64 if (GETPOST('location_incoterms')) {
65  $return_arr = array();
66 
67  // Define filter on text typed
68  $location_incoterms = GETPOST('location_incoterms');
69 
70  if (!empty($conf->global->MAIN_USE_LOCATION_INCOTERMS_DICTIONNARY)) { // Use location_incoterms
71  $sql = "SELECT z.location as location_incoterms, z.label as label";
72  $sql .= " FROM ".MAIN_DB_PREFIX."c_location_incoterms as z";
73  $sql .= " WHERE z.active = 1 AND UPPER(z.location) LIKE UPPER('%".$db->escape($location_incoterms)."%')";
74  $sql .= " ORDER BY z.location";
75  $sql .= $db->plimit(100); // Avoid pb with bad criteria
76  } else // Use table of commande
77  {
78  $sql = "SELECT DISTINCT s.location_incoterms FROM ".MAIN_DB_PREFIX.'commande as s';
79  $sql .= " WHERE UPPER(s.location_incoterms) LIKE UPPER('%".$db->escape($location_incoterms)."%')";
80 
81  //Todo: merge with data from table of supplier order
82  /* $sql .=" UNION";
83  $sql .= " SELECT DISTINCT p.location_incoterms FROM ".MAIN_DB_PREFIX.'commande_fournisseur as p';
84  $sql .= " WHERE UPPER(p.location_incoterms) LIKE UPPER('%".$db->escape($location_incoterms)."%')";
85  */
86  $sql .= " ORDER BY s.location_incoterms";
87  $sql .= $db->plimit(100); // Avoid pb with bad criteria
88  }
89 
90  //print $sql;
91  $resql = $db->query($sql);
92  //var_dump($db);
93  if ($resql) {
94  while ($row = $db->fetch_array($resql)) {
95  $row_array['label'] = $row['location_incoterms'].($row['label']?' - '.$row['label'] : '');
96  if ($location_incoterms) {
97  $row_array['value'] = $row['location_incoterms'];
98  }
99  // TODO Use a cache here to avoid to make select_state in each pass (this make a SQL and lot of logs)
100 
101  array_push($return_arr, $row_array);
102  }
103  }
104 
105  echo json_encode($return_arr);
106 }
107 
108 $db->close();
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:520
top_httphead
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1440
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1628