ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMailFormGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
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';
29 
38 {
39  private $tpl = null;
40  private $ctrl = null;
41  private $lng = null;
42 
43  private $umail = null;
44  private $mbox = null;
45  private $mfile = null;
46 
47  public function __construct()
48  {
49  global $tpl, $ilCtrl, $lng, $ilUser;
50 
51  $this->tpl = $tpl;
52  $this->ctrl = $ilCtrl;
53  $this->lng = $lng;
54 
55  $this->umail = new ilFormatMail($ilUser->getId());
56  $this->mfile = new ilFileDataMail($ilUser->getId());
57  $this->mbox = new ilMailBox($ilUser->getId());
58 
59  if(isset($_POST['mobj_id']) && (int)$_POST['mobj_id'])
60  {
61  $_GET['mobj_id'] = $_POST['mobj_id'];
62  }
63  // IF THERE IS NO OBJ_ID GIVEN GET THE ID OF MAIL ROOT NODE
64  if(!(int)$_GET['mobj_id'])
65  {
66  $_GET['mobj_id'] = $this->mbox->getInboxFolder();
67  }
68 
69  $this->ctrl->saveParameter($this, 'mobj_id');
70  }
71 
72  public function executeCommand()
73  {
74  $forward_class = $this->ctrl->getNextClass($this);
75  switch($forward_class)
76  {
77  case 'ilmailfoldergui':
78  include_once 'Services/Mail/classes/class.ilMailFolderGUI.php';
79 
80  $this->ctrl->forwardCommand(new ilMailFolderGUI());
81  break;
82 
83  case 'ilmailattachmentgui':
84  include_once 'Services/Mail/classes/class.ilMailAttachmentGUI.php';
85 
86  $this->ctrl->setReturn($this, "returnFromAttachments");
87  $this->ctrl->forwardCommand(new ilMailAttachmentGUI());
88  break;
89 
90  case 'ilmailsearchgui':
91  include_once 'Services/Contact/classes/class.ilMailSearchGUI.php';
92 
93  $this->ctrl->setReturn($this, "searchResults");
94  $this->ctrl->forwardCommand(new ilMailSearchGUI());
95  break;
96 
97  case 'ilmailsearchcoursesgui':
98  include_once 'Services/Contact/classes/class.ilMailSearchCoursesGUI.php';
99 
100  $this->ctrl->setReturn($this, "searchResults");
101  $this->ctrl->forwardCommand(new ilMailSearchCoursesGUI());
102  break;
103 
104  case 'ilmailsearchgroupsgui':
105  include_once 'Services/Contact/classes/class.ilMailSearchGroupsGUI.php';
106 
107  $this->ctrl->setReturn($this, "searchResults");
108  $this->ctrl->forwardCommand(new ilMailSearchGroupsGUI());
109  break;
110 
111  default:
112  if (!($cmd = $this->ctrl->getCmd()))
113  {
114  $cmd = "showForm";
115  }
116 
117  $this->$cmd();
118  break;
119  }
120  return true;
121  }
122 
123  public function sendMessage()
124  {
125  global $ilUser;
126 
127  // decode post values
128  $files = array();
129  if(is_array($_POST['attachments']))
130  {
131  foreach($_POST['attachments'] as $value)
132  {
133  $files[] = urldecode($value);
134  }
135  }
136 
137  // Remove \r
138  $f_message = str_replace("\r", '', ilUtil::securePlainString($_POST['m_message']));
139 
140  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
141  $f_message = $this->umail->formatLinebreakMessage($f_message);
142 
143  $this->umail->setSaveInSentbox(true);
144 
145  $m_type = isset($_POST["m_type"]) ? $_POST["m_type"] : array("normal");
146 
147  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
148  if($errorMessage = $this->umail->sendMail(
151  ilUtil::securePlainString($_POST['rcp_bcc']),
152  ilUtil::securePlainString($_POST['m_subject']), $f_message,
153  $files,
154 // $_POST['m_type'],
155  $m_type,
156  ilUtil::securePlainString($_POST['use_placeholders'])
157  )
158  )
159  {
160  if(is_array($_POST['attachments']))
161  {
162  foreach($_POST['attachments'] as $key => $value)
163  {
164  $_POST['attachments'][$key] = urldecode($value);
165  }
166  }
167  ilUtil::sendInfo($errorMessage);
168  }
169  else
170  {
171  $this->umail->savePostData($ilUser->getId(), array(), "", "", "", "", "", "", "", "");
172 
173  #$this->ctrl->setParameterByClass("ilmailfoldergui", "mobj_id", $this->mbox->getSentFolder());
174  $this->ctrl->setParameterByClass('ilmailgui', 'type', 'message_sent');
175 
177  {
178  ilUtil::sendInfo($this->lng->txt('mail_message_send'), true);
180  }
181  else
182  $this->ctrl->redirectByClass('ilmailgui');
183  }
184 
185  $this->showForm();
186  }
187 
188  public function saveDraft()
189  {
190  if(!$_POST['m_subject'])
191  {
192  $_POST['m_subject'] = 'No title';
193  }
194 
195  $draftsId = $this->mbox->getDraftsFolder();
196 
197  // decode post values
198  $files = array();
199  if(is_array($_POST['attachments']))
200  {
201  foreach($_POST['attachments'] as $value)
202  {
203  $files[] = urldecode($value);
204  }
205  }
206 
207  if(isset($_SESSION["draft"]))
208  {
209  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
210  $this->umail->updateDraft($draftsId, $files,
213  ilUtil::securePlainString($_POST["rcp_bcc"]),
214  $_POST["m_type"],
215  ilUtil::securePlainString($_POST["m_email"]),
216  ilUtil::securePlainString($_POST["m_subject"]),
217  ilUtil::securePlainString($_POST["m_message"]),
218  $_SESSION["draft"],
219  ilUtil::securePlainString($_POST['use_placeholders'])
220  );
221  #session_unregister("draft");
222  #ilUtil::sendInfo($this->lng->txt("mail_saved"),true);
223  #ilUtil::redirect("ilias.php?baseClass=ilMailGUI&mobj_id=".$mbox->getInboxFolder());
224 
225  unset($_SESSION["draft"]);
226  ilUtil::sendInfo($this->lng->txt("mail_saved"), true);
227 
230  else
231  $this->ctrl->redirectByClass("ilmailfoldergui");
232  }
233  else
234  {
235  if ($this->umail->sendInternalMail($draftsId,$_SESSION["AccountId"],$files,
236  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
239  ilUtil::securePlainString($_POST["rcp_bcc"]),
240  'read',
241  $_POST["m_type"],
242  ilUtil::securePlainString($_POST["m_email"]),
243  ilUtil::securePlainString($_POST["m_subject"]),
244  ilUtil::securePlainString($_POST["m_message"]),
245  $_SESSION["AccountId"],
246  ilUtil::securePlainString($_POST['use_placeholders'])
247  )
248  )
249  {
250  ilUtil::sendInfo($this->lng->txt("mail_saved"),true);
251  #$this->ctrl->setParameterByClass("ilmailfoldergui", "mobj_id", $this->mbox->getDraftsFolder());
252 
255  else
256  $this->ctrl->redirectByClass("ilmailfoldergui");
257  }
258  else
259  {
260  ilUtil::sendInfo($this->lng->txt("mail_send_error"));
261  }
262  }
263 
264  $this->showForm();
265  }
266 
267  public function searchRcpTo()
268  {
269  $_SESSION["mail_search"] = 'to';
270  ilUtil::sendInfo($this->lng->txt("mail_insert_query"));
271 
272  $this->showSearchForm();
273  }
274 
275  public function searchUsers($save = true)
276  {
277  global $ilUser, $ilCtrl;
278 
279  $this->tpl->setVariable("HEADER", $this->lng->txt("mail"));
280 
281  if ($save)
282  {
283  // decode post values
284  $files = array();
285  if(is_array($_POST['attachments']))
286  {
287  foreach($_POST['attachments'] as $value)
288  {
289  $files[] = urldecode($value);
290  }
291  }
292 
293  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
294  $this->umail->savePostData($ilUser->getId(),
295  $files,
298  ilUtil::securePlainString($_POST["rcp_bcc"]),
299  $_POST["m_type"],
300  ilUtil::securePlainString($_POST["m_email"]),
301  ilUtil::securePlainString($_POST["m_subject"]),
302  ilUtil::securePlainString($_POST["m_message"]),
303  ilUtil::securePlainString($_POST['use_placeholders'])
304  );
305  }
306  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
307  $form = new ilPropertyFormGUI();
308  $form->setId('search_rcp');
309  $form->setTitle($this->lng->txt('search_recipients'));
310  $form->setFormAction($ilCtrl->getFormAction($this, 'search'));
311 
312  $inp = new ilTextInputGUI($this->lng->txt("search_for"), 'search');
313  $inp->setSize(30);
314  if (strlen(trim($_SESSION["mail_search_search"])) > 0)
315  {
316  $inp->setValue(ilUtil::prepareFormOutput(trim($_SESSION["mail_search_search"]), true));
317  }
318  $form->addItem($inp);
319 
320  $chb = new ilCheckboxInputGUI($this->lng->txt("mail_search_addressbook"), 'type_addressbook');
321  if ($_SESSION['mail_search_type_addressbook'])
322  $chb->setChecked(true);
323  $inp->addSubItem($chb);
324 
325  $chb = new ilCheckboxInputGUI($this->lng->txt("mail_search_system"), 'type_system');
326  if ($_SESSION['mail_search_type_system'])
327  $chb->setChecked(true);
328  $inp->addSubItem($chb);
329 
330  $form->addCommandButton('search', $this->lng->txt("search"));
331  $form->addCommandButton('cancelSearch', $this->lng->txt("cancel"));
332 
333  $this->tpl->setContent($form->getHtml());
334  $this->tpl->show();
335  }
336 
337  public function searchCoursesTo()
338  {
339  global $ilUser;
340 
341  // decode post values
342  $files = array();
343  if(is_array($_POST['attachments']))
344  {
345  foreach($_POST['attachments'] as $value)
346  {
347  $files[] = urldecode($value);
348  }
349  }
350 
351  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
352  $this->umail->savePostData($ilUser->getId(),
353  $files,
356  ilUtil::securePlainString($_POST["rcp_bcc"]),
357  $_POST["m_type"],
358  ilUtil::securePlainString($_POST["m_email"]),
359  ilUtil::securePlainString($_POST["m_subject"]),
360  ilUtil::securePlainString($_POST["m_message"]),
361  ilUtil::securePlainString($_POST['use_placeholders'])
362  );
363 
364  if ($_SESSION["search_crs"])
365  {
366  $this->ctrl->setParameterByClass("ilmailsearchcoursesgui", "cmd", "showMembers");
367  }
368  $this->ctrl->setParameterByClass("ilmailsearchcoursesgui", "ref", "mail");
369  $this->ctrl->redirectByClass("ilmailsearchcoursesgui");
370  }
371 
372  public function searchGroupsTo()
373  {
374  global $ilUser;
375 
376  // decode post values
377  $files = array();
378  if(is_array($_POST['attachments']))
379  {
380  foreach($_POST['attachments'] as $value)
381  {
382  $files[] = urldecode($value);
383  }
384  }
385 
386  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
387  $this->umail->savePostData($ilUser->getId(),
388  $files,
391  ilUtil::securePlainString($_POST["rcp_bcc"]),
392  $_POST["m_type"],
393  ilUtil::securePlainString($_POST["m_email"]),
394  ilUtil::securePlainString($_POST["m_subject"]),
395  ilUtil::securePlainString($_POST["m_message"]),
396  ilUtil::securePlainString($_POST['use_placeholders'])
397  );
398 
399  $this->ctrl->setParameterByClass("ilmailsearchgroupsgui", "ref", "mail");
400  $this->ctrl->redirectByClass("ilmailsearchgroupsgui");
401  }
402 
403  public function searchRcpCc()
404  {
405  $_SESSION["mail_search"] = 'cc';
406  ilUtil::sendInfo($this->lng->txt("mail_insert_query"));
407 
408  $this->showSearchForm();
409  }
410 
411  public function searchRcpBc()
412  {
413  $_SESSION["mail_search"] = 'bc';
414  ilUtil::sendInfo($this->lng->txt("mail_insert_query"));
415 
416  $this->showSearchForm();
417  }
418 
419  public function showSearchForm()
420  {
421  global $ilUser;
422 
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"));
427 
428  if ($pref = $ilUser->getPref("mail_search"))
429  {
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\"");
432  }
433  else
434  {
435  $this->tpl->setVariable("SEARCH_SYSTEM_CHECKED", "checked=\"checked\"");
436  }
437 
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)
441  {
442  $this->tpl->setVariable("VALUE_SEARCH_FOR", ilUtil::prepareFormOutput(trim($_POST["search"]), true));
443  }
444  $this->tpl->parseCurrentBlock();
445 
446  $this->showForm();
447  }
448 
449  public function search()
450  {
451  global $ilUser;
452 
453  $_SESSION["mail_search_search"] = $_POST["search"];
454  $_SESSION["mail_search_type_system"] = $_POST["type_system"];
455  $_SESSION["mail_search_type_addressbook"] = $_POST["type_addressbook"];
456 
457  // IF NO TYPE IS GIVEN SEARCH IN BOTH 'system' and 'addressbook'
458  if(!$_SESSION["mail_search_type_system"] &&
459  !$_SESSION["mail_search_type_addressbook"])
460  {
461  $_SESSION["mail_search_type_system"] = 1;
462  $_SESSION["mail_search_type_addressbook"] = 1;
463  $ilUser->writePref("mail_search", "all");
464  }
465  if (strlen(trim($_SESSION["mail_search_search"])) == 0)
466  {
467  ilUtil::sendInfo($this->lng->txt("mail_insert_query"));
468  #$this->showSearchForm();
469  $this->searchUsers(false);
470  }
471  else if(strlen(trim($_SESSION["mail_search_search"])) < 3)
472  {
473  $this->lng->loadLanguageModule('search');
474  ilUtil::sendInfo($this->lng->txt('search_minimum_three'));
475  #$this->showSearchForm();
476  $this->searchUsers(false);
477  }
478  else
479  {
480  $this->ctrl->setParameterByClass("ilmailsearchgui", "search", urlencode($_SESSION["mail_search_search"]));
481  if($_SESSION["mail_search_type_system"])
482  {
483  $this->ctrl->setParameterByClass("ilmailsearchgui", "system", 1);
484  }
485  if($_SESSION["mail_search_type_addressbook"])
486  {
487  $this->ctrl->setParameterByClass("ilmailsearchgui", "addressbook", 1);
488  }
489  $this->ctrl->redirectByClass("ilmailsearchgui");
490  }
491  }
492 
493  public function cancelSearch()
494  {
495  unset($_SESSION["mail_search"]);
496 
497  #$this->showForm();
498  $this->searchResults();
499  }
500 
501  public function editAttachments()
502  {
503  // decode post values
504  $files = array();
505  if(is_array($_POST['attachments']))
506  {
507  foreach($_POST['attachments'] as $value)
508  {
509  $files[] = urldecode($value);
510  }
511  }
512 
513  // Note: For security reasons, ILIAS only allows Plain text messages.
514  $this->umail->savePostData($_SESSION["AccountId"],
515  $files,
518  ilUtil::securePlainString($_POST["rcp_bcc"]),
519  $_POST["m_type"],
520  ilUtil::securePlainString($_POST["m_email"]),
521  ilUtil::securePlainString($_POST["m_subject"]),
522  ilUtil::securePlainString($_POST["m_message"]),
523  ilUtil::securePlainString($_POST['use_placeholders'])
524  );
525 
526  $this->ctrl->redirectByClass("ilmailattachmentgui");
527  }
528 
529  public function returnFromAttachments()
530  {
531  $_GET["type"] = "attach";
532  $this->showForm();
533  }
534 
535  public function searchResults()
536  {
537  $_GET["type"] = "search_res";
538  $this->showForm();
539  }
540 
541  public function mailUser()
542  {
543  $_GET["type"] = "new";
544  $this->showForm();
545  }
546 
547  public function mailRole()
548  {
549  $_GET["type"] = "role";
550  $this->showForm();
551  }
552 
553  public function replyMail()
554  {
555  $_GET["type"] = "reply";
556  $this->showForm();
557  }
558 
559  public function mailAttachment()
560  {
561  $_GET["type"] = "attach";
562  $this->showForm();
563  }
564 
565  public function showForm()
566  {
567  global $rbacsystem, $ilUser, $ilCtrl, $lng, $ilTabs;
568 
569  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_new.html", "Services/Mail");
570  $this->tpl->setVariable("HEADER", $this->lng->txt("mail"));
571 
572  $this->lng->loadLanguageModule("crs");
573 
575  $ilTabs->setBackTarget($lng->txt('back'), $ilCtrl->getLinkTarget($this, 'cancelMail'));
576 
577  switch($_GET["type"])
578  {
579  case 'reply':
580  if($_SESSION['mail_id'])
581  {
582  $_GET['mail_id'] = $_SESSION['mail_id'];
583  }
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();
588  // NO ATTACHMENTS FOR REPLIES
589  $mailData["attachments"] = array();
590  //$mailData["rcp_cc"] = $this->umail->formatReplyRecipientsForCC();
591  $mailData["rcp_cc"] = '';
592  $mailData["rcp_to"] = $this->umail->formatReplyRecipient();
593  $_SESSION["mail_id"] = "";
594  break;
595 
596  case 'search_res':
597  $mailData = $this->umail->getSavedData();
598 
599  /*if($_SESSION["mail_search_results"])
600  {
601  $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results"],$_SESSION["mail_search"]);
602  }
603  unset($_SESSION["mail_search"]);
604  unset($_SESSION["mail_search_results"]);*/
605 
606  if($_SESSION["mail_search_results_to"])
607  {
608  $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_to"], 'to');
609  }
610  if($_SESSION["mail_search_results_cc"])
611  {
612  $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_cc"], 'cc');
613  }
614  if($_SESSION["mail_search_results_bcc"])
615  {
616  $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_bcc"], 'bc');
617  }
618 
619  unset($_SESSION["mail_search_results_to"]);
620  unset($_SESSION["mail_search_results_cc"]);
621  unset($_SESSION["mail_search_results_bcc"]);
622 
623  break;
624 
625  case 'attach':
626  $mailData = $this->umail->getSavedData();
627  break;
628 
629  case 'draft':
630  $_SESSION["draft"] = $_GET["mail_id"];
631  $mailData = $this->umail->getMail($_GET["mail_id"]);
632  break;
633 
634  case 'forward':
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"]))
640  {
641  if($error = $this->mfile->adoptAttachments($mailData["attachments"],$_GET["mail_id"]))
642  {
644  }
645  }
646  break;
647 
648  case 'new':
649  if($_GET['rcp_to'])
650  {
651  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
652  $mailData["rcp_to"] = ilUtil::securePlainString($_GET['rcp_to']);
653  }
654  else if($_SESSION['rcp_to'])
655  {
656  $mailData["rcp_to"] = $_SESSION['rcp_to'];
657  }
658  if($_GET['rcp_cc'])
659  {
660  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
661  $mailData["rcp_cc"] = ilUtil::securePlainString($_GET['rcp_cc']);
662  }
663  else if($_SESSION['rcp_cc'])
664  {
665  $mailData["rcp_cc"] = $_SESSION['rcp_cc'];
666  }
667  if($_GET['rcp_bcc'])
668  {
669  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
670  $mailData["rcp_bcc"] = ilUtil::securePlainString($_GET['rcp_bcc']);
671  }
672  else if($_SESSION['rcp_bcc'])
673  {
674  $mailData["rcp_bcc"] = $_SESSION['rcp_bcc'];
675  }
676  $mailData['m_message'] = '';
677  if(strlen($sig = ilMailFormCall::_getSignature()))
678  {
679  $mailData['m_message'] = $sig;
680  $mailData['m_message'] .= chr(13).chr(10).chr(13).chr(10);
681  }
682  $mailData['m_message'] .= $this->umail->appendSignature();
683 
684  $_SESSION['rcp_to'] = '';
685  $_SESSION['rcp_cc'] = '';
686  $_SESSION['rcp_bcc'] = '';
687  break;
688 
689  case 'role':
690 
691  if(is_array($_POST['roles']))
692  {
693  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
694  $mailData['rcp_to'] = ilUtil::securePlainString(implode(',',$_POST['roles']));
695  }
696  elseif(is_array($_SESSION['mail_roles']))
697  {
698  $mailData['rcp_to'] = ilUtil::securePlainString(implode(',', $_SESSION['mail_roles']));
699  }
700 
701  $mailData['m_message'] = '';
702  if(strlen($sig = ilMailFormCall::_getSignature()))
703  {
704  $mailData['m_message'] = $sig;
705  $mailData['m_message'] .= chr(13).chr(10).chr(13).chr(10);
706  }
707 
708  $mailData['m_message'] .= $_POST["additional_message_text"].chr(13).chr(10).$this->umail->appendSignature();
709  $_POST["additional_message_text"] = "";
710  $_SESSION['mail_roles'] = "";
711  break;
712 
713  case 'address':
714  $mailData["rcp_to"] = urldecode($_GET["rcp"]);
715  break;
716 
717  default:
718  // GET DATA FROM POST
719  $mailData = $_POST;
720 
721  // strip slashes
722  foreach ($mailData as $key => $value)
723  {
724  if (is_string($value))
725  {
726  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
727  $mailData[$key] = ilUtil::securePlainString($value);
728  }
729  }
730  break;
731  }
732 
733  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
734 
735  $form_gui = new ilPropertyFormGUI();
736  $form_gui->setTitle($this->lng->txt('compose'));
737  $form_gui->setOpenTag(false);
738  $this->tpl->setVariable('FORM_ACTION', $this->ctrl->getFormAction($this, 'sendMessage'));
739 
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"));
743 
744  //$dsSchema = array('response.results', 'login', 'firstname', 'lastname');
745  $dsSchema = array("resultsList" => 'response.results',
746  "fields" => array('login', 'firstname', 'lastname'));
747 
748  $dsFormatCallback = 'formatAutoCompleteResults';
749  $dsDataLink = $ilCtrl->getLinkTarget($this, 'lookupRecipientAsync', '', '', false);
750  $dsDelimiter = array(',');
751 
752  // RECIPIENT
753  $inp = new ilTextInputGUI($this->lng->txt('mail_to'), 'rcp_to');
754  $inp->setRequired(true);
755  $inp->setSize(50);
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);
763 
764  // CC
765  $inp = new ilTextInputGUI($this->lng->txt('cc'), 'rcp_cc');
766  $inp->setSize(50);
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);
774 
775  // BCC
776  $inp = new ilTextInputGUI($this->lng->txt('bc'), 'rcp_bcc');
777  $inp->setSize(50);
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);
785 
786  // SUBJECT
787  $inp = new ilTextInputGUI($this->lng->txt('subject'), 'm_subject');
788  $inp->setSize(50);
789  $inp->setRequired(true);
790  $inp->setValue($mailData["m_subject"]);
791  $form_gui->addItem($inp);
792 
793  // Attachments
794  include_once 'Services/Mail/classes/class.ilMailFormAttachmentFormPropertyGUI.php';
795  $att = new ilMailFormAttachmentPropertyGUI($this->lng->txt( ($mailData["attachments"]) ? 'edit' : 'add' ));
796 
797 
798  if (is_array($mailData["attachments"]) && count($mailData["attachments"]))
799  {
800  foreach($mailData["attachments"] as $key => $data)
801  {
802  $hidden = new ilHiddenInputGUI('attachments[]');
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);
809  }
810  }
811  $form_gui->addItem($att);
812 
813  // ONLY IF SYSTEM MAILS ARE ALLOWED
814  if($rbacsystem->checkAccess("system_message",$this->umail->getMailObjectReferenceId()))
815  {
816  $chb = new ilCheckboxInputGUI($this->lng->txt('type'), 'm_type[]');
817  $chb->setOptionTitle($this->lng->txt('system_message'));
818  $chb->setValue('system');
819  $chb->setChecked(false);
820  if(is_array($mailData["m_type"]) and in_array('system',$mailData["m_type"]))
821  {
822  $chb->setChecked(true);
823  }
824  $form_gui->addItem($chb);
825  }
826 
827 
828  // MESSAGE
829  $inp = new ilTextAreaInputGUI($this->lng->txt('message_content'), 'm_message');
830  //$inp->setValue(htmlspecialchars($mailData["m_message"], false));
831  $inp->setValue($mailData["m_message"]);
832  $inp->setRequired(false);
833  $inp->setCols(60);
834  $inp->setRows(10);
835 
836  // PLACEHOLDERS
837  $chb = new ilCheckboxInputGUI($this->lng->txt('activate_serial_letter_placeholders'), 'use_placeholders');
838  $chb->setOptionTitle($this->lng->txt('activate_serial_letter_placeholders'));
839  $chb->setValue(1);
840  $chb->setChecked(false);
841  $form_gui->addItem($inp);
842 
843  include_once 'Services/Mail/classes/class.ilMailFormPlaceholdersPropertyGUI.php';
844  $prop = new ilMailFormPlaceholdersPropertyGUI();
845 
846  $chb->addSubItem($prop);
847 
848  if ($mailData['use_placeholders'])
849  {
850  $chb->setChecked(true);
851  }
852 
853  $form_gui->addItem($chb);
854 
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'));
859 
860  $this->tpl->parseCurrentBlock();
861 
862  $this->tpl->setVariable('FORM', $form_gui->getHTML());
863 
864  $this->tpl->addJavaScript('Services/Mail/js/ilMailComposeFunctions.js');
865  $this->tpl->show();
866  }
867 
868  public function lookupRecipientAsync()
869  {
870  global $ilUser, $rbacsystem;
871  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
872  include_once 'Services/Mail/classes/class.ilMailForm.php';
873 
874  $search = $_REQUEST["query"];
875  $result = new stdClass();
876  $result->response = new stdClass();
877  $result->response->results = array();
878  if (!$search)
879  {
880  $result->response->total = 0;
881  echo ilJsonUtil::encode($result);
882  exit;
883  }
884 
885  $mailFormObj = new ilMailForm;
886  $result = $mailFormObj->getRecipientAsync("%" .$search. "%", $search);
887 
888  echo ilJsonUtil::encode($result);
889  exit;
890  }
891 
892  public function cancelMail()
893  {
896  else
897  return $this->showForm();
898  }
899 }
900 ?>