ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilMailFolderTableGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/Table/classes/class.ilTable2GUI.php';
5require_once 'Services/Mail/classes/class.ilMailUserCache.php';
6require_once 'Services/Mail/classes/class.ilMailBoxQuery.php';
7
15{
19 protected $lng;
20
24 protected $ctrl;
25
29 protected $user;
30
31 protected $_folderNode = array();
32 protected $_parentObject = null;
33 protected $_currentFolderId = 0;
34 protected $_number_of_mails = 0;
35 protected $_selectedItems = array();
36 protected $_isTrashFolder = false;
37 protected $_isDraftsFolder = false;
38 protected $_isSentFolder = false;
39
43 protected $filter = array();
44
48 protected $sub_filter = array();
49
58 public function __construct($a_parent_obj, $a_current_folder_id, $a_parent_cmd = '')
59 {
60 global $DIC;
61
62 $this->lng = $DIC->language();
63 $this->ctrl = $DIC->ctrl();
64 $this->user = $DIC->user();
65
66 $this->_currentFolderId = $a_current_folder_id;
67 $this->_parentObject = $a_parent_obj;
68
69 $this->setId('mail_folder_tbl_' . $a_current_folder_id);
70 $this->setPrefix('mtable');
71
72 $this->setExternalSorting(true);
73 $this->setExternalSegmentation(true);
74 $this->setDefaultOrderField('send_time');
75 $this->setDefaultOrderDirection('desc');
76
77 parent::__construct($a_parent_obj, $a_parent_cmd);
78
79 $this->setFormAction($this->ctrl->getFormAction($this->_parentObject, 'showFolder'));
80
81 $this->setEnableTitle(true);
82 $this->setSelectAllCheckbox('mail_id[]');
83 $this->setRowTemplate('tpl.mail_folder_row.html', 'Services/Mail');
84
85 $this->setFilterCommand('applyFilter');
86 $this->setResetCommand('resetFilter');
87 }
88
96 final public function prepareHTML()
97 {
98 $this->addColumn('', '', '1px', true);
99 $this->addColumn($this->lng->txt('personal_picture'), '', '10%');
100 if ($this->isDraftFolder() || $this->isSentFolder()) {
101 $this->addColumn($this->lng->txt('recipient'), 'rcp_to', '25%');
102 } else {
103 $this->addColumn($this->lng->txt('sender'), 'from', '25%');
104 }
105
106 if ($this->isLuceneSearchEnabled()) {
107 $this->addColumn($this->lng->txt('search_content'), '', '40%');
108 } else {
109 $this->addColumn($this->lng->txt('subject'), 'm_subject', '40%');
110 }
111 $this->addColumn($this->lng->txt('date'), 'send_time', '20%');
112
113 // init folder data
114 $mtree = new ilTree($this->user->getId());
115 $mtree->setTableNames('mail_tree', 'mail_obj_data');
116 $this->_folderNode = $mtree->getNodeData($this->_currentFolderId);
117
118 // fetch table data
119 $this->fetchTableData();
120
121 // command buttons
122 $this->initCommandButtons();
123
124 // mail actions
125 $this->initMultiCommands($this->_parentObject->mbox->getActions($this->_currentFolderId));
126
127 return $this;
128 }
129
137 public function isDraftFolder($a_bool = null)
138 {
139 if (null === $a_bool) {
141 }
142
143 $this->_isDraftsFolder = $a_bool;
144
145 return $this;
146 }
147
155 public function isSentFolder($a_bool = null)
156 {
157 if (null === $a_bool) {
159 }
160
161 $this->_isSentFolder = $a_bool;
162
163 return $this;
164 }
165
173 public function isTrashFolder($a_bool = null)
174 {
175 if (null === $a_bool) {
177 }
178
179 $this->_isTrashFolder = $a_bool;
180
181 return $this;
182 }
183
191 private function initCommandButtons()
192 {
193 if ($this->_folderNode['m_type'] == 'trash' && $this->getNumerOfMails() > 0) {
194 $this->addCommandButton('askForEmptyTrash', $this->lng->txt('mail_empty_trash'));
195 }
196
197 return $this;
198 }
199
207 private function initMultiCommands($actions)
208 {
209 foreach ($actions as $key => $action) {
210 if ($key == 'moveMails') {
211 $folders = $this->_parentObject->mbox->getSubFolders();
212 foreach ($folders as $folder) {
213 if ($folder['type'] != 'trash' ||
214 !$this->isTrashFolder()
215 ) {
216 if ($folder['type'] != 'user_folder') {
217 $label = $action . ' ' . $this->lng->txt('mail_' . $folder['title']) .
218 ($folder['type'] == 'trash' ? ' (' . $this->lng->txt('delete') . ')' : '');
219 $this->addMultiCommand($folder['obj_id'], $label);
220 } else {
221 $this->addMultiCommand($folder['obj_id'], $action . ' ' . $folder['title']);
222 }
223 }
224 }
225 } else {
226 if ($key != 'deleteMails' || $this->isTrashFolder()) {
228 }
229 }
230 }
231
232 return $this;
233 }
234
242 public function setSelectedItems($a_selected_items)
243 {
244 $this->_selectedItems = $a_selected_items;
245
246 return $this;
247 }
248
255 public function getSelectedItems()
256 {
258 }
259
263 protected function isLuceneSearchEnabled()
264 {
265 include_once 'Services/Search/classes/class.ilSearchSettings.php';
266 if (ilSearchSettings::getInstance()->enabledLucene() && strlen($this->filter['mail_filter'])) {
267 return true;
268 }
269 }
270
275 protected function fetchTableData()
276 {
277 if ($this->_folderNode['m_type'] == 'user_folder') {
278 $txt_folder = $this->_folderNode['title'];
279 $img_folder = 'icon_user_folder.png';
280 } else {
281 $txt_folder = $this->lng->txt('mail_' . $this->_folderNode['title']);
282 $img_folder = 'icon' . substr($this->_folderNode['title'], 1) . '.png';
283 }
284
285 try {
286 if ($this->isLuceneSearchEnabled()) {
287 include_once 'Services/Mail/classes/class.ilMailLuceneQueryParser.php';
288 $query_parser = new ilMailLuceneQueryParser($this->filter['mail_filter']);
289 $query_parser->setFields(array(
290 'title' => (bool) $this->filter['mail_filter_subject'],
291 'content' => (bool) $this->filter['mail_filter_body'],
292 'mattachment' => (bool) $this->filter['mail_filter_attach'],
293 'msender' => (bool) $this->filter['mail_filter_sender'],
294 'mrcp' => (bool) $this->filter['mail_filter_recipients']
295 ));
296 $query_parser->parse();
297
298 require_once 'Services/Mail/classes/class.ilMailLuceneSearcher.php';
299 require_once 'Services/Mail/classes/class.ilMailSearchResult.php';
301 $searcher = new ilMailLuceneSearcher($query_parser, $result);
302 $searcher->search($this->user->getId(), $this->_currentFolderId);
303
304 if (!$result->getIds()) {
305 throw new ilException('mail_search_empty_result');
306 }
307
309 ilMailBoxQuery::$filter = array();
310 } else {
311 ilMailBoxQuery::$filter = (array) $this->filter;
312 }
313
315
317 ilMailBoxQuery::$userId = $this->user->getId();
323
324 if (!count($data['set']) && $this->getOffset() > 0) {
325 $this->resetOffset();
326
330 }
331 } catch (Exception $e) {
332 $this->setTitleData($txt_folder, 0, 0, $img_folder);
333
334 if ('mail_search_empty_result' == $e->getMessage()) {
335 $data['set'] = array();
336 $data['cnt'] = 0;
337 } else {
338 throw $e;
339 }
340 }
341
342 if (!$this->isDraftFolder() && !$this->isSentFolder()) {
343 $user_ids = array();
344 foreach ($data['set'] as $mail) {
345 if ($mail['sender_id'] && $mail['sender_id'] != ANONYMOUS_USER_ID) {
346 $user_ids[$mail['sender_id']] = $mail['sender_id'];
347 }
348 }
349
351 }
352
353 $counter = 0;
354 foreach ($data['set'] as $key => $mail) {
355 ++$counter;
356
357 if (is_array($this->getSelectedItems()) && in_array($mail['mail_id'], $this->getSelectedItems())) {
358 $mail['checked'] = ' checked="checked" ';
359 }
360
361 if ($this->isDraftFolder() || $this->isSentFolder()) {
362 $mail['rcp_to'] = $mail['mail_login'] = ilUtil::htmlencodePlainString(
363 $this->_parentObject->umail->formatNamesForOutput($mail['rcp_to']),
364 false
365 );
366 } else {
367 if ($mail['sender_id'] == ANONYMOUS_USER_ID) {
368 $mail['img_sender'] = ilUtil::getImagePath('HeaderIconAvatar.svg');
369 $mail['from'] = $mail['mail_login'] = $mail['alt_sender'] = htmlspecialchars(ilMail::_getIliasMailerName());
370 } else {
371 $user = ilMailUserCache::getUserObjectById($mail['sender_id']);
372 if ($user) {
373 $mail['img_sender'] = $user->getPersonalPicturePath('xxsmall');
374 $mail['from'] = $mail['mail_login'] = $mail['alt_sender'] = htmlspecialchars($user->getPublicName());
375 } else {
376 $mail['from'] = $mail['mail_login'] = $mail['import_name'] . ' (' . $this->lng->txt('user_deleted') . ')';
377 }
378 }
379 }
380
381 if ($this->isDraftFolder()) {
382 $this->ctrl->setParameterByClass('ilmailformgui', 'mail_id', $mail['mail_id']);
383 $this->ctrl->setParameterByClass('ilmailformgui', 'type', 'draft');
384 $link_mark_as_read = $this->ctrl->getLinkTargetByClass('ilmailformgui');
385 $this->ctrl->clearParametersByClass('ilmailformgui');
386 } else {
387 $this->ctrl->setParameter($this->_parentObject, 'mail_id', $mail['mail_id']);
388 $link_mark_as_read = $this->ctrl->getLinkTarget($this->_parentObject, 'showMail');
389 $this->ctrl->clearParameters($this->_parentObject);
390 }
391 $css_class = $mail['m_status'] == 'read' ? 'mailread' : 'mailunread';
392
393 if ($this->isLuceneSearchEnabled()) {
394 $search_result = array();
395 foreach ($result->getFields($mail['mail_id']) as $content) {
396 if ('title' == $content[0]) {
397 $mail['msr_subject_link_read'] = $link_mark_as_read;
398 $mail['msr_subject_mailclass'] = $css_class;
399 $mail['msr_subject'] = $content[1];
400 } else {
401 $search_result[] = $content[1];
402 }
403 }
404 $mail['msr_data'] = implode('', array_map(function ($value) {
405 return '<p>' . $value . '</p>';
406 }, $search_result));
407
408 if (!$mail['msr_subject']) {
409 $mail['msr_subject_link_read'] = $link_mark_as_read;
410 $mail['msr_subject_mailclass'] = $css_class;
411 $mail['msr_subject'] = htmlspecialchars($mail['m_subject']);
412 }
413 } else {
414 $mail['mail_link_read'] = $link_mark_as_read;
415 $mail['mailclass'] = $css_class;
416 $mail['mail_subject'] = htmlspecialchars($mail['m_subject']);
417 }
418
419 $mail['mail_date'] = ilDatePresentation::formatDate(new ilDateTime($mail['send_time'], IL_CAL_DATETIME));
420
421 $data['set'][$key] = $mail;
422 }
423
424 $this->setData($data['set']);
425 $this->setMaxCount($data['cnt']);
426 $this->setNumerOfMails($data['cnt']);
427
428 $this->setTitleData($txt_folder, $data['cnt'], $data['cnt_unread'], $img_folder);
429
430 return $this;
431 }
432
443 protected function setTitleData($folderLabel, $mailCount, $unreadCount, $imgFolder)
444 {
445 $titleTemplate = new ilTemplate('tpl.mail_folder_title.html', true, true, 'Services/Mail');
446 $titleTemplate->setVariable('TXT_FOLDER', $folderLabel);
447 $titleTemplate->setVariable('MAIL_COUNT', $mailCount);
448 $titleTemplate->setVariable('TXT_MAIL_S', $this->lng->txt('mail_s'));
449 $titleTemplate->setVariable('MAIL_COUNT_UNREAD', $unreadCount);
450 $titleTemplate->setVariable('TXT_UNREAD', $this->lng->txt('unread'));
451
452 parent::setTitle($titleTemplate->get(), $imgFolder);
453
454 return $this;
455 }
456
464 public function setNumerOfMails($a_number_of_mails)
465 {
466 $this->_number_of_mails = $a_number_of_mails;
467
468 return $this;
469 }
470
477 public function getNumerOfMails()
478 {
480 }
481
488 public function fillRow($a_set)
489 {
490 foreach ($a_set as $key => $value) {
491 $this->tpl->setVariable(strtoupper($key), $value);
492 }
493 }
494
495 public function initFilter()
496 {
497 $this->filter = array();
498
499 include_once 'Services/Mail/classes/Form/class.ilMailQuickFilterInputGUI.php';
500 $ti = new ilMailQuickFilterInputGUI($this->lng->txt('mail_filter'), 'mail_filter');
501 $ti->setSubmitFormOnEnter(false);
502 $this->addFilterItem($ti);
503 $ti->readFromSession();
504 $this->filter['mail_filter'] = $ti->getValue();
505
506 include_once 'Services/Form/classes/class.ilCheckboxInputGUI.php';
507
508 if ($this->isDraftFolder() || $this->isSentFolder()) {
509 $this->sub_filter[] = $ci = new ilCheckboxInputGUI($this->lng->txt('mail_filter_recipients'), 'mail_filter_recipients');
510 $ci->setOptionTitle($this->lng->txt('mail_filter_recipients'));
511 $ci->setValue(1);
512 $ti->addSubItem($ci);
513 $ci->setParent($this);
514 $ci->readFromSession();
515 $this->filter['mail_filter_recipients'] = (int) $ci->getChecked();
516 } else {
517 $this->sub_filter[] = $ci = new ilCheckboxInputGUI($this->lng->txt('mail_filter_sender'), 'mail_filter_sender');
518 $ci->setOptionTitle($this->lng->txt('mail_filter_sender'));
519 $ci->setValue(1);
520 $ti->addSubItem($ci);
521 $ci->setParent($this);
522 $ci->readFromSession();
523 $this->filter['mail_filter_sender'] = (int) $ci->getChecked();
524 }
525
526 $this->sub_filter[] = $ci = new ilCheckboxInputGUI($this->lng->txt('mail_filter_subject'), 'mail_filter_subject');
527 $ci->setOptionTitle($this->lng->txt('mail_filter_subject'));
528 $ci->setValue(1);
529 $ti->addSubItem($ci);
530 $ci->setParent($this);
531 $ci->readFromSession();
532 $this->filter['mail_filter_subject'] = (int) $ci->getChecked();
533
534 $this->sub_filter[] = $ci = new ilCheckboxInputGUI($this->lng->txt('mail_filter_body'), 'mail_filter_body');
535 $ci->setOptionTitle($this->lng->txt('mail_filter_body'));
536 $ci->setValue(1);
537 $ti->addSubItem($ci);
538 $ci->setParent($this);
539 $ci->readFromSession();
540 $this->filter['mail_filter_body'] = (int) $ci->getChecked();
541
542 $this->sub_filter[] = $ci = new ilCheckboxInputGUI($this->lng->txt('mail_filter_attach'), 'mail_filter_attach');
543 $ci->setOptionTitle($this->lng->txt('mail_filter_attach'));
544 $ci->setValue(1);
545 $ti->addSubItem($ci);
546 $ci->setParent($this);
547 $ci->readFromSession();
548 $this->filter['mail_filter_attach'] = (int) $ci->getChecked();
549 }
550
554 public function writeFilterToSession()
555 {
556 parent::writeFilterToSession();
557
558 foreach ($this->sub_filter as $item) {
559 if ($item->checkInput()) {
560 $item->setValueByArray($_POST);
561 $item->writeToSession();
562 }
563 }
564 }
565
569 public function resetFilter()
570 {
571 parent::resetFilter();
572
573 foreach ($this->sub_filter as $item) {
574 if ($item->checkInput()) {
575 $item->setValueByArray($_POST);
576 $item->clearFromSession();
577 }
578 }
579 }
580}
$result
user()
Definition: user.php:4
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
This class represents a checkbox property in a property form.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date @access public.
@classDescription Date and time handling
Base class for ILIAS Exception handling.
static _getMailBoxListData()
_getMailBoxListData
getNumerOfMails()
Returns the total number of mails of the current folder @access public.
writeFilterToSession()
Write filter values to session.
fillRow($a_set)
Fill row @access public.
isSentFolder($a_bool=null)
Setter/Getter for folder status @access public.
setNumerOfMails($a_number_of_mails)
Set the total number of mails of the current folder @access public.
isTrashFolder($a_bool=null)
Setter/Getter for folder status @access public.
setSelectedItems($a_selected_items)
Set the selected items @access public.
getSelectedItems()
Get all selected items @access public.
__construct($a_parent_obj, $a_current_folder_id, $a_parent_cmd='')
Constructor @access public.
isDraftFolder($a_bool=null)
Setter/Getter for folder status @access public.
initMultiCommands($actions)
initMultiCommands @access private
initCommandButtons()
Performs special actions for folders such as user folders, trash and local folders @access private.
setTitleData($folderLabel, $mailCount, $unreadCount, $imgFolder)
Function to set the table title @access protected.
prepareHTML()
Call this before using getHTML() @access public.
static getUserObjectById($usr_id)
static preloadUserObjects(array $usr_ids)
Class ilTable2GUI.
setExternalSorting($a_val)
Set external sorting.
setPrefix($a_prefix)
set prefix for sort and offset fields (if you have two or more tables on a page that you want to sort...
determineOffsetAndOrder($a_omit_offset=false)
Determine offset and order.
setData($a_data)
set table data @access public
setResetCommand($a_val, $a_caption=null)
Set reset filter command.
setEnableTitle($a_enabletitle)
Set Enable Title.
getLimit()
Get limit.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
resetOffset($a_in_determination=false)
Reset offset.
addMultiCommand($a_cmd, $a_text)
Add Command button.
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
getOffset()
Get offset.
setExternalSegmentation($a_val)
Set external segmentation.
setId($a_val)
Set id.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
setFilterCommand($a_val, $a_caption=null)
Set filter command.
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
getOrderDirection()
Get order direction.
setMaxCount($a_max_count)
set max.
special template class to simplify handling of ITX/PEAR
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
static htmlencodePlainString($a_str, $a_make_links_clickable, $a_detect_goto_links=false)
Encodes a plain text string into HTML for display in a browser.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$counter
$action
$key
Definition: croninfo.php:18
global $DIC
Definition: saml.php:7