Merge commit 'origin/master' into fusionax
[platal.git] / include / validations / nomusage.inc.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
179afa7f 3 * Copyright (C) 2003-2008 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
22// {{{ class UsageReq
23
24class UsageReq extends Validate
25{
26 // {{{ properties
27
612a2d8a 28 public $unique = true;
0337d704 29
612a2d8a 30 public $nom_usage;
31 public $alias = '';
0337d704 32
612a2d8a 33 public $oldusage;
34 public $oldalias;
0337d704 35
612a2d8a 36 public $homonyme;
37 public $reason;
eaf30d86
PH
38
39 public $rules = "Refuser
40 tout ce qui n'est visiblement pas un nom de famille (ce qui est
41 extremement rare car à peu près n'importe quoi peut être un nom de
0337d704 42 famille...)";
43
44 // }}}
45 // {{{ constructor
46
532c06cf 47 public function __construct(User &$_user, $_usage, $_reason)
0337d704 48 {
5daf68f6
VZ
49 parent::__construct($_user, true, 'usage');
50 $this->nom_usage = $_usage;
21e9114c 51 $this->reason = $_reason;
5daf68f6
VZ
52
53 $res = XDB::query("SELECT prenom FROM auth_user_md5 WHERE user_id = {?}", $this->user->id());
54 $this->alias = make_username($res->fetchOneCell(), $this->nom_usage);
55 if (!$this->nom_usage) {
56 $this->alias = "";
57 }
0337d704 58
08cce2ff 59 $res = XDB::query("
0337d704 60 SELECT e.alias, u.nom_usage, a.id
61 FROM auth_user_md5 as u
62 LEFT JOIN aliases as e ON(e.type='alias' AND FIND_IN_SET('usage',e.flags) AND e.id = u.user_id)
63 LEFT JOIN aliases as a ON(a.alias = {?} AND a.id != u.user_id)
532c06cf 64 WHERE u.user_id = {?}", $this->alias, $this->user->id());
0337d704 65 list($this->oldalias, $this->oldusage, $this->homonyme) = $res->fetchOneRow();
66 }
67
68 // }}}
0337d704 69 // {{{ function formu()
70
612a2d8a 71 public function formu()
72 {
73 return 'include/form.valid.nomusage.tpl';
74 }
0337d704 75
76 // }}}
77 // {{{ function _mail_subj()
78
612a2d8a 79 protected function _mail_subj()
0337d704 80 {
81 return "[Polytechnique.org/USAGE] Changement de nom d'usage";
82 }
83
84 // }}}
85 // {{{ function _mail_body
86
612a2d8a 87 protected function _mail_body($isok)
0337d704 88 {
89 global $globals;
90 if ($isok) {
605d2899 91 $res = " Le changement de nom d'usage que tu as demandé vient d'être effectué.";
0337d704 92 if ($this->oldalias) {
a7de4ef7 93 $res .= "\n\n Les alias {$this->oldalias}@{$globals->mail->domain} et @{$globals->mail->domain2} ont été supprimés.";
0337d704 94 }
e4df055c 95 if ($this->nom_usage) {
a7de4ef7 96 $res .= "\n\n Les alias {$this->alias}@{$globals->mail->domain} et @{$globals->mail->domain2} sont maintenant à ta disposition !";
0337d704 97 }
fc0342c3
VZ
98 if ($globals->mailstorage->googleapps_domain) {
99 require_once 'googleapps.inc.php';
5daf68f6 100 $account = new GoogleAppsAccount($this->user);
fc0342c3
VZ
101 if ($account->active()) {
102 $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";
103 }
104 }
0337d704 105 return $res;
106 } else {
a7de4ef7 107 return " La demande de changement de nom d'usage que tu avais faite a été refusée.";
0337d704 108 }
109 }
110
111 // }}}
112 // {{{ function commit()
113
612a2d8a 114 public function commit()
0337d704 115 {
a2a1c2f2 116 require_once 'notifs.inc.php';
805f3d16 117 register_watch_op($this->user->id(), WATCH_FICHE, '', 'nom');
74c55fd6 118 require_once('user.func.inc.php');
5daf68f6 119 set_new_usage($this->user->id(), $this->nom_usage, $this->alias);
0337d704 120 return true;
121 }
122
123 // }}}
124}
125// }}}
126
a7de4ef7 127// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
0337d704 128?>