source: trunk/filemanager/inc/class.uifilemanager.inc.php @ 5038

Revision 5038, 47.9 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #2260 - Sincronismo do branch2.2(versão 2.2.8) do modulo filemanager para 2.4

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') {
[4284]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),
[4284]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                }
[4284]214               
[3638]215        }
[3879]216
[4284]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               
339                // Temas Expresso
340                $theme = "window_" . $GLOBALS['phpgw_info']['user']['preferences']['common']['theme'] . ".css";
[3568]341
[3879]342                if (!file_exists('filemanager/tp/expressowindow/css/' . $theme))
[3638]343                        $theme = "window_default.css";
[3568]344
[3638]345                // Path FileManager
346                $webserver_url = $GLOBALS['phpgw_info']['server']['webserver_url'];
[3879]347                $webserver_url = (!empty($webserver_url) ) ? $webserver_url : '/';
348
349                if (strrpos($webserver_url, '/') === false || strrpos($webserver_url, '/') != (strlen($webserver_url) - 1))
[3638]350                        $webserver_url .= '/';
[3568]351
[3879]352                $webserver_url = $webserver_url . 'filemanager/';
353
354                $js = "var path_filemanager     = '" . $webserver_url . "';";
355                $js .= "var my_home_filemanager = '" . trim($GLOBALS['uifilemanager']->bo->vfs->my_home) . "';";
356
357                echo "<script type='text/javascript'>" . $js . "</script>";
358
[3638]359                // Expresso Window - CSS
[3879]360                print '<link rel="stylesheet" type="text/css" href="' . $webserver_url . 'tp/expressowindow/css/' . $theme . '" >';
[3569]361
[3638]362                // Expresso Window - JS
[3879]363                echo "<script src='" . $GLOBALS['phpgw_info']['flags']['currentapp'] . "/tp/expressowindow/js/xtools.js'></script>";
364                echo "<script src='" . $GLOBALS['phpgw_info']['flags']['currentapp'] . "/tp/expressowindow/js/jsloader.js'></script>";
365                echo "<script src='" . $GLOBALS['phpgw_info']['flags']['currentapp'] . "/tp/expressowindow/js/makeW.js'></script>";
366                echo "<script src='" . $GLOBALS['phpgw_info']['flags']['currentapp'] . "/tp/expressowindow/js/dragdrop.js'></script>";
367                echo "<script src='" . $GLOBALS['phpgw_info']['flags']['currentapp'] . "/tp/expressowindow/js/show_hidden.js'></script>";
[3436]368
[3638]369                echo "<script src='./phpgwapi/js/dftree/dftree.js'></script>";
[3019]370
[3638]371                # Page to process users
372                # Code is fairly hackish at the beginning, but it gets better
373                # Highly suggest turning wrapping off due to long SQL queries
374                ###
375                # Some hacks to set and display directory paths correctly
376                ###
377                // new method for switching to a new dir.
[3879]378                if ($this->changedir == 'true' && $this->cdtodir || $this->goto_x) {
[3638]379                        $this->path = $this->cdtodir;
380                }
381
[3879]382                if (!$this->path) {
[3638]383                        $this->path = $this->bo->vfs->pwd();
384
[3879]385                        if (!$this->path || $this->bo->vfs->pwd(array('full' => False)) == '') {
386                                $this->path = $this->bo->homedir;
[3019]387                        }
[3638]388                }
[3019]389
[3638]390                $this->bo->vfs->cd(array('string' => False, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
391                $this->bo->vfs->cd(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
[3019]392
[3638]393                $pwd = $this->bo->vfs->pwd();
[3019]394
[3879]395                if (!$this->cwd = substr($this->path, strlen($this->bo->homedir) + 1)) {
[3638]396                        $this->cwd = '/';
[3879]397                } else {
[3638]398                        $this->cwd = substr($pwd, strrpos($pwd, '/') + 1);
399                }
[3019]400
[3638]401                $this->disppath = $this->path;
[3019]402
[3638]403                /* This just prevents // in some cases */
[3879]404                if ($this->path == '/') {
[3638]405                        $this->dispsep = '';
[3879]406                } else {
[3638]407                        $this->dispsep = '/';
408                }
[3019]409
[3879]410                if (!($this->lesspath = substr($this->path, 0, strrpos($this->path, '/')))) {
[3638]411                        $this->lesspath = '/';
412                }
[3019]413
[3879]414                /* Check permission */
415                if ($this->bo->vfs->acl_check(array(
416                                                'string' => $this->path,
417                                                'relatives' => array(RELATIVE_NONE),
418                                                'operation' => PHPGW_ACL_READ
419                                  ))) {
[3638]420                        $this->can_read = True;
421                }
[3019]422
423
[3913]424                if ( $_SESSION['phpgw_info']['user']['filemanager']['flush'] != 'flushed' ) {
[3879]425                        /* Flush journal-deleted */
[3638]426                        $this->bo->vfs->flush_journal(array(
[3879]427                                 'string' => $this->path,
428                                 'relatives' => array(RELATIVE_NONE),
429                                 'deleteall' => True
[3638]430                        ));
431                        $_SESSION['phpgw_info']['user']['filemanager']['flush'] = 'flushed';
432                }
[3019]433
434
435
[3638]436                # if is different path than home and no permission allowed
[3879]437                if ($this->path != $this->bo->homedir && $this->path != $this->bo->fakebase && $this->path != '/' && !$this->can_read) {
[3638]438                        $this->messages[] = lang('You do not have access to %1', $this->path);
439                        $this->path = $this->homedir;
440                        $this->bo->vfs->cd(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
441                        $GLOBALS['phpgw']->common->phpgw_footer();
442                        $GLOBALS['phpgw']->common->phpgw_exit();
443                }
[3019]444
[3638]445                $this->bo->userinfo['working_id'] = $this->bo->vfs->working_id;
446                $this->bo->userinfo['working_lid'] = $GLOBALS['phpgw']->accounts->id2name($this->bo->userinfo['working_id']);
[3019]447
[3638]448                # Verify path is real
[3879]449                if ($this->path != $this->bo->homedir && $this->path != '/' && $this->path != $this->bo->fakebase) {
450                        if (!$this->bo->vfs->file_exists(array(
451                                                        'string' => $this->path,
452                                                        'relatives' => array(RELATIVE_NONE)
453                                          ))) {
454                                $this->messages[] = lang('Error:') . lang('Directory %1 does not exist', $this->path);
[3019]455                                $this->path = $this->homedir;
456                                $this->bo->vfs->cd(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
457                                $GLOBALS['phpgw']->common->phpgw_footer();
458                                $GLOBALS['phpgw']->common->phpgw_exit();
459                        }
[3638]460                }
[3019]461
462
[3638]463                # Default is to sort by name
[3879]464                if (!$this->sortby) {
[3638]465                        $this->sortby = 'name';
466                }
[3879]467                if ($this->update_x == 1) {
[3638]468                        $this->bo->vfs->update_real(array(
[3879]469                                 'string' => $this->path,
470                                 'relatives' => array(RELATIVE_NONE)
[3638]471                        ));
[3879]472                        header('Location:' . $this->encode_href('index.php?menuaction=filemanager.uifilemanager.index', '&path=' . base64_encode($this->bo->homedir)));
473                } elseif ($this->newfile_x && $this->newfile_or_dir) { // create new textfile
[3638]474                        $this->createfile();
[3879]475                } elseif ($this->edit_cancel_x) {
[3638]476                        $this->readFilesInfo();
477                        $this->fileListing();
[3879]478                } elseif ($this->edit_x || $this->edit_preview_x || $this->edit_save_x || $this->edit_save_done_x) {
[3638]479                        $this->edit();
[3879]480                } else {
[3638]481                        //$this->readFilesInfo();
482                        $this->fileListing();
483                }
484        }
[3019]485
[3888]486        function setFileMaxSize()
487        {
488                $maxSize        = $_POST['maxFileSize'];
489                $file           = "setFileMaxSize.php";
490                $writeFile = "<?php $"."SET_FILE_MAX_SIZE="."\"".base64_encode(serialize($maxSize))."\""." ?>";
491                $filename = dirname(__FILE__).'/'.$file;
492                $content = $writeFile;
493                       
494                if ( !$handle = fopen($filename, 'w+') )
495                        return false;
496               
497                if (fwrite($handle, $content) === FALSE)
498                        return false;
499
500                fclose($handle);
501               
502                return true;
503        }
504
[3879]505        function get_permissions() {
506                /* get permissions */
507                if ((preg_match('+^' . $this->bo->fakebase . '\/(.*)(\/|$)+U', $this->path, $matches)) && $matches[1] != $this->bo->userinfo['account_lid']) { //FIXME matches not defined
508                        $this->bo->vfs->working_id = $GLOBALS['phpgw']->accounts->name2id($matches[1]); //FIXME matches not defined
509                } else {
[3638]510                        $this->bo->vfs->working_id = $this->bo->userinfo['username'];
511                }
[3019]512
[3638]513                # Check available permissions for $this->path, so we can disable unusable operations in user interface
[3879]514                $path = explode('/', $this->path);
515                $owner_id = $this->bo->vfs->ownerOf($this->bo->fakebase, $path[2]);
[3638]516                $user_id = $GLOBALS['phpgw_info']['user']['account_id'];
[3879]517                if ($owner_id == $user_id) {
[3638]518                        $rights = 31;
[3879]519                } else {
520                        $acl = CreateObject('phpgwapi.acl', $owner_id);
[3638]521                        $acl->account_id = $owner_id;
522                        $acl->read_repository();
523                        $rights = $acl->get_rights($user_id);
524                }
[3879]525                return $rights;
[3638]526        }
[3879]527
[5038]528        function dir_ls()
529        {
[3638]530                // change dir to this->path
531                $this->bo->vfs->cd(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
532                $return['permissions'] = $this->get_permissions();
[5038]533                /*$return['quota']['usedSpace'] = $this->bo->vfs->get_size(array(
[3879]534                                                'string' => $this->path,
535                                                'relatives' => array(RELATIVE_NONE)
[5038]536                                  ));*/
537               
538                $return['quota']['usedSpace'] = $this->bo->vfs->get_size_all( $GLOBALS['phpgw_info']['user']['account_id'] );
539                $return['files_count'] = $this->bo->vfs->count_files(array( 'string' => $this->path ));
540               
541                $quota = $this->bo->vfs->get_quota(array('string' => $this->bo->homedir ));
542               
[3638]543                reset($this->files_array);
544                $this->readFilesInfo();
[3019]545
[5038]546                for ($i = 0; $i != $this->numoffiles; $i++)
547                {
[3638]548                        $files = $this->files_array[$i];
[3019]549
[3879]550                        if ($files['mime_type'] == "Directory") {
[3638]551                                continue;
[3019]552                        }
[3638]553                        /* small keys to safe bandwidth */
554                        $tuple['name'] = htmlentities($files['name']);
[5038]555                        if ($_SESSION['phpgw_info']['user']['preferences']['filemanager']['viewIcons'] == 1)
556                        {
[3879]557                                if ($files['mime_type'] == 'image/png' ||
558                                                  $files['mime_type'] == 'image/gif' ||
[5038]559                                                  $files['mime_type'] == 'image/jpg')
560                                {
[3879]561                                        $filename = str_replace('=', '', base64_encode($tuple['name']));
562                                        $pathname = str_replace('=', '', base64_encode($this->path));
563                                        $tuple['icon'] = './index.php?menuaction=filemanager.vfs_functions.summary&file=' . $filename . '&path=' . $pathname;
[3019]564                                }
565                                else
[3879]566                                        $tuple['icon'] = $this->mime_icon($files['mime_type'], 64);
[3638]567                        }
568                        else
569                                $tuple['icon'] = $this->mime_icon($files['mime_type']);
570                        $tuple['type'] = $files['type'];
571                        $tuple['created'] = $this->vfs_functions->dateString2timeStamp($files['created']);
572                        $tuple['modified'] = $this->vfs_functions->dateString2timeStamp($files['modified']);
573                        $tuple['size'] = $files['size'];
574                        $tuple['mime_type'] = $files['mime_type'];
575                        $tuple['pub'] = $files['type'];
576                        $tuple['createdby_id'] = $GLOBALS['phpgw']->accounts->id2name($files['createdby_id']);
[3879]577                        $tuple['modifiedby_id'] = $files['modifiedby_id'] ? $GLOBALS['phpgw']->accounts->id2name($files['modifiedby_id']) : '';
[3638]578                        $tuple['owner'] = $GLOBALS['phpgw']->accounts->id2name($files['owner_id']);
579                        $tuple['comment'] = $files['comment'];
580                        $tuple['version'] = $files['version'];
581                        $output[] = $tuple;
[3019]582                }
[3638]583                $return['files'] = $output;
[3879]584                $return['quota']['quotaSize'] = ($quota * 1024 * 1024);
[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);
612                echo serialize($return);
613        }
[3879]614
615        function fileListing() {
[3638]616                $this->t->set_file(array('filemanager_list_t' => 'main.tpl'));
[3879]617                $this->t->set_block('filemanager_list_t', 'filemanager_header', 'filemanager_header');
618                $this->t->set_block('filemanager_list_t', 'filemanager_footer', 'filemanager_footer');
[3019]619
[3879]620                if ($this->numoffiles || $this->cwd) {
621                        $vars[path] = '<input type="hidden" id="currentPath" value="' . $this->path . '">';
622                        $vars[css] = '<link rel="stylesheet" type="text/css" href="filemanager/templates/default/main.css">';
[3638]623                        $vars[css].='<link rel="stylesheet" type="text/css" href="phpgwapi/js/dftree/dftree.css">';
624                        $_SESSION['phpgw_info']['user']['preferences']['filemanager']['lid'] = $GLOBALS['phpgw_info']['user']['account_lid'];
[3879]625                        $vars[preferences] = '<input type="hidden" id="userPreferences" value=\'' . serialize($_SESSION['phpgw_info']['user']['preferences']['filemanager']) . '\'>';
[3638]626                        // Used for important operations that needs security
[3879]627                        for ($key = ""; strlen($key) < 150; $key .= chr(rand(48, 95)))
628                                ;
[3638]629                        $_SESSION['phpgw_info']['filemanager']['user']['sec_key'] = $key;
[3879]630                        $vars[sec_key] = '<input type="hidden" id="userKey" value=\'' . $key . '\'>';
631                        $vars[script] = '<script>initDrawApi();</script>';
632
633                        $vars[new_button] = $this->toolButton('new', 'createfile', lang('New...'));
[3638]634                        $vars[new_button].='<input type="hidden" id="newfile_or_dir" name="newfile_or_dir" value="" />';
[3879]635
[3638]636                        // reload button with this url
[3879]637                        $vars[refresh_button] = $this->toolButton('reload', 'reload', lang('reload'));
[3019]638
[3638]639                        // go up icon when we're not at the top, dont allow to go outside /home = fakebase
[3879]640                        if ($this->path != '/' && $this->path != $this->bo->fakebase) {
641                                $vars[tools_button] = $this->toolButton('tools', 'tools', lang('tools'));
[3638]642                        }
643                        else
644                                $vars[tools_button] = "";
[3019]645
[3879]646                        $vars[toolbar1] = $toolbar;
[3019]647
[3879]648                        if (count($this->messages) > 0) {
649                                foreach ($this->messages as $msg) {
650                                        $messages.='<span>' . $msg . '</span>';
[3019]651                                }
652                        }
[3638]653                        $this->messages = NULL;
[3019]654
[3879]655                        $vars[messages] = $messages;
656
[3019]657                        $this->t->set_var($vars);
[3879]658                        $this->t->pparse('out', 'filemanager_header');
[3019]659                }
660
[3638]661                $this->t->set_var($vars);
[3879]662                $this->t->pparse('out', 'filemanager_footer');
[3638]663
664                $GLOBALS['phpgw']->common->phpgw_footer();
665                $GLOBALS['phpgw']->common->phpgw_exit();
666        }
667
[3879]668        function readFilesInfo() {
[3638]669                // start files info
670                # Read in file info from database to use in the rest of the script
671                # $fakebase is a special directory.  In that directory, we list the user's
672                # home directory and the directories for the groups they're in
673                $this->numoffiles = 0;
[3879]674                if ($this->path == $this->bo->fakebase) {
[3638]675                        // FIXME this test can be removed
[3879]676                        if (!$this->bo->vfs->file_exists(array('string' => $this->bo->homedir, 'relatives' => array(RELATIVE_NONE)))) {
[3638]677                                $this->bo->vfs->mkdir(array('string' => $this->bo->homedir, 'relatives' => array(RELATIVE_NONE)));
678                        }
[3019]679
[3638]680                        $ls_array = $this->bo->vfs->ls(array(
[3879]681                                                        'string' => $this->bo->homedir,
682                                                        'relatives' => array(RELATIVE_NONE),
683                                                        'checksubdirs' => False,
684                                                        'nofiles' => True
685                                          ));
[3638]686
687                        $this->files_array[] = $ls_array[0];
688                        $this->numoffiles++;
689
690                        reset($this->readable_groups);
[3879]691                        while (list($num, $group_array) = each($this->readable_groups)) {
[3638]692                                # If the group doesn't have access to this app, we don't show it
[3879]693                                /* if(!$this->groups_applications[$group_array['account_name']][$this->bo->appname]['enabled'])
694                                  {
695                                  continue;
696                                  }
697                                 */
[3019]698
699
[3879]700                                if (!$this->bo->vfs->file_exists(array('string' => $this->bo->fakebase . '/' . $group_array['account_name'], 'relatives' => array(RELATIVE_NONE)))) {
[3638]701                                        $this->bo->vfs->override_acl = 1;
702                                        $this->bo->vfs->mkdir(array(
[3879]703                                                 'string' => $this->bo->fakebase . '/' . $group_array['account_name'],
704                                                 'relatives' => array(RELATIVE_NONE)
[3638]705                                        ));
[3019]706
[3638]707                                        // FIXME we just created a fresh group dir so we know there nothing in it so we have to remove all existing content
[3879]708
709
[3638]710                                        $this->bo->vfs->override_acl = 0;
[3019]711
[3879]712                                        $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]713                                }
[3019]714
[3879]715                                $ls_array = $this->bo->vfs->ls(array('string' => $this->bo->fakebase . '/' . $group_array['account_name'], 'relatives' => array(RELATIVE_NONE), 'checksubdirs' => False, 'nofiles' => True));
[3019]716
[3638]717                                $this->files_array[] = $ls_array[0];
[3019]718
[3638]719                                $this->numoffiles++;
[3019]720                        }
[3879]721                } else {
[3638]722                        $ls_array = $this->bo->vfs->ls(array(
[3879]723                                                        'string' => $this->path,
724                                                        'relatives' => array(RELATIVE_NONE),
725                                                        'checksubdirs' => False,
726                                                        'nofiles' => False,
727                                                        'orderby' => $this->criteria,
728                                                        'otype' => $this->otype,
729                                                        'limit' => $this->limit,
730                                                        'offset' => $this->offset
731                                          ));
[3019]732
[3879]733                        while (list($num, $file_array) = each($ls_array)) {
[3638]734                                $this->numoffiles++;
735                                $this->files_array[] = $file_array;
[3019]736                        }
737                }
[3638]738
[3879]739                if (!is_array($this->files_array)) {
[3638]740                        $this->files_array = array();
741                }
742                // end file count
743        }
[3879]744
745        function removedir() {
[3638]746                //$toRemove = $this->path ^ $_SESSION['phpgw_info']['filemanager']['user']['sec_key'];
747                $toRemove = $this->path;
[3879]748
749                if ($this->bo->vfs->rm(array('string' => $toRemove, 'relatives' => array(RELATIVE_NONE))))
[3638]750                        echo "True";
751                else
752                        echo "False";
753        }
[3879]754
755        function createdir() {
756                if ($this->bo->badchar = $this->bo->bad_chars($this->filename, True, True)) {
757                        echo lang('Error:') . $this->bo->html_encode(lang('Directory names cannot contain "%1"', $badchar), 1);
[3638]758                        return;
[3019]759                }
[3638]760                /* TODO is this right or should it be a single $ ? */
[3879]761                if ($this->filename[strlen($this->filename) - 1] == ' ' || $this->filename[0] == ' ') {
762                        echo lang('Error:') . lang('Cannot create directory because it begins or ends in a space');
[3638]763                }
[3879]764
[3638]765                $ls_array = $this->bo->vfs->ls(array(
[3879]766                                                'string' => $this->path . '/' . $this->filename,
767                                                'relatives' => array(RELATIVE_NONE),
768                                                'checksubdirs' => False,
769                                                'nofiles' => True
770                                  ));
[3638]771
772                $fileinfo = $ls_array[0];
773
[3879]774                if ($fileinfo['name']) {
775                        if ($fileinfo['mime_type'] != 'Directory') {
776                                echo lang('Error:') . lang('%1 already exists as a file', $fileinfo['name']);
777                        } else {
778                                echo lang('Error:') . lang('Directory %1 already exists', $fileinfo['name']);
[3019]779                        }
[3879]780                } else {
[3638]781                        $this->bo->vfs->cd(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
[3879]782
783                        if ($this->bo->vfs->mkdir(array('string' => $this->filename))) {
784                                echo lang('Created directory %1', $this->disppath . '/' . $this->filename);
785                        } else {
786                                echo lang('Error:') . lang('Could not create %1', $this->disppath . '/' . $this->filename);
[3019]787                        }
788                }
[3638]789                echo lang('Directory created');
790        }
[3879]791
792        function getReturnExecuteForm() {
[3638]793                $response = $_SESSION['response'];
[3879]794
[3638]795                unset($_SESSION['response']);
[3879]796
[3638]797                echo $response;
798        }
[3879]799
[3638]800        function showUploadboxes()
801        {
802                $notify = CreateObject('filemanager.notifications');
[3879]803
[3638]804                $var = array(
[3879]805                         'change_upload_boxes'  => lang('Show'),
806                         'form_action'                  => $GLOBALS[phpgw]->link('/filemanager/inc/upload.php'),
807                         'emails_to'                            => $notify->EmailsToSend($GLOBALS['phpgw']->preferences->values['email']),
808                         'lang_file'                            => lang('File(s)'),
809                         'lang_comment'                 => lang('Comment(s)'),
810                         'lang_advanced_upload' => lang('Advanced Upload'),
[3897]811                         'lang_delete'                  => lang('delete'),
[3879]812                         'lang_upload'                  => lang('Upload files'),
813                         'max_size'                             => lang('The maximum size for each file is %1MB', ($this->current_config['filemanager_Max_file_size'])),
814                         'path'                                 => $this->path
[3638]815                );
[3879]816
817                print( serialize($var));
[3638]818        }
[3019]819
[3638]820        /* create textfile */
[3879]821        function createfile()
[3638]822        {
[3879]823                $this->filename = $this->newfile_or_dir;
824                if ($this->filename) {
825                        if ($badchar = $this->bo->bad_chars($this->filename, True, True)) {
826                                $this->messages[] = lang('Error:') . lang('File names cannot contain "%1"', $badchar);
[3019]827
[3638]828                                $this->fileListing();
829                        }
[3019]830
[3879]831                        if ($this->bo->vfs->file_exists(array(
832                                                        'string' => $this->filename,
833                                                        'relatives' => array(RELATIVE_ALL)
834                                          ))) {
835                                $this->messages[] = lang('Error:') . lang('File %1 already exists. Please edit it or delete it first.', $this->filename);
[3638]836                                $this->fileListing();
837                        }
[3019]838
[3879]839                        if ($this->bo->vfs->touch(array(
840                                                        'string' => $this->filename,
841                                                        'relatives' => array(RELATIVE_ALL)
842                                          ))) {
[3638]843                                $this->edit = 1;
844                                $this->numoffiles++;
845                                $this->edit();
[3879]846                        } else {
847                                $this->messages[] = lang('Error:') . lang('File %1 could not be created.', $this->filename);
[3638]848                                $this->fileListing();
849                        }
[3019]850                }
[3638]851        }
[3019]852
[3638]853        # Handle Editing files
[3879]854
855        function edit() {
856                if ($this->filename) {
857                        if (!$this->vfs_functions->verifyLock($this->path . '/' . $this->filename, RELATIVE_NONE)) {
[3638]858                                $GLOBALS['phpgw']->redirect('/index.php');
859                        }
860                        $ls_array = $this->bo->vfs->ls(array(
[3879]861                                                        'string' => $this->path . '/' . $this->filename,
862                                                        'relatives' => array(RELATIVE_NONE),
863                                                        'checksubdirs' => False,
864                                                        'nofiles' => True
865                                          ));
[3638]866                        $this->bo->vfs->touch(array(
[3879]867                                 'string' => $this->path . '/' . $this->filename,
868                                 'relatives' => array(RELATIVE_NONE)
[3638]869                        ));
[3019]870
871
[3879]872                        if ($ls_array[0]['mime_type']) {
[3638]873                                $mime_type = $ls_array[0]['mime_type'];
[3879]874                        } elseif ($this->prefs['viewtextplain']) {
[3638]875                                $mime_type = 'text/plain';
876                        }
[3879]877                        $editable = array('', 'text/plain', 'text/csv', 'text/html', 'text/text', 'message/rfc822');
[3019]878
[3879]879                        if (!in_array($mime_type, $editable)) {
880                                $this->messages[] = lang('Error:') . lang('Impossible to edit this file');
[3638]881                                $this->readFilesInfo();
882                                $this->fileListing();
883                                return;
[3019]884                        }
[3638]885                }
[3019]886
[3638]887                $this->readFilesInfo();
[3019]888
[3638]889                if ($mime_type == 'text/html')
890                        $this->t->set_file(array('filemanager_edit' => 'edit_html.tpl'));
891                else
892                        $this->t->set_file(array('filemanager_edit' => 'edit_file.tpl'));
[3019]893
[3879]894                $this->t->set_block('filemanager_edit', 'row', 'row');
[3019]895
896
[3638]897                $vars[refresh_script] = "<script src='filemanager/js/refresh.js'></script>";
[3019]898
[3879]899                $vars[preview_content] = '';
900                if ($this->edit_file) {
[3638]901                        $this->edit_file_content = stripslashes($this->edit_file_content);
902                }
[3019]903
[3879]904                if ($this->edit_preview_x) {
[3638]905                        $content = $this->edit_file_content;
[3019]906
[3879]907                        $vars[lang_preview_of] = lang('Preview of %1', $this->path . '/' . $edit_file);
[3019]908
[3879]909                        $vars[preview_content] = nl2br($content);
910                } elseif ($this->edit_save_x || $this->edit_save_done_x) {
[3638]911                        $content = $this->edit_file_content;
912                        //die( $content);
[3879]913                        if ($this->bo->vfs->write(array(
914                                                        'string' => $this->path . '/' . $this->edit_file,
915                                                        'relatives' => array(RELATIVE_NONE),
916                                                        'content' => $content
917                                          ))) {
918                                $this->messages[] = lang('Saved %1', $this->path . '/' . $this->edit_file);
[3019]919
[3879]920                                if ($this->edit_save_done_x) {
[3638]921                                        $this->readFilesInfo();
922                                        $this->fileListing();
923                                        exit;
[3019]924                                }
[3879]925                        } else {
926                                $this->messages[] = lang('Could not save %1', $this->path . '/' . $this->edit_file);
[3019]927                        }
[3638]928                }
[3019]929
[3638]930                # If we're in preview or save mode, we only show the file
931                # being previewed or saved
[3879]932                if ($this->edit_file && ($this->filename != $this->edit_file)) {
[3638]933                        continue;
934                }
935
[3879]936                if ($this->filename && $this->bo->vfs->file_exists(array(
937                                                'string' => $this->filename,
938                                                'relatives' => array(RELATIVE_ALL)
939                                  ))) {
940                        if ($this->edit_file) {
[3638]941                                $content = stripslashes($this->edit_file_content);
[3879]942                        } else {
[3638]943                                $content = $this->bo->vfs->read(array('string' => $this->filename));
944                        }
[3879]945                        $vars[form_action] = $GLOBALS['phpgw']->link('/index.php', 'menuaction=filemanager.uifilemanager.index', 'path=' . $this->path);
946                        $vars[edit_file] = $this->filename;
[3638]947                        # We need to include all of the fileman entries for each file's form,
948                        # so we loop through again
[3879]949                        for ($i = 0; $i != $this->numoffiles; $i++) {
950                                if ($this->filename)
951                                        $value = 'value="' . $this->filename . '"';
952                                $vars[filemans_hidden] = '<input type="hidden" name="filename" ' . $value . ' />';
[3638]953                        }
[3879]954                        $vars[file_content] = $content;
[3019]955
[3879]956                        $vars[buttonPreview] = $this->inputButton('edit_preview', 'edit_preview', lang('Preview %1', $this->bo->html_encode($this->fileman[0], 1)));
957                        $vars[buttonSave] = $this->inputButton('edit_save', 'save', lang('Save %1', $this->bo->html_encode($this->filename, 1)));
958                        $vars[buttonDone] = $this->inputButton('edit_save_done', 'ok', lang('Save %1, and go back to file listing ', $this->bo->html_encode($this->filename, 1)));
959                        $vars[buttonCancel] = $this->inputButton('edit_cancel', 'cancel', lang('Cancel editing %1 without saving', $this->bo->html_encode($this->filename, 1)));
[3019]960
[3879]961                        if ($mime_type == 'text/html') {
[3638]962                                $vars[fck_edit] = '<script type="text/javascript" src="filemanager/tp/ckeditor/ckeditor.js"></script>
[3879]963                                        <textarea cols="80" id="edit_file_content" name="edit_file_content" rows="10">' . $content . '</textarea>
[3019]964                                                <script type="text/javascript"> CKEDITOR.replace( \'edit_file_content\',{
965removePlugins : \'elementspath\',
966skin : \'office2003\',
967toolbar : [["Source","Preview","-","Cut","Copy","Paste","-","Print",
968"Undo","Redo","-","Find","Replace","-","SelectAll" ],
969["Table","HorizontalRule","Smiley","SpecialChar","PageBreak","-","Bold",
970"Italic","Underline","Strike","-","Subscript","Superscript",
971"NumberedList","BulletedList","-","Outdent","Indent","Blockquote",
972"JustifyLeft","JustifyCenter","JustifyRight","JustifyBlock",
973"Link", "TextColor","BGColor","Maximize"],
974["Styles","Format","Font","FontSize"]]
975                                });</script>';
[3638]976                        }
[3019]977
978
[3638]979                        $this->t->set_var($vars);
[3879]980                        $this->t->parse('rows', 'row');
981                        $this->t->pparse('out', 'row');
[3019]982                }
[3638]983        }
984
[3885]985        function history()
986        {
987                if ( $this->file)
988                {
989                        // FIXME this-file is never defined
[3638]990                        $journal_array = $this->bo->vfs->get_journal(array(
[3879]991                                                        'string' => $this->file, //FIXME
992                                                        'relatives' => array(RELATIVE_ALL)
[3885]993               
994                         ));
[3638]995
[3885]996                        if ( is_array($journal_array) )
997                        {
998                                $historyFile = array();
[3019]999
[3885]1000                                while ( list($num, $journal_entry) = each($journal_array) )
1001                                {
1002                                        $historyFile[] = array(
[5038]1003                                                                                        "created"       => $this->vfs_functions->dateString2timeStamp($journal_entry['created']),
[3885]1004                                                                                        "version"       => $journal_entry['version'],
1005                                                                                        "who"           => $GLOBALS['phpgw']->accounts->id2name($journal_entry['owner_id']),
1006                                                                                        "operation"     =>      $journal_entry['comment']
1007                                        );
[3638]1008                                }
[3885]1009                               
1010                        echo serialize( $historyFile );
[3638]1011                                $GLOBALS['phpgw']->common->phpgw_footer();
1012                                $GLOBALS['phpgw']->common->phpgw_exit();
[3885]1013                        }
1014                        else
1015                        {
[3638]1016                                echo lang('No version history for this file/directory');
1017                        }
[3019]1018                }
[3638]1019        }
[3879]1020
1021        function view() {
[3638]1022                if (!$this->bo->vfs->acl_check(array(
[3879]1023                                                'string' => $this->path,
1024                                                'relatives' => array(RELATIVE_NONE),
1025                                                'operation' => PHPGW_ACL_READ
1026                                  ))) {
[3638]1027                        $this->messages[] = lang("You have no permission to access this file");
[3879]1028                        header('Location:' . $this->encode_href('inc/index.php?menuaction=filemanager.uifilemanager.index', '&path=' . base64_encode($this->bo->homedir)));
[3638]1029
1030                        return;
1031                }
[3879]1032                if ($this->file) { //FIXME
[3638]1033                        $ls_array = $this->bo->vfs->ls(array(
[3879]1034                                                        'string' => $this->path . '/' . $this->file, //FIXME
1035                                                        'relatives' => array(RELATIVE_NONE),
1036                                                        'checksubdirs' => False,
1037                                                        'nofiles' => True
1038                                          ));
1039                        if ($ls_array[0]['mime_type']) {
[3638]1040                                $mime_type = $ls_array[0]['mime_type'];
[3879]1041                        } elseif ($this->prefs['viewtextplain']) {
[3638]1042                                $mime_type = 'text/plain';
1043                        }
[3879]1044                        $viewable = array('text/plain', 'text/csv', 'text/html',
1045                                 'text/text', 'image/jpeg', 'image/png', 'image/gif',
1046                                 'audio/mpeg', 'video/mpeg');
[3019]1047
[3879]1048                        if (in_array($mime_type, $viewable)) {
1049                                /* Note: if you put application/octet-stream you force download */
[3638]1050                                header('Content-type: ' . $mime_type);
1051                                header('Content-disposition: filename="' . addslashes($this->file) . '"');
1052                                Header("Pragma: public");
[3879]1053                        } else {
1054                                $GLOBALS['phpgw']->browser->content_header($this->file, $mime_type, $ls_array[0]['size']);
[3019]1055                        }
[3879]1056                        if ($ls_array[0]['size'] < 10240) {
[3638]1057                                echo $this->bo->vfs->read(array(
[3879]1058                                         'string' => $this->path . '/' . $this->file, //FIXME
1059                                         'relatives' => array(RELATIVE_NONE)
[3019]1060                                ));
[3879]1061                        } else {
[3638]1062                                $this->bo->vfs->print_content(array(
[3879]1063                                         'string' => $this->path . '/' . $this->file,
1064                                         'relatives' => array(RELATIVE_NONE)
1065                                                  )
1066                                );
[3638]1067                        }
1068                        $GLOBALS['phpgw']->common->phpgw_exit();
[3019]1069                }
[3638]1070        }
[3019]1071
[3936]1072        function export()
1073        {
1074                if ($this->file)
1075                {
[3638]1076                        $ls_array = $this->bo->vfs->ls(array(
[3879]1077                                                        'string' => $this->path . '/' . $this->file,
1078                                                        'relatives' => array(RELATIVE_NONE),
1079                                                        'checksubdirs' => False,
1080                                                        'nofiles' => True
1081                                          ));
[3936]1082
[3638]1083                        $mime_type = $ls_array[0]['mime_type'];
[3936]1084                       
[3638]1085                        $formats = array('text/html');
[3936]1086                       
1087                        if (!in_array($mime_type, $formats))
1088                        {
[3638]1089                                echo lang('Impossible to export this file');
1090                                return False;
1091                        }
[3936]1092                       
[3879]1093                        $content = $this->bo->vfs->read(array('string' => $this->path . '/' . $this->file,
1094                                                        'relatives' => array(RELATIVE_NONE)
1095                                          ));
[3019]1096
[3638]1097                        include_once('filemanager/tp/dompdf/dompdf_config.inc.php');
[3936]1098                       
[3638]1099                        $dompdf = new DOMPDF();
1100                        $dompdf->load_html($content);
1101                        $dompdf->set_paper($this->prefs['pdf_paper_type'], $this->prefs['pdf_type']);
[3879]1102                        /* Would be nice to implement 'Title','Subject','Author','Creator','CreationDate' */
[3638]1103                        $dompdf->render();
[3879]1104                        $dompdf->stream(strtok($this->file, '.') . ".pdf");
[3638]1105                        $GLOBALS['phpgw']->common->phpgw_exit();
[3019]1106                }
[3638]1107        }
[3019]1108
[3638]1109        //give back an array with all directories except current and dirs that are not accessable
[3879]1110        function all_other_directories() {
[3638]1111                # First we get the directories in their home directory
1112                $dirs = array();
1113                $dirs[] = array('directory' => $this->bo->fakebase, 'name' => $this->bo->userinfo['account_lid']);
1114
[3879]1115                $tmp_arr = array(
1116                         'string' => $this->bo->homedir,
1117                         'relatives' => array(RELATIVE_NONE),
1118                         'checksubdirs' => True,
1119                         'mime_type' => 'Directory'
[3638]1120                );
1121
[3879]1122                $ls_array = $this->bo->vfs->ls($tmp_arr, True);
[3638]1123
[3879]1124                while (list($num, $dir) = each($ls_array)) {
[3638]1125                        $dirs[] = $dir;
1126                }
[3019]1127
[3638]1128
1129                # Then we get the directories in their readable groups' home directories
1130                reset($this->readable_groups);
[3879]1131                while (list($num, $group_array) = each($this->readable_groups)) {
[3638]1132                        // Don't list directories for groups that don't exists
[3879]1133                        $test = $this->bo->vfs->get_real_info(array('string' => $this->bo->fakebase . '/' . $group_array['account_name'],
1134                                                        'relatives' => array(RELATIVE_NONE), 'relative' => False));
1135                        if ($test[mime_type] != 'Directory') {
[3638]1136                                continue;
1137                        }
1138
1139                        $dirs[] = array('directory' => $this->bo->fakebase, 'name' => $group_array['account_name']);
1140
[3879]1141                        $tmp_arr = array(
1142                                 'string' => $this->bo->fakebase . '/' . $group_array['account_name'],
1143                                 'relatives' => array(RELATIVE_NONE),
1144                                 'checksubdirs' => True,
1145                                 'mime_type' => 'Directory'
[3019]1146                        );
1147
[3879]1148                        $ls_array = $this->bo->vfs->ls($tmp_arr, True);
1149                        while (list($num, $dir) = each($ls_array)) {
[3019]1150                                $dirs[] = $dir;
1151                        }
[3638]1152                }
1153                reset($dirs);
[3879]1154                while (list($num, $dir) = each($dirs)) {
1155                        if (!$dir['directory']) {
[3638]1156                                continue;
1157                        }
[3019]1158
[3638]1159                        # So we don't display //
[3879]1160                        if ($dir['directory'] != '/') {
[3638]1161                                $dir['directory'] .= '/';
1162                        }
1163                        $return[] = $dir;
1164                }
1165                return $return;
1166        }
[3019]1167
[3879]1168        function update_groups() {
[3638]1169                # Get their readable groups to be used throughout the script
1170                $acl = array();
1171                $groups = array();
[3879]1172                $acl = $GLOBALS['phpgw']->acl->get_ids_for_location($GLOBALS['phpgw_info']['user']['account_id'], 1, 'filemanager');
[3638]1173                if (is_array($acl))
[3879]1174                        foreach ($acl as $key => $value) {
[3638]1175                                $info = array();
1176                                $info = $GLOBALS['phpgw']->accounts->get_account_data($value);
1177                                $groups[$key]['account_id'] = $value;
1178                                $groups[$key]['account_lid'] = $info[$value]['lid'];
1179                                $groups[$key]['account_name'] = $info[$value]['firstname'];
1180                                $groups[$key]['account_lastname'] = $info[$value]['lastname'];
1181                                $groups[$key]['account_fullname'] = $info[$value]['fullname'];
[3019]1182                        }
[3638]1183                $this->readable_groups = array();
[3879]1184                while (list($num, $account) = each($groups)) {
1185                        if ($this->bo->vfs->acl_check(array('owner_id' => $account['account_id'], 'operation' => PHPGW_ACL_READ))) {
[3638]1186                                $this->readable_groups[$account['account_lid']] = Array('account_id' => $account['account_id'], 'account_name' => $account['account_lid']);
[3019]1187                        }
1188                }
[3638]1189        }
[3879]1190
1191        function search() {
[3638]1192                /* TODO this is a primitive search */
1193                $this->update_groups();
[3879]1194                $this->dirs = $this->all_other_directories();
[3638]1195                $path = $this->path;
[3879]1196                if (strlen($this->text) > 3) {
[3638]1197                        $this->text = strtoupper($this->text);
[3879]1198                        foreach ($this->dirs as $elem) {
1199                                $this->path = $elem['directory'] . $elem['name'];
[3638]1200                                reset($this->files_array);
[3879]1201                                $this->readFilesInfo();
1202                                for ($i = 0; $i < count($this->files_array); $i++) {
[3638]1203                                        $comment = strtoupper($this->files_array[$i]['comment']);
1204                                        $name = strtoupper($this->files_array[$i]['name']);
[3879]1205                                        if (strstr($name, $this->text) ||
1206                                                          strstr($comment, $this->text)) {
1207                                                $return[$this->files_array[$i]['directory'] . $name] = $this->files_array[$i];
1208                                                $return[$this->files_array[$i]['directory'] . $name]['icon'] = $this->mime_icon($this->files_array[$i]['mime_type']);
[3638]1209                                        }
[3019]1210                                }
[3879]1211                                if (count($return) > 50) {
1212                                        $return = array_slice($return, 0, 50);
[3638]1213                                        break;
1214                                }
[3879]1215                        }
[3019]1216                }
[3638]1217                echo serialize(array_values($return));
1218        }
[3019]1219
[3638]1220        /* seek icon for mimetype else return an unknown icon */
[3019]1221
[3879]1222        function mime_icon($mime_type, $size=16) {
1223                if (!$mime_type)
1224                        $mime_type = 'unknown';
[3019]1225
[3879]1226                $mime_type = str_replace('/', '_', $mime_type);
[3019]1227
[3879]1228                $img = $GLOBALS['phpgw']->common->image('filemanager', 'mime' . $size . '_' . strtolower($mime_type));
1229                if (!$img)
1230                        $img = $GLOBALS['phpgw']->common->image('filemanager', 'mime' . $size . '_unknown');
1231
[3638]1232                return $img;
1233        }
[3019]1234
[3879]1235        function toolButton($link, $img='', $description='') {
1236                $image = $GLOBALS['phpgw']->common->image('filemanager', 'button_' . strtolower($img));
[3638]1237
[3879]1238                if ($img) {
1239                        return '<div name="' . $link . '" class="toolButton" onclick="toolbar.control(\'' . $link . '\',this);" title="' . $description . '"><img src="' . $image . '" alt="' . $description . '"/><small>' . $description . '</small></div>';
[3019]1240                }
[3638]1241        }
[3019]1242
[3879]1243        function inputButton($name, $img='', $description='') {
1244                $image = $GLOBALS['phpgw']->common->image('filemanager', 'button_' . strtolower($img));
[3638]1245
[3879]1246                if ($img) {
[3638]1247                        return '<td class="" align="center" valign="middle" height="28" width="70">
[3879]1248                        <input title="' . $description . '" name="' . $name . '" type="image" alt="' . $name . '" src="' . $image . '" value="clicked" /><br><small>' . $description . '</small>
[3638]1249                        </td>';
[3019]1250                }
[3638]1251        }
[3019]1252
[3879]1253        function html_form_input($type = NULL, $name = NULL, $value = NULL, $maxlength = NULL, $size = NULL, $checked = NULL, $string = '', $return = 1) {
[3638]1254                $text = ' ';
[3879]1255                if ($type != NULL && $type) {
1256                        if ($type == 'checkbox') {
[3638]1257                                $value = $this->bo->string_encode($value, 1);
[3019]1258                        }
[3879]1259                        $text .= 'type="' . $type . '" ';
[3019]1260                }
[3879]1261                if ($name != NULL && $name) {
1262                        $text .= 'name="' . $name . '" ';
[3019]1263                }
[3879]1264                if ($value != NULL && $value) {
1265                        $text .= 'value="' . $value . '" ';
[3638]1266                }
[3879]1267                if (is_int($maxlength) && $maxlength >= 0) {
1268                        $text .= 'maxlength="' . $maxlength . '" ';
[3638]1269                }
[3879]1270                if (is_int($size) && $size >= 0) {
1271                        $text .= 'size="' . $size . '" ';
[3638]1272                }
[3879]1273                if ($checked != NULL && $checked) {
[3638]1274                        $text .= 'checked ';
1275                }
[3019]1276
[3879]1277                return '<input' . $text . $string . '>';
[3638]1278        }
[3019]1279
[3879]1280        function html_form_option($value = NULL, $displayed = NULL, $selected = NULL, $return = 0) {
[3638]1281                $text = ' ';
[3879]1282                if ($value != NULL && $value) {
1283                        $text .= ' value="' . $value . '" ';
[3019]1284                }
[3879]1285                if ($selected != NULL && $selected) {
[3638]1286                        $text .= ' selected';
1287                }
[3879]1288                return '<option' . $text . '>' . $displayed . '</option>';
[3638]1289        }
[3019]1290
[3879]1291        function encode_href($href = NULL, $args = NULL, $extra_args) {
[3638]1292                $href = $this->bo->string_encode($href, 1);
[3879]1293                $all_args = $args . '&' . $this->bo->string_encode($extra_args, 1);
[3019]1294
[3638]1295                $address = $GLOBALS['phpgw']->link($href, $all_args);
[3019]1296
[3638]1297                return $address;
1298        }
[3019]1299
[3879]1300        function html_link($href = NULL, $args = NULL, $extra_args, $text = NULL, $return = 1, $encode = 1, $linkonly = 0, $target = NULL) {
[3638]1301                //      unset($encode);
[3879]1302                if ($encode) {
[3638]1303                        $href = $this->bo->string_encode($href, 1);
[3879]1304                        $all_args = $args . '&' . $this->bo->string_encode($extra_args, 1);
1305                } else {
[3638]1306                        //                              $href = $this->bo->string_encode($href, 1);
[3879]1307                        $all_args = $args . '&' . $extra_args;
[3638]1308                }
1309                ###
1310                # This decodes / back to normal
1311                ###
1312                //                      $all_args = preg_replace("/%2F/", "/", $all_args);
1313                //                      $href = preg_replace("/%2F/", "/", $href);
[3019]1314
[3638]1315                /* Auto-detect and don't disturb absolute links */
[3879]1316                if (!preg_match("|^http(.{0,1})://|", $href)) {
[3638]1317                        //Only add an extra / if there isn't already one there
1318                        // die(SEP);
[3879]1319                        if (!($href[0] == SEP)) {
[3638]1320                                $href = SEP . $href;
[3019]1321                        }
1322
[3638]1323                        /* $phpgw->link requires that the extra vars be passed separately */
1324                        //                              $link_parts = explode("?", $href);
1325                        $address = $GLOBALS['phpgw']->link($href, $all_args);
1326                        //                              $address = $GLOBALS['phpgw']->link($href);
[3879]1327                } else {
[3638]1328                        $address = $href;
[3019]1329                }
1330
[3638]1331                /* If $linkonly is set, don't add any HTML */
[3879]1332                if ($linkonly) {
[3638]1333                        $rstring = $address;
[3879]1334                } else {
1335                        if ($target) {
1336                                $target = 'target=' . $target;
[3019]1337                        }
[3638]1338
1339                        $text = trim($text);
[3879]1340                        $rstring = '<a href="' . $address . '" ' . $target . '>' . $text . '</a>';
[3019]1341                }
1342
[3638]1343                return($this->bo->eor($rstring, $return));
1344        }
1345
[3879]1346        function html_table_begin($width = NULL, $border = NULL, $cellspacing = NULL, $cellpadding = NULL, $rules = NULL, $string = '', $return = 0) {
1347                if ($width != NULL && $width) {
[3638]1348                        $width = "width=$width";
[3019]1349                }
[3879]1350                if (is_int($border) && $border >= 0) {
[3638]1351                        $border = "border=$border";
1352                }
[3879]1353                if (is_int($cellspacing) && $cellspacing >= 0) {
[3638]1354                        $cellspacing = "cellspacing=$cellspacing";
1355                }
[3879]1356                if (is_int($cellpadding) && $cellpadding >= 0) {
[3638]1357                        $cellpadding = "cellpadding=$cellpadding";
1358                }
[3879]1359                if ($rules != NULL && $rules) {
[3638]1360                        $rules = "rules=$rules";
1361                }
[3019]1362
[3638]1363                $rstring = "<table $width $border $cellspacing $cellpadding $rules $string>";
1364                return($this->bo->eor($rstring, $return));
1365        }
1366
[3879]1367        function html_table_end($return = 0) {
[3638]1368                $rstring = "</table>";
1369                return($this->bo->eor($rstring, $return));
1370        }
1371
[3879]1372        function html_table_row_begin($align = NULL, $halign = NULL, $valign = NULL, $bgcolor = NULL, $string = '', $return = 0) {
1373                if ($align != NULL && $align) {
[3638]1374                        $align = "align=$align";
[3019]1375                }
[3879]1376                if ($halign != NULL && $halign) {
[3638]1377                        $halign = "halign=$halign";
1378                }
[3879]1379                if ($valign != NULL && $valign) {
[3638]1380                        $valign = "valign=$valign";
1381                }
[3879]1382                if ($bgcolor != NULL && $bgcolor) {
[3638]1383                        $bgcolor = "bgcolor=$bgcolor";
1384                }
1385                $rstring = "<tr $align $halign $valign $bgcolor $string>";
1386                return($this->bo->eor($rstring, $return));
1387        }
[3019]1388
[3879]1389        function html_table_row_end($return = 0) {
[3638]1390                $rstring = "</tr>";
1391                return($this->bo->eor($rstring, $return));
1392        }
1393
[3879]1394        function html_table_col_begin($align = NULL, $halign = NULL, $valign = NULL, $rowspan = NULL, $colspan = NULL, $string = '', $return = 0) {
1395                if ($align != NULL && $align) {
[3638]1396                        $align = "align=$align";
[3019]1397                }
[3879]1398                if ($halign != NULL && $halign) {
[3638]1399                        $halign = "halign=$halign";
1400                }
[3879]1401                if ($valign != NULL && $valign) {
[3638]1402                        $valign = "valign=$valign";
1403                }
[3879]1404                if (is_int($rowspan) && $rowspan >= 0) {
[3638]1405                        $rowspan = "rowspan=$rowspan";
1406                }
[3879]1407                if (is_int($colspan) && $colspan >= 0) {
[3638]1408                        $colspan = "colspan=$colspan";
1409                }
1410
1411                $rstring = "<td $align $halign $valign $rowspan $colspan $string>";
1412                return($this->bo->eor($rstring, $return));
[3019]1413        }
[3638]1414
[3879]1415        function html_table_col_end($return = 0) {
[3638]1416                $rstring = "</td>";
1417                return($this->bo->eor($rstring, $return));
1418        }
[3879]1419
[3638]1420}
Note: See TracBrowser for help on using the repository browser.