source: branches/2.2/filemanager/inc/class.uifilemanager.inc.php @ 3873

Revision 3873, 47.0 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #1646 - Erro em gerenciamento de pastas do File manager

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