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

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

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

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