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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5254 - (hide annotations)
Fri Nov 25 10:59:14 2016 UTC (8 years, 2 months ago) by nhaye
File size: 40161 byte(s)
Merge de la branche d'application des nouvelles actions (passage des lots en nouvelles actions)

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26