Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 624 Rev 907
Line 1... Line 1...
1
<?php
1
<?php
-
 
2
/**
-
 
3
* PHP Version 5
-
 
4
*
-
 
5
* @category  PHP
-
 
6
* @package   jrest
-
 
7
* @author    David Delon <david@tela-botania.org>
-
 
8
* @author    Aurélien Peronnet <aurelien@tela-botania.org>
-
 
9
* @copyright 2010 Tela-Botanica
-
 
10
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
-
 
11
* @version   SVN: <svn_id>
-
 
12
* @link      /doc/jrest/
-
 
13
*/
Line -... Line 14...
-
 
14
 
2
 
15
/**
3
// In : utf8
16
* in:utf8
4
// Out : iso8859
17
* out:iso8859
5
 
18
* 
6
// Export vers feuille de calcul d'une selection de releves
19
* Export vers feuille de calcul d'une selection de releves
-
 
20
* 
7
 
21
*/
8
Class InventoryExport extends DBAccessor  {
-
 
Line 9... Line -...
9
 
-
 
10
 
22
class InventoryExport extends Cel  {
Line 11... Line 23...
11
	var $config;
23
 
Line 12... Line 24...
12
	var $extendSpreadsheetProductor;
24
	private $extendSpreadsheetProductor;
13
 
-
 
14
	function InventoryExport($config) {
-
 
Line 15... Line 25...
15
 
25
 
16
		$this->config=$config;
26
	function InventoryExport($config) {
17
		// Pas d'heritage multiple en php :(
27
 
Line 18... Line -...
18
 
-
 
19
 
28
		parent::__construct($config);
Line 20... Line 29...
20
		$this->extendSpreadsheetProductor = new SpreadsheetProductor();
29
 
21
		$this->extendSpreadsheetProductor->initSpreadsheet();
30
		$this->extendSpreadsheetProductor = new SpreadsheetProductor();
22
	}
31
		$this->extendSpreadsheetProductor->initSpreadsheet();
Line 23... Line 32...
23
 
32
	}
24
 
-
 
25
	function getElement($uid){
33
 
26
 
34
	function getElement($uid){
Line 27... Line 35...
27
		   // Controle detournement utilisateur
35
 
28
		    session_start();
36
		   // Controle detournement utilisateur
29
		 	$this->controleUtilisateur($uid[0]);
37
		    session_start();
30
 
38
		 	$this->controleUtilisateur($uid[0]);
Line 31... Line -...
31
			$DB=$this->connectDB($this->config,'database_cel');
-
 
32
 
-
 
33
 
-
 
34
			$criteres = array() ;
-
 
35
 
-
 
36
			if(isset($uid[1]))
-
 
37
			{
-
 
38
				$criteres = explode("&", $uid[1]) ;
-
 
39
			}
-
 
40
 
-
 
41
			$query="SELECT identifiant, ordre, nom_sel, num_nom_sel, nom_ret, num_nom_ret, num_taxon, famille, location, id_location, date_observation," .
-
 
42
		           " lieudit, station, milieu, commentaire, transmission, coord_x, coord_y, ref_geo FROM cel_inventory WHERE identifiant='".$DB->escapeSimple($uid[0])."' AND " ;
-
 
43
 
-
 
44
 
-
 
45
 
-
 
46
			foreach($criteres as $pair)
-
 
47
			{
-
 
48
				$nom_valeur = explode("=",$pair) ;
-
 
49
 
-
 
50
 
-
 
51
				if(sizeof($nom_valeur) != 0) {
-
 
52
 
-
 
53
					if($nom_valeur[0] == 'limite')
-
 
54
					{
-
 
55
						$limite = $DB->escapeSimple($nom_valeur[1]) ;
-
 
56
					}
-
 
57
					elseif($nom_valeur[0] == 'numero_page') {
-
 
58
						$numero_page = $DB->escapeSimple($nom_valeur[1]) ;
-
 
59
					}
-
 
60
					elseif($nom_valeur[0] == 'annee') {
-
 
61
						$query .= "year(date_observation) = '".$DB->escapeSimple($nom_valeur[1])."'" ;
-
 
62
						$query .= ' AND ' ;
-
 
63
					}
-
 
64
					elseif($nom_valeur[0] == 'mois') {
-
 
65
						$query .= "month(date_observation) = '".$DB->escapeSimple($nom_valeur[1])."'" ;
-
 
66
						$query .= ' AND ' ;
-
 
67
					}
-
 
68
					elseif($nom_valeur[0] == 'jour') {
-
 
69
						$query .= "day(date_observation) = '".$DB->escapeSimple($nom_valeur[1])."'" ;
-
 
70
						$query .= ' AND ' ;
-
 
71
					}
-
 
72
                    elseif($nom_valeur[0] == 'mots_cles') {
-
 
73
                        $liste_mc = explode(";",$nom_valeur[1]);
-
 
74
                        $query .= '(' ;
-
 
75
                        foreach($liste_mc as $mot) {
-
 
76
                                if(trim($mot) != '')
-
 
77
                                {
-
 
78
                                  $query .= "mots_cles LIKE '%".$DB->escapeSimple($mot)."%' OR " ;
-
 
79
                                }
-
 
80
                        }
-
 
81
                        $query = rtrim($query,' OR ');
-
 
82
                        $query .= ') AND ' ;
-
 
83
                    }
-
 
84
                    elseif ($nom_valeur[0] == 'nom_taxon') {
-
 
85
                    	$nom_valeur[1] = str_replace("*","%",$nom_valeur[1]);
-
 
86
                    	$query .= "(nom_sel LIKE '%".$DB->escapeSimple($nom_valeur[1]).
-
 
87
									"%' OR identifiant LIKE '%".$DB->escapeSimple($nom_valeur[1]).
-
 
88
									"%' OR ordre LIKE '%".$DB->escapeSimple($nom_valeur[1]).
-
 
89
									"%' OR nom_sel LIKE '%".$DB->escapeSimple($nom_valeur[1]).
-
 
90
									"%' OR num_nom_sel LIKE '%".$DB->escapeSimple($nom_valeur[1]).
-
 
91
									"%' OR nom_ret LIKE '%".$DB->escapeSimple($nom_valeur[1]).
-
 
92
									"%' OR num_nom_ret LIKE '%".$DB->escapeSimple($nom_valeur[1]).
-
 
93
									"%' OR num_taxon LIKE '%".$DB->escapeSimple($nom_valeur[1]).
-
 
94
									"%' OR location LIKE '%".$DB->escapeSimple($nom_valeur[1]).
-
 
95
									"%' OR id_location LIKE '%".$DB->escapeSimple($nom_valeur[1]).
-
 
96
									"%' OR date_observation LIKE '%".$DB->escapeSimple($nom_valeur[1]).
-
 
97
									"%' OR lieudit LIKE '%".$DB->escapeSimple($nom_valeur[1]).
-
 
98
									"%' OR station LIKE '%".$DB->escapeSimple($nom_valeur[1]).
-
 
99
									"%' OR milieu LIKE '%".$DB->escapeSimple($nom_valeur[1]).
-
 
100
									"%' OR commentaire LIKE '%".$DB->escapeSimple($nom_valeur[1]).
-
 
101
									"%' OR transmission LIKE '%".$DB->escapeSimple($nom_valeur[1]).
-
 
102
									"%' OR coord_x LIKE '%".$DB->escapeSimple($nom_valeur[1]).
-
 
103
									"%' OR coord_y LIKE '%".$DB->escapeSimple($nom_valeur[1]).
-
 
104
									"%')";
-
 
105
 
-
 
106
									//"%' OR famille LIKE '%".$DB->escapeSimple($nom_valeur[1]).
-
 
107
                    }
-
 
108
					else {
-
 
109
						if(trim($nom_valeur[0]) != '')
-
 
110
						{
-
 
111
						$query .= $nom_valeur[0]." = '".$DB->escapeSimple($nom_valeur[1])."'" ;
-
 
112
						$query .= ' AND ' ;
-
 
113
						}
-
 
114
					}
-
 
115
				}
-
 
116
			}
-
 
117
 
-
 
118
			$query = rtrim($query,' AND ') ;
-
 
119
 
-
 
120
 
-
 
121
			$query .=" ORDER BY ordre ";
-
 
122
 
39
 
123
       	    $res =& $DB->query($query);
40
			$criteres = array();
Line 124... Line -...
124
 
-
 
125
 
41
			
Line 126... Line 42...
126
			if (DB::isError($res)) {
42
			$chercheur_observations = new RechercheObservation($this->config);
127
			     die($res->getMessage());
43
 
Line 152... Line 68...
152
            $worksheet->write(0,11,'Milieu');
68
            $worksheet->write(0,11,'Milieu');
153
            $worksheet->write(0,12,'Notes');
69
            $worksheet->write(0,12,'Notes');
154
            $worksheet->write(0,13,'Latitude');
70
            $worksheet->write(0,13,'Latitude');
155
            $worksheet->write(0,14,'Longitude');
71
            $worksheet->write(0,14,'Longitude');
156
            $worksheet->write(0,15,'Referentiel Geographique');
72
            $worksheet->write(0,15,'Referentiel Geographique');
-
 
73
            
-
 
74
            $numero_page = isset($criteres['numero_page']) ? $criteres['numero_page'] : 0;
-
 
75
            $limite = isset($criteres['limite']) ? $criteres['limite'] : 50;
Line 157... Line -...
157
 
-
 
-
 
76
 
Line 158... Line 77...
158
 
77
			$observations = $chercheur_observations->rechercherObservations($uid[0], $criteres, $numero_page, $limite);
-
 
78
 
-
 
79
			$i=1;
159
 
80
			foreach ($observations as $obs) {
Line 160... Line -...
160
			$i=1;
-
 
161
			 while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
-
 
162
 
-
 
163
			 	// Denullifiage
-
 
164
				foreach($row as $k=>$v) {
-
 
165
					if (($v=="null") || ($v=="000null")) {
-
 
166
						$row[$k]="";
-
 
167
					}
-
 
168
					else {
-
 
169
						$row[$k]=utf8_decode($v);
-
 
170
					}
-
 
171
				}
81
 
172
 
82
				$obs = $this->denullifierTableauValeurCel(&$obs);
173
 
-
 
174
			  	if ($row['date_observation']!="0000-00-00 00:00:00") {
-
 
175
	                list($year,$month,$day)= split ('-',$row['date_observation']);
83
 
176
    	            list($day)= split (' ',$day);
84
			  	if ($obs['date_observation'] != "0000-00-00 00:00:00") {
177
	                $row['date_observation']=$day."/".$month."/".$year;
85
	                $obs['date_observation'] = $this->formaterDate($obs['date_observation']);
178
	        	}
86
	        	}
Line 179... Line -...
179
	        	else {
-
 
180
	                $row['date_observation']="00/00/0000";
87
	        	else {
181
	        	}
88
	                $obs['date_observation']="00/00/0000";
182
 
89
	        	}
183
 
90
 
184
                $worksheet->write($i,0,$row['nom_sel']);
91
                $worksheet->write($i,0,$obs['nom_sel']);
185
                $worksheet->write($i,1,$row['num_nom_sel']);
92
                $worksheet->write($i,1,$obs['nom_sel_nn']);
186
                $worksheet->write($i,2,$row['nom_ret']);
93
                $worksheet->write($i,2,$obs['nom_ret']);
187
                $worksheet->write($i,3,$row['num_nom_ret']);
94
                $worksheet->write($i,3,$obs['nom_ret_nn']);
188
                $worksheet->write($i,4,$row['num_taxon']);
95
                $worksheet->write($i,4,$obs['nt']);
189
                $worksheet->write($i,5,$row['famille']);
96
                $worksheet->write($i,5,$obs['famille']);
190
                $worksheet->write($i,6,$row['location']);
97
                $worksheet->write($i,6,$obs['zone_geo']);
191
                $worksheet->write($i,7,$row['id_location']);
98
                $worksheet->write($i,7,$this->convertirCodeZoneGeoVersDepartement($obs['ce_zone_geo']));
192
                $worksheet->write($i,8,$row['date_observation']);
99
                $worksheet->write($i,8,$obs['date_observation']);
193
                $worksheet->write($i,9,$row['lieudit']);
100
                $worksheet->write($i,9,$obs['lieudit']);
194
                $worksheet->write($i,10,$row['station']);
101
                $worksheet->write($i,10,$obs['station']);
195
                $worksheet->write($i,11,$row['milieu']);
102
                $worksheet->write($i,11,$obs['milieu']);
196
                $worksheet->write($i,12,$row['commentaire']);
103
                $worksheet->write($i,12,$obs['commentaire']);
197
                $worksheet->write($i,13,$row['coord_x']);
104
                $worksheet->write($i,13,$obs['latitude']);
Line 198... Line 105...
198
                $worksheet->write($i,14,$row['coord_y']);
105
                $worksheet->write($i,14,$obs['longitude']);
Line 199... Line 106...
199
                $worksheet->write($i,15,$row['ref_geo']);
106
                $worksheet->write($i,15,$obs['geodatum']);
200
                $i++;
-
 
201
    	    }
-
 
202
 
107
                $i++;
203
			$workbook->close();
-
 
204
 
-
 
205
			exit();
-
 
206
 
108
    	    }
207
 
-
 
208
	}
-
 
209
 
109
 
210
 
110
			$workbook->close();
211
 
111
 
212
}
112
			exit();
213
 
113
	}
Line 223... Line 123...
223
* Revision 1.5  2007-06-06 13:31:16  ddelon
123
* Revision 1.5  2007-06-06 13:31:16  ddelon
224
* v0.09
124
* v0.09
225
*
125
*
226
* Revision 1.4  2007-05-22 12:54:09  ddelon
126
* Revision 1.4  2007-05-22 12:54:09  ddelon
227
* Securisation acces utilisateur
127
* Securisation acces utilisateur
228
*
-
 
229
*
-
 
230
*
-
 
231
*/
128
*/
232
 
-
 
233
 
-
 
234
?>
129
?>
235
130