From befac35e0b993d9e79186bbb2eec2ba62f8cebeb Mon Sep 17 00:00:00 2001 From: nathangray Date: Tue, 23 Apr 2019 16:17:12 -0600 Subject: [PATCH] Add category override for addressbook vcard & infolog ical import --- .../class.addressbook_import_vcard.inc.php | 8 ++ ...ss.addressbook_wizard_import_vcard.inc.php | 9 ++- .../importexport_wizard_vcard_chooseowner.xet | 4 +- infolog/inc/class.infolog_ical.inc.php | 18 +++++ infolog/inc/class.infolog_import_ical.inc.php | 16 ++++ .../class.infolog_wizard_import_ical.inc.php | 79 +++++++++++++++++++ .../default/import.ical_conditions.xet | 17 ++++ 7 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 infolog/inc/class.infolog_wizard_import_ical.inc.php create mode 100644 infolog/templates/default/import.ical_conditions.xet diff --git a/addressbook/inc/class.addressbook_import_vcard.inc.php b/addressbook/inc/class.addressbook_import_vcard.inc.php index df7596b07c..7b866d1fa9 100644 --- a/addressbook/inc/class.addressbook_import_vcard.inc.php +++ b/addressbook/inc/class.addressbook_import_vcard.inc.php @@ -181,6 +181,14 @@ class addressbook_import_vcard implements importexport_iface_import_plugin { $record['owner'] = $this->user; } + // Check & apply value overrides + foreach((array)$this->definition->plugin_options['override_values'] as $field => $settings) + { + if($settings['value']) + { + $record[$field] = $settings['value']; + } + } if (is_array($record['cat_id'])) { $record['cat_id'] = implode(',',$this->bocontacts->find_or_add_categories($record['cat_id'], -1)); diff --git a/addressbook/inc/class.addressbook_wizard_import_vcard.inc.php b/addressbook/inc/class.addressbook_wizard_import_vcard.inc.php index 560f1640e3..277e978a83 100644 --- a/addressbook/inc/class.addressbook_wizard_import_vcard.inc.php +++ b/addressbook/inc/class.addressbook_wizard_import_vcard.inc.php @@ -93,7 +93,7 @@ class addressbook_wizard_import_vcard extends addressbook_import_vcard // init step60 else { - $content['msg'] = $this->steps['wizard_step60']; + $content['title'] = $this->steps['wizard_step60']; $content['step'] = 'wizard_step60'; if(!array_key_exists($content['contact_owner']) && $content['plugin_options']) { $content['contact_owner'] = $content['plugin_options']['contact_owner']; @@ -105,6 +105,13 @@ class addressbook_wizard_import_vcard extends addressbook_import_vcard $bocontacts = new Api\Contacts(); $sel_options['contact_owner'] = array('personal' => lang("Importer's personal")) + $bocontacts->get_addressbooks(Acl::ADD); + foreach(array('override_values') as $field) + { + if(!$content[$field] && array_key_exists($field, $content['plugin_options'])) + { + $content[$field] = $content['plugin_options'][$field]; + } + } $preserv = $content; unset ($preserv['button']); return 'addressbook.importexport_wizard_vcard_chooseowner'; diff --git a/addressbook/templates/default/importexport_wizard_vcard_chooseowner.xet b/addressbook/templates/default/importexport_wizard_vcard_chooseowner.xet index c12c50e6e6..9202645fde 100644 --- a/addressbook/templates/default/importexport_wizard_vcard_chooseowner.xet +++ b/addressbook/templates/default/importexport_wizard_vcard_chooseowner.xet @@ -9,7 +9,7 @@ - + @@ -17,7 +17,7 @@ - + diff --git a/infolog/inc/class.infolog_ical.inc.php b/infolog/inc/class.infolog_ical.inc.php index be83e4cb4f..b48288875d 100644 --- a/infolog/inc/class.infolog_ical.inc.php +++ b/infolog/inc/class.infolog_ical.inc.php @@ -87,6 +87,16 @@ class infolog_ical extends infolog_bo */ var $clientProperties; + /** + * Entry callback + * If set, this will be called on each discovered etry so it can be + * modified. Entry is passed by reference, return true to keep the event + * or false to skip it. + * + * @var callable + */ + var $entry_callback = null; + /** * Set Logging * @@ -532,6 +542,14 @@ class infolog_ical extends infolog_bo date_default_timezone_set($GLOBALS['egw_info']['server']['server_timezone']); } + if($this->entry_callback && is_callable($this->entry_callback)) + { + if(!call_user_func_array($this->entry_callback, array(&$taskData))) + { + // Callback cancelled entry + return false; + } + } if (!$taskData) return false; // keep the dates diff --git a/infolog/inc/class.infolog_import_ical.inc.php b/infolog/inc/class.infolog_import_ical.inc.php index 404baf1721..879a850598 100644 --- a/infolog/inc/class.infolog_import_ical.inc.php +++ b/infolog/inc/class.infolog_import_ical.inc.php @@ -94,6 +94,7 @@ class infolog_import_ical implements importexport_iface_import_plugin { @set_time_limit(0); // try switching execution time limit off $infolog_ical = new infolog_ical(); + $infolog_ical->entry_callback = array($this, 'entry_callback'); if (!$infolog_ical->importVTODO(stream_get_contents($_stream))) { $this->errors[] = lang('Error: importing the iCal'); @@ -107,6 +108,21 @@ class infolog_import_ical implements importexport_iface_import_plugin { return $success; } + /** + * Do some modification on each entry + */ + public function entry_callback(&$event) + { + // Check & apply value overrides + foreach((array)$this->definition->plugin_options['override_values'] as $field => $settings) + { + if($settings['value']) + { + $event[$field] = $settings['value']; + } + } + return true; + } /** * returns translated name of plugin diff --git a/infolog/inc/class.infolog_wizard_import_ical.inc.php b/infolog/inc/class.infolog_wizard_import_ical.inc.php new file mode 100644 index 0000000000..94b122826e --- /dev/null +++ b/infolog/inc/class.infolog_wizard_import_ical.inc.php @@ -0,0 +1,79 @@ + 'infolog.import.ical_conditions', + ); + /** + * constructor + */ + function __construct() + { + Api\Framework::includeJS('.','et2_widget_owner','calendar'); + Api\Framework::includeCSS('calendar','calendar'); + $this->steps = array( + 'wizard_step55' => lang('Edit conditions'), + ); + } + + // Conditions + function wizard_step55(&$content, &$sel_options, &$readonlys, &$preserv) + { + // return from step55 + if ($content['step'] == 'wizard_step55') + { + switch (array_search('pressed', $content['button'])) + { + case 'next': + return $GLOBALS['egw']->importexport_definitions_ui->get_step($content['step'],1); + case 'previous' : + return $GLOBALS['egw']->importexport_definitions_ui->get_step($content['step'],-1); + case 'finish': + return 'wizard_finish'; + default : + return $this->wizard_step55($content,$sel_options,$readonlys,$preserv); + } + } + // init step30 + else + { + $content['text'] = $this->steps['wizard_step55']; + $content['step'] = 'wizard_step55'; + foreach(array('override_values') as $field) + { + if(!$content[$field] && array_key_exists($field, $content['plugin_options'])) + { + $content[$field] = $content['plugin_options'][$field]; + } + } + $preserv = $content; + unset ($preserv['button']); + + // No real conditions, but we share a template + $content['no_conditions'] = true; + + return $this->step_templates[$content['step']]; + } + } +} diff --git a/infolog/templates/default/import.ical_conditions.xet b/infolog/templates/default/import.ical_conditions.xet new file mode 100644 index 0000000000..e60b2bf388 --- /dev/null +++ b/infolog/templates/default/import.ical_conditions.xet @@ -0,0 +1,17 @@ + + + + +