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

Revision 1704, 55.6 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Melhorias na visualização do módulo fm com tema azul

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