<?php
//$Id$ 
//gen openMairie le 05/10/2012 13:55

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

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

    function setvalF($val) {
        //affectation valeur formulaire
        $this->valF['service'] = $val['service'];
        $this->valF['libelle'] = $val['libelle'];
        if ($val['adresse'] == "") {
            $this->valF['adresse'] = ""; // -> default
        } else {
            $this->valF['adresse'] = $val['adresse'];
        }
        if ($val['adresse2'] == "") {
            $this->valF['adresse2'] = ""; // -> default
        } else {
            $this->valF['adresse2'] = $val['adresse2'];
        }
        if ($val['cp'] == "") {
            $this->valF['cp'] = ""; // -> default
        } else {
            $this->valF['cp'] = $val['cp'];
        }
        if ($val['ville'] == "") {
            $this->valF['ville'] = ""; // -> default
        } else {
            $this->valF['ville'] = $val['ville'];
        }
        if ($val['email'] == "") {
            $this->valF['email'] = ""; // -> default
        } else {
            $this->valF['email'] = $val['email'];
        }
        if (!is_numeric($val['delai'])) {
            $this->valF['delai'] = NULL;
        } else {
            $this->valF['delai'] = $val['delai'];
        }
    }

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

    function setType(&$form,$maj) {
        //type
        if ($maj==0){ //ajout
            $form->setType('service','text');
            $form->setType('libelle','text');
            $form->setType('adresse','text');
            $form->setType('adresse2','text');
            $form->setType('cp','text');
            $form->setType('ville','text');
            $form->setType('email','text');
            $form->setType('delai','text');
        }// fin ajout
        if ($maj==1){ //modifier
            $form->setType('service','hiddenstatic');
            $form->setType('libelle','text');
            $form->setType('adresse','text');
            $form->setType('adresse2','text');
            $form->setType('cp','text');
            $form->setType('ville','text');
            $form->setType('email','text');
            $form->setType('delai','text');
        }// fin modifier
        if ($maj==2){ //supprimer
            $form->setType('service','hiddenstatic');
            $form->setType('libelle','hiddenstatic');
            $form->setType('adresse','hiddenstatic');
            $form->setType('adresse2','hiddenstatic');
            $form->setType('cp','hiddenstatic');
            $form->setType('ville','hiddenstatic');
            $form->setType('email','hiddenstatic');
            $form->setType('delai','hiddenstatic');
        }//fin supprimer
        if ($maj==3){ //consulter
            $form->setType('service','static');
            $form->setType('libelle','static');
            $form->setType('adresse','static');
            $form->setType('adresse2','static');
            $form->setType('cp','static');
            $form->setType('ville','static');
            $form->setType('email','static');
            $form->setType('delai','static');
        }//fin consulter
    }

    function setOnchange(&$form,$maj) {
    //javascript controle client
        $form->setOnchange('delai','VerifNum(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("service", 10);
        $form->setTaille("libelle", 30);
        $form->setTaille("adresse", 30);
        $form->setTaille("adresse2", 30);
        $form->setTaille("cp", 10);
        $form->setTaille("ville", 30);
        $form->setTaille("email", 30);
        $form->setTaille("delai", 11);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("service", 5);
        $form->setMax("libelle", 70);
        $form->setMax("adresse", 40);
        $form->setMax("adresse2", 39);
        $form->setMax("cp", 5);
        $form->setMax("ville", 30);
        $form->setMax("email", 50);
        $form->setMax("delai", 11);
    }


    function setLib(&$form,$maj) {
    //libelle des champs
        $form->setLib('service',_('service'));
        $form->setLib('libelle',_('libelle'));
        $form->setLib('adresse',_('adresse'));
        $form->setLib('adresse2',_('adresse2'));
        $form->setLib('cp',_('cp'));
        $form->setLib('ville',_('ville'));
        $form->setLib('email',_('email'));
        $form->setLib('delai',_('delai'));
    }

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

    function setValsousformulaire(&$form,$maj,$validation,$idxformulaire,$retourformulaire,$typeformulaire,&$db,$DEBUG=null){
        $this->retourformulaire = $retourformulaire;
    }// 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 : consultation
        $this->rechercheTable($db, "consultation", "service", $id);
    }


}// fin classe
?>