Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1328 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
// +------------------------------------------------------------------------------------------------------+
22
// CVS : $Id: ecouteArbreFichier.php,v 1.1 2007-04-19 09:37:50 alexandre_tb Exp $
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
34
*@version       $Revision: 1.1 $
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
 
46
set_include_path(get_include_path() . PATH_SEPARATOR . '/home/alex/www/api/pear');
47
include_once ('../../../papyrus/configuration/pap_config.inc.php');
48
include_once ('../../../api/pear/DB.php');
49
include_once ('../../../api/json/JSON.php');
50
 
51
define ('PROJET_CHEMIN_APPLI','../');
52
define ('PROJET_CHEMIN_ICONES', "client/projet/icones/") ;
53
define ('PROJET_CHEMIN_CLASSES', PROJET_CHEMIN_APPLI.'classes/');//le chemin vers les fichiers propre à GSITE
54
define ('PROJET_CHEMIN_FONCTIONS', PROJET_CHEMIN_APPLI.'fonctions/') ;
55
define ('PROJET_CHEMIN_LIBRAIRIE','bibliotheque/');//le chemin de la librairie de fichier php
56
define ('PROJET_CHEMIN_FICHIER', PROJET_CHEMIN_APPLI.'fichiers/') ; // Chemin ou seront créer les dossiers
57
 
58
if (file_exists(PROJET_CHEMIN_CLASSES.'document.class.php')) {
59
	include_once (PROJET_CHEMIN_CLASSES.'document.class.php') ;
60
} else {
61
	echo 'impossible document_class';
62
}
63
if (file_exists(PROJET_CHEMIN_APPLI.'langues/pro_langue_fr.inc.php')) {
64
	include_once PROJET_CHEMIN_APPLI.'langues/pro_langue_fr.inc.php' ;
65
} else {
66
	echo 'impossible fichier de langue';
67
}
68
 
69
 
70
$GLOBALS['db'] = & DB::connect(PAP_DSN);
71
if (PEAR::isError($db)) {
72
    echo ($db->getMessage());
73
}
74
 
75
 
76
 // we're returning json
77
//header('Content-type: text/json');
78
 
79
$action = $_REQUEST["action"];
80
$data = $_REQUEST["data"];
81
$cache = $_REQUEST["dojo.preventCache"];
82
 
83
$data = str_replace("\\\"","\"",$data);
84
 
85
// instanciate a json-php instance
86
 
87
$json = new services_JSON();
88
 
89
if ( $action == "getChildren") {
90
    $jsonData = $json->decode($data);
91
    // get the node object
92
    $node = $jsonData->node;
93
}
94
 
95
function getChildren($node) {
96
   // setup the database connction
97
 
98
   // get the parent node
99
   $parent = $node->objectId;
100
	if (isset($_REQUEST['id_projet'])) $id_projet = $_REQUEST['id_projet'];
101
	if (preg_match ('/projet_([0-9]+)/', $node->objectId, $match)) $id_projet = $match[1];
102
   // correspondance entre l objectid de dojo et id_parent de projet_document
103
   if ( $parent == "root" || preg_match ('/projet_([0-9]+)/', $node->objectId, $match)) {
104
    	$id_parent = 0 ;
105
   } else {
106
   		$id_parent = $node->objectId;
107
   }
108
	$sql = 'select * from projet_documents where pd_pere='.$id_parent ;
109
	if (isset($id_projet)) $sql .= ' and pd_ce_projet='.$id_projet;
110
   // assemble the resulting rows into an array of node objects.
111
   // Each node object is represented in php by an associative array
112
   // the array of associative arrays will then be encoded in json and
113
   // returned back to the browser
114
   $resultat = $GLOBALS['db']->query($sql);
115
 
116
   if (DB::isError($resultat)) {
117
        die ("Echec de la requete<br />".$resultat->getMessage()."<br />".$resultat->getDebugInfo()) ;
118
   }
119
   $returnArray = array();
120
   $i = 0;
121
   while ( $ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
122
       $document = new document($ligne['pd_id'], $GLOBALS['db'], PROJET_CHEMIN_FICHIER, PROJET_CHEMIN_ICONES);
123
 
124
		// json attend de l utf8, en lui fournissant des donnees au format htmlentities,
125
		// ca passe
126
       $node = array(
127
          'title'=> htmlentities($document->getNomLong()),
128
          'widgetId' => 'document_'.$document->getIdDocument(),
129
          'objectId'=> $document->getIdDocument(),
130
          'isFolder'=> $document->isRepertoire(),
131
          'link' => $document->getChemin(),
132
          'childIconSrc' => $document->getCheminIcone(),
133
          'expandIcon' => PROJET_CHEMIN_ICONES.'folder-expanded.gif',
134
          'afterLabel' => ' '.$document->getTailleFormatee()
135
       );
136
       $returnArray[$i] = $node;
137
       $i++;
138
       unset ($document);
139
   }
140
   return $returnArray;
141
}
142
 
143
 
144
if ( $action == "getChildren") {
145
   $jsonData = $json->decode($data);
146
   // get the node object
147
   $node = $jsonData->node;
148
   $nodeArray = getChildren($node);
149
   if (!is_null($nodeArray)) print $json->encode($nodeArray);
150
}
151
 
152
 
153
 
154
 
155
 
156
?>