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

Revision 1506, 60.3 KB checked in by amuller, 15 years ago (diff)

Ticket #597 - Adicionando código do filemanager compatível com expresso

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