ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilMailFormGUI Class Reference
+ Collaboration diagram for ilMailFormGUI:

Public Member Functions

 __construct (\ilMailBodyPurifier $bodyPurifier=null)
 
 executeCommand ()
 
 sendMessage ()
 
 saveDraft ()
 
 searchUsers ($save=true)
 
 searchCoursesTo ()
 
 searchGroupsTo ()
 
 search ()
 
 cancelSearch ()
 
 editAttachments ()
 
 returnFromAttachments ()
 
 searchResults ()
 
 mailUser ()
 
 mailRole ()
 
 replyMail ()
 
 mailAttachment ()
 
 showForm ()
 
 lookupRecipientAsync ()
 
 cancelMail ()
 
 searchMailingListsTo ()
 

Protected Member Functions

 decodeAttachmentFiles (array $files)
 
 getTemplateDataById ()
 Called asynchronously when changing the template. More...
 
 saveMailBeforeSearch ()
 
 showSubmissionErrors (array $errors)
 

Private Attributes

 $tpl
 
 $ctrl
 
 $lng
 
 $user
 
 $tabs
 
 $toolbar
 
 $rbacsystem
 
 $umail
 
 $mbox
 
 $mfile
 
 $purifier
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilMailFormGUI::__construct ( \ilMailBodyPurifier  $bodyPurifier = null)
Parameters
ilMailBodyPurifier | null$bodyPurifier

Definition at line 77 of file class.ilMailFormGUI.php.

References $_GET, $_POST, $DIC, and user().

78  {
79  global $DIC;
80 
81  $this->tpl = $DIC->ui()->mainTemplate();
82  $this->ctrl = $DIC->ctrl();
83  $this->lng = $DIC->language();
84  $this->user = $DIC->user();
85  $this->tabs = $DIC->tabs();
86  $this->toolbar = $DIC->toolbar();
87  $this->rbacsystem = $DIC->rbac()->system();
88 
89  $this->umail = new ilFormatMail($this->user->getId());
90  $this->mfile = new ilFileDataMail($this->user->getId());
91  $this->mbox = new ilMailBox($this->user->getId());
92 
93  if (null === $bodyPurifier) {
94  $bodyPurifier = new ilMailBodyPurifier();
95  }
96  $this->purifier = $bodyPurifier;
97 
98  if (isset($_POST['mobj_id']) && (int) $_POST['mobj_id']) {
99  $_GET['mobj_id'] = $_POST['mobj_id'];
100  }
101 
102  if (!(int) $_GET['mobj_id']) {
103  $_GET['mobj_id'] = $this->mbox->getInboxFolder();
104  }
105  $_GET['mobj_id'] = (int) $_GET['mobj_id'];
106 
107  $this->ctrl->saveParameter($this, 'mobj_id');
108  }
global $DIC
Definition: saml.php:7
$_GET["client_id"]
This class handles all operations on files (attachments) in directory ilias_data/mail.
user()
Definition: user.php:4
Class UserMail this class handles user mails.
$_POST["username"]
+ Here is the call graph for this function:

Member Function Documentation

◆ cancelMail()

ilMailFormGUI::cancelMail ( )

Definition at line 840 of file class.ilMailFormGUI.php.

References ilMailFormCall\getRefererRedirectUrl(), ilMailFormCall\isRefererStored(), ilUtil\redirect(), and showForm().

841  {
844  }
845 
846  $this->showForm();
847  }
static redirect($a_script)
+ Here is the call graph for this function:

◆ cancelSearch()

ilMailFormGUI::cancelSearch ( )

Definition at line 374 of file class.ilMailFormGUI.php.

References $_SESSION, and searchResults().

375  {
376  unset($_SESSION["mail_search"]);
377  $this->searchResults();
378  }
$_SESSION["AccountId"]
+ Here is the call graph for this function:

◆ decodeAttachmentFiles()

ilMailFormGUI::decodeAttachmentFiles ( array  $files)
protected
Parameters
array$files
Returns
array

Definition at line 170 of file class.ilMailFormGUI.php.

References array, and user().

Referenced by saveDraft(), and sendMessage().

171  {
172  $decodedFiles = array();
173 
174  foreach ($files as $value) {
175  if (is_file($this->mfile->getMailPath() . '/' . $this->user->getId() . '_' . urldecode($value))) {
176  $decodedFiles[] = urldecode($value);
177  }
178  }
179 
180  return $decodedFiles;
181  }
$files
Definition: add-vimline.php:18
user()
Definition: user.php:4
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ editAttachments()

ilMailFormGUI::editAttachments ( )

Definition at line 380 of file class.ilMailFormGUI.php.

References $_POST, $files, array, ilMailFormCall\getContextId(), ilMailFormCall\getContextParameters(), ilUtil\securePlainString(), and user().

381  {
382  // decode post values
383  $files = array();
384  if (is_array($_POST['attachments'])) {
385  foreach ($_POST['attachments'] as $value) {
386  $files[] = urldecode($value);
387  }
388  }
389 
390  // Note: For security reasons, ILIAS only allows Plain text messages.
391  $this->umail->savePostData(
392  $this->user->getId(),
393  $files,
396  ilUtil::securePlainString($_POST["rcp_bcc"]),
397  $_POST["m_type"],
398  ilUtil::securePlainString($_POST["m_email"]),
399  ilUtil::securePlainString($_POST["m_subject"]),
400  ilUtil::securePlainString($_POST["m_message"]),
401  ilUtil::securePlainString($_POST['use_placeholders']),
404  );
405 
406  $this->ctrl->redirectByClass("ilmailattachmentgui");
407  }
$files
Definition: add-vimline.php:18
static securePlainString($a_str)
Remove unsecure characters from a plain text string.
user()
Definition: user.php:4
Create styles array
The data for the language used.
$_POST["username"]
+ Here is the call graph for this function:

◆ executeCommand()

ilMailFormGUI::executeCommand ( )

Definition at line 110 of file class.ilMailFormGUI.php.

111  {
112  $forward_class = $this->ctrl->getNextClass($this);
113  switch ($forward_class) {
114  case 'ilmailfoldergui':
115  include_once 'Services/Mail/classes/class.ilMailFolderGUI.php';
116 
117  $this->ctrl->forwardCommand(new ilMailFolderGUI());
118  break;
119 
120  case 'ilmailattachmentgui':
121  include_once 'Services/Mail/classes/class.ilMailAttachmentGUI.php';
122 
123  $this->ctrl->setReturn($this, "returnFromAttachments");
124  $this->ctrl->forwardCommand(new ilMailAttachmentGUI());
125  break;
126 
127  case 'ilmailsearchgui':
128  include_once 'Services/Contact/classes/class.ilMailSearchGUI.php';
129 
130  $this->ctrl->setReturn($this, "searchResults");
131  $this->ctrl->forwardCommand(new ilMailSearchGUI());
132  break;
133 
134  case 'ilmailsearchcoursesgui':
135  include_once 'Services/Contact/classes/class.ilMailSearchCoursesGUI.php';
136 
137  $this->ctrl->setReturn($this, "searchResults");
138  $this->ctrl->forwardCommand(new ilMailSearchCoursesGUI());
139  break;
140 
141  case 'ilmailinglistsgui':
142  include_once 'Services/Contact/classes/class.ilMailingListsGUI.php';
143 
144  $this->ctrl->setReturn($this, 'searchResults');
145  $this->ctrl->forwardCommand(new ilMailingListsGUI());
146  break;
147 
148  case 'ilmailsearchgroupsgui':
149  include_once 'Services/Contact/classes/class.ilMailSearchGroupsGUI.php';
150 
151  $this->ctrl->setReturn($this, "searchResults");
152  $this->ctrl->forwardCommand(new ilMailSearchGroupsGUI());
153  break;
154 
155  default:
156  if (!($cmd = $this->ctrl->getCmd())) {
157  $cmd = "showForm";
158  }
159 
160  $this->$cmd();
161  break;
162  }
163  return true;
164  }

◆ getTemplateDataById()

ilMailFormGUI::getTemplateDataById ( )
protected

Called asynchronously when changing the template.

Definition at line 448 of file class.ilMailFormGUI.php.

References $_GET, $template, $template_id, array, exit, and ilMailTemplateService\getTemplateContextById().

449  {
450  require_once 'Services/JSON/classes/class.ilJsonUtil.php';
451 
452  if (!isset($_GET['template_id'])) {
453  exit();
454  }
455 
456  try {
457  require_once 'Services/Mail/classes/class.ilMailTemplateService.php';
458  require_once 'Services/Mail/classes/class.ilMailTemplateDataProvider.php';
459  $template_id = (int) $_GET['template_id'];
460  $template_provider = new ilMailTemplateDataProvider();
461  $template = $template_provider->getTemplateById($template_id);
463  echo json_encode(array(
464  'm_subject' => $template->getSubject(),
465  'm_message' => $template->getMessage()
466  ));
467  } catch (Exception $e) {
468  }
469  exit();
470  }
$template
$_GET["client_id"]
Class ilMailTemplateDataProvider.
Create styles array
The data for the language used.
$template_id
+ Here is the call graph for this function:

◆ lookupRecipientAsync()

ilMailFormGUI::lookupRecipientAsync ( )

Definition at line 806 of file class.ilMailFormGUI.php.

References $_GET, $_POST, $result, array, exit, ilUtil\stripSlashes(), and ilStr\strLen().

807  {
808  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
809  include_once 'Services/Mail/classes/class.ilMailForm.php';
810  $search = '';
811  if (isset($_GET["term"]) && is_string($_GET["term"])) {
812  $search = $_GET["term"];
813  }
814  if (isset($_POST["term"]) && is_string($_POST["term"])) {
815  $search = $_POST["term"];
816  }
817 
818  $search = trim($search);
819 
820  $result = array();
821 
822  require_once 'Services/Utilities/classes/class.ilStr.php';
823  if (\ilStr::strLen($search) < 3) {
824  echo json_encode($result);
825  exit;
826  }
827 
828  // #14768
829  $quoted = ilUtil::stripSlashes($search);
830  $quoted = str_replace('%', '\%', $quoted);
831  $quoted = str_replace('_', '\_', $quoted);
832 
833  $mailFormObj = new ilMailForm;
834  $result = $mailFormObj->getRecipientAsync("%" . $quoted . "%", ilUtil::stripSlashes($search));
835 
836  echo json_encode($result);
837  exit;
838  }
static strLen($a_string)
Definition: class.ilStr.php:78
$result
$_GET["client_id"]
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
Create styles array
The data for the language used.
$_POST["username"]
+ Here is the call graph for this function:

◆ mailAttachment()

ilMailFormGUI::mailAttachment ( )

Definition at line 439 of file class.ilMailFormGUI.php.

References $_GET, and showForm().

440  {
441  $_GET["type"] = "attach";
442  $this->showForm();
443  }
$_GET["client_id"]
+ Here is the call graph for this function:

◆ mailRole()

ilMailFormGUI::mailRole ( )

Definition at line 427 of file class.ilMailFormGUI.php.

References $_GET, and showForm().

428  {
429  $_GET["type"] = "role";
430  $this->showForm();
431  }
$_GET["client_id"]
+ Here is the call graph for this function:

◆ mailUser()

ilMailFormGUI::mailUser ( )

Definition at line 421 of file class.ilMailFormGUI.php.

References $_GET, and showForm().

422  {
423  $_GET["type"] = "new";
424  $this->showForm();
425  }
$_GET["client_id"]
+ Here is the call graph for this function:

◆ replyMail()

ilMailFormGUI::replyMail ( )

Definition at line 433 of file class.ilMailFormGUI.php.

References $_GET, and showForm().

434  {
435  $_GET["type"] = "reply";
436  $this->showForm();
437  }
$_GET["client_id"]
+ Here is the call graph for this function:

◆ returnFromAttachments()

ilMailFormGUI::returnFromAttachments ( )

Definition at line 409 of file class.ilMailFormGUI.php.

References $_GET, and showForm().

410  {
411  $_GET["type"] = "attach";
412  $this->showForm();
413  }
$_GET["client_id"]
+ Here is the call graph for this function:

◆ saveDraft()

ilMailFormGUI::saveDraft ( )

Definition at line 224 of file class.ilMailFormGUI.php.

References $_POST, $_SESSION, $errors, $files, array, decodeAttachmentFiles(), ilMailFormCall\getContextId(), ilMailFormCall\getContextParameters(), ilMailFormCall\getRefererRedirectUrl(), ilMailFormCall\isRefererStored(), ilUtil\redirect(), ilUtil\securePlainString(), ilUtil\sendInfo(), showForm(), showSubmissionErrors(), and user().

225  {
226  if (!$_POST['m_subject']) {
227  $_POST['m_subject'] = 'No title';
228  }
229 
230  $draftFolderId = $this->mbox->getDraftsFolder();
231  $files = $this->decodeAttachmentFiles(isset($_POST['attachments']) ? (array) $_POST['attachments'] : array());
232 
233  if ($errors = $this->umail->validateRecipients(
237  )) {
238  $_POST['attachments'] = $files;
240  $this->showForm();
241  return;
242  }
243 
244  if (isset($_SESSION["draft"])) {
245  $draftId = (int) $_SESSION['draft'];
246  unset($_SESSION['draft']);
247  } else {
248  $draftId = $this->umail->getNewDraftId($this->user->getId(), $draftFolderId);
249  }
250 
251  $this->umail->updateDraft(
252  $draftFolderId,
253  $files,
256  ilUtil::securePlainString($_POST['rcp_bcc']),
257  $_POST['m_type'],
258  ilUtil::securePlainString($_POST['m_email']),
259  ilUtil::securePlainString($_POST['m_subject']),
260  ilUtil::securePlainString($_POST['m_message']),
261  $draftId,
262  (int) $_POST['use_placeholders'],
265  );
266 
267  ilUtil::sendInfo($this->lng->txt('mail_saved'), true);
268 
271  } else {
272  $this->ctrl->redirectByClass(['ilmailgui', 'ilmailfoldergui']);
273  }
274 
275  $this->showForm();
276  }
$files
Definition: add-vimline.php:18
decodeAttachmentFiles(array $files)
static securePlainString($a_str)
Remove unsecure characters from a plain text string.
$_SESSION["AccountId"]
user()
Definition: user.php:4
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
Create styles array
The data for the language used.
$errors
Definition: index.php:6
showSubmissionErrors(array $errors)
static redirect($a_script)
$_POST["username"]
+ Here is the call graph for this function:

◆ saveMailBeforeSearch()

ilMailFormGUI::saveMailBeforeSearch ( )
protected

Definition at line 852 of file class.ilMailFormGUI.php.

References $_POST, $files, array, ilMailFormCall\getContextId(), ilMailFormCall\getContextParameters(), ilUtil\securePlainString(), and user().

Referenced by searchCoursesTo(), searchGroupsTo(), and searchMailingListsTo().

853  {
854  $files = array();
855  if (is_array($_POST['attachments'])) {
856  foreach ($_POST['attachments'] as $value) {
857  $files[] = urldecode($value);
858  }
859  }
860 
861  $this->umail->savePostData(
862  $this->user->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']),
874  );
875  }
$files
Definition: add-vimline.php:18
static securePlainString($a_str)
Remove unsecure characters from a plain text string.
user()
Definition: user.php:4
Create styles array
The data for the language used.
$_POST["username"]
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ search()

ilMailFormGUI::search ( )

Definition at line 356 of file class.ilMailFormGUI.php.

References $_POST, $_SESSION, searchUsers(), and ilUtil\sendInfo().

357  {
358  $_SESSION["mail_search_search"] = $_POST["search"];
359  if (strlen(trim($_SESSION["mail_search_search"])) == 0) {
360  ilUtil::sendInfo($this->lng->txt("mail_insert_query"));
361  $this->searchUsers(false);
362  } else {
363  if (strlen(trim($_SESSION["mail_search_search"])) < 3) {
364  $this->lng->loadLanguageModule('search');
365  ilUtil::sendInfo($this->lng->txt('search_minimum_three'));
366  $this->searchUsers(false);
367  } else {
368  $this->ctrl->setParameterByClass("ilmailsearchgui", "search", urlencode($_SESSION["mail_search_search"]));
369  $this->ctrl->redirectByClass("ilmailsearchgui");
370  }
371  }
372  }
$_SESSION["AccountId"]
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
searchUsers($save=true)
$_POST["username"]
+ Here is the call graph for this function:

◆ searchCoursesTo()

ilMailFormGUI::searchCoursesTo ( )

Definition at line 333 of file class.ilMailFormGUI.php.

References $_SESSION, and saveMailBeforeSearch().

334  {
335  $this->saveMailBeforeSearch();
336 
337  if ($_SESSION['search_crs']) {
338  $this->ctrl->setParameterByClass('ilmailsearchcoursesgui', 'cmd', 'showMembers');
339  }
340 
341  $this->ctrl->setParameterByClass('ilmailsearchcoursesgui', 'ref', 'mail');
342  $this->ctrl->redirectByClass('ilmailsearchcoursesgui');
343  }
$_SESSION["AccountId"]
+ Here is the call graph for this function:

◆ searchGroupsTo()

ilMailFormGUI::searchGroupsTo ( )

Definition at line 348 of file class.ilMailFormGUI.php.

References saveMailBeforeSearch().

349  {
350  $this->saveMailBeforeSearch();
351 
352  $this->ctrl->setParameterByClass('ilmailsearchgroupsgui', 'ref', 'mail');
353  $this->ctrl->redirectByClass('ilmailsearchgroupsgui');
354  }
+ Here is the call graph for this function:

◆ searchMailingListsTo()

ilMailFormGUI::searchMailingListsTo ( )

Definition at line 880 of file class.ilMailFormGUI.php.

References saveMailBeforeSearch().

881  {
882  $this->saveMailBeforeSearch();
883 
884  $this->ctrl->setParameterByClass('ilmailinglistsgui', 'ref', 'mail');
885  $this->ctrl->redirectByClass('ilmailinglistsgui');
886  }
+ Here is the call graph for this function:

◆ searchResults()

ilMailFormGUI::searchResults ( )

Definition at line 415 of file class.ilMailFormGUI.php.

References $_GET, and showForm().

Referenced by cancelSearch().

416  {
417  $_GET["type"] = "search_res";
418  $this->showForm();
419  }
$_GET["client_id"]
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ searchUsers()

ilMailFormGUI::searchUsers (   $save = true)

Definition at line 278 of file class.ilMailFormGUI.php.

References $_POST, $_SESSION, $files, $form, array, ilMailFormCall\getContextId(), ilMailFormCall\getContextParameters(), ilUtil\prepareFormOutput(), ilUtil\securePlainString(), ilTextInputGUI\setSize(), and user().

Referenced by search().

279  {
280  $this->tpl->setTitle($this->lng->txt("mail"));
281 
282  if ($save) {
283  // decode post values
284  $files = array();
285  if (is_array($_POST['attachments'])) {
286  foreach ($_POST['attachments'] as $value) {
287  $files[] = urldecode($value);
288  }
289  }
290 
291  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
292  $this->umail->savePostData(
293  $this->user->getId(),
294  $files,
297  ilUtil::securePlainString($_POST["rcp_bcc"]),
298  $_POST["m_type"],
299  ilUtil::securePlainString($_POST["m_email"]),
300  ilUtil::securePlainString($_POST["m_subject"]),
301  ilUtil::securePlainString($_POST["m_message"]),
302  ilUtil::securePlainString($_POST['use_placeholders']),
305  );
306  }
307  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
308  $form = new ilPropertyFormGUI();
309  $form->setId('search_rcp');
310  $form->setTitle($this->lng->txt('search_recipients'));
311  $form->setFormAction($this->ctrl->getFormAction($this, 'search'));
312 
313  $inp = new ilTextInputGUI($this->lng->txt("search_for"), 'search');
314  $inp->setSize(30);
315  $dsDataLink = $this->ctrl->getLinkTarget($this, 'lookupRecipientAsync', '', true, false);
316  $inp->setDataSource($dsDataLink);
317 
318  if (strlen(trim($_SESSION["mail_search_search"])) > 0) {
319  $inp->setValue(ilUtil::prepareFormOutput(trim($_SESSION["mail_search_search"]), true));
320  }
321  $form->addItem($inp);
322 
323  $form->addCommandButton('search', $this->lng->txt("search"));
324  $form->addCommandButton('cancelSearch', $this->lng->txt("cancel"));
325 
326  $this->tpl->setContent($form->getHtml());
327  $this->tpl->show();
328  }
$files
Definition: add-vimline.php:18
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.
$_SESSION["AccountId"]
This class represents a property form user interface.
user()
Definition: user.php:4
if(isset($_POST['submit'])) $form
setSize($a_size)
Set Size.
This class represents a text property in a property form.
Create styles array
The data for the language used.
$_POST["username"]
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendMessage()

ilMailFormGUI::sendMessage ( )

Definition at line 183 of file class.ilMailFormGUI.php.

References $_POST, $errors, $files, $message, array, decodeAttachmentFiles(), ilMailFormCall\getRefererRedirectUrl(), ilMailFormCall\isRefererStored(), ilUtil\redirect(), ilUtil\securePlainString(), ilUtil\sendInfo(), showForm(), showSubmissionErrors(), string, and user().

184  {
185  $m_type = isset($_POST["m_type"]) ? $_POST["m_type"] : array("normal");
186 
187  $message = (string) $_POST['m_message'];
188  $mailBody = new ilMailBody($message, $this->purifier);
189 
190  $sanitizedMessage = $mailBody->getContent();
191 
192  $files = $this->decodeAttachmentFiles(isset($_POST['attachments']) ? (array) $_POST['attachments'] : array());
193 
194  $this->umail->setSaveInSentbox(true);
195  if ($errors = $this->umail->sendMail(
198  ilUtil::securePlainString($_POST['rcp_bcc']),
199  ilUtil::securePlainString($_POST['m_subject']),
200  $sanitizedMessage,
201  $files,
202  $m_type,
203  (int) $_POST['use_placeholders']
204  )
205  ) {
206  $_POST['attachments'] = $files;
208  } else {
209  $this->umail->savePostData($this->user->getId(), array(), "", "", "", "", "", "", "", "");
210 
211  $this->ctrl->setParameterByClass('ilmailgui', 'type', 'message_sent');
212 
214  ilUtil::sendInfo($this->lng->txt('mail_message_send'), true);
216  } else {
217  $this->ctrl->redirectByClass('ilmailgui');
218  }
219  }
220 
221  $this->showForm();
222  }
$files
Definition: add-vimline.php:18
decodeAttachmentFiles(array $files)
Add rich text string
static securePlainString($a_str)
Remove unsecure characters from a plain text string.
user()
Definition: user.php:4
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
catch(Exception $e) $message
Create styles array
The data for the language used.
$errors
Definition: index.php:6
showSubmissionErrors(array $errors)
static redirect($a_script)
$_POST["username"]
+ Here is the call graph for this function:

◆ showForm()

ilMailFormGUI::showForm ( )

Definition at line 472 of file class.ilMailFormGUI.php.

References $_GET, $_POST, $_SESSION, $data, $error, $key, $options, $size, $template, array, ilButton\BUTTON_TYPE_SUBMIT, ilUtil\formatSize(), ilMailFormCall\getContextId(), ilButton\getInstance(), ilBuddyList\getInstanceByGlobalUser(), ilLoggerFactory\getLogger(), ilMailFormCall\getSignature(), ilMailTemplateService\getTemplateContextById(), ilMailFormCall\isRefererStored(), ilUtil\securePlainString(), ilUtil\sendInfo(), ilMailFormCall\setContextId(), ilMailFormCall\setContextParameters(), ilFormPropertyGUI\setInfo(), ilCheckboxInputGUI\setOptionTitle(), ilFormPropertyGUI\setRequired(), ilTextInputGUI\setSize(), ilTextAreaInputGUI\setValue(), and user().

Referenced by cancelMail(), mailAttachment(), mailRole(), mailUser(), replyMail(), returnFromAttachments(), saveDraft(), searchResults(), and sendMessage().

473  {
474  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_new.html", "Services/Mail");
475  $this->tpl->setTitle($this->lng->txt("mail"));
476 
477  $this->lng->loadLanguageModule("crs");
478 
480  $this->tabs->setBackTarget($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'cancelMail'));
481  }
482 
483  switch ($_GET["type"]) {
484  case 'reply':
485  if ($_SESSION['mail_id']) {
486  $_GET['mail_id'] = $_SESSION['mail_id'];
487  }
488  $mailData = $this->umail->getMail($_GET["mail_id"]);
489  $mailData["m_subject"] = $this->umail->formatReplySubject();
490  $mailData["m_message"] = $this->umail->formatReplyMessage();
491  $mailData["m_message"] = $this->umail->prependSignature();
492  // NO ATTACHMENTS FOR REPLIES
493  $mailData["attachments"] = array();
494  //$mailData["rcp_cc"] = $this->umail->formatReplyRecipientsForCC();
495  $mailData["rcp_cc"] = '';
496  $mailData["rcp_to"] = $this->umail->formatReplyRecipient();
497  $_SESSION["mail_id"] = "";
498  break;
499 
500  case 'search_res':
501  $mailData = $this->umail->getSavedData();
502 
503  /*if($_SESSION["mail_search_results"])
504  {
505  $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results"],$_SESSION["mail_search"]);
506  }
507  unset($_SESSION["mail_search"]);
508  unset($_SESSION["mail_search_results"]);*/
509 
510  if ($_SESSION["mail_search_results_to"]) {
511  $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_to"], 'to');
512  }
513  if ($_SESSION["mail_search_results_cc"]) {
514  $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_cc"], 'cc');
515  }
516  if ($_SESSION["mail_search_results_bcc"]) {
517  $mailData = $this->umail->appendSearchResult($_SESSION["mail_search_results_bcc"], 'bc');
518  }
519 
520  unset($_SESSION["mail_search_results_to"]);
521  unset($_SESSION["mail_search_results_cc"]);
522  unset($_SESSION["mail_search_results_bcc"]);
523 
524  break;
525 
526  case 'attach':
527  $mailData = $this->umail->getSavedData();
528  break;
529 
530  case 'draft':
531  $_SESSION["draft"] = $_GET["mail_id"];
532  $mailData = $this->umail->getMail($_GET["mail_id"]);
533  ilMailFormCall::setContextId($mailData['tpl_ctx_id']);
534  ilMailFormCall::setContextParameters($mailData['tpl_ctx_params']);
535  break;
536 
537  case 'forward':
538  $mailData = $this->umail->getMail($_GET["mail_id"]);
539  $mailData["rcp_to"] = $mailData["rcp_cc"] = $mailData["rcp_bcc"] = '';
540  $mailData["m_subject"] = $this->umail->formatForwardSubject();
541  $mailData["m_message"] = $this->umail->prependSignature();
542  if (is_array($mailData["attachments"]) && count($mailData["attachments"])) {
543  if ($error = $this->mfile->adoptAttachments($mailData["attachments"], $_GET["mail_id"])) {
545  }
546  }
547  break;
548 
549  case 'new':
550  if ($_GET['rcp_to']) {
551  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
552  $mailData["rcp_to"] = ilUtil::securePlainString($_GET['rcp_to']);
553  } elseif ($_SESSION['rcp_to']) {
554  $mailData["rcp_to"] = $_SESSION['rcp_to'];
555  }
556  if ($_GET['rcp_cc']) {
557  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
558  $mailData["rcp_cc"] = ilUtil::securePlainString($_GET['rcp_cc']);
559  } elseif ($_SESSION['rcp_cc']) {
560  $mailData["rcp_cc"] = $_SESSION['rcp_cc'];
561  }
562  if ($_GET['rcp_bcc']) {
563  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
564  $mailData["rcp_bcc"] = ilUtil::securePlainString($_GET['rcp_bcc']);
565  } elseif ($_SESSION['rcp_bcc']) {
566  $mailData["rcp_bcc"] = $_SESSION['rcp_bcc'];
567  }
568  $mailData['m_message'] = '';
569  if (strlen($sig = ilMailFormCall::getSignature())) {
570  $mailData['m_message'] = $sig;
571  $mailData['m_message'] .= chr(13) . chr(10) . chr(13) . chr(10);
572  }
573  $mailData['m_message'] .= $this->umail->appendSignature();
574 
575  $_SESSION['rcp_to'] = '';
576  $_SESSION['rcp_cc'] = '';
577  $_SESSION['rcp_bcc'] = '';
578  break;
579 
580  case 'role':
581 
582  if (is_array($_POST['roles'])) {
583  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
584  $mailData['rcp_to'] = ilUtil::securePlainString(implode(',', $_POST['roles']));
585  } elseif (is_array($_SESSION['mail_roles'])) {
586  $mailData['rcp_to'] = ilUtil::securePlainString(implode(',', $_SESSION['mail_roles']));
587  }
588 
589  $mailData['m_message'] = '';
590  if (strlen($sig = ilMailFormCall::getSignature())) {
591  $mailData['m_message'] = $sig;
592  $mailData['m_message'] .= chr(13) . chr(10) . chr(13) . chr(10);
593  }
594 
595  $mailData['m_message'] .= $_POST["additional_message_text"] . chr(13) . chr(10) . $this->umail->appendSignature();
596  $_POST["additional_message_text"] = "";
597  $_SESSION['mail_roles'] = [];
598  break;
599 
600  case 'address':
601  $mailData["rcp_to"] = urldecode($_GET["rcp"]);
602  break;
603 
604  default:
605  // GET DATA FROM POST
606  $mailData = $_POST;
607 
608  // strip slashes
609  foreach ($mailData as $key => $value) {
610  if (is_string($value)) {
611  // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
612  $mailData[$key] = ilUtil::securePlainString($value);
613  }
614  }
615  break;
616  }
617 
618  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
619 
620  $form_gui = new ilPropertyFormGUI();
621  $form_gui->setTitle($this->lng->txt('compose'));
622  $form_gui->setId('mail_compose_form');
623  $form_gui->setName('mail_compose_form');
624  $form_gui->setFormAction($this->ctrl->getFormAction($this, 'sendMessage'));
625 
626  $this->tpl->setVariable('FORM_ID', $form_gui->getId());
627 
628  require_once 'Services/UIComponent/Button/classes/class.ilButton.php';
629  $btn = ilButton::getInstance();
630  $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT);
631  $btn->setForm('form_' . $form_gui->getName())
632  ->setName('searchUsers')
633  ->setCaption('search_recipients');
634  $this->toolbar->addStickyItem($btn);
635 
636  $btn = ilButton::getInstance();
637  $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT)
638  ->setName('searchCoursesTo')
639  ->setForm('form_' . $form_gui->getName())
640  ->setCaption('mail_my_courses');
641  $this->toolbar->addButtonInstance($btn);
642 
643  $btn = ilButton::getInstance();
644  $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT)
645  ->setName('searchGroupsTo')
646  ->setForm('form_' . $form_gui->getName())
647  ->setCaption('mail_my_groups');
648  $this->toolbar->addButtonInstance($btn);
649 
650  require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystem.php';
651  if (count(ilBuddyList::getInstanceByGlobalUser()->getLinkedRelations()) > 0) {
652  $btn = ilButton::getInstance();
653  $btn->setButtonType(ilButton::BUTTON_TYPE_SUBMIT)
654  ->setName('searchMailingListsTo')
655  ->setForm('form_' . $form_gui->getName())
656  ->setCaption('mail_my_mailing_lists');
657  $this->toolbar->addButtonInstance($btn);
658  }
659 
660  $dsDataLink = $this->ctrl->getLinkTarget($this, 'lookupRecipientAsync', '', true);
661 
662  // RECIPIENT
663  $inp = new ilTextInputGUI($this->lng->txt('mail_to'), 'rcp_to');
664  $inp->setRequired(true);
665  $inp->setSize(50);
666  $inp->setValue($mailData["rcp_to"]);
667  $inp->setDataSource($dsDataLink, ",");
668  $inp->setMaxLength(null);
669  $form_gui->addItem($inp);
670 
671  // CC
672  $inp = new ilTextInputGUI($this->lng->txt('cc'), 'rcp_cc');
673  $inp->setSize(50);
674  $inp->setValue($mailData["rcp_cc"]);
675  $inp->setDataSource($dsDataLink, ",");
676  $inp->setMaxLength(null);
677  $form_gui->addItem($inp);
678 
679  // BCC
680  $inp = new ilTextInputGUI($this->lng->txt('bc'), 'rcp_bcc');
681  $inp->setSize(50);
682  $inp->setValue($mailData["rcp_bcc"]);
683  $inp->setDataSource($dsDataLink, ",");
684  $inp->setMaxLength(null);
685  $form_gui->addItem($inp);
686 
687  // SUBJECT
688  $inp = new ilTextInputGUI($this->lng->txt('subject'), 'm_subject');
689  $inp->setSize(50);
690  $inp->setRequired(true);
691  $inp->setValue($mailData["m_subject"]);
692  $form_gui->addItem($inp);
693 
694  // Attachments
695  include_once 'Services/Mail/classes/class.ilMailFormAttachmentFormPropertyGUI.php';
696  $att = new ilMailFormAttachmentPropertyGUI($this->lng->txt(($mailData["attachments"]) ? 'edit' : 'add'));
697 
698  if (is_array($mailData["attachments"]) && count($mailData["attachments"])) {
699  foreach ($mailData["attachments"] as $data) {
700  if (is_file($this->mfile->getMailPath() . '/' . $this->user->getId() . "_" . $data)) {
701  $hidden = new ilHiddenInputGUI('attachments[]');
702  $form_gui->addItem($hidden);
703  $size = filesize($this->mfile->getMailPath() . '/' . $this->user->getId() . "_" . $data);
704  $label = $data . " [" . ilUtil::formatSize($size) . "]";
705  $att->addItem($label);
706  $hidden->setValue(urlencode($data));
707  }
708  }
709  }
710  $form_gui->addItem($att);
711 
712  // ONLY IF SYSTEM MAILS ARE ALLOWED
713  if ($this->rbacsystem->checkAccess("system_message", $this->umail->getMailObjectReferenceId())) {
714  $chb = new ilCheckboxInputGUI($this->lng->txt('type'), 'm_type[]');
715  $chb->setOptionTitle($this->lng->txt('system_message'));
716  $chb->setValue('system');
717  $chb->setChecked(false);
718  if (is_array($mailData["m_type"]) and in_array('system', $mailData["m_type"])) {
719  $chb->setChecked(true);
720  }
721  $form_gui->addItem($chb);
722  }
723 
725  $context_id = ilMailFormCall::getContextId();
726 
727  // Activate placeholders
728  $mailData['use_placeholders'] = true;
729 
730  try {
731  require_once 'Services/Mail/classes/class.ilMailTemplateService.php';
732  $context = ilMailTemplateService::getTemplateContextById($context_id);
733 
734  require_once 'Services/Mail/classes/class.ilMailTemplateDataProvider.php';
735  $template_provider = new ilMailTemplateDataProvider();
736  $templates = $template_provider->getTemplateByContextId($context->getId());
737 
738  if (count($templates)) {
739  $options = array();
740  foreach ($templates as $template) {
741  $options[$template->getTplId()] = $template->getTitle();
742  }
743  asort($options);
744 
745  require_once 'Services/Mail/classes/Form/class.ilMailTemplateSelectInputGUI.php';
746  $template_chb = new ilMailTemplateSelectInputGUI(
747  $this->lng->txt('mail_template_client'),
748  'template_id',
749  $this->ctrl->getLinkTarget($this, 'getTemplateDataById', '', true, false),
750  array('m_subject', 'm_message')
751  );
752  $template_chb->setInfo($this->lng->txt('mail_template_client_info'));
753  $template_chb->setOptions(array('' => $this->lng->txt('please_choose')) + $options);
754  $form_gui->addItem($template_chb);
755  }
756  } catch (Exception $e) {
757  require_once './Services/Logging/classes/public/class.ilLoggerFactory.php';
758  ilLoggerFactory::getLogger('mail')->error(sprintf('%s has been called with invalid context id: %s.', __METHOD__, $context_id));
759  }
760  } else {
761  require_once 'Services/Mail/classes/class.ilMailTemplateGenericContext.php';
762  $context = new ilMailTemplateGenericContext();
763  }
764 
765  // MESSAGE
766  $inp = new ilTextAreaInputGUI($this->lng->txt('message_content'), 'm_message');
767  //$inp->setValue(htmlspecialchars($mailData["m_message"], false));
768  $inp->setValue($mailData["m_message"]);
769  $inp->setRequired(false);
770  $inp->setCols(60);
771  $inp->setRows(10);
772  $form_gui->addItem($inp);
773 
774  // PLACEHOLDERS
775  $chb = new ilCheckboxInputGUI($this->lng->txt('mail_serial_letter_placeholders'), 'use_placeholders');
776  $chb->setOptionTitle($this->lng->txt('activate_serial_letter_placeholders'));
777  $chb->setValue(1);
778  if (isset($mailData['use_placeholders']) && $mailData['use_placeholders']) {
779  $chb->setChecked(true);
780  }
781 
782  require_once 'Services/Mail/classes/Form/class.ilManualPlaceholderInputGUI.php';
783  $placeholders = new ilManualPlaceholderInputGUI('m_message');
784  $placeholders->setInstructionText($this->lng->txt('mail_nacc_use_placeholder'));
785  $placeholders->setAdviseText(sprintf($this->lng->txt('placeholders_advise'), '<br />'));
786  foreach ($context->getPlaceholders() as $key => $value) {
787  $placeholders->addPlaceholder($value['placeholder'], $value['label']);
788  }
789  $chb->addSubItem($placeholders);
790  $form_gui->addItem($chb);
791 
792  $form_gui->addCommandButton('sendMessage', $this->lng->txt('send_mail'));
793  $form_gui->addCommandButton('saveDraft', $this->lng->txt('save_message'));
795  $form_gui->addCommandButton('cancelMail', $this->lng->txt('cancel'));
796  }
797 
798  $this->tpl->parseCurrentBlock();
799 
800  $this->tpl->setVariable('FORM', $form_gui->getHTML());
801 
802  $this->tpl->addJavaScript('Services/Mail/js/ilMailComposeFunctions.js');
803  $this->tpl->show();
804  }
$size
Definition: RandomTest.php:84
static securePlainString($a_str)
Remove unsecure characters from a plain text string.
static getInstanceByGlobalUser()
$_SESSION["AccountId"]
$template
This class represents a property form user interface.
$_GET["client_id"]
static getInstance()
setValue($a_value)
Set Value.
This class represents a checkbox property in a property form.
Class ilMailTemplateDataProvider.
user()
Definition: user.php:4
Class ilManualPlaceholderInputGUI.
setInfo($a_info)
Set Information Text.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
This class represents a hidden form property in a property form.
$error
Definition: Error.php:17
Class ilMailTemplateSelectInputGUI.
setSize($a_size)
Set Size.
This class represents a text property in a property form.
static setContextParameters(array $parameters)
Create styles array
The data for the language used.
This class represents a text area property in a property form.
static getSignature()
Get preset signature.
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.
setOptionTitle($a_optiontitle)
Set Option Title (optional).
const BUTTON_TYPE_SUBMIT
$key
Definition: croninfo.php:18
$_POST["username"]
setRequired($a_required)
Set Required.
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showSubmissionErrors()

ilMailFormGUI::showSubmissionErrors ( array  $errors)
protected
Parameters
array$errors

Definition at line 891 of file class.ilMailFormGUI.php.

References $error, $tpl, array, ilUtil\prepareFormOutput(), and ilUtil\sendInfo().

Referenced by saveDraft(), and sendMessage().

892  {
893  $errors_to_display = array();
894 
895  foreach ($errors as $error) {
896  $error = array_values($error);
897  $first_error = array_shift($error);
898 
899  $translation = $this->lng->txt($first_error);
900  if ($translation == '-' . $first_error . '-') {
901  $translation = $first_error;
902  }
903 
904  if (count($error) == 0 || $translation == $first_error) {
905  $errors_to_display[] = $translation;
906  } else {
907  // We expect all other parts of this error array are recipient addresses = input parameters
908  $error = array_map(function ($address) {
909  return ilUtil::prepareFormOutput($address);
910  }, $error);
911 
912  array_unshift($error, $translation);
913  $errors_to_display[] = call_user_func_array('sprintf', $error);
914  }
915  }
916 
917  if (count($errors_to_display) > 0) {
918  $tpl = new ilTemplate('tpl.mail_new_submission_errors.html', true, true, 'Services/Mail');
919  if (count($errors_to_display) == 1) {
920  $tpl->setCurrentBlock('single_error');
921  $tpl->setVariable('SINGLE_ERROR', current($errors_to_display));
922  $tpl->parseCurrentBlock();
923  } else {
924  $first_error = array_shift($errors_to_display);
925 
926  foreach ($errors_to_display as $error) {
927  $tpl->setCurrentBlock('error_loop');
928  $tpl->setVariable('ERROR', $error);
929  $tpl->parseCurrentBlock();
930  }
931 
932  $tpl->setCurrentBlock('multiple_errors');
933  $tpl->setVariable('FIRST_ERROR', $first_error);
934  $tpl->parseCurrentBlock();
935  }
936 
937  ilUtil::sendInfo($tpl->get());
938  }
939  }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$error
Definition: Error.php:17
special template class to simplify handling of ITX/PEAR
Create styles array
The data for the language used.
$errors
Definition: index.php:6
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $ctrl

ilMailFormGUI::$ctrl
private

Definition at line 27 of file class.ilMailFormGUI.php.

◆ $lng

ilMailFormGUI::$lng
private

Definition at line 32 of file class.ilMailFormGUI.php.

◆ $mbox

ilMailFormGUI::$mbox
private

Definition at line 62 of file class.ilMailFormGUI.php.

◆ $mfile

ilMailFormGUI::$mfile
private

Definition at line 67 of file class.ilMailFormGUI.php.

◆ $purifier

ilMailFormGUI::$purifier
private

Definition at line 72 of file class.ilMailFormGUI.php.

◆ $rbacsystem

ilMailFormGUI::$rbacsystem
private

Definition at line 52 of file class.ilMailFormGUI.php.

◆ $tabs

ilMailFormGUI::$tabs
private

Definition at line 42 of file class.ilMailFormGUI.php.

◆ $toolbar

ilMailFormGUI::$toolbar
private

Definition at line 47 of file class.ilMailFormGUI.php.

◆ $tpl

ilMailFormGUI::$tpl
private

Definition at line 22 of file class.ilMailFormGUI.php.

Referenced by showSubmissionErrors().

◆ $umail

ilMailFormGUI::$umail
private

Definition at line 57 of file class.ilMailFormGUI.php.

◆ $user

ilMailFormGUI::$user
private

Definition at line 37 of file class.ilMailFormGUI.php.


The documentation for this class was generated from the following file: