/[openfoncier]/trunk/obj/commission.class.php
ViewVC logotype

Contents of /trunk/obj/commission.class.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5169 - (show annotations)
Thu Nov 17 18:17:08 2016 UTC (8 years, 2 months ago) by softime
File size: 40274 byte(s)
* Merge de la branche de développement 3.34.0 vers le trunk

1 <?php
2 /**
3 * DBFORM - 'commission' - Surcharge gen.
4 *
5 * Ce script permet de définir la classe 'commission'.
6 *
7 * @package openads
8 * @version SVN : $Id: commission.class.php 4824 2015-06-15 05:58:07Z fmichon $
9 */
10
11 require_once "../gen/obj/commission.class.php";
12
13 /**
14 * Définition de la classe 'commission'.
15 *
16 * Cette classe permet d'interfacer la commission, c'est-à-dire
17 * l'enregistrement représentant ...
18 */
19 class commission extends commission_gen {
20
21 /**
22 * On active les nouvelles actions sur cette classe.
23 */
24 var $activate_class_action = true;
25
26 /**
27 * Constructeur.
28 */
29 function __construct($id, &$dnu1 = null, $dnu2 = null) {
30 $this->constructeur($id);
31 }
32
33 /**
34 * Champs contenant les UID des fichiers.
35 */
36 var $abstract_type = array(
37 "om_fichier_commission_ordre_jour" => "file",
38 "om_fichier_commission_compte_rendu" => "file",
39 );
40
41 /**
42 * Définition des actions disponibles sur la classe.
43 *
44 * @return void
45 */
46 function init_class_actions() {
47
48 // On récupère les actions génériques définies dans la méthode
49 // d'initialisation de la classe parente
50 parent::init_class_actions();
51
52 // ACTION - 011 - diffuser_ordre_jour
53 //
54 $this->class_actions[11] = array(
55 "identifier" => "diffuser_ordre_jour",
56 "portlet" => array(
57 "type" => "action-direct",
58 "libelle" => _("(OJ) Diffuser l'OJ"),
59 "order" => 28,
60 "class" => "transferer-16",
61 ),
62 "view" => "formulaire",
63 "method" => "diffuse_document",
64 "button" => "diffuser_ordre_jour",
65 "permission_suffix" => "diffuser_ordre_jour",
66 );
67
68 // ACTION - 012 - diffuser_compte_rendu
69 //
70 $this->class_actions[12] = array(
71 "identifier" => "diffuser_compte_rendu",
72 "portlet" => array(
73 "type" => "action-direct",
74 "libelle" => _("(CR) Diffuser le CR"),
75 "order" => 29,
76 "class" => "transferer-16",
77 ),
78 "view" => "formulaire",
79 "method" => "diffuse_document",
80 "button" => "diffuser_compte_rendu",
81 "permission_suffix" => "diffuser_compte_rendu",
82 );
83
84 // ACTION - 021 - edition_proposition_ordre_jour
85 //
86 $this->class_actions[21] = array(
87 "identifier" => "edition_proposition_ordre_jour",
88 "portlet" => array(
89 "type" => "action-blank",
90 "libelle" => _("(OJ) Proposition"),
91 "order" => 30,
92 "class" => "pdf-16",
93 ),
94 "view" => "view_edition_pdf",
95 "permission_suffix" => "consulter",
96 );
97
98 // ACTION - 022 - edition_ordre_jour
99 //
100 $this->class_actions[22] = array(
101 "identifier" => "edition_ordre_jour",
102 "portlet" => array(
103 "type" => "action-blank",
104 "libelle" => _("(OJ) Ordre du jour"),
105 "order" => 31,
106 "class" => "pdf-16",
107 ),
108 "view" => "view_edition_pdf",
109 "permission_suffix" => "consulter",
110 );
111
112 // ACTION - 023 - edition_compte_rendu
113 //
114 $this->class_actions[23] = array(
115 "identifier" => "edition_compte_rendu",
116 "portlet" => array(
117 "type" => "action-blank",
118 "libelle" => _("(CR) Compte-rendu"),
119 "order" => 32,
120 "class" => "pdf-16",
121 ),
122 "view" => "view_edition_pdf",
123 "permission_suffix" => "consulter",
124 );
125
126 // ACTION - 031 - view_plan_or_unplan_demands
127 //
128 $this->class_actions[31] = array(
129 "identifier" => "view_form_plan_or_unplan_demands",
130 "view" => "view_form_plan_or_unplan_demands",
131 "permission_suffix" => "dossiers_planifier_retirer",
132 "button" => _("Valider"),
133 );
134
135 // ACTION - 032 - view_form_add_and_plan_demand
136 //
137 $this->class_actions[32] = array(
138 "identifier" => "view_form_add_and_plan_demand",
139 "view" => "view_form_add_and_plan_demand",
140 "permission_suffix" => "dossiers_planifier_retirer",
141 "button" => _("Valider"),
142 );
143 }
144
145 /**
146 * Instance de la classe commission_type.
147 *
148 * @var mixed (resource | null)
149 */
150 var $inst_commission_type = null;
151
152 /**
153 * Récupère l'instance du type de commission.
154 *
155 * @param string $commission_type Identifiant du type de commission.
156 *
157 * @return object
158 */
159 function get_inst_commission_type($commission_type = null) {
160 //
161 return $this->get_inst_common("commission_type", $commission_type);
162 }
163
164 /**
165 *
166 */
167 function setType(&$form, $maj) {
168 //
169 parent::setType($form, $maj);
170
171 // Cache le champ code en ajout
172 if ($maj == 0) {
173
174 $form->setType('code', 'hidden');
175 }
176
177 if ($maj > 0) {
178 // Le type de commission n'est pas modifiable une fois la commission ajoutée
179 $form->setType('commission_type', 'selecthiddenstatic');
180
181 $form->setType('code', 'hiddenstatic');
182 }
183 // On définit le type des champs pour les actions direct
184 // utilisant la vue formulaire
185 if ($maj == 11 || $maj == 12) {
186 foreach ($this->champs as $key => $value) {
187 $form->setType($value, 'hidden');
188 }
189 }
190
191 //Cache les champs pour la finalisation
192 $form->setType('om_fichier_commission_ordre_jour', 'hidden');
193 $form->setType('om_final_commission_ordre_jour', 'hidden');
194 $form->setType('om_fichier_commission_compte_rendu', 'hidden');
195 $form->setType('om_final_commission_compte_rendu', 'hidden');
196 }
197
198 /**
199 *
200 */
201 function setOnchange(&$form, $maj) {
202 //
203 parent::setOnchange($form, $maj);
204 // Action javascript au changement du type de la commission
205 $form->setOnchange(
206 "commission_type",
207 "commission_update_data_from_commission_type(this.value);"
208 );
209 }
210
211 /**
212 *
213 */
214 function setVal(&$form, $maj, $validation, &$db) {
215 //
216 if ($maj == 0) {
217 // Date du jour par défaut
218 $form->setVal("date_commission", date('d/m/Y'));
219 }
220 }
221
222 /**
223 *
224 */
225 function setvalF($val) {
226 //
227 parent::setValF($val);
228
229 // Génération automatique du code de la commission
230 // Récupération du code du type de la commission
231 $commission_type_code = "";
232 if (isset($val['commission_type'])
233 && is_numeric($val['commission_type'])) {
234 //
235 $inst_commission_type = $this->get_inst_commission_type($val['commission_type']);
236 $commission_type_code = $inst_commission_type->getVal("code");
237 }
238 //Formatte la date
239 $dateFormatee = $this->formatDate($val['date_commission']);
240
241 //
242 $this->valF['code'] = $commission_type_code.$dateFormatee;
243 }
244
245 /**
246 * Prend une date au format JJ/MM/AAAA et retourne AAAAMMJJ
247 */
248 function formatDate($date) {
249 $dateFormatee = explode('/', $date);
250 $dateFormatee = $dateFormatee[2].$dateFormatee[1].$dateFormatee[0];
251 return $dateFormatee;
252 }
253
254 /**
255 *
256 */
257 function afterFormSpecificContent() {
258 //Le sous-formulaire spécifique ne s'affiche qu'en consultation
259 if ($this->getParameter("maj") == 3) {
260 $this->view_manage();
261 }
262 }
263
264 /**
265 * VIEW - view_manage.
266 *
267 * @return void
268 */
269 function view_manage() {
270
271 // Identifiant de l'enregistrement
272 $idx = $this->getVal($this->clePrimaire);
273
274 //
275 printf(
276 '
277 <div id="commission-manage-tabs">
278 <ul>
279 <li><a href="../scr/soustab.php?obj=dossier_commission&idxformulaire=%1$s&retourformulaire=commission" id="dossier_planifie">%2$s</a></li>
280 <li><a href="../scr/form.php?obj=commission&action=31&idx=%1$s" id="commission_dossiers_planifier_retirer">%3$s</a></li>
281 <li><a href="../scr/form.php?obj=commission&action=32&idx=%1$s" id="commission_dossiers_planifier_numero">%4$s</a></li>
282 </ul>
283 </div>',
284 $idx,
285 _("les dossiers planifies"),
286 _("planifier/retirer des dossiers"),
287 _("planifier un dossier specifique")
288 );
289
290 }
291
292 /**
293 * VIEW - view_edition_pdf.
294 *
295 * Edite l'édition de l'instruction ou affiche celle contenue dans le stockage.
296 *
297 * @return void
298 */
299 function view_edition_pdf() {
300
301 //
302 $this->checkAccessibility();
303 // Identifiant de l'enregistrement
304 $idx = $this->getVal($this->clePrimaire);
305
306 /**
307 * Définition des paramètres.
308 */
309 //
310 if ($this->getParameter("maj") == 21) {
311 $obj = "commission_proposition_ordre_jour";
312 } elseif ($this->getParameter("maj") == 22) {
313 $obj = "commission_ordre_jour";
314 $mention = "OJ";
315 $type = "de l'ordre du jour";
316 $field_uid = "om_fichier_commission_ordre_jour";
317 $field_final = "om_final_commission_ordre_jour";
318 } elseif ($this->getParameter("maj") == 23) {
319 $obj = "commission_compte_rendu";
320 $mention = "CR";
321 $type = "du compte-rendu";
322 $field_uid = "om_fichier_commission_compte_rendu";
323 $field_final = "om_final_commission_compte_rendu";
324 }
325
326 // Si l'instruction est finalisée
327 if (isset($field_final)
328 && $this->getVal($field_final) == 't'
329 && $this->getVal($field_final) != null) {
330 // Ouvre le document
331 $lien = '../spg/file.php?obj='.$this->table.'&'.
332 'champ='.$field_uid.'&id='.$this->getVal($this->clePrimaire);
333 //
334 header("Location: ".$lien);
335 } else {
336
337 // Génération du PDF
338 $result = $this->compute_pdf_output(
339 'etat',
340 $obj,
341 null,
342 $idx
343 );
344 // Affichage du PDF
345 $this->expose_pdf_output(
346 $result['pdf_output'],
347 $result['filename']
348 );
349 }
350 }
351
352 /**
353 * VIEW - view_form_plan_or_unplan_demands.
354 *
355 * @return void
356 */
357 function view_form_plan_or_unplan_demands() {
358
359 //
360 $this->checkAccessibility();
361 // Identifiant de l'enregistrement
362 $idx = $this->getVal($this->clePrimaire);
363
364 //
365 if (!isset($_POST["dossier"])) {
366 //
367 printf('<div id="view_form_plan_or_unplan_demands">');
368 //
369 printf('<div id="sousform-plan_or_unplan_demands">');
370 }
371
372 // Treatment
373 if (isset($_POST["dossier"])) {
374 //
375 $dossier_commission_all_ids = array();
376 $dossier_commission_checkeds = array();
377 //
378 $posted_dossier = $this->f->get_submitted_post_value('dossier');
379 $posted_checkeds = $this->f->get_submitted_post_value('checkeds');
380 //
381 foreach ($posted_dossier as $key => $value) {
382 $plop = explode("_", $value);
383 if (count($plop) == 2) {
384 $dossier_commission_all_ids[$plop[0]] = array(
385 "dossier_commission_id" => $plop[0],
386 "dossier" => $plop[1],
387 );
388 }
389 }
390 foreach (explode(";", $posted_checkeds) as $key => $value) {
391 $plop = explode("_", $value);
392 if (count($plop) == 2) {
393 $dossier_commission_checkeds[$plop[0]] = array(
394 "dossier_commission_id" => $plop[0],
395 "dossier" => $plop[1],
396 );
397 }
398 }
399 //
400 $planned = array_keys($dossier_commission_checkeds);
401 $unplanned = array_diff(
402 array_keys($dossier_commission_all_ids),
403 array_keys($dossier_commission_checkeds)
404 );
405 //
406 $ret = $this->update_planning(
407 array(
408 "planned" => $planned,
409 "unplanned" => $unplanned,
410 )
411 );
412 $this->message();
413 }
414
415 // Formulaire
416 printf(
417 '
418 <!-- ########## START DBFORM ########## -->
419 <form
420 method="post" action=""
421 onsubmit="commission_submit_plan_or_unplan_demands(\'plan_or_unplan_demands\', \'%s\', this);return false;">',
422 $this->getDataSubmit()
423 );
424
425 /**
426 *
427 */
428 //
429 $query = sprintf(
430 'SELECT
431 dossier_commission.dossier_commission as "dossier_commission_id",
432 dossier_commission.dossier as "dossier",
433 dossier.dossier_libelle as "dossier_libelle",
434 CASE WHEN demandeur.qualite = \'particulier\'
435 THEN TRIM(
436 CONCAT(
437 demandeur.particulier_nom,
438 \' \',
439 demandeur.particulier_prenom
440 )
441 )
442 ELSE TRIM(
443 CONCAT(
444 demandeur.personne_morale_raison_sociale,
445 \' \',
446 demandeur.personne_morale_denomination
447 )
448 )
449 END as "demandeur",
450 TRIM(
451 CONCAT(
452 dossier.terrain_adresse_voie_numero, \' \',
453 dossier.terrain_adresse_voie, \' \',
454 dossier.terrain_adresse_lieu_dit, \' \',
455 dossier.terrain_adresse_code_postal, \' \',
456 dossier.terrain_adresse_localite, \' \',
457 dossier.terrain_adresse_bp, \' \',
458 dossier.terrain_adresse_cedex
459 )
460 ) as "terrain",
461 instructeur.nom as "instructeur",
462 dossier_commission.motivation as "motivation",
463 to_char(dossier_commission.date_souhaitee, \'DD/MM/YYYY\') as "date_souhaitee",
464 to_char(dossier.date_limite, \'DD/MM/YYYY\') as "date_limite",
465 etat.libelle as "etat",
466 dossier_commission.avis as "avis"
467 FROM
468 %1$sdossier_commission
469 LEFT JOIN %1$sdossier
470 ON dossier_commission.dossier = dossier.dossier
471 LEFT JOIN %1$setat
472 ON dossier.etat = etat.etat
473 LEFT JOIN %1$slien_dossier_demandeur
474 ON dossier.dossier = lien_dossier_demandeur.dossier
475 AND lien_dossier_demandeur.petitionnaire_principal IS TRUE
476 LEFT JOIN %1$sdemandeur
477 ON lien_dossier_demandeur.demandeur = demandeur.demandeur
478 AND lien_dossier_demandeur.petitionnaire_principal IS TRUE
479 LEFT JOIN %1$sinstructeur
480 ON dossier.instructeur = instructeur.instructeur
481 ',
482 DB_PREFIXE
483 );
484 $orderby = "
485 ORDER BY
486 dossier_commission.avis DESC NULLS LAST,
487 dossier
488 ";
489 // Demandes déjà rattachées à la commission.
490 $sql = $query."
491 WHERE
492 dossier_commission.commission = ".$idx."
493 ".$orderby;
494 $res = $this->f->db->query($sql);
495 $this->f->addToLog(
496 __METHOD__."(): db->query(\"".$sql."\");",
497 VERBOSE_MODE
498 );
499 $this->f->isDatabaseError($res);
500 // Demandes rattachables à la commission.
501 $sqlAjout = $query."
502 WHERE
503 dossier_commission.commission IS NULL AND
504 dossier_commission.commission_type =
505 (
506 SELECT
507 commission_type
508 FROM
509 ".DB_PREFIXE."commission
510 WHERE commission.commission = ".$idx."
511 )
512 ".$orderby;
513 $resAjout = $this->f->db->query($sqlAjout);
514 $this->f->addToLog(
515 __METHOD__."(): db->query(\"".$sqlAjout."\");",
516 VERBOSE_MODE
517 );
518 $this->f->isDatabaseError($resAjout);
519
520 /**
521 * Aucun résultat. On affiche un message explicite à l'utilisateur
522 * et on sort de la view.
523 */
524 if ($res->numrows() == 0 && $resAjout->numrows() == 0) {
525 echo _("Aucune demande de passage pour ce type de commission.");
526 return;
527 }
528
529 /**
530 * Définition des templates HTML pour l'affichage du tableau.
531 */
532 //
533 $template_table = '
534 <table class="tab-tab">%s
535 <tbody>%s
536 </tbody>
537 </table>
538 ';
539 //
540 $template_head = '
541 <thead>
542 <tr class="ui-tabs-nav ui-accordion ui-state-default tab-title">
543 <th class="title col-0 firstcol"><span class="name"></span></th>
544 <th class="title col-0 firstcol"><span class="name">%s</span></th>
545 <th class="title col-0 firstcol"><span class="name">%s</span></th>
546 <th class="title col-0 firstcol"><span class="name">%s</span></th>
547 <th class="title col-0 firstcol"><span class="name">%s</span></th>
548 <th class="title col-0 firstcol"><span class="name">%s</span></th>
549 <th class="title col-0 firstcol"><span class="name">%s</span></th>
550 <th class="title col-0 firstcol"><span class="name">%s</span></th>
551 <th class="title col-0 firstcol"><span class="name">%s</span></th>
552 <th class="title col-0 firstcol"><span class="name">%s</span></th>
553 </tr>
554 </thead>';
555 //
556 $template_line = '
557 <tr class="tab-data odd" id="dossier_commission-%s">
558 <td class="icons">
559 <input type="checkbox"%s name="dossier[]" value="%s"%s />
560 </td>
561 <td class="col-1 firstcol">%s</td>
562 <td class="col-1 firstcol">%s</td>
563 <td class="col-1">%s</td>
564 <td class="col-2 lastcol">%s</td>
565 <td class="col-2 lastcol">%s</td>
566 <td class="col-2 lastcol">%s</td>
567 <td class="col-2 lastcol">%s</td>
568 <td class="col-2 lastcol">%s</td>
569 <td class="col-2 lastcol">%s</td>
570 </tr>';
571
572 /**
573 * Affichage du tableau.
574 */
575 //
576 $ct_head = sprintf(
577 $template_head,
578 _('id'),
579 _('dossier'),
580 _('demandeur'),
581 _('terrain'),
582 _('instructeur'),
583 _('motivation'),
584 _('date_souhaitee'),
585 _('date_limite'),
586 _('etat')
587 );
588 //
589 $ct_body = "";
590 //
591 while ($row =& $res->fetchRow(DB_FETCHMODE_ASSOC)) {
592 $ct_body .= sprintf(
593 $template_line,
594 $row['dossier'],
595 ' checked="checked"',
596 $row['dossier_commission_id']."_".$row['dossier'],
597 ($row['avis'] != '' ? 'disabled="disabled"' : ''),
598 $row['dossier_commission_id'],
599 $row['dossier_libelle'],
600 $row['demandeur'],
601 $row['terrain'],
602 $row['instructeur'],
603 $row['motivation'],
604 $this->f->formatDate($row['date_souhaitee']),
605 $this->f->formatDate($row['date_limite']),
606 $this->f->formatDate($row['etat'])
607 );
608 }
609 //
610 while ($row =& $resAjout->fetchRow(DB_FETCHMODE_ASSOC)) {
611 $ct_body .= sprintf(
612 $template_line,
613 $row['dossier'],
614 '',
615 $row['dossier_commission_id']."_".$row['dossier'],
616 '',
617 $row['dossier_commission_id'],
618 $row['dossier_libelle'],
619 $row['demandeur'],
620 $row['terrain'],
621 $row['instructeur'],
622 $row['motivation'],
623 $this->f->formatDate($row['date_souhaitee']),
624 $this->f->formatDate($row['date_limite']),
625 $this->f->formatDate($row['etat'])
626 );
627 }
628 //
629 printf($template_table, $ct_head, $ct_body);
630
631 /**
632 * Affichage du bouton de validation.
633 */
634 echo "\t<div class=\"formControls\">\n";
635 $correct = $this->correct;
636 $this->correct = false;
637 $this->bouton($this->getParameter("maj"));
638 $this->correct = $correct;
639 echo "\t</div>\n";
640
641 //
642 printf('</form>');
643
644 //
645 if (isset($_POST["dossier"])) {
646 printf('</div>');
647 printf('</div>');
648 }
649
650 }
651
652 /**
653 * VIEW - view_form_add_and_plan_demand.
654 *
655 * @return void
656 */
657 function view_form_add_and_plan_demand() {
658
659 //
660 $this->checkAccessibility();
661 // Identifiant de l'enregistrement
662 $idx = $this->getVal($this->clePrimaire);
663
664 //
665 if (!isset($_POST["dossier"])) {
666 //
667 printf('<div id="view_form_add_and_plan_demand">');
668 //
669 printf('<div id="sousform-add_and_plan_demand">');
670 }
671
672 // Treatment
673 if (isset($_POST["dossier"])) {
674 $ret = $this->add_and_plan_demand(
675 array(
676 "dossier" => $this->f->get_submitted_post_value('dossier'),
677 )
678 );
679 $this->message();
680 }
681
682 // Formulaire
683 printf(
684 '
685 <!-- ########## START DBFORM ########## -->
686 <form
687 method="post" action=""
688 onsubmit="affichersform(\'add_and_plan_demand\', \'%s\', this);return false;">',
689 $this->getDataSubmit()
690 );
691
692 // Le formulaire a un seul champ : dossier
693 $champs = array("dossier");
694 // Création d'un nouvel objet de type formulaire
695 $form = new $this->om_formulaire(null, 0, 0, $champs);
696 // Caractéristique du champ
697 $form->setLib("dossier", _("No de dossier")." :");
698 $form->setType("dossier", "text");
699 $form->setTaille("dossier", 25);
700 $form->setMax("dossier", 25);
701 //
702 $form->afficher($champs, 0, false, false);
703 //
704 echo "\t<div class=\"formControls\">\n";
705 $correct = $this->correct;
706 $this->correct = false;
707 $this->bouton($this->getParameter("maj"));
708 $this->correct = $correct;
709 echo "\t</div>\n";
710 //
711 printf('</form>');
712
713 //
714 if (isset($_POST["dossier"])) {
715 printf('</div>');
716 printf('</div>');
717 }
718
719 }
720
721 /**
722 * TREATMENT - update_planning.
723 *
724 * @return boolean
725 */
726 function update_planning($val = array()) {
727 //
728 $this->begin_treatment(__METHOD__);
729 // Identifiant de l'enregistrement
730 $idx = $this->getVal($this->clePrimaire);
731
732 //
733 if (isset($val["planned"])
734 && is_array($val["planned"])
735 && count($val["planned"]) != 0) {
736 // Mise à jour des éléments checked
737 $sql = "UPDATE ".DB_PREFIXE."dossier_commission SET commission=".$idx."
738 WHERE dossier_commission in (".implode(",", $val["planned"]).")
739 AND (commission IS NULL OR commission = ".$idx.")";
740 $res = $this->f->db->query($sql);
741 $this->f->addToLog(
742 __METHOD__."(): db->query(\"".$sql."\");",
743 VERBOSE_MODE
744 );
745 $this->f->isDatabaseError($res);
746 //
747 if (count($val["planned"]) != $this->f->db->affectedRows()) {
748 $this->correct = false;
749 $this->addToMessage(_("Erreur lors de la mise à jour de la planification."));
750 return $this->end_treatment(__METHOD__, false);
751 }
752 }
753
754 if (isset($val["unplanned"])
755 && is_array($val["unplanned"])
756 && count($val["unplanned"]) != 0) {
757 // Mise à jour des éléments unchecked
758 $sql = "UPDATE ".DB_PREFIXE."dossier_commission SET commission=null
759 WHERE dossier_commission in (".implode(",", $val["unplanned"]).") AND (avis = '' OR avis IS NULL)";
760 $res = $this->f->db->query($sql);
761 $this->f->addToLog(
762 __METHOD__."(): db->query(\"".$sql."\");",
763 VERBOSE_MODE
764 );
765 $this->f->isDatabaseError($res);
766 //
767 if (count($val["unplanned"]) != $this->f->db->affectedRows()) {
768 $this->correct = false;
769 $this->addToMessage(_("Erreur lors de la mise à jour de la planification."));
770 return $this->end_treatment(__METHOD__, false);
771 }
772 }
773 //
774 $this->addToMessage(_("Mise à jour de la planification effectuée."));
775 return $this->end_treatment(__METHOD__, true);
776 }
777
778 /**
779 * TREATMENT - add_and_plan_demand.
780 *
781 * @return boolean
782 */
783 function add_and_plan_demand($val = array()) {
784 //
785 $this->begin_treatment(__METHOD__);
786 // Identifiant de l'enregistrement
787 $idx = $this->getVal($this->clePrimaire);
788
789 // Vérification de l'existence du paramètre
790 if (!isset($val["dossier"]) || $val["dossier"] === "") {
791 $this->correct = false;
792 $this->addToMessage(_("Aucun numero de dossier saisi."));
793 return $this->end_treatment(__METHOD__, false);
794 }
795
796 // Vérification de l'existence du dossier
797 $dossier = $val["dossier"];
798 $sql = sprintf(
799 'SELECT dossier FROM %sdossier WHERE dossier = \'%s\'',
800 DB_PREFIXE,
801 $this->f->db->escapeSimple($dossier)
802 );
803 $res = $this->f->db->query($sql);
804 $this->f->addToLog(
805 __METHOD__."(): db->query(\"".$sql."\");",
806 VERBOSE_MODE
807 );
808 $this->f->isDatabaseError($res);
809
810 // Si le dossier n'existe pas
811 if ($res->numrows() == 0) {
812 $this->correct = false;
813 $this->addToMessage(_("Ce dossier n'existe pas."));
814 return $this->end_treatment(__METHOD__, false);
815 }
816
817 // Teste si le dossier est déjà à l'ordre du jour
818 $sql = sprintf(
819 'SELECT
820 dossier
821 FROM
822 %sdossier_commission
823 WHERE
824 dossier = \'%s\'
825 AND dossier_commission.commission = %s',
826 DB_PREFIXE,
827 $this->f->db->escapeSimple($dossier),
828 $idx
829 );
830 $res = $this->f->db->query($sql);
831 $this->f->addToLog(
832 __METHOD__."(): db->query(\"".$sql."\");",
833 VERBOSE_MODE
834 );
835 $this->f->isDatabaseError($res);
836
837 // Le dossier est déjà à l'ordre du jour
838 if ($res->numrows() != 0) {
839 $this->correct = false;
840 $this->addToMessage(_("Ce dossier est deja a l'ordre du jour."));
841 return $this->end_treatment(__METHOD__, false);
842 }
843
844 // Récupération du type de commission
845 $inst_commission_type = $this->get_inst_commission_type();
846 $commission_type_id = $inst_commission_type->getVal($inst_commission_type->clePrimaire);
847
848 // Tableau des données du nouveau dossier à passer en commission
849 $data = array(
850 "dossier_commission" => null,
851 "dossier" => $dossier,
852 "commission_type" => $commission_type_id,
853 "date_souhaitee" => date("d/m/Y"),
854 "motivation" => null,
855 "commission" => $idx,
856 "avis" => null,
857 "lu" => false,
858 );
859
860 // Ajout du nouveau dossier
861 require_once "../obj/dossier_commission.class.php";
862 $dossier_commission = new dossier_commission("]", $this->f->db, null);
863 $ret = $dossier_commission->ajouter($data);
864 if ($ret !== true) {
865 $this->correct = false;
866 $this->addToMessage(_("Une erreur s'est produite lors de l'ajout de ce dossier. Veuillez contacter votre administrateur."));
867 return $this->end_treatment(__METHOD__, false);
868 }
869
870 // Le dossier a bien été ajouté
871 $this->addToMessage(_("Dossier ajoute avec succes."));
872 return $this->end_treatment(__METHOD__, true);
873 }
874
875 /**
876 * TREATMENT - diffuse_document.
877 *
878 * @return boolean
879 */
880 function diffuse_document($val = array()) {
881 //
882 $this->begin_treatment(__METHOD__);
883 // Identifiant de l'enregistrement
884 $idx = $this->getVal($this->clePrimaire);
885
886 /**
887 * Définition des paramètres.
888 */
889 //
890 if ($this->getParameter("maj") == 11) {
891 $obj = "commission_ordre_jour";
892 $mention = "OJ";
893 $type = "de l'ordre du jour";
894 $champ = "ordre_jour";
895 } elseif ($this->getParameter("maj") == 12) {
896 $obj = "commission_compte_rendu";
897 $mention = "CR";
898 $type = "du compte-rendu";
899 $champ = "compte_rendu";
900 }
901
902 /**
903 * Composition du PDF.
904 */
905 //
906 $pdf_result = $this->compute_pdf_output(
907 "etat",
908 $obj,
909 null,
910 $idx
911 );
912
913 /**
914 * Envoi du mail.
915 */
916 $sql = "
917 SELECT
918 commission.listes_de_diffusion as listes_de_diffusion,
919 commission.code as code,
920 to_char(commission.date_commission, 'DD/MM/YYYY') as date_commission,
921 commission.libelle as libelle, commission_type.corps_du_courriel as corps_du_courriel
922 FROM
923 ".DB_PREFIXE."commission
924 LEFT JOIN
925 ".DB_PREFIXE."commission_type
926 ON
927 commission.commission_type = commission_type.commission_type
928 WHERE
929 commission.commission = ".$idx;
930 $res = $this->f->db->query($sql);
931 $this->f->addTolog(
932 __METHOD__." : db->query(\"".$sql."\");",
933 VERBOSE_MODE
934 );
935 $this->f->isDatabaseError($res);
936 $row =& $res->fetchRow(DB_FETCHMODE_ASSOC);
937 //
938 $titre = "[".$mention."] ".$row['date_commission']." ".$row['libelle'];
939 //
940 $corps = utf8_decode($row['corps_du_courriel']);
941 //
942 $listes_de_diffusion = str_replace(
943 "\r\n",
944 ',',
945 $row['listes_de_diffusion']
946 );
947 //
948 $piece_jointe = array(
949 "content" => $pdf_result['pdf_output'],
950 "title" => $mention."_".str_replace('/', '-', $row['date_commission'])."_".$row['code'].".pdf",
951 "stream" => '',
952 );
953 //
954 $ret = $this->f->sendMail(
955 $titre,
956 $corps,
957 $listes_de_diffusion,
958 array($piece_jointe)
959 );
960
961 /**
962 * Si une erreur survient lors de l'envoi du mail, on stoppe le traitement.
963 */
964 //
965 if ($ret !== true) {
966 $this->addToMessage(
967 sprintf(
968 _("Une erreur s'est produite lors de la diffusion %s. Veuillez contacter votre administrateur."),
969 $type
970 )
971 );
972 $this->correct = false;
973 return $this->end_treatment(__METHOD__, false);
974 }
975
976 /**
977 *
978 */
979 $ret = $this->finalise_document(array("champ" => $champ, ));
980 if ($ret !== true) {
981 $this->addToMessage(_("Une erreur s'est produite lors de la finalisation du document."));
982 $this->correct = false;
983 return $this->end_treatment(__METHOD__, false);
984 }
985
986 /**
987 *
988 */
989 $this->addToMessage(
990 sprintf(
991 _("La diffusion %s s'est effectuée avec succès."),
992 $type
993 )
994 );
995 $this->correct = true;
996 return $this->end_treatment(__METHOD__, true);
997 }
998
999 /**
1000 * TREATMENT - finalise_document.
1001 *
1002 * Finalisation des documents.
1003 *
1004 * @return boolean
1005 */
1006 function finalise_document($val = array()) {
1007 //
1008 $this->begin_treatment(__METHOD__);
1009 // Identifiant de l'enregistrement
1010 $idx = $this->getVal($this->clePrimaire);
1011 //
1012 $champ = $val["champ"];
1013
1014 /**
1015 * Génération du fichier PDF et de ses métadonnées avant le stockage.
1016 */
1017 // Génération du fichier PDF.
1018 $pdf_result = $this->compute_pdf_output(
1019 "etat",
1020 'commission_'.$champ,
1021 null,
1022 $idx
1023 );
1024 // Composition des métadonnées du document.
1025 $metadata = array_merge(
1026 array(
1027 'filename' => 'commission_'.$champ.'_'.$idx.'.pdf',
1028 'mimetype' => 'application/pdf',
1029 'size' => strlen($pdf_result["pdf_output"])
1030 ),
1031 $this->getMetadata("om_fichier_commission_".$champ)
1032 );
1033 //Si le document a déjà été finalisé
1034 //on met à jour le document mais pas son uid
1035 if ( $this->getVal("om_final_commission_".$champ) != 'f' ){
1036 $uid = $this->f->storage->update(
1037 $this->getVal("om_fichier_commission_".$champ), $pdf_result["pdf_output"], $metadata);
1038 }
1039 //Sinon, on joute le document et on récupère son uid
1040 else {
1041 //Stockage du PDF
1042 $uid = $this->f->storage->create($pdf_result["pdf_output"], $metadata);
1043 }
1044
1045 // Si le document n'a pas pu être stocké
1046 if ($uid == "" || $uid == 'OP_FAILURE') {
1047 $log_msg_error = "Finalisation non enregistrée - id commission_%s = %s - uid fichier = %s";
1048 $this->addToLog(sprintf($log_msg_error, $champ, $idx, $uid));
1049 $this->correct = false;
1050 return $this->end_treatment(__METHOD__, false);
1051 }
1052
1053 // Modifie uniquement les valeurs des champs concernant la finalisation
1054 // du document
1055 $valF = array(
1056 "om_final_commission_".$champ => true,
1057 "om_fichier_commission_".$champ => $uid
1058 );
1059 // Execution de la requête de modification des donnees de l'attribut
1060 // valF de l'objet dans l'attribut table de l'objet
1061 $res = $this->db->autoExecute(
1062 DB_PREFIXE.$this->table,
1063 $valF,
1064 DB_AUTOQUERY_UPDATE,
1065 $this->getCle($idx)
1066 );
1067 // Si une erreur survient
1068 if (database::isError($res)) {
1069 // Appel de la methode de recuperation des erreurs
1070 $this->erreur_db($res->getDebugInfo(), $res->getMessage(), '');
1071 $this->correct = false;
1072 return $this->end_treatment(__METHOD__, false);
1073 }
1074
1075 // Log
1076 $this->addToLog(_("Requete executee"), VERBOSE_MODE);
1077 // Log
1078 $message = _("Enregistrement")."&nbsp;".$idx."&nbsp;";
1079 $message .= _("de la table")."&nbsp;\"".$this->table."\"&nbsp;";
1080 $message .= "[&nbsp;".$this->db->affectedRows()."&nbsp;";
1081 $message .= _("enregistrement(s) mis a jour")."&nbsp;]";
1082 $this->addToLog($message, VERBOSE_MODE);
1083 //
1084 return $this->end_treatment(__METHOD__, true);
1085
1086 }
1087
1088 // {{{ Gestion des métadonnées pour les fichiers
1089
1090 /**
1091 *
1092 */
1093 var $metadata = array(
1094 "om_fichier_commission_ordre_jour" => array(
1095 "dossier" => "getDossier",
1096 "dossier_version" => "getDossierVersion",
1097 "numDemandeAutor" => "getNumDemandeAutor",
1098 "anneemoisDemandeAutor" => "getAnneemoisDemandeAutor",
1099 "typeInstruction" => "getTypeInstruction",
1100 "statutAutorisation" => "getStatutAutorisation",
1101 "typeAutorisation" => "getTypeAutorisation",
1102 "dateEvenementDocument" => "getDateEvenementDocument",
1103 "groupeInstruction" => 'getGroupeInstruction',
1104 "title" => 'getTitleOrdreCommission',
1105 ),
1106 "om_fichier_commission_compte_rendu" => array(
1107 "dossier" => "getDossier",
1108 "dossier_version" => "getDossierVersion",
1109 "numDemandeAutor" => "getNumDemandeAutor",
1110 "anneemoisDemandeAutor" => "getAnneemoisDemandeAutor",
1111 "typeInstruction" => "getTypeInstruction",
1112 "statutAutorisation" => "getStatutAutorisation",
1113 "typeAutorisation" => "getTypeAutorisation",
1114 "dateEvenementDocument" => "getDateEvenementDocument",
1115 "groupeInstruction" => 'getGroupeInstruction',
1116 "title" => 'getTitleCompteRenduCommission',
1117 ),
1118 );
1119
1120 /**
1121 * Récupération du numéro de dossier d'instruction à ajouter aux métadonnées
1122 * @return chaîne vide
1123 */
1124 protected function getDossier() {
1125 return "COMMISSION_".$this->getVal('date_commission');
1126 }
1127
1128 /**
1129 * Récupération la version du dossier d'instruction à ajouter aux métadonnées
1130 * @return chaîne vide
1131 */
1132 protected function getDossierVersion() {
1133 return "";
1134 }
1135
1136 /**
1137 * Récupération du numéro de dossier d'autorisation à ajouter aux métadonnées
1138 * @return chaîne vide
1139 */
1140 protected function getNumDemandeAutor() {
1141 return "";
1142 }
1143
1144 /**
1145 * Récupération de la date de demande initiale du dossier à ajouter aux métadonnées
1146 * @return chaîne vide
1147 */
1148 protected function getAnneemoisDemandeAutor() {
1149 return "";
1150 }
1151
1152 /**
1153 * Récupération du type de dossier d'instruction à ajouter aux métadonnées
1154 * @return chaîne vide
1155 */
1156 protected function getTypeInstruction() {
1157 return "";
1158 }
1159
1160 /**
1161 * Récupération du statut du dossier d'autorisation à ajouter aux métadonnées
1162 * @return chaîne vide
1163 */
1164 protected function getStatutAutorisation() {
1165 return "";
1166 }
1167
1168 /**
1169 * Récupération du type de dossier d'autorisation à ajouter aux métadonnées
1170 * @return chaîne vide
1171 */
1172 protected function getTypeAutorisation() {
1173 return "";
1174 }
1175
1176 /**
1177 * Récupération de la date d'ajout de document à ajouter aux métadonnées
1178 * @return date de l'évènement
1179 */
1180 protected function getDateEvenementDocument() {
1181 return date("Y-m-d");
1182 }
1183
1184 /**
1185 * Récupération du groupe d'instruction à ajouter aux métadonnées
1186 * @return string Groupe d'instruction
1187 */
1188 protected function getGroupeInstruction() {
1189 return "ADS";
1190 }
1191
1192 /**
1193 * Récupération du type du document à ajouter aux métadonnées
1194 * @return string Type de document
1195 */
1196 protected function getTitleOrdreCommission() {
1197 return 'Ordre du jour : '.$this->getVal($this->clePrimaire).'_'.$this->getVal('libelle');
1198 }
1199
1200 /**
1201 * Récupération du type du document à ajouter aux métadonnées
1202 * @return string Type de document
1203 */
1204 protected function getTitleCompteRenduCommission() {
1205 return 'Compte-rendu : '.$this->getVal($this->clePrimaire).'_'.$this->getVal('libelle');
1206 }
1207
1208 // }}}
1209
1210 }
1211
1212 ?>

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26