Easy access to admin page
[platal.git] / htdocs / admin / evenements.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
50a40a33 3 * Copyright (C) 2003-2006 Polytechnique.org *
0337d704 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
22require_once("xorg.inc.php");
23new_admin_page('admin/evenements.tpl');
d9a33f98 24$page->assign('xorg_title','Polytechnique.org - Administration - Evenements');
0337d704 25
5e2307dc 26$arch = Env::v('arch', 0);
27$evid = Post::i('evt_id');
0337d704 28$page->assign('arch', $arch);
29
5e2307dc 30switch(Post::v('action')) {
0337d704 31 case "Proposer":
08cce2ff 32 XDB::execute('UPDATE evenements SET titre={?}, texte={?}, peremption={?}, promo_min={?}, promo_max={?} WHERE id = {?}',
5e2307dc 33 Post::v('titre'), Post::v('texte'), Post::v('peremption'), Post::v('promo_min'), Post::v('promo_max'), $evid);
0337d704 34 break;
35
36 case "Valider":
08cce2ff 37 XDB::execute('UPDATE evenements SET creation_date = creation_date, flags = CONCAT(flags,",valide") WHERE id = {?}', $evid);
0337d704 38 break;
39
40 case "Invalider":
08cce2ff 41 XDB::execute('UPDATE evenements SET creation_date = creation_date, flags = REPLACE(flags,"valide", "") WHERE id = {?}', $evid);
0337d704 42 break;
43
44 case "Supprimer":
08cce2ff 45 XDB::execute('DELETE from evenements WHERE id = {?}', $evid);
0337d704 46 break;
47
48 case "Archiver":
08cce2ff 49 XDB::execute('UPDATE evenements SET creation_date = creation_date, flags = CONCAT(flags,",archive") WHERE id = {?}', $evid);
0337d704 50 break;
51
52 case "Desarchiver":
08cce2ff 53 XDB::execute('UPDATE evenements SET creation_date = creation_date, flags = REPLACE(flags,"archive","") WHERE id = {?}', $evid);
0337d704 54 break;
55
56 case "Editer":
08cce2ff 57 $res = XDB::query('SELECT titre, texte, peremption, promo_min, promo_max FROM evenements WHERE id={?}', $evid);
0337d704 58 list($titre, $texte, $peremption, $promo_min, $promo_max) = $res->fetchOneRow();
59 $page->assign('mode', 'edit');
60 $page->assign('titre',$titre);
61 $page->assign('texte',$texte);
62 $page->assign('promo_min',$promo_min);
63 $page->assign('promo_max',$promo_max);
64 $page->assign('peremption',$peremption);
65
66 $select = "";
67 for ($i = 1 ; $i < 30 ; $i++) {
68 $p_stamp=date("Ymd",time()+3600*24*$i);
69 $year=substr($p_stamp,0,4);
70 $month=substr($p_stamp,4,2);
71 $day=substr($p_stamp,6,2);
72
73 $select .= "<option value=\"$p_stamp\"" . (($p_stamp == strtr($peremption, array("-" => ""))) ? " selected" : "")."> $day / $month / $year</option>\n";
74 }
75 $page->assign('select',$select);
76
77 break;
78}
79
80if ($action != "Editer") {
81
82 $sql = "SELECT e.id, e.titre, e.texte,
83 DATE_FORMAT(e.creation_date,'%d/%m/%Y %T') AS creation_date,
84 DATE_FORMAT(e.peremption,'%d/%m/%Y') AS peremption,
85 e.promo_min, e.promo_max,
86 FIND_IN_SET('valide', e.flags) AS fvalide,
87 FIND_IN_SET('archive', e.flags) AS farch,
88 u.promo, u.nom, u.prenom, a.alias AS forlife
89 FROM evenements AS e
90 INNER JOIN auth_user_md5 AS u ON(e.user_id = u.user_id)
91 INNER JOIN aliases AS a ON (u.user_id = a.id AND a.type='a_vie')
92 WHERE ".($arch ? "" : "!")."FIND_IN_SET('archive',e.flags)
93 ORDER BY FIND_IN_SET('valide',e.flags), peremption";
08cce2ff 94 $page->assign('evs', XDB::iterator($sql));
0337d704 95}
96
97$page->run();
98?>