Commit | Line | Data |
---|---|---|
bb0727ea VZ |
1 | <?php |
2 | /*************************************************************************** | |
3 | * Copyright (C) 2003-2008 Polytechnique.org * | |
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 GoogleAppsModule extends PLModule | |
23 | { | |
24 | function handlers() | |
25 | { | |
26 | global $globals; | |
27 | if (!$globals->mailstorage->googleapps_domain) { | |
28 | return array(); | |
29 | } | |
30 | ||
31 | return array( | |
32 | 'googleapps' => $this->make_hook('index', AUTH_MDP), | |
33 | ); | |
34 | } | |
35 | ||
36 | function handler_index(&$page, $action = null, $subaction = null) | |
37 | { | |
38 | require_once("emails.inc.php"); | |
39 | require_once("googleapps.inc.php"); | |
40 | $page->changeTpl('googleapps/index.tpl'); | |
41 | $page->addJsLink('motdepasse.js'); | |
42 | $page->assign('xorg_title', 'Polytechnique.org - Compte Google Apps'); | |
43 | ||
44 | $account = new GoogleAppsAccount(S::v('uid'), S::v('forlife')); | |
45 | ||
46 | // Fills up the 'is Google Apps redirection active' variable. | |
47 | $page->assign('redirect_active', false); | |
48 | $page->assign('redirect_unique', true); | |
49 | ||
50 | if ($account->g_status == 'active') { | |
51 | $redirect = new Redirect(S::v('uid')); | |
52 | $page->assign('redirect_unique', !$redirect->other_active(NULL)); | |
53 | ||
54 | $storage = new MailStorageGoogleApps(S::v('uid')); | |
55 | $page->assign('redirect_active', $storage->active()); | |
56 | } | |
57 | ||
58 | // Updates the Google Apps account as required. | |
59 | if ($action) { | |
60 | if ($action == 'password') { | |
61 | if ($subaction == 'sync') { | |
62 | $account->set_password_sync(true); | |
84270653 | 63 | $account->set_password(S::v('password')); |
bb0727ea VZ |
64 | $page->trig("Ton mot de passe Google Apps sera dorénavant synchronisé avec ton mot de passe Polytechnique.org."); |
65 | } else if ($subaction == 'nosync') { | |
66 | $account->set_password_sync(false); | |
67 | } else if (Post::has('response2') && !$account->sync_password) { | |
68 | $account->set_password(Post::v('response2')); | |
69 | } | |
70 | } | |
71 | ||
72 | if ($action == 'suspend' && Post::has('suspend') && $account->g_status == 'active') { | |
73 | if ($account->pending_update_suspension) { | |
74 | $page->trig("Ton compte est déjà en cours de désactivation."); | |
75 | } else { | |
76 | $storage = new MailStorageGoogleApps(S::v('uid')); | |
77 | if ($storage->disable()) { | |
78 | $account->suspend(); | |
79 | $page->trig("Ton compte Google Apps est dorénavant désactivé."); | |
80 | } else { | |
81 | $page->trig("Ton compte Google Apps est ta seule adresse de redirection. Ton compte ne peux pas être désactivé."); | |
82 | } | |
83 | } | |
84 | } elseif ($action == 'unsuspend' && Post::has('unsuspend') && $account->g_status == 'disabled') { | |
85 | $account->unsuspend(Post::b('redirect_mails', true)); | |
86 | $page->trig("Ta demande de réactivation a bien été prise en compte."); | |
87 | } | |
88 | ||
89 | if ($action == 'create') { | |
90 | $page->assign('has_password_sync', Get::has('password_sync')); | |
91 | $page->assign('password_sync', Get::b('password_sync', true)); | |
92 | } | |
93 | if ($action == 'create' && Post::has('password_sync') && Post::has('redirect_mails')) { | |
94 | $password_sync = Post::b('password_sync'); | |
95 | $redirect_mails = Post::b('redirect_mails'); | |
96 | if ($password_sync) { | |
84270653 | 97 | $password = S::v('password'); |
bb0727ea VZ |
98 | } else { |
99 | $password = Post::v('response2'); | |
100 | } | |
101 | ||
102 | $account->create($password_sync, $password, $redirect_mails); | |
103 | $page->trig("La demande de création de ton compte Google Apps a bien été enregistrée."); | |
104 | } | |
105 | } | |
106 | ||
107 | $page->assign('account', $account); | |
108 | } | |
109 | } | |
110 | ||
111 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
112 | ?> |