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;
// 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()
);

View File

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

View File

@ -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()
);
}

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
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

View File

@ -2,7 +2,7 @@
<!DOCTYPE overlay PUBLIC "-//EGroupware GmbH//eTemplate 2.0//EN" "https://www.egroupware.org/etemplate2.0.dtd">
<overlay>
<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>
<template id="importexport.import_dialog.csv"/>
</template>

View File

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