From: Stéphane Jacob Date: Sun, 6 Nov 2011 17:10:15 +0000 (+0100) Subject: Unifies excel files handling. X-Git-Tag: xorg/1.1.4~20 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=ee923b43a6a0dd1e1418c7c262065d7519933f73;p=platal.git Unifies excel files handling. Signed-off-by: Stéphane Jacob --- diff --git a/modules/payment.php b/modules/payment.php index 4a28ef3..c338852 100644 --- a/modules/payment.php +++ b/modules/payment.php @@ -545,17 +545,17 @@ class PaymentModule extends PLModule $users = User::getBulkUsersWithUIDs($res, 'uid', 'user'); $sum = 0; - pl_cached_content_headers('text/x-csv', 1); + pl_cached_content_headers('text/x-csv', 'iso-8859-1', 1); $csv = fopen('php://output', 'w'); - fputcsv($csv, array('Date', 'Nom', 'Prénom', 'Sexe', 'Promotion', 'Email', 'Commentaire', 'Montant'), ';'); + fputcsv($csv, array('Date', 'Nom', utf8_decode('Prénom'), 'Sexe', 'Promotion', 'Email', 'Commentaire', 'Montant'), ';'); foreach ($users as $item) { $user = $item['user']; $sum += $item['amount']; - fputcsv($csv, array(format_datetime($item['date'], '%d/%m/%y'), $user->lastName(), $user->firstName(), + fputcsv($csv, array(format_datetime($item['date'], '%d/%m/%y'), utf8_decode($user->lastName()), utf8_decode($user->firstName()), ($user->isFemale()) ? 'F' : 'M', $user->promo(), $user->ForlifeEmail(), - $item['comment'], strtr($item['amount'],'.',',').' €' ), ';'); + utf8_decode($item['comment']), strtr($item['amount'], '.', ',') . ' EUR' ), ';'); } - fputcsv($csv, array(date('d/m/y'), 'Total', '', '', '' , '', '', strtr($sum,'.',',').' €'), ';'); + fputcsv($csv, array(date('d/m/y'), 'Total', '', '', '' , '', '', strtr($sum, '.', ',') . ' EUR'), ';'); fclose($csv); exit; diff --git a/modules/xnetevents.php b/modules/xnetevents.php index 3dbe0c6..0dc18e3 100644 --- a/modules/xnetevents.php +++ b/modules/xnetevents.php @@ -297,21 +297,54 @@ class XnetEventsModule extends PLModule return PL_NOT_FOUND; } - pl_cached_content_headers('text/x-csv', 1); + pl_cached_content_headers('text/x-csv', 'iso-8859-1', 1); $page->changeTpl('xnetevents/csv.tpl', NO_SKIN); $admin = may_update(); - $tri = (Env::v('order') == 'alpha' ? UserFilter::sortByPromo() : UserFilter::sortByName()); + $all = !Env::v('item_id', false); - $page->assign('participants', - get_event_participants($evt, $item_id, $tri)); + $participants = get_event_participants($evt, $item_id, $tri); + $title = 'Nom;Prénom;Promotion'; + if ($all) { + foreach ($evt['moments'] as $moment) { + $title .= ';' . $moment['titre']; + } + } + if ($admin && $evt['money']) { + $title .= ';À payer;'; + if ($evt['paiement_id']) { + $title .= 'Télépaiement;Liquide/Chèque;'; + } + $title .= 'Payé'; + } else { + $title .= ';Nombre'; + } + echo utf8_decode($title) . "\n"; + + if ($participants) { + foreach ($participants as $participant) { + $user = $participant['user']; + $line = $user->lastName() . ';' . $user->firstName() . ';' . $user->promo(); + if ($all) { + foreach ($evt['moments'] as $moment) { + $line .= ';' . $participant[$moment['item_id']]; + } + } + if ($admin && $evt['money']) { + $line .= ';' . $participant['montant'] . ';'; + if ($evt['paiement_id']) { + $line .= $participant['telepayment'] . ';' . $participant['adminpaid'] . ';'; + } + $line .= $participant['paid']; + } else { + $line .= ';' . $participant['nb']; + } - $page->assign('admin', $admin); - $page->assign('moments', $evt['moments']); - $page->assign('money', $evt['money']); - $page->assign('telepayment', $evt['paiement_id']); - $page->assign('tout', !Env::v('item_id', false)); + echo utf8_decode($line) . "\n"; + } + } + exit(); } function handler_ical($page, $eid = null) diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index 2d523ee..47f4a8d 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -452,9 +452,15 @@ class XnetGrpModule extends PLModule $filename = $globals->asso('diminutif') . '.csv'; } $users = $globals->asso()->getMembersFilter(null, new UFO_Name())->getUsers(); - pl_cached_content_headers('text/x-csv', 1); - $page->changeTpl('xnetgrp/annuaire-csv.tpl', NO_SKIN); - $page->assign('users', $users); + pl_cached_content_headers('text/x-csv', 'iso-8859-1', 1); + + echo utf8_decode("Nom;Prénom;Sexe;Promotion;Commentaire\n"); + foreach ($users as $user) { + $line = $user->lastName() . ';' . $user->firstName() . ';' . ($user->isFemale() ? 'F' : 'M') + . ';' . $user->promo() . ';' . strtr($user->group_comm, ';', ','); + echo utf8_decode($line) . "\n"; + } + exit(); } function handler_directory_sync($page) diff --git a/templates/payment/xnet.tpl b/templates/payment/xnet.tpl index 1ab4219..1545a83 100644 --- a/templates/payment/xnet.tpl +++ b/templates/payment/xnet.tpl @@ -82,6 +82,7 @@ il suffit de cliquer sur le titre de la colonne concernée.

Liste des personnes ayant payé (pour les administrateurs uniquement) :
{icon name=page_excel title="Fichier Excel"} Obtenir au format Excel + (encodage : iso-8859-1, séparateur : point-virgule)

diff --git a/templates/xnetevents/admin.tpl b/templates/xnetevents/admin.tpl index 551fa14..f9ae819 100644 --- a/templates/xnetevents/admin.tpl +++ b/templates/xnetevents/admin.tpl @@ -228,6 +228,7 @@ Ils ont payé mais ont oublié de s'inscrire : {icon name=page_excel title="Télécharger au format Excel"} Télécharger le fichier Excel + (encodage : iso-8859-1, séparateur : point-virgule)


diff --git a/templates/xnetevents/csv.tpl b/templates/xnetevents/csv.tpl deleted file mode 100644 index 7a52462..0000000 --- a/templates/xnetevents/csv.tpl +++ /dev/null @@ -1,35 +0,0 @@ -{**************************************************************************} -{* *} -{* Copyright (C) 2003-2011 Polytechnique.org *} -{* http://opensource.polytechnique.org/ *} -{* *} -{* This program is free software, you can redistribute it and/or modify *} -{* it under the terms of the GNU General Public License as published by *} -{* the Free Software Foundation, either version 2 of the License; or *} -{* (at your option) any later version. *} -{* *} -{* This program is distributed in the hope that it will be useful, *} -{* but WITHOUT ANY WARRANTY, without even the implied warranty of *} -{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *} -{* GNU General Public License for more details. *} -{* *} -{* You should have received a copy of the GNU General Public License *} -{* along with this program, if not; write to the Free Software *} -{* Foundation, Inc.; *} -{* 59 Temple Place, Suite 330; Boston, MA 02111-1307 USA *} -{* *} -{**************************************************************************} -Nom;Prénom;Promotion{if $tout}{foreach from=$moments item=m};{$m.titre}{/foreach}{if $admin && $money};À payer;{if -$telepayment}Télépaiement;Liquide/Chèque;{/if}Payé{/if}{else};Nombre{/if} - -{if $participants} -{foreach from=$participants item=m} - -; -{$m.user->lastName()};{$m.user->firstName()};{$m.user->promo()}{if $tout}{foreach from=$moments item=i};{$m[$i.item_id]}{/foreach}{if $admin && -$money};{$m.montant};{if $telepayment}{$m.telepayment};{$m.adminpaid};{/if}{$m.paid}{/if}{else};{$m.nb}{/if} - -{/foreach} -; -{/if} -{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/xnetgrp/annuaire-csv.tpl b/templates/xnetgrp/annuaire-csv.tpl deleted file mode 100644 index 75a8c8b..0000000 --- a/templates/xnetgrp/annuaire-csv.tpl +++ /dev/null @@ -1,30 +0,0 @@ -{**************************************************************************} -{* *} -{* Copyright (C) 2003-2011 Polytechnique.org *} -{* http://opensource.polytechnique.org/ *} -{* *} -{* This program is free software, you can redistribute it and/or modify *} -{* it under the terms of the GNU General Public License as published by *} -{* the Free Software Foundation, either version 2 of the License; or *} -{* (at your option) any later version. *} -{* *} -{* This program is distributed in the hope that it will be useful, *} -{* but WITHOUT ANY WARRANTY, without even the implied warranty of *} -{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *} -{* GNU General Public License for more details. *} -{* *} -{* You should have received a copy of the GNU General Public License *} -{* along with this program, if not; write to the Free Software *} -{* Foundation, Inc.; *} -{* 59 Temple Place, Suite 330; Boston, MA 02111-1307 USA *} -{* *} -{**************************************************************************} -Nom,Prénom,Sexe,Promotion,Commentaire -{if $users|@count} -{foreach from=$users item=user} - -{$user->lastName()},{$user->firstName()},{if $user->isFemale()}F{else}M{/if},{$user->promo()},{$user->group_comm|replace:',':'\,'} - -{/foreach} -{/if} -{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/xnetgrp/annuaire.tpl b/templates/xnetgrp/annuaire.tpl index 9c5c4fe..bdd9cd1 100644 --- a/templates/xnetgrp/annuaire.tpl +++ b/templates/xnetgrp/annuaire.tpl @@ -68,6 +68,7 @@ Le groupe {$asso->nom} compte {$plset_total_count} membres : {icon name=page_excel title="Fichier Excel"} Obtenir au format Excel + (encodage : iso-8859-1, séparateur : point-virgule)