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 | |
22 | class PlatalModule extends PLModule |
23 | { |
24 | function handlers() |
25 | { |
26 | return array( |
7927d719 |
27 | 'prefs' => $this->make_hook('prefs', AUTH_COOKIE), |
28 | 'prefs/rss' => $this->make_hook('rss', AUTH_COOKIE), |
7c77c3ee |
29 | 'password' => $this->make_hook('password', AUTH_MDP), |
6c49d0af |
30 | 'tmpPWD' => $this->make_hook('tmpPWD', AUTH_PUBLIC), |
9bae6004 |
31 | 'skin' => $this->make_hook('skin', AUTH_COOKIE), |
e59506eb |
32 | ); |
33 | } |
34 | |
7927d719 |
35 | function __set_rss_state($state) |
36 | { |
37 | global $globals; |
38 | |
39 | if ($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')); |
45 | } else { |
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'); |
50 | } |
51 | } |
52 | |
e59506eb |
53 | function handler_prefs(&$page) |
54 | { |
55 | global $globals; |
56 | |
57 | $page->changeTpl('preferences.tpl'); |
58 | $page->assign('xorg_title','Polytechnique.org - Mes préférences'); |
59 | |
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' |
65 | WHERE user_id = {?}", |
66 | Session::getInt('uid')); |
67 | $_SESSION['mail_fmt'] = $fmt; |
68 | redirect('preferences'); |
69 | } |
70 | |
71 | if (Env::has('rss')) { |
7927d719 |
72 | $this->__set_rss_state(Env::getBool('rss')); |
e59506eb |
73 | } |
74 | |
75 | $page->assign('prefs', $globals->hook->prefs()); |
a2558f2b |
76 | |
77 | return PL_OK; |
e59506eb |
78 | } |
9bae6004 |
79 | |
7927d719 |
80 | function handler_rss(&$page) |
81 | { |
82 | global $globals; |
83 | |
84 | $page->changeTpl('filrss.tpl'); |
85 | |
86 | $page->assign('goback', Env::get('referer', 'login')); |
87 | |
88 | if (Env::get('act_rss') == 'Activer') { |
89 | $this->__set_rss_state(true); |
90 | $page->trig("Ton Fil RSS est activé."); |
91 | } |
92 | |
93 | return PL_OK; |
94 | } |
95 | |
7c77c3ee |
96 | function handler_password(&$page) |
97 | { |
98 | global $globals; |
99 | |
100 | if (Post::has('response2')) { |
101 | require_once 'secure_hash.inc.php'; |
102 | |
103 | $_SESSION['password'] = $password = Post::get('response2'); |
104 | |
105 | $globals->xdb->execute('UPDATE auth_user_md5 |
106 | SET password={?} |
107 | WHERE user_id={?}', $password, |
108 | Session::getInt('uid')); |
109 | |
110 | $log =& Session::getMixed('log'); |
111 | $log->log('passwd', ''); |
112 | |
113 | if (Cookie::get('ORGaccess')) { |
114 | setcookie('ORGaccess', hash_encrypt($password), (time()+25920000), '/', '' ,0); |
115 | } |
116 | |
117 | $page->changeTpl('motdepasse.success.tpl'); |
118 | $page->run(); |
119 | } |
120 | |
121 | $page->changeTpl('motdepasse.tpl'); |
122 | $page->addJsLink('javascript/motdepasse.js'); |
123 | $page->assign('xorg_title','Polytechnique.org - Mon mot de passe'); |
124 | |
125 | return PL_OK; |
126 | } |
127 | |
6c49d0af |
128 | function handler_tmpPWD(&$page, $certif = null) |
129 | { |
130 | global $globals; |
131 | |
132 | $globals->xdb->execute('DELETE FROM perte_pass |
133 | WHERE DATE_SUB(NOW(), INTERVAL 380 MINUTE) > created'); |
134 | |
135 | $res = $globals->xdb->query('SELECT uid FROM perte_pass WHERE certificat={?}', $certif); |
136 | $ligne = $res->fetchOneAssoc(); |
137 | if (!$ligne) { |
138 | $page->changeTpl('index.tpl'); |
139 | $page->kill("Cette adresse n'existe pas ou n'existe plus sur le serveur."); |
140 | } |
141 | |
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")', |
148 | $password, $uid); |
149 | $globals->xdb->query('DELETE FROM perte_pass WHERE certificat={?}', $certif); |
150 | $logger->log("passwd",""); |
151 | $page->changeTpl('tmpPWD.success.tpl'); |
152 | } else { |
153 | $page->changeTpl('motdepasse.tpl'); |
154 | $page->addJsLink('javascript/motdepasse.js'); |
155 | } |
156 | |
157 | return PL_OK; |
158 | } |
159 | |
9bae6004 |
160 | function handler_skin(&$page) |
161 | { |
162 | global $globals; |
163 | |
164 | if (!$globals->skin->enable) { |
f09cee18 |
165 | redirect('./'); |
9bae6004 |
166 | } |
f09cee18 |
167 | |
168 | $page->changeTpl('skins.tpl'); |
9bae6004 |
169 | $page->assign('xorg_title','Polytechnique.org - Skins'); |
170 | |
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')); |
176 | set_skin(); |
177 | } |
178 | |
179 | $sql = "SELECT s.*,auteur,count(*) AS nb |
180 | FROM skins AS s |
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)); |
185 | return PL_OK; |
186 | } |
e59506eb |
187 | } |
188 | |
189 | ?> |