diff --git a/phpgwapi/inc/class.groupdav_handler.inc.php b/phpgwapi/inc/class.groupdav_handler.inc.php index 365efbb377..06607dfeb6 100644 --- a/phpgwapi/inc/class.groupdav_handler.inc.php +++ b/phpgwapi/inc/class.groupdav_handler.inc.php @@ -235,7 +235,7 @@ abstract class groupdav_handler */ function _common_get_put_delete($method,&$options,$id,&$return_no_access=false) { - if (!in_array($this->app,array('principals','groups')) && !$GLOBALS['egw_info']['user']['apps'][$this->app]) + if ($this->app != 'principals' && !$GLOBALS['egw_info']['user']['apps'][$this->app]) { if ($this->debug) error_log(__METHOD__."($method,,$id) 403 Forbidden: no app rights for '$this->app'"); return '403 Forbidden'; // no app rights diff --git a/phpgwapi/inc/class.groupdav_hooks.inc.php b/phpgwapi/inc/class.groupdav_hooks.inc.php new file mode 100644 index 0000000000..8ed402c496 --- /dev/null +++ b/phpgwapi/inc/class.groupdav_hooks.inc.php @@ -0,0 +1,97 @@ + + * @copyright (c) 2010 by Ralf Becker + * @version $Id$ + */ + +/** + * GroupDAV hooks: eg. preferences + */ +class groupdav_hooks +{ + /** + * Show GroupDAV preferences link in preferences + * + * @param string|array $args + */ + public static function menus($args) + { + $appname = 'groupdav'; + $location = is_array($args) ? $args['location'] : $args; + + if ($location == 'preferences') + { + $file = array( + 'Preferences' => egw::link('/index.php','menuaction=preferences.uisettings.index&appname='.$appname), + ); + if ($location == 'preferences') + { + display_section($appname,$file); + } + else + { + display_sidebox($appname,lang('Preferences'),$file); + } + } + } + + /** + * populates $settings for the preferences + * + * @param array|string $hook_data + * @return array + */ + static function settings($hook_data) + { + $settings = array(); + + 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]); // Use P for personal addressbook + unset($addressbooks[$user.'p']);// ignore (optional) private addressbook for now + } + $addressbooks = array( + 'P' => lang('Personal'), + 'G' => lang('Primary Group'), + //'U' => lang('Accounts'), // not yet working + 'O' => lang('All in one'), + 'A' => lang('All'), + ) + $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['add_default'] = array( + 'type' => 'multiselect', + 'label' => 'Addressbooks to sync with Apple clients', + 'name' => 'addressbook-home-set', + 'help' => 'Only read when a new account get created on the client! CardDAV attribute addressbook-home-set.', + 'values' => $addressbooks, + 'xmlrpc' => True, + 'admin' => False, + 'default' => 'P', + ); + return $settings; + } +} \ No newline at end of file diff --git a/phpgwapi/inc/class.groupdav_principals.inc.php b/phpgwapi/inc/class.groupdav_principals.inc.php index f5754dc476..94004bb427 100644 --- a/phpgwapi/inc/class.groupdav_principals.inc.php +++ b/phpgwapi/inc/class.groupdav_principals.inc.php @@ -251,20 +251,43 @@ class groupdav_principals extends groupdav_handler $this->base_uri.'/principals/groups/'.$group); } } - $addressbooks = array(); - $calendars = array(); + $addressbooks = $calendars = array(); if ($account['account_id'] == $GLOBALS['egw_info']['user']['account_id']) { - $addr_bo = new addressbook_bo(); - foreach ($addr_bo->get_addressbooks() as $id => $label) + $prefs = $GLOBALS['egw_info']['user']['preferences']['groupdav']; + $addressbook_home_set = $prefs['addressbook-home-set']; + if (empty($addressbook_home_set)) $addressbook_home_set = 'P'; // personal addressbook + + if (strpos($addressbook_home_set,'A') !== false) { - if ($id && is_numeric($id)) + $addressbook_home_set = array_keys(ExecMethod('addressbook.addressbook_bo.get_addressbooks',EGW_ACL_READ)); + } + else + { + $addressbook_home_set = explode(',',$addressbook_home_set); + } + foreach($addressbook_home_set as $id) + { + switch($id) + { + case 'P': + $id = $GLOBALS['egw_info']['user']['account_id']; + break; + case 'G': + $id = $GLOBALS['egw_info']['user']['account_primary_group']; + break; + case 'O': // "all in one" from groupdav.php/addressbook/ + $addressbooks[] = HTTP_WebDAV_Server::mkprop('href', + $this->base_uri.'/'); + continue 2; + } + if (is_numeric($id) && ($owner = $GLOBALS['egw']->accounts->id2name($id))) { - $owner = $GLOBALS['egw']->accounts->id2name($id); $addressbooks[] = HTTP_WebDAV_Server::mkprop('href', $this->base_uri.'/'.$owner.'/'); } } + $cal_bo = new calendar_bo(); foreach ($cal_bo->list_cals() as $label => $entry) { @@ -277,7 +300,7 @@ class groupdav_principals extends groupdav_handler else { $addressbooks[] = HTTP_WebDAV_Server::mkprop('href', - $this->base_uri.'/'.$account['account_lid'].'/'); + $this->base_uri.'/'.$account['account_lid'].'/'); $calendars[] = HTTP_WebDAV_Server::mkprop('href', $this->base_uri.'/'.$account['account_lid'].'/'); } diff --git a/phpgwapi/inc/class.hooks.inc.php b/phpgwapi/inc/class.hooks.inc.php index f928a6c496..245314d9c8 100644 --- a/phpgwapi/inc/class.hooks.inc.php +++ b/phpgwapi/inc/class.hooks.inc.php @@ -251,7 +251,11 @@ class hooks $f = EGW_SERVER_ROOT . $SEP . $appname . $SEP . 'setup' . $SEP . 'setup.inc.php'; $setup_info = array($appname => array()); if(@file_exists($f)) include($f); - $this->register_hooks($appname,$setup_info[$appname]['hooks']); + // some apps have setup_info for more then themselfs (eg. phpgwapi for groupdav) + foreach($setup_info as $appname => $data) + { + if ($data['hooks']) $this->register_hooks($appname,$data['hooks']); + } } } }