Merge branch 'platal-0.9.17'
[platal.git] / modules / xnetevents.php
index 93474a6..a879db9 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2007 Polytechnique.org                              *
+ *  Copyright (C) 2003-2008 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -58,6 +58,7 @@ class XnetEventsModule extends PLModule
             if (!may_update()) {
                 return PL_FORBIDDEN;
             }
+            S::assert_xsrf_token();
 
             $res = XDB::query("SELECT asso_id, short_name FROM groupex.evenements
                                 WHERE eid = {?} AND asso_id = {?}",
@@ -97,7 +98,7 @@ class XnetEventsModule extends PLModule
             XDB::execute("DELETE FROM requests
                                     WHERE type = 'paiements' AND data LIKE {?}",
                                    PayReq::same_event($eid, $globals->asso('id')));
-            update_NbValid();
+            $globals->updateNbValid();
         }
 
         if ($action == 'archive') {
@@ -127,13 +128,18 @@ class XnetEventsModule extends PLModule
              LEFT JOIN  groupex.evenements_participants AS ep ON (ep.eid = e.eid AND ep.uid = {?})
                  WHERE  asso_id = {?}
                    AND  archive = " . ($archive ? "1 " : "0 ")
-            . (is_member() || may_update() ? "" : " AND accept_nonmembre != 0 ")
               . "GROUP BY  e.eid
                  ORDER BY  inscr_open DESC, debut DESC", S::v('uid'), $globals->asso('id'));
 
         $evts = array();
+        $undisplayed_events = 0;
 
         while ($e = $evenements->next()) {
+            if (!is_member() && !may_update() && !$e['accept_nonmembre']) {
+                $undisplayed_events ++;
+                continue;
+            }
+
             $e['show_participants'] = ($e['show_participants'] && (is_member() || may_update()));
             $res = XDB::query(
                 "SELECT titre, details, montant, ei.item_id, nb, ep.paid
@@ -168,17 +174,27 @@ class XnetEventsModule extends PLModule
         }
 
         $page->assign('evenements', $evts);
+        $page->assign('undisplayed_events', $undisplayed_events);
     }
 
     function handler_sub(&$page, $eid = null)
     {
-        require_once dirname(__FILE__).'/xnetevents/xnetevents.inc.php';
+        $this->load('xnetevents.inc.php');
         $page->changeTpl('xnetevents/subscribe.tpl');
 
         $evt = get_event_detail($eid);
-        if (!$evt) {
+        if (is_null($evt)) {
             return PL_NOT_FOUND;
         }
+        if ($evt === false) {
+            global $globals, $platal;
+            $url = $globals->asso('sub_url');
+            if (empty($url)) {
+                $url = $platal->ns . 'subscribe';
+            }
+            $page->kill('Cet événement est reservé aux membres du groupe ' . $globals->asso('nom') .
+                        '. Pour devenir membre, rends-toi sur la page de <a href="' . $url . '">demande d\'inscripton</a>.');
+        }
 
         if (!$evt['inscr_open']) {
             $page->kill('Les inscriptions pour cet événement sont closes');
@@ -196,6 +212,8 @@ class XnetEventsModule extends PLModule
 
         if (!Post::has('submit')) {
             return;
+        } else {
+            S::assert_xsrf_token();
         }
 
         $moments = Post::v('moment',    array());
@@ -210,7 +228,7 @@ class XnetEventsModule extends PLModule
                 if (!isset($pers[$j]) || !is_numeric($pers[$j])
                 ||  $pers[$j] < 0)
                 {
-                    $page->trig('Tu dois choisir un nombre d\'invités correct !');
+                    $page->trigError('Tu dois choisir un nombre d\'invités correct !');
                     return;
                 }
                 $subs[$j] = 1 + $pers[$j];
@@ -219,11 +237,11 @@ class XnetEventsModule extends PLModule
 
         // impossible to unsubscribe if you already paid sthing
         if (!array_sum($subs) && $evt['paid'] != 0) {
-            $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");
+            $page->trigError("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");
             return;
         }
 
@@ -244,7 +262,7 @@ class XnetEventsModule extends PLModule
                 XDB::execute(
                     "DELETE FROM  groupex.evenements_participants
                            WHERE  eid = {?} AND uid = {?} AND item_id = {?}",
-                    $eid, S::v("uid"), $j);            
+                    $eid, S::v("uid"), $j);
                 $updated = $eid;
             }
             $total += $nb;
@@ -257,7 +275,7 @@ class XnetEventsModule extends PLModule
 
     function handler_csv(&$page, $eid = null, $item_id = null)
     {
-        require_once dirname(__FILE__).'/xnetevents/xnetevents.inc.php';
+        $this->load('xnetevents.inc.php');
 
         if (!is_numeric($item_id)) {
             $item_id = null;
@@ -292,7 +310,7 @@ class XnetEventsModule extends PLModule
     {
         global $globals;
 
-        require_once dirname(__FILE__).'/xnetevents/xnetevents.inc.php';
+        $this->load('xnetevents.inc.php');
         $evt = get_event_detail($eid);
         if (!$evt) {
             return PL_FORBIDDEN;
@@ -355,8 +373,11 @@ class XnetEventsModule extends PLModule
         $page->assign('moments', $moments);
 
         if (Post::v('intitule')) {
-            require_once dirname(__FILE__).'/xnetevents/xnetevents.inc.php';
-            $short_name = event_change_shortname($page, $infos['short_name'],
+            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;
@@ -505,7 +526,7 @@ class XnetEventsModule extends PLModule
     {
         global $globals;
 
-        require_once dirname(__FILE__).'/xnetevents/xnetevents.inc.php';
+        $this->load('xnetevents.inc.php');
 
         $evt = get_event_detail($eid, $item_id);
         if (!$evt) {
@@ -518,9 +539,11 @@ class XnetEventsModule extends PLModule
         }
 
         if (may_update() && Post::v('adm')) {
+            S::assert_xsrf_token();
+
             $member = get_infos(Post::v('mail'));
             if (!$member) {
-                $page->trig("Membre introuvable");
+                $page->trigError("Membre introuvable");
             }
 
             // change the price paid by a participant
@@ -556,7 +579,7 @@ class XnetEventsModule extends PLModule
                                  GROUP BY uid",
                                             $member['uid'], $evt['eid']);
                 $u = $res->fetchOneAssoc();
-                $u = $u['cnt'] ? null : $u['nb'];
+                $u = $u['cnt'] ? $u['nb'] : null;
                 subscribe_lists_event($u, $member['uid'], $evt);
             }