Subversion Repositories eFlore/Applications.cel

Rev

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

Rev Author Line No. Line
416 aurelien 1
<?php
2
 
3
// In : utf8
4
// Out : iso8859
5
 
6
// Export vers feuille de calcul d'une selection de releves
7
 
8
Class InventoryExport extends DBAccessor  {
9
 
10
 
11
	var $config;
12
	var $extendSpreadsheetProductor;
13
 
14
	function InventoryExport($config) {
15
 
16
		$this->config=$config;
17
		// Pas d'heritage multiple en php :(
18
 
19
 
20
		$this->extendSpreadsheetProductor = new SpreadsheetProductor();
21
		$this->extendSpreadsheetProductor->initSpreadsheet();
22
	}
23
 
24
 
25
	function getElement($uid){
26
 
27
		   // Controle detournement utilisateur
28
		    session_start();
29
		 $this->controleUtilisateur($uid[0]);
30
 
31
 
32
 
33
			$DB=$this->connectDB($this->config,'database_cel');
34
 
35
 
36
			$criteres = array() ;
37
 
38
			if(isset($uid[1]))
39
			{
40
				$criteres = explode("&", $uid[1]) ;
41
			}
42
 
43
			$query="SELECT identifiant, ordre, nom_sel, num_nom_sel, nom_ret, num_nom_ret, num_taxon, famille, location, id_location, date_observation," .
44
		           " lieudit, station, milieu, commentaire, transmission, coord_x, coord_y, ref_geo FROM cel_inventory WHERE identifiant='".$DB->escapeSimple($uid[0])."' AND " ;
45
 
46
 
47
 
48
			foreach($criteres as $pair)
49
			{
50
				$nom_valeur = explode("=",$pair) ;
51
 
52
 
53
				if(sizeof($nom_valeur) != 0) {
54
 
55
					if($nom_valeur[0] == 'limite')
56
					{
57
						$limite = $DB->escapeSimple($nom_valeur[1]) ;
58
					}
59
					elseif($nom_valeur[0] == 'numero_page') {
60
						$numero_page = $DB->escapeSimple($nom_valeur[1]) ;
61
					}
62
					elseif($nom_valeur[0] == 'annee') {
63
						$query .= "year(date_observation) = '".$DB->escapeSimple($nom_valeur[1])."'" ;
64
						$query .= ' AND ' ;
65
					}
66
					elseif($nom_valeur[0] == 'mois') {
67
						$query .= "month(date_observation) = '".$DB->escapeSimple($nom_valeur[1])."'" ;
68
						$query .= ' AND ' ;
69
					}
70
					elseif($nom_valeur[0] == 'jour') {
71
						$query .= "day(date_observation) = '".$DB->escapeSimple($nom_valeur[1])."'" ;
72
						$query .= ' AND ' ;
73
					}
74
                    elseif($nom_valeur[0] == 'mots_cles') {
75
                        $liste_mc = explode(";",$nom_valeur[1]);
76
                        $query .= '(' ;
77
                        foreach($liste_mc as $mot) {
78
                                if(trim($mot) != '')
79
                                {
80
                                  $query .= "mots_cles LIKE '%".$DB->escapeSimple($mot)."%' OR " ;
81
                                }
82
                        }
83
                        $query = rtrim($query,' OR ');
84
                        $query .= ') AND ' ;
85
                    }
86
                    elseif ($nom_valeur[0] == 'nom_taxon') {
87
                    	$nom_valeur[1] = str_replace("*","%",$nom_valeur[1]);
88
                    	$query .= "(nom_sel LIKE '%".$DB->escapeSimple($nom_valeur[1]).
89
									"%' OR identifiant LIKE '%".$DB->escapeSimple($nom_valeur[1]).
90
									"%' OR ordre LIKE '%".$DB->escapeSimple($nom_valeur[1]).
91
									"%' OR nom_sel LIKE '%".$DB->escapeSimple($nom_valeur[1]).
92
									"%' OR num_nom_sel LIKE '%".$DB->escapeSimple($nom_valeur[1]).
93
									"%' OR nom_ret LIKE '%".$DB->escapeSimple($nom_valeur[1]).
94
									"%' OR num_nom_ret LIKE '%".$DB->escapeSimple($nom_valeur[1]).
95
									"%' OR num_taxon LIKE '%".$DB->escapeSimple($nom_valeur[1]).
96
									"%' OR location LIKE '%".$DB->escapeSimple($nom_valeur[1]).
97
									"%' OR id_location LIKE '%".$DB->escapeSimple($nom_valeur[1]).
98
									"%' OR date_observation LIKE '%".$DB->escapeSimple($nom_valeur[1]).
99
									"%' OR lieudit LIKE '%".$DB->escapeSimple($nom_valeur[1]).
100
									"%' OR station LIKE '%".$DB->escapeSimple($nom_valeur[1]).
101
									"%' OR milieu LIKE '%".$DB->escapeSimple($nom_valeur[1]).
102
									"%' OR commentaire LIKE '%".$DB->escapeSimple($nom_valeur[1]).
103
									"%' OR transmission LIKE '%".$DB->escapeSimple($nom_valeur[1]).
104
									"%' OR coord_x LIKE '%".$DB->escapeSimple($nom_valeur[1]).
105
									"%' OR coord_y LIKE '%".$DB->escapeSimple($nom_valeur[1]).
106
									"%')";
107
 
108
									//"%' OR famille LIKE '%".$DB->escapeSimple($nom_valeur[1]).
109
                    }
110
					else {
111
						if(trim($nom_valeur[0]) != '')
112
						{
113
						$query .= $nom_valeur[0]." = '".$DB->escapeSimple($nom_valeur[1])."'" ;
114
						$query .= ' AND ' ;
115
						}
116
					}
117
				}
118
			}
119
 
120
			$query = rtrim($query,' AND ') ;
121
 
122
 
123
			$query .=" ORDER BY ordre ";
124
 
125
       	    $res =& $DB->query($query);
126
 
127
 
128
			if (DB::isError($res)) {
129
			     die($res->getMessage());
130
			}
131
 
132
 
133
 
134
    	    // Creating a workbook
135
			$workbook = new Spreadsheet_Excel_Writer();
136
 
137
 
540 david 138
			$workbook->send('liste.xls');
139
 
416 aurelien 140
			// Creating a worksheet
141
			$worksheet = $workbook->addWorksheet('Liste');
142
 
143
 
144
            $worksheet->write(0,0,'Nom saisi');
145
            $worksheet->write(0,1,'Numero nomenclatural');
146
            $worksheet->write(0,2,'Nom retenu');
147
            $worksheet->write(0,3,'Numero nomenclatural nom retenu');
148
            $worksheet->write(0,4,'Numero taxonomique');
149
            $worksheet->write(0,5,'Famille');
150
            $worksheet->write(0,6,'Commune');
151
            $worksheet->write(0,7,'Identifiant Commune');
152
            $worksheet->write(0,8,'Date Observation');
153
            $worksheet->write(0,9,'Lieu dit');
154
            $worksheet->write(0,10,'Station');
155
            $worksheet->write(0,11,'Milieu');
156
            $worksheet->write(0,12,'Commentaire');
157
            $worksheet->write(0,13,'X');
158
            $worksheet->write(0,14,'Y');
159
            $worksheet->write(0,15,'Referentiel Geographique');
160
 
161
 
162
 
163
			$i=1;
164
			 while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
165
 
166
			 	// Denullifiage
167
				foreach($row as $k=>$v) {
168
					if (($v=="null") || ($v=="000null")) {
169
						$row[$k]="";
170
					}
171
					else {
172
						$row[$k]=utf8_decode($v);
173
					}
174
				}
175
 
176
 
177
			  	if ($row['date_observation']!="0000-00-00 00:00:00") {
178
	                list($year,$month,$day)= split ('-',$row['date_observation']);
179
    	            list($day)= split (' ',$day);
180
	                $row['date_observation']=$day."/".$month."/".$year;
181
	        	}
182
	        	else {
183
	                $row['date_observation']="00/00/0000";
184
	        	}
185
 
186
 
187
                $worksheet->write($i,0,$row['nom_sel']);
188
                $worksheet->write($i,1,$row['num_nom_sel']);
189
                $worksheet->write($i,2,$row['nom_ret']);
190
                $worksheet->write($i,3,$row['num_nom_ret']);
191
                $worksheet->write($i,4,$row['num_taxon']);
192
                $worksheet->write($i,5,$row['famille']);
193
                $worksheet->write($i,6,$row['location']);
194
                $worksheet->write($i,7,$row['id_location']);
195
                $worksheet->write($i,8,$row['date_observation']);
196
                $worksheet->write($i,9,$row['lieudit']);
197
                $worksheet->write($i,10,$row['station']);
198
                $worksheet->write($i,11,$row['milieu']);
199
                $worksheet->write($i,12,$row['commentaire']);
200
                $worksheet->write($i,13,$row['coord_x']);
201
                $worksheet->write($i,14,$row['coord_y']);
202
                $worksheet->write($i,15,$row['ref_geo']);
203
                $i++;
204
    	    }
205
 
206
			$workbook->close();
207
 
208
			exit();
209
 
210
 
211
	}
212
 
213
 
214
 
215
}
216
 
217
 
218
/* +--Fin du code ---------------------------------------------------------------------------------------+
219
* $Log$
220
* Revision 1.7  2008-11-13 11:29:12  ddelon
221
* Reecriture gwt-ext
222
*
223
* Revision 1.6  2008-01-30 08:57:28  ddelon
224
* fin mise en place mygwt
225
*
226
* Revision 1.5  2007-06-06 13:31:16  ddelon
227
* v0.09
228
*
229
* Revision 1.4  2007-05-22 12:54:09  ddelon
230
* Securisation acces utilisateur
231
*
232
*
233
*
234
*/
235
 
236
 
237
?>