Subversion Repositories Applications.projet

Rev

Rev 6 | Go to most recent revision | Blame | Compare with Previous | 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_listeDocuments.class.php,v 1.1 2005-09-22 14:02:47 ddelon Exp $
/**
* Application projet
*
* La classe HTML_listeDocuments
*
*@package projet
//Auteur original :
*@author        Alexandre Granier <alexandre@tela-botanica.org>
//Autres auteurs :
*@author        Aucun
*@copyright     Tela-Botanica 2000-2004
*@version       $Revision: 1.1 $
// +------------------------------------------------------------------------------------------------------+
*/


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


// +------------------------------------------------------------------------------------------------------+
// |                                           LISTE des constantes                                       |
// +------------------------------------------------------------------------------------------------------+

define ("FICHIER_ICONE_COUPER", "cut.gif") ;
define ("FICHIER_ICONE_COLLER", "paste.gif") ;
define ("FICHIER_ICONE_SUPPRIMER", "trash.gif") ;
define ("FICHIER_ICONE_MODIFIER", "modif.png") ;

/**
 * class HTML_listeDocuments
 * 
 */
class HTML_listeDocuments extends HTML_Liste
{
    /*** Attributes: ***/

    /**
     * Une url.
     * @access private
     */
    var $_url;
    
    /**
     * Tableau contenant les actions possibles. "couper" => 1, "modifier" => 2,
     * "supprimer" => 3 Elles seront passées en paramètre aux url des icones des
     * documents.
     * @access private
     */
    var $_actions = array ("couper" => 1, "modifier" => 2, "supprimer" => 3) ;

    /**
     * Indique le chemin des icones couper, coller, modifier, supprimer. 
     * @access private
     */
    var $_chemin_icone = "icones/";
    
    /**
     * L'identifiant du répertoire que l'on est en train d'observer.
     * @access private
     */
    var $_id_repertoire;

    /**
     * Un tableau contenant les id et les noms du chemin des répertoires. 0 => ["id"],
     * ["nom"] etc.
     * @access private
     */
    var $_chemin_navigation = array ();

    /**
     * un pointeur vers une authentificatin PEAR
     * @access private
     */
    var $_auth ;
    /**
     * 
     *
     * @param bool utilise_pager Indique l'utilisation ou non du Pager.
     * @return void
     * @access public
     */
    function HTML_listeDocuments(&$url,  $utilise_pager = false, $id_repertoire = 0, $auth = '' )
    {
        HTML_Liste::HTML_Liste($utilise_pager, array('class' => 'table_cadre')) ;
        $this->_url = $url ;
        
        $this->_id_repertoire = $id_repertoire ;
        if (is_object($auth)) {
            $this->_auth = $auth ;
        }
    } // end of member function HTML_listeDocuments

    /**
     * 
     *
     * @param bool utilise_pager Voir HTML_listeDocuments
     * @return void
     * @access public
     */
    function __construct( $utilise_pager )
    {
        
    } // end of member function __construct

    /**
     * 
     *
     * @param Array tableau_label Un tableau contenant les labels à afficher dans l'entête.
     * @return void
     * @access public
     */
    function construitEntete( $tableau_label )
    {
        $this->addRow ($tableau_label, NULL, 'TH') ;
    } // end of member function construitEntete

    /**
     * 
     *
     * @param Array tableau_label Un tableau à deux dimensions avec les labels à afficher dans le corps du
     * tableau.
     * @return void
     * @access public
     */
    function construitListe( &$tableau_document, $droits, $mode = '', $objetDB = '')
    {
        $compteur = 0 ;$class[0] = 'ligne_impaire'; $class[1] = 'ligne_paire' ;

        for ($i = 0; $i < count ($tableau_document) ; $i++) {
            // Première condition : est-ce que le fichier a pour père le répertoire courant, si oui on l'affiche
            if ($tableau_document[$i]->_id_pere == $this->_id_repertoire || $mode == 'ignore_repertoire') {
                // d'abord l'image
                $icone = '<img src="'.$tableau_document[$i]->getCheminIcone().'" />' ;
                // Si le document est un répertoire, on ajoute id_repertoire au lien.
                if ($tableau_document[$i]->isRepertoire()) {
                    $this->_url->addQueryString ('id_repertoire', $tableau_document[$i]->getChemin()) ;
                    $lien = $this->_url->getURL() ;
                } else {    //  Si c'est un fichier, on fait un lien direct
                    $lien = $tableau_document[$i]->getChemin() ;
                }
                // pour éviter des effets de bords, on enlève id_repertoire de l'url
                // dans le cas d'un répertoire, pour les fichiers on le laisse pour
                // qu'après une opération, on reste dans le répertoire où a eu lieu l'opération
                if ($tableau_document[$i]->isRepertoire()) $this->_url->removeQueryString('id_repertoire') ;
                
                // on insère le lien
                $lien_nom = '<a href="'.$lien.'">'.$icone.' '.$tableau_document[$i]->getNomLong()."</a>\n" ;
                
                // Pour la taille on divise par 1000 et on écrit Ko
                $taille = round($tableau_document[$i]->getTaille() / 1000).'&nbsp;Ko' ;
                
                // Récupération de l'auteur
                include_once PROJET_CHEMIN_CLASSES.'annuaire.class.php' ;
                $annuaire = new annuaire($objetDB, array('table' => PROJET_ANNUAIRE, 'identifiant' => PROJET_CHAMPS_ID, 
                                            'nom' => PROJET_CHAMPS_NOM, 'prenom' => PROJET_CHAMPS_PRENOM)) ;
                $annuaire->setId($tableau_document[$i]->_id_proprietaire) ;
                $nom_prenom = $annuaire->getInfo('nom').' '.$annuaire->getInfo('prenom') ;
                // On rempli le tableau à donner en paramètre à HTML_Table avec toutes ces infos, une par colonne
                $ligne_tableau = array($lien_nom, $taille, $nom_prenom, $tableau_document[$i]->getDateMiseAJour()) ;
                if ($droits <= PROJET_DROIT_CONTRIBUTEUR) array_push ($ligne_tableau, $tableau_document[$i]->getVisibilite()) ;
                
                // On ajoute au tableau, les action couper / modifier / supprimer
                if ($droits <= PROJET_DROIT_COORDINATEUR || $this->_auth->getAuthData(PROJET_CHAMPS_ID) == $tableau_document[$i]->_id_proprietaire) 
                                                array_push ($ligne_tableau, $this->_actions ($tableau_document[$i])) ;
                $this->addRow ($ligne_tableau, array('class' => $class[$compteur]), 'TD', true) ;
                // enfin , s'il y a une description, on l'ajoute, mais sur une ligne entière (colspan)
                if ($tableau_document[$i]->getDescription() != "") {
                    $this->addRow (array ($tableau_document[$i]->getDescription()), array ("colspan" => count ($ligne_tableau), 'class' => $class[$compteur]), 'TD', true) ;
                }
                $compteur++;
            }
            
            if ($compteur == 2) $compteur = 0 ;
        }
        $this->updateColAttributes(0, array ('class' => 'col1')) ;
    } // end of member function construitListe

    /**
     * 
     *
     * @param Array actions Un tableau avec les valeurs d'actions comme clé. "couper", modifier",
     * "supprimer".
     * @return void
     * @access public
     */
    function setAction( $actions )
    {
        $this->_actions = $actions ;
    } // end of member function setAction
    
    /**
     * 
     *
     * @param string chemin Le chemin vers les icones couper, coller ...
     * @return void
     * @access public
     */
    function setCheminIcones( $chemin )
    {
        $this->_chemin_icone = $chemin ;
    } // end of member function setCheminIcones

    /**
     * Surcharge de l'opération de la classe mère. Ajoute la navigation dans les
     * répertoires.
     *
     * @return string
     * @access public
     */
    function toHTML( )
    {
        $chemin_navig = "" ;
        if ($this->_id_repertoire != "") {
            $chemin_navig = "<p>" ;
            $chemin_navig .= "<a href=\"".$this->_url->getURL()."\">".PROJET_RACINE."</a>\n" ;
            for ($i = 0; $i < count ($this->_chemin_navigation); $i+=2) {
                $chemin_navig .= "&gt;&nbsp;" ;
                $nom = $this->_chemin_navigation[$i+1] ;
                $this->_url->addQueryString ('id_repertoire', $this->_chemin_navigation[$i]) ;
                $chemin_navig .= "<a href=\"".$this->_url->getURL()."\">".$nom."</a>\n" ; 
            }
            $chemin_navig .= "</p>\n" ;
        }
        $res = $chemin_navig.HTML_Liste::toHTML() ;
        if ($this->getRowCount() == 1 && $this->_id_repertoire == '') {
            return '<div>'.PROJET_PAS_DE_DOCUMENTS.'</div>'."\n";
        }
        return $res ;
    } // end of member function toHTML

    /**
     * 
     *
     * @param Array tableau_navigation Un tableau contenant les identifiants et les noms des répertoires.  0 => ["id"],
     * ["nom"] etc.
     * @return void
     * @access public
     */
    function setCheminNavigation( $tableau_navigation )
    {
        $this->_chemin_navigation = $tableau_navigation ;
    } // end of member function setCheminNavigation

    /**
     * Affiche la légende des actions du module "documents"
     *
     * @return string
     * @access public
     */
    function affLegende( )
    {
        $res = "<h2 class=\"titre2_projet\">".PROJET_LEGENDE."</h2>\n" ;
        $res .= "<p><img src=\"".$this->_chemin_icone."/cut.gif\" title=\"couper\" alt=\"couper\">".PROJET_LEGENDE_DEPLACE."</p>\n" ;
        $res .= "<p><img src=\"".$this->_chemin_icone."/modif.png\" title=\"modifier\" alt=\"modifier\"> ".PROJET_LEGENDE_MODIFIE."</p>\n" ;
        $res .= "<p><img src=\"".$this->_chemin_icone."/trash.gif\" title=\"supprimer\" alt=\"supprimer\"> ".PROJET_LEGENDE_SUPPR."</p>\n" ;
        return $res ;
    } // end of member function affLegende


    /**
     * Renvoie le chemin HTML, depuis le répertoire courant jusqu'à la racine.
     *
     * @return string
     * @access private
     */
    function _getCheminHTML( )
    {
        $path = "" ;

        return $path ;
    } // end of member function _getCheminHTML



    /**
     * Renvoie une chaine contenant le code html des icones des actions possibles sur un
     * fichier, c'est à dire couper, modifier, supprimer.
     *
     * @return string
     * @access private
     */
    function _actions($document)
    {
        $this->_url->addQueryString ('id_document', $document->getIdDocument()) ;
        
        $this->_url->addQueryString (PROJET_VARIABLE_ACTION, $this->_actions["couper"]) ;
        $couper = '&nbsp;'.PROJET_FICHIER_COUPER ;
        if (!$document->isRepertoire()) $couper = '<a href="'.$this->_url->getURL().'">'.$couper.'</a>' ;
        
        $this->_url->addQueryString (PROJET_VARIABLE_ACTION, $this->_actions["modifier"]) ;
        $modifier = '<a href="'.$this->_url->getURL().'">'.PROJET_FICHIER_MODIFIER.'</a>&nbsp;' ;
        $this->_url->addQueryString (PROJET_VARIABLE_ACTION, $this->_actions["supprimer"]) ;
        $supprimer= '<a href="'.$this->_url->getURL().'" onclick="javascript:return confirm (\''.PROJET_FICHIER_SUPPRIMER.' ?\');">'.PROJET_FICHIER_SUPPRIMER.'</a>' ;
        $this->_url->removeQueryString ('id_document') ;
        $this->_url->addQueryString (PROJET_VARIABLE_ACTION, PROJET_ACTION_VOIR_DOCUMENT) ;
        return $modifier.$supprimer.$couper ;
    } // end of member function _action


} // end of HTML_listeDocuments
?>