From 9eb50fff4aacb710e301b5487e4e249fbc87559d Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Fri, 14 Dec 2007 23:20:18 +0000 Subject: [PATCH] fixed bug reported on the users list: if admin forced or set a default of 'personal' for the default addressbook where new accounts should be created, it prevents eg. syncml to create the contact, as it's the admins personal addressbook, to whom no user user has access, thanks to pgoerzen-at-hustlerturf.com --- addressbook/inc/class.bocontacts.inc.php | 28 ++++++++++++++++++++++-- addressbook/inc/class.uicontacts.inc.php | 6 ++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/addressbook/inc/class.bocontacts.inc.php b/addressbook/inc/class.bocontacts.inc.php index 370a6b9dda..b580b19e0b 100755 --- a/addressbook/inc/class.bocontacts.inc.php +++ b/addressbook/inc/class.bocontacts.inc.php @@ -112,6 +112,18 @@ class bocontacts extends socontacts * @var array */ var $prefs; + /** + * Default addressbook for new contacts, if no addressbook is specified (user preference) + * + * @var int + */ + var $default_addressbook; + /** + * Default addressbook is the private one + * + * @var boolean + */ + var $default_private; function bocontacts($contact_app='addressbook') { @@ -121,6 +133,18 @@ class bocontacts extends socontacts $this->now_su = time() + $this->tz_offset_s; $this->prefs =& $GLOBALS['egw_info']['user']['preferences']['addressbook']; + + // get the default addressbook from the users prefs + $this->default_private = substr($GLOBALS['egw_info']['user']['preferences']['addressbook'],-1) == 'p'; + $this->default_addressbook = $GLOBALS['egw_info']['user']['preferences']['addressbook'] ? + (int)$GLOBALS['egw_info']['user']['preferences']['addressbook'] : $this->user; + if ($this->default_addressbook > 0 && $this->default_addressbook != $this->user && + ($this->default_private || + $this->default_addressbook == (int)$GLOBALS['egw']->preferences->forced['addressbook']['add_default']) || + $this->default_addressbook == (int)$GLOBALS['egw']->preferences->default['addressbook']['add_default']) + { + $this->default_addressbook = $this->user; // admin set a default or forced pref for personal addressbook + } $this->contact_fields = array( 'id' => lang('Contact ID'), @@ -461,8 +485,8 @@ class bocontacts extends socontacts if (!$isUpdate) { // if no owner/addressbook set use the setting of the add_default prefs (if set, otherwise the users personal addressbook) - if (!isset($contact['owner'])) $contact['owner'] = (int)$this->prefs['add_default'] ? (int)$this->prefs['add_default'] : $this->user; - if (!isset($contact['private'])) $contact['private'] = (int)(substr($this->prefs['add_default'],-1) == 'p'); + if (!isset($contact['owner'])) $contact['owner'] = $this->default_addressbook; + if (!isset($contact['private'])) $contact['private'] = (int)$this->default_private; // allow admins to import contacts with creator / created date set if (!$contact['creator'] || !$this->is_admin($contact)) $contact['creator'] = $this->user; if (!$contact['created'] || !$this->is_admin($contact)) $contact['created'] = $this->now_su; diff --git a/addressbook/inc/class.uicontacts.inc.php b/addressbook/inc/class.uicontacts.inc.php index 61f16d7bdb..70219b8b58 100644 --- a/addressbook/inc/class.uicontacts.inc.php +++ b/addressbook/inc/class.uicontacts.inc.php @@ -1270,8 +1270,8 @@ class uicontacts extends bocontacts $content['private'] = (int) ($content['owner'] && substr($content['owner'],-1) == 'p'); if (!($this->grants[$content['owner'] = (string) (int) $content['owner']] & EGW_ACL_ADD)) { - $content['owner'] = $this->prefs['add_default']; - $content['private'] = (int) ($content['owner'] && substr($content['owner'],-1) == 'p'); + $content['owner'] = $this->default_addressbook; + $content['private'] = (int)$this->default_private; if (!($this->grants[$content['owner'] = (string) (int) $content['owner']] & EGW_ACL_ADD)) { @@ -1298,7 +1298,7 @@ class uicontacts extends bocontacts $content['id'])); // create a new contact with the content of the old foreach(array('id','modified','modifier','account_id') as $key) unset($content[$key]); - $content['owner'] = $this->prefs['add_default'] ? $this->prefs['add_default'] : $this->user; + $content['owner'] = $this->default_private ? $this->user.'p' : $this->default_addressbook; $content['creator'] = $this->user; $content['created'] = $this->now_su; $content['msg'] = lang('Contact copied');