<?php
//$Id$ 
//gen openMairie le 05/09/2013 10:49

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

class agent_gen extends om_dbform {
    var $table="agent";
    var $clePrimaire="agent";
    var $typeCle="A";
    var $required_field=array(
        "adresse",
        "agent",
        "cp",
        "nom",
        "prenom",
        "ville"
    );
    var $retourformulaire;

    function setvalF($val) {
        //affectation valeur formulaire
        $this->valF['agent'] = $val['agent'];
        $this->valF['nom'] = $val['nom'];
        $this->valF['prenom'] = $val['prenom'];
        $this->valF['adresse'] = $val['adresse'];
        $this->valF['cp'] = $val['cp'];
        $this->valF['ville'] = $val['ville'];
        if ($val['telephone'] == "") {
            $this->valF['telephone'] = NULL;
        } else {
            $this->valF['telephone'] = $val['telephone'];
        }
        if ($val['service'] == "") {
            $this->valF['service'] = NULL;
        } else {
            $this->valF['service'] = $val['service'];
        }
        if ($val['telephone_pro'] == "") {
            $this->valF['telephone_pro'] = NULL;
        } else {
            $this->valF['telephone_pro'] = $val['telephone_pro'];
        }
        if ($val['grade'] == "") {
            $this->valF['grade'] = NULL;
        } else {
            $this->valF['grade'] = $val['grade'];
        }
    }

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

    function setType(&$form,$maj) {
        //type
        if ($maj==0){ //ajout
            $form->setType('agent','text');
            $form->setType('nom','text');
            $form->setType('prenom','text');
            $form->setType('adresse','text');
            $form->setType('cp','text');
            $form->setType('ville','text');
            $form->setType('telephone','text');

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

            if($this->retourformulaire=='grade'
               and $form->val['grade'] == $this->getParameter('idxformulaire')) {
                $form->setType('grade','selecthiddenstatic');
            } else {
                $form->setType('grade','select');
            }
        }// fin ajout
        if ($maj==1){ //modifier
            $form->setType('agent','hiddenstatic');
            $form->setType('nom','text');
            $form->setType('prenom','text');
            $form->setType('adresse','text');
            $form->setType('cp','text');
            $form->setType('ville','text');
            $form->setType('telephone','text');

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

            if($this->retourformulaire=='grade'
               and $form->val['grade'] == $this->getParameter('idxformulaire')) {
                $form->setType('grade','selecthiddenstatic');
            } else {
                $form->setType('grade','select');
            }
        }// fin modifier
        if ($maj==2){ //supprimer
            $form->setType('agent','hiddenstatic');
            $form->setType('nom','hiddenstatic');
            $form->setType('prenom','hiddenstatic');
            $form->setType('adresse','hiddenstatic');
            $form->setType('cp','hiddenstatic');
            $form->setType('ville','hiddenstatic');
            $form->setType('telephone','hiddenstatic');
            $form->setType('service','selectstatic');
            $form->setType('telephone_pro','hiddenstatic');
            $form->setType('grade','selectstatic');
        }//fin supprimer
        if ($maj==3){ //consulter
            $form->setType('agent','static');
            $form->setType('nom','static');
            $form->setType('prenom','static');
            $form->setType('adresse','static');
            $form->setType('cp','static');
            $form->setType('ville','static');
            $form->setType('telephone','static');
            $form->setType('service','selectstatic');
            $form->setType('telephone_pro','static');
            $form->setType('grade','selectstatic');
        }//fin consulter
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("agent", 10);
        $form->setTaille("nom", 30);
        $form->setTaille("prenom", 30);
        $form->setTaille("adresse", 30);
        $form->setTaille("cp", 10);
        $form->setTaille("ville", 30);
        $form->setTaille("telephone", 14);
        $form->setTaille("service", 10);
        $form->setTaille("telephone_pro", 14);
        $form->setTaille("grade", 10);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("agent", 10);
        $form->setMax("nom", 40);
        $form->setMax("prenom", 40);
        $form->setMax("adresse", 80);
        $form->setMax("cp", 5);
        $form->setMax("ville", 40);
        $form->setMax("telephone", 14);
        $form->setMax("service", 10);
        $form->setMax("telephone_pro", 14);
        $form->setMax("grade", 10);
    }


    function setLib(&$form,$maj) {
    //libelle des champs
        $form->setLib('agent',_('agent'));
        $form->setLib('nom',_('nom'));
        $form->setLib('prenom',_('prenom'));
        $form->setLib('adresse',_('adresse'));
        $form->setLib('cp',_('cp'));
        $form->setLib('ville',_('ville'));
        $form->setLib('telephone',_('telephone'));
        $form->setLib('service',_('service'));
        $form->setLib('telephone_pro',_('telephone_pro'));
        $form->setLib('grade',_('grade'));
    }

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

        // grade
        $this->init_select($form, $db, $maj, $debug, "grade",
                           $sql_grade, $sql_grade_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 =='grade')
                $form->setVal('grade', $idxformulaire);
            if($retourformulaire =='service')
                $form->setVal('service', $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 : candidature
        $this->rechercheTable($db, "candidature", "agent", $id);
    }


}// fin classe
?>