2 /***************************************************************************
3 * Copyright (C) 2003-2010 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 ***************************************************************************/
22 // {{{ class NamesReq4
24 class NamesReq
extends Validate
28 public $unique = true
;
32 public $display_names;
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).";
42 public function __construct(User
&$_user, $_search_names, $_private_name_end)
44 parent
::__construct($_user, true
, 'usage');
45 require_once 'name.func.inc.php';
47 $this->sn_types
= build_types();
48 $this->sn_old
= build_sn_pub($this->user
->profile()->id());
49 $this->sn_new
= $_search_names;
50 $this->new_alias
= true
;
51 $this->display_names
= array();
53 build_display_names($this->display_names
, $_search_names,
54 $this->user
->profile()->isFemale(), $_private_name_end, $this->new_alias
);
55 foreach ($this->sn_new
AS $key => &$sn) {
56 if (!isset($sn['pub'])) {
57 unset($this->sn_new
[$key]);
60 $res = XDB
::query("SELECT alias
62 WHERE uid = {?} AND type = 'alias' AND FIND_IN_SET('usage', flags)",
64 $this->old_alias
= $res->fetchOneCell();
65 if ($this->old_alias
!= $this->new_alias
) {
66 $res = XDB
::query("SELECT uid
70 if ($res->fetchOneCell()) {
71 $this->new_alias
= null
;
77 // {{{ function formu()
79 public function formu()
81 return 'include/form.valid.names.tpl';
85 // {{{ function _mail_subj()
87 protected function _mail_subj()
89 return "[Polytechnique.org/NOMS] Changement de noms";
93 // {{{ function _mail_body
95 protected function _mail_body($isok)
99 $res = " Le changement de nom que tu as demandé vient d'être effectué.";
100 if ($this->old_alias
!= $this->new_alias
) {
101 if ($this->old_alias
) {
102 $res .= "\n\n Les alias {$this->old_alias}@{$globals->mail->domain} et @{$globals->mail->domain2} ont été supprimés.";
104 if ($this->new_alias
) {
105 $res .= "\n\n Les alias {$this->new_alias}@{$globals->mail->domain} et @{$globals->mail->domain2} sont maintenant à ta disposition !";
108 if ($globals->mailstorage
->googleapps_domain
) {
109 require_once 'googleapps.inc.php';
110 $account = new GoogleAppsAccount($this->user
);
111 if ($account->active()) {
112 $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 return " La demande de changement de nom que tu avais faite a été refusée.";
122 // {{{ function commit()
124 public function commit()
126 require_once 'name.func.inc.php';
128 set_profile_display($this->display_names
, $this->user
->profile()->id());
129 set_alias_names($this->sn_new
, $this->sn_old
, $this->user
->profile()->id(),
130 $this->user
->id(), true
, $this->new_alias
);
132 // Update the local User object, to pick up the new bestalias.
133 $this->user
= User
::getSilent($this->user
->id());
142 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: