<?php
//$Id$ 
//gen openMairie le 27/02/2013 15:37

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

class travaux_archive_gen extends om_dbform {
    var $table="travaux_archive";
    var $clePrimaire="travaux";
    var $typeCle="N";
    var $required_field=array(
        "observation",
        "travaux"
    );
    var $retourformulaire;

    function setvalF($val) {
        //affectation valeur formulaire
        if (!is_numeric($val['travaux'])) {
            $this->valF['travaux'] = ""; // -> requis
        } else {
            $this->valF['travaux'] = $val['travaux'];
        }
        if (!is_numeric($val['entreprise'])) {
            $this->valF['entreprise'] = NULL;
        } else {
            $this->valF['entreprise'] = $val['entreprise'];
        }
        if (!is_numeric($val['emplacement'])) {
            $this->valF['emplacement'] = NULL;
        } else {
            $this->valF['emplacement'] = $val['emplacement'];
        }
        if ($val['datedebinter'] != "") {
            $this->valF['datedebinter'] = $this->dateDB($val['datedebinter']);
        } else {
            $this->valF['datedebinter'] = NULL;
        }
        if ($val['datefininter'] != "") {
            $this->valF['datefininter'] = $this->dateDB($val['datefininter']);
        } else {
            $this->valF['datefininter'] = NULL;
        }
            $this->valF['observation'] = $val['observation'];
        if ($val['naturedemandeur'] == "") {
            $this->valF['naturedemandeur'] = NULL;
        } else {
            $this->valF['naturedemandeur'] = $val['naturedemandeur'];
        }
        if (!is_numeric($val['naturetravaux'])) {
            $this->valF['naturetravaux'] = NULL;
        } else {
            $this->valF['naturetravaux'] = $val['naturetravaux'];
        }
    }

    //=================================================
    //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('travaux','hidden');// cle automatique
            $form->setType('entreprise','text');
            $form->setType('emplacement','text');
            if($this->retourformulaire=='')
                $form->setType('datedebinter','date');
            else
                $form->setType('datedebinter','date2');
            if($this->retourformulaire=='')
                $form->setType('datefininter','date');
            else
                $form->setType('datefininter','date2');
            $form->setType('observation','textarea');
            $form->setType('naturedemandeur','text');

            if($this->retourformulaire=='travaux_nature'
               and $form->val['naturetravaux'] == $this->getParameter('idxformulaire')) {
                $form->setType('naturetravaux','selecthiddenstatic');
            } else {
                $form->setType('naturetravaux','select');
            }
        }// fin ajout
        if ($maj==1){ //modifier
            $form->setType('travaux','hiddenstatic');
            $form->setType('entreprise','text');
            $form->setType('emplacement','text');
            if($this->retourformulaire=='')
                $form->setType('datedebinter','date');
            else
                $form->setType('datedebinter','date2');
            if($this->retourformulaire=='')
                $form->setType('datefininter','date');
            else
                $form->setType('datefininter','date2');
            $form->setType('observation','textarea');
            $form->setType('naturedemandeur','text');

            if($this->retourformulaire=='travaux_nature'
               and $form->val['naturetravaux'] == $this->getParameter('idxformulaire')) {
                $form->setType('naturetravaux','selecthiddenstatic');
            } else {
                $form->setType('naturetravaux','select');
            }
        }// fin modifier
        if ($maj==2){ //supprimer
            $form->setType('travaux','hiddenstatic');
            $form->setType('entreprise','hiddenstatic');
            $form->setType('emplacement','hiddenstatic');
            $form->setType('datedebinter','hiddenstatic');
            $form->setType('datefininter','hiddenstatic');
            $form->setType('observation','hiddenstatic');
            $form->setType('naturedemandeur','hiddenstatic');
            $form->setType('naturetravaux','selectstatic');
        }//fin supprimer
        if ($maj==3){ //consulter
            $form->setType('travaux','static');
            $form->setType('entreprise','static');
            $form->setType('emplacement','static');
            $form->setType('datedebinter','datestatic');
            $form->setType('datefininter','datestatic');
            $form->setType('observation','textareastatic');
            $form->setType('naturedemandeur','static');
            $form->setType('naturetravaux','selectstatic');
        }//fin consulter
    }

    function setOnchange(&$form,$maj) {
    //javascript controle client
        $form->setOnchange('travaux','VerifNum(this)');
        $form->setOnchange('entreprise','VerifNum(this)');
        $form->setOnchange('emplacement','VerifNum(this)');
        $form->setOnchange('datedebinter','fdate(this)');
        $form->setOnchange('datefininter','fdate(this)');
        $form->setOnchange('naturetravaux','VerifNum(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("travaux", 11);
        $form->setTaille("entreprise", 11);
        $form->setTaille("emplacement", 11);
        $form->setTaille("datedebinter", 12);
        $form->setTaille("datefininter", 12);
        $form->setTaille("observation", 80);
        $form->setTaille("naturedemandeur", 20);
        $form->setTaille("naturetravaux", 11);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("travaux", 11);
        $form->setMax("entreprise", 11);
        $form->setMax("emplacement", 11);
        $form->setMax("datedebinter", 12);
        $form->setMax("datefininter", 12);
        $form->setMax("observation", 6);
        $form->setMax("naturedemandeur", 20);
        $form->setMax("naturetravaux", 11);
    }


    function setLib(&$form,$maj) {
    //libelle des champs
        $form->setLib('travaux',_('travaux'));
        $form->setLib('entreprise',_('entreprise'));
        $form->setLib('emplacement',_('emplacement'));
        $form->setLib('datedebinter',_('datedebinter'));
        $form->setLib('datefininter',_('datefininter'));
        $form->setLib('observation',_('observation'));
        $form->setLib('naturedemandeur',_('naturedemandeur'));
        $form->setLib('naturetravaux',_('naturetravaux'));
    }

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

        // naturetravaux
        $this->init_select($form, $db, $maj, $debug, "naturetravaux",
                           $sql_naturetravaux, $sql_naturetravaux_by_id, true);
    }// fin select

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

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

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

}// fin classe
?>