Overview
SHA1:b0c5c88ec9994b93538307e8dd19c04f65055f14
Date: 2018-06-24 01:23:18
User: bohwaz
Comment:Export CSV adapté à Excel, car c'est un logiciel de m****
Timelines: family | ancestors | descendants | both | trunk | stable
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2018-07-05
14:33
[6dfbdc5d58] Inclure le nom du plugin dans le message d'erreur (user: bohwaz, tags: trunk, stable)
2018-06-24
01:23
[b0c5c88ec9] Export CSV adapté à Excel, car c'est un logiciel de m**** (user: bohwaz, tags: trunk, stable)
2018-06-22
00:57
[6782dad4bf] Amélioration galerie dynamique (user: bohwaz, tags: trunk, stable)
Changes

Modified src/include/lib/Garradin/Membres/Import.php from [abd6fb1bd8] to [657b6765f3].

258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275

276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295

		$db->commit();

		fclose($fp);
		return true;
	}

    public function toCSV()
    {
        $db = DB::getInstance();

        $champs = Config::getInstance()->get('champs_membres')->getKeys();
        $champs = 'm.' . implode(', m.', $champs);

        $res = $db->prepare('SELECT ' . $champs . ', c.nom AS categorie FROM membres AS m 
            LEFT JOIN membres_categories AS c ON m.id_categorie = c.id ORDER BY c.id;')->execute();

        $fp = fopen('php://output', 'w');

        $header = false;

        while ($row = $res->fetchArray(SQLITE3_ASSOC))
        {
            unset($row->passe);

            if (!$header)
            {
                fputcsv($fp, array_keys($row));
                $header = true;
            }

            fputs($fp, Utils::row_to_csv($row) . "\r\n");
        }

        fclose($fp);

        return true;
    }
}







|










>








|



|







258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296

		$db->commit();

		fclose($fp);
		return true;
	}

    public function toCSV($excel = false)
    {
        $db = DB::getInstance();

        $champs = Config::getInstance()->get('champs_membres')->getKeys();
        $champs = 'm.' . implode(', m.', $champs);

        $res = $db->prepare('SELECT ' . $champs . ', c.nom AS categorie FROM membres AS m 
            LEFT JOIN membres_categories AS c ON m.id_categorie = c.id ORDER BY c.id;')->execute();

        $fp = fopen('php://output', 'w');
        fputs($fp, Utils::csv_header($excel));
        $header = false;

        while ($row = $res->fetchArray(SQLITE3_ASSOC))
        {
            unset($row->passe);

            if (!$header)
            {
                fputs($fp, Utils::row_to_csv(array_keys($row), $excel));
                $header = true;
            }

            fputs($fp, Utils::row_to_csv($row, $excel));
        }

        fclose($fp);

        return true;
    }
}

Modified src/include/lib/Garradin/Utils.php from [45da0b309d] to [56babf6e61].

719
720
721
722
723
724
725
726
727
728
729




730
731
732
733
734
735

736












        // Skip BOM
        if (fgets($fp, 4) !== chr(0xEF) . chr(0xBB) . chr(0xBF))
        {
            fseek($fp, 0);
        }
    }

    static public function row_to_csv($row)
    {
        $row = (array) $row;





        array_walk($row, function ($field) {
            return strtr($field, ['"' => '""', "\r\n" => "\n"]);
        });

        return '"' . implode('","', $row) . '"';
    }

}



















|



>
>
>
>




|
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
        // Skip BOM
        if (fgets($fp, 4) !== chr(0xEF) . chr(0xBB) . chr(0xBF))
        {
            fseek($fp, 0);
        }
    }

    static public function row_to_csv($row, $excel = false)
    {
        $row = (array) $row;

        $eol = "\r\n";
        // Excel ne comprends pas les virgules en france, le c*****!
        $separator = $excel ? '";"' : '","';

        array_walk($row, function ($field) {
            return strtr($field, ['"' => '""', "\r\n" => "\n"]);
        });

        $out = '"' . implode($separator, $row) . '"' . $eol;

        return $out;
    }

    static public function csv_header($excel = false)
    {
        if ($excel)
        {
            // BOM spécifique pour Excel sinon il ne sait pas lire l'UTF8!
            return chr(0xEF) . chr(0xBB) . chr(0xBF);
        }

        return '';
    }
}

Modified src/templates/admin/membres/import.tpl from [b30cfa5d1f] to [0e9a87ea52].

1
2
3
4
5

6
7
8
9
10
11
12
{include file="admin/_head.tpl" title="Import & export des membres" current="membres" js=1}

<ul class="actions">
    <li class="current"><a href="{$admin_url}membres/import.php">Importer</a></li>
    <li><a href="{$admin_url}membres/import.php?export">Exporter en CSV</a></li>

</ul>

{form_errors}

{if $ok}
    <p class="confirm">
        L'import s'est bien déroulé.





>







1
2
3
4
5
6
7
8
9
10
11
12
13
{include file="admin/_head.tpl" title="Import & export des membres" current="membres" js=1}

<ul class="actions">
    <li class="current"><a href="{$admin_url}membres/import.php">Importer</a></li>
    <li><a href="{$admin_url}membres/import.php?export">Exporter en CSV</a></li>
    <li><a href="{$admin_url}membres/import.php?export=excel">Exporter en CSV (Excel)</a></li>
</ul>

{form_errors}

{if $ok}
    <p class="confirm">
        L'import s'est bien déroulé.

Modified src/www/admin/membres/import.php from [729a351975] to [caede8a449].

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

$import = new Membres\Import;

if (null !== qg('export'))
{
    header('Content-type: application/csv');
    header('Content-Disposition: attachment; filename="Export membres - ' . $config->get('nom_asso') . ' - ' . date('Y-m-d') . '.csv"');
    $import->toCSV();
    exit;
}

$champs = $config->get('champs_membres')->getAll();
$champs->date_inscription = (object) ['title' => 'Date inscription', 'type' => 'date'];

if (f('import'))







|







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

$import = new Membres\Import;

if (null !== qg('export'))
{
    header('Content-type: application/csv');
    header('Content-Disposition: attachment; filename="Export membres - ' . $config->get('nom_asso') . ' - ' . date('Y-m-d') . '.csv"');
    $import->toCSV(qg('export') == 'excel' ? true : false);
    exit;
}

$champs = $config->get('champs_membres')->getAll();
$champs->date_inscription = (object) ['title' => 'Date inscription', 'type' => 'date'];

if (f('import'))