Simplifies blacklist verification (Closes #992).
[platal.git] / modules / xnetevents.php
index a879db9..de2fe0d 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2008 Polytechnique.org                              *
+ *  Copyright (C) 2003-2009 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -73,31 +73,31 @@ class XnetEventsModule extends PLModule
         if ($action == 'del') {
             // deletes the event mailing aliases
             if ($tmp[1]) {
-                XDB::execute(
-                    "DELETE FROM virtual WHERE type = 'evt' AND alias LIKE {?}",
-                    $tmp[1].'-absents@%');
-                XDB::execute(
-                    "DELETE FROM virtual WHERE type = 'evt' AND alias LIKE {?}",
-                    $tmp[1].'-participants@%');
+                foreach (array('-absents@', '-participants@', '-paye@', '-participants-non-paye@') as $v) {
+                    XDB::execute("DELETE FROM  virtual
+                                        WHERE  type = 'evt' AND alias LIKE {?}",
+                                 $tmp[1] . $v . '%');
+                }
             }
 
             // deletes the event items
-            XDB::execute("DELETE FROM groupex.evenements_items WHERE eid = {?}", $eid);
+            XDB::execute('DELETE FROM  groupex.evenements_items
+                                WHERE  eid = {?}', $eid);
 
             // deletes the event participants
-            XDB::execute("DELETE FROM groupex.evenements_participants
-                                    WHERE eid = {?}", $eid);
+            XDB::execute('DELETE FROM  groupex.evenements_participants
+                                WHERE  eid = {?}', $eid);
 
             // deletes the event
-            XDB::execute("DELETE FROM groupex.evenements
-                                    WHERE eid = {?} AND asso_id = {?}",
-                                   $eid, $globals->asso('id'));
+            XDB::execute('DELETE FROM  groupex.evenements
+                                WHERE  eid = {?} AND asso_id = {?}',
+                         $eid, $globals->asso('id'));
 
             // delete the requests for payments
             require_once 'validations.inc.php';
-            XDB::execute("DELETE FROM requests
-                                    WHERE type = 'paiements' AND data LIKE {?}",
-                                   PayReq::same_event($eid, $globals->asso('id')));
+            XDB::execute("DELETE FROM  requests
+                                WHERE  type = 'paiements' AND data LIKE {?}",
+                         PayReq::same_event($eid, $globals->asso('id')));
             $globals->updateNbValid();
         }
 
@@ -117,7 +117,7 @@ class XnetEventsModule extends PLModule
 
         $page->assign('archive', $archive);
         $evenements = XDB::iterator(
-                "SELECT  e.*, LEFT(10, e.debut) AS debut_day, LEFT(10, e.fin) AS fin_day,
+                "SELECT  e.*, LEFT(10, e.debut) AS first_day, LEFT(10, e.fin) AS last_day,
                          IF(e.deadline_inscription, e.deadline_inscription >= LEFT(NOW(), 10),
                             1) AS inscr_open, e.deadline_inscription,
                          u.nom, u.prenom, u.promo, a.alias,
@@ -133,6 +133,7 @@ class XnetEventsModule extends PLModule
 
         $evts = array();
         $undisplayed_events = 0;
+        $this->load('xnetevents.inc.php');
 
         while ($e = $evenements->next()) {
             if (!is_member() && !may_update() && !$e['accept_nonmembre']) {
@@ -167,6 +168,8 @@ class XnetEventsModule extends PLModule
                 $e['paid'] += trim($p);
             }
 
+            make_event_date($e);
+
             if (Env::has('updated') && $e['eid'] == Env::i('updated')) {
                 $page->assign('updated', $e);
             }
@@ -228,7 +231,7 @@ class XnetEventsModule extends PLModule
                 if (!isset($pers[$j]) || !is_numeric($pers[$j])
                 ||  $pers[$j] < 0)
                 {
-                    $page->trigError('Tu dois choisir un nombre d\'invités correct !');
+                    $page->trigError("Tu dois choisir un nombre d'invités correct&nbsp;!");
                     return;
                 }
                 $subs[$j] = 1 + $pers[$j];
@@ -237,11 +240,11 @@ class XnetEventsModule extends PLModule
 
         // impossible to unsubscribe if you already paid sthing
         if (!array_sum($subs) && $evt['paid'] != 0) {
-            $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");
+            $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;
         }
 
@@ -268,7 +271,8 @@ class XnetEventsModule extends PLModule
             $total += $nb;
         }
         if ($updated !== false) {
-            subscribe_lists_event($total, S::i('uid'), $evt);
+            $page->trigSuccess('Ton inscription à l\'événement a été mise à jour avec succès.');
+            subscribe_lists_event($total, S::i('uid'), $evt, $paid);
         }
         $page->assign('event', get_event_detail($eid));
     }
@@ -452,7 +456,7 @@ class XnetEventsModule extends PLModule
             // request for a new payment
             if (Post::v('paiement_id') == -1 && $money_defaut >= 0) {
                 require_once 'validations.inc.php';
-                $p = new PayReq(S::v('uid'),
+                $p = new PayReq(S::user(),
                                 Post::v('intitule')." - ".$globals->asso('nom'),
                                 Post::v('site'), $money_defaut,
                                 Post::v('confirmation'), 0, 999,
@@ -580,7 +584,7 @@ class XnetEventsModule extends PLModule
                                             $member['uid'], $evt['eid']);
                 $u = $res->fetchOneAssoc();
                 $u = $u['cnt'] ? $u['nb'] : null;
-                subscribe_lists_event($u, $member['uid'], $evt);
+                subscribe_lists_event($u, $member['uid'], $evt, $paid);
             }
 
             $evt = get_event_detail($eid, $item_id);
@@ -611,7 +615,7 @@ class XnetEventsModule extends PLModule
         while (list($char, $nb) = $res->next()) {
             $alphabet[ord($char)] = $char;
             $nb_tot += $nb;
-            if (Env::has('initiale') && $char == strtoupper(Env::v('initiale'))) {
+            if (Env::has('initiale') && $char == mb_strtoupper(Env::v('initiale'))) {
                 $tot = $nb;
             }
         }
@@ -652,19 +656,19 @@ class XnetEventsModule extends PLModule
                                 ORDER BY  nom, prenom, promo", $evt['eid']);
 
         $ofs   = Env::i('offset');
-        $tot   = (Env::v('initiale') ? $tot : $nb_tot) - $absents->total();
-        $nbp   = intval(($tot-1)/NB_PER_PAGE);
-        $links = array();
-        if ($ofs) {
-            $links['précédent'] = $ofs-1;
-        }
-        for ($i = 0; $i <= $nbp; $i++) {
-            $links[(string)($i+1)] = $i;
-        }
-        if ($ofs < $nbp) {
-            $links['suivant'] = $ofs+1;
-        }
-        if (count($links)>1) {
+        $tot   = (Env::v('initiale') ? $tot : $nb_tot);
+        $nbp   = ceil($tot / NB_PER_PAGE);
+        if ($nbp > 1) {
+            $links = array();
+            if ($ofs) {
+                $links['précédent'] = $ofs - 1;
+            }
+            for ($i = 1 ; $i <= $nbp; $i++) {
+                $links[(string)$i] = $i - 1;
+            }
+            if ($ofs < $nbp) {
+                $links['suivant'] = $ofs+1;
+            }
             $page->assign('links', $links);
         }