Subversion Repositories Applications.projet

Rev

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

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