X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fxnetevents%2Fxnetevents.inc.php;h=7bbd1d759102d7497567e9f35a86980a2197ad0e;hb=20c5c7e6a3ba4acebffb88a22d474931a2b4353b;hp=f2acb4433d01b8ac97db30ddd0f3c57b997f84dd;hpb=61664f8bcd3b1a622b0e67381802f5234c271772;p=platal.git diff --git a/modules/xnetevents/xnetevents.inc.php b/modules/xnetevents/xnetevents.inc.php index f2acb44..7bbd1d7 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, e.*, + "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(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, a.nom, a.prenom, a.promo, aa.alias - FROM groupex.evenements AS e + 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) + 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 = {?} + 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, $globals->asso('id')); + $eid, $eid, $item_id ? $item_id : 1, $asso_id); $evt = $res->fetchOneAssoc(); - if (!$evt || ($evt['accept_nonmembre'] == 0 && !is_member() && !may_update())) { + if (!$evt) { return null; } + if ($GLOBALS['IS_XNET_SITE'] && $evt['accept_nonmembre'] == 0 && !is_member() && !may_update()) { + return false; + } // smart calculation of the total number if (!$item_id) { @@ -68,7 +74,7 @@ function get_event_detail($eid, $item_id = false) } $res = XDB::query( - "SELECT titre, details, montant, ei.item_id, nb, ep.paid + "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 AND uid = {?}) @@ -78,12 +84,14 @@ function get_event_detail($eid, $item_id = false) $evt['topay'] = 0; $evt['paid'] = 0; + $evt['notify_payment'] = false; foreach ($evt['moments'] as $m) { $evt['topay'] += $m['nb'] * $m['montant']; if ($m['montant']) { $evt['money'] = true; } $evt['paid'] = $m['paid']; + $evt['notify_payment'] = $evt['notify_payment'] || $m['notify_payment']; } $req = XDB::query( @@ -92,18 +100,22 @@ function get_event_detail($eid, $item_id = false) WHERE ref = {?} AND uid = {?}", $evt['paiement_id'], S::v('uid')); $montants = $req->fetchColumn(); + $evt['telepaid'] = 0; foreach ($montants as $m) { $p = strtr(substr($m, 0, strpos($m, 'EUR')), ',', '.'); $evt['paid'] += trim($p); + $evt['telepaid'] += trim($p); } + make_event_date($evt); + return $evt; } // }}} // {{{ function get_event_participants() -function get_event_participants($evt, $item_id, $tri, $limit = '') { +function get_event_participants(&$evt, $item_id, $tri, $limit = '') { global $globals; if (Env::has('initiale')) { @@ -115,7 +127,7 @@ function get_event_participants($evt, $item_id, $tri, $limit = '') { } $eid = $evt['eid']; - $money = $evt['money'] && may_update(); + $money = $evt['money'] && (function_exists('may_update')) && may_update(); $pay_id = $evt['paiement_id']; $query = @@ -125,14 +137,15 @@ function get_event_participants($evt, $item_id, $tri, $limit = '') { IF(m.origine != 'X' OR u.perms = 'pending',m.email,a.alias) AS email, IF(m.origine != 'X',m.sexe,FIND_IN_SET('femme', u.flags)) AS femme, m.perms='admin' AS admin, - (m.origine = 'X') AS x, - ep.uid, ep.paid, SUM(nb) AS nb + (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 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' ) - WHERE ep.eid = {?} AND ep.nb > 0 + WHERE ep.eid = {?} ".(($item_id)?" AND item_id = $item_id":"")." $where GROUP BY ep.uid @@ -147,9 +160,17 @@ function get_event_participants($evt, $item_id, $tri, $limit = '') { $tab = array(); $user = 0; + $evt['adminpaid'] = 0; + $evt['telepaid'] = 0; + $evt['topay'] = 0; + $evt['paid'] = 0; while ($u = $res->next()) { + if ($u['nb'] == 0) { + continue; + } + $u['adminpaid'] = $u['paid']; $u['montant'] = 0; - if ($money && $pay_id) { + if ($money && $pay_id) { $res_ = XDB::query( "SELECT montant FROM {$globals->money->mpay_tprefix}transactions AS t @@ -157,21 +178,26 @@ function get_event_participants($evt, $item_id, $tri, $limit = '') { $pay_id, $u['uid']); $montants = $res_->fetchColumn(); foreach ($montants as $m) { - $p = strtr(substr($m, 0, strpos($m, "EUR")), ",", "."); - $u['paid'] += trim($p); + $p = strtr(substr($m, 0, strpos($m, "EUR")), ",", "."); + $u['paid'] += trim($p); } - } + } + $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) - WHERE ep.eid = {?} AND ep.uid = {?}", + "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) + WHERE ep.eid = {?} AND ep.uid = {?}", $eid, $u['uid']); while ($i = $res_->next()) { $u[$i['item_id']] = $i['nb']; $u['montant'] += $i['montant']*$i['nb']; } - $tab[] = $u; + $tab[] = $u; + $evt['telepaid'] += $u['telepayment']; + $evt['adminpaid'] += $u['adminpaid']; + $evt['paid'] += $u['paid']; + $evt['topay'] += $u['montant']; } return $tab; } @@ -180,21 +206,20 @@ function get_event_participants($evt, $item_id, $tri, $limit = '') { // {{{ function subscribe_lists_event() function subscribe_lists_event($participate, $uid, $evt) { - require_once('user.func.inc.php'); - global $globals,$page; + global $globals; + $page =& Platal::page(); $participant_list = $evt['participant_list']; $absent_list = $evt['absent_list']; - $email = get_user_forlife($uid); - - if ($email) { - $email .= '@'.$globals->mail->domain; + $user = User::getSilent($uid); + if ($user) { + $email = $user->forlifeEmail(); } else { $res = XDB::query("SELECT email FROM groupex.membres WHERE uid = {?} AND asso_id = {?}", - S::v('uid'), $globals->asso('id')); + $uid, $globals->asso('id')); $email = $res->fetchOneCell(); } @@ -229,7 +254,8 @@ function subscribe_lists_event($participate, $uid, $evt) } // }}} -function event_change_shortname(&$page, $old, $new) +// {{{ function event_change_shortname() +function event_change_shortname(&$page, $eid, $old, $new) { global $globals; @@ -238,11 +264,16 @@ function event_change_shortname(&$page, $old, $new) } // Quelques vérifications sur l'alias (caractères spéciaux) if ($new && !preg_match( "/^[a-zA-Z0-9\-.]{3,20}$/", $new)) { - $page->trig("Le raccourci demandé n'est pas valide. + $page->trigError("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; + } 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 @@ -252,7 +283,7 @@ function event_change_shortname(&$page, $old, $new) WHERE short_name = {?}', $new); if ($res->fetchOneCell() > 0) { - $page->trig("Le raccourci demandé est déjà utilisé. Choisis en un autre."); + $page->trigError("Le raccourci demandé est déjà utilisé. Choisis en un autre."); return $old; } } @@ -280,13 +311,13 @@ function event_change_shortname(&$page, $old, $new) $lastid = XDB::insertId(); XDB::execute( - "INSERT INTO virtual_redirect ( + "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 = {?} + WHERE ep.eid = {?} AND ep.nb > 0 GROUP BY ep.uid)", $lastid, '@'.$globals->mail->domain, $eid); @@ -295,14 +326,14 @@ function event_change_shortname(&$page, $old, $new) $lastid = XDB::insertId(); XDB::execute("INSERT INTO virtual_redirect ( - SELECT {?} AS vid, IF(u.nom IS NULL, m.email, CONCAT(a.alias, {?})) AS 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) + 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, $globals->asso('id')); + $lastid, "@".$globals->mail->domain, $eid, $globals->asso('id')); return $new; } @@ -322,6 +353,32 @@ function event_change_shortname(&$page, $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: ?>