5fa41508b7d66b712f4485459f48825b98101bbb
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, $arch) {
251 $page->changeTpl('admin/evenements.tpl');
252 $page->assign('xorg_title','Polytechnique.org - Administration - Evenements');
254 $arch = $arch == 'archives';
255 $evid = Post
::i('evt_id');
256 $page->assign('arch', $arch);
258 switch(Post
::v('action')) {
260 XDB
::execute('UPDATE evenements SET titre={?}, texte={?}, peremption={?}, promo_min={?}, promo_max={?} WHERE id = {?}',
261 Post
::v('titre'), Post
::v('texte'), Post
::v('peremption'), Post
::v('promo_min'), Post
::v('promo_max'), $evid);
265 XDB
::execute('UPDATE evenements SET creation_date = creation_date, flags = CONCAT(flags,",valide") WHERE id = {?}', $evid);
269 XDB
::execute('UPDATE evenements SET creation_date = creation_date, flags = REPLACE(flags,"valide", "") WHERE id = {?}', $evid);
273 XDB
::execute('DELETE from evenements WHERE id = {?}', $evid);
277 XDB
::execute('UPDATE evenements SET creation_date = creation_date, flags = CONCAT(flags,",archive") WHERE id = {?}', $evid);
281 XDB
::execute('UPDATE evenements SET creation_date = creation_date, flags = REPLACE(flags,"archive","") WHERE id = {?}', $evid);
285 $res = XDB
::query('SELECT titre, texte, peremption, promo_min, promo_max FROM evenements WHERE id={?}', $evid);
286 list($titre, $texte, $peremption, $promo_min, $promo_max) = $res->fetchOneRow();
287 $page->assign('mode', 'edit');
288 $page->assign('titre',$titre);
289 $page->assign('texte',$texte);
290 $page->assign('promo_min',$promo_min);
291 $page->assign('promo_max',$promo_max);
292 $page->assign('peremption',$peremption);
295 for ($i = 1 ; $i < 30 ; $i++
) {
296 $p_stamp=date("Ymd",time()+
3600*24*$i);
297 $year=substr($p_stamp,0,4);
298 $month=substr($p_stamp,4,2);
299 $day=substr($p_stamp,6,2);
301 $select .= "<option value=\"$p_stamp\"" . (($p_stamp == strtr($peremption, array("-" => ""))) ?
" selected" : "")."> $day / $month / $year</option>\n";
303 $page->assign('select',$select);
308 if ($action != "Editer") {
310 $sql = "SELECT e.id, e.titre, e.texte,
311 DATE_FORMAT(e.creation_date,'%d/%m/%Y %T') AS creation_date,
312 DATE_FORMAT(e.peremption,'%d/%m/%Y') AS peremption,
313 e.promo_min, e.promo_max,
314 FIND_IN_SET('valide', e.flags) AS fvalide,
315 FIND_IN_SET('archive', e.flags) AS farch,
316 u.promo, u.nom, u.prenom, a.alias AS forlife
318 INNER JOIN auth_user_md5 AS u ON(e.user_id = u.user_id)
319 INNER JOIN aliases AS a ON (u.user_id = a.id AND a.type='a_vie')
320 WHERE ".($arch ?
"" : "!")."FIND_IN_SET('archive',e.flags)
321 ORDER BY FIND_IN_SET('valide',e.flags), peremption";
322 $page->assign('evs', XDB
::iterator($sql));
326 function handler_admin_nl(&$page, $new = false
) {
327 $page->changeTpl('newsletter/admin.tpl');
328 $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : liste');
329 require_once("newsletter.inc.php");
333 pl_redirect("admin/newsletter");
336 $page->assign_by_ref('nl_list', get_nl_slist());
339 function handler_admin_nl_edit(&$page, $nid = 'last', $aid = null
, $action = 'edit') {
340 $page->changeTpl('newsletter/edit.tpl');
341 $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : Edition');
342 require_once("newsletter.inc.php");
344 $nl = new NewsLetter($nid);
346 if($action == 'delete') {
347 $nl->delArticle($aid);
348 pl_redirect("admin/newsletter/edit/$nid");
351 if($aid == 'update') {
352 $nl->_title
= Post
::v('title');
353 $nl->_date
= Post
::v('date');
354 $nl->_head
= Post
::v('head');
358 if(Post
::v('save')) {
359 $art = new NLArticle(Post
::v('title'), Post
::v('body'), Post
::v('append'),
360 $aid, Post
::v('cid'), Post
::v('pos'));
361 $nl->saveArticle($art);
362 pl_redirect("admin/newsletter/edit/$nid");
365 if($action == 'edit') {
367 if(Post
::has('title')) {
368 $art = new NLArticle(Post
::v('title'), Post
::v('body'), Post
::v('append'),
369 $eaid, Post
::v('cid'), Post
::v('pos'));
371 $art = ($eaid == 'new') ?
new NLArticle() : $nl->getArt($eaid);
373 $page->assign('art', $art);
376 $page->assign_by_ref('nl',$nl);
378 function handler_admin_nl_cat(&$page, $action = 'list', $id = null
) {
379 require_once('../classes/PLTableEditor.php');
380 $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : Catégories');
381 $page->assign('title', 'Gestion des catégories de la newsletter');
382 $table_editor = new PLTableEditor('admin/newsletter/categories','newsletter_cat','cid');
383 $table_editor->describe('titre','intitulé',true
);
384 $table_editor->describe('pos','position',true
);
385 $table_editor->apply($page, $action, $id);