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