8c13572befe738397d8a950be6c9d6a57e1df46e
2 /***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class EventsModule
extends PLModule
27 'events' => $this->make_hook('ev', AUTH_COOKIE
),
28 'events/submit' => $this->make_hook('ev_submit', AUTH_MDP
),
29 'admin/events' => $this->make_hook('admin_events', AUTH_MDP
, 'admin'),
31 'nl' => $this->make_hook('nl', AUTH_COOKIE
),
32 'nl/show' => $this->make_hook('nl_show', AUTH_COOKIE
),
33 'nl/submit' => $this->make_hook('nl_submit', AUTH_COOKIE
),
34 'admin/newsletter' => $this->make_hook('admin_nl', AUTH_MDP
, 'admin'),
35 'admin/newsletter/categories' => $this->make_hook('admin_nl_cat', AUTH_MDP
, 'admin'),
36 'admin/newsletter/edit' => $this->make_hook('admin_nl_edit', AUTH_MDP
, 'admin'),
40 function handler_ev(&$page)
42 $page->changeTpl('login.tpl');
44 $res = XDB
::query('SELECT date, naissance FROM auth_user_md5
45 WHERE user_id={?}', S
::v('uid'));
46 list($date, $naissance) = $res->fetchOneRow();
48 // incitation à mettre à jour la fiche
50 $d2 = mktime(0, 0, 0, substr($date, 5, 2), substr($date, 8, 2),
52 if( (time() - $d2) > 60 * 60 * 24 * 400 ) {
53 // si fiche date de + de 400j;
54 $page->assign('fiche_incitation', $date);
57 // Souhaite bon anniversaire
59 if (substr($naissance, 5) == date('m-d')) {
60 $page->assign('birthday', date('Y') - substr($naissance, 0, 4));
63 // incitation à mettre une photo
65 $res = XDB
::query('SELECT COUNT(*) FROM photo
66 WHERE uid={?}', S
::v('uid'));
67 $page->assign('photo_incitation', $res->fetchOneCell() == 0);
69 // Incitation à se géolocaliser
70 require_once 'geoloc.inc.php';
71 $res = localize_addresses(S
::v('uid', -1));
72 $page->assign('geoloc_incitation', count($res));
74 // affichage de la boîte avec quelques liens
75 require_once 'login.conf.php';
76 $pub_nbElem = $pub_nbLig * $pub_nbCol ;
77 if (count($pub_tjs) <= $pub_nbElem) {
78 $publicite = array_slice($pub_tjs, 0, $pub_nbElem);
80 $publicite = $pub_tjs ;
83 $nbAlea = $pub_nbElem - count($publicite) ;
85 $choix = array_rand($pub_rnd,$nbAlea) ;
86 foreach ($choix as $url) {
87 $publicite[$url] = $pub_rnd[$url] ;
90 $publicite = array_chunk( $publicite , $pub_nbLig , true
) ;
91 $page->assign_by_ref('publicite', $publicite);
95 if (S
::has('core_rss_hash')) {
96 $page->assign('xorg_rss',
97 array('title' => 'Polytechnique.org :: News',
98 'href' => '/rss/'.S
::v('forlife')
99 .'/'.S
::v('core_rss_hash').'/rss.xml')
103 // cache les evenements lus et raffiche les evenements a relire
105 XDB
::execute('DELETE FROM evenements_vus AS ev
106 INNER JOIN evenements AS e ON e.id = ev.evt_id
107 WHERE peremption < NOW)');
108 XDB
::execute('REPLACE INTO evenements_vus VALUES({?},{?})',
109 Env
::v('lu'), S
::v('uid'));
112 if (Env
::has('nonlu')){
113 XDB
::execute('DELETE FROM evenements_vus
114 WHERE evt_id = {?} AND user_id = {?}',
115 Env
::v('nonlu'), S
::v('uid'));
118 // affichage des evenements
119 // annonces promos triées par présence d'une limite sur les promos
120 // puis par dates croissantes d'expiration
121 $promo = S
::v('promo');
122 $sql = "SELECT e.id,e.titre,e.texte,a.user_id,a.nom,a.prenom,a.promo,l.alias AS forlife
124 INNER JOIN auth_user_md5 AS a ON e.user_id=a.user_id
125 INNER JOIN aliases AS l ON ( a.user_id=l.id AND l.type='a_vie' )
126 LEFT JOIN evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?})
127 WHERE FIND_IN_SET(e.flags, 'valide') AND peremption >= NOW()
128 AND (e.promo_min = 0 || e.promo_min <= {?})
129 AND (e.promo_max = 0 || e.promo_max >= {?})
130 AND ev.user_id IS NULL
131 ORDER BY (e.promo_min != 0 AND e.promo_max != 0) DESC, e.peremption";
132 $page->assign('evenement',
133 XDB
::iterator($sql, S
::v('uid'),
137 $sql = "SELECT e.id,e.titre, ev.user_id IS NULL AS nonlu
139 LEFT JOIN evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?})
140 WHERE FIND_IN_SET(e.flags, 'valide') AND peremption >= NOW()
141 AND (e.promo_min = 0 || e.promo_min <= {?})
142 AND (e.promo_max = 0 || e.promo_max >= {?})
143 ORDER BY (e.promo_min != 0 AND e.promo_max != 0) DESC, e.peremption";
144 $page->assign('evenement_summary',
145 XDB
::iterator($sql, S
::v('uid'),
150 function handler_ev_submit(&$page)
152 $page->changeTpl('evenements.tpl');
154 $titre = Post
::v('titre');
155 $texte = Post
::v('texte');
156 $promo_min = Post
::i('promo_min');
157 $promo_max = Post
::i('promo_max');
158 $peremption = Post
::i('peremption');
159 $valid_mesg = Post
::v('valid_mesg');
160 $action = Post
::v('action');
162 $page->assign('titre', $titre);
163 $page->assign('texte', $texte);
164 $page->assign('promo_min', $promo_min);
165 $page->assign('promo_max', $promo_max);
166 $page->assign('peremption', $peremption);
167 $page->assign('valid_mesg', $valid_mesg);
168 $page->assign('action', strtolower($action));
170 if ($action == 'Confirmer') {
171 $texte = preg_replace('/((http|ftp)+(s)?:\/\/[^<>\s]+)/i',
172 '<a href=\"\\0\">\\0</a>', $texte);
173 $texte = preg_replace('/([^,\s]+@[^,\s]+)/i',
174 '<a href=\"mailto:\\0\">\\0</a>', $texte);
175 require_once 'validations.inc.php';
176 $evtreq = new EvtReq($titre, $texte, $promo_min, $promo_max,
177 $peremption, $valid_mesg, S
::v('uid'));
179 $page->assign('ok', true
);
183 for ($i = 1 ; $i < 30 ; $i++
) {
184 $time = time() +
3600 * 24 * $i;
185 $p_stamp = date('Ymd', $time);
186 $year = date('Y', $time);
187 $month = date('m', $time);
188 $day = date('d', $time);
190 $select .= "<option value=\"$p_stamp\"";
191 if ($p_stamp == strtr($peremption, array("-" => ""))) {
192 $select .= " selected='selected'";
194 $select .= "> $day / $month / $year</option>\n";
196 $page->assign('select',$select);
199 function handler_nl(&$page, $action = null
)
201 require_once 'newsletter.inc.php';
203 $page->changeTpl('newsletter/index.tpl');
204 $page->assign('xorg_title','Polytechnique.org - Lettres mensuelles');
207 case 'out': unsubscribe_nl(); break;
208 case 'in': subscribe_nl(); break;
212 $page->assign('nls', get_nl_state());
213 $page->assign_by_ref('nl_list', get_nl_list());
216 function handler_nl_show(&$page, $nid = 'last')
218 $page->changeTpl('newsletter/show.tpl');
220 require_once 'newsletter.inc.php';
222 $nl = new NewsLetter($nid);
223 $page->assign_by_ref('nl', $nl);
225 if (Post
::has('send')) {
226 $nl->sendTo(S
::v('prenom'), S
::v('nom'),
227 S
::v('bestalias'), S
::v('femme'),
228 S
::v('mail_fmt') != 'text');
232 function handler_nl_submit(&$page)
234 $page->changeTpl('newsletter/submit.tpl');
236 require_once 'newsletter.inc.php';
238 if (Post
::has('see')) {
239 $art = new NLArticle(Post
::v('title'), Post
::v('body'), Post
::v('append'));
240 $page->assign('art', $art);
241 } elseif (Post
::has('valid')) {
242 require_once('validations.inc.php');
243 $art = new NLReq(S
::v('uid'), Post
::v('title'),
244 Post
::v('body'), Post
::v('append'));
246 $page->assign('submited', true
);
250 function handler_admin_events(&$page, $action = 'list', $eid = null
)
252 $page->changeTpl('admin/evenements.tpl');
253 $page->assign('xorg_title','Polytechnique.org - Administration - Evenements');
254 $page->register_modifier('hde', 'html_entity_decode');
256 $arch = $action == 'archives';
257 $page->assign('action', $action);
259 if (Post
::v('action') == "Proposer") {
260 XDB
::execute('UPDATE evenements
261 SET titre={?}, texte={?}, peremption={?}, promo_min={?}, promo_max={?}
263 Post
::v('titre'), Post
::v('texte'), Post
::v('peremption'),
264 Post
::v('promo_min'), Post
::v('promo_max'), Post
::i('evt_id'));
267 if ($action == 'edit') {
268 $res = XDB
::query('SELECT titre, texte, peremption, promo_min, promo_max
270 WHERE id={?}', $eid);
271 list($titre, $texte, $peremption, $promo_min, $promo_max) = $res->fetchOneRow();
272 $page->assign('titre',$titre);
273 $page->assign('texte',$texte);
274 $page->assign('promo_min',$promo_min);
275 $page->assign('promo_max',$promo_max);
276 $page->assign('peremption',$peremption);
279 for ($i = 1 ; $i < 30 ; $i++
) {
280 $p_stamp=date("Ymd",time()+
3600*24*$i);
281 $year=substr($p_stamp,0,4);
282 $month=substr($p_stamp,4,2);
283 $day=substr($p_stamp,6,2);
285 $select .= "<option value=\"$p_stamp\""
286 . (($p_stamp == strtr($peremption, array("-" => ""))) ?
" selected" : "")
287 . "> $day / $month / $year</option>\n";
289 $page->assign('select',$select);
293 XDB
::execute('DELETE from evenements
294 WHERE id = {?}', $eid);
298 XDB
::execute('UPDATE evenements
299 SET creation_date = creation_date, flags = CONCAT(flags,",archive")
300 WHERE id = {?}', $eid);
304 XDB
::execute('UPDATE evenements
305 SET creation_date = creation_date, flags = REPLACE(flags,"archive","")
306 WHERE id = {?}', $eid);
307 $action = 'archives';
312 XDB
::execute('UPDATE evenements
313 SET creation_date = creation_date, flags = CONCAT(flags,",valide")
314 WHERE id = {?}', $eid);
318 XDB
::execute('UPDATE evenements
319 SET creation_date = creation_date, flags = REPLACE(flags,"valide", "")
320 WHERE id = {?}', $eid);
324 $pid = ($eid && $action == 'preview') ?
$eid : -1;
325 $sql = "SELECT e.id, e.titre, e.texte,e.id = $pid AS preview,
326 DATE_FORMAT(e.creation_date,'%d/%m/%Y %T') AS creation_date,
327 DATE_FORMAT(e.peremption,'%d/%m/%Y') AS peremption,
328 e.promo_min, e.promo_max,
329 FIND_IN_SET('valide', e.flags) AS fvalide,
330 FIND_IN_SET('archive', e.flags) AS farch,
331 u.promo, u.nom, u.prenom, a.alias AS forlife
333 INNER JOIN auth_user_md5 AS u ON(e.user_id = u.user_id)
334 INNER JOIN aliases AS a ON (u.user_id = a.id AND a.type='a_vie')
335 WHERE ".($arch ?
"" : "!")."FIND_IN_SET('archive',e.flags)
336 ORDER BY FIND_IN_SET('valide',e.flags), e.peremption DESC";
337 $page->assign('evs', XDB
::iterator($sql));
339 $page->assign('arch', $arch);
342 function handler_admin_nl(&$page, $new = false
) {
343 $page->changeTpl('newsletter/admin.tpl');
344 $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : liste');
345 require_once("newsletter.inc.php");
349 pl_redirect("admin/newsletter");
352 $page->assign_by_ref('nl_list', get_nl_slist());
355 function handler_admin_nl_edit(&$page, $nid = 'last', $aid = null
, $action = 'edit') {
356 $page->changeTpl('newsletter/edit.tpl');
357 $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : Edition');
358 require_once("newsletter.inc.php");
360 $nl = new NewsLetter($nid);
362 if($action == 'delete') {
363 $nl->delArticle($aid);
364 pl_redirect("admin/newsletter/edit/$nid");
367 if($aid == 'update') {
368 $nl->_title
= Post
::v('title');
369 $nl->_date
= Post
::v('date');
370 $nl->_head
= Post
::v('head');
374 if(Post
::v('save')) {
375 $art = new NLArticle(Post
::v('title'), Post
::v('body'), Post
::v('append'),
376 $aid, Post
::v('cid'), Post
::v('pos'));
377 $nl->saveArticle($art);
378 pl_redirect("admin/newsletter/edit/$nid");
381 if($action == 'edit') {
383 if(Post
::has('title')) {
384 $art = new NLArticle(Post
::v('title'), Post
::v('body'), Post
::v('append'),
385 $eaid, Post
::v('cid'), Post
::v('pos'));
387 $art = ($eaid == 'new') ?
new NLArticle() : $nl->getArt($eaid);
389 $page->assign('art', $art);
392 $page->assign_by_ref('nl',$nl);
394 function handler_admin_nl_cat(&$page, $action = 'list', $id = null
) {
395 require_once('../classes/PLTableEditor.php');
396 $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : Catégories');
397 $page->assign('title', 'Gestion des catégories de la newsletter');
398 $table_editor = new PLTableEditor('admin/newsletter/categories','newsletter_cat','cid');
399 $table_editor->describe('titre','intitulé',true
);
400 $table_editor->describe('pos','position',true
);
401 $table_editor->apply($page, $action, $id);