Subversion Repositories Applications.projet

Rev

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

Rev 249 Rev 309
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.8 2007-06-25 12:15:06 alexandre_tb Exp $
22
// CVS : $Id: document.class.php,v 1.9 2008-08-25 15:18: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.8 $
34
*@version       $Revision: 1.9 $
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
        $this->_db = $objetDB ;
131
        if (is_object($objetDB)) {
-
 
132
        	$GLOBALS['projet_db'] = $objetDB;
-
 
133
        }  
132
        $this->_chemin_icone = $chemin_icones ;
134
        $this->_chemin_icone = $chemin_icones ;
133
        
135
        
134
        if ($id_document != "") {
136
        if ($id_document != "") {
135
            $requete = "select * from projet_documents where pd_id=".$id_document ;
137
            $requete = "select * from projet_documents where pd_id=".$id_document ;
136
            $resultat = $this->_db->query ($requete) ;
138
            $resultat = $GLOBALS['projet_db']->query ($requete) ;
137
            if (DB::isError($resultat)) {
139
            if (DB::isError($resultat)) {
138
                die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
140
                die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
139
            }
141
            }
140
            $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
142
            $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
141
    		if ($resultat->numRows()>0) {
143
    		if ($resultat->numRows()>0) {
142
	            $this->nom_fichier = $ligne->pd_lien;
144
	            $this->nom_fichier = $ligne->pd_lien;
143
	            $this->_id_projet = $ligne->pd_ce_projet;
145
	            $this->_id_projet = $ligne->pd_ce_projet;
144
	            $this->_id = $ligne->pd_id ;
146
	            $this->_id = $ligne->pd_id ;
145
	            fichier::fichier($chemin.$this->getChemin(), $this->_db) ;
147
	            fichier::fichier($chemin.$this->getChemin(), $GLOBALS['projet_db']) ;
146
	            
148
	            
147
	            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) ;
148
	            $this->_id_proprietaire = $ligne->pd_ce_utilisateur ;
150
	            $this->_id_proprietaire = $ligne->pd_ce_utilisateur ;
149
	            $this->_nom_long = $ligne->pd_nom ;
151
	            $this->_nom_long = $ligne->pd_nom ;
150
	            $this->_visibilite = $ligne->pd_visibilite ;
152
	            $this->_visibilite = $ligne->pd_visibilite ;
151
	            $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 ;
152
	            $this->_description = $ligne->pd_description ;
154
	            $this->_description = $ligne->pd_description ;
153
	            $this->_pd_lien = $ligne->pd_lien;
155
	            $this->_pd_lien = $ligne->pd_lien;
154
	            
156
	            
155
	            if ($this->_isRacine($ligne->pd_pere)) {
157
	            if ($this->_isRacine($ligne->pd_pere)) {
156
	                $this->_id_pere = 0 ;
158
	                $this->_id_pere = 0 ;
157
	            } else {
159
	            } else {
158
	                $this->_id_pere = $ligne->pd_pere ;
160
	                $this->_id_pere = $ligne->pd_pere ;
159
	            }
161
	            }
160
    		}
162
    		}
161
        }
163
        }
162
        
164
        
163
    } // end of member function document
165
    } // end of member function document
164
 
166
 
165
    /**
167
    /**
166
     * 
168
     * 
167
     *
169
     *
168
     * @param int id_document L'identifiant du document dans la base.
170
     * @param int id_document L'identifiant du document dans la base.
169
     * @param int objetDB Un objet PEAR:DB
171
     * @param int objetDB Un objet PEAR:DB
170
     * @return document
172
     * @return document
171
     * @access public
173
     * @access public
172
     */
174
     */
173
    function __construct( $id_document = "",  &$objetDB, $chemin = '', $chemin_icones = '' )
175
    function __construct( $id_document = "",  &$objetDB, $chemin = '', $chemin_icones = '' )
174
    {
176
    {
175
       
177
       
176
       $this->document($id_document, $objetDB, $chemin, $chemin_icones);
178
       $this->document($id_document, $objetDB, $chemin, $chemin_icones);
177
        
179
        
178
    } // end of member function __construct
180
    } // end of member function __construct
179
 
181
 
180
 
182
 
181
    /**
183
    /**
182
     * Renvoie le nom long du fichier.
184
     * Renvoie le nom long du fichier.
183
     *
185
     *
184
     * @return string
186
     * @return string
185
     * @access public
187
     * @access public
186
     */
188
     */
187
    function getNomLong( )
189
    function getNomLong( )
188
    {
190
    {
189
        return $this->_nom_long ;
191
        return $this->_nom_long ;
190
    } // end of member function getNomLong
192
    } // end of member function getNomLong
191
 
193
 
192
    /**
194
    /**
193
     * Renvoie la visibilité du document, soit "public" soit "prive"
195
     * Renvoie la visibilité du document, soit "public" soit "prive"
194
     *
196
     *
195
     * @return visibilite
197
     * @return visibilite
196
     * @access public
198
     * @access public
197
     */
199
     */
198
    function getVisibilite( )
200
    function getVisibilite( )
199
    {
201
    {
200
        return $this->_visibilite ;
202
        return $this->_visibilite ;
201
    } // end of member function getVisibilite
203
    } // end of member function getVisibilite
202
 
204
 
203
    /**
205
    /**
204
     * Renvoie la description du document, sous forme de chaine.
206
     * Renvoie la description du document, sous forme de chaine.
205
     *
207
     *
206
     * @return string
208
     * @return string
207
     * @access public
209
     * @access public
208
     */
210
     */
209
    function getDescription( )
211
    function getDescription( )
210
    {
212
    {
211
        return $this->_description ;
213
        return $this->_description ;
212
    } // end of member function getDescription
214
    } // end of member function getDescription
213
 
215
 
214
    /**
216
    /**
215
     * 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.
216
     *
218
     *
217
     * @return date
219
     * @return date
218
     * @access public
220
     * @access public
219
     */
221
     */
220
    function getDateMiseAJour( )
222
    function getDateMiseAJour( )
221
    {
223
    {
222
        return $this->_date_mise_a_jour ;
224
        return $this->_date_mise_a_jour ;
223
    } // end of member function getDateMiseAJour
225
    } // end of member function getDateMiseAJour
224
 
226
 
225
    /**
227
    /**
226
     * Renvoie l'identifiant d'un document.
228
     * Renvoie l'identifiant d'un document.
227
     *
229
     *
228
     * @return int
230
     * @return int
229
     * @access public
231
     * @access public
230
     */
232
     */
231
    function getIdDocument( )
233
    function getIdDocument( )
232
    {
234
    {
233
        return $this->_id ;
235
        return $this->_id ;
234
    } // end of member function getIdDocument
236
    } // end of member function getIdDocument
235
 
237
 
236
    /**
238
    /**
237
     * 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.
238
     *
240
     *
239
     * @return string
241
     * @return string
240
     * @access public
242
     * @access public
241
     */
243
     */
242
    function getCheminIcone()
244
    function getCheminIcone()
243
    {
245
    {
244
        if ($this->isRepertoire()) {
246
        if ($this->isRepertoire()) {
245
            return $this->_chemin_icone."repertoire.gif" ;
247
            return $this->_chemin_icone."repertoire.gif" ;
246
        } else {
248
        } else {
247
            if (is_object ($this->_type_mime)) return $this->_type_mime->getCheminIcone() ;
249
            if (is_object ($this->_type_mime)) return $this->_type_mime->getCheminIcone() ;
248
        }
250
        }
249
    } // end of member function getCheminIcone
251
    } // end of member function getCheminIcone
250
 
252
 
251
    /**
253
    /**
252
     * 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.
253
     *
255
     *
254
     * @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.
255
     * @param DB objetDB Un objet PEAR:DB
257
     * @param DB objetDB Un objet PEAR:DB
256
     * @return string
258
     * @return string
257
     * @static
259
     * @static
258
     * @access public
260
     * @access public
259
     */
261
     */
260
    function getNomRepertoireProjet( $id_projet , &$objetDB)
262
    function getNomRepertoireProjet( $id_projet , &$objetDB)
261
    {
263
    {
262
        // 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
263
        $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" ;
264
        $resultat = $objetDB->query ($requete) ;
266
        $resultat = $objetDB->query ($requete) ;
265
        if (DB::isError($resultat)) {
267
        if (DB::isError($resultat)) {
266
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
268
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
267
        }
269
        }
268
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
270
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
269
        return $ligne->pd_nom ;
271
        return $ligne->pd_nom ;
270
    } // end of member function getNomRepertoireProjet
272
    } // end of member function getNomRepertoireProjet
271
 
273
 
272
 
274
 
273
    /**
275
    /**
274
     * 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.
275
     *
277
     *
276
     * @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.
277
     * @return bool
279
     * @return bool
278
     * @access public
280
     * @access public
279
     */
281
     */
280
    function _isRacine( $id_document )
282
    function _isRacine( $id_document )
281
    {
283
    {
282
    	if ($id_document) {
284
    	if ($id_document) {
283
	        $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 ;
284
	        $resultat = $this->_db->query ($requete) ;
286
	        $resultat = $GLOBALS['projet_db']->query ($requete) ;
285
	        if (DB::isError($resultat)) {
287
	        if (DB::isError($resultat)) {
286
	            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
288
	            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
287
	        }
289
	        }
288
	        $ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT) ;
290
	        $ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT) ;
289
	        if ($resultat->numRows() >0) {
291
	        if ($resultat->numRows() >0) {
290
	        	if ($ligne->pd_pere == null){
292
	        	if ($ligne->pd_pere == null){
291
	            	return true ;
293
	            	return true ;
292
	        	}
294
	        	}
293
	        }
295
	        }
294
    	}
296
    	}
295
        return false ;
297
        return false ;
296
    } // end of member function _isRacine
298
    } // end of member function _isRacine
297
 
299
 
298
    /**
300
    /**
299
     * 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
300
     * 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.
301
     *
303
     *
302
     * @return string
304
     * @return string
303
     * @access public
305
     * @access public
304
     */
306
     */
305
    function getChemin($prefixe = '')
307
    function getChemin($prefixe = '')
306
    {
308
    {
307
        $chemin_repertoire_entre_racine_et_fichier = '';
309
        $chemin_repertoire_entre_racine_et_fichier = '';
308
 
310
 
309
        include_once PROJET_CHEMIN_CLASSES.'projet.class.php';
311
        include_once PROJET_CHEMIN_CLASSES.'projet.class.php';
310
        $projet = new projet ($this->_db, $this->_id_projet);
312
        $projet = new projet ($GLOBALS['projet_db'], $this->_id_projet);
311
        // l arborescence des repertoires
313
        // l arborescence des repertoires
312
        
314
        
313
        $tableau_navigation = $this->getPath($this->_id) ;
315
        $tableau_navigation = $this->getPath($this->_id) ;
314
        if (is_array ($tableau_navigation))$tableau_navigation = array_reverse($tableau_navigation);
316
        if (is_array ($tableau_navigation))$tableau_navigation = array_reverse($tableau_navigation);
315
        for ($i = 0; $i < count ($tableau_navigation); $i++) {
317
        for ($i = 0; $i < count ($tableau_navigation); $i++) {
316
        	$chemin_repertoire_entre_racine_et_fichier.= $tableau_navigation[$i]."/";	
318
        	$chemin_repertoire_entre_racine_et_fichier.= $tableau_navigation[$i]."/";	
317
        }
319
        }
318
        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 ;
319
    } 
321
    } 
320
 
322
 
321
 
323
 
322
    /**
324
    /**
323
     * 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
324
     * 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.
325
     * 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
326
     * vaut "".
328
     * vaut "".
327
     *
329
     *
328
     * @param int id_repertoire L'identifiant d'un répertoire.
330
     * @param int id_repertoire L'identifiant d'un répertoire.
329
     * @return Array
331
     * @return Array
330
     * @access public
332
     * @access public
331
     */
333
     */
332
     
334
     
333
    function getCheminIdRepertoire( $id_doc, &$objetDB )
335
    function getCheminIdRepertoire( $id_doc, &$objetDB )
334
    {
336
    {
335
        if ($id_doc == "") $id_doc = 0;
337
        if ($id_doc == "") $id_doc = 0;
336
        // 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
337
        $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 ;
338
        $resultat = $objetDB->query ($requete) ;
340
        $resultat = $objetDB->query ($requete) ;
339
        if (DB::isError($resultat)) {
341
        if (DB::isError($resultat)) {
340
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
342
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
341
        }
343
        }
342
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
344
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
343
        $chemin_rep_id_nom = array() ;
345
        $chemin_rep_id_nom = array() ;
344
        if ($resultat->numRows()>0) {
346
        if ($resultat->numRows()>0) {
345
    	    if ($ligne->pd_pere == 0) {
347
    	    if ($ligne->pd_pere == 0) {
346
        	    return ; //array ($ligne->pd_pere);
348
        	    return ; //array ($ligne->pd_pere);
347
        	}
349
        	}
348
            array_push ($chemin_rep_id_nom, $ligne->pd_pere) ;
350
            array_push ($chemin_rep_id_nom, $ligne->pd_pere) ;
349
            $tab = document::getCheminIdRepertoire($ligne->pd_pere, $objetDB) ;
351
            $tab = document::getCheminIdRepertoire($ligne->pd_pere, $objetDB) ;
350
            $chemin_rep_id_nom = array_merge ($tab, $chemin_rep_id_nom) ;
352
            $chemin_rep_id_nom = array_merge ($tab, $chemin_rep_id_nom) ;
351
        }
353
        }
352
        return array_reverse($chemin_rep_id_nom);
354
        return array_reverse($chemin_rep_id_nom);
353
    }
355
    }
354
	function getPath( $id_doc)
356
	function getPath( $id_doc)
355
    {
357
    {
356
        if ($id_doc == "") $id_doc = 0;
358
        if ($id_doc == "") $id_doc = 0;
357
        // on commence par rechercher le répertoire père, dans la base de donnée
359
        // on commence par rechercher le répertoire père, dans la base de donnée
358
        $requete = 'select pd_pere, pd_nom, pd_id, pd_ce_type from projet_documents where pd_id='.$id_doc ;
360
        $requete = 'select pd_pere, pd_nom, pd_id, pd_ce_type from projet_documents where pd_id='.$id_doc ;
359
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
361
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
360
        if (DB::isError($resultat)) {
362
        if (DB::isError($resultat)) {
361
            return ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
363
            return ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
362
        }
364
        }
363
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
365
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
364
        $chemin_rep_id_nom = array() ;
366
        $chemin_rep_id_nom = array() ;
365
        if ($resultat->numRows()>0) {
367
        if ($resultat->numRows()>0) {
366
    	    if ($ligne->pd_pere == 0) {
368
    	    if ($ligne->pd_pere == 0) {
367
        	    return;
369
        	    return array();
368
        	}
370
        	}
369
            array_push ($chemin_rep_id_nom, $ligne->pd_pere) ;
371
            array_push ($chemin_rep_id_nom, $ligne->pd_pere) ;
370
            $chemin_rep_id_nom = array_merge ($chemin_rep_id_nom, document::getPath($ligne->pd_pere) );
372
            $chemin_rep_id_nom = array_merge ($chemin_rep_id_nom, document::getPath($ligne->pd_pere) );
371
        }
373
        }
372
        return $chemin_rep_id_nom;
374
        return $chemin_rep_id_nom;
373
    }
375
    }
374
    /**
376
    /**
375
     *  Calcule le chemin vers le fichier ou le répertoire uploadé
377
     *  Calcule le chemin vers le fichier ou le répertoire uploadé
376
     *  renvoie un chaine de la forme dir1/dir2/fichier.ext
378
     *  renvoie un chaine de la forme dir1/dir2/fichier.ext
377
     *  En prenant comme racine le répertoire du projet, exclu.
379
     *  En prenant comme racine le répertoire du projet, exclu.
378
     * @return  string  Le chemin
380
     * @return  string  Le chemin
379
     */
381
     */
380
 
382
 
381
    function calculeCheminUploaded ($radical) {
383
    function calculeCheminUploaded ($radical) {
382
 
384
 
383
        if (isset($_FILES['fichier']['name'])) {
385
        if (isset($_FILES['fichier']['name'])) {
384
        	$extension = preg_replace("/^([^\.]+)\.(\w+$)/", "\\2", $_FILES['fichier']['name']) ;
386
        	$extension = preg_replace("/^([^\.]+)\.(\w+$)/", "\\2", $_FILES['fichier']['name']) ;
385
        } 
387
        } 
386
 
388
 
387
        if ($this->_id_pere != '') {
389
        if ($this->_id_pere != '') {
388
            // On appelle la méthode getCheminIdRepertoire qui renvoie un tableau avec la liste
390
            // On appelle la méthode getCheminIdRepertoire qui renvoie un tableau avec la liste
389
            // des répertoires jusqu'à la racine, on enlève la racine ($i = 0) et on concatène
391
            // des répertoires jusqu'à la racine, on enlève la racine ($i = 0) et on concatène
390
            // toutes les entrées pour obtenir le chemin jusqu'au répertoire courant
392
            // toutes les entrées pour obtenir le chemin jusqu'au répertoire courant
391
            $chemin_repertoire_entre_racine_et_repertoire_a_cree = '' ;
393
            $chemin_repertoire_entre_racine_et_repertoire_a_cree = '' ;
392
            $doc_pere = new document ($this->_id_pere, $this->_db);
394
            $doc_pere = new document ($this->_id_pere, $GLOBALS['projet_db']);
393
            return $doc_pere->getChemin();
395
            return $doc_pere->getChemin();
394
            $tableau_navigation = $this->getPath($this->_id_pere) ;
396
            $tableau_navigation = $this->getPath($this->_id_pere) ;
395
            
397
            
396
            for ($i = 0; $i < count ($tableau_navigation); $i++) $chemin_repertoire_entre_racine_et_repertoire_a_cree.= $tableau_navigation[$i]."/";
398
            for ($i = 0; $i < count ($tableau_navigation); $i++) $chemin_repertoire_entre_racine_et_repertoire_a_cree.= $tableau_navigation[$i]."/";
397
            $chemin = $chemin_repertoire_entre_racine_et_repertoire_a_cree ;
399
            $chemin = $chemin_repertoire_entre_racine_et_repertoire_a_cree ;
398
        } else {
400
        } else {
399
            // Si l'on est à la racine du projet, le chemin vide
401
            // Si l'on est à la racine du projet, le chemin vide
400
            return $radical ;
402
            return $radical ;
401
        }
403
        }
402
        return $chemin ;
404
        return $chemin ;
403
    }
405
    }
404
 
406
 
405
    /**
407
    /**
406
     * Enregistre une ligne dans la table projet_document
408
     * Enregistre une ligne dans la table projet_document
407
     * Le tableau de valeur doit contenir les éléments suivants 'document_nom','document_description','document_visibilite','fichier'
409
     * Le tableau de valeur doit contenir les éléments suivants 'document_nom','document_description','document_visibilite','fichier'
408
     *
410
     *
409
     * @param Array tableau_de_valeur Le tableau de valeur a insérer dans la base avec pour clé les noms des éléments
411
     * @param Array tableau_de_valeur Le tableau de valeur a insérer dans la base avec pour clé les noms des éléments
410
     * @access  public
412
     * @access  public
411
     * @return void
413
     * @return void
412
     */
414
     */
413
 
415
 
414
    function enregistrerSQL ($valeur, $chemin) {
416
    function enregistrerSQL ($valeur, $chemin) {
415
        
417
        
416
        // On teste si on a affaire à un répertoire ou un fichier
418
        // On teste si on a affaire à un répertoire ou un fichier
417
        if (isset ($_FILES['fichier']['name'])) {
419
        if (isset ($_FILES['fichier']['name'])) {
418
            // On tente de déterminer le type du fichier à partir de son nom dans $valeur['$fichier']
420
            // On tente de déterminer le type du fichier à partir de son nom dans $valeur['$fichier']
419
            $tableau_nom = explode (".", $_FILES['fichier']['name']) ;
421
            $tableau_nom = explode (".", $_FILES['fichier']['name']) ;
420
    
422
    
421
            // On prend le dernier élément du tableau, si c'est un tableau 
423
            // On prend le dernier élément du tableau, si c'est un tableau 
422
            if (is_array($tableau_nom)) {
424
            if (is_array($tableau_nom)) {
423
                $extension = array_pop($tableau_nom) ;
425
                $extension = array_pop($tableau_nom) ;
424
                $type = type_fichier_mime::factory($extension, $this->_db) ;
426
                $type = type_fichier_mime::factory($extension) ;
425
                $id_extension = $type->getIdType() ;
427
                $id_extension = $type->getIdType() ;
426
            } else {
428
            } else {
427
                $id_extension = 12 ;
429
                $id_extension = 12 ;
428
            }
430
            }
429
            $pd_lien = $chemin ;
431
            $pd_lien = $chemin ;
430
        } else {    // Le cas ou on a affaire à un répertoire
432
        } else {    // Le cas ou on a affaire à un répertoire
431
            $id_extension = 0 ;
433
            $id_extension = 0 ;
432
            // Le nom du répertoire est son identifiant avec un slash à la fin
434
            // Le nom du répertoire est son identifiant avec un slash à la fin
433
            $pd_lien = $chemin."/" ;
435
            $pd_lien = $chemin."/" ;
434
            if ($this->_id_pere != '') {
436
            if ($this->_id_pere != '') {
435
                // On appelle la méthode getCheminIdRepertoire qui renvoie un tableau avec la liste
437
                // On appelle la méthode getCheminIdRepertoire qui renvoie un tableau avec la liste
436
                // des répertoires jusqu'à la racine, on enlève la racine ($i = 0) et on concatène
438
                // des répertoires jusqu'à la racine, on enlève la racine ($i = 0) et on concatène
437
                // toutes les entrées pour obtenir le chemin jusqu'au répertoire courant
439
                // toutes les entrées pour obtenir le chemin jusqu'au répertoire courant
438
                $chemin_repertoire_entre_racine_et_repertoire_a_cree = '' ;
440
                $chemin_repertoire_entre_racine_et_repertoire_a_cree = '' ;
439
                $tableau_navigation = $this->getCheminIdRepertoire($this->_id_pere, $this->_db) ;
441
                $tableau_navigation = $this->getCheminIdRepertoire($this->_id_pere, $GLOBALS['projet_db']) ;
440
                for ($i = 0; $i < count ($tableau_navigation); $i+=2) $chemin_repertoire_entre_racine_et_repertoire_a_cree.= $tableau_navigation[$i]."/";
442
                for ($i = 0; $i < count ($tableau_navigation); $i+=2) $chemin_repertoire_entre_racine_et_repertoire_a_cree.= $tableau_navigation[$i]."/";
441
                $pd_lien .= $chemin_repertoire_entre_racine_et_repertoire_a_cree ;
443
                $pd_lien .= $chemin_repertoire_entre_racine_et_repertoire_a_cree ;
442
            }
444
            }
443
            //$pd_lien .= SQL_obtenirNouveauId($this->_db, 'projet_documents', 'pd_id')."/" ;
445
            //$pd_lien .= SQL_obtenirNouveauId($GLOBALS['projet_db'], 'projet_documents', 'pd_id')."/" ;
444
            $pd_lien = SQL_obtenirNouveauId($this->_db, 'projet_documents', 'pd_id')."/" ;
446
            $pd_lien = SQL_obtenirNouveauId($GLOBALS['projet_db'], 'projet_documents', 'pd_id')."/" ;
445
        }
447
        }
446
        $id = SQL_obtenirNouveauId($this->_db, 'projet_documents', 'pd_id') ;
448
        $id = SQL_obtenirNouveauId($GLOBALS['projet_db'], 'projet_documents', 'pd_id') ;
447
 
449
 
448
        $requete = "insert into projet_documents set pd_id=".$id ;
450
        $requete = "insert into projet_documents set pd_id=".$id ;
449
        $requete .= ", pd_nom=\"".$valeur['document_nom']."\", pd_description=\"".$valeur['document_description']."\"".
451
        $requete .= ", pd_nom=\"".$valeur['document_nom']."\", pd_description=\"".$valeur['document_description']."\"".
450
                    ", pd_visibilite=\"".$valeur['document_visibilite']."\", pd_date_de_mise_a_jour=NOW(),".
452
                    ", pd_visibilite=\"".$valeur['document_visibilite']."\", pd_date_de_mise_a_jour=NOW(),".
451
                    "pd_ce_projet=\"".$this->_id_projet."\", pd_ce_utilisateur=\"".$this->_id_proprietaire."\"".
453
                    "pd_ce_projet=\"".$this->_id_projet."\", pd_ce_utilisateur=\"".$this->_id_proprietaire."\"".
452
                    ", pd_pere=\"$this->_id_pere\", pd_ce_type=\"$id_extension\", pd_lien=\"$pd_lien\"" ;
454
                    ", pd_pere=\"$this->_id_pere\", pd_ce_type=\"$id_extension\", pd_lien=\"$pd_lien\"" ;
453
 
455
 
454
        $resultat = $this->_db->query ($requete) ;
456
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
455
        if (DB::isError($resultat)) {
457
        if (DB::isError($resultat)) {
456
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
458
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
457
        }
459
        }
458
        $this->_id = $id ;
460
        $this->_id = $id ;
459
        return $pd_lien;
461
        return $pd_lien;
460
    }
462
    }
461
 
463
 
462
	function genereNouveauNom ($radical, $ancien_nom, $id) {
464
	function genereNouveauNom ($radical, $ancien_nom, $id) {
463
		$extension = preg_replace("/^([^\.]+)\.(\w+$)/", "\\2", $ancien_nom) ;
465
		$extension = preg_replace("/^([^\.]+)\.(\w+$)/", "\\2", $ancien_nom) ;
464
        $nouveau_nom = $radical."_".$id.".".$extension ;
466
        $nouveau_nom = $radical."_".$id.".".$extension ;
465
        return $nouveau_nom;
467
        return $nouveau_nom;
466
	}
468
	}
467
 
469
 
468
    /**
470
    /**
469
     * Met à jour une ligne dans la table projet_document
471
     * Met à jour une ligne dans la table projet_document
470
     * Le tableau de valeur doit contenir les éléments suivants 'document_nom','document_description','document_visibilite','fichier'
472
     * Le tableau de valeur doit contenir les éléments suivants 'document_nom','document_description','document_visibilite','fichier'
471
     *
473
     *
472
     * @param Array tableau_de_valeur Le tableau de valeur a insérer dans la base avec pour clé les noms des éléments
474
     * @param Array tableau_de_valeur Le tableau de valeur a insérer dans la base avec pour clé les noms des éléments
473
     * @access  public
475
     * @access  public
474
     * @return void
476
     * @return void
475
     */
477
     */
476
 
478
 
477
    function majSQL ($valeur) {
479
    function majSQL ($valeur) {
478
        $requete = "update projet_documents set pd_nom=\"".$valeur['document_nom']."\", pd_description=\"".$valeur['document_description']."\"".
480
        $requete = "update projet_documents set pd_nom=\"".$valeur['document_nom']."\", pd_description=\"".$valeur['document_description']."\"".
479
                    ", pd_visibilite=\"".$valeur['document_visibilite']."\", pd_date_de_mise_a_jour=NOW()".
481
                    ", pd_visibilite=\"".$valeur['document_visibilite']."\", pd_date_de_mise_a_jour=NOW()".
480
                    " where pd_id=".$this->_id;
482
                    " where pd_id=".$this->_id;
481
 
483
 
482
        $resultat = $this->_db->query ($requete) ;
484
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
483
        if (DB::isError($resultat)) {
485
        if (DB::isError($resultat)) {
484
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
486
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
485
        }
487
        }
486
        return ;
488
        return ;
487
    }
489
    }
488
 
490
 
489
    /** Supprime les donnéexs du document dans la table projet_documents
491
    /** Supprime les donnéexs du document dans la table projet_documents
490
     *
492
     *
491
     *
493
     *
492
     * @return true en cas de succès
494
     * @return true en cas de succès
493
     */
495
     */
494
    
496
    
495
    function suppressionSQL () {
497
    function suppressionSQL () {
496
        $requete = 'delete from projet_documents where pd_id='.$this->_id ;
498
        $requete = 'delete from projet_documents where pd_id='.$this->_id ;
497
        $resultat = $this->_db->query ($requete) ;
499
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
498
        if ($this->_db->affectedRows()) return true ;
500
        if ($GLOBALS['projet_db']->affectedRows()) return true ;
499
        return false ;
501
        return false ;
500
    }
502
    }
501
    
503
    
502
    /**
504
    /**
503
     * Déplace un document au sein d'un même projet
505
     * Déplace un document au sein d'un même projet
504
     *
506
     *
505
     * @param int repertoire_destination L'identifiant du répertoire destination.
507
     * @param int repertoire_destination L'identifiant du répertoire destination.
506
     * @return bool
508
     * @return bool
507
     * @access public
509
     * @access public
508
     */
510
     */
509
    function deplace( $repertoire_destination, $repertoire_projet )
511
    function deplace( $repertoire_destination, $repertoire_projet )
510
    {
512
    {
511
 
513
 
512
        // On récupère les informations du répertoire cible
514
        // On récupère les informations du répertoire cible
513
        if ($repertoire_destination != 0) {
515
        if ($repertoire_destination != 0) {
514
            $repertoire_cible = new document ($repertoire_destination, $this->_db) ;
516
            $repertoire_cible = new document ($repertoire_destination, $GLOBALS['projet_db']) ;
515
            $chemin_rep_cible = $repertoire_cible->getChemin();
517
            $chemin_rep_cible = $repertoire_cible->getChemin();
516
        } else {
518
        } else {
517
        	// Si le repertoire destination est la racine cad id =0
519
        	// Si le repertoire destination est la racine cad id =0
518
        	// on cree un document qui aura pour chemin le repertoire du projet 
520
        	// on cree un document qui aura pour chemin le repertoire du projet 
519
        	include_once PROJET_CHEMIN_CLASSES.'projet.class.php';
521
        	include_once PROJET_CHEMIN_CLASSES.'projet.class.php';
520
            $projet = new projet ($this->_db, $this->_id_projet);
522
            $projet = new projet ($GLOBALS['projet_db'], $this->_id_projet);
521
        	$chemin_rep_cible = $projet->getNomRepertoire().'/';
523
        	$chemin_rep_cible = $projet->getNomRepertoire().'/';
522
        }
524
        }
523
   
525
   
524
        $nom_fichier = $this->_pd_lien ;
526
        $nom_fichier = $this->_pd_lien ;
525
        $requete = 'update projet_documents set pd_pere='.$repertoire_destination.' where pd_id='.$this->_id ;
527
        $requete = 'update projet_documents set pd_pere='.$repertoire_destination.' where pd_id='.$this->_id ;
526
        $resultat = $this->_db->query ($requete) ;
528
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
527
        if (DB::isError($resultat)) {
529
        if (DB::isError($resultat)) {
528
            echo ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
530
            echo ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
529
            return false ;
531
            return false ;
530
        }
532
        }
531
        //echo $this->_chemin.'<br>'.PROJET_CHEMIN_FICHIER.$chemin_rep_cible.$nom_fichier;
533
        //echo $this->_chemin.'<br>'.PROJET_CHEMIN_FICHIER.$chemin_rep_cible.$nom_fichier;
532
        return fichier::deplace ($this->_chemin, PROJET_CHEMIN_FICHIER.$chemin_rep_cible.$nom_fichier) ;
534
        return fichier::deplace ($this->_chemin, PROJET_CHEMIN_FICHIER.$chemin_rep_cible.$nom_fichier) ;
533
        
535
        
534
    } // end of member function deplace
536
    } // end of member function deplace
535
 
537
 
536
 
538
 
537
    /**
539
    /**
538
     * Pour modifier l'identifiant du projet auquel appartient un document.
540
     * Pour modifier l'identifiant du projet auquel appartient un document.
539
     *
541
     *
540
     * @param int id_projet L'identifiant du projet.
542
     * @param int id_projet L'identifiant du projet.
541
     * @return void
543
     * @return void
542
     * @access public
544
     * @access public
543
     */
545
     */
544
    function setIdProjet( $id_projet )
546
    function setIdProjet( $id_projet )
545
    {
547
    {
546
        $this->_id_projet = $id_projet ;
548
        $this->_id_projet = $id_projet ;
547
    } // end of member function setIdProjet
549
    } // end of member function setIdProjet
548
 
550
 
549
    /**
551
    /**
550
     * Permet de modifier l'identifiant du propietaire d'un projet.
552
     * Permet de modifier l'identifiant du propietaire d'un projet.
551
     *
553
     *
552
     * @param int id_proprietaire L'identifiant du proprietaire d'un document.
554
     * @param int id_proprietaire L'identifiant du proprietaire d'un document.
553
     * @return void
555
     * @return void
554
     * @access public
556
     * @access public
555
     */
557
     */
556
    function setIdProprietaire( $id_proprietaire )
558
    function setIdProprietaire( $id_proprietaire )
557
    {
559
    {
558
        $this->_id_proprietaire = $id_proprietaire ;
560
        $this->_id_proprietaire = $id_proprietaire ;
559
    } // end of member function setIdProprietaire
561
    } // end of member function setIdProprietaire
560
 
562
 
561
    /**
563
    /**
562
     * Permet de modifier l'identifiant du répertoire d'un document.
564
     * Permet de modifier l'identifiant du répertoire d'un document.
563
     *
565
     *
564
     * @param int id_repertoire L'identifiant du repertoire d'un document.
566
     * @param int id_repertoire L'identifiant du repertoire d'un document.
565
     * @return void
567
     * @return void
566
     * @access public
568
     * @access public
567
     */
569
     */
568
    function setIdRepertoire( $id_repertoire )
570
    function setIdRepertoire( $id_repertoire )
569
    {
571
    {
570
        $this->_id_pere = $id_repertoire;
572
        $this->_id_pere = $id_repertoire;
571
    } // end of member function setIdRepertoire
573
    } // end of member function setIdRepertoire
572
 
574
 
573
    /**
575
    /**
574
     * initAttributes sets all document attributes to its default                    value make
576
     * initAttributes sets all document attributes to its default                    value make
575
     * sure to call this method within your class constructor
577
     * sure to call this method within your class constructor
576
     */
578
     */
577
    function initAttributes( )
579
    function initAttributes( )
578
    {
580
    {
579
        $this->_visibilite = "public";
581
        $this->_visibilite = "public";
580
    }
582
    }
581
 
583
 
582
    /**
584
    /**
583
     * Renvoie les derniers documents de l'ensemble des projets.
585
     * Renvoie les derniers documents de l'ensemble des projets.
584
     *
586
     *
585
     * @param int nombre Le nombre de document à renvoyer
587
     * @param int nombre Le nombre de document à renvoyer
586
     * @return Array
588
     * @return Array
587
     * @static
589
     * @static
588
     * @access public
590
     * @access public
589
     */
591
     */
590
    function getDocumentsRecents( $nombre = 10, &$objetDB, $chemin, $chemin_icones, $id_projet = '', $visible = true)
592
    function getDocumentsRecents( $nombre = 10, &$objetDB, $chemin, $chemin_icones, $id_projet = '', $visible = true)
591
    {
593
    {
592
        // on recherche les documents, hors repertoire
594
        // on recherche les documents, hors repertoire
593
        $requete = 'select pd_id from projet_documents where pd_ce_type<>0 ';
595
        $requete = 'select pd_id from projet_documents where pd_ce_type<>0 ';
594
        if ($id_projet != '') $requete .= ' and pd_ce_projet='.$id_projet.' ';
596
        if ($id_projet != '') $requete .= ' and pd_ce_projet='.$id_projet.' ';
595
        if (!$visible) $requete .= ' and pd_visibilite="public" ';
597
        if (!$visible) $requete .= ' and pd_visibilite="public" ';
596
        $requete .= 'order by pd_date_de_mise_a_jour desc limit 0,'.$nombre ;
598
        $requete .= 'order by pd_date_de_mise_a_jour desc limit 0,'.$nombre ;
597
        $resultat = $objetDB->query ($requete) ;
599
        $resultat = $objetDB->query ($requete) ;
598
        if (DB::isError ($resultat)) {
600
        if (DB::isError ($resultat)) {
599
            die ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
601
            die ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
600
        }
602
        }
601
        $tableau_document = array() ;
603
        $tableau_document = array() ;
602
        
604
        
603
        while ($ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT)) {
605
        while ($ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT)) {
604
            array_push ($tableau_document, new document ($ligne->pd_id, $objetDB, $chemin, $chemin_icones)) ;
606
            array_push ($tableau_document, new document ($ligne->pd_id, $objetDB, $chemin, $chemin_icones)) ;
605
        }
607
        }
606
        return $tableau_document ;
608
        return $tableau_document ;
607
    } // end of member function getDocumentsRecents
609
    } // end of member function getDocumentsRecents
608
 
610
 
609
    /**
611
    /**
610
     * Renvoie les documents du projet passe en parametre sous forme d arbre d objet document
612
     * Renvoie les documents du projet passe en parametre sous forme d arbre d objet document
611
     *
613
     *
612
     * @param int l identifiant du projet
614
     * @param int l identifiant du projet
613
     * @return Array
615
     * @return Array
614
     * @static
616
     * @static
615
     * @access public
617
     * @access public
616
     */
618
     */
617
	function getArbreDocument($id_projet, $objetDB = '') {
619
	function getArbreDocument($id_projet, $objetDB = '') {
618
		$requete = 'select pd_id, pd_nom, pd_ce_type, pd_pere from projet_documents where pd_ce_projet='.$id_projet;
620
		$requete = 'select pd_id, pd_nom, pd_ce_type, pd_pere from projet_documents where pd_ce_projet='.$id_projet;
619
		$resultat = $GLOBALS['projet_db']->getAll($requete, null, DB_FETCHMODE_OBJECT);
621
		$resultat = $GLOBALS['projet_db']->getAll($requete, null, DB_FETCHMODE_OBJECT);
620
		if (DB::isError ($resultat)) {
622
		if (DB::isError ($resultat)) {
621
            return ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
623
            return ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
622
        }
624
        }
623
	
625
	
624
      	return $resultat;
626
      	return $resultat;
625
	}
627
	}
626
	 /**
628
	 /**
627
     * Renvoie la taille du document formatee avec une unite adapte
629
     * Renvoie la taille du document formatee avec une unite adapte
628
     *
630
     *
629
     * @return string La taille formate
631
     * @return string La taille formate
630
     * @access public
632
     * @access public
631
     */
633
     */
632
	function getTailleFormatee($precision = 1) {
634
	function getTailleFormatee($precision = 1) {
633
		$taille = $this->getTaille();
635
		$taille = $this->getTaille();
634
		if ($taille > 1000000) {
636
		if ($taille > 1000000) {
635
			$diviseur = 1000000;
637
			$diviseur = 1000000;
636
			$unite = 'Mo';
638
			$unite = 'Mo';
637
		} else {
639
		} else {
638
			$diviseur = 1000 ;
640
			$diviseur = 1000 ;
639
			$unite = 'Ko';
641
			$unite = 'Ko';
640
		}
642
		}
641
		return round ($taille / $diviseur, $precision).'&nbsp;'.$unite;
643
		return round ($taille / $diviseur, $precision).'&nbsp;'.$unite;
642
	}
644
	}
643
	
645
	
644
	/**
646
	/**
645
     * Renvoie une liste de document, enfant du document courant
647
     * Renvoie une liste de document, enfant du document courant
646
     * qui doit etre un repertoire bien sur
648
     * qui doit etre un repertoire bien sur
647
     *
649
     *
648
     * @return mixed un tableau de document
650
     * @return mixed un tableau de document
649
     * @access public
651
     * @access public
650
     */
652
     */
651
	function getDocumentsEnfant() {
653
	function getDocumentsEnfant() {
652
		
654
		
653
	}
655
	}
654
 
656
 
655
} // end of document
657
} // end of document
656
 
658
 
657
 
659
 
658
?>
660
?>