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

Revision 1529, 62.4 KB checked in by amuller, 15 years ago (diff)

Ticket #597 - Melhorias no módulo de gerenciamento de arquivos

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