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

Revision 1846, 48.6 KB checked in by amuller, 15 years ago (diff)

Ticket #597 - Melhoria do FM, tornando a programação des-orientada a objetos

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