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'));
178 $this->tpl->setContent($form->
getHTML());
184 $this->error->raiseError($this->
lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
188 if ($this->
http->wrapper()->post()->has(
'tpl_id')) {
189 $templateId = $this->
http->wrapper()->post()->retrieve(
'tpl_id', $this->
refinery->kindlyTo()->int());
192 if (!is_numeric($templateId) || $templateId < 1) {
193 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
207 if ($form->
getInput(
'context') === $genericContext->getId()) {
209 $this->
lng->txt(
'mail_template_no_valid_context')
217 $this->service->modifyExistingTemplate(
226 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'),
true);
227 $this->
ctrl->redirect($this,
'showTemplates');
229 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
230 }
catch (\
ILIAS\
Mail\Templates\TemplateSubjectSyntaxException) {
231 $form->
getItemByPostVar(
'm_subject')->setAlert($this->
lng->txt(
'mail_template_invalid_tpl_syntax'));
232 }
catch (\
ILIAS\
Mail\Templates\TemplateMessageSyntaxException) {
233 $form->
getItemByPostVar(
'm_message')->setAlert($this->
lng->txt(
'mail_template_invalid_tpl_syntax'));
236 $this->
lng->txt(
'mail_template_no_valid_context')
238 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'form_input_not_valid'));
244 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
253 if ($this->
http->wrapper()->query()->has(
'tpl_id')) {
254 $templateId = $this->
http->wrapper()->query()->retrieve(
260 if (!is_numeric($templateId) || $templateId < 1) {
261 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
267 $template = $this->service->loadTemplateForId((
int) $templateId);
271 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
277 $this->tpl->setContent($form->
getHTML());
286 'lang' => $template->
getLang(),
295 $this->error->raiseError($this->
lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
299 if ($this->
http->wrapper()->post()->has(
'tpl_id')) {
300 $templateIds = $this->
http->wrapper()->post()->retrieve(
305 if (count($templateIds) === 0 && $this->
http->wrapper()->query()->has(
'tpl_id')) {
306 $templateIds = [$this->
http->wrapper()->query()->retrieve(
312 if (0 === count($templateIds)) {
313 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'select_one'));
319 $confirm->setFormAction($this->
ctrl->getFormAction($this,
'deleteTemplate'));
321 $confirm->setHeaderText($this->
lng->txt(
'mail_tpl_sure_delete_entries'));
322 if (1 === count($templateIds)) {
323 $confirm->setHeaderText($this->
lng->txt(
'mail_tpl_sure_delete_entry'));
326 $confirm->setConfirm($this->
lng->txt(
'confirm'),
'deleteTemplate');
327 $confirm->setCancel($this->
lng->txt(
'cancel'),
'showTemplates');
329 foreach ($templateIds as $templateId) {
330 $template = $this->service->loadTemplateForId($templateId);
331 $confirm->addItem(
'tpl_id[]', (
string) $templateId, $template->getTitle());
334 $this->tpl->setContent($confirm->getHTML());
340 $this->error->raiseError($this->
lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
344 if ($this->
http->wrapper()->post()->has(
'tpl_id')) {
345 $templateIds = $this->
http->wrapper()->post()->retrieve(
350 if (count($templateIds) === 0) {
352 if ($this->
http->wrapper()->query()->has(
'tpl_id')) {
353 $templateId = $this->
http->wrapper()->query()->retrieve(
'tpl_id', $this->
refinery->kindlyTo()->int());
355 $templateIds = [$templateId];
358 if (0 === count($templateIds)) {
359 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'select_one'));
364 $this->service->deleteTemplatesByIds($templateIds);
366 if (1 === count($templateIds)) {
367 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'mail_tpl_deleted_s'),
true);
369 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'mail_tpl_deleted_p'),
true);
371 $this->
ctrl->redirect($this,
'showTemplates');
380 if ($this->
http->wrapper()->query()->has(
'triggerValue')) {
381 $triggerValue = $this->
http->wrapper()->query()->retrieve(
383 $this->
refinery->kindlyTo()->string()
389 $this->
lng->txt(
'mail_form_placeholders_label'),
395 $placeholders->setAdviseText(sprintf($this->
lng->txt(
'placeholders_advise'),
'<br />'));
397 $placeholders->setAdviseText($this->
lng->txt(
'placeholders_advise'));
401 foreach (
$context->getPlaceholders() as $value) {
402 $placeholders->addPlaceholder($value[
'placeholder'], $value[
'label']);
405 $placeholders->render(
true);
416 $title->setRequired(
true);
424 if (count($contexts) <= 1) {
425 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_no_context_available'),
true);
426 $this->
ctrl->redirect($this,
'showTemplates');
430 $context_options = [];
432 foreach ($contexts as $ctx) {
433 if ($ctx->getId() !== $generic_context->getId()) {
434 $context_options[$ctx->getId()] = $ctx;
435 $context_sort[$ctx->getId()] = $ctx->getTitle();
438 asort($context_sort);
440 foreach (array_keys($context_sort) as
$id) {
441 $ctx = $context_options[
$id];
442 $option =
new ilRadioOption($ctx->getTitle(), $ctx->getId());
443 $option->
setInfo($ctx->getDescription());
455 $hidden->setValue($this->
lng->getLangKey());
460 $subject->setSize(50);
471 $this->
lng->txt(
'mail_form_placeholders_label'),
476 $placeholders->setInstructionText($this->
lng->txt(
'mail_nacc_use_placeholder'));
478 $placeholders->setAdviseText(sprintf($this->
lng->txt(
'placeholders_advise'),
'<br />'));
480 $placeholders->setAdviseText($this->
lng->txt(
'placeholders_advise'));
482 $placeholders->supportsRerenderSignal(
484 $this->
ctrl->getLinkTarget($this,
'getAjaxPlaceholdersById',
'',
true)
486 if ($template ===
null) {
487 $context_id = $generic_context->getId();
489 $context_id = $template->getContext();
492 foreach (
$context->getPlaceholders() as $value) {
493 $placeholders->addPlaceholder($value[
'placeholder'], $value[
'label']);
507 $form->
setTitle($this->
lng->txt(
'mail_create_tpl'));
527 $this->error->raiseError($this->
lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
531 if ($this->
http->wrapper()->query()->has(
'tpl_id')) {
532 $templateId = $this->
http->wrapper()->query()->retrieve(
'tpl_id', $this->
refinery->kindlyTo()->int());
535 if (!is_numeric($templateId) || $templateId < 1) {
536 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
542 $template = $this->service->loadTemplateForId((
int) $templateId);
543 $this->service->unsetAsContextDefault($template);
545 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
550 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'),
true);
551 $this->
ctrl->redirect($this,
'showTemplates');
557 $this->error->raiseError($this->
lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
561 if ($this->
http->wrapper()->query()->has(
'tpl_id')) {
562 $templateId = $this->
http->wrapper()->query()->retrieve(
'tpl_id', $this->
refinery->kindlyTo()->int());
565 if (!is_numeric($templateId) || $templateId < 1) {
566 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
572 $template = $this->service->loadTemplateForId((
int) $templateId);
573 $this->service->setAsContextDefault($template);
575 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'mail_template_missing_id'));
580 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'),
true);
581 $this->
ctrl->redirect($this,
'showTemplates');
This class represents an option in a radio group.
Interface Observer Contains several chained tasks and infos about them.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
getAjaxPlaceholdersById()
Class ilMailTemplateTableGUI.
static getTemplateContextById(string $a_id)
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.
RFC 822 Email address list validation Utility.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
This class represents a text area property in a property form.
__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)
showEditTemplateForm(?ilPropertyFormGUI $form=null)
ilMailTemplateService $service