210 |
aurelien |
1 |
<?php
|
|
|
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
/**
|
|
|
4 |
* Classe de gestion des epeces.
|
|
|
5 |
*
|
|
|
6 |
* @package Collection
|
|
|
7 |
* @category Php 5.2
|
|
|
8 |
* @author Aurélien PERONNET <aurelien@tela-botanica.org>
|
|
|
9 |
* @copyright 2010 Tela-Botanica
|
|
|
10 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
|
|
11 |
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
|
|
|
12 |
* @version SVN: $Id: Espece.php 152 2010-09-06 16:19:12Z jpm $
|
|
|
13 |
*/
|
|
|
14 |
class Export extends aControleur {
|
|
|
15 |
|
|
|
16 |
public function __construct() {
|
|
|
17 |
|
|
|
18 |
parent::__construct();
|
|
|
19 |
$this->initialiser();
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
public function executerActionParDefaut() {
|
|
|
23 |
return $this->envoyerFichierCSVExportObservation();
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
public function initialiser() {
|
|
|
27 |
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
// +---------------------------------------------------------------------------------------------------------------+
|
|
|
31 |
// METHODES D'AFFICHAGE DE FORMULAIRE
|
|
|
32 |
public function envoyerFichierCSVExportObservation() {
|
|
|
33 |
|
|
|
34 |
$donnees = array();
|
|
|
35 |
|
|
|
36 |
$export_dao = new ExportDao();
|
|
|
37 |
|
|
|
38 |
$export = $export_dao->getExportObservations();
|
|
|
39 |
|
|
|
40 |
$csv = $this->convertirTableauAssocVersCSV($export);
|
|
|
41 |
|
|
|
42 |
$this->envoyerFichier($csv);
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
public function convertirTableauAssocVersCSV($tableau) {
|
232 |
aurelien |
46 |
|
210 |
aurelien |
47 |
$csv = '';
|
|
|
48 |
|
232 |
aurelien |
49 |
if(count($tableau > 0)) {
|
|
|
50 |
unset($tableau[0]['pseudo_participant']);
|
|
|
51 |
unset($tableau[0]['mail_participant']);
|
|
|
52 |
|
|
|
53 |
$colonnes = array_keys($tableau[0]);
|
|
|
54 |
|
|
|
55 |
$csv .= implode(';',$colonnes).";\n";
|
|
|
56 |
|
|
|
57 |
foreach($tableau as $elements) {
|
|
|
58 |
unset($elements['pseudo_participant']);
|
|
|
59 |
unset($elements['mail_participant']);
|
|
|
60 |
$csv .= implode(';',$elements).";\n";
|
|
|
61 |
}
|
210 |
aurelien |
62 |
}
|
|
|
63 |
|
|
|
64 |
return $csv;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
public function envoyerFichier($contenu) {
|
|
|
68 |
|
|
|
69 |
$nom_fichier = "observations_export.csv";
|
|
|
70 |
$chemin_fichier = Config::get('chemin_fichiers_temp').'/'.$nom_fichier;
|
|
|
71 |
|
|
|
72 |
file_put_contents($chemin_fichier, $contenu);
|
|
|
73 |
|
|
|
74 |
$contenu = file_get_contents($chemin_fichier);
|
|
|
75 |
$taille_fichier = filesize($chemin_fichier);
|
|
|
76 |
|
|
|
77 |
unlink($chemin_fichier);
|
|
|
78 |
|
|
|
79 |
ini_set('zlib.output_compression','Off');
|
|
|
80 |
|
|
|
81 |
header('Pragma: public');
|
|
|
82 |
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
|
|
|
83 |
header('Cache-Control: must-revalidate, pre-check=0, post-check=0, max-age=0');
|
|
|
84 |
|
|
|
85 |
header('Content-Tranfer-Encoding: none');
|
|
|
86 |
|
|
|
87 |
header('Content-Type: application/octetstream; name="'.$nom_fichier.'"');
|
|
|
88 |
header('Content-Disposition: attachement; filename="'.$nom_fichier.'"');
|
|
|
89 |
|
|
|
90 |
header('Content-Length: '.$taille_fichier);
|
|
|
91 |
|
|
|
92 |
echo $contenu;
|
|
|
93 |
exit();
|
|
|
94 |
}
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
?>
|