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

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

class lien_instruction_signataire_validateur_gen extends om_dbform {

    protected $_absolute_class_name = "lien_instruction_signataire_validateur";

    var $table = "lien_instruction_signataire_validateur";
    var $clePrimaire = "lien_instruction_signataire_validateur";
    var $typeCle = "N";
    var $required_field = array(
        "instruction",
        "lien_instruction_signataire_validateur",
        "signataire_arrete"
    );
    
    var $foreign_keys_extended = array(
        "instruction" => array("instruction", "instruction_modale", ),
        "signataire_arrete" => array("signataire_arrete", ),
    );
    
    /**
     *
     * @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(
            "lien_instruction_signataire_validateur",
            "instruction",
            "signataire_arrete",
            "rang",
        );
    }

    /**
     *
     * @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>";
    }

    /**
     *
     * @return string
     */
    function get_var_sql_forminc__sql_signataire_arrete() {
        return "SELECT signataire_arrete.signataire_arrete, signataire_arrete.civilite FROM ".DB_PREFIXE."signataire_arrete WHERE ((signataire_arrete.om_validite_debut IS NULL AND (signataire_arrete.om_validite_fin IS NULL OR signataire_arrete.om_validite_fin > CURRENT_DATE)) OR (signataire_arrete.om_validite_debut <= CURRENT_DATE AND (signataire_arrete.om_validite_fin IS NULL OR signataire_arrete.om_validite_fin > CURRENT_DATE))) ORDER BY signataire_arrete.civilite ASC";
    }

    /**
     *
     * @return string
     */
    function get_var_sql_forminc__sql_signataire_arrete_by_id() {
        return "SELECT signataire_arrete.signataire_arrete, signataire_arrete.civilite FROM ".DB_PREFIXE."signataire_arrete WHERE signataire_arrete = <idx>";
    }




    function setvalF($val = array()) {
        //affectation valeur formulaire
        if (!is_numeric($val['lien_instruction_signataire_validateur'])) {
            $this->valF['lien_instruction_signataire_validateur'] = ""; // -> requis
        } else {
            $this->valF['lien_instruction_signataire_validateur'] = $val['lien_instruction_signataire_validateur'];
        }
        if (!is_numeric($val['instruction'])) {
            $this->valF['instruction'] = ""; // -> requis
        } else {
            $this->valF['instruction'] = $val['instruction'];
        }
        if (!is_numeric($val['signataire_arrete'])) {
            $this->valF['signataire_arrete'] = ""; // -> requis
        } else {
            $this->valF['signataire_arrete'] = $val['signataire_arrete'];
        }
        if (!is_numeric($val['rang'])) {
            $this->valF['rang'] = 0; // -> default
        } else {
            $this->valF['rang'] = $val['rang'];
        }
    }

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

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

        // MODE SUPPRIMER
        if ($maj == 2 || $crud == 'delete') {
            $form->setType("lien_instruction_signataire_validateur", "hiddenstatic");
            $form->setType("instruction", "selectstatic");
            $form->setType("signataire_arrete", "selectstatic");
            $form->setType("rang", "hiddenstatic");
        }

        // MODE CONSULTER
        if ($maj == 3 || $crud == 'read') {
            $form->setType("lien_instruction_signataire_validateur", "static");
            $form->setType("instruction", "selectstatic");
            $form->setType("signataire_arrete", "selectstatic");
            $form->setType("rang", "static");
        }

    }


    function setOnchange(&$form, $maj) {
    //javascript controle client
        $form->setOnchange('lien_instruction_signataire_validateur','VerifNum(this)');
        $form->setOnchange('instruction','VerifNum(this)');
        $form->setOnchange('signataire_arrete','VerifNum(this)');
        $form->setOnchange('rang','VerifNum(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("lien_instruction_signataire_validateur", 11);
        $form->setTaille("instruction", 11);
        $form->setTaille("signataire_arrete", 11);
        $form->setTaille("rang", 11);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("lien_instruction_signataire_validateur", 11);
        $form->setMax("instruction", 11);
        $form->setMax("signataire_arrete", 11);
        $form->setMax("rang", 11);
    }


    function setLib(&$form, $maj) {
    //libelle des champs
        $form->setLib('lien_instruction_signataire_validateur', __('lien_instruction_signataire_validateur'));
        $form->setLib('instruction', __('instruction'));
        $form->setLib('signataire_arrete', __('signataire_arrete'));
        $form->setLib('rang', __('rang'));
    }
    /**
     *
     */
    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
        );
        // signataire_arrete
        $this->init_select(
            $form, 
            $this->f->get_db_reference(),
            $maj,
            null,
            "signataire_arrete",
            $this->get_var_sql_forminc__sql("signataire_arrete"),
            $this->get_var_sql_forminc__sql("signataire_arrete_by_id"),
            true
        );
    }


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

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

}
