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

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

class evenement_gen extends om_dbform {
    var $table="evenement";
    var $clePrimaire="evenement";
    var $typeCle="N";
    var $required_field=array(
        "evenement",
        "libelle"
    );
    var $retourformulaire;

    function setvalF($val) {
        //affectation valeur formulaire
        if (!is_numeric($val['evenement'])) {
            $this->valF['evenement'] = ""; // -> requis
        } else {
            $this->valF['evenement'] = $val['evenement'];
        }
        $this->valF['libelle'] = $val['libelle'];
        if ($val['nature'] == "") {
            $this->valF['nature'] = NULL;
        } else {
            $this->valF['nature'] = $val['nature'];
        }
        if ($val['action'] == "") {
            $this->valF['action'] = NULL;
        } else {
            $this->valF['action'] = $val['action'];
        }
        if ($val['etat'] == "") {
            $this->valF['etat'] = NULL;
        } else {
            $this->valF['etat'] = $val['etat'];
        }
        if (!is_numeric($val['delai'])) {
            $this->valF['delai'] = NULL;
        } else {
            $this->valF['delai'] = $val['delai'];
        }
        if ($val['accord_tacite'] == "") {
            $this->valF['accord_tacite'] = ""; // -> default
        } else {
            $this->valF['accord_tacite'] = $val['accord_tacite'];
        }
        if (!is_numeric($val['delai_notification'])) {
            $this->valF['delai_notification'] = NULL;
        } else {
            $this->valF['delai_notification'] = $val['delai_notification'];
        }
        if ($val['avis'] == "") {
            $this->valF['avis'] = NULL;
        } else {
            $this->valF['avis'] = $val['avis'];
        }
        if ($val['lettretype'] == "") {
            $this->valF['lettretype'] = ""; // -> default
        } else {
            $this->valF['lettretype'] = $val['lettretype'];
        }
        if ($val['consultation'] == "") {
            $this->valF['consultation'] = ""; // -> default
        } else {
            $this->valF['consultation'] = $val['consultation'];
        }
    }

    //=================================================
    //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('evenement','hidden');// cle automatique
            $form->setType('libelle','text');

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

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

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

            if($this->retourformulaire=='avis'
               and $form->val['avis'] == $this->getParameter('idxformulaire')) {
                $form->setType('avis','selecthiddenstatic');
            } else {
                $form->setType('avis','select');
            }
            $form->setType('lettretype','text');
            $form->setType('consultation','text');
        }// fin ajout
        if ($maj==1){ //modifier
            $form->setType('evenement','hiddenstatic');
            $form->setType('libelle','text');

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

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

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

            if($this->retourformulaire=='avis'
               and $form->val['avis'] == $this->getParameter('idxformulaire')) {
                $form->setType('avis','selecthiddenstatic');
            } else {
                $form->setType('avis','select');
            }
            $form->setType('lettretype','text');
            $form->setType('consultation','text');
        }// fin modifier
        if ($maj==2){ //supprimer
            $form->setType('evenement','hiddenstatic');
            $form->setType('libelle','hiddenstatic');
            $form->setType('nature','selectstatic');
            $form->setType('action','selectstatic');
            $form->setType('etat','selectstatic');
            $form->setType('delai','hiddenstatic');
            $form->setType('accord_tacite','hiddenstatic');
            $form->setType('delai_notification','hiddenstatic');
            $form->setType('avis','selectstatic');
            $form->setType('lettretype','hiddenstatic');
            $form->setType('consultation','hiddenstatic');
        }//fin supprimer
        if ($maj==3){ //consulter
            $form->setType('evenement','static');
            $form->setType('libelle','static');
            $form->setType('nature','selectstatic');
            $form->setType('action','selectstatic');
            $form->setType('etat','selectstatic');
            $form->setType('delai','static');
            $form->setType('accord_tacite','static');
            $form->setType('delai_notification','static');
            $form->setType('avis','selectstatic');
            $form->setType('lettretype','static');
            $form->setType('consultation','static');
        }//fin consulter
    }

    function setOnchange(&$form,$maj) {
    //javascript controle client
        $form->setOnchange('evenement','VerifNum(this)');
        $form->setOnchange('delai','VerifNum(this)');
        $form->setOnchange('delai_notification','VerifNum(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("evenement", 11);
        $form->setTaille("libelle", 30);
        $form->setTaille("nature", 10);
        $form->setTaille("action", 20);
        $form->setTaille("etat", 20);
        $form->setTaille("delai", 11);
        $form->setTaille("accord_tacite", 10);
        $form->setTaille("delai_notification", 11);
        $form->setTaille("avis", 20);
        $form->setTaille("lettretype", 30);
        $form->setTaille("consultation", 10);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("evenement", 11);
        $form->setMax("libelle", 70);
        $form->setMax("nature", 2);
        $form->setMax("action", 20);
        $form->setMax("etat", 20);
        $form->setMax("delai", 11);
        $form->setMax("accord_tacite", 3);
        $form->setMax("delai_notification", 11);
        $form->setMax("avis", 20);
        $form->setMax("lettretype", 60);
        $form->setMax("consultation", 3);
    }


    function setLib(&$form,$maj) {
    //libelle des champs
        $form->setLib('evenement',_('evenement'));
        $form->setLib('libelle',_('libelle'));
        $form->setLib('nature',_('nature'));
        $form->setLib('action',_('action'));
        $form->setLib('etat',_('etat'));
        $form->setLib('delai',_('delai'));
        $form->setLib('accord_tacite',_('accord_tacite'));
        $form->setLib('delai_notification',_('delai_notification'));
        $form->setLib('avis',_('avis'));
        $form->setLib('lettretype',_('lettretype'));
        $form->setLib('consultation',_('consultation'));
    }

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

        // action
        $this->init_select($form, $db, $maj, $debug, "action",
                           $sql_action, $sql_action_by_id, false);

        // avis
        $this->init_select($form, $db, $maj, $debug, "avis",
                           $sql_avis, $sql_avis_by_id, false);

        // etat
        $this->init_select($form, $db, $maj, $debug, "etat",
                           $sql_etat, $sql_etat_by_id, false);

        // nature
        $this->init_select($form, $db, $maj, $debug, "nature",
                           $sql_nature, $sql_nature_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 =='action')
                $form->setVal('action', $idxformulaire);
            if($retourformulaire =='avis')
                $form->setVal('avis', $idxformulaire);
            if($retourformulaire =='etat')
                $form->setVal('etat', $idxformulaire);
            if($retourformulaire =='nature')
                $form->setVal('nature', $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 : bible
        $this->rechercheTable($db, "bible", "evenement", $id);
        // Verification de la cle secondaire : instruction
        $this->rechercheTable($db, "instruction", "evenement", $id);
    }


}// fin classe
?>