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

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

class pere_gen extends om_dbform {

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



    function setvalF($val) {
        //affectation valeur formulaire
        if (!is_numeric($val['pere'])) {
            $this->valF['pere'] = ""; // -> requis
        } else {
            $this->valF['pere'] = $val['pere'];
        }
        $this->valF['libelle'] = $val['libelle'];
        if ($val['nomenclature_pere'] == "") {
            $this->valF['nomenclature_pere'] = NULL;
        } else {
            $this->valF['nomenclature_pere'] = $val['nomenclature_pere'];
        }
        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'];
        }
    }

    //=================================================
    //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("pere", "hidden");
            $form->setType("libelle", "text");
            if ($this->is_in_context_of_foreign_key("nomenclature_pere", $this->retourformulaire)) {
                $form->setType("nomenclature_pere", "selecthiddenstatic");
            } else {
                $form->setType("nomenclature_pere", "select");
            }
            $form->setType("point_geom", "geom");
            $form->setType("perim_geom", "geom");
        }

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

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

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

    }


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

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


    function setLib(&$form, $maj) {
    //libelle des champs
        $form->setLib('pere',_('pere'));
        $form->setLib('libelle',_('libelle'));
        $form->setLib('nomenclature_pere',_('nomenclature_pere'));
        $form->setLib('point_geom',_('point_geom'));
        $form->setLib('perim_geom',_('perim_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_pere
        $this->init_select($form, $this->f->db, $maj, null, "nomenclature_pere", $sql_nomenclature_pere, $sql_nomenclature_pere_by_id, false);
        // point_geom
        if ($maj == 1 || $maj == 3) {
            $contenu = array();
            $contenu[0] = array("pere", $this->getParameter("idx"), "0");
            $form->setSelect("point_geom", $contenu);
        }
        // perim_geom
        if ($maj == 1 || $maj == 3) {
            $contenu = array();
            $contenu[0] = array("pere", $this->getParameter("idx"), "1");
            $form->setSelect("perim_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_pere', $this->retourformulaire))
                $form->setVal('nomenclature_pere', $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 : fils
        $this->rechercheTable($this->f->db, "fils", "pere", $id);
    }


}

?>
