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

Revision 1879, 48.6 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Melhoria do FM. melhorias na interface, criação de pastas

  • 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                        'get_folders_list' => True,
34                        'showUploadboxes' => True,
35                        'createdir' => True,
36                        'removedir' => True,
37                        'uploadModel'=>True
38                );
39
40                //keep
41                var $bo;
42                var $vfs_functions;
43                var $t; //template object
44                var $dispath;
45                var $cwd;
46                var $lesspath;
47                var $readable_groups;
48                var $files_array;
49                var $numoffiles;
50                var $dispsep;
51
52                var $target;
53
54                var $prefs;//array
55
56                var $groups_applications;
57
58                var $current_config;
59                var $dirs;
60                var $to;
61                var $changedir; // for switching dir.
62                var $cdtodir; // for switching dir.
63                var $newfile_or_dir;
64                var $newfile_x;
65                var $createfile_var;
66                var $move_to_x;
67                var $copy_to_x;
68                var $edit_x;
69                var $edit_file;
70                var $edit_preview_x;
71                var $edit_save_x;
72                var $edit_save_done_x;
73                var $edit_cancel_x;
74
75                // this ones must be checked thorougly;
76                var $fileman = Array();
77                //var $fileman;
78                var $path;
79                var $file; // FIXME WHERE IS THIS FILLED?
80                var $sortby;
81                var $messages;
82
83                var $now;
84
85                function uifilemanager()
86                {
87                        $this->messages = &$_SESSION['phpgw_info']['filemanager']['user']['messages'];
88
89                        $GLOBALS['phpgw']->browser = CreateObject('phpgwapi.browser');
90
91                        $this->now = date('Y-m-d');
92
93                        $this->bo = CreateObject('filemanager.bofilemanager');
94
95                        $this->vfs_functions = CreateObject('filemanager.vfs_functions');
96
97                        $this->t = $GLOBALS['phpgw']->template;
98                        $c = CreateObject('phpgwapi.config','filemanager');
99                        $c->read_repository();
100                        $this->current_config = $c->config_data;
101
102
103                        // here local vars are created from the HTTP vars
104                        @reset($GLOBALS['HTTP_POST_VARS']);
105                        while(list($name,) = @each($GLOBALS['HTTP_POST_VARS']))
106                        {
107                                $this->$name = $GLOBALS['HTTP_POST_VARS'][$name];
108                        }
109
110                        @reset($GLOBALS['HTTP_GET_VARS']);
111                        while(list($name,) = @each($GLOBALS['HTTP_GET_VARS']))
112                        {
113                                $$name = $GLOBALS['HTTP_GET_VARS'][$name];
114                                $this->$name = $GLOBALS['HTTP_GET_VARS'][$name];
115
116                        }
117
118                        $to_decode = array
119                        (
120                                'op'    => array('op' => ''),
121                                'path'  => array('path' => ''),
122                                'filename' => array('filename' => ''),
123                                'file'  => array('file' => ''),
124                                'sortby'        => array('sortby' => ''),
125                                'messages'      => array('messages'     => ''),
126                                'show_upload_boxes'     => array('show_upload_boxes' => ''),
127                                'from'  =>      array('from' => ''),
128                                'to' => array('to' => '')
129
130                        );
131
132                        reset($to_decode);
133                        while(list($var, $conditions) = each($to_decode))
134                        {
135                                while(list($condvar, $condvalue) = each($conditions))
136                                {
137                                        if(isset($$condvar) && ($condvar == $var || $$condvar == $condvalue))
138                                        {
139                                                if(is_array($$var))
140                                                {
141                                                        $temp = array();
142                                                        while(list($varkey, $varvalue) = each($$var))
143                                                        {
144                                                                if(is_int($varkey))
145                                                                {
146                                                                        $temp[$varkey] = stripslashes(base64_decode(urldecode(($varvalue))));
147                                                                }
148                                                                else
149                                                                {
150                                                                        $temp[stripslashes(base64_decode(urldecode(($varkey))))] = $varvalue;
151                                                                }
152                                                        }
153                                                        $this->$var = $temp;
154                                                }
155                                                elseif(isset($$var))
156                                                {
157                                                        $this->$var = stripslashes(base64_decode(urldecode($$var)));
158                                                }
159                                        }
160                                }
161                        }
162
163                        // get appl. and user prefs
164                        $pref = CreateObject('phpgwapi.preferences', $this->bo->userinfo['username']);
165                        $pref->read_repository();
166                        //$GLOBALS['phpgw']->hooks->single('add_def_pref', $GLOBALS['appname']);
167                        $pref->save_repository(True);
168                        $pref_array = $pref->read_repository();
169                        $this->prefs = $pref_array[$this->bo->appname]; //FIXME check appname var in _debug_array
170
171                        //always show name
172
173                        $this->prefs[name] =1;
174
175
176                        if($this->prefs['viewinnewwin'])
177                        {
178                                $this->target = '_blank';
179                        }
180
181
182                        /*
183                                Check for essential directories
184                                admin must be able to disable these tests
185                        */
186                       
187                        // check if basedir exist
188                        $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
189                        if($test[mime_type]!='Directory')
190                        {
191                                die('Base directory does not exist, Ask adminstrator to check the global configuration.');
192                        }
193
194                        $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->fakebase, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
195                        if($test[mime_type]!='Directory')
196                        {
197
198                                $this->bo->vfs->override_acl = 1;
199
200                                $this->bo->vfs->mkdir(array(
201                                        'string' => $this->bo->fakebase,
202                                        'relatives' => array(RELATIVE_NONE)
203                                ));
204                               
205                                $this->bo->vfs->override_acl = 0;
206
207                                //test one more time
208                                $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->fakebase, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
209
210                                if($test[mime_type]!='Directory')
211                                {
212                                        die('Fake Base directory does not exist and could not be created, please ask the administrator to check the global configuration.');
213                                }
214                                else
215                                {
216                                        $this->messages[]= lang('Fake Base Dir did not exist, created a new one.');
217                                }
218                        }
219
220                        $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->homedir, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
221                        if($test[mime_type]!='Directory')
222                        {
223                                $this->bo->vfs->override_acl = 1;
224
225                                $this->bo->vfs->mkdir(array(
226                                        'string' => $this->bo->homedir,
227                                        'relatives' => array(RELATIVE_NONE)
228                                ));
229                                $this->bo->vfs->set_quota(array(
230                                        'string' => $this->bo->homedir,
231                                        'relatives' => array(RELATIVE_NONE),
232                                        'new_quota' => $this->current_config['filemanager_quota_size']
233                                ));
234       
235                                $this->bo->vfs->override_acl = 0;
236
237                                //test one more time
238                                $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->homedir, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
239
240                                if($test[mime_type]!='Directory')
241                                {
242                                        die('Your Home Dir does not exist and could not be created, please ask the adminstrator to check the global configuration.');
243                                }
244                                else
245                                {
246                                        $this->messages[]= lang('Your Home Dir did not exist, eGroupWare created a new one.');
247                                        // FIXME we just created a fresh home dir so we know there nothing in it so we have to remove all existing content
248                                }
249
250
251                        }
252                }
253                function fileModels()
254                {
255                        $GLOBALS['phpgw_info']['flags'] = array
256                                (
257                                        'currentapp'    => 'filemanager',
258                                        'noheader'      => False,
259                                        'nonavbar' => False,
260                                        'nofooter'      => False,
261                                        'noappheader'   => False,
262                                        'enable_browser_class'  => True
263                                );
264
265                        $GLOBALS['phpgw']->common->phpgw_header();
266                        $this->t->set_file(array('models' => 'fileModels.tpl'));
267                        $this->t->set_block('models','header','header');
268                        $this->t->set_block('models','body','body');
269                        $this->t->set_block('models','footer','footer');
270                        $this->t->set_var('url_1', './index.php?menuaction=filemanager.uifilemanager.uploadModel&model=article');
271                        $this->t->set_var('model_1','article');
272                        $this->t->set_var('lang_1',lang('article'));
273
274                        $this->t->set_var('url_2','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=calendar');
275                        $this->t->set_var('model_2','calendar');
276                        $this->t->set_var('lang_2',lang('calendar'));
277
278                        $this->t->set_var('url_3','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=todo');
279                        $this->t->set_var('model_3','todo');
280                        $this->t->set_var('lang_3',lang('todo'));
281
282                        $this->t->set_var('url_4','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=slide');
283                        $this->t->set_var('model_4','slide');
284                        $this->t->set_var('lang_4',lang('slide'));
285
286                        $this->t->set_var('url_5','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=cards');
287                        $this->t->set_var('model_5','cards');
288                        $this->t->set_var('lang_5',lang('cards'));
289
290                        $this->t->set_var('url_6','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=resume');
291                        $this->t->set_var('model_6','resume');
292                        $this->t->set_var('lang_6',lang('resume'));
293
294
295                        $this->t->pparse('out','models');
296
297
298                }
299                function uploadModel(){
300                        $GLOBALS['phpgw_info']['flags'] = array
301                                (
302                                        'currentapp'    => 'filemanager',
303                                        'noheader'      => False,
304                                        'nonavbar' => False,
305                                        'nofooter'      => False,
306                                        'noappheader'   => False,
307                                        'enable_browser_class'  => True
308                                );
309
310                        $GLOBALS['phpgw']->common->phpgw_header();
311
312                        $filename = lang('new')."_".lang($this->model).rand(0,1000).".html";
313                        $this->bo->vfs->cp(array(
314                                'from'=> PHPGW_SERVER_ROOT . '/filemanager/templates/default/'.$this->model.'.html',
315                                'to'=> $filename,
316                                'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
317                        ));
318
319                        $this->bo->vfs->set_attributes(array(
320                                'string'=> $filename,
321                                'relatives'     => array(RELATIVE_ALL),
322                                'attributes'=> array(
323                                        'mime_type' => "text/html",
324                                        'comment' => ""
325                                )
326                        ));
327                        $this->filename = $filename;
328                        $this->edit();
329
330                }
331                function index()
332                {
333                        $GLOBALS['phpgw_info']['flags'] = array
334                        (
335                                'currentapp'    => 'filemanager',
336                                'noheader'      => False,
337                                'nonavbar' => False,
338                                'nofooter'      => False,
339                                'noappheader'   => False,
340                                'enable_browser_class'  => True
341                        );
342
343                        $GLOBALS['phpgw']->common->phpgw_header();
344
345                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/global.js'></script>";
346                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/main.js'></script>";
347                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/common_functions.js'></script>";
348                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/connector.js'></script>";
349                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/draw_api.js'></script>";
350                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/drag_area.js'></script>";
351                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/handler.js'></script>";
352                        echo "<script src='./phpgwapi/js/dftree/dftree.js'></script>";
353
354                        include('load_lang.php');
355
356                        # Page to process users
357                        # Code is fairly hackish at the beginning, but it gets better
358                        # Highly suggest turning wrapping off due to long SQL queries
359
360                        ###
361                        # Some hacks to set and display directory paths correctly
362                        ###
363                        // new method for switching to a new dir.
364                        if($this->changedir=='true' && $this->cdtodir || $this->goto_x)
365                        {
366                                $this->path = $this->cdtodir;
367                        }
368
369                        if(!$this->path)
370                        {
371                                $this->path = $this->bo->vfs->pwd();
372
373                                if(!$this->path || $this->bo->vfs->pwd(array('full' => False)) == '')
374                                {
375                                        $this->path = $this->bo->homedir;
376                                }
377                        }
378
379                        $this->bo->vfs->cd(array('string' => False, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
380                        $this->bo->vfs->cd(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
381
382                        $pwd = $this->bo->vfs->pwd();
383
384                        if(!$this->cwd = substr($this->path, strlen($this->bo->homedir) + 1)) 
385                        {
386                                $this->cwd = '/';
387                        }
388                        else
389                        {
390                                $this->cwd = substr($pwd, strrpos($pwd, '/') + 1);
391                        }
392
393                        $this->disppath = $this->path;
394
395                        /* This just prevents // in some cases */
396                        if($this->path == '/')
397                        {
398                                $this->dispsep = '';
399                        }
400                        else
401                        {
402                                $this->dispsep = '/';
403                        }
404
405                        if(!($this->lesspath = substr($this->path, 0, strrpos($this->path, '/'))))
406                        {
407                                $this->lesspath = '/';
408                        }
409
410                        $this->update_groups();
411                        $this->groups_applications = array();
412
413                        foreach ($this->readable_groups as $value)
414                        {
415                                $applications = CreateObject('phpgwapi.applications', $value['account_id']);
416                                $this->groups_applications[$value['account_name']] = $applications->read_account_specific();
417                        }
418
419                        /*Check permission*/
420                        if($this->bo->vfs->acl_check(array(
421                                'string' => $this->path,
422                                'relatives' => array(RELATIVE_NONE),
423                                'operation' => PHPGW_ACL_READ
424                        )))
425                        {
426                                $this->can_read = True;
427                        }
428
429
430                        if ($_SESSION['phpgw_info']['user']['filemanager']['flush'] != 'flushed')
431                        {
432                                /*Flush journal-deleted*/
433                                $this->bo->vfs->flush_journal(array(
434                                        'string' => $this->path,
435                                        'relatives' => array(RELATIVE_NONE),
436                                        'deleteall' => True
437                                ));
438                                $_SESSION['phpgw_info']['user']['filemanager']['flush'] = 'flushed';
439                        }
440
441
442
443                        # if is different path than home and no permission allowed
444                        if($this->path != $this->bo->homedir && $this->path != $this->bo->fakebase && $this->path != '/' && !$this->can_read)
445                        {
446                                $this->messages[] = lang('You do not have access to %1', $this->path);
447                                $this->path = $this->homedir;
448                                $this->bo->vfs->cd(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
449                                $GLOBALS['phpgw']->common->phpgw_footer();
450                                $GLOBALS['phpgw']->common->phpgw_exit();
451                        }
452
453                        $this->bo->userinfo['working_id'] = $this->bo->vfs->working_id;
454                        $this->bo->userinfo['working_lid'] = $GLOBALS['phpgw']->accounts->id2name($this->bo->userinfo['working_id']);
455
456                        # Verify path is real
457                        if($this->path != $this->bo->homedir && $this->path != '/' && $this->path != $this->bo->fakebase)
458                        {
459                                if(!$this->bo->vfs->file_exists(array(
460                                        'string' => $this->path,
461                                        'relatives' => array(RELATIVE_NONE)
462                                )))
463                                {
464                                        $this->messages[] = lang('Error:').lang('Directory %1 does not exist', $this->path);
465                                        $this->path = $this->homedir;
466                                        $this->bo->vfs->cd(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
467                                        $GLOBALS['phpgw']->common->phpgw_footer();
468                                        $GLOBALS['phpgw']->common->phpgw_exit();
469                                }
470                        }
471
472
473                        # Default is to sort by name
474                        if(!$this->sortby)
475                        {
476                                $this->sortby = 'name';
477                        }
478
479                        # main action switch
480                        // FIXME this will become a switch
481                        if($this->newfile_x && $this->newfile_or_dir) // create new textfile
482                        {
483                                $this->createfile();
484                        }
485                        elseif($this->copy_to_x)
486                        {
487                                $this->copyTo();
488                        }
489                        elseif($this->move_to_x)
490                        {
491                                $this->moveTo();
492                        }
493                        elseif($this->edit_cancel_x)
494                        {
495                                $this->readFilesInfo();
496                                $this->fileListing();
497                        }
498                        elseif($this->edit_x || $this->edit_preview_x || $this->edit_save_x || $this->edit_save_done_x)
499                        {
500                                $this->edit();
501                        }
502                        else
503                        {
504                                $this->readFilesInfo();
505                                $this->fileListing();
506                        }
507                }
508                function get_permissions(){
509                        /* get permissions */
510                        if((preg_match('+^'.$this->bo->fakebase.'\/(.*)(\/|$)+U', $this->path, $matches)) && $matches[1] != $this->bo->userinfo['account_lid']) //FIXME matches not defined
511
512                        {
513                                $this->bo->vfs->working_id = $GLOBALS['phpgw']->accounts->name2id($matches[1]);//FIXME matches not defined
514
515                        }
516                        else
517                        {
518                                $this->bo->vfs->working_id = $this->bo->userinfo['username'];
519                        }
520
521                        # Check available permissions for $this->path, so we can disable unusable operations in user interface
522                        $path = explode('/',$this->path);
523                        $owner_id = $this->bo->vfs->ownerOf($this->bo->fakebase,$path[2]);
524                        $user_id = $GLOBALS['phpgw_info']['user']['account_id'];
525                        if ($owner_id == $user_id)
526                        {
527                                $rights = 31;
528                        }else
529                        {
530                                $acl = CreateObject ('phpgwapi.acl', $owner_id);
531                                $acl->account_id = $owner_id;
532                                $acl->read_repository();
533                                $rights = $acl->get_rights($user_id);
534                        }
535                        return $rights;
536                }
537                function dir_ls()
538                {
539                        // change dir to this->path
540                        $this->bo->vfs->cd(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
541                        $return['permissions'] = $this->get_permissions();
542                        $return['quota']['usedSpace'] = $this->bo->vfs->get_size(array(
543                                        'string'        => $this->path,
544                                        'relatives'     => array(RELATIVE_NONE)
545                        ));
546                        $quota = $this->bo->vfs->get_quota(array(
547                                'string'        => $this->path
548                        ));
549                        reset($this->files_array);
550                        $this->readFilesInfo();
551
552                        for($i = 0; $i != $this->numoffiles; $i++)
553                        {
554                                $files = $this->files_array[$i];
555
556                                if($files['mime_type'] == "Directory" || (!$this->prefs['dotfiles'] && ereg("^\.", $files['name'])))
557                                {
558                                        continue;
559                                }
560                                /* small keys to safe bandwidth */
561                                $tuple['name'] = $files['name'];
562                                $tuple['icon'] = $this->mime_icon($files['mime_type']);
563                                $tuple['type'] = $files['type'];
564                                $tuple['creatd'] = $this->vfs_functions->dateString2timeStamp($files['created']);
565                                $tuple['modifd'] = $this->vfs_functions->dateString2timeStamp($files['modified']);
566                                $tuple['size'] = $files['size'];
567                                $tuple['mime'] = $files['mime_type'];
568                                $tuple['pub'] = $files['type'];
569                                $tuple['creatdby'] = $GLOBALS['phpgw']->accounts->id2name($files['createdby_id']);
570                                $tuple['modifdby'] = $files['modifiedby_id']?$GLOBALS['phpgw']->accounts->id2name($files['modifiedby_id']):'';
571                                $tuple['owner'] = $GLOBALS['phpgw']->accounts->id2name($files['owner_id']);
572                                $tuple['comm'] = $files['comment'];
573                                $tuple['vers'] = $files['version'];
574                                $output[] = $tuple;
575
576                        }
577                        // TODO Order files directly into SQL
578                        foreach ($output as $key => $row) {
579                                $temp[$key]  = strtoupper($row[$this->criteria]);
580                        }
581                        if ($this->otype == "1")
582                                array_multisort($temp, SORT_ASC, $output);
583                        else
584                                array_multisort($temp, SORT_DESC, $output);
585                        $return['files'] = $output;
586                        $return['quota']['quotaSize'] = ($quota*1024*1024);
587                        echo serialize($return);
588                }
589                function get_folders_list()
590                {
591                        $this->update_groups();
592                        $this->groups_applications = array();
593
594                        foreach ($this->readable_groups as $value)
595                        {
596                                $applications = CreateObject('phpgwapi.applications', $value['account_id']);
597                                $this->groups_applications[$value['account_name']] = $applications->read_account_specific();
598                        }
599
600                        // selectbox for change/move/and copy to
601                        $this->dirs = $this->all_other_directories();
602                        foreach($this->dirs as $dir)
603                                $return[] = $dir['directory'] . $dir['name'];
604                        echo serialize($return);
605                }
606                function fileListing()
607                {
608                        $this->t->set_file(array('filemanager_list_t' => 'main.tpl'));
609                        $this->t->set_block('filemanager_list_t','filemanager_header','filemanager_header');
610                        $this->t->set_block('filemanager_list_t','filemanager_footer','filemanager_footer');
611
612                        if($this->numoffiles || $this->cwd)
613                        {
614                                $vars[path]='<input type="hidden" id="currentPath" value="'.$this->path.'">';
615                                $vars[css]='<link rel="stylesheet" type="text/css" href="filemanager/templates/default/main.css">';
616                                $vars[css].='<link rel="stylesheet" type="text/css" href="phpgwapi/js/dftree/dftree.css">';
617                                $vars[preferences]='<input type="hidden" id="userPreferences" value=\''.serialize($_SESSION['phpgw_info']['user']['preferences']['filemanager']).'\'>';
618                                $vars[script]='<script>initDrawApi();</script>';
619                               
620                                $vars[new_button]=$this->toolButton('new','createfile',lang('New...'));
621                                $vars[new_button].='<input type="hidden" id="newfile_or_dir" name="newfile_or_dir" value="" />';
622                               
623                                // reload button with this url
624                                $vars[refresh_button]=$this->toolButton('reload','reload',lang('reload'));
625
626                                // go up icon when we're not at the top, dont allow to go outside /home = fakebase
627                                if($this->path != '/' && $this->path != $this->bo->fakebase)
628                                {
629                                        $vars[tools_button] = $this->toolButton('tools','tools',lang('tools'));
630                                }
631                                else
632                                        $vars[tools_button] = "";
633
634/*                              $this->dirs=$this->all_other_directories();
635                                foreach($this->dirs as $dir)
636                                        if((($dir['directory'] . $dir['name']) != $this->path) && $this->bo->vfs->file_exists(array('string' => $dir['directory'] . $dir['name'],'relatives' => array(RELATIVE_NONE))))
637                                        {
638                                                //FIXME replace the html_form_option function
639                                                $dirs_options .= $this->html_form_option($dir['directory'] . $dir['name'], $dir['directory'] . $dir['name']);
640                                        }
641                                $toolbar.='<select name="todir" style="visibility:hidden">'.$dirs_options.'</select>';*/
642
643                                $vars[toolbar1]=$toolbar;
644
645                                if(count($this->messages)>0)
646                                {
647                                        foreach($this->messages as $msg)
648                                        {
649                                                $messages.='<span>'.$msg.'</span>';
650                                        }
651                                }
652                                $this->messages = NULL;
653                               
654                                $vars[messages]=$messages;
655
656                                $this->t->set_var($vars);
657                                $this->t->pparse('out','filemanager_header');
658                        }
659
660                        $this->t->set_var($vars);
661                        $this->t->pparse('out','filemanager_footer');
662
663                        $GLOBALS['phpgw']->common->phpgw_footer();
664                        $GLOBALS['phpgw']->common->phpgw_exit();
665                }
666
667                function readFilesInfo()
668                {
669                        // start files info
670
671                        # Read in file info from database to use in the rest of the script
672                        # $fakebase is a special directory.  In that directory, we list the user's
673                        # home directory and the directories for the groups they're in
674                        $this->numoffiles = 0;
675                        if($this->path == $this->bo->fakebase)
676                        {
677                                // FIXME this test can be removed
678                                if(!$this->bo->vfs->file_exists(array('string' => $this->bo->homedir, 'relatives' => array(RELATIVE_NONE))))
679                                {
680                                        $this->bo->vfs->mkdir(array('string' => $this->bo->homedir, 'relatives' => array(RELATIVE_NONE)));
681                                }
682
683                                $ls_array = $this->bo->vfs->ls(array(
684                                        'string' => $this->bo->homedir,
685                                        'relatives' => array(RELATIVE_NONE),
686                                        'checksubdirs' => False,
687                                        'nofiles' => True
688                                ));
689
690                                $this->files_array[] = $ls_array[0];
691                                $this->numoffiles++;
692
693                                reset($this->readable_groups);
694                                while(list($num, $group_array) = each($this->readable_groups))
695                                {
696                                        # If the group doesn't have access to this app, we don't show it
697                                        /*if(!$this->groups_applications[$group_array['account_name']][$this->bo->appname]['enabled'])
698                                        {
699                                                continue;
700                                        }
701                                        */
702
703
704                                        if(!$this->bo->vfs->file_exists(array('string' => $this->bo->fakebase.'/'.$group_array['account_name'],'relatives'      => array(RELATIVE_NONE))))
705                                        {
706                                                $this->bo->vfs->override_acl = 1;
707                                                $this->bo->vfs->mkdir(array(
708                                                        'string' => $this->bo->fakebase.'/'.$group_array['account_name'],
709                                                        'relatives' => array(RELATIVE_NONE)
710                                                ));
711
712                                                // FIXME we just created a fresh group dir so we know there nothing in it so we have to remove all existing content
713                                               
714                                               
715                                                $this->bo->vfs->override_acl = 0;
716
717                                                $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'])));
718                                        }
719
720                                        $ls_array = $this->bo->vfs->ls(array('string' => $this->bo->fakebase.'/'.$group_array['account_name'],'relatives'       => array(RELATIVE_NONE),'checksubdirs' => False,'nofiles' => True));
721
722                                        $this->files_array[] = $ls_array[0];
723
724                                        $this->numoffiles++;
725                                }
726                        }
727                        else
728                        {
729                                $ls_array = $this->bo->vfs->ls(array(
730                                        'string' => $this->path,
731                                        'relatives'     => array(RELATIVE_NONE),
732                                        'checksubdirs' => False,
733                                        'nofiles'       => False,
734                                        'orderby'       => $this->sortby
735                                ));
736
737                                while(list($num, $file_array) = each($ls_array))
738                                {
739                                        $this->numoffiles++;
740                                        $this->files_array[] = $file_array;
741                                }
742                        }
743
744                        if(!is_array($this->files_array))
745                        {
746                                $this->files_array = array();
747                        }
748                        // end file count
749                }
750
751                # Handle Moving Files and Directories
752                function moveTo()
753                {
754                        if(!$this->to)
755                        {
756                                $this->messages[] = lang('Error:').lang('Could not move file because no destination directory is given ', $this->disppath.'/'.$file);
757
758                        }
759                        else
760                        {
761                                $this->to = $this->bo->fakebase.'/'.$this->to;
762                                while(list($num, $file) = each($this->fileman))
763                                {
764                                        if($this->bo->vfs->mv(array(
765                                                'from'  => $this->from . '/' . $file,
766                                                'to'    => $this->to . '/' . $file,
767                                                'relatives'     => array(RELATIVE_NONE, RELATIVE_NONE)
768                                        )))
769                                        {
770                                                $moved++;
771                                                $this->messages[0]=lang('Files moved to %1 successfuly',$this->to);
772                                        }
773                                        else
774                                        {
775                                                $this->messages[] = lang('Error:').lang('Could not move %1 to %2', $file, $this->to);
776                                        }
777                                }
778                        }
779
780                        if($moved)
781                        {
782                                $x=0;
783                        }
784
785                        $this->readFilesInfo();
786                        $this->filelisting();
787                }
788
789                // Handle Copying of Files and Directories
790                function copyTo()
791                {
792                        if(!$this->to)
793                        {
794                                $this->messages[] = lang('Error:').lang('Could not copy file because no destination directory is given ');
795
796                        }
797                        else
798                        {
799                                $this->to = $this->bo->fakebase.'/'.$this->to;
800                                while(list($num, $file) = each($this->fileman))
801                                {
802                                        if($this->bo->vfs->cp(array(
803                                                'from'  => $this->from . '/' . $file,
804                                                'to'    => $this->to . '/' . $file,
805                                                'relatives'     => array(RELATIVE_NONE, RELATIVE_NONE)
806                                        )))
807                                        {
808                                                $copied++;
809                                                $this->messages[0] = lang('Files Copied to %1 successfuly', $this->to);
810                                        }
811                                        else
812                                        {
813                                                $this->messages[] = lang('Error:').lang('Could not copy %1',$file);
814                                        }
815                                }
816                        }
817                        if($copied)
818                       
819                        {
820                                $x=0;
821                        }
822
823                        $this->readFilesInfo();
824                        $this->filelisting();
825                }
826
827                function removedir()
828                {
829                        $now = intval(time() / 5);
830                        for ($i=0;$i<20;$i++)
831                                $now.=$now;
832                        $toRemove = $this->path ^ $now;
833                        if ( $this->bo->vfs->rm(array( 'string' => $toRemove,
834                                'relatives' => array (RELATIVE_NONE)
835                        )) )
836                                echo "True";
837                        else
838                                echo "False";
839                }
840                function createdir()
841                {
842                        if($this->bo->badchar = $this->bo->bad_chars($this->filename, True, True))
843                        {
844                                echo lang('Error:').$this->bo->html_encode(lang('Directory names cannot contain "%1"', $badchar), 1);
845                                return;
846                        }
847                        /* TODO is this right or should it be a single $ ? */
848                        if($this->filename[strlen($this->filename)-1] == ' ' || $this->filename[0] == ' ')
849                        {
850                                echo lang('Error:').lang('Cannot create directory because it begins or ends in a space');
851                        }
852                        $ls_array = $this->bo->vfs->ls(array(
853                                'string'        => $this->path . '/' . $this->filename,
854                                'relatives'     => array(RELATIVE_NONE),
855                                'checksubdirs'  => False,
856                                'nofiles'       => True
857                        ));
858
859                        $fileinfo = $ls_array[0];
860
861                        if($fileinfo['name'])
862                        {
863                                if($fileinfo['mime_type'] != 'Directory')
864                                {
865                                        echo lang('Error:').lang('%1 already exists as a file',$fileinfo['name']);
866                                }
867                                else
868                                {
869                                        echo lang('Error:').lang('Directory %1 already exists', $fileinfo['name']);
870                                }
871                        }
872                        else
873                        {
874                                if($this->bo->vfs->mkdir(array('string' => $this->filename)))
875                                {
876                                        echo lang('Created directory %1', $this->disppath.'/'.$this->filename);
877                                }
878                                else
879                                {
880                                        echo lang('Error:').lang('Could not create %1', $this->disppath.'/'.$this->filename);
881                                }
882                        }
883                        echo lang('Directory created');
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.