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 // Preferences thingies
28 'prefs' => $this->make_hook('prefs', AUTH_COOKIE
),
29 'prefs/rss' => $this->make_hook('prefs_rss', AUTH_COOKIE
),
30 'skin' => $this->make_hook('skin', AUTH_COOKIE
),
32 // password related thingies
33 'password' => $this->make_hook('password', AUTH_MDP
),
34 'tmpPWD' => $this->make_hook('tmpPWD', AUTH_PUBLIC
),
36 // happenings related thingies
37 'rss' => $this->make_hook('rss', AUTH_PUBLIC
),
41 function __set_rss_state($state)
46 $_SESSION['core_rss_hash'] = rand_url_id(16);
47 $globals->xdb
->execute('UPDATE auth_user_quick
48 SET core_rss_hash={?} WHERE user_id={?}',
49 Session
::get('core_rss_hash'),
50 Session
::getInt('uid'));
52 $globals->xdb
->execute('UPDATE auth_user_quick
53 SET core_rss_hash="" WHERE user_id={?}',
54 Session
::getInt('uid'));
55 Session
::kill('core_rss_hash');
59 function handler_prefs(&$page)
63 $page->changeTpl('preferences.tpl');
64 $page->assign('xorg_title','Polytechnique.org - Mes préférences');
66 if (Env
::has('mail_fmt')) {
67 $fmt = Env
::get('mail_fmt');
68 if ($fmt != 'texte') $fmt = 'html';
69 $globals->xdb
->execute("UPDATE auth_user_quick
70 SET core_mail_fmt = '$fmt'
72 Session
::getInt('uid'));
73 $_SESSION['mail_fmt'] = $fmt;
74 redirect('preferences');
77 if (Env
::has('rss')) {
78 $this->__set_rss_state(Env
::getBool('rss'));
81 $page->assign('prefs', $globals->hook
->prefs());
86 function handler_prefs_rss(&$page)
90 $page->changeTpl('filrss.tpl');
92 $page->assign('goback', Env
::get('referer', 'login'));
94 if (Env
::get('act_rss') == 'Activer') {
95 $this->__set_rss_state(true
);
96 $page->trig("Ton Fil RSS est activé.");
102 function handler_password(&$page)
106 if (Post
::has('response2')) {
107 require_once 'secure_hash.inc.php';
109 $_SESSION['password'] = $password = Post
::get('response2');
111 $globals->xdb
->execute('UPDATE auth_user_md5
113 WHERE user_id={?}', $password,
114 Session
::getInt('uid'));
116 $log =& Session
::getMixed('log');
117 $log->log('passwd', '');
119 if (Cookie
::get('ORGaccess')) {
120 setcookie('ORGaccess', hash_encrypt($password), (time()+
25920000), '/', '' ,0);
123 $page->changeTpl('motdepasse.success.tpl');
127 $page->changeTpl('motdepasse.tpl');
128 $page->addJsLink('javascript/motdepasse.js');
129 $page->assign('xorg_title','Polytechnique.org - Mon mot de passe');
134 function handler_tmpPWD(&$page, $certif = null
)
138 $globals->xdb
->execute('DELETE FROM perte_pass
139 WHERE DATE_SUB(NOW(), INTERVAL 380 MINUTE) > created');
141 $res = $globals->xdb
->query('SELECT uid FROM perte_pass WHERE certificat={?}', $certif);
142 $ligne = $res->fetchOneAssoc();
144 $page->changeTpl('index.tpl');
145 $page->kill("Cette adresse n'existe pas ou n'existe plus sur le serveur.");
148 $uid = $ligne["uid"];
149 if (Post
::has('response2')) {
150 $password = Post
::get('response2');
151 $logger = new DiogenesCoreLogger($uid);
152 $globals->xdb
->query('UPDATE auth_user_md5 SET password={?}
153 WHERE user_id={?} AND perms IN("admin","user")',
155 $globals->xdb
->query('DELETE FROM perte_pass WHERE certificat={?}', $certif);
156 $logger->log("passwd","");
157 $page->changeTpl('tmpPWD.success.tpl');
159 $page->changeTpl('motdepasse.tpl');
160 $page->addJsLink('javascript/motdepasse.js');
166 function handler_skin(&$page)
170 if (!$globals->skin
->enable
) {
174 $page->changeTpl('skins.tpl');
175 $page->assign('xorg_title','Polytechnique.org - Skins');
177 if (Env
::has('newskin')) { // formulaire soumis, traitons les données envoyées
178 $globals->xdb
->execute('UPDATE auth_user_quick
179 SET skin={?} WHERE user_id={?}',
180 Env
::getInt('newskin'),
181 Session
::getInt('uid'));
185 $sql = "SELECT s.*,auteur,count(*) AS nb
187 LEFT JOIN auth_user_quick AS a ON s.id=a.skin
188 WHERE skin_tpl != '' AND ext != ''
189 GROUP BY id ORDER BY s.date DESC";
190 $page->assign_by_ref('skins', $globals->xdb
->iterator($sql));
194 function handler_rss(&$page, $user = null
, $hash = null
)
198 require_once 'rss.inc.php';
200 $uid = init_rss('rss.tpl', $user, $hash);
202 $rss = $globals->xdb
->iterator(
203 'SELECT e.id, e.titre, e.texte, e.creation_date
204 FROM auth_user_md5 AS u
205 INNER JOIN evenements AS e ON ( (e.promo_min = 0 || e.promo_min <= u.promo)
206 AND (e.promo_max = 0 || e.promo_max >= u.promo) )
207 WHERE u.user_id = {?} AND FIND_IN_SET(e.flags, "valide")
208 AND peremption >= NOW()', $uid);
209 $page->assign('rss', $rss);