<?php
//$Id$ 
//gen openMairie le 17/02/2014 14:57

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

class affectation_gen extends om_dbform {
    var $table="affectation";
    var $clePrimaire="affectation";
    var $typeCle="N";
    var $required_field=array(
        "affectation",
        "bureau",
        "elu",
        "periode",
        "poste",
        "scrutin"
    );
    var $retourformulaire;

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

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

            if($this->retourformulaire=='elu'
               and $form->val['elu'] == $this->getParameter('idxformulaire')) {
                $form->setType('elu','selecthiddenstatic');
            } else {
                $form->setType('elu','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('note','textarea');
            $form->setType('decision','checkbox');

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

            if($this->retourformulaire=='elu'
               and $form->val['elu'] == $this->getParameter('idxformulaire')) {
                $form->setType('elu','selecthiddenstatic');
            } else {
                $form->setType('elu','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('note','textarea');
            $form->setType('decision','checkbox');

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

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

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("affectation", 11);
        $form->setMax("elu", 11);
        $form->setMax("scrutin", 15);
        $form->setMax("periode", 20);
        $form->setMax("poste", 20);
        $form->setMax("bureau", 4);
        $form->setMax("note", 6);
        $form->setMax("decision", 1);
        $form->setMax("candidat", 11);
    }


    function setLib(&$form,$maj) {
    //libelle des champs
        $form->setLib('affectation',_('affectation'));
        $form->setLib('elu',_('elu'));
        $form->setLib('scrutin',_('scrutin'));
        $form->setLib('periode',_('periode'));
        $form->setLib('poste',_('poste'));
        $form->setLib('bureau',_('bureau'));
        $form->setLib('note',_('note'));
        $form->setLib('decision',_('decision'));
        $form->setLib('candidat',_('candidat'));
    }

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

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

        // candidat
        $this->init_select($form, $db, $maj, $debug, "candidat",
                           $sql_candidat, $sql_candidat_by_id, false);

        // elu
        $this->init_select($form, $db, $maj, $debug, "elu",
                           $sql_elu, $sql_elu_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 =='bureau')
                $form->setVal('bureau', $idxformulaire);
            if($retourformulaire =='candidat')
                $form->setVal('candidat', $idxformulaire);
            if($retourformulaire =='elu')
                $form->setVal('elu', $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
?>