ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMailFormGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
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';
9 
18 {
19  private $tpl = null;
20  private $ctrl = null;
21  private $lng = null;
22 
23  private $umail = null;
24  private $mbox = null;
25  private $mfile = null;
26 
27  public function __construct()
28  {
29  global $tpl, $ilCtrl, $lng, $ilUser;
30 
31  $this->tpl = $tpl;
32  $this->ctrl = $ilCtrl;
33  $this->lng = $lng;
34 
35  $this->umail = new ilFormatMail($ilUser->getId());
36  $this->mfile = new ilFileDataMail($ilUser->getId());
37  $this->mbox = new ilMailBox($ilUser->getId());
38 
39  if(isset($_POST['mobj_id']) && (int)$_POST['mobj_id'])
40  {
41  $_GET['mobj_id'] = $_POST['mobj_id'];
42  }
43  // IF THERE IS NO OBJ_ID GIVEN GET THE ID OF MAIL ROOT NODE
44  if(!(int)$_GET['mobj_id'])
45  {
46  $_GET['mobj_id'] = $this->mbox->getInboxFolder();
47  }
48  $_GET['mobj_id'] = (int)$_GET['mobj_id'];
49  $this->ctrl->saveParameter($this, 'mobj_id');
50  }
51 
52  public function executeCommand()
53  {
54  $forward_class = $this->ctrl->getNextClass($this);
55  switch($forward_class)
56  {
57  case 'ilmailfoldergui':
58  include_once 'Services/Mail/classes/class.ilMailFolderGUI.php';
59 
60  $this->ctrl->forwardCommand(new ilMailFolderGUI());
61  break;
62 
63  case 'ilmailattachmentgui':
64  include_once 'Services/Mail/classes/class.ilMailAttachmentGUI.php';
65 
66  $this->ctrl->setReturn($this, "returnFromAttachments");
67  $this->ctrl->forwardCommand(new ilMailAttachmentGUI());
68  break;
69 
70  case 'ilmailsearchgui':
71  include_once 'Services/Contact/classes/class.ilMailSearchGUI.php';
72 
73  $this->ctrl->setReturn($this, "searchResults");
74  $this->ctrl->forwardCommand(new ilMailSearchGUI());
75  break;
76 
77  case 'ilmailsearchcoursesgui':
78  include_once 'Services/Contact/classes/class.ilMailSearchCoursesGUI.php';
79 
80  $this->ctrl->setReturn($this, "searchResults");
81  $this->ctrl->forwardCommand(new ilMailSearchCoursesGUI());
82  break;
83 
84  case 'ilmailinglistsgui':
85  include_once 'Services/Contact/classes/class.ilMailingListsGUI.php';
86 
87  $this->ctrl->setReturn($this, 'searchResults');
88  $this->ctrl->forwardCommand(new ilMailingListsGUI());
89  break;
90 
91  case 'ilmailsearchgroupsgui':
92  include_once 'Services/Contact/classes/class.ilMailSearchGroupsGUI.php';
93 
94  $this->ctrl->setReturn($this, "searchResults");
95  $this->ctrl->forwardCommand(new ilMailSearchGroupsGUI());
96  break;
97 
98  default:
99  if (!($cmd = $this->ctrl->getCmd()))
100  {
101  $cmd = "showForm";
102  }
103 
104  $this->$cmd();
105  break;
106  }
107  return true;
108  }
109 
110  public function sendMessage()
111  {
112  global $ilUser;
113 
114  // decode post values
115  $files = array();
116  if(is_array($_POST['attachments']))
117  {
118  foreach($_POST['attachments'] as $value)
119  {
120  if(is_file($this->mfile->getMailPath() . '/' . $ilUser->getId() . "_" . urldecode($value)))
121  {
122  $files[] = urldecode($value);
123  }
124  }
125  }
126 
127  // Remove \r
128  $f_message = str_replace("\r", '', ilUtil::securePlainString($_POST['m_message']));
129 
130  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
131  $f_message = $this->umail->formatLinebreakMessage($f_message);
132 
133  $this->umail->setSaveInSentbox(true);
134 
135  $m_type = isset($_POST["m_type"]) ? $_POST["m_type"] : array("normal");
136 
137  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
138  if($errorMessage = $this->umail->sendMail(
141  ilUtil::securePlainString($_POST['rcp_bcc']),
142  ilUtil::securePlainString($_POST['m_subject']), $f_message,
143  $files,
144 // $_POST['m_type'],
145  $m_type,
146  ilUtil::securePlainString($_POST['use_placeholders'])
147  )
148  )
149  {
150  if(is_array($_POST['attachments']))
151  {
152  foreach($_POST['attachments'] as $key => $value)
153  {
154  if(is_file($this->mfile->getMailPath() . '/' . $ilUser->getId() . "_" . urldecode($value)))
155  {
156  $_POST['attachments'][$key] = urldecode($value);
157  }
158  else
159  {
160  unset($_POST['attachments'][$key]);
161  }
162  }
163  }
164  ilUtil::sendInfo($errorMessage);
165  }
166  else
167  {
168  $this->umail->savePostData($ilUser->getId(), array(), "", "", "", "", "", "", "", "");
169 
170  $this->ctrl->setParameterByClass('ilmailgui', 'type', 'message_sent');
171 
173  {
174  ilUtil::sendInfo($this->lng->txt('mail_message_send'), true);
176  }
177  else
178  $this->ctrl->redirectByClass('ilmailgui');
179  }
180 
181  $this->showForm();
182  }
183 
184  public function saveDraft()
185  {
186  if(!$_POST['m_subject'])
187  {
188  $_POST['m_subject'] = 'No title';
189  }
190 
191  $draftsId = $this->mbox->getDraftsFolder();
192 
193  // decode post values
194  $files = array();
195  if(is_array($_POST['attachments']))
196  {
197  foreach($_POST['attachments'] as $value)
198  {
199  $files[] = urldecode($value);
200  }
201  }
202 
203  if(isset($_SESSION["draft"]))
204  {
205  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
206  $this->umail->updateDraft($draftsId, $files,
209  ilUtil::securePlainString($_POST["rcp_bcc"]),
210  $_POST["m_type"],
211  ilUtil::securePlainString($_POST["m_email"]),
212  ilUtil::securePlainString($_POST["m_subject"]),
213  ilUtil::securePlainString($_POST["m_message"]),
214  (int)$_SESSION["draft"],
215  (int)ilUtil::securePlainString($_POST['use_placeholders'])
216  );
217  #session_unregister("draft");
218  #ilUtil::sendInfo($this->lng->txt("mail_saved"),true);
219  #ilUtil::redirect("ilias.php?baseClass=ilMailGUI&mobj_id=".$mbox->getInboxFolder());
220 
221  unset($_SESSION["draft"]);
222  ilUtil::sendInfo($this->lng->txt("mail_saved"), true);
223 
226  else
227  $this->ctrl->redirectByClass("ilmailfoldergui");
228  }
229  else
230  {
231  if ($this->umail->sendInternalMail($draftsId,$_SESSION["AccountId"],$files,
232  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
235  ilUtil::securePlainString($_POST["rcp_bcc"]),
236  'read',
237  $_POST["m_type"],
238  ilUtil::securePlainString($_POST["m_email"]),
239  ilUtil::securePlainString($_POST["m_subject"]),
240  ilUtil::securePlainString($_POST["m_message"]),
241  $_SESSION["AccountId"],
242  ilUtil::securePlainString($_POST['use_placeholders'])
243  )
244  )
245  {
246  ilUtil::sendInfo($this->lng->txt("mail_saved"),true);
247  #$this->ctrl->setParameterByClass("ilmailfoldergui", "mobj_id", $this->mbox->getDraftsFolder());
248 
251  else
252  $this->ctrl->redirectByClass("ilmailfoldergui");
253  }
254  else
255  {
256  ilUtil::sendInfo($this->lng->txt("mail_send_error"));
257  }
258  }
259 
260  $this->showForm();
261  }
262 
263  public function searchRcpTo()
264  {
265  $_SESSION["mail_search"] = 'to';
266  ilUtil::sendInfo($this->lng->txt("mail_insert_query"));
267 
268  $this->showSearchForm();
269  }
270 
271  public function searchUsers($save = true)
272  {
273  global $ilUser, $ilCtrl;
274 
275  $this->tpl->setTitle($this->lng->txt("mail"));
276 
277  if ($save)
278  {
279  // decode post values
280  $files = array();
281  if(is_array($_POST['attachments']))
282  {
283  foreach($_POST['attachments'] as $value)
284  {
285  $files[] = urldecode($value);
286  }
287  }
288 
289  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
290  $this->umail->savePostData($ilUser->getId(),
291  $files,
294  ilUtil::securePlainString($_POST["rcp_bcc"]),
295  $_POST["m_type"],
296  ilUtil::securePlainString($_POST["m_email"]),
297  ilUtil::securePlainString($_POST["m_subject"]),
298  ilUtil::securePlainString($_POST["m_message"]),
299  ilUtil::securePlainString($_POST['use_placeholders'])
300  );
301  }
302  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
303  $form = new ilPropertyFormGUI();
304  $form->setId('search_rcp');
305  $form->setTitle($this->lng->txt('search_recipients'));
306  $form->setFormAction($ilCtrl->getFormAction($this, 'search'));
307 
308  $inp = new ilTextInputGUI($this->lng->txt("search_for"), 'search');
309  $inp->setSize(30);
310  $dsDataLink = $ilCtrl->getLinkTarget($this, 'lookupRecipientAsync', '', true);
311  $inp->setDataSource($dsDataLink);
312 
313  if (strlen(trim($_SESSION["mail_search_search"])) > 0)
314  {
315  $inp->setValue(ilUtil::prepareFormOutput(trim($_SESSION["mail_search_search"]), true));
316  }
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 
340  public function searchCoursesTo()
341  {
342  $this->saveMailBeforeSearch();
343 
344  if($_SESSION['search_crs'])
345  {
346  $this->ctrl->setParameterByClass('ilmailsearchcoursesgui', 'cmd', 'showMembers');
347  }
348 
349  $this->ctrl->setParameterByClass('ilmailsearchcoursesgui', 'ref', 'mail');
350  $this->ctrl->redirectByClass('ilmailsearchcoursesgui');
351  }
352 
356  public function searchGroupsTo()
357  {
358  $this->saveMailBeforeSearch();
359 
360  $this->ctrl->setParameterByClass('ilmailsearchgroupsgui', 'ref', 'mail');
361  $this->ctrl->redirectByClass('ilmailsearchgroupsgui');
362  }
363 
364  public function searchRcpCc()
365  {
366  $_SESSION["mail_search"] = 'cc';
367  ilUtil::sendInfo($this->lng->txt("mail_insert_query"));
368 
369  $this->showSearchForm();
370  }
371 
372  public function searchRcpBc()
373  {
374  $_SESSION["mail_search"] = 'bc';
375  ilUtil::sendInfo($this->lng->txt("mail_insert_query"));
376 
377  $this->showSearchForm();
378  }
379 
380  public function showSearchForm()
381  {
382  global $ilUser;
383 
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"));
388 
389  if ($pref = $ilUser->getPref("mail_search"))
390  {
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\"");
393  }
394  else
395  {
396  $this->tpl->setVariable("SEARCH_SYSTEM_CHECKED", "checked=\"checked\"");
397  }
398 
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)
402  {
403  $this->tpl->setVariable("VALUE_SEARCH_FOR", ilUtil::prepareFormOutput(trim($_POST["search"]), true));
404  }
405  $this->tpl->parseCurrentBlock();
406 
407  $this->showForm();
408  }
409 
410  public function search()
411  {
412  global $ilUser;
413 
414  $_SESSION["mail_search_search"] = $_POST["search"];
415  $_SESSION["mail_search_type_system"] = $_POST["type_system"];
416  $_SESSION["mail_search_type_addressbook"] = $_POST["type_addressbook"];
417 
418  if (strlen(trim($_SESSION["mail_search_search"])) == 0)
419  {
420  ilUtil::sendInfo($this->lng->txt("mail_insert_query"));
421  #$this->showSearchForm();
422  $this->searchUsers(false);
423  }
424  else if(strlen(trim($_SESSION["mail_search_search"])) < 3)
425  {
426  $this->lng->loadLanguageModule('search');
427  ilUtil::sendInfo($this->lng->txt('search_minimum_three'));
428  #$this->showSearchForm();
429  $this->searchUsers(false);
430  }
431  else
432  {
433  $this->ctrl->setParameterByClass("ilmailsearchgui", "search", urlencode($_SESSION["mail_search_search"]));
434  if($_SESSION["mail_search_type_system"])
435  {
436  $this->ctrl->setParameterByClass("ilmailsearchgui", "system", 1);
437  }
438  if($_SESSION["mail_search_type_addressbook"])
439  {
440  $this->ctrl->setParameterByClass("ilmailsearchgui", "addressbook", 1);
441  }
442  $this->ctrl->redirectByClass("ilmailsearchgui");
443  }
444  }
445 
446  public function cancelSearch()
447  {
448  unset($_SESSION["mail_search"]);
449 
450  #$this->showForm();
451  $this->searchResults();
452  }
453 
454  public function editAttachments()
455  {
456  // decode post values
457  $files = array();
458  if(is_array($_POST['attachments']))
459  {
460  foreach($_POST['attachments'] as $value)
461  {
462  $files[] = urldecode($value);
463  }
464  }
465 
466  // Note: For security reasons, ILIAS only allows Plain text messages.
467  $this->umail->savePostData($_SESSION["AccountId"],
468  $files,
471  ilUtil::securePlainString($_POST["rcp_bcc"]),
472  $_POST["m_type"],
473  ilUtil::securePlainString($_POST["m_email"]),
474  ilUtil::securePlainString($_POST["m_subject"]),
475  ilUtil::securePlainString($_POST["m_message"]),
476  ilUtil::securePlainString($_POST['use_placeholders'])
477  );
478 
479  $this->ctrl->redirectByClass("ilmailattachmentgui");
480  }
481 
482  public function returnFromAttachments()
483  {
484  $_GET["type"] = "attach";
485  $this->showForm();
486  }
487 
488  public function searchResults()
489  {
490  $_GET["type"] = "search_res";
491  $this->showForm();
492  }
493 
494  public function mailUser()
495  {
496  $_GET["type"] = "new";
497  $this->showForm();
498  }
499 
500  public function mailRole()
501  {
502  $_GET["type"] = "role";
503  $this->showForm();
504  }
505 
506  public function replyMail()
507  {
508  $_GET["type"] = "reply";
509  $this->showForm();
510  }
511 
512  public function mailAttachment()
513  {
514  $_GET["type"] = "attach";
515  $this->showForm();
516  }
517 
518  public function showForm()
519  {
520  global $rbacsystem, $ilUser, $ilCtrl, $lng, $ilTabs;
521 
522  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_new.html", "Services/Mail");
523  $this->tpl->setTitle($this->lng->txt("mail"));
524 
525  $this->lng->loadLanguageModule("crs");
526 
528  $ilTabs->setBackTarget($lng->txt('back'), $ilCtrl->getLinkTarget($this, 'cancelMail'));
529 
530  switch($_GET["type"])
531  {
532  case 'reply':
533  if($_SESSION['mail_id'])
534  {
535  $_GET['mail_id'] = $_SESSION['mail_id'];
536  }
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();
541  // NO ATTACHMENTS FOR REPLIES
542  $mailData["attachments"] = array();
543  //$mailData["rcp_cc"] = $this->umail->formatReplyRecipientsForCC();
544  $mailData["rcp_cc"] = '';
545  $mailData["rcp_to"] = $this->umail->formatReplyRecipient();
546  $_SESSION["mail_id"] = "";
547  break;
548 
549  case 'search_res':
550  $mailData = $this->umail->getSavedData();
551 
552  /*if($_SESSION["mail_search_results"])
553  {
554  $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results"],$_SESSION["mail_search"]);
555  }
556  unset($_SESSION["mail_search"]);
557  unset($_SESSION["mail_search_results"]);*/
558 
559  if($_SESSION["mail_search_results_to"])
560  {
561  $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_to"], 'to');
562  }
563  if($_SESSION["mail_search_results_cc"])
564  {
565  $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_cc"], 'cc');
566  }
567  if($_SESSION["mail_search_results_bcc"])
568  {
569  $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_bcc"], 'bc');
570  }
571 
572  unset($_SESSION["mail_search_results_to"]);
573  unset($_SESSION["mail_search_results_cc"]);
574  unset($_SESSION["mail_search_results_bcc"]);
575 
576  break;
577 
578  case 'attach':
579  $mailData = $this->umail->getSavedData();
580  break;
581 
582  case 'draft':
583  $_SESSION["draft"] = $_GET["mail_id"];
584  $mailData = $this->umail->getMail($_GET["mail_id"]);
585  break;
586 
587  case 'forward':
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"]))
593  {
594  if($error = $this->mfile->adoptAttachments($mailData["attachments"],$_GET["mail_id"]))
595  {
596  ilUtil::sendInfo($error);
597  }
598  }
599  break;
600 
601  case 'new':
602  if($_GET['rcp_to'])
603  {
604  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
605  $mailData["rcp_to"] = ilUtil::securePlainString($_GET['rcp_to']);
606  }
607  else if($_SESSION['rcp_to'])
608  {
609  $mailData["rcp_to"] = $_SESSION['rcp_to'];
610  }
611  if($_GET['rcp_cc'])
612  {
613  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
614  $mailData["rcp_cc"] = ilUtil::securePlainString($_GET['rcp_cc']);
615  }
616  else if($_SESSION['rcp_cc'])
617  {
618  $mailData["rcp_cc"] = $_SESSION['rcp_cc'];
619  }
620  if($_GET['rcp_bcc'])
621  {
622  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
623  $mailData["rcp_bcc"] = ilUtil::securePlainString($_GET['rcp_bcc']);
624  }
625  else if($_SESSION['rcp_bcc'])
626  {
627  $mailData["rcp_bcc"] = $_SESSION['rcp_bcc'];
628  }
629  $mailData['m_message'] = '';
630  if(strlen($sig = ilMailFormCall::getSignature()))
631  {
632  $mailData['m_message'] = $sig;
633  $mailData['m_message'] .= chr(13).chr(10).chr(13).chr(10);
634  }
635  $mailData['m_message'] .= $this->umail->appendSignature();
636 
637  $_SESSION['rcp_to'] = '';
638  $_SESSION['rcp_cc'] = '';
639  $_SESSION['rcp_bcc'] = '';
640  break;
641 
642  case 'role':
643 
644  if(is_array($_POST['roles']))
645  {
646  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
647  $mailData['rcp_to'] = ilUtil::securePlainString(implode(',',$_POST['roles']));
648  }
649  elseif(is_array($_SESSION['mail_roles']))
650  {
651  $mailData['rcp_to'] = ilUtil::securePlainString(implode(',', $_SESSION['mail_roles']));
652  }
653 
654  $mailData['m_message'] = '';
655  if(strlen($sig = ilMailFormCall::getSignature()))
656  {
657  $mailData['m_message'] = $sig;
658  $mailData['m_message'] .= chr(13).chr(10).chr(13).chr(10);
659  }
660 
661  $mailData['m_message'] .= $_POST["additional_message_text"].chr(13).chr(10).$this->umail->appendSignature();
662  $_POST["additional_message_text"] = "";
663  $_SESSION['mail_roles'] = "";
664  break;
665 
666  case 'address':
667  $mailData["rcp_to"] = urldecode($_GET["rcp"]);
668  break;
669 
670  default:
671  // GET DATA FROM POST
672  $mailData = $_POST;
673 
674  // strip slashes
675  foreach ($mailData as $key => $value)
676  {
677  if (is_string($value))
678  {
679  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
680  $mailData[$key] = ilUtil::securePlainString($value);
681  }
682  }
683  break;
684  }
685 
686  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
687 
688  $form_gui = new ilPropertyFormGUI();
689  $form_gui->setTitle($this->lng->txt('compose'));
690  $form_gui->setOpenTag(false);
691  $this->tpl->setVariable('FORM_ACTION', $this->ctrl->getFormAction($this, 'sendMessage'));
692 
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"));
697 
698  $dsDataLink = $ilCtrl->getLinkTarget($this, 'lookupRecipientAsync', '', true);
699 
700  // RECIPIENT
701  $inp = new ilTextInputGUI($this->lng->txt('mail_to'), 'rcp_to');
702  $inp->setRequired(true);
703  $inp->setSize(50);
704  $inp->setValue($mailData["rcp_to"]);
705  $inp->setDataSource($dsDataLink);
706  $inp->setMaxLength(null);
707  $form_gui->addItem($inp);
708 
709  // CC
710  $inp = new ilTextInputGUI($this->lng->txt('cc'), 'rcp_cc');
711  $inp->setSize(50);
712  $inp->setValue($mailData["rcp_cc"]);
713  $inp->setDataSource($dsDataLink);
714  $inp->setMaxLength(null);
715  $form_gui->addItem($inp);
716 
717  // BCC
718  $inp = new ilTextInputGUI($this->lng->txt('bc'), 'rcp_bcc');
719  $inp->setSize(50);
720  $inp->setValue($mailData["rcp_bcc"]);
721  $inp->setDataSource($dsDataLink);
722  $inp->setMaxLength(null);
723  $form_gui->addItem($inp);
724 
725  // SUBJECT
726  $inp = new ilTextInputGUI($this->lng->txt('subject'), 'm_subject');
727  $inp->setSize(50);
728  $inp->setRequired(true);
729  $inp->setValue($mailData["m_subject"]);
730  $form_gui->addItem($inp);
731 
732  // Attachments
733  include_once 'Services/Mail/classes/class.ilMailFormAttachmentFormPropertyGUI.php';
734  $att = new ilMailFormAttachmentPropertyGUI($this->lng->txt( ($mailData["attachments"]) ? 'edit' : 'add' ));
735 
736 
737  if (is_array($mailData["attachments"]) && count($mailData["attachments"]))
738  {
739  foreach($mailData["attachments"] as $data)
740  {
741  if(is_file($this->mfile->getMailPath() . '/' . $ilUser->getId() . "_" . $data))
742  {
743  $hidden = new ilHiddenInputGUI('attachments[]');
744  $form_gui->addItem($hidden);
745  $size = filesize($this->mfile->getMailPath() . '/' . $ilUser->getId() . "_" . $data);
746  $label = $data . " [" . ilFormat::formatSize($size) . "]";
747  $att->addItem($label);
748  $hidden->setValue(urlencode($data));
749  }
750  }
751  }
752  $form_gui->addItem($att);
753 
754  // ONLY IF SYSTEM MAILS ARE ALLOWED
755  if($rbacsystem->checkAccess("system_message",$this->umail->getMailObjectReferenceId()))
756  {
757  $chb = new ilCheckboxInputGUI($this->lng->txt('type'), 'm_type[]');
758  $chb->setOptionTitle($this->lng->txt('system_message'));
759  $chb->setValue('system');
760  $chb->setChecked(false);
761  if(is_array($mailData["m_type"]) and in_array('system',$mailData["m_type"]))
762  {
763  $chb->setChecked(true);
764  }
765  $form_gui->addItem($chb);
766  }
767 
768 
769  // MESSAGE
770  $inp = new ilTextAreaInputGUI($this->lng->txt('message_content'), 'm_message');
771  //$inp->setValue(htmlspecialchars($mailData["m_message"], false));
772  $inp->setValue($mailData["m_message"]);
773  $inp->setRequired(false);
774  $inp->setCols(60);
775  $inp->setRows(10);
776 
777  // PLACEHOLDERS
778  $chb = new ilCheckboxInputGUI($this->lng->txt('activate_serial_letter_placeholders'), 'use_placeholders');
779  $chb->setOptionTitle($this->lng->txt('activate_serial_letter_placeholders'));
780  $chb->setValue(1);
781  $chb->setChecked(false);
782  $form_gui->addItem($inp);
783 
784  include_once 'Services/Mail/classes/class.ilMailFormPlaceholdersPropertyGUI.php';
785  $prop = new ilMailFormPlaceholdersPropertyGUI();
786 
787  $chb->addSubItem($prop);
788 
789  if ($mailData['use_placeholders'])
790  {
791  $chb->setChecked(true);
792  }
793 
794  $form_gui->addItem($chb);
795 
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'));
800 
801  $this->tpl->parseCurrentBlock();
802 
803  $this->tpl->setVariable('FORM', $form_gui->getHTML());
804 
805  $this->tpl->addJavaScript('Services/Mail/js/ilMailComposeFunctions.js');
806  $this->tpl->show();
807  }
808 
809  public function lookupRecipientAsync()
810  {
811  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
812  include_once 'Services/Mail/classes/class.ilMailForm.php';
813 
814  $search = $_REQUEST["term"];
815  $result = array();
816  if (!$search)
817  {
819  exit;
820  }
821 
822  // #14768
823  $quoted = $search;
824  $quoted = str_replace('%', '\%', $quoted);
825  $quoted = str_replace('_', '\_', $quoted);
826 
827  $mailFormObj = new ilMailForm;
828  $result = $mailFormObj->getRecipientAsync("%" .$quoted. "%", $search);
829 
831  exit;
832  }
833 
834  public function cancelMail()
835  {
838  else
839  return $this->showForm();
840  }
841 
845  protected function saveMailBeforeSearch()
846  {
850  global $ilUser;
851 
852  // decode post values
853  $files = array();
854  if(is_array($_POST['attachments']))
855  {
856  foreach($_POST['attachments'] as $value)
857  {
858  $files[] = urldecode($value);
859  }
860  }
861 
862  $this->umail->savePostData($ilUser->getId(),
863  $files,
866  ilUtil::securePlainString($_POST['rcp_bcc']),
867  $_POST['m_type'],
868  ilUtil::securePlainString($_POST['m_email']),
869  ilUtil::securePlainString($_POST['m_subject']),
870  ilUtil::securePlainString($_POST['m_message']),
871  ilUtil::securePlainString($_POST['use_placeholders'])
872  );
873  }
874 
878  public function searchMailingListsTo()
879  {
880  $this->saveMailBeforeSearch();
881 
882  $this->ctrl->setParameterByClass('ilmailinglistsgui', 'ref', 'mail');
883  $this->ctrl->redirectByClass('ilmailinglistsgui');
884  }
885 }