4 require_once
'Services/User/classes/class.ilObjUser.php';
5 require_once
'Services/Mail/classes/class.ilMailbox.php';
6 require_once
'Services/Mail/classes/class.ilFormatMail.php';
7 require_once
'./Services/Mail/classes/class.ilFileDataMail.php';
8 require_once
'Services/Mail/classes/class.ilMailFormCall.php';
37 $this->mbox =
new ilMailBox($ilUser->getId());
41 $_GET[
'mobj_id'] = $_POST[
'mobj_id'];
44 if(!(
int)
$_GET[
'mobj_id'])
46 $_GET[
'mobj_id'] = $this->mbox->getInboxFolder();
49 $this->ctrl->saveParameter($this,
'mobj_id');
54 $forward_class = $this->ctrl->getNextClass($this);
55 switch($forward_class)
57 case 'ilmailfoldergui':
58 include_once
'Services/Mail/classes/class.ilMailFolderGUI.php';
63 case 'ilmailattachmentgui':
64 include_once
'Services/Mail/classes/class.ilMailAttachmentGUI.php';
66 $this->ctrl->setReturn($this,
"returnFromAttachments");
70 case 'ilmailsearchgui':
71 include_once
'Services/Contact/classes/class.ilMailSearchGUI.php';
73 $this->ctrl->setReturn($this,
"searchResults");
77 case 'ilmailsearchcoursesgui':
78 include_once
'Services/Contact/classes/class.ilMailSearchCoursesGUI.php';
80 $this->ctrl->setReturn($this,
"searchResults");
84 case 'ilmailinglistsgui':
85 include_once
'Services/Contact/classes/class.ilMailingListsGUI.php';
87 $this->ctrl->setReturn($this,
'searchResults');
91 case 'ilmailsearchgroupsgui':
92 include_once
'Services/Contact/classes/class.ilMailSearchGroupsGUI.php';
94 $this->ctrl->setReturn($this,
"searchResults");
99 if (!(
$cmd = $this->ctrl->getCmd()))
116 $decodedFiles =
array();
118 foreach($files as $value)
120 if(is_file($this->mfile->getMailPath() .
'/' .
$GLOBALS[
'DIC']->user()->getId() .
'_' . urldecode($value)))
122 $decodedFiles[] = urldecode($value);
126 return $decodedFiles;
134 $message = str_replace(
"\r",
'', $message);
136 $message = $this->umail->formatLinebreakMessage($message);
140 $this->umail->setSaveInSentbox(
true);
141 if(
$errors = $this->umail->sendMail(
148 (
int)
$_POST[
'use_placeholders']
152 $_POST[
'attachments'] =
$files;
157 $this->umail->savePostData(
$GLOBALS[
'DIC']->
user()->getId(),
array(),
"",
"",
"",
"",
"",
"",
"",
"");
159 $this->ctrl->setParameterByClass(
'ilmailgui',
'type',
'message_sent');
167 $this->ctrl->redirectByClass(
'ilmailgui');
177 $_POST[
'm_subject'] =
'No title';
180 $draftFolderId = $this->mbox->getDraftsFolder();
183 if(
$errors = $this->umail->validateRecipients(
202 $draftId = $this->umail->getNewDraftId(
$GLOBALS[
'DIC']->
user()->getId(), $draftFolderId);
205 $this->umail->updateDraft($draftFolderId,
$files,
214 (
int)
$_POST[
'use_placeholders'],
224 $this->ctrl->redirectByClass(
"ilmailfoldergui");
233 $this->tpl->setTitle($this->lng->txt(
"mail"));
239 if(is_array(
$_POST[
'attachments']))
241 foreach(
$_POST[
'attachments'] as $value)
243 $files[] = urldecode($value);
248 $this->umail->savePostData($ilUser->getId(),
262 include_once
'Services/Form/classes/class.ilPropertyFormGUI.php';
264 $form->setId(
'search_rcp');
265 $form->setTitle($this->lng->txt(
'search_recipients'));
266 $form->setFormAction($ilCtrl->getFormAction($this,
'search'));
268 $inp =
new ilTextInputGUI($this->lng->txt(
"search_for"),
'search');
270 $dsDataLink = $ilCtrl->getLinkTarget($this,
'lookupRecipientAsync',
'',
true,
false);
271 $inp->setDataSource($dsDataLink);
273 if (strlen(trim(
$_SESSION[
"mail_search_search"])) > 0)
277 $form->addItem($inp);
279 $form->addCommandButton(
'search', $this->lng->txt(
"search"));
280 $form->addCommandButton(
'cancelSearch', $this->lng->txt(
"cancel"));
282 $this->tpl->setContent($form->getHtml());
291 $this->saveMailBeforeSearch();
295 $this->ctrl->setParameterByClass(
'ilmailsearchcoursesgui',
'cmd',
'showMembers');
298 $this->ctrl->setParameterByClass(
'ilmailsearchcoursesgui',
'ref',
'mail');
299 $this->ctrl->redirectByClass(
'ilmailsearchcoursesgui');
307 $this->saveMailBeforeSearch();
309 $this->ctrl->setParameterByClass(
'ilmailsearchgroupsgui',
'ref',
'mail');
310 $this->ctrl->redirectByClass(
'ilmailsearchgroupsgui');
316 if(strlen(trim(
$_SESSION[
"mail_search_search"])) == 0)
323 if(strlen(trim(
$_SESSION[
"mail_search_search"])) < 3)
325 $this->lng->loadLanguageModule(
'search');
331 $this->ctrl->setParameterByClass(
"ilmailsearchgui",
"search", urlencode(
$_SESSION[
"mail_search_search"]));
332 $this->ctrl->redirectByClass(
"ilmailsearchgui");
347 if(is_array(
$_POST[
'attachments']))
349 foreach(
$_POST[
'attachments'] as $value)
351 $files[] = urldecode($value);
356 $this->umail->savePostData(
$GLOBALS[
'DIC'][
'ilUser']->getId(),
370 $this->ctrl->redirectByClass(
"ilmailattachmentgui");
375 $_GET[
"type"] =
"attach";
381 $_GET[
"type"] =
"search_res";
387 $_GET[
"type"] =
"new";
393 $_GET[
"type"] =
"role";
399 $_GET[
"type"] =
"reply";
405 $_GET[
"type"] =
"attach";
414 require_once
'Services/JSON/classes/class.ilJsonUtil.php';
416 if(!isset(
$_GET[
'template_id']))
423 require_once
'Services/Mail/classes/class.ilMailTemplateService.php';
424 require_once
'Services/Mail/classes/class.ilMailTemplateDataProvider.php';
427 $template = $template_provider->getTemplateById(
$template_id);
430 'm_subject' => $template->getSubject(),
431 'm_message' => $template->getMessage()
440 public function showForm()
447 $this->tpl->addBlockFile(
"ADM_CONTENT",
"adm_content",
"tpl.mail_new.html",
"Services/Mail");
448 $this->tpl->setTitle($this->lng->txt(
"mail"));
450 $this->lng->loadLanguageModule(
"crs");
453 $ilTabs->setBackTarget($lng->txt(
'back'), $ilCtrl->getLinkTarget($this,
'cancelMail'));
455 switch(
$_GET[
"type"])
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();
467 $mailData[
"attachments"] =
array();
469 $mailData[
"rcp_cc"] =
'';
470 $mailData[
"rcp_to"] = $this->umail->formatReplyRecipient();
475 $mailData = $this->umail->getSavedData();
486 $mailData = $this->umail->appendSearchResult(
$_SESSION[
"mail_search_results_to"],
'to');
490 $mailData = $this->umail->appendSearchResult(
$_SESSION[
"mail_search_results_cc"],
'cc');
494 $mailData = $this->umail->appendSearchResult(
$_SESSION[
"mail_search_results_bcc"],
'bc');
497 unset(
$_SESSION[
"mail_search_results_to"]);
498 unset(
$_SESSION[
"mail_search_results_cc"]);
499 unset(
$_SESSION[
"mail_search_results_bcc"]);
504 $mailData = $this->umail->getSavedData();
509 $mailData = $this->umail->getMail(
$_GET[
"mail_id"]);
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"]))
521 if(
$error = $this->mfile->adoptAttachments($mailData[
"attachments"],
$_GET[
"mail_id"]))
536 $mailData[
"rcp_to"] =
$_SESSION[
'rcp_to'];
545 $mailData[
"rcp_cc"] =
$_SESSION[
'rcp_cc'];
554 $mailData[
"rcp_bcc"] =
$_SESSION[
'rcp_bcc'];
556 $mailData[
'm_message'] =
'';
559 $mailData[
'm_message'] = $sig;
560 $mailData[
'm_message'] .= chr(13).chr(10).chr(13).chr(10);
562 $mailData[
'm_message'] .= $this->umail->appendSignature();
571 if(is_array(
$_POST[
'roles']))
576 elseif(is_array(
$_SESSION[
'mail_roles']))
581 $mailData[
'm_message'] =
'';
584 $mailData[
'm_message'] = $sig;
585 $mailData[
'm_message'] .= chr(13).chr(10).chr(13).chr(10);
588 $mailData[
'm_message'] .=
$_POST[
"additional_message_text"].chr(13).chr(10).$this->umail->appendSignature();
589 $_POST[
"additional_message_text"] =
"";
594 $mailData[
"rcp_to"] = urldecode(
$_GET[
"rcp"]);
602 foreach ($mailData as $key => $value)
604 if (is_string($value))
613 include_once(
'./Services/Form/classes/class.ilPropertyFormGUI.php');
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'));
621 $this->tpl->setVariable(
'FORM_ID', $form_gui->getId());
623 require_once
'Services/UIComponent/Button/classes/class.ilButton.php';
626 $btn->setForm(
'form_' . $form_gui->getName())
627 ->setName(
'searchUsers')
628 ->setCaption(
'search_recipients');
629 $ilToolbar->addStickyItem($btn);
633 ->setName(
'searchCoursesTo')
634 ->setForm(
'form_' . $form_gui->getName())
635 ->setCaption(
'mail_my_courses');
636 $ilToolbar->addButtonInstance($btn);
640 ->setName(
'searchGroupsTo')
641 ->setForm(
'form_' . $form_gui->getName())
642 ->setCaption(
'mail_my_groups');
643 $ilToolbar->addButtonInstance($btn);
647 ->setName(
'searchMailingListsTo')
648 ->setForm(
'form_' . $form_gui->getName())
649 ->setCaption(
'mail_my_mailing_lists');
650 $ilToolbar->addButtonInstance($btn);
652 $dsDataLink = $ilCtrl->getLinkTarget($this,
'lookupRecipientAsync',
'',
true);
658 $inp->setValue($mailData[
"rcp_to"]);
659 $inp->setDataSource($dsDataLink,
",");
660 $inp->setMaxLength(null);
661 $form_gui->addItem($inp);
666 $inp->setValue($mailData[
"rcp_cc"]);
667 $inp->setDataSource($dsDataLink,
",");
668 $inp->setMaxLength(null);
669 $form_gui->addItem($inp);
674 $inp->setValue($mailData[
"rcp_bcc"]);
675 $inp->setDataSource($dsDataLink,
",");
676 $inp->setMaxLength(null);
677 $form_gui->addItem($inp);
680 $inp =
new ilTextInputGUI($this->lng->txt(
'subject'),
'm_subject');
682 $inp->setRequired(
true);
683 $inp->setValue($mailData[
"m_subject"]);
684 $form_gui->addItem($inp);
687 include_once
'Services/Mail/classes/class.ilMailFormAttachmentFormPropertyGUI.php';
690 if (is_array($mailData[
"attachments"]) && count($mailData[
"attachments"]))
692 foreach($mailData[
"attachments"] as
$data)
694 if(is_file($this->mfile->getMailPath() .
'/' . $ilUser->getId() .
"_" .
$data))
697 $form_gui->addItem($hidden);
698 $size = filesize($this->mfile->getMailPath() .
'/' . $ilUser->getId() .
"_" .
$data);
700 $att->addItem($label);
701 $hidden->setValue(urlencode($data));
705 $form_gui->addItem($att);
708 if($rbacsystem->checkAccess(
"system_message",$this->umail->getMailObjectReferenceId()))
712 $chb->setValue(
'system');
713 $chb->setChecked(
false);
714 if(is_array($mailData[
"m_type"])
and in_array(
'system',$mailData[
"m_type"]))
716 $chb->setChecked(
true);
718 $form_gui->addItem($chb);
726 $mailData[
'use_placeholders'] =
true;
729 require_once
'Services/Mail/classes/class.ilMailTemplateService.php';
732 require_once
'Services/Mail/classes/class.ilMailTemplateDataProvider.php';
734 $templates = $template_provider->getTemplateByContexId($context->getId());
736 if(count($templates))
739 foreach($templates as $template)
741 $options[$template->getTplId()] = $template->getTitle();
745 require_once
'Services/Mail/classes/Form/class.ilMailTemplateSelectInputGUI.php';
747 $this->lng->txt(
'mail_template_client'),
749 $this->ctrl->getLinkTarget($this,
'getTemplateDataById',
'',
true,
false),
750 array(
'm_subject',
'm_message')
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);
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));
765 require_once
'Services/Mail/classes/class.ilMailTemplateGenericContext.php';
772 $inp->
setValue($mailData[
"m_message"]);
773 $inp->setRequired(
false);
776 $form_gui->addItem($inp);
779 $chb =
new ilCheckboxInputGUI($this->lng->txt(
'mail_serial_letter_placeholders'),
'use_placeholders');
780 $chb->
setOptionTitle($this->lng->txt(
'activate_serial_letter_placeholders'));
782 if(isset($mailData[
'use_placeholders']) && $mailData[
'use_placeholders'])
784 $chb->setChecked(
true);
787 require_once
'Services/Mail/classes/Form/class.ilManualPlaceholderInputGUI.php';
789 foreach($context->getPlaceholders() as $key => $value)
791 $placeholders->
addPlaceholder($value[
'placeholder'], $value[
'label'] );
793 $chb->addSubItem($placeholders);
794 $form_gui->addItem($chb);
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'));
801 $this->tpl->parseCurrentBlock();
803 $this->tpl->setVariable(
'FORM', $form_gui->getHTML());
805 $this->tpl->addJavaScript(
'Services/Mail/js/ilMailComposeFunctions.js');
811 include_once
'Services/JSON/classes/class.ilJsonUtil.php';
812 include_once
'Services/Mail/classes/class.ilMailForm.php';
814 if (isset(
$_GET[
"term"]) && is_string(
$_GET[
"term"])) {
815 $search =
$_GET[
"term"];
817 if (isset(
$_POST[
"term"]) && is_string(
$_POST[
"term"])) {
821 $search = trim($search);
825 require_once
'Services/Utilities/classes/class.ilStr.php';
833 $quoted = str_replace(
'%',
'\%', $quoted);
834 $quoted = str_replace(
'_',
'\_', $quoted);
848 return $this->showForm();
854 protected function saveMailBeforeSearch()
863 if(is_array(
$_POST[
'attachments']))
865 foreach(
$_POST[
'attachments'] as $value)
867 $files[] = urldecode($value);
871 $this->umail->savePostData($ilUser->getId(),
891 $this->saveMailBeforeSearch();
893 $this->ctrl->setParameterByClass(
'ilmailinglistsgui',
'ref',
'mail');
894 $this->ctrl->redirectByClass(
'ilmailinglistsgui');
900 require_once
'Services/Mail/classes/class.ilMailTemplateService.php';
901 require_once
'Services/Mail/classes/Form/class.ilManualPlaceholderInputGUI.php';
904 foreach($context->getPlaceholders() as $key => $value)
906 $placeholders->addPlaceholder($value[
'placeholder'], $value[
'label'] );
908 $placeholders->render(
true);
917 $errors_to_display =
array();
919 foreach($errors as
$error)
921 $error = array_values($error);
922 $first_error = array_shift($error);
924 $translation = $this->lng->txt($first_error);
925 if($translation ==
'-' . $first_error .
'-')
927 $translation = $first_error;
930 if(count($error) == 0 || $translation == $first_error)
932 $errors_to_display[] = $translation;
937 $error = array_map(
function($address) {
941 array_unshift($error, $translation);
942 $errors_to_display[] = call_user_func_array(
'sprintf', $error);
946 if(count($errors_to_display) > 0)
948 $tpl =
new ilTemplate(
'tpl.mail_new_submission_errors.html',
true,
true,
'Services/Mail');
949 if(count($errors_to_display) == 1)
951 $tpl->setCurrentBlock(
'single_error');
952 $tpl->setVariable(
'SINGLE_ERROR', current($errors_to_display));
953 $tpl->parseCurrentBlock();
957 $first_error = array_shift($errors_to_display);
959 foreach($errors_to_display as $error)
961 $tpl->setCurrentBlock(
'error_loop');
962 $tpl->setVariable(
'ERROR', $error);
963 $tpl->parseCurrentBlock();
966 $tpl->setCurrentBlock(
'multiple_errors');
967 $tpl->setVariable(
'FIRST_ERROR', $first_error);
968 $tpl->parseCurrentBlock();
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
static securePlainString($a_str)
Remove unsecure characters from a plain text string.
This class handles all operations on files (attachments) in directory ilias_data/mail.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
setValue($a_value)
Set Value.
Class ilMailTemplateDataProvider.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static encode($mixed, $suppress_native=false)
if(!is_array($argv)) $options
special template class to simplify handling of ITX/PEAR
setSize($a_size)
Set Size.
This class represents a text property in a property form.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
Create styles array
The data for the language used.
This class represents a text area property in a property form.
static getLogger($a_component_id)
Get component logger.
static formatSize($size, $a_mode='short', $a_lng=null)
Returns the specified file size value in a human friendly form.
static redirect($a_script)
http redirect to other script
static getTemplateContextById($a_id)