Commit | Line | Data |
---|---|---|
74e0093f | 1 | <?php |
2 | /*************************************************************************** | |
5ddeb07c | 3 | * Copyright (C) 2003-2007 Polytechnique.org * |
74e0093f | 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 | ||
22 | class EventsModule extends PLModule | |
23 | { | |
24 | function handlers() | |
25 | { | |
26 | return array( | |
1a828cd4 | 27 | 'events' => $this->make_hook('ev', AUTH_COOKIE), |
8fc4efa3 | 28 | 'rss' => $this->make_hook('rss', AUTH_PUBLIC, 'user', NO_HTTPS), |
9ed396c0 | 29 | 'events/preview' => $this->make_hook('preview', AUTH_PUBLIC, 'user', NO_AUTH), |
f62bd784 | 30 | 'events/photo' => $this->make_hook('photo', AUTH_PUBLIC), |
1a828cd4 | 31 | 'events/submit' => $this->make_hook('ev_submit', AUTH_MDP), |
92423144 | 32 | 'admin/events' => $this->make_hook('admin_events', AUTH_MDP, 'admin'), |
b829e258 | 33 | |
9ed396c0 | 34 | 'ajax/tips' => $this->make_hook('tips', AUTH_COOKIE, 'user', NO_AUTH), |
dc767839 | 35 | 'admin/tips' => $this->make_hook('admin_tips', AUTH_MDP, 'admin'), |
74e0093f | 36 | ); |
37 | } | |
38 | ||
02838718 | 39 | private function get_tips($exclude = null) |
dc767839 | 40 | { |
6ce5dee4 | 41 | global $globals; |
42 | // Add a new special tip when changing plat/al version | |
908db125 | 43 | if ($globals->version != S::v('last_version') && is_null($exclude)) { |
6ce5dee4 | 44 | XDB::execute('UPDATE auth_user_quick |
45 | SET last_version = {?} | |
46 | WHERE user_id = {?}', | |
47 | $globals->version, S::i('uid')); | |
48 | return array('id' => 0, | |
49 | 'titre' => 'Bienvenue sur la nouvelle version du site !', | |
50 | 'text' => 'Le site a été mis à jour depuis ta dernière visite vers la version ' . $globals->version | |
44837f02 FB |
51 | . '.<br /> Nous t\'invitons à <a href="review">faire un tour d\'horizon des ' |
52 | . 'nouveautés</a>.<br /><br />' | |
53 | . 'Tu peux également retrouver ces informations sur <a href="banana/xorg.m4x.innovation">' | |
54 | . 'les fora</a>, ou sur <a href="changelog">la liste exhaustive des modifications</a>', | |
6ce5dee4 | 55 | 'priorite' => 255, |
56 | 'promo_min' => 0, | |
57 | 'promo_max' => 0, | |
58 | 'state' => 'active', | |
59 | 'special' => true); | |
908db125 | 60 | } |
6ce5dee4 | 61 | |
dc767839 | 62 | $exclude = is_null($exclude) ? '' : ' AND id != ' . $exclude . ' '; |
63 | $priority = rand(0, 510); | |
64 | do { | |
65 | $priority = (int)($priority/2); | |
66 | $res = XDB::query("SELECT * | |
67 | FROM tips | |
68 | WHERE (peremption = '0000-00-00' OR peremption > CURDATE()) | |
69 | AND (promo_min = 0 OR promo_min <= {?}) | |
70 | AND (promo_max = 0 OR promo_max >= {?}) | |
71 | AND (priorite >= {?}) | |
5d617d8d | 72 | AND (state = 'active') |
dc767839 | 73 | $exclude |
74 | ORDER BY RAND() | |
75 | LIMIT 1", | |
76 | S::i('promo'), S::i('promo'), $priority); | |
77 | } while ($priority && !$res->numRows()); | |
78 | if (!$res->numRows()) { | |
79 | return null; | |
eaf30d86 | 80 | } |
dc767839 | 81 | return $res->fetchOneAssoc(); |
82 | } | |
83 | ||
02838718 | 84 | private function get_events($where, $order, array &$array, $name) |
d0e45ced | 85 | { |
86 | // affichage des evenements | |
87 | // annonces promos triées par présence d'une limite sur les promos | |
88 | // puis par dates croissantes d'expiration | |
89 | $promo = S::v('promo'); | |
eaf30d86 | 90 | $uid = S::i('uid'); |
d0e45ced | 91 | $sql = "SELECT e.id,e.titre, ev.user_id IS NULL AS nonlu |
92 | FROM evenements AS e | |
93 | LEFT JOIN evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?}) | |
9ed396c0 | 94 | WHERE FIND_IN_SET('valide', e.flags) AND peremption >= NOW() |
d0e45ced | 95 | AND (e.promo_min = 0 || e.promo_min <= {?}) |
96 | AND (e.promo_max = 0 || e.promo_max >= {?}) | |
97 | AND $where | |
98 | ORDER BY $order"; | |
99 | $sum = XDB::iterator($sql, $uid, $promo, $promo); | |
100 | if (!$sum->total()) { | |
101 | return false; | |
102 | } | |
b2bffbe6 | 103 | $sql = "SELECT e.id,e.titre,e.texte,e.post_id,a.user_id,a.nom,a.prenom,a.promo,l.alias AS forlife, |
794feea7 | 104 | p.x, p.y, p.attach IS NOT NULL AS img, FIND_IN_SET('wiki', e.flags) AS wiki |
02838718 | 105 | FROM evenements AS e |
106 | LEFT JOIN evenements_photo AS p ON (e.id = p.eid) | |
107 | INNER JOIN auth_user_md5 AS a ON e.user_id=a.user_id | |
108 | INNER JOIN aliases AS l ON ( a.user_id=l.id AND l.type='a_vie' ) | |
d0e45ced | 109 | LEFT JOIN evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?}) |
9ed396c0 | 110 | WHERE FIND_IN_SET('valide', e.flags) AND peremption >= NOW() |
d0e45ced | 111 | AND (e.promo_min = 0 || e.promo_min <= {?}) |
112 | AND (e.promo_max = 0 || e.promo_max >= {?}) | |
113 | AND ev.user_id IS NULL | |
114 | AND $where | |
115 | ORDER BY $order"; | |
116 | $evt = XDB::iterator($sql, $uid, $promo, $promo); | |
117 | $array[$name] = array('events' => $evt, 'summary' => $sum); | |
118 | return true; | |
119 | } | |
120 | ||
02838718 | 121 | private function upload_image(PlatalPage &$page, PlUpload &$upload) |
122 | { | |
123 | if (@!$_FILES['image']['tmp_name'] && !Env::v('image_url')) { | |
124 | return true; | |
125 | } | |
126 | if (!$upload->upload($_FILES['image']) && !$upload->download(Env::v('image_url'))) { | |
127 | $page->trig('Impossible de télécharger l\'image'); | |
128 | return false; | |
129 | } elseif (!$upload->isType('image')) { | |
130 | $page->trig('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG'); | |
131 | $upload->rm(); | |
132 | return false; | |
133 | } elseif (!$upload->resizeImage(200, 300, 100, 100, 32284)) { | |
134 | $page->trig('Impossible de retraiter l\'image'); | |
135 | return false; | |
136 | } | |
137 | return true; | |
138 | } | |
139 | ||
096f0dca | 140 | function handler_ev(&$page, $action = 'list', $eid = null, $pound = null) |
1a828cd4 | 141 | { |
8b1f8e12 | 142 | $page->changeTpl('events/index.tpl'); |
dc767839 | 143 | $page->addJsLink('ajax.js'); |
144 | $page->assign('tips', $this->get_tips()); | |
145 | ||
08cce2ff | 146 | $res = XDB::query('SELECT date, naissance FROM auth_user_md5 |
d0e45ced | 147 | WHERE user_id={?}', S::v('uid')); |
1a828cd4 | 148 | list($date, $naissance) = $res->fetchOneRow(); |
149 | ||
a7de4ef7 | 150 | // incitation à mettre à jour la fiche |
1a828cd4 | 151 | |
152 | $d2 = mktime(0, 0, 0, substr($date, 5, 2), substr($date, 8, 2), | |
153 | substr($date, 0, 4)); | |
154 | if( (time() - $d2) > 60 * 60 * 24 * 400 ) { | |
155 | // si fiche date de + de 400j; | |
156 | $page->assign('fiche_incitation', $date); | |
157 | } | |
158 | ||
159 | // Souhaite bon anniversaire | |
160 | ||
161 | if (substr($naissance, 5) == date('m-d')) { | |
162 | $page->assign('birthday', date('Y') - substr($naissance, 0, 4)); | |
163 | } | |
164 | ||
a7de4ef7 | 165 | // incitation à mettre une photo |
1a828cd4 | 166 | |
08cce2ff | 167 | $res = XDB::query('SELECT COUNT(*) FROM photo |
d0e45ced | 168 | WHERE uid={?}', S::v('uid')); |
1a828cd4 | 169 | $page->assign('photo_incitation', $res->fetchOneCell() == 0); |
170 | ||
a7de4ef7 | 171 | // Incitation à se géolocaliser |
1a828cd4 | 172 | require_once 'geoloc.inc.php'; |
cab08090 | 173 | $res = localize_addresses(S::v('uid', -1)); |
1a828cd4 | 174 | $page->assign('geoloc_incitation', count($res)); |
175 | ||
1a828cd4 | 176 | // ajout du lien RSS |
cab08090 | 177 | if (S::has('core_rss_hash')) { |
162370e7 | 178 | $page->setRssLink('Polytechnique.org :: News', |
179 | '/rss/'.S::v('forlife') .'/'.S::v('core_rss_hash').'/rss.xml'); | |
1a828cd4 | 180 | } |
181 | ||
182 | // cache les evenements lus et raffiche les evenements a relire | |
4e61caea | 183 | if ($action == 'read' && $eid) { |
eadff9f9 | 184 | XDB::execute('DELETE evenements_vus.* |
eaf30d86 | 185 | FROM evenements_vus AS ev |
eadff9f9 | 186 | INNER JOIN evenements AS e ON e.id = ev.evt_id |
187 | WHERE peremption < NOW()'); | |
08cce2ff | 188 | XDB::execute('REPLACE INTO evenements_vus VALUES({?},{?})', |
096f0dca | 189 | $eid, S::v('uid')); |
190 | pl_redirect('events#'.$pound); | |
1a828cd4 | 191 | } |
192 | ||
4e61caea | 193 | if ($action == 'unread' && $eid) { |
08cce2ff | 194 | XDB::execute('DELETE FROM evenements_vus |
eadff9f9 | 195 | WHERE evt_id = {?} AND user_id = {?}', |
4e61caea | 196 | $eid, S::v('uid')); |
096f0dca | 197 | pl_redirect('events#newsid'.$eid); |
1a828cd4 | 198 | } |
199 | ||
d0e45ced | 200 | $array = array(); |
9ed396c0 | 201 | $this->get_events('FIND_IN_SET(\'important\', e.flags)', 'e.creation_date DESC', $array, 'important'); |
202 | $this->get_events('e.creation_date > DATE_SUB(CURDATE(), INTERVAL 2 DAY) | |
203 | AND NOT FIND_IN_SET(\'important\', e.flags)', | |
d0e45ced | 204 | 'e.creation_date DESC', $array, 'news'); |
205 | $this->get_events('e.peremption < DATE_ADD(CURDATE(), INTERVAL 2 DAY) | |
9ed396c0 | 206 | AND e.creation_date <= DATE_SUB(CURDATE(), INTERVAL 2 DAY) |
207 | AND NOT FIND_IN_SET(\'important\', e.flags)', | |
d0e45ced | 208 | 'e.peremption, e.creation_date DESC', $array, 'end'); |
209 | $this->get_events('e.peremption >= DATE_ADD(CURDATE(), INTERVAL 2 DAY) | |
9ed396c0 | 210 | AND e.creation_date <= DATE_SUB(CURDATE(), INTERVAL 2 DAY) |
211 | AND NOT FIND_IN_SET(\'important\', e.flags)', | |
d0e45ced | 212 | 'e.peremption, e.creation_date DESC', $array, 'body'); |
213 | $page->assign_by_ref('events', $array); | |
1a828cd4 | 214 | } |
215 | ||
02838718 | 216 | function handler_photo(&$page, $eid = null, $valid = null) |
217 | { | |
218 | if ($eid && $eid != 'valid') { | |
219 | $res = XDB::query("SELECT * FROM evenements_photo WHERE eid = {?}", $eid); | |
220 | if ($res->numRows()) { | |
221 | $photo = $res->fetchOneAssoc(); | |
222 | header('Content-Type: image/' . $photo['attachmime']); | |
223 | echo $photo['attach']; | |
224 | exit; | |
225 | } | |
226 | } elseif ($eid == 'valid') { | |
227 | require_once 'validations.inc.php'; | |
228 | $valid = Validate::get_request_by_id($valid); | |
229 | if ($valid && $valid->img) { | |
230 | header('Content-Type: image/' . $valid->imgtype); | |
231 | echo $valid->img; | |
232 | exit; | |
233 | } | |
234 | } else { | |
235 | $upload = new PlUpload(S::v('forlife'), 'event'); | |
236 | if ($upload->exists() && $upload->isType('image')) { | |
237 | header('Content-Type: ' . $upload->contentType()); | |
238 | echo $upload->getContents(); | |
239 | exit; | |
240 | } | |
241 | } | |
242 | global $globals; | |
243 | header('Content-Type: image/png'); | |
244 | echo file_get_contents($globals->spoolroot . '/htdocs/images/logo.png'); | |
245 | exit; | |
246 | } | |
247 | ||
d1c97e42 | 248 | function handler_rss(&$page, $user = null, $hash = null) |
eaf30d86 | 249 | { |
d1c97e42 | 250 | require_once 'rss.inc.php'; |
eaf30d86 | 251 | |
8b1f8e12 | 252 | $uid = init_rss('events/rss.tpl', $user, $hash); |
eaf30d86 | 253 | |
d1c97e42 | 254 | $rss = XDB::iterator( |
f62bd784 | 255 | 'SELECT e.id, e.titre, e.texte, e.creation_date, e.post_id, p.attachmime IS NOT NULL AS photo, |
d1c97e42 | 256 | IF(u2.nom_usage = "", u2.nom, u2.nom_usage) AS nom, u2.prenom, u2.promo |
257 | FROM auth_user_md5 AS u | |
258 | INNER JOIN evenements AS e ON ( (e.promo_min = 0 || e.promo_min <= u.promo) | |
259 | AND (e.promo_max = 0 || e.promo_max >= u.promo) ) | |
f62bd784 | 260 | LEFT JOIN evenements_photo AS p ON (p.eid = e.id) |
d1c97e42 | 261 | INNER JOIN auth_user_md5 AS u2 ON (u2.user_id = e.user_id) |
010268b2 | 262 | WHERE u.user_id = {?} AND FIND_IN_SET("valide", e.flags) |
d1c97e42 | 263 | AND peremption >= NOW()', $uid); |
264 | $page->assign('rss', $rss); | |
db3bd146 | 265 | } |
266 | ||
267 | function handler_preview(&$page) | |
268 | { | |
db3bd146 | 269 | $page->changeTpl('events/preview.tpl', NO_SKIN); |
270 | $texte = Get::v('texte'); | |
271 | if (!is_utf8($texte)) { | |
272 | $texte = utf8_encode($texte); | |
273 | } | |
db3bd146 | 274 | $titre = Get::v('titre'); |
275 | if (!is_utf8($titre)) { | |
276 | $titre = utf8_encode($titre); | |
277 | } | |
794feea7 | 278 | $page->assign('texte', $texte); |
db3bd146 | 279 | $page->assign('titre', $titre); |
280 | header('Content-Type: text/html; charset=utf-8'); | |
281 | } | |
d1c97e42 | 282 | |
1a828cd4 | 283 | function handler_ev_submit(&$page) |
74e0093f | 284 | { |
8b1f8e12 | 285 | $page->changeTpl('events/submit.tpl'); |
db3bd146 | 286 | $page->addJsLink('ajax.js'); |
eaf30d86 | 287 | |
db3bd146 | 288 | require_once('wiki.inc.php'); |
289 | wiki_require_page('Xorg.Annonce'); | |
74e0093f | 290 | |
5e2307dc | 291 | $titre = Post::v('titre'); |
292 | $texte = Post::v('texte'); | |
293 | $promo_min = Post::i('promo_min'); | |
294 | $promo_max = Post::i('promo_max'); | |
295 | $peremption = Post::i('peremption'); | |
296 | $valid_mesg = Post::v('valid_mesg'); | |
297 | $action = Post::v('action'); | |
02838718 | 298 | $upload = new PlUpload(S::v('forlife'), 'event'); |
299 | $this->upload_image($page, $upload); | |
74e0093f | 300 | |
d1c97e42 | 301 | if (($promo_min > $promo_max && $promo_max != 0)|| |
2086ab7f | 302 | ($promo_min != 0 && ($promo_min <= 1900 || $promo_min >= 2020)) || |
303 | ($promo_max != 0 && ($promo_max <= 1900 || $promo_max >= 2020))) | |
304 | { | |
305 | $page->trig("L'intervalle de promotions n'est pas valide"); | |
306 | $action = null; | |
307 | } | |
308 | ||
74e0093f | 309 | $page->assign('titre', $titre); |
310 | $page->assign('texte', $texte); | |
311 | $page->assign('promo_min', $promo_min); | |
312 | $page->assign('promo_max', $promo_max); | |
313 | $page->assign('peremption', $peremption); | |
314 | $page->assign('valid_mesg', $valid_mesg); | |
315 | $page->assign('action', strtolower($action)); | |
02838718 | 316 | $page->assign_by_ref('upload', $upload); |
74e0093f | 317 | |
02838718 | 318 | if ($action == 'Supprimer l\'image') { |
319 | $upload->rm(); | |
320 | $page->assign('action', false); | |
321 | } elseif ($action && (!trim($texte) || !trim($titre))) { | |
1970c12b | 322 | $page->trig("L'article doit avoir un titre et un contenu"); |
db3bd146 | 323 | } elseif ($action) { |
74e0093f | 324 | require_once 'validations.inc.php'; |
325 | $evtreq = new EvtReq($titre, $texte, $promo_min, $promo_max, | |
02838718 | 326 | $peremption, $valid_mesg, S::v('uid'), $upload); |
74e0093f | 327 | $evtreq->submit(); |
328 | $page->assign('ok', true); | |
02838718 | 329 | } elseif (!Env::v('preview')) { |
330 | $upload->rm(); | |
74e0093f | 331 | } |
74e0093f | 332 | } |
b829e258 | 333 | |
dc767839 | 334 | function handler_tips(&$page, $tips = null) |
335 | { | |
493b6abe | 336 | header('Content-Type: text/html; charset="UTF-8"'); |
dc767839 | 337 | $page->changeTpl('include/tips.tpl', NO_SKIN); |
338 | $page->assign('tips', $this->get_tips($tips)); | |
339 | } | |
340 | ||
341 | function handler_admin_tips(&$page, $action = 'list', $id = null) | |
342 | { | |
343 | $page->assign('xorg_title', 'Polytechnique.org - Administration - Astuces'); | |
344 | $page->assign('title', 'Gestion des Astuces'); | |
345 | $table_editor = new PLTableEditor('admin/tips', 'tips', 'id'); | |
a7de4ef7 | 346 | $table_editor->describe('peremption', 'date de péremption', true); |
dc767839 | 347 | $table_editor->describe('promo_min', 'promo. min (0 aucune)', false); |
348 | $table_editor->describe('promo_max', 'promo. max (0 aucune)', false); | |
349 | $table_editor->describe('titre', 'titre', true); | |
5d617d8d | 350 | $table_editor->describe('state', 'actif', true); |
dc767839 | 351 | $table_editor->describe('text', 'texte (html) de l\'astuce', false); |
a7de4ef7 | 352 | $table_editor->describe('priorite', '0<=priorité<=255', true); |
3851b0a6 | 353 | $table_editor->list_on_edit(false); |
dc767839 | 354 | $table_editor->apply($page, $action, $id); |
3851b0a6 | 355 | if (($action == 'edit' && !is_null($id)) || $action == 'update') { |
3032cbd8 | 356 | $page->changeTpl('events/admin_tips.tpl'); |
357 | } | |
dc767839 | 358 | } |
359 | ||
eaf30d86 | 360 | function handler_admin_events(&$page, $action = 'list', $eid = null) |
506a46ed | 361 | { |
e2efba7d | 362 | $page->changeTpl('events/admin.tpl'); |
db3bd146 | 363 | $page->addJsLink('ajax.js'); |
92423144 | 364 | $page->assign('xorg_title','Polytechnique.org - Administration - Evenements'); |
506a46ed | 365 | $page->register_modifier('hde', 'html_entity_decode'); |
366 | ||
367 | $arch = $action == 'archives'; | |
368 | $page->assign('action', $action); | |
02838718 | 369 | |
370 | $upload = new PlUpload(S::v('forlife'), 'event'); | |
371 | if ((Env::has('preview') || Post::v('action') == "Proposer") && $eid) { | |
372 | $action = 'edit'; | |
373 | $this->upload_image($page, $upload); | |
374 | } | |
375 | ||
376 | if (Post::v('action') == 'Pas d\'image' && $eid) { | |
377 | $upload->rm(); | |
378 | XDB::execute("DELETE FROM evenements_photo WHERE eid = {?}", $eid); | |
379 | $action = 'edit'; | |
380 | } elseif (Post::v('action') == 'Supprimer l\'image' && $eid) { | |
381 | $upload->rm(); | |
382 | $action = 'edit'; | |
383 | } elseif (Post::v('action') == "Proposer" && $eid) { | |
2086ab7f | 384 | $promo_min = Post::i('promo_min'); |
385 | $promo_max = Post::i('promo_max'); | |
1b602af5 | 386 | if (($promo_min != 0 && ($promo_min <= 1900 || $promo_min >= 2020)) || |
387 | ($promo_max != 0 && ($promo_max <= 1900 || $promo_max >= 2020 || $promo_max < $promo_min))) | |
2086ab7f | 388 | { |
389 | $page->trig("L'intervalle de promotions $promo_min -> $promo_max n'est pas valide"); | |
390 | $action = 'edit'; | |
391 | } else { | |
9ed396c0 | 392 | $res = XDB::query('SELECT flags FROM evenements WHERE id = {?}', $eid); |
393 | $flags = new FlagSet($res->fetchOneCell()); | |
794feea7 | 394 | $flags->addFlag('wiki'); |
9ed396c0 | 395 | if (Post::v('important')) { |
396 | $flags->addFlag('important'); | |
397 | } else { | |
398 | $flags->rmFlag('important'); | |
eaf30d86 | 399 | } |
794feea7 | 400 | |
2086ab7f | 401 | XDB::execute('UPDATE evenements |
eaf30d86 | 402 | SET creation_date = creation_date, |
9ed396c0 | 403 | titre={?}, texte={?}, peremption={?}, promo_min={?}, promo_max={?}, |
404 | flags = {?} | |
eaf30d86 | 405 | WHERE id = {?}', |
2086ab7f | 406 | Post::v('titre'), Post::v('texte'), Post::v('peremption'), |
9ed396c0 | 407 | Post::v('promo_min'), Post::v('promo_max'), |
408 | $flags->flags(), $eid); | |
02838718 | 409 | if ($upload->exists() && list($x, $y, $type) = $upload->imageInfo()) { |
410 | XDB::execute('REPLACE INTO evenements_photo | |
411 | SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}', | |
412 | $eid, $type, $x, $y, $upload->getContents()); | |
413 | $upload->rm(); | |
414 | } | |
eaf30d86 | 415 | } |
92423144 | 416 | } |
506a46ed | 417 | |
418 | if ($action == 'edit') { | |
02838718 | 419 | $res = XDB::query('SELECT titre, texte, peremption, promo_min, promo_max, FIND_IN_SET(\'important\', flags), |
420 | attach IS NOT NULL | |
421 | FROM evenements AS e | |
422 | LEFT JOIN evenements_photo AS p ON(e.id = p.eid) | |
506a46ed | 423 | WHERE id={?}', $eid); |
02838718 | 424 | list($titre, $texte, $peremption, $promo_min, $promo_max, $important, $img) = $res->fetchOneRow(); |
506a46ed | 425 | $page->assign('titre',$titre); |
426 | $page->assign('texte',$texte); | |
427 | $page->assign('promo_min',$promo_min); | |
428 | $page->assign('promo_max',$promo_max); | |
429 | $page->assign('peremption',$peremption); | |
9ed396c0 | 430 | $page->assign('important', $important); |
02838718 | 431 | $page->assign('eid', $eid); |
432 | $page->assign('img', $img); | |
433 | $page->assign_by_ref('upload', $upload); | |
506a46ed | 434 | |
435 | $select = ""; | |
436 | for ($i = 1 ; $i < 30 ; $i++) { | |
437 | $p_stamp=date("Ymd",time()+3600*24*$i); | |
438 | $year=substr($p_stamp,0,4); | |
439 | $month=substr($p_stamp,4,2); | |
440 | $day=substr($p_stamp,6,2); | |
441 | ||
eaf30d86 | 442 | $select .= "<option value=\"$p_stamp\"" |
506a46ed | 443 | . (($p_stamp == strtr($peremption, array("-" => ""))) ? " selected" : "") |
444 | . "> $day / $month / $year</option>\n"; | |
445 | } | |
446 | $page->assign('select',$select); | |
447 | } else { | |
448 | switch ($action) { | |
449 | case 'delete': | |
450 | XDB::execute('DELETE from evenements | |
451 | WHERE id = {?}', $eid); | |
452 | break; | |
453 | ||
454 | case "archive": | |
455 | XDB::execute('UPDATE evenements | |
456 | SET creation_date = creation_date, flags = CONCAT(flags,",archive") | |
457 | WHERE id = {?}', $eid); | |
458 | break; | |
459 | ||
460 | case "unarchive": | |
461 | XDB::execute('UPDATE evenements | |
462 | SET creation_date = creation_date, flags = REPLACE(flags,"archive","") | |
463 | WHERE id = {?}', $eid); | |
464 | $action = 'archives'; | |
465 | $arch = true; | |
466 | break; | |
467 | ||
468 | case "valid": | |
469 | XDB::execute('UPDATE evenements | |
470 | SET creation_date = creation_date, flags = CONCAT(flags,",valide") | |
471 | WHERE id = {?}', $eid); | |
472 | break; | |
473 | ||
474 | case "unvalid": | |
475 | XDB::execute('UPDATE evenements | |
476 | SET creation_date = creation_date, flags = REPLACE(flags,"valide", "") | |
477 | WHERE id = {?}', $eid); | |
478 | break; | |
479 | } | |
480 | ||
481 | $pid = ($eid && $action == 'preview') ? $eid : -1; | |
482 | $sql = "SELECT e.id, e.titre, e.texte,e.id = $pid AS preview, | |
92423144 | 483 | DATE_FORMAT(e.creation_date,'%d/%m/%Y %T') AS creation_date, |
484 | DATE_FORMAT(e.peremption,'%d/%m/%Y') AS peremption, | |
485 | e.promo_min, e.promo_max, | |
486 | FIND_IN_SET('valide', e.flags) AS fvalide, | |
487 | FIND_IN_SET('archive', e.flags) AS farch, | |
794feea7 FB |
488 | u.promo, u.nom, u.prenom, a.alias AS forlife, |
489 | FIND_IN_SET('wiki', flags) AS wiki | |
92423144 | 490 | FROM evenements AS e |
491 | INNER JOIN auth_user_md5 AS u ON(e.user_id = u.user_id) | |
492 | INNER JOIN aliases AS a ON (u.user_id = a.id AND a.type='a_vie') | |
493 | WHERE ".($arch ? "" : "!")."FIND_IN_SET('archive',e.flags) | |
506a46ed | 494 | ORDER BY FIND_IN_SET('valide',e.flags), e.peremption DESC"; |
92423144 | 495 | $page->assign('evs', XDB::iterator($sql)); |
496 | } | |
506a46ed | 497 | $page->assign('arch', $arch); |
9ed396c0 | 498 | $page->assign('admin_evts', true); |
eaf30d86 | 499 | } |
74e0093f | 500 | } |
501 | ||
a7de4ef7 | 502 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
74e0093f | 503 | ?> |