Subversion Repositories eFlore/Applications.cel

Rev

Rev 1755 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1755 Rev 2458
Line 1... Line 1...
1
<?php
1
<?php
2
// ATTENTION ! Classe compatible uniquement avec nouveau format de bdd du cel //
-
 
3
 
-
 
4
/**
-
 
5
* PHP Version 5
-
 
6
*
-
 
7
* @category  PHP
-
 
8
* @package   jrest
-
 
9
* @author    David Delon <david@tela-botania.org>
-
 
10
* @author    Aurélien Peronnet <aurelien@tela-botania.org>
-
 
11
* @copyright 2010 Tela-Botanica
-
 
12
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
-
 
13
* @version   SVN: <svn_id>
2
// declare(encoding='UTF-8');
14
* @link      /doc/jrest/
-
 
15
*/
-
 
16
 
-
 
17
/**
3
/**
18
* in:utf8
-
 
19
* out:iso8859
-
 
20
* 
-
 
21
* Export vers feuille de calcul d'une selection de releves
4
 * Service d'export vers feuille de calcul d'une sélection de relevés.
22
* 
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>
23
*/
17
 */
Line 24... Line 18...
24
 
18
 
25
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(realpath(__FILE__))) . '/lib');
19
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(realpath(__FILE__))) . '/lib');
26
// la sortie est binaire (xls), mais OLE n'est pas compatible E_ALL en PHP-5.4
20
// la sortie est binaire (xls), mais OLE n'est pas compatible E_ALL en PHP-5.4
27
error_reporting(error_reporting() ^ E_STRICT);
21
error_reporting(error_reporting() ^ E_STRICT);
28
require_once("lib/OLE.php");
22
require_once 'lib/OLE.php';
Line 29... Line 23...
29
require_once("lib/Spreadsheet/Excel/Writer.php");
23
require_once 'lib/Spreadsheet/Excel/Writer.php';
Line 30... Line 24...
30
 
24
 
Line 31... Line 25...
31
class InventoryExport extends Cel  {
25
class InventoryExport extends Cel  {
32
 
-
 
33
	private $extendSpreadsheetProductor;
26
 
Line 34... Line 27...
34
 
27
	private $extendSpreadsheetProductor;
35
	function InventoryExport($config) {
28
 
36
 
29
	public function __construct($config) {
Line 37... Line 30...
37
		parent::__construct($config);
30
		parent::__construct($config);
38
 
-
 
39
		$this->extendSpreadsheetProductor = new SpreadsheetProductor();
31
 
40
		$this->extendSpreadsheetProductor->initSpreadsheet();
32
		$this->extendSpreadsheetProductor = new SpreadsheetProductor();
41
	}
33
		$this->extendSpreadsheetProductor->initSpreadsheet();
42
 
34
	}
43
	function getElement($uid){
35
 
-
 
36
	public function getElement($uid){
-
 
37
		// Controle detournement utilisateur
-
 
38
		$this->controleUtilisateur($uid[0]);
-
 
39
 
-
 
40
		$criteres = $_GET;
-
 
41
		$chercheur_observations = new RechercheObservation($this->config);
-
 
42
 
-
 
43
		// Creating a workbook
-
 
44
		$workbook = new Spreadsheet_Excel_Writer();
-
 
45
		$workbook->setVersion(8);
-
 
46
		$workbook->send('liste.xls');
-
 
47
 
-
 
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');
-
 
70
 
-
 
71
		$numero_page = isset($criteres['numero_page']) ? $criteres['numero_page'] : 0;
-
 
72
		$limite = isset($criteres['limite']) ? $criteres['limite'] : 0;
-
 
73
 
-
 
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
		}
-
 
79
 
-
 
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;
Line 44... Line -...
44
 
-
 
45
		   // Controle detournement utilisateur
-
 
46
		 	$this->controleUtilisateur($uid[0]);
-
 
47
 
-
 
48
			$criteres = $_GET;	
-
 
49
			$chercheur_observations = new RechercheObservation($this->config);
-
 
50
 
-
 
51
    	    // Creating a workbook
88
 
52
			$workbook = new Spreadsheet_Excel_Writer();
89
			if ($obs['date_observation'] != '0000-00-00 00:00:00') {
53
			$workbook->setVersion(8);
-
 
54
 
90
				$obs['date_observation'] = $this->formaterDate($obs['date_observation']);
55
			$workbook->send('liste.xls');
-
 
56
 
91
			} else {
57
			// Creating a worksheet
-
 
58
			$worksheet = $workbook->addWorksheet('Liste');
92
				$obs['date_observation'] = '00/00/0000';
59
			$worksheet->setInputEncoding('utf-8');
93
			}
60
			
94
 
61
            $worksheet->write(0,0,'Espece');
95
			$worksheet->write($i,0,$obs['nom_sel']);
62
            $worksheet->write(0,1,'Numero nomenclatural');
96
			$worksheet->write($i,1,$obs['nom_sel_nn']);
63
            $worksheet->write(0,2,'Nom retenu');
97
			$worksheet->write($i,2,$obs['nom_ret']);
64
            $worksheet->write(0,3,'Numero nomenclatural nom retenu');
98
			$worksheet->write($i,3,$obs['nom_ret_nn']);
65
            $worksheet->write(0,4,'Numero taxonomique');
99
			$worksheet->write($i,4,$obs['nt']);
66
            $worksheet->write(0,5,'Famille');
100
			$worksheet->write($i,5,$obs['famille']);
67
            $worksheet->write(0,6,'Referentiel taxonomique');
101
			$worksheet->write($i,6,$obs['nom_referentiel']);
68
            $worksheet->write(0,7,'Commune');
102
			$worksheet->write($i,7,$obs['zone_geo']);
69
            $worksheet->write(0,8,'Identifiant Commune');
103
			$worksheet->write($i,8,$this->convertirCodeZoneGeoVersDepartement($obs['ce_zone_geo']));
70
            $worksheet->write(0,9,'Date');
104
			$worksheet->write($i,9,$obs['date_observation']);
71
            $worksheet->write(0,10,'Lieu-dit');
105
			$worksheet->write($i,10,$obs['lieudit']);
72
            $worksheet->write(0,11,'Station');
106
			$worksheet->write($i,11,$obs['station']);
-
 
107
			$worksheet->write($i,12,$obs['milieu']);
-
 
108
			$worksheet->write($i,13,$obs['commentaire']);
73
            $worksheet->write(0,12,'Milieu');
109
			$worksheet->write($i,14,$obs['latitude']);
-
 
110
			$worksheet->write($i,15,$obs['longitude']);
-
 
111
			$worksheet->write($i,16,$obs['geodatum']);
74
            $worksheet->write(0,13,'Notes');
112
			$worksheet->write($i,17,$obs['ordre']);
75
            $worksheet->write(0,14,'Latitude');
113
			$worksheet->write($i,18,$obs['id_observation']);
76
            $worksheet->write(0,15,'Longitude');
114
			$i++;
77
            $worksheet->write(0,16,'Referentiel Geographique');
115
		}
-
 
116
 
78
            $worksheet->write(0,17,'Ordre');
117
		$indice_dernier_champ_supp = 19;
-
 
118
		$indices_champs_supp = array();
79
            $worksheet->write(0,18,'Identifiant');
119
		$gestion_champs_etendus = new GestionChampsEtendus($this->config, 'obs');
-
 
120
		$champs_supp_par_obs = $gestion_champs_etendus->consulterParLots($ids_obs);
-
 
121
 
-
 
122
		foreach ($champs_supp_par_obs as $id_obs => &$champs_supp) {
-
 
123
			foreach ($champs_supp as  &$champ_etendu) {
80
            
124
				$cle = $champ_etendu->cle;
-
 
125
				$label = $champ_etendu->label;
-
 
126
				$valeur = $champ_etendu->valeur;
81
            $numero_page = isset($criteres['numero_page']) ? $criteres['numero_page'] : 0;
127
				if(!isset($indices_champs_supp[$cle])) {
-
 
128
					$indices_champs_supp[$cle] = $indice_dernier_champ_supp;
Line 82... Line -...
82
            $limite = isset($criteres['limite']) ? $criteres['limite'] : 0;
-
 
83
 
-
 
84
			$observations = $chercheur_observations->rechercherObservations($uid[0], $criteres, $numero_page, $limite)->get();
-
 
85
			if(!$observations) {
-
 
86
				header('HTTP/1.0 204 No Content');
-
 
87
				exit;
-
 
88
			}
-
 
89
 
-
 
90
			$ids_obs = array();
-
 
91
			$indices_lignes_obs = array();
-
 
92
			
-
 
93
			$i=1;
-
 
94
			foreach ($observations as &$obs) {
-
 
95
 
-
 
96
				$obs = $this->denullifierTableauValeurCel($obs);
-
 
97
				$ids_obs[] = $obs['id_observation'];
-
 
98
				$indices_lignes_obs[$obs['id_observation']] = $i;
-
 
99
				
-
 
100
			  	if ($obs['date_observation'] != "0000-00-00 00:00:00") {
-
 
101
	                $obs['date_observation'] = $this->formaterDate($obs['date_observation']);
-
 
102
	        	}
-
 
103
	        	else {
-
 
104
	                $obs['date_observation']="00/00/0000";
-
 
105
	        	}
-
 
106
 
-
 
107
                $worksheet->write($i,0,$obs['nom_sel']);
-
 
108
                $worksheet->write($i,1,$obs['nom_sel_nn']);
-
 
109
                $worksheet->write($i,2,$obs['nom_ret']);
-
 
110
                $worksheet->write($i,3,$obs['nom_ret_nn']);
-
 
111
                $worksheet->write($i,4,$obs['nt']);
-
 
112
                $worksheet->write($i,5,$obs['famille']);
-
 
113
                $worksheet->write($i,6,$obs['nom_referentiel']);
-
 
114
                $worksheet->write($i,7,$obs['zone_geo']);
-
 
115
                $worksheet->write($i,8,$this->convertirCodeZoneGeoVersDepartement($obs['ce_zone_geo']));
-
 
116
                $worksheet->write($i,9,$obs['date_observation']);
-
 
117
                $worksheet->write($i,10,$obs['lieudit']);
-
 
118
                $worksheet->write($i,11,$obs['station']);
-
 
119
                $worksheet->write($i,12,$obs['milieu']);
-
 
120
                $worksheet->write($i,13,$obs['commentaire']);
-
 
121
                $worksheet->write($i,14,$obs['latitude']);
-
 
122
                $worksheet->write($i,15,$obs['longitude']);
-
 
123
                $worksheet->write($i,16,$obs['geodatum']);
-
 
124
                $worksheet->write($i,17,$obs['ordre']);
-
 
125
                $worksheet->write($i,18,$obs['id_observation']);
-
 
126
                $i++;
-
 
127
    	    }
-
 
128
    	    
-
 
129
    	    $indice_dernier_champ_supp = 19;
-
 
130
    	    $indices_champs_supp = array();
-
 
131
    	    $gestion_champs_etendus = new GestionChampsEtendus($this->config, 'obs');
-
 
132
    	    $champs_supp_par_obs = $gestion_champs_etendus->consulterParLots($ids_obs);
-
 
133
    	    
-
 
134
    	    foreach($champs_supp_par_obs as $id_obs => &$champs_supp) {
-
 
135
	    	    foreach($champs_supp as  &$champ_etendu) {
-
 
136
	    	    	$cle = $champ_etendu->cle;
-
 
137
	    	    	$label = $champ_etendu->label;
-
 
138
	    	    	$valeur = $champ_etendu->valeur;
-
 
139
	    	    	if(!isset($indices_champs_supp[$cle])) {
-
 
140
	    	    		$indices_champs_supp[$cle] = $indice_dernier_champ_supp;
-
 
141
	    	    		$worksheet->write(0, $indice_dernier_champ_supp, utf8_decode($label));
129
					$worksheet->write(0, $indice_dernier_champ_supp, utf8_decode($label));
142
	    	    		$indice_dernier_champ_supp++;
130
					$indice_dernier_champ_supp++;
143
	    	    	}
131
				}
144
	    	    	$num_ligne_obs = $indices_lignes_obs[$id_obs];
-
 
145
	    	    	$worksheet->write($num_ligne_obs,$indices_champs_supp[$cle],utf8_decode($valeur));
-
 
146
	    	    }
-
 
147
    	    }
-
 
148
    	    
-
 
149
			$workbook->close();
-
 
150
			exit();
-
 
151
	}
-
 
152
}
-
 
153
/* +--Fin du code ---------------------------------------------------------------------------------------+
-
 
154
* $Log$
-
 
155
* Revision 1.7  2008-11-13 11:29:12  ddelon
-
 
156
* Reecriture gwt-ext
-
 
157
*
-
 
158
* Revision 1.6  2008-01-30 08:57:28  ddelon
-
 
159
* fin mise en place mygwt
-
 
160
*
132
				$num_ligne_obs = $indices_lignes_obs[$id_obs];
-
 
133
				$worksheet->write($num_ligne_obs,$indices_champs_supp[$cle],utf8_decode($valeur));
161
* Revision 1.5  2007-06-06 13:31:16  ddelon
134
			}