diff --git a/addressbook/inc/class.addressbook_ui.inc.php b/addressbook/inc/class.addressbook_ui.inc.php index e9ae2e98ee..d085ef73fc 100644 --- a/addressbook/inc/class.addressbook_ui.inc.php +++ b/addressbook/inc/class.addressbook_ui.inc.php @@ -1379,11 +1379,18 @@ class addressbook_ui extends addressbook_bo $GLOBALS['egw_info']['user']['account_firstname'],$GLOBALS['egw_info']['user']['account_lastname']), $content['id'])); // create a new contact with the content of the old - foreach(array('id','modified','modifier','account_id','uid','cat_id','etag') as $key) + $copy_fields = unserialize($this->config['copy_fields']); + foreach($content as $key => $value) { - unset($content[$key]); + if(!in_array($key, $copy_fields) || in_array($key, array('etag'))) + { + unset($content[$key]); + } + } + if(!isset($content['owner'])) + { + $this->default_private ? $this->user.'p' : $this->default_addressbook; } - $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'); diff --git a/addressbook/inc/hook_config.inc.php b/addressbook/inc/hook_config.inc.php index f51df0f88b..1449ca0c37 100644 --- a/addressbook/inc/hook_config.inc.php +++ b/addressbook/inc/hook_config.inc.php @@ -110,3 +110,52 @@ function org_fileds_to_update($config) return html::checkbox_multiselect('newsettings[org_fileds_to_update]', $config['org_fileds_to_update'] ? $config['org_fileds_to_update'] : $bocontacts->org_fields,$fields,true,'',4); } + +/** + * Hook to get a multiselect box with all fieleds of fields used for copying for addressbook config + * + * @param array $config + * @return string html + */ +function copy_fields($config) +{ + $bocontacts = new addressbook_bo(); + $supported_fields = $bocontacts->get_fields('supported',null,0); // fields supported by the backend (ldap schemas!) + // get the list of account fields + $fields = array(); + foreach($bocontacts->contact_fields as $field => $label) + { + // some fields the user should never be allowed to copy or are coverted by an other attribute (n_fn for all n_*) + if (!in_array($field,array('id','tid','created','creator','modified','modifier','n_prefix','n_given','n_middle','n_family','n_suffix', 'account_id', 'uid'))) + { + $fields[$field] = $label; + } + } + $fields['link_to'] = 'Links'; + + if ($config['account_repository'] != 'ldap') // no custom-fields in ldap + { + foreach(config::get_customfields('addressbook') as $name => $data) + { + $fields['#'.$name] = $data['label']; + } + } + $default = array( + 'company', + 'department', + 'adr_one_street', + 'adr_one_street2', + 'adr_one_locality', + 'adr_one_region', + 'adr_one_postalcode', + 'adr_one_countryname', + 'email', + 'url', + 'tel_work', + 'cat_id' + ); + return html::checkbox_multiselect('newsettings[copy_fields]', + $config['copy_fields'] ? $config['copy_fields'] : $default, + $fields,true,'',4 + ); +} diff --git a/addressbook/templates/default/config.tpl b/addressbook/templates/default/config.tpl index 05fdfb41a8..2ec2f9be8c 100644 --- a/addressbook/templates/default/config.tpl +++ b/addressbook/templates/default/config.tpl @@ -54,6 +54,12 @@ +  {lang_Fields_to_copy_when_copying_an_address?} + + {hook_copy_fields} + + +  {lang_Use_an_extra_tab_for_private_custom_fields?}