show calendars and ressource-calendars for user whos preferences are displayed, for "default" and "forced" we only display all and primary group calendars, but ressources of current user

This commit is contained in:
Ralf Becker 2014-07-23 12:32:02 +00:00
parent 6a7258e98e
commit 94f0a2df9c
6 changed files with 50 additions and 34 deletions

View File

@ -17,8 +17,8 @@
*/ */
if (isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE__) if (isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE__)
{ {
interface activesync_plugin_write {}; interface activesync_plugin_write {}
interface activesync_plugin_meeting_requests {}; interface activesync_plugin_meeting_requests {}
} }
/** /**
@ -1576,14 +1576,12 @@ END:VTIMEZONE
function settings($hook_data) function settings($hook_data)
{ {
$cals = array(); $cals = array();
if (!$hook_data['setup']) if (!$hook_data['setup'] && is_numeric($hook_data['account_id']))
{ {
if (!isset($this->calendar)) $this->calendar = new calendar_boupdate(); foreach (calendar_bo::list_calendars($hook_data['account_id']) as $entry)
foreach ($this->calendar->list_cals() as $entry)
{ {
$account_id = $entry['grantor']; $account_id = $entry['grantor'];
if ($account_id != $GLOBALS['egw_info']['user']['account_id']) if ($account_id != $hook_data['account_id']) // skip current user
{ {
$cals[$account_id] = $entry['name']; $cals[$account_id] = $entry['name'];
} }

View File

@ -1650,7 +1650,7 @@ class calendar_bo
/** /**
* This is called only by list_cals(). It was moved here to remove fatal error in php5 beta4 * This is called only by list_cals(). It was moved here to remove fatal error in php5 beta4
*/ */
function _list_cals_add($id,&$users,&$groups) private static function _list_cals_add($id,&$users,&$groups)
{ {
$name = common::grab_owner_name($id); $name = common::grab_owner_name($id);
if (!($egw_name = $GLOBALS['egw']->accounts->id2name($id))) if (!($egw_name = $GLOBALS['egw']->accounts->id2name($id)))
@ -1680,28 +1680,41 @@ class calendar_bo
*/ */
function list_cals() function list_cals()
{ {
$users = $groups = array(); return self::list_calendars($GLOBALS['egw_info']['user']['account_id'], $this->grants);
foreach($this->grants as $id => $rights)
{
$this->_list_cals_add($id,$users,$groups);
} }
if (($memberships = $GLOBALS['egw']->accounts->membership($GLOBALS['egw_info']['user']['account_id'])))
/**
* generate list of user- / group-calendars or a given user
*
* @param int $user account_id of user to generate list for
* @param array $grants=null calendar grants from user, or null to query them from acl class
*/
public static function list_calendars($user, array $grants=null)
{
if (is_null($grants)) $grants = $GLOBALS['egw']->acl->get_grants('calendar', true, $user);
$users = $groups = array();
foreach(array_keys($grants) as $id)
{
self::_list_cals_add($id,$users,$groups);
}
if (($memberships = $GLOBALS['egw']->accounts->membership($user)))
{ {
foreach($memberships as $group_info) foreach($memberships as $group_info)
{ {
$this->_list_cals_add($group_info['account_id'],$users,$groups); self::_list_cals_add($group_info['account_id'],$users,$groups);
if ($account_perms = $GLOBALS['egw']->acl->get_ids_for_location($group_info['account_id'],EGW_ACL_READ,'calendar')) if (($account_perms = $GLOBALS['egw']->acl->get_ids_for_location($group_info['account_id'],EGW_ACL_READ,'calendar')))
{ {
foreach($account_perms as $id) foreach($account_perms as $id)
{ {
$this->_list_cals_add($id,$users,$groups); self::_list_cals_add($id,$users,$groups);
} }
} }
} }
} }
usort($users,array($this,'name_cmp')); usort($users, array(__CLASS__, 'name_cmp'));
usort($groups,array($this,'name_cmp')); usort($groups, array(__CLASS__, 'name_cmp'));
return array_merge($users, $groups); // users first and then groups, both alphabeticaly return array_merge($users, $groups); // users first and then groups, both alphabeticaly
} }
@ -1713,7 +1726,7 @@ class calendar_bo
* @param array $b * @param array $b
* @return int * @return int
*/ */
function name_cmp(array $a, array $b) public static function name_cmp(array $a, array $b)
{ {
return strnatcasecmp($a['name'], $b['name']); return strnatcasecmp($a['name'], $b['name']);
} }

View File

@ -1536,21 +1536,19 @@ class calendar_groupdav extends groupdav_handler
*/ */
static function get_settings($hook_data) static function get_settings($hook_data)
{ {
$calendars = array(); $calendars = array(
if (!isset($hook_data['setup'])) 'A' => lang('All'),
'G' => lang('Primary Group'),
);
if (!isset($hook_data['setup']) && in_array($hook_data['type'], array('user', 'group')))
{ {
$user = $GLOBALS['egw_info']['user']['account_id']; $user = $hook_data['account_id'];
$cal_bo = new calendar_bo(); foreach (calendar_bo::list_calendars($user) as $entry)
foreach ($cal_bo->list_cals() as $entry)
{ {
$calendars[$entry['grantor']] = $entry['name']; $calendars[$entry['grantor']] = $entry['name'];
} }
unset($calendars[$user]); unset($calendars[$user]);
} }
$calendars = array(
'A' => lang('All'),
'G' => lang('Primary Group'),
) + $calendars;
$settings = array(); $settings = array();
$settings['calendar-home-set'] = array( $settings['calendar-home-set'] = array(

View File

@ -1233,13 +1233,14 @@ class groupdav_principals extends groupdav_handler
/** /**
* Get all resources (we cache the resources here, to only query them once per request) * Get all resources (we cache the resources here, to only query them once per request)
* *
* @param int $user=null account_if of user, or null for current user
* @return array of array with values for res_id, cat_id and name (no other values1) * @return array of array with values for res_id, cat_id and name (no other values1)
*/ */
public static function get_resources() public static function get_resources($user=null)
{ {
if (!isset(self::$all_resources)) if (!isset(self::$all_resources))
{ {
if (!isset(self::$resources)) self::$resources = new resources_bo(); if (!isset(self::$resources)) self::$resources = new resources_bo($user);
self::$all_resources = array(); self::$all_resources = array();
$query = array( $query = array(

View File

@ -37,15 +37,16 @@ class bo_acl
/** /**
* Constructor * Constructor
* *
* @param int $user=null account_id of user whos rights to return, or null for current user
* @param boolean $session * @param boolean $session
*/ */
function __construct($session=False) function __construct($session=False, $user=null)
{ {
define('EGW_ACL_CAT_ADMIN',64); define('EGW_ACL_CAT_ADMIN',64);
define('EGW_ACL_DIRECT_BOOKING',128); define('EGW_ACL_DIRECT_BOOKING',128);
define('EGW_ACL_CALREAD',256); define('EGW_ACL_CALREAD',256);
$this->egw_cats = new categories('','resources'); $this->egw_cats = new categories($user, 'resources');
$this->debug = False; $this->debug = False;
//all this is only needed when called from uiacl. //all this is only needed when called from uiacl.

View File

@ -66,10 +66,15 @@ class resources_bo
'accessory_of' => 'Accessory of' 'accessory_of' => 'Accessory of'
); );
function __construct() /**
* Constructor
*
* @param int $user=null account_id of user to use for acl, default current user
*/
function __construct($user=null)
{ {
$this->so = new resources_so(); $this->so = new resources_so();
$this->acl =& CreateObject('resources.bo_acl'); $this->acl = CreateObject('resources.bo_acl', $user);
$this->cats = $this->acl->egw_cats; $this->cats = $this->acl->egw_cats;
$this->cal_right_transform = array( $this->cal_right_transform = array(