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