0337d704 |
1 | <?php |
2 | /*************************************************************************** |
3 | * Copyright (C) 2003-2004 Polytechnique.org * |
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 | |
22 | // {{{ function get_event_detail() |
23 | function get_event_detail($eid, $item_id = false) { |
24 | global $globals; |
25 | $res = $globals->xdb->query( |
26 | "SELECT SUM(nb) AS nb_tot, e.intitule, ei.titre, |
27 | debut AS deb, fin, membres_only, descriptif, e.eid, |
28 | e.show_participants, e.paiement_id, e.short_name, |
258b9710 |
29 | e.deadline_inscription, LEFT(NOW(), 10) AS now, |
0337d704 |
30 | al.vid AS absent_list, pl.vid AS participant_list, |
31 | a.nom, a.prenom, a.promo |
32 | FROM groupex.evenements AS e |
33 | INNER JOIN groupex.evenements_items AS ei ON (e.eid = ei.eid) |
34 | LEFT JOIN groupex.evenements_participants AS ep ON(e.eid = ep.eid AND ei.item_id = ep.item_id) |
35 | LEFT JOIN virtual AS al ON(al.type = 'evt' AND al.alias = CONCAT(short_name, {?})) |
36 | LEFT JOIN virtual AS pl ON(pl.type = 'evt' AND pl.alias = CONCAT(short_name, {?})) |
37 | LEFT JOIN auth_user_md5 AS a ON (a.user_id = e.organisateur_uid) |
38 | WHERE e.eid = {?} AND ei.item_id = {?} AND e.asso_id = {?} |
39 | GROUP BY ei.item_id", |
40 | '-absents@'.$globals->xnet->evts_domain, |
41 | '-participants@'.$globals->xnet->evts_domain, |
42 | $eid, $item_id?$item_id:1, $globals->asso('id')); |
43 | $evt = $res->fetchOneAssoc(); |
44 | if (!$evt) return false; |
45 | |
46 | // smart calculation of the total number |
47 | if (!$item_id) { |
48 | $res = $globals->xdb->query( |
49 | "SELECT MAX(nb) |
50 | FROM groupex.evenements AS e |
51 | INNER JOIN groupex.evenements_items AS ei ON (e.eid = ei.eid) |
52 | LEFT JOIN groupex.evenements_participants AS ep ON(e.eid = ep.eid AND ei.item_id = ep.item_id) |
53 | WHERE e.eid = {?} |
54 | GROUP BY ep.uid", $eid); |
55 | $evt['nb_tot'] = array_sum($res->fetchColumn()); |
56 | $evt['titre'] = ''; |
57 | $evt['item_id'] = 0; |
58 | } |
59 | |
60 | $res = $globals->xdb->iterator( |
61 | "SELECT eid, item_id, titre, montant |
62 | FROM groupex.evenements_items |
63 | WHERE eid = {?}", |
64 | $eid); |
65 | $moments = array(); $evt['money'] = false; |
66 | while ($m = $res->next()) { |
67 | $moments[$m['item_id']] = $m; |
68 | if ($m['montant'] > 0) $evt['money'] = true; |
69 | } |
70 | $evt['moments'] = $moments; |
71 | return $evt; |
72 | } |
73 | // }}} |
74 | |
75 | // {{{ function get_event_participants() |
76 | function get_event_participants($eid, $item_id, $where, $tri, $limit, $money, $pay_id) { |
77 | global $globals; |
78 | $query = |
79 | "SELECT IF(u.nom IS NULL,m.nom,IF(u.nom_usage<>'', u.nom_usage, u.nom)) AS nom, |
80 | IF(u.nom IS NULL,m.prenom,u.prenom) AS prenom, |
81 | IF(u.nom IS NULL,'extérieur',u.promo) AS promo, |
82 | IF(u.nom IS NULL,m.email,a.alias) AS email, |
83 | IF(u.nom IS NULL,0,FIND_IN_SET('femme', u.flags)) AS femme, |
84 | m.perms='admin' AS admin, |
85 | NOT(u.nom IS NULL) AS x, |
86 | ep.uid, ep.paid, SUM(nb) AS nb |
87 | FROM groupex.evenements_participants AS ep |
88 | INNER JOIN groupex.evenements AS e ON (ep.eid = e.eid) |
89 | LEFT JOIN groupex.membres AS m ON ( ep.uid = m.uid AND e.asso_id = m.asso_id) |
90 | LEFT JOIN auth_user_md5 AS u ON ( u.user_id = ep.uid ) |
91 | LEFT JOIN aliases AS a ON ( a.id = ep.uid AND a.type='a_vie' ) |
92 | WHERE ep.eid = {?} |
93 | ".(($item_id)?" AND item_id = $item_id":"")." |
94 | $where |
95 | GROUP BY ep.uid |
96 | ORDER BY $tri |
97 | $limit"; |
98 | if ($item_id) { |
99 | $res = $globals->xdb->query($query, $eid); |
100 | return $res->fetchAllAssoc(); |
101 | } |
102 | $res = $globals->xdb->iterator($query, $eid); |
103 | $tab = array(); |
104 | $user = 0; |
105 | while ($u = $res->next()) { |
106 | $u['montant'] = 0; |
107 | if ($money && $pay_id) { |
108 | $res_ = $globals->xdb->query( |
109 | "SELECT montant |
110 | FROM {$globals->money->mpay_tprefix}transactions AS t |
111 | WHERE ref = {?} AND uid = {?}", |
112 | $pay_id, $u['uid']); |
113 | $montants = $res_->fetchColumn(); |
114 | foreach ($montants as $m) { |
115 | $p = strtr(substr($m, 0, strpos($m, "EUR")), ",", "."); |
116 | $u['paid'] += trim($p); |
117 | } |
118 | } |
119 | $res_ = $globals->xdb->iterator( |
120 | "SELECT ep.nb, ep.item_id, ei.montant |
121 | FROM groupex.evenements_participants AS ep |
122 | INNER JOIN groupex.evenements_items AS ei ON (ei.eid = ep.eid AND ei.item_id = ep.item_id) |
123 | WHERE ep.eid = {?} AND ep.uid = {?}", |
124 | $eid, $u['uid']); |
125 | while ($i = $res_->next()) { |
126 | $u[$i['item_id']] = $i['nb']; |
127 | $u['montant'] += $i['montant']*$i['nb']; |
128 | } |
129 | $tab[] = $u; |
130 | } |
131 | return $tab; |
132 | } |
133 | // }}} |
134 | |
135 | // {{{ function subscribe_lists_event() |
136 | function subscribe_lists_event($participate, $uid, $participant_list, $absent_list) { |
137 | global $globals,$page; |
138 | |
139 | $email = Session::get('forlife'); |
140 | |
141 | if ($email) { |
142 | $email .= '@'.$globals->mail->domain; |
143 | } else { |
144 | $res = $globals->xdb->query("SELECT email FROM groupex.membres WHERE uid = {?} AND asso_id = {?}", Session::get('uid'), $globals->asso('id')); |
145 | $email = $res->fetchOneCell(); |
146 | } |
147 | |
148 | $subscribe = $participate?$participant_list:(is_member()?$absent_list:0); |
149 | $unsubscri = $participate?$absent_list:$participant_list; |
150 | |
151 | if ($subscribe) { |
152 | $globals->xdb->execute( |
153 | "REPLACE INTO virtual_redirect VALUES({?},{?})", |
154 | $subscribe, $email); |
155 | } |
156 | |
157 | if ($unsubscri) { |
158 | $globals->xdb->execute( |
159 | "DELETE FROM virtual_redirect WHERE vid = {?} AND redirect = {?}", |
160 | $unsubscri, $email); |
161 | } |
162 | |
163 | } |
164 | // }}} |
165 | |
166 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: |
167 | ?> |