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

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

class parametrage_annexe_gen extends om_dbform {

    protected $_absolute_class_name = "parametrage_annexe";

    var $table = "parametrage_annexe";
    var $clePrimaire = "parametrage_annexe";
    var $typeCle = "N";
    var $required_field = array(
        "document_object_type",
        "document_object_type_id",
        "instruction",
        "parametrage_annexe"
    );
    
    var $foreign_keys_extended = array(
        "instruction" => array("instruction", "instruction_modale", ),
    );
    
    /**
     *
     * @return string
     */
    function get_default_libelle() {
        return $this->getVal($this->clePrimaire)."&nbsp;".$this->getVal("instruction");
    }

    /**
     *
     * @return array
     */
    function get_var_sql_forminc__champs() {
        return array(
            "parametrage_annexe",
            "instruction",
            "document_object_type",
            "document_object_type_id",
            "condition",
        );
    }

    /**
     *
     * @return string
     */
    function get_var_sql_forminc__sql_instruction() {
        return "SELECT instruction.instruction, instruction.destinataire FROM ".DB_PREFIXE."instruction ORDER BY instruction.destinataire ASC";
    }

    /**
     *
     * @return string
     */
    function get_var_sql_forminc__sql_instruction_by_id() {
        return "SELECT instruction.instruction, instruction.destinataire FROM ".DB_PREFIXE."instruction WHERE instruction = <idx>";
    }




    function setvalF($val = array()) {
        //affectation valeur formulaire
        if (!is_numeric($val['parametrage_annexe'])) {
            $this->valF['parametrage_annexe'] = ""; // -> requis
        } else {
            $this->valF['parametrage_annexe'] = $val['parametrage_annexe'];
        }
        if (!is_numeric($val['instruction'])) {
            $this->valF['instruction'] = ""; // -> requis
        } else {
            $this->valF['instruction'] = $val['instruction'];
        }
        $this->valF['document_object_type'] = $val['document_object_type'];
        if (!is_numeric($val['document_object_type_id'])) {
            $this->valF['document_object_type_id'] = ""; // -> requis
        } else {
            $this->valF['document_object_type_id'] = $val['document_object_type_id'];
        }
        if ($val['condition'] == "") {
            $this->valF['condition'] = NULL;
        } else {
            $this->valF['condition'] = $val['condition'];
        }
    }

    //=================================================
    //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("parametrage_annexe", "hidden");
            if ($this->is_in_context_of_foreign_key("instruction", $this->retourformulaire)) {
                $form->setType("instruction", "selecthiddenstatic");
            } else {
                $form->setType("instruction", "select");
            }
            $form->setType("document_object_type", "text");
            $form->setType("document_object_type_id", "text");
            $form->setType("condition", "text");
        }

        // MDOE MODIFIER
        if ($maj == 1 || $crud == 'update') {
            $form->setType("parametrage_annexe", "hiddenstatic");
            if ($this->is_in_context_of_foreign_key("instruction", $this->retourformulaire)) {
                $form->setType("instruction", "selecthiddenstatic");
            } else {
                $form->setType("instruction", "select");
            }
            $form->setType("document_object_type", "text");
            $form->setType("document_object_type_id", "text");
            $form->setType("condition", "text");
        }

        // MODE SUPPRIMER
        if ($maj == 2 || $crud == 'delete') {
            $form->setType("parametrage_annexe", "hiddenstatic");
            $form->setType("instruction", "selectstatic");
            $form->setType("document_object_type", "hiddenstatic");
            $form->setType("document_object_type_id", "hiddenstatic");
            $form->setType("condition", "hiddenstatic");
        }

        // MODE CONSULTER
        if ($maj == 3 || $crud == 'read') {
            $form->setType("parametrage_annexe", "static");
            $form->setType("instruction", "selectstatic");
            $form->setType("document_object_type", "static");
            $form->setType("document_object_type_id", "static");
            $form->setType("condition", "static");
        }

    }


    function setOnchange(&$form, $maj) {
    //javascript controle client
        $form->setOnchange('parametrage_annexe','VerifNum(this)');
        $form->setOnchange('instruction','VerifNum(this)');
        $form->setOnchange('document_object_type_id','VerifNum(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("parametrage_annexe", 11);
        $form->setTaille("instruction", 11);
        $form->setTaille("document_object_type", 30);
        $form->setTaille("document_object_type_id", 11);
        $form->setTaille("condition", 20);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("parametrage_annexe", 11);
        $form->setMax("instruction", 11);
        $form->setMax("document_object_type", 63);
        $form->setMax("document_object_type_id", 11);
        $form->setMax("condition", 20);
    }


    function setLib(&$form, $maj) {
    //libelle des champs
        $form->setLib('parametrage_annexe', __('parametrage_annexe'));
        $form->setLib('instruction', __('instruction'));
        $form->setLib('document_object_type', __('document_object_type'));
        $form->setLib('document_object_type_id', __('document_object_type_id'));
        $form->setLib('condition', __('condition'));
    }
    /**
     *
     */
    function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) {

        // instruction
        $this->init_select(
            $form, 
            $this->f->get_db_reference(),
            $maj,
            null,
            "instruction",
            $this->get_var_sql_forminc__sql("instruction"),
            $this->get_var_sql_forminc__sql("instruction_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('instruction', $this->retourformulaire))
                $form->setVal('instruction', $idxformulaire);
        }// fin validation
        $this->set_form_default_values($form, $maj, $validation);
    }// fin setValsousformulaire

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

}
