';
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 "