2 /***************************************************************************
3 * Copyright (C) 2003-2007 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class ProfileAddress
extends ProfileNoSave
24 private function geolocAddress(&$address, &$success)
26 require_once 'geoloc.inc.php';
27 if (@$address['parsevalid'] ||
(@$address['text'] && @$address['changed']) ||
!@$address['cityid']) {
28 $address = array_merge($address, empty_address());
29 $new = get_address_infos(@$address['text']);
30 if (compare_addresses_text(@$adress['text'], $geotxt = get_address_text($new))
31 ||
@$address['parsevalid']) {
32 $address = array_merge($address, $new);
35 $address = array_merge($address, cut_address(@$address['text']));
36 $address['geoloc'] = $geotxt;
37 $address['geoloc_cityid'] = $new['cityid'];
40 $address['text'] = get_address_text($address);
41 unset($address['parsevalid']);
42 unset($address['changed']);
45 public function value(ProfilePage
&$page, $field, $value, &$success)
48 if (is_null($value)) {
49 $value = $page->values
['addresses'];
52 foreach ($value as $key=>&$adr) {
53 if (@$adr['removed']) {
58 foreach ($value as $key=>&$adr) {
59 $this->geolocAddress($adr, $s);
61 $success = $success && $s;
68 class ProfileAddresses
extends ProfilePage
70 protected $pg_template = 'profile/adresses.tpl';
72 public function __construct(PlWizard
&$wiz)
74 parent
::__construct($wiz);
75 $this->settings
['addresses'] = new ProfileAddress();
78 protected function fetchData()
80 if (count($this->orig
) > 0) {
81 $this->values
= $this->orig
;
84 // Build the addresses tree
85 $res = XDB
::query("SELECT a.adrid AS id, a.adr1, a.adr2, a.adr3,
86 a.postcode, a.city, a.cityid, a.region, a.regiontxt,
87 a.fax, a.glat, a.glng, a.datemaj, a.pub,
88 a.country, gp.pays AS countrytxt, gp.display,
89 FIND_IN_SET('res-secondaire', a.statut) AS secondaire,
90 FIND_IN_SET('courrier', a.statut) AS mail,
91 FIND_IN_SET('temporary', a.statut) AS temporary,
92 FIND_IN_SET('active', a.statut) AS current
94 INNER JOIN geoloc_pays AS gp ON(gp.a2 = a.country)
95 WHERE uid = {?} AND NOT FIND_IN_SET('pro', statut)
98 $this->values
['addresses'] = $res->fetchAllAssoc();
100 $res = XDB
::iterator("SELECT adrid, tel_type AS type, tel_pub AS pub, tel
106 while ($tel = $res->next()) {
107 $adrid = $tel['adrid'];
108 unset($tel['adrid']);
109 while ($this->values
['addresses'][$i]['id'] < $adrid) {
112 $address =& $this->values
['addresses'][$i];
113 if (!isset($address['tel'])) {
114 $address['tel'] = array();
116 if ($address['id'] == $adrid) {
117 $address['tel'][] = $tel;
120 foreach ($this->values
['addresses'] as $id=>&$address) {
121 unset($address['id']);
126 protected function saveData()
131 public function prepare(PlatalPage
&$page)
133 parent
::prepare($page);
137 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: