Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
12262f13 | 3 | * Copyright (C) 2003-2011 Polytechnique.org * |
0337d704 | 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 | ||
453cbb00 | 22 | // {{{ class NamesReq |
0337d704 | 23 | |
c3d1e6b6 | 24 | class NamesReq extends ProfileValidate |
0337d704 | 25 | { |
26 | // {{{ properties | |
27 | ||
612a2d8a | 28 | public $unique = true; |
0337d704 | 29 | |
dced83b4 SJ |
30 | public $sn_old; |
31 | public $sn_new; | |
32 | public $display_names; | |
f036c896 | 33 | public $mail_domain; |
dced83b4 SJ |
34 | public $old_alias; |
35 | public $new_alias; | |
36 | public $sn_types; | |
0337d704 | 37 | |
dced83b4 | 38 | public $rules = "Refuser tout ce qui n'est visiblement pas un nom de famille (ce qui est extremement rare car à peu près n'importe quoi peut être un nom de famille)."; |
0337d704 | 39 | |
40 | // }}} | |
41 | // {{{ constructor | |
42 | ||
26ba053e | 43 | public function __construct(User $_user, Profile $_profile, $_search_names, $_private_name_end) |
0337d704 | 44 | { |
c3d1e6b6 | 45 | parent::__construct($_user, $_profile, true, 'usage'); |
dced83b4 SJ |
46 | require_once 'name.func.inc.php'; |
47 | ||
48 | $this->sn_types = build_types(); | |
c3d1e6b6 | 49 | $this->sn_old = build_sn_pub($this->profile->id()); |
dced83b4 SJ |
50 | $this->sn_new = $_search_names; |
51 | $this->new_alias = true; | |
52 | $this->display_names = array(); | |
f036c896 | 53 | $this->mail_domain = $this->profileOwner->mainEmailDomain(); |
dced83b4 | 54 | |
e8a7cf31 | 55 | build_display_names($this->display_names, $_search_names, |
c3d1e6b6 | 56 | $this->profile->isFemale(), $_private_name_end, $this->new_alias); |
dced83b4 SJ |
57 | foreach ($this->sn_new AS $key => &$sn) { |
58 | if (!isset($sn['pub'])) { | |
59 | unset($this->sn_new[$key]); | |
60 | } | |
61 | } | |
c3d1e6b6 SJ |
62 | |
63 | if (!is_null($this->profileOwner)) { | |
f036c896 SJ |
64 | $this->old_alias = XDB::fetchOneCell('SELECT email |
65 | FROM email_source_account | |
66 | WHERE uid = {?} AND type = \'alias\' AND FIND_IN_SET(\'usage\', flags)', | |
67 | $this->profileOwner->id()); | |
c3d1e6b6 | 68 | if ($this->old_alias != $this->new_alias) { |
f036c896 SJ |
69 | $used = XDB::fetchOneCell('SELECT COUNT(uid) |
70 | FROM email_source_account | |
71 | WHERE email = {?} AND type != \'alias_aux\'', | |
72 | $this->new_alias); | |
c0436d0b | 73 | if ($used) { |
c3d1e6b6 SJ |
74 | $this->new_alias = null; |
75 | } | |
dced83b4 | 76 | } |
5daf68f6 | 77 | } |
0337d704 | 78 | } |
79 | ||
80 | // }}} | |
0337d704 | 81 | // {{{ function formu() |
82 | ||
612a2d8a | 83 | public function formu() |
84 | { | |
dced83b4 | 85 | return 'include/form.valid.names.tpl'; |
612a2d8a | 86 | } |
0337d704 | 87 | |
88 | // }}} | |
89 | // {{{ function _mail_subj() | |
90 | ||
612a2d8a | 91 | protected function _mail_subj() |
0337d704 | 92 | { |
dced83b4 | 93 | return "[Polytechnique.org/NOMS] Changement de noms"; |
0337d704 | 94 | } |
95 | ||
96 | // }}} | |
97 | // {{{ function _mail_body | |
98 | ||
612a2d8a | 99 | protected function _mail_body($isok) |
0337d704 | 100 | { |
0337d704 | 101 | if ($isok) { |
dced83b4 | 102 | $res = " Le changement de nom que tu as demandé vient d'être effectué."; |
c3d1e6b6 SJ |
103 | if (!is_null($this->profileOwner)) { |
104 | if ($this->old_alias != $this->new_alias) { | |
105 | if ($this->old_alias) { | |
f036c896 | 106 | $res .= "\n\n L'alias {$this->old_alias}@{$this->mail_domain} a été supprimé."; |
c3d1e6b6 SJ |
107 | } |
108 | if ($this->new_alias) { | |
f036c896 | 109 | $res .= "\n\n L'alias {$this->new_alias}@{$this->mail_domain} est maintenant à ta disposition !"; |
c3d1e6b6 | 110 | } |
dced83b4 | 111 | } |
c3d1e6b6 SJ |
112 | if ($globals->mailstorage->googleapps_domain) { |
113 | require_once 'googleapps.inc.php'; | |
114 | $account = new GoogleAppsAccount($this->profileOwner); | |
115 | if ($account->active()) { | |
116 | $res .= "\n\n Si tu utilises Google Apps, tu peux changer ton nom d'usage sur https://mail.google.com/a/polytechnique.org/#settings/accounts."; | |
117 | } | |
fc0342c3 VZ |
118 | } |
119 | } | |
0337d704 | 120 | return $res; |
121 | } else { | |
dced83b4 | 122 | return " La demande de changement de nom que tu avais faite a été refusée."; |
0337d704 | 123 | } |
124 | } | |
125 | ||
126 | // }}} | |
127 | // {{{ function commit() | |
128 | ||
612a2d8a | 129 | public function commit() |
0337d704 | 130 | { |
6cb58d39 | 131 | require_once 'name.func.inc.php'; |
dced83b4 | 132 | |
f4b04704 | 133 | set_profile_display($this->display_names, $this->profile); |
01ebbdbf | 134 | |
c3d1e6b6 SJ |
135 | if (!is_null($this->profileOwner)) { |
136 | set_alias_names($this->sn_new, $this->sn_old, $this->profile->id(), | |
f036c896 | 137 | $this->profileOwner, true, $this->new_alias); |
c3d1e6b6 SJ |
138 | |
139 | // Update the local User object, to pick up the new bestalias. | |
14da7ef4 | 140 | $this->profileOwner = User::getSilentWithUID($this->profileOwner->id()); |
c3d1e6b6 | 141 | } |
01ebbdbf | 142 | |
0337d704 | 143 | return true; |
144 | } | |
145 | ||
146 | // }}} | |
147 | } | |
148 | // }}} | |
149 | ||
a7de4ef7 | 150 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 151 | ?> |