cyrilleinvalides/choupas/www/admin/export.php

53 lines
1.0 KiB
PHP
Executable File

<?php
$func = include('includes/auth.php');
$func(function () {
if ( empty($_GET['begin']) )
die(EngineSystem::get('back')->load('pages/export.html')->run()->getData(''));
$a = Provider::get('cine')->query(sprintf(
'SELECT * FROM %3$s WHERE "%1$s" <= date AND date <= "%2$s ORDER BY date DESC";',
$_GET['begin'],
$_GET['end'],
$_GET['model']
));
if ( !$a[0] ) {
die(EngineSystem::get('back')->load('pages/error.html')->run(array(
'message' => "Aucun contact enregistr&eacute; entre les dates selectionn&eacute;es."
))->getData(''));
}
$schema = array_keys($a[0][0]);
header("Content-disposition: attachment; filename=export.xls");
header("Content-Type: application/force-download");
echo "<table>\n";
echo "\t<tr>\n";
foreach ( $schema as $field )
echo sprintf("\t\t" . '<th>%1$s</th>' . "\n", $field);
echo "\t</tr>\n";
foreach ( $a[0] as $row ) {
echo "\t<tr>\n";
foreach ( $row as $k => $v )
echo sprintf('<td>%2$s%1$s</td>', utf8_decode($v), $k === 'codepostal' ? "'" : "" );
echo "\t</tr>\n";
}
echo '</table>';
});
?>