+ //vérifier que l'alias n'est pas déja pris
+ if ($new && $old != $new) {
+ $res = XDB::query('SELECT COUNT(*)
+ FROM groupex.evenements
+ WHERE short_name = {?}',
+ $new);
+ if ($res->fetchOneCell() > 0) {
+ $page->trigError("Le raccourci demandé est déjà utilisé. Choisis en un autre.");
+ return $old;
+ }
+ }
+
+ if ($old == $new) {
+ return $new;
+ }
+
+ if ($old && $new) {
+ // if had a previous shortname change the old lists
+ foreach (array('-absents@', '-participants@') as $v) {
+ $v .= $globals->xnet->evts_domain;
+ XDB::execute("UPDATE virtual SET alias = {?}
+ WHERE type = 'evt' AND alias = {?}",
+ $new.$v, $old.$v);
+ }
+ return $new;
+ }
+
+ if (!$old && $new) {
+ // if we have a first new short_name create the lists
+
+ XDB::execute("INSERT INTO virtual SET type = 'evt', alias = {?}",
+ $new.'-participants@'.$globals->xnet->evts_domain);
+
+ $lastid = XDB::insertId();
+ XDB::execute(
+ "INSERT IGNORE INTO virtual_redirect (
+ SELECT {?} AS vid, IF(u.nom IS NULL, m.email, CONCAT(a.alias, {?})) AS redirect
+ FROM groupex.evenements_participants AS ep
+ LEFT JOIN groupex.membres AS m ON (ep.uid = m.uid)
+ LEFT JOIN auth_user_md5 AS u ON (u.user_id = ep.uid)
+ LEFT JOIN aliases AS a ON (a.id = ep.uid AND a.type = 'a_vie')
+ WHERE ep.eid = {?} AND ep.nb > 0
+ GROUP BY ep.uid)",
+ $lastid, '@'.$globals->mail->domain, $eid);
+
+ XDB::execute("INSERT INTO virtual SET type = 'evt', alias = {?}",
+ $new.'-absents@'.$globals->xnet->evts_domain);
+
+ $lastid = XDB::insertId();
+ XDB::execute("INSERT IGNORE INTO virtual_redirect (
+ SELECT {?} AS vid, IF(a.alias IS NULL, m.email, CONCAT(a.alias, {?})) AS redirect
+ FROM groupex.membres AS m
+ LEFT JOIN groupex.evenements_participants AS ep ON (ep.uid = m.uid AND ep.eid = {?})
+ LEFT JOIN auth_user_md5 AS u ON (u.user_id = m.uid)
+ LEFT JOIN aliases AS a ON (a.id = m.uid AND a.type = 'a_vie')
+ WHERE m.asso_id = {?} AND ep.uid IS NULL
+ GROUP BY m.uid)",
+ $lastid, "@".$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@') 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);
+ }
+ return $new;
+ }
+
+ // cannot happen
+ return $old;
+}
+// }}}
+
+// {{{ function make_event_date()
+function make_event_date(&$e)
+{
+ $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']);
+
+ $date = "";
+ if ($start && $end != $start) {
+ if ($first_day == $last_day) {
+ $date .= "le " . strftime("%d %B %Y", $start) . " de "
+ . strftime("%H:%M", $start) . " à " . strftime("%H:%M", $end);
+ } else {
+ $date .= "du " . strftime("%d %B %Y à %H:%M", $start)
+ . "\nau " . strftime("%d %B %Y à %H:%M", $end);
+ }
+ } else {
+ $date .= "le " . strftime("%d %B %Y à %H:%M", $start);
+ }
+ $e['date'] = $date;