ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilMailTemplateGUI Class Reference

Class ilMailTemplateGUI. More...

+ Collaboration diagram for ilMailTemplateGUI:

Public Member Functions

 __construct (\ilObject $parentObject)
 
 executeCommand ()
 
 getAjaxPlaceholdersById ()
 

Protected Member Functions

 showTemplates ()
 
 insertTemplate ()
 
 showInsertTemplateForm (ilPropertyFormGUI $form=null)
 
 updateTemplate ()
 
 showEditTemplateForm (ilPropertyFormGUI $form=null)
 
 populateFormWithTemplate (ilPropertyFormGUI $form, ilMailTemplate $template)
 
 confirmDeleteTemplate ()
 
 deleteTemplate ()
 
 getTemplateForm (ilMailTemplate $template=null)
 

Protected Attributes

 $form
 
 $tpl
 
 $ctrl
 
 $lng
 
 $toolbar
 
 $rbacsystem
 
 $parentObject
 
 $error
 

Private Member Functions

 isEditingAllowed ()
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilMailTemplateGUI::__construct ( \ilObject  $parentObject)

Definition at line 61 of file class.ilMailTemplateGUI.php.

References $DIC, and $parentObject.

62  {
63  global $DIC;
64 
65  $this->parentObject = $parentObject;
66 
67  $this->tpl = $DIC->ui()->mainTemplate();
68  $this->ctrl = $DIC->ctrl();
69  $this->lng = $DIC->language();
70  $this->toolbar = $DIC->toolbar();
71  $this->rbacsystem = $DIC->rbac()->system();
72  $this->error = $DIC['ilErr'];
73 
74  $this->lng->loadLanguageModule('meta');
75 
76  $this->provider = new ilMailTemplateDataProvider();
77  }
global $DIC
Definition: saml.php:7
Class ilMailTemplateDataProvider.

Member Function Documentation

◆ confirmDeleteTemplate()

ilMailTemplateGUI::confirmDeleteTemplate ( )
protected

Definition at line 290 of file class.ilMailTemplateGUI.php.

References $_GET, $_POST, $template, array, isEditingAllowed(), ilUtil\sendFailure(), and showTemplates().

291  {
292  if (!$this->isEditingAllowed()) {
293  $this->error->raiseError($this->lng->txt('msg_no_perm_write'), $this->error->WARNING);
294  }
295 
296  if (isset($_POST['tpl_id']) && is_array($_POST['tpl_id']) && count($_POST['tpl_id']) > 0) {
297  $tpl_ids = array_filter(array_map('intval', $_POST['tpl_id']));
298  } else {
299  if (isset($_GET['tpl_id']) && strlen($_GET['tpl_id'])) {
300  $tpl_ids = array_filter(array((int) $_GET['tpl_id']));
301  } else {
302  $tpl_ids = array();
303  }
304  }
305 
306  if (count($tpl_ids) == 0) {
307  ilUtil::sendFailure($this->lng->txt('select_one'));
308  $this->showTemplates();
309  return;
310  }
311 
312  require_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
313  $confirm = new ilConfirmationGUI();
314  $confirm->setFormAction($this->ctrl->getFormAction($this, 'deleteTemplate'));
315  $confirm->setHeaderText($this->lng->txt('mail_sure_delete_entry'));
316  $confirm->setConfirm($this->lng->txt('confirm'), 'deleteTemplate');
317  $confirm->setCancel($this->lng->txt('cancel'), 'showTemplates');
318 
319  foreach ($tpl_ids as $tpl_id) {
320  $template = $this->provider->getTemplateById((int) $tpl_id);
321  $confirm->addItem('tpl_id[]', $tpl_id, $template->getTitle());
322  }
323  $this->tpl->setContent($confirm->getHTML());
324  }
$template
$_GET["client_id"]
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$_POST["username"]
Confirmation screen class.
+ Here is the call graph for this function:

◆ deleteTemplate()

ilMailTemplateGUI::deleteTemplate ( )
protected

Definition at line 329 of file class.ilMailTemplateGUI.php.

References $_POST, isEditingAllowed(), ilUtil\sendFailure(), ilUtil\sendSuccess(), and showTemplates().

330  {
331  if (!$this->isEditingAllowed()) {
332  $this->error->raiseError($this->lng->txt('msg_no_perm_write'), $this->error->WARNING);
333  }
334 
335  if (isset($_POST['tpl_id']) && is_array($_POST['tpl_id']) && count($_POST['tpl_id']) > 0) {
336  $tpl_ids = array_filter(array_map('intval', $_POST['tpl_id']));
337  if (0 == count($tpl_ids)) {
338  ilUtil::sendFailure($this->lng->txt('select_one'));
339  $this->showTemplates();
340  return;
341  }
342  } else {
343  ilUtil::sendFailure($this->lng->txt('select_one'));
344  $this->showTemplates();
345  return;
346  }
347 
348  $this->provider->deleteTemplates($tpl_ids);
349 
350  if (1 == count($tpl_ids)) {
351  ilUtil::sendSuccess($this->lng->txt('mail_tpl_deleted_s'), true);
352  } else {
353  ilUtil::sendSuccess($this->lng->txt('mail_tpl_deleted_p'), true);
354  }
355  $this->ctrl->redirect($this, 'showTemplates');
356  }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$_POST["username"]
+ Here is the call graph for this function:

◆ executeCommand()

ilMailTemplateGUI::executeCommand ( )

Definition at line 90 of file class.ilMailTemplateGUI.php.

91  {
92  $next_class = $this->ctrl->getNextClass($this);
93  $cmd = $this->ctrl->getCmd();
94 
95  switch ($next_class) {
96  default:
97  if (!$cmd || !method_exists($this, $cmd)) {
98  $cmd = 'showTemplates';
99  }
100 
101  $this->$cmd();
102  break;
103  }
104  }

◆ getAjaxPlaceholdersById()

ilMailTemplateGUI::getAjaxPlaceholdersById ( )

Definition at line 358 of file class.ilMailTemplateGUI.php.

References $_GET, $key, exit, ilMailTemplateService\getTemplateContextById(), and ilUtil\stripSlashes().

359  {
360  $context_id = ilUtil::stripSlashes($_GET['triggerValue']);
361  require_once 'Services/Mail/classes/Form/class.ilManualPlaceholderInputGUI.php';
362  $placeholders = new ilManualPlaceholderInputGUI('m_message');
363  $placeholders->setInstructionText($this->lng->txt('mail_nacc_use_placeholder'));
364  $placeholders->setAdviseText(sprintf($this->lng->txt('placeholders_advise'), '<br />'));
365  $context = ilMailTemplateService::getTemplateContextById($context_id);
366  foreach ($context->getPlaceholders() as $key => $value) {
367  $placeholders->addPlaceholder($value['placeholder'], $value['label']);
368  }
369  $placeholders->render(true);
370  exit();
371  }
$_GET["client_id"]
Class ilManualPlaceholderInputGUI.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ getTemplateForm()

ilMailTemplateGUI::getTemplateForm ( ilMailTemplate  $template = null)
protected
Parameters
ilMailTemplate$template
Returns
ilPropertyFormGUI

Definition at line 377 of file class.ilMailTemplateGUI.php.

References $form, $id, $key, $message, $template, $title, array, ilMailTemplateService\getTemplateContextById(), ilMailTemplateService\getTemplateContexts(), isEditingAllowed(), ilUtil\sendFailure(), ilFormPropertyGUI\setDisabled(), and ilRadioOption\setInfo().

Referenced by insertTemplate(), showEditTemplateForm(), showInsertTemplateForm(), and updateTemplate().

378  {
379  $form = new ilPropertyFormGUI();
380 
381  $title = new ilTextInputGUI($this->lng->txt('mail_template_title'), 'title');
382  $title->setRequired(true);
383  $title->setDisabled(!$this->isEditingAllowed());
384  $form->addItem($title);
385 
386  $context = new ilRadioGroupInputGUI($this->lng->txt('mail_template_context'), 'context');
387  $context->setDisabled(!$this->isEditingAllowed());
389 
390  if (count($contexts) <= 1) {
391  ilUtil::sendFailure($this->lng->txt('mail_template_no_context_available'), true);
392  $this->ctrl->redirect($this, 'showTemplates');
393  }
394 
395  $context_sort = array();
396  $context_options = array();
397  $generic_context = new ilMailTemplateGenericContext();
398  foreach ($contexts as $ctx) {
399  if ($ctx->getId() != $generic_context->getId()) {
400  $context_options[$ctx->getId()] = $ctx;
401  $context_sort[$ctx->getId()] = $ctx->getTitle();
402  }
403  }
404  asort($context_sort);
405  $first = null;
406  foreach ($context_sort as $id => $title) {
407  $ctx = $context_options[$id];
408  $option = new ilRadioOption($ctx->getTitle(), $ctx->getId());
409  $option->setInfo($ctx->getDescription());
410  $context->addOption($option);
411 
412  if (!$first) {
413  $first = $id;
414  }
415  }
416  $context->setValue($first);
417  $context->setRequired(true);
418  $form->addItem($context);
419 
420  $hidde_language = new ilHiddenInputGUI('lang');
421  $hidde_language->setValue($this->lng->getLangKey());
422  $form->addItem($hidde_language);
423 
424  $subject = new ilTextInputGUI($this->lng->txt('subject'), 'm_subject');
425  $subject->setDisabled(!$this->isEditingAllowed());
426  $subject->setRequired(true);
427  $subject->setSize(50);
428  $form->addItem($subject);
429 
430  $message = new ilTextAreaInputGUI($this->lng->txt('message'), 'm_message');
431  $message->setDisabled(!$this->isEditingAllowed());
432  $message->setRequired(true);
433  $message->setCols(60);
434  $message->setRows(10);
435  $form->addItem($message);
436 
437  require_once 'Services/Mail/classes/Form/class.ilManualPlaceholderInputGUI.php';
438  $placeholders = new ilManualPlaceholderInputGUI('m_message');
439  $placeholders->setDisabled(!$this->isEditingAllowed());
440  $placeholders->setInstructionText($this->lng->txt('mail_nacc_use_placeholder'));
441  $placeholders->setAdviseText(sprintf($this->lng->txt('placeholders_advise'), '<br />'));
442  $placeholders->supportsRerenderSignal(
443  'context',
444  $this->ctrl->getLinkTarget($this, 'getAjaxPlaceholdersById', '', true, false)
445  );
446  if ($template === null) {
447  $context_id = $generic_context->getId();
448  } else {
449  $context_id = $template->getContext();
450  }
451  $context = ilMailTemplateService::getTemplateContextById($context_id);
452  foreach ($context->getPlaceholders() as $key => $value) {
453  $placeholders->addPlaceholder($value['placeholder'], $value['label']);
454  }
455  $form->addItem($placeholders);
456  if ($template instanceof ilMailTemplate && $template->getTplId() > 0) {
457  $id = new ilHiddenInputGUI('tpl_id');
458  $form->addItem($id);
459 
460  $form->setTitle($this->lng->txt('mail_edit_tpl'));
461  $form->setFormAction($this->ctrl->getFormaction($this, 'updateTemplate'));
462 
463  if ($this->isEditingAllowed()) {
464  $form->addCommandButton('updateTemplate', $this->lng->txt('save'));
465  }
466  } else {
467  $form->setTitle($this->lng->txt('mail_create_tpl'));
468  $form->setFormAction($this->ctrl->getFormaction($this, 'insertTemplate'));
469 
470  if ($this->isEditingAllowed()) {
471  $form->addCommandButton('insertTemplate', $this->lng->txt('save'));
472  }
473  }
474 
475  if ($this->isEditingAllowed()) {
476  $form->addCommandButton('showTemplates', $this->lng->txt('cancel'));
477  } else {
478  $form->addCommandButton('showTemplates', $this->lng->txt('back'));
479  }
480 
481  return $form;
482  }
This class represents an option in a radio group.
This class represents a property form user interface.
if(!array_key_exists('StateId', $_REQUEST)) $id
Class ilMailTemplate.
setInfo($a_info)
Set Info.
static getTemplateContexts($a_id=null)
Returns an array of mail template contexts, the key of each entry matches its id. ...
Class ilManualPlaceholderInputGUI.
This class represents a hidden form property in a property form.
catch(Exception $e) $message
This class represents a property in a property form.
This class represents a text property in a property form.
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
This class represents a text area property in a property form.
$key
Definition: croninfo.php:18
setDisabled($a_disabled)
Set Disabled.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insertTemplate()

ilMailTemplateGUI::insertTemplate ( )
protected

Definition at line 133 of file class.ilMailTemplateGUI.php.

References $form, $template, ilMailTemplateService\getTemplateContextById(), getTemplateForm(), isEditingAllowed(), ilUtil\sendFailure(), ilUtil\sendSuccess(), and showInsertTemplateForm().

134  {
135  if (!$this->isEditingAllowed()) {
136  $this->error->raiseError($this->lng->txt('msg_no_perm_write'), $this->error->WARNING);
137  }
138 
139  $form = $this->getTemplateForm();
140 
141  if (!$form->checkInput()) {
142  $form->setValuesByPost();
144  return;
145  }
146 
147  $generic_context = new ilMailTemplateGenericContext();
148  if ($form->getInput('context') == $generic_context->getId()) {
149  $form->getItemByPostVar('context')->setAlert($this->lng->txt('mail_template_no_valid_context'));
150  $form->setValuesByPost();
152  return;
153  }
154 
155  try {
156  $context = ilMailTemplateService::getTemplateContextById($form->getInput('context'));
157  $template = new ilMailTemplate();
158  $template->setTitle($form->getInput('title'));
159  $template->setContext($context->getId());
160  $template->setLang($form->getInput('lang'));
161  $template->setSubject($form->getInput('m_subject'));
162  $template->setMessage($form->getInput('m_message'));
163  $template->insert();
164 
165  ilUtil::sendSuccess($this->lng->txt('saved_successfully'), true);
166  $this->ctrl->redirect($this, 'showTemplates');
167  } catch (Exception $e) {
168  $form->getItemByPostVar('context')->setAlert($this->lng->txt('mail_template_no_valid_context'));
169  ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
170  }
171 
172  $form->setValuesByPost();
174  }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
$template
getTemplateForm(ilMailTemplate $template=null)
Class ilMailTemplate.
showInsertTemplateForm(ilPropertyFormGUI $form=null)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
+ Here is the call graph for this function:

◆ isEditingAllowed()

ilMailTemplateGUI::isEditingAllowed ( )
private
Returns
bool

Definition at line 82 of file class.ilMailTemplateGUI.php.

Referenced by confirmDeleteTemplate(), deleteTemplate(), getTemplateForm(), insertTemplate(), showTemplates(), and updateTemplate().

83  {
84  return $this->rbacsystem->checkAccess('write', $this->parentObject->getRefId());
85  }
+ Here is the caller graph for this function:

◆ populateFormWithTemplate()

ilMailTemplateGUI::populateFormWithTemplate ( ilPropertyFormGUI  $form,
ilMailTemplate  $template 
)
protected
Parameters
ilPropertyFormGUI$form
ilMailTemplate$template

Definition at line 275 of file class.ilMailTemplateGUI.php.

References array, ilMailTemplate\getContext(), ilMailTemplate\getLang(), ilMailTemplate\getMessage(), ilMailTemplate\getSubject(), ilMailTemplate\getTitle(), ilMailTemplate\getTplId(), and ilPropertyFormGUI\setValuesByArray().

Referenced by showEditTemplateForm().

276  {
277  $form->setValuesByArray(array(
278  'tpl_id' => $template->getTplId(),
279  'title' => $template->getTitle(),
280  'context' => $template->getContext(),
281  'lang' => $template->getLang(),
282  'm_subject' => $template->getSubject(),
283  'm_message' => $template->getMessage()
284  ));
285  }
Create styles array
The data for the language used.
setValuesByArray($a_values, $a_restrict_to_value_keys=false)
Set form values from an array.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showEditTemplateForm()

ilMailTemplateGUI::showEditTemplateForm ( ilPropertyFormGUI  $form = null)
protected
Parameters
ilPropertyFormGUI$form

Definition at line 248 of file class.ilMailTemplateGUI.php.

References $_GET, $form, $template, getTemplateForm(), populateFormWithTemplate(), ilUtil\sendFailure(), and showTemplates().

Referenced by updateTemplate().

249  {
250  if (!($form instanceof ilPropertyFormGUI)) {
251  if (!isset($_GET['tpl_id']) || !strlen($_GET['tpl_id'])) {
252  ilUtil::sendFailure($this->lng->txt('mail_template_missing_id'));
253  $this->showTemplates();
254  return;
255  }
256 
257  $template = $this->provider->getTemplateById((int) $_GET['tpl_id']);
258  if (!($template instanceof ilMailTemplate)) {
259  ilUtil::sendFailure($this->lng->txt('mail_template_missing_id'));
260  $this->showTemplates();
261  return;
262  }
263 
264  $form = $this->getTemplateForm($template);
265  $this->populateFormWithTemplate($form, $template);
266  }
267 
268  $this->tpl->setContent($form->getHTML());
269  }
$template
This class represents a property form user interface.
$_GET["client_id"]
getTemplateForm(ilMailTemplate $template=null)
Class ilMailTemplate.
populateFormWithTemplate(ilPropertyFormGUI $form, ilMailTemplate $template)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showInsertTemplateForm()

ilMailTemplateGUI::showInsertTemplateForm ( ilPropertyFormGUI  $form = null)
protected
Parameters
ilPropertyFormGUI$form

Definition at line 179 of file class.ilMailTemplateGUI.php.

References $form, and getTemplateForm().

Referenced by insertTemplate().

180  {
181  if (!($form instanceof ilPropertyFormGUI)) {
182  $form = $this->getTemplateForm();
183  }
184 
185  $this->tpl->setContent($form->getHTML());
186  }
This class represents a property form user interface.
getTemplateForm(ilMailTemplate $template=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showTemplates()

ilMailTemplateGUI::showTemplates ( )
protected

Definition at line 109 of file class.ilMailTemplateGUI.php.

References $tbl, ilLinkButton\getInstance(), ilMailTemplateService\getTemplateContexts(), isEditingAllowed(), and ilUtil\sendFailure().

Referenced by confirmDeleteTemplate(), deleteTemplate(), showEditTemplateForm(), and updateTemplate().

110  {
111  require_once 'Services/UIComponent/Button/classes/class.ilLinkButton.php';
112  require_once 'Services/Mail/classes/class.ilMailTemplateTableGUI.php';
113 
115  if (count($contexts) <= 1) {
116  ilUtil::sendFailure($this->lng->txt('mail_template_no_context_available'));
117  } elseif ($this->isEditingAllowed()) {
118  $create_tpl_button = ilLinkButton::getInstance();
119  $create_tpl_button->setCaption('mail_new_template');
120  $create_tpl_button->setUrl($this->ctrl->getLinkTarget($this, 'showInsertTemplateForm'));
121  $this->toolbar->addButtonInstance($create_tpl_button);
122  }
123 
124  $tbl = new ilMailTemplateTableGUI($this, 'showTemplates', !$this->isEditingAllowed());
125  $tbl->setData($this->provider->getTableData());
126 
127  $this->tpl->setContent($tbl->getHTML());
128  }
$tbl
Definition: example_048.php:81
static getTemplateContexts($a_id=null)
Returns an array of mail template contexts, the key of each entry matches its id. ...
Class ilMailTemplateTableGUI.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateTemplate()

ilMailTemplateGUI::updateTemplate ( )
protected

Definition at line 191 of file class.ilMailTemplateGUI.php.

References $_POST, $form, $template, ilMailTemplateService\getTemplateContextById(), getTemplateForm(), isEditingAllowed(), ilUtil\sendFailure(), ilUtil\sendSuccess(), showEditTemplateForm(), and showTemplates().

192  {
193  if (!$this->isEditingAllowed()) {
194  $this->error->raiseError($this->lng->txt('msg_no_perm_write'), $this->error->WARNING);
195  }
196 
197  if (!isset($_POST['tpl_id']) || !strlen($_POST['tpl_id'])) {
198  ilUtil::sendFailure($this->lng->txt('mail_template_missing_id'));
199  $this->showTemplates();
200  return;
201  }
202 
203  $template = $this->provider->getTemplateById((int) $_POST['tpl_id']);
204  if (!($template instanceof ilMailTemplate)) {
205  ilUtil::sendFailure($this->lng->txt('mail_template_missing_id'));
206  $this->showTemplates();
207  return;
208  }
209 
210  $form = $this->getTemplateForm();
211  if (!$form->checkInput()) {
212  $form->setValuesByPost();
213  $this->showEditTemplateForm($form);
214  return;
215  }
216 
217  $generic_context = new ilMailTemplateGenericContext();
218  if ($form->getInput('context') == $generic_context->getId()) {
219  $form->getItemByPostVar('context')->setAlert($this->lng->txt('mail_template_no_valid_context'));
220  $form->setValuesByPost();
221  $this->showEditTemplateForm($form);
222  return;
223  }
224 
225  try {
226  $context = ilMailTemplateService::getTemplateContextById($form->getInput('context'));
227  $template->setTitle($form->getInput('title'));
228  $template->setContext($context->getId());
229  $template->setLang($form->getInput('lang'));
230  $template->setSubject($form->getInput('m_subject'));
231  $template->setMessage($form->getInput('m_message'));
232  $template->update();
233 
234  ilUtil::sendSuccess($this->lng->txt('saved_successfully'), true);
235  $this->ctrl->redirect($this, 'showTemplates');
236  } catch (Exception $e) {
237  $form->getItemByPostVar('context')->setAlert($this->lng->txt('mail_template_no_valid_context'));
238  ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
239  }
240 
241  $form->setValuesByPost();
242  $this->showEditTemplateForm($form);
243  }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
showEditTemplateForm(ilPropertyFormGUI $form=null)
$template
getTemplateForm(ilMailTemplate $template=null)
Class ilMailTemplate.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$_POST["username"]
+ Here is the call graph for this function:

Field Documentation

◆ $ctrl

ilMailTemplateGUI::$ctrl
protected

Definition at line 31 of file class.ilMailTemplateGUI.php.

◆ $error

ilMailTemplateGUI::$error
protected

Definition at line 56 of file class.ilMailTemplateGUI.php.

◆ $form

ilMailTemplateGUI::$form
protected

◆ $lng

ilMailTemplateGUI::$lng
protected

Definition at line 36 of file class.ilMailTemplateGUI.php.

◆ $parentObject

ilMailTemplateGUI::$parentObject
protected

Definition at line 51 of file class.ilMailTemplateGUI.php.

Referenced by __construct().

◆ $rbacsystem

ilMailTemplateGUI::$rbacsystem
protected

Definition at line 46 of file class.ilMailTemplateGUI.php.

◆ $toolbar

ilMailTemplateGUI::$toolbar
protected

Definition at line 41 of file class.ilMailTemplateGUI.php.

◆ $tpl

ilMailTemplateGUI::$tpl
protected

Definition at line 26 of file class.ilMailTemplateGUI.php.


The documentation for this class was generated from the following file: