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