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 if(is_array(
$_POST[
'attachments']))
118 foreach(
$_POST[
'attachments'] as $value)
120 if(is_file($this->mfile->getMailPath() .
'/' . $ilUser->getId() .
"_" . urldecode($value)))
122 $files[] = urldecode($value);
131 $f_message = $this->umail->formatLinebreakMessage($f_message);
133 $this->umail->setSaveInSentbox(
true);
135 $m_type = isset(
$_POST[
"m_type"]) ?
$_POST[
"m_type"] : array(
"normal");
138 if($errorMessage = $this->umail->sendMail(
150 if(is_array(
$_POST[
'attachments']))
152 foreach(
$_POST[
'attachments'] as $key => $value)
154 if(is_file($this->mfile->getMailPath() .
'/' . $ilUser->getId() .
"_" . urldecode($value)))
156 $_POST[
'attachments'][$key] = urldecode($value);
160 unset(
$_POST[
'attachments'][$key]);
168 $this->umail->savePostData($ilUser->getId(), array(),
"",
"",
"",
"",
"",
"",
"",
"");
170 $this->ctrl->setParameterByClass(
'ilmailgui',
'type',
'message_sent');
178 $this->ctrl->redirectByClass(
'ilmailgui');
188 $_POST[
'm_subject'] =
'No title';
191 $draftsId = $this->mbox->getDraftsFolder();
195 if(is_array(
$_POST[
'attachments']))
197 foreach(
$_POST[
'attachments'] as $value)
199 $files[] = urldecode($value);
206 $this->umail->updateDraft($draftsId, $files,
217 #session_unregister("draft");
218 #ilUtil::sendInfo($this->lng->txt("mail_saved"),true);
219 #ilUtil::redirect("ilias.php?baseClass=ilMailGUI&mobj_id=".$mbox->getInboxFolder());
221 unset($_SESSION[
"draft"]);
227 $this->ctrl->redirectByClass(
"ilmailfoldergui");
231 if ($this->umail->sendInternalMail($draftsId,
$_SESSION[
"AccountId"],$files,
247 #$this->ctrl->setParameterByClass("ilmailfoldergui", "mobj_id", $this->mbox->getDraftsFolder());
252 $this->ctrl->redirectByClass(
"ilmailfoldergui");
275 $this->tpl->setTitle($this->lng->txt(
"mail"));
281 if(is_array(
$_POST[
'attachments']))
283 foreach(
$_POST[
'attachments'] as $value)
285 $files[] = urldecode($value);
290 $this->umail->savePostData($ilUser->getId(),
302 include_once
'Services/Form/classes/class.ilPropertyFormGUI.php';
304 $form->setId(
'search_rcp');
305 $form->setTitle($this->lng->txt(
'search_recipients'));
306 $form->setFormAction($ilCtrl->getFormAction($this,
'search'));
308 $inp =
new ilTextInputGUI($this->lng->txt(
"search_for"),
'search');
310 $dsDataLink = $ilCtrl->getLinkTarget($this,
'lookupRecipientAsync',
'',
true);
311 $inp->setDataSource($dsDataLink);
313 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());
342 $this->saveMailBeforeSearch();
346 $this->ctrl->setParameterByClass(
'ilmailsearchcoursesgui',
'cmd',
'showMembers');
349 $this->ctrl->setParameterByClass(
'ilmailsearchcoursesgui',
'ref',
'mail');
350 $this->ctrl->redirectByClass(
'ilmailsearchcoursesgui');
358 $this->saveMailBeforeSearch();
360 $this->ctrl->setParameterByClass(
'ilmailsearchgroupsgui',
'ref',
'mail');
361 $this->ctrl->redirectByClass(
'ilmailsearchgroupsgui');
384 $this->tpl->setCurrentBlock(
"search");
385 $this->tpl->setVariable(
"TXT_SEARCH_FOR",$this->lng->txt(
"search_for"));
386 $this->tpl->setVariable(
"TXT_SEARCH_SYSTEM",$this->lng->txt(
"mail_search_system"));
387 $this->tpl->setVariable(
"TXT_SEARCH_ADDRESS",$this->lng->txt(
"mail_search_addressbook"));
389 if ($pref = $ilUser->getPref(
"mail_search"))
391 if ($pref ==
"system" || $pref ==
"all") $this->tpl->setVariable(
"SEARCH_SYSTEM_CHECKED",
"checked=\"checked\"");
392 if ($pref ==
"addressbook" || $pref ==
"all") $this->tpl->setVariable(
"SEARCH_ADDRESS_CHECKED",
"checked=\"checked\"");
396 $this->tpl->setVariable(
"SEARCH_SYSTEM_CHECKED",
"checked=\"checked\"");
399 $this->tpl->setVariable(
"BUTTON_SEARCH",$this->lng->txt(
"search"));
400 $this->tpl->setVariable(
"BUTTON_CANCEL",$this->lng->txt(
"cancel"));
401 if (strlen(trim(
$_POST[
'search'])) > 0)
405 $this->tpl->parseCurrentBlock();
416 $_SESSION[
"mail_search_type_addressbook"] =
$_POST[
"type_addressbook"];
418 if (strlen(trim(
$_SESSION[
"mail_search_search"])) == 0)
421 #$this->showSearchForm();
424 else if(strlen(trim(
$_SESSION[
"mail_search_search"])) < 3)
426 $this->lng->loadLanguageModule(
'search');
428 #$this->showSearchForm();
433 $this->ctrl->setParameterByClass(
"ilmailsearchgui",
"search", urlencode(
$_SESSION[
"mail_search_search"]));
436 $this->ctrl->setParameterByClass(
"ilmailsearchgui",
"system", 1);
438 if(
$_SESSION[
"mail_search_type_addressbook"])
440 $this->ctrl->setParameterByClass(
"ilmailsearchgui",
"addressbook", 1);
442 $this->ctrl->redirectByClass(
"ilmailsearchgui");
458 if(is_array(
$_POST[
'attachments']))
460 foreach(
$_POST[
'attachments'] as $value)
462 $files[] = urldecode($value);
467 $this->umail->savePostData(
$_SESSION[
"AccountId"],
479 $this->ctrl->redirectByClass(
"ilmailattachmentgui");
484 $_GET[
"type"] =
"attach";
490 $_GET[
"type"] =
"search_res";
496 $_GET[
"type"] =
"new";
502 $_GET[
"type"] =
"role";
508 $_GET[
"type"] =
"reply";
514 $_GET[
"type"] =
"attach";
522 $this->tpl->addBlockFile(
"ADM_CONTENT",
"adm_content",
"tpl.mail_new.html",
"Services/Mail");
523 $this->tpl->setTitle($this->lng->txt(
"mail"));
525 $this->lng->loadLanguageModule(
"crs");
528 $ilTabs->setBackTarget($lng->txt(
'back'), $ilCtrl->getLinkTarget($this,
'cancelMail'));
530 switch(
$_GET[
"type"])
537 $mailData = $this->umail->getMail(
$_GET[
"mail_id"]);
538 $mailData[
"m_subject"] = $this->umail->formatReplySubject();
539 $mailData[
"m_message"] = $this->umail->formatReplyMessage();
540 $mailData[
"m_message"] = $this->umail->appendSignature();
542 $mailData[
"attachments"] = array();
544 $mailData[
"rcp_cc"] =
'';
545 $mailData[
"rcp_to"] = $this->umail->formatReplyRecipient();
550 $mailData = $this->umail->getSavedData();
561 $mailData = $this->umail->appendSearchResult(
$_SESSION[
"mail_search_results_to"],
'to');
565 $mailData = $this->umail->appendSearchResult(
$_SESSION[
"mail_search_results_cc"],
'cc');
569 $mailData = $this->umail->appendSearchResult(
$_SESSION[
"mail_search_results_bcc"],
'bc');
572 unset(
$_SESSION[
"mail_search_results_to"]);
573 unset(
$_SESSION[
"mail_search_results_cc"]);
574 unset(
$_SESSION[
"mail_search_results_bcc"]);
579 $mailData = $this->umail->getSavedData();
584 $mailData = $this->umail->getMail(
$_GET[
"mail_id"]);
588 $mailData = $this->umail->getMail(
$_GET[
"mail_id"]);
589 $mailData[
"rcp_to"] = $mailData[
"rcp_cc"] = $mailData[
"rcp_bcc"] =
'';
590 $mailData[
"m_subject"] = $this->umail->formatForwardSubject();
591 $mailData[
"m_message"] = $this->umail->appendSignature();
592 if(count($mailData[
"attachments"]))
594 if($error = $this->mfile->adoptAttachments($mailData[
"attachments"],
$_GET[
"mail_id"]))
609 $mailData[
"rcp_to"] =
$_SESSION[
'rcp_to'];
618 $mailData[
"rcp_cc"] =
$_SESSION[
'rcp_cc'];
627 $mailData[
"rcp_bcc"] =
$_SESSION[
'rcp_bcc'];
629 $mailData[
'm_message'] =
'';
632 $mailData[
'm_message'] = $sig;
633 $mailData[
'm_message'] .= chr(13).chr(10).chr(13).chr(10);
635 $mailData[
'm_message'] .= $this->umail->appendSignature();
644 if(is_array(
$_POST[
'roles']))
649 elseif(is_array(
$_SESSION[
'mail_roles']))
654 $mailData[
'm_message'] =
'';
657 $mailData[
'm_message'] = $sig;
658 $mailData[
'm_message'] .= chr(13).chr(10).chr(13).chr(10);
661 $mailData[
'm_message'] .=
$_POST[
"additional_message_text"].chr(13).chr(10).$this->umail->appendSignature();
662 $_POST[
"additional_message_text"] =
"";
667 $mailData[
"rcp_to"] = urldecode(
$_GET[
"rcp"]);
675 foreach ($mailData as $key => $value)
677 if (is_string($value))
686 include_once(
'./Services/Form/classes/class.ilPropertyFormGUI.php');
689 $form_gui->setTitle($this->lng->txt(
'compose'));
690 $form_gui->setOpenTag(
false);
691 $this->tpl->setVariable(
'FORM_ACTION', $this->ctrl->getFormAction($this,
'sendMessage'));
693 $this->tpl->setVariable(
'BUTTON_TO', $lng->txt(
"search_recipients"));
694 $this->tpl->setVariable(
'BUTTON_COURSES_TO', $lng->txt(
"mail_my_courses"));
695 $this->tpl->setVariable(
'BUTTON_GROUPS_TO', $lng->txt(
"mail_my_groups"));
696 $this->tpl->setVariable(
'BUTTON_MAILING_LISTS_TO', $lng->txt(
"mail_my_mailing_lists"));
698 $dsDataLink = $ilCtrl->getLinkTarget($this,
'lookupRecipientAsync',
'',
true);
704 $inp->setValue($mailData[
"rcp_to"]);
705 $inp->setDataSource($dsDataLink);
706 $inp->setMaxLength(null);
707 $form_gui->addItem($inp);
712 $inp->setValue($mailData[
"rcp_cc"]);
713 $inp->setDataSource($dsDataLink);
714 $inp->setMaxLength(null);
715 $form_gui->addItem($inp);
720 $inp->setValue($mailData[
"rcp_bcc"]);
721 $inp->setDataSource($dsDataLink);
722 $inp->setMaxLength(null);
723 $form_gui->addItem($inp);
726 $inp =
new ilTextInputGUI($this->lng->txt(
'subject'),
'm_subject');
728 $inp->setRequired(
true);
729 $inp->setValue($mailData[
"m_subject"]);
730 $form_gui->addItem($inp);
733 include_once
'Services/Mail/classes/class.ilMailFormAttachmentFormPropertyGUI.php';
737 if (is_array($mailData[
"attachments"]) && count($mailData[
"attachments"]))
739 foreach($mailData[
"attachments"] as
$data)
741 if(is_file($this->mfile->getMailPath() .
'/' . $ilUser->getId() .
"_" .
$data))
744 $form_gui->addItem($hidden);
745 $size = filesize($this->mfile->getMailPath() .
'/' . $ilUser->getId() .
"_" .
$data);
747 $att->addItem($label);
748 $hidden->setValue(urlencode($data));
752 $form_gui->addItem($att);
755 if($rbacsystem->checkAccess(
"system_message",$this->umail->getMailObjectReferenceId()))
759 $chb->setValue(
'system');
760 $chb->setChecked(
false);
761 if(is_array($mailData[
"m_type"]) and in_array(
'system',$mailData[
"m_type"]))
763 $chb->setChecked(
true);
765 $form_gui->addItem($chb);
772 $inp->
setValue($mailData[
"m_message"]);
773 $inp->setRequired(
false);
778 $chb =
new ilCheckboxInputGUI($this->lng->txt(
'activate_serial_letter_placeholders'),
'use_placeholders');
779 $chb->
setOptionTitle($this->lng->txt(
'activate_serial_letter_placeholders'));
781 $chb->setChecked(
false);
782 $form_gui->addItem($inp);
784 include_once
'Services/Mail/classes/class.ilMailFormPlaceholdersPropertyGUI.php';
787 $chb->addSubItem($prop);
789 if ($mailData[
'use_placeholders'])
791 $chb->setChecked(
true);
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';
824 $quoted = str_replace(
'%',
'\%', $quoted);
825 $quoted = str_replace(
'_',
'\_', $quoted);
828 $result = $mailFormObj->getRecipientAsync(
"%" .$quoted.
"%", $search);
845 protected function saveMailBeforeSearch()
854 if(is_array(
$_POST[
'attachments']))
856 foreach(
$_POST[
'attachments'] as $value)
858 $files[] = urldecode($value);
862 $this->umail->savePostData($ilUser->getId(),
880 $this->saveMailBeforeSearch();
882 $this->ctrl->setParameterByClass(
'ilmailinglistsgui',
'ref',
'mail');
883 $this->ctrl->redirectByClass(
'ilmailinglistsgui');