source: sandbox/filemanager/inc/class.uifilemanager.inc.php @ 1627

Revision 1627, 68.3 KB checked in by amuller, 15 years ago (diff)

Ticket #597 - Implementações novas, com arquivos restritos, quota, ckeditor

  • Property svn:executable set to *
Line 
1<?php
2        /**************************************************************************\
3        * -------------------------------------------------------------------------*
4        * This library is free software; you can redistribute it and/or modify it  *
5        * under the terms of the GNU Lesser General Public License as published by *
6        * the Free Software Foundation; either version 2.1 of the License,         *
7        * or any later version.                                                    *
8        * This library is distributed in the hope that it will be useful, but      *
9        * WITHOUT ANY WARRANTY; without even the implied warranty of               *
10        * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
11        * See the GNU Lesser General Public License for more details.              *
12        * You should have received a copy of the GNU Lesser General Public License *
13        * along with this library; if not, write to the Free Software Foundation,  *
14        * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            *
15        \**************************************************************************/
16
17        /* $Id: class.uifilemanager.inc.php 17511 2004-12-12 06:35:24Z dawnlinux $ */
18
19        class uifilemanager
20        {
21                var $public_functions = array(
22                        'index' => True,
23                        'help'  => True,
24                        'view'  => True,
25                        'export'=> True,
26                        'touch' => True,
27                        'history' => True,
28                        'edit' => True,
29                        'fileModels'=>True,
30                        'uploadModel'=>True
31                );
32
33                //keep
34                var $bo;
35                var $vfs_functions;
36                var $t; //template object
37                var $dispath;
38                var $cwd;
39                var $lesspath;
40                var $readable_groups;
41                var $files_array;
42                var $numoffiles;
43                var $dispsep;
44
45                var $target;
46
47                var $prefs;//array
48
49                var $groups_applications;
50
51                //originally post_vars
52                //              var $goto;
53                var $current_config;
54                var $goto_x;
55                var $todir;
56                var $changedir; // for switching dir.
57                var $cdtodir; // for switching dir.
58//              var $createdir;
59                var $newfile_or_dir;
60                var $newdir_x;
61                var $newfile_x;
62                var $createfile_var;
63                var $delete_x;
64                var $renamefiles;
65                var $rename_x;
66                var $move_to_x;
67//              var $copy_to;
68                var $copy_to_x;
69                var $edit_x;
70                var $edit_comments_x;
71                var $edit_file;
72                var $edit_preview_x;
73                var $edit_save_x;
74                var $edit_save_done_x;
75                var $edit_cancel_x;
76                var $comment_files;
77                var $upload_x;
78                var $uploadprocess;
79
80                // this ones must be checked thorougly;
81                var $fileman = Array();
82                //var $fileman;
83                var $path;
84                var $file; // FIXME WHERE IS THIS FILLED?
85                var $sortby;
86                var $messages = array();
87                var $show_upload_boxes;
88
89                var $debug = false;
90                var $now;
91
92                function uifilemanager()
93                {
94                        //                      error_reporting(8);
95                        $GLOBALS['phpgw']->browser = CreateObject('phpgwapi.browser');
96
97                        $this->now = date('Y-m-d');
98
99                        $this->bo = CreateObject('filemanager.bofilemanager');
100
101                        $this->vfs_functions = CreateObject('filemanager.vfs_functions');
102
103                        $this->t = $GLOBALS['phpgw']->template;
104                        $c = CreateObject('phpgwapi.config','filemanager');
105                        $c->read_repository();
106                        $this->current_config = $c->config_data;
107
108
109                        // here local vars are created from the HTTP vars
110                        @reset($GLOBALS['HTTP_POST_VARS']);
111                        while(list($name,) = @each($GLOBALS['HTTP_POST_VARS']))
112                        {
113                                $this->$name = $GLOBALS['HTTP_POST_VARS'][$name];
114                        }
115
116                        @reset($GLOBALS['HTTP_GET_VARS']);
117                        while(list($name,) = @each($GLOBALS['HTTP_GET_VARS']))
118                        {
119                                $$name = $GLOBALS['HTTP_GET_VARS'][$name];
120                                $this->$name = $GLOBALS['HTTP_GET_VARS'][$name];
121
122                        }
123
124                        $to_decode = array
125                        (
126                                /*
127                                Decode
128                                'var'   when      'avar' == 'value'
129                                or
130                                'var'   when      'var'  is set
131                                */
132                                'op'    => array('op' => ''),
133                                'path'  => array('path' => ''),
134                                'file'  => array('file' => ''),
135                                'sortby'        => array('sortby' => ''),
136                                //                              'fileman'       => array('fileman' => ''),
137                                'messages'      => array('messages'     => ''),
138                                //                              'help_name'     => array('help_name' => ''),
139                                //                              'renamefiles'   => array('renamefiles' => ''),
140                                'comment_files' => array('comment_files' => ''),
141                                'show_upload_boxes'     => array('show_upload_boxes' => '')
142                        );
143
144                        reset($to_decode);
145                        while(list($var, $conditions) = each($to_decode))
146                        {
147                                while(list($condvar, $condvalue) = each($conditions))
148                                {
149                                        if(isset($$condvar) && ($condvar == $var || $$condvar == $condvalue))
150                                        {
151                                                if(is_array($$var))
152                                                {
153                                                        $temp = array();
154                                                        while(list($varkey, $varvalue) = each($$var))
155                                                        {
156                                                                if(is_int($varkey))
157                                                                {
158                                                                        $temp[$varkey] = stripslashes(base64_decode(urldecode(($varvalue))));
159                                                                }
160                                                                else
161                                                                {
162                                                                        $temp[stripslashes(base64_decode(urldecode(($varkey))))] = $varvalue;
163                                                                }
164                                                        }
165                                                        $this->$var = $temp;
166                                                }
167                                                elseif(isset($$var))
168                                                {
169                                                        $this->$var = stripslashes(base64_decode(urldecode($$var)));
170                                                }
171                                        }
172                                }
173                        }
174
175                        // get appl. and user prefs
176                        $pref = CreateObject('phpgwapi.preferences', $this->bo->userinfo['username']);
177                        $pref->read_repository();
178                        //                      $GLOBALS['phpgw']->hooks->single('add_def_pref', $GLOBALS['appname']);
179                        $pref->save_repository(True);
180                        $pref_array = $pref->read_repository();
181                        $this->prefs = $pref_array[$this->bo->appname]; //FIXME check appname var in _debug_array
182
183                        //always show name
184
185                        $this->prefs[name] =1;
186
187
188                        if($this->prefs['viewinnewwin'])
189                        {
190                                $this->target = '_blank';
191                        }
192
193
194                        /*
195                                Check for essential directories
196                                admin must be able to disable these tests
197                        */
198                       
199                        // check if basedir exist
200                        $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
201                        if($test[mime_type]!='Directory')
202                        {
203                                die('Base directory does not exist, Ask adminstrator to check the global configuration.');
204                        }
205
206                        $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->fakebase, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
207                        if($test[mime_type]!='Directory')
208                        {
209
210                                $this->bo->vfs->override_acl = 1;
211
212                                $this->bo->vfs->mkdir(array(
213                                        'string' => $this->bo->fakebase,
214                                        'relatives' => array(RELATIVE_NONE)
215                                ));
216                               
217                                $this->bo->vfs->override_acl = 0;
218
219                                //test one more time
220                                $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->fakebase, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
221
222                                if($test[mime_type]!='Directory')
223                                {
224                                        die('Fake Base directory does not exist and could not be created, please ask the administrator to check the global configuration.');
225                                }
226                                else
227                                {
228                                        $this->messages[]= lang('Fake Base Dir did not exist, eGroupWare created a new one.');
229                                }
230                        }
231
232//                      die($this->bo->homedir);
233                        $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->homedir, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
234                        if($test[mime_type]!='Directory')
235                        {
236                                $this->bo->vfs->override_acl = 1;
237
238                                $this->bo->vfs->mkdir(array(
239                                        'string' => $this->bo->homedir,
240                                        'relatives' => array(RELATIVE_NONE)
241                                ));
242                                $this->bo->vfs->set_quota(array(
243                                        'string' => $this->bo->homedir,
244                                        'relatives' => array(RELATIVE_NONE),
245                                        'new_quota' => $this->current_config['filemanager_quota_size']
246                                ));
247       
248                                $this->bo->vfs->override_acl = 0;
249
250                                //test one more time
251                                $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->homedir, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
252
253                                if($test[mime_type]!='Directory')
254                                {
255                                        die('Your Home Dir does not exist and could not be created, please ask the adminstrator to check the global configuration.');
256                                }
257                                else
258                                {
259                                        $this->messages[]= lang('Your Home Dir did not exist, eGroupWare created a new one.');
260                                        // FIXME we just created a fresh home dir so we know there nothing in it so we have to remove all existing content
261                                }
262                        }
263                       
264                       
265                }
266                function fileModels()
267                {
268                        $GLOBALS['phpgw_info']['flags'] = array
269                                (
270                                        'currentapp'    => 'filemanager',
271                                        'noheader'      => False,
272                                        'nonavbar' => False,
273                                        'nofooter'      => False,
274                                        'noappheader'   => False,
275                                        'enable_browser_class'  => True
276                                );
277
278                        $GLOBALS['phpgw']->common->phpgw_header();
279                        $this->t->set_file(array('models' => 'fileModels.tpl'));
280                        $this->t->set_block('models','header','header');
281                        $this->t->set_block('models','body','body');
282                        $this->t->set_block('models','footer','footer');
283                        $this->t->set_var('url_1', './index.php?menuaction=filemanager.uifilemanager.uploadModel&model=article');
284                        $this->t->set_var('model_1','article');
285                        $this->t->set_var('lang_1',lang('article'));
286
287                        $this->t->set_var('url_2','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=calendar');
288                        $this->t->set_var('model_2','calendar');
289                        $this->t->set_var('lang_2',lang('calendar'));
290
291                        $this->t->set_var('url_3','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=todo');
292                        $this->t->set_var('model_3','todo');
293                        $this->t->set_var('lang_3',lang('todo'));
294
295                        $this->t->set_var('url_4','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=slide');
296                        $this->t->set_var('model_4','slide');
297                        $this->t->set_var('lang_4',lang('slide'));
298
299                        $this->t->set_var('url_5','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=cards');
300                        $this->t->set_var('model_5','cards');
301                        $this->t->set_var('lang_5',lang('cards'));
302
303                        $this->t->set_var('url_6','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=resume');
304                        $this->t->set_var('model_6','resume');
305                        $this->t->set_var('lang_6',lang('resume'));
306
307
308                        $this->t->pparse('out','models');
309
310
311                }
312                function uploadModel(){
313                        $GLOBALS['phpgw_info']['flags'] = array
314                                (
315                                        'currentapp'    => 'filemanager',
316                                        'noheader'      => False,
317                                        'nonavbar' => False,
318                                        'nofooter'      => False,
319                                        'noappheader'   => False,
320                                        'enable_browser_class'  => True
321                                );
322
323                        $GLOBALS['phpgw']->common->phpgw_header();
324
325                        $filename = lang('new')."_".lang($this->model).rand(0,1000).".html";
326                        $this->bo->vfs->cp(array(
327                                'from'=> PHPGW_SERVER_ROOT . '/filemanager/templates/default/'.$this->model.'.html',
328                                'to'=> $filename,
329                                'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
330                        ));
331
332                        $this->bo->vfs->set_attributes(array(
333                                'string'=> $filename,
334                                'relatives'     => array(RELATIVE_ALL),
335                                'attributes'=> array(
336                                        'mime_type' => "text/html",
337                                        'comment' => ""
338                                )
339                        ));
340                        $this->fileman[0] = $filename;
341                        $this->edit();
342
343                }
344                function index()
345                {
346                        if($noheader || $nofooter || (count($this->fileman) > 0))
347                        {
348                                $noheader = True;
349                                $nofooter = True;
350                                $noappheader= True;
351                                $nonavbar= True;
352                        }
353                        else
354                        {
355                                $GLOBALS['phpgw_info']['flags'] = array
356                                (
357                                        'currentapp'    => 'filemanager',
358                                        'noheader'      => $noheader,
359                                        'nonavbar' => $nonavbar,
360                                        'nofooter'      => $nofooter,
361                                        'noappheader'   => $noappheader,
362                                        'enable_browser_class'  => True
363                                );
364
365                                $GLOBALS['phpgw']->common->phpgw_header();
366
367                        }
368
369                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/global.js'></script>";
370                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/main.js'></script>";
371                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/common_functions.js'></script>";
372                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/connector.js'></script>";
373                        include('load_lang.php');
374
375                        # Page to process users
376                        # Code is fairly hackish at the beginning, but it gets better
377                        # Highly suggest turning wrapping off due to long SQL queries
378
379                        ###
380                        # Some hacks to set and display directory paths correctly
381                        ###
382                        if(!($this->edit_x || $this->edit_save_x || $this->edit_save_done_x) && !$this->bo->vfs->acl_check(array(
383                                'string' => $this->path,
384                                'relatives' => array(RELATIVE_NONE),
385                                'operation' => PHPGW_ACL_READ
386                        )))
387                        {
388                                $this->path = $this->bo->homedir;       
389                        }
390                        // new method for switching to a new dir.
391                        if($this->changedir=='true' && $this->cdtodir || $this->goto_x)
392                        {
393                                $this->path = $this->cdtodir;
394                        }
395
396                        if(!$this->path)
397                        {
398                                $this->path = $this->bo->vfs->pwd();
399
400                                if(!$this->path || $this->bo->vfs->pwd(array('full' => False)) == '')
401                                {
402                                        $this->path = $this->bo->homedir;
403                                }
404                        }
405
406                        $this->bo->vfs->cd(array('string' => False, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
407                        $this->bo->vfs->cd(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
408
409                        $pwd = $this->bo->vfs->pwd();
410
411                        if(!$this->cwd = substr($this->path, strlen($this->bo->homedir) + 1)) 
412                        {
413                                $this->cwd = '/';
414                        }
415                        else
416                        {
417                                $this->cwd = substr($pwd, strrpos($pwd, '/') + 1);
418                        }
419
420                        $this->disppath = $this->path;
421
422                        /* This just prevents // in some cases */
423                        if($this->path == '/')
424                        {
425                                $this->dispsep = '';
426                        }
427                        else
428                        {
429                                $this->dispsep = '/';
430                        }
431
432                        if(!($this->lesspath = substr($this->path, 0, strrpos($this->path, '/'))))
433                        {
434                                $this->lesspath = '/';
435                        }
436
437                        # Get their readable groups to be used throughout the script
438                        $acl = array();
439                        $groups = array();
440                        $acl = $GLOBALS['phpgw']->acl->get_ids_for_location($GLOBALS['phpgw_info']['user']['account_id'],1,'filemanager');
441                        if (is_array($acl))
442                                foreach($acl as $key => $value){
443                                        $info = array();
444                                        $info = $GLOBALS['phpgw']->accounts->get_account_data($value);
445                                        $groups[$key]['account_id'] = $value;
446                                        $groups[$key]['account_lid'] = $info[$value]['lid'];
447                                        $groups[$key]['account_name'] = $info[$value]['firstname'];
448                                        $groups[$key]['account_lastname'] = $info[$value]['lastname'];
449                                        $groups[$key]['account_fullname'] = $info[$value]['fullname'];
450                                }
451                        $this->readable_groups = array();
452                        while(list($num, $account) = each($groups))
453                        {
454//                              if($this->bo->vfs->acl_check(array('owner_id' => $account['account_id'],'operation' => PHPGW_ACL_READ)))
455                                {
456                                        $this->readable_groups[$account['account_lid']] = Array('account_id' => $account['account_id'], 'account_name' => $account['account_lid']);
457                                }
458                        }
459
460
461                        $this->groups_applications = array();
462
463                        foreach ($this->readable_groups as $value)
464                        {
465                                $applications = CreateObject('phpgwapi.applications', $value['account_id']);
466                                $this->groups_applications[$value['account_name']] = $applications->read_account_specific();
467                        }
468
469                        # We determine if they're in their home directory or a group's directory,
470                        # and set the VFS working_id appropriately
471                        if((preg_match('+^'.$this->bo->fakebase.'\/(.*)(\/|$)+U', $this->path, $matches)) && $matches[1] != $this->bo->userinfo['account_lid']) //FIXME matches not defined
472
473                        {
474                                $this->bo->vfs->working_id = $GLOBALS['phpgw']->accounts->name2id($matches[1]);//FIXME matches not defined
475
476                        }
477                        else
478                        {
479                                $this->bo->vfs->working_id = $this->bo->userinfo['username'];
480                        }
481
482                        # FIXME # comment waht happens here
483                        if($this->path != $this->bo->homedir && $this->path != $this->bo->fakebase && $this->path != '/' && !$this->bo->vfs->acl_check(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE),'operation' => PHPGW_ACL_READ)))
484                        {
485                                $this->messages[]= lang('Error:').lang('You do not have access to %1', $this->path);
486                                $this->html_link('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->homedir, lang('Go to your home directory'));
487
488                                $GLOBALS['phpgw']->common->phpgw_footer();
489                                $GLOBALS['phpgw']->common->phpgw_exit();
490                        }
491
492                        $this->bo->userinfo['working_id'] = $this->bo->vfs->working_id;
493                        $this->bo->userinfo['working_lid'] = $GLOBALS['phpgw']->accounts->id2name($this->bo->userinfo['working_id']);
494
495                        # If their home directory doesn't exist, we try to create it
496                        # Same for group directories
497
498                       
499                // Moved to constructor
500                /*
501                        if(($this->path == $this->homedir)      && !$this->bo->vfs->file_exists($pim_tmp_arr))
502                        {
503                                $this->bo->vfs->override_acl = 1;
504
505                                if(!$this->bo->vfs->mkdir(array(
506                                        'string' => $this->bo->homedir,
507                                        'relatives' => array(RELATIVE_NONE)
508                                )))
509                                {
510                                        $p = $this->bo->vfs->path_parts($pim_tmp_arr);
511
512                                        $this->messages[]= $GLOBALS['phpgw']->common->error_list(array(
513                                                lang('Could not create directory %1',
514                                                $this->bo->homedir . ' (' . $p->real_full_path . ')'
515                                        )));
516                                }
517
518                                $this->bo->vfs->override_acl = 0;
519                        }
520                        */
521
522                        # Verify path is real
523                        if($this->path != $this->bo->homedir && $this->path != '/' && $this->path != $this->bo->fakebase)
524                        {
525                                if(!$this->bo->vfs->file_exists(array(
526                                        'string' => $this->path,
527                                        'relatives' => array(RELATIVE_NONE)
528                                )))
529                                {
530                                        $this->messages[] = lang('Error:').lang('Directory %1 does not exist', $this->path);
531                                        $this->html_link('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->bo->homedir, lang('Go to your home directory'));
532
533                                        $GLOBALS['phpgw']->common->phpgw_footer();
534                                        $GLOBALS['phpgw']->common->phpgw_exit();
535                                }
536                        }
537
538
539                        /* Update the vfs */
540                        if ($_GET['update'] == 'True')
541                        {
542                                $this->bo->vfs->update_real(array(
543                                        'string' => $this->path,
544                                        'relatives' => array(RELATIVE_ALL)
545                                ));
546                        }
547
548                        # Check available permissions for $this->path, so we can disable unusable operations in user interface
549                        if($this->bo->vfs->acl_check(array(
550                                'string' => $this->path,
551                                'relatives' => array(RELATIVE_NONE),
552                                'operation' => PHPGW_ACL_ADD
553                        )))
554                        {
555                                $this->can_add = True;
556                        }
557                        if($this->bo->vfs->acl_check(array(
558                                'string' => $this->path,
559                                'relatives' => array(RELATIVE_NONE),
560                                'operation' => PHPGW_ACL_EDIT
561                        )))
562                        {
563                                $this->can_edit = True;
564                        }
565                        if($this->bo->vfs->acl_check(array(
566                                'string' => $this->path,
567                                'relatives' => array(RELATIVE_NONE),
568                                'operation' => PHPGW_ACL_DELETE
569                        )))
570                        {
571                                $this->can_delete = True;
572                        }
573
574
575                        # Default is to sort by name
576                        if(!$this->sortby)
577                        {
578                                $this->sortby = 'name';
579                        }
580
581                        if($this->debug)
582                        {
583                                $this->debug_filemanager();
584                        }
585
586                        # main action switch
587                        // FIXME this will become a switch
588                        if($this->newfile_x && $this->newfile_or_dir) // create new textfile
589                        {
590                                $this->createfile();
591                        }
592                        elseif($this->newfile_or_dir && $this->newdir_x)
593                        {
594                                $this->createdir();
595                        }
596                        elseif($this->uploadprocess)
597                        {
598                                $this->fileUpload();
599                        }
600                        elseif($this->upload_x || $this->show_upload_boxes)
601                        {
602                                $this->showUploadboxes();
603                        }
604                        elseif($this->copy_to_x)
605                        {
606                                $this->copyTo();
607                        }
608                        elseif($this->move_to_x)
609                        {
610                                $this->moveTo();
611                        }
612                        elseif($this->renamefiles)
613                        {
614                                $this->rename();
615                        }
616                        elseif($this->comment_files)
617                        {
618                                $this->editComment();
619                        }
620                        elseif($this->edit_cancel_x)
621                        {
622                                $this->readFilesInfo();
623                                $this->fileListing();
624                        }
625                        elseif($this->edit_x || $this->edit_preview_x || $this->edit_save_x || $this->edit_save_done_x)
626                        {
627                                $this->edit();
628                        }
629                        elseif($this->delete_x)
630                        {
631                                $this->delete();
632                        }
633                        else
634                        {
635                                $this->readFilesInfo();
636                                $this->fileListing();
637                        }
638                }
639                function fileListing()
640                {
641                        $this->t->set_file(array('filemanager_list_t' => 'filelisting.tpl'));
642                        $this->t->set_block('filemanager_list_t','filemanager_header','filemanager_header');
643                        $this->t->set_block('filemanager_list_t','column','column');
644                        $this->t->set_block('filemanager_list_t','row','row');
645                        $this->t->set_block('filemanager_list_t','filemanager_footer','filemanager_footer');
646
647                        $vars['form_action']=$this->encode_href('/index.php', 'menuaction=filemanager.uifilemanager.index','path='.$this->path);
648                        if($this->numoffiles || $this->cwd)
649                        {
650                                while(list($num, $name) = each($this->prefs))
651                                {
652                                        if($name)
653                                        {
654                                                $columns++;
655                                        }
656                                }
657                                $columns++;
658                                $usedSpace = $this->bo->vfs->get_size(array(
659                                        'string'        => $this->path,
660                                        'relatives'     => array(RELATIVE_NONE)
661                                ));
662                                $quota = $this->bo->vfs->get_quota(array(
663                                        'string'        => $this->path
664                                ));
665
666                                $vars[usedSpace]='<input type="hidden" id="usedSpace" value="'.$usedSpace.'">';
667                                $vars[quotaSize]='<input type="hidden" id="quotaSize" value="'.($quota*1024*1024).'">';
668                                $vars[javascript]='<script src="filemanager/js/draw_api.js"></script>
669                                        <link rel="stylesheet" type="text/css" href="filemanager/templates/default/main.css">';
670                                $vars[toolbar0]=$this->toolbar('location');
671                                $vars[toolbar1]=$this->toolbar('list_nav');
672
673                                if(count($this->messages)>0)
674                                {
675                                        foreach($this->messages as $msg)
676                                        {
677                                                $messages.='<p>'.$msg.'</p>';
678                                        }
679                                }
680
681                                $vars[messages]=$messages;
682
683                                $this->t->set_var($vars);
684                                $this->t->pparse('out','filemanager_header');
685
686                                ###
687                                # Start File Table Column Headers
688                                # Reads values from $file_attributes array and preferences
689                                ###
690                                $this->t->set_var('actions',lang('select'));
691                                $this->t->set_var('mini_bar','&nbsp;');
692
693
694                                reset($this->bo->file_attributes);
695
696                                if($this->numoffiles>0)
697                                {
698                                        while(list($internal, $displayed) = each($this->bo->file_attributes))
699                                        {
700                                                if($this->prefs[$internal])
701                                                {
702                                                        if ($internal != 'owner')
703                                                                $col_data='<span><a href="'.$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->path.'&sortby='.$internal).'">'.$displayed.'</a></span>';
704                                                        else
705                                                                $col_data='<span>'.$displayed.'</span>';
706                                                        $this->t->set_var('col_data',$col_data);
707                                                        $this->t->parse('columns','column',True);
708                                                }
709                                        }
710
711                                        $this->t->set_var('row_tr_color','#dedede');
712                                       
713                                        $this->t->parse('rows','row');
714                                       
715                                        $this->t->pparse('out','row');
716                                }
717                                else
718                                {
719                                        $lang_nofiles=lang('No files in this directory.');
720                                }
721                                $vars[lang_no_files]=$lang_nofiles;
722
723
724                                if($this->prefs['dotdot'] && $this->prefs['name'] && $this->path != '/')
725                                {
726                                        $this->t->set_var('actions','');
727
728                                        $link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->lesspath);
729
730                                        $col_data='<a href="'.$link.'"><img src="'.$GLOBALS['phpgw']->common->image('filemanager','mime16up').' "alt="'.lang('Folder Up').'" /></a>';
731                                        $col_data.='&nbsp;<a href="'.$link.'">..</a>';
732
733                                        $this->t->set_var('col_data',$col_data);
734                                        $this->t->parse('columns','column');
735
736                                        if($this->prefs['mime_type'])
737                                        {
738                                                $col_data=lang('Directory');
739                                                $this->t->set_var('col_data',$col_data);
740                                                $this->t->parse('columns','column',True);
741                                        }
742
743                                        $this->t->set_var('row_tr_color',$tr_color);
744                                        $this->t->parse('rows','row');
745                                        $this->t->pparse('out','row');
746                                }
747
748                                # List all of the files, with their attributes
749                                @reset($this->files_array);
750                                for($i = 0; $i != $this->numoffiles; $i++)
751                                {
752                                        $files = $this->files_array[$i];
753
754                                        if($this->rename_x || $this->edit_comments_x)
755                                        {
756                                                unset($this_selected);
757                                                unset($renamethis);
758                                                unset($edit_this_comment);
759
760                                                for($j = 0; $j != $this->numoffiles; $j++)
761                                                {
762                                                        if($this->fileman[$j] == $files['name'])
763                                                        {
764                                                                $this_selected = 1;
765                                                                break;
766                                                        }
767                                                }
768
769                                                if($this->rename_x && $this_selected)
770                                                {
771                                                        $renamethis = 1;
772                                                }
773                                                elseif($this->edit_comments_x && $this_selected)
774                                                {
775                                                        $edit_this_comment = 1;
776                                                }
777                                        }
778
779                                        if(!$this->prefs['dotfiles'] && ereg("^\.", $files['name']))
780                                        {
781                                                continue;
782                                        }
783
784                                        # Checkboxes
785                                        if(!$this->rename_x && !$this->edit_comments_x && $this->path != $this->bo->fakebase && $this->path != '/')
786                                        {
787                                                $cbox='<input type="checkbox" class="checkbox" name="fileman['.$i.']" value="'.$files['name'].'">';
788                                                $this->t->set_var('actions',$cbox);
789                                        }
790                                        elseif($renamethis)
791                                        {
792                                                $cbox=$this->html_form_input('hidden', 'fileman[' . base64_encode($files['name']) . ']', $files['name'], NULL, NULL, 'checked');
793                                                $this->t->set_var('actions',$cbox);
794                                        }
795                                        else
796                                        {
797                                                $this->t->set_var('actions','');
798                                        }
799                                        $minibar_data="";
800                                        if($this->path == $this->bo->homedir)
801                                        {
802                                                if ($files['type'] == "1")
803                                                {
804                                                        $image = $GLOBALS['phpgw']->common->image('filemanager','button_lock');
805                                                }
806                                                else
807                                                {
808                                                        $image = $GLOBALS['phpgw']->common->image('filemanager','button_unlock');
809                                                }
810                                                $link=$this->encode_href('/index.php','menuaction=filemanager.vfs_functions.setRestricted','file='.$files['name'].'&path='.$this->path);
811                                                $minibar_data = '<img id="restrict_'.$files['name'].'" onclick="javascript:cExecute(\''.$link.'\',setRestricted)" alt="'.lang("mark as restricted").'" title="'.lang("mark as restricted").'" src="'.$image.'">';
812                                        }
813
814
815                                        if ($files['mime_type'] == "text/html")
816                                        {
817                                                $link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.export','file='.$files['name'].'&path='.$this->path);
818                                                $image=$GLOBALS['phpgw']->common->image('filemanager','button_export');
819                                                $minibar_data.='<a href="'.$link.'"><img alt="'.lang("export").'" title="'.lang("export").'" src="'.$image.'"></a>';
820                                        }
821                                        else
822                                                $minibar_data.= "<a>&nbsp;</a>";
823                                        $this->t->set_var('mini_bar',$minibar_data);
824
825
826                                        # File name and icon
827                                        if($renamethis)
828                                        {
829                                                $col_data=$this->mime_icon($files['mime_type']);
830                                                $col_data.='<input type="text" maxlength="255" name="renamefiles[' . $files['name'] . ']" value="'.$files['name'].'">';
831                                        }
832                                        else
833                                        {
834                                                if($files['mime_type'] == 'Directory')
835                                                {
836                                                        $link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->path.$this->dispsep.$files['name']);
837
838                                                        $icon=$this->mime_icon($files['mime_type']);
839
840                                                        $col_data='<a href="'.$link.'">'.$icon.'</a>&nbsp;';
841                                                        $col_data.='<a href="'.$link.'">'.$files['name'].'</a>&nbsp;';
842                                                }
843                                                else
844                                                {
845
846                                                        if($this->prefs['viewonserver'] && isset($this->bo->filesdir) && !$files['link_directory'])
847                                                        {
848                                                                #FIXME
849                                                                $clickview = $this->filesdir.$pwd.'/'.$files['name'];
850
851                                                                if($phpwh_debug)
852                                                                {
853                                                                        echo 'Setting clickview = '.$clickview.'<br>'."\n";
854                                                                        $this->html_link($clickview,'', '',$files['name'], 0, 1, 0, '');
855                                                                }
856                                                        }
857                                                        else
858                                                        {
859                                                                $icon=$this->mime_icon($files['mime_type']);
860                                                                $link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.view','file='.$files['name'].'&path='.$this->path);
861
862                                                                $col_data='<a href="'.$link.'" target="'.$this->target.'">'.$icon.'</a>&nbsp;<a href="'.$link.'" target="'.$this->target.'">'.$files['name'].'</a>';
863                                                        }
864                                                }
865                                        }
866
867                                        $this->t->set_var('col_data',$col_data);
868                                        $this->t->parse('columns','column');
869
870                                        # MIME type
871                                        if($this->prefs['mime_type'])
872                                        {
873                                                $col_data=$files['mime_type'];
874                                                $this->t->set_var('col_data',$col_data);
875                                                $this->t->parse('columns','column',True);
876                                        }
877
878                                        # File size
879                                        if($this->prefs['size'])
880                                        {
881                                                $tmp_arr=array(
882                                                        'string'        => $files['directory'] . '/' . $files['name'],
883                                                        'relatives'     => array(RELATIVE_NONE)
884                                                );
885                                                if($files['mime_type'] != 'Directory') $tmp_arr['checksubdirs'] = false;
886
887                                                $size = $this->bo->vfs->get_size($tmp_arr);
888
889                                                $col_data=$this->bo->borkb($size);
890
891                                                $this->t->set_var('col_data',$col_data);
892                                                $this->t->parse('columns','column',True);
893                                        }
894
895                                        # Date created
896                                        if($this->prefs['created'])
897                                        {
898                                                $timestamp = $this->vfs_functions->dateString2timeStamp($files['created']);
899                                                if (time() - $timestamp > 86400) // Older than yesterday
900                                                        $col_data=date("Y-m-d",$timestamp);
901                                                else
902                                                        $col_data=date("H:i",$timestamp);
903                                                $this->t->set_var('col_data',$col_data);
904                                                $this->t->parse('columns','column',True);
905                                        }
906
907                                        # Date modified
908                                        if($this->prefs['modified'])
909                                        {
910                                                if ($files['modified'] != ''){
911                                                        $timestamp = $this->vfs_functions->dateString2timeStamp($files['modified']);
912                                                        if (time() - $timestamp > 86400) // Older than yesterday
913                                                                $col_data=date("Y-m-d",$timestamp);
914                                                        else
915                                                                $col_data=date("H:i",$timestamp);
916                                                }
917                                                else
918                                                        $col_data='';
919                                                $this->t->set_var('col_data',$col_data);
920                                                $this->t->parse('columns','column',True);
921                                        }
922
923                                        # Owner name
924                                        if($this->prefs['owner'])
925                                        {
926                                                $this->t->set_var('col_data',$GLOBALS['phpgw']->accounts->id2name($files['owner_id']));
927                                                $this->t->parse('columns','column',True);
928                                        }
929
930                                        # Creator name
931                                        if($this->prefs['createdby_id'])
932                                        {
933                                                $this->html_table_col_begin();
934                                                if($files['createdby_id'])
935                                                {
936                                                        $col_data=$GLOBALS['phpgw']->accounts->id2name($files['createdby_id']);
937                                                }
938                                                else $col_data='';
939
940                                                $this->t->set_var('col_data',$col_data);
941                                                $this->t->parse('columns','column',True);
942                                        }
943
944                                        # Modified by name
945                                        if($this->prefs['modifiedby_id'])
946                                        {
947                                                if($files['modifiedby_id'])
948                                                {
949                                                        $col_data=$GLOBALS['phpgw']->accounts->id2name($files['modifiedby_id']);
950                                                }
951                                                else $col_data='';
952                                                $this->t->set_var('col_data',$col_data);
953                                                $this->t->parse('columns','column',True);
954                                        }
955
956                                        # Application
957                                        if($this->prefs['app'])
958                                        {
959                                                $col_data=$files['app'];
960                                                $this->t->set_var('col_data',$col_data);
961                                                $this->t->parse('columns','column',True);
962                                        }
963
964                                        # Comment
965                                        if($this->prefs['comment'])
966                                        {
967                                                if($edit_this_comment)
968                                                {
969                                                        $col_data='<input type="text" name="comment_files[' . $files['name'] . ']" value="'.$files['comment'].'" maxlength="255">';
970                                                }
971                                                else
972                                                {
973                                                        $col_data=$files['comment'];
974                                                }
975                                                $this->t->set_var('col_data',$col_data);
976                                                $this->t->parse('columns','column',True);
977                                        }
978
979                                        # Version
980                                        if($this->prefs['version'])
981                                        {
982                                                $link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.history','file='.$files['name'].'&path='.$this->path);
983                                                $col_data='<a href="'.$link.'" target="_blank">'.$files['version'].'</a>';
984                                                $this->t->set_var('col_data',$col_data);
985                                                $this->t->parse('columns','column',True);
986                                        }
987
988                                        $usedspace += $files['size'];
989
990                                        $this->t->set_var('row_tr_color','');
991                                        $this->t->parse('rows','row');
992                                        $this->t->pparse('out','row');
993                                }
994
995                                // when renaming or changing comments render extra sumbmit button
996                                if($this->rename_x || $this->edit_comments_x)
997                                {
998                                        $col_data='<br/><input type="submit" name="save_changes" value="'.lang('Save changes').'">';
999                                        $this->t->set_var('col_data',$col_data);
1000                                        $this->t->parse('columns','column');
1001                                        $this->t->set_var('row_tr_color','');
1002                                        $this->t->parse('rows','row');
1003                                        $this->t->pparse('out','row');
1004                                }
1005                        }
1006
1007                        // The file and directory information
1008                        $vars[lang_files_in_this_dir]=lang('Files in this directory');
1009                        $vars[files_in_this_dir]=$this->numoffiles;
1010
1011                        $vars[lang_used_space]=lang('Used space');
1012                        $vars[used_space]=$this->bo->borkb($usedspace, NULL, 1);
1013
1014                        if($this->path == $this->bo->homedir || $this->path == $this->bo->fakebase)
1015                        {
1016                                $vars[lang_unused_space]=lang('Unused space');
1017                                $vars[unused_space]=$this->bo->borkb($this->bo->userinfo['hdspace'] - $usedspace, NULL, 1);
1018
1019                                $tmp_arr=array(
1020                                        'string'        => $this->path,
1021                                        'relatives'     => array(RELATIVE_NONE)
1022                                );
1023
1024                                $ls_array = $this->bo->vfs->ls($tmp_arr);
1025
1026                                $vars[lang_total_files]=lang('Total Files');
1027                                $vars[total_files]=     count($ls_array);
1028                        }
1029
1030                        $this->t->set_var($vars);
1031                        $this->t->pparse('out','filemanager_footer');
1032
1033                        $GLOBALS['phpgw']->common->phpgw_footer();
1034                        $GLOBALS['phpgw']->common->phpgw_exit();
1035                }
1036
1037                function readFilesInfo()
1038                {
1039                        // start files info
1040
1041                        # Read in file info from database to use in the rest of the script
1042                        # $fakebase is a special directory.  In that directory, we list the user's
1043                        # home directory and the directories for the groups they're in
1044                        $this->numoffiles = 0;
1045                        if($this->path == $this->bo->fakebase)
1046                        {
1047                                // FIXME this test can be removed
1048                                if(!$this->bo->vfs->file_exists(array('string' => $this->bo->homedir, 'relatives' => array(RELATIVE_NONE))))
1049                                {
1050                                        $this->bo->vfs->mkdir(array('string' => $this->bo->homedir, 'relatives' => array(RELATIVE_NONE)));
1051                                }
1052
1053                                $ls_array = $this->bo->vfs->ls(array(
1054                                        'string' => $this->bo->homedir,
1055                                        'relatives' => array(RELATIVE_NONE),
1056                                        'checksubdirs' => False,
1057                                        'nofiles' => True
1058                                ));
1059
1060                                $this->files_array[] = $ls_array[0];
1061                                $this->numoffiles++;
1062
1063                                reset($this->readable_groups);
1064                                while(list($num, $group_array) = each($this->readable_groups))
1065                                {
1066                                        # If the group doesn't have access to this app, we don't show it
1067                                        /*if(!$this->groups_applications[$group_array['account_name']][$this->bo->appname]['enabled'])
1068                                        {
1069                                                continue;
1070                                        }
1071                                        */
1072
1073
1074                                        if(!$this->bo->vfs->file_exists(array('string' => $this->bo->fakebase.'/'.$group_array['account_name'],'relatives'      => array(RELATIVE_NONE))))
1075                                        {
1076                                                $this->bo->vfs->override_acl = 1;
1077                                                $this->bo->vfs->mkdir(array(
1078                                                        'string' => $this->bo->fakebase.'/'.$group_array['account_name'],
1079                                                        'relatives' => array(RELATIVE_NONE)
1080                                                ));
1081
1082                                                // FIXME we just created a fresh group dir so we know there nothing in it so we have to remove all existing content
1083                                               
1084                                               
1085                                                $this->bo->vfs->override_acl = 0;
1086
1087                                                $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'])));
1088                                        }
1089
1090                                        $ls_array = $this->bo->vfs->ls(array('string' => $this->bo->fakebase.'/'.$group_array['account_name'],'relatives'       => array(RELATIVE_NONE),'checksubdirs' => False,'nofiles' => True));
1091
1092                                        $this->files_array[] = $ls_array[0];
1093
1094                                        $this->numoffiles++;
1095                                }
1096                        }
1097                        else
1098                        {
1099                                $ls_array = $this->bo->vfs->ls(array(
1100                                        'string' => $this->path,
1101                                        'relatives'     => array(RELATIVE_NONE),
1102                                        'checksubdirs' => False,
1103                                        'nofiles'       => False,
1104                                        'orderby'       => $this->sortby
1105                                ));
1106
1107                                if($phpwh_debug)
1108                                {
1109                                        echo '# of files found in "'.$this->path.'" : '.count($ls_array).'<br>'."\n";
1110                                }
1111
1112                                while(list($num, $file_array) = each($ls_array))
1113                                {
1114                                        $this->numoffiles++;
1115                                        $this->files_array[] = $file_array;
1116                                        if($phpwh_debug)
1117                                        {
1118                                                echo 'Filename: '.$file_array['name'].'<br>'."\n";
1119                                        }
1120                                }
1121                        }
1122
1123                        if(!is_array($this->files_array))
1124                        {
1125                                $this->files_array = array();
1126                        }
1127                        // end file count
1128                }
1129
1130                function toolbar($type)
1131                {
1132                        switch($type)
1133                        {
1134                                case 'location':
1135                                        $toolbar='
1136                                        <div id="fmLocation">
1137                                        <table cellspacing="10" cellpadding="0" border="0">
1138                                        <tr>
1139                                        ';
1140//                                      $toolbar.='<td><img alt="spacer" src="'.$GLOBALS['phpgw']->common->image('phpgwapi','buttonseparator').'" height="27" width="8"></td>';
1141//                                      $toolbar.='<td><img alt="spacer" src="'.$GLOBALS['phpgw']->common->image('filemanager','spacer').'" height="27" width="1"></td>';
1142
1143                                        // go up icon when we're not at the top, dont allow to go outside /home = fakebase
1144                                        if($this->path != '/' && $this->path != $this->bo->fakebase)
1145                                        {
1146                                                $link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->lesspath);
1147                                                $toolbar.=$this->buttonImage($link,'up',lang('go up'));
1148                                        }
1149
1150                                        // go home icon when we're not home already
1151                                        if($this->path != $this->bo->homedir)
1152                                        {
1153                                                $link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->bo->homedir);
1154                                                $toolbar.=$this->buttonImage($link,'home',lang('go home'));
1155                                        }
1156
1157                                        // reload button with this url
1158                                        $link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->path);
1159                                        $toolbar.=$this->buttonImage($link,'reload',lang('reload'));
1160
1161                                        $toolbar.='<td>'.lang('Location').':&nbsp;';
1162                                        //$toolbar.='<input id="fmInputLocation" type="text" size="20" disabled="disabled" name="location" value="'.$this->disppath.'"/>&nbsp;';
1163                                        $current_option='<option>'.$this->disppath.'</option>';
1164                                        // selectbox for change/move/and copy to
1165                                        $dirs_options=$this->all_other_directories_options();
1166                                        $toolbar.='<select id="cdtodir" name="cdtodir" onChange="document.formfm.changedir.value=\'true\';document.formfm.submit()">'.$current_option.$dirs_options.'</select>
1167                                        <input type="hidden" name="changedir" value="false"></td>
1168                                        ';
1169                                        //$toolbar.=$this->inputImage('goto','goto',lang('Quick jump to'));
1170                                        // upload button
1171                                        /*if($this->path != '/' && $this->path != $this->bo->fakebase && $this->can_add)
1172                                        {
1173                                                // upload button
1174                                                $toolbar.=$this->inputImage('upload','upload',lang('Upload'));
1175                                               
1176
1177                                        }*/
1178                                        $toolbar.='</tr></table>';
1179                                        $toolbar.='</div><br><br>';
1180                                        break;
1181                                case 'list_nav':
1182                                        $toolbar='
1183                                        <table cellspacing="10" cellpadding="0" border="0">
1184                                        <tr>';
1185                                        // selectbox for change/move/and copy to
1186                                        // submit buttons for
1187                                        if($this->path != '/' && $this->path != $this->bo->fakebase)
1188                                        {
1189                                                //$toolbar.='<td><img alt="spacer" src="'.$GLOBALS['phpgw']->common->image('phpgwapi','buttonseparator').'" height="27" width="8"></td>';
1190                                                //$toolbar.='<td><img alt="spacer" src="'.$GLOBALS['phpgw']->common->image('filemanager','spacer').'" height="27" width="1"></td>';
1191                                                // create dir and file button
1192                                                if($this->can_add)
1193                                                {
1194                                                        //$toolbar3.='<td><img alt="spacer" src="'.$GLOBALS['phpgw']->common->image('phpgwapi','buttonseparator').'" height="27" width="8"></td>';
1195                                                        //$toolbar3.='<td><img alt="spacer" src="'.$GLOBALS['phpgw']->common->image('filemanager','spacer').'" height="27" width="1"></td>';
1196
1197                                                        $toolbar.='<td><input type="hidden" id="newfile_or_dir" name="newfile_or_dir" value="" /></td>';
1198                                                        $toolbar.='<div onclick="alert(\'asdf\')">';
1199                                                        //TODO : create folder with problems
1200                                                        //$toolbar3.=$this->inputImage('newdir','createdir',lang('Create Folder'));
1201                                                        $toolbar.=$this->inputImage('new','createfile',lang('New...'));
1202                                                        $toolbar.='</div>';
1203                                                }
1204
1205                                                if(!$this->rename_x && !$this->edit_comments_x && $this->can_edit)
1206                                                {
1207                                                        // edit text file button
1208                                                        $toolbar.=$this->inputImage('edit','edit',lang('edit'));
1209                                                }
1210
1211                                                if(!$this->edit_comments_x && $this->can_edit)
1212                                                {
1213                                                        $toolbar.=$this->inputImage('rename','rename',lang('Rename'));
1214                                                }
1215
1216                                                if(!$this->rename_x && !$this->edit_comments_x && $this->can_delete)
1217                                                {
1218                                                        $toolbar.=$this->inputImage('delete','delete',lang('Delete'));
1219                                                }
1220
1221                                                if(!$this->rename_x && $this->can_edit &&
1222                                                $_SESSION['phpgw_info']['user']['preferences']['filemanager']['comment'] == 1)
1223                                                {
1224                                                        $toolbar.=$this->inputImage('edit_comments','edit_comments',lang('Edit comments'));
1225                                                }
1226
1227                                        }
1228
1229                                        //      $toolbar.='</tr></table>';
1230                                        if(!$this->rename_x && !$this->edit_comments_x)
1231                                        {
1232                                                // copy and move buttons
1233                                                if($this->path != '/' && $this->path != $this->bo->fakebase)
1234                                                {
1235                                                        $dirs_options=$this->all_other_directories_options();
1236                                                        if (strlen($dirs_options) > 0){
1237                                                                $toolbar3.=$this->inputImage('copy_to','copy_to',lang('Copy to'));
1238                                                                if ($this->can_delete)
1239                                                                        $toolbar3.=$this->inputImage('move_to','move_to',lang('Move to'));
1240                                                        }
1241                                                        $toolbar3.='<td><select name="todir" style="visibility:hidden">'.$dirs_options.'</select></td>';
1242
1243                                                }
1244
1245                                                if($toolbar3)
1246                                                {
1247                                                        $toolbar.=$toolbar3;
1248                                                /*      $toolbar.='
1249                                                        <table cellspacing="1" cellpadding="0" border="0">
1250                                                        <tr>'.$toolbar3;*/
1251                                                }
1252                                        }
1253                                        $toolbar.='</tr></table>';
1254
1255                                        break;
1256                                default:$x='';
1257                        }
1258
1259                        if($toolbar)
1260                        {
1261                                return $toolbar;
1262                        }
1263                }
1264
1265
1266                // move to bo
1267                # Handle File Uploads
1268                function fileUpload()
1269                {
1270                        if($this->path != '/' && $this->path != $this->bo->fakebase)
1271                        {
1272                                for($i = 0; $i != $this->show_upload_boxes; $i++)
1273                                {
1274                                        if($badchar = $this->bo->bad_chars($_FILES['upload_file']['name'][$i], True, True))
1275                                        {
1276                                                $this->messages[]=lang('Error:').lang('File names cannot contain "%1"', $badchar);
1277
1278                                                continue;
1279                                        }
1280
1281                                        # Check to see if the file exists in the database, and get its info at the same time
1282                                        $ls_array = $this->bo->vfs->ls(array(
1283                                                'string'=> $this->path . '/' . $_FILES['upload_file']['name'][$i],
1284                                                'relatives'     => array(RELATIVE_NONE),
1285                                                'checksubdirs'  => False,
1286                                                'nofiles'       => True
1287                                        ));
1288
1289                                        $fileinfo = $ls_array[0];
1290
1291                                        if($fileinfo['name'])
1292                                        {
1293                                                if($fileinfo['mime_type'] == 'Directory')
1294                                                {
1295                                                        $this->messages[]= lang('Error:').lang('Cannot replace %1 because it is a directory', $fileinfo['name']);
1296                                                        continue;
1297                                                }
1298                                        }
1299                                         $max_size = $this->current_config['filemanager_Max_file_size'];
1300                                         if (! $max_size)
1301                                                 $max_size = ini_get('upload_max_filesize');
1302                                         else
1303                                                 $max_size .= "M";
1304
1305                                         $upload_max_filesize = str_replace("M","",$max_size) * 1024 * 1024;
1306
1307                                        if ($_FILES['upload_file']['size'][$i] > $upload_max_filesize)
1308                                        {
1309                                                $this->messages[]=lang('The size of %1 has exceded the limit: %2', $this->disppath.'/'.$_FILES['upload_file']['name'][$i], $max_size);
1310                                        }
1311                                        else
1312                                        if($_FILES['upload_file']['size'][$i] > 0)
1313                                        {
1314                                                if($fileinfo['name'] && $fileinfo['deleteable'] != 'N')
1315                                                {
1316                                                        $tmp_arr=array(
1317                                                                'string'=> $_FILES['upload_file']['name'][$i],
1318                                                                'relatives'     => array(RELATIVE_ALL),
1319                                                                'attributes'    => array(
1320                                                                        'owner_id' => $this->bo->userinfo['username'],
1321                                                                        'modifiedby_id' => $this->bo->userinfo['username'],
1322                                                                        'modified' => $this->now,
1323                                                                        'size' => $_FILES['upload_file']['size'][$i],
1324                                                                        'mime_type' => $_FILES['upload_file']['type'][$i],
1325                                                                        'deleteable' => 'Y',
1326                                                                        'comment' => stripslashes($_POST['upload_comment'][$i])
1327                                                                )
1328                                                        );
1329                                                        $this->bo->vfs->set_attributes($tmp_arr);
1330
1331                                                        $tmp_arr=array(
1332                                                                'from'  => $_FILES['upload_file']['tmp_name'][$i],
1333                                                                'to'    => lang('new')."_".$_FILES['upload_file']['name'][$i],
1334                                                                'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
1335                                                        );
1336                                                        $this->bo->vfs->cp($tmp_arr);
1337
1338                                                        $this->messages[]=lang('Created new %1', $this->disppath.'/'.$_FILES['upload_file']['name'][$i]);
1339                                                }
1340                                                else
1341                                                {
1342
1343                                                        $this->bo->vfs->cp(array(
1344                                                                'from'=> $_FILES['upload_file']['tmp_name'][$i],
1345                                                                'to'=> $_FILES['upload_file']['name'][$i],
1346                                                                'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
1347                                                        ));
1348
1349                                                        $this->bo->vfs->set_attributes(array(
1350                                                                'string'=> $_FILES['upload_file']['name'][$i],
1351                                                                'relatives'     => array(RELATIVE_ALL),
1352                                                                'attributes'=> array(
1353                                                                        'mime_type' => $_FILES['upload_file']['type'][$i],
1354                                                                        'comment' => stripslashes($_POST['upload_comment'][$i])
1355                                                                )
1356                                                        ));
1357
1358                                                        $this->messages[]=lang('Created %1,%2', $this->disppath.'/'.$_FILES['upload_file']['name'][$i], $_FILES['upload_file']['size'][$i]);
1359                                                }
1360                                        }
1361                                        elseif($_FILES['upload_file']['name'][$i])
1362                                        {
1363                                                $this->bo->vfs->touch(array(
1364                                                        'string'=> $_FILES['upload_file']['name'][$i],
1365                                                        'relatives'     => array(RELATIVE_ALL)
1366                                                ));
1367
1368                                                $this->bo->vfs->set_attributes(array(
1369                                                        'string'=> $_FILES['upload_file']['name'][$i],
1370                                                        'relatives'     => array(RELATIVE_ALL),
1371                                                        'attributes'=> array(
1372                                                                'mime_type' => $_FILES['upload_file']['type'][$i],
1373                                                                'comment' => stripslashes($_POST['upload_comment'][$i])
1374                                                        )
1375                                                ));
1376
1377                                                $this->messages[]=lang('Created %1,%2', $this->disppath.'/'.$_FILES['upload_file']['name'][$i], $file_size[$i]);
1378                                        }
1379                                }
1380
1381                                $this->readFilesInfo();
1382                                $this->filelisting();
1383                        }
1384                }
1385                # Handle Editing comments
1386                function editComment()
1387                {
1388                        while(list($file) = each($this->comment_files))
1389                        {
1390                                if($badchar = $this->bo->bad_chars($this->comment_files[$file], False, True))
1391                                {
1392                                        $this->messages[]=lang('Error:').$this->bo->html_encode(': ' . lang('Comments cannot contain "%1"', $badchar), 1);
1393                                        continue;
1394                                }
1395
1396                                $this->bo->vfs->set_attributes(array(
1397                                        'string'        => $file,
1398                                        'relatives'     => array(RELATIVE_ALL),
1399                                        'attributes'    => array(
1400                                                'comment' => stripslashes($this->comment_files[$file])
1401                                        )
1402                                ));
1403
1404                                $this->messages[]=lang('Updated comment for %1', $this->path.'/'.$file);
1405                        }
1406
1407                        $this->readFilesInfo();
1408                        $this->filelisting();
1409                }
1410
1411                # Handle Renaming Files and Directories
1412                function rename()
1413                {
1414                        while(list($from, $to) = each($this->renamefiles))
1415                        {
1416                                if($badchar = $this->bo->bad_chars($to, True, True))
1417                                {
1418                                        $this->messages[]=lang('Error:').$this->bo->html_encode(lang('File names cannot contain "%1"', $badchar), 1);
1419                                        continue;
1420                                }
1421
1422                                if(ereg("/", $to) || ereg("\\\\", $to))
1423                                {
1424                                        $this->messages[]=lang('Error:').lang("File names cannot contain \\ or /");
1425                                }
1426                                elseif($this->vfs_functions->verifyLock($from,RELATIVE_ALL) && $this->bo->vfs->mv(array(
1427                                        'from'  => $from,
1428                                        'to'    => $to
1429                                )))
1430                                {
1431                                        $this->messages[]=lang('Renamed %1 to %2', $this->disppath.'/'.$from, $this->disppath.'/'.$to);
1432                                }
1433                                else
1434                                {
1435                                        $this->messages[]= lang('Error:').lang('Could not rename %1 to %2', $this->disppath.'/'.$from, $this->disppath.'/'.$to);
1436                                }
1437                        }
1438                        $this->readFilesInfo();
1439                        $this->filelisting();
1440                }
1441
1442                # Handle Moving Files and Directories
1443                function moveTo()
1444                {
1445                        if(!$this->todir)
1446                        {
1447                                $this->messages[] = lang('Error:').lang('Could not move file because no destination directory is given ', $this->disppath.'/'.$file);
1448
1449                        }
1450                        else
1451                        {
1452
1453                                while(list($num, $file) = each($this->fileman))
1454                                {
1455                                        if($this->bo->vfs->mv(array(
1456                                                'from'  => $file,
1457                                                'to'    => $this->todir . '/' . $file,
1458                                                'relatives'     => array(RELATIVE_ALL, RELATIVE_NONE)
1459                                        )))
1460                                        {
1461                                                $moved++;
1462                                                $this->messages[]=lang('Moved %1 to %2', $this->disppath.'/'.$file, $this->todir.'/'.$file);
1463                                        }
1464                                        else
1465                                        {
1466                                                $this->messages[] = lang('Error:').lang('Could not move %1 to %2', $this->disppath.'/'.$file, $this->todir.'/'.$file);
1467                                        }
1468                                }
1469                        }
1470
1471                        if($moved)
1472                        {
1473                                $x=0;
1474                        }
1475
1476                        $this->readFilesInfo();
1477                        $this->filelisting();
1478                }
1479
1480                // Handle Copying of Files and Directories
1481                function copyTo()
1482                {
1483                        if(!$this->todir)
1484                        {
1485                                $this->messages[] = lang('Error:').lang('Could not copy file because no destination directory is given ', $this->disppath.'/'.$file);
1486
1487                        }
1488                        else
1489                        {
1490                                while(list($num, $file) = each($this->fileman))
1491                                {
1492                                        if($this->bo->vfs->cp(array(
1493                                                'from'  => $file,
1494                                                'to'    => $this->todir . '/' . $file,
1495                                                'relatives'     => array(RELATIVE_ALL, RELATIVE_NONE)
1496                                        )))
1497                                        {
1498                                                $copied++;
1499                                                $this->messages[] = lang('Copied %1 to %2', $this->disppath.'/'.$file, $this->todir.'/'.$file);
1500                                        }
1501                                        else
1502                                        {
1503                                                $this->messages[] = lang('Could not copy %1 to %2', $this->disppath.'/'.$file, $this->todir.'/'.$file);
1504                                        }
1505                                }
1506                        }
1507                        if($copied)
1508                        {
1509                                $x=0;
1510                        }
1511
1512                        $this->readFilesInfo();
1513                        $this->filelisting();
1514                }
1515
1516                function createdir()
1517                {
1518                        if($this->newdir_x && $this->newfile_or_dir)
1519                        {
1520                                if($this->bo->badchar = $this->bo->bad_chars($this->newfile_or_dir, True, True))
1521                                {
1522                                        $this->messages[]= lang('Error:').$this->bo->html_encode(lang('Directory names cannot contain "%1"', $badchar), 1);
1523                                }
1524
1525                                /* TODO is this right or should it be a single $ ? */
1526                                if($$this->newfile_or_dir[strlen($this->newfile_or_dir)-1] == ' ' || $this->newfile_or_dir[0] == ' ')
1527                                {
1528                                        $this->messages[]= lang('Error:').lang('Cannot create directory because it begins or ends in a space');
1529                                }
1530
1531                                $ls_array = $this->bo->vfs->ls(array(
1532                                        'string'        => $this->path . '/' . $this->newfile_or_dir,
1533                                        'relatives'     => array(RELATIVE_NONE),
1534                                        'checksubdirs'  => False,
1535                                        'nofiles'       => True
1536                                ));
1537
1538                                $fileinfo = $ls_array[0];
1539
1540                                if($fileinfo['name'])
1541                                {
1542                                        if($fileinfo['mime_type'] != 'Directory')
1543                                        {
1544                                                $this->messages[]= lang('Error:').lang('%1 already exists as a file',$fileinfo['name']);
1545                                        }
1546                                        else
1547                                        {
1548                                                $this->messages[]= lang('Error:').lang('Directory %1 already exists', $fileinfo['name']);
1549                                        }
1550                                }
1551                                else
1552                                {
1553                                        if($this->bo->vfs->mkdir(array('string' => $this->newfile_or_dir)))
1554                                        {
1555                                                $this->messages[]=lang('Created directory %1', $this->disppath.'/'.$this->newfile_or_dir);
1556                                        }
1557                                        else
1558                                        {
1559                                                $this->messages[]=lang('Error:').lang('Could not create %1', $this->disppath.'/'.$this->newfile_or_dir);
1560                                        }
1561                                }
1562
1563                                $this->readFilesInfo();
1564                                $this->filelisting();
1565                        }
1566                }
1567                function delete()
1568                {
1569                        if( is_array($this->fileman) && count($this->fileman) >= 1)
1570                        {
1571                                foreach($this->fileman as $filename)
1572                                {
1573                                        if($this->vfs_functions->verifyLock($filename,RELATIVE_ALL) && $this->bo->vfs->delete(array('string' => $filename)))
1574                                        {
1575                                                $this->messages[]= lang('Deleted %1', $this->disppath.'/'.$filename).'<br/>';
1576                                        }
1577                                        else
1578                                        {
1579                                                $this->messages[]=lang('Error:').lang('Could not delete %1', $this->disppath.'/'.$filename);
1580                                        }
1581                                }
1582                        }
1583                        else
1584                        {
1585                                // make this a javascript func for quicker respons
1586                                $this->messages[]=lang('Error:').lang('Please select a file to delete.');
1587                        }
1588                        $this->readFilesInfo();
1589                        $this->filelisting();
1590                }
1591
1592                function debug_filemanager()
1593                {
1594                        error_reporting(8);
1595
1596                        echo "<b>Filemanager debug:</b><br>
1597                        path: {$this->path}<br>
1598                        disppath: {$this->disppath}<br>
1599                        cwd: {$this->cwd}<br>
1600                        lesspath: {$this->lesspath}
1601                        <p>
1602                        <b>eGroupware debug:</b><br>
1603                        real getabsolutepath: " . $this->bo->vfs->getabsolutepath(array('target' => False, 'mask' => False, 'fake' => False)) . "<br>
1604                        fake getabsolutepath: " . $this->bo->vfs->getabsolutepath(array('target' => False)) . "<br>
1605                        appsession: " . $GLOBALS['phpgw']->session->appsession('vfs','') . "<br>
1606                        pwd: " . $this->bo->vfs->pwd() . "<br>";
1607
1608                        echo '<p></p>';
1609                        var_dump($this);
1610                }
1611
1612                function showUploadboxes()
1613                {
1614                        $this->t->set_file(array('upload' => 'upload.tpl'));
1615                        $this->t->set_block('upload','upload_header','upload_header');
1616                        $this->t->set_block('upload','row','row');
1617                        $this->t->set_block('upload','upload_footer','upload_footer');
1618
1619                        if($this->path != '/' && $this->path != $this->bo->fakebase && $this->can_add)
1620                        {
1621                                $vars[form_action]=$GLOBALS[phpgw]->link('/index.php','menuaction=filemanager.uifilemanager.index');
1622                                $vars[path]=$this->path;
1623                                $vars[lang_file]=lang('File');
1624                                $vars[lang_comment]=lang('Comment');
1625                                $vars[num_upload_boxes]=1;
1626                                $this->t->set_var($vars);
1627                                $this->t->pparse('out','upload_header');
1628
1629                                $this->t->set_var('row_tr_color',$tr_color);
1630                                $this->t->parse('rows','row');
1631                                $this->t->pparse('out','row');
1632
1633                                $vars[lang_upload]=lang('Upload files');
1634                                $vars[change_upload_boxes].=lang('Show') . '&nbsp;';
1635                                $this->t->set_var($vars);
1636                                $this->t->pparse('out','upload_footer');
1637                        }
1638                }
1639
1640                /* create textfile */
1641                function createfile()
1642                {
1643                        $this->createfile_var=$this->newfile_or_dir;
1644                        if($this->createfile_var)
1645                        {
1646                                if($badchar = $this->bo->bad_chars($this->createfile_var, True, True))
1647                                {
1648                                        $this->messages[] = lang('Error:').lang('File names cannot contain "%1"',$badchar);
1649
1650                                        $this->fileListing();
1651                                }
1652
1653                                if($this->bo->vfs->file_exists(array(
1654                                        'string'=> $this->createfile_var,
1655                                        'relatives'     => array(RELATIVE_ALL)
1656                                )))
1657                                {
1658                                        $this->messages[]= lang('Error:').lang('File %1 already exists. Please edit it or delete it first.', $this->createfile_var);
1659                                        $this->fileListing();
1660                                }
1661
1662                                if($this->bo->vfs->touch(array(
1663                                        'string'        => $this->createfile_var,
1664                                        'relatives'     => array(RELATIVE_ALL)
1665                                )))
1666                                {
1667                                        $this->fileman = array();
1668                                        $this->fileman[0] = $this->createfile_var;
1669                                        $this->edit = 1;
1670                                        $this->numoffiles++;
1671                                        $this->edit();
1672                                }
1673                                else
1674                                {
1675                                        $this->messages[]= lang('Error:').lang('File %1 could not be created.', $this->createfile_var);
1676                                        $this->fileListing();
1677                                }
1678                        }
1679                }
1680
1681                # Handle Editing files
1682                function edit()
1683                {
1684                        $files = array_keys($this->fileman);
1685                        $this->file = $this->fileman[$files[0]];
1686                        if($this->file)
1687                        {
1688                                if (! $this->vfs_functions->verifyLock($this->path.'/'.$this->file,RELATIVE_NONE)){
1689                                        echo $this->messages['0'];
1690                                        $GLOBALS['phpgw']->redirect('/index.php');
1691
1692                                        //$GLOBALS['phpgw']->common->phpgw_exit();
1693                                }
1694                                $ls_array = $this->bo->vfs->ls(array(
1695                                        'string'        => $this->path.'/'.$this->file,
1696                                        'relatives'     => array(RELATIVE_NONE),
1697                                        'checksubdirs'  => False,
1698                                        'nofiles'       => True
1699                                ));
1700                                $this->bo->vfs->touch(array(
1701                                        'string'=> $this->path.'/'.$this->file,
1702                                        'relatives'     => array(RELATIVE_NONE)
1703                                ));
1704
1705
1706                                if($ls_array[0]['mime_type'])
1707                                {
1708                                        $mime_type = $ls_array[0]['mime_type'];
1709                                }
1710                                elseif($this->prefs['viewtextplain'])
1711                                {
1712                                        $mime_type = 'text/plain';
1713                                }
1714                                $editable = array('','text/plain','text/csv','text/html','text/text','message/rfc822');
1715
1716                                if(!in_array($mime_type,$editable)){
1717                                        echo lang('Impossbile to edit this file');
1718                                        return False;
1719                                }
1720                        }
1721
1722                        $this->readFilesInfo();
1723
1724                        if ($mime_type == 'text/html')
1725                                $this->t->set_file(array('filemanager_edit' => 'edit_html.tpl'));
1726                        else
1727                                $this->t->set_file(array('filemanager_edit' => 'edit_file.tpl'));
1728
1729                        $this->t->set_block('filemanager_edit','row','row');
1730
1731
1732                        $vars[refresh_script] = "<script src='filemanager/js/refresh.js'></script>";
1733
1734                        $vars[preview_content]='';
1735                        if($this->edit_file)
1736                        {
1737                                $this->edit_file_content = stripslashes($this->edit_file_content);
1738                        }
1739
1740                        if($this->edit_preview_x)
1741                        {
1742                                $content = $this->edit_file_content;
1743
1744                                $vars[lang_preview_of]=lang('Preview of %1', $this->path.'/'.$edit_file);
1745
1746                                $vars[preview_content]=nl2br($content);
1747                        }
1748                        elseif($this->edit_save_x || $this->edit_save_done_x)
1749                        {
1750                                $content = $this->edit_file_content;
1751                                //die( $content);
1752                                if($this->bo->vfs->write(array(
1753                                        'string'        => $this->path.'/'.$this->edit_file,
1754                                        'relatives'     => array(RELATIVE_NONE),
1755                                        'content'       => $content
1756                                )))
1757                                {
1758                                        $this->messages[]=lang('Saved %1', $this->path.'/'.$this->edit_file);
1759
1760                                        if($this->edit_save_done_x)
1761                                        {
1762                                                $this->readFilesInfo();
1763                                                $this->fileListing();
1764                                                exit;
1765                                        }
1766                                }
1767                                else
1768                                {
1769                                        echo lang('Could not save %1', $this->path.'/'.$this->edit_file);
1770                                        $this->messages[]=lang('Could not save %1', $this->path.'/'.$this->edit_file);
1771                                }
1772                        }
1773
1774                        # Now we display the edit boxes and forms
1775                        for($j = 0; $j != $this->numoffiles; $j++)
1776                        {
1777                                # If we're in preview or save mode, we only show the file
1778                                # being previewed or saved
1779                                if($this->edit_file &&($this->fileman[$j] != $this->edit_file))
1780                                {
1781                                        continue;
1782                                }
1783
1784                                if($this->fileman[$j] && $this->bo->vfs->file_exists(array(
1785                                        'string'        => $this->fileman[$j],
1786                                        'relatives'     => array(RELATIVE_ALL)
1787                                )))
1788                                {
1789                                        if($this->edit_file)
1790                                        {
1791                                                $content = stripslashes($this->edit_file_content);
1792                                        }
1793                                        else
1794                                        {
1795                                                $content = $this->bo->vfs->read(array('string' => $this->fileman[$j]));
1796                                        }
1797
1798                                        $vars[form_action]= $GLOBALS['phpgw']->link('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->path);
1799                                        $vars[edit_file]=$this->fileman[$j];
1800
1801                                        # We need to include all of the fileman entries for each file's form,
1802                                        # so we loop through again
1803                                        for($i = 0; $i != $this->numoffiles; $i++)
1804                                        {
1805                                                if($this->fileman[$i]) $value='value="'.$this->fileman[$i].'"';
1806                                                $vars[filemans_hidden]='<input type="hidden" name="fileman['.$i.']" '.$value.' />';
1807                                        }
1808
1809                                        $vars[file_content]=$content;
1810
1811                                        $vars[buttonPreview]=$this->inputImage('edit_preview','edit_preview',lang('Preview %1', $this->bo->html_encode($this->fileman[$j], 1)));
1812                                        $vars[buttonSave]=$this->inputImage('edit_save','save',lang('Save %1', $this->bo->html_encode($this->fileman[$j], 1)));
1813                                        $vars[buttonDone]=$this->inputImage('edit_save_done','ok',lang('Save %1, and go back to file listing ', $this->bo->html_encode($this->fileman[$j], 1)));
1814                                        $vars[buttonCancel]=$this->inputImage('edit_cancel','cancel',lang('Cancel editing %1 without saving', $this->bo->html_encode($this->fileman[$j], 1)));
1815
1816                                         if ($mime_type == 'text/html'){
1817                                                 $vars[fck_edit] = '<script type="text/javascript" src="filemanager/tp/ckeditor/ckeditor.js"></script>
1818                                                         <textarea cols="80" id="edit_file_content" name="edit_file_content" rows="10">'.$content.'</textarea>
1819                                                         <script type="text/javascript"> CKEDITOR.replace( \'edit_file_content\',{
1820                                        removePlugins : \'elementspath\',
1821                                        skin : \'office2003\',
1822                                        toolbar : [["Source","Preview","-","Cut","Copy","Paste","-","Print",
1823                                        "Undo","Redo","-","Find","Replace","-","SelectAll" ],
1824                                        ["Table","HorizontalRule","Smiley","SpecialChar","PageBreak","-","Bold",
1825                                        "Italic","Underline","Strike","-","Subscript","Superscript",
1826                                        "NumberedList","BulletedList","-","Outdent","Indent","Blockquote",
1827                                        "JustifyLeft","JustifyCenter","JustifyRight","JustifyBlock",
1828                                        "Link", "TextColor","BGColor","Maximize"],
1829                                        ["Styles","Format","Font","FontSize"]]
1830                                         });</script>';
1831
1832                                        }
1833
1834
1835                                        $this->t->set_var($vars);
1836                                        $this->t->parse('rows','row');
1837                                        $this->t->pparse('out','row');
1838
1839                                }
1840                        }
1841                }
1842
1843                function history()
1844                {
1845                        if($this->file) // FIXME this-file is never defined
1846                        {
1847                                $journal_array = $this->bo->vfs->get_journal(array(
1848                                        'string'        => $this->file,//FIXME
1849                                        'relatives'     => array(RELATIVE_ALL)
1850                                ));
1851
1852                                if(is_array($journal_array))
1853                                {
1854                                        $this->html_table_begin();
1855                                        $this->html_table_row_begin();
1856                                        $this->html_table_col_begin();
1857                                        echo lang('Date');
1858                                        $this->html_table_col_end();
1859                                        $this->html_table_col_begin();
1860                                        echo lang('Version');
1861                                        $this->html_table_col_end();
1862                                        $this->html_table_col_begin();
1863                                        echo lang('Who');
1864                                        $this->html_table_col_end();
1865                                        $this->html_table_col_begin();
1866                                        echo lang('Operation');
1867                                        $this->html_table_col_end();
1868                                        $this->html_table_row_end();
1869
1870                                        while(list($num, $journal_entry) = each($journal_array))
1871                                        {
1872                                                $this->html_table_row_begin();
1873                                                $this->html_table_col_begin();
1874                                                $this->bo->html_text($journal_entry['created'] . '&nbsp;&nbsp;&nbsp;');
1875                                                $this->html_table_col_end();
1876                                                $this->html_table_col_begin();
1877                                                $this->bo->html_text($journal_entry['version'] . '&nbsp;&nbsp;&nbsp;' );
1878                                                $this->html_table_col_end();
1879                                                $this->html_table_col_begin();
1880                                                $this->bo->html_text($GLOBALS['phpgw']->accounts->id2name($journal_entry['owner_id']) . '&nbsp;&nbsp;&nbsp;');
1881                                                $this->html_table_col_end();
1882                                                $this->html_table_col_begin();
1883                                                $this->bo->html_text($journal_entry['comment']);
1884                                                $this->html_table_col_end();
1885                                        }
1886
1887                                        $this->html_table_end();
1888                                        $GLOBALS['phpgw']->common->phpgw_footer();
1889                                        $GLOBALS['phpgw']->common->phpgw_exit();
1890                                }
1891                                else
1892                                {
1893                                        echo lang('No version history for this file/directory');
1894                                }
1895                        }
1896                }
1897                function view()
1898                {
1899                        if (!$this->bo->vfs->acl_check(array(
1900                                'string'        => $this->path,
1901                                'relatives'     => array(RELATIVE_NONE),
1902                                'operation'     => PHPGW_ACL_READ
1903                        )))
1904                        {
1905                                echo lang("You have no permission to access this file");
1906                                return false;
1907                        }
1908                        if($this->file) //FIXME
1909                        {
1910                                $ls_array = $this->bo->vfs->ls(array(
1911                                        'string'        => $this->path.'/'.$this->file,//FIXME
1912                                        'relatives'     => array(RELATIVE_NONE),
1913                                        'checksubdirs'  => False,
1914                                        'nofiles'       => True
1915                                ));
1916
1917                                if($ls_array[0]['mime_type'])
1918                                {
1919                                        $mime_type = $ls_array[0]['mime_type'];
1920                                }
1921                                elseif($this->prefs['viewtextplain'])
1922                                {
1923                                        $mime_type = 'text/plain';
1924                                }
1925                                $viewable = array('','text/plain','text/csv','text/html','text/text');
1926
1927                                if(in_array($mime_type,$viewable))
1928                                {
1929                                       
1930                                        header('Content-type: ' . $mime_type);
1931                                        header('Content-disposition: filename="' . $this->file . '"');//FIXME
1932                                        Header("Pragma: public");
1933                                }
1934                                else
1935                                {
1936                                        $GLOBALS['phpgw']->browser->content_header($this->file,$mime_type);//FIXME
1937                                }
1938                                echo $this->bo->vfs->read(array(
1939                                        'string'        => $this->path.'/'.$this->file,//FIXME
1940                                        'relatives'     => array(RELATIVE_NONE)
1941                                ));
1942                                $GLOBALS['phpgw']->common->phpgw_exit();
1943                        }
1944                }
1945
1946                function export(){
1947                        if($this->file)
1948                        {
1949                                $ls_array = $this->bo->vfs->ls(array(
1950                                        'string'        => $this->path.'/'.$this->file,
1951                                        'relatives'     => array(RELATIVE_NONE),
1952                                        'checksubdirs'  => False,
1953                                        'nofiles'       => True
1954                                ));
1955                                /*$timestamp = $this->vfs_functions->dateString2timeStamp($ls_array[0]['modified']);
1956                                if (time() - $timestamp < 60 && $ls_array[0]['modifiedby_id'] != $GLOBALS['phpgw_info']['user']['account_id']);
1957                                {
1958                                        // recently than last minute: someone is editing
1959                                }*/
1960                                $mime_type = $ls_array[0]['mime_type'];
1961                                $formats = array('text/html');
1962                                if(!in_array($mime_type,$formats)){
1963                                        echo lang('Impossbile to export this file');
1964                                        return False;
1965                                }
1966                                $content = $this->bo->vfs->read(array('string' => $this->path.'/'.$this->file,
1967                                               'relatives'     => array(RELATIVE_NONE)
1968                                       ));
1969
1970                                include_once('filemanager/tp/dompdf/dompdf_config.inc.php');
1971                                $dompdf = new DOMPDF();
1972                                $dompdf->load_html($content);
1973                                $dompdf->set_paper($this->prefs['pdf_paper_type'], $this->prefs['pdf_type']);
1974                                /* Would be nice to implement 'Title','Subject','Author','Creator','CreationDate'*/
1975                                $dompdf->render();
1976                                $dompdf->stream(strtok($this->file,'.').".pdf");
1977                                $GLOBALS['phpgw']->common->phpgw_exit();
1978                        }
1979                }
1980
1981                //give back an array with all directories except current and dirs that are not accessable
1982                function all_other_directories_options()
1983                {
1984                        # First we get the directories in their home directory
1985                        $dirs = array();
1986                        $dirs[] = array('directory' => $this->bo->fakebase, 'name' => $this->bo->userinfo['account_lid']);
1987
1988                        $tmp_arr=array(
1989                                'string'        => $this->bo->homedir,
1990                                'relatives'     => array(RELATIVE_NONE),
1991                                'checksubdirs'  => True,
1992                                'mime_type'     => 'Directory'
1993                        );
1994
1995                        $ls_array = $this->bo->vfs->ls($tmp_arr);
1996
1997                        while(list($num, $dir) = each($ls_array))
1998                        {
1999                                $dirs[] = $dir;
2000                        }
2001
2002
2003                        # Then we get the directories in their readable groups' home directories
2004                        reset($this->readable_groups);
2005                        while(list($num, $group_array) = each($this->readable_groups))
2006                        {
2007                                /* Don't list directories for groups that don't have access
2008                                if(!$this->groups_applications[$group_array['account_name']][$this->bo->appname]['enabled'])
2009                                {
2010]                                       continue;
2011                                }*/
2012
2013                                $dirs[] = array('directory' => $this->bo->fakebase, 'name' => $group_array['account_name']);
2014
2015                                $tmp_arr=array(
2016                                        'string'        => $this->bo->fakebase.'/'.$group_array['account_name'],
2017                                        'relatives'     => array(RELATIVE_NONE),
2018                                        'checksubdirs'  => True,
2019                                        'mime_type'     => 'Directory'
2020                                );
2021
2022                                $ls_array = $this->bo->vfs->ls($tmp_arr);
2023                                while(list($num, $dir) = each($ls_array))
2024                                {
2025                                        $dirs[] = $dir;
2026                                }
2027                        }
2028
2029                        reset($dirs);
2030                        while(list($num, $dir) = each($dirs))
2031                        {
2032                                if(!$dir['directory'])
2033                                {
2034                                        continue;
2035                                }
2036
2037                                # So we don't display //
2038                                if($dir['directory'] != '/')
2039                                {
2040                                        $dir['directory'] .= '/';
2041                                }
2042
2043                                # No point in displaying the current directory, or a directory that doesn't exist
2044                                if((($dir['directory'] . $dir['name']) != $this->path) && $this->bo->vfs->file_exists(array('string' => $dir['directory'] . $dir['name'],'relatives' => array(RELATIVE_NONE))))
2045                                {
2046                                        //FIXME replace the html_form_option function
2047                                        $options .= $this->html_form_option($dir['directory'] . $dir['name'], $dir['directory'] . $dir['name']);
2048                                }
2049                        }
2050
2051                        return $options;
2052                }
2053
2054                /* seek icon for mimetype else return an unknown icon */
2055                function mime_icon($mime_type, $size=16)
2056                {
2057                        if(!$mime_type) $mime_type='unknown';
2058
2059                        $mime_type=str_replace  ('/','_',$mime_type);
2060
2061                        $img=$GLOBALS['phpgw']->common->image('filemanager','mime'.$size.'_'.strtolower($mime_type));
2062                        if(!$img) $img=$GLOBALS['phpgw']->common->image('filemanager','mime'.$size.'_unknown');
2063
2064                        $icon='<img src="'.$img.' "alt="'.lang($mime_type).'" />';
2065                        return $icon;
2066                }
2067
2068                function buttonImage($link,$img='',$description='')
2069                {
2070                        $image=$GLOBALS['phpgw']->common->image('filemanager','button_'.strtolower($img));
2071
2072                        if($img)
2073                        {
2074                                return '<td class="" align="center" valign="middle" height="28" width="70">
2075                                <a href="'.$link.'" title="'.$description.'"><img src="'.$image.'" alt="'.$description.'"/></a><br><small>'.$description.'</small>
2076                                </td>';
2077                        }
2078                }
2079
2080                function inputImage($name,$img='',$description='')
2081                {
2082                        $image=$GLOBALS['phpgw']->common->image('filemanager','button_'.strtolower($img));
2083
2084                        if($img)
2085                        {
2086                                return '<td class="" align="center" valign="middle" height="28" width="70">
2087                                <input onclick="return formfmValidate(this.name)" title="'.$description.'" name="'.$name.'" type="image" alt="'.$name.'" src="'.$image.'" value="clicked" /><br><small>'.$description.'</small>
2088                                </td>';
2089                        }
2090                }
2091
2092                function html_form_input($type = NULL, $name = NULL, $value = NULL, $maxlength = NULL, $size = NULL, $checked = NULL, $string = '', $return = 1)
2093                {
2094                        $text = ' ';
2095                        if($type != NULL && $type)
2096                        {
2097                                if($type == 'checkbox')
2098                                {
2099                                        $value = $this->bo->string_encode($value, 1);
2100                                }
2101                                $text .= 'type="'.$type.'" ';
2102                        }
2103                        if($name != NULL && $name)
2104                        {
2105                                $text .= 'name="'.$name.'" ';
2106                        }
2107                        if($value != NULL && $value)
2108                        {
2109                                $text .= 'value="'.$value.'" ';
2110                        }
2111                        if(is_int($maxlength) && $maxlength >= 0)
2112                        {
2113                                $text .= 'maxlength="'.$maxlength.'" ';
2114                        }
2115                        if(is_int($size) && $size >= 0)
2116                        {
2117                                $text .= 'size="'.$size.'" ';
2118                        }
2119                        if($checked != NULL && $checked)
2120                        {
2121                                $text .= 'checked ';
2122                        }
2123
2124                        return '<input'.$text.$string.'>';
2125                }
2126
2127                function html_form_option($value = NULL, $displayed = NULL, $selected = NULL, $return = 0)
2128                {
2129                        $text = ' ';
2130                        if($value != NULL && $value)
2131                        {
2132                                $text .= ' value="'.$value.'" ';
2133                        }
2134                        if($selected != NULL && $selected)
2135                        {
2136                                $text .= ' selected';
2137                        }
2138                        return  '<option'.$text.'>'.$displayed.'</option>';
2139                }
2140
2141                function encode_href($href = NULL, $args = NULL , $extra_args)
2142                {
2143                        $href = $this->bo->string_encode($href, 1);
2144                        $all_args = $args.'&'.$this->bo->string_encode($extra_args, 1);
2145
2146                        $address = $GLOBALS['phpgw']->link($href, $all_args);
2147
2148                        return $address;
2149                }
2150
2151                function html_link($href = NULL, $args = NULL , $extra_args, $text = NULL, $return = 1, $encode = 1, $linkonly = 0, $target = NULL)
2152                {
2153                        //      unset($encode);
2154                        if($encode)
2155                        {
2156                                $href = $this->bo->string_encode($href, 1);
2157                                $all_args = $args.'&'.$this->bo->string_encode($extra_args, 1);
2158                        }
2159                        else
2160                        {
2161                                //                              $href = $this->bo->string_encode($href, 1);
2162                                $all_args = $args.'&'.$extra_args;
2163                        }
2164                        ###
2165                        # This decodes / back to normal
2166                        ###
2167                        //                      $all_args = preg_replace("/%2F/", "/", $all_args);
2168                        //                      $href = preg_replace("/%2F/", "/", $href);
2169
2170                        /* Auto-detect and don't disturb absolute links */
2171                        if(!preg_match("|^http(.{0,1})://|", $href))
2172                        {
2173                                //Only add an extra / if there isn't already one there
2174
2175                                // die(SEP);
2176                                if(!($href[0] == SEP))
2177                                {
2178                                        $href = SEP . $href;
2179                                }
2180
2181                                /* $phpgw->link requires that the extra vars be passed separately */
2182                                //                              $link_parts = explode("?", $href);
2183                                $address = $GLOBALS['phpgw']->link($href, $all_args);
2184                                //                              $address = $GLOBALS['phpgw']->link($href);
2185                        }
2186                        else
2187                        {
2188                                $address = $href;
2189                        }
2190
2191                        /* If $linkonly is set, don't add any HTML */
2192                        if($linkonly)
2193                        {
2194                                $rstring = $address;
2195                        }
2196                        else
2197                        {
2198                                if($target)
2199                                {
2200                                        $target = 'target='.$target;
2201                                }
2202
2203                                $text = trim($text);
2204                                $rstring = '<a href="'.$address.'" '.$target.'>'.$text.'</a>';
2205                        }
2206
2207                        return($this->bo->eor($rstring, $return));
2208                }
2209
2210                function html_table_begin($width = NULL, $border = NULL, $cellspacing = NULL, $cellpadding = NULL, $rules = NULL, $string = '', $return = 0)
2211                {
2212                        if($width != NULL && $width)
2213                        {
2214                                $width = "width=$width";
2215                        }
2216                        if(is_int($border) && $border >= 0)
2217                        {
2218                                $border = "border=$border";
2219                        }
2220                        if(is_int($cellspacing) && $cellspacing >= 0)
2221                        {
2222                                $cellspacing = "cellspacing=$cellspacing";
2223                        }
2224                        if(is_int($cellpadding) && $cellpadding >= 0)
2225                        {
2226                                $cellpadding = "cellpadding=$cellpadding";
2227                        }
2228                        if($rules != NULL && $rules)
2229                        {
2230                                $rules = "rules=$rules";
2231                        }
2232
2233                        $rstring = "<table $width $border $cellspacing $cellpadding $rules $string>";
2234                        return($this->bo->eor($rstring, $return));
2235                }
2236
2237                function html_table_end($return = 0)
2238                {
2239                        $rstring = "</table>";
2240                        return($this->bo->eor($rstring, $return));
2241                }
2242
2243                function html_table_row_begin($align = NULL, $halign = NULL, $valign = NULL, $bgcolor = NULL, $string = '', $return = 0)
2244                {
2245                        if($align != NULL && $align)
2246                        {
2247                                $align = "align=$align";
2248                        }
2249                        if($halign != NULL && $halign)
2250                        {
2251                                $halign = "halign=$halign";
2252                        }
2253                        if($valign != NULL && $valign)
2254                        {
2255                                $valign = "valign=$valign";
2256                        }
2257                        if($bgcolor != NULL && $bgcolor)
2258                        {
2259                                $bgcolor = "bgcolor=$bgcolor";
2260                        }
2261                        $rstring = "<tr $align $halign $valign $bgcolor $string>";
2262                        return($this->bo->eor($rstring, $return));
2263                }
2264
2265                function html_table_row_end($return = 0)
2266                {
2267                        $rstring = "</tr>";
2268                        return($this->bo->eor($rstring, $return));
2269                }
2270
2271                function html_table_col_begin($align = NULL, $halign = NULL, $valign = NULL, $rowspan = NULL, $colspan = NULL, $string = '', $return = 0)
2272                {
2273                        if($align != NULL && $align)
2274                        {
2275                                $align = "align=$align";
2276                        }
2277                        if($halign != NULL && $halign)
2278                        {
2279                                $halign = "halign=$halign";
2280                        }
2281                        if($valign != NULL && $valign)
2282                        {
2283                                $valign = "valign=$valign";
2284                        }
2285                        if(is_int($rowspan) && $rowspan >= 0)
2286                        {
2287                                $rowspan = "rowspan=$rowspan";
2288                        }
2289                        if(is_int($colspan) && $colspan >= 0)
2290                        {
2291                                $colspan = "colspan=$colspan";
2292                        }
2293
2294                        $rstring = "<td $align $halign $valign $rowspan $colspan $string>";
2295                        return($this->bo->eor($rstring, $return));
2296                }
2297
2298                function html_table_col_end($return = 0)
2299                {
2300                        $rstring = "</td>";
2301                        return($this->bo->eor($rstring, $return));
2302                }
2303        }
Note: See TracBrowser for help on using the repository browser.