Subversion Repositories Applications.bazar

Rev

Rev 468 | Blame | Compare with Previous | Last modification | View Log | RSS feed

Index: bibliotheque/bazar.fonct.rss.php
===================================================================
--- bibliotheque/bazar.fonct.rss.php    (révision 464)
+++ bibliotheque/bazar.fonct.rss.php    (révision 465)
@@ -392,7 +392,7 @@
                        $res .= '<br />'."\n".'<div class="BAZ_cadre_fiche BAZ_cadre_fiche_'.$GLOBALS['_BAZAR_']['class'].'">'."\n";
                        $res .= '<h2 class="BAZ_titre BAZ_titre_'.$GLOBALS['_BAZAR_']['class'].'">'.BAZ_LES_STRUCTURES_POSSEDANT_UNE_RESSOURCE.'</h2>'."\n";
                        $requete = 'SELECT '.BAZ_CHAMPS_ID.', '.BAZ_CHAMPS_NOM.' FROM bazar_appropriation,'.BAZ_ANNUAIRE.' WHERE ba_ce_id_fiche='.$GLOBALS['_BAZAR_']['id_fiche'].' AND ba_ce_id_structure='.BAZ_CHAMPS_ID.' ORDER BY '.BAZ_CHAMPS_NOM.' ASC';
-                       $resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
+                       $resultat = $GLOBALS['_BAZAR_']['db']->query($requete . ' -- ' . __FILE__ . ':' . __LINE__) ;
                        if (DB::isError ($resultat)) {
                                return $resultat->getMessage().'<br />'.$resultat->getDebugInfo();
                        }
@@ -640,18 +640,17 @@
 function gen_RSS($typeannonce='', $nbitem='', $emetteur='', $valide=1, $requeteSQL='', $requeteSQLFrom = '', $requeteWhereListe = '', $categorie_nature='', $order = '') {
        // generation de la requete MySQL personnalisee
 
-       $req_where=0;
        $requete = 'SELECT DISTINCT bf_id_fiche, bf_titre, bf_date_debut_validite_fiche, bf_description,bf_date_debut_evenement, bn_label_nature, bf_date_creation_fiche, bf_ce_utilisateur '.
                                'FROM bazar_fiche, bazar_nature '.$requeteSQLFrom.' WHERE '.$requeteWhereListe;
+
+       $where_cond = array();
        if ($valide!=2) {
-               $requete .= 'bf_statut_fiche='.$valide;
-               $req_where=1;
+               $where_cond[] = 'bf_statut_fiche='.$valide;
        }
        $nomflux=html_entity_decode(BAZ_DERNIERE_ACTU);
        if (!is_array ($typeannonce) && $typeannonce!='' and $typeannonce!='toutes') {
-               if ($req_where==1) {$requete .= ' AND ';}
-               $requete .= 'bf_ce_nature='.$typeannonce.' and bf_ce_nature=bn_id_nature ';;
-               $req_where=1;
+               $where_cond[] = 'bf_ce_nature='.$typeannonce;
+               $where_cond[] = ' bf_ce_nature=bn_id_nature';
                //le nom du flux devient le type d'annonce
                $requete_nom_flux = 'select bn_label_nature from bazar_nature where bn_id_nature = '.$typeannonce;
                $nomflux = $GLOBALS['_BAZAR_']['db']->getOne($requete_nom_flux) ;
@@ -659,38 +658,24 @@
 
        // cas où on veut toutes les annonces
        if ($typeannonce == 'toutes') {
-               if ($req_where==1) {$requete .= ' AND ';}
-               $requete .= 'bf_ce_nature IN (1,2,3,4' ;
-               $chaine = '';
-               $requete .= ') and bf_ce_nature=bn_id_nature ';
+               $where_cond[] = 'bf_ce_nature IN (1,2,3,4)';
+               $where_cond[] = 'bf_ce_nature=bn_id_nature';
        }
 
        // Cas ou il y plusieurs type d annonce demande
-       if (is_array ($typeannonce)) {
-               if ($req_where==1) {$requete .= ' AND ';}
-               $requete .= 'bf_ce_nature IN (' ;
-               $chaine = '';
-               foreach ($typeannonce as $valeur) $chaine .= '"'.$valeur.'",' ;
-               $requete .= substr ($chaine, 0, strlen ($chaine)-1) ;
-               $requete .= ') and bf_ce_nature=bn_id_nature ';
+       if (is_array($typeannonce) && ! empty($typeannonce)) {
+               $where_cond[] = 'bf_ce_nature IN (' . '"' . implode('","', $typeannonce) . '"' . ')';
+               $where_cond[] = 'bf_ce_nature=bn_id_nature';
        }
-       $utilisateur = new Administrateur_bazar ($GLOBALS['AUTH']) ;
 
-       if ($utilisateur->isSuperAdmin()) {
-               $req_where=1;
-       } else {
-               if ($req_where==1) {
-                       $requete .= ' AND ';
-               }
+       // useless ?
+       // $utilisateur = new Administrateur_bazar ($GLOBALS['AUTH']) ;
 
-       }
+       $where_cond[] = 'bf_date_debut_evenement >= NOW()';
+       $where_cond[] = 'bn_id_nature=bf_ce_nature';
 
-       $requete .= 'bf_date_debut_evenement >= NOW() AND bn_id_nature=bf_ce_nature';
-
        if ($emetteur!='' && $emetteur!='tous') {
-               if ($req_where==1) {$requete .= ' AND ';}
-               $requete .= 'bf_ce_utilisateur='.$emetteur;
-               $req_where=1;
+               $where_cond[] = 'bf_ce_utilisateur='.$emetteur;
                //requete pour afficher le nom de la structure
                $requetenom = 'SELECT '.BAZ_CHAMPS_NOM.', '.BAZ_CHAMPS_PRENOM.' FROM '.
                                                BAZ_ANNUAIRE.' WHERE '.BAZ_CHAMPS_ID.'='.$emetteur;
@@ -701,26 +686,25 @@
                $ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
                $nomflux .= ' ('.$ligne[BAZ_CHAMPS_NOM].' '.$ligne[BAZ_CHAMPS_PRENOM].')';
        }
-       if ($requeteSQL!='') {
-               if ($req_where==1) {$requete .= ' AND ';}
-               $requete .= '('.$requeteSQL.')';
-               $req_where=1;
+       if ($requeteSQL) {
+               $where_cond[] = $requeteSQL;
        }
+
        if ($categorie_nature!='') {
-               if ($req_where==1) {$requete .= ' AND ';}
-               $requete .= 'bn_ce_id_menu IN ('.$categorie_nature.') and bf_ce_nature=bn_id_nature ';
-               $req_where=1;
+               $where_cond[] = 'bn_ce_id_menu IN ('.$categorie_nature.')';
+               $where_cond[] = 'bf_ce_nature=bn_id_nature';
        }
 
        if (isset($_REQUEST['departement'])) {
-                 if ($req_where==1) {$requete .= ' AND ';}
-                 $requete .= ' bf_cp_lieu_evenement LIKE "'.$_REQUEST['departement'].'%" ';
+               $where_cond[] = 'bf_cp_lieu_evenement LIKE "'.$_REQUEST['departement'].'%"';
        }
 
+
+       $requete .= implode(' AND ', $where_cond);
        $requete .= ' ORDER BY bf_date_debut_evenement ASC ';
 
        if ($nbitem!='') {$requete .= ' LIMIT 0,'.$nbitem;}
-       $resultat = $GLOBALS['_BAZAR_']['db']->query($requete) ;
+       $resultat = $GLOBALS['_BAZAR_']['db']->query($requete . ' -- ' . __FILE__ . ':' . __LINE__) ;
 
        //mail('aurelien@tela-botanica.org','requete',$requete);