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

Revision 1557, 63.6 KB checked in by amuller, 14 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                                                $total = ($this->current_config['filemanager_quota_size'])*1024*1024;
1059                                                $usedSpace = $this->usedSpace();
1060                                                if ($usedSpace < $total)
1061                                                        $toolbar.=$this->inputImage('upload','upload',lang('Upload'));
1062                                        }
1063                                        $toolbar.='</tr></table>';
1064                                        $toolbar.='</div><br><br>';
1065                                        break;
1066                                case 'list_nav':
1067                                        $toolbar='
1068                                        <table cellspacing="10" cellpadding="0" border="0">
1069                                        <tr>';
1070                                        // selectbox for change/move/and copy to
1071                                        // submit buttons for
1072                                        if($this->path != '/' && $this->path != $this->bo->fakebase)
1073                                        {
1074                                                //$toolbar.='<td><img alt="spacer" src="'.$GLOBALS['phpgw']->common->image('phpgwapi','buttonseparator').'" height="27" width="8"></td>';
1075                                                //$toolbar.='<td><img alt="spacer" src="'.$GLOBALS['phpgw']->common->image('filemanager','spacer').'" height="27" width="1"></td>';
1076
1077                                                if(!$this->rename_x && !$this->edit_comments_x && $this->can_edit)
1078                                                {
1079                                                        // edit text file button
1080                                                        // $toolbar.=$this->inputImage('edit','edit',lang('edit'));
1081                                                }
1082
1083                                                if(!$this->edit_comments_x && $this->can_edit)
1084                                                {
1085                                                        $toolbar.=$this->inputImage('rename','rename',lang('Rename'));
1086                                                }
1087
1088                                                if(!$this->rename_x && !$this->edit_comments_x && $this->can_delete)
1089                                                {
1090                                                        $toolbar.=$this->inputImage('delete','delete',lang('Delete'));
1091                                                }
1092
1093                                                if(!$this->rename_x && $this->can_edit &&
1094                                                $_SESSION['phpgw_info']['user']['preferences']['filemanager']['comment'] == 1)
1095                                                {
1096                                                        $toolbar.=$this->inputImage('edit_comments','edit_comments',lang('Edit comments'));
1097                                                }
1098                                                $toolbar.='<td><img alt="spacer" src="'.$GLOBALS['phpgw']->common->image('filemanager','spacer').'" height="27" width="1"></td>';
1099                                        }
1100
1101                                        //      $toolbar.='</tr></table>';
1102                                        if(!$this->rename_x && !$this->edit_comments_x)
1103                                        {
1104                                                // copy and move buttons
1105                                                if($this->path != '/' && $this->path != $this->bo->fakebase)
1106                                                {
1107                                                        //$toolbar3.='<td><img alt="spacer" src="'.$GLOBALS['phpgw']->common->image('phpgwapi','buttonseparator').'" height="27" width="8"></td>';
1108                                                        //$toolbar3.='<td><img alt="spacer" src="'.$GLOBALS['phpgw']->common->image('filemanager','spacer').'" height="27" width="1"></td>';
1109
1110                                                        $dirs_options=$this->all_other_directories_options();
1111
1112                                                        $toolbar3.=$this->inputImage('copy_to','copy_to',lang('Copy to'));
1113                                                        if ($this->can_delete)
1114                                                                $toolbar3.=$this->inputImage('move_to','move_to',lang('Move to'));
1115                                                        $toolbar3.='<td><select name="todir"><option value="">'.lang('select a folder').'</option>'.$dirs_options.'</select></td>';
1116
1117                                                        $toolbar3.='<td><img alt="spacer" src="'.$GLOBALS['phpgw']->common->image('filemanager','spacer').'" height="27" width="1"></td>';
1118
1119                                                }
1120
1121                                                // create dir and file button
1122                                                if($this->path != '/' && $this->path != $this->bo->fakebase && $this->can_add)
1123                                                {
1124                                                        //$toolbar3.='<td><img alt="spacer" src="'.$GLOBALS['phpgw']->common->image('phpgwapi','buttonseparator').'" height="27" width="8"></td>';
1125                                                        //$toolbar3.='<td><img alt="spacer" src="'.$GLOBALS['phpgw']->common->image('filemanager','spacer').'" height="27" width="1"></td>';
1126
1127                                                        $toolbar3.='<td><input type="hidden" id="newfile_or_dir" name="newfile_or_dir" value="" /></td>';
1128                                                        $toolbar3.='<div onclick="alert(\'asdf\')">';
1129                                                        //TODO : create folder with problems
1130                                                        //$toolbar3.=$this->inputImage('newdir','createdir',lang('Create Folder'));
1131                                                        $toolbar3.=$this->inputImage('newfile','createfile',lang('Create File'));
1132                                                        $toolbar3.='</div>';
1133                                                }
1134
1135                                                if($toolbar3)
1136                                                {
1137                                                        $toolbar.=$toolbar3;
1138                                                /*      $toolbar.='
1139                                                        <table cellspacing="1" cellpadding="0" border="0">
1140                                                        <tr>'.$toolbar3;*/
1141                                                }
1142                                        }
1143                                        $toolbar.='</tr></table>';
1144
1145                                        break;
1146                                default:$x='';
1147                        }
1148
1149                        if($toolbar)
1150                        {
1151                                return $toolbar;
1152                        }
1153                }
1154
1155
1156                function usedSpace(){
1157                           for($i = 0; $i != $this->numoffiles; $i++)
1158                                $usedspace += $this->files_array[$i]['size'];
1159                           return $usedspace;
1160                }
1161
1162                // move to bo
1163                # Handle File Uploads
1164                function fileUpload()
1165                {
1166                        if ($this->usedSpace() > ($this->current_config['filemanager_quota_size'])*1024*1024)
1167                                echo lang('You exceded the quota');
1168                        else
1169                        if($this->path != '/' && $this->path != $this->bo->fakebase)
1170                        {
1171                                for($i = 0; $i != $this->show_upload_boxes; $i++)
1172                                {
1173                                        if($badchar = $this->bo->bad_chars($_FILES['upload_file']['name'][$i], True, True))
1174                                        {
1175                                                $this->messages[]= $GLOBALS['phpgw']->common->error_list(array($this->bo->html_encode(lang('File names cannot contain "%1"', $badchar), 1)));
1176
1177                                                continue;
1178                                        }
1179
1180                                        # Check to see if the file exists in the database, and get its info at the same time
1181                                        $ls_array = $this->bo->vfs->ls(array(
1182                                                'string'=> $this->path . '/' . $_FILES['upload_file']['name'][$i],
1183                                                'relatives'     => array(RELATIVE_NONE),
1184                                                'checksubdirs'  => False,
1185                                                'nofiles'       => True
1186                                        ));
1187
1188                                        $fileinfo = $ls_array[0];
1189
1190                                        if($fileinfo['name'])
1191                                        {
1192                                                if($fileinfo['mime_type'] == 'Directory')
1193                                                {
1194                                                        $this->messages[]= $GLOBALS['phpgw']->common->error_list(array(lang('Cannot replace %1 because it is a directory', $fileinfo['name'])));
1195                                                        continue;
1196                                                }
1197                                        }
1198                                         $max_size = $this->current_config['filemanager_Max_file_size'];
1199                                         if (! $max_size)
1200                                                 $max_size = ini_get('upload_max_filesize');
1201                                         else
1202                                                 $max_size .= "M";
1203
1204                                         $upload_max_filesize = str_replace("M","",$max_size) * 1024 * 1024;
1205
1206                                        if ($_FILES['upload_file']['size'][$i] > $upload_max_filesize)
1207                                        {
1208                                                $this->messages[]=lang('The size of %1 has exceded the limit: %2', $this->disppath.'/'.$_FILES['upload_file']['name'][$i], $max_size);
1209                                        }
1210                                        else
1211                                        if($_FILES['upload_file']['size'][$i] > 0)
1212                                        {
1213                                                if($fileinfo['name'] && $fileinfo['deleteable'] != 'N')
1214                                                {
1215                                                        $tmp_arr=array(
1216                                                                'string'=> $_FILES['upload_file']['name'][$i],
1217                                                                'relatives'     => array(RELATIVE_ALL),
1218                                                                'attributes'    => array(
1219                                                                        'owner_id' => $this->bo->userinfo['username'],
1220                                                                        'modifiedby_id' => $this->bo->userinfo['username'],
1221                                                                        'modified' => $this->now,
1222                                                                        'size' => $_FILES['upload_file']['size'][$i],
1223                                                                        'mime_type' => $_FILES['upload_file']['type'][$i],
1224                                                                        'deleteable' => 'Y',
1225                                                                        'comment' => stripslashes($_POST['upload_comment'][$i])
1226                                                                )
1227                                                        );
1228                                                        $this->bo->vfs->set_attributes($tmp_arr);
1229
1230                                                        $tmp_arr=array(
1231                                                                'from'  => $_FILES['upload_file']['tmp_name'][$i],
1232                                                                'to'    => $_FILES['upload_file']['name'][$i],
1233                                                                'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
1234                                                        );
1235                                                        $this->bo->vfs->cp($tmp_arr);
1236
1237                                                        $this->messages[]=lang('Replaced %1', $this->disppath.'/'.$_FILES['upload_file']['name'][$i]);
1238                                                }
1239                                                else
1240                                                {
1241
1242                                                        $this->bo->vfs->cp(array(
1243                                                                'from'=> $_FILES['upload_file']['tmp_name'][$i],
1244                                                                'to'=> $_FILES['upload_file']['name'][$i],
1245                                                                'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
1246                                                        ));
1247
1248                                                        $this->bo->vfs->set_attributes(array(
1249                                                                'string'=> $_FILES['upload_file']['name'][$i],
1250                                                                'relatives'     => array(RELATIVE_ALL),
1251                                                                'attributes'=> array(
1252                                                                        'mime_type' => $_FILES['upload_file']['type'][$i],
1253                                                                        'comment' => stripslashes($_POST['upload_comment'][$i])
1254                                                                )
1255                                                        ));
1256
1257                                                        $this->messages[]=lang('Created %1,%2', $this->disppath.'/'.$_FILES['upload_file']['name'][$i], $_FILES['upload_file']['size'][$i]);
1258                                                }
1259                                        }
1260                                        elseif($_FILES['upload_file']['name'][$i])
1261                                        {
1262                                                $this->bo->vfs->touch(array(
1263                                                        'string'=> $_FILES['upload_file']['name'][$i],
1264                                                        'relatives'     => array(RELATIVE_ALL)
1265                                                ));
1266
1267                                                $this->bo->vfs->set_attributes(array(
1268                                                        'string'=> $_FILES['upload_file']['name'][$i],
1269                                                        'relatives'     => array(RELATIVE_ALL),
1270                                                        'attributes'=> array(
1271                                                                'mime_type' => $_FILES['upload_file']['type'][$i],
1272                                                                'comment' => stripslashes($_POST['upload_comment'][$i])
1273                                                        )
1274                                                ));
1275
1276                                                $this->messages[]=lang('Created %1,%2', $this->disppath.'/'.$_FILES['upload_file']['name'][$i], $file_size[$i]);
1277                                        }
1278                                }
1279
1280                                $this->readFilesInfo();
1281                                $this->filelisting();
1282                        }
1283                }
1284
1285                # Handle Editing comments
1286                function editComment()
1287                {
1288                        while(list($file) = each($this->comment_files))
1289                        {
1290                                if($badchar = $this->bo->bad_chars($this->comment_files[$file], False, True))
1291                                {
1292                                        $this->messages[]=$GLOBALS['phpgw']->common->error_list(array($file . $this->bo->html_encode(': ' . lang('Comments cannot contain "%1"', $badchar), 1)));
1293                                        continue;
1294                                }
1295
1296                                $this->bo->vfs->set_attributes(array(
1297                                        'string'        => $file,
1298                                        'relatives'     => array(RELATIVE_ALL),
1299                                        'attributes'    => array(
1300                                                'comment' => stripslashes($this->comment_files[$file])
1301                                        )
1302                                ));
1303
1304                                $this->messages[]=lang('Updated comment for %1', $this->path.'/'.$file);
1305                        }
1306
1307                        $this->readFilesInfo();
1308                        $this->filelisting();
1309                }
1310
1311                # Handle Renaming Files and Directories
1312                function rename()
1313                {
1314                        while(list($from, $to) = each($this->renamefiles))
1315                        {
1316                                if($badchar = $this->bo->bad_chars($to, True, True))
1317                                {
1318                                        $this->messages[]=$GLOBALS['phpgw']->common->error_list(array($this->bo->html_encode(lang('File names cannot contain "%1"', $badchar), 1)));
1319                                        continue;
1320                                }
1321
1322                                if(ereg("/", $to) || ereg("\\\\", $to))
1323                                {
1324                                        $this->messages[]=$GLOBALS['phpgw']->common->error_list(array(lang("File names cannot contain \\ or /")));
1325                                }
1326                                elseif(!$this->bo->vfs->mv(array(
1327                                        'from'  => $from,
1328                                        'to'    => $to
1329                                )))
1330                                {
1331                                        $this->messages[]= $GLOBALS['phpgw']->common->error_list(array(lang('Could not rename %1 to %2', $this->disppath.'/'.$from, $this->disppath.'/'.$to)));
1332                                }
1333                                else
1334                                {
1335                                        $this->messages[]=lang('Renamed %1 to %2', $this->disppath.'/'.$from, $this->disppath.'/'.$to);
1336                                }
1337                        }
1338                        $this->readFilesInfo();
1339                        $this->filelisting();
1340                }
1341
1342                # Handle Moving Files and Directories
1343                function moveTo()
1344                {
1345                        if(!$this->todir)
1346                        {
1347                                $this->messages[] = $GLOBALS['phpgw']->common->error_list(array(lang('Could not move file because no destination directory is given ', $this->disppath.'/'.$file)));
1348
1349                        }
1350                        else
1351                        {
1352
1353                                while(list($num, $file) = each($this->fileman))
1354                                {
1355                                        if($this->bo->vfs->mv(array(
1356                                                'from'  => $file,
1357                                                'to'    => $this->todir . '/' . $file,
1358                                                'relatives'     => array(RELATIVE_ALL, RELATIVE_NONE)
1359                                        )))
1360                                        {
1361                                                $moved++;
1362                                                $this->messages[]=lang('Moved %1 to %2', $this->disppath.'/'.$file, $this->todir.'/'.$file);
1363                                        }
1364                                        else
1365                                        {
1366                                                $this->messages[] = $GLOBALS['phpgw']->common->error_list(array(lang('Could not move %1 to %2', $this->disppath.'/'.$file, $this->todir.'/'.$file)));
1367                                        }
1368                                }
1369                        }
1370
1371                        if($moved)
1372                        {
1373                                $x=0;
1374                        }
1375
1376                        $this->readFilesInfo();
1377                        $this->filelisting();
1378                }
1379
1380                // Handle Copying of Files and Directories
1381                function copyTo()
1382                {
1383                        if(!$this->todir)
1384                        {
1385                                $this->messages[] = $GLOBALS['phpgw']->common->error_list(array(lang('Could not copy file because no destination directory is given ', $this->disppath.'/'.$file)));
1386
1387                        }
1388                        else
1389                        {
1390                                while(list($num, $file) = each($this->fileman))
1391                                {
1392                                        if($this->bo->vfs->cp(array(
1393                                                'from'  => $file,
1394                                                'to'    => $this->todir . '/' . $file,
1395                                                'relatives'     => array(RELATIVE_ALL, RELATIVE_NONE)
1396                                        )))
1397                                        {
1398                                                $copied++;
1399                                                $this->messages[] .= lang('Copied %1 to %2', $this->disppath.'/'.$file, $this->todir.'/'.$file);
1400                                        }
1401                                        else
1402                                        {
1403                                                $this->messages[] .= lang('Could not copy %1 to %2', $this->disppath.'/'.$file, $this->todir.'/'.$file);
1404                                        }
1405                                }
1406                        }
1407                        if($copied)
1408                        {
1409                                $x=0;
1410                        }
1411
1412                        $this->readFilesInfo();
1413                        $this->filelisting();
1414                }
1415
1416                function createdir()
1417                {
1418                        if($this->newdir_x && $this->newfile_or_dir)
1419                        {
1420                                if($this->bo->badchar = $this->bo->bad_chars($this->newfile_or_dir, True, True))
1421                                {
1422                                        $this->messages[]= $GLOBALS['phpgw']->common->error_list(array($this->bo->html_encode(lang('Directory names cannot contain "%1"', $badchar), 1)));
1423                                }
1424
1425                                /* TODO is this right or should it be a single $ ? */
1426                                if($$this->newfile_or_dir[strlen($this->newfile_or_dir)-1] == ' ' || $this->newfile_or_dir[0] == ' ')
1427                                {
1428                                        $this->messages[]= $GLOBALS['phpgw']->common->error_list(array(lang('Cannot create directory because it begins or ends in a space')));
1429                                }
1430
1431                                $ls_array = $this->bo->vfs->ls(array(
1432                                        'string'        => $this->path . '/' . $this->newfile_or_dir,
1433                                        'relatives'     => array(RELATIVE_NONE),
1434                                        'checksubdirs'  => False,
1435                                        'nofiles'       => True
1436                                ));
1437
1438                                $fileinfo = $ls_array[0];
1439
1440                                if($fileinfo['name'])
1441                                {
1442                                        if($fileinfo['mime_type'] != 'Directory')
1443                                        {
1444                                                $this->messages[]= $GLOBALS['phpgw']->common->error_list(array(
1445                                                        lang('%1 already exists as a file',
1446                                                        $fileinfo['name'])
1447                                                ));
1448                                        }
1449                                        else
1450                                        {
1451                                                $this->messages[]= $GLOBALS['phpgw']->common->error_list(array(lang('Directory %1 already exists', $fileinfo['name'])));
1452                                        }
1453                                }
1454                                else
1455                                {
1456                                        if($this->bo->vfs->mkdir(array('string' => $this->newfile_or_dir)))
1457                                        {
1458                                                $this->messages[]=lang('Created directory %1', $this->disppath.'/'.$this->newfile_or_dir);
1459                                        }
1460                                        else
1461                                        {
1462                                                $this->messages[]=$GLOBALS['phpgw']->common->error_list(array(lang('Could not create %1', $this->disppath.'/'.$this->newfile_or_dir)));
1463                                        }
1464                                }
1465
1466                                $this->readFilesInfo();
1467                                $this->filelisting();
1468                        }
1469                }
1470
1471                function delete()
1472                {
1473                        if( is_array($this->fileman) && count($this->fileman) >= 1)
1474                        {
1475                                foreach($this->fileman as $filename)
1476                                {
1477                                        if($this->bo->vfs->delete(array('string' => $filename)))
1478                                        {
1479                                                $this->messages[]= lang('Deleted %1', $this->disppath.'/'.$filename).'<br/>';
1480                                        }
1481                                        else
1482                                        {
1483                                                $this->messages[]=$GLOBALS['phpgw']->common->error_list(array(lang('Could not delete %1', $this->disppath.'/'.$filename)));
1484                                        }
1485                                }
1486                        }
1487                        else
1488                        {
1489                                // make this a javascript func for quicker respons
1490                                $this->messages[]=$GLOBALS['phpgw']->common->error_list(array(lang('Please select a file to delete.')));
1491                        }
1492                        $this->readFilesInfo();
1493                        $this->filelisting();
1494                }
1495
1496                function debug_filemanager()
1497                {
1498                        error_reporting(8);
1499
1500                        echo "<b>Filemanager debug:</b><br>
1501                        path: {$this->path}<br>
1502                        disppath: {$this->disppath}<br>
1503                        cwd: {$this->cwd}<br>
1504                        lesspath: {$this->lesspath}
1505                        <p>
1506                        <b>eGroupware debug:</b><br>
1507                        real getabsolutepath: " . $this->bo->vfs->getabsolutepath(array('target' => False, 'mask' => False, 'fake' => False)) . "<br>
1508                        fake getabsolutepath: " . $this->bo->vfs->getabsolutepath(array('target' => False)) . "<br>
1509                        appsession: " . $GLOBALS['phpgw']->session->appsession('vfs','') . "<br>
1510                        pwd: " . $this->bo->vfs->pwd() . "<br>";
1511
1512                        echo '<p></p>';
1513                        var_dump($this);
1514                }
1515
1516                function showUploadboxes()
1517                {
1518                        $this->t->set_file(array('upload' => 'upload.tpl'));
1519                        $this->t->set_block('upload','upload_header','upload_header');
1520                        $this->t->set_block('upload','row','row');
1521                        $this->t->set_block('upload','upload_footer','upload_footer');
1522
1523                        # Decide how many upload boxes to show
1524                        if(!$this->show_upload_boxes || $this->show_upload_boxes <= 0)
1525                        {
1526                                if(!$this->show_upload_boxes = $this->prefs['show_upload_boxes'])
1527                                {
1528                                        $this->show_upload_boxes = 1;
1529                                }
1530                        }
1531
1532                        # Show file upload boxes. Note the last argument to html().  Repeats $this->show_upload_boxes times
1533                        if($this->path != '/' && $this->path != $this->bo->fakebase && $this->can_add)
1534                        {
1535                                $vars[form_action]=$GLOBALS[phpgw]->link('/index.php','menuaction=filemanager.uifilemanager.index');
1536                                $vars[path]=$this->path;
1537                                $vars[lang_file]=lang('File');
1538                                $vars[lang_comment]=lang('Comment');
1539                                $vars[num_upload_boxes]=$this->show_upload_boxes;
1540                                $this->t->set_var($vars);
1541                                $this->t->pparse('out','upload_header');
1542
1543                                for($i=0;$i<$this->show_upload_boxes;$i++)
1544                                {
1545                                        $this->t->set_var('row_tr_color',$tr_color);
1546                                        $this->t->parse('rows','row');
1547                                        $this->t->pparse('out','row');
1548                                }
1549
1550                                $vars[lang_upload]=lang('Upload files');
1551                                $vars[change_upload_boxes].=lang('Show') . '&nbsp;';
1552                                $links.= $this->html_link('/index.php','menuaction=filemanager.uifilemanager.index','show_upload_boxes=5', '5');
1553                                $links.='&nbsp;';
1554                                $links.= $this->html_link('/index.php','menuaction=filemanager.uifilemanager.index','show_upload_boxes=10', '10');
1555                                $links.='&nbsp;';
1556                                $links.= $this->html_link('/index.php','menuaction=filemanager.uifilemanager.index','show_upload_boxes=20', '20');
1557                                $links.='&nbsp;';
1558                                $links.= $this->html_link('/index.php','menuaction=filemanager.uifilemanager.index','show_upload_boxes=50', '50');
1559                                $links.='&nbsp;';
1560                                $links.= lang('upload fields');
1561                                $vars[change_upload_boxes].=$links;
1562                                $this->t->set_var($vars);
1563                                $this->t->pparse('out','upload_footer');
1564                        }
1565                }
1566
1567                /* create textfile */
1568                function createfile()
1569                {
1570                        $this->createfile_var=$this->newfile_or_dir;
1571                        if($this->createfile_var)
1572                        {
1573                                if($badchar = $this->bo->bad_chars($this->createfile_var, True, True))
1574                                {
1575                                        $this->messages[] = $GLOBALS['phpgw']->common->error_list(array(
1576                                                lang('File names cannot contain "%1"',$badchar),
1577                                                1)
1578                                        );
1579
1580                                        $this->fileListing();
1581                                }
1582
1583                                if($this->bo->vfs->file_exists(array(
1584                                        'string'=> $this->createfile_var,
1585                                        'relatives'     => array(RELATIVE_ALL)
1586                                )))
1587                                {
1588                                        $this->messages[]=$GLOBALS['phpgw']->common->error_list(array(lang('File %1 already exists. Please edit it or delete it first.', $this->createfile_var)));
1589                                        $this->fileListing();
1590                                }
1591
1592                                if($this->bo->vfs->touch(array(
1593                                        'string'        => $this->createfile_var,
1594                                        'relatives'     => array(RELATIVE_ALL)
1595                                )))
1596                                {
1597                                        $this->fileman = array();
1598                                        $this->fileman[0] = $this->createfile_var;
1599                                        $this->edit = 1;
1600                                        $this->numoffiles++;
1601                                        $this->edit();
1602                                }
1603                                else
1604                                {
1605                                        $this->messages[]=$GLOBALS['phpgw']->common->error_list(array(lang('File %1 could not be created.', $this->createfile_var)));
1606                                        $this->fileListing();
1607                                }
1608                        }
1609                }
1610
1611                # Handle Editing files
1612                function edit()
1613                {
1614                        $files = array_keys($this->fileman);
1615                        $this->file = $this->fileman[$files[0]];
1616                        if($this->file)
1617                        {
1618                                $ls_array = $this->bo->vfs->ls(array(
1619                                        'string'        => $this->path.'/'.$this->file,
1620                                        'relatives'     => array(RELATIVE_ALL),
1621                                        'checksubdirs'  => False,
1622                                        'nofiles'       => True
1623                                ));
1624
1625                                if($ls_array[0]['mime_type'])
1626                                {
1627                                        $mime_type = $ls_array[0]['mime_type'];
1628                                }
1629                                elseif($this->prefs['viewtextplain'])
1630                                {
1631                                        $mime_type = 'text/plain';
1632                                }
1633                                $viewable = array('','text/plain','text/csv','text/html','text/text');
1634
1635                                if(!in_array($mime_type,$viewable)){
1636                                        echo lang('Impossbile to edit this file');
1637                                        return False;
1638                                }
1639                        }
1640
1641                        $this->readFilesInfo();
1642
1643                        $this->t->set_file(array('filemanager_edit' => 'edit_file.tpl'));
1644                        $this->t->set_block('filemanager_edit','row','row');
1645
1646                        $vars[preview_content]='';
1647                        if($this->edit_file)
1648                        {
1649                                $this->edit_file_content = stripslashes($this->edit_file_content);
1650                        }
1651
1652                        if($this->edit_preview_x)
1653                        {
1654                                $content = $this->edit_file_content;
1655
1656                                $vars[lang_preview_of]=lang('Preview of %1', $this->path.'/'.$edit_file);
1657
1658                                $vars[preview_content]=nl2br($content);
1659                        }
1660                        elseif($this->edit_save_x || $this->edit_save_done_x)
1661                        {
1662                                $content = $this->edit_file_content;
1663                                //die( $content);
1664                                if($this->bo->vfs->write(array(
1665                                        'string'        => $this->edit_file,
1666                                        'relatives'     => array(RELATIVE_ALL),
1667                                        'content'       => $content
1668                                )))
1669                                {
1670                                        $this->messages[]=lang('Saved %1', $this->path.'/'.$this->edit_file);
1671
1672                                        if($this->edit_save_done_x)
1673                                        {
1674                                                $this->readFilesInfo();
1675                                                $this->fileListing();
1676                                                exit;
1677                                        }
1678                                }
1679                                else
1680                                {
1681                                        echo lang('Could not save %1', $this->path.'/'.$this->edit_file);
1682                                        $this->messages[]=lang('Could not save %1', $this->path.'/'.$this->edit_file);
1683                                }
1684                        }
1685
1686                        # Now we display the edit boxes and forms
1687                        for($j = 0; $j != $this->numoffiles; $j++)
1688                        {
1689                                # If we're in preview or save mode, we only show the file
1690                                # being previewed or saved
1691                                if($this->edit_file &&($this->fileman[$j] != $this->edit_file))
1692                                {
1693                                        continue;
1694                                }
1695
1696                                if($this->fileman[$j] && $this->bo->vfs->file_exists(array(
1697                                        'string'        => $this->fileman[$j],
1698                                        'relatives'     => array(RELATIVE_ALL)
1699                                )))
1700                                {
1701                                        if($this->edit_file)
1702                                        {
1703                                                $content = stripslashes($this->edit_file_content);
1704                                        }
1705                                        else
1706                                        {
1707                                                $content = $this->bo->vfs->read(array('string' => $this->fileman[$j]));
1708                                        }
1709
1710                                        $vars[form_action]= $GLOBALS['phpgw']->link('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->path);
1711                                        $vars[edit_file]=$this->fileman[$j];
1712
1713                                        # We need to include all of the fileman entries for each file's form,
1714                                        # so we loop through again
1715                                        for($i = 0; $i != $this->numoffiles; $i++)
1716                                        {
1717                                                if($this->fileman[$i]) $value='value="'.$this->fileman[$i].'"';
1718                                                $vars[filemans_hidden]='<input type="hidden" name="fileman['.$i.']" '.$value.' />';
1719                                        }
1720
1721                                        $vars[file_content]=$content;
1722
1723                                        $vars[buttonPreview]=$this->inputImage('edit_preview','edit_preview',lang('Preview %1', $this->bo->html_encode($this->fileman[$j], 1)));
1724                                        $vars[buttonSave]=$this->inputImage('edit_save','save',lang('Save %1', $this->bo->html_encode($this->fileman[$j], 1)));
1725                                        $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)));
1726                                        $vars[buttonCancel]=$this->inputImage('edit_cancel','cancel',lang('Cancel editing %1 without saving', $this->bo->html_encode($this->fileman[$j], 1)));
1727                                        $this->t->set_var($vars);
1728                                        $this->t->parse('rows','row');
1729                                        $this->t->pparse('out','row');
1730
1731                                }
1732                        }
1733                }
1734
1735                function history()
1736                {
1737                        if($this->file) // FIXME this-file is never defined
1738                        {
1739                                $journal_array = $this->bo->vfs->get_journal(array(
1740                                        'string'        => $this->file,//FIXME
1741                                        'relatives'     => array(RELATIVE_ALL)
1742                                ));
1743
1744                                if(is_array($journal_array))
1745                                {
1746                                        $this->html_table_begin();
1747                                        $this->html_table_row_begin();
1748                                        $this->html_table_col_begin();
1749                                        echo lang('Date');
1750                                        $this->html_table_col_end();
1751                                        $this->html_table_col_begin();
1752                                        echo lang('Version');
1753                                        $this->html_table_col_end();
1754                                        $this->html_table_col_begin();
1755                                        echo lang('Who');
1756                                        $this->html_table_col_end();
1757                                        $this->html_table_col_begin();
1758                                        echo lang('Operation');
1759                                        $this->html_table_col_end();
1760                                        $this->html_table_row_end();
1761
1762                                        while(list($num, $journal_entry) = each($journal_array))
1763                                        {
1764                                                $this->html_table_row_begin();
1765                                                $this->html_table_col_begin();
1766                                                $this->bo->html_text($journal_entry['created'] . '&nbsp;&nbsp;&nbsp;');
1767                                                $this->html_table_col_end();
1768                                                $this->html_table_col_begin();
1769                                                $this->bo->html_text($journal_entry['version'] . '&nbsp;&nbsp;&nbsp;' );
1770                                                $this->html_table_col_end();
1771                                                $this->html_table_col_begin();
1772                                                $this->bo->html_text($GLOBALS['phpgw']->accounts->id2name($journal_entry['owner_id']) . '&nbsp;&nbsp;&nbsp;');
1773                                                $this->html_table_col_end();
1774                                                $this->html_table_col_begin();
1775                                                $this->bo->html_text($journal_entry['comment']);
1776                                                $this->html_table_col_end();
1777                                        }
1778
1779                                        $this->html_table_end();
1780                                        $GLOBALS['phpgw']->common->phpgw_footer();
1781                                        $GLOBALS['phpgw']->common->phpgw_exit();
1782                                }
1783                                else
1784                                {
1785                                        echo lang('No version history for this file/directory');
1786                                }
1787                        }
1788                }
1789
1790                function view()
1791                {
1792                        if($this->file) //FIXME
1793                        {
1794                                $ls_array = $this->bo->vfs->ls(array(
1795                                        'string'        => $this->path.'/'.$this->file,//FIXME
1796                                        'relatives'     => array(RELATIVE_NONE),
1797                                        'checksubdirs'  => False,
1798                                        'nofiles'       => True
1799                                ));
1800
1801                                if($ls_array[0]['mime_type'])
1802                                {
1803                                        $mime_type = $ls_array[0]['mime_type'];
1804                                }
1805                                elseif($this->prefs['viewtextplain'])
1806                                {
1807                                        $mime_type = 'text/plain';
1808                                }
1809                                $viewable = array('','text/plain','text/csv','text/html','text/text');
1810
1811                                if(in_array($mime_type,$viewable) && !$_GET['download'])
1812                                {
1813                                       
1814                                    header('Content-type: ' . $mime_type);
1815                                        header('Content-disposition: filename="' . $this->file . '"');//FIXME
1816                                        Header("Pragma: public");
1817                                }
1818                                else
1819                                {
1820                                        $GLOBALS['phpgw']->browser->content_header($this->file,$mime_type);//FIXME
1821                                }
1822                                echo $this->bo->vfs->read(array(
1823                                        'string'        => $this->path.'/'.$this->file,//FIXME
1824                                        'relatives'     => array(RELATIVE_NONE)
1825                                ));
1826                                $GLOBALS['phpgw']->common->phpgw_exit();
1827                        }
1828                }
1829
1830                function download()
1831                {
1832                        for($i = 0; $i != $this->numoffiles; $i++)
1833                        {
1834                                if(!$this->fileman[$i])
1835                                {
1836                                        continue;
1837                                }
1838
1839                                $download_browser = CreateObject('phpgwapi.browser');
1840                                $download_browser->content_header($this->fileman[$i]);
1841                                echo $this->bo->vfs->read(array('string' => $this->fileman[$i]));
1842                                $GLOBALS['phpgw']->common->phpgw_exit();
1843                        }
1844                }
1845
1846                //give back an array with all directories except current and dirs that are not accessable
1847                function all_other_directories_options()
1848                {
1849                        # First we get the directories in their home directory
1850                        $dirs = array();
1851                        $dirs[] = array('directory' => $this->bo->fakebase, 'name' => $this->bo->userinfo['account_lid']);
1852
1853                        $tmp_arr=array(
1854                                'string'        => $this->bo->homedir,
1855                                'relatives'     => array(RELATIVE_NONE),
1856                                'checksubdirs'  => True,
1857                                'mime_type'     => 'Directory'
1858                        );
1859
1860                        $ls_array = $this->bo->vfs->ls($tmp_arr);
1861
1862                        while(list($num, $dir) = each($ls_array))
1863                        {
1864                                $dirs[] = $dir;
1865                        }
1866
1867
1868                        # Then we get the directories in their readable groups' home directories
1869                        reset($this->readable_groups);
1870                        while(list($num, $group_array) = each($this->readable_groups))
1871                        {
1872                                /* Don't list directories for groups that don't have access
1873                                if(!$this->groups_applications[$group_array['account_name']][$this->bo->appname]['enabled'])
1874                                {
1875]                                       continue;
1876                                }*/
1877
1878                                $dirs[] = array('directory' => $this->bo->fakebase, 'name' => $group_array['account_name']);
1879
1880                                $tmp_arr=array(
1881                                        'string'        => $this->bo->fakebase.'/'.$group_array['account_name'],
1882                                        'relatives'     => array(RELATIVE_NONE),
1883                                        'checksubdirs'  => True,
1884                                        'mime_type'     => 'Directory'
1885                                );
1886
1887                                $ls_array = $this->bo->vfs->ls($tmp_arr);
1888                                while(list($num, $dir) = each($ls_array))
1889                                {
1890                                        $dirs[] = $dir;
1891                                }
1892                        }
1893
1894                        reset($dirs);
1895                        while(list($num, $dir) = each($dirs))
1896                        {
1897                                if(!$dir['directory'])
1898                                {
1899                                        continue;
1900                                }
1901
1902                                # So we don't display //
1903                                if($dir['directory'] != '/')
1904                                {
1905                                        $dir['directory'] .= '/';
1906                                }
1907
1908                                # No point in displaying the current directory, or a directory that doesn't exist
1909                                if((($dir['directory'] . $dir['name']) != $this->path) && $this->bo->vfs->file_exists(array('string' => $dir['directory'] . $dir['name'],'relatives' => array(RELATIVE_NONE))))
1910                                {
1911                                        //FIXME replace the html_form_option function
1912                                        $options .= $this->html_form_option($dir['directory'] . $dir['name'], $dir['directory'] . $dir['name']);
1913                                }
1914                        }
1915
1916                        return $options;
1917                }
1918
1919                /* seek icon for mimetype else return an unknown icon */
1920                function mime_icon($mime_type, $size=16)
1921                {
1922                        if(!$mime_type) $mime_type='unknown';
1923
1924                        $mime_type=     str_replace     ('/','_',$mime_type);
1925
1926                        $img=$GLOBALS['phpgw']->common->image('filemanager','mime'.$size.'_'.strtolower($mime_type));
1927                        if(!$img) $img=$GLOBALS['phpgw']->common->image('filemanager','mime'.$size.'_unknown');
1928
1929                        $icon='<img src="'.$img.' "alt="'.lang($mime_type).'" />';
1930                        return $icon;
1931                }
1932
1933                function buttonImage($link,$img='',$description='')
1934                {
1935                        $image=$GLOBALS['phpgw']->common->image('filemanager','button_'.strtolower($img));
1936
1937                        if($img)
1938                        {
1939                                return '<td class="" align="center" valign="middle" height="28" width="70">
1940                                <a href="'.$link.'" title="'.$description.'"><img src="'.$image.'" alt="'.$description.'"/></a><br><small>'.$description.'</small>
1941                                </td>';
1942                        }
1943                }
1944
1945                function inputImage($name,$img='',$description='')
1946                {
1947                        $image=$GLOBALS['phpgw']->common->image('filemanager','button_'.strtolower($img));
1948
1949                        if($img)
1950                        {
1951                                return '<td class="" align="center" valign="middle" height="28" width="70">
1952                                <input onclick="return formfmValidate(this.name)" title="'.$description.'" name="'.$name.'" type="image" alt="'.$name.'" src="'.$image.'" value="clicked" /><br><small>'.$description.'</small>
1953                                </td>';
1954                        }
1955                }
1956
1957                function html_form_input($type = NULL, $name = NULL, $value = NULL, $maxlength = NULL, $size = NULL, $checked = NULL, $string = '', $return = 1)
1958                {
1959                        $text = ' ';
1960                        if($type != NULL && $type)
1961                        {
1962                                if($type == 'checkbox')
1963                                {
1964                                        $value = $this->bo->string_encode($value, 1);
1965                                }
1966                                $text .= 'type="'.$type.'" ';
1967                        }
1968                        if($name != NULL && $name)
1969                        {
1970                                $text .= 'name="'.$name.'" ';
1971                        }
1972                        if($value != NULL && $value)
1973                        {
1974                                $text .= 'value="'.$value.'" ';
1975                        }
1976                        if(is_int($maxlength) && $maxlength >= 0)
1977                        {
1978                                $text .= 'maxlength="'.$maxlength.'" ';
1979                        }
1980                        if(is_int($size) && $size >= 0)
1981                        {
1982                                $text .= 'size="'.$size.'" ';
1983                        }
1984                        if($checked != NULL && $checked)
1985                        {
1986                                $text .= 'checked ';
1987                        }
1988
1989                        return '<input'.$text.$string.'>';
1990                }
1991
1992                function html_form_option($value = NULL, $displayed = NULL, $selected = NULL, $return = 0)
1993                {
1994                        $text = ' ';
1995                        if($value != NULL && $value)
1996                        {
1997                                $text .= ' value="'.$value.'" ';
1998                        }
1999                        if($selected != NULL && $selected)
2000                        {
2001                                $text .= ' selected';
2002                        }
2003                        return  '<option'.$text.'>'.$displayed.'</option>';
2004                }
2005
2006                function encode_href($href = NULL, $args = NULL , $extra_args)
2007                {
2008                        $href = $this->bo->string_encode($href, 1);
2009                        $all_args = $args.'&'.$this->bo->string_encode($extra_args, 1);
2010
2011                        $address = $GLOBALS['phpgw']->link($href, $all_args);
2012
2013                        return $address;
2014                }
2015
2016                function html_link($href = NULL, $args = NULL , $extra_args, $text = NULL, $return = 1, $encode = 1, $linkonly = 0, $target = NULL)
2017                {
2018                        //      unset($encode);
2019                        if($encode)
2020                        {
2021                                $href = $this->bo->string_encode($href, 1);
2022                                $all_args = $args.'&'.$this->bo->string_encode($extra_args, 1);
2023                        }
2024                        else
2025                        {
2026                                //                              $href = $this->bo->string_encode($href, 1);
2027                                $all_args = $args.'&'.$extra_args;
2028                        }
2029                        ###
2030                        # This decodes / back to normal
2031                        ###
2032                        //                      $all_args = preg_replace("/%2F/", "/", $all_args);
2033                        //                      $href = preg_replace("/%2F/", "/", $href);
2034
2035                        /* Auto-detect and don't disturb absolute links */
2036                        if(!preg_match("|^http(.{0,1})://|", $href))
2037                        {
2038                                //Only add an extra / if there isn't already one there
2039
2040                                // die(SEP);
2041                                if(!($href[0] == SEP))
2042                                {
2043                                        $href = SEP . $href;
2044                                }
2045
2046                                /* $phpgw->link requires that the extra vars be passed separately */
2047                                //                              $link_parts = explode("?", $href);
2048                                $address = $GLOBALS['phpgw']->link($href, $all_args);
2049                                //                              $address = $GLOBALS['phpgw']->link($href);
2050                        }
2051                        else
2052                        {
2053                                $address = $href;
2054                        }
2055
2056                        /* If $linkonly is set, don't add any HTML */
2057                        if($linkonly)
2058                        {
2059                                $rstring = $address;
2060                        }
2061                        else
2062                        {
2063                                if($target)
2064                                {
2065                                        $target = 'target='.$target;
2066                                }
2067
2068                                $text = trim($text);
2069                                $rstring = '<a href="'.$address.'" '.$target.'>'.$text.'</a>';
2070                        }
2071
2072                        return($this->bo->eor($rstring, $return));
2073                }
2074
2075                function html_table_begin($width = NULL, $border = NULL, $cellspacing = NULL, $cellpadding = NULL, $rules = NULL, $string = '', $return = 0)
2076                {
2077                        if($width != NULL && $width)
2078                        {
2079                                $width = "width=$width";
2080                        }
2081                        if(is_int($border) && $border >= 0)
2082                        {
2083                                $border = "border=$border";
2084                        }
2085                        if(is_int($cellspacing) && $cellspacing >= 0)
2086                        {
2087                                $cellspacing = "cellspacing=$cellspacing";
2088                        }
2089                        if(is_int($cellpadding) && $cellpadding >= 0)
2090                        {
2091                                $cellpadding = "cellpadding=$cellpadding";
2092                        }
2093                        if($rules != NULL && $rules)
2094                        {
2095                                $rules = "rules=$rules";
2096                        }
2097
2098                        $rstring = "<table $width $border $cellspacing $cellpadding $rules $string>";
2099                        return($this->bo->eor($rstring, $return));
2100                }
2101
2102                function html_table_end($return = 0)
2103                {
2104                        $rstring = "</table>";
2105                        return($this->bo->eor($rstring, $return));
2106                }
2107
2108                function html_table_row_begin($align = NULL, $halign = NULL, $valign = NULL, $bgcolor = NULL, $string = '', $return = 0)
2109                {
2110                        if($align != NULL && $align)
2111                        {
2112                                $align = "align=$align";
2113                        }
2114                        if($halign != NULL && $halign)
2115                        {
2116                                $halign = "halign=$halign";
2117                        }
2118                        if($valign != NULL && $valign)
2119                        {
2120                                $valign = "valign=$valign";
2121                        }
2122                        if($bgcolor != NULL && $bgcolor)
2123                        {
2124                                $bgcolor = "bgcolor=$bgcolor";
2125                        }
2126                        $rstring = "<tr $align $halign $valign $bgcolor $string>";
2127                        return($this->bo->eor($rstring, $return));
2128                }
2129
2130                function html_table_row_end($return = 0)
2131                {
2132                        $rstring = "</tr>";
2133                        return($this->bo->eor($rstring, $return));
2134                }
2135
2136                function html_table_col_begin($align = NULL, $halign = NULL, $valign = NULL, $rowspan = NULL, $colspan = NULL, $string = '', $return = 0)
2137                {
2138                        if($align != NULL && $align)
2139                        {
2140                                $align = "align=$align";
2141                        }
2142                        if($halign != NULL && $halign)
2143                        {
2144                                $halign = "halign=$halign";
2145                        }
2146                        if($valign != NULL && $valign)
2147                        {
2148                                $valign = "valign=$valign";
2149                        }
2150                        if(is_int($rowspan) && $rowspan >= 0)
2151                        {
2152                                $rowspan = "rowspan=$rowspan";
2153                        }
2154                        if(is_int($colspan) && $colspan >= 0)
2155                        {
2156                                $colspan = "colspan=$colspan";
2157                        }
2158
2159                        $rstring = "<td $align $halign $valign $rowspan $colspan $string>";
2160                        return($this->bo->eor($rstring, $return));
2161                }
2162
2163                function html_table_col_end($return = 0)
2164                {
2165                        $rstring = "</td>";
2166                        return($this->bo->eor($rstring, $return));
2167                }
2168        }
Note: See TracBrowser for help on using the repository browser.