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