<?php
//$Id$
//gen openMairie le 18/10/2011 11:58
require_once ("../obj/operation.class.php");

class inhumation extends operation {

    var $categorie= 'inhumation';
    // concession

    function inhumation($id,&$db,$DEBUG) {
        $this->constructeur($id,$db,$DEBUG);
    }
    function setType(&$form,$maj) {
        parent::setType($form,$maj);
        if ($maj < 2) { //ajouter et modifier
            $form->setType('defunt_titre','select');
            $form->setType('defunt_nom','text');
            $form->setType('defunt_prenom','text');
            $form->setType('defunt_marital','text');
            $form->setType('defunt_datenaissance','date');
            $form->setType('defunt_datedeces','date');
            $form->setType('defunt_lieudeces','text');
            $form->setType('defunt_nature','select');
        }
        if ($maj == 3) {
            $form->setType('defunt_titre', 'selectstatic');
            $form->setType('defunt_nom', 'hiddenstatic');
            $form->setType('defunt_marital', 'hiddenstatic');
            $form->setType('defunt_prenom', 'hiddenstatic');
            $form->setType('defunt_datenaissance', 'hiddenstaticdate');
            $form->setType('defunt_datedeces', 'hiddenstaticdate');
            $form->setType('defunt_lieudeces', 'hiddenstatic');
            $form->setType('defunt_nature', 'hiddenstatic');
        }
    }

    function setSelect(&$form, $maj,&$db,$debug) {
        //
        parent::setSelect($form, $maj,$db,$debug);
        //
        if(file_exists ("../sql/".$db->phptype."/operation_defunt.form.inc.php")){
            include ("../sql/".$db->phptype."/operation_defunt.form.inc.php");
        }
        // defunt_titre
        $this->init_select($form, $db, $maj, $debug, "defunt_titre",
                           $sql_defunt_titre, $sql_defunt_titre_by_id, true);

        if($maj<2){

            // concession
            $contenu="";
            $contenu[0][0]="emplacement";
            $contenu[0][1]="emplacement";
            $contenu[1][0]="famille";
            $contenu[1][1]="famille";
            $contenu[2][0]="nature";
            $contenu[2][1]="concession";
            $form->setSelect("emplacement",$contenu);

            $contenu="";
            $contenu[0][0]="emplacement";
            $contenu[0][1]="famille";
            $contenu[1][0]="emplacement";
            $contenu[1][1]="emplacement";
            $contenu[2][0]="nature";
            $contenu[2][1]="concession";
            $form->setSelect("famille",$contenu);

            //nature
            $contenu=array();
            $contenu[0]=array('cercueil','zinc','urne');
            $contenu[1]=array(_('cercueil'),_("cercueil_zinc"),_("urne"));
            $form->setSelect("defunt_nature",$contenu);
        }
    }

    function setOnchange(&$form,$maj){
        parent::setOnchange($form,$maj);
        $form->setOnchange("defunt_nom","this.value=this.value.toUpperCase();");
        $form->setOnchange("defunt_prenom","this.value=this.value.toUpperCase();");
        $form->setOnchange("defunt_lieudeces","this.value=this.value.toUpperCase();");
        $form->setOnchange("defunt_marital","this.value=this.value.toUpperCase();");
        $form->setOnchange('defunt_datenaissance','fdate(this)');
        $form->setOnchange('defunt_datedeces','fdate(this)');
    }

    function setLib(&$form,$maj) {
        parent::setLib($form,$maj);
        $form->setLib('defunt_titre',"");
        $form->setLib('defunt_nom',_("nom"));
        $form->setLib('defunt_marital',_("epouse"));
        $form->setLib('defunt_prenom',_("prenom"));
        $form->setLib('defunt_datenaissance',_("ne(e) le"));
        $form->setLib('defunt_datedeces',_("decede le"));
        $form->setLib('defunt_lieudeces',_("a"));
        $form->setLib('defunt_nature',"");
    }

    function setGroupe(&$form,$maj){
       parent::setGroupe($form,$maj);
       /*  $form->setGroupe('defunt_titre','D');
        $form->setGroupe('defunt_nom','G');
        $form->setGroupe('defunt_marital','G');
        $form->setGroupe('defunt_prenom','F');

        $form->setGroupe('defunt_datenaissance','D');
        $form->setGroupe('defunt_datedeces','G');
        $form->setGroupe('defunt_lieudeces','G');
        $form->setGroupe('defunt_nature','F');*/
    }

    function setRegroupe (&$form, $maj) {
        parent::setRegroupe ($form, $maj);
        /* $form->setRegroupe('defunt_nom','G','');
        $form->setRegroupe('defunt_prenom','G','');
        $form->setRegroupe('defunt_marital','G','');
        $form->setRegroupe('defunt_datenaissance','G','');
        $form->setRegroupe('defunt_datedeces','G','');
        $form->setRegroupe('defunt_lieudeces','G','');
        $form->setRegroupe('defunt_nature','F','');*/
    }
  
    function triggerajouterapres($id,&$db,$val,$DEBUG){
        // creation du defunt
        $valF["operation_defunt"]=$db->nextId(DB_PREFIXE."operation_defunt");
        $valF['operation'] = $this->valF["operation"];
        $valF['defunt_titre'] = $val['defunt_titre'];
        if ($valF['defunt_titre'] == "") {
            $valF['defunt_titre'] = null;
        }
        $valF['defunt_nom'] = $val['defunt_nom'];
        $valF['defunt_marital'] = $val['defunt_marital'];
        $valF['defunt_prenom'] = $val['defunt_prenom'];
        //
        if ($val['defunt_datenaissance'] != "") {
            $valF['defunt_datenaissance'] = $this->dateDB($val['defunt_datenaissance']);
        } else {
            $valF['defunt_datenaissance'] = NULL;
        }
        //
        if ($val['defunt_datedeces'] != "") {
            $valF['defunt_datedeces'] = $this->dateDB($val['defunt_datedeces']);
        } else {
            $valF['defunt_datedeces'] = NULL;
        }
        $valF['defunt_lieudeces'] = $val['defunt_lieudeces'];
        $valF['defunt_nature'] = $val['defunt_nature'];
        $res= $db->autoExecute(DB_PREFIXE."operation_defunt",$valF,DB_AUTOQUERY_INSERT);
        if($this->f->isDatabaseError($res, true)){
            return false;
        }
        $this->addToMessage(_("Enregistrement ").
                   $valF["operation_defunt"]." de la table operation_defunt [".$db->affectedRows().
            " "._("ajoute")."]") ;

        return true;
    }

    function triggermodifierapres($id,&$db,$val,$DEBUG){
        // modification du defunt
        $valF['defunt_titre'] = $val['defunt_titre'];
        if ($valF['defunt_titre'] == "") {
            $valF['defunt_titre'] = null;
        }
        $valF['defunt_nom'] = $val['defunt_nom'];
        $valF['defunt_marital'] = $val['defunt_marital'];
        $valF['defunt_prenom'] = $val['defunt_prenom'];
        //
        if ($val['defunt_datenaissance'] != "") {
            $valF['defunt_datenaissance'] = $this->dateDB($val['defunt_datenaissance']);
        } else {
            $valF['defunt_datenaissance'] = NULL;
        }
        //
        if ($val['defunt_datedeces'] != "") {
            $valF['defunt_datedeces'] = $this->dateDB($val['defunt_datedeces']);
        } else {
            $valF['defunt_datedeces'] = NULL;
        }
        $valF['defunt_lieudeces'] = $val['defunt_lieudeces'];
        $valF['defunt_nature'] = $val['defunt_nature'];
        // a voir type de cercueil
        $cle= "operation =".$this->valF["operation"];
        $res= $db->autoExecute(DB_PREFIXE."operation_defunt",$valF,DB_AUTOQUERY_UPDATE,$cle);
        if($this->f->isDatabaseError($res, true)){
            return false;
        }
        $this->addToMessage(_("Enregistrement ").
                   $id." de la table operation_defunt [".$db->affectedRows().
            " "._("modifie")."]") ;

        return true;
    }


}// fin classe
?>