True,
'help' => True,
'view' => True,
'history' => True,
'edit' => True,
'download'=>True
);
//keep
var $bo;
var $t; //template object
var $dispath;
var $cwd;
var $lesspath;
var $readable_groups;
var $files_array;
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 $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;
var $path;
var $file;
var $sortby;
var $messages;
var $show_upload_boxes;
var $debug = false;
var $now;
function uifilemanager()
{
// error_reporting (8);
$this->now = date ('Y-m-d');
$this->bo = CreateObject('filemanager.bofilemanager');
$this->t = $GLOBALS['phpgw']->template;
// here local vars are created from the HTTP vars
@reset ($GLOBALS['HTTP_POST_VARS']);
while (list ($name,) = @each ($GLOBALS['HTTP_POST_VARS']))
{
$this->$name = $GLOBALS['HTTP_POST_VARS'][$name];
}
@reset ($GLOBALS['HTTP_GET_VARS']);
while (list ($name,) = @each ($GLOBALS['HTTP_GET_VARS']))
{
$$name = $GLOBALS['HTTP_GET_VARS'][$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', $GLOBALS['userinfo']['username']);
$pref->read_repository ();
// $GLOBALS['phpgw']->hooks->single ('add_def_pref', $GLOBALS['appname']);
$pref->save_repository (True);
$pref_array = $pref->read_repository ();
$this->prefs = $pref_array[$GLOBALS['appname']];
//always show name
$this->prefs[name] =1;
if ($this->prefs['viewinnewwin'])
{
$this->target = '_blank';
}
}
function index()
{
if ($noheader || $nofooter || ($this->download_x && (count ($this->fileman) > 0)))
{
$noheader = True;
$nofooter = True;
$noappheader= True;
$nonavbar=True;
}
else
{
$GLOBALS['phpgw_info']['flags'] = array
(
'currentapp' => 'filemanager',
'noheader' => $noheader,
'nonavbar' => $nonavbar,
'nofooter' => $nofooter,
'noappheader' => $noappheader,
'enable_browser_class' => True
);
$GLOBALS['phpgw']->common->phpgw_header();
}
// var_dump($GLOBALS[HTTP_POST_VARS]);
//var_dump($this->delete_x);
# 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->bo->vfs->pwd ();
if (!$this->path || $this->bo->vfs->pwd (array ('full' => False)) == '')
{
$this->path = $GLOBALS['homedir'];
}
}
$this->bo->vfs->cd (array ('string' => False, 'relatives' => array (RELATIVE_NONE), 'relative' => False));
$this->bo->vfs->cd (array ('string' => $this->path, 'relatives' => array (RELATIVE_NONE), 'relative' => False));
$pwd = $this->bo->vfs->pwd ();
if (!$this->cwd = substr ($this->path, strlen ($GLOBALS['homedir']) + 1))
{
$this->cwd = '/';
}
else
{
$this->cwd = substr ($pwd, strrpos ($pwd, '/') + 1);
}
$this->disppath = $this->path;
/* 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 = '/';
# Get their readable groups to be used throughout the script
$groups = array();
$groups = $GLOBALS['phpgw']->accounts->get_list ('groups');
$this->readable_groups = array();
while (list ($num, $account) = each ($groups))
{
if ($this->bo->vfs->acl_check (array ('owner_id' => $account['account_id'], 'operation' => PHPGW_ACL_READ)))
{
$this->readable_groups[$account['account_lid']] = Array('account_id' => $account['account_id'], 'account_name' => $account['account_lid']);
}
}
$this->groups_applications = array ();
while (list ($num, $group_array) = each ($this->readable_groups))
{
$group_id = $GLOBALS['phpgw']->accounts->name2id ($group_array['account_name']);
$applications = CreateObject('phpgwapi.applications', $group_id);
$this->groups_applications[$group_array['account_name']] = $applications->read_account_specific ();
}
# We determine if they're in their home directory or a group's directory,
# and set the VFS working_id appropriately
if ((preg_match ('+^'.$GLOBALS['fakebase'].'\/(.*)(\/|$)+U', $this->path, $matches)) && $matches[1] != $GLOBALS['userinfo']['account_lid'])
{
$this->bo->vfs->working_id = $GLOBALS['phpgw']->accounts->name2id ($matches[1]);
}
else
{
$this->bo->vfs->working_id = $GLOBALS['userinfo']['username'];
}
# FIXME # comment waht happens here
if ($this->path != $GLOBALS['homedir'] && $this->path != $GLOBALS['fakebase'] && $this->path != '/' && !$this->bo->vfs->acl_check (array ( 'string' => $this->path, 'relatives' => array (RELATIVE_NONE),'operation' => PHPGW_ACL_READ )))
{
$this->messages.= $GLOBALS['phpgw']->common->error_list (array (lang('You do not have access to %1', $this->path)));
$this->html_link ('/index.php','menuaction=filemanager.uifilemanager.index','path='.$GLOBALS['homedir'], lang('Go to your home directory'));
$GLOBALS['phpgw']->common->phpgw_footer ();
$GLOBALS['phpgw']->common->phpgw_exit ();
}
$GLOBALS['userinfo']['working_id'] = $this->bo->vfs->working_id;
$GLOBALS['userinfo']['working_lid'] = $GLOBALS['phpgw']->accounts->id2name ($GLOBALS['userinfo']['working_id']);
# If their home directory doesn't exist, we try to create it
# Same for group directories
if (($this->path == $GLOBALS['homedir']) && !$this->bo->vfs->file_exists ($pim_tmp_arr))
{
$this->bo->vfs->override_acl = 1;
if (!$this->bo->vfs->mkdir (array (
'string' => $GLOBALS['homedir'],
'relatives' => array (RELATIVE_NONE)
)))
{
$p = $this->bo->vfs->path_parts ($pim_tmp_arr);
$this->messages= $GLOBALS['phpgw']->common->error_list (array (
lang('Could not create directory %1',
$GLOBALS['homedir'] . ' (' . $p->real_full_path . ')'
)));
}
$this->bo->vfs->override_acl = 0;
}
# Verify path is real
if ($this->path != $GLOBALS['homedir'] && $this->path != '/' && $this->path != $GLOBALS['fakebase'])
{
if (!$this->bo->vfs->file_exists (array (
'string' => $this->path,
'relatives' => array (RELATIVE_NONE)
)))
{
$this->messages = $GLOBALS['phpgw']->common->error_list (array (lang('Directory %1 does not exist', $this->path)));
$this->html_link ('/index.php','menuaction=filemanager.uifilemanager.index','path='.$GLOBALS['homedir'], lang('Go to your home directory'));
$GLOBALS['phpgw']->common->phpgw_footer ();
$GLOBALS['phpgw']->common->phpgw_exit ();
}
}
/* Update if they request it, or one out of 20 page loads */
srand ((double) microtime() * 1000000);
if ($update || rand (0, 19) == 4)
{
$this->bo->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->bo->vfs->acl_check (array(
'string' => $this->path,
'relatives' => array (RELATIVE_NONE),
'operation' => PHPGW_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($this->messages) $this->messages='
'.$this->messages.'
';
$vars[messages]=$this->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->bo->file_attributes);
if($this->numoffiles>0)
{
while (list ($internal, $displayed) = each ($this->bo->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');
$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 != $GLOBALS['fakebase'] && $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 ($GLOBALS['filesdir']) && !$files['link_directory'])
{
#FIXME
$clickview = $GLOBALS['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'])
{
$tmp_arr=array(
'string' => $files['directory'] . '/' . $files['name'],
'relatives' => array (RELATIVE_NONE)
);
$size = $this->bo->vfs->get_size($tmp_arr);
$col_data=$this->bo->borkb ($size);
$this->t->set_var('col_data',$col_data);
$this->t->parse('columns','column',True);
}
# Date created
if ($this->prefs['created'])
{
$col_data=$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=$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'])
{
$this->t->set_var('col_data',$GLOBALS['phpgw']->accounts->id2name ($files['owner_id']));
$this->t->parse('columns','column',True);
}
# Creator name
if ($this->prefs['createdby_id'])
{
$this->html_table_col_begin ();
if ($files['createdby_id'])
{
$col_data=$GLOBALS['phpgw']->accounts->id2name ($files['createdby_id']);
}
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'])
{
$col_data=$GLOBALS['phpgw']->accounts->id2name ($files['modifiedby_id']);
}
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->bo->borkb ($usedspace, NULL, 1);
if ($this->path == $GLOBALS['homedir'] || $this->path == $GLOBALS['fakebase'])
{
$vars[lang_unused_space]=lang('Unused space');
$vars[unused_space]=$this->bo->borkb ($GLOBALS['userinfo']['hdspace'] - $usedspace, NULL, 1);
$tmp_arr=array (
'string' => $this->path,
'relatives' => array (RELATIVE_NONE)
);
$ls_array = $this->bo->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['phpgw']->common->phpgw_footer ();
$GLOBALS['phpgw']->common->phpgw_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 == $GLOBALS['fakebase'])
{
if (!$this->bo->vfs->file_exists (array ('string' => $GLOBALS['homedir'], 'relatives' => array (RELATIVE_NONE))))
{
$this->bo->vfs->mkdir (array ('string' => $GLOBALS['homedir'], 'relatives' => array (RELATIVE_NONE)));
}
$ls_array = $this->bo->vfs->ls (array ( 'string' => $GLOBALS['homedir'], 'relatives' => array (RELATIVE_NONE), 'checksubdirs' => False, 'nofiles' => True ) );
$this->files_array[] = $ls_array[0];
$this->numoffiles++;
reset ($this->readable_groups);
while (list ($num, $group_array) = each ($this->readable_groups))
{
# If the group doesn't have access to this app, we don't show it
if (!$this->groups_applications[$group_array['account_name']][$GLOBALS['appname']]['enabled'])
{
continue;
}
if (!$this->bo->vfs->file_exists (array ('string' => $GLOBALS['fakebase'].'/'.$group_array['account_name'],'relatives' => array (RELATIVE_NONE) )) )
{
$this->bo->vfs->override_acl = 1;
$this->bo->vfs->mkdir (array ( 'string' => $GLOBALS['fakebase'].'/'.$group_array['account_name'], 'relatives' => array (RELATIVE_NONE) ) );
$this->bo->vfs->override_acl = 0;
$this->bo->vfs->set_attributes (array ( 'string' => $GLOBALS['fakebase'].'/'.$group_array['account_name'], 'relatives' => array (RELATIVE_NONE), 'attributes' => array ( 'owner_id' => $group_array['account_id'], 'createdby_id' => $group_array['account_id'] ) ) );
}
$ls_array = $this->bo->vfs->ls (array ( 'string' => $GLOBALS['fakebase'].'/'.$group_array['account_name'], 'relatives' => array (RELATIVE_NONE), 'checksubdirs' => False, 'nofiles' => True ) );
$this->files_array[] = $ls_array[0];
$this->numoffiles++;
}
}
else
{
$ls_array = $this->bo->vfs->ls (array ( 'string' => $this->path, 'relatives' => array (RELATIVE_NONE), 'checksubdirs' => False, 'nofiles' => False, 'orderby' => $this->sortby ) );
if ($phpwh_debug)
{
echo '# of files found in "'.$this->path.'" : '.count($ls_array).' '."\n";
}
while (list ($num, $file_array) = each ($ls_array))
{
$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 ();
}
// end file count
}
function toolbar($type)
{
switch($type)
{
case 'location':
$toolbar='
';
$toolbar.='
';
$toolbar.='
';
// go up icon when we're not at the top
if ($this->path != '/')
{
$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 != $GLOBALS['homedir'])
{
$link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index','path='.$GLOBALS['homedir']);
$toolbar.=$this->buttonImage($link,'home',lang('go home'));
}
// reload button with this url
$link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->path);
$toolbar.=$this->buttonImage($link,'reload',lang('reload'));
$toolbar.='
'.lang('Location').': ';
//$toolbar.=' ';
$current_option='';
// selectbox for change/move/and copy to
$dirs_options=$this->all_other_directories_options();
$toolbar.='