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