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

Revision 1654, 7.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                        'rename'=>True,
27                        'delete'=>True
28                );
29
30                //keep
31                var $bo;
32                var $dispath;
33                var $cwd;
34                var $lesspath;
35                var $dispsep;
36
37                var $target;
38
39                var $prefs;//array
40
41                var $current_config;
42                // this ones must be checked thorougly;
43                var $fileman = Array();
44                //var $fileman;
45                var $path;
46                var $file;
47                var $debug = false;
48                var $now;
49
50                function vfs_functions()
51                {
52                        $this->now = date('Y-m-d');
53
54                        $this->bo = CreateObject('filemanager.bofilemanager');
55
56                        $c = CreateObject('phpgwapi.config','filemanager');
57                        $c->read_repository();
58                        $this->current_config = $c->config_data;
59
60
61                        // here local vars are created from the HTTP vars
62                        @reset($GLOBALS['HTTP_POST_VARS']);
63                        while(list($name,) = @each($GLOBALS['HTTP_POST_VARS']))
64                        {
65                                $this->$name = $GLOBALS['HTTP_POST_VARS'][$name];
66                        }
67
68                        @reset($GLOBALS['HTTP_GET_VARS']);
69                        while(list($name,) = @each($GLOBALS['HTTP_GET_VARS']))
70                        {
71                                $$name = $GLOBALS['HTTP_GET_VARS'][$name];
72                                $this->$name = $GLOBALS['HTTP_GET_VARS'][$name];
73
74                        }
75
76                        $to_decode = array
77                        (
78                                'op'    => array('op' => ''),
79                                'path'  => array('path' => ''),
80                                'file'  => array('file' => ''),
81                                'sortby'        => array('sortby' => ''),
82                                'messages'      => array('messages'     => ''),
83                                'comment'       => array('comment' => ''),
84                                'to'    => array('to' => '')
85                        );
86
87                        reset($to_decode);
88                        while(list($var, $conditions) = each($to_decode))
89                        {
90                                while(list($condvar, $condvalue) = each($conditions))
91                                {
92                                        if(isset($$condvar) && ($condvar == $var || $$condvar == $condvalue))
93                                        {
94                                                if(is_array($$var))
95                                                {
96                                                        $temp = array();
97                                                        while(list($varkey, $varvalue) = each($$var))
98                                                        {
99                                                                if(is_int($varkey))
100                                                                {
101                                                                        $temp[$varkey] = stripslashes(base64_decode(urldecode(($varvalue))));
102                                                                }
103                                                                else
104                                                                {
105                                                                        $temp[stripslashes(base64_decode(urldecode(($varkey))))] = $varvalue;
106                                                                }
107                                                        }
108                                                        $this->$var = $temp;
109                                                }
110                                                elseif(isset($$var))
111                                                {
112                                                        $this->$var = stripslashes(base64_decode(urldecode($$var)));
113                                                }
114                                        }
115                                }
116                        }
117
118                        // get appl. and user prefs
119                        $pref = CreateObject('phpgwapi.preferences', $this->bo->userinfo['username']);
120                        $pref->read_repository();
121                        $pref->save_repository(True);
122                        $pref_array = $pref->read_repository();
123                        $this->prefs = $pref_array[$this->bo->appname];
124
125                        //always show name
126
127                        $this->prefs[name] =1;         
128                       
129                }
130        // String format is YYYY-MM-DD HH:MM
131                function dateString2timeStamp($string){
132                        return mktime($string[11].$string[12],
133                                $string[14].$string[15],
134                                $string[17].$string[18],
135                                $string[5].$string[6],
136                                $string[8].$string[9],
137                                $string[0].$string[1].
138                                $string[2].$string[3]);
139                }
140                function verifyLock($file,$relative){
141                        $ls_array = $this->bo->vfs->ls(array(
142                                'string'        => $file,
143                                'relatives'     => array($relative),
144                                'checksubdirs'  => False,
145                                'nofiles'       => True
146                        ));
147                        $timestamp = $this->dateString2timeStamp($ls_array[0]['modified']);
148                        if (time() - $timestamp < 60 && $ls_array[0]['modifiedby_id'] != $GLOBALS['phpgw_info']['user']['account_id']) // recently than last minute: someone is editing
149                        {
150                                $this->messages[]=lang('Error:').lang('This file is being edited right now by:').$GLOBALS['phpgw']->accounts->id2name($ls_array[0]['modifiedby_id']);
151                                return False;
152
153                        }
154                        else
155                                return True;
156                }
157
158                function setRestricted(){
159                        $GLOBALS['phpgw_info']['flags'] = array
160                                (
161                                        'currentapp'    => 'filemanager',
162                                        'noheader'      => True,
163                                        'nonavbar' => True,
164                                        'nofooter'      => True,
165                                        'noappheader'   => True,
166                                        'enable_browser_class'  => True
167                                );
168
169                        if ($this->file)
170                        {
171                                $filename=$this->path.'/'.$this->file;
172                                if(!$this->verifyLock($filename,RELATIVE_NONE))
173                                {
174                                        echo "False";
175                                        return False;
176                                }
177                               
178                                $ls_array = $this->bo->vfs->ls(array(
179                                        'string'        => $filename,
180                                        'relatives'     => array(RELATIVE_NONE),
181                                        'checksubdirs'  => False,
182                                        'nofiles'       => True
183                                ));
184                                if (intval($ls_array[0]['type']) == 0)
185                                        $type = 1;
186                                else
187                                        $type = 0;
188
189                                if($this->bo->vfs->set_attributes (array(
190                                        'string'        => $filename,
191                                        'relatives'     => RELATIVE_NONE,
192                                        'attributes'    => array('type' => $type)
193                                        ))
194                                )
195                                {
196                                        echo "True:".$this->file;
197                                }
198                                else
199                                {
200                                        echo "False";
201                                }
202                        }
203
204                }
205                function touch(){
206                        if($this->file)
207                                if ($this->bo->vfs->touch(array('string'=> $this->file,'relatives' => array(RELATIVE_ALL))))
208                                {
209                                        echo "True";
210                                        return True;
211                                }
212                                else
213                                        return False;
214
215                }
216                function download()
217                {
218                        for($i = 0; $i != $this->numoffiles; $i++)
219                        {
220                                if(!$this->fileman[$i])
221                                {
222                                        continue;
223                                }
224
225                                $download_browser = CreateObject('phpgwapi.browser');
226                                $download_browser->content_header($this->fileman[$i]);
227                                echo $this->bo->vfs->read(array('string' => $this->fileman[$i]));
228                                $GLOBALS['phpgw']->common->phpgw_exit();
229                        }
230                }
231                function delete(){
232                        foreach($this->fileman as $filename)
233                        {
234                                if($this->verifyLock($filename,RELATIVE_ALL) && $this->bo->vfs->delete(array('string' => $filename)))
235                                {
236                                        echo $filename.":";
237                                }
238                                else
239                                {
240                                        echo "False:".$filename;
241                                        return False;
242                                }
243                        }
244                }
245                function editComment()
246                {
247                                if($badchar = $this->bo->bad_chars($this->comment, False, True))
248                                {
249                                        echo "False:badchar:".$badchar;
250                                        return False;
251                                }
252
253                                if ($this->bo->vfs->set_attributes(array(
254                                        'string'        => $this->file,
255                                        'relatives'     => array(RELATIVE_ALL),
256                                        'attributes'    => array(
257                                        'comment' => stripslashes($this->comment)
258                                        )
259                                )))
260                                {
261                                        echo "True:".$this->file;
262                                        return True;
263                                }
264                }
265                # Handle Renaming Files and Directories
266                function rename()
267                {
268                        if ($this->file)
269                        {
270                                if($badchar = $this->bo->bad_chars($this->to, True, True))
271                                {
272                                        echo "Error:badchar:".$badchar;
273                                        return false;
274                                }
275                                if(ereg("/", $this->to) || ereg("\\\\", $this->to))
276                                {
277                                        echo "Error:slashes";
278                                        return false;
279                                }
280                                elseif(!$this->verifyLock($this->file,RELATIVE_CURRENT))
281                                        echo "Error:editing";
282                                elseif ($this->bo->vfs->mv(array(
283                                        'from'  => $this->path.'/'.$this->file,
284                                        'to'    => $this->path.'/'.$this->to,
285                                        'relatives' => array(RELATIVE_NONE,RELATIVE_NONE)
286                                )))
287                                {
288                                        echo "True:".$this->file.":".$this->to;
289                                }
290                                else
291                                {
292                                        echo "Error:".$this->file.":".$this->to;
293                                }
294                        }
295                }
296
297        }
Note: See TracBrowser for help on using the repository browser.