feb369211c5108f513a88c3e556add56f11453df
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 ***************************************************************************/
28 public function __construct()
30 $this->bool
= new ProfileBool();
31 $this->pub
= new ProfilePub();
32 $this->tel
= new ProfileTel();
35 private function geolocAddress(array &$address, &$success)
37 require_once 'geoloc.inc.php';
39 unset($address['geoloc']);
40 unset($address['geoloc_cityid']);
41 if (@$address['parsevalid'] ||
(@$address['text'] && @$address['changed']) ||
!@$address['cityid']) {
42 $address = array_merge($address, empty_address());
43 $new = get_address_infos(@$address['text']);
44 if (compare_addresses_text(@$adress['text'], $geotxt = get_address_text($new))
45 ||
@$address['parsevalid']) {
46 $address = array_merge($address, $new);
49 $address = array_merge($address, cut_address(@$address['text']));
50 $address['geoloc'] = $geotxt;
51 $address['geoloc_cityid'] = $new['cityid'];
54 if (@$address['changed']) {
55 $address['datemaj'] = time();
57 $address['text'] = get_address_text($address);
60 private function cleanAddress(ProfilePage
&$page, array &$address, &$success)
62 if (@$address['changed']) {
63 $address['datemaj'] = time();
66 foreach ($address['tel'] as $t=>&$tel) {
67 if (@$tel['removed'] ||
!trim($tel['tel'])) {
68 unset($address['tel'][$t]);
70 $tel['pub'] = $this->pub
->value($page, 'pub', $tel['pub'], $s);
71 $tel['tel'] = $this->tel
->value($page, 'tel', $tel['tel'], $s);
77 unset($tel['removed']);
79 if (@$address['changed']) {
80 $address['datemaj'] = time();
82 $address['secondaire'] = $this->bool
->value($page, 'secondaire', $address['secondaire'], $s);
83 $address['mail'] = $this->bool
->value($page, 'mail', $address['mail'], $s);
84 $address['temporary'] = $this->bool
->value($page, 'temporary', $address['temporary'], $s);
85 $address['current'] = $this->bool
->value($page, 'current', @$address['current'], $s);
86 $address['pub'] = $this->pub
->value($page, 'pub', $address['pub'], $s);
87 unset($address['parsevalid']);
88 unset($address['changed']);
89 unset($address['removed']);
90 unset($address['display']);
93 public function value(ProfilePage
&$page, $field, $value, &$success)
96 if (is_null($value)) {
97 $value = $page->values
['addresses'];
100 foreach ($value as $key=>&$adr) {
101 if (@$adr['removed']) {
106 foreach ($value as $key=>&$adr) {
107 if (@$adr['current']) {
111 if (!$init && $current != 1 && count($value) > 0) {
116 foreach ($value as $key=>&$adr) {
118 $this->geolocAddress($adr, $s);
120 $this->cleanAddress($page, $adr, $s);
122 if (!trim($adr['text'])) {
125 $success = ($success && $ls);
131 private function saveTel($adrid, $telid, array &$tel)
133 XDB
::execute("INSERT INTO tels (uid, adrid, telid,
134 tel_type, tel_pub, tel)
135 VALUES ({?}, {?}, {?},
137 S
::i('uid'), $adrid, $telid,
138 $tel['type'], $tel['pub'], $tel['tel']);
141 private function saveAddress($adrid, array &$address)
144 if ($address['secondaire']) {
145 $flags[] = 'res-secondaire';
147 if ($address['mail']) {
148 $flags[] = 'courrier';
150 if ($address['temporary']) {
151 $flags[] = 'temporaire';
153 if ($address['current']) {
156 $flags = implode(',', $flags);
157 XDB
::execute("INSERT INTO adresses (adr1, adr2, adr3,
158 postcode, city, cityid,
159 country, region, regiontxt,
160 pub, datemaj, statut,
162 VALUES ({?}, {?}, {?},
165 {?}, FROM_UNIXTIME({?}), {?},
167 $address['adr1'], $address['adr2'], $address['adr3'],
168 $address['postcode'], $address['city'], $address['cityid'],
169 $address['country'], $address['region'], $address['regiontxt'],
170 $address['pub'], $address['datemaj'], $flags,
171 S
::i('uid'), $adrid);
172 foreach ($address['tel'] as $telid=>&$tel) {
173 $this->saveTel($adrid, $telid, $tel);
177 public function save(ProfilePage
&$page, $field, $value)
179 XDB
::execute("DELETE FROM adresses
182 XDB
::execute("DELETE FROM tels
185 foreach ($value as $adrid=>&$address) {
186 $this->saveAddress($adrid, $address);
191 class ProfileAddresses
extends ProfilePage
193 protected $pg_template = 'profile/adresses.tpl';
195 public function __construct(PlWizard
&$wiz)
197 parent
::__construct($wiz);
198 $this->settings
['addresses'] = new ProfileAddress();
201 protected function fetchData()
203 if (count($this->orig
) > 0) {
204 $this->values
= $this->orig
;
207 // Build the addresses tree
208 $res = XDB
::query("SELECT a.adrid AS id, a.adr1, a.adr2, a.adr3,
209 UNIX_TIMESTAMP(a.datemaj) AS datemaj,
210 a.postcode, a.city, a.cityid, a.region, a.regiontxt,
211 a.pub, a.country, gp.pays AS countrytxt, gp.display,
212 FIND_IN_SET('res-secondaire', a.statut) AS secondaire,
213 FIND_IN_SET('courrier', a.statut) AS mail,
214 FIND_IN_SET('temporaire', a.statut) AS temporary,
215 FIND_IN_SET('active', a.statut) AS current
217 INNER JOIN geoloc_pays AS gp ON(gp.a2 = a.country)
218 WHERE uid = {?} AND NOT FIND_IN_SET('pro', statut)
221 if ($res->numRows() == 0) {
222 $this->values
['addresses'] = array();
224 $this->values
['addresses'] = $res->fetchAllAssoc();
227 $res = XDB
::iterator("SELECT adrid, tel_type AS type, tel_pub AS pub, tel
233 $adrNb = count($this->values
['addresses']);
234 while ($tel = $res->next()) {
235 $adrid = $tel['adrid'];
236 unset($tel['adrid']);
237 while ($i < $adrNb && $this->values
['addresses'][$i]['id'] < $adrid) {
243 $address =& $this->values
['addresses'][$i];
244 if (!isset($address['tel'])) {
245 $address['tel'] = array();
247 if ($address['id'] == $adrid) {
248 $address['tel'][] = $tel;
251 foreach ($this->values
['addresses'] as $id=>&$address) {
252 if (!isset($address['tel'])) {
253 $address['tel'] = array();
255 unset($address['id']);
261 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: