Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 851 Rev 996
1
<?php
1
<?php
2
// ATTENTION ! Classe compatible uniquement avec nouveau format de bdd du cel //
2
// ATTENTION ! Classe compatible uniquement avec nouveau format de bdd du cel //
3
 
3
 
4
// in utf8
4
// in utf8
5
// out utf8
5
// out utf8
6
 
6
 
7
// Fournit un référentiel relatif à l'utilisateur sur l'un des champs demandes 
7
// Fournit un référentiel relatif à l'utilisateur sur l'un des champs demandes 
8
class SelfRefList extends Cel {
8
class SelfRefList extends Cel {
9
	
9
	
10
	private $referentiels = array('station', 'lieudit', 'milieu');
10
	private $referentiels = array('station', 'lieudit', 'milieu');
11
 
11
 
12
	/**
12
	/**
13
	 * Suivant le type de référentiel donné en paramètre, renvoie les liste de ses éléments
13
	 * Suivant le type de référentiel donné en paramètre, renvoie les liste de ses éléments
14
	 * 
14
	 * 
15
	 * uid[0] : utilisateur obligatoire
15
	 * uid[0] : utilisateur obligatoire
16
	 * uid[1] : referentiel demandé (obligatoire)
16
	 * uid[1] : referentiel demandé (obligatoire)
17
	 * $_GET["start"] et $GET_["limit"] : selection intervalle
17
	 * $_GET["start"] et $GET_["limit"] : selection intervalle
18
	 * $_GET["recherche"] : cherche les nom qui commmencent selon la valeur
18
	 * $_GET["recherche"] : cherche les nom qui commmencent selon la valeur
19
	 * 
19
	 * 
20
	 */
20
	 */
21
	function getElement($uid){
21
	function getElement($uid){
22
		
22
		
23
		   // Controle detournement utilisateur 
23
		   // Controle detournement utilisateur 
24
		    session_start();
-
 
25
 	        $this->controleUtilisateur($uid[0]);
24
 	        $this->controleUtilisateur($uid[0]);
26
			 
25
			 
27
			if (!$this->paramObligatoiresSontPresents($uid)) {
26
			if (!$this->paramObligatoiresSontPresents($uid)) {
28
				return;
27
				return;
29
			}
28
			}
30
			
29
			
31
			if($_GET['recherche'] == '*') {
30
			if($_GET['recherche'] == '*') {
32
				$_GET['recherche'] = '%';
31
				$_GET['recherche'] = '%';
33
			}
32
			}
34
			
33
			
35
			$referentiel_demande = $uid[1];
34
			$referentiel_demande = $uid[1];
36
			
35
			
37
			$value=array();
36
			$value=array();
38
	
37
	
39
           	$requete_referentiel = "SELECT DISTINCT ".$referentiel_demande." " .
38
           	$requete_referentiel = "SELECT DISTINCT ".$referentiel_demande." " .
40
           							"FROM cel_obs WHERE ce_utilisateur = '".$uid[0]."' ";
39
           							"FROM cel_obs WHERE ce_utilisateur = '".$uid[0]."' ";
41
           							
40
           							
42
           	if($this->filtreRechercheEstDemande()) { 
41
           	if($this->filtreRechercheEstDemande()) { 
43
           		$requete_referentiel .= " AND ".$referentiel_demande." LIKE '".$_GET["recherche"]."%'";
42
           		$requete_referentiel .= " AND ".$referentiel_demande." LIKE '".$_GET["recherche"]."%'";
44
           	}
43
           	}
45
 
44
 
46
			if ($this->limiteEstDemandee()) {
45
			if ($this->limiteEstDemandee()) {
47
				$requete_referentiel .= " ORDER BY '.$referentiel_demande.' LIMIT ".$_GET["start"].",".$_GET["limit"];
46
				$requete_referentiel .= " ORDER BY '.$referentiel_demande.' LIMIT ".$_GET["start"].",".$_GET["limit"];
48
			}
47
			}
49
		
48
		
50
		    $referentiel_resultat = $this->executerRequete($requete_referentiel);
49
		    $referentiel_resultat = $this->executerRequete($requete_referentiel);
51
		    $referentiel = array();
50
		    $referentiel = array();
52
		    
51
		    
53
		    foreach($referentiel_resultat as $cle => $valeur) {
52
		    foreach($referentiel_resultat as $cle => $valeur) {
54
		    	if($this->estUneValeurValide($valeur[$referentiel_demande])) {
53
		    	if($this->estUneValeurValide($valeur[$referentiel_demande])) {
55
		    		$referentiel[] = $valeur[$referentiel_demande];
54
		    		$referentiel[] = $valeur[$referentiel_demande];
56
		    	}
55
		    	}
57
 
56
 
58
		    }
57
		    }
59
		
58
		
60
			$output = json_encode($referentiel);
59
			$output = json_encode($referentiel);
61
			print($output);
60
			print($output);
62
	}
61
	}
63
	
62
	
64
	function paramObligatoiresSontPresents($uid) {
63
	function paramObligatoiresSontPresents($uid) {
65
		
64
		
66
		return (isset($uid[1]) && in_array($uid[1],$this->referentiels) && (isset($uid[0]) && $uid[0] != ""));
65
		return (isset($uid[1]) && in_array($uid[1],$this->referentiels) && (isset($uid[0]) && $uid[0] != ""));
67
	}
66
	}
68
	
67
	
69
	function filtreRechercheEstDemande() {
68
	function filtreRechercheEstDemande() {
70
		return (isset($_GET["recherche"]) && trim($_GET["recherche"]) != "");
69
		return (isset($_GET["recherche"]) && trim($_GET["recherche"]) != "");
71
	}
70
	}
72
	
71
	
73
	function limiteEstDemandee() {
72
	function limiteEstDemandee() {
74
		return isset($_GET["start"]) && is_numeric($_GET["start"]) && isset($_GET["limit"]) && is_numeric($_GET["limit"]);
73
		return isset($_GET["start"]) && is_numeric($_GET["start"]) && isset($_GET["limit"]) && is_numeric($_GET["limit"]);
75
	}
74
	}
76
	
75
	
77
	function estUneValeurValide($chaine) {
76
	function estUneValeurValide($chaine) {
78
		return ($chaine != null && $chaine != "000null" &&  trim($chaine) != "");
77
		return ($chaine != null && $chaine != "000null" &&  trim($chaine) != "");
79
	}
78
	}
80
}
79
}
81
 
80
 
82
 
81
 
83
/* +--Fin du code ---------------------------------------------------------------------------------------+
82
/* +--Fin du code ---------------------------------------------------------------------------------------+
84
* $Log$
83
* $Log$
85
* Revision 1.3  2008-01-30 08:57:28  ddelon
84
* Revision 1.3  2008-01-30 08:57:28  ddelon
86
* fin mise en place mygwt
85
* fin mise en place mygwt
87
*
86
*
88
* Revision 1.2  2007-05-22 12:54:09  ddelon
87
* Revision 1.2  2007-05-22 12:54:09  ddelon
89
* Securisation acces utilisateur
88
* Securisation acces utilisateur
90
* 
89
* 
91
*/
90
*/
92
?>
91
?>