dolibarr  7.0.0-beta
ziptown.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2010 Regis Houssin <regis.houssin@capnetworks.com>
3  * Copyright (C) 2011-204 Laurent Destailleur <eldy@users.sourceforge.net>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
25 if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal
26 if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
27 if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
28 if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
29 if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
30 if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
31 
32 require '../../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
34 
35 
36 
37 /*
38  * View
39  */
40 
41 // Ajout directives pour resoudre bug IE
42 //header('Cache-Control: Public, must-revalidate');
43 //header('Pragma: public');
44 
45 //top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
46 top_httphead();
47 
48 //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
49 
50 dol_syslog("GET is ".join(',',$_GET).', MAIN_USE_ZIPTOWN_DICTIONNARY='.(empty($conf->global->MAIN_USE_ZIPTOWN_DICTIONNARY)?'':$conf->global->MAIN_USE_ZIPTOWN_DICTIONNARY));
51 //var_dump($_GET);
52 
53 // Generation of list of zip-town
54 if (! empty($_GET['zipcode']) || ! empty($_GET['town']))
55 {
56  $return_arr = array();
57  $formcompany = new FormCompany($db);
58 
59  // Define filter on text typed
60  $zipcode = $_GET['zipcode']?$_GET['zipcode']:'';
61  $town = $_GET['town']?$_GET['town']:'';
62 
63  if (! empty($conf->global->MAIN_USE_ZIPTOWN_DICTIONNARY)) // Use zip-town table
64  {
65  $sql = "SELECT z.rowid, z.zip, z.town, z.fk_county, z.fk_pays as fk_country";
66  $sql.= ", c.rowid as fk_country, c.code as country_code, c.label as country";
67  $sql.= ", d.rowid as fk_county, d.code_departement as county_code, d.nom as county";
68  $sql.= " FROM ".MAIN_DB_PREFIX."c_ziptown as z";
69  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX ."c_departements as d ON z.fk_county = d.rowid";
70  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_regions as r ON d.fk_region = r.code_region,";
71  $sql.= " ".MAIN_DB_PREFIX."c_country as c";
72  $sql.= " WHERE z.fk_pays = c.rowid";
73  $sql.= " AND z.active = 1 AND c.active = 1";
74  if ($zipcode) $sql.=" AND z.zip LIKE '" . $db->escape($zipcode) . "%'";
75  if ($town) $sql.=" AND z.town LIKE '%" . $db->escape($town) . "%'";
76  $sql.= " ORDER BY z.zip, z.town";
77  $sql.= $db->plimit(100); // Avoid pb with bad criteria
78  }
79  else // Use table of third parties
80  {
81  $sql = "SELECT DISTINCT s.zip, s.town, s.fk_departement as fk_county, s.fk_pays as fk_country";
82  $sql.= ", c.code as country_code, c.label as country";
83  $sql.= ", d.code_departement as county_code , d.nom as county";
84  $sql.= " FROM ".MAIN_DB_PREFIX.'societe as s';
85  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX ."c_departements as d ON s.fk_departement = d.rowid";
86  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid';
87  $sql.= " WHERE";
88  if ($zipcode) $sql.= " s.zip LIKE '".$db->escape($zipcode)."%'";
89  if ($town) $sql.= " s.town LIKE '%" . $db->escape($town) . "%'";
90  $sql.= " ORDER BY s.fk_pays, s.zip, s.town";
91  $sql.= $db->plimit(100); // Avoid pb with bad criteria
92  }
93 
94  //print $sql;
95  $resql=$db->query($sql);
96  //var_dump($db);
97  if ($resql)
98  {
99  while ($row = $db->fetch_array($resql))
100  {
101  $country = $row['fk_country']?($langs->transnoentitiesnoconv('Country'.$row['country_code'])!='Country'.$row['country_code']?$langs->transnoentitiesnoconv('Country'.$row['country_code']):$row['country']):'';
102  $county = $row['fk_county']?($langs->transnoentitiesnoconv($row['county_code'])!=$row['county_code']?$langs->transnoentitiesnoconv($row['county_code']):($row['county']!='-'?$row['county']:'')):'';
103 
104  $row_array['label'] = $row['zip'].' '.$row['town'];
105  $row_array['label'] .= ($county || $country)?' (':'';
106  $row_array['label'] .= $county;
107  $row_array['label'] .= ($county && $country?' - ':'');
108  $row_array['label'] .= $country;
109  $row_array['label'] .= ($county || $country)?')':'';
110  if ($zipcode)
111  {
112  $row_array['value'] = $row['zip'];
113  $row_array['town'] = $row['town'];
114  }
115  if ($town)
116  {
117  $row_array['value'] = $row['town'];
118  $row_array['zipcode'] = $row['zip'];
119  }
120  $row_array['selectcountry_id'] = $row['fk_country'];
121  $row_array['state_id'] = $row['fk_county'];
122 
123  $row_array['states'] = $formcompany->select_state('',$row['fk_country'],'');
124 
125  array_push($return_arr,$row_array);
126  }
127  }
128 
129  echo json_encode($return_arr);
130 }
131 else
132 {
133 
134 }
135 
136 $db->close();
137 
Class to build HTML component for third parties management Only common components are here...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html')
Show HTTP header.
Definition: main.inc.php:1052