<?php
//$Id$ 
//gen openMairie le 25/04/2024 14:34

require_once PATH_OPENMAIRIE."om_dbform.class.php";

class om_actions_gen extends dbform {

    protected $_absolute_class_name = "om_actions";

    var $table = "om_actions";
    var $clePrimaire = "om_actions";
    var $typeCle = "N";
    var $required_field = array(
        "libelle",
        "module",
        "om_actions"
    );
    
    var $foreign_keys_extended = array(
        "om_tables" => array("om_tables", ),
    );
    
    /**
     *
     * @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(
            "om_actions",
            "libelle",
            "module",
            "parametres",
            "table_name",
        );
    }

    /**
     *
     * @return string
     */
    function get_var_sql_forminc__sql_table_name() {
        return "SELECT om_tables.table_name, om_tables.libelle FROM ".DB_PREFIXE."om_tables ORDER BY om_tables.libelle ASC";
    }

    /**
     *
     * @return string
     */
    function get_var_sql_forminc__sql_table_name_by_id() {
        return "SELECT om_tables.table_name, om_tables.libelle FROM ".DB_PREFIXE."om_tables WHERE table_name = '<idx>'";
    }




    function setvalF($val = array()) {
        //affectation valeur formulaire
        if (!is_numeric($val['om_actions'])) {
            $this->valF['om_actions'] = ""; // -> requis
        } else {
            $this->valF['om_actions'] = $val['om_actions'];
        }
        $this->valF['libelle'] = $val['libelle'];
        $this->valF['module'] = $val['module'];
            $this->valF['parametres'] = $val['parametres'];
        if ($val['table_name'] == "") {
            $this->valF['table_name'] = NULL;
        } else {
            $this->valF['table_name'] = $val['table_name'];
        }
    }

    //=================================================
    //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("om_actions", "hidden");
            $form->setType("libelle", "text");
            $form->setType("module", "text");
            $form->setType("parametres", "text");
            if ($this->is_in_context_of_foreign_key("om_tables", $this->retourformulaire)) {
                $form->setType("table_name", "selecthiddenstatic");
            } else {
                $form->setType("table_name", "select");
            }
        }

        // MDOE MODIFIER
        if ($maj == 1 || $crud == 'update') {
            $form->setType("om_actions", "hiddenstatic");
            $form->setType("libelle", "text");
            $form->setType("module", "text");
            $form->setType("parametres", "text");
            if ($this->is_in_context_of_foreign_key("om_tables", $this->retourformulaire)) {
                $form->setType("table_name", "selecthiddenstatic");
            } else {
                $form->setType("table_name", "select");
            }
        }

        // MODE SUPPRIMER
        if ($maj == 2 || $crud == 'delete') {
            $form->setType("om_actions", "hiddenstatic");
            $form->setType("libelle", "hiddenstatic");
            $form->setType("module", "hiddenstatic");
            $form->setType("parametres", "hiddenstatic");
            $form->setType("table_name", "selectstatic");
        }

        // MODE CONSULTER
        if ($maj == 3 || $crud == 'read') {
            $form->setType("om_actions", "static");
            $form->setType("libelle", "static");
            $form->setType("module", "static");
            $form->setType("parametres", "static");
            $form->setType("table_name", "selectstatic");
        }

    }


    function setOnchange(&$form, $maj) {
    //javascript controle client
        $form->setOnchange('om_actions','VerifNum(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("om_actions", 11);
        $form->setTaille("libelle", 30);
        $form->setTaille("module", 30);
        $form->setTaille("parametres", 10);
        $form->setTaille("table_name", 30);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("om_actions", 11);
        $form->setMax("libelle", 40);
        $form->setMax("module", 40);
        $form->setMax("parametres", -5);
        $form->setMax("table_name", 40);
    }


    function setLib(&$form, $maj) {
    //libelle des champs
        $form->setLib('om_actions', __('om_actions'));
        $form->setLib('libelle', __('libelle'));
        $form->setLib('module', __('module'));
        $form->setLib('parametres', __('parametres'));
        $form->setLib('table_name', __('table_name'));
    }
    /**
     *
     */
    function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) {

        // table_name
        $this->init_select(
            $form, 
            $this->f->db,
            $maj,
            null,
            "table_name",
            $this->get_var_sql_forminc__sql("table_name"),
            $this->get_var_sql_forminc__sql("table_name_by_id"),
            false
        );
    }


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

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

}
