bug 399, refuser les invites aux evenements xnet
[platal.git] / htdocs.net / groupe / evenements.php
CommitLineData
0337d704 1<?php
2require 'xnet.inc.php';
258b9710 3// vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
4/***************************************************************************
5 * Copyright (C) 2003-2004 Polytechnique.org *
6 * http://opensource.polytechnique.org/ *
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the Free Software *
20 * Foundation, Inc., *
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
22 ***************************************************************************/
0337d704 23
24new_group_page('xnet/groupe/evenements.tpl');
25
258b9710 26/**** manage inscriptions ****/
27// inscription to events
28if (Env::has('ins')) {
29 for ($i=1; Env::has('evt_'.$i); $i++)
30 {
31 $eid = Env::get('evt_'.$i);
32 $res = $globals->xdb->query("
33 SELECT deadline_inscription,
34 LEFT(NOW(), 10) AS now,
a8c3c073 35 noinvite,
258b9710 36 membres_only
37 FROM groupex.evenements
38 WHERE eid = {?}", $eid);
39 $e = $res->fetchOneAssoc();
40 // impossible to change inscription: either inscription closed or members only
41 if ($e['deadline_inscription'] && $e['deadline_inscription']<$e['now'])
42 {
43 $page->trig("Les inscriptions sont closes");
44 continue;
45 }
46
47 if ($e['membres_only'] && !is_member())
48 {
49 $page->trig("Les inscriptions à cet événement ne sont pas publiques");
50 continue;
51 }
52
53 // impossible to unsubscribe if you already paid sthing
54 $total_inscr = 0;
55 $inscriptions = array();
82ab5344 56 for ($j=1; Env::has('moment'.$eid.'_'.$j); $j++)
258b9710 57 {
82ab5344 58 $inscriptions[$j] = Env::get('moment'.$eid.'_'.$j);
258b9710 59 // retreive ohter field when more than one person
82ab5344 60 if ($inscriptions[$j] == 2)
61 $inscriptions[$j] = 1 + Env::get('personnes'.$eid.'_'.$j,0);
258b9710 62 // avoid negative count if other field incorrect
82ab5344 63 if ($inscriptions[$j] < 0)
64 $inscriptions[$j] = 0;
258b9710 65 // avoid floating count if other field incorrect
82ab5344 66 $inscriptions[$j] = floor($inscriptions[$j]);
a8c3c073 67 // avoid invite if no invite allowed
68 if ($inscriptions[$j] > 1 && $e['noinvite'])
69 $inscriptions[$j] = 1;
82ab5344 70 $total_inscr += $inscriptions[$j];
258b9710 71 }
72 $unsubscribing = ($total_inscr == 0);
73
74 // retreive the amount already paid for this event in cash
75 $res = $globals->xdb->query("
76 SELECT paid
77 FROM groupex.evenements_participants
78 WHERE eid = {?} AND uid = {?}
79 LIMIT 1",
80 $eid, Session::get("uid"));
81 $paid = $res->fetchOneCell();
82 if (!$paid) $paid = 0;
83
84 if ($unsubscribing && $paid != 0)
85 {
86 $page->trig("Impossible de te désinscrire complètement parce que tu as fait un paiement par chèque ou par liquide. Contacte un administrateur du groupe si tu es sûr de ne pas venir");
87 continue;
88 }
89
90 // update actual inscriptions
82ab5344 91 foreach ($inscriptions as $j=>$nb)
258b9710 92 {
93 if ($nb > 0)
94 {
95 $globals->xdb->execute(
96 "REPLACE INTO groupex.evenements_participants
97 VALUES ({?}, {?}, {?}, {?}, {?})",
82ab5344 98 $eid, Session::get("uid"), $j, $nb, $paid);
258b9710 99 }
100 else
101 {
102 $globals->xdb->execute(
103 "DELETE FROM groupex.evenements_participants
104 WHERE eid = {?} AND uid = {?} AND item_id = {?}",
82ab5344 105 $eid, Session::get("uid"), $j);
258b9710 106 }
107 }
108 }
0337d704 109}
110
258b9710 111/**** retreive all infos about all events ****/
112$page->assign('logged', logged());
113$page->assign('admin', may_update());
0337d704 114
258b9710 115$evenements = $globals->xdb->iterator(
be007d27 116"SELECT e.eid,
117 IF(e.intitule = '', ' ', e.intitule) AS intitule,
118 IF(e.descriptif = '', ' ', e.descriptif) AS descriptif,
258b9710 119 e.debut, e.fin,
120 LEFT(10,e.debut) AS debut_day,
121 LEFT(10,e.fin) AS fin_day,
a8c3c073 122 e.paiement_id, e.membres_only, e.noinvite,
258b9710 123 e.show_participants, u.nom, u.prenom, u.promo, a.alias, MAX(ep.nb) AS inscrit,
05370ed3 124 MAX(ep.paid) AS paid,
258b9710 125 e.short_name,
126 IF(e.deadline_inscription,e.deadline_inscription >= LEFT(NOW(), 10), 1) AS inscr_open, e.deadline_inscription
127 FROM groupex.evenements AS e
128INNER JOIN x4dat.auth_user_md5 AS u ON u.user_id = e.organisateur_uid
129 LEFT JOIN x4dat.aliases AS a ON (a.type = 'a_vie' AND a.id = u.user_id)
130 LEFT JOIN groupex.evenements_participants AS ep ON (ep.eid = e.eid AND ep.uid = {?})
131 WHERE asso_id = {?}
132 GROUP BY e.eid
133 ORDER BY debut",Session::get('uid'),$globals->asso('id'));
134
135$evts = array();
136while ($e = $evenements->next())
137{
138 $e['moments'] = $globals->xdb->iterator(
139 "SELECT titre, details, montant, ei.item_id, nb
140 FROM groupex.evenements_items AS ei
141 LEFT JOIN groupex.evenements_participants AS ep ON (ep.eid = ei.eid AND ep.item_id = ei.item_id AND uid = {?})
142 WHERE ei.eid = {?}",
143 Session::get('uid'), $e['eid']);
05370ed3 144 $query = $globals->xdb->query(
145 "SELECT montant
146 FROM {$globals->money->mpay_tprefix}transactions AS t
147 WHERE ref = {?} AND uid = {?}", $e['paiement_id'], Session::get('uid'));
148 $montants = $query->fetchColumn();
149 foreach ($montants as $m) {
150 $p = strtr(substr($m, 0, strpos($m, "EUR")), ",", ".");
151 $e['paid'] += trim($p);
152 }
258b9710 153 $evts[] = $e;
0337d704 154}
155
258b9710 156$page->assign('evenements', $evts);
157$page->assign('is_member', is_member());
0337d704 158
258b9710 159$page->assign('nb_evt', $evenements->total());
0337d704 160
161$page->run();
162
163?>