From b5e7b261ca9c39f721079314a6b0d0da2956d1a4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 27 May 2011 08:52:17 +0000 Subject: [PATCH] Work on zipautofill module --- htdocs/core/ajaxziptown.php | 15 ++++++--------- htdocs/install/mysql/migration/3.0.0-3.1.0.sql | 3 +++ htdocs/install/mysql/tables/llx_c_ziptown.sql | 3 ++- htdocs/lib/databases/pgsql.lib.php | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/htdocs/core/ajaxziptown.php b/htdocs/core/ajaxziptown.php index 004a68a34f0..e9cc5653fb7 100644 --- a/htdocs/core/ajaxziptown.php +++ b/htdocs/core/ajaxziptown.php @@ -63,16 +63,13 @@ if (! empty($_GET['zipcode']) || ! empty($_GET['town'])) if ($conf->global->MAIN_USE_ZIPTOWN_DICTIONNARY) // Use zip-town table { - $sql = "SELECT z.rowid, z.zip, z.town, z.fk_county"; + $sql = "SELECT z.rowid, z.zip, z.town, z.fk_county, z.fk_country"; $sql.= ", p.rowid as fk_country, p.code as country_code, p.libelle as country"; - $sql.= ", d.rowid as fk_county, d.code_departement as county_code , d.nom as county"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_ziptown as z"; - $sql.= ", ".MAIN_DB_PREFIX ."c_departements as d"; - $sql.= ", ".MAIN_DB_PREFIX."c_regions as r"; - $sql.= ",".MAIN_DB_PREFIX."c_pays as p"; - $sql.= " WHERE z.fk_county = d.rowid"; - $sql.= " AND d.fk_region = r.code_region"; - $sql.= " AND r.fk_pays = p.rowid"; + $sql.= ", d.rowid as fk_county, d.code_departement as county_code, d.nom as county"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_ziptown as z,".MAIN_DB_PREFIX."c_pays as p"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX ."c_departements as d ON z.fk_county = d.rowid"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_regions as r ON d.fk_region = r.code_region"; + $sql.= " WHERE z.fk_pays = p.rowid"; $sql.= " AND z.active = 1 AND d.active = 1 AND r.active = 1 AND p.active = 1"; if ($zipcode) " AND z.zip LIKE '" . $db->escape($zipcode) . "%'"; if ($town) " AND z.town LIKE '%" . $db->escape($town) . "%'"; diff --git a/htdocs/install/mysql/migration/3.0.0-3.1.0.sql b/htdocs/install/mysql/migration/3.0.0-3.1.0.sql index 070915e60ce..0e909015a03 100755 --- a/htdocs/install/mysql/migration/3.0.0-3.1.0.sql +++ b/htdocs/install/mysql/migration/3.0.0-3.1.0.sql @@ -17,6 +17,9 @@ RENAME TABLE llx_c_methode_commande_fournisseur TO llx_c_input_method; ALTER TABLE llx_adherent MODIFY login varchar(50); +ALTER TABLE llx_c_ziptown ADD COLUMN fk_pays integer NOT NULL DEFAULT 0 after fk_county; +ALTER TABLE llx_c_ziptown MODIFY fk_county integer NULL; + ALTER TABLE llx_c_actioncomm ADD COLUMN position integer NOT NULL DEFAULT 0; ALTER TABLE llx_propal ADD COLUMN fk_demand_reason integer NULL DEFAULT 0; ALTER TABLE llx_commande_fournisseur ADD COLUMN fk_cond_reglement integer NULL DEFAULT 0; diff --git a/htdocs/install/mysql/tables/llx_c_ziptown.sql b/htdocs/install/mysql/tables/llx_c_ziptown.sql index 8ffde4de01b..40759cdc50b 100644 --- a/htdocs/install/mysql/tables/llx_c_ziptown.sql +++ b/htdocs/install/mysql/tables/llx_c_ziptown.sql @@ -22,7 +22,8 @@ create table llx_c_ziptown ( rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY, code varchar(5) DEFAULT NULL, -- ex: code insee pour la France - fk_county integer NOT NULL, -- County id in llx_c_departements + fk_county integer, -- State id in llx_c_departements + fk_pays integer NOT NULL DEFAULT 0, -- Country id in llx_c_pays zip varchar(10) NOT NULL, -- Zip code town varchar(255) NOT NULL, -- Town name active tinyint NOT NULL DEFAULT 1 diff --git a/htdocs/lib/databases/pgsql.lib.php b/htdocs/lib/databases/pgsql.lib.php index 6588faf1e87..26cad4ba543 100644 --- a/htdocs/lib/databases/pgsql.lib.php +++ b/htdocs/lib/databases/pgsql.lib.php @@ -185,7 +185,7 @@ class DoliDb $line=preg_replace('/,$/','',$line); } - // Process case: "CREATE TABLE llx_c_ziptown(rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,code..." + // Process case: "CREATE TABLE llx_mytable(rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,code..." if (preg_match('/[\s\t\(]*(\w*)[\s\t]+int.*auto_increment/i',$line,$reg)) { $newline=preg_replace('/([\s\t\(]*)([a-zA-Z_0-9]*)[\s\t]+int.*auto_increment[^,]*/i','\\1 \\2 SERIAL PRIMARY KEY',$line); //$line = "-- ".$line." replaced by --\n".$newline;