[1506] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * -------------------------------------------------------------------------* |
---|
| 4 | * This library is free software; you can redistribute it and/or modify it * |
---|
| 5 | * under the terms of the GNU Lesser General Public License as published by * |
---|
| 6 | * the Free Software Foundation; either version 2.1 of the License, * |
---|
| 7 | * or any later version. * |
---|
| 8 | * This library is distributed in the hope that it will be useful, but * |
---|
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of * |
---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * |
---|
| 11 | * See the GNU Lesser General Public License for more details. * |
---|
| 12 | * You should have received a copy of the GNU Lesser General Public License * |
---|
| 13 | * along with this library; if not, write to the Free Software Foundation, * |
---|
| 14 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
---|
| 15 | \**************************************************************************/ |
---|
| 16 | |
---|
| 17 | /* $Id: class.uifilemanager.inc.php 17511 2004-12-12 06:35:24Z dawnlinux $ */ |
---|
| 18 | |
---|
| 19 | class uifilemanager |
---|
| 20 | { |
---|
| 21 | var $public_functions = array( |
---|
| 22 | 'index' => True, |
---|
| 23 | 'help' => True, |
---|
| 24 | 'view' => True, |
---|
[1575] | 25 | 'export'=> True, |
---|
| 26 | 'touch' => True, |
---|
[1506] | 27 | 'history' => True, |
---|
| 28 | 'edit' => True, |
---|
[1627] | 29 | 'fileModels'=>True, |
---|
[1693] | 30 | 'getReturnExecuteForm' => True, |
---|
[1719] | 31 | 'dir_ls' => True, |
---|
[1726] | 32 | 'search' => True, |
---|
[1879] | 33 | 'get_folders_list' => True, |
---|
[1804] | 34 | 'showUploadboxes' => True, |
---|
[1879] | 35 | 'createdir' => True, |
---|
| 36 | 'removedir' => True, |
---|
[1627] | 37 | 'uploadModel'=>True |
---|
[1506] | 38 | ); |
---|
| 39 | |
---|
| 40 | //keep |
---|
| 41 | var $bo; |
---|
[1627] | 42 | var $vfs_functions; |
---|
[1506] | 43 | var $t; //template object |
---|
| 44 | var $dispath; |
---|
| 45 | var $cwd; |
---|
| 46 | var $lesspath; |
---|
| 47 | var $readable_groups; |
---|
| 48 | var $files_array; |
---|
| 49 | var $numoffiles; |
---|
| 50 | var $dispsep; |
---|
| 51 | |
---|
| 52 | var $target; |
---|
| 53 | |
---|
| 54 | var $prefs;//array |
---|
| 55 | |
---|
| 56 | var $groups_applications; |
---|
| 57 | |
---|
[1556] | 58 | var $current_config; |
---|
[1726] | 59 | var $dirs; |
---|
[1694] | 60 | var $to; |
---|
[1506] | 61 | var $changedir; // for switching dir. |
---|
| 62 | var $cdtodir; // for switching dir. |
---|
| 63 | var $newfile_or_dir; |
---|
| 64 | var $newfile_x; |
---|
| 65 | var $createfile_var; |
---|
| 66 | var $move_to_x; |
---|
| 67 | var $copy_to_x; |
---|
| 68 | var $edit_x; |
---|
| 69 | var $edit_file; |
---|
| 70 | var $edit_preview_x; |
---|
| 71 | var $edit_save_x; |
---|
| 72 | var $edit_save_done_x; |
---|
| 73 | var $edit_cancel_x; |
---|
| 74 | |
---|
| 75 | // this ones must be checked thorougly; |
---|
| 76 | var $fileman = Array(); |
---|
| 77 | //var $fileman; |
---|
| 78 | var $path; |
---|
| 79 | var $file; // FIXME WHERE IS THIS FILLED? |
---|
| 80 | var $sortby; |
---|
[1694] | 81 | var $messages; |
---|
[1506] | 82 | |
---|
| 83 | var $now; |
---|
| 84 | |
---|
| 85 | function uifilemanager() |
---|
| 86 | { |
---|
[1694] | 87 | $this->messages = &$_SESSION['phpgw_info']['filemanager']['user']['messages']; |
---|
| 88 | |
---|
[1506] | 89 | $GLOBALS['phpgw']->browser = CreateObject('phpgwapi.browser'); |
---|
| 90 | |
---|
| 91 | $this->now = date('Y-m-d'); |
---|
| 92 | |
---|
| 93 | $this->bo = CreateObject('filemanager.bofilemanager'); |
---|
| 94 | |
---|
[1627] | 95 | $this->vfs_functions = CreateObject('filemanager.vfs_functions'); |
---|
| 96 | |
---|
[1506] | 97 | $this->t = $GLOBALS['phpgw']->template; |
---|
[1556] | 98 | $c = CreateObject('phpgwapi.config','filemanager'); |
---|
| 99 | $c->read_repository(); |
---|
| 100 | $this->current_config = $c->config_data; |
---|
[1506] | 101 | |
---|
[1556] | 102 | |
---|
[1506] | 103 | // here local vars are created from the HTTP vars |
---|
| 104 | @reset($GLOBALS['HTTP_POST_VARS']); |
---|
| 105 | while(list($name,) = @each($GLOBALS['HTTP_POST_VARS'])) |
---|
| 106 | { |
---|
| 107 | $this->$name = $GLOBALS['HTTP_POST_VARS'][$name]; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | @reset($GLOBALS['HTTP_GET_VARS']); |
---|
| 111 | while(list($name,) = @each($GLOBALS['HTTP_GET_VARS'])) |
---|
| 112 | { |
---|
| 113 | $$name = $GLOBALS['HTTP_GET_VARS'][$name]; |
---|
[1627] | 114 | $this->$name = $GLOBALS['HTTP_GET_VARS'][$name]; |
---|
| 115 | |
---|
[1506] | 116 | } |
---|
| 117 | |
---|
| 118 | $to_decode = array |
---|
| 119 | ( |
---|
| 120 | 'op' => array('op' => ''), |
---|
| 121 | 'path' => array('path' => ''), |
---|
[1654] | 122 | 'filename' => array('filename' => ''), |
---|
[1506] | 123 | 'file' => array('file' => ''), |
---|
| 124 | 'sortby' => array('sortby' => ''), |
---|
| 125 | 'messages' => array('messages' => ''), |
---|
[1694] | 126 | 'show_upload_boxes' => array('show_upload_boxes' => ''), |
---|
[1732] | 127 | 'from' => array('from' => ''), |
---|
[1694] | 128 | 'to' => array('to' => '') |
---|
| 129 | |
---|
[1506] | 130 | ); |
---|
| 131 | |
---|
| 132 | reset($to_decode); |
---|
| 133 | while(list($var, $conditions) = each($to_decode)) |
---|
| 134 | { |
---|
| 135 | while(list($condvar, $condvalue) = each($conditions)) |
---|
| 136 | { |
---|
| 137 | if(isset($$condvar) && ($condvar == $var || $$condvar == $condvalue)) |
---|
| 138 | { |
---|
| 139 | if(is_array($$var)) |
---|
| 140 | { |
---|
| 141 | $temp = array(); |
---|
| 142 | while(list($varkey, $varvalue) = each($$var)) |
---|
| 143 | { |
---|
| 144 | if(is_int($varkey)) |
---|
| 145 | { |
---|
| 146 | $temp[$varkey] = stripslashes(base64_decode(urldecode(($varvalue)))); |
---|
| 147 | } |
---|
| 148 | else |
---|
| 149 | { |
---|
| 150 | $temp[stripslashes(base64_decode(urldecode(($varkey))))] = $varvalue; |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | $this->$var = $temp; |
---|
| 154 | } |
---|
| 155 | elseif(isset($$var)) |
---|
| 156 | { |
---|
| 157 | $this->$var = stripslashes(base64_decode(urldecode($$var))); |
---|
| 158 | } |
---|
| 159 | } |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | // get appl. and user prefs |
---|
| 164 | $pref = CreateObject('phpgwapi.preferences', $this->bo->userinfo['username']); |
---|
| 165 | $pref->read_repository(); |
---|
[1693] | 166 | //$GLOBALS['phpgw']->hooks->single('add_def_pref', $GLOBALS['appname']); |
---|
[1506] | 167 | $pref->save_repository(True); |
---|
| 168 | $pref_array = $pref->read_repository(); |
---|
| 169 | $this->prefs = $pref_array[$this->bo->appname]; //FIXME check appname var in _debug_array |
---|
| 170 | |
---|
| 171 | //always show name |
---|
| 172 | |
---|
| 173 | $this->prefs[name] =1; |
---|
| 174 | |
---|
| 175 | |
---|
| 176 | if($this->prefs['viewinnewwin']) |
---|
| 177 | { |
---|
| 178 | $this->target = '_blank'; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | |
---|
| 182 | /* |
---|
| 183 | Check for essential directories |
---|
| 184 | admin must be able to disable these tests |
---|
| 185 | */ |
---|
| 186 | |
---|
| 187 | // check if basedir exist |
---|
| 188 | $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir, 'relatives' => array(RELATIVE_NONE), 'relative' => False)); |
---|
| 189 | if($test[mime_type]!='Directory') |
---|
| 190 | { |
---|
| 191 | die('Base directory does not exist, Ask adminstrator to check the global configuration.'); |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->fakebase, 'relatives' => array(RELATIVE_NONE), 'relative' => False)); |
---|
| 195 | if($test[mime_type]!='Directory') |
---|
| 196 | { |
---|
| 197 | |
---|
| 198 | $this->bo->vfs->override_acl = 1; |
---|
| 199 | |
---|
| 200 | $this->bo->vfs->mkdir(array( |
---|
| 201 | 'string' => $this->bo->fakebase, |
---|
| 202 | 'relatives' => array(RELATIVE_NONE) |
---|
| 203 | )); |
---|
| 204 | |
---|
| 205 | $this->bo->vfs->override_acl = 0; |
---|
| 206 | |
---|
| 207 | //test one more time |
---|
| 208 | $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->fakebase, 'relatives' => array(RELATIVE_NONE), 'relative' => False)); |
---|
| 209 | |
---|
| 210 | if($test[mime_type]!='Directory') |
---|
| 211 | { |
---|
| 212 | die('Fake Base directory does not exist and could not be created, please ask the administrator to check the global configuration.'); |
---|
| 213 | } |
---|
| 214 | else |
---|
| 215 | { |
---|
[1737] | 216 | $this->messages[]= lang('Fake Base Dir did not exist, created a new one.'); |
---|
[1506] | 217 | } |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->homedir, 'relatives' => array(RELATIVE_NONE), 'relative' => False)); |
---|
| 221 | if($test[mime_type]!='Directory') |
---|
| 222 | { |
---|
| 223 | $this->bo->vfs->override_acl = 1; |
---|
| 224 | |
---|
| 225 | $this->bo->vfs->mkdir(array( |
---|
| 226 | 'string' => $this->bo->homedir, |
---|
| 227 | 'relatives' => array(RELATIVE_NONE) |
---|
| 228 | )); |
---|
[1627] | 229 | $this->bo->vfs->set_quota(array( |
---|
| 230 | 'string' => $this->bo->homedir, |
---|
| 231 | 'relatives' => array(RELATIVE_NONE), |
---|
| 232 | 'new_quota' => $this->current_config['filemanager_quota_size'] |
---|
| 233 | )); |
---|
| 234 | |
---|
[1506] | 235 | $this->bo->vfs->override_acl = 0; |
---|
| 236 | |
---|
| 237 | //test one more time |
---|
| 238 | $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->homedir, 'relatives' => array(RELATIVE_NONE), 'relative' => False)); |
---|
| 239 | |
---|
| 240 | if($test[mime_type]!='Directory') |
---|
| 241 | { |
---|
| 242 | die('Your Home Dir does not exist and could not be created, please ask the adminstrator to check the global configuration.'); |
---|
| 243 | } |
---|
| 244 | else |
---|
| 245 | { |
---|
[1627] | 246 | $this->messages[]= lang('Your Home Dir did not exist, eGroupWare created a new one.'); |
---|
[1506] | 247 | // FIXME we just created a fresh home dir so we know there nothing in it so we have to remove all existing content |
---|
| 248 | } |
---|
[1693] | 249 | |
---|
| 250 | |
---|
[1506] | 251 | } |
---|
| 252 | } |
---|
[1627] | 253 | function fileModels() |
---|
| 254 | { |
---|
| 255 | $GLOBALS['phpgw_info']['flags'] = array |
---|
| 256 | ( |
---|
| 257 | 'currentapp' => 'filemanager', |
---|
| 258 | 'noheader' => False, |
---|
| 259 | 'nonavbar' => False, |
---|
| 260 | 'nofooter' => False, |
---|
| 261 | 'noappheader' => False, |
---|
| 262 | 'enable_browser_class' => True |
---|
| 263 | ); |
---|
[1506] | 264 | |
---|
[1627] | 265 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
| 266 | $this->t->set_file(array('models' => 'fileModels.tpl')); |
---|
| 267 | $this->t->set_block('models','header','header'); |
---|
| 268 | $this->t->set_block('models','body','body'); |
---|
| 269 | $this->t->set_block('models','footer','footer'); |
---|
| 270 | $this->t->set_var('url_1', './index.php?menuaction=filemanager.uifilemanager.uploadModel&model=article'); |
---|
| 271 | $this->t->set_var('model_1','article'); |
---|
| 272 | $this->t->set_var('lang_1',lang('article')); |
---|
| 273 | |
---|
| 274 | $this->t->set_var('url_2','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=calendar'); |
---|
| 275 | $this->t->set_var('model_2','calendar'); |
---|
| 276 | $this->t->set_var('lang_2',lang('calendar')); |
---|
| 277 | |
---|
| 278 | $this->t->set_var('url_3','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=todo'); |
---|
| 279 | $this->t->set_var('model_3','todo'); |
---|
| 280 | $this->t->set_var('lang_3',lang('todo')); |
---|
| 281 | |
---|
| 282 | $this->t->set_var('url_4','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=slide'); |
---|
| 283 | $this->t->set_var('model_4','slide'); |
---|
| 284 | $this->t->set_var('lang_4',lang('slide')); |
---|
| 285 | |
---|
| 286 | $this->t->set_var('url_5','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=cards'); |
---|
| 287 | $this->t->set_var('model_5','cards'); |
---|
| 288 | $this->t->set_var('lang_5',lang('cards')); |
---|
| 289 | |
---|
| 290 | $this->t->set_var('url_6','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=resume'); |
---|
| 291 | $this->t->set_var('model_6','resume'); |
---|
| 292 | $this->t->set_var('lang_6',lang('resume')); |
---|
| 293 | |
---|
| 294 | |
---|
| 295 | $this->t->pparse('out','models'); |
---|
| 296 | |
---|
| 297 | |
---|
| 298 | } |
---|
| 299 | function uploadModel(){ |
---|
| 300 | $GLOBALS['phpgw_info']['flags'] = array |
---|
| 301 | ( |
---|
| 302 | 'currentapp' => 'filemanager', |
---|
| 303 | 'noheader' => False, |
---|
| 304 | 'nonavbar' => False, |
---|
| 305 | 'nofooter' => False, |
---|
| 306 | 'noappheader' => False, |
---|
| 307 | 'enable_browser_class' => True |
---|
| 308 | ); |
---|
| 309 | |
---|
| 310 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
| 311 | |
---|
| 312 | $filename = lang('new')."_".lang($this->model).rand(0,1000).".html"; |
---|
| 313 | $this->bo->vfs->cp(array( |
---|
| 314 | 'from'=> PHPGW_SERVER_ROOT . '/filemanager/templates/default/'.$this->model.'.html', |
---|
| 315 | 'to'=> $filename, |
---|
| 316 | 'relatives' => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL) |
---|
| 317 | )); |
---|
| 318 | |
---|
| 319 | $this->bo->vfs->set_attributes(array( |
---|
| 320 | 'string'=> $filename, |
---|
| 321 | 'relatives' => array(RELATIVE_ALL), |
---|
| 322 | 'attributes'=> array( |
---|
| 323 | 'mime_type' => "text/html", |
---|
| 324 | 'comment' => "" |
---|
| 325 | ) |
---|
| 326 | )); |
---|
[1654] | 327 | $this->filename = $filename; |
---|
[1627] | 328 | $this->edit(); |
---|
| 329 | |
---|
| 330 | } |
---|
[1506] | 331 | function index() |
---|
| 332 | { |
---|
[1648] | 333 | $GLOBALS['phpgw_info']['flags'] = array |
---|
| 334 | ( |
---|
| 335 | 'currentapp' => 'filemanager', |
---|
| 336 | 'noheader' => False, |
---|
| 337 | 'nonavbar' => False, |
---|
| 338 | 'nofooter' => False, |
---|
| 339 | 'noappheader' => False, |
---|
| 340 | 'enable_browser_class' => True |
---|
| 341 | ); |
---|
[1506] | 342 | |
---|
[1648] | 343 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
[1506] | 344 | |
---|
[1556] | 345 | echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/global.js'></script>"; |
---|
[1529] | 346 | echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/main.js'></script>"; |
---|
| 347 | echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/common_functions.js'></script>"; |
---|
[1575] | 348 | echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/connector.js'></script>"; |
---|
[1654] | 349 | echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/draw_api.js'></script>"; |
---|
[1804] | 350 | echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/drag_area.js'></script>"; |
---|
[1846] | 351 | echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/handler.js'></script>"; |
---|
[1879] | 352 | echo "<script src='./phpgwapi/js/dftree/dftree.js'></script>"; |
---|
[1854] | 353 | |
---|
[1529] | 354 | include('load_lang.php'); |
---|
[1506] | 355 | |
---|
| 356 | # Page to process users |
---|
| 357 | # Code is fairly hackish at the beginning, but it gets better |
---|
| 358 | # Highly suggest turning wrapping off due to long SQL queries |
---|
| 359 | |
---|
| 360 | ### |
---|
| 361 | # Some hacks to set and display directory paths correctly |
---|
| 362 | ### |
---|
| 363 | // new method for switching to a new dir. |
---|
| 364 | if($this->changedir=='true' && $this->cdtodir || $this->goto_x) |
---|
| 365 | { |
---|
| 366 | $this->path = $this->cdtodir; |
---|
| 367 | } |
---|
| 368 | |
---|
| 369 | if(!$this->path) |
---|
| 370 | { |
---|
| 371 | $this->path = $this->bo->vfs->pwd(); |
---|
| 372 | |
---|
| 373 | if(!$this->path || $this->bo->vfs->pwd(array('full' => False)) == '') |
---|
| 374 | { |
---|
| 375 | $this->path = $this->bo->homedir; |
---|
| 376 | } |
---|
| 377 | } |
---|
| 378 | |
---|
| 379 | $this->bo->vfs->cd(array('string' => False, 'relatives' => array(RELATIVE_NONE), 'relative' => False)); |
---|
| 380 | $this->bo->vfs->cd(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE), 'relative' => False)); |
---|
| 381 | |
---|
| 382 | $pwd = $this->bo->vfs->pwd(); |
---|
| 383 | |
---|
| 384 | if(!$this->cwd = substr($this->path, strlen($this->bo->homedir) + 1)) |
---|
| 385 | { |
---|
| 386 | $this->cwd = '/'; |
---|
| 387 | } |
---|
| 388 | else |
---|
| 389 | { |
---|
| 390 | $this->cwd = substr($pwd, strrpos($pwd, '/') + 1); |
---|
| 391 | } |
---|
| 392 | |
---|
| 393 | $this->disppath = $this->path; |
---|
| 394 | |
---|
| 395 | /* This just prevents // in some cases */ |
---|
| 396 | if($this->path == '/') |
---|
| 397 | { |
---|
| 398 | $this->dispsep = ''; |
---|
| 399 | } |
---|
| 400 | else |
---|
| 401 | { |
---|
| 402 | $this->dispsep = '/'; |
---|
| 403 | } |
---|
| 404 | |
---|
| 405 | if(!($this->lesspath = substr($this->path, 0, strrpos($this->path, '/')))) |
---|
| 406 | { |
---|
| 407 | $this->lesspath = '/'; |
---|
| 408 | } |
---|
| 409 | |
---|
[1726] | 410 | $this->update_groups(); |
---|
[1506] | 411 | $this->groups_applications = array(); |
---|
| 412 | |
---|
[1508] | 413 | foreach ($this->readable_groups as $value) |
---|
[1506] | 414 | { |
---|
[1508] | 415 | $applications = CreateObject('phpgwapi.applications', $value['account_id']); |
---|
| 416 | $this->groups_applications[$value['account_name']] = $applications->read_account_specific(); |
---|
[1506] | 417 | } |
---|
| 418 | |
---|
[1804] | 419 | /*Check permission*/ |
---|
| 420 | if($this->bo->vfs->acl_check(array( |
---|
| 421 | 'string' => $this->path, |
---|
| 422 | 'relatives' => array(RELATIVE_NONE), |
---|
| 423 | 'operation' => PHPGW_ACL_READ |
---|
| 424 | ))) |
---|
[1506] | 425 | { |
---|
[1648] | 426 | $this->can_read = True; |
---|
| 427 | } |
---|
[1804] | 428 | |
---|
[1821] | 429 | |
---|
| 430 | if ($_SESSION['phpgw_info']['user']['filemanager']['flush'] != 'flushed') |
---|
| 431 | { |
---|
| 432 | /*Flush journal-deleted*/ |
---|
| 433 | $this->bo->vfs->flush_journal(array( |
---|
| 434 | 'string' => $this->path, |
---|
| 435 | 'relatives' => array(RELATIVE_NONE), |
---|
| 436 | 'deleteall' => True |
---|
| 437 | )); |
---|
| 438 | $_SESSION['phpgw_info']['user']['filemanager']['flush'] = 'flushed'; |
---|
| 439 | } |
---|
| 440 | |
---|
| 441 | |
---|
| 442 | |
---|
[1648] | 443 | # if is different path than home and no permission allowed |
---|
| 444 | if($this->path != $this->bo->homedir && $this->path != $this->bo->fakebase && $this->path != '/' && !$this->can_read) |
---|
| 445 | { |
---|
[1791] | 446 | $this->messages[] = lang('You do not have access to %1', $this->path); |
---|
| 447 | $this->path = $this->homedir; |
---|
| 448 | $this->bo->vfs->cd(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE), 'relative' => False)); |
---|
[1506] | 449 | $GLOBALS['phpgw']->common->phpgw_footer(); |
---|
| 450 | $GLOBALS['phpgw']->common->phpgw_exit(); |
---|
| 451 | } |
---|
| 452 | |
---|
| 453 | $this->bo->userinfo['working_id'] = $this->bo->vfs->working_id; |
---|
| 454 | $this->bo->userinfo['working_lid'] = $GLOBALS['phpgw']->accounts->id2name($this->bo->userinfo['working_id']); |
---|
| 455 | |
---|
| 456 | # Verify path is real |
---|
| 457 | if($this->path != $this->bo->homedir && $this->path != '/' && $this->path != $this->bo->fakebase) |
---|
| 458 | { |
---|
| 459 | if(!$this->bo->vfs->file_exists(array( |
---|
| 460 | 'string' => $this->path, |
---|
| 461 | 'relatives' => array(RELATIVE_NONE) |
---|
| 462 | ))) |
---|
| 463 | { |
---|
[1627] | 464 | $this->messages[] = lang('Error:').lang('Directory %1 does not exist', $this->path); |
---|
[1791] | 465 | $this->path = $this->homedir; |
---|
| 466 | $this->bo->vfs->cd(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE), 'relative' => False)); |
---|
[1506] | 467 | $GLOBALS['phpgw']->common->phpgw_footer(); |
---|
| 468 | $GLOBALS['phpgw']->common->phpgw_exit(); |
---|
| 469 | } |
---|
| 470 | } |
---|
| 471 | |
---|
[1556] | 472 | |
---|
[1506] | 473 | # Default is to sort by name |
---|
| 474 | if(!$this->sortby) |
---|
| 475 | { |
---|
| 476 | $this->sortby = 'name'; |
---|
| 477 | } |
---|
| 478 | |
---|
| 479 | # main action switch |
---|
| 480 | // FIXME this will become a switch |
---|
| 481 | if($this->newfile_x && $this->newfile_or_dir) // create new textfile |
---|
| 482 | { |
---|
| 483 | $this->createfile(); |
---|
| 484 | } |
---|
| 485 | elseif($this->copy_to_x) |
---|
| 486 | { |
---|
| 487 | $this->copyTo(); |
---|
| 488 | } |
---|
| 489 | elseif($this->move_to_x) |
---|
| 490 | { |
---|
| 491 | $this->moveTo(); |
---|
| 492 | } |
---|
| 493 | elseif($this->edit_cancel_x) |
---|
| 494 | { |
---|
| 495 | $this->readFilesInfo(); |
---|
| 496 | $this->fileListing(); |
---|
| 497 | } |
---|
| 498 | elseif($this->edit_x || $this->edit_preview_x || $this->edit_save_x || $this->edit_save_done_x) |
---|
| 499 | { |
---|
| 500 | $this->edit(); |
---|
| 501 | } |
---|
| 502 | else |
---|
| 503 | { |
---|
| 504 | $this->readFilesInfo(); |
---|
| 505 | $this->fileListing(); |
---|
| 506 | } |
---|
| 507 | } |
---|
[1719] | 508 | function get_permissions(){ |
---|
| 509 | /* get permissions */ |
---|
| 510 | if((preg_match('+^'.$this->bo->fakebase.'\/(.*)(\/|$)+U', $this->path, $matches)) && $matches[1] != $this->bo->userinfo['account_lid']) //FIXME matches not defined |
---|
| 511 | |
---|
| 512 | { |
---|
| 513 | $this->bo->vfs->working_id = $GLOBALS['phpgw']->accounts->name2id($matches[1]);//FIXME matches not defined |
---|
| 514 | |
---|
| 515 | } |
---|
| 516 | else |
---|
| 517 | { |
---|
| 518 | $this->bo->vfs->working_id = $this->bo->userinfo['username']; |
---|
| 519 | } |
---|
| 520 | |
---|
| 521 | # Check available permissions for $this->path, so we can disable unusable operations in user interface |
---|
| 522 | $path = explode('/',$this->path); |
---|
| 523 | $owner_id = $this->bo->vfs->ownerOf($this->bo->fakebase,$path[2]); |
---|
| 524 | $user_id = $GLOBALS['phpgw_info']['user']['account_id']; |
---|
| 525 | if ($owner_id == $user_id) |
---|
| 526 | { |
---|
| 527 | $rights = 31; |
---|
| 528 | }else |
---|
| 529 | { |
---|
| 530 | $acl = CreateObject ('phpgwapi.acl', $owner_id); |
---|
| 531 | $acl->account_id = $owner_id; |
---|
| 532 | $acl->read_repository(); |
---|
| 533 | $rights = $acl->get_rights($user_id); |
---|
| 534 | } |
---|
[1785] | 535 | return $rights; |
---|
[1719] | 536 | } |
---|
| 537 | function dir_ls() |
---|
| 538 | { |
---|
[1781] | 539 | // change dir to this->path |
---|
| 540 | $this->bo->vfs->cd(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE), 'relative' => False)); |
---|
[1785] | 541 | $return['permissions'] = $this->get_permissions(); |
---|
| 542 | $return['quota']['usedSpace'] = $this->bo->vfs->get_size(array( |
---|
| 543 | 'string' => $this->path, |
---|
| 544 | 'relatives' => array(RELATIVE_NONE) |
---|
| 545 | )); |
---|
| 546 | $quota = $this->bo->vfs->get_quota(array( |
---|
| 547 | 'string' => $this->path |
---|
| 548 | )); |
---|
[1719] | 549 | reset($this->files_array); |
---|
| 550 | $this->readFilesInfo(); |
---|
| 551 | |
---|
| 552 | for($i = 0; $i != $this->numoffiles; $i++) |
---|
| 553 | { |
---|
| 554 | $files = $this->files_array[$i]; |
---|
| 555 | |
---|
[1879] | 556 | if($files['mime_type'] == "Directory" || (!$this->prefs['dotfiles'] && ereg("^\.", $files['name']))) |
---|
[1719] | 557 | { |
---|
| 558 | continue; |
---|
| 559 | } |
---|
| 560 | /* small keys to safe bandwidth */ |
---|
| 561 | $tuple['name'] = $files['name']; |
---|
| 562 | $tuple['icon'] = $this->mime_icon($files['mime_type']); |
---|
| 563 | $tuple['type'] = $files['type']; |
---|
[1727] | 564 | $tuple['creatd'] = $this->vfs_functions->dateString2timeStamp($files['created']); |
---|
| 565 | $tuple['modifd'] = $this->vfs_functions->dateString2timeStamp($files['modified']); |
---|
[1719] | 566 | $tuple['size'] = $files['size']; |
---|
| 567 | $tuple['mime'] = $files['mime_type']; |
---|
| 568 | $tuple['pub'] = $files['type']; |
---|
| 569 | $tuple['creatdby'] = $GLOBALS['phpgw']->accounts->id2name($files['createdby_id']); |
---|
| 570 | $tuple['modifdby'] = $files['modifiedby_id']?$GLOBALS['phpgw']->accounts->id2name($files['modifiedby_id']):''; |
---|
| 571 | $tuple['owner'] = $GLOBALS['phpgw']->accounts->id2name($files['owner_id']); |
---|
| 572 | $tuple['comm'] = $files['comment']; |
---|
| 573 | $tuple['vers'] = $files['version']; |
---|
| 574 | $output[] = $tuple; |
---|
| 575 | |
---|
| 576 | } |
---|
[1727] | 577 | // TODO Order files directly into SQL |
---|
[1719] | 578 | foreach ($output as $key => $row) { |
---|
[1727] | 579 | $temp[$key] = strtoupper($row[$this->criteria]); |
---|
[1719] | 580 | } |
---|
| 581 | if ($this->otype == "1") |
---|
| 582 | array_multisort($temp, SORT_ASC, $output); |
---|
| 583 | else |
---|
| 584 | array_multisort($temp, SORT_DESC, $output); |
---|
[1785] | 585 | $return['files'] = $output; |
---|
| 586 | $return['quota']['quotaSize'] = ($quota*1024*1024); |
---|
| 587 | echo serialize($return); |
---|
[1719] | 588 | } |
---|
[1879] | 589 | function get_folders_list() |
---|
| 590 | { |
---|
| 591 | $this->update_groups(); |
---|
| 592 | $this->groups_applications = array(); |
---|
[1719] | 593 | |
---|
[1879] | 594 | foreach ($this->readable_groups as $value) |
---|
| 595 | { |
---|
| 596 | $applications = CreateObject('phpgwapi.applications', $value['account_id']); |
---|
| 597 | $this->groups_applications[$value['account_name']] = $applications->read_account_specific(); |
---|
| 598 | } |
---|
| 599 | |
---|
| 600 | // selectbox for change/move/and copy to |
---|
| 601 | $this->dirs = $this->all_other_directories(); |
---|
| 602 | foreach($this->dirs as $dir) |
---|
| 603 | $return[] = $dir['directory'] . $dir['name']; |
---|
| 604 | echo serialize($return); |
---|
| 605 | } |
---|
[1506] | 606 | function fileListing() |
---|
| 607 | { |
---|
[1719] | 608 | $this->t->set_file(array('filemanager_list_t' => 'main.tpl')); |
---|
[1506] | 609 | $this->t->set_block('filemanager_list_t','filemanager_header','filemanager_header'); |
---|
| 610 | $this->t->set_block('filemanager_list_t','filemanager_footer','filemanager_footer'); |
---|
| 611 | |
---|
| 612 | if($this->numoffiles || $this->cwd) |
---|
| 613 | { |
---|
[1654] | 614 | $vars[path]='<input type="hidden" id="currentPath" value="'.$this->path.'">'; |
---|
[1704] | 615 | $vars[css]='<link rel="stylesheet" type="text/css" href="filemanager/templates/default/main.css">'; |
---|
[1879] | 616 | $vars[css].='<link rel="stylesheet" type="text/css" href="phpgwapi/js/dftree/dftree.css">'; |
---|
[1719] | 617 | $vars[preferences]='<input type="hidden" id="userPreferences" value=\''.serialize($_SESSION['phpgw_info']['user']['preferences']['filemanager']).'\'>'; |
---|
[1704] | 618 | $vars[script]='<script>initDrawApi();</script>'; |
---|
[1750] | 619 | |
---|
| 620 | $vars[new_button]=$this->toolButton('new','createfile',lang('New...')); |
---|
| 621 | $vars[new_button].='<input type="hidden" id="newfile_or_dir" name="newfile_or_dir" value="" />'; |
---|
| 622 | |
---|
[1719] | 623 | // reload button with this url |
---|
| 624 | $vars[refresh_button]=$this->toolButton('reload','reload',lang('reload')); |
---|
| 625 | |
---|
[1704] | 626 | // go up icon when we're not at the top, dont allow to go outside /home = fakebase |
---|
| 627 | if($this->path != '/' && $this->path != $this->bo->fakebase) |
---|
| 628 | { |
---|
| 629 | $vars[tools_button] = $this->toolButton('tools','tools',lang('tools')); |
---|
| 630 | } |
---|
| 631 | else |
---|
| 632 | $vars[tools_button] = ""; |
---|
| 633 | |
---|
[1879] | 634 | /* $this->dirs=$this->all_other_directories(); |
---|
[1726] | 635 | foreach($this->dirs as $dir) |
---|
[1704] | 636 | if((($dir['directory'] . $dir['name']) != $this->path) && $this->bo->vfs->file_exists(array('string' => $dir['directory'] . $dir['name'],'relatives' => array(RELATIVE_NONE)))) |
---|
| 637 | { |
---|
| 638 | //FIXME replace the html_form_option function |
---|
| 639 | $dirs_options .= $this->html_form_option($dir['directory'] . $dir['name'], $dir['directory'] . $dir['name']); |
---|
| 640 | } |
---|
[1879] | 641 | $toolbar.='<select name="todir" style="visibility:hidden">'.$dirs_options.'</select>';*/ |
---|
[1704] | 642 | |
---|
| 643 | $vars[toolbar1]=$toolbar; |
---|
| 644 | |
---|
[1506] | 645 | if(count($this->messages)>0) |
---|
| 646 | { |
---|
| 647 | foreach($this->messages as $msg) |
---|
| 648 | { |
---|
[1694] | 649 | $messages.='<span>'.$msg.'</span>'; |
---|
[1506] | 650 | } |
---|
| 651 | } |
---|
[1694] | 652 | $this->messages = NULL; |
---|
| 653 | |
---|
[1506] | 654 | $vars[messages]=$messages; |
---|
| 655 | |
---|
| 656 | $this->t->set_var($vars); |
---|
| 657 | $this->t->pparse('out','filemanager_header'); |
---|
| 658 | } |
---|
| 659 | |
---|
| 660 | $this->t->set_var($vars); |
---|
| 661 | $this->t->pparse('out','filemanager_footer'); |
---|
| 662 | |
---|
| 663 | $GLOBALS['phpgw']->common->phpgw_footer(); |
---|
| 664 | $GLOBALS['phpgw']->common->phpgw_exit(); |
---|
| 665 | } |
---|
| 666 | |
---|
| 667 | function readFilesInfo() |
---|
| 668 | { |
---|
| 669 | // start files info |
---|
| 670 | |
---|
| 671 | # Read in file info from database to use in the rest of the script |
---|
| 672 | # $fakebase is a special directory. In that directory, we list the user's |
---|
| 673 | # home directory and the directories for the groups they're in |
---|
| 674 | $this->numoffiles = 0; |
---|
| 675 | if($this->path == $this->bo->fakebase) |
---|
| 676 | { |
---|
| 677 | // FIXME this test can be removed |
---|
| 678 | if(!$this->bo->vfs->file_exists(array('string' => $this->bo->homedir, 'relatives' => array(RELATIVE_NONE)))) |
---|
| 679 | { |
---|
| 680 | $this->bo->vfs->mkdir(array('string' => $this->bo->homedir, 'relatives' => array(RELATIVE_NONE))); |
---|
| 681 | } |
---|
| 682 | |
---|
| 683 | $ls_array = $this->bo->vfs->ls(array( |
---|
| 684 | 'string' => $this->bo->homedir, |
---|
| 685 | 'relatives' => array(RELATIVE_NONE), |
---|
| 686 | 'checksubdirs' => False, |
---|
| 687 | 'nofiles' => True |
---|
| 688 | )); |
---|
[1627] | 689 | |
---|
[1506] | 690 | $this->files_array[] = $ls_array[0]; |
---|
| 691 | $this->numoffiles++; |
---|
| 692 | |
---|
| 693 | reset($this->readable_groups); |
---|
| 694 | while(list($num, $group_array) = each($this->readable_groups)) |
---|
| 695 | { |
---|
| 696 | # If the group doesn't have access to this app, we don't show it |
---|
[1508] | 697 | /*if(!$this->groups_applications[$group_array['account_name']][$this->bo->appname]['enabled']) |
---|
[1506] | 698 | { |
---|
| 699 | continue; |
---|
| 700 | } |
---|
[1508] | 701 | */ |
---|
[1506] | 702 | |
---|
| 703 | |
---|
| 704 | if(!$this->bo->vfs->file_exists(array('string' => $this->bo->fakebase.'/'.$group_array['account_name'],'relatives' => array(RELATIVE_NONE)))) |
---|
| 705 | { |
---|
| 706 | $this->bo->vfs->override_acl = 1; |
---|
| 707 | $this->bo->vfs->mkdir(array( |
---|
| 708 | 'string' => $this->bo->fakebase.'/'.$group_array['account_name'], |
---|
| 709 | 'relatives' => array(RELATIVE_NONE) |
---|
| 710 | )); |
---|
| 711 | |
---|
| 712 | // FIXME we just created a fresh group dir so we know there nothing in it so we have to remove all existing content |
---|
| 713 | |
---|
| 714 | |
---|
| 715 | $this->bo->vfs->override_acl = 0; |
---|
| 716 | |
---|
| 717 | $this->bo->vfs->set_attributes(array('string' => $this->bo->fakebase.'/'.$group_array['account_name'],'relatives' => array(RELATIVE_NONE),'attributes' => array('owner_id' => $group_array['account_id'],'createdby_id' => $group_array['account_id']))); |
---|
| 718 | } |
---|
| 719 | |
---|
| 720 | $ls_array = $this->bo->vfs->ls(array('string' => $this->bo->fakebase.'/'.$group_array['account_name'],'relatives' => array(RELATIVE_NONE),'checksubdirs' => False,'nofiles' => True)); |
---|
| 721 | |
---|
| 722 | $this->files_array[] = $ls_array[0]; |
---|
| 723 | |
---|
| 724 | $this->numoffiles++; |
---|
| 725 | } |
---|
| 726 | } |
---|
| 727 | else |
---|
| 728 | { |
---|
| 729 | $ls_array = $this->bo->vfs->ls(array( |
---|
| 730 | 'string' => $this->path, |
---|
| 731 | 'relatives' => array(RELATIVE_NONE), |
---|
| 732 | 'checksubdirs' => False, |
---|
| 733 | 'nofiles' => False, |
---|
| 734 | 'orderby' => $this->sortby |
---|
| 735 | )); |
---|
| 736 | |
---|
| 737 | while(list($num, $file_array) = each($ls_array)) |
---|
| 738 | { |
---|
| 739 | $this->numoffiles++; |
---|
| 740 | $this->files_array[] = $file_array; |
---|
| 741 | } |
---|
| 742 | } |
---|
| 743 | |
---|
| 744 | if(!is_array($this->files_array)) |
---|
| 745 | { |
---|
| 746 | $this->files_array = array(); |
---|
| 747 | } |
---|
| 748 | // end file count |
---|
| 749 | } |
---|
| 750 | |
---|
| 751 | # Handle Moving Files and Directories |
---|
| 752 | function moveTo() |
---|
| 753 | { |
---|
[1694] | 754 | if(!$this->to) |
---|
[1506] | 755 | { |
---|
[1627] | 756 | $this->messages[] = lang('Error:').lang('Could not move file because no destination directory is given ', $this->disppath.'/'.$file); |
---|
[1506] | 757 | |
---|
| 758 | } |
---|
| 759 | else |
---|
| 760 | { |
---|
[1719] | 761 | $this->to = $this->bo->fakebase.'/'.$this->to; |
---|
[1506] | 762 | while(list($num, $file) = each($this->fileman)) |
---|
| 763 | { |
---|
| 764 | if($this->bo->vfs->mv(array( |
---|
[1732] | 765 | 'from' => $this->from . '/' . $file, |
---|
[1694] | 766 | 'to' => $this->to . '/' . $file, |
---|
[1732] | 767 | 'relatives' => array(RELATIVE_NONE, RELATIVE_NONE) |
---|
[1506] | 768 | ))) |
---|
| 769 | { |
---|
| 770 | $moved++; |
---|
[1841] | 771 | $this->messages[0]=lang('Files moved to %1 successfuly',$this->to); |
---|
[1506] | 772 | } |
---|
| 773 | else |
---|
| 774 | { |
---|
[1737] | 775 | $this->messages[] = lang('Error:').lang('Could not move %1 to %2', $file, $this->to); |
---|
[1506] | 776 | } |
---|
| 777 | } |
---|
| 778 | } |
---|
| 779 | |
---|
| 780 | if($moved) |
---|
| 781 | { |
---|
| 782 | $x=0; |
---|
| 783 | } |
---|
| 784 | |
---|
| 785 | $this->readFilesInfo(); |
---|
| 786 | $this->filelisting(); |
---|
| 787 | } |
---|
| 788 | |
---|
| 789 | // Handle Copying of Files and Directories |
---|
| 790 | function copyTo() |
---|
| 791 | { |
---|
[1694] | 792 | if(!$this->to) |
---|
[1506] | 793 | { |
---|
[1737] | 794 | $this->messages[] = lang('Error:').lang('Could not copy file because no destination directory is given '); |
---|
[1506] | 795 | |
---|
| 796 | } |
---|
| 797 | else |
---|
| 798 | { |
---|
[1719] | 799 | $this->to = $this->bo->fakebase.'/'.$this->to; |
---|
[1506] | 800 | while(list($num, $file) = each($this->fileman)) |
---|
| 801 | { |
---|
| 802 | if($this->bo->vfs->cp(array( |
---|
[1732] | 803 | 'from' => $this->from . '/' . $file, |
---|
[1694] | 804 | 'to' => $this->to . '/' . $file, |
---|
[1732] | 805 | 'relatives' => array(RELATIVE_NONE, RELATIVE_NONE) |
---|
[1506] | 806 | ))) |
---|
| 807 | { |
---|
| 808 | $copied++; |
---|
[1841] | 809 | $this->messages[0] = lang('Files Copied to %1 successfuly', $this->to); |
---|
[1506] | 810 | } |
---|
| 811 | else |
---|
| 812 | { |
---|
[1841] | 813 | $this->messages[] = lang('Error:').lang('Could not copy %1',$file); |
---|
[1506] | 814 | } |
---|
| 815 | } |
---|
| 816 | } |
---|
| 817 | if($copied) |
---|
[1648] | 818 | |
---|
[1506] | 819 | { |
---|
| 820 | $x=0; |
---|
| 821 | } |
---|
| 822 | |
---|
| 823 | $this->readFilesInfo(); |
---|
| 824 | $this->filelisting(); |
---|
| 825 | } |
---|
| 826 | |
---|
[1879] | 827 | function removedir() |
---|
| 828 | { |
---|
| 829 | $now = intval(time() / 5); |
---|
| 830 | for ($i=0;$i<20;$i++) |
---|
| 831 | $now.=$now; |
---|
| 832 | $toRemove = $this->path ^ $now; |
---|
| 833 | if ( $this->bo->vfs->rm(array( 'string' => $toRemove, |
---|
| 834 | 'relatives' => array (RELATIVE_NONE) |
---|
| 835 | )) ) |
---|
| 836 | echo "True"; |
---|
| 837 | else |
---|
| 838 | echo "False"; |
---|
| 839 | } |
---|
[1506] | 840 | function createdir() |
---|
| 841 | { |
---|
[1879] | 842 | if($this->bo->badchar = $this->bo->bad_chars($this->filename, True, True)) |
---|
[1506] | 843 | { |
---|
[1879] | 844 | echo lang('Error:').$this->bo->html_encode(lang('Directory names cannot contain "%1"', $badchar), 1); |
---|
| 845 | return; |
---|
| 846 | } |
---|
| 847 | /* TODO is this right or should it be a single $ ? */ |
---|
| 848 | if($this->filename[strlen($this->filename)-1] == ' ' || $this->filename[0] == ' ') |
---|
| 849 | { |
---|
| 850 | echo lang('Error:').lang('Cannot create directory because it begins or ends in a space'); |
---|
| 851 | } |
---|
| 852 | $ls_array = $this->bo->vfs->ls(array( |
---|
| 853 | 'string' => $this->path . '/' . $this->filename, |
---|
| 854 | 'relatives' => array(RELATIVE_NONE), |
---|
| 855 | 'checksubdirs' => False, |
---|
| 856 | 'nofiles' => True |
---|
| 857 | )); |
---|
| 858 | |
---|
| 859 | $fileinfo = $ls_array[0]; |
---|
| 860 | |
---|
| 861 | if($fileinfo['name']) |
---|
| 862 | { |
---|
| 863 | if($fileinfo['mime_type'] != 'Directory') |
---|
[1506] | 864 | { |
---|
[1879] | 865 | echo lang('Error:').lang('%1 already exists as a file',$fileinfo['name']); |
---|
[1506] | 866 | } |
---|
[1879] | 867 | else |
---|
[1506] | 868 | { |
---|
[1879] | 869 | echo lang('Error:').lang('Directory %1 already exists', $fileinfo['name']); |
---|
[1506] | 870 | } |
---|
[1879] | 871 | } |
---|
| 872 | else |
---|
| 873 | { |
---|
| 874 | if($this->bo->vfs->mkdir(array('string' => $this->filename))) |
---|
[1506] | 875 | { |
---|
[1879] | 876 | echo lang('Created directory %1', $this->disppath.'/'.$this->filename); |
---|
[1506] | 877 | } |
---|
| 878 | else |
---|
| 879 | { |
---|
[1879] | 880 | echo lang('Error:').lang('Could not create %1', $this->disppath.'/'.$this->filename); |
---|
[1506] | 881 | } |
---|
| 882 | } |
---|
[1879] | 883 | echo lang('Directory created'); |
---|
[1506] | 884 | } |
---|
[1693] | 885 | function getReturnExecuteForm(){ |
---|
| 886 | $response = $_SESSION['response']; |
---|
| 887 | $_SESSION['response'] = null; |
---|
| 888 | echo $response; |
---|
| 889 | return; |
---|
| 890 | } |
---|
[1506] | 891 | function showUploadboxes() |
---|
| 892 | { |
---|
[1804] | 893 | $GLOBALS['phpgw_info']['flags'] = array |
---|
| 894 | ( |
---|
| 895 | 'currentapp' => 'filemanager', |
---|
| 896 | 'noheader' => True, |
---|
| 897 | 'nonavbar' => True, |
---|
| 898 | 'nofooter' => True, |
---|
| 899 | 'noappheader' => True |
---|
| 900 | ); |
---|
| 901 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
| 902 | |
---|
[1506] | 903 | $this->t->set_file(array('upload' => 'upload.tpl')); |
---|
| 904 | $this->t->set_block('upload','upload_header','upload_header'); |
---|
| 905 | $this->t->set_block('upload','row','row'); |
---|
| 906 | $this->t->set_block('upload','upload_footer','upload_footer'); |
---|
| 907 | |
---|
[1804] | 908 | if($this->path != '/' && $this->path != $this->bo->fakebase) |
---|
[1506] | 909 | { |
---|
[1693] | 910 | $vars[max_size]=lang('Note: Uploaded is limited to %1MB',($this->current_config['filemanager_Max_file_size'])); |
---|
| 911 | $vars[form_action]=$GLOBALS[phpgw]->link('/filemanager/inc/upload.php'); |
---|
| 912 | //$vars[form_action]=$GLOBALS[phpgw]->link('/index.php','menuaction=filemanager.uifilemanager.index'); |
---|
[1506] | 913 | $vars[path]=$this->path; |
---|
| 914 | $vars[lang_file]=lang('File'); |
---|
| 915 | $vars[lang_comment]=lang('Comment'); |
---|
[1627] | 916 | $vars[num_upload_boxes]=1; |
---|
[1506] | 917 | $this->t->set_var($vars); |
---|
| 918 | $this->t->pparse('out','upload_header'); |
---|
| 919 | |
---|
[1627] | 920 | $this->t->set_var('row_tr_color',$tr_color); |
---|
| 921 | $this->t->parse('rows','row'); |
---|
| 922 | $this->t->pparse('out','row'); |
---|
[1506] | 923 | |
---|
| 924 | $vars[lang_upload]=lang('Upload files'); |
---|
| 925 | $vars[change_upload_boxes].=lang('Show') . ' '; |
---|
| 926 | $this->t->set_var($vars); |
---|
| 927 | $this->t->pparse('out','upload_footer'); |
---|
| 928 | } |
---|
| 929 | } |
---|
| 930 | |
---|
| 931 | /* create textfile */ |
---|
| 932 | function createfile() |
---|
| 933 | { |
---|
[1654] | 934 | $this->filename=$this->newfile_or_dir; |
---|
| 935 | if($this->filename) |
---|
[1506] | 936 | { |
---|
[1654] | 937 | if($badchar = $this->bo->bad_chars($this->filename, True, True)) |
---|
[1506] | 938 | { |
---|
[1627] | 939 | $this->messages[] = lang('Error:').lang('File names cannot contain "%1"',$badchar); |
---|
[1506] | 940 | |
---|
| 941 | $this->fileListing(); |
---|
| 942 | } |
---|
| 943 | |
---|
| 944 | if($this->bo->vfs->file_exists(array( |
---|
[1654] | 945 | 'string'=> $this->filename, |
---|
[1506] | 946 | 'relatives' => array(RELATIVE_ALL) |
---|
| 947 | ))) |
---|
| 948 | { |
---|
[1654] | 949 | $this->messages[]= lang('Error:').lang('File %1 already exists. Please edit it or delete it first.', $this->filename); |
---|
[1506] | 950 | $this->fileListing(); |
---|
| 951 | } |
---|
| 952 | |
---|
| 953 | if($this->bo->vfs->touch(array( |
---|
[1654] | 954 | 'string' => $this->filename, |
---|
[1506] | 955 | 'relatives' => array(RELATIVE_ALL) |
---|
| 956 | ))) |
---|
| 957 | { |
---|
| 958 | $this->edit = 1; |
---|
| 959 | $this->numoffiles++; |
---|
| 960 | $this->edit(); |
---|
| 961 | } |
---|
| 962 | else |
---|
| 963 | { |
---|
[1654] | 964 | $this->messages[]= lang('Error:').lang('File %1 could not be created.', $this->filename); |
---|
[1506] | 965 | $this->fileListing(); |
---|
| 966 | } |
---|
| 967 | } |
---|
| 968 | } |
---|
| 969 | |
---|
| 970 | # Handle Editing files |
---|
| 971 | function edit() |
---|
| 972 | { |
---|
[1654] | 973 | if($this->filename) |
---|
[1533] | 974 | { |
---|
[1654] | 975 | if (! $this->vfs_functions->verifyLock($this->path.'/'.$this->filename,RELATIVE_NONE)){ |
---|
[1590] | 976 | $GLOBALS['phpgw']->redirect('/index.php'); |
---|
| 977 | } |
---|
[1533] | 978 | $ls_array = $this->bo->vfs->ls(array( |
---|
[1654] | 979 | 'string' => $this->path.'/'.$this->filename, |
---|
[1575] | 980 | 'relatives' => array(RELATIVE_NONE), |
---|
[1533] | 981 | 'checksubdirs' => False, |
---|
| 982 | 'nofiles' => True |
---|
| 983 | )); |
---|
[1575] | 984 | $this->bo->vfs->touch(array( |
---|
[1654] | 985 | 'string'=> $this->path.'/'.$this->filename, |
---|
[1575] | 986 | 'relatives' => array(RELATIVE_NONE) |
---|
| 987 | )); |
---|
[1533] | 988 | |
---|
[1627] | 989 | |
---|
[1533] | 990 | if($ls_array[0]['mime_type']) |
---|
| 991 | { |
---|
| 992 | $mime_type = $ls_array[0]['mime_type']; |
---|
| 993 | } |
---|
| 994 | elseif($this->prefs['viewtextplain']) |
---|
| 995 | { |
---|
| 996 | $mime_type = 'text/plain'; |
---|
| 997 | } |
---|
[1575] | 998 | $editable = array('','text/plain','text/csv','text/html','text/text','message/rfc822'); |
---|
[1533] | 999 | |
---|
[1575] | 1000 | if(!in_array($mime_type,$editable)){ |
---|
[1726] | 1001 | $this->messages[] = lang('Error:').lang('Impossible to edit this file'); |
---|
| 1002 | $this->readFilesInfo(); |
---|
| 1003 | $this->fileListing(); |
---|
| 1004 | return; |
---|
[1533] | 1005 | } |
---|
| 1006 | } |
---|
| 1007 | |
---|
[1506] | 1008 | $this->readFilesInfo(); |
---|
| 1009 | |
---|
[1575] | 1010 | if ($mime_type == 'text/html') |
---|
| 1011 | $this->t->set_file(array('filemanager_edit' => 'edit_html.tpl')); |
---|
[1627] | 1012 | else |
---|
[1575] | 1013 | $this->t->set_file(array('filemanager_edit' => 'edit_file.tpl')); |
---|
| 1014 | |
---|
[1627] | 1015 | $this->t->set_block('filemanager_edit','row','row'); |
---|
[1575] | 1016 | |
---|
[1627] | 1017 | |
---|
[1575] | 1018 | $vars[refresh_script] = "<script src='filemanager/js/refresh.js'></script>"; |
---|
| 1019 | |
---|
[1506] | 1020 | $vars[preview_content]=''; |
---|
| 1021 | if($this->edit_file) |
---|
| 1022 | { |
---|
| 1023 | $this->edit_file_content = stripslashes($this->edit_file_content); |
---|
| 1024 | } |
---|
| 1025 | |
---|
| 1026 | if($this->edit_preview_x) |
---|
| 1027 | { |
---|
| 1028 | $content = $this->edit_file_content; |
---|
| 1029 | |
---|
| 1030 | $vars[lang_preview_of]=lang('Preview of %1', $this->path.'/'.$edit_file); |
---|
| 1031 | |
---|
| 1032 | $vars[preview_content]=nl2br($content); |
---|
| 1033 | } |
---|
| 1034 | elseif($this->edit_save_x || $this->edit_save_done_x) |
---|
| 1035 | { |
---|
| 1036 | $content = $this->edit_file_content; |
---|
| 1037 | //die( $content); |
---|
| 1038 | if($this->bo->vfs->write(array( |
---|
[1590] | 1039 | 'string' => $this->path.'/'.$this->edit_file, |
---|
| 1040 | 'relatives' => array(RELATIVE_NONE), |
---|
[1506] | 1041 | 'content' => $content |
---|
| 1042 | ))) |
---|
| 1043 | { |
---|
| 1044 | $this->messages[]=lang('Saved %1', $this->path.'/'.$this->edit_file); |
---|
| 1045 | |
---|
| 1046 | if($this->edit_save_done_x) |
---|
| 1047 | { |
---|
| 1048 | $this->readFilesInfo(); |
---|
| 1049 | $this->fileListing(); |
---|
| 1050 | exit; |
---|
| 1051 | } |
---|
| 1052 | } |
---|
| 1053 | else |
---|
| 1054 | { |
---|
| 1055 | $this->messages[]=lang('Could not save %1', $this->path.'/'.$this->edit_file); |
---|
| 1056 | } |
---|
| 1057 | } |
---|
| 1058 | |
---|
[1654] | 1059 | # If we're in preview or save mode, we only show the file |
---|
| 1060 | # being previewed or saved |
---|
| 1061 | if($this->edit_file &&($this->filename != $this->edit_file)) |
---|
[1506] | 1062 | { |
---|
[1654] | 1063 | continue; |
---|
| 1064 | } |
---|
| 1065 | |
---|
| 1066 | if($this->filename && $this->bo->vfs->file_exists(array( |
---|
| 1067 | 'string' => $this->filename, |
---|
| 1068 | 'relatives' => array(RELATIVE_ALL) |
---|
| 1069 | ))) |
---|
| 1070 | { |
---|
| 1071 | if($this->edit_file) |
---|
[1506] | 1072 | { |
---|
[1654] | 1073 | $content = stripslashes($this->edit_file_content); |
---|
[1506] | 1074 | } |
---|
[1654] | 1075 | else |
---|
[1506] | 1076 | { |
---|
[1654] | 1077 | $content = $this->bo->vfs->read(array('string' => $this->filename)); |
---|
| 1078 | } |
---|
| 1079 | $vars[form_action]= $GLOBALS['phpgw']->link('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->path); |
---|
| 1080 | $vars[edit_file]=$this->filename; |
---|
| 1081 | # We need to include all of the fileman entries for each file's form, |
---|
| 1082 | # so we loop through again |
---|
| 1083 | for($i = 0; $i != $this->numoffiles; $i++) |
---|
| 1084 | { |
---|
| 1085 | if($this->filename) $value='value="'.$this->filename.'"'; |
---|
| 1086 | $vars[filemans_hidden]='<input type="hidden" name="filename" '.$value.' />'; |
---|
| 1087 | } |
---|
| 1088 | $vars[file_content]=$content; |
---|
[1506] | 1089 | |
---|
[1654] | 1090 | $vars[buttonPreview]=$this->inputButton('edit_preview','edit_preview',lang('Preview %1', $this->bo->html_encode($this->fileman[$j], 1))); |
---|
| 1091 | $vars[buttonSave]=$this->inputButton('edit_save','save',lang('Save %1', $this->bo->html_encode($this->filename, 1))); |
---|
| 1092 | $vars[buttonDone]=$this->inputButton('edit_save_done','ok',lang('Save %1, and go back to file listing ', $this->bo->html_encode($this->filename, 1))); |
---|
| 1093 | $vars[buttonCancel]=$this->inputButton('edit_cancel','cancel',lang('Cancel editing %1 without saving', $this->bo->html_encode($this->filename, 1))); |
---|
[1506] | 1094 | |
---|
[1654] | 1095 | if ($mime_type == 'text/html'){ |
---|
| 1096 | $vars[fck_edit] = '<script type="text/javascript" src="filemanager/tp/ckeditor/ckeditor.js"></script> |
---|
| 1097 | <textarea cols="80" id="edit_file_content" name="edit_file_content" rows="10">'.$content.'</textarea> |
---|
| 1098 | <script type="text/javascript"> CKEDITOR.replace( \'edit_file_content\',{ |
---|
| 1099 | removePlugins : \'elementspath\', |
---|
| 1100 | skin : \'office2003\', |
---|
| 1101 | toolbar : [["Source","Preview","-","Cut","Copy","Paste","-","Print", |
---|
| 1102 | "Undo","Redo","-","Find","Replace","-","SelectAll" ], |
---|
| 1103 | ["Table","HorizontalRule","Smiley","SpecialChar","PageBreak","-","Bold", |
---|
| 1104 | "Italic","Underline","Strike","-","Subscript","Superscript", |
---|
| 1105 | "NumberedList","BulletedList","-","Outdent","Indent","Blockquote", |
---|
| 1106 | "JustifyLeft","JustifyCenter","JustifyRight","JustifyBlock", |
---|
| 1107 | "Link", "TextColor","BGColor","Maximize"], |
---|
| 1108 | ["Styles","Format","Font","FontSize"]] |
---|
| 1109 | });</script>'; |
---|
[1506] | 1110 | |
---|
[1654] | 1111 | } |
---|
[1506] | 1112 | |
---|
[1575] | 1113 | |
---|
[1654] | 1114 | $this->t->set_var($vars); |
---|
| 1115 | $this->t->parse('rows','row'); |
---|
| 1116 | $this->t->pparse('out','row'); |
---|
[1575] | 1117 | |
---|
[1506] | 1118 | } |
---|
[1654] | 1119 | |
---|
[1506] | 1120 | } |
---|
| 1121 | |
---|
| 1122 | function history() |
---|
| 1123 | { |
---|
| 1124 | if($this->file) // FIXME this-file is never defined |
---|
| 1125 | { |
---|
| 1126 | $journal_array = $this->bo->vfs->get_journal(array( |
---|
| 1127 | 'string' => $this->file,//FIXME |
---|
| 1128 | 'relatives' => array(RELATIVE_ALL) |
---|
| 1129 | )); |
---|
| 1130 | |
---|
| 1131 | if(is_array($journal_array)) |
---|
| 1132 | { |
---|
| 1133 | $this->html_table_begin(); |
---|
| 1134 | $this->html_table_row_begin(); |
---|
| 1135 | $this->html_table_col_begin(); |
---|
| 1136 | echo lang('Date'); |
---|
| 1137 | $this->html_table_col_end(); |
---|
| 1138 | $this->html_table_col_begin(); |
---|
| 1139 | echo lang('Version'); |
---|
| 1140 | $this->html_table_col_end(); |
---|
| 1141 | $this->html_table_col_begin(); |
---|
| 1142 | echo lang('Who'); |
---|
| 1143 | $this->html_table_col_end(); |
---|
| 1144 | $this->html_table_col_begin(); |
---|
| 1145 | echo lang('Operation'); |
---|
| 1146 | $this->html_table_col_end(); |
---|
| 1147 | $this->html_table_row_end(); |
---|
| 1148 | |
---|
| 1149 | while(list($num, $journal_entry) = each($journal_array)) |
---|
| 1150 | { |
---|
| 1151 | $this->html_table_row_begin(); |
---|
| 1152 | $this->html_table_col_begin(); |
---|
| 1153 | $this->bo->html_text($journal_entry['created'] . ' '); |
---|
| 1154 | $this->html_table_col_end(); |
---|
| 1155 | $this->html_table_col_begin(); |
---|
| 1156 | $this->bo->html_text($journal_entry['version'] . ' ' ); |
---|
| 1157 | $this->html_table_col_end(); |
---|
| 1158 | $this->html_table_col_begin(); |
---|
| 1159 | $this->bo->html_text($GLOBALS['phpgw']->accounts->id2name($journal_entry['owner_id']) . ' '); |
---|
| 1160 | $this->html_table_col_end(); |
---|
| 1161 | $this->html_table_col_begin(); |
---|
| 1162 | $this->bo->html_text($journal_entry['comment']); |
---|
| 1163 | $this->html_table_col_end(); |
---|
| 1164 | } |
---|
| 1165 | |
---|
| 1166 | $this->html_table_end(); |
---|
| 1167 | $GLOBALS['phpgw']->common->phpgw_footer(); |
---|
| 1168 | $GLOBALS['phpgw']->common->phpgw_exit(); |
---|
| 1169 | } |
---|
| 1170 | else |
---|
| 1171 | { |
---|
| 1172 | echo lang('No version history for this file/directory'); |
---|
| 1173 | } |
---|
| 1174 | } |
---|
| 1175 | } |
---|
[1627] | 1176 | function view() |
---|
| 1177 | { |
---|
| 1178 | if (!$this->bo->vfs->acl_check(array( |
---|
| 1179 | 'string' => $this->path, |
---|
| 1180 | 'relatives' => array(RELATIVE_NONE), |
---|
| 1181 | 'operation' => PHPGW_ACL_READ |
---|
| 1182 | ))) |
---|
[1575] | 1183 | { |
---|
[1726] | 1184 | $this->messages[] = lang("You have no permission to access this file"); |
---|
| 1185 | header('Location:'.$this->encode_href('inc/index.php?menuaction=filemanager.uifilemanager.index','&path='.base64_encode($this->bo->homedir))); |
---|
| 1186 | |
---|
| 1187 | return; |
---|
[1575] | 1188 | } |
---|
[1506] | 1189 | if($this->file) //FIXME |
---|
| 1190 | { |
---|
| 1191 | $ls_array = $this->bo->vfs->ls(array( |
---|
| 1192 | 'string' => $this->path.'/'.$this->file,//FIXME |
---|
[1535] | 1193 | 'relatives' => array(RELATIVE_NONE), |
---|
[1506] | 1194 | 'checksubdirs' => False, |
---|
| 1195 | 'nofiles' => True |
---|
| 1196 | )); |
---|
| 1197 | if($ls_array[0]['mime_type']) |
---|
| 1198 | { |
---|
| 1199 | $mime_type = $ls_array[0]['mime_type']; |
---|
| 1200 | } |
---|
| 1201 | elseif($this->prefs['viewtextplain']) |
---|
| 1202 | { |
---|
| 1203 | $mime_type = 'text/plain'; |
---|
| 1204 | } |
---|
[1750] | 1205 | $viewable = array('','text/plain','text/csv','text/html', |
---|
[1781] | 1206 | 'text/text','image/jpeg','image/png','image/gif', |
---|
| 1207 | 'audio/mpeg','video/mpeg'); |
---|
[1506] | 1208 | |
---|
[1781] | 1209 | if(in_array($mime_type,$viewable)) |
---|
[1506] | 1210 | { |
---|
[1693] | 1211 | /*Note: if you put application/octet-stream you force download */ |
---|
[1627] | 1212 | header('Content-type: ' . $mime_type); |
---|
[1726] | 1213 | header('Content-disposition: filename="' . addslashes($this->file) . '"'); |
---|
[1506] | 1214 | Header("Pragma: public"); |
---|
[1781] | 1215 | } |
---|
| 1216 | else |
---|
| 1217 | { |
---|
| 1218 | $GLOBALS['phpgw']->browser->content_header($this->file,$mime_type,$ls_array[0]['size']); |
---|
| 1219 | } |
---|
| 1220 | if ($ls_array[0]['size'] < 10240) |
---|
| 1221 | { |
---|
[1730] | 1222 | echo $this->bo->vfs->read(array( |
---|
| 1223 | 'string' => $this->path.'/'.$this->file,//FIXME |
---|
| 1224 | 'relatives' => array(RELATIVE_NONE) |
---|
| 1225 | )); |
---|
[1506] | 1226 | } |
---|
| 1227 | else |
---|
| 1228 | { |
---|
[1730] | 1229 | $this->bo->vfs->print_content(array( |
---|
| 1230 | 'string' => $this->path.'/'.$this->file, |
---|
| 1231 | 'relatives' => array(RELATIVE_NONE) |
---|
[1781] | 1232 | ) |
---|
| 1233 | ); |
---|
[1506] | 1234 | } |
---|
| 1235 | $GLOBALS['phpgw']->common->phpgw_exit(); |
---|
| 1236 | } |
---|
| 1237 | } |
---|
| 1238 | |
---|
[1575] | 1239 | function export(){ |
---|
| 1240 | if($this->file) |
---|
| 1241 | { |
---|
| 1242 | $ls_array = $this->bo->vfs->ls(array( |
---|
| 1243 | 'string' => $this->path.'/'.$this->file, |
---|
| 1244 | 'relatives' => array(RELATIVE_NONE), |
---|
| 1245 | 'checksubdirs' => False, |
---|
| 1246 | 'nofiles' => True |
---|
| 1247 | )); |
---|
[1627] | 1248 | /*$timestamp = $this->vfs_functions->dateString2timeStamp($ls_array[0]['modified']); |
---|
[1575] | 1249 | if (time() - $timestamp < 60 && $ls_array[0]['modifiedby_id'] != $GLOBALS['phpgw_info']['user']['account_id']); |
---|
| 1250 | { |
---|
[1627] | 1251 | // recently than last minute: someone is editing |
---|
| 1252 | }*/ |
---|
[1575] | 1253 | $mime_type = $ls_array[0]['mime_type']; |
---|
| 1254 | $formats = array('text/html'); |
---|
| 1255 | if(!in_array($mime_type,$formats)){ |
---|
[1726] | 1256 | echo lang('Impossible to export this file'); |
---|
[1575] | 1257 | return False; |
---|
| 1258 | } |
---|
| 1259 | $content = $this->bo->vfs->read(array('string' => $this->path.'/'.$this->file, |
---|
| 1260 | 'relatives' => array(RELATIVE_NONE) |
---|
| 1261 | )); |
---|
| 1262 | |
---|
| 1263 | include_once('filemanager/tp/dompdf/dompdf_config.inc.php'); |
---|
| 1264 | $dompdf = new DOMPDF(); |
---|
| 1265 | $dompdf->load_html($content); |
---|
[1592] | 1266 | $dompdf->set_paper($this->prefs['pdf_paper_type'], $this->prefs['pdf_type']); |
---|
| 1267 | /* Would be nice to implement 'Title','Subject','Author','Creator','CreationDate'*/ |
---|
[1575] | 1268 | $dompdf->render(); |
---|
| 1269 | $dompdf->stream(strtok($this->file,'.').".pdf"); |
---|
| 1270 | $GLOBALS['phpgw']->common->phpgw_exit(); |
---|
| 1271 | } |
---|
| 1272 | } |
---|
[1506] | 1273 | |
---|
| 1274 | //give back an array with all directories except current and dirs that are not accessable |
---|
[1726] | 1275 | function all_other_directories() |
---|
[1506] | 1276 | { |
---|
| 1277 | # First we get the directories in their home directory |
---|
| 1278 | $dirs = array(); |
---|
| 1279 | $dirs[] = array('directory' => $this->bo->fakebase, 'name' => $this->bo->userinfo['account_lid']); |
---|
| 1280 | |
---|
| 1281 | $tmp_arr=array( |
---|
| 1282 | 'string' => $this->bo->homedir, |
---|
| 1283 | 'relatives' => array(RELATIVE_NONE), |
---|
| 1284 | 'checksubdirs' => True, |
---|
| 1285 | 'mime_type' => 'Directory' |
---|
| 1286 | ); |
---|
| 1287 | |
---|
| 1288 | $ls_array = $this->bo->vfs->ls($tmp_arr); |
---|
| 1289 | |
---|
| 1290 | while(list($num, $dir) = each($ls_array)) |
---|
| 1291 | { |
---|
| 1292 | $dirs[] = $dir; |
---|
| 1293 | } |
---|
| 1294 | |
---|
| 1295 | |
---|
| 1296 | # Then we get the directories in their readable groups' home directories |
---|
| 1297 | reset($this->readable_groups); |
---|
| 1298 | while(list($num, $group_array) = each($this->readable_groups)) |
---|
| 1299 | { |
---|
[1524] | 1300 | /* Don't list directories for groups that don't have access |
---|
[1506] | 1301 | if(!$this->groups_applications[$group_array['account_name']][$this->bo->appname]['enabled']) |
---|
| 1302 | { |
---|
[1524] | 1303 | ] continue; |
---|
| 1304 | }*/ |
---|
[1506] | 1305 | |
---|
| 1306 | $dirs[] = array('directory' => $this->bo->fakebase, 'name' => $group_array['account_name']); |
---|
| 1307 | |
---|
| 1308 | $tmp_arr=array( |
---|
| 1309 | 'string' => $this->bo->fakebase.'/'.$group_array['account_name'], |
---|
| 1310 | 'relatives' => array(RELATIVE_NONE), |
---|
| 1311 | 'checksubdirs' => True, |
---|
| 1312 | 'mime_type' => 'Directory' |
---|
| 1313 | ); |
---|
| 1314 | |
---|
| 1315 | $ls_array = $this->bo->vfs->ls($tmp_arr); |
---|
| 1316 | while(list($num, $dir) = each($ls_array)) |
---|
| 1317 | { |
---|
| 1318 | $dirs[] = $dir; |
---|
| 1319 | } |
---|
| 1320 | } |
---|
| 1321 | reset($dirs); |
---|
| 1322 | while(list($num, $dir) = each($dirs)) |
---|
| 1323 | { |
---|
| 1324 | if(!$dir['directory']) |
---|
| 1325 | { |
---|
| 1326 | continue; |
---|
| 1327 | } |
---|
| 1328 | |
---|
| 1329 | # So we don't display // |
---|
| 1330 | if($dir['directory'] != '/') |
---|
| 1331 | { |
---|
| 1332 | $dir['directory'] .= '/'; |
---|
| 1333 | } |
---|
[1704] | 1334 | $return[] = $dir; |
---|
[1506] | 1335 | } |
---|
[1704] | 1336 | return $return; |
---|
[1506] | 1337 | } |
---|
| 1338 | |
---|
[1726] | 1339 | function update_groups() |
---|
| 1340 | { |
---|
| 1341 | # Get their readable groups to be used throughout the script |
---|
| 1342 | $acl = array(); |
---|
| 1343 | $groups = array(); |
---|
| 1344 | $acl = $GLOBALS['phpgw']->acl->get_ids_for_location($GLOBALS['phpgw_info']['user']['account_id'],1,'filemanager'); |
---|
| 1345 | if (is_array($acl)) |
---|
| 1346 | foreach($acl as $key => $value){ |
---|
| 1347 | $info = array(); |
---|
| 1348 | $info = $GLOBALS['phpgw']->accounts->get_account_data($value); |
---|
| 1349 | $groups[$key]['account_id'] = $value; |
---|
| 1350 | $groups[$key]['account_lid'] = $info[$value]['lid']; |
---|
| 1351 | $groups[$key]['account_name'] = $info[$value]['firstname']; |
---|
| 1352 | $groups[$key]['account_lastname'] = $info[$value]['lastname']; |
---|
| 1353 | $groups[$key]['account_fullname'] = $info[$value]['fullname']; |
---|
| 1354 | } |
---|
| 1355 | $this->readable_groups = array(); |
---|
| 1356 | while(list($num, $account) = each($groups)) |
---|
| 1357 | { |
---|
| 1358 | if($this->bo->vfs->acl_check(array('owner_id' => $account['account_id'],'operation' => PHPGW_ACL_READ))) |
---|
| 1359 | { |
---|
| 1360 | $this->readable_groups[$account['account_lid']] = Array('account_id' => $account['account_id'], 'account_name' => $account['account_lid']); |
---|
| 1361 | } |
---|
| 1362 | } |
---|
| 1363 | |
---|
| 1364 | } |
---|
| 1365 | function search() |
---|
| 1366 | { |
---|
| 1367 | /* TODO this is a primitive search */ |
---|
| 1368 | $this->update_groups(); |
---|
| 1369 | $this->dirs = $this->all_other_directories(); |
---|
| 1370 | $path = $this->path; |
---|
| 1371 | if (strlen($this->text) > 3) |
---|
| 1372 | { |
---|
| 1373 | $this->text = strtoupper($this->text); |
---|
| 1374 | foreach($this->dirs as $elem) |
---|
| 1375 | { |
---|
| 1376 | $this->path = $elem['directory'].$elem['name']; |
---|
| 1377 | reset($this->files_array); |
---|
| 1378 | $this->readFilesInfo(); |
---|
| 1379 | for($i = 0; $i < count($this->files_array); $i++) |
---|
| 1380 | { |
---|
| 1381 | $comment = strtoupper($this->files_array[$i]['comment']); |
---|
| 1382 | $name = strtoupper($this->files_array[$i]['name']); |
---|
| 1383 | if (strstr($name,$this->text) || |
---|
[1730] | 1384 | strstr($comment,$this->text) ){ |
---|
[1726] | 1385 | $return[$this->files_array[$i]['directory'].$name] = $this->files_array[$i]; |
---|
[1730] | 1386 | $return[$this->files_array[$i]['directory'].$name]['icon'] = $this->mime_icon($this->files_array[$i]['mime_type']); |
---|
| 1387 | } |
---|
[1726] | 1388 | } |
---|
| 1389 | if (count($return) > 50) |
---|
| 1390 | { |
---|
| 1391 | $return = array_slice($return,0,50); |
---|
| 1392 | break; |
---|
| 1393 | } |
---|
| 1394 | } |
---|
| 1395 | } |
---|
| 1396 | echo serialize(array_values($return)); |
---|
| 1397 | } |
---|
| 1398 | |
---|
[1506] | 1399 | /* seek icon for mimetype else return an unknown icon */ |
---|
| 1400 | function mime_icon($mime_type, $size=16) |
---|
| 1401 | { |
---|
| 1402 | if(!$mime_type) $mime_type='unknown'; |
---|
| 1403 | |
---|
[1575] | 1404 | $mime_type=str_replace ('/','_',$mime_type); |
---|
[1506] | 1405 | |
---|
| 1406 | $img=$GLOBALS['phpgw']->common->image('filemanager','mime'.$size.'_'.strtolower($mime_type)); |
---|
| 1407 | if(!$img) $img=$GLOBALS['phpgw']->common->image('filemanager','mime'.$size.'_unknown'); |
---|
| 1408 | |
---|
[1719] | 1409 | return $img; |
---|
[1506] | 1410 | } |
---|
| 1411 | |
---|
[1704] | 1412 | function toolButton($link,$img='',$description='') |
---|
[1506] | 1413 | { |
---|
| 1414 | $image=$GLOBALS['phpgw']->common->image('filemanager','button_'.strtolower($img)); |
---|
| 1415 | |
---|
| 1416 | if($img) |
---|
| 1417 | { |
---|
[1731] | 1418 | return '<span name="'.$link.'" class="toolButton" onclick="toolbar.control(\''.$link.'\');" title="'.$description.'"><img src="'.$image.'" alt="'.$description.'"/></a><small>'.$description.'</small></span>'; |
---|
[1506] | 1419 | } |
---|
| 1420 | } |
---|
| 1421 | |
---|
[1654] | 1422 | function inputButton($name,$img='',$description='') |
---|
| 1423 | { |
---|
| 1424 | $image=$GLOBALS['phpgw']->common->image('filemanager','button_'.strtolower($img)); |
---|
| 1425 | |
---|
| 1426 | if($img) |
---|
| 1427 | { |
---|
| 1428 | return '<td class="" align="center" valign="middle" height="28" width="70"> |
---|
| 1429 | <input title="'.$description.'" name="'.$name.'" type="image" alt="'.$name.'" src="'.$image.'" value="clicked" /><br><small>'.$description.'</small> |
---|
| 1430 | </td>'; |
---|
| 1431 | } |
---|
| 1432 | } |
---|
[1506] | 1433 | |
---|
| 1434 | |
---|
| 1435 | function html_form_input($type = NULL, $name = NULL, $value = NULL, $maxlength = NULL, $size = NULL, $checked = NULL, $string = '', $return = 1) |
---|
| 1436 | { |
---|
| 1437 | $text = ' '; |
---|
| 1438 | if($type != NULL && $type) |
---|
| 1439 | { |
---|
| 1440 | if($type == 'checkbox') |
---|
| 1441 | { |
---|
| 1442 | $value = $this->bo->string_encode($value, 1); |
---|
| 1443 | } |
---|
| 1444 | $text .= 'type="'.$type.'" '; |
---|
| 1445 | } |
---|
| 1446 | if($name != NULL && $name) |
---|
| 1447 | { |
---|
| 1448 | $text .= 'name="'.$name.'" '; |
---|
| 1449 | } |
---|
| 1450 | if($value != NULL && $value) |
---|
| 1451 | { |
---|
| 1452 | $text .= 'value="'.$value.'" '; |
---|
| 1453 | } |
---|
| 1454 | if(is_int($maxlength) && $maxlength >= 0) |
---|
| 1455 | { |
---|
| 1456 | $text .= 'maxlength="'.$maxlength.'" '; |
---|
| 1457 | } |
---|
| 1458 | if(is_int($size) && $size >= 0) |
---|
| 1459 | { |
---|
| 1460 | $text .= 'size="'.$size.'" '; |
---|
| 1461 | } |
---|
| 1462 | if($checked != NULL && $checked) |
---|
| 1463 | { |
---|
| 1464 | $text .= 'checked '; |
---|
| 1465 | } |
---|
| 1466 | |
---|
| 1467 | return '<input'.$text.$string.'>'; |
---|
| 1468 | } |
---|
| 1469 | |
---|
| 1470 | function html_form_option($value = NULL, $displayed = NULL, $selected = NULL, $return = 0) |
---|
| 1471 | { |
---|
| 1472 | $text = ' '; |
---|
| 1473 | if($value != NULL && $value) |
---|
| 1474 | { |
---|
| 1475 | $text .= ' value="'.$value.'" '; |
---|
| 1476 | } |
---|
| 1477 | if($selected != NULL && $selected) |
---|
| 1478 | { |
---|
| 1479 | $text .= ' selected'; |
---|
| 1480 | } |
---|
| 1481 | return '<option'.$text.'>'.$displayed.'</option>'; |
---|
| 1482 | } |
---|
| 1483 | |
---|
| 1484 | function encode_href($href = NULL, $args = NULL , $extra_args) |
---|
| 1485 | { |
---|
| 1486 | $href = $this->bo->string_encode($href, 1); |
---|
| 1487 | $all_args = $args.'&'.$this->bo->string_encode($extra_args, 1); |
---|
| 1488 | |
---|
| 1489 | $address = $GLOBALS['phpgw']->link($href, $all_args); |
---|
| 1490 | |
---|
| 1491 | return $address; |
---|
| 1492 | } |
---|
| 1493 | |
---|
| 1494 | function html_link($href = NULL, $args = NULL , $extra_args, $text = NULL, $return = 1, $encode = 1, $linkonly = 0, $target = NULL) |
---|
| 1495 | { |
---|
| 1496 | // unset($encode); |
---|
| 1497 | if($encode) |
---|
| 1498 | { |
---|
| 1499 | $href = $this->bo->string_encode($href, 1); |
---|
| 1500 | $all_args = $args.'&'.$this->bo->string_encode($extra_args, 1); |
---|
| 1501 | } |
---|
| 1502 | else |
---|
| 1503 | { |
---|
| 1504 | // $href = $this->bo->string_encode($href, 1); |
---|
| 1505 | $all_args = $args.'&'.$extra_args; |
---|
| 1506 | } |
---|
| 1507 | ### |
---|
| 1508 | # This decodes / back to normal |
---|
| 1509 | ### |
---|
| 1510 | // $all_args = preg_replace("/%2F/", "/", $all_args); |
---|
| 1511 | // $href = preg_replace("/%2F/", "/", $href); |
---|
| 1512 | |
---|
| 1513 | /* Auto-detect and don't disturb absolute links */ |
---|
| 1514 | if(!preg_match("|^http(.{0,1})://|", $href)) |
---|
| 1515 | { |
---|
| 1516 | //Only add an extra / if there isn't already one there |
---|
| 1517 | |
---|
| 1518 | // die(SEP); |
---|
| 1519 | if(!($href[0] == SEP)) |
---|
| 1520 | { |
---|
| 1521 | $href = SEP . $href; |
---|
| 1522 | } |
---|
| 1523 | |
---|
| 1524 | /* $phpgw->link requires that the extra vars be passed separately */ |
---|
| 1525 | // $link_parts = explode("?", $href); |
---|
| 1526 | $address = $GLOBALS['phpgw']->link($href, $all_args); |
---|
| 1527 | // $address = $GLOBALS['phpgw']->link($href); |
---|
| 1528 | } |
---|
| 1529 | else |
---|
| 1530 | { |
---|
| 1531 | $address = $href; |
---|
| 1532 | } |
---|
| 1533 | |
---|
| 1534 | /* If $linkonly is set, don't add any HTML */ |
---|
| 1535 | if($linkonly) |
---|
| 1536 | { |
---|
| 1537 | $rstring = $address; |
---|
| 1538 | } |
---|
| 1539 | else |
---|
| 1540 | { |
---|
| 1541 | if($target) |
---|
| 1542 | { |
---|
| 1543 | $target = 'target='.$target; |
---|
| 1544 | } |
---|
| 1545 | |
---|
| 1546 | $text = trim($text); |
---|
| 1547 | $rstring = '<a href="'.$address.'" '.$target.'>'.$text.'</a>'; |
---|
| 1548 | } |
---|
| 1549 | |
---|
| 1550 | return($this->bo->eor($rstring, $return)); |
---|
| 1551 | } |
---|
| 1552 | |
---|
| 1553 | function html_table_begin($width = NULL, $border = NULL, $cellspacing = NULL, $cellpadding = NULL, $rules = NULL, $string = '', $return = 0) |
---|
| 1554 | { |
---|
| 1555 | if($width != NULL && $width) |
---|
| 1556 | { |
---|
| 1557 | $width = "width=$width"; |
---|
| 1558 | } |
---|
| 1559 | if(is_int($border) && $border >= 0) |
---|
| 1560 | { |
---|
| 1561 | $border = "border=$border"; |
---|
| 1562 | } |
---|
| 1563 | if(is_int($cellspacing) && $cellspacing >= 0) |
---|
| 1564 | { |
---|
| 1565 | $cellspacing = "cellspacing=$cellspacing"; |
---|
| 1566 | } |
---|
| 1567 | if(is_int($cellpadding) && $cellpadding >= 0) |
---|
| 1568 | { |
---|
| 1569 | $cellpadding = "cellpadding=$cellpadding"; |
---|
| 1570 | } |
---|
| 1571 | if($rules != NULL && $rules) |
---|
| 1572 | { |
---|
| 1573 | $rules = "rules=$rules"; |
---|
| 1574 | } |
---|
| 1575 | |
---|
| 1576 | $rstring = "<table $width $border $cellspacing $cellpadding $rules $string>"; |
---|
| 1577 | return($this->bo->eor($rstring, $return)); |
---|
| 1578 | } |
---|
| 1579 | |
---|
| 1580 | function html_table_end($return = 0) |
---|
| 1581 | { |
---|
| 1582 | $rstring = "</table>"; |
---|
| 1583 | return($this->bo->eor($rstring, $return)); |
---|
| 1584 | } |
---|
| 1585 | |
---|
| 1586 | function html_table_row_begin($align = NULL, $halign = NULL, $valign = NULL, $bgcolor = NULL, $string = '', $return = 0) |
---|
| 1587 | { |
---|
| 1588 | if($align != NULL && $align) |
---|
| 1589 | { |
---|
| 1590 | $align = "align=$align"; |
---|
| 1591 | } |
---|
| 1592 | if($halign != NULL && $halign) |
---|
| 1593 | { |
---|
| 1594 | $halign = "halign=$halign"; |
---|
| 1595 | } |
---|
| 1596 | if($valign != NULL && $valign) |
---|
| 1597 | { |
---|
| 1598 | $valign = "valign=$valign"; |
---|
| 1599 | } |
---|
| 1600 | if($bgcolor != NULL && $bgcolor) |
---|
| 1601 | { |
---|
| 1602 | $bgcolor = "bgcolor=$bgcolor"; |
---|
| 1603 | } |
---|
| 1604 | $rstring = "<tr $align $halign $valign $bgcolor $string>"; |
---|
| 1605 | return($this->bo->eor($rstring, $return)); |
---|
| 1606 | } |
---|
| 1607 | |
---|
| 1608 | function html_table_row_end($return = 0) |
---|
| 1609 | { |
---|
| 1610 | $rstring = "</tr>"; |
---|
| 1611 | return($this->bo->eor($rstring, $return)); |
---|
| 1612 | } |
---|
| 1613 | |
---|
| 1614 | function html_table_col_begin($align = NULL, $halign = NULL, $valign = NULL, $rowspan = NULL, $colspan = NULL, $string = '', $return = 0) |
---|
| 1615 | { |
---|
| 1616 | if($align != NULL && $align) |
---|
| 1617 | { |
---|
| 1618 | $align = "align=$align"; |
---|
| 1619 | } |
---|
| 1620 | if($halign != NULL && $halign) |
---|
| 1621 | { |
---|
| 1622 | $halign = "halign=$halign"; |
---|
| 1623 | } |
---|
| 1624 | if($valign != NULL && $valign) |
---|
| 1625 | { |
---|
| 1626 | $valign = "valign=$valign"; |
---|
| 1627 | } |
---|
| 1628 | if(is_int($rowspan) && $rowspan >= 0) |
---|
| 1629 | { |
---|
| 1630 | $rowspan = "rowspan=$rowspan"; |
---|
| 1631 | } |
---|
| 1632 | if(is_int($colspan) && $colspan >= 0) |
---|
| 1633 | { |
---|
| 1634 | $colspan = "colspan=$colspan"; |
---|
| 1635 | } |
---|
| 1636 | |
---|
| 1637 | $rstring = "<td $align $halign $valign $rowspan $colspan $string>"; |
---|
| 1638 | return($this->bo->eor($rstring, $return)); |
---|
| 1639 | } |
---|
| 1640 | |
---|
| 1641 | function html_table_col_end($return = 0) |
---|
| 1642 | { |
---|
| 1643 | $rstring = "</td>"; |
---|
| 1644 | return($this->bo->eor($rstring, $return)); |
---|
| 1645 | } |
---|
| 1646 | } |
---|