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

//
require_once ("emplacement.class.php");

class terraincommunal extends emplacement {

    /**
     * Attribut de nature d'emplacement
     * @var string Prend la valeur "terraincommunal"
     */
    var $nature = "terraincommunal";

    function terraincommunal($id, &$db, $DEBUG) {
        //
        $this->constructeur($id, $db, $DEBUG);
        // Récupération des paramètres nécessaires aux calculs de taille et de
        // durée
        $this->init_parameters();
    }

    function init_parameters() {
        //
        $default_duree_terraincommunal = 5;
        $this->duree_terraincommunal = $this->f->getParameter("duree_terraincommunal");
        if (is_null($this->duree_terraincommunal)) {
            $this->duree_terraincommunal = $default_duree_terraincommunal;
        }
        //
        $default_superficie_terraincommunal = 2;
        $this->superficie_terraincommunal = $this->f->getParameter("superficie_terraincommunal");
        if (is_null($this->superficie_terraincommunal)) {
            $this->superficie_terraincommunal = $default_superficie_terraincommunal;
        }
    }

    function setvalF($val){
        //
        parent::setValF($val);
        //
        $this->valF['emplacement'] = $val['emplacement'];
        $this->valF['nature'] = $val['nature'];
        $this->valF['numero'] = $val['numero'];
        $this->valF['complement'] = $val['complement'];
        $this->valF['voie'] = $val['voie'];
        $this->valF['famille'] = $val['famille'];
        $this->valF['numeroacte'] = $val['numeroacte'];
        $this->valF['terme'] = $val['terme'];
        $this->valF['duree'] = $val['duree'];
        if($val['dateterme']!="")
            $this->valF['dateterme'] = $this->dateDB($val['dateterme']); //==
        if($val['datevente']!="")
            $this->valF['datevente'] = $this->dateDB($val['datevente']);
        $this->valF['placeoccupe'] = $val['placeoccupe'];
        $this->valF['superficie'] = $val['superficie'];
        $this->valF['placeconstat'] = $val['placeconstat'];
        $this->valF['observation'] = $val['observation'];
        $this->valF['positionx'] = $val['positionx'];
        $this->valF['positiony'] = $val['positiony'];
        $this->valF['photo'] = $val['photo'];
        //$this->valF['plans'] = $val['plans'];
        $this->valF['libre'] = $val['libre'];
        unset($this->valF['geom']);
        // temp
        $this->valF['temp1'] = $val['temp1'];
        $this->valF['temp2'] = $val['temp2'];
        $this->valF['temp3'] = $val['temp3'];
        $this->valF['temp4'] = $val['temp4'];
        $this->valF['temp5'] = $val['temp5'];
    }

    function setType(&$form,$maj) {
        //
        parent::setType($form, $maj);
        // Localisation
        $form->setType('geom', 'hidden');
        $form->setType('pgeom', 'hidden');
        $form->setType('plans', 'hidden');
        $form->setType('positionx', 'hidden');
        $form->setType('positiony', 'hidden');
        // Champs paramétrables
        $form->setType('temp1', 'hidden');
        $form->setType('temp2', 'hidden');
        $form->setType('temp3', 'hidden');
        $form->setType('temp4', 'hidden');
        $form->setType('temp5', 'hidden');
        //// Champs de l'emplacement qui ne concernent pas un terrain communal
        // Acte
        $form->setType('typeconcession', 'hidden');
        $form->setType('numerocadastre', 'hidden');
        $form->setType('numeroacte', 'hidden');
        $form->setType('renouvellementconcession', 'hidden');
        $form->setType('daterenouvellement', 'hidden');
        $form->setType('archive_daterenouvellement','hidden');
        $form->setType('archive_duree','hidden');
        $form->setType('archive_dateterme','hidden');
        $form->setType('archive_datevente','hidden');
        $form->setType('archive_daterenouvellement','hidden');
        $form->setType('archive_duree','hidden');
        $form->setType('archive_dateterme','hidden');
        $form->setType('archive_datevente','hidden');
        // Bati
        $form->setType('sepulturetype', 'hidden');
        $form->setType('videsanitaire', 'hidden');
        $form->setType('semelle', 'hidden');
        $form->setType('etatsemelle', 'hidden');
        $form->setType('monument', 'hidden');
        $form->setType('etatmonument', 'hidden');
        $form->setType('largeur', 'hidden');
        $form->setType('profondeur', 'hidden');
        // Abandon
        $form->setType('abandon', 'hidden');
        $form->setType('date_abandon', 'hidden');
        // XXX Ce champ est à supprimer de l'application
        $form->setType('photo','hidden');
        ////////
        // MODE AJOUTER & MODE MODIFIER
        if ($maj == 0 || $maj == 1) {
            // Id
            $form->setType('emplacement', 'hiddenstatic');
            $form->setType('nature', 'hiddenstatic');
            // Libre
            $form->setType('libre', 'select');
            // Adresse
            $form->setType('complement', 'select');
            $form->setType('voie', 'comboD');
            $form->setType('voielib', 'comboC');
            // Localisation
            if ($this->f->getParameter("option_localisation") == "plan") {
                $form->setType('plans', 'select');
                $form->setType('positionx', 'text');
                $form->setType('positiony', 'localisation_plan');
            } elseif ($this->f->getParameter("option_localisation") == "sig_interne") {
                $form->setType('geom', 'geom');
            } elseif ($this->f->getParameter("option_localisation") == "sig_externe") {
                
            }
            // Acte
            $form->setType('terme', 'hiddenstatic');
            $form->setType('duree', 'hiddenstatic');
            $form->setType('datevente','date');
            $form->setType('dateterme', 'hiddenstaticdate');
            // Place
            $form->setType('nombreplace', 'hidden');
            $form->setType('placeoccupe','static');
            $form->setType('superficie','text');
            $form->setType('placeconstat', 'hidden');
            $form->setType('dateconstat', 'hidden');
        }
        //
        if ($maj == 3) {
            // Localisation
            if ($this->f->getParameter("option_localisation") == "plan") {
                $form->setType('plans', 'localisation_plan_static');
                $form->setType('positionx', 'hidden');
                $form->setType('positiony', 'hidden');
            } elseif ($this->f->getParameter("option_localisation") == "sig_interne") {
                
            } elseif ($this->f->getParameter("option_localisation") == "sig_externe") {
                
            }
        }
    }

    //function verifier($val,&$db,$DEBUG,&$form,$maj){
    function verifier($val,&$db,$DEBUG){
        parent :: verifier($val,$db,$DEBUG);
        // verification donnees real non vide (GI/compatibilite postgresql)
        // Check data real not empty (compatibility postgresql)
        if ($val['duree']=="" or is_null($val['duree']))
            $this->valF['duree'] = 0;
        if ($val['placeoccupe']=="" or is_null($val['placeoccupe']))
            $this->valF['placeoccupe'] = 0;
        if ($val['nombreplace']=="" or is_null($val['nombreplace']))
            $this->valF['nombreplace'] = 0;
        if ($val['superficie']=="" or is_null($val['superficie']))
            $this->valF['superficie'] = 0;
        if ($val['placeconstat']=="" or is_null($val['placeconstat']))
            $this->valF['placeconstat'] = 0;
        if($this->correct)
            $this->verifierVoie($val,$db,$DEBUG);
    }//verifier   [verify]


    function setVal(&$form,$maj,$validation){
        parent::setVal($form,$maj,$validation);
        if ($validation==0) {
            if ($maj == 0){
                $form->setVal('terme', 'temporaire');
                $form->setVal('duree', $this->duree_terraincommunal);
                $form->setVal('superficie', $this->superficie_terraincommunal);
            }
        }
    }

    function setSelect(&$form, $maj, &$db, $debug) {
        //
        parent::setSelect($form, $maj, $db, $debug);
        // MODE AJOUTER & MODE MODIFIER
        if ($maj == 0 || $maj == 1) {
            // Localisation
            $contenu = array();
            $contenu[0] = array('plans', 'positionx');
            $form->setSelect("positiony", $contenu);
            // Libre
            $contenu = array();
            $contenu[0] = array('Non', 'Oui');
            $contenu[1] = array(_("Non"), _("Oui"));
            $form->setSelect("libre", $contenu);
        }
    }

    function triggerajouter($id,&$db,$val,$DEBUG) {
        $this->calculdatefin($id,$db,$val,$DEBUG);

        return true;
    }

    function triggermodifier($id,&$db,$val,$DEBUG) {
        $this->calculdatefin($id,$db,$val,$DEBUG);

        return true;
    }

}

?>
