e78a5a043c732264d3c90a6f97889750a3f99ad1
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 ***************************************************************************/
27 public function __construct()
29 $this->bool
= new ProfileBool();
30 $this->pub
= new ProfilePub();
33 private function geolocAddress(array &$address, &$success)
35 require_once 'geoloc.inc.php';
37 unset($address['geoloc']);
38 unset($address['geoloc_cityid']);
39 if (@$address['parsevalid'] ||
(@$address['text'] && @$address['changed']) ||
!@$address['cityid']) {
40 $address = array_merge($address, empty_address());
41 $new = get_address_infos(@$address['text']);
42 if (compare_addresses_text(@$adress['text'], $geotxt = get_address_text($new))
43 ||
@$address['parsevalid']) {
44 $address = array_merge($address, $new);
47 $address = array_merge($address, cut_address(@$address['text']));
48 $address['geoloc'] = $geotxt;
49 $address['geoloc_cityid'] = $new['cityid'];
52 if (@$address['changed']) {
53 $address['datemaj'] = time();
55 $address['text'] = get_address_text($address);
58 private function cleanAddress(ProfilePage
&$page, array &$address)
60 if (@$address['changed']) {
61 $address['datemaj'] = time();
63 foreach ($address['tel'] as $t=>&$tel) {
64 if (@$tel['removed'] ||
!trim($tel['tel'])) {
65 unset($address['tel'][$t]);
67 $tel['pub'] = $this->pub
->value($page, 'pub', $tel['pub'], $success);
69 unset($tel['removed']);
71 if (@$address['changed']) {
72 $address['datemaj'] = time();
75 $address['secondaire'] = $this->bool
->value($page, 'secondaire', $address['secondaire'], $success);
76 $address['mail'] = $this->bool
->value($page, 'mail', $address['mail'], $success);
77 $address['temporary'] = $this->bool
->value($page, 'temporary', $address['temporary'], $success);
78 $address['current'] = $this->bool
->value($page, 'current', @$address['current'], $success);
79 $address['pub'] = $this->pub
->value($page, 'pub', $address['pub'], $success);
80 unset($address['parsevalid']);
81 unset($address['changed']);
82 unset($address['removed']);
83 unset($address['display']);
86 public function value(ProfilePage
&$page, $field, $value, &$success)
89 if (is_null($value)) {
90 $value = $page->values
['addresses'];
93 foreach ($value as $key=>&$adr) {
94 if (@$adr['removed']) {
99 foreach ($value as $key=>&$adr) {
100 if (@$adr['current']) {
104 if (!$init && $current != 1 && count($value) > 0) {
109 foreach ($value as $key=>&$adr) {
110 $this->geolocAddress($adr, $s);
111 $this->cleanAddress($page, $adr);
113 $success = $success && $s;
115 if (!trim($adr['text'])) {
122 private function saveTel($adrid, $telid, array &$tel)
124 XDB
::execute("INSERT INTO tels (uid, adrid, telid,
125 tel_type, tel_pub, tel)
126 VALUES ({?}, {?}, {?},
128 S
::i('uid'), $adrid, $telid,
129 $tel['type'], $tel['pub'], $tel['tel']);
132 private function saveAddress($adrid, array &$address)
135 if ($address['secondaire']) {
136 $flags[] = 'res-secondaire';
138 if ($address['mail']) {
139 $flags[] = 'courrier';
141 if ($address['temporary']) {
142 $flags[] = 'temporaire';
144 if ($address['current']) {
147 $flags = implode(',', $flags);
148 XDB
::execute("INSERT INTO adresses (adr1, adr2, adr3,
149 postcode, city, cityid,
150 country, region, regiontxt,
151 pub, datemaj, statut,
153 VALUES ({?}, {?}, {?},
156 {?}, FROM_UNIXTIME({?}), {?},
158 $address['adr1'], $address['adr2'], $address['adr3'],
159 $address['postcode'], $address['city'], $address['cityid'],
160 $address['country'], $address['region'], $address['regiontxt'],
161 $address['pub'], $address['datemaj'], $flags,
162 S
::i('uid'), $adrid);
163 foreach ($address['tel'] as $telid=>&$tel) {
164 $this->saveTel($adrid, $telid, $tel);
168 public function save(ProfilePage
&$page, $field, $value)
170 XDB
::execute("DELETE FROM adresses
173 XDB
::execute("DELETE FROM tels
176 foreach ($value as $adrid=>&$address) {
177 $this->saveAddress($adrid, $address);
182 class ProfileAddresses
extends ProfilePage
184 protected $pg_template = 'profile/adresses.tpl';
186 public function __construct(PlWizard
&$wiz)
188 parent
::__construct($wiz);
189 $this->settings
['addresses'] = new ProfileAddress();
192 protected function fetchData()
194 if (count($this->orig
) > 0) {
195 $this->values
= $this->orig
;
198 // Build the addresses tree
199 $res = XDB
::query("SELECT a.adrid AS id, a.adr1, a.adr2, a.adr3,
200 UNIX_TIMESTAMP(a.datemaj) AS datemaj,
201 a.postcode, a.city, a.cityid, a.region, a.regiontxt,
202 a.pub, a.country, gp.pays AS countrytxt, gp.display,
203 FIND_IN_SET('res-secondaire', a.statut) AS secondaire,
204 FIND_IN_SET('courrier', a.statut) AS mail,
205 FIND_IN_SET('temporaire', a.statut) AS temporary,
206 FIND_IN_SET('active', a.statut) AS current
208 INNER JOIN geoloc_pays AS gp ON(gp.a2 = a.country)
209 WHERE uid = {?} AND NOT FIND_IN_SET('pro', statut)
212 if ($res->numRows() == 0) {
213 $this->values
['addresses'] = array();
215 $this->values
['addresses'] = $res->fetchAllAssoc();
218 $res = XDB
::iterator("SELECT adrid, tel_type AS type, tel_pub AS pub, tel
224 $adrNb = count($this->values
['addresses']);
225 while ($tel = $res->next()) {
226 $adrid = $tel['adrid'];
227 unset($tel['adrid']);
228 while ($i < $adrNb && $this->values
['addresses'][$i]['id'] < $adrid) {
234 $address =& $this->values
['addresses'][$i];
235 if (!isset($address['tel'])) {
236 $address['tel'] = array();
238 if ($address['id'] == $adrid) {
239 $address['tel'][] = $tel;
242 foreach ($this->values
['addresses'] as $id=>&$address) {
243 if (!isset($address['tel'])) {
244 $address['tel'] = array();
246 unset($address['id']);
252 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: