Subversion Repositories eFlore/Applications.bibliobota

Rev

Rev 2 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 30
1
<?php
1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */ 
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */ 
3
// +------------------------------------------------------------------------------------------------------+
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 4.1                                                                                      |
4
// | PHP version 4.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
7
// +------------------------------------------------------------------------------------------------------+
7
// +------------------------------------------------------------------------------------------------------+
8
// | This library is free software; you can redistribute it and/or                                        |
8
// | This library is free software; you can redistribute it and/or                                        |
9
// | modify it under the terms of the GNU Lesser General Public                                           |
9
// | modify it under the terms of the GNU Lesser General Public                                           |
10
// | License as published by the Free Software Foundation; either                                         |
10
// | License as published by the Free Software Foundation; either                                         |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
12
// |                                                                                                      |
12
// |                                                                                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
16
// | Lesser General Public License for more details.                                                      |
16
// | Lesser General Public License for more details.                                                      |
17
// |                                                                                                      |
17
// |                                                                                                      |
18
// | You should have received a copy of the GNU Lesser General Public                                     |
18
// | You should have received a copy of the GNU Lesser General Public                                     |
19
// | License along with this library; if not, write to the Free Software                                  |
19
// | License along with this library; if not, write to the Free Software                                  |
20
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
20
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
21
// +------------------------------------------------------------------------------------------------------+
21
// +------------------------------------------------------------------------------------------------------+
22
// CVS : $Id: bbc_requete_media.fonct.php,v 1.1 2005-11-23 10:22:25 jp_milcent Exp $
22
// CVS : $Id: bbc_requete_media.fonct.php,v 1.3 2004/09/15 10:32:30 jpm Exp $
23
/**
23
/**
24
* Fonctions de création de la requête sur un média.
24
* Fonctions de création de la requête sur un média.
25
*
25
*
26
* Contient une fonction créant la requête d'intérogation de la base de données.
26
* Contient une fonction créant la requête d'intérogation de la base de données.
27
* Valable pour le paramètre "media".
27
* Valable pour le paramètre "media".
28
*
28
*
29
*@package BiblioBota-Consultation
29
*@package BiblioBota-Consultation
30
*@subpackage Fonctions
30
*@subpackage Fonctions
31
//Auteur original :
31
//Auteur original :
32
*@author        Jean-Charles GRANGER <tela@vecteur.org>
32
*@author        Jean-Charles GRANGER <tela@vecteur.org>
33
//Autres auteurs :
33
//Autres auteurs :
34
*@author        Jean-Pascal MILCENT <jpm@clapas.org>
34
*@author        Jean-Pascal MILCENT <jpm@clapas.org>
35
*@copyright     Tela-Botanica 2000-2004
35
*@copyright     Tela-Botanica 2000-2004
36
*@version       $Revision: 1.1 $ $Date: 2005-11-23 10:22:25 $
36
*@version       $Revision: 1.3 $ $Date: 2004/09/15 10:32:30 $
37
// +------------------------------------------------------------------------------------------------------+
37
// +------------------------------------------------------------------------------------------------------+
38
*/
38
*/
39
 
39
 
40
// +------------------------------------------------------------------------------------------------------+
40
// +------------------------------------------------------------------------------------------------------+
41
// |                                            ENTETE du PROGRAMME                                       |
41
// |                                            ENTETE du PROGRAMME                                       |
42
// +------------------------------------------------------------------------------------------------------+
42
// +------------------------------------------------------------------------------------------------------+
43
 
-
 
44
 
43
 
45
// +------------------------------------------------------------------------------------------------------+
-
 
46
// |                                           LISTE de FONCTIONS                                         |
-
 
47
// +------------------------------------------------------------------------------------------------------+
-
 
-
 
44
 
-
 
45
// +------------------------------------------------------------------------------------------------------+
-
 
46
// |                                           LISTE de FONCTIONS                                         |
-
 
47
// +------------------------------------------------------------------------------------------------------+
48
 
48
 
49
/** Fonction mkquery() - Créé une requête intérogeant la base de donnée.
49
/** Fonction mkquery() - Créé une requête intérogeant la base de donnée.
50
*
50
*
51
* Fonction créant la requête d'intérogation de la base de données pour le
51
* Fonction créant la requête d'intérogation de la base de données pour le
52
* paramêtre "media".
52
* paramêtre "media".
53
*
53
*
54
* @return  string la requête permettant de récupérer les média.
54
* @return  string la requête permettant de récupérer les média.
55
*/
55
*/
56
function mkquery()
56
function mkquery()
57
{
57
{
58
    global $tbl;
58
    global $tbl;
59
    global $TabFinder;
59
    global $TabFinder;
60
    global $nbr_total;
60
    global $nbr_total;
61
    global $var_biblio;
61
    global $var_biblio;
62
    global $query_dom;
62
    global $query_dom;
63
    global $plugin_store;
63
    global $plugin_store;
64
    
64
    
65
    // si limit_domain vaut 1, alors on réduit les recherches au seul domaine botanique
65
    // si limit_domain vaut 1, alors on réduit les recherches au seul domaine botanique
66
    
66
    
67
    if ($var_biblio['limit_domain'] == 1) {
67
    if ($var_biblio['limit_domain'] == 1) {
68
        $add_from_dom = ', '.$tbl['domaine'].', '.$tbl['domaine_lk'];
68
        $add_from_dom = ', '.$tbl['domaine'].', '.$tbl['domaine_lk'];
69
        // lien domaines -- table de jointure domaines
69
        // lien domaines -- table de jointure domaines
70
        $add_limit_dom = ' AND ('.$tbl['domaine'].'.B_D_ID = '.$tbl['domaine_lk'].'.B_DL_IDDOM)';
70
        $add_limit_dom = ' AND ('.$tbl['domaine'].'.B_D_ID = '.$tbl['domaine_lk'].'.B_DL_IDDOM)';
71
        // lien articles -- table de jointure domaines
71
        // lien articles -- table de jointure domaines
72
        $add_limit_dom .= ' AND ('.$tbl['item'].'.B_I_IDITEM = '.$tbl['domaine_lk'].'.B_DL_IDITEM)';
72
        $add_limit_dom .= ' AND ('.$tbl['item'].'.B_I_IDITEM = '.$tbl['domaine_lk'].'.B_DL_IDITEM)';
73
        $add_limit_dom .= ' AND '.$tbl['domaine'].'.B_D_ID = 1';
73
        $add_limit_dom .= ' AND '.$tbl['domaine'].'.B_D_ID = 1';
74
    } else {
74
    } else {
75
        $add_from_dom = ', '.$tbl['domaine'].', '.$tbl['domaine_lk'];
75
        $add_from_dom = ', '.$tbl['domaine'].', '.$tbl['domaine_lk'];
76
        // lien domaines -- table de jointure domaines
76
        // lien domaines -- table de jointure domaines
77
        $add_limit_dom = ' AND ('.$tbl['domaine'].'.B_D_ID = '.$tbl['domaine_lk'].'.B_DL_IDDOM)';
77
        $add_limit_dom = ' AND ('.$tbl['domaine'].'.B_D_ID = '.$tbl['domaine_lk'].'.B_DL_IDDOM)';
78
        // lien articles -- table de jointure domaines
78
        // lien articles -- table de jointure domaines
79
        $add_limit_dom .= ' AND ('.$tbl['item'].'.B_I_IDITEM = '.$tbl['domaine_lk'].'.B_DL_IDITEM)';
79
        $add_limit_dom .= ' AND ('.$tbl['item'].'.B_I_IDITEM = '.$tbl['domaine_lk'].'.B_DL_IDITEM)';
80
    }
80
    }
81
    
81
    
82
    /*
82
    /*
83
    Pour une implémentation d'une recherche sur TOUTE LA TABLE ARTICLES
83
    Pour une implémentation d'une recherche sur TOUTE LA TABLE ARTICLES
84
    il faut une requête spéciale qui fasse une jointure à la fois avec les
84
    il faut une requête spéciale qui fasse une jointure à la fois avec les
85
    tables structure-coll-serie-fasc-art et les tables str-art-media... gasp... 
85
    tables structure-coll-serie-fasc-art et les tables str-art-media... gasp... 
86
    */
86
    */
87
    
87
    
88
    /* si la variable de catégorie / type vaut 0, il n'y a pas affinage de la requête par catégorie */
88
    /* si la variable de catégorie / type vaut 0, il n'y a pas affinage de la requête par catégorie */
89
    
89
    
90
    if (BB_ARGUMENT_REGROUPEMENT == 'article') {
90
    if (BB_ARGUMENT_REGROUPEMENT == 'article') {
91
        // On demande ici les articles : mise en place des réducteurs
91
        // On demande ici les articles : mise en place des réducteurs
92
        $add_select = 'B_C_CRAI, '.$tbl['serie'].'.*, B_C_NOMCOMPLET, B_C_ABREGE, B_F_NUMERO, B_F_TITRE, B_F_DATE, B_A_PAGEDEBUT, B_A_PAGEFIN, ';
92
        $add_select = 'B_C_CRAI, '.$tbl['serie'].'.*, B_C_NOMCOMPLET, B_C_ABREGE, B_F_NUMERO, B_F_TITRE, B_F_DATE, B_A_PAGEDEBUT, B_A_PAGEFIN, ';
93
        // $add_select = $tbl['collection'].".B_C_CRAI, ".$tbl['serie'].".*, ".$tbl['collection'].".B_C_NOMCOMPLET, ".$tbl['collection'].".B_C_ABREGE, ".$tbl['fascicule'].".B_F_TITRE, ".$tbl['fascicule'].".B_F_DATE, ".$tbl['article'].".B_A_PAGEDEBUT, ".$tbl['article'].".B_A_PAGEFIN, ";
93
        // $add_select = $tbl['collection'].".B_C_CRAI, ".$tbl['serie'].".*, ".$tbl['collection'].".B_C_NOMCOMPLET, ".$tbl['collection'].".B_C_ABREGE, ".$tbl['fascicule'].".B_F_TITRE, ".$tbl['fascicule'].".B_F_DATE, ".$tbl['article'].".B_A_PAGEDEBUT, ".$tbl['article'].".B_A_PAGEFIN, ";
94
        $add_from = $tbl['collection'].' LEFT JOIN '.$tbl['str'].' ON B_C_LKSTR = B_S_IDSTR, '.$tbl['fascicule'].', '.$tbl['serie'].', '.$tbl['article'].',';
94
        $add_from = $tbl['collection'].' LEFT JOIN '.$tbl['str'].' ON B_C_LKSTR = B_S_IDSTR, '.$tbl['fascicule'].', '.$tbl['serie'].', '.$tbl['article'].',';
95
        // jointure coll - serie
95
        // jointure coll - serie
96
        $special_join = ' AND ('.$tbl['collection'].'.B_C_CRAI = '.$tbl['serie'].'.B_SER_CRAICOLL)';
96
        $special_join = ' AND ('.$tbl['collection'].'.B_C_CRAI = '.$tbl['serie'].'.B_SER_CRAICOLL)';
97
        // jointure serie - fasc
97
        // jointure serie - fasc
98
        $special_join .= ' AND ('.$tbl['serie'].'.B_SER_CRAICOLL = '.$tbl['fascicule'].'.B_F_CRAICOLL)';
98
        $special_join .= ' AND ('.$tbl['serie'].'.B_SER_CRAICOLL = '.$tbl['fascicule'].'.B_F_CRAICOLL)';
99
        $special_join .= ' AND ('.$tbl['serie'].'.B_SER_IDSERIE = '.$tbl['fascicule'].'.B_F_CRAISERIE)';
99
        $special_join .= ' AND ('.$tbl['serie'].'.B_SER_IDSERIE = '.$tbl['fascicule'].'.B_F_CRAISERIE)';
100
        // jointure fasc - item
100
        // jointure fasc - item
101
        $special_join .= ' AND ('.$tbl['fascicule'].'.B_F_CRAICOLL = '.$tbl['article'].'.B_A_CRAICOLL)';
101
        $special_join .= ' AND ('.$tbl['fascicule'].'.B_F_CRAICOLL = '.$tbl['article'].'.B_A_CRAICOLL)';
102
        $special_join .= ' AND ('.$tbl['fascicule'].'.B_F_CRAISERIE = '.$tbl['article'].'.B_A_CRAISERIE)';
102
        $special_join .= ' AND ('.$tbl['fascicule'].'.B_F_CRAISERIE = '.$tbl['article'].'.B_A_CRAISERIE)';
103
        $special_join .= ' AND ('.$tbl['fascicule'].'.B_F_NUMERO = '.$tbl['article'].'.B_A_CRAIFASC)';
103
        $special_join .= ' AND ('.$tbl['fascicule'].'.B_F_NUMERO = '.$tbl['article'].'.B_A_CRAIFASC)';
104
        // jointure item - article
104
        // jointure item - article
105
        $special_join .= ' AND ('.$tbl['item'].'.B_I_IDITEM = '.$tbl['article'].'.B_A_IDART)';
105
        $special_join .= ' AND ('.$tbl['item'].'.B_I_IDITEM = '.$tbl['article'].'.B_A_IDART)';
106
        
106
        
107
        // réducteur de catégorie (collections) categ
107
        // réducteur de catégorie (collections) categ
108
        if ($TabFinder['categ'] != '') {
108
        if ($TabFinder['categ'] != '') {
109
            $add_to_query = ' AND ('.$tbl['article'].'.B_A_CRAICOLL like "'.$TabFinder['categ'].'%")';
109
            $add_to_query = ' AND ('.$tbl['article'].'.B_A_CRAICOLL like "'.$TabFinder['categ'].'%")';
110
        } else {
110
        } else {
111
            $add_to_query = '';
111
            $add_to_query = '';
112
        }
112
        }
113
    } else {
113
    } else {
114
        // On demande ici les livres et médias
114
        // On demande ici les livres et médias
115
        $add_select = $tbl['media'].'.*, '.$tbl['monnaie'].'.*, ';
115
        $add_select = $tbl['media'].'.*, '.$tbl['monnaie'].'.*, ';
116
        // Ajout du FROM
116
        // Ajout du FROM
117
        $add_from = $tbl['media'].' LEFT JOIN '.$tbl['str'].' ON B_M_LKSTR = B_S_IDSTR, '.$tbl['monnaie'].', ';
117
        $add_from = $tbl['media'].' LEFT JOIN '.$tbl['str'].' ON B_M_LKSTR = B_S_IDSTR, '.$tbl['monnaie'].', ';
118
        // lien media -- article
118
        // lien media -- article
119
        $special_join = ' AND ('.$tbl['media'].'.B_M_IDMEDIA = '.$tbl['item'].'.B_I_IDITEM)';
119
        $special_join = ' AND ('.$tbl['media'].'.B_M_IDMEDIA = '.$tbl['item'].'.B_I_IDITEM)';
120
        // lien media -- monnaie
120
        // lien media -- monnaie
121
        $special_join .= ' AND ('.$tbl['media'].'.B_M_LKMONNAIE = '.$tbl['monnaie'].'.GEN_MON_IDMONNAIE)';
121
        $special_join .= ' AND ('.$tbl['media'].'.B_M_LKMONNAIE = '.$tbl['monnaie'].'.GEN_MON_IDMONNAIE)';
122
        //pas de réducteur de catégorie pour les livres
122
        //pas de réducteur de catégorie pour les livres
123
        $add_to_query = '';
123
        $add_to_query = '';
124
    }
124
    }
125
    
125
    
126
    // Compte Total : comptage du nombre de données de la table
126
    // Compte Total : comptage du nombre de données de la table
127
    // d'abord, créer les critères de sélection physiques et logiques.
127
    // d'abord, créer les critères de sélection physiques et logiques.
128
    if (($TabFinder['categ_3'] == '') || (BB_ARGUMENT_REGROUPEMENT == 'article')) {
128
    if (($TabFinder['categ_3'] == '') || (BB_ARGUMENT_REGROUPEMENT == 'article')) {
129
        if ((!empty($query_dom['log']))) {
129
        if ((!empty($query_dom['log']))) {
130
            $create_log = $query_dom['log'];
130
            $create_log = $query_dom['log'];
131
        } else {
131
        } else {
132
            $create_log = '';
132
            $create_log = '';
133
        }
133
        }
134
    } else {
134
    } else {
135
        $create_log = 'B_I_TYPLOG = '.$TabFinder['categ_3'];
135
        $create_log = 'B_I_TYPLOG = '.$TabFinder['categ_3'];
136
    }
136
    }
137
    
137
    
138
    if ($TabFinder['categ_2'] == '') {
138
    if ($TabFinder['categ_2'] == '') {
139
        if ((!empty($query_dom['phy']))) {
139
        if ((!empty($query_dom['phy']))) {
140
            $create_phy = $query_dom['phy'];
140
            $create_phy = $query_dom['phy'];
141
        } else {
141
        } else {
142
            $create_phy = '';
142
            $create_phy = '';
143
        }
143
        }
144
    } else {
144
    } else {
145
        $create_phy = 'B_I_TYPPHY = '.$TabFinder['categ_2'];
145
        $create_phy = 'B_I_TYPPHY = '.$TabFinder['categ_2'];
146
    }
146
    }
147
    
147
    
148
    if (($create_phy != "")&&($create_log != "")) {
148
    if (($create_phy != "")&&($create_log != "")) {
149
        $create_logphy = "$create_log AND $create_phy";
149
        $create_logphy = "$create_log AND $create_phy";
150
    } else if (($create_phy != "")||($create_log != "")) {
150
    } else if (($create_phy != "")||($create_log != "")) {
151
        $create_logphy = "$create_log$create_phy";
151
        $create_logphy = "$create_log$create_phy";
152
    }
152
    }
153
    
153
    
154
    // Création du corps de la requête
154
    // Création du corps de la requête
155
    
155
    
156
    // Création du SELECT général
156
    // Création du SELECT général
157
    $normal_query = "SELECT DISTINCT $add_select B_D_ID, B_D_LABEL, B_S_IDSTR, B_S_NOM, B_AS_LIBELLE, ".$tbl['item'].".*, ".$tbl['item_typlog'].".*, ".$tbl['item_typphy'].".* ";
157
    $normal_query = "SELECT DISTINCT $add_select B_D_ID, B_D_LABEL, B_S_IDSTR, B_S_NOM, B_AS_LIBELLE, ".$tbl['item'].".*, ".$tbl['item_typlog'].".*, ".$tbl['item_typphy'].".* ";
158
    
158
    
159
    // Création du FROM général
159
    // Création du FROM général
160
    $normal_query .= " FROM $add_from ".$tbl['saisie'].", ".$tbl['item'].", ".$tbl['item_typlog'].", ".$tbl['item_typphy']."$add_from_dom";
160
    $normal_query .= " FROM $add_from ".$tbl['saisie'].", ".$tbl['item'].", ".$tbl['item_typlog'].", ".$tbl['item_typphy']."$add_from_dom";
161
    
161
    
162
    // Création du WHERE
162
    // Création du WHERE
163
    $normal_query .= " WHERE $create_logphy ";
163
    $normal_query .= " WHERE $create_logphy ";
164
    $normal_query .= " AND B_I_CACHER = 0 ";
164
    $normal_query .= " AND B_I_CACHER = 0 ";
165
    
165
    
166
    if (($TabFinder['typque'] == 0)&&($TabFinder['chaine'] != "")) {
166
    if (($TabFinder['typque'] == 0)&&($TabFinder['chaine'] != "")) {
167
        // le mode de moteur demandé est : expression exacte
167
        // le mode de moteur demandé est : expression exacte
168
        $normal_query .= " AND (";
168
        $normal_query .= " AND (";
169
        // on vérifie si la chaine est entre crochets
169
        // on vérifie si la chaine est entre crochets
170
        $check_method = ereg("\[*\]",$TabFinder['chaine']);
170
        $check_method = ereg("\[*\]",$TabFinder['chaine']);
171
        if ($check_method == 1) {
171
        if ($check_method == 1) {
172
            // si oui, on utilise le FULL TEXT
172
            // si oui, on utilise le FULL TEXT
173
            $TabFinder['chaine'] = ereg_replace("\[","",$TabFinder['chaine']);
173
            $TabFinder['chaine'] = ereg_replace("\[","",$TabFinder['chaine']);
174
            $TabFinder['chaine'] = ereg_replace("\]","",$TabFinder['chaine']);
174
            $TabFinder['chaine'] = ereg_replace("\]","",$TabFinder['chaine']);
175
            
175
            
176
            $normal_query .= "MATCH(B_I_TITRE) against ('".$TabFinder['chaine']."')";
176
            $normal_query .= "MATCH(B_I_TITRE) against ('".$TabFinder['chaine']."')";
177
            $normal_query .= " OR MATCH(B_I_RESUMCLE) against ('".$TabFinder['chaine']."')";
177
            $normal_query .= " OR MATCH(B_I_RESUMCLE) against ('".$TabFinder['chaine']."')";
178
            $normal_query .= " OR ".$tbl['item'].".B_I_COMMENT like '%".$TabFinder['chaine']."%'";
178
            $normal_query .= " OR ".$tbl['item'].".B_I_COMMENT like '%".$TabFinder['chaine']."%'";
179
        } else {
179
        } else {
180
            // si non, on utilise la methode classique
180
            // si non, on utilise la methode classique
181
            $normal_query .= $tbl['item'].".B_I_TITRE like '%".$TabFinder['chaine']."%'";
181
            $normal_query .= $tbl['item'].".B_I_TITRE like '%".$TabFinder['chaine']."%'";
182
            $normal_query .= " OR ".$tbl['item'].".B_I_RESUMCLE like '%".$TabFinder['chaine']."%'";
182
            $normal_query .= " OR ".$tbl['item'].".B_I_RESUMCLE like '%".$TabFinder['chaine']."%'";
183
            $normal_query .= " OR ".$tbl['item'].".B_I_COMMENT like '%".$TabFinder['chaine']."%'";
183
            $normal_query .= " OR ".$tbl['item'].".B_I_COMMENT like '%".$TabFinder['chaine']."%'";
184
        }
184
        }
185
        $normal_query .= ")";
185
        $normal_query .= ")";
186
    } else if (($TabFinder['chaine'] != "")&&($TabFinder['typque'] == 1)) {
186
    } else if (($TabFinder['chaine'] != "")&&($TabFinder['typque'] == 1)) {
187
        // le mode du moteur demandé est : chaque terme
187
        // le mode du moteur demandé est : chaque terme
188
        
188
        
189
        $result_from_ex = explode (" ", $TabFinder['chaine']);
189
        $result_from_ex = explode (" ", $TabFinder['chaine']);
190
        
190
        
191
        if (($result_from_ex != "")&&(count($result_from_ex)>=1)) {
191
        if (($result_from_ex != "")&&(count($result_from_ex)>=1)) {
192
            $i_ex = 0;
192
            $i_ex = 0;
193
            
193
            
194
            $normal_query .= " AND (";
194
            $normal_query .= " AND (";
195
            while ($i_ex < count($result_from_ex)) {
195
            while ($i_ex < count($result_from_ex)) {
196
                // on vérifie si la chaine est entre crochets
196
                // on vérifie si la chaine est entre crochets
197
                $check_method = ereg("\[*\]",$result_from_ex[$i_ex]);
197
                $check_method = ereg("\[*\]",$result_from_ex[$i_ex]);
198
                
198
                
199
                if ($check_method == 1) {
199
                if ($check_method == 1) {
200
                    $result_from_ex[$i_ex] = ereg_replace("\[","",$result_from_ex[$i_ex]);
200
                    $result_from_ex[$i_ex] = ereg_replace("\[","",$result_from_ex[$i_ex]);
201
                    $result_from_ex[$i_ex] = ereg_replace("\]","",$result_from_ex[$i_ex]);
201
                    $result_from_ex[$i_ex] = ereg_replace("\]","",$result_from_ex[$i_ex]);
202
                    // si oui, on utilise le FULL TEXT
202
                    // si oui, on utilise le FULL TEXT
203
                    $normal_query .= "MATCH(B_I_TITRE) against ('";
203
                    $normal_query .= "MATCH(B_I_TITRE) against ('";
204
                    if ($result_from_ex[$i_ex] != "") $normal_query .= "$result_from_ex[$i_ex]";
204
                    if ($result_from_ex[$i_ex] != "") $normal_query .= "$result_from_ex[$i_ex]";
205
                    $normal_query .= "') OR ";
205
                    $normal_query .= "') OR ";
206
                    
206
                    
207
                    $normal_query .= "MATCH(B_I_RESUMCLE) against ('";
207
                    $normal_query .= "MATCH(B_I_RESUMCLE) against ('";
208
                    if ($result_from_ex[$i_ex] != "") $normal_query .= "$result_from_ex[$i_ex]";
208
                    if ($result_from_ex[$i_ex] != "") $normal_query .= "$result_from_ex[$i_ex]";
209
                    $normal_query .= "') OR ";
209
                    $normal_query .= "') OR ";
210
                    
210
                    
211
                    $normal_query .= "B_I_COMMENT like '%";
211
                    $normal_query .= "B_I_COMMENT like '%";
212
                    if ($result_from_ex[$i_ex] != "") $normal_query .= "$result_from_ex[$i_ex]";
212
                    if ($result_from_ex[$i_ex] != "") $normal_query .= "$result_from_ex[$i_ex]";
213
                    $normal_query .= "%'";
213
                    $normal_query .= "%'";
214
                    
214
                    
215
                    if ($i_ex < (count($result_from_ex)-1)) $normal_query .= ") AND (";
215
                    if ($i_ex < (count($result_from_ex)-1)) $normal_query .= ") AND (";
216
                } else {
216
                } else {
217
                    // si non, on procède à une recherche classique
217
                    // si non, on procède à une recherche classique
218
                    $normal_query .= $tbl['item'].".B_I_TITRE like '%";
218
                    $normal_query .= $tbl['item'].".B_I_TITRE like '%";
219
                    if ($result_from_ex[$i_ex] != "") $normal_query .= "$result_from_ex[$i_ex]";
219
                    if ($result_from_ex[$i_ex] != "") $normal_query .= "$result_from_ex[$i_ex]";
220
                    $normal_query .= "%' OR ";
220
                    $normal_query .= "%' OR ";
221
                    $normal_query .= $tbl['item'].".B_I_RESUMCLE like '%";
221
                    $normal_query .= $tbl['item'].".B_I_RESUMCLE like '%";
222
                    if ($result_from_ex[$i_ex] != "") $normal_query .= "$result_from_ex[$i_ex]";
222
                    if ($result_from_ex[$i_ex] != "") $normal_query .= "$result_from_ex[$i_ex]";
223
                    $normal_query .= "%' OR ";
223
                    $normal_query .= "%' OR ";
224
                    
224
                    
225
                    $normal_query .= $tbl['item'].".B_I_COMMENT like '%";
225
                    $normal_query .= $tbl['item'].".B_I_COMMENT like '%";
226
                    if ($result_from_ex[$i_ex] != "") $normal_query .= "$result_from_ex[$i_ex]";
226
                    if ($result_from_ex[$i_ex] != "") $normal_query .= "$result_from_ex[$i_ex]";
227
                    $normal_query .= "%'";          
227
                    $normal_query .= "%'";          
228
                    
228
                    
229
                    if ($i_ex < (count($result_from_ex)-1)) $normal_query .= ") AND (";
229
                    if ($i_ex < (count($result_from_ex)-1)) $normal_query .= ") AND (";
230
                }
230
                }
231
                
231
                
232
                $i_ex++;
232
                $i_ex++;
233
            }
233
            }
234
            
234
            
235
            $normal_query .= ") ";
235
            $normal_query .= ") ";
236
        }
236
        }
237
    }
237
    }
238
    
238
    
239
    /* ajout, si nécessaire, de la contrainte categ */
239
    /* ajout, si nécessaire, de la contrainte categ */
240
    
240
    
241
    if (($TabFinder['categ'] != '') && (BB_ARGUMENT_REGROUPEMENT == 'media')) {
241
    if (($TabFinder['categ'] != '') && (BB_ARGUMENT_REGROUPEMENT == 'media')) {
242
        if ($TabFinder['categ'] == 'VIDE') {
242
        if ($TabFinder['categ'] == 'VIDE') {
243
            $normal_query .= ' AND (B_M_EDITEUR is null OR B_M_EDITEUR = "")';
243
            $normal_query .= ' AND (B_M_EDITEUR is null OR B_M_EDITEUR = "")';
244
        } else {
244
        } else {
245
            $normal_query .= ' AND (B_M_EDITEUR like "%'.$TabFinder['categ'].'%")';
245
            $normal_query .= ' AND (B_M_EDITEUR like "%'.$TabFinder['categ'].'%")';
246
        }
246
        }
247
    }
247
    }
248
    
248
    
249
    // Création des jointures
249
    // Création des jointures
250
    $normal_query .= " AND (".$tbl['saisie'].".B_AS_ID = ".$tbl['item'].".B_I_AUTEURSAISIE)"; // lien article -- type phy
250
    $normal_query .= " AND (".$tbl['saisie'].".B_AS_ID = ".$tbl['item'].".B_I_AUTEURSAISIE)"; // lien article -- type phy
251
    $normal_query .= " AND (".$tbl['item'].".B_I_TYPPHY = ".$tbl['item_typphy'].".B_IP_ID)"; // lien article -- type phy
251
    $normal_query .= " AND (".$tbl['item'].".B_I_TYPPHY = ".$tbl['item_typphy'].".B_IP_ID)"; // lien article -- type phy
252
    $normal_query .= " AND (".$tbl['item'].".B_I_TYPLOG = ".$tbl['item_typlog'].".B_IL_ID)"; // lien article -- type log
252
    $normal_query .= " AND (".$tbl['item'].".B_I_TYPLOG = ".$tbl['item_typlog'].".B_IL_ID)"; // lien article -- type log
253
    $normal_query .= " $add_limit_dom"; // si limitation au domaine principal
253
    $normal_query .= " $add_limit_dom"; // si limitation au domaine principal
254
    
254
    
255
    $normal_query.= $special_join; 
255
    $normal_query.= $special_join; 
256
    
256
    
257
    // Si TabFinder['auteur'] est non vide : on ajoute le critère de sélection 
257
    // Si TabFinder['auteur'] est non vide : on ajoute le critère de sélection 
258
    
258
    
259
    if ($TabFinder['auteur'] != '') {
259
    if ($TabFinder['auteur'] != '') {
260
        $tmp_auteur = explode(' ', $TabFinder['auteur']);
260
        $tmp_auteur = explode(' ', $TabFinder['auteur']);
261
        
261
        
262
        $normal_query .= ' AND (';
262
        $normal_query .= ' AND (';
263
        
263
        
264
        for ($tmp=0;$tmp<count($tmp_auteur);$tmp++) {
264
        for ($tmp=0;$tmp<count($tmp_auteur);$tmp++) {
265
            $normal_query .= $tbl['item'].'.B_I_AUTEURS like "%'.$tmp_auteur[$tmp].'%"';
265
            $normal_query .= $tbl['item'].'.B_I_AUTEURS like "%'.$tmp_auteur[$tmp].'%"';
266
            if ( $tmp < (count($tmp_auteur) - 1) ) {
266
            if ( $tmp < (count($tmp_auteur) - 1) ) {
267
                $normal_query .= ' AND ';
267
                $normal_query .= ' AND ';
268
            }
268
            }
269
        }
269
        }
270
        $normal_query .= ')';
270
        $normal_query .= ')';
271
    }
271
    }
272
    
272
    
273
    // Si TabFinder['geo'] est non vide :
273
    // Si TabFinder['geo'] est non vide :
274
    // 1- si TabFinder['chaine'] est vide on n'ajoute pas de AND
274
    // 1- si TabFinder['chaine'] est vide on n'ajoute pas de AND
275
    // 2- s'il n'est pas vide on ajoute AND
275
    // 2- s'il n'est pas vide on ajoute AND
276
    
276
    
277
    if ($TabFinder['geo'] != '') {
277
    if ($TabFinder['geo'] != '') {
278
        if ($TabFinder['geo'] == '1' || $TabFinder['geo'] == '2' || $TabFinder['geo'] == '3' || $TabFinder['geo'] == '4' 
278
        if ($TabFinder['geo'] == '1' || $TabFinder['geo'] == '2' || $TabFinder['geo'] == '3' || $TabFinder['geo'] == '4' 
279
            || $TabFinder['geo'] == '5' || $TabFinder['geo'] == '6' || $TabFinder['geo'] == '7' || $TabFinder['geo'] == '8' || $TabFinder['geo'] == '9' ) {
279
            || $TabFinder['geo'] == '5' || $TabFinder['geo'] == '6' || $TabFinder['geo'] == '7' || $TabFinder['geo'] == '8' || $TabFinder['geo'] == '9' ) {
280
            $TabFinder['geo'] = '0'.$TabFinder['geo'];
280
            $TabFinder['geo'] = '0'.$TabFinder['geo'];
281
            $TabFinder['geo'] = ereg_replace('00', '0', $TabFinder['geo']);
281
            $TabFinder['geo'] = ereg_replace('00', '0', $TabFinder['geo']);
282
        }
282
        }
283
        
283
        
284
        $normal_query .= " AND (".$tbl['item'].".B_I_GEO like '%".$TabFinder['geo']."%' ";
284
        $normal_query .= " AND (".$tbl['item'].".B_I_GEO like '%".$TabFinder['geo']."%' ";
285
        
285
        
286
        /* ajout de la jointure dpt */
286
        /* ajout de la jointure dpt */
287
        
287
        
288
        $comp_geo = "select * from ".$tbl['dpt']." where GFD_NAME like '%".$TabFinder['geo']."%'";
288
        $comp_geo = "select * from ".$tbl['dpt']." where GFD_NAME like '%".$TabFinder['geo']."%'";
289
        $comp_do = mysql_query($comp_geo) or die("<B>Erreur de requete GEO :</B> $comp_geo.");
289
        $comp_do = mysql_query($comp_geo) or die("<B>Erreur de requete GEO :</B> $comp_geo.");
290
        $comp_num = mysql_num_rows($comp_do);
290
        $comp_num = mysql_num_rows($comp_do);
291
        
291
        
292
        if ($comp_num > 0) {
292
        if ($comp_num > 0) {
293
            $i = 1;
293
            $i = 1;
294
            
294
            
295
            while ($row = mysql_fetch_object($comp_do)) {
295
            while ($row = mysql_fetch_object($comp_do)) {
296
                $tmp_stock = $row->GFD_ID;
296
                $tmp_stock = $row->GFD_ID;
297
                
297
                
298
                if ($tmp_stock != '') {
298
                if ($tmp_stock != '') {
299
                    if ($tmp_stock == '1' || $tmp_stock == '2' || $tmp_stock == '3' || $tmp_stock == '4' ||
299
                    if ($tmp_stock == '1' || $tmp_stock == '2' || $tmp_stock == '3' || $tmp_stock == '4' ||
300
                        $tmp_stock == '5' || $tmp_stock == '6' || $tmp_stock == '7' || $tmp_stock == '8' || $tmp_stock == '9' ) {
300
                        $tmp_stock == '5' || $tmp_stock == '6' || $tmp_stock == '7' || $tmp_stock == '8' || $tmp_stock == '9' ) {
301
                        $tmp_stock = '0'.$tmp_stock;
301
                        $tmp_stock = '0'.$tmp_stock;
302
                        $tmp_stock = ereg_replace('00', '0', $tmp_stock);
302
                        $tmp_stock = ereg_replace('00', '0', $tmp_stock);
303
                    }
303
                    }
304
                    
304
                    
305
                    if ($i == 1) {
305
                    if ($i == 1) {
306
                        $normal_query .= ' OR (';
306
                        $normal_query .= ' OR (';
307
                    }
307
                    }
308
                    $normal_query .= $tbl['item'].'.B_I_GEO like "%'.$tmp_stock.'%"';
308
                    $normal_query .= $tbl['item'].'.B_I_GEO like "%'.$tmp_stock.'%"';
309
                    if ($i < $comp_num) {
309
                    if ($i < $comp_num) {
310
                        $normal_query .= ' OR ';
310
                        $normal_query .= ' OR ';
311
                    }
311
                    }
312
                    if ($i == $comp_num) {
312
                    if ($i == $comp_num) {
313
                        $normal_query .= ') ';
313
                        $normal_query .= ') ';
314
                    }
314
                    }
315
                    $i++;
315
                    $i++;
316
                }
316
                }
317
            }
317
            }
318
        }
318
        }
319
        mysql_free_result($comp_do);
319
        mysql_free_result($comp_do);
320
        $normal_query .= ') ';
320
        $normal_query .= ') ';
321
    }
321
    }
322
    
322
    
323
    // traitement du réducteur SINCE (fonction de la date)
323
    // traitement du réducteur SINCE (fonction de la date)
324
    
324
    
325
    if ($TabFinder['since'] != '') {
325
    if ($TabFinder['since'] != '') {
326
        $since_var = explode('/', $TabFinder['since']);
326
        $since_var = explode('/', $TabFinder['since']);
327
        
327
        
328
        if (empty($since_var[0])) {
328
        if (empty($since_var[0])) {
329
            $since_var[0] = '';
329
            $since_var[0] = '';
330
        }
330
        }
331
        if (empty($since_var[1])) {
331
        if (empty($since_var[1])) {
332
            $since_var[1] = '';
332
            $since_var[1] = '';
333
        }
333
        }
334
        if (empty($since_var[2])) {
334
        if (empty($since_var[2])) {
335
            $since_var[2] = '';
335
            $since_var[2] = '';
336
        }
336
        }
337
        
337
        
338
        $timestamp = mktime (NULL,NULL,NULL,$since_var[1],$since_var[0],$since_var[2]);
338
        $timestamp = mktime (NULL,NULL,NULL,$since_var[1],$since_var[0],$since_var[2]);
339
        
339
        
340
        $normal_query .= ' AND B_I_MAJFICHE > '.$timestamp;
340
        $normal_query .= ' AND B_I_MAJFICHE > '.$timestamp;
341
    }
341
    }
342
    
342
    
343
    // Création de l'ordre de tri
343
    // Création de l'ordre de tri
344
    $order_query = " ORDER BY ".$TabFinder['sort'];
344
    $order_query = " ORDER BY ".$TabFinder['sort'];
345
    
345
    
346
    // Affectation de la requête à la variable qui va l'envoyer au moteur
346
    // Affectation de la requête à la variable qui va l'envoyer au moteur
347
    if (empty($plugin_store['query_add_query'])) {
347
    if (empty($plugin_store['query_add_query'])) {
348
        $plugin_store['query_add_query'] = '';
348
        $plugin_store['query_add_query'] = '';
349
    }
349
    }
350
    
350
    
351
    $unreq = $normal_query.' '.$add_to_query.' '.$plugin_store['query_add_query'].' '.$order_query;
351
    $unreq = $normal_query.' '.$add_to_query.' '.$plugin_store['query_add_query'].' '.$order_query;
352
    
352
    
-
 
353
    // Débogage de la requête
353
    //echo "$unreq";
354
    //trigger_error($unreq, E_USER_WARNING);
354
    
355
    
355
    return $unreq;
356
    return $unreq;
356
}
357
}
357
 
358
 
358
/* +--Fin du code ----------------------------------------------------------------------------------------+
359
/* +--Fin du code ----------------------------------------------------------------------------------------+
359
*
-
 
360
* $Log: not supported by cvs2svn $
-
 
361
* Revision 1.4  2005/05/17 10:10:08  jpm
-
 
362
* Correction des bogues avant mise en ligne du site v4.
360
*
363
*
361
* $Log: bbc_requete_media.fonct.php,v $
364
* Revision 1.3  2004/09/15 10:32:30  jpm
362
* Revision 1.3  2004/09/15 10:32:30  jpm
365
* Suppression d'une ligne après la balise de fermeture php.
363
* Suppression d'une ligne après la balise de fermeture php.
366
*
364
*
367
* Revision 1.2  2004/09/14 10:18:17  jpm
365
* Revision 1.2  2004/09/14 10:18:17  jpm
368
* Mise en forme et amélioration du code.
366
* Mise en forme et amélioration du code.
369
* Passage au XHTML strict.
367
* Passage au XHTML strict.
370
*
368
*
-
 
369
* Revision 1.1  2004/09/10 18:44:02  jpm
371
* Revision 1.1  2004/09/10 18:44:02  jpm
370
* Ajout des fichiers de gestion du moteur de recherche des médias.
372
* Ajout des fichiers de gestion du moteur de recherche des médias.
-
 
373
*
371
*
374
*
372
*
375
* +-- Fin du code ----------------------------------------------------------------------------------------+
373
* +-- Fin du code ----------------------------------------------------------------------------------------+
376
*/
374
*/
377
?>
375
?>