Subversion Repositories Applications.projet

Rev

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

Rev 389 Rev 397
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=".$GLOBALS['projet_db']->escapeSimple($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=".$GLOBALS['projet_db']->escapeSimple($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=".$GLOBALS['projet_db']->escapeSimple($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='.$GLOBALS['projet_db']->escapeSimple($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
 
357
	function getPath( $id_doc)
357
	function getPath( $id_doc)
358
    {
358
    {
359
        if ($id_doc == "") $id_doc = 0;
359
        if ($id_doc == "") $id_doc = 0;
360
        // 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
361
        $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='.$GLOBALS['projet_db']->escapeSimple($id_doc) ;
362
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
362
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
363
 
363
 
364
        if (DB::isError($resultat)) {
364
        if (DB::isError($resultat)) {
365
           return ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
365
           return ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
366
        }
366
        }
367
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
367
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
368
 
368
 
369
        $chemin_rep_id_nom = array() ;
369
        $chemin_rep_id_nom = array() ;
370
        if ($resultat->numRows()>0 && $ligne->pd_pere != 0 && $ligne->pd_pere != $ligne->pd_id) {
370
        if ($resultat->numRows()>0 && $ligne->pd_pere != 0 && $ligne->pd_pere != $ligne->pd_id) {
371
 
371
 
372
			array_push ($chemin_rep_id_nom, $ligne->pd_pere) ;
372
			array_push ($chemin_rep_id_nom, $ligne->pd_pere) ;
373
 
373
 
374
			// Récursion sur le répertoires ou fichiers fils
374
			// Récursion sur le répertoires ou fichiers fils
375
			$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) );
376
        }
376
        }
377
 
377
 
378
        return $chemin_rep_id_nom;
378
        return $chemin_rep_id_nom;
379
    }
379
    }
380
 
380
 
381
    /**
381
    /**
382
     *  Calcule le chemin vers le fichier ou le répertoire uploadé
382
     *  Calcule le chemin vers le fichier ou le répertoire uploadé
383
     *  renvoie un chaine de la forme dir1/dir2/fichier.ext
383
     *  renvoie un chaine de la forme dir1/dir2/fichier.ext
384
     *  En prenant comme racine le répertoire du projet, exclu.
384
     *  En prenant comme racine le répertoire du projet, exclu.
385
     * @return  string  Le chemin
385
     * @return  string  Le chemin
386
     */
386
     */
387
 
387
 
388
    function calculeCheminUploaded ($radical) {
388
    function calculeCheminUploaded ($radical) {
389
 
389
 
390
        if (isset($_FILES['fichier']['name'])) {
390
        if (isset($_FILES['fichier']['name'])) {
391
        	$extension = preg_replace("/^([^\.]+)\.(\w+$)/", "\\2", $_FILES['fichier']['name']) ;
391
        	$extension = preg_replace("/^([^\.]+)\.(\w+$)/", "\\2", $_FILES['fichier']['name']) ;
392
        }
392
        }
393
 
393
 
394
        if ($this->_id_pere != '') {
394
        if ($this->_id_pere != '') {
395
            // 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
396
            // 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
397
            // 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
398
            $chemin_repertoire_entre_racine_et_repertoire_a_cree = '' ;
398
            $chemin_repertoire_entre_racine_et_repertoire_a_cree = '' ;
399
            $doc_pere = new document ($this->_id_pere, $GLOBALS['projet_db']);
399
            $doc_pere = new document ($this->_id_pere, $GLOBALS['projet_db']);
400
            return $doc_pere->getChemin();
400
            return $doc_pere->getChemin();
401
            $tableau_navigation = $this->getPath($this->_id_pere) ;
401
            $tableau_navigation = $this->getPath($this->_id_pere) ;
402
 
402
 
403
            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]."/";
404
            $chemin = $chemin_repertoire_entre_racine_et_repertoire_a_cree ;
404
            $chemin = $chemin_repertoire_entre_racine_et_repertoire_a_cree ;
405
        } else {
405
        } else {
406
            // Si l'on est à la racine du projet, le chemin vide
406
            // Si l'on est à la racine du projet, le chemin vide
407
            return $radical ;
407
            return $radical ;
408
        }
408
        }
409
        return $chemin ;
409
        return $chemin ;
410
    }
410
    }
411
 
411
 
412
    /**
412
    /**
413
     * Enregistre une ligne dans la table projet_document
413
     * Enregistre une ligne dans la table projet_document
414
     * 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'
415
     *
415
     *
416
     * @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
417
     * @access  public
417
     * @access  public
418
     * @return void
418
     * @return void
419
     */
419
     */
420
 
420
 
421
    function enregistrerSQL ($valeur, $chemin) {
421
    function enregistrerSQL ($valeur, $chemin) {
422
 
422
 
423
        // 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
424
        if (isset ($_FILES['fichier']['name'])) {
424
        if (isset ($_FILES['fichier']['name'])) {
425
            // 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']
426
            $tableau_nom = explode (".", $_FILES['fichier']['name']) ;
426
            $tableau_nom = explode (".", $_FILES['fichier']['name']) ;
427
 
427
 
428
            // 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
429
            if (is_array($tableau_nom)) {
429
            if (is_array($tableau_nom)) {
430
                $extension = array_pop($tableau_nom) ;
430
                $extension = array_pop($tableau_nom) ;
431
                $type = type_fichier_mime::factory($extension) ;
431
                $type = type_fichier_mime::factory($extension) ;
432
                $id_extension = $type->getIdType() ;
432
                $id_extension = $type->getIdType() ;
433
            } else {
433
            } else {
434
                $id_extension = 12 ;
434
                $id_extension = 12 ;
435
            }
435
            }
436
            $pd_lien = $chemin ;
436
            $pd_lien = $chemin ;
437
        } else {    // Le cas ou on a affaire à un répertoire
437
        } else {    // Le cas ou on a affaire à un répertoire
438
            $id_extension = 0 ;
438
            $id_extension = 0 ;
439
            // 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
440
            $pd_lien = $chemin."/" ;
440
            $pd_lien = $chemin."/" ;
441
            if ($this->_id_pere != '') {
441
            if ($this->_id_pere != '') {
442
                // 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
443
                // 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
444
                // 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
445
                $chemin_repertoire_entre_racine_et_repertoire_a_cree = '' ;
445
                $chemin_repertoire_entre_racine_et_repertoire_a_cree = '' ;
446
                $tableau_navigation = $this->getCheminIdRepertoire($this->_id_pere, $GLOBALS['projet_db']) ;
446
                $tableau_navigation = $this->getCheminIdRepertoire($this->_id_pere, $GLOBALS['projet_db']) ;
447
                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]."/";
448
                $pd_lien .= $chemin_repertoire_entre_racine_et_repertoire_a_cree ;
448
                $pd_lien .= $chemin_repertoire_entre_racine_et_repertoire_a_cree ;
449
            }
449
            }
450
            //$pd_lien .= SQL_obtenirNouveauId($GLOBALS['projet_db'], 'projet_documents', 'pd_id')."/" ;
450
            //$pd_lien .= SQL_obtenirNouveauId($GLOBALS['projet_db'], 'projet_documents', 'pd_id')."/" ;
451
            $pd_lien = SQL_obtenirNouveauId($GLOBALS['projet_db'], 'projet_documents', 'pd_id')."/" ;
451
            $pd_lien = SQL_obtenirNouveauId($GLOBALS['projet_db'], 'projet_documents', 'pd_id')."/" ;
452
        }
452
        }
453
        $id = SQL_obtenirNouveauId($GLOBALS['projet_db'], 'projet_documents', 'pd_id') ;
453
        $id = SQL_obtenirNouveauId($GLOBALS['projet_db'], 'projet_documents', 'pd_id') ;
454
 
454
 
455
        $requete = "insert into projet_documents set pd_id=".$id ;
455
        $requete = "insert into projet_documents set pd_id=".$id ;
456
        $requete .= ", pd_nom=\"".$valeur['document_nom']."\", pd_description=\"".$valeur['document_description']."\"".
456
        $requete .= ", pd_nom=\"".$valeur['document_nom']."\", pd_description=\"".$valeur['document_description']."\"".
457
                    ", 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(),".
458
                    "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."\"".
459
                    ", 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\"" ;
460
 
460
 
461
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
461
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
462
        if (DB::isError($resultat)) {
462
        if (DB::isError($resultat)) {
463
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
463
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
464
        }
464
        }
465
        $this->_id = $id ;
465
        $this->_id = $id ;
466
        return $pd_lien;
466
        return $pd_lien;
467
    }
467
    }
468
 
468
 
469
	function genereNouveauNom ($radical, $ancien_nom, $id) {
469
	function genereNouveauNom ($radical, $ancien_nom, $id) {
470
		$extension = preg_replace("/^([^\.]+)\.(\w+$)/", "\\2", $ancien_nom) ;
470
		$extension = preg_replace("/^([^\.]+)\.(\w+$)/", "\\2", $ancien_nom) ;
471
        $nouveau_nom = $radical."_".$id.".".$extension ;
471
        $nouveau_nom = $radical."_".$id.".".$extension ;
472
        return $nouveau_nom;
472
        return $nouveau_nom;
473
	}
473
	}
474
 
474
 
475
    /**
475
    /**
476
     * Met à jour une ligne dans la table projet_document
476
     * Met à jour une ligne dans la table projet_document
477
     * 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'
478
     *
478
     *
479
     * @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
480
     * @access  public
480
     * @access  public
481
     * @return void
481
     * @return void
482
     */
482
     */
483
 
483
 
484
    function majSQL ($valeur) {
484
    function majSQL ($valeur) {
485
        $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']."\"".
486
                    ", 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()".
487
                    " where pd_id=".$this->_id;
487
                    " where pd_id=".$GLOBALS['projet_db']->escapeSimple($this->_id);
488
 
488
 
489
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
489
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
490
        if (DB::isError($resultat)) {
490
        if (DB::isError($resultat)) {
491
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
491
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
492
        }
492
        }
493
        return ;
493
        return ;
494
    }
494
    }
495
 
495
 
496
    /** Supprime les donnéexs du document dans la table projet_documents
496
    /** Supprime les donnéexs du document dans la table projet_documents
497
     *
497
     *
498
     *
498
     *
499
     * @return true en cas de succès
499
     * @return true en cas de succès
500
     */
500
     */
501
 
501
 
502
    function suppressionSQL () {
502
    function suppressionSQL () {
503
        $requete = 'delete from projet_documents where pd_id='.$this->_id ;
503
        $requete = 'delete from projet_documents where pd_id='.$GLOBALS['projet_db']->escapeSimple($this->_id) ;
504
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
504
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
505
        if ($GLOBALS['projet_db']->affectedRows()) return true ;
505
        if ($GLOBALS['projet_db']->affectedRows()) return true ;
506
        return false ;
506
        return false ;
507
    }
507
    }
508
 
508
 
509
    /**
509
    /**
510
     * Déplace un document au sein d'un même projet
510
     * Déplace un document au sein d'un même projet
511
     *
511
     *
512
     * @param int repertoire_destination L'identifiant du répertoire destination.
512
     * @param int repertoire_destination L'identifiant du répertoire destination.
513
     * @return bool
513
     * @return bool
514
     * @access public
514
     * @access public
515
     */
515
     */
516
    function deplace( $repertoire_destination, $repertoire_projet )
516
    function deplace( $repertoire_destination, $repertoire_projet )
517
    {
517
    {
518
 
518
 
519
        // On récupère les informations du répertoire cible
519
        // On récupère les informations du répertoire cible
520
        if ($repertoire_destination != 0) {
520
        if ($repertoire_destination != 0) {
521
            $repertoire_cible = new document ($repertoire_destination, $GLOBALS['projet_db']) ;
521
            $repertoire_cible = new document ($repertoire_destination, $GLOBALS['projet_db']) ;
522
            $chemin_rep_cible = $repertoire_cible->getChemin();
522
            $chemin_rep_cible = $repertoire_cible->getChemin();
523
        } else {
523
        } else {
524
        	// Si le repertoire destination est la racine cad id =0
524
        	// Si le repertoire destination est la racine cad id =0
525
        	// 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
526
        	include_once PROJET_CHEMIN_CLASSES.'projet.class.php';
526
        	include_once PROJET_CHEMIN_CLASSES.'projet.class.php';
527
            $projet = new projet ($GLOBALS['projet_db'], $this->_id_projet);
527
            $projet = new projet ($GLOBALS['projet_db'], $this->_id_projet);
528
        	$chemin_rep_cible = $projet->getNomRepertoire().'/';
528
        	$chemin_rep_cible = $projet->getNomRepertoire().'/';
529
        }
529
        }
530
 
530
 
531
        $nom_fichier = $this->_pd_lien ;
531
        $nom_fichier = $this->_pd_lien ;
532
        $requete = 'update projet_documents set pd_pere='.$repertoire_destination.' where pd_id='.$this->_id ;
532
        $requete = 'update projet_documents set pd_pere='.$GLOBALS['projet_db']->escapeSimple($repertoire_destination).' where pd_id='.$GLOBALS['projet_db']->escapeSimple($this->_id) ;
533
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
533
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
534
        if (DB::isError($resultat)) {
534
        if (DB::isError($resultat)) {
535
            echo ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
535
            echo ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
536
            return false ;
536
            return false ;
537
        }
537
        }
538
        //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;
539
        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) ;
540
 
540
 
541
    } // end of member function deplace
541
    } // end of member function deplace
542
 
542
 
543
 
543
 
544
    /**
544
    /**
545
     * Pour modifier l'identifiant du projet auquel appartient un document.
545
     * Pour modifier l'identifiant du projet auquel appartient un document.
546
     *
546
     *
547
     * @param int id_projet L'identifiant du projet.
547
     * @param int id_projet L'identifiant du projet.
548
     * @return void
548
     * @return void
549
     * @access public
549
     * @access public
550
     */
550
     */
551
    function setIdProjet( $id_projet )
551
    function setIdProjet( $id_projet )
552
    {
552
    {
553
        $this->_id_projet = $id_projet ;
553
        $this->_id_projet = $id_projet ;
554
    } // end of member function setIdProjet
554
    } // end of member function setIdProjet
555
 
555
 
556
    /**
556
    /**
557
     * Permet de modifier l'identifiant du propietaire d'un projet.
557
     * Permet de modifier l'identifiant du propietaire d'un projet.
558
     *
558
     *
559
     * @param int id_proprietaire L'identifiant du proprietaire d'un document.
559
     * @param int id_proprietaire L'identifiant du proprietaire d'un document.
560
     * @return void
560
     * @return void
561
     * @access public
561
     * @access public
562
     */
562
     */
563
    function setIdProprietaire( $id_proprietaire )
563
    function setIdProprietaire( $id_proprietaire )
564
    {
564
    {
565
        $this->_id_proprietaire = $id_proprietaire ;
565
        $this->_id_proprietaire = $id_proprietaire ;
566
    } // end of member function setIdProprietaire
566
    } // end of member function setIdProprietaire
567
 
567
 
568
    /**
568
    /**
569
     * Permet de modifier l'identifiant du répertoire d'un document.
569
     * Permet de modifier l'identifiant du répertoire d'un document.
570
     *
570
     *
571
     * @param int id_repertoire L'identifiant du repertoire d'un document.
571
     * @param int id_repertoire L'identifiant du repertoire d'un document.
572
     * @return void
572
     * @return void
573
     * @access public
573
     * @access public
574
     */
574
     */
575
    function setIdRepertoire( $id_repertoire )
575
    function setIdRepertoire( $id_repertoire )
576
    {
576
    {
577
        $this->_id_pere = $id_repertoire;
577
        $this->_id_pere = $id_repertoire;
578
    } // end of member function setIdRepertoire
578
    } // end of member function setIdRepertoire
579
 
579
 
580
    /**
580
    /**
581
     * initAttributes sets all document attributes to its default                    value make
581
     * initAttributes sets all document attributes to its default                    value make
582
     * sure to call this method within your class constructor
582
     * sure to call this method within your class constructor
583
     */
583
     */
584
    function initAttributes( )
584
    function initAttributes( )
585
    {
585
    {
586
        $this->_visibilite = "public";
586
        $this->_visibilite = "public";
587
    }
587
    }
588
 
588
 
589
    /**
589
    /**
590
     * Renvoie les derniers documents de l'ensemble des projets.
590
     * Renvoie les derniers documents de l'ensemble des projets.
591
     *
591
     *
592
     * @param int nombre Le nombre de document à renvoyer
592
     * @param int nombre Le nombre de document à renvoyer
593
     * @return Array
593
     * @return Array
594
     * @static
594
     * @static
595
     * @access public
595
     * @access public
596
     */
596
     */
597
    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)
598
    {
598
    {
599
        // on recherche les documents, hors repertoire
599
        // on recherche les documents, hors repertoire
600
        $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 ';
601
        if ($id_projet != '') $requete .= ' and pd_ce_projet='.$id_projet.' ';
601
        if ($id_projet != '') $requete .= ' and pd_ce_projet='.$GLOBALS['projet_db']->escapeSimple($id_projet).' ';
602
        if (!$visible) $requete .= ' and pd_visibilite="public" ';
602
        if (!$visible) $requete .= ' and pd_visibilite="public" ';
603
        $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 ;
604
        $resultat = $objetDB->query ($requete) ;
604
        $resultat = $objetDB->query ($requete) ;
605
        if (DB::isError ($resultat)) {
605
        if (DB::isError ($resultat)) {
606
            die ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
606
            die ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
607
        }
607
        }
608
        $tableau_document = array() ;
608
        $tableau_document = array() ;
609
 
609
 
610
        while ($ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT)) {
610
        while ($ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT)) {
611
            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)) ;
612
        }
612
        }
613
        return $tableau_document ;
613
        return $tableau_document ;
614
    } // end of member function getDocumentsRecents
614
    } // end of member function getDocumentsRecents
615
 
615
 
616
    /**
616
    /**
617
     * 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
618
     *
618
     *
619
     * @param int l identifiant du projet
619
     * @param int l identifiant du projet
620
     * @return Array
620
     * @return Array
621
     * @static
621
     * @static
622
     * @access public
622
     * @access public
623
     */
623
     */
624
	function getArbreDocument($id_projet, $objetDB = '') {
624
	function getArbreDocument($id_projet, $objetDB = '') {
625
		$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='.$GLOBALS['projet_db']->escapeSimple($id_projet);
626
		$resultat = $GLOBALS['projet_db']->getAll($requete, null, DB_FETCHMODE_OBJECT);
626
		$resultat = $GLOBALS['projet_db']->getAll($requete, null, DB_FETCHMODE_OBJECT);
627
		if (DB::isError ($resultat)) {
627
		if (DB::isError ($resultat)) {
628
            return ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
628
            return ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
629
        }
629
        }
630
 
630
 
631
      	return $resultat;
631
      	return $resultat;
632
	}
632
	}
633
	 /**
633
	 /**
634
     * Renvoie la taille du document formatee avec une unite adapte
634
     * Renvoie la taille du document formatee avec une unite adapte
635
     *
635
     *
636
     * @return string La taille formate
636
     * @return string La taille formate
637
     * @access public
637
     * @access public
638
     */
638
     */
639
	function getTailleFormatee($precision = 1) {
639
	function getTailleFormatee($precision = 1) {
640
		$taille = $this->getTaille();
640
		$taille = $this->getTaille();
641
		if ($taille > 1000000) {
641
		if ($taille > 1000000) {
642
			$diviseur = 1000000;
642
			$diviseur = 1000000;
643
			$unite = 'Mo';
643
			$unite = 'Mo';
644
		} else {
644
		} else {
645
			$diviseur = 1000 ;
645
			$diviseur = 1000 ;
646
			$unite = 'Ko';
646
			$unite = 'Ko';
647
		}
647
		}
648
		return round ($taille / $diviseur, $precision).'&nbsp;'.$unite;
648
		return round ($taille / $diviseur, $precision).'&nbsp;'.$unite;
649
	}
649
	}
650
 
650
 
651
	/**
651
	/**
652
     * Renvoie une liste de document, enfant du document courant
652
     * Renvoie une liste de document, enfant du document courant
653
     * qui doit etre un repertoire bien sur
653
     * qui doit etre un repertoire bien sur
654
     *
654
     *
655
     * @return mixed un tableau de document
655
     * @return mixed un tableau de document
656
     * @access public
656
     * @access public
657
     */
657
     */
658
	function getDocumentsEnfant() {
658
	function getDocumentsEnfant() {
659
 
659
 
660
	}
660
	}
661
 
661
 
662
} // end of document
662
} // end of document
663
 
663
 
664
 
664
 
665
?>
665
?>