456 |
aurelien |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
Class InventoryImageListPublic extends DBAccessor {
|
|
|
4 |
|
|
|
5 |
private $start = 0;
|
|
|
6 |
private $limit = 50;
|
|
|
7 |
private $distinct = true;
|
|
|
8 |
|
|
|
9 |
private $criteres = array('mot_cles' => 'c.ci_meta_mots_cles',
|
|
|
10 |
'auteur' => 'c.ci_ce_utilisateur',
|
|
|
11 |
'commune' => 'b.location',
|
|
|
12 |
'departement' => 'b.id_location',
|
|
|
13 |
'taxon' => 'b.nom_ret');
|
|
|
14 |
|
|
|
15 |
function InventoryImageListPublic($config) {
|
|
|
16 |
|
|
|
17 |
$this->config=$config;
|
|
|
18 |
}
|
|
|
19 |
|
|
|
20 |
function getRessource() {
|
|
|
21 |
|
|
|
22 |
}
|
|
|
23 |
|
|
|
24 |
function getElement($uid)
|
|
|
25 |
{
|
|
|
26 |
|
|
|
27 |
// uid[0] : utilisateur obligatoire
|
|
|
28 |
// uid[1] : critères de filtrage de la forme critère1:valeur1;critère2:valeur2
|
|
|
29 |
|
|
|
30 |
$DB=$this->connectDB($this->config,'cel_db');
|
|
|
31 |
|
|
|
32 |
$criteres = array() ;
|
|
|
33 |
|
|
|
34 |
if($uid[0] != '*') {
|
|
|
35 |
|
|
|
36 |
$criteres[$this->criteres['auteur']] = $uid[0];
|
|
|
37 |
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
$criteres = $this->traiterCriteres($_GET) ;
|
|
|
41 |
|
|
|
42 |
// Construction de la requête
|
|
|
43 |
$requete = (($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
|
|
|
44 |
'FROM cel_obs_images a '.
|
|
|
45 |
'INNER JOIN cel_inventory b '.
|
|
|
46 |
'ON a.coi_ce_observation = b.ordre AND a.coi_ce_utilisateur = b.identifiant '.
|
|
|
47 |
'INNER JOIN cel_images c '.
|
|
|
48 |
'ON a.coi_ce_image = c.ci_id_image AND a.coi_ce_utilisateur = c.ci_ce_utilisateur '.
|
|
|
49 |
'WHERE b.transmission = 1 AND b.identifiant = c.ci_ce_utilisateur AND ';
|
|
|
50 |
|
|
|
51 |
$numero_page = 0 ;
|
|
|
52 |
$limite = 50 ;
|
|
|
53 |
|
|
|
54 |
foreach($criteres as $pair)
|
|
|
55 |
{
|
|
|
56 |
$nom_valeur = explode("=",$pair) ;
|
|
|
57 |
|
|
|
58 |
if(sizeof($nom_valeur) != 0)
|
|
|
59 |
{
|
|
|
60 |
if($nom_valeur[0] == "ci_limite")
|
|
|
61 |
{
|
|
|
62 |
$this->limite = $DB->escapeSimple($nom_valeur[1]) ;
|
|
|
63 |
}
|
|
|
64 |
elseif($nom_valeur[0] == "c.ci_numero_page")
|
|
|
65 |
{
|
|
|
66 |
$this->start = $this->limite*$DB->escapeSimple($nom_valeur[1]) ;
|
|
|
67 |
}
|
|
|
68 |
elseif($nom_valeur[0] == "c.ci_meta_mots_cles")
|
|
|
69 |
{
|
|
|
70 |
$mots_cles = rtrim($nom_valeur[1], ',') ;
|
|
|
71 |
$mots_cles_liste = explode("," , $mots_cles) ;
|
|
|
72 |
|
|
|
73 |
foreach($mots_cles_liste as $mot_cle)
|
|
|
74 |
{
|
|
|
75 |
$requete .= $nom_valeur[0].' LIKE "%'.$DB->escapeSimple($mot_cle).'%"' ;
|
|
|
76 |
$requete .= ' AND ' ;
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
elseif($nom_valeur[0] == "c.ci_meta_comment")
|
|
|
80 |
{
|
|
|
81 |
$mots_comment_liste = explode(" " , $nom_valeur[1]) ;
|
|
|
82 |
|
|
|
83 |
foreach($mots_comment_liste as $mot_comment)
|
|
|
84 |
{
|
|
|
85 |
$mot_comment = trim($mot_comment) ;
|
|
|
86 |
$requete .= $nom_valeur[0].' LIKE "%'.$DB->escapeSimple($mot_comment).'%"' ;
|
|
|
87 |
$requete .= ' AND ' ;
|
|
|
88 |
}
|
|
|
89 |
}
|
|
|
90 |
elseif($nom_valeur[0] == "c.ci_meta_date")
|
|
|
91 |
{
|
|
|
92 |
$requete .= 'DATE_FORMAT( '.$nom_valeur[0].', \'%Y-%m-%d\' ) = "'.$DB->escapeSimple($nom_valeur[1]).'"' ;
|
|
|
93 |
$requete .= ' AND ' ;
|
|
|
94 |
}
|
|
|
95 |
elseif($nom_valeur[0] == "c.ci_id_tampon")
|
|
|
96 |
{
|
|
|
97 |
$ids_tampon = rtrim($nom_valeur[1], ',') ;
|
|
|
98 |
$requete .= 'c.ci_id_image IN ( '.$DB->escapeSimple($ids_tampon).')' ;
|
|
|
99 |
}
|
|
|
100 |
else
|
|
|
101 |
{
|
|
|
102 |
$requete .= $nom_valeur[0].' = "'.$DB->escapeSimple($nom_valeur[1]) ;
|
|
|
103 |
$requete .= '" AND ' ;
|
|
|
104 |
}
|
|
|
105 |
}
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
$requete = rtrim($requete,' AND ') ;
|
|
|
109 |
|
|
|
110 |
$requete .= ' ORDER BY '.((!is_null($this->orderby)) ? $this->orderby : 'c.ci_meta_date_ajout DESC').' ';
|
|
|
111 |
$requete .= "LIMIT $this->start,$this->limit ";
|
|
|
112 |
|
|
|
113 |
$res =& $DB->query($requete);
|
|
|
114 |
if (PEAR::isError($res)) {
|
|
|
115 |
die($res->getMessage());
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
$images = array();
|
|
|
119 |
|
|
|
120 |
while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
|
|
|
121 |
$images[]= $row;
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
$images_json = json_encode($images) ;
|
|
|
125 |
|
|
|
126 |
header("content-type: text/html") ;
|
|
|
127 |
print $images_json ;
|
|
|
128 |
exit() ;
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
private function traiterCriteres($tableau_criteres) {
|
|
|
132 |
|
|
|
133 |
$tableau_criteres_pour_bdd = array();
|
|
|
134 |
|
|
|
135 |
foreach($tableau_criteres as $nom_critere => $valeur_critere) {
|
|
|
136 |
if(isset($this->criteres[$nom_critere])) {
|
|
|
137 |
$tableau_criteres_pour_bdd[] = $this->criteres[$nom_critere].'='.$valeur_critere;
|
|
|
138 |
}
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
return $tableau_criteres_pour_bdd;
|
|
|
142 |
}
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
?>
|