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