2,8 → 2,10 |
|
Class InventoryImageListPublic extends DBAccessor { |
|
private $DB = null; |
|
private $start = 0; |
private $limit = 50; |
private $limit = 100; |
private $distinct = true; |
|
private $criteres = array('mot_cles' => 'c.ci_meta_mots_cles', |
22,37 → 24,109 |
} |
|
function getElement($uid) |
{ |
|
{ |
// uid[0] : utilisateur obligatoire |
// uid[1] : critères de filtrage de la forme critère1:valeur1;critère2:valeur2 |
|
$DB=$this->connectDB($this->config,'cel_db'); |
$this->DB = $this->connectDB($this->config,'cel_db'); |
|
$criteres = array() ; |
|
if($uid[0] != '*') { |
if($uid[0] == '*') { |
$criteres = array(); |
} else { |
|
$criteres[$this->criteres['auteur']] = $uid[0]; |
|
if(!$this->estUneRechercheGenerale()) { |
|
$criteres = $this->traiterCriteres($_GET); |
|
if(empty($criteres)) { |
header("content-type: text/html"); |
$images_json = json_encode(array()); |
print $images_json; |
exit() ; |
} |
} |
} |
|
$criteres = $this->traiterCriteres($_GET) ; |
|
// Construction de la requête |
$requete = (($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '. |
'FROM cel_obs_images a '. |
if(isset($_GET['start'])) { |
$this->start = $_GET['start']; |
} |
|
if(isset($_GET['limit'])) { |
$this->limit = $_GET['limit']; |
} |
|
// Construction de la requête |
$requete_debut = 'SELECT * '; |
|
$requete_nb = 'SELECT COUNT(*) as nb_res '; |
|
$jointure = 'FROM cel_obs_images a '. |
'INNER JOIN cel_inventory b '. |
'ON a.coi_ce_observation = b.ordre AND a.coi_ce_utilisateur = b.identifiant '. |
'INNER JOIN cel_images c '. |
'ON a.coi_ce_image = c.ci_id_image AND a.coi_ce_utilisateur = c.ci_ce_utilisateur '. |
'WHERE b.transmission = 1 AND b.identifiant = c.ci_ce_utilisateur AND '; |
|
$requete_debut .= $jointure; |
$requete_nb .= $jointure; |
|
if($this->estUneRechercheGenerale()) { |
$chaine_requete = $_GET['recherche']; |
$requete = $this->creerSousRequeteRechercheGenerale($chaine_requete) ; |
} else { |
$criteres = $this->traiterCriteres($_GET) ; |
$requete = $this->creerSousRequeteRechercheParCriteres($criteres); |
} |
|
$requete_debut .= $requete; |
$requete_nb .= $requete; |
|
$requete_debut = rtrim($requete_debut,'AND '); |
$requete_nb = rtrim($requete_nb,'AND '); |
|
$requete_debut .= ' ORDER BY '.((!is_null($this->orderby)) ? $this->orderby : 'c.ci_meta_date_ajout DESC').' '; |
$requete_debut .= "LIMIT $this->start,$this->limit "; |
|
$res =& $this->DB->query($requete_debut); |
if (PEAR::isError($res)) { |
die($res->getMessage()); |
} |
|
$res_nb =& $this->DB->query($requete_nb); |
if (PEAR::isError($res)) { |
die($res->getMessage()); |
} |
|
$images = array(); |
|
$total = 0; |
|
while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) { |
$images[]= $row; |
$nb_res = $row['nb_res']; |
} |
|
while ($row =& $res_nb->fetchrow(DB_FETCHMODE_ASSOC)) { |
$total= $row['nb_res']; |
} |
|
$numero_page = 0 ; |
$limite = 50 ; |
$resultat = array('total' => $total,'images' => $images, 'requete' => $requete_debut); |
|
$images_json = json_encode($resultat) ; |
|
header("content-type: text/html") ; |
print $images_json ; |
exit() ; |
} |
|
private function creerSousRequeteRechercheParCriteres($criteres) { |
|
$requete = ''; |
|
foreach($criteres as $pair) |
{ |
{ |
$nom_valeur = explode("=",$pair) ; |
|
if(sizeof($nom_valeur) != 0) |
59,11 → 133,11 |
{ |
if($nom_valeur[0] == "ci_limite") |
{ |
$this->limite = $DB->escapeSimple($nom_valeur[1]) ; |
$this->limite = $this->DB->escapeSimple($nom_valeur[1]) ; |
} |
elseif($nom_valeur[0] == "c.ci_numero_page") |
{ |
$this->start = $this->limite*$DB->escapeSimple($nom_valeur[1]) ; |
$this->start = $this->limite*$this->DB->escapeSimple($nom_valeur[1]) ; |
} |
elseif($nom_valeur[0] == "c.ci_meta_mots_cles") |
{ |
72,7 → 146,7 |
|
foreach($mots_cles_liste as $mot_cle) |
{ |
$requete .= $nom_valeur[0].' LIKE "%'.$DB->escapeSimple($mot_cle).'%"' ; |
$requete .= $nom_valeur[0].' LIKE "%'.$this->DB->escapeSimple($mot_cle).'%"' ; |
$requete .= ' AND ' ; |
} |
} |
83,23 → 157,35 |
foreach($mots_comment_liste as $mot_comment) |
{ |
$mot_comment = trim($mot_comment) ; |
$requete .= $nom_valeur[0].' LIKE "%'.$DB->escapeSimple($mot_comment).'%"' ; |
$requete .= $nom_valeur[0].' LIKE "%'.$this->DB->escapeSimple($mot_comment).'%"' ; |
$requete .= ' AND ' ; |
} |
} |
elseif($nom_valeur[0] == "c.ci_meta_date") |
{ |
$requete .= 'DATE_FORMAT( '.$nom_valeur[0].', \'%Y-%m-%d\' ) = "'.$DB->escapeSimple($nom_valeur[1]).'"' ; |
$requete .= 'DATE_FORMAT( '.$nom_valeur[0].', \'%Y-%m-%d\' ) = "'.$this->DB->escapeSimple($nom_valeur[1]).'"' ; |
$requete .= ' AND ' ; |
} |
elseif($nom_valeur[0] == "c.ci_id_tampon") |
{ |
$ids_tampon = rtrim($nom_valeur[1], ',') ; |
$requete .= 'c.ci_id_image IN ( '.$DB->escapeSimple($ids_tampon).')' ; |
$requete .= 'c.ci_id_image IN ( '.$this->DB->escapeSimple($ids_tampon).')' ; |
} |
else |
elseif($nom_valeur[0] == "b.nom_ret") |
{ |
$requete .= $nom_valeur[0].' = "'.$DB->escapeSimple($nom_valeur[1]) ; |
if($nom_valeur[1] == "indetermine") { |
$nom_valeur[1] = 'null'; |
} |
|
$requete .= ' ('; |
$requete .= $nom_valeur[0].' LIKE "%'.$this->DB->escapeSimple($nom_valeur[1]).'%"' ; |
$requete .= ' OR ' ; |
$requete .= 'b.nom_sel LIKE "%'.$this->DB->escapeSimple($nom_valeur[1]).'%"' ; |
$requete .= ') AND ' ; |
|
} else |
{ |
$requete .= $nom_valeur[0].' = "'.$this->DB->escapeSimple($nom_valeur[1]) ; |
$requete .= '" AND ' ; |
} |
} |
106,33 → 192,51 |
} |
|
$requete = rtrim($requete,' AND ') ; |
|
return $requete; |
} |
|
private function creerSousRequeteRechercheGenerale($chaine_requete) { |
|
if(trim($chaine_requete) == '') { |
return ''; |
} |
|
$chaine_requete = strtolower($chaine_requete); |
|
$chaine_requete = str_replace(' ','_',$chaine_requete); |
|
$requete = ' ('; |
|
$requete .= 'b.nom_ret LIKE "'.$this->DB->escapeSimple($chaine_requete).'%"' ; |
$requete .= ' OR ' ; |
|
$requete .= 'b.nom_sel LIKE "'.$this->DB->escapeSimple($chaine_requete).'%"' ; |
$requete .= ' OR ' ; |
|
$requete .= ' ORDER BY '.((!is_null($this->orderby)) ? $this->orderby : 'c.ci_meta_date_ajout DESC').' '; |
$requete .= "LIMIT $this->start,$this->limit "; |
$requete .= 'b.location LIKE "'.$this->DB->escapeSimple($chaine_requete).'%" ' ; |
$requete .= ' OR ' ; |
|
$res =& $DB->query($requete); |
if (PEAR::isError($res)) { |
die($res->getMessage()); |
} |
|
$images = array(); |
|
while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) { |
$images[]= $row; |
} |
|
$images_json = json_encode($images) ; |
|
header("content-type: text/html") ; |
print $images_json ; |
exit() ; |
$requete .= 'b.id_location LIKE "'.$this->DB->escapeSimple($chaine_requete).'%" ' ; |
$requete .= ' OR ' ; |
|
$requete .= 'c.ci_ce_utilisateur LIKE "'.$this->DB->escapeSimple($chaine_requete).'%" ' ; |
|
$requete .= ') '; |
|
return $requete; |
} |
|
private function estUneRechercheGenerale() { |
return isset($_GET['recherche']); |
} |
|
private function traiterCriteres($tableau_criteres) { |
|
$tableau_criteres_pour_bdd = array(); |
|
foreach($tableau_criteres as $nom_critere => $valeur_critere) { |
|
foreach($tableau_criteres as $nom_critere => $valeur_critere) { |
if(isset($this->criteres[$nom_critere])) { |
$tableau_criteres_pour_bdd[] = $this->criteres[$nom_critere].'='.$valeur_critere; |
} |
141,5 → 245,4 |
return $tableau_criteres_pour_bdd; |
} |
} |
|
?> |