98d25920064c3ed6afd5c27bb8f572c1ed0fcefd
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 = 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 = 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 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 XDB
::execute('REPLACE INTO evenements_vus VALUES({?},{?})',
107 Env
::get('lu'), Session
::getInt('uid'));
110 if (Env
::has('nonlu')){
111 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 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 XDB
::iterator($sql, Session
::getInt('uid'),
148 function handler_ev_submit(&$page)
151 $page->changeTpl('evenements.tpl');
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');
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));
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'));
178 $page->assign('ok', true
);
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);
189 $select .= "<option value=\"$p_stamp\"";
190 if ($p_stamp == strtr($peremption, array("-" => ""))) {
191 $select .= " selected='selected'";
193 $select .= "> $day / $month / $year</option>\n";
195 $page->assign('select',$select);
198 function handler_nl(&$page, $action = null
)
200 require_once 'newsletter.inc.php';
202 $page->changeTpl('newsletter/index.tpl');
203 $page->assign('xorg_title','Polytechnique.org - Lettres mensuelles');
206 case 'out': unsubscribe_nl(); break;
207 case 'in': subscribe_nl(); break;
211 $page->assign('nls', get_nl_state());
212 $page->assign_by_ref('nl_list', get_nl_list());
215 function handler_nl_show(&$page, $nid = 'last')
217 $page->changeTpl('newsletter/show.tpl');
219 require_once 'newsletter.inc.php';
221 $nl = new NewsLetter($nid);
222 $page->assign_by_ref('nl', $nl);
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');
231 function handler_nl_submit(&$page)
233 $page->changeTpl('newsletter/submit.tpl');
235 require_once 'newsletter.inc.php';
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'));
245 $page->assign('submited', true
);