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

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