small details
[platal.git] / modules / platal.php
CommitLineData
e59506eb 1<?php
2/***************************************************************************
3 * Copyright (C) 2003-2006 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
22class PlatalModule extends PLModule
23{
24 function handlers()
25 {
26 return array(
27 'preferences' => $this->make_hook('prefs', AUTH_COOKIE),
9bae6004 28 'skin' => $this->make_hook('skin', AUTH_COOKIE),
e59506eb 29 );
30 }
31
32 function handler_prefs(&$page)
33 {
34 global $globals;
35
36 $page->changeTpl('preferences.tpl');
37 $page->assign('xorg_title','Polytechnique.org - Mes préférences');
38
39 if (Env::has('mail_fmt')) {
40 $fmt = Env::get('mail_fmt');
41 if ($fmt != 'texte') $fmt = 'html';
42 $globals->xdb->execute("UPDATE auth_user_quick
43 SET core_mail_fmt = '$fmt'
44 WHERE user_id = {?}",
45 Session::getInt('uid'));
46 $_SESSION['mail_fmt'] = $fmt;
47 redirect('preferences');
48 }
49
50 if (Env::has('rss')) {
51 if (Env::getBool('rss')) {
52 $_SESSION['core_rss_hash'] = rand_url_id(16);
53 $globals->xdb->execute('UPDATE auth_user_quick
54 SET core_rss_hash={?} WHERE user_id={?}',
55 Session::get('core_rss_hash'),
56 Session::getInt('uid'));
57 } else {
58 $globals->xdb->execute('UPDATE auth_user_quick
59 SET core_rss_hash="" WHERE user_id={?}',
60 Session::getInt('uid'));
61 Session::kill('core_rss_hash');
62 }
63 redirect('preferences');
64 }
65
66 $page->assign('prefs', $globals->hook->prefs());
a2558f2b 67
68 return PL_OK;
e59506eb 69 }
9bae6004 70
71 function handler_skin(&$page)
72 {
73 global $globals;
74
75 if (!$globals->skin->enable) {
f09cee18 76 redirect('./');
9bae6004 77 }
f09cee18 78
79 $page->changeTpl('skins.tpl');
9bae6004 80 $page->assign('xorg_title','Polytechnique.org - Skins');
81
82 if (Env::has('newskin')) { // formulaire soumis, traitons les données envoyées
83 $globals->xdb->execute('UPDATE auth_user_quick
84 SET skin={?} WHERE user_id={?}',
85 Env::getInt('newskin'),
86 Session::getInt('uid'));
87 set_skin();
88 }
89
90 $sql = "SELECT s.*,auteur,count(*) AS nb
91 FROM skins AS s
92 LEFT JOIN auth_user_quick AS a ON s.id=a.skin
93 WHERE skin_tpl != '' AND ext != ''
94 GROUP BY id ORDER BY s.date DESC";
95 $page->assign_by_ref('skins', $globals->xdb->iterator($sql));
96 return PL_OK;
97 }
e59506eb 98}
99
100?>