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
),
35 'password/smtp' => $this->make_hook('smtppass', AUTH_MDP
),
37 // happenings related thingies
38 'rss' => $this->make_hook('rss', AUTH_PUBLIC
),
42 function __set_rss_state($state)
47 $_SESSION['core_rss_hash'] = rand_url_id(16);
48 $globals->xdb
->execute('UPDATE auth_user_quick
49 SET core_rss_hash={?} WHERE user_id={?}',
50 Session
::get('core_rss_hash'),
51 Session
::getInt('uid'));
53 $globals->xdb
->execute('UPDATE auth_user_quick
54 SET core_rss_hash="" WHERE user_id={?}',
55 Session
::getInt('uid'));
56 Session
::kill('core_rss_hash');
60 function handler_prefs(&$page)
64 $page->changeTpl('preferences.tpl');
65 $page->assign('xorg_title','Polytechnique.org - Mes préférences');
67 if (Env
::has('mail_fmt')) {
68 $fmt = Env
::get('mail_fmt');
69 if ($fmt != 'texte') $fmt = 'html';
70 $globals->xdb
->execute("UPDATE auth_user_quick
71 SET core_mail_fmt = '$fmt'
73 Session
::getInt('uid'));
74 $_SESSION['mail_fmt'] = $fmt;
75 redirect('preferences');
78 if (Env
::has('rss')) {
79 $this->__set_rss_state(Env
::getBool('rss'));
82 $page->assign('prefs', $globals->hook
->prefs());
87 function handler_prefs_rss(&$page)
91 $page->changeTpl('filrss.tpl');
93 $page->assign('goback', Env
::get('referer', 'login'));
95 if (Env
::get('act_rss') == 'Activer') {
96 $this->__set_rss_state(true
);
97 $page->trig("Ton Fil RSS est activé.");
103 function handler_password(&$page)
107 if (Post
::has('response2')) {
108 require_once 'secure_hash.inc.php';
110 $_SESSION['password'] = $password = Post
::get('response2');
112 $globals->xdb
->execute('UPDATE auth_user_md5
114 WHERE user_id={?}', $password,
115 Session
::getInt('uid'));
117 $log =& Session
::getMixed('log');
118 $log->log('passwd', '');
120 if (Cookie
::get('ORGaccess')) {
121 setcookie('ORGaccess', hash_encrypt($password), (time()+
25920000), '/', '' ,0);
124 $page->changeTpl('motdepasse.success.tpl');
128 $page->changeTpl('motdepasse.tpl');
129 $page->addJsLink('javascript/motdepasse.js');
130 $page->assign('xorg_title','Polytechnique.org - Mon mot de passe');
135 function handler_smtppass(&$page)
139 $page->changeTpl('acces_smtp.tpl');
140 $page->assign('xorg_title','Polytechnique.org - Acces SMTP/NNTP');
142 $uid = Session
::getInt('uid');
143 $pass = Env
::get('smtppass1');
144 $log = Session
::getMixed('log');
146 if (Env
::get('op') == "Valider" && strlen($pass) >= 6
147 && Env
::get('smtppass1') == Env
::get('smtppass2'))
149 $globals->xdb
->execute('UPDATE auth_user_md5 SET smtppass = {?}
150 WHERE user_id = {?}', $pass, $uid);
151 $page->trig('Mot de passe enregistré');
152 $log->log("passwd_ssl");
153 } elseif (Env
::get('op') == "Supprimer") {
154 $globals->xdb
->execute('UPDATE auth_user_md5 SET smtppass = ""
155 WHERE user_id = {?}', $uid);
156 $page->trig('Compte SMTP et NNTP supprimé');
157 $log->log("passwd_del");
160 $res = $globals->xdb
->query("SELECT IF(smtppass != '', 'actif', '')
162 WHERE user_id = {?}", $uid);
163 $page->assign('actif', $res->fetchOneCell());
168 function handler_tmpPWD(&$page, $certif = null
)
172 $globals->xdb
->execute('DELETE FROM perte_pass
173 WHERE DATE_SUB(NOW(), INTERVAL 380 MINUTE) > created');
175 $res = $globals->xdb
->query('SELECT uid FROM perte_pass WHERE certificat={?}', $certif);
176 $ligne = $res->fetchOneAssoc();
178 $page->changeTpl('index.tpl');
179 $page->kill("Cette adresse n'existe pas ou n'existe plus sur le serveur.");
182 $uid = $ligne["uid"];
183 if (Post
::has('response2')) {
184 $password = Post
::get('response2');
185 $logger = new DiogenesCoreLogger($uid);
186 $globals->xdb
->query('UPDATE auth_user_md5 SET password={?}
187 WHERE user_id={?} AND perms IN("admin","user")',
189 $globals->xdb
->query('DELETE FROM perte_pass WHERE certificat={?}', $certif);
190 $logger->log("passwd","");
191 $page->changeTpl('tmpPWD.success.tpl');
193 $page->changeTpl('motdepasse.tpl');
194 $page->addJsLink('javascript/motdepasse.js');
200 function handler_skin(&$page)
204 if (!$globals->skin
->enable
) {
208 $page->changeTpl('skins.tpl');
209 $page->assign('xorg_title','Polytechnique.org - Skins');
211 if (Env
::has('newskin')) { // formulaire soumis, traitons les données envoyées
212 $globals->xdb
->execute('UPDATE auth_user_quick
213 SET skin={?} WHERE user_id={?}',
214 Env
::getInt('newskin'),
215 Session
::getInt('uid'));
219 $sql = "SELECT s.*,auteur,count(*) AS nb
221 LEFT JOIN auth_user_quick AS a ON s.id=a.skin
222 WHERE skin_tpl != '' AND ext != ''
223 GROUP BY id ORDER BY s.date DESC";
224 $page->assign_by_ref('skins', $globals->xdb
->iterator($sql));
228 function handler_rss(&$page, $user = null
, $hash = null
)
232 require_once 'rss.inc.php';
234 $uid = init_rss('rss.tpl', $user, $hash);
236 $rss = $globals->xdb
->iterator(
237 'SELECT e.id, e.titre, e.texte, e.creation_date
238 FROM auth_user_md5 AS u
239 INNER JOIN evenements AS e ON ( (e.promo_min = 0 || e.promo_min <= u.promo)
240 AND (e.promo_max = 0 || e.promo_max >= u.promo) )
241 WHERE u.user_id = {?} AND FIND_IN_SET(e.flags, "valide")
242 AND peremption >= NOW()', $uid);
243 $page->assign('rss', $rss);