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

Revision 1726, 49.3 KB checked in by amuller, 14 years ago (diff)

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

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