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

Revision 1922, 47.1 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Melhorias na visualização dos arquivos

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