Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 85 additions & 20 deletions components/ILIAS/Mail/classes/class.ilMailFormGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -356,7 +360,7 @@ public function sendMessage(): void
ilUtil::securePlainString($value['m_subject']),
$value['m_message'],
$files,
$value['use_placeholders']
$value['use_placeholders'],
)
) {
$this->showSubmissionErrors($errors);
Expand Down Expand Up @@ -850,10 +854,10 @@ public function showForm(?Form $form = null): void
}

$this->tpl->parseCurrentBlock();
$this->addToolbarButtons();
if ($form === null) {
$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();
Expand Down Expand Up @@ -909,10 +913,14 @@ public function cancelMail(): void
$this->showForm();
}

protected function saveMailBeforeSearch(): void
protected function saveMailBeforeSearch(?array $input_results = null): void
{
$form = $this->buildForm()->withRequest($this->request);
$result = $form->getInputGroup()->getInputs()[0]->getInputs();
if (!$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();
Expand Down Expand Up @@ -1093,25 +1101,29 @@ protected function buildFormElements(?array $mail_data): array
$this->lng->txt('message_content')
)->withValue($mail_data['m_message'] ?? '');

$use_placeholders = $ff->hidden()->withValue('0');
$use_placeholder_value = $mail_data['use_placeholders'] ?? $this->mail_form_type === self::MAIL_FORM_TYPE_ROLE;
$mode = $use_placeholder_value ? self::MAIL_FORM_MODE_SERIAL_LETTER : self::MAIL_FORM_MODE_REGULAR_MAIL;
$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') . '<br />'
. sprintf($this->lng->txt('placeholders_advise'), '<br />')
)
;
$use_placeholders = $use_placeholders->withValue('1');
if ($mode === self::MAIL_FORM_MODE_SERIAL_LETTER) {
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') . '<br />'
. sprintf($this->lng->txt('placeholders_advise'), '<br />')
)
;
}
}
$use_placeholders = $use_placeholders->withAdditionalTransformation(
$this->refinery->kindlyTo()->bool()
);


if ($signal !== null) {
$m_subject = $m_subject->withAdditionalOnLoadCode(
function ($id) use ($signal) {
Expand Down Expand Up @@ -1211,14 +1223,14 @@ function (?array $v) {
];
}

protected function addToolbarButtons(): void
protected function addToolbarButtons(Form $form): void
{
$bf = $this->ui_factory->button();

$action = $this->ctrl->getFormAction($this, 'searchUsers');
$btn = $bf->standard(
$this->lng->txt('search_recipients'),
''
'',
)->withAdditionalOnLoadCode(
function ($id) use ($action) {
return "document.getElementById('{$id}').addEventListener('click', function (event) {
Expand Down Expand Up @@ -1297,5 +1309,58 @@ 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->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);
});"
);
}

public function toggleMailMode(): void
{
$form = $this->buildForm()->withRequest($this->request);

$mode = $this->getQueryParam('mail_form_mail_mode', $this->refinery->kindlyTo()->string(), self::MAIL_FORM_MODE_REGULAR_MAIL);
if (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');
}
$this->saveMailBeforeSearch($result ?? null);

$this->searchResults();
}
}
3 changes: 3 additions & 0 deletions lang/ilias_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -11630,6 +11630,7 @@ 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önlicher Mail und Serienmail umschalten
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
Expand Down Expand Up @@ -11772,6 +11773,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
Expand All @@ -11780,6 +11782,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
Expand Down
3 changes: 3 additions & 0 deletions lang/ilias_en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -11632,6 +11632,7 @@ 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 mail merge 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
Expand Down Expand Up @@ -11774,6 +11775,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#:#Regular 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.
Expand All @@ -11782,6 +11784,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
Expand Down