Addressbook - make sure import target addressbook is valid, if not use personal addressbook.

This commit is contained in:
nathangray 2017-09-27 11:34:18 -06:00
parent a2df97005c
commit 6b71e997fe
2 changed files with 14 additions and 0 deletions

View File

@ -68,6 +68,16 @@ class addressbook_import_contacts_csv extends importexport_basic_import_csv {
$contact_owner = isset( $_definition->plugin_options['contact_owner'] ) ?
$_definition->plugin_options['contact_owner'] : $this->user;
// Check to make sure target addressbook is valid
if(!in_array($contact_owner, array_keys($this->bocontacts->get_addressbooks(Api\Acl::ADD))))
{
$this->warnings[0] = lang("Unable to import into %1, using %2",
$contact_owner . ' ('.Api\Accounts::username($record->owner) . ')',
Api\Accounts::username($this->user)
);
$contact_owner = 'personal';
}
// Import into importer's personal addressbook
if($contact_owner == 'personal')
{

View File

@ -120,6 +120,10 @@ class addressbook_wizard_import_contacts_csv extends importexport_wizard_basic_i
$bocontacts = new Api\Contacts();
$sel_options['contact_owner'] = array('personal' => lang("Importer's personal")) + $bocontacts->get_addressbooks(Acl::ADD);
if(!in_array($content['contact_owner'], $sel_options['contact_owner']))
{
$sel_options['contact_owner'][$content['contact_owner']] = lang("'%1' is not allowed ('%2')!", $content['contact_owner'], implode(',',array_keys($sel_options['contact_owner'])));
}
if(!in_array('owner', $content['field_mapping'])) {
$content['no_owner_map'] = true;
}