<?php
//$Id$ 
//gen openMairie le 09/10/2012 10:26

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

class parcelle_gen extends om_dbform {
    var $table="parcelle";
    var $clePrimaire="parcelle";
    var $typeCle="A";
    var $required_field=array(
        "parcelle"
    );
    var $retourformulaire;

    function setvalF($val) {
        //affectation valeur formulaire
        $this->valF['parcelle'] = $val['parcelle'];
        if ($val['debut'] == "") {
            $this->valF['debut'] = ""; // -> default
        } else {
            $this->valF['debut'] = $val['debut'];
        }
        if ($val['rivoli'] == "") {
            $this->valF['rivoli'] = NULL;
        } else {
            $this->valF['rivoli'] = $val['rivoli'];
        }
        if ($val['proprietaire'] == "") {
            $this->valF['proprietaire'] = NULL;
        } else {
            $this->valF['proprietaire'] = $val['proprietaire'];
        }
        if ($val['pos'] == "") {
            $this->valF['pos'] = NULL;
        } else {
            $this->valF['pos'] = $val['pos'];
        }
        if (!is_numeric($val['surface'])) {
            $this->valF['surface'] = NULL;
        } else {
            $this->valF['surface'] = $val['surface'];
        }
        if ($val['section'] == "") {
            $this->valF['section'] = NULL;
        } else {
            $this->valF['section'] = $val['section'];
        }
        if ($val['commune'] == "") {
            $this->valF['commune'] = NULL;
        } else {
            $this->valF['commune'] = $val['commune'];
        }
        if ($val['geom'] == "") {
            unset($this->valF['geom']);
        } else {
            $this->valF['geom'] = $val['geom'];
        }
    }

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

    function setType(&$form,$maj) {
        //type
        if ($maj==0){ //ajout
            $form->setType('parcelle','text');
            $form->setType('debut','text');

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

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

            if($this->retourformulaire=='pos'
               and $form->val['pos'] == $this->getParameter('idxformulaire')) {
                $form->setType('pos','selecthiddenstatic');
            } else {
                $form->setType('pos','select');
            }
            $form->setType('surface','text');
            $form->setType('section','text');
            $form->setType('commune','text');
            $form->setType('geom','geom');
        }// fin ajout
        if ($maj==1){ //modifier
            $form->setType('parcelle','hiddenstatic');
            $form->setType('debut','text');

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

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

            if($this->retourformulaire=='pos'
               and $form->val['pos'] == $this->getParameter('idxformulaire')) {
                $form->setType('pos','selecthiddenstatic');
            } else {
                $form->setType('pos','select');
            }
            $form->setType('surface','text');
            $form->setType('section','text');
            $form->setType('commune','text');
            $form->setType('geom','geom');
        }// fin modifier
        if ($maj==2){ //supprimer
            $form->setType('parcelle','hiddenstatic');
            $form->setType('debut','hiddenstatic');
            $form->setType('rivoli','selectstatic');
            $form->setType('proprietaire','selectstatic');
            $form->setType('pos','selectstatic');
            $form->setType('surface','hiddenstatic');
            $form->setType('section','hiddenstatic');
            $form->setType('commune','hiddenstatic');
            $form->setType('geom','hiddenstatic');
        }//fin supprimer
        if ($maj==3){ //consulter
            $form->setType('parcelle','static');
            $form->setType('debut','static');
            $form->setType('rivoli','selectstatic');
            $form->setType('proprietaire','selectstatic');
            $form->setType('pos','selectstatic');
            $form->setType('surface','static');
            $form->setType('section','static');
            $form->setType('commune','static');
            $form->setType('geom','geom');
        }//fin consulter
    }

    function setOnchange(&$form,$maj) {
    //javascript controle client
        $form->setOnchange('surface','VerifNum(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("parcelle", 10);
        $form->setTaille("debut", 10);
        $form->setTaille("rivoli", 10);
        $form->setTaille("proprietaire", 10);
        $form->setTaille("pos", 10);
        $form->setTaille("surface", 20);
        $form->setTaille("section", 10);
        $form->setTaille("commune", 10);
        $form->setTaille("geom", 10);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("parcelle", 6);
        $form->setMax("debut", 4);
        $form->setMax("rivoli", 4);
        $form->setMax("proprietaire", 6);
        $form->setMax("pos", 6);
        $form->setMax("surface", 20);
        $form->setMax("section", 7);
        $form->setMax("commune", 5);
        $form->setMax("geom", -5);
    }


    function setLib(&$form,$maj) {
    //libelle des champs
        $form->setLib('parcelle',_('parcelle'));
        $form->setLib('debut',_('debut'));
        $form->setLib('rivoli',_('rivoli'));
        $form->setLib('proprietaire',_('proprietaire'));
        $form->setLib('pos',_('pos'));
        $form->setLib('surface',_('surface'));
        $form->setLib('section',_('section'));
        $form->setLib('commune',_('commune'));
        $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");

        // pos
        $this->init_select($form, $db, $maj, $debug, "pos",
                           $sql_pos, $sql_pos_by_id, false);

        // proprietaire
        $this->init_select($form, $db, $maj, $debug, "proprietaire",
                           $sql_proprietaire, $sql_proprietaire_by_id, false);

        // rivoli
        $this->init_select($form, $db, $maj, $debug, "rivoli",
                           $sql_rivoli, $sql_rivoli_by_id, false);
            // geom
            if($maj==1 || $maj==3){ //modification ou visualisation
                $contenu=array();
                $contenu[0]=array("parcelle",$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 =='pos')
                $form->setVal('pos', $idxformulaire);
            if($retourformulaire =='proprietaire')
                $form->setVal('proprietaire', $idxformulaire);
            if($retourformulaire =='rivoli')
                $form->setVal('rivoli', $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 : dossier
        $this->rechercheTable($db, "dossier", "parcelle", $id);
        // Verification de la cle secondaire : terrain
        $this->rechercheTable($db, "terrain", "parcelle", $id);
    }


}// fin classe
?>