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

Revision 8248, 48.1 KB checked in by angelo, 11 years ago (diff)

Ticket #3493 - Atualizar bibioteca CKEditor do Expresso

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