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

Revision 1590, 67.8 KB checked in by amuller, 14 years ago (diff)

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