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

Revision 3888, 47.0 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #1580 - Mensagem de erro pouco amigável para arquivos grandes

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