<?php
//$Id$ 
//gen openMairie le 05/10/2012 13:55

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

class bible_gen extends om_dbform {
    var $table="bible";
    var $clePrimaire="bible";
    var $typeCle="N";
    var $required_field=array(
        "bible",
        "contenu",
        "libelle"
    );
    var $retourformulaire;

    function setvalF($val) {
        //affectation valeur formulaire
        if (!is_numeric($val['bible'])) {
            $this->valF['bible'] = ""; // -> requis
        } else {
            $this->valF['bible'] = $val['bible'];
        }
        $this->valF['libelle'] = $val['libelle'];
        if (!is_numeric($val['evenement'])) {
            $this->valF['evenement'] = NULL;
        } else {
            $this->valF['evenement'] = $val['evenement'];
        }
            $this->valF['contenu'] = $val['contenu'];
        if (!is_numeric($val['complement'])) {
            $this->valF['complement'] = NULL;
        } else {
            $this->valF['complement'] = $val['complement'];
        }
        if ($val['automatique'] == "") {
            $this->valF['automatique'] = ""; // -> default
        } else {
            $this->valF['automatique'] = $val['automatique'];
        }
        if ($val['nature'] == "") {
            $this->valF['nature'] = NULL;
        } else {
            $this->valF['nature'] = $val['nature'];
        }
    }

    //=================================================
    //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('bible','hidden');// cle automatique
            $form->setType('libelle','text');

            if($this->retourformulaire=='evenement'
               and $form->val['evenement'] == $this->getParameter('idxformulaire')) {
                $form->setType('evenement','selecthiddenstatic');
            } else {
                $form->setType('evenement','select');
            }
            $form->setType('contenu','textarea');
            $form->setType('complement','text');
            $form->setType('automatique','text');

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

            if($this->retourformulaire=='evenement'
               and $form->val['evenement'] == $this->getParameter('idxformulaire')) {
                $form->setType('evenement','selecthiddenstatic');
            } else {
                $form->setType('evenement','select');
            }
            $form->setType('contenu','textarea');
            $form->setType('complement','text');
            $form->setType('automatique','text');

            if($this->retourformulaire=='nature'
               and $form->val['nature'] == $this->getParameter('idxformulaire')) {
                $form->setType('nature','selecthiddenstatic');
            } else {
                $form->setType('nature','select');
            }
        }// fin modifier
        if ($maj==2){ //supprimer
            $form->setType('bible','hiddenstatic');
            $form->setType('libelle','hiddenstatic');
            $form->setType('evenement','selectstatic');
            $form->setType('contenu','hiddenstatic');
            $form->setType('complement','hiddenstatic');
            $form->setType('automatique','hiddenstatic');
            $form->setType('nature','selectstatic');
        }//fin supprimer
        if ($maj==3){ //consulter
            $form->setType('bible','static');
            $form->setType('libelle','static');
            $form->setType('evenement','selectstatic');
            $form->setType('contenu','textareastatic');
            $form->setType('complement','static');
            $form->setType('automatique','static');
            $form->setType('nature','selectstatic');
        }//fin consulter
    }

    function setOnchange(&$form,$maj) {
    //javascript controle client
        $form->setOnchange('bible','VerifNum(this)');
        $form->setOnchange('evenement','VerifNum(this)');
        $form->setOnchange('complement','VerifNum(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("bible", 11);
        $form->setTaille("libelle", 30);
        $form->setTaille("evenement", 11);
        $form->setTaille("contenu", 80);
        $form->setTaille("complement", 11);
        $form->setTaille("automatique", 10);
        $form->setTaille("nature", 10);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("bible", 11);
        $form->setMax("libelle", 60);
        $form->setMax("evenement", 11);
        $form->setMax("contenu", 6);
        $form->setMax("complement", 11);
        $form->setMax("automatique", 3);
        $form->setMax("nature", 2);
    }


    function setLib(&$form,$maj) {
    //libelle des champs
        $form->setLib('bible',_('bible'));
        $form->setLib('libelle',_('libelle'));
        $form->setLib('evenement',_('evenement'));
        $form->setLib('contenu',_('contenu'));
        $form->setLib('complement',_('complement'));
        $form->setLib('automatique',_('automatique'));
        $form->setLib('nature',_('nature'));
    }

    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");

        // evenement
        $this->init_select($form, $db, $maj, $debug, "evenement",
                           $sql_evenement, $sql_evenement_by_id, false);

        // nature
        $this->init_select($form, $db, $maj, $debug, "nature",
                           $sql_nature, $sql_nature_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 =='evenement')
                $form->setVal('evenement', $idxformulaire);
            if($retourformulaire =='nature')
                $form->setVal('nature', $idxformulaire);
        }// fin validation
    }// fin setValsousformulaire

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

}// fin classe
?>