<?php
//$Id: parcelle.class.php 5616 2015-12-15 10:53:32Z nmeucci $ 
//gen openMairie le 15/12/2015 11:49

require_once "../obj/om_dbform.class.php";

class parcelle_gen extends om_dbform {

    var $table = "parcelle";
    var $clePrimaire = "parcelle";
    var $typeCle = "A";
    var $required_field = array(
        "parcelle"
    );
    
    var $foreign_keys_extended = array(
        "pos" => array("pos", ),
        "proprietaire" => array("proprietaire", ),
        "rivoli" => array("rivoli", ),
    );



    function setvalF($val) {
        //affectation valeur formulaire
        $this->valF['parcelle'] = $val['parcelle'];
        if ($val['debut'] == "") {
            $this->valF['debut'] = ""; // -> default
        } else {
            $this->valF['debut'] = $val['debut'];
        }
        if ($val['rivoli'] == "") {
            $this->valF['rivoli'] = NULL;
        } else {
            $this->valF['rivoli'] = $val['rivoli'];
        }
        if ($val['proprietaire'] == "") {
            $this->valF['proprietaire'] = NULL;
        } else {
            $this->valF['proprietaire'] = $val['proprietaire'];
        }
        if ($val['pos'] == "") {
            $this->valF['pos'] = NULL;
        } else {
            $this->valF['pos'] = $val['pos'];
        }
        if (!is_numeric($val['surface'])) {
            $this->valF['surface'] = NULL;
        } else {
            $this->valF['surface'] = $val['surface'];
        }
        if ($val['section'] == "") {
            $this->valF['section'] = NULL;
        } else {
            $this->valF['section'] = $val['section'];
        }
        if ($val['commune'] == "") {
            $this->valF['commune'] = NULL;
        } else {
            $this->valF['commune'] = $val['commune'];
        }
        if ($val['geom'] == "") {
            unset($this->valF['geom']);
        } else {
            $this->valF['geom'] = $val['geom'];
        }
    }

    //==========================
    // Formulaire  [form]
    //==========================
    /**
     *
     */
    function setType(&$form, $maj) {
        // Récupération du mode de l'action
        $crud = $this->get_action_crud($maj);

        // MODE AJOUTER
        if ($maj == 0 || $crud == 'create') {
            $form->setType("parcelle", "text");
            $form->setType("debut", "text");
            if ($this->is_in_context_of_foreign_key("rivoli", $this->retourformulaire)) {
                $form->setType("rivoli", "selecthiddenstatic");
            } else {
                $form->setType("rivoli", "select");
            }
            if ($this->is_in_context_of_foreign_key("proprietaire", $this->retourformulaire)) {
                $form->setType("proprietaire", "selecthiddenstatic");
            } else {
                $form->setType("proprietaire", "select");
            }
            if ($this->is_in_context_of_foreign_key("pos", $this->retourformulaire)) {
                $form->setType("pos", "selecthiddenstatic");
            } else {
                $form->setType("pos", "select");
            }
            $form->setType("surface", "text");
            $form->setType("section", "text");
            $form->setType("commune", "text");
            $form->setType("geom", "geom");
        }

        // MDOE MODIFIER
        if ($maj == 1 || $crud == 'update') {
            $form->setType("parcelle", "hiddenstatic");
            $form->setType("debut", "text");
            if ($this->is_in_context_of_foreign_key("rivoli", $this->retourformulaire)) {
                $form->setType("rivoli", "selecthiddenstatic");
            } else {
                $form->setType("rivoli", "select");
            }
            if ($this->is_in_context_of_foreign_key("proprietaire", $this->retourformulaire)) {
                $form->setType("proprietaire", "selecthiddenstatic");
            } else {
                $form->setType("proprietaire", "select");
            }
            if ($this->is_in_context_of_foreign_key("pos", $this->retourformulaire)) {
                $form->setType("pos", "selecthiddenstatic");
            } else {
                $form->setType("pos", "select");
            }
            $form->setType("surface", "text");
            $form->setType("section", "text");
            $form->setType("commune", "text");
            $form->setType("geom", "geom");
        }

        // MODE SUPPRIMER
        if ($maj == 2 || $crud == 'delete') {
            $form->setType("parcelle", "hiddenstatic");
            $form->setType("debut", "hiddenstatic");
            $form->setType("rivoli", "selectstatic");
            $form->setType("proprietaire", "selectstatic");
            $form->setType("pos", "selectstatic");
            $form->setType("surface", "hiddenstatic");
            $form->setType("section", "hiddenstatic");
            $form->setType("commune", "hiddenstatic");
            $form->setType("geom", "geom");
        }

        // MODE CONSULTER
        if ($maj == 3 || $crud == 'read') {
            $form->setType("parcelle", "static");
            $form->setType("debut", "static");
            $form->setType("rivoli", "selectstatic");
            $form->setType("proprietaire", "selectstatic");
            $form->setType("pos", "selectstatic");
            $form->setType("surface", "static");
            $form->setType("section", "static");
            $form->setType("commune", "static");
            $form->setType("geom", "geom");
        }

    }


    function setOnchange(&$form, $maj) {
    //javascript controle client
        $form->setOnchange('surface','VerifFloat(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("parcelle", 20);
        $form->setTaille("debut", 10);
        $form->setTaille("rivoli", 10);
        $form->setTaille("proprietaire", 10);
        $form->setTaille("pos", 10);
        $form->setTaille("surface", 20);
        $form->setTaille("section", 10);
        $form->setTaille("commune", 10);
        $form->setTaille("geom", 30);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("parcelle", 20);
        $form->setMax("debut", 4);
        $form->setMax("rivoli", 4);
        $form->setMax("proprietaire", 6);
        $form->setMax("pos", 6);
        $form->setMax("surface", 20);
        $form->setMax("section", 7);
        $form->setMax("commune", 5);
        $form->setMax("geom", 551432);
    }


    function setLib(&$form, $maj) {
    //libelle des champs
        $form->setLib('parcelle',_('parcelle'));
        $form->setLib('debut',_('debut'));
        $form->setLib('rivoli',_('rivoli'));
        $form->setLib('proprietaire',_('proprietaire'));
        $form->setLib('pos',_('pos'));
        $form->setLib('surface',_('surface'));
        $form->setLib('section',_('section'));
        $form->setLib('commune',_('commune'));
        $form->setLib('geom',_('geom'));
    }
    /**
     *
     */
    function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) {

        // Inclusion du fichier de requêtes
        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";
        }

        // pos
        $this->init_select($form, $this->f->db, $maj, null, "pos", $sql_pos, $sql_pos_by_id, false);
        // proprietaire
        $this->init_select($form, $this->f->db, $maj, null, "proprietaire", $sql_proprietaire, $sql_proprietaire_by_id, false);
        // rivoli
        $this->init_select($form, $this->f->db, $maj, null, "rivoli", $sql_rivoli, $sql_rivoli_by_id, false);
        // geom
        if ($maj == 1 || $maj == 3) {
            $contenu = array();
            $contenu[0] = array("parcelle", $this->getParameter("idx"), "0");
            $form->setSelect("geom", $contenu);
        }
    }


    //==================================
    // sous Formulaire 
    //==================================
    

    function setValsousformulaire(&$form, $maj, $validation, $idxformulaire, $retourformulaire, $typeformulaire, &$dnu1 = null, $dnu2 = null) {
        $this->retourformulaire = $retourformulaire;
        if($validation == 0) {
            if($this->is_in_context_of_foreign_key('pos', $this->retourformulaire))
                $form->setVal('pos', $idxformulaire);
            if($this->is_in_context_of_foreign_key('proprietaire', $this->retourformulaire))
                $form->setVal('proprietaire', $idxformulaire);
            if($this->is_in_context_of_foreign_key('rivoli', $this->retourformulaire))
                $form->setVal('rivoli', $idxformulaire);
        }// fin validation
        $this->set_form_default_values($form, $maj, $validation);
    }// fin setValsousformulaire

    //==================================
    // cle secondaire 
    //==================================
    
    /**
     * Methode clesecondaire
     */
    function cleSecondaire($id, &$dnu1 = null, $val = array(), $dnu2 = null) {
        // On appelle la methode de la classe parent
        parent::cleSecondaire($id);
        // Verification de la cle secondaire : dossier
        $this->rechercheTable($this->f->db, "dossier", "parcelle", $id);
        // Verification de la cle secondaire : dossier_autorisation_parcelle
        $this->rechercheTable($this->f->db, "dossier_autorisation_parcelle", "parcelle", $id);
        // Verification de la cle secondaire : dossier_parcelle
        $this->rechercheTable($this->f->db, "dossier_parcelle", "parcelle", $id);
    }


}

?>
