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