e2360a80bd50972730a99660fc6078a8d65b83f1
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 if (@$address['parsevalid'] ||
(@$address['text'] && @$address['changed']) ||
!@$address['cityid']) {
38 $address = array_merge($address, empty_address());
39 $new = get_address_infos(@$address['text']);
40 if (compare_addresses_text(@$adress['text'], $geotxt = get_address_text($new))
41 ||
@$address['parsevalid']) {
42 $address = array_merge($address, $new);
45 $address = array_merge($address, cut_address(@$address['text']));
46 $address['geoloc'] = $geotxt;
47 $address['geoloc_cityid'] = $new['cityid'];
50 if (@$address['changed']) {
51 $address['datemaj'] = time();
53 $address['text'] = get_address_text($address);
56 private function cleanAddress(ProfilePage
&$page, array &$address)
58 if (@$address['changed']) {
59 $address['datemaj'] = time();
61 foreach ($address['tel'] as $t=>&$tel) {
62 if (@$tel['removed']) {
63 unset($address['tel'][$t]);
65 $tel['pub'] = $this->pub
->value($page, 'pub', $tel['pub'], $success);
67 unset($tel['removed']);
69 if (@$address['changed']) {
70 $address['datemaj'] = time();
73 $address['secondaire'] = $this->bool
->value($page, 'secondaire', $address['secondaire'], $success);
74 $address['mail'] = $this->bool
->value($page, 'mail', $address['mail'], $success);
75 $address['temporary'] = $this->bool
->value($page, 'temporary', $address['temporary'], $success);
76 $address['current'] = $this->bool
->value($page, 'current', @$address['current'], $success);
77 $address['pub'] = $this->pub
->value($page, 'pub', $address['pub'], $success);
78 unset($address['parsevalid']);
79 unset($address['changed']);
80 unset($address['removed']);
81 unset($address['display']);
84 public function value(ProfilePage
&$page, $field, $value, &$success)
87 if (is_null($value)) {
88 $value = $page->values
['addresses'];
91 foreach ($value as $key=>&$adr) {
92 if (@$adr['removed']) {
97 foreach ($value as $key=>&$adr) {
98 $this->geolocAddress($adr, $s);
99 $this->cleanAddress($page, $adr);
101 $success = $success && $s;
107 private function saveTel($adrid, $telid, array &$tel)
109 XDB
::execute("INSERT INTO tels (uid, adrid, telid,
110 tel_type, tel_pub, tel)
111 VALUES ({?}, {?}, {?},
113 S
::i('uid'), $adrid, $telid,
114 $tel['type'], $tel['pub'], $tel['tel']);
117 private function saveAddress($adrid, array &$address)
120 if ($address['secondaire']) {
121 $flags[] = 'res-secondaire';
123 if ($address['mail']) {
124 $flags[] = 'courrier';
126 if ($address['temporary']) {
127 $flags[] = 'temporaire';
129 if ($address['current']) {
132 $flags = implode(',', $flags);
133 XDB
::execute("INSERT INTO adresses (adr1, adr2, adr3,
134 postcode, city, cityid,
135 country, region, regiontxt,
136 pub, datemaj, statut,
138 VALUES ({?}, {?}, {?},
141 {?}, FROM_UNIXTIME({?}), {?},
143 $address['adr1'], $address['adr2'], $address['adr3'],
144 $address['postcode'], $address['city'], $address['cityid'],
145 $address['country'], $address['region'], $address['regiontxt'],
146 $address['pub'], $address['datemaj'], $flags,
147 S
::i('uid'), $adrid);
148 foreach ($address['tel'] as $telid=>&$tel) {
149 $this->saveTel($adrid, $telid, $tel);
153 public function save(ProfilePage
&$page, $field, $value)
155 XDB
::execute("DELETE FROM adresses
158 XDB
::execute("DELETE FROM tels
161 foreach ($value as $adrid=>&$address) {
162 $this->saveAddress($adrid, $address);
167 class ProfileAddresses
extends ProfilePage
169 protected $pg_template = 'profile/adresses.tpl';
171 public function __construct(PlWizard
&$wiz)
173 parent
::__construct($wiz);
174 $this->settings
['addresses'] = new ProfileAddress();
177 protected function fetchData()
179 if (count($this->orig
) > 0) {
180 $this->values
= $this->orig
;
183 // Build the addresses tree
184 $res = XDB
::query("SELECT a.adrid AS id, a.adr1, a.adr2, a.adr3,
185 UNIX_TIMESTAMP(a.datemaj) AS datemaj,
186 a.postcode, a.city, a.cityid, a.region, a.regiontxt,
187 a.pub, a.country, gp.pays AS countrytxt, gp.display,
188 FIND_IN_SET('res-secondaire', a.statut) AS secondaire,
189 FIND_IN_SET('courrier', a.statut) AS mail,
190 FIND_IN_SET('temporaire', a.statut) AS temporary,
191 FIND_IN_SET('active', a.statut) AS current
193 INNER JOIN geoloc_pays AS gp ON(gp.a2 = a.country)
194 WHERE uid = {?} AND NOT FIND_IN_SET('pro', statut)
197 if ($res->numRows() == 0) {
198 $this->values
['addresses'] = array();
200 $this->values
['addresses'] = $res->fetchAllAssoc();
203 $res = XDB
::iterator("SELECT adrid, tel_type AS type, tel_pub AS pub, tel
209 $adrNb = count($this->values
['addresses']);
210 while ($tel = $res->next()) {
211 $adrid = $tel['adrid'];
212 unset($tel['adrid']);
213 while ($i < $adrNb && $this->values
['addresses'][$i]['id'] < $adrid) {
219 $address =& $this->values
['addresses'][$i];
220 if (!isset($address['tel'])) {
221 $address['tel'] = array();
223 if ($address['id'] == $adrid) {
224 $address['tel'][] = $tel;
227 foreach ($this->values
['addresses'] as $id=>&$address) {
228 if (!isset($address['tel'])) {
229 $address['tel'] = array();
231 unset($address['id']);
237 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: