True,
'help' => True,
'view' => True,
'export'=> True,
'touch' => True,
'history' => True,
'edit' => True,
'fileModels'=>True,
'getReturnExecuteForm' => True,
'dir_ls' => True,
'get_permissions' => True,
'search' => True,
'uploadModel'=>True
);
//keep
var $bo;
var $vfs_functions;
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;
var $current_config;
var $dirs;
var $to;
var $changedir; // for switching dir.
var $cdtodir; // for switching dir.
var $newfile_or_dir;
var $newdir_x;
var $newfile_x;
var $createfile_var;
var $move_to_x;
var $copy_to_x;
var $edit_x;
var $edit_file;
var $edit_preview_x;
var $edit_save_x;
var $edit_save_done_x;
var $edit_cancel_x;
var $upload_x;
// this ones must be checked thorougly;
var $fileman = Array();
//var $fileman;
var $path;
var $file; // FIXME WHERE IS THIS FILLED?
var $sortby;
var $messages;
var $show_upload_boxes;
var $now;
function uifilemanager()
{
$this->messages = &$_SESSION['phpgw_info']['filemanager']['user']['messages'];
$GLOBALS['phpgw']->browser = CreateObject('phpgwapi.browser');
$this->now = date('Y-m-d');
$this->bo = CreateObject('filemanager.bofilemanager');
$this->vfs_functions = CreateObject('filemanager.vfs_functions');
$this->t = $GLOBALS['phpgw']->template;
$c = CreateObject('phpgwapi.config','filemanager');
$c->read_repository();
$this->current_config = $c->config_data;
// 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];
$this->$name = $GLOBALS['HTTP_GET_VARS'][$name];
}
$to_decode = array
(
'op' => array('op' => ''),
'path' => array('path' => ''),
'filename' => array('filename' => ''),
'file' => array('file' => ''),
'sortby' => array('sortby' => ''),
'messages' => array('messages' => ''),
'show_upload_boxes' => array('show_upload_boxes' => ''),
'to' => array('to' => '')
);
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->bo->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[$this->bo->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->bo->vfs->get_real_info(array('string' => $this->bo->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->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->fakebase, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
if($test[mime_type]!='Directory')
{
$this->bo->vfs->override_acl = 1;
$this->bo->vfs->mkdir(array(
'string' => $this->bo->fakebase,
'relatives' => array(RELATIVE_NONE)
));
$this->bo->vfs->override_acl = 0;
//test one more time
$test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->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[]= lang('Fake Base Dir did not exist, eGroupWare created a new one.');
}
}
$test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->homedir, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
if($test[mime_type]!='Directory')
{
$this->bo->vfs->override_acl = 1;
$this->bo->vfs->mkdir(array(
'string' => $this->bo->homedir,
'relatives' => array(RELATIVE_NONE)
));
$this->bo->vfs->set_quota(array(
'string' => $this->bo->homedir,
'relatives' => array(RELATIVE_NONE),
'new_quota' => $this->current_config['filemanager_quota_size']
));
$this->bo->vfs->override_acl = 0;
//test one more time
$test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->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[]= 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
}
}
}
function fileModels()
{
$GLOBALS['phpgw_info']['flags'] = array
(
'currentapp' => 'filemanager',
'noheader' => False,
'nonavbar' => False,
'nofooter' => False,
'noappheader' => False,
'enable_browser_class' => True
);
$GLOBALS['phpgw']->common->phpgw_header();
$this->t->set_file(array('models' => 'fileModels.tpl'));
$this->t->set_block('models','header','header');
$this->t->set_block('models','body','body');
$this->t->set_block('models','footer','footer');
$this->t->set_var('url_1', './index.php?menuaction=filemanager.uifilemanager.uploadModel&model=article');
$this->t->set_var('model_1','article');
$this->t->set_var('lang_1',lang('article'));
$this->t->set_var('url_2','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=calendar');
$this->t->set_var('model_2','calendar');
$this->t->set_var('lang_2',lang('calendar'));
$this->t->set_var('url_3','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=todo');
$this->t->set_var('model_3','todo');
$this->t->set_var('lang_3',lang('todo'));
$this->t->set_var('url_4','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=slide');
$this->t->set_var('model_4','slide');
$this->t->set_var('lang_4',lang('slide'));
$this->t->set_var('url_5','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=cards');
$this->t->set_var('model_5','cards');
$this->t->set_var('lang_5',lang('cards'));
$this->t->set_var('url_6','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=resume');
$this->t->set_var('model_6','resume');
$this->t->set_var('lang_6',lang('resume'));
$this->t->pparse('out','models');
}
function uploadModel(){
$GLOBALS['phpgw_info']['flags'] = array
(
'currentapp' => 'filemanager',
'noheader' => False,
'nonavbar' => False,
'nofooter' => False,
'noappheader' => False,
'enable_browser_class' => True
);
$GLOBALS['phpgw']->common->phpgw_header();
$filename = lang('new')."_".lang($this->model).rand(0,1000).".html";
$this->bo->vfs->cp(array(
'from'=> PHPGW_SERVER_ROOT . '/filemanager/templates/default/'.$this->model.'.html',
'to'=> $filename,
'relatives' => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
));
$this->bo->vfs->set_attributes(array(
'string'=> $filename,
'relatives' => array(RELATIVE_ALL),
'attributes'=> array(
'mime_type' => "text/html",
'comment' => ""
)
));
$this->filename = $filename;
$this->edit();
}
function index()
{
$GLOBALS['phpgw_info']['flags'] = array
(
'currentapp' => 'filemanager',
'noheader' => False,
'nonavbar' => False,
'nofooter' => False,
'noappheader' => False,
'enable_browser_class' => True
);
$GLOBALS['phpgw']->common->phpgw_header();
echo "";
echo "";
echo "";
echo "";
echo "";
include('load_lang.php');
# 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
###
// 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 = $this->bo->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($this->bo->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 = '/';
}
$this->update_groups();
$this->groups_applications = array();
foreach ($this->readable_groups as $value)
{
$applications = CreateObject('phpgwapi.applications', $value['account_id']);
$this->groups_applications[$value['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('+^'.$this->bo->fakebase.'\/(.*)(\/|$)+U', $this->path, $matches)) && $matches[1] != $this->bo->userinfo['account_lid']) //FIXME matches not defined
{
$this->bo->vfs->working_id = $GLOBALS['phpgw']->accounts->name2id($matches[1]);//FIXME matches not defined
}
else
{
$this->bo->vfs->working_id = $this->bo->userinfo['username'];
}
# Check available permissions for $this->path, so we can disable unusable operations in user interface
$path = explode('/',$this->path);
$owner_id = $this->bo->vfs->ownerOf($this->bo->fakebase,$path[2]);
$user_id = $GLOBALS['phpgw_info']['user']['account_id'];
if ($owner_id == $user_id)
{
$this->can_read = True;
$this->can_add = True;
$this->can_edit = True;
$this->can_delete = True;
$this->can_private = True;
}else
{
$acl = CreateObject ('phpgwapi.acl', $owner_id);
$acl->account_id = $owner_id;
$acl->read_repository();
$rights = $acl->get_rights($user_id);
$this->can_read = $rights & PHPGW_ACL_READ;
$this->can_add = $rights & PHPGW_ACL_ADD;
$this->can_edit = $rights & PHPGW_ACL_EDIT;
$this->can_delete = $rights & PHPGW_ACL_DELETE;
$this->can_private = $rights & PHPGW_ACL_PRIVATE;
}
# if is different path than home and no permission allowed
if($this->path != $this->bo->homedir && $this->path != $this->bo->fakebase && $this->path != '/' && !$this->can_read)
{
echo 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['phpgw']->common->phpgw_footer();
$GLOBALS['phpgw']->common->phpgw_exit();
}
$this->bo->userinfo['working_id'] = $this->bo->vfs->working_id;
$this->bo->userinfo['working_lid'] = $GLOBALS['phpgw']->accounts->id2name($this->bo->userinfo['working_id']);
# Verify path is real
if($this->path != $this->bo->homedir && $this->path != '/' && $this->path != $this->bo->fakebase)
{
if(!$this->bo->vfs->file_exists(array(
'string' => $this->path,
'relatives' => array(RELATIVE_NONE)
)))
{
$this->messages[] = lang('Error:').lang('Directory %1 does not exist', $this->path);
$this->html_link('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->bo->homedir, lang('Go to your home directory'));
$GLOBALS['phpgw']->common->phpgw_footer();
$GLOBALS['phpgw']->common->phpgw_exit();
}
}
/* Update the vfs */
if ($this->update_x == 'True')
{
$this->bo->vfs->update_real(array(
'string' => $this->path,
'relatives' => array(RELATIVE_ALL)
));
}
# Default is to sort by name
if(!$this->sortby)
{
$this->sortby = 'name';
}
# 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->upload_x || $this->show_upload_boxes)
{
$this->showUploadboxes();
}
elseif($this->copy_to_x)
{
$this->copyTo();
}
elseif($this->move_to_x)
{
$this->moveTo();
}
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();
}
else
{
$this->readFilesInfo();
$this->fileListing();
}
}
function get_permissions(){
/* get permissions */
if((preg_match('+^'.$this->bo->fakebase.'\/(.*)(\/|$)+U', $this->path, $matches)) && $matches[1] != $this->bo->userinfo['account_lid']) //FIXME matches not defined
{
$this->bo->vfs->working_id = $GLOBALS['phpgw']->accounts->name2id($matches[1]);//FIXME matches not defined
}
else
{
$this->bo->vfs->working_id = $this->bo->userinfo['username'];
}
# Check available permissions for $this->path, so we can disable unusable operations in user interface
$path = explode('/',$this->path);
$owner_id = $this->bo->vfs->ownerOf($this->bo->fakebase,$path[2]);
$user_id = $GLOBALS['phpgw_info']['user']['account_id'];
if ($owner_id == $user_id)
{
$rights = 31;
}else
{
$acl = CreateObject ('phpgwapi.acl', $owner_id);
$acl->account_id = $owner_id;
$acl->read_repository();
$rights = $acl->get_rights($user_id);
}
echo $rights;
}
function dir_ls()
{
reset($this->files_array);
$this->readFilesInfo();
for($i = 0; $i != $this->numoffiles; $i++)
{
$files = $this->files_array[$i];
if(!$this->prefs['dotfiles'] && ereg("^\.", $files['name']))
{
continue;
}
/* small keys to safe bandwidth */
$tuple['name'] = $files['name'];
$tuple['icon'] = $this->mime_icon($files['mime_type']);
$tuple['type'] = $files['type'];
$tuple['creatd'] = $this->vfs_functions->dateString2timeStamp($files['created']);
$tuple['modifd'] = $this->vfs_functions->dateString2timeStamp($files['modified']);
$tuple['size'] = $files['size'];
$tuple['mime'] = $files['mime_type'];
$tuple['pub'] = $files['type'];
$tuple['creatdby'] = $GLOBALS['phpgw']->accounts->id2name($files['createdby_id']);
$tuple['modifdby'] = $files['modifiedby_id']?$GLOBALS['phpgw']->accounts->id2name($files['modifiedby_id']):'';
$tuple['owner'] = $GLOBALS['phpgw']->accounts->id2name($files['owner_id']);
$tuple['comm'] = $files['comment'];
$tuple['vers'] = $files['version'];
$output[] = $tuple;
}
// TODO Order files directly into SQL
foreach ($output as $key => $row) {
$temp[$key] = strtoupper($row[$this->criteria]);
}
if ($this->otype == "1")
array_multisort($temp, SORT_ASC, $output);
else
array_multisort($temp, SORT_DESC, $output);
echo serialize($output);
}
function fileListing()
{
$this->t->set_file(array('filemanager_list_t' => 'main.tpl'));
$this->t->set_block('filemanager_list_t','filemanager_header','filemanager_header');
$this->t->set_block('filemanager_list_t','filemanager_footer','filemanager_footer');
if($this->numoffiles || $this->cwd)
{
$usedSpace = $this->bo->vfs->get_size(array(
'string' => $this->path,
'relatives' => array(RELATIVE_NONE)
));
$quota = $this->bo->vfs->get_quota(array(
'string' => $this->path
));
$vars[usedSpace]='';
$vars[quotaSize]='';
$vars[path]='';
$vars[css]='';
$vars[preferences]='';
$vars[script]='';
// create dir and file button
if($this->can_add)
{
//TODO : create folder with problems
//$toolbar3.=$this->toolButton('newdir','createdir',lang('Create Folder'));
$vars[new_button]=$this->toolButton('new','createfile',lang('New...'));
$vars[new_button].='';
}
else
$vars[new_button]='';
// reload button with this url
$vars[refresh_button]=$this->toolButton('reload','reload',lang('reload'));
// go up icon when we're not at the top, dont allow to go outside /home = fakebase
if($this->path != '/' && $this->path != $this->bo->fakebase)
{
$vars[tools_button] = $this->toolButton('tools','tools',lang('tools'));
}
else
$vars[tools_button] = "";
// selectbox for change/move/and copy to
$this->dirs=$this->all_other_directories();
foreach($this->dirs as $elem)
$vars[folders].='
'.$elem['name'].'';
$this->dirs=$this->all_other_directories();
foreach($this->dirs as $dir)
if((($dir['directory'] . $dir['name']) != $this->path) && $this->bo->vfs->file_exists(array('string' => $dir['directory'] . $dir['name'],'relatives' => array(RELATIVE_NONE))))
{
//FIXME replace the html_form_option function
$dirs_options .= $this->html_form_option($dir['directory'] . $dir['name'], $dir['directory'] . $dir['name']);
}
$toolbar.='';
$vars[toolbar1]=$toolbar;
if(count($this->messages)>0)
{
foreach($this->messages as $msg)
{
$messages.=''.$msg.'';
}
}
$this->messages = NULL;
$vars[messages]=$messages;
$this->t->set_var($vars);
$this->t->pparse('out','filemanager_header');
}
$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 == $this->bo->fakebase)
{
// FIXME this test can be removed
if(!$this->bo->vfs->file_exists(array('string' => $this->bo->homedir, 'relatives' => array(RELATIVE_NONE))))
{
$this->bo->vfs->mkdir(array('string' => $this->bo->homedir, 'relatives' => array(RELATIVE_NONE)));
}
$ls_array = $this->bo->vfs->ls(array(
'string' => $this->bo->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']][$this->bo->appname]['enabled'])
{
continue;
}
*/
if(!$this->bo->vfs->file_exists(array('string' => $this->bo->fakebase.'/'.$group_array['account_name'],'relatives' => array(RELATIVE_NONE))))
{
$this->bo->vfs->override_acl = 1;
$this->bo->vfs->mkdir(array(
'string' => $this->bo->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->bo->vfs->override_acl = 0;
$this->bo->vfs->set_attributes(array('string' => $this->bo->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' => $this->bo->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
));
while(list($num, $file_array) = each($ls_array))
{
$this->numoffiles++;
$this->files_array[] = $file_array;
}
}
if(!is_array($this->files_array))
{
$this->files_array = array();
}
// end file count
}
# Handle Moving Files and Directories
function moveTo()
{
if(!$this->to)
{
$this->messages[] = lang('Error:').lang('Could not move file because no destination directory is given ', $this->disppath.'/'.$file);
}
else
{
$this->to = $this->bo->fakebase.'/'.$this->to;
while(list($num, $file) = each($this->fileman))
{
if($this->bo->vfs->mv(array(
'from' => $file,
'to' => $this->to . '/' . $file,
'relatives' => array(RELATIVE_ALL, RELATIVE_NONE)
)))
{
$moved++;
$this->messages[]=lang('Moved %1 to %2', $this->disppath.'/'.$file, $this->to.'/'.$file);
}
else
{
$this->messages[] = lang('Error:').lang('Could not move %1 to %2', $this->disppath.'/'.$file, $this->to.'/'.$file);
}
}
}
if($moved)
{
$x=0;
}
$this->readFilesInfo();
$this->filelisting();
}
// Handle Copying of Files and Directories
function copyTo()
{
if(!$this->to)
{
$this->messages[] = lang('Error:').lang('Could not copy file because no destination directory is given ', $this->disppath.'/'.$file);
}
else
{
$this->to = $this->bo->fakebase.'/'.$this->to;
while(list($num, $file) = each($this->fileman))
{
if($this->bo->vfs->cp(array(
'from' => $file,
'to' => $this->to . '/' . $file,
'relatives' => array(RELATIVE_ALL, RELATIVE_NONE)
)))
{
$copied++;
$this->messages[] = lang('Copied %1 to %2', $this->disppath.'/'.$file, $this->to.'/'.$file);
}
else
{
$this->messages[] = lang('Error:').lang('Could not copy %1 to %2', $this->disppath.'/'.$file, $this->to.'/'.$file);
}
}
}
if($copied)
{
$x=0;
}
$this->readFilesInfo();
$this->filelisting();
}
function createdir()
{
if($this->newdir_x && $this->newfile_or_dir)
{
if($this->bo->badchar = $this->bo->bad_chars($this->newfile_or_dir, True, True))
{
$this->messages[]= lang('Error:').$this->bo->html_encode(lang('Directory names cannot contain "%1"', $badchar), 1);
}
/* TODO is this right or should it be a single $ ? */
if($$this->newfile_or_dir[strlen($this->newfile_or_dir)-1] == ' ' || $this->newfile_or_dir[0] == ' ')
{
$this->messages[]= lang('Error:').lang('Cannot create directory because it begins or ends in a space');
}
$ls_array = $this->bo->vfs->ls(array(
'string' => $this->path . '/' . $this->newfile_or_dir,
'relatives' => array(RELATIVE_NONE),
'checksubdirs' => False,
'nofiles' => True
));
$fileinfo = $ls_array[0];
if($fileinfo['name'])
{
if($fileinfo['mime_type'] != 'Directory')
{
$this->messages[]= lang('Error:').lang('%1 already exists as a file',$fileinfo['name']);
}
else
{
$this->messages[]= lang('Error:').lang('Directory %1 already exists', $fileinfo['name']);
}
}
else
{
if($this->bo->vfs->mkdir(array('string' => $this->newfile_or_dir)))
{
$this->messages[]=lang('Created directory %1', $this->disppath.'/'.$this->newfile_or_dir);
}
else
{
$this->messages[]=lang('Error:').lang('Could not create %1', $this->disppath.'/'.$this->newfile_or_dir);
}
}
$this->readFilesInfo();
$this->filelisting();
}
}
function getReturnExecuteForm(){
$response = $_SESSION['response'];
$_SESSION['response'] = null;
echo $response;
return;
}
function showUploadboxes()
{
$this->t->set_file(array('upload' => 'upload.tpl'));
$this->t->set_block('upload','upload_header','upload_header');
$this->t->set_block('upload','row','row');
$this->t->set_block('upload','upload_footer','upload_footer');
if($this->path != '/' && $this->path != $this->bo->fakebase && $this->can_add)
{
$vars[max_size]=lang('Note: Uploaded is limited to %1MB',($this->current_config['filemanager_Max_file_size']));
$vars[form_action]=$GLOBALS[phpgw]->link('/filemanager/inc/upload.php');
//$vars[form_action]=$GLOBALS[phpgw]->link('/index.php','menuaction=filemanager.uifilemanager.index');
$vars[path]=$this->path;
$vars[lang_file]=lang('File');
$vars[lang_comment]=lang('Comment');
$vars[num_upload_boxes]=1;
$this->t->set_var($vars);
$this->t->pparse('out','upload_header');
$this->t->set_var('row_tr_color',$tr_color);
$this->t->parse('rows','row');
$this->t->pparse('out','row');
$vars[lang_upload]=lang('Upload files');
$vars[change_upload_boxes].=lang('Show') . ' ';
$this->t->set_var($vars);
$this->t->pparse('out','upload_footer');
}
}
/* create textfile */
function createfile()
{
$this->filename=$this->newfile_or_dir;
if($this->filename)
{
if($badchar = $this->bo->bad_chars($this->filename, True, True))
{
$this->messages[] = lang('Error:').lang('File names cannot contain "%1"',$badchar);
$this->fileListing();
}
if($this->bo->vfs->file_exists(array(
'string'=> $this->filename,
'relatives' => array(RELATIVE_ALL)
)))
{
$this->messages[]= lang('Error:').lang('File %1 already exists. Please edit it or delete it first.', $this->filename);
$this->fileListing();
}
if($this->bo->vfs->touch(array(
'string' => $this->filename,
'relatives' => array(RELATIVE_ALL)
)))
{
$this->edit = 1;
$this->numoffiles++;
$this->edit();
}
else
{
$this->messages[]= lang('Error:').lang('File %1 could not be created.', $this->filename);
$this->fileListing();
}
}
}
# Handle Editing files
function edit()
{
if($this->filename)
{
if (! $this->vfs_functions->verifyLock($this->path.'/'.$this->filename,RELATIVE_NONE)){
echo $this->messages['0'];
$GLOBALS['phpgw']->redirect('/index.php');
//$GLOBALS['phpgw']->common->phpgw_exit();
}
$ls_array = $this->bo->vfs->ls(array(
'string' => $this->path.'/'.$this->filename,
'relatives' => array(RELATIVE_NONE),
'checksubdirs' => False,
'nofiles' => True
));
$this->bo->vfs->touch(array(
'string'=> $this->path.'/'.$this->filename,
'relatives' => array(RELATIVE_NONE)
));
if($ls_array[0]['mime_type'])
{
$mime_type = $ls_array[0]['mime_type'];
}
elseif($this->prefs['viewtextplain'])
{
$mime_type = 'text/plain';
}
$editable = array('','text/plain','text/csv','text/html','text/text','message/rfc822');
if(!in_array($mime_type,$editable)){
$this->messages[] = lang('Error:').lang('Impossible to edit this file');
$this->readFilesInfo();
$this->fileListing();
return;
}
}
$this->readFilesInfo();
if ($mime_type == 'text/html')
$this->t->set_file(array('filemanager_edit' => 'edit_html.tpl'));
else
$this->t->set_file(array('filemanager_edit' => 'edit_file.tpl'));
$this->t->set_block('filemanager_edit','row','row');
$vars[refresh_script] = "";
$vars[preview_content]='';
if($this->edit_file)
{
$this->edit_file_content = stripslashes($this->edit_file_content);
}
if($this->edit_preview_x)
{
$content = $this->edit_file_content;
$vars[lang_preview_of]=lang('Preview of %1', $this->path.'/'.$edit_file);
$vars[preview_content]=nl2br($content);
}
elseif($this->edit_save_x || $this->edit_save_done_x)
{
$content = $this->edit_file_content;
//die( $content);
if($this->bo->vfs->write(array(
'string' => $this->path.'/'.$this->edit_file,
'relatives' => array(RELATIVE_NONE),
'content' => $content
)))
{
$this->messages[]=lang('Saved %1', $this->path.'/'.$this->edit_file);
if($this->edit_save_done_x)
{
$this->readFilesInfo();
$this->fileListing();
exit;
}
}
else
{
$this->messages[]=lang('Could not save %1', $this->path.'/'.$this->edit_file);
}
}
# If we're in preview or save mode, we only show the file
# being previewed or saved
if($this->edit_file &&($this->filename != $this->edit_file))
{
continue;
}
if($this->filename && $this->bo->vfs->file_exists(array(
'string' => $this->filename,
'relatives' => array(RELATIVE_ALL)
)))
{
if($this->edit_file)
{
$content = stripslashes($this->edit_file_content);
}
else
{
$content = $this->bo->vfs->read(array('string' => $this->filename));
}
$vars[form_action]= $GLOBALS['phpgw']->link('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->path);
$vars[edit_file]=$this->filename;
# We need to include all of the fileman entries for each file's form,
# so we loop through again
for($i = 0; $i != $this->numoffiles; $i++)
{
if($this->filename) $value='value="'.$this->filename.'"';
$vars[filemans_hidden]='';
}
$vars[file_content]=$content;
$vars[buttonPreview]=$this->inputButton('edit_preview','edit_preview',lang('Preview %1', $this->bo->html_encode($this->fileman[$j], 1)));
$vars[buttonSave]=$this->inputButton('edit_save','save',lang('Save %1', $this->bo->html_encode($this->filename, 1)));
$vars[buttonDone]=$this->inputButton('edit_save_done','ok',lang('Save %1, and go back to file listing ', $this->bo->html_encode($this->filename, 1)));
$vars[buttonCancel]=$this->inputButton('edit_cancel','cancel',lang('Cancel editing %1 without saving', $this->bo->html_encode($this->filename, 1)));
if ($mime_type == 'text/html'){
$vars[fck_edit] = '
';
}
$this->t->set_var($vars);
$this->t->parse('rows','row');
$this->t->pparse('out','row');
}
}
function history()
{
if($this->file) // FIXME this-file is never defined
{
$journal_array = $this->bo->vfs->get_journal(array(
'string' => $this->file,//FIXME
'relatives' => array(RELATIVE_ALL)
));
if(is_array($journal_array))
{
$this->html_table_begin();
$this->html_table_row_begin();
$this->html_table_col_begin();
echo lang('Date');
$this->html_table_col_end();
$this->html_table_col_begin();
echo lang('Version');
$this->html_table_col_end();
$this->html_table_col_begin();
echo lang('Who');
$this->html_table_col_end();
$this->html_table_col_begin();
echo lang('Operation');
$this->html_table_col_end();
$this->html_table_row_end();
while(list($num, $journal_entry) = each($journal_array))
{
$this->html_table_row_begin();
$this->html_table_col_begin();
$this->bo->html_text($journal_entry['created'] . ' ');
$this->html_table_col_end();
$this->html_table_col_begin();
$this->bo->html_text($journal_entry['version'] . ' ' );
$this->html_table_col_end();
$this->html_table_col_begin();
$this->bo->html_text($GLOBALS['phpgw']->accounts->id2name($journal_entry['owner_id']) . ' ');
$this->html_table_col_end();
$this->html_table_col_begin();
$this->bo->html_text($journal_entry['comment']);
$this->html_table_col_end();
}
$this->html_table_end();
$GLOBALS['phpgw']->common->phpgw_footer();
$GLOBALS['phpgw']->common->phpgw_exit();
}
else
{
echo lang('No version history for this file/directory');
}
}
}
function view()
{
if (!$this->bo->vfs->acl_check(array(
'string' => $this->path,
'relatives' => array(RELATIVE_NONE),
'operation' => PHPGW_ACL_READ
)))
{
$this->messages[] = lang("You have no permission to access this file");
header('Location:'.$this->encode_href('inc/index.php?menuaction=filemanager.uifilemanager.index','&path='.base64_encode($this->bo->homedir)));
return;
}
if($this->file) //FIXME
{
$ls_array = $this->bo->vfs->ls(array(
'string' => $this->path.'/'.$this->file,//FIXME
'relatives' => array(RELATIVE_NONE),
'checksubdirs' => False,
'nofiles' => True
));
if($ls_array[0]['mime_type'])
{
$mime_type = $ls_array[0]['mime_type'];
}
elseif($this->prefs['viewtextplain'])
{
$mime_type = 'text/plain';
}
$viewable = array('','text/plain','text/csv','text/html','text/text');
if(in_array($mime_type,$viewable))
{
/*Note: if you put application/octet-stream you force download */
header('Content-type: ' . $mime_type);
header('Content-disposition: filename="' . addslashes($this->file) . '"');
Header("Pragma: public");
}
else
{
$GLOBALS['phpgw']->browser->content_header($this->file,$mime_type,$ls_array[0]['size']);
}
$this->bo->vfs->print_content(array(
'string' => $this->path.'/'.$this->file,
'relatives' => array(RELATIVE_NONE)
)
);
$GLOBALS['phpgw']->common->phpgw_exit();
}
}
function export(){
if($this->file)
{
$ls_array = $this->bo->vfs->ls(array(
'string' => $this->path.'/'.$this->file,
'relatives' => array(RELATIVE_NONE),
'checksubdirs' => False,
'nofiles' => True
));
/*$timestamp = $this->vfs_functions->dateString2timeStamp($ls_array[0]['modified']);
if (time() - $timestamp < 60 && $ls_array[0]['modifiedby_id'] != $GLOBALS['phpgw_info']['user']['account_id']);
{
// recently than last minute: someone is editing
}*/
$mime_type = $ls_array[0]['mime_type'];
$formats = array('text/html');
if(!in_array($mime_type,$formats)){
echo lang('Impossible to export this file');
return False;
}
$content = $this->bo->vfs->read(array('string' => $this->path.'/'.$this->file,
'relatives' => array(RELATIVE_NONE)
));
include_once('filemanager/tp/dompdf/dompdf_config.inc.php');
$dompdf = new DOMPDF();
$dompdf->load_html($content);
$dompdf->set_paper($this->prefs['pdf_paper_type'], $this->prefs['pdf_type']);
/* Would be nice to implement 'Title','Subject','Author','Creator','CreationDate'*/
$dompdf->render();
$dompdf->stream(strtok($this->file,'.').".pdf");
$GLOBALS['phpgw']->common->phpgw_exit();
}
}
//give back an array with all directories except current and dirs that are not accessable
function all_other_directories()
{
# First we get the directories in their home directory
$dirs = array();
$dirs[] = array('directory' => $this->bo->fakebase, 'name' => $this->bo->userinfo['account_lid']);
$tmp_arr=array(
'string' => $this->bo->homedir,
'relatives' => array(RELATIVE_NONE),
'checksubdirs' => True,
'mime_type' => 'Directory'
);
$ls_array = $this->bo->vfs->ls($tmp_arr);
while(list($num, $dir) = each($ls_array))
{
$dirs[] = $dir;
}
# Then we get the directories in their readable groups' home directories
reset($this->readable_groups);
while(list($num, $group_array) = each($this->readable_groups))
{
/* Don't list directories for groups that don't have access
if(!$this->groups_applications[$group_array['account_name']][$this->bo->appname]['enabled'])
{
] continue;
}*/
$dirs[] = array('directory' => $this->bo->fakebase, 'name' => $group_array['account_name']);
$tmp_arr=array(
'string' => $this->bo->fakebase.'/'.$group_array['account_name'],
'relatives' => array(RELATIVE_NONE),
'checksubdirs' => True,
'mime_type' => 'Directory'
);
$ls_array = $this->bo->vfs->ls($tmp_arr);
while(list($num, $dir) = each($ls_array))
{
$dirs[] = $dir;
}
}
reset($dirs);
while(list($num, $dir) = each($dirs))
{
if(!$dir['directory'])
{
continue;
}
# So we don't display //
if($dir['directory'] != '/')
{
$dir['directory'] .= '/';
}
$return[] = $dir;
}
return $return;
}
function update_groups()
{
# Get their readable groups to be used throughout the script
$acl = array();
$groups = array();
$acl = $GLOBALS['phpgw']->acl->get_ids_for_location($GLOBALS['phpgw_info']['user']['account_id'],1,'filemanager');
if (is_array($acl))
foreach($acl as $key => $value){
$info = array();
$info = $GLOBALS['phpgw']->accounts->get_account_data($value);
$groups[$key]['account_id'] = $value;
$groups[$key]['account_lid'] = $info[$value]['lid'];
$groups[$key]['account_name'] = $info[$value]['firstname'];
$groups[$key]['account_lastname'] = $info[$value]['lastname'];
$groups[$key]['account_fullname'] = $info[$value]['fullname'];
}
$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']);
}
}
}
function search()
{
/* TODO this is a primitive search */
$this->update_groups();
$this->dirs = $this->all_other_directories();
$path = $this->path;
if (strlen($this->text) > 3)
{
$this->text = strtoupper($this->text);
foreach($this->dirs as $elem)
{
$this->path = $elem['directory'].$elem['name'];
reset($this->files_array);
$this->readFilesInfo();
for($i = 0; $i < count($this->files_array); $i++)
{
$comment = strtoupper($this->files_array[$i]['comment']);
$name = strtoupper($this->files_array[$i]['name']);
if (strstr($name,$this->text) ||
strstr($comment,$this->text) )
$return[$this->files_array[$i]['directory'].$name] = $this->files_array[$i];
}
if (count($return) > 50)
{
$return = array_slice($return,0,50);
break;
}
}
}
echo serialize(array_values($return));
}
/* seek icon for mimetype else return an unknown icon */
function mime_icon($mime_type, $size=16)
{
if(!$mime_type) $mime_type='unknown';
$mime_type=str_replace ('/','_',$mime_type);
$img=$GLOBALS['phpgw']->common->image('filemanager','mime'.$size.'_'.strtolower($mime_type));
if(!$img) $img=$GLOBALS['phpgw']->common->image('filemanager','mime'.$size.'_unknown');
return $img;
}
function toolButton($link,$img='',$description='')
{
$image=$GLOBALS['phpgw']->common->image('filemanager','button_'.strtolower($img));
if($img)
{
return ''.$description.'';
}
}
function inputButton($name,$img='',$description='')
{
$image=$GLOBALS['phpgw']->common->image('filemanager','button_'.strtolower($img));
if($img)
{
return '