<?php
//$Id$ 
//gen openMairie le 13/05/2013 10:46

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

class bureau_gen extends om_dbform {
    var $table="bureau";
    var $clePrimaire="bureau";
    var $typeCle="A";
    var $required_field=array(
        "bureau",
        "canton",
        "libelle"
    );
    var $retourformulaire;

    function setvalF($val) {
        //affectation valeur formulaire
        $this->valF['bureau'] = $val['bureau'];
        $this->valF['libelle'] = $val['libelle'];
        $this->valF['canton'] = $val['canton'];
        if ($val['adresse1'] == "") {
            $this->valF['adresse1'] = NULL;
        } else {
            $this->valF['adresse1'] = $val['adresse1'];
        }
        if ($val['adresse2'] == "") {
            $this->valF['adresse2'] = NULL;
        } else {
            $this->valF['adresse2'] = $val['adresse2'];
        }
        if ($val['cp'] == "") {
            $this->valF['cp'] = NULL;
        } else {
            $this->valF['cp'] = $val['cp'];
        }
        if ($val['ville'] == "") {
            $this->valF['ville'] = NULL;
        } else {
            $this->valF['ville'] = $val['ville'];
        }
    }

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

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

            if($this->retourformulaire=='canton'
               and $form->val['canton'] == $this->getParameter('idxformulaire')) {
                $form->setType('canton','selecthiddenstatic');
            } else {
                $form->setType('canton','select');
            }
            $form->setType('adresse1','text');
            $form->setType('adresse2','text');
            $form->setType('cp','text');
            $form->setType('ville','text');
        }// fin ajout
        if ($maj==1){ //modifier
            $form->setType('bureau','hiddenstatic');
            $form->setType('libelle','text');

            if($this->retourformulaire=='canton'
               and $form->val['canton'] == $this->getParameter('idxformulaire')) {
                $form->setType('canton','selecthiddenstatic');
            } else {
                $form->setType('canton','select');
            }
            $form->setType('adresse1','text');
            $form->setType('adresse2','text');
            $form->setType('cp','text');
            $form->setType('ville','text');
        }// fin modifier
        if ($maj==2){ //supprimer
            $form->setType('bureau','hiddenstatic');
            $form->setType('libelle','hiddenstatic');
            $form->setType('canton','selectstatic');
            $form->setType('adresse1','hiddenstatic');
            $form->setType('adresse2','hiddenstatic');
            $form->setType('cp','hiddenstatic');
            $form->setType('ville','hiddenstatic');
        }//fin supprimer
        if ($maj==3){ //consulter
            $form->setType('bureau','static');
            $form->setType('libelle','static');
            $form->setType('canton','selectstatic');
            $form->setType('adresse1','static');
            $form->setType('adresse2','static');
            $form->setType('cp','static');
            $form->setType('ville','static');
        }//fin consulter
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("bureau", 10);
        $form->setTaille("libelle", 30);
        $form->setTaille("canton", 10);
        $form->setTaille("adresse1", 30);
        $form->setTaille("adresse2", 30);
        $form->setTaille("cp", 10);
        $form->setTaille("ville", 30);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("bureau", 4);
        $form->setMax("libelle", 30);
        $form->setMax("canton", 8);
        $form->setMax("adresse1", 60);
        $form->setMax("adresse2", 60);
        $form->setMax("cp", 5);
        $form->setMax("ville", 40);
    }


    function setLib(&$form,$maj) {
    //libelle des champs
        $form->setLib('bureau',_('bureau'));
        $form->setLib('libelle',_('libelle'));
        $form->setLib('canton',_('canton'));
        $form->setLib('adresse1',_('adresse1'));
        $form->setLib('adresse2',_('adresse2'));
        $form->setLib('cp',_('cp'));
        $form->setLib('ville',_('ville'));
    }

    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");

        // canton
        $this->init_select($form, $db, $maj, $debug, "canton",
                           $sql_canton, $sql_canton_by_id, false);
    }// fin select

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

    function setValsousformulaire(&$form,$maj,$validation,$idxformulaire,$retourformulaire,$typeformulaire,&$db,$DEBUG=null){
        $this->retourformulaire = $retourformulaire;
        if($validation == 0) {
            if($retourformulaire =='canton')
                $form->setVal('canton', $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 : affectation
        $this->rechercheTable($db, "affectation", "bureau", $id);
        // Verification de la cle secondaire : candidature
        $this->rechercheTable($db, "candidature", "bureau", $id);
    }


}// fin classe
?>