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

Revision 1678, 61.4 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Integração com antivirus, e gestão de quotas

  • 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                        'uploadModel'=>True
31                );
32
33                //keep
34                var $bo;
35                var $vfs_functions;
36                var $t; //template object
37                var $dispath;
38                var $cwd;
39                var $lesspath;
40                var $readable_groups;
41                var $files_array;
42                var $numoffiles;
43                var $dispsep;
44
45                var $target;
46
47                var $prefs;//array
48
49                var $groups_applications;
50
51                //originally post_vars
52                //              var $goto;
53                var $current_config;
54                var $goto_x;
55                var $todir;
56                var $changedir; // for switching dir.
57                var $cdtodir; // for switching dir.
58//              var $createdir;
59                var $newfile_or_dir;
60                var $newdir_x;
61                var $newfile_x;
62                var $createfile_var;
63                var $move_to_x;
64//              var $copy_to;
65                var $copy_to_x;
66                var $edit_x;
67                var $edit_file;
68                var $edit_preview_x;
69                var $edit_save_x;
70                var $edit_save_done_x;
71                var $edit_cancel_x;
72                var $comment_files;
73                var $upload_x;
74                var $uploadprocess;
75
76                // this ones must be checked thorougly;
77                var $fileman = Array();
78                //var $fileman;
79                var $path;
80                var $file; // FIXME WHERE IS THIS FILLED?
81                var $sortby;
82                var $messages = array();
83                var $show_upload_boxes;
84
85                var $now;
86
87                function uifilemanager()
88                {
89                        //                      error_reporting(8);
90                        $GLOBALS['phpgw']->browser = CreateObject('phpgwapi.browser');
91
92                        $this->now = date('Y-m-d');
93
94                        $this->bo = CreateObject('filemanager.bofilemanager');
95
96                        $this->vfs_functions = CreateObject('filemanager.vfs_functions');
97
98                        $this->t = $GLOBALS['phpgw']->template;
99                        $c = CreateObject('phpgwapi.config','filemanager');
100                        $c->read_repository();
101                        $this->current_config = $c->config_data;
102
103
104                        // here local vars are created from the HTTP vars
105                        @reset($GLOBALS['HTTP_POST_VARS']);
106                        while(list($name,) = @each($GLOBALS['HTTP_POST_VARS']))
107                        {
108                                $this->$name = $GLOBALS['HTTP_POST_VARS'][$name];
109                        }
110
111                        @reset($GLOBALS['HTTP_GET_VARS']);
112                        while(list($name,) = @each($GLOBALS['HTTP_GET_VARS']))
113                        {
114                                $$name = $GLOBALS['HTTP_GET_VARS'][$name];
115                                $this->$name = $GLOBALS['HTTP_GET_VARS'][$name];
116
117                        }
118
119                        $to_decode = array
120                        (
121                                'op'    => array('op' => ''),
122                                'path'  => array('path' => ''),
123                                'filename' => array('filename' => ''),
124                                'file'  => array('file' => ''),
125                                'sortby'        => array('sortby' => ''),
126                                'messages'      => array('messages'     => ''),
127                                'comment_files' => array('comment_files' => ''),
128                                'show_upload_boxes'     => array('show_upload_boxes' => '')
129                        );
130
131                        reset($to_decode);
132                        while(list($var, $conditions) = each($to_decode))
133                        {
134                                while(list($condvar, $condvalue) = each($conditions))
135                                {
136                                        if(isset($$condvar) && ($condvar == $var || $$condvar == $condvalue))
137                                        {
138                                                if(is_array($$var))
139                                                {
140                                                        $temp = array();
141                                                        while(list($varkey, $varvalue) = each($$var))
142                                                        {
143                                                                if(is_int($varkey))
144                                                                {
145                                                                        $temp[$varkey] = stripslashes(base64_decode(urldecode(($varvalue))));
146                                                                }
147                                                                else
148                                                                {
149                                                                        $temp[stripslashes(base64_decode(urldecode(($varkey))))] = $varvalue;
150                                                                }
151                                                        }
152                                                        $this->$var = $temp;
153                                                }
154                                                elseif(isset($$var))
155                                                {
156                                                        $this->$var = stripslashes(base64_decode(urldecode($$var)));
157                                                }
158                                        }
159                                }
160                        }
161
162                        // get appl. and user prefs
163                        $pref = CreateObject('phpgwapi.preferences', $this->bo->userinfo['username']);
164                        $pref->read_repository();
165                        //                      $GLOBALS['phpgw']->hooks->single('add_def_pref', $GLOBALS['appname']);
166                        $pref->save_repository(True);
167                        $pref_array = $pref->read_repository();
168                        $this->prefs = $pref_array[$this->bo->appname]; //FIXME check appname var in _debug_array
169
170                        //always show name
171
172                        $this->prefs[name] =1;
173
174
175                        if($this->prefs['viewinnewwin'])
176                        {
177                                $this->target = '_blank';
178                        }
179
180
181                        /*
182                                Check for essential directories
183                                admin must be able to disable these tests
184                        */
185                       
186                        // check if basedir exist
187                        $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
188                        if($test[mime_type]!='Directory')
189                        {
190                                die('Base directory does not exist, Ask adminstrator to check the global configuration.');
191                        }
192
193                        $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->fakebase, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
194                        if($test[mime_type]!='Directory')
195                        {
196
197                                $this->bo->vfs->override_acl = 1;
198
199                                $this->bo->vfs->mkdir(array(
200                                        'string' => $this->bo->fakebase,
201                                        'relatives' => array(RELATIVE_NONE)
202                                ));
203                               
204                                $this->bo->vfs->override_acl = 0;
205
206                                //test one more time
207                                $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->fakebase, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
208
209                                if($test[mime_type]!='Directory')
210                                {
211                                        die('Fake Base directory does not exist and could not be created, please ask the administrator to check the global configuration.');
212                                }
213                                else
214                                {
215                                        $this->messages[]= lang('Fake Base Dir did not exist, eGroupWare created a new one.');
216                                }
217                        }
218
219                        $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->homedir, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
220                        if($test[mime_type]!='Directory')
221                        {
222                                $this->bo->vfs->override_acl = 1;
223
224                                $this->bo->vfs->mkdir(array(
225                                        'string' => $this->bo->homedir,
226                                        'relatives' => array(RELATIVE_NONE)
227                                ));
228                                $this->bo->vfs->set_quota(array(
229                                        'string' => $this->bo->homedir,
230                                        'relatives' => array(RELATIVE_NONE),
231                                        'new_quota' => $this->current_config['filemanager_quota_size']
232                                ));
233       
234                                $this->bo->vfs->override_acl = 0;
235
236                                //test one more time
237                                $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->homedir, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
238
239                                if($test[mime_type]!='Directory')
240                                {
241                                        die('Your Home Dir does not exist and could not be created, please ask the adminstrator to check the global configuration.');
242                                }
243                                else
244                                {
245                                        $this->messages[]= lang('Your Home Dir did not exist, eGroupWare created a new one.');
246                                        // FIXME we just created a fresh home dir so we know there nothing in it so we have to remove all existing content
247                                }
248                        }
249                       
250                       
251                }
252                function fileModels()
253                {
254                        $GLOBALS['phpgw_info']['flags'] = array
255                                (
256                                        'currentapp'    => 'filemanager',
257                                        'noheader'      => False,
258                                        'nonavbar' => False,
259                                        'nofooter'      => False,
260                                        'noappheader'   => False,
261                                        'enable_browser_class'  => True
262                                );
263
264                        $GLOBALS['phpgw']->common->phpgw_header();
265                        $this->t->set_file(array('models' => 'fileModels.tpl'));
266                        $this->t->set_block('models','header','header');
267                        $this->t->set_block('models','body','body');
268                        $this->t->set_block('models','footer','footer');
269                        $this->t->set_var('url_1', './index.php?menuaction=filemanager.uifilemanager.uploadModel&model=article');
270                        $this->t->set_var('model_1','article');
271                        $this->t->set_var('lang_1',lang('article'));
272
273                        $this->t->set_var('url_2','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=calendar');
274                        $this->t->set_var('model_2','calendar');
275                        $this->t->set_var('lang_2',lang('calendar'));
276
277                        $this->t->set_var('url_3','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=todo');
278                        $this->t->set_var('model_3','todo');
279                        $this->t->set_var('lang_3',lang('todo'));
280
281                        $this->t->set_var('url_4','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=slide');
282                        $this->t->set_var('model_4','slide');
283                        $this->t->set_var('lang_4',lang('slide'));
284
285                        $this->t->set_var('url_5','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=cards');
286                        $this->t->set_var('model_5','cards');
287                        $this->t->set_var('lang_5',lang('cards'));
288
289                        $this->t->set_var('url_6','./index.php?menuaction=filemanager.uifilemanager.uploadModel&model=resume');
290                        $this->t->set_var('model_6','resume');
291                        $this->t->set_var('lang_6',lang('resume'));
292
293
294                        $this->t->pparse('out','models');
295
296
297                }
298                function uploadModel(){
299                        $GLOBALS['phpgw_info']['flags'] = array
300                                (
301                                        'currentapp'    => 'filemanager',
302                                        'noheader'      => False,
303                                        'nonavbar' => False,
304                                        'nofooter'      => False,
305                                        'noappheader'   => False,
306                                        'enable_browser_class'  => True
307                                );
308
309                        $GLOBALS['phpgw']->common->phpgw_header();
310
311                        $filename = lang('new')."_".lang($this->model).rand(0,1000).".html";
312                        $this->bo->vfs->cp(array(
313                                'from'=> PHPGW_SERVER_ROOT . '/filemanager/templates/default/'.$this->model.'.html',
314                                'to'=> $filename,
315                                'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
316                        ));
317
318                        $this->bo->vfs->set_attributes(array(
319                                'string'=> $filename,
320                                'relatives'     => array(RELATIVE_ALL),
321                                'attributes'=> array(
322                                        'mime_type' => "text/html",
323                                        'comment' => ""
324                                )
325                        ));
326                        $this->filename = $filename;
327                        $this->edit();
328
329                }
330                function index()
331                {
332                        $GLOBALS['phpgw_info']['flags'] = array
333                        (
334                                'currentapp'    => 'filemanager',
335                                'noheader'      => False,
336                                'nonavbar' => False,
337                                'nofooter'      => False,
338                                'noappheader'   => False,
339                                'enable_browser_class'  => True
340                        );
341
342                        $GLOBALS['phpgw']->common->phpgw_header();
343
344                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/global.js'></script>";
345                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/main.js'></script>";
346                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/common_functions.js'></script>";
347                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/connector.js'></script>";
348                        echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/draw_api.js'></script>";
349                        include('load_lang.php');
350
351                        # Page to process users
352                        # Code is fairly hackish at the beginning, but it gets better
353                        # Highly suggest turning wrapping off due to long SQL queries
354
355                        ###
356                        # Some hacks to set and display directory paths correctly
357                        ###
358                        // new method for switching to a new dir.
359                        if($this->changedir=='true' && $this->cdtodir || $this->goto_x)
360                        {
361                                $this->path = $this->cdtodir;
362                        }
363
364                        if(!$this->path)
365                        {
366                                $this->path = $this->bo->vfs->pwd();
367
368                                if(!$this->path || $this->bo->vfs->pwd(array('full' => False)) == '')
369                                {
370                                        $this->path = $this->bo->homedir;
371                                }
372                        }
373
374                        $this->bo->vfs->cd(array('string' => False, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
375                        $this->bo->vfs->cd(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
376
377                        $pwd = $this->bo->vfs->pwd();
378
379                        if(!$this->cwd = substr($this->path, strlen($this->bo->homedir) + 1)) 
380                        {
381                                $this->cwd = '/';
382                        }
383                        else
384                        {
385                                $this->cwd = substr($pwd, strrpos($pwd, '/') + 1);
386                        }
387
388                        $this->disppath = $this->path;
389
390                        /* This just prevents // in some cases */
391                        if($this->path == '/')
392                        {
393                                $this->dispsep = '';
394                        }
395                        else
396                        {
397                                $this->dispsep = '/';
398                        }
399
400                        if(!($this->lesspath = substr($this->path, 0, strrpos($this->path, '/'))))
401                        {
402                                $this->lesspath = '/';
403                        }
404
405                        # Get their readable groups to be used throughout the script
406                        $acl = array();
407                        $groups = array();
408                        $acl = $GLOBALS['phpgw']->acl->get_ids_for_location($GLOBALS['phpgw_info']['user']['account_id'],1,'filemanager');
409                        if (is_array($acl))
410                                foreach($acl as $key => $value){
411                                        $info = array();
412                                        $info = $GLOBALS['phpgw']->accounts->get_account_data($value);
413                                        $groups[$key]['account_id'] = $value;
414                                        $groups[$key]['account_lid'] = $info[$value]['lid'];
415                                        $groups[$key]['account_name'] = $info[$value]['firstname'];
416                                        $groups[$key]['account_lastname'] = $info[$value]['lastname'];
417                                        $groups[$key]['account_fullname'] = $info[$value]['fullname'];
418                                }
419                        $this->readable_groups = array();
420                        while(list($num, $account) = each($groups))
421                        {
422                                if($this->bo->vfs->acl_check(array('owner_id' => $account['account_id'],'operation' => PHPGW_ACL_READ)))
423                                {
424                                        $this->readable_groups[$account['account_lid']] = Array('account_id' => $account['account_id'], 'account_name' => $account['account_lid']);
425                                }
426                        }
427
428                        $this->groups_applications = array();
429
430                        foreach ($this->readable_groups as $value)
431                        {
432                                $applications = CreateObject('phpgwapi.applications', $value['account_id']);
433                                $this->groups_applications[$value['account_name']] = $applications->read_account_specific();
434                        }
435
436                        # We determine if they're in their home directory or a group's directory,
437                        # and set the VFS working_id appropriately
438                        if((preg_match('+^'.$this->bo->fakebase.'\/(.*)(\/|$)+U', $this->path, $matches)) && $matches[1] != $this->bo->userinfo['account_lid']) //FIXME matches not defined
439
440                        {
441                                $this->bo->vfs->working_id = $GLOBALS['phpgw']->accounts->name2id($matches[1]);//FIXME matches not defined
442
443                        }
444                        else
445                        {
446                                $this->bo->vfs->working_id = $this->bo->userinfo['username'];
447                        }
448
449                        # Check available permissions for $this->path, so we can disable unusable operations in user interface
450                        $path = explode('/',$this->path);
451                        $owner_id = $this->bo->vfs->ownerOf($this->bo->fakebase,$path[2]);
452                        $user_id = $GLOBALS['phpgw_info']['user']['account_id'];
453                        if ($owner_id == $user_id)
454                        {
455                                $this->can_read = True;
456                                $this->can_add = True;
457                                $this->can_edit = True;
458                                $this->can_delete = True;
459                                $this->can_private = True;
460                        }else
461                        {
462                                $acl = CreateObject ('phpgwapi.acl', $owner_id);
463                                $acl->account_id = $owner_id;
464                                $acl->read_repository();
465                                $rights = $acl->get_rights($user_id);
466                                $this->can_read = $rights & PHPGW_ACL_READ;
467                                $this->can_add = $rights & PHPGW_ACL_ADD;
468                                $this->can_edit = $rights & PHPGW_ACL_EDIT;
469                                $this->can_delete = $rights & PHPGW_ACL_DELETE;
470                                $this->can_private = $rights & PHPGW_ACL_PRIVATE;
471                        }
472       
473                        # if is different path than home and no permission allowed
474                        if($this->path != $this->bo->homedir && $this->path != $this->bo->fakebase && $this->path != '/' && !$this->can_read)
475                        {
476                                echo lang('You do not have access to %1', $this->path);
477                                $this->html_link('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->homedir, lang('Go to your home directory'));
478
479                                $GLOBALS['phpgw']->common->phpgw_footer();
480                                $GLOBALS['phpgw']->common->phpgw_exit();
481                        }
482
483                        $this->bo->userinfo['working_id'] = $this->bo->vfs->working_id;
484                        $this->bo->userinfo['working_lid'] = $GLOBALS['phpgw']->accounts->id2name($this->bo->userinfo['working_id']);
485
486                        # Verify path is real
487                        if($this->path != $this->bo->homedir && $this->path != '/' && $this->path != $this->bo->fakebase)
488                        {
489                                if(!$this->bo->vfs->file_exists(array(
490                                        'string' => $this->path,
491                                        'relatives' => array(RELATIVE_NONE)
492                                )))
493                                {
494                                        $this->messages[] = lang('Error:').lang('Directory %1 does not exist', $this->path);
495                                        $this->html_link('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->bo->homedir, lang('Go to your home directory'));
496
497                                        $GLOBALS['phpgw']->common->phpgw_footer();
498                                        $GLOBALS['phpgw']->common->phpgw_exit();
499                                }
500                        }
501
502
503                        /* Update the vfs */
504                        if ($this->update_x == 'True')
505                        {
506                                $this->bo->vfs->update_real(array(
507                                        'string' => $this->path,
508                                        'relatives' => array(RELATIVE_ALL)
509                                ));
510                        }
511
512                        # Default is to sort by name
513                        if(!$this->sortby)
514                        {
515                                $this->sortby = 'name';
516                        }
517
518                        # main action switch
519                        // FIXME this will become a switch
520                        if($this->newfile_x && $this->newfile_or_dir) // create new textfile
521                        {
522                                $this->createfile();
523                        }
524                        elseif($this->newfile_or_dir && $this->newdir_x)
525                        {
526                                $this->createdir();
527                        }
528                        elseif($this->uploadprocess)
529                        {
530                                $this->fileUpload();
531                        }
532                        elseif($this->upload_x || $this->show_upload_boxes)
533                        {
534                                $this->showUploadboxes();
535                        }
536                        elseif($this->copy_to_x)
537                        {
538                                $this->copyTo();
539                        }
540                        elseif($this->move_to_x)
541                        {
542                                $this->moveTo();
543                        }
544                        elseif($this->edit_cancel_x)
545                        {
546                                $this->readFilesInfo();
547                                $this->fileListing();
548                        }
549                        elseif($this->edit_x || $this->edit_preview_x || $this->edit_save_x || $this->edit_save_done_x)
550                        {
551                                $this->edit();
552                        }
553                        else
554                        {
555                                $this->readFilesInfo();
556                                $this->fileListing();
557                        }
558                }
559                function fileListing()
560                {
561                        $this->t->set_file(array('filemanager_list_t' => 'filelisting.tpl'));
562                        $this->t->set_block('filemanager_list_t','filemanager_header','filemanager_header');
563                        $this->t->set_block('filemanager_list_t','column','column');
564                        $this->t->set_block('filemanager_list_t','row','row');
565                        $this->t->set_block('filemanager_list_t','filemanager_footer','filemanager_footer');
566
567                        $vars['form_action']=$this->encode_href('/index.php', 'menuaction=filemanager.uifilemanager.index','path='.$this->path);
568                        if($this->numoffiles || $this->cwd)
569                        {
570                                while(list($num, $name) = each($this->prefs))
571                                {
572                                        if($name)
573                                        {
574                                                $columns++;
575                                        }
576                                }
577                                $columns++;
578                                $usedSpace = $this->bo->vfs->get_size(array(
579                                        'string'        => $this->path,
580                                        'relatives'     => array(RELATIVE_NONE)
581                                ));
582                                $quota = $this->bo->vfs->get_quota(array(
583                                        'string'        => $this->path
584                                ));
585
586                                $vars[usedSpace]='<input type="hidden" id="usedSpace" value="'.$usedSpace.'">';
587                                $vars[quotaSize]='<input type="hidden" id="quotaSize" value="'.($quota*1024*1024).'">';
588                                $vars[path]='<input type="hidden" id="currentPath" value="'.$this->path.'">';
589                                $vars[css]='<script>initDrawApi();</script>
590                                        <link rel="stylesheet" type="text/css" href="filemanager/templates/default/main.css">';
591                                $vars[toolbar0]=$this->toolbar('location');
592                                $vars[toolbar1]=$this->toolbar('list_nav');
593
594                                if(count($this->messages)>0)
595                                {
596                                        foreach($this->messages as $msg)
597                                        {
598                                                $messages.='<p>'.$msg.'</p>';
599                                        }
600                                }
601
602                                $vars[messages]=$messages;
603
604                                $this->t->set_var($vars);
605                                $this->t->pparse('out','filemanager_header');
606
607                                ###
608                                # Start File Table Column Headers
609                                # Reads values from $file_attributes array and preferences
610                                ###
611                                $this->t->set_var('actions',lang('select'));
612                                $this->t->set_var('mini_bar','&nbsp;');
613
614
615                                reset($this->bo->file_attributes);
616
617                                if($this->numoffiles>0)
618                                {
619                                        while(list($internal, $displayed) = each($this->bo->file_attributes))
620                                        {
621                                                if($this->prefs[$internal])
622                                                {
623                                                        if ($internal != 'owner')
624                                                                $col_data='<span><a href="'.$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->path.'&sortby='.$internal).'">'.$displayed.'</a></span>';
625                                                        else
626                                                                $col_data='<span>'.$displayed.'</span>';
627                                                        $this->t->set_var('col_data',$col_data);
628                                                        $this->t->parse('columns','column',True);
629                                                }
630                                        }
631
632                                        $this->t->set_var('row_tr_color','#dedede');
633                                       
634                                        $this->t->parse('rows','row');
635                                       
636                                        $this->t->pparse('out','row');
637                                }
638                                else
639                                {
640                                        $lang_nofiles=lang('No files in this directory.');
641                                }
642                                $vars[lang_no_files]=$lang_nofiles;
643
644
645                                if($this->prefs['dotdot'] && $this->prefs['name'] && $this->path != '/')
646                                {
647                                        $this->t->set_var('actions','');
648
649                                        $link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->lesspath);
650
651                                        $col_data='<a href="'.$link.'"><img src="'.$GLOBALS['phpgw']->common->image('filemanager','mime16up').' "alt="'.lang('Folder Up').'" /></a>';
652                                        $col_data.='&nbsp;<a href="'.$link.'">..</a>';
653
654                                        $this->t->set_var('col_data',$col_data);
655                                        $this->t->parse('columns','column');
656
657                                        if($this->prefs['mime_type'])
658                                        {
659                                                $col_data=lang('Directory');
660                                                $this->t->set_var('col_data',$col_data);
661                                                $this->t->parse('columns','column',True);
662                                        }
663
664                                        $this->t->set_var('row_tr_color',$tr_color);
665                                        $this->t->parse('rows','row');
666                                        $this->t->pparse('out','row');
667                                }
668
669                                # List all of the files, with their attributes
670                                @reset($this->files_array);
671                                for($i = 0; $i != $this->numoffiles; $i++)
672                                {
673                                        $files = $this->files_array[$i];
674                                       
675
676                                        if(!$this->prefs['dotfiles'] && ereg("^\.", $files['name']))
677                                        {
678                                                continue;
679                                        }
680
681                                        # Checkboxes
682                                        if($this->path != $this->bo->fakebase && $this->path != '/')
683                                        {
684                                                $cbox='<input type="checkbox" name="fileman" value="'.$files['name'].'">';
685                                                $this->t->set_var('actions',$cbox);
686                                        }
687                                        else
688                                        {
689                                                $this->t->set_var('actions','');
690                                        }
691                                        $minibar_data="";
692                                        if($this->can_private)
693                                        {
694                                                if ($files['type'] == "1")
695                                                {
696                                                        $image = $GLOBALS['phpgw']->common->image('filemanager','button_lock');
697                                                }
698                                                else
699                                                {
700                                                        $image = $GLOBALS['phpgw']->common->image('filemanager','button_unlock');
701                                                }
702                                                $link=$this->encode_href('/index.php','menuaction=filemanager.vfs_functions.setRestricted','file='.$files['name'].'&path='.$this->path);
703                                                $minibar_data = '<img id="restrict_'.$files['name'].'" onClick="cExecute(\''.$link.'\',setRestricted)" alt="'.lang("mark as restricted").'" title="'.lang("mark as restricted").'" src="'.$image.'">';
704                                        }
705
706
707                                        if ($files['mime_type'] == "text/html")
708                                        {
709                                                $link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.export','file='.$files['name'].'&path='.$this->path);
710                                                $image=$GLOBALS['phpgw']->common->image('filemanager','button_export');
711                                                $minibar_data.='<a href="'.$link.'"><img alt="'.lang("export").'" title="'.lang("export").'" src="'.$image.'"></a>';
712                                        }
713                                        else
714                                                $minibar_data.= "<a>&nbsp;</a>";
715                                        $this->t->set_var('mini_bar',$minibar_data);
716
717
718                                        # File name and icon
719                                        if($files['mime_type'] == 'Directory')
720                                        {
721                                                $link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->path.$this->dispsep.$files['name']);
722
723                                                $icon=$this->mime_icon($files['mime_type']);
724
725                                                $col_data='<a href="'.$link.'">'.$icon.'</a>&nbsp;';
726                                                $col_data.='<a href="'.$link.'">'.$files['name'].'</a>&nbsp;';
727                                        }
728                                        else
729                                        {
730
731                                                if($this->prefs['viewonserver'] && isset($this->bo->filesdir) && !$files['link_directory'])
732                                                {
733                                                        #FIXME
734                                                        $clickview = $this->filesdir.$pwd.'/'.$files['name'];
735
736                                                }
737                                                else
738                                                {
739                                                        $icon=$this->mime_icon($files['mime_type']);
740                                                        $link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.view','file='.$files['name'].'&path='.$this->path);
741
742                                                        $col_data='<a href="'.$link.'" target="'.$this->target.'">'.$icon.'</a>&nbsp;'.
743                                                        '<a id="name_'.$files['name'].'" href="'.$link.'" target="'.$this->target.'">'.$files['name'].'</a>';
744                                                }
745                                        }
746
747
748                                        $this->t->set_var('col_data',$col_data);
749                                        $this->t->parse('columns','column');
750
751                                        # MIME type
752                                        if($this->prefs['mime_type'])
753                                        {
754                                                $col_data=$files['mime_type'];
755                                                $this->t->set_var('col_data',$col_data);
756                                                $this->t->parse('columns','column',True);
757                                        }
758
759                                        # File size
760                                        if($this->prefs['size'])
761                                        {
762                                                $tmp_arr=array(
763                                                        'string'        => $files['directory'] . '/' . $files['name'],
764                                                        'relatives'     => array(RELATIVE_NONE)
765                                                );
766                                                if($files['mime_type'] != 'Directory') $tmp_arr['checksubdirs'] = false;
767
768                                                $size = $this->bo->vfs->get_size($tmp_arr);
769
770                                                $col_data=$this->bo->borkb($size);
771
772                                                $this->t->set_var('col_data',$col_data);
773                                                $this->t->parse('columns','column',True);
774                                        }
775
776                                        # Date created
777                                        if($this->prefs['created'])
778                                        {
779                                                $timestamp = $this->vfs_functions->dateString2timeStamp($files['created']);
780                                                if (time() - $timestamp > 86400) // Older than yesterday
781                                                        $col_data=date("Y-m-d",$timestamp);
782                                                else
783                                                        $col_data=date("H:i",$timestamp);
784                                                $this->t->set_var('col_data',$col_data);
785                                                $this->t->parse('columns','column',True);
786                                        }
787
788                                        # Date modified
789                                        if($this->prefs['modified'])
790                                        {
791                                                if ($files['modified'] != ''){
792                                                        $timestamp = $this->vfs_functions->dateString2timeStamp($files['modified']);
793                                                        if (time() - $timestamp > 86400) // Older than yesterday
794                                                                $col_data=date("Y-m-d",$timestamp);
795                                                        else
796                                                                $col_data=date("H:i",$timestamp);
797                                                }
798                                                else
799                                                        $col_data='';
800                                                $this->t->set_var('col_data',$col_data);
801                                                $this->t->parse('columns','column',True);
802                                        }
803
804                                        # Owner name
805                                        if($this->prefs['owner'])
806                                        {
807                                                $this->t->set_var('col_data',$GLOBALS['phpgw']->accounts->id2name($files['owner_id']));
808                                                $this->t->parse('columns','column',True);
809                                        }
810
811                                        # Creator name
812                                        if($this->prefs['createdby_id'])
813                                        {
814                                                $this->html_table_col_begin();
815                                                if($files['createdby_id'])
816                                                {
817                                                        $col_data=$GLOBALS['phpgw']->accounts->id2name($files['createdby_id']);
818                                                }
819                                                else $col_data='';
820
821                                                $this->t->set_var('col_data',$col_data);
822                                                $this->t->parse('columns','column',True);
823                                        }
824
825                                        # Modified by name
826                                        if($this->prefs['modifiedby_id'])
827                                        {
828                                                if($files['modifiedby_id'])
829                                                {
830                                                        $col_data=$GLOBALS['phpgw']->accounts->id2name($files['modifiedby_id']);
831                                                }
832                                                else $col_data='';
833                                                $this->t->set_var('col_data',$col_data);
834                                                $this->t->parse('columns','column',True);
835                                        }
836
837                                        # Application
838                                        if($this->prefs['app'])
839                                        {
840                                                $col_data=$files['app'];
841                                                $this->t->set_var('col_data',$col_data);
842                                                $this->t->parse('columns','column',True);
843                                        }
844
845                                        # Comment
846                                        if($this->prefs['comment'])
847                                        {
848                                                if (strlen($files['comment']) == 0 )
849                                                        $files['comment'] = "&lt;".lang("no comments")."&gt;";
850                                                $col_data='<span id="'.$files['name'].'" onClick="setComments(this)">'.$files['comment'].'</span>';
851                                                $this->t->set_var('col_data',$col_data);
852                                                $this->t->parse('columns','column',True);
853                                        }
854
855                                        # Version
856                                        if($this->prefs['version'])
857                                        {
858                                                $link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.history','file='.$files['name'].'&path='.$this->path);
859                                                $col_data='<a href="'.$link.'" target="_blank">'.$files['version'].'</a>';
860                                                $this->t->set_var('col_data',$col_data);
861                                                $this->t->parse('columns','column',True);
862                                        }
863
864                                        $usedspace += $files['size'];
865
866                                        $this->t->set_var('row_tr_color','');
867                                        $this->t->parse('rows','row');
868                                        $this->t->pparse('out','row');
869                                }
870                        }
871
872                        // The file and directory information
873                        $vars[lang_files_in_this_dir]=lang('Files in this directory');
874                        $vars[files_in_this_dir]=$this->numoffiles;
875
876                        $vars[lang_used_space]=lang('Used space');
877                        $vars[used_space]=$this->bo->borkb($usedspace, NULL, 1);
878
879                        if($this->path == $this->bo->homedir || $this->path == $this->bo->fakebase)
880                        {
881                                $vars[lang_unused_space]=lang('Unused space');
882                                $vars[unused_space]=$this->bo->borkb($this->bo->userinfo['hdspace'] - $usedspace, NULL, 1);
883
884                                $tmp_arr=array(
885                                        'string'        => $this->path,
886                                        'relatives'     => array(RELATIVE_NONE)
887                                );
888
889                                $ls_array = $this->bo->vfs->ls($tmp_arr);
890
891                                $vars[lang_total_files]=lang('Total Files');
892                                $vars[total_files]=     count($ls_array);
893                        }
894
895                        $this->t->set_var($vars);
896                        $this->t->pparse('out','filemanager_footer');
897
898                        $GLOBALS['phpgw']->common->phpgw_footer();
899                        $GLOBALS['phpgw']->common->phpgw_exit();
900                }
901
902                function readFilesInfo()
903                {
904                        // start files info
905
906                        # Read in file info from database to use in the rest of the script
907                        # $fakebase is a special directory.  In that directory, we list the user's
908                        # home directory and the directories for the groups they're in
909                        $this->numoffiles = 0;
910                        if($this->path == $this->bo->fakebase)
911                        {
912                                // FIXME this test can be removed
913                                if(!$this->bo->vfs->file_exists(array('string' => $this->bo->homedir, 'relatives' => array(RELATIVE_NONE))))
914                                {
915                                        $this->bo->vfs->mkdir(array('string' => $this->bo->homedir, 'relatives' => array(RELATIVE_NONE)));
916                                }
917
918                                $ls_array = $this->bo->vfs->ls(array(
919                                        'string' => $this->bo->homedir,
920                                        'relatives' => array(RELATIVE_NONE),
921                                        'checksubdirs' => False,
922                                        'nofiles' => True
923                                ));
924
925                                $this->files_array[] = $ls_array[0];
926                                $this->numoffiles++;
927
928                                reset($this->readable_groups);
929                                while(list($num, $group_array) = each($this->readable_groups))
930                                {
931                                        # If the group doesn't have access to this app, we don't show it
932                                        /*if(!$this->groups_applications[$group_array['account_name']][$this->bo->appname]['enabled'])
933                                        {
934                                                continue;
935                                        }
936                                        */
937
938
939                                        if(!$this->bo->vfs->file_exists(array('string' => $this->bo->fakebase.'/'.$group_array['account_name'],'relatives'      => array(RELATIVE_NONE))))
940                                        {
941                                                $this->bo->vfs->override_acl = 1;
942                                                $this->bo->vfs->mkdir(array(
943                                                        'string' => $this->bo->fakebase.'/'.$group_array['account_name'],
944                                                        'relatives' => array(RELATIVE_NONE)
945                                                ));
946
947                                                // FIXME we just created a fresh group dir so we know there nothing in it so we have to remove all existing content
948                                               
949                                               
950                                                $this->bo->vfs->override_acl = 0;
951
952                                                $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'])));
953                                        }
954
955                                        $ls_array = $this->bo->vfs->ls(array('string' => $this->bo->fakebase.'/'.$group_array['account_name'],'relatives'       => array(RELATIVE_NONE),'checksubdirs' => False,'nofiles' => True));
956
957                                        $this->files_array[] = $ls_array[0];
958
959                                        $this->numoffiles++;
960                                }
961                        }
962                        else
963                        {
964                                $ls_array = $this->bo->vfs->ls(array(
965                                        'string' => $this->path,
966                                        'relatives'     => array(RELATIVE_NONE),
967                                        'checksubdirs' => False,
968                                        'nofiles'       => False,
969                                        'orderby'       => $this->sortby
970                                ));
971
972                                while(list($num, $file_array) = each($ls_array))
973                                {
974                                        $this->numoffiles++;
975                                        $this->files_array[] = $file_array;
976                                }
977                        }
978
979                        if(!is_array($this->files_array))
980                        {
981                                $this->files_array = array();
982                        }
983                        // end file count
984                }
985
986                function toolbar($type)
987                {
988                        switch($type)
989                        {
990                                case 'location':
991                                        $toolbar='
992                                        <div id="fmLocation">
993                                        <table cellspacing="10" cellpadding="0" border="0">
994                                        <tr>
995                                        ';
996//                                      $toolbar.='<td><img alt="spacer" src="'.$GLOBALS['phpgw']->common->image('phpgwapi','buttonseparator').'" height="27" width="8"></td>';
997//                                      $toolbar.='<td><img alt="spacer" src="'.$GLOBALS['phpgw']->common->image('filemanager','spacer').'" height="27" width="1"></td>';
998
999                                        // go up icon when we're not at the top, dont allow to go outside /home = fakebase
1000                                        if($this->path != '/' && $this->path != $this->bo->fakebase)
1001                                        {
1002                                                $link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->lesspath);
1003                                                $toolbar.=$this->linkButton($link,'up',lang('go up'));
1004                                        }
1005
1006                                        // go home icon when we're not home already
1007                                        if($this->path != $this->bo->homedir)
1008                                        {
1009                                                $link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->bo->homedir);
1010                                                $toolbar.=$this->linkButton($link,'home',lang('go home'));
1011                                        }
1012
1013                                        // reload button with this url
1014                                        $link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->path);
1015                                        $toolbar.=$this->linkButton($link,'reload',lang('reload'));
1016
1017                                        $toolbar.='<td>'.lang('Location').':&nbsp;';
1018                                        //$toolbar.='<input id="fmInputLocation" type="text" size="20" disabled="disabled" name="location" value="'.$this->disppath.'"/>&nbsp;';
1019                                        $current_option='<option>'.$this->disppath.'</option>';
1020                                        // selectbox for change/move/and copy to
1021                                        $dirs_options=$this->all_other_directories_options();
1022                                        $toolbar.='<select id="cdtodir" name="cdtodir" onChange="document.formfm.changedir.value=\'true\';document.formfm.submit()">'.$current_option.$dirs_options.'</select>
1023                                        <input type="hidden" name="changedir" value="false"></td>
1024                                        ';
1025                                        //$toolbar.=$this->inputImage('goto','goto',lang('Quick jump to'));
1026                                        // upload button
1027                                        /*if($this->path != '/' && $this->path != $this->bo->fakebase && $this->can_add)
1028                                        {
1029                                                // upload button
1030                                                $toolbar.=$this->inputImage('upload','upload',lang('Upload'));
1031                                               
1032
1033                                        }*/
1034                                        $toolbar.='</tr></table>';
1035                                        $toolbar.='</div><br><br>';
1036                                        break;
1037                                case 'list_nav':
1038                                        $toolbar='
1039                                        <table cellspacing="10" cellpadding="0" border="0">
1040                                        <tr>';
1041                                        // selectbox for change/move/and copy to
1042                                        // submit buttons for
1043                                        if($this->path != '/' && $this->path != $this->bo->fakebase)
1044                                        {
1045                                                // create dir and file button
1046                                                if($this->can_add)
1047                                                {
1048                                                        $toolbar.='<td><input type="hidden" id="newfile_or_dir" name="newfile_or_dir" value="" /></td>';
1049                                                        //TODO : create folder with problems
1050                                                        //$toolbar3.=$this->inputImage('newdir','createdir',lang('Create Folder'));
1051                                                        $toolbar.=$this->inputImage('new','createfile',lang('New...'));
1052                                                }
1053
1054                                                if($this->can_edit)
1055                                                {
1056                                                        // edit text file button
1057                                                        $toolbar.=$this->inputImage('edit','edit',lang('edit'));
1058                                                }
1059
1060                                                if($this->can_edit)
1061                                                {
1062                                                        $toolbar.=$this->inputImage('rename','rename',lang('Rename'));
1063                                                }
1064
1065                                                if($this->can_delete)
1066                                                {
1067                                                        $toolbar.=$this->inputImage('delete','delete',lang('Delete'));
1068                                                }
1069
1070                                        }
1071
1072                                                // copy and move buttons
1073                                                if($this->path != '/' && $this->path != $this->bo->fakebase)
1074                                                {
1075                                                        $dirs_options=$this->all_other_directories_options();
1076                                                        if (strlen($dirs_options) > 0){
1077                                                                $toolbar3.=$this->inputImage('copy_to','copy_to',lang('Copy to'));
1078                                                                if ($this->can_delete)
1079                                                                        $toolbar3.=$this->inputImage('move_to','move_to',lang('Move to'));
1080                                                        }
1081                                                        $toolbar3.='<td><select name="todir" style="visibility:hidden">'.$dirs_options.'</select></td>';
1082
1083                                                }
1084
1085                                                if($toolbar3)
1086                                                {
1087                                                        $toolbar.=$toolbar3;
1088                                                /*      $toolbar.='
1089                                                        <table cellspacing="1" cellpadding="0" border="0">
1090                                                        <tr>'.$toolbar3;*/
1091                                                }
1092                                        $toolbar.='</tr></table>';
1093
1094                                        break;
1095                                default:$x='';
1096                        }
1097
1098                        if($toolbar)
1099                        {
1100                                return $toolbar;
1101                        }
1102                }
1103
1104
1105                // move to bo
1106                # Handle File Uploads
1107                function fileUpload()
1108                {
1109                        if($this->path != '/' && $this->path != $this->bo->fakebase)
1110                        {
1111                                for($i = 0; $i != $this->show_upload_boxes; $i++)
1112                                {
1113                                        if($badchar = $this->bo->bad_chars($_FILES['upload_file']['name'][$i], True, True))
1114                                        {
1115                                                $this->messages[]=lang('Error:').lang('File names cannot contain "%1"', $badchar);
1116
1117                                                continue;
1118                                        }
1119
1120                                        # Check to see if the file exists in the database, and get its info at the same time
1121                                        $ls_array = $this->bo->vfs->ls(array(
1122                                                'string'=> $this->path . '/' . $_FILES['upload_file']['name'][$i],
1123                                                'relatives'     => array(RELATIVE_NONE),
1124                                                'checksubdirs'  => False,
1125                                                'nofiles'       => True
1126                                        ));
1127
1128                                        $fileinfo = $ls_array[0];
1129
1130                                        if($fileinfo['name'])
1131                                        {
1132                                                if($fileinfo['mime_type'] == 'Directory')
1133                                                {
1134                                                        $this->messages[]= lang('Error:').lang('Cannot replace %1 because it is a directory', $fileinfo['name']);
1135                                                        continue;
1136                                                }
1137                                        }
1138                                         $max_size = $this->current_config['filemanager_Max_file_size'];
1139                                         if (! $max_size)
1140                                                 $max_size = ini_get('upload_max_filesize');
1141                                         else
1142                                                 $max_size .= "M";
1143
1144                                        $upload_max_filesize = str_replace("M","",$max_size) * 1024 * 1024;
1145
1146                                        if ($_FILES['upload_file']['size'][$i] > $upload_max_filesize)
1147                                        {
1148                                                $this->messages[]=lang('The size of %1 has exceded the limit: %2', $this->disppath.'/'.$_FILES['upload_file']['name'][$i], $max_size);
1149                                        }
1150                                        else if(strlen($this->current_config['filemanager_antivirus_command']) > 0)
1151                                        {
1152                                                $command = "nice -n19 ".$this->current_config['filemanager_antivirus_command']." ".$_FILES['upload_file']['tmp_name'][$i];
1153                                                exec("bash -c ".escapeshellcmd(escapeshellarg($command)),$output,$return);
1154                                                if ($return == 1)
1155                                                {
1156                                                        $this->messages[]=lang('Error:').lang('The file sent was considered infected');
1157                                                        $this->readFilesInfo();
1158                                                        $this->filelisting();
1159                                                        return true;
1160                                                }
1161                                        }
1162                                        if($_FILES['upload_file']['size'][$i] > 0)
1163                                        {
1164                                                if($fileinfo['name'] && $fileinfo['deleteable'] != 'N')
1165                                                {
1166                                                        $tmp_arr=array(
1167                                                                'string'=> $_FILES['upload_file']['name'][$i],
1168                                                                'relatives'     => array(RELATIVE_ALL),
1169                                                                'attributes'    => array(
1170                                                                        'owner_id' => $this->bo->userinfo['username'],
1171                                                                        'modifiedby_id' => $this->bo->userinfo['username'],
1172                                                                        'modified' => $this->now,
1173                                                                        'size' => $_FILES['upload_file']['size'][$i],
1174                                                                        'mime_type' => $_FILES['upload_file']['type'][$i],
1175                                                                        'deleteable' => 'Y',
1176                                                                        'comment' => stripslashes($_POST['upload_comment'][$i])
1177                                                                )
1178                                                        );
1179                                                        $this->bo->vfs->set_attributes($tmp_arr);
1180
1181                                                        $tmp_arr=array(
1182                                                                'from'  => $_FILES['upload_file']['tmp_name'][$i],
1183                                                                'to'    => lang('new')."_".$_FILES['upload_file']['name'][$i],
1184                                                                'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
1185                                                        );
1186                                                        $this->bo->vfs->cp($tmp_arr);
1187
1188                                                        $this->messages[]=lang('Created new %1', $this->disppath.'/'.$_FILES['upload_file']['name'][$i]);
1189                                                }
1190                                                else
1191                                                {
1192
1193                                                        $this->bo->vfs->cp(array(
1194                                                                'from'=> $_FILES['upload_file']['tmp_name'][$i],
1195                                                                'to'=> $_FILES['upload_file']['name'][$i],
1196                                                                'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
1197                                                        ));
1198
1199                                                        $this->bo->vfs->set_attributes(array(
1200                                                                'string'=> $_FILES['upload_file']['name'][$i],
1201                                                                'relatives'     => array(RELATIVE_ALL),
1202                                                                'attributes'=> array(
1203                                                                        'mime_type' => $_FILES['upload_file']['type'][$i],
1204                                                                        'comment' => stripslashes($_POST['upload_comment'][$i])
1205                                                                )
1206                                                        ));
1207
1208                                                        $this->messages[]=lang('Created %1,%2', $this->disppath.'/'.$_FILES['upload_file']['name'][$i], $_FILES['upload_file']['size'][$i]);
1209                                                }
1210                                        }
1211                                        elseif($_FILES['upload_file']['name'][$i])
1212                                        {
1213                                                $this->bo->vfs->touch(array(
1214                                                        'string'=> $_FILES['upload_file']['name'][$i],
1215                                                        'relatives'     => array(RELATIVE_ALL)
1216                                                ));
1217
1218                                                $this->bo->vfs->set_attributes(array(
1219                                                        'string'=> $_FILES['upload_file']['name'][$i],
1220                                                        'relatives'     => array(RELATIVE_ALL),
1221                                                        'attributes'=> array(
1222                                                                'mime_type' => $_FILES['upload_file']['type'][$i],
1223                                                                'comment' => stripslashes($_POST['upload_comment'][$i])
1224                                                        )
1225                                                ));
1226
1227                                                $this->messages[]=lang('Created %1,%2', $this->disppath.'/'.$_FILES['upload_file']['name'][$i], $file_size[$i]);
1228                                        }
1229                                }
1230
1231                                $this->readFilesInfo();
1232                                $this->filelisting();
1233                        }
1234                }
1235                # Handle Moving Files and Directories
1236                function moveTo()
1237                {
1238                        if(!$this->todir)
1239                        {
1240                                $this->messages[] = lang('Error:').lang('Could not move file because no destination directory is given ', $this->disppath.'/'.$file);
1241
1242                        }
1243                        else
1244                        {
1245
1246                                while(list($num, $file) = each($this->fileman))
1247                                {
1248                                        if($this->bo->vfs->mv(array(
1249                                                'from'  => $file,
1250                                                'to'    => $this->todir . '/' . $file,
1251                                                'relatives'     => array(RELATIVE_ALL, RELATIVE_NONE)
1252                                        )))
1253                                        {
1254                                                $moved++;
1255                                                $this->messages[]=lang('Moved %1 to %2', $this->disppath.'/'.$file, $this->todir.'/'.$file);
1256                                        }
1257                                        else
1258                                        {
1259                                                $this->messages[] = lang('Error:').lang('Could not move %1 to %2', $this->disppath.'/'.$file, $this->todir.'/'.$file);
1260                                        }
1261                                }
1262                        }
1263
1264                        if($moved)
1265                        {
1266                                $x=0;
1267                        }
1268
1269                        $this->readFilesInfo();
1270                        $this->filelisting();
1271                }
1272
1273                // Handle Copying of Files and Directories
1274                function copyTo()
1275                {
1276                        if(!$this->todir)
1277                        {
1278                                $this->messages[] = lang('Error:').lang('Could not copy file because no destination directory is given ', $this->disppath.'/'.$file);
1279
1280                        }
1281                        else
1282                        {
1283                                while(list($num, $file) = each($this->fileman))
1284                                {
1285                                        if($this->bo->vfs->cp(array(
1286                                                'from'  => $file,
1287                                                'to'    => $this->todir . '/' . $file,
1288                                                'relatives'     => array(RELATIVE_ALL, RELATIVE_NONE)
1289                                        )))
1290                                        {
1291                                                $copied++;
1292                                                $this->messages[] = lang('Copied %1 to %2', $this->disppath.'/'.$file, $this->todir.'/'.$file);
1293                                        }
1294                                        else
1295                                        {
1296                                                $this->messages[] = lang('Error:').lang('Could not copy %1 to %2', $this->disppath.'/'.$file, $this->todir.'/'.$file);
1297                                        }
1298                                }
1299                        }
1300                        if($copied)
1301                       
1302                        {
1303                                $x=0;
1304                        }
1305
1306                        $this->readFilesInfo();
1307                        $this->filelisting();
1308                }
1309
1310                function createdir()
1311                {
1312                        if($this->newdir_x && $this->newfile_or_dir)
1313                        {
1314                                if($this->bo->badchar = $this->bo->bad_chars($this->newfile_or_dir, True, True))
1315                                {
1316                                        $this->messages[]= lang('Error:').$this->bo->html_encode(lang('Directory names cannot contain "%1"', $badchar), 1);
1317                                }
1318
1319                                /* TODO is this right or should it be a single $ ? */
1320                                if($$this->newfile_or_dir[strlen($this->newfile_or_dir)-1] == ' ' || $this->newfile_or_dir[0] == ' ')
1321                                {
1322                                        $this->messages[]= lang('Error:').lang('Cannot create directory because it begins or ends in a space');
1323                                }
1324
1325                                $ls_array = $this->bo->vfs->ls(array(
1326                                        'string'        => $this->path . '/' . $this->newfile_or_dir,
1327                                        'relatives'     => array(RELATIVE_NONE),
1328                                        'checksubdirs'  => False,
1329                                        'nofiles'       => True
1330                                ));
1331
1332                                $fileinfo = $ls_array[0];
1333
1334                                if($fileinfo['name'])
1335                                {
1336                                        if($fileinfo['mime_type'] != 'Directory')
1337                                        {
1338                                                $this->messages[]= lang('Error:').lang('%1 already exists as a file',$fileinfo['name']);
1339                                        }
1340                                        else
1341                                        {
1342                                                $this->messages[]= lang('Error:').lang('Directory %1 already exists', $fileinfo['name']);
1343                                        }
1344                                }
1345                                else
1346                                {
1347                                        if($this->bo->vfs->mkdir(array('string' => $this->newfile_or_dir)))
1348                                        {
1349                                                $this->messages[]=lang('Created directory %1', $this->disppath.'/'.$this->newfile_or_dir);
1350                                        }
1351                                        else
1352                                        {
1353                                                $this->messages[]=lang('Error:').lang('Could not create %1', $this->disppath.'/'.$this->newfile_or_dir);
1354                                        }
1355                                }
1356
1357                                $this->readFilesInfo();
1358                                $this->filelisting();
1359                        }
1360                }
1361                function showUploadboxes()
1362                {
1363                        $this->t->set_file(array('upload' => 'upload.tpl'));
1364                        $this->t->set_block('upload','upload_header','upload_header');
1365                        $this->t->set_block('upload','row','row');
1366                        $this->t->set_block('upload','upload_footer','upload_footer');
1367
1368                        if($this->path != '/' && $this->path != $this->bo->fakebase && $this->can_add)
1369                        {
1370                                $vars[form_action]=$GLOBALS[phpgw]->link('/index.php','menuaction=filemanager.uifilemanager.index');
1371                                $vars[path]=$this->path;
1372                                $vars[lang_file]=lang('File');
1373                                $vars[lang_comment]=lang('Comment');
1374                                $vars[num_upload_boxes]=1;
1375                                $this->t->set_var($vars);
1376                                $this->t->pparse('out','upload_header');
1377
1378                                $this->t->set_var('row_tr_color',$tr_color);
1379                                $this->t->parse('rows','row');
1380                                $this->t->pparse('out','row');
1381
1382                                $vars[lang_upload]=lang('Upload files');
1383                                $vars[change_upload_boxes].=lang('Show') . '&nbsp;';
1384                                $this->t->set_var($vars);
1385                                $this->t->pparse('out','upload_footer');
1386                        }
1387                }
1388
1389                /* create textfile */
1390                function createfile()
1391                {
1392                        $this->filename=$this->newfile_or_dir;
1393                        if($this->filename)
1394                        {
1395                                if($badchar = $this->bo->bad_chars($this->filename, True, True))
1396                                {
1397                                        $this->messages[] = lang('Error:').lang('File names cannot contain "%1"',$badchar);
1398
1399                                        $this->fileListing();
1400                                }
1401
1402                                if($this->bo->vfs->file_exists(array(
1403                                        'string'=> $this->filename,
1404                                        'relatives'     => array(RELATIVE_ALL)
1405                                )))
1406                                {
1407                                        $this->messages[]= lang('Error:').lang('File %1 already exists. Please edit it or delete it first.', $this->filename);
1408                                        $this->fileListing();
1409                                }
1410
1411                                if($this->bo->vfs->touch(array(
1412                                        'string'        => $this->filename,
1413                                        'relatives'     => array(RELATIVE_ALL)
1414                                )))
1415                                {
1416                                        $this->edit = 1;
1417                                        $this->numoffiles++;
1418                                        $this->edit();
1419                                }
1420                                else
1421                                {
1422                                        $this->messages[]= lang('Error:').lang('File %1 could not be created.', $this->filename);
1423                                        $this->fileListing();
1424                                }
1425                        }
1426                }
1427
1428                # Handle Editing files
1429                function edit()
1430                {
1431                        if($this->filename)
1432                        {
1433                                if (! $this->vfs_functions->verifyLock($this->path.'/'.$this->filename,RELATIVE_NONE)){
1434                                        echo $this->messages['0'];
1435                                        $GLOBALS['phpgw']->redirect('/index.php');
1436
1437                                        //$GLOBALS['phpgw']->common->phpgw_exit();
1438                                }
1439                                $ls_array = $this->bo->vfs->ls(array(
1440                                        'string'        => $this->path.'/'.$this->filename,
1441                                        'relatives'     => array(RELATIVE_NONE),
1442                                        'checksubdirs'  => False,
1443                                        'nofiles'       => True
1444                                ));
1445                                $this->bo->vfs->touch(array(
1446                                        'string'=> $this->path.'/'.$this->filename,
1447                                        'relatives'     => array(RELATIVE_NONE)
1448                                ));
1449
1450
1451                                if($ls_array[0]['mime_type'])
1452                                {
1453                                        $mime_type = $ls_array[0]['mime_type'];
1454                                }
1455                                elseif($this->prefs['viewtextplain'])
1456                                {
1457                                        $mime_type = 'text/plain';
1458                                }
1459                                $editable = array('','text/plain','text/csv','text/html','text/text','message/rfc822');
1460
1461                                if(!in_array($mime_type,$editable)){
1462                                        echo lang('Impossbile to edit this file');
1463                                        return False;
1464                                }
1465                        }
1466
1467                        $this->readFilesInfo();
1468
1469                        if ($mime_type == 'text/html')
1470                                $this->t->set_file(array('filemanager_edit' => 'edit_html.tpl'));
1471                        else
1472                                $this->t->set_file(array('filemanager_edit' => 'edit_file.tpl'));
1473
1474                        $this->t->set_block('filemanager_edit','row','row');
1475
1476
1477                        $vars[refresh_script] = "<script src='filemanager/js/refresh.js'></script>";
1478
1479                        $vars[preview_content]='';
1480                        if($this->edit_file)
1481                        {
1482                                $this->edit_file_content = stripslashes($this->edit_file_content);
1483                        }
1484
1485                        if($this->edit_preview_x)
1486                        {
1487                                $content = $this->edit_file_content;
1488
1489                                $vars[lang_preview_of]=lang('Preview of %1', $this->path.'/'.$edit_file);
1490
1491                                $vars[preview_content]=nl2br($content);
1492                        }
1493                        elseif($this->edit_save_x || $this->edit_save_done_x)
1494                        {
1495                                $content = $this->edit_file_content;
1496                                //die( $content);
1497                                if($this->bo->vfs->write(array(
1498                                        'string'        => $this->path.'/'.$this->edit_file,
1499                                        'relatives'     => array(RELATIVE_NONE),
1500                                        'content'       => $content
1501                                )))
1502                                {
1503                                        $this->messages[]=lang('Saved %1', $this->path.'/'.$this->edit_file);
1504
1505                                        if($this->edit_save_done_x)
1506                                        {
1507                                                $this->readFilesInfo();
1508                                                $this->fileListing();
1509                                                exit;
1510                                        }
1511                                }
1512                                else
1513                                {
1514                                        echo lang('Could not save %1', $this->path.'/'.$this->edit_file);
1515                                        $this->messages[]=lang('Could not save %1', $this->path.'/'.$this->edit_file);
1516                                }
1517                        }
1518
1519                        # If we're in preview or save mode, we only show the file
1520                        # being previewed or saved
1521                        if($this->edit_file &&($this->filename != $this->edit_file))
1522                        {
1523                                continue;
1524                        }
1525
1526                        if($this->filename && $this->bo->vfs->file_exists(array(
1527                                'string'        => $this->filename,
1528                                'relatives'     => array(RELATIVE_ALL)
1529                        )))
1530                        {
1531                                if($this->edit_file)
1532                                {
1533                                        $content = stripslashes($this->edit_file_content);
1534                                }
1535                                else
1536                                {
1537                                        $content = $this->bo->vfs->read(array('string' => $this->filename));
1538                                }
1539                                $vars[form_action]= $GLOBALS['phpgw']->link('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->path);
1540                                $vars[edit_file]=$this->filename;
1541                                # We need to include all of the fileman entries for each file's form,
1542                                # so we loop through again
1543                                for($i = 0; $i != $this->numoffiles; $i++)
1544                                {
1545                                        if($this->filename) $value='value="'.$this->filename.'"';
1546                                        $vars[filemans_hidden]='<input type="hidden" name="filename" '.$value.' />';
1547                                }
1548                                $vars[file_content]=$content;
1549
1550                                $vars[buttonPreview]=$this->inputButton('edit_preview','edit_preview',lang('Preview %1', $this->bo->html_encode($this->fileman[$j], 1)));
1551                                $vars[buttonSave]=$this->inputButton('edit_save','save',lang('Save %1', $this->bo->html_encode($this->filename, 1)));
1552                                $vars[buttonDone]=$this->inputButton('edit_save_done','ok',lang('Save %1, and go back to file listing ', $this->bo->html_encode($this->filename, 1)));
1553                                $vars[buttonCancel]=$this->inputButton('edit_cancel','cancel',lang('Cancel editing %1 without saving', $this->bo->html_encode($this->filename, 1)));
1554
1555                                if ($mime_type == 'text/html'){
1556                                        $vars[fck_edit] = '<script type="text/javascript" src="filemanager/tp/ckeditor/ckeditor.js"></script>
1557                                                <textarea cols="80" id="edit_file_content" name="edit_file_content" rows="10">'.$content.'</textarea>
1558                                                <script type="text/javascript"> CKEDITOR.replace( \'edit_file_content\',{
1559removePlugins : \'elementspath\',
1560skin : \'office2003\',
1561toolbar : [["Source","Preview","-","Cut","Copy","Paste","-","Print",
1562"Undo","Redo","-","Find","Replace","-","SelectAll" ],
1563["Table","HorizontalRule","Smiley","SpecialChar","PageBreak","-","Bold",
1564"Italic","Underline","Strike","-","Subscript","Superscript",
1565"NumberedList","BulletedList","-","Outdent","Indent","Blockquote",
1566"JustifyLeft","JustifyCenter","JustifyRight","JustifyBlock",
1567"Link", "TextColor","BGColor","Maximize"],
1568["Styles","Format","Font","FontSize"]]
1569                                });</script>';
1570
1571                                }
1572
1573
1574                                $this->t->set_var($vars);
1575                                $this->t->parse('rows','row');
1576                                $this->t->pparse('out','row');
1577
1578                        }
1579
1580                }
1581
1582                function history()
1583                {
1584                        if($this->file) // FIXME this-file is never defined
1585                        {
1586                                $journal_array = $this->bo->vfs->get_journal(array(
1587                                        'string'        => $this->file,//FIXME
1588                                        'relatives'     => array(RELATIVE_ALL)
1589                                ));
1590
1591                                if(is_array($journal_array))
1592                                {
1593                                        $this->html_table_begin();
1594                                        $this->html_table_row_begin();
1595                                        $this->html_table_col_begin();
1596                                        echo lang('Date');
1597                                        $this->html_table_col_end();
1598                                        $this->html_table_col_begin();
1599                                        echo lang('Version');
1600                                        $this->html_table_col_end();
1601                                        $this->html_table_col_begin();
1602                                        echo lang('Who');
1603                                        $this->html_table_col_end();
1604                                        $this->html_table_col_begin();
1605                                        echo lang('Operation');
1606                                        $this->html_table_col_end();
1607                                        $this->html_table_row_end();
1608
1609                                        while(list($num, $journal_entry) = each($journal_array))
1610                                        {
1611                                                $this->html_table_row_begin();
1612                                                $this->html_table_col_begin();
1613                                                $this->bo->html_text($journal_entry['created'] . '&nbsp;&nbsp;&nbsp;');
1614                                                $this->html_table_col_end();
1615                                                $this->html_table_col_begin();
1616                                                $this->bo->html_text($journal_entry['version'] . '&nbsp;&nbsp;&nbsp;' );
1617                                                $this->html_table_col_end();
1618                                                $this->html_table_col_begin();
1619                                                $this->bo->html_text($GLOBALS['phpgw']->accounts->id2name($journal_entry['owner_id']) . '&nbsp;&nbsp;&nbsp;');
1620                                                $this->html_table_col_end();
1621                                                $this->html_table_col_begin();
1622                                                $this->bo->html_text($journal_entry['comment']);
1623                                                $this->html_table_col_end();
1624                                        }
1625
1626                                        $this->html_table_end();
1627                                        $GLOBALS['phpgw']->common->phpgw_footer();
1628                                        $GLOBALS['phpgw']->common->phpgw_exit();
1629                                }
1630                                else
1631                                {
1632                                        echo lang('No version history for this file/directory');
1633                                }
1634                        }
1635                }
1636                function view()
1637                {
1638                        if (!$this->bo->vfs->acl_check(array(
1639                                'string'        => $this->path,
1640                                'relatives'     => array(RELATIVE_NONE),
1641                                'operation'     => PHPGW_ACL_READ
1642                        )))
1643                        {
1644                                echo lang("You have no permission to access this file");
1645                                return false;
1646                        }
1647                        if($this->file) //FIXME
1648                        {
1649                                $ls_array = $this->bo->vfs->ls(array(
1650                                        'string'        => $this->path.'/'.$this->file,//FIXME
1651                                        'relatives'     => array(RELATIVE_NONE),
1652                                        'checksubdirs'  => False,
1653                                        'nofiles'       => True
1654                                ));
1655
1656                                if($ls_array[0]['mime_type'])
1657                                {
1658                                        $mime_type = $ls_array[0]['mime_type'];
1659                                }
1660                                elseif($this->prefs['viewtextplain'])
1661                                {
1662                                        $mime_type = 'text/plain';
1663                                }
1664                                $viewable = array('','text/plain','text/csv','text/html','text/text');
1665
1666                                if(in_array($mime_type,$viewable))
1667                                {
1668                                       
1669                                        header('Content-type: ' . $mime_type);
1670                                        header('Content-disposition: filename="' . $this->file . '"');//FIXME
1671                                        Header("Pragma: public");
1672                                }
1673                                else
1674                                {
1675                                        $GLOBALS['phpgw']->browser->content_header($this->file,$mime_type);//FIXME
1676                                }
1677                                echo $this->bo->vfs->read(array(
1678                                        'string'        => $this->path.'/'.$this->file,//FIXME
1679                                        'relatives'     => array(RELATIVE_NONE)
1680                                ));
1681                                $GLOBALS['phpgw']->common->phpgw_exit();
1682                        }
1683                }
1684
1685                function export(){
1686                        if($this->file)
1687                        {
1688                                $ls_array = $this->bo->vfs->ls(array(
1689                                        'string'        => $this->path.'/'.$this->file,
1690                                        'relatives'     => array(RELATIVE_NONE),
1691                                        'checksubdirs'  => False,
1692                                        'nofiles'       => True
1693                                ));
1694                                /*$timestamp = $this->vfs_functions->dateString2timeStamp($ls_array[0]['modified']);
1695                                if (time() - $timestamp < 60 && $ls_array[0]['modifiedby_id'] != $GLOBALS['phpgw_info']['user']['account_id']);
1696                                {
1697                                        // recently than last minute: someone is editing
1698                                }*/
1699                                $mime_type = $ls_array[0]['mime_type'];
1700                                $formats = array('text/html');
1701                                if(!in_array($mime_type,$formats)){
1702                                        echo lang('Impossbile to export this file');
1703                                        return False;
1704                                }
1705                                $content = $this->bo->vfs->read(array('string' => $this->path.'/'.$this->file,
1706                                               'relatives'     => array(RELATIVE_NONE)
1707                                       ));
1708
1709                                include_once('filemanager/tp/dompdf/dompdf_config.inc.php');
1710                                $dompdf = new DOMPDF();
1711                                $dompdf->load_html($content);
1712                                $dompdf->set_paper($this->prefs['pdf_paper_type'], $this->prefs['pdf_type']);
1713                                /* Would be nice to implement 'Title','Subject','Author','Creator','CreationDate'*/
1714                                $dompdf->render();
1715                                $dompdf->stream(strtok($this->file,'.').".pdf");
1716                                $GLOBALS['phpgw']->common->phpgw_exit();
1717                        }
1718                }
1719
1720                //give back an array with all directories except current and dirs that are not accessable
1721                function all_other_directories_options()
1722                {
1723                        # First we get the directories in their home directory
1724                        $dirs = array();
1725                        $dirs[] = array('directory' => $this->bo->fakebase, 'name' => $this->bo->userinfo['account_lid']);
1726
1727                        $tmp_arr=array(
1728                                'string'        => $this->bo->homedir,
1729                                'relatives'     => array(RELATIVE_NONE),
1730                                'checksubdirs'  => True,
1731                                'mime_type'     => 'Directory'
1732                        );
1733
1734                        $ls_array = $this->bo->vfs->ls($tmp_arr);
1735
1736                        while(list($num, $dir) = each($ls_array))
1737                        {
1738                                $dirs[] = $dir;
1739                        }
1740
1741
1742                        # Then we get the directories in their readable groups' home directories
1743                        reset($this->readable_groups);
1744                        while(list($num, $group_array) = each($this->readable_groups))
1745                        {
1746                                /* Don't list directories for groups that don't have access
1747                                if(!$this->groups_applications[$group_array['account_name']][$this->bo->appname]['enabled'])
1748                                {
1749]                                       continue;
1750                                }*/
1751
1752                                $dirs[] = array('directory' => $this->bo->fakebase, 'name' => $group_array['account_name']);
1753
1754                                $tmp_arr=array(
1755                                        'string'        => $this->bo->fakebase.'/'.$group_array['account_name'],
1756                                        'relatives'     => array(RELATIVE_NONE),
1757                                        'checksubdirs'  => True,
1758                                        'mime_type'     => 'Directory'
1759                                );
1760
1761                                $ls_array = $this->bo->vfs->ls($tmp_arr);
1762                                while(list($num, $dir) = each($ls_array))
1763                                {
1764                                        $dirs[] = $dir;
1765                                }
1766                        }
1767
1768                        reset($dirs);
1769                        while(list($num, $dir) = each($dirs))
1770                        {
1771                                if(!$dir['directory'])
1772                                {
1773                                        continue;
1774                                }
1775
1776                                # So we don't display //
1777                                if($dir['directory'] != '/')
1778                                {
1779                                        $dir['directory'] .= '/';
1780                                }
1781
1782                                # No point in displaying the current directory, or a directory that doesn't exist
1783                                if((($dir['directory'] . $dir['name']) != $this->path) && $this->bo->vfs->file_exists(array('string' => $dir['directory'] . $dir['name'],'relatives' => array(RELATIVE_NONE))))
1784                                {
1785                                        //FIXME replace the html_form_option function
1786                                        $options .= $this->html_form_option($dir['directory'] . $dir['name'], $dir['directory'] . $dir['name']);
1787                                }
1788                        }
1789
1790                        return $options;
1791                }
1792
1793                /* seek icon for mimetype else return an unknown icon */
1794                function mime_icon($mime_type, $size=16)
1795                {
1796                        if(!$mime_type) $mime_type='unknown';
1797
1798                        $mime_type=str_replace  ('/','_',$mime_type);
1799
1800                        $img=$GLOBALS['phpgw']->common->image('filemanager','mime'.$size.'_'.strtolower($mime_type));
1801                        if(!$img) $img=$GLOBALS['phpgw']->common->image('filemanager','mime'.$size.'_unknown');
1802
1803                        $icon='<img src="'.$img.' "alt="'.lang($mime_type).'" />';
1804                        return $icon;
1805                }
1806
1807                function linkButton($link,$img='',$description='')
1808                {
1809                        $image=$GLOBALS['phpgw']->common->image('filemanager','button_'.strtolower($img));
1810
1811                        if($img)
1812                        {
1813                                return '<td class="" align="center" valign="middle" height="28" width="70">
1814                                <a href="'.$link.'" title="'.$description.'"><img src="'.$image.'" alt="'.$description.'"/></a><br><small>'.$description.'</small>
1815                                </td>';
1816                        }
1817                }
1818
1819                function inputButton($name,$img='',$description='')
1820                {
1821                        $image=$GLOBALS['phpgw']->common->image('filemanager','button_'.strtolower($img));
1822
1823                        if($img)
1824                        {
1825                                return '<td class="" align="center" valign="middle" height="28" width="70">
1826                                <input title="'.$description.'" name="'.$name.'" type="image" alt="'.$name.'" src="'.$image.'" value="clicked" /><br><small>'.$description.'</small>
1827                                </td>';
1828                        }
1829                }
1830                function inputImage($name,$img='',$description='')
1831                {
1832                        $image=$GLOBALS['phpgw']->common->image('filemanager','button_'.strtolower($img));
1833
1834                        if($img)
1835                        {
1836                                return '<td class="" align="center" valign="middle" height="28" width="70">
1837                                <img onClick="toolbar_control(\''.$name.'\')" title="'.$description.'" name="'.$name.'" alt="'.$name.'" src="'.$image.'" /><br><small>'.$description.'</small>
1838                                </td>';
1839                        }
1840                }
1841
1842
1843
1844                function html_form_input($type = NULL, $name = NULL, $value = NULL, $maxlength = NULL, $size = NULL, $checked = NULL, $string = '', $return = 1)
1845                {
1846                        $text = ' ';
1847                        if($type != NULL && $type)
1848                        {
1849                                if($type == 'checkbox')
1850                                {
1851                                        $value = $this->bo->string_encode($value, 1);
1852                                }
1853                                $text .= 'type="'.$type.'" ';
1854                        }
1855                        if($name != NULL && $name)
1856                        {
1857                                $text .= 'name="'.$name.'" ';
1858                        }
1859                        if($value != NULL && $value)
1860                        {
1861                                $text .= 'value="'.$value.'" ';
1862                        }
1863                        if(is_int($maxlength) && $maxlength >= 0)
1864                        {
1865                                $text .= 'maxlength="'.$maxlength.'" ';
1866                        }
1867                        if(is_int($size) && $size >= 0)
1868                        {
1869                                $text .= 'size="'.$size.'" ';
1870                        }
1871                        if($checked != NULL && $checked)
1872                        {
1873                                $text .= 'checked ';
1874                        }
1875
1876                        return '<input'.$text.$string.'>';
1877                }
1878
1879                function html_form_option($value = NULL, $displayed = NULL, $selected = NULL, $return = 0)
1880                {
1881                        $text = ' ';
1882                        if($value != NULL && $value)
1883                        {
1884                                $text .= ' value="'.$value.'" ';
1885                        }
1886                        if($selected != NULL && $selected)
1887                        {
1888                                $text .= ' selected';
1889                        }
1890                        return  '<option'.$text.'>'.$displayed.'</option>';
1891                }
1892
1893                function encode_href($href = NULL, $args = NULL , $extra_args)
1894                {
1895                        $href = $this->bo->string_encode($href, 1);
1896                        $all_args = $args.'&'.$this->bo->string_encode($extra_args, 1);
1897
1898                        $address = $GLOBALS['phpgw']->link($href, $all_args);
1899
1900                        return $address;
1901                }
1902
1903                function html_link($href = NULL, $args = NULL , $extra_args, $text = NULL, $return = 1, $encode = 1, $linkonly = 0, $target = NULL)
1904                {
1905                        //      unset($encode);
1906                        if($encode)
1907                        {
1908                                $href = $this->bo->string_encode($href, 1);
1909                                $all_args = $args.'&'.$this->bo->string_encode($extra_args, 1);
1910                        }
1911                        else
1912                        {
1913                                //                              $href = $this->bo->string_encode($href, 1);
1914                                $all_args = $args.'&'.$extra_args;
1915                        }
1916                        ###
1917                        # This decodes / back to normal
1918                        ###
1919                        //                      $all_args = preg_replace("/%2F/", "/", $all_args);
1920                        //                      $href = preg_replace("/%2F/", "/", $href);
1921
1922                        /* Auto-detect and don't disturb absolute links */
1923                        if(!preg_match("|^http(.{0,1})://|", $href))
1924                        {
1925                                //Only add an extra / if there isn't already one there
1926
1927                                // die(SEP);
1928                                if(!($href[0] == SEP))
1929                                {
1930                                        $href = SEP . $href;
1931                                }
1932
1933                                /* $phpgw->link requires that the extra vars be passed separately */
1934                                //                              $link_parts = explode("?", $href);
1935                                $address = $GLOBALS['phpgw']->link($href, $all_args);
1936                                //                              $address = $GLOBALS['phpgw']->link($href);
1937                        }
1938                        else
1939                        {
1940                                $address = $href;
1941                        }
1942
1943                        /* If $linkonly is set, don't add any HTML */
1944                        if($linkonly)
1945                        {
1946                                $rstring = $address;
1947                        }
1948                        else
1949                        {
1950                                if($target)
1951                                {
1952                                        $target = 'target='.$target;
1953                                }
1954
1955                                $text = trim($text);
1956                                $rstring = '<a href="'.$address.'" '.$target.'>'.$text.'</a>';
1957                        }
1958
1959                        return($this->bo->eor($rstring, $return));
1960                }
1961
1962                function html_table_begin($width = NULL, $border = NULL, $cellspacing = NULL, $cellpadding = NULL, $rules = NULL, $string = '', $return = 0)
1963                {
1964                        if($width != NULL && $width)
1965                        {
1966                                $width = "width=$width";
1967                        }
1968                        if(is_int($border) && $border >= 0)
1969                        {
1970                                $border = "border=$border";
1971                        }
1972                        if(is_int($cellspacing) && $cellspacing >= 0)
1973                        {
1974                                $cellspacing = "cellspacing=$cellspacing";
1975                        }
1976                        if(is_int($cellpadding) && $cellpadding >= 0)
1977                        {
1978                                $cellpadding = "cellpadding=$cellpadding";
1979                        }
1980                        if($rules != NULL && $rules)
1981                        {
1982                                $rules = "rules=$rules";
1983                        }
1984
1985                        $rstring = "<table $width $border $cellspacing $cellpadding $rules $string>";
1986                        return($this->bo->eor($rstring, $return));
1987                }
1988
1989                function html_table_end($return = 0)
1990                {
1991                        $rstring = "</table>";
1992                        return($this->bo->eor($rstring, $return));
1993                }
1994
1995                function html_table_row_begin($align = NULL, $halign = NULL, $valign = NULL, $bgcolor = NULL, $string = '', $return = 0)
1996                {
1997                        if($align != NULL && $align)
1998                        {
1999                                $align = "align=$align";
2000                        }
2001                        if($halign != NULL && $halign)
2002                        {
2003                                $halign = "halign=$halign";
2004                        }
2005                        if($valign != NULL && $valign)
2006                        {
2007                                $valign = "valign=$valign";
2008                        }
2009                        if($bgcolor != NULL && $bgcolor)
2010                        {
2011                                $bgcolor = "bgcolor=$bgcolor";
2012                        }
2013                        $rstring = "<tr $align $halign $valign $bgcolor $string>";
2014                        return($this->bo->eor($rstring, $return));
2015                }
2016
2017                function html_table_row_end($return = 0)
2018                {
2019                        $rstring = "</tr>";
2020                        return($this->bo->eor($rstring, $return));
2021                }
2022
2023                function html_table_col_begin($align = NULL, $halign = NULL, $valign = NULL, $rowspan = NULL, $colspan = NULL, $string = '', $return = 0)
2024                {
2025                        if($align != NULL && $align)
2026                        {
2027                                $align = "align=$align";
2028                        }
2029                        if($halign != NULL && $halign)
2030                        {
2031                                $halign = "halign=$halign";
2032                        }
2033                        if($valign != NULL && $valign)
2034                        {
2035                                $valign = "valign=$valign";
2036                        }
2037                        if(is_int($rowspan) && $rowspan >= 0)
2038                        {
2039                                $rowspan = "rowspan=$rowspan";
2040                        }
2041                        if(is_int($colspan) && $colspan >= 0)
2042                        {
2043                                $colspan = "colspan=$colspan";
2044                        }
2045
2046                        $rstring = "<td $align $halign $valign $rowspan $colspan $string>";
2047                        return($this->bo->eor($rstring, $return));
2048                }
2049
2050                function html_table_col_end($return = 0)
2051                {
2052                        $rstring = "</td>";
2053                        return($this->bo->eor($rstring, $return));
2054                }
2055        }
Note: See TracBrowser for help on using the repository browser.