source: branches/2.2/filemanager/inc/class.uifilemanager.inc.php @ 3569

Revision 3569, 48.6 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #1395 - Padronizacao das janelas do filemanager com as do Expresso.

Line 
1<?php
2        /**************************************************************************\
3        * -------------------------------------------------------------------------*
4        * This library is free software; you can redistribute it and/or modify it  *
5        * under the terms of the GNU Lesser General Public License as published by *
6        * the Free Software Foundation; either version 2.1 of the License,         *
7        * or any later version.                                                    *
8        * This library is distributed in the hope that it will be useful, but      *
9        * WITHOUT ANY WARRANTY; without even the implied warranty of               *
10        * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
11        * See the GNU Lesser General Public License for more details.              *
12        * You should have received a copy of the GNU Lesser General Public License *
13        * along with this library; if not, write to the Free Software Foundation,  *
14        * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            *
15        \**************************************************************************/
16
17        /* $Id: class.uifilemanager.inc.php 17511 2004-12-12 06:35:24Z dawnlinux $ */
18
19        class uifilemanager
20        {
21                var $public_functions = array(
22                        'index' => True,
23                        'help'  => True,
24                        'view'  => True,
25                        'export'=> True,
26                        'touch' => True,
27                        'history' => True,
28                        'edit' => True,
29                        'fileModels'=>True,
30                        'getReturnExecuteForm' => True,
31                        'dir_ls' => True,
32                        'search' => True,
33                        'get_folders_list' => True,
34                        'showUploadboxes' => True,
35                        'createdir' => True,
36                        'removedir' => True,
37                        'uploadModel'=>True
38                );
39
40                //keep
41                var $bo;
42                var $vfs_functions;
43                var $t; //template object
44                var $dispath;
45                var $cwd;
46                var $lesspath;
47                var $readable_groups;
48                var $files_array;
49                var $numoffiles;
50                var $dispsep;
51
52                var $target;
53
54                var $prefs;//array
55
56                var $groups_applications;
57
58                var $current_config;
59                var $dirs;
60                var $to;
61                var $changedir; // for switching dir.
62                var $cdtodir; // for switching dir.
63                var $newfile_or_dir;
64                var $newfile_x;
65                var $createfile_var;
66                var $move_to_x;
67                var $copy_to_x;
68                var $edit_x;
69                var $edit_file;
70                var $edit_preview_x;
71                var $edit_save_x;
72                var $edit_save_done_x;
73                var $edit_cancel_x;
74
75                // this ones must be checked thorougly;
76                var $fileman = Array();
77                //var $fileman;
78                var $path;
79                var $file; // FIXME WHERE IS THIS FILLED?
80                var $sortby;
81                var $messages;
82                var $limit; //for paging (paginacao)
83                var $offset; //for paging (paginacao)
84
85                var $now;
86
87                function uifilemanager()
88                {
89                        $this->messages = &$_SESSION['phpgw_info']['filemanager']['user']['messages'];
90
91                        $GLOBALS['phpgw']->browser = CreateObject('phpgwapi.browser');
92
93                        $this->now = date('Y-m-d');
94
95                        $this->bo = CreateObject('filemanager.bofilemanager');
96
97                        $this->vfs_functions = CreateObject('filemanager.vfs_functions');
98
99                        $this->t = $GLOBALS['phpgw']->template;
100                        $c = CreateObject('phpgwapi.config','filemanager');
101                        $c->read_repository();
102                        $this->current_config = $c->config_data;
103
104
105                        // here local vars are created from the HTTP vars
106                        @reset($GLOBALS['HTTP_POST_VARS']);
107                        while(list($name,) = @each($GLOBALS['HTTP_POST_VARS']))
108                        {
109                                $this->$name = $GLOBALS['HTTP_POST_VARS'][$name];
110                        }
111
112                        @reset($GLOBALS['HTTP_GET_VARS']);
113                        while(list($name,) = @each($GLOBALS['HTTP_GET_VARS']))
114                        {
115                                $$name = $GLOBALS['HTTP_GET_VARS'][$name];
116                                $this->$name = $GLOBALS['HTTP_GET_VARS'][$name];
117
118                        }
119
120                        $to_decode = array
121                        (
122                                'op'    => array('op' => ''),
123                                'path'  => array('path' => ''),
124                                'filename' => array('filename' => ''),
125                                'file'  => array('file' => ''),
126                                'sortby'        => array('sortby' => ''),
127                                'messages'      => array('messages'     => ''),
128                                'show_upload_boxes'     => array('show_upload_boxes' => ''),
129                                'from'  =>      array('from' => ''),
130                                'to' => array('to' => '')
131
132                        );
133
134                        reset($to_decode);
135                        while(list($var, $conditions) = each($to_decode))
136                        {
137                                while(list($condvar, $condvalue) = each($conditions))
138                                {
139                                        if(isset($$condvar) && ($condvar == $var || $$condvar == $condvalue))
140                                        {
141                                                $this->$var = stripslashes(base64_decode($$var));
142                                        }
143                                }
144                        }
145
146                        // get appl. and user prefs
147                        $pref = CreateObject('phpgwapi.preferences', $this->bo->userinfo['username']);
148                        $pref->read_repository();
149                        //$GLOBALS['phpgw']->hooks->single('add_def_pref', $GLOBALS['appname']);
150                        $pref->save_repository(True);
151                        $pref_array = $pref->read_repository();
152                        $this->prefs = $pref_array[$this->bo->appname]; //FIXME check appname var in _debug_array
153
154                        //always show name
155
156                        $this->prefs[name] =1;
157
158
159                        if($this->prefs['viewinnewwin'])
160                        {
161                                $this->target = '_blank';
162                        }
163
164
165                        /*
166                                Check for essential directories
167                                admin must be able to disable these tests
168                        */
169                       
170                        // check if basedir exist
171                        $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
172                        if($test[mime_type]!='Directory')
173                        {
174                                die('Base directory does not exist, Ask adminstrator to check the global configuration.');
175                        }
176
177                        $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->fakebase, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
178                        if($test[mime_type]!='Directory')
179                        {
180                                $this->bo->vfs->override_acl = 1;
181
182                                $this->bo->vfs->mkdir(array(
183                                        'string' => $this->bo->fakebase,
184                                        'relatives' => array(RELATIVE_NONE)
185                                ));
186                               
187                                $this->bo->vfs->override_acl = 0;
188
189                                //test one more time
190                                $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->fakebase, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
191
192                                if($test[mime_type]!='Directory')
193                                {
194                                        die('Fake Base directory does not exist and could not be created, please ask the administrator to check the global configuration.');
195                                }
196                                else
197                                {
198                                        $this->messages[]= lang('Fake Base Dir did not exist, created a new one.');
199                                }
200                        }
201
202                        $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->homedir, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
203                        if($test[mime_type]!='Directory')
204                        {
205                                $this->bo->vfs->override_acl = 1;
206
207                                $this->bo->vfs->mkdir(array(
208                                        'string' => $this->bo->homedir,
209                                        'relatives' => array(RELATIVE_NONE)
210                                ));
211                                $this->bo->vfs->set_quota(array(
212                                        'string' => $this->bo->homedir,
213                                        'relatives' => array(RELATIVE_NONE),
214                                        'new_quota' => $this->current_config['filemanager_quota_size']
215                                ));
216       
217                                $this->bo->vfs->override_acl = 0;
218
219                                //test one more time
220                                $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->homedir, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
221
222                                if($test[mime_type]!='Directory')
223                                {
224                                        die('Your Home Dir does not exist and could not be created, please ask the adminstrator to check the global configuration.');
225                                }
226                                else
227                                {
228                                        $this->messages[]= lang('Your Home Dir did not exist, eGroupWare created a new one.');
229                                        // FIXME we just created a fresh home dir so we know there nothing in it so we have to remove all existing content
230                                }
231
232
233                        }
234                }
235                function fileModels()
236                {
237                        $GLOBALS['phpgw_info']['flags'] = array
238                                (
239                                        'currentapp'    => 'filemanager',
240                                        'noheader'      => False,
241                                        'nonavbar' => False,
242                                        'nofooter'      => False,
243                                        'noappheader'   => False,
244                                        'enable_browser_class'  => True
245                                );
246
247                        $GLOBALS['phpgw']->common->phpgw_header();
248                        $this->t->set_file(array('models' => 'fileModels.tpl'));
249                        $this->t->set_block('models','header','header');
250                        $this->t->set_block('models','body','body');
251                        $this->t->set_block('models','footer','footer');
252                        $this->t->set_var('url_1', './index.php?menuaction=filemanager.uifilemanager.uploadModel&model=article');
253                        $this->t->set_var('model_1','article');
254                        $this->t->set_var('lang_1',lang('article'));
255
256                        $this->t->set_var('url_2','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=calendar');
257                        $this->t->set_var('model_2','calendar');
258                        $this->t->set_var('lang_2',lang('calendar'));
259
260                        $this->t->set_var('url_3','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=todo');
261                        $this->t->set_var('model_3','todo');
262                        $this->t->set_var('lang_3',lang('todo'));
263
264                        $this->t->set_var('url_4','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=slide');
265                        $this->t->set_var('model_4','slide');
266                        $this->t->set_var('lang_4',lang('slide'));
267
268                        $this->t->set_var('url_5','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=cards');
269                        $this->t->set_var('model_5','cards');
270                        $this->t->set_var('lang_5',lang('cards'));
271
272                        $this->t->set_var('url_6','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=resume');
273                        $this->t->set_var('model_6','resume');
274                        $this->t->set_var('lang_6',lang('resume'));
275
276
277                        $this->t->pparse('out','models');
278
279
280                }
281                function uploadModel(){
282                        $GLOBALS['phpgw_info']['flags'] = array
283                                (
284                                        'currentapp'    => 'filemanager',
285                                        'noheader'      => False,
286                                        'nonavbar' => False,
287                                        'nofooter'      => False,
288                                        'noappheader'   => False,
289                                        'enable_browser_class'  => True
290                                );
291
292                        $GLOBALS['phpgw']->common->phpgw_header();
293
294                        $filename = lang('new')."_".lang($this->model).rand(0,1000).".html";
295                        $this->bo->vfs->cp(array(
296                                'from'=> PHPGW_SERVER_ROOT . '/filemanager/templates/default/'.$this->model.'.html',
297                                'to'=> $filename,
298                                'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
299                        ));
300
301                        $this->bo->vfs->set_attributes(array(
302                                'string'=> $filename,
303                                'relatives'     => array(RELATIVE_ALL),
304                                'attributes'=> array(
305                                        'mime_type' => "text/html",
306                                        'comment' => ""
307                                )
308                        ));
309                        $this->filename = $filename;
310                        $this->edit();
311
312                }
313                function index()
314                {
315                        $GLOBALS['phpgw_info']['flags'] = array
316                        (
317                                'currentapp'    => 'filemanager',
318                                'noheader'      => False,
319                                'nonavbar' => False,
320                                'nofooter'      => False,
321                                'noappheader'   => False,
322                                'enable_browser_class'  => True
323                        );
324
325                        $GLOBALS['phpgw']->common->phpgw_header();
326
327                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/global.js'></script>";
328                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/main.js'></script>";
329                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/common_functions.js'></script>";
330                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/connector.js'></script>";
331                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/draw_api.js'></script>";
332                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/drag_area.js'></script>";
333                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/handler.js'></script>";
334
335
336                        // Temas Expresso
337                        $theme = "window_" . $GLOBALS['phpgw_info']['user']['preferences']['common']['theme'] . ".css";
338
339                        if( !file_exists('filemanager/tp/expressowindow/css/'.$theme) )
340                                $theme = "window_default.css";
341
342                        // Path FileManager
343                        $webserver_url = $GLOBALS['phpgw_info']['server']['webserver_url'];
344                        $webserver_url = ( !empty($webserver_url) ) ? $webserver_url : '/';
345               
346                        if(strrpos($webserver_url,'/') === false || strrpos($webserver_url,'/') != (strlen($webserver_url)-1))
347                                $webserver_url .= '/';
348               
349                        $webserver_url  = $webserver_url . 'filemanager/';
350                       
351                        $js  = "var path_filemanager    = '".$webserver_url."';";
352                       
353                        echo "<script type='text/javascript'>".$js."</script>";
354
355                        // Expresso Window - CSS
356                        print '<link rel="stylesheet" type="text/css" href="' . $webserver_url . 'tp/expressowindow/css/'.$theme.'" >';
357
358                        // Expresso Window - JS
359                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/tp/expressowindow/js/xtools.js'></script>";
360                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/tp/expressowindow/js/jsloader.js'></script>";
361                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/tp/expressowindow/js/makeW.js'></script>";
362                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/tp/expressowindow/js/dragdrop.js'></script>";
363                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/tp/expressowindow/js/show_hidden.js'></script>";
364
365                        echo "<script src='./phpgwapi/js/dftree/dftree.js'></script>";
366
367                        include('load_lang.php');
368
369                        # Page to process users
370                        # Code is fairly hackish at the beginning, but it gets better
371                        # Highly suggest turning wrapping off due to long SQL queries
372
373                        ###
374                        # Some hacks to set and display directory paths correctly
375                        ###
376                        // new method for switching to a new dir.
377                        if($this->changedir=='true' && $this->cdtodir || $this->goto_x)
378                        {
379                                $this->path = $this->cdtodir;
380                        }
381
382                        if(!$this->path)
383                        {
384                                $this->path = $this->bo->vfs->pwd();
385
386                                if(!$this->path || $this->bo->vfs->pwd(array('full' => False)) == '')
387                                {
388                                        $this->path = $this->bo->homedir;
389                                }
390                        }
391
392                        $this->bo->vfs->cd(array('string' => False, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
393                        $this->bo->vfs->cd(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
394
395                        $pwd = $this->bo->vfs->pwd();
396
397                        if(!$this->cwd = substr($this->path, strlen($this->bo->homedir) + 1)) 
398                        {
399                                $this->cwd = '/';
400                        }
401                        else
402                        {
403                                $this->cwd = substr($pwd, strrpos($pwd, '/') + 1);
404                        }
405
406                        $this->disppath = $this->path;
407
408                        /* This just prevents // in some cases */
409                        if($this->path == '/')
410                        {
411                                $this->dispsep = '';
412                        }
413                        else
414                        {
415                                $this->dispsep = '/';
416                        }
417
418                        if(!($this->lesspath = substr($this->path, 0, strrpos($this->path, '/'))))
419                        {
420                                $this->lesspath = '/';
421                        }
422
423                        /*Check permission*/
424                        if($this->bo->vfs->acl_check(array(
425                                'string' => $this->path,
426                                'relatives' => array(RELATIVE_NONE),
427                                'operation' => PHPGW_ACL_READ
428                        )))
429                        {
430                                $this->can_read = True;
431                        }
432
433
434                        if ($_SESSION['phpgw_info']['user']['filemanager']['flush'] != 'flushed')
435                        {
436                                /*Flush journal-deleted*/
437                                $this->bo->vfs->flush_journal(array(
438                                        'string' => $this->path,
439                                        'relatives' => array(RELATIVE_NONE),
440                                        'deleteall' => True
441                                ));
442                                $_SESSION['phpgw_info']['user']['filemanager']['flush'] = 'flushed';
443                        }
444
445
446
447                        # if is different path than home and no permission allowed
448                        if($this->path != $this->bo->homedir && $this->path != $this->bo->fakebase && $this->path != '/' && !$this->can_read)
449                        {
450                                $this->messages[] = lang('You do not have access to %1', $this->path);
451                                $this->path = $this->homedir;
452                                $this->bo->vfs->cd(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
453                                $GLOBALS['phpgw']->common->phpgw_footer();
454                                $GLOBALS['phpgw']->common->phpgw_exit();
455                        }
456
457                        $this->bo->userinfo['working_id'] = $this->bo->vfs->working_id;
458                        $this->bo->userinfo['working_lid'] = $GLOBALS['phpgw']->accounts->id2name($this->bo->userinfo['working_id']);
459
460                        # Verify path is real
461                        if($this->path != $this->bo->homedir && $this->path != '/' && $this->path != $this->bo->fakebase)
462                        {
463                                if(!$this->bo->vfs->file_exists(array(
464                                        'string' => $this->path,
465                                        'relatives' => array(RELATIVE_NONE)
466                                )))
467                                {
468                                        $this->messages[] = lang('Error:').lang('Directory %1 does not exist', $this->path);
469                                        $this->path = $this->homedir;
470                                        $this->bo->vfs->cd(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
471                                        $GLOBALS['phpgw']->common->phpgw_footer();
472                                        $GLOBALS['phpgw']->common->phpgw_exit();
473                                }
474                        }
475
476
477                        # Default is to sort by name
478                        if(!$this->sortby)
479                        {
480                                $this->sortby = 'name';
481                        }
482                        if($this->update_x == 1){
483                                $this->bo->vfs->update_real(array(
484                                        'string'        => $this->path,
485                                        'relatives'     => array(RELATIVE_NONE)
486                                ));
487                                header('Location:'.$this->encode_href('index.php?menuaction=filemanager.uifilemanager.index','&path='.base64_encode($this->bo->homedir)));
488                        }
489                        elseif($this->newfile_x && $this->newfile_or_dir) // create new textfile
490                        {
491                                $this->createfile();
492                        }
493                        elseif($this->edit_cancel_x)
494                        {
495                                $this->readFilesInfo();
496                                $this->fileListing();
497                        }
498                        elseif($this->edit_x || $this->edit_preview_x || $this->edit_save_x || $this->edit_save_done_x)
499                        {
500                                $this->edit();
501                        }
502                        else
503                        {
504                                //$this->readFilesInfo();
505                                $this->fileListing();
506                        }
507                }
508                function get_permissions(){
509                        /* get permissions */
510                        if((preg_match('+^'.$this->bo->fakebase.'\/(.*)(\/|$)+U', $this->path, $matches)) && $matches[1] != $this->bo->userinfo['account_lid']) //FIXME matches not defined
511
512                        {
513                                $this->bo->vfs->working_id = $GLOBALS['phpgw']->accounts->name2id($matches[1]);//FIXME matches not defined
514
515                        }
516                        else
517                        {
518                                $this->bo->vfs->working_id = $this->bo->userinfo['username'];
519                        }
520
521                        # Check available permissions for $this->path, so we can disable unusable operations in user interface
522                        $path = explode('/',$this->path);
523                        $owner_id = $this->bo->vfs->ownerOf($this->bo->fakebase,$path[2]);
524                        $user_id = $GLOBALS['phpgw_info']['user']['account_id'];
525                        if ($owner_id == $user_id)
526                        {
527                                $rights = 31;
528                        }else
529                        {
530                                $acl = CreateObject ('phpgwapi.acl', $owner_id);
531                                $acl->account_id = $owner_id;
532                                $acl->read_repository();
533                                $rights = $acl->get_rights($user_id);
534                        }
535                        return $rights;
536                }
537                function dir_ls()
538                {
539                        // change dir to this->path
540                        $this->bo->vfs->cd(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
541                        $return['permissions'] = $this->get_permissions();
542                        $return['quota']['usedSpace'] = $this->bo->vfs->get_size(array(
543                                        'string'        => $this->path,
544                                        'relatives'     => array(RELATIVE_NONE)
545                        ));
546                        $return['files_count'] = $this->bo->vfs->count_files(array(
547                                        'string'        => $this->path,
548                        ));
549                        $quota = $this->bo->vfs->get_quota(array(
550                                'string'        => $this->path
551                        ));
552                        reset($this->files_array);
553                        $this->readFilesInfo();
554
555                        for($i = 0; $i != $this->numoffiles; $i++)
556                        {
557                                $files = $this->files_array[$i];
558
559                                if($files['mime_type'] == "Directory")
560                                {
561                                        continue;
562                                }
563                                /* small keys to safe bandwidth */
564                                $tuple['name'] = htmlentities($files['name']);
565                                if ($_SESSION['phpgw_info']['user']['preferences']['filemanager']['viewIcons'] == 1){
566                                        if ($files['mime_type'] == 'image/png' ||
567                                                $files['mime_type'] == 'image/gif' ||
568                                                $files['mime_type'] == 'image/jpg')
569                                        {
570                                                $filename = str_replace('=','',base64_encode($tuple['name']));
571                                                $pathname = str_replace('=','',base64_encode($this->path));
572                                                $tuple['icon'] = './index.php?menuaction=filemanager.vfs_functions.summary&file='.$filename.'&path='.$pathname;
573                                        }
574                                        else
575                                                $tuple['icon'] =  $this->mime_icon($files['mime_type'],64);
576                                }
577                                else
578                                        $tuple['icon'] = $this->mime_icon($files['mime_type']);
579                                $tuple['type'] = $files['type'];
580                                $tuple['created'] = $this->vfs_functions->dateString2timeStamp($files['created']);
581                                $tuple['modified'] = $this->vfs_functions->dateString2timeStamp($files['modified']);
582                                $tuple['size'] = $files['size'];
583                                $tuple['mime_type'] = $files['mime_type'];
584                                $tuple['pub'] = $files['type'];
585                                $tuple['createdby_id'] = $GLOBALS['phpgw']->accounts->id2name($files['createdby_id']);
586                                $tuple['modifiedby_id'] = $files['modifiedby_id']?$GLOBALS['phpgw']->accounts->id2name($files['modifiedby_id']):'';
587                                $tuple['owner'] = $GLOBALS['phpgw']->accounts->id2name($files['owner_id']);
588                                $tuple['comment'] = $files['comment'];
589                                $tuple['version'] = $files['version'];
590                                $output[] = $tuple;
591
592                        }
593                        $return['files'] = $output;
594                        $return['quota']['quotaSize'] = ($quota*1024*1024);
595                        echo serialize($return);
596                }
597                function get_folders_list()
598                {
599                        $this->update_groups();
600                        $this->groups_applications = array();
601
602                        $user_groups = $GLOBALS['phpgw']->accounts->membership();
603                        foreach($user_groups as $val){
604                                $account_name = $GLOBALS['phpgw']->accounts->id2name($val['account_id']);
605                                $this->readable_groups[$account_name] = array(
606                                        'account_id' => $val['account_id'],
607                                        'account_name' => $account_name
608                                );
609                        }
610
611                        foreach ($this->readable_groups as $value)
612                        {
613                                $applications = CreateObject('phpgwapi.applications', $value['account_id']);
614                                $this->groups_applications[$value['account_name']] = $applications->read_account_specific();
615                        }
616
617
618                        // selectbox for change/move/and copy to
619                        $this->dirs = $this->all_other_directories();
620                        foreach($this->dirs as $dir)
621                                $return[] = $dir['directory'] . $dir['name'];
622                        sort(&$return, SORT_STRING);
623                        echo serialize($return);
624                }
625                function fileListing()
626                {
627                        $this->t->set_file(array('filemanager_list_t' => 'main.tpl'));
628                        $this->t->set_block('filemanager_list_t','filemanager_header','filemanager_header');
629                        $this->t->set_block('filemanager_list_t','filemanager_footer','filemanager_footer');
630
631                        if($this->numoffiles || $this->cwd)
632                        {
633                                $vars[path]='<input type="hidden" id="currentPath" value="'.$this->path.'">';
634                                $vars[css]='<link rel="stylesheet" type="text/css" href="filemanager/templates/default/main.css">';
635                                $vars[css].='<link rel="stylesheet" type="text/css" href="phpgwapi/js/dftree/dftree.css">';
636                                $_SESSION['phpgw_info']['user']['preferences']['filemanager']['lid'] = $GLOBALS['phpgw_info']['user']['account_lid'];
637                                $vars[preferences]='<input type="hidden" id="userPreferences" value=\''.serialize($_SESSION['phpgw_info']['user']['preferences']['filemanager']).'\'>';
638                                // Used for important operations that needs security
639                                for ($key = ""; strlen($key) < 150; $key .= chr(rand(48,95)));
640                                $_SESSION['phpgw_info']['filemanager']['user']['sec_key'] = $key;
641                                $vars[sec_key]='<input type="hidden" id="userKey" value=\''.$key.'\'>';
642                                $vars[script]='<script>initDrawApi();</script>';
643                               
644                                $vars[new_button]=$this->toolButton('new','createfile',lang('New...'));
645                                $vars[new_button].='<input type="hidden" id="newfile_or_dir" name="newfile_or_dir" value="" />';
646                               
647                                // reload button with this url
648                                $vars[refresh_button]=$this->toolButton('reload','reload',lang('reload'));
649
650                                // go up icon when we're not at the top, dont allow to go outside /home = fakebase
651                                if($this->path != '/' && $this->path != $this->bo->fakebase)
652                                {
653                                        $vars[tools_button] = $this->toolButton('tools','tools',lang('tools'));
654                                }
655                                else
656                                        $vars[tools_button] = "";
657
658                                $vars[toolbar1]=$toolbar;
659
660                                if(count($this->messages)>0)
661                                {
662                                        foreach($this->messages as $msg)
663                                        {
664                                                $messages.='<span>'.$msg.'</span>';
665                                        }
666                                }
667                                $this->messages = NULL;
668                               
669                                $vars[messages]=$messages;
670
671                                $this->t->set_var($vars);
672                                $this->t->pparse('out','filemanager_header');
673                        }
674
675                        $this->t->set_var($vars);
676                        $this->t->pparse('out','filemanager_footer');
677
678                        $GLOBALS['phpgw']->common->phpgw_footer();
679                        $GLOBALS['phpgw']->common->phpgw_exit();
680                }
681
682                function readFilesInfo()
683                {
684                        // start files info
685
686                        # Read in file info from database to use in the rest of the script
687                        # $fakebase is a special directory.  In that directory, we list the user's
688                        # home directory and the directories for the groups they're in
689                        $this->numoffiles = 0;
690                        if($this->path == $this->bo->fakebase)
691                        {
692                                // FIXME this test can be removed
693                                if(!$this->bo->vfs->file_exists(array('string' => $this->bo->homedir, 'relatives' => array(RELATIVE_NONE))))
694                                {
695                                        $this->bo->vfs->mkdir(array('string' => $this->bo->homedir, 'relatives' => array(RELATIVE_NONE)));
696                                }
697
698                                $ls_array = $this->bo->vfs->ls(array(
699                                        'string' => $this->bo->homedir,
700                                        'relatives' => array(RELATIVE_NONE),
701                                        'checksubdirs' => False,
702                                        'nofiles' => True
703                                ));
704
705                                $this->files_array[] = $ls_array[0];
706                                $this->numoffiles++;
707
708                                reset($this->readable_groups);
709                                while(list($num, $group_array) = each($this->readable_groups))
710                                {
711                                        # If the group doesn't have access to this app, we don't show it
712                                        /*if(!$this->groups_applications[$group_array['account_name']][$this->bo->appname]['enabled'])
713                                        {
714                                                continue;
715                                        }
716                                        */
717
718
719                                        if(!$this->bo->vfs->file_exists(array('string' => $this->bo->fakebase.'/'.$group_array['account_name'],'relatives'      => array(RELATIVE_NONE))))
720                                        {
721                                                $this->bo->vfs->override_acl = 1;
722                                                $this->bo->vfs->mkdir(array(
723                                                        'string' => $this->bo->fakebase.'/'.$group_array['account_name'],
724                                                        'relatives' => array(RELATIVE_NONE)
725                                                ));
726
727                                                // FIXME we just created a fresh group dir so we know there nothing in it so we have to remove all existing content
728                                               
729                                               
730                                                $this->bo->vfs->override_acl = 0;
731
732                                                $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'])));
733                                        }
734
735                                        $ls_array = $this->bo->vfs->ls(array('string' => $this->bo->fakebase.'/'.$group_array['account_name'],'relatives'       => array(RELATIVE_NONE),'checksubdirs' => False,'nofiles' => True));
736
737                                        $this->files_array[] = $ls_array[0];
738
739                                        $this->numoffiles++;
740                                }
741                        }
742                        else
743                        {
744                                $ls_array = $this->bo->vfs->ls(array(
745                                        'string' => $this->path,
746                                        'relatives'     => array(RELATIVE_NONE),
747                                        'checksubdirs' => False,
748                                        'nofiles'       => False,
749                                        'orderby'       => $this->criteria,
750                                        'otype'         => $this->otype,
751                                        'limit'         => $this->limit,
752                                        'offset'        => $this->offset
753                                ));
754
755                                while(list($num, $file_array) = each($ls_array))
756                                {
757                                        $this->numoffiles++;
758                                        $this->files_array[] = $file_array;
759                                }
760                        }
761
762                        if(!is_array($this->files_array))
763                        {
764                                $this->files_array = array();
765                        }
766                        // end file count
767                }
768                function removedir()
769                {
770                        $toRemove = $this->path ^ $_SESSION['phpgw_info']['filemanager']['user']['sec_key'];
771                        if ( $this->bo->vfs->rm(array( 'string' => $toRemove,
772                                'relatives' => array (RELATIVE_NONE)
773                        )) )
774                                echo "True";
775                        else
776                                echo "False";
777                }
778                function createdir()
779                {
780                        if($this->bo->badchar = $this->bo->bad_chars($this->filename, True, True))
781                        {
782                                echo lang('Error:').$this->bo->html_encode(lang('Directory names cannot contain "%1"', $badchar), 1);
783                                return;
784                        }
785                        /* TODO is this right or should it be a single $ ? */
786                        if($this->filename[strlen($this->filename)-1] == ' ' || $this->filename[0] == ' ')
787                        {
788                                echo lang('Error:').lang('Cannot create directory because it begins or ends in a space');
789                        }
790                        $ls_array = $this->bo->vfs->ls(array(
791                                'string'        => $this->path . '/' . $this->filename,
792                                'relatives'     => array(RELATIVE_NONE),
793                                'checksubdirs'  => False,
794                                'nofiles'       => True
795                        ));
796
797                        $fileinfo = $ls_array[0];
798
799                        if($fileinfo['name'])
800                        {
801                                if($fileinfo['mime_type'] != 'Directory')
802                                {
803                                        echo lang('Error:').lang('%1 already exists as a file',$fileinfo['name']);
804                                }
805                                else
806                                {
807                                        echo lang('Error:').lang('Directory %1 already exists', $fileinfo['name']);
808                                }
809                        }
810                        else
811                        {
812                                if($this->bo->vfs->mkdir(array('string' => $this->filename)))
813                                {
814                                        echo lang('Created directory %1', $this->disppath.'/'.$this->filename);
815                                }
816                                else
817                                {
818                                        echo lang('Error:').lang('Could not create %1', $this->disppath.'/'.$this->filename);
819                                }
820                        }
821                        echo lang('Directory created');
822                }
823                function getReturnExecuteForm(){
824                        $response = $_SESSION['response'];
825                        $_SESSION['response'] = null;
826                        echo $response;
827                        return;
828                }
829                function showUploadboxes()
830                {
831                        $GLOBALS['phpgw_info']['flags'] = array
832                                (
833                                        'currentapp'    => 'filemanager',
834                                        'noheader'      => True,
835                                        'nonavbar' => True,
836                                        'nofooter'      => True,
837                                        'noappheader'   => True
838                                );
839                        $GLOBALS['phpgw']->common->phpgw_header();
840
841                        $this->t->set_file(array('upload' => 'upload.tpl'));
842                        $this->t->set_block('upload','upload_header','upload_header');
843                        $this->t->set_block('upload','row','row');
844                        $this->t->set_block('upload','upload_footer','upload_footer');
845
846                        if($this->path != '/' && $this->path != $this->bo->fakebase)
847                        {
848                                $vars[max_size]=lang('Note: Uploaded is limited to %1MB',($this->current_config['filemanager_Max_file_size']));
849                                $vars[form_action]=$GLOBALS[phpgw]->link('/filemanager/inc/upload.php');
850                                //$vars[form_action]=$GLOBALS[phpgw]->link('/index.php','menuaction=filemanager.uifilemanager.index');
851                                $vars[path]=$this->path;
852                                $vars[lang_file]=lang('File');
853                                $vars[lang_comment]=lang('Comment');
854                                $vars[lang_advanced_upload]=lang('Advanced Upload');
855                                $vars[num_upload_boxes]=1;
856                                $this->t->set_var($vars);
857                                $this->t->pparse('out','upload_header');
858
859                                $this->t->set_var('row_tr_color',$tr_color);
860                                $this->t->parse('rows','row');
861                                $this->t->pparse('out','row');
862
863                                $vars[lang_upload]=lang('Upload files');
864                                $vars[change_upload_boxes].=lang('Show') . '&nbsp;';
865                                $this->t->set_var($vars);
866                                $this->t->pparse('out','upload_footer');
867                        }
868                }
869
870                /* create textfile */
871                function createfile()
872                {
873                        $this->filename=$this->newfile_or_dir;
874                        if($this->filename)
875                        {
876                                if($badchar = $this->bo->bad_chars($this->filename, True, True))
877                                {
878                                        $this->messages[] = lang('Error:').lang('File names cannot contain "%1"',$badchar);
879
880                                        $this->fileListing();
881                                }
882
883                                if($this->bo->vfs->file_exists(array(
884                                        'string'=> $this->filename,
885                                        'relatives'     => array(RELATIVE_ALL)
886                                )))
887                                {
888                                        $this->messages[]= lang('Error:').lang('File %1 already exists. Please edit it or delete it first.', $this->filename);
889                                        $this->fileListing();
890                                }
891
892                                if($this->bo->vfs->touch(array(
893                                        'string'        => $this->filename,
894                                        'relatives'     => array(RELATIVE_ALL)
895                                )))
896                                {
897                                        $this->edit = 1;
898                                        $this->numoffiles++;
899                                        $this->edit();
900                                }
901                                else
902                                {
903                                        $this->messages[]= lang('Error:').lang('File %1 could not be created.', $this->filename);
904                                        $this->fileListing();
905                                }
906                        }
907                }
908
909                # Handle Editing files
910                function edit()
911                {
912                        if($this->filename)
913                        {
914                                if (! $this->vfs_functions->verifyLock($this->path.'/'.$this->filename,RELATIVE_NONE)){
915                                        $GLOBALS['phpgw']->redirect('/index.php');
916                                }
917                                $ls_array = $this->bo->vfs->ls(array(
918                                        'string'        => $this->path.'/'.$this->filename,
919                                        'relatives'     => array(RELATIVE_NONE),
920                                        'checksubdirs'  => False,
921                                        'nofiles'       => True
922                                ));
923                                $this->bo->vfs->touch(array(
924                                        'string'=> $this->path.'/'.$this->filename,
925                                        'relatives'     => array(RELATIVE_NONE)
926                                ));
927
928
929                                if($ls_array[0]['mime_type'])
930                                {
931                                        $mime_type = $ls_array[0]['mime_type'];
932                                }
933                                elseif($this->prefs['viewtextplain'])
934                                {
935                                        $mime_type = 'text/plain';
936                                }
937                                $editable = array('','text/plain','text/csv','text/html','text/text','message/rfc822');
938
939                                if(!in_array($mime_type,$editable)){
940                                        $this->messages[] = lang('Error:').lang('Impossible to edit this file');
941                                        $this->readFilesInfo();
942                                        $this->fileListing();
943                                        return;
944                                }
945                        }
946
947                        $this->readFilesInfo();
948
949                        if ($mime_type == 'text/html')
950                                $this->t->set_file(array('filemanager_edit' => 'edit_html.tpl'));
951                        else
952                                $this->t->set_file(array('filemanager_edit' => 'edit_file.tpl'));
953
954                        $this->t->set_block('filemanager_edit','row','row');
955
956
957                        $vars[refresh_script] = "<script src='filemanager/js/refresh.js'></script>";
958
959                        $vars[preview_content]='';
960                        if($this->edit_file)
961                        {
962                                $this->edit_file_content = stripslashes($this->edit_file_content);
963                        }
964
965                        if($this->edit_preview_x)
966                        {
967                                $content = $this->edit_file_content;
968
969                                $vars[lang_preview_of]=lang('Preview of %1', $this->path.'/'.$edit_file);
970
971                                $vars[preview_content]=nl2br($content);
972                        }
973                        elseif($this->edit_save_x || $this->edit_save_done_x)
974                        {
975                                $content = $this->edit_file_content;
976                                //die( $content);
977                                if($this->bo->vfs->write(array(
978                                        'string'        => $this->path.'/'.$this->edit_file,
979                                        'relatives'     => array(RELATIVE_NONE),
980                                        'content'       => $content
981                                )))
982                                {
983                                        $this->messages[]=lang('Saved %1', $this->path.'/'.$this->edit_file);
984
985                                        if($this->edit_save_done_x)
986                                        {
987                                                $this->readFilesInfo();
988                                                $this->fileListing();
989                                                exit;
990                                        }
991                                }
992                                else
993                                {
994                                        $this->messages[]=lang('Could not save %1', $this->path.'/'.$this->edit_file);
995                                }
996                        }
997
998                        # If we're in preview or save mode, we only show the file
999                        # being previewed or saved
1000                        if($this->edit_file &&($this->filename != $this->edit_file))
1001                        {
1002                                continue;
1003                        }
1004
1005                        if($this->filename && $this->bo->vfs->file_exists(array(
1006                                'string'        => $this->filename,
1007                                'relatives'     => array(RELATIVE_ALL)
1008                        )))
1009                        {
1010                                if($this->edit_file)
1011                                {
1012                                        $content = stripslashes($this->edit_file_content);
1013                                }
1014                                else
1015                                {
1016                                        $content = $this->bo->vfs->read(array('string' => $this->filename));
1017                                }
1018                                $vars[form_action]= $GLOBALS['phpgw']->link('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->path);
1019                                $vars[edit_file]=$this->filename;
1020                                # We need to include all of the fileman entries for each file's form,
1021                                # so we loop through again
1022                                for($i = 0; $i != $this->numoffiles; $i++)
1023                                {
1024                                        if($this->filename) $value='value="'.$this->filename.'"';
1025                                        $vars[filemans_hidden]='<input type="hidden" name="filename" '.$value.' />';
1026                                }
1027                                $vars[file_content]=$content;
1028
1029                                $vars[buttonPreview]=$this->inputButton('edit_preview','edit_preview',lang('Preview %1', $this->bo->html_encode($this->fileman[0], 1)));
1030                                $vars[buttonSave]=$this->inputButton('edit_save','save',lang('Save %1', $this->bo->html_encode($this->filename, 1)));
1031                                $vars[buttonDone]=$this->inputButton('edit_save_done','ok',lang('Save %1, and go back to file listing ', $this->bo->html_encode($this->filename, 1)));
1032                                $vars[buttonCancel]=$this->inputButton('edit_cancel','cancel',lang('Cancel editing %1 without saving', $this->bo->html_encode($this->filename, 1)));
1033
1034                                if ($mime_type == 'text/html'){
1035                                        $vars[fck_edit] = '<script type="text/javascript" src="filemanager/tp/ckeditor/ckeditor.js"></script>
1036                                                <textarea cols="80" id="edit_file_content" name="edit_file_content" rows="10">'.$content.'</textarea>
1037                                                <script type="text/javascript"> CKEDITOR.replace( \'edit_file_content\',{
1038removePlugins : \'elementspath\',
1039skin : \'office2003\',
1040toolbar : [["Source","Preview","-","Cut","Copy","Paste","-","Print",
1041"Undo","Redo","-","Find","Replace","-","SelectAll" ],
1042["Table","HorizontalRule","Smiley","SpecialChar","PageBreak","-","Bold",
1043"Italic","Underline","Strike","-","Subscript","Superscript",
1044"NumberedList","BulletedList","-","Outdent","Indent","Blockquote",
1045"JustifyLeft","JustifyCenter","JustifyRight","JustifyBlock",
1046"Link", "TextColor","BGColor","Maximize"],
1047["Styles","Format","Font","FontSize"]]
1048                                });</script>';
1049
1050                                }
1051
1052
1053                                $this->t->set_var($vars);
1054                                $this->t->parse('rows','row');
1055                                $this->t->pparse('out','row');
1056
1057                        }
1058
1059                }
1060
1061                function history()
1062                {
1063                        if($this->file) // FIXME this-file is never defined
1064                        {
1065                                $journal_array = $this->bo->vfs->get_journal(array(
1066                                        'string'        => $this->file,//FIXME
1067                                        'relatives'     => array(RELATIVE_ALL)
1068                                ));
1069
1070                                if(is_array($journal_array))
1071                                {
1072                                        $this->html_table_begin();
1073                                        $this->html_table_row_begin();
1074                                        $this->html_table_col_begin();
1075                                        echo lang('Date');
1076                                        $this->html_table_col_end();
1077                                        $this->html_table_col_begin();
1078                                        echo lang('Version');
1079                                        $this->html_table_col_end();
1080                                        $this->html_table_col_begin();
1081                                        echo lang('Who');
1082                                        $this->html_table_col_end();
1083                                        $this->html_table_col_begin();
1084                                        echo lang('Operation');
1085                                        $this->html_table_col_end();
1086                                        $this->html_table_row_end();
1087
1088                                        while(list($num, $journal_entry) = each($journal_array))
1089                                        {
1090                                                $this->html_table_row_begin();
1091                                                $this->html_table_col_begin();
1092                                                $this->bo->html_text($journal_entry['created'] . '&nbsp;&nbsp;&nbsp;');
1093                                                $this->html_table_col_end();
1094                                                $this->html_table_col_begin();
1095                                                $this->bo->html_text($journal_entry['version'] . '&nbsp;&nbsp;&nbsp;' );
1096                                                $this->html_table_col_end();
1097                                                $this->html_table_col_begin();
1098                                                $this->bo->html_text($GLOBALS['phpgw']->accounts->id2name($journal_entry['owner_id']) . '&nbsp;&nbsp;&nbsp;');
1099                                                $this->html_table_col_end();
1100                                                $this->html_table_col_begin();
1101                                                $this->bo->html_text($journal_entry['comment']);
1102                                                $this->html_table_col_end();
1103                                        }
1104
1105                                        $this->html_table_end();
1106                                        $GLOBALS['phpgw']->common->phpgw_footer();
1107                                        $GLOBALS['phpgw']->common->phpgw_exit();
1108                                }
1109                                else
1110                                {
1111                                        echo lang('No version history for this file/directory');
1112                                }
1113                        }
1114                }
1115                function view()
1116                {
1117                        if (!$this->bo->vfs->acl_check(array(
1118                                'string'        => $this->path,
1119                                'relatives'     => array(RELATIVE_NONE),
1120                                'operation'     => PHPGW_ACL_READ
1121                        )))
1122                        {
1123                                $this->messages[] = lang("You have no permission to access this file");
1124                                header('Location:'.$this->encode_href('inc/index.php?menuaction=filemanager.uifilemanager.index','&path='.base64_encode($this->bo->homedir)));
1125
1126                                return;
1127                        }
1128                        if($this->file) //FIXME
1129                        {
1130                                $ls_array = $this->bo->vfs->ls(array(
1131                                        'string'        => $this->path.'/'.$this->file,//FIXME
1132                                        'relatives'     => array(RELATIVE_NONE),
1133                                        'checksubdirs'  => False,
1134                                        'nofiles'       => True
1135                                ));
1136                                if($ls_array[0]['mime_type'])
1137                                {
1138                                        $mime_type = $ls_array[0]['mime_type'];
1139                                }
1140                                elseif($this->prefs['viewtextplain'])
1141                                {
1142                                        $mime_type = 'text/plain';
1143                                }
1144                                $viewable = array('text/plain','text/csv','text/html',
1145                                        'text/text','image/jpeg','image/png','image/gif',
1146                                        'audio/mpeg','video/mpeg');
1147
1148                                if(in_array($mime_type,$viewable))
1149                                {
1150                                        /*Note: if you put application/octet-stream you force download */
1151                                        header('Content-type: ' . $mime_type);
1152                                        header('Content-disposition: filename="' . addslashes($this->file) . '"');
1153                                        Header("Pragma: public");
1154                                }
1155                                else
1156                                {
1157                                        $GLOBALS['phpgw']->browser->content_header($this->file,$mime_type,$ls_array[0]['size']);
1158                                }
1159                                if ($ls_array[0]['size'] < 10240)
1160                                {
1161                                        echo $this->bo->vfs->read(array(
1162                                                'string'    => $this->path.'/'.$this->file,//FIXME
1163                                                'relatives'    => array(RELATIVE_NONE)
1164                                        ));
1165                                }
1166                                else
1167                                {
1168                                        $this->bo->vfs->print_content(array(
1169                                                'string' => $this->path.'/'.$this->file,
1170                                                'relatives' => array(RELATIVE_NONE)
1171                                        )
1172                                );
1173                                }
1174                                $GLOBALS['phpgw']->common->phpgw_exit();
1175                        }
1176                }
1177
1178                function export(){
1179                        if($this->file)
1180                        {
1181                                $ls_array = $this->bo->vfs->ls(array(
1182                                        'string'        => $this->path.'/'.$this->file,
1183                                        'relatives'     => array(RELATIVE_NONE),
1184                                        'checksubdirs'  => False,
1185                                        'nofiles'       => True
1186                                ));
1187                                /*$timestamp = $this->vfs_functions->dateString2timeStamp($ls_array[0]['modified']);
1188                                if (time() - $timestamp < 60 && $ls_array[0]['modifiedby_id'] != $GLOBALS['phpgw_info']['user']['account_id']);
1189                                {
1190                                        // recently than last minute: someone is editing
1191                                }*/
1192                                $mime_type = $ls_array[0]['mime_type'];
1193                                $formats = array('text/html');
1194                                if(!in_array($mime_type,$formats)){
1195                                        echo lang('Impossible to export this file');
1196                                        return False;
1197                                }
1198                                $content = $this->bo->vfs->read(array('string' => $this->path.'/'.$this->file,
1199                                               'relatives'     => array(RELATIVE_NONE)
1200                                       ));
1201
1202                                include_once('filemanager/tp/dompdf/dompdf_config.inc.php');
1203                                $dompdf = new DOMPDF();
1204                                $dompdf->load_html($content);
1205                                $dompdf->set_paper($this->prefs['pdf_paper_type'], $this->prefs['pdf_type']);
1206                                /* Would be nice to implement 'Title','Subject','Author','Creator','CreationDate'*/
1207                                $dompdf->render();
1208                                $dompdf->stream(strtok($this->file,'.').".pdf");
1209                                $GLOBALS['phpgw']->common->phpgw_exit();
1210                        }
1211                }
1212
1213                //give back an array with all directories except current and dirs that are not accessable
1214                function all_other_directories()
1215                {
1216                        # First we get the directories in their home directory
1217                        $dirs = array();
1218                        $dirs[] = array('directory' => $this->bo->fakebase, 'name' => $this->bo->userinfo['account_lid']);
1219
1220                        $tmp_arr=array(
1221                                'string'        => $this->bo->homedir,
1222                                'relatives'     => array(RELATIVE_NONE),
1223                                'checksubdirs'  => True,
1224                                'mime_type'     => 'Directory'
1225                        );
1226
1227                        $ls_array = $this->bo->vfs->ls($tmp_arr,True);
1228
1229                        while(list($num, $dir) = each($ls_array))
1230                        {
1231                                $dirs[] = $dir;
1232                        }
1233
1234
1235                        # Then we get the directories in their readable groups' home directories
1236                        reset($this->readable_groups);
1237                        while(list($num, $group_array) = each($this->readable_groups))
1238                        {
1239                                // Don't list directories for groups that don't exists
1240                                $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->fakebase.'/'.$group_array['account_name'],
1241                                        'relatives' => array(RELATIVE_NONE), 'relative' => False));
1242                                if($test[mime_type]!='Directory')
1243                                {
1244                                        continue;
1245                                }
1246
1247                                $dirs[] = array('directory' => $this->bo->fakebase, 'name' => $group_array['account_name']);
1248
1249                                $tmp_arr=array(
1250                                        'string'        => $this->bo->fakebase.'/'.$group_array['account_name'],
1251                                        'relatives'     => array(RELATIVE_NONE),
1252                                        'checksubdirs'  => True,
1253                                        'mime_type'     => 'Directory'
1254                                );
1255
1256                                $ls_array = $this->bo->vfs->ls($tmp_arr,True);
1257                                while(list($num, $dir) = each($ls_array))
1258                                {
1259                                        $dirs[] = $dir;
1260                                }
1261                        }
1262                        reset($dirs);
1263                        while(list($num, $dir) = each($dirs))
1264                        {
1265                                if(!$dir['directory'])
1266                                {
1267                                        continue;
1268                                }
1269
1270                                # So we don't display //
1271                                if($dir['directory'] != '/')
1272                                {
1273                                        $dir['directory'] .= '/';
1274                                }
1275                                $return[] = $dir;
1276                        }
1277                        return $return;
1278                }
1279
1280                function update_groups()
1281                {
1282                        # Get their readable groups to be used throughout the script
1283                        $acl = array();
1284                        $groups = array();
1285                        $acl = $GLOBALS['phpgw']->acl->get_ids_for_location($GLOBALS['phpgw_info']['user']['account_id'],1,'filemanager');
1286                        if (is_array($acl))
1287                                foreach($acl as $key => $value){
1288                                        $info = array();
1289                                        $info = $GLOBALS['phpgw']->accounts->get_account_data($value);
1290                                        $groups[$key]['account_id'] = $value;
1291                                        $groups[$key]['account_lid'] = $info[$value]['lid'];
1292                                        $groups[$key]['account_name'] = $info[$value]['firstname'];
1293                                        $groups[$key]['account_lastname'] = $info[$value]['lastname'];
1294                                        $groups[$key]['account_fullname'] = $info[$value]['fullname'];
1295                                }
1296                        $this->readable_groups = array();
1297                        while(list($num, $account) = each($groups))
1298                        {
1299                                if($this->bo->vfs->acl_check(array('owner_id' => $account['account_id'],'operation' => PHPGW_ACL_READ)))
1300                                {
1301                                        $this->readable_groups[$account['account_lid']] = Array('account_id' => $account['account_id'], 'account_name' => $account['account_lid']);
1302                                }
1303                        }
1304
1305                }
1306                function search()
1307                {
1308                        /* TODO this is a primitive search */
1309                        $this->update_groups();
1310                        $this->dirs = $this->all_other_directories();
1311                        $path = $this->path;
1312                        if (strlen($this->text) > 3)
1313                        {                                                               
1314                                $this->text = strtoupper($this->text);
1315                                foreach($this->dirs as $elem)
1316                                {
1317                                        $this->path = $elem['directory'].$elem['name'];
1318                                        reset($this->files_array);
1319                                        $this->readFilesInfo();
1320                                        for($i = 0; $i < count($this->files_array); $i++)
1321                                        {
1322                                                $comment = strtoupper($this->files_array[$i]['comment']);
1323                                                $name = strtoupper($this->files_array[$i]['name']);
1324                                                if (strstr($name,$this->text) ||
1325                                                strstr($comment,$this->text) ){
1326                                                        $return[$this->files_array[$i]['directory'].$name] = $this->files_array[$i];
1327                                                        $return[$this->files_array[$i]['directory'].$name]['icon'] = $this->mime_icon($this->files_array[$i]['mime_type']);
1328                                                }
1329                                        }
1330                                        if (count($return) > 50)
1331                                        {
1332                                                $return = array_slice($return,0,50);
1333                                                break;
1334                                        }
1335                                }       
1336                        }
1337                        echo serialize(array_values($return));
1338                }
1339
1340                /* seek icon for mimetype else return an unknown icon */
1341                function mime_icon($mime_type, $size=16)
1342                {
1343                        if(!$mime_type) $mime_type='unknown';
1344
1345                        $mime_type=str_replace  ('/','_',$mime_type);
1346
1347                        $img=$GLOBALS['phpgw']->common->image('filemanager','mime'.$size.'_'.strtolower($mime_type));
1348                        if(!$img) $img=$GLOBALS['phpgw']->common->image('filemanager','mime'.$size.'_unknown');
1349
1350                        return $img;
1351                }
1352
1353                function toolButton($link,$img='',$description='')
1354                {
1355                        $image=$GLOBALS['phpgw']->common->image('filemanager','button_'.strtolower($img));
1356
1357                        if($img)
1358                        {
1359                                return '<span name="'.$link.'" class="toolButton" onclick="toolbar.control(\''.$link.'\',this);" title="'.$description.'"><img src="'.$image.'" alt="'.$description.'"/></a><small>'.$description.'</small></span>';
1360                        }
1361                }
1362
1363                function inputButton($name,$img='',$description='')
1364                {
1365                        $image=$GLOBALS['phpgw']->common->image('filemanager','button_'.strtolower($img));
1366
1367                        if($img)
1368                        {
1369                                return '<td class="" align="center" valign="middle" height="28" width="70">
1370                                <input title="'.$description.'" name="'.$name.'" type="image" alt="'.$name.'" src="'.$image.'" value="clicked" /><br><small>'.$description.'</small>
1371                                </td>';
1372                        }
1373                }
1374
1375
1376                function html_form_input($type = NULL, $name = NULL, $value = NULL, $maxlength = NULL, $size = NULL, $checked = NULL, $string = '', $return = 1)
1377                {
1378                        $text = ' ';
1379                        if($type != NULL && $type)
1380                        {
1381                                if($type == 'checkbox')
1382                                {
1383                                        $value = $this->bo->string_encode($value, 1);
1384                                }
1385                                $text .= 'type="'.$type.'" ';
1386                        }
1387                        if($name != NULL && $name)
1388                        {
1389                                $text .= 'name="'.$name.'" ';
1390                        }
1391                        if($value != NULL && $value)
1392                        {
1393                                $text .= 'value="'.$value.'" ';
1394                        }
1395                        if(is_int($maxlength) && $maxlength >= 0)
1396                        {
1397                                $text .= 'maxlength="'.$maxlength.'" ';
1398                        }
1399                        if(is_int($size) && $size >= 0)
1400                        {
1401                                $text .= 'size="'.$size.'" ';
1402                        }
1403                        if($checked != NULL && $checked)
1404                        {
1405                                $text .= 'checked ';
1406                        }
1407
1408                        return '<input'.$text.$string.'>';
1409                }
1410
1411                function html_form_option($value = NULL, $displayed = NULL, $selected = NULL, $return = 0)
1412                {
1413                        $text = ' ';
1414                        if($value != NULL && $value)
1415                        {
1416                                $text .= ' value="'.$value.'" ';
1417                        }
1418                        if($selected != NULL && $selected)
1419                        {
1420                                $text .= ' selected';
1421                        }
1422                        return  '<option'.$text.'>'.$displayed.'</option>';
1423                }
1424
1425                function encode_href($href = NULL, $args = NULL , $extra_args)
1426                {
1427                        $href = $this->bo->string_encode($href, 1);
1428                        $all_args = $args.'&'.$this->bo->string_encode($extra_args, 1);
1429
1430                        $address = $GLOBALS['phpgw']->link($href, $all_args);
1431
1432                        return $address;
1433                }
1434
1435                function html_link($href = NULL, $args = NULL , $extra_args, $text = NULL, $return = 1, $encode = 1, $linkonly = 0, $target = NULL)
1436                {
1437                        //      unset($encode);
1438                        if($encode)
1439                        {
1440                                $href = $this->bo->string_encode($href, 1);
1441                                $all_args = $args.'&'.$this->bo->string_encode($extra_args, 1);
1442                        }
1443                        else
1444                        {
1445                                //                              $href = $this->bo->string_encode($href, 1);
1446                                $all_args = $args.'&'.$extra_args;
1447                        }
1448                        ###
1449                        # This decodes / back to normal
1450                        ###
1451                        //                      $all_args = preg_replace("/%2F/", "/", $all_args);
1452                        //                      $href = preg_replace("/%2F/", "/", $href);
1453
1454                        /* Auto-detect and don't disturb absolute links */
1455                        if(!preg_match("|^http(.{0,1})://|", $href))
1456                        {
1457                                //Only add an extra / if there isn't already one there
1458
1459                                // die(SEP);
1460                                if(!($href[0] == SEP))
1461                                {
1462                                        $href = SEP . $href;
1463                                }
1464
1465                                /* $phpgw->link requires that the extra vars be passed separately */
1466                                //                              $link_parts = explode("?", $href);
1467                                $address = $GLOBALS['phpgw']->link($href, $all_args);
1468                                //                              $address = $GLOBALS['phpgw']->link($href);
1469                        }
1470                        else
1471                        {
1472                                $address = $href;
1473                        }
1474
1475                        /* If $linkonly is set, don't add any HTML */
1476                        if($linkonly)
1477                        {
1478                                $rstring = $address;
1479                        }
1480                        else
1481                        {
1482                                if($target)
1483                                {
1484                                        $target = 'target='.$target;
1485                                }
1486
1487                                $text = trim($text);
1488                                $rstring = '<a href="'.$address.'" '.$target.'>'.$text.'</a>';
1489                        }
1490
1491                        return($this->bo->eor($rstring, $return));
1492                }
1493
1494                function html_table_begin($width = NULL, $border = NULL, $cellspacing = NULL, $cellpadding = NULL, $rules = NULL, $string = '', $return = 0)
1495                {
1496                        if($width != NULL && $width)
1497                        {
1498                                $width = "width=$width";
1499                        }
1500                        if(is_int($border) && $border >= 0)
1501                        {
1502                                $border = "border=$border";
1503                        }
1504                        if(is_int($cellspacing) && $cellspacing >= 0)
1505                        {
1506                                $cellspacing = "cellspacing=$cellspacing";
1507                        }
1508                        if(is_int($cellpadding) && $cellpadding >= 0)
1509                        {
1510                                $cellpadding = "cellpadding=$cellpadding";
1511                        }
1512                        if($rules != NULL && $rules)
1513                        {
1514                                $rules = "rules=$rules";
1515                        }
1516
1517                        $rstring = "<table $width $border $cellspacing $cellpadding $rules $string>";
1518                        return($this->bo->eor($rstring, $return));
1519                }
1520
1521                function html_table_end($return = 0)
1522                {
1523                        $rstring = "</table>";
1524                        return($this->bo->eor($rstring, $return));
1525                }
1526
1527                function html_table_row_begin($align = NULL, $halign = NULL, $valign = NULL, $bgcolor = NULL, $string = '', $return = 0)
1528                {
1529                        if($align != NULL && $align)
1530                        {
1531                                $align = "align=$align";
1532                        }
1533                        if($halign != NULL && $halign)
1534                        {
1535                                $halign = "halign=$halign";
1536                        }
1537                        if($valign != NULL && $valign)
1538                        {
1539                                $valign = "valign=$valign";
1540                        }
1541                        if($bgcolor != NULL && $bgcolor)
1542                        {
1543                                $bgcolor = "bgcolor=$bgcolor";
1544                        }
1545                        $rstring = "<tr $align $halign $valign $bgcolor $string>";
1546                        return($this->bo->eor($rstring, $return));
1547                }
1548
1549                function html_table_row_end($return = 0)
1550                {
1551                        $rstring = "</tr>";
1552                        return($this->bo->eor($rstring, $return));
1553                }
1554
1555                function html_table_col_begin($align = NULL, $halign = NULL, $valign = NULL, $rowspan = NULL, $colspan = NULL, $string = '', $return = 0)
1556                {
1557                        if($align != NULL && $align)
1558                        {
1559                                $align = "align=$align";
1560                        }
1561                        if($halign != NULL && $halign)
1562                        {
1563                                $halign = "halign=$halign";
1564                        }
1565                        if($valign != NULL && $valign)
1566                        {
1567                                $valign = "valign=$valign";
1568                        }
1569                        if(is_int($rowspan) && $rowspan >= 0)
1570                        {
1571                                $rowspan = "rowspan=$rowspan";
1572                        }
1573                        if(is_int($colspan) && $colspan >= 0)
1574                        {
1575                                $colspan = "colspan=$colspan";
1576                        }
1577
1578                        $rstring = "<td $align $halign $valign $rowspan $colspan $string>";
1579                        return($this->bo->eor($rstring, $return));
1580                }
1581
1582                function html_table_col_end($return = 0)
1583                {
1584                        $rstring = "</td>";
1585                        return($this->bo->eor($rstring, $return));
1586                }
1587        }
Note: See TracBrowser for help on using the repository browser.