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

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