ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
12{
14 private $tpl;
15
17 private $ctrl;
18
20 private $lng;
21
23 private $user;
24
26 private $tabs;
27
29 private $toolbar;
30
32 private $rbacsystem;
33
35 private $umail;
36
38 private $mbox;
39
41 private $mfile;
42
45
47 private $purifier;
48
54 public function __construct(
56 ilMailBodyPurifier $bodyPurifier = null
57 ) {
58 global $DIC;
59
60 if (null === $templateService) {
61 $templateService = $DIC['mail.texttemplates.service'];
62 }
63 $this->templateService = $templateService;
64
65 $this->tpl = $DIC->ui()->mainTemplate();
66 $this->ctrl = $DIC->ctrl();
67 $this->lng = $DIC->language();
68 $this->user = $DIC->user();
69 $this->tabs = $DIC->tabs();
70 $this->toolbar = $DIC->toolbar();
71 $this->rbacsystem = $DIC->rbac()->system();
72
73 $this->umail = new ilFormatMail($this->user->getId());
74 $this->mfile = new ilFileDataMail($this->user->getId());
75 $this->mbox = new ilMailbox($this->user->getId());
76
77 if (null === $bodyPurifier) {
78 $bodyPurifier = new ilMailBodyPurifier();
79 }
80 $this->purifier = $bodyPurifier;
81
82 if (isset($_POST['mobj_id']) && (int) $_POST['mobj_id']) {
83 $_GET['mobj_id'] = $_POST['mobj_id'];
84 }
85
86 if (!(int) $_GET['mobj_id']) {
87 $_GET['mobj_id'] = $this->mbox->getInboxFolder();
88 }
89 $_GET['mobj_id'] = (int) $_GET['mobj_id'];
90
91 $this->ctrl->saveParameter($this, 'mobj_id');
92 }
93
94 public function executeCommand()
95 {
96 $forward_class = $this->ctrl->getNextClass($this);
97 switch ($forward_class) {
98 case 'ilmailfoldergui':
99 $this->ctrl->forwardCommand(new ilMailFolderGUI());
100 break;
101
102 case 'ilmailattachmentgui':
103 $this->ctrl->setReturn($this, "returnFromAttachments");
104 $this->ctrl->forwardCommand(new ilMailAttachmentGUI());
105 break;
106
107 case 'ilmailsearchgui':
108 $this->ctrl->setReturn($this, "searchResults");
109 $this->ctrl->forwardCommand(new ilMailSearchGUI());
110 break;
111
112 case 'ilmailsearchcoursesgui':
113 $this->ctrl->setReturn($this, "searchResults");
114 $this->ctrl->forwardCommand(new ilMailSearchCoursesGUI());
115 break;
116
117 case 'ilmailinglistsgui':
118 $this->ctrl->setReturn($this, 'searchResults');
119 $this->ctrl->forwardCommand(new ilMailingListsGUI());
120 break;
121
122 case 'ilmailsearchgroupsgui':
123 $this->ctrl->setReturn($this, "searchResults");
124 $this->ctrl->forwardCommand(new ilMailSearchGroupsGUI());
125 break;
126
127 default:
128 if (!($cmd = $this->ctrl->getCmd())) {
129 $cmd = "showForm";
130 }
131
132 $this->$cmd();
133 break;
134 }
135 }
136
141 protected function decodeAttachmentFiles(array $files)
142 {
143 $decodedFiles = array();
144
145 foreach ($files as $value) {
146 if (is_file($this->mfile->getMailPath() . '/' . $this->user->getId() . '_' . urldecode($value))) {
147 $decodedFiles[] = urldecode($value);
148 }
149 }
150
151 return $decodedFiles;
152 }
153
154 public function sendMessage()
155 {
156 $message = (string) $_POST['m_message'];
157
158 $mailBody = new ilMailBody($message, $this->purifier);
159
160 $sanitizedMessage = $mailBody->getContent();
161
162 $files = $this->decodeAttachmentFiles(isset($_POST['attachments']) ? (array) $_POST['attachments'] : array());
163
164 $mailer = $this->umail
165 ->withContextId(ilMailFormCall::getContextId() ?: '')
166 ->withContextParameters(is_array(ilMailFormCall::getContextParameters()) ? ilMailFormCall::getContextParameters() : []);
167
168 $mailer->setSaveInSentbox(true);
169
170 if ($errors = $mailer->enqueue(
174 ilUtil::securePlainString($_POST['m_subject']),
175 $sanitizedMessage,
176 $files,
177 (int) $_POST['use_placeholders']
178 )
179 ) {
180 $_POST['attachments'] = $files;
182 } else {
183 $mailer->savePostData($this->user->getId(), array(), "", "", "", "", "", "", "", "");
184
185 $this->ctrl->setParameterByClass('ilmailgui', 'type', 'message_sent');
186
188 ilUtil::sendSuccess($this->lng->txt('mail_message_send'), true);
189 $this->ctrl->redirectToURL(ilMailFormCall::getRefererRedirectUrl());
190 } else {
191 $this->ctrl->redirectByClass('ilmailgui');
192 }
193 }
194
195 $this->showForm();
196 }
197
198 public function saveDraft()
199 {
200 if (!$_POST['m_subject']) {
201 $_POST['m_subject'] = 'No title';
202 }
203
204 $draftFolderId = $this->mbox->getDraftsFolder();
205 $files = $this->decodeAttachmentFiles(isset($_POST['attachments']) ? (array) $_POST['attachments'] : array());
206
207 if ($errors = $this->umail->validateRecipients(
208 (string) ilUtil::securePlainString($_POST['rcp_to']),
209 (string) ilUtil::securePlainString($_POST['rcp_cc']),
210 (string) ilUtil::securePlainString($_POST['rcp_bcc'])
211 )) {
212 $_POST['attachments'] = $files;
214 $this->showForm();
215 return;
216 }
217
218 if (isset($_SESSION["draft"])) {
219 $draftId = (int) $_SESSION['draft'];
220 unset($_SESSION['draft']);
221 } else {
222 $draftId = $this->umail->getNewDraftId($this->user->getId(), $draftFolderId);
223 }
224
225 $this->umail->updateDraft(
226 $draftFolderId,
227 $files,
232 ilUtil::securePlainString($_POST['m_subject']),
233 ilUtil::securePlainString($_POST['m_message']),
234 $draftId,
235 (int) $_POST['use_placeholders'],
238 );
239
240 ilUtil::sendInfo($this->lng->txt('mail_saved'), true);
241
244 } else {
245 $this->ctrl->redirectByClass(['ilmailgui', 'ilmailfoldergui']);
246 }
247
248 $this->showForm();
249 }
250
251 public function searchUsers($save = true)
252 {
253 $this->tpl->setTitle($this->lng->txt("mail"));
254
255 if ($save) {
256 // decode post values
257 $files = array();
258 if (is_array($_POST['attachments'])) {
259 foreach ($_POST['attachments'] as $value) {
260 $files[] = urldecode($value);
261 }
262 }
263
264 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
265 $this->umail->savePostData(
266 $this->user->getId(),
267 $files,
272 ilUtil::securePlainString($_POST["m_subject"]),
273 ilUtil::securePlainString($_POST["m_message"]),
274 ilUtil::securePlainString($_POST['use_placeholders']),
277 );
278 }
279
280 $form = new ilPropertyFormGUI();
281 $form->setId('search_rcp');
282 $form->setTitle($this->lng->txt('search_recipients'));
283 $form->setFormAction($this->ctrl->getFormAction($this, 'search'));
284
285 $inp = new ilTextInputGUI($this->lng->txt("search_for"), 'search');
286 $inp->setSize(30);
287 $dsDataLink = $this->ctrl->getLinkTarget($this, 'lookupRecipientAsync', '', true, false);
288 $inp->setDataSource($dsDataLink);
289
290 if (strlen(trim($_SESSION["mail_search_search"])) > 0) {
291 $inp->setValue(ilUtil::prepareFormOutput(trim($_SESSION["mail_search_search"]), true));
292 }
293 $form->addItem($inp);
294
295 $form->addCommandButton('search', $this->lng->txt("search"));
296 $form->addCommandButton('cancelSearch', $this->lng->txt("cancel"));
297
298 $this->tpl->setContent($form->getHtml());
299 $this->tpl->printToStdout();
300 }
301
305 public function searchCoursesTo()
306 {
307 $this->saveMailBeforeSearch();
308
309 if ($_SESSION['search_crs']) {
310 $this->ctrl->setParameterByClass('ilmailsearchcoursesgui', 'cmd', 'showMembers');
311 }
312
313 $this->ctrl->setParameterByClass('ilmailsearchcoursesgui', 'ref', 'mail');
314 $this->ctrl->redirectByClass('ilmailsearchcoursesgui');
315 }
316
320 public function searchGroupsTo()
321 {
322 $this->saveMailBeforeSearch();
323
324 $this->ctrl->setParameterByClass('ilmailsearchgroupsgui', 'ref', 'mail');
325 $this->ctrl->redirectByClass('ilmailsearchgroupsgui');
326 }
327
328 public function search()
329 {
330 $_SESSION["mail_search_search"] = $_POST["search"];
331 if (strlen(trim($_SESSION["mail_search_search"])) == 0) {
332 ilUtil::sendInfo($this->lng->txt("mail_insert_query"));
333 $this->searchUsers(false);
334 } else {
335 if (strlen(trim($_SESSION["mail_search_search"])) < 3) {
336 $this->lng->loadLanguageModule('search');
337 ilUtil::sendInfo($this->lng->txt('search_minimum_three'));
338 $this->searchUsers(false);
339 } else {
340 $this->ctrl->setParameterByClass("ilmailsearchgui", "search", urlencode($_SESSION["mail_search_search"]));
341 $this->ctrl->redirectByClass("ilmailsearchgui");
342 }
343 }
344 }
345
346 public function cancelSearch()
347 {
348 unset($_SESSION["mail_search"]);
349 $this->searchResults();
350 }
351
352 public function editAttachments()
353 {
354 // decode post values
355 $files = array();
356 if (is_array($_POST['attachments'])) {
357 foreach ($_POST['attachments'] as $value) {
358 $files[] = urldecode($value);
359 }
360 }
361
362 // Note: For security reasons, ILIAS only allows Plain text messages.
363 $this->umail->savePostData(
364 $this->user->getId(),
365 $files,
370 ilUtil::securePlainString($_POST["m_subject"]),
371 ilUtil::securePlainString($_POST["m_message"]),
372 ilUtil::securePlainString($_POST['use_placeholders']),
375 );
376
377 $this->ctrl->redirectByClass("ilmailattachmentgui");
378 }
379
380 public function returnFromAttachments()
381 {
382 $_GET["type"] = "attach";
383 $this->showForm();
384 }
385
386 public function searchResults()
387 {
388 $_GET["type"] = "search_res";
389 $this->showForm();
390 }
391
392 public function mailUser()
393 {
394 $_GET["type"] = "new";
395 $this->showForm();
396 }
397
398 public function mailRole()
399 {
400 $_GET["type"] = "role";
401 $this->showForm();
402 }
403
404 public function replyMail()
405 {
406 $_GET["type"] = "reply";
407 $this->showForm();
408 }
409
410 public function mailAttachment()
411 {
412 $_GET["type"] = "attach";
413 $this->showForm();
414 }
415
419 protected function getTemplateDataById()
420 {
421 if (!isset($_GET['template_id'])) {
422 exit();
423 }
424
425 try {
426 $template = $this->templateService->loadTemplateForId((int) $_GET['template_id']);
427 $context = ilMailTemplateContextService::getTemplateContextById((string) $template->getContext());
428
429 echo json_encode([
430 'm_subject' => $template->getSubject(),
431 'm_message' => $template->getMessage(),
432 ]);
433 } catch (Exception $e) {
434 }
435 exit();
436 }
437
438 public function showForm()
439 {
440 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_new.html", "Services/Mail");
441 $this->tpl->setTitle($this->lng->txt("mail"));
442
443 $this->lng->loadLanguageModule("crs");
444
446 $this->tabs->setBackTarget($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'cancelMail'));
447 }
448
449 switch ($_GET["type"]) {
450 case 'reply':
451 if ($_SESSION['mail_id']) {
452 $_GET['mail_id'] = $_SESSION['mail_id'];
453 }
454 $mailData = $this->umail->getMail($_GET["mail_id"]);
455 $mailData["m_subject"] = $this->umail->formatReplySubject();
456 $mailData["m_message"] = $this->umail->formatReplyMessage();
457 $mailData["m_message"] = $this->umail->prependSignature();
458 // NO ATTACHMENTS FOR REPLIES
459 $mailData["attachments"] = array();
460 //$mailData["rcp_cc"] = $this->umail->formatReplyRecipientsForCC();
461 $mailData["rcp_cc"] = '';
462 $mailData["rcp_to"] = $this->umail->formatReplyRecipient();
463 $_SESSION["mail_id"] = "";
464 break;
465
466 case 'search_res':
467 $mailData = $this->umail->getSavedData();
468
469 /*if($_SESSION["mail_search_results"])
470 {
471 $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results"],$_SESSION["mail_search"]);
472 }
473 unset($_SESSION["mail_search"]);
474 unset($_SESSION["mail_search_results"]);*/
475
476 if ($_SESSION["mail_search_results_to"]) {
477 $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_to"], 'to');
478 }
479 if ($_SESSION["mail_search_results_cc"]) {
480 $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_cc"], 'cc');
481 }
482 if ($_SESSION["mail_search_results_bcc"]) {
483 $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_bcc"], 'bc');
484 }
485
486 unset($_SESSION["mail_search_results_to"]);
487 unset($_SESSION["mail_search_results_cc"]);
488 unset($_SESSION["mail_search_results_bcc"]);
489
490 break;
491
492 case 'attach':
493 $mailData = $this->umail->getSavedData();
494 break;
495
496 case 'draft':
497 $_SESSION["draft"] = $_GET["mail_id"];
498 $mailData = $this->umail->getMail($_GET["mail_id"]);
499 ilMailFormCall::setContextId($mailData['tpl_ctx_id']);
500 ilMailFormCall::setContextParameters($mailData['tpl_ctx_params']);
501 break;
502
503 case 'forward':
504 $mailData = $this->umail->getMail($_GET["mail_id"]);
505 $mailData["rcp_to"] = $mailData["rcp_cc"] = $mailData["rcp_bcc"] = '';
506 $mailData["m_subject"] = $this->umail->formatForwardSubject();
507 $mailData["m_message"] = $this->umail->prependSignature();
508 if (is_array($mailData["attachments"]) && count($mailData["attachments"])) {
509 if ($error = $this->mfile->adoptAttachments($mailData["attachments"], $_GET["mail_id"])) {
510 ilUtil::sendInfo($error);
511 }
512 }
513 break;
514
515 case 'new':
516 if ($_GET['rcp_to']) {
517 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
518 $mailData["rcp_to"] = ilUtil::securePlainString($_GET['rcp_to']);
519 } elseif ($_SESSION['rcp_to']) {
520 $mailData["rcp_to"] = $_SESSION['rcp_to'];
521 }
522 if ($_GET['rcp_cc']) {
523 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
524 $mailData["rcp_cc"] = ilUtil::securePlainString($_GET['rcp_cc']);
525 } elseif ($_SESSION['rcp_cc']) {
526 $mailData["rcp_cc"] = $_SESSION['rcp_cc'];
527 }
528 if ($_GET['rcp_bcc']) {
529 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
530 $mailData["rcp_bcc"] = ilUtil::securePlainString($_GET['rcp_bcc']);
531 } elseif ($_SESSION['rcp_bcc']) {
532 $mailData["rcp_bcc"] = $_SESSION['rcp_bcc'];
533 }
534 $mailData['m_message'] = '';
535 if (strlen($sig = ilMailFormCall::getSignature())) {
536 $mailData['m_message'] = $sig;
537 $mailData['m_message'] .= chr(13) . chr(10) . chr(13) . chr(10);
538 }
539 $mailData['m_message'] .= $this->umail->appendSignature();
540
541 $_SESSION['rcp_to'] = '';
542 $_SESSION['rcp_cc'] = '';
543 $_SESSION['rcp_bcc'] = '';
544 break;
545
546 case 'role':
547
548 if (is_array($_POST['roles'])) {
549 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
550 $mailData['rcp_to'] = ilUtil::securePlainString(implode(',', $_POST['roles']));
551 } elseif (is_array($_SESSION['mail_roles'])) {
552 $mailData['rcp_to'] = ilUtil::securePlainString(implode(',', $_SESSION['mail_roles']));
553 }
554
555 $mailData['m_message'] = '';
556 if (strlen($sig = ilMailFormCall::getSignature())) {
557 $mailData['m_message'] = $sig;
558 $mailData['m_message'] .= chr(13) . chr(10) . chr(13) . chr(10);
559 }
560
561 $mailData['m_message'] .= $_POST["additional_message_text"] . chr(13) . chr(10) . $this->umail->appendSignature();
562 $_POST["additional_message_text"] = "";
563 $_SESSION['mail_roles'] = [];
564 break;
565
566 case 'address':
567 $mailData["rcp_to"] = urldecode($_GET["rcp"]);
568 break;
569
570 default:
571 // GET DATA FROM POST
572 $mailData = $_POST;
573
574 // strip slashes
575 foreach ($mailData as $key => $value) {
576 if (is_string($value)) {
577 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
578 $mailData[$key] = ilUtil::securePlainString($value);
579 }
580 }
581 break;
582 }
583
584 $form_gui = new ilPropertyFormGUI();
585 $form_gui->setTitle($this->lng->txt('compose'));
586 $form_gui->setId('mail_compose_form');
587 $form_gui->setName('mail_compose_form');
588 $form_gui->setFormAction($this->ctrl->getFormAction($this, 'sendMessage'));
589
590 $this->tpl->setVariable('FORM_ID', $form_gui->getId());
591
592 $btn = ilButton::getInstance();
593 $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT);
594 $btn->setForm('form_' . $form_gui->getName())
595 ->setName('searchUsers')
596 ->setCaption('search_recipients');
597 $this->toolbar->addStickyItem($btn);
598
599 $btn = ilButton::getInstance();
600 $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT)
601 ->setName('searchCoursesTo')
602 ->setForm('form_' . $form_gui->getName())
603 ->setCaption('mail_my_courses');
604 $this->toolbar->addButtonInstance($btn);
605
606 $btn = ilButton::getInstance();
607 $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT)
608 ->setName('searchGroupsTo')
609 ->setForm('form_' . $form_gui->getName())
610 ->setCaption('mail_my_groups');
611 $this->toolbar->addButtonInstance($btn);
612
613 if (count(ilBuddyList::getInstanceByGlobalUser()->getLinkedRelations()) > 0) {
614 $btn = ilButton::getInstance();
615 $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT)
616 ->setName('searchMailingListsTo')
617 ->setForm('form_' . $form_gui->getName())
618 ->setCaption('mail_my_mailing_lists');
619 $this->toolbar->addButtonInstance($btn);
620 }
621
622 $dsDataLink = $this->ctrl->getLinkTarget($this, 'lookupRecipientAsync', '', true);
623
624 $inp = new ilTextInputGUI($this->lng->txt('mail_to'), 'rcp_to');
625 $inp->setRequired(true);
626 $inp->setSize(50);
627 $inp->setValue($mailData["rcp_to"]);
628 $inp->setDataSource($dsDataLink, ",");
629 $inp->setMaxLength(null);
630 $form_gui->addItem($inp);
631
632 $inp = new ilTextInputGUI($this->lng->txt('cc'), 'rcp_cc');
633 $inp->setSize(50);
634 $inp->setValue($mailData["rcp_cc"]);
635 $inp->setDataSource($dsDataLink, ",");
636 $inp->setMaxLength(null);
637 $form_gui->addItem($inp);
638
639 $inp = new ilTextInputGUI($this->lng->txt('bc'), 'rcp_bcc');
640 $inp->setSize(50);
641 $inp->setValue($mailData["rcp_bcc"]);
642 $inp->setDataSource($dsDataLink, ",");
643 $inp->setMaxLength(null);
644 $form_gui->addItem($inp);
645
646 $inp = new ilTextInputGUI($this->lng->txt('subject'), 'm_subject');
647 $inp->setSize(50);
648 $inp->setRequired(true);
649 $inp->setValue($mailData["m_subject"]);
650 $form_gui->addItem($inp);
651
652 $att = new ilMailFormAttachmentPropertyGUI($this->lng->txt(($mailData["attachments"]) ? 'edit' : 'add'));
653
654 if (is_array($mailData["attachments"]) && count($mailData["attachments"])) {
655 foreach ($mailData["attachments"] as $data) {
656 if (is_file($this->mfile->getMailPath() . '/' . $this->user->getId() . "_" . $data)) {
657 $hidden = new ilHiddenInputGUI('attachments[]');
658 $form_gui->addItem($hidden);
659 $size = filesize($this->mfile->getMailPath() . '/' . $this->user->getId() . "_" . $data);
660 $label = $data . " [" . ilUtil::formatSize($size) . "]";
661 $att->addItem($label);
662 $hidden->setValue(urlencode($data));
663 }
664 }
665 }
666 $form_gui->addItem($att);
667
669 $context_id = ilMailFormCall::getContextId();
670
671 $mailData['use_placeholders'] = true;
672
673 try {
675
676 $templates = $this->templateService->loadTemplatesForContextId($context->getId());
677 if (count($templates) > 0) {
678 $options = array();
679
680 $template_chb = new ilMailTemplateSelectInputGUI(
681 $this->lng->txt('mail_template_client'),
682 'template_id',
683 $this->ctrl->getLinkTarget($this, 'getTemplateDataById', '', true, false),
684 array('m_subject' => false, 'm_message' => true)
685 );
686
687 foreach ($templates as $template) {
688 $options[$template->getTplId()] = $template->getTitle();
689
690 if (!isset($mailData['template_id']) && $template->isDefault()) {
691 $template_chb->setValue($template->getTplId());
692 $form_gui->getItemByPostVar('m_subject')->setValue($template->getSubject());
693 $mailData["m_message"] = $template->getMessage();
694 }
695 }
696 if (isset($mailData['template_id'])) {
697 $template_chb->setValue((int) $mailData['template_id']);
698 }
699 asort($options);
700
701 $template_chb->setInfo($this->lng->txt('mail_template_client_info'));
702 $template_chb->setOptions(array('' => $this->lng->txt('please_choose')) + $options);
703 $form_gui->addItem($template_chb);
704 }
705 } catch (Exception $e) {
706 ilLoggerFactory::getLogger('mail')->error(sprintf(
707 '%s has been called with invalid context id: %s.',
708 __METHOD__,
709 $context_id
710 ));
711 }
712 } else {
714 }
715
716 $inp = new ilTextAreaInputGUI($this->lng->txt('message_content'), 'm_message');
717 //$inp->setValue(htmlspecialchars($mailData["m_message"], false));
718 $inp->setValue($mailData["m_message"]);
719 $inp->setRequired(false);
720 $inp->setCols(60);
721 $inp->setRows(10);
722 $form_gui->addItem($inp);
723
724 $chb = new ilCheckboxInputGUI($this->lng->txt('mail_serial_letter_placeholders'), 'use_placeholders');
725 $chb->setValue('1');
726 if (isset($mailData['use_placeholders']) && $mailData['use_placeholders']) {
727 $chb->setChecked(true);
728 }
729
730 $placeholders = new ilManualPlaceholderInputGUI('m_message');
731 $placeholders->setInstructionText($this->lng->txt('mail_nacc_use_placeholder'));
732 $placeholders->setAdviseText(sprintf($this->lng->txt('placeholders_advise'), '<br />'));
733 foreach ($context->getPlaceholders() as $key => $value) {
734 $placeholders->addPlaceholder($value['placeholder'], $value['label']);
735 }
736 $chb->addSubItem($placeholders);
737 $form_gui->addItem($chb);
738
739 $form_gui->addCommandButton('sendMessage', $this->lng->txt('send_mail'));
740 $form_gui->addCommandButton('saveDraft', $this->lng->txt('save_message'));
742 $form_gui->addCommandButton('cancelMail', $this->lng->txt('cancel'));
743 }
744
745 $this->tpl->parseCurrentBlock();
746
747 $this->tpl->setVariable('FORM', $form_gui->getHTML());
748
749 $this->tpl->addJavaScript('Services/Mail/js/ilMailComposeFunctions.js');
750 $this->tpl->printToStdout();
751 }
752
753 public function lookupRecipientAsync()
754 {
755 $search = '';
756 if (isset($_GET["term"]) && is_string($_GET["term"])) {
757 $search = $_GET["term"];
758 }
759 if (isset($_POST["term"]) && is_string($_POST["term"])) {
760 $search = $_POST["term"];
761 }
762
763 $search = trim($search);
764
765 $result = array();
766
767 require_once 'Services/Utilities/classes/class.ilStr.php';
768 if (ilStr::strLen($search) < 3) {
769 echo json_encode($result);
770 exit;
771 }
772
773 // #14768
774 $quoted = ilUtil::stripSlashes($search);
775 $quoted = str_replace('%', '\%', $quoted);
776 $quoted = str_replace('_', '\_', $quoted);
777
778 $mailFormObj = new ilMailForm;
779 $result = $mailFormObj->getRecipientAsync("%" . $quoted . "%", ilUtil::stripSlashes($search));
780
781 echo json_encode($result);
782 exit;
783 }
784
785 public function cancelMail()
786 {
789 }
790
791 $this->showForm();
792 }
793
797 protected function saveMailBeforeSearch()
798 {
799 $files = array();
800 if (is_array($_POST['attachments'])) {
801 foreach ($_POST['attachments'] as $value) {
802 $files[] = urldecode($value);
803 }
804 }
805
806 $this->umail->savePostData(
807 $this->user->getId(),
808 $files,
813 ilUtil::securePlainString($_POST['m_subject']),
814 ilUtil::securePlainString($_POST['m_message']),
815 ilUtil::securePlainString($_POST['use_placeholders']),
818 );
819 }
820
824 public function searchMailingListsTo()
825 {
826 $this->saveMailBeforeSearch();
827
828 $this->ctrl->setParameterByClass('ilmailinglistsgui', 'ref', 'mail');
829 $this->ctrl->redirectByClass('ilmailinglistsgui');
830 }
831
835 protected function showSubmissionErrors(array $errors)
836 {
837 $formatter = new ilMailErrorFormatter($this->lng);
838 $formattedErrors = $formatter->format($errors);
839
840 if (strlen($formattedErrors) > 0) {
841 ilUtil::sendFailure($formattedErrors);
842 }
843 }
844}
$result
user()
Definition: user.php:4
$size
Definition: RandomTest.php:84
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
static getInstanceByGlobalUser()
const BUTTON_TYPE_SUBMIT
static getInstance()
This class represents a checkbox property in a property form.
Class ilFileDataMail.
Class UserMail this class handles user mails.
This class represents a hidden form property in a property form.
static getLogger($a_component_id)
Get component logger.
Class ilMailErrorFormatter.
static getSignature()
Get preset signature.
static setContextParameters(array $parameters)
showSubmissionErrors(array $errors)
searchUsers($save=true)
decodeAttachmentFiles(array $files)
__construct(ilMailTemplateService $templateService=null, ilMailBodyPurifier $bodyPurifier=null)
ilMailFormGUI constructor.
getTemplateDataById()
Called asynchronously when changing the template.
Class ilMailTemplateSelectInputGUI.
Class ilMailTemplateService.
Mail Box class Base class for creating and handling mail boxes.
Class ilManualPlaceholderInputGUI.
This class represents a property form user interface.
static strLen($a_string)
Definition: class.ilStr.php:78
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)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static formatSize($size, $a_mode='short', $a_lng=null)
Returns the specified file size value in a human friendly form.
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
exit
Definition: login.php:29
$data
Definition: storeScorm.php:23
$errors
$context
Definition: webdav.php:26
$message
Definition: xapiexit.php:14
$DIC
Definition: xapitoken.php:46