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

Revision 1781, 49.2 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Melhorias no módulos gerenciador de arquivos do expresso livre

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