9716a21824df9bc1f7f625386f50a46149ef5610
2 /***************************************************************************
3 * Copyright (C) 2003-2004 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 require_once("xorg.inc.php");
23 require_once("validations.inc.php");
25 new_skinned_page('alias.tpl', AUTH_MDP
);
27 $uid = Session
::getInt('uid');
28 $forlife = Session
::get('forlife');
30 $page->assign('demande', AliasReq
::get_request($uid));
32 //Suppression d'un alias
33 if (Env
::get('suppr', false
)) {
34 $globals->xdb
->execute(
35 'DELETE virtual, virtual_redirect
37 INNER JOIN virtual_redirect USING (vid)
38 WHERE alias LIKE {?} AND (redirect = {?} OR redirect = {?})',
40 $forlife.'@'.$globals->mail
->domain
, $forlife.'@'.$globals->mail
->domain2
);
43 //Récupération des alias éventuellement existants
44 $res = $globals->xdb
->query(
45 "SELECT alias, emails_alias_pub
46 FROM auth_user_quick, virtual
47 INNER JOIN virtual_redirect USING(vid)
48 WHERE ( redirect={?} OR redirect= {?} )
49 AND alias LIKE '%@{$globals->mail->alias_dom}' AND user_id = {?}",
50 $forlife.'@'.$globals->mail
->domain
, $forlife.'@'.$globals->mail
->domain2
, Session
::getInt('uid'));
51 list($alias, $visibility) = $res->fetchOneRow();
52 $page->assign('actuel', $alias);
54 //Si l'utilisateur vient de faire une damande
55 if (Env
::has('alias') and Env
::has('raison')) {
56 $alias = Env
::get('alias');
57 $raison = Env
::get('raison');
58 $public = (Env
::get('public', 'off') == 'on')?
"public":"private";
60 $page->assign('r_alias', $alias);
61 $page->assign('r_raison', $raison);
62 if ($public == 'public') {
63 $page->assign('r_public', true
);
66 //Quelques vérifications sur l'alias (caractères spéciaux)
67 if (!preg_match( "/^[a-zA-Z0-9\-.]{3,20}$/", $alias)) {
68 $page->trig("L'adresse demandée n'est pas valide.
69 Vérifie qu'elle comporte entre 3 et 20 caractères
70 et qu'elle ne contient que des lettres non accentuées,
71 des chiffres ou les caractères - et .");
74 //vérifier que l'alias n'est pas déja pris
75 $res = $globals->xdb
->query('SELECT COUNT(*) FROM virtual WHERE alias={?}', $alias.'@'.$globals->mail
->alias_dom
);
76 if ($res->fetchOneCell() > 0) {
77 $page->trig("L'alias $alias@{$globals->mail->alias_dom} a déja été attribué.
78 Tu ne peux donc pas l'obtenir.");
82 //vérifier que l'alias n'est pas déja en demande
83 $it = new ValidateIterator ();
84 while($req = $it->next()) {
85 if ($req->type
== "alias" and $req->alias
== $alias) {
86 $page->trig("L'alias $alias@{$globals->mail->alias_dom} a déja été demandé.
87 Tu ne peux donc pas l'obtenir pour l'instant.");
92 //Insertion de la demande dans la base, écrase les requêtes précédente
93 $myalias = new AliasReq($uid, $alias, $raison, $public);
95 $page->assign('success',$alias);
101 elseif ((Env
::get('visible') == 'public') && ($visibility != 'public')) {
102 $globals->xdb
->execute("UPDATE auth_user_quick SET emails_alias_pub = 'public' WHERE user_id = {?}", Session
::getInt('uid'));
103 $visibility = 'public';
107 elseif ((Env
::get('visible') == 'private') && ($visibility != 'private')) {
108 $globals->xdb
->execute("UPDATE auth_user_quick SET emails_alias_pub = 'private' WHERE user_id = {?}", Session
::getInt('uid'));
109 $visibility = 'private';
112 if ($visibility == 'public') {
113 $page->assign('mail_public', true
);