ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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{
22 private $tpl;
23
27 private $ctrl;
28
32 private $lng;
33
37 private $user;
38
42 private $tabs;
43
47 private $toolbar;
48
52 private $rbacsystem;
53
57 private $umail;
58
62 private $mbox;
63
67 private $mfile;
68
72 private $purifier;
73
77 public function __construct(\ilMailBodyPurifier $bodyPurifier = null)
78 {
79 global $DIC;
80
81 $this->tpl = $DIC->ui()->mainTemplate();
82 $this->ctrl = $DIC->ctrl();
83 $this->lng = $DIC->language();
84 $this->user = $DIC->user();
85 $this->tabs = $DIC->tabs();
86 $this->toolbar = $DIC->toolbar();
87 $this->rbacsystem = $DIC->rbac()->system();
88
89 $this->umail = new ilFormatMail($this->user->getId());
90 $this->mfile = new ilFileDataMail($this->user->getId());
91 $this->mbox = new ilMailBox($this->user->getId());
92
93 if (null === $bodyPurifier) {
94 $bodyPurifier = new ilMailBodyPurifier();
95 }
96 $this->purifier = $bodyPurifier;
97
98 if (isset($_POST['mobj_id']) && (int) $_POST['mobj_id']) {
99 $_GET['mobj_id'] = $_POST['mobj_id'];
100 }
101
102 if (!(int) $_GET['mobj_id']) {
103 $_GET['mobj_id'] = $this->mbox->getInboxFolder();
104 }
105 $_GET['mobj_id'] = (int) $_GET['mobj_id'];
106
107 $this->ctrl->saveParameter($this, 'mobj_id');
108 }
109
110 public function executeCommand()
111 {
112 $forward_class = $this->ctrl->getNextClass($this);
113 switch ($forward_class) {
114 case 'ilmailfoldergui':
115 include_once 'Services/Mail/classes/class.ilMailFolderGUI.php';
116
117 $this->ctrl->forwardCommand(new ilMailFolderGUI());
118 break;
119
120 case 'ilmailattachmentgui':
121 include_once 'Services/Mail/classes/class.ilMailAttachmentGUI.php';
122
123 $this->ctrl->setReturn($this, "returnFromAttachments");
124 $this->ctrl->forwardCommand(new ilMailAttachmentGUI());
125 break;
126
127 case 'ilmailsearchgui':
128 include_once 'Services/Contact/classes/class.ilMailSearchGUI.php';
129
130 $this->ctrl->setReturn($this, "searchResults");
131 $this->ctrl->forwardCommand(new ilMailSearchGUI());
132 break;
133
134 case 'ilmailsearchcoursesgui':
135 include_once 'Services/Contact/classes/class.ilMailSearchCoursesGUI.php';
136
137 $this->ctrl->setReturn($this, "searchResults");
138 $this->ctrl->forwardCommand(new ilMailSearchCoursesGUI());
139 break;
140
141 case 'ilmailinglistsgui':
142 include_once 'Services/Contact/classes/class.ilMailingListsGUI.php';
143
144 $this->ctrl->setReturn($this, 'searchResults');
145 $this->ctrl->forwardCommand(new ilMailingListsGUI());
146 break;
147
148 case 'ilmailsearchgroupsgui':
149 include_once 'Services/Contact/classes/class.ilMailSearchGroupsGUI.php';
150
151 $this->ctrl->setReturn($this, "searchResults");
152 $this->ctrl->forwardCommand(new ilMailSearchGroupsGUI());
153 break;
154
155 default:
156 if (!($cmd = $this->ctrl->getCmd())) {
157 $cmd = "showForm";
158 }
159
160 $this->$cmd();
161 break;
162 }
163 return true;
164 }
165
170 protected function decodeAttachmentFiles(array $files)
171 {
172 $decodedFiles = array();
173
174 foreach ($files as $value) {
175 if (is_file($this->mfile->getMailPath() . '/' . $this->user->getId() . '_' . urldecode($value))) {
176 $decodedFiles[] = urldecode($value);
177 }
178 }
179
180 return $decodedFiles;
181 }
182
183 public function sendMessage()
184 {
185 $m_type = isset($_POST["m_type"]) ? $_POST["m_type"] : array("normal");
186
187 $message = (string) $_POST['m_message'];
188 $mailBody = new ilMailBody($message, $this->purifier);
189
190 $sanitizedMessage = $mailBody->getContent();
191
192 $files = $this->decodeAttachmentFiles(isset($_POST['attachments']) ? (array) $_POST['attachments'] : array());
193
194 $this->umail->setSaveInSentbox(true);
195 if ($errors = $this->umail->sendMail(
199 ilUtil::securePlainString($_POST['m_subject']),
200 $sanitizedMessage,
201 $files,
202 $m_type,
203 (int) $_POST['use_placeholders']
204 )
205 ) {
206 $_POST['attachments'] = $files;
208 } else {
209 $this->umail->savePostData($this->user->getId(), array(), "", "", "", "", "", "", "", "");
210
211 $this->ctrl->setParameterByClass('ilmailgui', 'type', 'message_sent');
212
214 ilUtil::sendInfo($this->lng->txt('mail_message_send'), true);
216 } else {
217 $this->ctrl->redirectByClass('ilmailgui');
218 }
219 }
220
221 $this->showForm();
222 }
223
224 public function saveDraft()
225 {
226 if (!$_POST['m_subject']) {
227 $_POST['m_subject'] = 'No title';
228 }
229
230 $draftFolderId = $this->mbox->getDraftsFolder();
231 $files = $this->decodeAttachmentFiles(isset($_POST['attachments']) ? (array) $_POST['attachments'] : array());
232
233 if ($errors = $this->umail->validateRecipients(
237 )) {
238 $_POST['attachments'] = $files;
240 $this->showForm();
241 return;
242 }
243
244 if (isset($_SESSION["draft"])) {
245 $draftId = (int) $_SESSION['draft'];
246 unset($_SESSION['draft']);
247 } else {
248 $draftId = $this->umail->getNewDraftId($this->user->getId(), $draftFolderId);
249 }
250
251 $this->umail->updateDraft(
252 $draftFolderId,
253 $files,
257 $_POST['m_type'],
259 ilUtil::securePlainString($_POST['m_subject']),
260 ilUtil::securePlainString($_POST['m_message']),
261 $draftId,
262 (int) $_POST['use_placeholders'],
265 );
266
267 ilUtil::sendInfo($this->lng->txt('mail_saved'), true);
268
271 } else {
272 $this->ctrl->redirectByClass(['ilmailgui', 'ilmailfoldergui']);
273 }
274
275 $this->showForm();
276 }
277
278 public function searchUsers($save = true)
279 {
280 $this->tpl->setTitle($this->lng->txt("mail"));
281
282 if ($save) {
283 // decode post values
284 $files = array();
285 if (is_array($_POST['attachments'])) {
286 foreach ($_POST['attachments'] as $value) {
287 $files[] = urldecode($value);
288 }
289 }
290
291 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
292 $this->umail->savePostData(
293 $this->user->getId(),
294 $files,
298 $_POST["m_type"],
300 ilUtil::securePlainString($_POST["m_subject"]),
301 ilUtil::securePlainString($_POST["m_message"]),
302 ilUtil::securePlainString($_POST['use_placeholders']),
305 );
306 }
307 include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
308 $form = new ilPropertyFormGUI();
309 $form->setId('search_rcp');
310 $form->setTitle($this->lng->txt('search_recipients'));
311 $form->setFormAction($this->ctrl->getFormAction($this, 'search'));
312
313 $inp = new ilTextInputGUI($this->lng->txt("search_for"), 'search');
314 $inp->setSize(30);
315 $dsDataLink = $this->ctrl->getLinkTarget($this, 'lookupRecipientAsync', '', true, false);
316 $inp->setDataSource($dsDataLink);
317
318 if (strlen(trim($_SESSION["mail_search_search"])) > 0) {
319 $inp->setValue(ilUtil::prepareFormOutput(trim($_SESSION["mail_search_search"]), true));
320 }
321 $form->addItem($inp);
322
323 $form->addCommandButton('search', $this->lng->txt("search"));
324 $form->addCommandButton('cancelSearch', $this->lng->txt("cancel"));
325
326 $this->tpl->setContent($form->getHtml());
327 $this->tpl->show();
328 }
329
333 public function searchCoursesTo()
334 {
335 $this->saveMailBeforeSearch();
336
337 if ($_SESSION['search_crs']) {
338 $this->ctrl->setParameterByClass('ilmailsearchcoursesgui', 'cmd', 'showMembers');
339 }
340
341 $this->ctrl->setParameterByClass('ilmailsearchcoursesgui', 'ref', 'mail');
342 $this->ctrl->redirectByClass('ilmailsearchcoursesgui');
343 }
344
348 public function searchGroupsTo()
349 {
350 $this->saveMailBeforeSearch();
351
352 $this->ctrl->setParameterByClass('ilmailsearchgroupsgui', 'ref', 'mail');
353 $this->ctrl->redirectByClass('ilmailsearchgroupsgui');
354 }
355
356 public function search()
357 {
358 $_SESSION["mail_search_search"] = $_POST["search"];
359 if (strlen(trim($_SESSION["mail_search_search"])) == 0) {
360 ilUtil::sendInfo($this->lng->txt("mail_insert_query"));
361 $this->searchUsers(false);
362 } else {
363 if (strlen(trim($_SESSION["mail_search_search"])) < 3) {
364 $this->lng->loadLanguageModule('search');
365 ilUtil::sendInfo($this->lng->txt('search_minimum_three'));
366 $this->searchUsers(false);
367 } else {
368 $this->ctrl->setParameterByClass("ilmailsearchgui", "search", urlencode($_SESSION["mail_search_search"]));
369 $this->ctrl->redirectByClass("ilmailsearchgui");
370 }
371 }
372 }
373
374 public function cancelSearch()
375 {
376 unset($_SESSION["mail_search"]);
377 $this->searchResults();
378 }
379
380 public function editAttachments()
381 {
382 // decode post values
383 $files = array();
384 if (is_array($_POST['attachments'])) {
385 foreach ($_POST['attachments'] as $value) {
386 $files[] = urldecode($value);
387 }
388 }
389
390 // Note: For security reasons, ILIAS only allows Plain text messages.
391 $this->umail->savePostData(
392 $this->user->getId(),
393 $files,
397 $_POST["m_type"],
399 ilUtil::securePlainString($_POST["m_subject"]),
400 ilUtil::securePlainString($_POST["m_message"]),
401 ilUtil::securePlainString($_POST['use_placeholders']),
404 );
405
406 $this->ctrl->redirectByClass("ilmailattachmentgui");
407 }
408
409 public function returnFromAttachments()
410 {
411 $_GET["type"] = "attach";
412 $this->showForm();
413 }
414
415 public function searchResults()
416 {
417 $_GET["type"] = "search_res";
418 $this->showForm();
419 }
420
421 public function mailUser()
422 {
423 $_GET["type"] = "new";
424 $this->showForm();
425 }
426
427 public function mailRole()
428 {
429 $_GET["type"] = "role";
430 $this->showForm();
431 }
432
433 public function replyMail()
434 {
435 $_GET["type"] = "reply";
436 $this->showForm();
437 }
438
439 public function mailAttachment()
440 {
441 $_GET["type"] = "attach";
442 $this->showForm();
443 }
444
448 protected function getTemplateDataById()
449 {
450 require_once 'Services/JSON/classes/class.ilJsonUtil.php';
451
452 if (!isset($_GET['template_id'])) {
453 exit();
454 }
455
456 try {
457 require_once 'Services/Mail/classes/class.ilMailTemplateService.php';
458 require_once 'Services/Mail/classes/class.ilMailTemplateDataProvider.php';
459 $template_id = (int) $_GET['template_id'];
460 $template_provider = new ilMailTemplateDataProvider();
461 $template = $template_provider->getTemplateById($template_id);
463 echo json_encode(array(
464 'm_subject' => $template->getSubject(),
465 'm_message' => $template->getMessage()
466 ));
467 } catch (Exception $e) {
468 }
469 exit();
470 }
471
472 public function showForm()
473 {
474 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_new.html", "Services/Mail");
475 $this->tpl->setTitle($this->lng->txt("mail"));
476
477 $this->lng->loadLanguageModule("crs");
478
480 $this->tabs->setBackTarget($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'cancelMail'));
481 }
482
483 switch ($_GET["type"]) {
484 case 'reply':
485 if ($_SESSION['mail_id']) {
486 $_GET['mail_id'] = $_SESSION['mail_id'];
487 }
488 $mailData = $this->umail->getMail($_GET["mail_id"]);
489 $mailData["m_subject"] = $this->umail->formatReplySubject();
490 $mailData["m_message"] = $this->umail->formatReplyMessage();
491 $mailData["m_message"] = $this->umail->prependSignature();
492 // NO ATTACHMENTS FOR REPLIES
493 $mailData["attachments"] = array();
494 //$mailData["rcp_cc"] = $this->umail->formatReplyRecipientsForCC();
495 $mailData["rcp_cc"] = '';
496 $mailData["rcp_to"] = $this->umail->formatReplyRecipient();
497 $_SESSION["mail_id"] = "";
498 break;
499
500 case 'search_res':
501 $mailData = $this->umail->getSavedData();
502
503 /*if($_SESSION["mail_search_results"])
504 {
505 $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results"],$_SESSION["mail_search"]);
506 }
507 unset($_SESSION["mail_search"]);
508 unset($_SESSION["mail_search_results"]);*/
509
510 if ($_SESSION["mail_search_results_to"]) {
511 $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_to"], 'to');
512 }
513 if ($_SESSION["mail_search_results_cc"]) {
514 $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_cc"], 'cc');
515 }
516 if ($_SESSION["mail_search_results_bcc"]) {
517 $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_bcc"], 'bc');
518 }
519
520 unset($_SESSION["mail_search_results_to"]);
521 unset($_SESSION["mail_search_results_cc"]);
522 unset($_SESSION["mail_search_results_bcc"]);
523
524 break;
525
526 case 'attach':
527 $mailData = $this->umail->getSavedData();
528 break;
529
530 case 'draft':
531 $_SESSION["draft"] = $_GET["mail_id"];
532 $mailData = $this->umail->getMail($_GET["mail_id"]);
533 ilMailFormCall::setContextId($mailData['tpl_ctx_id']);
534 ilMailFormCall::setContextParameters($mailData['tpl_ctx_params']);
535 break;
536
537 case 'forward':
538 $mailData = $this->umail->getMail($_GET["mail_id"]);
539 $mailData["rcp_to"] = $mailData["rcp_cc"] = $mailData["rcp_bcc"] = '';
540 $mailData["m_subject"] = $this->umail->formatForwardSubject();
541 $mailData["m_message"] = $this->umail->prependSignature();
542 if (is_array($mailData["attachments"]) && count($mailData["attachments"])) {
543 if ($error = $this->mfile->adoptAttachments($mailData["attachments"], $_GET["mail_id"])) {
545 }
546 }
547 break;
548
549 case 'new':
550 if ($_GET['rcp_to']) {
551 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
552 $mailData["rcp_to"] = ilUtil::securePlainString($_GET['rcp_to']);
553 } elseif ($_SESSION['rcp_to']) {
554 $mailData["rcp_to"] = $_SESSION['rcp_to'];
555 }
556 if ($_GET['rcp_cc']) {
557 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
558 $mailData["rcp_cc"] = ilUtil::securePlainString($_GET['rcp_cc']);
559 } elseif ($_SESSION['rcp_cc']) {
560 $mailData["rcp_cc"] = $_SESSION['rcp_cc'];
561 }
562 if ($_GET['rcp_bcc']) {
563 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
564 $mailData["rcp_bcc"] = ilUtil::securePlainString($_GET['rcp_bcc']);
565 } elseif ($_SESSION['rcp_bcc']) {
566 $mailData["rcp_bcc"] = $_SESSION['rcp_bcc'];
567 }
568 $mailData['m_message'] = '';
569 if (strlen($sig = ilMailFormCall::getSignature())) {
570 $mailData['m_message'] = $sig;
571 $mailData['m_message'] .= chr(13) . chr(10) . chr(13) . chr(10);
572 }
573 $mailData['m_message'] .= $this->umail->appendSignature();
574
575 $_SESSION['rcp_to'] = '';
576 $_SESSION['rcp_cc'] = '';
577 $_SESSION['rcp_bcc'] = '';
578 break;
579
580 case 'role':
581
582 if (is_array($_POST['roles'])) {
583 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
584 $mailData['rcp_to'] = ilUtil::securePlainString(implode(',', $_POST['roles']));
585 } elseif (is_array($_SESSION['mail_roles'])) {
586 $mailData['rcp_to'] = ilUtil::securePlainString(implode(',', $_SESSION['mail_roles']));
587 }
588
589 $mailData['m_message'] = '';
590 if (strlen($sig = ilMailFormCall::getSignature())) {
591 $mailData['m_message'] = $sig;
592 $mailData['m_message'] .= chr(13) . chr(10) . chr(13) . chr(10);
593 }
594
595 $mailData['m_message'] .= $_POST["additional_message_text"] . chr(13) . chr(10) . $this->umail->appendSignature();
596 $_POST["additional_message_text"] = "";
597 $_SESSION['mail_roles'] = [];
598 break;
599
600 case 'address':
601 $mailData["rcp_to"] = urldecode($_GET["rcp"]);
602 break;
603
604 default:
605 // GET DATA FROM POST
606 $mailData = $_POST;
607
608 // strip slashes
609 foreach ($mailData as $key => $value) {
610 if (is_string($value)) {
611 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
612 $mailData[$key] = ilUtil::securePlainString($value);
613 }
614 }
615 break;
616 }
617
618 include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
619
620 $form_gui = new ilPropertyFormGUI();
621 $form_gui->setTitle($this->lng->txt('compose'));
622 $form_gui->setId('mail_compose_form');
623 $form_gui->setName('mail_compose_form');
624 $form_gui->setFormAction($this->ctrl->getFormAction($this, 'sendMessage'));
625
626 $this->tpl->setVariable('FORM_ID', $form_gui->getId());
627
628 require_once 'Services/UIComponent/Button/classes/class.ilButton.php';
629 $btn = ilButton::getInstance();
630 $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT);
631 $btn->setForm('form_' . $form_gui->getName())
632 ->setName('searchUsers')
633 ->setCaption('search_recipients');
634 $this->toolbar->addStickyItem($btn);
635
636 $btn = ilButton::getInstance();
637 $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT)
638 ->setName('searchCoursesTo')
639 ->setForm('form_' . $form_gui->getName())
640 ->setCaption('mail_my_courses');
641 $this->toolbar->addButtonInstance($btn);
642
643 $btn = ilButton::getInstance();
644 $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT)
645 ->setName('searchGroupsTo')
646 ->setForm('form_' . $form_gui->getName())
647 ->setCaption('mail_my_groups');
648 $this->toolbar->addButtonInstance($btn);
649
650 require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystem.php';
651 if (count(ilBuddyList::getInstanceByGlobalUser()->getLinkedRelations()) > 0) {
652 $btn = ilButton::getInstance();
653 $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT)
654 ->setName('searchMailingListsTo')
655 ->setForm('form_' . $form_gui->getName())
656 ->setCaption('mail_my_mailing_lists');
657 $this->toolbar->addButtonInstance($btn);
658 }
659
660 $dsDataLink = $this->ctrl->getLinkTarget($this, 'lookupRecipientAsync', '', true);
661
662 // RECIPIENT
663 $inp = new ilTextInputGUI($this->lng->txt('mail_to'), 'rcp_to');
664 $inp->setRequired(true);
665 $inp->setSize(50);
666 $inp->setValue($mailData["rcp_to"]);
667 $inp->setDataSource($dsDataLink, ",");
668 $inp->setMaxLength(null);
669 $form_gui->addItem($inp);
670
671 // CC
672 $inp = new ilTextInputGUI($this->lng->txt('cc'), 'rcp_cc');
673 $inp->setSize(50);
674 $inp->setValue($mailData["rcp_cc"]);
675 $inp->setDataSource($dsDataLink, ",");
676 $inp->setMaxLength(null);
677 $form_gui->addItem($inp);
678
679 // BCC
680 $inp = new ilTextInputGUI($this->lng->txt('bc'), 'rcp_bcc');
681 $inp->setSize(50);
682 $inp->setValue($mailData["rcp_bcc"]);
683 $inp->setDataSource($dsDataLink, ",");
684 $inp->setMaxLength(null);
685 $form_gui->addItem($inp);
686
687 // SUBJECT
688 $inp = new ilTextInputGUI($this->lng->txt('subject'), 'm_subject');
689 $inp->setSize(50);
690 $inp->setRequired(true);
691 $inp->setValue($mailData["m_subject"]);
692 $form_gui->addItem($inp);
693
694 // Attachments
695 include_once 'Services/Mail/classes/class.ilMailFormAttachmentFormPropertyGUI.php';
696 $att = new ilMailFormAttachmentPropertyGUI($this->lng->txt(($mailData["attachments"]) ? 'edit' : 'add'));
697
698 if (is_array($mailData["attachments"]) && count($mailData["attachments"])) {
699 foreach ($mailData["attachments"] as $data) {
700 if (is_file($this->mfile->getMailPath() . '/' . $this->user->getId() . "_" . $data)) {
701 $hidden = new ilHiddenInputGUI('attachments[]');
702 $form_gui->addItem($hidden);
703 $size = filesize($this->mfile->getMailPath() . '/' . $this->user->getId() . "_" . $data);
704 $label = $data . " [" . ilUtil::formatSize($size) . "]";
705 $att->addItem($label);
706 $hidden->setValue(urlencode($data));
707 }
708 }
709 }
710 $form_gui->addItem($att);
711
712 // ONLY IF SYSTEM MAILS ARE ALLOWED
713 if ($this->rbacsystem->checkAccess("system_message", $this->umail->getMailObjectReferenceId())) {
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 $chb->setChecked(true);
720 }
721 $form_gui->addItem($chb);
722 }
723
725 $context_id = ilMailFormCall::getContextId();
726
727 // Activate placeholders
728 $mailData['use_placeholders'] = true;
729
730 try {
731 require_once 'Services/Mail/classes/class.ilMailTemplateService.php';
732 $context = ilMailTemplateService::getTemplateContextById($context_id);
733
734 require_once 'Services/Mail/classes/class.ilMailTemplateDataProvider.php';
735 $template_provider = new ilMailTemplateDataProvider();
736 $templates = $template_provider->getTemplateByContextId($context->getId());
737
738 if (count($templates)) {
739 $options = array();
740 foreach ($templates as $template) {
741 $options[$template->getTplId()] = $template->getTitle();
742 }
743 asort($options);
744
745 require_once 'Services/Mail/classes/Form/class.ilMailTemplateSelectInputGUI.php';
746 $template_chb = new ilMailTemplateSelectInputGUI(
747 $this->lng->txt('mail_template_client'),
748 'template_id',
749 $this->ctrl->getLinkTarget($this, 'getTemplateDataById', '', true, false),
750 array('m_subject', 'm_message')
751 );
752 $template_chb->setInfo($this->lng->txt('mail_template_client_info'));
753 $template_chb->setOptions(array('' => $this->lng->txt('please_choose')) + $options);
754 $form_gui->addItem($template_chb);
755 }
756 } catch (Exception $e) {
757 require_once './Services/Logging/classes/public/class.ilLoggerFactory.php';
758 ilLoggerFactory::getLogger('mail')->error(sprintf('%s has been called with invalid context id: %s.', __METHOD__, $context_id));
759 }
760 } else {
761 require_once 'Services/Mail/classes/class.ilMailTemplateGenericContext.php';
762 $context = new ilMailTemplateGenericContext();
763 }
764
765 // MESSAGE
766 $inp = new ilTextAreaInputGUI($this->lng->txt('message_content'), 'm_message');
767 //$inp->setValue(htmlspecialchars($mailData["m_message"], false));
768 $inp->setValue($mailData["m_message"]);
769 $inp->setRequired(false);
770 $inp->setCols(60);
771 $inp->setRows(10);
772 $form_gui->addItem($inp);
773
774 // PLACEHOLDERS
775 $chb = new ilCheckboxInputGUI($this->lng->txt('mail_serial_letter_placeholders'), 'use_placeholders');
776 $chb->setOptionTitle($this->lng->txt('activate_serial_letter_placeholders'));
777 $chb->setValue(1);
778 if (isset($mailData['use_placeholders']) && $mailData['use_placeholders']) {
779 $chb->setChecked(true);
780 }
781
782 require_once 'Services/Mail/classes/Form/class.ilManualPlaceholderInputGUI.php';
783 $placeholders = new ilManualPlaceholderInputGUI('m_message');
784 $placeholders->setInstructionText($this->lng->txt('mail_nacc_use_placeholder'));
785 $placeholders->setAdviseText(sprintf($this->lng->txt('placeholders_advise'), '<br />'));
786 foreach ($context->getPlaceholders() as $key => $value) {
787 $placeholders->addPlaceholder($value['placeholder'], $value['label']);
788 }
789 $chb->addSubItem($placeholders);
790 $form_gui->addItem($chb);
791
792 $form_gui->addCommandButton('sendMessage', $this->lng->txt('send_mail'));
793 $form_gui->addCommandButton('saveDraft', $this->lng->txt('save_message'));
795 $form_gui->addCommandButton('cancelMail', $this->lng->txt('cancel'));
796 }
797
798 $this->tpl->parseCurrentBlock();
799
800 $this->tpl->setVariable('FORM', $form_gui->getHTML());
801
802 $this->tpl->addJavaScript('Services/Mail/js/ilMailComposeFunctions.js');
803 $this->tpl->show();
804 }
805
806 public function lookupRecipientAsync()
807 {
808 include_once 'Services/JSON/classes/class.ilJsonUtil.php';
809 include_once 'Services/Mail/classes/class.ilMailForm.php';
810 $search = '';
811 if (isset($_GET["term"]) && is_string($_GET["term"])) {
812 $search = $_GET["term"];
813 }
814 if (isset($_POST["term"]) && is_string($_POST["term"])) {
815 $search = $_POST["term"];
816 }
817
818 $search = trim($search);
819
820 $result = array();
821
822 require_once 'Services/Utilities/classes/class.ilStr.php';
823 if (\ilStr::strLen($search) < 3) {
824 echo json_encode($result);
825 exit;
826 }
827
828 // #14768
829 $quoted = ilUtil::stripSlashes($search);
830 $quoted = str_replace('%', '\%', $quoted);
831 $quoted = str_replace('_', '\_', $quoted);
832
833 $mailFormObj = new ilMailForm;
834 $result = $mailFormObj->getRecipientAsync("%" . $quoted . "%", ilUtil::stripSlashes($search));
835
836 echo json_encode($result);
837 exit;
838 }
839
840 public function cancelMail()
841 {
844 }
845
846 $this->showForm();
847 }
848
852 protected function saveMailBeforeSearch()
853 {
854 $files = array();
855 if (is_array($_POST['attachments'])) {
856 foreach ($_POST['attachments'] as $value) {
857 $files[] = urldecode($value);
858 }
859 }
860
861 $this->umail->savePostData(
862 $this->user->getId(),
863 $files,
867 $_POST['m_type'],
869 ilUtil::securePlainString($_POST['m_subject']),
870 ilUtil::securePlainString($_POST['m_message']),
871 ilUtil::securePlainString($_POST['use_placeholders']),
874 );
875 }
876
880 public function searchMailingListsTo()
881 {
882 $this->saveMailBeforeSearch();
883
884 $this->ctrl->setParameterByClass('ilmailinglistsgui', 'ref', 'mail');
885 $this->ctrl->redirectByClass('ilmailinglistsgui');
886 }
887
891 protected function showSubmissionErrors(array $errors)
892 {
893 $errors_to_display = array();
894
895 foreach ($errors as $error) {
896 $error = array_values($error);
897 $first_error = array_shift($error);
898
899 $translation = $this->lng->txt($first_error);
900 if ($translation == '-' . $first_error . '-') {
901 $translation = $first_error;
902 }
903
904 if (count($error) == 0 || $translation == $first_error) {
905 $errors_to_display[] = $translation;
906 } else {
907 // We expect all other parts of this error array are recipient addresses = input parameters
908 $error = array_map(function ($address) {
909 return ilUtil::prepareFormOutput($address);
910 }, $error);
911
912 array_unshift($error, $translation);
913 $errors_to_display[] = call_user_func_array('sprintf', $error);
914 }
915 }
916
917 if (count($errors_to_display) > 0) {
918 $tpl = new ilTemplate('tpl.mail_new_submission_errors.html', true, true, 'Services/Mail');
919 if (count($errors_to_display) == 1) {
920 $tpl->setCurrentBlock('single_error');
921 $tpl->setVariable('SINGLE_ERROR', current($errors_to_display));
922 $tpl->parseCurrentBlock();
923 } else {
924 $first_error = array_shift($errors_to_display);
925
926 foreach ($errors_to_display as $error) {
927 $tpl->setCurrentBlock('error_loop');
928 $tpl->setVariable('ERROR', $error);
929 $tpl->parseCurrentBlock();
930 }
931
932 $tpl->setCurrentBlock('multiple_errors');
933 $tpl->setVariable('FIRST_ERROR', $first_error);
934 $tpl->parseCurrentBlock();
935 }
936
937 ilUtil::sendInfo($tpl->get());
938 }
939 }
940}
sprintf('%.4f', $callTime)
$result
user()
Definition: user.php:4
$size
Definition: RandomTest.php:84
$files
Definition: add-vimline.php:18
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
$_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.
This class handles all operations on files (attachments) in directory ilias_data/mail.
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.
static getSignature()
Get preset signature.
static setContextParameters(array $parameters)
showSubmissionErrors(array $errors)
searchUsers($save=true)
__construct(\ilMailBodyPurifier $bodyPurifier=null)
decodeAttachmentFiles(array $files)
getTemplateDataById()
Called asynchronously when changing the template.
Class ilMailTemplateDataProvider.
Class ilMailTemplateSelectInputGUI.
Class ilManualPlaceholderInputGUI.
This class represents a property form user interface.
static strLen($a_string)
Definition: class.ilStr.php:78
special template class to simplify handling of ITX/PEAR
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 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
$error
Definition: Error.php:17
catch(Exception $e) $message
$errors
Definition: index.php:6
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
$template_id