Unifies excel files handling.
authorStéphane Jacob <sj@m4x.org>
Sun, 6 Nov 2011 17:10:15 +0000 (18:10 +0100)
committerStéphane Jacob <sj@m4x.org>
Sun, 6 Nov 2011 17:10:15 +0000 (18:10 +0100)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
modules/payment.php
modules/xnetevents.php
modules/xnetgrp.php
templates/payment/xnet.tpl
templates/xnetevents/admin.tpl
templates/xnetevents/csv.tpl [deleted file]
templates/xnetgrp/annuaire-csv.tpl [deleted file]
templates/xnetgrp/annuaire.tpl

index 4a28ef3..c338852 100644 (file)
@@ -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;
index 3dbe0c6..0dc18e3 100644 (file)
@@ -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)
index 2d523ee..47f4a8d 100644 (file)
@@ -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)
index 1ab4219..1545a83 100644 (file)
@@ -82,6 +82,7 @@ il suffit de cliquer sur le titre de la colonne concernée.
 <p>
   Liste des personnes ayant payé (pour les administrateurs uniquement)&nbsp;:<br />
   <a href="{$platal->ns}payment/csv/{$p.id}.csv">{icon name=page_excel title="Fichier Excel"} Obtenir au format Excel</a>
+  <small>(encodage&nbsp;: iso-8859-1, séparateur&nbsp;: point-virgule)</small>
 </p>
 <table cellpadding="0" cellspacing="0" id="list_{$p.id}" class='bicol'>
   <tr>
index 551fa14..f9ae819 100644 (file)
@@ -228,6 +228,7 @@ Ils ont payé mais ont oublié de s'inscrire&nbsp;:
   <a href="{$platal->ns}events/csv/{$evt.eid}/{$platal->argv[2]}/{$evt.intitule|escape:url}{if $evt.titre}.{$evt.titre|escape:url}{/if}.csv">
     {icon name=page_excel title="Télécharger au format Excel"} Télécharger le fichier Excel
   </a>
+  <small>(encodage&nbsp;: iso-8859-1, séparateur&nbsp;: point-virgule)</small>
 </p>
 
 <hr />
diff --git a/templates/xnetevents/csv.tpl b/templates/xnetevents/csv.tpl
deleted file mode 100644 (file)
index 7a52462..0000000
+++ /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 (file)
index 75a8c8b..0000000
+++ /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: *}
index 9c5c4fe..bdd9cd1 100644 (file)
@@ -68,6 +68,7 @@ Le groupe {$asso->nom} compte {$plset_total_count} membres&nbsp;:
       {icon name=page_excel title="Fichier Excel"}
       Obtenir au format Excel
     </a>
+    <small>(encodage&nbsp;: iso-8859-1, séparateur&nbsp;: point-virgule)</small>
   </li>
   <li>
     <a href="{$platal->ns}annuaire/vcard/photos/{$asso->diminutif}.vcf">