<?php
//$Id$ 
//gen openMairie le 16/12/2015 11:14

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 $foreign_keys_extended = array(
        "travaux_nature" => array("travaux_nature", ),
    );



    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(&$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) {
        // Récupération du mode de l'action
        $crud = $this->get_action_crud($maj);

        // MODE AJOUTER
        if ($maj == 0 || $crud == 'create') {
            $form->setType("travaux", "hidden");
            $form->setType("entreprise", "text");
            $form->setType("emplacement", "text");
            $form->setType("datedebinter", "date");
            $form->setType("datefininter", "date");
            $form->setType("observation", "textarea");
            $form->setType("naturedemandeur", "text");
            if ($this->is_in_context_of_foreign_key("travaux_nature", $this->retourformulaire)) {
                $form->setType("naturetravaux", "selecthiddenstatic");
            } else {
                $form->setType("naturetravaux", "select");
            }
        }

        // MDOE MODIFIER
        if ($maj == 1 || $crud == 'update') {
            $form->setType("travaux", "hiddenstatic");
            $form->setType("entreprise", "text");
            $form->setType("emplacement", "text");
            $form->setType("datedebinter", "date");
            $form->setType("datefininter", "date");
            $form->setType("observation", "textarea");
            $form->setType("naturedemandeur", "text");
            if ($this->is_in_context_of_foreign_key("travaux_nature", $this->retourformulaire)) {
                $form->setType("naturetravaux", "selecthiddenstatic");
            } else {
                $form->setType("naturetravaux", "select");
            }
        }

        // MODE SUPPRIMER
        if ($maj == 2 || $crud == 'delete') {
            $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");
        }

        // MODE CONSULTER
        if ($maj == 3 || $crud == 'read') {
            $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");
        }

    }


    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, &$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";
        }

        // naturetravaux
        $this->init_select($form, $this->f->db, $maj, null, "naturetravaux", $sql_naturetravaux, $sql_naturetravaux_by_id, true);
    }


    //==================================
    // 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('travaux_nature', $this->retourformulaire))
                $form->setVal('naturetravaux', $idxformulaire);
        }// fin validation
        $this->set_form_default_values($form, $maj, $validation);
    }// fin setValsousformulaire

    //==================================
    // cle secondaire 
    //==================================
    

}

?>
