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
),
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
),
36 function handler_ev(&$page)
40 $page->changeTpl('login.tpl');
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();
46 // incitation à mettre à jour la fiche
48 $d2 = mktime(0, 0, 0, substr($date, 5, 2), substr($date, 8, 2),
50 if( (time() - $d2) > 60 * 60 * 24 * 400 ) {
51 // si fiche date de + de 400j;
52 $page->assign('fiche_incitation', $date);
55 // Souhaite bon anniversaire
57 if (substr($naissance, 5) == date('m-d')) {
58 $page->assign('birthday', date('Y') - substr($naissance, 0, 4));
61 // incitation à mettre une photo
63 $res = $globals->xdb
->query('SELECT COUNT(*) FROM photo
64 WHERE uid={?}', Session
::getInt('uid'));
65 $page->assign('photo_incitation', $res->fetchOneCell() == 0);
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));
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);
78 $publicite = $pub_tjs ;
81 $nbAlea = $pub_nbElem - count($publicite) ;
83 $choix = array_rand($pub_rnd,$nbAlea) ;
84 foreach ($choix as $url) {
85 $publicite[$url] = $pub_rnd[$url] ;
88 $publicite = array_chunk( $publicite , $pub_nbLig , true
) ;
89 $page->assign_by_ref('publicite', $publicite);
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')
101 // cache les evenements lus et raffiche les evenements a relire
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'));
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'));
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
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 = {?})
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'),
135 $sql = "SELECT e.id,e.titre, ev.user_id IS NULL AS nonlu
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'),
150 function handler_ev_submit(&$page)
153 $page->changeTpl('evenements.tpl');
155 $titre = Post
::get('titre');
156 $texte = Post
::get('texte');
157 $promo_min = Post
::getInt('promo_min');
158 $promo_max = Post
::getInt('promo_max');
159 $peremption = Post
::getInt('peremption');
160 $valid_mesg = Post
::get('valid_mesg');
161 $action = Post
::get('action');
163 $page->assign('titre', $titre);
164 $page->assign('texte', $texte);
165 $page->assign('promo_min', $promo_min);
166 $page->assign('promo_max', $promo_max);
167 $page->assign('peremption', $peremption);
168 $page->assign('valid_mesg', $valid_mesg);
169 $page->assign('action', strtolower($action));
171 if ($action == 'Confirmer') {
172 $texte = preg_replace('/((http|ftp)+(s)?:\/\/[^<>\s]+)/i',
173 '<a href=\"\\0\">\\0</a>', $texte);
174 $texte = preg_replace('/([^,\s]+@[^,\s]+)/i',
175 '<a href=\"mailto:\\0\">\\0</a>', $texte);
176 require_once 'validations.inc.php';
177 $evtreq = new EvtReq($titre, $texte, $promo_min, $promo_max,
178 $peremption, $valid_mesg, Session
::getInt('uid'));
180 $page->assign('ok', true
);
184 for ($i = 1 ; $i < 30 ; $i++
) {
185 $time = time() +
3600 * 24 * $i;
186 $p_stamp = date('Ymd', $time);
187 $year = date('Y', $time);
188 $month = date('m', $time);
189 $day = date('d', $time);
191 $select .= "<option value=\"$p_stamp\"";
192 if ($p_stamp == strtr($peremption, array("-" => ""))) {
193 $select .= " selected='selected'";
195 $select .= "> $day / $month / $year</option>\n";
197 $page->assign('select',$select);
202 function handler_nl(&$page, $action = null
)
204 require_once 'newsletter.inc.php';
206 $page->changeTpl('newsletter/index.tpl');
207 $page->assign('xorg_title','Polytechnique.org - Lettres mensuelles');
210 case 'out': unsubscribe_nl(); break;
211 case 'in': subscribe_nl(); break;
215 $page->assign('nls', get_nl_state());
216 $page->assign_by_ref('nl_list', get_nl_list());
221 function handler_nl_show(&$page, $nid = 'last')
223 $page->changeTpl('newsletter/show.tpl');
225 require_once 'newsletter.inc.php';
227 $nl = new NewsLetter($nid);
228 $page->assign_by_ref('nl', $nl);
230 if (Post
::has('send')) {
231 $nl->sendTo(Session
::get('prenom'), Session
::get('nom'),
232 Session
::get('bestalias'), Session
::get('femme'),
233 Session
::get('mail_fmt') != 'text');
239 function handler_nl_submit(&$page)
241 $page->changeTpl('newsletter/submit.tpl');
243 require_once 'newsletter.inc.php';
245 if (Post
::has('see')) {
246 $art = new NLArticle(Post
::get('title'), Post
::get('body'), Post
::get('append'));
247 $page->assign('art', $art);
248 } elseif (Post
::has('valid')) {
249 require_once('validations.inc.php');
250 $art = new NLReq(Session
::getInt('uid'), Post
::get('title'),
251 Post
::get('body'), Post
::get('append'));
253 $page->assign('submited', true
);