ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $m_type = isset($_POST["m_type"]) ? $_POST["m_type"] : array("normal");
157
158 $message = (string) $_POST['m_message'];
159
160 $mailBody = new ilMailBody($message, $this->purifier);
161
162 $sanitizedMessage = $mailBody->getContent();
163
164 $files = $this->decodeAttachmentFiles(isset($_POST['attachments']) ? (array) $_POST['attachments'] : array());
165
166 $mailer = $this->umail
168 ->withContextParameters(is_array(ilMailFormCall::getContextParameters()) ? ilMailFormCall::getContextParameters() : []);
169
170 $mailer->setSaveInSentbox(true);
171
172 if ($errors = $mailer->sendMail(
176 ilUtil::securePlainString($_POST['m_subject']),
177 $sanitizedMessage,
178 $files,
179 $m_type,
180 (int) $_POST['use_placeholders']
181 )
182 ) {
183 $_POST['attachments'] = $files;
185 } else {
186 $mailer->savePostData($this->user->getId(), array(), "", "", "", "", "", "", "", "");
187
188 $this->ctrl->setParameterByClass('ilmailgui', 'type', 'message_sent');
189
191 ilUtil::sendInfo($this->lng->txt('mail_message_send'), true);
192 $this->ctrl->redirectToURL(ilMailFormCall::getRefererRedirectUrl());
193 } else {
194 $this->ctrl->redirectByClass('ilmailgui');
195 }
196 }
197
198 $this->showForm();
199 }
200
201 public function saveDraft()
202 {
203 if (!$_POST['m_subject']) {
204 $_POST['m_subject'] = 'No title';
205 }
206
207 $draftFolderId = $this->mbox->getDraftsFolder();
208 $files = $this->decodeAttachmentFiles(isset($_POST['attachments']) ? (array) $_POST['attachments'] : array());
209
210 if ($errors = $this->umail->validateRecipients(
211 (string) ilUtil::securePlainString($_POST['rcp_to']),
212 (string) ilUtil::securePlainString($_POST['rcp_cc']),
213 (string) ilUtil::securePlainString($_POST['rcp_bcc'])
214 )) {
215 $_POST['attachments'] = $files;
217 $this->showForm();
218 return;
219 }
220
221 if (isset($_SESSION["draft"])) {
222 $draftId = (int) $_SESSION['draft'];
223 unset($_SESSION['draft']);
224 } else {
225 $draftId = $this->umail->getNewDraftId($this->user->getId(), $draftFolderId);
226 }
227
228 $this->umail->updateDraft(
229 $draftFolderId,
230 $files,
234 $_POST['m_type'],
236 ilUtil::securePlainString($_POST['m_subject']),
237 ilUtil::securePlainString($_POST['m_message']),
238 $draftId,
239 (int) $_POST['use_placeholders'],
242 );
243
244 ilUtil::sendInfo($this->lng->txt('mail_saved'), true);
245
248 } else {
249 $this->ctrl->redirectByClass(['ilmailgui', 'ilmailfoldergui']);
250 }
251
252 $this->showForm();
253 }
254
255 public function searchUsers($save = true)
256 {
257 $this->tpl->setTitle($this->lng->txt("mail"));
258
259 if ($save) {
260 // decode post values
261 $files = array();
262 if (is_array($_POST['attachments'])) {
263 foreach ($_POST['attachments'] as $value) {
264 $files[] = urldecode($value);
265 }
266 }
267
268 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
269 $this->umail->savePostData(
270 $this->user->getId(),
271 $files,
275 $_POST["m_type"],
277 ilUtil::securePlainString($_POST["m_subject"]),
278 ilUtil::securePlainString($_POST["m_message"]),
279 ilUtil::securePlainString($_POST['use_placeholders']),
282 );
283 }
284
285 $form = new ilPropertyFormGUI();
286 $form->setId('search_rcp');
287 $form->setTitle($this->lng->txt('search_recipients'));
288 $form->setFormAction($this->ctrl->getFormAction($this, 'search'));
289
290 $inp = new ilTextInputGUI($this->lng->txt("search_for"), 'search');
291 $inp->setSize(30);
292 $dsDataLink = $this->ctrl->getLinkTarget($this, 'lookupRecipientAsync', '', true, false);
293 $inp->setDataSource($dsDataLink);
294
295 if (strlen(trim($_SESSION["mail_search_search"])) > 0) {
296 $inp->setValue(ilUtil::prepareFormOutput(trim($_SESSION["mail_search_search"]), true));
297 }
298 $form->addItem($inp);
299
300 $form->addCommandButton('search', $this->lng->txt("search"));
301 $form->addCommandButton('cancelSearch', $this->lng->txt("cancel"));
302
303 $this->tpl->setContent($form->getHtml());
304 $this->tpl->show();
305 }
306
310 public function searchCoursesTo()
311 {
312 $this->saveMailBeforeSearch();
313
314 if ($_SESSION['search_crs']) {
315 $this->ctrl->setParameterByClass('ilmailsearchcoursesgui', 'cmd', 'showMembers');
316 }
317
318 $this->ctrl->setParameterByClass('ilmailsearchcoursesgui', 'ref', 'mail');
319 $this->ctrl->redirectByClass('ilmailsearchcoursesgui');
320 }
321
325 public function searchGroupsTo()
326 {
327 $this->saveMailBeforeSearch();
328
329 $this->ctrl->setParameterByClass('ilmailsearchgroupsgui', 'ref', 'mail');
330 $this->ctrl->redirectByClass('ilmailsearchgroupsgui');
331 }
332
333 public function search()
334 {
335 $_SESSION["mail_search_search"] = $_POST["search"];
336 if (strlen(trim($_SESSION["mail_search_search"])) == 0) {
337 ilUtil::sendInfo($this->lng->txt("mail_insert_query"));
338 $this->searchUsers(false);
339 } else {
340 if (strlen(trim($_SESSION["mail_search_search"])) < 3) {
341 $this->lng->loadLanguageModule('search');
342 ilUtil::sendInfo($this->lng->txt('search_minimum_three'));
343 $this->searchUsers(false);
344 } else {
345 $this->ctrl->setParameterByClass("ilmailsearchgui", "search", urlencode($_SESSION["mail_search_search"]));
346 $this->ctrl->redirectByClass("ilmailsearchgui");
347 }
348 }
349 }
350
351 public function cancelSearch()
352 {
353 unset($_SESSION["mail_search"]);
354 $this->searchResults();
355 }
356
357 public function editAttachments()
358 {
359 // decode post values
360 $files = array();
361 if (is_array($_POST['attachments'])) {
362 foreach ($_POST['attachments'] as $value) {
363 $files[] = urldecode($value);
364 }
365 }
366
367 // Note: For security reasons, ILIAS only allows Plain text messages.
368 $this->umail->savePostData(
369 $this->user->getId(),
370 $files,
374 $_POST["m_type"],
376 ilUtil::securePlainString($_POST["m_subject"]),
377 ilUtil::securePlainString($_POST["m_message"]),
378 ilUtil::securePlainString($_POST['use_placeholders']),
381 );
382
383 $this->ctrl->redirectByClass("ilmailattachmentgui");
384 }
385
386 public function returnFromAttachments()
387 {
388 $_GET["type"] = "attach";
389 $this->showForm();
390 }
391
392 public function searchResults()
393 {
394 $_GET["type"] = "search_res";
395 $this->showForm();
396 }
397
398 public function mailUser()
399 {
400 $_GET["type"] = "new";
401 $this->showForm();
402 }
403
404 public function mailRole()
405 {
406 $_GET["type"] = "role";
407 $this->showForm();
408 }
409
410 public function replyMail()
411 {
412 $_GET["type"] = "reply";
413 $this->showForm();
414 }
415
416 public function mailAttachment()
417 {
418 $_GET["type"] = "attach";
419 $this->showForm();
420 }
421
425 protected function getTemplateDataById()
426 {
427 if (!isset($_GET['template_id'])) {
428 exit();
429 }
430
431 try {
432 $template = $this->templateService->loadTemplateForId((int) $_GET['template_id']);
434
435 echo json_encode([
436 'm_subject' => $template->getSubject(),
437 'm_message' => $template->getMessage(),
438 ]);
439 } catch (Exception $e) {
440 }
441 exit();
442 }
443
444 public function showForm()
445 {
446 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_new.html", "Services/Mail");
447 $this->tpl->setTitle($this->lng->txt("mail"));
448
449 $this->lng->loadLanguageModule("crs");
450
452 $this->tabs->setBackTarget($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'cancelMail'));
453 }
454
455 switch ($_GET["type"]) {
456 case 'reply':
457 if ($_SESSION['mail_id']) {
458 $_GET['mail_id'] = $_SESSION['mail_id'];
459 }
460 $mailData = $this->umail->getMail($_GET["mail_id"]);
461 $mailData["m_subject"] = $this->umail->formatReplySubject();
462 $mailData["m_message"] = $this->umail->formatReplyMessage();
463 $mailData["m_message"] = $this->umail->prependSignature();
464 // NO ATTACHMENTS FOR REPLIES
465 $mailData["attachments"] = array();
466 //$mailData["rcp_cc"] = $this->umail->formatReplyRecipientsForCC();
467 $mailData["rcp_cc"] = '';
468 $mailData["rcp_to"] = $this->umail->formatReplyRecipient();
469 $_SESSION["mail_id"] = "";
470 break;
471
472 case 'search_res':
473 $mailData = $this->umail->getSavedData();
474
475 /*if($_SESSION["mail_search_results"])
476 {
477 $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results"],$_SESSION["mail_search"]);
478 }
479 unset($_SESSION["mail_search"]);
480 unset($_SESSION["mail_search_results"]);*/
481
482 if ($_SESSION["mail_search_results_to"]) {
483 $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_to"], 'to');
484 }
485 if ($_SESSION["mail_search_results_cc"]) {
486 $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_cc"], 'cc');
487 }
488 if ($_SESSION["mail_search_results_bcc"]) {
489 $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_bcc"], 'bc');
490 }
491
492 unset($_SESSION["mail_search_results_to"]);
493 unset($_SESSION["mail_search_results_cc"]);
494 unset($_SESSION["mail_search_results_bcc"]);
495
496 break;
497
498 case 'attach':
499 $mailData = $this->umail->getSavedData();
500 break;
501
502 case 'draft':
503 $_SESSION["draft"] = $_GET["mail_id"];
504 $mailData = $this->umail->getMail($_GET["mail_id"]);
505 ilMailFormCall::setContextId($mailData['tpl_ctx_id']);
506 ilMailFormCall::setContextParameters($mailData['tpl_ctx_params']);
507 break;
508
509 case 'forward':
510 $mailData = $this->umail->getMail($_GET["mail_id"]);
511 $mailData["rcp_to"] = $mailData["rcp_cc"] = $mailData["rcp_bcc"] = '';
512 $mailData["m_subject"] = $this->umail->formatForwardSubject();
513 $mailData["m_message"] = $this->umail->prependSignature();
514 if (is_array($mailData["attachments"]) && count($mailData["attachments"])) {
515 if ($error = $this->mfile->adoptAttachments($mailData["attachments"], $_GET["mail_id"])) {
516 ilUtil::sendInfo($error);
517 }
518 }
519 break;
520
521 case 'new':
522 if ($_GET['rcp_to']) {
523 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
524 $mailData["rcp_to"] = ilUtil::securePlainString($_GET['rcp_to']);
525 } elseif ($_SESSION['rcp_to']) {
526 $mailData["rcp_to"] = $_SESSION['rcp_to'];
527 }
528 if ($_GET['rcp_cc']) {
529 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
530 $mailData["rcp_cc"] = ilUtil::securePlainString($_GET['rcp_cc']);
531 } elseif ($_SESSION['rcp_cc']) {
532 $mailData["rcp_cc"] = $_SESSION['rcp_cc'];
533 }
534 if ($_GET['rcp_bcc']) {
535 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
536 $mailData["rcp_bcc"] = ilUtil::securePlainString($_GET['rcp_bcc']);
537 } elseif ($_SESSION['rcp_bcc']) {
538 $mailData["rcp_bcc"] = $_SESSION['rcp_bcc'];
539 }
540 $mailData['m_message'] = '';
541 if (strlen($sig = ilMailFormCall::getSignature())) {
542 $mailData['m_message'] = $sig;
543 $mailData['m_message'] .= chr(13) . chr(10) . chr(13) . chr(10);
544 }
545 $mailData['m_message'] .= $this->umail->appendSignature();
546
547 $_SESSION['rcp_to'] = '';
548 $_SESSION['rcp_cc'] = '';
549 $_SESSION['rcp_bcc'] = '';
550 break;
551
552 case 'role':
553
554 if (is_array($_POST['roles'])) {
555 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
556 $mailData['rcp_to'] = ilUtil::securePlainString(implode(',', $_POST['roles']));
557 } elseif (is_array($_SESSION['mail_roles'])) {
558 $mailData['rcp_to'] = ilUtil::securePlainString(implode(',', $_SESSION['mail_roles']));
559 }
560
561 $mailData['m_message'] = '';
562 if (strlen($sig = ilMailFormCall::getSignature())) {
563 $mailData['m_message'] = $sig;
564 $mailData['m_message'] .= chr(13) . chr(10) . chr(13) . chr(10);
565 }
566
567 $mailData['m_message'] .= $_POST["additional_message_text"] . chr(13) . chr(10) . $this->umail->appendSignature();
568 $_POST["additional_message_text"] = "";
569 $_SESSION['mail_roles'] = [];
570 break;
571
572 case 'address':
573 $mailData["rcp_to"] = urldecode($_GET["rcp"]);
574 break;
575
576 default:
577 // GET DATA FROM POST
578 $mailData = $_POST;
579
580 // strip slashes
581 foreach ($mailData as $key => $value) {
582 if (is_string($value)) {
583 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
584 $mailData[$key] = ilUtil::securePlainString($value);
585 }
586 }
587 break;
588 }
589
590 $form_gui = new ilPropertyFormGUI();
591 $form_gui->setTitle($this->lng->txt('compose'));
592 $form_gui->setId('mail_compose_form');
593 $form_gui->setName('mail_compose_form');
594 $form_gui->setFormAction($this->ctrl->getFormAction($this, 'sendMessage'));
595
596 $this->tpl->setVariable('FORM_ID', $form_gui->getId());
597
598 $btn = ilButton::getInstance();
599 $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT);
600 $btn->setForm('form_' . $form_gui->getName())
601 ->setName('searchUsers')
602 ->setCaption('search_recipients');
603 $this->toolbar->addStickyItem($btn);
604
605 $btn = ilButton::getInstance();
606 $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT)
607 ->setName('searchCoursesTo')
608 ->setForm('form_' . $form_gui->getName())
609 ->setCaption('mail_my_courses');
610 $this->toolbar->addButtonInstance($btn);
611
612 $btn = ilButton::getInstance();
613 $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT)
614 ->setName('searchGroupsTo')
615 ->setForm('form_' . $form_gui->getName())
616 ->setCaption('mail_my_groups');
617 $this->toolbar->addButtonInstance($btn);
618
619 if (count(ilBuddyList::getInstanceByGlobalUser()->getLinkedRelations()) > 0) {
620 $btn = ilButton::getInstance();
621 $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT)
622 ->setName('searchMailingListsTo')
623 ->setForm('form_' . $form_gui->getName())
624 ->setCaption('mail_my_mailing_lists');
625 $this->toolbar->addButtonInstance($btn);
626 }
627
628 $dsDataLink = $this->ctrl->getLinkTarget($this, 'lookupRecipientAsync', '', true);
629
630 $inp = new ilTextInputGUI($this->lng->txt('mail_to'), 'rcp_to');
631 $inp->setRequired(true);
632 $inp->setSize(50);
633 $inp->setValue($mailData["rcp_to"]);
634 $inp->setDataSource($dsDataLink, ",");
635 $inp->setMaxLength(null);
636 $form_gui->addItem($inp);
637
638 $inp = new ilTextInputGUI($this->lng->txt('cc'), 'rcp_cc');
639 $inp->setSize(50);
640 $inp->setValue($mailData["rcp_cc"]);
641 $inp->setDataSource($dsDataLink, ",");
642 $inp->setMaxLength(null);
643 $form_gui->addItem($inp);
644
645 $inp = new ilTextInputGUI($this->lng->txt('bc'), 'rcp_bcc');
646 $inp->setSize(50);
647 $inp->setValue($mailData["rcp_bcc"]);
648 $inp->setDataSource($dsDataLink, ",");
649 $inp->setMaxLength(null);
650 $form_gui->addItem($inp);
651
652 $inp = new ilTextInputGUI($this->lng->txt('subject'), 'm_subject');
653 $inp->setSize(50);
654 $inp->setRequired(true);
655 $inp->setValue($mailData["m_subject"]);
656 $form_gui->addItem($inp);
657
658 $att = new ilMailFormAttachmentPropertyGUI($this->lng->txt(($mailData["attachments"]) ? 'edit' : 'add'));
659
660 if (is_array($mailData["attachments"]) && count($mailData["attachments"])) {
661 foreach ($mailData["attachments"] as $data) {
662 if (is_file($this->mfile->getMailPath() . '/' . $this->user->getId() . "_" . $data)) {
663 $hidden = new ilHiddenInputGUI('attachments[]');
664 $form_gui->addItem($hidden);
665 $size = filesize($this->mfile->getMailPath() . '/' . $this->user->getId() . "_" . $data);
666 $label = $data . " [" . ilUtil::formatSize($size) . "]";
667 $att->addItem($label);
668 $hidden->setValue(urlencode($data));
669 }
670 }
671 }
672 $form_gui->addItem($att);
673
674 // ONLY IF SYSTEM MAILS ARE ALLOWED
675 if ($this->rbacsystem->checkAccess("system_message", $this->umail->getMailObjectReferenceId())) {
676 $chb = new ilCheckboxInputGUI($this->lng->txt('type'), 'm_type[]');
677 $chb->setOptionTitle($this->lng->txt('system_message'));
678 $chb->setValue('system');
679 $chb->setChecked(false);
680 if (is_array($mailData["m_type"]) and in_array('system', $mailData["m_type"])) {
681 $chb->setChecked(true);
682 }
683 $form_gui->addItem($chb);
684 }
685
687 $context_id = ilMailFormCall::getContextId();
688
689 $mailData['use_placeholders'] = true;
690
691 try {
693
694 $templates = $this->templateService->loadTemplatesForContextId($context->getId());
695 if (count($templates) > 0) {
696 $options = array();
697
698 $template_chb = new ilMailTemplateSelectInputGUI(
699 $this->lng->txt('mail_template_client'),
700 'template_id',
701 $this->ctrl->getLinkTarget($this, 'getTemplateDataById', '', true, false),
702 array('m_subject', 'm_message')
703 );
704
705 foreach ($templates as $template) {
706 $options[$template->getTplId()] = $template->getTitle();
707
708 if (!isset($mailData['template_id']) && $template->isDefault()) {
709 $template_chb->setValue($template->getTplId());
710 $form_gui->getItemByPostVar('m_subject')->setValue($template->getSubject());
711 $mailData["m_message"] = $template->getMessage();
712 }
713 }
714 if (isset($mailData['template_id'])) {
715 $template_chb->setValue((int) $mailData['template_id']);
716 }
717 asort($options);
718
719 $template_chb->setInfo($this->lng->txt('mail_template_client_info'));
720 $template_chb->setOptions(array('' => $this->lng->txt('please_choose')) + $options);
721 $form_gui->addItem($template_chb);
722 }
723 } catch (Exception $e) {
724 ilLoggerFactory::getLogger('mail')->error(sprintf(
725 '%s has been called with invalid context id: %s.',
726 __METHOD__,
727 $context_id
728 ));
729 }
730 } else {
732 }
733
734 // MESSAGE
735 $inp = new ilTextAreaInputGUI($this->lng->txt('message_content'), 'm_message');
736 //$inp->setValue(htmlspecialchars($mailData["m_message"], false));
737 $inp->setValue($mailData["m_message"]);
738 $inp->setRequired(false);
739 $inp->setCols(60);
740 $inp->setRows(10);
741 $form_gui->addItem($inp);
742
743 // PLACEHOLDERS
744 $chb = new ilCheckboxInputGUI($this->lng->txt('mail_serial_letter_placeholders'), 'use_placeholders');
745 $chb->setOptionTitle($this->lng->txt('activate_serial_letter_placeholders'));
746 $chb->setValue(1);
747 if (isset($mailData['use_placeholders']) && $mailData['use_placeholders']) {
748 $chb->setChecked(true);
749 }
750
751 $placeholders = new ilManualPlaceholderInputGUI('m_message');
752 $placeholders->setInstructionText($this->lng->txt('mail_nacc_use_placeholder'));
753 $placeholders->setAdviseText(sprintf($this->lng->txt('placeholders_advise'), '<br />'));
754 foreach ($context->getPlaceholders() as $key => $value) {
755 $placeholders->addPlaceholder($value['placeholder'], $value['label']);
756 }
757 $chb->addSubItem($placeholders);
758 $form_gui->addItem($chb);
759
760 $form_gui->addCommandButton('sendMessage', $this->lng->txt('send_mail'));
761 $form_gui->addCommandButton('saveDraft', $this->lng->txt('save_message'));
763 $form_gui->addCommandButton('cancelMail', $this->lng->txt('cancel'));
764 }
765
766 $this->tpl->parseCurrentBlock();
767
768 $this->tpl->setVariable('FORM', $form_gui->getHTML());
769
770 $this->tpl->addJavaScript('Services/Mail/js/ilMailComposeFunctions.js');
771 $this->tpl->show();
772 }
773
774 public function lookupRecipientAsync()
775 {
776 $search = '';
777 if (isset($_GET["term"]) && is_string($_GET["term"])) {
778 $search = $_GET["term"];
779 }
780 if (isset($_POST["term"]) && is_string($_POST["term"])) {
781 $search = $_POST["term"];
782 }
783
784 $search = trim($search);
785
786 $result = array();
787
788 require_once 'Services/Utilities/classes/class.ilStr.php';
789 if (ilStr::strLen($search) < 3) {
790 echo json_encode($result);
791 exit;
792 }
793
794 // #14768
795 $quoted = ilUtil::stripSlashes($search);
796 $quoted = str_replace('%', '\%', $quoted);
797 $quoted = str_replace('_', '\_', $quoted);
798
799 $mailFormObj = new ilMailForm;
800 $result = $mailFormObj->getRecipientAsync("%" . $quoted . "%", ilUtil::stripSlashes($search));
801
802 echo json_encode($result);
803 exit;
804 }
805
806 public function cancelMail()
807 {
810 }
811
812 $this->showForm();
813 }
814
818 protected function saveMailBeforeSearch()
819 {
820 $files = array();
821 if (is_array($_POST['attachments'])) {
822 foreach ($_POST['attachments'] as $value) {
823 $files[] = urldecode($value);
824 }
825 }
826
827 $this->umail->savePostData(
828 $this->user->getId(),
829 $files,
833 $_POST['m_type'],
835 ilUtil::securePlainString($_POST['m_subject']),
836 ilUtil::securePlainString($_POST['m_message']),
837 ilUtil::securePlainString($_POST['use_placeholders']),
840 );
841 }
842
846 public function searchMailingListsTo()
847 {
848 $this->saveMailBeforeSearch();
849
850 $this->ctrl->setParameterByClass('ilmailinglistsgui', 'ref', 'mail');
851 $this->ctrl->redirectByClass('ilmailinglistsgui');
852 }
853
857 protected function showSubmissionErrors(array $errors)
858 {
859 $formatter = new ilMailErrorFormatter($this->lng);
860 $formattedErrors = $formatter->format($errors);
861
862 if (strlen($formattedErrors) > 0) {
863 ilUtil::sendFailure($formattedErrors);
864 }
865 }
866}
$result
user()
Definition: user.php:4
$size
Definition: RandomTest.php:84
exit
Definition: backend.php:16
$_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
$template
$key
Definition: croninfo.php:18
catch(Exception $e) $message
$errors
Definition: index.php:6
$files
Definition: metarefresh.php:49
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
$data
Definition: bench.php:6
$context
Definition: webdav.php:25