reecriture des adresses dans le bon sens selon le pays
authorx2001corpet <x2001corpet@839d8a87-29fc-0310-9880-83ba4fa771e5>
Fri, 7 Oct 2005 07:19:35 +0000 (07:19 +0000)
committerx2001corpet <x2001corpet@839d8a87-29fc-0310-9880-83ba4fa771e5>
Fri, 7 Oct 2005 07:19:35 +0000 (07:19 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@73 839d8a87-29fc-0310-9880-83ba4fa771e5

htdocs/fiche.php
include/geoloc.inc.php
include/profil/get_adresses.inc.php
include/profil/update_adresses.inc.php
include/user.func.inc.php
plugins/function.display_address.php [new file with mode: 0644]
templates/geoloc/address.tpl
upgrade/0.9.9/01_adresses.sql [new file with mode: 0644]

index 671c2ae..de68402 100644 (file)
@@ -92,6 +92,7 @@ if (!logged() || Env::has('public')) {
             $user['adr'][$i]['city'] = '';
             $user['adr'][$i]['postcode'] = '';
             $user['adr'][$i]['region'] = '';
+            $user['adr'][$i]['regiontxt'] = '';
             $user['adr'][$i]['country'] = '00';
             $user['adr'][$i]['countrytxt'] = '';
         }
index 73a69ed..d77668a 100644 (file)
@@ -40,7 +40,7 @@ function _geoloc_country_smarty($params){
     return;
   return geoloc_country($params['country']);
 }
-$page->register_function('geoloc_country', '_geoloc_country_smarty');
+$GLOBALS['page']->register_function('geoloc_country', '_geoloc_country_smarty');
 
 /** donne la liste deroulante des regions pour un pays
  * @param $pays le pays dont on veut afficher les regions
@@ -64,7 +64,7 @@ function _geoloc_region_smarty($params){
     return;
   return geoloc_region($params['country'], $params['region']);
 }
-$page->register_function('geoloc_region', '_geoloc_region_smarty');
+$GLOBALS['page']->register_function('geoloc_region', '_geoloc_region_smarty');
 // }}}
 
 // {{{ get_address_infos($txt)
@@ -82,6 +82,8 @@ function get_address_infos($txt) {
     global $globals;
     if ($infos['sql'])
        $globals->xdb->execute("REPLACE INTO geoloc_city VALUES ".$infos['sql']);
+    if ($infos['display'])
+       $globals->xdb->execute("UPDATE geoloc_pays SET display = {?} WHERE a2 = {?}", $infos['display'], $infos['country']);
     return $infos;
 }
 // }}}
@@ -96,13 +98,26 @@ function get_address_text($adr) {
     if ($adr['adr2']) $t.= "\n".$adr['adr2'];
     if ($adr['adr3']) $t.= "\n".$adr['adr3'];
     $l = "";
-    if ($adr['country'] == 'US' || $adr['country'] == 'CA') {
-        if ($adr['city']) $l .= $adr['city'].",\n";
-        if ($adr['region']) $l .= $adr['region']." ";
-        if ($adr['postcode']) $l .= $adr['postcode'];
-    } else {
-        if ($adr['postcode']) $l .= $adr['postcode']." ";
-        if ($adr['city']) $l .= $adr['city'];
+    if ($adr['display']) {
+        $keys = explode(' ', $adr['display']);
+        foreach ($keys as $key) {
+            if (isset($adr[$key]))
+                $l .= " ".$adr[$key];
+            else
+                $l .= " ".$key;
+        }
+        if ($l) $l = substr($l, 1);
+    }
+    else
+    {
+        if ($adr['country'] == 'US' || $adr['country'] == 'CA' || $adr['country'] == 'GB') {
+            if ($adr['city']) $l .= $adr['city'].",\n";
+            if ($adr['region']) $l .= $adr['region']." ";
+            if ($adr['postcode']) $l .= $adr['postcode'];
+        } else {
+            if ($adr['postcode']) $l .= $adr['postcode']." ";
+            if ($adr['city']) $l .= $adr['city'];
+        }
     }
     if ($l) $t .= "\n".trim($l);
     if ($adr['country'] != '00' && (!$adr['countrytxt'] || $adr['countrytxt'] == strtoupper($adr['countrytxt']))) {
@@ -143,6 +158,7 @@ function empty_address() {
         "city" => "",
         "postcode" => "",
         "region" => "",
+        "regiontxt" => "",
         "country" => "00",
         "countrytxt" => "");
 }
@@ -170,11 +186,11 @@ function localize_addresses($uid) {
             $globals->xdb->execute("UPDATE adresses SET
                 adr1 = {?}, adr2 = {?}, adr3 = {?},
                 cityid = {?}, city = {?}, postcode = {?},
-                region = {?}, country = {?}
+                region = {?}, regiontxt = {?}, country = {?}
                 WHERE uid = {?} AND adrid = {?}",
                 $new['adr1'], $new['adr2'], $new['adr3'],
                 $new['cityid'], $new['city'], $new['postcode'],
-                $new['region'], $new['country'],
+                $new['region'], $new['regiontxt'], $new['country'],
                 $uid, $a['adrid']);
                 $new['store'] = true;
                 if (!$new['cityid']) $erreur[$a['adrid']] = $new;
index c2201a2..74bd2ab 100644 (file)
@@ -67,8 +67,8 @@ $res = $globals->xdb->iterRow(
        FIND_IN_SET('res-secondaire', statut), FIND_IN_SET('courrier', statut),
        FIND_IN_SET('active', statut), FIND_IN_SET('temporaire', statut),
        adr1, adr2, adr3, postcode, city, cityid,
-        a.country, region, tel, fax, pub, tel_pub,
-       gp.pays AS countrytxt
+        a.country, region, regiontxt, tel, fax, pub, tel_pub,
+       gp.pays AS countrytxt, gp.display
        FROM adresses AS a INNER JOIN geoloc_pays AS gp ON(gp.a2 = a.country)
        WHERE uid = {?} AND NOT FIND_IN_SET('pro',statut) ".$sql_order
 , Session::getInt('uid', -1)
@@ -83,9 +83,9 @@ for ($i = 0; $i < $nb_adr; $i++) {
        $adresses[$adrid]['secondaire'], $adresses[$adrid]['courrier'],
        $adresses[$adrid]['active'], $adresses[$adrid]['temporaire'],
        $adresses[$adrid]['adr1'], $adresses[$adrid]['adr2'], $adresses[$adrid]['adr3'], $adresses[$adrid]['postcode'], $adresses[$adrid]['city'], $adresses[$adrid]['cityid'],
-       $adresses[$adrid]['country'], $adresses[$adrid]['region'], $adresses[$adrid]['tel'], $adresses[$adrid]['fax'],
+       $adresses[$adrid]['country'], $adresses[$adrid]['region'], $adresses[$adrid]['regiontxt'], $adresses[$adrid]['tel'], $adresses[$adrid]['fax'],
        $adresses[$adrid]['pub'],
-       $adresses[$adrid]['tel_pub'],$adresses[$adrid]['countrytxt']) = $res->next();
+       $adresses[$adrid]['tel_pub'],$adresses[$adrid]['countrytxt'],$adresses[$adrid]['display']) = $res->next();
   $adresses[$adrid]['nouvelle'] = 'modif';
   $adresses[$adrid]['numero_formulaire'] = -1;
   require_once('geoloc.inc.php');
index cf4a150..a055076 100644 (file)
@@ -45,6 +45,7 @@ foreach($adresses as $adrid => $adr){
                         cityid = {?},
                         country = {?},
                         region = {?},
+                        regiontxt = {?},
                         tel = {?},
                         fax = {?},
                         pub = {?},
@@ -60,6 +61,7 @@ foreach($adresses as $adrid => $adr){
                         $adr['cityid'],
                         $adr['country'],
                         $adr['region'],
+                        $adr['regiontxt'],
                         $adr['tel'],
                         $adr['fax'],
                         $adr['pub'],
@@ -80,6 +82,7 @@ foreach($adresses as $adrid => $adr){
                                 cityid = {?},
                                 country = {?},
                                 region = {?},
+                                regiontxt = {?},
                                 tel = {?},
                                 fax = {?},
                                 pub = {?},
@@ -95,6 +98,7 @@ foreach($adresses as $adrid => $adr){
                                 $adr['cityid'],
                                 $adr['country'],
                                 $adr['region'],
+                                $adr['regiontxt'],
                                 $adr['tel'],
                                 $adr['fax'],
                                 $adr['pub'],
index 8f4fa6a..5de36d8 100644 (file)
@@ -205,13 +205,12 @@ function &get_user_details($login, $from_uid = '')
     $user['adr_pro'] = get_user_details_pro($uid);
 
     $sql  = "SELECT  a.adr1,a.adr2,a.adr3,a.postcode,a.city,
-                     gp.pays AS countrytxt,gr.name AS region,a.tel,a.fax,
+                     gp.pays AS countrytxt,a.region, a.regiontxt, a.tel,a.fax,
                      FIND_IN_SET('active', a.statut) AS active, a.adrid,
                      FIND_IN_SET('res-secondaire', a.statut) AS secondaire,
-                     a.pub, a.tel_pub
+                     a.pub, a.tel_pub, gp.display
                FROM  adresses AS a
           LEFT JOIN  geoloc_pays AS gp ON (gp.a2=a.country)
-          LEFT JOIN  geoloc_region AS gr ON (gr.a2=a.country and gr.region=a.region)
               WHERE  uid= {?} AND NOT FIND_IN_SET('pro',a.statut)
            ORDER BY  NOT FIND_IN_SET('active',a.statut), FIND_IN_SET('temporaire',a.statut), FIND_IN_SET('res-secondaire',a.statut)";
     $res  = $globals->xdb->query($sql, $uid);
diff --git a/plugins/function.display_address.php b/plugins/function.display_address.php
new file mode 100644 (file)
index 0000000..1ac3801
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2004 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  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                *
+ ***************************************************************************/
+
+
+function smarty_function_display_address($param, &$smarty) {
+    require_once('geoloc.inc.php');
+    $txtad = get_address_text($param['adr']);
+    if (!$txtad && !$param['adr']['tel'] && !$param['adr']['fax'] && !$param['adr']['mobile']) return "";
+
+    $lines = explode("\n",$txtad);
+    $txthtml = "";
+    if ($param['titre'])
+    {
+       if ($param['titre_div'])
+          $txthtml .= "<div class='titre'>".$param['titre']."</div>\n";
+       else
+           $txthtml .= "<em>".$param['titre']."</em><br />\n";
+    }
+    foreach ($lines as $line)
+    {
+       $txthtml .= "<strong>".$line."</strong><br/>\n";
+    }
+    if ($param['adr']['tel'])
+       $txthtml .= "<div>\n<em>Tél : </em>\n<strong>".$param['adr']['tel']."</strong>\n</div>\n";
+    if ($param['adr']['fax'])
+       $txthtml .= "<div>\n<em>Fax : </em>\n<strong>".$param['adr']['fax']."</strong>\n</div>\n";
+    if ($param['adr']['mobile'])
+       $txthtml .= "<div>\n<em>Tél : </em>\n<strong>".$param['adr']['mobile']."</strong>\n</div>\n";
+    if (!$params['nodiv'])
+    {
+       $txthtml = "<div class='adresse'>\n".$txthtml."</div>\n";
+    }
+    return $txthtml;
+}
+
+?>
index 05145a5..e434797 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
-
-      {if $address.adr1 || $address.countrytxt || $geoloc_address.city || $address.tel || $address.fax || $address.mobile}
-      {if $no_div neq 1}
-      <div class="adresse">
-      {/if}
-        {if $titre && ($address.adr1 || $address.city || $address.countrytxt)}
-          {if $titre_div}
-            <div class="titre">
-              {$titre}
-            </div>
-          {else}
-            <em>{$titre}</em><br />
-          {/if}
-        {/if}
-        {if $address.adr1}<strong>{$address.adr1}</strong><br />{/if}
-        {if $address.adr2}<strong>{$address.adr2}</strong><br />{/if}
-        {if $address.adr3}<strong>{$address.adr3}</strong><br />{/if}
-        {if $address.city}<strong>{$address.postcode} {$address.city}</strong><br />{/if}
-        {if $address.countrytxt}
-        <strong>{$address.countrytxt}{if $address.region && $address.countrytxt != 'France'} ({$address.region}){/if}</strong>
-        {/if}
-        
-        {if $address.tel}
-        <div>
-          <em>Tél : </em>
-          <strong>{$address.tel}</strong>
-        </div>
-        {/if}
-
-        {if $address.fax}
-        <div>
-          <em>Fax : </em>
-          <strong>{$address.fax}</strong>
-        </div>
-        {/if}
-        
-        {if $address.mobile}
-        <div>
-          <em>Mobile : </em>
-          <strong>{$address.mobile}</strong>
-        </div>
-        {/if}
-
-      {if $no_div neq 1}
-      </div>
-      {/if}
-      {/if}
+{display_address adr=$address titre=$titre titre_div=$titre_div no_div=$no_div}
 
 {* vim:set et sw=2 sts=2 sws=2: *}
diff --git a/upgrade/0.9.9/01_adresses.sql b/upgrade/0.9.9/01_adresses.sql
new file mode 100644 (file)
index 0000000..73ac4c6
--- /dev/null
@@ -0,0 +1,3 @@
+ALTER TABLE adresses ADD regiontxt VARCHAR(80) NOT NULL AFTER region;
+ALTER TABLE geoloc_pays ADD display VARCHAR(50) NOT NULL;
+