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

Diff of /trunk/obj/instruction.class.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1571 by nhaye, Thu Mar 28 12:22:00 2013 UTC revision 2119 by vpihour, Tue Jul 30 17:10:13 2013 UTC
# Line 32  class instruction extends instruction_ge Line 32  class instruction extends instruction_ge
32      var $archive_date_depot; // specific      var $archive_date_depot; // specific
33      var $retourformulaire;   // specific      var $retourformulaire;   // specific
34      var $idxformulaire;      // specific      var $idxformulaire;      // specific
35        var $valEvenement;
36        // Tableau contenant une partie des métadonnées arrêtés
37        var $metadonneesArrete;
38    
39        var $metadata = array(
40            "om_fichier_instruction" => array(
41                "dossier" => "getDossier",
42                "dossier_version" => "getDossierVersion",
43                "numDemandeAutor" => "getNumDemandeAutor",
44                "anneemoisDemandeAutor" => "getAnneemoisDemandeAutor",
45                "typeInstruction" => "getTypeInstruction",
46                "statutAutorisation" => "getStatutAutorisation",
47                "typeAutorisation" => "getTypeAutorisation",
48                "dateEvenementDocument" => "getDateEvenementDocument",
49                "groupeInstruction" => 'getGroupeInstruction',
50                "title" => 'getTitle',
51            ),
52        );
53    
54    
55      function instruction($id, &$db, $debug) {      function instruction($id, &$db, $debug) {
56          $this->constructeur($id, $db, $debug);          $this->constructeur($id, $db, $debug);
# Line 51  class instruction extends instruction_ge Line 70  class instruction extends instruction_ge
70              && isset($this->f->om_utilisateur["division"])              && isset($this->f->om_utilisateur["division"])
71              && $this->f->om_utilisateur["division"] != $this->getDivisionFromDossier()) {              && $this->f->om_utilisateur["division"] != $this->getDivisionFromDossier()) {
72              //              //
73              $this->actions_sup = array();              //On cache les liens d'action
74              $this->setParameter("actions", array());              $this->parameters["actions"]["modifier"] = NULL;
75                $this->parameters["actions"]["supprimer"] = NULL;
76                $this->actions_sup["finalisation"] = NULL;
77          }          }
78          // Si une action 'lu' est présente et que le champ lu est à true          // Si une action 'lu' est présente et que le champ lu est à true
79          // on supprime l'action          // on supprime l'action
# Line 61  class instruction extends instruction_ge Line 82  class instruction extends instruction_ge
82              && $this->val[array_search("lu", $this->champs)]== "t") {              && $this->val[array_search("lu", $this->champs)]== "t") {
83              unset($this->actions_sup["lu"]);              unset($this->actions_sup["lu"]);
84          }          }
85                
86            //Si le document est déjà finalisé, on affiche uniquement le lien de
87            //dé-finalisation
88            $om_final_instruction = $this->getVal("om_final_instruction");
89            if ( isset($this->actions_sup["finalisation"]) &&
90                $om_final_instruction== "t" ){
91                    
92                //On cache les liens d'action
93                $this->parameters["actions"]["modifier"] = NULL;
94                $this->parameters["actions"]["supprimer"] = NULL;
95                //On cache le lien de finalisation et on affiche le bon lien pour l'édition
96                $this->actions_sup["finalisation"] = NULL;
97                $this->actions_sup["pdfetat"]["lien"] = "../spg/file.php?id=";
98                $this->actions_sup["pdfetat"]["id"] =
99                    "&obj=instruction&champ=om_fichier_instruction";
100            }
101            //Si le document n'est pas finalisé, on affiche uniquement le lien de
102            //finalisation
103            if ( isset($this->actions_sup["definalisation"]) &&
104                $om_final_instruction!= "t" ){
105                    
106                //On cache le lien de finalisation et on affiche le bon lien pour l'édition
107                $this->actions_sup["definalisation"] = NULL;
108                $this->actions_sup["pdfetat"]["lien"] = "../app/pdf_instruction.php?idx=";
109                $this->actions_sup["pdfetat"]["id"] = "";
110            }
111            
112            $idxformulaire = $this->getParameter("idxformulaire");
113            $retourformulaire = $this->getParameter("retourformulaire");
114            //Si le dossier d'instruction auquel est rattachée l'instruction est cloturé,
115            //on affiche pas les liens du portlet
116            if ( $idxformulaire != '' &&
117                (
118                    $retourformulaire == 'dossier' ||
119                    $retourformulaire == 'dossier_instruction' ||
120                    $retourformulaire == 'dossier_instruction_mes_encours' ||
121                    $retourformulaire == 'dossier_instruction_tous_encours' ||
122                    $retourformulaire == 'dossier_instruction_mes_clotures' ||
123                    $retourformulaire == 'dossier_instruction_tous_clotures'
124                )){
125    
126                //On récuppère le statut du dossier d'instruction        
127                $statut = $this->getStatutAutorisationDossier($idxformulaire);
128                if ( $this->f->isUserInstructeur() && $statut == "cloture" ){
129                    
130                    //On cache le lien de modification
131                    $this->parameters["actions"]["modifier"] = NULL;
132                    $this->actions_sup["finalisation"] = NULL;
133                    $this->actions_sup["definalisation"] = NULL;
134                }
135            }
136      }      }
137    
138      /**      /**
# Line 74  class instruction extends instruction_ge Line 146  class instruction extends instruction_ge
146              && $this->f->om_utilisateur["division"] != $this->getDivisionFromDossier()              && $this->f->om_utilisateur["division"] != $this->getDivisionFromDossier()
147              && $this->getParameter("maj") != 3) {              && $this->getParameter("maj") != 3) {
148              //              //
149                $this->addToLog("canAccess(): utilisateur instructeur sur un dossier d'une autre division", EXTRA_VERBOSE_MODE);
150                return false;
151            }
152    
153            $retourformulaire = $this->getParameter("retourformulaire");
154            // Si l'utilisateur est un instructeur et que le dossier est cloturé
155            if ( $this->f->isUserInstructeur() &&
156                $this->getStatutAutorisationDossier($this->getParameter("idxformulaire")) == "cloture" &&
157                (
158                    $retourformulaire == 'dossier' ||
159                    $retourformulaire == 'dossier_instruction' ||
160                    $retourformulaire == 'dossier_instruction_mes_encours' ||
161                    $retourformulaire == 'dossier_instruction_tous_encours' ||
162                    $retourformulaire == 'dossier_instruction_mes_clotures' ||
163                    $retourformulaire == 'dossier_instruction_tous_clotures'
164                )
165                && $this->getParameter("maj") != 3 && $this->getParameter("maj") != 0 ) {
166                
167              return false;              return false;
168          }          }
169          //          //
# Line 81  class instruction extends instruction_ge Line 171  class instruction extends instruction_ge
171      }      }
172    
173      /**      /**
174       * Cette méthode permet de récupérer la division d'un dossier       * Cette variable permet de stocker le résultat de la méthode
175         * getDivisionFromDossier() afin de ne pas effectuer le recalcul à chacun de
176         * ces appels.
177         * @var string Code de la division du dossier en cours
178         */
179        var $_division_from_dossier = NULL;
180    
181        /**
182         * Cette méthode permet de récupérer le code de division correspondant
183         * au dossier sur lequel on se trouve.
184         *
185         * @return string Code de la division du dossier en cours
186       */       */
187      function getDivisionFromDossier() {      function getDivisionFromDossier() {
188    
189            // Cette méthode peut être appelée plusieurs fois lors d'une requête.
190            // Pour éviter de refaire le traitement de recherche de la division
191            // alors on vérifie si nous ne l'avons pas déjà calculé.
192            if ($this->_division_from_dossier != NULL) {
193                // Logger
194                $this->addToLog("getDivisionFromDossier(): retour de la valeur déjà calculée - '".$this->_division_from_dossier."'", EXTRA_VERBOSE_MODE);
195                // On retourne la valeur déjà calculée
196                return $this->_division_from_dossier;
197            }
198    
199            // Par défaut, on définit la valeur du dossier à NULL
200            $dossier = NULL;
201            // Test sur le mode et le contexte du formulaire
202            if ($this->getParameter("maj") == 0
203                && ($this->getParameter("retourformulaire") == "dossier"
204                    || $this->getParameter("retourformulaire") == "dossier_instruction"
205                    || $this->getParameter("retourformulaire") == "dossier_instruction_mes_encours"
206                    || $this->getParameter("retourformulaire") == "dossier_instruction_tous_encours"
207                    || $this->getParameter("retourformulaire") == "dossier_instruction_mes_clotures"
208                    || $this->getParameter("retourformulaire") == "dossier_instruction_tous_clotures")) {
209                // Si on se trouve en mode AJOUT (seul mode où l'enregistrement
210                // n'existe pas en base de données) ET que nous nous trouvons
211                // dans le contexte d'un dossier d'instruction alors on récupère
212                // le numéro de dossier depuis le paramètre 'idxformulaire'
213                $dossier = $this->getParameter("idxformulaire");
214            } else {
215                // Sinon on récupère le numéro de dossier dans le champs dossier de
216                // l'enregistrement (en base de données)
217                $dossier = $this->getVal("dossier");
218            }
219    
220            // On appelle la méthode de la classe utils qui renvoi le code de la
221            // division d'un dossier, on la stocke pour ne pas refaire le calcul au
222            // prochain appel de cette méthode
223            $this->_division_from_dossier = $this->f->getDivisionFromDossier($dossier);
224            // Logger
225            $this->addToLog("getDivisionFromDossier(): retour de la valeur nouvellement calculée - '".$this->_division_from_dossier."'", EXTRA_VERBOSE_MODE);
226            // On retourne la valeur retournée
227            return $this->_division_from_dossier;
228    
229        }
230    
231        /**
232         * Cette méthode permet de récupérer le dossier d'autorisation d'un dossier
233         */
234        function getNumDemandeAutorFromDossier($id) {
235          //          //
236          if (!isset($this->val[array_search("dossier", $this->champs)])) {          if (!isset($id)) {
237              return NULL;              return NULL;
238          }          }
239          //          //
240          $sql = "select division from ".DB_PREFIXE."dossier ";          $sql = "select dossier_autorisation from ".DB_PREFIXE."dossier ";
241          $sql .= " where dossier='".$this->val[array_search("dossier", $this->champs)]."'";          $sql .= " where dossier='".$id."'";
242          //          //
243          $division = $this->db->getOne($sql);          $dossier_autorisation = $this->db->getOne($sql);
244          $this->addToLog("getDivisionFromDossier(): db->getone(\"".$sql."\")", VERBOSE_MODE);          $this->addToLog("getNumDemandeAutorFromDossier(): db->getone(\"".$sql."\")", VERBOSE_MODE);
245          database::isError($division);          database::isError($dossier_autorisation);
246          //          //
247          return $division;          return $dossier_autorisation;
248      }      }
249    
250      // }}}      // }}}
# Line 139  class instruction extends instruction_ge Line 287  class instruction extends instruction_ge
287          $form->setType('action', 'hidden');          $form->setType('action', 'hidden');
288          $form->setType('delai_notification', 'hidden');          $form->setType('delai_notification', 'hidden');
289          $form->setType('avis_decision', 'hidden');          $form->setType('avis_decision', 'hidden');
290            $form->setType('autorite_competente', 'hidden');
291          //          //
292          $form->setType('archive_delai', 'hidden');          $form->setType('archive_delai', 'hidden');
293          $form->setType('archive_etat', 'hidden');          $form->setType('archive_etat', 'hidden');
# Line 153  class instruction extends instruction_ge Line 302  class instruction extends instruction_ge
302          $form->setType('archive_date_validite', 'hidden');          $form->setType('archive_date_validite', 'hidden');
303          $form->setType('archive_date_achevement', 'hidden');          $form->setType('archive_date_achevement', 'hidden');
304          $form->setType('archive_date_conformite', 'hidden');          $form->setType('archive_date_conformite', 'hidden');
305          $form->setType('archive_date_chantier', 'hidden');            $form->setType('archive_date_chantier', 'hidden');
306            $form->setType('archive_autorite_competente','hidden');
307          //          //
308          $form->setType('numero_arrete', 'hidden');          $form->setType('numero_arrete', 'hidden');
309            //
310            $form->setType('code_barres', 'hidden');
311                    
312          //          //
313            $form->setType('archive_incompletude','hidden');
314            $form->setType('archive_evenement_suivant_tacite','hidden');
315            $form->setType('archive_evenement_suivant_tacite_incompletude','hidden');
316            $form->setType('archive_etat_pendant_incompletude','hidden');
317            $form->setType('archive_date_limite_incompletude','hidden');
318            $form->setType('archive_delai_incompletude','hidden');
319          if ($maj < 2) { //ajouter et modifier          if ($maj < 2) { //ajouter et modifier
320              $form->setType('destinataire', 'hidden');              $form->setType('destinataire', 'hidden');
321              $form->setType('lettretype', 'hiddenstatic');              $form->setType('lettretype', 'hiddenstatic');
# Line 175  class instruction extends instruction_ge Line 333  class instruction extends instruction_ge
333              $form->setType('date_retour_rar','datedisabled');              $form->setType('date_retour_rar','datedisabled');
334              $form->setType('date_envoi_controle_legalite','datedisabled');              $form->setType('date_envoi_controle_legalite','datedisabled');
335              $form->setType('date_retour_controle_legalite','datedisabled');              $form->setType('date_retour_controle_legalite','datedisabled');
336                $form->setType('date_finalisation_courrier','datedisabled');
337    
338                // l'administrateur peut modifier les champs de retour de date
339                if ($this->f->user_is_admin == true) {
340                    $form->setType('date_retour_signature','date');
341                    $form->setType('date_retour_rar','date');
342                    $form->setType('date_retour_controle_legalite','date');
343                }
344    
345              if($maj==0){ // add              if($maj==0){ // add
346                  $form->setType('instruction', 'hiddenstatic');                  $form->setType('instruction', 'hiddenstatic');
347                  $form->setType('evenement', 'select');                  $form->setType('evenement', 'select');
# Line 199  class instruction extends instruction_ge Line 366  class instruction extends instruction_ge
366              $form->setType('bible', 'hidden');              $form->setType('bible', 'hidden');
367              $form->setType('bible2', 'hidden');              $form->setType('bible2', 'hidden');
368          }          }
369    
370            //Cache les champs pour la finalisation
371            $form->setType('om_fichier_instruction', 'hidden');
372            $form->setType('om_final_instruction', 'hidden');
373            // Cache le document arrêté
374            $form->setType('document_numerise', 'hidden');
375            
376            //Masquer les champs date_envoi_controle_legalite et
377            //date_retour_controle_legalite si ce n'est pas un arrêté
378            if ( !is_numeric($this->getVal("avis_decision"))){
379                
380                $form->setType("date_envoi_controle_legalite", "hidden");
381                $form->setType("date_retour_controle_legalite", "hidden");
382            }
383      }      }
384    
385      function setSelect(&$form, $maj,&$db,$debug) {      function setSelect(&$form, $maj,&$db,$debug) {
# Line 312  class instruction extends instruction_ge Line 493  class instruction extends instruction_ge
493      function cleSecondaire($id, &$db, $val, $DEBUG) {      function cleSecondaire($id, &$db, $val, $DEBUG) {
494          //          //
495          parent::cleSecondaire($id, $db, $val, $DEBUG);          parent::cleSecondaire($id, $db, $val, $DEBUG);
496            
497          /**          // Aucune clé secondaire n'a été trouvée, l'instruction peut être supprimée
498           * Vérification que l'élément supprimé est le dernier pour pouvoir          if ( $this->correct !== false ){
499           * remodifier les données de manière itérative.                      
500           */              /**
501          // Initialisation               * Vérification que l'élément supprimé est le dernier pour pouvoir
502          $dernierevenement = "";               * remodifier les données de manière itérative.
503          // Récupération du dernier élément de la table d'instruction qui               */
504          // concerne le dossier en cours              // Initialisation
505          $sql = "SELECT max(instruction)              $dernierevenement = "";
506          FROM ".DB_PREFIXE."instruction              // Récupération du dernier élément de la table d'instruction qui
507          WHERE dossier ='".$this->idxformulaire."'";              // concerne le dossier en cours
508          $dernierevenement = $db->getOne($sql);              $sql = "SELECT max(instruction)
509          $this->addToLog("setSelect(): db->getone(\"".$sql."\");", VERBOSE_MODE);              FROM ".DB_PREFIXE."instruction
510          if (database::isError($dernierevenement)) {              WHERE dossier ='".$this->idxformulaire."'";
511              die($dernierevenement->getMessage());              $dernierevenement = $db->getOne($sql);
512          }              $this->addToLog("setSelect(): db->getone(\"".$sql."\");", VERBOSE_MODE);
513          // Si on se trouve effectivement sur le dernier evenement d'instruction              if (database::isError($dernierevenement)) {
514          if ($dernierevenement == $id) {                  die($dernierevenement->getMessage());
515              // Alors on valide la suppression              }
516              $this->correct = true;              // Si on se trouve effectivement sur le dernier evenement d'instruction
517              $this->addToMessage(_('Destruction_chronologique'));              if ($dernierevenement == $id) {
518          } else {                  // Alors on valide la suppression
519              // Alors on annule la suppression                  $this->correct = true;
520              $this->correct = false;                  $this->addToMessage(_('Destruction_chronologique'));
521              $this->addToMessage(_("Seul le dernier evenement d'instruction peut etre supprime."));              } else {
522                    // Alors on annule la suppression
523                    $this->correct = false;
524                    $this->addToMessage(_("Seul le dernier evenement d'instruction peut etre supprime."));
525                }
526          }          }
527      }      }
528    
529      // Vérification de la non modification des dates de suivi      // Vérification de la non modification des dates de suivi
530      function updateDate($champ) {      function updateDate($champ) {
531          if($this->valF[$champ] != "") {          if($this->valF[$champ] != "") {
532              if($this->getVal($champ) != "" AND $this->getVal($champ) != $this->valF[$champ]) {  
533                  $this->correct = false;              // si l'utilisateur n'est pas un admin
534                  $this->addToMessage(_("Les dates de suivis ne peuvent etre modifiees"));              if (!$this->f->user_is_admin) {
535                    
536                    if($this->getVal($champ) != "" AND $this->getVal($champ) != $this->valF[$champ]) {
537                        $this->correct = false;
538                        $this->addToMessage(_("Les dates de suivis ne peuvent etre modifiees"));
539                    }
540              }              }
541          }          }
542      }      }
# Line 363  class instruction extends instruction_ge Line 553  class instruction extends instruction_ge
553                      WHERE defaut IS TRUE";                      WHERE defaut IS TRUE";
554                            
555              // Exécution de la requête              // Exécution de la requête
             $this->f->addToLog("deleteAllLienDossierInstructionTypeEvenementEvenement(): db->query(\"".$sql."\");", VERBOSE_MODE);  
556              $res = $this->f->db->query($sql);              $res = $this->f->db->query($sql);
557              $this->f->isDatabaseError();              $this->f->addToLog("deleteAllLienDossierInstructionTypeEvenementEvenement(): db->query(\"".$sql."\");", VERBOSE_MODE);
558                if ( database::isError($res)){
559                    die();
560                }
561                    
562              $row = $res->fetchrow(DB_FETCHMODE_ASSOC);              $row = $res->fetchrow(DB_FETCHMODE_ASSOC);
563                            
# Line 448  class instruction extends instruction_ge Line 640  class instruction extends instruction_ge
640           * - avis_decision           * - avis_decision
641           * - delai_notification           * - delai_notification
642           * - lettretype           * - lettretype
643             * - autorite_competente
644           * DEPUIS LE DOSSIER D'INSTRUCTION           * DEPUIS LE DOSSIER D'INSTRUCTION
645           * - archive_delai           * - archive_delai
646           * - archive_accord_tacite           * - archive_accord_tacite
# Line 462  class instruction extends instruction_ge Line 655  class instruction extends instruction_ge
655           * - date_achevement           * - date_achevement
656           * - date_chantier           * - date_chantier
657           * - date_conformite           * - date_conformite
658             * - avis_decision
659           * Il permet également de stocker la date_depot du dossier d'instruction           * Il permet également de stocker la date_depot du dossier d'instruction
660           * dans l'attribut $this->archive_date_depot de la classe.           * dans l'attribut $this->archive_date_depot de la classe.
661           */           */
# Line 498  class instruction extends instruction_ge Line 692  class instruction extends instruction_ge
692              if(isset($row['avis_decision']) and !empty($row['avis_decision'])) {              if(isset($row['avis_decision']) and !empty($row['avis_decision'])) {
693                  $this->valF['avis_decision']=$row['avis_decision'];                  $this->valF['avis_decision']=$row['avis_decision'];
694              }              }
695                // Récupération de la valeur de l'autorité compétente
696                // si l'autorité compétente est paramétré dans l'événement
697                $this->valF['autorite_competente'] = NULL;
698                if(isset($row['autorite_competente']) and !empty($row['autorite_competente'])) {
699                    $this->valF['autorite_competente']=$row['autorite_competente'];
700                }
701              // Récupération de la valeur de la lettre type              // Récupération de la valeur de la lettre type
702              // Sinon on lui affecte lavaleur par défaut standard              // Sinon on lui affecte lavaleur par défaut standard
703              if ($row['lettretype'] != "") {              if ($row['lettretype'] != "") {
# Line 556  class instruction extends instruction_ge Line 756  class instruction extends instruction_ge
756              if ($row['date_conformite']!='') {              if ($row['date_conformite']!='') {
757                  $this->valF['archive_date_conformite']= $row['date_conformite'];                    $this->valF['archive_date_conformite']= $row['date_conformite'];  
758              }              }
759                if ($row['incompletude']!='') {
760                    $this->valF['archive_incompletude']= $row['incompletude'];  
761                }
762                if ($row['evenement_suivant_tacite']!='') {
763                    $this->valF['archive_evenement_suivant_tacite']= $row['evenement_suivant_tacite'];  
764                }
765                if ($row['evenement_suivant_tacite_incompletude']!='') {
766                    $this->valF['archive_evenement_suivant_tacite_incompletude']= $row['evenement_suivant_tacite_incompletude'];  
767                }
768                if ($row['etat_pendant_incompletude']!='') {
769                    $this->valF['archive_etat_pendant_incompletude']= $row['etat_pendant_incompletude'];  
770                }
771                if ($row['date_limite_incompletude']!='') {
772                    $this->valF['archive_date_limite_incompletude']= $row['date_limite_incompletude'];  
773                }
774                if ($row['delai_incompletude']!='') {
775                    $this->valF['archive_delai_incompletude']= $row['delai_incompletude'];  
776                }
777                if ($row['autorite_competente']!='') {
778                    $this->valF['archive_autorite_competente']= $row['autorite_competente'];  
779                }
780          }          }
781    
782            // Identifiant du type de courrier
783            $idTypeCourrier = '11';
784            $idCourrier = str_pad($this->valF["instruction"], 10, "0", STR_PAD_LEFT);
785            // Code barres
786            $this->valF["code_barres"] = $idTypeCourrier . $idCourrier;
787      }      }
788            
789      // Test si une restriction est valide      // Test si une restriction est valide
# Line 680  class instruction extends instruction_ge Line 907  class instruction extends instruction_ge
907           * Mise à jour des valeurs du dossier en fonction des valeurs calculées           * Mise à jour des valeurs du dossier en fonction des valeurs calculées
908           * par l'action           * par l'action
909           */           */
910            $this->getValEvenement();
911          // Initialisation          // Initialisation
912          $valF = "";          $valF = "";
913            // état de complétude actuel du dossier
914            $incompletude =  $this->dossierIncomplet();
915    
916            if($incompletude === FALSE) {
917                // Si l'événement d'instruction est de type incompletude
918                if($this->valEvenement['type'] == "incompletude") {
919                    // On marque le dossier en incomplétude pour application des actions
920                    $incompletude = TRUE;
921                    // Set du flag incomplétude de la table dossier
922                    $valF['incompletude'] = TRUE;
923                    // Enregistrement de l'état dans la variable provisoire
924                    $valF['etat_pendant_incompletude'] = $this->valF['archive_etat'];
925                }
926            } else {
927                // Si l'evenement d'instruction est de type retour ou contient une
928                // decision, on sort d'incomplétude
929                if($this->valEvenement['type'] == "retour" OR
930                   $this->valEvenement['avis_decision'] != NULL) {
931                    // On enlève la marque d'incomplétude pour application des actions
932                    $incompletude = FALSE;
933                    // On enlève le flag d'incomplétude sur l'enregistrement de la table dossier
934                    $valF['incompletude'] = FALSE;
935                     // Restauration de l'état depuis l'état provisoire
936                    $valF['etat'] = $this->valF['archive_etat_pendant_incompletude'];
937                    // On vide la variable provisoire ainsi que le délai de complétude
938                    // et la date limite de complétude
939                    $valF['etat_pendant_incompletude'] = NULL;
940                    $valF['delai_incompletude'] = NULL;
941                    $valF['date_limite_incompletude'] = NULL;
942                }
943            }
944          // Récupération des paramètres de l'action          // Récupération des paramètres de l'action
945          $sql = "SELECT * FROM ".DB_PREFIXE."action          $sql = "SELECT * FROM ".DB_PREFIXE."action
946          WHERE action='".$this->valF['action']."'";          WHERE action='".$this->valF['action']."'";
# Line 691  class instruction extends instruction_ge Line 950  class instruction extends instruction_ge
950              die($res->getMessage());              die($res->getMessage());
951          }          }
952          while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)) {          while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)) {
953    
954              // pour chacune des regles, on applique la regle              // pour chacune des regles, on applique la regle
             if($row['regle_etat']!=''){  
                 $valF['etat'] = $this->regle($row['regle_etat']);  
             }  
955              if($row['regle_delai']!=''){              if($row['regle_delai']!=''){
956                  $valF['delai'] = $this->regle($row['regle_delai']);                  $valF['delai'] = $this->regle($row['regle_delai']);
957              }              }
# Line 734  class instruction extends instruction_ge Line 991  class instruction extends instruction_ge
991              if($row['regle_date_conformite']!=''){              if($row['regle_date_conformite']!=''){
992                  $valF['date_conformite']= $this->regle($row['regle_date_conformite']);                  $valF['date_conformite']= $this->regle($row['regle_date_conformite']);
993              }              }
994              // Appel des méthode stockées dans le champ methode_trigger              if($row['regle_date_limite_incompletude']!=''){
995              if ($row['methode_trigger'] != "") {                  $valF['date_limite_incompletude']= $this->regle($row['regle_date_limite_incompletude']);
996                  foreach (explode(";", $row['methode_trigger']) as $methode) {              }
997                      if (method_exists($this, $methode)) {              if($row['regle_delai_incompletude']!=''){
998                          $this->$methode();                  $valF['delai_incompletude']= $this->regle($row['regle_delai_incompletude']);
999                      }              }
1000                if($row['regle_autorite_competente']!=''){
1001                    $valF['autorite_competente']= $this->regle($row['regle_autorite_competente']);
1002                }
1003                if($row['regle_etat']!=''){
1004                    // Si on est dans le cas général ou qu'on est en incomplétude et
1005                    // qu'on a un événement de type incomplétude alors : on stocke
1006                    // l'état dans la variable courante
1007                    if ($incompletude == FALSE OR $this->valEvenement['type'] == "incompletude") {
1008                        $valF['etat'] = $this->regle($row['regle_etat']);
1009                    } else {
1010                        $valF['etat_pendant_incompletude'] = $this->regle($row['regle_etat']);
1011                    }
1012                }
1013                if($this->valEvenement['evenement_suivant_tacite'] != '') {
1014                    // Si on est pas en incomplétude on stocke l'événement tacite
1015                    //de l'événement dans la variable courante
1016                    if ($incompletude == FALSE) {
1017                        $valF['evenement_suivant_tacite'] = $this->valEvenement['evenement_suivant_tacite'];
1018                    } else {
1019                        $valF['evenement_suivant_tacite_incompletude'] = $this->valEvenement['evenement_suivant_tacite'];
1020                  }                  }
1021              }              }
1022          }          }
# Line 802  class instruction extends instruction_ge Line 1079  class instruction extends instruction_ge
1079                  }                  }
1080              }              }
1081          } // fin de if ($this->f->getParameter('option_erp') != "")          } // fin de if ($this->f->getParameter('option_erp') != "")
1082    
1083            // Mise à jour des données du dossier d'autorisation
1084            require_once "../obj/dossier_autorisation.class.php";
1085            $da = new dossier_autorisation($this->getNumDemandeAutorFromDossier($this->valF['dossier']), $this->db, DEBUG);
1086            $da->majDossierAutorisation();
1087      }          }    
1088    
1089      function triggermodifierapres($id,&$db,$val,$DEBUG) {      function triggermodifierapres($id,&$db,$val,$DEBUG) {
# Line 830  class instruction extends instruction_ge Line 1112  class instruction extends instruction_ge
1112              die($res->getMessage());              die($res->getMessage());
1113          }          }
1114          while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)) {          while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)) {
1115              // Ajout d'un événement d'instruction              // Si la date de retour signature est éditée on vérifie si il existe un événement automatique
1116                if ($this->getVal('date_retour_signature') == "" AND
1117              if ($this->getVal('date_retour_signature') == "" AND $this->valF['date_retour_signature'] != "") {                  $this->valF['date_retour_signature'] != "" AND
1118                    $row['evenement_retour_signature'] != "") {
1119                  $new_instruction = new instruction("]", $db, $DEBUG);                  $new_instruction = new instruction("]", $db, $DEBUG);
1120                    // Création d'un tableau avec la liste des champs de l'instruction
1121                  foreach($new_instruction->champs as $champ) {                  foreach($new_instruction->champs as $champ) {
1122                      $valNewInstr[$champ] = "";                      $valNewInstr[$champ] = "";
1123                  }                  }
1124                    // Définition des valeurs de la nouvelle instruction
1125                  $valNewInstr["evenement"] = $row['evenement_retour_signature'];                  $valNewInstr["evenement"] = $row['evenement_retour_signature'];
1126                  $valNewInstr["destinataire"] = $this->valF['destinataire'];                  $valNewInstr["destinataire"] = $this->valF['destinataire'];
1127                  $valNewInstr["dossier"] = $this->valF['dossier'];                  $valNewInstr["dossier"] = $this->valF['dossier'];
1128                  $valNewInstr["date_evenement"] = date("d/m/Y");                  $valNewInstr["date_evenement"] = date("d/m/Y");
1129                  $new_instruction->ajouter($valNewInstr,$db, $DEBUG);                  $new_instruction->ajouter($valNewInstr,$db, $DEBUG);
1130              }              }
1131                // Si la date de retour AR est éditée on vérifie si il existe un événement automatique
1132                if ($this->getVal('date_retour_rar') == "" AND
1133                    $this->valF['date_retour_rar'] != "" AND
1134                    $row['evenement_retour_ar'] != "" ) {
1135                    $new_instruction = new instruction("]", $db, $DEBUG);
1136                    // Création d'un tableau avec la liste des champs de l'instruction
1137                    foreach($new_instruction->champs as $champ) {
1138                        $valNewInstr[$champ] = "";
1139                    }
1140                    // Définition des valeurs de la nouvelle instruction
1141                    $valNewInstr["evenement"] = $row['evenement_retour_ar'];
1142                    $valNewInstr["destinataire"] = $this->valF['destinataire'];
1143                    $valNewInstr["dossier"] = $this->valF['dossier'];
1144                    $valNewInstr["date_evenement"] = date("d/m/Y");
1145                    $new_instruction->ajouter($valNewInstr,$db, $DEBUG);
1146                }
1147          }          }
1148    
1149          // Récupération des paramètres de l'action          // Récupération des paramètres de l'action
# Line 918  class instruction extends instruction_ge Line 1218  class instruction extends instruction_ge
1218                                      dossier.date_depot as \"ws_DA_In_Dte_Depot_Dem\",                                      dossier.date_depot as \"ws_DA_In_Dte_Depot_Dem\",
1219                                      dossier.terrain_numero as \"ws_DA_In_N_Voie\",                                      dossier.terrain_numero as \"ws_DA_In_N_Voie\",
1220                                      '' as \"ws_DA_In_Type_Voie\",                                      '' as \"ws_DA_In_Type_Voie\",
1221                                      dossier.complement as \"ws_DA_In_Adresse1\",                                      dossier.terrain_adresse_voie as \"ws_DA_In_Adresse1\",
1222                                      dossier.terrain_adresse_lieu_dit as \"ws_DA_In_Adresse2\",                                      dossier.terrain_adresse_lieu_dit as \"ws_DA_In_Adresse2\",
1223                                      dossier.terrain_adresse_code_postal as \"ws_DA_In_CP\",                                      dossier.terrain_adresse_code_postal as \"ws_DA_In_CP\",
1224                                      dossier.terrain_adresse_localite as \"ws_DA_In_Ville\",                                      dossier.terrain_adresse_localite as \"ws_DA_In_Ville\",
# Line 950  class instruction extends instruction_ge Line 1250  class instruction extends instruction_ge
1250                              WHERE instruction.instruction = ".$this->valF['instruction'];                              WHERE instruction.instruction = ".$this->valF['instruction'];
1251                  $resArrete = $this->db->query($sqlArrete);                  $resArrete = $this->db->query($sqlArrete);
1252                  $this->f->addToLog("triggerModifierApres(): db->query(\"".$sqlArrete."\");", VERBOSE_MODE);                  $this->f->addToLog("triggerModifierApres(): db->query(\"".$sqlArrete."\");", VERBOSE_MODE);
1253                  $this->f->isDatabaseError();                  if ( database::isError($resArrete)){
1254                        die();
1255                    }
1256            
1257                  $rowArrete = $resArrete->fetchRow(DB_FETCHMODE_ASSOC);                  $rowArrete = $resArrete->fetchRow(DB_FETCHMODE_ASSOC);
1258                  $msgenque->setArreteInfo($rowArrete);                  $msgenque->setArreteInfo($rowArrete);
1259                  $msgenque->enqueueMessage($msgenque::$ARRETE_ENVOI);                                  $msgenque->enqueueMessage($msgenque::$ARRETE_ENVOI);                
1260              }              }
1261          }          }
1262    
1263            // Mise à jour des données du dossier d'autorisation
1264            require_once "../obj/dossier_autorisation.class.php";
1265            $da = new dossier_autorisation($this->getNumDemandeAutorFromDossier($this->valF['dossier']), $this->db, DEBUG);
1266            $da->majDossierAutorisation();
1267      }      }
1268    
1269      function triggersupprimer($id,&$db,$val,$DEBUG) {      function triggersupprimer($id,&$db,$val,$DEBUG) {
# Line 965  class instruction extends instruction_ge Line 1272  class instruction extends instruction_ge
1272           * archive dans le dossier d'instruction avant de supprimer l'événement           * archive dans le dossier d'instruction avant de supprimer l'événement
1273           * d'instruction           * d'instruction
1274           */           */
1275          // archive en instruction (si suppression) [archive if delete instruction]          // Mise à jour des 4 valeurs modifiées par l'action
1276          $valF['delai']=$val['archive_delai'];          $valF['delai'] = $val['archive_delai'];
1277          $valF['accord_tacite']=$val['archive_accord_tacite'];          $valF['accord_tacite'] = $val['archive_accord_tacite'];
1278          $valF['etat']=$val['archive_etat'];          $valF['etat'] = $val['archive_etat'];
1279          if($val['archive_avis']=='')          if ($val['archive_avis'] != '') {
1280              $valF['avis_decision']= null;              $valF['avis_decision'] = $val['archive_avis'];
1281          else          } else {
1282              $valF['avis_decision']=$val['archive_avis'];              $valF['avis_decision'] = NULL;
1283          if($val['archive_date_complet']!='')          }
1284              $valF['date_complet']=$val['archive_date_complet'];          // Mise à jour des 10 dates avec la valeur présente dans le formulaire
1285          if($val['archive_date_dernier_depot']!='')          // de suppression. Si la valeur de la date est vide alors on fixe
1286              $valF['date_dernier_depot']=$val['archive_date_dernier_depot'];          // à la valeur NULL
1287          if($val['archive_date_rejet']!='')          //
1288              $valF['date_rejet']= $val['archive_date_rejet'];          if ($val['archive_date_complet'] != '') {
1289          if($val['archive_date_limite']!='')              $valF['date_complet'] = $val['archive_date_complet'];
1290              $valF['date_limite']= $val['archive_date_limite'];          } else {
1291          if($val['archive_date_notification_delai']!='')              $valF['date_complet'] = NULL;
1292              $valF['date_notification_delai']= $val['archive_date_notification_delai'];          }
1293          if($val['archive_date_decision']!='')          if ($val['archive_date_dernier_depot'] != '') {
1294              $valF['date_decision']= $val['archive_date_decision'];              $valF['date_dernier_depot'] = $val['archive_date_dernier_depot'];
1295          if($val['archive_date_validite']!='')          } else {
1296              $valF['date_validite']= $val['archive_date_validite'];              $valF['date_dernier_depot'] = NULL;
1297          if($val['archive_date_achevement']!='')          }
1298              $valF['date_achevement']= $val['archive_date_achevement'];          if ($val['archive_date_rejet'] != '') {
1299          if($val['archive_date_chantier']!='')              $valF['date_rejet'] = $val['archive_date_rejet'];
1300              $valF['date_chantier']= $val['archive_date_chantier'];          } else {
1301          if($val['archive_date_conformite']!='')              $valF['date_rejet'] = NULL;
1302              $valF['date_conformite']= $val['archive_date_conformite'];          }
1303            if ($val['archive_date_limite'] != '') {
1304                $valF['date_limite'] = $val['archive_date_limite'];
1305            } else {
1306                $valF['date_limite'] = NULL;
1307            }
1308            if ($val['archive_date_notification_delai'] != '') {
1309                $valF['date_notification_delai'] = $val['archive_date_notification_delai'];
1310            } else {
1311                $valF['date_notification_delai'] = NULL;
1312            }
1313            if ($val['archive_date_decision'] != '') {
1314                $valF['date_decision'] = $val['archive_date_decision'];
1315            } else {
1316                $valF['date_decision'] = NULL;
1317            }
1318            if ($val['archive_date_validite'] != '') {
1319                $valF['date_validite'] = $val['archive_date_validite'];
1320            } else {
1321                $valF['date_validite'] = NULL;
1322            }
1323            if ($val['archive_date_achevement'] != '') {
1324                $valF['date_achevement'] = $val['archive_date_achevement'];
1325            } else {
1326                $valF['date_achevement'] = NULL;
1327            }
1328            if ($val['archive_date_chantier'] != '') {
1329                $valF['date_chantier'] = $val['archive_date_chantier'];
1330            } else {
1331                $valF['date_chantier'] = NULL;
1332            }
1333            if ($val['archive_date_conformite'] != '') {
1334                $valF['date_conformite'] = $val['archive_date_conformite'];
1335            } else {
1336                $valF['date_conformite'] = NULL;
1337            }
1338            if ($val['archive_incompletude'] != '') {
1339                $valF['incompletude'] = $val['archive_incompletude'];
1340            } else {
1341                $valF['incompletude'] = NULL;
1342            }
1343            if ($val['archive_evenement_suivant_tacite'] != '') {
1344                $valF['evenement_suivant_tacite'] = $val['archive_evenement_suivant_tacite'];
1345            } else {
1346                $valF['evenement_suivant_tacite'] = NULL;
1347            }
1348            if ($val['archive_evenement_suivant_tacite_incompletude'] != '') {
1349                $valF['evenement_suivant_tacite_incompletude'] = $val['archive_evenement_suivant_tacite_incompletude'];
1350            } else {
1351                $valF['evenement_suivant_tacite_incompletude'] = NULL;
1352            }
1353            if ($val['archive_etat_pendant_incompletude'] != '') {
1354                $valF['etat_pendant_incompletude'] = $val['archive_etat_pendant_incompletude'];
1355            } else {
1356                $valF['etat_pendant_incompletude'] = NULL;
1357            }
1358            if ($val['archive_date_limite_incompletude'] != '') {
1359                $valF['date_limite_incompletude'] = $val['archive_date_limite_incompletude'];
1360            } else {
1361                $valF['date_limite_incompletude'] = NULL;
1362            }
1363            if ($val['archive_delai_incompletude'] != '') {
1364                $valF['delai_incompletude'] = $val['archive_delai_incompletude'];
1365            } else {
1366                $valF['delai_incompletude'] = NULL;
1367            }
1368            if ($val['archive_autorite_competente'] != '') {
1369                $valF['autorite_competente'] = $val['archive_autorite_competente'];
1370            } else {
1371                $valF['autorite_competente'] = NULL;
1372            }
1373          // On met à jour le dossier          // On met à jour le dossier
1374          $cle = " dossier='".$val['dossier']."'";          $cle = " dossier='".$val['dossier']."'";
1375          $res1 = $db->autoExecute(DB_PREFIXE.'dossier', $valF, DB_AUTOQUERY_UPDATE, $cle);          $res = $db->autoExecute(DB_PREFIXE.'dossier', $valF, DB_AUTOQUERY_UPDATE, $cle);
1376          $this->addToLog("triggersupprimer(): db->autoexecute(\"".DB_PREFIXE."dossier\", ".print_r($valF, true).", DB_AUTOQUERY_UPDATE, \"".$cle."\");", VERBOSE_MODE);          $this->addToLog("triggersupprimer(): db->autoexecute(\"".DB_PREFIXE."dossier\", ".print_r($valF, true).", DB_AUTOQUERY_UPDATE, \"".$cle."\");", VERBOSE_MODE);
1377          if (database::isError($res1)) {          if (database::isError($res)) {
1378              die($res->getMessage());              die($res->getMessage());
1379          }          }
1380          // Affichage d'informations à l'utilisateur          // Affichage d'informations à l'utilisateur
1381          $this->addToMessage(_("Suppression de l'instruction")." [".$db->affectedRows()." "._('enregistrement')." "._('mis_a_jour')."]");          $this->addToMessage(_("Suppression de l'instruction")." [".$db->affectedRows()." "._('enregistrement')." "._('mis_a_jour')."]");
1382    
1383            // Mise à jour de la demande si un récépissé d'instruction correspond à l'instruction à supprimer
1384        }
1385    
1386        function triggersupprimerapres($id,&$db,$val,$DEBUG) {
1387    
1388            // Mise à jour des données du dossier d'autorisation
1389            require_once "../obj/dossier_autorisation.class.php";
1390            $da = new dossier_autorisation($this->getNumDemandeAutorFromDossier($val["dossier"]), $this->db, DEBUG);
1391            $da->majDossierAutorisation();
1392      }      }
1393    
1394      // =============================================      // =============================================
# Line 1058  class instruction extends instruction_ge Line 1445  class instruction extends instruction_ge
1445      // Vérifie la restriction sur l'événement      // Vérifie la restriction sur l'événement
1446      function verifier($val = array(), &$db, $DEBUG){      function verifier($val = array(), &$db, $DEBUG){
1447          parent::verifier($val, $db, $DEBUG);          parent::verifier($val, $db, $DEBUG);
         //Récupère la restriction  
         $sql= "SELECT  
                   restriction  
               FROM  
                   ".DB_PREFIXE."evenement  
               WHERE  
                   evenement =".$this->valF['evenement'];  
   
         $res = $db->query($sql);  
         $this->f->addToLog("verifier(): db->query(\"".$sql."\");", VERBOSE_MODE);  
         $this->f->isDatabaseError();  
           
         $row=& $res->fetchRow(DB_FETCHMODE_ASSOC);  
1448    
1449          //Test qu'une restriction est présente          if ( isset($val['evenement']) && is_numeric($val['evenement'])){
1450          if ( isset($row['restriction']) && $row['restriction'] != "" ){          //Récupère la restriction
1451                            $sql= "SELECT
1452              //Test si la restriction est valide                        restriction
1453              if ( !$this->restrictionIsValid($row['restriction']) ){                    FROM
1454                                          ".DB_PREFIXE."evenement
1455                  $this->correct=false;                    WHERE
1456                  $this->addToMessage(_("Restriction non valide"));                        evenement =".$val['evenement'];
1457              }      
1458              else {              $res = $db->query($sql);
1459                $this->addToLog("verifier(): db->query(\"".$sql."\");", VERBOSE_MODE);
1460                if (database::isError($res)) {
1461                    die($res->getMessage());
1462                }        
1463                $row=& $res->fetchRow(DB_FETCHMODE_ASSOC);
1464        
1465                //Test qu'une restriction est présente
1466                if ( isset($row['restriction']) && $row['restriction'] != "" ){
1467                                    
1468                  $this->correct = true;                  //Test si la restriction est valide
1469                    if ( !$this->restrictionIsValid($row['restriction']) ){
1470                        
1471                        $this->correct=false;
1472                        $this->addToMessage(_("Restriction non valide"));
1473                    }
1474                    else {
1475                        
1476                        $this->correct = true;
1477                    }
1478              }              }
1479          }          }
1480    
# Line 1094  class instruction extends instruction_ge Line 1485  class instruction extends instruction_ge
1485          $this->updateDate("date_envoi_controle_legalite");          $this->updateDate("date_envoi_controle_legalite");
1486          $this->updateDate("date_retour_controle_legalite");          $this->updateDate("date_retour_controle_legalite");
1487      }      }
1488        
1489      /**      /**
1490       * Méthode permettant de mettre à jour l'état d'un DA       * Méthode permettant de récupérer toutes les valeurs de l'événement
1491         * sélectionné après validation du formulaire d'instruction
1492         *
1493         * @return array() veleurs de l'événement lié
1494       */       */
1495      function majEtatDA() {  
1496          if($this->valF['action'] == 'accepter' AND $this->valF['avis_decision'] == 8) {      private function getValEvenement() {
1497              $val['etat_dossier_autorisation']=5;          if(!empty($this->valEvenement)) {
1498          } elseif($this->valF['action'] == 'accepter' AND $this->valF['avis_decision'] == 15) {              return $this->valEvenement;
             $val['etat_dossier_autorisation']=3;  
         } elseif($this->valF['action'] == 'accepter') {  
             $val['etat_dossier_autorisation']=2;  
         } elseif($this->valF['action'] == 'rejeter') {  
             $val['etat_dossier_autorisation']=4;  
         } elseif($this->valF['action'] == 'terminer') {  
             $val['etat_dossier_autorisation']=8;  
         } elseif($this->valF['action'] == 'majorer') {  
             $val['etat_dossier_autorisation']=6;  
1499          } else {          } else {
1500              $val['etat_dossier_autorisation']=7;              $sql = "SELECT * FROM ".DB_PREFIXE."evenement
1501                    WHERE evenement=".$this->valF['evenement'];
1502                $res = $this->db->query($sql);
1503                $this->addToLog("getValEvenement(): db->query(\"".$sql."\");", VERBOSE_MODE);
1504                if (database::isError($res)) {
1505                    die($res->getMessage());
1506                }
1507                $this->valEvenement = $res->fetchRow(DB_FETCHMODE_ASSOC);
1508                return $this->valEvenement;
1509          }          }
1510                }
1511          //Récupération du numéro de dossier d'autorisation lié au dossier d'instruction  
1512          $IDdossier_autorisation = $this->getDossierAutorisation($this->valF['dossier']);      /**
1513               * Méthode permettant de savoir si le dossier lié à l'instruction à le flag
1514          // Mis à jour de l'état du dossier d'autorisation       * incompletude à true après validation du formulaire d'instruction
1515          require_once '../obj/dossier_autorisation.class.php';       *
1516          $dossier_autorisation = new dossier_autorisation($IDdossier_autorisation,$this->db,DEBUG);       * @return boolean
1517                 */
1518          $dossier_autorisation->val[array_search("etat_dossier_autorisation", $dossier_autorisation->champs)] = $val['etat_dossier_autorisation'];      private function dossierIncomplet() {
1519                    $sql = "SELECT incompletude FROM ".DB_PREFIXE."dossier
1520          //Récupération des données                  WHERE dossier='".$this->valF['dossier']."'";
1521          $valDossierAutorisation = array();          $incompletude = $this->db->getOne($sql);
1522          for ( $i=0 ; $i<count($dossier_autorisation->champs); $i++){          $this->addToLog("dossierIncomplet(): db->query(\"".$sql."\");", VERBOSE_MODE);
1523            if (database::isError($incompletude)) {
1524                die($incompletude->getMessage());
1525            }
1526            if ($incompletude == 't') {
1527                return true;
1528            } else {
1529                return false;
1530            }
1531        }
1532        
1533        /**
1534         * Finalisation des documents.
1535         * @param  string $champ    champ du fichier à finaliser
1536         * @param  booleen $status  permet de définir si on finalise ou définalise
1537         * @param  string $sousform permet de savoir si se trouve dans un sousformulaire (passé au javascript)
1538         */
1539        function finaliser( $champ = '', $status, $sousform, $retourformulaire){
1540    
1541            //Si on finalise le document
1542            if ( $status == 1 ){
1543                            
1544              $valDossierAutorisation[$dossier_autorisation->champs[$i]]=              //Génération du PDF
1545                  $dossier_autorisation->val[$i];              $_GET['output'] = "string";
1546                $f = $this->f;
1547                include '../app/pdf_instruction.php';
1548                
1549                //Métadonnées du document
1550                $metadata = array(
1551                    'filename' => 'instruction_'.$idx.'.pdf',
1552                    'mimetype' => 'application/pdf',
1553                    'size' => strlen($pdf_output)
1554                );
1555    
1556                // Récupération des métadonnées calculées après validation
1557                $spe_metadata = $this->getMetadata("om_fichier_instruction");
1558    
1559                $metadata = array_merge($metadata, $spe_metadata);
1560                //Si le document a déjà été finalisé
1561                //on met à jour le document mais pas son uid
1562                if ( $this->getVal("om_fichier_instruction") != '' ){
1563                    $uid = $this->f->storage->update(
1564                        $this->getVal("om_fichier_instruction"), $pdf_output, $metadata);
1565                }
1566                //Sinon, on joute le document et on récupère son uid
1567                else {
1568                    //Stockage du PDF
1569                    $uid = $this->f->storage->create($pdf_output, $metadata);
1570                }
1571            }
1572            else {
1573                //Récupération de l'uid du document finalisé
1574                $uid = $this->getVal("om_fichier_instruction");
1575                
1576                //On dé-finalise avant de finaliser
1577                if ( $uid == '' ){
1578                    return -1;
1579                }
1580          }          }
1581    
1582          $dossier_autorisation->modifier($valDossierAutorisation, $this->db, DEBUG);          //Mise à jour des données
1583      }          if ( $uid != '' ){
1584                    // Logger
1585     /**              $this->addToLog("finaliser() - begin", EXTRA_VERBOSE_MODE);
1586      * Méthode permettant de mettre à jour les données d'un DA              // Recuperation de la valeur de la cle primaire de l'objet
1587      */              if($this->getVal($this->clePrimaire) != '')
1588      function majDataDA() {                  $id = $this->getVal($this->clePrimaire);
1589                        else
1590          //Récupération du numéro de dossier d'autorisation lié au dossier d'instruction                  $id=$this->id;
         $IDdossier_autorisation = $this->getDossierAutorisation($this->valF['dossier']);  
         require_once '../obj/dossier_autorisation.class.php';  
         $dossier_autorisation = new dossier_autorisation($IDdossier_autorisation,$this->db,DEBUG);  
           
         require_once '../obj/dossier.class.php';  
         $dossier = new dossier($this->valF['dossier'],$this->db,DEBUG);  
           
         //Récupération des données  
         $valDossierAutorisation = array();  
         for ( $i=0 ; $i<count($dossier_autorisation->champs); $i++){  
1591                            
1592              if ( array_search($dossier_autorisation->champs[$i], $dossier->champs) ){              $actions = array();
1593                //Tableau contenant le lien vers le PDF et lien du portlet pour la mise
1594                //à jour de l'interface
1595                if ( $status == 0 ){
1596                    $lien = '../app/pdf_instruction.php?idx='.$id;
1597                                    
1598                  $valDossierAutorisation[$dossier_autorisation->champs[$i]]=$dossier->getVal($dossier_autorisation->champs[$i]);                  //Ajout des actions
1599                    //Si l'utilisateur a le droit de modifier l'objet
1600                    if ( $this->f->isAccredited('instruction') ||
1601                        $this->f->isAccredited('instruction_modifier') ){
1602                            
1603                        $actions["modifier"] = ($sousform!='')?
1604                            '<li><a href="#" onclick="ajaxIt(\'instruction\',
1605                            \'../scr/sousform.php?obj=instruction&amp;action=1&amp;idx='.
1606                            $this->getVal($this->clePrimaire).
1607                            '&amp;premiersf=0&amp;trisf=&amp;retourformulaire='.$retourformulaire.'&amp;idxformulaire='.
1608                            $this->getVal("dossier").
1609                            '&amp;retour=form\');">
1610                            <span class="om-prev-icon om-icon-16 edit-16" title="'.
1611                            _('Modifier').'">'.
1612                            _('Modifier').
1613                            '</span></a></li>':
1614                            '<li>
1615                            <a href="form.php?obj=instruction&amp;action=1'.'&amp;idx='.
1616                            $this->getVal($this->clePrimaire).
1617                            '&amp;premier=&amp;advs_id=&amp;recherche=&amp;tricol=&amp;selectioncol=&amp;valide=&amp;retour=form">
1618                            <span class="om-prev-icon om-icon-16 edit-16" title="'.
1619                            _('Modifier').'">'.
1620                            _('Modifier').
1621                            '</span></a></li>';
1622                    }
1623                    //Si l'utilisateur a le droit de supprimer l'objet
1624                    if ( $this->f->isAccredited('instruction') ||
1625                        $this->f->isAccredited('instruction_supprimer') ){
1626                            
1627                        $actions["supprimer"] = ($sousform!='')?
1628                            '<li><a href="#" onclick="ajaxIt(\'instruction\',
1629                            \'../scr/sousform.php?obj=instruction&amp;action=2&amp;idx='.
1630                            $this->getVal($this->clePrimaire).
1631                            '&amp;premiersf=0&amp;trisf=&amp;retourformulaire='.$retourformulaire.'&amp;idxformulaire='.
1632                            $this->getVal("dossier").
1633                            '&amp;retour=form\');">
1634                            <span class="om-prev-icon om-icon-16 delete-16" title="'.
1635                            _('Supprimer').'">'.
1636                            _('Supprimer').
1637                            '</span></a></li>':
1638                            '<li>
1639                            <a href="form.php?obj=instruction&amp;action=1'.'&amp;idx='.
1640                            $this->getVal($this->clePrimaire).
1641                            '&amp;premier=&amp;advs_id=&amp;recherche=&amp;tricol=&amp;selectioncol=&amp;valide=&amp;retour=form">
1642                            <span class="om-prev-icon om-icon-16 delete-16" title="'.
1643                            _('Supprimer').'">'.
1644                            _('Supprimer').
1645                            '</span></a></li>';
1646                    }
1647              }              }
1648              else {              else {
1649                  $valDossierAutorisation[$dossier_autorisation->champs[$i]]=                  $lien = '../spg/file.php?obj=instruction&'.
1650                  $dossier_autorisation->val[$i];                      'champ=om_fichier_instruction&id='.$id;
1651                }
1652    
1653               $retour = array(
1654                    "portlet"=> "<a href=\"#\" onclick=\"finalizeDocument(".
1655                        $id.", 'instruction', '".$sousform."', ".(($status==0)?1:0).")\">
1656                        <span class=\"om-prev-icon om-icon-16 om-icon-fix "
1657                        .(($status==1)?"de":"")."finalise\" title=\"".
1658                        (($status==1)?_("Reprendre la redaction du document"):_("Finaliser le document"))."\">".
1659                        (($status==1)?_("Reprendre la redaction du document"):_("Finaliser le document"))."</span>
1660                        </a>",
1661                    "pdf" => $lien,
1662                    "actions" => $actions
1663                );
1664    
1665                foreach ( $this->champs as $key=>$value )
1666                    $val[$value] = $this->val[$key];
1667                $val['date_evenement']=$this->dateDBToForm($val['date_evenement']);
1668                $val['archive_date_complet']=$this->dateDBToForm($val['archive_date_complet']);
1669                $val['archive_date_rejet']=$this->dateDBToForm($val['archive_date_rejet']);
1670                $val['archive_date_limite']=$this->dateDBToForm($val['archive_date_limite']);
1671                $val['archive_date_notification_delai']=$this->dateDBToForm($val['archive_date_notification_delai']);
1672                $val['archive_date_decision']=$this->dateDBToForm($val['archive_date_decision']);
1673                $val['archive_date_validite']=$this->dateDBToForm($val['archive_date_validite']);
1674                $val['archive_date_achevement']=$this->dateDBToForm($val['archive_date_achevement']);
1675                $val['archive_date_chantier']=$this->dateDBToForm($val['archive_date_chantier']);
1676                $val['archive_date_conformite']=$this->dateDBToForm($val['archive_date_conformite']);
1677                $val['archive_date_dernier_depot']=$this->dateDBToForm($val['archive_date_dernier_depot']);
1678                $val['archive_date_limite_incompletude']=$this->dateDBToForm($val['archive_date_limite_incompletude']);
1679                $val['date_finalisation_courrier']=$this->dateDBToForm($val['date_finalisation_courrier']);
1680                $val['date_envoi_signature']=$this->dateDBToForm($val['date_envoi_signature']);
1681                $val['date_retour_signature']=$this->dateDBToForm($val['date_retour_signature']);
1682                $val['date_envoi_rar']=$this->dateDBToForm($val['date_envoi_rar']);
1683                $val['date_retour_rar']=$this->dateDBToForm($val['date_retour_rar']);
1684                $val['date_envoi_controle_legalite']=$this->dateDBToForm($val['date_envoi_controle_legalite']);
1685                $val['date_retour_controle_legalite']=$this->dateDBToForm($val['date_retour_controle_legalite']);
1686                
1687                $this->setvalF($val);
1688    
1689                // Verification de la validite des donnees
1690                $this->verifier($this->val, $this->db, DEBUG);
1691                // Verification du verrou
1692                $this->testverrou();
1693                // Si les verifications precedentes sont correctes, on procede a
1694                // la modification, sinon on ne fait rien et on retourne une erreur
1695                if ($this->correct) {
1696                    // Execution du trigger 'before' specifique au MODE 'update'
1697                    $this->triggermodifier( $id, $this->db, $this->val, DEBUG);
1698                    $valF = array(
1699                            "om_final_instruction"=> ($status==1)?TRUE:FALSE,
1700                            "om_fichier_instruction"=>$uid,
1701                            "date_finalisation_courrier"=>date('Y-m-d'));
1702                    // Execution de la requête de modification des donnees de l'attribut
1703                    // valF de l'objet dans l'attribut table de l'objet
1704                    $res = $this->db->autoExecute(DB_PREFIXE.$this->table, $valF,
1705                        DB_AUTOQUERY_UPDATE, $this->getCle($id));
1706                     $this->addToLog("finaliser() : db->autoExecute(\"".DB_PREFIXE.$this->table."\", ".print_r($valF, true).", DB_AUTOQUERY_UPDATE, \"".$this->getCle($id)."\")", VERBOSE_MODE);
1707                    // Si une erreur survient
1708                    if (database::isError($res)) {
1709                        // Appel de la methode de recuperation des erreurs
1710                        $this->erreur_db($res->getDebugInfo(), $res->getMessage(), '');
1711                    } else {
1712                        // Log
1713                        $this->addToLog(_("Requete executee"), VERBOSE_MODE);
1714                        // Log
1715                        $message = _("Enregistrement")."&nbsp;".$id."&nbsp;";
1716                        $message .= _("de la table")."&nbsp;\"".$this->table."\"&nbsp;";
1717                        $message .= "[&nbsp;".$this->db->affectedRows()."&nbsp;";
1718                        $message .= _("enregistrement(s) mis a jour")."&nbsp;]";
1719                        $this->addToLog($message, VERBOSE_MODE);
1720                        // Mise en place du verrou pour ne pas finaliser plusieurs fois
1721                        // le meme document
1722                        $this->verrouille();
1723                        // Execution du trigger 'after' specifique au MODE 'update'
1724                        //$this->triggermodifierapres($id, $this->db, $val, DEBUG);
1725    
1726                        return $retour;
1727                    }
1728                } else {
1729                    // Message d'echec (saut d'une ligne supplementaire avant le
1730                    // message pour qu'il soit mis en evidence)
1731                    $this->addToLog("Finalisation non enregistree");
1732                    return -1;
1733              }              }
1734          }          }
1735            // Si le document n'a pas été stocké
1736            else{
1737                return -1;
1738            }
1739        }
1740    
1741          $dossier_autorisation->modifier($valDossierAutorisation, $this->db, DEBUG);      /**
1742                 * Récupération du numéro de dossier d'instruction à ajouter aux métadonnées
1743          // Suppression du liens entre les lots et le DA       * @return string numéro de dossier d'instruction
1744          $valLot['dossier_autorisation'] = NULL;       */
1745          $this->db->autoExecute(DB_PREFIXE."lot", $valLot, DB_AUTOQUERY_UPDATE, "dossier_autorisation='".$IDdossier_autorisation."'");      protected function getDossier() {
1746                    if(empty($this->specificMetadata)) {
1747          // Liaison des lots du DI avec le DA              $this->getSpecificMetadata();
         $sqlLot = "SELECT lot FROM ".DB_PREFIXE."lien_dossier_lot WHERE dossier='".$this->valF['dossier']."'";  
         $res = $this->db->query($sqlLot);  
         $this->addToLog($sqlLot);  
         $this->f->isDatabaseError();  
         while($rowLot = $res->fetchRow(DB_FETCHMODE_ASSOC)) {  
             $valLot['dossier_autorisation'] = $IDdossier_autorisation;  
             $this->db->autoExecute(DB_PREFIXE."lot", $valLot, DB_AUTOQUERY_UPDATE, "lot=".$rowLot['lot']);  
1748          }          }
1749            return $this->specificMetadata->dossier;
1750      }      }
1751            /**
1752      // Récupération de l'identifiant du dossier d'autorisation lié au dossier d'instruction       * Récupération la version du dossier d'instruction à ajouter aux métadonnées
1753      function getDossierAutorisation($dossier_instruction){       * @return int Version
1754         */
1755        protected function getDossierVersion() {
1756            if(empty($this->specificMetadata)) {
1757                $this->getSpecificMetadata();
1758            }
1759            return $this->specificMetadata->version;
1760        }
1761        /**
1762         * Récupération du numéro de dossier d'autorisation à ajouter aux métadonnées
1763         * @return string numéro de dossier d'autorisation
1764         */
1765        protected function getNumDemandeAutor() {
1766            if(empty($this->specificMetadata)) {
1767                $this->getSpecificMetadata();
1768            }
1769            return $this->specificMetadata->dossier_autorisation;
1770        }
1771        /**
1772         * Récupération de la date de demande initiale du dossier à ajouter aux métadonnées
1773         * @return date de la demande initiale
1774         */
1775        protected function getAnneemoisDemandeAutor() {
1776            if(empty($this->specificMetadata)) {
1777                $this->getSpecificMetadata();
1778            }
1779            return $this->specificMetadata->date_demande_initiale;
1780        }
1781        /**
1782         * Récupération du type de dossier d'instruction à ajouter aux métadonnées
1783         * @return string type du dossier d'instruction
1784         */
1785        protected function getTypeInstruction() {
1786            if(empty($this->specificMetadata)) {
1787                $this->getSpecificMetadata();
1788            }
1789            return $this->specificMetadata->dossier_instruction_type;
1790        }
1791        /**
1792         * Récupération du statut du dossier d'autorisation à ajouter aux métadonnées
1793         * @return string avis
1794         */
1795        protected function getStatutAutorisation() {
1796            if(empty($this->specificMetadata)) {
1797                $this->getSpecificMetadata();
1798            }
1799            return $this->specificMetadata->statut;
1800        }
1801        /**
1802         * Récupération du type de dossier d'autorisation à ajouter aux métadonnées
1803         * @return string type du dossier d'autorisation
1804         */
1805        protected function getTypeAutorisation() {
1806            if(empty($this->specificMetadata)) {
1807                $this->getSpecificMetadata();
1808            }
1809            return $this->specificMetadata->dossier_autorisation_type;
1810        }
1811        /**
1812         * Récupération de la date d'ajout de document à ajouter aux métadonnées
1813         * @return date de l'évènement
1814         */
1815        protected function getDateEvenementDocument() {
1816            return date("Y-m-d");
1817        }
1818        /**
1819         * Récupération du groupe d'instruction à ajouter aux métadonnées
1820         * @return string Groupe d'instruction
1821         */
1822        protected function getGroupeInstruction() {
1823            if(empty($this->specificMetadata)) {
1824                $this->getSpecificMetadata();
1825            }
1826            return $this->specificMetadata->groupe_instruction;
1827        }
1828        /**
1829         * Récupération du libellé du type du document à ajouter aux métadonnées
1830         * @return string Groupe d'instruction
1831         */
1832        protected function getTitle() {
1833    
1834            // Récupère le champ événement
1835            if (isset($this->valF["evenement"]) AND $this->valF["evenement"] != "") {
1836                $evenement = $this->valF["evenement"];
1837            } else {
1838                $evenement = $this->getVal("evenement");
1839            }
1840    
1841            // Requête sql
1842            $sql = "SELECT libelle FROM ".DB_PREFIXE."evenement
1843                    WHERE evenement=".$evenement;
1844            $evenement_libelle = $this->db->getOne($sql);
1845            $this->addToLog("getTitle(): db->getOne(\"".$sql."\");", VERBOSE_MODE);
1846            if (database::isError($evenement_libelle)) {
1847                die();
1848            }
1849    
1850            // Retourne le libelle de l'événement
1851            return $evenement_libelle;
1852        }
1853    
1854        /**
1855         * Cette méthode permet de stocker en attribut toutes les métadonnées
1856         * nécessaire à l'ajout d'un document.
1857         */
1858        public function getSpecificMetadata() {
1859            if (isset($this->valF["dossier"]) AND $this->valF["dossier"] != "") {
1860                $dossier = $this->valF["dossier"];
1861            } else {
1862                $dossier = $this->getVal("dossier");
1863            }
1864            //Requête pour récupérer les informations essentiels sur le dossier d'instruction
1865            $sql = "SELECT dossier.dossier as dossier,
1866                            dossier_autorisation.dossier_autorisation as dossier_autorisation,
1867                            to_char(dossier.date_demande, 'YYYY/MM') as date_demande_initiale,
1868                            dossier_instruction_type.code as dossier_instruction_type,
1869                            etat_dossier_autorisation.libelle as statut,
1870                            dossier_autorisation_type.code as dossier_autorisation_type,
1871                            groupe.code as groupe_instruction
1872                    FROM ".DB_PREFIXE."dossier
1873                        LEFT JOIN ".DB_PREFIXE."dossier_instruction_type  
1874                            ON dossier.dossier_instruction_type = dossier_instruction_type.dossier_instruction_type
1875                        LEFT JOIN ".DB_PREFIXE."dossier_autorisation
1876                            ON dossier.dossier_autorisation = dossier_autorisation.dossier_autorisation
1877                        LEFT JOIN ".DB_PREFIXE."etat_dossier_autorisation
1878                            ON  dossier_autorisation.etat_dossier_autorisation = etat_dossier_autorisation.etat_dossier_autorisation
1879                        LEFT JOIN ".DB_PREFIXE."dossier_autorisation_type_detaille
1880                            ON dossier_autorisation.dossier_autorisation_type_detaille = dossier_autorisation_type_detaille.dossier_autorisation_type_detaille
1881                        LEFT JOIN ".DB_PREFIXE."dossier_autorisation_type
1882                            ON dossier_autorisation_type_detaille.dossier_autorisation_type = dossier_autorisation_type.dossier_autorisation_type
1883                        LEFT JOIN ".DB_PREFIXE."groupe
1884                            ON dossier_autorisation_type.groupe = groupe.groupe
1885                    WHERE dossier.dossier = '".$dossier."'";
1886            $res = $this->db->query($sql);
1887            $this->f->addToLog("getSpecificMetadata() : db->query(".$sql.")", VERBOSE_MODE);
1888            if ( database::isError($res)){
1889                die();
1890            }
1891                    
1892          $sql = "SELECT          //Le résultat est récupéré dans un objet
1893                      dossier_autorisation.dossier_autorisation          $row =& $res->fetchRow(DB_FETCHMODE_OBJECT);
1894                  FROM  
1895                      ".DB_PREFIXE."dossier_autorisation          //Si il y a un résultat
1896                  LEFT JOIN          if ($row !== null) {
1897                    
1898                //Génération du numéro de version
1899                $sql = "SELECT
1900                            count(*)
1901                    FROM
1902                      ".DB_PREFIXE."dossier                      ".DB_PREFIXE."dossier
1903                    LEFT JOIN
1904                        ".DB_PREFIXE."dossier_autorisation
1905                      ON                      ON
1906                          dossier_autorisation.dossier_autorisation = dossier.dossier_autorisation                          dossier_autorisation.dossier_autorisation = dossier.dossier_autorisation
1907                    LEFT JOIN
1908                        ".DB_PREFIXE."dossier_instruction_type
1909                        ON
1910                            dossier_instruction_type.dossier_instruction_type = dossier.dossier_instruction_type
1911                  WHERE                  WHERE
1912                      dossier.dossier = '".$dossier_instruction."'";                      dossier_autorisation.dossier_autorisation = '".$row['dossier_autorisation']."'
1913                              AND
1914          $IDdossier_autorisation = $this->db->getOne($sql);                      dossier_instruction_type.code = '".$row['dossier_instruction_type']."'";
1915          $this->addToLog("getDossierAutorisation(): db->getone(\"".$sql."\")", VERBOSE_MODE);              $row['version'] = $this->db->getOne($sql);
1916          database::isError($IDdossier_autorisation);              $this->f->addToLog("getSpecificMetadata(): db->getOne(\"".$sql."\")", VERBOSE_MODE);
1917                if ( database::isError($row['version'])){
1918                    $this->f->addToError("", $row['version'], $row['version']);
1919                    return false;
1920                }
1921                
1922                //Formatage du numéro de version
1923                $row['version'] = str_pad($row['version'], 2, "0", STR_PAD_LEFT);
1924    
1925                //Alors on créé l'objet dossier_instruction
1926                $this->specificMetadata = $row;
1927    
1928            }
1929        }
1930        
1931        /**
1932         * Retourne le statut du dossier d'instruction
1933         * @param string $idx Identifiant du dossier d'instruction
1934         * @return string Le statut du dossier d'instruction
1935         */
1936        function getStatutAutorisationDossier($idx){
1937                    
1938          return $IDdossier_autorisation;          $statut = '';
1939            
1940            //Si l'identifiant du dossier d'instruction fourni est correct
1941            if ( $idx != '' ){
1942                
1943                //On récupère le statut de l'état du dossier à partir de l'identifiant du
1944                //dossier
1945                $sql = "SELECT etat.statut
1946                    FROM ".DB_PREFIXE."dossier
1947                    LEFT JOIN
1948                        ".DB_PREFIXE."etat
1949                        ON
1950                            dossier.etat = etat.etat
1951                    WHERE dossier ='".$idx."'";
1952                $statut = $this->db->getOne($sql);
1953                $this->f->addToLog("getStatutAutorisationDossier() : db->getOne(\"".$sql."\")", VERBOSE_MODE);
1954                if ( database::isError($statut)){
1955                    die();
1956                }
1957            }
1958            return $statut;
1959      }      }
1960  }// fin classe  }// fin classe
1961  ?>  ?>

Legend:
Removed from v.1571  
changed lines
  Added in v.2119

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26