bug 399, refuser les invites aux evenements xnet
[platal.git] / htdocs.net / groupe / evenements.php
index cbf1ad3..1e07f7d 100644 (file)
@@ -32,6 +32,7 @@ if (Env::has('ins')) {
         $res = $globals->xdb->query("
             SELECT  deadline_inscription,
                     LEFT(NOW(), 10) AS now,
+                    noinvite,
                     membres_only
             FROM    groupex.evenements
             WHERE   eid = {?}", $eid);
@@ -52,18 +53,21 @@ if (Env::has('ins')) {
         // impossible to unsubscribe if you already paid sthing
         $total_inscr = 0;
         $inscriptions = array();
-        for ($i=1; Env::has('moment'.$eid.'_'.$i); $i++)
+        for ($j=1; Env::has('moment'.$eid.'_'.$j); $j++)
         {
-            $inscriptions[$i] = Env::get('moment'.$eid.'_'.$i);
+            $inscriptions[$j] = Env::get('moment'.$eid.'_'.$j);
             // retreive ohter field when more than one person
-            if ($inscriptions[$i] == 2)
-                $inscriptions[$i] = 1 + Env::get('personnes'.$eid.'_'.$i,0);
+            if ($inscriptions[$j] == 2)
+                $inscriptions[$j] = 1 + Env::get('personnes'.$eid.'_'.$j,0);
             // avoid negative count if other field incorrect
-            if ($inscriptions[$i] < 0)
-                $inscriptions[$i] = 0;
+            if ($inscriptions[$j] < 0)
+                $inscriptions[$j] = 0;
             // avoid floating count if other field incorrect
-            $inscriptions[$i] = floor($inscriptions[$i]);
-            $total_inscr += $inscriptions[$i];
+            $inscriptions[$j] = floor($inscriptions[$j]);
+            // avoid invite if no invite allowed
+            if ($inscriptions[$j] > 1 && $e['noinvite'])
+                $inscriptions[$j] = 1;
+            $total_inscr += $inscriptions[$j];
         }
         $unsubscribing = ($total_inscr == 0);
 
@@ -84,21 +88,21 @@ if (Env::has('ins')) {
         }
 
         // update actual inscriptions
-        foreach ($inscriptions as $i=>$nb)
+        foreach ($inscriptions as $j=>$nb)
         {
             if ($nb > 0)
             {
                $globals->xdb->execute(
                    "REPLACE INTO  groupex.evenements_participants
                           VALUES  ({?}, {?}, {?}, {?}, {?})",
-                   $eid, Session::get("uid"), $i, $nb, $paid);
+                   $eid, Session::get("uid"), $j, $nb, $paid);
             }
             else
             {
                $globals->xdb->execute(
                    "DELETE FROM  groupex.evenements_participants
                           WHERE  eid = {?} AND uid = {?} AND item_id = {?}",
-                   $eid, Session::get("uid"), $i);             
+                   $eid, Session::get("uid"), $j);             
             }
         }
     }
@@ -109,12 +113,15 @@ $page->assign('logged', logged());
 $page->assign('admin', may_update());
 
 $evenements = $globals->xdb->iterator(
-"SELECT  e.eid, e.intitule, e.descriptif,
+"SELECT  e.eid, 
+         IF(e.intitule = '', ' ', e.intitule) AS intitule,
+         IF(e.descriptif = '', ' ', e.descriptif) AS descriptif,
         e.debut, e.fin,
         LEFT(10,e.debut) AS debut_day,
         LEFT(10,e.fin) AS fin_day,
-         e.paiement_id, e.membres_only,
+         e.paiement_id, e.membres_only, e.noinvite,
         e.show_participants, u.nom, u.prenom, u.promo, a.alias, MAX(ep.nb) AS inscrit,
+         MAX(ep.paid) AS paid,
         e.short_name,
          IF(e.deadline_inscription,e.deadline_inscription >= LEFT(NOW(), 10), 1) AS inscr_open, e.deadline_inscription
       FROM  groupex.evenements AS e
@@ -134,7 +141,15 @@ while ($e = $evenements->next())
       LEFT JOIN groupex.evenements_participants AS ep ON (ep.eid = ei.eid AND ep.item_id = ei.item_id AND uid = {?})
           WHERE ei.eid = {?}",
             Session::get('uid'), $e['eid']);
-    $e['paid'] = 0;
+    $query = $globals->xdb->query(
+        "SELECT montant
+           FROM {$globals->money->mpay_tprefix}transactions AS t
+         WHERE ref = {?} AND uid = {?}", $e['paiement_id'], Session::get('uid'));
+    $montants = $query->fetchColumn();
+    foreach ($montants as $m) {
+        $p = strtr(substr($m, 0, strpos($m, "EUR")), ",", ".");
+        $e['paid'] += trim($p);
+    }
     $evts[] = $e;
 }