#478: correctly sort payments
[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);
d91e720f 406 XDB::execute("UPDATE emails
407 SET rewrite = ''
408 WHERE uid = {?} AND rewrite LIKE CONCAT({?}, '@%')",
409 $mr['user_id'], $val);
86f0a6af 410 fix_bestalias($mr['user_id']);
411 $page->trig($val." a été supprimé");
412 }
413 break;
414 case "activate_fwd":
415 if (!empty($val)) {
416 $redirect->modify_one_email($val, true);
417 }
418 break;
419 case "deactivate_fwd":
420 if (!empty($val)) {
421 $redirect->modify_one_email($val, false);
422 }
423 break;
424 case "add_alias":
425 XDB::execute("INSERT INTO aliases (id,alias,type) VALUES ({?}, {?}, 'alias')",
426 $mr['user_id'], Env::v('email'));
427 break;
428
429 case "best":
430 // 'bestalias' is the first bit of the set : 1
431 // 255 is the max for flags (8 sets max)
432 XDB::execute("UPDATE aliases SET flags= flags & (255 - 1) WHERE id={?}", $mr['user_id']);
433 XDB::execute("UPDATE aliases
434 SET flags= flags | 1
435 WHERE id={?} AND alias={?}", $mr['user_id'], $val);
436 break;
437
438
439 // Editer un profil
440 case "u_edit":
441 require_once('secure_hash.inc.php');
442 $pass_encrypted = Env::v('newpass_clair') != "********" ? hash_encrypt(Env::v('newpass_clair')) : Env::v('passw');
443 $naiss = Env::v('naissanceN');
34ffe99a 444 $deces = Env::v('decesN');
86f0a6af 445 $perms = Env::v('permsN');
446 $prenm = Env::v('prenomN');
447 $nom = Env::v('nomN');
448 $promo = Env::i('promoN');
449 $sexe = Env::v('sexeN');
450 $comm = Env::v('commentN');
451
452 $query = "UPDATE auth_user_md5 SET
453 naissance = '$naiss',
34ffe99a 454 deces = '$deces',
86f0a6af 455 password = '$pass_encrypted',
456 perms = '$perms',
457 prenom = '".addslashes($prenm)."',
458 nom = '".addslashes($nom)."',
459 flags = '$sexe',
460 promo = $promo,
461 comment = '".addslashes($comm)."'
462 WHERE user_id = '{$mr['user_id']}'";
463 if (XDB::execute($query)) {
464 user_reindex($mr['user_id']);
465
466 require_once("diogenes/diogenes.hermes.inc.php");
467 $mailer = new HermesMailer();
468 $mailer->setFrom("webmaster@polytechnique.org");
469 $mailer->addTo("web@polytechnique.org");
470 $mailer->setSubject("INTERVENTION de ".S::v('forlife'));
471 $mailer->setTxtBody(preg_replace("/[ \t]+/", ' ', $query));
472 $mailer->send();
473
474 $page->trig("updaté correctement.");
475 }
476 if (Env::v('nomusageN') != $mr['nom_usage']) {
86f0a6af 477 set_new_usage($mr['user_id'], Env::v('nomusageN'), make_username(Env::v('prenomN'), Env::v('nomusageN')));
478 }
479 $r = XDB::query("SELECT *, a.alias AS forlife, u.flags AS sexe
480 FROM auth_user_md5 AS u
481 INNER JOIN aliases AS a ON (u.user_id=a.id)
482 WHERE user_id = {?}", $mr['user_id']);
483 $mr = $r->fetchOneAssoc();
484 break;
485
486 // DELETE FROM auth_user_md5
487 case "u_kill":
488 user_clear_all_subs($mr['user_id']);
489 $page->trig("'{$mr['user_id']}' a été désinscrit !");
490 require_once("diogenes/diogenes.hermes.inc.php");
491 $mailer = new HermesMailer();
492 $mailer->setFrom("webmaster@polytechnique.org");
493 $mailer->addTo("web@polytechnique.org");
494 $mailer->setSubject("INTERVENTION de ".S::v('forlife'));
495 $mailer->setTxtBody("\nUtilisateur $login effacé");
496 $mailer->send();
497 break;
498 }
499 }
500
501 $res = XDB::query("SELECT UNIX_TIMESTAMP(start), host
502 FROM logger.sessions
503 WHERE uid={?} AND suid=0
504 ORDER BY start DESC
505 LIMIT 1", $mr['user_id']);
506 list($lastlogin,$host) = $res->fetchOneRow();
507 $page->assign('lastlogin', $lastlogin);
508 $page->assign('host', $host);
509
510 $page->assign('aliases', XDB::iterator(
511 "SELECT alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire
512 FROM aliases
513 WHERE id = {?} AND type!='homonyme'
514 ORDER BY type!= 'a_vie'", $mr["user_id"]));
515 $page->assign('xorgmails', $xorgmails);
74c55fd6 516 $page->assign('email_panne', $email_panne);
86f0a6af 517 $page->assign('emails',$redirect->emails);
518
519 $page->assign('mr',$mr);
520 }
521 }
522 function handler_homonyms(&$page, $op = 'list', $target = null) {
523 $page->changeTpl('admin/homonymes.tpl');
524 $page->assign('xorg_title','Polytechnique.org - Administration - Homonymes');
525 require_once("homonymes.inc.php");
74c55fd6 526
86f0a6af 527 if ($target) {
528 if (! list($prenom,$nom,$forlife,$loginbis) = select_if_homonyme($target)) {
529 $target=0;
530 } else {
531 $page->assign('nom',$nom);
532 $page->assign('prenom',$prenom);
533 $page->assign('forlife',$forlife);
534 $page->assign('loginbis',$loginbis);
535 }
536 }
74c55fd6 537
86f0a6af 538 $page->assign('op',$op);
539 $page->assign('target',$target);
74c55fd6 540
86f0a6af 541 // on a un $target valide, on prepare les mails
542 if ($target) {
74c55fd6 543
86f0a6af 544 // on examine l'op a effectuer
545 switch ($op) {
546 case 'mail':
547 send_warning_homonyme($prenom, $nom, $forlife, $loginbis);
548 switch_bestalias($target, $loginbis);
549 $op = 'list';
550 break;
551 case 'correct':
552 switch_bestalias($target, $loginbis);
553 XDB::execute("UPDATE aliases SET type='homonyme',expire=NOW() WHERE alias={?}", $loginbis);
554 XDB::execute("REPLACE INTO homonymes (homonyme_id,user_id) VALUES({?},{?})", $target, $target);
555 send_robot_homonyme($prenom, $nom, $forlife, $loginbis);
556 $op = 'list';
557 break;
558 }
559 }
74c55fd6 560
86f0a6af 561 if ($op == 'list') {
562 $res = XDB::iterator(
563 "SELECT a.alias AS homonyme,s.id AS user_id,s.alias AS forlife,
564 promo,prenom,nom,
565 IF(h.homonyme_id=s.id, a.expire, NULL) AS expire,
566 IF(h.homonyme_id=s.id, a.type, NULL) AS type
567 FROM aliases AS a
568 LEFT JOIN homonymes AS h ON (h.homonyme_id = a.id)
569 INNER JOIN aliases AS s ON (s.id = h.user_id AND s.type='a_vie')
570 INNER JOIN auth_user_md5 AS u ON (s.id=u.user_id)
571 WHERE a.type='homonyme' OR a.expire!=''
572 ORDER BY a.alias,promo");
573 $hnymes = Array();
574 while ($tab = $res->next()) {
575 $hnymes[$tab['homonyme']][] = $tab;
576 }
577 $page->assign_by_ref('hnymes',$hnymes);
578 }
579 }
74c55fd6 580
86f0a6af 581 function handler_ax_xorg(&$page) {
582 $page->changeTpl('admin/ax-xorg.tpl');
583 $page->assign('xorg_title','Polytechnique.org - Administration - AX/X.org');
74c55fd6 584
86f0a6af 585 // liste des différences
586 $res = XDB::query(
587 '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
588 FROM auth_user_md5 AS u
589 INNER JOIN identification_ax AS ia ON u.matricule_ax = ia.matricule_ax
590 WHERE (SOUNDEX(u.nom) != SOUNDEX(ia.nom) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom)
591 AND SOUNDEX(u.nom) != SOUNDEX(ia.nom_patro) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom_patro))
592 OR u.prenom != ia.prenom OR (u.promo != ia.promo AND u.promo != ia.promo+1 AND u.promo != ia.promo-1)
593 ORDER BY u.promo,u.nom,u.prenom');
594 $page->assign('diffs', $res->fetchAllAssoc());
74c55fd6 595
86f0a6af 596 // gens à l'ax mais pas chez nous
597 $res = XDB::query(
598 'SELECT ia.promo,ia.nom,ia.nom_patro,ia.prenom
599 FROM identification_ax as ia
600 LEFT JOIN auth_user_md5 AS u ON u.matricule_ax = ia.matricule_ax
601 WHERE u.nom IS NULL');
602 $page->assign('mank', $res->fetchAllAssoc());
74c55fd6 603
86f0a6af 604 // gens chez nous et pas à l'ax
605 $res = XDB::query('SELECT promo,nom,prenom FROM auth_user_md5 WHERE matricule_ax IS NULL');
606 $page->assign('plus', $res->fetchAllAssoc());
607 }
74c55fd6 608
86f0a6af 609 function handler_deaths(&$page, $promo = 0, $validate = false) {
610 $page->changeTpl('admin/deces_promo.tpl');
611 $page->assign('xorg_title','Polytechnique.org - Administration - Deces');
74c55fd6 612
86f0a6af 613 if (!$promo)
614 $promo = Env::i('promo');
615 if (Env::has('sub10')) $promo -= 10;
616 if (Env::has('sub01')) $promo -= 1;
617 if (Env::has('add01')) $promo += 1;
618 if (Env::has('add10')) $promo += 10;
74c55fd6 619
86f0a6af 620 $page->assign('promo',$promo);
74c55fd6 621
86f0a6af 622 if ($validate) {
623 $new_deces = array();
624 $res = XDB::iterRow("SELECT user_id,matricule,nom,prenom,deces FROM auth_user_md5 WHERE promo = {?}", $promo);
625 while (list($uid,$mat,$nom,$prenom,$deces) = $res->next()) {
626 $val = Env::v($mat);
627 if($val == $deces || empty($val)) continue;
628 XDB::execute('UPDATE auth_user_md5 SET deces={?} WHERE matricule = {?}', $val, $mat);
629 $new_deces[] = array('name' => "$prenom $nom", 'date' => "$val");
630 if($deces=='0000-00-00' or empty($deces)) {
631 require_once('notifs.inc.php');
632 register_watch_op($uid, WATCH_DEATH, $val);
633 require_once('user.func.inc.php');
634 user_clear_all_subs($uid, false); // by default, dead ppl do not loose their email
635 }
636 }
637 $page->assign('new_deces',$new_deces);
638 }
74c55fd6 639
86f0a6af 640 $res = XDB::iterator('SELECT matricule, nom, prenom, deces FROM auth_user_md5 WHERE promo = {?} ORDER BY nom,prenom', $promo);
641 $page->assign('decedes', $res);
642 }
74c55fd6 643
86f0a6af 644 function handler_synchro_ax(&$page, $user = null, $action = null) {
645 $page->changeTpl('admin/synchro_ax.tpl');
646 $page->assign('xorg_title','Polytechnique.org - Administration - Synchro AX');
74c55fd6 647
86f0a6af 648 require_once('synchro_ax.inc.php');
74c55fd6 649
86f0a6af 650 if (is_ax_key_missing()) {
651 $page->assign('no_private_key', true);
652 $page->run();
653 }
74c55fd6 654
86f0a6af 655 require_once('user.func.inc.php');
656
657 if ($user)
658 $login = get_user_forlife($user);
659
660 if (Env::has('user')) {
661 $login = get_user_forlife(Env::v('user'));
662 if ($login === false) {
663 return;
664 }
665 }
74c55fd6 666
86f0a6af 667 if (Env::has('mat')) {
668 $res = XDB::query(
74c55fd6 669 "SELECT alias
86f0a6af 670 FROM aliases AS a
671 INNER JOIN auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie')
672 WHERE matricule={?}", Env::i('mat'));
673 $login = $res->fetchOneCell();
674 }
74c55fd6 675
86f0a6af 676 if ($login) {
677 if ($action == 'import') {
678 ax_synchronize($login, S::v('uid'));
679 }
680 // get details from user, but looking only info that can be seen by ax
681 $user = get_user_details($login, S::v('uid'), 'ax');
682 $userax= get_user_ax($user['matricule_ax']);
683 require_once 'profil.func.inc.php';
684 $diff = diff_user_details($userax, $user, 'ax');
74c55fd6 685
86f0a6af 686 $page->assign('x', $user);
687 $page->assign('diff', $diff);
688 }
689 }
74c55fd6 690
86f0a6af 691 function handler_validate(&$page) {
692 $page->changeTpl('admin/valider.tpl');
693 $page->assign('xorg_title','Polytechnique.org - Administration - Valider une demande');
694 require_once("validations.inc.php");
74c55fd6 695
86f0a6af 696 if(Env::has('uid') && Env::has('type') && Env::has('stamp')) {
697 $req = Validate::get_request(Env::v('uid'), Env::v('type'), Env::v('stamp'));
698 if($req) { $req->handle_formu(); }
699 }
74c55fd6 700
cfb96867 701 $r = XDB::iterator('SHOW COLUMNS FROM requests_answers');
702 while (($a = $r->next()) && $a['Field'] != 'category');
703 $page->assign('categories', $categories = explode(',', str_replace("'", '', substr($a['Type'], 5, -1))));
74c55fd6 704
cfb96867 705 $hidden = array();
706 if (Post::has('hide')) {
74c55fd6 707 $hide = array();
708 foreach ($categories as $cat)
cfb96867 709 if (!Post::v($cat)) {
710 $hidden[$cat] = 1;
711 $hide[] = $cat;
712 }
713 setcookie('hide_requests', join(',',$hide), time()+(count($hide)?25920000:(-3600)), '/', '', 0);
714 } elseif (Env::has('hide_requests')) {
715 foreach (explode(',',Env::v('hide_requests')) as $hide_type)
716 $hidden[$hide_type] = true;
717 }
718 $page->assign('hide_requests', $hidden);
74c55fd6 719
86f0a6af 720 $page->assign('vit', new ValidateIterator());
721 }
e18888f4 722 function handler_validate_answers(&$page, $action = 'list', $id = null) {
723 require_once('../classes/PLTableEditor.php');
724 $page->assign('xorg_title','Polytechnique.org - Administration - Réponses automatiques de validation');
725 $page->assign('title', 'Gestion des réponses automatiques');
726 $table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id');
727 $table_editor->describe('category','catégorie',true);
728 $table_editor->describe('title','titre',true);
729 $table_editor->describe('answer','texte',false);
730 $table_editor->apply($page, $action, $id);
731 }
e7ae7df9 732 function handler_skins(&$page, $action = 'list', $id = null) {
733 require_once('../classes/PLTableEditor.php');
734 $page->assign('xorg_title','Polytechnique.org - Administration - Skins');
735 $page->assign('title', 'Gestion des skins');
736 $table_editor = new PLTableEditor('admin/skins','skins','id');
737 $table_editor->describe('name','nom',true);
738 $table_editor->describe('skin_tpl','nom du template',true);
739 $table_editor->describe('auteur','auteur',false);
740 $table_editor->describe('comment','commentaire',true);
741 $table_editor->describe('date','date',false);
742 $table_editor->describe('ext','extension du screenshot',false);
743 $table_editor->apply($page, $action, $id);
74c55fd6 744 }
e7ae7df9 745 function handler_postfix_blacklist(&$page, $action = 'list', $id = null) {
746 require_once('../classes/PLTableEditor.php');
747 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Blacklist');
748 $page->assign('title', 'Blacklist de postfix');
749 $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true);
750 $table_editor->describe('reject_text','Texte de rejet',true);
751 $table_editor->describe('email','email',true);
752 $table_editor->apply($page, $action, $id);
74c55fd6 753 }
e7ae7df9 754 function handler_postfix_whitelist(&$page, $action = 'list', $id = null) {
755 require_once('../classes/PLTableEditor.php');
756 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Whitelist');
757 $page->assign('title', 'Whitelist de postfix');
758 $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true);
759 $table_editor->describe('email','email',true);
760 $table_editor->apply($page, $action, $id);
74c55fd6 761 }
e7ae7df9 762 function handler_logger_actions(&$page, $action = 'list', $id = null) {
763 require_once('../classes/PLTableEditor.php');
764 $page->assign('xorg_title','Polytechnique.org - Administration - Actions');
765 $page->assign('title', 'Gestion des actions de logger');
766 $table_editor = new PLTableEditor('admin/logger/actions','logger.actions','id');
767 $table_editor->describe('text','intitulé',true);
768 $table_editor->describe('description','description',true);
769 $table_editor->apply($page, $action, $id);
74c55fd6 770 }
e7ae7df9 771 function handler_downtime(&$page, $action = 'list', $id = null) {
772 require_once('../classes/PLTableEditor.php');
773 $page->assign('xorg_title','Polytechnique.org - Administration - Coupures');
774 $page->assign('title', 'Gestion des coupures');
775 $table_editor = new PLTableEditor('admin/downtime','coupures','id');
776 $table_editor->describe('debut','date',true);
777 $table_editor->describe('duree','durée',false);
778 $table_editor->describe('resume','résumé',true);
779 $table_editor->describe('services','services affectés',true);
780 $table_editor->describe('description','description',false);
781 $table_editor->apply($page, $action, $id);
74c55fd6 782 }
3aec1c21 783 function handler_wiki(&$page, $action='list') {
784 require_once 'wiki.inc.php';
74c55fd6 785
3aec1c21 786 // update wiki perms
787 if ($action == 'update') {
788 $perms_read = Post::v('read');
789 $perms_edot = Post::v('edit');
790 if ($perms_read || $perms_edit) {
791 foreach ($_POST as $wiki_page => $val) if ($val == 'on') {
792 $wiki_page = str_replace('_', '/', $wiki_page);
793 if (!$perms_read || !$perms_edit)
74c55fd6 794 list($perms0, $perms1) = wiki_get_perms($wiki_page);
3aec1c21 795 if ($perms_read)
796 $perms0 = $perms_read;
797 if ($perms_edit)
798 $perms1 = $perms_edit;
799 wiki_set_perms($wiki_page, $perms0, $perms1);
800 }
801 }
802 }
74c55fd6 803
3aec1c21 804 $perms = wiki_perms_options();
74c55fd6 805
3aec1c21 806 // list wiki pages and their perms
807 $wiki_pages = array();
808 $dir = wiki_work_dir();
809 if (is_dir($dir)) {
810 if ($dh = opendir($dir)) {
811 while (($file = readdir($dh)) !== false) if (substr($file,0,1) >= 'A' && substr($file,0,1) <= 'Z') {
812 list($read,$edit) = wiki_get_perms($file);
813 $wiki_pages[$file] = array('read' => $perms[$read], 'edit' => $perms[$edit]);
814 }
815 closedir($dh);
816 }
817 }
818 ksort($wiki_pages);
74c55fd6 819
3aec1c21 820 $page->changeTpl('admin/wiki.tpl');
74c55fd6 821 $page->assign('wiki_pages', $wiki_pages);
3aec1c21 822 $page->assign('perms_opts', $perms);
823 }
86f0a6af 824}
825
826?>