source: sandbox/filemanager/inc/class.vfs_functions.inc.php @ 1648

Revision 1648, 6.6 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - melhoria no modulo gerenciador de arquivos

  • Property svn:executable set to *
Line 
1<?php
2        /**************************************************************************\
3        * -------------------------------------------------------------------------*
4        * This library is free software; you can redistribute it and/or modify it  *
5        * under the terms of the GNU Lesser General Public License as published by *
6        * the Free Software Foundation; either version 2.1 of the License,         *
7        * or any later version.                                                    *
8        * This library is distributed in the hope that it will be useful, but      *
9        * WITHOUT ANY WARRANTY; without even the implied warranty of               *
10        * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
11        * See the GNU Lesser General Public License for more details.              *
12        * You should have received a copy of the GNU Lesser General Public License *
13        * along with this library; if not, write to the Free Software Foundation,  *
14        * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            *
15        \**************************************************************************/
16
17        /* $Id: class.uifilemanager.inc.php 17511 2004-12-12 06:35:24Z dawnlinux $ */
18
19        class vfs_functions
20        {
21                var $public_functions = array(
22                        'touch' => True,
23                        'download'=>True,
24                        'setRestricted'=>True,
25                        'editComment'=> True
26                );
27
28                //keep
29                var $bo;
30                var $dispath;
31                var $cwd;
32                var $lesspath;
33                var $dispsep;
34
35                var $target;
36
37                var $prefs;//array
38
39                var $current_config;
40                // this ones must be checked thorougly;
41                var $fileman = Array();
42                //var $fileman;
43                var $path;
44                var $file;
45                var $debug = false;
46                var $now;
47
48                function vfs_functions()
49                {
50                        $this->now = date('Y-m-d');
51
52                        $this->bo = CreateObject('filemanager.bofilemanager');
53
54                        $c = CreateObject('phpgwapi.config','filemanager');
55                        $c->read_repository();
56                        $this->current_config = $c->config_data;
57
58
59                        // here local vars are created from the HTTP vars
60                        @reset($GLOBALS['HTTP_POST_VARS']);
61                        while(list($name,) = @each($GLOBALS['HTTP_POST_VARS']))
62                        {
63                                $this->$name = $GLOBALS['HTTP_POST_VARS'][$name];
64                        }
65
66                        @reset($GLOBALS['HTTP_GET_VARS']);
67                        while(list($name,) = @each($GLOBALS['HTTP_GET_VARS']))
68                        {
69                                $$name = $GLOBALS['HTTP_GET_VARS'][$name];
70                                $this->$name = $GLOBALS['HTTP_GET_VARS'][$name];
71
72                        }
73
74                        $to_decode = array
75                        (
76                                'op'    => array('op' => ''),
77                                'path'  => array('path' => ''),
78                                'file'  => array('file' => ''),
79                                'sortby'        => array('sortby' => ''),
80                                'messages'      => array('messages'     => ''),
81                                'comment_files' => array('comment_files' => ''),
82                                'show_upload_boxes'     => array('show_upload_boxes' => '')
83                        );
84
85                        reset($to_decode);
86                        while(list($var, $conditions) = each($to_decode))
87                        {
88                                while(list($condvar, $condvalue) = each($conditions))
89                                {
90                                        if(isset($$condvar) && ($condvar == $var || $$condvar == $condvalue))
91                                        {
92                                                if(is_array($$var))
93                                                {
94                                                        $temp = array();
95                                                        while(list($varkey, $varvalue) = each($$var))
96                                                        {
97                                                                if(is_int($varkey))
98                                                                {
99                                                                        $temp[$varkey] = stripslashes(base64_decode(urldecode(($varvalue))));
100                                                                }
101                                                                else
102                                                                {
103                                                                        $temp[stripslashes(base64_decode(urldecode(($varkey))))] = $varvalue;
104                                                                }
105                                                        }
106                                                        $this->$var = $temp;
107                                                }
108                                                elseif(isset($$var))
109                                                {
110                                                        $this->$var = stripslashes(base64_decode(urldecode($$var)));
111                                                }
112                                        }
113                                }
114                        }
115
116                        // get appl. and user prefs
117                        $pref = CreateObject('phpgwapi.preferences', $this->bo->userinfo['username']);
118                        $pref->read_repository();
119                        $pref->save_repository(True);
120                        $pref_array = $pref->read_repository();
121                        $this->prefs = $pref_array[$this->bo->appname];
122
123                        //always show name
124
125                        $this->prefs[name] =1;         
126                       
127                }
128        // String format is YYYY-MM-DD HH:MM
129                function dateString2timeStamp($string){
130                        return mktime($string[11].$string[12],
131                                $string[14].$string[15],
132                                $string[17].$string[18],
133                                $string[5].$string[6],
134                                $string[8].$string[9],
135                                $string[0].$string[1].
136                                $string[2].$string[3]);
137                }
138                function verifyLock($file,$relative){
139                        $ls_array = $this->bo->vfs->ls(array(
140                                'string'        => $file,
141                                'relatives'     => array($relative),
142                                'checksubdirs'  => False,
143                                'nofiles'       => True
144                        ));
145                        $timestamp = $this->dateString2timeStamp($ls_array[0]['modified']);
146                        if (time() - $timestamp < 60 && $ls_array[0]['modifiedby_id'] != $GLOBALS['phpgw_info']['user']['account_id']) // recently than last minute: someone is editing
147                        {
148                                $this->messages[]=lang('Error:').lang('This file is being edited right now by:').$GLOBALS['phpgw']->accounts->id2name($ls_array[0]['modifiedby_id']);
149                                return False;
150
151                        }
152                        else
153                                return True;
154                }
155
156                function setRestricted(){
157                        $GLOBALS['phpgw_info']['flags'] = array
158                                (
159                                        'currentapp'    => 'filemanager',
160                                        'noheader'      => True,
161                                        'nonavbar' => True,
162                                        'nofooter'      => True,
163                                        'noappheader'   => True,
164                                        'enable_browser_class'  => True
165                                );
166
167                        if ($this->file)
168                        {
169                                $filename=$this->path.'/'.$this->file;
170                                if(!$this->verifyLock($filename,RELATIVE_NONE))
171                                {
172                                        echo "False";
173                                        return False;
174                                }
175                               
176                                $ls_array = $this->bo->vfs->ls(array(
177                                        'string'        => $filename,
178                                        'relatives'     => array(RELATIVE_NONE),
179                                        'checksubdirs'  => False,
180                                        'nofiles'       => True
181                                ));
182                                if (intval($ls_array[0]['type']) == 0)
183                                        $type = 1;
184                                else
185                                        $type = 0;
186
187                                if($this->bo->vfs->set_attributes (array(
188                                        'string'        => $filename,
189                                        'relatives'     => RELATIVE_NONE,
190                                        'attributes'    => array('type' => $type)
191                                        ))
192                                )
193                                {
194                                        echo "True:".$this->file;
195                                }
196                                else
197                                {
198                                        echo "False";
199                                }
200                        }
201
202                }
203                function touch(){
204                        if($this->file)
205                                if ($this->bo->vfs->touch(array('string'=> $this->file,'relatives' => array(RELATIVE_ALL))))
206                                {
207                                        echo "True";
208                                        return True;
209                                }
210                                else
211                                        return False;
212
213                }
214                function download()
215                {
216                        for($i = 0; $i != $this->numoffiles; $i++)
217                        {
218                                if(!$this->fileman[$i])
219                                {
220                                        continue;
221                                }
222
223                                $download_browser = CreateObject('phpgwapi.browser');
224                                $download_browser->content_header($this->fileman[$i]);
225                                echo $this->bo->vfs->read(array('string' => $this->fileman[$i]));
226                                $GLOBALS['phpgw']->common->phpgw_exit();
227                        }
228                }
229                function editComment()
230                {
231                        while(list($file) = each($this->comment_files))
232                        {
233                                if($badchar = $this->bo->bad_chars($this->comment_files[$file], False, True))
234                                {
235                                        echo "False:badchar:".$badchar;
236                                        return False;
237                                }
238
239                                $this->bo->vfs->set_attributes(array(
240                                        'string'        => $file,
241                                        'relatives'     => array(RELATIVE_ALL),
242                                        'attributes'    => array(
243                                        'comment' => stripslashes($this->comment_files[$file])
244                                        )
245                                ));
246
247                                echo "True:".$file;
248                                return True;
249                        }
250                }
251        }
Note: See TracBrowser for help on using the repository browser.