Subversion Repositories Applications.projet

Rev

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

Rev Author Line No. Line
431 mathias 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
// +------------------------------------------------------------------------------------------------------+
22
// CVS : $Id: AJAX_arbreDocuments.class.php,v 1.1 2007/04/19 09:20:26 alexandre_tb Exp $
23
/**
24
* Application projet
25
*
26
* La classe AJAX_arbreDocuments
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
34
*@version       $Revision: 1.1 $
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
 
53
// Appel de la bibliotheque dojo
54
include_once PROJET_CHEMIN_CLASSES.'HTML_Liste.class.php';
55
GEN_stockerFichierScript('dojo', 'api/js/dojo/dojo.js', 'text/javascript');
56
 
57
/**
58
 * class HTML_listeDocuments
59
 *
60
 */
61
class AJAX_arbreDocuments extends HTML_Liste
62
{
63
    /*** Attributes: ***/
64
 
65
    /**
66
     * Une url.
67
     * @access private
68
     */
69
    var $_url;
70
 
71
    /**
72
     * Tableau contenant les actions possibles. "couper" => 1, "modifier" => 2,
73
     * "supprimer" => 3 Elles seront passées en paramètre aux url des icones des
74
     * documents.
75
     * @access private
76
     */
77
    var $_actions = array ("couper" => 1, "modifier" => 2, "supprimer" => 3) ;
78
 
79
    /**
80
     * Indique le chemin des icones couper, coller, modifier, supprimer.
81
     * @access private
82
     */
83
    var $_chemin_icone = "icones/";
84
 
85
    /**
86
     * L'identifiant du répertoire que l'on est en train d'observer.
87
     * @access private
88
     */
89
    var $_id_repertoire;
90
 
91
    /**
92
     * Un tableau contenant les id et les noms du chemin des répertoires. 0 => ["id"],
93
     * ["nom"] etc.
94
     * @access private
95
     */
96
    var $_chemin_navigation = array ();
97
 
98
    /**
99
     * un pointeur vers une authentificatin PEAR
100
     * @access private
101
     */
102
    var $_auth ;
103
    /**
104
     *
105
     *
106
     * @param bool utilise_pager Indique l'utilisation ou non du Pager.
107
     * @return void
108
     * @access public
109
     */
110
    function AJAX_arbreDocuments(&$url,  $utilise_pager = false, $id_repertoire = 0, $auth = '' )
111
    {
112
        //HTML_Liste::HTML_Liste($utilise_pager, array('class' => 'table_cadre')) ;
113
        $this->_url = $url ;
114
 
115
        $this->_id_repertoire = $id_repertoire ;
116
        if (is_object($auth)) {
117
            $this->_auth = $auth ;
118
        }
119
    } // end of member function HTML_listeDocuments
120
 
121
	function AJAX_construitListe($id_projet, $droits, $mode = '', $objetDB = '') {
122
 
123
			GEN_stockerFichierScript('dojoScriptProjet', 'client/projet/js/arbreDocument.js');
124
 
125
		$res = '' ;
126
		$RCPUrl = PROJET_CHEMIN_APPLI.'services/ecouteArbreFichier.php?id_projet='.$id_projet;
127
		// Le noeud racine
128
		$res .= '<div dojoType="TreeLoadingController" RPCUrl="'.$RCPUrl.'" widgetId="treeController" DNDController="create"></div>
129
				<div dojoType="TreeSelector" widgetId="treeSelector"></div>
130
				<div dojoType="Tree" DNDMode="between" selector="treeSelector" DNDAcceptTypes="bandTree" widgetId="bandTree" controller="treeController" eventNames="moveTo:nodeRemoved">
131
				<div dojoType="TreeNode" title="Racine" widgetId="eisleyRoot" objectId="root" isFolder="true"></div>';
132
 
133
 
134
 
135
 
136
		return $res ;
137
	}
138
    /**
139
     *
140
     *
141
     * @param bool utilise_pager Voir HTML_listeDocuments
142
     * @return void
143
     * @access public
144
     */
145
    function __construct( &$url,  $utilise_pager = false, $id_repertoire = 0, $auth = '' )
146
    {
147
        $this->AJAX_arbreDocuments($url,  $utilise_pager, $id_repertoire, $auth);
148
 
149
    } // end of member function __construct
150
 
151
    /**
152
     *
153
     *
154
     * @param Array tableau_label Un tableau contenant les labels à afficher dans l'entête.
155
     * @return void
156
     * @access public
157
     */
158
    function construitEntete( $tableau_label )
159
    {
160
        $this->addRow ($tableau_label, NULL, 'TH') ;
161
    } // end of member function construitEntete
162
 
163
    /**
164
     *
165
     *
166
     * @param Array tableau_label Un tableau à deux dimensions avec les labels à afficher dans le corps du
167
     * tableau.
168
     * @return void
169
     * @access public
170
     */
171
    function construitListe( &$tableau_document, $droits, $mode = '', $objetDB = '')
172
    {
173
        $compteur = 0 ;$class[0] = 'ligne_impaire'; $class[1] = 'ligne_paire' ;
174
 
175
        for ($i = 0; $i < count ($tableau_document) ; $i++) {
176
            // Première condition : est-ce que le fichier a pour père le répertoire courant, si oui on l'affiche
177
            if ($tableau_document[$i]->_id_pere == $this->_id_repertoire || $mode == 'ignore_repertoire') {
178
                // d'abord l'image
179
                $icone = '<img src="'.$tableau_document[$i]->getCheminIcone().'" />' ;
180
                // Si le document est un répertoire, on ajoute id_repertoire au lien.
181
                if ($tableau_document[$i]->isRepertoire()) {
182
                    $this->_url->addQueryString ('id_repertoire', $tableau_document[$i]->getChemin()) ;
183
                    $lien = $this->_url->getURL() ;
184
                } else {    //  Si c'est un fichier, on fait un lien direct
185
                    $lien = $tableau_document[$i]->getChemin() ;
186
                }
187
                // pour éviter des effets de bords, on enlève id_repertoire de l'url
188
                // dans le cas d'un répertoire, pour les fichiers on le laisse pour
189
                // qu'après une opération, on reste dans le répertoire où a eu lieu l'opération
190
                if ($tableau_document[$i]->isRepertoire()) $this->_url->removeQueryString('id_repertoire') ;
191
 
192
                // on insère le lien
193
                $lien_nom = '<a href="'.$lien.'">'.$icone.' '.$tableau_document[$i]->getNomLong()."</a>\n" ;
194
 
195
                // Pour la taille on divise par 1000 et on écrit Ko
196
                $taille = round($tableau_document[$i]->getTaille() / 1000).'&nbsp;Ko' ;
197
 
198
                // Récupération de l'auteur
199
                include_once PROJET_CHEMIN_CLASSES.'annuaire.class.php' ;
200
                $annuaire = new annuaire($objetDB, array('table' => PROJET_ANNUAIRE, 'identifiant' => PROJET_CHAMPS_ID,
201
                                            'nom' => PROJET_CHAMPS_NOM, 'prenom' => PROJET_CHAMPS_PRENOM)) ;
202
                $annuaire->setId($tableau_document[$i]->_id_proprietaire) ;
203
                $nom_prenom = $annuaire->getInfo('nom').' '.$annuaire->getInfo('prenom') ;
204
                // On rempli le tableau à donner en paramètre à HTML_Table avec toutes ces infos, une par colonne
205
                $ligne_tableau = array($lien_nom, $taille, $nom_prenom, $tableau_document[$i]->getDateMiseAJour()) ;
206
                if ($droits <= PROJET_DROIT_CONTRIBUTEUR) array_push ($ligne_tableau, $tableau_document[$i]->getVisibilite()) ;
207
 
208
                // On ajoute au tableau, les action couper / modifier / supprimer
209
                if ($droits <= PROJET_DROIT_COORDINATEUR || $this->_auth->getAuthData(PROJET_CHAMPS_ID) == $tableau_document[$i]->_id_proprietaire)
210
                                                array_push ($ligne_tableau, $this->_actions ($tableau_document[$i])) ;
211
                if ($tableau_document[$i]->getVisibilite() != 'prive' || $droits < PROJET_DROIT_AUCUN) {
212
	                $this->addRow ($ligne_tableau, array('class' => $class[$compteur]), 'TD', true) ;
213
	                // enfin , s'il y a une description, on l'ajoute, mais sur une ligne entière (colspan)
214
	                if ($tableau_document[$i]->getDescription() != "") {
215
	                    $this->addRow (array ($tableau_document[$i]->getDescription()),
216
	                    		array ('colspan' => $this->getColCount(), 'class' => $class[$compteur])) ;
217
	                    $this->updateRowAttributes ($this->getRowCount()-1, array ('class' => $class[$compteur]), true) ;
218
	                }
219
                }
220
                $compteur++;
221
            }
222
 
223
            if ($compteur == 2) $compteur = 0 ;
224
        }
225
        $this->updateColAttributes(0, array ('class' => 'col1')) ;
226
    } // end of member function construitListe
227
 
228
    /**
229
     *
230
     *
231
     * @param Array actions Un tableau avec les valeurs d'actions comme clé. "couper", modifier",
232
     * "supprimer".
233
     * @return void
234
     * @access public
235
     */
236
    function setAction( $actions )
237
    {
238
        $this->_actions = $actions ;
239
    } // end of member function setAction
240
 
241
    /**
242
     *
243
     *
244
     * @param string chemin Le chemin vers les icones couper, coller ...
245
     * @return void
246
     * @access public
247
     */
248
    function setCheminIcones( $chemin )
249
    {
250
        $this->_chemin_icone = $chemin ;
251
    } // end of member function setCheminIcones
252
 
253
    /**
254
     * Surcharge de l'opération de la classe mère. Ajoute la navigation dans les
255
     * répertoires.
256
     *
257
     * @return string
258
     * @access public
259
     */
260
    function toHTML( )
261
    {
262
        $chemin_navig = "" ;
263
        if ($this->_id_repertoire != "") {
264
            $this->_url->removeQueryString(PROJET_VARIABLE_ID_REPERTOIRE) ;
265
            $chemin_navig = "<p>" ;
266
            $chemin_navig .= "<a href=\"".$this->_url->getURL()."\">".PROJET_RACINE."</a>\n" ;
267
            $this->_url->addQueryString(PROJET_VARIABLE_ID_REPERTOIRE, $this->_id_repertoire) ;
268
            for ($i = 0; $i < count ($this->_chemin_navigation); $i+=2) {
269
                $chemin_navig .= "&gt;&nbsp;" ;
270
                $nom = $this->_chemin_navigation[$i+1] ;
271
                $this->_url->addQueryString ('id_repertoire', $this->_chemin_navigation[$i]) ;
272
                $chemin_navig .= "<a href=\"".$this->_url->getURL()."\">".$nom."</a>\n" ;
273
            }
274
            $chemin_navig .= "</p>\n" ;
275
        }
276
        $res = $chemin_navig.HTML_Liste::toHTML() ;
277
        if ($this->getRowCount() == 1 && $this->_id_repertoire == '') {
278
            return '<div>'.PROJET_PAS_DE_DOCUMENTS.'</div>'."\n";
279
        }
280
        return $res ;
281
    } // end of member function toHTML
282
 
283
    /**
284
     *
285
     *
286
     * @param Array tableau_navigation Un tableau contenant les identifiants et les noms des répertoires.  0 => ["id"],
287
     * ["nom"] etc.
288
     * @return void
289
     * @access public
290
     */
291
    function setCheminNavigation( $tableau_navigation )
292
    {
293
        $this->_chemin_navigation = $tableau_navigation ;
294
    } // end of member function setCheminNavigation
295
 
296
    /**
297
     * Affiche la légende des actions du module "documents"
298
     *
299
     * @return string
300
     * @access public
301
     */
302
    function affLegende( )
303
    {
304
        $res = "<h2 class=\"titre2_projet\">".PROJET_LEGENDE."</h2>\n" ;
305
        $res .= "<p><img src=\"".$this->_chemin_icone."/cut.gif\" title=\"couper\" alt=\"couper\">".PROJET_LEGENDE_DEPLACE."</p>\n" ;
306
        $res .= "<p><img src=\"".$this->_chemin_icone."/modif.png\" title=\"modifier\" alt=\"modifier\"> ".PROJET_LEGENDE_MODIFIE."</p>\n" ;
307
        $res .= "<p><img src=\"".$this->_chemin_icone."/trash.gif\" title=\"supprimer\" alt=\"supprimer\"> ".PROJET_LEGENDE_SUPPR."</p>\n" ;
308
        return $res ;
309
    } // end of member function affLegende
310
 
311
 
312
    /**
313
     * Renvoie le chemin HTML, depuis le répertoire courant jusqu'à la racine.
314
     *
315
     * @return string
316
     * @access private
317
     */
318
    function _getCheminHTML( )
319
    {
320
        $path = "" ;
321
 
322
        return $path ;
323
    } // end of member function _getCheminHTML
324
 
325
 
326
 
327
    /**
328
     * Renvoie une chaine contenant le code html des icones des actions possibles sur un
329
     * fichier, c'est à dire couper, modifier, supprimer.
330
     *
331
     * @return string
332
     * @access private
333
     */
334
    function _actions($document)
335
    {
336
        $this->_url->addQueryString ('id_document', $document->getIdDocument()) ;
337
 
338
        $this->_url->addQueryString (PROJET_VARIABLE_ACTION, $this->_actions["couper"]) ;
339
        $couper = ' '.PROJET_FICHIER_COUPER ;
340
        if (!$document->isRepertoire()) $couper = '<a href="'.$this->_url->getURL().'">'.$couper.'</a>' ;
341
 
342
        $this->_url->addQueryString (PROJET_VARIABLE_ACTION, $this->_actions["modifier"]) ;
343
        $modifier = '<a href="'.$this->_url->getURL().'">'.PROJET_FICHIER_MODIFIER.'</a> ' ;
344
        $this->_url->addQueryString (PROJET_VARIABLE_ACTION, $this->_actions["supprimer"]) ;
345
        $supprimer= '<a href="'.$this->_url->getURL().'" onclick="javascript:return confirm (\''.PROJET_FICHIER_SUPPRIMER.' ?\');">'.PROJET_FICHIER_SUPPRIMER.'</a>' ;
346
        $this->_url->removeQueryString ('id_document') ;
347
        $this->_url->addQueryString (PROJET_VARIABLE_ACTION, PROJET_ACTION_VOIR_DOCUMENT) ;
348
        return $modifier.$supprimer.$couper ;
349
    } // end of member function _action
350
 
351
 
352
} // end of HTML_listeDocuments
353
?>