Subversion Repositories Applications.projet

Rev

Rev 303 | 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.10 2008-08-25 15:14:17 alexandre_tb 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.10 $
// +------------------------------------------------------------------------------------------------------+
*/


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


include_once PROJET_CHEMIN_CLASSES.'HTML_Liste.class.php';
/**
 * 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 repertoire 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 ;
    
    /**
     * le style d affichage
     * @access private
     */
    var $_mode_affichage ;
    /**
     * 
     *
     * @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 ;
        }
        $this->_mode_affichage = 'standart';
    } // end of member function HTML_listeDocuments

    /**
     * 
     *
     * @param bool utilise_pager Voir HTML_listeDocuments
     * @return void
     * @access public
     */
    function __construct( &$url,  $utilise_pager = false, $id_repertoire = 0, $auth = '', $id_projet = '' )
    {
        $this->HTML_listeDocuments($url,  $utilise_pager, $id_repertoire, $auth);
        
    } // 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') ;
    }

    /**
     * 
     *
     * @param Array tableau_label Un tableau a deux dimensions avec les labels a afficher dans le corps du
     * tableau.
     * @return void
     * @access public
     */
    function construitListe( &$tableau_document, $droits, $mode = '', $objetDB = '', $id_projet = '')
    {
        if ($this->_mode_affichage == 'standart') {
                $compteur = 0 ;$class[0] = 'ligne_impaire'; $class[1] = 'ligne_paire' ;
        //var_dump ($tableau_document);
                for ($i = 0; $i < count ($tableau_document) ; $i++) {
                    // Premiere condition : est-ce que le fichier a pour pere le repertoire 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 repertoire, on ajoute id_repertoire au lien.
                        
                        
                        if ($tableau_document[$i]->isRepertoire()) {
                            $this->_url->addQueryString ('id_repertoire', $tableau_document[$i]->getIdDocument()) ;
                            
                            $lien = $this->_url->getURL() ;
                        } else {    //  Si c'est un fichier, on fait un lien direct
                                
                                $this->_url->addQueryString('id_document', $tableau_document[$i]->getIdDocument());
                                $this->_url->addQueryString('service', 'telechargement');
                            $lien = $this->_url->getURL() ;
                            $this->_url->removeQueryString('service');
                            $this->_url->removeQueryString('id_document');
                            $lien = 'http://'.$this->_url->host.'/projets/'.$this->_url->querystring[PROJET_VARIABLE_ID_PROJET].'/telechargement/'.$tableau_document[$i]->getIdDocument();
                        }
                        // pour eviter des effets de bords, on enleve id_repertoire de l'url
                        // dans le cas d'un repertoire, pour les fichiers on le laisse pour
                        // qu'apres une operation, on reste dans le repertoire ou a eu lieu l'operation
                        if ($tableau_document[$i]->isRepertoire()) $this->_url->removeQueryString('id_repertoire') ;
                        
                        // on insere le lien
                        $lien_nom = '<a href="'.$lien.'">'.$icone.' '.$tableau_document[$i]->getNomLong()."</a>\n" ;
                        
                        $taille = $tableau_document[$i]->getTailleFormatee();
                        
                        // Recuperation 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 a donner en parametre a 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])) ;
                        
                        if ($tableau_document[$i]->getVisibilite() != 'prive' || $droits < PROJET_DROIT_AUCUN) {
                                $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' => $this->getColCount(), 'class' => $class[$compteur])) ;
                                    $this->updateRowAttributes ($this->getRowCount()-1, array ('class' => $class[$compteur]), true) ;
                                }
                        }
                        $compteur++;
                    }
                    
                    if ($compteur == 2) $compteur = 0 ;
                }
                $this->_url->removeQueryString('id_document');
                $this->updateColAttributes(0, array ('class' => 'col1')) ;
        } else {
                
        }
    } // end of member function construitListe

    /**
     * 
     *
     * @param Array actions Un tableau avec les valeurs d'actions comme cle. "couper", modifier",
     * "supprimer".
     * @return void
     * @access public
     */
    function setAction( $actions )
    {
        $this->_actions = $actions ;
    }

    /**
     * 
     *
     * @param string le mode, valeur possible standart ou ajax
     * @return void
     * @access public
     */
    function setModeAffichage( $mode )
    {
        $this->_mode_affichage = $mode ;
    }
    

    /**
     * 
     *
     * @param string chemin Le chemin vers les icones couper, coller ...
     * @return void
     * @access public
     */
    function setCheminIcones( $chemin )
    {
        $this->_chemin_icone = $chemin ;
    }

    /**
     * Surcharge de l'operation de la classe mere. Ajoute la navigation dans les
     * repertoires.
     *
     * @return string
     * @access public
     */
    function toHTML($id_projet = '', $droits)
    {
        if ($this->_mode_affichage == 'standart') {
                $chemin_navig = "" ;
                if ($this->_id_repertoire != "") {
                    $this->_url->removeQueryString(PROJET_VARIABLE_ID_REPERTOIRE) ;
                    $chemin_navig = "<p>" ;
                    $chemin_navig .= "<a href=\"".$this->_url->getURL()."\">".PROJET_RACINE."</a>\n" ;
                    $this->_url->addQueryString(PROJET_VARIABLE_ID_REPERTOIRE, $this->_id_repertoire) ;
                    for ($i = 0; $i < count ($this->_chemin_navigation); $i++) {
                        $chemin_navig .= "&gt;&nbsp;" ;
                        $doc = new document ($this->_chemin_navigation[$i], $GLOBALS['projet_db']);
                        $nom = $doc->getNomLong() ;
                        $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";
                }
        } else {
                GEN_stockerFichierScript('dojo', 'api/js/dojo/dojo.js', 'text/javascript');
                GEN_stockerFichierScript('dojoScriptProjet', 'client/projet/js/arbreDocument.js');
                
                        $res = '' ;
                        
                        $RCPUrl = PROJET_CHEMIN_APPLI.'services/ecouteArbreFichier.php?id_projet='.$id_projet;
                        $this->_url->addQueryString(PROJET_VARIABLE_SERVICE, 'ecouteArbreFichier');
                        
                        $RCPUrl = $this->_url->getURL();
                        // Le noeud racine
                                
                        if ($droits <= PROJET_DROIT_CONTRIBUTEUR) {
                                $tree = '<div dojoType="Tree" DNDMode="between" selector="treeSelector" DNDAcceptTypes="bandTree" widgetId="bandTree" controller="treeController" eventNames="moveTo:nodeRemoved">';
                        } else {
                                $tree = '<div dojoType="Tree" selector="treeSelector" DNDAcceptTypes="bandTree" widgetId="bandTree" controller="treeController">';
                        }
                $res .= '<div dojoType="TreeLoadingController" RPCUrl="'.$RCPUrl.'" widgetId="treeController" DNDController="create"></div>
                                <div dojoType="TreeSelector" widgetId="treeSelector"></div>'.$tree.
                                '<div dojoType="TreeNode" title="Racine" widgetId="rootNode" objectId="root" isFolder="true"></div></div>';    
                                                      
        }
        return $res ;
    } // end of member function toHTML

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

    /**
     * Affiche la legende 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 ;
    }


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

        return $path ;
    }

    /**
     * Renvoie une chaine contenant le code html des icones des actions possibles sur un
     * fichier, c'est a 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 = ' '.PROJET_FICHIER_COUPER ;
        $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> ' ;
        $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
?>