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 define('NB_PER_PAGE', 25);
24 class XnetEventsModule
extends PLModule
29 '%grp/events' => $this->make_hook('events', AUTH_MDP
),
30 '%grp/events/sub' => $this->make_hook('sub', AUTH_MDP
),
31 '%grp/events/csv' => $this->make_hook('csv', AUTH_MDP
),
32 '%grp/events/edit' => $this->make_hook('edit', AUTH_MDP
),
33 '%grp/events/admin' => $this->make_hook('admin', AUTH_MDP
),
37 function handler_events(&$page)
41 new_group_page('xnetevents/index.tpl');
43 if (Post
::has('del')) {
45 return PL_NOT_ALLOWED
;
48 $eid = Post
::v('del');
50 $res = XDB
::query("SELECT asso_id, short_name FROM groupex.evenements
51 WHERE eid = {?} AND asso_id = {?}",
52 $eid, $globals->asso('id'));
54 $tmp = $res->fetchOneRow();
56 return PL_NOT_ALLOWED
;
59 // deletes the event mailing aliases
62 "DELETE FROM virtual WHERE type = 'evt' AND alias LIKE {?}",
63 $tmp[1].'-absents@%');
65 "DELETE FROM virtual WHERE type = 'evt' AND alias LIKE {?}",
66 $tmp[1].'-participants@%');
69 // deletes the event items
70 XDB
::execute("DELETE FROM groupex.evenements_items WHERE eid = {?}", $eid);
72 // deletes the event participants
73 XDB
::execute("DELETE FROM groupex.evenements_participants
74 WHERE eid = {?}", $eid);
77 XDB
::execute("DELETE FROM groupex.evenements
78 WHERE eid = {?} AND asso_id = {?}",
79 $eid, $globals->asso('id'));
81 // delete the requests for payments
82 require_once 'validations.inc.php';
83 XDB
::execute("DELETE FROM requests
84 WHERE type = 'paiements' AND data LIKE {?}",
85 PayReq
::same_event($eid, $globals->asso('id')));
88 $page->assign('admin', may_update());
90 $evenements = XDB
::iterator(
91 "SELECT e.*, LEFT(10, e.debut) AS debut_day, LEFT(10, e.fin) AS fin_day,
92 IF(e.deadline_inscription, e.deadline_inscription >= LEFT(NOW(), 10),
93 1) AS inscr_open, e.deadline_inscription,
94 u.nom, u.prenom, u.promo, a.alias,
95 MAX(ep.nb) AS inscrit, MAX(ep.paid) AS paid
96 FROM groupex.evenements AS e
97 INNER JOIN x4dat.auth_user_md5 AS u ON u.user_id = e.organisateur_uid
98 INNER JOIN x4dat.aliases AS a ON (a.type = 'a_vie' AND a.id = u.user_id)
99 LEFT JOIN groupex.evenements_participants AS ep ON (ep.eid = e.eid AND ep.uid = {?})
102 ORDER BY debut", S
::v('uid'), $globals->asso('id'));
106 while ($e = $evenements->next()) {
108 "SELECT titre, details, montant, ei.item_id, nb
109 FROM groupex.evenements_items AS ei
110 LEFT JOIN groupex.evenements_participants AS ep
111 ON (ep.eid = ei.eid AND ep.item_id = ei.item_id AND uid = {?})
113 S
::v('uid'), $e['eid']);
114 $e['moments'] = $res->fetchAllAssoc();
117 foreach ($e['moments'] as $m) {
118 $e['topay'] +
= $m['nb'] * $m['montant'];
123 FROM {$globals->money->mpay_tprefix}transactions AS t
124 WHERE ref = {?} AND uid = {?}", $e['paiement_id'], S
::v('uid'));
125 $montants = $query->fetchColumn();
127 foreach ($montants as $m) {
128 $p = strtr(substr($m, 0, strpos($m, 'EUR')), ',', '.');
129 $e['paid'] +
= trim($p);
135 $page->assign('evenements', $evts);
136 $page->assign('is_member', is_member());
139 function handler_sub(&$page, $eid = null
)
141 require_once dirname(__FILE__
).'/xnetevents/xnetevents.inc.php';
143 new_group_page('xnetevents/subscribe.tpl');
145 $evt = get_event_detail($eid);
150 if (!$evt['inscr_open']) {
151 $page->kill('Les inscriptions pour cet événement sont closes');
154 $page->assign('event', $evt);
156 if (!Post
::has('submit')) {
160 $moments = Post
::v('moment', array());
161 $pers = Post
::v('personnes', array());
164 foreach ($moments as $j => $v) {
165 $subs[$j] = intval($v);
167 // retreive ohter field when more than one person
168 if ($subs[$j] == 2) {
169 if (!isset($pers[$j]) ||
!is_numeric($pers[$j])
172 $page->trig('Tu dois choisir un nombre d\'invités correct !');
175 $subs[$j] = 1 +
$pers[$j];
179 // impossible to unsubscribe if you already paid sthing
180 if (array_sum($subs) && $evt['paid'] != 0) {
181 $page->trig("Impossible de te désinscrire complètement ".
182 "parce que tu as fait un paiement par ".
183 "chèque ou par liquide. Contacte un ".
184 "administrateur du groupe si tu es sûr de ".
189 // update actual inscriptions
190 foreach ($subs as $j => $nb) {
193 "REPLACE INTO groupex.evenements_participants
194 VALUES ({?}, {?}, {?}, {?}, {?})",
195 $eid, S
::v('uid'), $j, $nb, $evt['paid']);
196 $page->assign('updated', true
);
199 "DELETE FROM groupex.evenements_participants
200 WHERE eid = {?} AND uid = {?} AND item_id = {?}",
201 $eid, S
::v("uid"), $j);
202 $page->assign('updated', true
);
206 $page->assign('event', get_event_detail($eid));
209 function handler_csv(&$page, $eid = null
, $item_id = null
)
211 require_once dirname(__FILE__
).'/xnetevents/xnetevents.inc.php';
213 if (!is_numeric($item_id)) {
217 $evt = get_event_detail($eid, $item_id);
222 header('Content-type: text/x-csv; encoding=iso-8859-1');
224 header('Cache-Control: ');
226 $page->changeTpl('xnetevents/csv.tpl', NO_SKIN
);
228 $admin = may_update();
230 $tri = (Env
::v('order') == 'alpha' ?
'promo, nom, prenom' : 'nom, prenom, promo');
232 $page->assign('participants',
233 get_event_participants($evt, $item_id, $tri));
235 $page->assign('admin', $admin);
236 $page->assign('moments', $evt['moments']);
237 $page->assign('money', $evt['money']);
238 $page->assign('tout', !Env
::v('item_id', false
));
241 function handler_edit(&$page, $eid = null
)
245 // check the event is in our group
246 if (!is_null($eid)) {
247 $res = XDB
::query("SELECT short_name, asso_id
248 FROM groupex.evenements
249 WHERE eid = {?}", $eid);
250 $infos = $res->fetchOneAssoc();
251 if ($infos['asso_id'] != $globals->asso('id')) {
252 return PL_NOT_ALLOWED
;
256 new_groupadmin_page('xnetevents/edit.tpl');
258 $moments = range(1, 4);
259 $page->assign('moments', $moments);
261 if (Post
::v('intitule')) {
262 require_once dirname(__FILE__
).'/xnetevents/xnetevents.inc.php';
263 $short_name = event_change_shortname($page, $infos['short_name'],
264 Env
::v('short_name', ''));
268 'asso_id' => $globals->asso('id'),
269 'organisateur_uid' => S
::v('uid'),
270 'paiement_id' => Post
::v('paiement_id') > 0 ? Post
::v('paiement_id') : null
,
271 'debut' => Post
::v('deb_Year').'-'.Post
::v('deb_Month')
272 .'-'.Post
::v('deb_Day').' '.Post
::v('deb_Hour')
273 .':'.Post
::v('deb_Minute').':00',
274 'fin' => Post
::v('fin_Year').'-'.Post
::v('fin_Month')
275 .'-'.Post
::v('fin_Day').' '.Post
::v('fin_Hour')
276 .':'.Post
::v('fin_Minute').':00',
277 'short_name' => $short_name,
280 $trivial = array('intitule', 'descriptif', 'noinvite',
281 'show_participants');
282 foreach ($trivial as $k) {
283 $evt[$k] = Post
::v($k);
286 if (Post
::v('deadline')) {
287 $evt['deadline_inscription'] = Post
::v('inscr_Year').'-'
288 . Post
::v('inscr_Month').'-'
289 . Post
::v('inscr_Day');
291 $evt['deadline_inscription'] = null
;
294 // Store the modifications in the database
295 XDB
::execute('REPLACE INTO groupex.evenements
296 SET eid={?}, asso_id={?}, organisateur_uid={?}, intitule={?},
297 paiement_id = {?}, descriptif = {?}, debut = {?},
298 fin = {?}, show_participants = {?}, short_name = {?},
299 deadline_inscription = {?}, noinvite = {?}',
300 $evt['eid'], $evt['asso_id'], $evt['organisateur_uid'],
301 $evt['intitule'], $evt['paiement_id'], $evt['descriptif'],
302 $evt['debut'], $evt['fin'], $evt['show_participants'],
303 $evt['short_name'], $evt['deadline_inscription'],
306 // if new event, get its id
308 $eid = mysql_insert_id();
314 foreach ($moments as $i) {
315 if (Post
::v('titre'.$i)) {
318 $montant = strtr(Post
::v('montant'.$i), ',', '.');
319 $money_defaut +
= (float)$montant;
321 REPLACE INTO groupex.evenements_items
322 VALUES ({?}, {?}, {?}, {?}, {?})",
323 $eid, $i, Post
::v('titre'.$i),
324 Post
::v('details'.$i), $montant);
326 XDB
::execute("DELETE FROM groupex.evenements_items
327 WHERE eid = {?} AND item_id = {?}", $eid, $i);
331 // request for a new payment
332 if (Post
::v('paiement_id') == -1 && $money_defaut >= 0) {
333 require_once 'validations.inc.php';
334 $p = new PayReq(S
::v('uid'),
335 Post
::v('intitule')." - ".$globals->asso('nom'),
336 Post
::v('site'), $money_defaut,
337 Post
::v('confirmation'), 0, 999,
338 $globals->asso('id'), $eid);
342 // events with no sub-event: add a sub-event with no name
343 if ($nb_moments == 0) {
344 XDB
::execute("INSERT INTO groupex.evenements_items
345 VALUES ({?}, {?}, '', '', 0)", $eid, 1);
348 if (is_null($evt['eid'])) {
349 pl_redirect('events/'.$eid);
353 // get a list of all the payment for this asso
354 $res = XDB
::iterator("SELECT id, text
355 FROM {$globals->money->mpay_tprefix}paiements
356 WHERE asso_id = {?}", $globals->asso('id'));
357 $paiements = array();
358 while ($a = $res->next()) $paiements[$a['id']] = $a['text']; {
359 $page->assign('paiements', $paiements);
362 // when modifying an old event retreive the old datas
365 "SELECT eid, intitule, descriptif, debut, fin,
366 show_participants, paiement_id, short_name,
367 deadline_inscription, noinvite
368 FROM groupex.evenements
369 WHERE eid = {?}", $eid);
370 $evt = $res->fetchOneAssoc();
371 // find out if there is already a request for a payment for this event
372 require_once 'validations.inc.php';
373 $res = XDB
::query("SELECT stamp FROM requests
374 WHERE type = 'paiements' AND data LIKE {?}",
375 PayReq
::same_event($eid, $globals->asso('id')));
376 $stamp = $res->fetchOneCell();
378 $evt['paiement_id'] = -2;
379 $evt['paiement_req'] = $stamp;
381 $page->assign('evt', $evt);
382 // get all the different moments infos
383 $res = XDB
::iterator(
384 "SELECT item_id, titre, details, montant
385 FROM groupex.evenements_items AS ei
386 INNER JOIN groupex.evenements AS e ON(e.eid = ei.eid)
388 ORDER BY item_id", $eid);
390 while ($item = $res->next()) {
391 $items[$item['item_id']] = $item;
393 $page->assign('items', $items);
397 function handler_admin(&$page, $eid = null
, $item_id = null
)
401 require_once dirname(__FILE__
).'/xnetevents/xnetevents.inc.php';
403 $evt = get_event_detail($eid, $item_id);
408 if ($evt['show_participants']) {
409 new_group_page('xnetevents/admin.tpl');
411 new_groupadmin_page('xnetevents/admin.tpl');
414 if (may_update() && Post
::v('adm')) {
415 $member = get_infos(Post
::v('mail'));
417 $page->trig("Membre introuvable");
420 // change the price paid by a participant
421 if (Env
::v('adm') == 'prix' && $member) {
422 XDB
::execute("UPDATE groupex.evenements_participants
423 SET paid = IF(paid + {?} > 0, paid + {?}, 0)
424 WHERE uid = {?} AND eid = {?}",
425 strtr(Env
::v('montant'), ',', '.'),
426 strtr(Env
::v('montant'), ',', '.'),
427 $member['uid'], $eid);
430 // change the number of personns coming with a participant
431 if (Env
::v('adm') == 'nbs' && $member) {
432 $res = XDB
::query("SELECT paid
433 FROM groupex.evenements_participants
434 WHERE uid = {?} AND eid = {?}",
435 $member['uid'], $eid);
437 $paid = intval($res->fetchOneCell());
438 $nbs = Post
::v('nb', array());
440 foreach ($nbs as $id => $nb) {
441 $nb = max(intval($nb), 0);
444 XDB
::execute("REPLACE INTO groupex.evenements_participants
445 VALUES ({?}, {?}, {?}, {?}, {?})",
446 $eid, $member['uid'], $id, $nb, $paid);
448 XDB
::execute("DELETE FROM groupex.evenements_participants
449 WHERE uid = {?} AND eid = {?} AND item_id = {?}",
450 $member['uid'], $eid, $id);
454 $res = XDB
::query("SELECT uid FROM groupex.evenements_participants
455 WHERE uid = {?} AND eid = {?}",
456 $member['uid'], $eid);
457 $u = $res->fetchOneCell();
458 subscribe_lists_event($u, $member['uid'], $evt);
461 $evt = get_event_detail($eid, $item_id);
464 $page->assign('admin', may_update());
465 $page->assign('evt', $evt);
466 $page->assign('tout', is_null($item_id));
468 if (count($evt['moments'])) {
469 $page->assign('moments', $evt['moments']);
472 $tri = (Env
::v('order') == 'alpha' ?
'promo, nom, prenom' : 'nom, prenom, promo');
473 $whereitemid = is_null($item_id) ?
'' : "AND ep.item_id = $item_id";
475 'SELECT UPPER(SUBSTRING(IF(u.nom IS NULL, m.nom,
476 IF(u.nom_usage<>"", u.nom_usage, u.nom)), 1, 1)),
477 COUNT(DISTINCT ep.uid)
478 FROM groupex.evenements_participants AS ep
479 INNER JOIN groupex.evenements AS e ON (ep.eid = e.eid)
480 LEFT JOIN groupex.membres AS m ON ( ep.uid = m.uid AND e.asso_id = m.asso_id)
481 LEFT JOIN auth_user_md5 AS u ON ( u.user_id = ep.uid )
482 WHERE ep.eid = {?} '.$whereitemid.'
483 GROUP BY UPPER(SUBSTRING(IF(u.nom IS NULL,m.nom,u.nom), 1, 1))', $eid);
487 while (list($char, $nb) = $res->next()) {
488 $alphabet[ord($char)] = $char;
490 if (Env
::has('initiale') && $char == strtoupper(Env
::v('initiale'))) {
495 $page->assign('alphabet', $alphabet);
497 $ofs = Env
::i('offset');
498 $tot = Env
::v('initiale') ?
$tot : $nb_tot;
499 $nbp = intval(($tot-1)/NB_PER_PAGE
);
502 $links['précédent'] = $ofs-1;
504 for ($i = 0; $i <= $nbp; $i++
) {
505 $links[(string)($i+
1)] = $i;
508 $links['suivant'] = $ofs+
1;
510 if (count($links)>1) {
511 $page->assign('links', $links);
514 if ($evt['paiement_id']) {
515 $res = XDB
::iterator(
516 "SELECT IF(u.nom_usage<>'', u.nom_usage, u.nom) AS nom, u.prenom,
517 u.promo, a.alias AS email, t.montant
518 FROM {$globals->money->mpay_tprefix}transactions AS t
519 INNER JOIN auth_user_md5 AS u ON(t.uid = u.user_id)
520 INNER JOIN aliases AS a ON (a.id = t.uid AND a.type='a_vie' )
521 LEFT JOIN groupex.evenements_participants AS ep ON(ep.uid = t.uid AND ep.eid = {?})
522 WHERE t.ref = {?} AND ep.uid IS NULL",
523 $evt['eid'], $evt['paiement_id']);
524 $page->assign('oublis', $res->total());
525 $page->assign('oubliinscription', $res);
528 $page->assign('participants',
529 get_event_participants($evt, $item_id, $tri,
530 "LIMIT ".($ofs*NB_PER_PAGE
).", ".NB_PER_PAGE
));