Subversion Repositories Applications.projet

Rev

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

Rev 2 Rev 6
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.1 2005-09-22 14:02:48 ddelon Exp $
22
// CVS : $Id: document.class.php,v 1.2 2005-09-26 20:18:27 ddelon 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.1 $
34
*@version       $Revision: 1.2 $
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
     * 
120
     * 
121
     *
121
     *
122
     * @param int id_document L'identifiant du document dans la base.
122
     * @param int id_document L'identifiant du document dans la base.
123
     * @param int objetDB un objet PEAR:DB
123
     * @param int objetDB un objet PEAR:DB
124
     * @return void
124
     * @return void
125
     * @access public
125
     * @access public
126
     */
126
     */
127
    function document( $id_document = "",  &$objetDB, $chemin = '', $chemin_icones = '')
127
    function document( $id_document = "",  &$objetDB, $chemin = '', $chemin_icones = '')
128
    {
128
    {
129
        $this->_db = $objetDB ;
129
        $this->_db = $objetDB ;
130
        $this->_chemin_icone = $chemin_icones ;
130
        $this->_chemin_icone = $chemin_icones ;
131
        if ($id_document != "") {
131
        if ($id_document != "") {
132
            $requete = "select * from projet_documents where pd_id=".$id_document ;
132
            $requete = "select * from projet_documents where pd_id=".$id_document ;
133
            $resultat = $this->_db->query ($requete) ;
133
            $resultat = $this->_db->query ($requete) ;
134
            if (DB::isError($resultat)) {
134
            if (DB::isError($resultat)) {
135
                die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
135
                die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
136
            }
136
            }
137
            $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
137
            $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
138
    
-
 
-
 
138
    		if ($resultat->numRows()>0) {
139
            fichier::fichier($chemin.$ligne->pd_lien, $this->_db) ;
139
	            fichier::fichier($chemin.$ligne->pd_lien, $this->_db) ;
140
            $this->_id = $ligne->pd_id ;
140
	            $this->_id = $ligne->pd_id ;
141
            if (is_object ($this->_type_mime)) $this->_type_mime->setCheminIcone ($chemin_icones) ;
141
	            if (is_object ($this->_type_mime)) $this->_type_mime->setCheminIcone ($chemin_icones) ;
142
            $this->_id_proprietaire = $ligne->pd_ce_utilisateur ;
142
	            $this->_id_proprietaire = $ligne->pd_ce_utilisateur ;
143
            $this->_nom_long = $ligne->pd_nom ;
143
	            $this->_nom_long = $ligne->pd_nom ;
144
            $this->_visibilite = $ligne->pd_visibilite ;
144
	            $this->_visibilite = $ligne->pd_visibilite ;
145
            $this->_date_mise_a_jour = $ligne->pd_date_de_mise_a_jour ;
145
	            $this->_date_mise_a_jour = $ligne->pd_date_de_mise_a_jour ;
146
            $this->_description = $ligne->pd_description ;
146
	            $this->_description = $ligne->pd_description ;
147
            $this->_pd_lien = $ligne->pd_lien;
147
	            $this->_pd_lien = $ligne->pd_lien;
148
            if ($this->_isRacine($ligne->pd_pere)) {
148
	            if ($this->_isRacine($ligne->pd_pere)) {
149
                $this->_id_pere = 0 ;
149
	                $this->_id_pere = 0 ;
150
            } else {
150
	            } else {
151
                $this->_id_pere = $ligne->pd_pere ;
151
	                $this->_id_pere = $ligne->pd_pere ;
152
            }
152
	            }
-
 
153
    		}
153
        }
154
        }
154
        
155
        
155
    } // end of member function document
156
    } // end of member function document
156
 
157
 
157
    /**
158
    /**
158
     * 
159
     * 
159
     *
160
     *
160
     * @param int id_document L'identifiant du document dans la base.
161
     * @param int id_document L'identifiant du document dans la base.
161
     * @param int objetDB Un objet PEAR:DB
162
     * @param int objetDB Un objet PEAR:DB
162
     * @return document
163
     * @return document
163
     * @access public
164
     * @access public
164
     */
165
     */
165
    function __construct( $id_document,  &$objetDB )
166
    function __construct( $id_document = "",  &$objetDB, $chemin = '', $chemin_icones = '' )
166
    {
167
    {
-
 
168
       
-
 
169
       $this->document($id_document, $objetDB, $chemin, $chemin_icones);
167
        
170
        
168
    } // end of member function __construct
171
    } // end of member function __construct
169
 
172
 
170
 
173
 
171
    /**
174
    /**
172
     * Renvoie le nom long du fichier.
175
     * Renvoie le nom long du fichier.
173
     *
176
     *
174
     * @return string
177
     * @return string
175
     * @access public
178
     * @access public
176
     */
179
     */
177
    function getNomLong( )
180
    function getNomLong( )
178
    {
181
    {
179
        return $this->_nom_long ;
182
        return $this->_nom_long ;
180
    } // end of member function getNomLong
183
    } // end of member function getNomLong
181
 
184
 
182
    /**
185
    /**
183
     * Renvoie la visibilité du document, soit "public" soit "prive"
186
     * Renvoie la visibilité du document, soit "public" soit "prive"
184
     *
187
     *
185
     * @return visibilite
188
     * @return visibilite
186
     * @access public
189
     * @access public
187
     */
190
     */
188
    function getVisibilite( )
191
    function getVisibilite( )
189
    {
192
    {
190
        return $this->_visibilite ;
193
        return $this->_visibilite ;
191
    } // end of member function getVisibilite
194
    } // end of member function getVisibilite
192
 
195
 
193
    /**
196
    /**
194
     * Renvoie la description du document, sous forme de chaine.
197
     * Renvoie la description du document, sous forme de chaine.
195
     *
198
     *
196
     * @return string
199
     * @return string
197
     * @access public
200
     * @access public
198
     */
201
     */
199
    function getDescription( )
202
    function getDescription( )
200
    {
203
    {
201
        return $this->_description ;
204
        return $this->_description ;
202
    } // end of member function getDescription
205
    } // end of member function getDescription
203
 
206
 
204
    /**
207
    /**
205
     * Renvoie la date de création ou de mise à jour du fichier.
208
     * Renvoie la date de création ou de mise à jour du fichier.
206
     *
209
     *
207
     * @return date
210
     * @return date
208
     * @access public
211
     * @access public
209
     */
212
     */
210
    function getDateMiseAJour( )
213
    function getDateMiseAJour( )
211
    {
214
    {
212
        return $this->_date_mise_a_jour ;
215
        return $this->_date_mise_a_jour ;
213
    } // end of member function getDateMiseAJour
216
    } // end of member function getDateMiseAJour
214
 
217
 
215
    /**
218
    /**
216
     * Renvoie l'identifiant d'un document.
219
     * Renvoie l'identifiant d'un document.
217
     *
220
     *
218
     * @return int
221
     * @return int
219
     * @access public
222
     * @access public
220
     */
223
     */
221
    function getIdDocument( )
224
    function getIdDocument( )
222
    {
225
    {
223
        return $this->_id ;
226
        return $this->_id ;
224
    } // end of member function getIdDocument
227
    } // end of member function getIdDocument
225
 
228
 
226
    /**
229
    /**
227
     * Renvoie le chemin de l'icone du fichier. Fait un appel à type_fichier_mime.
230
     * Renvoie le chemin de l'icone du fichier. Fait un appel à type_fichier_mime.
228
     *
231
     *
229
     * @return string
232
     * @return string
230
     * @access public
233
     * @access public
231
     */
234
     */
232
    function getCheminIcone()
235
    function getCheminIcone()
233
    {
236
    {
234
        if ($this->isRepertoire()) {
237
        if ($this->isRepertoire()) {
235
            return $this->_chemin_icone."repertoire.gif" ;
238
            return $this->_chemin_icone."repertoire.gif" ;
236
        } else {
239
        } else {
237
            return $this->_type_mime->getCheminIcone() ;
240
            return $this->_type_mime->getCheminIcone() ;
238
        }
241
        }
239
    } // end of member function getCheminIcone
242
    } // end of member function getCheminIcone
240
 
243
 
241
    /**
244
    /**
242
     * Permet de récupérer le nom du répertoire racine associé à un projet.
245
     * Permet de récupérer le nom du répertoire racine associé à un projet.
243
     *
246
     *
244
     * @param int id_projet L'identifiant du projet dont on veux récupérer le répertoire racine.
247
     * @param int id_projet L'identifiant du projet dont on veux récupérer le répertoire racine.
245
     * @param DB objetDB Un objet PEAR:DB
248
     * @param DB objetDB Un objet PEAR:DB
246
     * @return string
249
     * @return string
247
     * @static
250
     * @static
248
     * @access public
251
     * @access public
249
     */
252
     */
250
    function getNomRepertoireProjet( $id_projet , &$objetDB)
253
    function getNomRepertoireProjet( $id_projet , &$objetDB)
251
    {
254
    {
252
        // Dans la table projet_documents, pour les répertoires racines, pd_pere = null
255
        // Dans la table projet_documents, pour les répertoires racines, pd_pere = null
253
        $requete = "select pd_nom from projet_documents where pd_ce_projet=$id_projet and pd_pere is null" ;
256
        $requete = "select pd_nom from projet_documents where pd_ce_projet=$id_projet and pd_pere is null" ;
254
        $resultat = $objetDB->query ($requete) ;
257
        $resultat = $objetDB->query ($requete) ;
255
        if (DB::isError($resultat)) {
258
        if (DB::isError($resultat)) {
256
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
259
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
257
        }
260
        }
258
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
261
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
259
        return $ligne->pd_nom ;
262
        return $ligne->pd_nom ;
260
    } // end of member function getNomRepertoireProjet
263
    } // end of member function getNomRepertoireProjet
261
 
264
 
262
 
265
 
263
    /**
266
    /**
264
     * Renvoie true si le document passé en paramètre est le répertoire racine.
267
     * Renvoie true si le document passé en paramètre est le répertoire racine.
265
     *
268
     *
266
     * @param int id_document L'identifiant du document dont on veut savoir si c'est la racine.
269
     * @param int id_document L'identifiant du document dont on veut savoir si c'est la racine.
267
     * @return bool
270
     * @return bool
268
     * @access public
271
     * @access public
269
     */
272
     */
270
    function _isRacine( $id_document )
273
    function _isRacine( $id_document )
271
    {
274
    {
-
 
275
    	if ($id_document) {
272
        $requete = "select pd_pere from projet_documents where pd_id=$id_document" ;
276
	        $requete = "select pd_pere from projet_documents where pd_id=".$id_document ;
273
        $resultat = $this->_db->query ($requete) ;
277
	        $resultat = $this->_db->query ($requete) ;
274
        if (DB::isError($resultat)) {
278
	        if (DB::isError($resultat)) {
275
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
279
	            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
276
        }
280
	        }
277
        $ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT) ;
281
	        $ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT) ;
-
 
282
	        if ($resultat->numRows() >0) {
278
        if ($ligne->pd_pere == null){
283
	        	if ($ligne->pd_pere == null){
279
            return true ;
284
	            	return true ;
-
 
285
	        	}
280
        }
286
	        }
-
 
287
    	}
281
        return false ;
288
        return false ;
282
    } // end of member function _isRacine
289
    } // end of member function _isRacine
283
 
290
 
284
    /**
291
    /**
285
     * Renvoie le chemin d'un fichier ou d'un répertoire. Contrairement à la classe
292
     * Renvoie le chemin d'un fichier ou d'un répertoire. Contrairement à la classe
286
     * mère, cette méthode renvoie une URL projet et non pas un fichier.
293
     * mère, cette méthode renvoie une URL projet et non pas un fichier.
287
     *
294
     *
288
     * @return string
295
     * @return string
289
     * @access public
296
     * @access public
290
     */
297
     */
291
    function getChemin( )
298
    function getChemin( )
292
    {
299
    {
293
        if ($this->isRepertoire()) {
300
        if ($this->isRepertoire()) {
294
            return $this->_id ;
301
            return $this->_id ;
295
        } else {
302
        } else {
296
            return $this->_chemin ;
303
            return $this->_chemin ;
297
        }
304
        }
298
    } // end of member function getChemin
305
    } // end of member function getChemin
299
 
306
 
300
 
307
 
301
    /**
308
    /**
302
     * Renvoie pour le répertoire courant, les identifiants et les noms de tous les
309
     * Renvoie pour le répertoire courant, les identifiants et les noms de tous les
303
     * répertoires père jusqu'à la racine. 0 => ['id'], ['nom'] 1 => [id'], ['nom'] etc.
310
     * répertoires père jusqu'à la racine. 0 => ['id'], ['nom'] 1 => [id'], ['nom'] etc.
304
     * En commençant par la racine et en descendant.  Pour la racine id vaut "" et nom
311
     * En commençant par la racine et en descendant.  Pour la racine id vaut "" et nom
305
     * vaut "".
312
     * vaut "".
306
     *
313
     *
307
     * @param int id_repertoire L'identifiant d'un répertoire.
314
     * @param int id_repertoire L'identifiant d'un répertoire.
308
     * @return Array
315
     * @return Array
309
     * @access public
316
     * @access public
310
     */
317
     */
311
    function getCheminIdRepertoire( $id_repertoire, &$objetDB )
318
    function getCheminIdRepertoire( $id_repertoire, &$objetDB )
312
    {
319
    {
313
        if ($id_repertoire == "") $id_repertoire = 0;
320
        if ($id_repertoire == "") $id_repertoire = 0;
314
        // on commence par rechercher le répertoire père, dans la base de donnée
321
        // on commence par rechercher le répertoire père, dans la base de donnée
315
        $requete = "select pd_pere, pd_nom, pd_id from projet_documents where pd_id=$id_repertoire" ;
322
        $requete = "select pd_pere, pd_nom, pd_id from projet_documents where pd_id=$id_repertoire" ;
316
        $resultat = $objetDB->query ($requete) ;
323
        $resultat = $objetDB->query ($requete) ;
317
        if (DB::isError($resultat)) {
324
        if (DB::isError($resultat)) {
318
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
325
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
319
        }
326
        }
320
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
327
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
321
        $chemin_rep_id_nom = array() ;
328
        $chemin_rep_id_nom = array() ;
-
 
329
        if ($resultat->numRows()>0) {
322
        if ($ligne->pd_pere == 0) {
330
    	    if ($ligne->pd_pere == 0) {
323
            $tab = array ($ligne->pd_id, $ligne->pd_nom) ;
331
        	    $tab = array ($ligne->pd_id, $ligne->pd_nom) ;
324
            return $tab ;
332
            return $tab ;
-
 
333
        	} 
325
        } else {
334
        	else {
326
            $requete_pere = "select pd_id, pd_nom from projet_documents where pd_id=$ligne->pd_pere" ;
335
	            $requete_pere = "select pd_id, pd_nom from projet_documents where pd_id=$ligne->pd_pere" ;
327
            $resultat_pere = $objetDB->query ($requete_pere) ;
336
	            $resultat_pere = $objetDB->query ($requete_pere) ;
328
            if (DB::isError($resultat_pere)) {
337
	            if (DB::isError($resultat_pere)) {
329
                die ("Echec de la requete<br />".$resultat_pere->getMessage()."<br />".$resultat_pere->getDebugInfo()) ;
338
	                die ("Echec de la requete<br />".$resultat_pere->getMessage()."<br />".$resultat_pere->getDebugInfo()) ;
330
            }
339
	            }
331
            $ligne_pere = $resultat_pere->fetchRow (DB_FETCHMODE_OBJECT) ;
340
	            $ligne_pere = $resultat_pere->fetchRow (DB_FETCHMODE_OBJECT) ;
332
            array_push ($chemin_rep_id_nom, $ligne->pd_id,$ligne->pd_nom) ;
341
	            array_push ($chemin_rep_id_nom, $ligne->pd_id,$ligne->pd_nom) ;
333
            $tab = document::getCheminIdRepertoire($ligne_pere->pd_id, $objetDB) ;
342
	            $tab = document::getCheminIdRepertoire($ligne_pere->pd_id, $objetDB) ;
334
            $chemin_rep_id_nom = array_merge ($chemin_rep_id_nom, $tab) ;
343
	            $chemin_rep_id_nom = array_merge ($chemin_rep_id_nom, $tab) ;
-
 
344
        	}
335
        }
345
        }
336
        $tabl_resultat = array() ;
346
        $tabl_resultat = array() ;
337
        for ($i = 0; $i < count ($chemin_rep_id_nom); $i++) {
347
        for ($i = 0; $i < count ($chemin_rep_id_nom); $i++) {
338
            $val1 = array_pop ($chemin_rep_id_nom) ;
348
            $val1 = array_pop ($chemin_rep_id_nom) ;
339
            $val2 = array_pop ($chemin_rep_id_nom) ;
349
            $val2 = array_pop ($chemin_rep_id_nom) ;
340
            array_push ($tabl_resultat, $val2, $val1) ;
350
            array_push ($tabl_resultat, $val2, $val1) ;
341
        }
351
        }
342
        return $tabl_resultat ;
352
        return $tabl_resultat ;
343
    } // end of member function getCheminIdRepertoire
353
    } // end of member function getCheminIdRepertoire
344
 
354
 
345
    /**
355
    /**
346
     *  Calcule le chemin vers le fichier ou le répertoire uploadé
356
     *  Calcule le chemin vers le fichier ou le répertoire uploadé
347
     *  renvoie un chaine de la forme dir1/dir2/fichier.ext
357
     *  renvoie un chaine de la forme dir1/dir2/fichier.ext
348
     *  En prenant comme racine le répertoire du projet, exclu.
358
     *  En prenant comme racine le répertoire du projet, exclu.
349
     * @return  string  Le chemin
359
     * @return  string  Le chemin
350
     */
360
     */
351
 
361
 
352
    function calculeCheminUploaded ($radical) {
362
    function calculeCheminUploaded ($radical) {
353
        // On recherche le chemin vers le fichier, en fonction du répertoire
363
        // On recherche le chemin vers le fichier, en fonction du répertoire
354
        // ici on renomme le fichier à partir du dernier ID de la table gen_voiraussi
364
        // ici on renomme le fichier à partir du dernier ID de la table gen_voiraussi
355
        $requete_document = "select pd_id from projet_documents order by pd_id desc limit 1,1" ;
365
        $requete_document = "select pd_id from projet_documents order by pd_id desc limit 1,1" ;
356
        $resultat_document = $this->_db->query($requete_document) ;
366
        $resultat_document = $this->_db->query($requete_document) ;
357
        $ligne_document = $resultat_document->fetchRow(DB_FETCHMODE_OBJECT) ;
367
        $ligne_document = $resultat_document->fetchRow(DB_FETCHMODE_OBJECT) ;
358
        $nouveau_nom = $ligne_document->pd_id+ 1 ;
368
        $nouveau_nom = $ligne_document->pd_id+ 1 ;
359
        
369
        
360
        $extension = preg_replace("/([^\.]+)\.([a-zA-Z0-9]+$)/", "\\2", $_FILES['fichier']['name']) ;
370
        $extension = preg_replace("/([^\.]+)\.([a-zA-Z0-9]+$)/", "\\2", $_FILES['fichier']['name']) ;
361
        
371
        
362
        $nouveau_nom = $radical."_".$nouveau_nom.".".$extension ;
372
        $nouveau_nom = $radical."_".$nouveau_nom.".".$extension ;
363
        if ($this->_id_pere != '') {
373
        if ($this->_id_pere != '') {
364
            // On appelle la méthode getCheminIdRepertoire qui renvoie un tableau avec la liste
374
            // On appelle la méthode getCheminIdRepertoire qui renvoie un tableau avec la liste
365
            // des répertoires jusqu'à la racine, on enlève la racine ($i = 0) et on concatène
375
            // des répertoires jusqu'à la racine, on enlève la racine ($i = 0) et on concatène
366
            // toutes les entrées pour obtenir le chemin jusqu'au répertoire courant
376
            // toutes les entrées pour obtenir le chemin jusqu'au répertoire courant
367
            $chemin_repertoire_entre_racine_et_repertoire_a_cree = '' ;
377
            $chemin_repertoire_entre_racine_et_repertoire_a_cree = '' ;
368
            $tableau_navigation = $this->getCheminIdRepertoire($this->_id_pere, $this->_db) ;
378
            $tableau_navigation = $this->getCheminIdRepertoire($this->_id_pere, $this->_db) ;
369
            for ($i = 0; $i < count ($tableau_navigation); $i+=2) $chemin_repertoire_entre_racine_et_repertoire_a_cree.= $tableau_navigation[$i]."/";
379
            for ($i = 0; $i < count ($tableau_navigation); $i+=2) $chemin_repertoire_entre_racine_et_repertoire_a_cree.= $tableau_navigation[$i]."/";
370
            $chemin = $chemin_repertoire_entre_racine_et_repertoire_a_cree.$nouveau_nom ;
380
            $chemin = $chemin_repertoire_entre_racine_et_repertoire_a_cree.$nouveau_nom ;
371
        } else {
381
        } else {
372
            // Si l'on est à la racine du projet, le chemin est le nom du fichier
382
            // Si l'on est à la racine du projet, le chemin est le nom du fichier
373
            return $nouveau_nom ;
383
            return $nouveau_nom ;
374
        }
384
        }
375
        return $chemin ;
385
        return $chemin ;
376
    }
386
    }
377
 
387
 
378
    /**
388
    /**
379
     * Enregistre une ligne dans la table projet_document
389
     * Enregistre une ligne dans la table projet_document
380
     * Le tableau de valeur doit contenir les éléments suivants 'document_nom','document_description','document_visibilite','fichier'
390
     * Le tableau de valeur doit contenir les éléments suivants 'document_nom','document_description','document_visibilite','fichier'
381
     *
391
     *
382
     * @param Array tableau_de_valeur Le tableau de valeur a insérer dans la base avec pour clé les noms des éléments
392
     * @param Array tableau_de_valeur Le tableau de valeur a insérer dans la base avec pour clé les noms des éléments
383
     * @access  public
393
     * @access  public
384
     * @return void
394
     * @return void
385
     */
395
     */
386
 
396
 
387
    function enregistrerSQL ($valeur, $chemin) {
397
    function enregistrerSQL ($valeur, $chemin) {
388
        
398
        
389
        // On teste si on a affaire à un répertoire ou un fichier
399
        // On teste si on a affaire à un répertoire ou un fichier
390
        if (isset ($_FILES['fichier']['name'])) {
400
        if (isset ($_FILES['fichier']['name'])) {
391
            // On tente de déterminer le type du fichier à partir de son nom dans $valeur['$fichier']
401
            // On tente de déterminer le type du fichier à partir de son nom dans $valeur['$fichier']
392
            $tableau_nom = explode (".", $_FILES['fichier']['name']) ;
402
            $tableau_nom = explode (".", $_FILES['fichier']['name']) ;
393
    
403
    
394
            // On prend le dernier élément du tableau, si c'est un tableau 
404
            // On prend le dernier élément du tableau, si c'est un tableau 
395
            if (is_array($tableau_nom)) {
405
            if (is_array($tableau_nom)) {
396
                $extension = array_pop($tableau_nom) ;
406
                $extension = array_pop($tableau_nom) ;
397
                $type = type_fichier_mime::factory($extension, $this->_db) ;
407
                $type = type_fichier_mime::factory($extension, $this->_db) ;
398
                $id_extension = $type->getIdType() ;
408
                $id_extension = $type->getIdType() ;
399
            } else {
409
            } else {
400
                $id_extension = 12 ;
410
                $id_extension = 12 ;
401
            }
411
            }
402
            $pd_lien = $chemin ;
412
            $pd_lien = $chemin ;
403
        } else {    // Le cas ou on a affaire à un répertoire
413
        } else {    // Le cas ou on a affaire à un répertoire
404
            $id_extension = 0 ;
414
            $id_extension = 0 ;
405
            // Le nom du répertoire est son identifiant avec un slash à la fin
415
            // Le nom du répertoire est son identifiant avec un slash à la fin
406
            $pd_lien = $chemin."/" ;
416
            $pd_lien = $chemin."/" ;
407
            if ($this->_id_pere != '') {
417
            if ($this->_id_pere != '') {
408
                // On appelle la méthode getCheminIdRepertoire qui renvoie un tableau avec la liste
418
                // On appelle la méthode getCheminIdRepertoire qui renvoie un tableau avec la liste
409
                // des répertoires jusqu'à la racine, on enlève la racine ($i = 0) et on concatène
419
                // des répertoires jusqu'à la racine, on enlève la racine ($i = 0) et on concatène
410
                // toutes les entrées pour obtenir le chemin jusqu'au répertoire courant
420
                // toutes les entrées pour obtenir le chemin jusqu'au répertoire courant
411
                $chemin_repertoire_entre_racine_et_repertoire_a_cree = '' ;
421
                $chemin_repertoire_entre_racine_et_repertoire_a_cree = '' ;
412
                $tableau_navigation = $this->getCheminIdRepertoire($this->_id_pere, $this->_db) ;
422
                $tableau_navigation = $this->getCheminIdRepertoire($this->_id_pere, $this->_db) ;
413
                for ($i = 0; $i < count ($tableau_navigation); $i+=2) $chemin_repertoire_entre_racine_et_repertoire_a_cree.= $tableau_navigation[$i]."/";
423
                for ($i = 0; $i < count ($tableau_navigation); $i+=2) $chemin_repertoire_entre_racine_et_repertoire_a_cree.= $tableau_navigation[$i]."/";
414
                $pd_lien .= $chemin_repertoire_entre_racine_et_repertoire_a_cree ;
424
                $pd_lien .= $chemin_repertoire_entre_racine_et_repertoire_a_cree ;
415
            }
425
            }
416
            $pd_lien .= SQL_obtenirNouveauId($this->_db, 'projet_documents', 'pd_id')."/" ;
426
            $pd_lien .= SQL_obtenirNouveauId($this->_db, 'projet_documents', 'pd_id')."/" ;
417
        }
427
        }
418
        $id = SQL_obtenirNouveauId($this->_db, 'projet_documents', 'pd_id') ;
428
        $id = SQL_obtenirNouveauId($this->_db, 'projet_documents', 'pd_id') ;
419
 
429
 
420
        $requete = "insert into projet_documents set pd_id=".$id ;
430
        $requete = "insert into projet_documents set pd_id=".$id ;
421
        $requete .= ", pd_nom=\"".$valeur['document_nom']."\", pd_description=\"".$valeur['document_description']."\"".
431
        $requete .= ", pd_nom=\"".$valeur['document_nom']."\", pd_description=\"".$valeur['document_description']."\"".
422
                    ", pd_visibilite=\"".$valeur['document_visibilite']."\", pd_date_de_mise_a_jour=NOW(),".
432
                    ", pd_visibilite=\"".$valeur['document_visibilite']."\", pd_date_de_mise_a_jour=NOW(),".
423
                    "pd_ce_projet=\"".$this->_id_projet."\", pd_ce_utilisateur=\"".$this->_id_proprietaire."\"".
433
                    "pd_ce_projet=\"".$this->_id_projet."\", pd_ce_utilisateur=\"".$this->_id_proprietaire."\"".
424
                    ", pd_pere=\"$this->_id_pere\", pd_ce_type=\"$id_extension\", pd_lien=\"$pd_lien\"" ;
434
                    ", pd_pere=\"$this->_id_pere\", pd_ce_type=\"$id_extension\", pd_lien=\"$pd_lien\"" ;
425
 
435
 
426
        $resultat = $this->_db->query ($requete) ;
436
        $resultat = $this->_db->query ($requete) ;
427
        if (DB::isError($resultat)) {
437
        if (DB::isError($resultat)) {
428
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
438
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
429
        }
439
        }
430
        $this->_id = $id ;
440
        $this->_id = $id ;
431
        return $pd_lien;
441
        return $pd_lien;
432
    }
442
    }
433
 
443
 
434
 
444
 
435
    /**
445
    /**
436
     * Met à jour une ligne dans la table projet_document
446
     * Met à jour une ligne dans la table projet_document
437
     * Le tableau de valeur doit contenir les éléments suivants 'document_nom','document_description','document_visibilite','fichier'
447
     * Le tableau de valeur doit contenir les éléments suivants 'document_nom','document_description','document_visibilite','fichier'
438
     *
448
     *
439
     * @param Array tableau_de_valeur Le tableau de valeur a insérer dans la base avec pour clé les noms des éléments
449
     * @param Array tableau_de_valeur Le tableau de valeur a insérer dans la base avec pour clé les noms des éléments
440
     * @access  public
450
     * @access  public
441
     * @return void
451
     * @return void
442
     */
452
     */
443
 
453
 
444
    function majSQL ($valeur) {
454
    function majSQL ($valeur) {
445
        $requete = "update projet_documents set pd_nom=\"".$valeur['document_nom']."\", pd_description=\"".$valeur['document_description']."\"".
455
        $requete = "update projet_documents set pd_nom=\"".$valeur['document_nom']."\", pd_description=\"".$valeur['document_description']."\"".
446
                    ", pd_visibilite=\"".$valeur['document_visibilite']."\", pd_date_de_mise_a_jour=NOW()".
456
                    ", pd_visibilite=\"".$valeur['document_visibilite']."\", pd_date_de_mise_a_jour=NOW()".
447
                    " where pd_id=".$this->_id;
457
                    " where pd_id=".$this->_id;
448
 
458
 
449
        $resultat = $this->_db->query ($requete) ;
459
        $resultat = $this->_db->query ($requete) ;
450
        if (DB::isError($resultat)) {
460
        if (DB::isError($resultat)) {
451
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
461
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
452
        }
462
        }
453
        return ;
463
        return ;
454
    }
464
    }
455
 
465
 
456
    /** Supprime les donnéexs du document dans la table projet_documents
466
    /** Supprime les donnéexs du document dans la table projet_documents
457
     *
467
     *
458
     *
468
     *
459
     * @return true en cas de succès
469
     * @return true en cas de succès
460
     */
470
     */
461
    
471
    
462
    function suppressionSQL () {
472
    function suppressionSQL () {
463
        $requete = 'delete from projet_documents where pd_id='.$this->_id ;
473
        $requete = 'delete from projet_documents where pd_id='.$this->_id ;
464
        $resultat = $this->_db->query ($requete) ;
474
        $resultat = $this->_db->query ($requete) ;
465
        if ($this->_db->affectedRows()) return true ;
475
        if ($this->_db->affectedRows()) return true ;
466
        return false ;
476
        return false ;
467
    }
477
    }
468
    
478
    
469
    /**
479
    /**
470
     * Déplace un document au sein d'un même projet
480
     * Déplace un document au sein d'un même projet
471
     *
481
     *
472
     * @param int repertoire_destination L'identifiant du répertoire destination.
482
     * @param int repertoire_destination L'identifiant du répertoire destination.
473
     * @return bool
483
     * @return bool
474
     * @access public
484
     * @access public
475
     */
485
     */
476
    function deplace( $repertoire_destination, $repertoire_projet )
486
    function deplace( $repertoire_destination, $repertoire_projet )
477
    {
487
    {
478
        // On récupère les informations du répertoire cible
488
        // On récupère les informations du répertoire cible
479
        if ($repertoire_destination != 0) {
489
        if ($repertoire_destination != 0) {
480
            $repertoire_cible = new document ($repertoire_destination, $this->_db) ;
490
            $repertoire_cible = new document ($repertoire_destination, $this->_db) ;
481
            $rep = $repertoire_cible->_pd_lien ;
491
            $rep = $repertoire_cible->_pd_lien ;
482
        } else {
492
        } else {
483
            $rep = $repertoire_projet.'/' ;
493
            $rep = $repertoire_projet.'/' ;
484
        }
494
        }
485
        
495
        
486
        // On récupère le nom du fichier
496
        // On récupère le nom du fichier
487
        $decoupe = explode ('/', $this->_pd_lien) ;
497
        $decoupe = explode ('/', $this->_pd_lien) ;
488
        $nom_fichier = $decoupe[count($decoupe)-1] ;
498
        $nom_fichier = $decoupe[count($decoupe)-1] ;
489
        $requete = 'update projet_documents set pd_lien="'.$rep.$nom_fichier.'", pd_pere='.$repertoire_destination.' where pd_id='.$this->_id ;
499
        $requete = 'update projet_documents set pd_lien="'.$rep.$nom_fichier.'", pd_pere='.$repertoire_destination.' where pd_id='.$this->_id ;
490
        $resultat = $this->_db->query ($requete) ;
500
        $resultat = $this->_db->query ($requete) ;
491
        if (DB::isError($resultat)) {
501
        if (DB::isError($resultat)) {
492
            echo ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
502
            echo ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
493
            return false ;
503
            return false ;
494
        }
504
        }
495
        return fichier::deplace ($this->_chemin, PROJET_CHEMIN_FICHIER.$rep.$nom_fichier) ;
505
        return fichier::deplace ($this->_chemin, PROJET_CHEMIN_FICHIER.$rep.$nom_fichier) ;
496
        
506
        
497
    } // end of member function deplace
507
    } // end of member function deplace
498
 
508
 
499
 
509
 
500
    /**
510
    /**
501
     * Pour modifier l'identifiant du projet auquel appartient un document.
511
     * Pour modifier l'identifiant du projet auquel appartient un document.
502
     *
512
     *
503
     * @param int id_projet L'identifiant du projet.
513
     * @param int id_projet L'identifiant du projet.
504
     * @return void
514
     * @return void
505
     * @access public
515
     * @access public
506
     */
516
     */
507
    function setIdProjet( $id_projet )
517
    function setIdProjet( $id_projet )
508
    {
518
    {
509
        $this->_id_projet = $id_projet ;
519
        $this->_id_projet = $id_projet ;
510
    } // end of member function setIdProjet
520
    } // end of member function setIdProjet
511
 
521
 
512
    /**
522
    /**
513
     * Permet de modifier l'identifiant du propietaire d'un projet.
523
     * Permet de modifier l'identifiant du propietaire d'un projet.
514
     *
524
     *
515
     * @param int id_proprietaire L'identifiant du proprietaire d'un document.
525
     * @param int id_proprietaire L'identifiant du proprietaire d'un document.
516
     * @return void
526
     * @return void
517
     * @access public
527
     * @access public
518
     */
528
     */
519
    function setIdProprietaire( $id_proprietaire )
529
    function setIdProprietaire( $id_proprietaire )
520
    {
530
    {
521
        $this->_id_proprietaire = $id_proprietaire ;
531
        $this->_id_proprietaire = $id_proprietaire ;
522
    } // end of member function setIdProprietaire
532
    } // end of member function setIdProprietaire
523
 
533
 
524
    /**
534
    /**
525
     * Permet de modifier l'identifiant du répertoire d'un document.
535
     * Permet de modifier l'identifiant du répertoire d'un document.
526
     *
536
     *
527
     * @param int id_repertoire L'identifiant du repertoire d'un document.
537
     * @param int id_repertoire L'identifiant du repertoire d'un document.
528
     * @return void
538
     * @return void
529
     * @access public
539
     * @access public
530
     */
540
     */
531
    function setIdRepertoire( $id_repertoire )
541
    function setIdRepertoire( $id_repertoire )
532
    {
542
    {
533
        $this->_id_pere = $id_repertoire;
543
        $this->_id_pere = $id_repertoire;
534
    } // end of member function setIdRepertoire
544
    } // end of member function setIdRepertoire
535
 
545
 
536
    /**
546
    /**
537
     * initAttributes sets all document attributes to its default                    value make
547
     * initAttributes sets all document attributes to its default                    value make
538
     * sure to call this method within your class constructor
548
     * sure to call this method within your class constructor
539
     */
549
     */
540
    function initAttributes( )
550
    function initAttributes( )
541
    {
551
    {
542
        $this->_visibilite = "public";
552
        $this->_visibilite = "public";
543
    }
553
    }
544
 
554
 
545
    /**
555
    /**
546
     * Renvoie les derniers documents de l'ensemble des projets.
556
     * Renvoie les derniers documents de l'ensemble des projets.
547
     *
557
     *
548
     * @param int nombre Le nombre de document à renvoyer
558
     * @param int nombre Le nombre de document à renvoyer
549
     * @return Array
559
     * @return Array
550
     * @static
560
     * @static
551
     * @access public
561
     * @access public
552
     */
562
     */
553
    function getDocumentsRecents( $nombre = 10, &$objetDB, $chemin, $chemin_icones, $id_projet = '' )
563
    function getDocumentsRecents( $nombre = 10, &$objetDB, $chemin, $chemin_icones, $id_projet = '' )
554
    {
564
    {
555
        // on recherche les documents, hors répertoire
565
        // on recherche les documents, hors répertoire
556
        $requete = 'select pd_id from projet_documents where pd_ce_type<>0 ';
566
        $requete = 'select pd_id from projet_documents where pd_ce_type<>0 ';
557
        if ($id_projet != '') $requete .= ' and pd_ce_projet='.$id_projet.' ';
567
        if ($id_projet != '') $requete .= ' and pd_ce_projet='.$id_projet.' ';
558
        $requete .= 'order by pd_date_de_mise_a_jour desc limit 0,'.$nombre ;
568
        $requete .= 'order by pd_date_de_mise_a_jour desc limit 0,'.$nombre ;
559
        $resultat = $objetDB->query ($requete) ;
569
        $resultat = $objetDB->query ($requete) ;
560
        if (DB::isError ($resultat)) {
570
        if (DB::isError ($resultat)) {
561
            die ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
571
            die ('Echec de la requete : '.$requete.'<br />'.$resultat->getMessage()) ;
562
        }
572
        }
563
        $tableau_document = array() ;
573
        $tableau_document = array() ;
564
        
574
        
565
        while ($ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT)) {
575
        while ($ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT)) {
566
            array_push ($tableau_document, new document ($ligne->pd_id, $objetDB, $chemin, $chemin_icones)) ;
576
            array_push ($tableau_document, new document ($ligne->pd_id, $objetDB, $chemin, $chemin_icones)) ;
567
        }
577
        }
568
        return $tableau_document ;
578
        return $tableau_document ;
569
    } // end of member function getDocumentsRecents
579
    } // end of member function getDocumentsRecents
570
 
580
 
571
 
581
 
572
} // end of document
582
} // end of document
573
 
583
 
574
 
584
 
575
?>
585
?>