Subversion Repositories eFlore/Applications.cel

Rev

Rev 2458 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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