2 /***************************************************************************
3 * Copyright (C) 2003-2008 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 GoogleAppsModule
extends PLModule
27 if (!$globals->mailstorage
->googleapps_domain
) {
32 'googleapps' => $this->make_hook('index', AUTH_MDP
),
36 function handler_index(&$page, $action = null
, $subaction = null
)
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');
44 $account = new GoogleAppsAccount(S
::v('uid'), S
::v('forlife'));
46 // Fills up the 'is Google Apps redirection active' variable.
47 $page->assign('redirect_active', false
);
48 $page->assign('redirect_unique', true
);
50 if ($account->g_status
== 'active') {
51 $redirect = new Redirect(S
::v('uid'));
52 $page->assign('redirect_unique', !$redirect->other_active(NULL
));
54 $storage = new MailStorageGoogleApps(S
::v('uid'));
55 $page->assign('redirect_active', $storage->active());
58 // Updates the Google Apps account as required.
60 if ($action == 'password') {
61 if ($subaction == 'sync') {
62 $account->set_password_sync(true
);
63 $account->set_password(S
::v('password'));
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'));
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.");
76 $storage = new MailStorageGoogleApps(S
::v('uid'));
77 if ($storage->disable()) {
79 $page->trig("Ton compte Google Apps est dorénavant désactivé.");
81 $page->trig("Ton compte Google Apps est ta seule adresse de redirection. Ton compte ne peux pas être désactivé.");
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.");
89 if ($action == 'create') {
90 $page->assign('has_password_sync', Get
::has('password_sync'));
91 $page->assign('password_sync', Get
::b('password_sync', true
));
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');
97 $password = S
::v('password');
99 $password = Post
::v('response2');
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.");
107 $page->assign('account', $account);
111 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: