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