Subversion Repositories eFlore/Applications.cel

Rev

Rev 2385 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2385 Rev 2458
1
<?php
1
<?php
-
 
2
// declare(encoding='UTF-8');
-
 
3
/**
2
// ATTENTION ! Classe compatible uniquement avec nouveau format de bdd du cel //
4
 * Fournit une liste d'auto-complétions (=référentiel) relative à l'utilisateur sur l'un des champs demandés.
3
 
5
 *
-
 
6
 * @internal   Mininum PHP version : 5.2
4
// in utf8
7
 * @category   CEL
-
 
8
 * @package    Services
-
 
9
 * @subpackage Auto-complétions
5
// out utf8
10
 * @version    0.1
-
 
11
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
-
 
12
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
-
 
13
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
-
 
14
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
-
 
15
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
-
 
16
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
6
 
17
 */
7
// Fournit un référentiel relatif à l'utilisateur sur l'un des champs demandes
-
 
8
class SelfRefList extends Cel {
18
class SelfRefList extends Cel {
9
 
19
 
10
	private $referentiels = array('station', 'lieudit', 'milieu');
20
	private $referentiels = array('station', 'lieudit', 'milieu');
11
 
21
 
12
	/**
22
	/**
13
	 * Suivant le type de référentiel donné en paramètre, renvoie les liste de ses éléments
23
	 * Suivant le type de référentiel donné en paramètre, renvoie les liste de ses éléments
14
	 *
24
	 *
15
	 * uid[0] : utilisateur obligatoire
25
	 * uid[0] : utilisateur obligatoire
16
	 * uid[1] : referentiel demandé (obligatoire)
26
	 * uid[1] : referentiel demandé (obligatoire)
17
	 * $_GET["start"] et $GET_["limit"] : selection intervalle
27
	 * $_GET["start"] et $GET_["limit"] : selection intervalle
18
	 * $_GET["recherche"] : cherche les noms qui commmencent selon la valeur
28
	 * $_GET["recherche"] : cherche les noms qui commmencent selon la valeur
19
	 *
29
	 *
20
	 */
30
	 */
21
	public function getElement($uid){
31
	public function getElement($uid){
22
		// Controle detournement utilisateur
32
		// Controle detournement utilisateur
23
		$this->controleUtilisateur($uid[0]);
33
		$this->controleUtilisateur($uid[0]);
24
 
34
 
25
		if (!$this->paramObligatoiresSontPresents($uid)) {
35
		if (!$this->paramObligatoiresSontPresents($uid)) {
26
			return;
36
			return;
27
		}
37
		}
28
 
38
 
29
		if ($_GET['recherche'] == '*') {
39
		if ($_GET['recherche'] == '*') {
30
			$_GET['recherche'] = '%';
40
			$_GET['recherche'] = '%';
31
		}
41
		}
32
 
42
 
33
		$referentiel_demande = $uid[1];
43
		$referentiel_demande = $uid[1];
34
		$idUtilisateur = Cel::db()->proteger($uid[0]);
44
		$idUtilisateurP = Cel::db()->proteger($uid[0]);
35
 
-
 
36
		$requete = "SELECT DISTINCT $referentiel_demande " .
45
 
37
			'FROM cel_obs '.
-
 
38
			"WHERE ce_utilisateur = '$idUtilisateur' ";
46
		$filtreSql = '';
-
 
47
		if ($this->filtreRechercheEstDemande()) {
39
		if ($this->filtreRechercheEstDemande()) {
48
			$rechercheP = Cel::db()->proteger($_GET['recherche'].'%');
40
			$requete .= " AND $referentiel_demande LIKE '".$_GET["recherche"]."%'";
49
			$filtreRecherche = "AND $referentiel_demande LIKE $rechercheP ";
-
 
50
		}
-
 
51
 
41
		}
52
		$limiteSql = '';
-
 
53
		if ($this->limiteEstDemandee()) {
-
 
54
			$start = intval($_GET['start']);
42
		if ($this->limiteEstDemandee()) {
55
			$limit = intval($_GET['limit']);
43
			$requete .= " ORDER BY $referentiel_demande LIMIT ".$_GET['start'].','.$_GET['limit'];
56
			$limite = "LIMIT $start,$limit ";
-
 
57
		}
-
 
58
 
-
 
59
		$requete = "SELECT DISTINCT $referentiel_demande " .
-
 
60
			'FROM cel_obs '.
-
 
61
			"WHERE ce_utilisateur = $idUtilisateurP ".
-
 
62
			$filtreSql.
-
 
63
			"ORDER BY $referentiel_demande ".
-
 
64
			$limiteSql.
44
		}
65
			' -- '.__FILE__.':'.__LINE__;
45
		$resultat = Cel::db()->requeter($requete);
66
		$resultat = Cel::db()->requeter($requete);
46
 
67
 
47
		$referentiel = array();
68
		$referentiel = array();
48
		if (is_array($resultat)) {
69
		if (is_array($resultat)) {
49
			foreach ($resultat as $cle => $valeur) {
70
			foreach ($resultat as $cle => $valeur) {
50
				if ($this->estUneValeurValide($valeur[$referentiel_demande])) {
71
				if ($this->estUneValeurValide($valeur[$referentiel_demande])) {
51
					$referentiel[] = $valeur[$referentiel_demande];
72
					$referentiel[] = $valeur[$referentiel_demande];
52
				}
73
				}
53
 
-
 
54
			}
74
			}
55
		}
75
		}
56
		$this->envoyerJson($referentiel);
76
		$this->envoyerJson($referentiel);
57
		return true;
77
		return true;
58
	}
78
	}
59
 
79
 
60
	private function paramObligatoiresSontPresents($uid) {
80
	private function paramObligatoiresSontPresents($uid) {
61
		return (isset($uid[1]) && in_array($uid[1], $this->referentiels) && (isset($uid[0]) && $uid[0] != ''));
81
		return (isset($uid[1]) && in_array($uid[1], $this->referentiels) && (isset($uid[0]) && $uid[0] != ''));
62
	}
82
	}
63
 
83
 
64
	private function filtreRechercheEstDemande() {
84
	private function filtreRechercheEstDemande() {
65
		return (isset($_GET['recherche']) && trim($_GET['recherche']) != '');
85
		return (isset($_GET['recherche']) && trim($_GET['recherche']) != '');
66
	}
86
	}
67
 
87
 
68
	private function limiteEstDemandee() {
88
	private function limiteEstDemandee() {
69
		return isset($_GET['start']) && is_numeric($_GET['start']) && isset($_GET['limit']) && is_numeric($_GET['limit']);
89
		return isset($_GET['start']) && is_numeric($_GET['start']) && isset($_GET['limit']) && is_numeric($_GET['limit']);
70
	}
90
	}
71
 
91
 
72
	private function estUneValeurValide($chaine) {
92
	private function estUneValeurValide($chaine) {
73
		return ($chaine != null && $chaine != '000null' &&  trim($chaine) != '');
93
		return ($chaine != null && $chaine != '000null' &&  trim($chaine) != '');
74
	}
94
	}
75
}
95
}