19 declare(strict_types=1);
59 $this->tpl = $tpl ?? $DIC->ui()->mainTemplate();
60 $this->
ctrl = $ctrl ?? $DIC->ctrl();
61 $this->
lng = $lng ?? $DIC->language();
62 $this->
toolbar = $toolbar ?? $DIC->toolbar();
63 $this->rbacsystem = $rbacsystem ?? $DIC->rbac()->system();
64 $this->error = $error ?? $DIC[
'ilErr'];
65 $this->
http = $http ?? $DIC->http();
67 $this->ui_factory = $ui_factory ?? $DIC->ui()->factory();
68 $this->ui_renderer = $ui_renderer ?? $DIC->ui()->renderer();
69 $this->service = $template_service ?? $DIC->mail()->textTemplates();
71 $this->
lng->loadLanguageModule(
'meta');
76 return $this->rbacsystem->checkAccess(
'write', $this->parent_object->getRefId());
81 $cmd = $this->
ctrl->getCmd();
83 if ($this->
http->wrapper()->query()->has(
'mail_template_table_action')) {
84 $cmd = $this->
http->wrapper()->query()->retrieve(
85 'mail_template_table_action',
86 $this->
refinery->kindlyTo()->string()
89 if (!$cmd || !method_exists($this, $cmd)) {
90 $cmd =
'showTemplates';
98 if (count($contexts) <= 1) {
99 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_no_context_available'));
101 $this->
toolbar->addComponent($this->ui_factory->button()->standard(
102 $this->
lng->txt(
'mail_new_template'),
103 $this->
ctrl->getLinkTarget($this,
'showInsertTemplateForm')
108 $this->
http->request(),
116 $this->tpl->setContent($this->ui_renderer->render($tbl->getComponent()));
122 $this->error->raiseError($this->
lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
134 if ($form->
getInput(
'context') === $generic_context->getId()) {
136 $this->
lng->txt(
'mail_template_no_valid_context')
144 $this->service->createNewTemplate(
152 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'),
true);
153 $this->
ctrl->redirect($this,
'showTemplates');
154 }
catch (\
ILIAS\
Mail\Templates\TemplateSubjectSyntaxException) {
155 $form->
getItemByPostVar(
'm_subject')->setAlert($this->
lng->txt(
'mail_template_invalid_tpl_syntax'));
156 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'form_input_not_valid'));
157 }
catch (\
ILIAS\
Mail\Templates\TemplateMessageSyntaxException) {
158 $form->
getItemByPostVar(
'm_message')->setAlert($this->
lng->txt(
'mail_template_invalid_tpl_syntax'));
159 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'form_input_not_valid'));
162 $this->
lng->txt(
'mail_template_no_valid_context')
164 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'form_input_not_valid'));
177 $this->tpl->setContent($form->
getHTML());
183 $this->error->raiseError($this->
lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
187 if ($this->
http->wrapper()->post()->has(
'tpl_id')) {
188 $template_id = $this->
http->wrapper()->post()->retrieve(
'tpl_id', $this->
refinery->kindlyTo()->int());
191 if (!is_numeric($template_id) || $template_id < 1) {
192 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
206 if ($form->
getInput(
'context') === $generic_context->getId()) {
208 $this->
lng->txt(
'mail_template_no_valid_context')
216 $this->service->modifyExistingTemplate(
225 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'),
true);
226 $this->
ctrl->redirect($this,
'showTemplates');
228 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
229 }
catch (\
ILIAS\
Mail\Templates\TemplateSubjectSyntaxException) {
230 $form->
getItemByPostVar(
'm_subject')->setAlert($this->
lng->txt(
'mail_template_invalid_tpl_syntax'));
231 }
catch (\
ILIAS\
Mail\Templates\TemplateMessageSyntaxException) {
232 $form->
getItemByPostVar(
'm_message')->setAlert($this->
lng->txt(
'mail_template_invalid_tpl_syntax'));
235 $this->
lng->txt(
'mail_template_no_valid_context')
237 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'form_input_not_valid'));
243 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
252 if ($this->
http->wrapper()->query()->has(
'mail_template_tpl_ids')) {
253 $template_id = $this->
http->wrapper()->query()->retrieve(
254 'mail_template_tpl_ids',
259 if (!is_numeric($template_id) || $template_id < 1) {
260 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
266 $template = $this->service->loadTemplateForId((
int) $template_id);
270 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
276 $this->tpl->setContent($form->
getHTML());
285 'lang' => $template->
getLang(),
294 $this->error->raiseError($this->
lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
298 if ($this->
http->wrapper()->query()->has(
'mail_template_tpl_ids')) {
299 $template_ids = $this->
http->wrapper()->query()->retrieve(
300 'mail_template_tpl_ids',
303 if ($template_ids === [
'ALL_OBJECTS']) {
305 static fn(array $template):
int => (
int) ($template[
'tpl_id'] ?? 0),
306 $this->service->listAllTemplatesAsArray()
309 $template_ids = $this->
refinery->kindlyTo()->listOf($this->
refinery->kindlyTo()->int())
314 if (count($template_ids) === 0) {
315 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'select_one'));
321 $confirm->setFormAction($this->
ctrl->getFormAction($this,
'deleteTemplate'));
323 $confirm->setHeaderText($this->
lng->txt(
'mail_tpl_sure_delete_entries'));
324 if (count($template_ids) === 1) {
325 $confirm->setHeaderText($this->
lng->txt(
'mail_tpl_sure_delete_entry'));
328 $confirm->setConfirm($this->
lng->txt(
'confirm'),
'deleteTemplate');
329 $confirm->setCancel($this->
lng->txt(
'cancel'),
'showTemplates');
331 foreach ($template_ids as $template_id) {
332 $template = $this->service->loadTemplateForId($template_id);
333 $confirm->addItem(
'tpl_id[]', (
string) $template_id, $template->getTitle());
336 $this->tpl->setContent($confirm->getHTML());
342 $this->error->raiseError($this->
lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
346 if ($this->
http->wrapper()->post()->has(
'tpl_id')) {
347 $template_ids = $this->
http->wrapper()->post()->retrieve(
352 if (count($template_ids) === 0) {
354 if ($this->
http->wrapper()->query()->has(
'tpl_id')) {
355 $template_id = $this->
http->wrapper()->query()->retrieve(
'tpl_id', $this->
refinery->kindlyTo()->int());
357 $template_ids = [$template_id];
360 if (count($template_ids) === 0) {
361 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'select_one'));
366 $this->service->deleteTemplatesByIds($template_ids);
368 if (count($template_ids) === 1) {
369 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'mail_tpl_deleted_s'),
true);
371 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'mail_tpl_deleted_p'),
true);
373 $this->
ctrl->redirect($this,
'showTemplates');
379 if ($this->
http->wrapper()->query()->has(
'triggerValue')) {
380 $trigger_value = $this->
http->wrapper()->query()->retrieve(
382 $this->
refinery->kindlyTo()->string()
388 $this->
lng->txt(
'mail_form_placeholders_label'),
394 $placeholders->setAdviseText(sprintf($this->
lng->txt(
'placeholders_advise'),
'<br />'));
396 $placeholders->setAdviseText($this->
lng->txt(
'placeholders_advise'));
400 foreach (
$context->getPlaceholders() as $value) {
401 $placeholders->addPlaceholder($value[
'placeholder'], $value[
'label']);
404 $placeholders->render(
true);
412 $title->setRequired(
true);
420 if (count($contexts) <= 1) {
421 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_no_context_available'),
true);
422 $this->
ctrl->redirect($this,
'showTemplates');
426 $context_options = [];
428 foreach ($contexts as $ctx) {
429 if ($ctx->getId() !== $generic_context->getId()) {
430 $context_options[$ctx->getId()] = $ctx;
431 $context_sort[$ctx->getId()] = $ctx->getTitle();
434 asort($context_sort);
436 foreach (array_keys($context_sort) as
$id) {
437 $ctx = $context_options[
$id];
438 $option =
new ilRadioOption($ctx->getTitle(), $ctx->getId());
439 $option->
setInfo($ctx->getDescription());
451 $hidden->setValue($this->
lng->getLangKey());
456 $subject->setSize(50);
467 $this->
lng->txt(
'mail_form_placeholders_label'),
472 $placeholders->setInstructionText($this->
lng->txt(
'mail_nacc_use_placeholder'));
474 $placeholders->setAdviseText(sprintf($this->
lng->txt(
'placeholders_advise'),
'<br />'));
476 $placeholders->setAdviseText($this->
lng->txt(
'placeholders_advise'));
478 $placeholders->supportsRerenderSignal(
480 $this->
ctrl->getLinkTarget($this,
'getAjaxPlaceholdersById',
'',
true)
482 if ($template ===
null) {
483 $context_id = $generic_context->getId();
485 $context_id = $template->getContext();
488 foreach (
$context->getPlaceholders() as $value) {
489 $placeholders->addPlaceholder($value[
'placeholder'], $value[
'label']);
503 $form->
setTitle($this->
lng->txt(
'mail_create_tpl'));
523 $this->error->raiseError($this->
lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
527 if ($this->
http->wrapper()->query()->has(
'mail_template_tpl_ids')) {
528 $template_id = $this->
http->wrapper()->query()->retrieve(
529 'mail_template_tpl_ids',
534 if (!is_numeric($template_id) || $template_id < 1) {
535 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
541 $template = $this->service->loadTemplateForId((
int) $template_id);
542 $this->service->unsetAsContextDefault($template);
544 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
549 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'),
true);
550 $this->
ctrl->redirect($this,
'showTemplates');
556 $this->error->raiseError($this->
lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
560 if ($this->
http->wrapper()->query()->has(
'mail_template_tpl_ids')) {
561 $template_id = $this->
http->wrapper()->query()->retrieve(
562 'mail_template_tpl_ids',
567 if (!is_numeric($template_id) || $template_id < 1) {
568 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
574 $template = $this->service->loadTemplateForId((
int) $template_id);
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 class represents an option in a radio group.
ilMailTemplateGUI: ilObjMailGUI
Interface Observer Contains several chained tasks and infos about them.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
getAjaxPlaceholdersById()
static getTemplateContextById(string $a_id)
__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)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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)
showInsertTemplateForm(?ilPropertyFormGUI $form=null)
This is how the factory for UI elements looks.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
RFC 822 Email address list validation Utility.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
This class represents a text area property in a property form.
getTemplateForm(?ilMailTemplate $template=null)
showEditTemplateForm(?ilPropertyFormGUI $form=null)
ilMailTemplateService $service