86f0a6af |
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 AdminModule extends PLModule |
23 | { |
24 | function handlers() |
25 | { |
26 | return array( |
27 | 'admin' => $this->make_hook('default', AUTH_MDP, 'admin'), |
e7ae7df9 |
28 | 'admin/auth-groupes-x' => $this->make_hook('authgroupesx', AUTH_MDP, 'admin'), |
86f0a6af |
29 | 'admin/ax-xorg' => $this->make_hook('ax_xorg', AUTH_MDP, 'admin'), |
e7ae7df9 |
30 | 'admin/binets' => $this->make_hook('binets', AUTH_MDP, 'admin'), |
86f0a6af |
31 | 'admin/deaths' => $this->make_hook('deaths', AUTH_MDP, 'admin'), |
e7ae7df9 |
32 | 'admin/medals' => $this->make_hook('medals', AUTH_MDP, 'admin'), |
33 | 'admin/downtime' => $this->make_hook('downtime', AUTH_MDP, 'admin'), |
86f0a6af |
34 | 'admin/events' => $this->make_hook('events', AUTH_MDP, 'admin'), |
35 | 'admin/formations' => $this->make_hook('formations', AUTH_MDP, 'admin'), |
86f0a6af |
36 | 'admin/geoloc' => $this->make_hook('geoloc', AUTH_MDP, 'admin'), |
37 | 'admin/geoloc/dynamap' => $this->make_hook('geoloc_dynamap', AUTH_MDP, 'admin'), |
e7ae7df9 |
38 | 'admin/groupes-x' => $this->make_hook('groupesx', AUTH_MDP, 'admin'), |
39 | 'admin/homonyms' => $this->make_hook('homonyms', AUTH_MDP, 'admin'), |
40 | 'admin/lists' => $this->make_hook('lists', AUTH_MDP, 'admin'), |
41 | 'admin/logger' => $this->make_hook('logger', AUTH_MDP, 'admin'), |
42 | 'admin/logger/actions' => $this->make_hook('logger_actions', AUTH_MDP, 'admin'), |
43 | 'admin/newsletter' => $this->make_hook('newsletter', AUTH_MDP, 'admin'), |
44 | 'admin/newsletter/categories' => $this->make_hook('newsletter_cat', AUTH_MDP, 'admin'), |
45 | 'admin/newsletter/edit' => $this->make_hook('newsletter_edit', AUTH_MDP, 'admin'), |
46 | 'admin/payments' => $this->make_hook('payments', AUTH_MDP, 'admin'), |
47 | 'admin/postfix/blacklist' => $this->make_hook('postfix_blacklist', AUTH_MDP, 'admin'), |
48 | 'admin/postfix/delayed' => $this->make_hook('postfix_delayed', AUTH_MDP, 'admin'), |
49 | 'admin/postfix/regexp_bounces' => $this->make_hook('postfix_regexpsbounces', AUTH_MDP, 'admin'), |
50 | 'admin/postfix/whitelist' => $this->make_hook('postfix_whitelist', AUTH_MDP, 'admin'), |
51 | 'admin/skins' => $this->make_hook('skins', AUTH_MDP, 'admin'), |
52 | 'admin/synchro_ax' => $this->make_hook('synchro_ax', AUTH_MDP, 'admin'), |
86f0a6af |
53 | 'admin/trombino' => $this->make_hook('trombino', AUTH_MDP, 'admin'), |
e7ae7df9 |
54 | 'admin/user' => $this->make_hook('user', AUTH_MDP, 'admin'), |
55 | 'admin/validate' => $this->make_hook('validate', AUTH_MDP, 'admin'), |
3aec1c21 |
56 | 'admin/wiki' => $this->make_hook('wiki', AUTH_MDP, 'admin'), |
86f0a6af |
57 | ); |
58 | } |
59 | |
60 | function handler_default(&$page) |
61 | { |
62 | $page->changeTpl('admin/index.tpl'); |
63 | $page->assign('xorg_title','Polytechnique.org - Administration'); |
64 | } |
65 | |
66 | function handler_postfix_delayed(&$page) |
67 | { |
68 | $page->changeTpl('admin/postfix_delayed.tpl'); |
69 | $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Retardés'); |
70 | |
71 | if (Env::has('del')) { |
72 | $crc = Env::v('crc'); |
73 | XDB::execute("UPDATE postfix_mailseen SET release = 'del' WHERE crc = {?}", $crc); |
74 | $page->trig($crc." verra tous ses mails supprimés !"); |
75 | } elseif (Env::has('ok')) { |
76 | $crc = Env::v('crc'); |
77 | XDB::execute("UPDATE postfix_mailseen SET release = 'ok' WHERE crc = {?}", $crc); |
78 | $page->trig($crc." a le droit de passer !"); |
79 | } |
80 | |
81 | $sql = XDB::iterator( |
82 | "SELECT crc, nb, update_time, create_time, |
83 | FIND_IN_SET('del', release) AS del, |
84 | FIND_IN_SET('ok', release) AS ok |
85 | FROM postfix_mailseen |
86 | WHERE nb >= 30 |
87 | ORDER BY release != ''"); |
88 | |
89 | $page->assign_by_ref('mails', $sql); |
90 | } |
91 | |
92 | function handler_postfix_regexpsbounces(&$page, $new = null) { |
93 | $page->changeTpl('admin/emails_bounces_re.tpl'); |
94 | $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Regexps Bounces'); |
95 | $page->assign('new', $new); |
96 | |
97 | if (Post::has('submit')) { |
98 | foreach (Env::v('lvl') as $id=>$val) { |
99 | XDB::query( |
100 | "REPLACE INTO emails_bounces_re (id,pos,lvl,re,text) VALUES ({?}, {?}, {?}, {?}, {?})", |
101 | $id, $_POST['pos'][$id], $_POST['lvl'][$id], $_POST['re'][$id], $_POST['text'][$id] |
102 | ); |
103 | } |
104 | } |
105 | |
106 | $page->assign('bre', XDB::iterator("SELECT * FROM emails_bounces_re ORDER BY pos")); |
107 | } |
108 | |
109 | function handler_logger(&$page) { |
110 | $page->changeTpl('logger-view.tpl'); |
111 | $page->assign('xorg_title','Polytechnique.org - Administration - Logs des sessions'); |
112 | require_once('diogenes/diogenes.logger-view.inc.php'); |
113 | |
114 | if (!Env::has('logauth')) { |
115 | $_REQUEST['logauth'] = 'native'; |
116 | } |
117 | |
118 | $logview = new DiogenesLoggerView; |
119 | $logview->run($page); |
120 | |
121 | $page->fakeDiogenes(); |
122 | } |
123 | |
124 | function handler_user(&$page, $login = false) { |
125 | $page->changeTpl('admin/utilisateurs.tpl'); |
126 | $page->assign('xorg_title','Polytechnique.org - Administration - Edit/Su/Log'); |
127 | require_once("emails.inc.php"); |
128 | require_once("user.func.inc.php"); |
129 | |
130 | if (S::has('suid')) { |
131 | $page->kill("déjà en SUID !!!"); |
132 | } |
133 | |
134 | if (Env::has('user_id')) { |
135 | $login = get_user_login(Env::i('user_id')); |
136 | } elseif (Env::has('login')) { |
137 | $login = get_user_login(Env::v('login')); |
138 | } |
139 | |
140 | if(Env::has('logs_button') && $login) { |
141 | pl_redirect("admin/logger?login=$login&year=".date('Y')."&month=".date('m')); |
142 | } |
143 | |
144 | if (Env::has('ax_button') && $login) { |
145 | pl_redirect("admin/synchro_ax/$login"); |
146 | } |
147 | |
148 | if(Env::has('suid_button') && $login) { |
149 | $_SESSION['log']->log("suid_start", "login by ".S::v('forlife')); |
150 | $_SESSION['suid'] = $_SESSION; |
151 | $r = XDB::query("SELECT id FROM aliases WHERE alias={?}", $login); |
152 | if($uid = $r->fetchOneCell()) { |
153 | start_connexion($uid,true); |
154 | pl_redirect(""); |
155 | } |
156 | } |
157 | |
158 | if ($login) { |
159 | $r = XDB::query("SELECT *, a.alias AS forlife, u.flags AS sexe |
160 | FROM auth_user_md5 AS u |
161 | INNER JOIN aliases AS a ON ( a.id = u.user_id AND a.alias={?} AND type!='homonyme' )", $login); |
162 | $mr = $r->fetchOneAssoc(); |
163 | |
164 | $redirect = new Redirect($mr['user_id']); |
165 | |
166 | // Check if there was a submission |
167 | foreach($_POST as $key => $val) { |
168 | switch ($key) { |
169 | case "add_fwd": |
170 | $email = trim(Env::v('email')); |
171 | if (!isvalid_email_redirection($email)) { |
172 | $page->trig("invalid email $email"); |
173 | } else { |
174 | $redirect->add_email($email); |
175 | $page->trig("Ajout de $email effectué"); |
176 | } |
177 | break; |
178 | |
179 | case "del_fwd": |
180 | if (!empty($val)) { |
181 | $redirect->delete_email($val); |
182 | } |
183 | break; |
184 | |
185 | case "del_alias": |
186 | if (!empty($val)) { |
187 | XDB::execute("DELETE FROM aliases WHERE id={?} AND alias={?} |
188 | AND type!='a_vie' AND type!='homonyme'", $mr['user_id'], $val); |
189 | fix_bestalias($mr['user_id']); |
190 | $page->trig($val." a été supprimé"); |
191 | } |
192 | break; |
193 | case "activate_fwd": |
194 | if (!empty($val)) { |
195 | $redirect->modify_one_email($val, true); |
196 | } |
197 | break; |
198 | case "deactivate_fwd": |
199 | if (!empty($val)) { |
200 | $redirect->modify_one_email($val, false); |
201 | } |
202 | break; |
203 | case "add_alias": |
204 | XDB::execute("INSERT INTO aliases (id,alias,type) VALUES ({?}, {?}, 'alias')", |
205 | $mr['user_id'], Env::v('email')); |
206 | break; |
207 | |
208 | case "best": |
209 | // 'bestalias' is the first bit of the set : 1 |
210 | // 255 is the max for flags (8 sets max) |
211 | XDB::execute("UPDATE aliases SET flags= flags & (255 - 1) WHERE id={?}", $mr['user_id']); |
212 | XDB::execute("UPDATE aliases |
213 | SET flags= flags | 1 |
214 | WHERE id={?} AND alias={?}", $mr['user_id'], $val); |
215 | break; |
216 | |
217 | |
218 | // Editer un profil |
219 | case "u_edit": |
220 | require_once('secure_hash.inc.php'); |
221 | $pass_encrypted = Env::v('newpass_clair') != "********" ? hash_encrypt(Env::v('newpass_clair')) : Env::v('passw'); |
222 | $naiss = Env::v('naissanceN'); |
34ffe99a |
223 | $deces = Env::v('decesN'); |
86f0a6af |
224 | $perms = Env::v('permsN'); |
225 | $prenm = Env::v('prenomN'); |
226 | $nom = Env::v('nomN'); |
227 | $promo = Env::i('promoN'); |
228 | $sexe = Env::v('sexeN'); |
229 | $comm = Env::v('commentN'); |
230 | |
231 | $query = "UPDATE auth_user_md5 SET |
232 | naissance = '$naiss', |
34ffe99a |
233 | deces = '$deces', |
86f0a6af |
234 | password = '$pass_encrypted', |
235 | perms = '$perms', |
236 | prenom = '".addslashes($prenm)."', |
237 | nom = '".addslashes($nom)."', |
238 | flags = '$sexe', |
239 | promo = $promo, |
240 | comment = '".addslashes($comm)."' |
241 | WHERE user_id = '{$mr['user_id']}'"; |
242 | if (XDB::execute($query)) { |
243 | user_reindex($mr['user_id']); |
244 | |
245 | require_once("diogenes/diogenes.hermes.inc.php"); |
246 | $mailer = new HermesMailer(); |
247 | $mailer->setFrom("webmaster@polytechnique.org"); |
248 | $mailer->addTo("web@polytechnique.org"); |
249 | $mailer->setSubject("INTERVENTION de ".S::v('forlife')); |
250 | $mailer->setTxtBody(preg_replace("/[ \t]+/", ' ', $query)); |
251 | $mailer->send(); |
252 | |
253 | $page->trig("updaté correctement."); |
254 | } |
255 | if (Env::v('nomusageN') != $mr['nom_usage']) { |
256 | require_once('nomusage.inc.php'); |
257 | set_new_usage($mr['user_id'], Env::v('nomusageN'), make_username(Env::v('prenomN'), Env::v('nomusageN'))); |
258 | } |
259 | $r = XDB::query("SELECT *, a.alias AS forlife, u.flags AS sexe |
260 | FROM auth_user_md5 AS u |
261 | INNER JOIN aliases AS a ON (u.user_id=a.id) |
262 | WHERE user_id = {?}", $mr['user_id']); |
263 | $mr = $r->fetchOneAssoc(); |
264 | break; |
265 | |
266 | // DELETE FROM auth_user_md5 |
267 | case "u_kill": |
268 | user_clear_all_subs($mr['user_id']); |
269 | $page->trig("'{$mr['user_id']}' a été désinscrit !"); |
270 | require_once("diogenes/diogenes.hermes.inc.php"); |
271 | $mailer = new HermesMailer(); |
272 | $mailer->setFrom("webmaster@polytechnique.org"); |
273 | $mailer->addTo("web@polytechnique.org"); |
274 | $mailer->setSubject("INTERVENTION de ".S::v('forlife')); |
275 | $mailer->setTxtBody("\nUtilisateur $login effacé"); |
276 | $mailer->send(); |
277 | break; |
278 | } |
279 | } |
280 | |
281 | $res = XDB::query("SELECT UNIX_TIMESTAMP(start), host |
282 | FROM logger.sessions |
283 | WHERE uid={?} AND suid=0 |
284 | ORDER BY start DESC |
285 | LIMIT 1", $mr['user_id']); |
286 | list($lastlogin,$host) = $res->fetchOneRow(); |
287 | $page->assign('lastlogin', $lastlogin); |
288 | $page->assign('host', $host); |
289 | |
290 | $page->assign('aliases', XDB::iterator( |
291 | "SELECT alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire |
292 | FROM aliases |
293 | WHERE id = {?} AND type!='homonyme' |
294 | ORDER BY type!= 'a_vie'", $mr["user_id"])); |
295 | $page->assign('xorgmails', $xorgmails); |
296 | $page->assign('email_panne', $email_panne); |
297 | $page->assign('emails',$redirect->emails); |
298 | |
299 | $page->assign('mr',$mr); |
300 | } |
301 | } |
302 | function handler_homonyms(&$page, $op = 'list', $target = null) { |
303 | $page->changeTpl('admin/homonymes.tpl'); |
304 | $page->assign('xorg_title','Polytechnique.org - Administration - Homonymes'); |
305 | require_once("homonymes.inc.php"); |
306 | |
307 | if ($target) { |
308 | if (! list($prenom,$nom,$forlife,$loginbis) = select_if_homonyme($target)) { |
309 | $target=0; |
310 | } else { |
311 | $page->assign('nom',$nom); |
312 | $page->assign('prenom',$prenom); |
313 | $page->assign('forlife',$forlife); |
314 | $page->assign('loginbis',$loginbis); |
315 | } |
316 | } |
317 | |
318 | $page->assign('op',$op); |
319 | $page->assign('target',$target); |
320 | |
321 | // on a un $target valide, on prepare les mails |
322 | if ($target) { |
323 | |
324 | // on examine l'op a effectuer |
325 | switch ($op) { |
326 | case 'mail': |
327 | send_warning_homonyme($prenom, $nom, $forlife, $loginbis); |
328 | switch_bestalias($target, $loginbis); |
329 | $op = 'list'; |
330 | break; |
331 | case 'correct': |
332 | switch_bestalias($target, $loginbis); |
333 | XDB::execute("UPDATE aliases SET type='homonyme',expire=NOW() WHERE alias={?}", $loginbis); |
334 | XDB::execute("REPLACE INTO homonymes (homonyme_id,user_id) VALUES({?},{?})", $target, $target); |
335 | send_robot_homonyme($prenom, $nom, $forlife, $loginbis); |
336 | $op = 'list'; |
337 | break; |
338 | } |
339 | } |
340 | |
341 | if ($op == 'list') { |
342 | $res = XDB::iterator( |
343 | "SELECT a.alias AS homonyme,s.id AS user_id,s.alias AS forlife, |
344 | promo,prenom,nom, |
345 | IF(h.homonyme_id=s.id, a.expire, NULL) AS expire, |
346 | IF(h.homonyme_id=s.id, a.type, NULL) AS type |
347 | FROM aliases AS a |
348 | LEFT JOIN homonymes AS h ON (h.homonyme_id = a.id) |
349 | INNER JOIN aliases AS s ON (s.id = h.user_id AND s.type='a_vie') |
350 | INNER JOIN auth_user_md5 AS u ON (s.id=u.user_id) |
351 | WHERE a.type='homonyme' OR a.expire!='' |
352 | ORDER BY a.alias,promo"); |
353 | $hnymes = Array(); |
354 | while ($tab = $res->next()) { |
355 | $hnymes[$tab['homonyme']][] = $tab; |
356 | } |
357 | $page->assign_by_ref('hnymes',$hnymes); |
358 | } |
359 | } |
360 | |
361 | function handler_ax_xorg(&$page) { |
362 | $page->changeTpl('admin/ax-xorg.tpl'); |
363 | $page->assign('xorg_title','Polytechnique.org - Administration - AX/X.org'); |
364 | |
365 | // liste des différences |
366 | $res = XDB::query( |
367 | 'SELECT u.promo,u.nom AS nom,u.prenom AS prenom,ia.nom AS nomax,ia.prenom AS prenomax,u.matricule AS mat,ia.matricule_ax AS matax |
368 | FROM auth_user_md5 AS u |
369 | INNER JOIN identification_ax AS ia ON u.matricule_ax = ia.matricule_ax |
370 | WHERE (SOUNDEX(u.nom) != SOUNDEX(ia.nom) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom) |
371 | AND SOUNDEX(u.nom) != SOUNDEX(ia.nom_patro) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom_patro)) |
372 | OR u.prenom != ia.prenom OR (u.promo != ia.promo AND u.promo != ia.promo+1 AND u.promo != ia.promo-1) |
373 | ORDER BY u.promo,u.nom,u.prenom'); |
374 | $page->assign('diffs', $res->fetchAllAssoc()); |
375 | |
376 | // gens à l'ax mais pas chez nous |
377 | $res = XDB::query( |
378 | 'SELECT ia.promo,ia.nom,ia.nom_patro,ia.prenom |
379 | FROM identification_ax as ia |
380 | LEFT JOIN auth_user_md5 AS u ON u.matricule_ax = ia.matricule_ax |
381 | WHERE u.nom IS NULL'); |
382 | $page->assign('mank', $res->fetchAllAssoc()); |
383 | |
384 | // gens chez nous et pas à l'ax |
385 | $res = XDB::query('SELECT promo,nom,prenom FROM auth_user_md5 WHERE matricule_ax IS NULL'); |
386 | $page->assign('plus', $res->fetchAllAssoc()); |
387 | } |
388 | |
389 | function handler_deaths(&$page, $promo = 0, $validate = false) { |
390 | $page->changeTpl('admin/deces_promo.tpl'); |
391 | $page->assign('xorg_title','Polytechnique.org - Administration - Deces'); |
392 | |
393 | if (!$promo) |
394 | $promo = Env::i('promo'); |
395 | if (Env::has('sub10')) $promo -= 10; |
396 | if (Env::has('sub01')) $promo -= 1; |
397 | if (Env::has('add01')) $promo += 1; |
398 | if (Env::has('add10')) $promo += 10; |
399 | |
400 | $page->assign('promo',$promo); |
401 | |
402 | if ($validate) { |
403 | $new_deces = array(); |
404 | $res = XDB::iterRow("SELECT user_id,matricule,nom,prenom,deces FROM auth_user_md5 WHERE promo = {?}", $promo); |
405 | while (list($uid,$mat,$nom,$prenom,$deces) = $res->next()) { |
406 | $val = Env::v($mat); |
407 | if($val == $deces || empty($val)) continue; |
408 | XDB::execute('UPDATE auth_user_md5 SET deces={?} WHERE matricule = {?}', $val, $mat); |
409 | $new_deces[] = array('name' => "$prenom $nom", 'date' => "$val"); |
410 | if($deces=='0000-00-00' or empty($deces)) { |
411 | require_once('notifs.inc.php'); |
412 | register_watch_op($uid, WATCH_DEATH, $val); |
413 | require_once('user.func.inc.php'); |
414 | user_clear_all_subs($uid, false); // by default, dead ppl do not loose their email |
415 | } |
416 | } |
417 | $page->assign('new_deces',$new_deces); |
418 | } |
419 | |
420 | $res = XDB::iterator('SELECT matricule, nom, prenom, deces FROM auth_user_md5 WHERE promo = {?} ORDER BY nom,prenom', $promo); |
421 | $page->assign('decedes', $res); |
422 | } |
423 | |
424 | function handler_synchro_ax(&$page, $user = null, $action = null) { |
425 | $page->changeTpl('admin/synchro_ax.tpl'); |
426 | $page->assign('xorg_title','Polytechnique.org - Administration - Synchro AX'); |
427 | |
428 | require_once('synchro_ax.inc.php'); |
429 | |
430 | if (is_ax_key_missing()) { |
431 | $page->assign('no_private_key', true); |
432 | $page->run(); |
433 | } |
434 | |
435 | require_once('user.func.inc.php'); |
436 | |
437 | if ($user) |
438 | $login = get_user_forlife($user); |
439 | |
440 | if (Env::has('user')) { |
441 | $login = get_user_forlife(Env::v('user')); |
442 | if ($login === false) { |
443 | return; |
444 | } |
445 | } |
446 | |
447 | if (Env::has('mat')) { |
448 | $res = XDB::query( |
449 | "SELECT alias |
450 | FROM aliases AS a |
451 | INNER JOIN auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie') |
452 | WHERE matricule={?}", Env::i('mat')); |
453 | $login = $res->fetchOneCell(); |
454 | } |
455 | |
456 | if ($login) { |
457 | if ($action == 'import') { |
458 | ax_synchronize($login, S::v('uid')); |
459 | } |
460 | // get details from user, but looking only info that can be seen by ax |
461 | $user = get_user_details($login, S::v('uid'), 'ax'); |
462 | $userax= get_user_ax($user['matricule_ax']); |
463 | require_once 'profil.func.inc.php'; |
464 | $diff = diff_user_details($userax, $user, 'ax'); |
465 | |
466 | $page->assign('x', $user); |
467 | $page->assign('diff', $diff); |
468 | } |
469 | } |
470 | |
471 | function handler_events(&$page, $arch) { |
472 | $page->changeTpl('admin/evenements.tpl'); |
473 | $page->assign('xorg_title','Polytechnique.org - Administration - Evenements'); |
474 | |
475 | $arch = $arch == 'archives'; |
476 | $evid = Post::i('evt_id'); |
477 | $page->assign('arch', $arch); |
478 | |
479 | switch(Post::v('action')) { |
480 | case "Proposer": |
481 | XDB::execute('UPDATE evenements SET titre={?}, texte={?}, peremption={?}, promo_min={?}, promo_max={?} WHERE id = {?}', |
482 | Post::v('titre'), Post::v('texte'), Post::v('peremption'), Post::v('promo_min'), Post::v('promo_max'), $evid); |
483 | break; |
484 | |
485 | case "Valider": |
486 | XDB::execute('UPDATE evenements SET creation_date = creation_date, flags = CONCAT(flags,",valide") WHERE id = {?}', $evid); |
487 | break; |
488 | |
489 | case "Invalider": |
490 | XDB::execute('UPDATE evenements SET creation_date = creation_date, flags = REPLACE(flags,"valide", "") WHERE id = {?}', $evid); |
491 | break; |
492 | |
493 | case "Supprimer": |
494 | XDB::execute('DELETE from evenements WHERE id = {?}', $evid); |
495 | break; |
496 | |
497 | case "Archiver": |
498 | XDB::execute('UPDATE evenements SET creation_date = creation_date, flags = CONCAT(flags,",archive") WHERE id = {?}', $evid); |
499 | break; |
500 | |
501 | case "Desarchiver": |
502 | XDB::execute('UPDATE evenements SET creation_date = creation_date, flags = REPLACE(flags,"archive","") WHERE id = {?}', $evid); |
503 | break; |
504 | |
505 | case "Editer": |
506 | $res = XDB::query('SELECT titre, texte, peremption, promo_min, promo_max FROM evenements WHERE id={?}', $evid); |
507 | list($titre, $texte, $peremption, $promo_min, $promo_max) = $res->fetchOneRow(); |
508 | $page->assign('mode', 'edit'); |
509 | $page->assign('titre',$titre); |
510 | $page->assign('texte',$texte); |
511 | $page->assign('promo_min',$promo_min); |
512 | $page->assign('promo_max',$promo_max); |
513 | $page->assign('peremption',$peremption); |
514 | |
515 | $select = ""; |
516 | for ($i = 1 ; $i < 30 ; $i++) { |
517 | $p_stamp=date("Ymd",time()+3600*24*$i); |
518 | $year=substr($p_stamp,0,4); |
519 | $month=substr($p_stamp,4,2); |
520 | $day=substr($p_stamp,6,2); |
521 | |
522 | $select .= "<option value=\"$p_stamp\"" . (($p_stamp == strtr($peremption, array("-" => ""))) ? " selected" : "")."> $day / $month / $year</option>\n"; |
523 | } |
524 | $page->assign('select',$select); |
525 | |
526 | break; |
527 | } |
528 | |
529 | if ($action != "Editer") { |
530 | |
531 | $sql = "SELECT e.id, e.titre, e.texte, |
532 | DATE_FORMAT(e.creation_date,'%d/%m/%Y %T') AS creation_date, |
533 | DATE_FORMAT(e.peremption,'%d/%m/%Y') AS peremption, |
534 | e.promo_min, e.promo_max, |
535 | FIND_IN_SET('valide', e.flags) AS fvalide, |
536 | FIND_IN_SET('archive', e.flags) AS farch, |
537 | u.promo, u.nom, u.prenom, a.alias AS forlife |
538 | FROM evenements AS e |
539 | INNER JOIN auth_user_md5 AS u ON(e.user_id = u.user_id) |
540 | INNER JOIN aliases AS a ON (u.user_id = a.id AND a.type='a_vie') |
541 | WHERE ".($arch ? "" : "!")."FIND_IN_SET('archive',e.flags) |
542 | ORDER BY FIND_IN_SET('valide',e.flags), peremption"; |
543 | $page->assign('evs', XDB::iterator($sql)); |
544 | } |
545 | } |
546 | |
547 | function handler_newsletter(&$page, $new = false) { |
548 | $page->changeTpl('admin/newsletter.tpl'); |
549 | $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : liste'); |
550 | require_once("newsletter.inc.php"); |
551 | |
552 | if($new) { |
553 | insert_new_nl(); |
554 | pl_redirect("admin/newsletter"); |
555 | } |
556 | |
557 | $page->assign_by_ref('nl_list', get_nl_slist()); |
558 | } |
559 | |
560 | function handler_newsletter_edit(&$page, $nid = 'last', $aid = null, $action = 'edit') { |
561 | $page->changeTpl('admin/newsletter_edit.tpl'); |
562 | $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : Edition'); |
563 | require_once("newsletter.inc.php"); |
564 | |
565 | $nl = new NewsLetter($nid); |
566 | |
567 | if($action == 'delete') { |
568 | $nl->delArticle($aid); |
569 | pl_redirect("admin/newsletter/edit/$nid"); |
570 | } |
571 | |
572 | if($aid == 'update') { |
573 | $nl->_title = Post::v('title'); |
574 | $nl->_date = Post::v('date'); |
575 | $nl->_head = Post::v('head'); |
576 | $nl->save(); |
577 | } |
578 | |
579 | if(Post::v('save')) { |
580 | $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'), |
581 | $aid, Post::v('cid'), Post::v('pos')); |
582 | $nl->saveArticle($art); |
583 | pl_redirect("admin/newsletter/edit/$nid"); |
584 | } |
585 | |
586 | if($action == 'edit') { |
587 | $eaid = $aid; |
588 | if(Post::has('title')) { |
589 | $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'), |
590 | $eaid, Post::v('cid'), Post::v('pos')); |
591 | } else { |
592 | $art = ($eaid == 'new') ? new NLArticle() : $nl->getArt($eaid); |
593 | } |
594 | $page->assign('art', $art); |
595 | } |
596 | |
597 | $page->assign_by_ref('nl',$nl); |
598 | } |
599 | |
600 | function handler_lists(&$page) { |
601 | $page->changeTpl('admin/lists.tpl'); |
602 | $page->assign('xorg_title','Polytechnique.org - Administration - Mailing lists'); |
603 | require_once 'lists.inc.php'; |
604 | |
605 | $client =& lists_xmlrpc(S::v('uid'), S::v('password')); |
606 | $listes = $client->get_all_lists(); |
607 | $page->assign_by_ref('listes',$listes); |
608 | } |
609 | |
610 | function handler_validate(&$page) { |
611 | $page->changeTpl('admin/valider.tpl'); |
612 | $page->assign('xorg_title','Polytechnique.org - Administration - Valider une demande'); |
613 | require_once("validations.inc.php"); |
614 | |
615 | if(Env::has('uid') && Env::has('type') && Env::has('stamp')) { |
616 | $req = Validate::get_request(Env::v('uid'), Env::v('type'), Env::v('stamp')); |
617 | if($req) { $req->handle_formu(); } |
618 | } |
619 | |
620 | $page->assign('vit', new ValidateIterator()); |
621 | } |
622 | |
623 | function handler_geoloc(&$page, $action = false) { |
624 | $page->changeTpl('admin/geoloc.tpl'); |
625 | require_once("geoloc.inc.php"); |
626 | $page->assign('xorg_title','Polytechnique.org - Administration - Geolocalisation'); |
627 | |
628 | $nb_synchro = 0; |
629 | |
630 | if (Env::has('id') && is_numeric(Env::v('id'))) { |
631 | if (synchro_city(Env::v('id'))) $nb_synchro ++; |
632 | } |
633 | |
634 | if ($action == 'missinglat') { |
635 | $res = XDB::iterRow("SELECT id FROM geoloc_city WHERE lat = 0 AND lon = 0"); |
636 | while ($a = $res->next()) if (synchro_city($a[0])) $nb_synchro++; |
637 | } |
638 | |
639 | if ($nb_synchro) |
640 | $page->trig(($nb_synchro > 1)?($nb_synchro." villes ont été synchronisées"):"Une ville a été synchronisée"); |
641 | |
642 | $res = XDB::query("SELECT COUNT(*) FROM geoloc_city WHERE lat = 0 AND lon = 0"); |
643 | $page->assign("nb_missinglat", $res->fetchOneCell()); |
644 | } |
645 | |
646 | function handler_geoloc_dynamap(&$page, $action = false) { |
647 | $page->changeTpl('admin/geoloc_dynamap.tpl'); |
648 | |
649 | if ($action == 'cities_not_on_map') { |
650 | require_once('geoloc.inc.php'); |
651 | if (!fix_cities_not_on_map(20)) |
652 | $page->trig("Impossible d'accéder au webservice"); |
653 | else |
654 | $refresh = true; |
655 | } |
656 | |
657 | if ($action == 'smallest_maps') { |
658 | require_once('geoloc.inc.php'); |
659 | set_smallest_levels(); |
660 | } |
661 | |
662 | if ($action == 'precise_coordinates') { |
663 | XDB::execute("UPDATE adresses AS a INNER JOIN geoloc_city AS c ON(a.cityid = c.id) SET a.glat = c.lat / 100000, a.glng = c.lon / 100000"); |
664 | } |
665 | |
666 | if ($action == 'newmaps') { |
667 | require_once('geoloc.inc.php'); |
668 | if (!get_new_maps(Env::v('url'))) |
669 | $page->trig("Impossible d'accéder aux nouvelles cartes"); |
670 | } |
671 | |
672 | $countMissing = XDB::query("SELECT COUNT(*) FROM geoloc_city AS c LEFT JOIN geoloc_city_in_maps AS m ON(c.id = m.city_id) WHERE m.city_id IS NULL"); |
673 | $missing = $countMissing->fetchOneCell(); |
674 | |
675 | $countNoSmallest = XDB::query("SELECT SUM(IF(infos = 'smallest',1,0)) AS n FROM geoloc_city_in_maps GROUP BY city_id ORDER BY n"); |
676 | $noSmallest = $countNoSmallest->fetchOneCell() == 0; |
677 | |
678 | $countNoCoordinates = XDB::query("SELECT COUNT(*) FROM adresses WHERE cityid IS NOT NULL AND glat = 0 AND glng = 0"); |
679 | $noCoordinates = $countNoCoordinates->fetchOneCell(); |
680 | |
681 | if (isset($refresh) && $missing) { |
682 | $page->assign("xorg_extra_header", "<meta http-equiv='Refresh' content='3'/>"); |
683 | } |
684 | $page->assign("nb_cities_not_on_map", $missing); |
685 | $page->assign("no_smallest", $noSmallest); |
686 | $page->assign("no_coordinates", $noCoordinates); |
687 | } |
688 | |
689 | function handler_trombino(&$page, $uid = null, $action = null) { |
690 | $page->changeTpl('admin/admin_trombino.tpl'); |
691 | $page->assign('xorg_title','Polytechnique.org - Administration - Trombino'); |
692 | $page->assign('uid', $uid); |
693 | |
694 | $q = XDB::query( |
695 | "SELECT a.alias,promo |
696 | FROM auth_user_md5 AS u |
697 | INNER JOIN aliases AS a ON ( u.user_id = a.id AND type='a_vie' ) |
698 | WHERE user_id = {?}", $uid); |
699 | list($forlife, $promo) = $q->fetchOneRow(); |
700 | |
701 | switch ($action) { |
702 | |
703 | case "original": |
704 | header("Content-type: image/jpeg"); |
705 | readfile("/home/web/trombino/photos".$promo."/".$forlife.".jpg"); |
706 | exit; |
707 | break; |
708 | |
709 | case "new": |
710 | $data = file_get_contents($_FILES['userfile']['tmp_name']); |
711 | list($x, $y) = getimagesize($_FILES['userfile']['tmp_name']); |
712 | $mimetype = substr($_FILES['userfile']['type'], 6); |
713 | unlink($_FILES['userfile']['tmp_name']); |
714 | XDB::execute( |
715 | "REPLACE INTO photo SET uid={?}, attachmime = {?}, attach={?}, x={?}, y={?}", |
716 | $uid, $mimetype, $data, $x, $y); |
717 | break; |
718 | |
719 | case "delete": |
720 | XDB::execute('DELETE FROM photo WHERE uid = {?}', $uid); |
721 | break; |
722 | } |
723 | |
724 | $page->assign('forlife', $forlife); |
725 | } |
e7ae7df9 |
726 | |
727 | function handler_binets(&$page, $action = 'list', $id = null) { |
728 | require_once('../classes/PLTableEditor.php'); |
729 | $page->assign('xorg_title','Polytechnique.org - Administration - Binets'); |
730 | $page->assign('title', 'Gestion des binets'); |
731 | $table_editor = new PLTableEditor('admin/binets', 'binets_def', 'id'); |
732 | $table_editor->add_join_table('binets_ins','binet_id',true); |
733 | $table_editor->describe('text','intitulé',true); |
734 | $table_editor->apply($page, $action, $id); |
735 | } |
736 | function handler_formations(&$page, $action = 'list', $id = null) { |
737 | require_once('../classes/PLTableEditor.php'); |
738 | $page->assign('xorg_title','Polytechnique.org - Administration - Formations'); |
739 | $page->assign('title', 'Gestion des formations'); |
740 | $table_editor = new PLTableEditor('admin/formations','applis_def','id'); |
741 | $table_editor->add_join_table('applis_ins','aid',true); |
742 | $table_editor->describe('text','intitulé',true); |
743 | $table_editor->describe('url','site web',false); |
744 | $table_editor->apply($page, $action, $id); |
745 | } |
746 | function handler_groupesx(&$page, $action = 'list', $id = null) { |
747 | require_once('../classes/PLTableEditor.php'); |
748 | $page->assign('xorg_title','Polytechnique.org - Administration - Groupes X'); |
749 | $page->assign('title', 'Gestion des Groupes X'); |
750 | $table_editor = new PLTableEditor('admin/groupes-x','groupesx_def','id'); |
751 | $table_editor->add_join_table('groupesx_ins','gid',true); |
752 | $table_editor->describe('text','intitulé',true); |
753 | $table_editor->describe('url','site web',false); |
754 | $table_editor->apply($page, $action, $id); |
755 | } |
756 | function handler_skins(&$page, $action = 'list', $id = null) { |
757 | require_once('../classes/PLTableEditor.php'); |
758 | $page->assign('xorg_title','Polytechnique.org - Administration - Skins'); |
759 | $page->assign('title', 'Gestion des skins'); |
760 | $table_editor = new PLTableEditor('admin/skins','skins','id'); |
761 | $table_editor->describe('name','nom',true); |
762 | $table_editor->describe('skin_tpl','nom du template',true); |
763 | $table_editor->describe('auteur','auteur',false); |
764 | $table_editor->describe('comment','commentaire',true); |
765 | $table_editor->describe('date','date',false); |
766 | $table_editor->describe('ext','extension du screenshot',false); |
767 | $table_editor->apply($page, $action, $id); |
768 | } |
769 | function handler_authgroupesx(&$page, $action = 'list', $id = null) { |
770 | require_once('../classes/PLTableEditor.php'); |
771 | $page->assign('xorg_title','Polytechnique.org - Administration - Auth groupes X'); |
772 | $page->assign('title', 'Gestion de l\'authentification centralisée'); |
773 | $table_editor = new PLTableEditor('admin/auth-groupes-x','groupesx_auth','id'); |
774 | $table_editor->describe('name','nom',true); |
775 | $table_editor->describe('privkey','clé privée',false); |
776 | $table_editor->describe('datafields','champs renvoyés',true); |
777 | $table_editor->apply($page, $action, $id); |
778 | } |
779 | function handler_postfix_blacklist(&$page, $action = 'list', $id = null) { |
780 | require_once('../classes/PLTableEditor.php'); |
781 | $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Blacklist'); |
782 | $page->assign('title', 'Blacklist de postfix'); |
783 | $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true); |
784 | $table_editor->describe('reject_text','Texte de rejet',true); |
785 | $table_editor->describe('email','email',true); |
786 | $table_editor->apply($page, $action, $id); |
787 | } |
788 | function handler_postfix_whitelist(&$page, $action = 'list', $id = null) { |
789 | require_once('../classes/PLTableEditor.php'); |
790 | $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Whitelist'); |
791 | $page->assign('title', 'Whitelist de postfix'); |
792 | $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true); |
793 | $table_editor->describe('email','email',true); |
794 | $table_editor->apply($page, $action, $id); |
795 | } |
796 | function handler_logger_actions(&$page, $action = 'list', $id = null) { |
797 | require_once('../classes/PLTableEditor.php'); |
798 | $page->assign('xorg_title','Polytechnique.org - Administration - Actions'); |
799 | $page->assign('title', 'Gestion des actions de logger'); |
800 | $table_editor = new PLTableEditor('admin/logger/actions','logger.actions','id'); |
801 | $table_editor->describe('text','intitulé',true); |
802 | $table_editor->describe('description','description',true); |
803 | $table_editor->apply($page, $action, $id); |
804 | } |
805 | function handler_downtime(&$page, $action = 'list', $id = null) { |
806 | require_once('../classes/PLTableEditor.php'); |
807 | $page->assign('xorg_title','Polytechnique.org - Administration - Coupures'); |
808 | $page->assign('title', 'Gestion des coupures'); |
809 | $table_editor = new PLTableEditor('admin/downtime','coupures','id'); |
810 | $table_editor->describe('debut','date',true); |
811 | $table_editor->describe('duree','durée',false); |
812 | $table_editor->describe('resume','résumé',true); |
813 | $table_editor->describe('services','services affectés',true); |
814 | $table_editor->describe('description','description',false); |
815 | $table_editor->apply($page, $action, $id); |
816 | } |
817 | function handler_newsletter_cat(&$page, $action = 'list', $id = null) { |
818 | require_once('../classes/PLTableEditor.php'); |
819 | $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : Catégories'); |
820 | $page->assign('title', 'Gestion des catégories de la newsletter'); |
821 | $table_editor = new PLTableEditor('admin/newsletter/categories','newsletter_cat','cid'); |
822 | $table_editor->describe('titre','intitulé',true); |
823 | $table_editor->describe('pos','position',true); |
824 | $table_editor->apply($page, $action, $id); |
825 | } |
826 | function handler_payments(&$page, $action = 'list', $id = null) { |
827 | require_once('../classes/PLTableEditor.php'); |
828 | $page->assign('xorg_title','Polytechnique.org - Administration - Paiements'); |
829 | $page->assign('title', 'Gestion des télépaiements'); |
830 | $table_editor = new PLTableEditor('admin/payments','paiement.paiements','id'); |
831 | $table_editor->add_join_table('paiement.transactions','ref',true); |
832 | $table_editor->describe('text','intitulé',true); |
833 | $table_editor->describe('url','site web',false); |
834 | $table_editor->describe('montant_def','montant par défaut',false); |
835 | $table_editor->describe('montant_min','montant minimum',false); |
836 | $table_editor->describe('montant_max','montant maximum',false); |
837 | $table_editor->describe('mail','email contact',true); |
838 | $table_editor->describe('confirmation','message confirmation',false); |
839 | $table_editor->apply($page, $action, $id); |
840 | } |
841 | function handler_medals(&$page, $action = 'list', $id = null) { |
842 | require_once('../classes/PLTableEditor.php'); |
843 | $page->assign('xorg_title','Polytechnique.org - Administration - Distinctions'); |
844 | $page->assign('title', 'Gestion des Distinctions'); |
845 | $table_editor = new PLTableEditor('admin/medals','profile_medals','id'); |
846 | $table_editor->describe('text', 'intitulé', true); |
847 | $table_editor->describe('img', 'nom de l\'image', false); |
848 | $table_editor->apply($page, $action, $id); |
849 | if ($id && $action == 'edit') { |
850 | $page->changeTpl('admin/gerer_decos.tpl'); |
851 | |
852 | $mid = $id; |
853 | |
854 | if (Post::v('act') == 'del') { |
855 | XDB::execute('DELETE FROM profile_medals_grades WHERE mid={?} AND gid={?}', $mid, Post::i('gid')); |
856 | } elseif (Post::v('act') == 'new') { |
857 | XDB::execute('INSERT INTO profile_medals_grades (mid,gid) VALUES({?},{?})', |
858 | $mid, max(array_keys(Post::v('grades', array(0))))+1); |
859 | } else { |
860 | foreach (Post::v('grades', array()) as $gid=>$text) { |
861 | XDB::execute('UPDATE profile_medals_grades SET pos={?}, text={?} WHERE gid={?}', $_POST['pos'][$gid], $text, $gid); |
862 | } |
863 | } |
864 | $res = XDB::iterator('SELECT gid, text, pos FROM profile_medals_grades WHERE mid={?} ORDER BY pos', $mid); |
865 | $page->assign('grades', $res); |
866 | } |
867 | } |
3aec1c21 |
868 | function handler_wiki(&$page, $action='list') { |
869 | require_once 'wiki.inc.php'; |
870 | |
871 | // update wiki perms |
872 | if ($action == 'update') { |
873 | $perms_read = Post::v('read'); |
874 | $perms_edot = Post::v('edit'); |
875 | if ($perms_read || $perms_edit) { |
876 | foreach ($_POST as $wiki_page => $val) if ($val == 'on') { |
877 | $wiki_page = str_replace('_', '/', $wiki_page); |
878 | if (!$perms_read || !$perms_edit) |
879 | list($perms0, $perms1) = wiki_get_perms($wiki_page); |
880 | if ($perms_read) |
881 | $perms0 = $perms_read; |
882 | if ($perms_edit) |
883 | $perms1 = $perms_edit; |
884 | wiki_set_perms($wiki_page, $perms0, $perms1); |
885 | } |
886 | } |
887 | } |
888 | |
889 | $perms = wiki_perms_options(); |
890 | |
891 | // list wiki pages and their perms |
892 | $wiki_pages = array(); |
893 | $dir = wiki_work_dir(); |
894 | if (is_dir($dir)) { |
895 | if ($dh = opendir($dir)) { |
896 | while (($file = readdir($dh)) !== false) if (substr($file,0,1) >= 'A' && substr($file,0,1) <= 'Z') { |
897 | list($read,$edit) = wiki_get_perms($file); |
898 | $wiki_pages[$file] = array('read' => $perms[$read], 'edit' => $perms[$edit]); |
899 | } |
900 | closedir($dh); |
901 | } |
902 | } |
903 | ksort($wiki_pages); |
904 | |
905 | $page->changeTpl('admin/wiki.tpl'); |
906 | $page->assign('wiki_pages', $wiki_pages); |
907 | $page->assign('perms_opts', $perms); |
908 | } |
86f0a6af |
909 | } |
910 | |
911 | ?> |