<?php
//$Id$ 
//gen openMairie le 22/01/2026 14:05

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

class courrier_archive_gen extends om_dbform {

    protected $_absolute_class_name = "courrier_archive";

    var $table = "courrier_archive";
    var $clePrimaire = "courrier";
    var $typeCle = "N";
    var $required_field = array(
        "courrier"
    );
    
    var $foreign_keys_extended = array(
    );
    
    /**
     *
     * @return string
     */
    function get_default_libelle() {
        return $this->getVal($this->clePrimaire)."&nbsp;".$this->getVal("destinataire");
    }

    /**
     *
     * @return array
     */
    function get_var_sql_forminc__champs() {
        return array(
            "courrier",
            "destinataire",
            "datecourrier",
            "lettretype",
            "complement",
            "emplacement",
            "contrat",
            "contexte",
            "reprise_abandon",
            "finalise",
            "fichier",
            "date_finalisation",
            "travaux",
        );
    }




    function setvalF($val = array()) {
        //affectation valeur formulaire
        if (!is_numeric($val['courrier'])) {
            $this->valF['courrier'] = ""; // -> requis
        } else {
            $this->valF['courrier'] = $val['courrier'];
        }
        if (!is_numeric($val['destinataire'])) {
            $this->valF['destinataire'] = NULL;
        } else {
            $this->valF['destinataire'] = $val['destinataire'];
        }
        if ($val['datecourrier'] != "") {
            $this->valF['datecourrier'] = $this->dateDB($val['datecourrier']);
        } else {
            $this->valF['datecourrier'] = NULL;
        }
        if ($val['lettretype'] == "") {
            $this->valF['lettretype'] = NULL;
        } else {
            $this->valF['lettretype'] = $val['lettretype'];
        }
            $this->valF['complement'] = $val['complement'];
        if (!is_numeric($val['emplacement'])) {
            $this->valF['emplacement'] = NULL;
        } else {
            $this->valF['emplacement'] = $val['emplacement'];
        }
        if (!is_numeric($val['contrat'])) {
            $this->valF['contrat'] = NULL;
        } else {
            $this->valF['contrat'] = $val['contrat'];
        }
        if ($val['contexte'] == "") {
            $this->valF['contexte'] = NULL;
        } else {
            $this->valF['contexte'] = $val['contexte'];
        }
        if (!is_numeric($val['reprise_abandon'])) {
            $this->valF['reprise_abandon'] = NULL;
        } else {
            $this->valF['reprise_abandon'] = $val['reprise_abandon'];
        }
        if ($val['finalise'] == 1 || $val['finalise'] == "t" || $val['finalise'] == "Oui") {
            $this->valF['finalise'] = true;
        } else {
            $this->valF['finalise'] = false;
        }
        if ($val['fichier'] == "") {
            $this->valF['fichier'] = NULL;
        } else {
            $this->valF['fichier'] = $val['fichier'];
        }
        if ($val['date_finalisation'] != "") {
            $this->valF['date_finalisation'] = $this->dateDB($val['date_finalisation']);
        } else {
            $this->valF['date_finalisation'] = NULL;
        }
        if (!is_numeric($val['travaux'])) {
            $this->valF['travaux'] = NULL;
        } else {
            $this->valF['travaux'] = $val['travaux'];
        }
    }

    //=================================================
    //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("courrier", "hidden");
            $form->setType("destinataire", "text");
            $form->setType("datecourrier", "date");
            $form->setType("lettretype", "text");
            $form->setType("complement", "textarea");
            $form->setType("emplacement", "text");
            $form->setType("contrat", "text");
            $form->setType("contexte", "text");
            $form->setType("reprise_abandon", "text");
            $form->setType("finalise", "checkbox");
            $form->setType("fichier", "text");
            $form->setType("date_finalisation", "date");
            $form->setType("travaux", "text");
        }

        // MDOE MODIFIER
        if ($maj == 1 || $crud == 'update') {
            $form->setType("courrier", "hiddenstatic");
            $form->setType("destinataire", "text");
            $form->setType("datecourrier", "date");
            $form->setType("lettretype", "text");
            $form->setType("complement", "textarea");
            $form->setType("emplacement", "text");
            $form->setType("contrat", "text");
            $form->setType("contexte", "text");
            $form->setType("reprise_abandon", "text");
            $form->setType("finalise", "checkbox");
            $form->setType("fichier", "text");
            $form->setType("date_finalisation", "date");
            $form->setType("travaux", "text");
        }

        // MODE SUPPRIMER
        if ($maj == 2 || $crud == 'delete') {
            $form->setType("courrier", "hiddenstatic");
            $form->setType("destinataire", "hiddenstatic");
            $form->setType("datecourrier", "hiddenstatic");
            $form->setType("lettretype", "hiddenstatic");
            $form->setType("complement", "hiddenstatic");
            $form->setType("emplacement", "hiddenstatic");
            $form->setType("contrat", "hiddenstatic");
            $form->setType("contexte", "hiddenstatic");
            $form->setType("reprise_abandon", "hiddenstatic");
            $form->setType("finalise", "hiddenstatic");
            $form->setType("fichier", "hiddenstatic");
            $form->setType("date_finalisation", "hiddenstatic");
            $form->setType("travaux", "hiddenstatic");
        }

        // MODE CONSULTER
        if ($maj == 3 || $crud == 'read') {
            $form->setType("courrier", "static");
            $form->setType("destinataire", "static");
            $form->setType("datecourrier", "datestatic");
            $form->setType("lettretype", "static");
            $form->setType("complement", "textareastatic");
            $form->setType("emplacement", "static");
            $form->setType("contrat", "static");
            $form->setType("contexte", "static");
            $form->setType("reprise_abandon", "static");
            $form->setType("finalise", "checkboxstatic");
            $form->setType("fichier", "static");
            $form->setType("date_finalisation", "datestatic");
            $form->setType("travaux", "static");
        }

    }


    function setOnchange(&$form, $maj) {
    //javascript controle client
        $form->setOnchange('courrier','VerifNum(this)');
        $form->setOnchange('destinataire','VerifNum(this)');
        $form->setOnchange('datecourrier','fdate(this)');
        $form->setOnchange('emplacement','VerifNum(this)');
        $form->setOnchange('contrat','VerifNum(this)');
        $form->setOnchange('reprise_abandon','VerifNum(this)');
        $form->setOnchange('date_finalisation','fdate(this)');
        $form->setOnchange('travaux','VerifNum(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("courrier", 11);
        $form->setTaille("destinataire", 11);
        $form->setTaille("datecourrier", 12);
        $form->setTaille("lettretype", 30);
        $form->setTaille("complement", 80);
        $form->setTaille("emplacement", 11);
        $form->setTaille("contrat", 11);
        $form->setTaille("contexte", 30);
        $form->setTaille("reprise_abandon", 11);
        $form->setTaille("finalise", 1);
        $form->setTaille("fichier", 30);
        $form->setTaille("date_finalisation", 12);
        $form->setTaille("travaux", 11);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("courrier", 11);
        $form->setMax("destinataire", 11);
        $form->setMax("datecourrier", 12);
        $form->setMax("lettretype", 255);
        $form->setMax("complement", 6);
        $form->setMax("emplacement", 11);
        $form->setMax("contrat", 11);
        $form->setMax("contexte", 255);
        $form->setMax("reprise_abandon", 11);
        $form->setMax("finalise", 1);
        $form->setMax("fichier", 50);
        $form->setMax("date_finalisation", 12);
        $form->setMax("travaux", 11);
    }


    function setLib(&$form, $maj) {
    //libelle des champs
        $form->setLib('courrier', __('courrier'));
        $form->setLib('destinataire', __('destinataire'));
        $form->setLib('datecourrier', __('datecourrier'));
        $form->setLib('lettretype', __('lettretype'));
        $form->setLib('complement', __('complement'));
        $form->setLib('emplacement', __('emplacement'));
        $form->setLib('contrat', __('contrat'));
        $form->setLib('contexte', __('contexte'));
        $form->setLib('reprise_abandon', __('reprise_abandon'));
        $form->setLib('finalise', __('finalise'));
        $form->setLib('fichier', __('fichier'));
        $form->setLib('date_finalisation', __('date_finalisation'));
        $form->setLib('travaux', __('travaux'));
    }
    /**
     *
     */
    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
    //==================================
    

}
