Subversion Repositories Applications.projet

Rev

Rev 330 | Rev 397 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 330 Rev 389
1
<?php
1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */ 
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +------------------------------------------------------------------------------------------------------+
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 4.1                                                                                      |
4
// | PHP version 4.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
7
// +------------------------------------------------------------------------------------------------------+
7
// +------------------------------------------------------------------------------------------------------+
8
// | This library is free software; you can redistribute it and/or                                        |
8
// | This library is free software; you can redistribute it and/or                                        |
9
// | modify it under the terms of the GNU General Public                                                  |
9
// | modify it under the terms of the GNU General Public                                                  |
10
// | License as published by the Free Software Foundation; either                                         |
10
// | License as published by the Free Software Foundation; either                                         |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
12
// |                                                                                                      |
12
// |                                                                                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
16
// | General Public License for more details.                                                             |
16
// | General Public License for more details.                                                             |
17
// |                                                                                                      |
17
// |                                                                                                      |
18
// | You should have received a copy of the GNU General Public                                            |
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                                  |
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                            |
20
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
21
// +------------------------------------------------------------------------------------------------------+
21
// +------------------------------------------------------------------------------------------------------+
22
// CVS : $Id: document.class.php,v 1.10 2008-08-26 12:41:10 alexandre_tb Exp $
22
// CVS : $Id: document.class.php,v 1.10 2008-08-26 12:41:10 alexandre_tb Exp $
23
/**
23
/**
24
* Application projet
24
* Application projet
25
*
25
*
26
* La classe document
26
* La classe document
27
*
27
*
28
*@package projet
28
*@package projet
29
//Auteur original :
29
//Auteur original :
30
*@author        Alexandre Granier <alexandre@tela-botanica.org>
30
*@author        Alexandre Granier <alexandre@tela-botanica.org>
31
//Autres auteurs :
31
//Autres auteurs :
32
*@author        Aucun
32
*@author        Aucun
33
*@copyright     Tela-Botanica 2000-2004
33
*@copyright     Tela-Botanica 2000-2004
34
*@version       $Revision: 1.10 $
34
*@version       $Revision: 1.10 $
35
// +------------------------------------------------------------------------------------------------------+
35
// +------------------------------------------------------------------------------------------------------+
36
*/
36
*/
37
 
37
 
38
 
38
 
39
// +------------------------------------------------------------------------------------------------------+
39
// +------------------------------------------------------------------------------------------------------+
40
// |                                            ENTETE du PROGRAMME                                       |
40
// |                                            ENTETE du PROGRAMME                                       |
41
// +------------------------------------------------------------------------------------------------------+
41
// +------------------------------------------------------------------------------------------------------+
42
 
42
 
43
include_once PROJET_CHEMIN_CLASSES.'fichier.class.php' ;
43
include_once PROJET_CHEMIN_CLASSES.'fichier.class.php' ;
44
 
44
 
45
// +------------------------------------------------------------------------------------------------------+
45
// +------------------------------------------------------------------------------------------------------+
46
// |                                            ENTETE du PROGRAMME                                       |
46
// |                                            ENTETE du PROGRAMME                                       |
47
// +------------------------------------------------------------------------------------------------------+
47
// +------------------------------------------------------------------------------------------------------+
48
 
48
 
49
/**
49
/**
50
 * class document
50
 * class document
51
 * Représente un document associé à un projet. C'est à dire un fichier
51
 * Représente un document associé à un projet. C'est à dire un fichier
52
 * téléchargeable disposant en plus d'une visibilité, d'un nom long, d'une
52
 * téléchargeable disposant en plus d'une visibilité, d'un nom long, d'une
53
 * description et d'une url.
53
 * description et d'une url.
54
 */
54
 */
55
class document extends fichier
55
class document extends fichier
56
{
56
{
57
    /*** Attributes: ***/
57
    /*** Attributes: ***/
58
 
58
 
59
    /**
59
    /**
60
     * Description qui apparaitra à l'écran.
60
     * Description qui apparaitra à l'écran.
61
     * @access private
61
     * @access private
62
     */
62
     */
63
    var $_description;
63
    var $_description;
64
    /**
64
    /**
65
     * Date de dernière mise à jour des attributs du fichier.
65
     * Date de dernière mise à jour des attributs du fichier.
66
     * @access private
66
     * @access private
67
     */
67
     */
68
    var $_date_mise_a_jour;
68
    var $_date_mise_a_jour;
69
    /**
69
    /**
70
     * Soit public, soit privé.
70
     * Soit public, soit privé.
71
     * @access private
71
     * @access private
72
     */
72
     */
73
    var $_visibilite;
73
    var $_visibilite;
74
    /**
74
    /**
75
     * Le nom du fichier tel qu'il apparaitra à l'écran.
75
     * Le nom du fichier tel qu'il apparaitra à l'écran.
76
     * @access private
76
     * @access private
77
     */
77
     */
78
    var $_nom_long;
78
    var $_nom_long;
79
    /**
79
    /**
80
     * Un objet PEAR:DB
80
     * Un objet PEAR:DB
81
     * @access private
81
     * @access private
82
     */
82
     */
83
    var $_db;
83
    var $_db;
84
    
84
 
85
    /**
85
    /**
86
     * L'identifiant du document dans la table projet_document.
86
     * L'identifiant du document dans la table projet_document.
87
     * @access private
87
     * @access private
88
     */
88
     */
89
    var $_id;
89
    var $_id;
90
 
90
 
91
    /**
91
    /**
92
     * 
92
     *
93
     * @access private
93
     * @access private
94
     */
94
     */
95
    var $_chemin_icone;
95
    var $_chemin_icone;
96
    
96
 
97
    /**
97
    /**
98
     * L'identifiant du père, peut être à NULL
98
     * L'identifiant du père, peut être à NULL
99
     * @access private
99
     * @access private
100
     */
100
     */
101
    var $_id_pere;
101
    var $_id_pere;
102
    
102
 
103
    /**
103
    /**
104
     * L'identifiant du propriétaire. Provient d'un annuaire. Peut être à NULL.
104
     * L'identifiant du propriétaire. Provient d'un annuaire. Peut être à NULL.
105
     * @access private
105
     * @access private
106
     */
106
     */
107
    var $_id_proprietaire;
107
    var $_id_proprietaire;
108
    /**
108
    /**
109
     * L'identifiant du projet auquel appartient le document. Peut être à NULL.
109
     * L'identifiant du projet auquel appartient le document. Peut être à NULL.
110
     * @access private
110
     * @access private
111
     */
111
     */
112
    var $_id_projet;
112
    var $_id_projet;
113
 
113
 
114
    /**
114
    /**
115
    *   Le chemin du fichier, depuis le répertoire du projet
115
    *   Le chemin du fichier, depuis le répertoire du projet
116
    *
116
    *
117
    */
117
    */
118
    var $_pd_lien ;
118
    var $_pd_lien ;
119
    
119
 
120
    var $nom_fichier ;
120
    var $nom_fichier ;
121
    /**
121
    /**
122
     * 
122
     *
123
     *
123
     *
124
     * @param int id_document L'identifiant du document dans la base.
124
     * @param int id_document L'identifiant du document dans la base.
125
     * @param int objetDB un objet PEAR:DB
125
     * @param int objetDB un objet PEAR:DB
126
     * @return void
126
     * @return void
127
     * @access public
127
     * @access public
128
     */
128
     */
129
    function document( $id_document = "",  &$objetDB, $chemin = '', $chemin_icones = '')
129
    function document( $id_document = "",  &$objetDB, $chemin = '', $chemin_icones = '')
130
    {
130
    {
131
        if (is_object($objetDB)) {
131
        if (is_object($objetDB)) {
132
        	$GLOBALS['projet_db'] = $objetDB;
132
        	$GLOBALS['projet_db'] = $objetDB;
133
        }  
133
        }
134
        $this->_chemin_icone = $chemin_icones ;
134
        $this->_chemin_icone = $chemin_icones ;
135
        
135
 
136
        if ($id_document != "") {
136
        if ($id_document != "") {
137
            $requete = "select * from projet_documents where pd_id=".$id_document ;
137
            $requete = "select * from projet_documents where pd_id=".$id_document ;
138
            $resultat = $GLOBALS['projet_db']->query ($requete) ;
138
            $resultat = $GLOBALS['projet_db']->query ($requete) ;
139
            if (DB::isError($resultat)) {
139
            if (DB::isError($resultat)) {
140
                die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
140
                die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
141
            }
141
            }
142
            $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
142
            $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
143
    		if ($resultat->numRows()>0) {
143
    		if ($resultat->numRows()>0) {
144
	            $this->nom_fichier = $ligne->pd_lien;
144
	            $this->nom_fichier = $ligne->pd_lien;
145
	            $this->_id_projet = $ligne->pd_ce_projet;
145
	            $this->_id_projet = $ligne->pd_ce_projet;
146
	            $this->_id = $ligne->pd_id ;
146
	            $this->_id = $ligne->pd_id ;
147
	            fichier::fichier($chemin.$this->getChemin(), $GLOBALS['projet_db']) ;
147
	            fichier::fichier($chemin.$this->getChemin(), $GLOBALS['projet_db']) ;
148
	            
148
 
149
	            if (is_object ($this->_type_mime)) $this->_type_mime->setCheminIcone ($chemin_icones) ;
149
	            if (is_object ($this->_type_mime)) $this->_type_mime->setCheminIcone ($chemin_icones) ;
150
	            $this->_id_proprietaire = $ligne->pd_ce_utilisateur ;
150
	            $this->_id_proprietaire = $ligne->pd_ce_utilisateur ;
151
	            $this->_nom_long = $ligne->pd_nom ;
151
	            $this->_nom_long = $ligne->pd_nom ;
152
	            $this->_visibilite = $ligne->pd_visibilite ;
152
	            $this->_visibilite = $ligne->pd_visibilite ;
153
	            $this->_date_mise_a_jour = $ligne->pd_date_de_mise_a_jour ;
153
	            $this->_date_mise_a_jour = $ligne->pd_date_de_mise_a_jour ;
154
	            $this->_description = $ligne->pd_description ;
154
	            $this->_description = $ligne->pd_description ;
155
	            $this->_pd_lien = $ligne->pd_lien;
155
	            $this->_pd_lien = $ligne->pd_lien;
156
	            
156
 
157
	            if ($this->_isRacine($ligne->pd_pere)) {
157
	            if ($this->_isRacine($ligne->pd_pere)) {
158
	                $this->_id_pere = 0 ;
158
	                $this->_id_pere = 0 ;
159
	            } else {
159
	            } else {
160
	                $this->_id_pere = $ligne->pd_pere ;
160
	                $this->_id_pere = $ligne->pd_pere ;
161
	            }
161
	            }
162
    		}
162
    		}
163
        }
163
        }
164
        
164
 
165
    } // end of member function document
165
    } // end of member function document
166
 
166
 
167
    /**
167
    /**
168
     * 
168
     *
169
     *
169
     *
170
     * @param int id_document L'identifiant du document dans la base.
170
     * @param int id_document L'identifiant du document dans la base.
171
     * @param int objetDB Un objet PEAR:DB
171
     * @param int objetDB Un objet PEAR:DB
172
     * @return document
172
     * @return document
173
     * @access public
173
     * @access public
174
     */
174
     */
175
    function __construct( $id_document = "",  &$objetDB, $chemin = '', $chemin_icones = '' )
175
    function __construct( $id_document = "",  &$objetDB, $chemin = '', $chemin_icones = '' )
176
    {
176
    {
177
       
177
 
178
       $this->document($id_document, $objetDB, $chemin, $chemin_icones);
178
       $this->document($id_document, $objetDB, $chemin, $chemin_icones);
179
        
179
 
180
    } // end of member function __construct
180
    } // end of member function __construct
181
 
181
 
182
 
182
 
183
    /**
183
    /**
184
     * Renvoie le nom long du fichier.
184
     * Renvoie le nom long du fichier.
185
     *
185
     *
186
     * @return string
186
     * @return string
187
     * @access public
187
     * @access public
188
     */
188
     */
189
    function getNomLong( )
189
    function getNomLong( )
190
    {
190
    {
191
        return $this->_nom_long ;
191
        return $this->_nom_long ;
192
    } // end of member function getNomLong
192
    } // end of member function getNomLong
193
 
193
 
194
    /**
194
    /**
195
     * Renvoie la visibilité du document, soit "public" soit "prive"
195
     * Renvoie la visibilité du document, soit "public" soit "prive"
196
     *
196
     *
197
     * @return visibilite
197
     * @return visibilite
198
     * @access public
198
     * @access public
199
     */
199
     */
200
    function getVisibilite( )
200
    function getVisibilite( )
201
    {
201
    {
202
        return $this->_visibilite ;
202
        return $this->_visibilite ;
203
    } // end of member function getVisibilite
203
    } // end of member function getVisibilite
204
 
204
 
205
    /**
205
    /**
206
     * Renvoie la description du document, sous forme de chaine.
206
     * Renvoie la description du document, sous forme de chaine.
207
     *
207
     *
208
     * @return string
208
     * @return string
209
     * @access public
209
     * @access public
210
     */
210
     */
211
    function getDescription( )
211
    function getDescription( )
212
    {
212
    {
213
        return $this->_description ;
213
        return $this->_description ;
214
    } // end of member function getDescription
214
    } // end of member function getDescription
215
 
215
 
216
    /**
216
    /**
217
     * Renvoie la date de création ou de mise à jour du fichier.
217
     * Renvoie la date de création ou de mise à jour du fichier.
218
     *
218
     *
219
     * @return date
219
     * @return date
220
     * @access public
220
     * @access public
221
     */
221
     */
222
    function getDateMiseAJour( )
222
    function getDateMiseAJour( )
223
    {
223
    {
224
        return $this->_date_mise_a_jour ;
224
        return $this->_date_mise_a_jour ;
225
    } // end of member function getDateMiseAJour
225
    } // end of member function getDateMiseAJour
226
 
226
 
227
    /**
227
    /**
228
     * Renvoie l'identifiant d'un document.
228
     * Renvoie l'identifiant d'un document.
229
     *
229
     *
230
     * @return int
230
     * @return int
231
     * @access public
231
     * @access public
232
     */
232
     */
233
    function getIdDocument( )
233
    function getIdDocument( )
234
    {
234
    {
235
        return $this->_id ;
235
        return $this->_id ;
236
    } // end of member function getIdDocument
236
    } // end of member function getIdDocument
237
 
237
 
238
    /**
238
    /**
239
     * Renvoie le chemin de l'icone du fichier. Fait un appel à type_fichier_mime.
239
     * Renvoie le chemin de l'icone du fichier. Fait un appel à type_fichier_mime.
240
     *
240
     *
241
     * @return string
241
     * @return string
242
     * @access public
242
     * @access public
243
     */
243
     */
244
    function getCheminIcone()
244
    function getCheminIcone()
245
    {
245
    {
246
        if ($this->isRepertoire()) {
246
        if ($this->isRepertoire()) {
247
            return $this->_chemin_icone."repertoire.gif" ;
247
            return $this->_chemin_icone."repertoire.gif" ;
248
        } else {
248
        } else {
249
            if (is_object ($this->_type_mime)) return $this->_type_mime->getCheminIcone() ;
249
            if (is_object ($this->_type_mime)) return $this->_type_mime->getCheminIcone() ;
250
        }
250
        }
251
    } // end of member function getCheminIcone
251
    } // end of member function getCheminIcone
252
 
252
 
253
    /**
253
    /**
254
     * Permet de récupérer le nom du répertoire racine associé à un projet.
254
     * Permet de récupérer le nom du répertoire racine associé à un projet.
255
     *
255
     *
256
     * @param int id_projet L'identifiant du projet dont on veux récupérer le répertoire racine.
256
     * @param int id_projet L'identifiant du projet dont on veux récupérer le répertoire racine.
257
     * @param DB objetDB Un objet PEAR:DB
257
     * @param DB objetDB Un objet PEAR:DB
258
     * @return string
258
     * @return string
259
     * @static
259
     * @static
260
     * @access public
260
     * @access public
261
     */
261
     */
262
    function getNomRepertoireProjet( $id_projet , &$objetDB)
262
    function getNomRepertoireProjet( $id_projet , &$objetDB)
263
    {
263
    {
264
        // Dans la table projet_documents, pour les répertoires racines, pd_pere = null
264
        // Dans la table projet_documents, pour les répertoires racines, pd_pere = null
265
        $requete = "select pd_nom from projet_documents where pd_ce_projet=$id_projet and pd_pere is null" ;
265
        $requete = "select pd_nom from projet_documents where pd_ce_projet=$id_projet and pd_pere is null" ;
266
        $resultat = $objetDB->query ($requete) ;
266
        $resultat = $objetDB->query ($requete) ;
267
        if (DB::isError($resultat)) {
267
        if (DB::isError($resultat)) {
268
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
268
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
269
        }
269
        }
270
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
270
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
271
        return $ligne->pd_nom ;
271
        return $ligne->pd_nom ;
272
    } // end of member function getNomRepertoireProjet
272
    } // end of member function getNomRepertoireProjet
273
 
273
 
274
 
274
 
275
    /**
275
    /**
276
     * Renvoie true si le document passé en paramètre est le répertoire racine.
276
     * Renvoie true si le document passé en paramètre est le répertoire racine.
277
     *
277
     *
278
     * @param int id_document L'identifiant du document dont on veut savoir si c'est la racine.
278
     * @param int id_document L'identifiant du document dont on veut savoir si c'est la racine.
279
     * @return bool
279
     * @return bool
280
     * @access public
280
     * @access public
281
     */
281
     */
282
    function _isRacine( $id_document )
282
    function _isRacine( $id_document )
283
    {
283
    {
284
    	if ($id_document) {
284
    	if ($id_document) {
285
	        $requete = "select pd_pere from projet_documents where pd_id=".$id_document ;
285
	        $requete = "select pd_pere from projet_documents where pd_id=".$id_document ;
286
	        $resultat = $GLOBALS['projet_db']->query ($requete) ;
286
	        $resultat = $GLOBALS['projet_db']->query ($requete) ;
287
	        if (DB::isError($resultat)) {
287
	        if (DB::isError($resultat)) {
288
	            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
288
	            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
289
	        }
289
	        }
290
	        $ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT) ;
290
	        $ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT) ;
291
	        if ($resultat->numRows() >0) {
291
	        if ($resultat->numRows() >0) {
292
	        	if ($ligne->pd_pere == null){
292
	        	if ($ligne->pd_pere == null){
293
	            	return true ;
293
	            	return true ;
294
	        	}
294
	        	}
295
	        }
295
	        }
296
    	}
296
    	}
297
        return false ;
297
        return false ;
298
    } // end of member function _isRacine
298
    } // end of member function _isRacine
299
 
299
 
300
    /**
300
    /**
301
     * Renvoie le chemin d'un fichier ou d'un répertoire. Contrairement à la classe
301
     * Renvoie le chemin d'un fichier ou d'un répertoire. Contrairement à la classe
302
     * mère, cette méthode renvoie une URL projet et non pas un fichier.
302
     * mère, cette méthode renvoie une URL projet et non pas un fichier.
303
     *
303
     *
304
     * @return string
304
     * @return string
305
     * @access public
305
     * @access public
306
     */
306
     */
307
    function getChemin($prefixe = '')
307
    function getChemin($prefixe = '')
308
    {
308
    {
309
        $chemin_repertoire_entre_racine_et_fichier = '';
309
        $chemin_repertoire_entre_racine_et_fichier = '';
310
 
310
 
311
        include_once PROJET_CHEMIN_CLASSES.'projet.class.php';
311
        include_once PROJET_CHEMIN_CLASSES.'projet.class.php';
312
        $projet = new projet ($GLOBALS['projet_db'], $this->_id_projet);
312
        $projet = new projet ($GLOBALS['projet_db'], $this->_id_projet);
313
        // l arborescence des repertoires
313
        // l arborescence des repertoires
314
        
314
 
315
        $tableau_navigation = $this->getPath($this->_id) ;
315
        $tableau_navigation = $this->getPath($this->_id) ;
316
        if (is_array ($tableau_navigation))$tableau_navigation = array_reverse($tableau_navigation);
316
        if (is_array ($tableau_navigation))$tableau_navigation = array_reverse($tableau_navigation);
317
        for ($i = 0; $i < count ($tableau_navigation); $i++) {
317
        for ($i = 0; $i < count ($tableau_navigation); $i++) {
318
        	$chemin_repertoire_entre_racine_et_fichier.= $tableau_navigation[$i]."/";	
318
        	$chemin_repertoire_entre_racine_et_fichier.= $tableau_navigation[$i]."/";
319
        }
319
        }
320
        return $projet->getNomRepertoire().'/'.$chemin_repertoire_entre_racine_et_fichier.$this->nom_fichier ;
320
        return $projet->getNomRepertoire().'/'.$chemin_repertoire_entre_racine_et_fichier.$this->nom_fichier ;
321
    } 
321
    }
322
 
322
 
323
 
323
 
324
    /**
324
    /**
325
     * Renvoie pour le repertoire ou le fichier courant, les identifiants et les noms de tous les
325
     * Renvoie pour le repertoire ou le fichier courant, les identifiants et les noms de tous les
326
     * répertoires père jusqu'à la racine. 0 => ['id'], ['nom'] 1 => [id'], ['nom'] etc.
326
     * répertoires père jusqu'à la racine. 0 => ['id'], ['nom'] 1 => [id'], ['nom'] etc.
327
     * En commençant par la racine et en descendant.  Pour la racine id vaut "" et nom
327
     * En commençant par la racine et en descendant.  Pour la racine id vaut "" et nom
328
     * vaut "".
328
     * vaut "".
329
     *
329
     *
330
     * @param int id_repertoire L'identifiant d'un répertoire.
330
     * @param int id_repertoire L'identifiant d'un répertoire.
331
     * @return Array
331
     * @return Array
332
     * @access public
332
     * @access public
333
     */
333
     */
334
     
334
 
335
    function getCheminIdRepertoire( $id_doc, &$objetDB )
335
    function getCheminIdRepertoire( $id_doc, &$objetDB )
336
    {
336
    {
337
        if ($id_doc == "") $id_doc = 0;
337
        if ($id_doc == "") $id_doc = 0;
338
        // on commence par rechercher le répertoire père, dans la base de donnée
338
        // on commence par rechercher le répertoire père, dans la base de donnée
339
        $requete = 'select pd_pere, pd_nom, pd_id, pd_ce_type from projet_documents where pd_id='.$id_doc ;
339
        $requete = 'select pd_pere, pd_nom, pd_id, pd_ce_type from projet_documents where pd_id='.$id_doc ;
340
        $resultat = $objetDB->query ($requete) ;
340
        $resultat = $objetDB->query ($requete) ;
341
        if (DB::isError($resultat)) {
341
        if (DB::isError($resultat)) {
342
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
342
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
343
        }
343
        }
344
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
344
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
345
        $chemin_rep_id_nom = array() ;
345
        $chemin_rep_id_nom = array() ;
346
        if ($resultat->numRows()>0) {
346
        if ($resultat->numRows()>0) {
347
    	    if ($ligne->pd_pere == 0) {
347
    	    if ($ligne->pd_pere == 0) {
348
        	    return array ($ligne->pd_id);
348
        	    return array ($ligne->pd_id);
349
        	}
349
        	}
350
            array_push ($chemin_rep_id_nom, $ligne->pd_id) ;
350
            array_push ($chemin_rep_id_nom, $ligne->pd_id) ;
351
            $tab = document::getCheminIdRepertoire($ligne->pd_pere, $objetDB) ;
351
            $tab = document::getCheminIdRepertoire($ligne->pd_pere, $objetDB) ;
352
            $chemin_rep_id_nom = array_merge ($tab, $chemin_rep_id_nom) ;
352
            $chemin_rep_id_nom = array_merge ($tab, $chemin_rep_id_nom) ;
353
        }
353
        }
354
        return ($chemin_rep_id_nom);
354
        return ($chemin_rep_id_nom);
355
    }
355
    }
-
 
356
 
356
	function getPath( $id_doc)
357
	function getPath( $id_doc)
357
    {
358
    {
358
        if ($id_doc == "") $id_doc = 0;
359
        if ($id_doc == "") $id_doc = 0;
359
        // on commence par rechercher le répertoire père, dans la base de donnée
360
        // on commence par rechercher le répertoire père, dans la base de donnée
360
        $requete = 'select pd_pere, pd_nom, pd_id, pd_ce_type from projet_documents where pd_id='.$id_doc ;
361
        $requete = 'select pd_pere, pd_nom, pd_id, pd_ce_type from projet_documents where pd_id='.$id_doc ;
361
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
362
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
-
 
363
 
362
        if (DB::isError($resultat)) {
364
        if (DB::isError($resultat)) {
363
            return ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
365
           return ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
364
        }
366
        }
365
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
367
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
-
 
368
 
366
        $chemin_rep_id_nom = array() ;
369
        $chemin_rep_id_nom = array() ;
367
        if ($resultat->numRows()>0) {
370
        if ($resultat->numRows()>0 && $ligne->pd_pere != 0 && $ligne->pd_pere != $ligne->pd_id) {
368
    	    if ($ligne->pd_pere == 0) {
-
 
369
        	    return array();
-
 
370
        	}
371
 
371
            array_push ($chemin_rep_id_nom, $ligne->pd_pere) ;
372
			array_push ($chemin_rep_id_nom, $ligne->pd_pere) ;
-
 
373
 
-
 
374
			// Récursion sur le répertoires ou fichiers fils
372
            $chemin_rep_id_nom = array_merge ($chemin_rep_id_nom, document::getPath($ligne->pd_pere) );
375
			$chemin_rep_id_nom = array_merge ($chemin_rep_id_nom, document::getPath($ligne->pd_pere) );
373
        }
376
        }
-
 
377
 
374
        return $chemin_rep_id_nom;
378
        return $chemin_rep_id_nom;
375
    }
379
    }
-
 
380
 
376
    /**
381
    /**
377
     *  Calcule le chemin vers le fichier ou le répertoire uploadé
382
     *  Calcule le chemin vers le fichier ou le répertoire uploadé
378
     *  renvoie un chaine de la forme dir1/dir2/fichier.ext
383
     *  renvoie un chaine de la forme dir1/dir2/fichier.ext
379
     *  En prenant comme racine le répertoire du projet, exclu.
384
     *  En prenant comme racine le répertoire du projet, exclu.
380
     * @return  string  Le chemin
385
     * @return  string  Le chemin
381
     */
386
     */
382
 
387
 
383
    function calculeCheminUploaded ($radical) {
388
    function calculeCheminUploaded ($radical) {
384
 
389
 
385
        if (isset($_FILES['fichier']['name'])) {
390
        if (isset($_FILES['fichier']['name'])) {
386
        	$extension = preg_replace("/^([^\.]+)\.(\w+$)/", "\\2", $_FILES['fichier']['name']) ;
391
        	$extension = preg_replace("/^([^\.]+)\.(\w+$)/", "\\2", $_FILES['fichier']['name']) ;
387
        } 
392
        }
388
 
393
 
389
        if ($this->_id_pere != '') {
394
        if ($this->_id_pere != '') {
390
            // On appelle la méthode getCheminIdRepertoire qui renvoie un tableau avec la liste
395
            // On appelle la méthode getCheminIdRepertoire qui renvoie un tableau avec la liste
391
            // des répertoires jusqu'à la racine, on enlève la racine ($i = 0) et on concatène
396
            // des répertoires jusqu'à la racine, on enlève la racine ($i = 0) et on concatène
392
            // toutes les entrées pour obtenir le chemin jusqu'au répertoire courant
397
            // toutes les entrées pour obtenir le chemin jusqu'au répertoire courant
393
            $chemin_repertoire_entre_racine_et_repertoire_a_cree = '' ;
398
            $chemin_repertoire_entre_racine_et_repertoire_a_cree = '' ;
394
            $doc_pere = new document ($this->_id_pere, $GLOBALS['projet_db']);
399
            $doc_pere = new document ($this->_id_pere, $GLOBALS['projet_db']);
395
            return $doc_pere->getChemin();
400
            return $doc_pere->getChemin();
396
            $tableau_navigation = $this->getPath($this->_id_pere) ;
401
            $tableau_navigation = $this->getPath($this->_id_pere) ;
397
            
402
 
398
            for ($i = 0; $i < count ($tableau_navigation); $i++) $chemin_repertoire_entre_racine_et_repertoire_a_cree.= $tableau_navigation[$i]."/";
403
            for ($i = 0; $i < count ($tableau_navigation); $i++) $chemin_repertoire_entre_racine_et_repertoire_a_cree.= $tableau_navigation[$i]."/";
399
            $chemin = $chemin_repertoire_entre_racine_et_repertoire_a_cree ;
404
            $chemin = $chemin_repertoire_entre_racine_et_repertoire_a_cree ;
400
        } else {
405
        } else {
401
            // Si l'on est à la racine du projet, le chemin vide
406
            // Si l'on est à la racine du projet, le chemin vide
402
            return $radical ;
407
            return $radical ;
403
        }
408
        }
404
        return $chemin ;
409
        return $chemin ;
405
    }
410
    }
406
 
411
 
407
    /**
412
    /**
408
     * Enregistre une ligne dans la table projet_document
413
     * Enregistre une ligne dans la table projet_document
409
     * Le tableau de valeur doit contenir les éléments suivants 'document_nom','document_description','document_visibilite','fichier'
414
     * Le tableau de valeur doit contenir les éléments suivants 'document_nom','document_description','document_visibilite','fichier'
410
     *
415
     *
411
     * @param Array tableau_de_valeur Le tableau de valeur a insérer dans la base avec pour clé les noms des éléments
416
     * @param Array tableau_de_valeur Le tableau de valeur a insérer dans la base avec pour clé les noms des éléments
412
     * @access  public
417
     * @access  public
413
     * @return void
418
     * @return void
414
     */
419
     */
415
 
420
 
416
    function enregistrerSQL ($valeur, $chemin) {
421
    function enregistrerSQL ($valeur, $chemin) {
417
        
422
 
418
        // On teste si on a affaire à un répertoire ou un fichier
423
        // On teste si on a affaire à un répertoire ou un fichier
419
        if (isset ($_FILES['fichier']['name'])) {
424
        if (isset ($_FILES['fichier']['name'])) {
420
            // On tente de déterminer le type du fichier à partir de son nom dans $valeur['$fichier']
425
            // On tente de déterminer le type du fichier à partir de son nom dans $valeur['$fichier']
421
            $tableau_nom = explode (".", $_FILES['fichier']['name']) ;
426
            $tableau_nom = explode (".", $_FILES['fichier']['name']) ;
422
    
427
 
423
            // On prend le dernier élément du tableau, si c'est un tableau 
428
            // On prend le dernier élément du tableau, si c'est un tableau
424
            if (is_array($tableau_nom)) {
429
            if (is_array($tableau_nom)) {
425
                $extension = array_pop($tableau_nom) ;
430
                $extension = array_pop($tableau_nom) ;
426
                $type = type_fichier_mime::factory($extension) ;
431
                $type = type_fichier_mime::factory($extension) ;
427
                $id_extension = $type->getIdType() ;
432
                $id_extension = $type->getIdType() ;
428
            } else {
433
            } else {
429
                $id_extension = 12 ;
434
                $id_extension = 12 ;
430
            }
435
            }
431
            $pd_lien = $chemin ;
436
            $pd_lien = $chemin ;
432
        } else {    // Le cas ou on a affaire à un répertoire
437
        } else {    // Le cas ou on a affaire à un répertoire
433
            $id_extension = 0 ;
438
            $id_extension = 0 ;
434
            // Le nom du répertoire est son identifiant avec un slash à la fin
439
            // Le nom du répertoire est son identifiant avec un slash à la fin
435
            $pd_lien = $chemin."/" ;
440
            $pd_lien = $chemin."/" ;
436
            if ($this->_id_pere != '') {
441
            if ($this->_id_pere != '') {
437
                // On appelle la méthode getCheminIdRepertoire qui renvoie un tableau avec la liste
442
                // On appelle la méthode getCheminIdRepertoire qui renvoie un tableau avec la liste
438
                // des répertoires jusqu'à la racine, on enlève la racine ($i = 0) et on concatène
443
                // des répertoires jusqu'à la racine, on enlève la racine ($i = 0) et on concatène
439
                // toutes les entrées pour obtenir le chemin jusqu'au répertoire courant
444
                // toutes les entrées pour obtenir le chemin jusqu'au répertoire courant
440
                $chemin_repertoire_entre_racine_et_repertoire_a_cree = '' ;
445
                $chemin_repertoire_entre_racine_et_repertoire_a_cree = '' ;
441
                $tableau_navigation = $this->getCheminIdRepertoire($this->_id_pere, $GLOBALS['projet_db']) ;
446
                $tableau_navigation = $this->getCheminIdRepertoire($this->_id_pere, $GLOBALS['projet_db']) ;
442
                for ($i = 0; $i < count ($tableau_navigation); $i+=2) $chemin_repertoire_entre_racine_et_repertoire_a_cree.= $tableau_navigation[$i]."/";
447
                for ($i = 0; $i < count ($tableau_navigation); $i+=2) $chemin_repertoire_entre_racine_et_repertoire_a_cree.= $tableau_navigation[$i]."/";
443
                $pd_lien .= $chemin_repertoire_entre_racine_et_repertoire_a_cree ;
448
                $pd_lien .= $chemin_repertoire_entre_racine_et_repertoire_a_cree ;
444
            }
449
            }
445
            //$pd_lien .= SQL_obtenirNouveauId($GLOBALS['projet_db'], 'projet_documents', 'pd_id')."/" ;
450
            //$pd_lien .= SQL_obtenirNouveauId($GLOBALS['projet_db'], 'projet_documents', 'pd_id')."/" ;
446
            $pd_lien = SQL_obtenirNouveauId($GLOBALS['projet_db'], 'projet_documents', 'pd_id')."/" ;
451
            $pd_lien = SQL_obtenirNouveauId($GLOBALS['projet_db'], 'projet_documents', 'pd_id')."/" ;
447
        }
452
        }
448
        $id = SQL_obtenirNouveauId($GLOBALS['projet_db'], 'projet_documents', 'pd_id') ;
453
        $id = SQL_obtenirNouveauId($GLOBALS['projet_db'], 'projet_documents', 'pd_id') ;
449
 
454
 
450
        $requete = "insert into projet_documents set pd_id=".$id ;
455
        $requete = "insert into projet_documents set pd_id=".$id ;
451
        $requete .= ", pd_nom=\"".$valeur['document_nom']."\", pd_description=\"".$valeur['document_description']."\"".
456
        $requete .= ", pd_nom=\"".$valeur['document_nom']."\", pd_description=\"".$valeur['document_description']."\"".
452
                    ", pd_visibilite=\"".$valeur['document_visibilite']."\", pd_date_de_mise_a_jour=NOW(),".
457
                    ", pd_visibilite=\"".$valeur['document_visibilite']."\", pd_date_de_mise_a_jour=NOW(),".
453
                    "pd_ce_projet=\"".$this->_id_projet."\", pd_ce_utilisateur=\"".$this->_id_proprietaire."\"".
458
                    "pd_ce_projet=\"".$this->_id_projet."\", pd_ce_utilisateur=\"".$this->_id_proprietaire."\"".
454
                    ", pd_pere=\"$this->_id_pere\", pd_ce_type=\"$id_extension\", pd_lien=\"$pd_lien\"" ;
459
                    ", pd_pere=\"$this->_id_pere\", pd_ce_type=\"$id_extension\", pd_lien=\"$pd_lien\"" ;
455
 
460
 
456
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
461
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
457
        if (DB::isError($resultat)) {
462
        if (DB::isError($resultat)) {
458
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
463
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
459
        }
464
        }
460
        $this->_id = $id ;
465
        $this->_id = $id ;
461
        return $pd_lien;
466
        return $pd_lien;
462
    }
467
    }
463
 
468
 
464
	function genereNouveauNom ($radical, $ancien_nom, $id) {
469
	function genereNouveauNom ($radical, $ancien_nom, $id) {
465
		$extension = preg_replace("/^([^\.]+)\.(\w+$)/", "\\2", $ancien_nom) ;
470
		$extension = preg_replace("/^([^\.]+)\.(\w+$)/", "\\2", $ancien_nom) ;
466
        $nouveau_nom = $radical."_".$id.".".$extension ;
471
        $nouveau_nom = $radical."_".$id.".".$extension ;
467
        return $nouveau_nom;
472
        return $nouveau_nom;
468
	}
473
	}
469
 
474
 
470
    /**
475
    /**
471
     * Met à jour une ligne dans la table projet_document
476
     * Met à jour une ligne dans la table projet_document
472
     * Le tableau de valeur doit contenir les éléments suivants 'document_nom','document_description','document_visibilite','fichier'
477
     * Le tableau de valeur doit contenir les éléments suivants 'document_nom','document_description','document_visibilite','fichier'
473
     *
478
     *
474
     * @param Array tableau_de_valeur Le tableau de valeur a insérer dans la base avec pour clé les noms des éléments
479
     * @param Array tableau_de_valeur Le tableau de valeur a insérer dans la base avec pour clé les noms des éléments
475
     * @access  public
480
     * @access  public
476
     * @return void
481
     * @return void
477
     */
482
     */
478
 
483
 
479
    function majSQL ($valeur) {
484
    function majSQL ($valeur) {
480
        $requete = "update projet_documents set pd_nom=\"".$valeur['document_nom']."\", pd_description=\"".$valeur['document_description']."\"".
485
        $requete = "update projet_documents set pd_nom=\"".$valeur['document_nom']."\", pd_description=\"".$valeur['document_description']."\"".
481
                    ", pd_visibilite=\"".$valeur['document_visibilite']."\", pd_date_de_mise_a_jour=NOW()".
486
                    ", pd_visibilite=\"".$valeur['document_visibilite']."\", pd_date_de_mise_a_jour=NOW()".
482
                    " where pd_id=".$this->_id;
487
                    " where pd_id=".$this->_id;
483
 
488
 
484
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
489
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
485
        if (DB::isError($resultat)) {
490
        if (DB::isError($resultat)) {
486
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
491
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
487
        }
492
        }
488
        return ;
493
        return ;
489
    }
494
    }
490
 
495
 
491
    /** Supprime les donnéexs du document dans la table projet_documents
496
    /** Supprime les donnéexs du document dans la table projet_documents
492
     *
497
     *
493
     *
498
     *
494
     * @return true en cas de succès
499
     * @return true en cas de succès
495
     */
500
     */
496
    
501
 
497
    function suppressionSQL () {
502
    function suppressionSQL () {
498
        $requete = 'delete from projet_documents where pd_id='.$this->_id ;
503
        $requete = 'delete from projet_documents where pd_id='.$this->_id ;
499
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
504
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
500
        if ($GLOBALS['projet_db']->affectedRows()) return true ;
505
        if ($GLOBALS['projet_db']->affectedRows()) return true ;
501
        return false ;
506
        return false ;
502
    }
507
    }
503
    
508
 
504
    /**
509
    /**
505
     * Déplace un document au sein d'un même projet
510
     * Déplace un document au sein d'un même projet
506
     *
511
     *
507
     * @param int repertoire_destination L'identifiant du répertoire destination.
512
     * @param int repertoire_destination L'identifiant du répertoire destination.
508
     * @return bool
513
     * @return bool
509
     * @access public
514
     * @access public
510
     */
515
     */
511
    function deplace( $repertoire_destination, $repertoire_projet )
516
    function deplace( $repertoire_destination, $repertoire_projet )
512
    {
517
    {
513
 
518
 
514
        // On récupère les informations du répertoire cible
519
        // On récupère les informations du répertoire cible
515
        if ($repertoire_destination != 0) {
520
        if ($repertoire_destination != 0) {
516
            $repertoire_cible = new document ($repertoire_destination, $GLOBALS['projet_db']) ;
521
            $repertoire_cible = new document ($repertoire_destination, $GLOBALS['projet_db']) ;
517
            $chemin_rep_cible = $repertoire_cible->getChemin();
522
            $chemin_rep_cible = $repertoire_cible->getChemin();
518
        } else {
523
        } else {
519
        	// Si le repertoire destination est la racine cad id =0
524
        	// Si le repertoire destination est la racine cad id =0
520
        	// on cree un document qui aura pour chemin le repertoire du projet 
525
        	// on cree un document qui aura pour chemin le repertoire du projet
521
        	include_once PROJET_CHEMIN_CLASSES.'projet.class.php';
526
        	include_once PROJET_CHEMIN_CLASSES.'projet.class.php';
522
            $projet = new projet ($GLOBALS['projet_db'], $this->_id_projet);
527
            $projet = new projet ($GLOBALS['projet_db'], $this->_id_projet);
523
        	$chemin_rep_cible = $projet->getNomRepertoire().'/';
528
        	$chemin_rep_cible = $projet->getNomRepertoire().'/';
524
        }
529
        }
525
   
530
 
526
        $nom_fichier = $this->_pd_lien ;
531
        $nom_fichier = $this->_pd_lien ;
527
        $requete = 'update projet_documents set pd_pere='.$repertoire_destination.' where pd_id='.$this->_id ;
532
        $requete = 'update projet_documents set pd_pere='.$repertoire_destination.' where pd_id='.$this->_id ;
528
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
533
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
529
        if (DB::isError($resultat)) {
534
        if (DB::isError($resultat)) {
530
            echo ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
535
            echo ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
531
            return false ;
536
            return false ;
532
        }
537
        }
533
        //echo $this->_chemin.'<br>'.PROJET_CHEMIN_FICHIER.$chemin_rep_cible.$nom_fichier;
538
        //echo $this->_chemin.'<br>'.PROJET_CHEMIN_FICHIER.$chemin_rep_cible.$nom_fichier;
534
        return fichier::deplace ($this->_chemin, PROJET_CHEMIN_FICHIER.$chemin_rep_cible.$nom_fichier) ;
539
        return fichier::deplace ($this->_chemin, PROJET_CHEMIN_FICHIER.$chemin_rep_cible.$nom_fichier) ;
535
        
540
 
536
    } // end of member function deplace
541
    } // end of member function deplace
537
 
542
 
538
 
543
 
539
    /**
544
    /**
540
     * Pour modifier l'identifiant du projet auquel appartient un document.
545
     * Pour modifier l'identifiant du projet auquel appartient un document.
541
     *
546
     *
542
     * @param int id_projet L'identifiant du projet.
547
     * @param int id_projet L'identifiant du projet.
543
     * @return void
548
     * @return void
544
     * @access public
549
     * @access public
545
     */
550
     */
546
    function setIdProjet( $id_projet )
551
    function setIdProjet( $id_projet )
547
    {
552
    {
548
        $this->_id_projet = $id_projet ;
553
        $this->_id_projet = $id_projet ;
549
    } // end of member function setIdProjet
554
    } // end of member function setIdProjet
550
 
555
 
551
    /**
556
    /**
552
     * Permet de modifier l'identifiant du propietaire d'un projet.
557
     * Permet de modifier l'identifiant du propietaire d'un projet.
553
     *
558
     *
554
     * @param int id_proprietaire L'identifiant du proprietaire d'un document.
559
     * @param int id_proprietaire L'identifiant du proprietaire d'un document.
555
     * @return void
560
     * @return void
556
     * @access public
561
     * @access public
557
     */
562
     */
558
    function setIdProprietaire( $id_proprietaire )
563
    function setIdProprietaire( $id_proprietaire )
559
    {
564
    {
560
        $this->_id_proprietaire = $id_proprietaire ;
565
        $this->_id_proprietaire = $id_proprietaire ;
561
    } // end of member function setIdProprietaire
566
    } // end of member function setIdProprietaire
562
 
567
 
563
    /**
568
    /**
564
     * Permet de modifier l'identifiant du répertoire d'un document.
569
     * Permet de modifier l'identifiant du répertoire d'un document.
565
     *
570
     *
566
     * @param int id_repertoire L'identifiant du repertoire d'un document.
571
     * @param int id_repertoire L'identifiant du repertoire d'un document.
567
     * @return void
572
     * @return void
568
     * @access public
573
     * @access public
569
     */
574
     */
570
    function setIdRepertoire( $id_repertoire )
575
    function setIdRepertoire( $id_repertoire )
571
    {
576
    {
572
        $this->_id_pere = $id_repertoire;
577
        $this->_id_pere = $id_repertoire;
573
    } // end of member function setIdRepertoire
578
    } // end of member function setIdRepertoire
574
 
579
 
575
    /**
580
    /**
576
     * initAttributes sets all document attributes to its default                    value make
581
     * initAttributes sets all document attributes to its default                    value make
577
     * sure to call this method within your class constructor
582
     * sure to call this method within your class constructor
578
     */
583
     */
579
    function initAttributes( )
584
    function initAttributes( )
580
    {
585
    {
581
        $this->_visibilite = "public";
586
        $this->_visibilite = "public";
582
    }
587
    }
583
 
588
 
584
    /**
589
    /**
585
     * Renvoie les derniers documents de l'ensemble des projets.
590
     * Renvoie les derniers documents de l'ensemble des projets.
586
     *
591
     *
587
     * @param int nombre Le nombre de document à renvoyer
592
     * @param int nombre Le nombre de document à renvoyer
588
     * @return Array
593
     * @return Array
589
     * @static
594
     * @static
590
     * @access public
595
     * @access public
591
     */
596
     */
592
    function getDocumentsRecents( $nombre = 10, &$objetDB, $chemin, $chemin_icones, $id_projet = '', $visible = true)
597
    function getDocumentsRecents( $nombre = 10, &$objetDB, $chemin, $chemin_icones, $id_projet = '', $visible = true)
593
    {
598
    {
594
        // on recherche les documents, hors repertoire
599
        // on recherche les documents, hors repertoire
595
        $requete = 'select pd_id from projet_documents where pd_ce_type<>0 ';
600
        $requete = 'select pd_id from projet_documents where pd_ce_type<>0 ';
596
        if ($id_projet != '') $requete .= ' and pd_ce_projet='.$id_projet.' ';
601
        if ($id_projet != '') $requete .= ' and pd_ce_projet='.$id_projet.' ';
597
        if (!$visible) $requete .= ' and pd_visibilite="public" ';
602
        if (!$visible) $requete .= ' and pd_visibilite="public" ';
598
        $requete .= 'order by pd_date_de_mise_a_jour desc limit 0,'.$nombre ;
603
        $requete .= 'order by pd_date_de_mise_a_jour desc limit 0,'.$nombre ;
599
        $resultat = $objetDB->query ($requete) ;
604
        $resultat = $objetDB->query ($requete) ;
600
        if (DB::isError ($resultat)) {
605
        if (DB::isError ($resultat)) {
601
            die ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
606
            die ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
602
        }
607
        }
603
        $tableau_document = array() ;
608
        $tableau_document = array() ;
604
        
609
 
605
        while ($ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT)) {
610
        while ($ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT)) {
606
            array_push ($tableau_document, new document ($ligne->pd_id, $objetDB, $chemin, $chemin_icones)) ;
611
            array_push ($tableau_document, new document ($ligne->pd_id, $objetDB, $chemin, $chemin_icones)) ;
607
        }
612
        }
608
        return $tableau_document ;
613
        return $tableau_document ;
609
    } // end of member function getDocumentsRecents
614
    } // end of member function getDocumentsRecents
610
 
615
 
611
    /**
616
    /**
612
     * Renvoie les documents du projet passe en parametre sous forme d arbre d objet document
617
     * Renvoie les documents du projet passe en parametre sous forme d arbre d objet document
613
     *
618
     *
614
     * @param int l identifiant du projet
619
     * @param int l identifiant du projet
615
     * @return Array
620
     * @return Array
616
     * @static
621
     * @static
617
     * @access public
622
     * @access public
618
     */
623
     */
619
	function getArbreDocument($id_projet, $objetDB = '') {
624
	function getArbreDocument($id_projet, $objetDB = '') {
620
		$requete = 'select pd_id, pd_nom, pd_ce_type, pd_pere from projet_documents where pd_ce_projet='.$id_projet;
625
		$requete = 'select pd_id, pd_nom, pd_ce_type, pd_pere from projet_documents where pd_ce_projet='.$id_projet;
621
		$resultat = $GLOBALS['projet_db']->getAll($requete, null, DB_FETCHMODE_OBJECT);
626
		$resultat = $GLOBALS['projet_db']->getAll($requete, null, DB_FETCHMODE_OBJECT);
622
		if (DB::isError ($resultat)) {
627
		if (DB::isError ($resultat)) {
623
            return ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
628
            return ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
624
        }
629
        }
625
	
630
 
626
      	return $resultat;
631
      	return $resultat;
627
	}
632
	}
628
	 /**
633
	 /**
629
     * Renvoie la taille du document formatee avec une unite adapte
634
     * Renvoie la taille du document formatee avec une unite adapte
630
     *
635
     *
631
     * @return string La taille formate
636
     * @return string La taille formate
632
     * @access public
637
     * @access public
633
     */
638
     */
634
	function getTailleFormatee($precision = 1) {
639
	function getTailleFormatee($precision = 1) {
635
		$taille = $this->getTaille();
640
		$taille = $this->getTaille();
636
		if ($taille > 1000000) {
641
		if ($taille > 1000000) {
637
			$diviseur = 1000000;
642
			$diviseur = 1000000;
638
			$unite = 'Mo';
643
			$unite = 'Mo';
639
		} else {
644
		} else {
640
			$diviseur = 1000 ;
645
			$diviseur = 1000 ;
641
			$unite = 'Ko';
646
			$unite = 'Ko';
642
		}
647
		}
643
		return round ($taille / $diviseur, $precision).'&nbsp;'.$unite;
648
		return round ($taille / $diviseur, $precision).'&nbsp;'.$unite;
644
	}
649
	}
645
	
650
 
646
	/**
651
	/**
647
     * Renvoie une liste de document, enfant du document courant
652
     * Renvoie une liste de document, enfant du document courant
648
     * qui doit etre un repertoire bien sur
653
     * qui doit etre un repertoire bien sur
649
     *
654
     *
650
     * @return mixed un tableau de document
655
     * @return mixed un tableau de document
651
     * @access public
656
     * @access public
652
     */
657
     */
653
	function getDocumentsEnfant() {
658
	function getDocumentsEnfant() {
654
		
659
 
655
	}
660
	}
656
 
661
 
657
} // end of document
662
} // end of document
658
 
663
 
659
 
664
 
660
?>
665
?>