<?php
//$Id$ 
//gen openMairie le 08/04/2024 16:31

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

class lien_module_gen extends om_dbform {

    protected $_absolute_class_name = "lien_module";

    var $table = "lien_module";
    var $clePrimaire = "lien_module";
    var $typeCle = "N";
    var $required_field = array(
        "lien_module",
        "module",
        "object_name"
    );
    var $unique_key = array(
      array("module","object_id","object_name","parametres"),
    );
    var $foreign_keys_extended = array(
    );
    
    /**
     *
     * @return string
     */
    function get_default_libelle() {
        return $this->getVal($this->clePrimaire)."&nbsp;".$this->getVal("object_name");
    }

    /**
     *
     * @return array
     */
    function get_var_sql_forminc__champs() {
        return array(
            "lien_module",
            "object_name",
            "object_id",
            "module",
            "declencheur",
            "ordre",
            "parametres",
        );
    }




    function setvalF($val = array()) {
        //affectation valeur formulaire
        if (!is_numeric($val['lien_module'])) {
            $this->valF['lien_module'] = ""; // -> requis
        } else {
            $this->valF['lien_module'] = $val['lien_module'];
        }
        $this->valF['object_name'] = $val['object_name'];
        if ($val['object_id'] == "") {
            $this->valF['object_id'] = NULL;
        } else {
            $this->valF['object_id'] = $val['object_id'];
        }
        $this->valF['module'] = $val['module'];
        if ($val['declencheur'] == "") {
            $this->valF['declencheur'] = NULL;
        } else {
            $this->valF['declencheur'] = $val['declencheur'];
        }
        if (!is_numeric($val['ordre'])) {
            $this->valF['ordre'] = NULL;
        } else {
            $this->valF['ordre'] = $val['ordre'];
        }
            $this->valF['parametres'] = $val['parametres'];
    }

    //=================================================
    //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("lien_module", "hidden");
            $form->setType("object_name", "text");
            $form->setType("object_id", "text");
            $form->setType("module", "text");
            $form->setType("declencheur", "text");
            $form->setType("ordre", "text");
            $form->setType("parametres", "textarea");
        }

        // MDOE MODIFIER
        if ($maj == 1 || $crud == 'update') {
            $form->setType("lien_module", "hiddenstatic");
            $form->setType("object_name", "text");
            $form->setType("object_id", "text");
            $form->setType("module", "text");
            $form->setType("declencheur", "text");
            $form->setType("ordre", "text");
            $form->setType("parametres", "textarea");
        }

        // MODE SUPPRIMER
        if ($maj == 2 || $crud == 'delete') {
            $form->setType("lien_module", "hiddenstatic");
            $form->setType("object_name", "hiddenstatic");
            $form->setType("object_id", "hiddenstatic");
            $form->setType("module", "hiddenstatic");
            $form->setType("declencheur", "hiddenstatic");
            $form->setType("ordre", "hiddenstatic");
            $form->setType("parametres", "hiddenstatic");
        }

        // MODE CONSULTER
        if ($maj == 3 || $crud == 'read') {
            $form->setType("lien_module", "static");
            $form->setType("object_name", "static");
            $form->setType("object_id", "static");
            $form->setType("module", "static");
            $form->setType("declencheur", "static");
            $form->setType("ordre", "static");
            $form->setType("parametres", "textareastatic");
        }

    }


    function setOnchange(&$form, $maj) {
    //javascript controle client
        $form->setOnchange('lien_module','VerifNum(this)');
        $form->setOnchange('ordre','VerifNum(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("lien_module", 11);
        $form->setTaille("object_name", 30);
        $form->setTaille("object_id", 30);
        $form->setTaille("module", 30);
        $form->setTaille("declencheur", 30);
        $form->setTaille("ordre", 11);
        $form->setTaille("parametres", 80);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("lien_module", 11);
        $form->setMax("object_name", 150);
        $form->setMax("object_id", 255);
        $form->setMax("module", 50);
        $form->setMax("declencheur", 50);
        $form->setMax("ordre", 11);
        $form->setMax("parametres", 6);
    }


    function setLib(&$form, $maj) {
    //libelle des champs
        $form->setLib('lien_module', __('lien_module'));
        $form->setLib('object_name', __('object_name'));
        $form->setLib('object_id', __('object_id'));
        $form->setLib('module', __('module'));
        $form->setLib('declencheur', __('declencheur'));
        $form->setLib('ordre', __('ordre'));
        $form->setLib('parametres', __('parametres'));
    }
    /**
     *
     */
    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
    //==================================
    

}
