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

Revision 1755, 49.0 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Melhorias no módulos gerenciador de arquivos do expresso livre

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