<?php
//$Id$ 
//gen openMairie le 08/12/2025 11:26

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

class extra_data_register_def_gen extends om_dbform {

    protected $_absolute_class_name = "extra_data_register_def";

    var $table = "extra_data_register_def";
    var $clePrimaire = "extra_data_register_def";
    var $typeCle = "N";
    var $required_field = array(
        "description",
        "extra_data_register_def",
        "max_length",
        "name",
        "type"
    );
    var $unique_key = array(
      array("name","object_name"),
    );
    var $foreign_keys_extended = array(
    );
    
    /**
     *
     * @return string
     */
    function get_default_libelle() {
        return $this->getVal($this->clePrimaire)."&nbsp;".$this->getVal("name");
    }

    /**
     *
     * @return array
     */
    function get_var_sql_forminc__champs() {
        return array(
            "extra_data_register_def",
            "name",
            "description",
            "type",
            "object_name",
            "max_length",
            "alias_champ_fusion",
        );
    }




    function setvalF($val = array()) {
        //affectation valeur formulaire
        if (!is_numeric($val['extra_data_register_def'])) {
            $this->valF['extra_data_register_def'] = ""; // -> requis
        } else {
            $this->valF['extra_data_register_def'] = $val['extra_data_register_def'];
        }
        $this->valF['name'] = $val['name'];
        $this->valF['description'] = $val['description'];
        $this->valF['type'] = $val['type'];
        if ($val['object_name'] == "") {
            $this->valF['object_name'] = NULL;
        } else {
            $this->valF['object_name'] = $val['object_name'];
        }
        if (!is_numeric($val['max_length'])) {
            $this->valF['max_length'] = ""; // -> requis
        } else {
            $this->valF['max_length'] = $val['max_length'];
        }
        if ($val['alias_champ_fusion'] == "") {
            $this->valF['alias_champ_fusion'] = NULL;
        } else {
            $this->valF['alias_champ_fusion'] = $val['alias_champ_fusion'];
        }
    }

    //=================================================
    //cle primaire automatique [automatic primary key]
    //==================================================

    function setId(&$dnu1 = null) {
    //numero automatique
        $qres = $this->f->get_next_id_from_db_sequence(DB_PREFIXE.$this->table, array("origin" => __METHOD__));
        $this->valF[$this->clePrimaire] = $qres['result'];
    }

    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("extra_data_register_def", "hidden");
            $form->setType("name", "text");
            $form->setType("description", "text");
            $form->setType("type", "text");
            $form->setType("object_name", "text");
            $form->setType("max_length", "text");
            $form->setType("alias_champ_fusion", "text");
        }

        // MDOE MODIFIER
        if ($maj == 1 || $crud == 'update') {
            $form->setType("extra_data_register_def", "hiddenstatic");
            $form->setType("name", "text");
            $form->setType("description", "text");
            $form->setType("type", "text");
            $form->setType("object_name", "text");
            $form->setType("max_length", "text");
            $form->setType("alias_champ_fusion", "text");
        }

        // MODE SUPPRIMER
        if ($maj == 2 || $crud == 'delete') {
            $form->setType("extra_data_register_def", "hiddenstatic");
            $form->setType("name", "hiddenstatic");
            $form->setType("description", "hiddenstatic");
            $form->setType("type", "hiddenstatic");
            $form->setType("object_name", "hiddenstatic");
            $form->setType("max_length", "hiddenstatic");
            $form->setType("alias_champ_fusion", "hiddenstatic");
        }

        // MODE CONSULTER
        if ($maj == 3 || $crud == 'read') {
            $form->setType("extra_data_register_def", "static");
            $form->setType("name", "static");
            $form->setType("description", "static");
            $form->setType("type", "static");
            $form->setType("object_name", "static");
            $form->setType("max_length", "static");
            $form->setType("alias_champ_fusion", "static");
        }

    }


    function setOnchange(&$form, $maj) {
    //javascript controle client
        $form->setOnchange('extra_data_register_def','VerifNum(this)');
        $form->setOnchange('max_length','VerifNum(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("extra_data_register_def", 11);
        $form->setTaille("name", 30);
        $form->setTaille("description", 30);
        $form->setTaille("type", 15);
        $form->setTaille("object_name", 30);
        $form->setTaille("max_length", 11);
        $form->setTaille("alias_champ_fusion", 30);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("extra_data_register_def", 11);
        $form->setMax("name", 50);
        $form->setMax("description", 255);
        $form->setMax("type", 15);
        $form->setMax("object_name", 50);
        $form->setMax("max_length", 11);
        $form->setMax("alias_champ_fusion", 100);
    }


    function setLib(&$form, $maj) {
    //libelle des champs
        $form->setLib('extra_data_register_def', __('extra_data_register_def'));
        $form->setLib('name', __('name'));
        $form->setLib('description', __('description'));
        $form->setLib('type', __('type'));
        $form->setLib('object_name', __('object_name'));
        $form->setLib('max_length', __('max_length'));
        $form->setLib('alias_champ_fusion', __('alias_champ_fusion'));
    }
    /**
     *
     */
    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 : extra_data_register_values
        $this->rechercheTable($this->f->get_db_reference(), "extra_data_register_values", "definition_ref", $id);
    }


}
