Rev 2143 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php// ATTENTION ! Classe compatible uniquement avec nouveau format de bdd du cel //// in utf8// out utf8// Fournit un référentiel relatif à l'utilisateur sur l'un des champs demandesclass 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];$idUtilisateur = Cel::db()->proteger($uid[0]);$requete = "SELECT DISTINCT $referentiel_demande " .'FROM cel_obs '."WHERE ce_utilisateur = '$idUtilisateur' ";if ($this->filtreRechercheEstDemande()) {$requete .= " AND $referentiel_demande LIKE '".$_GET["recherche"]."%'";}if ($this->limiteEstDemandee()) {$requete .= " ORDER BY $referentiel_demande LIMIT ".$_GET['start'].','.$_GET['limit'];}$resultat = Cel::db()->requeter($requete);$referentiel = array();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) != '');}}