we don't need diogenes session anymore
[platal.git] / modules / events.php
CommitLineData
74e0093f 1<?php
2/***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
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 EventsModule extends PLModule
23{
24 function handlers()
25 {
26 return array(
1a828cd4 27 'events' => $this->make_hook('ev', AUTH_COOKIE),
28 'events/submit' => $this->make_hook('ev_submit', AUTH_MDP),
b829e258 29
164ca57a 30 'nl' => $this->make_hook('nl', AUTH_COOKIE),
31 'nl/show' => $this->make_hook('nl_show', AUTH_COOKIE),
32 'nl/submit' => $this->make_hook('nl_submit', AUTH_COOKIE),
74e0093f 33 );
34 }
35
1a828cd4 36 function handler_ev(&$page)
37 {
38 global $globals;
39
40 $page->changeTpl('login.tpl');
41
42 $res = $globals->xdb->query('SELECT date, naissance FROM auth_user_md5
43 WHERE user_id={?}', Session::getInt('uid'));
44 list($date, $naissance) = $res->fetchOneRow();
45
46 // incitation à mettre à jour la fiche
47
48 $d2 = mktime(0, 0, 0, substr($date, 5, 2), substr($date, 8, 2),
49 substr($date, 0, 4));
50 if( (time() - $d2) > 60 * 60 * 24 * 400 ) {
51 // si fiche date de + de 400j;
52 $page->assign('fiche_incitation', $date);
53 }
54
55 // Souhaite bon anniversaire
56
57 if (substr($naissance, 5) == date('m-d')) {
58 $page->assign('birthday', date('Y') - substr($naissance, 0, 4));
59 }
60
61 // incitation à mettre une photo
62
63 $res = $globals->xdb->query('SELECT COUNT(*) FROM photo
64 WHERE uid={?}', Session::getInt('uid'));
65 $page->assign('photo_incitation', $res->fetchOneCell() == 0);
66
67 // Incitation à se géolocaliser
68 require_once 'geoloc.inc.php';
69 $res = localize_addresses(Session::getInt('uid', -1));
70 $page->assign('geoloc_incitation', count($res));
71
72 // affichage de la boîte avec quelques liens
73 require_once 'login.conf.php';
74 $pub_nbElem = $pub_nbLig * $pub_nbCol ;
75 if (count($pub_tjs) <= $pub_nbElem) {
76 $publicite = array_slice($pub_tjs, 0, $pub_nbElem);
77 } else {
78 $publicite = $pub_tjs ;
79 }
80
81 $nbAlea = $pub_nbElem - count($publicite) ;
82 if ($nbAlea > 0) {
83 $choix = array_rand($pub_rnd,$nbAlea) ;
84 foreach ($choix as $url) {
85 $publicite[$url] = $pub_rnd[$url] ;
86 }
87 }
88 $publicite = array_chunk( $publicite , $pub_nbLig , true ) ;
89 $page->assign_by_ref('publicite', $publicite);
90
91 // ajout du lien RSS
92
93 if (Session::has('core_rss_hash')) {
94 $page->assign('xorg_rss',
95 array('title' => 'Polytechnique.org :: News',
96 'href' => '/rss/'.Session::get('forlife')
97 .'/'.Session::get('core_rss_hash').'/rss.xml')
98 );
99 }
100
101 // cache les evenements lus et raffiche les evenements a relire
102 if (Env::has('lu')){
103 $globals->xdb->execute('DELETE FROM evenements_vus AS ev
104 INNER JOIN evenements AS e ON e.id = ev.evt_id
105 WHERE peremption < NOW)');
106 $globals->xdb->execute('REPLACE INTO evenements_vus VALUES({?},{?})',
107 Env::get('lu'), Session::getInt('uid'));
108 }
109
110 if (Env::has('nonlu')){
111 $globals->xdb->execute('DELETE FROM evenements_vus
112 WHERE evt_id = {?} AND user_id = {?}',
113 Env::get('nonlu'), Session::getInt('uid'));
114 }
115
116 // affichage des evenements
117 // annonces promos triées par présence d'une limite sur les promos
118 // puis par dates croissantes d'expiration
119 $promo = Session::getInt('promo');
120 $sql = "SELECT e.id,e.titre,e.texte,a.user_id,a.nom,a.prenom,a.promo,l.alias AS forlife
2f678da1 121 FROM evenements AS e
122 INNER JOIN auth_user_md5 AS a ON e.user_id=a.user_id
123 INNER JOIN aliases AS l ON ( a.user_id=l.id AND l.type='a_vie' )
124 LEFT JOIN evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?})
1a828cd4 125 WHERE FIND_IN_SET(e.flags, 'valide') AND peremption >= NOW()
126 AND (e.promo_min = 0 || e.promo_min <= {?})
127 AND (e.promo_max = 0 || e.promo_max >= {?})
128 AND ev.user_id IS NULL
129 ORDER BY (e.promo_min != 0 AND e.promo_max != 0) DESC, e.peremption";
130 $page->assign('evenement',
131 $globals->xdb->iterator($sql, Session::getInt('uid'),
132 $promo, $promo)
133 );
134
135 $sql = "SELECT e.id,e.titre, ev.user_id IS NULL AS nonlu
136 FROM evenements AS e
137 LEFT JOIN evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?})
138 WHERE FIND_IN_SET(e.flags, 'valide') AND peremption >= NOW()
139 AND (e.promo_min = 0 || e.promo_min <= {?})
140 AND (e.promo_max = 0 || e.promo_max >= {?})
141 ORDER BY (e.promo_min != 0 AND e.promo_max != 0) DESC, e.peremption";
142 $page->assign('evenement_summary',
143 $globals->xdb->iterator($sql, Session::getInt('uid'),
144 $promo, $promo)
145 );
1a828cd4 146 }
147
148 function handler_ev_submit(&$page)
74e0093f 149 {
150 global $globals;
151 $page->changeTpl('evenements.tpl');
152
153 $titre = Post::get('titre');
154 $texte = Post::get('texte');
155 $promo_min = Post::getInt('promo_min');
156 $promo_max = Post::getInt('promo_max');
157 $peremption = Post::getInt('peremption');
158 $valid_mesg = Post::get('valid_mesg');
159 $action = Post::get('action');
160
161 $page->assign('titre', $titre);
162 $page->assign('texte', $texte);
163 $page->assign('promo_min', $promo_min);
164 $page->assign('promo_max', $promo_max);
165 $page->assign('peremption', $peremption);
166 $page->assign('valid_mesg', $valid_mesg);
167 $page->assign('action', strtolower($action));
168
169 if ($action == 'Confirmer') {
170 $texte = preg_replace('/((http|ftp)+(s)?:\/\/[^<>\s]+)/i',
171 '<a href=\"\\0\">\\0</a>', $texte);
172 $texte = preg_replace('/([^,\s]+@[^,\s]+)/i',
173 '<a href=\"mailto:\\0\">\\0</a>', $texte);
174 require_once 'validations.inc.php';
175 $evtreq = new EvtReq($titre, $texte, $promo_min, $promo_max,
176 $peremption, $valid_mesg, Session::getInt('uid'));
177 $evtreq->submit();
178 $page->assign('ok', true);
179 }
180
181 $select = '';
182 for ($i = 1 ; $i < 30 ; $i++) {
183 $time = time() + 3600 * 24 * $i;
184 $p_stamp = date('Ymd', $time);
185 $year = date('Y', $time);
186 $month = date('m', $time);
187 $day = date('d', $time);
188
189 $select .= "<option value=\"$p_stamp\"";
190 if ($p_stamp == strtr($peremption, array("-" => ""))) {
191 $select .= " selected='selected'";
192 }
193 $select .= "> $day / $month / $year</option>\n";
194 }
195 $page->assign('select',$select);
74e0093f 196 }
b829e258 197
164ca57a 198 function handler_nl(&$page, $action = null)
199 {
200 require_once 'newsletter.inc.php';
201
202 $page->changeTpl('newsletter/index.tpl');
203 $page->assign('xorg_title','Polytechnique.org - Lettres mensuelles');
204
205 switch ($action) {
206 case 'out': unsubscribe_nl(); break;
207 case 'in': subscribe_nl(); break;
208 default: ;
209 }
210
211 $page->assign('nls', get_nl_state());
212 $page->assign_by_ref('nl_list', get_nl_list());
164ca57a 213 }
214
215 function handler_nl_show(&$page, $nid = 'last')
b829e258 216 {
217 $page->changeTpl('newsletter/show.tpl');
218
219 require_once 'newsletter.inc.php';
220
221 $nl = new NewsLetter($nid);
222 $page->assign_by_ref('nl', $nl);
223
224 if (Post::has('send')) {
225 $nl->sendTo(Session::get('prenom'), Session::get('nom'),
226 Session::get('bestalias'), Session::get('femme'),
227 Session::get('mail_fmt') != 'text');
228 }
b829e258 229 }
164ca57a 230
231 function handler_nl_submit(&$page)
232 {
233 $page->changeTpl('newsletter/submit.tpl');
234
235 require_once 'newsletter.inc.php';
236
237 if (Post::has('see')) {
238 $art = new NLArticle(Post::get('title'), Post::get('body'), Post::get('append'));
239 $page->assign('art', $art);
240 } elseif (Post::has('valid')) {
241 require_once('validations.inc.php');
242 $art = new NLReq(Session::getInt('uid'), Post::get('title'),
243 Post::get('body'), Post::get('append'));
244 $art->submit();
245 $page->assign('submited', true);
246 }
164ca57a 247 }
74e0093f 248}
249
250?>