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

Revision 1804, 48.2 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Melhorias no modulo gerenciador de arquivos

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