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

Revision 1841, 48.5 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Melhoria do FM, tratamento de janelas diferenciado

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