Ajout bouton Export CSV dans le formulaire
This commit is contained in:
parent
8aec006092
commit
6e0ef64f69
@ -8,6 +8,8 @@
|
||||
*
|
||||
* @author Rémi Jean <remi.jean@outlook.com>
|
||||
* @copyright Copyright (C) 2008-2018, Rémi Jean
|
||||
* @author Frédéric Tempez <frederic.tempez@outlook.com>
|
||||
* @copyright Copyright (C) 2018-2019, Frédéric Tempez
|
||||
* @license GNU General Public License, version 3
|
||||
* @link http://zwiicms.com/
|
||||
*/
|
||||
@ -18,7 +20,9 @@ class form extends common {
|
||||
'config' => self::GROUP_MODERATOR,
|
||||
'data' => self::GROUP_MODERATOR,
|
||||
'delete' => self::GROUP_MODERATOR,
|
||||
'index' => self::GROUP_VISITOR
|
||||
'index' => self::GROUP_VISITOR,
|
||||
'export2csv' => self::GROUP_MODERATOR,
|
||||
'output2csv' => self::GROUP_MODERATOR
|
||||
];
|
||||
|
||||
public static $data = [];
|
||||
@ -135,6 +139,34 @@ class form extends common {
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Export CSV
|
||||
* @author Frédéric Tempez <frederic.tempez@outlook.com>
|
||||
* @copyright Copyright (C) 2018-2019, Frédéric Tempez
|
||||
*/
|
||||
public function export2csv() {
|
||||
$data = $this->getData(['module', $this->getUrl(0), 'data']);
|
||||
if ($data !== []) {
|
||||
$csvfilename = 'data-'.date('dmY').'-'.date('hm').'-'.rand(10,99).'.csv';
|
||||
if (!file_exists('site/file/source/data')) {
|
||||
mkdir('site/file/source/data');
|
||||
}
|
||||
$fp = fopen('site/file/source/data/'.$csvfilename, 'w');
|
||||
fputcsv($fp, array_keys($data[1]), ';','"');
|
||||
foreach ($data as $fields) {
|
||||
fputcsv($fp, $fields, ';','"');
|
||||
}
|
||||
fclose($fp);
|
||||
// Valeurs en sortie
|
||||
$this->addOutput([
|
||||
'notification' => ' Export CSV effectué dans :<br />'.$csvfilename,
|
||||
'redirect' => helper::baseUrl() . $this->getUrl(0) .'/data',
|
||||
'state' => true
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Suppression
|
||||
*/
|
||||
|
@ -7,6 +7,14 @@
|
||||
'value' => 'Retour'
|
||||
]); ?>
|
||||
</div>
|
||||
<div class="col2 offset8">
|
||||
<?php echo template::button('formDataBack', [
|
||||
'class' => 'buttonBlue',
|
||||
'href' => helper::baseUrl() . $this->getUrl(0) . '/export2csv',
|
||||
'ico' => 'download',
|
||||
'value' => 'Export CSV'
|
||||
]); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php echo template::table([11, 1], $module::$data, ['Données', '']); ?>
|
||||
<?php echo $module::$pagination; ?>
|
Loading…
Reference in New Issue
Block a user