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

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

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

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']?$this->current_config['filemanager_quota_size']:0
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_delete'                  => lang('delete'),
780                         'lang_upload'                  => lang('Upload files'),
781                         'max_size'                             => lang('The maximum size for each file is %1MB', ($this->current_config['filemanager_Max_file_size'])),
782                         'path'                                 => $this->path
783                );
784
785                print( serialize($var));
786        }
787
788        /* create textfile */
789        function createfile()
790        {
791                $this->filename = $this->newfile_or_dir;
792                if ($this->filename) {
793                        if ($badchar = $this->bo->bad_chars($this->filename, True, True)) {
794                                $this->messages[] = lang('Error:') . lang('File names cannot contain "%1"', $badchar);
795
796                                $this->fileListing();
797                        }
798
799                        if ($this->bo->vfs->file_exists(array(
800                                                        'string' => $this->filename,
801                                                        'relatives' => array(RELATIVE_ALL)
802                                          ))) {
803                                $this->messages[] = lang('Error:') . lang('File %1 already exists. Please edit it or delete it first.', $this->filename);
804                                $this->fileListing();
805                        }
806
807                        if ($this->bo->vfs->touch(array(
808                                                        'string' => $this->filename,
809                                                        'relatives' => array(RELATIVE_ALL)
810                                          ))) {
811                                $this->edit = 1;
812                                $this->numoffiles++;
813                                $this->edit();
814                        } else {
815                                $this->messages[] = lang('Error:') . lang('File %1 could not be created.', $this->filename);
816                                $this->fileListing();
817                        }
818                }
819        }
820
821        # Handle Editing files
822
823        function edit() {
824                if ($this->filename) {
825                        if (!$this->vfs_functions->verifyLock($this->path . '/' . $this->filename, RELATIVE_NONE)) {
826                                $GLOBALS['phpgw']->redirect('/index.php');
827                        }
828                        $ls_array = $this->bo->vfs->ls(array(
829                                                        'string' => $this->path . '/' . $this->filename,
830                                                        'relatives' => array(RELATIVE_NONE),
831                                                        'checksubdirs' => False,
832                                                        'nofiles' => True
833                                          ));
834                        $this->bo->vfs->touch(array(
835                                 'string' => $this->path . '/' . $this->filename,
836                                 'relatives' => array(RELATIVE_NONE)
837                        ));
838
839
840                        if ($ls_array[0]['mime_type']) {
841                                $mime_type = $ls_array[0]['mime_type'];
842                        } elseif ($this->prefs['viewtextplain']) {
843                                $mime_type = 'text/plain';
844                        }
845                        $editable = array('', 'text/plain', 'text/csv', 'text/html', 'text/text', 'message/rfc822');
846
847                        if (!in_array($mime_type, $editable)) {
848                                $this->messages[] = lang('Error:') . lang('Impossible to edit this file');
849                                $this->readFilesInfo();
850                                $this->fileListing();
851                                return;
852                        }
853                }
854
855                $this->readFilesInfo();
856
857                if ($mime_type == 'text/html')
858                        $this->t->set_file(array('filemanager_edit' => 'edit_html.tpl'));
859                else
860                        $this->t->set_file(array('filemanager_edit' => 'edit_file.tpl'));
861
862                $this->t->set_block('filemanager_edit', 'row', 'row');
863
864
865                $vars[refresh_script] = "<script src='filemanager/js/refresh.js'></script>";
866
867                $vars[preview_content] = '';
868                if ($this->edit_file) {
869                        $this->edit_file_content = stripslashes($this->edit_file_content);
870                }
871
872                if ($this->edit_preview_x) {
873                        $content = $this->edit_file_content;
874
875                        $vars[lang_preview_of] = lang('Preview of %1', $this->path . '/' . $edit_file);
876
877                        $vars[preview_content] = nl2br($content);
878                } elseif ($this->edit_save_x || $this->edit_save_done_x) {
879                        $content = $this->edit_file_content;
880                        //die( $content);
881                        if ($this->bo->vfs->write(array(
882                                                        'string' => $this->path . '/' . $this->edit_file,
883                                                        'relatives' => array(RELATIVE_NONE),
884                                                        'content' => $content
885                                          ))) {
886                                $this->messages[] = lang('Saved %1', $this->path . '/' . $this->edit_file);
887
888                                if ($this->edit_save_done_x) {
889                                        $this->readFilesInfo();
890                                        $this->fileListing();
891                                        exit;
892                                }
893                        } else {
894                                $this->messages[] = lang('Could not save %1', $this->path . '/' . $this->edit_file);
895                        }
896                }
897
898                # If we're in preview or save mode, we only show the file
899                # being previewed or saved
900                if ($this->edit_file && ($this->filename != $this->edit_file)) {
901                        continue;
902                }
903
904                if ($this->filename && $this->bo->vfs->file_exists(array(
905                                                'string' => $this->filename,
906                                                'relatives' => array(RELATIVE_ALL)
907                                  ))) {
908                        if ($this->edit_file) {
909                                $content = stripslashes($this->edit_file_content);
910                        } else {
911                                $content = $this->bo->vfs->read(array('string' => $this->filename));
912                        }
913                        $vars[form_action] = $GLOBALS['phpgw']->link('/index.php', 'menuaction=filemanager.uifilemanager.index', 'path=' . $this->path);
914                        $vars[edit_file] = $this->filename;
915                        # We need to include all of the fileman entries for each file's form,
916                        # so we loop through again
917                        for ($i = 0; $i != $this->numoffiles; $i++) {
918                                if ($this->filename)
919                                        $value = 'value="' . $this->filename . '"';
920                                $vars[filemans_hidden] = '<input type="hidden" name="filename" ' . $value . ' />';
921                        }
922                        $vars[file_content] = $content;
923
924                        $vars[buttonPreview] = $this->inputButton('edit_preview', 'edit_preview', lang('Preview %1', $this->bo->html_encode($this->fileman[0], 1)));
925                        $vars[buttonSave] = $this->inputButton('edit_save', 'save', lang('Save %1', $this->bo->html_encode($this->filename, 1)));
926                        $vars[buttonDone] = $this->inputButton('edit_save_done', 'ok', lang('Save %1, and go back to file listing ', $this->bo->html_encode($this->filename, 1)));
927                        $vars[buttonCancel] = $this->inputButton('edit_cancel', 'cancel', lang('Cancel editing %1 without saving', $this->bo->html_encode($this->filename, 1)));
928
929                        if ($mime_type == 'text/html') {
930                                $vars[fck_edit] = '<script type="text/javascript" src="filemanager/tp/ckeditor/ckeditor.js"></script>
931                                        <textarea cols="80" id="edit_file_content" name="edit_file_content" rows="10">' . $content . '</textarea>
932                                                <script type="text/javascript"> CKEDITOR.replace( \'edit_file_content\',{
933removePlugins : \'elementspath\',
934skin : \'office2003\',
935toolbar : [["Source","Preview","-","Cut","Copy","Paste","-","Print",
936"Undo","Redo","-","Find","Replace","-","SelectAll" ],
937["Table","HorizontalRule","Smiley","SpecialChar","PageBreak","-","Bold",
938"Italic","Underline","Strike","-","Subscript","Superscript",
939"NumberedList","BulletedList","-","Outdent","Indent","Blockquote",
940"JustifyLeft","JustifyCenter","JustifyRight","JustifyBlock",
941"Link", "TextColor","BGColor","Maximize"],
942["Styles","Format","Font","FontSize"]]
943                                });</script>';
944                        }
945
946
947                        $this->t->set_var($vars);
948                        $this->t->parse('rows', 'row');
949                        $this->t->pparse('out', 'row');
950                }
951        }
952
953        function history()
954        {
955                if ( $this->file)
956                {
957                        // FIXME this-file is never defined
958                        $journal_array = $this->bo->vfs->get_journal(array(
959                                                        'string' => $this->file, //FIXME
960                                                        'relatives' => array(RELATIVE_ALL)
961               
962                         ));
963
964                        if ( is_array($journal_array) )
965                        {
966                                $historyFile = array();
967
968                                while ( list($num, $journal_entry) = each($journal_array) )
969                                {
970                                        $historyFile[] = array(
971                                                                                        "created"       => $journal_entry['created'],
972                                                                                        "version"       => $journal_entry['version'],
973                                                                                        "who"           => $GLOBALS['phpgw']->accounts->id2name($journal_entry['owner_id']),
974                                                                                        "operation"     =>      $journal_entry['comment']
975                                        );
976                                }
977                               
978                        echo serialize( $historyFile );
979                                $GLOBALS['phpgw']->common->phpgw_footer();
980                                $GLOBALS['phpgw']->common->phpgw_exit();
981                        }
982                        else
983                        {
984                                echo lang('No version history for this file/directory');
985                        }
986                }
987        }
988
989        function view() {
990                if (!$this->bo->vfs->acl_check(array(
991                                                'string' => $this->path,
992                                                'relatives' => array(RELATIVE_NONE),
993                                                'operation' => PHPGW_ACL_READ
994                                  ))) {
995                        $this->messages[] = lang("You have no permission to access this file");
996                        header('Location:' . $this->encode_href('inc/index.php?menuaction=filemanager.uifilemanager.index', '&path=' . base64_encode($this->bo->homedir)));
997
998                        return;
999                }
1000                if ($this->file) { //FIXME
1001                        $ls_array = $this->bo->vfs->ls(array(
1002                                                        'string' => $this->path . '/' . $this->file, //FIXME
1003                                                        'relatives' => array(RELATIVE_NONE),
1004                                                        'checksubdirs' => False,
1005                                                        'nofiles' => True
1006                                          ));
1007                        if ($ls_array[0]['mime_type']) {
1008                                $mime_type = $ls_array[0]['mime_type'];
1009                        } elseif ($this->prefs['viewtextplain']) {
1010                                $mime_type = 'text/plain';
1011                        }
1012                        $viewable = array('text/plain', 'text/csv', 'text/html',
1013                                 'text/text', 'image/jpeg', 'image/png', 'image/gif',
1014                                 'audio/mpeg', 'video/mpeg');
1015
1016                        if (in_array($mime_type, $viewable)) {
1017                                /* Note: if you put application/octet-stream you force download */
1018                                header('Content-type: ' . $mime_type);
1019                                header('Content-disposition: filename="' . addslashes($this->file) . '"');
1020                                Header("Pragma: public");
1021                        } else {
1022                                $GLOBALS['phpgw']->browser->content_header($this->file, $mime_type, $ls_array[0]['size']);
1023                        }
1024                        if ($ls_array[0]['size'] < 10240) {
1025                                echo $this->bo->vfs->read(array(
1026                                         'string' => $this->path . '/' . $this->file, //FIXME
1027                                         'relatives' => array(RELATIVE_NONE)
1028                                ));
1029                        } else {
1030                                $this->bo->vfs->print_content(array(
1031                                         'string' => $this->path . '/' . $this->file,
1032                                         'relatives' => array(RELATIVE_NONE)
1033                                                  )
1034                                );
1035                        }
1036                        $GLOBALS['phpgw']->common->phpgw_exit();
1037                }
1038        }
1039
1040        function export()
1041        {
1042                if ($this->file)
1043                {
1044                        $ls_array = $this->bo->vfs->ls(array(
1045                                                        'string' => $this->path . '/' . $this->file,
1046                                                        'relatives' => array(RELATIVE_NONE),
1047                                                        'checksubdirs' => False,
1048                                                        'nofiles' => True
1049                                          ));
1050
1051                        $mime_type = $ls_array[0]['mime_type'];
1052                       
1053                        $formats = array('text/html');
1054                       
1055                        if (!in_array($mime_type, $formats))
1056                        {
1057                                echo lang('Impossible to export this file');
1058                                return False;
1059                        }
1060                       
1061                        $content = $this->bo->vfs->read(array('string' => $this->path . '/' . $this->file,
1062                                                        'relatives' => array(RELATIVE_NONE)
1063                                          ));
1064
1065                        include_once('filemanager/tp/dompdf/dompdf_config.inc.php');
1066                       
1067                        $dompdf = new DOMPDF();
1068                        $dompdf->load_html($content);
1069                        $dompdf->set_paper($this->prefs['pdf_paper_type'], $this->prefs['pdf_type']);
1070                        /* Would be nice to implement 'Title','Subject','Author','Creator','CreationDate' */
1071                        $dompdf->render();
1072                        $dompdf->stream(strtok($this->file, '.') . ".pdf");
1073                        $GLOBALS['phpgw']->common->phpgw_exit();
1074                }
1075        }
1076
1077        //give back an array with all directories except current and dirs that are not accessable
1078        function all_other_directories() {
1079                # First we get the directories in their home directory
1080                $dirs = array();
1081                $dirs[] = array('directory' => $this->bo->fakebase, 'name' => $this->bo->userinfo['account_lid']);
1082
1083                $tmp_arr = array(
1084                         'string' => $this->bo->homedir,
1085                         'relatives' => array(RELATIVE_NONE),
1086                         'checksubdirs' => True,
1087                         'mime_type' => 'Directory'
1088                );
1089
1090                $ls_array = $this->bo->vfs->ls($tmp_arr, True);
1091
1092                while (list($num, $dir) = each($ls_array)) {
1093                        $dirs[] = $dir;
1094                }
1095
1096
1097                # Then we get the directories in their readable groups' home directories
1098                reset($this->readable_groups);
1099                while (list($num, $group_array) = each($this->readable_groups)) {
1100                        // Don't list directories for groups that don't exists
1101                        $test = $this->bo->vfs->get_real_info(array('string' => $this->bo->fakebase . '/' . $group_array['account_name'],
1102                                                        'relatives' => array(RELATIVE_NONE), 'relative' => False));
1103                        if ($test[mime_type] != 'Directory') {
1104                                continue;
1105                        }
1106
1107                        $dirs[] = array('directory' => $this->bo->fakebase, 'name' => $group_array['account_name']);
1108
1109                        $tmp_arr = array(
1110                                 'string' => $this->bo->fakebase . '/' . $group_array['account_name'],
1111                                 'relatives' => array(RELATIVE_NONE),
1112                                 'checksubdirs' => True,
1113                                 'mime_type' => 'Directory'
1114                        );
1115
1116                        $ls_array = $this->bo->vfs->ls($tmp_arr, True);
1117                        while (list($num, $dir) = each($ls_array)) {
1118                                $dirs[] = $dir;
1119                        }
1120                }
1121                reset($dirs);
1122                while (list($num, $dir) = each($dirs)) {
1123                        if (!$dir['directory']) {
1124                                continue;
1125                        }
1126
1127                        # So we don't display //
1128                        if ($dir['directory'] != '/') {
1129                                $dir['directory'] .= '/';
1130                        }
1131                        $return[] = $dir;
1132                }
1133                return $return;
1134        }
1135
1136        function update_groups() {
1137                # Get their readable groups to be used throughout the script
1138                $acl = array();
1139                $groups = array();
1140                $acl = $GLOBALS['phpgw']->acl->get_ids_for_location($GLOBALS['phpgw_info']['user']['account_id'], 1, 'filemanager');
1141                if (is_array($acl))
1142                        foreach ($acl as $key => $value) {
1143                                $info = array();
1144                                $info = $GLOBALS['phpgw']->accounts->get_account_data($value);
1145                                $groups[$key]['account_id'] = $value;
1146                                $groups[$key]['account_lid'] = $info[$value]['lid'];
1147                                $groups[$key]['account_name'] = $info[$value]['firstname'];
1148                                $groups[$key]['account_lastname'] = $info[$value]['lastname'];
1149                                $groups[$key]['account_fullname'] = $info[$value]['fullname'];
1150                        }
1151                $this->readable_groups = array();
1152                while (list($num, $account) = each($groups)) {
1153                        if ($this->bo->vfs->acl_check(array('owner_id' => $account['account_id'], 'operation' => PHPGW_ACL_READ))) {
1154                                $this->readable_groups[$account['account_lid']] = Array('account_id' => $account['account_id'], 'account_name' => $account['account_lid']);
1155                        }
1156                }
1157        }
1158
1159        function search() {
1160                /* TODO this is a primitive search */
1161                $this->update_groups();
1162                $this->dirs = $this->all_other_directories();
1163                $path = $this->path;
1164                if (strlen($this->text) > 3) {
1165                        $this->text = strtoupper($this->text);
1166                        foreach ($this->dirs as $elem) {
1167                                $this->path = $elem['directory'] . $elem['name'];
1168                                reset($this->files_array);
1169                                $this->readFilesInfo();
1170                                for ($i = 0; $i < count($this->files_array); $i++) {
1171                                        $comment = strtoupper($this->files_array[$i]['comment']);
1172                                        $name = strtoupper($this->files_array[$i]['name']);
1173                                        if (strstr($name, $this->text) ||
1174                                                          strstr($comment, $this->text)) {
1175                                                $return[$this->files_array[$i]['directory'] . $name] = $this->files_array[$i];
1176                                                $return[$this->files_array[$i]['directory'] . $name]['icon'] = $this->mime_icon($this->files_array[$i]['mime_type']);
1177                                        }
1178                                }
1179                                if (count($return) > 50) {
1180                                        $return = array_slice($return, 0, 50);
1181                                        break;
1182                                }
1183                        }
1184                }
1185                echo serialize(array_values($return));
1186        }
1187
1188        /* seek icon for mimetype else return an unknown icon */
1189
1190        function mime_icon($mime_type, $size=16) {
1191                if (!$mime_type)
1192                        $mime_type = 'unknown';
1193
1194                $mime_type = str_replace('/', '_', $mime_type);
1195
1196                $img = $GLOBALS['phpgw']->common->image('filemanager', 'mime' . $size . '_' . strtolower($mime_type));
1197                if (!$img)
1198                        $img = $GLOBALS['phpgw']->common->image('filemanager', 'mime' . $size . '_unknown');
1199
1200                return $img;
1201        }
1202
1203        function toolButton($link, $img='', $description='') {
1204                $image = $GLOBALS['phpgw']->common->image('filemanager', 'button_' . strtolower($img));
1205
1206                if ($img) {
1207                        return '<div name="' . $link . '" class="toolButton" onclick="toolbar.control(\'' . $link . '\',this);" title="' . $description . '"><img src="' . $image . '" alt="' . $description . '"/><small>' . $description . '</small></div>';
1208                }
1209        }
1210
1211        function inputButton($name, $img='', $description='') {
1212                $image = $GLOBALS['phpgw']->common->image('filemanager', 'button_' . strtolower($img));
1213
1214                if ($img) {
1215                        return '<td class="" align="center" valign="middle" height="28" width="70">
1216                        <input title="' . $description . '" name="' . $name . '" type="image" alt="' . $name . '" src="' . $image . '" value="clicked" /><br><small>' . $description . '</small>
1217                        </td>';
1218                }
1219        }
1220
1221        function html_form_input($type = NULL, $name = NULL, $value = NULL, $maxlength = NULL, $size = NULL, $checked = NULL, $string = '', $return = 1) {
1222                $text = ' ';
1223                if ($type != NULL && $type) {
1224                        if ($type == 'checkbox') {
1225                                $value = $this->bo->string_encode($value, 1);
1226                        }
1227                        $text .= 'type="' . $type . '" ';
1228                }
1229                if ($name != NULL && $name) {
1230                        $text .= 'name="' . $name . '" ';
1231                }
1232                if ($value != NULL && $value) {
1233                        $text .= 'value="' . $value . '" ';
1234                }
1235                if (is_int($maxlength) && $maxlength >= 0) {
1236                        $text .= 'maxlength="' . $maxlength . '" ';
1237                }
1238                if (is_int($size) && $size >= 0) {
1239                        $text .= 'size="' . $size . '" ';
1240                }
1241                if ($checked != NULL && $checked) {
1242                        $text .= 'checked ';
1243                }
1244
1245                return '<input' . $text . $string . '>';
1246        }
1247
1248        function html_form_option($value = NULL, $displayed = NULL, $selected = NULL, $return = 0) {
1249                $text = ' ';
1250                if ($value != NULL && $value) {
1251                        $text .= ' value="' . $value . '" ';
1252                }
1253                if ($selected != NULL && $selected) {
1254                        $text .= ' selected';
1255                }
1256                return '<option' . $text . '>' . $displayed . '</option>';
1257        }
1258
1259        function encode_href($href = NULL, $args = NULL, $extra_args) {
1260                $href = $this->bo->string_encode($href, 1);
1261                $all_args = $args . '&' . $this->bo->string_encode($extra_args, 1);
1262
1263                $address = $GLOBALS['phpgw']->link($href, $all_args);
1264
1265                return $address;
1266        }
1267
1268        function html_link($href = NULL, $args = NULL, $extra_args, $text = NULL, $return = 1, $encode = 1, $linkonly = 0, $target = NULL) {
1269                //      unset($encode);
1270                if ($encode) {
1271                        $href = $this->bo->string_encode($href, 1);
1272                        $all_args = $args . '&' . $this->bo->string_encode($extra_args, 1);
1273                } else {
1274                        //                              $href = $this->bo->string_encode($href, 1);
1275                        $all_args = $args . '&' . $extra_args;
1276                }
1277                ###
1278                # This decodes / back to normal
1279                ###
1280                //                      $all_args = preg_replace("/%2F/", "/", $all_args);
1281                //                      $href = preg_replace("/%2F/", "/", $href);
1282
1283                /* Auto-detect and don't disturb absolute links */
1284                if (!preg_match("|^http(.{0,1})://|", $href)) {
1285                        //Only add an extra / if there isn't already one there
1286                        // die(SEP);
1287                        if (!($href[0] == SEP)) {
1288                                $href = SEP . $href;
1289                        }
1290
1291                        /* $phpgw->link requires that the extra vars be passed separately */
1292                        //                              $link_parts = explode("?", $href);
1293                        $address = $GLOBALS['phpgw']->link($href, $all_args);
1294                        //                              $address = $GLOBALS['phpgw']->link($href);
1295                } else {
1296                        $address = $href;
1297                }
1298
1299                /* If $linkonly is set, don't add any HTML */
1300                if ($linkonly) {
1301                        $rstring = $address;
1302                } else {
1303                        if ($target) {
1304                                $target = 'target=' . $target;
1305                        }
1306
1307                        $text = trim($text);
1308                        $rstring = '<a href="' . $address . '" ' . $target . '>' . $text . '</a>';
1309                }
1310
1311                return($this->bo->eor($rstring, $return));
1312        }
1313
1314        function html_table_begin($width = NULL, $border = NULL, $cellspacing = NULL, $cellpadding = NULL, $rules = NULL, $string = '', $return = 0) {
1315                if ($width != NULL && $width) {
1316                        $width = "width=$width";
1317                }
1318                if (is_int($border) && $border >= 0) {
1319                        $border = "border=$border";
1320                }
1321                if (is_int($cellspacing) && $cellspacing >= 0) {
1322                        $cellspacing = "cellspacing=$cellspacing";
1323                }
1324                if (is_int($cellpadding) && $cellpadding >= 0) {
1325                        $cellpadding = "cellpadding=$cellpadding";
1326                }
1327                if ($rules != NULL && $rules) {
1328                        $rules = "rules=$rules";
1329                }
1330
1331                $rstring = "<table $width $border $cellspacing $cellpadding $rules $string>";
1332                return($this->bo->eor($rstring, $return));
1333        }
1334
1335        function html_table_end($return = 0) {
1336                $rstring = "</table>";
1337                return($this->bo->eor($rstring, $return));
1338        }
1339
1340        function html_table_row_begin($align = NULL, $halign = NULL, $valign = NULL, $bgcolor = NULL, $string = '', $return = 0) {
1341                if ($align != NULL && $align) {
1342                        $align = "align=$align";
1343                }
1344                if ($halign != NULL && $halign) {
1345                        $halign = "halign=$halign";
1346                }
1347                if ($valign != NULL && $valign) {
1348                        $valign = "valign=$valign";
1349                }
1350                if ($bgcolor != NULL && $bgcolor) {
1351                        $bgcolor = "bgcolor=$bgcolor";
1352                }
1353                $rstring = "<tr $align $halign $valign $bgcolor $string>";
1354                return($this->bo->eor($rstring, $return));
1355        }
1356
1357        function html_table_row_end($return = 0) {
1358                $rstring = "</tr>";
1359                return($this->bo->eor($rstring, $return));
1360        }
1361
1362        function html_table_col_begin($align = NULL, $halign = NULL, $valign = NULL, $rowspan = NULL, $colspan = NULL, $string = '', $return = 0) {
1363                if ($align != NULL && $align) {
1364                        $align = "align=$align";
1365                }
1366                if ($halign != NULL && $halign) {
1367                        $halign = "halign=$halign";
1368                }
1369                if ($valign != NULL && $valign) {
1370                        $valign = "valign=$valign";
1371                }
1372                if (is_int($rowspan) && $rowspan >= 0) {
1373                        $rowspan = "rowspan=$rowspan";
1374                }
1375                if (is_int($colspan) && $colspan >= 0) {
1376                        $colspan = "colspan=$colspan";
1377                }
1378
1379                $rstring = "<td $align $halign $valign $rowspan $colspan $string>";
1380                return($this->bo->eor($rstring, $return));
1381        }
1382
1383        function html_table_col_end($return = 0) {
1384                $rstring = "</td>";
1385                return($this->bo->eor($rstring, $return));
1386        }
1387
1388}
Note: See TracBrowser for help on using the repository browser.