Fixes entreprise validation when user only indicated the entreprise name.
[platal.git] / modules / gadgets.php
CommitLineData
92e80560
VZ
1<?php
2/***************************************************************************
9f5bd98e 3 * Copyright (C) 2003-2010 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
22class 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),
eb5a266d 28 'gadgets/ig-events' => $this->make_hook('ig_events', AUTH_PUBLIC),
92e80560 29 'gadgets/ig-search.xml' => $this->make_hook('ig_search_xml', AUTH_PUBLIC, 'user', NO_HTTPS),
eb5a266d 30 'gadgets/ig-search' => $this->make_hook('ig_search', AUTH_PUBLIC),
92e80560
VZ
31 );
32 }
33
a0b45322
FB
34 function handler_ig_events_xml(&$page)
35 {
92e80560
VZ
36 require_once 'gadgets/gadgets.inc.php';
37 init_igoogle_xml('gadgets/ig-events.xml.tpl');
38 }
39
a0b45322
FB
40 function handler_ig_events(&$page)
41 {
92e80560
VZ
42 require_once 'gadgets/gadgets.inc.php';
43 init_igoogle_html('gadgets/ig-events.tpl', AUTH_COOKIE);
44
1bf36cd1 45 $events = XDB::iterator("SELECT SQL_CALC_FOUND_ROWS
a0b45322 46 e.id, e.titre, UNIX_TIMESTAMP(e.creation_date) AS creation_date,
1bf36cd1
SJ
47 IF(u.nom_usage = '', u.nom, u.nom_usage) AS nom, u.prenom, u.promo,
48 ev.uid IS NULL AS nonlu, e.uid
49 FROM announces AS e
f280f651 50 LEFT JOIN announce_read AS ev ON (e.id = ev.evt_id AND ev.uid = {?})
1bf36cd1
SJ
51 WHERE FIND_IN_SET('valide', e.flags) AND expiration >= NOW()
52 ORDER BY e.creation_date DESC", S::i('uid'));
92e80560 53 $page->assign('event_count', XDB::query("SELECT FOUND_ROWS()")->fetchOneCell());
a0b45322
FB
54
55 Platal::load('events', 'feed.inc.php');
56 $user = S::user();
57 $data = array();
58 while ($e = PlFeed::nextEvent($events, $user)) {
59 $data[] = $e;
60 if (count($data) == 5) {
61 break;
62 }
63 }
64 $page->assign('events', $data);
92e80560
VZ
65 }
66
67 function handler_ig_search_xml(&$page) {
68 require_once 'gadgets/gadgets.inc.php';
69 init_igoogle_xml('gadgets/ig-search.xml.tpl');
70 }
71
72 function handler_ig_search(&$page)
73 {
74 if (Env::has('quick') && Env::s('quick') != '') {
75 require_once 'userset.inc.php';
76 $view = new SearchSet(true);
77 $view->addMod('gadget', 'Gadget', true);
78 $view->apply(null, $page);
79
80 $nb_tot = $view->count();
81 $page->assign('result_count', $nb_tot);
82
83 if (!S::logged() && $nb_tot > $globals->search->public_max) {
84 $page->assign('error', 'Votre recherche a généré trop de résultats pour un affichage public.');
85 } elseif ($nb_tot > $globals->search->private_max) {
86 $page->assign('error', 'Recherche trop générale.');
87 } elseif (empty($nb_tot)) {
88 $page->assign('error', 'Il n\'existe personne correspondant à ces critères dans la base !');
89 }
90 }
91
92 require_once 'gadgets/gadgets.inc.php';
93 init_igoogle_html('gadgets/ig-search.tpl', AUTH_PUBLIC);
94 }
95}
96
97// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
98?>