1 |
nhaye |
2483 |
<?php |
2 |
|
|
/** |
3 |
|
|
* |
4 |
|
|
* |
5 |
|
|
* @package openmairie_exemple |
6 |
|
|
* @version SVN : $Id: requeteur.php 2229 2013-04-03 09:10:11Z jbastide $ |
7 |
|
|
*/ |
8 |
|
|
|
9 |
|
|
require_once "../obj/utils.class.php"; |
10 |
|
|
$f = new utils("nohtml", "reqmo"); |
11 |
|
|
|
12 |
|
|
/** |
13 |
|
|
* |
14 |
|
|
*/ |
15 |
|
|
// Nom de l'objet metier |
16 |
|
|
(isset($_GET['obj']) ? $obj = $_GET['obj'] : $obj = ""); |
17 |
|
|
|
18 |
|
|
/** |
19 |
|
|
* |
20 |
|
|
* Requêteur |
21 |
|
|
* principe de REQMO (requete memorisée): |
22 |
|
|
* permet de faire des requetes memorisees |
23 |
|
|
* la requete est parametree en sql/typedebase/langue/obj.reqmo.inc.php |
24 |
|
|
* $reqmo['sql'] = requete parametrable |
25 |
|
|
* les parametres sont entre crochets |
26 |
|
|
* type de parametre = $reqmo['parametre'] |
27 |
|
|
* checked : case à cocher pour que la zone soit prise en compte |
28 |
|
|
* liste : liste de valeur proposé pour parametrer une selection ou un tri |
29 |
|
|
* select : liste de valeur proposé pour parametrer une selection ou un tri d apres une requete dans une table |
30 |
|
|
* $reqmo['libelle'] = libelle de la requete |
31 |
|
|
* $reqmo['separateur'] = separateur pour fichier csv |
32 |
|
|
*/ |
33 |
|
|
|
34 |
|
|
/** |
35 |
|
|
* Fichiers requis |
36 |
|
|
*/ |
37 |
|
|
if (file_exists ("../dyn/var.inc")) |
38 |
|
|
include ("../dyn/var.inc"); |
39 |
|
|
|
40 |
|
|
/** |
41 |
|
|
* Paramètres |
42 |
|
|
*/ |
43 |
|
|
set_time_limit(180); |
44 |
|
|
$DEBUG=0; |
45 |
|
|
$aff = "requeteur"; |
46 |
|
|
$validation = 0; |
47 |
|
|
if (isset ($_GET['validation'])) |
48 |
|
|
$validation = $_GET['validation']; |
49 |
|
|
$idx = ""; |
50 |
|
|
if (isset($_GET['idx'])) |
51 |
|
|
$idx = $_GET['idx']; |
52 |
|
|
$ent = "reqmo"."->".$obj; |
53 |
|
|
$ico = "ico_aide.png"; |
54 |
|
|
// |
55 |
|
|
$f->setTitle(_("Requetes memorisees")." -> "._($obj)); |
56 |
|
|
$f->setFlag(NULL); |
57 |
|
|
$f->display(); |
58 |
|
|
|
59 |
|
|
if (file_exists ("../sql/".$f -> phptype."/".$obj.".reqmo.inc.php")) { |
60 |
|
|
include ("../sql/".$f -> phptype."/".$obj.".reqmo.inc.php"); |
61 |
|
|
} |
62 |
|
|
elseif (file_exists ("../sql/".$f -> phptype."/".$obj.".reqmo.inc")) { |
63 |
|
|
include ("../sql/".$f -> phptype."/".$obj.".reqmo.inc"); |
64 |
|
|
} |
65 |
|
|
if (isset ($_GET ['step'])) |
66 |
|
|
$step = $_GET ['step']; |
67 |
|
|
else |
68 |
|
|
$step = 0; |
69 |
|
|
|
70 |
|
|
/** |
71 |
|
|
* Ouverture du conteneur de la page |
72 |
|
|
*/ |
73 |
|
|
// |
74 |
|
|
echo "\n<div id=\"generator-generate\">\n"; |
75 |
|
|
// |
76 |
|
|
echo "<div id=\"formulaire\">\n\n"; |
77 |
|
|
// |
78 |
|
|
$f->layout->display_start_navbar(); |
79 |
|
|
echo "<ul>\n"; |
80 |
|
|
if (isset($reqmo["reqmo_libelle"])) { |
81 |
|
|
echo "\t<li><a href=\"#tabs-1\">"._("Export de : ")._($reqmo["reqmo_libelle"])."</a></li>\n"; |
82 |
|
|
} elseif (isset($reqmo["libelle"])) { |
83 |
|
|
echo "\t<li><a href=\"#tabs-1\">"._("Export de : ")._($reqmo["libelle"])."</a></li>\n"; |
84 |
|
|
} else { |
85 |
|
|
echo "\t<li><a href=\"#tabs-1\">"._("Export de : ")._($obj)."</a></li>\n"; |
86 |
|
|
} |
87 |
|
|
echo "</ul>\n"; |
88 |
|
|
// |
89 |
|
|
$f->layout->display_stop_navbar(); |
90 |
|
|
echo "\n<div id=\"tabs-1\">\n"; |
91 |
|
|
|
92 |
|
|
/** |
93 |
|
|
* |
94 |
|
|
*/ |
95 |
|
|
if ($step == 0) { |
96 |
|
|
|
97 |
|
|
// |
98 |
|
|
$validation = 1; |
99 |
|
|
$cptemp = 0; |
100 |
|
|
$cpts=0; |
101 |
|
|
$cptsel=0; |
102 |
|
|
|
103 |
|
|
/** |
104 |
|
|
* Ouverture du formulaire |
105 |
|
|
*/ |
106 |
|
|
// Ouverture de la balise formulaire |
107 |
|
|
echo "<form method=\"post\" action=\"requeteur.php?obj=".$obj."&step=1\" name=\"f1\">\n"; |
108 |
|
|
$param["obj"]=$obj; |
109 |
|
|
$param["phptype"]= $f -> phptype; |
110 |
|
|
$param["db"]= $f -> db; |
111 |
|
|
$param["validation"]=$validation; |
112 |
|
|
$param["cptemp"]= $cptemp; |
113 |
|
|
$param["cpts"]=$cpts; |
114 |
|
|
$param["cptsel"]=$cptsel; |
115 |
|
|
$f->layout->display_requeteur_formulaire($param,$f); |
116 |
|
|
// |
117 |
|
|
// Affichage des actions de controles du formulaire |
118 |
|
|
echo "<div class=\"formControls\">"; |
119 |
|
|
// Bouton de validation du formulaire |
120 |
|
|
$param["input"]="<input type=\"submit\" name=\"valid.reqmo\" value=\""._("Executer la requete sur :")." '"._($obj)."'\" />"; |
121 |
|
|
$f->layout->display_input($param); |
122 |
|
|
// Lien retour |
123 |
|
|
$param["lien"]="<a href=\"reqmo.php\" class=\"retour\">"._("Retour")."</a>"; |
124 |
|
|
$f->layout->display_lien_retour($param); |
125 |
|
|
// Fermeture du conteneur des actions de controles du formulaire |
126 |
|
|
echo "</div>"; |
127 |
|
|
// Fermeture de la balise formulaire |
128 |
|
|
echo "\n</form>\n"; |
129 |
|
|
|
130 |
|
|
} else { // On affiche le csv ou le tableau |
131 |
|
|
$temp = explode ("[",$reqmo["sql"]); |
132 |
|
|
for($i = 1; $i < sizeof ($temp); $i++) |
133 |
|
|
{ |
134 |
|
|
$temp1 = explode ("]", $temp [$i]); |
135 |
|
|
$temp4 = explode (" as ", $temp1 [0]); |
136 |
|
|
if (isset ($temp4 [1])) |
137 |
|
|
$temp5 = $temp4 [1]; // uniquement as |
138 |
|
|
else |
139 |
|
|
$temp5 = $temp1 [0]; // en entier |
140 |
|
|
if (isset ($_POST [$temp5])) |
141 |
|
|
$temp2 = $_POST [$temp5]; |
142 |
|
|
else |
143 |
|
|
$temp2 = ""; |
144 |
|
|
// **** |
145 |
|
|
if(isset($reqmo[$temp5])){ |
146 |
|
|
if($reqmo[$temp5]=="checked") |
147 |
|
|
{ |
148 |
|
|
if ($temp2 == 'Oui') |
149 |
|
|
{ |
150 |
|
|
$reqmo ['sql'] = str_replace ("[".$temp1[0]."]",$temp1[0],$reqmo['sql']); |
151 |
|
|
} |
152 |
|
|
else |
153 |
|
|
{ |
154 |
|
|
$reqmo['sql']=str_replace("[".$temp1[0]."],",'',$reqmo['sql']); |
155 |
|
|
$reqmo['sql']=str_replace(",[".$temp1[0]."]",'',$reqmo['sql']); |
156 |
|
|
$reqmo['sql']=str_replace(", [".$temp1[0]."]",'',$reqmo['sql']); |
157 |
|
|
$reqmo['sql']=str_replace("[".$temp1[0]."]",'',$reqmo['sql']); |
158 |
|
|
} |
159 |
|
|
} |
160 |
|
|
else |
161 |
|
|
{ |
162 |
|
|
$reqmo['sql']=str_replace("[".$temp1[0]."]",$temp2,$reqmo['sql']); |
163 |
|
|
} |
164 |
|
|
//**** |
165 |
|
|
}else |
166 |
|
|
{ |
167 |
|
|
$reqmo['sql']=str_replace("[".$temp1[0]."]",$temp2,$reqmo['sql']); |
168 |
|
|
}//**** |
169 |
|
|
$temp1[0]=""; |
170 |
|
|
} |
171 |
|
|
|
172 |
|
|
$blanc = 0; |
173 |
|
|
$temp = ""; |
174 |
|
|
for($i=0;$i<strlen($reqmo['sql']);$i++) |
175 |
|
|
{ |
176 |
|
|
if (substr($reqmo['sql'],$i,1)==chr(13) or substr($reqmo['sql'],$i,1)==chr(10) or substr($reqmo['sql'],$i,1)==chr(32)) |
177 |
|
|
{ |
178 |
|
|
if ($blanc==0) |
179 |
|
|
$temp=$temp.chr(32); |
180 |
|
|
$blanc=1; |
181 |
|
|
} |
182 |
|
|
else |
183 |
|
|
{ |
184 |
|
|
$temp=$temp.substr($reqmo['sql'],$i,1); |
185 |
|
|
$blanc=0; |
186 |
|
|
} |
187 |
|
|
} |
188 |
|
|
$reqmo['sql']=$temp ; |
189 |
|
|
$reqmo['sql']=str_replace(',,',',',$reqmo['sql']); |
190 |
|
|
$reqmo['sql']=str_replace(', ,',',',$reqmo['sql']); |
191 |
|
|
$reqmo['sql']=str_replace(', from',' from',$reqmo['sql']); |
192 |
|
|
$reqmo['sql']=str_replace('select ,','select ',$reqmo['sql']); |
193 |
|
|
// post limite |
194 |
|
|
if (isset($_POST['limite'])) |
195 |
|
|
$limite = $_POST['limite']; |
196 |
|
|
else |
197 |
|
|
$limite = 100; |
198 |
|
|
// post sortie |
199 |
|
|
if (isset ($_POST['sortie'])) |
200 |
|
|
$sortie= $_POST['sortie']; |
201 |
|
|
else |
202 |
|
|
$sortie ='tableau'; |
203 |
|
|
// post separateur de champ (csv) |
204 |
|
|
if (isset ($_POST['separateur'])) |
205 |
|
|
$separateur= $_POST['separateur']; |
206 |
|
|
else |
207 |
|
|
$separateur =';'; |
208 |
|
|
// limite uniquement pour tableau |
209 |
|
|
if ($sortie =='tableau') |
210 |
|
|
$reqmo['sql']= $reqmo['sql']." limit ".$limite; |
211 |
|
|
// execution de la requete |
212 |
|
|
$res = $f -> db -> query ($reqmo['sql']); |
213 |
|
|
$f->isDatabaseError($res); |
214 |
|
|
|
215 |
|
|
$info = $res -> tableInfo (); |
216 |
|
|
if ($sortie =='tableau') { |
217 |
|
|
// |
218 |
|
|
echo " "; |
219 |
|
|
$param['class']="tab"; |
220 |
|
|
$param['idcolumntoggle']="requeteur"; |
221 |
|
|
$f->layout->display_table_start($param); |
222 |
|
|
//echo "<table class=\"tab-tab\">\n"; |
223 |
|
|
// |
224 |
|
|
echo "<thead><tr class=\"ui-tabs-nav ui-accordion ui-state-default tab-title\">"; |
225 |
|
|
$key=0; |
226 |
|
|
foreach($info as $elem) { |
227 |
|
|
$param = array( |
228 |
|
|
"key" => $key, |
229 |
|
|
"info" => $info |
230 |
|
|
); |
231 |
|
|
$f->layout->display_table_cellule_entete_colonnes($param); |
232 |
|
|
echo "<center>"._($elem['name'])."</center></th>"; |
233 |
|
|
$key=$key+1; |
234 |
|
|
} |
235 |
|
|
echo "</tr></thead>\n"; |
236 |
|
|
// |
237 |
|
|
$cptenr = 0; |
238 |
|
|
while ($row=& $res->fetchRow()) { |
239 |
|
|
// |
240 |
|
|
echo "<tr class=\"tab-data ".($cptenr % 2 == 0 ? "odd" : "even")."\">\n"; |
241 |
|
|
// |
242 |
|
|
$cptenr = $cptenr + 1; |
243 |
|
|
$i = 0; |
244 |
|
|
foreach ($row as $elem) { |
245 |
|
|
if (is_numeric($elem)) |
246 |
|
|
echo "<td class='resultrequete' align='right'>"; |
247 |
|
|
else |
248 |
|
|
echo "<td class='resultrequete'>"; |
249 |
|
|
$tmp=""; |
250 |
|
|
$tmp=str_replace(chr(13).chr(10),'<br>', $elem); |
251 |
|
|
echo $tmp."</td>"; |
252 |
|
|
$i++; |
253 |
|
|
} |
254 |
|
|
echo "</tr>\n"; |
255 |
|
|
} |
256 |
|
|
// |
257 |
|
|
echo "</tbody></table>\n"; |
258 |
|
|
if ($cptenr==0){ |
259 |
|
|
echo "<br>"._('aucun')." "._('enregistrement')."<br>"; |
260 |
|
|
} |
261 |
|
|
} |
262 |
|
|
else |
263 |
|
|
{ |
264 |
|
|
$inf=""; |
265 |
|
|
foreach ($info as $elem) |
266 |
|
|
{ |
267 |
|
|
//echo $elem['name'].$separateur; |
268 |
|
|
$inf=$inf.$elem['name'].$separateur; |
269 |
|
|
} |
270 |
|
|
//echo "<br />"; |
271 |
|
|
$inf .= "\n"; |
272 |
|
|
$cptenr=0; |
273 |
|
|
while ($row=& $res->fetchRow()) |
274 |
|
|
{ |
275 |
|
|
$cptenr=$cptenr+1; |
276 |
|
|
$i=0; |
277 |
|
|
foreach($row as $elem) |
278 |
|
|
{ |
279 |
|
|
//echo $elem.$separateur; |
280 |
|
|
//**** |
281 |
|
|
$tmp=""; |
282 |
|
|
$tmp=str_replace(chr(13).chr(10),' / ', $elem); |
283 |
|
|
$tmp=str_replace(';',' ', $tmp); |
284 |
|
|
//***** |
285 |
|
|
$inf .= $tmp.$separateur; |
286 |
|
|
$i++; |
287 |
|
|
} |
288 |
|
|
//echo "<br />"; |
289 |
|
|
$inf .= "\n"; |
290 |
|
|
} |
291 |
|
|
if ($cptenr==0){ |
292 |
|
|
$inf .="\n"._('aucun')." "._('enregistrement')."\n"; |
293 |
|
|
} |
294 |
|
|
$nom_fichier="export_".$obj.".csv"; |
295 |
|
|
$fic = fopen ("../tmp/".$nom_fichier,"w"); |
296 |
|
|
fwrite ($fic, $inf); |
297 |
|
|
fclose ($fic); |
298 |
|
|
echo _("Le fichier a ete exporte, vous pouvez l'ouvrir immediatement en cliquant sur : "); |
299 |
|
|
$msg = "<a class=\"om-prev-icon trace-16\" href=\"javascript:traces('".$nom_fichier."');\">"; |
300 |
|
|
$msg .= _("Telecharger le fichier")." [".$nom_fichier."]"; |
301 |
|
|
$msg .= "</a>"; |
302 |
|
|
// |
303 |
|
|
$param['lien']=$msg; |
304 |
|
|
$f->layout->display_lien($param); |
305 |
|
|
$msg .= "<br />"; |
306 |
|
|
|
307 |
|
|
} |
308 |
|
|
|
309 |
|
|
// Affichage des actions de controles du formulaire |
310 |
|
|
echo "<div class=\"formControls\">"; |
311 |
|
|
// Lien retour |
312 |
|
|
$param["lien"]="<a href=\"../scr/requeteur.php?obj=".$obj."&step=0\" class=\"retour\">"._("Retour")."</a>"; |
313 |
|
|
$f->layout->display_lien_retour($param); |
314 |
|
|
// Fermeture du conteneur des actions de controles du formulaire |
315 |
|
|
echo "</div>"; |
316 |
|
|
} |
317 |
|
|
|
318 |
|
|
/** |
319 |
|
|
* Fermeture du conteneur de la page |
320 |
|
|
*/ |
321 |
|
|
// |
322 |
|
|
echo "</div>\n"; |
323 |
|
|
// |
324 |
|
|
echo "</div>\n"; |
325 |
|
|
// |
326 |
|
|
echo "</div>\n"; |
327 |
|
|
?> |