84 $tpl = $DIC->ui()->mainTemplate();
94 $lng = $DIC->language();
113 if (
$http === null) {
114 $http = $DIC->http();
128 if (null === $templateService) {
129 $templateService = $DIC[
'mail.texttemplates.service'];
131 $this->service = $templateService;
133 $this->lng->loadLanguageModule(
'meta');
141 return $this->rbacsystem->checkAccess(
'write', $this->parentObject->getRefId());
149 $next_class = $this->ctrl->getNextClass($this);
150 $cmd = $this->ctrl->getCmd();
152 switch ($next_class) {
154 if (!$cmd || !method_exists($this, $cmd)) {
155 $cmd =
'showTemplates';
169 if (count($contexts) <= 1) {
173 $create_tpl_button->setCaption(
'mail_new_template');
174 $create_tpl_button->setUrl($this->ctrl->getLinkTarget($this,
'showInsertTemplateForm'));
175 $this->toolbar->addButtonInstance($create_tpl_button);
178 $tbl = new \ilMailTemplateTableGUI(
185 $tbl->setData($this->service->listAllTemplatesAsArray());
187 $this->tpl->setContent(
$tbl->getHTML());
196 $this->error->raiseError($this->lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
201 if (!
$form->checkInput()) {
202 $form->setValuesByPost();
207 $generic_context = new \ilMailTemplateGenericContext();
208 if (
$form->getInput(
'context') === $generic_context->getId()) {
209 $form->getItemByPostVar(
'context')->setAlert($this->lng->txt(
'mail_template_no_valid_context'));
210 $form->setValuesByPost();
216 $this->service->createNewTemplate(
218 (string)
$form->getInput(
'title'),
219 (string)
$form->getInput(
'm_subject'),
220 (string)
$form->getInput(
'm_message'),
221 (string)
$form->getInput(
'lang')
224 \ilUtil::sendSuccess($this->lng->txt(
'saved_successfully'),
true);
225 $this->ctrl->redirect($this,
'showTemplates');
227 $form->getItemByPostVar(
'context')->setAlert($this->lng->txt(
'mail_template_no_valid_context'));
231 $form->setValuesByPost();
245 $this->tpl->setContent(
$form->getHTML());
254 $this->error->raiseError($this->lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
257 $templateId = $this->
http->request()->getParsedBody()[
'tpl_id'] ?? 0;
259 if (!is_numeric($templateId) || $templateId < 1) {
267 if (!
$form->checkInput()) {
268 $form->setValuesByPost();
273 $genericContext = new \ilMailTemplateGenericContext();
274 if (
$form->getInput(
'context') === $genericContext->getId()) {
275 $form->getItemByPostVar(
'context')->setAlert($this->lng->txt(
'mail_template_no_valid_context'));
276 $form->setValuesByPost();
282 $this->service->modifyExistingTemplate(
285 (string)
$form->getInput(
'title'),
286 (string)
$form->getInput(
'm_subject'),
287 (string)
$form->getInput(
'm_message'),
288 (string)
$form->getInput(
'lang')
291 \ilUtil::sendSuccess($this->lng->txt(
'saved_successfully'),
true);
292 $this->ctrl->redirect($this,
'showTemplates');
293 }
catch (\OutOfBoundsException $e) {
296 $form->getItemByPostVar(
'context')->setAlert($this->lng->txt(
'mail_template_no_valid_context'));
300 $form->setValuesByPost();
315 $templateId = $this->
http->request()->getQueryParams()[
'tpl_id'] ?? 0;
317 if (!is_numeric($templateId) || $templateId < 1) {
324 $template = $this->service->loadTemplateForId((
int) $templateId);
334 $this->tpl->setContent(
$form->getHTML());
347 'lang' => $template->
getLang(),
359 $this->error->raiseError($this->lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
362 $templateIds = $this->
http->request()->getParsedBody()[
'tpl_id'] ?? array();
363 if (is_array($templateIds) && count($templateIds) > 0) {
364 $templateIds = array_filter(array_map(
'intval', $templateIds));
366 $templateId = $this->
http->request()->getQueryParams()[
'tpl_id'] ??
'';
367 if (is_numeric($templateId) && $templateId > 0) {
368 $templateIds = array_filter(array((
int) $templateId));
370 $templateIds = array();
374 if (0 === count($templateIds)) {
380 $confirm = new \ilConfirmationGUI();
381 $confirm->setFormAction($this->ctrl->getFormAction($this,
'deleteTemplate'));
383 $confirm->setHeaderText($this->lng->txt(
'mail_tpl_sure_delete_entry'));
384 if (1 === count($templateIds)) {
385 $confirm->setHeaderText($this->lng->txt(
'mail_tpl_sure_delete_entries'));
388 $confirm->setConfirm($this->lng->txt(
'confirm'),
'deleteTemplate');
389 $confirm->setCancel($this->lng->txt(
'cancel'),
'showTemplates');
391 foreach ($templateIds as $templateId) {
392 $template = $this->service->loadTemplateForId((
int) $templateId);
393 $confirm->addItem(
'tpl_id[]', $templateId,
$template->getTitle());
396 $this->tpl->setContent($confirm->getHTML());
405 $this->error->raiseError($this->lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
408 $templateIds = $this->
http->request()->getParsedBody()[
'tpl_id'] ?? array();
409 if (is_array($templateIds) && count($templateIds) > 0) {
410 $templateIds = array_filter(array_map(
'intval', $templateIds));
412 $templateId = $this->
http->request()->getQueryParams()[
'tpl_id'] ??
'';
413 if (is_numeric($templateId) && $templateId > 0) {
414 $templateIds = array_filter(array((
int) $templateId));
416 $templateIds = array();
420 if (0 === count($templateIds)) {
426 $this->service->deleteTemplatesByIds($templateIds);
428 if (1 === count($templateIds)) {
429 \ilUtil::sendSuccess($this->lng->txt(
'mail_tpl_deleted_s'),
true);
431 \ilUtil::sendSuccess($this->lng->txt(
'mail_tpl_deleted_p'),
true);
433 $this->ctrl->redirect($this,
'showTemplates');
441 $triggerValue = $this->
http->request()->getQueryParams()[
'triggerValue'] ??
'';
444 $placeholders = new \ilManualPlaceholderInputGUI(
'm_message');
445 $placeholders->setInstructionText($this->lng->txt(
'mail_nacc_use_placeholder'));
446 $placeholders->setAdviseText(sprintf($this->lng->txt(
'placeholders_advise'),
'<br />'));
449 foreach (
$context->getPlaceholders() as
$key => $value) {
450 $placeholders->addPlaceholder($value[
'placeholder'], $value[
'label']);
453 $placeholders->render(
true);
464 $form = new \ilPropertyFormGUI();
466 $title = new \ilTextInputGUI($this->lng->txt(
'mail_template_title'),
'title');
467 $title->setRequired(
true);
471 $context = new \ilRadioGroupInputGUI($this->lng->txt(
'mail_template_context'),
'context');
475 if (count($contexts) <= 1) {
477 $this->ctrl->redirect($this,
'showTemplates');
480 $context_sort = array();
481 $context_options = array();
482 $generic_context = new \ilMailTemplateGenericContext();
483 foreach ($contexts as $ctx) {
484 if ($ctx->getId() != $generic_context->getId()) {
485 $context_options[$ctx->getId()] = $ctx;
486 $context_sort[$ctx->getId()] = $ctx->getTitle();
489 asort($context_sort);
491 foreach ($context_sort as
$id =>
$title) {
492 $ctx = $context_options[
$id];
493 $option = new \ilRadioOption($ctx->getTitle(), $ctx->getId());
494 $option->setInfo($ctx->getDescription());
505 $hidden = new \ilHiddenInputGUI(
'lang');
506 $hidden->setValue($this->lng->getLangKey());
507 $form->addItem($hidden);
509 $subject = new \ilTextInputGUI($this->lng->txt(
'subject'),
'm_subject');
511 $subject->setSize(50);
512 $form->addItem($subject);
514 $message = new \ilTextAreaInputGUI($this->lng->txt(
'message'),
'm_message');
521 $placeholders = new \ilManualPlaceholderInputGUI(
'm_message');
523 $placeholders->setInstructionText($this->lng->txt(
'mail_nacc_use_placeholder'));
524 $placeholders->setAdviseText(sprintf($this->lng->txt(
'placeholders_advise'),
'<br />'));
525 $placeholders->supportsRerenderSignal(
527 $this->ctrl->getLinkTarget($this,
'getAjaxPlaceholdersById',
'',
true,
false)
530 $context_id = $generic_context->getId();
535 foreach (
$context->getPlaceholders() as
$key => $value) {
536 $placeholders->addPlaceholder($value[
'placeholder'], $value[
'label']);
538 $form->addItem($placeholders);
540 $id = new \ilHiddenInputGUI(
'tpl_id');
543 $form->setTitle($this->lng->txt(
'mail_edit_tpl'));
544 $form->setFormAction($this->ctrl->getFormaction($this,
'updateTemplate'));
547 $form->addCommandButton(
'updateTemplate', $this->lng->txt(
'save'));
550 $form->setTitle($this->lng->txt(
'mail_create_tpl'));
551 $form->setFormAction($this->ctrl->getFormaction($this,
'insertTemplate'));
554 $form->addCommandButton(
'insertTemplate', $this->lng->txt(
'save'));
559 $form->addCommandButton(
'showTemplates', $this->lng->txt(
'cancel'));
561 $form->addCommandButton(
'showTemplates', $this->lng->txt(
'back'));
573 $this->error->raiseError($this->lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
576 $templateId = $this->
http->request()->getQueryParams()[
'tpl_id'] ?? 0;
578 if (!is_numeric($templateId) || $templateId < 1) {
585 $template = $this->service->loadTemplateForId((
int) $templateId);
586 $this->service->unsetAsContextDefault(
$template);
593 \ilUtil::sendSuccess($this->lng->txt(
'saved_successfully'),
true);
594 $this->ctrl->redirect($this,
'showTemplates');
603 $this->error->raiseError($this->lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
606 $templateId = $this->
http->request()->getQueryParams()[
'tpl_id'] ?? 0;
608 if (!is_numeric($templateId) || $templateId < 1) {
615 $template = $this->service->loadTemplateForId((
int) $templateId);
616 $this->service->setAsContextDefault(
$template);
623 \ilUtil::sendSuccess($this->lng->txt(
'saved_successfully'),
true);
624 $this->ctrl->redirect($this,
'showTemplates');
An entity that renders components to a string output.
This class provides processing control methods.
class ilRbacSystem system function like checkAccess, addActiveRole ...
populateFormWithTemplate(\ilPropertyFormGUI $form, \ilMailTemplate $template)
static getTemplateContextById($a_id)
Class ilMailTemplateService.
if(!array_key_exists('StateId', $_REQUEST)) $id
getAjaxPlaceholdersById()
Provides an interface to the ILIAS HTTP services.
catch(Exception $e) $message
static http()
Fetches the global http state from ILIAS.
__construct(\ilObject $parentObject, \ilTemplate $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.
This is how the factory for UI elements looks.
showEditTemplateForm(\ilPropertyFormGUI $form=null)
static getTemplateContexts($a_id=null)
Returns an array of mail template contexts, the key of each entry matches its id. ...
special template class to simplify handling of ITX/PEAR
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
getTemplateForm(\ilMailTemplate $template=null)
showInsertTemplateForm(\ilPropertyFormGUI $form=null)