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

Revision 3541, 47.7 KB checked in by rodsouza, 13 years ago (diff)

Ticket #1371 - Corrige problema de reconstrução recursiva de pastas

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