diff --git a/htdocs/comm/adresse_livraison.php b/htdocs/comm/adresse_livraison.php index 06c178bafff..a5e46dcaf6d 100644 --- a/htdocs/comm/adresse_livraison.php +++ b/htdocs/comm/adresse_livraison.php @@ -230,14 +230,12 @@ if ($_GET["action"] == 'create' || $_POST["action"] == 'create') print ''.$langs->trans('DeliveryAddressLabel').''; print ''.$langs->trans('Name').''; - print ''.$langs->trans('Address').''; - print ''.$langs->trans('Zip').'use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' onChange="autofilltownfromzip_PopupPostalCode(cp.value,ville)"'; - print '>'; - if ($conf->use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' '; + print ''.$langs->trans('Zip').''; + if ($conf->use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' '; print ''; print ''.$langs->trans('Town').''; @@ -273,7 +271,7 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit') $head = societe_prepare_head($societe); dol_fiche_head($head, 'customer', $societe->nom); - + print_titre($langs->trans("EditDeliveryAddress")); print "
\n"; @@ -340,10 +338,8 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit') print $livraison->adresse; print ''; - print ''.$langs->trans('Zip').'use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' onChange="autofilltownfromzip_PopupPostalCode(cp.value,ville)"'; - print '>'; - if ($conf->use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' '; + print ''.$langs->trans('Zip').''; + if ($conf->use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' '; print ''; print ''.$langs->trans('Town').''; diff --git a/htdocs/lib/lib_head.js b/htdocs/lib/lib_head.js index 1b64ef4badf..1e768d142b8 100644 --- a/htdocs/lib/lib_head.js +++ b/htdocs/lib/lib_head.js @@ -25,14 +25,17 @@ function barcode_coder_save(formNameID) /*================================================================= Purpose: Pour la fonction de saisie auto des villes - Input: postalcode,objectville + Input: postalcode,objecttown,objectcountry,objectstate Author: Eric Seigne Licence: GPL ==================================================================*/ -function autofilltownfromzip_PopupPostalCode(postalcode,objectville) +function autofilltownfromzip_PopupPostalCode(postalcode,objecttown,objectcountry,objectstate) { - var url = 'searchpostalcode.php?cp=' + postalcode + '&targetobject=window.opener.document.formsoc.' + objectville.name; + var url = '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; // alert(url); var hWnd = window.open(url, "SearchPostalCodeWindow", "width=" + 300 + ",height=" + 150 + ",resizable=yes,scrollbars=yes"); if((document.window != null) && (!hWnd.opener)) hWnd.opener = document.window; diff --git a/htdocs/searchpostalcode.php b/htdocs/searchpostalcode.php index ee115fe92a8..3e621559ed3 100644 --- a/htdocs/searchpostalcode.php +++ b/htdocs/searchpostalcode.php @@ -1,6 +1,6 @@ - * Copyright (C) 2006 Laurent Destailleur +/* Copyright (C) 2005 Eric Seigne + * Copyright (C) 2006-2009 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 @@ -26,20 +26,17 @@ * * Description: * ------------ - * @version $Id$ - * @revision $Id$ * @author Eric Seigne - * @project * @copyright Eric Seigne 13/06/2005 * * ************************************************************************* */ /** - \file htdocs/searchpostalcode.php - \ingroup societe - \brief Recherche de la ville correspondant au code postal saisi. 1er tour on cherche dans la table societe, si on a deux clients dans la meme ville c'est direct. Si jamais la recherche ne donne rien alors on lance la recherche dans la table des codes postaux. - \version $Revision$ -*/ + * \file htdocs/searchpostalcode.php + * \ingroup societe + * \brief Recherche de la ville correspondant au code postal saisi. 1er tour on cherche dans la table societe, si on a deux clients dans la meme ville c'est direct. Si jamais la recherche ne donne rien alors on lance la recherche dans la table des codes postaux. + * \version $Id$ + */ require("pre.inc.php"); $langs->load("companies"); @@ -49,24 +46,33 @@ function run_request($table) { global $db; $cp=isset($_GET["cp"])?trim($_GET["cp"]):''; - $cp=eregi_replace('\*','%',$cp); - - $sql = "SELECT DISTINCT ville, cp"; - $sql.= " FROM ".MAIN_DB_PREFIX.$table; - $sql.= " WHERE cp ".($cp?"LIKE":"=")." '".addslashes($cp)."'"; - $sql.= " ORDER by ville"; - $result=$db->query($sql); + $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=eregi_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); } - //print $sql.'
'; + return $result; } // Securite acces client -if ($user->societe_id > 0) +if ($user->societe_id > 0) { $_GET["action"] = ''; $_POST["action"] = ''; @@ -74,99 +80,106 @@ if ($user->societe_id > 0) } +/* + * View + */ -top_htmlhead("", $langs->trans("SearchTown")); - -print ""; - -print " +$javascript=" \n"; +top_htmlhead("", $langs->trans("SearchTown")); -print "

"; // Ouvre 3 div a la place de top_menu car le llxFooter en ferme 3 +// Same as llxHeader. Open what llxFooter close +print ''; +print $javascript; -print "
"; +print '
'; +print "

"; // Ouvre div a la place de top_menu car le llxFooter en ferme un + +print ""; print ''; -print ""; +print "
"; print ""; print " "; print "\n"; +$num=0; + $result = run_request("societe"); - -$num=$db->num_rows($result); -if($num == 0) +if ($result) { - $result = run_request("postalcode"); $num=$db->num_rows($result); + //print 'sql='.$sql.' num='.$num; exit; + if($num == 0) + { + $result = run_request("postalcode"); + $num=$db->num_rows($result); + } + + // Si on n'a pas ou un seul resultat on switche direct et on remplit le formulaire + if($num <= 1) + { + $obj = $db->fetch_object($result); + $ville = $obj->ville; + $ville_code = urlencode("$ville"); + print ""; + } + else + { + // Sinon on affiche la liste des villes dont c'est le code postal ... + for ($i = 0; $i < $num; $i++) + { + $obj = $db->fetch_object($result); + + $cp = $obj->cp; + $ville = $obj->ville; + + $dep = $obj->fk_departement; + $dep_lib = $obj->fk_departement; + + $country_code = $obj->pays_code; + $temp=$obj->pays_code?$langs->transcountry("Country",$obj->pays_code):''; + if ($temp == 'Country') $temp=$obj->pays_lib; + $country_lib = $temp; + + $var=!$var; + print ""; + print ''; + print "'; + print ''; + print ""; + } + } } -// Si on n'a qu'un seul resultat on switche direct et on remplit le formulaire -if($num <= 1) -{ - $obj = $db->fetch_object($result); - $ville = $obj->ville; - $ville_code = urlencode("$ville"); - print ""; -} -else -{ - // Sinon on affiche la liste des villes dont c'est le code postal ... - for ($i = 0; $i < $num; $i++) - { - $obj = $db->fetch_object($result); - $ville = $obj->ville; - $ville_code = urlencode("$ville"); - if ($obj->cp) - $cp = "(" . $obj->cp . ")"; - else - $cp = ""; - - if($bgcolor=="#DDDDFF") - $bgcolor="#EEEEFF"; - else - $bgcolor="#DDDDFF"; - - $var=!$var; - print ""; - } -} - - $var=!$var; print ""; diff --git a/htdocs/soc.php b/htdocs/soc.php index 2ef282f2814..355746e48cd 100644 --- a/htdocs/soc.php +++ b/htdocs/soc.php @@ -461,14 +461,12 @@ $_GET["action"] == 'create' || $_POST["action"] == 'create') print ''; } - print ''; - print ''; print ''; @@ -820,10 +818,8 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit') print $soc->adresse; print ''; - print ''; print ''; diff --git a/htdocs/translate.class.php b/htdocs/translate.class.php index 5b6b3473956..189d193bf67 100644 --- a/htdocs/translate.class.php +++ b/htdocs/translate.class.php @@ -444,10 +444,10 @@ class Translate { /** - * \brief Retourne la version traduite du texte passe en parametre complete du code pays - * \param str chaine a traduire - * \param countrycode code pays (FR, ...) - * \return string chaine traduite + * \brief Return translation of a key depending on country + * \param str string root to translate + * \param countrycode country code (FR, ...) + * \return string translated string */ function transcountry($str, $countrycode) { @@ -458,9 +458,9 @@ class Translate { /** * \brief Retourne la version traduite du texte passe en parametre complete du code pays - * \param str chaine a traduire - * \param countrycode code pays (FR, ...) - * \return string chaine traduite + * \param str string root to translate + * \param countrycode country code (FR, ...) + * \return string translated string */ function transcountrynoentities($str, $countrycode) {
"; print " Recherche code postal: " . $_GET['cp'] . " "; print "
"; + print ''; + print "\n"; + print "
'.$country_lib.'"; + print ''.$cp.''.$ville.'
"; - print ""; - print "\n"; - print "
"; - print ' '.$ville.' '.$cp; - print "
"; -print ""; -print "trans("Modify")."\">"; +print "
"; +print "trans("Select")."\">"; print "   "; print "trans("Cancel")."\" onClick=\"window.close();\">"; print "
'.$langs->trans('Address').'
'.$langs->trans('Zip').'use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' onChange="autofilltownfromzip_PopupPostalCode(cp.value,ville)"'; - print '>'; - if ($conf->use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' '; + print '
'.$langs->trans('Zip').''; + if ($conf->use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' '; print ''.$langs->trans('Town').'
'.$langs->trans('Zip').'use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' onChange="autofilltownfromzip_PopupPostalCode(cp.value,ville)"'; - print '>'; - if ($conf->use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' '; + print '
'.$langs->trans('Zip').''; + if ($conf->use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' '; print ''.$langs->trans('Town').'