<?php
//$Id$ 
//gen openMairie le 17/12/2013 15:51

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

class candidature_gen extends om_dbform {
    var $table="candidature";
    var $clePrimaire="candidature";
    var $typeCle="N";
    var $required_field=array(
        "agent",
        "bureau",
        "candidature",
        "periode",
        "poste",
        "scrutin"
    );
    var $retourformulaire;

    function setvalF($val) {
        //affectation valeur formulaire
        if (!is_numeric($val['candidature'])) {
            $this->valF['candidature'] = ""; // -> requis
        } else {
            $this->valF['candidature'] = $val['candidature'];
        }
        $this->valF['agent'] = $val['agent'];
        $this->valF['scrutin'] = $val['scrutin'];
        $this->valF['periode'] = $val['periode'];
        $this->valF['poste'] = $val['poste'];
        $this->valF['bureau'] = $val['bureau'];
        if ($val['recuperation'] == 1 || $val['recuperation'] == "t" || $val['recuperation'] == "Oui") {
            $this->valF['recuperation'] = true;
        } else {
            $this->valF['recuperation'] = false;
        }
            $this->valF['note'] = $val['note'];
        if ($val['decision'] == 1 || $val['decision'] == "t" || $val['decision'] == "Oui") {
            $this->valF['decision'] = true;
        } else {
            $this->valF['decision'] = false;
        }
            $this->valF['debut'] = $val['debut'];
            $this->valF['fin'] = $val['fin'];
    }

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

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

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

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

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

            if($this->retourformulaire=='bureau'
               and $form->val['bureau'] == $this->getParameter('idxformulaire')) {
                $form->setType('bureau','selecthiddenstatic');
            } else {
                $form->setType('bureau','select');
            }
            $form->setType('recuperation','checkbox');
            $form->setType('note','textarea');
            $form->setType('decision','checkbox');
            $form->setType('debut','text');
            $form->setType('fin','text');
        }// fin ajout
        if ($maj==1){ //modifier
            $form->setType('candidature','hiddenstatic');

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

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

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

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

            if($this->retourformulaire=='bureau'
               and $form->val['bureau'] == $this->getParameter('idxformulaire')) {
                $form->setType('bureau','selecthiddenstatic');
            } else {
                $form->setType('bureau','select');
            }
            $form->setType('recuperation','checkbox');
            $form->setType('note','textarea');
            $form->setType('decision','checkbox');
            $form->setType('debut','text');
            $form->setType('fin','text');
        }// fin modifier
        if ($maj==2){ //supprimer
            $form->setType('candidature','hiddenstatic');
            $form->setType('agent','selectstatic');
            $form->setType('scrutin','selectstatic');
            $form->setType('periode','selectstatic');
            $form->setType('poste','selectstatic');
            $form->setType('bureau','selectstatic');
            $form->setType('recuperation','hiddenstatic');
            $form->setType('note','hiddenstatic');
            $form->setType('decision','hiddenstatic');
            $form->setType('debut','hiddenstatic');
            $form->setType('fin','hiddenstatic');
        }//fin supprimer
        if ($maj==3){ //consulter
            $form->setType('candidature','static');
            $form->setType('agent','selectstatic');
            $form->setType('scrutin','selectstatic');
            $form->setType('periode','selectstatic');
            $form->setType('poste','selectstatic');
            $form->setType('bureau','selectstatic');
            $form->setType('recuperation','checkboxstatic');
            $form->setType('note','textareastatic');
            $form->setType('decision','checkboxstatic');
            $form->setType('debut','static');
            $form->setType('fin','static');
        }//fin consulter
    }

    function setOnchange(&$form,$maj) {
    //javascript controle client
        $form->setOnchange('candidature','VerifNum(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("candidature", 11);
        $form->setTaille("agent", 10);
        $form->setTaille("scrutin", 15);
        $form->setTaille("periode", 20);
        $form->setTaille("poste", 20);
        $form->setTaille("bureau", 10);
        $form->setTaille("recuperation", 1);
        $form->setTaille("note", 80);
        $form->setTaille("decision", 1);
        $form->setTaille("debut", 8);
        $form->setTaille("fin", 8);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("candidature", 11);
        $form->setMax("agent", 10);
        $form->setMax("scrutin", 15);
        $form->setMax("periode", 20);
        $form->setMax("poste", 20);
        $form->setMax("bureau", 4);
        $form->setMax("recuperation", 1);
        $form->setMax("note", 6);
        $form->setMax("decision", 1);
        $form->setMax("debut", 8);
        $form->setMax("fin", 8);
    }


    function setLib(&$form,$maj) {
    //libelle des champs
        $form->setLib('candidature',_('candidature'));
        $form->setLib('agent',_('agent'));
        $form->setLib('scrutin',_('scrutin'));
        $form->setLib('periode',_('periode'));
        $form->setLib('poste',_('poste'));
        $form->setLib('bureau',_('bureau'));
        $form->setLib('recuperation',_('recuperation'));
        $form->setLib('note',_('note'));
        $form->setLib('decision',_('decision'));
        $form->setLib('debut',_('debut'));
        $form->setLib('fin',_('fin'));
    }

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

        // agent
        $this->init_select($form, $db, $maj, $debug, "agent",
                           $sql_agent, $sql_agent_by_id, false);

        // bureau
        $this->init_select($form, $db, $maj, $debug, "bureau",
                           $sql_bureau, $sql_bureau_by_id, false);

        // periode
        $this->init_select($form, $db, $maj, $debug, "periode",
                           $sql_periode, $sql_periode_by_id, false);

        // poste
        $this->init_select($form, $db, $maj, $debug, "poste",
                           $sql_poste, $sql_poste_by_id, false);

        // scrutin
        $this->init_select($form, $db, $maj, $debug, "scrutin",
                           $sql_scrutin, $sql_scrutin_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 =='agent')
                $form->setVal('agent', $idxformulaire);
            if($retourformulaire =='bureau')
                $form->setVal('bureau', $idxformulaire);
            if($retourformulaire =='periode')
                $form->setVal('periode', $idxformulaire);
            if($retourformulaire =='poste')
                $form->setVal('poste', $idxformulaire);
            if($retourformulaire =='scrutin')
                $form->setVal('scrutin', $idxformulaire);
        }// fin validation
    }// fin setValsousformulaire

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

}// fin classe
?>