X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fxnetevents%2Fxnetevents.inc.php;h=d2725d47d2fd8b104cde5a4f2c26d01be1cb8fb7;hb=ee71865181e96e7b0754ef9e7da4b3cb26f4c1d7;hp=494d664821ce45ca7d1e60536de90fe3dff4dc33;hpb=0c8cd507ad27b70c20e9f056b77fc286ee88e04f;p=platal.git diff --git a/modules/xnetevents/xnetevents.inc.php b/modules/xnetevents/xnetevents.inc.php index 494d664..d2725d4 100644 --- a/modules/xnetevents/xnetevents.inc.php +++ b/modules/xnetevents/xnetevents.inc.php @@ -1,6 +1,6 @@ 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 debut_day, LEFT(10, e.fin) AS fin_day, - LEFT(NOW(), 10) AS now, - ei.titre, - al.vid AS absent_list, pl.vid AS participant_list, - a.nom, a.prenom, a.promo, aa.alias - FROM groupex.evenements AS e - INNER JOIN x4dat.auth_user_md5 AS a ON a.user_id = e.organisateur_uid - INNER JOIN x4dat.aliases AS aa ON (aa.type = 'a_vie' AND aa.id = a.user_id) - INNER JOIN groupex.evenements_items AS ei ON (e.eid = ei.eid) - LEFT JOIN groupex.evenements_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, {?})) - 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, - $eid, $eid, $item_id ? $item_id : 1, $asso_id); + "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 first_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, + bl.vid AS payed_list, ul.vid AS booked_unpayed_list, + a.nom, a.prenom, a.promo, aa.alias + FROM #groupex#.evenements AS e + INNER JOIN #x4dat#.auth_user_md5 AS a ON a.user_id = e.organisateur_uid + INNER JOIN #x4dat#.aliases AS aa ON (aa.type = 'a_vie' AND aa.id = a.user_id) + INNER JOIN #groupex#.evenements_items AS ei ON (e.eid = ei.eid) + LEFT JOIN #groupex#.evenements_participants AS ep ON (e.eid = ep.eid AND ei.item_id = ep.item_id) + LEFT JOIN #x4dat#.virtual AS al ON (al.type = 'evt' AND al.alias = CONCAT(short_name, {?})) + LEFT JOIN #x4dat#.virtual AS pl ON (pl.type = 'evt' AND pl.alias = CONCAT(short_name, {?})) + LEFT JOIN #x4dat#.virtual AS bl ON (bl.type = 'evt' AND bl.alias = CONCAT(short_name, {?})) + LEFT JOIN #x4dat#.virtual AS ul ON (ul.type = 'evt' AND ul.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(); @@ -62,9 +65,9 @@ function get_event_detail($eid, $item_id = false, $asso_id = null) if (!$item_id) { $res = XDB::query( "SELECT MAX(nb) - FROM groupex.evenements AS e - INNER JOIN groupex.evenements_items AS ei ON (e.eid = ei.eid) - LEFT JOIN groupex.evenements_participants AS ep + FROM #groupex#.evenements AS e + INNER JOIN #groupex#.evenements_items AS ei ON (e.eid = ei.eid) + LEFT JOIN #groupex#.evenements_participants AS ep ON (e.eid = ep.eid AND ei.item_id = ep.item_id) WHERE e.eid = {?} GROUP BY ep.uid", $evt['eid']); @@ -75,8 +78,8 @@ function get_event_detail($eid, $item_id = false, $asso_id = null) $res = XDB::query( "SELECT titre, details, montant, ei.item_id, nb, ep.paid, FIND_IN_SET('notify_payment', ep.flags) AS notify_payment - FROM groupex.evenements_items AS ei - LEFT JOIN groupex.evenements_participants AS ep + 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 = {?}", S::v('uid'), $evt['eid']); @@ -107,6 +110,8 @@ function get_event_detail($eid, $item_id = false, $asso_id = null) $evt['telepaid'] += trim($p); } + make_event_date($evt); + return $evt; } @@ -138,11 +143,11 @@ function get_event_participants(&$evt, $item_id, $tri, $limit = '') { (m.origine = 'X' OR m.origine IS NULL) AS x, ep.uid, SUM(ep.paid) AS paid, SUM(ep.nb) AS nb, FIND_IN_SET('notify_payment', ep.flags) AS notify_payment - FROM groupex.evenements_participants AS ep - INNER JOIN groupex.evenements AS e ON (ep.eid = e.eid) - LEFT JOIN groupex.membres AS m ON ( ep.uid = m.uid AND e.asso_id = m.asso_id) - 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' ) + FROM #groupex#.evenements_participants AS ep + INNER JOIN #groupex#.evenements AS e ON (ep.eid = e.eid) + LEFT JOIN #groupex#.membres AS m ON ( ep.uid = m.uid AND e.asso_id = m.asso_id) + LEFT JOIN #x4dat#.auth_user_md5 AS u ON ( u.user_id = ep.uid ) + LEFT JOIN #x4dat#.aliases AS a ON ( a.id = ep.uid AND a.type='a_vie' ) WHERE ep.eid = {?} ".(($item_id)?" AND item_id = $item_id":"")." $where @@ -183,8 +188,8 @@ function get_event_participants(&$evt, $item_id, $tri, $limit = '') { $u['telepayment'] = $u['paid'] - $u['adminpaid']; $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) + 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) WHERE ep.eid = {?} AND ep.uid = {?}", $eid, $u['uid']); while ($i = $res_->next()) { @@ -202,21 +207,23 @@ function get_event_participants(&$evt, $item_id, $tri, $limit = '') { // }}} // {{{ function subscribe_lists_event() -function subscribe_lists_event($participate, $uid, $evt) +function subscribe_lists_event($participate, $uid, $evt, $paid, $payment = null) { global $globals; $page =& Platal::page(); - $participant_list = $evt['participant_list']; - $absent_list = $evt['absent_list']; + $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); if ($user) { $email = $user->forlifeEmail(); } else { - $res = XDB::query("SELECT email - FROM groupex.membres - WHERE uid = {?} AND asso_id = {?}", + $res = XDB::query("SELECT email + FROM #groupex#.membres + WHERE uid = {?} AND asso_id = {?}", $uid, $globals->asso('id')); $email = $res->fetchOneCell(); } @@ -224,8 +231,8 @@ function subscribe_lists_event($participate, $uid, $evt) function subscribe($list, $email) { if ($list && $email) { - XDB::execute("REPLACE INTO virtual_redirect - VALUES ({?},{?})", + XDB::execute("REPLACE INTO virtual_redirect + VALUES ({?},{?})", $list, $email); } } @@ -233,25 +240,35 @@ function subscribe_lists_event($participate, $uid, $evt) function unsubscribe($list, $email) { if ($list && $email) { - XDB::execute("DELETE FROM virtual_redirect - WHERE vid = {?} AND redirect = {?}", + XDB::execute("DELETE FROM virtual_redirect + WHERE vid = {?} AND redirect = {?}", $list, $email); } } - if (is_null($participate)) { - unsubscribe($participant_list, $email); - subscribe($absent_list, $email); - } elseif ($participate) { - subscribe($participant_list, $email); - unsubscribe($absent_list, $email); + if (is_null($payment)) { + if (is_null($participate)) { + unsubscribe($participant_list, $email); + subscribe($absent_list, $email); + } elseif ($participate) { + subscribe($participant_list, $email); + unsubscribe($absent_list, $email); + } else { + unsubscribe($participant_list, $email); + unsubscribe($absent_list, $email); + } + } + if ($paid > 0) { + unsubscribe($unpayed_list, $email); + subscribe($payed_list, $email); } else { - unsubscribe($participant_list, $email); - unsubscribe($absent_list, $email); + unsubscribe($payed_list, $email); + subscribe($unpayed_list, $email); } } // }}} +// {{{ function event_change_shortname() function event_change_shortname(&$page, $eid, $old, $new) { global $globals; @@ -266,12 +283,17 @@ function event_change_shortname(&$page, $eid, $old, $new) et qu'il ne contient que des lettres non accentuées, des chiffres ou les caractères - et ."); return $old; + } elseif ($new && ctype_digit($new)) { + $page->trigError("Le raccourci demandé ne peut être accepté car il + ne contient que des chiffres. Rajoute-lui par exemple + une lettre."); + return $old; } //vérifier que l'alias n'est pas déja pris if ($new && $old != $new) { $res = XDB::query('SELECT COUNT(*) - FROM groupex.evenements + FROM #groupex#.evenements WHERE short_name = {?}', $new); if ($res->fetchOneCell() > 0) { @@ -286,58 +308,66 @@ function event_change_shortname(&$page, $eid, $old, $new) if ($old && $new) { // if had a previous shortname change the old lists - foreach (array('-absents@', '-participants@') as $v) { + 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); + 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 + $lastid = array(); + $where = array( + '-participants@' => 'ep.nb > 0', + '-paye@' => 'ep.paid > 0', + '-participants-non-paye@' => 'ep.nb > 0 AND ep.paid = 0' + ); + + 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(); + } - 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 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 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')); + foreach (array('-participants@', '-paye@', '-participants-non-paye@') as $v) { + XDB::execute("INSERT IGNORE INTO virtual_redirect ( + SELECT {?} AS vid, IF(a.alias 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 #x4dat#.auth_user_md5 AS u ON (u.user_id = ep.uid) + LEFT JOIN #x4dat#.aliases AS a ON (a.id = ep.uid AND a.type = 'a_vie') + WHERE ep.eid = {?} AND " . $where[$v] . " + GROUP BY ep.uid)", + $lastid[$v], '@' . $globals->mail->domain, $eid); + } + 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 #x4dat#.auth_user_md5 AS u ON (u.user_id = m.uid) + LEFT JOIN #x4dat#.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['-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@') as $v) { + 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); + XDB::execute("DELETE virtual, virtual_redirect + FROM virtual + LEFT JOIN virtual_redirect USING(vid) + WHERE virtual.alias = {?}", + $infos['short_name'] . $v); } return $new; } @@ -345,6 +375,32 @@ function event_change_shortname(&$page, $eid, $old, $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; +} +// }}} // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>