* 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * *************************************************************************** * File : searchpostalcode.php * Author : Eric SEIGNE * mailto:eric.seigne@ryxeo.com * http://www.ryxeo.com/ * Date : 13/06/2005 * Licence : GNU/GPL Version 2 * * Description: * ------------ * @author Eric Seigne * @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 $Id$ */ 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; } // Securite acces client if ($user->societe_id > 0) { $_GET["action"] = ''; $_POST["action"] = ''; $_GET["socid"] = $user->societe_id; } /* * View */ $javascript=" \n"; top_htmlhead("", $langs->trans("SearchTown")); // Same as llxHeader. Open what llxFooter close print ''; print $javascript; print '
'; print "

"; // Ouvre div a la place de top_menu car le llxFooter en ferme un print "
"; print ''; print ""; print ""; print " "; print "\n"; $num=0; $result = run_request("societe"); if ($result) { $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 ""; } } } $var=!$var; print ""; print "
"; print " Recherche code postal: " . $_GET['cp'] . " "; print "
"; print ''; print "\n"; print "
'.$country_lib.'"; print ''.$cp.''.$ville.'
"; print "
"; print "trans("Select")."\">"; print "   "; print "trans("Cancel")."\" onClick=\"window.close();\">"; print "

\n"; $db->close(); llxFooter('$Date$ - $Revision$',0); ?>