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

Revision 3885, 46.6 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #1657 - Correcao de layout para exibicao do historico do arquivo

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