Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 449 Rev 480
Line 1... Line 1...
1
<?php
1
<?php
Line 2... Line 2...
2
 
2
 
3
// In : utf8
3
// In : utf8
Line -... Line 4...
-
 
4
// Out : utf8
-
 
5
 
-
 
6
/*
-
 
7
 
-
 
8
Octobre 2010 David Delon.
-
 
9
Import d'observations dans le carnet en ligne à partir d'un fichier excel chargé par l'utilisateur
-
 
10
et liaison d'images déjà chargee aux observations ainsi crées.
4
// Out : utf8
11
 
-
 
12
Nom des colonnes imposé, mais présence de toutes les colonnes non obligatoires, ordre non imposé
-
 
13
Aucune valeur dans les colonnes n'est obligatoire
-
 
14
Pour une ligne donnée, si tous les champs vides on ne fait rien, ou si seul le champ image est présent.
Line 5... Line -...
5
 
-
 
6
// Import depuis une feuille de calcul
15
Si la seule différence entre deux lignes est la valeur de la colonne image, on considère que c'est la même observation à laquelle on associe plusieurs images.
7
 
-
 
8
// Test fonction d'import
-
 
Line 9... Line 16...
9
// Import de base
16
Si au moins deux lignes (ou plus) sont complètement identiques on prend en compte une seule ligne (les doublons sont éliminés).
Line 10... Line 17...
10
// TODO : soigner les controles ...
17
 
11
// Scenario avance
18
*/
12
 
19
 
13
 
20
 
Line 22... Line 29...
22
define('NOTES','notes'); // Texte libre
29
define('NOTES','notes'); // Texte libre
23
define('DATEOBS','date'); // date au format jj/mm/aaaa
30
define('DATEOBS','date'); // date au format jj/mm/aaaa
24
define('ESPECE','espece'); // texte libre, nom latin, ou code nomenclatural (format BDNFFnn999999)
31
define('ESPECE','espece'); // texte libre, nom latin, ou code nomenclatural (format BDNFFnn999999)
25
define('IMAGE','image'); //  nom des fichiers images préalablement uploadés sur le CEL séparés par des "/"
32
define('IMAGE','image'); //  nom des fichiers images préalablement uploadés sur le CEL séparés par des "/"
Line 26... Line 33...
26
 
33
 
27
// Resultat analyse ligne // TODO : Classe ?
34
// Resultat de l'analyse d'une ligne
28
define('LIGNE_VIDE',1); //  
35
define('LIGNE_VIDE',1); //  
29
define('LIGNE_NORMALE',2); //  
36
define('LIGNE_NORMALE',2); //  
Line 30... Line 37...
30
define('LIGNE_IMAGE_SEULEMENT',3); //  
37
define('LIGNE_IMAGE_SEULEMENT',3); //  
Line 37... Line 44...
37
Class InventoryImportExcel extends DBAccessor  {
44
Class InventoryImportExcel extends DBAccessor  {
Line 38... Line 45...
38
 
45
 
Line 39... Line 46...
39
// Element constituant une observation 
46
// Element constituant une observation 
-
 
47
 
-
 
48
	var $format_observation=array(COMMUNE ,LIEUDIT ,STATION ,MILIEU ,LATITUDE ,LONGITUDE ,NOTES ,DATEOBS ,ESPECE ,IMAGE );
-
 
49
 
40
 
50
 
-
 
51
// Fichier configuration
-
 
52
	var $config;
-
 
53
 
41
	var $format_observation=array(COMMUNE ,LIEUDIT ,STATION ,MILIEU ,LATITUDE ,LONGITUDE ,NOTES ,DATEOBS ,ESPECE ,IMAGE );
54
// Encapsulation classe lecture fichier excel
Line -... Line 55...
-
 
55
 
-
 
56
	var $extendExcelReader;
-
 
57
 
42
	var $config;
58
/**
Line 43... Line 59...
43
	var $extendExcelReader;
59
 Constructeur
44
 
60
**/
Line 45... Line 61...
45
	function InventoryImportExcel($config) {
61
	function InventoryImportExcel($config) {
46
 
62
 
47
		$this->config=$config;
63
		$this->config=$config;
Line -... Line 64...
-
 
64
		// Pas d'heritage multiple en php :(
-
 
65
 
48
		// Pas d'heritage multiple en php :(
66
		$this->extendExcelReader = new ExcelReader();
49
 
67
		$this->extendExcelReader->initExcelReader();
Line 50... Line -...
50
		$this->extendExcelReader = new ExcelReader();
-
 
Line -... Line 68...
-
 
68
	}
Line -... Line 69...
-
 
69
 
51
		$this->extendExcelReader->initExcelReader();
70
/**
52
	}
71
 Sur post
-
 
72
**/
Line 53... Line 73...
53
 
73
	function createElement($pairs) {
Line 54... Line 74...
54
 
74
 
55
	function createElement($pairs) {
75
 
Line 56... Line 76...
56
 
76
		$pairs['utilisateur']=$_POST['identifiant'];
Line 57... Line 77...
57
		// uid[0] : utilisateur obligatoire
77
			
58
 
-
 
59
			
78
 
-
 
79
		session_start();
60
		session_start();
80
                $this->controleUtilisateur($pairs['utilisateur']);
61
                $this->controleUtilisateur($pairs['identifiant']);
81
 
Line 62... Line 82...
62
 
82
 
63
                foreach($_FILES as $file) { // FIXME : est necessaire
83
		foreach($_FILES as $file) { // C'est le plus simple
Line 82... Line 102...
82
	        for($row=1;$row<=$rowcount;$row++) 
102
	        for($row=1;$row<=$rowcount;$row++) 
83
        	        for($col=1;$col<=$colcount;$col++) 
103
        	        for($col=1;$col<=$colcount;$col++) 
84
                	        $arr[$col][$row] = $data->val($row,$col,0);
104
                	        $arr[$col][$row] = $data->val($row,$col,0);
Line 85... Line -...
85
 
-
 
Line 86... Line 105...
86
 
105
 
Line 87... Line 106...
87
		//print_r($arr);
106
 
Line 126... Line 145...
126
		print_r($line[IMAGE]);
145
		print_r($line[IMAGE]);
127
	*/
146
	*/
Line 128... Line 147...
128
 
147
 
Line 129... Line 148...
129
// 1 : Traitement lignes
148
// 1 : Traitement lignes
130
 
149
 
131
		for ($i=0;$i<=$colcount-1;$i++) {
150
		for ($i=0;$i<=$rowcount-1;$i++) {
-
 
151
			// On saute les lignes vides du debut et les lignes contenant des information sur image uniquement
-
 
152
			while ((in_array($retour_analyse=$this->analyserLigne($line,$i),array(LIGNE_IMAGE_SEULEMENT, LIGNE_VIDE))) && ($i<=$rowcount)) {
-
 
153
				if  ($retour_analyse==LIGNE_IMAGE_SEULEMENT) {
-
 
154
	//				print "image non rattachee a une observation";
132
			// On saute les lignes vides 
155
				}
-
 
156
				else {
133
			while (($this->analyserLigne($line,$i)==LIGNE_VIDE) && ($i<=$colcount)) {
157
	//				print "vide";
134
				print "vide";
158
				}
135
				$i++;
159
				$i++;
136
			}
160
			}
137
			while (($this->analyserLigne($line,$i)==LIGNE_NORMALE) && ($i<=$colcount)) {
161
			while (($this->analyserLigne($line,$i)==LIGNE_NORMALE) && ($i<=$rowcount)) {
-
 
162
				$ordre=$this->traiterLigne($line,$i,$pairs['utilisateur']);
138
				$this->traiterLigne($line,$i);
163
				$i++;
139
				$i++;
164
				// On saute les lignes vide ou on traite les lignes suivantes contenant des informations sur image seulement
140
				while ((in_array($retour_analyse=$this->analyserLigne($line,$i),array(LIGNE_IMAGE_SEULEMENT, LIGNE_VIDE))) && ($i<=$colcount)) {
165
				while ((in_array($retour_analyse=$this->analyserLigne($line,$i),array(LIGNE_IMAGE_SEULEMENT, LIGNE_VIDE))) && ($i<=$rowcount)) {
141
					if  ($retour_analyse==LIGNE_IMAGE_SEULEMENT) {
166
					if  ($retour_analyse==LIGNE_IMAGE_SEULEMENT) {
142
						$this->traiterLigneComplement($line,$i);
167
						$this->traiterLigneComplement($line,$i,$pairs['utilisateur'],$ordre); // images supplementaires
143
					}
168
					}
144
					else {
169
					else {
145
						print "vide";
170
	//					print "vide";
146
					}
171
					}
147
					$i++;
172
					$i++;
Line 148... Line -...
148
				}	
-
 
Line 149... Line 173...
149
			}
173
				}	
Line 150... Line 174...
150
			
174
			}
Line 181... Line 205...
181
	}
205
	}
Line 182... Line 206...
182
	
206
	
Line 183... Line 207...
183
 
207
 
-
 
208
}
184
}
209
 
185
 
210
function traiterLigne($line,$i,$utilisateur) { // Controle donnee et insertion
186
function traiterLigne($line,$i) {
211
	$info_image=array();
187
	foreach ($this->format_observation as $colonne) {
212
	foreach ($this->format_observation as $colonne) {
188
		if (isset ($line[$colonne][$i]) && $line[$colonne][$i]!='') {
213
		if (isset ($line[$colonne][$i]) && $line[$colonne][$i]!='') {
189
			switch ($colonne) {  // On ne garde que les colonnes que l'on souhaite traiter
-
 
190
				case COMMUNE:
-
 
191
					$info_commune=$this->traiterCommune($line[COMMUNE][$i]);
214
			switch ($colonne) {  // On ne garde que les colonnes que l'on souhaite traiter
192
					echo $info_commune['name'];	
215
				case COMMUNE:
193
					echo $info_commune['code'];	
216
					$info_commune=$this->traiterCommune($line[COMMUNE][$i]);
194
					break;
217
					break;
195
				case LIEUDIT:
218
				case LIEUDIT:
196
					$this->traiterLieudit($line[LIEUDIT][$i]);
219
					$info_lieudit=$this->traiterLieudit($line[LIEUDIT][$i]);
197
					break;
220
					break;
198
				case STATION:
221
				case STATION:
199
					$this->traiterStation($line[STATION][$i]);
222
					$info_station=$this->traiterStation($line[STATION][$i]);
200
					break;
223
					break;
201
				case MILIEU:
224
				case MILIEU:
202
					$this->traiterMilieu($line[MILIEU][$i]);
225
					$info_milieu=$this->traiterMilieu($line[MILIEU][$i]);
203
					break;
226
					break;
204
				case LATITUDE:
227
				case LATITUDE:
205
					$this->traiterLatitude($line[LATITUDE][$i]);
228
					$info_latitude=$this->traiterLatitude($line[LATITUDE][$i]);
206
					break;
229
					break;
207
				case LONGITUDE:
230
				case LONGITUDE:
208
					$this->traiterLongitude($line[LONGITUDE][$i]);
231
					$info_longitude=$this->traiterLongitude($line[LONGITUDE][$i]);
209
					break;
232
					break;
210
				case NOTES:
233
				case NOTES:
211
					$this->traiterNotes($line[NOTES][$i]);
234
					$info_notes=$this->traiterNotes($line[NOTES][$i]);
212
					break;
235
					break;
213
				case DATEOBS:
236
				case DATEOBS:
214
					$this->traiterDateObs($line[DATEOBS][$i]);
237
					$info_dateobs=$this->traiterDateObs($line[DATEOBS][$i]);
-
 
238
					break;
-
 
239
				case ESPECE:
-
 
240
					$info_espece=$this->traiterEspece($line[ESPECE][$i]);
-
 
241
					if (isset($info_espece['en_id_nom']) && $info_espece['en_id_nom']!='') {
-
 
242
						$complement=$this->rechercherInformationsComplementaires($info_espece['en_id_nom']);
-
 
243
						$info_espece['nom_ret']=$complement['Nom_Retenu'];
-
 
244
	        	                        $info_espece['num_nom_ret']=$complement['Num_Nom_Retenu'];
-
 
245
        	        	                $info_espece['num_taxon']=$complement['Num_Taxon'];
-
 
246
                	        	        $info_espece['famille']=$complement['Famille'];
215
					break;
247
					}
216
				case ESPECE:
248
 
217
					$this->traiterEspece($line[ESPECE][$i]);
249
 
218
					break;
250
					break;
219
				case IMAGE:
251
				case IMAGE:
220
					$this->traiterImage($line[IMAGE][$i]);
-
 
221
					break;
252
					$info_image=$this->traiterImage($line[IMAGE][$i],$utilisateur); // Image separee par des / +  utilisateur
-
 
253
					break;
-
 
254
			}
-
 
255
		}
-
 
256
		else {	
-
 
257
		 	switch($colonne) {
-
 
258
				case COMMUNE:
-
 
259
					$info_commune['name']="000null";
-
 
260
					$info_commune['code']="000null";
-
 
261
					break;
-
 
262
				case LIEUDIT:
-
 
263
					$info_lieudit="000null";
-
 
264
					break;
-
 
265
				case STATION:
-
 
266
					$info_station="000null";
-
 
267
					break;
-
 
268
				case MILIEU:
-
 
269
					$info_milieu="000null";
-
 
270
					break;
-
 
271
				case LATITUDE:
-
 
272
					$info_latitude="000null";
-
 
273
					break;
-
 
274
				case LONGITUDE:
-
 
275
					$info_longitude="000null";
-
 
276
					break;
-
 
277
 
-
 
278
			}
-
 
279
 
-
 
280
		}
-
 
281
	}
-
 
282
 
-
 
283
                // Dernier numero d'ordre utilise :
-
 
284
 
-
 
285
                $DB=$this->connectDB($this->config,'database_cel'); // TODO / a garder en memoire pour eviter appels mutliples
-
 
286
                $query="SELECT MAX(ordre) AS ordre FROM cel_inventory WHERE identifiant='".$DB->escapeSimple($utilisateur)."' ";
-
 
287
 
-
 
288
                $res =& $DB->query($query);
-
 
289
                if (DB::isError($res)) {
-
 
290
                        die($res->getMessage());
-
 
291
                }
-
 
292
                $ordre=0;
-
 
293
 
-
 
294
                while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
-
 
295
                    $ordre=$row['ordre']+1;
-
 
296
                }
-
 
297
 
-
 
298
                list($jour,$mois,$annee)=split("/",$info_dateobs);
-
 
299
                $info_dateobs=$annee."-".$mois."-".$jour." 0:0:0";
-
 
300
 
-
 
301
 
-
 
302
	 $query  = "INSERT INTO cel_inventory (identifiant,ordre,nom_sel,num_nom_sel,nom_ret,num_nom_ret,num_taxon,famille,location,id_location,date_observation,lieudit,station, milieu, commentaire, date_creation,date_modification,coord_x,coord_y) " .
-
 
303
                " VALUES('".$DB->escapeSimple($utilisateur)."','".
-
 
304
                $DB->escapeSimple($ordre)."','".
-
 
305
                $DB->escapeSimple($info_espece['nom_sel'])."','".
-
 
306
                $DB->escapeSimple($info_espece['en_id_nom'])."','".
-
 
307
                $DB->escapeSimple($info_espece['nom_ret'])."','".
-
 
308
                $DB->escapeSimple($info_espece['num_nom_ret'])."','".
-
 
309
                $DB->escapeSimple($info_espece['num_taxon'])."','".
-
 
310
                $DB->escapeSimple($info_espece['famille'])."','".
-
 
311
                $DB->escapeSimple($info_commune['name'])."','".
-
 
312
                $DB->escapeSimple($info_commune['code'])."','".
-
 
313
                $DB->escapeSimple($info_dateobs)."','".
-
 
314
                $DB->escapeSimple($info_lieudit)."','".
-
 
315
                $DB->escapeSimple($info_station)."','".
-
 
316
                $DB->escapeSimple($info_milieu)."','".
-
 
317
                $DB->escapeSimple($info_notes)."',".
-
 
318
                "now() , now(),'".
-
 
319
                $DB->escapeSimple($info_latitude)."','".
-
 
320
                $DB->escapeSimple($info_longitude)."')";
-
 
321
//		print $query;
-
 
322
//		print "\n";
-
 
323
 
-
 
324
 
-
 
325
		   $res =& $DB->query($query);
-
 
326
 
-
 
327
                if (PEAR::isError($res)) {
-
 
328
                        return false;
-
 
329
                }
-
 
330
		
-
 
331
 
-
 
332
	// creation lien image
-
 
333
	foreach ($info_image as $pic) {
-
 
334
 
-
 
335
		$query = 'INSERT INTO cel_obs_images (coi_ce_image, coi_ce_utilisateur, coi_ce_observation) VALUES ("'.$DB->escapeSimple($pic['ci_id_image']).'","'.$DB->escapeSimple($utilisateur).'",    "'.$DB->escapeSimple($ordre).'") ON DUPLICATE KEY UPDATE coi_ce_image = coi_ce_image' ;	
-
 
336
	
-
 
337
//print $query;
-
 
338
 
-
 
339
		$res =& $DB->query($query);
-
 
340
 
-
 
341
                if (PEAR::isError($res)) {
-
 
342
                        return false;
222
			}
343
                }
Line -... Line 344...
-
 
344
		
-
 
345
 
-
 
346
	}
-
 
347
 
-
 
348
 
223
			print "\n";
349
 
Line 224... Line 350...
224
		}
350
		return $ordre;
225
	}
-
 
-
 
351
 
226
 
352
 
Line 227... Line 353...
227
}
353
}
228
 
354
 
Line 229... Line -...
229
function traiterLigneComplement($line,$i) {
-
 
Line 230... Line 355...
230
	$this->traiterImage($line[IMAGE][$i]);
355
function traiterLigneComplement($line,$i,$utilisateur) {
Line 231... Line 356...
231
	print "\n";
356
 
Line 246... Line 371...
246
 
371
 
247
	if ($elements[1]) { // departement present
372
	if ($elements[1]) { // departement present
248
		$nom_commune=$elements[1];
373
		$nom_commune=$elements[1];
Line 249... Line 374...
249
		$code_commune=$elements[2];
374
		$code_commune=$elements[2];
Line 250... Line 375...
250
 
375
 
251
 	        $query="SELECT DISTINCT name, code  FROM locations WHERE name = '".$DB->escapeSimple($nom_commune)."%' AND code ='".$DB->escapeSimple($code_commune)."'";
376
 	        $query="SELECT DISTINCT name, code  FROM locations WHERE name = '".$DB->escapeSimple($nom_commune)."' AND code ='".$DB->escapeSimple($code_commune)."'";
252
 
377
 
253
	}
378
	}
Line 280... Line 405...
280
 
405
 
Line 281... Line 406...
281
}
406
}
Line 282... Line 407...
282
 
407
 
-
 
408
function traiterLieudit($lieudit) { // texte libre
283
function traiterLieudit($lieudit) { // texte libre
409
 
284
 
410
	//echo "traitement lieudit";
Line 285... Line 411...
285
	echo "traitement lieudit";
411
 
286
	return utf8_encode(ltrim($lieudit));
412
	return utf8_encode(ltrim($lieudit));
287
}
413
}
288
 
414
 
Line 289... Line 415...
289
function traiterStation($station) { // texte libre
415
function traiterStation($station) { // texte libre
290
	echo "traitement station";
416
//	echo "traitement station";
291
	return utf8_encode(ltrim($station));
417
	return utf8_encode(ltrim($station));
292
}
418
}
Line 293... Line 419...
293
 
419
 
294
function traiterMilieu($milieu) { // texte libre
420
function traiterMilieu($milieu) { // texte libre
295
	echo "traitement milieu";
421
//	echo "traitement milieu";
296
	return utf8_encode(ltrim($milieu));
422
	return utf8_encode(ltrim($milieu));
Line 297... Line 423...
297
}
423
}
298
 
424
 
299
function traiterLatitude($latitude) {	//  verifier formal decimal + limite france ? TODO 
425
function traiterLatitude($latitude) {	//  verifier formal decimal + limite france ? TODO 
300
	echo "traitement latitude";
426
//	echo "traitement latitude";
Line 301... Line 427...
301
	return ltrim($latitude);
427
	return ltrim($latitude);
302
}
428
}
303
 
429
 
304
function traiterLongitude($longitude) { // verifier format decimal + limite france ? TODO 
430
function traiterLongitude($longitude) { // verifier format decimal + limite france ? TODO 
Line 305... Line 431...
305
	echo "traitement longitude";
431
//	echo "traitement longitude";
306
	return ltrim($longitude);
432
	return ltrim($longitude);
307
}
433
}
308
 
434
 
Line 309... Line 435...
309
function traiterNotes($notes) { // texte libre
435
function traiterNotes($notes) { // texte libre
Line 310... Line 436...
310
	echo "traitement notes";
436
//	echo "traitement notes";
311
	return utf8_encode(ltrim($notes));
437
	return utf8_encode(ltrim($notes));
Line 312... Line 438...
312
}
438
}
Line 313... Line 439...
313
 
439
 
Line 314... Line 440...
314
function traiterDateObs($dateobs) { // verifier jj/mm/aaaa sinon date vide TODO 
440
function traiterDateObs($dateobs) { // verifier jj/mm/aaaa sinon date vide TODO 
Line 315... Line -...
315
	echo "traitement dateobs";
-
 
Line -... Line 441...
-
 
441
//	echo "traitement dateobs";
-
 
442
	return ltrim($dateobs);
316
	return ltrim($notes);
443
}
317
}
444
 
318
 
445
function traiterEspece($identifiant_espece) {  // texte libre, nom scientifique , ou code nomenclatural (format BDNFFnn999999)
319
function traiterEspece($identifiant_espece) {  // texte libre, nom scientifique , ou code nomenclatural (format BDNFFnn999999)
446
 
320
 
447
//	echo "traitement  espece";
321
	echo "traitement  espece";
448
        $identifiant_espece=ltrim($identifiant_espece);
322
        $identifiant_espece=ltrim($identifiant_espece);
449
 
323
 
450
        $identifiant_espece=utf8_encode($identifiant_espece); // FIXME : devrait deja etre en utf8 a ce niveau
324
        $identifiant_espece=utf8_encode($identifiant_espece); // FIXME : devrait deja etre en utf8 a ce niveau
451
 
325
 
452
	preg_match('/BDNFFnn([0-9][0-9]*)/',$identifiant_espece,$elements);
326
	preg_match('/BDNFFnn([0-9][0-9]*)/',$identifiant_espece,$elements);
453
 
327
 
454
		if ($elements[1]) { // Numero nomenclatural 
328
		if ($elements[1]) { // Numero nomenclatural 
455
 
329
 
456
 
330
	 	$DB=$this->connectDB($this->config);
457
// Recherche du nom associe
331
 
458
                        $DB=$this->connectDB($this->config); // FIXME : gerer cache de connection
332
                    $query = "SELECT DISTINCT en_nom_genre, en_epithete_espece, en_nom_supra_generique, en_epithete_infra_generique,".
459
                                      $query = "SELECT DISTINCT en_nom_genre, en_epithete_espece, en_nom_supra_generique, en_epithete_infra_generique,".
333
                                        "   auteur_bex.enaia_intitule_abrege AS abreviation_auteur_basio_ex ".
460
                                        "   auteur_bex.enaia_intitule_abrege AS abreviation_auteur_basio_ex ".
334
                                        " , auteur_b.enaia_intitule_abrege AS abreviation_auteur_basio ".
461
                                        " , auteur_b.enaia_intitule_abrege AS abreviation_auteur_basio ".
335
                                        " , auteur_mex.enaia_intitule_abrege AS abreviation_auteur_modif_ex ".
462
                                        " , auteur_mex.enaia_intitule_abrege AS abreviation_auteur_modif_ex ".
-
 
463
                                        " , auteur_m.enaia_intitule_abrege AS abreviation_auteur_modif ".
-
 
464
                                        " , en_epithete_espece, en_epithete_infra_specifique, enrg_abreviation_rang, en_id_nom" .
-
 
465
                                        " FROM eflore_nom, eflore_nom_rang, eflore_selection_nom a,  " .
-
 
466
                                        "         eflore_naturaliste_intitule_abreviation AS auteur_bex ".
-
 
467
                                        "   , eflore_naturaliste_intitule_abreviation AS auteur_b ".
-
 
468
                                        "   , eflore_naturaliste_intitule_abreviation AS auteur_mex ".
-
 
469
                                        "   , eflore_naturaliste_intitule_abreviation AS auteur_m ".
-
 
470
				     	" WHERE a.esn_id_nom= '".$elements[1]. "'".
-
 
471
					" AND a.esn_id_version_projet_taxon = 25 ".
-
 
472
				    	" AND en_ce_rang = enrg_id_rang" .
-
 
473
				     	" AND en_id_nom = a.esn_id_nom" .
336
                                        " , auteur_m.enaia_intitule_abrege AS abreviation_auteur_modif ".
474
				     	" AND en_ce_auteur_basio_ex = auteur_bex.enaia_id_intitule_naturaliste_abrege ".
Line 337... Line 475...
337
                                        " , en_epithete_espece, en_epithete_infra_specifique, enrg_abreviation_rang, en_id_nom" .
475
				        " AND en_ce_auteur_basio = auteur_b.enaia_id_intitule_naturaliste_abrege  ".
Line 338... Line 476...
338
                                        " FROM eflore_nom, eflore_nom_rang, eflore_selection_nom a,  " .
476
		                        " AND en_ce_auteur_modif_ex = auteur_mex.enaia_id_intitule_naturaliste_abrege ".
339
                                        "         eflore_naturaliste_intitule_abreviation AS auteur_bex ".
477
                   		        " AND en_ce_auteur_modif = auteur_m.enaia_id_intitule_naturaliste_abrege ".
340
                                            "   , eflore_naturaliste_intitule_abreviation AS auteur_b ".
-
 
Line 341... Line 478...
341
                                            "   , eflore_naturaliste_intitule_abreviation AS auteur_mex ".
478
                                        " AND a.esn_id_version_projet_taxon=en_id_version_projet_nom ";
Line 342... Line 479...
342
                                            "   , eflore_naturaliste_intitule_abreviation AS auteur_m ".
479
		
343
                             " WHERE a.esn_id_nom= '".$elements[1]. "'".
480
				    	$res =& $DB->query($query);
Line 389... Line 526...
389
    [nom_superieur] => monspessulanum
526
    [nom_superieur] => monspessulanum
390
    [agg] => 
527
    [agg] => 
391
    [nom_complet] => Acer monspessulanum subsp. monspessulanum
528
    [nom_complet] => Acer monspessulanum subsp. monspessulanum
Line 392... Line 529...
392
 
529
 
393
*/
-
 
Line -... Line 530...
-
 
530
*/
-
 
531
 
-
 
532
 
-
 
533
        		$DB=$this->connectDB($this->config); // FIXME regarder si opportun ici
-
 
534
 
-
 
535
                      	$query="SELECT DISTINCT en_id_nom" .
-
 
536
                                        " FROM eflore_nom, eflore_nom_rang " .
-
 
537
                                        " WHERE en_id_version_projet_nom = '25' AND en_nom_genre = '".$DB->escapeSimple($nom_latin_decoupe['nom_genre'])."' " .
-
 
538
                                        " AND en_ce_rang = '".$DB->escapeSimple($nom_latin_decoupe['rang_taxonomique'])."' " ;
-
 
539
					if (isset($nom_latin_decoupe['nom_infrasp']) && $nom_latin_decoupe['nom_infrasp']!="") {
-
 
540
						$query.=" AND en_epithete_infra_specifique = '".$DB->escapeSimple($nom_latin_decoupe['nom_infrasp'])."' " ;
-
 
541
					}
-
 
542
                                        $query.=" AND en_epithete_espece =  '".$DB->escapeSimple($nom_latin_decoupe['nom_sp'])."' AND en_ce_rang = enrg_id_rang " .
-
 
543
                                        " LIMIT 1";
-
 
544
 
-
 
545
 
-
 
546
			}
-
 
547
 
-
 
548
			$res =& $DB->query($query);
-
 
549
 
-
 
550
			if (DB::isError($res)) {
-
 
551
				 die($res->getMessage());
-
 
552
			}
-
 
553
 
-
 
554
			$id_nom=$res->fetchrow(DB_FETCHMODE_ASSOC);
394
/*
555
 
395
 
556
			// Recherche du nom associe
396
 
557
                        $DB=$this->connectDB($this->config); // FIXME : gerer cache de connection
397
                      	$query="SELECT DISTINCT en_nom_genre, en_epithete_espece, en_nom_supra_generique, en_epithete_infra_generique,".
558
                                      $query = "SELECT DISTINCT en_nom_genre, en_epithete_espece, en_nom_supra_generique, en_epithete_infra_generique,".
398
                                        "   auteur_bex.enaia_intitule_abrege AS abreviation_auteur_basio_ex ".
559
                                        "   auteur_bex.enaia_intitule_abrege AS abreviation_auteur_basio_ex ".
399
                                        " , auteur_b.enaia_intitule_abrege AS abreviation_auteur_basio ".
560
                                        " , auteur_b.enaia_intitule_abrege AS abreviation_auteur_basio ".
400
                                        " , auteur_mex.enaia_intitule_abrege AS abreviation_auteur_modif_ex ".
561
                                        " , auteur_mex.enaia_intitule_abrege AS abreviation_auteur_modif_ex ".
401
                                        " , auteur_m.enaia_intitule_abrege AS abreviation_auteur_modif ".
562
                                        " , auteur_m.enaia_intitule_abrege AS abreviation_auteur_modif ".
402
                                        " , en_epithete_espece, en_epithete_infra_specifique, enrg_abreviation_rang, en_id_nom, esn_ce_statut" .
563
                                        " , en_epithete_espece, en_epithete_infra_specifique, enrg_abreviation_rang, en_id_nom" .
403
                                        " FROM eflore_nom, eflore_nom_rang, " .
564
                                        " FROM eflore_nom, eflore_nom_rang, eflore_selection_nom a,  " .
404
                                        "         eflore_naturaliste_intitule_abreviation AS auteur_bex ".
565
                                        "         eflore_naturaliste_intitule_abreviation AS auteur_bex ".
405
                                        "   , eflore_naturaliste_intitule_abreviation AS auteur_b ".
566
                                        "   , eflore_naturaliste_intitule_abreviation AS auteur_b ".
406
                                        "   , eflore_naturaliste_intitule_abreviation AS auteur_mex ".
567
                                        "   , eflore_naturaliste_intitule_abreviation AS auteur_mex ".
407
                                        "   , eflore_naturaliste_intitule_abreviation AS auteur_m ".
568
                                        "   , eflore_naturaliste_intitule_abreviation AS auteur_m ".
408
                                "   , eflore_selection_nom".
569
				     	" WHERE a.esn_id_nom= '".$id_nom['en_id_nom']. "'".
409
                                        " WHERE en_id_version_projet_nom = '25' AND en_nom_genre = '".$DB->escapeSimple($nom_latin_decoupe['nom_genre'])."' " .
570
					" AND a.esn_id_version_projet_taxon = 25 ".
410
                                        " AND en_ce_rang = '".$DB->escapeSimple($nom_latin_decoupe['rang_taxonomique'])."' " .
571
				    	" AND en_ce_rang = enrg_id_rang" .
411
                                        " AND en_epithete_espece =  '".$DB->escapeSimple($nom_latin_decoupe['nom_sp'])."' AND en_ce_rang = enrg_id_rang " .
572
				     	" AND en_id_nom = a.esn_id_nom" .
412
                                        " AND en_ce_auteur_basio_ex = auteur_bex.enaia_id_intitule_naturaliste_abrege ".
573
				     	" AND en_ce_auteur_basio_ex = auteur_bex.enaia_id_intitule_naturaliste_abrege ".
413
                                        " AND en_ce_auteur_basio = auteur_b.enaia_id_intitule_naturaliste_abrege  ".
574
				        " AND en_ce_auteur_basio = auteur_b.enaia_id_intitule_naturaliste_abrege  ".
414
                                        " AND en_ce_auteur_modif_ex = auteur_mex.enaia_id_intitule_naturaliste_abrege ".
575
		                        " AND en_ce_auteur_modif_ex = auteur_mex.enaia_id_intitule_naturaliste_abrege ".
415
                                        " AND en_ce_auteur_modif = auteur_m.enaia_id_intitule_naturaliste_abrege ".
-
 
Line 416... Line 576...
416
                                        " AND esn_id_version_projet_taxon=en_id_version_projet_nom " .
576
                   		        " AND en_ce_auteur_modif = auteur_m.enaia_id_intitule_naturaliste_abrege ".
-
 
577
                                        " AND a.esn_id_version_projet_taxon=en_id_version_projet_nom ";
-
 
578
				$res =& $DB->query($query);
417
                                        " AND esn_id_nom= en_id_nom ".
579
 
-
 
580
 
-
 
581
					if (DB::isError($res)) {
-
 
582
						die($res->getMessage());
-
 
583
					}
-
 
584
 
-
 
585
					$row =& $res->fetchrow(DB_FETCHMODE_ASSOC);
-
 
586
		 			return array("nom_sel"=>$this->formaterNom($row),"en_id_nom"=>$id_nom['en_id_nom']);
Line 418... Line 587...
418
                                        " ORDER BY esn_ce_statut, en_ce_rang, en_epithete_espece, en_nom_genre LIMIT 50";
587
 
Line 419... Line 588...
419
 
588
 
-
 
589
 
420
*/
590
	
-
 
591
 
-
 
592
}
-
 
593
 
-
 
594
 
-
 
595
 
-
 
596
function traiterImage($images,$utilisateur) { // recherche id image de ce nom 
-
 
597
 
-
 
598
	//echo "traitement  image";
-
 
599
        $DB=$this->connectDB($this->config,'cel_db');
-
 
600
 
-
 
601
	$liste_images = explode("/",$images) ;
-
 
602
 
-
 
603
	$row =array();
-
 
604
        foreach($liste_images as $image) {
-
 
605
 
-
 
606
		$query="SELECT * FROM cel_images WHERE ci_ce_utilisateur='".$DB->escapeSimple($utilisateur)."' AND ci_nom_original='".$DB->escapeSimple($image)."'";
-
 
607
 
-
 
608
	        $res  =& $DB->query($query);
-
 
609
		$row [] =& $res->fetchrow(DB_FETCHMODE_ASSOC);
-
 
610
 
421
			}
611
	        if (DB::isError($res)) {
Line 422... Line 612...
422
 
612
        	    die($res->getMessage());
Line -... Line 613...
-
 
613
	        }
-
 
614
 
-
 
615
	}
-
 
616
	return $row;
-
 
617
 
-
 
618
 
-
 
619
}
-
 
620
 
-
 
621
 
-
 
622
// utilitaire : FIXME mutualiser avec autres scripts
-
 
623
 
-
 
624
       function rechercherInformationsComplementaires($numNom) {
-
 
625
 
-
 
626
                $DB=$this->connectDB($this->config);
-
 
627
 
-
 
628
                $query = "SELECT DISTINCT en_nom_genre, en_epithete_espece, en_nom_supra_generique, en_epithete_infra_generique,".
-
 
629
                                                        "   auteur_bex.enaia_intitule_abrege AS abreviation_auteur_basio_ex ".
-
 
630
                                        " , auteur_b.enaia_intitule_abrege AS abreviation_auteur_basio ".
-
 
631
                                        " , auteur_mex.enaia_intitule_abrege AS abreviation_auteur_modif_ex ".
-
 
632
                                        " , auteur_m.enaia_intitule_abrege AS abreviation_auteur_modif ".
-
 
633
                             " , en_epithete_espece, en_epithete_infra_specifique, enrg_abreviation_rang, b.esn_id_taxon, b.esn_id_nom" .
-
 
634
                             " FROM eflore_nom, eflore_nom_rang," .
-
 
635
                                                "         eflore_naturaliste_intitule_abreviation AS auteur_bex ".
-
 
636
                                        "   , eflore_naturaliste_intitule_abreviation AS auteur_b ".
-
 
637
                                        "   , eflore_naturaliste_intitule_abreviation AS auteur_mex ".
-
 
638
                                        "   , eflore_naturaliste_intitule_abreviation AS auteur_m ".
-
 
639
                             " ,eflore_selection_nom a, eflore_selection_nom b".
-
 
640
                             " WHERE a.esn_id_nom= ".$numNom.
-
 
641
                             " AND a.esn_id_version_projet_taxon = 25 ".
-
 
642
                             " AND a.esn_id_taxon=b.esn_id_taxon ".
-
 
643
                             " AND b.esn_ce_statut=3 ".
-
 
644
                             " AND a.esn_id_version_projet_taxon=b.esn_id_version_projet_taxon" .
-
 
645
                             " AND en_ce_rang = enrg_id_rang" .
-
 
646
                             " AND en_id_nom = b.esn_id_nom" .
-
 
647
                             " AND en_ce_auteur_basio_ex = auteur_bex.enaia_id_intitule_naturaliste_abrege ".
-
 
648
                         " AND en_ce_auteur_basio = auteur_b.enaia_id_intitule_naturaliste_abrege  ".
-
 
649
                         " AND en_ce_auteur_modif_ex = auteur_mex.enaia_id_intitule_naturaliste_abrege ".
-
 
650
                     " AND en_ce_auteur_modif = auteur_m.enaia_id_intitule_naturaliste_abrege ".
-
 
651
                             " AND a.esn_id_version_projet_taxon=en_id_version_projet_nom ";
-
 
652
 
-
 
653
 
-
 
654
           $res =& $DB->query($query);
-
 
655
 
-
 
656
 
-
 
657
 
-
 
658
        if (DB::isError($res)) {
-
 
659
                die($res->getMessage());
-
 
660
        }
-
 
661
 
-
 
662
                // Nom retenu, Num Nomen nom retenu, Num Taxon,
-
 
663
                                                                                // Famille
-
 
664
 
-
 
665
                $value=array('Nom_Retenu'=>"",'Num_Nom_Retenu'=>"0",'Num_Taxon'=>"0",'Famille'=>"");
-
 
666
 
-
 
667
                while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
-
 
668
                        $fam=$this->rechercherFamille($row['esn_id_taxon'],$DB);
-
 
669
                while (($fam['en_ce_rang']!='fin') && ($fam['en_ce_rang'] !=120)) {
-
 
670
                        $fam=$this->rechercherFamille($fam['etr_id_taxon_2'],$DB);
-
 
671
                }
-
 
672
                if ($fam['en_ce_rang']==120) {
-
 
673
                        $famille=$fam['en_nom_supra_generique'];
-
 
674
                }
-
 
675
                else {
-
 
676
                        $famille="Famille inconnue";
-
 
677
                }
423
}
678
                $value=array('Nom_Retenu'=>$this->formaterNom($row),'Num_Nom_Retenu'=>$row['esn_id_nom'],'Num_Taxon'=>$row['esn_id_taxon'],'Famille'=>$famille);
-
 
679
 
-
 
680
 
424
 
681
            }
425
 
682
 
Line 426... Line 683...
426
 
683
            return $value;
427
function traiterImage($image) { // recherche id image de ce nom et creation table correspondance
684
 
Line 452... Line 709...
452
                                }
709
                                }
453
                                $nom .= ' '.$rawnom['en_epithete_infra_specifique'];
710
                                $nom .= ' '.$rawnom['en_epithete_infra_specifique'];
454
                        }
711
                        }
Line 455... Line 712...
455
 
712
 
-
 
713
                }
456
                }
714
 
-
 
715
                return $nom .$this->retournerAuteur($rawnom) ;
-
 
716
 
-
 
717
 }
-
 
718
 
-
 
719
 
-
 
720
function rechercherFamille($taxon,&$DB) {
-
 
721
 
-
 
722
        $row=array();
-
 
723
 
-
 
724
        $query="SELECT DISTINCT en_ce_rang, etr_id_taxon_2, en_id_nom, en_nom_supra_generique ".
-
 
725
        " FROM eflore_taxon_relation, eflore_selection_nom, eflore_nom ".
-
 
726
        " WHERE etr_id_taxon_1 = ".$taxon.
-
 
727
        " AND etr_id_version_projet_taxon_1 = 25 ".
-
 
728
        " AND etr_id_categorie_taxon = 3 ".
-
 
729
        " AND etr_id_valeur_taxon = 3 ".
-
 
730
        " AND esn_id_taxon =  etr_id_taxon_2 ".
-
 
731
        " AND esn_ce_statut = 3 ".
-
 
732
        " AND esn_id_version_projet_taxon = etr_id_version_projet_taxon_1 ".
-
 
733
        " AND en_id_nom = esn_id_nom ".
-
 
734
        " AND esn_id_version_projet_taxon=en_id_version_projet_nom  ";
-
 
735
        $res =& $DB->query($query);
-
 
736
 
-
 
737
        if (DB::isError($res)) {
-
 
738
         die($res->getMessage());
-
 
739
        }
-
 
740
 
-
 
741
        if ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
-
 
742
                return $row;
-
 
743
    }
-
 
744
    else {
-
 
745
        $row['en_ce_rang']='fin';
-
 
746
        return $row;
-
 
747
    }
457
                return $nom.$this->retournerAuteur($rawnom) ;
748
 
Line -... Line 749...
-
 
749
}
458
}
750
 
459
 
751
 
460
function retournerAuteur($rawnom) {
752
function retournerAuteur($rawnom) {
461
	$auteurs = '';
753
                $auteurs = '';
462
	$auteur_basio = '';
754
                $auteur_basio = '';
463
	$auteur_modif = '';
755
                $auteur_modif = '';
464
	if (!empty($rawnom['abreviation_auteur_basio_ex']) && $rawnom['abreviation_auteur_basio_ex']!='-' )  {
756
                if (!empty($rawnom['abreviation_auteur_basio_ex']) && $rawnom['abreviation_auteur_basio_ex']!='-' )  {
465
	    $auteur_basio .= $rawnom['abreviation_auteur_basio_ex'];
757
                    $auteur_basio .= $rawnom['abreviation_auteur_basio_ex'];
466
	    if (!empty($rawnom['abreviation_auteur_basio']) && $rawnom['abreviation_auteur_basio']!='-') {
758
                    if (!empty($rawnom['abreviation_auteur_basio']) && $rawnom['abreviation_auteur_basio']!='-') {
467
		$auteur_basio .= ' ex '.$rawnom['abreviation_auteur_basio'];
759
                        $auteur_basio .= ' ex '.$rawnom['abreviation_auteur_basio'];
468
	    }
760
                    }
469
	} else if (!empty($rawnom['abreviation_auteur_basio']) && $rawnom['abreviation_auteur_basio']!='-') {
-
 
470
	    $auteur_basio .= $rawnom['abreviation_auteur_basio'];
-
 
471
	}
-
 
472
 
-
 
473
	if (!empty($rawnom['abreviation_auteur_modif_ex']) && $rawnom['abreviation_auteur_modif_ex']!='-') {
-
 
474
	    $auteur_modif .= $rawnom['abreviation_auteur_modif_ex'];
-
 
475
	    if (!empty($rawnom['abreviation_auteur_modif']) && $rawnom['abreviation_auteur_modif']!='-') {
761
                } else if (!empty($rawnom['abreviation_auteur_basio']) && $rawnom['abreviation_auteur_basio']!='-') {
476
		$auteur_modif .= ' ex '.$rawnom['abreviation_auteur_modif'];
-
 
477
	    }
-
 
478
	} else if (!empty($rawnom['abreviation_auteur_modif']) && $rawnom['abreviation_auteur_modif']!='-')  {
-
 
479
	    $auteur_modif .= $rawnom['abreviation_auteur_modif'];
-
 
480
	}
-
 
481
 
-
 
482
	if (!empty($auteur_modif)) {
-
 
483
	    $auteurs = ' ('.$auteur_basio.') '.$auteur_modif;
-
 
484
	} elseif (!empty($auteur_basio)) {
-
 
Line -... Line 762...
-
 
762
                    $auteur_basio .= $rawnom['abreviation_auteur_basio'];
-
 
763
                }
-
 
764
 
-
 
765
                if (!empty($rawnom['abreviation_auteur_modif_ex']) && $rawnom['abreviation_auteur_modif_ex']!='-') {
-
 
766
                    $auteur_modif .= $rawnom['abreviation_auteur_modif_ex'];
-
 
767
                    if (!empty($rawnom['abreviation_auteur_modif']) && $rawnom['abreviation_auteur_modif']!='-') {
-
 
768
                        $auteur_modif .= ' ex '.$rawnom['abreviation_auteur_modif'];
-
 
769
                    }
-
 
770
                } else if (!empty($rawnom['abreviation_auteur_modif']) && $rawnom['abreviation_auteur_modif']!='-')  {
-
 
771
                    $auteur_modif .= $rawnom['abreviation_auteur_modif'];
-
 
772
                }
-
 
773
 
-
 
774
                if (!empty($auteur_modif)) {
-
 
775
                    $auteurs = ' ('.$auteur_basio.') '.$auteur_modif;
-
 
776
                } elseif (!empty($auteur_basio)) {
485
	    $auteurs = ' '.$auteur_basio;
777
                    $auteurs = ' '.$auteur_basio;
486
	}
778
                }
Line -... Line 779...
-
 
779
 
487
 
780
                return $auteurs ;
Line 488... Line 781...
488
	return $auteurs ;
781
}