| 1 | <?php |
| 2 | require 'xnet.inc.php'; |
| 3 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: |
| 4 | /*************************************************************************** |
| 5 | * Copyright (C) 2003-2004 Polytechnique.org * |
| 6 | * http://opensource.polytechnique.org/ * |
| 7 | * * |
| 8 | * This program is free software; you can redistribute it and/or modify * |
| 9 | * it under the terms of the GNU General Public License as published by * |
| 10 | * the Free Software Foundation; either version 2 of the License, or * |
| 11 | * (at your option) any later version. * |
| 12 | * * |
| 13 | * This program is distributed in the hope that it will be useful, * |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 16 | * GNU General Public License for more details. * |
| 17 | * * |
| 18 | * You should have received a copy of the GNU General Public License * |
| 19 | * along with this program; if not, write to the Free Software * |
| 20 | * Foundation, Inc., * |
| 21 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
| 22 | ***************************************************************************/ |
| 23 | |
| 24 | new_group_page('xnet/groupe/evenements.tpl'); |
| 25 | |
| 26 | /**** manage inscriptions ****/ |
| 27 | // inscription to events |
| 28 | if (Env::has('ins')) { |
| 29 | for ($i=1; Env::has('evt_'.$i); $i++) |
| 30 | { |
| 31 | $eid = Env::get('evt_'.$i); |
| 32 | $res = $globals->xdb->query(" |
| 33 | SELECT deadline_inscription, |
| 34 | LEFT(NOW(), 10) AS now, |
| 35 | membres_only |
| 36 | FROM groupex.evenements |
| 37 | WHERE eid = {?}", $eid); |
| 38 | $e = $res->fetchOneAssoc(); |
| 39 | // impossible to change inscription: either inscription closed or members only |
| 40 | if ($e['deadline_inscription'] && $e['deadline_inscription']<$e['now']) |
| 41 | { |
| 42 | $page->trig("Les inscriptions sont closes"); |
| 43 | continue; |
| 44 | } |
| 45 | |
| 46 | if ($e['membres_only'] && !is_member()) |
| 47 | { |
| 48 | $page->trig("Les inscriptions à cet événement ne sont pas publiques"); |
| 49 | continue; |
| 50 | } |
| 51 | |
| 52 | // impossible to unsubscribe if you already paid sthing |
| 53 | $total_inscr = 0; |
| 54 | $inscriptions = array(); |
| 55 | for ($i=1; Env::has('moment'.$eid.'_'.$i); $i++) |
| 56 | { |
| 57 | $inscriptions[$i] = Env::get('moment'.$eid.'_'.$i); |
| 58 | // retreive ohter field when more than one person |
| 59 | if ($inscriptions[$i] == 2) |
| 60 | $inscriptions[$i] = 1 + Env::get('personnes'.$eid.'_'.$i,0); |
| 61 | // avoid negative count if other field incorrect |
| 62 | if ($inscriptions[$i] < 0) |
| 63 | $inscriptions[$i] = 0; |
| 64 | // avoid floating count if other field incorrect |
| 65 | $inscriptions[$i] = floor($inscriptions[$i]); |
| 66 | $total_inscr += $inscriptions[$i]; |
| 67 | } |
| 68 | $unsubscribing = ($total_inscr == 0); |
| 69 | |
| 70 | // retreive the amount already paid for this event in cash |
| 71 | $res = $globals->xdb->query(" |
| 72 | SELECT paid |
| 73 | FROM groupex.evenements_participants |
| 74 | WHERE eid = {?} AND uid = {?} |
| 75 | LIMIT 1", |
| 76 | $eid, Session::get("uid")); |
| 77 | $paid = $res->fetchOneCell(); |
| 78 | if (!$paid) $paid = 0; |
| 79 | |
| 80 | if ($unsubscribing && $paid != 0) |
| 81 | { |
| 82 | $page->trig("Impossible de te désinscrire complètement parce que tu as fait un paiement par chèque ou par liquide. Contacte un administrateur du groupe si tu es sûr de ne pas venir"); |
| 83 | continue; |
| 84 | } |
| 85 | |
| 86 | // update actual inscriptions |
| 87 | foreach ($inscriptions as $i=>$nb) |
| 88 | { |
| 89 | if ($nb > 0) |
| 90 | { |
| 91 | $globals->xdb->execute( |
| 92 | "REPLACE INTO groupex.evenements_participants |
| 93 | VALUES ({?}, {?}, {?}, {?}, {?})", |
| 94 | $eid, Session::get("uid"), $i, $nb, $paid); |
| 95 | } |
| 96 | else |
| 97 | { |
| 98 | $globals->xdb->execute( |
| 99 | "DELETE FROM groupex.evenements_participants |
| 100 | WHERE eid = {?} AND uid = {?} AND item_id = {?}", |
| 101 | $eid, Session::get("uid"), $i); |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | /**** retreive all infos about all events ****/ |
| 108 | $page->assign('logged', logged()); |
| 109 | $page->assign('admin', may_update()); |
| 110 | |
| 111 | $evenements = $globals->xdb->iterator( |
| 112 | "SELECT e.eid, e.intitule, e.descriptif, |
| 113 | e.debut, e.fin, |
| 114 | LEFT(10,e.debut) AS debut_day, |
| 115 | LEFT(10,e.fin) AS fin_day, |
| 116 | e.paiement_id, e.membres_only, |
| 117 | e.show_participants, u.nom, u.prenom, u.promo, a.alias, MAX(ep.nb) AS inscrit, |
| 118 | e.short_name, |
| 119 | IF(e.deadline_inscription,e.deadline_inscription >= LEFT(NOW(), 10), 1) AS inscr_open, e.deadline_inscription |
| 120 | FROM groupex.evenements AS e |
| 121 | INNER JOIN x4dat.auth_user_md5 AS u ON u.user_id = e.organisateur_uid |
| 122 | LEFT JOIN x4dat.aliases AS a ON (a.type = 'a_vie' AND a.id = u.user_id) |
| 123 | LEFT JOIN groupex.evenements_participants AS ep ON (ep.eid = e.eid AND ep.uid = {?}) |
| 124 | WHERE asso_id = {?} |
| 125 | GROUP BY e.eid |
| 126 | ORDER BY debut",Session::get('uid'),$globals->asso('id')); |
| 127 | |
| 128 | $evts = array(); |
| 129 | while ($e = $evenements->next()) |
| 130 | { |
| 131 | $e['moments'] = $globals->xdb->iterator( |
| 132 | "SELECT titre, details, montant, ei.item_id, nb |
| 133 | FROM groupex.evenements_items AS ei |
| 134 | LEFT JOIN groupex.evenements_participants AS ep ON (ep.eid = ei.eid AND ep.item_id = ei.item_id AND uid = {?}) |
| 135 | WHERE ei.eid = {?}", |
| 136 | Session::get('uid'), $e['eid']); |
| 137 | $e['paid'] = 0; |
| 138 | $evts[] = $e; |
| 139 | } |
| 140 | |
| 141 | $page->assign('evenements', $evts); |
| 142 | $page->assign('is_member', is_member()); |
| 143 | |
| 144 | $page->assign('nb_evt', $evenements->total()); |
| 145 | |
| 146 | $page->run(); |
| 147 | |
| 148 | ?> |