<?php
//$Id$ 
//gen openMairie le 25/02/2022 18:28

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

class categorie_tiers_consulte_gen extends om_dbform {

    protected $_absolute_class_name = "categorie_tiers_consulte";

    var $table = "categorie_tiers_consulte";
    var $clePrimaire = "categorie_tiers_consulte";
    var $typeCle = "N";
    var $required_field = array(
        "categorie_tiers_consulte",
        "date_debut_validite",
        "date_fin_validite",
        "libelle"
    );
    
    var $foreign_keys_extended = array(
    );
    
    /**
     *
     * @return string
     */
    function get_default_libelle() {
        return $this->getVal($this->clePrimaire)."&nbsp;".$this->getVal("libelle");
    }

    /**
     *
     * @return array
     */
    function get_var_sql_forminc__champs() {
        return array(
            "categorie_tiers_consulte",
            "code",
            "description",
            "libelle",
            "date_debut_validite",
            "date_fin_validite",
        );
    }




    function setvalF($val = array()) {
        //affectation valeur formulaire
        if (!is_numeric($val['categorie_tiers_consulte'])) {
            $this->valF['categorie_tiers_consulte'] = ""; // -> requis
        } else {
            $this->valF['categorie_tiers_consulte'] = $val['categorie_tiers_consulte'];
        }
        if ($val['code'] == "") {
            $this->valF['code'] = NULL;
        } else {
            $this->valF['code'] = $val['code'];
        }
            $this->valF['description'] = $val['description'];
        $this->valF['libelle'] = $val['libelle'];
        if ($val['date_debut_validite'] != "") {
            $this->valF['date_debut_validite'] = $this->dateDB($val['date_debut_validite']);
        }
        if ($val['date_fin_validite'] != "") {
            $this->valF['date_fin_validite'] = $this->dateDB($val['date_fin_validite']);
        }
    }

    //=================================================
    //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 = array()) {
    //numero automatique -> pas de controle ajout cle primaire
    }

    function verifierAjout($val = array(), &$dnu1 = null) {
    //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("categorie_tiers_consulte", "hidden");
            $form->setType("code", "text");
            $form->setType("description", "textarea");
            $form->setType("libelle", "text");
            $form->setType("date_debut_validite", "date");
            $form->setType("date_fin_validite", "date");
        }

        // MDOE MODIFIER
        if ($maj == 1 || $crud == 'update') {
            $form->setType("categorie_tiers_consulte", "hiddenstatic");
            $form->setType("code", "text");
            $form->setType("description", "textarea");
            $form->setType("libelle", "text");
            $form->setType("date_debut_validite", "date");
            $form->setType("date_fin_validite", "date");
        }

        // MODE SUPPRIMER
        if ($maj == 2 || $crud == 'delete') {
            $form->setType("categorie_tiers_consulte", "hiddenstatic");
            $form->setType("code", "hiddenstatic");
            $form->setType("description", "hiddenstatic");
            $form->setType("libelle", "hiddenstatic");
            $form->setType("date_debut_validite", "hiddenstatic");
            $form->setType("date_fin_validite", "hiddenstatic");
        }

        // MODE CONSULTER
        if ($maj == 3 || $crud == 'read') {
            $form->setType("categorie_tiers_consulte", "static");
            $form->setType("code", "static");
            $form->setType("description", "textareastatic");
            $form->setType("libelle", "static");
            $form->setType("date_debut_validite", "datestatic");
            $form->setType("date_fin_validite", "datestatic");
        }

    }


    function setOnchange(&$form, $maj) {
    //javascript controle client
        $form->setOnchange('categorie_tiers_consulte','VerifNum(this)');
        $form->setOnchange('date_debut_validite','fdate(this)');
        $form->setOnchange('date_fin_validite','fdate(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("categorie_tiers_consulte", 11);
        $form->setTaille("code", 30);
        $form->setTaille("description", 80);
        $form->setTaille("libelle", 30);
        $form->setTaille("date_debut_validite", 12);
        $form->setTaille("date_fin_validite", 12);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("categorie_tiers_consulte", 11);
        $form->setMax("code", 50);
        $form->setMax("description", 6);
        $form->setMax("libelle", 255);
        $form->setMax("date_debut_validite", 12);
        $form->setMax("date_fin_validite", 12);
    }


    function setLib(&$form, $maj) {
    //libelle des champs
        $form->setLib('categorie_tiers_consulte', __('categorie_tiers_consulte'));
        $form->setLib('code', __('code'));
        $form->setLib('description', __('description'));
        $form->setLib('libelle', __('libelle'));
        $form->setLib('date_debut_validite', __('date_debut_validite'));
        $form->setLib('date_fin_validite', __('date_fin_validite'));
    }
    /**
     *
     */
    function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) {

    }


    //==================================
    // sous Formulaire
    //==================================
    

    function setValsousformulaire(&$form, $maj, $validation, $idxformulaire, $retourformulaire, $typeformulaire, &$dnu1 = null, $dnu2 = null) {
        $this->retourformulaire = $retourformulaire;
        $this->set_form_default_values($form, $maj, $validation);
    }// fin setValsousformulaire

    //==================================
    // cle secondaire
    //==================================
    
    /**
     * Methode clesecondaire
     */
    function cleSecondaire($id, &$dnu1 = null, $val = array(), $dnu2 = null) {
        // On appelle la methode de la classe parent
        parent::cleSecondaire($id);
        // Verification de la cle secondaire : lien_categorie_tiers_consulte_om_collectivite
        $this->rechercheTable($this->f->db, "lien_categorie_tiers_consulte_om_collectivite", "categorie_tiers_consulte", $id);
        // Verification de la cle secondaire : tiers_consulte
        $this->rechercheTable($this->f->db, "tiers_consulte", "categorie_tiers_consulte", $id);
    }


}
