home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2004 April
/
CMCD0404.ISO
/
Software
/
Freeware
/
Programare
/
groupoffice-com-2.01
/
modules
/
filesystem
/
treeview.inc
< prev
next >
Wrap
Text File
|
2004-03-08
|
8KB
|
268 lines
<?php
/*
Copyright Intermesh 2003
Author: Merijn Schering <mschering@intermesh.nl>
Version: 1.0 Release date: 08 July 2003
This program 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 of the License, or (at your
option) any later version.
*/
$image['mlastnode'] = '<img src="'.$GO_THEME->images['mlastnode'].'" border="0" height="22" width="16" />';
$image['emptylastnode'] = '<img src="'.$GO_THEME->images['emptylastnode'].'" border="0" height="22" width="16" />';
$image['plastnode'] = '<img src="'.$GO_THEME->images['plastnode'].'" border="0" height="22" width="16" />';
$image['mnode'] = '<img src="'.$GO_THEME->images['mnode'].'" border="0" height="22" width="16" />';
$image['emptynode'] = '<img src="'.$GO_THEME->images['emptynode'].'" border="0" height="22" width="16" />';
$image['pnode'] = '<img src="'.$GO_THEME->images['pnode'].'" border="0" height="22" width="16" />';
$image['vertline'] = '<img src="'.$GO_THEME->images['vertline'].'" border="0" height="22" width="16" />';
$image['blank'] = '<img src="'.$GO_THEME->images['blank'].'" border="0" height="22" width="16" />';
$image['group'] = '<img src="'.$GO_THEME->images['workgroup'].'" border="0" height="22" width="24" />';
$image['user'] = '<img src="'.$GO_THEME->images['workstation'].'" border="0" height="22" width="20" />';
$image['opened_folder'] = '<img src="'.$GO_THEME->images['folderopen'].'" border="0" height="22" width="24" />';
$image['closed_folder'] = '<img src="'.$GO_THEME->images['folderclosed'].'" border="0" height="22" width="24" />';
$image['opened_folder_shared'] = '<img src="'.$GO_THEME->images['shared_folder_open'].'" border="0" height="22" width="24" />';
$image['closed_folder_shared'] = '<img src="'.$GO_THEME->images['shared_folder_closed'].'" border="0" height="22" width="24" />';
function print_filesystem($folders, $images='', $arguments='')
{
global $image, $path, $GO_SECURITY;
$fs = new filesystem();
$count = count($folders);
for ($i=0;$i<$count;$i++)
{
if ($fs->has_read_permission($GO_SECURITY->user_id, $folders[$i]['path']))
{
$subfolders = $fs->get_folders($folders[$i]['path']);
$subfolders_count = count($subfolders);
$open = in_array($folders[$i]['path'], $_SESSION['expanded']);
}else
{
$subfolders = array();
$subfolders_count = 0;
$open = false;
}
if ($subfolders_count > 0)
{
if ($i < ($count-1))
{
$new_image = $image['vertline'];
$node = $open ? $image['mnode'] : $image['pnode'];
}else
{
$new_image = $image['blank'];
$node = $open ? $image['mlastnode'] : $image['plastnode'];
}
}else
{
if ($i < ($count-1))
{
$new_image = $image['vertline'];
$node = $image['emptynode'];
}else
{
$new_image = $image['blank'];
$node = $image['emptylastnode'];
}
}
if ($folders[$i]['path'] == $path)
{
if($fs->get_share($folders[$i]['path']))
{
$folder_image = $image['opened_folder_shared'];
}else
{
$folder_image = $image['opened_folder'];
}
}else
{
if($fs->get_share($folders[$i]['path']))
{
$folder_image = $image['closed_folder_shared'];
}else
{
$folder_image = $image['closed_folder'];
}
}
$short_name = cut_string($folders[$i]['name'], 30);
echo '<table border="0" cellpadding="0" cellspacing="0">';
echo '<tr><td nowrap><a href="'.$_SERVER['PHP_SELF'].'?path='.urlencode($path).'&expand_path='.urlencode($folders[$i]['path']).$arguments.'">'.$images.$node.'</a>'.$folder_image.'</td>';
echo '<td nowrap><a href="'.$_SERVER['PHP_SELF'].'?path='.urlencode($folders[$i]['path']).$arguments.'" title="'.$folders[$i]['name'].'">'.$short_name.'</a></td></tr></table>';
if ($open)
{
print_filesystem($subfolders, $images.$new_image, $arguments);
}
}
unset($fs);
}
if (!isset($_SESSION['expanded']))
{
$_SESSION['expanded'][]=-1;
}
//expand or collaps the expand id which is passed when a user clicks a node
if (isset($_REQUEST['expand_path']))
{
$expand_path = smartstrip($_REQUEST['expand_path']);
$key = array_search($expand_path, $_SESSION['expanded']);
if (!$key)
{
$_SESSION['expanded'][] = $expand_path;
}else
{
unset($_SESSION['expanded'][$key]);
}
}else
{
//always expand folder clicks
if (isset($path))
{
$key = array_search($path, $_SESSION['expanded']);
if (!$key)
{
$_SESSION['expanded'][] = $path;
}
}
}
//stay in search mode if search is clicked
if ($task == 'search')
{
$arguments = '&task=search';
}else
{
$arguments = '';
}
echo '<table border="0" cellpadding="0" cellspacing="0">';
echo '<tr><td nowrap><a href="'.$_SERVER['PHP_SELF'].'?path='.urlencode($home_path).$arguments.'">'.$image['user'].'</a></td>';
echo '<td nowrap><a href="'.$_SERVER['PHP_SELF'].'?path='.urlencode($home_path).$arguments.'">home</a></td></tr></table>';
$folder = array();
$folder['path'] = $home_path;
$folder['name'] = basename($folder['path']);
print_filesystem(array($folder),'',$arguments);
require_once($GO_CONFIG->class_path.'users.class.inc');
$users = new users();
$users_array = array();
foreach ( $fs->get_my_shares() as $sharer )
{
$users->get_user( $sharer );
if ($users->f('id') != $GO_SECURITY->user_id)
{
$user['id'] = $users->f('id');
$user['username'] = $users->f('username');
$middle_name = $users->f('middle_name') == '' ? '' : $users->f('middle_name').' ';
$user['name'] = $users->f('first_name').' '.$middle_name.$users->f('last_name');
$shared_folders = array();
if($open = in_array($sharer, $_SESSION['expanded']))
{
$share_count = $fs->get_shares($users->f('id'));
$shared_folders = array();
$had_permission = false;
while ($fs->next_record())
{
if (file_exists($fs->f('path')))
{
if (is_dir($fs->f('path')))
{
$is_sub_dir = isset($last_folder) ? $fs->is_sub_dir($fs->f('path'), $last_folder) : false;
if (!$had_permission || !$is_sub_dir)
{
if ($GO_SECURITY->has_permission($GO_SECURITY->user_id, $fs->f('acl_read')) || $GO_SECURITY->has_permission($GO_SECURITY->user_id, $fs->f('acl_write')))
{
$folder['path'] = $fs->f('path');
$folder['name'] = basename($folder['path']);
$folder['share_path'] = $folder['path'];
$shared_folders[] = $folder;
$had_permission = true;
}else
{
$had_permission = false;
$share_count--;
}
}else
{
$share_count--;
}
}else
{
$share_count--;
}
}else
{
$fs2 = new filesystem();
$fs2->delete_share($fs->f('path'));
$share_count--;
}
if (!$is_sub_dir)
{
$last_folder = $fs->f('path');
}
}
}
$user['shared_folders'] = $shared_folders;
$users_array[] = $user;
}
}
$counter = $count = count($users_array);
if ($count > 0)
{
echo '<table border="0" cellpadding="0" cellspacing="0">';
echo '<tr><td>'.$image['group'].'</td>';
echo '<td>'.$fbShares.'</td></tr></table>';
while($user = array_shift($users_array))
{
$open = in_array($user['id'], $_SESSION['expanded']);
$sign = $open ? 'm' : 'p';
$share_count = count($user['shared_folders']);
if ($counter > 1)
{ $leftside = $image['vertline'];
$node = $image[$sign.'node'];
}else
{
$leftside = $image['blank'];
$node = $image[$sign.'lastnode'];
}
$short_name = cut_string($user['name'], 30);
echo '<table border="0" cellpadding="0" cellspacing="0">';
echo '<tr><td nowrap><a href="'.$_SERVER['PHP_SELF'].'?path='.urlencode($path).'&expand_path='.urlencode($user['id']).$arguments.'" title="'.$user['name'].'">'.$node.$image['user'].'</a></td>';
echo '<td nowrap><a href="'.$_SERVER['PHP_SELF'].'?path='.urlencode($path).'&expand_path='.urlencode($user['id']).$arguments.'" title="'.$user['name'].'">'.$short_name.'</a></td></tr></table>';
if($open)
{
print_filesystem($user['shared_folders'], $leftside,$arguments);
}
$counter--;
}
}
?>