Fix organizer display for events created by xnet accounts.
[platal.git] / modules / xnetevents / xnetevents.inc.php
index 1380295..dade470 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2011 Polytechnique.org                              *
+ *  Copyright (C) 2003-2014 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
+// {{{ function get_event_order()
+/* get the order to paste the events
+ * @param $asso_id: group's id
+ */
+function get_event_order($asso_id)
+{
+    $order = XDB::fetchOneCell('SELECT g.event_order
+                                  FROM groups as g
+                                 WHERE id = {?}',
+                                       $asso_id);
+    return $order;
+}
+// }}}
+
+// {{{ function get_events()
+/* get the events of the given group ordered by the standard order for the group
+ * @param $asso_id: group's id
+ * @param $order: order to paste the events (asc or desc)
+ * @param $archive: whether to get the archived events (1) or the actuals (0)
+ */
+function get_events($asso_id, $order, $archive)
+{
+    if ($order != 'asc' && $order != 'desc') {
+        $order = 'desc';
+    }
+    $evts = XDB::fetchAllAssoc('eid', "SELECT ge.eid, ge.uid, ge.intitule, ge.debut, ge.fin, ge.show_participants, ge.deadline_inscription, ge.accept_nonmembre, ge.paiement_id
+                                         FROM group_events as ge
+                                        WHERE asso_id = {?} and archive = {?}
+                                     ORDER BY ge.debut $order",
+                                              $asso_id, $archive);
+    return $evts;
+}
+// }}}
+
+// {{{ function get_event() (detail, for subs page only for now)
+/* get event details
+ * @param $eid: event's id
+ */
+function get_event($eid)
+{
+    $evt = XDB::fetchOneAssoc('SELECT ge.uid, ge.intitule, ge.descriptif, ge.debut, ge.fin, ge.deadline_inscription, ge.accept_nonmembre, ge.paiement_id
+                                         FROM group_events as ge
+                                        WHERE eid = {?}',
+                                        $eid);
+    if (!is_null($evt['deadline_inscription']) && strtotime($evt['deadline_inscription']) < time()) {
+        $evt['inscr_open'] = false;
+    } else {
+        $evt['inscr_open'] = true;
+    }
+    $evt['organizer'] = User::getSilent($evt['uid']);
+    $evt['date'] = make_event_date($evt['debut'], $evt['fin']);
+
+    return $evt;
+}
+// }}}
+
+// {{{ function get_event_items()
+/** get items of the given event
+ *
+ * @param $eid : event's id
+ *
+ */
+function get_event_items($eid)
+{
+    $evt = XDB::fetchAllAssoc('item_id', 'SELECT gei.item_id, gei.titre, gei.details, gei.montant
+        FROM group_event_items as gei
+        WHERE eid = {?}',
+        $eid);
+    return $evt;
+}
+// }}}
+
+// {{{ function get_event_subscription()
+/* get all participations if uid is not specified, only the user's participation if uid specified
+ * @param $eid: event's id
+ * @param $uid: user's id
+ */
+function get_event_subscription($eid, $uid = null)
+{
+    if (!is_null($uid)) {
+        $where = ' and gep.uid = '.$uid;
+    }
+    else {
+        $where = '';
+    }
+   $sub =  XDB::fetchAllAssoc('item_id','SELECT gep.item_id, gep.nb, gep.paid FROM group_event_participants as gep
+                                          WHERE gep.eid = {?}'.$where,
+                                                $eid);
+   return $sub;
+}
+// }}}
+
+// {{{ function get_event_telepaid()
+/* get the total payments made by a user for an event
+ * @param $eid: event's id
+ * @param $uid: user's id
+ */
+function get_event_telepaid($eid, $uid)
+{
+   $telepaid = XDB::fetchOneCell('SELECT SUM(pt.amount)
+                                    FROM payment_transactions AS pt
+                               LEFT JOIN group_events as ge ON (ge.paiement_id = pt.ref)
+                                   WHERE ge.eid = {?} AND pt.uid = {?}', 
+                                         $eid, $uid);
+    return $telepaid;
+}
+// }}}
+
 // {{{ function get_event_detail()
 
 function get_event_detail($eid, $item_id = false, $asso_id = null)
@@ -27,30 +135,26 @@ function get_event_detail($eid, $item_id = false, $asso_id = null)
     if (is_null($asso_id)) {
         $asso_id = $globals->asso('id');
     }
-    $res = XDB::query('SELECT  SUM(nb) AS nb_tot, COUNT(DISTINCT ep.uid) AS nb, e.*,
-                               IF(e.deadline_inscription,
-                                     e.deadline_inscription >= LEFT(NOW(), 10),
-                                     1) AS inscr_open,
-                               LEFT(10, e.debut) AS start_day, LEFT(10, e.fin) AS last_day,
-                               LEFT(NOW(), 10) AS now,
-                               ei.titre, al.vid AS absent_list, pl.vid AS participant_list,
-                               pyl.vid AS payed_list, bl.vid AS booked_unpayed_list,
-                               e.subscription_notification
-                         FROM  group_events              AS e
-                   INNER JOIN  group_event_items        AS ei ON (e.eid = ei.eid)
-                    LEFT JOIN  group_event_participants AS ep ON(e.eid = ep.eid AND ei.item_id = ep.item_id)
-                    LEFT JOIN  virtual AS al ON(al.type = \'evt\' AND al.alias = CONCAT(short_name, {?}))
-                    LEFT JOIN  virtual AS pl ON(pl.type = \'evt\' AND pl.alias = CONCAT(short_name, {?}))
-                    LEFT JOIN  virtual AS pyl ON(pyl.type = \'evt\' AND pyl.alias = CONCAT(short_name, {?}))
-                    LEFT JOIN  virtual AS bl ON(bl.type = \'evt\' AND bl.alias = CONCAT(short_name, {?}))
-                        WHERE  (e.eid = {?} OR e.short_name = {?}) AND ei.item_id = {?} AND e.asso_id = {?}
-                     GROUP BY  ei.item_id',
-                   '-absents@'.$globals->xnet->evts_domain,
-                   '-participants@'.$globals->xnet->evts_domain,
-                   '-paye@' . $globals->xnet->evts_domain,
-                   '-participants-non-paye@' . $globals->xnet->evts_domain,
-                   $eid, $eid, $item_id ? $item_id : 1, $asso_id);
-    $evt = $res->fetchOneAssoc();
+    if (!$item_id) {
+        $where = '';
+        $group_by = 'e.eid';
+    } else {
+        $where = XDB::format(' AND ei.item_id = {?}', $item_id);
+        $group_by = 'ei.item_id';
+    }
+    $evt = XDB::fetchOneAssoc('SELECT  SUM(nb) AS nb_tot, COUNT(DISTINCT ep.uid) AS nb, e.*, SUM(IF(nb > 0, 1, 0)) AS user_count,
+                                       IF(e.deadline_inscription,
+                                          e.deadline_inscription >= LEFT(NOW(), 10),
+                                          1) AS inscr_open,
+                                       LEFT(e.debut, 10) AS first_day, LEFT(e.fin, 10) AS last_day,
+                                       LEFT(NOW(), 10) AS now,
+                                       ei.titre, e.subscription_notification
+                                 FROM  group_events             AS e
+                           INNER JOIN  group_event_items        AS ei ON (e.eid = ei.eid)
+                            LEFT JOIN  group_event_participants AS ep ON(e.eid = ep.eid AND ei.item_id = ep.item_id)
+                                WHERE  (e.eid = {?} OR e.short_name = {?}) AND e.asso_id = {?}' . $where . '
+                             GROUP BY  ' . $group_by,
+                              $eid, $eid, $asso_id);
 
     if (!$evt) {
         return null;
@@ -59,17 +163,18 @@ function get_event_detail($eid, $item_id = false, $asso_id = null)
         return false;
     }
 
-    // smart calculation of the total number
     if (!$item_id) {
-        $res = XDB::query('SELECT  MAX(nb)
-                             FROM  group_events              AS e
-                       INNER JOIN  group_event_items        AS ei ON (e.eid = ei.eid)
-                        LEFT JOIN  group_event_participants AS ep ON (e.eid = ep.eid AND ei.item_id = ep.item_id)
-                            WHERE  e.eid = {?}
-                         GROUP BY  ep.uid', $evt['eid']);
-        $evt['nb_tot'] = array_sum($res->fetchColumn());
+        /* Don't try to be to smart here, in case we're getting the global summary, we cannot have
+         * a general formula to estimate the total number of comers since 'moments' may (or may not be)
+         * disjuncted. As a consequence, we can only provides the number of user having fullfiled the
+         * registration procedure.
+         */
+        $evt['user_count'] = $evt['nb_tot'] = $evt['nb'];
         $evt['titre'] = '';
         $evt['item_id'] = 0;
+        $evt['csv_name'] = urlencode($evt['intitule']);
+    } else {
+        $evt['csv_name'] = urlencode($evt['intitule'] . '.' . $evt['titre']);
     }
 
     $evt['moments'] = XDB::fetchAllAssoc('SELECT  titre, details, montant, ei.item_id, nb,
@@ -87,23 +192,21 @@ function get_event_detail($eid, $item_id = false, $asso_id = null)
         if ($m['montant']) {
             $evt['money'] = true;
         }
-        $evt['paid']  = $m['paid'];
+        $evt['paid'] += $m['paid'];
         $evt['notify_payment'] = $evt['notify_payment'] || $m['notify_payment'];
     }
 
-    $montants = XDB::fetchColumn('SELECT  amount
+    $montant = XDB::fetchOneCell('SELECT  SUM(amount) AS sum_amount
                                     FROM  payment_transactions AS t
                                    WHERE  ref = {?} AND uid = {?}',
                                    $evt['paiement_id'], S::v('uid'));
-    $evt['telepaid'] = 0;
-    foreach ($montants as $m) {
-        $p = strtr(substr($m, 0, strpos($m, 'EUR')), ',', '.');
-        $evt['paid'] += trim($p);
-        $evt['telepaid'] += trim($p);
-    }
+    $evt['telepaid'] = $montant;
+    $evt['paid'] += $montant;
     $evt['organizer'] = User::getSilent($evt['uid']);
 
-    make_event_date($evt);
+    $evt['date'] = make_event_date($evt['debut'], $evt['fin']);
+
+    $evt['show_participants'] = ($evt['show_participants'] && $GLOBALS['IS_XNET_SITE'] && (is_member() || may_update()));
 
     return $evt;
 }
@@ -111,7 +214,7 @@ function get_event_detail($eid, $item_id = false, $asso_id = null)
 // }}}
 
 // {{{ function get_event_participants()
-function get_event_participants(&$evt, $item_id, array $tri = array(), $limit = null)
+function get_event_participants(&$evt, $item_id, array $tri = array(), $limit = null, $offset = 0)
 {
     global $globals;
 
@@ -126,7 +229,7 @@ function get_event_participants(&$evt, $item_id, array $tri = array(), $limit =
                                          WHERE  ep.eid = {?} AND nb > 0 ' . $append . '
                                       GROUP BY  ep.uid', $eid);
     $uf = new UserFilter(new PFC_True(), $tri);
-    $users = User::getBulkUsersWithUIDs($uf->filter(array_keys($query), new PlLimit($count, $offset)));
+    $users = User::getBulkUsersWithUIDs($uf->filter(array_keys($query), new PlLimit($limit, $offset)));
     $tab = array();
     foreach ($users as $user) {
         $uid = $user->id();
@@ -143,17 +246,14 @@ function get_event_participants(&$evt, $item_id, array $tri = array(), $limit =
     $evt['topay']     = 0;
     $evt['paid']      = 0;
     foreach ($tab as $uid=>&$u) {
-        $u['adminpaid'] = $u['paid'];
+        $u['adminpaid'] = (float)$u['paid'];
         $u['montant'] = 0;
         if ($money && $pay_id) {
-            $montants = XDB::fetchColumn('SELECT  amount
+            $montant = XDB::fetchOneCell('SELECT  SUM(amount)
                                             FROM  payment_transactions AS t
                                            WHERE  ref = {?} AND uid = {?}',
                                          $pay_id, $uid);
-            foreach ($montants as $m) {
-                $p = strtr(substr($m, 0, strpos($m, "EUR")), ",", ".");
-                $u['paid'] += trim($p);
-            }
+            $u['paid'] += $montant;
         }
         $u['telepayment'] = $u['paid'] - $u['adminpaid'];
         $res_ = XDB::iterator('SELECT  ep.nb, ep.item_id, ei.montant
@@ -163,7 +263,7 @@ function get_event_participants(&$evt, $item_id, array $tri = array(), $limit =
                             $eid, $uid);
         while ($i = $res_->next()) {
             $u[$i['item_id']] = $i['nb'];
-            $u['montant'] += $i['montant']*$i['nb'];
+            $u['montant'] += $i['montant'] * $i['nb'];
         }
         $evt['telepaid']  += $u['telepayment'];
         $evt['adminpaid'] += $u['adminpaid'];
@@ -174,11 +274,89 @@ function get_event_participants(&$evt, $item_id, array $tri = array(), $limit =
 }
 // }}}
 
+//  {{{ function subscribe()
+/** set or update the user's subscription
+ *
+ * @param $uid: user's id
+ * @param $eid: event's id
+ * @param $subs: user's new subscription
+ *
+ */
+function subscribe($uid, $eid, $subs = array())
+{
+    global $globals;
+    // get items
+    $items = get_event_items($eid);
+    // get previous subscription
+    $old_subs = get_event_subscription($eid, $uid);
+    $participate = false;
+    $updated = false;
+    // TODO : change the way to deal with manual payment
+    $paid = 0;
+    foreach ($old_subs as $item_id => $s) {
+        $paid += $s['paid'];
+    }
+    $paid_updated = false;
+    // for each item of the event
+    foreach ($items as $item_id => $details) {
+        // check if there is an old subscription
+        if (array_key_exists($item_id, $old_subs)) {
+            // compares new and old subscription
+            if ($old_subs[$item_id]['nb'] != $subs[$item_id]) {
+                if ($subs[$item_id] != 0) {
+                    echo "je m'inscris  ";
+                    XDB::execute('INSERT INTO group_event_participants (eid, uid, item_id, nb, flags, paid)
+                                       VALUES ({?}, {?}, {?}, {?}, {?}, {?})
+                      ON DUPLICATE KEY UPDATE nb = VALUES(nb), flags = VALUES(flags), paid = VALUES(paid)',
+                                             $eid, $uid, $item_id, $subs[$item_id],(Env::has('notify_payment') ? 'notify_payment' : 0), (!$paid_updated ? $paid : 0));
+                    $participate = true;
+                    $paid_updated = true;
+                } else { // we do not store non-subscription to event items
+                    XDB::execute('DELETE FROM group_event_participants
+                                        WHERE eid = {?} AND uid = {?} AND item_id = {?}',
+                                              $eid, $uid, $item_id);
+                }
+                $updated = true;
+            }
+        } else { // if no old subscription
+            if ($subs[$item_id] != 0) {
+                XDB::execute('INSERT INTO group_event_participants (eid, uid, item_id, nb, flags, paid)
+                                   VALUES ({?}, {?}, {?}, {?}, {?}, {?})',
+                                          $eid, $uid, $item_id, $subs[$item_id], '', 0);
+                $participate = true;
+                $updated = true;
+            }
+        }
+    }
+    // item 0 stores whether the user participates globally or not, if he has to be notified when payment is created and his manual payment
+    /*
+    if (array_key_exists(0, $old_subs)) {
+        XDB::execute('UPDATE group_event_participants
+                         SET nb = {?}
+                       WHERE eid = {?}, uid = {?}, item_id = 0',
+                             ($participate ? 1 : 0), $eid, $uid);
+    } else {
+        XDB::execute('INSERT INTO group_event_participants (eid, uid, item_id, nb, flags, paid)
+                           VALUES ({?}, {?}, {?}, {?}, {?}, {?})',
+                                  $eid, $uid, 0, ($participate ? 1 : 0), (Env::has('notify_payment') ? 'notify_payment' : ''), 0);
+    }
+    */
+    // if subscription is updated, we have to update the event aliases
+    if ($updated) {
+        $short_name = get_event_detail($eid)['short_name'];
+        subscribe_lists_event($uid, $short_name, ($participate ? 1 : -1), 0);
+    }
+    return $updated;
+}
+//  }}}
+
+// TODO : correct this function to be compatible with subscribe() (use $eid, remove useless argument)
+// TODO : correct other calls
 //  {{{ function subscribe_lists_event()
 /** Subscribes user to various event related mailing lists.
  *
  * @param $uid: user's id.
- * @param evt: events data, in particular ids of the lists at stake.
+ * @param short_name: event's short_name, which corresponds to the beginning of the emails.
  * @param participate: indicates if the user takes part at the event or not;
  *      -1 means he did not answer, 0 means no, and 1 means yes.
  * @param paid: has the user already payed anything?
@@ -186,32 +364,13 @@ function get_event_participants(&$evt, $item_id, array $tri = array(), $limit =
  * @param payment: is this function called from a payment page?
  *      If true, only payment related lists should be updated.
  */
-function subscribe_lists_event($uid, $evt, $participate, $paid, $payment = false)
+function subscribe_lists_event($uid, $short_name, $participate, $paid, $payment = false)
 {
-    $participant_list  = $evt['participant_list'];
-    $absent_list       = $evt['absent_list'];
-    $unpayed_list      = $evt['booked_unpayed_list'];
-    $payed_list        = $evt['payed_list'];
-
-    $user = User::getSilent($uid);
-    $email = $user->forlifeEmail();
-
-    function subscribe($list, $email)
-    {
-        if ($list && $email) {
-            XDB::execute('INSERT IGNORE INTO  virtual_redirect
-                                      VALUES  ({?}, {?})',
-                         $list, $email);
-        }
-    }
+    global $globals;
+    require_once 'emails.inc.php';
 
-    function unsubscribe($list, $email)
-    {
-        if ($list && $email) {
-            XDB::execute('DELETE FROM  virtual_redirect
-                                WHERE  vid = {?} AND redirect = {?}',
-                         $list, $email);
-        }
+    if (is_null($short_name)) {
+        return;
     }
 
     /** If $payment is not null, we do not retrieve the value of $participate,
@@ -219,32 +378,32 @@ function subscribe_lists_event($uid, $evt, $participate, $paid, $payment = false
      */
     if ($payment === true) {
         if ($paid > 0) {
-            unsubscribe($unpayed_list, $email);
-            subscribe($payed_list, $email);
+            delete_from_list_alias($uid, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event');
+            add_to_list_alias($uid, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event');
         }
     } else {
         switch ($participate) {
           case -1:
-            unsubscribe($participant_list, $email);
-            unsubscribe($unpayed_list, $email);
-            unsubscribe($payed_list, $email);
-            subscribe($absent_list, $email);
+            delete_from_list_alias($uid, $short_name . $globals->xnet->participant_list, $globals->xnet->evts_domain, 'event');
+            delete_from_list_alias($uid, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event');
+            delete_from_list_alias($uid, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event');
+            add_to_list_alias($uid, $short_name . $globals->xnet->absent_list, $globals->xnet->evts_domain, 'event');
             break;
           case 0:
-            unsubscribe($participant_list, $email);
-            unsubscribe($absent_list, $email);
-            unsubscribe($unpayed_list, $email);
-            unsubscribe($payed_list, $email);
+            delete_from_list_alias($uid, $short_name . $globals->xnet->participant_list, $globals->xnet->evts_domain, 'event');
+            delete_from_list_alias($uid, $short_name . $globals->xnet->absent_list, $globals->xnet->evts_domain, 'event');
+            delete_from_list_alias($uid, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event');
+            delete_from_list_alias($uid, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event');
             break;
           case 1:
-            subscribe($participant_list, $email);
-            unsubscribe($absent_list, $email);
+            add_to_list_alias($uid, $short_name . $globals->xnet->participant_list, $globals->xnet->evts_domain, 'event');
+            delete_from_list_alias($uid, $short_name . $globals->xnet->absent_list, $globals->xnet->evts_domain, 'event');
             if ($paid > 0) {
-                unsubscribe($unpayed_list, $email);
-                subscribe($payed_list, $email);
+                delete_from_list_alias($uid, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event');
+                add_to_list_alias($uid, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event');
             } else {
-                subscribe($unpayed_list, $email);
-                unsubscribe($payed_list, $email);
+                add_to_list_alias($uid, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event');
+                delete_from_list_alias($uid, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event');
             }
             break;
         }
@@ -253,9 +412,10 @@ function subscribe_lists_event($uid, $evt, $participate, $paid, $payment = false
 // }}}
 
 //  {{{ function event_change_shortname()
-function event_change_shortname(&$page, $eid, $old, $new)
+function event_change_shortname($page, $eid, $old, $new)
 {
     global $globals;
+    require_once 'emails.inc.php';
 
     if (is_null($old)) {
         $old = '';
@@ -292,13 +452,13 @@ function event_change_shortname(&$page, $eid, $old, $new)
 
     if ($old && $new) {
         // if had a previous shortname change the old lists
-        foreach (array('-absents@', '-participants@', '-paye@', '-participants-non-paye@') as $v) {
-            $v .= $globals->xnet->evts_domain;
-            XDB::execute("UPDATE  virtual
-                             SET  alias = {?}
-                           WHERE  type = 'evt' AND alias = {?}",
-                         $new . $v, $old . $v);
+        foreach (explode(',', $globals->xnet->event_lists) as $suffix) {
+            XDB::execute('UPDATE  email_virtual
+                             SET  email = {?}
+                           WHERE  type = \'event\' AND email = {?}',
+                         $new . $suffix, $old . $suffix);
         }
+
         return $new;
     }
 
@@ -306,52 +466,41 @@ function event_change_shortname(&$page, $eid, $old, $new)
         // if we have a first new short_name create the lists
         $lastid = array();
         $where = array(
-            '-participants@'          => 'ep.nb > 0',
-            '-paye@'                  => 'ep.paid > 0',
-            '-participants-non-paye@' => 'ep.nb > 0 AND ep.paid = 0'
+            $globals->xnet->participant_list => 'g.nb > 0',
+            $globals->xnet->payed_list       => '(g.paid > 0 OR p.amount > 0)',
+            $globals->xnet->unpayed_list     => 'g.nb > 0 AND g.paid = 0 AND p.amount IS NULL'
         );
 
-        foreach (array('-absents@', '-participants@', '-paye@', '-participants-non-paye@') as $v) {
-            XDB::execute("INSERT INTO  virtual
-                                  SET  type = 'evt', alias = {?}",
-                         $new . $v . $globals->xnet->evts_domain);
-
-            $lastid[$v] = XDB::insertId();
+        foreach (array($globals->xnet->participant_list, $globals->xnet->payed_list, $globals->xnet->unpayed_list) as $suffix) {
+            $uids = XDB::fetchColumn('SELECT  g.uid
+                                        FROM  group_event_participants AS g
+                                  INNER JOIN  group_events             AS e ON (g.eid = e.eid)
+                                   LEFT JOIN  payment_transactions     AS p ON (e.paiement_id = p.ref AND g.uid = p.uid)
+                                       WHERE  g.eid = {?} AND ' . $where[$suffix],
+                                     $eid);
+            foreach ($uids as $uid) {
+                add_to_list_alias($uid, $new . $suffix, $globals->xnet->evts_domain, 'event');
+            }
         }
 
-        foreach (array('-participants@', '-paye@', '-participants-non-paye@') as $v) {
-            XDB::execute("INSERT IGNORE INTO  virtual_redirect (
-                                      SELECT  {?} AS vid, IF(al.alias IS NULL, a.email, CONCAT(al.alias, {?})) AS redirect
-                                        FROM  group_event_participants AS ep
-                                   LEFT JOIN  accounts AS a  ON (ep.uid = a.uid)
-                                   LEFT JOIN  aliases  AS al ON (al.uid = a.uid AND al.type = 'a_vie')
-                                       WHERE  ep.eid = {?} AND " . $where[$v] . "
-                                    GROUP BY  ep.uid)",
-                         $lastid[$v], '@' . $globals->mail->domain, $eid);
+        $uids = XDB::fetchColumn('SELECT  m.uid
+                                    FROM  group_members            AS m
+                               LEFT JOIN  group_event_participants AS e ON (e.uid = m.uid AND e.eid = {?})
+                                   WHERE  m.asso_id = {?} AND e.uid IS NULL',
+                                 $eid, $globals->asso('id'));
+        foreach ($uids as $uid) {
+            add_to_list_alias($uid, $new . $globals->xnet->absent_list, $globals->xnet->evts_domain, 'event');
         }
-        XDB::execute("INSERT IGNORE INTO  virtual_redirect (
-                                  SELECT  {?} AS vid, IF(al.alias IS NULL, a.email, CONCAT(al.alias, {?})) AS redirect
-                                    FROM  group_members AS m
-                               LEFT JOIN  accounts  AS a  ON (a.uid = m.uid)
-                               LEFT JOIN  aliases   AS al ON (al.uid = a.uid AND al.type = 'a_vie')
-                               LEFT JOIN  group_event_participants AS ep ON (ep.uid = m.uid AND ep.eid = {?})
-                                   WHERE  m.asso_id = {?} AND ep.uid IS NULL
-                                GROUP BY  m.uid)",
-                     $lastid['-absents@'], '@' . $globals->mail->domain, $eid, $globals->asso('id'));
 
         return $new;
     }
 
     if ($old && !$new) {
         // if we delete the old short name, delete the lists
-        foreach (array('-absents@', '-participants@', '-paye@', '-participants-non-paye@') as $v) {
-            $v .= $globals->xnet->evts_domain;
-            XDB::execute("DELETE  virtual, virtual_redirect
-                            FROM  virtual
-                       LEFT JOIN  virtual_redirect USING(vid)
-                           WHERE  virtual.alias = {?}",
-                         $infos['short_name'] . $v);
+        foreach (explode(',', $globals->xnet->event_lists) as $suffix) {
+            delete_list_alias($old . $suffix, $globals->xnet->evts_domain);
         }
+
         return $new;
     }
 
@@ -361,14 +510,14 @@ function event_change_shortname(&$page, $eid, $old, $new)
 // }}}
 
 //  {{{ function make_event_date()
-function make_event_date(&$e)
+function make_event_date($debut, $fin)
 {
-    $start     = strtotime($e['debut']);
-    $end       = strtotime($e['fin']);
-    $first_day = @strtotime($e['first_day']);
-    $last_day  = strtotime($e['last_day']);
-    unset($e['debut'], $e['fin'], $e['first_day'], $e['last_day']);
-
+    $start     = strtotime($debut);
+    $end       = strtotime($fin);
+//    $first_day = $e['first_day'];
+//    $last_day  = $e['last_day'];
+    $first_day = strftime("%d %B %Y", $start);
+    $last_day = strftime("%d %B %Y", $end);
     $date = "";
     if ($start && $end != $start) {
         if ($first_day == $last_day) {
@@ -381,9 +530,9 @@ function make_event_date(&$e)
     } else {
         $date .= "le " . strftime("%d %B %Y à %H:%M", $start);
     }
-    $e['date'] = $date;
+    return $date;
 }
 // }}}
 
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
 ?>