1 |
<?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: reqmo.class.php 6046 2016-02-26 15:27:06Z fmichon $ |
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 |
$dir = substr($dir, 0, strlen($dir) - 4)."/sql/".OM_DB_PHPTYPE."/"; |
49 |
$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 |
echo "\n<div id=\"".$this->extension."\">\n"; |
75 |
// |
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 |
$urlRetour = "../scr/reqmo.php", $error = false) { |
163 |
|
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 |
$param["error"]=$error; |
179 |
// 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 |
// Gestion éventuelle du multi-collectivités |
230 |
if (strpos($reqmo['sql'], 'IN (<idx_collectivite>)') !== false) { |
231 |
// Par défaut comportement mono |
232 |
$idx_collectivite = $_SESSION['collectivite']; |
233 |
// Si utilisateur multi |
234 |
if ($this->f->has_collectivite_multi() === true) { |
235 |
$idx_collectivite = $this->f->get_list_id_collectivites(); |
236 |
// si échec |
237 |
if ($idx_collectivite === false) { |
238 |
return _("Erreur de base de donnees. Contactez votre administrateur."); |
239 |
} |
240 |
} |
241 |
// Remplacement |
242 |
$reqmo['sql']=str_replace('<idx_collectivite>', $idx_collectivite, $reqmo['sql']); |
243 |
} |
244 |
// Variable qui sert à vérifier qu'au moins un des critères a été sélectionné |
245 |
$checked = false; |
246 |
$hasCritere = false; |
247 |
// |
248 |
$temp = explode ("[", $reqmo["sql"]); |
249 |
for($i = 1; $i < count($temp); $i++) { |
250 |
$temp1 = explode ("]", $temp [$i]); |
251 |
$temp4 = explode (" as ", $temp1 [0]); |
252 |
if (isset ($temp4 [1])) { |
253 |
$temp5 = $temp4 [1]; // uniquement as |
254 |
} else { |
255 |
$temp5 = $temp1 [0]; // en entier |
256 |
} |
257 |
|
258 |
if ($this->f->get_submitted_post_value($temp5) !== null && |
259 |
$this->f->get_submitted_post_value($temp5) !== '') { |
260 |
$temp2 = $this->f->get_submitted_post_value($temp5); |
261 |
} elseif (isset($reqmo['required'][$temp1[0]]) |
262 |
&& $reqmo['required'][$temp1[0]] === false |
263 |
&& isset($reqmo['default'][$temp1[0]])) { |
264 |
// récupération de l'éventuel défaut |
265 |
$temp2 = $reqmo['default'][$temp1[0]]; |
266 |
} else { |
267 |
$temp2 = ""; |
268 |
} |
269 |
// **** |
270 |
if(isset($reqmo[$temp5])){ |
271 |
if($reqmo[$temp5]=="checked") { |
272 |
$hasCritere = true; |
273 |
if ($this->f->get_submitted_post_value($temp5) == 'Oui'|| |
274 |
$this->f->get_submitted_post_value($temp5) === '') { |
275 |
$reqmo ['sql'] = str_replace ("[".$temp1[0]."]", |
276 |
$temp1[0], |
277 |
$reqmo['sql']); |
278 |
// |
279 |
$checked=true; |
280 |
} else { |
281 |
$reqmo['sql']=str_replace("[".$temp1[0]."],", |
282 |
'', |
283 |
$reqmo['sql']); |
284 |
$reqmo['sql']=str_replace(",[".$temp1[0]."]", |
285 |
'', |
286 |
$reqmo['sql']); |
287 |
$reqmo['sql']=str_replace(", [".$temp1[0]."]", |
288 |
'', |
289 |
$reqmo['sql']); |
290 |
$reqmo['sql']=str_replace("[".$temp1[0]."]", |
291 |
'', |
292 |
$reqmo['sql']); |
293 |
} |
294 |
} else { |
295 |
if ($temp2=="") return _("Veuillez saisir toutes les valeurs du formulaire."); |
296 |
elseif (!$this->hasType($temp2, $reqmo['type'][$temp1[0]])) return _("Veuillez saisir les valeurs au bon format."); |
297 |
$reqmo['sql']=str_replace("[".$temp1[0]."]", |
298 |
$temp2, |
299 |
$reqmo['sql']); |
300 |
} |
301 |
//**** |
302 |
} else { |
303 |
if ($temp2=="") return _("Veuillez saisir toutes les valeurs du formulaire."); |
304 |
elseif (!$this->hasType($temp2, $reqmo['type'][$temp1[0]])) return _("Veuillez saisir les valeurs au bon format."); |
305 |
$reqmo['sql']=str_replace("[".$temp1[0]."]", |
306 |
$temp2, |
307 |
$reqmo['sql']); |
308 |
} |
309 |
//**** |
310 |
$temp1[0]=""; |
311 |
} |
312 |
// |
313 |
if (!$checked&&$hasCritere) return _("Veuillez choisir au moins un critère."); |
314 |
// |
315 |
$blanc = 0; |
316 |
$temp = ""; |
317 |
for($i=0;$i<strlen($reqmo['sql']);$i++) { |
318 |
if (substr($reqmo['sql'], $i, 1)==chr(13) or |
319 |
substr($reqmo['sql'], $i, 1)==chr(10) or |
320 |
substr($reqmo['sql'], $i, 1)==chr(32)) { |
321 |
if ($blanc==0){ |
322 |
$temp=$temp.chr(32); |
323 |
} |
324 |
$blanc=1; |
325 |
} else { |
326 |
$temp=$temp.substr($reqmo['sql'],$i,1); |
327 |
$blanc=0; |
328 |
} |
329 |
} |
330 |
$reqmo['sql']=$temp ; |
331 |
$reqmo['sql']=str_replace(',,', ',', $reqmo['sql']); |
332 |
$reqmo['sql']=str_replace(', ,', ',', $reqmo['sql']); |
333 |
$reqmo['sql']=str_replace(', from', ' from', $reqmo['sql']); |
334 |
$reqmo['sql']=str_replace(', FROM', ' FROM', $reqmo['sql']); |
335 |
$reqmo['sql']=str_replace('select ,', 'select ', $reqmo['sql']); |
336 |
$reqmo['sql']=str_replace('SELECT ,', 'SELECT ', $reqmo['sql']); |
337 |
// post limite |
338 |
if ($this->f->get_submitted_post_value('limite') !== null) { |
339 |
$limite = $this->f->get_submitted_post_value('limite'); |
340 |
} else { |
341 |
$limite = 100; |
342 |
} |
343 |
// post sortie |
344 |
if ($this->f->get_submitted_post_value('sortie') !== null) { |
345 |
$sortie= $this->f->get_submitted_post_value('sortie'); |
346 |
} else { |
347 |
$sortie ='tableau'; |
348 |
} |
349 |
// |
350 |
if($sortie =='tableau'&&!is_numeric($limite)){ |
351 |
return _("Veuillez saisir une valeur numérique pour le nombre limite d'enregistrement à afficher."); |
352 |
} |
353 |
// limite uniquement pour tableau |
354 |
if ($sortie =='tableau') { |
355 |
$reqmo['sql']= $reqmo['sql']." limit ".$limite; |
356 |
} |
357 |
// s'il y a des conditions à supprimer |
358 |
if (isset($reqmo['conditions_to_delete']) |
359 |
&& is_array($reqmo['conditions_to_delete'])) { |
360 |
// on supprime chacune que l'on trouve |
361 |
foreach ($reqmo['conditions_to_delete'] as $condition) { |
362 |
$condition = trim($condition); |
363 |
if (strpos($reqmo['sql'], $condition) !== false) { |
364 |
$reqmo['sql']=str_replace($condition, '', $reqmo['sql']); |
365 |
} |
366 |
} |
367 |
} |
368 |
$this->reqmo = $reqmo; |
369 |
return true; |
370 |
} |
371 |
|
372 |
function displayTable($url = "../scr/requeteur.php") { |
373 |
// execution de la requete |
374 |
$res_reqmo = $this->f->db-> query ($this->reqmo['sql']); |
375 |
$this->f->isDatabaseError($res_reqmo); |
376 |
|
377 |
$this->info = $res_reqmo -> tableInfo (); |
378 |
// |
379 |
echo " "; |
380 |
$param['class']="tab"; |
381 |
$param['idcolumntoggle']="requeteur"; |
382 |
$this->f->layout->display_table_start($param); |
383 |
//echo "<table class=\"tab-tab\">\n"; |
384 |
// |
385 |
echo "<thead><tr class=\"ui-tabs-nav ui-accordion ui-state-default tab-title\">"; |
386 |
$key=0; |
387 |
foreach($this->info as $elem) { |
388 |
$param = array( |
389 |
"key" => $key, |
390 |
"info" => $this->info |
391 |
); |
392 |
$this->f->layout->display_table_cellule_entete_colonnes($param); |
393 |
echo "<center>"._($elem['name'])."</center></th>"; |
394 |
$key=$key+1; |
395 |
} |
396 |
echo "</tr></thead>\n"; |
397 |
// |
398 |
$cptenr = 0; |
399 |
while ($row=& $res_reqmo->fetchRow()) { |
400 |
// |
401 |
echo "<tr class=\"tab-data ".($cptenr % 2 == 0 ? "odd" : "even")."\">\n"; |
402 |
// |
403 |
$cptenr = $cptenr + 1; |
404 |
$i = 0; |
405 |
foreach ($row as $elem) { |
406 |
if (is_numeric($elem)) { |
407 |
echo "<td class='resultrequete' align='right'>"; |
408 |
} else { |
409 |
echo "<td class='resultrequete'>"; |
410 |
} |
411 |
$tmp=""; |
412 |
$tmp=str_replace(chr(13).chr(10), '<br>', $elem); |
413 |
echo $tmp."</td>"; |
414 |
$i++; |
415 |
} |
416 |
echo "</tr>\n"; |
417 |
} |
418 |
// |
419 |
echo "</tbody></table>\n"; |
420 |
if ($cptenr==0){ |
421 |
echo "<br>"._('aucun')." "._('enregistrement')."<br>"; |
422 |
} |
423 |
$this->displayBoutonRetour($url); |
424 |
} |
425 |
|
426 |
function displayCSV($separateur, $url = "../scr/requeteur.php") { |
427 |
|
428 |
// execution de la requete |
429 |
$res_reqmo = $this->f->db-> query ($this->reqmo['sql']); |
430 |
$this->f->isDatabaseError($res_reqmo); |
431 |
|
432 |
$this->info = $res_reqmo -> tableInfo (); |
433 |
|
434 |
$inf=""; |
435 |
foreach ($this->info as $elem) { |
436 |
$inf=$inf.$elem['name'].$separateur; |
437 |
} |
438 |
$inf .= "\n"; |
439 |
$cptenr=0; |
440 |
while ($row=& $res_reqmo->fetchRow()) { |
441 |
$cptenr=$cptenr+1; |
442 |
$i=0; |
443 |
foreach($row as $elem) { |
444 |
//**** |
445 |
$tmp=""; |
446 |
$tmp=str_replace(chr(13).chr(10), ' / ', $elem); |
447 |
$tmp=str_replace(';', ' ', $tmp); |
448 |
//***** |
449 |
$inf .= $tmp.$separateur; |
450 |
$i++; |
451 |
} |
452 |
$inf .= "\n"; |
453 |
} |
454 |
if ($cptenr==0){ |
455 |
$inf .="\n"._('aucun')." "._('enregistrement')."\n"; |
456 |
} |
457 |
|
458 |
/** |
459 |
* Écriture de l'export dans un fichier sur le disque et affichage du |
460 |
* lien de téléchargement. |
461 |
*/ |
462 |
// Composition du nom du fichier |
463 |
$nom_fichier = "export_".$this->obj.".csv"; |
464 |
// Composition des métadonnées du fichier |
465 |
$metadata_fichier = array( |
466 |
"filename" => $nom_fichier, |
467 |
"size" => strlen($inf), |
468 |
"mimetype" => "text/csv", |
469 |
); |
470 |
// Écriture du fichier |
471 |
$uid_fichier = $this->f->storage->create_temporary($inf, $metadata_fichier); |
472 |
// |
473 |
echo _("Le fichier a ete exporte, vous pouvez l'ouvrir immediatement en cliquant sur : "); |
474 |
$msg = "<a class=\"om-prev-icon trace-16\" href=\"../spg/file.php?uid=".$uid_fichier."&mode=temporary\" target=\"_blank\">"; |
475 |
$msg .= _("Telecharger le fichier")." [".$nom_fichier."]"; |
476 |
$msg .= "</a>"; |
477 |
// |
478 |
$param['lien']=$msg; |
479 |
$this->f->layout->display_lien($param); |
480 |
$msg .= "<br />"; |
481 |
$this->displayBoutonRetour($url); |
482 |
} |
483 |
|
484 |
function displayPDF($url = "../scr/requeteur.php") { |
485 |
require_once "../core/fpdf_etat.php"; |
486 |
|
487 |
$pdf = new PDF($this->reqmo['om_sousetat_orientation'], "mm", $this->reqmo['om_sousetat_format'], |
488 |
true, |
489 |
'UTF-8'); |
490 |
$pdf->setPrintHeader(false); |
491 |
// Affichage de la mention Page X/X en pied de page |
492 |
$pdf->startPageGroup(); |
493 |
$pdf->set_footer(array( |
494 |
"offset" => 12, |
495 |
"html" => sprintf( |
496 |
'<p style="text-align:center;font-size:8pt;"><em>Page %s/%s</em></p>', |
497 |
$pdf->getPageNumGroupAlias(), |
498 |
$pdf->getPageGroupAlias() |
499 |
), |
500 |
)); |
501 |
// Ajoute une nouvelle page à l'édition |
502 |
$pdf->AddPage(); |
503 |
// On récupère l'enregistrement 'om_sousetat' de la collectivité en cours dans |
504 |
// l'état 'actif' |
505 |
$niveau = $_SESSION['niveau']; |
506 |
$sql = " select * from ".DB_PREFIXE."om_sousetat "; |
507 |
$sql .= " where id='".$this->reqmo["om_sousetat"]."' "; |
508 |
$sql .= " and actif IS TRUE "; |
509 |
$sql .= " and om_collectivite='".$_SESSION['collectivite']."' "; |
510 |
$res2 = $this->f->db->query($sql); |
511 |
$this->f->addToLog("pdfetat.php: db->query(\"".$sql."\");", VERBOSE_MODE); |
512 |
$this->f->isDatabaseError($res2); |
513 |
// Si on obtient aucun résultat |
514 |
if ($res2->numrows() == 0) { |
515 |
// On libère le résultat de la requête précédente |
516 |
$res2->free(); |
517 |
// |
518 |
if ($niveau == "") { |
519 |
// On récupère l'identifiant de la collectivité de niveau 2 |
520 |
$sql = "select om_collectivite from ".DB_PREFIXE."om_collectivite "; |
521 |
$sql .= " where niveau='2' "; |
522 |
$niveau = $this->f->db->getone($sql); |
523 |
$this->f->addToLog("pdfetat.php: db->getone(\"".$sql."\");", VERBOSE_MODE); |
524 |
$this->f->isDatabaseError($niveau); |
525 |
} |
526 |
// On récupère l'enregistrement 'om_sousetat' de la collectivité de niveau |
527 |
// 2 dans l'état 'actif' |
528 |
$sql = " select * from ".DB_PREFIXE."om_sousetat "; |
529 |
$sql .= " where id='".$this->reqmo["om_sousetat"]."'"; |
530 |
$sql .= " and actif IS TRUE "; |
531 |
$sql .= " and om_collectivite='".$niveau."' "; |
532 |
$res2 = $this->f->db->query($sql); |
533 |
$this->f->addToLog("pdfetat.php: db->query(\"".$sql."\");", VERBOSE_MODE); |
534 |
$this->f->isDatabaseError($res2); |
535 |
// Si on obtient aucun résultat |
536 |
if ($res2->numrows() == 0) { |
537 |
// On libère le résultat de la requête précédente |
538 |
$res2->free(); |
539 |
// On récupère l'enregistrement 'om_sousetat' de la collectivité de |
540 |
// niveau 2 dans n'importe quel état |
541 |
$sql = " select * from ".DB_PREFIXE."om_sousetat "; |
542 |
$sql .= " where id='".$this->reqmo["om_sousetat"]."' "; |
543 |
$sql .= " and om_collectivite='".$niveau."' "; |
544 |
$res2 = $this->f->db->query($sql); |
545 |
$this->f->addToLog("pdfetat.php: db->query(\"".$sql."\");", VERBOSE_MODE); |
546 |
$this->f->isDatabaseError($res2); |
547 |
} |
548 |
} |
549 |
|
550 |
// |
551 |
while ($sousetat =& $res2->fetchRow(DB_FETCHMODE_ASSOC)) { |
552 |
$idx = ""; |
553 |
$_GET['idx'] = ""; |
554 |
// |
555 |
$titre = ''; |
556 |
$titre = $sousetat['titre']; |
557 |
$titre = str_replace("&aujourdhui", date('d/m/Y'), $titre); |
558 |
$collectivite = isset($collectivite)&&$collectivite != array()? |
559 |
$collectivite: |
560 |
$this->f->getCollectivite(); |
561 |
if (isset($collectivite) && $collectivite != array()) { |
562 |
// |
563 |
foreach (array_keys($collectivite) as $elem) { |
564 |
// |
565 |
$temp = "&".$elem; |
566 |
$titre = str_replace($temp, $collectivite[$elem], $titre); |
567 |
$sql = str_replace($temp, $collectivite[$elem], $sql); |
568 |
if ( strstr($elem, "ged_") === false && strstr($elem, "erp_") === false |
569 |
&& strstr($elem, "id_") === false && strstr($elem, "sig_") === false |
570 |
&& strstr($elem, "option_") === false ) { |
571 |
$champs_remplacement_etat[] = "&".$elem; |
572 |
} |
573 |
} |
574 |
} |
575 |
//Date au format jour_de_la_semaine jour_du_mois mois_de_l'année |
576 |
//Ex. Lundi 12 Mars |
577 |
$jourSemaine = array(_('Dimanche'),_('Lundi'),_('Mardi'),_('Mercredi'),_('Jeudi'), |
578 |
_('Vendredi'),_('Samedi')); |
579 |
$moisAnnee = array(_('Janvier'),_('Fevrier'),_('Mars'),_('Avril'),_('Mai'), |
580 |
_('Juin'),_('Juillet'),_('Aout'),_('Septembre'),_('Octobre'),_('Novembre') |
581 |
,_('Decembre')); |
582 |
$titre=str_replace("&jourSemaine",$jourSemaine[date('w')]." ".date('d')." ".$moisAnnee[date('n')-1]." ".date('Y'),$titre); |
583 |
$sousetat['titre'] = $titre; |
584 |
$sousetat['om_sql'] = $this->reqmo['sql']; |
585 |
// imprime les colonnes de la requete |
586 |
$edition = array( |
587 |
'se_font' => 'helvetica', |
588 |
'se_couleurtexte' => array(0,0,0) |
589 |
); |
590 |
$pdf->sousetatdb($this->f->db, $edition, $sousetat); |
591 |
} |
592 |
|
593 |
// Construction du nom du fichier |
594 |
$filename = date("Ymd-His"); |
595 |
$filename .= "-reqmo"; |
596 |
$filename .= "-".$this->obj; |
597 |
$filename .= ".pdf"; |
598 |
$contenu = $pdf->Output($filename, "S"); |
599 |
|
600 |
// Métadonnées du fichier csv résultat |
601 |
$metadata['filename'] = $filename; |
602 |
$metadata['size'] = strlen($contenu); |
603 |
$metadata['mimetype'] = "application/pdf"; |
604 |
// Création du fichier sur le storage temporaire |
605 |
$pdf_res_uid = $this->f->storage->create_temporary($contenu, $metadata); |
606 |
// Affichage du message d'erreur ou de validation |
607 |
if($pdf_res_uid === "OP_FAILURE" ){ |
608 |
$this->f->addToMessage("error", _("Erreur de configuration. Contactez votre administrateur.")); |
609 |
} else { |
610 |
$msg = _("Le fichier a ete exporte, vous pouvez l'ouvrir immediatement en cliquant sur : "); |
611 |
$msg .= "<a class='bold' target='_blanc' href=\"../spg/file.php?uid=".$pdf_res_uid."&mode=temporary\">"; |
612 |
$msg .= _("Telecharger le fichier")." [".$filename."]"; |
613 |
$msg .= "</a>"; |
614 |
$this->f->addToMessage("ok", $msg); |
615 |
} |
616 |
$this->f->displayMessages(); |
617 |
// |
618 |
echo "<br />"; |
619 |
$this->displayBoutonRetour($url); |
620 |
} |
621 |
|
622 |
public function display_requeteur_formulaire($param,$f) { |
623 |
// |
624 |
// requeteur formulaire |
625 |
// |
626 |
$db=$param["db"]; |
627 |
$extension = $param["extension"]; |
628 |
if (file_exists ("../sql/".OM_DB_PHPTYPE."/".$this->obj.".".$extension.".inc.php")) { |
629 |
include ("../sql/".OM_DB_PHPTYPE."/".$this->obj.".".$extension.".inc.php"); |
630 |
} |
631 |
elseif (file_exists ("../sql/".OM_DB_PHPTYPE."/".$this->obj.".".$extension.".inc")) { |
632 |
include ("../sql/".OM_DB_PHPTYPE."/".$this->obj.".".$extension.".inc"); |
633 |
} |
634 |
$validation = $param["validation"]; |
635 |
$cptemp = $param["cptemp"]; |
636 |
$cpts=$param["cpts"]; |
637 |
$cptsel=$param["cptsel"]; |
638 |
$error = $param["error"]; |
639 |
echo "<table cellpadding=\"0\" class=\"formEntete ui-corner-all\">\n"; |
640 |
// |
641 |
if ($error !== false){ |
642 |
$this->f->displayMessage("error", $error); |
643 |
} |
644 |
echo "<tr><td colspan=\"2\">"; |
645 |
// |
646 |
echo "<fieldset class=\"cadre ui-corner-all ui-widget-content\">\n"; |
647 |
// |
648 |
echo "\t<legend class=\"ui-corner-all ui-widget-content ui-state-active\">"; |
649 |
echo _("Criteres de la requete"); |
650 |
echo "</legend>\n"; |
651 |
// |
652 |
echo "<table>"; |
653 |
// On separe tous les champs entre crochets dans la requête |
654 |
$temp = explode ("[", $reqmo["sql"]); |
655 |
// |
656 |
for ($i = 1; $i < sizeof($temp); $i++) { |
657 |
// On vire le crochet de la fin |
658 |
$temp1 = explode("]", $temp[$i]); |
659 |
// On check si alias |
660 |
$temp4 = explode (" as ", $temp1[0]); |
661 |
if (isset($temp4[1])) { |
662 |
$temp1[0] = $temp4[1]; |
663 |
} |
664 |
// |
665 |
$temp6 = $temp1[0]; |
666 |
|
667 |
if (!isset($reqmo[$temp1[0]])) { |
668 |
// saisie criteres where |
669 |
// |
670 |
if ($cpts == 0) { |
671 |
echo "<tr>\n"; |
672 |
} elseif ($cpts == 4) { |
673 |
echo "</tr>\n<tr>\n"; |
674 |
$cpts = 0; |
675 |
} |
676 |
// |
677 |
echo "\t<td class=\"tri\">"; |
678 |
echo " "._($temp6)." <input type=\"text\" name=\"".$temp1[0]."\" value=\"\" size=\"30\" class=\"champFormulaire\" />"; |
679 |
echo "</td>\n"; |
680 |
// |
681 |
$cpts++; |
682 |
} else { |
683 |
// |
684 |
|
685 |
if ($reqmo[$temp1[0]] == "checked") { |
686 |
// |
687 |
if ($cptemp == 0) { |
688 |
echo "<tr>\n"; |
689 |
echo "\t<td colspan=\"4\"><b>"; |
690 |
echo _("Choix des champs a afficher"); |
691 |
echo "</b></td>\n"; |
692 |
echo "</tr>\n<tr>\n"; |
693 |
} elseif ($cptemp == 4) { |
694 |
echo "</tr>\n<tr>\n"; |
695 |
$cptemp = 0; |
696 |
} |
697 |
// |
698 |
echo "\t<td colspan='2' class='champs'>"; |
699 |
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\"":"")." />"; |
700 |
echo " "._($temp6)." "; |
701 |
echo "</td>\n"; |
702 |
// |
703 |
$cptemp++; |
704 |
} else { |
705 |
// |
706 |
$temp3 = ""; |
707 |
$temp3 = $reqmo[$temp1[0]]; |
708 |
if(!is_array($temp3)) { |
709 |
$temp3 = substr($temp3, 0, 6); |
710 |
} |
711 |
// |
712 |
if ($temp3 == "select") { |
713 |
// |
714 |
if ($cptsel == 0) { |
715 |
echo "</tr><tr>\n"; |
716 |
echo "\t<td colspan=\"4\"><b>"; |
717 |
echo _("Choix des criteres de tri"); |
718 |
echo "</b></td>\n"; |
719 |
echo "</tr>\n"; |
720 |
} elseif ($cptsel == 4) { |
721 |
echo "</tr>\n<tr>\n"; |
722 |
$cptsel = 0; |
723 |
} |
724 |
// |
725 |
echo "\t<td class=\"tri\">"; |
726 |
echo _($temp6)." "; |
727 |
echo "<select name=\"".$temp1[0]."\" class=\"champFormulaire\">"; |
728 |
$res1 = $db->query($reqmo[$temp1[0]]); |
729 |
$f->isDatabaseError($res1); |
730 |
while ($row1 =& $res1->fetchRow()) { |
731 |
echo "<option value=\"".$row1[0]."\" ".(($this->f->get_submitted_post_value($temp1[0])==$row1[0])?"selected=\"selected\"":"").">".$row1[1]."</option>"; |
732 |
} |
733 |
echo "</select>"; |
734 |
echo "</td>\n"; |
735 |
// |
736 |
$cptsel++; |
737 |
} |
738 |
//Si un tableau est fourni |
739 |
elseif(is_array($temp3)) { |
740 |
// |
741 |
if ($cptsel == 0) { |
742 |
echo "</tr><tr>\n"; |
743 |
echo "\t<td colspan=\"4\"><b>"; |
744 |
echo _("Choix des criteres de tri"); |
745 |
echo "</b></td>\n"; |
746 |
echo "</tr><tr>\n"; |
747 |
} elseif ($cptsel == 4) { |
748 |
echo "</tr>\n<tr>\n"; |
749 |
$cptsel = 0; |
750 |
} |
751 |
// |
752 |
echo "\t<td class=\"tri\">"; |
753 |
echo _($temp6)." "; |
754 |
echo "<select name=\"".$temp1[0]."\" class=\"champFormulaire\">"; |
755 |
foreach ($reqmo [$temp1 [0]] as $elem) { |
756 |
echo "<option value='".$elem."' ".(($this->f->get_submitted_post_value($temp1[0])==$elem)?"selected='selected'":"").">"._($elem)."</option>"; |
757 |
} |
758 |
echo "</select>"; |
759 |
echo "</td>\n"; |
760 |
// |
761 |
$cptsel++; |
762 |
} |
763 |
// Si un input est fourni |
764 |
else { |
765 |
// |
766 |
if ($cptsel == 0) { |
767 |
echo "</tr><tr>\n"; |
768 |
echo "\t<td colspan=\"4\"><b>"; |
769 |
echo _("Choix des criteres de tri"); |
770 |
echo "</b></td>\n"; |
771 |
echo "</tr><tr>\n"; |
772 |
} elseif ($cptsel == 4) { |
773 |
echo "</tr>\n<tr>\n"; |
774 |
$cptsel = 0; |
775 |
} |
776 |
// |
777 |
echo "\t<td class=\"tri\">"; |
778 |
echo _($temp6)." "; |
779 |
echo "<input type=\"text\" name=\""._($temp6)."\" placeholder=\"".$reqmo[$temp6]."\" value=\"".$this->f->get_submitted_post_value($temp1[0])."\" size=\"10\" class=\"champFormulaire\" />"; |
780 |
echo "</td>\n"; |
781 |
// |
782 |
$cptsel++; |
783 |
} |
784 |
} |
785 |
} |
786 |
// re initialisation |
787 |
$temp1[0] = ""; |
788 |
} |
789 |
echo "</tr>"; |
790 |
echo "</table>"; |
791 |
// |
792 |
echo "</fieldset>\n"; |
793 |
// |
794 |
//echo "<table>\n"; |
795 |
// |
796 |
echo "<tr><td colspan=\"2\">"; |
797 |
// |
798 |
echo "<fieldset class=\"cadre ui-corner-all ui-widget-content\">\n"; |
799 |
// |
800 |
echo "\t<legend class=\"ui-corner-all ui-widget-content ui-state-active\">"; |
801 |
echo _("Parametres de sortie"); |
802 |
echo "</legend>\n"; |
803 |
// |
804 |
echo "<table>"; |
805 |
// |
806 |
echo "<tr>"; |
807 |
// |
808 |
echo "<td class=\"params\">"._("Choix du format de sortie")." "; |
809 |
echo "<select name=\"sortie\" class=\"champFormulaire\">"; |
810 |
echo "<option value=\"tableau\" ".(($this->f->get_submitted_post_value('sortie')=="tableau")?"selected='selected'":"").">"._("Tableau - Affichage a l'ecran")."</option>"; |
811 |
echo "<option value=\"csv\" ".(($this->f->get_submitted_post_value('sortie')=="csv")?"selected='selected'":"").">"._("CSV - Export vers logiciel tableur")."</option>"; |
812 |
|
813 |
if(isset($reqmo["om_sousetat"]) AND $reqmo["om_sousetat"] != "") { |
814 |
echo "<option value=\"pdf\" ".(($this->f->get_submitted_post_value('sortie')=="pdf")?"selected='selected'":"").">"._("PDF - Version imprimable")."</option>"; |
815 |
} |
816 |
echo "</select>"; |
817 |
echo "</td>"; |
818 |
// |
819 |
echo "</tr>"; |
820 |
echo "<tr>"; |
821 |
// |
822 |
echo "<td class=\"params\">"._("Separateur de champs (pour le format CSV)")." "; |
823 |
echo "<select name=\"separateur\" class=\"champFormulaire\">"; |
824 |
echo "<option ".(($this->f->get_submitted_post_value('separateur')==";")?"selected='selected'":"").">;</option>"; |
825 |
echo "<option ".(($this->f->get_submitted_post_value('separateur')=="|")?"selected='selected'":"").">|</option>"; |
826 |
echo "<option ".(($this->f->get_submitted_post_value('separateur')==",")?"selected='selected'":"").">,</option>"; |
827 |
echo "</select>"; |
828 |
echo "</td>"; |
829 |
// |
830 |
echo "</tr>"; |
831 |
echo "<tr>"; |
832 |
// |
833 |
echo "<td class=\"params\" >"._("Nombre limite d'enregistrements a afficher (pour le format Tableau)")." "; |
834 |
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\" />"; |
835 |
echo "</td>"; |
836 |
echo "</tr>"; |
837 |
echo "</table>"; |
838 |
// |
839 |
echo "</fieldset>\n"; |
840 |
// |
841 |
echo "</td></tr>\n"; |
842 |
// Fermeture de la balise table |
843 |
echo "</table>\n"; |
844 |
} |
845 |
|
846 |
/** |
847 |
* Test si la valeur passée en argument est du type attendu |
848 |
* @param type $valeur Valeur à tester |
849 |
* @param type $type Type attendu de la donnée |
850 |
*/ |
851 |
function hasType($valeur, $type){ |
852 |
|
853 |
switch ($type){ |
854 |
case 'date' : |
855 |
$d = DateTime::createFromFormat('d/m/Y', $valeur); |
856 |
return $d && $d->format('d/m/Y') == $valeur; |
857 |
case 'integer' : |
858 |
return is_numeric($valeur); |
859 |
case 'string' : |
860 |
return is_string($valeur); |
861 |
default : |
862 |
return false; |
863 |
} |
864 |
} |
865 |
|
866 |
}// fin classe |
867 |
?> |