True,
'help' => True,
'view' => True,
'history' => True,
'edit' => True,
'download'=>True,
'search_tpl'=>True,
);
//keep
var $bo;
var $t;
//template object
/**
* instantiation of the etemplate as classenvariable
*
* @var etemplate
*/
var $tmpl;
var $search_options;
var $disppath;
var $cwd;
var $lesspath;
var $readable_groups;
var $files_array;
var $dirs_options;
var $numoffiles;
var $dispsep;
var $target;
var $prefs;//array
var $groups_applications;
//originally post_vars
// var $goto;
var $goto_x;
var $download_x;
var $todir;
var $changedir; // for switching dir.
var $cdtodir; // for switching dir.
// var $createdir;
var $newfile_or_dir;
var $newdir_x;
var $newfile_x;
var $createfile_var;
var $delete_x;
var $renamefiles;
var $rename_x;
var $move_to_x;
// var $copy_to;
var $copy_to_x;
var $edit_x;
var $edit_comments_x;
var $edit_file;
var $edit_preview_x;
var $edit_save_x;
var $edit_save_done_x;
var $edit_cancel_x;
var $comment_files;
var $upload_x;
var $uploadprocess;
// this ones must be checked thorougly;
var $fileman = Array();
//var $fileman;
var $path;
var $file; // FIXME WHERE IS THIS FILLED?
var $sortby;
var $messages = array();
var $show_upload_boxes;
//var $debug = false;
var $debug = false;
var $now;
function uifilemanager()
{
// discarded becouse of class extension
//$this->bo =& CreateObject('filemanager.bofilemanager');
$this->bofilemanager();
//KL begin 200703 searchtemplate
// etemplate stuff
$this->tmpl =& CreateObject('etemplate.etemplate');
$this->html =& $GLOBALS['egw']->html;
// this may be needed using etemplates
if(!@is_object($GLOBALS['egw']->js))
{
$GLOBALS['egw']->js =& CreateObject('phpgwapi.javascript');
}
//KL end 200703 searchtemplate
// error_reporting(8);
$GLOBALS['egw']->browser =& CreateObject('phpgwapi.browser');
$this->dateformat=$GLOBALS['egw_info']['user']['preferences']['common']['dateformat'];
//$this->now = date($this->dateformat);
$this->now = date('Y-m-d');
$this->t = $GLOBALS['egw']->template;
// here local vars are created from the HTTP vars
@reset($_POST);
while(list($name,) = @each($_POST))
{
$this->$name = $_POST[$name];
}
@reset($_GET);
while(list($name,) = @each($_GET))
{
$$name = $_GET[$name];
}
$to_decode = array
(
/*
Decode
'var' when 'avar' == 'value'
or
'var' when 'var' is set
*/
'op' => array('op' => ''),
'path' => array('path' => ''),
'file' => array('file' => ''),
'sortby' => array('sortby' => ''),
// 'fileman' => array('fileman' => ''),
'messages' => array('messages' => ''),
// 'help_name' => array('help_name' => ''),
// 'renamefiles' => array('renamefiles' => ''),
'comment_files' => array('comment_files' => ''),
'show_upload_boxes' => array('show_upload_boxes' => '')
);
reset($to_decode);
while(list($var, $conditions) = each($to_decode))
{
while(list($condvar, $condvalue) = each($conditions))
{
if(isset($$condvar) && ($condvar == $var || $$condvar == $condvalue))
{
if(is_array($$var))
{
$temp = array();
while(list($varkey, $varvalue) = each($$var))
{
if(is_int($varkey))
{
$temp[$varkey] = stripslashes(base64_decode(urldecode(($varvalue))));
}
else
{
$temp[stripslashes(base64_decode(urldecode(($varkey))))] = $varvalue;
}
}
$this->$var = $temp;
}
elseif(isset($$var))
{
$this->$var = stripslashes(base64_decode(urldecode($$var)));
}
}
}
}
// get appl. and user prefs
$pref =& CreateObject('phpgwapi.preferences', $this->userinfo['username']);
$pref->read_repository();
// $GLOBALS['egw']->hooks->single('add_def_pref', $GLOBALS['appname']);
$pref->save_repository(True);
$pref_array = $pref->read_repository();
$this->prefs = $pref_array[$this->appname]; //FIXME check appname var in _debug_array
//always show name
$this->prefs['name'] = 1;
if($this->prefs['viewinnewwin'])
{
$this->target = '_blank';
}
/*
Check for essential directories
admin must be able to disable these tests
*/
// check if basedir exist
$test=$this->vfs->get_real_info(array('string' => $this->basedir, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
if($test['mime_type'] != 'Directory')
{
die('Base directory does not exist, Ask adminstrator to check the global configuration.');
}
$test=$this->vfs->get_real_info(array('string' => $this->basedir.$this->fakebase, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
if($test['mime_type'] != 'Directory')
{
$this->vfs->override_acl = 1;
$this->vfs->mkdir(array(
'string' => $this->fakebase,
'relatives' => array(RELATIVE_NONE)
));
$this->vfs->override_acl = 0;
//test one more time
$test=$this->vfs->get_real_info(array('string' => $this->basedir.$this->fakebase, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
if($test['mime_type']!='Directory')
{
die('Fake Base directory does not exist and could not be created, please ask the administrator to check the global configuration.');
}
else
{
$this->messages[]= $GLOBALS['egw']->common->error_list(array(
lang('Fake Base Dir did not exist, eGroupWare created a new one.')
));
}
}
// die($this->homedir);
$test=$this->vfs->get_real_info(array('string' => $this->basedir.$this->homedir, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
if($test['mime_type'] != 'Directory')
{
$this->vfs->override_acl = 1;
$this->vfs->mkdir(array(
'string' => $this->homedir,
'relatives' => array(RELATIVE_NONE)
));
$this->vfs->override_acl = 0;
//test one more time
$test=$this->vfs->get_real_info(array('string' => $this->basedir.$this->homedir, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
if($test['mime_type'] != 'Directory')
{
die('Your Home Dir does not exist and could not be created, please ask the adminstrator to check the global configuration.');
}
else
{
$this->messages[]= $GLOBALS['egw']->common->error_list(array(
lang('Your Home Dir did not exist, eGroupWare created a new one.')
));
// FIXME we just created a fresh home dir so we know there nothing in it so we have to remove all existing content
}
}
$GLOBALS['uifilemanager'] =& $this; // make ourself available for ExecMethod of get_rows function
}
function index()
{
//echo "
call index
";
if ($_GET['action']=='search')
{
$this->search_tpl();
}
else
{
$this->index_2();
}
}
function index_2()
{
//echo "
call index_2
";
//_debug_array($this->tmpl);
$sessiondata = $this->read_sessiondata();
if($noheader || $nofooter || ($this->download_x && (count($this->fileman) > 0)))
{
$noheader = True;
$nofooter = True;
$noappheader= True;
$nonavbar= True;
}
else
{
$GLOBALS['egw_info']['flags'] = array
(
'currentapp' => 'filemanager',
'noheader' => $noheader,
'nonavbar' => $nonavbar,
'nofooter' => $nofooter,
'noappheader' => $noappheader,
'enable_browser_class' => True
);
$GLOBALS['egw']->common->egw_header();
}
# Page to process users
# Code is fairly hackish at the beginning, but it gets better
# Highly suggest turning wrapping off due to long SQL queries
###
# Some hacks to set and display directory paths correctly
###
/*
if($this->goto || $this->goto_x)
{
$this->path = $this->cdtodir;
}
*/
// new method for switching to a new dir.
if($this->changedir=='true' && $this->cdtodir || $this->goto_x)
{
$this->path = $this->cdtodir;
}
if(!$this->path)
{
$this->path = $this->vfs->pwd();
if(!$this->path || $this->vfs->pwd(array('full' => False)) == '')
{
$this->path = $this->homedir;
}
}
$this->vfs->cd(array('string' => False, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
$this->vfs->cd(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
$pwd = $this->vfs->pwd();
if(!$this->cwd = substr($this->path, strlen($this->homedir) + 1))
{
$this->cwd = '/';
}
else
{
$this->cwd = substr($pwd, strrpos($pwd, '/') + 1);
}
$this->disppath = $this->path;
$sessiondata['workingdir']="$this->disppath";
/* This just prevents // in some cases */
if($this->path == '/')
{
$this->dispsep = '';
}
else
{
$this->dispsep = '/';
}
if(!($this->lesspath = substr($this->path, 0, strrpos($this->path, '/'))))
{
$this->lesspath = '/';
}
//echo "
#$this->path#
";
# Get their readable groups to be used throughout the script
$groups = array();
$groups = $GLOBALS['egw']->accounts->get_list('groups');
$this->readable_groups = Array();
while(list($num, $account) = each($groups))
{
if($this->vfs->acl_check(array('owner_id' => $account['account_id'],'operation' => EGW_ACL_READ)))
{
$this->readable_groups[$account['account_lid']] = Array('account_id' => $account['account_id'], 'account_name' => $account['account_lid']);
}
}
$sessiondata['readable_groups']=$this->readable_groups;
$this->groups_applications = array();
while(list($num, $group_array) = each($this->readable_groups))
{
$group_id = $GLOBALS['egw']->accounts->name2id($group_array['account_name']);
$applications =& CreateObject('phpgwapi.applications', $group_id);
$this->groups_applications[$group_array['account_name']] = $applications->read_account_specific();
}
$sessiondata['groups_applications']=$this->groups_applications;
# We determine if they're in their home directory or a group's directory,
# and set the VFS working_id appropriately
if((preg_match('+^'.$this->fakebase.'\/(.*)(\/|$)+U', $this->path, $matches)) && $matches[1] != $this->userinfo['account_lid']) //FIXME matches not defined
{
$this->vfs->working_id = $GLOBALS['egw']->accounts->name2id($matches[1]);//FIXME matches not defined
}
else
{
$this->vfs->working_id = $this->userinfo['username'];
}
$this->save_sessiondata($sessiondata);
# FIXME # comment what happens here
if($this->path != $this->homedir && $this->path != $this->fakebase && $this->path != '/' && !$this->vfs->acl_check(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE),'operation' => EGW_ACL_READ)))
{
echo "
died for some reasons
";
$this->messages[]= $GLOBALS['egw']->common->error_list(array(lang('You do not have access to %1', $this->path)));
$this->html_link('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->homedir, lang('Go to your home directory'));
$GLOBALS['egw']->common->egw_footer();
$GLOBALS['egw']->common->egw_exit();
}
$this->userinfo['working_id'] = $this->vfs->working_id;
$this->userinfo['working_lid'] = $GLOBALS['egw']->accounts->id2name($this->userinfo['working_id']);
# If their home directory doesn't exist, we try to create it
# Same for group directories
// Moved to constructor
/*
if(($this->path == $this->homedir) && !$this->vfs->file_exists($pim_tmp_arr))
{
$this->vfs->override_acl = 1;
if(!$this->vfs->mkdir(array(
'string' => $this->homedir,
'relatives' => array(RELATIVE_NONE)
)))
{
$p = $this->vfs->path_parts($pim_tmp_arr);
$this->messages[]= $GLOBALS['egw']->common->error_list(array(
lang('Could not create directory %1',
$this->homedir . ' (' . $p->real_full_path . ')'
)));
}
$this->vfs->override_acl = 0;
}
*/
# Verify path is real
if($this->path != $this->homedir && $this->path != '/' && $this->path != $this->fakebase)
{
if(!$this->vfs->file_exists(array(
'string' => $this->path,
'relatives' => array(RELATIVE_NONE)
)))
{
echo "
died for some other reasons
";
$this->messages[] = $GLOBALS['egw']->common->error_list(array(lang('Directory %1 does not exist', $this->path)));
$this->html_link('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->homedir, lang('Go to your home directory'));
$GLOBALS['egw']->common->egw_footer();
$GLOBALS['egw']->common->egw_exit();
}
}
/* Update if they request it, or one out of 20 page loads */
srand((double) microtime() * 1000000);
if($_GET['update'] || rand(0, 19) == 4)
{
$this->vfs->update_real(array(
'string' => $this->path,
'relatives' => array(RELATIVE_NONE)
));
}
# Check available permissions for $this->path, so we can disable unusable operations in user interface
if($this->vfs->acl_check(array(
'string' => $this->path,
'relatives' => array(RELATIVE_NONE),
'operation' => EGW_ACL_ADD
)))
{
$this->can_add = True;
}
# Default is to sort by name
if(!$this->sortby)
{
$this->sortby = 'name';
}
if($this->debug)
{
$this->debug_filemanager();
}
# main action switch
// FIXME this will become a switch
if($this->newfile_x && $this->newfile_or_dir) // create new textfile
{
$this->createfile();
}
elseif($this->newfile_or_dir && $this->newdir_x)
{
$this->createdir();
}
elseif($this->uploadprocess)
{
$this->fileUpload();
}
elseif($this->upload_x || $this->show_upload_boxes)
{
$this->showUploadboxes();
}
elseif($this->copy_to_x)
{
$this->copyTo();
}
elseif($this->move_to_x)
{
$this->moveTo();
}
elseif($this->download_x)
{
$this->download();
}
elseif($this->renamefiles)
{
$this->rename();
}
elseif($this->comment_files)
{
$this->editComment();
}
elseif($this->edit_cancel_x)
{
$this->readFilesInfo();
$this->fileListing();
}
elseif($this->edit_x || $this->edit_preview_x || $this->edit_save_x || $this->edit_save_done_x)
{
$this->edit();
}
elseif($this->delete_x)
{
$this->delete();
}
else
{
$this->readFilesInfo();
$this->fileListing();
}
}
function fileListing()
{
$this->t->set_file(array('filemanager_list_t' => 'filelisting.tpl'));
$this->t->set_block('filemanager_list_t','filemanager_header','filemanager_header');
$this->t->set_block('filemanager_list_t','column','column');
$this->t->set_block('filemanager_list_t','row','row');
$this->t->set_block('filemanager_list_t','filemanager_footer','filemanager_footer');
$vars['form_action']=$this->encode_href('/index.php', 'menuaction=filemanager.uifilemanager.index','path='.$this->path);
if($this->numoffiles || $this->cwd)
{
while(list($num, $name) = each($this->prefs))
{
if($name)
{
$columns++;
}
}
$columns++;
$vars['toolbar0'] = $this->toolbar('location');
$vars['toolbar1'] = $this->toolbar('list_nav');
if(count($this->messages)>0)
{
foreach($this->messages as $msg)
{
$messages.='
'.$msg.'
';
}
}
$vars['messages'] = $messages;
$this->t->set_var($vars);
$this->t->pparse('out','filemanager_header');
###
# Start File Table Column Headers
# Reads values from $file_attributes array and preferences
###
$this->t->set_var('actions',lang('select'));
reset($this->file_attributes);
if($this->numoffiles>0)
{
while(list($internal, $displayed) = each($this->file_attributes))
{
if($this->prefs[$internal])
{
$col_data=''.$displayed.'';
$this->t->set_var('col_data',$col_data);
$this->t->parse('columns','column',True);
}
}
$this->t->set_var('row_tr_color','#dedede');
//kan dit weg?
$this->t->parse('rows','row');
$this->t->pparse('out','row');
}
else
{
$lang_nofiles=lang('No files in this directory.');
}
$vars['lang_no_files'] = $lang_nofiles;
if($this->prefs['dotdot'] && $this->prefs['name'] && $this->path != '/')
{
$this->t->set_var('actions','');
$link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->lesspath);
$col_data='';
$col_data.=' ..';
$this->t->set_var('col_data',$col_data);
$this->t->parse('columns','column');
if($this->prefs['mime_type'])
{
$col_data=lang('Directory');
$this->t->set_var('col_data',$col_data);
$this->t->parse('columns','column',True);
}
$this->t->set_var('row_tr_color',$tr_color);
$this->t->parse('rows','row');
$this->t->pparse('out','row');
}
# List all of the files, with their attributes
@reset($this->files_array);
for($i = 0; $i != $this->numoffiles; $i++)
{
$files = $this->files_array[$i];
if($this->rename_x || $this->edit_comments_x)
{
unset($this_selected);
unset($renamethis);
unset($edit_this_comment);
for($j = 0; $j != $this->numoffiles; $j++)
{
if($this->fileman[$j] == $files['name'])
{
$this_selected = 1;
break;
}
}
if($this->rename_x && $this_selected)
{
$renamethis = 1;
}
elseif($this->edit_comments_x && $this_selected)
{
$edit_this_comment = 1;
}
}
if(!$this->prefs['dotfiles'] && ereg("^\.", $files['name']))
{
continue;
}
# Checkboxes
//if(!$this->rename_x && !$this->edit_comments_x && $this->path != $this->fakebase && $this->path != '/')
if(!$this->rename_x && !$this->edit_comments_x && $this->path != '/')
{
$cbox='';
$this->t->set_var('actions',$cbox);
}
elseif($renamethis)
{
$cbox=$this->html_form_input('hidden', 'fileman[' . base64_encode($files['name']) . ']', $files['name'], NULL, NULL, 'checked');
$this->t->set_var('actions',$cbox);
}
else
{
$this->t->set_var('actions','');
}
# File name and icon
if($renamethis)
{
$col_data=$this->mime_icon($files['mime_type']);
$col_data.='';
}
else
{
if($files['mime_type'] == 'Directory')
{
$link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->path.$this->dispsep.$files['name']);
$icon=$this->mime_icon($files['mime_type']);
$col_data=''.$icon.' ';
$col_data.=''.$files['name'].' ';
}
else
{
if($this->prefs['viewonserver'] && isset($this->filesdir) && !$files['link_directory'])
{
#FIXME
$clickview = $this->filesdir.$pwd.'/'.$files['name'];
if($phpwh_debug)
{
echo 'Setting clickview = '.$clickview.' '."\n";
$this->html_link($clickview,'', '',$files['name'], 0, 1, 0, '');
}
}
else
{
$icon=$this->mime_icon($files['mime_type']);
$link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.view','file='.$files['name'].'&path='.$this->path);
$col_data=''.$icon.''.$files['name'].'';
}
}
}
$this->t->set_var('col_data',$col_data);
$this->t->parse('columns','column');
# MIME type
if($this->prefs['mime_type'])
{
$col_data=$files['mime_type'];
$this->t->set_var('col_data',$col_data);
$this->t->parse('columns','column',True);
}
# File size
if($this->prefs['size'])
{
// KL to fetch the size of the object here is just WRONG, since the array may be already sorted by size
//$tmp_arr=array(
// 'string' => $files['directory'] . '/' . $files['name'],
// 'relatives' => array(RELATIVE_NONE)
//;
//if($files['mime_type'] != 'Directory') $tmp_arr['checksubdirs'] = false;
//$size = $this->vfs->get_size($tmp_arr);
$size = $files['size'];
$col_data=$this->borkb($size);
$this->t->set_var('col_data',$col_data);
$this->t->parse('columns','column',True);
}
# Date created
if($this->prefs['created'])
{
$col_data=date($this->dateformat,strtotime($files['created']));
$this->t->set_var('col_data',$col_data);
$this->t->parse('columns','column',True);
}
# Date modified
if($this->prefs['modified'])
{
if($files['modified'] != '0000-00-00')
{
$col_data=date($this->dateformat,strtotime($files['modified']));
}
else
{
$col_data='';
}
$this->t->set_var('col_data',$col_data);
$this->t->parse('columns','column',True);
}
# Owner name
if($this->prefs['owner'])
{
// KL to fetch the name of the object here is just WRONG, since the array may be already sorted by id
//$this->t->set_var('col_data',$GLOBALS['egw']->accounts->id2name($files['owner_id']));
$this->t->set_var('col_data',$files['owner_name']);
$this->t->parse('columns','column',True);
}
# Creator name
if($this->prefs['createdby_id'])
{
$this->html_table_col_begin();
if($files['createdby_id'])
{
// KL to fetch the name of the object here is just WRONG, since the array may be already sorted by id
//$col_data=$GLOBALS['egw']->accounts->id2name($files['createdby_id']);
$col_data=$files['createdby_name'];
}
else $col_data='';
$this->t->set_var('col_data',$col_data);
$this->t->parse('columns','column',True);
}
# Modified by name
if($this->prefs['modifiedby_id'])
{
if($files['modifiedby_id'])
{
// KL to fetch the name of the object here is just WRONG, since the array may be already sorted by id
//$col_data=$GLOBALS['egw']->accounts->id2name($files['modifiedby_id']);
$col_data=$files['modifiedby_name'];
}
else $col_data='';
$this->t->set_var('col_data',$col_data);
$this->t->parse('columns','column',True);
}
# Application
if($this->prefs['app'])
{
$col_data=$files['app'];
$this->t->set_var('col_data',$col_data);
$this->t->parse('columns','column',True);
}
# Comment
if($this->prefs['comment'])
{
if($edit_this_comment)
{
$col_data='';
}
else
{
$col_data=$files['comment'];
}
$this->t->set_var('col_data',$col_data);
$this->t->parse('columns','column',True);
}
# Version
if($this->prefs['version'])
{
$link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.history','file='.$files['name'].'&path='.$this->path);
$col_data=''.$files['version'].'';
$this->t->set_var('col_data',$col_data);
$this->t->parse('columns','column',True);
}
if($files['mime_type'] == 'Directory')
{
$usedspace += $fileinfo[0];
}
else
{
$usedspace += $files['size'];
}
$this->t->set_var('row_tr_color','');
$this->t->parse('rows','row');
$this->t->pparse('out','row');
}
// when renaming or changing comments render extra sumbmit button
if($this->rename_x || $this->edit_comments_x)
{
$col_data=' ';
$this->t->set_var('col_data',$col_data);
$this->t->parse('columns','column');
$this->t->set_var('row_tr_color','');
$this->t->parse('rows','row');
$this->t->pparse('out','row');
}
}
// The file and directory information
$vars['lang_files_in_this_dir'] = lang('Files in this directory');
$vars['files_in_this_dir'] = $this->numoffiles;
$vars['lang_used_space'] = lang('Used space');
$vars['used_space'] = $this->borkb($usedspace, NULL, 1);
if($this->path == $this->homedir || $this->path == $this->fakebase)
{
$vars['lang_unused_space'] = lang('Unused space');
$vars['unused_space'] = $this->borkb($this->userinfo['hdspace'] - $usedspace, NULL, 1);
$tmp_arr=array(
'string' => $this->path,
'relatives' => array(RELATIVE_NONE)
);
$ls_array = $this->vfs->ls($tmp_arr);
$vars['lang_total_files'] = lang('Total Files');
$vars['total_files'] = count($ls_array);
}
$this->t->set_var($vars);
$this->t->pparse('out','filemanager_footer');
$GLOBALS['egw']->common->egw_footer();
$GLOBALS['egw']->common->egw_exit();
}
function readFilesInfo()
{
// start files info
# Read in file info from database to use in the rest of the script
# $fakebase is a special directory. In that directory, we list the user's
# home directory and the directories for the groups they're in
$this->numoffiles = 0;
if($this->path == $this->fakebase)
{
// FIXME this test can be removed
if(!$this->vfs->file_exists(array('string' => $this->homedir, 'relatives' => array(RELATIVE_NONE))))
{
$this->vfs->mkdir(array('string' => $this->homedir, 'relatives' => array(RELATIVE_NONE)));
}
reset($this->readable_groups);
// create the directorys of the readableGroups if they do not exist
while(list($num, $group_array) = each($this->readable_groups))
{
# If the group doesn't have access to this app, we don't show it, and do not appkly any action here
if(!$this->groups_applications[$group_array['account_name']][$this->appname]['enabled'])
{
continue;
}
if(!$this->vfs->file_exists(array('string' => $this->fakebase.'/'.$group_array['account_name'],'relatives' => array(RELATIVE_NONE))))
{
$this->vfs->override_acl = 1;
$this->vfs->mkdir(array(
'string' => $this->fakebase.'/'.$group_array['account_name'],
'relatives' => array(RELATIVE_NONE)
));
// FIXME we just created a fresh group dir so we know there nothing in it so we have to remove all existing content
$this->vfs->override_acl = 0;
$this->vfs->set_attributes(array('string' => $this->fakebase.'/'.$group_array['account_name'],'relatives' => array(RELATIVE_NONE),'attributes' => array('owner_id' => $group_array['account_id'],'createdby_id' => $group_array['account_id'])));
}
}
}
// read the list of the existing directorys/files
$ls_array = $this->vfs->ls(array(
'string' => $this->path,
'relatives' => array(RELATIVE_NONE),
'checksubdirs' => false,
'nofiles' => false,
'orderby' => $this->sortby
));
$heimatverz=explode('/',$this->homedir);
// process the list: check if we are allowed to read it, get the real size, and count the files/dirs
while(list($num, $file_array) = each($ls_array))
{
if($this->path == $this->fakebase)
{
if ($file_array['name'] && (array_key_exists($file_array['name'],$this->readable_groups) || $this->fakebase.'/'.$file_array['name'] == $this->homedir || $file_array['name'] == $heimatverz[2]))
{
if(!$this->groups_applications[$file_array['name']][$this->appname]['enabled'] && $this->fakebase.'/'.$file_array['name'] != $this->homedir && $file_array['name'] != $heimatverz[2])
{
continue;
}
}
if ($file_array['name'] && !array_key_exists($file_array['name'],$this->readable_groups) && !($this->fakebase.'/'.$file_array['name'] == $this->homedir || $file_array['name'] == $heimatverz[2]))
{
continue;
}
}
// get additional info, which was not retrieved meeting our needs -> size, ids
if($this->prefs['size'])
{
//KL get the real size of the object
$tmp_arr=array(
'string' => $file_array['directory'] . '/' . $file_array['name'],
'relatives' => array(RELATIVE_NONE)
);
if($file_array['mime_type'] != 'Directory') $tmp_arr['checksubdirs'] = false;
$file_array['size']=$this->vfs->get_size($tmp_arr);
// KL got the real size
}
if($this->prefs['owner'])
{
$file_array['owner_name']=$GLOBALS['egw']->accounts->id2name($file_array['owner_id']);
}
# Creator name
if($this->prefs['createdby_id'])
{
if($file_array['createdby_id'])
{
//$col_data=$GLOBALS['egw']->accounts->id2name($files['createdby_lid']);
$file_array['createdby_name']=$GLOBALS['egw']->accounts->id2name($file_array['createdby_id']);
}
else
{
$file_array['createdby_name']='';
}
}
# Modified by name
if($this->prefs['modifiedby_id'])
{
if($file_array['modifiedby_id'])
{
$file_array['modifiedby_name']=$GLOBALS['egw']->accounts->id2name($file_array['modifiedby_id']);
}
else
{
$file_array['modifiedby_name']='';
}
}
// got additional info
$this->numoffiles++;
$this->files_array[] = $file_array;
if($phpwh_debug)
{
echo 'Filename: '.$file_array['name'].' '."\n";
}
}
if( !is_array($this->files_array) )
{
$this->files_array = array();
}
else
{
// KL sorting by multisort, if sort-param is set.
if ($this->sortby)
{
$mysorting=$this->sortby;
if ($mysorting=='owner')
{
$mysorting='owner_name';
}
elseif ($mysorting=='createdby_id')
{
$mysorting='createdby_name';
}
elseif($mysorting=='modifiedby_id')
{
$mysorting='modifiedby_name';
}
foreach ($this->files_array as $key => $row) {
$file[$key] = $row[$mysorting];
}
// cast and sort file as container of the sort-key-column ascending to sort
// $files_array (as last Param), by the common key
array_multisort(array_map('strtolower',$file), SORT_ASC, $this->files_array);
}
// KL sorting done
}
}
function toolbar($type)
{
//echo "
call toolbar
";
switch($type)
{
case 'location':
$toolbar='
';
$toolbar.='
';
$toolbar.='
';
// go up icon when we're not at the top, dont allow to go outside /home = fakebase
if($this->path != '/' && $this->path != $this->fakebase)
{
$link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->lesspath);
$toolbar.=$this->buttonImage($link,'up',lang('go up'));
}
// go home icon when we're not home already
if($this->path != $this->homedir)
{
$link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->homedir);
$toolbar.=$this->buttonImage($link,'home',lang('go home'));
}
// reload button with this url
$link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index&update=1','path='.$this->path);
$toolbar.=$this->buttonImage($link,'reload',lang('reload'));
$toolbar.='
'.lang('Location').': ';
//$toolbar.=' ';
$current_option='';
// selectbox for change/move/and copy to
$this->dirs_options=$this->all_other_directories_options();
$toolbar.='
";
return($this->eor($rstring, $return));
}
function search_tpl($content=null)
{
//echo "
search_tpl
";
//_debug_array($content);
$debug=0;
$content['message']='';
if ($_GET['action']=='search')
{
$content['searchcreated']=1;
$content['datecreatedfrom']=date("U")-24*60*60;
$content['start_search']=lang('start search');
}
if ($content['start_search'] && strlen($content['start_search'])>0)
{
$searchactivated=1;
$read_onlys['searchstring']=true;
}
$content['nm']=$this->read_sessiondata('nm');
$this->search_options=$content['nm']['search_options'];
$content['nm']['search']=$content['searchstring'];
$debug=$content['debug'];
// initialisieren des nextmatch widgets, durch auslesen der sessiondaten
// wenn leer, bzw. kein array dann von hand initialisieren
$content['nm']=$this->read_sessiondata('nm');
$content['message'].= "
content may be set
";
if (!is_array($content['nm']))
{
$content['message'].= "
content is not set
";
$content['debug']=$debug;
$content['nm'] = array( // I = value set by the app, 0 = value on return / output
'get_rows' => 'filemanager.uifilemanager.get_rows', // I method/callback to request the data for the rows eg. 'notes.bo.get_rows'
'filter_label' => '', // I label for filter (optional)
'filter_help' => '', // I help-msg for filter (optional)
'no_filter' => True, // I disable the 1. filter
'no_filter2' => True, // I disable the 2. filter (params are the same as for filter)
'no_cat' => True, // I disable the cat-selectbox
//'template' => , // I template to use for the rows, if not set via options
//'header_left' => ,// I template to show left of the range-value, left-aligned (optional)
//'header_right' => ,// I template to show right of the range-value, right-aligned (optional)
//'bottom_too' => True, // I show the nextmatch-line (arrows, filters, search, ...) again after the rows
'never_hide' => True, // I never hide the nextmatch-line if less then maxmatch entrie
'lettersearch' => True,// I show a lettersearch
'searchletter' => false,// I0 active letter of the lettersearch or false for [all]
'start' => 0,// IO position in list
//'num_rows' => // IO number of rows to show, defaults to maxmatches from the general prefs
//'cat_id' => // IO category, if not 'no_cat' => True
//'search' => // IO search pattern
'order' => 'vfs_created',// IO name of the column to sort after (optional for the sortheaders)
'sort' => 'DESC',// IO direction of the sort: 'ASC' or 'DESC'
'col_filter' => array(),// IO array of column-name value pairs (optional for the filterheaders)
//'filter' => // IO filter, if not 'no_filter' => True
//'filter_no_lang' => True// I set no_lang for filter (=dont translate the options)
//'filter_onchange'=> 'this.form.submit();'// I onChange action for filter, default: this.form.submit();
//'filter2' => // IO filter2, if not 'no_filter2' => True
//'filter2_no_lang'=> True// I set no_lang for filter2 (=dont translate the options)
//'filter2_onchange'=> 'this.form.submit();'// I onChange action for filter, default: this.form.submit();
//'rows' => // O content set by callback
//'total' => // O the total number of entries
//'sel_options' => // O additional or changed sel_options set by the callback and merged into $tmpl->sel_options
'no_columnselection'=>false,
'default_cols' => '!vfs_file_id,fulldir,mime_type',
);
} else {
// lesen wenn gesetzt
$content['message'].= "
content is set
";
//_debug_print($content);
}
//echo " ";
// loeschen wenn gesetzt
if (($content['clear_search']&&strlen($content['clear_search'])>0) or $_GET['actioncd']=='clear')
{
$content['debug']=0;
$content['nm']['search_options']=array();
unset($content['nm']['search']);
$searchactivated=0;
$content['checkall']=0;
$content['checkonlyfiles']=0;
$content['checkonlydirs']=0;
$content['searchstring']='';
$content['searchcreated']=0;
$content['datecreatedto']='';
$content['datecreatedfrom']='';
$content['searchmodified']=0;
$content['datemodifiedto']='';
$content['datemodifiedfrom']='';
$read_onlys=array();
$this->search_options=array();
}
$sel_options = array(
'vfs_mime_type' => array('directory'=>'directory', ''=>'')
);
$this->tmpl->read('filemanager.search');
// the call of this function switches from enabled to disabled for various fields of the search dialog
//enable_disable_SearchFields($searchactivated);
//echo "
enable_disable_SearchFields
";
//echo "
".$content['datecreatedfrom']."
";
$switchflag=$searchactivated;
$this->tmpl->set_cell_attribute('checkall','disabled',$switchflag);
if ($content['checkall']) $this->tmpl->set_cell_attribute('alllabel','label',lang($this->tmpl->get_cell_attribute('alllabel','label')).'(x)');
$this->tmpl->set_cell_attribute('checkonlyfiles','disabled',$switchflag);
if ($content['checkonlyfiles']) $this->tmpl->set_cell_attribute('filelabel','label',lang($this->tmpl->get_cell_attribute('filelabel','label')).'(x)');
$this->tmpl->set_cell_attribute('checkonlydirs','disabled',$switchflag);
if ($content['checkonlydirs']) $this->tmpl->set_cell_attribute('dirlabel','label',lang($this->tmpl->get_cell_attribute('dirlabel','label')).'(x)');
$this->tmpl->set_cell_attribute('searchstring','disabled',$switchflag);
//search created date
if ($content['searchcreated'] or $content['datecreatedfrom']!='' or $content['datecreatedto']!='')
{
$content['searchcreated']=1;
$this->tmpl->set_cell_attribute('createdlabel','label',lang($this->tmpl->get_cell_attribute('createdlabel','label')).'(x)');
$read_onlys['datecreatedto']=$switchflag;
$read_onlys['datecreatedfrom']=$switchflag;
// the to-date is to be switched to the end of the day, so between a date and another one includes the to-date of the search
// the used database time function is a timestamp function, and a date converted turns out to be the beginning of the day
if ($content['datecreatedto']!='')
{
$content['datecreatedto']=$content['datecreatedto']+23*60*60+59;
}
if (($content['datecreatedfrom']=='' && $content['datecreatedto']) or ($content['datecreatedfrom'] && $content['datecreatedto']=='') ) $content['searchcreatedtext']=lang('Choosing only one date (from/to) will result in a search returning all entries older/younger than the entered date');
if (($content['datecreatedfrom']!='' && $content['datecreatedto']!='' && $content['datecreatedto']<$content['datecreatedfrom']) ) $content['searchcreatedtext']=lang('Choosing dates where to-date is smaller than the from-date, will result in a search returning all entries but thoose between the two entered dates');
}
else
{
$content['searchcreatedtext']='';
}
$this->tmpl->set_cell_attribute('searchcreated','disabled',$switchflag);
//search modified date
if ($content['searchmodified'] or $content['datemodifiedfrom']!='' or $content['datemodifiedto']!='')
{
$content['searchmodified']=1;
$this->tmpl->set_cell_attribute('modifiedlabel','label',lang($this->tmpl->get_cell_attribute('modifiedlabel','label')).'(x)');
$read_onlys['datemodifiedto']=$switchflag;
$read_onlys['datemodifiedfrom']=$switchflag;
// the to-date is to be switched to the end of the day, so between a date and another one includes the to-date of the search
// the used database time function is a timestamp function, and a date converted turns out to be the beginning of the day
if ($content['datemodifiedto']!='')
{
$content['datemodifiedto']=$content['datemodifiedto']+23*60*60+59;
}
if (($content['datemodifiedfrom']=='' && $content['datemodifiedto']) or ($content['datemodifiedfrom'] && $content['datemodifiedto']=='') ) $content['searchmodifiedtext']=lang('Choosing only one date (from/to) will result in a search returning all entries older/younger than the entered date');
if (($content['datemodifiedfrom']!='' && $content['datemodifiedto']!='' && $content['datemodifiedto']<$content['datemodifiedfrom']) ) $content['searchmodifiedtext']=lang('Choosing dates where to-date is smaller than the from-date, will result in a search returning all entries but thoose between the two entered dates');
}
else
{
$content['searchmodifiedtext']='';
}
$this->tmpl->set_cell_attribute('searchmodified','disabled',$switchflag);
$this->tmpl->set_cell_attribute('debuginfos','disabled',!$debug);
//_debug_array($content);
//echo "
";
echo $this->tmpl->exec('filemanager.uifilemanager.search_tpl',$content,$sel_options,$read_onlys,array('vfs_file_id'=>$this->data['vfs_file_id']));
// the debug info will be displayed at the very end of the page
//_debug_array($content);
}
/**
* the call of this function switches from enabled to disabled for various fields of the search dialog
*/
function enable_disable_SearchFields($switchflag)
{
//does not work at all. The calling of $this->tmpl returns nothing
return;
echo "
enable_disable_SearchFields
";
$this->tmpl->set_cell_attribute('checkall','disabled',$switchflag);
if ($content['checkall']) $this->tmpl->set_cell_attribute('alllabel','label',lang($this->tmpl->get_cell_attribute('alllabel','label')).'(x)');
$this->tmpl->set_cell_attribute('checkonlyfiles','disabled',$switchflag);
if ($content['checkonlyfiles']) $this->tmpl->set_cell_attribute('filelabel','label',lang($this->tmpl->get_cell_attribute('filelabel','label')).'(x)');
$this->tmpl->set_cell_attribute('checkonlydirs','disabled',$switchflag);
if ($content['checkonlydirs']) $this->tmpl->set_cell_attribute('dirlabel','label',lang($this->tmpl->get_cell_attribute('dirlabel','label')).'(x)');
$this->tmpl->set_cell_attribute('searchstring','disabled',$switchflag);
//return $template;
return true;
}
/**
* Saves state of the filemanager list in the session
*
* @param array $values
*/
function save_sessiondata($values,$key='')
{
if (strlen($key)>0)
{
$internalbuffer=$this->read_sessiondata();
$internalbuffer[$key]=$values;
$this->save_sessiondata($internalbuffer);
}
else
{
//echo "
\n";
$GLOBALS['egw']->session->appsession(@$this->called_by.'session_data','filemanager',$values);
}
}
/**
* reads list-state from the session
*
* @return array
*/
function read_sessiondata($key='')
{
$values = $GLOBALS['egw']->session->appsession(@$this->called_by.'session_data','filemanager');
if (strlen($key)>0)
{
return $values[$key];
}
else
{
return $values;
}
}
/**
* query rows for the nextmatch widget
*
* @param array $query with keys 'start', 'search', 'order', 'sort', 'col_filter'
* For other keys like 'filter', 'cat_id' you have to reimplement this method in a derived class.
* @param array &$rows returned rows/competitions
* @param array &$readonlys eg. to disable buttons based on acl, not use here, maybe in a derived class
* @param string $join='' sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or
* "LEFT JOIN table2 ON (x=y)", Note: there's no quoting done on $join!
* @param boolean $need_full_no_count=false If true an unlimited query is run to determine the total number of rows, default false
* @return int total number of rows
* optional not used here: $join='',$need_full_no_count=false
*/
function get_rows(&$query,&$rows,&$readonlys)
{
//echo "
retrieve rows
";
$startposition=$query['start'];
//$this->save_sessiondata($query);
$sessiondata = $this->read_sessiondata();
//_debug_array($sessiondata['dirs_options_array']);
//_debug_array($sessiondata['readable_groups']);
//_debug_array($sessiondata['groups_applications']);
if (!($this->search_options))
{
$sessiondata['start']=$startposition;
$this->search_options=$sessiondata['nm']['search_options'];
}
//_debug_array($this->search_options);
$additionalwhereclause=", (select vfs_file_id as fileid, ".$this->db->concat($this->db->concat("vfs_directory","'/'"),"vfs_name")." as fulldir from egw_vfs WHERE vfs_mime_type <> 'journal' and vfs_mime_type <> 'journal-deleted' and vfs_name is not null and vfs_name <>'' and vfs_name<>'home' and vfs_app='filemanager') vfs2 WHERE vfs2.fileid=egw_vfs.vfs_file_id";
//search options
if ($this->search_options['checkonlyfiles'] && !$this->search_options['checkonlydirs'])
{
$additionalwhereclause.=" and vfs_mime_type<>'directory' ";
}
elseif ($this->search_options['checkonlydirs'] && !$this->search_options['checkonlyfiles'])
{
$additionalwhereclause.=" and vfs_mime_type='directory' ";
}
elseif ($this->search_options['checkonlyfiles'] && $this->search_options['checkonlydirs'])
{
}
// timespecific search options
// search regarding the creation date
if ($this->search_options['searchcreated'] && $this->search_options['datecreatedfrom'] && ($this->search_options['datecreatedfrom']<=$this->search_options['datecreatedto'] or !($this->search_options['datecreatedto']) or ($this->search_options['datecreatedto']=='')))
{
$additionalwhereclause.=" and vfs_created >=".$this->db->FROM_UNIXTIME($this->search_options['datecreatedfrom']);
}
if ($this->search_options['searchcreated'] && $this->search_options['datecreatedto'] && ($this->search_options['datecreatedfrom']<=$this->search_options['datecreatedto'] or !($this->search_options['datecreatedfrom']) or ($this->search_options['datecreatedfrom']=='')))
{
$additionalwhereclause.=" and vfs_created <=".$this->db->FROM_UNIXTIME($this->search_options['datecreatedto']);
}
if ($this->search_options['searchcreated'] && $this->search_options['datecreatedto'] && $this->search_options['datecreatedfrom'] && ($this->search_options['datecreatedfrom']>$this->search_options['datecreatedto']))
{
$additionalwhereclause.=" and (vfs_created >=".$this->db->FROM_UNIXTIME($this->search_options['datecreatedfrom']);
$additionalwhereclause.=" or vfs_created <=".$this->db->FROM_UNIXTIME($this->search_options['datecreatedto']).")";
}
// search regarding the modification date
if ($this->search_options['searchmodified'] && $this->search_options['datemodifiedfrom'] && ($this->search_options['datemodifiedfrom']<=$this->search_options['datemodifiedto'] or !($this->search_options['datemodifiedto']) or ($this->search_options['datemodifiedto']=='')))
{
$additionalwhereclause.=" and vfs_modified >=".$this->db->FROM_UNIXTIME($this->search_options['datemodifiedfrom']);
}
if ($this->search_options['searchmodified'] && $this->search_options['datemodifiedto'] && ($this->search_options['datemodifiedfrom']<=$this->search_options['datemodifiedto'] or !($this->search_options['datemodifiedfrom']) or ($this->search_options['datemodifiedfrom']=='')))
{
$additionalwhereclause.=" and vfs_modified <=".$this->db->FROM_UNIXTIME($this->search_options['datemodifiedto']);
}
if ($this->search_options['searchmodified'] && $this->search_options['datemodifiedto'] && $this->search_options['datemodifiedfrom'] && ($this->search_options['datemodifiedfrom']>$this->search_options['datemodifiedto']))
{
$additionalwhereclause.=" and (vfs_modified >=".$this->db->FROM_UNIXTIME($this->search_options['datemodifiedfrom']);
$additionalwhereclause.=" or vfs_modified <=".$this->db->FROM_UNIXTIME($this->search_options['datemodifiedto']).")";
}
// only show contacts if the order-criteria starts with the given letter
if ($query['searchletter']!=false)
{
$additionalwhereclause .= " and ".($query['order']).' '.$GLOBALS['egw']->db->capabilities['case_insensitive_like'].' '.$GLOBALS['egw']->db->quote($query['searchletter'].'%');
}
else
{
//echo "
reset colfilter?!
";
$query['searchletter']=false;
}
// filter for allowed groups
$firstleveldirs[]=array();
$count_fld=0;
$or='';
$aclcondition=" ( ";
array_push($sessiondata['dirs_options_array'],$sessiondata['workingdir']);
foreach ($sessiondata['dirs_options_array'] as $dir)
{
$splitteddir=explode('/',$dir);
$nix=array_shift($splitteddir);
$vfsbase=array_shift($splitteddir);
$vfs1stleveldir=array_shift($splitteddir);
if (!in_array("/$vfsbase/$vfs1stleveldir", $firstleveldirs))
{
$count_fld++;
if ($count_fld>1) $or='or';
array_push($firstleveldirs,"/$vfsbase/$vfs1stleveldir");
$aclcondition.=" $or ".$this->db->concat($this->db->concat("vfs_directory","'/'"),vfs_name)." like '/$vfsbase/$vfs1stleveldir%' and vfs_mime_type='directory' ";
$aclcondition.=" or vfs_directory like '/$vfsbase/$vfs1stleveldir%' ";
//$aclcondition.=" or (vfs_directory='".implode('/',$splitteddir)."' and vfs_name='".$vfsname."')";
}
}
$aclcondition.=")";
if ($count_fld>0) $additionalwhereclause .= " and ".$aclcondition;
//echo "
$aclcondition
";
// save the nextmatch entrys/settings with the sessiondata
if (!$_POST['exec']['clear_search'])
{
$query['search_options']=$this->search_options;
}
else
{
//echo "
retrieve rows, clear search
";
unset($query['search']);
unset($query['start_search']);
$switchflag=0;
}
$this->save_sessiondata($query,'nm');
// defaultfilter we dont want journal, and a whole lot of other stuff excluded, so we use the Join part of get_rows to do that
// echo "
$additionalwhereclause
";
$rc=parent::get_rows($query,$rows,$readonlys, $additionalwhereclause);
//set the applicationheader
$GLOBALS['egw_info']['flags']['app_header'] = lang('filemanager');
foreach ($rows as $key => $row)
{
$rows[$key]['dir_link']='filemanager.uifilemanager.index&path='.urlencode(base64_encode($row['vfs_directory']));
if (strtolower($row['vfs_mime_type']) == 'directory')
{
$rows[$key]['file_link']='filemanager.uifilemanager.index&path='.urlencode(base64_encode($row['vfs_directory'].'/'.$row['vfs_name']));
}
else
{
$rows[$key]['file_link']='filemanager.uifilemanager.view&path='.urlencode(base64_encode($row['vfs_directory'])).'&file='.urlencode(base64_encode($row['vfs_name']));
}
$rows[$key]['icon'] = $this->mime_icon($row['vfs_mime_type'],16,true);
$rows[$key]['file'] = $row['vfs_directory'].'/'.$row['vfs_name'];
}
// add some info to the appheader that the user may be informed about the search-base of its query-result
if ($query['searchletter'])
{
$order = $order;
$GLOBALS['egw_info']['flags']['app_header'] .= ' - '.lang("%1 starts with '%2'",$order,$query['searchletter']);
}
if ($query['search'])
{
$GLOBALS['egw_info']['flags']['app_header'] .= ' - '.lang("Search for '%1'",$query['search']);
}
return $rc;
}
}