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

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

class consultation_gen extends om_dbform {
    var $table="consultation";
    var $clePrimaire="consultation";
    var $typeCle="N";
    var $required_field=array(
        "consultation",
        "date_envoi",
        "dossier",
        "service"
    );
    var $retourformulaire;

    function setvalF($val) {
        //affectation valeur formulaire
        if (!is_numeric($val['consultation'])) {
            $this->valF['consultation'] = ""; // -> requis
        } else {
            $this->valF['consultation'] = $val['consultation'];
        }
        $this->valF['dossier'] = $val['dossier'];
        $this->valF['service'] = $val['service'];
        if ($val['date_envoi'] != "") {
            $this->valF['date_envoi'] = $this->dateDB($val['date_envoi']);
        }
        if ($val['date_retour'] != "") {
            $this->valF['date_retour'] = $this->dateDB($val['date_retour']);
        } else {
            $this->valF['date_retour'] = NULL;
        }
        if ($val['avis'] == "") {
            $this->valF['avis'] = NULL;
        } else {
            $this->valF['avis'] = $val['avis'];
        }
        if ($val['date_limite'] != "") {
            $this->valF['date_limite'] = $this->dateDB($val['date_limite']);
        } else {
            $this->valF['date_limite'] = NULL;
        }
    }

    //=================================================
    //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('consultation','hidden');// cle automatique

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

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

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

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

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

            if($this->retourformulaire=='avis'
               and $form->val['avis'] == $this->getParameter('idxformulaire')) {
                $form->setType('avis','selecthiddenstatic');
            } else {
                $form->setType('avis','select');
            }
            if($this->retourformulaire=='')
                $form->setType('date_limite','date');
            else
                $form->setType('date_limite','date2');
        }// fin modifier
        if ($maj==2){ //supprimer
            $form->setType('consultation','hiddenstatic');
            $form->setType('dossier','selectstatic');
            $form->setType('service','selectstatic');
            $form->setType('date_envoi','hiddenstatic');
            $form->setType('date_retour','hiddenstatic');
            $form->setType('avis','selectstatic');
            $form->setType('date_limite','hiddenstatic');
        }//fin supprimer
        if ($maj==3){ //consulter
            $form->setType('consultation','static');
            $form->setType('dossier','selectstatic');
            $form->setType('service','selectstatic');
            $form->setType('date_envoi','datestatic');
            $form->setType('date_retour','datestatic');
            $form->setType('avis','selectstatic');
            $form->setType('date_limite','datestatic');
        }//fin consulter
    }

    function setOnchange(&$form,$maj) {
    //javascript controle client
        $form->setOnchange('consultation','VerifNum(this)');
        $form->setOnchange('date_envoi','fdate(this)');
        $form->setOnchange('date_retour','fdate(this)');
        $form->setOnchange('date_limite','fdate(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("consultation", 11);
        $form->setTaille("dossier", 12);
        $form->setTaille("service", 10);
        $form->setTaille("date_envoi", 12);
        $form->setTaille("date_retour", 12);
        $form->setTaille("avis", 10);
        $form->setTaille("date_limite", 12);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("consultation", 11);
        $form->setMax("dossier", 12);
        $form->setMax("service", 5);
        $form->setMax("date_envoi", 12);
        $form->setMax("date_retour", 12);
        $form->setMax("avis", 2);
        $form->setMax("date_limite", 12);
    }


    function setLib(&$form,$maj) {
    //libelle des champs
        $form->setLib('consultation',_('consultation'));
        $form->setLib('dossier',_('dossier'));
        $form->setLib('service',_('service'));
        $form->setLib('date_envoi',_('date_envoi'));
        $form->setLib('date_retour',_('date_retour'));
        $form->setLib('avis',_('avis'));
        $form->setLib('date_limite',_('date_limite'));
    }

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

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

        // dossier
        $this->init_select($form, $db, $maj, $debug, "dossier",
                           $sql_dossier, $sql_dossier_by_id, false);

        // service
        $this->init_select($form, $db, $maj, $debug, "service",
                           $sql_service, $sql_service_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 =='avis')
                $form->setVal('avis', $idxformulaire);
            if($retourformulaire =='dossier')
                $form->setVal('dossier', $idxformulaire);
            if($retourformulaire =='service')
                $form->setVal('service', $idxformulaire);
        }// fin validation
    }// fin setValsousformulaire

    //==================================
    // cle secondaire  [secondary key]
    //==================================

}// fin classe
?>