diff --git a/components/ILIAS/Mail/classes/class.ilMailFormGUI.php b/components/ILIAS/Mail/classes/class.ilMailFormGUI.php index 0249ebad6802..9ceb3599db7c 100755 --- a/components/ILIAS/Mail/classes/class.ilMailFormGUI.php +++ b/components/ILIAS/Mail/classes/class.ilMailFormGUI.php @@ -35,6 +35,8 @@ use ILIAS\Data\Clock\ClockFactory; use ILIAS\Data\Factory as DataFactory; use ILIAS\Mail\Folder\MailScheduleData; +use ILIAS\UI\URLBuilder; +use ILIAS\Data\URI; /** * @ilCtrl_Calls ilMailFormGUI: ilMailAttachmentGUI, ilMailSearchGUI, ilMailSearchCoursesGUI, ilMailSearchGroupsGUI, ilMailingListsGUI, ilMailFormUploadHandlerGUI @@ -53,6 +55,8 @@ class ilMailFormGUI final public const string MAIL_FORM_TYPE_FORWARD = 'forward'; final public const string MAIL_FORM_TYPE_DRAFT = 'draft'; final public const string MAIL_FORM_TYPE_OUTBOX = 'outbox'; + final public const string MAIL_FORM_MODE_REGULAR_MAIL = 'regular_mail'; + final public const string MAIL_FORM_MODE_SERIAL_LETTER = 'serial_letter'; private readonly ilGlobalTemplateInterface $tpl; private readonly ilCtrlInterface $ctrl; @@ -850,10 +854,10 @@ public function showForm(?Form $form = null): void } $this->tpl->parseCurrentBlock(); - $this->addToolbarButtons(); - if ($form === null) { - $form = $this->buildForm($mail_data); - } + + $form ??= $this->buildForm($mail_data); + $this->addToolbarButtons($form); + $this->tpl->setVariable('FORM', $this->ui_renderer->render($form)); $this->tpl->addJavaScript('assets/js/ilMailComposeFunctions.js'); $this->tpl->printToStdout(); @@ -909,14 +913,20 @@ public function cancelMail(): void $this->showForm(); } - protected function saveMailBeforeSearch(): void + /** + * @param array|null $input_results + */ + private function saveMailBeforeSearch(?array $input_results = null): void { - $form = $this->buildForm()->withRequest($this->request); - $result = $form->getInputGroup()->getInputs()[0]->getInputs(); + if (empty($input_results)) { + $form = $this->buildForm()->withRequest($this->request); + $result = $form->getInputGroup()->getInputs()[0]->getInputs(); + } else { + $result = $input_results; + } $resource_collection_id = null; - $attachments = $result['attachments']->getValue(); - if (count($attachments) > 0) { + if (!empty($result['attachments']->getValue())) { $files = $this->handleAttachments($result['attachments']->getValue()); $resource_collection_id = $this->getIdforCollection($files); } @@ -1025,14 +1035,17 @@ protected function buildFormElements(?array $mail_data): array $template_chb = null; $signal = null; + $use_placeholder_value = false; + $context = new ilMailTemplateGenericContext(); if (ilMailFormCall::getContextId()) { $context_id = ilMailFormCall::getContextId(); try { $context = ilMailTemplateContextService::getTemplateContextById($context_id); + $use_placeholder_value = true; $templates = $this->template_service->loadTemplatesForContextId($context->getId()); - if (count($templates) > 0) { + if (!empty($templates)) { $options = []; $tmpl_value = ''; @@ -1063,7 +1076,7 @@ protected function buildFormElements(?array $mail_data): array ->withValue($tmpl_value) ->withOnUpdate($signal); } - } catch (Exception $e) { + } catch (Exception) { ilLoggerFactory::getLogger('mail')->error(sprintf( '%s has been called with invalid context id: %s.', __METHOD__, @@ -1071,7 +1084,7 @@ protected function buildFormElements(?array $mail_data): array )); } } else { - $context = new ilMailTemplateGenericContext(); + $use_placeholder_value = $mail_data['use_placeholders'] ?? false; } $m_subject = $ff @@ -1093,21 +1106,25 @@ protected function buildFormElements(?array $mail_data): array $this->lng->txt('message_content') )->withValue($mail_data['m_message'] ?? ''); - $use_placeholders = $ff->hidden()->withValue('0'); + $use_placeholders = $ff->hidden()->withValue($use_placeholder_value ? '1' : '0'); + $placeholders = []; - foreach ($context->getPlaceholders() as $key => $value) { - $placeholders[$value['placeholder']] = $value['label']; - } - if (count($placeholders) > 0) { - $m_message = $m_message - ->withMustacheVariables( - $placeholders, - $this->lng->txt('mail_nacc_use_placeholder') . '
' - . sprintf($this->lng->txt('placeholders_advise'), '
') - ) - ; - $use_placeholders = $use_placeholders->withValue('1'); + $mode = $use_placeholder_value ? self::MAIL_FORM_MODE_SERIAL_LETTER : self::MAIL_FORM_MODE_REGULAR_MAIL; + if ($mode === self::MAIL_FORM_MODE_SERIAL_LETTER && $context) { + foreach ($context->getPlaceholders() as $value) { + $placeholders[$value['placeholder']] = $value['label']; + } + if (!empty($placeholders)) { + $m_message = $m_message + ->withMustacheVariables( + $placeholders, + $this->lng->txt('mail_nacc_use_placeholder') . '
' + . sprintf($this->lng->txt('placeholders_advise'), '
') + ) + ; + } } + $use_placeholders = $use_placeholders->withAdditionalTransformation( $this->refinery->kindlyTo()->bool() ); @@ -1199,8 +1216,8 @@ function (?array $v) { } $elements['use_schedule'] = $use_schedule_input; - $elements['use_placeholders'] = $use_placeholders; + $section = $ff->section( $elements, $this->lng->txt('compose') @@ -1211,7 +1228,7 @@ function (?array $v) { ]; } - protected function addToolbarButtons(): void + protected function addToolbarButtons(Form $form): void { $bf = $this->ui_factory->button(); @@ -1297,5 +1314,90 @@ function ($id) use ($action) { } ); $this->toolbar->addComponent($btn); + + $result = $form->getInputGroup()->getInputs()[0]->getInputs(); + $use_placeholders = (bool) $result['use_placeholders']->getValue(); + $action = $this->ctrl->getFormAction($this, 'toggleMailMode'); + $url_builder = new UrlBuilder(new URI(ILIAS_HTTP_PATH . '/' . $action)); + [$url_builder, $mail_mode_parameter] = $url_builder->acquireParameter(['mail', 'form'], 'mail_mode'); + + $btn = $this->ui_factory->viewControl()->mode( + [ + $this->lng->txt(self::MAIL_FORM_MODE_REGULAR_MAIL) => (string) $url_builder->withParameter( + $mail_mode_parameter, + self::MAIL_FORM_MODE_REGULAR_MAIL + )->buildURI(), + $this->lng->txt(self::MAIL_FORM_MODE_SERIAL_LETTER) => (string) $url_builder->withParameter( + $mail_mode_parameter, + self::MAIL_FORM_MODE_SERIAL_LETTER + )->buildURI(), + ], + 'mail_mode_switch_label' + )->withActive( + $this->lng->txt($use_placeholders ? self::MAIL_FORM_MODE_SERIAL_LETTER : self::MAIL_FORM_MODE_REGULAR_MAIL) + ); + $this->toolbar->addSeparator(); + $this->toolbar->addComponent($btn); + $this->tpl->addOnLoadCode( + "document.getElementById('{$this->toolbar->getId()}') + .querySelector('div[aria-label=\"" . $this->lng->txt('mail_mode_switch_label') . "\"]') + .querySelectorAll('button[data-action]').forEach(function(button) { + button.addEventListener('click', function(event) { + event.preventDefault(); + event.stopPropagation(); + event.stopImmediatePropagation(); + + let mailform = document.querySelector('form.c-form'); + let action = button.getAttribute('data-action'); + if (action && mailform) { + let submitBtn = mailform.querySelector('button[type=\"submit\"]'); + if (submitBtn) { + submitBtn.formAction = action; + mailform.requestSubmit(btn); + } else { + mailform.action = action; + mailform.submit(); + } + } + return false; + }, true); + });" + ); + } + + private function toggleMailMode(): never + { + $form = $this->buildForm()->withRequest($this->request); + + $mode = $this->getQueryParam( + 'mail_form_mail_mode', + $this->refinery->kindlyTo()->string(), + self::MAIL_FORM_MODE_REGULAR_MAIL + ); + + $result = null; + if (!ilMailFormCall::getContextId() && in_array( + $mode, + [self::MAIL_FORM_MODE_REGULAR_MAIL, self::MAIL_FORM_MODE_SERIAL_LETTER], + true + )) { + $result = $form->getInputGroup()->getInputs()[0]->getInputs(); + $result['use_placeholders'] = $result['use_placeholders']->withValue( + $mode === self::MAIL_FORM_MODE_SERIAL_LETTER ? '1' : '0' + ); + } elseif ($mode === self::MAIL_FORM_MODE_REGULAR_MAIL && ilMailFormCall::getContextId()) { + $this->tpl->setOnScreenMessage( + $this->tpl::MESSAGE_TYPE_INFO, + sprintf( + $this->lng->txt('mail_mode_switch_locked'), + $this->lng->txt('regular_mail') + ), + true + ); + } + + $this->saveMailBeforeSearch($result ?? null); + + $this->ctrl->redirect($this, 'searchResults'); } } diff --git a/lang/ilias_de.lang b/lang/ilias_de.lang index e3171cd20843..fc66885e3ce4 100644 --- a/lang/ilias_de.lang +++ b/lang/ilias_de.lang @@ -11630,6 +11630,8 @@ mail#:#mail_member_notification#:#Teilnehmerbenachrichtigung mail#:#mail_members_of_mailing_list#:#Mitglieder der Verteilerliste „%s“ mail#:#mail_members_search_continue#:#Weiter mail#:#mail_message_send#:#Die Mail wurde versandt. +mail#:#mail_mode_switch_label#:#Zwischen „Persönliche Mail” und „Serienbrief” umschalten +mail#:#mail_mode_switch_locked#:#Sie können nicht zu „%s” wechseln. mail#:#mail_move_error#:#Beim Versuch, Ihre E-Mail zu verschieben, ist ein Fehler aufgetreten. mail#:#mail_move_to#:#Verschieben nach: mail#:#mail_move_to_folder_btn_label#:#Mail verschieben @@ -11772,6 +11774,7 @@ mail#:#only_inbox_trash_info#:#Falls aktiviert, werden ausschließlich Mails gel mail#:#orphaned_mail_body#:#Es existieren alte oder verwaiste Mails in den folgenden Ordnern. Beachten Sie, dass diese Mails in kürze automatisch gelöscht werden. mail#:#orphaned_mail_subject#:#Benachrichtigung über alte Mails mail#:#placeholders_advise#:#Persönliche Platzhalter werden nur für Personen im „An”-Feld ersetzt. Personen im „CC”-Feld und „BCC”-Feld erhalten die Mail mit nicht-ersetzten Platzhaltern. +mail#:#regular_mail#:#Persönliche Mail mail#:#search_content#:#Suchergebnis mail#:#search_recipients#:#Personen suchen mail#:#second_email_missing_info#:#Auswahl nicht möglich, da keine zweite E-Mail-Adresse eingetragen wurde @@ -11780,6 +11783,7 @@ mail#:#send_mail_admins#:#Administration mail#:#send_mail_members#:#Mitglied mail#:#send_mail_to#:#Mail an mail#:#send_mail_tutors#:#Kursbetreuung +mail#:#serial_letter#:#Serienbrief mail#:#show_mail_settings#:#Einstellungen anzeigen mail#:#show_mail_settings_info#:#Aktiviert die Anzeige der Mail-Einstellungen im Bereich 'Einstellungen' oder 'Mail'. Benutzer können die Mail-Einstellungen nur ändern, wenn die Konfiguration des Benutzer-Profils dies erlaubt. Wenn Benutzer nicht berechtigt sind, die Mail-Einstellung ihrer Profils zu ändern, dann gelten die globalen Einstellungen. Dies gilt auch dann, wenn Benutzer in der Vergangenheit die Berechtigung zum Ändern der Mail-Einstellungen hatten und persönliche Einstellungen vorgenommen haben. mail#:#system_notification_installation_changed_by#:#Geändert durch diff --git a/lang/ilias_en.lang b/lang/ilias_en.lang index 375d1ee00f6b..a512af4ff51c 100644 --- a/lang/ilias_en.lang +++ b/lang/ilias_en.lang @@ -11632,6 +11632,8 @@ mail#:#mail_member_notification#:#Participant Notification mail#:#mail_members_of_mailing_list#:#Members of Mailing List "%s" mail#:#mail_members_search_continue#:#Continue mail#:#mail_message_send#:#Message sent. +mail#:#mail_mode_switch_label#:#Switch between „Personal Mail” and „Serial Letter” mode +mail#:#mail_mode_switch_locked#:#You cannot switch to „%s” mode. mail#:#mail_move_error#:#An error occurred while trying to move your mail. mail#:#mail_move_to#:#Move to: mail#:#mail_move_to_folder_btn_label#:#Move Mail @@ -11774,6 +11776,7 @@ mail#:#only_inbox_trash_info#:#Only delete e-mails that are located in the Inbox mail#:#orphaned_mail_body#:#Your mailbox contains the following old or orphaned mails. Please note that these mails will soon be automatically deleted. mail#:#orphaned_mail_subject#:#Notification of old mails mail#:#placeholders_advise#:#Personal placeholders are only replaced with user-specific information for recipients listed in the ‘To’ field.%s Personal placeholders for recipients listed in the CC and BCC fields are NOT replaced with user-specific information and instead show up as placeholders. +mail#:#regular_mail#:#Personal Mail mail#:#search_content#:#Search Result mail#:#search_recipients#:#Look up Users mail#:#second_email_missing_info#:#Selection not possible because no second e-mail address has been entered. @@ -11782,6 +11785,7 @@ mail#:#send_mail_admins#:#All Administrators mail#:#send_mail_members#:#All Members mail#:#send_mail_to#:#Mail to mail#:#send_mail_tutors#:#All Tutors +mail#:#serial_letter#:#Serial Letter mail#:#show_mail_settings#:#Show Mail Settings mail#:#show_mail_settings_info#:#Enable individual users to alter their mail settings, thereby overriding the global mail settings that would otherwise apply to them. ‘Mail Settings’ are accessible via their ‘Personal Settings’ or ‘Communication > Mail’. Note: In order for users to be allowed to change their individual mail settings and thereby override the global settings, this needs to be set in the 'Standard Fields' section of the global user account administration settings. If users do not have the permission to change these profile settings, the global default is applied even if users were able to and did change their personal mail settings in the past. mail#:#system_notification_installation_changed_by#:#Changed by