Subversion Repositories Applications.papyrus

Rev

Rev 688 | Blame | Last modification | View Log | RSS feed

<?php
/*vim: set expandtab tabstop=4 shiftwidth=4: */ 
// +------------------------------------------------------------------------------------------------------+
// | PHP version 4.1                                                                                      |
// +------------------------------------------------------------------------------------------------------+
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
// +------------------------------------------------------------------------------------------------------+
// | This library is free software; you can redistribute it and/or                                        |
// | modify it under the terms of the GNU General Public                                                  |
// | License as published by the Free Software Foundation; either                                         |
// | version 2.1 of the License, or (at your option) any later version.                                   |
// |                                                                                                      |
// | This library is distributed in the hope that it will be useful,                                      |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
// | General Public License for more details.                                                             |
// |                                                                                                      |
// | You should have received a copy of the GNU General Public                                            |
// | License along with this library; if not, write to the Free Software                                  |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
// +------------------------------------------------------------------------------------------------------+
// CVS : $Id: HTML_formulaireDocument.class.php,v 1.3 2006-01-05 15:02:55 alexandre_tb Exp $
/**
* Application projet
*
* La classe HTML_formulaireDocument
*
*@package projet
//Auteur original :
*@author        Alexandre Granier <alexandre@tela-botanica.org>
//Autres auteurs :
*@author        Aucun
*@copyright     Tela-Botanica 2000-2004
*@version       $Revision: 1.3 $
// +------------------------------------------------------------------------------------------------------+
*/


// +------------------------------------------------------------------------------------------------------+
// |                                            ENTETE du PROGRAMME                                       |
// +------------------------------------------------------------------------------------------------------+

/** Inclure le fichier de langue pour utiliser cette classe de façon autonome. */

require_once 'HTML/QuickForm.php' ;
require_once 'HTML/QuickForm/checkbox.php' ;
require_once 'HTML/QuickForm/select.php' ;

/**
 * class HTML_formulaireDocument
 * 
 */
class HTML_formulaireDocument extends HTML_QuickForm
{
    /** Le type d'un document, par défaut 'fichier'
     * 
     * @access private
     */
    var $_type = 'fichier';

    /**
     * Constructeur
     *
     * @param string formName Le nom du formulaire
     * @param string method Méthode post ou get
     * @param string action L'action du formulaire.
     * @param int target La cible.
     * @param Array attributes Les attributs HTML en plus.
     * @param bool trackSubmit ??
     * @return void
     * @access public
     */
    function HTML_formulaireDocument( $formName,  $method = "post",  $action,  $target = "_self",  $attributes = '',  $trackSubmit = false )
    {
        HTML_QuickForm::HTML_QuickForm($formName, $method, $action, $target, $attributes, $trackSubmit) ;
    } // end of member function HTML_formulaireDocument

    /**
     * 
     *
     * @return void
     * @access public
     */
    function construitFormulaire($action = PROJET_NOUVEAU_FICHIER)
    {
        $this->addElement ('text', 'document_nom', PROJET_FICHIER_NOM_DOCUMENT, array ('size' => 40)) ;
        $this->addRule ('document_nom', PROJET_FICHIER_ALERTE, 'required', '', 'client') ;
        $this->addElement ('html', '<tr><td colspan="2">'.PROJET_FICHIER_NOM_DOCUMENT_EXPLICATION.'</td></tr>') ;
        $this->addElement ('textarea', 'document_description', PROJET_FICHIER_DESCRIPTION, array('cols'=>40, 'rows'=>10)) ;
        
        // on fait un groupe avec les boutons radio pour les mettres sur la même ligne

        $radio[] = &HTML_QuickForm::createElement('radio', 'document_visibilite', 'public', PROJET_FICHIER_PUBLIC, 'public') ;
        $radio[] = &HTML_QuickForm::createElement('radio', 'document_visibilite', 'prive', PROJET_FICHIER_PRIVEE, 'prive');
        $this->addGroup($radio, null, PROJET_FICHIERS_VISIBILITE, '&nbsp;');
        
        // Le champs fichier si le type du document est un fichier
        if ($this->_type == 'fichier' && $action == PROJET_NOUVEAU_FICHIER) {
            $GLOBALS['fichier'] = $this->addElement ('file', 'fichier', PROJET_FICHIER_LE_FICHIER) ;
            $this->setMaxFileSize(4*1024*1024) ;
            $this->addRule ('fichier', PROJET_FICHIER_ALERTE_PAS_DE_FICHIER, 'required', '', 'client') ;
        }
        
        $url_annuler = new Net_URL($this->getAttribute('action')) ;
        $url_annuler->removeQueryString(PROJET_VARIABLE_ACTION) ;
        // on fait un groupe avec les boutons pour les mettres sur la même ligne
        $buttons[] = &HTML_QuickForm::createElement('link', 'annuler', PROJET_FICHIER_ANNULER, 
                            preg_replace ("/&amp;/", "&", $url_annuler->getURL()), PROJET_FICHIER_ANNULER); // Le preg_replace contourne un pb de QuickForm et Net_URL
                                                                                                            // qui remplacent deux fois les & par des &amp;
                                                                                                            // ce qui fait échouer le lien
        $buttons[] = &HTML_QuickForm::createElement('submit', 'valider', PROJET_FICHIER_VALIDER);
        $this->addGroup($buttons, null, null, '&nbsp;');
        $this->applyFilter('document_nom', 'addslashes') ;
        $this->applyFilter('document_description', 'addslashes') ;
        
        $this->setRequiredNote('<span style="color: #ff0000">*</span>'.PROJET_CHAMPS_REQUIS) ;
    } // end of member function construitFormulaire

    /**
     *  Permet de spécifier le type de formulaire à montrer
     *
     * @param string type Le type d'un document, 'fichier' ou 'repertoire'
     * @return void
     * @access public
     */
    function setType( $type )
    {
        if ($type != 'fichier' && $type != 'repertoire') trigger_error ('type invalide', E_USER_ERROR) ;
        $this->_type = $type ;
    } // end of member function setType

    /**
     * 
     *
     * @return string
     * @access public
     */
    function toHTML( )
    {
        $res = HTML_QuickForm::toHTML() ;
        return $res ;
    } // end of member function toHTML


} // end of HTML_formulaireDocument
?>