<?php
//$Id$ 
//gen openMairie le 16/05/2012 11:07 
require_once ("../obj/om_dbform.class.php");

class defunt_prestation_gen extends om_dbform {
    var $table="defunt_prestation";
    var $clePrimaire="defunt_prestation";
    var $typeCle="N";
    var $retourformulaire;

    function setvalF($val) {
        //affectation valeur formulaire
        $this->valF['defunt_prestation'] = $val['defunt_prestation'];
        $this->valF['prestation'] = $val['prestation'];
        $this->valF['lieu'] = $val['lieu'];
        if($val['date']!="") $this->valF['date'] = $this->dateDB($val['date']);
        $this->valF['heure'] = $val['heure'];
        $this->valF['destination'] = $val['destination'];
        $this->valF['via'] = $val['via'];
        $this->valF['vehicule'] = $val['vehicule'];
        $this->valF['defunt'] = $val['defunt'];
    }

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

    function setId(&$db) {
    //numero automatique
        $this->valF[$this->table] = $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
    }

    //====================================
    // verifier avant validation [verify]
    //=====================================
    /**
     * Methode verifier
     */
    function verifier($val = array(), &$db = NULL, $DEBUG = false) {
        // On appelle la methode de la classe parent
        parent::verifier($val, $db, $DEBUG);
        // On verifie si le champ n'est pas vide
        if ($this->valF['prestation'] == "") {
            $this->correct = false;
            $this->addToMessage(_("Le champ")." "._("prestation")." "._("est obligatoire"));
        }
    }


    //==========================
    // Formulaire  [form]
    //==========================

    function setType(&$form,$maj) {
        //type
        if ($maj==0){ //ajout
            $form->setType('defunt_prestation','hidden');// cle automatique
            if($this->retourformulaire=='prestation')
                $form->setType('prestation','hiddenstatic');
            else
                $form->setType('prestation','select');
            $form->setType('lieu','text');
            if($this->retourformulaire=='')
                $form->setType('date','date');
            else
                $form->setType('date','date2');
            $form->setType('heure','text');
            $form->setType('destination','text');
            $form->setType('via','text');
            if($this->retourformulaire=='vehicule')
                $form->setType('vehicule','hiddenstatic');
            else
                $form->setType('vehicule','select');
            if($this->retourformulaire=='defunt')
                $form->setType('defunt','hiddenstatic');
            else
                $form->setType('defunt','select');
        }// fin ajout
        if ($maj==1){ //modifier
            $form->setType('defunt_prestation','hiddenstatic');
            if($this->retourformulaire=='prestation')
                $form->setType('prestation','hiddenstatic');
            else
                $form->setType('prestation','select');
            $form->setType('lieu','text');
            if($this->retourformulaire=='')
                $form->setType('date','date');
            else
                $form->setType('date','date2');
            $form->setType('heure','text');
            $form->setType('destination','text');
            $form->setType('via','text');
            if($this->retourformulaire=='vehicule')
                $form->setType('vehicule','hiddenstatic');
            else
                $form->setType('vehicule','select');
            if($this->retourformulaire=='defunt')
                $form->setType('defunt','hiddenstatic');
            else
                $form->setType('defunt','select');
        }// fin modifier
        if ($maj==2){ //supprimer
            $form->setType('defunt_prestation','hiddenstatic');
            $form->setType('prestation','hiddenstatic');
            $form->setType('lieu','hiddenstatic');
            $form->setType('date','hiddenstatic');
            $form->setType('heure','hiddenstatic');
            $form->setType('destination','hiddenstatic');
            $form->setType('via','hiddenstatic');
            $form->setType('vehicule','hiddenstatic');
            $form->setType('defunt','hiddenstatic');
        }//fin supprimer
    }

    function setOnchange(&$form,$maj) {
    //javascript controle client
        $form->setOnchange('defunt_prestation','VerifNum(this)');
        $form->setOnchange('prestation','VerifNum(this)');
        $form->setOnchange('date','fdate(this)');
        $form->setOnchange('vehicule','VerifNum(this)');
        $form->setOnchange('defunt','VerifNum(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("defunt_prestation", 8);
        $form->setTaille("prestation", 8);
        $form->setTaille("lieu", 30);
        $form->setTaille("date", 10);
        $form->setTaille("heure", 8);
        $form->setTaille("destination", 30);
        $form->setTaille("via", 30);
        $form->setTaille("vehicule", 8);
        $form->setTaille("defunt", 8);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("defunt_prestation", 8);
        $form->setMax("prestation", 8);
        $form->setMax("lieu", 40);
        $form->setMax("date", 10);
        $form->setMax("heure", 8);
        $form->setMax("destination", 40);
        $form->setMax("via", 40);
        $form->setMax("vehicule", 8);
        $form->setMax("defunt", 8);
    }


    function setLib(&$form,$maj) {
    //libelle des champs
        $form->setLib('defunt_prestation',_('defunt_prestation'));
        $form->setLib('prestation',_('prestation'));
        $form->setLib('lieu',_('lieu'));
        $form->setLib('date',_('date'));
        $form->setLib('heure',_('heure'));
        $form->setLib('destination',_('destination'));
        $form->setLib('via',_('via'));
        $form->setLib('vehicule',_('vehicule'));
        $form->setLib('defunt',_('defunt'));
    }

    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");
        if($maj<2){
            // prestation
            $contenu=array();
            $res = $db->query($sql_prestation);
            // Logger
            $this->addToLog("setSelect()[gen/obj]: db->query(\"".$sql_prestation."\");", VERBOSE_MODE);
            if (database::isError($res))
                die($res->getMessage().$sql_prestation);
            else{
                if ($debug == 1)
                    echo " la requete ".$sql_prestation." est executee<br>";
                $contenu[0][0]='';
                $contenu[1][0]=_('choisir')."&nbsp;"._('prestation');
                $k=1;
                    while ($row=& $res->fetchRow()){
                        $contenu[0][$k]=$row[0];
                        $contenu[1][$k]=$row[1];
                        $k++;
                }
                $form->setSelect('prestation',$contenu);
            }// fin error db
            // vehicule
            $contenu=array();
            $res = $db->query($sql_vehicule);
            // Logger
            $this->addToLog("setSelect()[gen/obj]: db->query(\"".$sql_vehicule."\");", VERBOSE_MODE);
            if (database::isError($res))
                die($res->getMessage().$sql_vehicule);
            else{
                if ($debug == 1)
                    echo " la requete ".$sql_vehicule." est executee<br>";
                $contenu[0][0]='';
                $contenu[1][0]=_('choisir')."&nbsp;"._('vehicule');
                $k=1;
                    while ($row=& $res->fetchRow()){
                        $contenu[0][$k]=$row[0];
                        $contenu[1][$k]=$row[1];
                        $k++;
                }
                $form->setSelect('vehicule',$contenu);
            }// fin error db
            // defunt
            $contenu=array();
            $res = $db->query($sql_defunt);
            // Logger
            $this->addToLog("setSelect()[gen/obj]: db->query(\"".$sql_defunt."\");", VERBOSE_MODE);
            if (database::isError($res))
                die($res->getMessage().$sql_defunt);
            else{
                if ($debug == 1)
                    echo " la requete ".$sql_defunt." est executee<br>";
                $contenu[0][0]='';
                $contenu[1][0]=_('choisir')."&nbsp;"._('defunt');
                $k=1;
                    while ($row=& $res->fetchRow()){
                        $contenu[0][$k]=$row[0];
                        $contenu[1][$k]=$row[1];
                        $k++;
                }
                $form->setSelect('defunt',$contenu);
            }// fin error db
        }// fin maj
    }// fin select

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

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

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

}// fin classe
?>