<?php
//$Id$ 
//gen openMairie le 03/09/2025 16:43

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

class document_instruction_importe_gen extends om_dbform {

    protected $_absolute_class_name = "document_instruction_importe";

    var $table = "document_instruction_importe";
    var $clePrimaire = "document_instruction_importe";
    var $typeCle = "N";
    var $required_field = array(
        "document_instruction_importe",
        "document_type",
        "dossier",
        "nom_fichier",
        "uid"
    );
    var $unique_key = array(
      "uid",
    );
    var $foreign_keys_extended = array(
        "document_type" => array("document_type", ),
        "dossier" => array("dossier", "dossier_instruction", "dossier_instruction_mes_encours", "dossier_instruction_tous_encours", "dossier_instruction_mes_clotures", "dossier_instruction_tous_clotures", "dossier_contentieux", "dossier_contentieux_mes_infractions", "dossier_contentieux_toutes_infractions", "dossier_contentieux_mes_recours", "dossier_contentieux_tous_recours", "sous_dossier", ),
    );
    
    /**
     *
     * @return string
     */
    function get_default_libelle() {
        return $this->getVal($this->clePrimaire)."&nbsp;".$this->getVal("uid");
    }

    /**
     *
     * @return array
     */
    function get_var_sql_forminc__champs() {
        return array(
            "document_instruction_importe",
            "uid",
            "dossier",
            "nom_fichier",
            "description",
            "document_type",
            "date_creation",
            "date_modification",
            "uid_dossier_final",
            "uid_thumbnail",
        );
    }

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

    /**
     *
     * @return string
     */
    function get_var_sql_forminc__sql_document_type_by_id() {
        return "SELECT document_type.document_type, document_type.libelle FROM ".DB_PREFIXE."document_type WHERE document_type = <idx>";
    }

    /**
     *
     * @return string
     */
    function get_var_sql_forminc__sql_dossier() {
        return "SELECT dossier.dossier, dossier.annee FROM ".DB_PREFIXE."dossier ORDER BY dossier.annee ASC";
    }

    /**
     *
     * @return string
     */
    function get_var_sql_forminc__sql_dossier_by_id() {
        return "SELECT dossier.dossier, dossier.annee FROM ".DB_PREFIXE."dossier WHERE dossier = '<idx>'";
    }




    function setvalF($val = array()) {
        //affectation valeur formulaire
        if (!is_numeric($val['document_instruction_importe'])) {
            $this->valF['document_instruction_importe'] = ""; // -> requis
        } else {
            $this->valF['document_instruction_importe'] = $val['document_instruction_importe'];
        }
        $this->valF['uid'] = $val['uid'];
        $this->valF['dossier'] = $val['dossier'];
        $this->valF['nom_fichier'] = $val['nom_fichier'];
            $this->valF['description'] = $val['description'];
        if (!is_numeric($val['document_type'])) {
            $this->valF['document_type'] = ""; // -> requis
        } else {
            $this->valF['document_type'] = $val['document_type'];
        }
        if ($val['date_creation'] != "") {
            $this->valF['date_creation'] = $this->dateDB($val['date_creation']);
        } else {
            $this->valF['date_creation'] = NULL;
        }
        if ($val['date_modification'] != "") {
            $this->valF['date_modification'] = $this->dateDB($val['date_modification']);
        } else {
            $this->valF['date_modification'] = NULL;
        }
        if ($val['uid_dossier_final'] == 1 || $val['uid_dossier_final'] == "t" || $val['uid_dossier_final'] == "Oui") {
            $this->valF['uid_dossier_final'] = true;
        } else {
            $this->valF['uid_dossier_final'] = false;
        }
        if ($val['uid_thumbnail'] == "") {
            $this->valF['uid_thumbnail'] = NULL;
        } else {
            $this->valF['uid_thumbnail'] = $val['uid_thumbnail'];
        }
    }

    //=================================================
    //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("document_instruction_importe", "hidden");
            $form->setType("uid", "text");
            if ($this->is_in_context_of_foreign_key("dossier", $this->retourformulaire)) {
                $form->setType("dossier", "selecthiddenstatic");
            } else {
                $form->setType("dossier", "select");
            }
            $form->setType("nom_fichier", "text");
            $form->setType("description", "textarea");
            if ($this->is_in_context_of_foreign_key("document_type", $this->retourformulaire)) {
                $form->setType("document_type", "selecthiddenstatic");
            } else {
                $form->setType("document_type", "select");
            }
            $form->setType("date_creation", "date");
            $form->setType("date_modification", "date");
            $form->setType("uid_dossier_final", "checkbox");
            $form->setType("uid_thumbnail", "text");
        }

        // MDOE MODIFIER
        if ($maj == 1 || $crud == 'update') {
            $form->setType("document_instruction_importe", "hiddenstatic");
            $form->setType("uid", "text");
            if ($this->is_in_context_of_foreign_key("dossier", $this->retourformulaire)) {
                $form->setType("dossier", "selecthiddenstatic");
            } else {
                $form->setType("dossier", "select");
            }
            $form->setType("nom_fichier", "text");
            $form->setType("description", "textarea");
            if ($this->is_in_context_of_foreign_key("document_type", $this->retourformulaire)) {
                $form->setType("document_type", "selecthiddenstatic");
            } else {
                $form->setType("document_type", "select");
            }
            $form->setType("date_creation", "date");
            $form->setType("date_modification", "date");
            $form->setType("uid_dossier_final", "checkbox");
            $form->setType("uid_thumbnail", "text");
        }

        // MODE SUPPRIMER
        if ($maj == 2 || $crud == 'delete') {
            $form->setType("document_instruction_importe", "hiddenstatic");
            $form->setType("uid", "hiddenstatic");
            $form->setType("dossier", "selectstatic");
            $form->setType("nom_fichier", "hiddenstatic");
            $form->setType("description", "hiddenstatic");
            $form->setType("document_type", "selectstatic");
            $form->setType("date_creation", "hiddenstatic");
            $form->setType("date_modification", "hiddenstatic");
            $form->setType("uid_dossier_final", "hiddenstatic");
            $form->setType("uid_thumbnail", "hiddenstatic");
        }

        // MODE CONSULTER
        if ($maj == 3 || $crud == 'read') {
            $form->setType("document_instruction_importe", "static");
            $form->setType("uid", "static");
            $form->setType("dossier", "selectstatic");
            $form->setType("nom_fichier", "static");
            $form->setType("description", "textareastatic");
            $form->setType("document_type", "selectstatic");
            $form->setType("date_creation", "datestatic");
            $form->setType("date_modification", "datestatic");
            $form->setType("uid_dossier_final", "checkboxstatic");
            $form->setType("uid_thumbnail", "static");
        }

    }


    function setOnchange(&$form, $maj) {
    //javascript controle client
        $form->setOnchange('document_instruction_importe','VerifNum(this)');
        $form->setOnchange('document_type','VerifNum(this)');
        $form->setOnchange('date_creation','fdate(this)');
        $form->setOnchange('date_modification','fdate(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("document_instruction_importe", 11);
        $form->setTaille("uid", 30);
        $form->setTaille("dossier", 30);
        $form->setTaille("nom_fichier", 30);
        $form->setTaille("description", 80);
        $form->setTaille("document_type", 11);
        $form->setTaille("date_creation", 12);
        $form->setTaille("date_modification", 12);
        $form->setTaille("uid_dossier_final", 1);
        $form->setTaille("uid_thumbnail", 30);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("document_instruction_importe", 11);
        $form->setMax("uid", 255);
        $form->setMax("dossier", 255);
        $form->setMax("nom_fichier", 255);
        $form->setMax("description", 6);
        $form->setMax("document_type", 11);
        $form->setMax("date_creation", 12);
        $form->setMax("date_modification", 12);
        $form->setMax("uid_dossier_final", 1);
        $form->setMax("uid_thumbnail", 255);
    }


    function setLib(&$form, $maj) {
    //libelle des champs
        $form->setLib('document_instruction_importe', __('document_instruction_importe'));
        $form->setLib('uid', __('uid'));
        $form->setLib('dossier', __('dossier'));
        $form->setLib('nom_fichier', __('nom_fichier'));
        $form->setLib('description', __('description'));
        $form->setLib('document_type', __('document_type'));
        $form->setLib('date_creation', __('date_creation'));
        $form->setLib('date_modification', __('date_modification'));
        $form->setLib('uid_dossier_final', __('uid_dossier_final'));
        $form->setLib('uid_thumbnail', __('uid_thumbnail'));
    }
    /**
     *
     */
    function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) {

        // document_type
        $this->init_select(
            $form, 
            $this->f->db,
            $maj,
            null,
            "document_type",
            $this->get_var_sql_forminc__sql("document_type"),
            $this->get_var_sql_forminc__sql("document_type_by_id"),
            true
        );
        // dossier
        $this->init_select(
            $form, 
            $this->f->db,
            $maj,
            null,
            "dossier",
            $this->get_var_sql_forminc__sql("dossier"),
            $this->get_var_sql_forminc__sql("dossier_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('document_type', $this->retourformulaire))
                $form->setVal('document_type', $idxformulaire);
            if($this->is_in_context_of_foreign_key('dossier', $this->retourformulaire))
                $form->setVal('dossier', $idxformulaire);
        }// fin validation
        $this->set_form_default_values($form, $maj, $validation);
    }// fin setValsousformulaire

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

}
