<?php
//$Id: om_widget.class.php 1847 2012-10-05 11:45:39Z fmichon $ 
//gen openMairie le 05/10/2012 13:40

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

class om_widget_gen extends om_dbform {
    var $table="om_widget";
    var $clePrimaire="om_widget";
    var $typeCle="N";
    var $required_field=array(
        "libelle",
        "lien",
        "om_collectivite",
        "om_profil",
        "om_widget",
        "texte"
    );
    var $retourformulaire;

    function setvalF($val) {
        //affectation valeur formulaire
        if (!is_numeric($val['om_widget'])) {
            $this->valF['om_widget'] = ""; // -> requis
        } else {
            $this->valF['om_widget'] = $val['om_widget'];
        }
        if (!is_numeric($val['om_collectivite'])) {
            $this->valF['om_collectivite'] = ""; // -> requis
        } else {
            if($_SESSION['niveau']==1) {
                $this->valF['om_collectivite'] = $_SESSION['collectivite'];
            } else {
                $this->valF['om_collectivite'] = $val['om_collectivite'];
            }
        }
        $this->valF['libelle'] = $val['libelle'];
        $this->valF['lien'] = $val['lien'];
            $this->valF['texte'] = $val['texte'];
        if (!is_numeric($val['om_profil'])) {
            $this->valF['om_profil'] = ""; // -> requis
        } else {
            $this->valF['om_profil'] = $val['om_profil'];
        }
    }

    //=================================================
    //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('om_widget','hidden');// cle automatique
            if($this->retourformulaire=='om_collectivite')
                if($_SESSION['niveau']==2) {
                    $form->setType('om_collectivite','selecthiddenstatic');
                } else {
                    $form->setType('om_collectivite','hidden');
                }
            else
                if($_SESSION['niveau']==2)
                    $form->setType('om_collectivite','select');
                else
                    $form->setType('om_collectivite','hidden');
            $form->setType('libelle','text');
            $form->setType('lien','text');
            $form->setType('texte','textarea');

            if($this->retourformulaire=='om_profil'
               and $form->val['om_profil'] == $this->getParameter('idxformulaire')) {
                $form->setType('om_profil','selecthiddenstatic');
            } else {
                $form->setType('om_profil','select');
            }
        }// fin ajout
        if ($maj==1){ //modifier
            $form->setType('om_widget','hiddenstatic');
            if($this->retourformulaire=='om_collectivite')
                if($_SESSION['niveau']==2) {
                    $form->setType('om_collectivite','selecthiddenstatic');
                } else {
                    $form->setType('om_collectivite','hidden');
                }
            else
                if($_SESSION['niveau']==2)
                    $form->setType('om_collectivite','select');
                else
                    $form->setType('om_collectivite','hidden');
            $form->setType('libelle','text');
            $form->setType('lien','text');
            $form->setType('texte','textarea');

            if($this->retourformulaire=='om_profil'
               and $form->val['om_profil'] == $this->getParameter('idxformulaire')) {
                $form->setType('om_profil','selecthiddenstatic');
            } else {
                $form->setType('om_profil','select');
            }
        }// fin modifier
        if ($maj==2){ //supprimer
            $form->setType('om_widget','hiddenstatic');
            if($_SESSION['niveau']==2) {
                $form->setType('om_collectivite','selectstatic');
            } else {
                $form->setType('om_collectivite','hidden');
            }
            $form->setType('libelle','hiddenstatic');
            $form->setType('lien','hiddenstatic');
            $form->setType('texte','hiddenstatic');
            $form->setType('om_profil','selectstatic');
        }//fin supprimer
        if ($maj==3){ //consulter
            $form->setType('om_widget','static');
            if($this->retourformulaire=='om_collectivite')
                if($_SESSION['niveau']==2) {
                    $form->setType('om_collectivite','selectstatic');
                } else {
                    $form->setType('om_collectivite','hidden');
                }
            else
                if($_SESSION['niveau']==2)
                    $form->setType('om_collectivite','selectstatic');
                else
                    $form->setType('om_collectivite','hidden');
            $form->setType('libelle','static');
            $form->setType('lien','static');
            $form->setType('texte','textareastatic');
            $form->setType('om_profil','selectstatic');
        }//fin consulter
    }

    function setOnchange(&$form,$maj) {
    //javascript controle client
        $form->setOnchange('om_widget','VerifNum(this)');
        $form->setOnchange('om_collectivite','VerifNum(this)');
        $form->setOnchange('om_profil','VerifNum(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("om_widget", 11);
        $form->setTaille("om_collectivite", 11);
        $form->setTaille("libelle", 30);
        $form->setTaille("lien", 30);
        $form->setTaille("texte", 80);
        $form->setTaille("om_profil", 11);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("om_widget", 11);
        $form->setMax("om_collectivite", 11);
        $form->setMax("libelle", 40);
        $form->setMax("lien", 80);
        $form->setMax("texte", 6);
        $form->setMax("om_profil", 11);
    }


    function setLib(&$form,$maj) {
    //libelle des champs
        $form->setLib('om_widget',_('om_widget'));
        $form->setLib('om_collectivite',_('om_collectivite'));
        $form->setLib('libelle',_('libelle'));
        $form->setLib('lien',_('lien'));
        $form->setLib('texte',_('texte'));
        $form->setLib('om_profil',_('om_profil'));
    }

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

        // om_collectivite
        $this->init_select($form, $db, $maj, $debug, "om_collectivite",
                           $sql_om_collectivite, $sql_om_collectivite_by_id, false);

        // om_profil
        $this->init_select($form, $db, $maj, $debug, "om_profil",
                           $sql_om_profil, $sql_om_profil_by_id, false);
    }// fin select

    function setVal(&$form,$maj,$validation,&$db,$DEBUG=null){
        if($validation==0 and $maj==0 and $_SESSION['niveau']==1) {
            $form->setVal('om_collectivite', $_SESSION['collectivite']);
        }// fin validation
    }// fin setVal

    //==================================
    // sous Formulaire  [subform]
    //==================================

    function setValsousformulaire(&$form,$maj,$validation,$idxformulaire,$retourformulaire,$typeformulaire,&$db,$DEBUG=null){
        $this->retourformulaire = $retourformulaire;
        if($validation==0 and $maj==0 and $_SESSION['niveau']==1) {
            $form->setVal('om_collectivite', $_SESSION['collectivite']);
        }// fin validation
        if($validation == 0) {
            if($retourformulaire =='om_collectivite')
                $form->setVal('om_collectivite', $idxformulaire);
            if($retourformulaire =='om_profil')
                $form->setVal('om_profil', $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 : om_tdb
        $this->rechercheTable($db, "om_tdb", "om_widget", $id);
    }


}// fin classe
?>