Proof of concept:
[platal.git] / htdocs / login.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
50a40a33 3 * Copyright (C) 2003-2006 Polytechnique.org *
0337d704 4 * http://opensource.polytechnique.org/ *
5 * *
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. *
10 * *
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. *
15 * *
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 *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22require_once('xorg.inc.php');
23new_skinned_page('login.tpl', AUTH_COOKIE);
24
25$res = $globals->xdb->query('SELECT date, naissance FROM auth_user_md5 WHERE user_id={?}', Session::getInt('uid'));
26list($date, $naissance) = $res->fetchOneRow();
27
28// incitation à mettre à jour la fiche
29
30$d2 = mktime(0, 0, 0, substr($date, 5, 2), substr($date, 8, 2), substr($date, 0, 4));
31if( (time() - $d2) > 60 * 60 * 24 * 400 ) {
32 // si fiche date de + de 400j;
33 $page->assign('fiche_incitation', $date);
34}
35
36// Souhaite bon anniversaire
37
38if (substr($naissance, 5) == date("m-d")) {
39 $page->assign('birthday', date("Y") - substr($naissance, 0, 4));
40}
41
42// incitation à mettre une photo
43
44$res = $globals->xdb->query('SELECT COUNT(*) FROM photo WHERE uid={?}', Session::getInt('uid'));
45$page->assign('photo_incitation', $res->fetchOneCell() == 0);
46
47// Incitation à se géolocaliser
48require_once('geoloc.inc.php');
49$res = localize_addresses(Session::getInt('uid', -1));
50$page->assign('geoloc_incitation', count($res));
51
52// affichage de la boîte avec quelques liens
53
54require_once('login.conf.php') ;
55$pub_nbElem = $pub_nbLig * $pub_nbCol ;
56if (count($pub_tjs) <= $pub_nbElem)
57 $publicite = array_slice ($pub_tjs,0,$pub_nbElem) ;
58else
59 $publicite = $pub_tjs ;
60$nbAlea = $pub_nbElem - count($publicite) ;
61if ($nbAlea > 0) {
62 $choix = array_rand($pub_rnd,$nbAlea) ;
63 foreach ($choix as $url)
64 $publicite[$url] = $pub_rnd[$url] ;
65 }
66$publicite = array_chunk( $publicite , $pub_nbLig , true ) ;
67$page->assign_by_ref('publicite', $publicite);
68
69// ajout du lien RSS
70
71if (Session::has('core_rss_hash')) {
72 $page->assign('xorg_rss', Array("title" => "Polytechnique.org :: News", "href" => "/rss.php/".Session::get('forlife')."/".Session::get('core_rss_hash').".xml"));
73}
74
f75b2292 75// cache les evenements lus et raffiche les evenements a relire
76if (Env::has('lu')){
77 $globals->xdb->execute('DELETE FROM evenements_vus AS ev INNER JOIN evenements AS e ON e.id = ev.evt_id WHERE peremption < NOW)');
78 $globals->xdb->execute('REPLACE INTO evenements_vus VALUES({?},{?})', Env::get('lu'), Session::getInt('uid'));
79}
80if (Env::has('nonlu')){
81 $globals->xdb->execute('DELETE FROM evenements_vus WHERE evt_id = {?} AND user_id = {?}', Env::get('nonlu'), Session::getInt('uid'));
82}
83
0337d704 84// affichage des evenements
85// annonces promos triées par présence d'une limite sur les promos
86// puis par dates croissantes d'expiration
87$promo = Session::getInt('promo');
88$sql = "SELECT e.id,e.titre,e.texte,a.user_id,a.nom,a.prenom,a.promo,l.alias AS forlife
89 FROM evenements AS e
90 INNER JOIN auth_user_md5 AS a ON e.user_id=a.user_id
91 INNER JOIN aliases AS l ON ( a.user_id=l.id AND l.type='a_vie' )
f75b2292 92 LEFT JOIN evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?})
93 WHERE FIND_IN_SET(e.flags, 'valide') AND peremption >= NOW()
94 AND (e.promo_min = 0 || e.promo_min <= {?})
95 AND (e.promo_max = 0 || e.promo_max >= {?})
96 AND ev.user_id IS NULL
97 ORDER BY (e.promo_min != 0 AND e.promo_max != 0) DESC, e.peremption";
98$page->assign('evenement', $globals->xdb->iterator($sql, Session::getInt('uid'), $promo, $promo));
99
100$sql = "SELECT e.id,e.titre, ev.user_id IS NULL AS nonlu
101 FROM evenements AS e
102 LEFT JOIN evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?})
0337d704 103 WHERE FIND_IN_SET(e.flags, 'valide') AND peremption >= NOW()
104 AND (e.promo_min = 0 || e.promo_min <= {?})
105 AND (e.promo_max = 0 || e.promo_max >= {?})
106 ORDER BY (e.promo_min != 0 AND e.promo_max != 0) DESC, e.peremption";
f75b2292 107$page->assign('evenement_summary', $globals->xdb->iterator($sql, Session::getInt('uid'), $promo, $promo));
0337d704 108
51c9b362 109$page->assign('refe',$_SERVER['PHP_SELF']);
110
0337d704 111$page->run();
112
113// vim:set et sws=4 sw=4 sts=4:
114?>