When adding a new address to a profile, tick the "can receive mail" checkbox by default
[platal.git] / modules / profile / addresses.inc.php
CommitLineData
0b14f91d
FB
1<?php
2/***************************************************************************
c441aabe 3 * Copyright (C) 2003-2014 Polytechnique.org *
0b14f91d
FB
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
eb54852e 22class ProfileSettingAddresses implements ProfileSetting
0b14f91d 23{
26ba053e 24 public function value(ProfilePage $page, $field, $value, &$success)
0b14f91d 25 {
2db7542d 26 $success = true;
eb54852e
SJ
27 $addresses = array();
28
29 if (is_null($value)) {
07e4a9a0 30 $it = Address::iterate(array($page->pid()), array(Address::LINK_PROFILE), array(0), Visibility::get(Visibility::VIEW_ADMIN));
eb54852e
SJ
31 while ($address = $it->next()) {
32 $addresses[] = $address->toFormArray();
2db7542d 33 }
eb54852e 34 if (count($addresses) == 0) {
6c2a3be1 35 $address = new Address(array('mail' => 1));
eb54852e 36 $addresses[] = $address->toFormArray();
c6a7beb2 37 }
eb54852e 38 return $addresses;
7568a515 39 }
041a5cec 40
eb54852e 41 return Address::formatFormArray($value, $success);
d5489b09
FB
42 }
43
26ba053e 44 public function save(ProfilePage $page, $field, $value)
d5489b09 45 {
d3ce1117
SJ
46 $deletePrivate = S::user()->isMe($page->owner) || S::admin();
47
48 Phone::deletePhones($page->pid(), Phone::LINK_ADDRESS, null, $deletePrivate);
baab50c7 49 Address::deleteAddresses($page->pid(), Address::LINK_PROFILE, null, null, $deletePrivate);
57fa97b3 50 AddressReq::purge_requests($page->pid(), 0, 0, Address::LINK_PROFILE);
a3328b1e 51 Address::saveFromArray($value, $page->pid(), Address::LINK_PROFILE, null, $deletePrivate);
313e8575
SJ
52 if (S::user()->isMe($page->owner) && count($value) > 1) {
53 Platal::page()->trigWarning('Attention, tu as plusieurs adresses sur ton profil. Pense à supprimer celles qui sont obsolètes.');
54 }
d5489b09 55 }
a0fce0c6 56
eb54852e
SJ
57 public function getText($value)
58 {
59 return Address::formArrayToString($value);
a0fce0c6 60 }
0b14f91d
FB
61}
62
66c4bdaf 63class ProfilePageAddresses extends ProfilePage
0b14f91d
FB
64{
65 protected $pg_template = 'profile/adresses.tpl';
66
26ba053e 67 public function __construct(PlWizard $wiz)
0b14f91d
FB
68 {
69 parent::__construct($wiz);
eb54852e 70 $this->settings['addresses'] = new ProfileSettingAddresses();
041a5cec 71 $this->watched['addresses'] = true;
57fa97b3 72 Platal::page()->assign('geocoding_removal', true);
0b14f91d 73 }
0b14f91d
FB
74}
75
448c8cdc 76// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
0b14f91d 77?>