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();
|
624 |
aurelien |
29 |
$this->controleUtilisateur($uid[0]);
|
416 |
aurelien |
30 |
|
|
|
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 |
|
|
|
123 |
$res =& $DB->query($query);
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
if (DB::isError($res)) {
|
|
|
127 |
die($res->getMessage());
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
|
132 |
// Creating a workbook
|
|
|
133 |
$workbook = new Spreadsheet_Excel_Writer();
|
|
|
134 |
|
|
|
135 |
|
540 |
david |
136 |
$workbook->send('liste.xls');
|
|
|
137 |
|
416 |
aurelien |
138 |
// Creating a worksheet
|
|
|
139 |
$worksheet = $workbook->addWorksheet('Liste');
|
624 |
aurelien |
140 |
|
|
|
141 |
$worksheet->write(0,0,'Espece');
|
416 |
aurelien |
142 |
$worksheet->write(0,1,'Numero nomenclatural');
|
|
|
143 |
$worksheet->write(0,2,'Nom retenu');
|
|
|
144 |
$worksheet->write(0,3,'Numero nomenclatural nom retenu');
|
|
|
145 |
$worksheet->write(0,4,'Numero taxonomique');
|
|
|
146 |
$worksheet->write(0,5,'Famille');
|
|
|
147 |
$worksheet->write(0,6,'Commune');
|
|
|
148 |
$worksheet->write(0,7,'Identifiant Commune');
|
624 |
aurelien |
149 |
$worksheet->write(0,8,'Date');
|
|
|
150 |
$worksheet->write(0,9,'Lieu-dit');
|
416 |
aurelien |
151 |
$worksheet->write(0,10,'Station');
|
|
|
152 |
$worksheet->write(0,11,'Milieu');
|
624 |
aurelien |
153 |
$worksheet->write(0,12,'Notes');
|
|
|
154 |
$worksheet->write(0,13,'Latitude');
|
|
|
155 |
$worksheet->write(0,14,'Longitude');
|
416 |
aurelien |
156 |
$worksheet->write(0,15,'Referentiel Geographique');
|
|
|
157 |
|
|
|
158 |
|
|
|
159 |
|
|
|
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 |
}
|
|
|
172 |
|
|
|
173 |
|
|
|
174 |
if ($row['date_observation']!="0000-00-00 00:00:00") {
|
|
|
175 |
list($year,$month,$day)= split ('-',$row['date_observation']);
|
|
|
176 |
list($day)= split (' ',$day);
|
|
|
177 |
$row['date_observation']=$day."/".$month."/".$year;
|
|
|
178 |
}
|
|
|
179 |
else {
|
|
|
180 |
$row['date_observation']="00/00/0000";
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
|
|
|
184 |
$worksheet->write($i,0,$row['nom_sel']);
|
|
|
185 |
$worksheet->write($i,1,$row['num_nom_sel']);
|
|
|
186 |
$worksheet->write($i,2,$row['nom_ret']);
|
|
|
187 |
$worksheet->write($i,3,$row['num_nom_ret']);
|
|
|
188 |
$worksheet->write($i,4,$row['num_taxon']);
|
|
|
189 |
$worksheet->write($i,5,$row['famille']);
|
|
|
190 |
$worksheet->write($i,6,$row['location']);
|
|
|
191 |
$worksheet->write($i,7,$row['id_location']);
|
|
|
192 |
$worksheet->write($i,8,$row['date_observation']);
|
|
|
193 |
$worksheet->write($i,9,$row['lieudit']);
|
|
|
194 |
$worksheet->write($i,10,$row['station']);
|
|
|
195 |
$worksheet->write($i,11,$row['milieu']);
|
|
|
196 |
$worksheet->write($i,12,$row['commentaire']);
|
|
|
197 |
$worksheet->write($i,13,$row['coord_x']);
|
|
|
198 |
$worksheet->write($i,14,$row['coord_y']);
|
|
|
199 |
$worksheet->write($i,15,$row['ref_geo']);
|
|
|
200 |
$i++;
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
$workbook->close();
|
|
|
204 |
|
|
|
205 |
exit();
|
|
|
206 |
|
|
|
207 |
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
|
|
|
211 |
|
|
|
212 |
}
|
|
|
213 |
|
|
|
214 |
|
|
|
215 |
/* +--Fin du code ---------------------------------------------------------------------------------------+
|
|
|
216 |
* $Log$
|
|
|
217 |
* Revision 1.7 2008-11-13 11:29:12 ddelon
|
|
|
218 |
* Reecriture gwt-ext
|
|
|
219 |
*
|
|
|
220 |
* Revision 1.6 2008-01-30 08:57:28 ddelon
|
|
|
221 |
* fin mise en place mygwt
|
|
|
222 |
*
|
|
|
223 |
* Revision 1.5 2007-06-06 13:31:16 ddelon
|
|
|
224 |
* v0.09
|
|
|
225 |
*
|
|
|
226 |
* Revision 1.4 2007-05-22 12:54:09 ddelon
|
|
|
227 |
* Securisation acces utilisateur
|
|
|
228 |
*
|
|
|
229 |
*
|
|
|
230 |
*
|
|
|
231 |
*/
|
|
|
232 |
|
|
|
233 |
|
|
|
234 |
?>
|