Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1585 Rev 1622
Line 88... Line 88...
88
 
88
 
89
		return array('type' => 'png', 'img' => $img);
89
		return array('type' => 'png', 'img' => $img);
Line 90... Line 90...
90
	}
90
	}
91
 
-
 
92
	public function getTout($params) {
-
 
93
		$emplacements = null;
-
 
94
		$concatenation_id = "CONCAT(IFNULL(latitude,''),IFNULL(longitude,''), IFNULL(wgs84_latitude,''),IFNULL(wgs84_longitude,'')) ";
-
 
95
 
-
 
96
		$requete = 'SELECT ce_zone_geo, zone_geo, station, '.
-
 
97
			'	mots_cles_texte, latitude, wgs84_latitude, longitude, wgs84_longitude, '.
-
 
98
			"	$concatenation_id AS id_coord ".
-
 
99
			'FROM cel_obs AS co '.
-
 
100
			'	LEFT JOIN cel_zones_geo AS l '.
-
 
101
			'		ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) '.
-
 
102
			"WHERE transmission = '1' ".
-
 
103
			" AND (".
-
 
104
			$this->construireWhereRectangleStationOR()." OR ".
-
 
105
			$this->construireWhereRectangleCommuneOR().") ".
-
 
106
			$this->construireWhereDept().
-
 
107
			$this->construireWhereCommune().
-
 
108
			$this->construireWhereUtilisateur().
-
 
109
			$this->construireWhereNumTaxonAvecSousTaxons().
-
 
110
			$this->construireWhereNomTaxon().
-
 
111
			$this->construireWhereReferentiel().
-
 
112
			$this->construireWhereDate().
-
 
113
			$this->construireWhereCommentaire().
-
 
114
			$this->construireWherePhotosSeulement().
-
 
115
			$this->construireWhereProjet().
-
 
116
			$this->construireWhereTag().
-
 
Line -... Line 91...
-
 
91
 
-
 
92
	public function getTout($params) {
-
 
93
 
-
 
94
		$emplacements = null;		
-
 
95
		$concatenation_id = "CONCAT(IFNULL(latitude,''),IFNULL(longitude,''), IFNULL(wgs84_latitude,''),IFNULL(wgs84_longitude,'')) ";
-
 
96
		
-
 
97
		$requete =  'SELECT ce_zone_geo, zone_geo, station, '.
-
 
98
								"mots_cles_texte, ".
-
 
99
								"latitude, ".
-
 
100
								"wgs84_latitude, ".
-
 
101
								"longitude, ".
-
 
102
								"wgs84_longitude, ".
-
 
103
								$concatenation_id." as id_coord ".
-
 
104
					'FROM cel_obs AS co '.
-
 
105
                    '   LEFT JOIN cel_zones_geo AS l '.
-
 
106
                    '       ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) '.
-
 
107
                    "WHERE transmission = '1' ".
-
 
108
					" AND (".
-
 
109
					$this->construireWhereRectangleStationOR()." OR ".
-
 
110
					$this->construireWhereRectangleCommuneOR().") ".
-
 
111
					$this->construireWhereDept().
-
 
112
                    $this->construireWhereCommune().
-
 
113
                    $this->construireWhereUtilisateur().
-
 
114
					$this->construireWhereNumTaxonAvecSousTaxons().
-
 
115
					$this->construireWhereNomTaxon().
-
 
116
					$this->construireWhereReferentiel().
-
 
117
					$this->construireWhereDate().
-
 
118
					$this->construireWhereCommentaire().
-
 
119
					$this->construireWherePhotosSeulement().
-
 
120
					$this->construireWhereProjet().
-
 
121
					$this->construireWhereTag().
117
			$this->construireWhereNombreDeJours().
122
					$this->construireWhereNombreDeJours().
118
			' GROUP BY id_coord';
123
					' GROUP BY id_coord';
119
 
124
		
120
		$resultats_emplacements = $this->executerRequete($requete);
125
		$resultats_emplacements = $this->executerRequete($requete);
121
		$emplacements = $this->traiterEmplacements($resultats_emplacements, $this->compterObservations($params));
126
		$emplacements = $this->traiterEmplacements($resultats_emplacements, $this->compterObservations($params));
122
		return $emplacements;
127
		return $emplacements;
123
	}
128
	}
124
 
129
	
125
	private function afficherRequeteFormatee($requete) {
130
	private function afficherRequeteFormatee($requete) {
126
		$requete = str_replace(')',')<br />',$requete);
131
		$requete = str_replace(')',')<br />',$requete);
Line 131... Line 136...
131
 
136
 
Line 132... Line 137...
132
	private $nb_obs = 0;
137
	private $nb_obs = 0;
133
 
138
 
134
	private function compterObservations($params) {
139
	private function compterObservations($params) {
135
		$requete =  'SELECT COUNT(*) as nb '.
140
		$requete =  'SELECT COUNT(*) as nb '.
136
			'FROM cel_obs AS co '.
141
					'FROM cel_obs AS co '.
137
			'	LEFT JOIN cel_zones_geo AS l '.
142
                    '   LEFT JOIN cel_zones_geo AS l '.
138
			'		ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) '.
143
                    '       ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) '.
139
			"WHERE transmission = '1' ".
144
                    "WHERE transmission = '1' ".
140
			" AND (".
145
					" AND (".
141
			$this->construireWhereRectangleStationOR()." OR ".
146
					$this->construireWhereRectangleStationOR()." OR ".
142
			$this->construireWhereRectangleCommuneOR().") ".
147
					$this->construireWhereRectangleCommuneOR().") ".
143
			$this->construireWhereDept().
148
					$this->construireWhereDept().
144
			$this->construireWhereCommune().
149
                    $this->construireWhereCommune().
145
			$this->construireWhereUtilisateur().
150
                    $this->construireWhereUtilisateur().
146
			$this->construireWhereNumTaxonAvecSousTaxons().
151
					$this->construireWhereNumTaxonAvecSousTaxons().
147
			$this->construireWhereNomTaxon().
152
					$this->construireWhereNomTaxon().
148
			$this->construireWhereReferentiel().
153
					$this->construireWhereReferentiel().
149
			$this->construireWhereDate().
154
					$this->construireWhereDate().
150
			$this->construireWhereCommentaire().
155
					$this->construireWhereCommentaire().
151
			$this->construireWherePhotosSeulement().
156
					$this->construireWherePhotosSeulement().
152
			$this->construireWhereProjet().
157
					$this->construireWhereProjet().
Line 153... Line 158...
153
			$this->construireWhereTag().
158
					$this->construireWhereTag().
154
			$this->construireWhereNombreDeJours();
159
					$this->construireWhereNombreDeJours();
155
 
160
 
Line 242... Line 247...
242
		}
247
		}
Line 243... Line 248...
243
 
248
 
244
		if (isset($this->parametres['ne']) && $this->parametres['sw'] && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
249
		if (isset($this->parametres['ne']) && $this->parametres['sw'] && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['ne']) && ! $this->etreNull($this->parametres['sw'])) {
245
			$ne = $this->decomposerLatLng($this->parametres['ne']);
250
			$ne = $this->decomposerLatLng($this->parametres['ne']);
246
			$sw = $this->decomposerLatLng($this->parametres['sw']);
251
			$sw = $this->decomposerLatLng($this->parametres['sw']);
247
			$marqueurs['points'] = CartoGroupage::creerGroupesQuadtree($points, $ne['lat'], $ne['lng'], $sw['lat'], $sw['lng'], $zoom);
252
			$marqueurs['points'] = CartoGroupage::creerGroupesQuadtree(&$points, $ne['lat'], $ne['lng'], $sw['lat'], $sw['lng'], $zoom);
248
		} else {
253
		} else {
249
			$marqueurs['points'] = $points;
254
			$marqueurs['points'] = $points;
250
		}
255
		}
251
		//$marqueurs['stats']['latDiff'] = abs($marqueurs['stats']['latMin'] - $marqueurs['stats']['latMax']);
256
		//$marqueurs['stats']['latDiff'] = abs($marqueurs['stats']['latMin'] - $marqueurs['stats']['latMax']);
Line 297... Line 302...
297
		if (stristr($tags, 'sensible') === FALSE) {
302
		if (stristr($tags, 'sensible') === FALSE) {
298
			$sensible = false;
303
			$sensible = false;
299
		}
304
		}
300
		return $sensible;
305
		return $sensible;
301
	}
306
	}
302
 
307
	
303
	private function communeEstDemandee() {
308
	private function communeEstDemandee() {
304
		$station_infos = $this->decomposerParametreStation();
309
	    $station_infos = $this->decomposerParametreStation();
305
		$commune_demandee = true;
310
	    $commune_demandee = true;
306
		if ($station_infos['type'] == self::MARQUEUR_STATION) {
311
	    if($station_infos['type'] == self::MARQUEUR_STATION) {
307
			$commune_demandee = false;
312
			$commune_demandee = false;
308
		}
313
	    }
309
		return $commune_demandee;
314
	    return $commune_demandee;
310
	}
315
	}
Line 311... Line 316...
311
 
316
 
312
	/**
317
	/**
313
	 * Données pour l'affichage des obs d'une station
318
	 * Données pour l'affichage des obs d'une station
314
	 */
319
	 */
315
	public function getObservations($params) {
320
	public function getObservations($params) {
316
		$resultats = array();
321
		$resultats = array();
317
		$total = 0;
322
		$total = 0;
318
		if (isset($this->parametres['station']) && !$this->etreNull($this->parametres['station'])) {
323
		if (isset($this->parametres['station']) && !$this->etreNull($this->parametres['station'])) {
319
			$requete = 	'SELECT SQL_CALC_FOUND_ROWS id_observation, ce_utilisateur, courriel_utilisateur, nom_utilisateur, prenom_utilisateur, '.
324
			$requete = 	'SELECT SQL_CALC_FOUND_ROWS id_observation, ce_utilisateur, courriel_utilisateur, nom_utilisateur, prenom_utilisateur, '.
320
				'	nom_sel, nom_ret, nom_sel_nn, nom_ret_nn, nt, famille, '.
325
						'	nom_sel, nom_ret, nom_sel_nn, nom_ret_nn, nt, famille, '.
321
				'	lieudit, zone_geo, date_observation, milieu, commentaire, '.
326
						'	lieudit, zone_geo, date_observation, milieu, commentaire, '.
322
				'	utm_secteur, utm_x, utm_y, code, date_transmission '.
327
						'	utm_secteur, utm_x, utm_y, code, date_transmission, nom_referentiel '.
323
				'FROM cel_obs AS co '.
328
						'FROM cel_obs AS co '.
324
				'	LEFT JOIN cel_zones_geo AS l '.
329
						'	LEFT JOIN cel_zones_geo AS l '.
325
				"		ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) ".
330
						"		ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) ".
326
				"WHERE transmission = '1' ".
331
						"WHERE transmission = '1' ".
327
				(($this->communeEstDemandee()) ? $this->construireWhereCommuneSansCoordonneesAvecSensibles() : $this->construireWhereCoordonneesSansSensibles()).
332
						(($this->communeEstDemandee()) ? $this->construireWhereCommuneSansCoordonneesAvecSensibles() : $this->construireWhereCoordonneesSansSensibles()).
328
				$this->construireWhereDept().
333
						$this->construireWhereDept().
329
				$this->construireWhereUtilisateur().
334
						$this->construireWhereUtilisateur().
330
				$this->construireWhereNumTaxonAvecSousTaxons().
335
						$this->construireWhereNumTaxonAvecSousTaxons().
331
				$this->construireWhereNomTaxon().
336
						$this->construireWhereNomTaxon().
332
				$this->construireWhereReferentiel().
337
						$this->construireWhereReferentiel().
333
				$this->construireWhereDate().
338
						$this->construireWhereDate().
334
				$this->construireWhereCommentaire().
339
						$this->construireWhereCommentaire().
335
				$this->construireWherePhotosSeulement().
340
						$this->construireWherePhotosSeulement().
336
				$this->construireWhereProjet().
341
						$this->construireWhereProjet().
337
				$this->construireWhereTag().
342
						$this->construireWhereTag().
338
				$this->construireWhereNombreDeJours().
343
						$this->construireWhereNombreDeJours().
339
				'ORDER BY nom_sel ASC '.
344
	                    'ORDER BY nom_sel ASC '.
340
				"LIMIT {$this->start},{$this->limit} ";
345
	                    "LIMIT {$this->start},{$this->limit} ";
341
			//echo $requete;exit;
346
			//echo $requete;exit;
342
			$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
347
			$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
343
			$requete = 'SELECT FOUND_ROWS()';
348
			$requete = 'SELECT FOUND_ROWS()';
344
			$total = (int) $this->requeter($requete, self::SQL_RETOUR_COLONNE);
349
			$total = (int) $this->requeter($requete, self::SQL_RETOUR_COLONNE);
Line 366... Line 371...
366
				$observation['date'] = ($donnee->date_observation != '0000-00-00 00:00:00') ? $this->formaterDate($donnee->date_observation, '%d/%m/%Y') : '';
371
				$observation['date'] = ($donnee->date_observation != '0000-00-00 00:00:00') ? $this->formaterDate($donnee->date_observation, '%d/%m/%Y') : '';
367
				$observation['datePubli'] = $this->formaterDate($donnee->date_transmission);
372
				$observation['datePubli'] = $this->formaterDate($donnee->date_transmission);
368
				$observation['lieu'] = $this->traiterLieu($donnee);
373
				$observation['lieu'] = $this->traiterLieu($donnee);
369
				$observation['observateur'] = $donnee->courriel_utilisateur;
374
				$observation['observateur'] = $donnee->courriel_utilisateur;
370
				$observation['observateurId'] = $donnee->ce_utilisateur;
375
				$observation['observateurId'] = $donnee->ce_utilisateur;
371
				$observation['urlEflore'] = $this->getUrlEflore($donnee->nom_sel_nn);
376
				$observation['urlEflore'] = $this->getUrlEflore($donnee->nom_referentiel, $donnee->nom_sel_nn);
Line 372... Line 377...
372
 
377
 
373
				if (isset($donnee->zone_geo)) {
378
				if (isset($donnee->zone_geo)) {
374
					$observations['commune'] = $this->nettoyerTexte($donnee->zone_geo);
379
					$observations['commune'] = $this->nettoyerTexte($donnee->zone_geo);
375
				}
380
				}
Line 381... Line 386...
381
			}
386
			}
382
		}
387
		}
383
		return $observations;
388
		return $observations;
384
	}
389
	}
Line 385... Line -...
385
 
-
 
386
	private function getUrlEflore($nn) {
-
 
387
		$urlEflore = null;
-
 
388
		if (! $this->etreNull($nn)) {
-
 
389
			$urlEflore = sprintf($this->config['settings']['efloreUrlTpl'], $nn, 'illustration');
-
 
390
		}
-
 
391
		return $urlEflore;
-
 
392
	}
-
 
393
 
390
 
394
	private function traiterLieu($donnee) {
391
	private function traiterLieu($donnee) {
395
		$lieu = array();
392
		$lieu = array();
396
		if (!$this->etreNull($donnee->lieudit)) {
393
		if (!$this->etreNull($donnee->lieudit)) {
397
			$lieu[] = $donnee->lieudit;
394
			$lieu[] = $donnee->lieudit;
Line 439... Line 436...
439
				$observations['observations'][$id] = $infos;
436
				$observations['observations'][$id] = $infos;
440
			}
437
			}
441
		}
438
		}
442
		return $observations;
439
		return $observations;
443
	}
440
	}
444
 
441
	
445
	private function ajouterAuteursAuxObs($observations) {
442
	private function ajouterAuteursAuxObs($observations) {
446
		$observateurs = $this->recupererUtilisateursIdentite(array_keys($observations['observateurs']));
443
		$observateurs = $this->recupererUtilisateursIdentite(array_keys($observations['observateurs']));
447
		unset($observations['observateurs']);
444
		unset($observations['observateurs']);
448
		foreach ($observations['observations'] as $id => $infos) {
445
		foreach ($observations['observations'] as $id => $infos) {
449
			$courriel = strtolower($infos['observateur']);
446
			$courriel = strtolower($infos['observateur']);
Line 471... Line 468...
471
	 */
468
	 */
472
	public function getTaxons($params) {
469
	public function getTaxons($params) {
473
		$json = null;
470
		$json = null;
Line 474... Line 471...
474
 
471
 
475
		$requete = 	'SELECT SQL_CALC_FOUND_ROWS DISTINCT nom_ret, nom_ret_nn, nt, famille '.
472
		$requete = 	'SELECT SQL_CALC_FOUND_ROWS DISTINCT nom_ret, nom_ret_nn, nt, famille '.
476
			'FROM cel_obs AS co '.
473
					'FROM cel_obs AS co '.
477
			'	LEFT JOIN cel_zones_geo AS l '.
474
					'	LEFT JOIN cel_zones_geo AS l '.
478
			'		ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) '.
475
					'		ON (l.nom = co.zone_geo AND l.id_zone_geo = co.ce_zone_geo) '.
479
			"WHERE transmission = '1' ".
476
					"WHERE transmission = '1' ".
480
			"	AND nom_ret != '' ".
477
					"	AND nom_ret != '' ".
481
			$this->construireWhereDept().
478
					$this->construireWhereDept().
482
			$this->construireWhereCommune().
479
                    $this->construireWhereCommune().
483
			$this->construireWhereUtilisateur().
480
                    $this->construireWhereUtilisateur().
484
			$this->construireWhereNumTaxon().
481
					$this->construireWhereNumTaxon().
485
			$this->construireWhereNomTaxon().
482
					$this->construireWhereNomTaxon().
486
			$this->construireWhereReferentiel().
483
					$this->construireWhereReferentiel().
487
			$this->construireWhereDate().
484
					$this->construireWhereDate().
488
			$this->construireWhereCommentaire().
485
					$this->construireWhereCommentaire().
489
			$this->construireWherePhotosSeulement().
486
					$this->construireWherePhotosSeulement().
490
			$this->construireWhereProjet().
487
					$this->construireWhereProjet().
491
			$this->construireWhereTag().
488
					$this->construireWhereTag().
492
			$this->construireWhereNombreDeJours().
489
					$this->construireWhereNombreDeJours().
493
			'ORDER BY nom_ret ASC '.
490
					'ORDER BY nom_ret ASC '.
494
			"LIMIT {$this->start},{$this->limit} ";
491
                    "LIMIT {$this->start},{$this->limit} ";
495
		//$this->debug[] = $requete;
492
		//$this->debug[] = $requete;
496
		$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
493
		$resultats = $this->requeter($requete, self::SQL_RETOUR_COMPLET, self::SQL_MODE_OBJET);
497
		//echo $requete;exit;
494
		//echo $requete;exit;
498
		$requete = 'SELECT FOUND_ROWS()';
495
		$requete = 'SELECT FOUND_ROWS()';
Line 537... Line 534...
537
				$sql = " AND (latitude LIKE $lat AND longitude LIKE $lng) ";
534
				$sql = " AND (latitude LIKE $lat AND longitude LIKE $lng) ";
538
			}
535
			}
539
		}
536
		}
540
		return $sql;
537
		return $sql;
541
	}
538
	}
542
 
539
	
543
	private function construireWhereCoordonneesSansSensibles() {
540
	private function construireWhereCoordonneesSansSensibles() {
544
		$sql = '(';
541
		$sql = '(';
545
		// Récupération des coordonnées depuis l'id station
542
		// Récupération des coordonnées depuis l'id station
546
		extract($this->decomposerParametreStation());
543
		extract($this->decomposerParametreStation());
547
		if (isset($type)) {
544
		if (isset($type)) {
Line 611... Line 608...
611
					$sql = " AND nom_ret LIKE $nom ";
608
					$sql = " AND nom_ret LIKE $nom ";
612
			}
609
			}
613
		}
610
		}
614
		return $sql;
611
		return $sql;
615
	}
612
	}
616
 
613
	
617
	private function construireWhereReferentiel() {
614
	private function construireWhereReferentiel() {
618
		$sql = '';
615
		$sql = '';
619
		extract($this->parametres);
616
		extract($this->parametres);
620
		if (isset($referentiel) && !$this->etreNull($referentiel)) {
617
		if (isset($referentiel) && !$this->etreNull($referentiel)) {
621
			$referentiel = $this->proteger($referentiel.'%');
618
			$referentiel = $this->proteger($referentiel.'%');
Line 830... Line 827...
830
			$lngMax = $ne['lng'];
827
			$lngMax = $ne['lng'];
Line 831... Line 828...
831
 
828
 
832
			$sql = "( (latitude != 0 AND longitude != 0) ".
829
			$sql = "( (latitude != 0 AND longitude != 0) ".
833
				" AND latitude BETWEEN $latMin AND $latMax ".
830
				" AND latitude BETWEEN $latMin AND $latMax ".
834
				" AND longitude BETWEEN $lngMin AND $lngMax )";
831
				" AND longitude BETWEEN $lngMin AND $lngMax )";
835
 
832
			
836
			/*$sql = " MBRWithin(mon_point, GeomFromText('POLYGON((".$latMin.' '.$lngMin.','.
833
			/*$sql = " MBRWithin(mon_point, GeomFromText('POLYGON((".$latMin.' '.$lngMin.','.
837
			$latMax.' '.$lngMin.','.
834
			$latMax.' '.$lngMin.','.
838
			$latMax.' '.$lngMax.','.
835
			$latMax.' '.$lngMax.','.
839
			$latMax.' '.$lngMin.','.
836
			$latMax.' '.$lngMin.','.
840
			$latMin.' '.$lngMin."))')) ";		*/
837
			$latMin.' '.$lngMin."))')) ";		*/	
841
		}
838
		}
842
		return $sql;
839
		return $sql;
Line 843... Line 840...
843
	}
840
	}
Line 874... Line 871...
874
			$lngMax = $ne['lng'];
871
			$lngMax = $ne['lng'];
Line 875... Line 872...
875
 
872
 
876
			$sql = "( wgs84_longitude != 0 AND wgs84_latitude != 0 ".
873
			$sql = "( wgs84_longitude != 0 AND wgs84_latitude != 0 ".
877
				" AND wgs84_latitude BETWEEN $latMin AND $latMax ".
874
				" AND wgs84_latitude BETWEEN $latMin AND $latMax ".
878
				" AND wgs84_longitude BETWEEN $lngMin AND $lngMax )";
875
				" AND wgs84_longitude BETWEEN $lngMin AND $lngMax )";
879
 
876
			
880
			/*$sql = " MBRWithin(point_commune, GeomFromText('POLYGON((".$latMin.' '.$lngMin.','.
877
			/*$sql = " MBRWithin(point_commune, GeomFromText('POLYGON((".$latMin.' '.$lngMin.','.
881
			$latMax.' '.$lngMin.','.
878
			$latMax.' '.$lngMin.','.
882
			$latMax.' '.$lngMax.','.
879
			$latMax.' '.$lngMax.','.
883
			$latMax.' '.$lngMin.','.
880
			$latMax.' '.$lngMin.','.
Line 924... Line 921...
924
			           			(latitude = '000null' OR latitude = '' OR latitude = 0 OR latitude IS NULL) ".
921
			           			(latitude = '000null' OR latitude = '' OR latitude = 0 OR latitude IS NULL) ".
925
								" AND (longitude = '000null' OR longitude = '' OR longitude = 0 OR longitude IS NULL)".
922
								" AND (longitude = '000null' OR longitude = '' OR longitude = 0 OR longitude IS NULL)".
926
							')'.
923
							')'.
927
							' OR mots_cles_texte LIKE "%sensible%"'.
924
							' OR mots_cles_texte LIKE "%sensible%"'.
928
						') ';
925
						') ';
929
 
926
			
930
		}
927
		}
931
		return $sql;
928
		return $sql;
932
	}
929
	}
933
 
930
	
934
 
931
	
935
	private function construireWherePhotosSeulement() {
932
	private function construireWherePhotosSeulement() {
936
		$sql = '';
933
		$sql = '';
937
		if (isset($this->parametres['photos']) && $this->parametres['photos'] == 1) {
934
		if (isset($this->parametres['photos']) && $this->parametres['photos'] == 1) {
938
			$sql = 'AND co.id_observation IN (SELECT DISTINCT id_observation FROM cel_obs_images) ';
935
			$sql = 'AND co.id_observation IN (SELECT DISTINCT id_observation FROM cel_obs_images) ';
939
		}
936
		}
Line 949... Line 946...
949
			$utilisateur = $this->proteger($utilisateur);
946
			$utilisateur = $this->proteger($utilisateur);
950
			$sql = " AND co.courriel_utilisateur = $utilisateur ";
947
			$sql = " AND co.courriel_utilisateur = $utilisateur ";
951
		}
948
		}
952
		return $sql;
949
		return $sql;
953
	}
950
	}
954
 
951
	
955
 
952
	
956
	private function construireWhereNumTaxon() {
953
	private function construireWhereNumTaxon() {
957
		$sql = '';
954
		$sql = '';
958
		// Récupération des coordonnées depuis l'id station
955
		// Récupération des coordonnées depuis l'id station
959
		extract($this->parametres);
956
		extract($this->parametres);
960
		if (isset($this->parametres['num_taxon']) && !$this->etreNull($num_taxon)) {
957
		if (isset($this->parametres['num_taxon']) && !$this->etreNull($num_taxon)) {
961
		$num_taxon = $this->proteger($num_taxon);
958
		$num_taxon = $this->proteger($num_taxon);
962
		$sql = " AND nt = $num_taxon ";
959
		$sql = " AND nt = $num_taxon ";
963
		}
960
		}
964
		return $sql;
961
		return $sql;
965
	}
962
	}
966
 
963
	
967
	private function construireWhereNumTaxonAvecSousTaxons() {
964
	private function construireWhereNumTaxonAvecSousTaxons() {
968
		$sql = '';
965
		$sql = '';
969
		// Récupération des coordonnées depuis l'id station
966
		// Récupération des coordonnées depuis l'id station
970
		extract($this->parametres);
967
		extract($this->parametres);
971
		if (isset($this->parametres['num_taxon']) && !$this->etreNull($num_taxon)) {
968
		if (isset($this->parametres['num_taxon']) && !$this->etreNull($num_taxon)) {
Line 982... Line 979...
982
				$sql = " AND nt = $num_taxon ";
979
				$sql = " AND nt = $num_taxon ";
983
			}
980
			}
984
		}
981
		}
985
		return $sql;
982
		return $sql;
986
	}
983
	}
987
 
984
	
988
	private function obtenirSousTaxons($nt) {
985
	private function obtenirSousTaxons($nt) {
989
		$referentiel = 'bdtfx';
986
		$referentiel = 'bdtfx';
990
		if($this->parametres['referentiel'] && $this->parametres['referentiel'] != "" && $this->parametres['referentiel'] != '*') {
987
		if($this->parametres['referentiel'] && $this->parametres['referentiel'] != "" && $this->parametres['referentiel'] != '*') {
991
			$referentiel = $this->parametres['referentiel'];
988
			$referentiel = $this->parametres['referentiel'];
992
		}
989
		}
Line 1006... Line 1003...
1006
		if (!$this->etreNull($projet_sql)) {
1003
		if (!$this->etreNull($projet_sql)) {
1007
			$sql = " AND ($projet_sql) ";
1004
			$sql = " AND ($projet_sql) ";
1008
		}
1005
		}
1009
		return $sql;
1006
		return $sql;
1010
	}
1007
	}
1011
 
1008
	
1012
	/**
1009
	/**
1013
	 * Traitement de $projet pour construction du filtre dans la requête
1010
	 * Traitement de $projet pour construction du filtre dans la requête
1014
	 */
1011
	 */
1015
	private function getSqlWhereProjet($projet) {
1012
	private function getSqlWhereProjet($projet) {
1016
		$sql = null;
1013
		$sql = null;
1017
		if (isset($projet) && !$this->etreNull($projet)) {
1014
		if (isset($projet) && !$this->etreNull($projet)) {
1018
			$sql = 'co.mots_cles_texte LIKE '.$this->proteger('%'.$projet.'%');
1015
			$sql = 'co.mots_cles_texte LIKE '.$this->proteger('%'.$projet.'%');
1019
		}
1016
		}
1020
		return $sql;
1017
		return $sql;
1021
	}
1018
	}
1022
 
1019
	
1023
	private function construireWhereTag() {
1020
	private function construireWhereTag() {
1024
		$sql = '';
1021
		$sql = '';
1025
		extract($this->parametres);
1022
		extract($this->parametres);
1026
		$tag_sql = isset($tag) ? $this->getSqlWhereObsAvecImagesTaguees($tag) : null;
1023
		$tag_sql = isset($tag) ? $this->getSqlWhereObsAvecImagesTaguees($tag) : null;
1027
		if (!$this->etreNull($tag_sql)) {
1024
		if (!$this->etreNull($tag_sql)) {
1028
			$sql = " AND ($tag_sql) ";
1025
			$sql = " AND ($tag_sql) ";
1029
		}
1026
		}
1030
		return $sql;
1027
		return $sql;
1031
	}
1028
	}
1032
 
1029
	
1033
	private function construireWhereNombreDeJours() {
1030
	private function construireWhereNombreDeJours() {
1034
		$sql = null;
1031
		$sql = null;
1035
		extract($this->parametres);
1032
		extract($this->parametres);
1036
		if (isset($nbjours) && !$this->etreNull($nbjours)) {
1033
		if (isset($nbjours) && !$this->etreNull($nbjours)) {
1037
			$sql = ' AND DATEDIFF(CURDATE(),co.date_creation) <= '.$this->proteger($nbjours).' ';
1034
			$sql = ' AND DATEDIFF(CURDATE(),co.date_creation) <= '.$this->proteger($nbjours).' ';
1038
		}
1035
		}
1039
		return $sql;
1036
		return $sql;
1040
	}
1037
	}
1041
 
1038
	
1042
	/**
1039
	/**
1043
	 * Traitement de $tag pour construction du filtre dans la requête
1040
	 * Traitement de $tag pour construction du filtre dans la requête
1044
	 */
1041
	 */
1045
	private function getSqlWhereObsAvecImagesTaguees($tag) {
1042
	private function getSqlWhereObsAvecImagesTaguees($tag) {
1046
		$sql = null;
1043
		$sql = null;
Line 1065... Line 1062...
1065
						(!$this->etreNull($tag_sql) ? "AND ($tag_sql) " : '').
1062
						(!$this->etreNull($tag_sql) ? "AND ($tag_sql) " : '').
1066
						'ORDER BY utilisateur ASC, ci.ordre ASC';
1063
						'ORDER BY utilisateur ASC, ci.ordre ASC';
1067
			//$this->debug[] = $requete;
1064
			//$this->debug[] = $requete;
1068
			//die($requete);
1065
			//die($requete);
1069
			$elements_tag = $this->executerRequete($requete);
1066
			$elements_tag = $this->executerRequete($requete);
1070
 
1067
			
1071
			$requete_tag = array();
1068
			$requete_tag = array();
1072
			if ($elements_tag != false && count($elements_tag) > 0) {
1069
			if ($elements_tag != false && count($elements_tag) > 0) {
1073
 
1070
				
1074
				$filtres = array();
1071
				$filtres = array();
1075
				foreach ($elements_tag as $occurence) {
1072
				foreach ($elements_tag as $occurence) {
1076
					$utilisateur = $occurence['utilisateur'];
1073
					$utilisateur = $occurence['utilisateur'];
1077
					$id_obs = $occurence['id_obs'];
1074
					$id_obs = $occurence['id_obs'];
1078
					if (!array_key_exists($utilisateur, $filtres)) {
1075
					if (!array_key_exists($utilisateur, $filtres)) {
Line 1080... Line 1077...
1080
					}
1077
					}
1081
					if (!array_key_exists($id_obs, $filtres[$utilisateur])) {
1078
					if (!array_key_exists($id_obs, $filtres[$utilisateur])) {
1082
						$filtres[$utilisateur][$id_obs] = $id_obs;
1079
						$filtres[$utilisateur][$id_obs] = $id_obs;
1083
					}
1080
					}
1084
				}
1081
				}
1085
 
1082
				
1086
				// Pré-construction du where de la requête
1083
				// Pré-construction du where de la requête
1087
				$tpl_where = "(id_observation IN (%s))";
1084
				$tpl_where = "(id_observation IN (%s))";
1088
				foreach ($filtres as $utilisateur => $id_obs) {
1085
				foreach ($filtres as $utilisateur => $id_obs) {
1089
					$requete_tag[] = sprintf($tpl_where, implode(',', $id_obs));
1086
					$requete_tag[] = sprintf($tpl_where, implode(',', $id_obs));
1090
				}
1087
				}
1091
 
1088
				
1092
			} else {
1089
			} else {
1093
				$this->messages[] = "Aucune observation ne possède d'images avec ce mot-clé.";
1090
				$this->messages[] = "Aucune observation ne possède d'images avec ce mot-clé.";
1094
			}
1091
			}
1095
			if (count($requete_tag) > 0) {
1092
			if (count($requete_tag) > 0) {
1096
				$sql = implode(" \nOR ", $requete_tag);
1093
				$sql = implode(" \nOR ", $requete_tag);
1097
			}
1094
			}
1098
		}
1095
		}
1099
		return $sql;
1096
		return $sql;
1100
	}
1097
	}
1101
 
1098
	
1102
	/**
1099
	/**
1103
	 * Traitement de $tag pour construction du filtre dans la requête
1100
	 * Traitement de $tag pour construction du filtre dans la requête
1104
	 */
1101
	 */
1105
	private function getSqlWhereMotsCles($tag) {
1102
	private function getSqlWhereMotsCles($tag) {
1106
		$sql = null;
1103
		$sql = null;
Line 1108... Line 1105...
1108
		$requete_projet = $this->getSqlWhereMotsClesImages($mots_cles);
1105
		$requete_projet = $this->getSqlWhereMotsClesImages($mots_cles);
1109
		$sql = $requete_projet;
1106
		$sql = $requete_projet;
1110
		//$this->debug[] = $sql;
1107
		//$this->debug[] = $sql;
1111
		return $sql;
1108
		return $sql;
1112
	}
1109
	}
1113
 
1110
	
1114
	/**
1111
	/**
1115
	 * Traitement de $tag pour construction du filtre dans la requête
1112
	 * Traitement de $tag pour construction du filtre dans la requête
1116
	 */
1113
	 */
1117
	private function getSqlWhereMotsClesImages($mots_cles_encodes) {
1114
	private function getSqlWhereMotsClesImages($mots_cles_encodes) {
1118
		$where_mots_cles_images = array();
1115
		$where_mots_cles_images = array();
Line 1120... Line 1117...
1120
			$where_mots_cles_images[] = "ci.mots_cles_texte LIKE $mot_cle_encode";
1117
			$where_mots_cles_images[] = "ci.mots_cles_texte LIKE $mot_cle_encode";
1121
		}
1118
		}
1122
		$where_mots_cles_images = implode(' '.$mots_cles_encodes['type'].' ', $where_mots_cles_images);
1119
		$where_mots_cles_images = implode(' '.$mots_cles_encodes['type'].' ', $where_mots_cles_images);
1123
		return $where_mots_cles_images;
1120
		return $where_mots_cles_images;
1124
	}
1121
	}
1125
 
1122
	
1126
	private function decomposerParametreTag($tags) {
1123
	private function decomposerParametreTag($tags) {
1127
 
1124
		
1128
		$mots_cles = array('type' => null, 'motsCles' => null, 'motsClesEncodesProteges' => null);
1125
		$mots_cles = array('type' => null, 'motsCles' => null, 'motsClesEncodesProteges' => null);
1129
		if (preg_match('/.+OU.+/', $tags)) {
1126
		if (preg_match('/.+OU.+/', $tags)) {
1130
			$mots_cles['type'] = 'OR';
1127
			$mots_cles['type'] = 'OR';
1131
			$mots_cles['motsCles'] = explode('OU', $tags);
1128
			$mots_cles['motsCles'] = explode('OU', $tags);
1132
		} else if (preg_match('/.+ET.+/', $tags)) {
1129
		} else if (preg_match('/.+ET.+/', $tags)) {
1133
			$mots_cles['type'] = 'AND';
1130
			$mots_cles['type'] = 'AND';
1134
			$mots_cles['motsCles'] = explode('ET', $tags);
1131
			$mots_cles['motsCles'] = explode('ET', $tags);
1135
		} else {
1132
		} else {
1136
			$mots_cles['motsCles'][] = $tags;
1133
			$mots_cles['motsCles'][] = $tags;
1137
		}
1134
		}
1138
 
1135
		
1139
		foreach ($mots_cles['motsCles'] as $mot) {
1136
		foreach ($mots_cles['motsCles'] as $mot) {
1140
			$mots_cles['motsClesEncodesProteges'][] = $this->bdd->quote('%'.$mot.'%');
1137
			$mots_cles['motsClesEncodesProteges'][] = $this->bdd->quote('%'.$mot.'%');
1141
		}
1138
		}
1142
		$this->debug[] = $mots_cles;
1139
		$this->debug[] = $mots_cles;
1143
		return $mots_cles;
1140
		return $mots_cles;