Subversion Repositories eFlore/Applications.cel

Rev

Rev 637 | Rev 741 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 637 Rev 715
Line 27... Line 27...
27
	private $format = null;
27
	private $format = null;
28
	private $service = null;
28
	private $service = null;
29
	private $squelette = null;
29
	private $squelette = null;
30
	private $squelette_dossier = null;
30
	private $squelette_dossier = null;
31
	private $flux = array();
31
	private $flux = array();
-
 
32
	private $criteres = array(
-
 
33
		'auteur' => 'identifiant', 
-
 
34
		'commune' => 'location', 
-
 
35
		'departement' => 'id_location',
-
 
36
		'taxon' => 'nom_ret',
-
 
37
		'commentaire' => 'commentaire',
-
 
38
		'date' => 'date_observation',
-
 
39
		'projet' => 'mots-cles');
Line 32... Line 40...
32
	
40
	
33
	/**
41
	/**
34
	 * Méthode appelée avec une requête de type GET.
42
	 * Méthode appelée avec une requête de type GET.
35
	 */
43
	 */
Line 191... Line 199...
191
		return $contenu;
199
		return $contenu;
192
	}
200
	}
Line 193... Line 201...
193
	
201
	
194
	private function getServiceParDefaut() {
202
	private function getServiceParDefaut() {
195
		// Construction de la requête
203
		// Construction de la requête
196
		$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
204
		$requete = 	(isset($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
197
			'FROM cel_inventory '.
205
			'FROM cel_inventory '.
198
			(($this->etreFluxAdmin()) ? '' : 'WHERE transmission = 1 ').
206
			(($this->etreFluxAdmin()) ? '' : 'WHERE transmission = 1 ').
199
			'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'date_modification DESC').' '.
207
			'ORDER BY '.(isset($this->orderby) && (!is_null($this->orderby)) ? $this->orderby  : 'date_modification DESC').' '.
Line 200... Line 208...
200
			"LIMIT $this->start,$this->limit ";
208
			"LIMIT $this->start,$this->limit ";
Line 201... Line 209...
201
		
209
		
Line 230... Line 238...
230
				// Construction de la requête
238
				// Construction de la requête
231
				$requete = 	'SELECT * '.
239
				$requete = 	'SELECT * '.
232
					'FROM cel_inventory '.
240
					'FROM cel_inventory '.
233
					'WHERE '.implode(" \nOR ", $requete_where).' '.
241
					'WHERE '.implode(" \nOR ", $requete_where).' '.
234
					'	'.(($this->etreFluxAdmin()) ? '' : 'AND transmission = 1 ').
242
					'	'.(($this->etreFluxAdmin()) ? '' : 'AND transmission = 1 ').
235
					'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'date_modification, date_creation DESC').' '.
243
					'ORDER BY '.(isset($this->orderby) && (!is_null($this->orderby)) ? $this->orderby  : 
-
 
244
						'date_modification, date_creation DESC').' '.
236
					"LIMIT $this->start,$this->limit ";
245
					"LIMIT $this->start,$this->limit ";
237
				$elements = $this->executerRequete($requete);
246
				$elements = $this->executerRequete($requete);
Line 238... Line 247...
238
				
247
				
239
				// Création du contenu
248
				// Création du contenu
Line 252... Line 261...
252
		$commune = $this->parametres[0];
261
		$commune = $this->parametres[0];
253
		if (isset($commune)) {
262
		if (isset($commune)) {
254
			$commune = $this->bdd->quote($commune);
263
			$commune = $this->bdd->quote($commune);
Line 255... Line 264...
255
			
264
			
256
			// Construction de la requête
265
			// Construction de la requête
257
			$requete = 	(($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
266
			$requete = 	(isset($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
258
				'FROM cel_inventory '.
267
				'FROM cel_inventory '.
259
				"WHERE location = $commune ".
268
				"WHERE location = $commune ".
260
				'	'.(($this->etreFluxAdmin()) ? '' : 'AND transmission = 1 ').
269
				'	'.(($this->etreFluxAdmin()) ? '' : 'AND transmission = 1 ').
261
				'ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'date_modification DESC, location ASC').' '.
270
				'ORDER BY '.(isset($this->orderby) && (!is_null($this->orderby)) ? $this->orderby  : 'date_modification DESC, location ASC').' '.
Line 262... Line 271...
262
				"LIMIT $this->start,$this->limit ";
271
				"LIMIT $this->start,$this->limit ";
Line 263... Line 272...
263
			
272
			
Line 269... Line 278...
269
			$this->messages[] = "Le service demandé nécessite d'indiquer une nom de commune en dernier paramêtre.";
278
			$this->messages[] = "Le service demandé nécessite d'indiquer une nom de commune en dernier paramêtre.";
270
		}
279
		}
271
		return $contenu;
280
		return $contenu;
272
	}
281
	}
Line -... Line 282...
-
 
282
	
-
 
283
	private function getServiceMultiCriteres() {
-
 
284
		$contenu = '';
-
 
285
		if (isset($_GET['debut'])) $this->start = $_GET['debut'];		
-
 
286
		if (isset($_GET['limite'])) $this->limite = $_GET['limite'];
-
 
287
		
-
 
288
		// Construction de la requête
-
 
289
		$requete = (isset($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
-
 
290
				'FROM cel_inventory '.
-
 
291
				'WHERE transmission = 1 '.
-
 
292
			'	AND ';
-
 
293
		
-
 
294
		if ($this->estUneRechercheGenerale()) {
-
 
295
			$chaine_requete = $_GET['recherche'];
-
 
296
			$requete .= $this->creerSousRequeteRechercheGenerale($chaine_requete);
-
 
297
		} else {
-
 
298
			$criteres = $this->traiterCriteresMultiples($_GET) ;
-
 
299
			if (!empty($criteres)) {
-
 
300
				$requete .= $this->creerSousRequeteRechercheParCriteres($criteres);
-
 
301
			}	
-
 
302
		}
-
 
303
		$requete = rtrim($requete, 'AND ');
-
 
304
		$requete .= 'ORDER BY '.(isset($this->orderby) && (!is_null($this->orderby)) ? $this->orderby  : 
-
 
305
			'date_modification DESC, location ASC').' '.
-
 
306
				"LIMIT $this->start,$this->limit ";
-
 
307
		
-
 
308
		$elements = $this->executerRequete($requete);//echo $requete;
-
 
309
 
-
 
310
		// Création du contenu
-
 
311
		if ($elements != false && count($elements) > 0) {
-
 
312
			$contenu = $this->executerService($elements);
-
 
313
		} else {
-
 
314
			$this->messages[] = "Aucune observation disponible.";
-
 
315
		}
-
 
316
        
-
 
317
        return $contenu;
-
 
318
	}
-
 
319
	
-
 
320
	private function creerSousRequeteRechercheParCriteres($criteres) {
-
 
321
		$requete = '';
-
 
322
		foreach ($criteres as $pair) {
-
 
323
			$nom_valeur = explode("=",$pair);
-
 
324
			if (sizeof($nom_valeur) != 0) {
-
 
325
				switch ($nom_valeur[0]) {
-
 
326
					case "ci_limite" : $this->limite = $this->bdd->quote($nom_valeur[1]); break;
-
 
327
					case "commentaire" : $mots_comment_liste = explode(" " , $nom_valeur[1]);
-
 
328
						foreach($mots_comment_liste as $mot_comment) {
-
 
329
							$mot_comment = trim($mot_comment) ;
-
 
330
							$requete .= $nom_valeur[0].' LIKE '.$this->bdd->quote('%'.$mot_comment.'%').' AND ';
-
 
331
						}
-
 
332
						break;
-
 
333
					case "date_observation" : 
-
 
334
						$nom_valeur[1] = str_replace('/', '-', $nom_valeur[1]);
-
 
335
						if (preg_match('/(^[0-9]{2})-([0-9]{2})-([0-9]{4}$)/', $nom_valeur[1], $matches)) {
-
 
336
							$nom_valeur[1] = $matches[3].'-'.$matches[2].'-'.$matches[1];
-
 
337
						}
-
 
338
						$requete .= $nom_valeur[0].'='.$this->bdd->quote($nom_valeur[1]).' AND '; break;
-
 
339
					case "nom_ret" : 
-
 
340
						if ($nom_valeur[1] == "indetermine") $nom_valeur[1] = 'null';						
-
 
341
						$requete .= ' ('.$nom_valeur[0].' LIKE "%'.$nom_valeur[1].'%" OR nom_sel LIKE "%'.
-
 
342
							$nom_valeur[1].'%") AND '; break;
-
 
343
					case "mots-cles" : $requete .= $this->creerSousRequeteMotsCles($nom_valeur[1]); break; 		
-
 
344
					default : $requete .= $nom_valeur[0].' = "'.$nom_valeur[1].'" AND '; break;
-
 
345
				}
-
 
346
			}
-
 
347
		}
-
 
348
		$requete = rtrim($requete,' AND ');
-
 
349
		return $requete;
-
 
350
	}
-
 
351
	
-
 
352
	private function creerSousRequeteMotsCles($mot_cle) {
-
 
353
		$requete = 'mots_cles like "inexistant" OR';
-
 
354
		if (preg_match('/.*,.*/', $mot_cle)) {
-
 
355
			$requete = $this->creerSousRequeteMotsClesOu($mot_cle);
-
 
356
		} else if (preg_match('/.*ET.*/', $mot_cle)) {
-
 
357
			$requete = $this->creerSousRequeteMotsClesEt($mot_cle);
-
 
358
		} else {		
-
 
359
			// Construction de la requête
-
 
360
			$prerequete = 	'SELECT * '.
-
 
361
				'FROM cel_mots_cles_obs '.
-
 
362
				'WHERE cmc_id_mot_cle_general = '.$this->bdd->quote($this->encoderMotCle($mot_cle)); 
-
 
363
			$elements = $this->executerRequete($prerequete);
-
 
364
			if ($elements != false && count($elements) > 0) {
-
 
365
				$requete = '';
-
 
366
				foreach ($elements as $occurence) {
-
 
367
					$requete .= '(mots_cles LIKE "%'.$occurence['cmc_id_mot_cle_utilisateur'].'%" AND identifiant = '.
-
 
368
						$this->bdd->quote($occurence['cmc_id_proprietaire']).' ) OR ';	
-
 
369
				}
-
 
370
			}
-
 
371
		}
-
 
372
		$requete = rtrim($requete,' OR ').' AND ';
-
 
373
		return $requete;
-
 
374
	}
-
 
375
	
-
 
376
	private function creerSousRequeteMotsClesOu($mot_cle) {	
-
 
377
		$requete = 'mots_cles like "inexistant" OR';	
-
 
378
		$tab_mots_cles = explode(',', $mot_cle);
-
 
379
		$where = '';
-
 
380
		foreach ($tab_mots_cles as $mot) {
-
 
381
			$where .= 'cmc_id_mot_cle_general = '.$this->bdd->quote($this->encoderMotCle($mot)).' OR ';
-
 
382
		}
-
 
383
		$where = rtrim($where,' OR ');
-
 
384
		
-
 
385
		// Construction de la requête
-
 
386
		$prerequete = 	"SELECT cmc_id_mot_cle_utilisateur, cmc_id_proprietaire FROM cel_mots_cles_obs WHERE $where "; 
-
 
387
		$elements = $this->executerRequete($prerequete);//print_r($elements);
-
 
388
		if ($elements != false && count($elements) > 0) {
-
 
389
			$requete = '';
-
 
390
			foreach ($elements as $occurence) {
-
 
391
				$requete .= '(mots_cles LIKE "%'.$occurence['cmc_id_mot_cle_utilisateur'].'%" AND identifiant = '.
-
 
392
					$this->bdd->quote($occurence['cmc_id_proprietaire']).' ) OR ';
-
 
393
			}
-
 
394
		}
-
 
395
		return $requete;
-
 
396
	}
-
 
397
	
-
 
398
	private function creerSousRequeteMotsClesEt($mot_cle) {
-
 
399
		$requete = 'mots_cles like "inexistant" OR';
-
 
400
		$where = '';
-
 
401
		$champs = 'a.cmc_id_proprietaire , ';
-
 
402
		$table = '';
-
 
403
		$i = "a"; $j = "a";
-
 
404
		
-
 
405
		$tab_mots_cles = explode("ET", $mot_cle); 
-
 
406
		foreach ($tab_mots_cles as $mot) {
-
 
407
			$champs .= "$i.cmc_id_mot_cle_utilisateur as $i , ";
-
 
408
			$table .= "cel_mots_cles_obs $i , ";
-
 
409
			$where .= "$i.cmc_id_mot_cle_general = ".$this->bdd->quote($this->encoderMotCle($mot)).' AND ';
-
 
410
			if ($i !== "a") {
-
 
411
				$where .= " $i.cmc_id_proprietaire = ".$j.".cmc_id_proprietaire AND ";
-
 
412
				$j++;
-
 
413
			}
-
 
414
			$i++;
-
 
415
		}
-
 
416
		$where = rtrim($where,' AND '); $champs = rtrim($champs,' , '); $table = rtrim($table,' , ');
-
 
417
		
-
 
418
		// Construction de la requête
-
 
419
		$prerequete = 	"SELECT $champs FROM $table WHERE $where "; 
-
 
420
		$elements = $this->executerRequete($prerequete);//print_r($elements);
-
 
421
		if ($elements != false && count($elements) > 0) {
-
 
422
			$requete = '';
-
 
423
			foreach ($elements as $occurence) {
-
 
424
				$requete = ' (';
-
 
425
				for ($j = 'a'; $j < $i; $j++) {
-
 
426
					$requete .= 'mots_cles like "%'.$occurence[$j].'%" AND ';
-
 
427
				}
-
 
428
				$requete .= ' identifiant = '.$this->bdd->quote($occurence['cmc_id_proprietaire']).' ) OR ';
-
 
429
			}
-
 
430
		}
-
 
431
		return $requete;
-
 
432
	}		
-
 
433
	
-
 
434
	private function traiterCriteresMultiples($tableau_criteres) {
-
 
435
		$tableau_criteres_pour_bdd = array();
-
 
436
				
-
 
437
		foreach($tableau_criteres as $nom_critere => $valeur_critere) {
-
 
438
			if (isset($this->criteres[$nom_critere])) {
-
 
439
				$tableau_criteres_pour_bdd[] = $this->criteres[$nom_critere].'='.$valeur_critere;
-
 
440
			}
-
 
441
		}
-
 
442
		return $tableau_criteres_pour_bdd;
-
 
443
	}
-
 
444
	
-
 
445
	private function creerSousRequeteRechercheGenerale($chaine_requete) {
-
 
446
		$requete = '';
-
 
447
		if (trim($chaine_requete) != '') {	
-
 
448
			$chaine_requete = strtolower($chaine_requete);
-
 
449
			$chaine_requete = str_replace(' ', '_', $chaine_requete);
-
 
450
			$requete = ' ('.
-
 
451
				'nom_ret LIKE "'.$chaine_requete.'%"'.
-
 
452
				' OR '.
-
 
453
				'nom_sel LIKE "'.$chaine_requete.'%"'.
-
 
454
				' OR '.
-
 
455
				'location LIKE "'.$chaine_requete.'%" '.
-
 
456
				' OR '.
-
 
457
				'id_location LIKE "'.$chaine_requete.'%" '.
-
 
458
				' OR '.
-
 
459
				'identifiant LIKE "'.$chaine_requete.'%" '.
-
 
460
				') ';
-
 
461
		}
-
 
462
		return $requete;
-
 
463
	}
-
 
464
	
-
 
465
	private function estUneRechercheGenerale() {
-
 
466
		return isset($_GET['recherche']);
-
 
467
	}
273
	
468
	
274
	private function executerService($elements) {
469
	private function executerService($elements) {
275
		$contenu = '';
470
		$contenu = '';
276
		if (is_array($elements)) {
471
		if (is_array($elements)) {
277
			// Prétraitement des données
472
			// Prétraitement des données
Line 291... Line 486...
291
	
486
	
292
	private function construireDonneesCommunesAuFlux($observations) {
487
	private function construireDonneesCommunesAuFlux($observations) {
293
		$donnees = $this->getFlux($this->service);
488
		$donnees = $this->getFlux($this->service);
294
		$donnees['guid'] = $this->getUrlServiceBase();
489
		$donnees['guid'] = $this->getUrlServiceBase();
295
		$donnees['lien_service'] = $this->creerUrlService();
490
		$donnees['lien_service'] = $this->creerUrlService();
296
		$donnees['lien_cel'] = $this->config['settings']['celUrlAbsolu'];
491
		$donnees['lien_cel'] = $this->config['settings']['baseURLAbsolu'];
297
		$donnees['editeur'] = $this->config['settings']['editeur'];
492
		$donnees['editeur'] = $this->config['settings']['editeur'];
298
		$derniere_info_en_date = reset($observations);
493
		$derniere_info_en_date = reset($observations);
299
		$date_modification_timestamp = strtotime($derniere_info_en_date['date_modification']);
494
		$date_modification_timestamp = strtotime($derniere_info_en_date['date_modification']);
300
		$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
495
		$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
301
		$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
496
		$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
302
		$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
497
		$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
303
		$donnees['annee_courante'] = date('Y');
498
		$donnees['annee_courante'] = date('Y');
304
		$donnees['generateur'] = 'CEL - Jrest - CelSyndicationObservation';
499
		$donnees['generateur'] = 'CEL - Jrest - CelSyndicationObservation';
305
		preg_match('/([0-9]+)/', '$Revision$', $match);
-
 
306
		$donnees['generateur_version'] = $match[1];
500
		$donnees['generateur_version'] = (preg_match('/([0-9]+)/', '$Revision$', $match)) ?  $match[1] : '0';
307
		return $donnees; 
501
		return $donnees; 
Line 308... Line 502...
308
	}
502
	}
309
	
503
	
Line 391... Line 585...
391
		$categorie = $this->nettoyerTexte($categorie);
585
		$categorie = $this->nettoyerTexte($categorie);
392
		return $categorie;
586
		return $categorie;
393
	}
587
	}
Line 394... Line 588...
394
	
588
	
395
	private function etreFluxAdmin() {
589
	private function etreFluxAdmin() {
396
		return ($_GET['admin'] == '1') ? true : false;
590
		return (isset($_GET['admin']) && $_GET['admin'] == '1') ? true : false;
Line 397... Line 591...
397
	}
591
	}
398
	
592
	
399
	private function creerUrlService() {
593
	private function creerUrlService() {