Add ability to choose target calendar & addressbook when importing ical/vcard

This commit is contained in:
nathan 2023-01-19 15:48:35 -07:00
parent 802a312839
commit 48008f4e96
6 changed files with 48 additions and 53 deletions

View File

@ -91,20 +91,20 @@ class addressbook_import_vcard implements importexport_iface_import_plugin {
$this->definition = $_definition; $this->definition = $_definition;
// user, is admin ? // 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']; $this->user = $GLOBALS['egw_info']['user']['account_id'];
// set contact owner // set contact owner
$contact_owner = isset( $_definition->plugin_options['contact_owner'] ) ? $contact_owner = isset($_definition->plugin_options['contact_owner']) ?
$_definition->plugin_options['contact_owner'] : $this->user; $_definition->plugin_options['contact_owner'] : $this->user;
// Import into importer's personal addressbook // Import into importer's personal addressbook
if($contact_owner == 'personal') if($contact_owner == 'personal')
{ {
$contact_owner = $this->user; $contact_owner = $this->user;
} }
// dry run? // 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 // Needed for categories to work right
$GLOBALS['egw_info']['flags']['currentapp'] = 'addressbook'; $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) public function get_options_etpl(importexport_definition &$definition=null)
{ {
$contacts = new EGroupware\Api\Contacts();
$charset = $definition->plugin_options['charset']; $charset = $definition->plugin_options['charset'];
if($charset == 'user') $charset = $GLOBALS['egw_info']['user']['preferences']['addressbook']['vcard_charset']; if($charset == 'user') $charset = $GLOBALS['egw_info']['user']['preferences']['addressbook']['vcard_charset'];
return array( return array(
'name' => 'addressbook.import_vcard', 'name' => 'addressbook.import_vcard',
'content' => array( 'content' => array(
'file_type' => 'vcard,ical,vcf', 'file_type' => 'vcard,ical,vcf',
'charset' => $charset 'charset' => $charset,
'contact_owner' => $definition->plugin_options['contact_owner'] == 'personal' ?
$GLOBALS['egw_info']['user']['account_id'] :
$definition->plugin_options['contact_owner']
), ),
'sel_options' => array( '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() 'preserv' => array()
); );

View File

@ -2,20 +2,14 @@
<!DOCTYPE overlay PUBLIC "-//EGroupware GmbH//eTemplate 2.0//EN" "https://www.egroupware.org/etemplate2.0.dtd"> <!DOCTYPE overlay PUBLIC "-//EGroupware GmbH//eTemplate 2.0//EN" "https://www.egroupware.org/etemplate2.0.dtd">
<overlay> <overlay>
<template id="addressbook.import_vcard" template="" lang="" group="0" version="1.9.001"> <template id="addressbook.import_vcard" template="" lang="" group="0" version="1.9.001">
<grid> <et2-vbox>
<columns> <et2-select id="contact_owner" label="Import into" class="et2-label-fixed"></et2-select>
<column/> <et2-select class="et2-label-fixed" id="charset" noLang="1" label="Charset of file"></et2-select>
<column width="180px"/> </et2-vbox>
</columns> <styles>
<rows> .et2-label-fixed {
<row> --label-width: 180px;
<et2-description value="Charset of file"></et2-description> }
<et2-select class="width180" id="charset" noLang="1"></et2-select> </styles>
</row> </template>
</rows>
</grid>
<styles>
.width180 select { width:150px;}
</styles>
</template>
</overlay> </overlay>

View File

@ -134,7 +134,7 @@ class calendar_import_ical implements importexport_iface_import_plugin {
} }
// switch off notifications by default // switch off notifications by default
$plugin_options = $_definition->plugin_options; $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; $plugin_options['no_notification'] = true;
$_definition->plugin_options = $plugin_options; $_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) // Set owner, if not set will be null (current user)
$owner = $plugin_options['cal_owner']; $owner = $plugin_options['cal_owner'];
if(is_array($owner))
{
$owner = array_pop($owner);
}
// Purge // Purge
if($plugin_options['empty_before_import']) 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_past = new Api\DateTime();
$remove_future = new Api\DateTime(); $remove_future = new Api\DateTime();
$plugin_options = array_merge(array('remove_past' => 100, 'remove_future' => 365), $plugin_options); $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( $this->purge_calendar(
$owner, $owner,
@ -295,15 +299,16 @@ class calendar_import_ical implements importexport_iface_import_plugin {
public function get_options_etpl(importexport_definition &$definition=null) public function get_options_etpl(importexport_definition &$definition=null)
{ {
return array( return array(
'name' => 'addressbook.import_vcard', 'name' => 'calendar.import_ical',
'content' => array( 'content' => array(
'file_type' => 'ical', '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( 'sel_options' => array(
'charset' => Api\Translation::get_installed_charsets() 'charset' => Api\Translation::get_installed_charsets()
), ),
'preserv' => array() 'preserv' => array()
); );
} }

View File

@ -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 html link to the current record calendar en HTML link to the current record
ical calendar en iCal ical calendar en iCal
ical / rfc2445 calendar en iCal / rfc2445 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 export calendar en iCal export
ical file calendar en iCal file ical file calendar en iCal file
ical import calendar en iCal import ical import calendar en iCal import

View File

@ -2,7 +2,7 @@
<!DOCTYPE overlay PUBLIC "-//EGroupware GmbH//eTemplate 2.0//EN" "https://www.egroupware.org/etemplate2.0.dtd"> <!DOCTYPE overlay PUBLIC "-//EGroupware GmbH//eTemplate 2.0//EN" "https://www.egroupware.org/etemplate2.0.dtd">
<overlay> <overlay>
<template id="calendar.import_csv" template="" lang="" group="0" version="1.9.001"> <template id="calendar.import_csv" template="" lang="" group="0" version="1.9.001">
<calendar-owner id="owner" label="Import into" emptyLabel="From file" multiple="false" <calendar-owner id="cal_owner" label="Import into" emptyLabel="From file" multiple="false"
class="et2-label-fixed"></calendar-owner> class="et2-label-fixed"></calendar-owner>
<template id="importexport.import_dialog.csv"/> <template id="importexport.import_dialog.csv"/>
</template> </template>

View File

@ -2,20 +2,10 @@
<!DOCTYPE overlay PUBLIC "-//EGroupware GmbH//eTemplate 2.0//EN" "https://www.egroupware.org/etemplate2.0.dtd"> <!DOCTYPE overlay PUBLIC "-//EGroupware GmbH//eTemplate 2.0//EN" "https://www.egroupware.org/etemplate2.0.dtd">
<overlay> <overlay>
<template id="calendar.import_ical" template="" lang="" group="0" version="1.9.001"> <template id="calendar.import_ical" template="" lang="" group="0" version="1.9.001">
<grid> <et2-select class="et2-label-fixed" id="charset" noLang="1" label="Charset of file"></et2-select>
<columns> <calendar-owner id="cal_owner" label="Import into" emptyLabel="From file" multiple="false"
<column/> class="et2-label-fixed"
<column width="180px"/> helpText="iCal cannot change the owner of an existing event. This applies to new events only.">
</columns> </calendar-owner>
<rows> </template>
<row>
<et2-description value="Charset of file"></et2-description>
<et2-select class="width180" id="charset" noLang="1"></et2-select>
</row>
</rows>
</grid>
<styles>
.width180 select { width:150px;}
</styles>
</template>
</overlay> </overlay>