6a632ad8ea5fd96e7ab6bb1918b18c3972153c51
[platal.git] / plugins / function.display_address.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2008 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22 function display_address_isIdentity($idt, $value, $test_reverse = true)
23 {
24 $value = strtolower(replace_accent($value));
25 $idt = strtolower(replace_accent($idt));
26 $idt = preg_replace('/[^a-z]/', '', $idt);
27
28 $value = preg_replace('/[^a-z]/', '', $value);
29 if (strpos($value, $idt) !== false || strpos($idt, $value) !== false || levenshtein($value, $idt) < strlen($idt) / 3) {
30 return true;
31 }
32
33 if ($test_reverse) {
34 return display_address_isIdentity($idt, implode(' ', array_reverse(explode(' ', $value))), false);
35 }
36 return false;
37 }
38
39 function smarty_function_display_address($param, &$smarty)
40 {
41 require_once('geoloc.inc.php');
42 $txtad = get_address_text($param['adr']);
43 if (!$txtad &&
44 !$param['adr']['tels'] && !count($param['adr']['tels']) &&
45 !$param['adr']['tel'] &&
46 !$param['adr']['fax'] &&
47 !$param['adr']['mobile']) return "";
48
49 $lines = explode("\n", $txtad);
50 $idt = array_shift($lines);
51 $restore = true;
52
53 if (!display_address_isIdentity($param['for'], $idt)) {
54 array_unshift($lines, $idt);
55 $idt = $param['for'];
56 $restore = false;
57 }
58
59 $txthtml = "";
60 $map = "<a href=\"http://maps.google.fr/?q="
61 . urlencode(implode(", ", $lines) . " ($idt)")
62 . "\"><img src=\"images/icons/map.gif\" alt=\"Google Maps\" title=\"Carte\"/></a>";
63 $comment = "";
64 if ($param['adr']['comment'] != "")
65 {
66 $commentHtml = str_replace(array('&', '"'), array('&amp;', '&quot;'), $param['adr']['comment']);
67 $commentJs = str_replace(array('\\', '\''), array('\\\\', '\\\''), $commentHtml);
68 $comment = "<img style=\"margin-left: 5px;\" src=\"images/icons/comments.gif\""
69 . " onmouseover=\"return overlib('"
70 . $commentJs
71 . "',WIDTH,250);\""
72 . " onmouseout=\"nd();\""
73 . " alt=\"Commentaire\" title=\""
74 . $commentHtml
75 . "\"/>";
76 }
77 if ($restore) {
78 array_unshift($lines, $idt);
79 }
80 if ($param['titre'])
81 {
82 if ($param['titre_div'])
83 $txthtml .= "<div class='titre'>".pl_entity_decode($param['titre'])."&nbsp;".$map.$comment."</div>\n";
84 else
85 $txthtml .= "<em>".pl_entity_decode($param['titre'])."&nbsp;</em>".$map.$comment."<br />\n";
86 }
87 foreach ($lines as $line)
88 {
89 $txthtml .= "<strong>".$line."</strong><br/>\n";
90 }
91 if ($param['adr']['tel'])
92 $txthtml .= "<div>\n<em>Tél : </em>\n<strong>".$param['adr']['tel']."</strong>\n</div>\n";
93 if ($param['adr']['fax'])
94 $txthtml .= "<div>\n<em>Fax : </em>\n<strong>".$param['adr']['fax']."</strong>\n</div>\n";
95 if ($param['adr']['mobile'])
96 $txthtml .= "<div>\n<em>Mob : </em>\n<strong>".$param['adr']['mobile']."</strong>\n</div>\n";
97 if ($param['adr']['tels'] && count($param['adr']['tels'])) {
98 foreach ($param['adr']['tels'] as $tel) {
99 switch ($tel['tel_type']) {
100 case 'fixed':
101 $tel_type = 'Tél';
102 break;
103 case 'fax':
104 $tel_type = 'Fax';
105 break;
106 case 'mobile':
107 $tel_type = 'Mob';
108 break;
109 default:
110 $tel_type = $tel['tel_type'];
111 }
112 $txthtml .= "<div>\n<em>" . $tel_type . "&nbsp;: </em>\n<strong>" . $tel['tel'] . "</strong>\n</div>\n";
113 }
114 }
115 if (!$param['nodiv']) {
116 $pos = $param['pos'] ? " style='float: " . $param['pos'] . "'" : '';
117 $txthtml = "<div class='adresse' $pos>\n".$txthtml."</div>\n";
118 }
119 return $txthtml;
120 }
121
122 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
123 ?>