<?php
/**
 * Ce script définit la classe 'zone'.
 *
 * @package opencimetiere
 * @version SVN : $Id$
 */

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

/**
 * Définition de la classe 'zone' (om_dbform).
 */
class zone extends zone_gen {

    /**
     *
     * @return array
     */
    function get_var_sql_forminc__champs() {
        return array(
            "zone",
            "cimetiere",
            "zonetype",
            "zonelib",
            "geom",
            "'' as lien_sig_externe",
        );
    }

    /**
     * SETTER_FORM - setLib.
     *
     * @return void
     */
    function setLib(&$form, $maj) {
        parent::setLib($form, $maj);
        //
        $form->setLib($this->clePrimaire, __("id"));
        $form->setLib("zonelib", __("libelle"));
        $form->setLib("lien_sig_externe", '');
    }

    /**
     * SETTER_FORM - setType.
     *
     * @return void
     */
    function setType(&$form, $maj) {
        parent::setType($form, $maj);
        // Gestion du champs geom
        $form->setType('geom', 'hidden');
        $form->setType('lien_sig_externe', 'hidden');
        if ($this->f->getParameter("option_localisation") == "sig_interne") {
            if ($maj == 0 || $maj == 1 || $maj == 3) {
                $form->setType('geom', 'geom');
            }
        } elseif ($this->f->getParameter("option_localisation") == "sig_externe") {
            if ($maj == 3) {
                $form->setType('lien_sig_externe', 'http');
            }
        }

    }

    /**
     * SETTER_FORM - setSelect.
     *
     * @return void
     */
    function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) {
        parent::setSelect($form, $maj);
        if ($maj == 3) {
            if ($this->f->getParameter("option_localisation") == "sig_externe") {
                $contenu[0] = 'Lien vers le SIG externe';
                $form->setSelect("lien_sig_externe",$contenu);

            }
        }
    }

    /**
     * SETTER_FORM - setVal.
     *
     * @return void
     */
    function setVal(&$form, $maj, $validation, &$dnu1 = null, $dnu2 = null) {
        parent::setVal($form, $maj, $validation);
        if ($maj == 3) {
            // requêtes
            if ($this->f->getParameter("option_localisation") == "sig_externe") {
                $url='../app/localisation_sig_externe.php?&insee='.$this->f->getParameter('code_insee').'&obj=zone&idx='.$this->getVal('zone').'&cimetiere='.$this->getVal('cimetiere');
                $form->setVal('lien_sig_externe', $url);
            }
        }
    }
}
