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

Revision 1896, 11.3 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Melhoria do FM. melhorias na interface, Cartao do usuario

  • 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.vfs_functions.inc.php 2009-11-11 amuller $ */
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                        'archive'=>True,
29                        'unarchive'=>True,
30                        'copyto'=>True,
31                        'moveto'=>True,
32                        'summary' => True
33                );
34
35                //keep
36                var $bo;
37                var $dispath;
38                var $cwd;
39                var $lesspath;
40                var $dispsep;
41
42                var $target;
43
44                var $prefs;//array
45
46                var $current_config;
47                // this ones must be checked thorougly;
48                var $fileman = Array();
49                //var $fileman;
50                var $path;
51                var $file;
52                var $debug = false;
53                var $now;
54
55                function vfs_functions()
56                {
57                        $this->now = date('Y-m-d H:i:s');
58
59                        $this->bo = CreateObject('filemanager.bofilemanager');
60
61                        $c = CreateObject('phpgwapi.config','filemanager');
62                        $c->read_repository();
63                        $this->current_config = $c->config_data;
64
65
66                        // here local vars are created from the HTTP vars
67                        @reset($GLOBALS['HTTP_POST_VARS']);
68                        while(list($name,) = @each($GLOBALS['HTTP_POST_VARS']))
69                        {
70                                $this->$name = $GLOBALS['HTTP_POST_VARS'][$name];
71                        }
72
73                        @reset($GLOBALS['HTTP_GET_VARS']);
74                        while(list($name,) = @each($GLOBALS['HTTP_GET_VARS']))
75                        {
76                                $$name = $GLOBALS['HTTP_GET_VARS'][$name];
77                                $this->$name = $GLOBALS['HTTP_GET_VARS'][$name];
78
79                        }
80
81                        $to_decode = array
82                        (
83                                'op'    => array('op' => ''),
84                                'path'  => array('path' => ''),
85                                'file'  => array('file' => ''),
86                                'sortby'        => array('sortby' => ''),
87                                'messages'      => array('messages'     => ''),
88                                'comment'       => array('comment' => ''),
89                                'to'    => array('to' => '')
90                        );
91
92                        reset($to_decode);
93                        while(list($var, $conditions) = each($to_decode))
94                        {
95                                while(list($condvar, $condvalue) = each($conditions))
96                                {
97                                        if(isset($$condvar) && ($condvar == $var || $$condvar == $condvalue))
98                                        {
99                                                if(is_array($$var))
100                                                {
101                                                        $temp = array();
102                                                        while(list($varkey, $varvalue) = each($$var))
103                                                        {
104                                                                if(is_int($varkey))
105                                                                {
106                                                                        $temp[$varkey] = stripslashes(base64_decode(urldecode(($varvalue))));
107                                                                }
108                                                                else
109                                                                {
110                                                                        $temp[stripslashes(base64_decode(urldecode(($varkey))))] = $varvalue;
111                                                                }
112                                                        }
113                                                        $this->$var = $temp;
114                                                }
115                                                elseif(isset($$var))
116                                                {
117                                                        $this->$var = stripslashes(base64_decode(urldecode($$var)));
118                                                }
119                                        }
120                                }
121                        }
122
123                        // get appl. and user prefs
124                        $pref = CreateObject('phpgwapi.preferences', $this->bo->userinfo['username']);
125                        $pref->read_repository();
126                        $pref->save_repository(True);
127                        $pref_array = $pref->read_repository();
128                        $this->prefs = $pref_array[$this->bo->appname];
129
130                        //always show name
131
132                        $this->prefs[name] =1;         
133                       
134                }
135        // String format is YYYY-MM-DD HH:MM
136                function dateString2timeStamp($string){
137                        return mktime($string[11].$string[12],
138                                $string[14].$string[15],
139                                $string[17].$string[18],
140                                $string[5].$string[6],
141                                $string[8].$string[9],
142                                $string[0].$string[1].
143                                $string[2].$string[3]);
144                }
145                function verifyLock($file,$relative){
146                        $ls_array = $this->bo->vfs->ls(array(
147                                'string'        => $file,
148                                'relatives'     => array($relative),
149                                'checksubdirs'  => False,
150                                'nofiles'       => True
151                        ));
152                        $timestamp = $this->dateString2timeStamp($ls_array[0]['modified']);
153                        if (time() - $timestamp < 60 && $ls_array[0]['modifiedby_id'] != $GLOBALS['phpgw_info']['user']['account_id']) // recently than last minute: someone is editing
154                        {
155                                $this->messages[]=lang('Error:').lang('This file is being edited right now by:').$GLOBALS['phpgw']->accounts->id2name($ls_array[0]['modifiedby_id']);
156                                return False;
157
158                        }
159                        else
160                                return True;
161                }
162
163                function setRestricted(){
164                        $GLOBALS['phpgw_info']['flags'] = array
165                                (
166                                        'currentapp'    => 'filemanager',
167                                        'noheader'      => True,
168                                        'nonavbar' => True,
169                                        'nofooter'      => True,
170                                        'noappheader'   => True,
171                                        'enable_browser_class'  => True
172                                );
173
174                        if ($this->file)
175                        {
176                                $filename=$this->path.'/'.$this->file;
177                                if(!$this->verifyLock($filename,RELATIVE_NONE))
178                                {
179                                        echo "False";
180                                        return False;
181                                }
182                               
183                                $ls_array = $this->bo->vfs->ls(array(
184                                        'string'        => $filename,
185                                        'relatives'     => array(RELATIVE_NONE),
186                                        'checksubdirs'  => False,
187                                        'nofiles'       => True
188                                ));
189                                if (intval($ls_array[0]['type']) == 0)
190                                        $type = 1;
191                                else
192                                        $type = 0;
193
194                                if($this->bo->vfs->set_attributes (array(
195                                        'string'        => $filename,
196                                        'relatives'     => RELATIVE_NONE,
197                                        'attributes'    => array('type' => $type)
198                                        ))
199                                )
200                                {
201                                        echo "True|".$this->file;
202                                }
203                                else
204                                {
205                                        echo "False";
206                                }
207                        }
208
209                }
210                function touch(){
211                        if($this->file)
212                                if ($this->bo->vfs->touch(array('string'=> $this->file,'relatives' => array(RELATIVE_ALL))))
213                                {
214                                        echo "True";
215                                        return True;
216                                }
217                                else
218                                        return False;
219
220                }
221                function summary()
222                {
223                        header('Content-Type: image/gif');
224                        $expires = 60*60*24*15;
225                        header("Cache-Control: maxage=".$expires);
226                        header("Pragma: public");
227                        header("Expires: ".gmdate('D, d M Y H:i:s', time()+$expires));
228                        if($this->file)
229                        {       
230                                $content = $this->bo->vfs->summary(array('path' => $this->path,
231                                        'string' => $this->file
232                                ));
233                                if (strlen($content) < 1)
234                                {
235                                        $filename = './filemanager/templates/default/images/error.gif';
236                                        $handle = fopen($filename,'rb');
237                                        $content = fread($handle,filesize($filename));
238                                        fclose($handle);
239                                }
240                                echo $content;
241                        }
242                        $GLOBALS['phpgw']->common->phpgw_exit();
243                }
244       
245                function delete(){
246                        foreach($this->fileman as $filecode)
247                        {
248                                $filename = base64_decode($filecode);
249                                if($this->verifyLock($filename,RELATIVE_ALL) && $this->bo->vfs->rm(array(
250                                        'string' => $this->path.'/'.$filename,
251                                        'relatives' => array (RELATIVE_NONE)
252                                )))
253                                {
254                                        echo $filename."|";
255                                }
256                                else
257                                {
258                                        echo "False|".$filename;
259                                        return False;
260                                }
261                        }
262                }
263                function archive(){
264                        foreach($this->fileman as $filecode)
265                        {
266                                $filename = base64_decode($filecode);
267                                if(!$this->verifyLock($filename,RELATIVE_ALL))
268                                {
269                                        echo "locked|".$filename;
270                                        return False;
271                                }
272                                $command .= " ".escapeshellarg($filename);
273                        }
274                        $zipFileName=$GLOBALS['phpgw_info']['user']['account_lid'].date("Y-m-d,H:i:s").".zip";
275                        $zipFilePath=ini_get("session.save_path")."/".$zipFileName;
276                        $command = $zipFilePath.$command;
277
278                        if (strlen($this->pswd) > 0){
279                                $command = " -P ".(base64_decode($this->pswd) ^ $_SESSION['phpgw_info']['filemanager']['user']['sec_key'])." ".$command;
280                        }
281
282                        exec("cd ".$this->bo->vfs->basedir.$this->path.";".escapeshellcmd("nice -n19 zip -9 ".$command),$output,$return_var);
283                        exec("history -c"); // privacy is good, we dont want get passwords!
284                        if ($return_var > 1){
285                                echo "False|".$return_var;
286                                return false;
287                        }
288
289                        $this->bo->vfs->cp(array(
290                                'from'=> $zipFilePath,
291                                'to'=> $zipFileName,
292                                'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
293                        ));
294                        $this->bo->vfs->set_attributes(array(
295                                'string'=> $zipFileName,
296                                'relatives'     => array(RELATIVE_ALL),
297                                'attributes'=> array(
298                                        'mime_type' => "application/zip"
299                                )
300                        ));
301                        exec("rm -f ".escapeshellcmd(escapeshellarg($zipFilePath)));
302                        $this->delete();
303                }
304                function unarchive(){
305                        $command = escapeshellarg($this->file);
306                        if (strlen($this->pswd) > 0){
307                                $command = " -P ".(base64_decode($this->pswd) ^ $_SESSION['phpgw_info']['filemanager']['user']['sec_key'])." ".$command;
308                        }
309
310                        exec("cd ".escapeshellarg($this->bo->vfs->basedir.$this->path).";".escapeshellcmd("nice -n19 unzip ".$command),$output, $return_var);
311                        exec("history -c"); // privacy is good, we dont want get passwords!
312
313                        if ($return_var == 9 || $return_var == 5 || $return_var == 82){
314                                echo "wpasswd|";
315                                return false;
316                        }else if($return_var > 1){
317                                echo "False|";
318                        }
319
320                        $this->fileman[] = $this->file;
321                        $this->delete();
322                        $this->bo->vfs->update_real(array(
323                                        'string'        => $this->path,
324                                        'relatives'     => array(RELATIVE_NONE)
325                                ));
326                }
327                function editComment()
328                {
329                                if($badchar = $this->bo->bad_chars($this->comment, False, True))
330                                {
331                                        echo "False|badchar|".$badchar;
332                                        return False;
333                                }
334
335                                if ($this->bo->vfs->set_attributes(array(
336                                        'string'        => $this->file,
337                                        'relatives'     => array(RELATIVE_ALL),
338                                        'attributes'    => array(
339                                        'comment' => stripslashes($this->comment)
340                                        )
341                                )))
342                                {
343                                        echo "True|".$this->file;
344                                        return True;
345                                }
346                }
347                # Handle Moving Files and Directories
348                function moveto()
349                {
350                        if(!$this->to)
351                        {
352                                echo "NODIR|";
353                                return;
354                        }
355                        else
356                        {
357                                $this->from = base64_decode($this->from);
358                                while(list($num, $file) = each($this->fileman))
359                                {
360                                        if($this->bo->vfs->mv(array(
361                                                'from'  => $this->from . '/' . $file,
362                                                'to'    => $this->to . '/' . $file,
363                                                'relatives'     => array(RELATIVE_NONE, RELATIVE_NONE)
364                                        )))
365                                                $moved++;
366                                        else
367                                                $error++;
368                                }
369                        }
370                        if($error > 0){
371                                echo "SOMEERROR|".$error;
372                                return;
373                        }
374                        if($moved > 0)
375                                echo "MOVED|".$moved;
376                }
377
378                // Handle Copying of Files and Directories
379                function copyto()
380                {
381                        if(!$this->to)
382                        {
383                                echo "NODIR|";
384                                return;
385                        }
386                        else
387                        {
388                                $this->from = base64_decode($this->from);
389                                while(list($num, $file) = each($this->fileman))
390                                {
391                                        if($this->bo->vfs->cp(array(
392                                                'from'  => $this->from . '/' . $file,
393                                                'to'    => $this->to . '/' . $file,
394                                                'relatives'     => array(RELATIVE_NONE, RELATIVE_NONE)
395                                        )))
396                                                $copied++;
397                                        else
398                                                $error++;
399                                }
400                        }
401                        if($error > 0){
402                                echo "SOMEERROR|".$error;
403                                return;
404                        }
405                        if($copied > 0)
406                                echo "COPIED|".$copied;
407                }
408
409                # Handle Renaming Files and Directories
410                function rename()
411                {
412                        if ($this->file)
413                        {
414                                if($badchar = $this->bo->bad_chars($this->to, True, True))
415                                {
416                                        echo "Error|badchar|".$badchar;
417                                        return false;
418                                }
419                                if(ereg("/", $this->to) || ereg("\\\\", $this->to))
420                                {
421                                        echo "Error|slashes";
422                                        return false;
423                                }
424                                elseif(!$this->verifyLock($this->file,RELATIVE_CURRENT))
425                                        echo "Error|editing";
426                                elseif ($this->bo->vfs->mv(array(
427                                        'from'  => $this->path.'/'.$this->file,
428                                        'to'    => $this->path.'/'.$this->to,
429                                        'relatives' => array(RELATIVE_NONE,RELATIVE_NONE)
430                                )))
431                                {
432                                        echo "True|".$this->file."|".$this->to;
433                                }
434                                else
435                                {
436                                        echo "Error|".$this->file."|".$this->to;
437                                }
438                        }
439                }
440
441        }
Note: See TracBrowser for help on using the repository browser.