| 1 | <?php |
| 2 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: |
| 3 | /*************************************************************************** |
| 4 | * Copyright (C) 2003-2006 Polytechnique.org * |
| 5 | * http://opensource.polytechnique.org/ * |
| 6 | * * |
| 7 | * This program is free software; you can redistribute it and/or modify * |
| 8 | * it under the terms of the GNU General Public License as published by * |
| 9 | * the Free Software Foundation; either version 2 of the License, or * |
| 10 | * (at your option) any later version. * |
| 11 | * * |
| 12 | * This program is distributed in the hope that it will be useful, * |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 15 | * GNU General Public License for more details. * |
| 16 | * * |
| 17 | * You should have received a copy of the GNU General Public License * |
| 18 | * along with this program; if not, write to the Free Software * |
| 19 | * Foundation, Inc., * |
| 20 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
| 21 | ***************************************************************************/ |
| 22 | |
| 23 | require 'xnet.inc.php'; |
| 24 | |
| 25 | new_group_page('xnet/groupe/evt-modif.tpl'); |
| 26 | |
| 27 | $page->assign('logged', logged()); |
| 28 | $page->assign('admin', may_update()); |
| 29 | |
| 30 | $moments = range(1, 4); |
| 31 | $page->assign('moments', $moments); |
| 32 | |
| 33 | $page->assign('eid', Env::get('eid')); |
| 34 | |
| 35 | if (!may_update()) |
| 36 | redirect("evenements.php"); |
| 37 | |
| 38 | if ($eid = Env::get('eid')) { |
| 39 | $res = $globals->xdb->query("SELECT asso_id, short_name FROM groupex.evenements WHERE eid = {?}", $eid); |
| 40 | $infos = $res->fetchOneAssoc(); |
| 41 | if ($infos['asso_id'] != $globals->asso('id')) { |
| 42 | unset($eid); |
| 43 | unset($infos); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | $get_form = true; |
| 48 | |
| 49 | if (Post::get('intitule')) { |
| 50 | $get_form = false; |
| 51 | $short_name = Env::get('short_name'); |
| 52 | //Quelques vérifications sur l'alias (caractères spéciaux) |
| 53 | if ($short_name && !preg_match( "/^[a-zA-Z0-9\-.]{3,20}$/", $short_name)) |
| 54 | { |
| 55 | $page->trig("Le raccourci demandé n'est pas valide. |
| 56 | Vérifie qu'il comporte entre 3 et 20 caractères |
| 57 | et qu'il ne contient que des lettres non accentuées, |
| 58 | des chiffres ou les caractères - et ."); |
| 59 | $short_name = $infos['short_name']; |
| 60 | $get_form = true; |
| 61 | } |
| 62 | //vérifier que l'alias n'est pas déja pris |
| 63 | if ($short_name && $short_name != $infos['short_name']) { |
| 64 | $res = $globals->xdb->query('SELECT COUNT(*) FROM virtual WHERE alias LIKE {?}', $short_name."-%"); |
| 65 | if ($res->fetchOneCell() > 0) { |
| 66 | $page->trig("Le raccourci demandé est déjà utilisé. Choisis en un autre."); |
| 67 | $short_name = $infos['short_name']; |
| 68 | $get_form = true; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // if had a previous shortname change the old lists |
| 73 | if ($short_name && $infos['short_name'] && $short_name != $infos['short_name']) { |
| 74 | $globals->xdb->execute("UPDATE virtual SET alias = REPLACE(alias, {?}, {?}) WHERE type = 'evt' AND alias LIKE {?}", |
| 75 | $infos['short_name'], $short_name, $infos['short_name']."-%"); |
| 76 | } |
| 77 | // if we have a first new short_name create the lists |
| 78 | elseif ($short_name && !$infos['short_name']) |
| 79 | { |
| 80 | $globals->xdb->execute("INSERT INTO virtual SET type = 'evt', alias = {?}", |
| 81 | $short_name."-participants@".$globals->xnet->evts_domain); |
| 82 | |
| 83 | $res = $globals->xdb->query("SELECT LAST_INSERT_ID()"); |
| 84 | $globals->xdb->execute("INSERT INTO virtual_redirect ( |
| 85 | SELECT {?} AS vid, IF(u.nom IS NULL, m.email, CONCAT(a.alias, {?})) AS redirect |
| 86 | FROM groupex.evenements_participants AS ep |
| 87 | LEFT JOIN groupex.membres AS m ON (ep.uid = m.uid) |
| 88 | LEFT JOIN auth_user_md5 AS u ON (u.user_id = ep.uid) |
| 89 | LEFT JOIN aliases AS a ON (a.id = ep.uid AND a.type = 'a_vie') |
| 90 | WHERE ep.eid = {?} |
| 91 | GROUP BY ep.uid)", |
| 92 | $res->fetchOneCell(), "@".$globals->mail->domain, $eid); |
| 93 | |
| 94 | $globals->xdb->execute("INSERT INTO virtual SET type = 'evt', alias = {?}", |
| 95 | $short_name."-absents@".$globals->xnet->evts_domain); |
| 96 | |
| 97 | $res = $globals->xdb->query("SELECT LAST_INSERT_ID()"); |
| 98 | $globals->xdb->execute("INSERT INTO virtual_redirect ( |
| 99 | SELECT {?} AS vid, IF(u.nom IS NULL, m.email, CONCAT(a.alias, {?})) AS redirect |
| 100 | FROM groupex.membres AS m |
| 101 | LEFT JOIN groupex.evenements_participants AS ep ON (ep.uid = m.uid) |
| 102 | LEFT JOIN auth_user_md5 AS u ON (u.user_id = m.uid) |
| 103 | LEFT JOIN aliases AS a ON (a.id = m.uid AND a.type = 'a_vie') |
| 104 | WHERE m.asso_id = {?} AND ep.uid IS NULL |
| 105 | GROUP BY m.uid)", |
| 106 | $res->fetchOneCell(), "@".$globals->mail->domain, $globals->asso('id')); |
| 107 | } |
| 108 | // if we delete the old short name, delete the lists |
| 109 | elseif (!$short_name && $infos['short_name']) { |
| 110 | $globals->xdb->execute("DELETE virtual, virtual_redirect FROM virtual LEFT JOIN virtual_redirect USING(vid) WHERE virtual.alias LIKE {?}", |
| 111 | $infos['short_name']."-%"); |
| 112 | } |
| 113 | |
| 114 | $evt = array(); |
| 115 | $evt['eid'] = $eid; |
| 116 | $evt['asso_id'] = $globals->asso('id'); |
| 117 | $evt['organisateur_uid'] = Session::get('uid'); |
| 118 | $evt['intitule'] = Post::get('intitule'); |
| 119 | $evt['paiement_id'] =(Post::get('paiement_id')>0)?Post::get('paiement_id'):null; |
| 120 | $evt['descriptif'] =Post::get('descriptif'); |
| 121 | $evt['debut'] = Post::get('deb_Year')."-".Post::get('deb_Month')."-".Post::get('deb_Day')." ".Post::get('deb_Hour').":".Post::get('deb_Minute').":00"; |
| 122 | $evt['fin'] = Post::get('fin_Year')."-".Post::get('fin_Month')."-".Post::get('fin_Day')." ".Post::get('fin_Hour').":".Post::get('fin_Minute').":00"; |
| 123 | $evt['membres_only'] = Post::get('membres_only'); |
| 124 | $evt['advertise'] = Post::get('advertise'); |
| 125 | $evt['show_participants'] = Post::get('show_participants'); |
| 126 | $evt['noinvite'] = Post::get('noinvite'); |
| 127 | if (!$short_name) $short_name = ''; |
| 128 | $evt['short_name'] = $short_name; |
| 129 | $evt['deadline_inscription'] = (Post::get('deadline', 'off')=='on')?null:(Post::get('inscr_Year')."-".Post::get('inscr_Month')."-".Post::get('inscr_Day')); |
| 130 | |
| 131 | // Store the modifications in the database |
| 132 | $globals->xdb->execute("REPLACE INTO groupex.evenements |
| 133 | SET eid={?}, asso_id={?}, organisateur_uid={?}, intitule={?}, |
| 134 | paiement_id = {?}, descriptif = {?}, |
| 135 | debut = {?}, fin = {?}, |
| 136 | membres_only = {?}, advertise = {?}, show_participants = {?}, |
| 137 | short_name = {?}, deadline_inscription = {?}, noinvite = {?}", |
| 138 | $evt['eid'], $evt['asso_id'], $evt['organisateur_uid'], $evt['intitule'] |
| 139 | , $evt['paiement_id'], $evt['descriptif'], |
| 140 | $evt['debut'], $evt['fin'], |
| 141 | $evt['membres_only'], $evt['advertise'], $evt['show_participants'], |
| 142 | $evt['short_name'], $evt['deadline_inscription'], $evt['noinvite']); |
| 143 | |
| 144 | // if new event, get its id |
| 145 | if (!$eid) { |
| 146 | $res = $globals->xdb->query("SELECT LAST_INSERT_ID()"); |
| 147 | $eid = $res->fetchOneCell(); |
| 148 | $evt['eid'] = $eid; |
| 149 | } |
| 150 | |
| 151 | $nb_moments = 0; |
| 152 | $money_defaut = 0; |
| 153 | foreach ($moments as $i) |
| 154 | { |
| 155 | if (Post::get('titre'.$i)) { |
| 156 | $nb_moments++; |
| 157 | if (!($money_defaut > 0)) |
| 158 | $money_defaut = strtr(Post::get('montant'.$i), ',', '.'); |
| 159 | $globals->xdb->execute(" |
| 160 | REPLACE INTO groupex.evenements_items VALUES ( |
| 161 | {?}, {?}, |
| 162 | {?}, {?}, {?})", |
| 163 | $eid, $i, |
| 164 | Post::get('titre'.$i), Post::get('details'.$i), strtr(Post::get('montant'.$i), ',', '.')); |
| 165 | } |
| 166 | else |
| 167 | { |
| 168 | $globals->xdb->execute("DELETE FROM groupex.evenements_items WHERE eid = {?} AND item_id = {?}", $eid, $i); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | // request for a new payment |
| 173 | if (Post::get('paiement_id') == -1 && $money_defaut >= 0) { |
| 174 | require_once ('validations.inc.php'); |
| 175 | $p = new PayReq( |
| 176 | Session::get('uid'), |
| 177 | Post::get('intitule')." - ".$globals->asso('nom'), |
| 178 | Post::get('site'), |
| 179 | $money_defaut, |
| 180 | Post::get('confirmation'), |
| 181 | 0, |
| 182 | 999, |
| 183 | $globals->asso('id'), |
| 184 | $eid); |
| 185 | $p->submit(); |
| 186 | } |
| 187 | |
| 188 | // events with no sub-event: add a sub-event with no name |
| 189 | if ($nb_moments == 0) |
| 190 | $globals->xdb->execute("INSERT INTO groupex.evenements_items VALUES ({?}, {?}, '', '', 0)", $eid, 1); |
| 191 | } |
| 192 | |
| 193 | if (Env::has('sup') && $eid) { |
| 194 | // deletes the event |
| 195 | $globals->xdb->execute("DELETE FROM groupex.evenements WHERE eid = {?} AND asso_id = {?}", $eid, $globals->asso('id')); |
| 196 | // deletes the event items |
| 197 | $globals->xdb->execute("DELETE FROM groupex.evenements_items WHERE eid = {?}", $eid); |
| 198 | // deletes the event participants |
| 199 | $globals->xdb->execute("DELETE FROM groupex.evenements_participants WHERE eid = {?}", $eid); |
| 200 | // deletes the event mailing aliases |
| 201 | if ($infos['short_name']) |
| 202 | $globals->xdb->execute("DELETE FROM virtual WHERE type = 'evt' AND alias LIKE {?}", $infos['short_name']."-%"); |
| 203 | // delete the requests for payments |
| 204 | require_once('validations.inc.php'); |
| 205 | $globals->xdb->execute("DELETE FROM requests WHERE type = 'paiements' AND data LIKE {?}", PayReq::same_event($eid, $globals->asso('id'))); |
| 206 | redirect("evenements.php"); |
| 207 | } |
| 208 | |
| 209 | if (!$get_form) |
| 210 | redirect("evenements.php"); |
| 211 | |
| 212 | // get a list of all the payment for this asso |
| 213 | $res = $globals->xdb->iterator |
| 214 | ("SELECT id, text FROM {$globals->money->mpay_tprefix}paiements WHERE asso_id = {?}", $globals->asso('id')); |
| 215 | $paiements = array(); |
| 216 | while ($a = $res->next()) $paiements[$a['id']] = $a['text']; |
| 217 | $page->assign('paiements', $paiements); |
| 218 | |
| 219 | // when modifying an old event retreive the old datas |
| 220 | if ($eid) { |
| 221 | $res = $globals->xdb->query( |
| 222 | "SELECT eid, intitule, descriptif, debut, fin, membres_only, advertise, show_participants, paiement_id, short_name, deadline_inscription, noinvite |
| 223 | FROM groupex.evenements |
| 224 | WHERE eid = {?}", $eid); |
| 225 | $evt = $res->fetchOneAssoc(); |
| 226 | // find out if there is already a request for a payment for this event |
| 227 | require_once('validations.inc.php'); |
| 228 | $res = $globals->xdb->query("SELECT stamp FROM requests WHERE type = 'paiements' AND data LIKE {?}", PayReq::same_event($eid, $globals->asso('id'))); |
| 229 | $stamp = $res->fetchOneCell(); |
| 230 | if ($stamp) { |
| 231 | $evt['paiement_id'] = -2; |
| 232 | $evt['paiement_req'] = $stamp; |
| 233 | } |
| 234 | $page->assign('evt', $evt); |
| 235 | // get all the different moments infos |
| 236 | $res = $globals->xdb->iterator( |
| 237 | "SELECT item_id, titre, details, montant |
| 238 | FROM groupex.evenements_items AS ei |
| 239 | INNER JOIN groupex.evenements AS e ON(e.eid = ei.eid) |
| 240 | WHERE e.eid = {?} |
| 241 | ORDER BY item_id", $eid); |
| 242 | $items = array(); |
| 243 | while ($item = $res->next()) $items[$item['item_id']] = $item; |
| 244 | $page->assign('items', $items); |
| 245 | } |
| 246 | |
| 247 | $page->run(); |
| 248 | |
| 249 | ?> |