1 |
<?php |
2 |
//$Id: rapport_instruction.class.php 6046 2016-02-26 15:27:06Z fmichon $ |
3 |
//gen openMairie le 07/01/2013 15:28 |
4 |
|
5 |
require_once ("../gen/obj/rapport_instruction.class.php"); |
6 |
|
7 |
class rapport_instruction extends rapport_instruction_gen { |
8 |
|
9 |
var $metadata = array( |
10 |
"om_fichier_rapport_instruction" => array( |
11 |
"dossier" => "getDossier", |
12 |
"dossier_version" => "getDossierVersion", |
13 |
"numDemandeAutor" => "getNumDemandeAutor", |
14 |
"anneemoisDemandeAutor" => "getAnneemoisDemandeAutor", |
15 |
"typeInstruction" => "getTypeInstruction", |
16 |
"statutAutorisation" => "getStatutAutorisation", |
17 |
"typeAutorisation" => "getTypeAutorisation", |
18 |
"dateEvenementDocument" => "getDateEvenementDocument", |
19 |
"groupeInstruction" => 'getGroupeInstruction', |
20 |
"title" => 'getTitle', |
21 |
), |
22 |
); |
23 |
|
24 |
var $abstract_type = array( |
25 |
"om_fichier_rapport_instruction" => "file", |
26 |
); |
27 |
|
28 |
/** @var boolean Les nouvelles actions sont activées sur cet objet */ |
29 |
var $activate_class_action; |
30 |
|
31 |
/** |
32 |
* Instance de la classe dossier |
33 |
* |
34 |
* @var mixed |
35 |
*/ |
36 |
var $inst_dossier = null; |
37 |
|
38 |
function rapport_instruction($id,&$db,$debug) { |
39 |
//On active les nouvelles actions |
40 |
$this->activate_class_action = true; |
41 |
$this->constructeur($id,$db,$debug); |
42 |
}// fin constructeur |
43 |
|
44 |
/** |
45 |
* Définition des actions disponibles sur la classe. |
46 |
* |
47 |
* @return void |
48 |
*/ |
49 |
function init_class_actions() { |
50 |
|
51 |
// On récupère les actions génériques définies dans la méthode |
52 |
// d'initialisation de la classe parente |
53 |
parent::init_class_actions(); |
54 |
|
55 |
// ACTION - 001 - modifier |
56 |
// Modification du libellé de l'action "modifier" |
57 |
$this->class_actions[1]["portlet"]["libelle"] = _("Modifier"); |
58 |
$this->class_actions[1]["condition"] = array("show_rapport_instruction_finaliser_portlet_action", |
59 |
"is_editable"); |
60 |
|
61 |
// ACTION - 002 - supprimer |
62 |
// Modification de la condition d'affichage de l'action "supprimer" |
63 |
$this->class_actions[2]["condition"] = array("show_rapport_instruction_finaliser_portlet_action", |
64 |
"is_deletable"); |
65 |
|
66 |
// ACTION - 100 - edition |
67 |
// Permet d'afficher l'édition du rapport d'instruction |
68 |
$this->class_actions[100] = array( |
69 |
"identifier" => "edition", |
70 |
"portlet" => array( |
71 |
"type" => "action-blank", |
72 |
"libelle" => _("Edition"), |
73 |
"order" => 100, |
74 |
"class" => "pdf-16", |
75 |
), |
76 |
"view" => "view_edition", |
77 |
"permission_suffix" => "consulter", |
78 |
); |
79 |
|
80 |
// ACTION - 110 - finalise |
81 |
// Permet de finaliser le rapport d'instruction |
82 |
$this->class_actions[110] = array( |
83 |
"identifier" => "finalise", |
84 |
"portlet" => array( |
85 |
"type" => "action-direct", |
86 |
"libelle" => _("Finaliser le document"), |
87 |
"order" => 110, |
88 |
"class" => "finalise", |
89 |
), |
90 |
"view" => "formulaire", |
91 |
"method" => "finalize", |
92 |
"button" => "finalise", |
93 |
"permission_suffix" => "finaliser", |
94 |
"condition" => array("show_rapport_instruction_finaliser_portlet_action", |
95 |
"is_finalizable"), |
96 |
); |
97 |
|
98 |
// ACTION - 120 - definalise |
99 |
// Permet de reprendre la rédaction du rapport d'instruction |
100 |
$this->class_actions[120] = array( |
101 |
"identifier" => "definalise", |
102 |
"portlet" => array( |
103 |
"type" => "action-direct", |
104 |
"libelle" => _("Reprendre la redaction du document"), |
105 |
"order" => 120, |
106 |
"class" => "definalise", |
107 |
), |
108 |
"view" => "formulaire", |
109 |
"method" => "unfinalize", |
110 |
"button" => "definalise", |
111 |
"permission_suffix" => "definaliser", |
112 |
"condition" => array("show_unfinalize_portlet_action", |
113 |
"is_unfinalizable"), |
114 |
); |
115 |
} |
116 |
|
117 |
/** |
118 |
* CONDITION - is_editable. |
119 |
* |
120 |
* Condition pour afficher le bouton de modification. |
121 |
* |
122 |
* @return boolean |
123 |
*/ |
124 |
function is_editable() { |
125 |
|
126 |
// |
127 |
if ($this->f->can_bypass("rapport_instruction", "modifier")){ |
128 |
return true; |
129 |
} |
130 |
|
131 |
if ($this->is_dossier_instruction_not_closed()&&$this->is_instructeur_from_division()){ |
132 |
return true; |
133 |
} |
134 |
// |
135 |
return false; |
136 |
} |
137 |
|
138 |
/** |
139 |
* CONDITION - is_deletable. |
140 |
* |
141 |
* Condition pour afficher le bouton de suppression. |
142 |
* |
143 |
* @return boolean |
144 |
*/ |
145 |
function is_deletable() { |
146 |
|
147 |
if ($this->f->can_bypass("rapport_instruction", "supprimer")){ |
148 |
return true; |
149 |
} |
150 |
|
151 |
if ($this->is_dossier_instruction_not_closed()&&$this->is_instructeur_from_division()){ |
152 |
return true; |
153 |
} |
154 |
|
155 |
return false; |
156 |
} |
157 |
|
158 |
/** |
159 |
* CONDITION - is_finalizable. |
160 |
* |
161 |
* Condition pour afficher le bouton de finalisation. |
162 |
* |
163 |
* @return boolean |
164 |
*/ |
165 |
function is_finalizable() { |
166 |
|
167 |
if($this->f->can_bypass("rapport_instruction", "finaliser")){ |
168 |
return true; |
169 |
} |
170 |
|
171 |
if ($this->is_instructeur_from_division() && $this->is_dossier_instruction_not_closed()){ |
172 |
return true; |
173 |
} |
174 |
|
175 |
return false; |
176 |
} |
177 |
|
178 |
/** |
179 |
* CONDITION - is_unfinalizable. |
180 |
* |
181 |
* Condition pour afficher le bouton de définalisation. |
182 |
* |
183 |
* @return boolean |
184 |
*/ |
185 |
function is_unfinalizable() { |
186 |
|
187 |
if($this->f->can_bypass("rapport_instruction", "definaliser")){ |
188 |
return true; |
189 |
} |
190 |
|
191 |
if ($this->is_instructeur_from_division() && $this->is_dossier_instruction_not_closed()){ |
192 |
return true; |
193 |
} |
194 |
|
195 |
return false; |
196 |
} |
197 |
|
198 |
/** |
199 |
* Permet de récupérer l'édition de la consultation. |
200 |
* |
201 |
* @param string $output type de sortie |
202 |
* |
203 |
* @return string si le type de sortie est string, le contenu du pdf est retourné. |
204 |
*/ |
205 |
function generate_edition($output) { |
206 |
|
207 |
// Variable de retour |
208 |
$return = ""; |
209 |
|
210 |
// |
211 |
$_GET["output"] = $output; |
212 |
$f = $this->f; |
213 |
// Redirection vers le script d'édition pdf avec les bons paramètres |
214 |
include "../pdf/pdfetat.php"; |
215 |
|
216 |
// retour selon le paramètre |
217 |
if($output == "string") { |
218 |
$return = $pdf_output; |
219 |
} |
220 |
|
221 |
// |
222 |
return $return; |
223 |
} |
224 |
|
225 |
/** |
226 |
* VIEW - view_edition. |
227 |
* |
228 |
* Permet de visualiser le pdf en le générant ou en le récupérant depuis |
229 |
* le système de fichier. |
230 |
* |
231 |
* @return void |
232 |
*/ |
233 |
function view_edition() { |
234 |
|
235 |
// |
236 |
if($this->getVal("om_final_rapport_instruction") == 't' |
237 |
&& $this->getVal("om_final_rapport_instruction") != null) { |
238 |
|
239 |
// |
240 |
$lien = '../spg/file.php?obj='.$this->table.'&'. |
241 |
'champ=om_fichier_rapport_instruction&id='.$this->getVal($this->clePrimaire); |
242 |
// |
243 |
header("Location: ".$lien); |
244 |
} else { |
245 |
|
246 |
// Identifiant du rapport d'instruction |
247 |
$idx = $this->getVal($this->clePrimaire); |
248 |
|
249 |
// Récupère la colelctivité du dossier d'instruction |
250 |
$dossier_instruction_om_collectivite = $this->get_dossier_instruction_om_collectivite(); |
251 |
|
252 |
// |
253 |
$collectivite = $this->f->getCollectivite($dossier_instruction_om_collectivite); |
254 |
|
255 |
// Génération du PDF |
256 |
$result = $this->compute_pdf_output('etat', $this->table, $collectivite, $idx); |
257 |
// Affichage du PDF |
258 |
$this->expose_pdf_output( |
259 |
$result['pdf_output'], |
260 |
$result['filename'] |
261 |
); |
262 |
} |
263 |
} |
264 |
|
265 |
/** |
266 |
* Récupère la collectivité du dossier d'instruction. |
267 |
* |
268 |
* @return integer |
269 |
*/ |
270 |
function get_dossier_instruction_om_collectivite() { |
271 |
|
272 |
// |
273 |
require_once "../obj/dossier_instruction.class.php"; |
274 |
$dossier_instruction = new dossier_instruction($this->getVal('dossier_instruction'), $this->f->db, false); |
275 |
|
276 |
// |
277 |
return $dossier_instruction->getVal('om_collectivite'); |
278 |
} |
279 |
|
280 |
// Modification du style de certains champs |
281 |
function setType(&$form,$maj) { |
282 |
parent::setType($form,$maj); |
283 |
|
284 |
$form->setType('dossier_instruction', 'hidden'); |
285 |
|
286 |
if( $maj < 2 ){ |
287 |
// Select pour le proposition de décision |
288 |
$form->setType('proposition_decision', 'select'); |
289 |
} |
290 |
|
291 |
// Modification |
292 |
$form->setType('dossier_libelle', 'hiddenstatic'); |
293 |
|
294 |
//Cache les champs pour la finalisation |
295 |
$form->setType('om_fichier_rapport_instruction', 'hidden'); |
296 |
$form->setType('om_final_rapport_instruction', 'hidden'); |
297 |
|
298 |
// |
299 |
if($maj == 110 || $maj == 120) { |
300 |
// |
301 |
foreach ($this->champs as $value) { |
302 |
// |
303 |
$form->setType($value, 'hidden'); |
304 |
} |
305 |
} |
306 |
} |
307 |
|
308 |
// Pré-remplir les champs |
309 |
function setValsousformulaire(&$form, $maj,$validation,$idxformulaire,$retourformulaire,$typeformulaire,&$db,$DEBUG=null) { |
310 |
|
311 |
parent::setValsousformulaire($form, $maj,$validation,$idxformulaire,$retourformulaire,$typeformulaire,$db,$DEBUG); |
312 |
|
313 |
if($maj == 0) { |
314 |
|
315 |
// Analyse réglementaire |
316 |
// Choisi par l'administrateur |
317 |
$temp_analyse_reglementaire = explode("\r",$this->f->getParameter('rapport_instruction_analyse_reglementaire')); |
318 |
$analyse_reglementaire = ""; |
319 |
foreach ($temp_analyse_reglementaire as $value) { |
320 |
$analyse_reglementaire .= "<p>".$value."</p>"; |
321 |
} |
322 |
|
323 |
$form->setVal("analyse_reglementaire_om_html",$analyse_reglementaire); |
324 |
|
325 |
// Description du projet |
326 |
// Libellé des travaux du dossier en cours |
327 |
// Création de la requête |
328 |
$sql = "SELECT dossier_libelle, |
329 |
CONCAT(donnees_techniques.am_projet_desc,' ',donnees_techniques.co_projet_desc) as libelle |
330 |
FROM |
331 |
".DB_PREFIXE."dossier |
332 |
LEFT JOIN ".DB_PREFIXE."donnees_techniques ON |
333 |
donnees_techniques.dossier_instruction = dossier.dossier |
334 |
WHERE |
335 |
dossier.dossier = '".$idxformulaire."'"; |
336 |
|
337 |
// Exécution de la requête |
338 |
$res = $db->query($sql); |
339 |
$this->f->addToLog("setVal(): db->query(\"".$sql."\");", VERBOSE_MODE); |
340 |
if ( database::isError($res)){ |
341 |
die(); |
342 |
} |
343 |
|
344 |
// Si le champ travaux est rempli |
345 |
while ($row=&$res->fetchrow(DB_FETCHMODE_ASSOC)){ |
346 |
|
347 |
if ( $row['libelle'] != "" ){ |
348 |
|
349 |
$description_projet = $row['libelle']; |
350 |
|
351 |
$form->setVal("description_projet_om_html",$description_projet); |
352 |
} |
353 |
|
354 |
// Ajout automatique du numéro de dossier d'instruction |
355 |
$form->setVal("dossier_libelle", $row['dossier_libelle']); |
356 |
} |
357 |
|
358 |
// Ajout automatique du numéro de dossier d'instruction |
359 |
$form->setVal("dossier_instruction",$idxformulaire); |
360 |
} |
361 |
} |
362 |
|
363 |
/* |
364 |
* Select pour le proposition_decision |
365 |
*/ |
366 |
function setSelect(&$form, $maj,&$db,$debug) { |
367 |
|
368 |
// Lors d'un ajout ou d'une modification |
369 |
if( $maj < 2 ){ |
370 |
|
371 |
// proposition_decision |
372 |
$contenu=array(); |
373 |
|
374 |
$k = 0; |
375 |
$contenu[0][$k]=""; |
376 |
$contenu[1][$k++]=_('choisir')." "._('proposition_decision'); |
377 |
|
378 |
// Si le paramètre existe et a été remplie |
379 |
if ( !is_null($this->f->getParameter('rapport_instruction_proposition_decision'))){ |
380 |
|
381 |
$donnees = $this->f->getParameter('rapport_instruction_proposition_decision'); |
382 |
$donnees = explode('<br />', nl2br(htmlentities($donnees))); |
383 |
|
384 |
// Pour chaque ligne du paramètre, faire une ligne dans le select |
385 |
foreach ($donnees as $value) { |
386 |
|
387 |
$contenu[0][$k]=$value; |
388 |
$contenu[1][$k++]=$value; |
389 |
} |
390 |
} |
391 |
$form->setSelect("proposition_decision",$contenu); |
392 |
|
393 |
} |
394 |
|
395 |
} |
396 |
|
397 |
|
398 |
/** |
399 |
* Récupération du numéro de dossier d'instruction à ajouter aux métadonnées |
400 |
* @return string numéro de dossier d'autorisation |
401 |
*/ |
402 |
protected function getDossier() { |
403 |
if(empty($this->specificMetadata)) { |
404 |
$this->getSpecificMetadata(); |
405 |
} |
406 |
return $this->specificMetadata->dossier; |
407 |
} |
408 |
/** |
409 |
* Récupération la version du dossier d'instruction à ajouter aux métadonnées |
410 |
* @return int Version |
411 |
*/ |
412 |
protected function getDossierVersion() { |
413 |
if(empty($this->specificMetadata)) { |
414 |
$this->getSpecificMetadata(); |
415 |
} |
416 |
return $this->specificMetadata->version; |
417 |
} |
418 |
/** |
419 |
* Récupération du numéro de dossier d'autorisation à ajouter aux métadonnées |
420 |
* @return string numéro de dossier d'autorisation |
421 |
*/ |
422 |
protected function getNumDemandeAutor() { |
423 |
if(empty($this->specificMetadata)) { |
424 |
$this->getSpecificMetadata(); |
425 |
} |
426 |
return $this->specificMetadata->dossier_autorisation; |
427 |
} |
428 |
/** |
429 |
* Récupération de la date de demande initiale du dossier à ajouter aux métadonnées |
430 |
* @return date date de la demande initiale |
431 |
*/ |
432 |
protected function getAnneemoisDemandeAutor() { |
433 |
if(empty($this->specificMetadata)) { |
434 |
$this->getSpecificMetadata(); |
435 |
} |
436 |
return $this->specificMetadata->date_demande_initiale; |
437 |
} |
438 |
/** |
439 |
* Récupération du type de dossier d'instruction à ajouter aux métadonnées |
440 |
* @return string type du dossier d'instruction |
441 |
*/ |
442 |
protected function getTypeInstruction() { |
443 |
if(empty($this->specificMetadata)) { |
444 |
$this->getSpecificMetadata(); |
445 |
} |
446 |
return $this->specificMetadata->dossier_instruction_type; |
447 |
} |
448 |
/** |
449 |
* Récupération du statut du dossier d'autorisation à ajouter aux métadonnées |
450 |
* @return string avis |
451 |
*/ |
452 |
protected function getStatutAutorisation() { |
453 |
if(empty($this->specificMetadata)) { |
454 |
$this->getSpecificMetadata(); |
455 |
} |
456 |
return $this->specificMetadata->statut; |
457 |
} |
458 |
/** |
459 |
* Récupération du type de dossier d'autorisation à ajouter aux métadonnées |
460 |
* @return string type de dossier d'autorisation |
461 |
*/ |
462 |
protected function getTypeAutorisation() { |
463 |
if(empty($this->specificMetadata)) { |
464 |
$this->getSpecificMetadata(); |
465 |
} |
466 |
return $this->specificMetadata->dossier_autorisation_type; |
467 |
} |
468 |
/** |
469 |
* Récupération de la date d'ajout de document à ajouter aux métadonnées |
470 |
* @return date de l'évènement |
471 |
*/ |
472 |
protected function getDateEvenementDocument() { |
473 |
return date("Y-m-d"); |
474 |
} |
475 |
/** |
476 |
* Récupération du groupe d'instruction à ajouter aux métadonnées |
477 |
* @return string Groupe d'instruction |
478 |
*/ |
479 |
protected function getGroupeInstruction() { |
480 |
if(empty($this->specificMetadata)) { |
481 |
$this->getSpecificMetadata(); |
482 |
} |
483 |
return $this->specificMetadata->groupe_instruction; |
484 |
} |
485 |
/** |
486 |
* Récupération du type du document à ajouter aux métadonnées |
487 |
* @return string Type de document |
488 |
*/ |
489 |
protected function getTitle() { |
490 |
return "Rapport d'instruction"; |
491 |
} |
492 |
|
493 |
/** |
494 |
* Cette méthode permet de stocker en attribut toutes les métadonnées |
495 |
* nécessaire à l'ajout d'un document. |
496 |
*/ |
497 |
public function getSpecificMetadata() { |
498 |
//Requête pour récupérer les informations essentiels sur le dossier d'instruction |
499 |
$sql = "SELECT dossier.dossier as dossier, |
500 |
dossier_autorisation.dossier_autorisation as dossier_autorisation, |
501 |
to_char(dossier.date_demande, 'YYYY/MM') as date_demande_initiale, |
502 |
dossier_instruction_type.code as dossier_instruction_type, |
503 |
etat_dossier_autorisation.libelle as statut, |
504 |
dossier_autorisation_type.code as dossier_autorisation_type, |
505 |
groupe.code as groupe_instruction |
506 |
FROM ".DB_PREFIXE."dossier |
507 |
LEFT JOIN ".DB_PREFIXE."dossier_instruction_type |
508 |
ON dossier.dossier_instruction_type = dossier_instruction_type.dossier_instruction_type |
509 |
LEFT JOIN ".DB_PREFIXE."dossier_autorisation |
510 |
ON dossier.dossier_autorisation = dossier_autorisation.dossier_autorisation |
511 |
LEFT JOIN ".DB_PREFIXE."etat_dossier_autorisation |
512 |
ON dossier_autorisation.etat_dossier_autorisation = etat_dossier_autorisation.etat_dossier_autorisation |
513 |
LEFT JOIN ".DB_PREFIXE."dossier_autorisation_type_detaille |
514 |
ON dossier_autorisation.dossier_autorisation_type_detaille = dossier_autorisation_type_detaille.dossier_autorisation_type_detaille |
515 |
LEFT JOIN ".DB_PREFIXE."dossier_autorisation_type |
516 |
ON dossier_autorisation_type_detaille.dossier_autorisation_type = dossier_autorisation_type.dossier_autorisation_type |
517 |
LEFT JOIN ".DB_PREFIXE."groupe |
518 |
ON dossier_autorisation_type.groupe = groupe.groupe |
519 |
WHERE dossier.dossier = '".$this->getVal("dossier_instruction")."'"; |
520 |
$res = $this->db->query($sql); |
521 |
$this->f->addToLog("getSpecificMetadata() : db->query(".$sql.")", VERBOSE_MODE); |
522 |
if ( database::isError($res)){ |
523 |
die(); |
524 |
} |
525 |
|
526 |
//Le résultat est récupéré dans un objet |
527 |
$row =& $res->fetchRow(DB_FETCHMODE_OBJECT); |
528 |
|
529 |
//Si il y a un résultat |
530 |
if ($row !== null) { |
531 |
|
532 |
// Instrance de la classe dossier. |
533 |
// Il est nécessaire de préciser l'identifiant du dossier d'instruction |
534 |
// car le nom du champ n'est pas identique au nom de la table. |
535 |
// S'ils avaient été identiques, alors get_inst_common aurait récupérée |
536 |
// l'identifiant. |
537 |
$inst_dossier = $this->get_inst_dossier($this->getVal('dossier_instruction')); |
538 |
|
539 |
// Insère l'attribut version à l'objet |
540 |
$row->version = $inst_dossier->get_dossier_instruction_version(); |
541 |
|
542 |
//Alors on créé l'objet dossier_instruction |
543 |
$this->specificMetadata = $row; |
544 |
} |
545 |
} |
546 |
|
547 |
/** |
548 |
* Surcharge du bouton retour afin de retourner sur le dossier d'instruction selon de cas |
549 |
*/ |
550 |
function retoursousformulaire($idxformulaire, $retourformulaire, $val, |
551 |
$objsf, $premiersf, $tricolsf, $validation, |
552 |
$idx, $maj, $retour) { |
553 |
|
554 |
// Ajout et consultation, retour dossier |
555 |
if ( ( $maj == 0 && $validation == 0 ) || |
556 |
( $maj == 3 && $validation == 0 ) || |
557 |
( $maj == 0 && $validation == 1 ) ){ |
558 |
|
559 |
echo "\n<a class=\"retour\" "; |
560 |
echo "href=\"#\" "; |
561 |
echo "onclick=\"redirectPortletAction(1,'main');\" "; |
562 |
echo ">"; |
563 |
echo _("Retour"); |
564 |
echo "</a>\n"; |
565 |
} |
566 |
//Sinon affiche un retour normal |
567 |
else { |
568 |
|
569 |
parent::retoursousformulaire($idxformulaire, $retourformulaire, $val, |
570 |
$objsf, $premiersf, $tricolsf, $validation, |
571 |
$idx, $maj, $retour); |
572 |
} |
573 |
} |
574 |
|
575 |
/** |
576 |
* TREATMENT - finalize. |
577 |
* |
578 |
* Permet de finaliser un enregistrement. |
579 |
* |
580 |
* @param array $val valeurs soumises par le formulaire |
581 |
* |
582 |
* @return boolean |
583 |
*/ |
584 |
function finalize($val = array()) { |
585 |
// Begin |
586 |
$this->begin_treatment(__METHOD__); |
587 |
|
588 |
// |
589 |
$ret = $this->manage_finalizing("finalize", $val); |
590 |
|
591 |
// Si le traitement ne s'est pas déroulé correctement |
592 |
if ($ret !== true) { |
593 |
|
594 |
// Return |
595 |
return $this->end_treatment(__METHOD__, false); |
596 |
} |
597 |
|
598 |
// Return |
599 |
return $this->end_treatment(__METHOD__, true); |
600 |
|
601 |
} |
602 |
|
603 |
/** |
604 |
* TREATMENT - unfinalize. |
605 |
* |
606 |
* Permet de definaliser un enregistrement. |
607 |
* |
608 |
* @param array $val valeurs soumises par le formulaire |
609 |
* |
610 |
* @return boolean |
611 |
*/ |
612 |
function unfinalize($val = array()) { |
613 |
// Begin |
614 |
$this->begin_treatment(__METHOD__); |
615 |
|
616 |
// |
617 |
$ret = $this->manage_finalizing("unfinalize", $val); |
618 |
|
619 |
// Si le traitement ne s'est pas déroulé correctement |
620 |
if ($ret !== true) { |
621 |
|
622 |
// Return |
623 |
return $this->end_treatment(__METHOD__, false); |
624 |
} |
625 |
|
626 |
// Return |
627 |
return $this->end_treatment(__METHOD__, true); |
628 |
} |
629 |
|
630 |
/** |
631 |
* Finalisation des documents. |
632 |
* |
633 |
* @param string $mode finalize/unfinalize |
634 |
* @param array $val valeurs soumises par le formulaire |
635 |
*/ |
636 |
function manage_finalizing($mode = null, $val = array()) { |
637 |
|
638 |
// Si le mode n'existe pas on retourne false |
639 |
if ($mode != "finalize" && $mode != "unfinalize") { |
640 |
return false; |
641 |
} |
642 |
|
643 |
// Recuperation de la valeur de la cle primaire de l'objet |
644 |
$id = $this->getVal($this->clePrimaire); |
645 |
|
646 |
// Si on finalise le document |
647 |
if ($mode == "finalize") { |
648 |
|
649 |
// Récupère la colelctivité du dossier d'instruction |
650 |
$dossier_instruction_om_collectivite = $this->get_dossier_instruction_om_collectivite(); |
651 |
// |
652 |
$collectivite = $this->f->getCollectivite($dossier_instruction_om_collectivite); |
653 |
// Génération du PDF |
654 |
$result = $this->compute_pdf_output('etat', $this->table, $collectivite, $id); |
655 |
$pdf_output = $result['pdf_output']; |
656 |
|
657 |
//Métadonnées du document |
658 |
$metadata = array( |
659 |
'filename' => 'rapport_instruction_'.$id.'.pdf', |
660 |
'mimetype' => 'application/pdf', |
661 |
'size' => strlen($pdf_output) |
662 |
); |
663 |
// Récupération des métadonnées calculées après validation |
664 |
$spe_metadata = $this->getMetadata("om_fichier_rapport_instruction"); |
665 |
|
666 |
// Assemble les métadonnées |
667 |
$metadata = array_merge($metadata, $spe_metadata); |
668 |
|
669 |
// Si le document a déjà été finalisé |
670 |
if ($this->getVal("om_fichier_rapport_instruction") != '') { |
671 |
|
672 |
// Met à jour le document mais pas son uid |
673 |
$uid = $this->f->storage->update( |
674 |
$this->getVal("om_fichier_rapport_instruction"), $pdf_output, $metadata); |
675 |
} |
676 |
// Sinon, ajoute le document et récupère son uid |
677 |
else { |
678 |
|
679 |
// Stockage du PDF |
680 |
$uid = $this->f->storage->create($pdf_output, $metadata); |
681 |
} |
682 |
} |
683 |
else { |
684 |
//Récupération de l'uid du document finalisé |
685 |
$uid = $this->getVal("om_fichier_rapport_instruction"); |
686 |
|
687 |
//On dé-finalise avant de finaliser |
688 |
if ($uid == '' || $uid == 'OP_FAILURE'){ |
689 |
$this->correct = false; |
690 |
$this->msg = ""; |
691 |
$this->addToMessage(_("Finalisation non enregistree")); |
692 |
$this->addToLog( |
693 |
_("Finalisation non enregistree")." - ". |
694 |
_("id consultation")." = ".$id." - ". |
695 |
_("uid fichier")." = ".$uid |
696 |
); |
697 |
|
698 |
// Stop le traitement |
699 |
return false; |
700 |
} |
701 |
} |
702 |
|
703 |
//Mise à jour des données |
704 |
if ($uid != '' && $uid != 'OP_FAILURE') { |
705 |
|
706 |
// Logger |
707 |
$this->addToLog(__METHOD__."() - begin", EXTRA_VERBOSE_MODE); |
708 |
|
709 |
// |
710 |
foreach ($this->champs as $key => $value) { |
711 |
// |
712 |
$val[$value] = $this->val[$key]; |
713 |
} |
714 |
|
715 |
// |
716 |
$this->setvalF($val); |
717 |
// Verification de la validite des donnees |
718 |
$this->verifier($this->val, $this->db, DEBUG); |
719 |
// Si les verifications precedentes sont correctes, on procede a |
720 |
// la modification, sinon on ne fait rien et on retourne une erreur |
721 |
if ($this->correct) { |
722 |
|
723 |
// Execution du trigger 'before' specifique au MODE 'update' |
724 |
$this->triggermodifier($id, $this->db, $this->val, DEBUG); |
725 |
|
726 |
// |
727 |
$valF = ''; |
728 |
if($mode=="finalize") { |
729 |
$valF["om_final_rapport_instruction"] = true; |
730 |
} else { |
731 |
$valF["om_final_rapport_instruction"] = false; |
732 |
} |
733 |
$valF["om_fichier_rapport_instruction"] = $uid; |
734 |
|
735 |
// Execution de la requête de modification des donnees de l'attribut |
736 |
// valF de l'objet dans l'attribut table de l'objet |
737 |
$res = $this->db->autoExecute(DB_PREFIXE.$this->table, $valF, |
738 |
DB_AUTOQUERY_UPDATE, $this->getCle($id)); |
739 |
$this->addToLog( |
740 |
__METHOD__."() : db->autoExecute(\"".DB_PREFIXE.$this->table."\", ".print_r($valF, true).", DB_AUTOQUERY_UPDATE, \"".$this->getCle($id)."\")", |
741 |
VERBOSE_MODE |
742 |
); |
743 |
|
744 |
// Si une erreur survient |
745 |
if (database::isError($res, true)) { |
746 |
|
747 |
// Appel de la methode de recuperation des erreurs |
748 |
$this->erreur_db($res->getDebugInfo(), $res->getMessage(), ''); |
749 |
$this->correct = false; |
750 |
return false; |
751 |
} else { |
752 |
|
753 |
// Log |
754 |
$this->addToLog(_("Requete executee"), VERBOSE_MODE); |
755 |
// Log |
756 |
$message = _("Enregistrement")." ".$id." "; |
757 |
$message .= _("de la table")." \"".$this->table."\" "; |
758 |
$message .= "[ ".$this->db->affectedRows()." "; |
759 |
$message .= _("enregistrement(s) mis a jour")." ]"; |
760 |
$this->addToLog($message, VERBOSE_MODE); |
761 |
// Execution du trigger 'after' specifique au MODE 'update' |
762 |
$this->triggermodifierapres($id, $this->db, $this->val, DEBUG); |
763 |
|
764 |
if($mode == "finalize") { |
765 |
$etat = _('finalisation'); |
766 |
} else { |
767 |
$etat = _('definalisation'); |
768 |
} |
769 |
$this->msg = ""; |
770 |
$this->addToMessage(sprintf(_("La %s du document s'est effectuee avec succes."), $etat)); |
771 |
return true; |
772 |
} |
773 |
// |
774 |
} else { |
775 |
$this->correct = false; |
776 |
$this->msg=""; |
777 |
// Message d'echec (saut d'une ligne supplementaire avant le |
778 |
// message pour qu'il soit mis en evidence) |
779 |
$this->addToMessage(_("Finalisation non enregistree")); |
780 |
$this->addToLog( |
781 |
_("Finalisation non enregistree")." - ". |
782 |
_("id consultation")." = ".$id." - ". |
783 |
_("uid fichier")." = ".$uid |
784 |
); |
785 |
return false; |
786 |
} |
787 |
} |
788 |
// Si le document n'a pas été stocké |
789 |
else{ |
790 |
$this->correct = false; |
791 |
$this->msg=""; |
792 |
$this->addToMessage(_("Finalisation non enregistree")); |
793 |
$this->addToLog( |
794 |
_("Finalisation non enregistree")." - ". |
795 |
_("id consultation")." = ".$id." - ". |
796 |
_("uid fichier")." = ".$uid |
797 |
); |
798 |
return false; |
799 |
} |
800 |
} |
801 |
|
802 |
/** |
803 |
* Cette variable permet de stocker le résultat de la méthode |
804 |
* getDivisionFromDossier() afin de ne pas effectuer le recalcul à chacun de |
805 |
* ces appels. |
806 |
* @var string Code de la division du dossier en cours |
807 |
*/ |
808 |
var $_division_from_dossier = NULL; |
809 |
|
810 |
/** |
811 |
* Cette méthode permet de récupérer le code de division correspondant |
812 |
* au dossier sur lequel on se trouve. |
813 |
* |
814 |
* @return string Code de la division du dossier en cours |
815 |
*/ |
816 |
function getDivisionFromDossier() { |
817 |
|
818 |
// Cette méthode peut être appelée plusieurs fois lors d'une requête. |
819 |
// Pour éviter de refaire le traitement de recherche de la division |
820 |
// alors on vérifie si nous ne l'avons pas déjà calculé. |
821 |
if ($this->_division_from_dossier != NULL) { |
822 |
// Logger |
823 |
$this->addToLog("getDivisionFromDossier(): retour de la valeur déjà calculée - '".$this->_division_from_dossier."'", EXTRA_VERBOSE_MODE); |
824 |
// On retourne la valeur déjà calculée |
825 |
return $this->_division_from_dossier; |
826 |
} |
827 |
|
828 |
// Par défaut, on définit la valeur du dossier à NULL |
829 |
$dossier = NULL; |
830 |
// Test sur le mode et le contexte du formulaire |
831 |
if ($this->getParameter("maj") == 0 |
832 |
&& ($this->getParameter("retourformulaire") == "dossier" |
833 |
|| $this->getParameter("retourformulaire") == "dossier_instruction" |
834 |
|| $this->getParameter("retourformulaire") == "dossier_instruction_mes_encours" |
835 |
|| $this->getParameter("retourformulaire") == "dossier_instruction_tous_encours" |
836 |
|| $this->getParameter("retourformulaire") == "dossier_instruction_mes_clotures" |
837 |
|| $this->getParameter("retourformulaire") == "dossier_instruction_tous_clotures")) { |
838 |
// Si on se trouve en mode AJOUT (seul mode où l'enregistrement |
839 |
// n'existe pas en base de données) ET que nous nous trouvons |
840 |
// dans le contexte d'un dossier d'instruction alors on récupère |
841 |
// le numéro de dossier depuis le paramètre 'idxformulaire' |
842 |
$dossier = $this->getParameter("idxformulaire"); |
843 |
} else { |
844 |
// Sinon on récupère le numéro de dossier dans le champs dossier de |
845 |
// l'enregistrement (en base de données) |
846 |
$dossier = $this->getVal("dossier_instruction"); |
847 |
} |
848 |
|
849 |
// On appelle la méthode de la classe utils qui renvoi le code de la |
850 |
// division d'un dossier, on la stocke pour ne pas refaire le calcul au |
851 |
// prochain appel de cette méthode |
852 |
$this->_division_from_dossier = $this->f->getDivisionFromDossier($dossier); |
853 |
// Logger |
854 |
$this->addToLog("getDivisionFromDossier(): retour de la valeur nouvellement calculée - '".$this->_division_from_dossier."'", EXTRA_VERBOSE_MODE); |
855 |
// On retourne la valeur retournée |
856 |
return $this->_division_from_dossier; |
857 |
|
858 |
} |
859 |
|
860 |
/** |
861 |
* Si le dossier d'instruction auquel est rattachée la consultation est |
862 |
* cloturé, on affiche pas les liens du portlet. |
863 |
* |
864 |
* @return boolean true si non cloturé false sinon |
865 |
*/ |
866 |
function is_dossier_instruction_not_closed() { |
867 |
$idxformulaire = $this->getParameter("idxformulaire"); |
868 |
$retourformulaire = $this->getParameter("retourformulaire"); |
869 |
//Si le dossier d'instruction auquel est rattachée la consultation est |
870 |
//cloturé, on affiche pas les liens du portlet |
871 |
if ( $idxformulaire != '' && |
872 |
( |
873 |
$retourformulaire == 'dossier' || |
874 |
$retourformulaire == 'dossier_instruction' || |
875 |
$retourformulaire == 'dossier_instruction_mes_encours' || |
876 |
$retourformulaire == 'dossier_instruction_tous_encours' || |
877 |
$retourformulaire == 'dossier_instruction_mes_clotures' || |
878 |
$retourformulaire == 'dossier_instruction_tous_clotures' |
879 |
)){ |
880 |
|
881 |
//On récuppère le statut du dossier d'instruction |
882 |
$statut = $this->f->getStatutDossier($idxformulaire); |
883 |
if ( $this->f->isUserInstructeur() && $statut == "cloture" ){ |
884 |
return false; |
885 |
} |
886 |
} |
887 |
return true; |
888 |
} |
889 |
|
890 |
/** |
891 |
* Défini si l'utilisateur est un intructeur qui en correspond à la division |
892 |
* du dossier. |
893 |
* |
894 |
* @return boolean true si correspond false sinon |
895 |
*/ |
896 |
function is_instructeur_from_division() { |
897 |
|
898 |
if ($this->f->isUserInstructeur() |
899 |
&& isset($this->f->om_utilisateur["division"]) |
900 |
&& $this->f->om_utilisateur["division"] != $this->getDivisionFromDossier()) { |
901 |
// |
902 |
return false; |
903 |
} |
904 |
return true; |
905 |
} |
906 |
|
907 |
/** |
908 |
* Si le document est finalisé l'action "finaliser" n'est pas affichée |
909 |
* |
910 |
* @return boolean true sinon lu false sinon |
911 |
*/ |
912 |
function show_rapport_instruction_finaliser_portlet_action() { |
913 |
if ($this->is_document_finalized("om_final_rapport_instruction")) { |
914 |
return false; |
915 |
} |
916 |
return true; |
917 |
} |
918 |
|
919 |
/** |
920 |
* Retourne is_document_finalized("om_final_consultation") |
921 |
* |
922 |
* @return boolean true si finalisé false sinon |
923 |
*/ |
924 |
function show_unfinalize_portlet_action() { |
925 |
return $this->is_document_finalized("om_final_rapport_instruction"); |
926 |
} |
927 |
|
928 |
/** |
929 |
* Permet de savoir si le document passé en paramètre est finalisé |
930 |
* |
931 |
* @param string $field flag finalisé |
932 |
* |
933 |
* @return boolean true si finalisé false sinon |
934 |
*/ |
935 |
function is_document_finalized($field) { |
936 |
if($this->getVal($field) == 't') { |
937 |
return true; |
938 |
} |
939 |
return false; |
940 |
} |
941 |
|
942 |
|
943 |
/** |
944 |
* Récupère l'instance du dossier d'instruction |
945 |
* |
946 |
* @param mixed Identifiant du dossier d'instruction |
947 |
* |
948 |
* @return object |
949 |
*/ |
950 |
function get_inst_dossier($dossier = null) { |
951 |
// |
952 |
return $this->get_inst_common("dossier", $dossier); |
953 |
} |
954 |
|
955 |
|
956 |
}// fin classe |
957 |
?> |