<?php
/**
 * @package opencimetiere
 * @version SVN : $Id$
 */

//
require_once "../gen/obj/emplacement.class.php";

class emplacement extends emplacement_gen {

    /*
    classe contenant les elements de localisation + champ famille
    heritage
        emplacement -> concession -> colombarium
                                  -> terraincommunal
                                  -> enfeu
                    -> ossuaire   -> depositoire
    */

    function setLib(&$form, $maj) {
        //
        parent::setLib($form, $maj);
        //
        $this->form->setLib("emplacement", _("id"));
        //
        $this->form->setLib("complement", "&nbsp;");
        $this->form->setLib("voielib", "&nbsp;");
    }

    function setLayout(&$form, $maj) {

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

        //// CONTAINER GLOBAL - START
        $this->form->setBloc("emplacement", "D", "", "emplacement-form form-action-".$maj);

        //// LIGNE ID + LIBRE - START
        $this->form->setBloc("emplacement", "D", "", "row-fluid");
            //// BLOC ID + LIBRE - START
            $this->form->setBloc("emplacement", "D", "", $bloc_global_width_full." emplacement-bloc emplacement-bloc-identification ");
                //// BLOC ID - START
                $this->form->setBloc("emplacement", "D", "", "span6");
                $this->form->setBloc("nature", "F");
                //// BLOC ID - END
                //// BLOC LIBRE - START
                $this->form->setBloc("libre", "DF", "", "span6 emplacement-field-libre");
                //// BLOC LIBRE - END
            $this->form->setBloc("libre", "F");
            //// BLOC ID + LIBRE - END
        $this->form->setBloc("libre", "F");
        //// LIGNE ID + LIBRE - END

        //// LIGNE ADRESSE + LOCALISATION - START
        $this->form->setBloc("numero", "D", "", "row-fluid");
            //// BLOC ADRESSE + LOCALISATION - START
            $this->form->setBloc("numero", "D", "", $bloc_global_width_full." emplacement-bloc emplacement-bloc-adresse-localisation ");
                //// LIGNE ADRESSE - START
                $this->form->setBloc("numero", "D", "", "row-fluid");
                    //// BLOC ADRESSE - START
                    $this->form->setBloc("numero", "D",  _("Adresse"), "group span12");
                    $this->form->setBloc("voielib", "F");
                    //// BLOC ADRESSE - END
                $this->form->setBloc("voielib", "F");
                //// LIGNE ADRESSE - END
                //// LIGNE LOCALISATION - START
                $this->form->setBloc("plans", "D", "", "row-fluid");
                    //// BLOC LOCALISATION - START
                    $this->form->setBloc("plans", "D", _("Localisation"), "group span12");
                    $this->form->setBloc("positiony", "F");
                    //// BLOC LOCALISATION - END
                $this->form->setBloc("positiony", "F");
                //// LIGNE LOCALISATION - END
                //// LIGNE LOCALISATION - START
                $this->form->setBloc("geom", "D", "", "row-fluid");
                    //// BLOC LOCALISATION - START
                    $this->form->setBloc("geom", "DF", _("Localisation"), "group span12");
                    //// BLOC LOCALISATION - END
                $this->form->setBloc("geom", "F");
                //// LIGNE LOCALISATION - END
            $this->form->setBloc("geom", "F");
            //// BLOC ADRESSE + LOCALISATION - END
        $this->form->setBloc("geom", "F");
        //// LIGNE ADRESSE + LOCALISATION - END

        //// LIGNE ACTE + ABANDON + BATI + PLACE - START
        $this->form->setBloc("famille", "D", "", "row-fluid");
            //// BLOC ACTE + ABANDON + BATI + PLACE - START
            $this->form->setBloc("famille", "D", "", $bloc_global_width_full." emplacement-bloc emplacement-bloc-infos ");
                //// LIGNE ACTE + ABANDON + BATI + PLACE - START
                $this->form->setBloc("famille", "D", "", "row-fluid");
                    //// BLOC ACTE + ABANDON - START
                    $this->form->setBloc("famille", "D", "", $bloc_global_width_half);
                        //// LIGNE ACTE - START
                        $this->form->setBloc("famille", "D", "", "row-fluid");
                            //// BLOC ACTE - START
                            $this->form->setBloc("famille", "D", _("Acte de concession"), " emplacement-bloc-acte span12");
                                $this->form->setBloc("famille", "D", "", "span12");
                                $this->form->setBloc("archive_datevente", "F");
                            $this->form->setBloc("archive_datevente", "F");
                            //// BLOC ACTE - END
                        $this->form->setBloc("archive_datevente", "F");
                        //// LIGNE ACTE - END
                        //// LIGNE ABANDON - START
                        $this->form->setBloc("abandon", "D", "", "row-fluid");
                            //// BLOC ABANDON - START
                            $this->form->setBloc("abandon", "D", _("Abandon"), "emplacement-bloc-abandon span12");
                                $this->form->setBloc("abandon", "D", "", "span12");
                                $this->form->setBloc("date_abandon", "F");
                            $this->form->setBloc("date_abandon", "F");
                            //// BLOC ABANDON - END
                        $this->form->setBloc("date_abandon", "F");
                        //// LIGNE ABANDON - END
                    $this->form->setBloc("date_abandon", "F");
                    //// BLOC ACTE + ABANDON - END
                    //// BLOC BATI + PLACE - START
                    $this->form->setBloc("sepulturetype", "D", "", $bloc_global_width_half);
                        //// LIGNE BATI - START
                        $this->form->setBloc("sepulturetype", "D", "", "row-fluid");
                            //// BLOC BATI - START
                            $this->form->setBloc("sepulturetype", "D", _("Bati"), "emplacement-bloc-bati span12");
                                $this->form->setBloc("sepulturetype", "D", "", "span12");
                                $this->form->setBloc("profondeur", "F");
                            $this->form->setBloc("profondeur", "F");
                            //// BLOC BATI - END
                        $this->form->setBloc("profondeur", "F");
                        //// LIGNE BATI - END
                        //// LIGNE PLACE - START
                        $this->form->setBloc("nombreplace", "D", "", "row-fluid");
                            //// BLOC PLACE - START
                            $this->form->setBloc("nombreplace", "D", _("Gestion de la place"), "emplacement-bloc-gestion-de-la-place span12 ");
                                $this->form->setBloc("nombreplace", "D", "", "span12");
                                $this->form->setBloc("dateconstat", "F");
                            $this->form->setBloc("dateconstat", "F");
                            //// BLOC PLACE - END
                        $this->form->setBloc("dateconstat", "F");
                        //// LIGNE PLACE - END
                    $this->form->setBloc("dateconstat", "F");
                    //// BLOC BATI + PLACE - END
                $this->form->setBloc("dateconstat", "F");
                //// LIGNE ACTE + ABANDON + BATI + PLACE - END
            $this->form->setBloc("dateconstat", "F");
            //// BLOC ACTE + ABANDON + BATI + PLACE - END
        $this->form->setBloc("dateconstat", "F");
        //// LIGNE ACTE + ABANDON + BATI + PLACE - END

        //// LIGNE OBSERVATION - START
        $this->form->setBloc("observation", "D", "", "row-fluid");
            //// BLOC OBSERVATION - START
            $this->form->setBloc("observation", "D", "", $bloc_global_width_full." emplacement-bloc emplacement-bloc-observation ");
                $this->form->setBloc("observation", "DF", "", "group span12");
            $this->form->setBloc("observation", "F");
            // BLOC OBSERVATION - END
        $this->form->setBloc("observation", "F");
        //// LIGNE OBSERVATION - START

        //// CONTAINER GLOBAL - END
        $this->form->setBloc("observation", "F");

    }

    /**
     * Surcharge réalisée pour le retour sur les écrans 'concessionlibre',
     * 'terraincommunallibre', 'colombariumlibre' et 'terme'
     */
    function getDataSubmit() {
        //
        $datasubmit = parent::getDatasubmit();
        //
        if ($this->getParameter("specific_origin") != NULL) {
            $datasubmit .= "&amp;specific_origin=".$this->getParameter("specific_origin");
        }
        //
        return $datasubmit;
    }

    /**
     * Surcharge réalisée pour le retour sur les écrans 'concessionlibre',
     * 'terraincommunallibre', 'colombariumlibre' et 'terme'
     */
    function retour($premier = 0, $recherche = "", $tricol = "") {

        echo "\n<a class=\"retour\" ";
        echo "href=\"";
        //
        
        if ($this->getParameter("retour")=="form" AND !($this->getParameter("validation")>0 AND $this->getParameter("maj")==2 AND $this->correct)) {
            echo "form.php?";
        } else {
            echo "tab.php?";
        }
        if ($this->getParameter("specific_origin") != NULL) {
            echo "obj=".$this->getParameter("specific_origin");
        } else {
            echo "obj=".get_class($this);
        }
        if ($this->getParameter("retour")=="form") {
            echo "&amp;idx=".$this->getParameter("idx");
            echo "&amp;action=3";
        }
        echo "&amp;premier=".$this->getParameter("premier");
        echo "&amp;tricol=".$this->getParameter("tricol");
        echo "&amp;recherche=".$this->getParameter("recherche");
        echo "&amp;selectioncol=".$this->getParameter("selectioncol");
        echo "&amp;advs_id=".$this->getParameter("advs_id");
        echo "&amp;valide=".$this->getParameter("valide");

        //
        echo "\"";
        echo ">";
        //
        echo _("Retour");
        //
        echo "</a>\n";

    }

    function verifier($val, $db, $DEBUG){
        //
        if (isset($this->valF['libre']) && $this->valF['libre']=='Non') {
            $this->required_field[] = "famille";
        }
        //
        parent::verifier($val, $db, $DEBUG);
        //
        if ($this->valF['voie'] == "") {
            $this->correct = false;
            $this->addToMessage(_("Le champ")." "._("voie")." "._("est obligatoire"));
        }
        if ($this->valF['numero'] == "") {
            $this->correct = false;
            $this->addToMessage(_("Le champ")." "._("numero")." "._("est obligatoire"));
        }
        if($val['numero']==""){
            $this->valF['numero'] = NULL;
        }
        if($val['voie']==""){
            $this->valF['voie'] = NULL;
        }
        if($val['datevente']==""){
            $this->valF['datevente'] = NULL;
        }
        if($val['duree']==""){
            $this->valF['duree'] = NULL;
        }
        if($val['dateterme']==""){
            $this->valF['dateterme'] = NULL;
        }
        if($val['nombreplace']==""){
            $this->valF['nombreplace'] = NULL;
        }
        if($val['placeoccupe']==""){
            $this->valF['placeoccupe'] = NULL;
        }
        if($val['superficie']==""){
            $this->valF['superficie'] = NULL;
        }
        if($val['placeconstat']==""){
            $this->valF['placeconstat'] = NULL;
        }
        if($val['dateconstat']==""){
            $this->valF['dateconstat'] = NULL;
        }
        if($val['positionx']==""){
            $this->valF['positionx'] = NULL;
        }
        if($val['positiony']==""){
            $this->valF['positiony'] = NULL;
        }
        if($val['daterenouvellement']==""){
            $this->valF['daterenouvellement'] = NULL;
        }
        if($val['largeur']==""){
            $this->valF['largeur'] = NULL;
        }
        if($val['profondeur']==""){
            $this->valF['profondeur'] = NULL;
        }
        if($val['date_abandon']==""){
            $this->valF['date_abandon'] = NULL;
        }
    }


    function setSelect(&$form, $maj,$db,$debug) {
        parent::setSelect($form, $maj,$db,$debug);
        if($maj<2){
            $contenu="";
            $contenu[0][0]="voie";
            $contenu[0][1]="voie";
            $contenu[1][0]="voielib";
            $contenu[1][1]="voielib";
            $form->setSelect("voie",$contenu);
            //libvoie
            $contenu="";
            $contenu[0][0]="voie";
            $contenu[0][1]="voielib";
            $contenu[1][0]="voie";
            $contenu[1][1]="voie";
            $form->setSelect("voielib",$contenu);
            // complement
            $contenu=array();
            $contenu[0]=array('',_("bis"),_("ter"),_("quater"));
            $contenu[1]=array('',_("bis"),_("ter"),_("quater"));
            $form->setSelect("complement",$contenu);
        }
        // geom
        if ($maj == 1 || $maj == 3) { //modification ou visualisation
            $contenu=array();
            $contenu[0]=array($this->nature, $this->getParameter("idx"),"0");
            $form->setSelect('geom', $contenu);
        }
    }

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


    function setVal(&$form,$maj,$validation){
        if ($validation==0) {
            if ($maj == 0){
                $form->setVal('emplacement', "[...]");
                
              $form->setVal('placeoccupe', 0);
              $form->setVal('numerocadastre', 0);
              $form->setVal('numeroacte', 0);
              $form->setVal('terme', 0);
              $form->setVal('duree', 0.0);
              $form->setVal('nombreplace', 0.0);
              $form->setVal('superficie', 0.0);
              $form->setVal('placeconstat', 0.0);
              $form->setVal('nature', $this->nature);
              $form->setVal('positionx', 10); // compatibilite localisation mozilla
              $form->setVal('positiony', 10); // compatibilite localisation mozilla
            }
        }
    }



    function verifierVoie($val,&$db,$DEBUG){
        // verif voie [verify street]
        $sql = "select voie from ".DB_PREFIXE."voie where voie ='".$val['voie']."'";
        $res = $db->query($sql);
        if($DEBUG==1) echo $sql;
        if (database::isError($res))
            die($res->getMessage().$sql);
        else{
           $nbligne=$res->numrows();
           if ($nbligne==0){
                $this->addToMessage(_("voie")." ".$val['voie']." "._("inexistant"));
                $this->correct=false;
            }
        }
        // maj
        if($val['emplacement']==""){
            $maj=0;
        }else
            $maj=1;
        // verif DOUBLON numero + complement + voie [Doubloon street]
        $sql = "select emplacement from ".DB_PREFIXE."emplacement where numero='".$val['numero'].
        "' and complement='".$val['complement']."' and voie='".$val['voie']."'";
        $res = $db->query($sql);
        if($DEBUG==1) echo $sql;
        if (database::isError($res))
            die($res->getMessage().$sql);
        else{
           $nbligne=$res->numrows();
           if ($nbligne>1 and $maj==1){
               $this->addToMessage(_("adresse")." ".$val['numero']." ".
                      $val['complement']." ".$val['voie']." "._("existant"));
               $this->correct=false;
            }
            if ($nbligne>0 and $maj==0){
               $this->addToMessage(_("adresse")." ".$val['numero']." ".
                      $val['complement']." ".$val['voie']." "._("existant"));
               $this->correct=false;
            }
        }
    }

    // CALCUL SUR DATE FIN et MODIFIER

    function calculdatefin($id,&$db,$val,$DEBUG){
        // SPECIFIQUE - calcul date de fin de concession
        //[specific - Calculation of the date of the term]
        if($val['datevente']!="" and $val['datevente']!="00/00/0000" and $val['datevente'] != NULL
        and $val['duree']!="" and $val['duree'] != NULL and  $val['terme']=="temporaire"){
            $temp =explode("-", $this->valF['datevente']);
            $temp[0] = $temp[0]+$val['duree'];
            $this->valF['dateterme']= $temp[0]."-".$temp[1]."-".$temp[2];
            $terme=$temp[2]."/".$temp[1]."/".$temp[0];
            $this->addToMessage(_("terme")." ".$terme."<br>");
        }
    }



}// fin classe
?>
