1 |
nhaye |
2563 |
<?php |
2 |
|
|
/** |
3 |
|
|
* Classe permettant de factoriser la génération du rendu des requêtes mémorisées |
4 |
|
|
* |
5 |
|
|
* Requêteur |
6 |
|
|
* principe de REQMO (requête memorisée): |
7 |
|
|
* permet de faire des requêtes memorisées |
8 |
|
|
* la requête est paramétrée en sql/typedebase/langue/obj.reqmo.inc.php |
9 |
|
|
* $reqmo['sql'] = requête paramétrable |
10 |
|
|
* les paramètres sont entre crochets |
11 |
|
|
* type de paramètre = $reqmo['parametre'] |
12 |
|
|
* checked : case à cocher pour que la zone soit prise en compte |
13 |
|
|
* liste : liste de valeur proposé pour paramétrer une sélection ou un tri |
14 |
|
|
* select : liste de valeur proposé pour paramétrer une sélection ou un tri |
15 |
|
|
* d'après une requête dans une table |
16 |
|
|
* $reqmo['libelle'] = libéllé de la requête |
17 |
|
|
* $reqmo['separateur'] = séparateur pour fichier csv |
18 |
|
|
* |
19 |
|
|
* @package openfoncier |
20 |
|
|
* @version SVN : $Id$ |
21 |
|
|
*/ |
22 |
|
|
|
23 |
|
|
class reqmo { |
24 |
|
|
|
25 |
|
|
// utils |
26 |
|
|
var $f = ""; |
27 |
|
|
|
28 |
|
|
// Liste des fichiers reqmo |
29 |
|
|
var $tab_reqmo = array(); |
30 |
|
|
|
31 |
|
|
// Type de rendu |
32 |
|
|
var $sortie = ""; |
33 |
|
|
|
34 |
|
|
var $info; |
35 |
|
|
|
36 |
|
|
var $obj; |
37 |
|
|
|
38 |
|
|
var $extension; |
39 |
|
|
|
40 |
|
|
function __construct($f, $obj, $extension = "reqmo") { |
41 |
|
|
$this->f = $f; |
42 |
|
|
$this->obj = $obj; |
43 |
|
|
$this->extension = $extension; |
44 |
|
|
}// fin constructeur |
45 |
|
|
|
46 |
|
|
private function getReqmoFile() { |
47 |
|
|
$dir = getcwd(); |
48 |
fmichon |
3172 |
$dir = substr($dir, 0, strlen($dir) - 4)."/sql/".OM_DB_PHPTYPE."/"; |
49 |
nhaye |
2563 |
$dossier = opendir($dir); |
50 |
|
|
while ($entree = readdir($dossier)) { |
51 |
|
|
if (strstr($entree, $this->extension)) { |
52 |
|
|
|
53 |
|
|
// Si l'extention du fichier $entree est .inc.php |
54 |
|
|
if (strpos($entree, ".inc.php")) { |
55 |
|
|
$filext = strlen($this->extension)+9; |
56 |
|
|
} |
57 |
|
|
// Sinon on considere qu'elle est -> .inc (compatibilite) |
58 |
|
|
else { |
59 |
|
|
$filext = strlen($this->extension)+5; |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
array_push($this->tab_reqmo, |
63 |
|
|
array('file' => substr($entree, 0, strlen($entree) - $filext))); |
64 |
|
|
} |
65 |
|
|
} |
66 |
|
|
closedir($dossier); |
67 |
|
|
asort($this->tab_reqmo); |
68 |
|
|
|
69 |
|
|
return $this->tab_reqmo; |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
function displayReqmoList($url = "../scr/requeteur.php") { |
73 |
|
|
$this->getReqmoFile(); |
74 |
nhaye |
2589 |
echo "\n<div id=\"".$this->extension."\">\n"; |
75 |
nhaye |
2563 |
// |
76 |
|
|
echo "<fieldset class=\"cadre ui-corner-all ui-widget-content\">\n"; |
77 |
|
|
// |
78 |
|
|
echo "\t<legend class=\"ui-corner-all ui-widget-content ui-state-active\">"; |
79 |
|
|
echo _("Choix de la requete memorisee"); |
80 |
|
|
echo "</legend>\n"; |
81 |
|
|
// |
82 |
|
|
echo "\t<div class=\"list\">\n"; |
83 |
|
|
if (count($this->tab_reqmo) == 0) { |
84 |
|
|
echo "<p>"; |
85 |
|
|
echo _("Il n'y a aucun element de ce type dans l'application."); |
86 |
|
|
echo "</p>"; |
87 |
|
|
} |
88 |
|
|
// |
89 |
|
|
$this->f->layout->display_start_liste_responsive(); |
90 |
|
|
// |
91 |
|
|
$nbr_elements=0; |
92 |
|
|
foreach ($this->tab_reqmo as $elem) { |
93 |
|
|
$nbr_elements=$nbr_elements+1; |
94 |
|
|
$this->f->layout->display_start_block_liste_responsive($nbr_elements); |
95 |
|
|
echo "<span>\n"; |
96 |
|
|
// |
97 |
|
|
$params = array( |
98 |
|
|
"file" => $elem['file'] |
99 |
|
|
); |
100 |
|
|
// XXX passe plus par le layout dans le cas ou l'url est passée en paramètre |
101 |
|
|
// $this->f->layout->display_reqmo_lien($params); |
102 |
|
|
echo "<a "; |
103 |
|
|
echo " class=\"om-prev-icon reqmo-16\" href=\"".$url."?obj=".$params['file']."\">"; |
104 |
|
|
echo _($params['file']); |
105 |
|
|
echo "</a>"; |
106 |
|
|
|
107 |
|
|
echo "</span>\n"; |
108 |
|
|
$this->f->layout->display_close_block_liste_responsive(); |
109 |
|
|
// |
110 |
|
|
} |
111 |
|
|
$this->f->layout->display_close_liste_responsive(); |
112 |
|
|
echo "\t</div>\n"; |
113 |
|
|
// |
114 |
|
|
echo "</fieldset>\n"; |
115 |
|
|
// |
116 |
|
|
echo "</div>\n"; |
117 |
|
|
|
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
/** |
121 |
|
|
* Ouverture du conteneur de contenu |
122 |
|
|
* @return [type] [description] |
123 |
|
|
*/ |
124 |
|
|
private function openContent() { |
125 |
|
|
/** |
126 |
|
|
* Ouverture du conteneur de la page |
127 |
|
|
*/ |
128 |
|
|
// |
129 |
|
|
echo "\n<div id=\"generator-generate\">\n"; |
130 |
|
|
// |
131 |
|
|
echo "<div id=\"formulaire\">\n\n"; |
132 |
|
|
// |
133 |
|
|
$this->f->layout->display_start_navbar(); |
134 |
|
|
echo "<ul>\n"; |
135 |
|
|
if (isset($reqmo["reqmo_libelle"])) { |
136 |
|
|
echo "\t<li><a href=\"#tabs-1\">". |
137 |
|
|
_("Export de : "). |
138 |
|
|
_($reqmo["reqmo_libelle"])."</a></li>\n"; |
139 |
|
|
} elseif (isset($reqmo["libelle"])) { |
140 |
|
|
echo "\t<li><a href=\"#tabs-1\">". |
141 |
|
|
_("Export de : "). |
142 |
|
|
_($reqmo["libelle"])."</a></li>\n"; |
143 |
|
|
} else { |
144 |
|
|
echo "\t<li><a href=\"#tabs-1\">". |
145 |
|
|
_("Export de : ")._($this->obj). |
146 |
|
|
"</a></li>\n"; |
147 |
|
|
} |
148 |
|
|
echo "</ul>\n"; |
149 |
|
|
// |
150 |
|
|
$this->f->layout->display_stop_navbar(); |
151 |
|
|
echo "\n<div id=\"tabs-1\">\n"; |
152 |
|
|
} |
153 |
|
|
|
154 |
|
|
/** |
155 |
|
|
* Affichage du formulaire de la requête mémorisée |
156 |
|
|
* @param [type] $validation [description] |
157 |
|
|
* @return [type] [description] |
158 |
|
|
*/ |
159 |
|
|
function displayForm( |
160 |
|
|
$validation, |
161 |
|
|
$urlRequet = "../scr/requeteur.php", |
162 |
vpihour |
3352 |
$urlRetour = "../scr/reqmo.php", $error = false) { |
163 |
nhaye |
2563 |
|
164 |
|
|
$this->openContent(); |
165 |
|
|
/** |
166 |
|
|
* Ouverture du formulaire |
167 |
|
|
*/ |
168 |
|
|
// Ouverture de la balise formulaire |
169 |
|
|
echo "<form method=\"post\" action=\"".$urlRequet."?obj=".$this->obj. |
170 |
|
|
"&step=1\" name=\"f1\">\n"; |
171 |
|
|
$param["obj"]=$this->obj; |
172 |
|
|
$param["db"]= $this->f->db; |
173 |
|
|
$param["validation"]=$validation; |
174 |
|
|
$param["cptemp"]= 0; |
175 |
|
|
$param["cpts"]=0; |
176 |
|
|
$param["cptsel"]=0; |
177 |
|
|
$param["extension"]=$this->extension; |
178 |
vpihour |
3352 |
$param["error"]=$error; |
179 |
nhaye |
2563 |
// XXX Plus possible d'utiliser cette méthode |
180 |
|
|
// $this->f->layout->display_requeteur_formulaire($param, $this->f); |
181 |
|
|
$this->display_requeteur_formulaire($param, $this->f); |
182 |
|
|
// |
183 |
|
|
// Affichage des actions de controles du formulaire |
184 |
|
|
echo "<div class=\"formControls\">"; |
185 |
|
|
// Bouton de validation du formulaire |
186 |
|
|
$param["input"]="<input type=\"submit\" name=\"valid.reqmo\" value=\"". |
187 |
|
|
_("Executer la requete sur :")." '"._($this->obj)."'\" />"; |
188 |
|
|
$this->f->layout->display_input($param); |
189 |
|
|
// Lien retour |
190 |
|
|
// XXX Plus possible |
191 |
|
|
$param["lien"]="<a href=\"".$urlRetour."\" class=\"retour\">"._("Retour")."</a>"; |
192 |
|
|
$this->f->layout->display_lien_retour($param); |
193 |
|
|
// Fermeture du conteneur des actions de controles du formulaire |
194 |
|
|
echo "</div>"; |
195 |
|
|
// Fermeture de la balise formulaire |
196 |
|
|
echo "\n</form>\n"; |
197 |
|
|
$this->closeContent(); |
198 |
|
|
} |
199 |
|
|
|
200 |
|
|
/** |
201 |
|
|
* Fermeture du conteneur de contenu |
202 |
|
|
* @return [type] [description] |
203 |
|
|
*/ |
204 |
|
|
private function displayBoutonRetour($url) { |
205 |
|
|
// Affichage des actions de controles du formulaire |
206 |
|
|
echo "<div class=\"formControls\">"; |
207 |
|
|
// Lien retour |
208 |
|
|
$param["lien"]="<a href=\"".$url."?obj=".$this->obj. |
209 |
|
|
"&step=0\" class=\"retour\">"._("Retour")."</a>"; |
210 |
|
|
$this->f->layout->display_lien_retour($param); |
211 |
|
|
// Fermeture du conteneur des actions de controles du formulaire |
212 |
|
|
echo "</div>"; |
213 |
|
|
} |
214 |
|
|
|
215 |
|
|
/** |
216 |
|
|
* Fermeture du conteneur de contenu |
217 |
|
|
* @return [type] [description] |
218 |
|
|
*/ |
219 |
|
|
private function closeContent() { |
220 |
|
|
// |
221 |
|
|
echo "</div>\n"; |
222 |
|
|
// |
223 |
|
|
echo "</div>\n"; |
224 |
|
|
// |
225 |
|
|
echo "</div>\n"; |
226 |
|
|
} |
227 |
|
|
|
228 |
|
|
function prepareRequest($reqmo) { |
229 |
vpihour |
3354 |
//Variable qui sert à vérifier qu'au moins un des critères a été sélectionné |
230 |
|
|
$checked = false; |
231 |
|
|
$hasCritere = false; |
232 |
|
|
// |
233 |
nhaye |
2563 |
$temp = explode ("[", $reqmo["sql"]); |
234 |
|
|
for($i = 1; $i < count($temp); $i++) { |
235 |
|
|
$temp1 = explode ("]", $temp [$i]); |
236 |
|
|
$temp4 = explode (" as ", $temp1 [0]); |
237 |
|
|
if (isset ($temp4 [1])) { |
238 |
|
|
$temp5 = $temp4 [1]; // uniquement as |
239 |
|
|
} else { |
240 |
|
|
$temp5 = $temp1 [0]; // en entier |
241 |
|
|
} |
242 |
|
|
|
243 |
vpihour |
3352 |
if ($this->f->get_submitted_post_value($temp5) !== null && |
244 |
|
|
$this->f->get_submitted_post_value($temp5) !== '') { |
245 |
nmeucci |
3239 |
$temp2 = $this->f->get_submitted_post_value($temp5); |
246 |
nhaye |
2563 |
} else { |
247 |
|
|
$temp2 = ""; |
248 |
|
|
} |
249 |
|
|
// **** |
250 |
|
|
if(isset($reqmo[$temp5])){ |
251 |
|
|
if($reqmo[$temp5]=="checked") { |
252 |
vpihour |
3354 |
$hasCritere = true; |
253 |
|
|
if ($this->f->get_submitted_post_value($temp5) == 'Oui'|| |
254 |
|
|
$this->f->get_submitted_post_value($temp5) === '') { |
255 |
nhaye |
2563 |
$reqmo ['sql'] = str_replace ("[".$temp1[0]."]", |
256 |
|
|
$temp1[0], |
257 |
|
|
$reqmo['sql']); |
258 |
vpihour |
3354 |
// |
259 |
|
|
$checked=true; |
260 |
nhaye |
2563 |
} else { |
261 |
|
|
$reqmo['sql']=str_replace("[".$temp1[0]."],", |
262 |
|
|
'', |
263 |
|
|
$reqmo['sql']); |
264 |
|
|
$reqmo['sql']=str_replace(",[".$temp1[0]."]", |
265 |
|
|
'', |
266 |
|
|
$reqmo['sql']); |
267 |
|
|
$reqmo['sql']=str_replace(", [".$temp1[0]."]", |
268 |
|
|
'', |
269 |
|
|
$reqmo['sql']); |
270 |
|
|
$reqmo['sql']=str_replace("[".$temp1[0]."]", |
271 |
|
|
'', |
272 |
|
|
$reqmo['sql']); |
273 |
|
|
} |
274 |
|
|
} else { |
275 |
vpihour |
3354 |
if ($temp2=="") return _("Veuillez saisir toutes les valeurs du formulaire."); |
276 |
|
|
elseif (!$this->hasType($temp2, $reqmo['type'][$temp1[0]])) return _("Veuillez saisir les valeurs au bon format."); |
277 |
nhaye |
2563 |
$reqmo['sql']=str_replace("[".$temp1[0]."]", |
278 |
|
|
$temp2, |
279 |
|
|
$reqmo['sql']); |
280 |
|
|
} |
281 |
|
|
//**** |
282 |
|
|
} else { |
283 |
vpihour |
3354 |
if ($temp2=="") return _("Veuillez saisir toutes les valeurs du formulaire."); |
284 |
|
|
elseif (!$this->hasType($temp2, $reqmo['type'][$temp1[0]])) return _("Veuillez saisir les valeurs au bon format."); |
285 |
nhaye |
2563 |
$reqmo['sql']=str_replace("[".$temp1[0]."]", |
286 |
|
|
$temp2, |
287 |
|
|
$reqmo['sql']); |
288 |
|
|
} |
289 |
|
|
//**** |
290 |
|
|
$temp1[0]=""; |
291 |
|
|
} |
292 |
vpihour |
3354 |
// |
293 |
|
|
if (!$checked&&$hasCritere) return _("Veuillez choisir au moins un critère."); |
294 |
|
|
// |
295 |
nhaye |
2563 |
$blanc = 0; |
296 |
|
|
$temp = ""; |
297 |
|
|
for($i=0;$i<strlen($reqmo['sql']);$i++) { |
298 |
|
|
if (substr($reqmo['sql'], $i, 1)==chr(13) or |
299 |
|
|
substr($reqmo['sql'], $i, 1)==chr(10) or |
300 |
|
|
substr($reqmo['sql'], $i, 1)==chr(32)) { |
301 |
|
|
if ($blanc==0){ |
302 |
|
|
$temp=$temp.chr(32); |
303 |
|
|
} |
304 |
|
|
$blanc=1; |
305 |
|
|
} else { |
306 |
|
|
$temp=$temp.substr($reqmo['sql'],$i,1); |
307 |
|
|
$blanc=0; |
308 |
|
|
} |
309 |
|
|
} |
310 |
|
|
$reqmo['sql']=$temp ; |
311 |
|
|
$reqmo['sql']=str_replace(',,', ',', $reqmo['sql']); |
312 |
|
|
$reqmo['sql']=str_replace(', ,', ',', $reqmo['sql']); |
313 |
|
|
$reqmo['sql']=str_replace(', from', ' from', $reqmo['sql']); |
314 |
softime |
3303 |
$reqmo['sql']=str_replace(', FROM', ' FROM', $reqmo['sql']); |
315 |
nhaye |
2563 |
$reqmo['sql']=str_replace('select ,', 'select ', $reqmo['sql']); |
316 |
softime |
3303 |
$reqmo['sql']=str_replace('SELECT ,', 'SELECT ', $reqmo['sql']); |
317 |
nhaye |
2563 |
// post limite |
318 |
nmeucci |
3239 |
if ($this->f->get_submitted_post_value('limite') !== null) { |
319 |
|
|
$limite = $this->f->get_submitted_post_value('limite'); |
320 |
nhaye |
2563 |
} else { |
321 |
|
|
$limite = 100; |
322 |
|
|
} |
323 |
|
|
// post sortie |
324 |
nmeucci |
3239 |
if ($this->f->get_submitted_post_value('sortie') !== null) { |
325 |
|
|
$sortie= $this->f->get_submitted_post_value('sortie'); |
326 |
nhaye |
2563 |
} else { |
327 |
|
|
$sortie ='tableau'; |
328 |
|
|
} |
329 |
vpihour |
3354 |
// |
330 |
|
|
if($sortie =='tableau'&&!is_numeric($limite)){ |
331 |
|
|
return _("Veuillez saisir une valeur numérique pour le nombre limite d'enregistrement à afficher."); |
332 |
|
|
} |
333 |
nhaye |
2563 |
// limite uniquement pour tableau |
334 |
|
|
if ($sortie =='tableau') { |
335 |
|
|
$reqmo['sql']= $reqmo['sql']." limit ".$limite; |
336 |
|
|
} |
337 |
nhaye |
2573 |
$this->reqmo = $reqmo; |
338 |
vpihour |
3352 |
return true; |
339 |
nhaye |
2563 |
} |
340 |
|
|
|
341 |
|
|
function displayTable($url = "../scr/requeteur.php") { |
342 |
nhaye |
2573 |
// execution de la requete |
343 |
|
|
$res_reqmo = $this->f->db-> query ($this->reqmo['sql']); |
344 |
|
|
$this->f->isDatabaseError($res_reqmo); |
345 |
|
|
|
346 |
|
|
$this->info = $res_reqmo -> tableInfo (); |
347 |
nhaye |
2563 |
// |
348 |
|
|
echo " "; |
349 |
|
|
$param['class']="tab"; |
350 |
|
|
$param['idcolumntoggle']="requeteur"; |
351 |
|
|
$this->f->layout->display_table_start($param); |
352 |
|
|
//echo "<table class=\"tab-tab\">\n"; |
353 |
|
|
// |
354 |
|
|
echo "<thead><tr class=\"ui-tabs-nav ui-accordion ui-state-default tab-title\">"; |
355 |
|
|
$key=0; |
356 |
|
|
foreach($this->info as $elem) { |
357 |
|
|
$param = array( |
358 |
|
|
"key" => $key, |
359 |
|
|
"info" => $this->info |
360 |
|
|
); |
361 |
|
|
$this->f->layout->display_table_cellule_entete_colonnes($param); |
362 |
|
|
echo "<center>"._($elem['name'])."</center></th>"; |
363 |
|
|
$key=$key+1; |
364 |
|
|
} |
365 |
|
|
echo "</tr></thead>\n"; |
366 |
|
|
// |
367 |
|
|
$cptenr = 0; |
368 |
nhaye |
2573 |
while ($row=& $res_reqmo->fetchRow()) { |
369 |
nhaye |
2563 |
// |
370 |
|
|
echo "<tr class=\"tab-data ".($cptenr % 2 == 0 ? "odd" : "even")."\">\n"; |
371 |
|
|
// |
372 |
|
|
$cptenr = $cptenr + 1; |
373 |
|
|
$i = 0; |
374 |
|
|
foreach ($row as $elem) { |
375 |
|
|
if (is_numeric($elem)) { |
376 |
|
|
echo "<td class='resultrequete' align='right'>"; |
377 |
|
|
} else { |
378 |
|
|
echo "<td class='resultrequete'>"; |
379 |
|
|
} |
380 |
|
|
$tmp=""; |
381 |
|
|
$tmp=str_replace(chr(13).chr(10), '<br>', $elem); |
382 |
|
|
echo $tmp."</td>"; |
383 |
|
|
$i++; |
384 |
|
|
} |
385 |
|
|
echo "</tr>\n"; |
386 |
|
|
} |
387 |
|
|
// |
388 |
|
|
echo "</tbody></table>\n"; |
389 |
|
|
if ($cptenr==0){ |
390 |
|
|
echo "<br>"._('aucun')." "._('enregistrement')."<br>"; |
391 |
|
|
} |
392 |
|
|
$this->displayBoutonRetour($url); |
393 |
|
|
} |
394 |
|
|
|
395 |
|
|
function displayCSV($separateur, $url = "../scr/requeteur.php") { |
396 |
nhaye |
2573 |
|
397 |
|
|
// execution de la requete |
398 |
|
|
$res_reqmo = $this->f->db-> query ($this->reqmo['sql']); |
399 |
|
|
$this->f->isDatabaseError($res_reqmo); |
400 |
|
|
|
401 |
|
|
$this->info = $res_reqmo -> tableInfo (); |
402 |
|
|
|
403 |
nhaye |
2563 |
$inf=""; |
404 |
|
|
foreach ($this->info as $elem) { |
405 |
|
|
$inf=$inf.$elem['name'].$separateur; |
406 |
|
|
} |
407 |
|
|
$inf .= "\n"; |
408 |
|
|
$cptenr=0; |
409 |
nhaye |
2573 |
while ($row=& $res_reqmo->fetchRow()) { |
410 |
nhaye |
2563 |
$cptenr=$cptenr+1; |
411 |
|
|
$i=0; |
412 |
|
|
foreach($row as $elem) { |
413 |
|
|
//**** |
414 |
|
|
$tmp=""; |
415 |
|
|
$tmp=str_replace(chr(13).chr(10), ' / ', $elem); |
416 |
|
|
$tmp=str_replace(';', ' ', $tmp); |
417 |
|
|
//***** |
418 |
|
|
$inf .= $tmp.$separateur; |
419 |
|
|
$i++; |
420 |
|
|
} |
421 |
|
|
$inf .= "\n"; |
422 |
|
|
} |
423 |
|
|
if ($cptenr==0){ |
424 |
|
|
$inf .="\n"._('aucun')." "._('enregistrement')."\n"; |
425 |
|
|
} |
426 |
|
|
$nom_fichier="export_".$this->obj.".csv"; |
427 |
|
|
$fic = fopen ("../tmp/".$nom_fichier, "w"); |
428 |
|
|
fwrite ($fic, $inf); |
429 |
|
|
fclose ($fic); |
430 |
|
|
echo _("Le fichier a ete exporte, vous pouvez l'ouvrir immediatement en cliquant sur : "); |
431 |
|
|
$msg = "<a class=\"om-prev-icon trace-16\" href=\"javascript:traces('".$nom_fichier."');\">"; |
432 |
|
|
$msg .= _("Telecharger le fichier")." [".$nom_fichier."]"; |
433 |
|
|
$msg .= "</a>"; |
434 |
|
|
// |
435 |
|
|
$param['lien']=$msg; |
436 |
|
|
$this->f->layout->display_lien($param); |
437 |
|
|
$msg .= "<br />"; |
438 |
|
|
$this->displayBoutonRetour($url); |
439 |
|
|
} |
440 |
|
|
|
441 |
nhaye |
2573 |
function displayPDF($url = "../scr/requeteur.php") { |
442 |
|
|
require_once "../core/fpdf_etat.php"; |
443 |
|
|
|
444 |
nhaye |
2656 |
$pdf = new PDF($this->reqmo['om_sousetat_orientation'], "mm", $this->reqmo['om_sousetat_format'], |
445 |
|
|
true, |
446 |
|
|
'UTF-8'); |
447 |
|
|
$pdf->setPrintHeader(false); |
448 |
nhaye |
2573 |
// Ajoute une nouvelle page à l'édition |
449 |
|
|
$pdf->AddPage(); |
450 |
|
|
// On récupère l'enregistrement 'om_sousetat' de la collectivité en cours dans |
451 |
|
|
// l'état 'actif' |
452 |
|
|
$niveau = $_SESSION['niveau']; |
453 |
|
|
$sql = " select * from ".DB_PREFIXE."om_sousetat "; |
454 |
|
|
$sql .= " where id='".$this->reqmo["om_sousetat"]."' "; |
455 |
|
|
$sql .= " and actif IS TRUE "; |
456 |
|
|
$sql .= " and om_collectivite='".$_SESSION['collectivite']."' "; |
457 |
|
|
$res2 = $this->f->db->query($sql); |
458 |
|
|
$this->f->addToLog("pdfetat.php: db->query(\"".$sql."\");", VERBOSE_MODE); |
459 |
|
|
$this->f->isDatabaseError($res2); |
460 |
|
|
// Si on obtient aucun résultat |
461 |
|
|
if ($res2->numrows() == 0) { |
462 |
|
|
// On libère le résultat de la requête précédente |
463 |
|
|
$res2->free(); |
464 |
|
|
// |
465 |
|
|
if ($niveau == "") { |
466 |
|
|
// On récupère l'identifiant de la collectivité de niveau 2 |
467 |
|
|
$sql = "select om_collectivite from ".DB_PREFIXE."om_collectivite "; |
468 |
|
|
$sql .= " where niveau='2' "; |
469 |
|
|
$niveau = $this->f->db->getone($sql); |
470 |
|
|
$this->f->addToLog("pdfetat.php: db->getone(\"".$sql."\");", VERBOSE_MODE); |
471 |
|
|
$this->f->isDatabaseError($niveau); |
472 |
|
|
} |
473 |
|
|
// On récupère l'enregistrement 'om_sousetat' de la collectivité de niveau |
474 |
|
|
// 2 dans l'état 'actif' |
475 |
|
|
$sql = " select * from ".DB_PREFIXE."om_sousetat "; |
476 |
|
|
$sql .= " where id='".$this->reqmo["om_sousetat"]."'"; |
477 |
|
|
$sql .= " and actif IS TRUE "; |
478 |
|
|
$sql .= " and om_collectivite='".$niveau."' "; |
479 |
|
|
$res2 = $this->f->db->query($sql); |
480 |
|
|
$this->f->addToLog("pdfetat.php: db->query(\"".$sql."\");", VERBOSE_MODE); |
481 |
|
|
$this->f->isDatabaseError($res2); |
482 |
|
|
// Si on obtient aucun résultat |
483 |
|
|
if ($res2->numrows() == 0) { |
484 |
|
|
// On libère le résultat de la requête précédente |
485 |
|
|
$res2->free(); |
486 |
|
|
// On récupère l'enregistrement 'om_sousetat' de la collectivité de |
487 |
|
|
// niveau 2 dans n'importe quel état |
488 |
|
|
$sql = " select * from ".DB_PREFIXE."om_sousetat "; |
489 |
|
|
$sql .= " where id='".$this->reqmo["om_sousetat"]."' "; |
490 |
|
|
$sql .= " and om_collectivite='".$niveau."' "; |
491 |
|
|
$res2 = $this->f->db->query($sql); |
492 |
|
|
$this->f->addToLog("pdfetat.php: db->query(\"".$sql."\");", VERBOSE_MODE); |
493 |
|
|
$this->f->isDatabaseError($res2); |
494 |
|
|
} |
495 |
|
|
} |
496 |
|
|
|
497 |
|
|
// |
498 |
|
|
while ($sousetat =& $res2->fetchRow(DB_FETCHMODE_ASSOC)) { |
499 |
|
|
$idx = ""; |
500 |
|
|
$_GET['idx'] = ""; |
501 |
|
|
// |
502 |
|
|
$titre = ''; |
503 |
|
|
$titre = $sousetat['titre']; |
504 |
|
|
$titre = str_replace("&aujourdhui", date('d/m/Y'), $titre); |
505 |
|
|
$collectivite = isset($collectivite)&&$collectivite != array()? |
506 |
|
|
$collectivite: |
507 |
|
|
$this->f->collectivite; |
508 |
|
|
if (isset($collectivite) && $collectivite != array()) { |
509 |
|
|
// |
510 |
|
|
foreach (array_keys($collectivite) as $elem) { |
511 |
|
|
// |
512 |
|
|
$temp = "&".$elem; |
513 |
|
|
$titre = str_replace($temp, $collectivite[$elem], $titre); |
514 |
|
|
$sql = str_replace($temp, $collectivite[$elem], $sql); |
515 |
|
|
if ( strstr($elem, "ged_") === false && strstr($elem, "erp_") === false |
516 |
|
|
&& strstr($elem, "id_") === false && strstr($elem, "sig_") === false |
517 |
|
|
&& strstr($elem, "option_") === false ) { |
518 |
|
|
$champs_remplacement_etat[] = "&".$elem; |
519 |
|
|
} |
520 |
|
|
} |
521 |
|
|
} |
522 |
|
|
//Date au format jour_de_la_semaine jour_du_mois mois_de_l'année |
523 |
|
|
//Ex. Lundi 12 Mars |
524 |
|
|
$jourSemaine = array(_('Dimanche'),_('Lundi'),_('Mardi'),_('Mercredi'),_('Jeudi'), |
525 |
|
|
_('Vendredi'),_('Samedi')); |
526 |
|
|
$moisAnnee = array(_('Janvier'),_('Fevrier'),_('Mars'),_('Avril'),_('Mai'), |
527 |
|
|
_('Juin'),_('Juillet'),_('Aout'),_('Septembre'),_('Octobre'),_('Novembre') |
528 |
|
|
,_('Decembre')); |
529 |
|
|
$titre=str_replace("&jourSemaine",$jourSemaine[date('w')]." ".date('d')." ".$moisAnnee[date('n')-1]." ".date('Y'),$titre); |
530 |
|
|
$sousetat['titre'] = $titre; |
531 |
|
|
$sousetat['om_sql'] = $this->reqmo['sql']; |
532 |
|
|
// imprime les colonnes de la requete |
533 |
|
|
$edition = array( |
534 |
|
|
'se_font' => 'helvetica', |
535 |
|
|
'se_couleurtexte' => array(0,0,0) |
536 |
|
|
); |
537 |
|
|
$pdf->sousetatdb($this->f->db, $edition, $sousetat); |
538 |
|
|
} |
539 |
|
|
|
540 |
|
|
// Construction du nom du fichier |
541 |
|
|
$filename = date("Ymd-His"); |
542 |
|
|
$filename .= "-reqmo"; |
543 |
|
|
$filename .= "-".$this->obj; |
544 |
|
|
$filename .= ".pdf"; |
545 |
|
|
$contenu = $pdf->Output($filename, "S"); |
546 |
|
|
|
547 |
|
|
// Métadonnées du fichier csv résultat |
548 |
|
|
$metadata['filename'] = $filename; |
549 |
|
|
$metadata['size'] = strlen($contenu); |
550 |
|
|
$metadata['mimetype'] = "application/pdf"; |
551 |
|
|
// Création du fichier sur le storage temporaire |
552 |
nhaye |
2581 |
$pdf_res_uid = $this->f->storage->create_temporary($contenu, $metadata); |
553 |
|
|
// Affichage du message d'erreur ou de validation |
554 |
|
|
if($pdf_res_uid === "OP_FAILURE" ){ |
555 |
|
|
$this->f->addToMessage("error", _("Erreur de configuration. Contactez votre administrateur.")); |
556 |
|
|
} else { |
557 |
|
|
$msg = _("Le fichier a ete exporte, vous pouvez l'ouvrir immediatement en cliquant sur : "); |
558 |
nhaye |
2583 |
$msg .= "<a class='bold' target='_blanc' href=\"../spg/file.php?uid=".$pdf_res_uid."&mode=temporary\">"; |
559 |
nhaye |
2581 |
$msg .= _("Telecharger le fichier")." [".$filename."]"; |
560 |
|
|
$msg .= "</a>"; |
561 |
|
|
$this->f->addToMessage("ok", $msg); |
562 |
|
|
} |
563 |
|
|
$this->f->displayMessages(); |
564 |
nhaye |
2573 |
// |
565 |
nhaye |
2581 |
echo "<br />"; |
566 |
nhaye |
2573 |
$this->displayBoutonRetour($url); |
567 |
|
|
} |
568 |
|
|
|
569 |
nhaye |
2563 |
public function display_requeteur_formulaire($param,$f) { |
570 |
|
|
// |
571 |
|
|
// requeteur formulaire |
572 |
|
|
// |
573 |
|
|
$db=$param["db"]; |
574 |
|
|
$extension = $param["extension"]; |
575 |
fmichon |
3172 |
if (file_exists ("../sql/".OM_DB_PHPTYPE."/".$this->obj.".".$extension.".inc.php")) { |
576 |
|
|
include ("../sql/".OM_DB_PHPTYPE."/".$this->obj.".".$extension.".inc.php"); |
577 |
nhaye |
2563 |
} |
578 |
fmichon |
3172 |
elseif (file_exists ("../sql/".OM_DB_PHPTYPE."/".$this->obj.".".$extension.".inc")) { |
579 |
|
|
include ("../sql/".OM_DB_PHPTYPE."/".$this->obj.".".$extension.".inc"); |
580 |
nhaye |
2563 |
} |
581 |
|
|
$validation = $param["validation"]; |
582 |
|
|
$cptemp = $param["cptemp"]; |
583 |
|
|
$cpts=$param["cpts"]; |
584 |
|
|
$cptsel=$param["cptsel"]; |
585 |
vpihour |
3352 |
$error = $param["error"]; |
586 |
nhaye |
2563 |
echo "<table cellpadding=\"0\" class=\"formEntete ui-corner-all\">\n"; |
587 |
|
|
// |
588 |
vpihour |
3354 |
if ($error !== false){ |
589 |
vpihour |
3352 |
require_once PATH_OPENMAIRIE."om_message.class.php"; |
590 |
|
|
$message = new message(); |
591 |
vpihour |
3354 |
$message->displayMessage("error", $error); |
592 |
vpihour |
3352 |
} |
593 |
nhaye |
2563 |
echo "<tr><td colspan=\"2\">"; |
594 |
|
|
// |
595 |
|
|
echo "<fieldset class=\"cadre ui-corner-all ui-widget-content\">\n"; |
596 |
|
|
// |
597 |
|
|
echo "\t<legend class=\"ui-corner-all ui-widget-content ui-state-active\">"; |
598 |
|
|
echo _("Criteres de la requete"); |
599 |
|
|
echo "</legend>\n"; |
600 |
|
|
// |
601 |
|
|
echo "<table>"; |
602 |
|
|
// On separe tous les champs entre crochets dans la requête |
603 |
|
|
$temp = explode ("[", $reqmo["sql"]); |
604 |
|
|
// |
605 |
|
|
for ($i = 1; $i < sizeof($temp); $i++) { |
606 |
|
|
// On vire le crochet de la fin |
607 |
|
|
$temp1 = explode("]", $temp[$i]); |
608 |
|
|
// On check si alias |
609 |
|
|
$temp4 = explode (" as ", $temp1[0]); |
610 |
|
|
if (isset($temp4[1])) { |
611 |
|
|
$temp1[0] = $temp4[1]; |
612 |
|
|
} |
613 |
|
|
// |
614 |
|
|
$temp6 = $temp1[0]; |
615 |
|
|
|
616 |
|
|
if (!isset($reqmo[$temp1[0]])) { |
617 |
|
|
// saisie criteres where |
618 |
|
|
// |
619 |
|
|
if ($cpts == 0) { |
620 |
|
|
echo "<tr>\n"; |
621 |
|
|
} elseif ($cpts == 4) { |
622 |
|
|
echo "</tr>\n<tr>\n"; |
623 |
|
|
$cpts = 0; |
624 |
|
|
} |
625 |
|
|
// |
626 |
|
|
echo "\t<td class=\"tri\">"; |
627 |
|
|
echo " "._($temp6)." <input type=\"text\" name=\"".$temp1[0]."\" value=\"\" size=\"30\" class=\"champFormulaire\" />"; |
628 |
|
|
echo "</td>\n"; |
629 |
|
|
// |
630 |
|
|
$cpts++; |
631 |
|
|
} else { |
632 |
|
|
// |
633 |
|
|
|
634 |
|
|
if ($reqmo[$temp1[0]] == "checked") { |
635 |
|
|
// |
636 |
|
|
if ($cptemp == 0) { |
637 |
|
|
echo "<tr>\n"; |
638 |
|
|
echo "\t<td colspan=\"4\"><b>"; |
639 |
|
|
echo _("Choix des champs a afficher"); |
640 |
|
|
echo "</b></td>\n"; |
641 |
|
|
echo "</tr>\n<tr>\n"; |
642 |
|
|
} elseif ($cptemp == 4) { |
643 |
|
|
echo "</tr>\n<tr>\n"; |
644 |
|
|
$cptemp = 0; |
645 |
|
|
} |
646 |
|
|
// |
647 |
|
|
echo "\t<td colspan='2' class='champs'>"; |
648 |
vpihour |
3354 |
echo "<input type=\"checkbox\" value=\"".(($this->f->get_submitted_post_value($temp1[0])!==null||$this->f->get_submitted_get_value('step')===null||$this->f->get_submitted_get_value('step')=="0")?"Oui":"")."\" name=\"".$temp1[0]."\" size=\"40\" class=\"champFormulaire\" ".(($this->f->get_submitted_post_value($temp1[0])=="Oui"||$this->f->get_submitted_get_value('step')===null||$this->f->get_submitted_get_value('step')=="0")?"checked=\"checked\"":"")." />"; |
649 |
nhaye |
2563 |
echo " "._($temp6)." "; |
650 |
|
|
echo "</td>\n"; |
651 |
|
|
// |
652 |
|
|
$cptemp++; |
653 |
|
|
} else { |
654 |
|
|
// |
655 |
|
|
$temp3 = ""; |
656 |
|
|
$temp3 = $reqmo[$temp1[0]]; |
657 |
|
|
if(!is_array($temp3)) { |
658 |
|
|
$temp3 = substr($temp3, 0, 6); |
659 |
|
|
} |
660 |
|
|
// |
661 |
|
|
if ($temp3 == "select") { |
662 |
|
|
// |
663 |
|
|
if ($cptsel == 0) { |
664 |
|
|
echo "</tr><tr>\n"; |
665 |
|
|
echo "\t<td colspan=\"4\"><b>"; |
666 |
|
|
echo _("Choix des criteres de tri"); |
667 |
|
|
echo "</b></td>\n"; |
668 |
|
|
echo "</tr>\n"; |
669 |
|
|
} elseif ($cptsel == 4) { |
670 |
|
|
echo "</tr>\n<tr>\n"; |
671 |
|
|
$cptsel = 0; |
672 |
|
|
} |
673 |
|
|
// |
674 |
|
|
echo "\t<td class=\"tri\">"; |
675 |
|
|
echo _($temp6)." "; |
676 |
|
|
echo "<select name=\"".$temp1[0]."\" class=\"champFormulaire\">"; |
677 |
|
|
$res1 = $db->query($reqmo[$temp1[0]]); |
678 |
|
|
$f->isDatabaseError($res1); |
679 |
|
|
while ($row1 =& $res1->fetchRow()) { |
680 |
vpihour |
3352 |
echo "<option value=\"".$row1[0]."\" ".(($this->f->get_submitted_post_value($temp1[0])==$row1[0])?"selected=\"selected\"":"").">".$row1[1]."</option>"; |
681 |
nhaye |
2563 |
} |
682 |
|
|
echo "</select>"; |
683 |
|
|
echo "</td>\n"; |
684 |
|
|
// |
685 |
|
|
$cptsel++; |
686 |
vpihour |
3219 |
} |
687 |
|
|
//Si un tableau est fourni |
688 |
|
|
elseif(is_array($temp3)) { |
689 |
nhaye |
2563 |
// |
690 |
|
|
if ($cptsel == 0) { |
691 |
|
|
echo "</tr><tr>\n"; |
692 |
|
|
echo "\t<td colspan=\"4\"><b>"; |
693 |
|
|
echo _("Choix des criteres de tri"); |
694 |
|
|
echo "</b></td>\n"; |
695 |
|
|
echo "</tr><tr>\n"; |
696 |
|
|
} elseif ($cptsel == 4) { |
697 |
|
|
echo "</tr>\n<tr>\n"; |
698 |
|
|
$cptsel = 0; |
699 |
|
|
} |
700 |
|
|
// |
701 |
|
|
echo "\t<td class=\"tri\">"; |
702 |
|
|
echo _($temp6)." "; |
703 |
|
|
echo "<select name=\"".$temp1[0]."\" class=\"champFormulaire\">"; |
704 |
|
|
foreach ($reqmo [$temp1 [0]] as $elem) { |
705 |
vpihour |
3353 |
echo "<option value='".$elem."' ".(($this->f->get_submitted_post_value($temp1[0])==$elem)?"selected='selected'":"").">"._($elem)."</option>"; |
706 |
nhaye |
2563 |
} |
707 |
|
|
echo "</select>"; |
708 |
|
|
echo "</td>\n"; |
709 |
|
|
// |
710 |
|
|
$cptsel++; |
711 |
vpihour |
3219 |
} |
712 |
|
|
// Si un input est fourni |
713 |
|
|
else { |
714 |
|
|
// |
715 |
|
|
if ($cptsel == 0) { |
716 |
|
|
echo "</tr><tr>\n"; |
717 |
|
|
echo "\t<td colspan=\"4\"><b>"; |
718 |
|
|
echo _("Choix des criteres de tri"); |
719 |
|
|
echo "</b></td>\n"; |
720 |
|
|
echo "</tr><tr>\n"; |
721 |
|
|
} elseif ($cptsel == 4) { |
722 |
|
|
echo "</tr>\n<tr>\n"; |
723 |
|
|
$cptsel = 0; |
724 |
|
|
} |
725 |
|
|
// |
726 |
|
|
echo "\t<td class=\"tri\">"; |
727 |
|
|
echo _($temp6)." "; |
728 |
vpihour |
3352 |
echo "<input type=\"text\" name=\""._($temp6)."\" placeholder=\"".$reqmo[$temp6]."\" value=\"".$this->f->get_submitted_post_value($temp1[0])."\" size=\"10\" class=\"champFormulaire\" />"; |
729 |
vpihour |
3219 |
echo "</td>\n"; |
730 |
|
|
// |
731 |
|
|
$cptsel++; |
732 |
nhaye |
2563 |
} |
733 |
|
|
} |
734 |
|
|
} |
735 |
|
|
// re initialisation |
736 |
|
|
$temp1[0] = ""; |
737 |
|
|
} |
738 |
|
|
echo "</tr>"; |
739 |
|
|
echo "</table>"; |
740 |
|
|
// |
741 |
|
|
echo "</fieldset>\n"; |
742 |
|
|
// |
743 |
|
|
//echo "<table>\n"; |
744 |
|
|
// |
745 |
|
|
echo "<tr><td colspan=\"2\">"; |
746 |
|
|
// |
747 |
|
|
echo "<fieldset class=\"cadre ui-corner-all ui-widget-content\">\n"; |
748 |
|
|
// |
749 |
|
|
echo "\t<legend class=\"ui-corner-all ui-widget-content ui-state-active\">"; |
750 |
|
|
echo _("Parametres de sortie"); |
751 |
|
|
echo "</legend>\n"; |
752 |
|
|
// |
753 |
|
|
echo "<table>"; |
754 |
|
|
// |
755 |
|
|
echo "<tr>"; |
756 |
|
|
// |
757 |
|
|
echo "<td class=\"params\">"._("Choix du format de sortie")." "; |
758 |
|
|
echo "<select name=\"sortie\" class=\"champFormulaire\">"; |
759 |
vpihour |
3352 |
echo "<option value=\"tableau\" ".(($this->f->get_submitted_post_value('sortie')=="tableau")?"selected='selected'":"").">"._("Tableau - Affichage a l'ecran")."</option>"; |
760 |
|
|
echo "<option value=\"csv\" ".(($this->f->get_submitted_post_value('sortie')=="csv")?"selected='selected'":"").">"._("CSV - Export vers logiciel tableur")."</option>"; |
761 |
nhaye |
2573 |
|
762 |
|
|
if(isset($reqmo["om_sousetat"]) AND $reqmo["om_sousetat"] != "") { |
763 |
vpihour |
3352 |
echo "<option value=\"pdf\" ".(($this->f->get_submitted_post_value('sortie')=="pdf")?"selected='selected'":"").">"._("PDF - Version imprimable")."</option>"; |
764 |
nhaye |
2573 |
} |
765 |
nhaye |
2563 |
echo "</select>"; |
766 |
|
|
echo "</td>"; |
767 |
|
|
// |
768 |
|
|
echo "</tr>"; |
769 |
|
|
echo "<tr>"; |
770 |
|
|
// |
771 |
|
|
echo "<td class=\"params\">"._("Separateur de champs (pour le format CSV)")." "; |
772 |
|
|
echo "<select name=\"separateur\" class=\"champFormulaire\">"; |
773 |
vpihour |
3352 |
echo "<option ".(($this->f->get_submitted_post_value('separateur')==";")?"selected='selected'":"").">;</option>"; |
774 |
|
|
echo "<option ".(($this->f->get_submitted_post_value('separateur')=="|")?"selected='selected'":"").">|</option>"; |
775 |
|
|
echo "<option ".(($this->f->get_submitted_post_value('separateur')==",")?"selected='selected'":"").">,</option>"; |
776 |
nhaye |
2563 |
echo "</select>"; |
777 |
|
|
echo "</td>"; |
778 |
|
|
// |
779 |
|
|
echo "</tr>"; |
780 |
|
|
echo "<tr>"; |
781 |
|
|
// |
782 |
|
|
echo "<td class=\"params\" >"._("Nombre limite d'enregistrements a afficher (pour le format Tableau)")." "; |
783 |
vpihour |
3354 |
echo "<input type=\"text\" name=\"limite\" value=\"".(($this->f->get_submitted_post_value('limite')!==""&&$this->f->get_submitted_get_value('step')!==null&&$this->f->get_submitted_get_value('step')!="0")?$this->f->get_submitted_post_value('limite'):"100")."\" size=\"5\" class=\"champFormulaire\" />"; |
784 |
nhaye |
2563 |
echo "</td>"; |
785 |
|
|
echo "</tr>"; |
786 |
|
|
echo "</table>"; |
787 |
|
|
// |
788 |
|
|
echo "</fieldset>\n"; |
789 |
|
|
// |
790 |
|
|
echo "</td></tr>\n"; |
791 |
|
|
// Fermeture de la balise table |
792 |
|
|
echo "</table>\n"; |
793 |
|
|
} |
794 |
vpihour |
3354 |
|
795 |
|
|
/** |
796 |
|
|
* Test si la valeur passée en argument est du type attendu |
797 |
|
|
* @param type $valeur Valeur à tester |
798 |
|
|
* @param type $type Type attendu de la donnée |
799 |
|
|
*/ |
800 |
|
|
function hasType($valeur, $type){ |
801 |
|
|
|
802 |
|
|
switch ($type){ |
803 |
|
|
case 'date' : |
804 |
|
|
$d = DateTime::createFromFormat('d/m/Y', $valeur); |
805 |
|
|
return $d && $d->format('d/m/Y') == $valeur; |
806 |
|
|
case 'integer' : |
807 |
|
|
return is_numeric($valeur); |
808 |
|
|
case 'string' : |
809 |
|
|
return is_string($valeur); |
810 |
|
|
default : |
811 |
|
|
return false; |
812 |
|
|
} |
813 |
|
|
} |
814 |
nhaye |
2563 |
|
815 |
|
|
}// fin classe |
816 |
|
|
?> |