<?php
//$Id$ 
//gen openMairie le 11/06/2013 15:04

require_once ("../obj/om_dbform.class.php");

class zone_gen extends om_dbform {
    var $table="zone";
    var $clePrimaire="zone";
    var $typeCle="N";
    var $required_field=array(
        "cimetiere",
        "zone",
        "zonelib",
        "zonetype"
    );
    var $retourformulaire;

    function setvalF($val) {
        //affectation valeur formulaire
        if (!is_numeric($val['zone'])) {
            $this->valF['zone'] = ""; // -> requis
        } else {
            $this->valF['zone'] = $val['zone'];
        }
        if (!is_numeric($val['cimetiere'])) {
            $this->valF['cimetiere'] = ""; // -> requis
        } else {
            $this->valF['cimetiere'] = $val['cimetiere'];
        }
        if (!is_numeric($val['zonetype'])) {
            $this->valF['zonetype'] = ""; // -> requis
        } else {
            $this->valF['zonetype'] = $val['zonetype'];
        }
        $this->valF['zonelib'] = $val['zonelib'];
        if ($val['geom'] == "") {
            unset($this->valF['geom']);
        } else {
            $this->valF['geom'] = $val['geom'];
        }
    }

    //=================================================
    //cle primaire automatique [automatic primary key]
    //==================================================

    function setId(&$db) {
    //numero automatique
        $this->valF[$this->clePrimaire] = $db->nextId(DB_PREFIXE.$this->table);
    }

    function setValFAjout($val) {
    //numero automatique -> pas de controle ajout cle primaire
    }

    function verifierAjout() {
    //numero automatique -> pas de verfication de cle primaire
    }

    //==========================
    // Formulaire  [form]
    //==========================

    function setType(&$form,$maj) {
        //type
        if ($maj==0){ //ajout
            $form->setType('zone','hidden');// cle automatique

            if($this->retourformulaire=='cimetiere'
               and $form->val['cimetiere'] == $this->getParameter('idxformulaire')) {
                $form->setType('cimetiere','selecthiddenstatic');
            } else {
                $form->setType('cimetiere','select');
            }

            if($this->retourformulaire=='zone_type'
               and $form->val['zonetype'] == $this->getParameter('idxformulaire')) {
                $form->setType('zonetype','selecthiddenstatic');
            } else {
                $form->setType('zonetype','select');
            }
            $form->setType('zonelib','text');
            $form->setType('geom','geom');
        }// fin ajout
        if ($maj==1){ //modifier
            $form->setType('zone','hiddenstatic');

            if($this->retourformulaire=='cimetiere'
               and $form->val['cimetiere'] == $this->getParameter('idxformulaire')) {
                $form->setType('cimetiere','selecthiddenstatic');
            } else {
                $form->setType('cimetiere','select');
            }

            if($this->retourformulaire=='zone_type'
               and $form->val['zonetype'] == $this->getParameter('idxformulaire')) {
                $form->setType('zonetype','selecthiddenstatic');
            } else {
                $form->setType('zonetype','select');
            }
            $form->setType('zonelib','text');
            $form->setType('geom','geom');
        }// fin modifier
        if ($maj==2){ //supprimer
            $form->setType('zone','hiddenstatic');
            $form->setType('cimetiere','selectstatic');
            $form->setType('zonetype','selectstatic');
            $form->setType('zonelib','hiddenstatic');
            $form->setType('geom','hiddenstatic');
        }//fin supprimer
        if ($maj==3){ //consulter
            $form->setType('zone','static');
            $form->setType('cimetiere','selectstatic');
            $form->setType('zonetype','selectstatic');
            $form->setType('zonelib','static');
            $form->setType('geom','geom');
        }//fin consulter
    }

    function setOnchange(&$form,$maj) {
    //javascript controle client
        $form->setOnchange('zone','VerifNum(this)');
        $form->setOnchange('cimetiere','VerifNum(this)');
        $form->setOnchange('zonetype','VerifNum(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("zone", 11);
        $form->setTaille("cimetiere", 11);
        $form->setTaille("zonetype", 11);
        $form->setTaille("zonelib", 30);
        $form->setTaille("geom", 30);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("zone", 11);
        $form->setMax("cimetiere", 11);
        $form->setMax("zonetype", 11);
        $form->setMax("zonelib", 40);
        $form->setMax("geom", 551432);
    }


    function setLib(&$form,$maj) {
    //libelle des champs
        $form->setLib('zone',_('zone'));
        $form->setLib('cimetiere',_('cimetiere'));
        $form->setLib('zonetype',_('zonetype'));
        $form->setLib('zonelib',_('zonelib'));
        $form->setLib('geom',_('geom'));
    }

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

        // cimetiere
        $this->init_select($form, $db, $maj, $debug, "cimetiere",
                           $sql_cimetiere, $sql_cimetiere_by_id, false);

        // zonetype
        $this->init_select($form, $db, $maj, $debug, "zonetype",
                           $sql_zonetype, $sql_zonetype_by_id, true);
            // geom
            if($maj==1 || $maj==3){ //modification ou visualisation
                $contenu=array();
                $contenu[0]=array("zone",$this->getParameter("idx"),"0");
                $form->setSelect('geom',$contenu);
            }
    }// fin select

    //==================================
    // sous Formulaire  [subform]
    //==================================

    function setValsousformulaire(&$form,$maj,$validation,$idxformulaire,$retourformulaire,$typeformulaire,&$db,$DEBUG=null){
        $this->retourformulaire = $retourformulaire;
        if($validation == 0) {
            if($retourformulaire =='cimetiere')
                $form->setVal('cimetiere', $idxformulaire);
            if($retourformulaire =='zone_type')
                $form->setVal('zonetype', $idxformulaire);
        }// fin validation
    }// fin setValsousformulaire

    //==================================
    // cle secondaire  [secondary key]
    //==================================
    /**
     * Methode clesecondaire
     */
    function cleSecondaire($id, &$db = NULL, $val = array(), $DEBUG = false) {
        // On appelle la methode de la classe parent
        parent::cleSecondaire($id, $db, $val, $DEBUG);
        // Verification de la cle secondaire : voie
        $this->rechercheTable($db, "voie", "zone", $id);
    }


}// fin classe
?>