5e089289c3f274ae3d7e804f74689b0a836db3a7
2 /***************************************************************************
3 * Copyright (C) 2003-2010 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 // {{{ function get_event_detail()
24 function get_event_detail($eid, $item_id = false
, $asso_id = null
)
27 if (is_null($asso_id)) {
28 $asso_id = $globals->asso('id');
31 "SELECT SUM(nb) AS nb_tot, COUNT(DISTINCT ep.uid) AS nb, e.*,
32 IF(e.deadline_inscription, e.deadline_inscription >= LEFT(NOW(), 10), 1) AS inscr_open,
33 LEFT(10, e.debut) AS first_day, LEFT(10, e.fin) AS last_day,
34 LEFT(NOW(), 10) AS now, ei.titre,
35 al.vid AS absent_list, pl.vid AS participant_list,
36 bl.vid AS payed_list, ul.vid AS booked_unpayed_list,
37 a.nom, a.prenom, a.promo, aa.alias
38 FROM #groupex#.evenements AS e
39 INNER JOIN #x4dat#.auth_user_md5 AS a ON a.user_id = e.organisateur_uid
40 INNER JOIN #x4dat#.aliases AS aa ON (aa.type = 'a_vie' AND aa.id = a.user_id)
41 INNER JOIN #groupex#.evenements_items AS ei ON (e.eid = ei.eid)
42 LEFT JOIN #groupex#.evenements_participants AS ep ON (e.eid = ep.eid AND ei.item_id = ep.item_id)
43 LEFT JOIN #x4dat#.virtual AS al ON (al.type = 'evt' AND al.alias = CONCAT(short_name, {?}))
44 LEFT JOIN #x4dat#.virtual AS pl ON (pl.type = 'evt' AND pl.alias = CONCAT(short_name, {?}))
45 LEFT JOIN #x4dat#.virtual AS bl ON (bl.type = 'evt' AND bl.alias = CONCAT(short_name, {?}))
46 LEFT JOIN #x4dat#.virtual AS ul ON (ul.type = 'evt' AND ul.alias = CONCAT(short_name, {?}))
47 WHERE (e.eid = {?} OR e.short_name = {?}) AND ei.item_id = {?} AND e.asso_id = {?}
49 '-absents@' . $globals->xnet
->evts_domain
,
50 '-participants@' . $globals->xnet
->evts_domain
,
51 '-paye@' . $globals->xnet
->evts_domain
,
52 '-participants-non-paye@' . $globals->xnet
->evts_domain
,
53 $eid, $eid, $item_id ?
$item_id : 1, $asso_id);
55 $evt = $res->fetchOneAssoc();
60 if ($GLOBALS['IS_XNET_SITE'] && $evt['accept_nonmembre'] == 0 && !is_member() && !may_update()) {
64 // smart calculation of the total number
68 FROM #groupex#.evenements AS e
69 INNER JOIN #groupex#.evenements_items AS ei ON (e.eid = ei.eid)
70 LEFT JOIN #groupex#.evenements_participants AS ep
71 ON (e.eid = ep.eid AND ei.item_id = ep.item_id)
73 GROUP BY ep.uid", $evt['eid']);
74 $evt['nb_tot'] = array_sum($res->fetchColumn());
80 "SELECT titre, details, montant, ei.item_id, nb, ep.paid, FIND_IN_SET('notify_payment', ep.flags) AS notify_payment
81 FROM #groupex#.evenements_items AS ei
82 LEFT JOIN #groupex#.evenements_participants AS ep
83 ON (ep.eid = ei.eid AND ep.item_id = ei.item_id AND uid = {?})
85 S
::v('uid'), $evt['eid']);
86 $evt['moments'] = $res->fetchAllAssoc();
90 $evt['notify_payment'] = false
;
91 foreach ($evt['moments'] as $m) {
92 $evt['topay'] +
= $m['nb'] * $m['montant'];
96 $evt['paid'] = $m['paid'];
97 $evt['notify_payment'] = $evt['notify_payment'] ||
$m['notify_payment'];
102 FROM {$globals->money->mpay_tprefix}transactions AS t
103 WHERE ref = {?} AND uid = {?}", $evt['paiement_id'], S
::v('uid'));
104 $montants = $req->fetchColumn();
106 $evt['telepaid'] = 0;
107 foreach ($montants as $m) {
108 $p = strtr(substr($m, 0, strpos($m, 'EUR')), ',', '.');
109 $evt['paid'] +
= trim($p);
110 $evt['telepaid'] +
= trim($p);
113 make_event_date($evt);
120 // {{{ function get_event_participants()
121 function get_event_participants(&$evt, $item_id, $tri, $limit = '') {
124 if (Env
::has('initiale')) {
125 $where = 'AND IF(u.nom IS NULL, m.nom,
126 IF(u.nom_usage<>"", u.nom_usage, u.nom))
127 LIKE "'.addslashes(Env
::v('initiale')).'%"';
133 $money = $evt['money'] && (function_exists('may_update')) && may_update();
134 $pay_id = $evt['paiement_id'];
137 "SELECT IF(m.origine != 'X',m.nom,IF(u.nom_usage<>'', u.nom_usage, u.nom)) AS nom,
138 IF(m.origine != 'X',m.prenom,u.prenom) AS prenom,
139 IF(m.origine != 'X','extérieur',u.promo) AS promo,
140 IF(m.origine != 'X' OR u.perms = 'pending',m.email,a.alias) AS email,
141 IF(m.origine != 'X',m.sexe,FIND_IN_SET('femme', u.flags)) AS femme,
142 m.perms='admin' AS admin,
143 (m.origine = 'X' OR m.origine IS NULL) AS x,
144 ep.uid, SUM(ep.paid) AS paid, SUM(ep.nb) AS nb,
145 FIND_IN_SET('notify_payment', ep.flags) AS notify_payment
146 FROM #groupex#.evenements_participants AS ep
147 INNER JOIN #groupex#.evenements AS e ON (ep.eid = e.eid)
148 LEFT JOIN #groupex#.membres AS m ON ( ep.uid = m.uid AND e.asso_id = m.asso_id)
149 LEFT JOIN #x4dat#.auth_user_md5 AS u ON ( u.user_id = ep.uid )
150 LEFT JOIN #x4dat#.aliases AS a ON ( a.id = ep.uid AND a.type='a_vie' )
152 ".(($item_id)?
" AND item_id = $item_id":"")."
155 ORDER BY $tri $limit";
158 $res = XDB
::query($query, $eid);
159 return $res->fetchAllAssoc();
162 $res = XDB
::iterator($query, $eid);
166 $evt['adminpaid'] = 0;
167 $evt['telepaid'] = 0;
170 while ($u = $res->next()) {
174 $u['adminpaid'] = $u['paid'];
176 if ($money && $pay_id) {
179 FROM {$globals->money->mpay_tprefix}transactions AS t
180 WHERE ref = {?} AND uid = {?}",
182 $montants = $res_->fetchColumn();
183 foreach ($montants as $m) {
184 $p = strtr(substr($m, 0, strpos($m, "EUR")), ",", ".");
185 $u['paid'] +
= trim($p);
188 $u['telepayment'] = $u['paid'] - $u['adminpaid'];
189 $res_ = XDB
::iterator(
190 "SELECT ep.nb, ep.item_id, ei.montant
191 FROM #groupex#.evenements_participants AS ep
192 INNER JOIN #groupex#.evenements_items AS ei ON (ei.eid = ep.eid AND ei.item_id = ep.item_id)
193 WHERE ep.eid = {?} AND ep.uid = {?}",
195 while ($i = $res_->next()) {
196 $u[$i['item_id']] = $i['nb'];
197 $u['montant'] +
= $i['montant']*$i['nb'];
200 $evt['telepaid'] +
= $u['telepayment'];
201 $evt['adminpaid'] +
= $u['adminpaid'];
202 $evt['paid'] +
= $u['paid'];
203 $evt['topay'] +
= $u['montant'];
209 // {{{ function subscribe_lists_event()
210 function subscribe_lists_event($participate, $uid, $evt, $paid, $payment = null
)
213 $page =& Platal
::page();
215 $participant_list = $evt['participant_list'];
216 $absent_list = $evt['absent_list'];
217 $unpayed_list = $evt['booked_unpayed_list'];
218 $payed_list = $evt['payed_list'];
220 $user = User
::getSilent($uid);
222 $email = $user->forlifeEmail();
224 $res = XDB
::query("SELECT email
225 FROM #groupex#.membres
226 WHERE uid = {?} AND asso_id = {?}",
227 $uid, $globals->asso('id'));
228 $email = $res->fetchOneCell();
231 function subscribe($list, $email)
233 if ($list && $email) {
234 XDB
::execute("REPLACE INTO virtual_redirect
240 function unsubscribe($list, $email)
242 if ($list && $email) {
243 XDB
::execute("DELETE FROM virtual_redirect
244 WHERE vid = {?} AND redirect = {?}",
249 if (is_null($payment)) {
250 if (is_null($participate)) {
251 unsubscribe($participant_list, $email);
252 subscribe($absent_list, $email);
253 } elseif ($participate) {
254 subscribe($participant_list, $email);
255 unsubscribe($absent_list, $email);
257 unsubscribe($participant_list, $email);
258 unsubscribe($absent_list, $email);
262 unsubscribe($unpayed_list, $email);
263 subscribe($payed_list, $email);
265 unsubscribe($payed_list, $email);
266 if (!is_null($participate)) {
267 subscribe($unpayed_list, $email);
273 // {{{ function event_change_shortname()
274 function event_change_shortname(&$page, $eid, $old, $new)
281 // Quelques vérifications sur l'alias (caractères spéciaux)
282 if ($new && !preg_match( "/^[a-zA-Z0-9\-.]{3,20}$/", $new)) {
283 $page->trigError("Le raccourci demandé n'est pas valide.
284 Vérifie qu'il comporte entre 3 et 20 caractères
285 et qu'il ne contient que des lettres non accentuées,
286 des chiffres ou les caractères - et .");
288 } elseif ($new && ctype_digit($new)) {
289 $page->trigError("Le raccourci demandé ne peut être accepté car il
290 ne contient que des chiffres. Rajoute-lui par exemple
295 //vérifier que l'alias n'est pas déja pris
296 if ($new && $old != $new) {
297 $res = XDB
::query('SELECT COUNT(*)
298 FROM #groupex#.evenements
299 WHERE short_name = {?}',
301 if ($res->fetchOneCell() > 0) {
302 $page->trigError("Le raccourci demandé est déjà utilisé. Choisis en un autre.");
312 // if had a previous shortname change the old lists
313 foreach (array('-absents@', '-participants@', '-paye@', '-participants-non-paye@') as $v) {
314 $v .= $globals->xnet
->evts_domain
;
315 XDB
::execute("UPDATE virtual
317 WHERE type = 'evt' AND alias = {?}",
318 $new . $v, $old . $v);
324 // if we have a first new short_name create the lists
327 '-participants@' => 'ep.nb > 0',
328 '-paye@' => 'ep.paid > 0',
329 '-participants-non-paye@' => 'ep.nb > 0 AND ep.paid = 0'
332 foreach (array('-absents@', '-participants@', '-paye@', '-participants-non-paye@') as $v) {
333 XDB
::execute("INSERT INTO virtual
334 SET type = 'evt', alias = {?}",
335 $new . $v . $globals->xnet
->evts_domain
);
337 $lastid[$v] = XDB
::insertId();
340 foreach (array('-participants@', '-paye@', '-participants-non-paye@') as $v) {
341 XDB
::execute("INSERT IGNORE INTO virtual_redirect (
342 SELECT {?} AS vid, IF(a.alias IS NULL, m.email, CONCAT(a.alias, {?})) AS redirect
343 FROM #groupex#.evenements_participants AS ep
344 LEFT JOIN #groupex#.membres AS m ON (ep.uid = m.uid)
345 LEFT JOIN #x4dat#.auth_user_md5 AS u ON (u.user_id = ep.uid)
346 LEFT JOIN #x4dat#.aliases AS a ON (a.id = ep.uid AND a.type = 'a_vie')
347 WHERE ep.eid = {?} AND " . $where[$v] . "
349 $lastid[$v], '@' . $globals->mail
->domain
, $eid);
351 XDB
::execute("INSERT IGNORE INTO virtual_redirect (
352 SELECT {?} AS vid, IF(a.alias IS NULL, m.email, CONCAT(a.alias, {?})) AS redirect
353 FROM #groupex#.membres AS m
354 LEFT JOIN #groupex#.evenements_participants AS ep ON (ep.uid = m.uid AND ep.eid = {?})
355 LEFT JOIN #x4dat#.auth_user_md5 AS u ON (u.user_id = m.uid)
356 LEFT JOIN #x4dat#.aliases AS a ON (a.id = m.uid AND a.type = 'a_vie')
357 WHERE m.asso_id = {?} AND ep.uid IS NULL
359 $lastid['-absents@'], '@' . $globals->mail
->domain
, $eid, $globals->asso('id'));
365 // if we delete the old short name, delete the lists
366 foreach (array('-absents@', '-participants@', '-paye@', '-participants-non-paye@') as $v) {
367 $v .= $globals->xnet
->evts_domain
;
368 XDB
::execute("DELETE virtual, virtual_redirect
370 LEFT JOIN virtual_redirect USING(vid)
371 WHERE virtual.alias = {?}",
372 $infos['short_name'] . $v);
382 // {{{ function make_event_date()
383 function make_event_date(&$e)
385 $start = strtotime($e['debut']);
386 $end = strtotime($e['fin']);
387 $first_day = strtotime($e['first_day']);
388 $last_day = strtotime($e['last_day']);
389 unset($e['debut'], $e['fin'], $e['first_day'], $e['last_day']);
392 if ($start && $end != $start) {
393 if ($first_day == $last_day) {
394 $date .= "le " . strftime("%d %B %Y", $start) . " de "
395 . strftime("%H:%M", $start) . " à " . strftime("%H:%M", $end);
397 $date .= "du " . strftime("%d %B %Y à %H:%M", $start)
398 . "\nau " . strftime("%d %B %Y à %H:%M", $end);
401 $date .= "le " . strftime("%d %B %Y à %H:%M", $start);
407 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: