source: trunk/filemanager/inc/class.uifilemanager.inc.php @ 2851

Revision 2851, 46.7 KB checked in by amuller, 14 years ago (diff)

Ticket #1086 - Desfazendo erros no commit anterior

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