19declare(strict_types=1);
59 $this->tpl =
$tpl ??
$DIC->ui()->mainTemplate();
61 $this->
lng = $lng ??
$DIC->language();
69 $this->service = $template_service ??
$DIC->mail()->textTemplates();
71 $this->
lng->loadLanguageModule(
'meta');
76 return $this->rbacsystem->checkAccess(
'write', $this->parent_object->getRefId());
93 $cmd = $this->
ctrl->getCmd();
94 if (!$cmd || !method_exists($this, $cmd .
'Command')) {
95 $cmd =
'showTemplates';
97 $verified_command = $cmd .
'Command';
99 $this->$verified_command();
104 $action = $this->
http->wrapper()->query()->retrieve(
105 'mail_template_table_action',
106 $this->
refinery->kindlyTo()->string()
114 default => $this->
ctrl->redirect($this,
'showTemplates'),
121 if (count($contexts) <= 1) {
122 $this->tpl->setOnScreenMessage(
123 $this->tpl::MESSAGE_TYPE_FAILURE,
124 $this->
lng->txt(
'mail_template_no_context_available')
128 $this->ui_factory->button()->standard(
129 $this->lng->txt(
'mail_new_template'),
130 $this->ctrl->getLinkTarget($this,
'showInsertTemplateForm')
135 $table_uri = (
new DataFactory())->uri(
136 ILIAS_HTTP_PATH .
'/'
137 . $this->
ctrl->getLinkTarget($this,
'executeTableAction')
141 $this->
http->request(),
146 !$this->isEditingAllowed()
149 $this->tpl->setContent($this->ui_renderer->render($tbl->getComponent()));
155 $this->
error->raiseError($this->
lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
167 if (
$form->
getInput(
'context') === $generic_context->getId()) {
169 $this->
lng->txt(
'mail_template_no_valid_context')
177 $this->service->createNewTemplate(
185 $this->tpl->setOnScreenMessage(
186 $this->tpl::MESSAGE_TYPE_SUCCESS,
187 $this->
lng->txt(
'saved_successfully'),
190 $this->
ctrl->redirect($this,
'showTemplates');
191 }
catch (\
ILIAS\
Mail\Templates\TemplateSubjectSyntaxException) {
193 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_FAILURE, $this->
lng->txt(
'form_input_not_valid'));
194 }
catch (\
ILIAS\
Mail\Templates\TemplateMessageSyntaxException) {
196 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_FAILURE, $this->
lng->txt(
'form_input_not_valid'));
197 }
catch (Exception) {
199 $this->
lng->txt(
'mail_template_no_valid_context')
201 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_FAILURE, $this->
lng->txt(
'form_input_not_valid'));
220 $this->
error->raiseError($this->
lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
224 if ($this->
http->wrapper()->post()->has(
'tpl_id')) {
225 $template_id = $this->
http->wrapper()->post()->retrieve(
'tpl_id', $this->
refinery->kindlyTo()->int());
228 if (!is_numeric($template_id) || $template_id < 1) {
229 $this->tpl->setOnScreenMessage(
230 $this->tpl::MESSAGE_TYPE_FAILURE,
231 $this->
lng->txt(
'mail_template_missing_id')
246 if (
$form->
getInput(
'context') === $generic_context->getId()) {
248 $this->
lng->txt(
'mail_template_no_valid_context')
256 $this->service->modifyExistingTemplate(
265 $this->tpl->setOnScreenMessage(
266 $this->tpl::MESSAGE_TYPE_SUCCESS,
267 $this->
lng->txt(
'saved_successfully'),
270 $this->
ctrl->redirect($this,
'showTemplates');
271 }
catch (OutOfBoundsException) {
272 $this->tpl->setOnScreenMessage(
273 $this->tpl::MESSAGE_TYPE_FAILURE,
274 $this->
lng->txt(
'mail_template_missing_id')
276 }
catch (\
ILIAS\
Mail\Templates\TemplateSubjectSyntaxException) {
278 }
catch (\
ILIAS\
Mail\Templates\TemplateMessageSyntaxException) {
280 }
catch (Exception) {
282 $this->
lng->txt(
'mail_template_no_valid_context')
284 $this->tpl->setOnScreenMessage(
285 $this->tpl::MESSAGE_TYPE_FAILURE,
286 $this->
lng->txt(
'form_input_not_valid')
292 }
catch (Exception) {
293 $this->tpl->setOnScreenMessage(
294 $this->tpl::MESSAGE_TYPE_FAILURE,
295 $this->
lng->txt(
'mail_template_missing_id')
305 if ($this->
http->wrapper()->query()->has(
'mail_template_tpl_ids')) {
306 $template_id = $this->
http->wrapper()->query()->retrieve(
307 'mail_template_tpl_ids',
308 $this->
refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
312 if (!is_numeric($template_id) || $template_id < 1) {
313 $this->tpl->setOnScreenMessage(
314 $this->tpl::MESSAGE_TYPE_FAILURE,
315 $this->
lng->txt(
'mail_template_missing_id')
322 $template = $this->service->loadTemplateForId((
int) $template_id);
325 }
catch (Exception) {
326 $this->tpl->setOnScreenMessage(
327 $this->tpl::MESSAGE_TYPE_FAILURE,
328 $this->
lng->txt(
'mail_template_missing_id')
344 'lang' => $template->
getLang(),
353 $this->
error->raiseError($this->
lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
357 if ($this->
http->wrapper()->query()->has(
'mail_template_tpl_ids')) {
358 $template_ids = $this->
http->wrapper()->query()->retrieve(
359 'mail_template_tpl_ids',
360 $this->
refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string())
362 if ($template_ids === [
'ALL_OBJECTS']) {
363 $template_ids = array_map(
364 static fn(array $template):
int => (
int) ($template[
'tpl_id'] ?? 0),
365 $this->service->listAllTemplatesAsArray()
368 $template_ids = $this->
refinery->kindlyTo()->listOf($this->
refinery->kindlyTo()->int())
369 ->transform($template_ids);
373 if (count($template_ids) === 0) {
374 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_FAILURE, $this->
lng->txt(
'select_one'));
380 $confirm->setFormAction($this->
ctrl->getFormAction($this,
'deleteTemplate'));
382 $confirm->setHeaderText($this->
lng->txt(
'mail_tpl_sure_delete_entries'));
383 if (count($template_ids) === 1) {
384 $confirm->setHeaderText($this->
lng->txt(
'mail_tpl_sure_delete_entry'));
387 $confirm->setConfirm($this->
lng->txt(
'confirm'),
'deleteTemplate');
388 $confirm->setCancel($this->
lng->txt(
'cancel'),
'showTemplates');
390 foreach ($template_ids as $template_id) {
391 $template = $this->service->loadTemplateForId($template_id);
392 $confirm->addItem(
'tpl_id[]', (
string) $template_id, $template->getTitle());
395 $this->tpl->setContent($confirm->getHTML());
401 $this->
error->raiseError($this->
lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
405 if ($this->
http->wrapper()->post()->has(
'tpl_id')) {
406 $template_ids = $this->
http->wrapper()->post()->retrieve(
408 $this->
refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
411 if (count($template_ids) === 0) {
413 if ($this->
http->wrapper()->query()->has(
'tpl_id')) {
414 $template_id = $this->
http->wrapper()->query()->retrieve(
'tpl_id', $this->
refinery->kindlyTo()->int());
416 $template_ids = [$template_id];
419 if (count($template_ids) === 0) {
420 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_FAILURE, $this->
lng->txt(
'select_one'));
425 $this->service->deleteTemplatesByIds($template_ids);
427 if (count($template_ids) === 1) {
428 $this->tpl->setOnScreenMessage(
429 $this->tpl::MESSAGE_TYPE_SUCCESS,
430 $this->
lng->txt(
'mail_tpl_deleted_s'),
434 $this->tpl->setOnScreenMessage(
435 $this->tpl::MESSAGE_TYPE_SUCCESS,
436 $this->
lng->txt(
'mail_tpl_deleted_p'),
440 $this->
ctrl->redirect($this,
'showTemplates');
446 if ($this->
http->wrapper()->query()->has(
'triggerValue')) {
447 $trigger_value = $this->
http->wrapper()->query()->retrieve(
449 $this->
refinery->kindlyTo()->string()
455 $this->
lng->txt(
'mail_form_placeholders_label'),
459 $placeholders->setInstructionText($this->
lng->txt(
'mail_nacc_use_placeholder'));
461 $placeholders->setAdviseText(sprintf($this->
lng->txt(
'placeholders_advise'),
'<br />'));
462 }
catch (Throwable) {
463 $placeholders->setAdviseText($this->
lng->txt(
'placeholders_advise'));
467 foreach (
$context->getPlaceholders() as $value) {
468 $placeholders->addPlaceholder($value[
'placeholder'], $value[
'label']);
471 $placeholders->render(
true);
479 $title->setRequired(
true);
487 if (count($contexts) <= 1) {
488 $this->tpl->setOnScreenMessage(
489 $this->tpl::MESSAGE_TYPE_FAILURE,
490 $this->
lng->txt(
'mail_template_no_context_available'),
493 $this->
ctrl->redirect($this,
'showTemplates');
497 $context_options = [];
499 foreach ($contexts as $ctx) {
500 if ($ctx->getId() !== $generic_context->getId()) {
501 $context_options[$ctx->getId()] = $ctx;
502 $context_sort[$ctx->getId()] = $ctx->getTitle();
505 asort($context_sort);
507 foreach (array_keys($context_sort) as
$id) {
508 $ctx = $context_options[
$id];
509 $option =
new ilRadioOption($ctx->getTitle(), $ctx->getId());
510 $option->setInfo($ctx->getDescription());
522 $hidden->setValue($this->
lng->getLangKey());
527 $subject->setSize(50);
538 $this->
lng->txt(
'mail_form_placeholders_label'),
543 $placeholders->setInstructionText($this->
lng->txt(
'mail_nacc_use_placeholder'));
545 $placeholders->setAdviseText(sprintf($this->
lng->txt(
'placeholders_advise'),
'<br />'));
546 }
catch (Throwable) {
547 $placeholders->setAdviseText($this->
lng->txt(
'placeholders_advise'));
549 $placeholders->supportsRerenderSignal(
551 $this->
ctrl->getLinkTarget($this,
'getAjaxPlaceholdersById',
'',
true)
553 if ($template ===
null) {
554 $context_id = $generic_context->getId();
556 $context_id = $template->getContext();
559 foreach (
$context->getPlaceholders() as $value) {
560 $placeholders->addPlaceholder($value[
'placeholder'], $value[
'label']);
574 $form->
setTitle($this->
lng->txt(
'mail_create_tpl'));
594 $this->
error->raiseError($this->
lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
598 if ($this->
http->wrapper()->query()->has(
'mail_template_tpl_ids')) {
599 $template_id = $this->
http->wrapper()->query()->retrieve(
600 'mail_template_tpl_ids',
601 $this->
refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
605 if (!is_numeric($template_id) || $template_id < 1) {
606 $this->tpl->setOnScreenMessage(
607 $this->tpl::MESSAGE_TYPE_FAILURE,
608 $this->
lng->txt(
'mail_template_missing_id')
615 $template = $this->service->loadTemplateForId((
int) $template_id);
616 $this->service->unsetAsContextDefault($template);
617 }
catch (Exception) {
618 $this->tpl->setOnScreenMessage(
619 $this->tpl::MESSAGE_TYPE_FAILURE,
620 $this->
lng->txt(
'mail_template_missing_id')
626 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(
'saved_successfully'),
true);
627 $this->
ctrl->redirect($this,
'showTemplates');
633 $this->
error->raiseError($this->
lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
637 if ($this->
http->wrapper()->query()->has(
'mail_template_tpl_ids')) {
638 $template_id = $this->
http->wrapper()->query()->retrieve(
639 'mail_template_tpl_ids',
640 $this->
refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
644 if (!is_numeric($template_id) || $template_id < 1) {
645 $this->tpl->setOnScreenMessage(
646 $this->tpl::MESSAGE_TYPE_FAILURE,
647 $this->
lng->txt(
'mail_template_missing_id')
654 $template = $this->service->loadTemplateForId((
int) $template_id);
655 $this->service->setAsContextDefault($template);
656 }
catch (Exception) {
657 $this->tpl->setOnScreenMessage(
658 $this->tpl::MESSAGE_TYPE_FAILURE,
659 $this->
lng->txt(
'mail_template_missing_id')
665 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(
'saved_successfully'),
true);
666 $this->
ctrl->redirect($this,
'showTemplates');
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Builds a Color from either hex- or rgb values.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Error Handling & global info handling.
static getTemplateContextById(string $a_id)
static getTemplateContexts(?array $a_id=null)
Returns an array of mail template contexts, the key of each entry matches its id.
@ilCtrl_isCalledBy ilMailTemplateGUI: ilObjMailGUI
ilGlobalTemplateInterface $tpl
executeTableActionCommand()
showEditTemplateForm(?ilPropertyFormGUI $form=null)
showInsertTemplateFormCommand(?ilPropertyFormGUI $form=null)
getTemplateForm(?ilMailTemplate $template=null)
getUnsafeGetCommands()
This method must return a list of unsafe GET commands.
getSafePostCommands()
This method must return a list of safe POST commands.
getAjaxPlaceholdersByIdCommand()
ilMailTemplateService $service
populateFormWithTemplate(ilPropertyFormGUI $form, ilMailTemplate $template)
__construct(protected ilObject $parent_object, ?ilGlobalTemplateInterface $tpl=null, ?ilCtrlInterface $ctrl=null, ?ilLanguage $lng=null, ?ilToolbarGUI $toolbar=null, ?ilRbacSystem $rbacsystem=null, ?ilErrorHandling $error=null, ?GlobalHttpState $http=null, ?Factory $ui_factory=null, ?Renderer $ui_renderer=null, ?ilMailTemplateService $template_service=null)
Class ilObject Basic functions for all objects.
This class represents an option in a radio group.
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
This class represents a text area property in a property form.
This class represents a text property in a property form.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
Interface GlobalHttpState.
This is how the factory for UI elements looks.
An entity that renders components to a string output.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
RFC 822 Email address list validation Utility.