ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilMailFormGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/User/classes/class.ilObjUser.php';
5require_once 'Services/Mail/classes/class.ilMailbox.php';
6require_once 'Services/Mail/classes/class.ilFormatMail.php';
7require_once './Services/Mail/classes/class.ilFileDataMail.php';
8require_once 'Services/Mail/classes/class.ilMailFormCall.php';
9
18{
19 private $tpl = null;
20 private $ctrl = null;
21 private $lng = null;
22
23 private $umail = null;
24 private $mbox = null;
25 private $mfile = null;
26
27 public function __construct()
28 {
29 global $tpl, $ilCtrl, $lng, $ilUser;
30
31 $this->tpl = $tpl;
32 $this->ctrl = $ilCtrl;
33 $this->lng = $lng;
34
35 $this->umail = new ilFormatMail($ilUser->getId());
36 $this->mfile = new ilFileDataMail($ilUser->getId());
37 $this->mbox = new ilMailBox($ilUser->getId());
38
39 if(isset($_POST['mobj_id']) && (int)$_POST['mobj_id'])
40 {
41 $_GET['mobj_id'] = $_POST['mobj_id'];
42 }
43 // IF THERE IS NO OBJ_ID GIVEN GET THE ID OF MAIL ROOT NODE
44 if(!(int)$_GET['mobj_id'])
45 {
46 $_GET['mobj_id'] = $this->mbox->getInboxFolder();
47 }
48 $_GET['mobj_id'] = (int)$_GET['mobj_id'];
49 $this->ctrl->saveParameter($this, 'mobj_id');
50 }
51
52 public function executeCommand()
53 {
54 $forward_class = $this->ctrl->getNextClass($this);
55 switch($forward_class)
56 {
57 case 'ilmailfoldergui':
58 include_once 'Services/Mail/classes/class.ilMailFolderGUI.php';
59
60 $this->ctrl->forwardCommand(new ilMailFolderGUI());
61 break;
62
63 case 'ilmailattachmentgui':
64 include_once 'Services/Mail/classes/class.ilMailAttachmentGUI.php';
65
66 $this->ctrl->setReturn($this, "returnFromAttachments");
67 $this->ctrl->forwardCommand(new ilMailAttachmentGUI());
68 break;
69
70 case 'ilmailsearchgui':
71 include_once 'Services/Contact/classes/class.ilMailSearchGUI.php';
72
73 $this->ctrl->setReturn($this, "searchResults");
74 $this->ctrl->forwardCommand(new ilMailSearchGUI());
75 break;
76
77 case 'ilmailsearchcoursesgui':
78 include_once 'Services/Contact/classes/class.ilMailSearchCoursesGUI.php';
79
80 $this->ctrl->setReturn($this, "searchResults");
81 $this->ctrl->forwardCommand(new ilMailSearchCoursesGUI());
82 break;
83
84 case 'ilmailinglistsgui':
85 include_once 'Services/Contact/classes/class.ilMailingListsGUI.php';
86
87 $this->ctrl->setReturn($this, 'searchResults');
88 $this->ctrl->forwardCommand(new ilMailingListsGUI());
89 break;
90
91 case 'ilmailsearchgroupsgui':
92 include_once 'Services/Contact/classes/class.ilMailSearchGroupsGUI.php';
93
94 $this->ctrl->setReturn($this, "searchResults");
95 $this->ctrl->forwardCommand(new ilMailSearchGroupsGUI());
96 break;
97
98 default:
99 if (!($cmd = $this->ctrl->getCmd()))
100 {
101 $cmd = "showForm";
102 }
103
104 $this->$cmd();
105 break;
106 }
107 return true;
108 }
109
114 protected function decodeAttachmentFiles(array $files)
115 {
116 $decodedFiles = array();
117
118 foreach($files as $value)
119 {
120 if(is_file($this->mfile->getMailPath() . '/' . $GLOBALS['ilUser']->getId() . '_' . urldecode($value)))
121 {
122 $decodedFiles[] = urldecode($value);
123 }
124 }
125
126 return $decodedFiles;
127 }
128
129 public function sendMessage()
130 {
131 global $ilUser;
132
133 $files = $this->decodeAttachmentFiles(isset($_POST['attachments']) ? (array)$_POST['attachments'] : array());
134
135 $message = strip_tags(ilUtil::stripSlashes($_POST['m_message'], false));
136 $message = str_replace("\r", '', $message);
137 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
138 $message = $this->umail->formatLinebreakMessage($message);
139
140 $this->umail->setSaveInSentbox(true);
141
142 $m_type = isset($_POST["m_type"]) ? $_POST["m_type"] : array("normal");
143
144 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
145 if($errorMessage = $this->umail->sendMail(
149 ilUtil::securePlainString($_POST['m_subject']), $message,
150 $files,
151 $m_type,
152 (int)$_POST['use_placeholders']
153 )
154 )
155 {
156 $_POST['attachments'] = $files;
157 ilUtil::sendInfo($errorMessage);
158 }
159 else
160 {
161 $this->umail->savePostData($ilUser->getId(), array(), "", "", "", "", "", "", "", "");
162
163 $this->ctrl->setParameterByClass('ilmailgui', 'type', 'message_sent');
164
166 {
167 ilUtil::sendInfo($this->lng->txt('mail_message_send'), true);
169 }
170 else
171 $this->ctrl->redirectByClass('ilmailgui');
172 }
173
174 $this->showForm();
175 }
176
177 public function saveDraft()
178 {
179 if(!$_POST['m_subject'])
180 {
181 $_POST['m_subject'] = 'No title';
182 }
183
184 $draftFolderId = $this->mbox->getDraftsFolder();
185 $files = $this->decodeAttachmentFiles(isset($_POST['attachments']) ? (array)$_POST['attachments'] : array());
186
187 if($errorMessage = $this->umail->validateRecipients(
191 ))
192 {
193 $_POST['attachments'] = $files;
194 ilUtil::sendInfo($errorMessage);
195 $this->showForm();
196 return;
197 }
198
199 if(isset($_SESSION["draft"]))
200 {
201 $draftId = (int)$_SESSION['draft'];
202 unset($_SESSION['draft']);
203 }
204 else
205 {
206 $draftId = $this->umail->getNewDraftId($GLOBALS['ilUser']->getId(), $draftFolderId);
207 }
208
209 $this->umail->updateDraft($draftFolderId, $files,
213 $_POST['m_type'],
215 ilUtil::securePlainString($_POST['m_subject']),
216 ilUtil::securePlainString($_POST['m_message']),
217 $draftId,
218 (int)$_POST['use_placeholders'],
221 );
222
223 ilUtil::sendInfo($this->lng->txt('mail_saved'), true);
224
227 else
228 $this->ctrl->redirectByClass("ilmailfoldergui");
229
230 $this->showForm();
231 }
232
233 public function searchUsers($save = true)
234 {
235 global $ilUser, $ilCtrl;
236
237 $this->tpl->setTitle($this->lng->txt("mail"));
238
239 if ($save)
240 {
241 // decode post values
242 $files = array();
243 if(is_array($_POST['attachments']))
244 {
245 foreach($_POST['attachments'] as $value)
246 {
247 $files[] = urldecode($value);
248 }
249 }
250
251 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
252 $this->umail->savePostData($ilUser->getId(),
253 $files,
257 $_POST["m_type"],
259 ilUtil::securePlainString($_POST["m_subject"]),
260 ilUtil::securePlainString($_POST["m_message"]),
261 ilUtil::securePlainString($_POST['use_placeholders']),
264 );
265 }
266 include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
267 $form = new ilPropertyFormGUI();
268 $form->setId('search_rcp');
269 $form->setTitle($this->lng->txt('search_recipients'));
270 $form->setFormAction($ilCtrl->getFormAction($this, 'search'));
271
272 $inp = new ilTextInputGUI($this->lng->txt("search_for"), 'search');
273 $inp->setSize(30);
274 $dsDataLink = $ilCtrl->getLinkTarget($this, 'lookupRecipientAsync', '', true, false);
275 $inp->setDataSource($dsDataLink);
276
277 if (strlen(trim($_SESSION["mail_search_search"])) > 0)
278 {
279 $inp->setValue(ilUtil::prepareFormOutput(trim($_SESSION["mail_search_search"]), true));
280 }
281 $form->addItem($inp);
282
283 $form->addCommandButton('search', $this->lng->txt("search"));
284 $form->addCommandButton('cancelSearch', $this->lng->txt("cancel"));
285
286 $this->tpl->setContent($form->getHtml());
287 $this->tpl->show();
288 }
289
293 public function searchCoursesTo()
294 {
295 $this->saveMailBeforeSearch();
296
297 if($_SESSION['search_crs'])
298 {
299 $this->ctrl->setParameterByClass('ilmailsearchcoursesgui', 'cmd', 'showMembers');
300 }
301
302 $this->ctrl->setParameterByClass('ilmailsearchcoursesgui', 'ref', 'mail');
303 $this->ctrl->redirectByClass('ilmailsearchcoursesgui');
304 }
305
309 public function searchGroupsTo()
310 {
311 $this->saveMailBeforeSearch();
312
313 $this->ctrl->setParameterByClass('ilmailsearchgroupsgui', 'ref', 'mail');
314 $this->ctrl->redirectByClass('ilmailsearchgroupsgui');
315 }
316
317 public function search()
318 {
319 $_SESSION["mail_search_search"] = $_POST["search"];
320 if(strlen(trim($_SESSION["mail_search_search"])) == 0)
321 {
322 ilUtil::sendInfo($this->lng->txt("mail_insert_query"));
323 $this->searchUsers(false);
324 }
325 else
326 {
327 if(strlen(trim($_SESSION["mail_search_search"])) < 3)
328 {
329 $this->lng->loadLanguageModule('search');
330 ilUtil::sendInfo($this->lng->txt('search_minimum_three'));
331 $this->searchUsers(false);
332 }
333 else
334 {
335 $this->ctrl->setParameterByClass("ilmailsearchgui", "search", urlencode($_SESSION["mail_search_search"]));
336 $this->ctrl->redirectByClass("ilmailsearchgui");
337 }
338 }
339 }
340
341 public function cancelSearch()
342 {
343 unset($_SESSION["mail_search"]);
344 $this->searchResults();
345 }
346
347 public function editAttachments()
348 {
349 // decode post values
350 $files = array();
351 if(is_array($_POST['attachments']))
352 {
353 foreach($_POST['attachments'] as $value)
354 {
355 $files[] = urldecode($value);
356 }
357 }
358
359 // Note: For security reasons, ILIAS only allows Plain text messages.
360 $this->umail->savePostData($_SESSION["AccountId"],
361 $files,
365 $_POST["m_type"],
367 ilUtil::securePlainString($_POST["m_subject"]),
368 ilUtil::securePlainString($_POST["m_message"]),
369 ilUtil::securePlainString($_POST['use_placeholders']),
372 );
373
374 $this->ctrl->redirectByClass("ilmailattachmentgui");
375 }
376
377 public function returnFromAttachments()
378 {
379 $_GET["type"] = "attach";
380 $this->showForm();
381 }
382
383 public function searchResults()
384 {
385 $_GET["type"] = "search_res";
386 $this->showForm();
387 }
388
389 public function mailUser()
390 {
391 $_GET["type"] = "new";
392 $this->showForm();
393 }
394
395 public function mailRole()
396 {
397 $_GET["type"] = "role";
398 $this->showForm();
399 }
400
401 public function replyMail()
402 {
403 $_GET["type"] = "reply";
404 $this->showForm();
405 }
406
407 public function mailAttachment()
408 {
409 $_GET["type"] = "attach";
410 $this->showForm();
411 }
412
416 protected function getTemplateDataById()
417 {
418 require_once 'Services/JSON/classes/class.ilJsonUtil.php';
419
420 if(!isset($_GET['template_id']))
421 {
422 exit();
423 }
424
425 try
426 {
427 require_once 'Services/Mail/classes/class.ilMailTemplateService.php';
428 require_once 'Services/Mail/classes/class.ilMailTemplateDataProvider.php';
429 $template_id = (int)$_GET['template_id'];
430 $template_provider = new ilMailTemplateDataProvider();
431 $template = $template_provider->getTemplateById($template_id);
432 $context = ilMailTemplateService::getTemplateContextById($template->getContext());
433 echo ilJsonUtil::encode(array(
434 'm_subject' => $template->getSubject(),
435 'm_message' => $template->getMessage()
436 ));
437 }
438 catch(Exception $e)
439 {
440 }
441 exit();
442 }
443
444 public function showForm()
445 {
449 global $rbacsystem, $ilUser, $ilCtrl, $lng, $ilTabs, $ilToolbar;
450
451 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_new.html", "Services/Mail");
452 $this->tpl->setTitle($this->lng->txt("mail"));
453
454 $this->lng->loadLanguageModule("crs");
455
457 $ilTabs->setBackTarget($lng->txt('back'), $ilCtrl->getLinkTarget($this, 'cancelMail'));
458
459 switch($_GET["type"])
460 {
461 case 'reply':
462 if($_SESSION['mail_id'])
463 {
464 $_GET['mail_id'] = $_SESSION['mail_id'];
465 }
466 $mailData = $this->umail->getMail($_GET["mail_id"]);
467 $mailData["m_subject"] = $this->umail->formatReplySubject();
468 $mailData["m_message"] = $this->umail->formatReplyMessage();
469 $mailData["m_message"] = $this->umail->prependSignature();
470 // NO ATTACHMENTS FOR REPLIES
471 $mailData["attachments"] = array();
472 //$mailData["rcp_cc"] = $this->umail->formatReplyRecipientsForCC();
473 $mailData["rcp_cc"] = '';
474 $mailData["rcp_to"] = $this->umail->formatReplyRecipient();
475 $_SESSION["mail_id"] = "";
476 break;
477
478 case 'search_res':
479 $mailData = $this->umail->getSavedData();
480
481 /*if($_SESSION["mail_search_results"])
482 {
483 $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results"],$_SESSION["mail_search"]);
484 }
485 unset($_SESSION["mail_search"]);
486 unset($_SESSION["mail_search_results"]);*/
487
488 if($_SESSION["mail_search_results_to"])
489 {
490 $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_to"], 'to');
491 }
492 if($_SESSION["mail_search_results_cc"])
493 {
494 $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_cc"], 'cc');
495 }
496 if($_SESSION["mail_search_results_bcc"])
497 {
498 $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_bcc"], 'bc');
499 }
500
501 unset($_SESSION["mail_search_results_to"]);
502 unset($_SESSION["mail_search_results_cc"]);
503 unset($_SESSION["mail_search_results_bcc"]);
504
505 break;
506
507 case 'attach':
508 $mailData = $this->umail->getSavedData();
509 break;
510
511 case 'draft':
512 $_SESSION["draft"] = $_GET["mail_id"];
513 $mailData = $this->umail->getMail($_GET["mail_id"]);
514 ilMailFormCall::setContextId($mailData['tpl_ctx_id']);
515 ilMailFormCall::setContextParameters($mailData['tpl_ctx_params']);
516 break;
517
518 case 'forward':
519 $mailData = $this->umail->getMail($_GET["mail_id"]);
520 $mailData["rcp_to"] = $mailData["rcp_cc"] = $mailData["rcp_bcc"] = '';
521 $mailData["m_subject"] = $this->umail->formatForwardSubject();
522 $mailData["m_message"] = $this->umail->prependSignature();
523 if(count($mailData["attachments"]))
524 {
525 if($error = $this->mfile->adoptAttachments($mailData["attachments"],$_GET["mail_id"]))
526 {
527 ilUtil::sendInfo($error);
528 }
529 }
530 break;
531
532 case 'new':
533 if($_GET['rcp_to'])
534 {
535 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
536 $mailData["rcp_to"] = ilUtil::securePlainString($_GET['rcp_to']);
537 }
538 else if($_SESSION['rcp_to'])
539 {
540 $mailData["rcp_to"] = $_SESSION['rcp_to'];
541 }
542 if($_GET['rcp_cc'])
543 {
544 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
545 $mailData["rcp_cc"] = ilUtil::securePlainString($_GET['rcp_cc']);
546 }
547 else if($_SESSION['rcp_cc'])
548 {
549 $mailData["rcp_cc"] = $_SESSION['rcp_cc'];
550 }
551 if($_GET['rcp_bcc'])
552 {
553 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
554 $mailData["rcp_bcc"] = ilUtil::securePlainString($_GET['rcp_bcc']);
555 }
556 else if($_SESSION['rcp_bcc'])
557 {
558 $mailData["rcp_bcc"] = $_SESSION['rcp_bcc'];
559 }
560 $mailData['m_message'] = '';
561 if(strlen($sig = ilMailFormCall::getSignature()))
562 {
563 $mailData['m_message'] = $sig;
564 $mailData['m_message'] .= chr(13).chr(10).chr(13).chr(10);
565 }
566 $mailData['m_message'] .= $this->umail->appendSignature();
567
568 $_SESSION['rcp_to'] = '';
569 $_SESSION['rcp_cc'] = '';
570 $_SESSION['rcp_bcc'] = '';
571 break;
572
573 case 'role':
574
575 if(is_array($_POST['roles']))
576 {
577 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
578 $mailData['rcp_to'] = ilUtil::securePlainString(implode(',',$_POST['roles']));
579 }
580 elseif(is_array($_SESSION['mail_roles']))
581 {
582 $mailData['rcp_to'] = ilUtil::securePlainString(implode(',', $_SESSION['mail_roles']));
583 }
584
585 $mailData['m_message'] = '';
586 if(strlen($sig = ilMailFormCall::getSignature()))
587 {
588 $mailData['m_message'] = $sig;
589 $mailData['m_message'] .= chr(13).chr(10).chr(13).chr(10);
590 }
591
592 $mailData['m_message'] .= $_POST["additional_message_text"].chr(13).chr(10).$this->umail->appendSignature();
593 $_POST["additional_message_text"] = "";
594 $_SESSION['mail_roles'] = "";
595 break;
596
597 case 'address':
598 $mailData["rcp_to"] = urldecode($_GET["rcp"]);
599 break;
600
601 default:
602 // GET DATA FROM POST
603 $mailData = $_POST;
604
605 // strip slashes
606 foreach ($mailData as $key => $value)
607 {
608 if (is_string($value))
609 {
610 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
611 $mailData[$key] = ilUtil::securePlainString($value);
612 }
613 }
614 break;
615 }
616
617 include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
618
619 $form_gui = new ilPropertyFormGUI();
620 $form_gui->setTitle($this->lng->txt('compose'));
621 $form_gui->setId('mail_compose_form');
622 $form_gui->setName('mail_compose_form');
623 $form_gui->setFormAction($this->ctrl->getFormAction($this, 'sendMessage'));
624
625 $this->tpl->setVariable('FORM_ID', $form_gui->getId());
626
627 require_once 'Services/UIComponent/Button/classes/class.ilButton.php';
628 $btn = ilButton::getInstance();
629 $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT);
630 $btn->setForm('form_' . $form_gui->getName())
631 ->setName('searchUsers')
632 ->setCaption('search_recipients');
633 $ilToolbar->addStickyItem($btn);
634
635 $btn = ilButton::getInstance();
636 $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT)
637 ->setName('searchCoursesTo')
638 ->setForm('form_' . $form_gui->getName())
639 ->setCaption('mail_my_courses');
640 $ilToolbar->addButtonInstance($btn);
641
642 $btn = ilButton::getInstance();
643 $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT)
644 ->setName('searchGroupsTo')
645 ->setForm('form_' . $form_gui->getName())
646 ->setCaption('mail_my_groups');
647 $ilToolbar->addButtonInstance($btn);
648
649 $btn = ilButton::getInstance();
650 $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT)
651 ->setName('searchMailingListsTo')
652 ->setForm('form_' . $form_gui->getName())
653 ->setCaption('mail_my_mailing_lists');
654 $ilToolbar->addButtonInstance($btn);
655
656 $dsDataLink = $ilCtrl->getLinkTarget($this, 'lookupRecipientAsync', '', true);
657
658 // RECIPIENT
659 $inp = new ilTextInputGUI($this->lng->txt('mail_to'), 'rcp_to');
660 $inp->setRequired(true);
661 $inp->setSize(50);
662 $inp->setValue($mailData["rcp_to"]);
663 $inp->setDataSource($dsDataLink, ",");
664 $inp->setMaxLength(null);
665 $form_gui->addItem($inp);
666
667 // CC
668 $inp = new ilTextInputGUI($this->lng->txt('cc'), 'rcp_cc');
669 $inp->setSize(50);
670 $inp->setValue($mailData["rcp_cc"]);
671 $inp->setDataSource($dsDataLink, ",");
672 $inp->setMaxLength(null);
673 $form_gui->addItem($inp);
674
675 // BCC
676 $inp = new ilTextInputGUI($this->lng->txt('bc'), 'rcp_bcc');
677 $inp->setSize(50);
678 $inp->setValue($mailData["rcp_bcc"]);
679 $inp->setDataSource($dsDataLink, ",");
680 $inp->setMaxLength(null);
681 $form_gui->addItem($inp);
682
683 // SUBJECT
684 $inp = new ilTextInputGUI($this->lng->txt('subject'), 'm_subject');
685 $inp->setSize(50);
686 $inp->setRequired(true);
687 $inp->setValue($mailData["m_subject"]);
688 $form_gui->addItem($inp);
689
690 // Attachments
691 include_once 'Services/Mail/classes/class.ilMailFormAttachmentFormPropertyGUI.php';
692 $att = new ilMailFormAttachmentPropertyGUI($this->lng->txt( ($mailData["attachments"]) ? 'edit' : 'add' ));
693
694 if (is_array($mailData["attachments"]) && count($mailData["attachments"]))
695 {
696 foreach($mailData["attachments"] as $data)
697 {
698 if(is_file($this->mfile->getMailPath() . '/' . $ilUser->getId() . "_" . $data))
699 {
700 $hidden = new ilHiddenInputGUI('attachments[]');
701 $form_gui->addItem($hidden);
702 $size = filesize($this->mfile->getMailPath() . '/' . $ilUser->getId() . "_" . $data);
703 $label = $data . " [" . ilFormat::formatSize($size) . "]";
704 $att->addItem($label);
705 $hidden->setValue(urlencode($data));
706 }
707 }
708 }
709 $form_gui->addItem($att);
710
711 // ONLY IF SYSTEM MAILS ARE ALLOWED
712 if($rbacsystem->checkAccess("system_message",$this->umail->getMailObjectReferenceId()))
713 {
714 $chb = new ilCheckboxInputGUI($this->lng->txt('type'), 'm_type[]');
715 $chb->setOptionTitle($this->lng->txt('system_message'));
716 $chb->setValue('system');
717 $chb->setChecked(false);
718 if(is_array($mailData["m_type"]) and in_array('system',$mailData["m_type"]))
719 {
720 $chb->setChecked(true);
721 }
722 $form_gui->addItem($chb);
723 }
724
726 {
727 $context_id = ilMailFormCall::getContextId();
728
729 // Activate placeholders
730 $mailData['use_placeholders'] = true;
731
732 try {
733 require_once 'Services/Mail/classes/class.ilMailTemplateService.php';
734 $context = ilMailTemplateService::getTemplateContextById($context_id);
735
736 require_once 'Services/Mail/classes/class.ilMailTemplateDataProvider.php';
737 $template_provider = new ilMailTemplateDataProvider();
738 $templates = $template_provider->getTemplateByContexId($context->getId());
739
740 if(count($templates))
741 {
742 $options = array();
743 foreach($templates as $template)
744 {
745 $options[$template->getTplId()] = $template->getTitle();
746 }
747 asort($options);
748
749 require_once 'Services/Mail/classes/Form/class.ilMailTemplateSelectInputGUI.php';
750 $template_chb = new ilMailTemplateSelectInputGUI(
751 $this->lng->txt('mail_template_client'),
752 'template_id',
753 $this->ctrl->getLinkTarget($this, 'getTemplateDataById', '', true, false),
754 array('m_subject', 'm_message')
755 );
756 $template_chb->setInfo($this->lng->txt('mail_template_client_info'));
757 $template_chb->setOptions(array('' => $this->lng->txt('please_choose')) + $options);
758 $form_gui->addItem($template_chb);
759 }
760 }
761 catch(Exception $e)
762 {
763 require_once './Services/Logging/classes/public/class.ilLoggerFactory.php';
764 ilLoggerFactory::getLogger('mail')->error(sprintf('%s has been called with invalid context id: %s.', __METHOD__, $context_id));
765 }
766 }
767 else
768 {
769 require_once 'Services/Mail/classes/class.ilMailTemplateGenericContext.php';
770 $context = new ilMailTemplateGenericContext();
771 }
772
773 // MESSAGE
774 $inp = new ilTextAreaInputGUI($this->lng->txt('message_content'), 'm_message');
775 //$inp->setValue(htmlspecialchars($mailData["m_message"], false));
776 $inp->setValue($mailData["m_message"]);
777 $inp->setRequired(false);
778 $inp->setCols(60);
779 $inp->setRows(10);
780 $form_gui->addItem($inp);
781
782 // PLACEHOLDERS
783 $chb = new ilCheckboxInputGUI($this->lng->txt('mail_serial_letter_placeholders'), 'use_placeholders');
784 $chb->setOptionTitle($this->lng->txt('activate_serial_letter_placeholders'));
785 $chb->setValue(1);
786 if(isset($mailData['use_placeholders']) && $mailData['use_placeholders'])
787 {
788 $chb->setChecked(true);
789 }
790
791 require_once 'Services/Mail/classes/Form/class.ilManualPlaceholderInputGUI.php';
792 $placeholders = new ilManualPlaceholderInputGUI($this->ctrl->getLinkTarget($this, 'getAjaxPlaceholdersById', '', true, false));
793 foreach($context->getPlaceholders() as $key => $value)
794 {
795 $placeholders->addPlaceholder($value['placeholder'], $value['label'] );
796 }
797 $chb->addSubItem($placeholders);
798 $form_gui->addItem($chb);
799
800 $form_gui->addCommandButton('sendMessage', $this->lng->txt('send_mail'));
801 $form_gui->addCommandButton('saveDraft', $this->lng->txt('save_message'));
803 $form_gui->addCommandButton('cancelMail', $this->lng->txt('cancel'));
804
805 $this->tpl->parseCurrentBlock();
806
807 $this->tpl->setVariable('FORM', $form_gui->getHTML());
808
809 $this->tpl->addJavaScript('Services/Mail/js/ilMailComposeFunctions.js');
810 $this->tpl->show();
811 }
812
813 public function lookupRecipientAsync()
814 {
815 include_once 'Services/JSON/classes/class.ilJsonUtil.php';
816 include_once 'Services/Mail/classes/class.ilMailForm.php';
817
818 $search = $_REQUEST["term"];
819 $result = array();
820 if (!$search)
821 {
823 exit;
824 }
825
826 // #14768
827 $quoted = ilUtil::stripSlashes($search);
828 $quoted = str_replace('%', '\%', $quoted);
829 $quoted = str_replace('_', '\_', $quoted);
830
831 $mailFormObj = new ilMailForm;
832 $result = $mailFormObj->getRecipientAsync("%" . $quoted . "%", ilUtil::stripSlashes($search));
833
835 exit;
836 }
837
838 public function cancelMail()
839 {
842 else
843 return $this->showForm();
844 }
845
849 protected function saveMailBeforeSearch()
850 {
854 global $ilUser;
855
856 // decode post values
857 $files = array();
858 if(is_array($_POST['attachments']))
859 {
860 foreach($_POST['attachments'] as $value)
861 {
862 $files[] = urldecode($value);
863 }
864 }
865
866 $this->umail->savePostData($ilUser->getId(),
867 $files,
871 $_POST['m_type'],
873 ilUtil::securePlainString($_POST['m_subject']),
874 ilUtil::securePlainString($_POST['m_message']),
875 ilUtil::securePlainString($_POST['use_placeholders']),
878 );
879 }
880
884 public function searchMailingListsTo()
885 {
886 $this->saveMailBeforeSearch();
887
888 $this->ctrl->setParameterByClass('ilmailinglistsgui', 'ref', 'mail');
889 $this->ctrl->redirectByClass('ilmailinglistsgui');
890 }
891
892 public function getAjaxPlaceholdersById()
893 {
894 $context_id = ilUtil::stripSlashes($_GET['context_id']);
895 require_once 'Services/Mail/classes/class.ilMailTemplateService.php';
896 require_once 'Services/Mail/classes/Form/class.ilManualPlaceholderInputGUI.php';
897 $placeholders = new ilManualPlaceholderInputGUI($this->ctrl->getLinkTarget($this, 'getAjaxPlaceholdersById', '', true, false));
898 $context = ilMailTemplateService::getTemplateContextById($context_id);
899 foreach($context->getPlaceholders() as $key => $value)
900 {
901 $placeholders->addPlaceholder($value['placeholder'], $value['label'] );
902 }
903 $placeholders->render(true);
904 exit();
905 }
906}
$result
$size
Definition: RandomTest.php:79
$_GET["client_id"]
$_SESSION["AccountId"]
const BUTTON_TYPE_SUBMIT
static getInstance()
This class represents a checkbox property in a property form.
This class handles all operations on files (attachments) in directory ilias_data/mail.
Class UserMail this class handles user mails.
static formatSize($size, $a_mode='short', $a_lng=null)
Returns the specified file size value in a human friendly form.
This class represents a hidden form property in a property form.
static encode($mixed, $suppress_native=false)
static getLogger($a_component_id)
Get component logger.
static getSignature()
Get preset signature.
static setContextParameters(array $parameters)
searchUsers($save=true)
decodeAttachmentFiles(array $files)
getTemplateDataById()
Called asynchronously when changing the template.
Class ilMailTemplateDataProvider.
Class ilMailTemplateSelectInputGUI.
Class ilManualPlaceholderInputGUI.
This class represents a property form user interface.
This class represents a text area property in a property form.
This class represents a text property in a property form.
static redirect($a_script)
http redirect to other script
static securePlainString($a_str)
Remove unsecure characters from a plain text string.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
$_POST['username']
Definition: cron.php:12
$data
$template_id
Definition: example_062.php:89
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
global $ilCtrl
Definition: ilias.php:18
exit
Definition: login.php:54
$cmd
Definition: sahs_server.php:35
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
if(!is_array($argv)) $options
global $ilUser
Definition: imgupload.php:15