<?php
//$Id$ 
//gen openMairie le 20/09/2013 15:51

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 $retourformulaire;

    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(&$db) {
    //numero automatique
        $this->valF[$this->clePrimaire] = $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) {
        //type
        if ($maj==0){ //ajout
            $form->setType('defunt','hidden');// cle automatique
            $form->setType('nature','text');
            $form->setType('taille','text');

            if($this->retourformulaire=='emplacement'
               and $form->val['emplacement'] == $this->getParameter('idxformulaire')) {
                $form->setType('emplacement','selecthiddenstatic');
            } else {
                $form->setType('emplacement','select');
            }

            if($this->retourformulaire=='titre_de_civilite'
               and $form->val['titre'] == $this->getParameter('idxformulaire')) {
                $form->setType('titre','selecthiddenstatic');
            } else {
                $form->setType('titre','select');
            }
            $form->setType('nom','text');
            $form->setType('prenom','text');
            $form->setType('marital','text');
            if($this->retourformulaire=='')
                $form->setType('datenaissance','date');
            else
                $form->setType('datenaissance','date2');
            if($this->retourformulaire=='')
                $form->setType('datedeces','date');
            else
                $form->setType('datedeces','date2');
            $form->setType('lieudeces','text');
            if($this->retourformulaire=='')
                $form->setType('dateinhumation','date');
            else
                $form->setType('dateinhumation','date2');
            $form->setType('exhumation','text');
            if($this->retourformulaire=='')
                $form->setType('dateexhumation','date');
            else
                $form->setType('dateexhumation','date2');
            $form->setType('observation','textarea');
            $form->setType('reduction','text');
            if($this->retourformulaire=='')
                $form->setType('datereduction','date');
            else
                $form->setType('datereduction','date2');
            $form->setType('historique','textarea');
            $form->setType('verrou','text');
        }// fin ajout
        if ($maj==1){ //modifier
            $form->setType('defunt','hiddenstatic');
            $form->setType('nature','text');
            $form->setType('taille','text');

            if($this->retourformulaire=='emplacement'
               and $form->val['emplacement'] == $this->getParameter('idxformulaire')) {
                $form->setType('emplacement','selecthiddenstatic');
            } else {
                $form->setType('emplacement','select');
            }

            if($this->retourformulaire=='titre_de_civilite'
               and $form->val['titre'] == $this->getParameter('idxformulaire')) {
                $form->setType('titre','selecthiddenstatic');
            } else {
                $form->setType('titre','select');
            }
            $form->setType('nom','text');
            $form->setType('prenom','text');
            $form->setType('marital','text');
            if($this->retourformulaire=='')
                $form->setType('datenaissance','date');
            else
                $form->setType('datenaissance','date2');
            if($this->retourformulaire=='')
                $form->setType('datedeces','date');
            else
                $form->setType('datedeces','date2');
            $form->setType('lieudeces','text');
            if($this->retourformulaire=='')
                $form->setType('dateinhumation','date');
            else
                $form->setType('dateinhumation','date2');
            $form->setType('exhumation','text');
            if($this->retourformulaire=='')
                $form->setType('dateexhumation','date');
            else
                $form->setType('dateexhumation','date2');
            $form->setType('observation','textarea');
            $form->setType('reduction','text');
            if($this->retourformulaire=='')
                $form->setType('datereduction','date');
            else
                $form->setType('datereduction','date2');
            $form->setType('historique','textarea');
            $form->setType('verrou','text');
        }// fin modifier
        if ($maj==2){ //supprimer
            $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');
        }//fin supprimer
        if ($maj==3){ //consulter
            $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');
        }//fin consulter
    }

    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,&$db,$debug) {
        if(file_exists ("../sql/".$db->phptype."/".$this->table.".form.inc.php"))
            include ("../sql/".$db->phptype."/".$this->table.".form.inc.php");
        elseif(file_exists ("../sql/".$db->phptype."/".$this->table.".form.inc"))
            include ("../sql/".$db->phptype."/".$this->table.".form.inc");

        // emplacement
        $this->init_select($form, $db, $maj, $debug, "emplacement",
                           $sql_emplacement, $sql_emplacement_by_id, false);

        // titre
        $this->init_select($form, $db, $maj, $debug, "titre",
                           $sql_titre, $sql_titre_by_id, true);
    }// fin select

    //==================================
    // sous Formulaire  [subform]
    //==================================

    function setValsousformulaire(&$form,$maj,$validation,$idxformulaire,$retourformulaire,$typeformulaire,&$db,$DEBUG=null){
        $this->retourformulaire = $retourformulaire;
        if($validation == 0) {
            if($retourformulaire =='emplacement')
                $form->setVal('emplacement', $idxformulaire);
            if($retourformulaire =='titre_de_civilite')
                $form->setVal('titre', $idxformulaire);
        }// fin validation
    }// fin setValsousformulaire

    //==================================
    // cle secondaire  [secondary key]
    //==================================
    /**
     * Methode clesecondaire
     */
    function cleSecondaire($id, &$db = NULL, $val = array(), $DEBUG = false) {
        // On appelle la methode de la classe parent
        parent::cleSecondaire($id, $db, $val, $DEBUG);
        // Verification de la cle secondaire : operation_defunt
        $this->rechercheTable($db, "operation_defunt", "defunt", $id);
    }


}// fin classe
?>