b5552859abf6c1e138c303cf8e5407892f1d9ed9
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
::get('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", Session
::get('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 Session
::get('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'], Session
::get('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
)
143 require_once dirname(__FILE__
).'/xnetevents/xnetevents.inc.php';
145 new_group_page('xnetevents/subscribe.tpl');
147 $evt = get_event_detail($eid);
152 if (!$evt['inscr_open']) {
153 $page->kill('Les inscriptions pour cet événement sont closes');
156 $page->assign('event', $evt);
158 if (!Post
::has('submit')) {
162 $moments = Post
::getMixed('moment', array());
163 $pers = Post
::getMixed('personnes', array());
166 foreach ($moments as $j => $v) {
167 $subs[$j] = intval($v);
169 // retreive ohter field when more than one person
170 if ($subs[$j] == 2) {
171 if (!isset($pers[$j]) ||
!is_numeric($pers[$j])
174 $page->trig('Tu dois choisir un nombre d\'invités correct !');
177 $subs[$j] = 1 +
$pers[$j];
181 // impossible to unsubscribe if you already paid sthing
182 if (array_sum($subs) && $evt['paid'] != 0) {
183 $page->trig("Impossible de te désinscrire complètement ".
184 "parce que tu as fait un paiement par ".
185 "chèque ou par liquide. Contacte un ".
186 "administrateur du groupe si tu es sûr de ".
191 // update actual inscriptions
192 foreach ($subs as $j => $nb) {
195 "REPLACE INTO groupex.evenements_participants
196 VALUES ({?}, {?}, {?}, {?}, {?})",
197 $eid, Session
::getInt('uid'), $j, $nb, $evt['paid']);
198 $page->assign('updated', true
);
201 "DELETE FROM groupex.evenements_participants
202 WHERE eid = {?} AND uid = {?} AND item_id = {?}",
203 $eid, Session
::getInt("uid"), $j);
204 $page->assign('updated', true
);
208 $page->assign('event', get_event_detail($eid));
211 function handler_csv(&$page, $eid = null
, $item_id = null
)
213 require_once dirname(__FILE__
).'/xnetevents/xnetevents.inc.php';
215 if (!is_numeric($item_id)) {
219 $evt = get_event_detail($eid, $item_id);
224 header('Content-type: text/x-csv; encoding=iso-8859-1');
226 header('Cache-Control: ');
228 new_nonhtml_page('xnetevents/csv.tpl');
230 $admin = may_update();
232 $tri = (Env
::get('order') == 'alpha' ?
'promo, nom, prenom' : 'nom, prenom, promo');
234 $page->assign('participants',
235 get_event_participants($evt, $item_id, $tri));
237 $page->assign('admin', $admin);
238 $page->assign('moments', $evt['moments']);
239 $page->assign('money', $evt['money']);
240 $page->assign('tout', !Env
::get('item_id', false
));
243 function handler_edit(&$page, $eid = null
)
247 // check the event is in our group
248 if (!is_null($eid)) {
249 $res = XDB
::query("SELECT short_name, asso_id
250 FROM groupex.evenements
251 WHERE eid = {?}", $eid);
252 $infos = $res->fetchOneAssoc();
253 if ($infos['asso_id'] != $globals->asso('id')) {
254 return PL_NOT_ALLOWED
;
258 new_groupadmin_page('xnetevents/edit.tpl');
260 $moments = range(1, 4);
261 $page->assign('moments', $moments);
263 if (Post
::get('intitule')) {
264 require_once dirname(__FILE__
).'/xnetevents/xnetevents.inc.php';
265 $short_name = event_change_shortname($page, $infos['short_name'],
266 Env
::get('short_name', ''));
270 'asso_id' => $globals->asso('id'),
271 'organisateur_uid' => Session
::get('uid'),
272 'paiement_id' => Post
::get('paiement_id') > 0 ? Post
::get('paiement_id') : null
,
273 'debut' => Post
::get('deb_Year').'-'.Post
::get('deb_Month')
274 .'-'.Post
::get('deb_Day').' '.Post
::get('deb_Hour')
275 .':'.Post
::get('deb_Minute').':00',
276 'fin' => Post
::get('fin_Year').'-'.Post
::get('fin_Month')
277 .'-'.Post
::get('fin_Day').' '.Post
::get('fin_Hour')
278 .':'.Post
::get('fin_Minute').':00',
279 'short_name' => $short_name,
282 $trivial = array('intitule', 'descriptif', 'noinvite',
283 'show_participants');
284 foreach ($trivial as $k) {
285 $evt[$k] = Post
::get($k);
288 if (Post
::get('deadline')) {
289 $evt['deadline_inscription'] = Post
::get('inscr_Year').'-'
290 . Post
::get('inscr_Month').'-'
291 . Post
::get('inscr_Day');
293 $evt['deadline_inscription'] = null
;
296 // Store the modifications in the database
297 XDB
::execute('REPLACE INTO groupex.evenements
298 SET eid={?}, asso_id={?}, organisateur_uid={?}, intitule={?},
299 paiement_id = {?}, descriptif = {?}, debut = {?},
300 fin = {?}, show_participants = {?}, short_name = {?},
301 deadline_inscription = {?}, noinvite = {?}',
302 $evt['eid'], $evt['asso_id'], $evt['organisateur_uid'],
303 $evt['intitule'], $evt['paiement_id'], $evt['descriptif'],
304 $evt['debut'], $evt['fin'], $evt['show_participants'],
305 $evt['short_name'], $evt['deadline_inscription'],
308 // if new event, get its id
310 $eid = mysql_insert_id();
316 foreach ($moments as $i) {
317 if (Post
::get('titre'.$i)) {
320 $montant = strtr(Post
::get('montant'.$i), ',', '.');
321 $money_defaut +
= (float)$montant;
323 REPLACE INTO groupex.evenements_items
324 VALUES ({?}, {?}, {?}, {?}, {?})",
325 $eid, $i, Post
::get('titre'.$i),
326 Post
::get('details'.$i), $montant);
328 XDB
::execute("DELETE FROM groupex.evenements_items
329 WHERE eid = {?} AND item_id = {?}", $eid, $i);
333 // request for a new payment
334 if (Post
::get('paiement_id') == -1 && $money_defaut >= 0) {
335 require_once 'validations.inc.php';
336 $p = new PayReq(Session
::get('uid'),
337 Post
::get('intitule')." - ".$globals->asso('nom'),
338 Post
::get('site'), $money_defaut,
339 Post
::get('confirmation'), 0, 999,
340 $globals->asso('id'), $eid);
344 // events with no sub-event: add a sub-event with no name
345 if ($nb_moments == 0) {
346 XDB
::execute("INSERT INTO groupex.evenements_items
347 VALUES ({?}, {?}, '', '', 0)", $eid, 1);
350 if (is_null($evt['eid'])) {
352 redirect(smarty_function_rel().'/'.$platal->path
.'/'.$eid);
356 // get a list of all the payment for this asso
357 $res = XDB
::iterator("SELECT id, text
358 FROM {$globals->money->mpay_tprefix}paiements
359 WHERE asso_id = {?}", $globals->asso('id'));
360 $paiements = array();
361 while ($a = $res->next()) $paiements[$a['id']] = $a['text']; {
362 $page->assign('paiements', $paiements);
365 // when modifying an old event retreive the old datas
368 "SELECT eid, intitule, descriptif, debut, fin,
369 show_participants, paiement_id, short_name,
370 deadline_inscription, noinvite
371 FROM groupex.evenements
372 WHERE eid = {?}", $eid);
373 $evt = $res->fetchOneAssoc();
374 // find out if there is already a request for a payment for this event
375 require_once 'validations.inc.php';
376 $res = XDB
::query("SELECT stamp FROM requests
377 WHERE type = 'paiements' AND data LIKE {?}",
378 PayReq
::same_event($eid, $globals->asso('id')));
379 $stamp = $res->fetchOneCell();
381 $evt['paiement_id'] = -2;
382 $evt['paiement_req'] = $stamp;
384 $page->assign('evt', $evt);
385 // get all the different moments infos
386 $res = XDB
::iterator(
387 "SELECT item_id, titre, details, montant
388 FROM groupex.evenements_items AS ei
389 INNER JOIN groupex.evenements AS e ON(e.eid = ei.eid)
391 ORDER BY item_id", $eid);
393 while ($item = $res->next()) {
394 $items[$item['item_id']] = $item;
396 $page->assign('items', $items);
400 function handler_admin(&$page, $eid = null
, $item_id = null
)
404 require_once dirname(__FILE__
).'/xnetevents/xnetevents.inc.php';
406 $evt = get_event_detail($eid, $item_id);
411 if ($evt['show_participants']) {
412 new_group_page('xnetevents/admin.tpl');
414 new_groupadmin_page('xnetevents/admin.tpl');
417 if (may_update() && Post
::get('adm')) {
418 $member = get_infos(Post
::get('mail'));
420 $page->trig("Membre introuvable");
423 // change the price paid by a participant
424 if (Env
::get('adm') == 'prix' && $member) {
425 XDB
::execute("UPDATE groupex.evenements_participants
426 SET paid = IF(paid + {?} > 0, paid + {?}, 0)
427 WHERE uid = {?} AND eid = {?}",
428 strtr(Env
::get('montant'), ',', '.'),
429 strtr(Env
::get('montant'), ',', '.'),
430 $member['uid'], $eid);
433 // change the number of personns coming with a participant
434 if (Env
::get('adm') == 'nbs' && $member) {
435 $res = XDB
::query("SELECT paid
436 FROM groupex.evenements_participants
437 WHERE uid = {?} AND eid = {?}",
438 $member['uid'], $eid);
440 $paid = intval($res->fetchOneCell());
441 $nbs = Post
::getMixed('nb', array());
443 foreach ($nbs as $id => $nb) {
444 $nb = max(intval($nb), 0);
447 XDB
::execute("REPLACE INTO groupex.evenements_participants
448 VALUES ({?}, {?}, {?}, {?}, {?})",
449 $eid, $member['uid'], $id, $nb, $paid);
451 XDB
::execute("DELETE FROM groupex.evenements_participants
452 WHERE uid = {?} AND eid = {?} AND item_id = {?}",
453 $member['uid'], $eid, $id);
457 $res = XDB
::query("SELECT uid FROM groupex.evenements_participants
458 WHERE uid = {?} AND eid = {?}",
459 $member['uid'], $eid);
460 $u = $res->fetchOneCell();
461 subscribe_lists_event($u, $member['uid'], $evt);
464 $evt = get_event_detail($eid, $item_id);
467 $page->assign('admin', may_update());
468 $page->assign('evt', $evt);
469 $page->assign('tout', is_null($item_id));
471 if (count($evt['moments'])) {
472 $page->assign('moments', $evt['moments']);
475 $tri = (Env
::get('order') == 'alpha' ?
'promo, nom, prenom' : 'nom, prenom, promo');
476 $whereitemid = is_null($item_id) ?
'' : "AND ep.item_id = $item_id";
478 'SELECT UPPER(SUBSTRING(IF(u.nom IS NULL, m.nom,
479 IF(u.nom_usage<>"", u.nom_usage, u.nom)), 1, 1)),
480 COUNT(DISTINCT ep.uid)
481 FROM groupex.evenements_participants AS ep
482 INNER JOIN groupex.evenements AS e ON (ep.eid = e.eid)
483 LEFT JOIN groupex.membres AS m ON ( ep.uid = m.uid AND e.asso_id = m.asso_id)
484 LEFT JOIN auth_user_md5 AS u ON ( u.user_id = ep.uid )
485 WHERE ep.eid = {?} '.$whereitemid.'
486 GROUP BY UPPER(SUBSTRING(IF(u.nom IS NULL,m.nom,u.nom), 1, 1))', $eid);
490 while (list($char, $nb) = $res->next()) {
491 $alphabet[ord($char)] = $char;
493 if (Env
::has('initiale') && $char == strtoupper(Env
::get('initiale'))) {
498 $page->assign('alphabet', $alphabet);
500 $ofs = Env
::getInt('offset');
501 $tot = Env
::get('initiale') ?
$tot : $nb_tot;
502 $nbp = intval(($tot-1)/NB_PER_PAGE
);
505 $links['précédent'] = $ofs-1;
507 for ($i = 0; $i <= $nbp; $i++
) {
508 $links[(string)($i+
1)] = $i;
511 $links['suivant'] = $ofs+
1;
513 if (count($links)>1) {
514 $page->assign('links', $links);
517 if ($evt['paiement_id']) {
518 $res = XDB
::iterator(
519 "SELECT IF(u.nom_usage<>'', u.nom_usage, u.nom) AS nom, u.prenom,
520 u.promo, a.alias AS email, t.montant
521 FROM {$globals->money->mpay_tprefix}transactions AS t
522 INNER JOIN auth_user_md5 AS u ON(t.uid = u.user_id)
523 INNER JOIN aliases AS a ON (a.id = t.uid AND a.type='a_vie' )
524 LEFT JOIN groupex.evenements_participants AS ep ON(ep.uid = t.uid AND ep.eid = {?})
525 WHERE t.ref = {?} AND ep.uid IS NULL",
526 $evt['eid'], $evt['paiement_id']);
527 $page->assign('oublis', $res->total());
528 $page->assign('oubliinscription', $res);
531 $page->assign('participants',
532 get_event_participants($evt, $item_id, $tri,
533 "LIMIT ".($ofs*NB_PER_PAGE
).", ".NB_PER_PAGE
));