avoid calling accounts->members(hips) without an account_id and cast accounts->members(hips) to array, to cope without PHP warnings for not (longer) existing accounts

This commit is contained in:
Ralf Becker 2012-08-09 09:53:34 +00:00
parent 38d14091ff
commit 959739d32b
6 changed files with 75 additions and 61 deletions

View File

@ -1144,7 +1144,7 @@ class calendar_bo
{
foreach($event['participants'] as $uid => $accept)
{
if ($uid == $user || $uid < 0 && in_array($user,$GLOBALS['egw']->accounts->members($uid,true)))
if ($uid == $user || $uid < 0 && in_array($user, (array)$GLOBALS['egw']->accounts->members($uid,true)))
{
// if we are a participant, we have an implicite FREEBUSY, READ and PRIVAT grant
$grant |= EGW_ACL_FREEBUSY | EGW_ACL_READ | EGW_ACL_PRIVATE;

View File

@ -238,7 +238,7 @@ class calendar_boupdate extends calendar_bo
if ($uid < 0) // group, check it's members too
{
$users += $GLOBALS['egw']->accounts->members($uid,true);
$users += (array)$GLOBALS['egw']->accounts->members($uid,true);
$users = array_unique($users);
}
$users[] = $uid;

View File

@ -465,8 +465,8 @@ class calendar_ical extends calendar_boupdate
case 'g':
$cutype = 'GROUP';
$participantURL = 'urn:uuid:'.common::generate_uid('accounts', $uid);
$members = $GLOBALS['egw']->accounts->members($uid, true);
if (!isset($event['participants'][$this->user]) && in_array($this->user, $members))
if (!isset($event['participants'][$this->user]) &&
($members = $GLOBALS['egw']->accounts->members($uid, true)) && in_array($this->user, $members))
{
$user = $this->resource_info($this->user);
$attributes['ATTENDEE'][] = 'MAILTO:' . $user['email'];
@ -2822,8 +2822,8 @@ class calendar_ical extends calendar_boupdate
$status != 'X' && $status != 'U')
{
// User tries to reply to the group invitiation
$members = $GLOBALS['egw']->accounts->members($uid, true);
if (in_array($this->user, $members))
if (($members = $GLOBALS['egw']->accounts->members($uid, true)) &&
in_array($this->user, $members))
{
//Horde::logMessage("vevent2egw: set status to " . $status,
// __FILE__, __LINE__, PEAR_LOG_DEBUG);

View File

@ -266,9 +266,9 @@ class accounts
elseif(in_array($param['type'],array('groupmembers','groupmembers+memberships')))
{
$members = array();
foreach($this->memberships($GLOBALS['egw_info']['user']['account_id'],true) as $grp)
foreach((array)$this->memberships($GLOBALS['egw_info']['user']['account_id'],true) as $grp)
{
$members = array_unique(array_merge($members,$this->members($grp,true)));
$members = array_unique(array_merge($members, (array)$this->members($grp,true)));
if ($param['type'] == 'groupmembers+memberships') $members[] = $grp;
}
$param['type'] = $param['type'] == 'groupmembers+memberships' ? 'both' : 'accounts';
@ -578,8 +578,8 @@ class accounts
$account_lid != $GLOBALS['egw_info']['user']['account_lid'] ||
// only allow group-members for account-selection is groupmembers
$GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'groupmembers' &&
!array_intersect($this->memberships($account_id,true),
$this->memberships($GLOBALS['egw_info']['user']['account_id'],true))))
!array_intersect((array)$this->memberships($account_id,true),
(array)$this->memberships($GLOBALS['egw_info']['user']['account_id'],true))))
{
//error_log(__METHOD__."($account_id='$account_lid') returning FALSE");
return false; // user is not allowed to see given account
@ -702,7 +702,7 @@ class accounts
$accounts['groups'][$id] = $id;
if ($use != 'groups')
{
foreach($this->members($id,true) as $id)
foreach((array)$this->members($id,true) as $id)
{
$accounts['accounts'][$id] = $id;
}

View File

@ -52,9 +52,9 @@ class acl
* Some functions are specific to this account, and others are generic.
*
* @example acl->acl(5); // 5 is the user id
* @param int $account_id int-the user id
* @param int $account_id=null user id or default null to use current user from $GLOBALS['egw_info']['user']['account_id']
*/
function acl($account_id = '')
function __construct($account_id = null)
{
if (is_object($GLOBALS['egw_setup']->db))
{
@ -70,6 +70,17 @@ class acl
}
}
/**
* PHP4 constructor
*
* @deprecated use __construct
* @param int $account_id=null
*/
function acl($account_id = null)
{
$this->__construct($account_id);
}
function DONTlist_methods($_type='xmlrpc')
{
/*
@ -131,15 +142,15 @@ class acl
// Here is yet another work around(tm) (jengo)
if (!$this->account_id)
{
$this->acl();
$this->__construct();
}
if ($no_groups === true || !$this->account_id)
if ($no_groups === true || !(int)$this->account_id)
{
$acl_acc_list = $this->account_id;
}
else
{
$acl_acc_list = $GLOBALS['egw']->accounts->memberships($this->account_id,true);
$acl_acc_list = (array)$GLOBALS['egw']->accounts->memberships($this->account_id, true);
if (is_array($no_groups)) $acl_acc_list = array_diff($acl_acc_list,$no_groups);
array_unshift($acl_acc_list,$this->account_id);
}
@ -481,12 +492,10 @@ class acl
if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp'];
$accounts = array($account_id);
if ($use_memberships)
if ($use_memberships && (int)$account_id > 0)
{
foreach((array)$GLOBALS['egw']->accounts->membership($account_id) as $group)
{
$accounts[] = $group['account_id'];
}
$accounts = $GLOBALS['egw']->accounts->memberships($account_id, true);
$accounts[] = $account_id;
}
$rights = array();
foreach($this->db->select(acl::TABLE,'acl_location,acl_rights',array(
@ -642,7 +651,7 @@ class acl
$account_id = get_account_id($accountid,$this->account_id);
$cache_accountid[$accountid] = $account_id;
}
$memberships = $GLOBALS['egw']->accounts->memberships($account_id,true);
if ((int)$account_id > 0) $memberships = $GLOBALS['egw']->accounts->memberships($account_id, true);
$memberships[] = $account_id;
$apps = false;
@ -669,58 +678,61 @@ class acl
* @param string $app optional defaults to $GLOBALS['egw_info']['flags']['currentapp']
* @param boolean/array $enum_group_acls=true should group acls be returned for all members of that group, default yes
* if an array of group-id's is given, that id's will NOT be enumerated!
* @param int $user=null user whos grants to return, default current user
* @return array with account-ids (of owners) and granted rights as values
*/
function get_grants($app='',$enum_group_acls=true)
function get_grants($app='',$enum_group_acls=true,$user=null)
{
if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp'];
if (!$user) $user = $this->account_id;
$memberships = array($this->account_id);
foreach((array)$GLOBALS['egw']->accounts->membership($this->account_id) as $group)
static $cache = array(); // some caching withing the request
$grants =& $cache[$app][$user];
if (!isset($grants))
{
$memberships[] = $group['account_id'];
}
$grants = $accounts = Array();
foreach($this->db->select(acl::TABLE,array('acl_account','acl_rights','acl_location'),array(
'acl_appname' => $app,
'acl_location' => $memberships,
),__LINE__,__FILE__) as $row)
{
$grantor = $row['acl_account'];
$rights = $row['acl_rights'];
$granted_to = (int) $row['acl_location'];
if ((int)$user > 0) $memberships = $GLOBALS['egw']->accounts->memberships($user, true);
$memberships[] = $user;
if(!isset($grants[$grantor]))
$grants = $accounts = Array();
foreach($this->db->select(acl::TABLE,array('acl_account','acl_rights','acl_location'),array(
'acl_appname' => $app,
'acl_location' => $memberships,
),__LINE__,__FILE__) as $row)
{
$grants[$grantor] = 0;
}
$grants[$grantor] |= $rights;
$grantor = $row['acl_account'];
$rights = $row['acl_rights'];
$granted_to = (int) $row['acl_location'];
// if the right is granted from a group and we enummerated group ACL's
if ($GLOBALS['egw']->accounts->get_type($grantor) == 'g' && $enum_group_acls &&
(!is_array($enum_group_acls) || !in_array($grantor,$enum_group_acls)))
{
// return the grant for each member of the group
foreach((array)$GLOBALS['egw']->accounts->member($grantor) as $member)
if(!isset($grants[$grantor]))
{
if (!$member) continue; // can happen if group has no members
$grants[$grantor] = 0;
}
$grants[$grantor] |= $rights;
// Don't allow to override private with group ACL's!
$rights &= ~EGW_ACL_PRIVATE;
$grantor = $member['account_id'];
if(!isset($grants[$grantor]))
// if the right is granted from a group and we enummerated group ACL's
if ($GLOBALS['egw']->accounts->get_type($grantor) == 'g' && $enum_group_acls &&
(!is_array($enum_group_acls) || !in_array($grantor,$enum_group_acls)))
{
// return the grant for each member of the group
foreach((array)$GLOBALS['egw']->accounts->members($grantor, true) as $grantor)
{
$grants[$grantor] = 0;
if (!$grantor) continue; // can happen if group has no members
// Don't allow to override private with group ACL's!
$rights &= ~EGW_ACL_PRIVATE;
if(!isset($grants[$grantor]))
{
$grants[$grantor] = 0;
}
$grants[$grantor] |= $rights;
}
$grants[$grantor] |= $rights;
}
}
// user has implizit all rights on own data
$grants[$user] = ~0;
}
// user has implizit all rights on own data
$grants[$GLOBALS['egw_info']['user']['account_id']] = ~0;
//echo "acl::get_grants('$app',$enum_group_acls) ".function_backtrace(); _debug_array($grants);
return $grants;
}

View File

@ -149,12 +149,12 @@ class uiaccountsel
}
else
{
$memberships = $this->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true);
$memberships = (array)$this->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true);
}
$select = count($selected) && !isset($selected[0]) ? array_keys($selected) : $selected;
foreach($memberships as $gid)
{
foreach($this->accounts->members($gid,true) as $member)
foreach((array)$this->accounts->members($gid,true) as $member)
{
if (!in_array($member,$select)) $select[] = $member;
}
@ -163,7 +163,7 @@ class uiaccountsel
{
if ($account_sel == 'primary_group')
{
$memberships = $this->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true);
$memberships = (array)$this->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true);
}
$select = array_merge($select,$memberships);
}
@ -177,6 +177,7 @@ class uiaccountsel
'type' => $use,
'app' => $app,
));
//error_log(__METHOD__."() account_selection='$this->account_selection', accounts->search(array('type'=>'$use', 'app' => '$app')) returns ".array2string($select));
}
// make sure everything in $selected is also in $select, as in the other account-selection methods
if ($selected && ($missing = array_diff_key($selected,$select)))
@ -264,6 +265,7 @@ class uiaccountsel
$select2 += $select;
$select =& $select2; unset($select2);
}
//error_log(__METHOD__."(..., use='$use', ...) account_selection='$this->account_selection', select=".array2string($select));
if ($nohtml)
{