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

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

class voie_gen extends om_dbform {
    var $table="voie";
    var $clePrimaire="voie";
    var $typeCle="N";
    var $required_field=array(
        "voie",
        "voielib",
        "voietype",
        "zone"
    );
    var $retourformulaire;

    function setvalF($val) {
        //affectation valeur formulaire
        if (!is_numeric($val['voie'])) {
            $this->valF['voie'] = ""; // -> requis
        } else {
            $this->valF['voie'] = $val['voie'];
        }
        if (!is_numeric($val['zone'])) {
            $this->valF['zone'] = ""; // -> requis
        } else {
            $this->valF['zone'] = $val['zone'];
        }
        if (!is_numeric($val['voietype'])) {
            $this->valF['voietype'] = ""; // -> requis
        } else {
            $this->valF['voietype'] = $val['voietype'];
        }
        $this->valF['voielib'] = $val['voielib'];
        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('voie','hidden');// cle automatique

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

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

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

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

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

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("voie", 11);
        $form->setMax("zone", 11);
        $form->setMax("voietype", 11);
        $form->setMax("voielib", 40);
        $form->setMax("geom", 551428);
    }


    function setLib(&$form,$maj) {
    //libelle des champs
        $form->setLib('voie',_('voie'));
        $form->setLib('zone',_('zone'));
        $form->setLib('voietype',_('voietype'));
        $form->setLib('voielib',_('voielib'));
        $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");

        // voietype
        $this->init_select($form, $db, $maj, $debug, "voietype",
                           $sql_voietype, $sql_voietype_by_id, true);

        // zone
        $this->init_select($form, $db, $maj, $debug, "zone",
                           $sql_zone, $sql_zone_by_id, false);
            // geom
            if($maj==1 || $maj==3){ //modification ou visualisation
                $contenu=array();
                $contenu[0]=array("voie",$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 =='voie_type')
                $form->setVal('voietype', $idxformulaire);
            if($retourformulaire =='zone')
                $form->setVal('zone', $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 : emplacement
        $this->rechercheTable($db, "emplacement", "voie", $id);
    }


}// fin classe
?>