Subversion Repositories Applications.projet

Rev

Rev 131 | Rev 249 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 ddelon 1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 4.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
7
// +------------------------------------------------------------------------------------------------------+
8
// | This library is free software; you can redistribute it and/or                                        |
9
// | modify it under the terms of the GNU General Public                                                  |
10
// | License as published by the Free Software Foundation; either                                         |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
12
// |                                                                                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
16
// | General Public License for more details.                                                             |
17
// |                                                                                                      |
18
// | You should have received a copy of the GNU General Public                                            |
19
// | License along with this library; if not, write to the Free Software                                  |
20
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
21
// +------------------------------------------------------------------------------------------------------+
208 neiluj 22
// CVS : $Id: HTML_listeDocuments.class.php,v 1.8 2007-04-19 15:34:35 neiluj Exp $
2 ddelon 23
/**
24
* Application projet
25
*
26
* La classe HTML_listeDocuments
27
*
28
*@package projet
29
//Auteur original :
30
*@author        Alexandre Granier <alexandre@tela-botanica.org>
31
//Autres auteurs :
32
*@author        Aucun
33
*@copyright     Tela-Botanica 2000-2004
208 neiluj 34
*@version       $Revision: 1.8 $
2 ddelon 35
// +------------------------------------------------------------------------------------------------------+
36
*/
37
 
38
 
39
// +------------------------------------------------------------------------------------------------------+
40
// |                                            ENTETE du PROGRAMME                                       |
41
// +------------------------------------------------------------------------------------------------------+
42
 
43
 
44
// +------------------------------------------------------------------------------------------------------+
45
// |                                           LISTE des constantes                                       |
46
// +------------------------------------------------------------------------------------------------------+
47
 
48
define ("FICHIER_ICONE_COUPER", "cut.gif") ;
49
define ("FICHIER_ICONE_COLLER", "paste.gif") ;
50
define ("FICHIER_ICONE_SUPPRIMER", "trash.gif") ;
51
define ("FICHIER_ICONE_MODIFIER", "modif.png") ;
52
 
208 neiluj 53
 
54
include_once PROJET_CHEMIN_CLASSES.'HTML_Liste.class.php';
2 ddelon 55
/**
56
 * class HTML_listeDocuments
57
 *
58
 */
59
class HTML_listeDocuments extends HTML_Liste
60
{
61
    /*** Attributes: ***/
62
 
63
    /**
64
     * Une url.
65
     * @access private
66
     */
67
    var $_url;
68
 
69
    /**
70
     * Tableau contenant les actions possibles. "couper" => 1, "modifier" => 2,
71
     * "supprimer" => 3 Elles seront passées en paramètre aux url des icones des
72
     * documents.
73
     * @access private
74
     */
75
    var $_actions = array ("couper" => 1, "modifier" => 2, "supprimer" => 3) ;
76
 
77
    /**
78
     * Indique le chemin des icones couper, coller, modifier, supprimer.
79
     * @access private
80
     */
81
    var $_chemin_icone = "icones/";
82
 
83
    /**
84
     * L'identifiant du répertoire que l'on est en train d'observer.
85
     * @access private
86
     */
87
    var $_id_repertoire;
88
 
89
    /**
90
     * Un tableau contenant les id et les noms du chemin des répertoires. 0 => ["id"],
91
     * ["nom"] etc.
92
     * @access private
93
     */
94
    var $_chemin_navigation = array ();
95
 
96
    /**
97
     * un pointeur vers une authentificatin PEAR
98
     * @access private
99
     */
100
    var $_auth ;
101
    /**
102
     *
103
     *
104
     * @param bool utilise_pager Indique l'utilisation ou non du Pager.
105
     * @return void
106
     * @access public
107
     */
108
    function HTML_listeDocuments(&$url,  $utilise_pager = false, $id_repertoire = 0, $auth = '' )
109
    {
110
        HTML_Liste::HTML_Liste($utilise_pager, array('class' => 'table_cadre')) ;
111
        $this->_url = $url ;
112
 
113
        $this->_id_repertoire = $id_repertoire ;
114
        if (is_object($auth)) {
115
            $this->_auth = $auth ;
116
        }
117
    } // end of member function HTML_listeDocuments
118
 
119
    /**
120
     *
121
     *
122
     * @param bool utilise_pager Voir HTML_listeDocuments
123
     * @return void
124
     * @access public
125
     */
15 ddelon 126
    function __construct( &$url,  $utilise_pager = false, $id_repertoire = 0, $auth = '' )
2 ddelon 127
    {
15 ddelon 128
        $this->HTML_listeDocuments($url,  $utilise_pager, $id_repertoire, $auth);
2 ddelon 129
 
130
    } // end of member function __construct
131
 
132
    /**
133
     *
134
     *
135
     * @param Array tableau_label Un tableau contenant les labels à afficher dans l'entête.
136
     * @return void
137
     * @access public
138
     */
139
    function construitEntete( $tableau_label )
140
    {
141
        $this->addRow ($tableau_label, NULL, 'TH') ;
142
    } // end of member function construitEntete
143
 
144
    /**
145
     *
146
     *
147
     * @param Array tableau_label Un tableau à deux dimensions avec les labels à afficher dans le corps du
148
     * tableau.
149
     * @return void
150
     * @access public
151
     */
152
    function construitListe( &$tableau_document, $droits, $mode = '', $objetDB = '')
153
    {
154
        $compteur = 0 ;$class[0] = 'ligne_impaire'; $class[1] = 'ligne_paire' ;
155
 
156
        for ($i = 0; $i < count ($tableau_document) ; $i++) {
208 neiluj 157
            // première condition : est-ce que le fichier a pour père le répertoire courant, si oui on l'affiche
2 ddelon 158
            if ($tableau_document[$i]->_id_pere == $this->_id_repertoire || $mode == 'ignore_repertoire') {
159
                // d'abord l'image
160
                $icone = '<img src="'.$tableau_document[$i]->getCheminIcone().'" />' ;
161
                // Si le document est un répertoire, on ajoute id_repertoire au lien.
162
                if ($tableau_document[$i]->isRepertoire()) {
163
                    $this->_url->addQueryString ('id_repertoire', $tableau_document[$i]->getChemin()) ;
164
                    $lien = $this->_url->getURL() ;
165
                } else {    //  Si c'est un fichier, on fait un lien direct
166
                    $lien = $tableau_document[$i]->getChemin() ;
167
                }
168
                // pour éviter des effets de bords, on enlève id_repertoire de l'url
169
                // dans le cas d'un répertoire, pour les fichiers on le laisse pour
170
                // qu'après une opération, on reste dans le répertoire où a eu lieu l'opération
171
                if ($tableau_document[$i]->isRepertoire()) $this->_url->removeQueryString('id_repertoire') ;
172
 
173
                // on insère le lien
174
                $lien_nom = '<a href="'.$lien.'">'.$icone.' '.$tableau_document[$i]->getNomLong()."</a>\n" ;
175
 
176
                // Pour la taille on divise par 1000 et on écrit Ko
177
                $taille = round($tableau_document[$i]->getTaille() / 1000).'&nbsp;Ko' ;
178
 
179
                // Récupération de l'auteur
180
                include_once PROJET_CHEMIN_CLASSES.'annuaire.class.php' ;
181
                $annuaire = new annuaire($objetDB, array('table' => PROJET_ANNUAIRE, 'identifiant' => PROJET_CHAMPS_ID,
182
                                            'nom' => PROJET_CHAMPS_NOM, 'prenom' => PROJET_CHAMPS_PRENOM)) ;
183
                $annuaire->setId($tableau_document[$i]->_id_proprietaire) ;
184
                $nom_prenom = $annuaire->getInfo('nom').' '.$annuaire->getInfo('prenom') ;
185
                // On rempli le tableau à donner en paramètre à HTML_Table avec toutes ces infos, une par colonne
186
                $ligne_tableau = array($lien_nom, $taille, $nom_prenom, $tableau_document[$i]->getDateMiseAJour()) ;
187
                if ($droits <= PROJET_DROIT_CONTRIBUTEUR) array_push ($ligne_tableau, $tableau_document[$i]->getVisibilite()) ;
188
 
189
                // On ajoute au tableau, les action couper / modifier / supprimer
190
                if ($droits <= PROJET_DROIT_COORDINATEUR || $this->_auth->getAuthData(PROJET_CHAMPS_ID) == $tableau_document[$i]->_id_proprietaire)
191
                                                array_push ($ligne_tableau, $this->_actions ($tableau_document[$i])) ;
104 alexandre_ 192
                if ($tableau_document[$i]->getVisibilite() != 'prive' || $droits < PROJET_DROIT_AUCUN) {
193
	                $this->addRow ($ligne_tableau, array('class' => $class[$compteur]), 'TD', true) ;
194
	                // enfin , s'il y a une description, on l'ajoute, mais sur une ligne entière (colspan)
195
	                if ($tableau_document[$i]->getDescription() != "") {
196
	                    $this->addRow (array ($tableau_document[$i]->getDescription()),
197
	                    		array ('colspan' => $this->getColCount(), 'class' => $class[$compteur])) ;
131 alexandre_ 198
	                    $this->updateRowAttributes ($this->getRowCount()-1, array ('class' => $class[$compteur]), true) ;
104 alexandre_ 199
	                }
2 ddelon 200
                }
201
                $compteur++;
202
            }
203
 
204
            if ($compteur == 2) $compteur = 0 ;
205
        }
206
        $this->updateColAttributes(0, array ('class' => 'col1')) ;
207
    } // end of member function construitListe
208
 
209
    /**
210
     *
211
     *
212
     * @param Array actions Un tableau avec les valeurs d'actions comme clé. "couper", modifier",
213
     * "supprimer".
214
     * @return void
215
     * @access public
216
     */
217
    function setAction( $actions )
218
    {
219
        $this->_actions = $actions ;
220
    } // end of member function setAction
221
 
222
    /**
223
     *
224
     *
225
     * @param string chemin Le chemin vers les icones couper, coller ...
226
     * @return void
227
     * @access public
228
     */
229
    function setCheminIcones( $chemin )
230
    {
231
        $this->_chemin_icone = $chemin ;
232
    } // end of member function setCheminIcones
233
 
234
    /**
235
     * Surcharge de l'opération de la classe mère. Ajoute la navigation dans les
236
     * répertoires.
237
     *
238
     * @return string
239
     * @access public
240
     */
241
    function toHTML( )
242
    {
243
        $chemin_navig = "" ;
244
        if ($this->_id_repertoire != "") {
11 alexandre_ 245
            $this->_url->removeQueryString(PROJET_VARIABLE_ID_REPERTOIRE) ;
2 ddelon 246
            $chemin_navig = "<p>" ;
247
            $chemin_navig .= "<a href=\"".$this->_url->getURL()."\">".PROJET_RACINE."</a>\n" ;
11 alexandre_ 248
            $this->_url->addQueryString(PROJET_VARIABLE_ID_REPERTOIRE, $this->_id_repertoire) ;
2 ddelon 249
            for ($i = 0; $i < count ($this->_chemin_navigation); $i+=2) {
250
                $chemin_navig .= "&gt;&nbsp;" ;
251
                $nom = $this->_chemin_navigation[$i+1] ;
252
                $this->_url->addQueryString ('id_repertoire', $this->_chemin_navigation[$i]) ;
253
                $chemin_navig .= "<a href=\"".$this->_url->getURL()."\">".$nom."</a>\n" ;
254
            }
255
            $chemin_navig .= "</p>\n" ;
256
        }
257
        $res = $chemin_navig.HTML_Liste::toHTML() ;
258
        if ($this->getRowCount() == 1 && $this->_id_repertoire == '') {
259
            return '<div>'.PROJET_PAS_DE_DOCUMENTS.'</div>'."\n";
260
        }
261
        return $res ;
262
    } // end of member function toHTML
263
 
264
    /**
265
     *
266
     *
267
     * @param Array tableau_navigation Un tableau contenant les identifiants et les noms des répertoires.  0 => ["id"],
268
     * ["nom"] etc.
269
     * @return void
270
     * @access public
271
     */
272
    function setCheminNavigation( $tableau_navigation )
273
    {
274
        $this->_chemin_navigation = $tableau_navigation ;
275
    } // end of member function setCheminNavigation
276
 
277
    /**
278
     * Affiche la légende des actions du module "documents"
279
     *
280
     * @return string
281
     * @access public
282
     */
283
    function affLegende( )
284
    {
285
        $res = "<h2 class=\"titre2_projet\">".PROJET_LEGENDE."</h2>\n" ;
286
        $res .= "<p><img src=\"".$this->_chemin_icone."/cut.gif\" title=\"couper\" alt=\"couper\">".PROJET_LEGENDE_DEPLACE."</p>\n" ;
287
        $res .= "<p><img src=\"".$this->_chemin_icone."/modif.png\" title=\"modifier\" alt=\"modifier\"> ".PROJET_LEGENDE_MODIFIE."</p>\n" ;
288
        $res .= "<p><img src=\"".$this->_chemin_icone."/trash.gif\" title=\"supprimer\" alt=\"supprimer\"> ".PROJET_LEGENDE_SUPPR."</p>\n" ;
289
        return $res ;
290
    } // end of member function affLegende
291
 
292
 
293
    /**
294
     * Renvoie le chemin HTML, depuis le répertoire courant jusqu'à la racine.
295
     *
296
     * @return string
297
     * @access private
298
     */
299
    function _getCheminHTML( )
300
    {
301
        $path = "" ;
302
 
303
        return $path ;
304
    } // end of member function _getCheminHTML
305
 
306
 
307
 
308
    /**
309
     * Renvoie une chaine contenant le code html des icones des actions possibles sur un
310
     * fichier, c'est à dire couper, modifier, supprimer.
311
     *
312
     * @return string
313
     * @access private
314
     */
315
    function _actions($document)
316
    {
317
        $this->_url->addQueryString ('id_document', $document->getIdDocument()) ;
318
 
319
        $this->_url->addQueryString (PROJET_VARIABLE_ACTION, $this->_actions["couper"]) ;
95 alexandre_ 320
        $couper = ' '.PROJET_FICHIER_COUPER ;
2 ddelon 321
        if (!$document->isRepertoire()) $couper = '<a href="'.$this->_url->getURL().'">'.$couper.'</a>' ;
322
 
323
        $this->_url->addQueryString (PROJET_VARIABLE_ACTION, $this->_actions["modifier"]) ;
95 alexandre_ 324
        $modifier = '<a href="'.$this->_url->getURL().'">'.PROJET_FICHIER_MODIFIER.'</a> ' ;
2 ddelon 325
        $this->_url->addQueryString (PROJET_VARIABLE_ACTION, $this->_actions["supprimer"]) ;
326
        $supprimer= '<a href="'.$this->_url->getURL().'" onclick="javascript:return confirm (\''.PROJET_FICHIER_SUPPRIMER.' ?\');">'.PROJET_FICHIER_SUPPRIMER.'</a>' ;
327
        $this->_url->removeQueryString ('id_document') ;
328
        $this->_url->addQueryString (PROJET_VARIABLE_ACTION, PROJET_ACTION_VOIR_DOCUMENT) ;
329
        return $modifier.$supprimer.$couper ;
330
    } // end of member function _action
331
 
332
 
333
} // end of HTML_listeDocuments
334
?>