Better fix for GoogleMaps
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 27 May 2007 15:44:22 +0000 (15:44 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 27 May 2007 15:44:22 +0000 (15:44 +0000)
 plugins/function.display_address.php |   30 ++++++++++++++++++++++++++++--
 templates/admin/synchro_ax.tpl       |    4 ++--
 templates/geoloc/address.tpl         |    2 +-
 templates/profile/fiche_referent.tpl |    2 +-
 templates/profile/profile.tpl        |   11 +++++++----
 5 files changed, 39 insertions(+), 10 deletions(-)

git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1841 839d8a87-29fc-0310-9880-83ba4fa771e5

plugins/function.display_address.php
templates/admin/synchro_ax.tpl
templates/geoloc/address.tpl
templates/profile/fiche_referent.tpl
templates/profile/profile.tpl

index fe5d355..81fbebe 100644 (file)
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
+function display_address_isIdentity($idt, $value, $test_reverse = true)
+{
+    $value = strtolower(replace_accent($value));
+    $idt   = strtolower(replace_accent($idt));
+    $idt   = preg_replace('/[^a-z]/', '', $idt);
+
+    $value = preg_replace('/[^a-z]/', '', $value);
+    if (strpos($value, $idt) !== false || strpos($idt, $value) !== false || levenshtein($value, $idt) < strlen($idt) / 3) {
+        return true;
+    }
+
+    if ($test_reverse) { 
+        return display_address_isIdentity($idt, implode(' ', array_reverse(explode(' ', $value))), false); 
+    }
+    return false;
+}
 
 function smarty_function_display_address($param, &$smarty)
 {
@@ -30,14 +46,24 @@ function smarty_function_display_address($param, &$smarty)
         !$param['adr']['fax'] &&
         !$param['adr']['mobile']) return "";
 
+
     $lines = explode("\n", $txtad);
-    $idt   = array_shift($lines); 
+    $idt   = array_shift($lines);
+    $restore = true;
+
+    if (!display_address_isIdentity($param['for'], $idt)) {
+        array_unshift($lines, $idt);
+        $idt = $param['for'];
+        $restore = false;
+    }
 
     $txthtml = "";
     $map = "<a href=\"http://maps.google.fr/?q="
          .   urlencode(str_replace('États-Unis d\'Amérique', 'USA', implode(", ", $lines) . " ($idt)"))
          . "\"><img src=\"images/icons/map.gif\" alt=\"Google Maps\" title=\"Carte\"/></a>";
-    array_unshift($lines, $idt);
+    if ($restore) {
+        array_unshift($lines, $idt);
+    }
     if ($param['titre'])
     {
         if ($param['titre_div'])
index 5427b02..c8adc6e 100644 (file)
@@ -90,7 +90,7 @@ Adresses
     Effacer l'adresse {$adr.adrid}.
 {else}
     {if $adr.adrid}Modifier l'adresse {$adr.adrid} :{else}Ajouter l'adresse :{/if}
-  {include file='geoloc/address.tpl' address=$adr no_div=1}
+  {include file='geoloc/address.tpl' address=$adr no_div=1 for="`$x.prenom` `$x.nom`"}
 {/if}
 </td></tr>
 {/foreach}
@@ -127,7 +127,7 @@ Emplois
       <em>Poste : </em> <strong>{$pro.poste}</strong>
     </div>
     {/if}
-  {include file='geoloc/address.tpl' address=$pro no_div=1}
+  {include file='geoloc/address.tpl' address=$pro no_div=1 for=$pro.entreprise}
 {/if}
 </td></tr>
 {/foreach}
index 0867a52..0bfef79 100644 (file)
@@ -20,6 +20,6 @@
 {*                                                                        *}
 {**************************************************************************}
 
-{display_address adr=$address titre=$titre titre_div=$titre_div no_div=$no_div}
+{display_address adr=$address titre=$titre titre_div=$titre_div no_div=$no_div for=$for}
 
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
index c5bd2c6..f05f71d 100644 (file)
@@ -66,7 +66,7 @@
   {foreach from=$adr_pro item="address" key="i"}
   <h2>{$address.entreprise}</h2>
   {include file="include/emploi.tpl" address=$address}
-  {include file="geoloc/address.tpl" address=$address titre="Adresse : "}
+  {include file="geoloc/address.tpl" address=$address titre="Adresse : " for=$address.entreprise}
   
   <div class="spacer">&nbsp;</div>
   {/foreach}
index 09dd97d..6f049b1 100644 (file)
@@ -132,11 +132,14 @@ function chgMainWinLoc(strPage)
       <h2>Contact : </h2>
       {foreach from=$x.adr item="address" key="i"}
         {if $address.active}
-        {include file="geoloc/address.tpl" address=$address titre_div=true titre="Mon adresse actuelle :"}
+        {include file="geoloc/address.tpl" address=$address titre_div=true titre="Mon adresse actuelle :"
+                 for="`$x.prenom` `$x.nom`"}
         {elseif $address.secondaire}
-        {include file="geoloc/address.tpl" address=$address titre_div=true titre="Adresse secondaire :"}
+        {include file="geoloc/address.tpl" address=$address titre_div=true titre="Adresse secondaire :"
+                 for="`$x.prenom` `$x.nom`"}
         {else}
-        {include file="geoloc/address.tpl" address=$address titre_div=true titre="Adresse principale :"}
+        {include file="geoloc/address.tpl" address=$address titre_div=true titre="Adresse principale :"
+                 for="`$x.prenom` `$x.nom`"}
         {/if}
       {/foreach}
       <div class="spacer">&nbsp;</div>
@@ -149,7 +152,7 @@ function chgMainWinLoc(strPage)
       <h2>Informations professionnelles :</h2>
       {foreach from=$x.adr_pro item="address" key="i"}
       {include file="include/emploi.tpl" address=$address}
-      {include file="geoloc/address.tpl" address=$address titre="Adresse : "}
+      {include file="geoloc/address.tpl" address=$address titre="Adresse : " for=$address.entreprise}
       <div class="spacer">&nbsp;</div>
       {/foreach}
     </td>