source: sandbox/2.5.1-evolucao/filemanager/inc/class.uifilemanager.inc.php @ 8265

Revision 8265, 48.1 KB checked in by angelo, 10 years ago (diff)

Ticket #0000 - sincronizacao das alteracoes do trunk com este sandbox

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