<?php
/**
 * Ce fichier permet de declarer la classe formulaire.
 *
 * @package openmairie
 * @link http://www.openmairie.org/
 * @version SVN : $Id$
 */

/**
 * Cette classe a pour objet la construction des champs du formulaire suivant :
 * - $type    (tableau) : type de champ
 * - $val     (tableau) : valeur du champ
 * - $taille  (tableau) : taille du champ
 * - $max     (tableau) : saisie maximale autorisee pour le champ
 * - $lib     (tableau) : libelle de saisie
 * - $select  (tableau) : valeur des controles liste
 *                        [0] value
 *                        [1] libelle (<option>libelle</option>)
 * - $groupe  (tableau) : regroupement de champ par ligne
 * - $regroupe (tableau) : fieldset
 * - $enteteTab (string) : entete du formulaire
 */

(defined("FORMATDATE") ? "" : define("FORMATDATE", "AAAA-MM-JJ"));

class formulaire {
    
    /**
     * Entete
     * @var
     */
    var $enteteTab = "";
    
    /**
     * Valeur par defaut du champ
     * @var
     */
    var $val;
    
    /**
     * Type de champ
     * @var
     */
    var $type;
    
    /**
     * Taille du champ
     * @var
     */
    var $taille;
    
    /**
     * Nombre de caracteres maximum a saisir
     * @var
     */
    var $max;
    
    /**
     * Libelle du champ
     * @var
     */
    var $lib;
    
    /**
     * Regroupement
     * @var
     */
    var $groupe;
    
    /**
     * Valeur des listes
     * @var
     */
    var $select;
    
    /**
     * Javascript en cas de changement
     * @var
     */
    var $onchange;
    
    /**
     * Javascript en cas de keyup
     * @var
     */
    var $onkeyup;
    
    /**
     * Javascript en cas de clic
     * @var
     */
    var $onclick;
    
    /**
     * Fieldset
     * @var
     */
    var $regroupe;
    
    /**
     *
     * @var
     */
    var $correct;
    
    /**
     * Constructeur
     * 
     * Initialisation des tableaux de parametrage du formulaire
     * - valeur par defaut 
     *   en modification et suppression = initialiser par la valeur des champs
     *   en ajout = initialisation vide
     * - type par defaut
     *   text pour ajout et modification
     *   static pour suppression
     *
     * @param NULL $unused Parametre inutilise
     * @param integer $validation 
     * @param integer $maj
     * @param array $champs
     * @param array $val
     * @param array $max
     * @return void
     */
    function formulaire($unused = NULL, $validation, $maj, $champs = array(),
                        $val = array(), $max = array()) {
        
        //
        // valeur par defaut et type
        if ($maj == 0) { // ajouter
            for ($i = 0; $i < count($champs); $i++) {
                $this->val[$champs[$i]] = "";
                $this->type[$champs[$i]] = "text";
            }
        }
        if ($maj == 1) { // modifier
            if ($validation == 0) {
                $i = 0;
                foreach ($val as $elem){
                    $this->val[$champs[$i]] = strtr($elem, chr(34), "'");
                    $i++;
                }
            }
            for ($i = 0; $i < count($champs); $i++) {
                $this->type[$champs[$i]] = "text";
                if ($validation != 0) {
                    $this->val[$champs[$i]] = "";
                }
            }
        }
        if ($maj == 2) { // supprimer
            if ($validation == 0) {
                $i = 0;
                foreach ($val as $elem) {
                    $this->val[$champs[$i]] = strtr($elem, chr(34), "'");
                    $i++;
                }
            }
            for ($i = 0; $i < count($champs); $i++) {
                $this->type[$champs[$i]] = "static";
                if ($validation != 0) {
                    $this->val[$champs[$i]] = "";
                }
            }
        }
        // taille et longueur maximum
        $i = 0;
        foreach ($max as $elem) {
            $this->taille[$champs[$i]] = $elem;
            $this->max[$champs[$i]] = $elem;
            $i++;
        }
        // libelle, group, select, onchange
        for ($i = 0; $i<count($champs); $i++) {
            $this->lib[$champs[$i]] = ucwords($champs[$i]);
            $this->groupe[$champs[$i]] = "";
            $this->select[$champs[$i]][0] = "";
            $this->select[$champs[$i]][1] = "";
            $this->onchange[$champs[$i]] = "";
            $this->onkeyup[$champs[$i]] = "";
            $this->onclick[$champs[$i]] = "";
        }
        
    }
    
    // {{{ Methodes permettant l'affichage de la table contenant le formulaire
    
    /**
     * Entete
     *
     * @return void
     */
    function entete() {
        
        echo "\n<!-- ########## START FORMULAIRE ########## -->\n";
        echo "<table class=\"formEntete ui-corner-all\" cellpadding=\"0\" cellspacing=\"0\">\n";
        
    }
    
    /**
     * Enpied
     *
     * @return void
     */
    function enpied() {
        
        echo "\n</table>\n";
        echo "<!-- ########## END FORMULAIRE ########## -->\n";
        
    }
    
    /**
     * Cette methode permet d'afficher un champ dans une ligne de tableau ou
     * non en fonction de ces parametres
     * 
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     * @return void
     */
    function afficherChamp($champ, $validation, $DEBUG = false) {
        
        // Ouverture d'une nouvelle ligne de tableau si le champ ne fait pas
        // partie d'un Groupe (au milieu 'G' ou a la fin 'F' de ce groupe)
        if ($this->groupe[$champ] != "F" and $this->groupe[$champ] != "G") {
            echo "\n";
            echo "\t<tr>\n";
        }
        
        // Affichage de la cellule contenant le libelle du champ si le type du
        // champ n'est pas 'hidden'
        if ($this->type[$champ] != "hidden") {
            // Ouvertue de la cellule
            echo "\t\t<td class=\"formLibelle\">\n";
            // libelle du champ
            echo $this->lib[$champ];
            // Fermeture de la cellule
            echo "\n";
            echo "\t\t</td>\n";
            
        }
        
        // Ouverture de la cellule
        echo "\t\t<td";
        if ($this->type[$champ] == "hidden") {
            // Si le type du champ est 'hidden' alors on ajoute la propriete
            // style pour ne pas afficher la cellule en css pour que le code
            // reste xhtml valide
            echo " colspan=\"2\" style=\"display:none;\"";
        }
        echo ">\n";
        
        // Affichage du champ en fonction de son type
        $fonction = $this->type[$champ];
        if ($fonction == "static") {
            $fonction = "statiq";
        }
        $this->$fonction($champ, $validation);
        
        // Fermeture de la cellule
        echo "\n";
        echo "\t\t</td>\n";
        
        // Fermeture de la ligne de tableau si le champ ne fait pas partie
        // d'un Groupe (au debut 'F' ou au milieu 'G' de ce groupe)
        if ($this->groupe[$champ] != "D" and $this->groupe[$champ] != "G") {
            echo "\t</tr>\n";
        }
        
    }
    
    /**
     * Cette methode permet d'afficher un champ dans un fieldset ou non en
     * fonction de ces parametres
     * 
     * @param string $champ Identifiant du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     * @return void
     */
    function afficherChampRegroupe($champ, $validation, $DEBUG = false) {
        
        // Ouverture d'une nouvelle ligne de tableau pour afficher un fieldset
        // si le champ est le debut 'D' d'un Regroupe et si le type du champ
        // n'est pas 'hidden'
        if ($this->type[$champ] != "hidden"
            and $this->regroupe[$champ][0] == "D") {
            // Ouverture d'une nouvelle ligne de tableau et d'une nouvelle
            // cellule
            echo "\n";
            echo "\t<tr>\n";
            echo "\t\t<td colspan=\"2\">\n";
            // Ouverture du fieldset
            echo "<fieldset";
            echo " class=\"cadre ui-corner-all ui-widget-content";
            if (isset($this->regroupe[$champ][2])
                and $this->regroupe[$champ][2] != "") {
                echo " ".$this->regroupe[$champ][2]."";
            }
            echo "\"";
            echo ">\n";
            echo "<legend class=\"ui-corner-all ui-widget-content ui-state-active\">";
            echo $this->regroupe[$champ][1];
            echo "</legend>\n";
            // Ouverture d'une table
            echo "<table>\n";
        }
        
        // 
        $this->afficherChamp($champ, $validation);
        
        // Fermeture de la ligne de tableau pour fermer le fieldset
        // si le champ est la fin 'F' d'un Regroupe et si le type du champ
        // n'est pas 'hidden'
        if ($this->type[$champ] != "hidden"
            and $this->regroupe[$champ][0] == "F") {
            // Fermeture de la table
            echo "\n";
            echo "</table>\n";
            // Fermeture du fieldset
            echo "</fieldset>\n";
            // Fermeture de la cellule et de la ligne de tableau
            echo "\t\t</td>\n";
            echo "\t</tr>\n";
        }
        
    }
    
    /**
     * Cette methode permet d'afficher
     *
     * @param array $champs Liste des identifiants des champs 
     * @param integer $validation - 0 1er passage
     *                            - > 0 passage suivant suite validation
     * @param boolean $DEBUG Parametre inutilise
     * @param boolean $correct
     */
    function afficher($champs, $validation, $DEBUG = false, $correct) {
        
        //
        $this->correct = $correct;
        
        //
        for ($i = 0; $i < count($champs); $i++) {
            //
            if (isset($this->regroupe[$champs[$i]])) {
                $this->afficherChampRegroupe($champs[$i], $validation);
            } else {
                $this->afficherChamp($champs[$i], $validation);
            }
        }
        
    }
    
    // }}}
    
    
    
    /**
     *
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function affichepdf($champ, $validation, $DEBUG = false) {
        
        //
        $scan_pdf = $this->val[$champ];
        //
        echo "<object data='".$scan_pdf."' name='".$champ."' value=\"".
        $scan_pdf."\" type='application/pdf' width='650' height='200'>";
        echo "</object>";
        
    }
    
    /**
     * La valeur du champ est passe par le controle hidden
     *
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function hiddenstatic($champ, $validation, $DEBUG = false) {
        
        //
        echo "<input";
        echo " type=\"hidden\"";
        echo " name=\"".$champ."\"";
        echo " value=\"".$this->val[$champ]."\"";
        echo " class=\"champFormulaire\"";
        echo " />\n";
        echo $this->val[$champ]."\n";
        
    }
    
    /**
     * La valeur du champ est passe par le controle hidden
     *
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function hiddenstaticnum($champ, $validation, $DEBUG = false) {
        
        echo "<input type='hidden' ";
        echo "name='".$champ."' ";
        echo "value=\"".$this->val[$champ]."\" ";
        echo "class='champFormulaire' >\n";
        echo "<p align='right'>".$this->val[$champ]."</p>\n";
        
    }
    
    /**
     * La valeur du champ n est pas passe, affichage du champ en texte
     *
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function textareahiddenstatic($champ, $validation, $DEBUG = false) {
        
        echo "<input type='hidden' ";
        echo "name='".$champ."' ";
        echo "value=\"".$this->val[$champ]."\" ";
        echo "class='champFormulaire' >\n";
        $this->val[$champ] = str_replace("\n","<br>",$this->val[$champ]);
        echo $this->val[$champ]."\n";
        
    }
    
    /**
     * La valeur du champ est passe par le controle hidden
     *
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function hiddenstaticdate($champ, $validation, $DEBUG = false) {
        
        //
        if ($this->val[$champ] != "" and $validation == 0) {
            $defautDate = $this->dateAff($this->val[$champ]);
        } else {
            $defautDate = $this->val[$champ];
        }
        //
        if (!$this->correct) {
            echo "<input type='hidden' ";
            echo "name='".$champ."' ";
            echo "value=\"".$defautDate."\" ";
            echo "class='champFormulaire' />\n";
            echo $defautDate."";
        } else {
            echo $this->val[$champ]."\n";
        }
        
    }
    
    /**
     * La valeur du champ n'est pas conservee
     *
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function statiq($champ, $validation, $DEBUG = false) {
        
        echo $this->val[$champ]."\n";
        
    }
    
    /**
     * 
     *
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function textarea($champ, $validation, $DEBUG = false) {
        
        //
        echo "<textarea";
        echo " name=\"".$champ."\"";
        echo " cols=\"".$this->taille[$champ]."\"";
        echo " rows=\"".$this->max[$champ]."\"";
        echo " class=\"champFormulaire\"";
        if (!$this->correct) {
            if (isset($this->onchange) and $this->onchange[$champ] != "") {
                echo " onchange=\"".$this->onchange[$champ]."\"";
            }
            if (isset($this->onkeyup) and $this->onkeyup[$champ] != "") {
                echo " onkeyup=\"".$this->onkeyup[$champ]."\"";
            }
            if (isset($this->onclick) and $this->onclick[$champ] != "") {
                echo " onclick=\"".$this->onclick[$champ]."\"";
            }
        } else {
            echo " disabled=\"disabled\"";
        }
        echo ">\n";
        echo $this->val[$champ];
        echo "</textarea>\n";
        
    }
    
    /**
     * Page HTML : les \n => <br> en affichage
     *
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function pagehtml($champ, $validation, $DEBUG = false) {
        
        //
        if ($this->val[$champ] != "" and $validation == 0) {
            $this->val[$champ] = str_replace("<br>", "\n", $this->val[$champ]);
        }
        //
        if (!$this->correct) {
            echo "<textarea ";
            echo "name='".$champ."' ";
            echo "cols=".$this->taille[$champ]." ";
            echo "rows=".$this->max[$champ]." ";
            echo "onchange=\"".$this->onchange[$champ]."\" ";
            echo "class='champFormulaire' >";
            echo $this->val[$champ];
            echo "</textarea>\n";
        } else {
            echo "<textarea ";
            echo "name='".$champ."' ";
            echo "cols=".$this->taille[$champ]." ";
            echo "rows=".$this->max[$champ]." ";
            echo "onchange=\"".$this->onchange[$champ]."\" ";
            echo "class='champFormulaire' ";
            echo "disabled=\"disabled\" >";
            echo $this->val[$champ];
            echo "</textarea>\n";
        }
        
    }
    
    /**
     * Recuperation d une valeur dans un champ
     * - le champ d origine = $this->select[$champ][0]
     * - le champ d arrive = $champPage HTML : les \n => <br> en affichage
     *
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function textareamulti($champ, $validation, $DEBUG = false) {
        
        if (!$this->correct) {
            //
            echo "<input";
            echo " type=\"button\"";
            echo " onclick=\"selectauto('".$champ."','".$this->select[$champ][0]."')\"";
            echo " value=\"->\" ";
            echo " class=\"boutonmulti\"";
            echo " />\n";
        }
        //
        echo "<textarea";
        echo " name=\"".$champ."\"";
        echo " cols=\"".$this->taille[$champ]."\"";
        echo " rows=\"".$this->max[$champ]."\"";
        echo " class=\"champFormulaire champmulti\"";
        if (!$this->correct) {
            if (isset($this->onchange) and $this->onchange[$champ] != "") {
                echo " onchange=\"".$this->onchange[$champ]."\"";
            }
            if (isset($this->onkeyup) and $this->onkeyup[$champ] != "") {
                echo " onkeyup=\"".$this->onkeyup[$champ]."\"";
            }
            if (isset($this->onclick) and $this->onclick[$champ] != "") {
                echo " onclick=\"".$this->onclick[$champ]."\"";
            }
        } else {
            echo " disabled=\"disabled\"";
        }
        echo ">\n";
        echo $this->val[$champ];
        echo "</textarea>\n";
        
    }
    
    /**
     * La date est saisie ou affichee sous le format JJ/MM/AAAA, un calendrier
     * s affiche en js
     *
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function date($champ, $validation, $DEBUG = false) {
        
        //
        if ($this->val[$champ] != "" and $validation == 0) {
            $this->val[$champ] = $this->dateAff($this->val[$champ]);
        }
        //
        echo "<input";
        echo " type=\"text\"";
        echo " name=\"".$champ."\"";
        echo " value=\"".$this->val[$champ]."\"";
        echo " size=\"".$this->taille[$champ]."\"";
        echo " maxlength=\"10\"";
        if (!$this->correct) {
            echo " class=\"champFormulaire datepicker\"";
            if ($this->onchange != "") {
                echo " onchange=\"".$this->onchange[$champ]."\"";
            }
            if ($this->onkeyup != "") {
                echo " onkeyup=\"".$this->onkeyup[$champ]."\"";
            }
            if ($this->onclick != "") {
                echo " onclick=\"".$this->onclick[$champ]."\"";
            }
        } else {
            echo " class=\"champFormulaire\"";
            echo " disabled=\"disabled\"";
        }
        echo " />\n";
        
    }
    
    /**
     * Date en Full Onglet, la date est saisie ou affichee sous le format
     * JJ/MM/AAAA, un calendrier s affiche en js
     *
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function date2($champ, $validation, $DEBUG = false) {
        
        //
        $this->date($champ, $validation);
        
    }
    
    /**
     * SELECT - Affichage de table
     * - select['nomduchamp'][0]= value de l option
     * - $select['nomduchamp'][1]= affichage
     * 
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function select($champ, $validation, $DEBUG = false) {
        
        //
        if (!$this->correct) {
            if ($this->onchange[$champ] != "") {
                echo "<select ";
                echo "name='".$champ."' ";
                echo "size='1' ";
                echo "onchange=\"".$this->onchange[$champ]."\" ";
                echo "class='champFormulaire' >\n";
            } else {
                echo "<select ";
                echo "name='".$champ."' ";
                echo "size='1' ";
                echo "class='champFormulaire' >\n";
            }
        } else {
            echo "<select ";
            echo "name='".$champ."' ";
            echo "size='1' ";
            echo "class='champFormulaire' ";
            echo "disabled=\"disabled\" >\n";
        }
        //
        $k = 0;
        foreach ($this->select[$champ] as $elem) {
            while ($k <count($elem)) {
                if (!$this->correct) {
                    if ($this->val[$champ] == $this->select[$champ][0][$k]) {
                        echo "\t<option ";
                        echo "selected=\"selected\" ";
                        echo "value=\"".$this->select[$champ][0][$k]."\">";
                        echo $this->select[$champ][1][$k];
                        echo "</option>\n";
                    } else {
                        echo "\t<option ";
                        echo "value=\"".$this->select[$champ][0][$k]."\">";
                        echo $this->select[$champ][1][$k];
                        echo "</option>\n";
                    }
                    $k++;
                } else {
                    if ($this->val[$champ] == $this->select[$champ][0][$k]) {
                        echo "\t<option ";
                        echo "selected=\"selected\" ";
                        echo "value=\"".$this->select[$champ][0][$k]."\" >";
                        echo $this->select[$champ][1][$k];
                        echo "</option>\n";
                        $k = count($elem);
                    }
                    $k++;
                }
            }
        }
        //
        echo "</select>";
        
    }
    
    /**
     * SELECT disbaled - Affichage champ + lien mais pas modification de
     * donnees $val
     * 
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function selectdisabled($champ, $validation, $DEBUG = false) {
        
        //
        echo "<select ";
        echo "name='".$champ."' ";
        echo "size='1' ";
        echo "class='champFormulaire' ";
        echo "disabled=\"disabled\">\n";
        //
        $k = 0;
        foreach ($this->select[$champ] as $elem) {
            while ($k < count($elem)) {
                if (!$this->correct) {
                    if ($this->val[$champ] == $this->select[$champ][0][$k]) {
                        echo "\t<option ";
                        echo "selected=\"selected\" ";
                        echo "value=\"".$this->select[$champ][0][$k]."\">";
                        echo $this->select[$champ][1][$k];
                        echo "</option>\n";
                    }
                    $k++;
                } else {
                    if ($this->val[$champ] == $this->select[$champ][0][$k]){
                        echo "\t<option ";
                        echo "selected=\"selected\" ";
                        echo "value=\"".$this->select[$champ][0][$k]."\">";
                        echo $this->select[$champ][1][$k];
                        echo "</option>\n";
                        $k = count($elem);
                    }
                    $k++;
                }
            }
        }
        //
        echo "</select>\n";
        
    }
    
    /**
     * 
     * 
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function text($champ, $validation, $DEBUG = false) {
        
        //
        echo "<input";
        echo " type=\"".$this->type[$champ]."\"";
        echo " name=\"".$champ."\"";
        echo " value=\"".$this->val[$champ]."\"";
        echo " size=\"".$this->taille[$champ]."\"";
        echo " maxlength=\"".$this->max[$champ]."\"";
        echo " class=\"champFormulaire\"";
        if (!$this->correct) {
            if (isset($this->onchange) and $this->onchange[$champ] != "") {
                echo " onchange=\"".$this->onchange[$champ]."\"";
            }
            if (isset($this->onkeyup) and $this->onkeyup[$champ] != "") {
                echo " onkeyup=\"".$this->onkeyup[$champ]."\"";
            }
            if (isset($this->onclick) and $this->onclick[$champ] != "") {
                echo " onclick=\"".$this->onclick[$champ]."\"";
            }
        } else {
            echo " disabled=\"disabled\"";
        }
        echo " />\n";
        
    }
    
    /**
     * 
     * 
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function hidden($champ, $validation, $DEBUG = false) {
        
        //
        echo "<input";
        echo " type=\"".$this->type[$champ]."\"";
        echo " name=\"".$champ."\"";
        echo " value=\"".$this->val[$champ]."\"";
        //echo " size=\"".$this->taille[$champ]."\"";
        //echo " maxlength=\"".$this->max[$champ]."\"";
        echo " class=\"champFormulaire\"";
        if (!$this->correct) {
            if (isset($this->onchange) and $this->onchange[$champ] != "") {
                echo " onchange=\"".$this->onchange[$champ]."\"";
            }
            if (isset($this->onkeyup) and $this->onkeyup[$champ] != "") {
                echo " onkeyup=\"".$this->onkeyup[$champ]."\"";
            }
            if (isset($this->onclick) and $this->onclick[$champ] != "") {
                echo " onclick=\"".$this->onclick[$champ]."\"";
            }
        } else {
            echo " disabled=\"disabled\"";
        }
        echo " />\n";
        
    }
    
    /**
     * 
     * 
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function password($champ, $validation, $DEBUG = false) {
        
        //
        echo "<input";
        echo " type=\"".$this->type[$champ]."\"";
        echo " name=\"".$champ."\"";
        echo " value=\"".$this->val[$champ]."\"";
        echo " size=\"".$this->taille[$champ]."\"";
        echo " maxlength=\"".$this->max[$champ]."\"";
        echo " class=\"champFormulaire\"";
        if (!$this->correct) {
            if (isset($this->onchange) and $this->onchange[$champ] != "") {
                echo " onchange=\"".$this->onchange[$champ]."\"";
            }
            if (isset($this->onkeyup) and $this->onkeyup[$champ] != "") {
                echo " onkeyup=\"".$this->onkeyup[$champ]."\"";
            }
            if (isset($this->onclick) and $this->onclick[$champ] != "") {
                echo " onclick=\"".$this->onclick[$champ]."\"";
            }
        } else {
            echo " disabled=\"disabled\"";
        }
        echo " />\n";
        
    }
    
    /**
     * textDisabled - pas de passage de parametre
     * 
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function textdisabled($champ, $validation, $DEBUG = false) {
        
        //
        echo "<input";
        echo " type=\"text\"";
        echo " name=\"".$champ."\"";
        echo " value=\"".$this->val[$champ]."\"";
        echo " size=\"".$this->taille[$champ]."\"";
        echo " maxlength=\"".$this->max[$champ]."\"";
        echo " class=\"champFormulaire\"";
        echo " disabled=\"disabled\"";
        echo " />\n";
        
    }
    
    /**
     * textreadonly - champ texte non modifiable - pas de passage de parametre
     * 
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function textreadonly($champ, $validation, $DEBUG = false) {
        
        //
        echo "<input";
        echo " type=\"text\"";
        echo " name=\"".$champ."\"";
        echo " value=\"".$this->val[$champ]."\"";
        echo " size=\"".$this->taille[$champ]."\"";
        echo " maxlength=\"".$this->max[$champ]."\"";
        echo " class=\"champFormulaire\"";
        echo " readonly=\"readonly\"";
        echo " />\n";
     
    }
    
    /**
     * Checkbox
     * 
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function checkbox($champ, $validation, $DEBUG = false) {
        
        //
        if ($this->val[$champ] == "Oui") {
            $value = "Oui";
            $checked = " checked=\"checked\"";
        } else {
            $value = "";
            $checked = "";
        }
        //
        echo "<input";
        echo " type=\"".$this->type[$champ]."\"";
        echo " name=\"".$champ."\"";
        echo " value=\"".$value."\"";
        echo " size=\"".$this->taille[$champ]."\"";
        echo " maxlength=\"".$this->max[$champ]."\"";
        echo " class=\"champFormulaire\"";
        echo $checked;
        if (!$this->correct) {
            echo " onchange=\"changevaluecheckbox(this);";
            if (isset($this->onchange) and $this->onchange[$champ] != "") {
                echo "".$this->onchange[$champ]."";
            }
            echo "\"";
            if (isset($this->onkeyup) and $this->onkeyup[$champ] != "") {
                echo " onkeyup=\"".$this->onkeyup[$champ]."\"";
            }
            if (isset($this->onclick) and $this->onclick[$champ] != "") {
                echo " onclick=\"".$this->onclick[$champ]."\"";
            }
        } else {
            echo " disabled=\"disabled\"";
        }
        echo " />\n";
        
    }

    /**
     * Checkboxnum
     * 
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function checkboxnum($champ, $validation, $DEBUG = false) {
        
        //
        if($this->val[$champ] == 1) {
            $value = 1;
            $checked = "checked ";
        } else {
            $value = 0;
            $checked = "";
        }
        //
        if (!$this->correct) {
            if ($this->onchange != "") {
                echo "<input type='checkbox' ";
                echo "name='".$champ."' ";
                echo "value=\"$value\" ";
                echo "size=".$this->taille[$champ]." ";
                echo "maxlength=".$this->max[$champ]." ";
                echo "onchange=\"changevaluecheckboxnum(this);".$this->onchange[$champ]."\" ";
                echo "class='champFormulaire' ";
                echo $checked;
                echo ">\n";
            } else {
                echo "<input type='checkbox' ";
                echo "name='".$champ."' ";
                echo "value=\"$value\" ";
                echo "size=".$this->taille[$champ]." ";
                echo "maxlength=".$this->max[$champ]." ";
                echo "onchange=\"changevaluecheckboxnum(this)\" ";
                echo "class='champFormulaire' ";
                echo $checked;
                echo ">\n";
            }
        } else {
            echo "<input type='checkbox' ";
            echo "name='".$champ."' ";
            echo "value=\"$value\" ";
            echo "size=".$this->taille[$champ]." ";
            echo "maxlength=".$this->max[$champ]." ";
            echo "onchange=\"changevaluecheckboxnum(this)\" ";
            echo "class='champFormulaire' ";
            echo "disabled=\"disabled\" ";
            echo $checked;
            echo ">\n";
        }
        
    }
    
    /**
     * Combo gauche
     * (recherche de correspondance entre table importante)
     * $select['code_departement_naissance'][0][0]="departement";// table
     * $select['code_departement_naissance'][0][1]="code"; // zone origine
     * $select['code_departement_naissance'][1][0]="libelle_departement"; // zone correl
     * $select['code_departement_naissance'][1][1]="libelle_departement_naissance"; // champ correl
     * (facultatif)
     * $select['code_departement_naissance'][2][0]="code_departement"; // champ pour le where
     * $select['code_departement_naissance'][2][1]="code_departement_naissance"; // zone du formulaire concernee
     *
     * 
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function comboG($champ, $validation, $DEBUG = false) {
        
        if (!$this->correct) {
            // zone libelle
            $tab = $this->select[$champ][0][0];
            $zorigine = $this->select[$champ][0][1];
            $zcorrel = $this->select[$champ][1][0];
            $correl = $this->select[$champ][1][1];
            if (isset($this->select[$champ][2][0])) {
                $zcorrel2 = $this->select[$champ][2][1];
                $correl2 = $this->select[$champ][2][0];
            } else {
                $zcorrel2 = "s1"; // valeur du champ submit (sinon pb dans js)
                $correl2 = "";
            }
            $params = "&amp;table=".$tab."&amp;correl=".$correl."&amp;zorigine=".$zorigine."&amp;zcorrel=".$zcorrel."&amp;correl2=".$correl2;
            //
            echo "<a class=\"combog ui-state-default ui-corner-all\" href=\"javascript:vcorrel('".$champ."','".$zcorrel2."','".$params."');\">\n";
            echo "<span class=\"ui-icon ui-icon-circle-arrow-w\" ";
            echo "title=\""._("Cliquer ici pour correler")."\">";
            echo "<- "._("Correler");
            echo "</span>";
            echo "</a>\n";
        }
        
        echo "<input ";
        echo "type=\"text\" ";
        //echo "type=\"".$this->type[$champ]."\" ";
        echo " autocomplete=\"off\" ";
        echo "name=\"".$champ."\" ";
        echo "value=\"".$this->val[$champ]."\" ";
        echo "size=\"".$this->taille[$champ]."\" ";
        echo "maxlength=\"".$this->max[$champ]."\" ";
        if (!$this->correct) {
            if ($this->onchange != "") {
                echo "onchange=\"".$this->onchange[$champ]."\" ";
            }
        } else {
            echo "disabled=\"disabled\" ";
        }
        echo "class=\"champFormulaire combog\" ";
        echo "/>\n";
        
    }
    
    /**
     * comboG2 [sousform]
     *
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function comboG2($champ, $validation, $DEBUG = false) {
        
        if (!$this->correct) {
            // zone libelle
            $tab = $this->select[$champ][0][0];
            $zorigine = $this->select[$champ][0][1];
            $zcorrel = $this->select[$champ][1][0];
            $correl = $this->select[$champ][1][1];
            if (isset($this->select[$champ][2][0])) {
                $zcorrel2 = $this->select[$champ][2][1];
                $correl2 = $this->select[$champ][2][0];
            } else {
                $zcorrel2 = "s1"; // valeur du champ submit (sinon pb dans js)
                $correl2 = "";
            }
            $params="&table=".$tab."&correl=".$correl."&zorigine=".$zorigine."&zcorrel=".$zcorrel."&correl2=".$correl2;
            // appel vcorrel2
            echo "<a class=\"combog ui-state-default ui-corner-all\" href=\"javascript:vcorrel2('".$champ."','".$zcorrel2."','".$params."');\">";
            echo "<span class=\"ui-icon ui-icon-circle-arrow-w\" ";
            echo "title=\""._("Cliquer ici pour correler")."\">";
            echo "<- "._("Correler");
            echo "</span>";
            echo "</a>";
            //
            echo "<input type=".$this->type[$champ]." ";
            echo "name='".$champ."' ";
            echo " autocomplete=\"off\" ";
            echo "value=\"".$this->val[$champ]."\" ";
            echo "size=".$this->taille[$champ]." ";
            echo "maxlength=".$this->max[$champ]." ";
            echo "onchange=\"".$this->onchange[$champ]."\" ";
            echo "class='champFormulaire combog' ";
            echo ">\n";
        } else {
            echo "<input type=".$this->type[$champ]." ";
            echo "name='".$champ."' ";
            echo "value=\"".$this->val[$champ]."\" ";
            echo "size=".$this->taille[$champ]." ";
            echo "maxlength=".$this->max[$champ]." ";
            echo "class='champFormulaire combog' ";
            echo "disabled=\"disabled\"";
            echo ">\n";
        }
        
    }
    
    /**
     * Combo droit (recherche de correspondance entre table importante)
     * $select['code_departement_naissance'][0][0]="departement";// table
     * $select['code_departement_naissance'][0][1]="code"; // zone origine
     * $select['code_departement_naissance'][1][0]="libelle_departement"; // zone correl
     * $select['code_departement_naissance'][1][1]="libelle_departement_naissance"; // champ correl
     * (facultatif)
     * $select['code_departement_naissance'][2][0]="code_departement"; // champ pour le where
     * $select['code_departement_naissance'][2][1]="code_departement_naissance"; // zone du formulaire concern?
     *
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function comboD($champ, $validation, $DEBUG = false) {
        
        echo "<input ";
        echo "type=\"text\" ";
        //echo "type=\"".$this->type[$champ]."\" ";
        echo "name=\"".$champ."\" ";
        echo "value=\"".$this->val[$champ]."\" ";
        echo " autocomplete=\"off\" ";
        echo "size=\"".$this->taille[$champ]."\" ";
        echo "maxlength=\"".$this->max[$champ]."\" ";
        if (!$this->correct) {
            if ($this->onchange != "") {
                echo "onchange=\"".$this->onchange[$champ]."\" ";
            }
        } else {
            echo "disabled=\"disabled\" ";
        }
        echo "class=\"champFormulaire combod\" ";
        echo "/>\n";
        
        if (!$this->correct) {
            //
            $tab = $this->select[$champ][0][0];
            $zorigine = $this->select[$champ][0][1];
            $zcorrel = $this->select[$champ][1][0];
            $correl = $this->select[$champ][1][1];
            if (isset($this->select[$champ][2][0])) {
                $zcorrel2 = $this->select[$champ][2][1];
                $correl2 = $this->select[$champ][2][0];
            } else {
                $zcorrel2 = "s1";  // valeur du champ submit (sinon pb dans js)
                $correl2 = "";
            }
            $params = "&amp;table=".$tab."&amp;correl=".$correl."&amp;zorigine=".$zorigine."&amp;zcorrel=".$zcorrel."&amp;correl2=".$correl2;
            echo "<a class=\"combod ui-state-default ui-corner-all\" href=\"javascript:vcorrel('".$champ."','".$zcorrel2."','".$params."');\">\n";
            echo "<span class=\"ui-icon ui-icon-circle-arrow-e\" ";
            echo "title=\""._("Cliquer ici pour correler")."\">";
            echo "-> "._("Correler");
            echo "</span>";
            echo "</a>\n";
        }
        
    }
    
    /**
     * combo D2 pour F2 (sousformdyn)
     * 
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function comboD2($champ, $validation, $DEBUG = false) {
        
        if ($this->correct) {
            echo "<input type='".$this->type[$champ]."' ";
            echo "name='".$champ."' ";
            echo "value=\"".$this->val[$champ]."\" ";
            echo "size='".$this->taille[$champ]."' ";
            echo "maxlength='".$this->max[$champ]."' ";
            echo "class='champFormulaire combod' ";
            echo "disabled=\"disabled\" ";
            echo ">\n";
        } else {
            echo "<input type='".$this->type[$champ]."' ";
            echo "name='".$champ."' ";
            echo "value=\"".$this->val[$champ]."\" ";
            echo " autocomplete=\"off\" ";
            echo "size='".$this->taille[$champ]."' ";
            echo "maxlength='".$this->max[$champ]."' ";
            echo "onchange=\"".$this->onchange[$champ]."\" ";
            echo "class='champFormulaire combod' ";
            echo ">\n";
            //
            $tab = $this->select[$champ][0][0];
            $zorigine = $this->select[$champ][0][1];
            $zcorrel = $this->select[$champ][1][0];
            $correl = $this->select[$champ][1][1];
            if (isset($this->select[$champ][2][0])) {
                $zcorrel2 = $this->select[$champ][2][1];
                $correl2 = $this->select[$champ][2][0];
            } else {
                $zcorrel2 = "s1";  // valeur du champ submit (sinon pb dans js)
                $correl2 = "";
            }
            $params = "&table=".$tab."&correl=".$correl."&zorigine=".$zorigine."&zcorrel=".$zcorrel."&correl2=".$correl2;
            // appel vcorrel2
            echo "<a class=\"combod ui-state-default ui-corner-all\" href=\"javascript:vcorrel2('".$champ."','".$zcorrel2."','".$params."');\">";
            echo "<span class=\"ui-icon ui-icon-circle-arrow-e\" ";
            echo "title=\""._("Cliquer ici pour correler")."\">";
            echo "-> "._("Correler");
            echo "</span>";
            echo "</a>\n";
        }
        
    }
    
    /**
     * combo en cascade ex: voie -> zone -> cimetiere
     *
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function comboC($champ, $validation, $DEBUG = false) {
        
        $tab=$this->select[$champ][0][0];
        $zorigine=$this->select[$champ][0][1];
        $zcorrel=$this->select[$champ][1][0];
        $correl=$this->select[$champ][1][1];
        if(isset($this->select[$champ][2][0])){
        $zcorrel2=$this->select[$champ][2][1];
        $correl2=$this->select[$champ][2][0];
        }else{
        $zcorrel2="s1"; // valeur du champ submit (sinon pb dans js)
        $correl2="";
        }
        $params="&table=".$tab."&correl=".$correl."&zorigine=".$zorigine."&zcorrel=".$zcorrel."&correl2=".$correl2;
        
        echo "<a class=\"combog ui-state-default ui-corner-all\" href=\"javascript:vcorrel('".$champ."','".$zcorrel2."','".$params."');\">";
        echo "<span class=\"ui-icon ui-icon-circle-arrow-w\" ";
        echo "title=\""._("Cliquer ici pour correler")."\">";
        echo "<- "._("Correler");
        echo "</span>";
        echo "</a>\n";
        
        echo "<input type='".$this->type[$champ]."' ";
        echo " name='".$champ."' ";
        echo " value=\"".$this->val[$champ]."\" ";
        echo " autocomplete=\"off\" ";
        echo " size='".$this->taille[$champ]."' ";
        echo " maxlength='".$this->max[$champ]."' ";
        echo " onchange=\"".$this->onchange[$champ]."\" ";
        echo " class='champFormulaire comboc' />\n";
        
        echo "<a class=\"comboc ui-state-default ui-corner-all\" href=\"javascript:vcorrel3('".$tab."');\">";
        echo "<span class=\"ui-icon ui-icon-extlink\" ";
        echo "title=\""._("Cliquer ici pour correler")."\">";
        echo "<- "._("Correler");
        echo "</span>";
        echo "</a>\n";
        
    }
    
    /**
     *
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function upload($champ, $validation, $DEBUG = false) {
        
        //
        echo "<input";
        echo " type=\"text\"";
        echo " name=\"".$champ."\"";
        echo " value=\"".$this->val[$champ]."\"";
        echo " size=\"".$this->taille[$champ]."\"";
        echo " maxlength=\"".$this->max[$champ]."\"";
        echo " class=\"champFormulaire upload\"";
        if (!$this->correct) {
            if (isset($this->onchange) and $this->onchange[$champ] != "") {
                echo " onchange=\"".$this->onchange[$champ]."\"";
            }
            if (isset($this->onkeyup) and $this->onkeyup[$champ] != "") {
                echo " onkeyup=\"".$this->onkeyup[$champ]."\"";
            }
            if (isset($this->onclick) and $this->onclick[$champ] != "") {
                echo " onclick=\"".$this->onclick[$champ]."\"";
            }
        } else {
            echo " disabled=\"disabled\"";
        }
        echo " />\n";
        
        //
        if (!$this->correct) {
            //
            echo "<a class=\"upload ui-state-default ui-corner-all\" href=\"javascript:vupload('".$champ."');\">";
            echo "<span class=\"ui-icon ui-icon-arrowthickstop-1-s\" ";
            echo "title=\""._("Cliquer ici pour telecharger un fichier depuis votre poste de travail")."\">";
            echo _("Telecharger");
            echo "</span>";
            echo "</a>\n";
            //
            echo "<a class=\"voir ui-state-default ui-corner-all\" href=\"javascript:voir('".$champ."');\">\n";
            echo "<span class=\"ui-icon ui-icon-newwin\" ";
            echo "title=\""._("Cliquer ici pour voir le fichier")."\">";
            echo _("Voir");
            echo "</span>";
            echo "</a>\n";
        }
        
    }
    
    /**
     * upload2  [subform 2]
     *
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function upload2($champ, $validation, $DEBUG = false) {
        
        //
        echo "<input";
        echo " type=\"text\"";
        echo " name=\"".$champ."\"";
        echo " value=\"".$this->val[$champ]."\"";
        echo " size=\"".$this->taille[$champ]."\"";
        echo " maxlength=\"".$this->max[$champ]."\"";
        echo " class=\"champFormulaire upload\"";
        if (!$this->correct) {
            if (isset($this->onchange) and $this->onchange[$champ] != "") {
                echo " onchange=\"".$this->onchange[$champ]."\"";
            }
            if (isset($this->onkeyup) and $this->onkeyup[$champ] != "") {
                echo " onkeyup=\"".$this->onkeyup[$champ]."\"";
            }
            if (isset($this->onclick) and $this->onclick[$champ] != "") {
                echo " onclick=\"".$this->onclick[$champ]."\"";
            }
        } else {
            echo " disabled=\"disabled\"";
        }
        echo " />\n";
        
        //
        if (!$this->correct) {
            //
            echo "<a class=\"upload ui-state-default ui-corner-all\" href=\"javascript:vupload2('".$champ."');\">";
            echo "<span class=\"ui-icon ui-icon-arrowthickstop-1-s\" ";
            echo "title=\""._("Cliquer ici pour telecharger un fichier depuis votre poste de travail")."\">";
            echo _("Telecharger");
            echo "</span>";
            echo "</a>\n";
            //
            echo "<a class=\"voir ui-state-default ui-corner-all\" href=\"javascript:voir2('".$champ."');\">\n";
            echo "<span class=\"ui-icon ui-icon-newwin\" ";
            echo "title=\""._("Cliquer ici pour voir le fichier")."\">";
            echo _("Voir");
            echo "</span>";
            echo "</a>\n";
        }
        
    }
    
    /**
     *
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function voir($champ, $validation, $DEBUG = false) {
        
        if (!$this->correct) {
            //
            echo "<input type='text' ";
            echo "name='".$champ."' ";
            echo "value=\"".$this->val[$champ]."\" ";
            echo "size=".$this->taille[$champ]." ";
            echo "maxlength=".$this->max[$champ]." ";
            echo "onchange=\"".$this->onchange[$champ]."\" ";
            echo "class='champFormulaire voir' ";
            echo ">";
            //
            echo "<a class=\"voir ui-state-default ui-corner-all\" href=\"javascript:voir('".$champ."');\">\n";
            echo "<span class=\"ui-icon ui-icon-newwin\" ";
            echo "title=\""._("Cliquer ici pour voir le fichier")."\">";
            echo _("Voir");
            echo "</span>";
            echo "</a>\n";
        } else {
            //
            echo "<input type='text' ";
            echo "name='".$champ."' ";
            echo "value=\"".$this->val[$champ]."\" ";
            echo "size=".$this->taille[$champ]." ";
            echo "maxlength=".$this->max[$champ]." ";
            echo "class='champFormulaire voir' ";
            echo "disabled=\"disabled\" ";
            echo ">\n";
        }
        
    }
    
    /**
     * voir2 [subform2]
     * 
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function voir2($champ, $validation, $DEBUG = false) {
        
        if (!$this->correct) {
            //
            echo "<input type='hidden' ";
            echo "name='".$champ."' ";
            echo "value=\"".$this->val[$champ]."\" ";
            echo "class='champFormulaire voir' ";
            echo ">\n";
            //
            echo "<p class='voir'>";
            echo $this->val[$champ];
            echo " </p>\n";
            //
            echo "<a class=\"voir ui-state-default ui-corner-all\" href=\"javascript:voir2('".$champ."');\">\n";
            echo "<span class=\"voir ui-icon ui-icon-newwin\" ";
            echo "title=\""._("Cliquer ici pour voir le fichier")."\">";
            echo _("Voir");
            echo "</span>";
            echo "</a>\n";
        } else {
            //
            echo "<input type='text' ";
            echo "name='".$champ."' ";
            echo "value='".$this->val[$champ]."' ";
            echo "size=".$this->taille[$champ]." ";
            echo "maxlength=".$this->max[$champ]." ";
            echo "class='champFormulaire voir' ";
            echo "disabled=\"disabled\" ";
            echo ">\n";
        }
        
    }

    /**
     * localisation
     * - $select['positiony'][0]="plan";// zone plan
     * - $select['positiony'][1]="positionx"; // zone coordonnees X
     *
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function localisation($champ, $validation, $DEBUG = false) {
        
        //
        echo "<input";
        echo " type=\"text\"";
        echo " name=\"".$champ."\"";
        echo " value=\"".$this->val[$champ]."\"";
        echo " size=\"".$this->taille[$champ]."\"";
        echo " maxlength=\"".$this->max[$champ]."\"";
        echo " class=\"champFormulaire localisation\"";
        if (!$this->correct) {
            if (isset($this->onchange) and $this->onchange[$champ] != "") {
                echo " onchange=\"".$this->onchange[$champ]."\"";
            }
            if (isset($this->onkeyup) and $this->onkeyup[$champ] != "") {
                echo " onkeyup=\"".$this->onkeyup[$champ]."\"";
            }
            if (isset($this->onclick) and $this->onclick[$champ] != "") {
                echo " onclick=\"".$this->onclick[$champ]."\"";
            }
        } else {
            echo " disabled=\"disabled\"";
        }
        echo " />\n";
        
        //
        if (!$this->correct) {
            // zone libelle
            $plan = $this->select[$champ][0][0];  // plan
            $positionx = $this->select[$champ][0][1];
            //
            echo "<a class=\"localisation ui-state-default ui-corner-all\" href=\"javascript:localisation('".$champ."','".$plan."','".$positionx."');\">";
            echo "<span class=\"ui-icon ui-icon-pin-s\" ";
            echo "title=\""._("Cliquer ici pour positionner l'element")."\">";
            echo _("Localisation");
            echo "</span>";
            echo "</a>";
        }
        
    }

    function localisation2($champ, $validation, $DEBUG = false) {
        
        //
        echo "<input";
        echo " type=\"text\"";
        echo " name=\"".$champ."\"";
        echo " value=\"".$this->val[$champ]."\"";
        echo " size=\"".$this->taille[$champ]."\"";
        echo " maxlength=\"".$this->max[$champ]."\"";
        echo " class=\"champFormulaire localisation\"";
        if (!$this->correct) {
            if (isset($this->onchange) and $this->onchange[$champ] != "") {
                echo " onchange=\"".$this->onchange[$champ]."\"";
            }
            if (isset($this->onkeyup) and $this->onkeyup[$champ] != "") {
                echo " onkeyup=\"".$this->onkeyup[$champ]."\"";
            }
            if (isset($this->onclick) and $this->onclick[$champ] != "") {
                echo " onclick=\"".$this->onclick[$champ]."\"";
            }
        } else {
            echo " disabled=\"disabled\"";
        }
        echo " />\n";
        
        //
        if (!$this->correct) {
            // zone libelle
            $plan = $this->select[$champ][0][0];  // plan
            $positionx = $this->select[$champ][0][1];
            //
            echo "<a class=\"localisation ui-state-default ui-corner-all\" href=\"javascript:localisation2('".$champ."','".$plan."','".$positionx."');\">";
            echo "<span class=\"ui-icon ui-icon-pin-s\" ";
            echo "title=\""._("Cliquer ici pour positionner l'element")."\">";
            echo _("Localisation");
            echo "</span>";
            echo "</a>";
        }
        
    }


    
    /**
     * rvb
     * 
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function rvb($champ, $validation, $DEBUG = false) {
        
        //
        if (!$this->correct) {
            $this->val[$champ] = str_replace("\n", "-", $this->val[$champ]);
        }
        echo "<input";
        echo " type=\"text\"";
        echo " name=\"".$champ."\"";
        echo " value=\"".$this->val[$champ]."\"";
        echo " size=\"".$this->taille[$champ]."\"";
        echo " maxlength=\"".$this->max[$champ]."\"";
        echo " class=\"champFormulaire rvb\"";
        if (!$this->correct) {
            if (isset($this->onchange) and $this->onchange[$champ] != "") {
                echo " onchange=\"".$this->onchange[$champ]."\"";
            }
            if (isset($this->onkeyup) and $this->onkeyup[$champ] != "") {
                echo " onkeyup=\"".$this->onkeyup[$champ]."\"";
            }
            if (isset($this->onclick) and $this->onclick[$champ] != "") {
                echo " onclick=\"".$this->onclick[$champ]."\"";
            }
        } else {
            echo " disabled=\"disabled\"";
        }
        echo " />\n";
        
        //
        if (!$this->correct) {
            //
            echo "<a class=\"rvb ui-state-default ui-corner-all\" href=\"javascript:rvb('".$champ."');\">\n";
            echo "<span class=\"ui-icon ui-icon-image\" ";
            echo "title=\""._("Cliquer ici pour selectionner une couleur")."\">";
            echo _("RVB");
            echo "</span>";
            echo "</a>\n";
        }
        
    }
    
    function rvb2($champ, $validation, $DEBUG = false) {    
        //
        if (!$this->correct) {
            $this->val[$champ] = str_replace("\n", "-", $this->val[$champ]);
        }
        echo "<input";
        echo " type=\"text\"";
        echo " name=\"".$champ."\"";
        echo " value=\"".$this->val[$champ]."\"";
        echo " size=\"".$this->taille[$champ]."\"";
        echo " maxlength=\"".$this->max[$champ]."\"";
        echo " class=\"champFormulaire rvb\"";
        if (!$this->correct) {
            if (isset($this->onchange) and $this->onchange[$champ] != "") {
                echo " onchange=\"".$this->onchange[$champ]."\"";
            }
            if (isset($this->onkeyup) and $this->onkeyup[$champ] != "") {
                echo " onkeyup=\"".$this->onkeyup[$champ]."\"";
            }
            if (isset($this->onclick) and $this->onclick[$champ] != "") {
                echo " onclick=\"".$this->onclick[$champ]."\"";
            }
        } else {
            echo " disabled=\"disabled\"";
        }
        echo " />\n";
        //
        if (!$this->correct) {
            //
            echo "<a class=\"rvb ui-state-default ui-corner-all\" href=\"javascript:rvb2('".$champ."');\">\n";
            echo "<span class=\"ui-icon ui-icon-image\" ";
            echo "title=\""._("Cliquer ici pour selectionner une couleur")."\">";
            echo _("RVB");
            echo "</span>";
            echo "</a>\n";
        }
        
    }
    
    /**
     * http - lien http en formulaire - passage d argument sur une
     * application tierce
     * 
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function http($champ, $validation, $DEBUG = false) {
        
        //
        if (isset($this->select[$champ][0])) {
            $aff = $this->select[$champ][0];
        } else {
            $aff = $champ;
        }
        //
        echo "<a href=\"".$this->val[$champ]."\" target=\"_blank\">";
        echo $aff;
        echo "</a>\n";
        
    }
    
    /**
     * httpclick - lien http en formulaire - passage d argument sur une
     * application tierce
     * 
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function httpclick($champ, $validation, $DEBUG = false) {
        
        //
        if (isset($this->select[$champ][0])) {
            $aff = $this->select[$champ][0];
        } else {
            $aff = $champ;
        }
        //
        echo "<a href='#' onclick=\"".$this->val[$champ]."\" >";
        echo $aff;
        echo "</a>\n";
        
    }

    /**
     * Recuperation des variables sous formulaires
     * 
     * @param string $champ Libelle des champs a afficher
     * @param integer $validation - 0 1er passage
     *                            - > 0 passage suivant suite validation
     * @param boolean $postVar
     * @param boolean $DEBUG Parametre inutilise
     */
    function recupererPostvarsousform($champs, $validation, $postVar, $DEBUG = false) {
        for ($i = 0; $i < count($champs); $i++) {
            if ($validation > 0) {
                // magic_quotes_gpc est initialise dans php.ini
                // mise automatique de quote quand il y a un ", \ , '.
                if ($this->type[$champs[$i]] != "textdisabled"
                    and $this->type[$champs[$i]] != "static"
                    and array_key_exists($champs[$i], $postVar)) { 
                    if (!get_magic_quotes_gpc()) { // magic_quotes_gpc = Off
                        if(DBCHARSET=="UTF8") // ***
                            $this->val[$champs[$i]] = utf8_encode(strtr($postVar[$champs[$i]], chr(34), "'"));
                        else
                            $this->val[$champs[$i]] = strtr($postVar[$champs[$i]], chr(34), "'");     
                    } else { // magic_quotes_gpc = On
                        if(DBCHARSET=="UTF8") // ***
                            $this->val[$champs[$i]] = utf8_encode(strtr(stripslashes($postVar[$champs[$i]]), chr(34), "'"));
                        else
                            $this->val[$champs[$i]] = strtr(stripslashes($postVar[$champs[$i]]), chr(34), "'");
                    }
                } else {
                    $this->val[$champs[$i]] = "";
                    $this->val[$champs[$i]] = utf8_decode($this->val[$champs[$i]]);
                }
            }
        }
        
    }
    
    /**
     * Recuperation des variables formulaires
     * ajout test si variable post existe
     * avant affectation a?$this->val[$champs[$i]]
     *
     * @param string $champ Libelle des champs a afficher
     * @param integer $validation - 0 1er passage
     *                            - > 0 passage suivant suite validation
     * @param boolean $postVar
     * @param boolean $DEBUG Parametre inutilise
     */
    function recupererPostvar($champs, $validation, $postVar, $DEBUG = false) {
        for ($i = 0; $i < count($champs); $i++) {
            if ($validation > 0) {
                // magic_quotes_gpc est initialise dans php.ini
                // mise automatique de quote quand il y a un ", \ , '.
                if ($this->type[$champs[$i]] != "textdisabled"
                    and $this->type[$champs[$i]] != "static") {
                    // cas de checkbox/select multiple : les valeurs renvoyees
                    // dans le post sont dans un tableau donc ici les valeurs
                    // sont linearises dans une chaine avec separateur ;
                    if ($this->type[$champs[$i]] == "checkbox_multiple"
                        || $this->type[$champs[$i]] == "select_multiple") {
                        if (isset($postVar[$champs[$i]])) {
                            if (!get_magic_quotes_gpc()) { // magic_quotes_gpc = Off
                                $this->val[$champs[$i]] = implode(";",$postVar[$champs[$i]]);
                            } else { // magic_quotes_gpc = On
                                $this->val[$champs[$i]] = stripslashes(implode(";",$postVar[$champs[$i]]));
                            }
                        } else {
                            $this->val[$champs[$i]] = "";
                        }
                    } else { // cas standard
                        if (isset($postVar[$champs[$i]])) {
                            if (!get_magic_quotes_gpc()) { // magic_quotes_gpc = Off
                                $this->val[$champs[$i]] = strtr($postVar[$champs[$i]],chr(34),"'");
                            } else { // magic_quotes_gpc = On
                                $this->val[$champs[$i]] = strtr(stripslashes($postVar[$champs[$i]]),chr(34),"'");
                            }
                        } else {
                            $this->val[$champs[$i]] = "";
                        }
                    }
                } else {
                    $this->val[$champs[$i]] = "";
                }
            }
        }
        
    }
    
    /**
     *
     * 
     * @param string $champ
     * @param string $contenu
     * @return void
     */
    function setVal($champ, $contenu) {
        
        $this->val[$champ] = $contenu;
        
    }
    
    /**
     *
     *
     * @param string $champ
     * @param string $contenu Type de champ :
     *                        - 'text' : saisie texte alpha numerique
     *                        - 'hidden' : le champ est cache, le parametre est
     *                        passe
     *                        - 'password' : saisie masquee
     *                        - 'static' : champ uniquement affiche
     *                        - 'date' : saisie de date
     *                        - 'hiddenstatic' : champ affiche et passage du
     *                        parametre
     *                        - 'select' : zone de selection soit sur une autre
     *                        table, soit par rapport a un tableau
     * @return void
     */
    function setType($champ, $contenu) {
        
        $this->type[$champ] = $contenu;
        
    }
    
    /**
     * Libelle
     * 
     * @param string $champ
     * @param string $contenu
     * @return void
     */
    function setLib($champ, $contenu) {
        
        $this->lib[$champ] = $contenu;
        
    }
    
    /**
     * Maximum autorise a la saisie
     * 
     * @param string $champ
     * @param string $contenu
     * @return void
     */
    function setMax($champ, $contenu) {
        
        $this->max[$champ] = $contenu;
        
    }
    
    /**
     * Taille du controle
     * 
     * @param string $champ
     * @param string $contenu
     * @return void
     */
    function setTaille($champ, $contenu) {
        
        $this->taille[$champ] = $contenu;
        
    }
    
    /**
     * 
     * 
     * @param string $champ
     * @param string $contenu
     * @return void
     */
    function setSelect($champ, $contenu) {
        
        /*
        GESTION DES TABLES ET PASSAGE DE PARAMETRES
        valeur de $select ============================================================
        TABLE ------------------------------------------------------------------------
        select['nomduchamp'][0]= value de l option
        $select['nomduchamp'][1]= affichage
        COMBO (recherche de correspondance entre table importante)--------------------
        $select['code_departement_naissance'][0][0]="departement";// table
        $select['code_departement_naissance'][0][1]="code"; // zone origine
        $select['code_departement_naissance'][1][0]="libelle_departement"; // zone correl
        $select['code_departement_naissance'][1][1]="libelle_departement_naissance"; // champ correl
        (facultatif)
        $select['code_departement_naissance'][2][0]="code_departement"; // champ pour le where
        $select['code_departement_naissance'][2][1]="code_departement_naissance"; // zone du formulaire concerne
        TEXTAREAMULTI ----------------------------------------------------------------
        select['nomduchamp'][0]=  nom du champ origine pour recuperer la valeur
        -------------------------------------------------------------------------------
        */
        $this->select[$champ] = $contenu;
        
    }
    
    /**
     *
     * @param string $champ
     * @param string $contenu
     * @return void
     */
    function setOnchange($champ, $contenu) {
        
        $this->onchange[$champ] = $contenu;
        
    }
    
    /**
     *
     * @param string $champ
     * @param string $contenu
     * @return void
     */
    function setOnkeyup($champ, $contenu) {
        
        $this->onkeyup[$champ] = $contenu;
        
    }
    
    /**
     *
     * @param string $champ
     * @param string $contenu
     * @return void
     */
    function setOnclick($champ, $contenu) {
        
        $this->onclick[$champ] = $contenu;
        
    }
    
    /**
     *
     * @param string $champ
     * @param string $contenu Position du champ dans le groupe :
     *                        - 'D' premier champ du groupe
     *                        - 'G' champ du groupe
     *                        - 'F' dernier champ du groupe
     * @return void
     */
    function setGroupe($champ, $contenu) {
        
        $this->groupe[$champ] = $contenu;
        
    }
    
    /**
     *
     * @param string $champ
     * @param string $contenu Position du champ dans le fieldset :
     *                        - 'D' premier champ du fieldset
     *                        - 'G' champ du fieldset
     *                        - 'F' dernier champ du fieldset
     * @param string $libelle
     * @return void
     */
    function setRegroupe($champ, $contenu, $libelle, $style = "") {
        
        $this->regroupe[$champ][0] = $contenu;
        $this->regroupe[$champ][1] = $libelle;
        $this->regroupe[$champ][2] = $style;
        
    }
    
    /**
     * Affichage de la date suivant le format de la base de donnees
     *
     * @param string $val
     * @return string
     */
    function dateAff($val) {
        
        if (FORMATDATE == "AAAA-MM-JJ") {
            $valTemp = explode("-", $val);
            if( count($valTemp) == 3 ) {
                return $valTemp[2]."/".$valTemp[1]."/".$valTemp[0];
            }else{
                return $val;
            }
        }
        //
        if (FOMATDATE == "JJ/MM/AAAA") {
            return $val;
        }
        
    }
    
    /**
     * Envoi avec le logiciel de messagerie
     *
     * @param
     * @param
     * @param boolean $DEBUG Parametre inutilise
     * @return void
     */
    function mail($champ, $validation, $DEBUG = false) {
        
        //
        if (!$this->correct) {
            if ($this->onchange != "") {
                echo "<input type=".$this->type[$champ]." name='".
                $champ."' value=\"".
                $this->val[$champ]."\" size=".$this->taille[$champ].
                " maxlength=".$this->max[$champ]." 
                onchange=\"".$this->onchange[$champ]."\" class='champFormulaire mail' >";
            } else {
                echo "<input type=".$this->type[$champ]." name='".
                $champ."' value=\"".
                $this->val[$champ]."\" size=".$this->taille[$champ].
                " maxlength=".$this->max[$champ]." class='champFormulaire mail' >";
            }
        } else {
            echo "<input type=".$this->type[$champ]." name='".
            $champ."' value=\"".
            $this->val[$champ]."\" size=".$this->taille[$champ].
            " maxlength=".$this->max[$champ]." class='champFormulaire mail' 
            disabled=\"disabled\">";
        }
        //
        $mail = $this->val[$champ];
        //
        echo "<a class=\"mail ui-state-default ui-corner-all\" href='mailto:".$mail."'>";
        echo "<span class=\"ui-icon ui-icon-mail-closed\" ";
        echo "title=\""._("Cliquer ici pour envoyer un mail a cette adresse")."\">";
        echo _("MailTo");
        echo "</span>";
        echo "</a>";
        
    }


    /**
     * Checkbox
     * 
     * @param string $champ Nom du champ
     * @param integer $validation
     * @param boolean $DEBUG Parametre inutilise
     */
    function checkbox_multiple($champ, $validation, $DEBUG = false, $disabled = false) {

        // ***************************************************************************
        // CHECKBOX_MULTIPLE
        //select['nomduchamp'][0]= value de l option
        //select['nomduchamp'][1]= affichage
        // ****************************************************************************
        // Delinearisation
        $selected_values = explode(";", $this->val[$champ]);
        //
        $k = 0;
        foreach ($this->select[$champ] as $elem) {
            while ($k <count($elem)) {
                //
                //
                echo "<input";
                echo " type=\"checkbox\"";
                echo " name=\"".$champ."[]\"";
                echo " value=\"".$this->select[$champ][0][$k]."\"";
                if ($disabled == true) {
                    echo " disabled=\"disabled\"";
                }
                echo " class=\"champFormulaire\"";
                if (in_array($this->select[$champ][0][$k], $selected_values)) {
                    echo " checked=\"checked\"";
                }
                if (!$this->correct) {
                    if (isset($this->onchange) and $this->onchange[$champ] != "") {
                        echo " onchange=\"".$this->onchange[$champ]."\"";
                    }
                    if (isset($this->onkeyup) and $this->onkeyup[$champ] != "") {
                        echo " onkeyup=\"".$this->onkeyup[$champ]."\"";
                    }
                    if (isset($this->onclick) and $this->onclick[$champ] != "") {
                        echo " onclick=\"".$this->onclick[$champ]."\"";
                    }
                } else {
                    echo " disabled=\"disabled\"";
                }
                echo " />\n";
                echo $this->select[$champ][1][$k];
                echo "<br/>";
                $k++;
                //
            }
        }

    }

    function checkbox_multiple_disabled($champ, $validation, $DEBUG = false) {
        $this->checkbox_multiple($champ, $validation, $DEBUG, true);
    }

    /**
     *
     * @param boolean $DEBUG Parametre inutilise
     */
    function select_multiple($champ,$validation,$DEBUG = false){
        
        // ***************************************************************************
        // SELECT_MULTIPLE
        //select['nomduchamp'][0]= value de l option
        //select['nomduchamp'][1]= affichage
        // ****************************************************************************
        // Delinearisation
        $selected_values = explode(";", $this->val[$champ]);
        //
        echo "<select";
        echo " name=\"".$champ."[]\"";
        echo " multiple=\"multiple\"";
        echo " size=\"".$this->taille[$champ]."\"";
        echo " class=\"champFormulaire selectmultiple\"";
        if (!$this->correct) {
            if (isset($this->onchange) and $this->onchange[$champ] != "") {
                echo " onchange=\"".$this->onchange[$champ]."\"";
            }
            if (isset($this->onkeyup) and $this->onkeyup[$champ] != "") {
                echo " onkeyup=\"".$this->onkeyup[$champ]."\"";
            }
            if (isset($this->onclick) and $this->onclick[$champ] != "") {
                echo " onclick=\"".$this->onclick[$champ]."\"";
            }
        } else {
            echo " disabled=\"disabled\"";
        }
        echo " />\n";
        //
        $k = 0;
        foreach ($this->select[$champ] as $elem) {
            while ($k <count($elem)) {
                echo "\t<option ";
                echo " value=\"".$this->select[$champ][0][$k]."\"";
                if (in_array($this->select[$champ][0][$k], $selected_values)) {
                    echo " selected=\"selected\"";
                }
                echo ">";
                echo $this->select[$champ][1][$k];
                echo "</option>\n";
                $k++;
            }
        }
        //
        echo "</select>\n";
    }
    
    /**
     *
     * @param boolean $DEBUG Parametre inutilise
     */
    function selectliste($champ,$validation,$DEBUG = false){
        
        // ***************************************************************************
        // SELECTLISTE (liste)
        // affichage de table
        //select['nomduchamp'][0]= value de l option
        //select['nomduchamp'][1]= affichage
        // ****************************************************************************
        if(!$this->correct) {
        echo "<select name='".$champ."' size='".$this->taille[$champ].
        "' class='champFormulaire' ";
        if($this->onchange[$champ]!="")
        echo "onchange=\"".$this->onchange[$champ]."\" ";  
        if($this->onclick[$champ]!="")
        echo "onclick=\"".$this->onclick[$champ]."\" ";  
        echo ">";
        }else
        echo "<select name='".$champ."' size='".$this->taille[$champ].
        "' class='champFormulaire' disabled=\"disabled\" >";
        $k=0;
        foreach($this->select[$champ] as $elem)
        //  $nOption++;
        while ($k <count($elem)) {
        if(!$this->correct) {
        if ($this->val[$champ]==$this->select[$champ][0][$k])
        echo "<option selected=\"selected\" value=\"".$this->select[$champ][0][$k].
        "\">".$this->select[$champ][1][$k]."</option>";
        else
        echo "<option value=\"".$this->select[$champ][0][$k].
        "\">".$this->select[$champ][1][$k]."</option>";
        $k++;
        
        }else{
        if ($this->val[$champ]==$this->select[$champ][0][$k]){
        echo "<option selected=\"selected\" value=\"".$this->select[$champ][0][$k].
        "\" >".$this->select[$champ][1][$k]."</option>";
        $k =count($elem);
        }
        $k++;
        }
        }
        echo "</select>";
        
    }
    
    /**
     *
     * @param boolean $DEBUG Parametre inutilise
     */
    function selectlistemulti($champ,$validation,$DEBUG = false){
        
        // ***************************************************************************
        // SELECTLISTEMULTI (liste)
        // affichage de table
        //select['nomduchamp'][0]= value de l option
        //select['nomduchamp'][1]= affichage
        //select['nomduchamp'][2]= autre select dont la value peut etre ajoutee
        //select['nomduchamp'][3]= champ cache des values ajoutees ex: 45,12,32
        // ****************************************************************************
        // colones = taille
        // lignes = max
        echo "<table><tr><td>";
        if(!$this->correct) {
        $champ2=$this->select[$champ][2];
        $champ3=$this->select[$champ][3];
        echo "<table border=1 ><tr><td>";
        echo "<input type='button' name='_select$champ' onclick='addlist(\"$champ\",\"$champ2\",\"$champ3\")' value='->' class='boutonmulti'> ";
        echo "</td></tr><tr><td>";
        echo "<input type='button' name='_unselect$champ' onclick='removelist(\"$champ\",\"$champ3\")' value='<-' class='boutonmulti'> ";
        echo "</td></tr><tr><td>";
        echo "<input type='button' name='_unselectall$champ' onclick='removealllist(\"$champ\",\"$champ3\")' value='<<' class='boutonmulti'> ";
        echo "</td></tr></table></td><td>";
        echo "<select name='".$champ."' size='".$this->taille[$champ].
        "' class='champFormulaire' ";
        if($this->onchange[$champ]!="")
        echo "onchange=\"".$this->onchange[$champ]."\" ";  
        if($this->onclick[$champ]!="")
        echo "onclick=\"".$this->onclick[$champ]."\" ";  
        echo ">";
        }else 
        echo "<select name='".$champ."' size='".$this->taille[$champ].
        "' class='champFormulaire' disabled=\"disabled\" >";
        $k=0;
        foreach($this->select[$champ] as $elem)
        //  $nOption++;
        while ($k <count($elem)) {
        if(!$this->correct) {
        if ($this->val[$champ]==$this->select[$champ][0][$k])
        echo "<option selected=\"selected\" value=\"".$this->select[$champ][0][$k].
        "\">".$this->select[$champ][1][$k]."</option>";
        else
        echo "<option value=\"".$this->select[$champ][0][$k].
        "\">".$this->select[$champ][1][$k]."</option>";
        $k++;
        }else{
        if ($this->val[$champ]==$this->select[$champ][0][$k]){
        echo "<option selected=\"selected\" value=\"".$this->select[$champ][0][$k].
        "\" >".$this->select[$champ][1][$k]."</option>";
        $k =count($elem);
        }
        $k++;
        }
        }
        echo "</select>";
        echo "</td></tr></table>";
        
    }
    
}

?>