1 |
<?php |
2 |
// |
3 |
// Id: index.php,v 1.2 2003/01/30 17:43:42 cain Exp |
4 |
// $Id: index.php,v 1.2 2003/01/30 17:43:42 cain Exp $ |
5 |
// |
6 |
//ini_set('include_path',realpath(dirname(__FILE__).'/../../../').':'.realpath(dirname(__FILE__).'/../../../../includes').':'.ini_get('include_path')); |
7 |
//ini_set('error_reporting',E_ALL); |
8 |
|
9 |
################################################## |
10 |
# |
11 |
# init template engine |
12 |
# |
13 |
|
14 |
// you need the template class from http://sf.net/projects/simpltpl |
15 |
if (!@include('HTML/Template/Xipe.php')) { |
16 |
print 'sorry, you need the template class PEAR::HTML_Template_Xipe<br>'. |
17 |
'or if i have time i put the examples <a href="http://os.visionp.de/">here online</a>'; |
18 |
die(); |
19 |
} |
20 |
require_once('HTML/Template/Xipe/Filter/TagLib.php'); |
21 |
$options = array( 'templateDir' => dirname(__FILE__) ); |
22 |
$tpl = new HTML_Template_Xipe($options); |
23 |
|
24 |
require_once('HTML/Template/Xipe/Filter/Modifier.php'); |
25 |
$modifiers = new HTML_Template_Xipe_Filter_Modifier($tpl->options); |
26 |
$tpl->registerPrefilter(array(&$modifiers,'imgSrc'), |
27 |
array(dirname(__FILE__),'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']))); |
28 |
|
29 |
|
30 |
// session stuff to save the opened folders etc. |
31 |
session_start(); |
32 |
if(!session_is_registered('session')) |
33 |
{ |
34 |
$session = new stdClass; // standard PHP-class constructor |
35 |
session_register('session'); |
36 |
$session->data = array(); |
37 |
$session->use = 'Filesystem'; |
38 |
} |
39 |
else // since the class is read from the session it is not automatically made global |
40 |
{ |
41 |
$session = &$_SESSION['session']; |
42 |
} |
43 |
|
44 |
// set the source to use |
45 |
if( @$_REQUEST['use_DB'] ) |
46 |
$session->use = 'DB'; |
47 |
if( @$_REQUEST['use_Filesystem'] ) |
48 |
$session->use = 'Filesystem'; |
49 |
if( @$_REQUEST['use_XML'] ) |
50 |
$session->use = 'XML'; |
51 |
if( @$_REQUEST['use_Array'] ) |
52 |
$session->use = 'Array'; |
53 |
|
54 |
################################################## |
55 |
# |
56 |
# actual tree stuff |
57 |
# |
58 |
define('TABLE_TREE','Tree_Nested'); |
59 |
define('DB_DSN','mysql://root@localhost/test'); |
60 |
|
61 |
require_once('treeClass.php'); |
62 |
if( $session->use == 'DB' ) |
63 |
{ |
64 |
$options = array( 'table' => TABLE_TREE , 'order' => 'name'); |
65 |
$tree = new treeClass( 'DBnested' , DB_DSN , $options ); |
66 |
} |
67 |
if( $session->use == 'Filesystem' ) |
68 |
{ |
69 |
# to let it work on the filesystem :-) |
70 |
$options = array( 'order' => 'name'); |
71 |
$tree = new treeClass( 'Filesystem' , dirname(__FILE__).'/tmp' , $options ); |
72 |
} |
73 |
if( $session->use == 'XML' ) |
74 |
{ |
75 |
$tree = new treeClass( 'XML' , dirname(__FILE__).'/config.xml' ); |
76 |
} |
77 |
if( $session->use == 'Array' ) |
78 |
{ |
79 |
// the actual data for the tree, they have to have the given structure |
80 |
$arrayData = array( 'name'=>'Root', |
81 |
'children'=>array( |
82 |
array('name'=>'dir1'), |
83 |
array('name'=>'dir2', |
84 |
'children'=>array( |
85 |
array('name'=>'dir2_1'), |
86 |
array('name'=>'dir2_2'), |
87 |
) |
88 |
), |
89 |
array('name'=>'dir3') |
90 |
) |
91 |
); |
92 |
|
93 |
// any on an array |
94 |
$options = array( 'order' => 'name'); |
95 |
$tree = new treeClass( 'Array' , $arrayData , $options ); |
96 |
} |
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
if( PEAR::isError($res=$tree->setup()) ) |
103 |
{ |
104 |
$methodFailed = true; |
105 |
$results[] = $res; |
106 |
} |
107 |
|
108 |
$tree->setRemoveRecursively(); |
109 |
|
110 |
// detect action |
111 |
|
112 |
if( @$_REQUEST['action_copy'] || @$_REQUEST['action_copy_x'] || |
113 |
@$_REQUEST['action_cut'] || @$_REQUEST['action_cut_x'] ) |
114 |
{ |
115 |
if( @$_REQUEST['action_copy'] || @$_REQUEST['action_copy_x']) $session->action = 'copy'; |
116 |
if( @$_REQUEST['action_cut'] || @$_REQUEST['action_cut_x'] ) $session->action = 'cut'; |
117 |
|
118 |
if( is_array($_REQUEST['selectedNodes']) && sizeof($_REQUEST['selectedNodes'])) |
119 |
{ |
120 |
$session->data = $_REQUEST['selectedNodes']; |
121 |
} |
122 |
else |
123 |
{ |
124 |
$session->action = ''; |
125 |
} |
126 |
} |
127 |
|
128 |
if( @$_REQUEST['action_paste'] || @$_REQUEST['action_paste_x'] ) |
129 |
{ |
130 |
if( is_array($session->data) && sizeof($session->data)) |
131 |
{ |
132 |
if( $session->action == 'copy' ) |
133 |
{ |
134 |
if( is_array($_REQUEST['selectedNodes']) && sizeof($_REQUEST['selectedNodes'])) |
135 |
{ |
136 |
$dest = $_REQUEST['selectedNodes']; |
137 |
$sources = $session->data; |
138 |
foreach( $sources as $aSrc ) |
139 |
{ |
140 |
foreach( $dest as $aDest ) |
141 |
{ |
142 |
$methodCalls[] = "tree->copy( $aSrc , $aDest )"; |
143 |
$results[] = $tree->copy( $aSrc , $aDest ); |
144 |
} |
145 |
} |
146 |
|
147 |
#$results = 'Sorry COPY is not implemented yet :-('; |
148 |
$session->data = array(); |
149 |
unset($session->action); |
150 |
$tree->setup(); |
151 |
} |
152 |
else |
153 |
{ |
154 |
$methodFailed = true; |
155 |
$results = 'Please choose destination folder(s) to paste to!'; |
156 |
} |
157 |
} |
158 |
|
159 |
if( $session->action == 'cut') |
160 |
{ |
161 |
if( !$_REQUEST['moveDest'] ) |
162 |
{ |
163 |
$methodFailed = true; |
164 |
$results = 'Please choose a destination to paste to!'; |
165 |
} |
166 |
else |
167 |
{ |
168 |
foreach( $session->data as $aNodeId ) |
169 |
{ |
170 |
$methodCalls[] = "tree->move( $aNodeId , {$_REQUEST['moveDest']} )"; |
171 |
$results[] = $tree->move( $aNodeId , $_REQUEST['moveDest'] ); |
172 |
} |
173 |
$session->data = array(); |
174 |
unset($session->action); |
175 |
$tree->setup(); |
176 |
} |
177 |
} |
178 |
} |
179 |
} |
180 |
|
181 |
if( (@$_REQUEST['action_delete'] || @$_REQUEST['action_delete_x']) && |
182 |
is_array($_REQUEST['selectedNodes']) && sizeof($_REQUEST['selectedNodes']) ) |
183 |
{ |
184 |
$rootId = $tree->getRootId(); |
185 |
foreach( $_REQUEST['selectedNodes'] as $aNodeId ) |
186 |
{ |
187 |
if( $rootId == $aNodeId ) |
188 |
{ |
189 |
$methodCalls[] = 0; |
190 |
$results[] = 'Cant remove Root with this application!'; |
191 |
$methodFailed = true; |
192 |
} |
193 |
else |
194 |
{ |
195 |
$methodCalls[] = "tree->remove( $aNodeId )"; |
196 |
$res = $tree->remove( $aNodeId ); |
197 |
if(PEAR::isError($res)) |
198 |
$methodFailed = true; |
199 |
$results[] = $res; |
200 |
} |
201 |
} |
202 |
$session->data = array(); |
203 |
unset($session->action); |
204 |
$tree->setup(); |
205 |
} |
206 |
|
207 |
|
208 |
if( @$_REQUEST['action_add'] && |
209 |
is_array($_REQUEST['selectedNodes']) && sizeof($_REQUEST['selectedNodes']) && |
210 |
$_REQUEST['newFolder'] ) |
211 |
{ |
212 |
foreach( $_REQUEST['selectedNodes'] as $aNodeId ) |
213 |
{ |
214 |
$methodCalls[] = "tree->add( {$_REQUEST['newFolder']} , $aNodeId )"; |
215 |
$res = $tree->add( $_REQUEST['newFolder'] , $aNodeId ); |
216 |
if(PEAR::isError($res)) |
217 |
$methodFailed = true; |
218 |
$results[] = $res; |
219 |
} |
220 |
$session->data = array(); |
221 |
unset($session->action); |
222 |
$tree->setup(); |
223 |
} |
224 |
|
225 |
|
226 |
$allVisibleFolders = $tree->getAllVisible(); |
227 |
|
228 |
if( !@is_array($_REQUEST['selectedNodes']) ) |
229 |
$_REQUEST['selectedNodes'] = array(); |
230 |
|
231 |
################################################## |
232 |
# |
233 |
# show the template |
234 |
# |
235 |
$tpl->compile('index.tpl'); |
236 |
include($tpl->compiledTemplate); |
237 |
?> |