Subversion Repositories eFlore/Applications.cel

Rev

Rev 1612 | Rev 1625 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1612 Rev 1617
Line 18... Line 18...
18
* @copyright 2012
18
* @copyright 2012
19
*/
19
*/
Line 20... Line 20...
20
 
20
 
21
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(realpath(__FILE__))) . '/lib');
21
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(realpath(__FILE__))) . '/lib');
22
// la sortie est binaire (xls), mais OLE n'est pas compatible E_ALL en PHP-5.4
22
// la sortie est binaire (xls), mais OLE n'est pas compatible E_ALL en PHP-5.4
23
error_reporting(error_reporting() ^ E_STRICT);
23
//error_reporting(error_reporting() ^ E_STRICT);
24
require_once("lib/OLE.php");
24
require_once("lib/OLE.php");
Line 25... Line 25...
25
require_once("lib/Spreadsheet/Excel/Writer.php");
25
require_once("lib/Spreadsheet/Excel/Writer.php");
Line 26... Line 26...
26
 
26
 
27
class CelWidgetExport extends Cel {
27
class CelWidgetExport extends Cel {
-
 
28
	
28
	
29
	private $nom_fichier_export = 'cel_export';
29
	private $nom_fichier_export = 'cel_export';
30
	private $champs_a_exclure = array(
-
 
31
		'ce_utilisateur' => true, 
30
	private $champs_a_exclure = array('ce_utilisateur' => 'ce_utilisateur', 
32
		'courriel_utilisateur' => true,
31
		'courriel_utilisateur' => 'courriel_utilisateur',
33
		'transmission' => true,
32
		'transmission' => 'transmission');
34
		'code_insee_calcule' => true);
33
	private $correspondance_champs = array(
35
	private $correspondance_champs = array(
34
		'id_observation' => 'Identifiant Observation',
36
		'id_observation' => 'Identifiant Observation',
Line 47... Line 49...
47
		'lieudit' => 'Lieu-Dit',
49
		'lieudit' => 'Lieu-Dit',
48
		'station' => 'Station',
50
		'station' => 'Station',
49
		'milieu' => 'Milieu',
51
		'milieu' => 'Milieu',
50
		'latitude' => 'Latitude',
52
		'latitude' => 'Latitude',
51
		'longitude' => 'Longitude',
53
		'longitude' => 'Longitude',
-
 
54
		'altitude' => 'Altitude',
52
		'geodatum' => 'Référentiel Géographique',
55
		'geodatum' => 'Référentiel Géographique',
53
		'date_observation' => 'Date Observation',
56
		'date_observation' => 'Date Observation',
54
		'mots_cles_texte' => 'Mots Clés',
57
		'mots_cles_texte' => 'Mots Clés',
55
		'commentaire' => 'Commentaires',
58
		'commentaire' => 'Commentaires',
56
		'date_creation' => 'Date Création',
59
		'date_creation' => 'Date Création',
57
		'date_modification' => 'Date Modification',
60
		'date_modification' => 'Date Modification',
58
		'date_transmission' => 'Date Transmission'
61
		'date_transmission' => 'Date Transmission',
-
 
62
		'abondance' => 'Abondance',
-
 
63
		'certitude' => 'Certitude',
-
 
64
		'phenologie' => 'Phénologie'
59
		);
65
		);
60
	private $parametres_autorises = array(
66
	private $parametres_autorises = array(
61
		'utilisateur' => 'courriel_utilisateur',
67
		'utilisateur' => 'courriel_utilisateur',
62
		'commune' => 'zone_geo',
68
		'commune' => 'zone_geo',
63
		'dept' => 'departement',
69
		'dept' => 'departement',
Line 90... Line 96...
90
		
96
		
91
		unset($criteres['limite']);
97
		unset($criteres['limite']);
Line 92... Line 98...
92
		unset($criteres['debut']);
98
		unset($criteres['debut']);
93
	
-
 
94
		$observations = $chercheur_observations->rechercherObservations(null, $criteres, $numero_page, $limite);
99
	
95
 
100
		$observations = $chercheur_observations->rechercherObservations(null, $criteres, $numero_page, $limite);
96
		switch($this->format) {
101
		switch($this->format) {
97
			case 'csv':
102
			case 'csv':
98
				$csv = $this->convertirEnCsv($observations);
103
				$csv = $this->convertirEnCsv($observations);
Line 132... Line 137...
132
	private function convertirEnCsv($data)
137
	private function convertirEnCsv($data)
133
	{
138
	{
134
		$chemin_temp = "php://temp";
139
		$chemin_temp = "php://temp";
135
		$outstream = fopen($chemin_temp, 'r+');
140
		$outstream = fopen($chemin_temp, 'r+');
136
		$intitule_champs = array();
141
		$intitule_champs = array();
137
		foreach($data as $ligne) {
142
		foreach($data as &$ligne) {
138
			$ligne = $this->filtrerDonneesSensibles($ligne);
143
			$ligne = $this->filtrerDonneesSensibles($ligne);
139
			$ligne = array_diff_key($ligne, $this->champs_a_exclure);
144
			$ligne = array_diff_key($ligne, $this->champs_a_exclure);
140
			if(empty($intitule_champs)) {
145
			if(empty($intitule_champs)) {
141
				$intitule_champs = $this->creerEntetesChamps($ligne);
146
				$intitule_champs = $this->creerEntetesChamps($ligne);
142
				fputcsv($outstream, $intitule_champs, ',', '"');			
147
				fputcsv($outstream, $intitule_champs, ',', '"');			
Line 159... Line 164...
159
		$worksheet = $workbook->addWorksheet('Liste');
164
		$worksheet = $workbook->addWorksheet('Liste');
160
		$worksheet->setInputEncoding('utf-8');
165
		$worksheet->setInputEncoding('utf-8');
161
		$workbook->send($this->nom_fichier_export.'.xls');
166
		$workbook->send($this->nom_fichier_export.'.xls');
Line 162... Line 167...
162
		
167
		
163
		$nb_lignes = 1;
168
		$nb_lignes = 1;
164
		
169
				
165
		foreach($data as $ligne) {
170
		foreach($data as &$ligne) {
166
			$ligne = $this->filtrerDonneesSensibles($ligne);
171
			$ligne = $this->filtrerDonneesSensibles($ligne);
167
			$ligne = array_diff_key($ligne, $this->champs_a_exclure);
172
			$ligne = array_diff_key($ligne, $this->champs_a_exclure);
168
			if(empty($intitule_champs)) {
173
			if(empty($intitule_champs)) {
169
				$intitule_champs = $this->creerEntetesChamps($ligne);
174
				$intitule_champs = $this->creerEntetesChamps($ligne);
170
				$indice = 0;
175
				$indice = 0;
171
				foreach ($intitule_champs as $intitule) {	
176
				foreach ($intitule_champs as &$intitule) {	
172
					$colonne = $intitule_champs[$indice];
177
					$colonne = $intitule_champs[$indice];
173
					$worksheet->write(0,$indice,$colonne);
178
					$worksheet->write(0,$indice,$colonne);
174
					$indice++;
179
					$indice++;
175
				}
180
				}
176
			}
181
			}
177
			$indice = 0;
182
			$indice = 0;
178
			foreach($ligne as $champ) {
183
			foreach($ligne as &$champ) {
179
				$worksheet->write($nb_lignes,$indice,$champ);
184
				$worksheet->write($nb_lignes,$indice,$champ);
180
				$indice++;
185
				$indice++;
181
			}
186
			}
182
			$nb_lignes++;
187
			$nb_lignes++;