First version of the addresses page
[platal.git] / modules / profile / addresses.inc.php
CommitLineData
0b14f91d
FB
1<?php
2/***************************************************************************
3 * Copyright (C) 2003-2007 Polytechnique.org *
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
22class ProfileAddress extends ProfileNoSave
23{
24 public function value(ProfilePage &$page, $field, $value, &$success)
25 {
26 $success = true;
27 if (is_null($value)) {
28 return $page->values['addresses'];
29 }
30 foreach ($value as $key=>&$adr) {
31 if ($adr['removed']) {
32 unset($value[$key]);
33 }
34 }
35 return $value;
36 }
37}
38
39class ProfileAddresses extends ProfilePage
40{
41 protected $pg_template = 'profile/adresses.tpl';
42
43 public function __construct(PlWizard &$wiz)
44 {
45 parent::__construct($wiz);
46 $this->settings['addresses'] = new ProfileAddress();
47 }
48
49 protected function fetchData()
50 {
51 if (count($this->orig) > 0) {
52 $this->values = $this->orig;
53 return;
54 }
55 // Build the addresses tree
56 $res = XDB::query("SELECT adrid AS id, adr1, adr2, adr3,
57 postcode, city, cityid, region, regiontxt,
58 fax, glat, glng, datemaj, pub,
59 FIND_IN_SET('res-secondaire', statut) AS secondaire,
60 FIND_IN_SET('courrier', statut) AS mail,
61 FIND_IN_SET('temporary', statut) AS temporary,
62 FIND_IN_SET('active', statut) AS current,
63 FIND_IN_SET('coord-checked', statut) AS checked,
64 FIND_IN_SET('coord-valid', statut) AS valid
65 FROM adresses
66 WHERE uid = {?}
67 ORDER BY adrid",
68 S::i('uid'));
69 $this->values['addresses'] = $res->fetchAllAssoc();
70
71 $res = XDB::iterRow("SELECT adrid, telid, tel_type, tel_pub, tel
72 FROM tels
73 WHERE uid = {?}
74 ORDER BY adrid",
75 S::i('uid'));
76 $i = 0;
77 while (list($adrid, $telid, $type, $pub, $tel) = $res->next()) {
78 while ($this->values['addresses'][$i]['id'] < $adrid) {
79 $i++;
80 }
81 $address =& $this->values['addresses'][$i];
82 if (!isset($address['tel'])) {
83 $address['tel'] = array();
84 }
85 if ($address['id'] == $adrid) {
86 $address['tel'][] = array('id' => $telid,
87 'type' => $type,
88 'pub' => $pub,
89 'tel' => $tel);
90 }
91 }
92 parent::fetchData();
93 }
94
95 protected function saveData()
96 {
97 parent::saveData();
98 }
99
100 public function prepare(PlatalPage &$page)
101 {
102 parent::prepare($page);
103 }
104}
105
106// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
107?>