* @copyright 2010 Tela-Botanica * @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL * @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL * @version SVN: $Id: Espece.php 152 2010-09-06 16:19:12Z jpm $ */ class Export extends aControleur { public function __construct() { parent::__construct(); $this->initialiser(); } public function executerActionParDefaut() { return $this->envoyerFichierCSVExportObservation(); } public function initialiser() { } // +---------------------------------------------------------------------------------------------------------------+ // METHODES D'AFFICHAGE DE FORMULAIRE public function envoyerFichierCSVExportObservation() { $donnees = array(); $export_dao = new ExportDao(); $export = $export_dao->getExportObservations(); $csv = $this->convertirTableauAssocVersCSV($export); $this->envoyerFichier($csv); } public function convertirTableauAssocVersCSV($tableau) { $csv = ''; if(count($tableau > 0)) { unset($tableau[0]['pseudo_participant']); unset($tableau[0]['mail_participant']); $colonnes = array_keys($tableau[0]); $csv .= implode(';',$colonnes).";\n"; foreach($tableau as $elements) { unset($elements['pseudo_participant']); unset($elements['mail_participant']); $ligne = ""; // parcours des cases de chaque ligne nécessaire car si on utilise implode // les valeurs vides ne sont pas prises et ça décale les colonnes foreach ($elements as $element) { $ligne .= '"'.$element.'";'; } $csv .= $ligne."\n"; } } return $csv; } public function envoyerFichier($contenu) { $nom_fichier = "observations_export.csv"; $chemin_fichier = Config::get('chemin_fichiers_temp').'/'.$nom_fichier; file_put_contents($chemin_fichier, $contenu); $contenu = file_get_contents($chemin_fichier); $taille_fichier = filesize($chemin_fichier); unlink($chemin_fichier); ini_set('zlib.output_compression','Off'); header('Pragma: public'); header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); header('Cache-Control: must-revalidate, pre-check=0, post-check=0, max-age=0'); header('Content-Tranfer-Encoding: none'); header('Content-Type: application/octetstream; name="'.$nom_fichier.'"'); header('Content-Disposition: attachement; filename="'.$nom_fichier.'"'); header('Content-Length: '.$taille_fichier); echo $contenu; exit(); } } ?>