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