X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fxnetevents%2Fxnetevents.inc.php;h=fe8fc4a132c7ee4251b5cf05b05d4cb659f20352;hb=5660032ac785d410f90e3f5b0d6948dc90b0cfea;hp=57cffaf4d09afaae83d8f0170d8e72a9b6d0b54a;hpb=d1e6167749fdad08c81e23d09e1bbbf76e3b989b;p=platal.git diff --git a/modules/xnetevents/xnetevents.inc.php b/modules/xnetevents/xnetevents.inc.php index 57cffaf..fe8fc4a 100644 --- a/modules/xnetevents/xnetevents.inc.php +++ b/modules/xnetevents/xnetevents.inc.php @@ -34,15 +34,17 @@ function get_event_detail($eid, $item_id = false, $asso_id = null) 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 - 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) - 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, {?})) + 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) + 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, {?})) 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(); @@ -56,9 +58,9 @@ function get_event_detail($eid, $item_id = false, $asso_id = null) // smart calculation of the total number 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 ON (e.eid = ep.eid AND ei.item_id = ep.item_id) + 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']); $evt['nb_tot'] = array_sum($res->fetchColumn()); @@ -68,8 +70,8 @@ function get_event_detail($eid, $item_id = false, $asso_id = null) $evt['moments'] = XDB::fetchAllAssoc('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 ON (ep.eid = ei.eid AND ep.item_id = ei.item_id + 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::i('uid'), $evt['eid']); @@ -115,7 +117,7 @@ function get_event_participants(&$evt, $item_id, array $tri = array(), $count = $append = $item_id ? XDB::foramt(' AND ep.item_id = {?}', $item_id) : ''; $query = XDB::fetchAllAssoc('uid', 'SELECT 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 + FROM #groupex#.evenements_participants AS ep WHERE ep.eid = {?} AND nb > 0 ' . $append . ' GROUP BY ep.uid', $eid); $uf = new UserFilter(new UFC_True(), $tri); @@ -150,8 +152,8 @@ function get_event_participants(&$evt, $item_id, array $tri = array(), $count = } $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, $uid); while ($i = $res_->next()) { @@ -168,21 +170,23 @@ function get_event_participants(&$evt, $item_id, array $tri = array(), $count = // }}} // {{{ 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(); } @@ -190,8 +194,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); } } @@ -199,21 +203,30 @@ 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); } } // }}} @@ -243,7 +256,7 @@ function event_change_shortname(&$page, $eid, $old, $new) //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) { @@ -258,56 +271,65 @@ 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(al.alias IS NULL, a.email, CONCAT(al.alias, {?})) AS redirect - FROM groupex.evenements_participants AS ep - LEFT JOIN accounts AS a ON (ep.uid = a.uid) - LEFT JOIN aliases AS al ON (al.id = a.uid AND al.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(); + 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 #groupex#.evenements_participants AS ep + LEFT JOIN #x4dat#.accounts AS a ON (ep.uid = a.uid) + LEFT JOIN #x4dat#.aliases AS al ON (al.id = a.uid AND al.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(al.alias IS NULL, a.email, CONCAT(al.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 accounts AS a ON (a.uid = m.uid) - LEFT JOIN aliases AS al ON (al.id = a.uid AND al.type = 'a_vie') + FROM #groupex#.membres AS m + LEFT JOIN #x4dat#.accounts AS a ON (a.uid = m.uid) + LEFT JOIN #x4dat#.aliases AS al ON (al.id = a.uid AND al.type = 'a_vie') + LEFT JOIN #groupex#.evenements_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, "@".$globals->mail->domain, $eid, $globals->asso('id')); + $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; }