motdepasse -> password
[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),
7c77c3ee 28 'password' => $this->make_hook('password', AUTH_MDP),
9bae6004 29 'skin' => $this->make_hook('skin', AUTH_COOKIE),
e59506eb 30 );
31 }
32
33 function handler_prefs(&$page)
34 {
35 global $globals;
36
37 $page->changeTpl('preferences.tpl');
38 $page->assign('xorg_title','Polytechnique.org - Mes préférences');
39
40 if (Env::has('mail_fmt')) {
41 $fmt = Env::get('mail_fmt');
42 if ($fmt != 'texte') $fmt = 'html';
43 $globals->xdb->execute("UPDATE auth_user_quick
44 SET core_mail_fmt = '$fmt'
45 WHERE user_id = {?}",
46 Session::getInt('uid'));
47 $_SESSION['mail_fmt'] = $fmt;
48 redirect('preferences');
49 }
50
51 if (Env::has('rss')) {
52 if (Env::getBool('rss')) {
53 $_SESSION['core_rss_hash'] = rand_url_id(16);
54 $globals->xdb->execute('UPDATE auth_user_quick
55 SET core_rss_hash={?} WHERE user_id={?}',
56 Session::get('core_rss_hash'),
57 Session::getInt('uid'));
58 } else {
59 $globals->xdb->execute('UPDATE auth_user_quick
60 SET core_rss_hash="" WHERE user_id={?}',
61 Session::getInt('uid'));
62 Session::kill('core_rss_hash');
63 }
64 redirect('preferences');
65 }
66
67 $page->assign('prefs', $globals->hook->prefs());
a2558f2b 68
69 return PL_OK;
e59506eb 70 }
9bae6004 71
7c77c3ee 72 function handler_password(&$page)
73 {
74 global $globals;
75
76 if (Post::has('response2')) {
77 require_once 'secure_hash.inc.php';
78
79 $_SESSION['password'] = $password = Post::get('response2');
80
81 $globals->xdb->execute('UPDATE auth_user_md5
82 SET password={?}
83 WHERE user_id={?}', $password,
84 Session::getInt('uid'));
85
86 $log =& Session::getMixed('log');
87 $log->log('passwd', '');
88
89 if (Cookie::get('ORGaccess')) {
90 setcookie('ORGaccess', hash_encrypt($password), (time()+25920000), '/', '' ,0);
91 }
92
93 $page->changeTpl('motdepasse.success.tpl');
94 $page->run();
95 }
96
97 $page->changeTpl('motdepasse.tpl');
98 $page->addJsLink('javascript/motdepasse.js');
99 $page->assign('xorg_title','Polytechnique.org - Mon mot de passe');
100
101 return PL_OK;
102 }
103
9bae6004 104 function handler_skin(&$page)
105 {
106 global $globals;
107
108 if (!$globals->skin->enable) {
f09cee18 109 redirect('./');
9bae6004 110 }
f09cee18 111
112 $page->changeTpl('skins.tpl');
9bae6004 113 $page->assign('xorg_title','Polytechnique.org - Skins');
114
115 if (Env::has('newskin')) { // formulaire soumis, traitons les données envoyées
116 $globals->xdb->execute('UPDATE auth_user_quick
117 SET skin={?} WHERE user_id={?}',
118 Env::getInt('newskin'),
119 Session::getInt('uid'));
120 set_skin();
121 }
122
123 $sql = "SELECT s.*,auteur,count(*) AS nb
124 FROM skins AS s
125 LEFT JOIN auth_user_quick AS a ON s.id=a.skin
126 WHERE skin_tpl != '' AND ext != ''
127 GROUP BY id ORDER BY s.date DESC";
128 $page->assign_by_ref('skins', $globals->xdb->iterator($sql));
129 return PL_OK;
130 }
e59506eb 131}
132
133?>