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';
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();
91 $this->mbox =
new ilMailBox($this->
user->getId());
93 if (null === $bodyPurifier) {
96 $this->purifier = $bodyPurifier;
98 if (isset(
$_POST[
'mobj_id']) && (
int)
$_POST[
'mobj_id']) {
99 $_GET[
'mobj_id'] = $_POST[
'mobj_id'];
102 if (!(
int)
$_GET[
'mobj_id']) {
103 $_GET[
'mobj_id'] = $this->mbox->getInboxFolder();
105 $_GET[
'mobj_id'] = (int) $_GET[
'mobj_id'];
107 $this->ctrl->saveParameter($this,
'mobj_id');
112 $forward_class = $this->ctrl->getNextClass($this);
113 switch ($forward_class) {
114 case 'ilmailfoldergui':
115 include_once
'Services/Mail/classes/class.ilMailFolderGUI.php';
120 case 'ilmailattachmentgui':
121 include_once
'Services/Mail/classes/class.ilMailAttachmentGUI.php';
123 $this->ctrl->setReturn($this,
"returnFromAttachments");
127 case 'ilmailsearchgui':
128 include_once
'Services/Contact/classes/class.ilMailSearchGUI.php';
130 $this->ctrl->setReturn($this,
"searchResults");
134 case 'ilmailsearchcoursesgui':
135 include_once
'Services/Contact/classes/class.ilMailSearchCoursesGUI.php';
137 $this->ctrl->setReturn($this,
"searchResults");
141 case 'ilmailinglistsgui':
142 include_once
'Services/Contact/classes/class.ilMailingListsGUI.php';
144 $this->ctrl->setReturn($this,
'searchResults');
148 case 'ilmailsearchgroupsgui':
149 include_once
'Services/Contact/classes/class.ilMailSearchGroupsGUI.php';
151 $this->ctrl->setReturn($this,
"searchResults");
156 if (!($cmd = $this->ctrl->getCmd())) {
172 $decodedFiles =
array();
174 foreach ($files as $value) {
175 if (is_file($this->mfile->getMailPath() .
'/' . $this->
user->getId() .
'_' . urldecode($value))) {
176 $decodedFiles[] = urldecode($value);
180 return $decodedFiles;
190 $sanitizedMessage = $mailBody->getContent();
194 $this->umail->setSaveInSentbox(
true);
195 if (
$errors = $this->umail->sendMail(
203 (
int)
$_POST[
'use_placeholders']
206 $_POST[
'attachments'] =
$files;
209 $this->umail->savePostData($this->
user->getId(),
array(),
"",
"",
"",
"",
"",
"",
"",
"");
211 $this->ctrl->setParameterByClass(
'ilmailgui',
'type',
'message_sent');
217 $this->ctrl->redirectByClass(
'ilmailgui');
226 if (!
$_POST[
'm_subject']) {
227 $_POST[
'm_subject'] =
'No title';
230 $draftFolderId = $this->mbox->getDraftsFolder();
233 if (
$errors = $this->umail->validateRecipients(
248 $draftId = $this->umail->getNewDraftId($this->
user->getId(), $draftFolderId);
251 $this->umail->updateDraft(
262 (
int)
$_POST[
'use_placeholders'],
272 $this->ctrl->redirectByClass([
'ilmailgui',
'ilmailfoldergui']);
280 $this->tpl->setTitle($this->lng->txt(
"mail"));
285 if (is_array(
$_POST[
'attachments'])) {
286 foreach (
$_POST[
'attachments'] as $value) {
287 $files[] = urldecode($value);
292 $this->umail->savePostData(
293 $this->
user->getId(),
307 include_once
'Services/Form/classes/class.ilPropertyFormGUI.php';
309 $form->setId(
'search_rcp');
310 $form->setTitle($this->lng->txt(
'search_recipients'));
311 $form->setFormAction($this->ctrl->getFormAction($this,
'search'));
313 $inp =
new ilTextInputGUI($this->lng->txt(
"search_for"),
'search');
315 $dsDataLink = $this->ctrl->getLinkTarget($this,
'lookupRecipientAsync',
'',
true,
false);
316 $inp->setDataSource($dsDataLink);
318 if (strlen(trim(
$_SESSION[
"mail_search_search"])) > 0) {
321 $form->addItem($inp);
323 $form->addCommandButton(
'search', $this->lng->txt(
"search"));
324 $form->addCommandButton(
'cancelSearch', $this->lng->txt(
"cancel"));
326 $this->tpl->setContent(
$form->getHtml());
338 $this->ctrl->setParameterByClass(
'ilmailsearchcoursesgui',
'cmd',
'showMembers');
341 $this->ctrl->setParameterByClass(
'ilmailsearchcoursesgui',
'ref',
'mail');
342 $this->ctrl->redirectByClass(
'ilmailsearchcoursesgui');
352 $this->ctrl->setParameterByClass(
'ilmailsearchgroupsgui',
'ref',
'mail');
353 $this->ctrl->redirectByClass(
'ilmailsearchgroupsgui');
359 if (strlen(trim(
$_SESSION[
"mail_search_search"])) == 0) {
363 if (strlen(trim(
$_SESSION[
"mail_search_search"])) < 3) {
364 $this->lng->loadLanguageModule(
'search');
368 $this->ctrl->setParameterByClass(
"ilmailsearchgui",
"search", urlencode(
$_SESSION[
"mail_search_search"]));
369 $this->ctrl->redirectByClass(
"ilmailsearchgui");
384 if (is_array(
$_POST[
'attachments'])) {
385 foreach (
$_POST[
'attachments'] as $value) {
386 $files[] = urldecode($value);
391 $this->umail->savePostData(
392 $this->
user->getId(),
406 $this->ctrl->redirectByClass(
"ilmailattachmentgui");
411 $_GET[
"type"] =
"attach";
417 $_GET[
"type"] =
"search_res";
423 $_GET[
"type"] =
"new";
429 $_GET[
"type"] =
"role";
435 $_GET[
"type"] =
"reply";
441 $_GET[
"type"] =
"attach";
450 require_once
'Services/JSON/classes/class.ilJsonUtil.php';
452 if (!isset(
$_GET[
'template_id'])) {
457 require_once
'Services/Mail/classes/class.ilMailTemplateService.php';
458 require_once
'Services/Mail/classes/class.ilMailTemplateDataProvider.php';
463 echo json_encode(
array(
474 $this->tpl->addBlockFile(
"ADM_CONTENT",
"adm_content",
"tpl.mail_new.html",
"Services/Mail");
475 $this->tpl->setTitle($this->lng->txt(
"mail"));
477 $this->lng->loadLanguageModule(
"crs");
480 $this->tabs->setBackTarget($this->lng->txt(
'back'), $this->ctrl->getLinkTarget($this,
'cancelMail'));
483 switch (
$_GET[
"type"]) {
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();
493 $mailData[
"attachments"] =
array();
495 $mailData[
"rcp_cc"] =
'';
496 $mailData[
"rcp_to"] = $this->umail->formatReplyRecipient();
501 $mailData = $this->umail->getSavedData();
510 if (
$_SESSION[
"mail_search_results_to"]) {
511 $mailData = $this->umail->appendSearchResult(
$_SESSION[
"mail_search_results_to"],
'to');
513 if (
$_SESSION[
"mail_search_results_cc"]) {
514 $mailData = $this->umail->appendSearchResult(
$_SESSION[
"mail_search_results_cc"],
'cc');
516 if (
$_SESSION[
"mail_search_results_bcc"]) {
517 $mailData = $this->umail->appendSearchResult(
$_SESSION[
"mail_search_results_bcc"],
'bc');
520 unset(
$_SESSION[
"mail_search_results_to"]);
521 unset(
$_SESSION[
"mail_search_results_cc"]);
522 unset(
$_SESSION[
"mail_search_results_bcc"]);
527 $mailData = $this->umail->getSavedData();
532 $mailData = $this->umail->getMail(
$_GET[
"mail_id"]);
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"])) {
550 if (
$_GET[
'rcp_to']) {
554 $mailData[
"rcp_to"] =
$_SESSION[
'rcp_to'];
556 if (
$_GET[
'rcp_cc']) {
560 $mailData[
"rcp_cc"] =
$_SESSION[
'rcp_cc'];
562 if (
$_GET[
'rcp_bcc']) {
566 $mailData[
"rcp_bcc"] =
$_SESSION[
'rcp_bcc'];
568 $mailData[
'm_message'] =
'';
570 $mailData[
'm_message'] = $sig;
571 $mailData[
'm_message'] .= chr(13) . chr(10) . chr(13) . chr(10);
573 $mailData[
'm_message'] .= $this->umail->appendSignature();
582 if (is_array(
$_POST[
'roles'])) {
585 } elseif (is_array(
$_SESSION[
'mail_roles'])) {
589 $mailData[
'm_message'] =
'';
591 $mailData[
'm_message'] = $sig;
592 $mailData[
'm_message'] .= chr(13) . chr(10) . chr(13) . chr(10);
595 $mailData[
'm_message'] .=
$_POST[
"additional_message_text"] . chr(13) . chr(10) . $this->umail->appendSignature();
596 $_POST[
"additional_message_text"] =
"";
601 $mailData[
"rcp_to"] = urldecode(
$_GET[
"rcp"]);
609 foreach ($mailData as
$key => $value) {
610 if (is_string($value)) {
618 include_once(
'./Services/Form/classes/class.ilPropertyFormGUI.php');
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'));
626 $this->tpl->setVariable(
'FORM_ID', $form_gui->getId());
628 require_once
'Services/UIComponent/Button/classes/class.ilButton.php';
631 $btn->setForm(
'form_' . $form_gui->getName())
632 ->setName(
'searchUsers')
633 ->setCaption(
'search_recipients');
634 $this->toolbar->addStickyItem($btn);
638 ->setName(
'searchCoursesTo')
639 ->setForm(
'form_' . $form_gui->getName())
640 ->setCaption(
'mail_my_courses');
641 $this->toolbar->addButtonInstance($btn);
645 ->setName(
'searchGroupsTo')
646 ->setForm(
'form_' . $form_gui->getName())
647 ->setCaption(
'mail_my_groups');
648 $this->toolbar->addButtonInstance($btn);
650 require_once
'Services/Contact/BuddySystem/classes/class.ilBuddySystem.php';
654 ->setName(
'searchMailingListsTo')
655 ->setForm(
'form_' . $form_gui->getName())
656 ->setCaption(
'mail_my_mailing_lists');
657 $this->toolbar->addButtonInstance($btn);
660 $dsDataLink = $this->ctrl->getLinkTarget($this,
'lookupRecipientAsync',
'',
true);
666 $inp->setValue($mailData[
"rcp_to"]);
667 $inp->setDataSource($dsDataLink,
",");
668 $inp->setMaxLength(null);
669 $form_gui->addItem($inp);
674 $inp->setValue($mailData[
"rcp_cc"]);
675 $inp->setDataSource($dsDataLink,
",");
676 $inp->setMaxLength(null);
677 $form_gui->addItem($inp);
682 $inp->setValue($mailData[
"rcp_bcc"]);
683 $inp->setDataSource($dsDataLink,
",");
684 $inp->setMaxLength(null);
685 $form_gui->addItem($inp);
688 $inp =
new ilTextInputGUI($this->lng->txt(
'subject'),
'm_subject');
690 $inp->setRequired(
true);
691 $inp->setValue($mailData[
"m_subject"]);
692 $form_gui->addItem($inp);
695 include_once
'Services/Mail/classes/class.ilMailFormAttachmentFormPropertyGUI.php';
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)) {
702 $form_gui->addItem($hidden);
703 $size = filesize($this->mfile->getMailPath() .
'/' . $this->
user->getId() .
"_" .
$data);
705 $att->addItem($label);
706 $hidden->setValue(urlencode($data));
710 $form_gui->addItem($att);
713 if ($this->rbacsystem->checkAccess(
"system_message", $this->umail->getMailObjectReferenceId())) {
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);
721 $form_gui->addItem($chb);
728 $mailData[
'use_placeholders'] =
true;
731 require_once
'Services/Mail/classes/class.ilMailTemplateService.php';
734 require_once
'Services/Mail/classes/class.ilMailTemplateDataProvider.php';
736 $templates = $template_provider->getTemplateByContextId($context->getId());
738 if (count($templates)) {
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);
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));
761 require_once
'Services/Mail/classes/class.ilMailTemplateGenericContext.php';
768 $inp->
setValue($mailData[
"m_message"]);
769 $inp->setRequired(
false);
772 $form_gui->addItem($inp);
775 $chb =
new ilCheckboxInputGUI($this->lng->txt(
'mail_serial_letter_placeholders'),
'use_placeholders');
776 $chb->
setOptionTitle($this->lng->txt(
'activate_serial_letter_placeholders'));
778 if (isset($mailData[
'use_placeholders']) && $mailData[
'use_placeholders']) {
779 $chb->setChecked(
true);
782 require_once
'Services/Mail/classes/Form/class.ilManualPlaceholderInputGUI.php';
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']);
789 $chb->addSubItem($placeholders);
790 $form_gui->addItem($chb);
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'));
798 $this->tpl->parseCurrentBlock();
800 $this->tpl->setVariable(
'FORM', $form_gui->getHTML());
802 $this->tpl->addJavaScript(
'Services/Mail/js/ilMailComposeFunctions.js');
808 include_once
'Services/JSON/classes/class.ilJsonUtil.php';
809 include_once
'Services/Mail/classes/class.ilMailForm.php';
811 if (isset(
$_GET[
"term"]) && is_string(
$_GET[
"term"])) {
812 $search =
$_GET[
"term"];
814 if (isset(
$_POST[
"term"]) && is_string(
$_POST[
"term"])) {
818 $search = trim($search);
822 require_once
'Services/Utilities/classes/class.ilStr.php';
830 $quoted = str_replace(
'%',
'\%', $quoted);
831 $quoted = str_replace(
'_',
'\_', $quoted);
855 if (is_array(
$_POST[
'attachments'])) {
856 foreach (
$_POST[
'attachments'] as $value) {
857 $files[] = urldecode($value);
861 $this->umail->savePostData(
862 $this->
user->getId(),
884 $this->ctrl->setParameterByClass(
'ilmailinglistsgui',
'ref',
'mail');
885 $this->ctrl->redirectByClass(
'ilmailinglistsgui');
893 $errors_to_display =
array();
895 foreach ($errors as
$error) {
896 $error = array_values($error);
897 $first_error = array_shift($error);
899 $translation = $this->lng->txt($first_error);
900 if ($translation ==
'-' . $first_error .
'-') {
901 $translation = $first_error;
904 if (count($error) == 0 || $translation == $first_error) {
905 $errors_to_display[] = $translation;
908 $error = array_map(
function ($address) {
912 array_unshift($error, $translation);
913 $errors_to_display[] = call_user_func_array(
'sprintf', $error);
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();
924 $first_error = array_shift($errors_to_display);
926 foreach ($errors_to_display as $error) {
927 $tpl->setCurrentBlock(
'error_loop');
928 $tpl->setVariable(
'ERROR', $error);
929 $tpl->parseCurrentBlock();
932 $tpl->setCurrentBlock(
'multiple_errors');
933 $tpl->setVariable(
'FIRST_ERROR', $first_error);
934 $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.
static getInstanceByGlobalUser()
This class handles all operations on files (attachments) in directory ilias_data/mail.
setValue($a_value)
Set Value.
Class ilMailTemplateDataProvider.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
catch(Exception $e) $message
if(isset($_POST['submit'])) $form
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)
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
static getTemplateContextById($a_id)