Subversion Repositories Sites.obs-saisons.fr

Rev

Rev 232 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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