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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6565 - (hide annotations)
Fri Apr 21 16:14:15 2017 UTC (7 years, 9 months ago) by softime
File size: 40951 byte(s)
Merge de la version 4.0.0

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 softime 6565 $sql = "SELECT dossier
794     FROM ".DB_PREFIXE."dossier
795     INNER JOIN ".DB_PREFIXE."dossier_instruction_type
796     ON dossier.dossier_instruction_type = dossier_instruction_type.dossier_instruction_type
797     INNER JOIN ".DB_PREFIXE."dossier_autorisation_type_detaille
798     ON dossier_instruction_type.dossier_autorisation_type_detaille = dossier_autorisation_type_detaille.dossier_autorisation_type_detaille
799     INNER JOIN ".DB_PREFIXE."dossier_autorisation_type
800     ON dossier_autorisation_type_detaille.dossier_autorisation_type = dossier_autorisation_type.dossier_autorisation_type
801     INNER JOIN ".DB_PREFIXE."groupe
802     ON dossier_autorisation_type.groupe = groupe.groupe
803     AND groupe.code != 'CTX'
804     WHERE dossier = '".$this->f->db->escapeSimple($dossier)."'";
805 jymadier 4554 $res = $this->f->db->query($sql);
806     $this->f->addToLog(
807     __METHOD__."(): db->query(\"".$sql."\");",
808     VERBOSE_MODE
809     );
810     $this->f->isDatabaseError($res);
811    
812     // Si le dossier n'existe pas
813     if ($res->numrows() == 0) {
814     $this->correct = false;
815     $this->addToMessage(_("Ce dossier n'existe pas."));
816     return $this->end_treatment(__METHOD__, false);
817     }
818    
819     // Teste si le dossier est déjà à l'ordre du jour
820     $sql = sprintf(
821     'SELECT
822     dossier
823     FROM
824     %sdossier_commission
825     WHERE
826     dossier = \'%s\'
827     AND dossier_commission.commission = %s',
828     DB_PREFIXE,
829     $this->f->db->escapeSimple($dossier),
830     $idx
831     );
832     $res = $this->f->db->query($sql);
833     $this->f->addToLog(
834     __METHOD__."(): db->query(\"".$sql."\");",
835     VERBOSE_MODE
836     );
837     $this->f->isDatabaseError($res);
838    
839     // Le dossier est déjà à l'ordre du jour
840     if ($res->numrows() != 0) {
841     $this->correct = false;
842     $this->addToMessage(_("Ce dossier est deja a l'ordre du jour."));
843     return $this->end_treatment(__METHOD__, false);
844     }
845    
846     // Récupération du type de commission
847     $inst_commission_type = $this->get_inst_commission_type();
848     $commission_type_id = $inst_commission_type->getVal($inst_commission_type->clePrimaire);
849    
850     // Tableau des données du nouveau dossier à passer en commission
851     $data = array(
852     "dossier_commission" => null,
853     "dossier" => $dossier,
854     "commission_type" => $commission_type_id,
855     "date_souhaitee" => date("d/m/Y"),
856     "motivation" => null,
857     "commission" => $idx,
858     "avis" => null,
859     "lu" => false,
860     );
861    
862     // Ajout du nouveau dossier
863     require_once "../obj/dossier_commission.class.php";
864     $dossier_commission = new dossier_commission("]", $this->f->db, null);
865     $ret = $dossier_commission->ajouter($data);
866     if ($ret !== true) {
867     $this->correct = false;
868     $this->addToMessage(_("Une erreur s'est produite lors de l'ajout de ce dossier. Veuillez contacter votre administrateur."));
869     return $this->end_treatment(__METHOD__, false);
870     }
871    
872     // Le dossier a bien été ajouté
873     $this->addToMessage(_("Dossier ajoute avec succes."));
874     return $this->end_treatment(__METHOD__, true);
875     }
876    
877     /**
878     * TREATMENT - diffuse_document.
879     *
880     * @return boolean
881     */
882     function diffuse_document($val = array()) {
883     //
884     $this->begin_treatment(__METHOD__);
885     // Identifiant de l'enregistrement
886     $idx = $this->getVal($this->clePrimaire);
887    
888     /**
889     * Définition des paramètres.
890     */
891     //
892     if ($this->getParameter("maj") == 11) {
893     $obj = "commission_ordre_jour";
894     $mention = "OJ";
895     $type = "de l'ordre du jour";
896     $champ = "ordre_jour";
897     } elseif ($this->getParameter("maj") == 12) {
898     $obj = "commission_compte_rendu";
899     $mention = "CR";
900     $type = "du compte-rendu";
901     $champ = "compte_rendu";
902     }
903    
904     /**
905     * Composition du PDF.
906     */
907     //
908     $pdf_result = $this->compute_pdf_output(
909     "etat",
910     $obj,
911     null,
912     $idx
913     );
914    
915     /**
916     * Envoi du mail.
917     */
918     $sql = "
919     SELECT
920     commission.listes_de_diffusion as listes_de_diffusion,
921     commission.code as code,
922     to_char(commission.date_commission, 'DD/MM/YYYY') as date_commission,
923     commission.libelle as libelle, commission_type.corps_du_courriel as corps_du_courriel
924     FROM
925     ".DB_PREFIXE."commission
926     LEFT JOIN
927     ".DB_PREFIXE."commission_type
928     ON
929     commission.commission_type = commission_type.commission_type
930     WHERE
931     commission.commission = ".$idx;
932     $res = $this->f->db->query($sql);
933     $this->f->addTolog(
934     __METHOD__." : db->query(\"".$sql."\");",
935     VERBOSE_MODE
936     );
937     $this->f->isDatabaseError($res);
938     $row =& $res->fetchRow(DB_FETCHMODE_ASSOC);
939     //
940     $titre = "[".$mention."] ".$row['date_commission']." ".$row['libelle'];
941     //
942     $corps = utf8_decode($row['corps_du_courriel']);
943     //
944     $listes_de_diffusion = str_replace(
945     "\r\n",
946     ',',
947     $row['listes_de_diffusion']
948     );
949     //
950     $piece_jointe = array(
951     "content" => $pdf_result['pdf_output'],
952     "title" => $mention."_".str_replace('/', '-', $row['date_commission'])."_".$row['code'].".pdf",
953     "stream" => '',
954     );
955     //
956     $ret = $this->f->sendMail(
957     $titre,
958     $corps,
959     $listes_de_diffusion,
960     array($piece_jointe)
961     );
962    
963     /**
964     * Si une erreur survient lors de l'envoi du mail, on stoppe le traitement.
965     */
966     //
967     if ($ret !== true) {
968     $this->addToMessage(
969     sprintf(
970     _("Une erreur s'est produite lors de la diffusion %s. Veuillez contacter votre administrateur."),
971     $type
972     )
973     );
974     $this->correct = false;
975     return $this->end_treatment(__METHOD__, false);
976     }
977    
978     /**
979     *
980     */
981     $ret = $this->finalise_document(array("champ" => $champ, ));
982     if ($ret !== true) {
983     $this->addToMessage(_("Une erreur s'est produite lors de la finalisation du document."));
984     $this->correct = false;
985     return $this->end_treatment(__METHOD__, false);
986     }
987    
988     /**
989     *
990     */
991     $this->addToMessage(
992     sprintf(
993     _("La diffusion %s s'est effectuée avec succès."),
994     $type
995     )
996     );
997     $this->correct = true;
998     return $this->end_treatment(__METHOD__, true);
999     }
1000    
1001     /**
1002     * TREATMENT - finalise_document.
1003     *
1004     * Finalisation des documents.
1005     *
1006     * @return boolean
1007     */
1008     function finalise_document($val = array()) {
1009     //
1010     $this->begin_treatment(__METHOD__);
1011     // Identifiant de l'enregistrement
1012     $idx = $this->getVal($this->clePrimaire);
1013     //
1014     $champ = $val["champ"];
1015    
1016     /**
1017     * Génération du fichier PDF et de ses métadonnées avant le stockage.
1018     */
1019     // Génération du fichier PDF.
1020     $pdf_result = $this->compute_pdf_output(
1021     "etat",
1022     'commission_'.$champ,
1023     null,
1024     $idx
1025     );
1026     // Composition des métadonnées du document.
1027     $metadata = array_merge(
1028     array(
1029     'filename' => 'commission_'.$champ.'_'.$idx.'.pdf',
1030     'mimetype' => 'application/pdf',
1031     'size' => strlen($pdf_result["pdf_output"])
1032     ),
1033     $this->getMetadata("om_fichier_commission_".$champ)
1034     );
1035 nmeucci 4649 //Si le document a déjà été finalisé
1036     //on met à jour le document mais pas son uid
1037     if ( $this->getVal("om_final_commission_".$champ) != 'f' ){
1038     $uid = $this->f->storage->update(
1039     $this->getVal("om_fichier_commission_".$champ), $pdf_result["pdf_output"], $metadata);
1040     }
1041     //Sinon, on joute le document et on récupère son uid
1042     else {
1043     //Stockage du PDF
1044     $uid = $this->f->storage->create($pdf_result["pdf_output"], $metadata);
1045     }
1046 jymadier 4554
1047     // Si le document n'a pas pu être stocké
1048     if ($uid == "" || $uid == 'OP_FAILURE') {
1049 softime 5169 $log_msg_error = "Finalisation non enregistrée - id commission_%s = %s - uid fichier = %s";
1050     $this->addToLog(sprintf($log_msg_error, $champ, $idx, $uid));
1051 jymadier 4554 $this->correct = false;
1052     return $this->end_treatment(__METHOD__, false);
1053 mbroquet 3730 }
1054 jymadier 4554
1055     // Modifie uniquement les valeurs des champs concernant la finalisation
1056     // du document
1057     $valF = array(
1058     "om_final_commission_".$champ => true,
1059     "om_fichier_commission_".$champ => $uid
1060     );
1061     // Execution de la requête de modification des donnees de l'attribut
1062     // valF de l'objet dans l'attribut table de l'objet
1063     $res = $this->db->autoExecute(
1064     DB_PREFIXE.$this->table,
1065     $valF,
1066     DB_AUTOQUERY_UPDATE,
1067     $this->getCle($idx)
1068     );
1069     // Si une erreur survient
1070     if (database::isError($res)) {
1071     // Appel de la methode de recuperation des erreurs
1072     $this->erreur_db($res->getDebugInfo(), $res->getMessage(), '');
1073     $this->correct = false;
1074     return $this->end_treatment(__METHOD__, false);
1075     }
1076    
1077     // Log
1078     $this->addToLog(_("Requete executee"), VERBOSE_MODE);
1079     // Log
1080     $message = _("Enregistrement")."&nbsp;".$idx."&nbsp;";
1081     $message .= _("de la table")."&nbsp;\"".$this->table."\"&nbsp;";
1082     $message .= "[&nbsp;".$this->db->affectedRows()."&nbsp;";
1083     $message .= _("enregistrement(s) mis a jour")."&nbsp;]";
1084     $this->addToLog($message, VERBOSE_MODE);
1085     //
1086     return $this->end_treatment(__METHOD__, true);
1087    
1088 mbroquet 3730 }
1089    
1090 jymadier 4554 // {{{ Gestion des métadonnées pour les fichiers
1091    
1092 mbroquet 3730 /**
1093 jymadier 4554 *
1094     */
1095     var $metadata = array(
1096     "om_fichier_commission_ordre_jour" => array(
1097     "dossier" => "getDossier",
1098     "dossier_version" => "getDossierVersion",
1099     "numDemandeAutor" => "getNumDemandeAutor",
1100     "anneemoisDemandeAutor" => "getAnneemoisDemandeAutor",
1101     "typeInstruction" => "getTypeInstruction",
1102     "statutAutorisation" => "getStatutAutorisation",
1103     "typeAutorisation" => "getTypeAutorisation",
1104     "dateEvenementDocument" => "getDateEvenementDocument",
1105     "groupeInstruction" => 'getGroupeInstruction',
1106     "title" => 'getTitleOrdreCommission',
1107     ),
1108     "om_fichier_commission_compte_rendu" => array(
1109     "dossier" => "getDossier",
1110     "dossier_version" => "getDossierVersion",
1111     "numDemandeAutor" => "getNumDemandeAutor",
1112     "anneemoisDemandeAutor" => "getAnneemoisDemandeAutor",
1113     "typeInstruction" => "getTypeInstruction",
1114     "statutAutorisation" => "getStatutAutorisation",
1115     "typeAutorisation" => "getTypeAutorisation",
1116     "dateEvenementDocument" => "getDateEvenementDocument",
1117     "groupeInstruction" => 'getGroupeInstruction',
1118     "title" => 'getTitleCompteRenduCommission',
1119     ),
1120     );
1121    
1122     /**
1123 mbroquet 3730 * Récupération du numéro de dossier d'instruction à ajouter aux métadonnées
1124     * @return chaîne vide
1125     */
1126     protected function getDossier() {
1127 nmeucci 4275 return "COMMISSION_".$this->getVal('date_commission');
1128 mbroquet 3730 }
1129 jymadier 4554
1130 mbroquet 3730 /**
1131     * Récupération la version du dossier d'instruction à ajouter aux métadonnées
1132     * @return chaîne vide
1133     */
1134     protected function getDossierVersion() {
1135     return "";
1136     }
1137 jymadier 4554
1138 mbroquet 3730 /**
1139     * Récupération du numéro de dossier d'autorisation à ajouter aux métadonnées
1140     * @return chaîne vide
1141     */
1142     protected function getNumDemandeAutor() {
1143     return "";
1144     }
1145 jymadier 4554
1146 mbroquet 3730 /**
1147     * Récupération de la date de demande initiale du dossier à ajouter aux métadonnées
1148     * @return chaîne vide
1149     */
1150     protected function getAnneemoisDemandeAutor() {
1151     return "";
1152     }
1153 jymadier 4554
1154 mbroquet 3730 /**
1155     * Récupération du type de dossier d'instruction à ajouter aux métadonnées
1156     * @return chaîne vide
1157     */
1158     protected function getTypeInstruction() {
1159     return "";
1160     }
1161 jymadier 4554
1162 mbroquet 3730 /**
1163     * Récupération du statut du dossier d'autorisation à ajouter aux métadonnées
1164     * @return chaîne vide
1165     */
1166     protected function getStatutAutorisation() {
1167     return "";
1168     }
1169 jymadier 4554
1170 mbroquet 3730 /**
1171     * Récupération du type de dossier d'autorisation à ajouter aux métadonnées
1172     * @return chaîne vide
1173     */
1174     protected function getTypeAutorisation() {
1175     return "";
1176     }
1177 jymadier 4554
1178 mbroquet 3730 /**
1179     * Récupération de la date d'ajout de document à ajouter aux métadonnées
1180     * @return date de l'évènement
1181     */
1182     protected function getDateEvenementDocument() {
1183     return date("Y-m-d");
1184     }
1185 jymadier 4554
1186 mbroquet 3730 /**
1187     * Récupération du groupe d'instruction à ajouter aux métadonnées
1188     * @return string Groupe d'instruction
1189     */
1190     protected function getGroupeInstruction() {
1191     return "ADS";
1192     }
1193 jymadier 4554
1194 mbroquet 3730 /**
1195     * Récupération du type du document à ajouter aux métadonnées
1196     * @return string Type de document
1197     */
1198     protected function getTitleOrdreCommission() {
1199 nmeucci 4275 return 'Ordre du jour : '.$this->getVal($this->clePrimaire).'_'.$this->getVal('libelle');
1200 mbroquet 3730 }
1201 jymadier 4554
1202 mbroquet 3730 /**
1203     * Récupération du type du document à ajouter aux métadonnées
1204     * @return string Type de document
1205     */
1206     protected function getTitleCompteRenduCommission() {
1207 nmeucci 4275 return 'Compte-rendu : '.$this->getVal($this->clePrimaire).'_'.$this->getVal('libelle');
1208 mbroquet 3730 }
1209 jymadier 4554
1210     // }}}
1211    
1212     }
1213    
1214     ?>

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26