1 <?php declare(strict_types=1);
85 $tpl = $DIC->ui()->mainTemplate();
95 $lng = $DIC->language();
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');
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) {
297 $form->getItemByPostVar(
'context')->setAlert($this->lng->txt(
'mail_template_no_valid_context'));
301 $form->setValuesByPost();
316 $templateId = $this->
http->request()->getQueryParams()[
'tpl_id'] ?? 0;
318 if (!is_numeric($templateId) || $templateId < 1) {
325 $template = $this->service->loadTemplateForId((
int) $templateId);
335 $this->tpl->setContent(
$form->getHTML());
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'));
447 $placeholders->setAdviseText(sprintf($this->lng->txt(
'placeholders_advise'),
'<br />'));
450 foreach (
$context->getPlaceholders() as $key => $value) {
451 $placeholders->addPlaceholder($value[
'placeholder'], $value[
'label']);
454 $placeholders->render(
true);
467 $title =
new ilTextInputGUI($this->lng->txt(
'mail_template_title'),
'title');
468 $title->setRequired(
true);
470 $form->addItem($title);
476 if (count($contexts) <= 1) {
478 $this->ctrl->redirect($this,
'showTemplates');
481 $context_sort = array();
482 $context_options = array();
484 foreach ($contexts as $ctx) {
485 if ($ctx->getId() != $generic_context->getId()) {
486 $context_options[$ctx->getId()] = $ctx;
487 $context_sort[$ctx->getId()] = $ctx->getTitle();
490 asort($context_sort);
492 foreach ($context_sort as $id => $title) {
493 $ctx = $context_options[$id];
494 $option =
new ilRadioOption($ctx->getTitle(), $ctx->getId());
495 $option->
setInfo($ctx->getDescription());
507 $hidden->setValue($this->lng->getLangKey());
508 $form->addItem($hidden);
510 $subject =
new ilTextInputGUI($this->lng->txt(
'subject'),
'm_subject');
512 $subject->setSize(50);
513 $form->addItem($subject);
524 $placeholders->setInstructionText($this->lng->txt(
'mail_nacc_use_placeholder'));
525 $placeholders->setAdviseText(sprintf($this->lng->txt(
'placeholders_advise'),
'<br />'));
526 $placeholders->supportsRerenderSignal(
528 $this->ctrl->getLinkTarget($this,
'getAjaxPlaceholdersById',
'',
true,
false)
530 if ($template === null) {
531 $context_id = $generic_context->getId();
533 $context_id = $template->getContext();
536 foreach (
$context->getPlaceholders() as $key => $value) {
537 $placeholders->addPlaceholder($value[
'placeholder'], $value[
'label']);
539 $form->addItem($placeholders);
544 $form->setTitle($this->lng->txt(
'mail_edit_tpl'));
545 $form->setFormAction($this->ctrl->getFormaction($this,
'updateTemplate'));
548 $form->addCommandButton(
'updateTemplate', $this->lng->txt(
'save'));
551 $form->setTitle($this->lng->txt(
'mail_create_tpl'));
552 $form->setFormAction($this->ctrl->getFormaction($this,
'insertTemplate'));
555 $form->addCommandButton(
'insertTemplate', $this->lng->txt(
'save'));
560 $form->addCommandButton(
'showTemplates', $this->lng->txt(
'cancel'));
562 $form->addCommandButton(
'showTemplates', $this->lng->txt(
'back'));
574 $this->error->raiseError($this->lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
577 $templateId = $this->
http->request()->getQueryParams()[
'tpl_id'] ?? 0;
579 if (!is_numeric($templateId) || $templateId < 1) {
586 $template = $this->service->loadTemplateForId((
int) $templateId);
587 $this->service->unsetAsContextDefault($template);
594 ilUtil::sendSuccess($this->lng->txt(
'saved_successfully'),
true);
595 $this->ctrl->redirect($this,
'showTemplates');
604 $this->error->raiseError($this->lng->txt(
'msg_no_perm_write'), $this->error->WARNING);
607 $templateId = $this->
http->request()->getQueryParams()[
'tpl_id'] ?? 0;
609 if (!is_numeric($templateId) || $templateId < 1) {
616 $template = $this->service->loadTemplateForId((
int) $templateId);
617 $this->service->setAsContextDefault($template);
624 ilUtil::sendSuccess($this->lng->txt(
'saved_successfully'),
true);
625 $this->ctrl->redirect($this,
'showTemplates');
This class represents an option in a radio group.
An entity that renders components to a string output.
This class provides processing control methods.
class ilRbacSystem system function like checkAccess, addActiveRole ...
showEditTemplateForm(ilPropertyFormGUI $form=null)
static getTemplateContextById($a_id)
getTemplateForm(ilMailTemplate $template=null)
Class ilMailTemplateService.
__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.
getAjaxPlaceholdersById()
setInfo($a_info)
Set Info.
Class ilMailTemplateTableGUI.
Provides an interface to the ILIAS HTTP services.
static http()
Fetches the global http state from ILIAS.
populateFormWithTemplate(ilPropertyFormGUI $form, ilMailTemplate $template)
Class ilGlobalPageTemplate.
This is how the factory for UI elements looks.
static getTemplateContexts($a_id=null)
Returns an array of mail template contexts, the key of each entry matches its id. ...
showInsertTemplateForm(ilPropertyFormGUI $form=null)
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.
This class represents a text area property in a property form.
Confirmation screen class.