* @author Jean-Pascal MILCENT * @author Aurelien PERONNET * @license GPL v3 * @license CECILL v2 * @copyright 1999-2014 Tela Botanica */ class SelfRefList extends Cel { private $referentiels = array('station', 'lieudit', 'milieu'); /** * Suivant le type de référentiel donné en paramètre, renvoie les liste de ses éléments * * uid[0] : utilisateur obligatoire * uid[1] : referentiel demandé (obligatoire) * $_GET["start"] et $GET_["limit"] : selection intervalle * $_GET["recherche"] : cherche les noms qui commmencent selon la valeur * */ public function getElement($uid){ // Controle detournement utilisateur $this->controleUtilisateur($uid[0]); if (!$this->paramObligatoiresSontPresents($uid)) { return; } if ($_GET['recherche'] == '*') { $_GET['recherche'] = '%'; } $referentiel_demande = $uid[1]; $idUtilisateurP = Cel::db()->proteger($uid[0]); $filtreSql = ''; if ($this->filtreRechercheEstDemande()) { $rechercheP = Cel::db()->proteger($_GET['recherche'].'%'); $filtreSql = "AND $referentiel_demande LIKE $rechercheP "; } $limiteSql = ''; if ($this->limiteEstDemandee()) { $start = intval($_GET['start']); $limit = intval($_GET['limit']); $limite = "LIMIT $start,$limit "; } $requete = "SELECT DISTINCT $referentiel_demande " . 'FROM cel_obs '. "WHERE ce_utilisateur = $idUtilisateurP ". $filtreSql. "ORDER BY $referentiel_demande ". $limiteSql. ' -- '.__FILE__.':'.__LINE__; $resultat = Cel::db()->requeter($requete); $referentiel = array(); if (is_array($resultat)) { foreach ($resultat as $cle => $valeur) { if ($this->estUneValeurValide($valeur[$referentiel_demande])) { $referentiel[] = $valeur[$referentiel_demande]; } } } $this->envoyerJson($referentiel); return true; } private function paramObligatoiresSontPresents($uid) { return (isset($uid[1]) && in_array($uid[1], $this->referentiels) && (isset($uid[0]) && $uid[0] != '')); } private function filtreRechercheEstDemande() { return (isset($_GET['recherche']) && trim($_GET['recherche']) != ''); } private function limiteEstDemandee() { return isset($_GET['start']) && is_numeric($_GET['start']) && isset($_GET['limit']) && is_numeric($_GET['limit']); } private function estUneValeurValide($chaine) { return ($chaine != null && $chaine != '000null' && trim($chaine) != ''); } }