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

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

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

revision 871 by fmichon, Wed Nov 28 21:28:38 2012 UTC revision 943 by fmichon, Fri Nov 30 15:25:27 2012 UTC
# Line 26  class dossier extends dossier_gen { Line 26  class dossier extends dossier_gen {
26      var $aff_description = "startClosed";      var $aff_description = "startClosed";
27      var $aff_amenagement = "startClosed";      var $aff_amenagement = "startClosed";
28    
29          function dossier($id,&$db,$DEBUG) {      function dossier($id,&$db,$DEBUG) {
30          $this->constructeur($id,$db,$DEBUG);          $this->constructeur($id,$db,$DEBUG);
31      } // fin constructeur      } // fin constructeur
32        
33        // {{{ Gestion de la confidentialité des données spécifiques
34    
35        /**
36         * Surcharge pour gérer les actions disponibles dans le portlet
37         */
38        function checkAccessibility() {
39            //
40            parent::checkAccessibility();
41            // Si l'utilisateur est un intructeur qui en correspond pas à la
42            // division du dossier
43            if ($this->f->isUserInstructeur()
44                && isset($this->f->om_utilisateur["division"])
45                && $this->f->om_utilisateur["division"] != $this->getDivisionFromDossier()) {
46                //
47                $this->actions_sup = array();
48                $this->setParameter("actions", array());
49            }
50        }
51    
52        /**
53         * Cette methode est à surcharger elle permet de tester dans chaque classe
54         * des droits des droits spécifiques en fonction des données
55         */
56        function canAccess() {
57            // Si l'utilisateur est un intructeur qui ne correspond pas à la
58            // division du dossier
59            if ($this->f->isUserInstructeur()
60                && $this->f->om_utilisateur["division"] != $this->getDivisionFromDossier()
61                && $this->getParameter("maj") != 3) {
62                //
63                return false;
64            }
65            //
66            return true;
67        }
68    
69        /**
70         * Cette méthode permet de récupérer la division d'un dossier
71         */
72        function getDivisionFromDossier() {
73            //
74            if (!isset($this->val[array_search("dossier", $this->champs)])) {
75                return NULL;
76            }
77            //
78            $sql = "select division from ".DB_PREFIXE."dossier ";
79            $sql .= " where dossier='".$this->val[array_search("dossier", $this->champs)]."'";
80            //
81            $division = $this->db->getOne($sql);
82            $this->addToLog("getDivisionFromDossier(): db->getone(\"".$sql."\")", VERBOSE_MODE);
83            database::isError($division);
84            //
85            return $division;
86        }
87    
88        // }}}
89    
90      function setValFAjout($val = array()) {      function setValFAjout($val = array()) {
91          // Cle primaire          $this->valF['dossier'] = $val['dossier_autorisation'].str_pad(rand(1, 99),2, "0", STR_PAD_LEFT);
         $lettre=$this->f->collectivite["lettre"];  
         $numero_unique = $this->f->collectivite["numero_unique"];  
         if($numero_unique==1){  
         // numero unique (voir dyn/var.inc)  
         $temp=$this->$db->nextId(DB_PREFIXE.$this->table);  
         }else{  
         // numero suivant nature  
         $temp=$this->db->nextId(DB_PREFIXE."dossier_".$val['nature']);  
         }  
         $temp=str_pad($temp,4,"0", STR_PAD_LEFT);  
         $this->valF['dossier'] = $this->valF['nature'].$this->valF['annee'].  
                                  $lettre.$temp;  
92      }      }
93    
94      function setvalF($val){      function setvalF($val){
# Line 316  class dossier extends dossier_gen { Line 361  class dossier extends dossier_gen {
361          if(!$this->f->getParameter('afficher_division') === 'true') {          if(!$this->f->getParameter('afficher_division') === 'true') {
362              $form->setType('division', 'hidden');              $form->setType('division', 'hidden');
363          }          }
364            $form->setType('dossier_autorisation', 'hiddenstatic');
365            //
366            if ($maj == 0) {
367                $form->setType('dossier_autorisation', 'select');
368            }
369      }      }
370    
371      function setVal(&$form,$maj,$validation){      function setVal(&$form,$maj,$validation){
# Line 713  class dossier extends dossier_gen { Line 763  class dossier extends dossier_gen {
763                    
764      }      }
765    
       
   
766      /* =============================================================      /* =============================================================
767      * fonction trigger relative a la connexion SIG      * fonction trigger relative a la connexion SIG
768      * $sig = 1 dans dyn/var.inc      * $sig = 1 dans dyn/var.inc
# Line 734  class dossier extends dossier_gen { Line 782  class dossier extends dossier_gen {
782                  $this->addToMessage("<br>"._("Parcelle non renseignee dans dossier")." ".$id." <br>");                  $this->addToMessage("<br>"._("Parcelle non renseignee dans dossier")." ".$id." <br>");
783                            
784          }          }
785                    
786            // envoi du message a ERP en cas d'un depot du dossier dat
787            if ($this->valF['nature'] ==
788                    $this->f->getParameter('erp_depot_dossier_dat')) {
789                $msgenque = new MessageEnqueuer();
790                $msgenque->setDossierInstructionIdentifier($this->valF['dossier']);
791                $msgenque->enqueueMessage($msgenque::$ERP_DEPOT_DOSSIER_DAT);
792            }
793            
794            // envoi du message a ERP en cas d'une demande d'ouverture DAT
795            if ($this->valF['nature'] ==
796                    $this->f->getParameter('erp_demande_ouverture_dat')) {
797                $msgenque = new MessageEnqueuer();
798                $msgenque->setDossierInstructionIdentifier($this->valF['dossier']);
799                $msgenque->enqueueMessage($msgenque::$ERP_DEMANDE_OUVERTURE_DAT);
800            }
801            
802            if ($this->valF['erp'] === true) {
803                // envoi du message a ERP en cas d'annulation d'une demande
804                if ($this->valF['nature'] ==
805                        $this->f->getParameter('erp_annulation_demande')) {
806                    $msgenque = new MessageEnqueuer();
807                    $msgenque->setDossierInstructionIdentifier($this->valF['dossier']);
808                    $msgenque->enqueueMessage($msgenque::$ERP_ANNULATION_DEMANDE);
809                }
810                
811                // envoi du message a ERP en cas d'ouverture d'un dossier PC "rattache"
812                // au dossier DAACT
813                if ($this->valF['nature'] ==
814                        $this->f->getParameter('erp_demande_ouverture_pc_daact')) {
815                    $msgenque = new MessageEnqueuer();
816                    $msgenque->setDossierInstructionIdentifier($this->valF['dossier']);
817                    $msgenque->enqueueMessage($msgenque::$ERP_DEMANDE_OUVERTURE_PC);
818                }
819            }
820                    
821      }      }
822            
# Line 764  class dossier extends dossier_gen { Line 847  class dossier extends dossier_gen {
847              $sql = "SELECT              $sql = "SELECT
848                          quartier, arrondissement                          quartier, arrondissement
849                      FROM                      FROM
850                          quartier                          ".DB_PREFIXE."quartier
851                      WHERE                      WHERE
852                          code_impots='$quartier'";                          code_impots='$quartier'";
853                            
# Line 800  class dossier extends dossier_gen { Line 883  class dossier extends dossier_gen {
883      /*      /*
884       * Retourne l'intructeur correspondant le mieux à la parcelle       * Retourne l'intructeur correspondant le mieux à la parcelle
885       * */       * */
886       function getInstructeurDivision( $quartier, $arrondissement, $section, $nature) {       function getInstructeurDivision( $quartier, $arrondissement, $section, $dossier_autorisation) {
887                                    
888          $quartier = ( $quartier == NULL ) ? -1 : $quartier;          $quartier = ( $quartier == NULL ) ? -1 : $quartier;
889          $arrondissement = ( $arrondissement == NULL ) ? -1 : $arrondissement;          $arrondissement = ( $arrondissement == NULL ) ? -1 : $arrondissement;
890                    
891            /*Récupération du dossier_autorisation_type_detaille concerné par le $dossier_autorisation*/
892          $sql = "          $sql = "
893             SELECT             SELECT
894                 instructeur, section, quartier, arrondissement, nature                 dossier_autorisation_type_detaille
895             FROM             FROM
896                 lien_localisation_nature l                 ".DB_PREFIXE."dossier_autorisation
897             WHERE             WHERE
898                 ( nature IS NULL AND arrondissement IS NULL AND quartier IS NULL AND section IS NULL ) OR                 dossier_autorisation = '$dossier_autorisation'";    
899                 ( nature IS NULL AND arrondissement IS NULL AND quartier IS NULL AND section = '$section' ) OR          
900                 ( nature IS NULL AND arrondissement IS NULL AND quartier = $quartier AND section IS NULL ) OR          $this->addToLog("getInstructeurDivision : db->query(\"$sql\")", VERBOSE_MODE);
901                 ( nature IS NULL AND arrondissement IS NULL AND quartier = $quartier AND section = '$section' ) OR          $resDATD = $this->db->query($sql);
902                 ( nature IS NULL AND arrondissement = $arrondissement AND quartier IS NULL AND section IS NULL ) OR          if (database :: isError($resDATD))
903                 ( nature IS NULL AND arrondissement = $arrondissement AND quartier IS NULL AND section = '$section' ) OR              die($resDATD->getMessage()."erreur ".$sql);
                ( nature IS NULL AND arrondissement = $arrondissement AND quartier = $quartier AND section IS NULL ) OR  
                ( nature IS NULL AND arrondissement = $arrondissement AND quartier = $quartier AND section = '$section' ) OR  
                ( nature = '$nature' AND arrondissement IS NULL AND quartier IS NULL AND section IS NULL ) OR  
                ( nature = '$nature' AND arrondissement IS NULL AND quartier IS NULL AND section = '$section' ) OR  
                ( nature = '$nature' AND arrondissement IS NULL AND quartier = $quartier AND section IS NULL ) OR  
                ( nature = '$nature' AND arrondissement IS NULL AND quartier = $quartier AND section = '$section' ) OR  
                ( nature = '$nature' AND arrondissement = $arrondissement AND quartier IS NULL AND section IS NULL ) OR  
                ( nature = '$nature' AND arrondissement = $arrondissement AND quartier IS NULL AND section = '$section' ) OR  
                ( nature = '$nature' AND arrondissement = $arrondissement AND quartier = $quartier AND section IS NULL ) OR  
                ( nature = '$nature' AND arrondissement = $arrondissement AND quartier = $quartier AND section = '$section' )  
            ORDER BY section, quartier, arrondissement, nature  
            LIMIT 1  
         ";  
           
         $this->addToLog("getInstructeurDivision( quartier, arrondissement, section, nature) : db->query(\"$sql\")", VERBOSE_MODE);  
         $res = $this->db->query($sql);  
         if (database :: isError($res))  
             die($res->getMessage()."erreur ".$sql);  
904                    
905          if ( $res->numRows() > 0 ){          if ( $resDATD->numRows() > 0 ){
906                $rowDATD = $resDATD->fetchRow(DB_FETCHMODE_ASSOC);
907                            
908              $row = $res->fetchRow(DB_FETCHMODE_ASSOC);              $sql = "
909                   SELECT
910                       instructeur, section, quartier, arrondissement, dossier_autorisation_type_detaille
911                   FROM
912                       ".DB_PREFIXE."affectation_automatique l
913                   WHERE
914                       ( dossier_autorisation_type_detaille IS NULL AND arrondissement IS NULL AND quartier IS NULL AND section IS NULL ) OR
915                       ( dossier_autorisation_type_detaille IS NULL AND arrondissement IS NULL AND quartier IS NULL AND section = '$section' ) OR
916                       ( dossier_autorisation_type_detaille IS NULL AND arrondissement IS NULL AND quartier = $quartier AND section IS NULL ) OR
917                       ( dossier_autorisation_type_detaille IS NULL AND arrondissement IS NULL AND quartier = $quartier AND section = '$section' ) OR
918                       ( dossier_autorisation_type_detaille IS NULL AND arrondissement = $arrondissement AND quartier IS NULL AND section IS NULL ) OR
919                       ( dossier_autorisation_type_detaille IS NULL AND arrondissement = $arrondissement AND quartier IS NULL AND section = '$section' ) OR
920                       ( dossier_autorisation_type_detaille IS NULL AND arrondissement = $arrondissement AND quartier = $quartier AND section IS NULL ) OR
921                       ( dossier_autorisation_type_detaille IS NULL AND arrondissement = $arrondissement AND quartier = $quartier AND section = '$section' ) OR
922                       ( dossier_autorisation_type_detaille = ".$rowDATD['dossier_autorisation_type_detaille']." AND arrondissement IS NULL AND quartier IS NULL AND section IS NULL ) OR
923                       ( dossier_autorisation_type_detaille = ".$rowDATD['dossier_autorisation_type_detaille']." AND arrondissement IS NULL AND quartier IS NULL AND section = '$section' ) OR
924                       ( dossier_autorisation_type_detaille = ".$rowDATD['dossier_autorisation_type_detaille']." AND arrondissement IS NULL AND quartier = $quartier AND section IS NULL ) OR
925                       ( dossier_autorisation_type_detaille = ".$rowDATD['dossier_autorisation_type_detaille']." AND arrondissement IS NULL AND quartier = $quartier AND section = '$section' ) OR
926                       ( dossier_autorisation_type_detaille = ".$rowDATD['dossier_autorisation_type_detaille']." AND arrondissement = $arrondissement AND quartier IS NULL AND section IS NULL ) OR
927                       ( dossier_autorisation_type_detaille = ".$rowDATD['dossier_autorisation_type_detaille']." AND arrondissement = $arrondissement AND quartier IS NULL AND section = '$section' ) OR
928                       ( dossier_autorisation_type_detaille = ".$rowDATD['dossier_autorisation_type_detaille']." AND arrondissement = $arrondissement AND quartier = $quartier AND section IS NULL ) OR
929                       ( dossier_autorisation_type_detaille = ".$rowDATD['dossier_autorisation_type_detaille']." AND arrondissement = $arrondissement AND quartier = $quartier AND section = '$section' )
930                   ORDER BY section, quartier, arrondissement, dossier_autorisation_type_detaille
931                   LIMIT 1
932                ";
933                            
934              $sql = "SELECT division FROM instructeur WHERE instructeur = ".$row['instructeur'];              $this->addToLog("getInstructeurDivision : db->query(\"$sql\")", VERBOSE_MODE);
935              $res = $this->db->query($sql);              $res = $this->db->query($sql);
936              if (database :: isError($res))              if (database :: isError($res))
937                  die($res->getMessage()."erreur ".$sql);                  die($res->getMessage()."erreur ".$sql);
938                                
939              if ( $res->numRows() > 0 ){              if ( $res->numRows() > 0 ){
940                                    
941                  $rowT=& $res->fetchRow(DB_FETCHMODE_ASSOC);                  $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
942                  $row['division'] = $rowT['division'];                  
943                    $sql = "SELECT division FROM ".DB_PREFIXE."instructeur WHERE instructeur = ".$row['instructeur'];
944                    $res = $this->db->query($sql);
945                    if (database :: isError($res))
946                        die($res->getMessage()."erreur ".$sql);
947                        
948                    if ( $res->numRows() > 0 ){
949                        
950                        $rowT=& $res->fetchRow(DB_FETCHMODE_ASSOC);
951                        $row['division'] = $rowT['division'];
952                    }
953                    
954                    return $row;
955              }              }
               
             return $row;  
956          }          }
957            
958          return NULL;          return NULL;
959       }       }
960            
# Line 893  class dossier extends dossier_gen { Line 994  class dossier extends dossier_gen {
994              $section = $this->getSection($val['parcelle']);              $section = $this->getSection($val['parcelle']);
995          }          }
996                    
997          // Si aucun instructeur n'est saisi et que la nature n'est pas vide          // Si aucun instructeur n'est saisi et que la dossier_autorisation_type_detaille n'est pas vide
998          // alors on récupère l'instructeur et la division depuis l'affectation          // alors on récupère l'instructeur et la division depuis l'affectation
999          if ( ( empty($this->valF['instructeur']) || $this->valF['instructeur'] == '' ) && $val['nature'] != '' ) {          if ( ( empty($this->valF['instructeur']) || $this->valF['instructeur'] == '' ) && $val['dossier_autorisation'] != '' ) {
1000                            
1001              //              //
1002              $instructeurDivision = $this->getInstructeurDivision($quartier, $arrondissement, $section, $val['nature']);              $instructeurDivision = $this->getInstructeurDivision($quartier, $arrondissement, $section, $val['dossier_autorisation']);
1003              if ( $instructeurDivision != NULL ){              if ( $instructeurDivision != NULL ){
1004                                    
1005                  $instructeur = $instructeurDivision['instructeur'];                  $instructeur = $instructeurDivision['instructeur'];
# Line 941  class dossier extends dossier_gen { Line 1042  class dossier extends dossier_gen {
1042                  $this->addToMessage("<br>"._("Parcelle ou parcelle_lot non renseignee dans dossier")." ".$id." <br>");                      $this->addToMessage("<br>"._("Parcelle ou parcelle_lot non renseignee dans dossier")." ".$id." <br>");    
1043              }              }
1044          }          }
1045            
1046            // BOGUE: le test pour la nature doit etre change parce que
1047            // 'erp_depot_dossier_dat' n'a pas la connexion directe avec
1048            // qualification d'un dossier, mais c'est necessaire pour les tests
1049            if ($this->val[array_search('a_qualifier', $this->champs)] == 't'
1050                && $this->valF['a_qualifier'] === false) {
1051                
1052                $dossier_nature_dat = array(
1053                        $this->f->getParameter('erp_depot_dossier_dat'),
1054                        $this->f->getParameter('erp_demande_ouverture_dat'));
1055                
1056                // envoi du message "ERP Qualifie" pour un dossier DAT qui a besoin
1057                // de la qualification URBA
1058                if (in_array($this->valF['nature'], $dossier_nature_dat)) {
1059                    $msgenque = new MessageEnqueuer();
1060                    $msgenque->setDossierInstructionIdentifier($this->valF['dossier']);
1061                    $msgenque->setCompetence($this->valF['autorite_competente']);
1062                    $msgenque->setContraintePlu($this->valF['servitude']);
1063                    $msgenque->setReferenceCadastrale(
1064                            $this->getReferenceCadastrale($this->valF['dossier']));
1065                    $msgenque->enqueueMessage($msgenque::$ERP_QUALIFIE);                            
1066                }
1067                
1068                // envoi des messages a ERP en cas du dossier PC traite par URBA, et
1069                // qui etait classifie come ERP
1070                if ($this->valF['nature'] == 'PC' && $this->valF['erp'] == true) {
1071                    $msgenque = new MessageEnqueuer();
1072                    $msgenque->setDossierInstructionIdentifier($this->valF['dossier']);
1073                    $msgenque->enqueueMessage($msgenque::$ERP_DEMANDE_COMPLETUDE_PC);
1074                    $msgenque->enqueueMessage($msgenque::$ERP_DEMANDE_QUALIFICATION_PC);
1075                }
1076                
1077            }    
1078    
1079      }      }
1080        
1081        
1082        /**
1083         * Retourne la reference cadastrale de la demande attache a un dossier ERP
1084         * specifique
1085         * @param string $dossier L'identifiant du dossier
1086         * @return string|null La reference cadastrale si elle est trouve,
1087         * sinon NULL. En cas d'erreur de la BD, l'execution s'arrete.
1088         */
1089        function getReferenceCadastrale($dossier) {
1090            $sql = "SELECT terrain_references_cadastrales FROM ".DB_PREFIXE."demande WHERE dossier_instruction = '" . $dossier . "'";
1091            $res = $this->db->limitquery($sql, 0, 1);
1092            $this->addToLog("getReferenceCadastrale(): db->limitquery(\"".
1093                            str_replace(",",", ",$sql)."\", 0, 1);", VERBOSE_MODE);
1094            // Si une erreur survient on die
1095            if (database::isError($res, true)) {
1096                // Appel de la methode de recuperation des erreurs
1097                $this->erreur_db($res->getDebugInfo(), $res->getMessage(), 'demande');
1098            }
1099            // retourne la nature du dossier
1100            while ($row =& $res->fetchRow()) {
1101                return $row[0];
1102            }
1103            // la nature n'etait pas trouve, ce qui ne devrait pas se passer
1104            return NULL;
1105        }
1106        
1107    
1108      function sig_parametre(&$db){      function sig_parametre(&$db){
1109          if (file_exists ("../dyn/var.inc"))          if (file_exists ("../dyn/var.inc"))

Legend:
Removed from v.871  
changed lines
  Added in v.943

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26