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

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

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