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

Revision 1727, 48.7 KB checked in by amuller, 15 years ago (diff)

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

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