19 declare(strict_types=1);
61 $this->tpl = $tpl ?? $DIC->ui()->mainTemplate();
62 $this->
ctrl = $ctrl ?? $DIC->ctrl();
63 $this->
lng = $lng ?? $DIC->language();
64 $this->
toolbar = $toolbar ?? $DIC->toolbar();
65 $this->rbacsystem = $rbacsystem ?? $DIC->rbac()->system();
66 $this->error = $error ?? $DIC[
'ilErr'];
67 $this->
http = $http ?? $DIC->http();
69 $this->uiFactory = $uiFactory ?? $DIC->ui()->factory();
70 $this->uiRenderer = $uiRenderer ?? $DIC->ui()->renderer();
71 $this->service = $templateService ?? $DIC->mail()->textTemplates();
73 $this->
lng->loadLanguageModule(
'meta');
78 return $this->rbacsystem->checkAccess(
'write', $this->parentObject->getRefId());
83 $cmd = $this->
ctrl->getCmd();
84 if (!$cmd || !method_exists($this, $cmd)) {
85 $cmd =
'showTemplates';
93 if (count($contexts) <= 1) {
94 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_no_context_available'));
96 $this->
toolbar->addComponent($this->uiFactory->button()->standard(
97 $this->
lng->txt(
'mail_new_template'),
98 $this->
ctrl->getLinkTarget($this,
'showInsertTemplateForm')
109 $tbl->setData($this->service->listAllTemplatesAsArray());
111 $this->tpl->setContent($tbl->getHTML());
120 $this->error->raiseError($this->
lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
132 if ($form->
getInput(
'context') === $generic_context->getId()) {
134 $this->
lng->txt(
'mail_template_no_valid_context')
142 $this->service->createNewTemplate(
150 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'),
true);
151 $this->
ctrl->redirect($this,
'showTemplates');
152 }
catch (\
ILIAS\
Mail\Templates\TemplateSubjectSyntaxException) {
153 $form->
getItemByPostVar(
'm_subject')->setAlert($this->
lng->txt(
'mail_template_invalid_tpl_syntax'));
154 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'form_input_not_valid'));
155 }
catch (\
ILIAS\
Mail\Templates\TemplateMessageSyntaxException) {
156 $form->
getItemByPostVar(
'm_message')->setAlert($this->
lng->txt(
'mail_template_invalid_tpl_syntax'));
157 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'form_input_not_valid'));
160 $this->
lng->txt(
'mail_template_no_valid_context')
162 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'form_input_not_valid'));
179 $this->tpl->setContent($form->
getHTML());
185 $this->error->raiseError($this->
lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
189 if ($this->
http->wrapper()->post()->has(
'tpl_id')) {
190 $templateId = $this->
http->wrapper()->post()->retrieve(
'tpl_id', $this->
refinery->kindlyTo()->int());
193 if (!is_numeric($templateId) || $templateId < 1) {
194 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
208 if ($form->
getInput(
'context') === $genericContext->getId()) {
210 $this->
lng->txt(
'mail_template_no_valid_context')
218 $this->service->modifyExistingTemplate(
227 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'),
true);
228 $this->
ctrl->redirect($this,
'showTemplates');
230 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
231 }
catch (\
ILIAS\
Mail\Templates\TemplateSubjectSyntaxException) {
232 $form->
getItemByPostVar(
'm_subject')->setAlert($this->
lng->txt(
'mail_template_invalid_tpl_syntax'));
233 }
catch (\
ILIAS\
Mail\Templates\TemplateMessageSyntaxException) {
234 $form->
getItemByPostVar(
'm_message')->setAlert($this->
lng->txt(
'mail_template_invalid_tpl_syntax'));
237 $this->
lng->txt(
'mail_template_no_valid_context')
239 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'form_input_not_valid'));
245 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
254 if ($this->
http->wrapper()->query()->has(
'tpl_id')) {
255 $templateId = $this->
http->wrapper()->query()->retrieve(
261 if (!is_numeric($templateId) || $templateId < 1) {
262 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
268 $template = $this->service->loadTemplateForId((
int) $templateId);
272 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
278 $this->tpl->setContent($form->
getHTML());
287 'lang' => $template->
getLang(),
296 $this->error->raiseError($this->
lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
300 if ($this->
http->wrapper()->post()->has(
'tpl_id')) {
301 $templateIds = $this->
http->wrapper()->post()->retrieve(
306 if (count($templateIds) === 0 && $this->
http->wrapper()->query()->has(
'tpl_id')) {
307 $templateIds = [$this->
http->wrapper()->query()->retrieve(
313 if (0 === count($templateIds)) {
314 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'select_one'));
320 $confirm->setFormAction($this->
ctrl->getFormAction($this,
'deleteTemplate'));
322 $confirm->setHeaderText($this->
lng->txt(
'mail_tpl_sure_delete_entries'));
323 if (1 === count($templateIds)) {
324 $confirm->setHeaderText($this->
lng->txt(
'mail_tpl_sure_delete_entry'));
327 $confirm->setConfirm($this->
lng->txt(
'confirm'),
'deleteTemplate');
328 $confirm->setCancel($this->
lng->txt(
'cancel'),
'showTemplates');
330 foreach ($templateIds as $templateId) {
331 $template = $this->service->loadTemplateForId($templateId);
332 $confirm->addItem(
'tpl_id[]', (
string) $templateId, $template->getTitle());
335 $this->tpl->setContent($confirm->getHTML());
341 $this->error->raiseError($this->
lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
345 if ($this->
http->wrapper()->post()->has(
'tpl_id')) {
346 $templateIds = $this->
http->wrapper()->post()->retrieve(
351 if (count($templateIds) === 0) {
353 if ($this->
http->wrapper()->query()->has(
'tpl_id')) {
354 $templateId = $this->
http->wrapper()->query()->retrieve(
'tpl_id', $this->
refinery->kindlyTo()->int());
356 $templateIds = [$templateId];
359 if (0 === count($templateIds)) {
360 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'select_one'));
365 $this->service->deleteTemplatesByIds($templateIds);
367 if (1 === count($templateIds)) {
368 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'mail_tpl_deleted_s'),
true);
370 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'mail_tpl_deleted_p'),
true);
372 $this->
ctrl->redirect($this,
'showTemplates');
381 if ($this->
http->wrapper()->query()->has(
'triggerValue')) {
382 $triggerValue = $this->
http->wrapper()->query()->retrieve(
384 $this->
refinery->kindlyTo()->string()
390 $this->
lng->txt(
'mail_form_placeholders_label'),
396 $placeholders->setAdviseText(sprintf($this->
lng->txt(
'placeholders_advise'),
'<br />'));
398 $placeholders->setAdviseText($this->
lng->txt(
'placeholders_advise'));
402 foreach (
$context->getPlaceholders() as $value) {
403 $placeholders->addPlaceholder($value[
'placeholder'], $value[
'label']);
406 $placeholders->render(
true);
418 $title->setRequired(
true);
426 if (count($contexts) <= 1) {
427 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_no_context_available'),
true);
428 $this->
ctrl->redirect($this,
'showTemplates');
432 $context_options = [];
434 foreach ($contexts as $ctx) {
435 if ($ctx->getId() !== $generic_context->getId()) {
436 $context_options[$ctx->getId()] = $ctx;
437 $context_sort[$ctx->getId()] = $ctx->getTitle();
440 asort($context_sort);
442 foreach (array_keys($context_sort) as
$id) {
443 $ctx = $context_options[
$id];
444 $option =
new ilRadioOption($ctx->getTitle(), $ctx->getId());
445 $option->
setInfo($ctx->getDescription());
457 $hidden->setValue($this->
lng->getLangKey());
462 $subject->setSize(50);
467 $message->setRequired(
true);
468 $message->setCols(60);
469 $message->setRows(10);
473 $this->
lng->txt(
'mail_form_placeholders_label'),
478 $placeholders->setInstructionText($this->
lng->txt(
'mail_nacc_use_placeholder'));
480 $placeholders->setAdviseText(sprintf($this->
lng->txt(
'placeholders_advise'),
'<br />'));
482 $placeholders->setAdviseText($this->
lng->txt(
'placeholders_advise'));
484 $placeholders->supportsRerenderSignal(
486 $this->
ctrl->getLinkTarget($this,
'getAjaxPlaceholdersById',
'',
true)
488 if ($template === null) {
489 $context_id = $generic_context->getId();
491 $context_id = $template->getContext();
494 foreach (
$context->getPlaceholders() as $value) {
495 $placeholders->addPlaceholder($value[
'placeholder'], $value[
'label']);
509 $form->
setTitle($this->
lng->txt(
'mail_create_tpl'));
529 $this->error->raiseError($this->
lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
533 if ($this->
http->wrapper()->query()->has(
'tpl_id')) {
534 $templateId = $this->
http->wrapper()->query()->retrieve(
'tpl_id', $this->
refinery->kindlyTo()->int());
537 if (!is_numeric($templateId) || $templateId < 1) {
538 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
544 $template = $this->service->loadTemplateForId((
int) $templateId);
545 $this->service->unsetAsContextDefault($template);
547 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
552 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'),
true);
553 $this->
ctrl->redirect($this,
'showTemplates');
559 $this->error->raiseError($this->
lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
563 if ($this->
http->wrapper()->query()->has(
'tpl_id')) {
564 $templateId = $this->
http->wrapper()->query()->retrieve(
'tpl_id', $this->
refinery->kindlyTo()->int());
567 if (!is_numeric($templateId) || $templateId < 1) {
568 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
574 $template = $this->service->loadTemplateForId((
int) $templateId);
575 $this->service->setAsContextDefault($template);
577 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
582 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'),
true);
583 $this->
ctrl->redirect($this,
'showTemplates');
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
showEditTemplateForm(ilPropertyFormGUI $form=null)
Interface Observer Contains several chained tasks and infos about them.
__construct(protected ilObject $parentObject, ilGlobalTemplateInterface $tpl=null, ilCtrlInterface $ctrl=null, ilLanguage $lng=null, ilToolbarGUI $toolbar=null, ilRbacSystem $rbacsystem=null, ilErrorHandling $error=null, GlobalHttpState $http=null, Factory $uiFactory=null, Renderer $uiRenderer=null, ilMailTemplateService $templateService=null)
getTemplateForm(ilMailTemplate $template=null)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
getAjaxPlaceholdersById()
Class ilMailTemplateTableGUI.
static getTemplateContextById(string $a_id)
ilGlobalTemplateInterface $tpl
static getTemplateContexts(?array $a_id=null)
Returns an array of mail template contexts, the key of each entry matches its id. ...
static http()
Fetches the global http state from ILIAS.
populateFormWithTemplate(ilPropertyFormGUI $form, ilMailTemplate $template)
This is how the factory for UI elements looks.
RFC 822 Email address list validation Utility.
showInsertTemplateForm(ilPropertyFormGUI $form=null)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
This class represents a text area property in a property form.
ilMailTemplateService $service