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

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

Ticket #597 - Melhoria do FM, Implementação do arquivamento

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