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

class operation extends operation_gen {

    //var $clePrimaire='operation.operation'; // surcharge operation_gen

    var $id;                                // gestion de l identifiant $id
    // ************************************************************************************************************
    //                     Probleme de gestion de cle primaire en lien avec table fille
    //                     ============================================================
    // la cle operation provoque une erreur de champ ambigu avec operation_defunt dans le select constructeur
    // du fait de l utilisation de la cle primaire operation pour la recherche dans la table fille operation_defunt
    // ce probleme est resolu par la surcharge des methodes de dbformdyn suivantes
    // -> surcharge de getcle
    // -> surcharge de clesecondaire -> destruction operation_defunt en trigger
    // reste a regler dans openMairie dbeformdyn.class.php : $id = $val[$this->clePrimaire]; sinon on a l erreur
    //    Notice: Undefined index: val[operation.operation] in
    //      /var/www/opencimetiere/trunk/php/openmairie/dbformdyn.class.php on line 336 dans methode modifier
    //      /var/www/opencimetiere/trunk/php/openmairie/dbformdyn.class.php on line 398 dans methode supprimer
    // *************************************************************************************************************

    function getCle($id = "") {
        // gestion de la cle primaire pour methode modifier et supprimer
        $cle=" operation  = ".$this->id;
        return $cle;
    }

    function cleSecondaire($id, &$db = NULL, $val = array(), $DEBUG = false) {
        // Initialisation de l'attribut correct a true
        $this->correct = true;
        // initialisation de $this->id pour getCle de supprimer
        $this->id=$val['operation'];
    }

    function setvalF($val) {
        parent ::setvalF($val) ;
        unset($this->valF['entreprise']);
        // enregistrement operation_defunt
        unset($this->valF['defunt_titre']);
        unset($this->valF['defunt_nom']);
        unset($this->valF['defunt_marital']);
        unset($this->valF['defunt_prenom']);
        unset($this->valF['defunt_datenaissance']);
        unset($this->valF['defunt_datedeces']);
        unset($this->valF['defunt_lieudeces']);
        unset($this->valF['defunt_nature']);
        if(!is_numeric($val['emplacement_transfert'])) unset($this->valF['emplacement_transfert']);
        // *** gestion de la cle primaire ***
        // re-initialisation de la cle pour la methode ajouter -> message
        $this->clePrimaire = 'operation';
        // initialisation de la cle pour la methode modifier
        $this->id=$val['operation'];
        // ***
    }

    function verifier($val,&$db,$DEBUG){
        // le numerodossier est automatique -> pas d appel a la methode parent
        $this->correct = true;
        if ($this->valF['date'] == "") {
            $this->correct = false;
            $this->addToMessage("<br />"._("Le champ")." "._("date")." "._("est obligatoire"));
        }

        if ($this->valF['heure'] == "") {
            $this->correct = false;
            $this->addToMessage("<br />"._("Le champ")." "._("heure")." "._("est obligatoire"));
        }

        // *** ajout fr
        if ($this->valF['emplacement'] == "") {
            $this->correct = false;
            $this->addToMessage("<br />"._("Le champ")." "._("emplacement")." "._("est obligatoire"));
        } // ***
    }

    function setType(&$form,$maj) {
        parent::setType($form,$maj);
        if ($maj < 2) { //ajouter et modifier
            $form->setType('numdossier', 'hiddenstatic'); // registre a terme
            $form->setType('famille','comboG');
            $form->setType('emplacement', 'comboD'); // pb de cle numerique
            $form->setType('entreprise', 'select');
            $form->setType('societe_coordonnee', 'textareamulti');
            $form->setType('pf', 'select');
            $form->setType('pf_coordonnee', 'textareamulti');
            $form->setType('etat', 'hiddenstatic');
            $form->setType('particulier', 'checkbox');
            $form->setType('categorie', 'hiddenstatic');

            $form->setType('defunt_titre', 'hidden');
            $form->setType('defunt_nom', 'hidden');
            $form->setType('defunt_marital', 'hidden');
            $form->setType('defunt_prenom', 'hidden');
            $form->setType('defunt_datenaissance', 'hidden');
            $form->setType('defunt_datedeces', 'hidden');
            $form->setType('defunt_lieudeces', 'hidden');
            $form->setType('defunt_nature', 'hidden');

            $form->setType('emplacement_transfert', 'hidden');
            $form->setType('emplacement_transfert_famille', 'hidden');
        }
        if ($maj == 3) {
            $form->setType('defunt_titre', 'hidden');
            $form->setType('defunt_nom', 'hidden');
            $form->setType('defunt_marital', 'hidden');
            $form->setType('defunt_prenom', 'hidden');
            $form->setType('defunt_datenaissance', 'hidden');
            $form->setType('defunt_datedeces', 'hidden');
            $form->setType('defunt_lieudeces', 'hidden');
            $form->setType('defunt_nature', 'hidden');

            $form->setType('emplacement_transfert', 'hidden');
            $form->setType('emplacement_transfert_famille', 'hidden');
            
            $form->setType('etat', 'hidden');
            $form->setType('observation', 'hidden');
            $form->setType('categorie', 'hidden');

            $form->setType('emplacement','static');
        }
    }


    function setVal(&$form, $maj, $validation, &$db, $DEBUG = false) {
        if ($validation == 0) {
            if ($maj == 0){
                $form->setVal('categorie', $this->categorie);
                $form->setVal('etat', "actif");
                $form->setVal('date', date('Y-m-d'));
                $form->setVal('operation.operation', 0); // initialisation
            }
        }
    }

    function setSelect(&$form, $maj,$db,$debug) {
        if($maj<2){
            if(file_exists ("../sql/".$db->phptype."/".$this->table.".form.inc.php"))
                include ("../sql/".$db->phptype."/".$this->table.".form.inc.php");

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

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

            // entreprise_coordonnee
            $contenu = array();
            $res = $db->query($sql_entreprise);
            if (database::isError($res))
                die($res->getMessage().$sql);
            else{
                $contenu[0][0]='';
                $contenu[1][0]=_('choisir')."&nbsp;"._('entreprise');
                $k=1;
                while ($row=& $res->fetchRow()){
                     $contenu[0][$k] = $row[0];
                     $contenu[1][$k] = $row[1];
                     $k++;
                }
                $form->setSelect("entreprise",$contenu);
            }
            // multi
            $contenu=array();
            $contenu[0] ="entreprise";
            $form->setSelect("societe_coordonnee",$contenu);

            // pf_coordonnee
            $contenu = array();
            $res = $db->query($sql_pf);
            if (database::isError($res))
                die($res->getMessage().$sql);
            else{
                $contenu[0][0]='';
                $contenu[1][0]=_('choisir')."&nbsp;"._('pf');
                $k=1;
                while ($row=& $res->fetchRow()){
                     $contenu[0][$k] = $row[0];
                     $contenu[1][$k] = $row[1];
                     $k++;
                }
                $form->setSelect("pf",$contenu);
            }
            // multi
            $contenu=array();
            $contenu[0] ="pf";
            $form->setSelect("pf_coordonnee",$contenu);
        }
    }

    function setOnchange(&$form,$maj){
        parent::setOnchange($form,$maj);
        $form->setOnchange("famille","this.value=this.value.toUpperCase();");
        $form->setOnchange('heure','ftime(this)');
    }

    function setLib(&$form,$maj) {
        $form->setLib('emplacement',_("emplacement"));
        $form->setLib('heure',_("heure"));
        $form->setLib('famille',_("famille"));
        $form->setLib('operation',_("operation"));
        $form->setLib('date',_("date"));
        $form->setLib('etat',_("etat"));
        $form->setLib('numdossier',_("numdossier"));
        $form->setLib('societe_coordonnee',"");
        $form->setLib('pf_coordonnee',"");
        // Libellé différent pour la consultation et pour la suppression
        // que pour l'ajout et la modification
        if ($maj == 3 || $maj == 2) {
            $form->setLib('entreprise', _("entreprise"));
            $form->setLib('pf', _("pompe funebre"));
        } else {
            $form->setLib('entreprise', _("votre choix et validation  bouton ci-dessous"));
            $form->setLib('pf', _("votre choix et validation  bouton ci-dessous"));
        }
    }

    function setGroupe(&$form,$maj){
        /*$form->setGroupe('date','D');
        $form->setGroupe('heure','F');*/

        /*$form->setGroupe('emplacement','D');
        $form->setGroupe('famille','F');*
        /*$form->setGroupe('entreprise','D');
        $form->setGroupe('societe_coordonnee','F');
        $form->setGroupe('pf','D');
        $form->setGroupe('pf_coordonnee','F');*/
    }


    function setRegroupe (&$form, $maj) {
        /*$form->setRegroupe('numdossier','D',' '._('operation').' ', "collapsible");
        $form->setRegroupe('operation_categ','G','');
        $form->setRegroupe('date','G','');
        $form->setRegroupe('heure','G','');
        $form->setRegroupe('emplacement','G','');
        $form->setRegroupe('famille','F','');*/

        /*$form->setRegroupe('entreprise','D',' '._('entreprise').' ', "collapsible");
        $form->setRegroupe('societe_coordonnee','G','');
        $form->setRegroupe('particulier','F','');

        $form->setRegroupe('pf','D',' '._('pf').' ', "collapsible");
        $form->setRegroupe('pf_coordonnee','F','');*/
    } // setRegroupe ()
    
    function setLayout(&$form, $maj) {

        //
        $bloc_global_width_full = "span12";
        $bloc_global_width_half = "span6";

        //// CONTAINER GLOBAL - START
        $this->form->setBloc("operation", "D", "", "emplacement-form form-action-".$maj);
        //---------------------------------------------------------------------------------
           //// LIGNE num dossier - START
            $this->form->setBloc("numdossier", "D", "", "row-fluid");
                //// BLOC ID + LIBRE - START
                $this->form->setBloc("numdossier", "D", "", $bloc_global_width_full." emplacement-bloc emplacement-bloc-identification ");
                  //// BLOC ID - START
                  $this->form->setBloc("numdossier", "D", "", " span12");
                  $this->form->setBloc("heure", "F");
                $this->form->setBloc("heure", "F");
            //// LIGNE num dossier - END
             $this->form->setBloc("heure", "F");
           
            ///emplacement et famille     
            $this->form->setBloc("emplacement", "D", "", "row-fluid");
                //// BLOC emplacement et famille- START
                $this->form->setBloc("emplacement", "D", "", $bloc_global_width_full." emplacement-bloc emplacement-bloc-adresse-localisation ");
                    //// LIGNE emplacement et famille- START
                    $this->form->setBloc("emplacement", "D", "", "row-fluid");
                        //// BLOC emplacement et famille - START
                        $this->form->setBloc("emplacement", "D",  _("emplacement"), "group span12");
                        $this->form->setBloc("famille", "F");
                        //// BLOC emplacement et famille - END
                    $this->form->setBloc("famille", "F");
                $this->form->setBloc("famille", "F");
            $this->form->setBloc("famille", "F");               
            /////           
            //// entreprise+ + pompe funebre
            $this->form->setBloc("entreprise", "D", "", $bloc_global_width_full." emplacement-bloc emplacement-bloc-infos ");
            //// LIGNE entreprise + pompe funebre - START
            $this->form->setBloc("entreprise", "D", "", "row-fluid");
                    
                    //// BLOC entreprise - START
                    $this->form->setBloc("entreprise", "D", "", $bloc_global_width_half);
                    //// ligne entreprise - START
                     $this->form->setBloc("entreprise", "D", "", "row-fluid");
                            //// BLOC ENTREPRISE - START
                            $this->form->setBloc("entreprise", "D", _("entreprise"), " emplacement-bloc-acte span11");
                            $this->form->setBloc("entreprise", "D", "", "span11");
                            $this->form->setBloc("particulier", "F");
                            $this->form->setBloc("particulier", "F");
                     //// BLOC entreprise - END
                     $this->form->setBloc("particulier", "F");
                    //// LIGNE entreprise - END
                    $this->form->setBloc("particulier", "F");
                              
                              
                    //// BLOC pf - START
                    $this->form->setBloc("pf", "D", "", $bloc_global_width_half);
                    //// ligne pf - START
                     $this->form->setBloc("pf", "D", "", "row-fluid");
                            //// BLOC PF - START
                            $this->form->setBloc("pf", "D", _("pompe funebre"), " emplacement-bloc-acte span11");
                            $this->form->setBloc("pf", "D", "", "span11");
                            $this->form->setBloc("pf_coordonnee", "F");
                            $this->form->setBloc("pf_coordonnee", "F");
                             
                    //// BLOC pf - END
                     $this->form->setBloc("pf_coordonnee", "F");
                    //// LIGNE pf - END
                    $this->form->setBloc("pf_coordonnee", "F");
                    
            //// LIGNE entreprise + pompe funebre - END
            $this->form->setBloc("pf_coordonnee", "F");
        $this->form->setBloc("pf_coordonnee", "F");
        //defunt
        $this->form->setBloc("defunt_titre", "D", "", $bloc_global_width_full." emplacement-bloc emplacement-bloc-infos ");
            $this->form->setBloc("defunt_titre", "D", "", "row-fluid");
                    //// BLOC
                    $this->form->setBloc("defunt_titre", "D", "", $bloc_global_width_full);
                        //// LIGNE defunt - START
                        $this->form->setBloc("defunt_titre", "D", "", "row-fluid");
                            //// BLOC defunt - START
                            $this->form->setBloc("defunt_titre", "D", _("defunt"), " emplacement-bloc-acte span12");
                                $this->form->setBloc("defunt_titre", "D", "", "span12");
                                $this->form->setBloc("defunt_nature", "F");
                            $this->form->setBloc("defunt_nature", "F");
                            //// BLOC defunt- END
                        $this->form->setBloc("defunt_nature", "F");
                    //// LIGNE defunt - END
                    $this->form->setBloc("defunt_nature", "F");
                     //// LIGNE defunt - END
            $this->form->setBloc("defunt_nature", "F");
         $this->form->setBloc("defunt_nature", "F");
        /// CONTAINER GLOBAL - END
        $this->form->setBloc("observation", "F");
    }

    function triggerajouter($id,&$db,$val,$DEBUG)
    {
        //  numero de registre
        $temp= $db->nextId(DB_PREFIXE."numdossier");
        $temp= date('Y')."-".$temp;
        $this->form->setVal('numdossier',$temp);
        $this->valF['numdossier'] = $temp;
    }

    function triggersupprimer($id,&$db,$val,$DEBUG){
        $sql= "delete from ".DB_PREFIXE."operation_defunt where operation=".$this->id.";";
        $res= $db->query($sql);
        if (database::isError($res))
            die($res->getMessage().$sql);
    }

}// fin classe
?>