diff --git a/infolog/inc/class.boinfolog.inc.php b/infolog/inc/class.boinfolog.inc.php index cd932ff40f..d0c4abecd9 100644 --- a/infolog/inc/class.boinfolog.inc.php +++ b/infolog/inc/class.boinfolog.inc.php @@ -17,22 +17,32 @@ { var $public_functions = array ( - 'init' => True, // in class soinfolog - 'read' => True, - 'write' => True, - 'delete' => True, - 'check_access' => True, - 'readProj' => True, - 'readAddr' => True, - 'anzSubs' => True, - 'readIdArray' => True, - 'accountInfo' => True, // in class boinfolog (this class) - 'addr2name' => True + 'init' => True, // in class soinfolog + 'read' => True, + 'write' => True, + 'delete' => True, + 'check_access' => True, + 'readProj' => True, + 'readAddr' => True, + 'anzSubs' => True, + 'readIdArray' => True, + 'accountInfo' => True, // in class boinfolog (this class) + 'addr2name' => True, + 'attach_file' => True, + 'delete_attached'=> True, + 'info_attached' => True, + 'list_attached' => True, + 'read_attached' => True, + 'attached_local' => True ); var $enums; var $so; + var $vfs; + var $vfs_basedir='/infolog'; + var $valid_pathes = array(); + var $send_file_ips = array(); - function boinfolog( $info_id = 0) + function boinfolog( $info_id = 0) { $this->enums = array( 'priority' => array ( @@ -64,6 +74,28 @@ )); $this->so = CreateObject('infolog.soinfolog'); + $this->vfs = CreateObject('infolog.vfs'); + + $this->config = CreateObject('phpgwapi.config'); + $this->config->read_repository(); + + if ($this->config->config_data) + { + $link_pathes = unserialize($this->config->config_data['link_pathes']); + $send_file_ips = unserialize($this->config->config_data['send_file_ips']); + /* + * config.save_repository is calling addslashes, + * while read_repository does not call stripslashes, + * so we remove them here manually + */ + while (list($k,$v) = each($link_pathes)) { + $ks = stripslashes($k); + $this->link_pathes[$ks] = stripslashes($v); + $this->send_file_ips[$ks] = stripslashes($send_file_ips[$k]); + } + // echo "
bo: link_pathes="; _debug_array($this->link_pathes); + // echo "
bo: send_file_ips="; _debug_array($this->send_file_ips); + } $this->read( $info_id); } @@ -168,13 +200,15 @@ $this->addr2name( $this->readAddr( $this->so->data['info_addr_id'] ))) { $this->so->data['info_from'] = ''; - } + } return $this->so->data; } function delete($info_id) { - $this->so->delete($info_id); + $this->delete_attached($info_id); + + $this->so->delete($info_id); } function write($values) @@ -188,18 +222,18 @@ $values['owner'] = $this->so->user; } $values['datecreated'] = time(); // is now MODIFICATION-date - + if (!$values['subject']) { $values['subject'] = substr($values['des'],0,60).' ...'; - } + } if ($values['addr_id'] && !$values['from']) { $values['from'] = $this->addr2name( $this->readAddr( $values['addr_id'] )); } $this->so->write($values); } - + function anzSubs( $info_id ) { return $this->so->anzSubs( $info_id ); @@ -212,4 +246,156 @@ $action,$addr_id,$proj_id,$info_id, $ordermethod,$start,$total); } + + + function vfs_path($info_id,$file='') + { + return $this->vfs_basedir . '/' . $info_id . ($file ? '/' . $file : ''); + } + + /* + ** Put a file to the corrosponding place in the VFS and set the attributes + ** ACL check is done by the VFS + */ + function attach_file($info_id,$filepos,$name,$size,$type,$comment='',$full_fname='') + { + //echo "
add_one_file: info_id='$info_id', filepos='$filepos', name='$name', size='$size', type='$type', comment='$comment', full_fname='$full_fname'
\n"; + + // create the root for attached files in infolog, if it does not exists + if (!($this->vfs->file_exists($this->vfs_basedir,array(RELATIVE_ROOT)))) + { + $this->vfs->override_acl = 1; + $this->vfs->mkdir($this->vfs_basedir,array(RELATIVE_ROOT)); + $this->vfs->override_acl = 0; + } + + $dir=$this->vfs_path($info_id); + if (!($this->vfs->file_exists($dir,array(RELATIVE_ROOT)))) + { + $this->vfs->override_acl = 1; + $this->vfs->mkdir($dir,array(RELATIVE_ROOT)); + $this->vfs->override_acl = 0; + } + $fname = $this->vfs_path($info_id,$name); + $tfname = ''; + if ($full_fname) + { + $full_fname = str_replace('\\\\','/',$full_fname); // vfs uses only '/' + reset($this->link_pathes); + while ((list($valid,$trans) = each($this->link_pathes)) && !$tfname) + { // check case-insensitive for WIN etc. + $check = $valid[0] == '\\' || strstr(':',$valid) ? 'eregi' : 'ereg'; + $valid2 = str_replace('\\','/',$valid); + if ($check('^('.$valid2.')(.*)$',$full_fname,$parts) && + ereg($this->send_file_ips[$valid],$ip) && // right IP + $this->vfs->file_exists($trans.$parts[2],array(RELATIVE_NONE|VFS_REAL))) + { + $tfname = $trans.$parts[2]; + } + // echo "add_one_file: full_fname='$full_fname', valid2='$valid2', trans='$trans', check=$check, tfname='$tfname', parts=(x,'${parts[1]}','${parts[2]}')
\n"; + } + if ($tfname && !$this->vfs->securitycheck($tfname)) + { + return lang('Invalid filename').': '.$tfname; + } + } + if ($tfname) // file is local + { + $this->vfs->symlink($tfname,$fname,array(RELATIVE_NONE|VFS_REAL,RELATIVE_ROOT)); + } + else + { + $this->vfs->cp($filepos,$fname,array(RELATIVE_NONE|VFS_REAL,RELATIVE_ROOT)); + } + $this->vfs->set_attributes ($fname, array (RELATIVE_ROOT), + array ('mime_type' => $type, + 'comment' => stripslashes ($comment), + 'app' => 'infolog')); + } + + function delete_attached($info_id,$fname = '') + { + $file = $this->vfs_path($info_id,$fname); + + if ($this->vfs->file_exists($file,array(RELATIVE_ROOT))) + { + $this->vfs->override_acl = 1; + $this->vfs->delete($file,array(RELATIVE_ROOT)); + $this->vfs->override_acl = 0; + } + } + + function info_attached($info_id,$filename) + { + $attachments = $this->vfs->ls($this->vfs_path($info_id,$filename),array(REALTIVE_NONE)); + + if (!count($attachments) || !$attachments[0]['name']) + { + return False; + } + return $attachments[0]; + } + + function list_attached($info_id) + { + $attachments = $this->vfs->ls($this->vfs_path($info_id),array(REALTIVE_NONE)); + + if (!count($attachments) || !$attachments[0]['name']) + { + return False; + } + while (list($keys,$fileinfo) = each($attachments)) + { + $attached[$fileinfo['name']] = $fileinfo['comment']; + } + return $attached; + } + + function is_win_path($path) + { + return $path[0] == '\\' || strstr($path,':'); + } + + function read_attached($info_id,$filename) + { + if (!$info_id || !$filename || !$this->check_access($info_id,PHPGW_ACL_READ)) + { + return False; + } + return $this->vfs->read($this->vfs_path($info_id,$filename),array(RELATIVE_ROOT)); + } + + /* + * Checks if filename should be local availible and if so returns 'file:/path' for HTTP-redirect + * else return False + */ + function attached_local($info_id,$filename,$ip,$win_user) + { + //echo "attached_local(info_id='$info_id', filename='$filename', ip='$ip', win_user='$win_user', count(send_file_ips)=".count($this->send_file_ips).")
\n"; + + if (!$info_id || !$filename || !$this->check_access($info_id,PHPGW_ACL_READ) || + !count($this->send_file_ips)) + { + return False; + } + $link = $this->vfs->readlink ($this->vfs_path($info_id,$filename), array (RELATIVE_ROOT)); + + if ($link) + { + reset($this->link_pathes); $fname = ''; + while ((list($valid,$trans) = each($this->link_pathes)) && !$fname) + { + if (!$this->is_win_path($valid) == !$win_user && // valid for this OS + eregi('^'.$trans.'(.*)$',$link,$parts) && // right path + ereg($this->send_file_ips[$valid],$ip)) // right IP + { + $fname = $valid . $parts[1]; + $fname = !$win_user ? str_replace('\\','/',$fname) : str_replace('/','\\',$fname); + return 'file:'.($win_user ? '//' : '' ).$fname; + } + // echo "attached_local: link=$link, valid=$valid, trans='$trans', fname='$fname', parts=(x,'${parts[1]}','${parts[2]}')
\n"; + } + } + return False; + } } diff --git a/infolog/inc/class.html.inc.php b/infolog/inc/class.html.inc.php index 588fbb3fb3..c5ac7c7c84 100644 --- a/infolog/inc/class.html.inc.php +++ b/infolog/inc/class.html.inc.php @@ -40,10 +40,16 @@ class html return $html; } + function input($name,$value='',$type='',$options='' ) + { + if ($type) $type = "type=$type"; + + return "\n"; + } + function submit_button($name,$lang,$onClick='') { - return "\n"; + return $this->input($name,lang($lang),'submit',$onClick ? "onClick=\"$onClick\"" : ''); } /* @@ -76,12 +82,6 @@ class html return "\n"; } - - function file($name,$value='') - { - return "\n"; - } - function form($content,$hidden_vars,$url,$url_vars='',$method='POST') { $html = "