Subversion Repositories eFlore/Applications.cel

Rev

Rev 2458 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
416 aurelien 1
<?php
2458 jpm 2
// declare(encoding='UTF-8');
907 aurelien 3
/**
2458 jpm 4
 * Service d'export vers feuille de calcul d'une sélection de relevés.
5
 *
6
 * @internal   Mininum PHP version : 5.2
7
 * @category   CEL
8
 * @package    Services
9
 * @subpackage Observations
10
 * @version    0.1
11
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
12
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
13
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
14
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
15
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
16
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
17
 */
416 aurelien 18
 
1606 raphael 19
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(realpath(__FILE__))) . '/lib');
20
// la sortie est binaire (xls), mais OLE n'est pas compatible E_ALL en PHP-5.4
21
error_reporting(error_reporting() ^ E_STRICT);
2458 jpm 22
require_once 'lib/OLE.php';
23
require_once 'lib/Spreadsheet/Excel/Writer.php';
1606 raphael 24
 
907 aurelien 25
class InventoryExport extends Cel  {
416 aurelien 26
 
907 aurelien 27
	private $extendSpreadsheetProductor;
416 aurelien 28
 
2458 jpm 29
	public function __construct($config) {
907 aurelien 30
		parent::__construct($config);
416 aurelien 31
 
32
		$this->extendSpreadsheetProductor = new SpreadsheetProductor();
33
		$this->extendSpreadsheetProductor->initSpreadsheet();
34
	}
35
 
2458 jpm 36
	public function getElement($uid){
37
		// Controle detournement utilisateur
38
		$this->controleUtilisateur($uid[0]);
416 aurelien 39
 
2458 jpm 40
		$criteres = $_GET;
41
		$chercheur_observations = new RechercheObservation($this->config);
416 aurelien 42
 
2458 jpm 43
		// Creating a workbook
44
		$workbook = new Spreadsheet_Excel_Writer();
45
		$workbook->setVersion(8);
46
		$workbook->send('liste.xls');
416 aurelien 47
 
2458 jpm 48
		// Creating a worksheet
49
		$worksheet = $workbook->addWorksheet('Liste');
50
		$worksheet->setInputEncoding('utf-8');
51
		$worksheet->write(0,0,'Espece');
52
		$worksheet->write(0,1,'Numero nomenclatural');
53
		$worksheet->write(0,2,'Nom retenu');
54
		$worksheet->write(0,3,'Numero nomenclatural nom retenu');
55
		$worksheet->write(0,4,'Numero taxonomique');
56
		$worksheet->write(0,5,'Famille');
57
		$worksheet->write(0,6,'Referentiel taxonomique');
58
		$worksheet->write(0,7,'Commune');
59
		$worksheet->write(0,8,'Identifiant Commune');
60
		$worksheet->write(0,9,'Date');
61
		$worksheet->write(0,10,'Lieu-dit');
62
		$worksheet->write(0,11,'Station');
63
		$worksheet->write(0,12,'Milieu');
64
		$worksheet->write(0,13,'Notes');
65
		$worksheet->write(0,14,'Latitude');
66
		$worksheet->write(0,15,'Longitude');
67
		$worksheet->write(0,16,'Referentiel Geographique');
68
		$worksheet->write(0,17,'Ordre');
69
		$worksheet->write(0,18,'Identifiant');
416 aurelien 70
 
2458 jpm 71
		$numero_page = isset($criteres['numero_page']) ? $criteres['numero_page'] : 0;
72
		$limite = isset($criteres['limite']) ? $criteres['limite'] : 0;
540 david 73
 
2458 jpm 74
		$observations = $chercheur_observations->rechercherObservations($uid[0], $criteres, $numero_page, $limite)->get();
75
		if (!$observations) {
76
			header('HTTP/1.0 204 No Content');
77
			exit;
78
		}
416 aurelien 79
 
2458 jpm 80
		$ids_obs = array();
81
		$indices_lignes_obs = array();
82
 
83
		$i = 1;
84
		foreach ($observations as &$obs) {
85
			$obs = $this->denullifierTableauValeurCel($obs);
86
			$ids_obs[] = $obs['id_observation'];
87
			$indices_lignes_obs[$obs['id_observation']] = $i;
88
 
89
			if ($obs['date_observation'] != '0000-00-00 00:00:00') {
90
				$obs['date_observation'] = $this->formaterDate($obs['date_observation']);
91
			} else {
92
				$obs['date_observation'] = '00/00/0000';
1755 raphael 93
			}
94
 
2458 jpm 95
			$worksheet->write($i,0,$obs['nom_sel']);
96
			$worksheet->write($i,1,$obs['nom_sel_nn']);
97
			$worksheet->write($i,2,$obs['nom_ret']);
98
			$worksheet->write($i,3,$obs['nom_ret_nn']);
99
			$worksheet->write($i,4,$obs['nt']);
100
			$worksheet->write($i,5,$obs['famille']);
101
			$worksheet->write($i,6,$obs['nom_referentiel']);
102
			$worksheet->write($i,7,$obs['zone_geo']);
103
			$worksheet->write($i,8,$this->convertirCodeZoneGeoVersDepartement($obs['ce_zone_geo']));
104
			$worksheet->write($i,9,$obs['date_observation']);
105
			$worksheet->write($i,10,$obs['lieudit']);
106
			$worksheet->write($i,11,$obs['station']);
107
			$worksheet->write($i,12,$obs['milieu']);
108
			$worksheet->write($i,13,$obs['commentaire']);
109
			$worksheet->write($i,14,$obs['latitude']);
110
			$worksheet->write($i,15,$obs['longitude']);
111
			$worksheet->write($i,16,$obs['geodatum']);
112
			$worksheet->write($i,17,$obs['ordre']);
113
			$worksheet->write($i,18,$obs['id_observation']);
114
			$i++;
115
		}
416 aurelien 116
 
2458 jpm 117
		$indice_dernier_champ_supp = 19;
118
		$indices_champs_supp = array();
119
		$gestion_champs_etendus = new GestionChampsEtendus($this->config, 'obs');
120
		$champs_supp_par_obs = $gestion_champs_etendus->consulterParLots($ids_obs);
416 aurelien 121
 
2458 jpm 122
		foreach ($champs_supp_par_obs as $id_obs => &$champs_supp) {
123
			foreach ($champs_supp as  &$champ_etendu) {
124
				$cle = $champ_etendu->cle;
125
				$label = $champ_etendu->label;
126
				$valeur = $champ_etendu->valeur;
127
				if(!isset($indices_champs_supp[$cle])) {
128
					$indices_champs_supp[$cle] = $indice_dernier_champ_supp;
129
					$worksheet->write(0, $indice_dernier_champ_supp, utf8_decode($label));
130
					$indice_dernier_champ_supp++;
131
				}
132
				$num_ligne_obs = $indices_lignes_obs[$id_obs];
133
				$worksheet->write($num_ligne_obs,$indices_champs_supp[$cle],utf8_decode($valeur));
134
			}
135
		}
136
 
137
		$workbook->close();
138
		exit();
416 aurelien 139
	}
2458 jpm 140
}