source: trunk/filemanager/inc/class.uifilemanager.inc.php @ 5322

Revision 5322, 47.9 KB checked in by niltonneto, 12 years ago (diff)

Ticket #663 - Alterado caminho do CKEditor para utilizar lib da API.

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