| 206 | alexandre_ | 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 | // +------------------------------------------------------------------------------------------------------+
 | 
        
           | 234 | alexandre_ | 22 | // CVS : $Id: ecouteArbreFichier.php,v 1.1.2.1 2007-05-11 13:58:14 alexandre_tb Exp $
 | 
        
           | 206 | alexandre_ | 23 | /**
 | 
        
           |  |  | 24 | * Application projet
 | 
        
           |  |  | 25 | *
 | 
        
           |  |  | 26 | * Service d ecoute de l arbre du porte document, renvoie les donnees du repertoire demande
 | 
        
           |  |  | 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-2005
 | 
        
           | 234 | alexandre_ | 34 | *@version       $Revision: 1.1.2.1 $
 | 
        
           | 206 | alexandre_ | 35 | // +------------------------------------------------------------------------------------------------------+
 | 
        
           |  |  | 36 | */
 | 
        
           |  |  | 37 |   | 
        
           |  |  | 38 | // +------------------------------------------------------------------------------------------------------+
 | 
        
           |  |  | 39 | // |                                            ENTETE du PROGRAMME                                       |
 | 
        
           |  |  | 40 | // +------------------------------------------------------------------------------------------------------+
 | 
        
           |  |  | 41 |   | 
        
           |  |  | 42 | // ATTENTION - le programme suivant doit renvoyer un tableau, meme vide
 | 
        
           |  |  | 43 | // sinon l arbre dojo ne fonctionnera pas (ligne 117 $returnArray = array)
 | 
        
           |  |  | 44 |   | 
        
           |  |  | 45 |   | 
        
           | 234 | alexandre_ | 46 | include_once (GEN_CHEMIN_API.'json/JSON.php');
 | 
        
           | 206 | alexandre_ | 47 |   | 
        
           |  |  | 48 | $action = $_REQUEST["action"];
 | 
        
           |  |  | 49 | $data = $_REQUEST["data"];
 | 
        
           |  |  | 50 | $cache = $_REQUEST["dojo.preventCache"];
 | 
        
           |  |  | 51 |   | 
        
           |  |  | 52 | $data = str_replace("\\\"","\"",$data);
 | 
        
           |  |  | 53 |   | 
        
           | 234 | alexandre_ | 54 | // instanciation d un json-php
 | 
        
           | 206 | alexandre_ | 55 |   | 
        
           |  |  | 56 | $json = new services_JSON();
 | 
        
           |  |  | 57 |   | 
        
           |  |  | 58 | if ( $action == "getChildren") {
 | 
        
           |  |  | 59 |     $jsonData = $json->decode($data);
 | 
        
           |  |  | 60 |     // get the node object
 | 
        
           |  |  | 61 |     $node = $jsonData->node;
 | 
        
           |  |  | 62 | }
 | 
        
           |  |  | 63 |   | 
        
           | 234 | alexandre_ | 64 | if ( $action == "getChildren") {
 | 
        
           |  |  | 65 |    $jsonData = $json->decode($data);
 | 
        
           |  |  | 66 |    // get the node object
 | 
        
           |  |  | 67 |    $node = $jsonData->node;
 | 
        
           |  |  | 68 |    // on recupere le noeud parent
 | 
        
           | 206 | alexandre_ | 69 |    $parent = $node->objectId;
 | 
        
           |  |  | 70 | 	if (isset($_REQUEST['id_projet'])) $id_projet = $_REQUEST['id_projet'];
 | 
        
           |  |  | 71 | 	if (preg_match ('/projet_([0-9]+)/', $node->objectId, $match)) $id_projet = $match[1];
 | 
        
           |  |  | 72 |    // correspondance entre l objectid de dojo et id_parent de projet_document
 | 
        
           |  |  | 73 |    if ( $parent == "root" || preg_match ('/projet_([0-9]+)/', $node->objectId, $match)) {
 | 
        
           |  |  | 74 |     	$id_parent = 0 ;
 | 
        
           |  |  | 75 |    } else {
 | 
        
           |  |  | 76 |    		$id_parent = $node->objectId;
 | 
        
           |  |  | 77 |    }
 | 
        
           |  |  | 78 | 	$sql = 'select * from projet_documents where pd_pere='.$id_parent ;
 | 
        
           |  |  | 79 | 	if (isset($id_projet)) $sql .= ' and pd_ce_projet='.$id_projet;
 | 
        
           |  |  | 80 |   | 
        
           | 234 | alexandre_ | 81 |    $resultat = $GLOBALS['projet_db']->query($sql);
 | 
        
           |  |  | 82 |   | 
        
           | 206 | alexandre_ | 83 |    if (DB::isError($resultat)) {
 | 
        
           |  |  | 84 |         die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
 | 
        
           |  |  | 85 |    }
 | 
        
           | 234 | alexandre_ | 86 |    $nodeArray = array();
 | 
        
           | 206 | alexandre_ | 87 |    $i = 0;
 | 
        
           | 234 | alexandre_ | 88 |   | 
        
           |  |  | 89 |    include_once PROJET_CHEMIN_CLASSES.'document.class.php';
 | 
        
           |  |  | 90 |   | 
        
           |  |  | 91 |    if ($GLOBALS['projet_auth']->getAuth()) {
 | 
        
           |  |  | 92 | 	    include_once PROJET_CHEMIN_CLASSES.'participe.class.php' ;
 | 
        
           |  |  | 93 | 	    $participant = new participe($GLOBALS['projet_db']) ;
 | 
        
           |  |  | 94 | 	    $id_u = $this->_auth->getAuthData(PROJET_CHAMPS_ID) ;
 | 
        
           |  |  | 95 | 	    $isCoord = $participant->isCoordinateur($id_u, $this->_id_projet, $this->_db) ;
 | 
        
           |  |  | 96 | 	    if ($isCoord) $droits = PROJET_DROIT_COORDINATEUR ;
 | 
        
           |  |  | 97 | 	    $isAdm = participe::isAdministrateur($this->_auth->getAuthData(PROJET_CHAMPS_ID), $this->_db) ;
 | 
        
           |  |  | 98 | 	    if ($isAdm) $droits = PROJET_DROIT_ADMINISTRATEUR ;
 | 
        
           |  |  | 99 | 	    if ($isAdm) $isCoord = true ;
 | 
        
           |  |  | 100 | 	    $isParticipant = $participant->isContributeur($id_u, $this->_id_projet, $this->_db);
 | 
        
           |  |  | 101 | 	    if ($isParticipant) $droits = PROJET_DROIT_CONTRIBUTEUR;
 | 
        
           |  |  | 102 |   | 
        
           |  |  | 103 | 	    $statut = participe::getStatutSurProjetCourant ($this->_auth->getAuthData(PROJET_CHAMPS_ID), $this->_id_projet, $this->_db) ;
 | 
        
           |  |  | 104 | 	    // si participant, on ajoute le champs visibilite
 | 
        
           |  |  | 105 |    } else {
 | 
        
           |  |  | 106 |    	$droits = PROJET_DROIT_AUCUN;
 | 
        
           |  |  | 107 |    }
 | 
        
           |  |  | 108 |   | 
        
           | 206 | alexandre_ | 109 |    while ( $ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
 | 
        
           | 234 | alexandre_ | 110 |        $document = new document($ligne['pd_id'], $GLOBALS['projet_db'], PROJET_CHEMIN_FICHIER, PROJET_CHEMIN_ICONES);
 | 
        
           |  |  | 111 | 		$GLOBALS['url']->addQueryString('id_document', $document->getIdDocument());
 | 
        
           |  |  | 112 | 		$GLOBALS['url']->addQueryString(PROJET_VARIABLE_SERVICE, 'telechargement');
 | 
        
           | 206 | alexandre_ | 113 | 		// json attend de l utf8, en lui fournissant des donnees au format htmlentities,
 | 
        
           |  |  | 114 | 		// ca passe
 | 
        
           | 234 | alexandre_ | 115 |   | 
        
           |  |  | 116 | 		// On regarde si l utilisateur a les droits pour deplacer
 | 
        
           |  |  | 117 | 		if ($droits <= PROJET_DROIT_COORDINATEUR ||
 | 
        
           |  |  | 118 | 			$GLOBALS['projet_auth']->getAuthData(PROJET_CHAMPS_ID) == $document->_id_proprietaire) {
 | 
        
           |  |  | 119 | 				$actions = 'MOVE,REMOVE,EDIT' ;
 | 
        
           |  |  | 120 | 				if ($document->isRepertoire()) $actions .= ',ADDCHILD';
 | 
        
           |  |  | 121 | 			}
 | 
        
           |  |  | 122 | 				else $actions = '';
 | 
        
           |  |  | 123 |   | 
        
           | 206 | alexandre_ | 124 |        $node = array(
 | 
        
           |  |  | 125 |           'title'=> htmlentities($document->getNomLong()),
 | 
        
           |  |  | 126 |           'widgetId' => 'document_'.$document->getIdDocument(),
 | 
        
           |  |  | 127 |           'objectId'=> $document->getIdDocument(),
 | 
        
           |  |  | 128 |           'isFolder'=> $document->isRepertoire(),
 | 
        
           | 234 | alexandre_ | 129 |           'link' => str_replace ('&', '&', $GLOBALS['url']->getURL()),
 | 
        
           | 206 | alexandre_ | 130 |           'childIconSrc' => $document->getCheminIcone(),
 | 
        
           |  |  | 131 |           'expandIcon' => PROJET_CHEMIN_ICONES.'folder-expanded.gif',
 | 
        
           | 234 | alexandre_ | 132 |           'afterLabel' => ' '.$document->getTailleFormatee(),
 | 
        
           | 206 | alexandre_ | 133 |        );
 | 
        
           | 234 | alexandre_ | 134 |        // On regarde si l utilisateur a les droits pour deplacer
 | 
        
           |  |  | 135 | 		if ($droits <= PROJET_DROIT_COORDINATEUR ||
 | 
        
           |  |  | 136 | 			$GLOBALS['projet_auth']->getAuthData(PROJET_CHAMPS_ID) == $document->_id_proprietaire) {
 | 
        
           |  |  | 137 | 				$actions = 'MOVE,REMOVE,EDIT' ;
 | 
        
           |  |  | 138 | 				if ($document->isRepertoire()) $actions .= ',ADDCHILD';
 | 
        
           |  |  | 139 | 				$node['actions'] = $actions;
 | 
        
           |  |  | 140 | 			}
 | 
        
           |  |  | 141 | 				else {
 | 
        
           |  |  | 142 | 					$node['actions'] = '';
 | 
        
           |  |  | 143 |   | 
        
           |  |  | 144 | 				}
 | 
        
           |  |  | 145 |        $nodeArray[$i] = $node;
 | 
        
           | 206 | alexandre_ | 146 |        $i++;
 | 
        
           |  |  | 147 |        unset ($document);
 | 
        
           |  |  | 148 |    }
 | 
        
           | 234 | alexandre_ | 149 |    if (!is_null($nodeArray)) {
 | 
        
           |  |  | 150 |    	header ('Content-type: json');
 | 
        
           |  |  | 151 |    	print $json->encode($nodeArray);
 | 
        
           |  |  | 152 |    	exit();
 | 
        
           |  |  | 153 |    }
 | 
        
           | 206 | alexandre_ | 154 | }
 | 
        
           |  |  | 155 |   | 
        
           |  |  | 156 |   | 
        
           |  |  | 157 |   | 
        
           |  |  | 158 |   | 
        
           |  |  | 159 |   | 
        
           |  |  | 160 | ?>
 |