<?php
//$Id$ 
//gen openMairie le 16/12/2015 11:14

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

class defunt_gen extends om_dbform {

    var $table = "defunt";
    var $clePrimaire = "defunt";
    var $typeCle = "N";
    var $required_field = array(
        "defunt"
    );
    
    var $foreign_keys_extended = array(
        "emplacement" => array("emplacement", ),
        "titre_de_civilite" => array("titre_de_civilite", ),
    );



    function setvalF($val) {
        //affectation valeur formulaire
        if (!is_numeric($val['defunt'])) {
            $this->valF['defunt'] = ""; // -> requis
        } else {
            $this->valF['defunt'] = $val['defunt'];
        }
        if ($val['nature'] == "") {
            $this->valF['nature'] = NULL;
        } else {
            $this->valF['nature'] = $val['nature'];
        }
        if (!is_numeric($val['taille'])) {
            $this->valF['taille'] = NULL;
        } else {
            $this->valF['taille'] = $val['taille'];
        }
        if (!is_numeric($val['emplacement'])) {
            $this->valF['emplacement'] = NULL;
        } else {
            $this->valF['emplacement'] = $val['emplacement'];
        }
        if (!is_numeric($val['titre'])) {
            $this->valF['titre'] = NULL;
        } else {
            $this->valF['titre'] = $val['titre'];
        }
        if ($val['nom'] == "") {
            $this->valF['nom'] = NULL;
        } else {
            $this->valF['nom'] = $val['nom'];
        }
        if ($val['prenom'] == "") {
            $this->valF['prenom'] = NULL;
        } else {
            $this->valF['prenom'] = $val['prenom'];
        }
        if ($val['marital'] == "") {
            $this->valF['marital'] = NULL;
        } else {
            $this->valF['marital'] = $val['marital'];
        }
        if ($val['datenaissance'] != "") {
            $this->valF['datenaissance'] = $this->dateDB($val['datenaissance']);
        } else {
            $this->valF['datenaissance'] = NULL;
        }
        if ($val['datedeces'] != "") {
            $this->valF['datedeces'] = $this->dateDB($val['datedeces']);
        } else {
            $this->valF['datedeces'] = NULL;
        }
        if ($val['lieudeces'] == "") {
            $this->valF['lieudeces'] = NULL;
        } else {
            $this->valF['lieudeces'] = $val['lieudeces'];
        }
        if ($val['dateinhumation'] != "") {
            $this->valF['dateinhumation'] = $this->dateDB($val['dateinhumation']);
        } else {
            $this->valF['dateinhumation'] = NULL;
        }
        if ($val['exhumation'] == "") {
            $this->valF['exhumation'] = NULL;
        } else {
            $this->valF['exhumation'] = $val['exhumation'];
        }
        if ($val['dateexhumation'] != "") {
            $this->valF['dateexhumation'] = $this->dateDB($val['dateexhumation']);
        } else {
            $this->valF['dateexhumation'] = NULL;
        }
            $this->valF['observation'] = $val['observation'];
        if ($val['reduction'] == "") {
            $this->valF['reduction'] = NULL;
        } else {
            $this->valF['reduction'] = $val['reduction'];
        }
        if ($val['datereduction'] != "") {
            $this->valF['datereduction'] = $this->dateDB($val['datereduction']);
        } else {
            $this->valF['datereduction'] = NULL;
        }
            $this->valF['historique'] = $val['historique'];
        if ($val['verrou'] == "") {
            $this->valF['verrou'] = NULL;
        } else {
            $this->valF['verrou'] = $val['verrou'];
        }
    }

    //=================================================
    //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) {
    //numero automatique -> pas de controle ajout cle primaire
    }

    function verifierAjout() {
    //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("defunt", "hidden");
            $form->setType("nature", "text");
            $form->setType("taille", "text");
            if ($this->is_in_context_of_foreign_key("emplacement", $this->retourformulaire)) {
                $form->setType("emplacement", "selecthiddenstatic");
            } else {
                $form->setType("emplacement", "select");
            }
            if ($this->is_in_context_of_foreign_key("titre_de_civilite", $this->retourformulaire)) {
                $form->setType("titre", "selecthiddenstatic");
            } else {
                $form->setType("titre", "select");
            }
            $form->setType("nom", "text");
            $form->setType("prenom", "text");
            $form->setType("marital", "text");
            $form->setType("datenaissance", "date");
            $form->setType("datedeces", "date");
            $form->setType("lieudeces", "text");
            $form->setType("dateinhumation", "date");
            $form->setType("exhumation", "text");
            $form->setType("dateexhumation", "date");
            $form->setType("observation", "textarea");
            $form->setType("reduction", "text");
            $form->setType("datereduction", "date");
            $form->setType("historique", "textarea");
            $form->setType("verrou", "text");
        }

        // MDOE MODIFIER
        if ($maj == 1 || $crud == 'update') {
            $form->setType("defunt", "hiddenstatic");
            $form->setType("nature", "text");
            $form->setType("taille", "text");
            if ($this->is_in_context_of_foreign_key("emplacement", $this->retourformulaire)) {
                $form->setType("emplacement", "selecthiddenstatic");
            } else {
                $form->setType("emplacement", "select");
            }
            if ($this->is_in_context_of_foreign_key("titre_de_civilite", $this->retourformulaire)) {
                $form->setType("titre", "selecthiddenstatic");
            } else {
                $form->setType("titre", "select");
            }
            $form->setType("nom", "text");
            $form->setType("prenom", "text");
            $form->setType("marital", "text");
            $form->setType("datenaissance", "date");
            $form->setType("datedeces", "date");
            $form->setType("lieudeces", "text");
            $form->setType("dateinhumation", "date");
            $form->setType("exhumation", "text");
            $form->setType("dateexhumation", "date");
            $form->setType("observation", "textarea");
            $form->setType("reduction", "text");
            $form->setType("datereduction", "date");
            $form->setType("historique", "textarea");
            $form->setType("verrou", "text");
        }

        // MODE SUPPRIMER
        if ($maj == 2 || $crud == 'delete') {
            $form->setType("defunt", "hiddenstatic");
            $form->setType("nature", "hiddenstatic");
            $form->setType("taille", "hiddenstatic");
            $form->setType("emplacement", "selectstatic");
            $form->setType("titre", "selectstatic");
            $form->setType("nom", "hiddenstatic");
            $form->setType("prenom", "hiddenstatic");
            $form->setType("marital", "hiddenstatic");
            $form->setType("datenaissance", "hiddenstatic");
            $form->setType("datedeces", "hiddenstatic");
            $form->setType("lieudeces", "hiddenstatic");
            $form->setType("dateinhumation", "hiddenstatic");
            $form->setType("exhumation", "hiddenstatic");
            $form->setType("dateexhumation", "hiddenstatic");
            $form->setType("observation", "hiddenstatic");
            $form->setType("reduction", "hiddenstatic");
            $form->setType("datereduction", "hiddenstatic");
            $form->setType("historique", "hiddenstatic");
            $form->setType("verrou", "hiddenstatic");
        }

        // MODE CONSULTER
        if ($maj == 3 || $crud == 'read') {
            $form->setType("defunt", "static");
            $form->setType("nature", "static");
            $form->setType("taille", "static");
            $form->setType("emplacement", "selectstatic");
            $form->setType("titre", "selectstatic");
            $form->setType("nom", "static");
            $form->setType("prenom", "static");
            $form->setType("marital", "static");
            $form->setType("datenaissance", "datestatic");
            $form->setType("datedeces", "datestatic");
            $form->setType("lieudeces", "static");
            $form->setType("dateinhumation", "datestatic");
            $form->setType("exhumation", "static");
            $form->setType("dateexhumation", "datestatic");
            $form->setType("observation", "textareastatic");
            $form->setType("reduction", "static");
            $form->setType("datereduction", "datestatic");
            $form->setType("historique", "textareastatic");
            $form->setType("verrou", "static");
        }

    }


    function setOnchange(&$form, $maj) {
    //javascript controle client
        $form->setOnchange('defunt','VerifNum(this)');
        $form->setOnchange('taille','VerifFloat(this)');
        $form->setOnchange('emplacement','VerifNum(this)');
        $form->setOnchange('titre','VerifNum(this)');
        $form->setOnchange('datenaissance','fdate(this)');
        $form->setOnchange('datedeces','fdate(this)');
        $form->setOnchange('dateinhumation','fdate(this)');
        $form->setOnchange('dateexhumation','fdate(this)');
        $form->setOnchange('datereduction','fdate(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("defunt", 11);
        $form->setTaille("nature", 15);
        $form->setTaille("taille", 20);
        $form->setTaille("emplacement", 20);
        $form->setTaille("titre", 11);
        $form->setTaille("nom", 30);
        $form->setTaille("prenom", 30);
        $form->setTaille("marital", 30);
        $form->setTaille("datenaissance", 12);
        $form->setTaille("datedeces", 12);
        $form->setTaille("lieudeces", 30);
        $form->setTaille("dateinhumation", 12);
        $form->setTaille("exhumation", 10);
        $form->setTaille("dateexhumation", 12);
        $form->setTaille("observation", 80);
        $form->setTaille("reduction", 10);
        $form->setTaille("datereduction", 12);
        $form->setTaille("historique", 80);
        $form->setTaille("verrou", 10);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("defunt", 11);
        $form->setMax("nature", 15);
        $form->setMax("taille", 20);
        $form->setMax("emplacement", 20);
        $form->setMax("titre", 11);
        $form->setMax("nom", 40);
        $form->setMax("prenom", 40);
        $form->setMax("marital", 40);
        $form->setMax("datenaissance", 12);
        $form->setMax("datedeces", 12);
        $form->setMax("lieudeces", 40);
        $form->setMax("dateinhumation", 12);
        $form->setMax("exhumation", 3);
        $form->setMax("dateexhumation", 12);
        $form->setMax("observation", 6);
        $form->setMax("reduction", 3);
        $form->setMax("datereduction", 12);
        $form->setMax("historique", 6);
        $form->setMax("verrou", 3);
    }


    function setLib(&$form, $maj) {
    //libelle des champs
        $form->setLib('defunt',_('defunt'));
        $form->setLib('nature',_('nature'));
        $form->setLib('taille',_('taille'));
        $form->setLib('emplacement',_('emplacement'));
        $form->setLib('titre',_('titre'));
        $form->setLib('nom',_('nom'));
        $form->setLib('prenom',_('prenom'));
        $form->setLib('marital',_('marital'));
        $form->setLib('datenaissance',_('datenaissance'));
        $form->setLib('datedeces',_('datedeces'));
        $form->setLib('lieudeces',_('lieudeces'));
        $form->setLib('dateinhumation',_('dateinhumation'));
        $form->setLib('exhumation',_('exhumation'));
        $form->setLib('dateexhumation',_('dateexhumation'));
        $form->setLib('observation',_('observation'));
        $form->setLib('reduction',_('reduction'));
        $form->setLib('datereduction',_('datereduction'));
        $form->setLib('historique',_('historique'));
        $form->setLib('verrou',_('verrou'));
    }
    /**
     *
     */
    function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) {

        // Inclusion du fichier de requêtes
        if (file_exists("../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc.php")) {
            include "../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc.php";
        } elseif (file_exists("../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc")) {
            include "../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc";
        }

        // emplacement
        $this->init_select($form, $this->f->db, $maj, null, "emplacement", $sql_emplacement, $sql_emplacement_by_id, false);
        // titre
        $this->init_select($form, $this->f->db, $maj, null, "titre", $sql_titre, $sql_titre_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('emplacement', $this->retourformulaire))
                $form->setVal('emplacement', $idxformulaire);
            if($this->is_in_context_of_foreign_key('titre_de_civilite', $this->retourformulaire))
                $form->setVal('titre', $idxformulaire);
        }// fin validation
        $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 : operation_defunt
        $this->rechercheTable($this->f->db, "operation_defunt", "defunt", $id);
    }


}

?>
