Subversion Repositories eFlore/Applications.cel

Rev

Rev 1609 | Rev 1755 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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