24 require_once
'Services/User/classes/class.ilObjUser.php';
25 require_once
'Services/Mail/classes/class.ilMailbox.php';
26 require_once
'Services/Mail/classes/class.ilFormatMail.php';
27 require_once
'classes/class.ilFileDataMail.php';
28 require_once
'Services/Mail/classes/class.ilMailFormCall.php';
57 $this->mbox =
new ilMailBox($ilUser->getId());
61 $_GET[
'mobj_id'] = $_POST[
'mobj_id'];
64 if(!(
int)
$_GET[
'mobj_id'])
66 $_GET[
'mobj_id'] = $this->mbox->getInboxFolder();
69 $this->ctrl->saveParameter($this,
'mobj_id');
74 $forward_class = $this->ctrl->getNextClass($this);
75 switch($forward_class)
77 case 'ilmailfoldergui':
78 include_once
'Services/Mail/classes/class.ilMailFolderGUI.php';
83 case 'ilmailattachmentgui':
84 include_once
'Services/Mail/classes/class.ilMailAttachmentGUI.php';
86 $this->ctrl->setReturn($this,
"returnFromAttachments");
90 case 'ilmailsearchgui':
91 include_once
'Services/Contact/classes/class.ilMailSearchGUI.php';
93 $this->ctrl->setReturn($this,
"searchResults");
97 case 'ilmailsearchcoursesgui':
98 include_once
'Services/Contact/classes/class.ilMailSearchCoursesGUI.php';
100 $this->ctrl->setReturn($this,
"searchResults");
104 case 'ilmailsearchgroupsgui':
105 include_once
'Services/Contact/classes/class.ilMailSearchGroupsGUI.php';
107 $this->ctrl->setReturn($this,
"searchResults");
112 if (!(
$cmd = $this->ctrl->getCmd()))
129 if(is_array(
$_POST[
'attachments']))
131 foreach(
$_POST[
'attachments'] as $value)
133 $files[] = urldecode($value);
141 $f_message = $this->umail->formatLinebreakMessage($f_message);
143 $this->umail->setSaveInSentbox(
true);
145 $m_type = isset(
$_POST[
"m_type"]) ?
$_POST[
"m_type"] : array(
"normal");
148 if($errorMessage = $this->umail->sendMail(
160 if(is_array(
$_POST[
'attachments']))
162 foreach(
$_POST[
'attachments'] as $key => $value)
164 $_POST[
'attachments'][$key] = urldecode($value);
171 $this->umail->savePostData($ilUser->getId(), array(),
"",
"",
"",
"",
"",
"",
"",
"");
173 #$this->ctrl->setParameterByClass("ilmailfoldergui", "mobj_id", $this->mbox->getSentFolder());
174 $this->ctrl->setParameterByClass(
'ilmailgui',
'type',
'message_sent');
182 $this->ctrl->redirectByClass(
'ilmailgui');
192 $_POST[
'm_subject'] =
'No title';
195 $draftsId = $this->mbox->getDraftsFolder();
199 if(is_array(
$_POST[
'attachments']))
201 foreach(
$_POST[
'attachments'] as $value)
203 $files[] = urldecode($value);
210 $this->umail->updateDraft($draftsId,
$files,
221 #session_unregister("draft");
222 #ilUtil::sendInfo($this->lng->txt("mail_saved"),true);
223 #ilUtil::redirect("ilias.php?baseClass=ilMailGUI&mobj_id=".$mbox->getInboxFolder());
231 $this->ctrl->redirectByClass(
"ilmailfoldergui");
235 if ($this->umail->sendInternalMail($draftsId,
$_SESSION[
"AccountId"],
$files,
251 #$this->ctrl->setParameterByClass("ilmailfoldergui", "mobj_id", $this->mbox->getDraftsFolder());
256 $this->ctrl->redirectByClass(
"ilmailfoldergui");
279 $this->tpl->setVariable(
"HEADER", $this->lng->txt(
"mail"));
285 if(is_array(
$_POST[
'attachments']))
287 foreach(
$_POST[
'attachments'] as $value)
289 $files[] = urldecode($value);
294 $this->umail->savePostData($ilUser->getId(),
306 include_once
'Services/Form/classes/class.ilPropertyFormGUI.php';
308 $form->setId(
'search_rcp');
309 $form->setTitle($this->lng->txt(
'search_recipients'));
310 $form->setFormAction($ilCtrl->getFormAction($this,
'search'));
312 $inp =
new ilTextInputGUI($this->lng->txt(
"search_for"),
'search');
314 if (strlen(trim(
$_SESSION[
"mail_search_search"])) > 0)
318 $form->addItem($inp);
320 $chb =
new ilCheckboxInputGUI($this->lng->txt(
"mail_search_addressbook"),
'type_addressbook');
321 if (
$_SESSION[
'mail_search_type_addressbook'])
323 $inp->addSubItem($chb);
326 if (
$_SESSION[
'mail_search_type_system'])
328 $inp->addSubItem($chb);
330 $form->addCommandButton(
'search', $this->lng->txt(
"search"));
331 $form->addCommandButton(
'cancelSearch', $this->lng->txt(
"cancel"));
333 $this->tpl->setContent($form->getHtml());
343 if(is_array(
$_POST[
'attachments']))
345 foreach(
$_POST[
'attachments'] as $value)
347 $files[] = urldecode($value);
352 $this->umail->savePostData($ilUser->getId(),
366 $this->ctrl->setParameterByClass(
"ilmailsearchcoursesgui",
"cmd",
"showMembers");
368 $this->ctrl->setParameterByClass(
"ilmailsearchcoursesgui",
"ref",
"mail");
369 $this->ctrl->redirectByClass(
"ilmailsearchcoursesgui");
378 if(is_array(
$_POST[
'attachments']))
380 foreach(
$_POST[
'attachments'] as $value)
382 $files[] = urldecode($value);
387 $this->umail->savePostData($ilUser->getId(),
399 $this->ctrl->setParameterByClass(
"ilmailsearchgroupsgui",
"ref",
"mail");
400 $this->ctrl->redirectByClass(
"ilmailsearchgroupsgui");
423 $this->tpl->setCurrentBlock(
"search");
424 $this->tpl->setVariable(
"TXT_SEARCH_FOR",$this->lng->txt(
"search_for"));
425 $this->tpl->setVariable(
"TXT_SEARCH_SYSTEM",$this->lng->txt(
"mail_search_system"));
426 $this->tpl->setVariable(
"TXT_SEARCH_ADDRESS",$this->lng->txt(
"mail_search_addressbook"));
428 if ($pref = $ilUser->getPref(
"mail_search"))
430 if ($pref ==
"system" || $pref ==
"all") $this->tpl->setVariable(
"SEARCH_SYSTEM_CHECKED",
"checked=\"checked\"");
431 if ($pref ==
"addressbook" || $pref ==
"all") $this->tpl->setVariable(
"SEARCH_ADDRESS_CHECKED",
"checked=\"checked\"");
435 $this->tpl->setVariable(
"SEARCH_SYSTEM_CHECKED",
"checked=\"checked\"");
438 $this->tpl->setVariable(
"BUTTON_SEARCH",$this->lng->txt(
"search"));
439 $this->tpl->setVariable(
"BUTTON_CANCEL",$this->lng->txt(
"cancel"));
440 if (strlen(trim(
$_POST[
'search'])) > 0)
444 $this->tpl->parseCurrentBlock();
455 $_SESSION[
"mail_search_type_addressbook"] =
$_POST[
"type_addressbook"];
458 if(!
$_SESSION[
"mail_search_type_system"] &&
459 !
$_SESSION[
"mail_search_type_addressbook"])
461 $_SESSION[
"mail_search_type_system"] = 1;
462 $_SESSION[
"mail_search_type_addressbook"] = 1;
463 $ilUser->writePref(
"mail_search",
"all");
465 if (strlen(trim(
$_SESSION[
"mail_search_search"])) == 0)
468 #$this->showSearchForm();
471 else if(strlen(trim(
$_SESSION[
"mail_search_search"])) < 3)
473 $this->lng->loadLanguageModule(
'search');
475 #$this->showSearchForm();
480 $this->ctrl->setParameterByClass(
"ilmailsearchgui",
"search", urlencode(
$_SESSION[
"mail_search_search"]));
483 $this->ctrl->setParameterByClass(
"ilmailsearchgui",
"system", 1);
485 if(
$_SESSION[
"mail_search_type_addressbook"])
487 $this->ctrl->setParameterByClass(
"ilmailsearchgui",
"addressbook", 1);
489 $this->ctrl->redirectByClass(
"ilmailsearchgui");
505 if(is_array(
$_POST[
'attachments']))
507 foreach(
$_POST[
'attachments'] as $value)
509 $files[] = urldecode($value);
514 $this->umail->savePostData(
$_SESSION[
"AccountId"],
526 $this->ctrl->redirectByClass(
"ilmailattachmentgui");
531 $_GET[
"type"] =
"attach";
537 $_GET[
"type"] =
"search_res";
543 $_GET[
"type"] =
"new";
549 $_GET[
"type"] =
"role";
555 $_GET[
"type"] =
"reply";
561 $_GET[
"type"] =
"attach";
567 global $rbacsystem, $ilUser,
$ilCtrl,
$lng, $ilTabs;
569 $this->tpl->addBlockFile(
"ADM_CONTENT",
"adm_content",
"tpl.mail_new.html",
"Services/Mail");
570 $this->tpl->setVariable(
"HEADER", $this->lng->txt(
"mail"));
572 $this->lng->loadLanguageModule(
"crs");
575 $ilTabs->setBackTarget($lng->txt(
'back'), $ilCtrl->getLinkTarget($this,
'cancelMail'));
577 switch(
$_GET[
"type"])
584 $mailData = $this->umail->getMail(
$_GET[
"mail_id"]);
585 $mailData[
"m_subject"] = $this->umail->formatReplySubject();
586 $mailData[
"m_message"] = $this->umail->formatReplyMessage();
587 $mailData[
"m_message"] = $this->umail->appendSignature();
589 $mailData[
"attachments"] = array();
591 $mailData[
"rcp_cc"] =
'';
592 $mailData[
"rcp_to"] = $this->umail->formatReplyRecipient();
597 $mailData = $this->umail->getSavedData();
608 $mailData = $this->umail->appendSearchResult(
$_SESSION[
"mail_search_results_to"],
'to');
612 $mailData = $this->umail->appendSearchResult(
$_SESSION[
"mail_search_results_cc"],
'cc');
616 $mailData = $this->umail->appendSearchResult(
$_SESSION[
"mail_search_results_bcc"],
'bc');
619 unset(
$_SESSION[
"mail_search_results_to"]);
620 unset(
$_SESSION[
"mail_search_results_cc"]);
621 unset(
$_SESSION[
"mail_search_results_bcc"]);
626 $mailData = $this->umail->getSavedData();
631 $mailData = $this->umail->getMail(
$_GET[
"mail_id"]);
635 $mailData = $this->umail->getMail(
$_GET[
"mail_id"]);
636 $mailData[
"rcp_to"] = $mailData[
"rcp_cc"] = $mailData[
"rcp_bcc"] =
'';
637 $mailData[
"m_subject"] = $this->umail->formatForwardSubject();
638 $mailData[
"m_message"] = $this->umail->appendSignature();
639 if(count($mailData[
"attachments"]))
641 if(
$error = $this->mfile->adoptAttachments($mailData[
"attachments"],
$_GET[
"mail_id"]))
656 $mailData[
"rcp_to"] =
$_SESSION[
'rcp_to'];
665 $mailData[
"rcp_cc"] =
$_SESSION[
'rcp_cc'];
674 $mailData[
"rcp_bcc"] =
$_SESSION[
'rcp_bcc'];
676 $mailData[
'm_message'] =
'';
679 $mailData[
'm_message'] = $sig;
680 $mailData[
'm_message'] .= chr(13).chr(10).chr(13).chr(10);
682 $mailData[
'm_message'] .= $this->umail->appendSignature();
691 if(is_array(
$_POST[
'roles']))
696 elseif(is_array(
$_SESSION[
'mail_roles']))
701 $mailData[
'm_message'] =
'';
704 $mailData[
'm_message'] = $sig;
705 $mailData[
'm_message'] .= chr(13).chr(10).chr(13).chr(10);
708 $mailData[
'm_message'] .=
$_POST[
"additional_message_text"].chr(13).chr(10).$this->umail->appendSignature();
709 $_POST[
"additional_message_text"] =
"";
714 $mailData[
"rcp_to"] = urldecode(
$_GET[
"rcp"]);
722 foreach ($mailData as $key => $value)
724 if (is_string($value))
733 include_once(
'./Services/Form/classes/class.ilPropertyFormGUI.php');
736 $form_gui->setTitle($this->lng->txt(
'compose'));
737 $form_gui->setOpenTag(
false);
738 $this->tpl->setVariable(
'FORM_ACTION', $this->ctrl->getFormAction($this,
'sendMessage'));
740 $this->tpl->setVariable(
'BUTTON_TO', $lng->txt(
"search_recipients"));
741 $this->tpl->setVariable(
'BUTTON_COURSES_TO', $lng->txt(
"mail_my_courses"));
742 $this->tpl->setVariable(
'BUTTON_GROUPS_TO', $lng->txt(
"mail_my_groups"));
745 $dsSchema = array(
"resultsList" =>
'response.results',
746 "fields" => array(
'login',
'firstname',
'lastname'));
748 $dsFormatCallback =
'formatAutoCompleteResults';
749 $dsDataLink = $ilCtrl->getLinkTarget($this,
'lookupRecipientAsync',
'',
'',
false);
750 $dsDelimiter = array(
',');
756 $inp->setValue($mailData[
"rcp_to"]);
757 $inp->setDataSource($dsDataLink);
758 $inp->setDataSourceSchema($dsSchema);
759 $inp->setDataSourceResultFormat($dsFormatCallback);
760 $inp->setDataSourceDelimiter($dsDelimiter);
761 $inp->setMaxLength(null);
762 $form_gui->addItem($inp);
767 $inp->setValue($mailData[
"rcp_cc"]);
768 $inp->setDataSource($dsDataLink);
769 $inp->setDataSourceSchema($dsSchema);
770 $inp->setDataSourceResultFormat($dsFormatCallback);
771 $inp->setDataSourceDelimiter($dsDelimiter);
772 $inp->setMaxLength(null);
773 $form_gui->addItem($inp);
778 $inp->setValue($mailData[
"rcp_bcc"]);
779 $inp->setDataSource($dsDataLink);
780 $inp->setDataSourceSchema($dsSchema);
781 $inp->setDataSourceResultFormat($dsFormatCallback);
782 $inp->setDataSourceDelimiter($dsDelimiter);
783 $inp->setMaxLength(null);
784 $form_gui->addItem($inp);
787 $inp =
new ilTextInputGUI($this->lng->txt(
'subject'),
'm_subject');
789 $inp->setRequired(
true);
790 $inp->setValue($mailData[
"m_subject"]);
791 $form_gui->addItem($inp);
794 include_once
'Services/Mail/classes/class.ilMailFormAttachmentFormPropertyGUI.php';
798 if (is_array($mailData[
"attachments"]) && count($mailData[
"attachments"]))
800 foreach($mailData[
"attachments"] as $key =>
$data)
803 $hidden->setValue(urlencode(
$data));
804 $form_gui->addItem($hidden);
805 $size = round(filesize($this->mfile->getMailPath() .
'/' . $ilUser->getId() .
"_" .
$data) / 1024);
806 if ($size < 1) $size = 1;
807 $label =
$data .
" [" . number_format($size, 0,
".",
"") .
" KByte]";
808 $att->addItem($label);
811 $form_gui->addItem($att);
814 if($rbacsystem->checkAccess(
"system_message",$this->umail->getMailObjectReferenceId()))
818 $chb->setValue(
'system');
819 $chb->setChecked(
false);
820 if(is_array($mailData[
"m_type"]) and in_array(
'system',$mailData[
"m_type"]))
822 $chb->setChecked(
true);
824 $form_gui->addItem($chb);
831 $inp->
setValue($mailData[
"m_message"]);
832 $inp->setRequired(
false);
837 $chb =
new ilCheckboxInputGUI($this->lng->txt(
'activate_serial_letter_placeholders'),
'use_placeholders');
838 $chb->
setOptionTitle($this->lng->txt(
'activate_serial_letter_placeholders'));
840 $chb->setChecked(
false);
841 $form_gui->addItem($inp);
843 include_once
'Services/Mail/classes/class.ilMailFormPlaceholdersPropertyGUI.php';
846 $chb->addSubItem($prop);
848 if ($mailData[
'use_placeholders'])
850 $chb->setChecked(
true);
853 $form_gui->addItem($chb);
855 $form_gui->addCommandButton(
'sendMessage', $this->lng->txt(
'send_mail'));
856 $form_gui->addCommandButton(
'saveDraft', $this->lng->txt(
'save_message'));
858 $form_gui->addCommandButton(
'cancelMail', $this->lng->txt(
'cancel'));
860 $this->tpl->parseCurrentBlock();
862 $this->tpl->setVariable(
'FORM', $form_gui->getHTML());
864 $this->tpl->addJavaScript(
'Services/Mail/js/ilMailComposeFunctions.js');
870 global $ilUser, $rbacsystem;
871 include_once
'Services/JSON/classes/class.ilJsonUtil.php';
872 include_once
'Services/Mail/classes/class.ilMailForm.php';
875 $result =
new stdClass();
876 $result->response =
new stdClass();
877 $result->response->results = array();
880 $result->response->total = 0;