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

Revision 1535, 63.4 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Melhorias no filemanager com correção de bugs

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