Subversion Repositories Applications.projet

Compare Revisions

Ignore whitespace Rev 248 → Rev 249

/trunk/classes/document.class.php
19,7 → 19,7
// | License along with this library; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
// +------------------------------------------------------------------------------------------------------+
// CVS : $Id: document.class.php,v 1.7 2007-04-19 09:22:29 alexandre_tb Exp $
// CVS : $Id: document.class.php,v 1.8 2007-06-25 12:15:06 alexandre_tb Exp $
/**
* Application projet
*
31,7 → 31,7
//Autres auteurs :
*@author Aucun
*@copyright Tela-Botanica 2000-2004
*@version $Revision: 1.7 $
*@version $Revision: 1.8 $
// +------------------------------------------------------------------------------------------------------+
*/
 
116,6 → 116,8
*
*/
var $_pd_lien ;
var $nom_fichier ;
/**
*
*
128,6 → 130,7
{
$this->_db = $objetDB ;
$this->_chemin_icone = $chemin_icones ;
if ($id_document != "") {
$requete = "select * from projet_documents where pd_id=".$id_document ;
$resultat = $this->_db->query ($requete) ;
136,8 → 139,11
}
$ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
if ($resultat->numRows()>0) {
fichier::fichier($chemin.$ligne->pd_lien, $this->_db) ;
$this->nom_fichier = $ligne->pd_lien;
$this->_id_projet = $ligne->pd_ce_projet;
$this->_id = $ligne->pd_id ;
fichier::fichier($chemin.$this->getChemin(), $this->_db) ;
if (is_object ($this->_type_mime)) $this->_type_mime->setCheminIcone ($chemin_icones) ;
$this->_id_proprietaire = $ligne->pd_ce_utilisateur ;
$this->_nom_long = $ligne->pd_nom ;
145,6 → 151,7
$this->_date_mise_a_jour = $ligne->pd_date_de_mise_a_jour ;
$this->_description = $ligne->pd_description ;
$this->_pd_lien = $ligne->pd_lien;
if ($this->_isRacine($ligne->pd_pere)) {
$this->_id_pere = 0 ;
} else {
237,7 → 244,7
if ($this->isRepertoire()) {
return $this->_chemin_icone."repertoire.gif" ;
} else {
return $this->_type_mime->getCheminIcone() ;
if (is_object ($this->_type_mime)) return $this->_type_mime->getCheminIcone() ;
}
} // end of member function getCheminIcone
 
295,18 → 302,25
* @return string
* @access public
*/
function getChemin( )
function getChemin($prefixe = '')
{
if ($this->isRepertoire()) {
return $this->_id ;
} else {
return $this->_chemin ;
$chemin_repertoire_entre_racine_et_fichier = '';
 
include_once PROJET_CHEMIN_CLASSES.'projet.class.php';
$projet = new projet ($this->_db, $this->_id_projet);
// l arborescence des repertoires
$tableau_navigation = $this->getPath($this->_id) ;
if (is_array ($tableau_navigation))$tableau_navigation = array_reverse($tableau_navigation);
for ($i = 0; $i < count ($tableau_navigation); $i++) {
$chemin_repertoire_entre_racine_et_fichier.= $tableau_navigation[$i]."/";
}
} // end of member function getChemin
return $projet->getNomRepertoire().'/'.$chemin_repertoire_entre_racine_et_fichier.$this->nom_fichier ;
}
 
 
/**
* Renvoie pour le répertoire courant, les identifiants et les noms de tous les
* Renvoie pour le repertoire ou le fichier courant, les identifiants et les noms de tous les
* répertoires père jusqu'à la racine. 0 => ['id'], ['nom'] 1 => [id'], ['nom'] etc.
* En commençant par la racine et en descendant. Pour la racine id vaut "" et nom
* vaut "".
315,11 → 329,12
* @return Array
* @access public
*/
function getCheminIdRepertoire( $id_repertoire, &$objetDB )
function getCheminIdRepertoire( $id_doc, &$objetDB )
{
if ($id_repertoire == "") $id_repertoire = 0;
if ($id_doc == "") $id_doc = 0;
// on commence par rechercher le répertoire père, dans la base de donnée
$requete = "select pd_pere, pd_nom, pd_id from projet_documents where pd_id=$id_repertoire" ;
$requete = 'select pd_pere, pd_nom, pd_id, pd_ce_type from projet_documents where pd_id='.$id_doc ;
$resultat = $objetDB->query ($requete) ;
if (DB::isError($resultat)) {
die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
328,30 → 343,34
$chemin_rep_id_nom = array() ;
if ($resultat->numRows()>0) {
if ($ligne->pd_pere == 0) {
$tab = array ($ligne->pd_id, $ligne->pd_nom) ;
return $tab ;
}
else {
$requete_pere = "select pd_id, pd_nom from projet_documents where pd_id=$ligne->pd_pere" ;
$resultat_pere = $objetDB->query ($requete_pere) ;
if (DB::isError($resultat_pere)) {
die ("Echec de la requete<br />".$resultat_pere->getMessage()."<br />".$resultat_pere->getDebugInfo()) ;
}
$ligne_pere = $resultat_pere->fetchRow (DB_FETCHMODE_OBJECT) ;
array_push ($chemin_rep_id_nom, $ligne->pd_id,$ligne->pd_nom) ;
$tab = document::getCheminIdRepertoire($ligne_pere->pd_id, $objetDB) ;
$chemin_rep_id_nom = array_merge ($chemin_rep_id_nom, $tab) ;
return ; //array ($ligne->pd_pere);
}
array_push ($chemin_rep_id_nom, $ligne->pd_pere) ;
$tab = document::getCheminIdRepertoire($ligne->pd_pere, $objetDB) ;
$chemin_rep_id_nom = array_merge ($tab, $chemin_rep_id_nom) ;
}
$tabl_resultat = array() ;
for ($i = 0; $i < count ($chemin_rep_id_nom); $i++) {
$val1 = array_pop ($chemin_rep_id_nom) ;
$val2 = array_pop ($chemin_rep_id_nom) ;
array_push ($tabl_resultat, $val2, $val1) ;
return array_reverse($chemin_rep_id_nom);
}
function getPath( $id_doc)
{
if ($id_doc == "") $id_doc = 0;
// on commence par rechercher le répertoire père, dans la base de donnée
$requete = 'select pd_pere, pd_nom, pd_id, pd_ce_type from projet_documents where pd_id='.$id_doc ;
$resultat = $GLOBALS['projet_db']->query ($requete) ;
if (DB::isError($resultat)) {
return ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
}
return $tabl_resultat ;
} // end of member function getCheminIdRepertoire
 
$ligne = $resultat->fetchRow (DB_FETCHMODE_OBJECT) ;
$chemin_rep_id_nom = array() ;
if ($resultat->numRows()>0) {
if ($ligne->pd_pere == 0) {
return;
}
array_push ($chemin_rep_id_nom, $ligne->pd_pere) ;
$chemin_rep_id_nom = array_merge ($chemin_rep_id_nom, document::getPath($ligne->pd_pere) );
}
return $chemin_rep_id_nom;
}
/**
* Calcule le chemin vers le fichier ou le répertoire uploadé
* renvoie un chaine de la forme dir1/dir2/fichier.ext
360,27 → 379,25
*/
 
function calculeCheminUploaded ($radical) {
// On recherche le chemin vers le fichier, en fonction du répertoire
// ici on renomme le fichier à partir du dernier ID de la table gen_voiraussi
$requete_document = "select pd_id from projet_documents order by pd_id desc limit 1,1" ;
$resultat_document = $this->_db->query($requete_document) ;
$ligne_document = $resultat_document->fetchRow(DB_FETCHMODE_OBJECT) ;
$nouveau_nom = $ligne_document->pd_id + 1 ;
$extension = preg_replace("/^([^\.]+)\.(\w+$)/", "\\2", $_FILES['fichier']['name']) ;
$nouveau_nom = $radical."_".$nouveau_nom.".".$extension ;
 
if (isset($_FILES['fichier']['name'])) {
$extension = preg_replace("/^([^\.]+)\.(\w+$)/", "\\2", $_FILES['fichier']['name']) ;
}
 
if ($this->_id_pere != '') {
// On appelle la méthode getCheminIdRepertoire qui renvoie un tableau avec la liste
// des répertoires jusqu'à la racine, on enlève la racine ($i = 0) et on concatène
// toutes les entrées pour obtenir le chemin jusqu'au répertoire courant
$chemin_repertoire_entre_racine_et_repertoire_a_cree = '' ;
$tableau_navigation = $this->getCheminIdRepertoire($this->_id_pere, $this->_db) ;
for ($i = 0; $i < count ($tableau_navigation); $i+=2) $chemin_repertoire_entre_racine_et_repertoire_a_cree.= $tableau_navigation[$i]."/";
$chemin = $chemin_repertoire_entre_racine_et_repertoire_a_cree.$nouveau_nom ;
$doc_pere = new document ($this->_id_pere, $this->_db);
return $doc_pere->getChemin();
$tableau_navigation = $this->getPath($this->_id_pere) ;
for ($i = 0; $i < count ($tableau_navigation); $i++) $chemin_repertoire_entre_racine_et_repertoire_a_cree.= $tableau_navigation[$i]."/";
$chemin = $chemin_repertoire_entre_racine_et_repertoire_a_cree ;
} else {
// Si l'on est à la racine du projet, le chemin est le nom du fichier
return $nouveau_nom ;
// Si l'on est à la racine du projet, le chemin vide
return $radical ;
}
return $chemin ;
}
423,7 → 440,8
for ($i = 0; $i < count ($tableau_navigation); $i+=2) $chemin_repertoire_entre_racine_et_repertoire_a_cree.= $tableau_navigation[$i]."/";
$pd_lien .= $chemin_repertoire_entre_racine_et_repertoire_a_cree ;
}
$pd_lien .= SQL_obtenirNouveauId($this->_db, 'projet_documents', 'pd_id')."/" ;
//$pd_lien .= SQL_obtenirNouveauId($this->_db, 'projet_documents', 'pd_id')."/" ;
$pd_lien = SQL_obtenirNouveauId($this->_db, 'projet_documents', 'pd_id')."/" ;
}
$id = SQL_obtenirNouveauId($this->_db, 'projet_documents', 'pd_id') ;
 
441,6 → 459,11
return $pd_lien;
}
 
function genereNouveauNom ($radical, $ancien_nom, $id) {
$extension = preg_replace("/^([^\.]+)\.(\w+$)/", "\\2", $ancien_nom) ;
$nouveau_nom = $radical."_".$id.".".$extension ;
return $nouveau_nom;
}
 
/**
* Met à jour une ligne dans la table projet_document
485,24 → 508,28
*/
function deplace( $repertoire_destination, $repertoire_projet )
{
 
// On récupère les informations du répertoire cible
if ($repertoire_destination != 0) {
$repertoire_cible = new document ($repertoire_destination, $this->_db) ;
$rep = $repertoire_cible->_pd_lien ;
$chemin_rep_cible = $repertoire_cible->getChemin();
} else {
$rep = $repertoire_projet.'/' ;
// Si le repertoire destination est la racine cad id =0
// on cree un document qui aura pour chemin le repertoire du projet
include_once PROJET_CHEMIN_CLASSES.'projet.class.php';
$projet = new projet ($this->_db, $this->_id_projet);
$chemin_rep_cible = $projet->getNomRepertoire().'/';
}
// On récupère le nom du fichier
$decoupe = explode ('/', $this->_pd_lien) ;
$nom_fichier = $decoupe[count($decoupe)-1] ;
$requete = 'update projet_documents set pd_lien="'.$rep.$nom_fichier.'", pd_pere='.$repertoire_destination.' where pd_id='.$this->_id ;
$nom_fichier = $this->_pd_lien ;
$requete = 'update projet_documents set pd_pere='.$repertoire_destination.' where pd_id='.$this->_id ;
$resultat = $this->_db->query ($requete) ;
if (DB::isError($resultat)) {
echo ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
return false ;
}
return fichier::deplace ($this->_chemin, PROJET_CHEMIN_FICHIER.$rep.$nom_fichier) ;
//echo $this->_chemin.'<br>'.PROJET_CHEMIN_FICHIER.$chemin_rep_cible.$nom_fichier;
return fichier::deplace ($this->_chemin, PROJET_CHEMIN_FICHIER.$chemin_rep_cible.$nom_fichier) ;
} // end of member function deplace
 
613,6 → 640,17
}
return round ($taille / $diviseur, $precision).'&nbsp;'.$unite;
}
/**
* Renvoie une liste de document, enfant du document courant
* qui doit etre un repertoire bien sur
*
* @return mixed un tableau de document
* @access public
*/
function getDocumentsEnfant() {
}
} // end of document