2001-05-25 05:34:24 +02:00
< ? php
/************************************************************************** \
2004-05-05 14:06:13 +02:00
* eGroupWare API - VFS *
2002-01-16 07:36:51 +01:00
* This file written by Jason Wies ( Zone ) < zone @ phpgroupware . org > *
2004-05-05 14:06:13 +02:00
* This class handles file / dir access for eGroupWare *
2001-06-27 09:20:12 +02:00
* Copyright ( C ) 2001 Jason Wies *
2001-05-25 05:34:24 +02:00
* -------------------------------------------------------------------------*
2004-05-05 14:06:13 +02:00
* This library is part of the eGroupWare API *
* http :// www . egroupware . org / api *
2001-05-25 05:34:24 +02:00
* ------------------------------------------------------------------------ *
* This library is free software ; you can redistribute it and / or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation ; either version 2.1 of the License , *
* or any later version . *
* This library is distributed in the hope that it will be useful , but *
* WITHOUT ANY WARRANTY ; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . *
* See the GNU Lesser General Public License for more details . *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library ; if not , write to the Free Software Foundation , *
* Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA *
\ **************************************************************************/
/* $Id$ */
2001-08-05 09:53:59 +02:00
/*!
@ class vfs
2003-02-17 20:34:56 +01:00
@ abstract Virtual File System with SQL backend
2001-08-05 09:53:59 +02:00
@ description Authors : Zone
*/
2001-05-25 05:34:24 +02:00
2001-07-10 23:35:23 +02:00
/* These are used in calls to extra_sql () */
2001-08-10 02:03:02 +02:00
define ( 'VFS_SQL_SELECT' , 1 );
define ( 'VFS_SQL_DELETE' , 2 );
2001-08-11 11:01:47 +02:00
define ( 'VFS_SQL_UPDATE' , 4 );
2001-07-11 07:57:04 +02:00
2003-02-17 20:34:56 +01:00
class vfs extends vfs_shared
2001-05-25 05:34:24 +02:00
{
2001-08-11 11:01:47 +02:00
var $working_id ;
var $working_lid ;
var $meta_types ;
2001-12-10 05:04:56 +01:00
var $now ;
2002-08-26 06:20:33 +02:00
var $file_actions ;
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function vfs
@ abstract constructor , sets up variables
2001-07-10 23:35:23 +02:00
*/
2001-08-11 11:01:47 +02:00
function vfs ()
2001-05-25 05:34:24 +02:00
{
2003-02-17 20:34:56 +01:00
$this -> vfs_shared ();
2001-09-28 22:41:36 +02:00
$this -> basedir = $GLOBALS [ 'phpgw_info' ][ 'server' ][ 'files_dir' ];
$this -> working_id = $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'account_id' ];
$this -> working_lid = $GLOBALS [ 'phpgw' ] -> accounts -> id2name ( $this -> working_id );
$this -> now = date ( 'Y-m-d' );
2001-08-11 11:01:47 +02:00
/*
File / dir attributes , each corresponding to a database field . Useful for use in loops
If an attribute was added to the table , add it here and possibly add it to
set_attributes ()
2001-12-10 05:04:56 +01:00
set_attributes now uses this array () . 07 - Dec - 01 skeeter
2001-08-11 11:01:47 +02:00
*/
2001-09-28 22:41:36 +02:00
2003-02-17 20:34:56 +01:00
$this -> attributes [] = 'deleteable' ;
$this -> attributes [] = 'content' ;
2002-08-26 06:20:33 +02:00
/*
Decide whether to use any actual filesystem calls ( fopen (), fread (),
unlink (), rmdir (), touch (), etc . ) . If not , then we ' re working completely
in the database .
*/
2004-02-08 23:30:14 +01:00
$this -> file_actions = $GLOBALS [ 'phpgw_info' ][ 'server' ][ 'file_store_contents' ] == 'filesystem' ||
! $GLOBALS [ 'phpgw_info' ][ 'server' ][ 'file_store_contents' ];
2003-08-28 16:31:11 +02:00
// test if the files-dir is inside the document-root, and refuse working if so
//
if ( $this -> file_actions && $this -> in_docroot ( $this -> basedir ))
{
$GLOBALS [ 'phpgw' ] -> common -> phpgw_header ();
if ( $GLOBALS [ 'phpgw_info' ][ 'flags' ][ 'noheader' ])
{
echo parse_navbar ();
}
echo '<p align="center"><font color="red"><b>' . lang ( 'Path to user and group files HAS TO BE OUTSIDE of the webservers document-root!!!' ) . " </b></font></p> \n " ;
$GLOBALS [ 'phpgw' ] -> common -> phpgw_exit ();
}
2001-08-11 11:01:47 +02:00
/*
These are stored in the MIME - type field and should normally be ignored .
Adding a type here will ensure it is normally ignored , but you will have to
explicitly add it to acl_check (), and to any other SELECT ' s in this file
*/
2001-09-28 22:41:36 +02:00
$this -> meta_types = array ( 'journal' , 'journal-deleted' );
2001-08-11 11:01:47 +02:00
/* We store the linked directories in an array now, so we don't have to make the SQL call again */
2002-04-08 16:23:27 +02:00
if ( $GLOBALS [ 'phpgw_info' ][ 'server' ][ 'db_type' ] == 'mssql'
|| $GLOBALS [ 'phpgw_info' ][ 'server' ][ 'db_type' ] == 'sybase' )
{
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " SELECT directory, name, link_directory, link_name FROM phpgw_vfs WHERE CONVERT(varchar,link_directory) != '' AND CONVERT(varchar,link_name) != '' " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_SELECT )), __LINE__ , __FILE__ );
}
else
{
2002-06-24 05:18:59 +02:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " SELECT directory, name, link_directory, link_name FROM phpgw_vfs WHERE (link_directory IS NOT NULL or link_directory != '') AND (link_name IS NOT NULL or link_name != '') " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_SELECT )), __LINE__ , __FILE__ );
2002-04-08 16:23:27 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
$this -> linked_dirs = array ();
2001-09-28 22:41:36 +02:00
while ( $GLOBALS [ 'phpgw' ] -> db -> next_record ())
2001-08-11 11:01:47 +02:00
{
2001-09-28 22:41:36 +02:00
$this -> linked_dirs [] = $GLOBALS [ 'phpgw' ] -> db -> Record ;
2001-08-11 11:01:47 +02:00
}
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2003-08-28 16:31:11 +02:00
/*!
@ function in_docroot
@ abstract test if $path lies within the webservers document - root
*/
function in_docroot ( $path )
{
2004-02-08 23:30:14 +01:00
$docroots = array ( PHPGW_SERVER_ROOT , $_SERVER [ 'DOCUMENT_ROOT' ]);
2003-08-28 16:31:11 +02:00
foreach ( $docroots as $docroot )
{
$len = strlen ( $docroot );
if ( $docroot == substr ( $path , 0 , $len ))
{
$rest = substr ( $path , $len );
if ( ! strlen ( $rest ) || $rest [ 0 ] == DIRECTORY_SEPARATOR )
{
return True ;
}
}
}
return False ;
}
2001-08-11 11:01:47 +02:00
/*!
@ function extra_sql
@ abstract Return extra SQL code that should be appended to certain queries
2002-01-16 07:36:51 +01:00
@ param query_type The type of query to get extra SQL code for , in the form of a VFS_SQL define
2001-08-11 11:01:47 +02:00
@ result Extra SQL code
*/
2002-01-16 07:36:51 +01:00
function extra_sql ( $data )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
{
$data = array ( 'query_type' => VFS_SQL_SELECT );
}
if ( $data [ 'query_type' ] == VFS_SQL_SELECT || $data [ 'query_type' ] == VFS_SQL_DELETE || $data [ 'query_type' ] = VFS_SQL_UPDATE )
2001-07-13 07:12:18 +02:00
{
2001-09-28 22:41:36 +02:00
$sql = ' AND ((' ;
2003-09-21 15:54:07 +02:00
foreach ( $this -> meta_types as $num => $type )
2001-08-11 11:01:47 +02:00
{
if ( $num )
2001-09-28 22:41:36 +02:00
$sql .= ' AND ' ;
2001-08-11 11:01:47 +02:00
$sql .= " mime_type != ' $type ' " ;
}
2001-09-28 22:41:36 +02:00
$sql .= ') OR mime_type IS NULL)' ;
2001-07-13 07:12:18 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
return ( $sql );
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function add_journal
@ abstract Add a journal entry after ( or before ) completing an operation ,
and increment the version number . This function should be used internally only
2002-01-16 07:36:51 +01:00
@ discussion Note that state_one and state_two are ignored for some VFS_OPERATION ' s , for others
2001-08-11 11:01:47 +02:00
they are required . They are ignored for any " custom " operation
2002-01-16 07:36:51 +01:00
The two operations that require state_two :
operation state_two
2001-08-11 11:01:47 +02:00
VFS_OPERATION_COPIED fake_full_path of copied to
VFS_OPERATION_MOVED fake_full_path of moved to
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
If deleting , you must call add_journal () before you delete the entry from the database
2002-01-16 07:36:51 +01:00
@ param string File or directory to add entry for
@ param relatives Relativity array
@ param operation The operation that was performed . Either a VFS_OPERATION define or
2001-08-11 11:01:47 +02:00
a non - integer descriptive text string
2002-01-16 07:36:51 +01:00
@ param state_one The first " state " of the file or directory . Can be a file name , size ,
2001-08-11 11:01:47 +02:00
location , whatever is appropriate for the specific operation
2002-01-16 07:36:51 +01:00
@ param state_two The second " state " of the file or directory
@ param incversion Boolean True / False . Increment the version for the file ? Note that this is
2001-08-11 11:01:47 +02:00
handled automatically for the VFS_OPERATION defines .
i . e . VFS_OPERATION_EDITED would increment the version , VFS_OPERATION_COPIED
would not
@ result Boolean True / False
*/
2002-01-16 07:36:51 +01:00
function add_journal ( $data )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT ),
'state_one' => False ,
'state_two' => False ,
'incversion' => True
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-09-28 22:41:36 +02:00
$account_id = $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'account_id' ];
2002-01-16 07:36:51 +01:00
$p = $this -> path_parts ( array ( 'string' => $data [ 'string' ], 'relatives' => array ( $data [ 'relatives' ][ 0 ])));
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* We check that they have some sort of access to the file other than read */
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array ( 'string' => $p -> fake_full_path , 'relatives' => array ( $p -> mask ), 'operation' => PHPGW_ACL_WRITE )) &&
! $this -> acl_check ( array ( 'string' => $p -> fake_full_path , 'relatives' => array ( $p -> mask ), 'operation' => PHPGW_ACL_EDIT )) &&
! $this -> acl_check ( array ( 'string' => $p -> fake_full_path , 'relatives' => array ( $p -> mask ), 'operation' => PHPGW_ACL_DELETE )))
2001-07-13 07:12:18 +02:00
{
2001-08-11 11:01:47 +02:00
return False ;
2001-07-13 07:12:18 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> file_exists ( array ( 'string' => $p -> fake_full_path , 'relatives' => array ( $p -> mask ))))
2001-07-11 07:57:04 +02:00
{
2001-08-11 11:01:47 +02:00
return False ;
2001-07-11 07:57:04 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$ls_array = $this -> ls ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'checksubdirs' => False ,
'mime_type' => False ,
'nofiles' => True
)
);
2001-08-11 11:01:47 +02:00
$file_array = $ls_array [ 0 ];
2001-09-28 22:41:36 +02:00
$sql = 'INSERT INTO phpgw_vfs (' ;
$sql2 .= ' VALUES (' ;
2001-08-11 11:01:47 +02:00
for ( $i = 0 ; list ( $attribute , $value ) = each ( $file_array ); $i ++ )
2001-07-11 07:57:04 +02:00
{
2002-08-26 06:20:33 +02:00
if ( $attribute == 'file_id' || $attribute == 'content' )
2001-07-11 07:57:04 +02:00
{
2001-08-11 11:01:47 +02:00
continue ;
2001-07-11 07:57:04 +02:00
}
2001-09-28 22:41:36 +02:00
if ( $attribute == 'owner_id' )
2001-07-11 07:57:04 +02:00
{
2001-08-11 11:01:47 +02:00
$value = $account_id ;
2001-07-11 07:57:04 +02:00
}
2001-09-28 22:41:36 +02:00
if ( $attribute == 'created' )
2001-07-11 07:57:04 +02:00
{
2001-08-11 11:01:47 +02:00
$value = $this -> now ;
2001-07-11 07:57:04 +02:00
}
2001-08-24 09:44:43 +02:00
2001-09-28 22:41:36 +02:00
if ( $attribute == 'modified' && ! $modified )
2001-08-24 09:44:43 +02:00
{
unset ( $value );
}
2001-09-28 22:41:36 +02:00
if ( $attribute == 'mime_type' )
2001-07-11 07:57:04 +02:00
{
2001-09-28 22:41:36 +02:00
$value = 'journal' ;
2001-07-11 07:57:04 +02:00
}
2001-09-28 22:41:36 +02:00
if ( $attribute == 'comment' )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
switch ( $data [ 'operation' ])
2001-08-11 11:01:47 +02:00
{
case VFS_OPERATION_CREATED :
2001-09-28 22:41:36 +02:00
$value = 'Created' ;
2002-01-16 07:36:51 +01:00
$data [ 'incversion' ] = True ;
2001-08-11 11:01:47 +02:00
break ;
case VFS_OPERATION_EDITED :
2001-09-28 22:41:36 +02:00
$value = 'Edited' ;
2002-01-16 07:36:51 +01:00
$data [ 'incversion' ] = True ;
2001-08-11 11:01:47 +02:00
break ;
case VFS_OPERATION_EDITED_COMMENT :
2001-09-28 22:41:36 +02:00
$value = 'Edited comment' ;
2002-01-16 07:36:51 +01:00
$data [ 'incversion' ] = False ;
2001-08-11 11:01:47 +02:00
break ;
case VFS_OPERATION_COPIED :
2002-01-16 07:36:51 +01:00
if ( ! $data [ 'state_one' ])
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
$data [ 'state_one' ] = $p -> fake_full_path ;
2001-08-11 11:01:47 +02:00
}
2002-01-16 07:36:51 +01:00
if ( ! $data [ 'state_two' ])
2001-08-11 11:01:47 +02:00
{
return False ;
}
2002-01-16 07:36:51 +01:00
$value = 'Copied ' . $data [ 'state_one' ] . ' to ' . $data [ 'state_two' ];
$data [ 'incversion' ] = False ;
2001-08-11 11:01:47 +02:00
break ;
case VFS_OPERATION_MOVED :
2002-01-16 07:36:51 +01:00
if ( ! $data [ 'state_one' ])
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
$data [ 'state_one' ] = $p -> fake_full_path ;
2001-08-11 11:01:47 +02:00
}
2002-01-16 07:36:51 +01:00
if ( ! $data [ 'state_two' ])
2001-08-11 11:01:47 +02:00
{
return False ;
}
2002-01-16 07:36:51 +01:00
$value = 'Moved ' . $data [ 'state_one' ] . ' to ' . $data [ 'state_two' ];
$data [ 'incversion' ] = False ;
2001-08-11 11:01:47 +02:00
break ;
case VFS_OPERATION_DELETED :
2001-09-28 22:41:36 +02:00
$value = 'Deleted' ;
2002-01-16 07:36:51 +01:00
$data [ 'incversion' ] = False ;
2001-08-11 11:01:47 +02:00
break ;
default :
2002-01-16 07:36:51 +01:00
$value = $data [ 'operation' ];
2001-08-11 11:01:47 +02:00
break ;
}
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*
Let ' s increment the version for the file itself . We keep the current
version when making the journal entry , because that was the version that
was operated on . The maximum numbers for each part in the version string :
none . 99.9 . 9
*/
2002-01-16 07:36:51 +01:00
if ( $attribute == 'version' && $data [ 'incversion' ])
2001-08-11 11:01:47 +02:00
{
$version_parts = split ( " \ . " , $value );
$newnumofparts = $numofparts = count ( $version_parts );
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $version_parts [ 3 ] >= 9 )
{
$version_parts [ 3 ] = 0 ;
$version_parts [ 2 ] ++ ;
$version_parts_3_update = 1 ;
}
elseif ( isset ( $version_parts [ 3 ]))
{
$version_parts [ 3 ] ++ ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $version_parts [ 2 ] >= 9 && $version_parts [ 3 ] == 0 && $version_parts_3_update )
{
$version_parts [ 2 ] = 0 ;
$version_parts [ 1 ] ++ ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $version_parts [ 1 ] > 99 )
{
$version_parts [ 1 ] = 0 ;
$version_parts [ 0 ] ++ ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
for ( $i = 0 ; $i < $newnumofparts ; $i ++ )
{
if ( ! isset ( $version_parts [ $i ]))
{
break ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $i )
{
2001-09-28 22:41:36 +02:00
$newversion .= '.' ;
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
$newversion .= $version_parts [ $i ];
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$this -> set_attributes ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'attributes' => array (
'version' => $newversion
)
)
);
2001-08-11 11:01:47 +02:00
}
2001-08-24 09:44:43 +02:00
if ( isset ( $value ))
{
if ( $i > 1 )
{
2001-09-28 22:41:36 +02:00
$sql .= ', ' ;
$sql2 .= ', ' ;
2001-08-24 09:44:43 +02:00
}
$sql .= " $attribute " ;
2003-02-17 20:34:56 +01:00
$sql2 .= " ' " . $this -> clean_string ( array ( 'string' => $value )) . " ' " ;
2001-08-24 09:44:43 +02:00
}
2001-07-11 07:57:04 +02:00
}
2001-09-28 22:41:36 +02:00
$sql .= ')' ;
$sql2 .= ')' ;
2001-08-11 11:01:47 +02:00
$sql .= $sql2 ;
2001-09-28 22:41:36 +02:00
2001-07-12 01:48:25 +02:00
/*
2001-08-11 11:01:47 +02:00
These are some special situations where we need to flush the journal entries
or move the 'journal' entries to 'journal-deleted' . Kind of hackish , but they
provide a consistent feel to the system
2001-07-12 01:48:25 +02:00
*/
2002-01-16 07:36:51 +01:00
if ( $data [ 'operation' ] == VFS_OPERATION_CREATED )
2001-08-11 11:01:47 +02:00
{
$flush_path = $p -> fake_full_path ;
$deleteall = True ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $data [ 'operation' ] == VFS_OPERATION_COPIED || $data [ 'operation' ] == VFS_OPERATION_MOVED )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
$flush_path = $data [ 'state_two' ];
2001-08-11 11:01:47 +02:00
$deleteall = False ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $flush_path )
{
2002-01-16 07:36:51 +01:00
$flush_path_parts = $this -> path_parts ( array (
'string' => $flush_path ,
'relatives' => array ( RELATIVE_NONE )
)
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$this -> flush_journal ( array (
'string' => $flush_path_parts -> fake_full_path ,
'relatives' => array ( $flush_path_parts -> mask ),
'deleteall' => $deleteall
)
);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $data [ 'operation' ] == VFS_OPERATION_COPIED )
2001-08-11 11:01:47 +02:00
{
/*
We copy it going the other way as well , so both files show the operation .
The code is a bad hack to prevent recursion . Ideally it would use VFS_OPERATION_COPIED
*/
2002-01-16 07:36:51 +01:00
$this -> add_journal ( array (
'string' => $data [ 'state_two' ],
'relatives' => array ( RELATIVE_NONE ),
'operation' => 'Copied ' . $data [ 'state_one' ] . ' to ' . $data [ 'state_two' ],
'state_one' => NULL ,
'state_two' => NULL ,
'incversion' => False
)
);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $data [ 'operation' ] == VFS_OPERATION_MOVED )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
$state_one_path_parts = $this -> path_parts ( array (
'string' => $data [ 'state_one' ],
'relatives' => array ( RELATIVE_NONE )
)
);
2001-09-28 22:41:36 +02:00
2004-02-08 23:30:14 +01:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " UPDATE phpgw_vfs SET mime_type='journal-deleted' WHERE directory=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $state_one_path_parts -> fake_leading_dirs_clean ) . " ' AND name=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $state_one_path_parts -> fake_name_clean ) . " ' AND mime_type='journal' " );
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*
We create the file in addition to logging the MOVED operation . This is an
advantage because we can now search for 'Create' to see when a file was created
*/
2002-01-16 07:36:51 +01:00
$this -> add_journal ( array (
'string' => $data [ 'state_two' ],
'relatives' => array ( RELATIVE_NONE ),
'operation' => VFS_OPERATION_CREATED
)
);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* This is the SQL query we made for THIS request, remember that one? */
2001-09-28 22:41:36 +02:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( $sql , __LINE__ , __FILE__ );
2001-07-12 01:48:25 +02:00
/*
2001-08-11 11:01:47 +02:00
If we were to add an option of whether to keep journal entries for deleted files
or not , it would go in the if here
2001-07-12 01:48:25 +02:00
*/
2002-01-16 07:36:51 +01:00
if ( $data [ 'operation' ] == VFS_OPERATION_DELETED )
2001-08-11 11:01:47 +02:00
{
2004-02-08 23:30:14 +01:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " UPDATE phpgw_vfs SET mime_type='journal-deleted' WHERE directory=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_leading_dirs_clean ) . " ' AND name=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_name_clean ) . " ' AND mime_type='journal' " );
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
return True ;
2001-07-12 01:48:25 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function flush_journal
@ abstract Flush journal entries for $string . Used before adding $string
@ discussion flush_journal () is an internal function and should be called from add_journal () only
2002-01-16 07:36:51 +01:00
@ param string File / directory to flush journal entries of
@ param relatives Realtivity array
@ param deleteall Delete all types of journal entries , including the active Create entry .
2001-08-11 11:01:47 +02:00
Normally you only want to delete the Create entry when replacing the file
Note that this option does not effect $deleteonly
2002-01-16 07:36:51 +01:00
@ param deletedonly Only flush 'journal-deleted' entries ( created when $string was deleted )
2001-08-11 11:01:47 +02:00
@ result Boolean True / False
2001-07-31 08:37:55 +02:00
*/
2002-01-16 07:36:51 +01:00
function flush_journal ( $data )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT ),
'deleteall' => False ,
'deletedonly' => False
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
2001-09-28 22:41:36 +02:00
2004-02-08 23:30:14 +01:00
$sql = " DELETE FROM phpgw_vfs WHERE directory=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_leading_dirs_clean ) . " ' AND name=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_name_clean ) . " ' " ;
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $data [ 'deleteall' ])
2001-08-11 11:01:47 +02:00
{
$sql .= " AND (mime_type != 'journal' AND comment != 'Created') " ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
$sql .= " AND (mime_type='journal-deleted' " ;
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $data [ 'deletedonly' ])
2001-08-11 11:01:47 +02:00
{
$sql .= " OR mime_type='journal' " ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
$sql .= " ) " ;
2001-09-28 22:41:36 +02:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( $sql , __LINE__ , __FILE__ );
2001-08-11 11:01:47 +02:00
if ( $query )
2001-05-25 05:34:24 +02:00
{
2001-08-11 11:01:47 +02:00
return True ;
2001-05-25 05:34:24 +02:00
}
else
{
2001-08-11 11:01:47 +02:00
return False ;
2001-05-25 05:34:24 +02:00
}
}
2001-09-28 22:41:36 +02:00
2003-02-17 20:34:56 +01:00
/*
* See vfs_shared
*/
2002-01-16 07:36:51 +01:00
function get_journal ( $data )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT ),
'type' => False
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
if ( ! $this -> acl_check ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask )
)))
2001-08-11 11:01:47 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2004-02-08 23:30:14 +01:00
$sql = " SELECT * FROM phpgw_vfs WHERE directory=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_leading_dirs_clean ) . " ' AND name=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_name_clean ) . " ' " ;
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $data [ 'type' ] == 1 )
2001-05-25 05:34:24 +02:00
{
2001-08-11 11:01:47 +02:00
$sql .= " AND mime_type='journal' " ;
2001-05-25 05:34:24 +02:00
}
2002-01-16 07:36:51 +01:00
elseif ( $data [ 'type' ] == 2 )
2001-07-02 21:00:31 +02:00
{
2001-08-11 11:01:47 +02:00
$sql .= " AND mime_type='journal-deleted' " ;
2001-07-02 21:00:31 +02:00
}
2001-05-25 05:34:24 +02:00
else
{
2001-08-11 11:01:47 +02:00
$sql .= " AND (mime_type='journal' OR mime_type='journal-deleted') " ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( $sql , __LINE__ , __FILE__ );
while ( $GLOBALS [ 'phpgw' ] -> db -> next_record ())
2001-08-11 11:01:47 +02:00
{
2001-09-28 22:41:36 +02:00
$rarray [] = $GLOBALS [ 'phpgw' ] -> db -> Record ;
}
2001-08-11 11:01:47 +02:00
return $rarray ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2003-02-17 20:34:56 +01:00
/*
* See vfs_shared
*/
2002-01-16 07:36:51 +01:00
function acl_check ( $data )
2001-07-02 21:00:31 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT ),
'operation' => PHPGW_ACL_READ ,
'must_exist' => False
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-08-11 11:01:47 +02:00
/* Accommodate special situations */
2002-01-16 07:36:51 +01:00
if ( $this -> override_acl || $data [ 'relatives' ][ 0 ] == RELATIVE_USER_APP )
2001-08-11 11:01:47 +02:00
{
return True ;
}
2001-09-28 22:41:36 +02:00
2002-06-24 05:18:59 +02:00
if ( ! $data [ 'owner_id' ])
2001-08-11 11:01:47 +02:00
{
2002-06-24 05:18:59 +02:00
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
2001-09-28 22:41:36 +02:00
2002-06-24 05:18:59 +02:00
/* Temporary, until we get symlink type files set up */
if ( $p -> outside )
2001-08-11 11:01:47 +02:00
{
2002-06-24 05:18:59 +02:00
return True ;
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2002-06-24 05:18:59 +02:00
/* Read access is always allowed here, but nothing else is */
if ( $data [ 'string' ] == '/' || $data [ 'string' ] == $this -> fakebase )
{
if ( $data [ 'operation' ] == PHPGW_ACL_READ )
{
return True ;
}
else
{
return False ;
}
}
2001-09-28 22:41:36 +02:00
2002-06-24 05:18:59 +02:00
/* If the file doesn't exist, we get ownership from the parent directory */
2002-01-16 07:36:51 +01:00
if ( ! $this -> file_exists ( array (
2002-06-24 05:18:59 +02:00
'string' => $p -> fake_full_path ,
2002-01-16 07:36:51 +01:00
'relatives' => array ( $p -> mask )
))
)
2001-08-11 11:01:47 +02:00
{
2002-06-24 05:18:59 +02:00
if ( $data [ 'must_exist' ])
{
return False ;
}
2001-09-28 22:41:36 +02:00
2002-06-24 05:18:59 +02:00
$data [ 'string' ] = $p -> fake_leading_dirs ;
$p2 = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $p -> mask )
)
);
if ( ! $this -> file_exists ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $p -> mask )
))
)
{
return False ;
}
2001-08-11 11:01:47 +02:00
}
else
{
2002-06-24 05:18:59 +02:00
$p2 = $p ;
2001-08-11 11:01:47 +02:00
}
2002-06-24 05:18:59 +02:00
/*
We don ' t use ls () to get owner_id as we normally would ,
because ls () calls acl_check (), which would create an infinite loop
*/
2004-02-08 23:30:14 +01:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " SELECT owner_id FROM phpgw_vfs WHERE directory=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p2 -> fake_leading_dirs_clean ) . " ' AND name=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p2 -> fake_name_clean ) . " ' " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_SELECT )), __LINE__ , __FILE__ );
2002-06-24 05:18:59 +02:00
$GLOBALS [ 'phpgw' ] -> db -> next_record ();
$owner_id = $GLOBALS [ 'phpgw' ] -> db -> Record [ 'owner_id' ];
}
else
{
$owner_id = $data [ 'owner_id' ];
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2002-06-24 06:02:14 +02:00
/* This is correct. The ACL currently doesn't handle undefined values correctly */
if ( ! $owner_id )
{
$owner_id = 0 ;
}
2002-06-24 05:18:59 +02:00
$user_id = $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'account_id' ];
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* They always have access to their own files */
2002-06-24 05:18:59 +02:00
if ( $owner_id == $user_id )
2001-08-11 11:01:47 +02:00
{
return True ;
}
2001-09-28 22:41:36 +02:00
2002-06-24 05:18:59 +02:00
/* Check if they're in the group */
$memberships = $GLOBALS [ 'phpgw' ] -> accounts -> membership ( $user_id );
2001-09-28 22:41:36 +02:00
2001-08-28 10:13:35 +02:00
if ( is_array ( $memberships ))
2001-08-11 11:01:47 +02:00
{
2003-09-21 15:54:07 +02:00
foreach ( $memberships as $group_array )
2001-08-11 11:01:47 +02:00
{
2002-06-24 05:18:59 +02:00
if ( $owner_id == $group_array [ 'account_id' ])
2001-08-28 10:13:35 +02:00
{
$group_ok = 1 ;
break ;
}
2001-08-11 11:01:47 +02:00
}
}
2001-09-28 22:41:36 +02:00
2002-06-24 05:18:59 +02:00
$acl = CreateObject ( 'phpgwapi.acl' , $owner_id );
$acl -> account_id = $owner_id ;
$acl -> read_repository ();
$rights = $acl -> get_rights ( $user_id );
/* Add privileges from the groups this user belongs to */
if ( is_array ( $memberships ))
2001-07-02 21:00:31 +02:00
{
2003-09-21 15:54:07 +02:00
foreach ( $memberships as $group_array )
2001-08-11 11:01:47 +02:00
{
2002-06-24 05:18:59 +02:00
$rights |= $acl -> get_rights ( $group_array [ 'account_id' ]);
2001-08-11 11:01:47 +02:00
}
2001-07-02 21:00:31 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $rights & $data [ 'operation' ])
2001-07-02 21:00:31 +02:00
{
2001-08-11 11:01:47 +02:00
return True ;
2001-07-02 21:00:31 +02:00
}
2001-08-11 11:01:47 +02:00
elseif ( ! $rights && $group_ok )
2001-07-02 21:00:31 +02:00
{
2002-06-24 05:18:59 +02:00
$conf = CreateObject ( 'phpgwapi.config' , 'phpgwapi' );
$conf -> read_repository ();
if ( $conf -> config_data [ 'acl_default' ] == 'grant' )
{
return True ;
}
else
{
return False ;
}
2001-07-02 21:00:31 +02:00
}
else
{
return False ;
}
}
2001-09-28 22:41:36 +02:00
2003-02-17 20:34:56 +01:00
/*
* See vfs_shared
*/
2002-01-16 07:36:51 +01:00
function read ( $data )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
if ( ! $this -> acl_check ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => PHPGW_ACL_READ
))
)
2001-08-11 11:01:47 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2002-08-26 06:20:33 +02:00
$conf = CreateObject ( 'phpgwapi.config' , 'phpgwapi' );
$conf -> read_repository ();
if ( $this -> file_actions || $p -> outside )
2001-05-25 05:34:24 +02:00
{
2002-08-26 06:20:33 +02:00
if ( $fp = fopen ( $p -> real_full_path , 'rb' ))
{
$contents = fread ( $fp , filesize ( $p -> real_full_path ));
fclose ( $fp );
}
else
{
$contents = False ;
}
2001-05-25 05:34:24 +02:00
}
else
{
2002-08-26 06:20:33 +02:00
$ls_array = $this -> ls ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
)
);
$contents = $ls_array [ 0 ][ 'content' ];
2001-05-25 05:34:24 +02:00
}
2002-01-16 07:36:51 +01:00
2001-12-20 03:38:02 +01:00
return $contents ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2003-02-17 20:34:56 +01:00
/*
* See vfs_shared
*/
2002-01-16 07:36:51 +01:00
function write ( $data )
2001-07-02 21:00:31 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT ),
'content' => ''
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $this -> file_exists ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask )
))
)
2001-08-11 11:01:47 +02:00
{
$acl_operation = PHPGW_ACL_EDIT ;
$journal_operation = VFS_OPERATION_EDITED ;
}
else
{
$acl_operation = PHPGW_ACL_ADD ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => $acl_operation
))
)
2001-08-11 11:01:47 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2003-10-04 09:37:03 +02:00
umask ( 0177 );
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*
2002-01-16 07:36:51 +01:00
If 'string' doesn ' t exist , touch () creates both the file and the database entry
If 'string' does exist , touch () sets the modification time and modified by
2001-08-11 11:01:47 +02:00
*/
2002-01-16 07:36:51 +01:00
$this -> touch ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask )
)
);
2001-09-28 22:41:36 +02:00
2002-08-26 06:20:33 +02:00
$conf = CreateObject ( 'phpgwapi.config' , 'phpgwapi' );
$conf -> read_repository ();
if ( $this -> file_actions )
2001-08-11 11:01:47 +02:00
{
2002-08-26 06:20:33 +02:00
if ( $fp = fopen ( $p -> real_full_path , 'wb' ))
{
2004-09-06 05:48:10 +02:00
fwrite ( $fp , $data [ 'content' ]);
2002-08-26 06:20:33 +02:00
fclose ( $fp );
$write_ok = 1 ;
}
}
2001-09-28 22:41:36 +02:00
2002-08-26 06:20:33 +02:00
if ( $write_ok || ! $this -> file_actions )
{
if ( $this -> file_actions )
{
$set_attributes_array = array (
'size' => filesize ( $p -> real_full_path )
);
}
else
{
$set_attributes_array = array (
'size' => strlen ( $data [ 'content' ]),
'content' => $data [ 'content' ]
);
}
$this -> set_attributes ( array
(
2002-01-16 07:36:51 +01:00
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
2002-08-26 06:20:33 +02:00
'attributes' => $set_attributes_array
2002-01-16 07:36:51 +01:00
)
);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $journal_operation )
{
2002-01-16 07:36:51 +01:00
$this -> add_journal ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => $journal_operation
)
);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
return True ;
}
else
{
return False ;
}
2001-07-02 21:00:31 +02:00
}
2001-09-28 22:41:36 +02:00
2003-02-17 20:34:56 +01:00
/*
* See vfs_shared
*/
2002-01-16 07:36:51 +01:00
function touch ( $data )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
$account_id = $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'account_id' ];
$currentapp = $GLOBALS [ 'phpgw_info' ][ 'flags' ][ 'currentapp' ];
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
2001-09-28 22:41:36 +02:00
2003-10-04 09:37:03 +02:00
umask ( 0177 );
2001-09-28 22:41:36 +02:00
2002-08-26 06:20:33 +02:00
if ( $this -> file_actions )
2001-07-13 07:12:18 +02:00
{
2002-08-26 06:20:33 +02:00
/*
PHP ' s touch function will automatically decide whether to
create the file or set the modification time
*/
$rr = @ touch ( $p -> real_full_path );
if ( $p -> outside )
{
return $rr ;
}
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* We, however, have to decide this ourselves */
2002-01-16 07:36:51 +01:00
if ( $this -> file_exists ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask )
))
)
{
if ( ! $this -> acl_check ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => PHPGW_ACL_EDIT
)))
2001-08-11 11:01:47 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$vr = $this -> set_attributes ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'attributes' => array (
'modifiedby_id' => $account_id ,
'modified' => $this -> now
)
)
);
2001-08-11 11:01:47 +02:00
}
else
{
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => PHPGW_ACL_ADD
))
)
2001-08-11 11:01:47 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2004-02-08 23:30:14 +01:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " INSERT INTO phpgw_vfs (owner_id, directory, name) VALUES ( $this->working_id , ' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_leading_dirs_clean ) . " ', ' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_name_clean ) . " ') " , __LINE__ , __FILE__ );
2002-01-16 07:36:51 +01:00
$this -> set_attributes ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'attributes' => array (
'createdby_id' => $account_id ,
'created' => $this -> now ,
'size' => 0 ,
'deleteable' => 'Y' ,
'app' => $currentapp
)
)
);
$this -> correct_attributes ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask )
2001-09-28 22:41:36 +02:00
)
);
2001-08-11 11:01:47 +02:00
2002-01-16 07:36:51 +01:00
$this -> add_journal ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => VFS_OPERATION_CREATED
)
);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $rr || $vr || $query )
{
return True ;
}
else
{
return False ;
2001-07-13 07:12:18 +02:00
}
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2003-02-17 20:34:56 +01:00
/*
* See vfs_shared
2004-02-08 23:30:14 +01:00
* If $data [ 'symlink' ] the file is symlinked instead of copied
2003-02-17 20:34:56 +01:00
*/
2002-01-16 07:36:51 +01:00
function cp ( $data )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT , RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-09-28 22:41:36 +02:00
$account_id = $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'account_id' ];
2002-01-16 07:36:51 +01:00
$f = $this -> path_parts ( array (
'string' => $data [ 'from' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
$t = $this -> path_parts ( array (
'string' => $data [ 'to' ],
'relatives' => array ( $data [ 'relatives' ][ 1 ])
)
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array (
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask ),
'operation' => PHPGW_ACL_READ
))
)
2001-07-02 21:00:31 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2004-02-08 23:30:14 +01:00
if ( $exists = $this -> file_exists ( array (
2002-01-16 07:36:51 +01:00
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask )
))
)
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask ),
'operation' => PHPGW_ACL_EDIT
))
)
2001-08-11 11:01:47 +02:00
{
return False ;
}
}
else
{
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask ),
'operation' => PHPGW_ACL_ADD
))
)
2001-08-11 11:01:47 +02:00
{
return False ;
}
}
2001-09-28 22:41:36 +02:00
2003-10-04 09:37:03 +02:00
umask ( 0177 );
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $this -> file_type ( array (
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask )
)) != 'Directory'
)
2001-08-11 11:01:47 +02:00
{
2002-08-26 06:20:33 +02:00
if ( $this -> file_actions )
2001-08-11 11:01:47 +02:00
{
2004-02-08 23:30:14 +01:00
if ( @ $data [ 'symlink' ])
{
if ( $exists )
{
@ unlink ( $t -> real_full_path );
}
if ( ! symlink ( $f -> real_full_path , $t -> real_full_path ))
{
return False ;
}
}
elseif ( ! copy ( $f -> real_full_path , $t -> real_full_path ))
2002-08-26 06:20:33 +02:00
{
return False ;
}
$size = filesize ( $t -> real_full_path );
}
else
{
$content = $this -> read ( array (
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask )
)
);
$size = strlen ( $content );
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $t -> outside )
{
return True ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$ls_array = $this -> ls ( array (
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask ),
'checksubdirs' => False ,
'mime_type' => False ,
'nofiles' => True
)
);
2001-08-11 11:01:47 +02:00
$record = $ls_array [ 0 ];
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $this -> file_exists ( array (
'string' => $data [ 'to' ],
'relatives' => array ( $data [ 'relatives' ][ 1 ])
))
)
2001-08-11 11:01:47 +02:00
{
2004-02-08 23:30:14 +01:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " UPDATE phpgw_vfs SET owner_id=' $this->working_id ', directory=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $t -> fake_leading_dirs_clean ) . " ', name=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $t -> fake_name_clean ) . " ' WHERE owner_id=' $this->working_id ' AND directory=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $t -> fake_leading_dirs_clean ) . " ' AND name=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $t -> fake_name_clean ) . " ' " . $this -> extra_sql ( VFS_SQL_UPDATE ), __LINE__ , __FILE__ );
2001-09-28 22:41:36 +02:00
2002-08-26 06:20:33 +02:00
$set_attributes_array = array (
'createdby_id' => $account_id ,
'created' => $this -> now ,
'size' => $size ,
'mime_type' => $record [ 'mime_type' ],
'deleteable' => $record [ 'deleteable' ],
'comment' => $record [ 'comment' ],
'app' => $record [ 'app' ]
);
if ( ! $this -> file_actions )
{
$set_attributes_array [ 'content' ] = $content ;
}
2002-01-16 07:36:51 +01:00
$this -> set_attributes ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask ),
2002-08-26 06:20:33 +02:00
'attributes' => $set_attributes_array
2002-01-16 07:36:51 +01:00
)
);
$this -> add_journal ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask ),
'operation' => VFS_OPERATION_EDITED
2001-09-28 22:41:36 +02:00
)
);
2001-08-11 11:01:47 +02:00
}
else
{
2002-01-16 07:36:51 +01:00
$this -> touch ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask )
)
);
2002-08-26 06:20:33 +02:00
$set_attributes_array = array (
'createdby_id' => $account_id ,
'created' => $this -> now ,
'size' => $size ,
'mime_type' => $record [ 'mime_type' ],
'deleteable' => $record [ 'deleteable' ],
'comment' => $record [ 'comment' ],
'app' => $record [ 'app' ]
);
if ( ! $this -> file_actions )
{
$set_attributes_array [ 'content' ] = $content ;
}
2002-01-16 07:36:51 +01:00
$this -> set_attributes ( array (
2002-08-26 06:20:33 +02:00
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask ),
'attributes' => $set_attributes_array
2001-09-28 22:41:36 +02:00
)
);
2001-08-11 11:01:47 +02:00
}
2002-01-16 07:36:51 +01:00
$this -> correct_attributes ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask )
)
);
2001-08-11 11:01:47 +02:00
}
else /* It's a directory */
{
/* First, make the initial directory */
2002-01-16 07:36:51 +01:00
$this -> mkdir ( array (
'string' => $data [ 'to' ],
'relatives' => array ( $data [ 'relatives' ][ 1 ])
)
);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* Next, we create all the directories below the initial directory */
2003-09-21 15:54:07 +02:00
foreach ( $this -> ls ( array (
2002-01-16 07:36:51 +01:00
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask ),
'checksubdirs' => True ,
'mime_type' => 'Directory'
2003-09-21 15:54:07 +02:00
)) as $entry )
2001-08-11 11:01:47 +02:00
{
2001-09-28 22:41:36 +02:00
$newdir = ereg_replace ( " ^ $f->fake_full_path " , " $t->fake_full_path " , $entry [ 'directory' ]);
2002-01-16 07:36:51 +01:00
$this -> mkdir ( array (
'string' => $newdir . '/' . $entry [ 'name' ],
'relatives' => array ( $t -> mask )
)
);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* Lastly, we copy the files over */
2003-09-21 15:54:07 +02:00
foreach ( $this -> ls ( array (
2002-01-16 07:36:51 +01:00
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask )
2003-09-21 15:54:07 +02:00
)) as $entry )
2001-08-11 11:01:47 +02:00
{
2001-09-28 22:41:36 +02:00
if ( $entry [ 'mime_type' ] == 'Directory' )
2001-08-11 11:01:47 +02:00
{
continue ;
}
2001-09-28 22:41:36 +02:00
$newdir = ereg_replace ( " ^ $f->fake_full_path " , " $t->fake_full_path " , $entry [ 'directory' ]);
2002-01-16 07:36:51 +01:00
$this -> cp ( array (
'from' => " $entry[directory] / $entry[name] " ,
'to' => " $newdir / $entry[name] " ,
'relatives' => array ( $f -> mask , $t -> mask )
)
);
2001-08-11 11:01:47 +02:00
}
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( ! $f -> outside )
2001-07-02 21:00:31 +02:00
{
2002-01-16 07:36:51 +01:00
$this -> add_journal ( array (
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask ),
'operation' => VFS_OPERATION_COPIED ,
'state_one' => NULL ,
'state_two' => $t -> fake_full_path
)
);
2001-07-02 21:00:31 +02:00
}
2001-09-28 22:41:36 +02:00
2001-05-25 05:34:24 +02:00
return True ;
}
2001-09-28 22:41:36 +02:00
2003-02-17 20:34:56 +01:00
/*
* See vfs_shared
*/
2002-01-16 07:36:51 +01:00
function mv ( $data )
2001-07-02 21:00:31 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT , RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-09-28 22:41:36 +02:00
$account_id = $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'account_id' ];
2002-01-16 07:36:51 +01:00
$f = $this -> path_parts ( array (
'string' => $data [ 'from' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
$t = $this -> path_parts ( array (
'string' => $data [ 'to' ],
'relatives' => array ( $data [ 'relatives' ][ 1 ])
)
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array (
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask ),
'operation' => PHPGW_ACL_READ
))
|| ! $this -> acl_check ( array (
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask ),
'operation' => PHPGW_ACL_DELETE
))
)
2001-07-02 21:00:31 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask ),
'operation' => PHPGW_ACL_ADD
))
)
2001-07-02 21:00:31 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $this -> file_exists ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask )
))
)
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask ),
'operation' => PHPGW_ACL_EDIT
))
)
2001-08-11 11:01:47 +02:00
{
return False ;
}
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2003-10-04 09:37:03 +02:00
umask ( 0177 );
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* We can't move directories into themselves */
2002-01-16 07:36:51 +01:00
if (( $this -> file_type ( array (
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask )
) == 'Directory' ))
&& ereg ( " ^ $f->fake_full_path " , $t -> fake_full_path )
)
2001-06-18 23:18:22 +02:00
{
2001-09-28 22:41:36 +02:00
if (( $t -> fake_full_path == $f -> fake_full_path ) || substr ( $t -> fake_full_path , strlen ( $f -> fake_full_path ), 1 ) == '/' )
2001-08-11 11:01:47 +02:00
{
return False ;
}
2001-06-18 23:18:22 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $this -> file_exists ( array (
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask )
))
)
2001-06-18 23:18:22 +02:00
{
2001-08-11 11:01:47 +02:00
/* We get the listing now, because it will change after we update the database */
2002-01-16 07:36:51 +01:00
$ls = $this -> ls ( array (
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask )
)
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $this -> file_exists ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask )
))
)
2001-08-24 09:44:43 +02:00
{
2002-01-16 07:36:51 +01:00
$this -> rm ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask )
)
);
2001-08-24 09:44:43 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*
We add the journal entry now , before we delete . This way the mime_type
field will be updated to 'journal-deleted' when the file is actually deleted
*/
if ( ! $f -> outside )
{
2002-01-16 07:36:51 +01:00
$this -> add_journal ( array (
'string' => $f -> fake_full_path ,
'relatives' => array ( $f -> mask ),
'operation' => VFS_OPERATION_MOVED ,
'state_one' => $f -> fake_full_path ,
'state_two' => $t -> fake_full_path
)
);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*
If the from file is outside , it won ' t have a database entry ,
so we have to touch it and find the size
*/
if ( $f -> outside )
{
$size = filesize ( $f -> real_full_path );
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$this -> touch ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask )
)
);
2004-02-08 23:30:14 +01:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " UPDATE phpgw_vfs SET size= $size WHERE directory=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $t -> fake_leading_dirs_clean ) . " ' AND name=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $t -> fake_name_clean ) . " ' " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_UPDATE )), __LINE__ , __FILE__ );
2001-08-11 11:01:47 +02:00
}
elseif ( ! $t -> outside )
{
2004-02-08 23:30:14 +01:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " UPDATE phpgw_vfs SET name=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $t -> fake_name_clean ) . " ', directory=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $t -> fake_leading_dirs_clean ) . " ' WHERE directory=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $f -> fake_leading_dirs_clean ) . " ' AND name=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $f -> fake_name_clean ) . " ' " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_UPDATE )), __LINE__ , __FILE__ );
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$this -> set_attributes ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask ),
'attributes' => array (
'modifiedby_id' => $account_id ,
'modified' => $this -> now
)
)
);
$this -> correct_attributes ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask )
2001-09-28 22:41:36 +02:00
)
);
2002-08-26 06:20:33 +02:00
if ( $this -> file_actions )
{
$rr = rename ( $f -> real_full_path , $t -> real_full_path );
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*
This removes the original entry from the database
The actual file is already deleted because of the rename () above
*/
if ( $t -> outside )
{
2002-01-16 07:36:51 +01:00
$this -> rm ( array (
'string' => $f -> fake_full_path ,
'relatives' => $f -> mask
)
);
2001-08-11 11:01:47 +02:00
}
2001-06-18 23:18:22 +02:00
}
else
{
2001-08-11 11:01:47 +02:00
return False ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $this -> file_type ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask )
)) == 'Directory'
)
2001-05-25 05:34:24 +02:00
{
2001-08-11 11:01:47 +02:00
/* We got $ls from above, before we renamed the directory */
2003-09-21 15:54:07 +02:00
foreach ( $ls as $entry )
2001-05-25 05:34:24 +02:00
{
2001-09-28 22:41:36 +02:00
$newdir = ereg_replace ( " ^ $f->fake_full_path " , $t -> fake_full_path , $entry [ 'directory' ]);
2003-02-17 20:34:56 +01:00
$newdir_clean = $this -> clean_string ( array ( 'string' => $newdir ));
2001-09-28 22:41:36 +02:00
2004-02-08 23:30:14 +01:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " UPDATE phpgw_vfs SET directory=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $newdir_clean ) . " ' WHERE file_id=' $entry[file_id] ' " .
$this -> extra_sql ( array ( 'query_type' => VFS_SQL_UPDATE )), __LINE__ , __FILE__ );
2002-01-16 07:36:51 +01:00
$this -> correct_attributes ( array (
'string' => " $newdir / $entry[name] " ,
'relatives' => array ( $t -> mask )
)
);
2001-05-25 05:34:24 +02:00
}
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$this -> add_journal ( array (
'string' => $t -> fake_full_path ,
'relatives' => array ( $t -> mask ),
'operation' => VFS_OPERATION_MOVED ,
'state_one' => $f -> fake_full_path ,
'state_two' => $t -> fake_full_path
)
);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
return True ;
2001-07-11 07:57:04 +02:00
}
2001-09-28 22:41:36 +02:00
2003-02-17 20:34:56 +01:00
/*
* See vfs_shared
*/
2002-01-16 07:36:51 +01:00
function rm ( $data )
2001-07-02 21:00:31 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT )
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
if ( ! $this -> acl_check ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => PHPGW_ACL_DELETE
))
)
2001-07-02 21:00:31 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> file_exists ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
))
)
2001-08-11 11:01:47 +02:00
{
2002-08-26 06:20:33 +02:00
if ( $this -> file_actions )
{
$rr = unlink ( $p -> real_full_path );
}
else
{
$rr = True ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $rr )
{
return True ;
}
else
{
return False ;
}
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $this -> file_type ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)) != 'Directory'
)
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
$this -> add_journal ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => VFS_OPERATION_DELETED
)
);
2001-09-28 22:41:36 +02:00
2004-02-08 23:30:14 +01:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " DELETE FROM phpgw_vfs WHERE directory=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_leading_dirs_clean ) . " ' AND name=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_name_clean ) . " ' " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_DELETE )), __LINE__ , __FILE__ );
2002-08-26 06:20:33 +02:00
if ( $this -> file_actions )
{
$rr = unlink ( $p -> real_full_path );
}
else
{
$rr = True ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $query || $rr )
{
return True ;
}
else
{
return False ;
}
}
else
{
2002-01-16 07:36:51 +01:00
$ls = $this -> ls ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask )
)
);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* First, we cycle through the entries and delete the files */
2003-09-21 15:54:07 +02:00
foreach ( $ls as $entry )
2001-08-11 11:01:47 +02:00
{
2001-09-28 22:41:36 +02:00
if ( $entry [ 'mime_type' ] == 'Directory' )
2001-08-11 11:01:47 +02:00
{
continue ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$this -> rm ( array (
'string' => " $entry[directory] / $entry[name] " ,
'relatives' => array ( $p -> mask )
)
);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* Now we cycle through again and delete the directories */
2003-09-21 15:54:07 +02:00
foreach ( $ls as $entry )
2001-08-11 11:01:47 +02:00
{
2001-09-28 22:41:36 +02:00
if ( $entry [ 'mime_type' ] != 'Directory' )
2001-08-11 11:01:47 +02:00
{
continue ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* Only the best in confusing recursion */
2002-01-16 07:36:51 +01:00
$this -> rm ( array (
'string' => " $entry[directory] / $entry[name] " ,
'relatives' => array ( $p -> mask )
)
);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* If the directory is linked, we delete the placeholder directory */
2002-01-16 07:36:51 +01:00
$ls_array = $this -> ls ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'checksubdirs' => False ,
'mime_type' => False ,
'nofiles' => True
)
);
2001-08-11 11:01:47 +02:00
$link_info = $ls_array [ 0 ];
2001-09-28 22:41:36 +02:00
if ( $link_info [ 'link_directory' ] && $link_info [ 'link_name' ])
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
$path = $this -> path_parts ( array (
'string' => $link_info [ 'directory' ] . '/' . $link_info [ 'name' ],
'relatives' => array ( $p -> mask ),
'nolinks' => True
)
);
2002-08-26 06:20:33 +02:00
if ( $this -> file_actions )
{
rmdir ( $path -> real_full_path );
}
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* Last, we delete the directory itself */
2002-01-16 07:36:51 +01:00
$this -> add_journal ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operaton' => VFS_OPERATION_DELETED
)
);
2001-09-28 22:41:36 +02:00
2004-02-08 23:30:14 +01:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " DELETE FROM phpgw_vfs WHERE directory=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_leading_dirs_clean ) . " ' AND name=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_name_clean ) . " ' " .
$this -> extra_sql ( array ( 'query_type' => VFS_SQL_DELETE )), __LINE__ , __FILE__ );
2001-09-28 22:41:36 +02:00
2002-08-26 06:20:33 +02:00
if ( $this -> file_actions )
{
rmdir ( $p -> real_full_path );
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
return True ;
}
2001-07-02 21:00:31 +02:00
}
2001-09-28 22:41:36 +02:00
2003-02-17 20:34:56 +01:00
/*
* See vfs_shared
*/
2002-01-16 07:36:51 +01:00
function mkdir ( $data )
2001-06-14 08:39:10 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-09-28 22:41:36 +02:00
$account_id = $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'account_id' ];
$currentapp = $GLOBALS [ 'phpgw_info' ][ 'flags' ][ 'currentapp' ];
2002-01-16 07:36:51 +01:00
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => PHPGW_ACL_ADD )
)
)
2001-06-14 08:39:10 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* We don't allow /'s in dir names, of course */
if ( ereg ( " / " , $p -> fake_name ))
2001-07-11 07:57:04 +02:00
{
2001-08-11 11:01:47 +02:00
return False ;
2001-07-11 07:57:04 +02:00
}
2001-09-28 22:41:36 +02:00
2003-10-04 09:37:03 +02:00
umask ( 077 );
2001-09-28 22:41:36 +02:00
2002-08-26 06:20:33 +02:00
if ( $this -> file_actions )
2001-06-18 23:18:22 +02:00
{
2003-09-21 15:54:07 +02:00
if ( !@ is_dir ( $p -> real_leading_dirs_clean )) // eg. /home or /group does not exist
{
if ( !@ mkdir ( $p -> real_leading_dirs_clean , 0770 )) // ==> create it
{
return False ;
}
}
if ( @ is_dir ( $p -> real_full_path )) // directory already exists
{
$this -> update_real ( $data , True ); // update its contents
}
elseif ( !@ mkdir ( $p -> real_full_path , 0770 ))
2002-08-26 06:20:33 +02:00
{
return False ;
}
2001-06-18 23:18:22 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> file_exists ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask )
))
)
{
2004-02-08 23:30:14 +01:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " INSERT INTO phpgw_vfs (owner_id, name, directory) VALUES ( $this->working_id , ' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_name_clean ) . " ', ' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_leading_dirs_clean ) . " ') " , __LINE__ , __FILE__ );
2002-01-16 07:36:51 +01:00
$this -> set_attributes ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'attributes' => array (
'createdby_id' => $account_id ,
'size' => 4096 ,
'mime_type' => 'Directory' ,
'created' => $this -> now ,
'deleteable' => 'Y' ,
'app' => $currentapp
)
)
);
$this -> correct_attributes ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask )
2001-09-28 22:41:36 +02:00
)
);
2002-01-16 07:36:51 +01:00
$this -> add_journal ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => VFS_OPERATION_CREATED
)
);
2001-06-18 23:18:22 +02:00
}
2001-08-11 11:01:47 +02:00
else
2001-06-18 23:18:22 +02:00
{
2001-08-11 11:01:47 +02:00
return False ;
2001-06-18 23:18:22 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
return True ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2003-02-17 20:34:56 +01:00
/*
* See vfs_shared
*/
2002-01-16 07:36:51 +01:00
function make_link ( $data )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT , RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-09-28 22:41:36 +02:00
$account_id = $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'account_id' ];
$currentapp = $GLOBALS [ 'phpgw_info' ][ 'flags' ][ 'currentapp' ];
2002-01-16 07:36:51 +01:00
$vp = $this -> path_parts ( array (
'string' => $data [ 'vdir' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
$rp = $this -> path_parts ( array (
'string' => $data [ 'rdir' ],
'relatives' => array ( $data [ 'relatives' ][ 1 ])
)
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array (
'string' => $vp -> fake_full_path ,
'relatives' => array ( $vp -> mask ),
'operation' => PHPGW_ACL_ADD
))
)
2001-05-25 05:34:24 +02:00
{
2001-08-11 11:01:47 +02:00
return False ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if (( ! $this -> file_exists ( array (
'string' => $rp -> real_full_path ,
'relatives' => array ( $rp -> mask )
)))
&& ! mkdir ( $rp -> real_full_path , 0770 ))
2001-06-16 05:54:10 +02:00
{
2001-08-11 11:01:47 +02:00
return False ;
2001-06-16 05:54:10 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> mkdir ( array (
'string' => $vp -> fake_full_path ,
'relatives' => array ( $vp -> mask )
))
)
2001-06-16 05:54:10 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$size = $this -> get_size ( array (
'string' => $rp -> real_full_path ,
'relatives' => array ( $rp -> mask )
)
);
$this -> set_attributes ( array (
'string' => $vp -> fake_full_path ,
'relatives' => array ( $vp -> mask ),
'attributes' => array (
'link_directory' => $rp -> real_leading_dirs ,
'link_name' => $rp -> real_name ,
'size' => $size
)
)
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$this -> correct_attributes ( array (
'string' => $vp -> fake_full_path ,
'relatives' => array ( $vp -> mask )
2001-09-28 22:41:36 +02:00
)
);
2001-08-11 11:01:47 +02:00
return True ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2003-02-17 20:34:56 +01:00
/*
* See vfs_shared
*/
2002-01-16 07:36:51 +01:00
function set_attributes ( $data )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT ),
'attributes' => array ()
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*
This is kind of trivial , given that set_attributes () can change owner_id ,
size , etc .
*/
2002-01-16 07:36:51 +01:00
if ( ! $this -> acl_check ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => PHPGW_ACL_EDIT
))
)
2001-05-25 05:34:24 +02:00
{
2001-08-11 11:01:47 +02:00
return False ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> file_exists ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
))
)
{
return False ;
}
2001-12-20 03:38:02 +01:00
2001-08-11 11:01:47 +02:00
/*
2001-08-24 09:44:43 +02:00
All this voodoo just decides which attributes to update
2002-01-16 07:36:51 +01:00
depending on if the attribute was supplied in the 'attributes' array
2001-08-11 11:01:47 +02:00
*/
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$ls_array = $this -> ls ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'checksubdirs' => False ,
'nofiles' => True
)
);
2001-08-11 11:01:47 +02:00
$record = $ls_array [ 0 ];
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$sql = 'UPDATE phpgw_vfs SET ' ;
$change_attributes = 0 ;
2003-09-21 15:54:07 +02:00
foreach ( $this -> attributes as $attribute )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( isset ( $data [ 'attributes' ][ $attribute ]))
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
/*
Indicate that the EDITED_COMMENT operation needs to be journaled ,
but only if the comment changed
*/
if ( $attribute == 'comment' && $data [ 'attributes' ][ $attribute ] != $record [ $attribute ])
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
$edited_comment = 1 ;
2001-08-11 11:01:47 +02:00
}
2002-01-16 07:36:51 +01:00
if ( $change_attributes > 0 )
2001-08-24 09:44:43 +02:00
{
2002-01-16 07:36:51 +01:00
$sql .= ', ' ;
2001-08-24 09:44:43 +02:00
}
2004-07-24 22:29:15 +02:00
// RalfBecker 2004/07/24:
// this is only a hack to fix bug [ 991222 ] Error uploading file
// the whole class need to be reworked with the new db-functions
if ( ! isset ( $this -> column_defs ))
{
$table_defs = $GLOBALS [ 'phpgw' ] -> db -> get_table_definitions ( 'phpgwapi' , 'phpgw_vfs' );
$this -> column_defs = $table_defs [ 'fd' ];
}
$sql .= $attribute . '=' . $GLOBALS [ 'phpgw' ] -> db -> quote ( $data [ 'attributes' ][ $attribute ], $this -> column_defs [ $attribute ][ 'type' ]);
2002-01-16 07:36:51 +01:00
$change_attributes ++ ;
2001-12-10 05:04:56 +01:00
}
}
2002-01-16 07:36:51 +01:00
2003-09-21 15:54:07 +02:00
if ( ! $change_attributes )
{
return True ; // nothing to do
}
2004-07-24 22:29:15 +02:00
$sql .= ' WHERE file_id=' . ( int ) $record [ 'file_id' ];
2002-01-16 07:36:51 +01:00
$sql .= $this -> extra_sql ( array ( 'query_type' => VFS_SQL_UPDATE ));
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( $sql , __LINE__ , __FILE__ );
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $query )
2001-07-09 07:09:27 +02:00
{
2002-01-16 07:36:51 +01:00
if ( $edited_comment )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
$this -> add_journal ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => VFS_OPERATION_EDITED_COMMENT
)
);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
return True ;
}
else
{
return False ;
2001-07-09 07:09:27 +02:00
}
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function correct_attributes
2002-01-16 07:36:51 +01:00
@ abstract Set the correct attributes for 'string' ( e . g . owner )
@ param string File / directory to correct attributes of
@ param relatives Relativity array
2001-08-11 11:01:47 +02:00
@ result Boolean True / False
2001-05-25 05:34:24 +02:00
*/
2002-01-16 07:36:51 +01:00
function correct_attributes ( $data )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
2001-09-28 22:41:36 +02:00
if ( $p -> fake_leading_dirs != $this -> fakebase && $p -> fake_leading_dirs != '/' )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
$ls_array = $this -> ls ( array (
'string' => $p -> fake_leading_dirs ,
'relatives' => array ( $p -> mask ),
'checksubdirs' => False ,
'nofiles' => True
)
);
$set_attributes_array = Array (
2002-01-07 11:50:42 +01:00
'owner_id' => $ls_array [ 0 ][ 'owner_id' ]
);
2001-08-11 11:01:47 +02:00
}
elseif ( preg_match ( " +^ $this->fakebase\ /(.*) $ +U " , $p -> fake_full_path , $matches ))
{
2002-01-16 07:36:51 +01:00
$set_attributes_array = Array (
2002-01-07 11:50:42 +01:00
'owner_id' => $GLOBALS [ 'phpgw' ] -> accounts -> name2id ( $matches [ 1 ])
);
2001-05-25 05:34:24 +02:00
}
else
{
2002-01-16 07:36:51 +01:00
$set_attributes_array = Array (
2002-01-07 11:50:42 +01:00
'owner_id' => 0
);
2001-05-25 05:34:24 +02:00
}
2001-12-15 05:24:37 +01:00
2002-01-16 07:36:51 +01:00
$this -> set_attributes ( array (
'string' => $p -> fake_full_name ,
'relatives' => array ( $p -> mask ),
'attributes' => $set_attributes_array
)
);
2001-12-15 05:24:37 +01:00
2002-01-16 07:36:51 +01:00
return True ;
2001-12-15 05:24:37 +01:00
}
2003-02-17 20:34:56 +01:00
/*
* See vfs_shared
*/
2002-01-16 07:36:51 +01:00
function file_type ( $data )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
if ( ! $this -> acl_check ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => PHPGW_ACL_READ ,
'must_exist' => True
))
)
2001-07-11 07:57:04 +02:00
{
2001-08-11 11:01:47 +02:00
return False ;
2001-07-11 07:57:04 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $p -> outside )
2001-07-13 07:12:18 +02:00
{
2001-08-11 11:01:47 +02:00
if ( is_dir ( $p -> real_full_path ))
{
2001-09-28 22:41:36 +02:00
return ( 'Directory' );
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*
We don ' t return an empty string here , because it may still match with a database query
because of linked directories
*/
2001-07-13 07:12:18 +02:00
}
2001-09-28 22:41:36 +02:00
2001-07-13 07:12:18 +02:00
/*
2001-08-11 11:01:47 +02:00
We don ' t use ls () because it calls file_type () to determine if it has been
passed a directory
2001-07-13 07:12:18 +02:00
*/
2001-12-20 03:38:02 +01:00
$db2 = $GLOBALS [ 'phpgw' ] -> db ;
2004-02-08 23:30:14 +01:00
$db2 -> query ( " SELECT mime_type FROM phpgw_vfs WHERE directory=' " .
$db2 -> db_addslashes ( $p -> fake_leading_dirs_clean ) . " ' AND name=' " .
$db2 -> db_addslashes ( $p -> fake_name_clean ) . " ' " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_SELECT )), __LINE__ , __FILE__ );
2001-12-20 03:38:02 +01:00
$db2 -> next_record ();
$mime_type = $db2 -> Record [ 'mime_type' ];
2001-12-15 05:24:37 +01:00
if ( ! $mime_type )
{
2002-01-16 07:36:51 +01:00
$mime_type = $this -> get_ext_mime_type ( array ( 'string' => $data [ 'string' ]));
2001-12-15 05:24:37 +01:00
{
2004-02-08 23:30:14 +01:00
$db2 -> query ( " UPDATE phpgw_vfs SET mime_type=' $mime_type ' WHERE directory=' " .
$db2 -> db_addslashes ( $p -> fake_leading_dirs_clean ) . " ' AND name=' " .
$db2 -> db_addslashes ( $p -> fake_name_clean ) . " ' " .
$this -> extra_sql ( array ( 'query_type' => VFS_SQL_SELECT )), __LINE__ , __FILE__ );
2001-12-15 05:24:37 +01:00
}
}
2002-01-16 07:36:51 +01:00
2001-12-15 05:24:37 +01:00
return $mime_type ;
2001-07-13 07:12:18 +02:00
}
2001-09-28 22:41:36 +02:00
2003-02-17 20:34:56 +01:00
/*
* See vfs_shared
*/
2002-01-16 07:36:51 +01:00
function file_exists ( $data )
2001-07-09 07:09:27 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( $p -> outside )
{
2002-01-16 07:36:51 +01:00
$rr = file_exists ( $p -> real_full_path );
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
return $rr ;
2001-12-15 05:24:37 +01:00
}
2001-09-28 22:41:36 +02:00
2001-12-20 03:38:02 +01:00
$db2 = $GLOBALS [ 'phpgw' ] -> db ;
2004-06-16 00:31:19 +02:00
$db2 -> query ( " SELECT name FROM phpgw_vfs WHERE directory=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_leading_dirs_clean ) . " ' AND name=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_name_clean ) . " ' " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_SELECT )), __LINE__ , __FILE__ );
2001-12-20 03:38:02 +01:00
2002-01-16 07:36:51 +01:00
if ( $db2 -> next_record ())
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
return True ;
2001-08-11 11:01:47 +02:00
}
else
{
2002-01-16 07:36:51 +01:00
return False ;
2001-08-11 11:01:47 +02:00
}
2001-07-09 07:09:27 +02:00
}
2001-09-28 22:41:36 +02:00
2003-02-17 20:34:56 +01:00
/*
* See vfs_shared
*/
2002-01-16 07:36:51 +01:00
function get_size ( $data )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT ),
'checksubdirs' => True
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
if ( ! $this -> acl_check ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => PHPGW_ACL_READ ,
'must_exist' => True
))
)
2001-08-11 11:01:47 +02:00
{
return False ;
}
2001-09-28 22:41:36 +02:00
2001-07-02 22:38:49 +02:00
/*
2001-08-11 11:01:47 +02:00
WIP - this should run through all of the subfiles / directories in the directory and tally up
their sizes . Should modify ls () to be able to return a list for files outside the virtual root
2001-07-02 22:38:49 +02:00
*/
2001-08-11 11:01:47 +02:00
if ( $p -> outside )
2001-07-02 22:38:49 +02:00
{
2002-01-16 07:36:51 +01:00
$size = filesize ( $p -> real_full_path );
return $size ;
2001-07-02 22:38:49 +02:00
}
2001-09-28 22:41:36 +02:00
2003-09-21 15:54:07 +02:00
foreach ( $this -> ls ( array (
2002-01-16 07:36:51 +01:00
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'checksubdirs' => $data [ 'checksubdirs' ],
'nofiles' => ! $data [ 'checksubdirs' ]
2003-09-21 15:54:07 +02:00
)) as $file_array )
2001-08-11 11:01:47 +02:00
{
/*
Make sure the file is in the directory we want , and not
some deeper nested directory with a similar name
*/
2002-01-16 07:36:51 +01:00
/*
if ( @! ereg ( '^' . $file_array [ 'directory' ], $p -> fake_full_path ))
2001-08-11 11:01:47 +02:00
{
continue ;
}
2002-01-16 07:36:51 +01:00
*/
2001-09-28 22:41:36 +02:00
$size += $file_array [ 'size' ];
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $data [ 'checksubdirs' ])
2001-08-11 11:01:47 +02:00
{
2004-02-08 23:30:14 +01:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( " SELECT size FROM phpgw_vfs WHERE directory=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_leading_dirs_clean ) . " ' AND name=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_name_clean ) . " ' " .
$this -> extra_sql ( array ( 'query_text' => VFS_SQL_SELECT )));
2001-09-28 22:41:36 +02:00
$GLOBALS [ 'phpgw' ] -> db -> next_record ();
2002-01-16 07:36:51 +01:00
$size += $GLOBALS [ 'phpgw' ] -> db -> Record [ 0 ];
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
return $size ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/*!
@ function checkperms
@ abstract Check if $this -> working_id has write access to create files in $dir
@ discussion Simple call to acl_check
2002-01-16 07:36:51 +01:00
@ param string Directory to check access of
@ param relatives Relativity array
2001-08-11 11:01:47 +02:00
@ result Boolean True / False
*/
2002-01-16 07:36:51 +01:00
function checkperms ( $data )
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
if ( ! $this -> acl_check ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask ),
'operation' => PHPGW_ACL_ADD
))
)
2001-07-10 23:35:23 +02:00
{
2001-08-11 11:01:47 +02:00
return False ;
2001-07-10 23:35:23 +02:00
}
2001-08-11 11:01:47 +02:00
else
2001-07-10 23:35:23 +02:00
{
2001-08-11 11:01:47 +02:00
return True ;
2001-07-10 23:35:23 +02:00
}
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2003-02-17 20:34:56 +01:00
/*
* See vfs_shared
2004-02-08 23:30:14 +01:00
* If $data [ 'readlink' ] then a readlink is tryed on the real file
* If $data [ 'file_id' ] then the file_id is used instead of a path
2003-02-17 20:34:56 +01:00
*/
2002-01-16 07:36:51 +01:00
function ls ( $data )
2001-07-13 07:12:18 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT ),
'checksubdirs' => True ,
'mime_type' => False ,
'nofiles' => False ,
'orderby' => 'directory'
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
2001-08-11 11:01:47 +02:00
$dir = $p -> fake_full_path ;
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
/* If they pass us a file or 'nofiles' is set, return the info for $dir only */
2004-02-08 23:30:14 +01:00
if ( @ $data [ 'file_id' ]
|| ((( $type = $this -> file_type ( array (
2002-01-16 07:36:51 +01:00
'string' => $dir ,
'relatives' => array ( $p -> mask )
)) != 'Directory' ))
|| ( $data [ 'nofiles' ])) && ! $p -> outside
)
2001-07-13 07:12:18 +02:00
{
2001-08-11 11:01:47 +02:00
/* SELECT all, the, attributes */
2001-09-28 22:41:36 +02:00
$sql = 'SELECT ' ;
2003-09-21 15:54:07 +02:00
foreach ( $this -> attributes as $num => $attribute )
2001-07-13 07:12:18 +02:00
{
2001-08-11 11:01:47 +02:00
if ( $num )
2001-07-13 07:12:18 +02:00
{
2001-09-28 22:41:36 +02:00
$sql .= ', ' ;
2001-07-13 07:12:18 +02:00
}
2001-09-28 22:41:36 +02:00
2001-12-10 05:04:56 +01:00
$sql .= $attribute ;
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2004-02-08 23:30:14 +01:00
$sql .= " FROM phpgw_vfs WHERE " ;
if ( @ $data [ 'file_id' ])
{
$sql .= 'file_id=' . ( int ) $data [ 'file_id' ];
}
else
{
$sql .= " directory=' " . $GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_leading_dirs_clean ) .
" ' AND name=' " . $GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_name_clean ) . " ' " .
$this -> extra_sql ( array ( 'query_type' => VFS_SQL_SELECT ));
}
2001-09-28 22:41:36 +02:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( $sql , __LINE__ , __FILE__ );
$GLOBALS [ 'phpgw' ] -> db -> next_record ();
$record = $GLOBALS [ 'phpgw' ] -> db -> Record ;
2001-08-11 11:01:47 +02:00
/* We return an array of one array to maintain the standard */
$rarray = array ();
2003-09-21 15:54:07 +02:00
foreach ( $this -> attributes as $attribute )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
if ( $attribute == 'mime_type' && ! $record [ $attribute ])
2001-12-15 05:24:37 +01:00
{
2001-12-20 03:38:02 +01:00
$db2 = $GLOBALS [ 'phpgw' ] -> db ;
2002-01-16 07:36:51 +01:00
$record [ $attribute ] = $this -> get_ext_mime_type ( array (
'string' => $p -> fake_name_clean
)
);
2001-12-15 05:24:37 +01:00
if ( $record [ $attribute ])
{
2004-06-16 00:31:19 +02:00
$db2 -> query ( " UPDATE phpgw_vfs SET mime_type=' " . $record [ $attribute ] . " ' WHERE directory=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_leading_dirs_clean ) . " ' AND name=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_name_clean ) . " ' " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_SELECT )), __LINE__ , __FILE__ );
2001-12-15 05:24:37 +01:00
}
}
2002-01-16 07:36:51 +01:00
2001-08-11 11:01:47 +02:00
$rarray [ 0 ][ $attribute ] = $record [ $attribute ];
2001-07-13 07:12:18 +02:00
}
2004-02-08 23:30:14 +01:00
if ( $this -> file_actions && @ $data [ 'readlink' ]) // test if file is a symlink and get it's target
{
$rarray [ 0 ][ 'symlink' ] = @ readlink ( $p -> real_full_path );
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
return $rarray ;
2001-07-13 07:12:18 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
//WIP - this should recurse using the same options the virtual part of ls () does
/* If $dir is outside the virutal root, we have to check the file system manually */
if ( $p -> outside )
2001-07-13 07:12:18 +02:00
{
2002-01-16 07:36:51 +01:00
if ( $this -> file_type ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( $p -> mask )
)) == 'Directory'
&& ! $data [ 'nofiles' ]
)
2001-08-11 11:01:47 +02:00
{
$dir_handle = opendir ( $p -> real_full_path );
while ( $filename = readdir ( $dir_handle ))
{
2001-09-28 22:41:36 +02:00
if ( $filename == '.' || $filename == '..' )
2001-08-11 11:01:47 +02:00
{
continue ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$rarray [] = $this -> get_real_info ( array (
'string' => $p -> real_full_path . SEP . $filename ,
'relatives' => array ( $p -> mask )
)
);
2001-08-11 11:01:47 +02:00
}
}
else
{
2002-01-16 07:36:51 +01:00
$rarray [] = $this -> get_real_info ( array (
'string' => $p -> real_full_path ,
'relatives' => array ( $p -> mask )
)
);
2001-08-11 11:01:47 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
return $rarray ;
2001-07-13 07:12:18 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* $dir's not a file, is inside the virtual root, and they want to check subdirs */
/* SELECT all, the, attributes FROM phpgw_vfs WHERE file=$dir */
2001-09-28 22:41:36 +02:00
$sql = 'SELECT ' ;
2003-09-21 15:54:07 +02:00
foreach ( $this -> attributes as $num => $attribute )
2001-05-25 05:34:24 +02:00
{
2001-08-11 11:01:47 +02:00
if ( $num )
{
$sql .= " , " ;
}
2001-09-28 22:41:36 +02:00
2001-12-10 05:04:56 +01:00
$sql .= $attribute ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2003-02-17 20:34:56 +01:00
$dir_clean = $this -> clean_string ( array ( 'string' => $dir ));
2004-02-08 23:30:14 +01:00
$sql .= " FROM phpgw_vfs WHERE directory LIKE ' " . $GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $dir_clean ) . " %' " ;
2002-01-16 07:36:51 +01:00
$sql .= $this -> extra_sql ( array ( 'query_type' => VFS_SQL_SELECT ));
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( $data [ 'mime_type' ])
2001-05-25 05:34:24 +02:00
{
2002-01-16 07:36:51 +01:00
$sql .= " AND mime_type=' " . $data [ 'mime_type' ] . " ' " ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$sql .= ' ORDER BY ' . $data [ 'orderby' ];
2001-09-28 22:41:36 +02:00
$query = $GLOBALS [ 'phpgw' ] -> db -> query ( $sql , __LINE__ , __FILE__ );
2001-08-11 11:01:47 +02:00
$rarray = array ();
2001-09-28 22:41:36 +02:00
for ( $i = 0 ; $GLOBALS [ 'phpgw' ] -> db -> next_record (); $i ++ )
2001-07-10 23:35:23 +02:00
{
2001-09-28 22:41:36 +02:00
$record = $GLOBALS [ 'phpgw' ] -> db -> Record ;
2001-08-11 11:01:47 +02:00
/* Further checking on the directory. This makes sure /home/user/test won't match /home/user/test22 */
2002-01-16 07:36:51 +01:00
if ( @! ereg ( " ^ $dir (/| $ ) " , $record [ 'directory' ]))
2001-08-11 11:01:47 +02:00
{
continue ;
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* If they want only this directory, then $dir should end without a trailing / */
2002-01-16 07:36:51 +01:00
if ( ! $data [ 'checksubdirs' ] && ereg ( " ^ $dir / " , $record [ 'directory' ]))
2001-08-11 11:01:47 +02:00
{
continue ;
}
2001-09-28 22:41:36 +02:00
2003-09-21 15:54:07 +02:00
foreach ( $this -> attributes as $attribute )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
if ( $attribute == 'mime_type' && ! $record [ $attribute ])
2001-12-15 05:24:37 +01:00
{
2001-12-20 03:38:02 +01:00
$db2 = $GLOBALS [ 'phpgw' ] -> db ;
2002-01-16 07:36:51 +01:00
$record [ $attribute ] = $this -> get_ext_mime_type ( array (
'string' => $p -> fake_name_clean
)
);
2001-12-15 05:24:37 +01:00
if ( $record [ $attribute ])
{
2004-06-16 00:31:19 +02:00
$db2 -> query ( " UPDATE phpgw_vfs SET mime_type=' " . $record [ $attribute ] . " ' WHERE directory=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_leading_dirs_clean ) . " ' AND name=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_name_clean ) . " ' " . $this -> extra_sql ( array ( 'query_type' => VFS_SQL_SELECT )), __LINE__ , __FILE__ );
2001-12-15 05:24:37 +01:00
}
}
2002-01-16 07:36:51 +01:00
2001-08-11 11:01:47 +02:00
$rarray [ $i ][ $attribute ] = $record [ $attribute ];
}
2001-07-10 23:35:23 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
return $rarray ;
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
2003-02-17 20:34:56 +01:00
/*
* See vfs_shared
*/
2003-09-21 15:54:07 +02:00
function update_real ( $data , $recursive = False )
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( file_exists ( $p -> real_full_path ))
2001-07-13 07:12:18 +02:00
{
2001-08-11 11:01:47 +02:00
if ( is_dir ( $p -> real_full_path ))
2001-07-13 07:12:18 +02:00
{
2001-08-11 11:01:47 +02:00
$dir_handle = opendir ( $p -> real_full_path );
while ( $filename = readdir ( $dir_handle ))
2001-07-13 07:12:18 +02:00
{
2001-09-28 22:41:36 +02:00
if ( $filename == '.' || $filename == '..' )
2001-08-11 11:01:47 +02:00
{
continue ;
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$rarray [] = $this -> get_real_info ( array (
'string' => $p -> fake_full_path . '/' . $filename ,
'relatives' => array ( RELATIVE_NONE )
)
);
2001-07-13 07:12:18 +02:00
}
}
2001-08-11 11:01:47 +02:00
else
2001-07-13 07:12:18 +02:00
{
2002-01-16 07:36:51 +01:00
$rarray [] = $this -> get_real_info ( array (
'string' => $p -> fake_full_path ,
'relatives' => array ( RELATIVE_NONE )
)
);
2001-07-13 07:12:18 +02:00
}
2001-09-28 22:41:36 +02:00
2001-08-24 09:44:43 +02:00
if ( ! is_array ( $rarray ))
{
$rarray = array ();
}
2003-09-21 15:54:07 +02:00
foreach ( $rarray as $num => $file_array )
2001-07-13 07:12:18 +02:00
{
2002-01-16 07:36:51 +01:00
$p2 = $this -> path_parts ( array (
'string' => $file_array [ 'directory' ] . '/' . $file_array [ 'name' ],
'relatives' => array ( RELATIVE_NONE )
)
);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* Note the mime_type. This can be "Directory", which is how we create directories */
2002-01-07 11:50:42 +01:00
$set_attributes_array = Array (
'size' => $file_array [ 'size' ],
'mime_type' => $file_array [ 'mime_type' ]
);
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
if ( ! $this -> file_exists ( array (
'string' => $p2 -> fake_full_path ,
'relatives' => array ( RELATIVE_NONE )
))
)
2001-08-11 11:01:47 +02:00
{
2002-01-16 07:36:51 +01:00
$this -> touch ( array (
'string' => $p2 -> fake_full_path ,
'relatives' => array ( RELATIVE_NONE )
)
);
}
2003-09-21 15:54:07 +02:00
$this -> set_attributes ( array (
'string' => $p2 -> fake_full_path ,
'relatives' => array ( RELATIVE_NONE ),
'attributes' => $set_attributes_array
)
);
if ( $recursive && $file_array [ 'mime_type' ] == 'Directory' )
2002-01-16 07:36:51 +01:00
{
2003-09-21 15:54:07 +02:00
$dir_data = $data ;
$dir_data [ 'string' ] = $file_array [ 'directory' ] . '/' . $file_array [ 'name' ];
$this -> update_real ( $dir_data , $recursive );
2001-08-11 11:01:47 +02:00
}
2001-07-13 07:12:18 +02:00
}
}
}
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
/* Helper functions */
2001-09-28 22:41:36 +02:00
2002-06-24 05:18:59 +02:00
/* This fetchs all available file system information for string (not using the database) */
2002-01-16 07:36:51 +01:00
function get_real_info ( $data )
2001-07-13 07:12:18 +02:00
{
2002-01-16 07:36:51 +01:00
if ( ! is_array ( $data ))
2001-09-24 20:17:26 +02:00
{
2002-01-16 07:36:51 +01:00
$data = array ();
2001-09-24 20:17:26 +02:00
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$default_values = array
(
'relatives' => array ( RELATIVE_CURRENT )
);
$data = array_merge ( $this -> default_values ( $data , $default_values ), $data );
$p = $this -> path_parts ( array (
'string' => $data [ 'string' ],
'relatives' => array ( $data [ 'relatives' ][ 0 ])
)
);
2001-09-28 22:41:36 +02:00
2001-08-11 11:01:47 +02:00
if ( is_dir ( $p -> real_full_path ))
{
2001-09-28 22:41:36 +02:00
$mime_type = 'Directory' ;
2001-08-11 11:01:47 +02:00
}
2001-12-15 05:24:37 +01:00
else
{
2002-01-16 07:36:51 +01:00
$mime_type = $this -> get_ext_mime_type ( array (
'string' => $p -> fake_name
)
);
2001-12-15 05:24:37 +01:00
if ( $mime_type )
{
2004-02-08 23:30:14 +01:00
$GLOBALS [ 'phpgw' ] -> db -> query ( " UPDATE phpgw_vfs SET mime_type=' " . $mime_type . " ' WHERE directory=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_leading_dirs_clean ) . " ' AND name=' " .
$GLOBALS [ 'phpgw' ] -> db -> db_addslashes ( $p -> fake_name_clean ) . " ' " .
$this -> extra_sql ( array ( 'query_type' => VFS_SQL_SELECT )), __LINE__ , __FILE__ );
2001-12-15 05:24:37 +01:00
}
}
2001-09-28 22:41:36 +02:00
2002-01-16 07:36:51 +01:00
$size = filesize ( $p -> real_full_path );
2001-09-28 22:41:36 +02:00
$rarray = array (
'directory' => $p -> fake_leading_dirs ,
'name' => $p -> fake_name ,
2002-01-16 07:36:51 +01:00
'size' => $size ,
2001-09-28 22:41:36 +02:00
'mime_type' => $mime_type
);
2001-08-11 11:01:47 +02:00
return ( $rarray );
2001-07-13 07:12:18 +02:00
}
2001-05-25 05:34:24 +02:00
}
2001-09-28 22:41:36 +02:00
?>