2 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
3 /***************************************************************************
4 * Copyright (C) 2003-2004 Polytechnique.org *
5 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
21 ***************************************************************************/
23 require 'xnet.inc.php';
25 new_group_page('xnet/groupe/evt-modif.tpl');
27 $page->assign('logged', logged());
28 $page->assign('admin', may_update());
30 $moments = range(1, 4);
31 $page->assign('moments', $moments);
33 $page->assign('eid', Env
::get('eid'));
36 redirect("evenements.php");
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')) {
49 if (Post
::get('intitule')) {
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))
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'];
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'];
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']."-%");
77 // if we have a first new short_name create the lists
78 elseif ($short_name && !$infos['short_name'])
80 $globals->xdb
->execute("INSERT INTO virtual SET type = 'evt', alias = {?}",
81 $short_name."-participants@".$globals->xnet
->evts_domain
);
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')
92 $res->fetchOneCell(), "@".$globals->mail
->domain
, $eid);
94 $globals->xdb
->execute("INSERT INTO virtual SET type = 'evt', alias = {?}",
95 $short_name."-absents@".$globals->xnet
->evts_domain
);
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
106 $res->fetchOneCell(), "@".$globals->mail
->domain
, $globals->asso('id'));
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']."-%");
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['short_name'] = $short_name;
127 $evt['deadline_inscription'] = (Post
::get('deadline', 'off')=='on')?null
:(Post
::get('inscr_Year')."-".Post
::get('inscr_Month')."-".Post
::get('inscr_Day'));
129 // Store the modifications in the database
130 $globals->xdb
->execute("REPLACE INTO groupex.evenements
131 SET eid={?}, asso_id={?}, organisateur_uid={?}, intitule={?},
132 paiement_id = {?}, descriptif = {?},
133 debut = {?}, fin = {?},
134 membres_only = {?}, advertise = {?}, show_participants = {?},
135 short_name = {?}, deadline_inscription = {?}",
136 $evt['eid'], $evt['asso_id'], $evt['organisateur_uid'], $evt['intitule']
137 , $evt['paiement_id'], $evt['descriptif'],
138 $evt['debut'], $evt['fin'],
139 $evt['membres_only'], $evt['advertise'], $evt['show_participants'],
140 $evt['short_name'], $evt['deadline_inscription']);
142 // if new event, get its id
144 $res = $globals->xdb
->query("SELECT LAST_INSERT_ID()");
145 $eid = $res->fetchOneCell();
151 foreach ($moments as $i)
153 if (Post
::get('titre'.$i)) {
155 if (!($money_defaut > 0))
156 $money_defaut = strtr(Post
::get('montant'.$i), ',', '.');
157 $globals->xdb
->execute("
158 REPLACE INTO groupex.evenements_items VALUES (
162 Post
::get('titre'.$i), Post
::get('details'.$i), strtr(Post
::get('montant'.$i), ',', '.'));
166 $globals->xdb
->execute("DELETE FROM groupex.evenements_items WHERE eid = {?} AND item_id = {?}", $eid, $i);
170 // request for a new payment
171 if (Post
::get('paiement_id') == -1 && $money_defaut >= 0) {
172 require_once ('validations.inc.php');
175 Post
::get('intitule')." - ".$globals->asso('nom'),
178 Post
::get('confirmation'),
181 $globals->asso('id'),
186 // events with no sub-event: add a sub-event with no name
187 if ($nb_moments == 0)
188 $globals->xdb
->execute("INSERT INTO groupex.evenements_items VALUES ({?}, {?}, '', '', 0)", $eid, 1);
191 if (Env
::has('sup') && $eid) {
193 $globals->xdb
->execute("DELETE FROM groupex.evenements WHERE eid = {?} AND asso_id = {?}", $eid, $globals->asso('id'));
194 // deletes the event items
195 $globals->xdb
->execute("DELETE FROM groupex.evenements_items WHERE eid = {?}", $eid);
196 // deletes the event participants
197 $globals->xdb
->execute("DELETE FROM groupex.evenements_participants WHERE eid = {?}", $eid);
198 // deletes the event mailing aliases
199 if ($infos['short_name'])
200 $globals->xdb
->execute("DELETE FROM virtual WHERE type = 'evt' AND alias LIKE {?}", $infos['short_name']."-%");
201 // delete the requests for payments
202 require_once('validations.inc.php');
203 $globals->xdb
->execute("DELETE FROM requests WHERE type = 'paiements' AND data LIKE {?}", PayReq
::same_event($eid, $globals->asso('id')));
207 redirect("evenements.php");
209 // get a list of all the payment for this asso
210 $res = $globals->xdb
->iterator
211 ("SELECT id, text FROM {$globals->money->mpay_tprefix}paiements WHERE asso_id = {?}", $globals->asso('id'));
212 $paiements = array();
213 while ($a = $res->next()) $paiements[$a['id']] = $a['text'];
214 $page->assign('paiements', $paiements);
216 // when modifying an old event retreive the old datas
218 $res = $globals->xdb
->query(
219 "SELECT eid, intitule, descriptif, debut, fin, membres_only, advertise, show_participants, paiement_id, short_name, deadline_inscription
220 FROM groupex.evenements
221 WHERE eid = {?}", $eid);
222 $evt = $res->fetchOneAssoc();
223 // find out if there is already a request for a payment for this event
224 require_once('validations.inc.php');
225 $res = $globals->xdb
->query("SELECT stamp FROM requests WHERE type = 'paiements' AND data LIKE {?}", PayReq
::same_event($eid, $globals->asso('id')));
226 $stamp = $res->fetchOneCell();
228 $evt['paiement_id'] = -2;
229 $evt['paiement_req'] = $stamp;
231 $page->assign('evt', $evt);
232 // get all the different moments infos
233 $res = $globals->xdb
->iterator(
234 "SELECT item_id, titre, details, montant
235 FROM groupex.evenements_items AS ei
236 INNER JOIN groupex.evenements AS e ON(e.eid = ei.eid)
238 ORDER BY item_id", $eid);
240 while ($item = $res->next()) $items[$item['item_id']] = $item;
241 $page->assign('items', $items);