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