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

Revision 1750, 48.9 KB checked in by amuller, 15 years ago (diff)

Ticket #597 - melhoria 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
647                                // selectbox for change/move/and copy to
648                                $this->dirs=$this->all_other_directories();
649                                foreach($this->dirs as $elem)
650                                        $vars[folders].='<br><span onclick="load(\''.$elem['directory'].$elem['name'].'\')" class="l" onmouseover="this.style.border=\'1px solid black\'" onmouseout="this.style.border=\'1px solid transparent\'">'.$elem['name'].'</span>';
651                               
652
653                                $this->dirs=$this->all_other_directories();
654                                foreach($this->dirs as $dir)
655                                        if((($dir['directory'] . $dir['name']) != $this->path) && $this->bo->vfs->file_exists(array('string' => $dir['directory'] . $dir['name'],'relatives' => array(RELATIVE_NONE))))
656                                        {
657                                                //FIXME replace the html_form_option function
658                                                $dirs_options .= $this->html_form_option($dir['directory'] . $dir['name'], $dir['directory'] . $dir['name']);
659                                        }
660
661                                $toolbar.='<select name="todir" style="visibility:hidden">'.$dirs_options.'</select>';
662
663                                $vars[toolbar1]=$toolbar;
664
665                                if(count($this->messages)>0)
666                                {
667                                        foreach($this->messages as $msg)
668                                        {
669                                                $messages.='<span>'.$msg.'</span>';
670                                        }
671                                }
672                                $this->messages = NULL;
673                               
674                                $vars[messages]=$messages;
675
676                                $this->t->set_var($vars);
677                                $this->t->pparse('out','filemanager_header');
678                        }
679
680                        $this->t->set_var($vars);
681                        $this->t->pparse('out','filemanager_footer');
682
683                        $GLOBALS['phpgw']->common->phpgw_footer();
684                        $GLOBALS['phpgw']->common->phpgw_exit();
685                }
686
687                function readFilesInfo()
688                {
689                        // start files info
690
691                        # Read in file info from database to use in the rest of the script
692                        # $fakebase is a special directory.  In that directory, we list the user's
693                        # home directory and the directories for the groups they're in
694                        $this->numoffiles = 0;
695                        if($this->path == $this->bo->fakebase)
696                        {
697                                // FIXME this test can be removed
698                                if(!$this->bo->vfs->file_exists(array('string' => $this->bo->homedir, 'relatives' => array(RELATIVE_NONE))))
699                                {
700                                        $this->bo->vfs->mkdir(array('string' => $this->bo->homedir, 'relatives' => array(RELATIVE_NONE)));
701                                }
702
703                                $ls_array = $this->bo->vfs->ls(array(
704                                        'string' => $this->bo->homedir,
705                                        'relatives' => array(RELATIVE_NONE),
706                                        'checksubdirs' => False,
707                                        'nofiles' => True
708                                ));
709
710                                $this->files_array[] = $ls_array[0];
711                                $this->numoffiles++;
712
713                                reset($this->readable_groups);
714                                while(list($num, $group_array) = each($this->readable_groups))
715                                {
716                                        # If the group doesn't have access to this app, we don't show it
717                                        /*if(!$this->groups_applications[$group_array['account_name']][$this->bo->appname]['enabled'])
718                                        {
719                                                continue;
720                                        }
721                                        */
722
723
724                                        if(!$this->bo->vfs->file_exists(array('string' => $this->bo->fakebase.'/'.$group_array['account_name'],'relatives'      => array(RELATIVE_NONE))))
725                                        {
726                                                $this->bo->vfs->override_acl = 1;
727                                                $this->bo->vfs->mkdir(array(
728                                                        'string' => $this->bo->fakebase.'/'.$group_array['account_name'],
729                                                        'relatives' => array(RELATIVE_NONE)
730                                                ));
731
732                                                // FIXME we just created a fresh group dir so we know there nothing in it so we have to remove all existing content
733                                               
734                                               
735                                                $this->bo->vfs->override_acl = 0;
736
737                                                $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'])));
738                                        }
739
740                                        $ls_array = $this->bo->vfs->ls(array('string' => $this->bo->fakebase.'/'.$group_array['account_name'],'relatives'       => array(RELATIVE_NONE),'checksubdirs' => False,'nofiles' => True));
741
742                                        $this->files_array[] = $ls_array[0];
743
744                                        $this->numoffiles++;
745                                }
746                        }
747                        else
748                        {
749                                $ls_array = $this->bo->vfs->ls(array(
750                                        'string' => $this->path,
751                                        'relatives'     => array(RELATIVE_NONE),
752                                        'checksubdirs' => False,
753                                        'nofiles'       => False,
754                                        'orderby'       => $this->sortby
755                                ));
756
757                                while(list($num, $file_array) = each($ls_array))
758                                {
759                                        $this->numoffiles++;
760                                        $this->files_array[] = $file_array;
761                                }
762                        }
763
764                        if(!is_array($this->files_array))
765                        {
766                                $this->files_array = array();
767                        }
768                        // end file count
769                }
770
771                # Handle Moving Files and Directories
772                function moveTo()
773                {
774                        if(!$this->to)
775                        {
776                                $this->messages[] = lang('Error:').lang('Could not move file because no destination directory is given ', $this->disppath.'/'.$file);
777
778                        }
779                        else
780                        {
781                                $this->to = $this->bo->fakebase.'/'.$this->to;
782                                while(list($num, $file) = each($this->fileman))
783                                {
784                                        if($this->bo->vfs->mv(array(
785                                                'from'  => $this->from . '/' . $file,
786                                                'to'    => $this->to . '/' . $file,
787                                                'relatives'     => array(RELATIVE_NONE, RELATIVE_NONE)
788                                        )))
789                                        {
790                                                $moved++;
791                                                $this->messages[]=lang('Moved %1 to %2', $this->from . '/' . $file, $this->to . '/' . $file);
792                                        }
793                                        else
794                                        {
795                                                $this->messages[] = lang('Error:').lang('Could not move %1 to %2', $file, $this->to);
796                                        }
797                                }
798                        }
799
800                        if($moved)
801                        {
802                                $x=0;
803                        }
804
805                        $this->readFilesInfo();
806                        $this->filelisting();
807                }
808
809                // Handle Copying of Files and Directories
810                function copyTo()
811                {
812                        if(!$this->to)
813                        {
814                                $this->messages[] = lang('Error:').lang('Could not copy file because no destination directory is given ');
815
816                        }
817                        else
818                        {
819                                $this->to = $this->bo->fakebase.'/'.$this->to;
820                                while(list($num, $file) = each($this->fileman))
821                                {
822                                        if($this->bo->vfs->cp(array(
823                                                'from'  => $this->from . '/' . $file,
824                                                'to'    => $this->to . '/' . $file,
825                                                'relatives'     => array(RELATIVE_NONE, RELATIVE_NONE)
826                                        )))
827                                        {
828                                                $copied++;
829                                                $this->messages[] = lang('Copied %1 to %2', $this->disppath.'/'.$file, $this->to.'/'.$file);
830                                        }
831                                        else
832                                        {
833                                                $this->messages[] = lang('Error:').lang('Could not copy %1 to %2',$file , $this->to);
834                                        }
835                                }
836                        }
837                        if($copied)
838                       
839                        {
840                                $x=0;
841                        }
842
843                        $this->readFilesInfo();
844                        $this->filelisting();
845                }
846
847                function createdir()
848                {
849                        if($this->newdir_x && $this->newfile_or_dir)
850                        {
851                                if($this->bo->badchar = $this->bo->bad_chars($this->newfile_or_dir, True, True))
852                                {
853                                        $this->messages[]= lang('Error:').$this->bo->html_encode(lang('Directory names cannot contain "%1"', $badchar), 1);
854                                }
855
856                                /* TODO is this right or should it be a single $ ? */
857                                if($$this->newfile_or_dir[strlen($this->newfile_or_dir)-1] == ' ' || $this->newfile_or_dir[0] == ' ')
858                                {
859                                        $this->messages[]= lang('Error:').lang('Cannot create directory because it begins or ends in a space');
860                                }
861
862                                $ls_array = $this->bo->vfs->ls(array(
863                                        'string'        => $this->path . '/' . $this->newfile_or_dir,
864                                        'relatives'     => array(RELATIVE_NONE),
865                                        'checksubdirs'  => False,
866                                        'nofiles'       => True
867                                ));
868
869                                $fileinfo = $ls_array[0];
870
871                                if($fileinfo['name'])
872                                {
873                                        if($fileinfo['mime_type'] != 'Directory')
874                                        {
875                                                $this->messages[]= lang('Error:').lang('%1 already exists as a file',$fileinfo['name']);
876                                        }
877                                        else
878                                        {
879                                                $this->messages[]= lang('Error:').lang('Directory %1 already exists', $fileinfo['name']);
880                                        }
881                                }
882                                else
883                                {
884                                        if($this->bo->vfs->mkdir(array('string' => $this->newfile_or_dir)))
885                                        {
886                                                $this->messages[]=lang('Created directory %1', $this->disppath.'/'.$this->newfile_or_dir);
887                                        }
888                                        else
889                                        {
890                                                $this->messages[]=lang('Error:').lang('Could not create %1', $this->disppath.'/'.$this->newfile_or_dir);
891                                        }
892                                }
893
894                                $this->readFilesInfo();
895                                $this->filelisting();
896                        }
897                }
898                function getReturnExecuteForm(){
899                        $response = $_SESSION['response'];
900                        $_SESSION['response'] = null;
901                        echo $response;
902                        return;
903                }
904                function showUploadboxes()
905                {
906                        $this->t->set_file(array('upload' => 'upload.tpl'));
907                        $this->t->set_block('upload','upload_header','upload_header');
908                        $this->t->set_block('upload','row','row');
909                        $this->t->set_block('upload','upload_footer','upload_footer');
910
911                        if($this->path != '/' && $this->path != $this->bo->fakebase && $this->can_add)
912                        {
913                                $vars[max_size]=lang('Note: Uploaded is limited to %1MB',($this->current_config['filemanager_Max_file_size']));
914                                $vars[form_action]=$GLOBALS[phpgw]->link('/filemanager/inc/upload.php');
915                                //$vars[form_action]=$GLOBALS[phpgw]->link('/index.php','menuaction=filemanager.uifilemanager.index');
916                                $vars[path]=$this->path;
917                                $vars[lang_file]=lang('File');
918                                $vars[lang_comment]=lang('Comment');
919                                $vars[num_upload_boxes]=1;
920                                $this->t->set_var($vars);
921                                $this->t->pparse('out','upload_header');
922
923                                $this->t->set_var('row_tr_color',$tr_color);
924                                $this->t->parse('rows','row');
925                                $this->t->pparse('out','row');
926
927                                $vars[lang_upload]=lang('Upload files');
928                                $vars[change_upload_boxes].=lang('Show') . '&nbsp;';
929                                $this->t->set_var($vars);
930                                $this->t->pparse('out','upload_footer');
931                        }
932                }
933
934                /* create textfile */
935                function createfile()
936                {
937                        $this->filename=$this->newfile_or_dir;
938                        if($this->filename)
939                        {
940                                if($badchar = $this->bo->bad_chars($this->filename, True, True))
941                                {
942                                        $this->messages[] = lang('Error:').lang('File names cannot contain "%1"',$badchar);
943
944                                        $this->fileListing();
945                                }
946
947                                if($this->bo->vfs->file_exists(array(
948                                        'string'=> $this->filename,
949                                        'relatives'     => array(RELATIVE_ALL)
950                                )))
951                                {
952                                        $this->messages[]= lang('Error:').lang('File %1 already exists. Please edit it or delete it first.', $this->filename);
953                                        $this->fileListing();
954                                }
955
956                                if($this->bo->vfs->touch(array(
957                                        'string'        => $this->filename,
958                                        'relatives'     => array(RELATIVE_ALL)
959                                )))
960                                {
961                                        $this->edit = 1;
962                                        $this->numoffiles++;
963                                        $this->edit();
964                                }
965                                else
966                                {
967                                        $this->messages[]= lang('Error:').lang('File %1 could not be created.', $this->filename);
968                                        $this->fileListing();
969                                }
970                        }
971                }
972
973                # Handle Editing files
974                function edit()
975                {
976                        if($this->filename)
977                        {
978                                if (! $this->vfs_functions->verifyLock($this->path.'/'.$this->filename,RELATIVE_NONE)){
979                                        $GLOBALS['phpgw']->redirect('/index.php');
980                                }
981                                $ls_array = $this->bo->vfs->ls(array(
982                                        'string'        => $this->path.'/'.$this->filename,
983                                        'relatives'     => array(RELATIVE_NONE),
984                                        'checksubdirs'  => False,
985                                        'nofiles'       => True
986                                ));
987                                $this->bo->vfs->touch(array(
988                                        'string'=> $this->path.'/'.$this->filename,
989                                        'relatives'     => array(RELATIVE_NONE)
990                                ));
991
992
993                                if($ls_array[0]['mime_type'])
994                                {
995                                        $mime_type = $ls_array[0]['mime_type'];
996                                }
997                                elseif($this->prefs['viewtextplain'])
998                                {
999                                        $mime_type = 'text/plain';
1000                                }
1001                                $editable = array('','text/plain','text/csv','text/html','text/text','message/rfc822');
1002
1003                                if(!in_array($mime_type,$editable)){
1004                                        $this->messages[] = lang('Error:').lang('Impossible to edit this file');
1005                                        $this->readFilesInfo();
1006                                        $this->fileListing();
1007                                        return;
1008                                }
1009                        }
1010
1011                        $this->readFilesInfo();
1012
1013                        if ($mime_type == 'text/html')
1014                                $this->t->set_file(array('filemanager_edit' => 'edit_html.tpl'));
1015                        else
1016                                $this->t->set_file(array('filemanager_edit' => 'edit_file.tpl'));
1017
1018                        $this->t->set_block('filemanager_edit','row','row');
1019
1020
1021                        $vars[refresh_script] = "<script src='filemanager/js/refresh.js'></script>";
1022
1023                        $vars[preview_content]='';
1024                        if($this->edit_file)
1025                        {
1026                                $this->edit_file_content = stripslashes($this->edit_file_content);
1027                        }
1028
1029                        if($this->edit_preview_x)
1030                        {
1031                                $content = $this->edit_file_content;
1032
1033                                $vars[lang_preview_of]=lang('Preview of %1', $this->path.'/'.$edit_file);
1034
1035                                $vars[preview_content]=nl2br($content);
1036                        }
1037                        elseif($this->edit_save_x || $this->edit_save_done_x)
1038                        {
1039                                $content = $this->edit_file_content;
1040                                //die( $content);
1041                                if($this->bo->vfs->write(array(
1042                                        'string'        => $this->path.'/'.$this->edit_file,
1043                                        'relatives'     => array(RELATIVE_NONE),
1044                                        'content'       => $content
1045                                )))
1046                                {
1047                                        $this->messages[]=lang('Saved %1', $this->path.'/'.$this->edit_file);
1048
1049                                        if($this->edit_save_done_x)
1050                                        {
1051                                                $this->readFilesInfo();
1052                                                $this->fileListing();
1053                                                exit;
1054                                        }
1055                                }
1056                                else
1057                                {
1058                                        $this->messages[]=lang('Could not save %1', $this->path.'/'.$this->edit_file);
1059                                }
1060                        }
1061
1062                        # If we're in preview or save mode, we only show the file
1063                        # being previewed or saved
1064                        if($this->edit_file &&($this->filename != $this->edit_file))
1065                        {
1066                                continue;
1067                        }
1068
1069                        if($this->filename && $this->bo->vfs->file_exists(array(
1070                                'string'        => $this->filename,
1071                                'relatives'     => array(RELATIVE_ALL)
1072                        )))
1073                        {
1074                                if($this->edit_file)
1075                                {
1076                                        $content = stripslashes($this->edit_file_content);
1077                                }
1078                                else
1079                                {
1080                                        $content = $this->bo->vfs->read(array('string' => $this->filename));
1081                                }
1082                                $vars[form_action]= $GLOBALS['phpgw']->link('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->path);
1083                                $vars[edit_file]=$this->filename;
1084                                # We need to include all of the fileman entries for each file's form,
1085                                # so we loop through again
1086                                for($i = 0; $i != $this->numoffiles; $i++)
1087                                {
1088                                        if($this->filename) $value='value="'.$this->filename.'"';
1089                                        $vars[filemans_hidden]='<input type="hidden" name="filename" '.$value.' />';
1090                                }
1091                                $vars[file_content]=$content;
1092
1093                                $vars[buttonPreview]=$this->inputButton('edit_preview','edit_preview',lang('Preview %1', $this->bo->html_encode($this->fileman[$j], 1)));
1094                                $vars[buttonSave]=$this->inputButton('edit_save','save',lang('Save %1', $this->bo->html_encode($this->filename, 1)));
1095                                $vars[buttonDone]=$this->inputButton('edit_save_done','ok',lang('Save %1, and go back to file listing ', $this->bo->html_encode($this->filename, 1)));
1096                                $vars[buttonCancel]=$this->inputButton('edit_cancel','cancel',lang('Cancel editing %1 without saving', $this->bo->html_encode($this->filename, 1)));
1097
1098                                if ($mime_type == 'text/html'){
1099                                        $vars[fck_edit] = '<script type="text/javascript" src="filemanager/tp/ckeditor/ckeditor.js"></script>
1100                                                <textarea cols="80" id="edit_file_content" name="edit_file_content" rows="10">'.$content.'</textarea>
1101                                                <script type="text/javascript"> CKEDITOR.replace( \'edit_file_content\',{
1102removePlugins : \'elementspath\',
1103skin : \'office2003\',
1104toolbar : [["Source","Preview","-","Cut","Copy","Paste","-","Print",
1105"Undo","Redo","-","Find","Replace","-","SelectAll" ],
1106["Table","HorizontalRule","Smiley","SpecialChar","PageBreak","-","Bold",
1107"Italic","Underline","Strike","-","Subscript","Superscript",
1108"NumberedList","BulletedList","-","Outdent","Indent","Blockquote",
1109"JustifyLeft","JustifyCenter","JustifyRight","JustifyBlock",
1110"Link", "TextColor","BGColor","Maximize"],
1111["Styles","Format","Font","FontSize"]]
1112                                });</script>';
1113
1114                                }
1115
1116
1117                                $this->t->set_var($vars);
1118                                $this->t->parse('rows','row');
1119                                $this->t->pparse('out','row');
1120
1121                        }
1122
1123                }
1124
1125                function history()
1126                {
1127                        if($this->file) // FIXME this-file is never defined
1128                        {
1129                                $journal_array = $this->bo->vfs->get_journal(array(
1130                                        'string'        => $this->file,//FIXME
1131                                        'relatives'     => array(RELATIVE_ALL)
1132                                ));
1133
1134                                if(is_array($journal_array))
1135                                {
1136                                        $this->html_table_begin();
1137                                        $this->html_table_row_begin();
1138                                        $this->html_table_col_begin();
1139                                        echo lang('Date');
1140                                        $this->html_table_col_end();
1141                                        $this->html_table_col_begin();
1142                                        echo lang('Version');
1143                                        $this->html_table_col_end();
1144                                        $this->html_table_col_begin();
1145                                        echo lang('Who');
1146                                        $this->html_table_col_end();
1147                                        $this->html_table_col_begin();
1148                                        echo lang('Operation');
1149                                        $this->html_table_col_end();
1150                                        $this->html_table_row_end();
1151
1152                                        while(list($num, $journal_entry) = each($journal_array))
1153                                        {
1154                                                $this->html_table_row_begin();
1155                                                $this->html_table_col_begin();
1156                                                $this->bo->html_text($journal_entry['created'] . '&nbsp;&nbsp;&nbsp;');
1157                                                $this->html_table_col_end();
1158                                                $this->html_table_col_begin();
1159                                                $this->bo->html_text($journal_entry['version'] . '&nbsp;&nbsp;&nbsp;' );
1160                                                $this->html_table_col_end();
1161                                                $this->html_table_col_begin();
1162                                                $this->bo->html_text($GLOBALS['phpgw']->accounts->id2name($journal_entry['owner_id']) . '&nbsp;&nbsp;&nbsp;');
1163                                                $this->html_table_col_end();
1164                                                $this->html_table_col_begin();
1165                                                $this->bo->html_text($journal_entry['comment']);
1166                                                $this->html_table_col_end();
1167                                        }
1168
1169                                        $this->html_table_end();
1170                                        $GLOBALS['phpgw']->common->phpgw_footer();
1171                                        $GLOBALS['phpgw']->common->phpgw_exit();
1172                                }
1173                                else
1174                                {
1175                                        echo lang('No version history for this file/directory');
1176                                }
1177                        }
1178                }
1179                function view()
1180                {
1181                        if (!$this->bo->vfs->acl_check(array(
1182                                'string'        => $this->path,
1183                                'relatives'     => array(RELATIVE_NONE),
1184                                'operation'     => PHPGW_ACL_READ
1185                        )))
1186                        {
1187                                $this->messages[] = lang("You have no permission to access this file");
1188                                header('Location:'.$this->encode_href('inc/index.php?menuaction=filemanager.uifilemanager.index','&path='.base64_encode($this->bo->homedir)));
1189
1190                                return;
1191                        }
1192                        if($this->file) //FIXME
1193                        {
1194                                $ls_array = $this->bo->vfs->ls(array(
1195                                        'string'        => $this->path.'/'.$this->file,//FIXME
1196                                        'relatives'     => array(RELATIVE_NONE),
1197                                        'checksubdirs'  => False,
1198                                        'nofiles'       => True
1199                                ));
1200                                if($ls_array[0]['mime_type'])
1201                                {
1202                                        $mime_type = $ls_array[0]['mime_type'];
1203                                }
1204                                elseif($this->prefs['viewtextplain'])
1205                                {
1206                                        $mime_type = 'text/plain';
1207                                }
1208                                $viewable = array('','text/plain','text/csv','text/html',
1209                                        'text/text','image/jpeg','image/png','image/gif');
1210
1211                                if(in_array($mime_type,$viewable) || $ls_array[0]['size'] < 10240)
1212                                {
1213                                        /*Note: if you put application/octet-stream you force download */
1214                                        header('Content-type: ' . $mime_type);
1215                                        header('Content-disposition: filename="' . addslashes($this->file) . '"');
1216                                        Header("Pragma: public");
1217                                        echo $this->bo->vfs->read(array(
1218                                                'string'    => $this->path.'/'.$this->file,//FIXME
1219                                                'relatives'    => array(RELATIVE_NONE)
1220                                        ));
1221
1222                                }
1223                                else
1224                                {
1225                                        $GLOBALS['phpgw']->browser->content_header($this->file,$mime_type,$ls_array[0]['size']);
1226                                        $this->bo->vfs->print_content(array(
1227                                                'string' => $this->path.'/'.$this->file,
1228                                                'relatives' => array(RELATIVE_NONE)
1229                                                )
1230                                        );
1231                                }
1232                                $GLOBALS['phpgw']->common->phpgw_exit();
1233                        }
1234                }
1235
1236                function export(){
1237                        if($this->file)
1238                        {
1239                                $ls_array = $this->bo->vfs->ls(array(
1240                                        'string'        => $this->path.'/'.$this->file,
1241                                        'relatives'     => array(RELATIVE_NONE),
1242                                        'checksubdirs'  => False,
1243                                        'nofiles'       => True
1244                                ));
1245                                /*$timestamp = $this->vfs_functions->dateString2timeStamp($ls_array[0]['modified']);
1246                                if (time() - $timestamp < 60 && $ls_array[0]['modifiedby_id'] != $GLOBALS['phpgw_info']['user']['account_id']);
1247                                {
1248                                        // recently than last minute: someone is editing
1249                                }*/
1250                                $mime_type = $ls_array[0]['mime_type'];
1251                                $formats = array('text/html');
1252                                if(!in_array($mime_type,$formats)){
1253                                        echo lang('Impossible to export this file');
1254                                        return False;
1255                                }
1256                                $content = $this->bo->vfs->read(array('string' => $this->path.'/'.$this->file,
1257                                               'relatives'     => array(RELATIVE_NONE)
1258                                       ));
1259
1260                                include_once('filemanager/tp/dompdf/dompdf_config.inc.php');
1261                                $dompdf = new DOMPDF();
1262                                $dompdf->load_html($content);
1263                                $dompdf->set_paper($this->prefs['pdf_paper_type'], $this->prefs['pdf_type']);
1264                                /* Would be nice to implement 'Title','Subject','Author','Creator','CreationDate'*/
1265                                $dompdf->render();
1266                                $dompdf->stream(strtok($this->file,'.').".pdf");
1267                                $GLOBALS['phpgw']->common->phpgw_exit();
1268                        }
1269                }
1270
1271                //give back an array with all directories except current and dirs that are not accessable
1272                function all_other_directories()
1273                {
1274                        # First we get the directories in their home directory
1275                        $dirs = array();
1276                        $dirs[] = array('directory' => $this->bo->fakebase, 'name' => $this->bo->userinfo['account_lid']);
1277
1278                        $tmp_arr=array(
1279                                'string'        => $this->bo->homedir,
1280                                'relatives'     => array(RELATIVE_NONE),
1281                                'checksubdirs'  => True,
1282                                'mime_type'     => 'Directory'
1283                        );
1284
1285                        $ls_array = $this->bo->vfs->ls($tmp_arr);
1286
1287                        while(list($num, $dir) = each($ls_array))
1288                        {
1289                                $dirs[] = $dir;
1290                        }
1291
1292
1293                        # Then we get the directories in their readable groups' home directories
1294                        reset($this->readable_groups);
1295                        while(list($num, $group_array) = each($this->readable_groups))
1296                        {
1297                                /* Don't list directories for groups that don't have access
1298                                if(!$this->groups_applications[$group_array['account_name']][$this->bo->appname]['enabled'])
1299                                {
1300]                                       continue;
1301                                }*/
1302
1303                                $dirs[] = array('directory' => $this->bo->fakebase, 'name' => $group_array['account_name']);
1304
1305                                $tmp_arr=array(
1306                                        'string'        => $this->bo->fakebase.'/'.$group_array['account_name'],
1307                                        'relatives'     => array(RELATIVE_NONE),
1308                                        'checksubdirs'  => True,
1309                                        'mime_type'     => 'Directory'
1310                                );
1311
1312                                $ls_array = $this->bo->vfs->ls($tmp_arr);
1313                                while(list($num, $dir) = each($ls_array))
1314                                {
1315                                        $dirs[] = $dir;
1316                                }
1317                        }
1318                        reset($dirs);
1319                        while(list($num, $dir) = each($dirs))
1320                        {
1321                                if(!$dir['directory'])
1322                                {
1323                                        continue;
1324                                }
1325
1326                                # So we don't display //
1327                                if($dir['directory'] != '/')
1328                                {
1329                                        $dir['directory'] .= '/';
1330                                }
1331                                $return[] = $dir;
1332                        }
1333                        return $return;
1334                }
1335
1336                function update_groups()
1337                {
1338                        # Get their readable groups to be used throughout the script
1339                        $acl = array();
1340                        $groups = array();
1341                        $acl = $GLOBALS['phpgw']->acl->get_ids_for_location($GLOBALS['phpgw_info']['user']['account_id'],1,'filemanager');
1342                        if (is_array($acl))
1343                                foreach($acl as $key => $value){
1344                                        $info = array();
1345                                        $info = $GLOBALS['phpgw']->accounts->get_account_data($value);
1346                                        $groups[$key]['account_id'] = $value;
1347                                        $groups[$key]['account_lid'] = $info[$value]['lid'];
1348                                        $groups[$key]['account_name'] = $info[$value]['firstname'];
1349                                        $groups[$key]['account_lastname'] = $info[$value]['lastname'];
1350                                        $groups[$key]['account_fullname'] = $info[$value]['fullname'];
1351                                }
1352                        $this->readable_groups = array();
1353                        while(list($num, $account) = each($groups))
1354                        {
1355                                if($this->bo->vfs->acl_check(array('owner_id' => $account['account_id'],'operation' => PHPGW_ACL_READ)))
1356                                {
1357                                        $this->readable_groups[$account['account_lid']] = Array('account_id' => $account['account_id'], 'account_name' => $account['account_lid']);
1358                                }
1359                        }
1360
1361                }
1362                function search()
1363                {
1364                        /* TODO this is a primitive search */
1365                        $this->update_groups();
1366                        $this->dirs = $this->all_other_directories();
1367                        $path = $this->path;
1368                        if (strlen($this->text) > 3)
1369                        {                                                               
1370                                $this->text = strtoupper($this->text);
1371                                foreach($this->dirs as $elem)
1372                                {
1373                                        $this->path = $elem['directory'].$elem['name'];
1374                                        reset($this->files_array);
1375                                        $this->readFilesInfo();
1376                                        for($i = 0; $i < count($this->files_array); $i++)
1377                                        {
1378                                                $comment = strtoupper($this->files_array[$i]['comment']);
1379                                                $name = strtoupper($this->files_array[$i]['name']);
1380                                                if (strstr($name,$this->text) ||
1381                                                strstr($comment,$this->text) ){
1382                                                        $return[$this->files_array[$i]['directory'].$name] = $this->files_array[$i];
1383                                                        $return[$this->files_array[$i]['directory'].$name]['icon'] = $this->mime_icon($this->files_array[$i]['mime_type']);
1384                                                }
1385                                        }
1386                                        if (count($return) > 50)
1387                                        {
1388                                                $return = array_slice($return,0,50);
1389                                                break;
1390                                        }
1391                                }       
1392                        }
1393                        echo serialize(array_values($return));
1394                }
1395
1396                /* seek icon for mimetype else return an unknown icon */
1397                function mime_icon($mime_type, $size=16)
1398                {
1399                        if(!$mime_type) $mime_type='unknown';
1400
1401                        $mime_type=str_replace  ('/','_',$mime_type);
1402
1403                        $img=$GLOBALS['phpgw']->common->image('filemanager','mime'.$size.'_'.strtolower($mime_type));
1404                        if(!$img) $img=$GLOBALS['phpgw']->common->image('filemanager','mime'.$size.'_unknown');
1405
1406                        return $img;
1407                }
1408
1409                function toolButton($link,$img='',$description='')
1410                {
1411                        $image=$GLOBALS['phpgw']->common->image('filemanager','button_'.strtolower($img));
1412
1413                        if($img)
1414                        {
1415                                return '<span name="'.$link.'" class="toolButton" onclick="toolbar.control(\''.$link.'\');" title="'.$description.'"><img src="'.$image.'" alt="'.$description.'"/></a><small>'.$description.'</small></span>';
1416                        }
1417                }
1418
1419                function inputButton($name,$img='',$description='')
1420                {
1421                        $image=$GLOBALS['phpgw']->common->image('filemanager','button_'.strtolower($img));
1422
1423                        if($img)
1424                        {
1425                                return '<td class="" align="center" valign="middle" height="28" width="70">
1426                                <input title="'.$description.'" name="'.$name.'" type="image" alt="'.$name.'" src="'.$image.'" value="clicked" /><br><small>'.$description.'</small>
1427                                </td>';
1428                        }
1429                }
1430
1431
1432                function html_form_input($type = NULL, $name = NULL, $value = NULL, $maxlength = NULL, $size = NULL, $checked = NULL, $string = '', $return = 1)
1433                {
1434                        $text = ' ';
1435                        if($type != NULL && $type)
1436                        {
1437                                if($type == 'checkbox')
1438                                {
1439                                        $value = $this->bo->string_encode($value, 1);
1440                                }
1441                                $text .= 'type="'.$type.'" ';
1442                        }
1443                        if($name != NULL && $name)
1444                        {
1445                                $text .= 'name="'.$name.'" ';
1446                        }
1447                        if($value != NULL && $value)
1448                        {
1449                                $text .= 'value="'.$value.'" ';
1450                        }
1451                        if(is_int($maxlength) && $maxlength >= 0)
1452                        {
1453                                $text .= 'maxlength="'.$maxlength.'" ';
1454                        }
1455                        if(is_int($size) && $size >= 0)
1456                        {
1457                                $text .= 'size="'.$size.'" ';
1458                        }
1459                        if($checked != NULL && $checked)
1460                        {
1461                                $text .= 'checked ';
1462                        }
1463
1464                        return '<input'.$text.$string.'>';
1465                }
1466
1467                function html_form_option($value = NULL, $displayed = NULL, $selected = NULL, $return = 0)
1468                {
1469                        $text = ' ';
1470                        if($value != NULL && $value)
1471                        {
1472                                $text .= ' value="'.$value.'" ';
1473                        }
1474                        if($selected != NULL && $selected)
1475                        {
1476                                $text .= ' selected';
1477                        }
1478                        return  '<option'.$text.'>'.$displayed.'</option>';
1479                }
1480
1481                function encode_href($href = NULL, $args = NULL , $extra_args)
1482                {
1483                        $href = $this->bo->string_encode($href, 1);
1484                        $all_args = $args.'&'.$this->bo->string_encode($extra_args, 1);
1485
1486                        $address = $GLOBALS['phpgw']->link($href, $all_args);
1487
1488                        return $address;
1489                }
1490
1491                function html_link($href = NULL, $args = NULL , $extra_args, $text = NULL, $return = 1, $encode = 1, $linkonly = 0, $target = NULL)
1492                {
1493                        //      unset($encode);
1494                        if($encode)
1495                        {
1496                                $href = $this->bo->string_encode($href, 1);
1497                                $all_args = $args.'&'.$this->bo->string_encode($extra_args, 1);
1498                        }
1499                        else
1500                        {
1501                                //                              $href = $this->bo->string_encode($href, 1);
1502                                $all_args = $args.'&'.$extra_args;
1503                        }
1504                        ###
1505                        # This decodes / back to normal
1506                        ###
1507                        //                      $all_args = preg_replace("/%2F/", "/", $all_args);
1508                        //                      $href = preg_replace("/%2F/", "/", $href);
1509
1510                        /* Auto-detect and don't disturb absolute links */
1511                        if(!preg_match("|^http(.{0,1})://|", $href))
1512                        {
1513                                //Only add an extra / if there isn't already one there
1514
1515                                // die(SEP);
1516                                if(!($href[0] == SEP))
1517                                {
1518                                        $href = SEP . $href;
1519                                }
1520
1521                                /* $phpgw->link requires that the extra vars be passed separately */
1522                                //                              $link_parts = explode("?", $href);
1523                                $address = $GLOBALS['phpgw']->link($href, $all_args);
1524                                //                              $address = $GLOBALS['phpgw']->link($href);
1525                        }
1526                        else
1527                        {
1528                                $address = $href;
1529                        }
1530
1531                        /* If $linkonly is set, don't add any HTML */
1532                        if($linkonly)
1533                        {
1534                                $rstring = $address;
1535                        }
1536                        else
1537                        {
1538                                if($target)
1539                                {
1540                                        $target = 'target='.$target;
1541                                }
1542
1543                                $text = trim($text);
1544                                $rstring = '<a href="'.$address.'" '.$target.'>'.$text.'</a>';
1545                        }
1546
1547                        return($this->bo->eor($rstring, $return));
1548                }
1549
1550                function html_table_begin($width = NULL, $border = NULL, $cellspacing = NULL, $cellpadding = NULL, $rules = NULL, $string = '', $return = 0)
1551                {
1552                        if($width != NULL && $width)
1553                        {
1554                                $width = "width=$width";
1555                        }
1556                        if(is_int($border) && $border >= 0)
1557                        {
1558                                $border = "border=$border";
1559                        }
1560                        if(is_int($cellspacing) && $cellspacing >= 0)
1561                        {
1562                                $cellspacing = "cellspacing=$cellspacing";
1563                        }
1564                        if(is_int($cellpadding) && $cellpadding >= 0)
1565                        {
1566                                $cellpadding = "cellpadding=$cellpadding";
1567                        }
1568                        if($rules != NULL && $rules)
1569                        {
1570                                $rules = "rules=$rules";
1571                        }
1572
1573                        $rstring = "<table $width $border $cellspacing $cellpadding $rules $string>";
1574                        return($this->bo->eor($rstring, $return));
1575                }
1576
1577                function html_table_end($return = 0)
1578                {
1579                        $rstring = "</table>";
1580                        return($this->bo->eor($rstring, $return));
1581                }
1582
1583                function html_table_row_begin($align = NULL, $halign = NULL, $valign = NULL, $bgcolor = NULL, $string = '', $return = 0)
1584                {
1585                        if($align != NULL && $align)
1586                        {
1587                                $align = "align=$align";
1588                        }
1589                        if($halign != NULL && $halign)
1590                        {
1591                                $halign = "halign=$halign";
1592                        }
1593                        if($valign != NULL && $valign)
1594                        {
1595                                $valign = "valign=$valign";
1596                        }
1597                        if($bgcolor != NULL && $bgcolor)
1598                        {
1599                                $bgcolor = "bgcolor=$bgcolor";
1600                        }
1601                        $rstring = "<tr $align $halign $valign $bgcolor $string>";
1602                        return($this->bo->eor($rstring, $return));
1603                }
1604
1605                function html_table_row_end($return = 0)
1606                {
1607                        $rstring = "</tr>";
1608                        return($this->bo->eor($rstring, $return));
1609                }
1610
1611                function html_table_col_begin($align = NULL, $halign = NULL, $valign = NULL, $rowspan = NULL, $colspan = NULL, $string = '', $return = 0)
1612                {
1613                        if($align != NULL && $align)
1614                        {
1615                                $align = "align=$align";
1616                        }
1617                        if($halign != NULL && $halign)
1618                        {
1619                                $halign = "halign=$halign";
1620                        }
1621                        if($valign != NULL && $valign)
1622                        {
1623                                $valign = "valign=$valign";
1624                        }
1625                        if(is_int($rowspan) && $rowspan >= 0)
1626                        {
1627                                $rowspan = "rowspan=$rowspan";
1628                        }
1629                        if(is_int($colspan) && $colspan >= 0)
1630                        {
1631                                $colspan = "colspan=$colspan";
1632                        }
1633
1634                        $rstring = "<td $align $halign $valign $rowspan $colspan $string>";
1635                        return($this->bo->eor($rstring, $return));
1636                }
1637
1638                function html_table_col_end($return = 0)
1639                {
1640                        $rstring = "</td>";
1641                        return($this->bo->eor($rstring, $return));
1642                }
1643        }
Note: See TracBrowser for help on using the repository browser.