move logic of which addressbook/calendars are shared into app-handler

move app-specific settings to app-handler
This commit is contained in:
Ralf Becker 2012-02-10 11:27:26 +00:00
parent c01e631e95
commit 9d85196706
6 changed files with 223 additions and 139 deletions

View File

@ -780,4 +780,87 @@ class addressbook_groupdav extends groupdav_handler
{
return $this->bo->check_perms($acl,$contact);
}
/**
* Return calendars/addressbooks shared from other users with the current one
*
* return array account_id => account_lid pairs
*/
function get_shared()
{
$shared = array();
$addressbook_home_set = $GLOBALS['egw_info']['user']['preferences']['groupdav']['addressbook-home-set'];
if (empty($addressbook_home_set)) $addressbook_home_set = 'P'; // personal addressbook
$addressbook_home_set = explode(',',$addressbook_home_set);
// replace symbolic id's with real nummeric id's
foreach(array(
'G' => $GLOBALS['egw_info']['user']['account_primary_group'],
'U' => '0',
) as $sym => $id)
{
if (($key = array_search($sym, $addressbook_home_set)) !== false)
{
$addressbook_home_set[$key] = $id;
}
}
foreach($this->bo->get_addressbooks(EGW_ACL_READ) as $id => $label)
{
if (($id || !$GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) &&
$user != $id && // no current user and no accounts, if disabled in ab prefs
(in_array('A',$addressbook_home_set) || in_array((string)$id,$addressbook_home_set)) &&
is_numeric($id) && ($owner = $id ? $this->accounts->id2name($id) : 'accounts'))
{
$shared[$id] = $owner;
}
}
return $shared;
}
/**
* Return appliction specific settings
*
* return array of array with settings
*/
static function get_settings()
{
if ($hook_data['setup'])
{
$addressbooks = array();
}
else
{
$user = $GLOBALS['egw_info']['user']['account_id'];
$addressbook_bo = new addressbook_bo();
$addressbooks = $addressbook_bo->get_addressbooks(EGW_ACL_READ);
unset($addressbooks[$user]); // allways synced
unset($addressbooks[$user.'p']);// ignore (optional) private addressbook for now
}
$addressbooks = array(
'A' => lang('All'),
'G' => lang('Primary Group'),
'U' => lang('Accounts'),
) + $addressbooks;
// rewriting owner=0 to 'U', as 0 get's always selected by prefs
if (!isset($addressbooks[0]))
{
unset($addressbooks['U']);
}
else
{
unset($addressbooks[0]);
}
$settings = array();
$settings['addressbook-home-set'] = array(
'type' => 'multiselect',
'label' => 'Addressbooks to sync in addition to personal addressbook',
'name' => 'addressbook-home-set',
'help' => lang('Only supported by a few fully conformant clients (eg. from Apple). If you have to enter a URL, it will most likly not be suppored!').'<br/>'.lang('They will be sub-folders in users home (%1 attribute).','CardDAV "addressbook-home-set"'),
'values' => $addressbooks,
'xmlrpc' => True,
'admin' => False,
);
return $settings;
}
}

View File

@ -1218,4 +1218,76 @@ class calendar_groupdav extends groupdav_handler
if ($this->debug > 1) error_log("ical Handler called: " . $this->agent);
return $handler;
}
/**
* Return calendars/addressbooks shared from other users with the current one
*
* return array account_id => account_lid pairs
*/
function get_shared()
{
$shared = array();
$calendar_home_set = $GLOBALS['egw_info']['user']['preferences']['groupdav']['calendar-home-set'];
$calendar_home_set = $calendar_home_set ? explode(',',$calendar_home_set) : array();
// replace symbolic id's with real nummeric id's
foreach(array(
'G' => $GLOBALS['egw_info']['user']['account_primary_group'],
) as $sym => $id)
{
if (($key = array_search($sym, $calendar_home_set)) !== false)
{
$calendar_home_set[$key] = $id;
}
}
foreach(ExecMethod('calendar.calendar_bo.list_cals') as $entry)
{
$id = $entry['grantor'];
if ($id && $user != $id && // no current user and no accounts yet (todo)
(in_array('A',$calendar_home_set) || in_array((string)$id,$calendar_home_set)) &&
is_numeric($id) && ($owner = $this->accounts->id2name($id)))
{
$shared[$id] = $owner;
}
}
return $shared;
}
/**
* Return appliction specific settings
*
* return array of array with settings
*/
static function get_settings()
{
if ($hook_data['setup'])
{
$calendars = array();
}
else
{
$user = $GLOBALS['egw_info']['user']['account_id'];
$cal_bo = new calendar_bo();
foreach ($cal_bo->list_cals() as $entry)
{
$calendars[$entry['grantor']] = $entry['name'];
}
unset($calendars[$user]);
}
$calendars = array(
'A' => lang('All'),
'G' => lang('Primary Group'),
) + $calendars;
$settings = array();
$settings['calendar-home-set'] = array(
'type' => 'multiselect',
'label' => 'Calendars to sync in addition to personal calendar',
'name' => 'calendar-home-set',
'help' => lang('Only supported by a few fully conformant clients (eg. from Apple). If you have to enter a URL, it will most likly not be suppored!').'<br/>'.lang('They will be sub-folders in users home (%1 attribute).','CalDAV "calendar-home-set"'),
'values' => $calendars,
'xmlrpc' => True,
'admin' => False,
);
return $settings;
}
}

View File

@ -612,4 +612,35 @@ class infolog_groupdav extends groupdav_handler
return $handler;
}
}
/**
* Return appliction specific settings
*
* return array of array with settings
*/
static function get_settings()
{
translation::add_app('infolog');
$infolog = new infolog_bo();
if (!($types = $infolog->enums['type']))
{
$types = array(
'task' => 'Tasks',
);
}
$settings = array();
$settings['infolog-types'] = array(
'type' => 'multiselect',
'label' => 'InfoLog types to sync',
'name' => 'infolog-types',
'help' => 'Which InfoLog types should be synced with the device, default only tasks.',
'values' => $types,
'default' => 'task',
'xmlrpc' => True,
'admin' => False,
);
return $settings;
}
}

View File

@ -643,71 +643,20 @@ class groupdav extends HTTP_WebDAV_Server
protected function add_shared(array &$files, $path, $app, $user)
{
// currently only show shared calendars/addressbooks for current user and not in the root
if ($path == '/' || $user != $GLOBALS['egw_info']['user']['account_id'])
if ($path == '/' || $user != $GLOBALS['egw_info']['user']['account_id'] ||
!isset($GLOBALS['egw_info']['user']['apps'][$app])) // also avoids principals, inbox and outbox
{
return true;
}
switch($app)
$handler = $this->app_handler($app);
if (($shared = $handler->get_shared()))
{
case 'addressbook':
$addressbook_home_set = $GLOBALS['egw_info']['user']['preferences']['groupdav']['addressbook-home-set'];
if (empty($addressbook_home_set)) $addressbook_home_set = 'P'; // personal addressbook
$addressbook_home_set = explode(',',$addressbook_home_set);
// replace symbolic id's with real nummeric id's
foreach(array(
'G' => $GLOBALS['egw_info']['user']['account_primary_group'],
'U' => '0',
) as $sym => $id)
{
if (($key = array_search($sym, $addressbook_home_set)) !== false)
{
$addressbook_home_set[$key] = $id;
}
}
foreach(ExecMethod('addressbook.addressbook_bo.get_addressbooks',EGW_ACL_READ) as $id => $label)
{
if (($id || !$GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) &&
$user != $id && // no current user and no accounts, if disabled in ab prefs
(in_array('A',$addressbook_home_set) || in_array((string)$id,$addressbook_home_set)) &&
is_numeric($id) && ($owner = $id ? $this->accounts->id2name($id) : 'accounts'))
{
$file = $this->add_app($app,false,$id,$path.'addressbook-'.$owner.'/');
$file['props']['resourcetype']['val'][] = self::mkprop(self::CALENDARSERVER,'shared','');
$files[] = $file;
}
}
break;
case 'calendar':
$calendar_home_set = $GLOBALS['egw_info']['user']['preferences']['groupdav']['calendar-home-set'];
$calendar_home_set = $calendar_home_set ? explode(',',$calendar_home_set) : array();
// replace symbolic id's with real nummeric id's
foreach(array(
'G' => $GLOBALS['egw_info']['user']['account_primary_group'],
) as $sym => $id)
{
if (($key = array_search($sym, $calendar_home_set)) !== false)
{
$calendar_home_set[$key] = $id;
}
}
foreach(ExecMethod('calendar.calendar_bo.list_cals') as $entry)
{
$id = $entry['grantor'];
if ($id && $user != $id && // no current user and no accounts yet (todo)
(in_array('A',$calendar_home_set) || in_array((string)$id,$calendar_home_set)) &&
is_numeric($id) && ($owner = $this->accounts->id2name($id)))
{
$file = $this->add_app($app,false,$id,$path.'calendar-'.$owner.'/');
$file['props']['resourcetype']['val'][] = self::mkprop(self::CALENDARSERVER,'shared','');
$files[] = $file;
}
}
break;
case 'infolog':
// ToDo:
break;
foreach($shared as $id => $owner)
{
$file = $this->add_app($app,false,$id,$path.$app.'-'.$owner.'/');
$file['props']['resourcetype']['val'][] = self::mkprop(self::CALENDARSERVER,'shared','');
$files[] = $file;
}
}
return true;
}

View File

@ -457,6 +457,26 @@ abstract class groupdav_handler
return $entry[self::$path_attr].self::$path_extension;
}
/**
* Return calendars/addressbooks shared from other users with the current one
*
* return array account_id => account_lid pairs
*/
function get_shared()
{
return array();
}
/**
* Return appliction specific settings
*
* return array of array with settings
*/
static function get_settings()
{
return array();
}
/**
* Add a resource
*

View File

@ -54,91 +54,20 @@ class groupdav_hooks
if ($hook_data['setup'])
{
$addressbooks = array();
$apps = array('addressbook','calendar','infolog');
}
else
{
$user = $GLOBALS['egw_info']['user']['account_id'];
$addressbook_bo = new addressbook_bo();
$addressbooks = $addressbook_bo->get_addressbooks(EGW_ACL_READ);
unset($addressbooks[$user]); // allways synced
unset($addressbooks[$user.'p']);// ignore (optional) private addressbook for now
$apps = array_keys($GLOBALS['egw_info']['user']['apps']);
}
$addressbooks = array(
'A' => lang('All'),
'G' => lang('Primary Group'),
'U' => lang('Accounts'),
) + $addressbooks;
// rewriting owner=0 to 'U', as 0 get's always selected by prefs
if (!isset($addressbooks[0]))
foreach($apps as $app)
{
unset($addressbooks['U']);
}
else
{
unset($addressbooks[0]);
}
$settings['addressbook-home-set'] = array(
'type' => 'multiselect',
'label' => 'Addressbooks to sync in addition to personal addressbook',
'name' => 'addressbook-home-set',
'help' => lang('Only supported by a few fully conformant clients (eg. from Apple). If you have to enter a URL, it will most likly not be suppored!').'<br/>'.lang('They will be sub-folders in users home (%1 attribute).','CardDAV "addressbook-home-set"'),
'values' => $addressbooks,
'xmlrpc' => True,
'admin' => False,
);
if ($hook_data['setup'])
{
$calendars = array();
}
else
{
$user = $GLOBALS['egw_info']['user']['account_id'];
$cal_bo = new calendar_bo();
foreach ($cal_bo->list_cals() as $entry)
$class_name = $app.'_groupdav';
if (class_exists($class_name, true))
{
$calendars[$entry['grantor']] = $entry['name'];
$settings += call_user_func(array($class_name,'get_settings'));
}
unset($calendars[$user]);
}
$calendars = array(
'A' => lang('All'),
'G' => lang('Primary Group'),
) + $calendars;
$settings['calendar-home-set'] = array(
'type' => 'multiselect',
'label' => 'Calendars to sync in addition to personal calendar',
'name' => 'calendar-home-set',
'help' => lang('Only supported by a few fully conformant clients (eg. from Apple). If you have to enter a URL, it will most likly not be suppored!').'<br/>'.lang('They will be sub-folders in users home (%1 attribute).','CalDAV "calendar-home-set"'),
'values' => $calendars,
'xmlrpc' => True,
'admin' => False,
);
translation::add_app('infolog');
$infolog = new infolog_bo();
if (!($types = $infolog->enums['type']))
{
$types = array(
'task' => 'Tasks',
);
}
$settings['infolog-types'] = array(
'type' => 'multiselect',
'label' => 'InfoLog types to sync',
'name' => 'infolog-types',
'help' => 'Which InfoLog types should be synced with the device, default only tasks.',
'values' => $types,
'default' => 'task',
'xmlrpc' => True,
'admin' => False,
);
$settings['debug_level'] = array(
'type' => 'select',