Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
c441aabe | 3 | * Copyright (C) 2003-2014 Polytechnique.org * |
0337d704 | 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 | ||
c860774b NI |
22 | // {{{ function get_event_order() |
23 | /* get the order to paste the events | |
24 | * @param $asso_id: group's id | |
25 | */ | |
26 | function get_event_order($asso_id) | |
27 | { | |
28 | $order = XDB::fetchOneCell('SELECT g.event_order | |
29 | FROM groups as g | |
30 | WHERE id = {?}', | |
31 | $asso_id); | |
32 | return $order; | |
33 | } | |
34 | // }}} | |
35 | ||
36 | // {{{ function get_events() | |
37 | /* get the events of the given group ordered by the standard order for the group | |
38 | * @param $asso_id: group's id | |
39 | * @param $order: order to paste the events (asc or desc) | |
13fc173c | 40 | * @param $archive: whether to get the archived events (1) or the actuals (0) |
c860774b | 41 | */ |
13fc173c | 42 | function get_events($asso_id, $order, $archive) |
c860774b NI |
43 | { |
44 | if ($order != 'asc' && $order != 'desc') { | |
45 | $order = 'desc'; | |
46 | } | |
47 | $evts = XDB::fetchAllAssoc('eid', "SELECT ge.eid, ge.uid, ge.intitule, ge.debut, ge.fin, ge.show_participants, ge.deadline_inscription, ge.accept_nonmembre, ge.paiement_id | |
48 | FROM group_events as ge | |
13fc173c | 49 | WHERE asso_id = {?} and archive = {?} |
c860774b | 50 | ORDER BY ge.debut $order", |
13fc173c | 51 | $asso_id, $archive); |
c860774b NI |
52 | return $evts; |
53 | } | |
54 | // }}} | |
55 | ||
56 | // {{{ function get_event() (detail, for subs page only for now) | |
57 | /* get event details | |
58 | * @param $eid: event's id | |
59 | */ | |
60 | function get_event($eid) | |
61 | { | |
62 | $evt = XDB::fetchOneAssoc('SELECT ge.uid, ge.intitule, ge.descriptif, ge.debut, ge.fin, ge.deadline_inscription, ge.accept_nonmembre, ge.paiement_id | |
63 | FROM group_events as ge | |
64 | WHERE eid = {?}', | |
65 | $eid); | |
66 | if (!is_null($evt['deadline_inscription']) && strtotime($evt['deadline_inscription']) < time()) { | |
67 | $evt['inscr_open'] = false; | |
68 | } else { | |
69 | $evt['inscr_open'] = true; | |
70 | } | |
96b778a6 | 71 | $evt['organizer'] = User::getSilent($evt['uid']); |
c860774b NI |
72 | $evt['date'] = make_event_date($evt['debut'], $evt['fin']); |
73 | ||
74 | return $evt; | |
75 | } | |
76 | // }}} | |
77 | ||
78 | // {{{ function get_event_items() | |
79 | /** get items of the given event | |
80 | * | |
81 | * @param $eid : event's id | |
82 | * | |
83 | */ | |
84 | function get_event_items($eid) | |
85 | { | |
86 | $evt = XDB::fetchAllAssoc('item_id', 'SELECT gei.item_id, gei.titre, gei.details, gei.montant | |
87 | FROM group_event_items as gei | |
88 | WHERE eid = {?}', | |
89 | $eid); | |
90 | return $evt; | |
91 | } | |
92 | // }}} | |
93 | ||
94 | // {{{ function get_event_subscription() | |
95 | /* get all participations if uid is not specified, only the user's participation if uid specified | |
96 | * @param $eid: event's id | |
97 | * @param $uid: user's id | |
98 | */ | |
99 | function get_event_subscription($eid, $uid = null) | |
100 | { | |
101 | if (!is_null($uid)) { | |
102 | $where = ' and gep.uid = '.$uid; | |
103 | } | |
104 | else { | |
105 | $where = ''; | |
106 | } | |
107 | $sub = XDB::fetchAllAssoc('item_id','SELECT gep.item_id, gep.nb, gep.paid FROM group_event_participants as gep | |
108 | WHERE gep.eid = {?}'.$where, | |
109 | $eid); | |
110 | return $sub; | |
111 | } | |
112 | // }}} | |
113 | ||
114 | // {{{ function get_event_telepaid() | |
115 | /* get the total payments made by a user for an event | |
116 | * @param $eid: event's id | |
117 | * @param $uid: user's id | |
118 | */ | |
119 | function get_event_telepaid($eid, $uid) | |
120 | { | |
121 | $telepaid = XDB::fetchOneCell('SELECT SUM(pt.amount) | |
122 | FROM payment_transactions AS pt | |
123 | LEFT JOIN group_events as ge ON (ge.paiement_id = pt.ref) | |
124 | WHERE ge.eid = {?} AND pt.uid = {?}', | |
125 | $eid, $uid); | |
126 | return $telepaid; | |
127 | } | |
128 | // }}} | |
129 | ||
0337d704 | 130 | // {{{ function get_event_detail() |
d6d580ec | 131 | |
2ac0bcee | 132 | function get_event_detail($eid, $item_id = false, $asso_id = null) |
d6d580ec | 133 | { |
0337d704 | 134 | global $globals; |
2ac0bcee FB |
135 | if (is_null($asso_id)) { |
136 | $asso_id = $globals->asso('id'); | |
137 | } | |
3092eea7 SJ |
138 | if (!$item_id) { |
139 | $where = ''; | |
140 | $group_by = 'e.eid'; | |
141 | } else { | |
142 | $where = XDB::format(' AND ei.item_id = {?}', $item_id); | |
143 | $group_by = 'ei.item_id'; | |
144 | } | |
e48b1c76 | 145 | $evt = XDB::fetchOneAssoc('SELECT SUM(nb) AS nb_tot, COUNT(DISTINCT ep.uid) AS nb, e.*, SUM(IF(nb > 0, 1, 0)) AS user_count, |
7852229b SJ |
146 | IF(e.deadline_inscription, |
147 | e.deadline_inscription >= LEFT(NOW(), 10), | |
148 | 1) AS inscr_open, | |
0ea9f32b | 149 | LEFT(e.debut, 10) AS first_day, LEFT(e.fin, 10) AS last_day, |
7852229b SJ |
150 | LEFT(NOW(), 10) AS now, |
151 | ei.titre, e.subscription_notification | |
152 | FROM group_events AS e | |
153 | INNER JOIN group_event_items AS ei ON (e.eid = ei.eid) | |
154 | LEFT JOIN group_event_participants AS ep ON(e.eid = ep.eid AND ei.item_id = ep.item_id) | |
3092eea7 SJ |
155 | WHERE (e.eid = {?} OR e.short_name = {?}) AND e.asso_id = {?}' . $where . ' |
156 | GROUP BY ' . $group_by, | |
157 | $eid, $eid, $asso_id); | |
d6d580ec | 158 | |
df1cf596 | 159 | if (!$evt) { |
d6d580ec | 160 | return null; |
161 | } | |
df1cf596 FB |
162 | if ($GLOBALS['IS_XNET_SITE'] && $evt['accept_nonmembre'] == 0 && !is_member() && !may_update()) { |
163 | return false; | |
164 | } | |
0337d704 | 165 | |
0337d704 | 166 | if (!$item_id) { |
f9e8637a FB |
167 | /* Don't try to be to smart here, in case we're getting the global summary, we cannot have |
168 | * a general formula to estimate the total number of comers since 'moments' may (or may not be) | |
169 | * disjuncted. As a consequence, we can only provides the number of user having fullfiled the | |
170 | * registration procedure. | |
171 | */ | |
172 | $evt['user_count'] = $evt['nb_tot'] = $evt['nb']; | |
0337d704 | 173 | $evt['titre'] = ''; |
174 | $evt['item_id'] = 0; | |
80575e7c SJ |
175 | $evt['csv_name'] = urlencode($evt['intitule']); |
176 | } else { | |
177 | $evt['csv_name'] = urlencode($evt['intitule'] . '.' . $evt['titre']); | |
0337d704 | 178 | } |
d6d580ec | 179 | |
07eb5b0e FB |
180 | $evt['moments'] = XDB::fetchAllAssoc('SELECT titre, details, montant, ei.item_id, nb, |
181 | ep.paid, FIND_IN_SET(\'notify_payment\', ep.flags) AS notify_payment | |
eb41eda9 FB |
182 | FROM group_event_items AS ei |
183 | LEFT JOIN group_event_participants AS ep ON (ep.eid = ei.eid AND ep.item_id = ei.item_id | |
07eb5b0e FB |
184 | AND uid = {?}) |
185 | WHERE ei.eid = {?}', | |
186 | S::i('uid'), $evt['eid']); | |
d6d580ec | 187 | $evt['topay'] = 0; |
98a7e9dc | 188 | $evt['paid'] = 0; |
2ac0bcee | 189 | $evt['notify_payment'] = false; |
d6d580ec | 190 | foreach ($evt['moments'] as $m) { |
191 | $evt['topay'] += $m['nb'] * $m['montant']; | |
98a7e9dc | 192 | if ($m['montant']) { |
54ac7230 | 193 | $evt['money'] = true; |
98a7e9dc | 194 | } |
51f1911c | 195 | $evt['paid'] += $m['paid']; |
2ac0bcee | 196 | $evt['notify_payment'] = $evt['notify_payment'] || $m['notify_payment']; |
d6d580ec | 197 | } |
198 | ||
a7c0d514 | 199 | $montant = XDB::fetchOneCell('SELECT SUM(amount) AS sum_amount |
b3cd1320 | 200 | FROM payment_transactions AS t |
07eb5b0e FB |
201 | WHERE ref = {?} AND uid = {?}', |
202 | $evt['paiement_id'], S::v('uid')); | |
a7c0d514 DB |
203 | $evt['telepaid'] = $montant; |
204 | $evt['paid'] += $montant; | |
ed996b5a | 205 | $evt['organizer'] = User::getSilent($evt['uid']); |
d6d580ec | 206 | |
c860774b | 207 | $evt['date'] = make_event_date($evt['debut'], $evt['fin']); |
20c5c7e6 | 208 | |
b6f69874 | 209 | $evt['show_participants'] = ($evt['show_participants'] && $GLOBALS['IS_XNET_SITE'] && (is_member() || may_update())); |
5a6bcfb7 | 210 | |
0337d704 | 211 | return $evt; |
212 | } | |
d6d580ec | 213 | |
0337d704 | 214 | // }}} |
215 | ||
216 | // {{{ function get_event_participants() | |
8270d13a | 217 | function get_event_participants(&$evt, $item_id, array $tri = array(), $limit = null, $offset = 0) |
07eb5b0e | 218 | { |
0337d704 | 219 | global $globals; |
ed21e24a | 220 | |
ed21e24a | 221 | $eid = $evt['eid']; |
2ac0bcee | 222 | $money = $evt['money'] && (function_exists('may_update')) && may_update(); |
ed21e24a | 223 | $pay_id = $evt['paiement_id']; |
224 | ||
c81e03c0 | 225 | $append = $item_id ? XDB::format(' AND ep.item_id = {?}', $item_id) : ''; |
07eb5b0e FB |
226 | $query = XDB::fetchAllAssoc('uid', 'SELECT ep.uid, SUM(ep.paid) AS paid, SUM(ep.nb) AS nb, |
227 | FIND_IN_SET(\'notify_payment\', ep.flags) AS notify_payment | |
eb41eda9 | 228 | FROM group_event_participants AS ep |
07eb5b0e FB |
229 | WHERE ep.eid = {?} AND nb > 0 ' . $append . ' |
230 | GROUP BY ep.uid', $eid); | |
c8763ca3 | 231 | $uf = new UserFilter(new PFC_True(), $tri); |
8270d13a | 232 | $users = User::getBulkUsersWithUIDs($uf->filter(array_keys($query), new PlLimit($limit, $offset))); |
07eb5b0e FB |
233 | $tab = array(); |
234 | foreach ($users as $user) { | |
235 | $uid = $user->id(); | |
236 | $tab[$uid] = $query[$uid]; | |
237 | $tab[$uid]['user'] = $user; | |
238 | } | |
ed21e24a | 239 | |
0337d704 | 240 | if ($item_id) { |
07eb5b0e | 241 | return $tab; |
0337d704 | 242 | } |
ed21e24a | 243 | |
e01ebe65 FB |
244 | $evt['adminpaid'] = 0; |
245 | $evt['telepaid'] = 0; | |
246 | $evt['topay'] = 0; | |
247 | $evt['paid'] = 0; | |
07eb5b0e | 248 | foreach ($tab as $uid=>&$u) { |
5dcca1b1 | 249 | $u['adminpaid'] = (float)$u['paid']; |
0337d704 | 250 | $u['montant'] = 0; |
2ac0bcee | 251 | if ($money && $pay_id) { |
a7c0d514 | 252 | $montant = XDB::fetchOneCell('SELECT SUM(amount) |
b3cd1320 | 253 | FROM payment_transactions AS t |
07eb5b0e FB |
254 | WHERE ref = {?} AND uid = {?}', |
255 | $pay_id, $uid); | |
a7c0d514 | 256 | $u['paid'] += $montant; |
2ac0bcee | 257 | } |
58591700 | 258 | $u['telepayment'] = $u['paid'] - $u['adminpaid']; |
07eb5b0e | 259 | $res_ = XDB::iterator('SELECT ep.nb, ep.item_id, ei.montant |
eb41eda9 FB |
260 | FROM group_event_participants AS ep |
261 | INNER JOIN group_event_items AS ei ON (ei.eid = ep.eid AND ei.item_id = ep.item_id) | |
07eb5b0e FB |
262 | WHERE ep.eid = {?} AND ep.uid = {?}', |
263 | $eid, $uid); | |
0337d704 | 264 | while ($i = $res_->next()) { |
265 | $u[$i['item_id']] = $i['nb']; | |
f9e8637a | 266 | $u['montant'] += $i['montant'] * $i['nb']; |
0337d704 | 267 | } |
e01ebe65 FB |
268 | $evt['telepaid'] += $u['telepayment']; |
269 | $evt['adminpaid'] += $u['adminpaid']; | |
270 | $evt['paid'] += $u['paid']; | |
271 | $evt['topay'] += $u['montant']; | |
0337d704 | 272 | } |
273 | return $tab; | |
274 | } | |
275 | // }}} | |
276 | ||
c860774b NI |
277 | // {{{ function subscribe() |
278 | /** set or update the user's subscription | |
279 | * | |
280 | * @param $uid: user's id | |
281 | * @param $eid: event's id | |
282 | * @param $subs: user's new subscription | |
283 | * | |
284 | */ | |
285 | function subscribe($uid, $eid, $subs = array()) | |
286 | { | |
287 | global $globals; | |
288 | // get items | |
289 | $items = get_event_items($eid); | |
290 | // get previous subscription | |
291 | $old_subs = get_event_subscription($eid, $uid); | |
292 | $participate = false; | |
293 | $updated = false; | |
294 | // TODO : change the way to deal with manual payment | |
295 | $paid = 0; | |
296 | foreach ($old_subs as $item_id => $s) { | |
297 | $paid += $s['paid']; | |
298 | } | |
299 | $paid_updated = false; | |
300 | // for each item of the event | |
301 | foreach ($items as $item_id => $details) { | |
302 | // check if there is an old subscription | |
303 | if (array_key_exists($item_id, $old_subs)) { | |
c860774b NI |
304 | // compares new and old subscription |
305 | if ($old_subs[$item_id]['nb'] != $subs[$item_id]) { | |
c860774b NI |
306 | if ($subs[$item_id] != 0) { |
307 | echo "je m'inscris "; | |
308 | XDB::execute('INSERT INTO group_event_participants (eid, uid, item_id, nb, flags, paid) | |
309 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}) | |
310 | ON DUPLICATE KEY UPDATE nb = VALUES(nb), flags = VALUES(flags), paid = VALUES(paid)', | |
311 | $eid, $uid, $item_id, $subs[$item_id],(Env::has('notify_payment') ? 'notify_payment' : 0), (!$paid_updated ? $paid : 0)); | |
312 | $participate = true; | |
313 | $paid_updated = true; | |
314 | } else { // we do not store non-subscription to event items | |
c860774b NI |
315 | XDB::execute('DELETE FROM group_event_participants |
316 | WHERE eid = {?} AND uid = {?} AND item_id = {?}', | |
317 | $eid, $uid, $item_id); | |
318 | } | |
319 | $updated = true; | |
320 | } | |
321 | } else { // if no old subscription | |
c860774b | 322 | if ($subs[$item_id] != 0) { |
c860774b NI |
323 | XDB::execute('INSERT INTO group_event_participants (eid, uid, item_id, nb, flags, paid) |
324 | VALUES ({?}, {?}, {?}, {?}, {?}, {?})', | |
325 | $eid, $uid, $item_id, $subs[$item_id], '', 0); | |
326 | $participate = true; | |
327 | $updated = true; | |
328 | } | |
329 | } | |
330 | } | |
331 | // item 0 stores whether the user participates globally or not, if he has to be notified when payment is created and his manual payment | |
332 | /* | |
333 | if (array_key_exists(0, $old_subs)) { | |
334 | XDB::execute('UPDATE group_event_participants | |
335 | SET nb = {?} | |
336 | WHERE eid = {?}, uid = {?}, item_id = 0', | |
337 | ($participate ? 1 : 0), $eid, $uid); | |
338 | } else { | |
339 | XDB::execute('INSERT INTO group_event_participants (eid, uid, item_id, nb, flags, paid) | |
340 | VALUES ({?}, {?}, {?}, {?}, {?}, {?})', | |
341 | $eid, $uid, 0, ($participate ? 1 : 0), (Env::has('notify_payment') ? 'notify_payment' : ''), 0); | |
342 | } | |
343 | */ | |
344 | // if subscription is updated, we have to update the event aliases | |
345 | if ($updated) { | |
c860774b NI |
346 | $short_name = get_event_detail($eid)['short_name']; |
347 | subscribe_lists_event($uid, $short_name, ($participate ? 1 : -1), 0); | |
348 | } | |
349 | return $updated; | |
350 | } | |
351 | // }}} | |
352 | ||
353 | // TODO : correct this function to be compatible with subscribe() (use $eid, remove useless argument) | |
354 | // TODO : correct other calls | |
0337d704 | 355 | // {{{ function subscribe_lists_event() |
50208d22 SJ |
356 | /** Subscribes user to various event related mailing lists. |
357 | * | |
358 | * @param $uid: user's id. | |
7852229b | 359 | * @param short_name: event's short_name, which corresponds to the beginning of the emails. |
50208d22 SJ |
360 | * @param participate: indicates if the user takes part at the event or not; |
361 | * -1 means he did not answer, 0 means no, and 1 means yes. | |
362 | * @param paid: has the user already payed anything? | |
363 | * 0 means no, a positive amount means yes. | |
364 | * @param payment: is this function called from a payment page? | |
365 | * If true, only payment related lists should be updated. | |
366 | */ | |
7852229b | 367 | function subscribe_lists_event($uid, $short_name, $participate, $paid, $payment = false) |
9193e8f7 | 368 | { |
7852229b SJ |
369 | global $globals; |
370 | require_once 'emails.inc.php'; | |
0337d704 | 371 | |
7852229b SJ |
372 | if (is_null($short_name)) { |
373 | return; | |
0337d704 | 374 | } |
375 | ||
50208d22 SJ |
376 | /** If $payment is not null, we do not retrieve the value of $participate, |
377 | * thus we do not alter participant and absent lists. | |
378 | */ | |
379 | if ($payment === true) { | |
380 | if ($paid > 0) { | |
7e82b545 SJ |
381 | delete_from_list_alias($uid, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event'); |
382 | add_to_list_alias($uid, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event'); | |
50208d22 SJ |
383 | } |
384 | } else { | |
385 | switch ($participate) { | |
386 | case -1: | |
7e82b545 SJ |
387 | delete_from_list_alias($uid, $short_name . $globals->xnet->participant_list, $globals->xnet->evts_domain, 'event'); |
388 | delete_from_list_alias($uid, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event'); | |
389 | delete_from_list_alias($uid, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event'); | |
390 | add_to_list_alias($uid, $short_name . $globals->xnet->absent_list, $globals->xnet->evts_domain, 'event'); | |
50208d22 SJ |
391 | break; |
392 | case 0: | |
7e82b545 SJ |
393 | delete_from_list_alias($uid, $short_name . $globals->xnet->participant_list, $globals->xnet->evts_domain, 'event'); |
394 | delete_from_list_alias($uid, $short_name . $globals->xnet->absent_list, $globals->xnet->evts_domain, 'event'); | |
395 | delete_from_list_alias($uid, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event'); | |
396 | delete_from_list_alias($uid, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event'); | |
50208d22 SJ |
397 | break; |
398 | case 1: | |
7e82b545 SJ |
399 | add_to_list_alias($uid, $short_name . $globals->xnet->participant_list, $globals->xnet->evts_domain, 'event'); |
400 | delete_from_list_alias($uid, $short_name . $globals->xnet->absent_list, $globals->xnet->evts_domain, 'event'); | |
50208d22 | 401 | if ($paid > 0) { |
7e82b545 SJ |
402 | delete_from_list_alias($uid, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event'); |
403 | add_to_list_alias($uid, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event'); | |
50208d22 | 404 | } else { |
7e82b545 SJ |
405 | add_to_list_alias($uid, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event'); |
406 | delete_from_list_alias($uid, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event'); | |
50208d22 SJ |
407 | } |
408 | break; | |
1cf7d38b | 409 | } |
9193e8f7 | 410 | } |
0337d704 | 411 | } |
412 | // }}} | |
413 | ||
20c5c7e6 | 414 | // {{{ function event_change_shortname() |
26ba053e | 415 | function event_change_shortname($page, $eid, $old, $new) |
5070a22d | 416 | { |
417 | global $globals; | |
7852229b | 418 | require_once 'emails.inc.php'; |
5070a22d | 419 | |
f56e5e53 | 420 | if (is_null($old)) { |
421 | $old = ''; | |
422 | } | |
a7de4ef7 | 423 | // Quelques vérifications sur l'alias (caractères spéciaux) |
2179ffa2 | 424 | if ($new && !preg_match( "/^[a-zA-Z0-9\-.]{3,20}$/", $new)) { |
a7d35093 | 425 | $page->trigError("Le raccourci demandé n'est pas valide. |
a7de4ef7 | 426 | Vérifie qu'il comporte entre 3 et 20 caractères |
427 | et qu'il ne contient que des lettres non accentuées, | |
428 | des chiffres ou les caractères - et ."); | |
5070a22d | 429 | return $old; |
4aae4d2c | 430 | } elseif ($new && (is_int($new) || ctype_digit($new))) { |
940ae3a0 SJ |
431 | $page->trigError("Le raccourci demandé ne peut être accepté car il |
432 | ne contient que des chiffres. Rajoute-lui par exemple | |
433 | une lettre."); | |
434 | return $old; | |
5070a22d | 435 | } |
436 | ||
a7de4ef7 | 437 | //vérifier que l'alias n'est pas déja pris |
5070a22d | 438 | if ($new && $old != $new) { |
9193e8f7 | 439 | $res = XDB::query('SELECT COUNT(*) |
eb41eda9 | 440 | FROM group_events |
9193e8f7 | 441 | WHERE short_name = {?}', |
442 | $new); | |
5070a22d | 443 | if ($res->fetchOneCell() > 0) { |
a7d35093 | 444 | $page->trigError("Le raccourci demandé est déjà utilisé. Choisis en un autre."); |
5070a22d | 445 | return $old; |
446 | } | |
447 | } | |
448 | ||
449 | if ($old == $new) { | |
450 | return $new; | |
451 | } | |
452 | ||
453 | if ($old && $new) { | |
454 | // if had a previous shortname change the old lists | |
7852229b SJ |
455 | foreach (explode(',', $globals->xnet->event_lists) as $suffix) { |
456 | XDB::execute('UPDATE email_virtual | |
457 | SET email = {?} | |
458 | WHERE type = \'event\' AND email = {?}', | |
459 | $new . $suffix, $old . $suffix); | |
5070a22d | 460 | } |
7852229b | 461 | |
5070a22d | 462 | return $new; |
463 | } | |
464 | ||
465 | if (!$old && $new) { | |
466 | // if we have a first new short_name create the lists | |
9ff5b337 SJ |
467 | $lastid = array(); |
468 | $where = array( | |
2335f07e SJ |
469 | $globals->xnet->participant_list => 'g.nb > 0', |
470 | $globals->xnet->payed_list => '(g.paid > 0 OR p.amount > 0)', | |
471 | $globals->xnet->unpayed_list => 'g.nb > 0 AND g.paid = 0 AND p.amount IS NULL' | |
9ff5b337 SJ |
472 | ); |
473 | ||
7852229b | 474 | foreach (array($globals->xnet->participant_list, $globals->xnet->payed_list, $globals->xnet->unpayed_list) as $suffix) { |
2335f07e SJ |
475 | $uids = XDB::fetchColumn('SELECT g.uid |
476 | FROM group_event_participants AS g | |
477 | INNER JOIN group_events AS e ON (g.eid = e.eid) | |
478 | LEFT JOIN payment_transactions AS p ON (e.paiement_id = p.ref AND g.uid = p.uid) | |
479 | WHERE g.eid = {?} AND ' . $where[$suffix], | |
7852229b | 480 | $eid); |
7e82b545 SJ |
481 | foreach ($uids as $uid) { |
482 | add_to_list_alias($uid, $new . $suffix, $globals->xnet->evts_domain, 'event'); | |
7852229b | 483 | } |
9ff5b337 | 484 | } |
2335f07e | 485 | |
7852229b SJ |
486 | $uids = XDB::fetchColumn('SELECT m.uid |
487 | FROM group_members AS m | |
488 | LEFT JOIN group_event_participants AS e ON (e.uid = m.uid AND e.eid = {?}) | |
489 | WHERE m.asso_id = {?} AND e.uid IS NULL', | |
490 | $eid, $globals->asso('id')); | |
7e82b545 SJ |
491 | foreach ($uids as $uid) { |
492 | add_to_list_alias($uid, $new . $globals->xnet->absent_list, $globals->xnet->evts_domain, 'event'); | |
9ff5b337 | 493 | } |
5070a22d | 494 | |
495 | return $new; | |
496 | } | |
497 | ||
498 | if ($old && !$new) { | |
499 | // if we delete the old short name, delete the lists | |
7852229b SJ |
500 | foreach (explode(',', $globals->xnet->event_lists) as $suffix) { |
501 | delete_list_alias($old . $suffix, $globals->xnet->evts_domain); | |
5070a22d | 502 | } |
7852229b | 503 | |
5070a22d | 504 | return $new; |
505 | } | |
506 | ||
507 | // cannot happen | |
508 | return $old; | |
509 | } | |
20c5c7e6 SJ |
510 | // }}} |
511 | ||
512 | // {{{ function make_event_date() | |
c860774b | 513 | function make_event_date($debut, $fin) |
20c5c7e6 | 514 | { |
c860774b NI |
515 | $start = strtotime($debut); |
516 | $end = strtotime($fin); | |
517 | // $first_day = $e['first_day']; | |
518 | // $last_day = $e['last_day']; | |
519 | $first_day = strftime("%d %B %Y", $start); | |
520 | $last_day = strftime("%d %B %Y", $end); | |
20c5c7e6 SJ |
521 | $date = ""; |
522 | if ($start && $end != $start) { | |
523 | if ($first_day == $last_day) { | |
524 | $date .= "le " . strftime("%d %B %Y", $start) . " de " | |
525 | . strftime("%H:%M", $start) . " à " . strftime("%H:%M", $end); | |
526 | } else { | |
527 | $date .= "du " . strftime("%d %B %Y à %H:%M", $start) | |
528 | . "\nau " . strftime("%d %B %Y à %H:%M", $end); | |
529 | } | |
530 | } else { | |
531 | $date .= "le " . strftime("%d %B %Y à %H:%M", $start); | |
532 | } | |
c860774b | 533 | return $date; |
20c5c7e6 SJ |
534 | } |
535 | // }}} | |
5070a22d | 536 | |
448c8cdc | 537 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: |
0337d704 | 538 | ?> |