Subversion Repositories Applications.projet

Rev

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

<?php
/*vim: set expandtab tabstop=4 shiftwidth=4: */ 
// +------------------------------------------------------------------------------------------------------+
// | PHP version 4.1                                                                                      |
// +------------------------------------------------------------------------------------------------------+
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
// +------------------------------------------------------------------------------------------------------+
// | This library is free software; you can redistribute it and/or                                        |
// | modify it under the terms of the GNU General Public                                                  |
// | License as published by the Free Software Foundation; either                                         |
// | version 2.1 of the License, or (at your option) any later version.                                   |
// |                                                                                                      |
// | This library is distributed in the hope that it will be useful,                                      |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
// | General Public License for more details.                                                             |
// |                                                                                                      |
// | You should have received a copy of the GNU General Public                                            |
// | 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: ecouteArbreFichier.php,v 1.1 2007-04-19 09:37:50 alexandre_tb Exp $
/**
* Application projet
*
* Service d ecoute de l arbre du porte document, renvoie les donnees du repertoire demande
*
*@package projet
//Auteur original :
*@author        Alexandre Granier <alexandre@tela-botanica.org>
//Autres auteurs :
*@author        Aucun
*@copyright     Tela-Botanica 2000-2005
*@version       $Revision: 1.1 $
// +------------------------------------------------------------------------------------------------------+
*/

// +------------------------------------------------------------------------------------------------------+
// |                                            ENTETE du PROGRAMME                                       |
// +------------------------------------------------------------------------------------------------------+

// ATTENTION - le programme suivant doit renvoyer un tableau, meme vide
// sinon l arbre dojo ne fonctionnera pas (ligne 117 $returnArray = array)


set_include_path(get_include_path() . PATH_SEPARATOR . '/home/alex/www/api/pear');
include_once ('../../../papyrus/configuration/pap_config.inc.php');
include_once ('../../../api/pear/DB.php');
include_once ('../../../api/json/JSON.php');

define ('PROJET_CHEMIN_APPLI','../');
define ('PROJET_CHEMIN_ICONES', "client/projet/icones/") ;
define ('PROJET_CHEMIN_CLASSES', PROJET_CHEMIN_APPLI.'classes/');//le chemin vers les fichiers propre à GSITE
define ('PROJET_CHEMIN_FONCTIONS', PROJET_CHEMIN_APPLI.'fonctions/') ;
define ('PROJET_CHEMIN_LIBRAIRIE','bibliotheque/');//le chemin de la librairie de fichier php
define ('PROJET_CHEMIN_FICHIER', PROJET_CHEMIN_APPLI.'fichiers/') ; // Chemin ou seront créer les dossiers

if (file_exists(PROJET_CHEMIN_CLASSES.'document.class.php')) {
        include_once (PROJET_CHEMIN_CLASSES.'document.class.php') ;
} else {
        echo 'impossible document_class';
}
if (file_exists(PROJET_CHEMIN_APPLI.'langues/pro_langue_fr.inc.php')) {
        include_once PROJET_CHEMIN_APPLI.'langues/pro_langue_fr.inc.php' ;
} else {
        echo 'impossible fichier de langue';
}


$GLOBALS['db'] = & DB::connect(PAP_DSN);
if (PEAR::isError($db)) {
    echo ($db->getMessage());
}


 // we're returning json
//header('Content-type: text/json');

$action = $_REQUEST["action"];
$data = $_REQUEST["data"];
$cache = $_REQUEST["dojo.preventCache"];

$data = str_replace("\\\"","\"",$data);

// instanciate a json-php instance

$json = new services_JSON();

if ( $action == "getChildren") {
    $jsonData = $json->decode($data);
    // get the node object
    $node = $jsonData->node;
}

function getChildren($node) {
   // setup the database connction

   // get the parent node
   $parent = $node->objectId;
        if (isset($_REQUEST['id_projet'])) $id_projet = $_REQUEST['id_projet'];
        if (preg_match ('/projet_([0-9]+)/', $node->objectId, $match)) $id_projet = $match[1];
   // correspondance entre l objectid de dojo et id_parent de projet_document
   if ( $parent == "root" || preg_match ('/projet_([0-9]+)/', $node->objectId, $match)) {
        $id_parent = 0 ;
   } else {
                $id_parent = $node->objectId;
   }
        $sql = 'select * from projet_documents where pd_pere='.$id_parent ;
        if (isset($id_projet)) $sql .= ' and pd_ce_projet='.$id_projet;
   // assemble the resulting rows into an array of node objects.
   // Each node object is represented in php by an associative array
   // the array of associative arrays will then be encoded in json and
   // returned back to the browser
   $resultat = $GLOBALS['db']->query($sql);

   if (DB::isError($resultat)) {
        die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
   }
   $returnArray = array();
   $i = 0;
   while ( $ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
       $document = new document($ligne['pd_id'], $GLOBALS['db'], PROJET_CHEMIN_FICHIER, PROJET_CHEMIN_ICONES);

                // json attend de l utf8, en lui fournissant des donnees au format htmlentities,
                // ca passe
       $node = array(
          'title'=> htmlentities($document->getNomLong()),
          'widgetId' => 'document_'.$document->getIdDocument(),
          'objectId'=> $document->getIdDocument(),
          'isFolder'=> $document->isRepertoire(),
          'link' => $document->getChemin(),
          'childIconSrc' => $document->getCheminIcone(),
          'expandIcon' => PROJET_CHEMIN_ICONES.'folder-expanded.gif',
          'afterLabel' => ' '.$document->getTailleFormatee()
       );
       $returnArray[$i] = $node;
       $i++;
       unset ($document);
   }
   return $returnArray;
}


if ( $action == "getChildren") {
   $jsonData = $json->decode($data);
   // get the node object
   $node = $jsonData->node;
   $nodeArray = getChildren($node);
   if (!is_null($nodeArray)) print $json->encode($nodeArray);
}





?>