2 /***************************************************************************
3 * Copyright (C) 2003-2006 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 PlatalModule
extends PLModule
27 'prefs' => $this->make_hook('prefs', AUTH_COOKIE
),
28 'prefs/rss' => $this->make_hook('rss', AUTH_COOKIE
),
29 'password' => $this->make_hook('password', AUTH_MDP
),
30 'tmpPWD' => $this->make_hook('tmpPWD', AUTH_PUBLIC
),
31 'skin' => $this->make_hook('skin', AUTH_COOKIE
),
35 function __set_rss_state($state)
40 $_SESSION['core_rss_hash'] = rand_url_id(16);
41 $globals->xdb
->execute('UPDATE auth_user_quick
42 SET core_rss_hash={?} WHERE user_id={?}',
43 Session
::get('core_rss_hash'),
44 Session
::getInt('uid'));
46 $globals->xdb
->execute('UPDATE auth_user_quick
47 SET core_rss_hash="" WHERE user_id={?}',
48 Session
::getInt('uid'));
49 Session
::kill('core_rss_hash');
53 function handler_prefs(&$page)
57 $page->changeTpl('preferences.tpl');
58 $page->assign('xorg_title','Polytechnique.org - Mes préférences');
60 if (Env
::has('mail_fmt')) {
61 $fmt = Env
::get('mail_fmt');
62 if ($fmt != 'texte') $fmt = 'html';
63 $globals->xdb
->execute("UPDATE auth_user_quick
64 SET core_mail_fmt = '$fmt'
66 Session
::getInt('uid'));
67 $_SESSION['mail_fmt'] = $fmt;
68 redirect('preferences');
71 if (Env
::has('rss')) {
72 $this->__set_rss_state(Env
::getBool('rss'));
75 $page->assign('prefs', $globals->hook
->prefs());
80 function handler_rss(&$page)
84 $page->changeTpl('filrss.tpl');
86 $page->assign('goback', Env
::get('referer', 'login'));
88 if (Env
::get('act_rss') == 'Activer') {
89 $this->__set_rss_state(true
);
90 $page->trig("Ton Fil RSS est activé.");
96 function handler_password(&$page)
100 if (Post
::has('response2')) {
101 require_once 'secure_hash.inc.php';
103 $_SESSION['password'] = $password = Post
::get('response2');
105 $globals->xdb
->execute('UPDATE auth_user_md5
107 WHERE user_id={?}', $password,
108 Session
::getInt('uid'));
110 $log =& Session
::getMixed('log');
111 $log->log('passwd', '');
113 if (Cookie
::get('ORGaccess')) {
114 setcookie('ORGaccess', hash_encrypt($password), (time()+
25920000), '/', '' ,0);
117 $page->changeTpl('motdepasse.success.tpl');
121 $page->changeTpl('motdepasse.tpl');
122 $page->addJsLink('javascript/motdepasse.js');
123 $page->assign('xorg_title','Polytechnique.org - Mon mot de passe');
128 function handler_tmpPWD(&$page, $certif = null
)
132 $globals->xdb
->execute('DELETE FROM perte_pass
133 WHERE DATE_SUB(NOW(), INTERVAL 380 MINUTE) > created');
135 $res = $globals->xdb
->query('SELECT uid FROM perte_pass WHERE certificat={?}', $certif);
136 $ligne = $res->fetchOneAssoc();
138 $page->changeTpl('index.tpl');
139 $page->kill("Cette adresse n'existe pas ou n'existe plus sur le serveur.");
142 $uid = $ligne["uid"];
143 if (Post
::has('response2')) {
144 $password = Post
::get('response2');
145 $logger = new DiogenesCoreLogger($uid);
146 $globals->xdb
->query('UPDATE auth_user_md5 SET password={?}
147 WHERE user_id={?} AND perms IN("admin","user")',
149 $globals->xdb
->query('DELETE FROM perte_pass WHERE certificat={?}', $certif);
150 $logger->log("passwd","");
151 $page->changeTpl('tmpPWD.success.tpl');
153 $page->changeTpl('motdepasse.tpl');
154 $page->addJsLink('javascript/motdepasse.js');
160 function handler_skin(&$page)
164 if (!$globals->skin
->enable
) {
168 $page->changeTpl('skins.tpl');
169 $page->assign('xorg_title','Polytechnique.org - Skins');
171 if (Env
::has('newskin')) { // formulaire soumis, traitons les données envoyées
172 $globals->xdb
->execute('UPDATE auth_user_quick
173 SET skin={?} WHERE user_id={?}',
174 Env
::getInt('newskin'),
175 Session
::getInt('uid'));
179 $sql = "SELECT s.*,auteur,count(*) AS nb
181 LEFT JOIN auth_user_quick AS a ON s.id=a.skin
182 WHERE skin_tpl != '' AND ext != ''
183 GROUP BY id ORDER BY s.date DESC";
184 $page->assign_by_ref('skins', $globals->xdb
->iterator($sql));