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

Revision 1525, 61.3 KB checked in by amuller, 15 years ago (diff)

Ticket #597 - Melhorando bugs de interface do filemanager

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