65 $this->tpl = $DIC->ui()->mainTemplate();
66 $this->ctrl = $DIC->ctrl();
67 $this->lng = $DIC->language();
68 $this->
user = $DIC->user();
69 $this->tabs = $DIC->tabs();
70 $this->toolbar = $DIC->toolbar();
71 $this->rbacsystem = $DIC->rbac()->system();
77 if (null === $bodyPurifier) {
80 $this->purifier = $bodyPurifier;
82 if (isset(
$_POST[
'mobj_id']) && (
int)
$_POST[
'mobj_id']) {
83 $_GET[
'mobj_id'] = $_POST[
'mobj_id'];
86 if (!(
int)
$_GET[
'mobj_id']) {
87 $_GET[
'mobj_id'] = $this->mbox->getInboxFolder();
89 $_GET[
'mobj_id'] = (int) $_GET[
'mobj_id'];
91 $this->ctrl->saveParameter($this,
'mobj_id');
96 $forward_class = $this->ctrl->getNextClass($this);
97 switch ($forward_class) {
98 case 'ilmailfoldergui':
102 case 'ilmailattachmentgui':
103 $this->ctrl->setReturn($this,
"returnFromAttachments");
107 case 'ilmailsearchgui':
108 $this->ctrl->setReturn($this,
"searchResults");
112 case 'ilmailsearchcoursesgui':
113 $this->ctrl->setReturn($this,
"searchResults");
117 case 'ilmailinglistsgui':
118 $this->ctrl->setReturn($this,
'searchResults');
122 case 'ilmailsearchgroupsgui':
123 $this->ctrl->setReturn($this,
"searchResults");
128 if (!($cmd = $this->ctrl->getCmd())) {
143 $decodedFiles = array();
145 foreach ($files as $value) {
146 if (is_file($this->mfile->getMailPath() .
'/' . $this->
user->getId() .
'_' . urldecode($value))) {
147 $decodedFiles[] = urldecode($value);
151 return $decodedFiles;
160 $sanitizedMessage = $mailBody->getContent();
164 $mailer = $this->umail
168 $mailer->setSaveInSentbox(
true);
170 if (
$errors = $mailer->enqueue(
177 (
int)
$_POST[
'use_placeholders']
180 $_POST[
'attachments'] = $files;
183 $mailer->savePostData($this->
user->getId(), array(),
"",
"",
"",
"",
"",
"",
"",
"");
185 $this->ctrl->setParameterByClass(
'ilmailgui',
'type',
'message_sent');
188 ilUtil::sendSuccess($this->lng->txt(
'mail_message_send'),
true);
191 $this->ctrl->redirectByClass(
'ilmailgui');
200 if (!
$_POST[
'm_subject']) {
201 $_POST[
'm_subject'] =
'No title';
204 $draftFolderId = $this->mbox->getDraftsFolder();
207 if (
$errors = $this->umail->validateRecipients(
212 $_POST[
'attachments'] = $files;
222 $draftId = $this->umail->getNewDraftId($this->
user->getId(), $draftFolderId);
225 $this->umail->updateDraft(
235 (
int)
$_POST[
'use_placeholders'],
245 $this->ctrl->redirectByClass([
'ilmailgui',
'ilmailfoldergui']);
253 $this->tpl->setTitle($this->lng->txt(
"mail"));
258 if (is_array(
$_POST[
'attachments'])) {
259 foreach (
$_POST[
'attachments'] as $value) {
260 $files[] = urldecode($value);
265 $this->umail->savePostData(
266 $this->
user->getId(),
281 $form->setId(
'search_rcp');
282 $form->setTitle($this->lng->txt(
'search_recipients'));
283 $form->setFormAction($this->ctrl->getFormAction($this,
'search'));
285 $inp =
new ilTextInputGUI($this->lng->txt(
"search_for"),
'search');
287 $dsDataLink = $this->ctrl->getLinkTarget($this,
'lookupRecipientAsync',
'',
true,
false);
288 $inp->setDataSource($dsDataLink);
290 if (strlen(trim(
$_SESSION[
"mail_search_search"])) > 0) {
293 $form->addItem($inp);
295 $form->addCommandButton(
'search', $this->lng->txt(
"search"));
296 $form->addCommandButton(
'cancelSearch', $this->lng->txt(
"cancel"));
298 $this->tpl->setContent($form->getHtml());
299 $this->tpl->printToStdout();
310 $this->ctrl->setParameterByClass(
'ilmailsearchcoursesgui',
'cmd',
'showMembers');
313 $this->ctrl->setParameterByClass(
'ilmailsearchcoursesgui',
'ref',
'mail');
314 $this->ctrl->redirectByClass(
'ilmailsearchcoursesgui');
324 $this->ctrl->setParameterByClass(
'ilmailsearchgroupsgui',
'ref',
'mail');
325 $this->ctrl->redirectByClass(
'ilmailsearchgroupsgui');
331 if (strlen(trim(
$_SESSION[
"mail_search_search"])) == 0) {
335 if (strlen(trim(
$_SESSION[
"mail_search_search"])) < 3) {
336 $this->lng->loadLanguageModule(
'search');
340 $this->ctrl->setParameterByClass(
"ilmailsearchgui",
"search", urlencode(
$_SESSION[
"mail_search_search"]));
341 $this->ctrl->redirectByClass(
"ilmailsearchgui");
356 if (is_array(
$_POST[
'attachments'])) {
357 foreach (
$_POST[
'attachments'] as $value) {
358 $files[] = urldecode($value);
363 $this->umail->savePostData(
364 $this->
user->getId(),
377 $this->ctrl->redirectByClass(
"ilmailattachmentgui");
382 $_GET[
"type"] =
"attach";
388 $_GET[
"type"] =
"search_res";
394 $_GET[
"type"] =
"new";
400 $_GET[
"type"] =
"role";
406 $_GET[
"type"] =
"reply";
412 $_GET[
"type"] =
"attach";
421 if (!isset(
$_GET[
'template_id'])) {
426 $template = $this->templateService->loadTemplateForId((
int)
$_GET[
'template_id']);
430 'm_subject' => $template->getSubject(),
431 'm_message' => $template->getMessage(),
440 $this->tpl->addBlockFile(
"ADM_CONTENT",
"adm_content",
"tpl.mail_new.html",
"Services/Mail");
441 $this->tpl->setTitle($this->lng->txt(
"mail"));
443 $this->lng->loadLanguageModule(
"crs");
446 $this->tabs->setBackTarget($this->lng->txt(
'back'), $this->ctrl->getLinkTarget($this,
'cancelMail'));
449 switch (
$_GET[
"type"]) {
454 $mailData = $this->umail->getMail(
$_GET[
"mail_id"]);
455 $mailData[
"m_subject"] = $this->umail->formatReplySubject();
456 $mailData[
"m_message"] = $this->umail->formatReplyMessage();
457 $mailData[
"m_message"] = $this->umail->prependSignature();
459 $mailData[
"attachments"] = array();
461 $mailData[
"rcp_cc"] =
'';
462 $mailData[
"rcp_to"] = $this->umail->formatReplyRecipient();
467 $mailData = $this->umail->getSavedData();
476 if (
$_SESSION[
"mail_search_results_to"]) {
477 $mailData = $this->umail->appendSearchResult(
$_SESSION[
"mail_search_results_to"],
'to');
479 if (
$_SESSION[
"mail_search_results_cc"]) {
480 $mailData = $this->umail->appendSearchResult(
$_SESSION[
"mail_search_results_cc"],
'cc');
482 if (
$_SESSION[
"mail_search_results_bcc"]) {
483 $mailData = $this->umail->appendSearchResult(
$_SESSION[
"mail_search_results_bcc"],
'bc');
486 unset(
$_SESSION[
"mail_search_results_to"]);
487 unset(
$_SESSION[
"mail_search_results_cc"]);
488 unset(
$_SESSION[
"mail_search_results_bcc"]);
493 $mailData = $this->umail->getSavedData();
498 $mailData = $this->umail->getMail(
$_GET[
"mail_id"]);
504 $mailData = $this->umail->getMail(
$_GET[
"mail_id"]);
505 $mailData[
"rcp_to"] = $mailData[
"rcp_cc"] = $mailData[
"rcp_bcc"] =
'';
506 $mailData[
"m_subject"] = $this->umail->formatForwardSubject();
507 $mailData[
"m_message"] = $this->umail->prependSignature();
508 if (is_array($mailData[
"attachments"]) && count($mailData[
"attachments"])) {
509 if ($error = $this->mfile->adoptAttachments($mailData[
"attachments"],
$_GET[
"mail_id"])) {
516 if (
$_GET[
'rcp_to']) {
520 $mailData[
"rcp_to"] =
$_SESSION[
'rcp_to'];
522 if (
$_GET[
'rcp_cc']) {
526 $mailData[
"rcp_cc"] =
$_SESSION[
'rcp_cc'];
528 if (
$_GET[
'rcp_bcc']) {
532 $mailData[
"rcp_bcc"] =
$_SESSION[
'rcp_bcc'];
534 $mailData[
'm_message'] =
'';
536 $mailData[
'm_message'] = $sig;
537 $mailData[
'm_message'] .= chr(13) . chr(10) . chr(13) . chr(10);
539 $mailData[
'm_message'] .= $this->umail->appendSignature();
548 if (is_array(
$_POST[
'roles'])) {
551 } elseif (is_array(
$_SESSION[
'mail_roles'])) {
555 $mailData[
'm_message'] =
'';
557 $mailData[
'm_message'] = $sig;
558 $mailData[
'm_message'] .= chr(13) . chr(10) . chr(13) . chr(10);
561 $mailData[
'm_message'] .=
$_POST[
"additional_message_text"] . chr(13) . chr(10) . $this->umail->appendSignature();
562 $_POST[
"additional_message_text"] =
"";
567 $mailData[
"rcp_to"] = urldecode(
$_GET[
"rcp"]);
575 foreach ($mailData as $key => $value) {
576 if (is_string($value)) {
585 $form_gui->setTitle($this->lng->txt(
'compose'));
586 $form_gui->setId(
'mail_compose_form');
587 $form_gui->setName(
'mail_compose_form');
588 $form_gui->setFormAction($this->ctrl->getFormAction($this,
'sendMessage'));
590 $this->tpl->setVariable(
'FORM_ID', $form_gui->getId());
594 $btn->setForm(
'form_' . $form_gui->getName())
595 ->setName(
'searchUsers')
596 ->setCaption(
'search_recipients');
597 $this->toolbar->addStickyItem($btn);
601 ->setName(
'searchCoursesTo')
602 ->setForm(
'form_' . $form_gui->getName())
603 ->setCaption(
'mail_my_courses');
604 $this->toolbar->addButtonInstance($btn);
608 ->setName(
'searchGroupsTo')
609 ->setForm(
'form_' . $form_gui->getName())
610 ->setCaption(
'mail_my_groups');
611 $this->toolbar->addButtonInstance($btn);
616 ->setName(
'searchMailingListsTo')
617 ->setForm(
'form_' . $form_gui->getName())
618 ->setCaption(
'mail_my_mailing_lists');
619 $this->toolbar->addButtonInstance($btn);
622 $dsDataLink = $this->ctrl->getLinkTarget($this,
'lookupRecipientAsync',
'',
true);
625 $inp->setRequired(
true);
627 $inp->setValue($mailData[
"rcp_to"]);
628 $inp->setDataSource($dsDataLink,
",");
629 $inp->setMaxLength(null);
630 $form_gui->addItem($inp);
634 $inp->setValue($mailData[
"rcp_cc"]);
635 $inp->setDataSource($dsDataLink,
",");
636 $inp->setMaxLength(null);
637 $form_gui->addItem($inp);
641 $inp->setValue($mailData[
"rcp_bcc"]);
642 $inp->setDataSource($dsDataLink,
",");
643 $inp->setMaxLength(null);
644 $form_gui->addItem($inp);
646 $inp =
new ilTextInputGUI($this->lng->txt(
'subject'),
'm_subject');
648 $inp->setRequired(
true);
649 $inp->setValue($mailData[
"m_subject"]);
650 $form_gui->addItem($inp);
654 if (is_array($mailData[
"attachments"]) && count($mailData[
"attachments"])) {
655 foreach ($mailData[
"attachments"] as
$data) {
656 if (is_file($this->mfile->getMailPath() .
'/' . $this->
user->getId() .
"_" .
$data)) {
658 $form_gui->addItem($hidden);
659 $size = filesize($this->mfile->getMailPath() .
'/' . $this->
user->getId() .
"_" .
$data);
661 $att->addItem($label);
662 $hidden->setValue(urlencode($data));
666 $form_gui->addItem($att);
671 $mailData[
'use_placeholders'] =
true;
676 $templates = $this->templateService->loadTemplatesForContextId(
$context->getId());
677 if (count($templates) > 0) {
681 $this->lng->txt(
'mail_template_client'),
683 $this->ctrl->getLinkTarget($this,
'getTemplateDataById',
'',
true,
false),
684 array(
'm_subject' =>
false,
'm_message' =>
true)
687 foreach ($templates as $template) {
688 $options[$template->getTplId()] = $template->
getTitle();
690 if (!isset($mailData[
'template_id']) && $template->isDefault()) {
691 $template_chb->setValue($template->getTplId());
692 $form_gui->getItemByPostVar(
'm_subject')->setValue($template->getSubject());
693 $mailData[
"m_message"] = $template->getMessage();
696 if (isset($mailData[
'template_id'])) {
697 $template_chb->setValue((
int) $mailData[
'template_id']);
701 $template_chb->setInfo($this->lng->txt(
'mail_template_client_info'));
702 $template_chb->setOptions(array(
'' => $this->lng->txt(
'please_choose')) + $options);
703 $form_gui->addItem($template_chb);
707 '%s has been called with invalid context id: %s.',
718 $inp->
setValue($mailData[
"m_message"]);
719 $inp->setRequired(
false);
722 $form_gui->addItem($inp);
724 $chb =
new ilCheckboxInputGUI($this->lng->txt(
'mail_serial_letter_placeholders'),
'use_placeholders');
726 if (isset($mailData[
'use_placeholders']) && $mailData[
'use_placeholders']) {
727 $chb->setChecked(
true);
731 $placeholders->setInstructionText($this->lng->txt(
'mail_nacc_use_placeholder'));
732 $placeholders->setAdviseText(sprintf($this->lng->txt(
'placeholders_advise'),
'<br />'));
733 foreach (
$context->getPlaceholders() as $key => $value) {
734 $placeholders->addPlaceholder($value[
'placeholder'], $value[
'label']);
736 $chb->addSubItem($placeholders);
737 $form_gui->addItem($chb);
739 $form_gui->addCommandButton(
'sendMessage', $this->lng->txt(
'send_mail'));
740 $form_gui->addCommandButton(
'saveDraft', $this->lng->txt(
'save_message'));
742 $form_gui->addCommandButton(
'cancelMail', $this->lng->txt(
'cancel'));
745 $this->tpl->parseCurrentBlock();
747 $this->tpl->setVariable(
'FORM', $form_gui->getHTML());
749 $this->tpl->addJavaScript(
'Services/Mail/js/ilMailComposeFunctions.js');
750 $this->tpl->printToStdout();
756 if (isset(
$_GET[
"term"]) && is_string(
$_GET[
"term"])) {
757 $search =
$_GET[
"term"];
759 if (isset(
$_POST[
"term"]) && is_string(
$_POST[
"term"])) {
763 $search = trim($search);
767 require_once
'Services/Utilities/classes/class.ilStr.php';
775 $quoted = str_replace(
'%',
'\%', $quoted);
776 $quoted = str_replace(
'_',
'\_', $quoted);
800 if (is_array(
$_POST[
'attachments'])) {
801 foreach (
$_POST[
'attachments'] as $value) {
802 $files[] = urldecode($value);
806 $this->umail->savePostData(
807 $this->
user->getId(),
828 $this->ctrl->setParameterByClass(
'ilmailinglistsgui',
'ref',
'mail');
829 $this->ctrl->redirectByClass(
'ilmailinglistsgui');
838 $formattedErrors = $formatter->format($errors);
840 if (strlen($formattedErrors) > 0) {
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()
static getTemplateContextById($a_id)
Class ilMailTemplateService.
setValue($a_value)
Set Value.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
Mail Box class Base class for creating and handling mail boxes.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
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)