<?php
//$Id$ 
//gen openMairie le 13/02/2013 14:41

require_once ("../gen/obj/donnees_techniques.class.php");

class donnees_techniques extends donnees_techniques_gen {

    var $cerfa;     // Instance de la classe cerfa

    /** @var boolean Les nouvelles actions sont activées sur cet objet */
    var $activate_class_action;

    function donnees_techniques($id,&$db,$debug) {
        //On active les nouvelles actions
        $this->activate_class_action = true;
        $this->constructeur($id,$db,$debug);
    }// fin constructeur

    /**
     * Définition des actions disponibles sur la classe.
     *
     * @return void
     */
    function init_class_actions() {

        // On récupère les actions génériques définies dans la méthode 
        // d'initialisation de la classe parente
        parent::init_class_actions();

        // ACTION - 001 - modifier
        //
        $this->class_actions[1]["condition"] = "is_editable";

        // ACTION - 002 - supprimer
        //
        $this->class_actions[2]["condition"] = "is_deletable";
    }

    /**
     * CONDITION - is_deletable.
     *
     * Condition pour afficher le bouton de suppression.
     *
     * @return boolean
     */
    function is_deletable() {

        // Si c'est un sous-formulaire du dossier d'autorisation
        if ($this->getParameter("retourformulaire") == 'dossier_autorisation'
            || $this->getParameter("retourformulaire") == 'dossier_autorisation_avis') {

            //
            return false;
        }

        // Contrôle si l'utilisateur possède un bypass
        $bypass = $this->f->isAccredited(get_class()."_supprimer_bypass");
        //
        if ($bypass == true) {

            //
            return true;
        }

        // Si l'utilisateur est un intructeur qui ne correspond pas à la
        // division du dossier
        if ($this->f->isUserInstructeur()
            && $this->f->om_utilisateur["division"] != $this->getDivisionFromDossier()) {

            //
            return false;
        }

        // Si l'utilisateur est un instructeur et que le dossier est cloturé
        if ($this->f->isUserInstructeur()
            && $this->getParameter("idxformulaire") != ''
            && $this->f->getStatutDossier($this->getParameter("idxformulaire")) == "cloture") {

            //
            return false;
        }

        //
        return true;
    }

    /**
     * CONDITION - is_editable.
     *
     * Condition pour afficher le bouton de modification.
     *
     * @return boolean
     */
    function is_editable() {

        // Si c'est un sous-formulaire du dossier d'autorisation
        if ($this->getParameter("retourformulaire") == 'dossier_autorisation'
            || $this->getParameter("retourformulaire") == 'dossier_autorisation_avis') {

            //
            return false;
        }

        // Contrôle si l'utilisateur possède un bypass
        $bypass = $this->f->isAccredited(get_class()."_modifier_bypass");
        //
        if ($bypass == true) {

            //
            return true;
        }

        // Si l'utilisateur est un intructeur qui ne correspond pas à la
        // division du dossier
        if ($this->f->isUserInstructeur()
            && $this->f->om_utilisateur["division"] != $this->getDivisionFromDossier()) {

            //
            return false;
        }

        // Si l'utilisateur est un instructeur et que le dossier est cloturé
        if ($this->f->isUserInstructeur()
            && $this->getParameter("idxformulaire") != ''
            && $this->f->getStatutDossier($this->getParameter("idxformulaire")) == "cloture") {

            //
            return false;
        }

        //
        return true;
    }

    /**
     * Méthode permettant de récupérer l'id du cerfa lié au dossier.
     *
     * @return cerfa handler du cerfa
     */
    function getCerfa() {
        if($this->cerfa != null) {
            return $this->cerfa;
        }
        require_once ("../obj/cerfa.class.php");
        $this->cerfa = new cerfa($this->getVal("cerfa"), $this->db, DEBUG);
        return $this->cerfa;
    }

    /**
     * Méthode permettant de vérifier si le tableau passé en parametre est défini
     * dans la table des cerfa
     */

    function setTabSelect($tab, $idchamp) {
        // Test si un tableau de surface a été défini
        if ( $this->cerfa->getVal($idchamp) !=  "" ){
            
            // Configuration du tableau des surfaces
            $contenu['column_header']=$tab[$this->cerfa->getVal($idchamp)]['column_header'];
            $contenu['row_header']=$tab[$this->cerfa->getVal($idchamp)]['row_header'];
    
            foreach($tab[$this->cerfa->getVal($idchamp)]['values'] as $champ) {
                $contenu['values'][$champ] = $this->getVal($champ);
            }
    
            $this->form->setSelect($idchamp,$contenu);
        }
    }


    function setSelect(&$form, $maj,&$db,$debug) {
        if(file_exists ("../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc.php"))
            include ("../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc.php");
        elseif(file_exists ("../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc"))
            include ("../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc");

        if(empty($this->cerfa)) {
            $this->getCerfa();
        }

        $this->setTabSelect($tab_surface, "tab_surface");
        $this->setTabSelect($tab_tax_su_princ, "tab_tax_su_princ");
        $this->setTabSelect($tab_tax_su_heber, "tab_tax_su_heber");
        $this->setTabSelect($tab_tax_su_secon, "tab_tax_su_secon");
        $this->setTabSelect($tab_tax_su_tot, "tab_tax_su_tot");
        $this->setTabSelect($tab_tax_su_non_habit_surf, "tab_tax_su_non_habit_surf");
        $this->setTabSelect($tab_tax_su_parc_statio_expl_comm, "tab_tax_su_parc_statio_expl_comm");
        $this->setTabSelect($tab_tax_am, "tab_tax_am");
        
        // Définition des champs Oui/Non/Je ne sais pas
        $value[] = array(
            "nesaispas",
            "non",
            "oui",
            );
        $value[] = array(
            _("Je ne sais pas"),
            _("Non"),
            _("Oui"),
            );
        
        $form->setSelect('terr_juri_titul',$value);
        $form->setSelect('terr_juri_lot',$value);
        $form->setSelect('terr_juri_zac',$value);
        $form->setSelect('terr_juri_afu',$value);
        $form->setSelect('terr_juri_pup',$value);
        $form->setSelect('terr_juri_oin',$value);
        $form->setSelect('terr_juri_desc',$value);
        $form->setSelect('terr_div_surf_etab',$value);
        $form->setSelect('terr_div_surf_av_div',$value);
        
        
        //Récupérer le nom et le prénom de l'architecte
        $coordonneesArchitecte = $this->getPrenomNomArchitecte($this->getVal('architecte'));
        $value = "";
        if ($maj<2){
            $value = array(
                "data" => $coordonneesArchitecte,
                "obj" => "architecte", 
            );
        }
        else {
            $value[0][0]=$this->getVal('architecte');
            $value[1][0]=$coordonneesArchitecte;// table
        }
        $form->setSelect('architecte', $value);
    }


    // XXX Créer une nouvelle méthode au même endroit que l'appel a checkAccessibility()
    function checkAccessibility() {
        if(file_exists ("../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc.php"))
            include ("../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc.php");
        elseif(file_exists ("../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc"))
            include ("../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc");

        //
        if(empty($this->cerfa)) {
            $this->getCerfa();
        }

        $id_tab_surface = $this->cerfa->getVal("tab_surface");
        $id_tab_tax_su_princ = $this->cerfa->getVal("tab_tax_su_princ");
        $id_tab_tax_su_heber = $this->cerfa->getVal("tab_tax_su_heber");
        $id_tab_tax_su_secon = $this->cerfa->getVal("tab_tax_su_secon");
        $id_tab_tax_su_tot = $this->cerfa->getVal("tab_tax_su_tot");
        $id_tab_tax_su_non_habit_surf = $this->cerfa->getVal("tab_tax_su_non_habit_surf");
        $id_tab_tax_su_parc_statio_expl_comm = $this->cerfa->getVal("tab_tax_su_parc_statio_expl_comm");
        $id_tab_tax_am = $this->cerfa->getVal("tab_tax_am");

        //Suppression des champs de tableaux
        if(!empty($id_tab_surface)) {
            foreach($tab_surface[$this->cerfa->getVal("tab_surface")]['values'] as $champ) {
                unset($this->champs[array_search($champ,$this->champs)]);
            }
        }
        if(!empty($id_tab_tax_su_princ)) {
            foreach($tab_tax_su_princ[$this->cerfa->getVal("tab_tax_su_princ")]['values'] as $champ) {
                unset($this->champs[array_search($champ,$this->champs)]);
            }
        }
        if(!empty($id_tab_tax_su_heber)) {
            foreach($tab_tax_su_heber[$this->cerfa->getVal("tab_tax_su_heber")]['values'] as $champ) {
                unset($this->champs[array_search($champ,$this->champs)]);
            }
        }
        if(!empty($id_tab_tax_su_secon)) {
            foreach($tab_tax_su_secon[$this->cerfa->getVal("tab_tax_su_secon")]['values'] as $champ) {
                unset($this->champs[array_search($champ,$this->champs)]);
            }
        }
        if(!empty($id_tab_tax_su_tot)) {
            foreach($tab_tax_su_tot[$this->cerfa->getVal("tab_tax_su_tot")]['values'] as $champ) {
                unset($this->champs[array_search($champ,$this->champs)]);
            }
        }
        if(!empty($id_tab_tax_su_non_habit_surf)) {
            foreach($tab_tax_su_non_habit_surf[$this->cerfa->getVal("tab_tax_su_non_habit_surf")]['values'] as $champ) {
                unset($this->champs[array_search($champ,$this->champs)]);
            }
        }
        if(!empty($id_tab_tax_su_parc_statio_expl_comm)) {
            foreach($tab_tax_su_parc_statio_expl_comm[$this->cerfa->getVal("tab_tax_su_parc_statio_expl_comm")]['values'] as $champ) {
                unset($this->champs[array_search($champ,$this->champs)]);
            }
        }
        if(!empty($id_tab_tax_am)) {
            foreach($tab_tax_am[$this->cerfa->getVal("tab_tax_am")]['values'] as $champ) {
                unset($this->champs[array_search($champ,$this->champs)]);
            }
        }
        // Renumérotation
        $this->champs = array_values($this->champs);
    }

    /**
     * Méthode permettant de définir le type des différents tableaux en fonction 
     * des valeurs du cerfa
     **/
    function setTabType($tab) {
        // Définition du type "tableau"
        if ( $this->cerfa->getVal($tab) !=  "" ){
            
            $this->form->setType($tab,'tableau');
        }
        //Le chache si non défini
        else {
            
            $this->form->setType($tab,'hidden');
        }
    }

    /**
     * Méthode permettant de définir le type des champs des tableaux en fonction 
     * des valeurs du cerfa
     **/
    function setTabChampType($tab) {
        if(file_exists ("../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc.php"))
            include ("../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc.php");
        elseif(file_exists ("../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc"))
            include ("../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc");
        // Pour chaque champ dans la liste des champs du cerfa 
        $tableau = $$tab;
        foreach ($this->champs as $champ) {
            
            if(array_search($champ, $this->cerfa->champs) !== false) {
                // On les cache si décoché dans le formulaire de cerfa
                if($this->cerfa->getVal($champ) == 'f') {
                    $this->form->setType($champ,'hidden');
                }
            } else {
                
                if(!in_array($champ, $tableau[$this->cerfa->getVal($tab)]['values'])) {

                    $this->form->setType($champ,'hidden');
                }
            }
        }
    }



    function setType(&$form,$maj) {
        parent::setType($form,$maj);

        if(file_exists ("../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc.php"))
            include ("../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc.php");
        elseif(file_exists ("../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc"))
            include ("../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc");

        if(empty($this->cerfa)) {
            $this->getCerfa();
        }

        $this->setTabType("tab_surface");
        $this->setTabType("tab_tax_su_princ");
        $this->setTabType("tab_tax_su_heber");
        $this->setTabType("tab_tax_su_secon");
        $this->setTabType("tab_tax_su_tot");
        $this->setTabType("tab_tax_su_non_habit_surf");
        $this->setTabType("tab_tax_su_parc_statio_expl_comm");
        $this->setTabType("tab_tax_am");

        //Champs select pour les liste a choix oui/non/je ne sais pas (terr_*)
        if($maj == 0) {
            $form->setType('terr_juri_titul','select');
            $form->setType('terr_juri_lot','select');
            $form->setType('terr_juri_zac','select');
            $form->setType('terr_juri_afu','select');
            $form->setType('terr_juri_pup','select');
            $form->setType('terr_juri_oin','select');
            $form->setType('architecte', 'manage_with_popup');

        } elseif($maj == 1) {
            $form->setType('terr_juri_titul','select');
            $form->setType('terr_juri_lot','select');
            $form->setType('terr_juri_zac','select');
            $form->setType('terr_juri_afu','select');
            $form->setType('terr_juri_pup','select');
            $form->setType('terr_juri_oin','select');
            $form->setType('architecte', 'manage_with_popup');

        } elseif($maj == 2) {
            $form->setType('terr_juri_titul','selectstatic');
            $form->setType('terr_juri_lot','selectstatic');
            $form->setType('terr_juri_zac','selectstatic');
            $form->setType('terr_juri_afu','selectstatic');
            $form->setType('terr_juri_pup','selectstatic');
            $form->setType('terr_juri_oin','selectstatic');
            $form->setType('architecte', 'selectstatic');

        } elseif($maj == 3) {
            $form->setType('terr_juri_titul','selectstatic');
            $form->setType('terr_juri_lot','selectstatic');
            $form->setType('terr_juri_zac','selectstatic');
            $form->setType('terr_juri_afu','selectstatic');
            $form->setType('terr_juri_pup','selectstatic');
            $form->setType('terr_juri_oin','selectstatic');
            $form->setType('architecte', 'selectstatic');

        }

        // Anciens champs à conserver pour les anciens cerfa
        $form->setType("co_statio_avt_shob", "hidden");
        $form->setType("co_statio_apr_shob", "hidden");
        $form->setType("co_statio_avt_surf", "hidden");
        $form->setType("co_statio_apr_surf", "hidden");
        $form->setType("co_trx_amgt", "hidden");
        $form->setType("co_modif_aspect", "hidden");
        $form->setType("co_modif_struct", "hidden");
        $form->setType("co_trx_imm", "hidden");
        $form->setType("co_cstr_shob", "hidden");
        $form->setType("am_voyage_deb", "hidden");
        $form->setType("am_voyage_fin", "hidden");
        $form->setType("am_modif_amgt", "hidden");
        $form->setType("am_lot_max_shob", "hidden");
        $form->setType("mod_desc", "hidden");
        $form->setType("tr_total", "hidden");
        $form->setType("tr_partiel", "hidden");
        $form->setType("tr_desc", "hidden");
        $form->setType("avap_co_clot", "hidden");
        $form->setType("avap_aut_coup_aba_arb", "hidden");
        $form->setType("avap_ouv_infra", "hidden");
        $form->setType("avap_aut_inst_mob", "hidden");
        $form->setType("avap_aut_plant", "hidden");
        $form->setType("avap_aut_auv_elec", "hidden");
        $form->setType("tax_dest_loc_tr", "hidden");


        //Cache les champs des clés étrangères, elles sont renseignées automatiquement
        $form->setType('dossier_instruction', 'hidden');
        $form->setType('lot', 'hidden');
        $form->setType('cerfa', 'hidden');
        
        // Boucler sur les champs du cerfa pour cacher les données qui ne doivent
        // pas être saisies

        foreach ($this->champs as $champ) {
            if(array_search($champ, $this->cerfa->champs) !== false) {
                if($this->cerfa->getVal($champ) == 'f') {
                    $form->setType($champ,'hidden');
                }
            } else {
                $id_tab_surface = $this->cerfa->getVal("tab_surface");
                $id_tab_tax_su_princ = $this->cerfa->getVal("tab_tax_su_princ");
                $id_tab_tax_su_heber = $this->cerfa->getVal("tab_tax_su_heber");
                $id_tab_tax_su_secon = $this->cerfa->getVal("tab_tax_su_secon");
                $id_tab_tax_su_tot = $this->cerfa->getVal("tab_tax_su_tot");
                $id_tab_tax_su_non_habit_surf = $this->cerfa->getVal("tab_tax_su_non_habit_surf");
                $id_tab_tax_su_parc_statio_expl_comm = $this->cerfa->getVal("tab_tax_su_parc_statio_expl_comm");
                $id_tab_tax_am = $this->cerfa->getVal("tab_tax_am");
                $hidden = true;

                // On cache tous les champs
                $form->setType($champ,'hidden');

                // On défini l'affichage des champs des tableaux de configuration
                // Si les tableau sont définis dans le cerfa on test si les champs des données
                // techniques sont définis dans les tableaux de configuration des tableaux
                // pour chaque cerfa  alors on les affiche en type "text"
                if(!empty($id_tab_surface)) {
                    if(in_array($champ, $tab_surface[$this->cerfa->getVal("tab_surface")]['values'])) {
                        $hidden = false;
                    }
                }
                if(!empty($id_tab_tax_su_princ)) {
                    if(in_array($champ, $tab_tax_su_princ[$this->cerfa->getVal("tab_tax_su_princ")]['values'])) {
                        $hidden = false;
                    }
                }
                if(!empty($id_tab_tax_su_heber)) {
                    if(in_array($champ, $tab_tax_su_heber[$this->cerfa->getVal("tab_tax_su_heber")]['values'])) {
                        $hidden = false;
                    }
                }
                if(!empty($id_tab_tax_su_secon)) {
                    if(in_array($champ, $tab_tax_su_secon[$this->cerfa->getVal("tab_tax_su_secon")]['values'])) {
                        $hidden = false;
                    }
                }
                if(!empty($id_tab_tax_su_tot)) {
                    if(in_array($champ, $tab_tax_su_tot[$this->cerfa->getVal("tab_tax_su_tot")]['values'])) {
                        $hidden = false;
                    }
                }
                if(!empty($id_tab_tax_su_non_habit_surf)) {
                    if(in_array($champ, $tab_tax_su_non_habit_surf[$this->cerfa->getVal("tab_tax_su_non_habit_surf")]['values'])) {
                        $hidden = false;
                    }
                }
                if(!empty($id_tab_tax_su_parc_statio_expl_comm)) {
                    if(in_array($champ, $tab_tax_su_parc_statio_expl_comm[$this->cerfa->getVal("tab_tax_su_parc_statio_expl_comm")]['values'])) {
                        $hidden = false;
                    }
                }
                if(!empty($id_tab_tax_am)) {
                    if(in_array($champ, $tab_tax_am[$this->cerfa->getVal("tab_tax_am")]['values'])) {
                        $hidden = false;
                    }
                }

                if(!$hidden){
                    if($maj < 2) {
                        $form->setType($champ,'text');
                    } else {
                        $form->setType($champ,'static');
                    }
                    
                }
            }
        }
    }

    // Ajout des clés étrangères
    function setValsousformulaire(&$form,$maj,$validation,$idxformulaire,$retourformulaire,$typeformulaire,&$db,$DEBUG=null){
        $this->retourformulaire = $retourformulaire;
        if($validation == 0) {
            
            //Si on est dans le dossier
            if($retourformulaire =='dossier' || $retourformulaire =='dossier_instruction' ) {
                
                $form->setVal('dossier_instruction', $idxformulaire);
                $form->setVal('lot', "");
            }
            
            //Si on est dans le lot
            if($retourformulaire =='lot') {
                
                $form->setVal('dossier_instruction', "");
                $form->setVal('lot', $idxformulaire);
            }
        }// fin validation
    }// fin setValsousformulaire

    function setLib(&$form,$maj) {
        parent::setLib($form,$maj);
        //libelle des champs
        $form->setLib('tab_surface', "");
        $form->setLib('tab_tax_su_princ', "");
        $form->setLib('tab_tax_su_heber', "");
        $form->setLib('tab_tax_su_secon', "");
        $form->setLib('tab_tax_su_tot', "");
        $form->setLib('tab_tax_su_non_habit_surf', "");
        $form->setLib('tab_tax_su_parc_statio_expl_comm', "");
        $form->setLib('tab_tax_am', "");
        $form->setLib('ope_proj_desc', _("description"));
    }

    function setLayout(&$form, $maj) {

        // Terrain
        $form->setBloc('terr_juri_titul','D',"","col_12");
            $form->setFieldset('terr_juri_titul','D'
                               ,_("Terrain"), "startClosed");

                $form->setBloc('terr_juri_titul','D',_("Situation juridique du terrain"), "col_12 alignFormSpec");
                $form->setBloc('terr_juri_oin','F');
                $form->setBloc('terr_juri_desc','DF',"", "group");
                $form->setBloc('terr_div_surf_etab','D',_("Terrain issu d'une division de propriete"), "col_12 alignFormSpec");
                $form->setBloc('terr_div_surf_av_div', 'F');

            $form->setFieldset('terr_div_surf_av_div','F','');
            
        $form->setBloc('terr_div_surf_av_div','F');

        // Description de la demande / du projet
        $form->setFieldset('ope_proj_desc', 'D',
            _("Description de la demande / du projet"), "col_12 startClosed");
            $form->setBloc('ope_proj_desc', 'DF', "", "group");
            $form->setBloc('ope_proj_div_co', 'DF', "", "group");
            $form->setBloc('ope_proj_div_contr', 'DF', "", "group");
        $form->setFieldset('ope_proj_div_contr', 'F');

        // Aménager
        $form->setBloc('am_lotiss','D',"","col_12");
            $form->setFieldset('am_lotiss','D'
                                       ,_("Amenager"), "startClosed");
                $form->setBloc('am_lotiss','D',"","col_12");
                    $form->setFieldset('am_lotiss','D'
                                       ,_("Projet d'amenagement"), "startClosed alignFormSpec");
                        // bloc 4.1
                        $form->setBloc('am_lotiss','DF',_("Nature des travaux, installations
                                       ou amenagements envisages"), "group");
                        $form->setBloc('am_div_mun','DF',"", "group");
                        $form->setBloc('am_autre_div','DF',"", "group");
                        $form->setBloc('am_camping','DF',"", "group");
                        $form->setBloc('am_parc_resid_loi','DF',"", "group");
                        $form->setBloc('am_sport_moto','DF',"", "group");
                        $form->setBloc('am_sport_attrac','DF',"", "group");
                        $form->setBloc('am_sport_golf','DF',"", "group");
                        $form->setBloc('am_caravane','DF',"", "group");
                        $form->setBloc('am_carav_duree','DF',"", "group");
                        $form->setBloc('am_statio','DF',"", "group");
                        $form->setBloc('am_statio_cont','DF',"", "group");
                        $form->setBloc('am_affou_exhau','DF',"", "group");
                        $form->setBloc('am_affou_exhau_sup','DF',"", "group");
                        $form->setBloc('am_affou_prof','DF',"", "group");
                        $form->setBloc('am_exhau_haut','DF',"", "group");
                        
                        $form->setBloc('am_chem_ouv_esp','D',_("Dans les secteurs proteges :"),"col_12");
                            $form->setBloc('am_chem_ouv_esp','DF',_("Amenagement situe dans un espace remarquable :"), "group");
                            $form->setBloc('am_agri_peche','DF',"", "group");
                            
                            $form->setBloc('am_crea_voie','DF',_("Amenagement situe dans un secteur sauvegarde :"), "group");
                            $form->setBloc('am_modif_voie_exist','DF',"", "group");
                            $form->setBloc('am_crea_esp_sauv','DF',"", "group");
                            
                            $form->setBloc('am_crea_esp_class','DF',_("Amenagement situe dans un site classe ou une reserve naturelle 1 :"), "group");
                            $form->setBloc('am_coupe_abat','DF',"", "group");
                            $form->setBloc('am_prot_plu','DF',"", "group");
                            $form->setBloc('am_prot_muni','DF',"", "group");
                            $form->setBloc('am_mobil_voyage','DF',"", "group");
                            $form->setBloc('am_aire_voyage','DF',"", "group");
                            $form->setBloc('am_rememb_afu','DF',"", "group");
                            $form->setBloc('co_ouvr_infra','DF',"", "group");
                        $form->setBloc('co_ouvr_infra','F');

                        $form->setBloc('am_mob_art','DF',_("Dans un secteur sauvegarde, site classe ou reserve naturelle :"), "group");
                        $form->setBloc('am_modif_voie_esp','DF',"", "group");
                        $form->setBloc('am_plant_voie_esp','DF',"", "group");
                        $form->setBloc('co_ouvr_elec','DF',"", "group");
                    $form->setFieldset('co_ouvr_elec','F','');
                $form->setBloc('co_ouvr_elec','F');
                $form->setBloc('am_projet_desc','D',"","col_12");
                    $form->setFieldset('am_projet_desc','D'
                                       ,_("Description amenagement"), "startClosed");

                        $form->setBloc('am_projet_desc','DF',"", "group");
                        $form->setBloc('am_terr_surf','DF',"", "alignFormSpec");
                        $form->setBloc('am_tranche_desc','DF',"", "group");
                    $form->setFieldset('am_tranche_desc','F','');
                $form->setBloc('am_tranche_desc','F');
                $form->setBloc('am_lot_max_nb','D',"","col_12");
                    $form->setFieldset('am_lot_max_nb','D'
                                       ,_("Complement d'amenagement"), "startClosed");
                        // bloc 4.2
                        $form->setBloc('am_lot_max_nb','D',_("Demande concernant un lotissement"),"col_12 alignFormSpec");
                        
                            $form->setBloc('am_lot_max_nb','DF',"", "group");
                            $form->setBloc('am_lot_max_shon','DF',"", "group");
                        
                            $form->setBloc('am_lot_cstr_cos','DF',_("Comment la constructibilite globale sera-t-elle repartie ?"), "group");
                            $form->setBloc('am_lot_cstr_plan','DF',"", "group");
                            $form->setBloc('am_lot_cstr_vente','DF',"", "group");
                            $form->setBloc('am_lot_fin_diff','DF',"", "group");
                            
                            $form->setBloc('am_lot_consign','DF',_("si oui, quelle garantie sera utilisee ?"), "group");
                            $form->setBloc('am_lot_gar_achev','DF',"", "group");
                            $form->setBloc('am_lot_vente_ant','DF',"", "group");
                        $form->setBloc('am_lot_vente_ant','F');

                        // bloc 4.3
                        $form->setBloc('am_exist_agrand','D',_("Amenagement d'un camping ou
                                       d'un terrain amenage en vue de l'hebergement
                                       touristique"),"col_12");
                                       
                            $form->setBloc('am_exist_agrand','DF',"", "alignFormSpec");
                                $form->setBloc('am_exist_date','DF',"", "alignFormSpec-type-date");
                                $form->setBloc('am_exist_num','D',"", "alignFormSpec");
                            $form->setBloc('am_empl_nb','F',"", "");
                            
                            $form->setBloc('am_tente_nb','D',_("Nombre maximum d’emplacements reserves aux :"), "col_12 alignForm");
                            $form->setBloc('am_mobil_nb','F',"", "");
                            
                            $form->setBloc('am_pers_nb','DF',"", "alignFormSpec group");
                            
                            $form->setBloc('am_empl_hll_nb','D',_("Implantation d’habitations legeres de loisirs (HLL) :"), "col_12 alignFormSpec");
                            //$form->setBloc('am_empl_hll_nb','DF',"", "group");
                            $form->setBloc('am_hll_shon','F');
                                
                            $form->setBloc('am_periode_exploit','DF',"", "group");
                            
                            $form->setBloc('am_coupe_bois','D',_("Declaration de coupe et/ou abattage d’arbres :"),"col_12 cerfasubtitle");
                                
                                $form->setBloc('am_coupe_bois','D',_("Courte description du lieu :"), "cerfasubtitle alignForm");
                                $form->setBloc('am_coupe_align','F',"", "");
                                
                                $form->setBloc('am_coupe_ess','D',_("Nature du boisement :"),"col_12 cerfasubtitle alignForm");
                                $form->setBloc('am_coupe_autr','F');
                            $form->setBloc('am_coupe_autr','F');
                            
                        $form->setBloc('am_coupe_autr','F');


                    $form->setFieldset('am_coupe_autr','F','');
                
                $form->setBloc('am_coupe_autr','F');
            $form->setFieldset('am_coupe_autr','F','');
        $form->setBloc('am_coupe_autr','F');
        // Fin amménager
        // Construire
        $form->setBloc('co_archi_recours','D',"","col_12");
            $form->setFieldset('co_archi_recours','D'
                               ,_("Construire"), "startClosed");
                $form->setBloc('co_archi_recours','D', "","col_12");
                    $form->setFieldset('co_archi_recours','D'
                               ,_("Projet construction"), "startClosed");
                
                        $form->setBloc('co_archi_recours','D',_("Architecte"), "col_12");
                            $form->setBloc('co_archi_recours','DF',"", "alignFormSpec group");
                            $form->setBloc('architecte','DF', "", "group");
                        $form->setBloc('architecte','F');
                        
                        $form->setBloc('co_cstr_nouv','D',_("Nature du projet"), "col_12 alignFormSpec");
                        $form->setBloc('avap_co_elt_pro','DF',"", "group");
                        $form->setBloc('avap_nouv_haut_surf','DF',"", "group");
                        $form->setBloc('co_cloture','F');
                        $form->setBloc('co_projet_desc','DF',"", "group");
                        $form->setBloc('co_elec_tension','DF', "", "alignFormSpec");
                    $form->setFieldset('co_elec_tension','F','');
                    $form->setFieldset('co_tot_log_nb','D'
                               ,_("Complement construction"), "startClosed");

                        $form->setBloc('co_tot_log_nb','D',"", "alignForm");
                        $form->setBloc('co_tot_coll_nb','F',"", "");
                        
                        $form->setBloc('co_mais_piece_nb','D',"", "alignForm");
                        $form->setBloc('co_mais_niv_nb','F',"", "");
                        
                        $form->setBloc('co_fin_lls_nb','D', _("Repartition du nombre total de logement crees par type de financement :"),"col_12");
                            $form->setBloc('co_fin_lls_nb','D',"", "alignForm");
                            $form->setBloc('co_fin_autr_nb','F',"", "");
                            
                            $form->setBloc('co_fin_autr_desc','DF',"", "alignFormSpec group");
                            $form->setBloc('co_mais_contrat_ind','DF',"", "alignFormSpec group");
                        $form->setBloc('co_mais_contrat_ind','F');
                        
                        $form->setBloc('co_uti_pers','D',_("Mode d'utilisation principale des logements :"), "col_12");
                            $form->setBloc('co_uti_pers','D', "", "alignForm");
                            $form->setBloc('co_uti_loc','F',"", "");
                        $form->setBloc('co_uti_loc','F',"", "");
                        
                        $form->setBloc('co_uti_princ','D',_("S’il s’agit d’une occupation personnelle, veuillez preciser :"), "col_12");
                            $form->setBloc('co_uti_princ','D',"", "alignForm");
                            $form->setBloc('co_uti_secon','F',"", "");
                        $form->setBloc('co_uti_secon','F',"", "group");

                        $form->setBloc('co_anx_pisc','D',_("Si le projet porte sur une annexe a l’habitation, veuillez preciser :"), "col_12");
                            $form->setBloc('co_anx_pisc','D',"", "alignForm");
                            $form->setBloc('co_anx_autr_desc','F',"", "");
                        $form->setBloc('co_anx_autr_desc','F',"", "group");
                        
                        $form->setBloc('co_resid_agees','D',_("Si le projet est un foyer ou une residence, a quel titre :"), "col_12 alignForm");
                            $form->setBloc('co_resid_agees','D',"", "alignForm");
                            $form->setBloc('co_resid_hand','F',"", "");
                        $form->setBloc('co_resid_hand','F',"", "group");
                        
                        $form->setBloc('co_resid_autr','DF',"", "group alignFormSpec");
                        $form->setBloc('co_resid_autr_desc','DF',"", "group");
                        $form->setBloc('co_foyer_chamb_nb','DF',"", "group alignFormSpec");
                        
                        $form->setBloc('co_log_1p_nb','D',_("Repartition du nombre de logements crees selon le nombre de pieces :"), "col_12");
                            $form->setBloc('co_log_1p_nb','D', "", "alignForm");
                            $form->setBloc('co_log_6p_nb','F',"", "group");
                        $form->setBloc('co_log_6p_nb','F',"", "group");
                        
                        $form->setBloc('co_bat_niv_nb','DF',"", "alignFormSpec");
                        
                        $form->setBloc('co_trx_exten','D',_("Indiquez si vos travaux comprennent notamment :"), "col_12");
                            $form->setBloc('co_trx_exten','D',"", "alignForm");
                            $form->setBloc('co_trx_nivsup','F',"", "group");

                            $form->setBloc('co_demont_periode','DF', _("Construction periodiquement demontee et re-installee :"),"col_12 group");
                        $form->setBloc('co_demont_periode','F',"", "group");

                    $form->setFieldset('co_demont_periode','F','');
                    $form->setFieldset('tab_surface','D'
                               ,_("Destinations et surfaces des constructions"), "startClosed");
                        $form->setBloc('tab_surface','D', "","col_12 group");
                        $form->setBloc('tab_surface','F');
                        $form->setBloc('co_sp_transport','D', _("Destination des constructions futures en cas de realisation au benefice d'un service public ou d'interet collectif :"),"col_12");
                            $form->setBloc('co_sp_transport','D', "","alignForm");
                            $form->setBloc('co_sp_culture','F', "","");
                        $form->setBloc('co_sp_culture','F', "","");
                
                    $form->setFieldset('co_sp_culture','F','');
                    $form->setFieldset('co_statio_avt_nb','D'
                               ,_("Divers construction"), "startClosed");

                        $form->setBloc('co_statio_avt_nb','D', _("Nombre de places de stationnement"),"col_12");
                            $form->setBloc('co_statio_avt_nb','D', "","alignForm");
                            $form->setBloc('co_statio_apr_nb','F', "","");
                        $form->setBloc('co_statio_apr_nb','F', "","");
                        
                        $form->setBloc('co_statio_adr','D', _("Places de stationnement affectees au projet, amenagees ou reservees en dehors du terrain sur lequel est situe le projet"),"col_12");
                            $form->setBloc('co_statio_adr','DF', "","group");
                            
                            $form->setBloc('co_statio_place_nb','D', "","col_12");
                                $form->setBloc('co_statio_place_nb','D', "","alignForm");
                                $form->setBloc('co_statio_tot_shob','F', "","");
                            $form->setBloc('co_statio_tot_shob','F', "","");
                        $form->setBloc('co_statio_tot_shob','F');
                        $form->setBloc('co_statio_comm_cin_surf','D', _("Pour les commerces et cinemas :"),"col_12 alignFormSpec");
                        $form->setBloc('co_perf_energ','F',"", "");
                
                    $form->setFieldset('co_perf_energ','F','');
                $form->setBloc('co_perf_energ','F');

            $form->setFieldset('co_perf_energ','F','');
        
        $form->setBloc('co_perf_energ','F');
        // Fin construire

        /*Fieldset n°6 Projet necessitant demolitions */
        $form->setBloc('dm_constr_dates','D',"","col_12");
            $form->setFieldset('dm_constr_dates','D'
                               ,_("Demolir"), "startClosed");
                $form->setBloc('dm_constr_dates','DF', "","group");
                $form->setBloc('dm_total','D', "","alignFormSpec");
                $form->setBloc('dm_partiel','F');
                $form->setBloc('dm_projet_desc','DF', "","group");
                $form->setBloc('dm_tot_log_nb','DF', "","alignFormSpec");
            $form->setFieldset('dm_tot_log_nb','F','');
        
        $form->setBloc('dm_tot_log_nb','F');

        /*Fieldset n°4 Ouverture de chantier */
        $form->setBloc('doc_date','D',"","col_12");
            $form->setFieldset('doc_date','D'
                               ,_("Ouverture de chantier"), "startClosed alignFormSpec");
                $form->setBloc('doc_date','DF', "","group");
                $form->setBloc('doc_tot_trav','DF', "","group");
                $form->setBloc('doc_tranche_trav','DF', "","group");
                $form->setBloc('doc_tranche_trav_desc','DF', "","group");
                $form->setBloc('doc_surf','DF', "","group");
                $form->setBloc('doc_nb_log','DF', "","group");
                $form->setBloc('doc_nb_log_indiv','DF', "","group");
                $form->setBloc('doc_nb_log_coll','DF', "","group");
                //
                $form->setBloc('doc_nb_log_lls','DF', _("Repartition du nombre de logements commences par type de financement"), "group");
                $form->setBloc('doc_nb_log_aa','DF', "","group");
                $form->setBloc('doc_nb_log_ptz','DF', "","group");
                $form->setBloc('doc_nb_log_autre','DF', "","group");
            $form->setFieldset('doc_nb_log_autre','F','');
        $form->setBloc('doc_nb_log_autre','F');

        /*Fieldset n°4  Achèvement des travaux */
        $form->setBloc('daact_date','D',"","col_12");
            $form->setFieldset('daact_date','D'
                               ,_("Achevement des travaux") , "startClosed alignFormSpec");
                $form->setBloc('daact_date','DF', "","group");
                $form->setBloc('daact_date_chgmt_dest','DF', "","group");
                $form->setBloc('daact_tot_trav','DF', "","group");
                $form->setBloc('daact_tranche_trav','DF', "","group");
                $form->setBloc('daact_tranche_trav_desc','DF', "","group");
                $form->setBloc('daact_surf','DF', "","group");
                $form->setBloc('daact_nb_log','DF', "","group");
                $form->setBloc('daact_nb_log_indiv','DF', "","group");
                $form->setBloc('daact_nb_log_coll','DF', "","group");
                //
                $form->setBloc('daact_nb_log_lls','DF', _("Repartition du nombre de logements commences par type de financement"), "group");
                $form->setBloc('daact_nb_log_aa','DF', "","group");
                $form->setBloc('daact_nb_log_ptz','DF', "","group");
                $form->setBloc('daact_nb_log_autre','DF', "","group");
            $form->setFieldset('daact_nb_log_autre','F','');
        $form->setBloc('daact_nb_log_autre','F');

        $form->setBloc('code_cnil','D',"","col_12");
            $form->setFieldset('code_cnil','D'
                               ,_("cnil (opposition à l’utilisation des informations du formulaire à des fins commerciales)") , "startClosed alignFormSpec");
                $form->setBloc('code_cnil','DF', "","group");
            $form->setFieldset('code_cnil','F','');
        $form->setBloc('code_cnil','F');

        $form->setBloc('tax_surf_tot_cstr','D',"","col_12");
            $form->setFieldset('tax_surf_tot_cstr','D'
                               ,_("Declaration des elements necessaires au calcul des impositions"), "startClosed");

                $form->setBloc('tax_surf_tot_cstr','D', _("Renseignement"),"col_12");
                    $form->setBloc('tax_surf_tot_cstr','D', "", "alignFormSpec");
                    $form->setBloc('tax_surf_suppr_mod','F', "","");
                $form->setBloc('tax_surf_suppr_mod','F', "","");

                $form->setBloc('tab_tax_su_princ','D',_("Creation de locaux destines a l’habitation :"),"col_12");
                    $form->setBloc('tab_tax_su_princ','DF',_("tab_tax_su_princ"), "col_12");
                    $form->setBloc('tab_tax_su_heber','DF',_("tab_tax_su_heber"), "col_12");
                $form->setBloc('tab_tax_su_tot','F', "","");
                //
                $form->setBloc('tax_ext_pret','DF', _("Extension de l’habitation principale, creation d’un batiment annexe a cette habitation ou d’un garage clos et couvert. "), "alignFormSpec");
                $form->setBloc('tax_ext_desc','DF', "","group");
                $form->setBloc('tax_surf_tax_exist_cons','D', "","alignFormSpec");
                $form->setBloc('tax_log_ap_trvx_nb','F');

                $form->setBloc('tax_comm_nb','D', _("Creation ou extension de locaux non destines a l'habitation :"),"col_12");
                    $form->setBloc('tax_comm_nb','DF', "","col_12 alignFormSpec");
                    $form->setBloc('tab_tax_su_parc_statio_expl_comm','DF');
                $form->setBloc('tab_tax_su_parc_statio_expl_comm','F');
                //
                $form->setBloc('tab_tax_am','DF',_("tab_tax_am"),"col_12");

                $form->setBloc('tax_am_statio_ext_cr','D', _("Autres elements crees soumis à la taxe d’amenagement :"),"col_12");
                $form->setBloc('tax_pann_volt_sup_cr','F');

                $form->setBloc('tax_surf_loc_arch','D', _("Redevance d’archeologie preventive"),"col_12 alignFormSpec");
                $form->setBloc('tax_eol_haut_nb_arch','F');

                $form->setBloc('tax_trx_presc_ppr','D', _("Cas particuliers"),"col_12 alignFormSpec");
                $form->setBloc('tax_monu_hist','F');

                $form->setBloc('vsd_surf_planch_smd','D', _("Versement pour sous-densite (VSD)"),"col_12");
                    $form->setBloc('vsd_surf_planch_smd','D', "","alignFormSpec");
                    $form->setBloc('vsd_const_sxist_non_dem_surf','F');
                    
                    $form->setBloc('vsd_rescr_fisc','DF',"", "alignFormSpec-type-date");
                $form->setBloc('vsd_rescr_fisc','F');
                
                $form->setBloc('pld_val_terr','D', _("Plafond legal de densite (PLD)"),"col_12 alignFormSpec");
                $form->setBloc('pld_const_exist_dem_surf','F');

                $form->setBloc('tax_desc','DF', _("Autres renseignements"),"col_12 alignFormSpec");

            $form->setFieldset('tax_desc','F','');
        
        $form->setBloc('tax_desc','F');
    }

    /**
     * Surcharge de la méthode setOnChange
     */
    function setOnchange(&$form,$maj){
        parent::setOnchange($form,$maj);

        $form->setOnchange("co_tot_ind_nb","sommeChampsCerfa('co_tot_log_nb',['co_tot_ind_nb','co_tot_coll_nb']);");
        $form->setOnchange("co_tot_coll_nb","sommeChampsCerfa('co_tot_log_nb',['co_tot_ind_nb','co_tot_coll_nb']);");

        $form->setOnchange("doc_nb_log_indiv","sommeChampsCerfa('doc_nb_log',['doc_nb_log_indiv','doc_nb_log_coll']);");
        $form->setOnchange("doc_nb_log_coll","sommeChampsCerfa('doc_nb_log',['doc_nb_log_indiv','doc_nb_log_coll']);");
        
        $form->setOnchange("su_avt_shon1","calculSurfaceTotal();");
        $form->setOnchange("su_avt_shon2","calculSurfaceTotal();");
        $form->setOnchange("su_avt_shon3","calculSurfaceTotal();");
        $form->setOnchange("su_avt_shon4","calculSurfaceTotal();");
        $form->setOnchange("su_avt_shon5","calculSurfaceTotal();");
        $form->setOnchange("su_avt_shon6","calculSurfaceTotal();");
        $form->setOnchange("su_avt_shon7","calculSurfaceTotal();");
        $form->setOnchange("su_avt_shon8","calculSurfaceTotal();");
        $form->setOnchange("su_avt_shon9","calculSurfaceTotal();");
        $form->setOnchange("su_cstr_shon1","calculSurfaceTotal();");
        $form->setOnchange("su_cstr_shon2","calculSurfaceTotal();");
        $form->setOnchange("su_cstr_shon3","calculSurfaceTotal();");
        $form->setOnchange("su_cstr_shon4","calculSurfaceTotal();");
        $form->setOnchange("su_cstr_shon5","calculSurfaceTotal();");
        $form->setOnchange("su_cstr_shon6","calculSurfaceTotal();");
        $form->setOnchange("su_cstr_shon7","calculSurfaceTotal();");
        $form->setOnchange("su_cstr_shon8","calculSurfaceTotal();");
        $form->setOnchange("su_cstr_shon9","calculSurfaceTotal();");
        $form->setOnchange("su_chge_shon1","calculSurfaceTotal();");
        $form->setOnchange("su_chge_shon2","calculSurfaceTotal();");
        $form->setOnchange("su_chge_shon3","calculSurfaceTotal();");
        $form->setOnchange("su_chge_shon4","calculSurfaceTotal();");
        $form->setOnchange("su_chge_shon5","calculSurfaceTotal();");
        $form->setOnchange("su_chge_shon6","calculSurfaceTotal();");
        $form->setOnchange("su_chge_shon7","calculSurfaceTotal();");
        $form->setOnchange("su_chge_shon8","calculSurfaceTotal();");
        $form->setOnchange("su_chge_shon9","calculSurfaceTotal();");
        $form->setOnchange("su_demo_shon1","calculSurfaceTotal();");
        $form->setOnchange("su_demo_shon2","calculSurfaceTotal();");
        $form->setOnchange("su_demo_shon3","calculSurfaceTotal();");
        $form->setOnchange("su_demo_shon4","calculSurfaceTotal();");
        $form->setOnchange("su_demo_shon5","calculSurfaceTotal();");
        $form->setOnchange("su_demo_shon6","calculSurfaceTotal();");
        $form->setOnchange("su_demo_shon7","calculSurfaceTotal();");
        $form->setOnchange("su_demo_shon8","calculSurfaceTotal();");
        $form->setOnchange("su_demo_shon9","calculSurfaceTotal();");
        $form->setOnchange("su_sup_shon1","calculSurfaceTotal();");
        $form->setOnchange("su_sup_shon2","calculSurfaceTotal();");
        $form->setOnchange("su_sup_shon3","calculSurfaceTotal();");
        $form->setOnchange("su_sup_shon4","calculSurfaceTotal();");
        $form->setOnchange("su_sup_shon5","calculSurfaceTotal();");
        $form->setOnchange("su_sup_shon6","calculSurfaceTotal();");
        $form->setOnchange("su_sup_shon7","calculSurfaceTotal();");
        $form->setOnchange("su_sup_shon8","calculSurfaceTotal();");
        $form->setOnchange("su_sup_shon9","calculSurfaceTotal();");
        $form->setOnchange("su_tot_shon1","calculSurfaceTotal();");
        $form->setOnchange("su_tot_shon2","calculSurfaceTotal();");
        $form->setOnchange("su_tot_shon3","calculSurfaceTotal();");
        $form->setOnchange("su_tot_shon4","calculSurfaceTotal();");
        $form->setOnchange("su_tot_shon5","calculSurfaceTotal();");
        $form->setOnchange("su_tot_shon6","calculSurfaceTotal();");
        $form->setOnchange("su_tot_shon7","calculSurfaceTotal();");
        $form->setOnchange("su_tot_shon8","calculSurfaceTotal();");
        $form->setOnchange("su_tot_shon9","calculSurfaceTotal();");

    }

    
    /**
     * Surcharge du bouton retour afin de retourner sur le dossier d'instruction selon de cas
     */
    function retoursousformulaire($idxformulaire, $retourformulaire, $val,
                                  $objsf, $premiersf, $tricolsf, $validation,
                                  $idx, $maj, $retour) {

        $visualisation = $this->getParameter('visualisation');
        
        if ( $visualisation == "" ){
            
            // Ajout et consultation, retour dossier
            if ( ( $maj == 0 && $validation == 0 ) || 
                ( $maj == 3 && $validation == 0 ) ||
                ( $maj == 0 && $validation == 1 )  && $retourformulaire == "dossier_instruction" ){
             
                echo "\n<a class=\"retour\" ";
                    echo "href=\"#\" ";
                    echo "onclick=\"redirectPortletAction(1,'main');\" ";
                    echo ">";
                    echo _("Retour");
                echo "</a>\n";
            }
            //Sinon affiche un retour normal
            else{
                
                parent::retoursousformulaire($idxformulaire, $retourformulaire, $val,
                                      $objsf, $premiersf, $tricolsf, $validation,
                                      $idx, $maj, $retour);
            }
        }
    }

    /**
     * Cette variable permet de stocker le résultat de la méthode
     * getDivisionFromDossier() afin de ne pas effectuer le recalcul à chacun de
     * ces appels.
     * @var string Code de la division du dossier en cours
     */
    var $_division_from_dossier = NULL;

    /**
     * Cette méthode permet de récupérer le code de division correspondant
     * au dossier sur lequel on se trouve.
     *
     * @return string Code de la division du dossier en cours
     */
    function getDivisionFromDossier() {

        // Cette méthode peut être appelée plusieurs fois lors d'une requête.
        // Pour éviter de refaire le traitement de recherche de la division
        // alors on vérifie si nous ne l'avons pas déjà calculé.
        if ($this->_division_from_dossier != NULL) {
            // Logger
            $this->addToLog("getDivisionFromDossier(): retour de la valeur déjà calculée - '".$this->_division_from_dossier."'", EXTRA_VERBOSE_MODE);
            // On retourne la valeur déjà calculée
            return $this->_division_from_dossier;
        }

        // Par défaut, on définit la valeur du dossier à NULL
        $dossier = NULL;
        // Test sur le mode et le contexte du formulaire
        if ($this->getParameter("maj") == 0
            && ($this->getParameter("retourformulaire") == "dossier"
                || $this->getParameter("retourformulaire") == "dossier_instruction"
                || $this->getParameter("retourformulaire") == "dossier_instruction_mes_encours"
                || $this->getParameter("retourformulaire") == "dossier_instruction_tous_encours"
                || $this->getParameter("retourformulaire") == "dossier_instruction_mes_clotures"
                || $this->getParameter("retourformulaire") == "dossier_instruction_tous_clotures")) {
            // Si on se trouve en mode AJOUT (seul mode où l'enregistrement
            // n'existe pas en base de données) ET que nous nous trouvons
            // dans le contexte d'un dossier d'instruction alors on récupère
            // le numéro de dossier depuis le paramètre 'idxformulaire'
            $dossier = $this->getParameter("idxformulaire");
        } else {
            // Sinon on récupère le numéro de dossier dans le champs dossier de
            // l'enregistrement (en base de données)
            $dossier = $this->getVal("dossier_instruction");
        }

        // On appelle la méthode de la classe utils qui renvoi le code de la
        // division d'un dossier, on la stocke pour ne pas refaire le calcul au
        // prochain appel de cette méthode
        $this->_division_from_dossier = $this->f->getDivisionFromDossier($dossier);
        // Logger
        $this->addToLog("getDivisionFromDossier(): retour de la valeur nouvellement calculée - '".$this->_division_from_dossier."'", EXTRA_VERBOSE_MODE);
        // On retourne la valeur retournée
        return $this->_division_from_dossier;

    }
    
    /**
     * Retourne le nom et le prénom de l'architecte qui a l'identifiant $id
     * @param integer $id
     * @param object $db
     * @return string
     */
    function getPrenomNomArchitecte($id){
        
        $coordonneesArchitecte = "";
        if ( $id != '' && is_numeric($id) ){
            
            $sql = "SELECT 
                CONCAT(architecte.prenom, ' ', architecte.nom)
            FROM
                ".DB_PREFIXE."architecte
            WHERE 
                architecte.architecte = ".$id;
            $coordonneesArchitecte = $this->db->getOne($sql);
            $this->f->addToLog("setSelect() : db->getOne(\"".$sql."\")", VERBOSE_MODE);
            if ( database::isError($coordonneesArchitecte)){
                $this->f->addToError("", $coordonneesArchitecte, $coordonneesArchitecte);
                return false;
            }
        }
        return $coordonneesArchitecte;
    }

}// fin classe
?>
