[ Index ]
 

Code source de Dolibarr 2.0.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/htdocs/ -> searchpostalcode.php (source)

   1  <?php
   2  /** **************************************************************************
   3   * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
   4   *
   5   * This program is free software; you can redistribute it and/or modify
   6   * it under the terms of the GNU General Public License as published by
   7   * the Free Software Foundation; either version 2 of the License.
   8   *
   9   * This program is distributed in the hope that it will be useful,
  10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12   * GNU General Public License for more details.
  13   *
  14   * You should have received a copy of the GNU General Public License
  15   * along with this program; if not, write to the Free Software
  16   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17   * ***************************************************************************
  18   * File  : searchpostalcode.php
  19   * Author  : Eric SEIGNE
  20   *           mailto:eric.seigne@ryxeo.com
  21   *           http://www.ryxeo.com/
  22   * Date    : 13/06/2005
  23   * Licence : GNU/GPL Version 2
  24   *
  25   * Description:
  26   * ------------
  27   *
  28   * @version    $Id: searchpostalcode.php,v 1.4 2005/08/20 16:46:35 eldy Exp $
  29   * @source     $Source: /cvsroot/dolibarr/dolibarr/htdocs/searchpostalcode.php,v $
  30   * @revision   $Revision: 1.4 $
  31   * @author     Eric Seigne
  32   * @project   
  33   * @copyright  Eric Seigne 13/06/2005
  34   *
  35   * ************************************************************************* */
  36  
  37  /**
  38          \file       htdocs/searchpostalcode.php
  39          \ingroup    societe
  40          \brief      Recherche de la ville correspondant au code postal saisi. 1er tour on cherche dans la table societé, si on a deux clients dans la même ville c'est direct. Si jamais ça ne donne rien alors on lance la recherche dans la table des codes postaux.
  41          \version    $Revision: 1.4 $
  42  */
  43  
  44  require ("pre.inc.php");
  45  
  46  $user->getrights('societe');
  47  $langs->load("companies");
  48  
  49  
  50  function run_request($table)
  51  {
  52      global $db;
  53      $sql = "SELECT ville,cp from ".MAIN_DB_PREFIX.$table;
  54      if(isset($_GET['cp']) && trim($_GET['cp']) != "") {
  55          $sql .= " where cp ";
  56          if(strstr($_GET['cp'],'%'))
  57          $sql .="LIKE";
  58          else
  59          $sql .="=";
  60          $sql .= " '" . $_GET['cp'] . "'";
  61      }
  62      else {
  63          $sql .= " LIMIT 30";
  64      }
  65      $result=$db->query($sql);
  66      if (!$result) {
  67          dolibarr_print_error($db);
  68      }
  69      //  print $sql;
  70  }
  71  
  72  
  73  // Sécurité accés client
  74  if ($user->societe_id > 0) 
  75  {
  76      $_GET["action"] = '';
  77      $_POST["action"] = '';
  78      $_GET["socid"] = $user->societe_id;
  79  }
  80  
  81  
  82  
  83  top_htmlhead("", $langs->trans("SearchTown"), "");
  84  
  85  
  86  print "
  87  <script language=\"JavaScript\">
  88  <!--
  89  function MAJ(target)
  90  {
  91    var e2 = \"\";
  92    for (var i = 0; i < document.villes.elements.length && e2 == \"\"; i++)
  93    {
  94      var e = document.villes.elements[i];
  95      if (e.checked){
  96        e2 = e.value;
  97        target.value = unescape(e2);
  98      }
  99    }
 100    window.close();
 101  }
 102  
 103  function change_categorie(urlbase,leselect)
 104  {
 105    if (leselect.options[leselect.selectedIndex].value!=\"dummy\")
 106    eval(\"location='\"+urlbase+\"?c=\"+leselect.options[leselect.selectedIndex].value+\"&objet=$objet'\");
 107  }
 108  //-->
 109  </script>\n";
 110  
 111  print "<body>";
 112  
 113  print "<div><div><div><br>";    // Ouvre 3 div a la place de top_menu car le llxFooter en ferme 3
 114  
 115  print "<form method=\"post\" action=\"javascript:MAJ(" . $_GET['targetobject'] . ");\" name=\"villes\" enctype=\"application/x-www-form-urlencoded\">";
 116  print "<table class=\"noborder\" align=\"center\" width=\"90%\">";
 117  print "<tr class=\"liste_titre\">";
 118  print "  <td colspan=\"3\" align=\"center\">";
 119  print "  <b>Recherche code postal: " . $_GET['cp'] . " </b>";
 120  print "  </td>";
 121  print "</tr>\n";
 122  
 123  run_request("societe");
 124  
 125  $num=$db->num_rows();
 126  if($num == 0) {
 127    run_request("postalcode");
 128    $num=$db->num_rows();
 129  }
 130  
 131  // Si on n'a qu'un seul résultat on switche direct et on remplit le formulaire
 132  if($num <= 1) {
 133    $obj = $db->fetch_object($result);
 134    $ville = $obj->ville;
 135    $ville_code = urlencode("$ville");  
 136    print "<input type=\"radio\" name=\"choix\" value=\"$ville\" checked>
 137  <script language=\"javascript\">
 138  document.villes.submit();
 139  </script>\n";
 140  }
 141  else {
 142      // Sinon on affiche la liste des villes dont c'est le code postal ...
 143      for($i = 0; $i < $num; $i++)
 144      {
 145          $obj = $db->fetch_object($result);
 146          $ville = $obj->ville;
 147          $ville_code = urlencode("$ville");
 148          if(strstr($_GET['cp'],'%') || trim($_GET['cp'])=="")
 149          $cp = "(" . $obj->postalcode . ")";
 150          else
 151          $cp = "";
 152  
 153          if($bgcolor=="#DDDDFF")
 154          $bgcolor="#EEEEFF";
 155          else
 156          $bgcolor="#DDDDFF";
 157  
 158          $var=!$var;
 159          print "<tr ".$bc[$var]."><td width=\"10%\">";
 160          print "<label><input type=\"radio\" name=\"choix\" value=\"$ville\"> $ville $cp</label>";
 161          print "</td></tr>";
 162      }
 163  }
 164  
 165  
 166  print "    <input type=\"hidden\" name=\"nb_i\" value=\"$i\">";
 167  
 168  $var=!$var;
 169  print "<tr><td align=\"center\" colspan=\"3\">";
 170  print "<input type=\"submit\" class=\"button\" name=\"envoyer\" value=\"".$langs->trans("Modify")."\">";
 171  print " &nbsp; ";
 172  print "<input type=\"button\" class=\"button\" value=\"".$langs->trans("Cancel")."\" onClick=\"window.close();\">";
 173  print "</td></tr>";
 174  
 175  print "</table></form>\n";
 176  print "<br>";
 177  
 178  $db->close();
 179  
 180  llxFooter('$Date: 2005/08/20 16:46:35 $ - $Revision: 1.4 $');
 181  ?>


Généré le : Mon Nov 26 12:29:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics