True, 'download'=>True, 'setRestricted'=>True, 'editComment'=> True, 'rename'=>True, 'delete'=>True, 'summary' => True ); //keep var $bo; var $dispath; var $cwd; var $lesspath; var $dispsep; var $target; var $prefs;//array var $current_config; // this ones must be checked thorougly; var $fileman = Array(); //var $fileman; var $path; var $file; var $debug = false; var $now; function vfs_functions() { $this->now = date('Y-m-d'); $this->bo = CreateObject('filemanager.bofilemanager'); $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' => ''), 'file' => array('file' => ''), 'sortby' => array('sortby' => ''), 'messages' => array('messages' => ''), 'comment' => array('comment' => ''), '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(); $pref->save_repository(True); $pref_array = $pref->read_repository(); $this->prefs = $pref_array[$this->bo->appname]; //always show name $this->prefs[name] =1; } // String format is YYYY-MM-DD HH:MM function dateString2timeStamp($string){ return mktime($string[11].$string[12], $string[14].$string[15], $string[17].$string[18], $string[5].$string[6], $string[8].$string[9], $string[0].$string[1]. $string[2].$string[3]); } function verifyLock($file,$relative){ $ls_array = $this->bo->vfs->ls(array( 'string' => $file, 'relatives' => array($relative), 'checksubdirs' => False, 'nofiles' => True )); $timestamp = $this->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 { $this->messages[]=lang('Error:').lang('This file is being edited right now by:').$GLOBALS['phpgw']->accounts->id2name($ls_array[0]['modifiedby_id']); return False; } else return True; } function setRestricted(){ $GLOBALS['phpgw_info']['flags'] = array ( 'currentapp' => 'filemanager', 'noheader' => True, 'nonavbar' => True, 'nofooter' => True, 'noappheader' => True, 'enable_browser_class' => True ); if ($this->file) { $filename=$this->path.'/'.$this->file; if(!$this->verifyLock($filename,RELATIVE_NONE)) { echo "False"; return False; } $ls_array = $this->bo->vfs->ls(array( 'string' => $filename, 'relatives' => array(RELATIVE_NONE), 'checksubdirs' => False, 'nofiles' => True )); if (intval($ls_array[0]['type']) == 0) $type = 1; else $type = 0; if($this->bo->vfs->set_attributes (array( 'string' => $filename, 'relatives' => RELATIVE_NONE, 'attributes' => array('type' => $type) )) ) { echo "True:".$this->file; } else { echo "False"; } } } function touch(){ if($this->file) if ($this->bo->vfs->touch(array('string'=> $this->file,'relatives' => array(RELATIVE_ALL)))) { echo "True"; return True; } else return False; } function summary() { if($this->file) { header('Content-Type: image/gif'); $expires = 60*60*24*15; /* 15 days */ header("Cache-Control: maxage=".$expires); header("Pragma: public"); header("Expires: ".gmdate('D, d M Y H:i:s', time()+$expires)); $content = $this->bo->vfs->summary(array('path' => $this->path, 'string' => $this->file )); if (sizeof($content) > 0) echo $content; else { $filename = './filemanager/templates/default/images/error.gif'; $handle = fopen($filename,'rb'); echo fread($handle,filesize($filename)); fclose($handle); } $GLOBALS['phpgw']->common->phpgw_exit(); } } function delete(){ foreach($this->fileman as $filename) { if($this->verifyLock($filename,RELATIVE_ALL) && $this->bo->vfs->delete(array('string' => $filename))) { echo $filename.":"; } else { echo "False:".$filename; return False; } } } function editComment() { if($badchar = $this->bo->bad_chars($this->comment, False, True)) { echo "False:badchar:".$badchar; return False; } if ($this->bo->vfs->set_attributes(array( 'string' => $this->file, 'relatives' => array(RELATIVE_ALL), 'attributes' => array( 'comment' => stripslashes($this->comment) ) ))) { echo "True:".$this->file; return True; } } # Handle Renaming Files and Directories function rename() { if ($this->file) { if($badchar = $this->bo->bad_chars($this->to, True, True)) { echo "Error:badchar:".$badchar; return false; } if(ereg("/", $this->to) || ereg("\\\\", $this->to)) { echo "Error:slashes"; return false; } elseif(!$this->verifyLock($this->file,RELATIVE_CURRENT)) echo "Error:editing"; elseif ($this->bo->vfs->mv(array( 'from' => $this->path.'/'.$this->file, 'to' => $this->path.'/'.$this->to, 'relatives' => array(RELATIVE_NONE,RELATIVE_NONE) ))) { echo "True:".$this->file.":".$this->to; } else { echo "Error:".$this->file.":".$this->to; } } } }