ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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['DIC']->user()->getId() . '_' . urldecode($value)))
121 {
122 $decodedFiles[] = urldecode($value);
123 }
124 }
125
126 return $decodedFiles;
127 }
128
129 public function sendMessage()
130 {
131 $m_type = isset($_POST["m_type"]) ? $_POST["m_type"] : array("normal");
132
133 $message = strip_tags(ilUtil::stripSlashes($_POST['m_message'], false));
134 $message = str_replace("\r", '', $message);
135 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
136 $message = $this->umail->formatLinebreakMessage($message);
137
138 $files = $this->decodeAttachmentFiles(isset($_POST['attachments']) ? (array)$_POST['attachments'] : array());
139
140 $this->umail->setSaveInSentbox(true);
141 if($errors = $this->umail->sendMail(
145 ilUtil::securePlainString($_POST['m_subject']), $message,
146 $files,
147 $m_type,
148 (int)$_POST['use_placeholders']
149 )
150 )
151 {
152 $_POST['attachments'] = $files;
154 }
155 else
156 {
157 $this->umail->savePostData($GLOBALS['DIC']->user()->getId(), array(), "", "", "", "", "", "", "", "");
158
159 $this->ctrl->setParameterByClass('ilmailgui', 'type', 'message_sent');
160
162 {
163 ilUtil::sendInfo($this->lng->txt('mail_message_send'), true);
165 }
166 else
167 $this->ctrl->redirectByClass('ilmailgui');
168 }
169
170 $this->showForm();
171 }
172
173 public function saveDraft()
174 {
175 if(!$_POST['m_subject'])
176 {
177 $_POST['m_subject'] = 'No title';
178 }
179
180 $draftFolderId = $this->mbox->getDraftsFolder();
181 $files = $this->decodeAttachmentFiles(isset($_POST['attachments']) ? (array)$_POST['attachments'] : array());
182
183 if($errors = $this->umail->validateRecipients(
187 ))
188 {
189 $_POST['attachments'] = $files;
191 $this->showForm();
192 return;
193 }
194
195 if(isset($_SESSION["draft"]))
196 {
197 $draftId = (int)$_SESSION['draft'];
198 unset($_SESSION['draft']);
199 }
200 else
201 {
202 $draftId = $this->umail->getNewDraftId($GLOBALS['DIC']->user()->getId(), $draftFolderId);
203 }
204
205 $this->umail->updateDraft($draftFolderId, $files,
209 $_POST['m_type'],
211 ilUtil::securePlainString($_POST['m_subject']),
212 ilUtil::securePlainString($_POST['m_message']),
213 $draftId,
214 (int)$_POST['use_placeholders'],
217 );
218
219 ilUtil::sendInfo($this->lng->txt('mail_saved'), true);
220
223 else
224 $this->ctrl->redirectByClass("ilmailfoldergui");
225
226 $this->showForm();
227 }
228
229 public function searchUsers($save = true)
230 {
231 global $ilUser, $ilCtrl;
232
233 $this->tpl->setTitle($this->lng->txt("mail"));
234
235 if ($save)
236 {
237 // decode post values
238 $files = array();
239 if(is_array($_POST['attachments']))
240 {
241 foreach($_POST['attachments'] as $value)
242 {
243 $files[] = urldecode($value);
244 }
245 }
246
247 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
248 $this->umail->savePostData($ilUser->getId(),
249 $files,
253 $_POST["m_type"],
255 ilUtil::securePlainString($_POST["m_subject"]),
256 ilUtil::securePlainString($_POST["m_message"]),
257 ilUtil::securePlainString($_POST['use_placeholders']),
260 );
261 }
262 include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
263 $form = new ilPropertyFormGUI();
264 $form->setId('search_rcp');
265 $form->setTitle($this->lng->txt('search_recipients'));
266 $form->setFormAction($ilCtrl->getFormAction($this, 'search'));
267
268 $inp = new ilTextInputGUI($this->lng->txt("search_for"), 'search');
269 $inp->setSize(30);
270 $dsDataLink = $ilCtrl->getLinkTarget($this, 'lookupRecipientAsync', '', true, false);
271 $inp->setDataSource($dsDataLink);
272
273 if (strlen(trim($_SESSION["mail_search_search"])) > 0)
274 {
275 $inp->setValue(ilUtil::prepareFormOutput(trim($_SESSION["mail_search_search"]), true));
276 }
277 $form->addItem($inp);
278
279 $form->addCommandButton('search', $this->lng->txt("search"));
280 $form->addCommandButton('cancelSearch', $this->lng->txt("cancel"));
281
282 $this->tpl->setContent($form->getHtml());
283 $this->tpl->show();
284 }
285
289 public function searchCoursesTo()
290 {
291 $this->saveMailBeforeSearch();
292
293 if($_SESSION['search_crs'])
294 {
295 $this->ctrl->setParameterByClass('ilmailsearchcoursesgui', 'cmd', 'showMembers');
296 }
297
298 $this->ctrl->setParameterByClass('ilmailsearchcoursesgui', 'ref', 'mail');
299 $this->ctrl->redirectByClass('ilmailsearchcoursesgui');
300 }
301
305 public function searchGroupsTo()
306 {
307 $this->saveMailBeforeSearch();
308
309 $this->ctrl->setParameterByClass('ilmailsearchgroupsgui', 'ref', 'mail');
310 $this->ctrl->redirectByClass('ilmailsearchgroupsgui');
311 }
312
313 public function search()
314 {
315 $_SESSION["mail_search_search"] = $_POST["search"];
316 if(strlen(trim($_SESSION["mail_search_search"])) == 0)
317 {
318 ilUtil::sendInfo($this->lng->txt("mail_insert_query"));
319 $this->searchUsers(false);
320 }
321 else
322 {
323 if(strlen(trim($_SESSION["mail_search_search"])) < 3)
324 {
325 $this->lng->loadLanguageModule('search');
326 ilUtil::sendInfo($this->lng->txt('search_minimum_three'));
327 $this->searchUsers(false);
328 }
329 else
330 {
331 $this->ctrl->setParameterByClass("ilmailsearchgui", "search", urlencode($_SESSION["mail_search_search"]));
332 $this->ctrl->redirectByClass("ilmailsearchgui");
333 }
334 }
335 }
336
337 public function cancelSearch()
338 {
339 unset($_SESSION["mail_search"]);
340 $this->searchResults();
341 }
342
343 public function editAttachments()
344 {
345 // decode post values
346 $files = array();
347 if(is_array($_POST['attachments']))
348 {
349 foreach($_POST['attachments'] as $value)
350 {
351 $files[] = urldecode($value);
352 }
353 }
354
355 // Note: For security reasons, ILIAS only allows Plain text messages.
356 $this->umail->savePostData($GLOBALS['DIC']['ilUser']->getId(),
357 $files,
361 $_POST["m_type"],
363 ilUtil::securePlainString($_POST["m_subject"]),
364 ilUtil::securePlainString($_POST["m_message"]),
365 ilUtil::securePlainString($_POST['use_placeholders']),
368 );
369
370 $this->ctrl->redirectByClass("ilmailattachmentgui");
371 }
372
373 public function returnFromAttachments()
374 {
375 $_GET["type"] = "attach";
376 $this->showForm();
377 }
378
379 public function searchResults()
380 {
381 $_GET["type"] = "search_res";
382 $this->showForm();
383 }
384
385 public function mailUser()
386 {
387 $_GET["type"] = "new";
388 $this->showForm();
389 }
390
391 public function mailRole()
392 {
393 $_GET["type"] = "role";
394 $this->showForm();
395 }
396
397 public function replyMail()
398 {
399 $_GET["type"] = "reply";
400 $this->showForm();
401 }
402
403 public function mailAttachment()
404 {
405 $_GET["type"] = "attach";
406 $this->showForm();
407 }
408
412 protected function getTemplateDataById()
413 {
414 require_once 'Services/JSON/classes/class.ilJsonUtil.php';
415
416 if(!isset($_GET['template_id']))
417 {
418 exit();
419 }
420
421 try
422 {
423 require_once 'Services/Mail/classes/class.ilMailTemplateService.php';
424 require_once 'Services/Mail/classes/class.ilMailTemplateDataProvider.php';
425 $template_id = (int)$_GET['template_id'];
426 $template_provider = new ilMailTemplateDataProvider();
427 $template = $template_provider->getTemplateById($template_id);
428 $context = ilMailTemplateService::getTemplateContextById($template->getContext());
429 echo ilJsonUtil::encode(array(
430 'm_subject' => $template->getSubject(),
431 'm_message' => $template->getMessage()
432 ));
433 }
434 catch(Exception $e)
435 {
436 }
437 exit();
438 }
439
440 public function showForm()
441 {
445 global $rbacsystem, $ilUser, $ilCtrl, $lng, $ilTabs, $ilToolbar;
446
447 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_new.html", "Services/Mail");
448 $this->tpl->setTitle($this->lng->txt("mail"));
449
450 $this->lng->loadLanguageModule("crs");
451
453 $ilTabs->setBackTarget($lng->txt('back'), $ilCtrl->getLinkTarget($this, 'cancelMail'));
454
455 switch($_GET["type"])
456 {
457 case 'reply':
458 if($_SESSION['mail_id'])
459 {
460 $_GET['mail_id'] = $_SESSION['mail_id'];
461 }
462 $mailData = $this->umail->getMail($_GET["mail_id"]);
463 $mailData["m_subject"] = $this->umail->formatReplySubject();
464 $mailData["m_message"] = $this->umail->formatReplyMessage();
465 $mailData["m_message"] = $this->umail->prependSignature();
466 // NO ATTACHMENTS FOR REPLIES
467 $mailData["attachments"] = array();
468 //$mailData["rcp_cc"] = $this->umail->formatReplyRecipientsForCC();
469 $mailData["rcp_cc"] = '';
470 $mailData["rcp_to"] = $this->umail->formatReplyRecipient();
471 $_SESSION["mail_id"] = "";
472 break;
473
474 case 'search_res':
475 $mailData = $this->umail->getSavedData();
476
477 /*if($_SESSION["mail_search_results"])
478 {
479 $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results"],$_SESSION["mail_search"]);
480 }
481 unset($_SESSION["mail_search"]);
482 unset($_SESSION["mail_search_results"]);*/
483
484 if($_SESSION["mail_search_results_to"])
485 {
486 $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_to"], 'to');
487 }
488 if($_SESSION["mail_search_results_cc"])
489 {
490 $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_cc"], 'cc');
491 }
492 if($_SESSION["mail_search_results_bcc"])
493 {
494 $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_bcc"], 'bc');
495 }
496
497 unset($_SESSION["mail_search_results_to"]);
498 unset($_SESSION["mail_search_results_cc"]);
499 unset($_SESSION["mail_search_results_bcc"]);
500
501 break;
502
503 case 'attach':
504 $mailData = $this->umail->getSavedData();
505 break;
506
507 case 'draft':
508 $_SESSION["draft"] = $_GET["mail_id"];
509 $mailData = $this->umail->getMail($_GET["mail_id"]);
510 ilMailFormCall::setContextId($mailData['tpl_ctx_id']);
511 ilMailFormCall::setContextParameters($mailData['tpl_ctx_params']);
512 break;
513
514 case 'forward':
515 $mailData = $this->umail->getMail($_GET["mail_id"]);
516 $mailData["rcp_to"] = $mailData["rcp_cc"] = $mailData["rcp_bcc"] = '';
517 $mailData["m_subject"] = $this->umail->formatForwardSubject();
518 $mailData["m_message"] = $this->umail->prependSignature();
519 if(count($mailData["attachments"]))
520 {
521 if($error = $this->mfile->adoptAttachments($mailData["attachments"],$_GET["mail_id"]))
522 {
524 }
525 }
526 break;
527
528 case 'new':
529 if($_GET['rcp_to'])
530 {
531 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
532 $mailData["rcp_to"] = ilUtil::securePlainString($_GET['rcp_to']);
533 }
534 else if($_SESSION['rcp_to'])
535 {
536 $mailData["rcp_to"] = $_SESSION['rcp_to'];
537 }
538 if($_GET['rcp_cc'])
539 {
540 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
541 $mailData["rcp_cc"] = ilUtil::securePlainString($_GET['rcp_cc']);
542 }
543 else if($_SESSION['rcp_cc'])
544 {
545 $mailData["rcp_cc"] = $_SESSION['rcp_cc'];
546 }
547 if($_GET['rcp_bcc'])
548 {
549 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
550 $mailData["rcp_bcc"] = ilUtil::securePlainString($_GET['rcp_bcc']);
551 }
552 else if($_SESSION['rcp_bcc'])
553 {
554 $mailData["rcp_bcc"] = $_SESSION['rcp_bcc'];
555 }
556 $mailData['m_message'] = '';
557 if(strlen($sig = ilMailFormCall::getSignature()))
558 {
559 $mailData['m_message'] = $sig;
560 $mailData['m_message'] .= chr(13).chr(10).chr(13).chr(10);
561 }
562 $mailData['m_message'] .= $this->umail->appendSignature();
563
564 $_SESSION['rcp_to'] = '';
565 $_SESSION['rcp_cc'] = '';
566 $_SESSION['rcp_bcc'] = '';
567 break;
568
569 case 'role':
570
571 if(is_array($_POST['roles']))
572 {
573 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
574 $mailData['rcp_to'] = ilUtil::securePlainString(implode(',',$_POST['roles']));
575 }
576 elseif(is_array($_SESSION['mail_roles']))
577 {
578 $mailData['rcp_to'] = ilUtil::securePlainString(implode(',', $_SESSION['mail_roles']));
579 }
580
581 $mailData['m_message'] = '';
582 if(strlen($sig = ilMailFormCall::getSignature()))
583 {
584 $mailData['m_message'] = $sig;
585 $mailData['m_message'] .= chr(13).chr(10).chr(13).chr(10);
586 }
587
588 $mailData['m_message'] .= $_POST["additional_message_text"].chr(13).chr(10).$this->umail->appendSignature();
589 $_POST["additional_message_text"] = "";
590 $_SESSION['mail_roles'] = "";
591 break;
592
593 case 'address':
594 $mailData["rcp_to"] = urldecode($_GET["rcp"]);
595 break;
596
597 default:
598 // GET DATA FROM POST
599 $mailData = $_POST;
600
601 // strip slashes
602 foreach ($mailData as $key => $value)
603 {
604 if (is_string($value))
605 {
606 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
607 $mailData[$key] = ilUtil::securePlainString($value);
608 }
609 }
610 break;
611 }
612
613 include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
614
615 $form_gui = new ilPropertyFormGUI();
616 $form_gui->setTitle($this->lng->txt('compose'));
617 $form_gui->setId('mail_compose_form');
618 $form_gui->setName('mail_compose_form');
619 $form_gui->setFormAction($this->ctrl->getFormAction($this, 'sendMessage'));
620
621 $this->tpl->setVariable('FORM_ID', $form_gui->getId());
622
623 require_once 'Services/UIComponent/Button/classes/class.ilButton.php';
624 $btn = ilButton::getInstance();
625 $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT);
626 $btn->setForm('form_' . $form_gui->getName())
627 ->setName('searchUsers')
628 ->setCaption('search_recipients');
629 $ilToolbar->addStickyItem($btn);
630
631 $btn = ilButton::getInstance();
632 $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT)
633 ->setName('searchCoursesTo')
634 ->setForm('form_' . $form_gui->getName())
635 ->setCaption('mail_my_courses');
636 $ilToolbar->addButtonInstance($btn);
637
638 $btn = ilButton::getInstance();
639 $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT)
640 ->setName('searchGroupsTo')
641 ->setForm('form_' . $form_gui->getName())
642 ->setCaption('mail_my_groups');
643 $ilToolbar->addButtonInstance($btn);
644
645 $btn = ilButton::getInstance();
646 $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT)
647 ->setName('searchMailingListsTo')
648 ->setForm('form_' . $form_gui->getName())
649 ->setCaption('mail_my_mailing_lists');
650 $ilToolbar->addButtonInstance($btn);
651
652 $dsDataLink = $ilCtrl->getLinkTarget($this, 'lookupRecipientAsync', '', true);
653
654 // RECIPIENT
655 $inp = new ilTextInputGUI($this->lng->txt('mail_to'), 'rcp_to');
656 $inp->setRequired(true);
657 $inp->setSize(50);
658 $inp->setValue($mailData["rcp_to"]);
659 $inp->setDataSource($dsDataLink, ",");
660 $inp->setMaxLength(null);
661 $form_gui->addItem($inp);
662
663 // CC
664 $inp = new ilTextInputGUI($this->lng->txt('cc'), 'rcp_cc');
665 $inp->setSize(50);
666 $inp->setValue($mailData["rcp_cc"]);
667 $inp->setDataSource($dsDataLink, ",");
668 $inp->setMaxLength(null);
669 $form_gui->addItem($inp);
670
671 // BCC
672 $inp = new ilTextInputGUI($this->lng->txt('bc'), 'rcp_bcc');
673 $inp->setSize(50);
674 $inp->setValue($mailData["rcp_bcc"]);
675 $inp->setDataSource($dsDataLink, ",");
676 $inp->setMaxLength(null);
677 $form_gui->addItem($inp);
678
679 // SUBJECT
680 $inp = new ilTextInputGUI($this->lng->txt('subject'), 'm_subject');
681 $inp->setSize(50);
682 $inp->setRequired(true);
683 $inp->setValue($mailData["m_subject"]);
684 $form_gui->addItem($inp);
685
686 // Attachments
687 include_once 'Services/Mail/classes/class.ilMailFormAttachmentFormPropertyGUI.php';
688 $att = new ilMailFormAttachmentPropertyGUI($this->lng->txt( ($mailData["attachments"]) ? 'edit' : 'add' ));
689
690 if (is_array($mailData["attachments"]) && count($mailData["attachments"]))
691 {
692 foreach($mailData["attachments"] as $data)
693 {
694 if(is_file($this->mfile->getMailPath() . '/' . $ilUser->getId() . "_" . $data))
695 {
696 $hidden = new ilHiddenInputGUI('attachments[]');
697 $form_gui->addItem($hidden);
698 $size = filesize($this->mfile->getMailPath() . '/' . $ilUser->getId() . "_" . $data);
699 $label = $data . " [" . ilUtil::formatSize($size) . "]";
700 $att->addItem($label);
701 $hidden->setValue(urlencode($data));
702 }
703 }
704 }
705 $form_gui->addItem($att);
706
707 // ONLY IF SYSTEM MAILS ARE ALLOWED
708 if($rbacsystem->checkAccess("system_message",$this->umail->getMailObjectReferenceId()))
709 {
710 $chb = new ilCheckboxInputGUI($this->lng->txt('type'), 'm_type[]');
711 $chb->setOptionTitle($this->lng->txt('system_message'));
712 $chb->setValue('system');
713 $chb->setChecked(false);
714 if(is_array($mailData["m_type"]) and in_array('system',$mailData["m_type"]))
715 {
716 $chb->setChecked(true);
717 }
718 $form_gui->addItem($chb);
719 }
720
722 {
723 $context_id = ilMailFormCall::getContextId();
724
725 // Activate placeholders
726 $mailData['use_placeholders'] = true;
727
728 try {
729 require_once 'Services/Mail/classes/class.ilMailTemplateService.php';
730 $context = ilMailTemplateService::getTemplateContextById($context_id);
731
732 require_once 'Services/Mail/classes/class.ilMailTemplateDataProvider.php';
733 $template_provider = new ilMailTemplateDataProvider();
734 $templates = $template_provider->getTemplateByContexId($context->getId());
735
736 if(count($templates))
737 {
738 $options = array();
739 foreach($templates as $template)
740 {
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 }
757 catch(Exception $e)
758 {
759 require_once './Services/Logging/classes/public/class.ilLoggerFactory.php';
760 ilLoggerFactory::getLogger('mail')->error(sprintf('%s has been called with invalid context id: %s.', __METHOD__, $context_id));
761 }
762 }
763 else
764 {
765 require_once 'Services/Mail/classes/class.ilMailTemplateGenericContext.php';
766 $context = new ilMailTemplateGenericContext();
767 }
768
769 // MESSAGE
770 $inp = new ilTextAreaInputGUI($this->lng->txt('message_content'), 'm_message');
771 //$inp->setValue(htmlspecialchars($mailData["m_message"], false));
772 $inp->setValue($mailData["m_message"]);
773 $inp->setRequired(false);
774 $inp->setCols(60);
775 $inp->setRows(10);
776 $form_gui->addItem($inp);
777
778 // PLACEHOLDERS
779 $chb = new ilCheckboxInputGUI($this->lng->txt('mail_serial_letter_placeholders'), 'use_placeholders');
780 $chb->setOptionTitle($this->lng->txt('activate_serial_letter_placeholders'));
781 $chb->setValue(1);
782 if(isset($mailData['use_placeholders']) && $mailData['use_placeholders'])
783 {
784 $chb->setChecked(true);
785 }
786
787 require_once 'Services/Mail/classes/Form/class.ilManualPlaceholderInputGUI.php';
788 $placeholders = new ilManualPlaceholderInputGUI($this->ctrl->getLinkTarget($this, 'getAjaxPlaceholdersById', '', true, false));
789 foreach($context->getPlaceholders() as $key => $value)
790 {
791 $placeholders->addPlaceholder($value['placeholder'], $value['label'] );
792 }
793 $chb->addSubItem($placeholders);
794 $form_gui->addItem($chb);
795
796 $form_gui->addCommandButton('sendMessage', $this->lng->txt('send_mail'));
797 $form_gui->addCommandButton('saveDraft', $this->lng->txt('save_message'));
799 $form_gui->addCommandButton('cancelMail', $this->lng->txt('cancel'));
800
801 $this->tpl->parseCurrentBlock();
802
803 $this->tpl->setVariable('FORM', $form_gui->getHTML());
804
805 $this->tpl->addJavaScript('Services/Mail/js/ilMailComposeFunctions.js');
806 $this->tpl->show();
807 }
808
809 public function lookupRecipientAsync()
810 {
811 include_once 'Services/JSON/classes/class.ilJsonUtil.php';
812 include_once 'Services/Mail/classes/class.ilMailForm.php';
813 $search = '';
814 if (isset($_GET["term"]) && is_string($_GET["term"])) {
815 $search = $_GET["term"];
816 }
817 if (isset($_POST["term"]) && is_string($_POST["term"])) {
818 $search = $_POST["term"];
819 }
820
821 $search = trim($search);
822
823 $result = array();
824
825 require_once 'Services/Utilities/classes/class.ilStr.php';
826 if (\ilStr::strLen($search) < 3) {
827 echo json_encode($result);
828 exit;
829 }
830
831 // #14768
832 $quoted = ilUtil::stripSlashes($search);
833 $quoted = str_replace('%', '\%', $quoted);
834 $quoted = str_replace('_', '\_', $quoted);
835
836 $mailFormObj = new ilMailForm;
837 $result = $mailFormObj->getRecipientAsync("%" . $quoted . "%", ilUtil::stripSlashes($search));
838
839 echo json_encode($result);
840 exit;
841 }
842
843 public function cancelMail()
844 {
847 else
848 return $this->showForm();
849 }
850
854 protected function saveMailBeforeSearch()
855 {
859 global $ilUser;
860
861 // decode post values
862 $files = array();
863 if(is_array($_POST['attachments']))
864 {
865 foreach($_POST['attachments'] as $value)
866 {
867 $files[] = urldecode($value);
868 }
869 }
870
871 $this->umail->savePostData($ilUser->getId(),
872 $files,
876 $_POST['m_type'],
878 ilUtil::securePlainString($_POST['m_subject']),
879 ilUtil::securePlainString($_POST['m_message']),
880 ilUtil::securePlainString($_POST['use_placeholders']),
883 );
884 }
885
889 public function searchMailingListsTo()
890 {
891 $this->saveMailBeforeSearch();
892
893 $this->ctrl->setParameterByClass('ilmailinglistsgui', 'ref', 'mail');
894 $this->ctrl->redirectByClass('ilmailinglistsgui');
895 }
896
897 public function getAjaxPlaceholdersById()
898 {
899 $context_id = ilUtil::stripSlashes($_GET['context_id']);
900 require_once 'Services/Mail/classes/class.ilMailTemplateService.php';
901 require_once 'Services/Mail/classes/Form/class.ilManualPlaceholderInputGUI.php';
902 $placeholders = new ilManualPlaceholderInputGUI($this->ctrl->getLinkTarget($this, 'getAjaxPlaceholdersById', '', true, false));
903 $context = ilMailTemplateService::getTemplateContextById($context_id);
904 foreach($context->getPlaceholders() as $key => $value)
905 {
906 $placeholders->addPlaceholder($value['placeholder'], $value['label'] );
907 }
908 $placeholders->render(true);
909 exit();
910 }
911
915 protected function showSubmissionErrors(array $errors)
916 {
917 $errors_to_display = array();
918
919 foreach($errors as $error)
920 {
921 $error = array_values($error);
922 $first_error = array_shift($error);
923
924 $translation = $this->lng->txt($first_error);
925 if($translation == '-' . $first_error . '-')
926 {
927 $translation = $first_error;
928 }
929
930 if(count($error) == 0 || $translation == $first_error)
931 {
932 $errors_to_display[] = $translation;
933 }
934 else
935 {
936 // We expect all other parts of this error array are recipient addresses = input parameters
937 $error = array_map(function($address) {
938 return ilUtil::prepareFormOutput($address);
939 }, $error);
940
941 array_unshift($error, $translation);
942 $errors_to_display[] = call_user_func_array('sprintf', $error);
943 }
944 }
945
946 if(count($errors_to_display) > 0)
947 {
948 $tpl = new ilTemplate('tpl.mail_new_submission_errors.html', true, true, 'Services/Mail');
949 if(count($errors_to_display) == 1)
950 {
951 $tpl->setCurrentBlock('single_error');
952 $tpl->setVariable('SINGLE_ERROR', current($errors_to_display));
953 $tpl->parseCurrentBlock();
954 }
955 else
956 {
957 $first_error = array_shift($errors_to_display);
958
959 foreach($errors_to_display as $error)
960 {
961 $tpl->setCurrentBlock('error_loop');
962 $tpl->setVariable('ERROR', $error);
963 $tpl->parseCurrentBlock();
964 }
965
966 $tpl->setCurrentBlock('multiple_errors');
967 $tpl->setVariable('FIRST_ERROR', $first_error);
968 $tpl->parseCurrentBlock();
969 }
970
971 ilUtil::sendInfo($tpl->get());
972 }
973 }
974}
sprintf('%.4f', $callTime)
$result
user()
Definition: user.php:4
$error
Definition: Error.php:17
$size
Definition: RandomTest.php:79
$files
Definition: add-vimline.php:18
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
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 encode($mixed, $suppress_native=false)
static getLogger($a_component_id)
Get component logger.
static getSignature()
Get preset signature.
static setContextParameters(array $parameters)
showSubmissionErrors(array $errors)
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.
static strLen($a_string)
Definition: class.ilStr.php:91
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)
http redirect to other 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_id
Definition: example_062.php:89
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $ilCtrl
Definition: ilias.php:18
$cmd
Definition: sahs_server.php:35
$errors
if(!is_array($argv)) $options
$ilUser
Definition: imgupload.php:18