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

Revision 1508, 60.7 KB checked in by amuller, 15 years ago (diff)

Ticket #597 - Arrumando permissões de usuários para usuários

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