From 80ca1b4e452e761903acd2a72d9fe21716a1098e Mon Sep 17 00:00:00 2001 From: x2001corpet Date: Fri, 7 Oct 2005 07:19:35 +0000 Subject: [PATCH] reecriture des adresses dans le bon sens selon le pays git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@73 839d8a87-29fc-0310-9880-83ba4fa771e5 --- htdocs/fiche.php | 1 + include/geoloc.inc.php | 38 +++++++++++++++++------- include/profil/get_adresses.inc.php | 8 ++--- include/profil/update_adresses.inc.php | 4 +++ include/user.func.inc.php | 5 ++-- plugins/function.display_address.php | 54 ++++++++++++++++++++++++++++++++++ templates/geoloc/address.tpl | 48 +----------------------------- upgrade/0.9.9/01_adresses.sql | 3 ++ 8 files changed, 96 insertions(+), 65 deletions(-) create mode 100644 plugins/function.display_address.php create mode 100644 upgrade/0.9.9/01_adresses.sql diff --git a/htdocs/fiche.php b/htdocs/fiche.php index 671c2ae..de68402 100644 --- a/htdocs/fiche.php +++ b/htdocs/fiche.php @@ -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'] = ''; } diff --git a/include/geoloc.inc.php b/include/geoloc.inc.php index 73a69ed..d77668a 100644 --- a/include/geoloc.inc.php +++ b/include/geoloc.inc.php @@ -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; diff --git a/include/profil/get_adresses.inc.php b/include/profil/get_adresses.inc.php index c2201a2..74bd2ab 100644 --- a/include/profil/get_adresses.inc.php +++ b/include/profil/get_adresses.inc.php @@ -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'); diff --git a/include/profil/update_adresses.inc.php b/include/profil/update_adresses.inc.php index cf4a150..a055076 100644 --- a/include/profil/update_adresses.inc.php +++ b/include/profil/update_adresses.inc.php @@ -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'], diff --git a/include/user.func.inc.php b/include/user.func.inc.php index 8f4fa6a..5de36d8 100644 --- a/include/user.func.inc.php +++ b/include/user.func.inc.php @@ -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 index 0000000..1ac3801 --- /dev/null +++ b/plugins/function.display_address.php @@ -0,0 +1,54 @@ +".$param['titre']."\n"; + else + $txthtml .= "".$param['titre']."
\n"; + } + foreach ($lines as $line) + { + $txthtml .= "".$line."
\n"; + } + if ($param['adr']['tel']) + $txthtml .= "
\nTél : \n".$param['adr']['tel']."\n
\n"; + if ($param['adr']['fax']) + $txthtml .= "
\nFax : \n".$param['adr']['fax']."\n
\n"; + if ($param['adr']['mobile']) + $txthtml .= "
\nTél : \n".$param['adr']['mobile']."\n
\n"; + if (!$params['nodiv']) + { + $txthtml = "
\n".$txthtml."
\n"; + } + return $txthtml; +} + +?> diff --git a/templates/geoloc/address.tpl b/templates/geoloc/address.tpl index 05145a5..e434797 100644 --- a/templates/geoloc/address.tpl +++ b/templates/geoloc/address.tpl @@ -20,52 +20,6 @@ {* *} {**************************************************************************} - - {if $address.adr1 || $address.countrytxt || $geoloc_address.city || $address.tel || $address.fax || $address.mobile} - {if $no_div neq 1} -
- {/if} - {if $titre && ($address.adr1 || $address.city || $address.countrytxt)} - {if $titre_div} -
- {$titre} -
- {else} - {$titre}
- {/if} - {/if} - {if $address.adr1}{$address.adr1}
{/if} - {if $address.adr2}{$address.adr2}
{/if} - {if $address.adr3}{$address.adr3}
{/if} - {if $address.city}{$address.postcode} {$address.city}
{/if} - {if $address.countrytxt} - {$address.countrytxt}{if $address.region && $address.countrytxt != 'France'} ({$address.region}){/if} - {/if} - - {if $address.tel} -
- Tél : - {$address.tel} -
- {/if} - - {if $address.fax} -
- Fax : - {$address.fax} -
- {/if} - - {if $address.mobile} -
- Mobile : - {$address.mobile} -
- {/if} - - {if $no_div neq 1} -
- {/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 index 0000000..73ac4c6 --- /dev/null +++ b/upgrade/0.9.9/01_adresses.sql @@ -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; + -- 2.1.4