<?php
//$Id$ 
//gen openMairie le 10/04/2015 16:50

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

class fils_gen extends om_dbform {

    var $table = "fils";
    var $clePrimaire = "fils";
    var $typeCle = "N";
    var $required_field = array(
        "fils",
        "libelle",
        "pere"
    );
    
    var $foreign_keys_extended = array(
        "nomenclature_fils" => array("nomenclature_fils", ),
        "pere" => array("pere", ),
    );



    function setvalF($val) {
        //affectation valeur formulaire
        if (!is_numeric($val['fils'])) {
            $this->valF['fils'] = ""; // -> requis
        } else {
            $this->valF['fils'] = $val['fils'];
        }
        $this->valF['libelle'] = $val['libelle'];
        if (!is_numeric($val['pere'])) {
            $this->valF['pere'] = ""; // -> requis
        } else {
            $this->valF['pere'] = $val['pere'];
        }
        if ($val['nomenclature_fils'] == "") {
            $this->valF['nomenclature_fils'] = NULL;
        } else {
            $this->valF['nomenclature_fils'] = $val['nomenclature_fils'];
        }
        if ($val['point_geom'] == "") {
            unset($this->valF['point_geom']);
        } else {
            $this->valF['point_geom'] = $val['point_geom'];
        }
        if ($val['perim_geom'] == "") {
            unset($this->valF['perim_geom']);
        } else {
            $this->valF['perim_geom'] = $val['perim_geom'];
        }
        if ($val['ligne_geom'] == "") {
            unset($this->valF['ligne_geom']);
        } else {
            $this->valF['ligne_geom'] = $val['ligne_geom'];
        }
    }

    //=================================================
    //cle primaire automatique [automatic primary key]
    //==================================================

    function setId(&$dnu1 = null) {
    //numero automatique
        $this->valF[$this->clePrimaire] = $this->f->db->nextId(DB_PREFIXE.$this->table);
    }

    function setValFAjout($val) {
    //numero automatique -> pas de controle ajout cle primaire
    }

    function verifierAjout() {
    //numero automatique -> pas de verfication de cle primaire
    }

    //==========================
    // Formulaire  [form]
    //==========================
    /**
     *
     */
    function setType(&$form, $maj) {

        // MODE AJOUTER
        if ($maj == 0) {
            $form->setType("fils", "hidden");
            $form->setType("libelle", "text");
            if ($this->is_in_context_of_foreign_key("pere", $this->retourformulaire)) {
                $form->setType("pere", "selecthiddenstatic");
            } else {
                $form->setType("pere", "select");
            }
            if ($this->is_in_context_of_foreign_key("nomenclature_fils", $this->retourformulaire)) {
                $form->setType("nomenclature_fils", "selecthiddenstatic");
            } else {
                $form->setType("nomenclature_fils", "select");
            }
            $form->setType("point_geom", "geom");
            $form->setType("perim_geom", "geom");
            $form->setType("ligne_geom", "geom");
        }

        // MDOE MODIFIER
        if ($maj == 1) {
            $form->setType("fils", "hiddenstatic");
            $form->setType("libelle", "text");
            if ($this->is_in_context_of_foreign_key("pere", $this->retourformulaire)) {
                $form->setType("pere", "selecthiddenstatic");
            } else {
                $form->setType("pere", "select");
            }
            if ($this->is_in_context_of_foreign_key("nomenclature_fils", $this->retourformulaire)) {
                $form->setType("nomenclature_fils", "selecthiddenstatic");
            } else {
                $form->setType("nomenclature_fils", "select");
            }
            $form->setType("point_geom", "geom");
            $form->setType("perim_geom", "geom");
            $form->setType("ligne_geom", "geom");
        }

        // MODE SUPPRIMER
        if ($maj == 2) {
            $form->setType("fils", "hiddenstatic");
            $form->setType("libelle", "hiddenstatic");
            $form->setType("pere", "selectstatic");
            $form->setType("nomenclature_fils", "selectstatic");
            $form->setType("point_geom", "geom");
            $form->setType("perim_geom", "geom");
            $form->setType("ligne_geom", "geom");
        }

        // MODE CONSULTER
        if ($maj == 3) {
            $form->setType("fils", "static");
            $form->setType("libelle", "static");
            $form->setType("pere", "selectstatic");
            $form->setType("nomenclature_fils", "selectstatic");
            $form->setType("point_geom", "geom");
            $form->setType("perim_geom", "geom");
            $form->setType("ligne_geom", "geom");
        }

    }


    function setOnchange(&$form, $maj) {
    //javascript controle client
        $form->setOnchange('fils','VerifNum(this)');
        $form->setOnchange('pere','VerifNum(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("fils", 11);
        $form->setTaille("libelle", 30);
        $form->setTaille("pere", 11);
        $form->setTaille("nomenclature_fils", 10);
        $form->setTaille("point_geom", 30);
        $form->setTaille("perim_geom", 30);
        $form->setTaille("ligne_geom", 30);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("fils", 11);
        $form->setMax("libelle", 80);
        $form->setMax("pere", 11);
        $form->setMax("nomenclature_fils", 10);
        $form->setMax("point_geom", 551424);
        $form->setMax("perim_geom", 551444);
        $form->setMax("ligne_geom", 551440);
    }


    function setLib(&$form, $maj) {
    //libelle des champs
        $form->setLib('fils',_('fils'));
        $form->setLib('libelle',_('libelle'));
        $form->setLib('pere',_('pere'));
        $form->setLib('nomenclature_fils',_('nomenclature_fils'));
        $form->setLib('point_geom',_('point_geom'));
        $form->setLib('perim_geom',_('perim_geom'));
        $form->setLib('ligne_geom',_('ligne_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";
        }

        // nomenclature_fils
        $this->init_select($form, $this->f->db, $maj, null, "nomenclature_fils", $sql_nomenclature_fils, $sql_nomenclature_fils_by_id, false);
        // pere
        $this->init_select($form, $this->f->db, $maj, null, "pere", $sql_pere, $sql_pere_by_id, false);
        // point_geom
        if ($maj == 1 || $maj == 3) {
            $contenu = array();
            $contenu[0] = array("fils", $this->getParameter("idx"), "0");
            $form->setSelect("point_geom", $contenu);
        }
        // perim_geom
        if ($maj == 1 || $maj == 3) {
            $contenu = array();
            $contenu[0] = array("fils", $this->getParameter("idx"), "1");
            $form->setSelect("perim_geom", $contenu);
        }
        // ligne_geom
        if ($maj == 1 || $maj == 3) {
            $contenu = array();
            $contenu[0] = array("fils", $this->getParameter("idx"), "2");
            $form->setSelect("ligne_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('nomenclature_fils', $this->retourformulaire))
                $form->setVal('nomenclature_fils', $idxformulaire);
            if($this->is_in_context_of_foreign_key('pere', $this->retourformulaire))
                $form->setVal('pere', $idxformulaire);
        }// fin validation
        $this->set_form_default_values($form, $maj, $validation);
    }// fin setValsousformulaire

    //==================================
    // cle secondaire 
    //==================================
    

}

?>
