*
* This class user interface for the phpwebhosting 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 *
\**************************************************************************/
/* $Id$ */
class uiphpwebhosting
{
var $public_functions = array(
'index' => True,
'action' => True,
'help' => True,
'history' => True,
'view' => True,
'view_file' => True,
'edit' => True
);
var $bo;
var $nextmatchs;
var $browser;
var $template_dir;
var $help_info;
function uiphpwebhosting()
{
$this->bo = CreateObject('phpwebhosting.bophpwebhosting');
$this->nextmatchs = CreateObject('phpgwapi.nextmatchs');
$this->browser = CreateObject('phpgwapi.browser');
$this->template_dir = $GLOBALS['phpgw']->common->get_tpl_dir($GLOBALS['phpgw_info']['flags']['currentapp']);
$this->check_access();
$this->create_home_dir();
$this->verify_path();
$this->update();
}
function load_header()
{
unset($GLOBALS['phpgw_info']['flags']['noheader']);
unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
unset($GLOBALS['phpgw_info']['flags']['noappheader']);
unset($GLOBALS['phpgw_info']['flags']['noappfooter']);
$GLOBALS['phpgw']->common->phpgw_header();
}
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))
{
$this->no_access_exists(lang('You do not have access to %1',$this->bo->path));
}
$this->bo->userinfo['working_id'] = $this->bo->vfs->working_id;
$this->bo->userinfo['working_lid'] = $GLOBALS['phpgw']->accounts->id2name($this->bo->userinfo['working_id']);
}
function set_col_headers(&$p,$var,$append=True)
{
$p->set_var($var);
$p->parse('col_headers','column_headers',$append);
}
function no_access_exists($error_msg)
{
if($this->bo->debug)
{
echo 'DEBUG: ui.no_access_exists: you do not have access to this directory
'."\n";
}
$p = CreateObject('phpgwapi.Template',$this->template_dir);
$p->set_unknowns('remove');
$p->set_file(
Array(
'_errors' => 'errors.tpl'
)
);
$p->set_block('_errors','error_page','error_page');
$p->set_block('_errors','ind_error','ind_error');
$p->set_var('error',$error_msg);
$p->parse('errors','ind_error',True);
$p->set_var('error','
Go to your Home directory'
);
$p->parse('errors','ind_error',True);
$p->pfp('output','error_page');
$GLOBALS['phpgw']->common->phpgw_exit();
}
function create_home_dir()
{
###
# If their home directory doesn't exist, we create it
# Same for group directories
###
if($this->bo->debug)
{
echo 'DEBUG: ui.create_home_dir: PATH = '.$this->bo->path.'
'."\n";
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)))
{
//$this->bo->vfs->override_acl = 1;
if (!$this->bo->vfs->mkdir($this->bo->homedir,Array(RELATIVE_NONE)))
{
echo lang('failed to create directory') . ' '. $this->bo->homedir . '
';
}
//$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)))
{
//$this->bo->vfs->override_acl = 1;
if (!$this->bo->vfs->mkdir($this->bo->homedir,Array(RELATIVE_NONE)))
{
echo lang('failed to create directory') . ' '. $this->bo->homedir . '
';
}
//$this->bo->vfs->override_acl = 0;
if($this->bo->debug)
{
echo 'DEBUG: ui.create_home_dir: PATH = '.$this->bo->path.'
'."\n";
echo 'DEBUG: ui.create_home_dir(): matches[1] = '.$this->bo->matches[1].'
'."\n";
}
$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));
}
}
}
}
function verify_path()
{
###
# Verify path is real
###
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";
}
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->no_access_exists(lang('Directory %1 does not exist',$this->bo->path));
}
}
function update()
{
/* Update if they request it, or one out of 20 page loads */
srand((double)microtime() * 1000000);
if($this->bo->update || rand(0,19) == 4)
{
$this->bo->vfs->update_real($this->bo->path,Array(RELATIVE_NONE));
}
if($this->bo->update)
{
Header('Location: '.$GLOBALS['phpgw']->link(
'/index.php',
Array(
'menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.index',
'path' => urlencode($this->bo->path)
)
)
);
}
}
function action()
{
$actions = Array(
'rename' => lang('Rename'),
'delete' => lang('Delete'),
'go' => lang('Go To'),
'copy' => lang('Copy To'),
'move' => lang('Move To'),
'download' => lang('Download'),
'newdir' => lang('Create Folder'),
'newfile' => lang('Create File')
);
@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')
{
$var = Array(
'menuaction' => $this->bo->appname.'.ui'.$this->bo->appname.'.edit',
'path' => urlencode($this->bo->path),
'file' => urlencode($this->bo->createfile)
);
}
elseif(is_array($errors))
{
$var['errors'] = urlencode(base64_encode(serialize($errors)));
}
Header('Location: '.$GLOBALS['phpgw']->link('/index.php',$var));
}
}
}
function help()
{
$this->load_header();
$this->bo->load_help_info();
@reset($this->bo->help_info);
while(list($num,$help_array) = each($this->bo->help_info))
{
if ($help_array[0] != $this->bo->help_name)
{
continue;
}
$help_array[1] = preg_replace("/\[(.*)\|(.*)\]/Ue","\$this->build_help('\\1','\\2')",$help_array[1]);
$help_array[1] = preg_replace("/\[(.*)\]/Ue","\$this->build_help('\\1','\\1')",$help_array[1]);
echo ''."\n".ucwords(str_replace('_',' ',$help_array[0]))."\n".''."\n";
echo ''."\n".$help_array[1].'';
}
$GLOBALS['phpgw']->common->phpgw_exit ();
}
function build_help($help_option,$text='')
{
if($this->bo->settings['show_help'])
{
$help = ($text?'':''."\n");
$help .= ' ';
$help .= ($text?$text:'[?]');
$help .= '';
$help .= ($text?'':"\n".' ');
return $help;
}
else
{
return '';
}
}
function image($image,$alt)
{
return '';
}
function link($array_params,$text)
{
return ''.$text.'';
}
function build_upload_choices($number)
{
return $this->link(
Array(
'menuaction' => get_var('menuaction',Array('GET')),
'path' => $this->bo->path,
'show_upload_boxes' => $number
),
$number).' ';
}
function column_header(&$p,$internal,$displayed,$link=True)
{
if($link)
{
$header_str = ''.lang($displayed).'';
}
else
{
$header_str = $displayed;
}
$this->set_col_headers(
$p,
Array(
'td_extras' => '',
'column_header' => $header_str.$this->build_help($internal)
)
);
}
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(
'table_extras' => '',
'tr_extras' => '',
'td_extras' => ' align="center" width="25%"'
);
$var['column_header'] = ''.$this->build_help('edit');
$this->set_col_headers($p,$var,False);
$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
###
$dirs[] = Array(
'directory' => $this->bo->fakebase,
'name' => $this->bo->userinfo['account_lid']
);
$ls_array = $this->bo->vfs->ls($this->bo->homedir,Array(RELATIVE_NONE),True,'Directory');
while(list($num,$dir) = each($ls_array))
{
$dirs[] = $dir;
}
###
# Then we get the directories in their membership's home directories
###
reset($this->bo->memberships);
while(list($num,$group_array) = each($this->bo->memberships))
{
###
# Don't list directories for groups that don't have access
###
if(!$this->bo->membership_applications[$group_array['account_name']][$this->bo->appname]['enabled'])
{
continue;
}
$dirs[] = Array(
'directory' => $this->bo->fakebase,
'name' => $group_array['account_name']
);
$ls_array = $this->bo->vfs->ls($this->bo->fakebase.SEP.$group_array['account_name'],Array(RELATIVE_NONE),True,'Directory');
while(list($num,$dir) = each($ls_array))
{
$dirs[] = $dir;
}
}
$dir_list = '';
reset($dirs);
while(list($num, $dir) = each($dirs))
{
if(!$dir['directory'])
{
continue;
}
###
# So we don't display //
###
if($dir['directory'] != '/')
{
$dir['directory'] .= SEP;
}
$selected = '';
if($num == 0)
{
$selected = ' selected';
}
###
# 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)))
{
$dir_list .= '';
}
}
$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%"'
);
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['column_header'] = ''.$this->build_help('update');
$this->set_col_headers($p,$var,False);
if($this->bo->path != '/' && $this->bo->path != $this->bo->fakebase)
{
$var['column_header'] = ' '.$this->build_help('create_file');
}
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','');
}
return $p->fp('output','table');
}
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);
$var['td_extras'] = ' align="right"';
$var['column_header'] = ''.lang('Used Space').':';
$p->set_var($var);
$p->parse('col_headers','column_headers_normal',True);
$var['td_extras'] = ' align="left"';
$var['column_header'] = $this->bo->borkb($usedspace);
$p->set_var($var);
$p->parse('col_headers','column_headers_normal',True);
if($this_homedir)
{
$var['td_extras'] = ' align="right"';
$var['column_header'] = ''.lang('Unused space').':';
$p->set_var($var);
$p->parse('col_headers','column_headers_normal',True);
$var['td_extras'] = ' align="left"';
$var['column_header'] = $this->bo->borkb($this->bo->userinfo['hdspace'] - $usedspace);
$p->set_var($var);
$p->parse('col_headers','column_headers_normal',True);
}
$p->parse('list','column_rows',True);
$p->set_var('col_headers','');
if($this_homedir)
{
$var['td_extras'] = ' colspan="'.($info_columns / 2).'" align="right" width="50%"';
$var['column_header'] = ''.lang('Total Files').':';
$p->set_var($var);
$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)));
$p->set_var($var);
$p->parse('col_headers','column_headers_normal',True);
$p->parse('list','column_rows',True);
$p->set_var('col_headers','');
}
return $p->fp('output','table');
}
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 = 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['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['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"
. ' TYPE: '.$this->bo->vfs->file_type($file,Array(RELATIVE_NONE)).' '."\n" . ' | '."\n"
. '
'."\n" . ' FILENAME: '.$file."\n" . ' | '."\n" . '
'."\n" . ' VERSION: '.$this->bo->vfs->get_version($file,Array(RELATIVE_NONE))."\n" . ' | '."\n" . '
'."\n" . $file_content."\n" . ' | '."\n" . '