2 |
jp_milcent |
1 |
<?php
|
|
|
2 |
/*vim: set expandtab tabstop=4 shiftwidth=4: */
|
|
|
3 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
4 |
// | PHP version 4.1 |
|
|
|
5 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
6 |
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org) |
|
|
|
7 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
8 |
// | This library is free software; you can redistribute it and/or |
|
|
|
9 |
// | modify it under the terms of the GNU Lesser General Public |
|
|
|
10 |
// | License as published by the Free Software Foundation; either |
|
|
|
11 |
// | version 2.1 of the License, or (at your option) any later version. |
|
|
|
12 |
// | |
|
|
|
13 |
// | This library is distributed in the hope that it will be useful, |
|
|
|
14 |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
15 |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
|
|
16 |
// | Lesser General Public License for more details. |
|
|
|
17 |
// | |
|
|
|
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 |
|
|
|
20 |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
|
|
21 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
22 |
// CVS : $Id: bbc_requete_lien.fonct.php,v 1.1 2005-11-23 10:22:25 jp_milcent Exp $
|
|
|
23 |
/**
|
|
|
24 |
* Fonctions de création de la requête sur un lien.
|
|
|
25 |
*
|
|
|
26 |
* Contient une fonction créant la requête d'intérogation de la base de données.
|
|
|
27 |
* Valable pour le paramètre "lien".
|
|
|
28 |
*
|
|
|
29 |
*@package BiblioBota-Consultation
|
|
|
30 |
*@subpackage Fonctions
|
|
|
31 |
//Auteur original :
|
|
|
32 |
*@author Jean-Charles GRANGER <tela@vecteur.org>
|
|
|
33 |
//Autres auteurs :
|
|
|
34 |
*@author Jean-Pascal MILCENT <jpm@clapas.org>
|
|
|
35 |
*@copyright Tela-Botanica 2000-2004
|
|
|
36 |
*@version $Revision: 1.1 $ $Date: 2005-11-23 10:22:25 $
|
|
|
37 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
38 |
*/
|
|
|
39 |
|
|
|
40 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
41 |
// | ENTETE du PROGRAMME |
|
|
|
42 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
43 |
/*Mettre ici les inclusions de fichiers*/
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
47 |
// | LISTE de FONCTIONS |
|
|
|
48 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
49 |
/*Mettre ici la liste de fonctions.*/
|
|
|
50 |
|
|
|
51 |
function mkquery()
|
|
|
52 |
{
|
|
|
53 |
global $TabFinder, $tbl;
|
|
|
54 |
|
|
|
55 |
// Initialisation
|
|
|
56 |
$order_query = '';
|
|
|
57 |
|
|
|
58 |
// Si la variable de catégorie vaut 0, il n'y a pas affinage de la requête par catégorie. Sinon, on affine.
|
|
|
59 |
|
|
|
60 |
if ($TabFinder['categ'] != 0) {
|
|
|
61 |
$add_to_from = $tbl['cat'].', '.$tbl['categlien'].', ';
|
|
|
62 |
$add_to_query = ' AND ('.$tbl['cat'].'.B_CAT_IDCAT = '.$TabFinder['categ'].')';
|
|
|
63 |
|
|
|
64 |
if ($TabFinder['chaine'] != '') {
|
|
|
65 |
$join_categ = ' AND ';
|
|
|
66 |
} else {
|
|
|
67 |
$join_categ = '';
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
$join_categ .= ' AND ('.$tbl['link'].'.B_L_IDLINK = '.$tbl['categlien'].'.B_LC_IDLINK) AND ('.$tbl['cat'].'.B_CAT_IDCAT = '.$tbl['categlien'].'.B_LC_IDCAT)';
|
|
|
71 |
} else {
|
|
|
72 |
$add_to_from = '';
|
|
|
73 |
$add_to_query = '';
|
|
|
74 |
$join_categ = '';
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
// Création du SELECT
|
|
|
78 |
$normal_query = 'SELECT '.$tbl['link'].'.*, '.$tbl['str'].'.B_S_NOM ';
|
|
|
79 |
// si le raffinement de catégorie vaut autre chose que 0, il faut ajouter les tables de catégories
|
|
|
80 |
if ($TabFinder['categ'] != 0) {
|
|
|
81 |
$normal_query .= ', '.$tbl['categlien'].'.*, '.$tbl['cat'].'.B_CAT_LABEL, '.$tbl['cat'].'.B_CAT_IDCAT ';
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
// Création du FROM
|
|
|
85 |
$normal_query .= 'FROM '.$add_to_from.$tbl['link'].' LEFT JOIN '.$tbl['str'].' ON '.$tbl['link'].'.B_L_LKSTR = '.$tbl['str'].'.B_S_IDSTR ';
|
|
|
86 |
|
|
|
87 |
// Création du WHERE
|
|
|
88 |
$normal_query .= 'WHERE B_L_CACHER = 0 ';
|
|
|
89 |
|
|
|
90 |
if (($TabFinder['typque'] == 0) && ($TabFinder['chaine'] != '')) {
|
|
|
91 |
$normal_query .= ' AND (';
|
|
|
92 |
$normal_query .= $tbl['link'].'.B_L_TITRE like "%'.$TabFinder['chaine'].'%" '.
|
|
|
93 |
'OR '.$tbl['link'].'.B_L_URL like "%'.$TabFinder['chaine'].'%" '.
|
|
|
94 |
'OR '.$tbl['link'].'.B_L_RESUMCLE like "%'.$TabFinder['chaine'].'%" ';
|
|
|
95 |
$normal_query .= ') ';
|
|
|
96 |
} else if ($TabFinder['chaine'] != '') {
|
|
|
97 |
$normal_query .= ' AND (';
|
|
|
98 |
|
|
|
99 |
// Si la variable de type de recherche vaut 1, il faut que le moteur recherche chaque motif
|
|
|
100 |
|
|
|
101 |
if ($TabFinder['typque'] == 1) {
|
|
|
102 |
$result_from_ex = explode (' ', $TabFinder['chaine']);
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
$i_ex = 0;
|
|
|
106 |
|
|
|
107 |
while ($i_ex < count($result_from_ex)) {
|
|
|
108 |
$normal_query .= $tbl['link'].'.B_L_TITRE LIKE "%';
|
|
|
109 |
if ($result_from_ex[$i_ex] != '') {
|
|
|
110 |
$normal_query .= $result_from_ex[$i_ex];
|
|
|
111 |
}
|
|
|
112 |
$normal_query .= '%" OR ';
|
|
|
113 |
|
|
|
114 |
$normal_query .= $tbl['link'].'.B_L_URL LIKE "%';
|
|
|
115 |
if ($result_from_ex[$i_ex] != '') {
|
|
|
116 |
$normal_query .= $result_from_ex[$i_ex];
|
|
|
117 |
}
|
|
|
118 |
$normal_query .= '%" OR ';
|
|
|
119 |
|
|
|
120 |
$normal_query .= $tbl['link'].'.B_L_RESUMCLE LIKE "%';
|
|
|
121 |
if ($result_from_ex[$i_ex] != '') {
|
|
|
122 |
$normal_query .= $result_from_ex[$i_ex];
|
|
|
123 |
}
|
|
|
124 |
$normal_query .= '%"';
|
|
|
125 |
|
|
|
126 |
if ($i_ex < (count($result_from_ex) - 1)) {
|
|
|
127 |
$normal_query .= ') AND (';
|
|
|
128 |
}
|
|
|
129 |
$i_ex++;
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
$normal_query .= ')';
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
// traitement du réducteur SINCE (fonction de la date)
|
|
|
136 |
|
|
|
137 |
if ($TabFinder['since'] != '') {
|
|
|
138 |
$since_var = explode('/', $TabFinder['since']);
|
|
|
139 |
|
|
|
140 |
if (empty($since_var[0])) {
|
|
|
141 |
$since_var[0] = '';
|
|
|
142 |
}
|
|
|
143 |
if (empty($since_var[1])) {
|
|
|
144 |
$since_var[1] = '';
|
|
|
145 |
}
|
|
|
146 |
if (empty($since_var[2])) {
|
|
|
147 |
$since_var[2] = '';
|
|
|
148 |
}
|
|
|
149 |
$timestamp = mktime(NULL, NULL, NULL, $since_var[1], $since_var[0], $since_var[2]);
|
|
|
150 |
|
|
|
151 |
if (!ereg('WHERE', $normal_query)) {
|
|
|
152 |
$normal_query .= ' WHERE ';
|
|
|
153 |
} else {
|
|
|
154 |
$normal_query .= ' AND ';
|
|
|
155 |
}
|
|
|
156 |
$normal_query .= 'B_L_MAJFICHE > '.$timestamp;
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
// Création de l'ordre de tri
|
|
|
160 |
$order_query = ' ORDER BY '.$TabFinder['sort'];
|
|
|
161 |
|
|
|
162 |
// Affectation de la requête à la variable qui va l'envoyer au moteur
|
|
|
163 |
|
|
|
164 |
$unreq = $normal_query.' '.$join_categ.' '.$add_to_query.' '.$order_query;
|
|
|
165 |
return $unreq;
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
/* +--Fin du code ----------------------------------------------------------------------------------------+
|
|
|
169 |
*
|
|
|
170 |
* $Log: not supported by cvs2svn $
|
|
|
171 |
* Revision 1.4 2005/06/20 17:32:14 jpm
|
|
|
172 |
* Correction erreur de construction de la requête sql.
|
|
|
173 |
*
|
|
|
174 |
* Revision 1.3 2005/05/17 10:10:08 jpm
|
|
|
175 |
* Correction des bogues avant mise en ligne du site v4.
|
|
|
176 |
*
|
|
|
177 |
* Revision 1.2 2004/09/14 11:49:52 jpm
|
|
|
178 |
* Ajout de l'entête au fichier.
|
|
|
179 |
*
|
|
|
180 |
*
|
|
|
181 |
* +-- Fin du code ----------------------------------------------------------------------------------------+
|
|
|
182 |
*/
|
|
|
183 |
?>
|