Subversion Repositories Applications.projet

Rev

Rev 249 | Rev 330 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 249 Rev 309
Line 17... Line 17...
17
// |                                                                                                      |
17
// |                                                                                                      |
18
// | You should have received a copy of the GNU General Public                                            |
18
// | You should have received a copy of the GNU General Public                                            |
19
// | License along with this library; if not, write to the Free Software                                  |
19
// | License along with this library; if not, write to the Free Software                                  |
20
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
20
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
21
// +------------------------------------------------------------------------------------------------------+
21
// +------------------------------------------------------------------------------------------------------+
22
// CVS : $Id: document.class.php,v 1.8 2007-06-25 12:15:06 alexandre_tb Exp $
22
// CVS : $Id: document.class.php,v 1.9 2008-08-25 15:18:10 alexandre_tb Exp $
23
/**
23
/**
24
* Application projet
24
* Application projet
25
*
25
*
26
* La classe document
26
* La classe document
27
*
27
*
Line 29... Line 29...
29
//Auteur original :
29
//Auteur original :
30
*@author        Alexandre Granier <alexandre@tela-botanica.org>
30
*@author        Alexandre Granier <alexandre@tela-botanica.org>
31
//Autres auteurs :
31
//Autres auteurs :
32
*@author        Aucun
32
*@author        Aucun
33
*@copyright     Tela-Botanica 2000-2004
33
*@copyright     Tela-Botanica 2000-2004
34
*@version       $Revision: 1.8 $
34
*@version       $Revision: 1.9 $
35
// +------------------------------------------------------------------------------------------------------+
35
// +------------------------------------------------------------------------------------------------------+
36
*/
36
*/
Line 37... Line 37...
37
 
37
 
Line 126... Line 126...
126
     * @return void
126
     * @return void
127
     * @access public
127
     * @access public
128
     */
128
     */
129
    function document( $id_document = "",  &$objetDB, $chemin = '', $chemin_icones = '')
129
    function document( $id_document = "",  &$objetDB, $chemin = '', $chemin_icones = '')
130
    {
130
    {
131
        $this->_db = $objetDB ;
131
        if (is_object($objetDB)) {
-
 
132
        	$GLOBALS['projet_db'] = $objetDB;
-
 
133
        }  
132
        $this->_chemin_icone = $chemin_icones ;
134
        $this->_chemin_icone = $chemin_icones ;
Line 133... Line 135...
133
        
135
        
134
        if ($id_document != "") {
136
        if ($id_document != "") {
135
            $requete = "select * from projet_documents where pd_id=".$id_document ;
137
            $requete = "select * from projet_documents where pd_id=".$id_document ;
136
            $resultat = $this->_db->query ($requete) ;
138
            $resultat = $GLOBALS['projet_db']->query ($requete) ;
137
            if (DB::isError($resultat)) {
139
            if (DB::isError($resultat)) {
138
                die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
140
                die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
139
            }
141
            }
140
            $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
142
            $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
141
    		if ($resultat->numRows()>0) {
143
    		if ($resultat->numRows()>0) {
142
	            $this->nom_fichier = $ligne->pd_lien;
144
	            $this->nom_fichier = $ligne->pd_lien;
143
	            $this->_id_projet = $ligne->pd_ce_projet;
145
	            $this->_id_projet = $ligne->pd_ce_projet;
144
	            $this->_id = $ligne->pd_id ;
146
	            $this->_id = $ligne->pd_id ;
Line 145... Line 147...
145
	            fichier::fichier($chemin.$this->getChemin(), $this->_db) ;
147
	            fichier::fichier($chemin.$this->getChemin(), $GLOBALS['projet_db']) ;
146
	            
148
	            
147
	            if (is_object ($this->_type_mime)) $this->_type_mime->setCheminIcone ($chemin_icones) ;
149
	            if (is_object ($this->_type_mime)) $this->_type_mime->setCheminIcone ($chemin_icones) ;
148
	            $this->_id_proprietaire = $ligne->pd_ce_utilisateur ;
150
	            $this->_id_proprietaire = $ligne->pd_ce_utilisateur ;
Line 279... Line 281...
279
     */
281
     */
280
    function _isRacine( $id_document )
282
    function _isRacine( $id_document )
281
    {
283
    {
282
    	if ($id_document) {
284
    	if ($id_document) {
283
	        $requete = "select pd_pere from projet_documents where pd_id=".$id_document ;
285
	        $requete = "select pd_pere from projet_documents where pd_id=".$id_document ;
284
	        $resultat = $this->_db->query ($requete) ;
286
	        $resultat = $GLOBALS['projet_db']->query ($requete) ;
285
	        if (DB::isError($resultat)) {
287
	        if (DB::isError($resultat)) {
286
	            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
288
	            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
287
	        }
289
	        }
288
	        $ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT) ;
290
	        $ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT) ;
289
	        if ($resultat->numRows() >0) {
291
	        if ($resultat->numRows() >0) {
Line 305... Line 307...
305
    function getChemin($prefixe = '')
307
    function getChemin($prefixe = '')
306
    {
308
    {
307
        $chemin_repertoire_entre_racine_et_fichier = '';
309
        $chemin_repertoire_entre_racine_et_fichier = '';
Line 308... Line 310...
308
 
310
 
309
        include_once PROJET_CHEMIN_CLASSES.'projet.class.php';
311
        include_once PROJET_CHEMIN_CLASSES.'projet.class.php';
310
        $projet = new projet ($this->_db, $this->_id_projet);
312
        $projet = new projet ($GLOBALS['projet_db'], $this->_id_projet);
Line 311... Line 313...
311
        // l arborescence des repertoires
313
        // l arborescence des repertoires
312
        
314
        
313
        $tableau_navigation = $this->getPath($this->_id) ;
315
        $tableau_navigation = $this->getPath($this->_id) ;
Line 362... Line 364...
362
        }
364
        }
363
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
365
        $ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
364
        $chemin_rep_id_nom = array() ;
366
        $chemin_rep_id_nom = array() ;
365
        if ($resultat->numRows()>0) {
367
        if ($resultat->numRows()>0) {
366
    	    if ($ligne->pd_pere == 0) {
368
    	    if ($ligne->pd_pere == 0) {
367
        	    return;
369
        	    return array();
368
        	}
370
        	}
369
            array_push ($chemin_rep_id_nom, $ligne->pd_pere) ;
371
            array_push ($chemin_rep_id_nom, $ligne->pd_pere) ;
370
            $chemin_rep_id_nom = array_merge ($chemin_rep_id_nom, document::getPath($ligne->pd_pere) );
372
            $chemin_rep_id_nom = array_merge ($chemin_rep_id_nom, document::getPath($ligne->pd_pere) );
371
        }
373
        }
372
        return $chemin_rep_id_nom;
374
        return $chemin_rep_id_nom;
Line 387... Line 389...
387
        if ($this->_id_pere != '') {
389
        if ($this->_id_pere != '') {
388
            // On appelle la méthode getCheminIdRepertoire qui renvoie un tableau avec la liste
390
            // On appelle la méthode getCheminIdRepertoire qui renvoie un tableau avec la liste
389
            // des répertoires jusqu'à la racine, on enlève la racine ($i = 0) et on concatène
391
            // des répertoires jusqu'à la racine, on enlève la racine ($i = 0) et on concatène
390
            // toutes les entrées pour obtenir le chemin jusqu'au répertoire courant
392
            // toutes les entrées pour obtenir le chemin jusqu'au répertoire courant
391
            $chemin_repertoire_entre_racine_et_repertoire_a_cree = '' ;
393
            $chemin_repertoire_entre_racine_et_repertoire_a_cree = '' ;
392
            $doc_pere = new document ($this->_id_pere, $this->_db);
394
            $doc_pere = new document ($this->_id_pere, $GLOBALS['projet_db']);
393
            return $doc_pere->getChemin();
395
            return $doc_pere->getChemin();
394
            $tableau_navigation = $this->getPath($this->_id_pere) ;
396
            $tableau_navigation = $this->getPath($this->_id_pere) ;
Line 395... Line 397...
395
            
397
            
396
            for ($i = 0; $i < count ($tableau_navigation); $i++) $chemin_repertoire_entre_racine_et_repertoire_a_cree.= $tableau_navigation[$i]."/";
398
            for ($i = 0; $i < count ($tableau_navigation); $i++) $chemin_repertoire_entre_racine_et_repertoire_a_cree.= $tableau_navigation[$i]."/";
Line 419... Line 421...
419
            $tableau_nom = explode (".", $_FILES['fichier']['name']) ;
421
            $tableau_nom = explode (".", $_FILES['fichier']['name']) ;
Line 420... Line 422...
420
    
422
    
421
            // On prend le dernier élément du tableau, si c'est un tableau 
423
            // On prend le dernier élément du tableau, si c'est un tableau 
422
            if (is_array($tableau_nom)) {
424
            if (is_array($tableau_nom)) {
423
                $extension = array_pop($tableau_nom) ;
425
                $extension = array_pop($tableau_nom) ;
424
                $type = type_fichier_mime::factory($extension, $this->_db) ;
426
                $type = type_fichier_mime::factory($extension) ;
425
                $id_extension = $type->getIdType() ;
427
                $id_extension = $type->getIdType() ;
426
            } else {
428
            } else {
427
                $id_extension = 12 ;
429
                $id_extension = 12 ;
428
            }
430
            }
Line 434... Line 436...
434
            if ($this->_id_pere != '') {
436
            if ($this->_id_pere != '') {
435
                // On appelle la méthode getCheminIdRepertoire qui renvoie un tableau avec la liste
437
                // On appelle la méthode getCheminIdRepertoire qui renvoie un tableau avec la liste
436
                // des répertoires jusqu'à la racine, on enlève la racine ($i = 0) et on concatène
438
                // des répertoires jusqu'à la racine, on enlève la racine ($i = 0) et on concatène
437
                // toutes les entrées pour obtenir le chemin jusqu'au répertoire courant
439
                // toutes les entrées pour obtenir le chemin jusqu'au répertoire courant
438
                $chemin_repertoire_entre_racine_et_repertoire_a_cree = '' ;
440
                $chemin_repertoire_entre_racine_et_repertoire_a_cree = '' ;
439
                $tableau_navigation = $this->getCheminIdRepertoire($this->_id_pere, $this->_db) ;
441
                $tableau_navigation = $this->getCheminIdRepertoire($this->_id_pere, $GLOBALS['projet_db']) ;
440
                for ($i = 0; $i < count ($tableau_navigation); $i+=2) $chemin_repertoire_entre_racine_et_repertoire_a_cree.= $tableau_navigation[$i]."/";
442
                for ($i = 0; $i < count ($tableau_navigation); $i+=2) $chemin_repertoire_entre_racine_et_repertoire_a_cree.= $tableau_navigation[$i]."/";
441
                $pd_lien .= $chemin_repertoire_entre_racine_et_repertoire_a_cree ;
443
                $pd_lien .= $chemin_repertoire_entre_racine_et_repertoire_a_cree ;
442
            }
444
            }
443
            //$pd_lien .= SQL_obtenirNouveauId($this->_db, 'projet_documents', 'pd_id')."/" ;
445
            //$pd_lien .= SQL_obtenirNouveauId($GLOBALS['projet_db'], 'projet_documents', 'pd_id')."/" ;
444
            $pd_lien = SQL_obtenirNouveauId($this->_db, 'projet_documents', 'pd_id')."/" ;
446
            $pd_lien = SQL_obtenirNouveauId($GLOBALS['projet_db'], 'projet_documents', 'pd_id')."/" ;
445
        }
447
        }
446
        $id = SQL_obtenirNouveauId($this->_db, 'projet_documents', 'pd_id') ;
448
        $id = SQL_obtenirNouveauId($GLOBALS['projet_db'], 'projet_documents', 'pd_id') ;
Line 447... Line 449...
447
 
449
 
448
        $requete = "insert into projet_documents set pd_id=".$id ;
450
        $requete = "insert into projet_documents set pd_id=".$id ;
449
        $requete .= ", pd_nom=\"".$valeur['document_nom']."\", pd_description=\"".$valeur['document_description']."\"".
451
        $requete .= ", pd_nom=\"".$valeur['document_nom']."\", pd_description=\"".$valeur['document_description']."\"".
450
                    ", pd_visibilite=\"".$valeur['document_visibilite']."\", pd_date_de_mise_a_jour=NOW(),".
452
                    ", pd_visibilite=\"".$valeur['document_visibilite']."\", pd_date_de_mise_a_jour=NOW(),".
451
                    "pd_ce_projet=\"".$this->_id_projet."\", pd_ce_utilisateur=\"".$this->_id_proprietaire."\"".
453
                    "pd_ce_projet=\"".$this->_id_projet."\", pd_ce_utilisateur=\"".$this->_id_proprietaire."\"".
Line 452... Line 454...
452
                    ", pd_pere=\"$this->_id_pere\", pd_ce_type=\"$id_extension\", pd_lien=\"$pd_lien\"" ;
454
                    ", pd_pere=\"$this->_id_pere\", pd_ce_type=\"$id_extension\", pd_lien=\"$pd_lien\"" ;
453
 
455
 
454
        $resultat = $this->_db->query ($requete) ;
456
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
455
        if (DB::isError($resultat)) {
457
        if (DB::isError($resultat)) {
456
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
458
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
457
        }
459
        }
Line 477... Line 479...
477
    function majSQL ($valeur) {
479
    function majSQL ($valeur) {
478
        $requete = "update projet_documents set pd_nom=\"".$valeur['document_nom']."\", pd_description=\"".$valeur['document_description']."\"".
480
        $requete = "update projet_documents set pd_nom=\"".$valeur['document_nom']."\", pd_description=\"".$valeur['document_description']."\"".
479
                    ", pd_visibilite=\"".$valeur['document_visibilite']."\", pd_date_de_mise_a_jour=NOW()".
481
                    ", pd_visibilite=\"".$valeur['document_visibilite']."\", pd_date_de_mise_a_jour=NOW()".
480
                    " where pd_id=".$this->_id;
482
                    " where pd_id=".$this->_id;
Line 481... Line 483...
481
 
483
 
482
        $resultat = $this->_db->query ($requete) ;
484
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
483
        if (DB::isError($resultat)) {
485
        if (DB::isError($resultat)) {
484
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
486
            die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
485
        }
487
        }
486
        return ;
488
        return ;
Line 492... Line 494...
492
     * @return true en cas de succès
494
     * @return true en cas de succès
493
     */
495
     */
Line 494... Line 496...
494
    
496
    
495
    function suppressionSQL () {
497
    function suppressionSQL () {
496
        $requete = 'delete from projet_documents where pd_id='.$this->_id ;
498
        $requete = 'delete from projet_documents where pd_id='.$this->_id ;
497
        $resultat = $this->_db->query ($requete) ;
499
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
498
        if ($this->_db->affectedRows()) return true ;
500
        if ($GLOBALS['projet_db']->affectedRows()) return true ;
499
        return false ;
501
        return false ;
Line 500... Line 502...
500
    }
502
    }
501
    
503
    
Line 509... Line 511...
509
    function deplace( $repertoire_destination, $repertoire_projet )
511
    function deplace( $repertoire_destination, $repertoire_projet )
510
    {
512
    {
Line 511... Line 513...
511
 
513
 
512
        // On récupère les informations du répertoire cible
514
        // On récupère les informations du répertoire cible
513
        if ($repertoire_destination != 0) {
515
        if ($repertoire_destination != 0) {
514
            $repertoire_cible = new document ($repertoire_destination, $this->_db) ;
516
            $repertoire_cible = new document ($repertoire_destination, $GLOBALS['projet_db']) ;
515
            $chemin_rep_cible = $repertoire_cible->getChemin();
517
            $chemin_rep_cible = $repertoire_cible->getChemin();
516
        } else {
518
        } else {
517
        	// Si le repertoire destination est la racine cad id =0
519
        	// Si le repertoire destination est la racine cad id =0
518
        	// on cree un document qui aura pour chemin le repertoire du projet 
520
        	// on cree un document qui aura pour chemin le repertoire du projet 
519
        	include_once PROJET_CHEMIN_CLASSES.'projet.class.php';
521
        	include_once PROJET_CHEMIN_CLASSES.'projet.class.php';
520
            $projet = new projet ($this->_db, $this->_id_projet);
522
            $projet = new projet ($GLOBALS['projet_db'], $this->_id_projet);
521
        	$chemin_rep_cible = $projet->getNomRepertoire().'/';
523
        	$chemin_rep_cible = $projet->getNomRepertoire().'/';
Line 522... Line 524...
522
        }
524
        }
523
   
525
   
524
        $nom_fichier = $this->_pd_lien ;
526
        $nom_fichier = $this->_pd_lien ;
525
        $requete = 'update projet_documents set pd_pere='.$repertoire_destination.' where pd_id='.$this->_id ;
527
        $requete = 'update projet_documents set pd_pere='.$repertoire_destination.' where pd_id='.$this->_id ;
526
        $resultat = $this->_db->query ($requete) ;
528
        $resultat = $GLOBALS['projet_db']->query ($requete) ;
527
        if (DB::isError($resultat)) {
529
        if (DB::isError($resultat)) {
528
            echo ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
530
            echo ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
529
            return false ;
531
            return false ;