aliases.id => aliases.uid
[platal.git] / include / validations / names.inc.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
9f5bd98e 3 * Copyright (C) 2003-2010 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
dced83b4 22// {{{ class NamesReq4
0337d704 23
dced83b4 24class NamesReq extends Validate
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;
33 public $old_alias;
34 public $new_alias;
35 public $sn_types;
0337d704 36
dced83b4 37 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 38
39 // }}}
40 // {{{ constructor
41
dced83b4 42 public function __construct(User &$_user, $_search_names, $_private_name_end)
0337d704 43 {
5daf68f6 44 parent::__construct($_user, true, 'usage');
dced83b4
SJ
45 require_once 'name.func.inc.php';
46
47 $this->sn_types = build_types();
48 $this->sn_old = build_sn_pub();
49 $this->sn_new = $_search_names;
50 $this->new_alias = true;
51 $this->display_names = array();
52
53 build_display_names($this->display_names, $_search_names, $_private_name_end, $this->new_alias);
54 foreach ($this->sn_new AS $key => &$sn) {
55 if (!isset($sn['pub'])) {
56 unset($this->sn_new[$key]);
57 }
58 }
59 $res = XDB::query("SELECT alias
60 FROM aliases
fe13bc1d 61 WHERE uid = {?} AND type = 'alias' AND FIND_IN_SET('usage', flags)",
dced83b4
SJ
62 $this->user->id());
63 $this->old_alias = $res->fetchOneCell();
64 if ($this->old_alias != $this->new_alias) {
fe13bc1d 65 $res = XDB::query("SELECT uid
dced83b4
SJ
66 FROM aliases
67 WHERE alias = {?}",
68 $this->new_alias);
69 if ($res->fetchOneCell()) {
70 $this->new_alias = null;
71 }
5daf68f6 72 }
0337d704 73 }
74
75 // }}}
0337d704 76 // {{{ function formu()
77
612a2d8a 78 public function formu()
79 {
dced83b4 80 return 'include/form.valid.names.tpl';
612a2d8a 81 }
0337d704 82
83 // }}}
84 // {{{ function _mail_subj()
85
612a2d8a 86 protected function _mail_subj()
0337d704 87 {
dced83b4 88 return "[Polytechnique.org/NOMS] Changement de noms";
0337d704 89 }
90
91 // }}}
92 // {{{ function _mail_body
93
612a2d8a 94 protected function _mail_body($isok)
0337d704 95 {
96 global $globals;
97 if ($isok) {
dced83b4
SJ
98 $res = " Le changement de nom que tu as demandé vient d'être effectué.";
99 if ($this->old_alias != $this->new_alias) {
100 if ($this->old_alias) {
101 $res .= "\n\n Les alias {$this->old_alias}@{$globals->mail->domain} et @{$globals->mail->domain2} ont été supprimés.";
102 }
103 if ($this->new_alias) {
104 $res .= "\n\n Les alias {$this->new_alias}@{$globals->mail->domain} et @{$globals->mail->domain2} sont maintenant à ta disposition !";
105 }
0337d704 106 }
fc0342c3
VZ
107 if ($globals->mailstorage->googleapps_domain) {
108 require_once 'googleapps.inc.php';
5daf68f6 109 $account = new GoogleAppsAccount($this->user);
fc0342c3 110 if ($account->active()) {
dced83b4 111 $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.";
fc0342c3
VZ
112 }
113 }
0337d704 114 return $res;
115 } else {
dced83b4 116 return " La demande de changement de nom que tu avais faite a été refusée.";
0337d704 117 }
118 }
119
120 // }}}
121 // {{{ function commit()
122
612a2d8a 123 public function commit()
0337d704 124 {
a2a1c2f2 125 require_once 'notifs.inc.php';
6cb58d39 126 require_once 'name.func.inc.php';
dced83b4
SJ
127
128 register_watch_op($this->user->id(), WATCH_FICHE, '', 'search_names');
129 set_profile_display($this->display_names);
130 set_alias_names($this->sn_new, $this->sn_old, true, $this->new_alias);
01ebbdbf
VZ
131
132 // Update the local User object, to pick up the new bestalias.
133 $this->user = User::getSilent($this->user->id());
134
0337d704 135 return true;
136 }
137
138 // }}}
139}
140// }}}
141
a7de4ef7 142// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
0337d704 143?>