74e0093f |
1 | <?php |
2 | /*************************************************************************** |
3 | * Copyright (C) 2003-2006 Polytechnique.org * |
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 | |
22 | class EventsModule extends PLModule |
23 | { |
24 | function handlers() |
25 | { |
26 | return array( |
1a828cd4 |
27 | 'events' => $this->make_hook('ev', AUTH_COOKIE), |
28 | 'events/submit' => $this->make_hook('ev_submit', AUTH_MDP), |
b829e258 |
29 | |
164ca57a |
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), |
74e0093f |
33 | ); |
34 | } |
35 | |
1a828cd4 |
36 | function handler_ev(&$page) |
37 | { |
1a828cd4 |
38 | $page->changeTpl('login.tpl'); |
39 | |
08cce2ff |
40 | $res = XDB::query('SELECT date, naissance FROM auth_user_md5 |
1a828cd4 |
41 | WHERE user_id={?}', Session::getInt('uid')); |
42 | list($date, $naissance) = $res->fetchOneRow(); |
43 | |
44 | // incitation à mettre à jour la fiche |
45 | |
46 | $d2 = mktime(0, 0, 0, substr($date, 5, 2), substr($date, 8, 2), |
47 | substr($date, 0, 4)); |
48 | if( (time() - $d2) > 60 * 60 * 24 * 400 ) { |
49 | // si fiche date de + de 400j; |
50 | $page->assign('fiche_incitation', $date); |
51 | } |
52 | |
53 | // Souhaite bon anniversaire |
54 | |
55 | if (substr($naissance, 5) == date('m-d')) { |
56 | $page->assign('birthday', date('Y') - substr($naissance, 0, 4)); |
57 | } |
58 | |
59 | // incitation à mettre une photo |
60 | |
08cce2ff |
61 | $res = XDB::query('SELECT COUNT(*) FROM photo |
1a828cd4 |
62 | WHERE uid={?}', Session::getInt('uid')); |
63 | $page->assign('photo_incitation', $res->fetchOneCell() == 0); |
64 | |
65 | // Incitation à se géolocaliser |
66 | require_once 'geoloc.inc.php'; |
67 | $res = localize_addresses(Session::getInt('uid', -1)); |
68 | $page->assign('geoloc_incitation', count($res)); |
69 | |
70 | // affichage de la boîte avec quelques liens |
71 | require_once 'login.conf.php'; |
72 | $pub_nbElem = $pub_nbLig * $pub_nbCol ; |
73 | if (count($pub_tjs) <= $pub_nbElem) { |
74 | $publicite = array_slice($pub_tjs, 0, $pub_nbElem); |
75 | } else { |
76 | $publicite = $pub_tjs ; |
77 | } |
78 | |
79 | $nbAlea = $pub_nbElem - count($publicite) ; |
80 | if ($nbAlea > 0) { |
81 | $choix = array_rand($pub_rnd,$nbAlea) ; |
82 | foreach ($choix as $url) { |
83 | $publicite[$url] = $pub_rnd[$url] ; |
84 | } |
85 | } |
86 | $publicite = array_chunk( $publicite , $pub_nbLig , true ) ; |
87 | $page->assign_by_ref('publicite', $publicite); |
88 | |
89 | // ajout du lien RSS |
90 | |
91 | if (Session::has('core_rss_hash')) { |
92 | $page->assign('xorg_rss', |
93 | array('title' => 'Polytechnique.org :: News', |
94 | 'href' => '/rss/'.Session::get('forlife') |
95 | .'/'.Session::get('core_rss_hash').'/rss.xml') |
96 | ); |
97 | } |
98 | |
99 | // cache les evenements lus et raffiche les evenements a relire |
100 | if (Env::has('lu')){ |
08cce2ff |
101 | XDB::execute('DELETE FROM evenements_vus AS ev |
1a828cd4 |
102 | INNER JOIN evenements AS e ON e.id = ev.evt_id |
103 | WHERE peremption < NOW)'); |
08cce2ff |
104 | XDB::execute('REPLACE INTO evenements_vus VALUES({?},{?})', |
1a828cd4 |
105 | Env::get('lu'), Session::getInt('uid')); |
106 | } |
107 | |
108 | if (Env::has('nonlu')){ |
08cce2ff |
109 | XDB::execute('DELETE FROM evenements_vus |
1a828cd4 |
110 | WHERE evt_id = {?} AND user_id = {?}', |
111 | Env::get('nonlu'), Session::getInt('uid')); |
112 | } |
113 | |
114 | // affichage des evenements |
115 | // annonces promos triées par présence d'une limite sur les promos |
116 | // puis par dates croissantes d'expiration |
117 | $promo = Session::getInt('promo'); |
118 | $sql = "SELECT e.id,e.titre,e.texte,a.user_id,a.nom,a.prenom,a.promo,l.alias AS forlife |
2f678da1 |
119 | FROM evenements AS e |
120 | INNER JOIN auth_user_md5 AS a ON e.user_id=a.user_id |
121 | INNER JOIN aliases AS l ON ( a.user_id=l.id AND l.type='a_vie' ) |
122 | LEFT JOIN evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?}) |
1a828cd4 |
123 | WHERE FIND_IN_SET(e.flags, 'valide') AND peremption >= NOW() |
124 | AND (e.promo_min = 0 || e.promo_min <= {?}) |
125 | AND (e.promo_max = 0 || e.promo_max >= {?}) |
126 | AND ev.user_id IS NULL |
127 | ORDER BY (e.promo_min != 0 AND e.promo_max != 0) DESC, e.peremption"; |
128 | $page->assign('evenement', |
08cce2ff |
129 | XDB::iterator($sql, Session::getInt('uid'), |
1a828cd4 |
130 | $promo, $promo) |
131 | ); |
132 | |
133 | $sql = "SELECT e.id,e.titre, ev.user_id IS NULL AS nonlu |
134 | FROM evenements AS e |
135 | LEFT JOIN evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?}) |
136 | WHERE FIND_IN_SET(e.flags, 'valide') AND peremption >= NOW() |
137 | AND (e.promo_min = 0 || e.promo_min <= {?}) |
138 | AND (e.promo_max = 0 || e.promo_max >= {?}) |
139 | ORDER BY (e.promo_min != 0 AND e.promo_max != 0) DESC, e.peremption"; |
140 | $page->assign('evenement_summary', |
08cce2ff |
141 | XDB::iterator($sql, Session::getInt('uid'), |
1a828cd4 |
142 | $promo, $promo) |
143 | ); |
1a828cd4 |
144 | } |
145 | |
146 | function handler_ev_submit(&$page) |
74e0093f |
147 | { |
74e0093f |
148 | $page->changeTpl('evenements.tpl'); |
149 | |
150 | $titre = Post::get('titre'); |
151 | $texte = Post::get('texte'); |
152 | $promo_min = Post::getInt('promo_min'); |
153 | $promo_max = Post::getInt('promo_max'); |
154 | $peremption = Post::getInt('peremption'); |
155 | $valid_mesg = Post::get('valid_mesg'); |
156 | $action = Post::get('action'); |
157 | |
158 | $page->assign('titre', $titre); |
159 | $page->assign('texte', $texte); |
160 | $page->assign('promo_min', $promo_min); |
161 | $page->assign('promo_max', $promo_max); |
162 | $page->assign('peremption', $peremption); |
163 | $page->assign('valid_mesg', $valid_mesg); |
164 | $page->assign('action', strtolower($action)); |
165 | |
166 | if ($action == 'Confirmer') { |
167 | $texte = preg_replace('/((http|ftp)+(s)?:\/\/[^<>\s]+)/i', |
168 | '<a href=\"\\0\">\\0</a>', $texte); |
169 | $texte = preg_replace('/([^,\s]+@[^,\s]+)/i', |
170 | '<a href=\"mailto:\\0\">\\0</a>', $texte); |
171 | require_once 'validations.inc.php'; |
172 | $evtreq = new EvtReq($titre, $texte, $promo_min, $promo_max, |
173 | $peremption, $valid_mesg, Session::getInt('uid')); |
174 | $evtreq->submit(); |
175 | $page->assign('ok', true); |
176 | } |
177 | |
178 | $select = ''; |
179 | for ($i = 1 ; $i < 30 ; $i++) { |
180 | $time = time() + 3600 * 24 * $i; |
181 | $p_stamp = date('Ymd', $time); |
182 | $year = date('Y', $time); |
183 | $month = date('m', $time); |
184 | $day = date('d', $time); |
185 | |
186 | $select .= "<option value=\"$p_stamp\""; |
187 | if ($p_stamp == strtr($peremption, array("-" => ""))) { |
188 | $select .= " selected='selected'"; |
189 | } |
190 | $select .= "> $day / $month / $year</option>\n"; |
191 | } |
192 | $page->assign('select',$select); |
74e0093f |
193 | } |
b829e258 |
194 | |
164ca57a |
195 | function handler_nl(&$page, $action = null) |
196 | { |
197 | require_once 'newsletter.inc.php'; |
198 | |
199 | $page->changeTpl('newsletter/index.tpl'); |
200 | $page->assign('xorg_title','Polytechnique.org - Lettres mensuelles'); |
201 | |
202 | switch ($action) { |
203 | case 'out': unsubscribe_nl(); break; |
204 | case 'in': subscribe_nl(); break; |
205 | default: ; |
206 | } |
207 | |
208 | $page->assign('nls', get_nl_state()); |
209 | $page->assign_by_ref('nl_list', get_nl_list()); |
164ca57a |
210 | } |
211 | |
212 | function handler_nl_show(&$page, $nid = 'last') |
b829e258 |
213 | { |
214 | $page->changeTpl('newsletter/show.tpl'); |
215 | |
216 | require_once 'newsletter.inc.php'; |
217 | |
218 | $nl = new NewsLetter($nid); |
219 | $page->assign_by_ref('nl', $nl); |
220 | |
221 | if (Post::has('send')) { |
222 | $nl->sendTo(Session::get('prenom'), Session::get('nom'), |
223 | Session::get('bestalias'), Session::get('femme'), |
224 | Session::get('mail_fmt') != 'text'); |
225 | } |
b829e258 |
226 | } |
164ca57a |
227 | |
228 | function handler_nl_submit(&$page) |
229 | { |
230 | $page->changeTpl('newsletter/submit.tpl'); |
231 | |
232 | require_once 'newsletter.inc.php'; |
233 | |
234 | if (Post::has('see')) { |
235 | $art = new NLArticle(Post::get('title'), Post::get('body'), Post::get('append')); |
236 | $page->assign('art', $art); |
237 | } elseif (Post::has('valid')) { |
238 | require_once('validations.inc.php'); |
239 | $art = new NLReq(Session::getInt('uid'), Post::get('title'), |
240 | Post::get('body'), Post::get('append')); |
241 | $art->submit(); |
242 | $page->assign('submited', true); |
243 | } |
164ca57a |
244 | } |
74e0093f |
245 | } |
246 | |
247 | ?> |