From 4f10a0584b9a24af98c39de0919c9a007963be9b Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Sat, 15 Jul 2006 14:57:09 +0000 Subject: [PATCH] migrate evenements.php (partially I guess) and csv export git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@502 839d8a87-29fc-0310-9880-83ba4fa771e5 --- htdocs.net/groupe/evenements.php | 163 --------------------------- htdocs.net/groupe/evt-csv.php | 53 --------- htdocs.net/index.php | 2 +- include/xnet/page.inc.php | 2 +- modules/xnetevents.php | 210 +++++++++++++++++++++++++++++++++++ templates/xnet/groupe/evenements.tpl | 2 +- templates/xnet/groupe/evt-admin.tpl | 4 +- 7 files changed, 215 insertions(+), 221 deletions(-) delete mode 100644 htdocs.net/groupe/evenements.php delete mode 100644 htdocs.net/groupe/evt-csv.php create mode 100644 modules/xnetevents.php diff --git a/htdocs.net/groupe/evenements.php b/htdocs.net/groupe/evenements.php deleted file mode 100644 index 6495182..0000000 --- a/htdocs.net/groupe/evenements.php +++ /dev/null @@ -1,163 +0,0 @@ -xdb->query(" - SELECT deadline_inscription, - LEFT(NOW(), 10) AS now, - noinvite, - membres_only - FROM groupex.evenements - WHERE eid = {?}", $eid); - $e = $res->fetchOneAssoc(); - // impossible to change inscription: either inscription closed or members only - if ($e['deadline_inscription'] && $e['deadline_inscription']<$e['now']) - { - $page->trig("Les inscriptions sont closes"); - continue; - } - - if ($e['membres_only'] && !is_member()) - { - $page->trig("Les inscriptions à cet événement ne sont pas publiques"); - continue; - } - - // impossible to unsubscribe if you already paid sthing - $total_inscr = 0; - $inscriptions = array(); - for ($j=1; Env::has('moment'.$eid.'_'.$j); $j++) - { - $inscriptions[$j] = Env::get('moment'.$eid.'_'.$j); - // retreive ohter field when more than one person - if ($inscriptions[$j] == 2) - $inscriptions[$j] = 1 + Env::get('personnes'.$eid.'_'.$j,0); - // avoid negative count if other field incorrect - if ($inscriptions[$j] < 0) - $inscriptions[$j] = 0; - // avoid floating count if other field incorrect - $inscriptions[$j] = floor($inscriptions[$j]); - // avoid invite if no invite allowed - if ($inscriptions[$j] > 1 && $e['noinvite']) - $inscriptions[$j] = 1; - $total_inscr += $inscriptions[$j]; - } - $unsubscribing = ($total_inscr == 0); - - // retreive the amount already paid for this event in cash - $res = $globals->xdb->query(" - SELECT paid - FROM groupex.evenements_participants - WHERE eid = {?} AND uid = {?} - LIMIT 1", - $eid, Session::get("uid")); - $paid = $res->fetchOneCell(); - if (!$paid) $paid = 0; - - if ($unsubscribing && $paid != 0) - { - $page->trig("Impossible de te désinscrire complètement parce que tu as fait un paiement par chèque ou par liquide. Contacte un administrateur du groupe si tu es sûr de ne pas venir"); - continue; - } - - // update actual inscriptions - foreach ($inscriptions as $j=>$nb) - { - if ($nb > 0) - { - $globals->xdb->execute( - "REPLACE INTO groupex.evenements_participants - VALUES ({?}, {?}, {?}, {?}, {?})", - $eid, Session::get("uid"), $j, $nb, $paid); - } - else - { - $globals->xdb->execute( - "DELETE FROM groupex.evenements_participants - WHERE eid = {?} AND uid = {?} AND item_id = {?}", - $eid, Session::get("uid"), $j); - } - } - } -} - -/**** retreive all infos about all events ****/ -$page->assign('logged', logged()); -$page->assign('admin', may_update()); - -$evenements = $globals->xdb->iterator( -"SELECT e.eid, - IF(e.intitule = '', ' ', e.intitule) AS intitule, - IF(e.descriptif = '', ' ', e.descriptif) AS descriptif, - e.debut, e.fin, - LEFT(10,e.debut) AS debut_day, - LEFT(10,e.fin) AS fin_day, - e.paiement_id, e.membres_only, e.noinvite, - e.show_participants, u.nom, u.prenom, u.promo, a.alias, MAX(ep.nb) AS inscrit, - MAX(ep.paid) AS paid, - e.short_name, - IF(e.deadline_inscription,e.deadline_inscription >= LEFT(NOW(), 10), 1) AS inscr_open, e.deadline_inscription - FROM groupex.evenements AS e -INNER JOIN x4dat.auth_user_md5 AS u ON u.user_id = e.organisateur_uid - LEFT JOIN x4dat.aliases AS a ON (a.type = 'a_vie' AND a.id = u.user_id) - LEFT JOIN groupex.evenements_participants AS ep ON (ep.eid = e.eid AND ep.uid = {?}) - WHERE asso_id = {?} - GROUP BY e.eid - ORDER BY debut",Session::get('uid'),$globals->asso('id')); - -$evts = array(); -while ($e = $evenements->next()) -{ - $e['moments'] = $globals->xdb->iterator( - "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'), $e['eid']); - $query = $globals->xdb->query( - "SELECT montant - FROM {$globals->money->mpay_tprefix}transactions AS t - WHERE ref = {?} AND uid = {?}", $e['paiement_id'], Session::get('uid')); - $montants = $query->fetchColumn(); - foreach ($montants as $m) { - $p = strtr(substr($m, 0, strpos($m, "EUR")), ",", "."); - $e['paid'] += trim($p); - } - $evts[] = $e; -} - -$page->assign('evenements', $evts); -$page->assign('is_member', is_member()); - -$page->assign('nb_evt', $evenements->total()); - -$page->run(); - -?> diff --git a/htdocs.net/groupe/evt-csv.php b/htdocs.net/groupe/evt-csv.php deleted file mode 100644 index 02ffa40..0000000 --- a/htdocs.net/groupe/evt-csv.php +++ /dev/null @@ -1,53 +0,0 @@ -"", u.nom_usage, u.nom)) LIKE "'.addslashes(Env::get('initiale')).'%"' : ''; - - $participants = get_event_participants(Env::get('eid'), Env::get('item_id'), $ini, $tri, "", $evt['money'] && $admin, $evt['paiement_id']); - - $page->assign('participants', $participants); - $page->assign('admin', $admin); - $page->assign('moments', $evt['moments']); - $page->assign('money', $evt['money']); - $page->assign('tout', !Env::get('item_id', false)); -} - -$page->run(); - -// vim:set et sw=4 sts=4 sws=4 foldmethod=marker: -?> diff --git a/htdocs.net/index.php b/htdocs.net/index.php index cf5079d..a3896b6 100644 --- a/htdocs.net/index.php +++ b/htdocs.net/index.php @@ -24,7 +24,7 @@ require 'xnet.inc.php'; require_once dirname(__FILE__).'/../classes/Xnet.php'; require_once dirname(__FILE__).'/../classes/PLModule.php'; -$platal = new Xnet('xnet', 'xnetgrp', 'xnetlists'); +$platal = new Xnet('xnet', 'xnetgrp', 'xnetlists', 'xnetevents'); $platal->run(); ?> diff --git a/include/xnet/page.inc.php b/include/xnet/page.inc.php index 597219a..b150c37 100644 --- a/include/xnet/page.inc.php +++ b/include/xnet/page.inc.php @@ -81,7 +81,7 @@ class XnetPage extends PlatalPage if ($globals->asso('mail_domain')) { $sub['listes de diffusion'] = "$dim/lists"; } - $sub['événement'] = "$dim/evenements.php"; + $sub['événement'] = "$dim/events"; if (false) { $sub['carnet'] = "$dim/carnet.php"; } diff --git a/modules/xnetevents.php b/modules/xnetevents.php new file mode 100644 index 0000000..460bedb --- /dev/null +++ b/modules/xnetevents.php @@ -0,0 +1,210 @@ + $this->make_hook('events', AUTH_MDP), + 'grp/events/csv' => $this->make_hook('csv', AUTH_MDP), + ); + } + + function handler_events(&$page) + { + global $globals; + + new_group_page('xnet/groupe/evenements.tpl'); + + /**** manage inscriptions ****/ + // inscription to events + if (Env::has('ins')) { + for ($i=1; Env::has('evt_'.$i); $i++) { + $eid = Env::get('evt_'.$i); + $res = $globals->xdb->query(" + SELECT deadline_inscription, + LEFT(NOW(), 10) AS now, + noinvite, + membres_only + FROM groupex.evenements + WHERE eid = {?}", $eid); + $e = $res->fetchOneAssoc(); + // impossible to change inscription: either inscription closed or members only + if ($e['deadline_inscription'] && $e['deadline_inscription'] < $e['now']) + { + $page->trig("Les inscriptions sont closes"); + continue; + } + + if ($e['membres_only'] && !is_member()) + { + $page->trig("Les inscriptions à cet événement ne sont pas publiques"); + continue; + } + + // impossible to unsubscribe if you already paid sthing + $total_inscr = 0; + $inscriptions = array(); + for ($j=1; Env::has('moment'.$eid.'_'.$j); $j++) + { + $inscriptions[$j] = Env::get('moment'.$eid.'_'.$j); + // retreive ohter field when more than one person + if ($inscriptions[$j] == 2) + $inscriptions[$j] = 1 + Env::get('personnes'.$eid.'_'.$j,0); + // avoid negative count if other field incorrect + if ($inscriptions[$j] < 0) + $inscriptions[$j] = 0; + // avoid floating count if other field incorrect + $inscriptions[$j] = floor($inscriptions[$j]); + // avoid invite if no invite allowed + if ($inscriptions[$j] > 1 && $e['noinvite']) + $inscriptions[$j] = 1; + $total_inscr += $inscriptions[$j]; + } + $unsubscribing = ($total_inscr == 0); + + // retreive the amount already paid for this event in cash + $res = $globals->xdb->query(" + SELECT paid + FROM groupex.evenements_participants + WHERE eid = {?} AND uid = {?} + LIMIT 1", + $eid, Session::get("uid")); + $paid = $res->fetchOneCell(); + if (!$paid) $paid = 0; + + if ($unsubscribing && $paid != 0) { + $page->trig("Impossible de te désinscrire complètement ". + "parce que tu as fait un paiement par ". + "chèque ou par liquide. Contacte un ". + "administrateur du groupe si tu es sûr de ". + "ne pas venir"); + continue; + } + + // update actual inscriptions + foreach ($inscriptions as $j=>$nb) { + if ($nb > 0) { + $globals->xdb->execute( + "REPLACE INTO groupex.evenements_participants + VALUES ({?}, {?}, {?}, {?}, {?})", + $eid, Session::get("uid"), $j, $nb, $paid); + } else { + $globals->xdb->execute( + "DELETE FROM groupex.evenements_participants + WHERE eid = {?} AND uid = {?} AND item_id = {?}", + $eid, Session::get("uid"), $j); + } + } + } + } + + /**** retreive all infos about all events ****/ + $page->assign('logged', logged()); + $page->assign('admin', may_update()); + + $evenements = $globals->xdb->iterator( + "SELECT e.eid, + IF(e.intitule = '', ' ', e.intitule) AS intitule, + IF(e.descriptif = '', ' ', e.descriptif) AS descriptif, + e.debut, e.fin, + LEFT(10,e.debut) AS debut_day, + LEFT(10,e.fin) AS fin_day, + e.paiement_id, e.membres_only, e.noinvite, + e.show_participants, u.nom, u.prenom, u.promo, a.alias, MAX(ep.nb) AS inscrit, + MAX(ep.paid) AS paid, + e.short_name, + IF(e.deadline_inscription, e.deadline_inscription >= LEFT(NOW(), 10), + 1) AS inscr_open, e.deadline_inscription + FROM groupex.evenements AS e + INNER JOIN x4dat.auth_user_md5 AS u ON u.user_id = e.organisateur_uid + LEFT JOIN x4dat.aliases AS a ON (a.type = 'a_vie' AND a.id = u.user_id) + LEFT JOIN groupex.evenements_participants AS ep ON (ep.eid = e.eid AND ep.uid = {?}) + WHERE asso_id = {?} + GROUP BY e.eid + ORDER BY debut",Session::get('uid'),$globals->asso('id')); + + $evts = array(); + while ($e = $evenements->next()) { + $e['moments'] = $globals->xdb->iterator( + "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'), $e['eid']); + $query = $globals->xdb->query( + "SELECT montant + FROM {$globals->money->mpay_tprefix}transactions AS t + WHERE ref = {?} AND uid = {?}", $e['paiement_id'], Session::get('uid')); + $montants = $query->fetchColumn(); + foreach ($montants as $m) { + $p = strtr(substr($m, 0, strpos($m, "EUR")), ",", "."); + $e['paid'] += trim($p); + } + $evts[] = $e; + } + + $page->assign('evenements', $evts); + $page->assign('is_member', is_member()); + } + + function handler_csv(&$page, $eid = null, $item_id = null) + { + require_once('xnet/evenements.php'); + + $evt = get_event_detail($eid, $item_id); + if (!$evt) { + return PL_NOT_FOUND; + } + + header('Content-type: text/x-csv'); + header('Pragma: '); + header('Cache-Control: '); + + new_nonhtml_page('xnet/groupe/evt-csv.tpl'); + + $admin = may_update(); + + $tri = (Env::get('order') == 'alpha' ? 'promo, nom, prenom' : 'nom, prenom, promo'); + + if (Env::has('initiale')) { + $ini = 'AND IF(u.nom IS NULL, m.nom, + IF(u.nom_usage<>"", u.nom_usage, u.nom)) + LIKE "'.addslashes(Env::get('initiale')).'%"'; + } else { + $ini = ''; + } + + $participants = get_event_participants($eid, $item_id, $ini, $tri, "", + $evt['money'] && $admin, + $evt['paiement_id']); + + $page->assign('participants', $participants); + $page->assign('admin', $admin); + $page->assign('moments', $evt['moments']); + $page->assign('money', $evt['money']); + $page->assign('tout', !Env::get('item_id', false)); + } +} + +?> diff --git a/templates/xnet/groupe/evenements.tpl b/templates/xnet/groupe/evenements.tpl index de67a5d..96f3832 100644 --- a/templates/xnet/groupe/evenements.tpl +++ b/templates/xnet/groupe/evenements.tpl @@ -44,7 +44,7 @@ Ev {else} -
+ {foreach from=$evenements item=e} diff --git a/templates/xnet/groupe/evt-admin.tpl b/templates/xnet/groupe/evt-admin.tpl index 502561b..5d970df 100644 --- a/templates/xnet/groupe/evt-admin.tpl +++ b/templates/xnet/groupe/evt-admin.tpl @@ -20,7 +20,7 @@ {* *} {**************************************************************************} -

{$asso.nom} : Evénements

+

{$asso.nom} : Evénements

L'événement {$evt.intitule} {if $evt.titre} - {$evt.titre}{/if} comptera {$evt.nb_tot} personne{if $evt.nb_tot > 1}s{/if}. @@ -163,7 +163,7 @@ Ils ont pay {if $admin}

-[Télécharger le fichier Excel] +[Télécharger le fichier Excel]


-- 2.1.4