Subversion Repositories eFlore/Applications.cel

Rev

Rev 605 | Rev 874 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 605 Rev 761
Line 1... Line 1...
1
<?php
1
<?php
Line 2... Line 2...
2
 
2
 
3
Class InventoryImageListPublic extends DBAccessor {
-
 
4
	
-
 
5
	private $DB = null;
-
 
6
	
-
 
7
	private $start = 0;
-
 
8
	private $limit = 100;
-
 
9
	private $distinct = true;
3
Class InventoryImageListPublic extends Cel {
10
	
4
		
11
	private $criteres = array('mot_cles' => 'c.ci_meta_mots_cles', 
5
	private $criteres = array('mots-cles' => 'c.ci_meta_mots_cles', 
12
							'auteur' => 'c.ci_ce_utilisateur', 
6
							'auteur' => 'c.ci_ce_utilisateur', 
13
							'commune' => 'b.location', 
7
							'commune' => 'b.location', 
14
							'departement' => 'b.id_location',
8
							'dept' => 'b.id_location',
Line 15... Line 9...
15
							'taxon' => 'b.nom_ret');
9
							'taxon' => 'b.nom_ret');
16
 
10
 
-
 
11
	function InventoryImageListPublic($config) {
-
 
12
		
-
 
13
		parent::__construct($config);
-
 
14
		
17
	function InventoryImageListPublic($config) {
15
		$this->start = 0;
18
 
16
		$this->limit = 100;
Line 19... Line 17...
19
		$this->config=$config;
17
		$this->distinct = true;
Line 20... Line 18...
20
	}
18
	}
Line 21... Line 19...
21
 
19
 
22
	function getRessource() {
20
	function getRessource() {
23
	
-
 
24
	}
-
 
25
 
-
 
26
	function getElement($uid)
-
 
27
	{				
-
 
28
		// uid[0] : utilisateur obligatoire
21
	
Line 29... Line 22...
29
		// uid[1] : critères de filtrage de la forme critère1:valeur1;critère2:valeur2
22
	}
30
 
23
 
31
		$this->DB = $this->connectDB($this->config,'cel_db');
24
	function getElement($uid)
Line 84... Line 77...
84
		$requete_nb .= $requete;
77
		$requete_nb .= $requete;
Line 85... Line 78...
85
			
78
			
86
		$requete_debut = rtrim($requete_debut,'AND ');
79
		$requete_debut = rtrim($requete_debut,'AND ');
Line 87... Line 80...
87
		$requete_nb = rtrim($requete_nb,'AND ');
80
		$requete_nb = rtrim($requete_nb,'AND ');
88
		
81
		
Line 89... Line 82...
89
		$requete_debut .= ' ORDER BY '.((!is_null($this->orderby)) ? $this->orderby  : 'c.ci_meta_date_ajout DESC').' ';	
82
		$requete_debut .= ' ORDER BY c.ci_meta_date_ajout DESC ';	
90
		$requete_debut .= "LIMIT $this->start,$this->limit ";
-
 
91
		
-
 
92
		$res =& $this->DB->query($requete_debut);
-
 
Line 93... Line 83...
93
        if (PEAR::isError($res)) {
83
		$requete_debut .= "LIMIT $this->start,$this->limit ";
94
        	die($res->getMessage());
-
 
95
        }
-
 
96
        
-
 
Line 97... Line 84...
97
		$res_nb =& $this->DB->query($requete_nb);
84
		
Line 98... Line 85...
98
        if (PEAR::isError($res)) {
85
		$res = $this->executerRequete($requete_debut);
Line 99... Line 86...
99
        	die($res->getMessage());
86
        
100
        }
87
		$res_nb =& $this->executerRequete($requete_nb);
101
        
88
        
102
        $images = array();
89
        $images = array();
Line 103... Line 90...
103
        
90
        
104
        $total = 0;
91
        $total = 0;
105
        
92
        
Line 106... Line 93...
106
		while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
93
		foreach ($res as $row) {
Line 107... Line 94...
107
	    	$images[]= $row;
94
	    	$images[]= $row;
-
 
95
	    	$nb_res = $row['nb_res'];
-
 
96
    	}
Line 108... Line 97...
108
	    	$nb_res = $row['nb_res'];
97
    	
109
    	}
98
		foreach ($res_nb as $row) {
110
    	
99
	    	$total= $row['nb_res'];
111
		while ($row =& $res_nb->fetchrow(DB_FETCHMODE_ASSOC)) {
100
    	}
Line 131... Line 120...
131
 
120
 
132
			if(sizeof($nom_valeur) != 0)
121
			if(sizeof($nom_valeur) != 0)
133
			{
122
			{
134
					if($nom_valeur[0] == "ci_limite")
123
					if($nom_valeur[0] == "ci_limite")
135
					{
124
					{
136
						$this->limite = $this->DB->escapeSimple($nom_valeur[1]) ;
125
						$this->limite = $this->proteger($nom_valeur[1]) ;
137
					}
126
					}
138
					elseif($nom_valeur[0] == "c.ci_numero_page")
127
					elseif($nom_valeur[0] == "c.ci_numero_page")
139
					{
128
					{
140
						$this->start = $this->limite*$this->DB->escapeSimple($nom_valeur[1]) ;
129
						$this->start = $this->limite*$this->proteger($nom_valeur[1]) ;
141
					}
130
					}
142
					elseif($nom_valeur[0] == "c.ci_meta_mots_cles")
131
					elseif($nom_valeur[0] == "c.ci_meta_mots_cles")
143
					{
-
 
144
						$mots_cles = rtrim($nom_valeur[1], ',') ;
-
 
145
						$mots_cles_liste = explode("," , $mots_cles) ;
-
 
146
 
-
 
147
						foreach($mots_cles_liste as $mot_cle)
-
 
148
						{
132
					{
149
							$requete .= $nom_valeur[0].' LIKE "%'.$this->DB->escapeSimple($mot_cle).'%"' ;
-
 
150
							$requete .= ' AND ' ;
-
 
151
						}
133
						$requete .= $this->creerSousRequeteMotsCles($nom_valeur[1]);   
152
					}
134
					}
153
					elseif($nom_valeur[0] == "c.ci_meta_comment")
135
					elseif($nom_valeur[0] == "c.ci_meta_comment")
154
					{
136
					{
Line 155... Line 137...
155
						$mots_comment_liste = explode(" " , $nom_valeur[1]) ;
137
						$mots_comment_liste = explode(" " , $nom_valeur[1]) ;
156
 
138
 
157
						foreach($mots_comment_liste as $mot_comment)
139
						foreach($mots_comment_liste as $mot_comment)
158
						{
140
						{
159
							$mot_comment = trim($mot_comment) ;
141
							$mot_comment = trim($mot_comment) ;
160
							$requete .= $nom_valeur[0].' LIKE "%'.$this->DB->escapeSimple($mot_comment).'%"' ;
142
							$requete .= $nom_valeur[0].' LIKE "%'.$this->proteger($mot_comment).'%"' ;
161
							$requete .= ' AND ' ;
143
							$requete .= ' AND ' ;
162
						}
144
						}
163
					}
145
					}
164
					elseif($nom_valeur[0] == "c.ci_meta_date")
146
					elseif($nom_valeur[0] == "c.ci_meta_date")
165
					{
147
					{
166
						$requete .= 'DATE_FORMAT( '.$nom_valeur[0].', \'%Y-%m-%d\' ) = "'.$this->DB->escapeSimple($nom_valeur[1]).'"' ;
148
						$requete .= 'DATE_FORMAT( '.$nom_valeur[0].', \'%Y-%m-%d\' ) = "'.$this->proteger($nom_valeur[1]).'"' ;
167
						$requete .= ' AND ' ;
149
						$requete .= ' AND ' ;
168
					}
150
					}
169
					elseif($nom_valeur[0] == "c.ci_id_tampon")
151
					elseif($nom_valeur[0] == "c.ci_id_tampon")
170
					{
152
					{
171
						$ids_tampon = rtrim($nom_valeur[1], ',') ;
153
						$ids_tampon = rtrim($nom_valeur[1], ',') ;
172
						$requete .= 'c.ci_id_image IN ( '.$this->DB->escapeSimple($ids_tampon).')' ;
154
						$requete .= 'c.ci_id_image IN ( '.$this->proteger($ids_tampon).')' ;
173
					}
155
					}
174
					elseif($nom_valeur[0] == "b.nom_ret")
156
					elseif($nom_valeur[0] == "b.nom_ret")
175
					{
157
					{
176
						if($nom_valeur[1] == "indetermine") {
158
						if($nom_valeur[1] == "indetermine") {
Line 177... Line 159...
177
							$nom_valeur[1] = 'null';
159
							$nom_valeur[1] = 'null';
178
						}
160
						}
179
						
161
						
180
						$requete .= ' (';
162
						$requete .= ' (';
181
						$requete .= $nom_valeur[0].' LIKE "%'.$this->DB->escapeSimple($nom_valeur[1]).'%"' ;
163
						$requete .= $nom_valeur[0].' LIKE "%'.$this->proteger($nom_valeur[1]).'%"' ;
Line 182... Line 164...
182
						$requete .= ' OR ' ;
164
						$requete .= ' OR ' ;
183
						$requete .= 'b.nom_sel LIKE "%'.$this->DB->escapeSimple($nom_valeur[1]).'%"' ;
165
						$requete .= 'b.nom_sel LIKE "%'.$this->proteger($nom_valeur[1]).'%"' ;
184
						$requete .= ') AND ' ;
166
						$requete .= ') AND ' ;
185
						
167
						
186
					} else
168
					} else
187
					{
169
					{
188
						$requete .= $nom_valeur[0].' = "'.$this->DB->escapeSimple($nom_valeur[1]) ;
170
						$requete .= $nom_valeur[0].' = "'.$this->proteger($nom_valeur[1]) ;
Line 206... Line 188...
206
		
188
		
Line 207... Line 189...
207
		$chaine_requete = str_replace(' ','_',$chaine_requete);
189
		$chaine_requete = str_replace(' ','_',$chaine_requete);
Line 208... Line 190...
208
		
190
		
209
		$requete = ' (';
191
		$requete = ' (';
Line 210... Line 192...
210
	
192
	
211
		$requete .= 'b.nom_ret LIKE "'.$this->DB->escapeSimple($chaine_requete).'%"' ;
193
		$requete .= 'b.nom_ret LIKE "'.$this->proteger($chaine_requete).'%"' ;
Line 212... Line 194...
212
		$requete .= ' OR ' ;
194
		$requete .= ' OR ' ;
213
		
195
		
Line 214... Line 196...
214
		$requete .= 'b.nom_sel LIKE "'.$this->DB->escapeSimple($chaine_requete).'%"' ;
196
		$requete .= 'b.nom_sel LIKE "'.$this->proteger($chaine_requete).'%"' ;
215
		$requete .= ' OR ' ;
197
		$requete .= ' OR ' ;
Line -... Line 198...
-
 
198
 
-
 
199
		$requete .= 'b.location LIKE "'.$this->proteger($chaine_requete).'%" ' ;
-
 
200
		$requete .= ' OR ' ;
216
 
201
		
Line 217... Line 202...
217
		$requete .= 'b.location LIKE "'.$this->DB->escapeSimple($chaine_requete).'%" ' ;
202
		$requete .= 'b.id_location LIKE "'.$this->proteger($chaine_requete).'%" ' ;
Line 218... Line 203...
218
		$requete .= ' OR ' ;
203
		$requete .= ' OR ' ;
219
		
204
		
Line 242... Line 227...
242
			}
227
			}
243
		}
228
		}
Line 244... Line 229...
244
		
229
		
245
		return $tableau_criteres_pour_bdd;
230
		return $tableau_criteres_pour_bdd;
-
 
231
	}
-
 
232
	
-
 
233
		
-
 
234
	private function creerSousRequeteMotsCles($mot_cle) {
-
 
235
        $requete = '';
-
 
236
        if (preg_match('/.*,.*/', $mot_cle)) {
-
 
237
            $requete = $this->creerSousRequeteMotsClesOu($mot_cle);
-
 
238
        } else if (preg_match('/.*ET.*/', $mot_cle)) {
-
 
239
            $requete = $this->creerSousRequeteMotsClesEt($mot_cle);
-
 
240
        } else {       
-
 
241
            // Construction de la requête
-
 
242
            $prerequete =   "SELECT cmc_id_mot_cle_utilisateur, cmc_id_proprietaire FROM cel_mots_cles_images WHERE $where ".
-
 
243
                'cmc_id_mot_cle_general = '.$this->proteger($this->encoderMotCle($mot_cle));
-
 
244
            $elements = $this->executerRequete($prerequete);
-
 
245
            if ($elements != false && count($elements) > 0) {
-
 
246
                foreach ($elements as $occurence) {
-
 
247
                    $requete .= '(ci_meta_mots_cles LIKE "%'.$occurence['cmc_id_mot_cle_utilisateur'].'%" AND ci_ce_utilisateur = '.
-
 
248
                        $this->proteger($occurence['cmc_id_proprietaire']).' ) OR '; 
-
 
249
                }
-
 
250
            }
-
 
251
        }
-
 
252
        $requete = rtrim($requete,' OR ').' AND ';
-
 
253
        return $requete;
-
 
254
    }
-
 
255
   
-
 
256
    private function creerSousRequeteMotsClesOu($mot_cle) {
-
 
257
        $requete = '';
-
 
258
       
-
 
259
        $tab_mots_cles = explode(',', $mot_cle);
-
 
260
        $where = '';
-
 
261
        foreach ($tab_mots_cles as $mot) {
-
 
262
            $where .= 'cmc_id_mot_cle_general = '.$this->proteger($this->encoderMotCle($mot)).' OR ';
-
 
263
        }
-
 
264
        $where = rtrim($where,' OR ');
-
 
265
       
-
 
266
        // Construction de la requête
-
 
267
        $prerequete =   "SELECT cmc_id_mot_cle_utilisateur, cmc_id_proprietaire FROM cel_mots_cles_images WHERE $where ";
-
 
268
        $elements = $this->executerRequete($prerequete);//print_r($elements);
-
 
269
        if ($elements != false && count($elements) > 0) {
-
 
270
            foreach ($elements as $occurence) {
-
 
271
                $requete .= '(ci_meta_mots_cles LIKE "%'.$occurence['cmc_id_mot_cle_utilisateur'].'%" AND ci_ce_utilisateur = '.
-
 
272
                    $this->proteger($occurence['cmc_id_proprietaire']).' ) OR ';
-
 
273
            }
-
 
274
        }
-
 
275
        return $requete;
-
 
276
    }
-
 
277
	
-
 
278
	private function creerSousRequeteMotsClesEt($mot_cle) {
-
 
279
        $requete = '';
-
 
280
        $where = '';
-
 
281
        $champs = 'a.cmc_id_proprietaire , ';
-
 
282
        $table = '';
-
 
283
        $i = "a"; $j = "a";
-
 
284
       
-
 
285
        $tab_mots_cles = explode("ET", $mot_cle);
-
 
286
        foreach ($tab_mots_cles as $mot) {
-
 
287
            $champs .= "$i.cmc_id_mot_cle_utilisateur as $i , ";
-
 
288
            $table .= "cel_mots_cles_images $i , ";
-
 
289
            $where .= "$i.cmc_id_mot_cle_general = ".$this->proteger($this->encoderMotCle($mot)).' AND ';
-
 
290
            if ($i !== "a") {
-
 
291
                $where .= " $i.cmc_id_proprietaire = ".$j.".cmc_id_proprietaire AND ";
-
 
292
                $j++;
-
 
293
            }
-
 
294
            $i++;
-
 
295
        }
-
 
296
        $where = rtrim($where,' AND '); $champs = rtrim($champs,' , '); $table = rtrim($table,' , ');
-
 
297
       
-
 
298
        // Construction de la requête
-
 
299
        $prerequete =   "SELECT $champs FROM $table WHERE $where ";
-
 
300
        $elements = $this->executerRequete($prerequete);//print_r($elements);
-
 
301
        if ($elements != false && count($elements) > 0) {
-
 
302
            foreach ($elements as $occurence) {
-
 
303
                $requete = ' (';
-
 
304
                for ($j = 'a'; $j < $i; $j++) {
-
 
305
                    $requete .= 'ci_meta_mots_cles like "%'.$occurence[$j].'%" AND ';
-
 
306
                }
-
 
307
                $requete .= ' ci_ce_utilisateur = '.$this->proteger($occurence['cmc_id_proprietaire']).' ) OR ';
-
 
308
            }
-
 
309
        }
-
 
310
        return $requete;
246
	}
311
    } 
247
}
312
}
248
?>
313
?>