Change default: show menu in xnet pages.
[platal.git] / modules / admin.php
CommitLineData
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
22class AdminModule extends PLModule
23{
24 function handlers()
25 {
26 return array(
5f9a40b4 27 'phpinfo' => $this->make_hook('phpinfo', AUTH_MDP, 'admin'),
28 'admin' => $this->make_hook('default', AUTH_MDP, 'admin'),
86f0a6af 29 'admin/ax-xorg' => $this->make_hook('ax_xorg', AUTH_MDP, 'admin'),
30 'admin/deaths' => $this->make_hook('deaths', AUTH_MDP, 'admin'),
e7ae7df9 31 'admin/downtime' => $this->make_hook('downtime', AUTH_MDP, 'admin'),
e7ae7df9 32 'admin/homonyms' => $this->make_hook('homonyms', AUTH_MDP, 'admin'),
e7ae7df9 33 'admin/logger' => $this->make_hook('logger', AUTH_MDP, 'admin'),
34 'admin/logger/actions' => $this->make_hook('logger_actions', AUTH_MDP, 'admin'),
e7ae7df9 35 'admin/postfix/blacklist' => $this->make_hook('postfix_blacklist', AUTH_MDP, 'admin'),
36 'admin/postfix/delayed' => $this->make_hook('postfix_delayed', AUTH_MDP, 'admin'),
37 'admin/postfix/regexp_bounces' => $this->make_hook('postfix_regexpsbounces', AUTH_MDP, 'admin'),
38 'admin/postfix/whitelist' => $this->make_hook('postfix_whitelist', AUTH_MDP, 'admin'),
39 'admin/skins' => $this->make_hook('skins', AUTH_MDP, 'admin'),
40 'admin/synchro_ax' => $this->make_hook('synchro_ax', AUTH_MDP, 'admin'),
e7ae7df9 41 'admin/user' => $this->make_hook('user', AUTH_MDP, 'admin'),
42 'admin/validate' => $this->make_hook('validate', AUTH_MDP, 'admin'),
e18888f4 43 'admin/validate/answers' => $this->make_hook('validate_answers', AUTH_MDP, 'admin'),
3aec1c21 44 'admin/wiki' => $this->make_hook('wiki', AUTH_MDP, 'admin'),
86f0a6af 45 );
46 }
47
5f9a40b4 48 function handler_phpinfo(&$page)
49 {
50 phpinfo();
51 exit;
52 }
53
86f0a6af 54 function handler_default(&$page)
55 {
56 $page->changeTpl('admin/index.tpl');
57 $page->assign('xorg_title','Polytechnique.org - Administration');
58 }
59
60 function handler_postfix_delayed(&$page)
61 {
62 $page->changeTpl('admin/postfix_delayed.tpl');
63 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Retardés');
64
65 if (Env::has('del')) {
66 $crc = Env::v('crc');
67 XDB::execute("UPDATE postfix_mailseen SET release = 'del' WHERE crc = {?}", $crc);
68 $page->trig($crc." verra tous ses mails supprimés !");
69 } elseif (Env::has('ok')) {
70 $crc = Env::v('crc');
71 XDB::execute("UPDATE postfix_mailseen SET release = 'ok' WHERE crc = {?}", $crc);
72 $page->trig($crc." a le droit de passer !");
73 }
74
75 $sql = XDB::iterator(
76 "SELECT crc, nb, update_time, create_time,
77 FIND_IN_SET('del', release) AS del,
78 FIND_IN_SET('ok', release) AS ok
79 FROM postfix_mailseen
80 WHERE nb >= 30
81 ORDER BY release != ''");
82
83 $page->assign_by_ref('mails', $sql);
84 }
85
86 function handler_postfix_regexpsbounces(&$page, $new = null) {
87 $page->changeTpl('admin/emails_bounces_re.tpl');
88 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Regexps Bounces');
89 $page->assign('new', $new);
90
91 if (Post::has('submit')) {
92 foreach (Env::v('lvl') as $id=>$val) {
93 XDB::query(
94 "REPLACE INTO emails_bounces_re (id,pos,lvl,re,text) VALUES ({?}, {?}, {?}, {?}, {?})",
95 $id, $_POST['pos'][$id], $_POST['lvl'][$id], $_POST['re'][$id], $_POST['text'][$id]
96 );
97 }
98 }
99
100 $page->assign('bre', XDB::iterator("SELECT * FROM emails_bounces_re ORDER BY pos"));
101 }
102
441e9e98 103 // {{{ logger view
86f0a6af 104
441e9e98 105 /** Retrieves the available days for a given year and month.
106 * Obtain a list of days of the given month in the given year
107 * that are within the range of dates that we have log entries for.
108 *
109 * @param integer year
110 * @param integer month
111 * @return array days in that month we have log entries covering.
112 * @private
113 */
114 function _getDays($year, $month)
115 {
116 // give a 'no filter' option
117 $months[0] = "----";
118
119 if ($year && $month) {
120 $day_max = Array(-1, 31, checkdate(2, 29, $year) ? 29 : 28 , 31,
121 30, 31, 30, 31, 31, 30, 31, 30, 31);
122 $res = XDB::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)),
123 MONTH(MAX(start)), MONTH(MIN(start)),
124 DAYOFMONTH(MAX(start)),
125 DAYOFMONTH(MIN(start))
126 FROM logger.sessions");
127 list($ymax, $ymin, $mmax, $mmin, $dmax, $dmin) = $res->fetchOneRow();
128
129 if (($year < $ymin) || ($year == $ymin && $month < $mmin)) {
130 return array();
131 }
132
133 if (($year > $ymax) || ($year == $ymax && $month > $mmax)) {
134 return array();
135 }
136
137 $min = ($year==$ymin && $month==$mmin) ? intval($dmin) : 1;
138 $max = ($year==$ymax && $month==$mmax) ? intval($dmax) : $day_max[$month];
139
140 for($i = $min; $i<=$max; $i++) {
141 $days[$i] = $i;
142 }
143 }
144 return $days;
145 }
146
147
148 /** Retrieves the available months for a given year.
149 * Obtains a list of month numbers that are within the timeframe that
150 * we have log entries for.
151 *
152 * @param integer year
153 * @return array List of month numbers we have log info for.
154 * @private
155 */
156 function _getMonths($year)
157 {
158 // give a 'no filter' option
159 $months[0] = "----";
160
161 if ($year) {
162 $res = XDB::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)),
163 MONTH(MAX(start)), MONTH(MIN(start))
164 FROM logger.sessions");
165 list($ymax, $ymin, $mmax, $mmin) = $res->fetchOneRow();
166
167 if (($year < $ymin) || ($year > $ymax)) {
168 return array();
169 }
170
171 $min = $year == $ymin ? intval($mmin) : 1;
172 $max = $year == $ymax ? intval($mmax) : 12;
173
174 for($i = $min; $i<=$max; $i++) {
175 $months[$i] = $i;
176 }
177 }
178 return $months;
179 }
180
181
182 /** Retrieves the available years.
183 * Obtains a list of years that we have log entries covering.
184 *
185 * @return array years we have log entries for.
186 * @private
187 */
188 function _getYears()
189 {
190 // give a 'no filter' option
191 $years[0] = "----";
192
193 // retrieve available years
194 $res = XDB::query("select YEAR(MAX(start)), YEAR(MIN(start)) FROM logger.sessions");
195 list($max, $min) = $res->fetchOneRow();
196
197 for($i = intval($min); $i<=$max; $i++) {
198 $years[$i] = $i;
199 }
200 return $years;
201 }
202
203
204 /** Make a where clause to get a user's sessions.
205 * Prepare the where clause request that will retrieve the sessions.
206 *
207 * @param $year INTEGER Only get log entries made during the given year.
208 * @param $month INTEGER Only get log entries made during the given month.
209 * @param $day INTEGER Only get log entries made during the given day.
210 * @param $uid INTEGER Only get log entries referring to the given user ID.
211 *
212 * @return STRING the WHERE clause of a query, including the 'WHERE' keyword
213 * @private
214 */
215 function _makeWhere($year, $month, $day, $uid)
216 {
217 // start constructing the "where" clause
218 $where = array();
219
220 if ($uid)
221 array_push($where, "uid='$uid'");
222
223 // we were given at least a year
224 if ($year) {
225 if ($day) {
226 $dmin = mktime(0, 0, 0, $month, $day, $year);
227 $dmax = mktime(0, 0, 0, $month, $day+1, $year);
228 } elseif ($month) {
229 $dmin = mktime(0, 0, 0, $month, 1, $year);
230 $dmax = mktime(0, 0, 0, $month+1, 1, $year);
231 } else {
232 $dmin = mktime(0, 0, 0, 1, 1, $year);
233 $dmax = mktime(0, 0, 0, 1, 1, $year+1);
234 }
235 $where[] = "start >= " . date("Ymd000000", $dmin);
236 $where[] = "start < " . date("Ymd000000", $dmax);
237 }
238
239 if (!empty($where)) {
240 return ' WHERE ' . implode($where, " AND ");
241 } else {
242 return '';
243 }
244 // WE know it's totally reversed, so better use array_reverse than a SORT BY start DESC
245 }
246
247 // }}}
248
249 function handler_logger(&$page, $action = null, $arg = null) {
250 if ($action == 'session') {
251
252 // we are viewing a session
253 $res = XDB::query("SELECT ls.*, a.alias AS username, sa.alias AS suer
254 FROM logger.sessions AS ls
255 LEFT JOIN aliases AS a ON (a.id = ls.uid AND a.type='a_vie')
256 LEFT JOIN aliases AS sa ON (sa.id = ls.suid AND sa.type='a_vie')
257 WHERE ls.id = {?}", $arg);
258
259 $page->assign('session', $a = $res->fetchOneAssoc());
260
261 $res = XDB::iterator('SELECT a.text, e.data, UNIX_TIMESTAMP(e.stamp) AS stamp
262 FROM logger.events AS e
263 LEFT JOIN logger.actions AS a ON e.action=a.id
264 WHERE e.session={?}', $arg);
265 while ($myarr = $res->next()) {
266 $page->append('events', $myarr);
267 }
268
269 } else {
270 $loguser = $action == 'user' ? $arg : Env::v('loguser');
271
272 $res = XDB::query('SELECT id FROM aliases WHERE alias={?}',
273 $loguser);
274 $loguid = $res->fetchOneCell();
275
276 if ($loguid) {
277 $year = Env::i('year');
278 $month = Env::i('month');
279 $day = Env::i('day');
280 } else {
281 $year = Env::i('year', intval(date('Y')));
282 $month = Env::i('month', intval(date('m')));
283 $day = Env::i('day', intval(date('d')));
284 }
285
286 if (!$year)
287 $month = 0;
288 if (!$month)
289 $day = 0;
290
291 // smarty assignments
292 // retrieve available years
293 $page->assign('years', $this->_getYears());
294 $page->assign('year', $year);
295
296 // retrieve available months for the current year
297 $page->assign('months', $this->_getMonths($year));
298 $page->assign('month', $month);
299
300 // retrieve available days for the current year and month
301 $page->assign('days', $this->_getDays($year, $month));
302 $page->assign('day', $day);
303
304 $page->assign('loguser', $loguser);
305 // smarty assignments
306
307 if ($loguid || $year) {
308
309 // get the requested sessions
310 $where = $this->_makeWhere($year, $month, $day, $loguid);
311 $select = "SELECT s.id, UNIX_TIMESTAMP(s.start) as start, s.uid,
312 a.alias as username
313 FROM logger.sessions AS s
314 LEFT JOIN aliases AS a ON (a.id = s.uid AND a.type='a_vie')
315 $where
316 ORDER BY start DESC";
317 $res = XDB::iterator($select);
318
319 $sessions = array();
320 while ($mysess = $res->next()) {
321 $mysess['events'] = array();
322 $sessions[$mysess['id']] = $mysess;
323 }
324 array_reverse($sessions);
325
326 // attach events
327 $sql = "SELECT s.id, a.text
328 FROM logger.sessions AS s
329 LEFT JOIN logger.events AS e ON(e.session=s.id)
330 INNER JOIN logger.actions AS a ON(a.id=e.action)
331 $where";
332
333 $res = XDB::iterator($sql);
334 while ($event = $res->next()) {
335 array_push($sessions[$event['id']]['events'], $event['text']);
336 }
337 $page->assign_by_ref('sessions', $sessions);
338 } else {
339 $page->assign('msg_nofilters', "Sélectionner une annuée et/ou un utilisateur");
340 }
86f0a6af 341 }
342
441e9e98 343 $page->changeTpl('logger-view.tpl');
86f0a6af 344
c4271d38 345 $page->assign('xorg_title','Polytechnique.org - Administration - Logs des sessions');
86f0a6af 346 }
347
348 function handler_user(&$page, $login = false) {
349 $page->changeTpl('admin/utilisateurs.tpl');
350 $page->assign('xorg_title','Polytechnique.org - Administration - Edit/Su/Log');
351 require_once("emails.inc.php");
352 require_once("user.func.inc.php");
353
354 if (S::has('suid')) {
355 $page->kill("déjà en SUID !!!");
356 }
357
358 if (Env::has('user_id')) {
359 $login = get_user_login(Env::i('user_id'));
360 } elseif (Env::has('login')) {
361 $login = get_user_login(Env::v('login'));
362 }
363
364 if(Env::has('logs_button') && $login) {
365 pl_redirect("admin/logger?login=$login&year=".date('Y')."&month=".date('m'));
366 }
367
368 if (Env::has('ax_button') && $login) {
369 pl_redirect("admin/synchro_ax/$login");
370 }
371
372 if(Env::has('suid_button') && $login) {
373 $_SESSION['log']->log("suid_start", "login by ".S::v('forlife'));
374 $_SESSION['suid'] = $_SESSION;
375 $r = XDB::query("SELECT id FROM aliases WHERE alias={?}", $login);
376 if($uid = $r->fetchOneCell()) {
377 start_connexion($uid,true);
378 pl_redirect("");
379 }
380 }
381
382 if ($login) {
383 $r = XDB::query("SELECT *, a.alias AS forlife, u.flags AS sexe
384 FROM auth_user_md5 AS u
385 INNER JOIN aliases AS a ON ( a.id = u.user_id AND a.alias={?} AND type!='homonyme' )", $login);
386 $mr = $r->fetchOneAssoc();
387
388 $redirect = new Redirect($mr['user_id']);
389
390 // Check if there was a submission
391 foreach($_POST as $key => $val) {
392 switch ($key) {
393 case "add_fwd":
394 $email = trim(Env::v('email'));
395 if (!isvalid_email_redirection($email)) {
396 $page->trig("invalid email $email");
397 } else {
398 $redirect->add_email($email);
399 $page->trig("Ajout de $email effectué");
400 }
401 break;
402
403 case "del_fwd":
404 if (!empty($val)) {
405 $redirect->delete_email($val);
406 }
407 break;
408
409 case "del_alias":
410 if (!empty($val)) {
411 XDB::execute("DELETE FROM aliases WHERE id={?} AND alias={?}
412 AND type!='a_vie' AND type!='homonyme'", $mr['user_id'], $val);
d91e720f 413 XDB::execute("UPDATE emails
414 SET rewrite = ''
415 WHERE uid = {?} AND rewrite LIKE CONCAT({?}, '@%')",
416 $mr['user_id'], $val);
86f0a6af 417 fix_bestalias($mr['user_id']);
418 $page->trig($val." a été supprimé");
419 }
420 break;
421 case "activate_fwd":
422 if (!empty($val)) {
423 $redirect->modify_one_email($val, true);
424 }
425 break;
426 case "deactivate_fwd":
427 if (!empty($val)) {
428 $redirect->modify_one_email($val, false);
429 }
430 break;
431 case "add_alias":
432 XDB::execute("INSERT INTO aliases (id,alias,type) VALUES ({?}, {?}, 'alias')",
433 $mr['user_id'], Env::v('email'));
434 break;
435
436 case "best":
437 // 'bestalias' is the first bit of the set : 1
438 // 255 is the max for flags (8 sets max)
439 XDB::execute("UPDATE aliases SET flags= flags & (255 - 1) WHERE id={?}", $mr['user_id']);
440 XDB::execute("UPDATE aliases
441 SET flags= flags | 1
442 WHERE id={?} AND alias={?}", $mr['user_id'], $val);
443 break;
444
445
446 // Editer un profil
447 case "u_edit":
448 require_once('secure_hash.inc.php');
449 $pass_encrypted = Env::v('newpass_clair') != "********" ? hash_encrypt(Env::v('newpass_clair')) : Env::v('passw');
450 $naiss = Env::v('naissanceN');
34ffe99a 451 $deces = Env::v('decesN');
86f0a6af 452 $perms = Env::v('permsN');
453 $prenm = Env::v('prenomN');
454 $nom = Env::v('nomN');
455 $promo = Env::i('promoN');
456 $sexe = Env::v('sexeN');
457 $comm = Env::v('commentN');
458
459 $query = "UPDATE auth_user_md5 SET
460 naissance = '$naiss',
34ffe99a 461 deces = '$deces',
86f0a6af 462 password = '$pass_encrypted',
463 perms = '$perms',
464 prenom = '".addslashes($prenm)."',
465 nom = '".addslashes($nom)."',
466 flags = '$sexe',
467 promo = $promo,
468 comment = '".addslashes($comm)."'
469 WHERE user_id = '{$mr['user_id']}'";
470 if (XDB::execute($query)) {
471 user_reindex($mr['user_id']);
472
473 require_once("diogenes/diogenes.hermes.inc.php");
474 $mailer = new HermesMailer();
475 $mailer->setFrom("webmaster@polytechnique.org");
476 $mailer->addTo("web@polytechnique.org");
477 $mailer->setSubject("INTERVENTION de ".S::v('forlife'));
478 $mailer->setTxtBody(preg_replace("/[ \t]+/", ' ', $query));
479 $mailer->send();
480
481 $page->trig("updaté correctement.");
482 }
483 if (Env::v('nomusageN') != $mr['nom_usage']) {
86f0a6af 484 set_new_usage($mr['user_id'], Env::v('nomusageN'), make_username(Env::v('prenomN'), Env::v('nomusageN')));
485 }
486 $r = XDB::query("SELECT *, a.alias AS forlife, u.flags AS sexe
487 FROM auth_user_md5 AS u
488 INNER JOIN aliases AS a ON (u.user_id=a.id)
489 WHERE user_id = {?}", $mr['user_id']);
490 $mr = $r->fetchOneAssoc();
491 break;
492
493 // DELETE FROM auth_user_md5
494 case "u_kill":
495 user_clear_all_subs($mr['user_id']);
496 $page->trig("'{$mr['user_id']}' a été désinscrit !");
497 require_once("diogenes/diogenes.hermes.inc.php");
498 $mailer = new HermesMailer();
499 $mailer->setFrom("webmaster@polytechnique.org");
500 $mailer->addTo("web@polytechnique.org");
501 $mailer->setSubject("INTERVENTION de ".S::v('forlife'));
502 $mailer->setTxtBody("\nUtilisateur $login effacé");
503 $mailer->send();
504 break;
505 }
506 }
507
508 $res = XDB::query("SELECT UNIX_TIMESTAMP(start), host
509 FROM logger.sessions
510 WHERE uid={?} AND suid=0
511 ORDER BY start DESC
512 LIMIT 1", $mr['user_id']);
513 list($lastlogin,$host) = $res->fetchOneRow();
514 $page->assign('lastlogin', $lastlogin);
515 $page->assign('host', $host);
516
517 $page->assign('aliases', XDB::iterator(
518 "SELECT alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire
519 FROM aliases
520 WHERE id = {?} AND type!='homonyme'
521 ORDER BY type!= 'a_vie'", $mr["user_id"]));
86f0a6af 522 $page->assign('emails',$redirect->emails);
523
524 $page->assign('mr',$mr);
525 }
526 }
527 function handler_homonyms(&$page, $op = 'list', $target = null) {
528 $page->changeTpl('admin/homonymes.tpl');
529 $page->assign('xorg_title','Polytechnique.org - Administration - Homonymes');
530 require_once("homonymes.inc.php");
74c55fd6 531
86f0a6af 532 if ($target) {
533 if (! list($prenom,$nom,$forlife,$loginbis) = select_if_homonyme($target)) {
534 $target=0;
535 } else {
536 $page->assign('nom',$nom);
537 $page->assign('prenom',$prenom);
538 $page->assign('forlife',$forlife);
539 $page->assign('loginbis',$loginbis);
540 }
541 }
74c55fd6 542
86f0a6af 543 $page->assign('op',$op);
544 $page->assign('target',$target);
74c55fd6 545
86f0a6af 546 // on a un $target valide, on prepare les mails
547 if ($target) {
74c55fd6 548
86f0a6af 549 // on examine l'op a effectuer
550 switch ($op) {
551 case 'mail':
552 send_warning_homonyme($prenom, $nom, $forlife, $loginbis);
553 switch_bestalias($target, $loginbis);
554 $op = 'list';
555 break;
556 case 'correct':
557 switch_bestalias($target, $loginbis);
558 XDB::execute("UPDATE aliases SET type='homonyme',expire=NOW() WHERE alias={?}", $loginbis);
559 XDB::execute("REPLACE INTO homonymes (homonyme_id,user_id) VALUES({?},{?})", $target, $target);
560 send_robot_homonyme($prenom, $nom, $forlife, $loginbis);
561 $op = 'list';
562 break;
563 }
564 }
74c55fd6 565
86f0a6af 566 if ($op == 'list') {
567 $res = XDB::iterator(
568 "SELECT a.alias AS homonyme,s.id AS user_id,s.alias AS forlife,
569 promo,prenom,nom,
570 IF(h.homonyme_id=s.id, a.expire, NULL) AS expire,
571 IF(h.homonyme_id=s.id, a.type, NULL) AS type
572 FROM aliases AS a
573 LEFT JOIN homonymes AS h ON (h.homonyme_id = a.id)
574 INNER JOIN aliases AS s ON (s.id = h.user_id AND s.type='a_vie')
575 INNER JOIN auth_user_md5 AS u ON (s.id=u.user_id)
576 WHERE a.type='homonyme' OR a.expire!=''
577 ORDER BY a.alias,promo");
578 $hnymes = Array();
579 while ($tab = $res->next()) {
580 $hnymes[$tab['homonyme']][] = $tab;
581 }
582 $page->assign_by_ref('hnymes',$hnymes);
583 }
584 }
74c55fd6 585
86f0a6af 586 function handler_ax_xorg(&$page) {
587 $page->changeTpl('admin/ax-xorg.tpl');
588 $page->assign('xorg_title','Polytechnique.org - Administration - AX/X.org');
74c55fd6 589
86f0a6af 590 // liste des différences
591 $res = XDB::query(
592 '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
593 FROM auth_user_md5 AS u
594 INNER JOIN identification_ax AS ia ON u.matricule_ax = ia.matricule_ax
595 WHERE (SOUNDEX(u.nom) != SOUNDEX(ia.nom) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom)
596 AND SOUNDEX(u.nom) != SOUNDEX(ia.nom_patro) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom_patro))
597 OR u.prenom != ia.prenom OR (u.promo != ia.promo AND u.promo != ia.promo+1 AND u.promo != ia.promo-1)
598 ORDER BY u.promo,u.nom,u.prenom');
599 $page->assign('diffs', $res->fetchAllAssoc());
74c55fd6 600
86f0a6af 601 // gens à l'ax mais pas chez nous
602 $res = XDB::query(
603 'SELECT ia.promo,ia.nom,ia.nom_patro,ia.prenom
604 FROM identification_ax as ia
605 LEFT JOIN auth_user_md5 AS u ON u.matricule_ax = ia.matricule_ax
606 WHERE u.nom IS NULL');
607 $page->assign('mank', $res->fetchAllAssoc());
74c55fd6 608
86f0a6af 609 // gens chez nous et pas à l'ax
610 $res = XDB::query('SELECT promo,nom,prenom FROM auth_user_md5 WHERE matricule_ax IS NULL');
611 $page->assign('plus', $res->fetchAllAssoc());
612 }
74c55fd6 613
86f0a6af 614 function handler_deaths(&$page, $promo = 0, $validate = false) {
615 $page->changeTpl('admin/deces_promo.tpl');
616 $page->assign('xorg_title','Polytechnique.org - Administration - Deces');
74c55fd6 617
86f0a6af 618 if (!$promo)
619 $promo = Env::i('promo');
620 if (Env::has('sub10')) $promo -= 10;
621 if (Env::has('sub01')) $promo -= 1;
622 if (Env::has('add01')) $promo += 1;
623 if (Env::has('add10')) $promo += 10;
74c55fd6 624
86f0a6af 625 $page->assign('promo',$promo);
74c55fd6 626
86f0a6af 627 if ($validate) {
628 $new_deces = array();
629 $res = XDB::iterRow("SELECT user_id,matricule,nom,prenom,deces FROM auth_user_md5 WHERE promo = {?}", $promo);
630 while (list($uid,$mat,$nom,$prenom,$deces) = $res->next()) {
631 $val = Env::v($mat);
632 if($val == $deces || empty($val)) continue;
633 XDB::execute('UPDATE auth_user_md5 SET deces={?} WHERE matricule = {?}', $val, $mat);
634 $new_deces[] = array('name' => "$prenom $nom", 'date' => "$val");
635 if($deces=='0000-00-00' or empty($deces)) {
636 require_once('notifs.inc.php');
637 register_watch_op($uid, WATCH_DEATH, $val);
638 require_once('user.func.inc.php');
639 user_clear_all_subs($uid, false); // by default, dead ppl do not loose their email
640 }
641 }
642 $page->assign('new_deces',$new_deces);
643 }
74c55fd6 644
86f0a6af 645 $res = XDB::iterator('SELECT matricule, nom, prenom, deces FROM auth_user_md5 WHERE promo = {?} ORDER BY nom,prenom', $promo);
646 $page->assign('decedes', $res);
647 }
74c55fd6 648
86f0a6af 649 function handler_synchro_ax(&$page, $user = null, $action = null) {
650 $page->changeTpl('admin/synchro_ax.tpl');
651 $page->assign('xorg_title','Polytechnique.org - Administration - Synchro AX');
74c55fd6 652
86f0a6af 653 require_once('synchro_ax.inc.php');
74c55fd6 654
86f0a6af 655 if (is_ax_key_missing()) {
656 $page->assign('no_private_key', true);
657 $page->run();
658 }
74c55fd6 659
86f0a6af 660 require_once('user.func.inc.php');
661
662 if ($user)
663 $login = get_user_forlife($user);
664
665 if (Env::has('user')) {
666 $login = get_user_forlife(Env::v('user'));
667 if ($login === false) {
668 return;
669 }
670 }
74c55fd6 671
86f0a6af 672 if (Env::has('mat')) {
673 $res = XDB::query(
74c55fd6 674 "SELECT alias
86f0a6af 675 FROM aliases AS a
676 INNER JOIN auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie')
677 WHERE matricule={?}", Env::i('mat'));
678 $login = $res->fetchOneCell();
679 }
74c55fd6 680
86f0a6af 681 if ($login) {
682 if ($action == 'import') {
683 ax_synchronize($login, S::v('uid'));
684 }
685 // get details from user, but looking only info that can be seen by ax
686 $user = get_user_details($login, S::v('uid'), 'ax');
687 $userax= get_user_ax($user['matricule_ax']);
688 require_once 'profil.func.inc.php';
689 $diff = diff_user_details($userax, $user, 'ax');
74c55fd6 690
86f0a6af 691 $page->assign('x', $user);
692 $page->assign('diff', $diff);
693 }
694 }
74c55fd6 695
ed5b9703 696 function handler_validate(&$page, $action = 'list', $id = null) {
86f0a6af 697 $page->changeTpl('admin/valider.tpl');
698 $page->assign('xorg_title','Polytechnique.org - Administration - Valider une demande');
699 require_once("validations.inc.php");
74c55fd6 700
ed5b9703 701 if ($action == 'edit' and !is_null($id)) {
702 $page->assign('preview_id', $id);
703 }
704
86f0a6af 705 if(Env::has('uid') && Env::has('type') && Env::has('stamp')) {
706 $req = Validate::get_request(Env::v('uid'), Env::v('type'), Env::v('stamp'));
707 if($req) { $req->handle_formu(); }
708 }
74c55fd6 709
cfb96867 710 $r = XDB::iterator('SHOW COLUMNS FROM requests_answers');
711 while (($a = $r->next()) && $a['Field'] != 'category');
712 $page->assign('categories', $categories = explode(',', str_replace("'", '', substr($a['Type'], 5, -1))));
74c55fd6 713
cfb96867 714 $hidden = array();
715 if (Post::has('hide')) {
74c55fd6 716 $hide = array();
717 foreach ($categories as $cat)
cfb96867 718 if (!Post::v($cat)) {
719 $hidden[$cat] = 1;
720 $hide[] = $cat;
721 }
722 setcookie('hide_requests', join(',',$hide), time()+(count($hide)?25920000:(-3600)), '/', '', 0);
723 } elseif (Env::has('hide_requests')) {
724 foreach (explode(',',Env::v('hide_requests')) as $hide_type)
725 $hidden[$hide_type] = true;
726 }
727 $page->assign('hide_requests', $hidden);
74c55fd6 728
86f0a6af 729 $page->assign('vit', new ValidateIterator());
730 }
e18888f4 731 function handler_validate_answers(&$page, $action = 'list', $id = null) {
e18888f4 732 $page->assign('xorg_title','Polytechnique.org - Administration - Réponses automatiques de validation');
733 $page->assign('title', 'Gestion des réponses automatiques');
734 $table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id');
735 $table_editor->describe('category','catégorie',true);
736 $table_editor->describe('title','titre',true);
737 $table_editor->describe('answer','texte',false);
738 $table_editor->apply($page, $action, $id);
739 }
e7ae7df9 740 function handler_skins(&$page, $action = 'list', $id = null) {
e7ae7df9 741 $page->assign('xorg_title','Polytechnique.org - Administration - Skins');
742 $page->assign('title', 'Gestion des skins');
743 $table_editor = new PLTableEditor('admin/skins','skins','id');
744 $table_editor->describe('name','nom',true);
745 $table_editor->describe('skin_tpl','nom du template',true);
746 $table_editor->describe('auteur','auteur',false);
747 $table_editor->describe('comment','commentaire',true);
748 $table_editor->describe('date','date',false);
749 $table_editor->describe('ext','extension du screenshot',false);
750 $table_editor->apply($page, $action, $id);
74c55fd6 751 }
e7ae7df9 752 function handler_postfix_blacklist(&$page, $action = 'list', $id = null) {
e7ae7df9 753 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Blacklist');
754 $page->assign('title', 'Blacklist de postfix');
755 $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true);
756 $table_editor->describe('reject_text','Texte de rejet',true);
757 $table_editor->describe('email','email',true);
758 $table_editor->apply($page, $action, $id);
74c55fd6 759 }
e7ae7df9 760 function handler_postfix_whitelist(&$page, $action = 'list', $id = null) {
e7ae7df9 761 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Whitelist');
762 $page->assign('title', 'Whitelist de postfix');
763 $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true);
764 $table_editor->describe('email','email',true);
765 $table_editor->apply($page, $action, $id);
74c55fd6 766 }
e7ae7df9 767 function handler_logger_actions(&$page, $action = 'list', $id = null) {
e7ae7df9 768 $page->assign('xorg_title','Polytechnique.org - Administration - Actions');
769 $page->assign('title', 'Gestion des actions de logger');
770 $table_editor = new PLTableEditor('admin/logger/actions','logger.actions','id');
771 $table_editor->describe('text','intitulé',true);
772 $table_editor->describe('description','description',true);
773 $table_editor->apply($page, $action, $id);
74c55fd6 774 }
e7ae7df9 775 function handler_downtime(&$page, $action = 'list', $id = null) {
e7ae7df9 776 $page->assign('xorg_title','Polytechnique.org - Administration - Coupures');
777 $page->assign('title', 'Gestion des coupures');
778 $table_editor = new PLTableEditor('admin/downtime','coupures','id');
779 $table_editor->describe('debut','date',true);
780 $table_editor->describe('duree','durée',false);
781 $table_editor->describe('resume','résumé',true);
782 $table_editor->describe('services','services affectés',true);
783 $table_editor->describe('description','description',false);
784 $table_editor->apply($page, $action, $id);
74c55fd6 785 }
3aec1c21 786 function handler_wiki(&$page, $action='list') {
787 require_once 'wiki.inc.php';
74c55fd6 788
3aec1c21 789 // update wiki perms
790 if ($action == 'update') {
791 $perms_read = Post::v('read');
792 $perms_edot = Post::v('edit');
793 if ($perms_read || $perms_edit) {
794 foreach ($_POST as $wiki_page => $val) if ($val == 'on') {
795 $wiki_page = str_replace('_', '/', $wiki_page);
796 if (!$perms_read || !$perms_edit)
74c55fd6 797 list($perms0, $perms1) = wiki_get_perms($wiki_page);
3aec1c21 798 if ($perms_read)
799 $perms0 = $perms_read;
800 if ($perms_edit)
801 $perms1 = $perms_edit;
802 wiki_set_perms($wiki_page, $perms0, $perms1);
803 }
804 }
805 }
74c55fd6 806
3aec1c21 807 $perms = wiki_perms_options();
74c55fd6 808
3aec1c21 809 // list wiki pages and their perms
810 $wiki_pages = array();
811 $dir = wiki_work_dir();
812 if (is_dir($dir)) {
813 if ($dh = opendir($dir)) {
814 while (($file = readdir($dh)) !== false) if (substr($file,0,1) >= 'A' && substr($file,0,1) <= 'Z') {
815 list($read,$edit) = wiki_get_perms($file);
816 $wiki_pages[$file] = array('read' => $perms[$read], 'edit' => $perms[$edit]);
817 }
818 closedir($dh);
819 }
820 }
821 ksort($wiki_pages);
74c55fd6 822
3aec1c21 823 $page->changeTpl('admin/wiki.tpl');
74c55fd6 824 $page->assign('wiki_pages', $wiki_pages);
3aec1c21 825 $page->assign('perms_opts', $perms);
826 }
86f0a6af 827}
828
829?>