Commit | Line | Data |
---|---|---|
80ca1b4e | 1 | <?php |
2 | /*************************************************************************** | |
5ddeb07c | 3 | * Copyright (C) 2003-2007 Polytechnique.org * |
80ca1b4e | 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 | ||
3641a0e6 | 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 | ||
eaf30d86 PH |
33 | if ($test_reverse) { |
34 | return display_address_isIdentity($idt, implode(' ', array_reverse(explode(' ', $value))), false); | |
3641a0e6 | 35 | } |
36 | return false; | |
37 | } | |
80ca1b4e | 38 | |
92630203 | 39 | function smarty_function_display_address($param, &$smarty) |
40 | { | |
80ca1b4e | 41 | require_once('geoloc.inc.php'); |
42 | $txtad = get_address_text($param['adr']); | |
79a5acea | 43 | if (!$txtad && |
44 | !$param['adr']['tels'] && !count($param['adr']['tels']) && | |
45 | !$param['adr']['tel'] && | |
46 | !$param['adr']['fax'] && | |
47 | !$param['adr']['mobile']) return ""; | |
80ca1b4e | 48 | |
3641a0e6 | 49 | |
a450ecb7 | 50 | $lines = explode("\n", $txtad); |
3641a0e6 | 51 | $idt = array_shift($lines); |
52 | $restore = true; | |
53 | ||
54 | if (!display_address_isIdentity($param['for'], $idt)) { | |
55 | array_unshift($lines, $idt); | |
56 | $idt = $param['for']; | |
57 | $restore = false; | |
58 | } | |
92630203 | 59 | |
80ca1b4e | 60 | $txthtml = ""; |
92630203 | 61 | $map = "<a href=\"http://maps.google.fr/?q=" |
1a5db4b8 | 62 | . urlencode(implode(", ", $lines) . " ($idt)") |
6261a1b5 | 63 | . "\"><img src=\"images/icons/map.gif\" alt=\"Google Maps\" title=\"Carte\"/></a>"; |
3641a0e6 | 64 | if ($restore) { |
65 | array_unshift($lines, $idt); | |
66 | } | |
80ca1b4e | 67 | if ($param['titre']) |
68 | { | |
bf73c651 | 69 | if ($param['titre_div']) |
70 | $txthtml .= "<div class='titre'>".$param['titre'].$map."</div>\n"; | |
6261a1b5 | 71 | else |
72 | $txthtml .= "<em>".$param['titre']."</em>".$map."<br />\n"; | |
80ca1b4e | 73 | } |
74 | foreach ($lines as $line) | |
75 | { | |
bf73c651 | 76 | $txthtml .= "<strong>".$line."</strong><br/>\n"; |
80ca1b4e | 77 | } |
78 | if ($param['adr']['tel']) | |
a7de4ef7 | 79 | $txthtml .= "<div>\n<em>Tél : </em>\n<strong>".$param['adr']['tel']."</strong>\n</div>\n"; |
80ca1b4e | 80 | if ($param['adr']['fax']) |
bf73c651 | 81 | $txthtml .= "<div>\n<em>Fax : </em>\n<strong>".$param['adr']['fax']."</strong>\n</div>\n"; |
80ca1b4e | 82 | if ($param['adr']['mobile']) |
a7de4ef7 | 83 | $txthtml .= "<div>\n<em>Tél : </em>\n<strong>".$param['adr']['mobile']."</strong>\n</div>\n"; |
79a5acea | 84 | if ($param['adr']['tels'] && count($param['adr']['tels'])) { |
eaf30d86 | 85 | foreach ($param['adr']['tels'] as $tel) |
79a5acea | 86 | $txthtml .= "<div>\n<em>".$tel['tel_type']." : </em>\n<strong>".$tel['tel']."</strong>\n</div>\n"; |
87 | } | |
6261a1b5 | 88 | if (!$param['nodiv']) { |
89 | $pos = $param['pos'] ? " style='float: " . $param['pos'] . "'" : ''; | |
90 | $txthtml = "<div class='adresse' $pos>\n".$txthtml."</div>\n"; | |
80ca1b4e | 91 | } |
92 | return $txthtml; | |
93 | } | |
94 | ||
a7de4ef7 | 95 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
80ca1b4e | 96 | ?> |