+ function on_subscribe($forlife, $uid, $promo, $password)
+ {
+ require_once 'newsletter.inc.php';
+ subscribe_nl($uid);
+ }
+
+ function handler_bug(&$page)
+ {
+ $this->handler_ev($page);
+ $page->assign('bug', 1);
+ }
+
+ function handler_ev(&$page, $action = 'list', $eid = null, $pound = null)
+ {
+ $page->changeTpl('login.tpl');
+
+ // donne la derniere date de session
+ $page->assign('lastlogin', strftime("%Y%m%d%H%M%S",S::i('lastlogin')));
+
+ $res = XDB::query('SELECT date, naissance FROM auth_user_md5
+ WHERE user_id={?}', S::v('uid'));
+ list($date, $naissance) = $res->fetchOneRow();
+
+ // incitation à mettre à jour la fiche
+
+ $d2 = mktime(0, 0, 0, substr($date, 5, 2), substr($date, 8, 2),
+ substr($date, 0, 4));
+ if( (time() - $d2) > 60 * 60 * 24 * 400 ) {
+ // si fiche date de + de 400j;
+ $page->assign('fiche_incitation', $date);
+ }
+
+ // Souhaite bon anniversaire
+
+ if (substr($naissance, 5) == date('m-d')) {
+ $page->assign('birthday', date('Y') - substr($naissance, 0, 4));
+ }
+
+ // incitation à mettre une photo
+
+ $res = XDB::query('SELECT COUNT(*) FROM photo
+ WHERE uid={?}', S::v('uid'));
+ $page->assign('photo_incitation', $res->fetchOneCell() == 0);
+
+ // Incitation à se géolocaliser
+ require_once 'geoloc.inc.php';
+ $res = localize_addresses(S::v('uid', -1));
+ $page->assign('geoloc_incitation', count($res));
+
+ // affichage de la boîte avec quelques liens
+ /* Bandeau de publicité sur la page de login */
+ $publicite = array(
+ 'password' => 'Changer mon mot de passe' ,
+ 'Docs/Dons' => 'Faire un don à l\'association Polytechnique.org'
+ ) ;
+
+ // Liens apparaissant de façon aléatoire
+ $pub_rnd = array(
+ 'nl/show' => 'Afficher la dernière newsletter' ,
+ 'http://www.polytechnique.net/login' => 'Vers les autres sites polytechniciens' ,
+ "trombi/{$_SESSION["promo"]}" => "Voir le trombi de ma promo" ,
+ 'banana' => 'Un petit tour du côté des forums !!'
+ ) ;
+
+ $choix = array_rand($pub_rnd, 2);
+ foreach ($choix as $url) {
+ $publicite[$url] = $pub_rnd[$url] ;
+ }
+ $page->assign('publicite', array_chunk($publicite, 2, true));
+
+ // ajout du lien RSS
+ if (S::has('core_rss_hash')) {
+ $page->setRssLink('Polytechnique.org :: News',
+ '/rss/'.S::v('forlife') .'/'.S::v('core_rss_hash').'/rss.xml');
+ }
+
+ // cache les evenements lus et raffiche les evenements a relire
+ if ($action == 'read' && $eid) {
+ XDB::execute('DELETE evenements_vus.*
+ FROM evenements_vus AS ev
+ INNER JOIN evenements AS e ON e.id = ev.evt_id
+ WHERE peremption < NOW()');
+ XDB::execute('REPLACE INTO evenements_vus VALUES({?},{?})',
+ $eid, S::v('uid'));
+ pl_redirect('events#'.$pound);
+ }
+
+ if ($action == 'unread' && $eid) {
+ XDB::execute('DELETE FROM evenements_vus
+ WHERE evt_id = {?} AND user_id = {?}',
+ $eid, S::v('uid'));
+ pl_redirect('events#newsid'.$eid);
+ }
+
+ // affichage des evenements
+ // annonces promos triées par présence d'une limite sur les promos
+ // puis par dates croissantes d'expiration
+ $promo = S::v('promo');
+ $sql = "SELECT e.id,e.titre,e.texte,a.user_id,a.nom,a.prenom,a.promo,l.alias AS forlife
+ FROM evenements AS e
+ INNER JOIN auth_user_md5 AS a ON e.user_id=a.user_id
+ INNER JOIN aliases AS l ON ( a.user_id=l.id AND l.type='a_vie' )
+ LEFT JOIN evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?})
+ WHERE FIND_IN_SET(e.flags, 'valide') AND peremption >= NOW()
+ AND (e.promo_min = 0 || e.promo_min <= {?})
+ AND (e.promo_max = 0 || e.promo_max >= {?})
+ AND ev.user_id IS NULL
+ ORDER BY (e.promo_min != 0 AND e.promo_max != 0) DESC, e.peremption";
+ $page->assign('evenement',
+ XDB::iterator($sql, S::v('uid'),
+ $promo, $promo)
+ );
+
+ $sql = "SELECT e.id,e.titre, ev.user_id IS NULL AS nonlu
+ FROM evenements AS e
+ LEFT JOIN evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?})
+ WHERE FIND_IN_SET(e.flags, 'valide') AND peremption >= NOW()
+ AND (e.promo_min = 0 || e.promo_min <= {?})
+ AND (e.promo_max = 0 || e.promo_max >= {?})
+ ORDER BY (e.promo_min != 0 AND e.promo_max != 0) DESC, e.peremption";
+ $page->assign('evenement_summary',
+ XDB::iterator($sql, S::v('uid'),
+ $promo, $promo)
+ );
+ }
+
+ function handler_ev_submit(&$page)