From: x2000habouzit Date: Sat, 15 Jul 2006 23:11:07 +0000 (+0000) Subject: clean admin code. X-Git-Tag: xorg/0.9.11~389 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=ed21e24a99eb61c529abadec68cde74de71ce54f;p=platal.git clean admin code. make old include/xnet/evenements.php a private include. git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@513 839d8a87-29fc-0310-9880-83ba4fa771e5 --- diff --git a/modules/xnetevents.php b/modules/xnetevents.php index b65342a..db1f4d5 100644 --- a/modules/xnetevents.php +++ b/modules/xnetevents.php @@ -19,6 +19,8 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ +define('NB_PER_PAGE', 25); + class XnetEventsModule extends PLModule { function handlers() @@ -138,7 +140,7 @@ class XnetEventsModule extends PLModule { global $globals; - require_once('xnet/evenements.php'); + require_once dirname(__FILE__).'/xnetevents/xnetevents.php'; new_group_page('xnetevents/subscribe.tpl'); @@ -206,7 +208,7 @@ class XnetEventsModule extends PLModule function handler_csv(&$page, $eid = null, $item_id = null) { - require_once('xnet/evenements.php'); + require_once dirname(__FILE__).'/xnetevents/xnetevents.php'; if (!is_numeric($item_id)) { $item_id = null; @@ -227,19 +229,9 @@ class XnetEventsModule extends PLModule $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', + get_event_participants($evt, $item_id, $tri)); - $page->assign('participants', $participants); $page->assign('admin', $admin); $page->assign('moments', $evt['moments']); $page->assign('money', $evt['money']); @@ -477,100 +469,93 @@ class XnetEventsModule extends PLModule { global $globals; - define('NB_PER_PAGE', 25); - - require_once('xnet/evenements.php'); + require_once dirname(__FILE__).'/xnetevents/xnetevents.php'; $evt = get_event_detail($eid, $item_id); - - // the event doesn't exist or doesn't belong to this assoif (!$evt) if (!$evt) { return PL_NOT_FOUND; } if ($evt['show_participants']) { - new_group_page('xnet/groupe/evt-admin.tpl'); + new_group_page('xnetevents/admin.tpl'); } else { - new_groupadmin_page('xnet/groupe/evt-admin.tpl'); + new_groupadmin_page('xnetevents/admin.tpl'); } - $admin = may_update(); - - // select a member from his mail - if ($admin && Env::get('adm') && Env::get('mail')) { - if (strpos(Env::get('mail'), '@') === false) { - $res = $globals->xdb->query( - "SELECT m.uid - FROM groupex.membres AS m - INNER JOIN aliases AS a ON (a.id = m.uid) - WHERE a.alias = {?} AND m.asso_id = {?}", - Env::get('mail'), $globals->asso('id')); - } else { - $res = $globals->xdb->query( - "SELECT m.uid - FROM groupex.membres AS m - WHERE m.email = {?} AND m.asso_id = {?}", - Env::get('mail'), $globals->asso('id')); + if (may_update() && Post::get('adm')) { + $member = get_infos(Post::get('mail')); + if (!$member) { + $page->trig("Membre introuvable"); } - $member = $res->fetchOneCell(); - if (!$member) $page->trig("Membre introuvable"); - } - // change the price paid by a participant - if ($admin && Env::get('adm') == 'prix' && $member) { - $globals->xdb->execute("UPDATE groupex.evenements_participants SET paid = IF(paid + {?} > 0, paid + {?}, 0) WHERE uid = {?} AND eid = {?}", + // change the price paid by a participant + if (Env::get('adm') == 'prix' && $member) { + $globals->xdb->execute("UPDATE groupex.evenements_participants + SET paid = IF(paid + {?} > 0, paid + {?}, 0) + WHERE uid = {?} AND eid = {?}", strtr(Env::get('montant'), ',', '.'), strtr(Env::get('montant'), ',', '.'), - $member, Env::get('eid')); - } + $member['uid'], $eid); + } - // change the number of personns coming with a participant - if ($admin && Env::get('adm') == 'nbs' && $member) { - $res = $globals->xdb->query("SELECT paid FROM groupex.evenements_participants WHERE uid = {?} AND eid = {?}", $member, Env::get('eid')); - $paid = $res->fetchOneCell(); - $participate = false; - foreach ($evt['moments'] as $m) if (Env::has('nb'.$m['item_id'])) { - $nb = Env::getInt('nb'.$m['item_id'], 0); - if ($nb < 0) $nb = 0; - if ($nb) { - $participate = true; - if (!$paid) $paid = 0; - $globals->xdb->execute("REPLACE INTO groupex.evenements_participants VALUES ({?}, {?}, {?}, {?}, {?})", - Env::get('eid'), $member, $m['item_id'], $nb, $paid); - } else { - $globals->xdb->execute("DELETE FROM groupex.evenements_participants WHERE uid = {?} AND eid = {?} AND item_id = {?}", $member, Env::get('eid'), $m['item_id']); + // change the number of personns coming with a participant + if (Env::get('adm') == 'nbs' && $member) { + $res = $globals->xdb->query("SELECT paid + FROM groupex.evenements_participants + WHERE uid = {?} AND eid = {?}", + $member['uid'], $eid); + + $paid = intval($res->fetchOneCell()); + $nbs = Post::getMixed('nb', array()); + + foreach ($nbs as $id => $nb) { + $nb = intval($nb); + + if ($nb < 0) { + $nb = 0; + } + + if ($nb) { + $globals->xdb->execute("REPLACE INTO groupex.evenements_participants + VALUES ({?}, {?}, {?}, {?}, {?})", + $eid, $member['uid'], $id, $nb, $paid); + } else { + $globals->xdb->execute("DELETE FROM groupex.evenements_participants + WHERE uid = {?} AND eid = {?} AND item_id = {?}", + $member['uid'], $eid, $id); + } } - } - if ($participate) { - subscribe_lists_event(true, $member, $evt['participant_list'], $evt['absent_list']); - } else { - $res = $globals->xdb->query( - "SELECT uid FROM groupex.evenements_participants - WHERE uid = {?} AND eid = {?}", $member, $eid); + + $res = $globals->xdb->query("SELECT uid FROM groupex.evenements_participants + WHERE uid = {?} AND eid = {?}", + $member['uid'], $eid); $u = $res->fetchOneCell(); - subscribe_lists_event($u, $member, $evt['participant_list'], $evt['absent_list']); + subscribe_lists_event($u, $member['uid'], $evt); } + $evt = get_event_detail($eid, $item_id); } - $page->assign('admin', $admin); + $page->assign('admin', may_update()); $page->assign('evt', $evt); - $page->assign('url_page', Env::get('PHP_SELF')."?eid=".Env::get('eid').(Env::has('item_id')?("&item_id=".Env::getInt('item_id')):'')); $page->assign('tout', !Env::has('item_id')); - if (count($evt['moments'])) $page->assign('moments', $evt['moments']); - $page->assign('money', $evt['money']); + if (count($evt['moments'])) { + $page->assign('moments', $evt['moments']); + } $tri = (Env::get('order') == 'alpha' ? 'promo, nom, prenom' : 'nom, prenom, promo'); $whereitemid = Env::has('item_id')?('AND ep.item_id = '.Env::getInt('item_id', 1)):''; $res = $globals->xdb->iterRow( - 'SELECT UPPER(SUBSTRING(IF(u.nom IS NULL,m.nom,IF(u.nom_usage<>"", u.nom_usage, u.nom)), 1, 1)), COUNT(DISTINCT ep.uid) + 'SELECT UPPER(SUBSTRING(IF(u.nom IS NULL, m.nom, + IF(u.nom_usage<>"", u.nom_usage, u.nom)), 1, 1)), + COUNT(DISTINCT ep.uid) 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 ) WHERE ep.eid = {?} '.$whereitemid.' - GROUP BY UPPER(SUBSTRING(IF(u.nom IS NULL,m.nom,u.nom), 1, 1))', Env::get('eid')); + GROUP BY UPPER(SUBSTRING(IF(u.nom IS NULL,m.nom,u.nom), 1, 1))', $eid); $alphabet = array(); $nb_tot = 0; @@ -601,12 +586,8 @@ class XnetEventsModule extends PLModule $page->assign('links', $links); } - $ini = Env::has('initiale') ? 'AND IF(u.nom IS NULL,m.nom,IF(u.nom_usage<>"", u.nom_usage, u.nom)) LIKE "'.addslashes(Env::get('initiale')).'%"' : ''; - - $participants = get_event_participants(Env::get('eid'), Env::get('item_id'), $ini, $tri, "LIMIT ".($ofs*NB_PER_PAGE).", ".NB_PER_PAGE, $evt['money'] && $admin, $evt['paiement_id']); - if ($evt['paiement_id']) { - $res = $globals->xdb->iterator( + $res = $globals->xdb->iterator( "SELECT IF(u.nom_usage<>'', u.nom_usage, u.nom) AS nom, u.prenom, u.promo, a.alias AS email, t.montant FROM {$globals->money->mpay_tprefix}transactions AS t @@ -615,11 +596,13 @@ class XnetEventsModule extends PLModule LEFT JOIN groupex.evenements_participants AS ep ON(ep.uid = t.uid AND ep.eid = {?}) WHERE t.ref = {?} AND ep.uid IS NULL", $evt['eid'], $evt['paiement_id']); - $page->assign('oublis', $res->total()); - $page->assign('oubliinscription', $res); + $page->assign('oublis', $res->total()); + $page->assign('oubliinscription', $res); } - $page->assign('participants', $participants); + $page->assign('participants', + get_event_participants($evt, $item_id, $tri, + "LIMIT ".($ofs*NB_PER_PAGE).", ".NB_PER_PAGE)); } } diff --git a/include/xnet/evenements.php b/modules/xnetevents/xnetevents.php similarity index 90% rename from include/xnet/evenements.php rename to modules/xnetevents/xnetevents.php index 732f21c..c0e3bd7 100644 --- a/include/xnet/evenements.php +++ b/modules/xnetevents/xnetevents.php @@ -99,8 +99,21 @@ function get_event_detail($eid, $item_id = false) // }}} // {{{ function get_event_participants() -function get_event_participants($eid, $item_id, $where, $tri, $limit, $money, $pay_id) { +function get_event_participants($evt, $item_id, $tri, $limit = '') { global $globals; + + 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')).'%"'; + } else { + $where = ''; + } + + $eid = $evt['eid']; + $money = $evt['money'] && may_update(); + $pay_id = $evt['paiement_id']; + $query = "SELECT IF(u.nom IS NULL,m.nom,IF(u.nom_usage<>'', u.nom_usage, u.nom)) AS nom, IF(u.nom IS NULL,m.prenom,u.prenom) AS prenom, @@ -119,15 +132,17 @@ function get_event_participants($eid, $item_id, $where, $tri, $limit, $money, $p ".(($item_id)?" AND item_id = $item_id":"")." $where GROUP BY ep.uid - ORDER BY $tri - $limit"; + ORDER BY $tri $limit"; + if ($item_id) { $res = $globals->xdb->query($query, $eid); return $res->fetchAllAssoc(); } + $res = $globals->xdb->iterator($query, $eid); $tab = array(); $user = 0; + while ($u = $res->next()) { $u['montant'] = 0; if ($money && $pay_id) { @@ -159,9 +174,12 @@ function get_event_participants($eid, $item_id, $where, $tri, $limit, $money, $p // }}} // {{{ function subscribe_lists_event() -function subscribe_lists_event($participate, $uid, $participant_list, $absent_list) { +function subscribe_lists_event($participate, $uid, $evt) { global $globals,$page; - + + $participant_list = $evt['participant_list']; + $absent_list = $evt['absent_list']; + $email = Session::get('forlife'); if ($email) { @@ -171,8 +189,8 @@ function subscribe_lists_event($participate, $uid, $participant_list, $absent_li $email = $res->fetchOneCell(); } - $subscribe = $participate?$participant_list:(is_member()?$absent_list:0); - $unsubscri = $participate?$absent_list:$participant_list; + $subscribe = $participate ? $participant_list : (is_member()?$absent_list:0); + $unsubscri = $participate ? $absent_list : $participant_list; if ($subscribe) { $globals->xdb->execute( diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index 2c8a39b..94b935e 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -23,7 +23,7 @@ function get_infos($email) { global $globals; // look for uid instead of email if numeric - $field = is_numeric($email)?'uid':'email'; + $field = is_numeric($email) ? 'uid' : 'email'; if ($field == 'email') { $email = strtolower($email); @@ -588,10 +588,10 @@ class XnetGrpModule extends PLModule if ($forlife = get_user_forlife($email)) { $globals->xdb->execute( 'INSERT INTO groupex.membres (uid,asso_id,origine) - SELECT user_id,{?},"X" - FROM auth_user_md5 AS u - INNER JOIN aliases AS a ON (u.user_id = a.id) - WHERE a.alias={?}', $globals->asso('id'), $forlife); + SELECT user_id,{?},"X" + FROM auth_user_md5 AS u + INNER JOIN aliases AS a ON (u.user_id = a.id) + WHERE a.alias={?}', $globals->asso('id'), $forlife); global $platal; redirect(smarty_function_rel()."/{$platal->ns}member/$email"); } else { diff --git a/templates/xnet/groupe/evt-admin.tpl b/templates/xnetevents/admin.tpl similarity index 76% rename from templates/xnet/groupe/evt-admin.tpl rename to templates/xnetevents/admin.tpl index 2e5d3d9..5f4d85a 100644 --- a/templates/xnet/groupe/evt-admin.tpl +++ b/templates/xnetevents/admin.tpl @@ -23,7 +23,8 @@

{$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}. +L'événement {$evt.intitule} {if $evt.titre} - {$evt.titre}{/if} comptera +{$evt.nb_tot} personne{if $evt.nb_tot > 1}s{/if}.

{if $evt.participant_list} @@ -36,17 +37,17 @@ L' {if $moments}

-[argv[2]}class="erreur"{/if}>tout] +[argv[2]}class="erreur"{/if}>tout] {foreach from=$moments item=m} -[argv[2] eq $m.item_id}class="erreur"{/if}>{$m.titre}] +[argv[2] eq $m.item_id}class="erreur"{/if}>{$m.titre}] {/foreach}

{/if}

-[tout] +[tout] {foreach from=$alphabet item=c} -[{$c}] +[{$c}] {/foreach}

@@ -108,7 +109,7 @@ Ils ont pay {else} Nombre {/if} - {if $admin && $money} + {if $admin && $evt.money} Montant Payé {/if} @@ -117,7 +118,7 @@ Ils ont pay {/if} {foreach from=$participants item=m} - + {if $m.femme}•{/if}{$m.prenom} {$m.nom} @@ -141,7 +142,7 @@ Ils ont pay {else} {$m[1]} {/if} - {if $admin && $money} + {if $admin && $evt.money} $m.paid}class="erreur"{/if}>{$m.montant}€ {$m.paid}€ {/if} @@ -156,46 +157,44 @@ Ils ont pay

{foreach from=$links item=ofs key=txt} -{$txt} +{$txt} {/foreach}

{if $admin}

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


En tant qu'administrateur, tu peux fixer la venue (accompagnée ou pas) d'un des membres du groupe. -Donne ici son mail (complet pour les extérieurs, sans @polytechnique.org pour les X), ainsi que le -nombre de participants. +Donne ici son mail, ainsi que le nombre de participants.

-
+

- - + - Mail: - {if $platal->argv[2]} - - {$evt.titre}: - {else} - {if $moments} - {foreach from=$moments item=m} - {$m.titre}: - {/foreach} + Mail: + + {if $platal->argv[2]} + {$evt.titre}: {else} - Nombre: + {foreach from=$moments item=m} + {$m.titre}: + {foreachelse} + Nombre: + {/foreach} {/if} - {/if} - +

+{if $evt.money} +

@@ -208,9 +207,8 @@ entrer un montant n Note que tu peux cliquer sur les noms des membres pour remplir automatiquement la case ci-dessous

-
+

- Mail: montant: € @@ -219,4 +217,6 @@ Note que tu peux cliquer sur les noms des membres pour remplir automatiquement l

{/if} +{/if} + {* vim:set et sw=2 sts=2 sws=2: *}