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) || |
330 |
substr($reqmo['sql'], $i, 1)==chr(10) || |
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 |
$qres = $this->f->get_all_results_from_db_query( |
386 |
$this->reqmo['sql'], |
387 |
array( |
388 |
"origin" => __METHOD__, |
389 |
"get_columns_name" => true, |
390 |
"mode" => DB_FETCHMODE_ORDERED |
391 |
) |
392 |
); |
393 |
|
394 |
$this->info = $qres['columns_name']; |
395 |
// |
396 |
echo " "; |
397 |
$param['class']="tab"; |
398 |
$param['idcolumntoggle']="requeteur"; |
399 |
$this->f->layout->display_table_start($param); |
400 |
//echo "<table class=\"tab-tab\">\n"; |
401 |
// |
402 |
echo "<thead><tr class=\"ui-tabs-nav ui-accordion ui-state-default tab-title\">"; |
403 |
$key=0; |
404 |
foreach($this->info as $elem) { |
405 |
$param = array( |
406 |
"key" => $key, |
407 |
"info" => $this->info |
408 |
); |
409 |
$this->f->layout->display_table_cellule_entete_colonnes($param); |
410 |
echo "<center>".__($elem)."</center></th>"; |
411 |
$key=$key+1; |
412 |
} |
413 |
echo "</tr></thead>\n"; |
414 |
// |
415 |
$cptenr = 0; |
416 |
foreach($qres['result'] as $row) { |
417 |
// |
418 |
echo "<tr class=\"tab-data ".($cptenr % 2 == 0 ? "odd" : "even")."\">\n"; |
419 |
// |
420 |
$cptenr = $cptenr + 1; |
421 |
$i = 0; |
422 |
foreach ($row as $elem) { |
423 |
if (is_numeric($elem)) { |
424 |
echo "<td class='resultrequete' align='right'>"; |
425 |
} else { |
426 |
echo "<td class='resultrequete'>"; |
427 |
} |
428 |
$tmp=""; |
429 |
$tmp=str_replace(chr(13).chr(10), '<br>', $elem); |
430 |
echo $tmp."</td>"; |
431 |
$i++; |
432 |
} |
433 |
echo "</tr>\n"; |
434 |
} |
435 |
// |
436 |
echo "</tbody></table>\n"; |
437 |
if ($cptenr==0){ |
438 |
echo "<br>".__('aucun')." ".__('enregistrement')."<br>"; |
439 |
} |
440 |
$this->displayBoutonRetour($url); |
441 |
} |
442 |
|
443 |
function displayCSV($separateur, $url = "requeteur.php") { |
444 |
|
445 |
// execution de la requete |
446 |
$qres = $this->f->get_all_results_from_db_query( |
447 |
$this->reqmo['sql'], |
448 |
array( |
449 |
"origin" => __METHOD__, |
450 |
"get_columns_name" => true, |
451 |
"mode" => DB_FETCHMODE_ORDERED |
452 |
) |
453 |
); |
454 |
$this->info = $qres['columns_name']; |
455 |
$inf=""; |
456 |
foreach ($this->info as $elem) { |
457 |
$inf=$inf.$elem.$separateur; |
458 |
} |
459 |
$inf .= "\n"; |
460 |
$cptenr=0; |
461 |
foreach($qres['result'] as $row) { |
462 |
$cptenr=$cptenr+1; |
463 |
$i=0; |
464 |
foreach($row as $elem) { |
465 |
//**** |
466 |
$tmp=""; |
467 |
$tmp=str_replace(chr(13).chr(10), ' / ', $elem); |
468 |
$tmp=str_replace(';', ' ', $tmp); |
469 |
//***** |
470 |
$inf .= '"'.$tmp.'"'.$separateur; |
471 |
$i++; |
472 |
} |
473 |
$inf .= "\n"; |
474 |
} |
475 |
if ($cptenr==0){ |
476 |
$inf .="\n".__('aucun')." ".__('enregistrement')."\n"; |
477 |
} |
478 |
|
479 |
/** |
480 |
* Écriture de l'export dans un fichier sur le disque et affichage du |
481 |
* lien de téléchargement. |
482 |
*/ |
483 |
// Composition du nom du fichier |
484 |
$nom_fichier = "export_".$this->obj.".csv"; |
485 |
// Composition des métadonnées du fichier |
486 |
$metadata_fichier = array( |
487 |
"filename" => $nom_fichier, |
488 |
"size" => strlen($inf), |
489 |
"mimetype" => "text/csv", |
490 |
); |
491 |
// Écriture du fichier |
492 |
$uid_fichier = $this->f->storage->create_temporary($inf, $metadata_fichier); |
493 |
// |
494 |
echo __("Le fichier a ete exporte, vous pouvez l'ouvrir immediatement en cliquant sur : "); |
495 |
$msg = "<a class=\"om-prev-icon trace-16\" href=\"../app/index.php?module=form&snippet=file&uid=".$uid_fichier."&mode=temporary\" target=\"_blank\">"; |
496 |
$msg .= __("Telecharger le fichier")." [".$nom_fichier."]"; |
497 |
$msg .= "</a>"; |
498 |
// |
499 |
$param['lien']=$msg; |
500 |
$this->f->layout->display_lien($param); |
501 |
$msg .= "<br />"; |
502 |
$this->displayBoutonRetour($url); |
503 |
} |
504 |
|
505 |
function displayPDF($url = "requeteur.php") { |
506 |
require_once PATH_OPENMAIRIE."fpdf_etat.php"; |
507 |
$pdf = new PDF($this->reqmo['om_sousetat_orientation'], "mm", $this->reqmo['om_sousetat_format'], |
508 |
true, |
509 |
'UTF-8'); |
510 |
$pdf->setPrintHeader(false); |
511 |
// Affichage de la mention Page X/X en pied de page |
512 |
$pdf->startPageGroup(); |
513 |
$pdf->set_footer(array( |
514 |
"offset" => 12, |
515 |
"html" => sprintf( |
516 |
'<p style="text-align:center;font-size:8pt;"><em>Page %s/%s</em></p>', |
517 |
$pdf->getPageNumGroupAlias(), |
518 |
$pdf->getPageGroupAlias() |
519 |
), |
520 |
)); |
521 |
// Ajoute une nouvelle page à l'édition |
522 |
$pdf->AddPage(); |
523 |
// On récupère l'enregistrement 'om_sousetat' de la collectivité en cours dans |
524 |
// l'état 'actif' |
525 |
$niveau = $_SESSION['niveau']; |
526 |
$sql = sprintf( |
527 |
'SELECT |
528 |
* |
529 |
FROM |
530 |
%1$som_sousetat |
531 |
WHERE |
532 |
id = \'%2$s\' |
533 |
AND actif IS TRUE |
534 |
AND om_collectivite = \'%3$d\'', |
535 |
DB_PREFIXE, |
536 |
$this->f->db->escapeSimple($this->reqmo["om_sousetat"]), |
537 |
intval($_SESSION['collectivite']) |
538 |
); |
539 |
$qres2 = $this->f->get_all_results_from_db_query( |
540 |
$sql, |
541 |
array( |
542 |
'origin' => __METHOD__ |
543 |
) |
544 |
); |
545 |
// Si on obtient aucun résultat |
546 |
if ($qres2['row_count'] == 0) { |
547 |
// |
548 |
if ($niveau == "") { |
549 |
// On récupère l'identifiant de la collectivité de niveau 2 |
550 |
$qres = $this->f->get_one_result_from_db_query( |
551 |
sprintf( |
552 |
'SELECT |
553 |
om_collectivite |
554 |
FROM |
555 |
%1$som_collectivite |
556 |
WHERE |
557 |
niveau = \'2\'', |
558 |
DB_PREFIXE |
559 |
), |
560 |
array( |
561 |
"origin" => __METHOD__, |
562 |
) |
563 |
); |
564 |
$niveau = $qres["result"]; |
565 |
} |
566 |
// On récupère l'enregistrement 'om_sousetat' de la collectivité de niveau |
567 |
// 2 dans l'état 'actif' |
568 |
$sql = sprintf( |
569 |
'SELECT |
570 |
* |
571 |
FROM |
572 |
%1$som_sousetat |
573 |
WHERE |
574 |
id = \'%2$s\' |
575 |
AND actif IS TRUE |
576 |
AND om_collectivite = \'%3$d\'', |
577 |
DB_PREFIXE, |
578 |
$this->f->db->escapeSimple($this->reqmo["om_sousetat"]), |
579 |
intval($niveau) |
580 |
); |
581 |
$qres2 = $this->f->get_all_results_from_db_query( |
582 |
$sql, |
583 |
array( |
584 |
'origin' => __METHOD__ |
585 |
) |
586 |
); |
587 |
// Si on obtient aucun résultat |
588 |
if ($qres2['row_count'] == 0) { |
589 |
// On récupère l'enregistrement 'om_sousetat' de la collectivité de |
590 |
// niveau 2 dans n'importe quel état |
591 |
$sql = sprintf( |
592 |
'SELECT |
593 |
* |
594 |
FROM |
595 |
%1$som_sousetat |
596 |
WHERE |
597 |
id = \'%2$s\' |
598 |
AND om_collectivite = \'%3$d\'', |
599 |
DB_PREFIXE, |
600 |
$this->f->db->escapeSimple($this->reqmo["om_sousetat"]), |
601 |
intval($niveau) |
602 |
); |
603 |
$qres2 = $this->f->get_all_results_from_db_query( |
604 |
$sql, |
605 |
array( |
606 |
'origin' => __METHOD__ |
607 |
) |
608 |
); |
609 |
} |
610 |
} |
611 |
|
612 |
// |
613 |
foreach($qres2['result'] as $sousetat) { |
614 |
$idx = ""; |
615 |
$_GET['idx'] = ""; |
616 |
// |
617 |
$titre = ''; |
618 |
$titre = $sousetat['titre']; |
619 |
$titre = str_replace("&aujourdhui", date('d/m/Y'), $titre); |
620 |
$collectivite = isset($collectivite)&&$collectivite != array()? |
621 |
$collectivite: |
622 |
$this->f->getCollectivite(); |
623 |
if (isset($collectivite) && $collectivite != array()) { |
624 |
// |
625 |
foreach (array_keys($collectivite) as $elem) { |
626 |
// |
627 |
if (is_array($collectivite[$elem]) === false) { |
628 |
$temp = "&".$elem; |
629 |
$titre = str_replace($temp, $collectivite[$elem], $titre); |
630 |
$sql = str_replace($temp, $collectivite[$elem], $sql); |
631 |
if ( strstr($elem, "ged_") === false && strstr($elem, "erp_") === false |
632 |
&& strstr($elem, "id_") === false && strstr($elem, "sig_") === false |
633 |
&& strstr($elem, "option_") === false ) { |
634 |
$champs_remplacement_etat[] = "&".$elem; |
635 |
} |
636 |
} |
637 |
} |
638 |
} |
639 |
//Date au format jour_de_la_semaine jour_du_mois mois_de_l'année |
640 |
//Ex. Lundi 12 Mars |
641 |
$jourSemaine = array(__('Dimanche'),__('Lundi'),__('Mardi'),__('Mercredi'),__('Jeudi'), |
642 |
__('Vendredi'),_('Samedi')); |
643 |
$moisAnnee = array(__('Janvier'),__('Fevrier'),_('Mars'),__('Avril'),__('Mai'), |
644 |
__('Juin'),__('Juillet'),__('Aout'),__('Septembre'),__('Octobre'),__('Novembre') |
645 |
,__('Decembre')); |
646 |
$titre=str_replace("&jourSemaine",$jourSemaine[date('w')]." ".date('d')." ".$moisAnnee[date('n')-1]." ".date('Y'),$titre); |
647 |
$sousetat['titre'] = $titre; |
648 |
$sousetat['om_sql'] = $this->reqmo['sql']; |
649 |
// imprime les colonnes de la requete |
650 |
$edition = array( |
651 |
'se_font' => 'helvetica', |
652 |
'se_couleurtexte' => array(0,0,0) |
653 |
); |
654 |
$pdf->sousetatdb($this->f->db, $edition, $sousetat); |
655 |
} |
656 |
|
657 |
// Construction du nom du fichier |
658 |
$filename = date("Ymd-His"); |
659 |
$filename .= "-reqmo"; |
660 |
$filename .= "-".$this->obj; |
661 |
$filename .= ".pdf"; |
662 |
$contenu = $pdf->Output($filename, "S"); |
663 |
|
664 |
// Métadonnées du fichier csv résultat |
665 |
$metadata['filename'] = $filename; |
666 |
$metadata['size'] = strlen($contenu); |
667 |
$metadata['mimetype'] = "application/pdf"; |
668 |
// Création du fichier sur le storage temporaire |
669 |
$pdf_res_uid = $this->f->storage->create_temporary($contenu, $metadata); |
670 |
// Affichage du message d'erreur ou de validation |
671 |
if($pdf_res_uid === "OP_FAILURE" ){ |
672 |
$this->f->addToMessage("error", __("Erreur de configuration. Contactez votre administrateur.")); |
673 |
} else { |
674 |
$msg = __("Le fichier a ete exporte, vous pouvez l'ouvrir immediatement en cliquant sur : "); |
675 |
$msg .= "<a class='bold' target='_blanc' href=\"../app/index.php?module=form&snippet=file&uid=".$pdf_res_uid."&mode=temporary\">"; |
676 |
$msg .= __("Telecharger le fichier")." [".$filename."]"; |
677 |
$msg .= "</a>"; |
678 |
$this->f->addToMessage("ok", $msg); |
679 |
} |
680 |
$this->f->displayMessages(); |
681 |
// |
682 |
echo "<br />"; |
683 |
$this->displayBoutonRetour($url); |
684 |
} |
685 |
|
686 |
public function display_requeteur_formulaire($param,$f) { |
687 |
// |
688 |
// requeteur formulaire |
689 |
// |
690 |
$db=$param["db"]; |
691 |
$extension = $param["extension"]; |
692 |
if (file_exists ("../sql/".OM_DB_PHPTYPE."/".$this->obj.".".$extension.".inc.php")) { |
693 |
include ("../sql/".OM_DB_PHPTYPE."/".$this->obj.".".$extension.".inc.php"); |
694 |
} |
695 |
elseif (file_exists ("../sql/".OM_DB_PHPTYPE."/".$this->obj.".".$extension.".inc")) { |
696 |
include ("../sql/".OM_DB_PHPTYPE."/".$this->obj.".".$extension.".inc"); |
697 |
} |
698 |
$validation = $param["validation"]; |
699 |
$cptemp = $param["cptemp"]; |
700 |
$cpts=$param["cpts"]; |
701 |
$cptsel=$param["cptsel"]; |
702 |
$error = $param["error"]; |
703 |
echo "<table cellpadding=\"0\" class=\"formEntete ui-corner-all\">\n"; |
704 |
// |
705 |
if ($error !== false){ |
706 |
$this->f->displayMessage("error", $error); |
707 |
} |
708 |
echo "<tr><td colspan=\"2\">"; |
709 |
// |
710 |
echo "<fieldset class=\"cadre ui-corner-all ui-widget-content\">\n"; |
711 |
// |
712 |
echo "\t<legend class=\"ui-corner-all ui-widget-content ui-state-active\">"; |
713 |
echo __("Criteres de la requete"); |
714 |
echo "</legend>\n"; |
715 |
// |
716 |
echo "<table>"; |
717 |
// On separe tous les champs entre crochets dans la requête |
718 |
$temp = explode ("[", $reqmo["sql"]); |
719 |
// |
720 |
for ($i = 1; $i < sizeof($temp); $i++) { |
721 |
// On vire le crochet de la fin |
722 |
$temp1 = explode("]", $temp[$i]); |
723 |
// On check si alias |
724 |
$temp4 = explode (" as ", $temp1[0]); |
725 |
if (isset($temp4[1])) { |
726 |
$temp1[0] = $temp4[1]; |
727 |
} |
728 |
// |
729 |
$temp6 = $temp1[0]; |
730 |
|
731 |
if (!isset($reqmo[$temp1[0]])) { |
732 |
// saisie criteres where |
733 |
// |
734 |
if ($cpts == 0) { |
735 |
echo "<tr>\n"; |
736 |
} elseif ($cpts == 4) { |
737 |
echo "</tr>\n<tr>\n"; |
738 |
$cpts = 0; |
739 |
} |
740 |
// |
741 |
echo "\t<td class=\"tri\">"; |
742 |
echo " ".__($temp6)." <input type=\"text\" name=\"".$temp1[0]."\" value=\"\" size=\"30\" class=\"champFormulaire\" />"; |
743 |
echo "</td>\n"; |
744 |
// |
745 |
$cpts++; |
746 |
} else { |
747 |
// |
748 |
|
749 |
if ($reqmo[$temp1[0]] == "checked") { |
750 |
// |
751 |
if ($cptemp == 0) { |
752 |
echo "<tr>\n"; |
753 |
echo "\t<td colspan=\"4\"><b>"; |
754 |
echo __("Choix des champs a afficher"); |
755 |
echo "</b></td>\n"; |
756 |
echo "</tr>\n<tr>\n"; |
757 |
} elseif ($cptemp == 4) { |
758 |
echo "</tr>\n<tr>\n"; |
759 |
$cptemp = 0; |
760 |
} |
761 |
// |
762 |
echo "\t<td colspan='2' class='champs'>"; |
763 |
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\"":"")." />"; |
764 |
echo " ".__($temp6)." "; |
765 |
echo "</td>\n"; |
766 |
// |
767 |
$cptemp++; |
768 |
} else { |
769 |
// |
770 |
$temp3 = ""; |
771 |
$temp3 = $reqmo[$temp1[0]]; |
772 |
if(!is_array($temp3)) { |
773 |
$temp3 = substr($temp3, 0, 6); |
774 |
} |
775 |
// |
776 |
if ($temp3 == "select") { |
777 |
// |
778 |
if ($cptsel == 0) { |
779 |
echo "</tr><tr>\n"; |
780 |
echo "\t<td colspan=\"4\"><b>"; |
781 |
echo __("Choix des criteres de tri"); |
782 |
echo "</b></td>\n"; |
783 |
echo "</tr>\n"; |
784 |
} elseif ($cptsel == 4) { |
785 |
echo "</tr>\n<tr>\n"; |
786 |
$cptsel = 0; |
787 |
} |
788 |
// |
789 |
echo "\t<td class=\"tri\">"; |
790 |
echo __($temp6)." "; |
791 |
echo "<select name=\"".$temp1[0]."\" class=\"champFormulaire\">"; |
792 |
$qres1 = $this->f->get_all_results_from_db_query( |
793 |
$reqmo[$temp1[0]], |
794 |
array( |
795 |
'origin' => __METHOD__, |
796 |
'mode' => DB_FETCHMODE_ORDERED |
797 |
) |
798 |
); |
799 |
foreach($qres1['result'] as $row1) { |
800 |
echo "<option value=\"".$row1[0]."\" ".(($this->f->get_submitted_post_value($temp1[0])==$row1[0])?"selected=\"selected\"":"").">".$row1[1]."</option>"; |
801 |
} |
802 |
echo "</select>"; |
803 |
echo "</td>\n"; |
804 |
// |
805 |
$cptsel++; |
806 |
} |
807 |
//Si un tableau est fourni |
808 |
elseif(is_array($temp3)) { |
809 |
// |
810 |
if ($cptsel == 0) { |
811 |
echo "</tr><tr>\n"; |
812 |
echo "\t<td colspan=\"4\"><b>"; |
813 |
echo __("Choix des criteres de tri"); |
814 |
echo "</b></td>\n"; |
815 |
echo "</tr><tr>\n"; |
816 |
} elseif ($cptsel == 4) { |
817 |
echo "</tr>\n<tr>\n"; |
818 |
$cptsel = 0; |
819 |
} |
820 |
// |
821 |
echo "\t<td class=\"tri\">"; |
822 |
echo __($temp6)." "; |
823 |
echo "<select name=\"".$temp1[0]."\" class=\"champFormulaire\">"; |
824 |
foreach ($reqmo [$temp1 [0]] as $elem) { |
825 |
echo "<option value='".$elem."' ".(($this->f->get_submitted_post_value($temp1[0])==$elem)?"selected='selected'":"").">".__($elem)."</option>"; |
826 |
} |
827 |
echo "</select>"; |
828 |
echo "</td>\n"; |
829 |
// |
830 |
$cptsel++; |
831 |
} |
832 |
// Si un input est fourni |
833 |
else { |
834 |
// |
835 |
if ($cptsel == 0) { |
836 |
echo "</tr><tr>\n"; |
837 |
echo "\t<td colspan=\"4\"><b>"; |
838 |
echo __("Choix des criteres de tri"); |
839 |
echo "</b></td>\n"; |
840 |
echo "</tr><tr>\n"; |
841 |
} elseif ($cptsel == 4) { |
842 |
echo "</tr>\n<tr>\n"; |
843 |
$cptsel = 0; |
844 |
} |
845 |
// |
846 |
echo "\t<td class=\"tri\">"; |
847 |
echo __($temp6)." "; |
848 |
echo "<input type=\"text\" name=\"".__($temp6)."\" placeholder=\"".$reqmo[$temp6]."\" value=\"".$this->f->get_submitted_post_value($temp1[0])."\" size=\"10\" class=\"champFormulaire\" />"; |
849 |
echo "</td>\n"; |
850 |
// |
851 |
$cptsel++; |
852 |
} |
853 |
} |
854 |
} |
855 |
// re initialisation |
856 |
$temp1[0] = ""; |
857 |
} |
858 |
echo "</tr>"; |
859 |
echo "</table>"; |
860 |
// |
861 |
echo "</fieldset>\n"; |
862 |
// |
863 |
//echo "<table>\n"; |
864 |
// |
865 |
echo "<tr><td colspan=\"2\">"; |
866 |
// |
867 |
echo "<fieldset class=\"cadre ui-corner-all ui-widget-content\">\n"; |
868 |
// |
869 |
echo "\t<legend class=\"ui-corner-all ui-widget-content ui-state-active\">"; |
870 |
echo __("Parametres de sortie"); |
871 |
echo "</legend>\n"; |
872 |
// |
873 |
echo "<table>"; |
874 |
// |
875 |
echo "<tr>"; |
876 |
// |
877 |
echo "<td class=\"params\">".__("Choix du format de sortie")." "; |
878 |
echo "<select name=\"sortie\" class=\"champFormulaire\">"; |
879 |
echo "<option value=\"tableau\" ".(($this->f->get_submitted_post_value('sortie')=="tableau")?"selected='selected'":"").">".__("Tableau - Affichage a l'ecran")."</option>"; |
880 |
echo "<option value=\"csv\" ".(($this->f->get_submitted_post_value('sortie')=="csv")?"selected='selected'":"").">".__("CSV - Export vers logiciel tableur")."</option>"; |
881 |
|
882 |
if(isset($reqmo["om_sousetat"]) && $reqmo["om_sousetat"] != "") { |
883 |
echo "<option value=\"pdf\" ".(($this->f->get_submitted_post_value('sortie')=="pdf")?"selected='selected'":"").">".__("PDF - Version imprimable")."</option>"; |
884 |
} |
885 |
echo "</select>"; |
886 |
echo "</td>"; |
887 |
// |
888 |
echo "</tr>"; |
889 |
echo "<tr>"; |
890 |
// |
891 |
echo "<td class=\"params\">".__("Separateur de champs (pour le format CSV)")." "; |
892 |
echo "<select name=\"separateur\" class=\"champFormulaire\">"; |
893 |
echo "<option ".(($this->f->get_submitted_post_value('separateur')==";")?"selected='selected'":"").">;</option>"; |
894 |
echo "<option ".(($this->f->get_submitted_post_value('separateur')=="|")?"selected='selected'":"").">|</option>"; |
895 |
echo "<option ".(($this->f->get_submitted_post_value('separateur')==",")?"selected='selected'":"").">,</option>"; |
896 |
echo "</select>"; |
897 |
echo "</td>"; |
898 |
// |
899 |
echo "</tr>"; |
900 |
echo "<tr>"; |
901 |
// |
902 |
echo "<td class=\"params\" >".__("Nombre limite d'enregistrements a afficher (pour le format Tableau)")." "; |
903 |
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\" />"; |
904 |
echo "</td>"; |
905 |
echo "</tr>"; |
906 |
echo "</table>"; |
907 |
// |
908 |
echo "</fieldset>\n"; |
909 |
// |
910 |
echo "</td></tr>\n"; |
911 |
// Fermeture de la balise table |
912 |
echo "</table>\n"; |
913 |
} |
914 |
|
915 |
/** |
916 |
* Test si la valeur passée en argument est du type attendu |
917 |
* @param type $valeur Valeur à tester |
918 |
* @param type $type Type attendu de la donnée |
919 |
*/ |
920 |
function hasType($valeur, $type){ |
921 |
|
922 |
switch ($type){ |
923 |
case 'date' : |
924 |
$d = DateTime::createFromFormat('d/m/Y', $valeur); |
925 |
return $d && $d->format('d/m/Y') == $valeur; |
926 |
case 'integer' : |
927 |
return is_numeric($valeur); |
928 |
case 'string' : |
929 |
return is_string($valeur); |
930 |
default : |
931 |
return false; |
932 |
} |
933 |
} |
934 |
|
935 |
} |
936 |
|
937 |
|