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) {
|
|
|
46 |
|
|
|
47 |
$csv = '';
|
|
|
48 |
$colonnes = array_keys($tableau[0]);
|
|
|
49 |
$csv .= implode(';',$colonnes).";\n";
|
|
|
50 |
|
|
|
51 |
foreach($tableau as $elements) {
|
|
|
52 |
$csv .= implode(';',$elements).";\n";
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
return $csv;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
public function envoyerFichier($contenu) {
|
|
|
59 |
|
|
|
60 |
$nom_fichier = "observations_export.csv";
|
|
|
61 |
$chemin_fichier = Config::get('chemin_fichiers_temp').'/'.$nom_fichier;
|
|
|
62 |
|
|
|
63 |
file_put_contents($chemin_fichier, $contenu);
|
|
|
64 |
|
|
|
65 |
$contenu = file_get_contents($chemin_fichier);
|
|
|
66 |
$taille_fichier = filesize($chemin_fichier);
|
|
|
67 |
|
|
|
68 |
unlink($chemin_fichier);
|
|
|
69 |
|
|
|
70 |
ini_set('zlib.output_compression','Off');
|
|
|
71 |
|
|
|
72 |
header('Pragma: public');
|
|
|
73 |
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
|
|
|
74 |
header('Cache-Control: must-revalidate, pre-check=0, post-check=0, max-age=0');
|
|
|
75 |
|
|
|
76 |
header('Content-Tranfer-Encoding: none');
|
|
|
77 |
|
|
|
78 |
header('Content-Type: application/octetstream; name="'.$nom_fichier.'"');
|
|
|
79 |
header('Content-Disposition: attachement; filename="'.$nom_fichier.'"');
|
|
|
80 |
|
|
|
81 |
header('Content-Length: '.$taille_fichier);
|
|
|
82 |
|
|
|
83 |
echo $contenu;
|
|
|
84 |
exit();
|
|
|
85 |
}
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
?>
|