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

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