ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilMailTemplateGUI Class Reference

Class ilMailTemplateGUI. More...

+ Collaboration diagram for ilMailTemplateGUI:

Public Member Functions

 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
 

Detailed Description

Member Function Documentation

◆ confirmDeleteTemplate()

ilMailTemplateGUI::confirmDeleteTemplate ( )
protected

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

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

282  {
283  if(isset($_POST['tpl_id']) && is_array($_POST['tpl_id']) && count($_POST['tpl_id']) > 0)
284  {
285  $tpl_ids = array_filter(array_map('intval', $_POST['tpl_id']));
286  }
287  else if(isset($_GET['tpl_id']) && strlen($_GET['tpl_id']))
288  {
289  $tpl_ids = array_filter(array((int)$_GET['tpl_id']));
290  }
291  else
292  {
293  $tpl_ids = array();
294  }
295 
296  if(count($tpl_ids) == 0)
297  {
298  ilUtil::sendFailure($this->lng->txt('select_one'));
299  $this->showTemplates();
300  return;
301  }
302 
303  require_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
304  $confirm = new ilConfirmationGUI();
305  $confirm->setFormAction($this->ctrl->getFormAction($this, 'deleteTemplate'));
306  $confirm->setHeaderText($this->lng->txt('mail_sure_delete_entry'));
307  $confirm->setConfirm($this->lng->txt('confirm'), 'deleteTemplate');
308  $confirm->setCancel($this->lng->txt('cancel'), 'showTemplates');
309 
310  foreach($tpl_ids as $tpl_id)
311  {
312  $template = $this->provider->getTemplateById((int)$tpl_id);
313  $confirm->addItem('tpl_id[]', $tpl_id, $template->getTitle());
314  }
315  $this->tpl->setContent($confirm->getHTML());
316  }
$_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 321 of file class.ilMailTemplateGUI.php.

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

322  {
323  if(isset($_POST['tpl_id']) && is_array($_POST['tpl_id']) && count($_POST['tpl_id']) > 0)
324  {
325  $tpl_ids = array_filter(array_map('intval', $_POST['tpl_id']));
326  if(0 == count($tpl_ids))
327  {
328  ilUtil::sendFailure($this->lng->txt('select_one'));
329  $this->showTemplates();
330  return;
331  }
332  }
333  else
334  {
335  ilUtil::sendFailure($this->lng->txt('select_one'));
336  $this->showTemplates();
337  return;
338  }
339 
340  $this->provider->deleteTemplates($tpl_ids);
341 
342  if(1 == count($tpl_ids))
343  {
344  ilUtil::sendSuccess($this->lng->txt('mail_tpl_deleted_s'), true);
345  }
346  else
347  {
348  ilUtil::sendSuccess($this->lng->txt('mail_tpl_deleted_p'), true);
349  }
350  $this->ctrl->redirect($this, 'showTemplates');
351  }
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 69 of file class.ilMailTemplateGUI.php.

References $cmd.

70  {
71  $next_class = $this->ctrl->getNextClass($this);
72  $cmd = $this->ctrl->getCmd();
73 
74  switch($next_class)
75  {
76  default:
77  if(!$cmd || !method_exists($this, $cmd))
78  {
79  $cmd = 'showTemplates';
80  }
81 
82  $this->$cmd();
83  break;
84  }
85  }
$cmd
Definition: sahs_server.php:35

◆ getAjaxPlaceholdersById()

ilMailTemplateGUI::getAjaxPlaceholdersById ( )

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

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

354  {
355  $context_id = ilUtil::stripSlashes($_GET['context_id']);
356  require_once 'Services/Mail/classes/Form/class.ilManualPlaceholderInputGUI.php';
357  $placeholders = new ilManualPlaceholderInputGUI($this->ctrl->getLinkTarget($this, 'getAjaxPlaceholdersById', '', true, false));
358  $context = ilMailTemplateService::getTemplateContextById($context_id);
359  foreach( $context->getPlaceholders() as $key => $value)
360  {
361  $placeholders->addPlaceholder($value['placeholder'], $value['label'] );
362  }
363  $placeholders->render(true);
364  exit();
365  }
$_GET["client_id"]
Class ilManualPlaceholderInputGUI.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
+ Here is the call graph for this function:

◆ getTemplateForm()

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

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

References $form, $title, array, ilMailTemplateService\getTemplateContextById(), ilMailTemplateService\getTemplateContexts(), ilMailTemplate\getTplId(), ilUtil\sendFailure(), ilRadioOption\setInfo(), and ilFormPropertyGUI\setRequired().

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

372  {
373  $form = new ilPropertyFormGUI();
374 
375  $title = new ilTextInputGUI($this->lng->txt('mail_template_title'), 'title');
376  $title->setRequired(true);
377  $form->addItem($title);
378 
379  $context = new ilRadioGroupInputGUI($this->lng->txt('mail_template_context'), 'context');
381 
382  if(count($contexts) <= 1)
383  {
384  ilUtil::sendFailure($this->lng->txt('mail_template_no_context_available'), true);
385  $this->ctrl->redirect($this, 'showTemplates');
386  }
387 
388  $context_sort = array();
389  $context_options = array();
390  $generic_context = new ilMailTemplateGenericContext();
391  foreach($contexts as $ctx)
392  {
393  if($ctx->getId() != $generic_context->getId())
394  {
395  $context_options[$ctx->getId()] = $ctx;
396  $context_sort[$ctx->getId()] = $ctx->getTitle();
397  }
398  }
399  asort($context_sort);
400  $first = null;
401  foreach($context_sort as $id => $title)
402  {
403  $ctx = $context_options[$id];
404  $option = new ilRadioOption($ctx->getTitle(), $ctx->getId());
405  $option->setInfo($ctx->getDescription());
406  $context->addOption($option);
407 
408  if(!$first)
409  {
410  $first = $id;
411  }
412  }
413  $context->setValue($first);
414  $context->setRequired(true);
415  $form->addItem($context);
416 
417  /*$lang = new ilSelectInputGUI($this->lng->txt('language'), 'lang');
418  $options = array();
419  foreach($this->lng->getInstalledLanguages() as $iso2code)
420  {
421  $options[$iso2code] = $this->lng->txt('meta_l_' . $iso2code);
422  }
423  asort($options);
424  $lang->setOptions(array('' => $this->lng->txt('please_choose')) + $options);
425  $lang->setRequired(true);
426  $form->addItem($lang);*/
427  $hidde_language = new ilHiddenInputGUI('lang');
428  $hidde_language->setValue($this->lng->getLangKey());
429  $form->addItem($hidde_language);
430 
431  $subject = new ilTextInputGUI($this->lng->txt('subject'), 'm_subject');
432  $subject->setRequired(true);
433  $subject->setSize(50);
434  $form->addItem($subject);
435 
436  $message = new ilTextAreaInputGUI($this->lng->txt('message'), 'm_message');
437  $message->setRequired(true);
438  $message->setCols(60);
439  $message->setRows(10);
440  $form->addItem($message);
441 
442  require_once 'Services/Mail/classes/Form/class.ilManualPlaceholderInputGUI.php';
443  $placeholders = new ilManualPlaceholderInputGUI($this->ctrl->getLinkTarget($this, 'getAjaxPlaceholdersById', '', true, false));
444 
445  if( $template === null )
446  {
447  $context_id = $generic_context->getId();
448  }
449  else
450  {
451  $context_id = $template->getContext();
452  }
453  $context = ilMailTemplateService::getTemplateContextById($context_id);
454  foreach( $context->getPlaceholders() as $key => $value)
455  {
456  $placeholders->addPlaceholder($value['placeholder'], $value['label'] );
457  }
458  $form->addItem($placeholders);
459  if($template instanceof ilMailTemplate && $template->getTplId() > 0)
460  {
461  $id = new ilHiddenInputGUI('tpl_id');
462  $form->addItem($id);
463 
464  $form->setTitle($this->lng->txt('mail_edit_tpl'));
465  $form->setFormAction($this->ctrl->getFormaction($this, 'updateTemplate'));
466  $form->addCommandButton('updateTemplate', $this->lng->txt('save'));
467  }
468  else
469  {
470  $form->setTitle($this->lng->txt('mail_create_tpl'));
471  $form->setFormAction($this->ctrl->getFormaction($this, 'insertTemplate'));
472  $form->addCommandButton('insertTemplate', $this->lng->txt('save'));
473  }
474 
475  $form->addCommandButton('showTemplates', $this->lng->txt('cancel'));
476  return $form;
477  }
This class represents an option in a radio group.
This class represents a property form user interface.
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.
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.
setRequired($a_required)
Set Required.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insertTemplate()

ilMailTemplateGUI::insertTemplate ( )
protected

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

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

118  {
119  $form = $this->getTemplateForm();
120 
121  if(!$form->checkInput())
122  {
123  $form->setValuesByPost();
125  return;
126  }
127 
128  $generic_context = new ilMailTemplateGenericContext();
129  if($form->getInput('context') == $generic_context->getId())
130  {
131  $form->getItemByPostVar('context')->setAlert($this->lng->txt('mail_template_no_valid_context'));
132  $form->setValuesByPost();
134  return;
135  }
136 
137  try
138  {
139  $context = ilMailTemplateService::getTemplateContextById($form->getInput('context'));
140  $template = new ilMailTemplate();
141  $template->setTitle($form->getInput('title'));
142  $template->setContext($context->getId());
143  $template->setLang($form->getInput('lang'));
144  $template->setSubject($form->getInput('m_subject'));
145  $template->setMessage($form->getInput('m_message'));
146  $template->insert();
147 
148  ilUtil::sendSuccess($this->lng->txt('saved_successfully'), true);
149  $this->ctrl->redirect($this, 'showTemplates');
150  }
151  catch(Exception $e)
152  {
153  $form->getItemByPostVar('context')->setAlert($this->lng->txt('mail_template_no_valid_context'));
154  ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
155  }
156 
157  $form->setValuesByPost();
159  }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
showInsertTemplateForm(ilPropertyFormGUI $form=NULL)
getTemplateForm(ilMailTemplate $template=null)
Class ilMailTemplate.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
+ Here is the call graph for this function:

◆ populateFormWithTemplate()

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

Definition at line 266 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().

267  {
268  $form->setValuesByArray(array(
269  'tpl_id' => $template->getTplId(),
270  'title' => $template->getTitle(),
271  'context' => $template->getContext(),
272  'lang' => $template->getLang(),
273  'm_subject' => $template->getSubject(),
274  'm_message' => $template->getMessage()
275  ));
276  }
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 236 of file class.ilMailTemplateGUI.php.

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

Referenced by updateTemplate().

237  {
238  if(!($form instanceof ilPropertyFormGUI))
239  {
240  if(!isset($_GET['tpl_id']) || !strlen($_GET['tpl_id']))
241  {
242  ilUtil::sendFailure($this->lng->txt('mail_template_missing_id'));
243  $this->showTemplates();
244  return;
245  }
246 
247  $template = $this->provider->getTemplateById((int)$_GET['tpl_id']);
248  if(!($template instanceof ilMailTemplate))
249  {
250  ilUtil::sendFailure($this->lng->txt('mail_template_missing_id'));
251  $this->showTemplates();
252  return;
253  }
254 
255  $form = $this->getTemplateForm($template);
256  $this->populateFormWithTemplate($form, $template);
257  }
258 
259  $this->tpl->setContent($form->getHTML());
260  }
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 164 of file class.ilMailTemplateGUI.php.

References $form, and getTemplateForm().

Referenced by insertTemplate().

165  {
166  if(!($form instanceof ilPropertyFormGUI))
167  {
168  $form = $this->getTemplateForm();
169  }
170  $this->tpl->setContent($form->getHTML());
171  }
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 90 of file class.ilMailTemplateGUI.php.

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

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

91  {
92  require_once 'Services/UIComponent/Button/classes/class.ilLinkButton.php';
93  require_once 'Services/Mail/classes/class.ilMailTemplateTableGUI.php';
94 
96  if(count($contexts) <= 1)
97  {
98  ilUtil::sendFailure($this->lng->txt('mail_template_no_context_available'));
99  }
100  else
101  {
102  $create_tpl_button = ilLinkButton::getInstance();
103  $create_tpl_button->setCaption('mail_new_template');
104  $create_tpl_button->setUrl($this->ctrl->getLinkTarget($this, 'showInsertTemplateForm'));
105  $this->toolbar->addButtonInstance($create_tpl_button);
106  }
107 
108  $tbl = new ilMailTemplateTableGUI($this, 'showTemplates');
109  $tbl->setData($this->provider->getTableData());
110 
111  $this->tpl->setContent($tbl->getHTML());
112  }
$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 176 of file class.ilMailTemplateGUI.php.

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

177  {
178  if(!isset($_POST['tpl_id']) || !strlen($_POST['tpl_id']))
179  {
180  ilUtil::sendFailure($this->lng->txt('mail_template_missing_id'));
181  $this->showTemplates();
182  return;
183  }
184 
185  $template = $this->provider->getTemplateById((int)$_POST['tpl_id']);
186  if(!($template instanceof ilMailTemplate))
187  {
188  ilUtil::sendFailure($this->lng->txt('mail_template_missing_id'));
189  $this->showTemplates();
190  return;
191  }
192 
193  $form = $this->getTemplateForm();
194  if(!$form->checkInput())
195  {
196  $form->setValuesByPost();
197  $this->showEditTemplateForm($form);
198  return;
199  }
200 
201  $generic_context = new ilMailTemplateGenericContext();
202  if($form->getInput('context') == $generic_context->getId())
203  {
204  $form->getItemByPostVar('context')->setAlert($this->lng->txt('mail_template_no_valid_context'));
205  $form->setValuesByPost();
206  $this->showEditTemplateForm($form);
207  return;
208  }
209 
210  try
211  {
212  $context = ilMailTemplateService::getTemplateContextById($form->getInput('context'));
213  $template->setTitle($form->getInput('title'));
214  $template->setContext($context->getId());
215  $template->setLang($form->getInput('lang'));
216  $template->setSubject($form->getInput('m_subject'));
217  $template->setMessage($form->getInput('m_message'));
218  $template->update();
219 
220  ilUtil::sendSuccess($this->lng->txt('saved_successfully'), true);
221  $this->ctrl->redirect($this, 'showTemplates');
222  }
223  catch(Exception $e)
224  {
225  $form->getItemByPostVar('context')->setAlert($this->lng->txt('mail_template_no_valid_context'));
226  ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
227  }
228 
229  $form->setValuesByPost();
230  $this->showEditTemplateForm($form);
231  }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
getTemplateForm(ilMailTemplate $template=null)
Class ilMailTemplate.
showEditTemplateForm(ilPropertyFormGUI $form=NULL)
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.

◆ $form

ilMailTemplateGUI::$form
protected

◆ $lng

ilMailTemplateGUI::$lng
protected

Definition at line 36 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: