From 48008f4e964fd19ce2bdc01a4c94bb28b8cb4edb Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 19 Jan 2023 15:48:35 -0700 Subject: [PATCH] Add ability to choose target calendar & addressbook when importing ical/vcard --- .../class.addressbook_import_vcard.inc.php | 31 +++++++++++-------- .../templates/default/import_vcard.xet | 26 ++++++---------- .../inc/class.calendar_import_ical.inc.php | 19 +++++++----- calendar/lang/egw_en.lang | 1 + calendar/templates/default/import_csv.xet | 2 +- calendar/templates/default/import_ical.xet | 22 ++++--------- 6 files changed, 48 insertions(+), 53 deletions(-) diff --git a/addressbook/inc/class.addressbook_import_vcard.inc.php b/addressbook/inc/class.addressbook_import_vcard.inc.php index 7b866d1fa9..bf18dd4382 100644 --- a/addressbook/inc/class.addressbook_import_vcard.inc.php +++ b/addressbook/inc/class.addressbook_import_vcard.inc.php @@ -91,20 +91,20 @@ class addressbook_import_vcard implements importexport_iface_import_plugin { $this->definition = $_definition; // user, is admin ? - $this->is_admin = isset( $GLOBALS['egw_info']['user']['apps']['admin'] ) && $GLOBALS['egw_info']['user']['apps']['admin']; + $this->is_admin = isset($GLOBALS['egw_info']['user']['apps']['admin']) && $GLOBALS['egw_info']['user']['apps']['admin']; $this->user = $GLOBALS['egw_info']['user']['account_id']; - // set contact owner - $contact_owner = isset( $_definition->plugin_options['contact_owner'] ) ? - $_definition->plugin_options['contact_owner'] : $this->user; - // Import into importer's personal addressbook - if($contact_owner == 'personal') - { - $contact_owner = $this->user; - } + // set contact owner + $contact_owner = isset($_definition->plugin_options['contact_owner']) ? + $_definition->plugin_options['contact_owner'] : $this->user; + // Import into importer's personal addressbook + if($contact_owner == 'personal') + { + $contact_owner = $this->user; + } // dry run? - $this->dry_run = isset( $_definition->plugin_options['dry_run'] ) ? $_definition->plugin_options['dry_run'] : false; + $this->dry_run = isset($_definition->plugin_options['dry_run']) ? $_definition->plugin_options['dry_run'] : false; // Needed for categories to work right $GLOBALS['egw_info']['flags']['currentapp'] = 'addressbook'; @@ -352,16 +352,21 @@ class addressbook_import_vcard implements importexport_iface_import_plugin { */ public function get_options_etpl(importexport_definition &$definition=null) { + $contacts = new EGroupware\Api\Contacts(); $charset = $definition->plugin_options['charset']; if($charset == 'user') $charset = $GLOBALS['egw_info']['user']['preferences']['addressbook']['vcard_charset']; return array( 'name' => 'addressbook.import_vcard', 'content' => array( - 'file_type' => 'vcard,ical,vcf', - 'charset' => $charset + 'file_type' => 'vcard,ical,vcf', + 'charset' => $charset, + 'contact_owner' => $definition->plugin_options['contact_owner'] == 'personal' ? + $GLOBALS['egw_info']['user']['account_id'] : + $definition->plugin_options['contact_owner'] ), 'sel_options' => array( - 'charset' => Api\Translation::get_installed_charsets() + 'charset' => Api\Translation::get_installed_charsets(), + 'contact_owner' => $contacts->get_addressbooks(Api\Acl::ADD) ), 'preserv' => array() ); diff --git a/addressbook/templates/default/import_vcard.xet b/addressbook/templates/default/import_vcard.xet index eb972a5a30..7518c8783c 100644 --- a/addressbook/templates/default/import_vcard.xet +++ b/addressbook/templates/default/import_vcard.xet @@ -2,20 +2,14 @@ + + + + + + .et2-label-fixed { + --label-width: 180px; + } + + \ No newline at end of file diff --git a/calendar/inc/class.calendar_import_ical.inc.php b/calendar/inc/class.calendar_import_ical.inc.php index a844f82365..a00e45112d 100644 --- a/calendar/inc/class.calendar_import_ical.inc.php +++ b/calendar/inc/class.calendar_import_ical.inc.php @@ -134,7 +134,7 @@ class calendar_import_ical implements importexport_iface_import_plugin { } // switch off notifications by default $plugin_options = $_definition->plugin_options; - if (!array_key_exists('no_notification', $_definition->plugin_options)) + if(!array_key_exists('no_notification', $_definition->plugin_options)) { $plugin_options['no_notification'] = true; $_definition->plugin_options = $plugin_options; @@ -142,6 +142,10 @@ class calendar_import_ical implements importexport_iface_import_plugin { // Set owner, if not set will be null (current user) $owner = $plugin_options['cal_owner']; + if(is_array($owner)) + { + $owner = array_pop($owner); + } // Purge if($plugin_options['empty_before_import']) @@ -149,9 +153,9 @@ class calendar_import_ical implements importexport_iface_import_plugin { $remove_past = new Api\DateTime(); $remove_future = new Api\DateTime(); $plugin_options = array_merge(array('remove_past' => 100, 'remove_future' => 365), $plugin_options); - foreach(array('remove_past','remove_future') as $date) + foreach(array('remove_past', 'remove_future') as $date) { - ${$date}->add( (($date == 'remove_past' ? -1 : 1) * (int)$plugin_options[$date]) . ' days'); + ${$date}->add((($date == 'remove_past' ? -1 : 1) * (int)$plugin_options[$date]) . ' days'); } $this->purge_calendar( $owner, @@ -295,15 +299,16 @@ class calendar_import_ical implements importexport_iface_import_plugin { public function get_options_etpl(importexport_definition &$definition=null) { return array( - 'name' => 'addressbook.import_vcard', - 'content' => array( + 'name' => 'calendar.import_ical', + 'content' => array( 'file_type' => 'ical', - 'charset' => $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'] + 'charset' => $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'], + 'cal_owner' => $definition->plugin_options['cal_owner'] ?? $GLOBALS['egw_info']['user']['account_id'] ), 'sel_options' => array( 'charset' => Api\Translation::get_installed_charsets() ), - 'preserv' => array() + 'preserv' => array() ); } diff --git a/calendar/lang/egw_en.lang b/calendar/lang/egw_en.lang index 2c5c8905e8..4b835a2de8 100644 --- a/calendar/lang/egw_en.lang +++ b/calendar/lang/egw_en.lang @@ -307,6 +307,7 @@ how much entries to skip calendar en How much entries to skip? html link to the current record calendar en HTML link to the current record ical calendar en iCal ical / rfc2445 calendar en iCal / rfc2445 +iCal cannot change the owner of an existing event. This applies to new events only. calendar en iCal cannot change the owner of an existing event. This applies to new events only. ical export calendar en iCal export ical file calendar en iCal file ical import calendar en iCal import diff --git a/calendar/templates/default/import_csv.xet b/calendar/templates/default/import_csv.xet index 528db24ce0..7c277e94d4 100644 --- a/calendar/templates/default/import_csv.xet +++ b/calendar/templates/default/import_csv.xet @@ -2,7 +2,7 @@ \ No newline at end of file