ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjMailGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26
31{
32 private const string SETTINGS_SUB_TAB_ID_GENERAL = 'settings_general';
33 private const string SETTINGS_SUB_TAB_ID_EXTERNAL = 'settings_external';
34 private const string PASSWORD_PLACE_HOLDER = '***********************';
35
36 private readonly ilTabsGUI $tabs;
39
40 public function __construct($a_data, int $a_id, bool $a_call_by_reference)
41 {
42 global $DIC;
43 $this->type = 'mail';
44 parent::__construct($a_data, $a_id, $a_call_by_reference, false);
45
46 $this->tabs = $DIC->tabs();
47 $this->mustache_factory = $DIC->mail()->mustacheFactory();
48 $this->mail_signature_service = $DIC->mail()->signature();
49
50 $this->lng->loadLanguageModule('mail');
51 }
52
53 public function executeCommand(): void
54 {
55 $next_class = $this->ctrl->getNextClass($this) ?? '';
56 $cmd = $this->ctrl->getCmd();
57 $this->prepareOutput();
58
59 switch (strtolower($next_class)) {
60 case strtolower(ilPermissionGUI::class):
61 $perm_gui = new ilPermissionGUI($this);
62 $this->ctrl->forwardCommand($perm_gui);
63 break;
64
65 case strtolower(ilMailTemplateGUI::class):
66 if (!$this->isViewAllowed()) {
67 $this->ilias->raiseError(
68 $this->lng->txt('msg_no_perm_write'),
69 $this->ilias->error_obj->WARNING
70 );
71 }
72
73 $this->ctrl->forwardCommand(new ilMailTemplateGUI($this->object));
74 break;
75
76 default:
77 if (!$cmd) {
78 $cmd = 'view';
79 }
80 $cmd .= 'Object';
81 $this->$cmd();
82 break;
83 }
84 }
85
86 private function isEditingAllowed(): bool
87 {
88 return $this->rbac_system->checkAccess('write', $this->object->getRefId());
89 }
90
91 private function isViewAllowed(): bool
92 {
93 return $this->rbac_system->checkAccess('read', $this->object->getRefId());
94 }
95
96 private function isPermissionChangeAllowed(): bool
97 {
98 return $this->rbac_system->checkAccess('edit_permission', $this->object->getRefId());
99 }
100
101 public function getAdminTabs(): void
102 {
103 $this->getTabs();
104 }
105
106 protected function getTabs(): void
107 {
108 if ($this->isViewAllowed()) {
109 $this->tabs->addTarget(
110 'settings',
111 $this->ctrl->getLinkTarget($this, 'view'),
112 [
113 'view',
114 'save',
115 '',
116 'showExternalSettingsForm',
117 'saveExternalSettingsForm',
118 'sendTestUserMail',
119 'sendTestSystemMail',
120 ]
121 );
122 }
123
124 if ($this->isViewAllowed()) {
125 $this->tabs->addTarget(
126 'mail_templates',
127 $this->ctrl->getLinkTargetByClass(ilMailTemplateGUI::class, 'showTemplates'),
128 '',
129 ilMailTemplateGUI::class
130 );
131 }
132
133 if ($this->isPermissionChangeAllowed()) {
134 $this->tabs->addTarget(
135 'perm_settings',
136 $this->ctrl->getLinkTargetByClass([static::class, ilPermissionGUI::class], 'perm'),
137 ['perm', 'info', 'owner'],
138 ilPermissionGUI::class
139 );
140 }
141 }
142
143 protected function buildSettingsSubTabs(string $active_sub_tab): void
144 {
145 if ($this->isViewAllowed()) {
146 $this->tabs->addSubTab(
147 self::SETTINGS_SUB_TAB_ID_GENERAL,
148 $this->lng->txt('mail_settings_general_tab'),
149 $this->ctrl->getLinkTarget($this, 'view')
150 );
151
152 if ($this->settings->get('mail_allow_external', '0')) {
153 $this->tabs->addSubTab(
154 self::SETTINGS_SUB_TAB_ID_EXTERNAL,
155 $this->lng->txt('mail_settings_external_tab'),
156 $this->ctrl->getLinkTarget($this, 'showExternalSettingsForm')
157 );
158 }
159
160 $this->tabs->activateSubTab($active_sub_tab);
161 }
162 }
163
164 public function viewObject(): void
165 {
167 }
168
169 protected function showGeneralSettingsForm(?ilPropertyFormGUI $form = null): void
170 {
171 if (!$this->isViewAllowed()) {
172 $this->ilias->raiseError($this->lng->txt('msg_no_perm_write'), $this->ilias->error_obj->WARNING);
173 }
174
175 $this->buildSettingsSubTabs(self::SETTINGS_SUB_TAB_ID_GENERAL);
176
177 if ($form === null) {
178 $form = $this->getGeneralSettingsForm();
179 $this->populateGeneralSettingsForm($form);
180 }
181
182 $this->tpl->setContent($form->getHTML());
183 }
184
186 {
187 $form = new ilPropertyFormGUI();
188
189 $form->setFormAction($this->ctrl->getFormAction($this, 'save'));
190 $form->setTitle($this->lng->txt('general_settings'));
191
192 $cb = new ilCheckboxInputGUI($this->lng->txt('mail_allow_external'), 'mail_allow_external');
193 $cb->setInfo($this->lng->txt('mail_allow_external_info'));
194 $cb->setValue('1');
195 $cb->setDisabled(!$this->isEditingAllowed());
196 $form->addItem($cb);
197
198 $incoming_mail_gui = new ilIncomingMailInputGUI(
199 $this->lng->txt('mail_incoming'),
200 'incoming_type'
201 );
202 $incoming_mail_gui->setDisabled(!$this->isEditingAllowed());
203 $this->ctrl->setParameterByClass(ilObjUserFolderGUI::class, 'ref_id', USER_FOLDER_ID);
204 $this->ctrl->clearParametersByClass(ilObjUserFolderGUI::class);
205 $form->addItem($incoming_mail_gui);
206
207 $show_mail_settings_gui = new ilCheckboxInputGUI(
208 $this->lng->txt('show_mail_settings'),
209 'show_mail_settings'
210 );
211 $show_mail_settings_gui->setInfo($this->lng->txt('show_mail_settings_info'));
212 $show_mail_settings_gui->setValue('1');
213 $form->addItem($show_mail_settings_gui);
214
215 $ti = new ilNumberInputGUI($this->lng->txt('mail_maxsize_attach'), 'mail_maxsize_attach');
216 $ti->setSuffix($this->lng->txt('kb'));
217 $ti->setInfo($this->lng->txt('mail_max_size_attachments_total'));
218 $ti->setMaxLength(10);
219 $ti->setSize(10);
220 $ti->setDisabled(!$this->isEditingAllowed());
221 $form->addItem($ti);
222
223 $mn = new ilFormSectionHeaderGUI();
224 $mn->setTitle($this->lng->txt('mail_member_notification'));
225 $form->addItem($mn);
226
227 $cron_mail = new ilSelectInputGUI(
228 $this->lng->txt('cron_mail_notification'),
229 'mail_notification'
230 );
231 $cron_options = [
232 0 => $this->lng->txt('cron_mail_notification_never'),
233 1 => $this->lng->txt('cron_mail_notification_cron'),
234 ];
235 $cron_mail->setOptions($cron_options);
236 $cron_mail->setInfo(sprintf(
237 $this->lng->txt('cron_mail_notification_desc'),
238 $this->lng->txt('mail_allow_external')
239 ));
240 $cron_mail->setDisabled(!$this->isEditingAllowed());
241 $form->addItem($cron_mail);
242
245 $form,
246 $this
247 );
248
249 $mn = new ilFormSectionHeaderGUI();
250 $mn->setTitle($this->lng->txt('mail_auto_responder'));
251 $form->addItem($mn);
252
253 $input = new ilNumberInputGUI($this->lng->txt('mail_auto_responder_idle_time'), 'mail_auto_responder_idle_time');
254 $input->setMinValue(1);
255 $input->allowDecimals(false);
256 $input->setInfo($this->lng->txt('mail_auto_responder_idle_time_info'));
257 $input->setSuffix($this->lng->txt('days'));
258 $input->setDisabled(!$this->isEditingAllowed());
259 $input->setSize(5);
260 $form->addItem($input);
261
262 if ($this->isEditingAllowed()) {
263 $form->addCommandButton('save', $this->lng->txt('save'));
264 }
265
266 return $form;
267 }
268
269 protected function populateGeneralSettingsForm(ilPropertyFormGUI $form): void
270 {
271 $form->setValuesByArray([
272 'mail_allow_external' => (bool) $this->settings->get('mail_allow_external', '0'),
273 'incoming_type' => (string) $this->settings->get('mail_incoming_mail', '0'),
274 'mail_address_option' => $this->settings->get('mail_address_option', '') !== '' ?
275 $this->settings->get('mail_address_option') :
277 'mail_address_option_both' => $this->settings->get('mail_address_option', '') !== '' ?
278 $this->settings->get('mail_address_option') :
280 'show_mail_settings' => (bool) $this->settings->get('show_mail_settings', '1'),
281 'mail_maxsize_attach' => $this->settings->get('mail_maxsize_attach', ''),
282 'mail_notification' => $this->settings->get('mail_notification', ''),
283 'mail_auto_responder_idle_time' => is_numeric($this->settings->get('mail_auto_responder_idle_time', (string) AutoresponderService::AUTO_RESPONDER_DEFAULT_IDLE_TIME)) ?
284 (string) $this->settings->get('mail_auto_responder_idle_time', '3') :
285 '',
286 ]);
287 }
288
289 public function saveObject(): void
290 {
291 if (!$this->isEditingAllowed()) {
292 $this->ilias->raiseError($this->lng->txt('msg_no_perm_write'), $this->ilias->error_obj->WARNING);
293 }
294
295 $form = $this->getGeneralSettingsForm();
296 if ($form->checkInput()) {
297 $incoming_type = (int) $form->getInput('incoming_type');
298
299 $mail_address_option = ilMailOptions::FIRST_EMAIL;
300 if ($incoming_type === ilMailOptions::INCOMING_EMAIL) {
301 $mail_address_option = (int) $form->getInput('mail_address_option');
302 } elseif ($incoming_type === ilMailOptions::INCOMING_BOTH) {
303 $mail_address_option = (int) $form->getInput('mail_address_option_both');
304 }
305
306 $this->settings->set('mail_allow_external', (string) ((int) $form->getInput('mail_allow_external')));
307 $this->settings->set('mail_incoming_mail', (string) $incoming_type);
308 $this->settings->set('show_mail_settings', (string) ((int) $form->getInput('show_mail_settings')));
309 $this->settings->set('mail_address_option', (string) $mail_address_option);
310 $this->settings->set('mail_maxsize_attach', (string) $form->getInput('mail_maxsize_attach'));
311 $this->settings->set('mail_notification', (string) ((int) $form->getInput('mail_notification')));
312 $this->settings->set('mail_auto_responder_idle_time', (string) $form->getInput('mail_auto_responder_idle_time'));
313
314 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
315 $this->ctrl->redirect($this);
316 }
317
318 $form->setValuesByPost();
319 $this->showGeneralSettingsForm($form);
320 }
321
322 protected function showExternalSettingsFormObject(?ilPropertyFormGUI $form = null): void
323 {
324 if (!$this->isViewAllowed()) {
325 $this->ilias->raiseError($this->lng->txt('msg_no_perm_write'), $this->ilias->error_obj->WARNING);
326 }
327
328 $this->buildSettingsSubTabs(self::SETTINGS_SUB_TAB_ID_EXTERNAL);
329
330 if ($form === null) {
331 $form = $this->getExternalSettingsForm();
332 $this->populateExternalSettingsForm($form);
333 }
334
335 if ($this->user->getEmail() !== '') {
336 $this->toolbar->addComponent($this->ui_factory->button()->standard(
337 $this->lng->txt('mail_external_send_test_usr'),
338 $this->ctrl->getLinkTarget($this, 'sendTestUserMail')
339 ));
340 $this->toolbar->addComponent($this->ui_factory->button()->standard(
341 $this->lng->txt('mail_external_send_test_sys'),
342 $this->ctrl->getLinkTarget($this, 'sendTestSystemMail')
343 ));
344 }
345
346 $this->tpl->setContent($form->getHTML());
347 }
348
349 protected function sendTestUserMailObject(): void
350 {
351 $this->sendTestMail(true);
352 }
353
354 protected function sendTestSystemMailObject(): void
355 {
356 $this->sendTestMail();
357 }
358
359 protected function sendTestMail(bool $is_manual_mail = false): void
360 {
361 if (!$this->isViewAllowed()) {
362 $this->ilias->raiseError($this->lng->txt('msg_no_perm_write'), $this->ilias->error_obj->WARNING);
363 }
364
365 if ($this->user->getEmail() === '') {
367 return;
368 }
369
370 if ($is_manual_mail) {
371 $mail = new ilMail($this->user->getId());
372 } else {
373 $mail = new ilMail(ANONYMOUS_USER_ID);
374 }
375
376 $mail->setSaveInSentbox(false);
377 $mail->appendInstallationSignature(!$is_manual_mail);
378
379 $lng_variable_prefix = 'sys';
380 if ($is_manual_mail) {
381 $lng_variable_prefix = 'usr';
382 }
383
384 $mail->enqueue(
385 $this->user->getEmail(),
386 '',
387 '',
388 $this->lng->txt('mail_email_' . $lng_variable_prefix . '_subject'),
389 $this->lng->txt('mail_email_' . $lng_variable_prefix . '_body'),
390 []
391 );
392
393 $this->tpl->setOnScreenMessage('success', $this->lng->txt('mail_external_test_sent'));
395 }
396
398 {
399 $form = new ilPropertyFormGUI();
400
401 $form->setFormAction($this->ctrl->getFormAction($this, 'saveExternalSettingsForm'));
402 $form->setTitle($this->lng->txt('mail_settings_external_frm_head'));
403
404 $smtp = new ilCheckboxInputGUI($this->lng->txt('mail_smtp_status'), 'mail_smtp_status');
405 $smtp->setInfo($this->lng->txt('mail_smtp_status_info'));
406 $smtp->setValue('1');
407 $smtp->setDisabled(!$this->isEditingAllowed());
408 $form->addItem($smtp);
409
410 $host = new ilTextInputGUI($this->lng->txt('mail_smtp_host'), 'mail_smtp_host');
411 $host->setInfo($this->lng->txt('mail_smtp_host_info'));
412 $host->setRequired(true);
413 $host->setDisabled(!$this->isEditingAllowed());
414 $smtp->addSubItem($host);
415
416 $port = new ilNumberInputGUI($this->lng->txt('mail_smtp_port'), 'mail_smtp_port');
417 $port->setInfo($this->lng->txt('mail_smtp_port_info'));
418 $port->allowDecimals(false);
419 $port->setMinValue(0);
420 $port->setMinValue(0);
421 $port->setRequired(true);
422 $port->setDisabled(!$this->isEditingAllowed());
423 $smtp->addSubItem($port);
424
425 $encryption = new ilSelectInputGUI(
426 $this->lng->txt('mail_smtp_encryption'),
427 'mail_smtp_encryption'
428 );
429 $encryption_options = [
430 '' => $this->lng->txt('please_choose'),
431 'tls' => $this->lng->txt('mail_smtp_encryption_tls'),
432 'ssl' => $this->lng->txt('mail_smtp_encryption_ssl'),
433 ];
434
435 $encryption->setOptions($encryption_options);
436 $encryption->setDisabled(!$this->isEditingAllowed());
437 $smtp->addSubItem($encryption);
438
439 $user = new ilTextInputGUI($this->lng->txt('mail_smtp_user'), 'mail_smtp_user');
440 $user->setDisabled(!$this->isEditingAllowed());
441 $user->setDisableHtmlAutoComplete(true);
442 $smtp->addSubItem($user);
443
444 $password = new ilPasswordInputGUI(
445 $this->lng->txt('mail_smtp_password'),
446 'mail_smtp_password'
447 );
448 $password->setRetype(false);
449 $password->setSkipSyntaxCheck(true);
450 $password->setDisabled(!$this->isEditingAllowed());
451 $password->setDisableHtmlAutoComplete(true);
452 $smtp->addSubItem($password);
453
454 $pre = new ilTextInputGUI($this->lng->txt('mail_subject_prefix'), 'mail_subject_prefix');
455 $pre->setSize(12);
456 $pre->setMaxLength(32);
457 $pre->setInfo($this->lng->txt('mail_subject_prefix_info'));
458 $pre->setDisabled(!$this->isEditingAllowed());
459 $form->addItem($pre);
460
461 $send_html = new ilCheckboxInputGUI($this->lng->txt('mail_send_html'), 'mail_send_html');
462 $send_html->setInfo($this->lng->txt('mail_send_html_info'));
463 $send_html->setValue('1');
464 $send_html->setDisabled(!$this->isEditingAllowed());
465 $form->addItem($send_html);
466
467 $sh = new ilFormSectionHeaderGUI();
468 $sh->setTitle($this->lng->txt('mail_settings_user_frm_head'));
469 $form->addItem($sh);
470
471 $user_from_address = new ilEMailInputGUI(
472 $this->lng->txt('mail_system_usr_from_addr'),
473 'mail_system_usr_from_addr'
474 );
475 $user_from_address->setInfo($this->lng->txt('mail_system_usr_from_addr_info'));
476 $user_from_address->setRequired(true);
477 $user_from_address->setDisabled(!$this->isEditingAllowed());
478 $form->addItem($user_from_address);
479
480 $use_global_reply_to_address = new ilCheckboxInputGUI(
481 $this->lng->txt('mail_use_global_reply_to_addr'),
482 'use_global_reply_to_addr'
483 );
484 $use_global_reply_to_address->setInfo($this->lng->txt('mail_use_global_reply_to_addr_info'));
485 $use_global_reply_to_address->setValue('1');
486 $use_global_reply_to_address->setDisabled(!$this->isEditingAllowed());
487 $form->addItem($use_global_reply_to_address);
488 $global_reply_to = new ilEMailInputGUI(
489 $this->lng->txt('mail_global_reply_to_addr'),
490 'global_reply_to_addr'
491 );
492 $global_reply_to->setInfo($this->lng->txt('mail_global_reply_to_addr_info'));
493 $global_reply_to->setRequired(true);
494 $global_reply_to->setDisabled(!$this->isEditingAllowed());
495 $use_global_reply_to_address->addSubItem($global_reply_to);
496
497 $user_from_name = new ilTextInputGUI(
498 $this->lng->txt('mail_system_usr_from_name'),
499 'mail_system_usr_from_name'
500 );
501 $user_from_name->setInfo($this->lng->txt('mail_system_usr_from_name_info'));
502 $user_from_name->setRequired(true);
503 $user_from_name->setDisabled(!$this->isEditingAllowed());
504 $form->addItem($user_from_name);
505
506 $user_envelope_from_addr = new ilEMailInputGUI(
507 $this->lng->txt('mail_system_usr_env_from_addr'),
508 'mail_system_usr_env_from_addr'
509 );
510 $user_envelope_from_addr->setInfo($this->lng->txt('mail_system_usr_env_from_addr_info'));
511 $user_envelope_from_addr->setDisabled(!$this->isEditingAllowed());
512 $form->addItem($user_envelope_from_addr);
513
514 [$user_signature_inputs, $installation_signature_inputs] = array_map(
515 fn(Signature $signature): array => $this->buildSignaturePlaceholderInputs($signature),
517 );
518 foreach ($user_signature_inputs as $user_signature_input) {
519 $form->addItem($user_signature_input);
520 }
521
522 $sh = new ilFormSectionHeaderGUI();
523 $sh->setTitle($this->lng->txt('mail_settings_system_frm_head'));
524 $form->addItem($sh);
525
526 $system_from_addr = new ilEMailInputGUI(
527 $this->lng->txt('mail_system_sys_from_addr'),
528 'mail_system_sys_from_addr'
529 );
530 $system_from_addr->setInfo($this->lng->txt('mail_system_sys_from_addr_info'));
531 $system_from_addr->setRequired(true);
532 $system_from_addr->setDisabled(!$this->isEditingAllowed());
533 $form->addItem($system_from_addr);
534
535 $system_from_name = new ilTextInputGUI(
536 $this->lng->txt('mail_system_sys_from_name'),
537 'mail_system_sys_from_name'
538 );
539 $system_from_name->setRequired(true);
540 $system_from_name->setDisabled(!$this->isEditingAllowed());
541 $form->addItem($system_from_name);
542
543 $system_reply_to_addr = new ilEMailInputGUI(
544 $this->lng->txt('mail_system_sys_reply_to_addr'),
545 'mail_system_sys_reply_to_addr'
546 );
547 $system_reply_to_addr->setRequired(true);
548 $system_reply_to_addr->setDisabled(!$this->isEditingAllowed());
549 $form->addItem($system_reply_to_addr);
550
551 $system_return_path = new ilEMailInputGUI(
552 $this->lng->txt('mail_system_sys_env_from_addr'),
553 'mail_system_sys_env_from_addr'
554 );
555 $system_return_path->setInfo($this->lng->txt('mail_system_sys_env_from_addr_info'));
556 $system_return_path->setDisabled(!$this->isEditingAllowed());
557 $form->addItem($system_return_path);
558
559 foreach ($installation_signature_inputs as $installation_signature_input) {
560 $form->addItem($installation_signature_input);
561 }
562
563 if ($this->isEditingAllowed()) {
564 $form->addCommandButton('saveExternalSettingsForm', $this->lng->txt('save'));
565 }
566
567 return $form;
568 }
569
573 private function buildSignaturePlaceholderInputs(Signature $signature): array
574 {
575 $signature_input = new ilTextAreaInputGUI(
576 $this->lng->txt($signature->getPersistenceIdentifier()),
577 $signature->getPersistenceIdentifier()
578 );
579 $signature_input->setRows(8);
580 $signature_input->setDisabled(!$this->isEditingAllowed());
581
582 $placeholder_input = new ilManualPlaceholderInputGUI(
583 $this->lng->txt('mail_form_placeholders_label'),
584 'm_placeholders',
585 $signature->getPersistenceIdentifier(),
586 );
587 $placeholder_input->setDisabled(!$this->isEditingAllowed());
588
589 $placeholder = $this->mail_signature_service->getPlaceholder();
590 do {
591 if ($signature->supports($placeholder)) {
592 $placeholder_input->addPlaceholder($placeholder->getId(), $placeholder->getLabel());
593 }
594 } while ($placeholder = $placeholder->getNext());
595
596 return [$signature_input, $placeholder_input];
597 }
598
599 protected function populateExternalSettingsForm(ilPropertyFormGUI $form): void
600 {
601 $subject_prefix = $this->settings->get('mail_subject_prefix');
602 if ($subject_prefix === null) {
603 $subject_prefix = ilMimeMail::MAIL_SUBJECT_PREFIX;
604 }
605
606 [$user_signature, $installation_signature] = $this->getAvailableSignatures();
607
608 $form->setValuesByArray([
609 'mail_smtp_status' => (bool) $this->settings->get('mail_smtp_status', '0'),
610 'mail_smtp_host' => $this->settings->get('mail_smtp_host', ''),
611 'mail_smtp_port' => $this->settings->get('mail_smtp_port', ''),
612 'mail_smtp_user' => $this->settings->get('mail_smtp_user', ''),
613 'mail_smtp_password' => $this->settings->get('mail_smtp_password') !== '' ?
614 self::PASSWORD_PLACE_HOLDER :
615 '',
616 'mail_smtp_encryption' => $this->settings->get('mail_smtp_encryption', ''),
617 'mail_subject_prefix' => $subject_prefix,
618 'mail_send_html' => (bool) $this->settings->get('mail_send_html', '0'),
619 'mail_system_usr_from_addr' => $this->settings->get('mail_system_usr_from_addr', ''),
620 'mail_system_usr_from_name' => $this->settings->get('mail_system_usr_from_name', ''),
621 'mail_system_usr_env_from_addr' => $this->settings->get('mail_system_usr_env_from_addr', ''),
622 'mail_system_sys_from_addr' => $this->settings->get('mail_system_sys_from_addr', ''),
623 'mail_system_sys_from_name' => $this->settings->get('mail_system_sys_from_name', ''),
624 $user_signature->getPersistenceIdentifier() => $this->settings->get($user_signature->getPersistenceIdentifier(), ''),
625 'mail_system_sys_reply_to_addr' => $this->settings->get('mail_system_sys_reply_to_addr', ''),
626 'mail_system_sys_env_from_addr' => $this->settings->get('mail_system_sys_env_from_addr', ''),
627 $installation_signature->getPersistenceIdentifier() => $this->settings->get($installation_signature->getPersistenceIdentifier(), ''),
628 'use_global_reply_to_addr' => (bool) $this->settings->get('use_global_reply_to_addr', '0'),
629 'global_reply_to_addr' => $this->settings->get('global_reply_to_addr', ''),
630 ]);
631 }
632
633 protected function saveExternalSettingsFormObject(): void
634 {
635 if (!$this->isEditingAllowed()) {
636 $this->ilias->raiseError($this->lng->txt('msg_no_perm_write'), $this->ilias->error_obj->WARNING);
637 }
638
639 $form = $this->getExternalSettingsForm();
640 $is_form_valid = $form->checkInput();
641
642 if (!$is_form_valid) {
643 $form->setValuesByPost();
644 $this->showExternalSettingsFormObject($form);
645 return;
646 }
647
648 $is_smtp_enabled = (bool) $form->getInput('mail_smtp_status');
649 if ($is_smtp_enabled && $form->getInput('mail_smtp_user') &&
650 !$form->getInput('mail_smtp_password')
651 ) {
652 $form->getItemByPostVar('mail_smtp_password')->setRequired(true);
653 $form->getItemByPostVar('mail_smtp_password')
654 ->setAlert($this->lng->txt('mail_smtp_password_req'));
655 $form->setValuesByPost();
656 $this->showExternalSettingsFormObject($form);
657 return;
658 }
659
660 // If all forms in ILIAS use the UI/KS forms (here and in Services/Mail), we should move this to a proper constraint/trafo
661 $is_valid_template_syntax = $this->refinery->custom()->constraint(function ($value): bool {
662 try {
663 $this->mustache_factory->getBasicEngine()->render((string) $value, []);
664 return true;
665 } catch (Exception) {
666 return false;
667 }
668 }, $this->lng->txt('mail_template_invalid_tpl_syntax'));
669
670 $valid_templates = true;
671 $availabe_signatures = array_map(
672 static fn(Signature $signature): string => $signature->getPersistenceIdentifier(),
673 $this->getAvailableSignatures()
674 );
675 foreach (
676 ['mail_system_usr_from_name', ...$availabe_signatures] as $template
677 ) {
678 try {
679 $is_valid_template_syntax->check((string) $form->getInput($template));
680 } catch (Exception) {
681 $form->getItemByPostVar($template)->setAlert(
682 $is_valid_template_syntax->problemWith((string) $form->getInput($template))
683 );
684 $valid_templates = false;
685 }
686 }
687 if (!$valid_templates) {
688 $form->setValuesByPost();
689 $this->showExternalSettingsFormObject($form);
690 return;
691 }
692
693 $this->settings->set('mail_smtp_status', (string) ((int) $form->getInput('mail_smtp_status')));
694 $this->settings->set('mail_smtp_host', (string) $form->getInput('mail_smtp_host'));
695 $this->settings->set('mail_smtp_port', (string) ((int) $form->getInput('mail_smtp_port')));
696 $this->settings->set('mail_smtp_user', (string) $form->getInput('mail_smtp_user'));
697 if ($form->getInput('mail_smtp_password') !== self::PASSWORD_PLACE_HOLDER) {
698 $this->settings->set('mail_smtp_password', (string) $form->getInput('mail_smtp_password'));
699 }
700 $this->settings->set('mail_smtp_encryption', (string) $form->getInput('mail_smtp_encryption'));
701 $this->settings->set('mail_send_html', (string) $form->getInput('mail_send_html'));
702 $this->settings->set('mail_subject_prefix', (string) $form->getInput('mail_subject_prefix'));
703 $this->settings->set('mail_system_usr_from_addr', (string) $form->getInput('mail_system_usr_from_addr'));
704 $this->settings->set('mail_system_usr_from_name', (string) $form->getInput('mail_system_usr_from_name'));
705 $this->settings->set(
706 'mail_system_usr_env_from_addr',
707 (string) $form->getInput('mail_system_usr_env_from_addr')
708 );
709 $this->settings->set(
710 'mail_system_sys_from_addr',
711 (string) $form->getInput('mail_system_sys_from_addr')
712 );
713 $this->settings->set('mail_system_sys_from_name', (string) $form->getInput('mail_system_sys_from_name'));
714 $this->settings->set(
715 'mail_system_sys_reply_to_addr',
716 (string) $form->getInput('mail_system_sys_reply_to_addr')
717 );
718 $this->settings->set(
719 'mail_system_sys_env_from_addr',
720 (string) $form->getInput('mail_system_sys_env_from_addr')
721 );
722 $this->settings->set('use_global_reply_to_addr', (string) ((int) $form->getInput('use_global_reply_to_addr')));
723 $this->settings->set('global_reply_to_addr', (string) $form->getInput('global_reply_to_addr'));
724
725 foreach ($availabe_signatures as $availabe_signature) {
726 $this->settings->set(
727 $availabe_signature,
728 (string) $form->getInput($availabe_signature)
729 );
730 }
731
732 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
733 $this->ctrl->redirect($this, 'showExternalSettingsForm');
734 }
735
736 public static function _goto(string $target): void
737 {
738 global $DIC;
739 $main_tpl = $DIC->ui()->mainTemplate();
740
741 $mail = new ilMail($DIC->user()->getId());
742
743 if ($DIC->rbac()->system()->checkAccess('internal_mail', $mail->getMailObjectReferenceId())) {
744 $DIC->ctrl()->redirectToURL('ilias.php?baseClass=ilMailGUI');
745 } elseif ($DIC->access()->checkAccess('read', '', ROOT_FOLDER_ID)) {
746 $main_tpl->setOnScreenMessage('failure', sprintf(
747 $DIC->language()->txt('msg_no_perm_read_item'),
749 ), true);
750
751 $DIC->ctrl()->setTargetScript('ilias.php');
752 $DIC->ctrl()->setParameterByClass(ilRepositoryGUI::class, 'ref_id', ROOT_FOLDER_ID);
753 $DIC->ctrl()->redirectByClass(ilRepositoryGUI::class);
754 }
755
756 $DIC['ilErr']->raiseError($DIC->language()->txt('msg_no_perm_read'), $DIC['ilErr']->FATAL);
757 }
758
762 private function getAvailableSignatures(): array
763 {
764 return [
765 new MailUserSignature($this->settings),
767 ];
768 }
769}
static addFieldsToForm(int $a_form_id, ilPropertyFormGUI $a_form, ilObjectGUI $a_parent_gui)
This class represents a checkbox property in a property form.
This class represents a email property in a property form.
This class represents a section header in a property form.
final const int INCOMING_BOTH
final const int FIRST_EMAIL
final const int INCOMING_EMAIL
@ilCtrl_isCalledBy ilMailTemplateGUI: ilObjMailGUI
final const string MAIL_SUBJECT_PREFIX
This class represents a number property in a property form.
@ilCtrl_Calls ilObjMailGUI: ilPermissionGUI
viewObject()
viewObject container presentation for "administration -> repository, trash, permissions"
readonly ilMustacheFactory $mustache_factory
populateGeneralSettingsForm(ilPropertyFormGUI $form)
getAdminTabs()
administration tabs show only permissions and trash folder
const string SETTINGS_SUB_TAB_ID_EXTERNAL
__construct($a_data, int $a_id, bool $a_call_by_reference)
readonly ilTabsGUI $tabs
static _goto(string $target)
sendTestMail(bool $is_manual_mail=false)
getTabs()
@abstract overwrite in derived GUI class of your object type
const string PASSWORD_PLACE_HOLDER
readonly MailSignatureService $mail_signature_service
buildSettingsSubTabs(string $active_sub_tab)
buildSignaturePlaceholderInputs(Signature $signature)
showGeneralSettingsForm(?ilPropertyFormGUI $form=null)
const string SETTINGS_SUB_TAB_ID_GENERAL
populateExternalSettingsForm(ilPropertyFormGUI $form)
showExternalSettingsFormObject(?ilPropertyFormGUI $form=null)
Class ilObjectGUI Basic methods of all Output classes.
prepareOutput(bool $show_sub_objects=true)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
This class represents a password property in a property form.
This class represents a property form user interface.
setValuesByArray(array $a_values, bool $a_restrict_to_value_keys=false)
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a text area property in a property form.
This class represents a text property in a property form.
const USER_FOLDER_ID
Definition: constants.php:33
const ANONYMOUS_USER_ID
Definition: constants.php:27
const ROOT_FOLDER_ID
Definition: constants.php:32
supports(Placeholder $placeholder)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ilObjForumAdministration.
global $DIC
Definition: shib_login.php:26