Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
5e1513f6 | 3 | * Copyright (C) 2003-2011 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 | ||
c9f82d49 | 22 | class CarnetModule extends PLModule |
23 | { | |
24 | function handlers() | |
25 | { | |
26 | return array( | |
5ae3e9a9 SJ |
27 | 'carnet' => $this->make_hook('index', AUTH_COOKIE, 'directory_private'), |
28 | 'carnet/panel' => $this->make_hook('panel', AUTH_COOKIE, 'directory_private'), | |
29 | 'carnet/notifs' => $this->make_hook('notifs', AUTH_COOKIE, 'directory_private'), | |
190efb3a | 30 | |
5ae3e9a9 SJ |
31 | 'carnet/contacts' => $this->make_hook('contacts', AUTH_COOKIE, 'directory_private'), |
32 | 'carnet/contacts/pdf' => $this->make_hook('pdf', AUTH_COOKIE, 'directory_private'), | |
33 | 'carnet/contacts/vcard' => $this->make_hook('vcard', AUTH_COOKIE, 'directory_private'), | |
34 | 'carnet/contacts/ical' => $this->make_token_hook('ical', AUTH_COOKIE, 'directory_private'), | |
35 | 'carnet/contacts/csv' => $this->make_token_hook('csv', AUTH_COOKIE, 'directory_private'), | |
190efb3a | 36 | 'carnet/contacts/csv/birthday' => $this->make_token_hook('csv_birthday', AUTH_COOKIE, 'directory_private'), |
91204dbf | 37 | 'carnet/batch' => $this->make_hook('batch', AUTH_COOKIE, 'directory_private'), |
190efb3a | 38 | |
5ae3e9a9 | 39 | 'carnet/rss' => $this->make_token_hook('rss', AUTH_COOKIE, 'directory_private'), |
c9f82d49 | 40 | ); |
41 | } | |
0337d704 | 42 | |
26ba053e | 43 | function _add_rss_link($page) |
fc12cbd1 | 44 | { |
84fc72ff | 45 | if (!S::hasAuthToken()) { |
fc12cbd1 | 46 | return; |
fd8f77de | 47 | } |
162370e7 | 48 | $page->setRssLink('Polytechnique.org :: Carnet', |
2ab3486b | 49 | '/carnet/rss/' . S::v('hruid') . '/' . S::user()->token . '/rss.xml'); |
fc12cbd1 | 50 | } |
51 | ||
26ba053e | 52 | function handler_index($page) |
b48a0758 | 53 | { |
54 | $page->changeTpl('carnet/index.tpl'); | |
46f272fe | 55 | $page->setTitle('Mon carnet'); |
b48a0758 | 56 | $this->_add_rss_link($page); |
b48a0758 | 57 | } |
58 | ||
26ba053e | 59 | function handler_panel($page) |
fc12cbd1 | 60 | { |
61 | $page->changeTpl('carnet/panel.tpl'); | |
62 | ||
63 | if (Get::has('read')) { | |
009b8ab7 FB |
64 | XDB::execute('UPDATE watch |
65 | SET last = FROM_UNIXTIME({?}) | |
66 | WHERE uid = {?}', | |
67 | Get::i('read'), S::i('uid')); | |
069ddda8 | 68 | S::user()->invalidWatchCache(); |
ebfdf077 | 69 | Platal::session()->updateNbNotifs(); |
8b00e0e0 | 70 | pl_redirect('carnet/panel'); |
fc12cbd1 | 71 | } |
72 | ||
73 | require_once 'notifs.inc.php'; | |
009b8ab7 | 74 | $page->assign('now', time()); |
fc12cbd1 | 75 | |
009b8ab7 FB |
76 | $user = S::user(); |
77 | $notifs = Watch::getEvents($user, time() - (7 * 86400)); | |
fc12cbd1 | 78 | $page->assign('notifs', $notifs); |
79 | $page->assign('today', date('Y-m-d')); | |
80 | $this->_add_rss_link($page); | |
fc12cbd1 | 81 | } |
82 | ||
26ba053e | 83 | private function getSinglePromotion(PlPage $page, $promo) |
b48a0758 | 84 | { |
4aae4d2c | 85 | if (!(is_int($promo) || ctype_digit($promo)) || $promo < 1920 || $promo > date('Y')) { |
e46cf8c4 | 86 | $page->trigError('Promotion invalide : ' . $promo . '.'); |
4e7bf1e0 FB |
87 | return null; |
88 | } | |
89 | return (int)$promo; | |
90 | } | |
91 | ||
26ba053e | 92 | private function getPromo(PlPage $page, $promo) |
4e7bf1e0 FB |
93 | { |
94 | if (strpos($promo, '-') === false) { | |
95 | $promo = $this->getSinglePromotion($page, $promo); | |
96 | if (!$promo) { | |
97 | return null; | |
b48a0758 | 98 | } else { |
4e7bf1e0 | 99 | return array($promo); |
b48a0758 | 100 | } |
b48a0758 | 101 | } |
4e7bf1e0 FB |
102 | |
103 | list($promo1, $promo2) = explode('-', $promo); | |
104 | $promo1 = $this->getSinglePromotion($page, $promo1); | |
105 | if (!$promo1) { | |
106 | return null; | |
107 | } | |
108 | $promo2 = $this->getSinglePromotion($page, $promo2); | |
109 | if (!$promo2) { | |
110 | return null; | |
111 | } | |
112 | if ($promo1 > $promo2) { | |
e46cf8c4 | 113 | $page->trigError('Intervalle non valide : ' . $promo . '.'); |
4e7bf1e0 FB |
114 | return null; |
115 | } | |
116 | $array = array(); | |
117 | for ($i = $promo1 ; $i <= $promo2 ; ++$i) { | |
118 | $array[] = $i; | |
119 | } | |
120 | return $array; | |
b48a0758 | 121 | } |
122 | ||
26ba053e | 123 | private function addPromo(PlPage $page, $promo) |
b48a0758 | 124 | { |
4e7bf1e0 FB |
125 | $promos = $this->getPromo($page, $promo); |
126 | if (!$promos || count($promos) == 0) { | |
127 | return; | |
128 | } | |
129 | $to_add = array(); | |
130 | foreach ($promos as $promo) { | |
131 | $to_add[] = XDB::format('({?}, {?})', S::i('uid'), $promo); | |
132 | } | |
133 | XDB::execute('INSERT IGNORE INTO watch_promo (uid, promo) | |
134 | VALUES ' . implode(', ', $to_add)); | |
069ddda8 FB |
135 | S::user()->invalidWatchCache(); |
136 | Platal::session()->updateNbNotifs(); | |
4e7bf1e0 | 137 | } |
b48a0758 | 138 | |
26ba053e | 139 | private function delPromo(PlPage $page, $promo) |
4e7bf1e0 FB |
140 | { |
141 | $promos = $this->getPromo($page, $promo); | |
142 | if (!$promos || count($promos) == 0) { | |
143 | return; | |
144 | } | |
145 | $to_delete = array(); | |
146 | foreach ($promos as $promo) { | |
147 | $to_delete[] = XDB::format('{?}', $promo); | |
148 | } | |
149 | XDB::execute('DELETE FROM watch_promo | |
150 | WHERE ' . XDB::format('uid = {?}', S::i('uid')) . ' | |
151 | AND promo IN (' . implode(', ', $to_delete) . ')'); | |
069ddda8 FB |
152 | S::user()->invalidWatchCache(); |
153 | Platal::session()->updateNbNotifs(); | |
4e7bf1e0 FB |
154 | } |
155 | ||
fe286e5f SJ |
156 | private function getGroup(PlPage $page, $group) |
157 | { | |
158 | $groupid = XDB::fetchOneCell("SELECT id | |
159 | FROM groups | |
160 | WHERE (nom = {?} OR diminutif = {?}) AND NOT FIND_IN_SET('private', pub)", | |
161 | $group, $group); | |
162 | if (is_null($groupid)) { | |
163 | $search = XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $group); | |
164 | $res = XDB::query('SELECT id | |
165 | FROM groups | |
166 | WHERE (nom ' . $search . ' OR diminutif ' . $search . ") AND NOT FIND_IN_SET('private', pub)", | |
167 | $search, $search); | |
168 | if ($res->numRows() == 1) { | |
169 | $groupid = $res->fetchOneCell(); | |
170 | } | |
171 | } | |
172 | return $groupid; | |
173 | } | |
174 | ||
175 | private function addGroup(PlPage $page, $group) | |
176 | { | |
177 | $groupid = $this->getGroup($page, $group); | |
178 | if (is_null($groupid)) { | |
179 | return; | |
180 | } | |
181 | XDB::execute('INSERT IGNORE INTO watch_group (uid, groupid) | |
182 | VALUES ({?}, {?})', | |
183 | S::i('uid'), $groupid); | |
184 | S::user()->invalidWatchCache(); | |
185 | Platal::session()->updateNbNotifs(); | |
186 | } | |
187 | ||
188 | private function delGroup(PlPage $page, $group) | |
189 | { | |
190 | $groupid = $this->getGroup($page, $group); | |
191 | if (is_null($groupid)) { | |
192 | return; | |
193 | } | |
194 | XDB::execute('DELETE FROM watch_group | |
195 | WHERE uid = {?} AND groupid = {?}', | |
196 | S::i('uid'), $groupid); | |
197 | S::user()->invalidWatchCache(); | |
198 | Platal::session()->updateNbNotifs(); | |
199 | } | |
200 | ||
26ba053e | 201 | public function addNonRegistered(PlPage $page, PlUser $user) |
4e7bf1e0 FB |
202 | { |
203 | XDB::execute('INSERT IGNORE INTO watch_nonins (uid, ni_id) | |
204 | VALUES ({?}, {?})', S::i('uid'), $user->id()); | |
91204dbf SJ |
205 | if (XDB::affectedRows() > 0) { |
206 | S::user()->invalidWatchCache(); | |
207 | Platal::session()->updateNbNotifs(); | |
208 | $page->trigSuccess('Contact ajouté : ' . $user->fullName(true)); | |
209 | } else { | |
210 | $page->trigWarning('Contact déjà dans la liste : ' . $user->fullName(true)); | |
211 | } | |
4e7bf1e0 | 212 | } |
b48a0758 | 213 | |
26ba053e | 214 | public function delNonRegistered(PlPage $page, PlUser $user) |
4e7bf1e0 FB |
215 | { |
216 | XDB::execute('DELETE FROM watch_nonins | |
217 | WHERE uid = {?} AND ni_id = {?}', | |
218 | S::i('uid'), $user->id()); | |
069ddda8 FB |
219 | S::user()->invalidWatchCache(); |
220 | Platal::session()->updateNbNotifs(); | |
4e7bf1e0 | 221 | } |
b48a0758 | 222 | |
91204dbf SJ |
223 | public function addRegistered(PlPage $page, Profile $profile) |
224 | { | |
225 | XDB::execute('INSERT IGNORE INTO contacts (uid, contact) | |
226 | VALUES ({?}, {?})', | |
227 | S::i('uid'), $profile->id()); | |
228 | if (XDB::affectedRows() > 0) { | |
229 | S::user()->invalidWatchCache(); | |
230 | Platal::session()->updateNbNotifs(); | |
231 | $page->trigSuccess('Contact ajouté : ' . $profile->fullName(true)); | |
232 | } else { | |
233 | $page->trigWarning('Contact déjà dans la liste : ' . $profile->fullName(true)); | |
234 | } | |
235 | } | |
236 | ||
237 | public function delRegistered(PlPage $page, Profile $profile) | |
238 | { | |
239 | XDB::execute('DELETE FROM contacts | |
240 | WHERE uid = {?} AND contact = {?}', | |
241 | S::i('uid'), $profile->id()); | |
242 | if (XDB::affectedRows() > 0) { | |
243 | S::user()->invalidWatchCache(); | |
244 | Platal::session()->updateNbNotifs(); | |
245 | $page->trigSuccess("Contact retiré !"); | |
246 | } | |
247 | ||
248 | } | |
249 | ||
26ba053e | 250 | public function handler_notifs($page, $action = null, $arg = null) |
4e7bf1e0 FB |
251 | { |
252 | $page->changeTpl('carnet/notifs.tpl'); | |
b48a0758 | 253 | |
40d428d8 VZ |
254 | if ($action) { |
255 | S::assert_xsrf_token(); | |
4e7bf1e0 FB |
256 | switch ($action) { |
257 | case 'add_promo': | |
258 | $this->addPromo($page, $arg); | |
259 | break; | |
b48a0758 | 260 | |
4e7bf1e0 FB |
261 | case 'del_promo': |
262 | $this->delPromo($page, $arg); | |
263 | break; | |
b48a0758 | 264 | |
fe286e5f SJ |
265 | case 'add_group': |
266 | $this->addGroup($page, $arg); | |
267 | break; | |
268 | ||
269 | case 'del_group': | |
270 | $this->delGroup($page, $arg); | |
271 | break; | |
272 | ||
4e7bf1e0 FB |
273 | case 'del_nonins': |
274 | $user = User::get($arg); | |
275 | if ($user) { | |
276 | $this->delNonRegistered($page, $user); | |
277 | } | |
278 | break; | |
279 | ||
280 | case 'add_nonins': | |
281 | $user = User::get($arg); | |
282 | if ($user) { | |
283 | $this->addNonRegistered($page, $user); | |
284 | } | |
285 | break; | |
286 | } | |
b48a0758 | 287 | } |
288 | ||
40d428d8 VZ |
289 | if (Env::has('subs')) { |
290 | S::assert_xsrf_token(); | |
4e7bf1e0 FB |
291 | $flags = new PlFlagSet(); |
292 | foreach (Env::v('sub') as $key=>$value) { | |
293 | $flags->addFlag($key, $value); | |
294 | } | |
295 | XDB::execute('UPDATE watch | |
296 | SET actions = {?} | |
297 | WHERE uid = {?}', $flags, S::i('uid')); | |
069ddda8 FB |
298 | S::user()->invalidWatchCache(); |
299 | Platal::session()->updateNbNotifs(); | |
e6bf9216 VZ |
300 | } |
301 | ||
40d428d8 VZ |
302 | if (Env::has('flags_contacts')) { |
303 | S::assert_xsrf_token(); | |
4e7bf1e0 FB |
304 | XDB::execute('UPDATE watch |
305 | SET ' . XDB::changeFlag('flags', 'contacts', Env::b('contacts')) . ' | |
7e735012 | 306 | WHERE uid = {?}', S::i('uid')); |
069ddda8 FB |
307 | S::user()->invalidWatchCache(); |
308 | Platal::session()->updateNbNotifs(); | |
b48a0758 | 309 | } |
e6bf9216 | 310 | |
40d428d8 VZ |
311 | if (Env::has('flags_mail')) { |
312 | S::assert_xsrf_token(); | |
4e7bf1e0 FB |
313 | XDB::execute('UPDATE watch |
314 | SET ' . XDB::changeFlag('flags', 'mail', Env::b('mail')) . ' | |
7e735012 | 315 | WHERE uid = {?}', S::i('uid')); |
069ddda8 FB |
316 | S::user()->invalidWatchCache(); |
317 | Platal::session()->updateNbNotifs(); | |
4e7bf1e0 FB |
318 | } |
319 | ||
320 | $user = S::user(); | |
321 | $nonins = new UserFilter(new UFC_WatchRegistration($user)); | |
322 | ||
323 | $promo = XDB::fetchColumn('SELECT promo | |
324 | FROM watch_promo | |
325 | WHERE uid = {?} | |
326 | ORDER BY promo', S::i('uid')); | |
327 | $page->assign('promo_count', count($promo)); | |
328 | $ranges = array(); | |
329 | $range_start = null; | |
330 | $range_end = null; | |
331 | foreach ($promo as $p) { | |
332 | if (is_null($range_start)) { | |
333 | $range_start = $range_end = $p; | |
334 | } else if ($p != $range_end + 1) { | |
335 | $ranges[] = array($range_start, $range_end); | |
336 | $range_start = $range_end = $p; | |
337 | } else { | |
338 | $range_end = $p; | |
339 | } | |
b48a0758 | 340 | } |
4e7bf1e0 FB |
341 | $ranges[] = array($range_start, $range_end); |
342 | $page->assign('promo_ranges', $ranges); | |
343 | $page->assign('nonins', $nonins->getUsers()); | |
b48a0758 | 344 | |
fe286e5f SJ |
345 | $groups = XDB::fetchColumn('SELECT g.nom |
346 | FROM watch_group AS w | |
347 | INNER JOIN groups AS g ON (g.id = w.groupid) | |
348 | WHERE w.uid = {?} | |
349 | ORDER BY g.nom', | |
350 | S::i('uid')); | |
351 | $page->assign('groups', $groups); | |
352 | $page->assign('groups_count', count($groups)); | |
4e7bf1e0 FB |
353 | list($flags, $actions) = XDB::fetchOneRow('SELECT flags, actions |
354 | FROM watch | |
355 | WHERE uid = {?}', S::i('uid')); | |
356 | $flags = new PlFlagSet($flags); | |
357 | $actions = new PlFlagSet($actions); | |
358 | $page->assign('flags', $flags); | |
359 | $page->assign('actions', $actions); | |
b48a0758 | 360 | } |
361 | ||
26ba053e | 362 | function handler_contacts($page, $action = null, $subaction = null, $ssaction = null) |
b48a0758 | 363 | { |
46f272fe | 364 | $page->setTitle('Mes contacts'); |
59a61432 | 365 | $this->_add_rss_link($page); |
b48a0758 | 366 | |
e6bf9216 VZ |
367 | // For XSRF protection, checks both the normal xsrf token, and the special RSS token. |
368 | // It allows direct linking to contact adding in the RSS feed. | |
2ab3486b | 369 | if (Env::v('action') && Env::v('token') !== S::user()->token) { |
40d428d8 VZ |
370 | S::assert_xsrf_token(); |
371 | } | |
372 | switch (Env::v('action')) { | |
373 | case 'retirer': | |
ba4ddab6 | 374 | if (($contact = Profile::get(Env::v('user')))) { |
91204dbf | 375 | $this->delRegistered($page, $contact); |
b48a0758 | 376 | } |
377 | break; | |
378 | ||
40d428d8 | 379 | case 'ajouter': |
ba4ddab6 | 380 | if (($contact = Profile::get(Env::v('user')))) { |
91204dbf | 381 | $this->addRegistered($page, $contact); |
b48a0758 | 382 | } |
d6460651 | 383 | break; |
b48a0758 | 384 | } |
385 | ||
355a5f15 | 386 | $search = false; |
0264cf05 | 387 | $user = S::user(); |
355a5f15 RB |
388 | |
389 | require_once 'userset.inc.php'; | |
390 | ||
a2aa8436 | 391 | if ($action == 'search') { |
392 | $action = $subaction; | |
393 | $subaction = $ssaction; | |
394 | $search = true; | |
395 | } | |
396 | if ($search && trim(Env::v('quick'))) { | |
a2aa8436 | 397 | $base = 'carnet/contacts/search'; |
78a47eb4 | 398 | $view = new QuickSearchSet(new UFC_Contact($user)); |
a2aa8436 | 399 | } else { |
400 | $base = 'carnet/contacts'; | |
355a5f15 RB |
401 | $view = new ProfileSet(new UFC_Contact($user)); |
402 | } | |
76cbe885 | 403 | |
1fae7605 | 404 | $view->addMod('minifiche', 'Mini-fiches', true); |
8c4a0c30 | 405 | $view->addMod('trombi', 'Trombinoscope', false, array('with_admin' => false, 'with_promo' => true)); |
0a928a2f | 406 | $view->addMod('map', 'Planisphère'); |
76cbe885 | 407 | $view->apply('carnet/contacts', $page, $action, $subaction); |
76cbe885 | 408 | $page->changeTpl('carnet/mescontacts.tpl'); |
b48a0758 | 409 | } |
410 | ||
26ba053e | 411 | function handler_pdf($page, $arg0 = null, $arg1 = null) |
b48a0758 | 412 | { |
460d8f55 | 413 | $this->load('contacts.pdf.inc.php'); |
714f5437 | 414 | $user = S::user(); |
b48a0758 | 415 | |
732e5855 | 416 | Platal::session()->close(); |
b48a0758 | 417 | |
1a074f45 | 418 | $order = array(new UFO_Name()); |
b48a0758 | 419 | if ($arg0 == 'promo') { |
714f5437 | 420 | $order = array_unshift($order, new UFO_Promo()); |
b48a0758 | 421 | } else { |
714f5437 | 422 | $order[] = new UFO_Promo(); |
b48a0758 | 423 | } |
714f5437 | 424 | $filter = new UserFilter(new UFC_Contact($user), $order); |
b48a0758 | 425 | |
b48a0758 | 426 | $pdf = new ContactsPDF(); |
427 | ||
641f2115 FB |
428 | $it = $filter->iterProfiles(); |
429 | while ($p = $it->next()) { | |
714f5437 | 430 | $pdf = ContactsPDF::addContact($pdf, $p, $arg0 == 'photos' || $arg1 == 'photos'); |
b48a0758 | 431 | } |
432 | $pdf->Output(); | |
433 | ||
434 | exit; | |
435 | } | |
436 | ||
82af3fc3 | 437 | function handler_rss(PlPage $page, PlUser $user) |
c9f82d49 | 438 | { |
460d8f55 | 439 | $this->load('feed.inc.php'); |
4e9a7a6d | 440 | $feed = new CarnetFeed(); |
190efb3a | 441 | return $feed->run($page, $user); |
c9f82d49 | 442 | } |
fbfb06dc | 443 | |
ddaa62b8 FB |
444 | function buildBirthRef(Profile $profile) |
445 | { | |
446 | $date = strtotime($profile->birthdate); | |
447 | $tomorrow = $date + 86400; | |
448 | return array( | |
449 | 'timestamp' => $date, | |
450 | 'date' => date('Ymd', $date), | |
451 | 'tomorrow' => date('Ymd', $tomorrow), | |
f036c896 | 452 | 'email' => $profile->owner()->bestEmail(), |
ddaa62b8 FB |
453 | 'summary' => 'Anniversaire de ' . $profile->fullName(true) |
454 | ); | |
455 | } | |
456 | ||
82af3fc3 | 457 | function handler_csv_birthday(PlPage $page, PlUser $user) |
b3ad574d | 458 | { |
b3ad574d PC |
459 | $page->changeTpl('carnet/calendar.outlook.tpl', NO_SKIN); |
460 | $filter = new UserFilter(new UFC_Contact($user)); | |
461 | $profiles = $filter->iterProfiles(); | |
462 | $page->assign('events', PlIteratorUtils::map($profiles, array($this, 'buildBirthRef'))); | |
463 | $years = array(date("Y")); | |
464 | for ($i = 1; $i <= 10; ++$i) { | |
465 | $years[] = $years[0] + $i; | |
466 | } | |
467 | $page->assign('years', $years); | |
468 | $lang = 'fr'; | |
469 | if (preg_match('/([a-zA-Z]{2,8})($|[^a-zA-Z])/', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches)) { | |
470 | $lang = strtolower($matches[1]); | |
471 | } | |
472 | $page->assign('lang', $lang); | |
473 | if ($lang == 'fr') { | |
474 | $encoding = 'iso8859-15'; | |
475 | } else { | |
476 | $encoding = 'utf-8'; | |
477 | } | |
009f4a24 | 478 | pl_cached_content_headers('text/comma-separated-values; charset=' . $encoding, 1); |
b3ad574d | 479 | } |
ddaa62b8 | 480 | |
82af3fc3 | 481 | function handler_ical(PlPage $page, PlUser $user) |
fbfb06dc | 482 | { |
99544d53 | 483 | require_once 'ical.inc.php'; |
801fcad8 | 484 | $page->changeTpl('carnet/calendar.tpl', NO_SKIN); |
3585b0c8 | 485 | $page->register_function('display_ical', 'display_ical'); |
fbfb06dc | 486 | |
19550958 | 487 | $filter = new UserFilter(new UFC_Contact($user)); |
641f2115 | 488 | $profiles = $filter->iterProfiles(); |
ddaa62b8 | 489 | $page->assign('events', PlIteratorUtils::map($profiles, array($this, 'buildBirthRef'))); |
fbfb06dc | 490 | |
009f4a24 | 491 | pl_cached_content_headers('text/calendar', 1); |
fbfb06dc | 492 | } |
5e193297 | 493 | |
26ba053e | 494 | function handler_vcard($page, $photos = null) |
5e193297 | 495 | { |
f40e4ce5 | 496 | $pf = new ProfileFilter(new UFC_Contact(S::user())); |
5d42c993 | 497 | $vcard = new VCard($photos == 'photos'); |
801adeec | 498 | $vcard->addProfiles($pf->getProfiles(null, Profile::FETCH_ALL)); |
5d42c993 | 499 | $vcard->show(); |
5e193297 | 500 | } |
b3ad574d | 501 | |
82af3fc3 | 502 | function handler_csv(PlPage $page, PlUser $user) |
b3ad574d | 503 | { |
b3ad574d PC |
504 | $page->changeTpl('carnet/mescontacts.outlook.tpl', NO_SKIN); |
505 | $pf = new ProfileFilter(new UFC_Contact($user)); | |
506 | require_once 'carnet/outlook.inc.php'; | |
507 | Outlook::output_profiles($pf->getProfiles(), 'fr'); | |
508 | } | |
91204dbf SJ |
509 | |
510 | function handler_batch($page) | |
511 | { | |
512 | $page->changeTpl('carnet/batch.tpl'); | |
513 | $errors = false; | |
514 | $incomplete = array(); | |
515 | ||
516 | if (Post::has('add')) { | |
517 | S::assert_xsrf_token(); | |
518 | require_once 'userset.inc.php'; | |
519 | require_once 'emails.inc.php'; | |
520 | require_once 'marketing.inc.php'; | |
521 | ||
522 | $list = explode("\n", Post::v('list')); | |
523 | $origin = Post::v('origin'); | |
524 | ||
525 | foreach ($list as $item) { | |
526 | if ($item = trim($item)) { | |
527 | $elements = preg_split("/\s/", $item); | |
528 | $email = array_pop($elements); | |
529 | if (!isvalid_email($email)) { | |
530 | $page->trigError('Email invalide : ' . $email); | |
531 | $incomplete[] = $item; | |
532 | $errors = true; | |
533 | continue; | |
534 | } | |
535 | ||
536 | $user = User::getSilent($email); | |
537 | if (is_null($user)) { | |
538 | $details = implode(' ', $elements); | |
539 | $promo = trim(array_pop($elements)); | |
540 | $cond = new PFC_And(); | |
541 | if (preg_match('/^[MDX]\d{4}$/', $promo)) { | |
542 | $cond->addChild(new UFC_Promo('=', UserFilter::DISPLAY, $promo)); | |
543 | } else { | |
544 | $cond->addChild(new UFC_NameTokens($promo)); | |
545 | } | |
546 | foreach ($elements as $element) { | |
547 | $cond->addChild(new UFC_NameTokens($element)); | |
548 | } | |
549 | $uf = new UserFilter($cond); | |
550 | $count = $uf->getTotalCount(); | |
551 | if ($count == 0) { | |
552 | $page->trigError('Les informations : « ' . $item . ' » ne correspondent à aucun camarade.'); | |
553 | $incomplete[] = $item; | |
554 | $errors = true; | |
555 | continue; | |
556 | } elseif ($count > 1) { | |
557 | $page->trigError('Les informations : « ' . $item . ' » sont ambigues et correspondent à plusieurs camarades.'); | |
558 | $incomplete[] = $item; | |
559 | $errors = true; | |
560 | continue; | |
561 | } else { | |
562 | $user = $uf->getUser(); | |
563 | } | |
564 | } | |
565 | ||
566 | if ($user->state == 'active') { | |
567 | $this->addRegistered($page, $user->profile()); | |
568 | } else { | |
569 | if (!User::isForeignEmailAddress($email)) { | |
570 | $page->trigError('Email pas encore attribué : ' . $email); | |
571 | $incomplete[] = $item; | |
572 | $errors = true; | |
573 | } else { | |
574 | $this->addNonRegistered($page, $user); | |
575 | if (!Marketing::get($user->id(), $email, true)) { | |
576 | check_email($email, "Une adresse surveillée est proposée au marketing par " . S::user()->login()); | |
577 | $market = new Marketing($user->id(), $email, 'default', null, $origin, S::v('uid'), null); | |
578 | $market->add(); | |
579 | } | |
580 | } | |
581 | } | |
582 | } | |
583 | } | |
584 | } | |
585 | $page->assign('errors', $errors); | |
586 | $page->assign('incomplete', $incomplete); | |
587 | } | |
4da0b8d7 | 588 | } |
c9f82d49 | 589 | |
a7de4ef7 | 590 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
c9f82d49 | 591 | ?> |