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

Revision 4220, 46.9 KB checked in by diogenesduarte, 13 years ago (diff)

Ticket #1831 - resolvendo problema de cota padrão nula.

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