X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;ds=sidebyside;f=modules%2Fxnetevents%2Fxnetevents.inc.php;h=ce2a8387717cdbe0730c81ddbc65b035eb5f5041;hb=c46ec4752db88dbde3f792a278f350c922cd211d;hp=c0e3bd713211014b844ec81f779072b9ac94cbd7;hpb=352fb10191f46abd6b0d309615c2fd23375ba646;p=platal.git diff --git a/modules/xnetevents/xnetevents.inc.php b/modules/xnetevents/xnetevents.inc.php index c0e3bd7..ce2a838 100644 --- a/modules/xnetevents/xnetevents.inc.php +++ b/modules/xnetevents/xnetevents.inc.php @@ -24,7 +24,7 @@ function get_event_detail($eid, $item_id = false) { global $globals; - $res = $globals->xdb->query( + $res = XDB::query( "SELECT SUM(nb) AS nb_tot, e.*, IF(e.deadline_inscription, e.deadline_inscription >= LEFT(NOW(), 10), 1) AS inscr_open, @@ -54,7 +54,7 @@ function get_event_detail($eid, $item_id = false) // smart calculation of the total number if (!$item_id) { - $res = $globals->xdb->query( + $res = XDB::query( "SELECT MAX(nb) FROM groupex.evenements AS e INNER JOIN groupex.evenements_items AS ei ON (e.eid = ei.eid) @@ -67,13 +67,13 @@ function get_event_detail($eid, $item_id = false) $evt['item_id'] = 0; } - $res = $globals->xdb->query( + $res = XDB::query( "SELECT titre, details, montant, ei.item_id, nb FROM groupex.evenements_items AS ei 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'), $evt['eid']); + S::v('uid'), $evt['eid']); $evt['moments'] = $res->fetchAllAssoc(); $evt['topay'] = 0; @@ -81,10 +81,10 @@ function get_event_detail($eid, $item_id = false) $evt['topay'] += $m['nb'] * $m['montant']; } - $req = $globals->xdb->query( + $req = XDB::query( "SELECT montant FROM {$globals->money->mpay_tprefix}transactions AS t - WHERE ref = {?} AND uid = {?}", $evt['paiement_id'], Session::get('uid')); + WHERE ref = {?} AND uid = {?}", $evt['paiement_id'], S::v('uid')); $montants = $req->fetchColumn(); $evt['paid'] = 0; @@ -105,7 +105,7 @@ function get_event_participants($evt, $item_id, $tri, $limit = '') { if (Env::has('initiale')) { $where = 'AND IF(u.nom IS NULL, m.nom, IF(u.nom_usage<>"", u.nom_usage, u.nom)) - LIKE "'.addslashes(Env::get('initiale')).'%"'; + LIKE "'.addslashes(Env::v('initiale')).'%"'; } else { $where = ''; } @@ -135,18 +135,18 @@ function get_event_participants($evt, $item_id, $tri, $limit = '') { ORDER BY $tri $limit"; if ($item_id) { - $res = $globals->xdb->query($query, $eid); + $res = XDB::query($query, $eid); return $res->fetchAllAssoc(); } - $res = $globals->xdb->iterator($query, $eid); + $res = XDB::iterator($query, $eid); $tab = array(); $user = 0; while ($u = $res->next()) { $u['montant'] = 0; if ($money && $pay_id) { - $res_ = $globals->xdb->query( + $res_ = XDB::query( "SELECT montant FROM {$globals->money->mpay_tprefix}transactions AS t WHERE ref = {?} AND uid = {?}", @@ -157,7 +157,7 @@ function get_event_participants($evt, $item_id, $tri, $limit = '') { $u['paid'] += trim($p); } } - $res_ = $globals->xdb->iterator( + $res_ = XDB::iterator( "SELECT ep.nb, ep.item_id, ei.montant FROM groupex.evenements_participants AS ep INNER JOIN groupex.evenements_items AS ei ON (ei.eid = ep.eid AND ei.item_id = ep.item_id) @@ -180,12 +180,12 @@ function subscribe_lists_event($participate, $uid, $evt) { $participant_list = $evt['participant_list']; $absent_list = $evt['absent_list']; - $email = Session::get('forlife'); + $email = S::v('forlife'); if ($email) { $email .= '@'.$globals->mail->domain; } else { - $res = $globals->xdb->query("SELECT email FROM groupex.membres WHERE uid = {?} AND asso_id = {?}", Session::get('uid'), $globals->asso('id')); + $res = XDB::query("SELECT email FROM groupex.membres WHERE uid = {?} AND asso_id = {?}", S::v('uid'), $globals->asso('id')); $email = $res->fetchOneCell(); } @@ -193,13 +193,13 @@ function subscribe_lists_event($participate, $uid, $evt) { $unsubscri = $participate ? $absent_list : $participant_list; if ($subscribe) { - $globals->xdb->execute( + XDB::execute( "REPLACE INTO virtual_redirect VALUES({?},{?})", $subscribe, $email); } if ($unsubscri) { - $globals->xdb->execute( + XDB::execute( "DELETE FROM virtual_redirect WHERE vid = {?} AND redirect = {?}", $unsubscri, $email); } @@ -207,5 +207,96 @@ function subscribe_lists_event($participate, $uid, $evt) { } // }}} +function event_change_shortname(&$page, $old, $new) +{ + global $globals; + + // Quelques vérifications sur l'alias (caractères spéciaux) + if ($old && !preg_match( "/^[a-zA-Z0-9\-.]{3,20}$/", $old)) { + $page->trig("Le raccourci demandé n'est pas valide. + Vérifie qu'il comporte entre 3 et 20 caractères + et qu'il ne contient que des lettres non accentuées, + des chiffres ou les caractères - et ."); + return $old; + } + + //vérifier que l'alias n'est pas déja pris + if ($new && $old != $new) { + $res = XDB::query('SELECT COUNT(*) FROM virtual + WHERE alias LIKE {?}', + $new.'-absents@%'); + if ($res->fetchOneCell() > 0) { + $page->trig("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 = mysql_insert_id(); + XDB::execute( + "INSERT 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 = {?} + 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 = mysql_insert_id(); + XDB::execute("INSERT INTO virtual_redirect ( + SELECT {?} AS vid, IF(u.nom 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) + 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, $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; +} + // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: ?>