source: branches/2.2/filemanager/inc/class.uifilemanager.inc.php @ 4915

Revision 4915, 48.0 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #2199 - Corrigido bug para criar e mover arquivos dentro do filemanager

RevLine 
[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
20class 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') {
[4228]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),
[4220]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                }
[4228]214               
[3638]215        }
[3879]216
[4228]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);
[4915]584                //echo serialize(htmlspecialchars_decode(htmlentities($return)));
[3638]585                echo serialize($return);
586        }
[3879]587
588        function get_folders_list() {
589                $this->update_groups();
[3638]590                $this->groups_applications = array();
591
592                $user_groups = $GLOBALS['phpgw']->accounts->membership();
[3879]593                foreach ($user_groups as $val) {
[3638]594                        $account_name = $GLOBALS['phpgw']->accounts->id2name($val['account_id']);
595                        $this->readable_groups[$account_name] = array(
[3879]596                                 'account_id' => $val['account_id'],
597                                 'account_name' => $account_name
[3638]598                        );
599                }
600
[3879]601                foreach ($this->readable_groups as $value) {
[3638]602                        $applications = CreateObject('phpgwapi.applications', $value['account_id']);
603                        $this->groups_applications[$value['account_name']] = $applications->read_account_specific();
604                }
[3019]605
606
[3638]607                // selectbox for change/move/and copy to
608                $this->dirs = $this->all_other_directories();
[3879]609                foreach ($this->dirs as $dir)
[3638]610                        $return[] = $dir['directory'] . $dir['name'];
611                sort(&$return, SORT_STRING);
[4915]612
[3638]613                echo serialize($return);
614        }
[3879]615
616        function fileListing() {
[3638]617                $this->t->set_file(array('filemanager_list_t' => 'main.tpl'));
[3879]618                $this->t->set_block('filemanager_list_t', 'filemanager_header', 'filemanager_header');
619                $this->t->set_block('filemanager_list_t', 'filemanager_footer', 'filemanager_footer');
[3019]620
[3879]621                if ($this->numoffiles || $this->cwd) {
622                        $vars[path] = '<input type="hidden" id="currentPath" value="' . $this->path . '">';
623                        $vars[css] = '<link rel="stylesheet" type="text/css" href="filemanager/templates/default/main.css">';
[3638]624                        $vars[css].='<link rel="stylesheet" type="text/css" href="phpgwapi/js/dftree/dftree.css">';
625                        $_SESSION['phpgw_info']['user']['preferences']['filemanager']['lid'] = $GLOBALS['phpgw_info']['user']['account_lid'];
[3879]626                        $vars[preferences] = '<input type="hidden" id="userPreferences" value=\'' . serialize($_SESSION['phpgw_info']['user']['preferences']['filemanager']) . '\'>';
[3638]627                        // Used for important operations that needs security
[3879]628                        for ($key = ""; strlen($key) < 150; $key .= chr(rand(48, 95)))
629                                ;
[3638]630                        $_SESSION['phpgw_info']['filemanager']['user']['sec_key'] = $key;
[3879]631                        $vars[sec_key] = '<input type="hidden" id="userKey" value=\'' . $key . '\'>';
632                        $vars[script] = '<script>initDrawApi();</script>';
633
634                        $vars[new_button] = $this->toolButton('new', 'createfile', lang('New...'));
[3638]635                        $vars[new_button].='<input type="hidden" id="newfile_or_dir" name="newfile_or_dir" value="" />';
[3879]636
[3638]637                        // reload button with this url
[3879]638                        $vars[refresh_button] = $this->toolButton('reload', 'reload', lang('reload'));
[3019]639
[3638]640                        // go up icon when we're not at the top, dont allow to go outside /home = fakebase
[3879]641                        if ($this->path != '/' && $this->path != $this->bo->fakebase) {
642                                $vars[tools_button] = $this->toolButton('tools', 'tools', lang('tools'));
[3638]643                        }
644                        else
645                                $vars[tools_button] = "";
[3019]646
[3879]647                        $vars[toolbar1] = $toolbar;
[3019]648
[3879]649                        if (count($this->messages) > 0) {
650                                foreach ($this->messages as $msg) {
651                                        $messages.='<span>' . $msg . '</span>';
[3019]652                                }
653                        }
[3638]654                        $this->messages = NULL;
[3019]655
[3879]656                        $vars[messages] = $messages;
657
[3019]658                        $this->t->set_var($vars);
[3879]659                        $this->t->pparse('out', 'filemanager_header');
[3019]660                }
661
[3638]662                $this->t->set_var($vars);
[3879]663                $this->t->pparse('out', 'filemanager_footer');
[3638]664
665                $GLOBALS['phpgw']->common->phpgw_footer();
666                $GLOBALS['phpgw']->common->phpgw_exit();
667        }
668
[3879]669        function readFilesInfo() {
[3638]670                // start files info
671                # Read in file info from database to use in the rest of the script
672                # $fakebase is a special directory.  In that directory, we list the user's
673                # home directory and the directories for the groups they're in
674                $this->numoffiles = 0;
[3879]675                if ($this->path == $this->bo->fakebase) {
[3638]676                        // FIXME this test can be removed
[3879]677                        if (!$this->bo->vfs->file_exists(array('string' => $this->bo->homedir, 'relatives' => array(RELATIVE_NONE)))) {
[3638]678                                $this->bo->vfs->mkdir(array('string' => $this->bo->homedir, 'relatives' => array(RELATIVE_NONE)));
679                        }
[3019]680
[3638]681                        $ls_array = $this->bo->vfs->ls(array(
[3879]682                                                        'string' => $this->bo->homedir,
683                                                        'relatives' => array(RELATIVE_NONE),
684                                                        'checksubdirs' => False,
685                                                        'nofiles' => True
686                                          ));
[3638]687
688                        $this->files_array[] = $ls_array[0];
689                        $this->numoffiles++;
690
691                        reset($this->readable_groups);
[3879]692                        while (list($num, $group_array) = each($this->readable_groups)) {
[3638]693                                # If the group doesn't have access to this app, we don't show it
[3879]694                                /* if(!$this->groups_applications[$group_array['account_name']][$this->bo->appname]['enabled'])
695                                  {
696                                  continue;
697                                  }
698                                 */
[3019]699
700
[3879]701                                if (!$this->bo->vfs->file_exists(array('string' => $this->bo->fakebase . '/' . $group_array['account_name'], 'relatives' => array(RELATIVE_NONE)))) {
[3638]702                                        $this->bo->vfs->override_acl = 1;
703                                        $this->bo->vfs->mkdir(array(
[3879]704                                                 'string' => $this->bo->fakebase . '/' . $group_array['account_name'],
705                                                 'relatives' => array(RELATIVE_NONE)
[3638]706                                        ));
[3019]707
[3638]708                                        // FIXME we just created a fresh group dir so we know there nothing in it so we have to remove all existing content
[3879]709
710
[3638]711                                        $this->bo->vfs->override_acl = 0;
[3019]712
[3879]713                                        $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]714                                }
[3019]715
[3879]716                                $ls_array = $this->bo->vfs->ls(array('string' => $this->bo->fakebase . '/' . $group_array['account_name'], 'relatives' => array(RELATIVE_NONE), 'checksubdirs' => False, 'nofiles' => True));
[3019]717
[3638]718                                $this->files_array[] = $ls_array[0];
[3019]719
[3638]720                                $this->numoffiles++;
[3019]721                        }
[3879]722                } else {
[3638]723                        $ls_array = $this->bo->vfs->ls(array(
[3879]724                                                        'string' => $this->path,
725                                                        'relatives' => array(RELATIVE_NONE),
726                                                        'checksubdirs' => False,
727                                                        'nofiles' => False,
728                                                        'orderby' => $this->criteria,
729                                                        'otype' => $this->otype,
730                                                        'limit' => $this->limit,
731                                                        'offset' => $this->offset
732                                          ));
[3019]733
[3879]734                        while (list($num, $file_array) = each($ls_array)) {
[3638]735                                $this->numoffiles++;
736                                $this->files_array[] = $file_array;
[3019]737                        }
738                }
[3638]739
[3879]740                if (!is_array($this->files_array)) {
[3638]741                        $this->files_array = array();
742                }
743                // end file count
744        }
[3879]745
746        function removedir() {
[3638]747                //$toRemove = $this->path ^ $_SESSION['phpgw_info']['filemanager']['user']['sec_key'];
748                $toRemove = $this->path;
[3879]749
750                if ($this->bo->vfs->rm(array('string' => $toRemove, 'relatives' => array(RELATIVE_NONE))))
[3638]751                        echo "True";
752                else
753                        echo "False";
754        }
[3879]755
[4915]756        function createdir()
757        {
[3879]758                if ($this->bo->badchar = $this->bo->bad_chars($this->filename, True, True)) {
759                        echo lang('Error:') . $this->bo->html_encode(lang('Directory names cannot contain "%1"', $badchar), 1);
[3638]760                        return;
[3019]761                }
[3638]762                /* TODO is this right or should it be a single $ ? */
[3879]763                if ($this->filename[strlen($this->filename) - 1] == ' ' || $this->filename[0] == ' ') {
764                        echo lang('Error:') . lang('Cannot create directory because it begins or ends in a space');
[3638]765                }
[3879]766
[3638]767                $ls_array = $this->bo->vfs->ls(array(
[3879]768                                                'string' => $this->path . '/' . $this->filename,
769                                                'relatives' => array(RELATIVE_NONE),
770                                                'checksubdirs' => False,
771                                                'nofiles' => True
772                                  ));
[3638]773
774                $fileinfo = $ls_array[0];
775
[4915]776                if ($fileinfo['name'])
777                {
[3879]778                        if ($fileinfo['mime_type'] != 'Directory') {
779                                echo lang('Error:') . lang('%1 already exists as a file', $fileinfo['name']);
780                        } else {
781                                echo lang('Error:') . lang('Directory %1 already exists', $fileinfo['name']);
[3019]782                        }
[4915]783                }
784                else
785                {
[3638]786                        $this->bo->vfs->cd(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
[3879]787
[4915]788                        if ($this->bo->vfs->mkdir(array('string' => $this->filename)))
789                        {
790                                echo "True";
791                                //echo lang('Created directory %1', $this->disppath . '/' . $this->filename);
792                        }
793                        else
794                        {
[3879]795                                echo lang('Error:') . lang('Could not create %1', $this->disppath . '/' . $this->filename);
[3019]796                        }
797                }
[4915]798               
[3638]799        }
[3879]800
801        function getReturnExecuteForm() {
[3638]802                $response = $_SESSION['response'];
[3879]803
[3638]804                unset($_SESSION['response']);
[3879]805
[3638]806                echo $response;
807        }
[3879]808
[3638]809        function showUploadboxes()
810        {
811                $notify = CreateObject('filemanager.notifications');
[3879]812
[3638]813                $var = array(
[3879]814                         'change_upload_boxes'  => lang('Show'),
815                         'form_action'                  => $GLOBALS[phpgw]->link('/filemanager/inc/upload.php'),
816                         'emails_to'                            => $notify->EmailsToSend($GLOBALS['phpgw']->preferences->values['email']),
817                         'lang_file'                            => lang('File(s)'),
818                         'lang_comment'                 => lang('Comment(s)'),
819                         'lang_advanced_upload' => lang('Advanced Upload'),
[3897]820                         'lang_delete'                  => lang('delete'),
[3879]821                         'lang_upload'                  => lang('Upload files'),
822                         'max_size'                             => lang('The maximum size for each file is %1MB', ($this->current_config['filemanager_Max_file_size'])),
823                         'path'                                 => $this->path
[3638]824                );
[3879]825
826                print( serialize($var));
[3638]827        }
[3019]828
[3638]829        /* create textfile */
[3879]830        function createfile()
[3638]831        {
[3879]832                $this->filename = $this->newfile_or_dir;
833                if ($this->filename) {
834                        if ($badchar = $this->bo->bad_chars($this->filename, True, True)) {
835                                $this->messages[] = lang('Error:') . lang('File names cannot contain "%1"', $badchar);
[3019]836
[3638]837                                $this->fileListing();
838                        }
[3019]839
[3879]840                        if ($this->bo->vfs->file_exists(array(
841                                                        'string' => $this->filename,
842                                                        'relatives' => array(RELATIVE_ALL)
843                                          ))) {
844                                $this->messages[] = lang('Error:') . lang('File %1 already exists. Please edit it or delete it first.', $this->filename);
[3638]845                                $this->fileListing();
846                        }
[3019]847
[3879]848                        if ($this->bo->vfs->touch(array(
849                                                        'string' => $this->filename,
850                                                        'relatives' => array(RELATIVE_ALL)
851                                          ))) {
[3638]852                                $this->edit = 1;
853                                $this->numoffiles++;
854                                $this->edit();
[3879]855                        } else {
856                                $this->messages[] = lang('Error:') . lang('File %1 could not be created.', $this->filename);
[3638]857                                $this->fileListing();
858                        }
[3019]859                }
[3638]860        }
[3019]861
[3638]862        # Handle Editing files
[3879]863
864        function edit() {
865                if ($this->filename) {
866                        if (!$this->vfs_functions->verifyLock($this->path . '/' . $this->filename, RELATIVE_NONE)) {
[3638]867                                $GLOBALS['phpgw']->redirect('/index.php');
868                        }
869                        $ls_array = $this->bo->vfs->ls(array(
[3879]870                                                        'string' => $this->path . '/' . $this->filename,
871                                                        'relatives' => array(RELATIVE_NONE),
872                                                        'checksubdirs' => False,
873                                                        'nofiles' => True
874                                          ));
[3638]875                        $this->bo->vfs->touch(array(
[3879]876                                 'string' => $this->path . '/' . $this->filename,
877                                 'relatives' => array(RELATIVE_NONE)
[3638]878                        ));
[3019]879
880
[3879]881                        if ($ls_array[0]['mime_type']) {
[3638]882                                $mime_type = $ls_array[0]['mime_type'];
[3879]883                        } elseif ($this->prefs['viewtextplain']) {
[3638]884                                $mime_type = 'text/plain';
885                        }
[3879]886                        $editable = array('', 'text/plain', 'text/csv', 'text/html', 'text/text', 'message/rfc822');
[3019]887
[3879]888                        if (!in_array($mime_type, $editable)) {
889                                $this->messages[] = lang('Error:') . lang('Impossible to edit this file');
[3638]890                                $this->readFilesInfo();
891                                $this->fileListing();
892                                return;
[3019]893                        }
[3638]894                }
[3019]895
[3638]896                $this->readFilesInfo();
[3019]897
[3638]898                if ($mime_type == 'text/html')
899                        $this->t->set_file(array('filemanager_edit' => 'edit_html.tpl'));
900                else
901                        $this->t->set_file(array('filemanager_edit' => 'edit_file.tpl'));
[3019]902
[3879]903                $this->t->set_block('filemanager_edit', 'row', 'row');
[3019]904
905
[3638]906                $vars[refresh_script] = "<script src='filemanager/js/refresh.js'></script>";
[3019]907
[3879]908                $vars[preview_content] = '';
909                if ($this->edit_file) {
[3638]910                        $this->edit_file_content = stripslashes($this->edit_file_content);
911                }
[3019]912
[3879]913                if ($this->edit_preview_x) {
[3638]914                        $content = $this->edit_file_content;
[3019]915
[3879]916                        $vars[lang_preview_of] = lang('Preview of %1', $this->path . '/' . $edit_file);
[3019]917
[3879]918                        $vars[preview_content] = nl2br($content);
919                } elseif ($this->edit_save_x || $this->edit_save_done_x) {
[3638]920                        $content = $this->edit_file_content;
921                        //die( $content);
[3879]922                        if ($this->bo->vfs->write(array(
923                                                        'string' => $this->path . '/' . $this->edit_file,
924                                                        'relatives' => array(RELATIVE_NONE),
925                                                        'content' => $content
926                                          ))) {
927                                $this->messages[] = lang('Saved %1', $this->path . '/' . $this->edit_file);
[3019]928
[3879]929                                if ($this->edit_save_done_x) {
[3638]930                                        $this->readFilesInfo();
931                                        $this->fileListing();
932                                        exit;
[3019]933                                }
[3879]934                        } else {
935                                $this->messages[] = lang('Could not save %1', $this->path . '/' . $this->edit_file);
[3019]936                        }
[3638]937                }
[3019]938
[3638]939                # If we're in preview or save mode, we only show the file
940                # being previewed or saved
[3879]941                if ($this->edit_file && ($this->filename != $this->edit_file)) {
[3638]942                        continue;
943                }
944
[3879]945                if ($this->filename && $this->bo->vfs->file_exists(array(
946                                                'string' => $this->filename,
947                                                'relatives' => array(RELATIVE_ALL)
948                                  ))) {
949                        if ($this->edit_file) {
[3638]950                                $content = stripslashes($this->edit_file_content);
[3879]951                        } else {
[3638]952                                $content = $this->bo->vfs->read(array('string' => $this->filename));
953                        }
[3879]954                        $vars[form_action] = $GLOBALS['phpgw']->link('/index.php', 'menuaction=filemanager.uifilemanager.index', 'path=' . $this->path);
955                        $vars[edit_file] = $this->filename;
[3638]956                        # We need to include all of the fileman entries for each file's form,
957                        # so we loop through again
[3879]958                        for ($i = 0; $i != $this->numoffiles; $i++) {
959                                if ($this->filename)
960                                        $value = 'value="' . $this->filename . '"';
961                                $vars[filemans_hidden] = '<input type="hidden" name="filename" ' . $value . ' />';
[3638]962                        }
[3879]963                        $vars[file_content] = $content;
[3019]964
[3879]965                        $vars[buttonPreview] = $this->inputButton('edit_preview', 'edit_preview', lang('Preview %1', $this->bo->html_encode($this->fileman[0], 1)));
966                        $vars[buttonSave] = $this->inputButton('edit_save', 'save', lang('Save %1', $this->bo->html_encode($this->filename, 1)));
967                        $vars[buttonDone] = $this->inputButton('edit_save_done', 'ok', lang('Save %1, and go back to file listing ', $this->bo->html_encode($this->filename, 1)));
968                        $vars[buttonCancel] = $this->inputButton('edit_cancel', 'cancel', lang('Cancel editing %1 without saving', $this->bo->html_encode($this->filename, 1)));
[3019]969
[3879]970                        if ($mime_type == 'text/html') {
[3638]971                                $vars[fck_edit] = '<script type="text/javascript" src="filemanager/tp/ckeditor/ckeditor.js"></script>
[3879]972                                        <textarea cols="80" id="edit_file_content" name="edit_file_content" rows="10">' . $content . '</textarea>
[3019]973                                                <script type="text/javascript"> CKEDITOR.replace( \'edit_file_content\',{
974removePlugins : \'elementspath\',
975skin : \'office2003\',
976toolbar : [["Source","Preview","-","Cut","Copy","Paste","-","Print",
977"Undo","Redo","-","Find","Replace","-","SelectAll" ],
978["Table","HorizontalRule","Smiley","SpecialChar","PageBreak","-","Bold",
979"Italic","Underline","Strike","-","Subscript","Superscript",
980"NumberedList","BulletedList","-","Outdent","Indent","Blockquote",
981"JustifyLeft","JustifyCenter","JustifyRight","JustifyBlock",
982"Link", "TextColor","BGColor","Maximize"],
983["Styles","Format","Font","FontSize"]]
984                                });</script>';
[3638]985                        }
[3019]986
987
[3638]988                        $this->t->set_var($vars);
[3879]989                        $this->t->parse('rows', 'row');
990                        $this->t->pparse('out', 'row');
[3019]991                }
[3638]992        }
993
[3885]994        function history()
995        {
996                if ( $this->file)
997                {
998                        // FIXME this-file is never defined
[3638]999                        $journal_array = $this->bo->vfs->get_journal(array(
[3879]1000                                                        'string' => $this->file, //FIXME
1001                                                        'relatives' => array(RELATIVE_ALL)
[3885]1002               
1003                         ));
[3638]1004
[3885]1005                        if ( is_array($journal_array) )
1006                        {
1007                                $historyFile = array();
[3019]1008
[3885]1009                                while ( list($num, $journal_entry) = each($journal_array) )
1010                                {
1011                                        $historyFile[] = array(
1012                                                                                        "created"       => $journal_entry['created'],
1013                                                                                        "version"       => $journal_entry['version'],
1014                                                                                        "who"           => $GLOBALS['phpgw']->accounts->id2name($journal_entry['owner_id']),
1015                                                                                        "operation"     =>      $journal_entry['comment']
1016                                        );
[3638]1017                                }
[3885]1018                               
1019                        echo serialize( $historyFile );
[3638]1020                                $GLOBALS['phpgw']->common->phpgw_footer();
1021                                $GLOBALS['phpgw']->common->phpgw_exit();
[3885]1022                        }
1023                        else
1024                        {
[3638]1025                                echo lang('No version history for this file/directory');
1026                        }
[3019]1027                }
[3638]1028        }
[3879]1029
1030        function view() {
[3638]1031                if (!$this->bo->vfs->acl_check(array(
[3879]1032                                                'string' => $this->path,
1033                                                'relatives' => array(RELATIVE_NONE),
1034                                                'operation' => PHPGW_ACL_READ
1035                                  ))) {
[3638]1036                        $this->messages[] = lang("You have no permission to access this file");
[3879]1037                        header('Location:' . $this->encode_href('inc/index.php?menuaction=filemanager.uifilemanager.index', '&path=' . base64_encode($this->bo->homedir)));
[3638]1038
1039                        return;
1040                }
[3879]1041                if ($this->file) { //FIXME
[3638]1042                        $ls_array = $this->bo->vfs->ls(array(
[3879]1043                                                        'string' => $this->path . '/' . $this->file, //FIXME
1044                                                        'relatives' => array(RELATIVE_NONE),
1045                                                        'checksubdirs' => False,
1046                                                        'nofiles' => True
1047                                          ));
1048                        if ($ls_array[0]['mime_type']) {
[3638]1049                                $mime_type = $ls_array[0]['mime_type'];
[3879]1050                        } elseif ($this->prefs['viewtextplain']) {
[3638]1051                                $mime_type = 'text/plain';
1052                        }
[3879]1053                        $viewable = array('text/plain', 'text/csv', 'text/html',
1054                                 'text/text', 'image/jpeg', 'image/png', 'image/gif',
1055                                 'audio/mpeg', 'video/mpeg');
[3019]1056
[3879]1057                        if (in_array($mime_type, $viewable)) {
1058                                /* Note: if you put application/octet-stream you force download */
[3638]1059                                header('Content-type: ' . $mime_type);
1060                                header('Content-disposition: filename="' . addslashes($this->file) . '"');
1061                                Header("Pragma: public");
[3879]1062                        } else {
1063                                $GLOBALS['phpgw']->browser->content_header($this->file, $mime_type, $ls_array[0]['size']);
[3019]1064                        }
[3879]1065                        if ($ls_array[0]['size'] < 10240) {
[3638]1066                                echo $this->bo->vfs->read(array(
[3879]1067                                         'string' => $this->path . '/' . $this->file, //FIXME
1068                                         'relatives' => array(RELATIVE_NONE)
[3019]1069                                ));
[3879]1070                        } else {
[3638]1071                                $this->bo->vfs->print_content(array(
[3879]1072                                         'string' => $this->path . '/' . $this->file,
1073                                         'relatives' => array(RELATIVE_NONE)
1074                                                  )
1075                                );
[3638]1076                        }
1077                        $GLOBALS['phpgw']->common->phpgw_exit();
[3019]1078                }
[3638]1079        }
[3019]1080
[3936]1081        function export()
1082        {
1083                if ($this->file)
1084                {
[3638]1085                        $ls_array = $this->bo->vfs->ls(array(
[3879]1086                                                        'string' => $this->path . '/' . $this->file,
1087                                                        'relatives' => array(RELATIVE_NONE),
1088                                                        'checksubdirs' => False,
1089                                                        'nofiles' => True
1090                                          ));
[3936]1091
[3638]1092                        $mime_type = $ls_array[0]['mime_type'];
[3936]1093                       
[3638]1094                        $formats = array('text/html');
[3936]1095                       
1096                        if (!in_array($mime_type, $formats))
1097                        {
[3638]1098                                echo lang('Impossible to export this file');
1099                                return False;
1100                        }
[3936]1101                       
[3879]1102                        $content = $this->bo->vfs->read(array('string' => $this->path . '/' . $this->file,
1103                                                        'relatives' => array(RELATIVE_NONE)
1104                                          ));
[3019]1105
[3638]1106                        include_once('filemanager/tp/dompdf/dompdf_config.inc.php');
[3936]1107                       
[3638]1108                        $dompdf = new DOMPDF();
1109                        $dompdf->load_html($content);
1110                        $dompdf->set_paper($this->prefs['pdf_paper_type'], $this->prefs['pdf_type']);
[3879]1111                        /* Would be nice to implement 'Title','Subject','Author','Creator','CreationDate' */
[3638]1112                        $dompdf->render();
[3879]1113                        $dompdf->stream(strtok($this->file, '.') . ".pdf");
[3638]1114                        $GLOBALS['phpgw']->common->phpgw_exit();
[3019]1115                }
[3638]1116        }
[3019]1117
[3638]1118        //give back an array with all directories except current and dirs that are not accessable
[3879]1119        function all_other_directories() {
[3638]1120                # First we get the directories in their home directory
1121                $dirs = array();
1122                $dirs[] = array('directory' => $this->bo->fakebase, 'name' => $this->bo->userinfo['account_lid']);
1123
[3879]1124                $tmp_arr = array(
1125                         'string' => $this->bo->homedir,
1126                         'relatives' => array(RELATIVE_NONE),
1127                         'checksubdirs' => True,
1128                         'mime_type' => 'Directory'
[3638]1129                );
1130
[3879]1131                $ls_array = $this->bo->vfs->ls($tmp_arr, True);
[3638]1132
[3879]1133                while (list($num, $dir) = each($ls_array)) {
[3638]1134                        $dirs[] = $dir;
1135                }
[3019]1136
[3638]1137
1138                # Then we get the directories in their readable groups' home directories
1139                reset($this->readable_groups);
[3879]1140                while (list($num, $group_array) = each($this->readable_groups)) {
[3638]1141                        // Don't list directories for groups that don't exists
[3879]1142                        $test = $this->bo->vfs->get_real_info(array('string' => $this->bo->fakebase . '/' . $group_array['account_name'],
1143                                                        'relatives' => array(RELATIVE_NONE), 'relative' => False));
1144                        if ($test[mime_type] != 'Directory') {
[3638]1145                                continue;
1146                        }
1147
1148                        $dirs[] = array('directory' => $this->bo->fakebase, 'name' => $group_array['account_name']);
1149
[3879]1150                        $tmp_arr = array(
1151                                 'string' => $this->bo->fakebase . '/' . $group_array['account_name'],
1152                                 'relatives' => array(RELATIVE_NONE),
1153                                 'checksubdirs' => True,
1154                                 'mime_type' => 'Directory'
[3019]1155                        );
1156
[3879]1157                        $ls_array = $this->bo->vfs->ls($tmp_arr, True);
1158                        while (list($num, $dir) = each($ls_array)) {
[3019]1159                                $dirs[] = $dir;
1160                        }
[3638]1161                }
1162                reset($dirs);
[3879]1163                while (list($num, $dir) = each($dirs)) {
1164                        if (!$dir['directory']) {
[3638]1165                                continue;
1166                        }
[3019]1167
[3638]1168                        # So we don't display //
[3879]1169                        if ($dir['directory'] != '/') {
[3638]1170                                $dir['directory'] .= '/';
1171                        }
1172                        $return[] = $dir;
1173                }
1174                return $return;
1175        }
[3019]1176
[3879]1177        function update_groups() {
[3638]1178                # Get their readable groups to be used throughout the script
1179                $acl = array();
1180                $groups = array();
[3879]1181                $acl = $GLOBALS['phpgw']->acl->get_ids_for_location($GLOBALS['phpgw_info']['user']['account_id'], 1, 'filemanager');
[3638]1182                if (is_array($acl))
[3879]1183                        foreach ($acl as $key => $value) {
[3638]1184                                $info = array();
1185                                $info = $GLOBALS['phpgw']->accounts->get_account_data($value);
1186                                $groups[$key]['account_id'] = $value;
1187                                $groups[$key]['account_lid'] = $info[$value]['lid'];
1188                                $groups[$key]['account_name'] = $info[$value]['firstname'];
1189                                $groups[$key]['account_lastname'] = $info[$value]['lastname'];
1190                                $groups[$key]['account_fullname'] = $info[$value]['fullname'];
[3019]1191                        }
[3638]1192                $this->readable_groups = array();
[3879]1193                while (list($num, $account) = each($groups)) {
1194                        if ($this->bo->vfs->acl_check(array('owner_id' => $account['account_id'], 'operation' => PHPGW_ACL_READ))) {
[3638]1195                                $this->readable_groups[$account['account_lid']] = Array('account_id' => $account['account_id'], 'account_name' => $account['account_lid']);
[3019]1196                        }
1197                }
[3638]1198        }
[3879]1199
1200        function search() {
[3638]1201                /* TODO this is a primitive search */
1202                $this->update_groups();
[3879]1203                $this->dirs = $this->all_other_directories();
[3638]1204                $path = $this->path;
[3879]1205                if (strlen($this->text) > 3) {
[3638]1206                        $this->text = strtoupper($this->text);
[3879]1207                        foreach ($this->dirs as $elem) {
1208                                $this->path = $elem['directory'] . $elem['name'];
[3638]1209                                reset($this->files_array);
[3879]1210                                $this->readFilesInfo();
1211                                for ($i = 0; $i < count($this->files_array); $i++) {
[3638]1212                                        $comment = strtoupper($this->files_array[$i]['comment']);
1213                                        $name = strtoupper($this->files_array[$i]['name']);
[3879]1214                                        if (strstr($name, $this->text) ||
1215                                                          strstr($comment, $this->text)) {
1216                                                $return[$this->files_array[$i]['directory'] . $name] = $this->files_array[$i];
1217                                                $return[$this->files_array[$i]['directory'] . $name]['icon'] = $this->mime_icon($this->files_array[$i]['mime_type']);
[3638]1218                                        }
[3019]1219                                }
[3879]1220                                if (count($return) > 50) {
1221                                        $return = array_slice($return, 0, 50);
[3638]1222                                        break;
1223                                }
[3879]1224                        }
[3019]1225                }
[3638]1226                echo serialize(array_values($return));
1227        }
[3019]1228
[3638]1229        /* seek icon for mimetype else return an unknown icon */
[3019]1230
[3879]1231        function mime_icon($mime_type, $size=16) {
1232                if (!$mime_type)
1233                        $mime_type = 'unknown';
[3019]1234
[3879]1235                $mime_type = str_replace('/', '_', $mime_type);
[3019]1236
[3879]1237                $img = $GLOBALS['phpgw']->common->image('filemanager', 'mime' . $size . '_' . strtolower($mime_type));
1238                if (!$img)
1239                        $img = $GLOBALS['phpgw']->common->image('filemanager', 'mime' . $size . '_unknown');
1240
[3638]1241                return $img;
1242        }
[3019]1243
[3879]1244        function toolButton($link, $img='', $description='') {
1245                $image = $GLOBALS['phpgw']->common->image('filemanager', 'button_' . strtolower($img));
[3638]1246
[3879]1247                if ($img) {
1248                        return '<div name="' . $link . '" class="toolButton" onclick="toolbar.control(\'' . $link . '\',this);" title="' . $description . '"><img src="' . $image . '" alt="' . $description . '"/><small>' . $description . '</small></div>';
[3019]1249                }
[3638]1250        }
[3019]1251
[3879]1252        function inputButton($name, $img='', $description='') {
1253                $image = $GLOBALS['phpgw']->common->image('filemanager', 'button_' . strtolower($img));
[3638]1254
[3879]1255                if ($img) {
[3638]1256                        return '<td class="" align="center" valign="middle" height="28" width="70">
[3879]1257                        <input title="' . $description . '" name="' . $name . '" type="image" alt="' . $name . '" src="' . $image . '" value="clicked" /><br><small>' . $description . '</small>
[3638]1258                        </td>';
[3019]1259                }
[3638]1260        }
[3019]1261
[3879]1262        function html_form_input($type = NULL, $name = NULL, $value = NULL, $maxlength = NULL, $size = NULL, $checked = NULL, $string = '', $return = 1) {
[3638]1263                $text = ' ';
[3879]1264                if ($type != NULL && $type) {
1265                        if ($type == 'checkbox') {
[3638]1266                                $value = $this->bo->string_encode($value, 1);
[3019]1267                        }
[3879]1268                        $text .= 'type="' . $type . '" ';
[3019]1269                }
[3879]1270                if ($name != NULL && $name) {
1271                        $text .= 'name="' . $name . '" ';
[3019]1272                }
[3879]1273                if ($value != NULL && $value) {
1274                        $text .= 'value="' . $value . '" ';
[3638]1275                }
[3879]1276                if (is_int($maxlength) && $maxlength >= 0) {
1277                        $text .= 'maxlength="' . $maxlength . '" ';
[3638]1278                }
[3879]1279                if (is_int($size) && $size >= 0) {
1280                        $text .= 'size="' . $size . '" ';
[3638]1281                }
[3879]1282                if ($checked != NULL && $checked) {
[3638]1283                        $text .= 'checked ';
1284                }
[3019]1285
[3879]1286                return '<input' . $text . $string . '>';
[3638]1287        }
[3019]1288
[3879]1289        function html_form_option($value = NULL, $displayed = NULL, $selected = NULL, $return = 0) {
[3638]1290                $text = ' ';
[3879]1291                if ($value != NULL && $value) {
1292                        $text .= ' value="' . $value . '" ';
[3019]1293                }
[3879]1294                if ($selected != NULL && $selected) {
[3638]1295                        $text .= ' selected';
1296                }
[3879]1297                return '<option' . $text . '>' . $displayed . '</option>';
[3638]1298        }
[3019]1299
[3879]1300        function encode_href($href = NULL, $args = NULL, $extra_args) {
[3638]1301                $href = $this->bo->string_encode($href, 1);
[3879]1302                $all_args = $args . '&' . $this->bo->string_encode($extra_args, 1);
[3019]1303
[3638]1304                $address = $GLOBALS['phpgw']->link($href, $all_args);
[3019]1305
[3638]1306                return $address;
1307        }
[3019]1308
[3879]1309        function html_link($href = NULL, $args = NULL, $extra_args, $text = NULL, $return = 1, $encode = 1, $linkonly = 0, $target = NULL) {
[3638]1310                //      unset($encode);
[3879]1311                if ($encode) {
[3638]1312                        $href = $this->bo->string_encode($href, 1);
[3879]1313                        $all_args = $args . '&' . $this->bo->string_encode($extra_args, 1);
1314                } else {
[3638]1315                        //                              $href = $this->bo->string_encode($href, 1);
[3879]1316                        $all_args = $args . '&' . $extra_args;
[3638]1317                }
1318                ###
1319                # This decodes / back to normal
1320                ###
1321                //                      $all_args = preg_replace("/%2F/", "/", $all_args);
1322                //                      $href = preg_replace("/%2F/", "/", $href);
[3019]1323
[3638]1324                /* Auto-detect and don't disturb absolute links */
[3879]1325                if (!preg_match("|^http(.{0,1})://|", $href)) {
[3638]1326                        //Only add an extra / if there isn't already one there
1327                        // die(SEP);
[3879]1328                        if (!($href[0] == SEP)) {
[3638]1329                                $href = SEP . $href;
[3019]1330                        }
1331
[3638]1332                        /* $phpgw->link requires that the extra vars be passed separately */
1333                        //                              $link_parts = explode("?", $href);
1334                        $address = $GLOBALS['phpgw']->link($href, $all_args);
1335                        //                              $address = $GLOBALS['phpgw']->link($href);
[3879]1336                } else {
[3638]1337                        $address = $href;
[3019]1338                }
1339
[3638]1340                /* If $linkonly is set, don't add any HTML */
[3879]1341                if ($linkonly) {
[3638]1342                        $rstring = $address;
[3879]1343                } else {
1344                        if ($target) {
1345                                $target = 'target=' . $target;
[3019]1346                        }
[3638]1347
1348                        $text = trim($text);
[3879]1349                        $rstring = '<a href="' . $address . '" ' . $target . '>' . $text . '</a>';
[3019]1350                }
1351
[3638]1352                return($this->bo->eor($rstring, $return));
1353        }
1354
[3879]1355        function html_table_begin($width = NULL, $border = NULL, $cellspacing = NULL, $cellpadding = NULL, $rules = NULL, $string = '', $return = 0) {
1356                if ($width != NULL && $width) {
[3638]1357                        $width = "width=$width";
[3019]1358                }
[3879]1359                if (is_int($border) && $border >= 0) {
[3638]1360                        $border = "border=$border";
1361                }
[3879]1362                if (is_int($cellspacing) && $cellspacing >= 0) {
[3638]1363                        $cellspacing = "cellspacing=$cellspacing";
1364                }
[3879]1365                if (is_int($cellpadding) && $cellpadding >= 0) {
[3638]1366                        $cellpadding = "cellpadding=$cellpadding";
1367                }
[3879]1368                if ($rules != NULL && $rules) {
[3638]1369                        $rules = "rules=$rules";
1370                }
[3019]1371
[3638]1372                $rstring = "<table $width $border $cellspacing $cellpadding $rules $string>";
1373                return($this->bo->eor($rstring, $return));
1374        }
1375
[3879]1376        function html_table_end($return = 0) {
[3638]1377                $rstring = "</table>";
1378                return($this->bo->eor($rstring, $return));
1379        }
1380
[3879]1381        function html_table_row_begin($align = NULL, $halign = NULL, $valign = NULL, $bgcolor = NULL, $string = '', $return = 0) {
1382                if ($align != NULL && $align) {
[3638]1383                        $align = "align=$align";
[3019]1384                }
[3879]1385                if ($halign != NULL && $halign) {
[3638]1386                        $halign = "halign=$halign";
1387                }
[3879]1388                if ($valign != NULL && $valign) {
[3638]1389                        $valign = "valign=$valign";
1390                }
[3879]1391                if ($bgcolor != NULL && $bgcolor) {
[3638]1392                        $bgcolor = "bgcolor=$bgcolor";
1393                }
1394                $rstring = "<tr $align $halign $valign $bgcolor $string>";
1395                return($this->bo->eor($rstring, $return));
1396        }
[3019]1397
[3879]1398        function html_table_row_end($return = 0) {
[3638]1399                $rstring = "</tr>";
1400                return($this->bo->eor($rstring, $return));
1401        }
1402
[3879]1403        function html_table_col_begin($align = NULL, $halign = NULL, $valign = NULL, $rowspan = NULL, $colspan = NULL, $string = '', $return = 0) {
1404                if ($align != NULL && $align) {
[3638]1405                        $align = "align=$align";
[3019]1406                }
[3879]1407                if ($halign != NULL && $halign) {
[3638]1408                        $halign = "halign=$halign";
1409                }
[3879]1410                if ($valign != NULL && $valign) {
[3638]1411                        $valign = "valign=$valign";
1412                }
[3879]1413                if (is_int($rowspan) && $rowspan >= 0) {
[3638]1414                        $rowspan = "rowspan=$rowspan";
1415                }
[3879]1416                if (is_int($colspan) && $colspan >= 0) {
[3638]1417                        $colspan = "colspan=$colspan";
1418                }
1419
1420                $rstring = "<td $align $halign $valign $rowspan $colspan $string>";
1421                return($this->bo->eor($rstring, $return));
[3019]1422        }
[3638]1423
[3879]1424        function html_table_col_end($return = 0) {
[3638]1425                $rstring = "</td>";
1426                return($this->bo->eor($rstring, $return));
1427        }
[3879]1428
[3638]1429}
Note: See TracBrowser for help on using the repository browser.