From 89cdd1b207d4d57907293e5b288c8fd27208c3f0 Mon Sep 17 00:00:00 2001 From: sim Date: Tue, 4 Mar 2003 00:04:06 +0000 Subject: [PATCH] A fairly large set of changes (committed all at once to reduce "broken" time): (1) Port to XSLT templates (2) Completes (apart from all the bugs :) the functionality of the three-teir phpgroupware style object system (no longer is filemanager a single 3000 line file!) (3) The beginings of a pluggable "uiaction" framework (ideally in the future this will be used for optional "rich text editors", or view filters etc) --- filemanager/inc/class.bofilemanager.inc.php | 366 +++++- filemanager/inc/class.uiaction_base.inc.php | 28 + filemanager/inc/class.uiaction_edit.inc.php | 185 +++ filemanager/inc/class.uiactions.inc.php | 50 + filemanager/inc/class.uifilemanager.inc.php | 1121 ++++++++++--------- 5 files changed, 1228 insertions(+), 522 deletions(-) create mode 100644 filemanager/inc/class.uiaction_base.inc.php create mode 100644 filemanager/inc/class.uiaction_edit.inc.php create mode 100644 filemanager/inc/class.uiactions.inc.php diff --git a/filemanager/inc/class.bofilemanager.inc.php b/filemanager/inc/class.bofilemanager.inc.php index 051e5e014b..737c7f1444 100755 --- a/filemanager/inc/class.bofilemanager.inc.php +++ b/filemanager/inc/class.bofilemanager.inc.php @@ -37,6 +37,9 @@ var $newfile; var $fileman = Array(); + var $changes = Array(); + var $upload_comment = Array(); + var $upload_file = Array(); var $op; var $file; var $help_name; @@ -74,14 +77,24 @@ 'todir', 'sortby', 'fileman', + 'upload_file', + 'upload_comment', + 'upload_name', 'messages', 'help_name', 'renamefiles', 'comment_files', 'show_upload_boxes', 'submit', + 'cancel', 'rename', + 'upload', + 'edit_comments', + 'apply_edit_comment', + 'apply_edit_name', + 'changes', 'delete', + 'edit', 'go', 'copy', 'move', @@ -152,13 +165,22 @@ if(!$this->path) { $this->path = $this->vfs->pwd(); - if (!$this->path || $this->vfs->pwd(False) == '') + if (!$this->path || $this->vfs->pwd(array( + 'full' => False + )) == '') { $this->path = $this->homedir; } } - $this->vfs->cd(False,False,Array(RELATIVE_NONE)); - $this->vfs->cd($this->path,False,Array(RELATIVE_NONE)); + $this->vfs->cd(array( + 'relative' => False, + 'relatives'=>Array(RELATIVE_NONE) + )); + $this->vfs->cd(array( + 'string' => $this->path, + 'relative' => False, + 'relatives' => Array(RELATIVE_NONE) + )); $this->pwd = $this->vfs->pwd(); @@ -200,8 +222,11 @@ . 'fakebase: '.$this->fakebase.'
' . 'homedir: '.$this->homedir.'

' . 'phpGW debug:
' - . 'real getabsolutepath: '.$this->vfs->getabsolutepath(False, False, False).'
' - . 'fake getabsolutepath: '.$this->vfs->getabsolutepath(False).'
' + . 'real cabsolutepath: '.$this->vfs->getabsolutepath(array( + 'string' => False, + 'fake' => False + )).'
' + . 'fake getabsolutepath: '.$this->vfs->getabsolutepath().'
' . 'appsession: '.$GLOBALS['phpgw']->session->appsession('vfs','').'
' . 'pwd: '.$this->vfs->pwd().'
'; } @@ -243,6 +268,20 @@ function initialize_vars($name) { $var = get_var($name,Array('GET','POST')); + + //to get the file uploads, without requiring register_globals in php.ini + if(phpversion() >= '4.2.0') + { + $meth = '_FILES'; + } + else + { + $meth = 'HTTP_POST_FILES'; + } + if(@isset($GLOBALS[$meth][$name])) + { + $var = $GLOBALS[$meth][$name]; + } if($this->debug) { echo ''."\n"; @@ -282,12 +321,23 @@ if ($this->path == $this->fakebase) { - if (!$this->vfs->file_exists($this->homedir,Array(RELATIVE_NONE))) + if (!$this->vfs->file_exists(array( + 'string' => $this->homedir, + 'relatives' =>Array(RELATIVE_NONE) + ))) { - $this->vfs->mkdir($this->homedir,Array(RELATIVE_NONE)); + $this->vfs->mkdir(array( + 'string' => $this->homedir, + 'relatives' => Array(RELATIVE_NONE) + )); } - $ls_array = $this->vfs->ls($this->homedir,Array(RELATIVE_NONE),False,False,True); + $ls_array = $this->vfs->ls(array( + 'string' => $this->homedir, + 'relatives' =>Array(RELATIVE_NONE), + 'checksubdirs' => False, + 'nofiles' => True + )); $this->files_array[] = $ls_array[0]; reset ($this->memberships); @@ -302,20 +352,40 @@ continue; } - if (!$this->vfs->file_exists($this->fakebase.'/'.$group_array['account_name'],Array(RELATIVE_NONE))) + if (!$this->vfs->file_exists(array( + 'string' => $this->fakebase.'/'.$group_array['account_name'], + 'relatives' => Array(RELATIVE_NONE) + ))) { - $this->vfs->mkdir($this->fakebase.'/'.$group_array['account_name'],Array(RELATIVE_NONE)); - $this->vfs->set_attributes($this->fakebase.'/'.$group_array['account_name'],Array(RELATIVE_NONE),Array('owner_id' => $group_array['account_id'], 'createdby_id' => $group_array['account_id'])); + $this->vfs->mkdir(array( + 'string' => $this->fakebase.'/'.$group_array['account_name'], + 'relatives' => Array(RELATIVE_NONE) + )); + $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']) + )); } - $ls_array = $this->vfs->ls($this->fakebase.'/'.$group_array['account_name'],Array(RELATIVE_NONE),False,False,True); + $ls_array = $this->vfs->ls(array( + 'string' => $this->fakebase.'/'.$group_array['account_name'], + 'relatives' => Array(RELATIVE_NONE), + 'checksubdirs' => False, + 'nofiles' => True + )); $this->files_array[] = $ls_array[0]; } } else { - $ls_array = $this->vfs->ls($this->path,Array(RELATIVE_NONE),False,False,False,$this->sortby); + $ls_array = $this->vfs->ls(array( + 'string' => $this->path, + 'relatives' => Array(RELATIVE_NONE), + 'checksubdirs' => False, + 'orderby' =>$this->sortby + )); if ($this->debug) { @@ -335,7 +405,6 @@ { $this->files_array = Array(); } - return $this->files_array; } @@ -360,6 +429,87 @@ { $this->path = $this->todir; } + function f_apply_edit_comment() + { + $result=''; + for ($i=0; $ifileman) ; $i++) + { + $file = $this->fileman[$i]; + + if (!$this->vfs->set_attributes (array ( + 'string' => $file, + 'relatives' => array (RELATIVE_ALL), + 'attributes' => array ( + 'comment' => stripslashes ($this->changes[$file]) + ) + ) + )) + { + $result .= lang(' Error: failed to change comment for :').$file."\n"; + } + } + + return $result; + } + + function f_apply_edit_name() + { + $result=''; + while (list ($from, $to) = each ($this->changes)) + { + if ($badchar = $this->bad_chars ($to, True, True)) + { + $result .= 'File names cannot contain "'.$badchar.'"'; + continue; + } + + if (ereg ("/", $to) || ereg ("\\\\", $to)) + { + //echo $GLOBALS['phpgw']->common->error_list (array ("File names cannot contain \\ or /")); + $result .= "File names cannot contain \\ or /"; + } + elseif (!$this->vfs->mv (array ( + 'from' => $from, + 'to' => $to + )) + ) + { + //echo $GLOBALS['phpgw']->common->error_list (array ('Could not rename '.$disppath.'/'.$from.' to '.$disppath.'/'.$to)); + $result .= 'Could not rename '.$this->path.'/'.$from.' to '.$this->path.'/'.$to; + } + else + { + $result .= 'Renamed '.$this->path.'/'.$from.' to '.$this->path.'/'.$to; + } + } + /*html_break (2); + html_link_back ();*/ + + + /*echo "f_apply_edit_name()"; + print_r($this->fileman); + echo '
'; + print_r($this->changes); + die(); + + $result=''; + for ($i=0; $ifileman) ; $i++) + { + $file = $this->fileman[$i]; + + if (!$this->vfs->mv (array ( + 'from' => $file, + 'relatives' => array (RELATIVE_ALL), + 'to' => $this->changes[$file] + ) + )) + { + $result .= lang(' Error: failed to rename :').$file."\n"; + } + } +*/ + return $result; + } function f_delete() { @@ -368,7 +518,12 @@ { if($this->fileman[$i]) { - $ls_array = $this->vfs->ls($this->path.SEP.$this->fileman[$i],Array(RELATIVE_NONE),False,False,True); + $ls_array = $this->vfs->ls(array( + 'string' => $this->path.SEP.$this->fileman[$i], + 'relatives' => Array(RELATIVE_NONE), + 'checksubdirs' =>False, + 'nofiles' => True + )); $fileinfo = $ls_array[0]; if($fileinfo) { @@ -380,7 +535,10 @@ { $mime_type = 'File'; } - if($this->vfs->delete($this->path.SEP.$this->fileman[$i],Array(RELATIVE_USER_NONE))) + if($this->vfs->delete(array( + 'string' => $this->path.SEP.$this->fileman[$i], + 'relatives' => Array(RELATIVE_USER_NONE) + ))) { $errors[] = ''.$mime_type.' Deleted: '.$this->path.SEP.$this->fileman[$i].''; } @@ -405,7 +563,11 @@ { if($this->fileman[$i]) { - if($this->vfs->cp($this->path.SEP.$this->fileman[$i],$this->todir.SEP.$this->fileman[$i],Array(RELATIVE_NONE,RELATIVE_NONE))) + if($this->vfs->cp(array( + 'from' => $this->path.SEP.$this->fileman[$i], + 'to' => $this->todir.SEP.$this->fileman[$i], + 'relatives' => Array(RELATIVE_NONE,RELATIVE_NONE) + ))) { $errors[] = 'File copied: '.$this->path.SEP.$this->fileman[$i].' to '.$this->todir.SEP.$this->fileman[$i].''; } @@ -425,7 +587,11 @@ { if($this->fileman[$i]) { - if($this->vfs->mv($this->path.SEP.$this->fileman[$i],$this->todir.SEP.$this->fileman[$i],Array(RELATIVE_NONE,RELATIVE_NONE))) + if($this->vfs->mv(array( + 'from' => $this->path.SEP.$this->fileman[$i], + 'to' => $this->todir.SEP.$this->fileman[$i], + 'relatives' => Array(RELATIVE_NONE,RELATIVE_NONE) + ))) { $errors[] = 'File moved: '.$this->path.SEP.$this->fileman[$i].' to '.$this->todir.SEP.$this->fileman[$i].''; } @@ -443,7 +609,10 @@ $numoffiles = count($this->fileman); for($i=0;$i!=$numoffiles;$i++) { - if($this->fileman[$i] && $this->vfs->file_exists($this->bo->path.SEP.$this->bo->fileman[$i],Array(RELATIVE_NONE))) + if($this->fileman[$i] && $this->vfs->file_exists(array( + 'string' => $this->bo->path.SEP.$this->bo->fileman[$i], + 'relatives' => Array(RELATIVE_NONE) + ))) { execmethod($this->appname.'.ui'.$this->appname.'.view_file', Array( @@ -477,7 +646,12 @@ return $errors; } - $ls_array = $this->vfs->ls($this->path.SEP.$this->createdir,Array(RELATIVE_NONE),False,False,True); + $ls_array = $this->vfs->ls(array( + 'string' => $this->path.SEP.$this->createdir, + 'relatives' => Array(RELATIVE_NONE), + 'checksubdirs' => False, + 'nofiles' => True + )); $fileinfo = $ls_array[0]; if ($fileinfo['name']) @@ -493,7 +667,10 @@ } else { - if ($this->vfs->mkdir($this->path.SEP.$this->createdir,Array(RELATIVE_NONE))) + if ($this->vfs->mkdir(array( + 'string' => $this->path.SEP.$this->createdir, + 'relatives' => Array(RELATIVE_NONE) + ))) { $errors[] = 'Created directory '.$this->path.SEP.$this->createdir.''; // $this->path = $this->path.SEP.$this->createdir; @@ -516,12 +693,18 @@ $errors[] = 'Filenames cannot contain "'.$badchar.'"'; return $errors; } - if($this->vfs->file_exists($this->path.SEP.$this->createfile,Array(RELATIVE_NONE))) + if($this->vfs->file_exists(array( + 'string' => $this->path.SEP.$this->createfile, + 'relatives' => Array(RELATIVE_NONE) + ))) { $errors[] = 'File '.$this->path.SEP.$this->createfile.' already exists. Please edit it or delete it first.'; return $errors; } - if(!$this->vfs->touch($this->path.SEP.$this->createfile,Array(RELATIVE_NONE))) + if(!$this->vfs->touch(array( + 'string' => $this->path.SEP.$this->createfile, + 'relatives' => Array(RELATIVE_NONE) + ))) { $errors[] = 'File '.$this->path.SEP.$this->createfile.' could not be created.'; } @@ -532,7 +715,144 @@ } return $errors; } + + function f_upload() + { + /* echo 'sub:'.$this->show_upload_boxes .' uf: '; + + print_r($this->upload_file); + echo ' cf: '; print_r($this->upload_comment); + echo ' files: '; print_r($HTTP_POST_FILES); + die();*/ + //echo (($show_upload_boxes > 1) ? $head_pre.$msg_top : $head_top); + for ($i = 0; $i != $this->show_upload_boxes; $i++) + { + if ($badchar = $this->bad_chars ($this->upload_file['name'][$i], True, True)) + { + array_push($err_msgs,$this->html_encode ('Filenames cannot contain "'.$badchar.'"', 1)); + //echo $GLOBALS['phpgw']->common->error_list (array (html_encode ('Filenames cannot contain "'.$badchar.'"', 1))); + continue; + } + + ### + # Check to see if the file exists in the database, and get its info at the same time + ### + + $ls_array = $this->vfs->ls (array ( + 'string' => $this->path . '/' . $this->upload_file['name'][$i], + 'relatives' => array (RELATIVE_NONE), + 'checksubdirs' => False, + 'nofiles' => True + ) + ); + + $fileinfo = $ls_array[0]; + + if ($fileinfo['name']) + { + if ($fileinfo['mime_type'] == 'Directory') + { + array_push($err_msgs,'Cannot replace '.$fileinfo['name'].' because it is a directory'); + //echo $GLOBALS['phpgw']->common->error_list (array ('Cannot replace '.$fileinfo['name'].' because it is a directory')); + continue; + } + } + + if ($this->upload_file['size'][$i] > 0) + { + if ($fileinfo['name'] && $fileinfo['deleteable'] != 'N') + { + if ( + $this->vfs->cp (array ( + 'from' => $this->upload_file['tmp_name'][$i], + 'to' => $this->upload_file['name'][$i], + 'relatives' => array (RELATIVE_NONE|VFS_REAL, RELATIVE_ALL) + ) + ) + ) { + $this->vfs->set_attributes (array ( + 'string' => $this->upload_file['name'][$i], + 'relatives' => array (RELATIVE_ALL), + 'attributes' => array ( + 'owner_id' => $GLOBALS['userinfo']['username'], + 'modifiedby_id' => $GLOBALS['userinfo']['username'], + 'modified' => $now, + 'size' => $this->upload_file['size'][$i], + 'mime_type' => $this->upload_file['type'][$i], + 'deleteable' => 'Y', + 'comment' => stripslashes ($upload_comment[$i]) + ) + ) + ); + + } else { + array_push($err_msgs,'Failed to upload file: '.$this->upload_file['name'][$i]); + continue; + } + + $result .=' Replaced '.$disppath.'/'.$this->upload_file['name'][$i].' '.$this->upload_file['size'][$i]; + } + else + { + if ( + $this->vfs->cp (array ( + 'from' => $this->upload_file['tmp_name'][$i], + 'to' => $this->upload_file['name'][$i], + 'relatives' => array (RELATIVE_NONE|VFS_REAL, RELATIVE_ALL) + ) + ) + ) { + + $this->vfs->set_attributes (array ( + 'string' => $this->upload_file['name'][$i], + 'relatives' => array (RELATIVE_ALL), + 'attributes' => array ( + 'mime_type' => $this->upload_file_['type'][$i], + 'comment' => stripslashes ($this->upload_comment[$i]) + ) + ) + ); + } else { + array_push($err_msgs,'Failed to upload file: '.$this->upload_file['name'][$i]); + continue; + } + $result .= 'Created '.$this->path.'/'.$this->upload_file['name'][$i] .' '. $this->upload_file['size'][$i]; + } + } + elseif ($this->upload_file['name'][$i]) + { + $this->vfs->touch (array ( + 'string' => $this->upload_file['name'][$i], + 'relatives' => array (RELATIVE_ALL) + ) + ); + + $this->vfs->set_attributes (array ( + 'string' => $this->upload_file['name'][$i], + 'relatives' => array (RELATIVE_ALL), + 'attributes' => array ( + 'mime_type' => $this->upload_file['type'][$i], + 'comment' => $this->upload_comment[$i] + ) + ) + ); + + $result .= 'Created '.$this->path.'/'.$this->upload_file['name'][$i].' '. $this->file_size[$i]; + } + } + + //output any error messages + // $backlink = ($show_upload_boxes > 1) ? 'Back to file manager' : html_link_back(1); + $refreshjs = ' + '; + +// if (sizeof($err_msgs)) echo $GLOBALS['phpgw']->common->error_list ($err_msgs,'Error',$backlink); + return $result.$err_msgs; + + } function load_help_info() { $this->help_info = Array( diff --git a/filemanager/inc/class.uiaction_base.inc.php b/filemanager/inc/class.uiaction_base.inc.php new file mode 100644 index 0000000000..94a775cac6 --- /dev/null +++ b/filemanager/inc/class.uiaction_base.inc.php @@ -0,0 +1,28 @@ +common->phpgw_header(); + } + + function action_link($action) + { + return $GLOBALS['phpgw']->link('/index.php', + Array( + 'menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.action', + 'path' => urlencode($this->bo->path), + 'uiaction' => urlencode($action) + ) + ); + + } + } + + +?> \ No newline at end of file diff --git a/filemanager/inc/class.uiaction_edit.inc.php b/filemanager/inc/class.uiaction_edit.inc.php new file mode 100644 index 0000000000..0612ddff31 --- /dev/null +++ b/filemanager/inc/class.uiaction_edit.inc.php @@ -0,0 +1,185 @@ + 'Edit', + 'edit_save' => false, + 'edit_preview' => false, + 'edit_cancel' => false + ); + + function uiaction_edit() + { + $this->bo = CreateObject('filemanager.bofilemanager'); + + $GLOBALS['phpgw']->xslttpl->add_file(array('widgets',$GLOBALS['phpgw']->common->get_tpl_dir('phpgwapi','default') . SEP . 'app_header')); + + $var = Array( + 'img_up' => array('widget' => array('type' => 'img', + 'src' => $GLOBALS['phpgw']->common->image($this->bo->appname,'up'), + 'alt' => lang('Up'), + 'link' => $GLOBALS['phpgw']->link('/index.php',Array( + 'menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.index', + 'path' => urlencode($this->bo->lesspath) + )) + )), + + 'img_home' => array('widget' => array('type' => 'img', + 'src' => $GLOBALS['phpgw']->common->image($this->bo->appname,'folder_home'), + 'alt' => lang('Folder'), + 'link' => $GLOBALS['phpgw']->link('/index.php',Array( + 'menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.index', + 'path' => urlencode($this->bo->homedir) + )) + )), + + 'dir' => $this->bo->path, + 'img_dir' => array('widget' => array('type' => 'img', + 'src' => $GLOBALS['phpgw']->common->image($this->bo->appname,'folder_large'), + 'alt' => lang('Folder') + )), + ); + $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('filemanager_nav' => $var)); + + $this->template_dir = $GLOBALS['phpgw']->common->get_tpl_dir($GLOBALS['phpgw_info']['flags']['currentapp']); + } + function edit($parent, $param=false) + { + + $GLOBALS['phpgw']->xslttpl->add_file(array('edit',$GLOBALS['phpgw']->common->get_tpl_dir('phpgwapi','default') . SEP . 'app_header')); + $GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('form_action' =>$GLOBALS['phpgw']->link('/index.php', + Array( + 'menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.action', + 'path' => $this->bo->path + ) + ))); + $this->load_header(); + $this->bo = &$parent->bo; + if (UIEDIT_DEBUG) echo ' action::edit '; +// $this->load_header(); + $edit_file = get_var('file', array('GET', 'POST')); + if (!strlen($edit_file)) + { + $edit_file = $this->bo->fileman[0]; + } + + +/* $this->bo->vfs->cd(array( + 'string' => $this->bo->path, + 'relatives' => array(RELATIVE_NONE) + )); + + // echo "path ".$this->bo->vfs->pwd()." Editing: ".$edit_file; +*/ + $vars = array(); + $vars['action1'][] = array('widget' => array('type' => 'img', + 'src' => $GLOBALS['phpgw']->common->image($this->bo->appname,'preview'), + )); + $vars['action1'][] = array('widget' => array('type' => 'submit', + 'name' => "uiaction_edit_preview", + 'value'=>lang('Preview') + )); + //$this->action_link('edit_preview'); + $vars['action2'][] = array('widget' => array('type' => 'img', + 'src' => $GLOBALS['phpgw']->common->image($this->bo->appname,'filesave'), + )); + $vars['action2'][] = array('widget' => array('type' => 'submit', + 'name' => 'uiaction_edit_save', + 'value'=>lang('Save') + )); + $vars['action3'][] = array('widget' => array('type' => 'img', + 'src' => $GLOBALS['phpgw']->common->image($this->bo->appname,'button_cancel'), + )); + + $vars['action3'][] = array('widget' => array('type' => 'submit', + 'name' => 'uiaction_edit_cancel', + 'value'=>lang('Close') + )); + $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('nav_data' => $vars)); + $vars = array('filename' => $edit_file); + + if (get_var('edited', array('GET', 'POST'))) + { + $content = get_var('edit_file_content', array('GET', 'POST')); + } + else + { + $content = $this->bo->vfs->read (array ('string' => $edit_file)); + } + + if ($param == 'edit_preview') + { + $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('preview'=>$content)); + // $vars['preview'] = nl2br($content); + } + + elseif ($param =='edit_save') + { + if ($this->bo->vfs->write (array ( + 'string' => $parent->bo->path.'/'.$edit_file , + 'relatives' => array(RELATIVE_NONE), + 'content' => $content + )) + ) + { + $vars['output'] = lang('Saved x', $parent->bo->path.'/'.$edit_file); + } + else + { + $vars['output'] = lang('Could not save x', $parent->bo->path.'/'.$edit_file); + } + } + + if ($edit_file && $this->bo->vfs->file_exists (array ( + 'string' => $edit_file, + 'relatives' => array (RELATIVE_ALL) + )) + ) + { + $vars['form_data'][] = array('widget' => array('type' => "hidden" , + 'name'=> "edited", + 'value'=>"1" + )); + + $vars['form_data'][] = array('widget' => array('type' => "hidden", + 'name' => 'edit_file', + 'value' => $edit_file + )); + + $vars['form_data'][] = array('widget' => array('type'=>"hidden", + 'name'=> "fileman[0]", + 'value' => $this->bo->html_encode($edit_file,1) + )); + $vars['file_content'] = $content; + } + //} + $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('filemanager_edit' => $vars)); + } + + function edit_cancel($parent) + { + $url = $GLOBALS['phpgw']->link('/index.php', + Array( + 'menuaction' => $parent->bo->appname.'.ui'.$parent->bo->appname.'.index', + 'path' => urlencode($parent->bo->path), + ) + ); + //echo "cancel : $url"; + header('Location: '. $url); + exit(); + } + function edit_save($parent) + { + $this->edit($parent, 'edit_save'); + } + + function edit_preview($parent) + { + $this->edit($parent, 'edit_preview'); + } + } +?> \ No newline at end of file diff --git a/filemanager/inc/class.uiactions.inc.php b/filemanager/inc/class.uiactions.inc.php new file mode 100644 index 0000000000..57a6fac29e --- /dev/null +++ b/filemanager/inc/class.uiactions.inc.php @@ -0,0 +1,50 @@ +'filemanager.uiaction_edit' + ); + var $actions = array(); + + function uiactions() + { + //Construct the action objects + foreach($this->action_classes as $action_class) + { + $o = CreateObject($action_class); + foreach ($o->actions as $name => $displayname) + { + $this->actions[$name] = &$o; + } + } + } + function run_action($parent, $action) + { + + + // print_r($this->actions); + $this->actions[$action]->$action($parent); + exit(); + } + function dispatch($parent) + { + //First, see if the action is specified in the url with a 'uiaction=' param + if ($action = get_var('uiaction', array('GET', 'POST'))) + { + $this->run_action($parent, $action); + } + @reset($_POST); + while(list($name,$value) = each($_POST)) + { + if (substr($name, 0 , 8) == 'uiaction') + { + $action = substr($name, 9); + $this->run_action($parent, $action); + + } + } + + } + } +?> diff --git a/filemanager/inc/class.uifilemanager.inc.php b/filemanager/inc/class.uifilemanager.inc.php index a570eef071..ef3c8bd80a 100755 --- a/filemanager/inc/class.uifilemanager.inc.php +++ b/filemanager/inc/class.uifilemanager.inc.php @@ -2,23 +2,19 @@ /**************************************************************************\ * phpGroupWare * * This file written by Mark A Peters (Skeeter) * - * This class user interface for the filemanager app * - * Copyright (C) 2002 Mark A Peters * - * -------------------------------------------------------------------------* - * This library is free software; you can redistribute it and/or modify it * - * under the terms of the GNU Lesser General Public License as published by * - * the Free Software Foundation; either version 2.1 of the License, * - * or any later version. * - * This library is distributed in the hope that it will be useful, but * - * WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License * - * along with this library; if not, write to the Free Software Foundation, * - * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + * Modified by Jonathon Sim for Zeald Ltd * + * User interface for the filemanager app * + * Copyright (C) 2002 Mark A Peters (C) 2003 Zeald Ltd * + * -------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; either version 2 of the License, or (at your * + * option) any later version. * \**************************************************************************/ + /* $Id$ */ + define('UI_DEBUG', 0); class uifilemanager { @@ -30,17 +26,51 @@ 'history' => True, 'view' => True, 'view_file' => True, - 'edit' => True + 'edit' => True, + 'rename' => True, + 'edit_comments' => True ); - + var $bo; var $nextmatchs; var $browser; var $template_dir; var $help_info; + var $mime_ico = array ( + 'application/pdf' => 'pdf', + 'application/postscript' => 'postscript', + 'application/msword' => 'word', + 'application/vnd.ms-excel' => 'excel', + 'application/vnd.ms-powerpoint' => 'ppt', + 'application/x-gzip' => 'tgz', + 'application/x-bzip' => 'tgz', + 'application/zip' => 'tgz', + 'application/x-debian-package' => 'deb', + 'application/x-rpm' => 'rpm', + 'application' => 'document', + 'application/octet-stream' => 'unknown', + 'audio' => 'sound', + 'audio/mpeg' => 'sound', + 'Directory' => 'folder', + 'exe' => 'exe', + 'image' => 'image', + 'text' => 'txt', + 'text/html' => 'html', + 'text/plain' => 'txt', + 'text/xml' => 'html', + 'text/x-vcalendar' => 'vcalendar', + 'text/calendar' => 'vcalendar', + 'text/x-vcard' => 'vcard', + 'text/x-tex' => 'tex', + 'unknown' => 'unknown', + 'video' => 'video', + 'message' => 'message' +); function uifilemanager() { + $GLOBALS['phpgw_info']['flags']['xslt_app'] = True; + $this->actions = CreateObject('filemanager.uiactions'); $this->bo = CreateObject('filemanager.bofilemanager'); $this->nextmatchs = CreateObject('phpgwapi.nextmatchs'); $this->browser = CreateObject('phpgwapi.browser'); @@ -49,6 +79,8 @@ $this->create_home_dir(); $this->verify_path(); $this->update(); + $GLOBALS['phpgw']->xslttpl->add_file(array('widgets',$GLOBALS['phpgw']->common->get_tpl_dir('phpgwapi','default') . SEP . 'app_header')); + } function load_header() @@ -62,7 +94,10 @@ function check_access() { - if($this->bo->path != $this->bo->homedir && $this->bo->path != $this->bo->fakebase && $this->bo->path != '/' && !$this->bo->vfs->acl_check($this->bo->path,Array(RELATIVE_NONE),PHPGW_ACL_READ)) + if($this->bo->path != $this->bo->homedir && $this->bo->path != $this->bo->fakebase && $this->bo->path != '/' && !$this->bo->vfs->acl_check(array( + 'string'=>$this->bo->path, + 'relatives' => Array(RELATIVE_NONE), + 'operation' => PHPGW_ACL_READ))) { $this->no_access_exists(lang('You do not have access to %1',$this->bo->path)); } @@ -72,8 +107,8 @@ function set_col_headers(&$p,$var,$append=True) { - $p->set_var($var); - $p->parse('col_headers','column_headers',$append); + // $p->set_var($var); + // $p->parse('col_headers','column_headers',$append); } function no_access_exists($error_msg) @@ -105,7 +140,7 @@ ); $p->parse('errors','ind_error',True); $p->pfp('output','error_page'); - $GLOBALS['phpgw']->common->phpgw_exit(); + exit(); } function create_home_dir() @@ -121,21 +156,33 @@ echo 'DEBUG: ui.create_home_dir: PATH = '.urlencode($this->bo->path).'
'."\n"; } - if(($this->bo->path == $this->bo->homedir) && !$this->bo->vfs->file_exists($this->bo->homedir,Array(RELATIVE_NONE))) + if(($this->bo->path == $this->bo->homedir) && !$this->bo->vfs->file_exists(array( + 'string' => $this->bo->homedir, + 'relatives' => Array(RELATIVE_NONE) + ))) { - //$this->bo->vfs->override_acl = 1; - if (!$this->bo->vfs->mkdir($this->bo->homedir,Array(RELATIVE_NONE))) + $this->bo->vfs->override_acl = 1; + if (!$this->bo->vfs->mkdir(array( + 'string' => $this->bo->homedir, + 'relatives' => Array(RELATIVE_NONE) + ))) { echo lang('failed to create directory') . ' '. $this->bo->homedir . '

'; } - //$this->bo->vfs->override_acl = 0; + $this->bo->vfs->override_acl = 0; } elseif(preg_match("|^".$this->bo->fakebase."\/(.*)$|U",$this->bo->path,$this->bo->matches)) { - if (!$this->bo->vfs->file_exists($this->bo->path,Array(RELATIVE_NONE))) + if (!$this->bo->vfs->file_exists(array( + 'string' => $this->bo->path, + 'relatives' => Array(RELATIVE_NONE) + ))) { //$this->bo->vfs->override_acl = 1; - if (!$this->bo->vfs->mkdir($this->bo->homedir,Array(RELATIVE_NONE))) + if (!$this->bo->vfs->mkdir(array( + 'string' => $this->bo->homedir, + 'relatives' => Array(RELATIVE_NONE) + ))) { echo lang('failed to create directory') . ' '. $this->bo->homedir . '

'; } @@ -150,7 +197,11 @@ $group_id = $GLOBALS['phpgw']->accounts->name2id($this->bo->matches[1]); if($group_id) { - $this->bo->vfs->set_attributes($this->bo->path,Array(RELATIVE_NONE),Array('owner_id' => $group_id, 'createdby_id' => $group_id)); + $this->bo->vfs->set_attributes(array( + 'string' => $this->bo->path, + 'relatives' => Array(RELATIVE_NONE), + 'attributes' => Array('owner_id' => $group_id, 'createdby_id' => $group_id) + )); } } } @@ -165,13 +216,18 @@ if($this->bo->debug) { echo 'DEBUG: ui.verify_path: PATH = '.$this->bo->path.'
'."\n"; - echo 'DEBUG: ui.verify_path: exists = '.$this->bo->vfs->file_exists($this->bo->path,Array(RELATIVE_NONE)).'
'."\n"; + echo 'DEBUG: ui.verify_path: exists = '.$this->bo->vfs->file_exists(array( + 'string' => $this->bo->path, + 'relatives' => Array(RELATIVE_NONE))).'
'."\n"; } if($this->bo->path != $this->bo->homedir && $this->bo->path != '/' && $this->bo->path != $this->bo->fakebase && - !$this->bo->vfs->file_exists($this->bo->path,Array(RELATIVE_NONE))) + !$this->bo->vfs->file_exists(array( + 'string' => $this->bo->path, + 'relatives' => Array(RELATIVE_NONE) + ))) { $this->no_access_exists(lang('Directory %1 does not exist',$this->bo->path)); } @@ -183,7 +239,10 @@ srand((double)microtime() * 1000000); if($this->bo->update || rand(0,19) == 4) { - $this->bo->vfs->update_real($this->bo->path,Array(RELATIVE_NONE)); + $this->bo->vfs->update_real( array( + 'string' => $this->bo->path, + 'relatives' =>Array(RELATIVE_NONE) + )); } if($this->bo->update) { @@ -197,9 +256,17 @@ ); } } - + //Dispatches various file manager actions to the appropriate handler function action() { + if (UI_DEBUG) + { + echo " Debug mode
"; + echo "function : ".$this->bo->$function; + print_r($_POST); + die(); + + } $actions = Array( 'rename' => lang('Rename'), 'delete' => lang('Delete'), @@ -208,34 +275,82 @@ 'move' => lang('Move To'), 'download' => lang('Download'), 'newdir' => lang('Create Folder'), - 'newfile' => lang('Create File') + 'newfile' => lang('Create File'), + 'edit' => lang('Edit'), + 'edit_comments' => lang('Edit Comments'), + 'apply_edit_comment' => '1', + 'apply_edit_name' => '1', + 'cancel' => lang('Cancel'), + 'upload' => lang('Upload Files') ); + + $local_functions = array( + 'rename', + 'edit_comments' + ); + $bo_functions = array( + 'apply_edit_comment', + 'apply_edit_name', + 'copy', + 'delete', + 'move', + 'newdir', + 'newfile', + 'go', + 'upload', + 'download' + ); + if (trim(strtolower($this->bo->cancel)) == strtolower(lang('Cancel'))) { + $this->cancel(); + exit(); + } + //If the action is a "uiaction" (ie it has its own seperate interface), this will run it + $this->actions->dispatch($this); @reset($actions); while(list($function,$text) = each($actions)) { if(isset($this->bo->$function) && !empty($this->bo->$function) && trim(strtolower($this->bo->$function)) == strtolower($text)) { - $f_function = 'f_'.$function; - $errors = $this->bo->$f_function(); - $var = Array( - 'menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.index', - 'path' => urlencode($this->bo->path) - ); - if($function == 'newfile') + //If the action is provided by this class, this'l do it + if (in_array($function, $local_functions)) { + echo " uifunction $function "; + //Header('Location: '.$GLOBALS['phpgw']->link('/index.php',$var)); + $this->$function(); + exit(); + } //For actions provided by the back-end, with no gui + elseif (in_array($function, $bo_functions)) + { + echo " bofunction $function "; + $f_function = 'f_'.$function; + $errors = $this->bo->$f_function(); $var = Array( - 'menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.edit', - 'path' => urlencode($this->bo->path), - 'file' => urlencode($this->bo->createfile) + 'menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.index', + 'path' => urlencode($this->bo->path) ); - } - elseif(is_array($errors)) - { - $var['errors'] = urlencode(base64_encode(serialize($errors))); - } - Header('Location: '.$GLOBALS['phpgw']->link('/index.php',$var)); + if($function == 'newfile') + { + $var = Array( + 'menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.edit', + 'path' => urlencode($this->bo->path), + 'file' => urlencode($this->bo->createfile) + ); + } + elseif(strlen($errors)) + { + $var['errors'] = $errors; + } + Header('Location: '.$GLOBALS['phpgw']->link('/index.php',$var)); + exit(); + } } + } + Header('Location: '.$GLOBALS['phpgw']->link('/index.php',Array( + 'menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.index', + 'path' => urlencode($this->bo->path), + 'errors' => lang('Unknown Action!') + ))); } function help() @@ -256,7 +371,7 @@ echo ''."\n".ucwords(str_replace('_',' ',$help_array[0]))."\n".'
'."\n"; echo ''."\n".$help_array[1].''; } - $GLOBALS['phpgw']->common->phpgw_exit (); + exit(); } function build_help($help_option,$text='') @@ -283,7 +398,7 @@ return ''; } } - +/* function image($image,$alt) { return ''.$alt.''; @@ -329,47 +444,49 @@ ) ); } - +*/ function display_buttons() { - $p = CreateObject('phpgwapi.Template',$this->template_dir); - $p->set_file( - Array( - '_buttons' => 'small_table.tpl' - ) - ); - $p->set_block('_buttons','table','table'); - $p->set_block('_buttons','column_headers','column_headers'); - $p->set_block('_buttons','column_headers_normal','column_headers_normal'); - $p->set_block('_buttons','column_rows','column_rows'); + $var = array(); - $var = Array( - 'table_extras' => '', - 'tr_extras' => '', - 'td_extras' => ' align="center" width="25%"' - ); + $button['type'] = 'submit'; + $button['name'] = 'uiaction_edit'; + $button['value'] = lang('Edit'); + $button['caption'] = $this->build_help('edit'); + + $var[] = array('widget' => $button); + $button['name'] = "rename"; + $button['value'] =lang('Rename'); + $button['caption'] = $this->build_help('rename'); + + $var[] = array('widget' => $button); + $button['name'] = "delete"; + $button['value'] =lang('Delete'); + $button['caption'] = $this->build_help('delete'); + $var[] = array('widget' => $button); + + $button['name'] = "edit_comments"; + $button['value'] =lang('Edit Comments'); + $button['caption'] = $this->build_help('edit_comments'); + $var[] = array('widget' => $button); + + $var[] = array('widget' => array( 'type' => 'seperator' )); - $var['column_header'] = ''.$this->build_help('edit'); - $this->set_col_headers($p,$var,False); + $button['name'] = "go"; + $button['value'] = lang('Go To'); + $button['caption'] = $this->build_help('go_to'); + $var[] = array('widget' => $button); + + $button['name'] = "copy"; + $button['value'] = lang('Copy To'); + $button['caption'] = $this->build_help('copy_to'); + $var[] = array('widget' => $button); + + $button['name'] = "move"; + $button['value'] = lang('Move To'); + $button['caption'] =$this->build_help('move_to'); + $var[] = array('widget' => $button); - $var['column_header'] = ''.$this->build_help('rename'); - $this->set_col_headers($p,$var); - - $var['column_header'] = ''.$this->build_help('delete'); - $this->set_col_headers($p,$var); - - $var['column_header'] = ''.$this->build_help('edit_comments'); - $this->set_col_headers($p,$var); - $p->parse('list','column_rows',True); - - $var['column_header'] = ''.$this->build_help('go_to'); - $this->set_col_headers($p,$var,False); - - $var['column_header'] = ''.$this->build_help('copy_to'); - $this->set_col_headers($p,$var); - - $var['column_header'] = ''.$this->build_help('move_to'); - $this->set_col_headers($p,$var); ### # First we get the directories in their home directory @@ -379,7 +496,11 @@ 'directory' => $this->bo->fakebase, 'name' => $this->bo->userinfo['account_lid'] ); - $ls_array = $this->bo->vfs->ls($this->bo->homedir,Array(RELATIVE_NONE),True,'Directory'); + $ls_array = $this->bo->vfs->ls(array( + 'string' => $this->bo->homedir, + 'relatives' => Array(RELATIVE_NONE), + 'nofiles' => True, + 'mime_type' => 'Directory')); while(list($num,$dir) = each($ls_array)) { $dirs[] = $dir; @@ -406,14 +527,19 @@ 'name' => $group_array['account_name'] ); - $ls_array = $this->bo->vfs->ls($this->bo->fakebase.SEP.$group_array['account_name'],Array(RELATIVE_NONE),True,'Directory'); + $ls_array = $this->bo->vfs->ls(array( + 'string' => $this->bo->fakebase.SEP.$group_array['account_name'], + 'relatives' => Array(RELATIVE_NONE), + 'nofiles' => True, + 'mime_type' => 'Directory' + )); while(list($num,$dir) = each($ls_array)) { $dirs[] = $dir; } } - $dir_list = ''; + $dir_list = array(); reset($dirs); while(list($num, $dir) = each($dirs)) { @@ -441,97 +567,86 @@ # No point in displaying the current directory, or a directory that doesn't exist ### - if((($dir['directory'].$dir['name']) != $this->bo->path) && $this->bo->vfs->file_exists($dir['directory'].$dir['name'],Array(RELATIVE_NONE))) + if((($dir['directory'].$dir['name']) != $this->bo->path) && $this->bo->vfs->file_exists(array( + 'string' => $dir['directory'].$dir['name'], + 'relatives' => Array(RELATIVE_NONE) + ))) { - $dir_list .= ''; + $dir_list[] =array('option'=> array('value'=> urlencode($dir['directory'].$dir['name']), + 'selected' => $selected, + 'caption' => $dir['directory'].$dir['name'] + )); } } - $var['column_header'] = ''.$this->build_help('directory_list'); - $this->set_col_headers($p,$var); - $p->parse('list','column_rows',True); - $p->set_var('col_headers',''); - - $var = Array( - 'tr_extras' => '', - 'td_extras' => ' colspan="2" align="center" width="50%"' - ); + $var[] = array('widget' => array( 'type' => 'select', + 'name'=> 'todir', + 'options' => $dir_list, + 'caption' => $this->build_help('directory_list') + )); if($this->bo->path != '/' && $this->bo->path != $this->bo->fakebase) { - $var['column_header'] = ''.$this->build_help('download'); - $this->set_col_headers($p,$var); - - $var['column_header'] = '    '.$this->build_help('create_folder'); - $this->set_col_headers($p,$var); - $p->parse('list','column_rows',True); + $var[] = array('widget' => array('type'=>'submit', + 'name'=> 'download', + 'value' => lang('Download'), + 'caption' => $this->build_help('download') + )); + $var[] = array('widget' => array( 'type' => 'seperator' )); + $var[] = array('widget' => array('type' => 'text', + 'name' => 'createdir', + 'maxlength' => '255', + 'size' => '15' + )); + $var[] = array('widget' => array('type' => 'submit', + 'name' => 'newdir', + 'value' => lang('Create Folder'), + 'caption' => $this->build_help('create_folder') + )); + $var[] = array('widget' => array( 'type' => 'seperator' )); } - - $var['column_header'] = ''.$this->build_help('update'); - $this->set_col_headers($p,$var,False); - + /* $var[] = array('widget' => array('type' => 'submit', + 'name' => 'update', + 'value' => lang('Update'), + 'caption' => $this->build_help('update') + )); +*/ if($this->bo->path != '/' && $this->bo->path != $this->bo->fakebase) { - $var['column_header'] = '    '.$this->build_help('create_file'); + $var[] = array('widget' => array( 'type' => 'text', + 'name' => 'createfile', + 'maxlength' => '255', + 'size' => '15' + )); + $var[] = array('widget' => array('type' => 'submit', + 'name' => 'newfile', + 'value' => lang('Create File'), + 'caption' => $this->build_help('create_file') + )); + $var[] = array('widget' => array( 'type' => 'seperator' )); } - else - { - $var['column_header'] = ' '; - } - $this->set_col_headers($p,$var); - $p->parse('list','column_rows',True); - $p->set_var('col_headers',''); if($this->bo->settings['show_command_line']) { - $var = Array( - 'tr_extras' => '', - 'td_extras' => ' colspan="4" align="center" width="100%"', - 'column_header' => ''.$this->build_help('command_line').'
'.$this->build_help('execute') - ); - $this->set_col_headers($p,$var); - $p->parse('list','column_rows',True); - $p->set_var('col_headers',''); + + $var[] = array('widget' => array( 'type' => 'text' , + 'name'=> 'command_line', + 'size' => '50', + 'caption' => $this->build_help('command_line') + )); + $var[] = array('widget' => array( 'type' => 'submit', + 'name' => 'execute', + 'value' => lang('Execute'), + 'caption' => $this->build_help('execute') + )); + $var[] = array('widget' => array( 'type' => 'seperator' )); } - return $p->fp('output','table'); + return $var; } function display_summary_info($numoffiles,$usedspace) { - $p = CreateObject('phpgwapi.Template',$this->template_dir); - $p->set_file( - Array( - '_info' => 'small_table.tpl' - ) - ); - $p->set_block('_info','table','table'); - $p->set_block('_info','column_headers','column_headers'); - $p->set_block('_info','column_headers_normal','column_headers_normal'); - $p->set_block('_info','column_rows','column_rows'); - $this_homedir = ($this->bo->path == $this->bo->homedir || $this->bo->path == $this->bo->fakedir); - $info_columns = 4 + ($this_homedir?2:0); - $var = Array( - 'table_extras' => ' cols="'.$info_columns.'"', - 'tr_extras' => '', - 'td_extras' => ' colspan="'.$info_columns.'" align="center" width="100%"', - 'column_header' => $this->build_help('file_stats') - ); - $this->set_col_headers($p,$var,False); - $p->parse('list','column_rows',True); - $p->set_var('col_headers',''); - - $var = Array( - 'tr_extras' => '', - 'td_extras' => ' align="right"' - ); - - $var['column_header'] = ''.lang('Files').':'; - $p->set_var($var); - $p->parse('col_headers','column_headers_normal',False); - - $var['td_extras'] = ' align="left"'; - $var['column_header'] = $numoffiles; $p->set_var($var); $p->parse('col_headers','column_headers_normal',True); @@ -569,7 +684,10 @@ $p->parse('col_headers','column_headers_normal',False); $var['td_extras'] = ' colspan="'.($info_columns / 2).'" align="left" width="50%"'; - $var['column_header'] = count($this->bo->vfs->ls($this->bo->path,Array(RELATIVE_NONE))); + $var['column_header'] = count($this->bo->vfs->ls(array( + 'string' => $this->bo->path, + 'relatives' => Array(RELATIVE_NONE) + ))); $p->set_var($var); $p->parse('col_headers','column_headers_normal',True); @@ -582,375 +700,367 @@ function display_uploads() { - $p = CreateObject('phpgwapi.Template',$this->template_dir); - $p->set_file( - Array( - '_uploads' => 'small_table.tpl' - ) - ); - $p->set_block('_uploads','table','table'); - $p->set_block('_uploads','column_headers','column_headers'); - $p->set_block('_uploads','column_headers_normal','column_headers_normal'); - $p->set_block('_uploads','column_rows','column_rows'); + $var_head[] = array('widget' => array('type' => 'label', + 'caption' => lang('File').$this->build_help('upload_file') + )); - $var = Array( - 'table_extras' => ' cols="3"', - 'tr_extras' => '' - ); - $var['td_extras'] = ' align="right" width="45%"'; - $var['column_header'] = ''.lang('File').''.$this->build_help('upload_file'); - $p->set_var($var); - $p->parse('col_headers','column_headers_normal',False); - - $var['td_extras'] = ' align="center" width="10%"'; - $var['column_header'] = ' '; - $p->set_var($var); - $p->parse('col_headers','column_headers_normal',True); - - $var['td_extras'] = ' align="left" width="45%"'; - $var['column_header'] = ''.lang('Comment').''.$this->build_help('upload_comment'); - $p->set_var($var); - $p->parse('col_headers','column_headers_normal',True); - - $p->parse('list','column_rows',True); - - $input_file = ''; - $input_comment = ''; - - $var['tr_extras'] = ''; - $var['td_extras'] = ' colspan="3" align="center"'; - $var['column_header'] = ''."\n".$input_file.$input_comment; - $p->set_var($var); - $p->parse('col_headers','column_headers_normal',False); - $p->parse('list','column_rows',True); - - for($i=1;$i<$this->bo->show_upload_boxes;$i++) + $var_head[] = array('widget' => array('type' => 'label', + 'caption' => lang('Comment').$this->build_help('upload_comment') + )); + $table_head [] =array('table_col' => $var_head); + // $var[] = array('widget' => array('type' => 'seperator')); + for($i=0;$i<$this->bo->show_upload_boxes;$i++) { - $var['column_header'] = $input_file.$input_comment; - $p->set_var($var); - $p->parse('col_headers','column_headers_normal',False); - $p->parse('list','column_rows',True); + $var = array(); + $var[] = array('widget' => array('type' => 'file', + 'name' => 'upload_file[]' , + 'maxlength'=> '255' + )); + + $var[] = array('widget' => array('type' => 'text', + 'name' => 'upload_comment[]' + )); + +/* $var[] = array('widget' => array('type' => 'label', + 'caption' => $input_file.$input_comment + )); */ + $table_rows [] = array('table_col' => $var); } + $var = array(); + $var[] = array('widget' => array('type' =>'submit', + 'name' => 'upload', + 'value' => lang('Upload Files'), + 'caption' => $this->build_help('upload_files') + )); + + $var[] = array('widget' => array('type' => 'hidden', + 'name' => 'show_upload_boxes', + 'value' => $this->bo->show_upload_boxes + )); + + $table_rows [] = array('table_col' => $var); - $var['column_header'] = ''.$this->build_help('upload_files'); - $p->set_var($var); - $p->parse('col_headers','column_headers_normal',False); - $p->parse('list','column_rows',True); - - $var['column_header'] = lang('Show').'  '.$this->build_upload_choices(5).$this->build_upload_choices(10).$this->build_upload_choices(20).$this->build_upload_choices(30).lang('upload fields').$this->build_help('show_upload_fields'); - $p->set_var($var); - $p->parse('col_headers','column_headers_normal',False); - $p->parse('list','column_rows',True); - - return '

'."\n".$p->fp('output','table').'
'."\n"; + + return array('table' => array('table_head' =>$table_head , + 'table_row' => $table_rows) + ); } - function index() + function dirs_first($files_array) + { + $dirs = array(); + $files = array(); + $result = array(); + + for($i=0;$i!=count($files_array);$i++) + { + $file = $files_array[$i]; + if ($file['mime_type'] == 'Directory') + { + $dirs[] = $file; + } + else + { + $files[] = $file; + } + } + return array_merge($dirs, $files); + } + + function index( $edit=array()) { $this->load_header(); $files_array = $this->bo->load_files(); + $usage = 0; + $files_array = $this->dirs_first($files_array); if(count($files_array) || $this->bo->cwd) { - $p = CreateObject('phpgwapi.Template',$this->template_dir); - $p->set_unknowns('remove'); - - $p->set_file( - Array( - '_index' => 'index.tpl' + $file_output = array(); + for($i=0;$i!=count($files_array);$i++) + { + $file = $files_array[$i]; + $usage += $file['size']; + if (!count($edit) ) + { + $file_attributes['checkbox'] = ''; + $file_output[$i]['checkbox'] =array('widget' => array( 'type' => 'checkbox', + 'name' => 'fileman[]', + 'value' => $file['name'] + )); + } + + @reset($this->bo->file_attributes); + while(list($internal,$displayed) = each($this->bo->file_attributes)) + { + if ($this->bo->settings[$internal]) + { + if ($internal==$edit[$file['name']]) + { + $file_output[$i][$internal] = array('widget' => array('type' => 'text', + 'name' => 'changes['.$file['name'].']', + 'value' => $file[$internal] + )); + } + else + { + switch($internal) + { + case 'owner_id': + case 'owner': + case 'createdby_id': + case 'modifiedby_id': + $name = $GLOBALS['phpgw']->accounts->id2name($file[$internal]) ; + $file_output[$i][$internal] = $name ? $name: ''; + break; + case 'created': + case 'modified': + //Convert ISO 8601 date format used by DAV into something people can read + $file_output[$i][$internal] = $this->bo->convert_date($file[$internal]); + break; + case 'name': + $mime_parts = explode('/',$file['mime_type']); + $file_icon = $this->mime_ico[$file['mime_type']]; + if (!$file_icon) { + $file_icon = ( $this->mime_ico[$mime_parts[0]]) ? $this->mime_ico[$mime_parts[0]] : $this->mime_ico['unknown']; + if (strpos($file['name'],'.exe') !== false) $file_icon = $this->mime_ico['exe']; + } + + $file_output[$i]['name']['icon'] = array( + 'widget' => array( 'type' => 'img', + 'src' => $GLOBALS['phpgw']->common->image($this->bo->appname,$file_icon) + )); + + if ($file['mime_type']=='Directory') + { + $href = array('menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.index', + 'path' => $this->bo->path.SEP.$file['name'] + ); + } + else + { + $href = Array( 'menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.view', + 'path' => urlencode($this->bo->path), + 'file' => urlencode($file['name']) + ); + + } + $file_output[$i]['name']['link'] = array( + "widget"=> array( + 'type' => 'link', + 'caption' => $file['name'], + 'href' => $GLOBALS['phpgw']->link('/index.php', $href) + )); + if ($mime_parts[0] == 'text') + { + $href['menuaction'] = $this->bo->appname.'.ui'.$this->bo->appname.'.action'; + $href['uiaction'] = 'edit'; + $file_output[$i]['name']['edit'] = array('widget' => array( 'type' => 'img', + 'src' => $GLOBALS['phpgw']->common->image($this->bo->appname,'pencil'), + 'link' => $GLOBALS['phpgw']->link('/index.php', $href) + )); + } + break; + default: + $file_output[$i][$internal] = $file[$internal]; + + } + } + $file_attributes[$internal] = array("widget"=> array( + 'type' => 'link', + 'caption' => $displayed, + 'href' => $GLOBALS['phpgw']->link('/index.php', array( + 'menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.index', + 'path'=>$this->bo->path, + 'sortby' => $internal + )) + )); + } + } + } + + $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('summary' => array( + 'file_count' => count($files_array), + 'usage' => $usage + ))); + + $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('file_attributes' => $file_attributes)); + $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array( + 'files' => array( + 'file' => $file_output + ) ) ); - $p->set_block('_index','index','index'); - $p->set_block('_index','column_headers','column_headers'); - $p->set_block('_index','column_headers_normal','column_headers_normal'); - $p->set_block('_index','column_rows','column_rows'); + $GLOBALS['phpgw']->xslttpl->add_file(array('index',$GLOBALS['phpgw']->common->get_tpl_dir('phpgwapi','default') . SEP . 'app_header')); $GLOBALS['tr_color'] = $GLOBALS['phpgw_info']['theme']['row_off']; $var = Array( - 'error' => (isset($this->bo->errors) && is_array(unserialize(base64_decode($this->bo->errors)))?$GLOBALS['phpgw']->common->error_list(unserialize(base64_decode($this->bo->errors)),'Results'):''), - 'tr_extras' => ' bgcolor="'.$this->nextmatchs->alternate_row_color().'" border="0"', 'form_action' => $GLOBALS['phpgw']->link('/index.php', Array( 'menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.action', 'path' => urlencode($this->bo->path) ) - ), - 'img_up' => $this->link(Array( - 'menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.index', - 'path' => urlencode($this->bo->lesspath) ), - $this->image('folder_up.gif',lang('Up'))), + 'error' => (isset($this->bo->errors) && is_array(unserialize(base64_decode($this->bo->errors)))?$GLOBALS['phpgw']->common->error_list(unserialize(base64_decode($this->bo->errors)),'Results'):''), + 'img_up' => array('widget' => array('type' => 'img', + 'src' => $GLOBALS['phpgw']->common->image($this->bo->appname,'up'), + 'alt' => lang('Up'), + 'link' => $GLOBALS['phpgw']->link('/index.php',Array( + 'menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.index', + 'path' => urlencode($this->bo->lesspath) + )) + )), 'help_up' => $this->build_help('up'), - 'img_home' => $this->image('folder_home.gif',lang('Folder')), - 'dir' => ''."\n" - . ' '.strtoupper($this->bo->path).''."\n" - . ' ', + 'img_home' => array('widget' => array('type' => 'img', + 'src' => $GLOBALS['phpgw']->common->image($this->bo->appname,'folder_home'), + 'alt' => lang('Folder'), + 'link' => $GLOBALS['phpgw']->link('/index.php',Array( + 'menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.index', + 'path' => urlencode($this->bo->homedir) + )) + )), + 'dir' => $this->bo->path, + 'img_dir' => array('widget' => array('type' => 'img', + 'src' => $GLOBALS['phpgw']->common->image($this->bo->appname,'folder_large'), + 'alt' => lang('Folder'), 'link' => $GLOBALS['phpgw']->link('/index.php',Array( + 'menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.index', + 'path' => urlencode($this->bo->path) + )) + )), 'help_home' => $this->build_help('home'), - 'col_headers' => '', - 'column_header' => '' ); - $p->set_var($var); + if (strlen($this->bo->errors)) + { + $var['errors'] = $this->bo->errors; + } - $this->column_header($p,'sort_by','Sort By',False); + if (count($edit)) + { + $var['img_cancel'] = array('widget' => array('type' => 'img', + 'src' => $GLOBALS['phpgw']->common->image($this->bo->appname,'button_cancel'), + 'alt' => lang('Folder') + )); + $var['button_cancel'] = array('widget' => array('type' => 'submit', + 'name' => 'cancel', + 'value' => lang('Cancel') + )); + $var['img_ok'] = array('widget' => array('type' => 'img', + 'src' => $GLOBALS['phpgw']->common->image($this->bo->appname,'button_ok'), + 'alt' => lang('Folder') + )); + $var['button_ok'] = array('widget' => array('type' => 'submit', + 'name' => 'submit', + 'value' => lang('OK') + )); + @reset($edit); + while( list($file,$prop) = each($edit)) + { + $var['fileman'][] = array('widget' => array('type'=>'hidden', + 'name' => 'fileman[]', + 'value' => $file + )); + } + @reset($edit); list($file,$prop) = each($edit); + $var['action'] = array('widget' => array('type'=>'hidden', + 'name' => 'apply_edit_'.$prop, + 'value' => 1 + )); + } + + $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('index' => $var)); - $columns = 1; @reset($this->bo->file_attributes); - while(list($internal,$displayed) = each($this->bo->file_attributes)) - { - if ($this->bo->settings[$internal]) - { - $this->column_header($p,$internal,$displayed,True); - $columns++; - } - } - $p->parse('col_row','column_rows',True); - $p->set_var('col_headers',''); - -// $var = Array( -// 'tr_extras' => ' bgcolor="'.$this->nextmatchs->alternate_row_color().'" border="0"' -// ); -// $this->set_col_headers($p,$var,True); - - $p->set_var('colspan',$columns); + $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('settings' => $this->bo->settings)); + $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('display_settings' => $GLOBALS['phpgw_info']['theme'])); - if($this->bo->settings['dotdot'] && $this->bo->settings['name'] && $this->bo->path != '/') + if(!count($edit)) { - $this->set_col_headers( - $p, - Array( - 'tr_extras' => ' bgcolor="'.$this->nextmatchs->alternate_row_color().'" border="0"', - 'col_headers' => '', - 'td_extras' => '', - 'column_header' => ' ' - ) - ); - - $this->set_col_headers( - $p, - Array( - 'column_header' => $this->image('folder.gif','folder') - .$this->link( - Array( - 'menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.index', - 'path' => $this->bo->lesspath - ), - '..' - ) - ) - ); - - $loop_cntr = 2; - - if($this->bo->settings['mime_type']) - { - $this->set_col_headers( - $p, - Array( - 'column_header' => 'Directory' - ) - ); - $loop_cntr++; - } - - for($i=$loop_cntr;$i<$columns;$i++) - { - $this->set_col_headers( - $p, - Array( - 'column_header' => ' ' - ) - ); - } - $p->parse('col_row','column_rows',True); - $p->set_var('col_headers',''); + $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('buttons'=> array('button' => $this->display_buttons()) )); + $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('uploads' => $this->display_uploads() )); } - - $usedspace = 0; - reset($files_array); - $numoffiles = count($files_array); - for($i=0;$i!=$numoffiles;$i++) - { - $files = $files_array[$i]; - $var = Array( - 'tr_extras' => ' bgcolor="'.$this->nextmatchs->alternate_row_color().'" border="0"', - 'td_extras' => '', - 'column_header' => '' - ); - $this->set_col_headers($p,$var,False); -// $p->set_var($var); -// $p->parse('col_headers','column_headers'); - - $usedspace += $files['size']; - - @reset($this->bo->file_attributes); - while(list($internal,$displayed) = each($this->bo->file_attributes)) - { - if($this->bo->settings[$internal]) - { - $var = Array( - 'td_extras' => '' - ); - switch($internal) - { - case 'name': - switch($files['mime_type']) - { - case 'Directory': - $var['column_header'] = $this->image('folder.gif','folder') - .$this->link( - Array( - 'menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.index', - 'path' => $this->bo->path.SEP.$files['name'] - ), - ''.$files['name'].'' - ); - break; - default: - $var['column_header'] = $this->link( - Array( - 'menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.view', - 'path' => urlencode($this->bo->path), - 'file' => urlencode($files['name']) - ), - ''.$files['name'].'' - ); - break; - } - break; - case 'deletable': - if ($files['deleteable'] == 'N') - { - $var['column_header'] = $this->image('locked.gif','locked'); - } - else - { - $var['column_header'] = ' '; - } - break; - case 'size': - $var['column_header'] = $this->bo->borkb($files['size']); - $var['td_extras'] = ' align="right"'; - break; - case 'version': - $var['column_header'] = $this->link( - Array( - 'menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.history', - 'path' => $this->bo->path, - 'file' => $files['name'] - ), - $files['version'] - ); - break; - case 'modified': - case 'created': - $var['column_header'] = $this->bo->convert_date($files[$internal]); - break; - case 'owner': - case 'createdby_id': - case 'modifiedby_id': - switch($internal) - { - case 'owner': - $ivar = 'owner_id'; - break; - default: - $ivar = $internal; - break; - } - $var['column_header'] = ($files[$ivar]?$GLOBALS['phpgw']->accounts->id2name($files[$ivar]):' '); - break; - default: - $var['column_header'] = ($files[$internal]?$files[$internal]:' '); - break; - } - $this->set_col_headers($p,$var); - } - } - $p->parse('col_row','column_rows',True); - $p->set_var('col_headers',''); - } - - $p->set_var('buttons',$this->display_buttons()); - $p->set_var('info',$this->display_summary_info($numoffiles,$usedspace)); - $p->set_var('uploads',$this->display_uploads()); - - $p->pfp('output','index'); + $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('index' => $var)); } - } - function view() + } + function cancel() { - $this->load_header(); - if($this->bo->vfs->file_exists($this->bo->path.'/'.$this->bo->file,Array(RELATIVE_NONE))) - { - $content_type = $this->bo->vfs->file_type($this->bo->path.$this->bo->dispsep.$this->bo->file,Array(RELATIVE_NONE)); - if($content_type) - { - $cont_type = explode('/',$content_type); - $content_type = $cont_type[1]; - } - else - { - } - switch($content_type) - { - case 'jpeg': - case 'gif': - case 'bmp': - case 'png': - $alignment = 'center'; - $file_content = ''."\n"; - break; - default: - $alignment = 'left'; - $file_content = nl2br($this->bo->vfs->read($this->bo->path.$this->bo->dispsep.$this->bo->file,Array(RELATIVE_NONE))); - break; - } - $file = $this->bo->path.$this->bo->dispsep.$this->bo->file; - $GLOBALS['tr_color'] = $GLOBALS['phpgw_info']['theme']['row_off']; - - echo ''."\n" - . ' '."\n" - . ' '."\n" - . ' '."\n" - . ' '."\n" - . ' '."\n" - . ' '."\n" - . ' '."\n" - . ' '."\n" - . ' '."\n" - . ' '."\n" - . ' '."\n" - . ' '."\n" - . '
'."\n" - . ' TYPE: '.$this->bo->vfs->file_type($file,Array(RELATIVE_NONE)).'
'."\n" - . '
'."\n" - . ' FILENAME: '.$file."\n" - . '
'."\n" - . ' VERSION: '.$this->bo->vfs->get_version($file,Array(RELATIVE_NONE))."\n" - . '
'."\n" - . $file_content."\n" - . '
'."\n"; - } + $var = Array( + 'menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.index', + 'path' => urlencode($this->bo->path) + ); + Header('Location: '.$GLOBALS['phpgw']->link('/index.php',$var)); } - + function rename() + { + $edit=array(); + for ($i=0; $i!=count($this->bo->fileman);$i++) + { + $edit[$this->bo->fileman[$i]] = 'name'; + } + $this->index($edit); + } + function edit_comments() + { + $edit=array(); + for ($i=0; $i!=count($this->bo->fileman);$i++) + { + $edit[$this->bo->fileman[$i]] = 'comment'; + } + $this->index($edit); + } + function view() + { + //Some VFSs (ie WebDAV) are able to provide their own more efficent view method + //than just reading the file into memory then dumping it back out again + if ($this->bo->vfs->options('VIEW')) + { + $this->bo->vfs->view(array ( + 'string' => $this->bo->path.'/'.$this->bo->file, + 'relatives' => array (RELATIVE_NONE) + )); + } + else + { + + $GLOBALS['phpgw_info']['flags']['noheader'] = true; + $GLOBALS['phpgw_info']['flags']['nonavbar'] = true; + $GLOBALS['phpgw_info']['flags']['noappheader'] = true; + $GLOBALS['phpgw_info']['flags']['noappfooter'] = true; + $ls_array = $this->bo->vfs->ls (array ( + 'string' => $this->bo->path.'/'.$this->bo->file, + 'relatives' => array (RELATIVE_ALL), + 'checksubdirs' => False, + 'nofiles' => True + ) + ); + + if ($ls_array[0]['mime_type']) + { + $mime_type = $ls_array[0]['mime_type']; + } + elseif ($GLOBALS['settings']['viewtextplain']) + { + $mime_type = 'text/plain'; + } + + header('Content-type: ' . $mime_type); + echo $this->bo->vfs->read (array ( + 'string' => $this->bo->path.'/'.$this->bo->file, + 'relatives' => array (RELATIVE_NONE) + ) + ); + } + exit();; + } + function history() { $this->load_header(); $file = $this->bo->path.$this->bo->dispsep.$this->bo->file; - if($this->bo->vfs->file_exists($file,Array(RELATIVE_NONE))) + if($this->bo->vfs->file_exists(array( + 'string' => $file, + 'relatives' => Array(RELATIVE_NONE) + ))) { $col_headers = Array( 'Date' => 'created', @@ -1003,7 +1113,10 @@ $p->parse('col_row','column_rows',True); $p->set_var('col_headers',''); - $journal_array = $this->bo->vfs->get_journal($file,Array(RELATIVE_NONE)); + $journal_array = $this->bo->vfs->get_journal(array( + 'string' => $file, + 'relatives' => Array(RELATIVE_NONE) + )); while(list($num,$journal_entry) = each($journal_array)) { @reset($col_headers); @@ -1039,22 +1152,32 @@ $this->bo->file = $file_array['file']; } $file = $this->bo->path.SEP.$this->bo->file; - if($this->bo->vfs->file_exists($file,Array(RELATIVE_NONE))) + if($this->bo->vfs->file_exists(array( + 'string' => $file, + 'relatives' => Array(RELATIVE_NONE) + ))) { $browser = CreateObject('phpgwapi.browser'); - $browser->content_header($this->bo->file,$this->bo->vfs->file_type($file,Array(RELATIVE_NONE)),$this->bo->vfs->get_size($file,Array(RELATIVE_NONE)),True); + $browser->content_header($this->bo->file,$this->bo->vfs->file_type(array( + 'string' => $file, + 'relatives' => Array(RELATIVE_NONE))), + $this->bo->vfs->get_size(array( + 'string' => $file, + 'relatives' => Array(RELATIVE_NONE), + 'checksubdirs' => True + ))); // $browser->content_header($this->bo->file); - echo $this->bo->vfs->read($file,Array(RELATIVE_NONE)); + echo $this->bo->vfs->read(array( + 'string' => $file, + 'relatives' => Array(RELATIVE_NONE) + )); flush(); } if(!is_array($file_array)) { - $GLOBALS['phpgw']->common->phpgw_exit (); + exit(); } } - function edit() - { - $this->load_header(); - } + }