1<?
php declare(strict_types=1);
 
  114        if (
$http === 
null) {
 
  115            $http = $DIC->http();
 
  129        if (
null === $templateService) {
 
  130            $templateService = 
$DIC[
'mail.texttemplates.service'];
 
  132        $this->service = $templateService;
 
  134        $this->lng->loadLanguageModule(
'meta');
 
  142        return $this->rbacsystem->checkAccess(
'write', $this->parentObject->getRefId());
 
  150        $next_class = $this->ctrl->getNextClass($this);
 
  151        $cmd = $this->ctrl->getCmd();
 
  153        switch ($next_class) {
 
  155                if (!$cmd || !method_exists($this, $cmd)) {
 
  156                    $cmd = 
'showTemplates';
 
  170        if (count($contexts) <= 1) {
 
  174            $create_tpl_button->setCaption(
'mail_new_template');
 
  175            $create_tpl_button->setUrl($this->ctrl->getLinkTarget($this, 
'showInsertTemplateForm'));
 
  176            $this->toolbar->addButtonInstance($create_tpl_button);
 
  186        $tbl->setData($this->service->listAllTemplatesAsArray());
 
  188        $this->tpl->setContent($tbl->getHTML());
 
  197            $this->
error->raiseError($this->lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
 
  202        if (!
$form->checkInput()) {
 
  203            $form->setValuesByPost();
 
  209        if (
$form->getInput(
'context') === $generic_context->getId()) {
 
  210            $form->getItemByPostVar(
'context')->setAlert($this->lng->txt(
'mail_template_no_valid_context'));
 
  211            $form->setValuesByPost();
 
  217            $this->service->createNewTemplate(
 
  219                (
string) 
$form->getInput(
'title'),
 
  220                (
string) 
$form->getInput(
'm_subject'),
 
  221                (
string) 
$form->getInput(
'm_message'),
 
  222                (
string) 
$form->getInput(
'lang')
 
  225            ilUtil::sendSuccess($this->lng->txt(
'saved_successfully'), 
true);
 
  226            $this->ctrl->redirect($this, 
'showTemplates');
 
  227        } 
catch (Exception 
$e) {
 
  228            $form->getItemByPostVar(
'context')->setAlert($this->lng->txt(
'mail_template_no_valid_context'));
 
  232        $form->setValuesByPost();
 
  246        $this->tpl->setContent(
$form->getHTML());
 
  255            $this->
error->raiseError($this->lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
 
  258        $templateId = $this->
http->request()->getParsedBody()[
'tpl_id'] ?? 0;
 
  260        if (!is_numeric($templateId) || $templateId < 1) {
 
  268            if (!
$form->checkInput()) {
 
  269                $form->setValuesByPost();
 
  275            if (
$form->getInput(
'context') === $genericContext->getId()) {
 
  276                $form->getItemByPostVar(
'context')->setAlert($this->lng->txt(
'mail_template_no_valid_context'));
 
  277                $form->setValuesByPost();
 
  283                $this->service->modifyExistingTemplate(
 
  286                    (
string) 
$form->getInput(
'title'),
 
  287                    (
string) 
$form->getInput(
'm_subject'),
 
  288                    (
string) 
$form->getInput(
'm_message'),
 
  289                    (
string) 
$form->getInput(
'lang')
 
  292                ilUtil::sendSuccess($this->lng->txt(
'saved_successfully'), 
true);
 
  293                $this->ctrl->redirect($this, 
'showTemplates');
 
  294            } 
catch (OutOfBoundsException 
$e) {
 
  296            } 
catch (Exception 
$e) {
 
  297                $form->getItemByPostVar(
'context')->setAlert($this->lng->txt(
'mail_template_no_valid_context'));
 
  301            $form->setValuesByPost();
 
  303        } 
catch (Exception 
$e) {
 
  316            $templateId = $this->
http->request()->getQueryParams()[
'tpl_id'] ?? 0;
 
  318            if (!is_numeric($templateId) || $templateId < 1) {
 
  325                $template = $this->service->loadTemplateForId((
int) $templateId);
 
  328            } 
catch (Exception 
$e) {
 
  335        $this->tpl->setContent(
$form->getHTML());
 
  344        $form->setValuesByArray(array(
 
  348            'lang' => $template->
getLang(),
 
  360            $this->
error->raiseError($this->lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
 
  363        $templateIds = $this->
http->request()->getParsedBody()[
'tpl_id'] ?? array();
 
  364        if (is_array($templateIds) && count($templateIds) > 0) {
 
  365            $templateIds = array_filter(array_map(
'intval', $templateIds));
 
  367            $templateId = $this->
http->request()->getQueryParams()[
'tpl_id'] ?? 
'';
 
  368            if (is_numeric($templateId) && $templateId > 0) {
 
  369                $templateIds = array_filter(array((
int) $templateId));
 
  371                $templateIds = array();
 
  375        if (0 === count($templateIds)) {
 
  382        $confirm->setFormAction($this->ctrl->getFormAction($this, 
'deleteTemplate'));
 
  384        $confirm->setHeaderText($this->lng->txt(
'mail_tpl_sure_delete_entry'));
 
  385        if (1 === count($templateIds)) {
 
  386            $confirm->setHeaderText($this->lng->txt(
'mail_tpl_sure_delete_entries'));
 
  389        $confirm->setConfirm($this->lng->txt(
'confirm'), 
'deleteTemplate');
 
  390        $confirm->setCancel($this->lng->txt(
'cancel'), 
'showTemplates');
 
  392        foreach ($templateIds as $templateId) {
 
  393            $template = $this->service->loadTemplateForId((
int) $templateId);
 
  394            $confirm->addItem(
'tpl_id[]', $templateId, $template->getTitle());
 
  397        $this->tpl->setContent($confirm->getHTML());
 
  406            $this->
error->raiseError($this->lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
 
  409        $templateIds = $this->
http->request()->getParsedBody()[
'tpl_id'] ?? array();
 
  410        if (is_array($templateIds) && count($templateIds) > 0) {
 
  411            $templateIds = array_filter(array_map(
'intval', $templateIds));
 
  413            $templateId = $this->
http->request()->getQueryParams()[
'tpl_id'] ?? 
'';
 
  414            if (is_numeric($templateId) && $templateId > 0) {
 
  415                $templateIds = array_filter(array((
int) $templateId));
 
  417                $templateIds = array();
 
  421        if (0 === count($templateIds)) {
 
  427        $this->service->deleteTemplatesByIds($templateIds);
 
  429        if (1 === count($templateIds)) {
 
  430            ilUtil::sendSuccess($this->lng->txt(
'mail_tpl_deleted_s'), 
true);
 
  432            ilUtil::sendSuccess($this->lng->txt(
'mail_tpl_deleted_p'), 
true);
 
  434        $this->ctrl->redirect($this, 
'showTemplates');
 
  442        $triggerValue = $this->
http->request()->getQueryParams()[
'triggerValue'] ?? 
'';
 
  446        $placeholders->setInstructionText($this->lng->txt(
'mail_nacc_use_placeholder'));
 
  448            $placeholders->setAdviseText(sprintf($this->lng->txt(
'placeholders_advise'), 
'<br />'));
 
  449        } 
catch (Throwable 
$e) {
 
  450            $placeholders->setAdviseText($this->lng->txt(
'placeholders_advise'));
 
  454        foreach (
$context->getPlaceholders() as $key => $value) {
 
  455            $placeholders->addPlaceholder($value[
'placeholder'], $value[
'label']);
 
  458        $placeholders->render(
true);
 
  471        $title = 
new ilTextInputGUI($this->lng->txt(
'mail_template_title'), 
'title');
 
  472        $title->setRequired(
true);
 
  474        $form->addItem($title);
 
  480        if (count($contexts) <= 1) {
 
  482            $this->ctrl->redirect($this, 
'showTemplates');
 
  485        $context_sort = array();
 
  486        $context_options = array();
 
  488        foreach ($contexts as $ctx) {
 
  489            if ($ctx->getId() != $generic_context->getId()) {
 
  490                $context_options[$ctx->getId()] = $ctx;
 
  491                $context_sort[$ctx->getId()] = $ctx->getTitle();
 
  494        asort($context_sort);
 
  496        foreach ($context_sort as $id => $title) {
 
  497            $ctx = $context_options[$id];
 
  498            $option = 
new ilRadioOption($ctx->getTitle(), $ctx->getId());
 
  499            $option->setInfo($ctx->getDescription());
 
  511        $hidden->setValue($this->lng->getLangKey());
 
  512        $form->addItem($hidden);
 
  514        $subject = 
new ilTextInputGUI($this->lng->txt(
'subject'), 
'm_subject');
 
  516        $subject->setSize(50);
 
  517        $form->addItem($subject);
 
  528        $placeholders->setInstructionText($this->lng->txt(
'mail_nacc_use_placeholder'));
 
  530            $placeholders->setAdviseText(sprintf($this->lng->txt(
'placeholders_advise'), 
'<br />'));
 
  531        } 
catch (Throwable 
$e) {
 
  532            $placeholders->setAdviseText($this->lng->txt(
'placeholders_advise'));
 
  534        $placeholders->supportsRerenderSignal(
 
  536            $this->ctrl->getLinkTarget($this, 
'getAjaxPlaceholdersById', 
'', 
true, 
false)
 
  538        if ($template === 
null) {
 
  539            $context_id = $generic_context->getId();
 
  541            $context_id = $template->getContext();
 
  544        foreach (
$context->getPlaceholders() as $key => $value) {
 
  545            $placeholders->addPlaceholder($value[
'placeholder'], $value[
'label']);
 
  547        $form->addItem($placeholders);
 
  552            $form->setTitle($this->lng->txt(
'mail_edit_tpl'));
 
  553            $form->setFormAction($this->ctrl->getFormaction($this, 
'updateTemplate'));
 
  556                $form->addCommandButton(
'updateTemplate', $this->lng->txt(
'save'));
 
  559            $form->setTitle($this->lng->txt(
'mail_create_tpl'));
 
  560            $form->setFormAction($this->ctrl->getFormaction($this, 
'insertTemplate'));
 
  563                $form->addCommandButton(
'insertTemplate', $this->lng->txt(
'save'));
 
  568            $form->addCommandButton(
'showTemplates', $this->lng->txt(
'cancel'));
 
  570            $form->addCommandButton(
'showTemplates', $this->lng->txt(
'back'));
 
  582            $this->
error->raiseError($this->lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
 
  585        $templateId = $this->
http->request()->getQueryParams()[
'tpl_id'] ?? 0;
 
  587        if (!is_numeric($templateId) || $templateId < 1) {
 
  594            $template = $this->service->loadTemplateForId((
int) $templateId);
 
  595            $this->service->unsetAsContextDefault($template);
 
  596        } 
catch (Exception 
$e) {
 
  602        ilUtil::sendSuccess($this->lng->txt(
'saved_successfully'), 
true);
 
  603        $this->ctrl->redirect($this, 
'showTemplates');
 
  612            $this->
error->raiseError($this->lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
 
  615        $templateId = $this->
http->request()->getQueryParams()[
'tpl_id'] ?? 0;
 
  617        if (!is_numeric($templateId) || $templateId < 1) {
 
  624            $template = $this->service->loadTemplateForId((
int) $templateId);
 
  625            $this->service->setAsContextDefault($template);
 
  626        } 
catch (Exception 
$e) {
 
  632        ilUtil::sendSuccess($this->lng->txt(
'saved_successfully'), 
true);
 
  633        $this->ctrl->redirect($this, 
'showTemplates');
 
An exception for terminatinating execution or to throw for unit testing.
Provides an interface to the ILIAS HTTP services.
error($a_errmsg)
set error message @access public
Confirmation screen class.
This class provides processing control methods.
Class ilGlobalPageTemplate.
static getTemplateContextById($a_id)
static getTemplateContexts($a_id=null)
Returns an array of mail template contexts, the key of each entry matches its id.
__construct(ilObject $parentObject, ilGlobalPageTemplate $tpl=null, ilCtrl $ctrl=null, ilLanguage $lng=null, ilToolbarGUI $toolbar=null, ilRbacSystem $rbacsystem=null, ilErrorHandling $error=null, HTTPServices $http=null, Factory $uiFactory=null, Renderer $uiRenderer=null, ilMailTemplateService $templateService=null)
ilMailTemplateGUI constructor.
getTemplateForm(ilMailTemplate $template=null)
getAjaxPlaceholdersById()
showInsertTemplateForm(ilPropertyFormGUI $form=null)
showEditTemplateForm(ilPropertyFormGUI $form=null)
populateFormWithTemplate(ilPropertyFormGUI $form, ilMailTemplate $template)
Class ilMailTemplateService.
Class ilMailTemplateTableGUI.
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 sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
This is how the factory for UI elements looks.
An entity that renders components to a string output.
static http()
Fetches the global http state from ILIAS.