Commit | Line | Data |
---|---|---|
92e80560 VZ |
1 | <?php |
2 | /*************************************************************************** | |
8d84c630 | 3 | * Copyright (C) 2003-2009 Polytechnique.org * |
92e80560 VZ |
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 GadgetsModule extends PLModule | |
23 | { | |
24 | function handlers() | |
25 | { | |
26 | return array( | |
27 | 'gadgets/ig-events.xml' => $this->make_hook('ig_events_xml', AUTH_PUBLIC, 'user', NO_HTTPS), | |
28 | 'gadgets/ig-events' => $this->make_hook('ig_events', AUTH_PUBLIC), | |
29 | 'gadgets/ig-search.xml' => $this->make_hook('ig_search_xml', AUTH_PUBLIC, 'user', NO_HTTPS), | |
30 | 'gadgets/ig-search' => $this->make_hook('ig_search', AUTH_PUBLIC), | |
31 | ); | |
32 | } | |
33 | ||
34 | function handler_ig_events_xml(&$page) { | |
35 | require_once 'gadgets/gadgets.inc.php'; | |
36 | init_igoogle_xml('gadgets/ig-events.xml.tpl'); | |
37 | } | |
38 | ||
39 | function handler_ig_events(&$page) { | |
40 | require_once 'gadgets/gadgets.inc.php'; | |
41 | init_igoogle_html('gadgets/ig-events.tpl', AUTH_COOKIE); | |
42 | ||
43 | $events = XDB::iterator( | |
44 | 'SELECT SQL_CALC_FOUND_ROWS | |
45 | e.id, e.titre, UNIX_TIMESTAMP(e.creation_date) AS creation_date, | |
46 | IF(u.nom_usage = "", u.nom, u.nom_usage) AS nom, u.prenom, u.promo, | |
47 | ev.user_id IS NULL AS nonlu | |
48 | FROM evenements AS e | |
49 | INNER JOIN auth_user_md5 AS u ON e.user_id = u.user_id | |
50 | LEFT JOIN evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?}) | |
51 | WHERE FIND_IN_SET("valide", e.flags) AND peremption >= NOW() | |
52 | AND (e.promo_min = 0 || e.promo_min <= {?}) | |
53 | AND (e.promo_max = 0 || e.promo_max >= {?}) | |
54 | ORDER BY e.creation_date DESC | |
55 | LIMIT {?}', | |
56 | S::i('uid'), S::i('promo'), S::i('promo'), 5); | |
57 | $page->assign('events', $events); | |
58 | $page->assign('event_count', XDB::query("SELECT FOUND_ROWS()")->fetchOneCell()); | |
59 | } | |
60 | ||
61 | function handler_ig_search_xml(&$page) { | |
62 | require_once 'gadgets/gadgets.inc.php'; | |
63 | init_igoogle_xml('gadgets/ig-search.xml.tpl'); | |
64 | } | |
65 | ||
66 | function handler_ig_search(&$page) | |
67 | { | |
68 | if (Env::has('quick') && Env::s('quick') != '') { | |
69 | require_once 'userset.inc.php'; | |
70 | $view = new SearchSet(true); | |
71 | $view->addMod('gadget', 'Gadget', true); | |
72 | $view->apply(null, $page); | |
73 | ||
74 | $nb_tot = $view->count(); | |
75 | $page->assign('result_count', $nb_tot); | |
76 | ||
77 | if (!S::logged() && $nb_tot > $globals->search->public_max) { | |
78 | $page->assign('error', 'Votre recherche a généré trop de résultats pour un affichage public.'); | |
79 | } elseif ($nb_tot > $globals->search->private_max) { | |
80 | $page->assign('error', 'Recherche trop générale.'); | |
81 | } elseif (empty($nb_tot)) { | |
82 | $page->assign('error', 'Il n\'existe personne correspondant à ces critères dans la base !'); | |
83 | } | |
84 | } | |
85 | ||
86 | require_once 'gadgets/gadgets.inc.php'; | |
87 | init_igoogle_html('gadgets/ig-search.tpl', AUTH_PUBLIC); | |
88 | } | |
89 | } | |
90 | ||
91 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
92 | ?> |