| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2014 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_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) |
| 40 | * @param $archive: whether to get the archived events (1) or the actuals (0) |
| 41 | */ |
| 42 | function get_events($asso_id, $order, $archive) |
| 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 |
| 49 | WHERE asso_id = {?} and archive = {?} |
| 50 | ORDER BY ge.debut $order", |
| 51 | $asso_id, $archive); |
| 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 | } |
| 71 | $evt['organizer'] = User::getSilent($evt['uid'])->profile(); |
| 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 | |
| 130 | // {{{ function get_event_detail() |
| 131 | |
| 132 | function get_event_detail($eid, $item_id = false, $asso_id = null) |
| 133 | { |
| 134 | global $globals; |
| 135 | if (is_null($asso_id)) { |
| 136 | $asso_id = $globals->asso('id'); |
| 137 | } |
| 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 | } |
| 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, |
| 146 | IF(e.deadline_inscription, |
| 147 | e.deadline_inscription >= LEFT(NOW(), 10), |
| 148 | 1) AS inscr_open, |
| 149 | LEFT(e.debut, 10) AS first_day, LEFT(e.fin, 10) AS last_day, |
| 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) |
| 155 | WHERE (e.eid = {?} OR e.short_name = {?}) AND e.asso_id = {?}' . $where . ' |
| 156 | GROUP BY ' . $group_by, |
| 157 | $eid, $eid, $asso_id); |
| 158 | |
| 159 | if (!$evt) { |
| 160 | return null; |
| 161 | } |
| 162 | if ($GLOBALS['IS_XNET_SITE'] && $evt['accept_nonmembre'] == 0 && !is_member() && !may_update()) { |
| 163 | return false; |
| 164 | } |
| 165 | |
| 166 | if (!$item_id) { |
| 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']; |
| 173 | $evt['titre'] = ''; |
| 174 | $evt['item_id'] = 0; |
| 175 | $evt['csv_name'] = urlencode($evt['intitule']); |
| 176 | } else { |
| 177 | $evt['csv_name'] = urlencode($evt['intitule'] . '.' . $evt['titre']); |
| 178 | } |
| 179 | |
| 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 |
| 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 |
| 184 | AND uid = {?}) |
| 185 | WHERE ei.eid = {?}', |
| 186 | S::i('uid'), $evt['eid']); |
| 187 | $evt['topay'] = 0; |
| 188 | $evt['paid'] = 0; |
| 189 | $evt['notify_payment'] = false; |
| 190 | foreach ($evt['moments'] as $m) { |
| 191 | $evt['topay'] += $m['nb'] * $m['montant']; |
| 192 | if ($m['montant']) { |
| 193 | $evt['money'] = true; |
| 194 | } |
| 195 | $evt['paid'] += $m['paid']; |
| 196 | $evt['notify_payment'] = $evt['notify_payment'] || $m['notify_payment']; |
| 197 | } |
| 198 | |
| 199 | $montant = XDB::fetchOneCell('SELECT SUM(amount) AS sum_amount |
| 200 | FROM payment_transactions AS t |
| 201 | WHERE ref = {?} AND uid = {?}', |
| 202 | $evt['paiement_id'], S::v('uid')); |
| 203 | $evt['telepaid'] = $montant; |
| 204 | $evt['paid'] += $montant; |
| 205 | $evt['organizer'] = User::getSilent($evt['uid']); |
| 206 | |
| 207 | $evt['date'] = make_event_date($evt['debut'], $evt['fin']); |
| 208 | |
| 209 | $evt['show_participants'] = ($evt['show_participants'] && $GLOBALS['IS_XNET_SITE'] && (is_member() || may_update())); |
| 210 | |
| 211 | return $evt; |
| 212 | } |
| 213 | |
| 214 | // }}} |
| 215 | |
| 216 | // {{{ function get_event_participants() |
| 217 | function get_event_participants(&$evt, $item_id, array $tri = array(), $limit = null, $offset = 0) |
| 218 | { |
| 219 | global $globals; |
| 220 | |
| 221 | $eid = $evt['eid']; |
| 222 | $money = $evt['money'] && (function_exists('may_update')) && may_update(); |
| 223 | $pay_id = $evt['paiement_id']; |
| 224 | |
| 225 | $append = $item_id ? XDB::format(' AND ep.item_id = {?}', $item_id) : ''; |
| 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 |
| 228 | FROM group_event_participants AS ep |
| 229 | WHERE ep.eid = {?} AND nb > 0 ' . $append . ' |
| 230 | GROUP BY ep.uid', $eid); |
| 231 | $uf = new UserFilter(new PFC_True(), $tri); |
| 232 | $users = User::getBulkUsersWithUIDs($uf->filter(array_keys($query), new PlLimit($limit, $offset))); |
| 233 | $tab = array(); |
| 234 | foreach ($users as $user) { |
| 235 | $uid = $user->id(); |
| 236 | $tab[$uid] = $query[$uid]; |
| 237 | $tab[$uid]['user'] = $user; |
| 238 | } |
| 239 | |
| 240 | if ($item_id) { |
| 241 | return $tab; |
| 242 | } |
| 243 | |
| 244 | $evt['adminpaid'] = 0; |
| 245 | $evt['telepaid'] = 0; |
| 246 | $evt['topay'] = 0; |
| 247 | $evt['paid'] = 0; |
| 248 | foreach ($tab as $uid=>&$u) { |
| 249 | $u['adminpaid'] = (float)$u['paid']; |
| 250 | $u['montant'] = 0; |
| 251 | if ($money && $pay_id) { |
| 252 | $montant = XDB::fetchOneCell('SELECT SUM(amount) |
| 253 | FROM payment_transactions AS t |
| 254 | WHERE ref = {?} AND uid = {?}', |
| 255 | $pay_id, $uid); |
| 256 | $u['paid'] += $montant; |
| 257 | } |
| 258 | $u['telepayment'] = $u['paid'] - $u['adminpaid']; |
| 259 | $res_ = XDB::iterator('SELECT ep.nb, ep.item_id, ei.montant |
| 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) |
| 262 | WHERE ep.eid = {?} AND ep.uid = {?}', |
| 263 | $eid, $uid); |
| 264 | while ($i = $res_->next()) { |
| 265 | $u[$i['item_id']] = $i['nb']; |
| 266 | $u['montant'] += $i['montant'] * $i['nb']; |
| 267 | } |
| 268 | $evt['telepaid'] += $u['telepayment']; |
| 269 | $evt['adminpaid'] += $u['adminpaid']; |
| 270 | $evt['paid'] += $u['paid']; |
| 271 | $evt['topay'] += $u['montant']; |
| 272 | } |
| 273 | return $tab; |
| 274 | } |
| 275 | // }}} |
| 276 | |
| 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)) { |
| 304 | echo 'prev exists '; |
| 305 | // compares new and old subscription |
| 306 | if ($old_subs[$item_id]['nb'] != $subs[$item_id]) { |
| 307 | echo 'different '; |
| 308 | if ($subs[$item_id] != 0) { |
| 309 | echo "je m'inscris "; |
| 310 | XDB::execute('INSERT INTO group_event_participants (eid, uid, item_id, nb, flags, paid) |
| 311 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}) |
| 312 | ON DUPLICATE KEY UPDATE nb = VALUES(nb), flags = VALUES(flags), paid = VALUES(paid)', |
| 313 | $eid, $uid, $item_id, $subs[$item_id],(Env::has('notify_payment') ? 'notify_payment' : 0), (!$paid_updated ? $paid : 0)); |
| 314 | $participate = true; |
| 315 | $paid_updated = true; |
| 316 | } else { // we do not store non-subscription to event items |
| 317 | echo "je me desinscris "; |
| 318 | XDB::execute('DELETE FROM group_event_participants |
| 319 | WHERE eid = {?} AND uid = {?} AND item_id = {?}', |
| 320 | $eid, $uid, $item_id); |
| 321 | } |
| 322 | $updated = true; |
| 323 | } |
| 324 | } else { // if no old subscription |
| 325 | echo 'no prev '; |
| 326 | if ($subs[$item_id] != 0) { |
| 327 | echo 'subscribe '; |
| 328 | XDB::execute('INSERT INTO group_event_participants (eid, uid, item_id, nb, flags, paid) |
| 329 | VALUES ({?}, {?}, {?}, {?}, {?}, {?})', |
| 330 | $eid, $uid, $item_id, $subs[$item_id], '', 0); |
| 331 | $participate = true; |
| 332 | $updated = true; |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | // item 0 stores whether the user participates globally or not, if he has to be notified when payment is created and his manual payment |
| 337 | /* |
| 338 | if (array_key_exists(0, $old_subs)) { |
| 339 | XDB::execute('UPDATE group_event_participants |
| 340 | SET nb = {?} |
| 341 | WHERE eid = {?}, uid = {?}, item_id = 0', |
| 342 | ($participate ? 1 : 0), $eid, $uid); |
| 343 | } else { |
| 344 | XDB::execute('INSERT INTO group_event_participants (eid, uid, item_id, nb, flags, paid) |
| 345 | VALUES ({?}, {?}, {?}, {?}, {?}, {?})', |
| 346 | $eid, $uid, 0, ($participate ? 1 : 0), (Env::has('notify_payment') ? 'notify_payment' : ''), 0); |
| 347 | } |
| 348 | */ |
| 349 | // if subscription is updated, we have to update the event aliases |
| 350 | if ($updated) { |
| 351 | echo "inscription mise a jour "; |
| 352 | $short_name = get_event_detail($eid)['short_name']; |
| 353 | subscribe_lists_event($uid, $short_name, ($participate ? 1 : -1), 0); |
| 354 | } |
| 355 | return $updated; |
| 356 | } |
| 357 | // }}} |
| 358 | |
| 359 | // TODO : correct this function to be compatible with subscribe() (use $eid, remove useless argument) |
| 360 | // TODO : correct other calls |
| 361 | // {{{ function subscribe_lists_event() |
| 362 | /** Subscribes user to various event related mailing lists. |
| 363 | * |
| 364 | * @param $uid: user's id. |
| 365 | * @param short_name: event's short_name, which corresponds to the beginning of the emails. |
| 366 | * @param participate: indicates if the user takes part at the event or not; |
| 367 | * -1 means he did not answer, 0 means no, and 1 means yes. |
| 368 | * @param paid: has the user already payed anything? |
| 369 | * 0 means no, a positive amount means yes. |
| 370 | * @param payment: is this function called from a payment page? |
| 371 | * If true, only payment related lists should be updated. |
| 372 | */ |
| 373 | function subscribe_lists_event($uid, $short_name, $participate, $paid, $payment = false) |
| 374 | { |
| 375 | global $globals; |
| 376 | require_once 'emails.inc.php'; |
| 377 | |
| 378 | if (is_null($short_name)) { |
| 379 | return; |
| 380 | } |
| 381 | |
| 382 | /** If $payment is not null, we do not retrieve the value of $participate, |
| 383 | * thus we do not alter participant and absent lists. |
| 384 | */ |
| 385 | if ($payment === true) { |
| 386 | if ($paid > 0) { |
| 387 | delete_from_list_alias($uid, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event'); |
| 388 | add_to_list_alias($uid, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event'); |
| 389 | } |
| 390 | } else { |
| 391 | switch ($participate) { |
| 392 | case -1: |
| 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->unpayed_list, $globals->xnet->evts_domain, 'event'); |
| 395 | delete_from_list_alias($uid, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event'); |
| 396 | add_to_list_alias($uid, $short_name . $globals->xnet->absent_list, $globals->xnet->evts_domain, 'event'); |
| 397 | break; |
| 398 | case 0: |
| 399 | delete_from_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'); |
| 401 | delete_from_list_alias($uid, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event'); |
| 402 | delete_from_list_alias($uid, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event'); |
| 403 | break; |
| 404 | case 1: |
| 405 | add_to_list_alias($uid, $short_name . $globals->xnet->participant_list, $globals->xnet->evts_domain, 'event'); |
| 406 | delete_from_list_alias($uid, $short_name . $globals->xnet->absent_list, $globals->xnet->evts_domain, 'event'); |
| 407 | if ($paid > 0) { |
| 408 | delete_from_list_alias($uid, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event'); |
| 409 | add_to_list_alias($uid, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event'); |
| 410 | } else { |
| 411 | add_to_list_alias($uid, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event'); |
| 412 | delete_from_list_alias($uid, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event'); |
| 413 | } |
| 414 | break; |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | // }}} |
| 419 | |
| 420 | // {{{ function event_change_shortname() |
| 421 | function event_change_shortname($page, $eid, $old, $new) |
| 422 | { |
| 423 | global $globals; |
| 424 | require_once 'emails.inc.php'; |
| 425 | |
| 426 | if (is_null($old)) { |
| 427 | $old = ''; |
| 428 | } |
| 429 | // Quelques vérifications sur l'alias (caractères spéciaux) |
| 430 | if ($new && !preg_match( "/^[a-zA-Z0-9\-.]{3,20}$/", $new)) { |
| 431 | $page->trigError("Le raccourci demandé n'est pas valide. |
| 432 | Vérifie qu'il comporte entre 3 et 20 caractères |
| 433 | et qu'il ne contient que des lettres non accentuées, |
| 434 | des chiffres ou les caractères - et ."); |
| 435 | return $old; |
| 436 | } elseif ($new && (is_int($new) || ctype_digit($new))) { |
| 437 | $page->trigError("Le raccourci demandé ne peut être accepté car il |
| 438 | ne contient que des chiffres. Rajoute-lui par exemple |
| 439 | une lettre."); |
| 440 | return $old; |
| 441 | } |
| 442 | |
| 443 | //vérifier que l'alias n'est pas déja pris |
| 444 | if ($new && $old != $new) { |
| 445 | $res = XDB::query('SELECT COUNT(*) |
| 446 | FROM group_events |
| 447 | WHERE short_name = {?}', |
| 448 | $new); |
| 449 | if ($res->fetchOneCell() > 0) { |
| 450 | $page->trigError("Le raccourci demandé est déjà utilisé. Choisis en un autre."); |
| 451 | return $old; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | if ($old == $new) { |
| 456 | return $new; |
| 457 | } |
| 458 | |
| 459 | if ($old && $new) { |
| 460 | // if had a previous shortname change the old lists |
| 461 | foreach (explode(',', $globals->xnet->event_lists) as $suffix) { |
| 462 | XDB::execute('UPDATE email_virtual |
| 463 | SET email = {?} |
| 464 | WHERE type = \'event\' AND email = {?}', |
| 465 | $new . $suffix, $old . $suffix); |
| 466 | } |
| 467 | |
| 468 | return $new; |
| 469 | } |
| 470 | |
| 471 | if (!$old && $new) { |
| 472 | // if we have a first new short_name create the lists |
| 473 | $lastid = array(); |
| 474 | $where = array( |
| 475 | $globals->xnet->participant_list => 'g.nb > 0', |
| 476 | $globals->xnet->payed_list => '(g.paid > 0 OR p.amount > 0)', |
| 477 | $globals->xnet->unpayed_list => 'g.nb > 0 AND g.paid = 0 AND p.amount IS NULL' |
| 478 | ); |
| 479 | |
| 480 | foreach (array($globals->xnet->participant_list, $globals->xnet->payed_list, $globals->xnet->unpayed_list) as $suffix) { |
| 481 | $uids = XDB::fetchColumn('SELECT g.uid |
| 482 | FROM group_event_participants AS g |
| 483 | INNER JOIN group_events AS e ON (g.eid = e.eid) |
| 484 | LEFT JOIN payment_transactions AS p ON (e.paiement_id = p.ref AND g.uid = p.uid) |
| 485 | WHERE g.eid = {?} AND ' . $where[$suffix], |
| 486 | $eid); |
| 487 | foreach ($uids as $uid) { |
| 488 | add_to_list_alias($uid, $new . $suffix, $globals->xnet->evts_domain, 'event'); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | $uids = XDB::fetchColumn('SELECT m.uid |
| 493 | FROM group_members AS m |
| 494 | LEFT JOIN group_event_participants AS e ON (e.uid = m.uid AND e.eid = {?}) |
| 495 | WHERE m.asso_id = {?} AND e.uid IS NULL', |
| 496 | $eid, $globals->asso('id')); |
| 497 | foreach ($uids as $uid) { |
| 498 | add_to_list_alias($uid, $new . $globals->xnet->absent_list, $globals->xnet->evts_domain, 'event'); |
| 499 | } |
| 500 | |
| 501 | return $new; |
| 502 | } |
| 503 | |
| 504 | if ($old && !$new) { |
| 505 | // if we delete the old short name, delete the lists |
| 506 | foreach (explode(',', $globals->xnet->event_lists) as $suffix) { |
| 507 | delete_list_alias($old . $suffix, $globals->xnet->evts_domain); |
| 508 | } |
| 509 | |
| 510 | return $new; |
| 511 | } |
| 512 | |
| 513 | // cannot happen |
| 514 | return $old; |
| 515 | } |
| 516 | // }}} |
| 517 | |
| 518 | // {{{ function make_event_date() |
| 519 | function make_event_date($debut, $fin) |
| 520 | { |
| 521 | $start = strtotime($debut); |
| 522 | $end = strtotime($fin); |
| 523 | // $first_day = $e['first_day']; |
| 524 | // $last_day = $e['last_day']; |
| 525 | $first_day = strftime("%d %B %Y", $start); |
| 526 | $last_day = strftime("%d %B %Y", $end); |
| 527 | $date = ""; |
| 528 | if ($start && $end != $start) { |
| 529 | if ($first_day == $last_day) { |
| 530 | $date .= "le " . strftime("%d %B %Y", $start) . " de " |
| 531 | . strftime("%H:%M", $start) . " à " . strftime("%H:%M", $end); |
| 532 | } else { |
| 533 | $date .= "du " . strftime("%d %B %Y à %H:%M", $start) |
| 534 | . "\nau " . strftime("%d %B %Y à %H:%M", $end); |
| 535 | } |
| 536 | } else { |
| 537 | $date .= "le " . strftime("%d %B %Y à %H:%M", $start); |
| 538 | } |
| 539 | return $date; |
| 540 | } |
| 541 | // }}} |
| 542 | |
| 543 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: |
| 544 | ?> |