ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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.

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"]
Confirmation screen class.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$_POST['username']
Definition: cron.php:12

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

+ Here is the call graph for this function:

◆ deleteTemplate()

ilMailTemplateGUI::deleteTemplate ( )
protected

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

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.

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

+ Here is the call graph for this function:

◆ executeCommand()

ilMailTemplateGUI::executeCommand ( )

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

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

References $cmd.

◆ getAjaxPlaceholdersById()

ilMailTemplateGUI::getAjaxPlaceholdersById ( )

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

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 }
Class ilManualPlaceholderInputGUI.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
exit
Definition: login.php:54

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

+ 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.

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->setSize(50);
433 $form->addItem($subject);
434
435 $message = new ilTextAreaInputGUI($this->lng->txt('message'), 'm_message');
436 $message->setRequired(true);
437 $message->setCols(60);
438 $message->setRows(10);
439 $form->addItem($message);
440
441 require_once 'Services/Mail/classes/Form/class.ilManualPlaceholderInputGUI.php';
442 $placeholders = new ilManualPlaceholderInputGUI($this->ctrl->getLinkTarget($this, 'getAjaxPlaceholdersById', '', true, false));
443
444 if( $template === null )
445 {
446 $context_id = $generic_context->getId();
447 }
448 else
449 {
450 $context_id = $template->getContext();
451 }
452 $context = ilMailTemplateService::getTemplateContextById($context_id);
453 foreach( $context->getPlaceholders() as $key => $value)
454 {
455 $placeholders->addPlaceholder($value['placeholder'], $value['label'] );
456 }
457 $form->addItem($placeholders);
458 if($template instanceof ilMailTemplate && $template->getTplId() > 0)
459 {
460 $id = new ilHiddenInputGUI('tpl_id');
461 $form->addItem($id);
462
463 $form->setTitle($this->lng->txt('mail_edit_tpl'));
464 $form->setFormAction($this->ctrl->getFormaction($this, 'updateTemplate'));
465 $form->addCommandButton('updateTemplate', $this->lng->txt('save'));
466 }
467 else
468 {
469 $form->setTitle($this->lng->txt('mail_create_tpl'));
470 $form->setFormAction($this->ctrl->getFormaction($this, 'insertTemplate'));
471 $form->addCommandButton('insertTemplate', $this->lng->txt('save'));
472 }
473
474 $form->addCommandButton('showTemplates', $this->lng->txt('cancel'));
475 return $form;
476 }
This class represents a hidden form property in a property form.
static getTemplateContexts($a_id=null)
Returns an array of mail template contexts, the key of each entry matches its id.
Class ilMailTemplate.
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a text area property in a property form.
This class represents a text property in a property form.

References $form, ilMailTemplateService\getTemplateContextById(), ilMailTemplateService\getTemplateContexts(), ilMailTemplate\getTplId(), and ilUtil\sendFailure().

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

+ 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.

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 }
getTemplateForm(ilMailTemplate $template=null)
showInsertTemplateForm(ilPropertyFormGUI $form=NULL)

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

+ 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.

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 }

References $form, ilMailTemplate\getContext(), ilMailTemplate\getLang(), ilMailTemplate\getMessage(), ilMailTemplate\getSubject(), ilMailTemplate\getTitle(), and ilMailTemplate\getTplId().

Referenced by showEditTemplateForm().

+ 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.

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 }
populateFormWithTemplate(ilPropertyFormGUI $form, ilMailTemplate $template)

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

Referenced by updateTemplate().

+ 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.

165 {
166 if(!($form instanceof ilPropertyFormGUI))
167 {
168 $form = $this->getTemplateForm();
169 }
170 $this->tpl->setContent($form->getHTML());
171 }

References $form, and getTemplateForm().

Referenced by insertTemplate().

+ 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.

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 }
static getInstance()
Factory.
Class ilMailTemplateTableGUI.
$tbl
Definition: example_048.php:81

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

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

+ 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.

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();
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();
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();
231 }
showEditTemplateForm(ilPropertyFormGUI $form=NULL)

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

+ Here is the call graph for this function:

Field Documentation

◆ $ctrl

ilMailTemplateGUI::$ctrl
protected

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

◆ $form

◆ $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: