VFS SQL2 classes

This commit is contained in:
viniciuscb 2005-05-17 14:48:20 +00:00
parent 7c5b4d93c0
commit 729b5d3d7a
5 changed files with 528 additions and 647 deletions

View File

@ -32,7 +32,7 @@
// same object (i.e. use reference) in $this->vfs // same object (i.e. use reference) in $this->vfs
if ($create_vfs) if ($create_vfs)
{ {
$this->vfs = CreateObject('phpgwapi.vfs'); $this->vfs =& CreateObject('phpgwapi.vfs');
} }
$this->default_filetype_icon = PHPGW_INCLUDE_ROOT.'/filescenter/icons/default.gif'; $this->default_filetype_icon = PHPGW_INCLUDE_ROOT.'/filescenter/icons/default.gif';
@ -58,12 +58,12 @@
*/ */
function add_filetype($data,$return_image=false,$dont_update=false) function add_filetype($data,$return_image=false,$dont_update=false)
{ {
if (!$data['extension'] && !$data['mime']) if (!$data['extension'] && !$data['mime'])
{ {
return false; return false;
} }
if (!$data['mime']) if (!$data['mime'])
{ {
$data['mime'] = $this->get_mime_type($data['extension']); $data['mime'] = $this->get_mime_type($data['extension']);
@ -96,6 +96,8 @@
$data['image'] = fread($fp,filesize($data['icon_name'])); $data['image'] = fread($fp,filesize($data['icon_name']));
fclose($fp); fclose($fp);
$data['image'] = $this->db->quote($data['image'],'blob');
unset($data['icon_name']); unset($data['icon_name']);
} }
@ -161,6 +163,11 @@
$where['mime_id'] = $data['mime_id']; $where['mime_id'] = $data['mime_id'];
if ($data['image'])
{
$data['image'] = $this->db->quote($data['image'],'blob');
}
$res = $this->db->update('phpgw_vfs2_mimetypes',$data,$where,__LINE__,__FILE__); $res = $this->db->update('phpgw_vfs2_mimetypes',$data,$where,__LINE__,__FILE__);
@ -197,7 +204,6 @@
*/ */
function get_type($data, $return_image=false) function get_type($data, $return_image=false)
{ {
//TODO error messages //TODO error messages
if ((!$data['extension'] || $data['extension'] == '(n/a)') && if ((!$data['extension'] || $data['extension'] == '(n/a)') &&
!$data['mime_id'] && !$data['mime']) !$data['mime_id'] && !$data['mime'])
@ -222,8 +228,25 @@
array('mime'=>$data['mime']),__LINE__,__FILE__); array('mime'=>$data['mime']),__LINE__,__FILE__);
} }
if($this->db->next_record()) if ($data['extension'] && $data['mime'])
{
//if there is extension and mime specified and nothing was found only with extension, search mime
if ($this->db->next_record())
return $this->db->Record; return $this->db->Record;
else
{
$this->db->select('phpgw_vfs2_mimetypes',$return_fields,
array('mime'=>$data['mime']),__LINE__,__FILE__);
if ($this->db->next_record())
return $this->db->Record;
}
}
else
{
if ($this->db->next_record())
return $this->db->Record;
}
return false; return false;
@ -275,6 +298,8 @@
fclose($fp); fclose($fp);
} }
$data['image'] = $this->db->quote($data['image'],'blob');
unset($data['icon_name']); unset($data['icon_name']);
} }

View File

@ -200,7 +200,7 @@
break; break;
case 'view': case 'view':
$acl = CreateObject('phpgwapi.acl',$user_id); $acl =& CreateObject('phpgwapi.acl',$user_id);
//fetch ids of prefixes that user can view //fetch ids of prefixes that user can view
if (!$pr_list = $acl->get_location_list_for_id(PHPGW_VFS2_PREFIX_APP,PHPGW_ACL_READ,$user_id)) if (!$pr_list = $acl->get_location_list_for_id(PHPGW_VFS2_PREFIX_APP,PHPGW_ACL_READ,$user_id))
@ -301,7 +301,7 @@
$list_of_users_to_del = array_diff($current_permissions,$user_list); $list_of_users_to_del = array_diff($current_permissions,$user_list);
$acl = CreateObject('phpgwapi.acl',$current_user_id); $acl =& CreateObject('phpgwapi.acl',$current_user_id);
foreach($list_of_users_to_add as $user_id) foreach($list_of_users_to_add as $user_id)
{ {
@ -362,7 +362,7 @@
return false; return false;
} }
$acl = CreateObject('phpgwapi.acl'); $acl =& CreateObject('phpgwapi.acl');
$user_ids = $acl->get_ids_for_location($prefix_id,PHPGW_ACL_READ,PHPGW_VFS2_PREFIX_APP); $user_ids = $acl->get_ids_for_location($prefix_id,PHPGW_ACL_READ,PHPGW_VFS2_PREFIX_APP);
return ($user_ids)?$user_ids:array(); return ($user_ids)?$user_ids:array();

View File

@ -161,14 +161,27 @@
return false; return false;
} }
foreach($account_ids as $account_id => $acl_rights) //gets an array will all accounts as key
$accounts = array_keys($account_ids);
$this->db->delete('phpgw_vfs2_shares',
array('account_id'=>$accounts,'file_id'=>$file_id),
__LINE__,__FILE__);
return true;
}
/**
* Function: remove_all_permissions
*
* Removes all permissions of a file
*/
function remove_all_permissions($file_id)
{ {
$this->db->delete('phpgw_vfs2_shares', $this->db->delete('phpgw_vfs2_shares',
array('account_id'=>$account_id,'file_id'=>$file_id), array('file_id'=>$file_id),
__LINE__,__FILE__); __LINE__,__FILE__);
} }
return true;
}
/*! /*!
* function get_permissions * function get_permissions
@ -207,8 +220,42 @@
* others that he have $permission (false) * others that he have $permission (false)
* @result array with the list of the file_id's of all shares * @result array with the list of the file_id's of all shares
*/ */
function get_shares($account_id,$is_owner=false,$permission=PHPGW_ACL_READ) function get_shares($account_id,$is_owner=false,$permission=PHPGW_ACL_READ,$exclude_dir='')
{ {
$default_values = array(
'is_owner' => false,
'permission' => PHPGW_ACL_READ
);
if (is_array($account_id))
{
$account_id = array_merge($default_values,$account_id);
$is_owner = $account_id['is_owner'];
$permission = $account_id['permission'];
$exclude_dir = $account_id['exclude_dir'];
$only_dir = $account_id['only_dir'];
$account_id = $account_id['account_id'];
}
if ($exclude_dir)
{
if (is_array($exclude_dir))
{
foreach ($exclude_dir as $dir)
{
$append .= " AND fls.directory NOT LIKE '".$dir."%' ";
}
}
else
{
$append .= " AND fls.directory NOT LIKE '".$exclude_dir."%' ";
}
}
elseif ($only_dir)
{
$append .= " AND fls.directory LIKE '".$only_dir."%' ";
}
if ($is_owner) if ($is_owner)
{ {
$sql = "SELECT DISTINCT sh.file_id as file_id, $sql = "SELECT DISTINCT sh.file_id as file_id,
@ -218,8 +265,11 @@
fls.owner_id as owner_id fls.owner_id as owner_id
FROM phpgw_vfs2_shares as sh, FROM phpgw_vfs2_shares as sh,
phpgw_vfs2_files as fls phpgw_vfs2_files as fls
INNER JOIN phpgw_vfs2_mimetypes mime on fls.mime_id = mime.mime_id
WHERE sh.file_id = fls.file_id WHERE sh.file_id = fls.file_id
AND mime.mime = 'Directory'
AND fls.shared = 'Y' AND fls.shared = 'Y'
$append
AND fls.owner_id = $account_id"; AND fls.owner_id = $account_id";
} }
else else
@ -241,9 +291,12 @@
fls.owner_id as owner_id fls.owner_id as owner_id
FROM phpgw_vfs2_shares as sh, FROM phpgw_vfs2_shares as sh,
phpgw_vfs2_files as fls phpgw_vfs2_files as fls
INNER JOIN phpgw_vfs2_mimetypes mime on fls.mime_id = mime.mime_id
WHERE sh.file_id = fls.file_id WHERE sh.file_id = fls.file_id
AND mime.mime = 'Directory'
AND sh.account_id IN (".implode(',',$accounts).") AND sh.account_id IN (".implode(',',$accounts).")
AND fls.shared = 'Y' AND fls.shared = 'Y'
$append
AND fls.owner_id != $account_id"; AND fls.owner_id != $account_id";
} }
@ -312,14 +365,16 @@
return $res; return $res;
} }
/*! /**
* function get_file_permissions * Function: get_file_permissions
* @description Get the permissions for a user in a given file *
* For files in a shared dir, will get the acl rights of the parent * Gets the permissions for a user in a given file For files in a
* dir, and if not specified, of the parent of the parent, and so on. * shared dir, will get the acl rights of the parent dir, and if
* NOTE: this consider that files CANNOT have permissions set, only * not specified, of the parent of the parent, and so on. NOTE:
* this consider that files CANNOT have permissions set, only
* their parent dir, and the file inherits the nearer parent with * their parent dir, and the file inherits the nearer parent with
* permissions defined * permissions defined (even if these permissions are NONE)
*
* @result int some mask of various PHPGW_ACL_* * @result int some mask of various PHPGW_ACL_*
*/ */
function get_file_permissions($account_id,$file_id) function get_file_permissions($account_id,$file_id)
@ -364,31 +419,54 @@
} }
$accounts[] = $account_id; $accounts[] = $account_id;
$accounts[] = 0; //default permission for all users
$accounts = implode(',',$accounts); $accounts = implode(',',$accounts);
//searches for information in the parent dirs //searches for information in the parent dirs
for($i=0; $i<count($parent_dirs_array);$i++) for($i=0; $i<count($parent_dirs_array);$i++)
{ {
$dir_name = array_pop(explode('/',$parent_dirs_array[$i])); $dir_name = array_pop(explode('/',$parent_dirs_array[$i]));
if ($dir_name) if ($dir_name)
{ {
//if file have a reg in table, will try to see if it is
//with permissions to the current user
$sql = "SELECT sh.acl_rights as acl_rights, $sql = "SELECT sh.acl_rights as acl_rights,
fls.directory as directory, fls.directory as directory,
fls.name as name, fls.name as name,
fls.owner_id as owner_id fls.owner_id as owner_id,
FROM phpgw_vfs2_shares as sh, fls.shared as shared
phpgw_vfs2_files as fls FROM phpgw_vfs2_files as fls,
WHERE sh.file_id = fls.file_id phpgw_vfs2_shares as sh
AND (sh.account_id IN ($accounts) WHERE fls.file_id = sh.file_id
OR fls.owner_id = $account_id)
AND fls.directory = '".$parent_dirs_array[$i+1]."' AND fls.directory = '".$parent_dirs_array[$i+1]."'
AND fls.name = '".$dir_name."'"; AND fls.name = '".$dir_name."'
AND fls.shared = 'Y'";
$this->db->query($sql,__LINE__,__FILE__); $this->db->query($sql,__LINE__,__FILE__);
/* if ($this->db->next_record())
{
$sql = "SELECT sh.acl_rights as acl_rights,
fls.directory as directory,
fls.name as name,
fls.owner_id as owner_id,
fls.shared as shared
FROM phpgw_vfs2_files as fls,
phpgw_vfs2_shares as sh
WHERE (sh.account_id IN ($accounts)
OR fls.owner_id = $account_id)
AND fls.file_id = sh.file_id
AND fls.directory = '".$parent_dirs_array[$i+1]."'
AND fls.name = '".$dir_name."'
AND fls.shared = 'Y'";
$this->db->query($sql,__LINE__,__FILE__);
/*
$this->db->select('phpgw_vfs2_files','file_id', $this->db->select('phpgw_vfs2_files','file_id',
array('directory'=>$parent_dirs_array[$i+1], array('directory'=>$parent_dirs_array[$i+1],
'name'=>$dir_name), __LINE__,__FILE__); 'name'=>$dir_name), __LINE__,__FILE__);
@ -399,8 +477,14 @@
array('file_id'=>$this->db->Record['file_id'], array('file_id'=>$this->db->Record['file_id'],
'account_id'=>$account_id),__LINE__,__FILE__);*/ 'account_id'=>$account_id),__LINE__,__FILE__);*/
// echo "tested file: ".$dir_name." \n<br>";
// echo $sql."<br><br>\n\n";
while ($this->db->next_record()) while ($this->db->next_record())
{ {
// echo "results for file: ".$dir_name." \n<br>";
if ($this->db->Record['owner_id'] == $account_id) if ($this->db->Record['owner_id'] == $account_id)
{ {
//the user can do anything with any dir or file //the user can do anything with any dir or file
@ -417,6 +501,11 @@
{ {
return $result; return $result;
} }
else
{
return 0;
}
}
} }
} }
return false; return false;

File diff suppressed because it is too large Load Diff

View File

@ -81,7 +81,7 @@
// creating a new object. // creating a new object.
if ($create_vfs) if ($create_vfs)
{ {
$this->vfs = CreateObject('phpgwapi.vfs'); $this->vfs =& CreateObject('phpgwapi.vfs');
} }
/* FIXME this takes a value defined in the filescenter /* FIXME this takes a value defined in the filescenter