Esempio n. 1
0
 public function showForm()
 {
     global $rbacsystem, $ilUser, $ilCtrl, $lng, $ilTabs;
     $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_new.html", "Services/Mail");
     $this->tpl->setTitle($this->lng->txt("mail"));
     $this->lng->loadLanguageModule("crs");
     if (ilMailFormCall::isRefererStored()) {
         $ilTabs->setBackTarget($lng->txt('back'), $ilCtrl->getLinkTarget($this, 'cancelMail'));
     }
     switch ($_GET["type"]) {
         case 'reply':
             if ($_SESSION['mail_id']) {
                 $_GET['mail_id'] = $_SESSION['mail_id'];
             }
             $mailData = $this->umail->getMail($_GET["mail_id"]);
             $mailData["m_subject"] = $this->umail->formatReplySubject();
             $mailData["m_message"] = $this->umail->formatReplyMessage();
             $mailData["m_message"] = $this->umail->prependSignature();
             // NO ATTACHMENTS FOR REPLIES
             $mailData["attachments"] = array();
             //$mailData["rcp_cc"] = $this->umail->formatReplyRecipientsForCC();
             $mailData["rcp_cc"] = '';
             $mailData["rcp_to"] = $this->umail->formatReplyRecipient();
             $_SESSION["mail_id"] = "";
             break;
         case 'search_res':
             $mailData = $this->umail->getSavedData();
             /*if($_SESSION["mail_search_results"])
             		{
             			$mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results"],$_SESSION["mail_search"]);
             		}
             		unset($_SESSION["mail_search"]);
             		unset($_SESSION["mail_search_results"]);*/
             if ($_SESSION["mail_search_results_to"]) {
                 $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_to"], 'to');
             }
             if ($_SESSION["mail_search_results_cc"]) {
                 $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_cc"], 'cc');
             }
             if ($_SESSION["mail_search_results_bcc"]) {
                 $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_bcc"], 'bc');
             }
             unset($_SESSION["mail_search_results_to"]);
             unset($_SESSION["mail_search_results_cc"]);
             unset($_SESSION["mail_search_results_bcc"]);
             break;
         case 'attach':
             $mailData = $this->umail->getSavedData();
             break;
         case 'draft':
             $_SESSION["draft"] = $_GET["mail_id"];
             $mailData = $this->umail->getMail($_GET["mail_id"]);
             break;
         case 'forward':
             $mailData = $this->umail->getMail($_GET["mail_id"]);
             $mailData["rcp_to"] = $mailData["rcp_cc"] = $mailData["rcp_bcc"] = '';
             $mailData["m_subject"] = $this->umail->formatForwardSubject();
             $mailData["m_message"] = $this->umail->prependSignature();
             if (count($mailData["attachments"])) {
                 if ($error = $this->mfile->adoptAttachments($mailData["attachments"], $_GET["mail_id"])) {
                     ilUtil::sendInfo($error);
                 }
             }
             break;
         case 'new':
             if ($_GET['rcp_to']) {
                 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
                 $mailData["rcp_to"] = ilUtil::securePlainString($_GET['rcp_to']);
             } else {
                 if ($_SESSION['rcp_to']) {
                     $mailData["rcp_to"] = $_SESSION['rcp_to'];
                 }
             }
             if ($_GET['rcp_cc']) {
                 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
                 $mailData["rcp_cc"] = ilUtil::securePlainString($_GET['rcp_cc']);
             } else {
                 if ($_SESSION['rcp_cc']) {
                     $mailData["rcp_cc"] = $_SESSION['rcp_cc'];
                 }
             }
             if ($_GET['rcp_bcc']) {
                 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
                 $mailData["rcp_bcc"] = ilUtil::securePlainString($_GET['rcp_bcc']);
             } else {
                 if ($_SESSION['rcp_bcc']) {
                     $mailData["rcp_bcc"] = $_SESSION['rcp_bcc'];
                 }
             }
             $mailData['m_message'] = '';
             if (strlen($sig = ilMailFormCall::getSignature())) {
                 $mailData['m_message'] = $sig;
                 $mailData['m_message'] .= chr(13) . chr(10) . chr(13) . chr(10);
             }
             $mailData['m_message'] .= $this->umail->appendSignature();
             $_SESSION['rcp_to'] = '';
             $_SESSION['rcp_cc'] = '';
             $_SESSION['rcp_bcc'] = '';
             break;
         case 'role':
             if (is_array($_POST['roles'])) {
                 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
                 $mailData['rcp_to'] = ilUtil::securePlainString(implode(',', $_POST['roles']));
             } elseif (is_array($_SESSION['mail_roles'])) {
                 $mailData['rcp_to'] = ilUtil::securePlainString(implode(',', $_SESSION['mail_roles']));
             }
             $mailData['m_message'] = '';
             if (strlen($sig = ilMailFormCall::getSignature())) {
                 $mailData['m_message'] = $sig;
                 $mailData['m_message'] .= chr(13) . chr(10) . chr(13) . chr(10);
             }
             $mailData['m_message'] .= $_POST["additional_message_text"] . chr(13) . chr(10) . $this->umail->appendSignature();
             $_POST["additional_message_text"] = "";
             $_SESSION['mail_roles'] = "";
             break;
         case 'address':
             $mailData["rcp_to"] = urldecode($_GET["rcp"]);
             break;
         default:
             // GET DATA FROM POST
             $mailData = $_POST;
             // strip slashes
             foreach ($mailData as $key => $value) {
                 if (is_string($value)) {
                     // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
                     $mailData[$key] = ilUtil::securePlainString($value);
                 }
             }
             break;
     }
     include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
     $form_gui = new ilPropertyFormGUI();
     $form_gui->setTitle($this->lng->txt('compose'));
     $form_gui->setOpenTag(false);
     $this->tpl->setVariable('FORM_ACTION', $this->ctrl->getFormAction($this, 'sendMessage'));
     $this->tpl->setVariable('BUTTON_TO', $lng->txt("search_recipients"));
     $this->tpl->setVariable('BUTTON_COURSES_TO', $lng->txt("mail_my_courses"));
     $this->tpl->setVariable('BUTTON_GROUPS_TO', $lng->txt("mail_my_groups"));
     $this->tpl->setVariable('BUTTON_MAILING_LISTS_TO', $lng->txt("mail_my_mailing_lists"));
     $dsDataLink = $ilCtrl->getLinkTarget($this, 'lookupRecipientAsync', '', true);
     // RECIPIENT
     $inp = new ilTextInputGUI($this->lng->txt('mail_to'), 'rcp_to');
     $inp->setRequired(true);
     $inp->setSize(50);
     $inp->setValue($mailData["rcp_to"]);
     $inp->setDataSource($dsDataLink, ",");
     $inp->setMaxLength(null);
     $form_gui->addItem($inp);
     // CC
     $inp = new ilTextInputGUI($this->lng->txt('cc'), 'rcp_cc');
     $inp->setSize(50);
     $inp->setValue($mailData["rcp_cc"]);
     $inp->setDataSource($dsDataLink, ",");
     $inp->setMaxLength(null);
     $form_gui->addItem($inp);
     // BCC
     $inp = new ilTextInputGUI($this->lng->txt('bc'), 'rcp_bcc');
     $inp->setSize(50);
     $inp->setValue($mailData["rcp_bcc"]);
     $inp->setDataSource($dsDataLink, ",");
     $inp->setMaxLength(null);
     $form_gui->addItem($inp);
     // SUBJECT
     $inp = new ilTextInputGUI($this->lng->txt('subject'), 'm_subject');
     $inp->setSize(50);
     $inp->setRequired(true);
     $inp->setValue($mailData["m_subject"]);
     $form_gui->addItem($inp);
     // Attachments
     include_once 'Services/Mail/classes/class.ilMailFormAttachmentFormPropertyGUI.php';
     $att = new ilMailFormAttachmentPropertyGUI($this->lng->txt($mailData["attachments"] ? 'edit' : 'add'));
     if (is_array($mailData["attachments"]) && count($mailData["attachments"])) {
         foreach ($mailData["attachments"] as $data) {
             if (is_file($this->mfile->getMailPath() . '/' . $ilUser->getId() . "_" . $data)) {
                 $hidden = new ilHiddenInputGUI('attachments[]');
                 $form_gui->addItem($hidden);
                 $size = filesize($this->mfile->getMailPath() . '/' . $ilUser->getId() . "_" . $data);
                 $label = $data . " [" . ilFormat::formatSize($size) . "]";
                 $att->addItem($label);
                 $hidden->setValue(urlencode($data));
             }
         }
     }
     $form_gui->addItem($att);
     // ONLY IF SYSTEM MAILS ARE ALLOWED
     if ($rbacsystem->checkAccess("system_message", $this->umail->getMailObjectReferenceId())) {
         $chb = new ilCheckboxInputGUI($this->lng->txt('type'), 'm_type[]');
         $chb->setOptionTitle($this->lng->txt('system_message'));
         $chb->setValue('system');
         $chb->setChecked(false);
         if (is_array($mailData["m_type"]) and in_array('system', $mailData["m_type"])) {
             $chb->setChecked(true);
         }
         $form_gui->addItem($chb);
     }
     // MESSAGE
     $inp = new ilTextAreaInputGUI($this->lng->txt('message_content'), 'm_message');
     //$inp->setValue(htmlspecialchars($mailData["m_message"], false));
     $inp->setValue($mailData["m_message"]);
     $inp->setRequired(false);
     $inp->setCols(60);
     $inp->setRows(10);
     // PLACEHOLDERS
     $chb = new ilCheckboxInputGUI($this->lng->txt('activate_serial_letter_placeholders'), 'use_placeholders');
     $chb->setOptionTitle($this->lng->txt('activate_serial_letter_placeholders'));
     $chb->setValue(1);
     $chb->setChecked(false);
     $form_gui->addItem($inp);
     include_once 'Services/Mail/classes/class.ilMailFormPlaceholdersPropertyGUI.php';
     $prop = new ilMailFormPlaceholdersPropertyGUI();
     $chb->addSubItem($prop);
     if ($mailData['use_placeholders']) {
         $chb->setChecked(true);
     }
     $form_gui->addItem($chb);
     $form_gui->addCommandButton('sendMessage', $this->lng->txt('send_mail'));
     $form_gui->addCommandButton('saveDraft', $this->lng->txt('save_message'));
     if (ilMailFormCall::isRefererStored()) {
         $form_gui->addCommandButton('cancelMail', $this->lng->txt('cancel'));
     }
     $this->tpl->parseCurrentBlock();
     $this->tpl->setVariable('FORM', $form_gui->getHTML());
     $this->tpl->addJavaScript('Services/Mail/js/ilMailComposeFunctions.js');
     $this->tpl->show();
 }