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

Revision 3568, 48.4 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #1395 - Corrigido o path para o carregamento dinamico dos temas setados nas preferencias.

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