From 21987a43109e08202fb7a139525bfdd690421bf8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 21 Feb 2010 15:16:49 +0000 Subject: [PATCH] Fix: fix hidden option MAIN_AUTOFILL_TOWNFROMZIP --- htdocs/comm/addpropal.php | 10 +-- htdocs/comm/adresse_livraison.php | 8 +- htdocs/{ => core}/searchpostalcode.php | 110 ++++++++++++++++--------- htdocs/lib/lib_head.js | 4 +- htdocs/soc.php | 4 +- 5 files changed, 85 insertions(+), 51 deletions(-) rename htdocs/{ => core}/searchpostalcode.php (82%) diff --git a/htdocs/comm/addpropal.php b/htdocs/comm/addpropal.php index 551ce3c55b1..0adee081865 100644 --- a/htdocs/comm/addpropal.php +++ b/htdocs/comm/addpropal.php @@ -109,7 +109,7 @@ if ($_GET["action"] == 'create') print ''; // Ref - print ''; + print ''; // Reference client print ''; // Societe - print ''; print ''; @@ -140,12 +140,12 @@ if ($_GET["action"] == 'create') print '.'; print ''; - // Date facture - print ''; - print ''; + print ''; // Terms of payment print ''; print ''; print ''; @@ -344,7 +344,7 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit') print ''; print ''; print ''; diff --git a/htdocs/searchpostalcode.php b/htdocs/core/searchpostalcode.php similarity index 82% rename from htdocs/searchpostalcode.php rename to htdocs/core/searchpostalcode.php index f76e12e4c71..81f06df488d 100644 --- a/htdocs/searchpostalcode.php +++ b/htdocs/core/searchpostalcode.php @@ -1,6 +1,6 @@ - * Copyright (C) 2006-2009 Laurent Destailleur + * Copyright (C) 2006-2010 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,36 +41,6 @@ require("pre.inc.php"); $langs->load("companies"); - -function run_request($table) -{ - global $db; - $cp=isset($_GET["cp"])?trim($_GET["cp"]):''; - - $sql = "SELECT DISTINCT cp, ville, fk_departement, fk_pays, p.code as pays_code, p.libelle as pays_lib"; - $sql.= " FROM ".MAIN_DB_PREFIX.$table; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX.'c_pays as p ON fk_pays = p.rowid'; - $sql.= " WHERE"; - if ($cp) - { - $cp=str_replace('*','%',$cp); - $sql.= " cp LIKE '".addslashes($cp)."' AND"; - $sql.= " (ville IS NOT NULL OR fk_departement IS NOT NULL OR fk_pays IS NOT NULL)"; - } - else $sql.= " cp != '' AND cp IS NOT NULL"; - $sql.= " ORDER by fk_pays, ville, cp"; - $sql.= ' '.$db->plimit(50); // Avoid pb with bad criteria - - //print $sql.'
'; - $result=$db->query($sql); - if (!$result) - { - dol_print_error($db); - } - return $result; -} - - // Security Access Client if ($user->societe_id > 0) { @@ -79,6 +49,12 @@ if ($user->societe_id > 0) $_GET["socid"] = $user->societe_id; } +// Entry parameter are +// $_GET = array +// 'cp' => string '78180' (length=5) +// 'targettown' => string 'window.opener.document.formsoc.ville' (length=36) +// 'targetcountry' => string 'window.opener.document.formsoc.pays_id' (length=38) +// 'targetstate' /* * View @@ -104,10 +80,12 @@ function MAJ(targettown,targetcountry,targetstate) //--> \n"; + top_htmlhead("", $langs->trans("SearchTown")); // Same as llxHeader. Open what llxFooter close print ''; + print $javascript; print '
'.$langs->trans("Ref").'
'.$langs->trans("Ref").'
'.$langs->trans('RefCustomer').''; @@ -117,7 +117,7 @@ if ($_GET["action"] == 'create') print '
'.$langs->trans('Company').''.$soc->getNomUrl(1); + print '
'.$langs->trans('Company').''.$soc->getNomUrl(1); print ''; print '
'.$langs->trans('Date').''; + // Date + print '
'.$langs->trans('Date').''; $html->select_date('','','','','',"addprop"); print '
'.$langs->trans("ValidityDuration").' '.$langs->trans("days").'
'.$langs->trans("ValidityDuration").' '.$langs->trans("days").'
'.$langs->trans('PaymentConditionsShort').''; diff --git a/htdocs/comm/adresse_livraison.php b/htdocs/comm/adresse_livraison.php index e898a6979c0..d20d78bead7 100644 --- a/htdocs/comm/adresse_livraison.php +++ b/htdocs/comm/adresse_livraison.php @@ -50,7 +50,7 @@ $result = restrictedArea($user, 'societe', $socid); if ($_POST["action"] == 'add' || $_POST["action"] == 'update') { $livraison = new AdresseLivraison($db); - + $livraison->socid = $_POST["socid"]; $livraison->label = ($_POST["label"]!=$langs->trans('RequiredField')?$_POST["label"]:''); $livraison->nom = ($_POST["nom"]!=$langs->trans('RequiredField')?$_POST["nom"]:''); @@ -139,7 +139,7 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes' && $user- { $livraison = new AdresseLivraison($db); $result = $livraison->delete($_GET["id"], $socid); - + if ($result == 0) { Header("Location: adresse_livraison.php?socid=".$socid); @@ -239,7 +239,7 @@ if ($_GET["action"] == 'create' || $_POST["action"] == 'create') print '
'.$langs->trans('Zip').''; - if ($conf->use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' '; + if ($conf->use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' '; print '
'.$langs->trans('Town').'
'.$langs->trans('Zip').''; - if ($conf->use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' '; + if ($conf->use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' '; print '
'.$langs->trans('Town').'
"; } else @@ -155,6 +147,7 @@ if ($result) $cp = $obj->cp; $ville = $obj->ville; + $ville_code = urlencode("$ville"); $dep = $obj->fk_departement; $dep_lib = $obj->fk_departement; @@ -179,8 +172,11 @@ if ($result) $var=!$var; print ""; @@ -189,4 +185,42 @@ print "
'; @@ -131,19 +109,33 @@ if ($result) //print 'sql='.$sql.' num='.$num; exit; if($num == 0) { - $result = run_request("postalcode"); - $num=$db->num_rows($result); + if ($conf->global->MAIN_AUTOFILL_TOWNFROMZIP == 2) + { + $result = run_request("postalcode"); // If a table llx_postalcode exists + $num=$db->num_rows($result); + } } + $showselect=1; + // If it has not, or only one result on switch and fill the form if($num <= 1) { $obj = $db->fetch_object($result); $ville = $obj->ville; $ville_code = urlencode("$ville"); - print "
"; - print ''; - print "\n"; + print "
"; + if ($ville && $ville_code) + { + print ''; + print "\n"; + } + else + { + $langs->load("errors"); + print $langs->trans("ErrorRecordNotFound"); + $showselect=0; + } print "
"; print "
"; -print "trans("Select")."\">"; -print "   "; +if ($showselect) +{ + print "trans("Select")."\">"; + print "   "; +} print "trans("Cancel")."\" onClick=\"window.close();\">"; print "

\n"; $db->close(); llxFooter('$Date$ - $Revision$',0); + + +/** + * Enter description here... + * + * @param unknown_type $table + * @return unknown + */ +function run_request($table) +{ + global $db; + $cp=isset($_GET["cp"])?trim($_GET["cp"]):''; + + $sql = "SELECT DISTINCT cp, ville, fk_departement, fk_pays, p.code as pays_code, p.libelle as pays_lib"; + $sql.= " FROM ".MAIN_DB_PREFIX.$table; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX.'c_pays as p ON fk_pays = p.rowid'; + $sql.= " WHERE"; + if ($cp) + { + $cp=str_replace('*','%',$cp); + $sql.= " cp LIKE '".addslashes($cp)."' AND"; + $sql.= " (ville IS NOT NULL OR fk_departement IS NOT NULL OR fk_pays IS NOT NULL)"; + } + else $sql.= " cp != '' AND cp IS NOT NULL"; + $sql.= " ORDER by fk_pays, ville, cp"; + $sql.= ' '.$db->plimit(50); // Avoid pb with bad criteria + + //print $sql.'
'; + $result=$db->query($sql); + if (!$result) + { + dol_print_error($db); + exit; + } + + return $result; +} + ?> diff --git a/htdocs/lib/lib_head.js b/htdocs/lib/lib_head.js index 8ea5bf9ba96..9c03f2daa60 100644 --- a/htdocs/lib/lib_head.js +++ b/htdocs/lib/lib_head.js @@ -32,9 +32,9 @@ function barcode_coder_save(formNameID) Licence: GPL ==================================================================*/ -function autofilltownfromzip_PopupPostalCode(postalcode,objecttown,objectcountry,objectstate) +function autofilltownfromzip_PopupPostalCode(url_root, postalcode,objecttown,objectcountry,objectstate) { - var url = 'searchpostalcode.php?cp=' + postalcode; + var url = url_root + '/core/searchpostalcode.php?cp=' + postalcode; url = url + '&targettown=window.opener.document.formsoc.' + objecttown.name; url = url + '&targetcountry=window.opener.document.formsoc.' + objectcountry.name; url = url + '&targetstate=window.opener.document.formsoc.' + objectstate.name; diff --git a/htdocs/soc.php b/htdocs/soc.php index 6f4c0356859..5d2a1c1f7ca 100644 --- a/htdocs/soc.php +++ b/htdocs/soc.php @@ -503,7 +503,7 @@ $_GET["action"] == 'create' || $_POST["action"] == 'create') print ''; print ''.$langs->trans('Zip').''; - if ($conf->use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' '; + if ($conf->use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' '; print ''; print ''.$langs->trans('Town').''; @@ -886,7 +886,7 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit') print ''; print ''.$langs->trans('Zip').''; - if ($conf->use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' '; + if ($conf->use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' '; print ''; print ''.$langs->trans('Town').'';