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/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'),
32 'admin/users' => $this->make_hook('user', AUTH_MDP
, 'admin'),
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'),
49 function handler_default(&$page)
51 $page->changeTpl('admin/index.tpl');
52 $page->assign('xorg_title','Polytechnique.org - Administration');
55 function handler_postfix_delayed(&$page)
57 $page->changeTpl('admin/postfix_delayed.tpl');
58 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Retardés');
60 if (Env
::has('del')) {
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')) {
66 XDB
::execute("UPDATE postfix_mailseen SET release = 'ok' WHERE crc = {?}", $crc);
67 $page->trig($crc." a le droit de passer !");
71 "SELECT crc, nb, update_time, create_time,
72 FIND_IN_SET('del', release) AS del,
73 FIND_IN_SET('ok', release) AS ok
76 ORDER BY release != ''");
78 $page->assign_by_ref('mails', $sql);
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);
86 if (Post
::has('submit')) {
87 foreach (Env
::v('lvl') as $id=>$val) {
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]
95 $page->assign('bre', XDB
::iterator("SELECT * FROM emails_bounces_re ORDER BY pos"));
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');
103 if (!Env
::has('logauth')) {
104 $_REQUEST['logauth'] = 'native';
107 $logview = new DiogenesLoggerView
;
108 $logview->run($page);
110 $page->fakeDiogenes();
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");
119 if (S
::has('suid')) {
120 $page->kill("déjà en SUID !!!");
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'));
129 if(Env
::has('logs_button') && $login) {
130 pl_redirect("admin/logger?login=$login&year=".date('Y')."&month=".date('m'));
133 if (Env
::has('ax_button') && $login) {
134 pl_redirect("admin/synchro_ax/$login");
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
);
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();
153 $redirect = new Redirect($mr['user_id']);
155 // Check if there was a submission
156 foreach($_POST as $key => $val) {
159 $email = trim(Env
::v('email'));
160 if (!isvalid_email_redirection($email)) {
161 $page->trig("invalid email $email");
163 $redirect->add_email($email);
164 $page->trig("Ajout de $email effectué");
170 $redirect->delete_email($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é");
184 $redirect->modify_one_email($val, true
);
187 case "deactivate_fwd":
189 $redirect->modify_one_email($val, false
);
193 XDB
::execute("INSERT INTO aliases (id,alias,type) VALUES ({?}, {?}, 'alias')",
194 $mr['user_id'], Env
::v('email'));
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
203 WHERE id={?} AND alias={?}", $mr['user_id'], $val);
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');
219 $query = "UPDATE auth_user_md5 SET
220 naissance = '$naiss',
221 password = '$pass_encrypted',
223 prenom = '".addslashes($prenm)."',
224 nom = '".addslashes($nom)."',
227 comment = '".addslashes($comm)."'
228 WHERE user_id = '{$mr['user_id']}'";
229 if (XDB
::execute($query)) {
230 user_reindex($mr['user_id']);
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));
240 $page->trig("updaté correctement.");
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')));
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();
253 // DELETE FROM auth_user_md5
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é");
268 $res = XDB
::query("SELECT UNIX_TIMESTAMP(start), host
270 WHERE uid={?} AND suid=0
272 LIMIT 1", $mr['user_id']);
273 list($lastlogin,$host) = $res->fetchOneRow();
274 $page->assign('lastlogin', $lastlogin);
275 $page->assign('host', $host);
277 $page->assign('aliases', XDB
::iterator(
278 "SELECT alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire
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
);
286 $page->assign('mr',$mr);
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");
295 if (! list($prenom,$nom,$forlife,$loginbis) = select_if_homonyme($target)) {
298 $page->assign('nom',$nom);
299 $page->assign('prenom',$prenom);
300 $page->assign('forlife',$forlife);
301 $page->assign('loginbis',$loginbis);
305 $page->assign('op',$op);
306 $page->assign('target',$target);
308 // on a un $target valide, on prepare les mails
311 // on examine l'op a effectuer
314 send_warning_homonyme($prenom, $nom, $forlife, $loginbis);
315 switch_bestalias($target, $loginbis);
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);
329 $res = XDB
::iterator(
330 "SELECT a.alias AS homonyme,s.id AS user_id,s.alias AS forlife,
332 IF(h.homonyme_id=s.id, a.expire, NULL) AS expire,
333 IF(h.homonyme_id=s.id, a.type, NULL) AS type
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");
341 while ($tab = $res->next()) {
342 $hnymes[$tab['homonyme']][] = $tab;
344 $page->assign_by_ref('hnymes',$hnymes);
348 function handler_ax_xorg(&$page) {
349 $page->changeTpl('admin/ax-xorg.tpl');
350 $page->assign('xorg_title','Polytechnique.org - Administration - AX/X.org');
352 // liste des différences
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());
363 // gens à l'ax mais pas chez nous
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());
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());
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');
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;
387 $page->assign('promo',$promo);
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()) {
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
404 $page->assign('new_deces',$new_deces);
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);
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');
415 require_once('synchro_ax.inc.php');
417 if (is_ax_key_missing()) {
418 $page->assign('no_private_key', true
);
422 require_once('user.func.inc.php');
425 $login = get_user_forlife($user);
427 if (Env
::has('user')) {
428 $login = get_user_forlife(Env
::v('user'));
429 if ($login === false
) {
434 if (Env
::has('mat')) {
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();
444 if ($action == 'import') {
445 ax_synchronize($login, S
::v('uid'));
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');
453 $page->assign('x', $user);
454 $page->assign('diff', $diff);
458 function handler_events(&$page, $arch) {
459 $page->changeTpl('admin/evenements.tpl');
460 $page->assign('xorg_title','Polytechnique.org - Administration - Evenements');
462 $arch = $arch == 'archives';
463 $evid = Post
::i('evt_id');
464 $page->assign('arch', $arch);
466 switch(Post
::v('action')) {
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);
473 XDB
::execute('UPDATE evenements SET creation_date = creation_date, flags = CONCAT(flags,",valide") WHERE id = {?}', $evid);
477 XDB
::execute('UPDATE evenements SET creation_date = creation_date, flags = REPLACE(flags,"valide", "") WHERE id = {?}', $evid);
481 XDB
::execute('DELETE from evenements WHERE id = {?}', $evid);
485 XDB
::execute('UPDATE evenements SET creation_date = creation_date, flags = CONCAT(flags,",archive") WHERE id = {?}', $evid);
489 XDB
::execute('UPDATE evenements SET creation_date = creation_date, flags = REPLACE(flags,"archive","") WHERE id = {?}', $evid);
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);
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);
509 $select .= "<option value=\"$p_stamp\"" . (($p_stamp == strtr($peremption, array("-" => ""))) ?
" selected" : "")."> $day / $month / $year</option>\n";
511 $page->assign('select',$select);
516 if ($action != "Editer") {
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
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));
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");
541 pl_redirect("admin/newsletter");
544 $page->assign_by_ref('nl_list', get_nl_slist());
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");
552 $nl = new NewsLetter($nid);
554 if($action == 'delete') {
555 $nl->delArticle($aid);
556 pl_redirect("admin/newsletter/edit/$nid");
559 if($aid == 'update') {
560 $nl->_title
= Post
::v('title');
561 $nl->_date
= Post
::v('date');
562 $nl->_head
= Post
::v('head');
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");
573 if($action == 'edit') {
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'));
579 $art = ($eaid == 'new') ?
new NLArticle() : $nl->getArt($eaid);
581 $page->assign('art', $art);
584 $page->assign_by_ref('nl',$nl);
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';
592 $client =& lists_xmlrpc(S
::v('uid'), S
::v('password'));
593 $listes = $client->get_all_lists();
594 $page->assign_by_ref('listes',$listes);
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");
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(); }
607 $page->assign('vit', new ValidateIterator());
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');
617 if (Env
::has('id') && is_numeric(Env
::v('id'))) {
618 if (synchro_city(Env
::v('id'))) $nb_synchro ++
;
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++
;
627 $page->trig(($nb_synchro > 1)?
($nb_synchro." villes ont été synchronisées"):"Une ville a été synchronisée");
629 $res = XDB
::query("SELECT COUNT(*) FROM geoloc_city WHERE lat = 0 AND lon = 0");
630 $page->assign("nb_missinglat", $res->fetchOneCell());
633 function handler_geoloc_dynamap(&$page, $action = false
) {
634 $page->changeTpl('admin/geoloc_dynamap.tpl');
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");
644 if ($action == 'smallest_maps') {
645 require_once('geoloc.inc.php');
646 set_smallest_levels();
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");
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");
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();
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;
665 $countNoCoordinates = XDB
::query("SELECT COUNT(*) FROM adresses WHERE cityid IS NOT NULL AND glat = 0 AND glng = 0");
666 $noCoordinates = $countNoCoordinates->fetchOneCell();
668 if (isset($refresh) && $missing) {
669 $page->assign("xorg_extra_header", "<meta http-equiv='Refresh' content='3'/>");
671 $page->assign("nb_cities_not_on_map", $missing);
672 $page->assign("no_smallest", $noSmallest);
673 $page->assign("no_coordinates", $noCoordinates);
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);
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();
691 header("Content-type: image/jpeg");
692 readfile("/home/web/trombino/photos".$promo."/".$forlife.".jpg");
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']);
702 "REPLACE INTO photo SET uid={?}, attachmime = {?}, attach={?}, x={?}, y={?}",
703 $uid, $mimetype, $data, $x, $y);
707 XDB
::execute('DELETE FROM photo WHERE uid = {?}', $uid);
711 $page->assign('forlife', $forlife);