Example #1
0
 public function submit()
 {
     if ($this->evt) {
         XDB::execute('DELETE FROM requests WHERE type={?} AND data LIKE {?}', 'paiements', PayReq::same_event($this->evt, $this->asso_id));
     }
     parent::submit();
 }
Example #2
0
 function handler_edit($page, $eid = null)
 {
     global $globals;
     // get eid if the the given one is a short name
     if (!is_null($eid) && !is_numeric($eid)) {
         $res = XDB::query("SELECT eid\n                                 FROM group_events\n                                WHERE asso_id = {?} AND short_name = {?}", $globals->asso('id'), $eid);
         if ($res->numRows()) {
             $eid = (int) $res->fetchOneCell();
         }
     }
     // check the event is in our group
     if (!is_null($eid)) {
         $res = XDB::query("SELECT short_name\n                                 FROM group_events\n                                WHERE eid = {?} AND asso_id = {?}", $eid, $globals->asso('id'));
         if ($res->numRows()) {
             $infos = $res->fetchOneAssoc();
         } else {
             return PL_FORBIDDEN;
         }
     }
     $page->changeTpl('xnetevents/edit.tpl');
     $moments = range(1, 4);
     $error = false;
     $page->assign('moments', $moments);
     if (Post::v('intitule')) {
         S::assert_xsrf_token();
         $this->load('xnetevents.inc.php');
         $short_name = event_change_shortname($page, $eid, $infos['short_name'], Env::v('short_name', ''));
         if ($short_name != Env::v('short_name')) {
             $error = true;
         }
         $evt = array('eid' => $eid, 'asso_id' => $globals->asso('id'), 'paiement_id' => Post::v('paiement_id') > 0 ? Post::v('paiement_id') : null, 'debut' => Post::v('deb_Year') . '-' . Post::v('deb_Month') . '-' . Post::v('deb_Day') . ' ' . Post::v('deb_Hour') . ':' . Post::v('deb_Minute') . ':00', 'fin' => Post::v('fin_Year') . '-' . Post::v('fin_Month') . '-' . Post::v('fin_Day') . ' ' . Post::v('fin_Hour') . ':' . Post::v('fin_Minute') . ':00', 'short_name' => $short_name);
         $trivial = array('intitule', 'descriptif', 'noinvite', 'subscription_notification', 'show_participants', 'accept_nonmembre', 'uid');
         foreach ($trivial as $k) {
             $evt[$k] = Post::v($k);
         }
         if (!$eid) {
             $evt['uid'] = S::v('uid');
         }
         if (Post::v('deadline')) {
             $evt['deadline_inscription'] = Post::v('inscr_Year') . '-' . Post::v('inscr_Month') . '-' . Post::v('inscr_Day');
         } else {
             $evt['deadline_inscription'] = null;
         }
         // Store the modifications in the database
         XDB::execute('INSERT INTO  group_events (eid, asso_id, uid, intitule, paiement_id,
                                                  descriptif, debut, fin, show_participants,
                                                  short_name, deadline_inscription, noinvite,
                                                  accept_nonmembre, subscription_notification)
                            VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})
           ON DUPLICATE KEY UPDATE  asso_id = VALUES(asso_id), uid = VALUES(uid), intitule = VALUES(intitule),
                                    paiement_id = VALUES(paiement_id), descriptif = VALUES(descriptif), debut = VALUES(debut),
                                    fin = VALUES(fin), show_participants = VALUES(show_participants), short_name = VALUES(short_name),
                                    deadline_inscription = VALUES(deadline_inscription), noinvite = VALUES(noinvite),
                                    accept_nonmembre = VALUES(accept_nonmembre), subscription_notification = VALUES(subscription_notification)', $evt['eid'], $evt['asso_id'], $evt['uid'], $evt['intitule'], $evt['paiement_id'], $evt['descriptif'], $evt['debut'], $evt['fin'], $evt['show_participants'], $evt['short_name'], $evt['deadline_inscription'], $evt['noinvite'], $evt['accept_nonmembre'], $evt['subscription_notification']);
         // if new event, get its id
         if (!$eid) {
             $eid = XDB::insertId();
         }
         foreach ($moments as $i) {
             if (Post::v('titre' . $i)) {
                 $nb_moments++;
                 $montant = strtr(Post::v('montant' . $i), ',', '.');
                 $money_defaut += (double) $montant;
                 XDB::execute('INSERT INTO  group_event_items (eid, item_id, titre, details, montant)
                                    VALUES  ({?}, {?}, {?}, {?}, {?})
                   ON DUPLICATE KEY UPDATE  titre = VALUES(titre), details = VALUES(details), montant = VALUES(montant)', $eid, $i, Post::v('titre' . $i), Post::v('details' . $i), $montant);
             } else {
                 XDB::execute('DELETE FROM  group_event_items
                                     WHERE  eid = {?} AND item_id = {?}', $eid, $i);
             }
         }
         // request for a new payment
         if (Post::v('paiement_id') == -1 && $money_defaut >= 0) {
             $p = new PayReq(S::user(), $globals->asso('nom') . " - " . Post::v('intitule'), Post::v('site'), $money_defaut, Post::v('confirmation'), 0, 999, $globals->asso('id'), $eid, Post::v('payment_public') == 'yes');
             if ($p->accept()) {
                 $p->submit();
             } else {
                 $page->assign('payment_message', Post::v('confirmation'));
                 $page->assign('payment_site', Post::v('site'));
                 $page->assign('payment_public', Post::v('payment_public') == 'yes');
                 $page->assign('error', true);
                 $error = true;
             }
         }
         // events with no sub-event: add a sub-event with default name
         if ($nb_moments == 0) {
             XDB::execute("INSERT INTO group_event_items\n                                   VALUES ({?}, {?}, 'Événement', '', 0)", $eid, 1);
         }
         if (!$error) {
             pl_redirect('events');
         }
     }
     // get a list of all the payment for this asso
     $res = XDB::iterator("SELECT  id, text\n                                FROM  payments\n                               WHERE  asso_id = {?} AND NOT FIND_IN_SET('old', flags)", $globals->asso('id'));
     $paiements = array();
     while ($a = $res->next()) {
         $paiements[$a['id']] = $a['text'];
     }
     $page->assign('paiements', $paiements);
     // when modifying an old event retreive the old datas
     if ($eid) {
         $res = XDB::query("SELECT  eid, intitule, descriptif, debut, fin, uid,\n                             show_participants, paiement_id, short_name,\n                             deadline_inscription, noinvite, accept_nonmembre, subscription_notification\n                       FROM  group_events\n                      WHERE eid = {?}", $eid);
         $evt = $res->fetchOneAssoc();
         // find out if there is already a request for a payment for this event
         $res = XDB::query("SELECT  stamp\n                                 FROM  requests\n                                WHERE  type = 'paiements' AND data LIKE {?}", PayReq::same_event($eid, $globals->asso('id')));
         $stamp = $res->fetchOneCell();
         if ($stamp) {
             $evt['paiement_id'] = -2;
             $evt['paiement_req'] = $stamp;
         }
         $page->assign('evt', $evt);
         // get all the different moments infos
         $res = XDB::iterator("SELECT  item_id, titre, details, montant\n                       FROM  group_event_items AS ei\n                 INNER JOIN  group_events AS e ON(e.eid = ei.eid)\n                      WHERE  e.eid = {?}\n                   ORDER BY item_id", $eid);
         $items = array();
         while ($item = $res->next()) {
             $items[$item['item_id']] = $item;
         }
         $page->assign('items', $items);
     }
     $page->assign('url_ref', $eid);
 }