diff --git a/actions/wabue/appointment/import.php b/actions/wabue/appointment/import.php
index 8652060..7e60881 100644
--- a/actions/wabue/appointment/import.php
+++ b/actions/wabue/appointment/import.php
@@ -38,6 +38,7 @@
"Abend",
];
+$check_only = get_input('check', 'yes') == 'yes';
$file = elgg_get_uploaded_file('import');
$spreadsheet = IOFactory::load($file);
@@ -63,6 +64,7 @@ function parse_input_date(string $value): ?array
];
}
$errors = [];
+$events_imported = 0;
foreach ($spreadsheet->getWorksheetIterator() as $worksheet) {
$current_user = elgg_get_logged_in_user_entity();
@@ -77,7 +79,7 @@ function parse_input_date(string $value): ?array
if (!$headersValid) {
foreach ($headers as $index => $header) {
if (!($worksheet->getCellByColumnAndRow($index + 1, $row->getRowIndex())->getValue() == $header)) {
- $errors[] = "Worksheet " . $worksheet->getTitle() . "doesn't match header validation. Skipping";
+ $errors[] = "Worksheet " . $worksheet->getTitle() . " doesn't match header validation. Skipping";
continue 3;
}
}
@@ -148,7 +150,7 @@ function parse_input_date(string $value): ?array
$errors[] = "Did not catch all required event cells. Skipping row: $row_text";
continue;
}
- elgg_call(ELGG_IGNORE_ACCESS, function () use ($value, $fromDate, $toDate, $organizer, $event, $current_user, $type) {
+ elgg_call(ELGG_IGNORE_ACCESS, function () use ($value, $fromDate, $toDate, $organizer, $event, $current_user, $type, $check_only, $events_imported) {
set_input('schedule_type', 'fixed');
set_input('start_date', $fromDate['date']);
set_input('end_date', $toDate['date']);
@@ -161,24 +163,26 @@ function parse_input_date(string $value): ?array
set_input('description', $event['Wer']);
set_input('venue', $event['Wo']);
set_input('region', $type);
- $session = elgg()->session;
- $session->setLoggedInUser($organizer);
- event_calendar_set_event_from_form(0, 0);
- $session->setLoggedInUser($current_user);
+ if (!$check_only) {
+ $session = elgg()->session;
+ $session->setLoggedInUser($organizer);
+ event_calendar_set_event_from_form(0, 0);
+ $session->setLoggedInUser($current_user);
+ }
});
-
+ $events_imported++;
}
}
if (count($errors) > 0) {
return elgg_error_response(
- elgg_echo('wabue:appointment:import:error'),
- elgg_generate_url('view:uploadappointments', ['errors' => substr(join('
', $errors),0, 2000)])
+ elgg_echo('wabue:appointment:import:error', [$events_imported]),
+ elgg_generate_url('view:uploadappointments', ['errors' => substr(join('
', $errors),0, 2000), 'events_imported' => $events_imported])
);
} else {
return elgg_ok_response(
'',
- elgg_echo('wabue:appointment:import:successful'),
+ elgg_echo('wabue:appointment:import:successful', [$events_imported]),
elgg_generate_url('view:uploadappointments')
);
}
diff --git a/languages/de.php b/languages/de.php
index c3ffe61..9d2fdb0 100644
--- a/languages/de.php
+++ b/languages/de.php
@@ -157,9 +157,12 @@
'wabue:settings:appointmentusers:label' => 'Benutzer zum Terminupload',
'wabue:settings:appointmentusers:help' => 'Benutzer*innen, die den Excel-Terminupload nutzen können. Ein Benutzername pro Zeile.',
'wabue:appointments:gatekeeper:error' => 'Du bist nicht für diesen Service berechtigt',
- 'wabue:appointment:import:error' => 'Es traten Fehler beim Importieren der Termine auf',
- 'wabue:appointment:import:successful' => 'Termine erfolgreich hochgeladen',
+ 'wabue:appointment:import:error' => 'Es traten Fehler beim Importieren der Termine auf. %d Termine waren erfolgreich',
+ 'wabue:appointment:import:successful' => '%d Termine erfolgreich hochgeladen',
'wabue:appointment:import:file:label' => 'Termin-Datei',
'wabue:appointment:import:file:help' => 'Eine Excel-Datei mit Arbeitsblättern mit den zu importierenden Terminen gemäß der Kopfzeilen Was, Von Wann, Bis Wann, Wer, Wo, Art and Ansprechpartner',
'wabue:appointment:import:submit' => 'Importieren',
+
+ 'wabue:appointment:import:check:label' => 'Nur prüfen',
+ 'wabue:appointment:import:check:help' => 'Termine nicht importieren, Importdatei nur prüfen',
];
diff --git a/languages/en.php b/languages/en.php
index 283e707..2b3ce97 100644
--- a/languages/en.php
+++ b/languages/en.php
@@ -9,10 +9,12 @@
'wabue:settings:appointmentusers:label' => 'Users that can upload appointments',
'wabue:settings:appointmentusers:help' => 'Usernames that can use the excel upload for appointments. One user per line',
'wabue:appointments:gatekeeper:error' => 'You are not allowed to use this service',
- 'wabue:appointment:import:error' => 'There were errors loading the appointments',
- 'wabue:appointment:import:successful' => 'Successfully loaded the appointments',
+ 'wabue:appointment:import:error' => 'There were errors loading the appointments. %d appointments loaded successfully',
+ 'wabue:appointment:import:successful' => 'Successfully loaded %d appointments',
'wabue:appointment:import:file:label' => 'Event-File',
'wabue:appointment:import:file:help' => 'An Excel file containing worksheets that hold the appointments to be imported using the headers Was, Von Wann, Bis Wann, Wer, Wo, Art and Ansprechpartner',
'wabue:appointment:import:submit' => 'Import',
+ 'wabue:appointment:import:check:label' => 'Only check import',
+ 'wabue:appointment:import:check:help' => "Don't import events, only validate import",
];
diff --git a/views/default/forms/wabue/appointment/import.php b/views/default/forms/wabue/appointment/import.php
index de2692e..75b60f2 100644
--- a/views/default/forms/wabue/appointment/import.php
+++ b/views/default/forms/wabue/appointment/import.php
@@ -5,9 +5,10 @@
use Wabue\Membership\Tools;
$errors = get_input('errors','');
+$events_imported = get_input('events_imported', 0);
if (!empty($errors)) {
- echo elgg_view_module('error', elgg_echo('wabue:appointment:import:error'), $errors);
+ echo elgg_view_message('error', $errors);
}
echo elgg_view_field([
@@ -18,6 +19,16 @@
'required' => true,
]);
+echo elgg_view_field([
+ '#type' => 'checkbox',
+ '#label' => elgg_echo('wabue:appointment:import:check:label'),
+ '#help' => elgg_echo('wabue:appointment:import:check:help'),
+ 'name' => 'check',
+ 'value' => 'yes',
+ 'checked' => true,
+ 'switch' => true
+]);
+
elgg_set_form_footer(
elgg_view_field([
'#type' => 'submit',