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

Revision 1556, 63.6 KB checked in by amuller, 15 years ago (diff)

Ticket #597 - Melhorias no módulo filemanager, implementação de quota!

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