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