ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilMailFormGUI Class Reference
+ Collaboration diagram for ilMailFormGUI:

Public Member Functions

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

Protected Member Functions

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

Private Attributes

 $tpl = null
 
 $ctrl = null
 
 $lng = null
 
 $umail = null
 
 $mbox = null
 
 $mfile = null
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilMailFormGUI::__construct ( )

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

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 }
$_GET["client_id"]
$_POST["username"]
This class handles all operations on files (attachments) in directory ilias_data/mail.
Class UserMail this class handles user mails.
global $ilCtrl
Definition: ilias.php:18
$ilUser
Definition: imgupload.php:18

References $_GET, $_POST, $ilCtrl, $ilUser, $lng, and $tpl.

Member Function Documentation

◆ cancelMail()

ilMailFormGUI::cancelMail ( )

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

844 {
847 else
848 return $this->showForm();
849 }
static redirect($a_script)
http redirect to other script

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

+ Here is the call graph for this function:

◆ cancelSearch()

ilMailFormGUI::cancelSearch ( )

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

338 {
339 unset($_SESSION["mail_search"]);
340 $this->searchResults();
341 }
$_SESSION["AccountId"]

References $_SESSION, and searchResults().

+ Here is the call graph for this function:

◆ decodeAttachmentFiles()

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

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

115 {
116 $decodedFiles = array();
117
118 foreach($files as $value)
119 {
120 if(is_file($this->mfile->getMailPath() . '/' . $GLOBALS['DIC']->user()->getId() . '_' . urldecode($value)))
121 {
122 $decodedFiles[] = urldecode($value);
123 }
124 }
125
126 return $decodedFiles;
127 }
$files
Definition: add-vimline.php:18
$GLOBALS['loaded']
Global hash that tracks already loaded includes.

References $files, and $GLOBALS.

Referenced by saveDraft(), and sendMessage().

+ Here is the caller graph for this function:

◆ editAttachments()

ilMailFormGUI::editAttachments ( )

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

344 {
345 // decode post values
346 $files = array();
347 if(is_array($_POST['attachments']))
348 {
349 foreach($_POST['attachments'] as $value)
350 {
351 $files[] = urldecode($value);
352 }
353 }
354
355 // Note: For security reasons, ILIAS only allows Plain text messages.
356 $this->umail->savePostData($GLOBALS['DIC']['ilUser']->getId(),
357 $files,
361 $_POST["m_type"],
363 ilUtil::securePlainString($_POST["m_subject"]),
364 ilUtil::securePlainString($_POST["m_message"]),
365 ilUtil::securePlainString($_POST['use_placeholders']),
368 );
369
370 $this->ctrl->redirectByClass("ilmailattachmentgui");
371 }
static securePlainString($a_str)
Remove unsecure characters from a plain text string.

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

+ Here is the call graph for this function:

◆ executeCommand()

ilMailFormGUI::executeCommand ( )

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

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 }
$cmd
Definition: sahs_server.php:35

References $cmd.

◆ getAjaxPlaceholdersById()

ilMailFormGUI::getAjaxPlaceholdersById ( )

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

898 {
899 $context_id = ilUtil::stripSlashes($_GET['context_id']);
900 require_once 'Services/Mail/classes/class.ilMailTemplateService.php';
901 require_once 'Services/Mail/classes/Form/class.ilManualPlaceholderInputGUI.php';
902 $placeholders = new ilManualPlaceholderInputGUI($this->ctrl->getLinkTarget($this, 'getAjaxPlaceholdersById', '', true, false));
903 $context = ilMailTemplateService::getTemplateContextById($context_id);
904 foreach($context->getPlaceholders() as $key => $value)
905 {
906 $placeholders->addPlaceholder($value['placeholder'], $value['label'] );
907 }
908 $placeholders->render(true);
909 exit();
910 }
Class ilManualPlaceholderInputGUI.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled

References $_GET, exit, ilMailTemplateService\getTemplateContextById(), and ilUtil\stripSlashes().

+ Here is the call graph for this function:

◆ getTemplateDataById()

ilMailFormGUI::getTemplateDataById ( )
protected

Called asynchronously when changing the template.

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

413 {
414 require_once 'Services/JSON/classes/class.ilJsonUtil.php';
415
416 if(!isset($_GET['template_id']))
417 {
418 exit();
419 }
420
421 try
422 {
423 require_once 'Services/Mail/classes/class.ilMailTemplateService.php';
424 require_once 'Services/Mail/classes/class.ilMailTemplateDataProvider.php';
425 $template_id = (int)$_GET['template_id'];
426 $template_provider = new ilMailTemplateDataProvider();
427 $template = $template_provider->getTemplateById($template_id);
428 $context = ilMailTemplateService::getTemplateContextById($template->getContext());
429 echo ilJsonUtil::encode(array(
430 'm_subject' => $template->getSubject(),
431 'm_message' => $template->getMessage()
432 ));
433 }
434 catch(Exception $e)
435 {
436 }
437 exit();
438 }
static encode($mixed, $suppress_native=false)
Class ilMailTemplateDataProvider.
$template_id
Definition: example_062.php:89

References $_GET, $template_id, ilJsonUtil\encode(), exit, and ilMailTemplateService\getTemplateContextById().

+ Here is the call graph for this function:

◆ lookupRecipientAsync()

ilMailFormGUI::lookupRecipientAsync ( )

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

810 {
811 include_once 'Services/JSON/classes/class.ilJsonUtil.php';
812 include_once 'Services/Mail/classes/class.ilMailForm.php';
813 $search = '';
814 if (isset($_GET["term"]) && is_string($_GET["term"])) {
815 $search = $_GET["term"];
816 }
817 if (isset($_POST["term"]) && is_string($_POST["term"])) {
818 $search = $_POST["term"];
819 }
820
821 $search = trim($search);
822
823 $result = array();
824
825 require_once 'Services/Utilities/classes/class.ilStr.php';
826 if (\ilStr::strLen($search) < 3) {
827 echo json_encode($result);
828 exit;
829 }
830
831 // #14768
832 $quoted = ilUtil::stripSlashes($search);
833 $quoted = str_replace('%', '\%', $quoted);
834 $quoted = str_replace('_', '\_', $quoted);
835
836 $mailFormObj = new ilMailForm;
837 $result = $mailFormObj->getRecipientAsync("%" . $quoted . "%", ilUtil::stripSlashes($search));
838
839 echo json_encode($result);
840 exit;
841 }
$result
static strLen($a_string)
Definition: class.ilStr.php:91

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

+ Here is the call graph for this function:

◆ mailAttachment()

ilMailFormGUI::mailAttachment ( )

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

404 {
405 $_GET["type"] = "attach";
406 $this->showForm();
407 }

References $_GET.

◆ mailRole()

ilMailFormGUI::mailRole ( )

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

392 {
393 $_GET["type"] = "role";
394 $this->showForm();
395 }

References $_GET.

◆ mailUser()

ilMailFormGUI::mailUser ( )

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

386 {
387 $_GET["type"] = "new";
388 $this->showForm();
389 }

References $_GET.

◆ replyMail()

ilMailFormGUI::replyMail ( )

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

398 {
399 $_GET["type"] = "reply";
400 $this->showForm();
401 }

References $_GET.

◆ returnFromAttachments()

ilMailFormGUI::returnFromAttachments ( )

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

374 {
375 $_GET["type"] = "attach";
376 $this->showForm();
377 }

References $_GET.

◆ saveDraft()

ilMailFormGUI::saveDraft ( )

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

174 {
175 if(!$_POST['m_subject'])
176 {
177 $_POST['m_subject'] = 'No title';
178 }
179
180 $draftFolderId = $this->mbox->getDraftsFolder();
181 $files = $this->decodeAttachmentFiles(isset($_POST['attachments']) ? (array)$_POST['attachments'] : array());
182
183 if($errors = $this->umail->validateRecipients(
187 ))
188 {
189 $_POST['attachments'] = $files;
191 $this->showForm();
192 return;
193 }
194
195 if(isset($_SESSION["draft"]))
196 {
197 $draftId = (int)$_SESSION['draft'];
198 unset($_SESSION['draft']);
199 }
200 else
201 {
202 $draftId = $this->umail->getNewDraftId($GLOBALS['DIC']->user()->getId(), $draftFolderId);
203 }
204
205 $this->umail->updateDraft($draftFolderId, $files,
209 $_POST['m_type'],
211 ilUtil::securePlainString($_POST['m_subject']),
212 ilUtil::securePlainString($_POST['m_message']),
213 $draftId,
214 (int)$_POST['use_placeholders'],
217 );
218
219 ilUtil::sendInfo($this->lng->txt('mail_saved'), true);
220
223 else
224 $this->ctrl->redirectByClass("ilmailfoldergui");
225
226 $this->showForm();
227 }
user()
Definition: user.php:4
showSubmissionErrors(array $errors)
decodeAttachmentFiles(array $files)
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$errors

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

+ Here is the call graph for this function:

◆ search()

ilMailFormGUI::search ( )

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

314 {
315 $_SESSION["mail_search_search"] = $_POST["search"];
316 if(strlen(trim($_SESSION["mail_search_search"])) == 0)
317 {
318 ilUtil::sendInfo($this->lng->txt("mail_insert_query"));
319 $this->searchUsers(false);
320 }
321 else
322 {
323 if(strlen(trim($_SESSION["mail_search_search"])) < 3)
324 {
325 $this->lng->loadLanguageModule('search');
326 ilUtil::sendInfo($this->lng->txt('search_minimum_three'));
327 $this->searchUsers(false);
328 }
329 else
330 {
331 $this->ctrl->setParameterByClass("ilmailsearchgui", "search", urlencode($_SESSION["mail_search_search"]));
332 $this->ctrl->redirectByClass("ilmailsearchgui");
333 }
334 }
335 }
searchUsers($save=true)

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

+ Here is the call graph for this function:

◆ searchCoursesTo()

ilMailFormGUI::searchCoursesTo ( )

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

290 {
291 $this->saveMailBeforeSearch();
292
293 if($_SESSION['search_crs'])
294 {
295 $this->ctrl->setParameterByClass('ilmailsearchcoursesgui', 'cmd', 'showMembers');
296 }
297
298 $this->ctrl->setParameterByClass('ilmailsearchcoursesgui', 'ref', 'mail');
299 $this->ctrl->redirectByClass('ilmailsearchcoursesgui');
300 }

References $_SESSION.

◆ searchGroupsTo()

ilMailFormGUI::searchGroupsTo ( )

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

306 {
307 $this->saveMailBeforeSearch();
308
309 $this->ctrl->setParameterByClass('ilmailsearchgroupsgui', 'ref', 'mail');
310 $this->ctrl->redirectByClass('ilmailsearchgroupsgui');
311 }

◆ searchMailingListsTo()

ilMailFormGUI::searchMailingListsTo ( )

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

890 {
891 $this->saveMailBeforeSearch();
892
893 $this->ctrl->setParameterByClass('ilmailinglistsgui', 'ref', 'mail');
894 $this->ctrl->redirectByClass('ilmailinglistsgui');
895 }

◆ searchResults()

ilMailFormGUI::searchResults ( )

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

380 {
381 $_GET["type"] = "search_res";
382 $this->showForm();
383 }

References $_GET.

Referenced by cancelSearch().

+ Here is the caller graph for this function:

◆ searchUsers()

ilMailFormGUI::searchUsers (   $save = true)

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

230 {
231 global $ilUser, $ilCtrl;
232
233 $this->tpl->setTitle($this->lng->txt("mail"));
234
235 if ($save)
236 {
237 // decode post values
238 $files = array();
239 if(is_array($_POST['attachments']))
240 {
241 foreach($_POST['attachments'] as $value)
242 {
243 $files[] = urldecode($value);
244 }
245 }
246
247 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
248 $this->umail->savePostData($ilUser->getId(),
249 $files,
253 $_POST["m_type"],
255 ilUtil::securePlainString($_POST["m_subject"]),
256 ilUtil::securePlainString($_POST["m_message"]),
257 ilUtil::securePlainString($_POST['use_placeholders']),
260 );
261 }
262 include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
263 $form = new ilPropertyFormGUI();
264 $form->setId('search_rcp');
265 $form->setTitle($this->lng->txt('search_recipients'));
266 $form->setFormAction($ilCtrl->getFormAction($this, 'search'));
267
268 $inp = new ilTextInputGUI($this->lng->txt("search_for"), 'search');
269 $inp->setSize(30);
270 $dsDataLink = $ilCtrl->getLinkTarget($this, 'lookupRecipientAsync', '', true, false);
271 $inp->setDataSource($dsDataLink);
272
273 if (strlen(trim($_SESSION["mail_search_search"])) > 0)
274 {
275 $inp->setValue(ilUtil::prepareFormOutput(trim($_SESSION["mail_search_search"]), true));
276 }
277 $form->addItem($inp);
278
279 $form->addCommandButton('search', $this->lng->txt("search"));
280 $form->addCommandButton('cancelSearch', $this->lng->txt("cancel"));
281
282 $this->tpl->setContent($form->getHtml());
283 $this->tpl->show();
284 }
This class represents a property form user interface.
This class represents a text property in a property form.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public

References $_POST, $_SESSION, $files, $ilCtrl, $ilUser, ilMailFormCall\getContextId(), ilMailFormCall\getContextParameters(), ilUtil\prepareFormOutput(), and ilUtil\securePlainString().

Referenced by search().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendMessage()

ilMailFormGUI::sendMessage ( )

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

130 {
131 $m_type = isset($_POST["m_type"]) ? $_POST["m_type"] : array("normal");
132
133 $message = strip_tags(ilUtil::stripSlashes($_POST['m_message'], false));
134 $message = str_replace("\r", '', $message);
135 // Note: For security reasons, ILIAS only allows Plain text strings in E-Mails.
136 $message = $this->umail->formatLinebreakMessage($message);
137
138 $files = $this->decodeAttachmentFiles(isset($_POST['attachments']) ? (array)$_POST['attachments'] : array());
139
140 $this->umail->setSaveInSentbox(true);
141 if($errors = $this->umail->sendMail(
145 ilUtil::securePlainString($_POST['m_subject']), $message,
146 $files,
147 $m_type,
148 (int)$_POST['use_placeholders']
149 )
150 )
151 {
152 $_POST['attachments'] = $files;
154 }
155 else
156 {
157 $this->umail->savePostData($GLOBALS['DIC']->user()->getId(), array(), "", "", "", "", "", "", "", "");
158
159 $this->ctrl->setParameterByClass('ilmailgui', 'type', 'message_sent');
160
162 {
163 ilUtil::sendInfo($this->lng->txt('mail_message_send'), true);
165 }
166 else
167 $this->ctrl->redirectByClass('ilmailgui');
168 }
169
170 $this->showForm();
171 }

References $_POST, $errors, $files, $GLOBALS, decodeAttachmentFiles(), ilMailFormCall\getRefererRedirectUrl(), ilMailFormCall\isRefererStored(), ilUtil\redirect(), ilUtil\securePlainString(), ilUtil\sendInfo(), showSubmissionErrors(), ilUtil\stripSlashes(), and user().

+ Here is the call graph for this function:

◆ showSubmissionErrors()

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

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

916 {
917 $errors_to_display = array();
918
919 foreach($errors as $error)
920 {
921 $error = array_values($error);
922 $first_error = array_shift($error);
923
924 $translation = $this->lng->txt($first_error);
925 if($translation == '-' . $first_error . '-')
926 {
927 $translation = $first_error;
928 }
929
930 if(count($error) == 0 || $translation == $first_error)
931 {
932 $errors_to_display[] = $translation;
933 }
934 else
935 {
936 // We expect all other parts of this error array are recipient addresses = input parameters
937 $error = array_map(function($address) {
938 return ilUtil::prepareFormOutput($address);
939 }, $error);
940
941 array_unshift($error, $translation);
942 $errors_to_display[] = call_user_func_array('sprintf', $error);
943 }
944 }
945
946 if(count($errors_to_display) > 0)
947 {
948 $tpl = new ilTemplate('tpl.mail_new_submission_errors.html', true, true, 'Services/Mail');
949 if(count($errors_to_display) == 1)
950 {
951 $tpl->setCurrentBlock('single_error');
952 $tpl->setVariable('SINGLE_ERROR', current($errors_to_display));
953 $tpl->parseCurrentBlock();
954 }
955 else
956 {
957 $first_error = array_shift($errors_to_display);
958
959 foreach($errors_to_display as $error)
960 {
961 $tpl->setCurrentBlock('error_loop');
962 $tpl->setVariable('ERROR', $error);
963 $tpl->parseCurrentBlock();
964 }
965
966 $tpl->setCurrentBlock('multiple_errors');
967 $tpl->setVariable('FIRST_ERROR', $first_error);
968 $tpl->parseCurrentBlock();
969 }
970
971 ilUtil::sendInfo($tpl->get());
972 }
973 }
$error
Definition: Error.php:17
special template class to simplify handling of ITX/PEAR

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

Referenced by saveDraft(), and sendMessage().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $ctrl

ilMailFormGUI::$ctrl = null
private

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

◆ $lng

ilMailFormGUI::$lng = null
private

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

Referenced by __construct().

◆ $mbox

ilMailFormGUI::$mbox = null
private

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

◆ $mfile

ilMailFormGUI::$mfile = null
private

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

◆ $tpl

ilMailFormGUI::$tpl = null
private

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

Referenced by __construct(), and showSubmissionErrors().

◆ $umail

ilMailFormGUI::$umail = null
private

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


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