2 /***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class AdminModule
extends PLModule
27 'admin' => $this->make_hook('default', AUTH_MDP
, 'admin'),
28 'admin/auth-groupes-x' => $this->make_hook('authgroupesx', AUTH_MDP
, 'admin'),
29 'admin/ax-xorg' => $this->make_hook('ax_xorg', AUTH_MDP
, 'admin'),
30 'admin/binets' => $this->make_hook('binets', AUTH_MDP
, 'admin'),
31 'admin/deaths' => $this->make_hook('deaths', AUTH_MDP
, 'admin'),
32 'admin/medals' => $this->make_hook('medals', AUTH_MDP
, 'admin'),
33 'admin/downtime' => $this->make_hook('downtime', AUTH_MDP
, 'admin'),
34 'admin/events' => $this->make_hook('events', AUTH_MDP
, 'admin'),
35 'admin/formations' => $this->make_hook('formations', AUTH_MDP
, 'admin'),
36 'admin/geoloc' => $this->make_hook('geoloc', AUTH_MDP
, 'admin'),
37 'admin/geoloc/dynamap' => $this->make_hook('geoloc_dynamap', AUTH_MDP
, 'admin'),
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'),
53 'admin/trombino' => $this->make_hook('trombino', AUTH_MDP
, 'admin'),
54 'admin/user' => $this->make_hook('user', AUTH_MDP
, 'admin'),
55 'admin/validate' => $this->make_hook('validate', AUTH_MDP
, 'admin'),
56 'admin/wiki' => $this->make_hook('wiki', AUTH_MDP
, 'admin'),
60 function handler_default(&$page)
62 $page->changeTpl('admin/index.tpl');
63 $page->assign('xorg_title','Polytechnique.org - Administration');
66 function handler_postfix_delayed(&$page)
68 $page->changeTpl('admin/postfix_delayed.tpl');
69 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Retardés');
71 if (Env
::has('del')) {
73 XDB
::execute("UPDATE postfix_mailseen SET release = 'del' WHERE crc = {?}", $crc);
74 $page->trig($crc." verra tous ses mails supprimés !");
75 } elseif (Env
::has('ok')) {
77 XDB
::execute("UPDATE postfix_mailseen SET release = 'ok' WHERE crc = {?}", $crc);
78 $page->trig($crc." a le droit de passer !");
82 "SELECT crc, nb, update_time, create_time,
83 FIND_IN_SET('del', release) AS del,
84 FIND_IN_SET('ok', release) AS ok
87 ORDER BY release != ''");
89 $page->assign_by_ref('mails', $sql);
92 function handler_postfix_regexpsbounces(&$page, $new = null
) {
93 $page->changeTpl('admin/emails_bounces_re.tpl');
94 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Regexps Bounces');
95 $page->assign('new', $new);
97 if (Post
::has('submit')) {
98 foreach (Env
::v('lvl') as $id=>$val) {
100 "REPLACE INTO emails_bounces_re (id,pos,lvl,re,text) VALUES ({?}, {?}, {?}, {?}, {?})",
101 $id, $_POST['pos'][$id], $_POST['lvl'][$id], $_POST['re'][$id], $_POST['text'][$id]
106 $page->assign('bre', XDB
::iterator("SELECT * FROM emails_bounces_re ORDER BY pos"));
109 function handler_logger(&$page) {
110 $page->changeTpl('logger-view.tpl');
111 $page->assign('xorg_title','Polytechnique.org - Administration - Logs des sessions');
112 require_once('diogenes/diogenes.logger-view.inc.php');
114 if (!Env
::has('logauth')) {
115 $_REQUEST['logauth'] = 'native';
118 $logview = new DiogenesLoggerView
;
119 $logview->run($page);
121 $page->fakeDiogenes();
124 function handler_user(&$page, $login = false
) {
125 $page->changeTpl('admin/utilisateurs.tpl');
126 $page->assign('xorg_title','Polytechnique.org - Administration - Edit/Su/Log');
127 require_once("emails.inc.php");
128 require_once("user.func.inc.php");
130 if (S
::has('suid')) {
131 $page->kill("déjà en SUID !!!");
134 if (Env
::has('user_id')) {
135 $login = get_user_login(Env
::i('user_id'));
136 } elseif (Env
::has('login')) {
137 $login = get_user_login(Env
::v('login'));
140 if(Env
::has('logs_button') && $login) {
141 pl_redirect("admin/logger?login=$login&year=".date('Y')."&month=".date('m'));
144 if (Env
::has('ax_button') && $login) {
145 pl_redirect("admin/synchro_ax/$login");
148 if(Env
::has('suid_button') && $login) {
149 $_SESSION['log']->log("suid_start", "login by ".S
::v('forlife'));
150 $_SESSION['suid'] = $_SESSION;
151 $r = XDB
::query("SELECT id FROM aliases WHERE alias={?}", $login);
152 if($uid = $r->fetchOneCell()) {
153 start_connexion($uid,true
);
159 $r = XDB
::query("SELECT *, a.alias AS forlife, u.flags AS sexe
160 FROM auth_user_md5 AS u
161 INNER JOIN aliases AS a ON ( a.id = u.user_id AND a.alias={?} AND type!='homonyme' )", $login);
162 $mr = $r->fetchOneAssoc();
164 $redirect = new Redirect($mr['user_id']);
166 // Check if there was a submission
167 foreach($_POST as $key => $val) {
170 $email = trim(Env
::v('email'));
171 if (!isvalid_email_redirection($email)) {
172 $page->trig("invalid email $email");
174 $redirect->add_email($email);
175 $page->trig("Ajout de $email effectué");
181 $redirect->delete_email($val);
187 XDB
::execute("DELETE FROM aliases WHERE id={?} AND alias={?}
188 AND type!='a_vie' AND type!='homonyme'", $mr['user_id'], $val);
189 fix_bestalias($mr['user_id']);
190 $page->trig($val." a été supprimé");
195 $redirect->modify_one_email($val, true
);
198 case "deactivate_fwd":
200 $redirect->modify_one_email($val, false
);
204 XDB
::execute("INSERT INTO aliases (id,alias,type) VALUES ({?}, {?}, 'alias')",
205 $mr['user_id'], Env
::v('email'));
209 // 'bestalias' is the first bit of the set : 1
210 // 255 is the max for flags (8 sets max)
211 XDB
::execute("UPDATE aliases SET flags= flags & (255 - 1) WHERE id={?}", $mr['user_id']);
212 XDB
::execute("UPDATE aliases
214 WHERE id={?} AND alias={?}", $mr['user_id'], $val);
220 require_once('secure_hash.inc.php');
221 $pass_encrypted = Env
::v('newpass_clair') != "********" ?
hash_encrypt(Env
::v('newpass_clair')) : Env
::v('passw');
222 $naiss = Env
::v('naissanceN');
223 $deces = Env
::v('decesN');
224 $perms = Env
::v('permsN');
225 $prenm = Env
::v('prenomN');
226 $nom = Env
::v('nomN');
227 $promo = Env
::i('promoN');
228 $sexe = Env
::v('sexeN');
229 $comm = Env
::v('commentN');
231 $query = "UPDATE auth_user_md5 SET
232 naissance = '$naiss',
234 password = '$pass_encrypted',
236 prenom = '".addslashes($prenm)."',
237 nom = '".addslashes($nom)."',
240 comment = '".addslashes($comm)."'
241 WHERE user_id = '{$mr['user_id']}'";
242 if (XDB
::execute($query)) {
243 user_reindex($mr['user_id']);
245 require_once("diogenes/diogenes.hermes.inc.php");
246 $mailer = new HermesMailer();
247 $mailer->setFrom("webmaster@polytechnique.org");
248 $mailer->addTo("web@polytechnique.org");
249 $mailer->setSubject("INTERVENTION de ".S
::v('forlife'));
250 $mailer->setTxtBody(preg_replace("/[ \t]+/", ' ', $query));
253 $page->trig("updaté correctement.");
255 if (Env
::v('nomusageN') != $mr['nom_usage']) {
256 require_once('nomusage.inc.php');
257 set_new_usage($mr['user_id'], Env
::v('nomusageN'), make_username(Env
::v('prenomN'), Env
::v('nomusageN')));
259 $r = XDB
::query("SELECT *, a.alias AS forlife, u.flags AS sexe
260 FROM auth_user_md5 AS u
261 INNER JOIN aliases AS a ON (u.user_id=a.id)
262 WHERE user_id = {?}", $mr['user_id']);
263 $mr = $r->fetchOneAssoc();
266 // DELETE FROM auth_user_md5
268 user_clear_all_subs($mr['user_id']);
269 $page->trig("'{$mr['user_id']}' a été désinscrit !");
270 require_once("diogenes/diogenes.hermes.inc.php");
271 $mailer = new HermesMailer();
272 $mailer->setFrom("webmaster@polytechnique.org");
273 $mailer->addTo("web@polytechnique.org");
274 $mailer->setSubject("INTERVENTION de ".S
::v('forlife'));
275 $mailer->setTxtBody("\nUtilisateur $login effacé");
281 $res = XDB
::query("SELECT UNIX_TIMESTAMP(start), host
283 WHERE uid={?} AND suid=0
285 LIMIT 1", $mr['user_id']);
286 list($lastlogin,$host) = $res->fetchOneRow();
287 $page->assign('lastlogin', $lastlogin);
288 $page->assign('host', $host);
290 $page->assign('aliases', XDB
::iterator(
291 "SELECT alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire
293 WHERE id = {?} AND type!='homonyme'
294 ORDER BY type!= 'a_vie'", $mr["user_id"]));
295 $page->assign('xorgmails', $xorgmails);
296 $page->assign('email_panne', $email_panne);
297 $page->assign('emails',$redirect->emails
);
299 $page->assign('mr',$mr);
302 function handler_homonyms(&$page, $op = 'list', $target = null
) {
303 $page->changeTpl('admin/homonymes.tpl');
304 $page->assign('xorg_title','Polytechnique.org - Administration - Homonymes');
305 require_once("homonymes.inc.php");
308 if (! list($prenom,$nom,$forlife,$loginbis) = select_if_homonyme($target)) {
311 $page->assign('nom',$nom);
312 $page->assign('prenom',$prenom);
313 $page->assign('forlife',$forlife);
314 $page->assign('loginbis',$loginbis);
318 $page->assign('op',$op);
319 $page->assign('target',$target);
321 // on a un $target valide, on prepare les mails
324 // on examine l'op a effectuer
327 send_warning_homonyme($prenom, $nom, $forlife, $loginbis);
328 switch_bestalias($target, $loginbis);
332 switch_bestalias($target, $loginbis);
333 XDB
::execute("UPDATE aliases SET type='homonyme',expire=NOW() WHERE alias={?}", $loginbis);
334 XDB
::execute("REPLACE INTO homonymes (homonyme_id,user_id) VALUES({?},{?})", $target, $target);
335 send_robot_homonyme($prenom, $nom, $forlife, $loginbis);
342 $res = XDB
::iterator(
343 "SELECT a.alias AS homonyme,s.id AS user_id,s.alias AS forlife,
345 IF(h.homonyme_id=s.id, a.expire, NULL) AS expire,
346 IF(h.homonyme_id=s.id, a.type, NULL) AS type
348 LEFT JOIN homonymes AS h ON (h.homonyme_id = a.id)
349 INNER JOIN aliases AS s ON (s.id = h.user_id AND s.type='a_vie')
350 INNER JOIN auth_user_md5 AS u ON (s.id=u.user_id)
351 WHERE a.type='homonyme' OR a.expire!=''
352 ORDER BY a.alias,promo");
354 while ($tab = $res->next()) {
355 $hnymes[$tab['homonyme']][] = $tab;
357 $page->assign_by_ref('hnymes',$hnymes);
361 function handler_ax_xorg(&$page) {
362 $page->changeTpl('admin/ax-xorg.tpl');
363 $page->assign('xorg_title','Polytechnique.org - Administration - AX/X.org');
365 // liste des différences
367 '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
368 FROM auth_user_md5 AS u
369 INNER JOIN identification_ax AS ia ON u.matricule_ax = ia.matricule_ax
370 WHERE (SOUNDEX(u.nom) != SOUNDEX(ia.nom) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom)
371 AND SOUNDEX(u.nom) != SOUNDEX(ia.nom_patro) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom_patro))
372 OR u.prenom != ia.prenom OR (u.promo != ia.promo AND u.promo != ia.promo+1 AND u.promo != ia.promo-1)
373 ORDER BY u.promo,u.nom,u.prenom');
374 $page->assign('diffs', $res->fetchAllAssoc());
376 // gens à l'ax mais pas chez nous
378 'SELECT ia.promo,ia.nom,ia.nom_patro,ia.prenom
379 FROM identification_ax as ia
380 LEFT JOIN auth_user_md5 AS u ON u.matricule_ax = ia.matricule_ax
381 WHERE u.nom IS NULL');
382 $page->assign('mank', $res->fetchAllAssoc());
384 // gens chez nous et pas à l'ax
385 $res = XDB
::query('SELECT promo,nom,prenom FROM auth_user_md5 WHERE matricule_ax IS NULL');
386 $page->assign('plus', $res->fetchAllAssoc());
389 function handler_deaths(&$page, $promo = 0, $validate = false
) {
390 $page->changeTpl('admin/deces_promo.tpl');
391 $page->assign('xorg_title','Polytechnique.org - Administration - Deces');
394 $promo = Env
::i('promo');
395 if (Env
::has('sub10')) $promo -= 10;
396 if (Env
::has('sub01')) $promo -= 1;
397 if (Env
::has('add01')) $promo +
= 1;
398 if (Env
::has('add10')) $promo +
= 10;
400 $page->assign('promo',$promo);
403 $new_deces = array();
404 $res = XDB
::iterRow("SELECT user_id,matricule,nom,prenom,deces FROM auth_user_md5 WHERE promo = {?}", $promo);
405 while (list($uid,$mat,$nom,$prenom,$deces) = $res->next()) {
407 if($val == $deces ||
empty($val)) continue;
408 XDB
::execute('UPDATE auth_user_md5 SET deces={?} WHERE matricule = {?}', $val, $mat);
409 $new_deces[] = array('name' => "$prenom $nom", 'date' => "$val");
410 if($deces=='0000-00-00' or empty($deces)) {
411 require_once('notifs.inc.php');
412 register_watch_op($uid, WATCH_DEATH
, $val);
413 require_once('user.func.inc.php');
414 user_clear_all_subs($uid, false
); // by default, dead ppl do not loose their email
417 $page->assign('new_deces',$new_deces);
420 $res = XDB
::iterator('SELECT matricule, nom, prenom, deces FROM auth_user_md5 WHERE promo = {?} ORDER BY nom,prenom', $promo);
421 $page->assign('decedes', $res);
424 function handler_synchro_ax(&$page, $user = null
, $action = null
) {
425 $page->changeTpl('admin/synchro_ax.tpl');
426 $page->assign('xorg_title','Polytechnique.org - Administration - Synchro AX');
428 require_once('synchro_ax.inc.php');
430 if (is_ax_key_missing()) {
431 $page->assign('no_private_key', true
);
435 require_once('user.func.inc.php');
438 $login = get_user_forlife($user);
440 if (Env
::has('user')) {
441 $login = get_user_forlife(Env
::v('user'));
442 if ($login === false
) {
447 if (Env
::has('mat')) {
451 INNER JOIN auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie')
452 WHERE matricule={?}", Env
::i('mat'));
453 $login = $res->fetchOneCell();
457 if ($action == 'import') {
458 ax_synchronize($login, S
::v('uid'));
460 // get details from user, but looking only info that can be seen by ax
461 $user = get_user_details($login, S
::v('uid'), 'ax');
462 $userax= get_user_ax($user['matricule_ax']);
463 require_once 'profil.func.inc.php';
464 $diff = diff_user_details($userax, $user, 'ax');
466 $page->assign('x', $user);
467 $page->assign('diff', $diff);
471 function handler_events(&$page, $arch) {
472 $page->changeTpl('admin/evenements.tpl');
473 $page->assign('xorg_title','Polytechnique.org - Administration - Evenements');
475 $arch = $arch == 'archives';
476 $evid = Post
::i('evt_id');
477 $page->assign('arch', $arch);
479 switch(Post
::v('action')) {
481 XDB
::execute('UPDATE evenements SET titre={?}, texte={?}, peremption={?}, promo_min={?}, promo_max={?} WHERE id = {?}',
482 Post
::v('titre'), Post
::v('texte'), Post
::v('peremption'), Post
::v('promo_min'), Post
::v('promo_max'), $evid);
486 XDB
::execute('UPDATE evenements SET creation_date = creation_date, flags = CONCAT(flags,",valide") WHERE id = {?}', $evid);
490 XDB
::execute('UPDATE evenements SET creation_date = creation_date, flags = REPLACE(flags,"valide", "") WHERE id = {?}', $evid);
494 XDB
::execute('DELETE from evenements WHERE id = {?}', $evid);
498 XDB
::execute('UPDATE evenements SET creation_date = creation_date, flags = CONCAT(flags,",archive") WHERE id = {?}', $evid);
502 XDB
::execute('UPDATE evenements SET creation_date = creation_date, flags = REPLACE(flags,"archive","") WHERE id = {?}', $evid);
506 $res = XDB
::query('SELECT titre, texte, peremption, promo_min, promo_max FROM evenements WHERE id={?}', $evid);
507 list($titre, $texte, $peremption, $promo_min, $promo_max) = $res->fetchOneRow();
508 $page->assign('mode', 'edit');
509 $page->assign('titre',$titre);
510 $page->assign('texte',$texte);
511 $page->assign('promo_min',$promo_min);
512 $page->assign('promo_max',$promo_max);
513 $page->assign('peremption',$peremption);
516 for ($i = 1 ; $i < 30 ; $i++
) {
517 $p_stamp=date("Ymd",time()+
3600*24*$i);
518 $year=substr($p_stamp,0,4);
519 $month=substr($p_stamp,4,2);
520 $day=substr($p_stamp,6,2);
522 $select .= "<option value=\"$p_stamp\"" . (($p_stamp == strtr($peremption, array("-" => ""))) ?
" selected" : "")."> $day / $month / $year</option>\n";
524 $page->assign('select',$select);
529 if ($action != "Editer") {
531 $sql = "SELECT e.id, e.titre, e.texte,
532 DATE_FORMAT(e.creation_date,'%d/%m/%Y %T') AS creation_date,
533 DATE_FORMAT(e.peremption,'%d/%m/%Y') AS peremption,
534 e.promo_min, e.promo_max,
535 FIND_IN_SET('valide', e.flags) AS fvalide,
536 FIND_IN_SET('archive', e.flags) AS farch,
537 u.promo, u.nom, u.prenom, a.alias AS forlife
539 INNER JOIN auth_user_md5 AS u ON(e.user_id = u.user_id)
540 INNER JOIN aliases AS a ON (u.user_id = a.id AND a.type='a_vie')
541 WHERE ".($arch ?
"" : "!")."FIND_IN_SET('archive',e.flags)
542 ORDER BY FIND_IN_SET('valide',e.flags), peremption";
543 $page->assign('evs', XDB
::iterator($sql));
547 function handler_newsletter(&$page, $new = false
) {
548 $page->changeTpl('admin/newsletter.tpl');
549 $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : liste');
550 require_once("newsletter.inc.php");
554 pl_redirect("admin/newsletter");
557 $page->assign_by_ref('nl_list', get_nl_slist());
560 function handler_newsletter_edit(&$page, $nid = 'last', $aid = null
, $action = 'edit') {
561 $page->changeTpl('admin/newsletter_edit.tpl');
562 $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : Edition');
563 require_once("newsletter.inc.php");
565 $nl = new NewsLetter($nid);
567 if($action == 'delete') {
568 $nl->delArticle($aid);
569 pl_redirect("admin/newsletter/edit/$nid");
572 if($aid == 'update') {
573 $nl->_title
= Post
::v('title');
574 $nl->_date
= Post
::v('date');
575 $nl->_head
= Post
::v('head');
579 if(Post
::v('save')) {
580 $art = new NLArticle(Post
::v('title'), Post
::v('body'), Post
::v('append'),
581 $aid, Post
::v('cid'), Post
::v('pos'));
582 $nl->saveArticle($art);
583 pl_redirect("admin/newsletter/edit/$nid");
586 if($action == 'edit') {
588 if(Post
::has('title')) {
589 $art = new NLArticle(Post
::v('title'), Post
::v('body'), Post
::v('append'),
590 $eaid, Post
::v('cid'), Post
::v('pos'));
592 $art = ($eaid == 'new') ?
new NLArticle() : $nl->getArt($eaid);
594 $page->assign('art', $art);
597 $page->assign_by_ref('nl',$nl);
600 function handler_lists(&$page) {
601 $page->changeTpl('admin/lists.tpl');
602 $page->assign('xorg_title','Polytechnique.org - Administration - Mailing lists');
603 require_once 'lists.inc.php';
605 $client =& lists_xmlrpc(S
::v('uid'), S
::v('password'));
606 $listes = $client->get_all_lists();
607 $page->assign_by_ref('listes',$listes);
610 function handler_validate(&$page) {
611 $page->changeTpl('admin/valider.tpl');
612 $page->assign('xorg_title','Polytechnique.org - Administration - Valider une demande');
613 require_once("validations.inc.php");
615 if(Env
::has('uid') && Env
::has('type') && Env
::has('stamp')) {
616 $req = Validate
::get_request(Env
::v('uid'), Env
::v('type'), Env
::v('stamp'));
617 if($req) { $req->handle_formu(); }
620 $page->assign('vit', new ValidateIterator());
623 function handler_geoloc(&$page, $action = false
) {
624 $page->changeTpl('admin/geoloc.tpl');
625 require_once("geoloc.inc.php");
626 $page->assign('xorg_title','Polytechnique.org - Administration - Geolocalisation');
630 if (Env
::has('id') && is_numeric(Env
::v('id'))) {
631 if (synchro_city(Env
::v('id'))) $nb_synchro ++
;
634 if ($action == 'missinglat') {
635 $res = XDB
::iterRow("SELECT id FROM geoloc_city WHERE lat = 0 AND lon = 0");
636 while ($a = $res->next()) if (synchro_city($a[0])) $nb_synchro++
;
640 $page->trig(($nb_synchro > 1)?
($nb_synchro." villes ont été synchronisées"):"Une ville a été synchronisée");
642 $res = XDB
::query("SELECT COUNT(*) FROM geoloc_city WHERE lat = 0 AND lon = 0");
643 $page->assign("nb_missinglat", $res->fetchOneCell());
646 function handler_geoloc_dynamap(&$page, $action = false
) {
647 $page->changeTpl('admin/geoloc_dynamap.tpl');
649 if ($action == 'cities_not_on_map') {
650 require_once('geoloc.inc.php');
651 if (!fix_cities_not_on_map(20))
652 $page->trig("Impossible d'accéder au webservice");
657 if ($action == 'smallest_maps') {
658 require_once('geoloc.inc.php');
659 set_smallest_levels();
662 if ($action == 'precise_coordinates') {
663 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");
666 if ($action == 'newmaps') {
667 require_once('geoloc.inc.php');
668 if (!get_new_maps(Env
::v('url')))
669 $page->trig("Impossible d'accéder aux nouvelles cartes");
672 $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");
673 $missing = $countMissing->fetchOneCell();
675 $countNoSmallest = XDB
::query("SELECT SUM(IF(infos = 'smallest',1,0)) AS n FROM geoloc_city_in_maps GROUP BY city_id ORDER BY n");
676 $noSmallest = $countNoSmallest->fetchOneCell() == 0;
678 $countNoCoordinates = XDB
::query("SELECT COUNT(*) FROM adresses WHERE cityid IS NOT NULL AND glat = 0 AND glng = 0");
679 $noCoordinates = $countNoCoordinates->fetchOneCell();
681 if (isset($refresh) && $missing) {
682 $page->assign("xorg_extra_header", "<meta http-equiv='Refresh' content='3'/>");
684 $page->assign("nb_cities_not_on_map", $missing);
685 $page->assign("no_smallest", $noSmallest);
686 $page->assign("no_coordinates", $noCoordinates);
689 function handler_trombino(&$page, $uid = null
, $action = null
) {
690 $page->changeTpl('admin/admin_trombino.tpl');
691 $page->assign('xorg_title','Polytechnique.org - Administration - Trombino');
692 $page->assign('uid', $uid);
695 "SELECT a.alias,promo
696 FROM auth_user_md5 AS u
697 INNER JOIN aliases AS a ON ( u.user_id = a.id AND type='a_vie' )
698 WHERE user_id = {?}", $uid);
699 list($forlife, $promo) = $q->fetchOneRow();
704 header("Content-type: image/jpeg");
705 readfile("/home/web/trombino/photos".$promo."/".$forlife.".jpg");
710 $data = file_get_contents($_FILES['userfile']['tmp_name']);
711 list($x, $y) = getimagesize($_FILES['userfile']['tmp_name']);
712 $mimetype = substr($_FILES['userfile']['type'], 6);
713 unlink($_FILES['userfile']['tmp_name']);
715 "REPLACE INTO photo SET uid={?}, attachmime = {?}, attach={?}, x={?}, y={?}",
716 $uid, $mimetype, $data, $x, $y);
720 XDB
::execute('DELETE FROM photo WHERE uid = {?}', $uid);
724 $page->assign('forlife', $forlife);
727 function handler_binets(&$page, $action = 'list', $id = null
) {
728 require_once('../classes/PLTableEditor.php');
729 $page->assign('xorg_title','Polytechnique.org - Administration - Binets');
730 $page->assign('title', 'Gestion des binets');
731 $table_editor = new PLTableEditor('admin/binets', 'binets_def', 'id');
732 $table_editor->add_join_table('binets_ins','binet_id',true
);
733 $table_editor->describe('text','intitulé',true
);
734 $table_editor->apply($page, $action, $id);
736 function handler_formations(&$page, $action = 'list', $id = null
) {
737 require_once('../classes/PLTableEditor.php');
738 $page->assign('xorg_title','Polytechnique.org - Administration - Formations');
739 $page->assign('title', 'Gestion des formations');
740 $table_editor = new PLTableEditor('admin/formations','applis_def','id');
741 $table_editor->add_join_table('applis_ins','aid',true
);
742 $table_editor->describe('text','intitulé',true
);
743 $table_editor->describe('url','site web',false
);
744 $table_editor->apply($page, $action, $id);
746 function handler_groupesx(&$page, $action = 'list', $id = null
) {
747 require_once('../classes/PLTableEditor.php');
748 $page->assign('xorg_title','Polytechnique.org - Administration - Groupes X');
749 $page->assign('title', 'Gestion des Groupes X');
750 $table_editor = new PLTableEditor('admin/groupes-x','groupesx_def','id');
751 $table_editor->add_join_table('groupesx_ins','gid',true
);
752 $table_editor->describe('text','intitulé',true
);
753 $table_editor->describe('url','site web',false
);
754 $table_editor->apply($page, $action, $id);
756 function handler_skins(&$page, $action = 'list', $id = null
) {
757 require_once('../classes/PLTableEditor.php');
758 $page->assign('xorg_title','Polytechnique.org - Administration - Skins');
759 $page->assign('title', 'Gestion des skins');
760 $table_editor = new PLTableEditor('admin/skins','skins','id');
761 $table_editor->describe('name','nom',true
);
762 $table_editor->describe('skin_tpl','nom du template',true
);
763 $table_editor->describe('auteur','auteur',false
);
764 $table_editor->describe('comment','commentaire',true
);
765 $table_editor->describe('date','date',false
);
766 $table_editor->describe('ext','extension du screenshot',false
);
767 $table_editor->apply($page, $action, $id);
769 function handler_authgroupesx(&$page, $action = 'list', $id = null
) {
770 require_once('../classes/PLTableEditor.php');
771 $page->assign('xorg_title','Polytechnique.org - Administration - Auth groupes X');
772 $page->assign('title', 'Gestion de l\'authentification centralisée');
773 $table_editor = new PLTableEditor('admin/auth-groupes-x','groupesx_auth','id');
774 $table_editor->describe('name','nom',true
);
775 $table_editor->describe('privkey','clé privée',false
);
776 $table_editor->describe('datafields','champs renvoyés',true
);
777 $table_editor->apply($page, $action, $id);
779 function handler_postfix_blacklist(&$page, $action = 'list', $id = null
) {
780 require_once('../classes/PLTableEditor.php');
781 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Blacklist');
782 $page->assign('title', 'Blacklist de postfix');
783 $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true
);
784 $table_editor->describe('reject_text','Texte de rejet',true
);
785 $table_editor->describe('email','email',true
);
786 $table_editor->apply($page, $action, $id);
788 function handler_postfix_whitelist(&$page, $action = 'list', $id = null
) {
789 require_once('../classes/PLTableEditor.php');
790 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Whitelist');
791 $page->assign('title', 'Whitelist de postfix');
792 $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true
);
793 $table_editor->describe('email','email',true
);
794 $table_editor->apply($page, $action, $id);
796 function handler_logger_actions(&$page, $action = 'list', $id = null
) {
797 require_once('../classes/PLTableEditor.php');
798 $page->assign('xorg_title','Polytechnique.org - Administration - Actions');
799 $page->assign('title', 'Gestion des actions de logger');
800 $table_editor = new PLTableEditor('admin/logger/actions','logger.actions','id');
801 $table_editor->describe('text','intitulé',true
);
802 $table_editor->describe('description','description',true
);
803 $table_editor->apply($page, $action, $id);
805 function handler_downtime(&$page, $action = 'list', $id = null
) {
806 require_once('../classes/PLTableEditor.php');
807 $page->assign('xorg_title','Polytechnique.org - Administration - Coupures');
808 $page->assign('title', 'Gestion des coupures');
809 $table_editor = new PLTableEditor('admin/downtime','coupures','id');
810 $table_editor->describe('debut','date',true
);
811 $table_editor->describe('duree','durée',false
);
812 $table_editor->describe('resume','résumé',true
);
813 $table_editor->describe('services','services affectés',true
);
814 $table_editor->describe('description','description',false
);
815 $table_editor->apply($page, $action, $id);
817 function handler_newsletter_cat(&$page, $action = 'list', $id = null
) {
818 require_once('../classes/PLTableEditor.php');
819 $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : Catégories');
820 $page->assign('title', 'Gestion des catégories de la newsletter');
821 $table_editor = new PLTableEditor('admin/newsletter/categories','newsletter_cat','cid');
822 $table_editor->describe('titre','intitulé',true
);
823 $table_editor->describe('pos','position',true
);
824 $table_editor->apply($page, $action, $id);
826 function handler_payments(&$page, $action = 'list', $id = null
) {
827 require_once('../classes/PLTableEditor.php');
828 $page->assign('xorg_title','Polytechnique.org - Administration - Paiements');
829 $page->assign('title', 'Gestion des télépaiements');
830 $table_editor = new PLTableEditor('admin/payments','paiement.paiements','id');
831 $table_editor->add_join_table('paiement.transactions','ref',true
);
832 $table_editor->describe('text','intitulé',true
);
833 $table_editor->describe('url','site web',false
);
834 $table_editor->describe('montant_def','montant par défaut',false
);
835 $table_editor->describe('montant_min','montant minimum',false
);
836 $table_editor->describe('montant_max','montant maximum',false
);
837 $table_editor->describe('mail','email contact',true
);
838 $table_editor->describe('confirmation','message confirmation',false
);
839 $table_editor->apply($page, $action, $id);
841 function handler_medals(&$page, $action = 'list', $id = null
) {
842 require_once('../classes/PLTableEditor.php');
843 $page->assign('xorg_title','Polytechnique.org - Administration - Distinctions');
844 $page->assign('title', 'Gestion des Distinctions');
845 $table_editor = new PLTableEditor('admin/medals','profile_medals','id');
846 $table_editor->describe('text', 'intitulé', true
);
847 $table_editor->describe('img', 'nom de l\'image', false
);
848 $table_editor->apply($page, $action, $id);
849 if ($id && $action == 'edit') {
850 $page->changeTpl('admin/gerer_decos.tpl');
854 if (Post
::v('act') == 'del') {
855 XDB
::execute('DELETE FROM profile_medals_grades WHERE mid={?} AND gid={?}', $mid, Post
::i('gid'));
856 } elseif (Post
::v('act') == 'new') {
857 XDB
::execute('INSERT INTO profile_medals_grades (mid,gid) VALUES({?},{?})',
858 $mid, max(array_keys(Post
::v('grades', array(0))))+
1);
860 foreach (Post
::v('grades', array()) as $gid=>$text) {
861 XDB
::execute('UPDATE profile_medals_grades SET pos={?}, text={?} WHERE gid={?}', $_POST['pos'][$gid], $text, $gid);
864 $res = XDB
::iterator('SELECT gid, text, pos FROM profile_medals_grades WHERE mid={?} ORDER BY pos', $mid);
865 $page->assign('grades', $res);
868 function handler_wiki(&$page, $action='list') {
869 require_once 'wiki.inc.php';
872 if ($action == 'update') {
873 $perms_read = Post
::v('read');
874 $perms_edot = Post
::v('edit');
875 if ($perms_read ||
$perms_edit) {
876 foreach ($_POST as $wiki_page => $val) if ($val == 'on') {
877 $wiki_page = str_replace('_', '/', $wiki_page);
878 if (!$perms_read ||
!$perms_edit)
879 list($perms0, $perms1) = wiki_get_perms($wiki_page);
881 $perms0 = $perms_read;
883 $perms1 = $perms_edit;
884 wiki_set_perms($wiki_page, $perms0, $perms1);
889 $perms = wiki_perms_options();
891 // list wiki pages and their perms
892 $wiki_pages = array();
893 $dir = wiki_work_dir();
895 if ($dh = opendir($dir)) {
896 while (($file = readdir($dh)) !== false
) if (substr($file,0,1) >= 'A' && substr($file,0,1) <= 'Z') {
897 list($read,$edit) = wiki_get_perms($file);
898 $wiki_pages[$file] = array('read' => $perms[$read], 'edit' => $perms[$edit]);
905 $page->changeTpl('admin/wiki.tpl');
906 $page->assign('wiki_pages', $wiki_pages);
907 $page->assign('perms_opts', $perms);