<?php
//$Id$ 
//gen openMairie le 17/02/2014 14:57

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

class om_tdb_gen extends om_dbform {
    var $table="om_tdb";
    var $clePrimaire="om_tdb";
    var $typeCle="N";
    var $required_field=array(
        "bloc",
        "login",
        "om_tdb",
        "om_widget"
    );
    var $retourformulaire;

    function setvalF($val) {
        //affectation valeur formulaire
        if (!is_numeric($val['om_tdb'])) {
            $this->valF['om_tdb'] = ""; // -> requis
        } else {
            $this->valF['om_tdb'] = $val['om_tdb'];
        }
        $this->valF['login'] = $val['login'];
        $this->valF['bloc'] = $val['bloc'];
        if (!is_numeric($val['position'])) {
            $this->valF['position'] = NULL;
        } else {
            $this->valF['position'] = $val['position'];
        }
        if (!is_numeric($val['om_widget'])) {
            $this->valF['om_widget'] = ""; // -> requis
        } else {
            $this->valF['om_widget'] = $val['om_widget'];
        }
    }

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

    function setId(&$db) {
    //numero automatique
        $this->valF[$this->clePrimaire] = $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) {
        //type
        if ($maj==0){ //ajout
            $form->setType('om_tdb','hidden');// cle automatique
            $form->setType('login','text');
            $form->setType('bloc','text');
            $form->setType('position','text');

            if($this->retourformulaire=='om_widget'
               and $form->val['om_widget'] == $this->getParameter('idxformulaire')) {
                $form->setType('om_widget','selecthiddenstatic');
            } else {
                $form->setType('om_widget','select');
            }
        }// fin ajout
        if ($maj==1){ //modifier
            $form->setType('om_tdb','hiddenstatic');
            $form->setType('login','text');
            $form->setType('bloc','text');
            $form->setType('position','text');

            if($this->retourformulaire=='om_widget'
               and $form->val['om_widget'] == $this->getParameter('idxformulaire')) {
                $form->setType('om_widget','selecthiddenstatic');
            } else {
                $form->setType('om_widget','select');
            }
        }// fin modifier
        if ($maj==2){ //supprimer
            $form->setType('om_tdb','hiddenstatic');
            $form->setType('login','hiddenstatic');
            $form->setType('bloc','hiddenstatic');
            $form->setType('position','hiddenstatic');
            $form->setType('om_widget','selectstatic');
        }//fin supprimer
        if ($maj==3){ //consulter
            $form->setType('om_tdb','static');
            $form->setType('login','static');
            $form->setType('bloc','static');
            $form->setType('position','static');
            $form->setType('om_widget','selectstatic');
        }//fin consulter
    }

    function setOnchange(&$form,$maj) {
    //javascript controle client
        $form->setOnchange('om_tdb','VerifNum(this)');
        $form->setOnchange('position','VerifNum(this)');
        $form->setOnchange('om_widget','VerifNum(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("om_tdb", 11);
        $form->setTaille("login", 30);
        $form->setTaille("bloc", 10);
        $form->setTaille("position", 11);
        $form->setTaille("om_widget", 11);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("om_tdb", 11);
        $form->setMax("login", 40);
        $form->setMax("bloc", 10);
        $form->setMax("position", 11);
        $form->setMax("om_widget", 11);
    }


    function setLib(&$form,$maj) {
    //libelle des champs
        $form->setLib('om_tdb',_('om_tdb'));
        $form->setLib('login',_('login'));
        $form->setLib('bloc',_('bloc'));
        $form->setLib('position',_('position'));
        $form->setLib('om_widget',_('om_widget'));
    }

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

        // om_widget
        $this->init_select($form, $db, $maj, $debug, "om_widget",
                           $sql_om_widget, $sql_om_widget_by_id, false);
    }// fin select

    //==================================
    // sous Formulaire  [subform]
    //==================================

    function setValsousformulaire(&$form,$maj,$validation,$idxformulaire,$retourformulaire,$typeformulaire,&$db,$DEBUG=null){
        $this->retourformulaire = $retourformulaire;
        if($validation == 0) {
            if($retourformulaire =='om_widget')
                $form->setVal('om_widget', $idxformulaire);
        }// fin validation
    }// fin setValsousformulaire

    //==================================
    // cle secondaire  [secondary key]
    //==================================

}// fin classe
?>