<?php
//$Id$ 
//gen openMairie le 01/08/2013 15:05

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

class scrutin_gen extends om_dbform {
    var $table="scrutin";
    var $clePrimaire="scrutin";
    var $typeCle="A";
    var $required_field=array(
        "canton",
        "date_scrutin",
        "libelle",
        "scrutin",
        "tour"
    );
    var $retourformulaire;

    function setvalF($val) {
        //affectation valeur formulaire
        $this->valF['scrutin'] = $val['scrutin'];
        $this->valF['libelle'] = $val['libelle'];
        $this->valF['tour'] = $val['tour'];
        $this->valF['canton'] = $val['canton'];
        if ($val['date_scrutin'] != "") {
            $this->valF['date_scrutin'] = $this->dateDB($val['date_scrutin']);
        }
        if ($val['solde'] == 1 || $val['solde'] == "t" || $val['solde'] == "Oui") {
            $this->valF['solde'] = true;
        } else {
            $this->valF['solde'] = false;
        }
        if ($val['convocation_agent'] == "") {
            $this->valF['convocation_agent'] = NULL;
        } else {
            $this->valF['convocation_agent'] = $val['convocation_agent'];
        }
        if ($val['convocation_president'] == "") {
            $this->valF['convocation_president'] = NULL;
        } else {
            $this->valF['convocation_president'] = $val['convocation_president'];
        }
    }

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

    function setType(&$form,$maj) {
        //type
        if ($maj==0){ //ajout
            $form->setType('scrutin','text');
            $form->setType('libelle','text');
            $form->setType('tour','text');

            if($this->retourformulaire=='canton'
               and $form->val['canton'] == $this->getParameter('idxformulaire')) {
                $form->setType('canton','selecthiddenstatic');
            } else {
                $form->setType('canton','select');
            }
            if($this->retourformulaire=='')
                $form->setType('date_scrutin','date');
            else
                $form->setType('date_scrutin','date2');
            $form->setType('solde','checkbox');
            $form->setType('convocation_agent','text');
            $form->setType('convocation_president','text');
        }// fin ajout
        if ($maj==1){ //modifier
            $form->setType('scrutin','hiddenstatic');
            $form->setType('libelle','text');
            $form->setType('tour','text');

            if($this->retourformulaire=='canton'
               and $form->val['canton'] == $this->getParameter('idxformulaire')) {
                $form->setType('canton','selecthiddenstatic');
            } else {
                $form->setType('canton','select');
            }
            if($this->retourformulaire=='')
                $form->setType('date_scrutin','date');
            else
                $form->setType('date_scrutin','date2');
            $form->setType('solde','checkbox');
            $form->setType('convocation_agent','text');
            $form->setType('convocation_president','text');
        }// fin modifier
        if ($maj==2){ //supprimer
            $form->setType('scrutin','hiddenstatic');
            $form->setType('libelle','hiddenstatic');
            $form->setType('tour','hiddenstatic');
            $form->setType('canton','selectstatic');
            $form->setType('date_scrutin','hiddenstatic');
            $form->setType('solde','hiddenstatic');
            $form->setType('convocation_agent','hiddenstatic');
            $form->setType('convocation_president','hiddenstatic');
        }//fin supprimer
        if ($maj==3){ //consulter
            $form->setType('scrutin','static');
            $form->setType('libelle','static');
            $form->setType('tour','static');
            $form->setType('canton','selectstatic');
            $form->setType('date_scrutin','datestatic');
            $form->setType('solde','checkboxstatic');
            $form->setType('convocation_agent','static');
            $form->setType('convocation_president','static');
        }//fin consulter
    }

    function setOnchange(&$form,$maj) {
    //javascript controle client
        $form->setOnchange('date_scrutin','fdate(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("scrutin", 15);
        $form->setTaille("libelle", 30);
        $form->setTaille("tour", 10);
        $form->setTaille("canton", 10);
        $form->setTaille("date_scrutin", 12);
        $form->setTaille("solde", 1);
        $form->setTaille("convocation_agent", 30);
        $form->setTaille("convocation_president", 30);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("scrutin", 15);
        $form->setMax("libelle", 40);
        $form->setMax("tour", 1);
        $form->setMax("canton", 8);
        $form->setMax("date_scrutin", 12);
        $form->setMax("solde", 1);
        $form->setMax("convocation_agent", 100);
        $form->setMax("convocation_president", 100);
    }


    function setLib(&$form,$maj) {
    //libelle des champs
        $form->setLib('scrutin',_('scrutin'));
        $form->setLib('libelle',_('libelle'));
        $form->setLib('tour',_('tour'));
        $form->setLib('canton',_('canton'));
        $form->setLib('date_scrutin',_('date_scrutin'));
        $form->setLib('solde',_('solde'));
        $form->setLib('convocation_agent',_('convocation_agent'));
        $form->setLib('convocation_president',_('convocation_president'));
    }

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

        // canton
        $this->init_select($form, $db, $maj, $debug, "canton",
                           $sql_canton, $sql_canton_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 =='canton')
                $form->setVal('canton', $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 : affectation
        $this->rechercheTable($db, "affectation", "scrutin", $id);
        // Verification de la cle secondaire : candidat
        $this->rechercheTable($db, "candidat", "scrutin", $id);
        // Verification de la cle secondaire : candidature
        $this->rechercheTable($db, "candidature", "scrutin", $id);
    }


}// fin classe
?>