diff --git a/plugins/calendar/calendar.php b/plugins/calendar/calendar.php index 4dec7089..de4645ef 100644 --- a/plugins/calendar/calendar.php +++ b/plugins/calendar/calendar.php @@ -975,10 +975,18 @@ class calendar extends rcube_plugin if (!$err && $_FILES['_data']['tmp_name']) { $calendar = get_input_value('calendar', RCUBE_INPUT_GPC); - $events = $this->get_ical()->import_from_file($_FILES['_data']['tmp_name']); - - $count = $errors = 0; $rangestart = $_REQUEST['_range'] ? date_create("now -" . intval($_REQUEST['_range']) . " months") : 0; + $count = $errors = 0; + + try { + $events = $this->get_ical()->import_from_file($_FILES['_data']['tmp_name'], 'UTF-8', true); + } + catch (Exception $e) { + $errors = 1; + $msg = $e->getMessage(); + $events = array(); + } + foreach ($events as $event) { // TODO: correctly handle recurring events which start before $rangestart if ($event['end'] < $rangestart && (!$event['recurrence'] || ($event['recurrence']['until'] && $event['recurrence']['until'] < $rangestart))) @@ -1000,8 +1008,9 @@ class calendar extends rcube_plugin $this->rc->output->command('display_message', $this->gettext('importnone'), 'notice'); $this->rc->output->command('plugin.import_success', array('source' => $calendar)); } - else - $this->rc->output->command('display_message', $this->gettext('importerror'), 'error'); + else { + $this->rc->output->command('plugin.import_error', array('message' => $this->gettext('importerror') . ($msg ? ': ' . $msg : ''))); + } } else { if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) { @@ -1012,7 +1021,7 @@ class calendar extends rcube_plugin $msg = rcube_label('fileuploaderror'); } - $this->rc->output->command('display_message', $msg, 'error'); + $this->rc->output->command('plugin.import_error', array('message' => $msg)); $this->rc->output->command('plugin.unlock_saving', false); } diff --git a/plugins/calendar/calendar_ui.js b/plugins/calendar/calendar_ui.js index 81e350f0..d6272535 100644 --- a/plugins/calendar/calendar_ui.js +++ b/plugins/calendar/calendar_ui.js @@ -1963,10 +1963,17 @@ function rcube_calendar_ui(settings) if (form && form.elements._data.value) { rcmail.async_upload_form(form, 'import_events', function(e) { rcmail.set_busy(false, null, me.saving_lock); + $('.ui-dialog-buttonpane button', $dialog.parent()).button('enable'); + + // display error message if no sophisticated response from server arrived (e.g. iframe load error) + if (me.import_succeeded === null) + rcmail.display_message(rcmail.get_label('importerror', 'calendar'), 'error'); }); // display upload indicator + me.import_succeeded = null; me.saving_lock = rcmail.set_busy(true, 'uploading'); + $('.ui-dialog-buttonpane button', $dialog.parent()).button('disable'); } }; @@ -1981,6 +1988,7 @@ function rcube_calendar_ui(settings) closeOnEscape: false, title: rcmail.gettext('importevents', 'calendar'), close: function() { + $('.ui-dialog-buttonpane button', $dialog.parent()).button('enable'); $dialog.dialog("destroy").hide(); }, buttons: buttons, @@ -1992,6 +2000,7 @@ function rcube_calendar_ui(settings) // callback from server if import succeeded this.import_success = function(p) { + this.import_succeeded = true; $("#eventsimport:ui-dialog").dialog('close'); rcmail.set_busy(false, null, me.saving_lock); rcmail.gui_objects.importform.reset(); @@ -2000,6 +2009,13 @@ function rcube_calendar_ui(settings) this.refresh(p); }; + // callback from server to report errors on import + this.import_error = function(p) + { + this.import_succeeded = false; + rcmail.display_message(p.message || rcmail.get_label('importerror', 'calendar'), 'error'); + } + // show URL of the given calendar in a dialog box this.showurl = function(calendar) { @@ -2762,6 +2778,7 @@ window.rcmail && rcmail.addEventListener('init', function(evt) { rcmail.addEventListener('plugin.unlock_saving', function(p){ cal.unlock_saving(); }); rcmail.addEventListener('plugin.refresh_calendar', function(p){ cal.refresh(p); }); rcmail.addEventListener('plugin.import_success', function(p){ cal.import_success(p); }); + rcmail.addEventListener('plugin.import_error', function(p){ cal.import_error(p); }); // let's go var cal = new rcube_calendar_ui($.extend(rcmail.env.calendar_settings, rcmail.env.libcal_settings));