ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
4 require_once 'Services/Table/classes/class.ilTable2GUI.php';
5 require_once 'Services/Mail/classes/class.ilMailUserCache.php';
6 require_once 'Services/Mail/classes/class.ilMailBoxQuery.php';
7 
15 {
16  protected $lng = null;
17  protected $ctrl = null;
18 
19  protected $_folderNode = array();
20  protected $_parentObject = null;
21  protected $_currentFolderId = 0;
22  protected $_number_of_mails = 0;
23  protected $_selectedItems = array();
24  protected $_isTrashFolder = false;
25  protected $_isDraftsFolder = false;
26  protected $_isSentFolder = false;
27 
31  protected $filter = array();
32 
36  protected $sub_filter = array();
37 
46  public function __construct($a_parent_obj, $a_current_folder_id, $a_parent_cmd = '')
47  {
52  global $lng, $ilCtrl;
53 
54  $this->lng = $lng;
55  $this->ctrl = $ilCtrl;
56 
57  $this->_currentFolderId = $a_current_folder_id;
58  $this->_parentObject = $a_parent_obj;
59 
60  $this->setId('mail_folder_tbl_'.$a_current_folder_id);
61  $this->setPrefix('mtable');
62 
63  $this->setExternalSorting(true);
64  $this->setExternalSegmentation(true);
65  $this->setDefaultOrderField('send_time');
66  $this->setDefaultOrderDirection('desc');
67 
68  parent::__construct($a_parent_obj, $a_parent_cmd);
69 
70  $this->setFormAction($this->ctrl->getFormAction($this->_parentObject, 'showFolder'));
71 
72  $this->setEnableTitle(true);
73  $this->setSelectAllCheckbox('mail_id[]');
74  $this->setRowTemplate('tpl.mail_folder_row.html', 'Services/Mail');
75 
76  $this->setFilterCommand('applyFilter');
77  $this->setResetCommand('resetFilter');
78  }
79 
87  final public function prepareHTML()
88  {
89  global $ilUser;
90 
91  $this->addColumn('', '', '1px', true);
92  $this->addColumn($this->lng->txt('personal_picture'), '', '10%');
93  if($this->isDraftFolder() || $this->isSentFolder())
94  $this->addColumn($this->lng->txt('recipient'), 'rcp_to', '25%');
95  else
96  $this->addColumn($this->lng->txt('sender'), 'from', '25%');
97 
98  if($this->isLuceneSearchEnabled())
99  {
100  $this->addColumn($this->lng->txt('search_content'), '', '40%');
101  }
102  else
103  {
104  $this->addColumn($this->lng->txt('subject'), 'm_subject', '40%');
105  }
106  $this->addColumn($this->lng->txt('date'), 'send_time', '20%');
107 
108  // init folder data
109  $mtree = new ilTree($ilUser->getId());
110  $mtree->setTableNames('mail_tree', 'mail_obj_data');
111  $this->_folderNode = $mtree->getNodeData($this->_currentFolderId);
112 
113  // fetch table data
114  $this->fetchTableData();
115 
116  // command buttons
117  $this->initCommandButtons();
118 
119  // mail actions
120  $this->initMultiCommands($this->_parentObject->mbox->getActions($this->_currentFolderId));
121 
122  return $this;
123  }
124 
132  public function isDraftFolder($a_bool = null)
133  {
134  if(null === $a_bool)
135  {
136  return $this->_isDraftsFolder;
137  }
138 
139  $this->_isDraftsFolder = $a_bool;
140 
141  return $this;
142  }
143 
151  public function isSentFolder($a_bool = null)
152  {
153  if(null === $a_bool)
154  {
155  return $this->_isSentFolder;
156  }
157 
158  $this->_isSentFolder = $a_bool;
159 
160  return $this;
161  }
162 
170  public function isTrashFolder($a_bool = null)
171  {
172  if(null === $a_bool)
173  {
174  return $this->_isTrashFolder;
175  }
176 
177  $this->_isTrashFolder = $a_bool;
178 
179  return $this;
180  }
181 
189  private function initCommandButtons()
190  {
191  if($this->_folderNode['m_type'] == 'trash' && $this->getNumerOfMails() > 0)
192  {
193  $this->addCommandButton('askForEmptyTrash', $this->lng->txt('mail_empty_trash'));
194  }
195 
196  return $this;
197  }
198 
206  private function initMultiCommands($actions)
207  {
208  foreach($actions as $key => $action)
209  {
210  if($key == 'moveMails')
211  {
212  $folders = $this->_parentObject->mbox->getSubFolders();
213  foreach($folders as $folder)
214  {
215  if($folder['type'] != 'trash' ||
216  !$this->isTrashFolder()
217  )
218  {
219  if($folder['type'] != 'user_folder')
220  {
221  $label = $action . ' ' . $this->lng->txt('mail_' . $folder['title']) .
222  ($folder['type'] == 'trash' ? ' (' . $this->lng->txt('delete') . ')' : '');
223  $this->addMultiCommand($folder['obj_id'], $label);
224  }
225  else
226  $this->addMultiCommand($folder['obj_id'], $action . ' ' . $folder['title']);
227  }
228  }
229  }
230  else
231  {
232  if($key != 'deleteMails' || $this->isTrashFolder())
233  $this->addMultiCommand($key, $action);
234  }
235  }
236 
237  return $this;
238  }
239 
247  public function setSelectedItems($a_selected_items)
248  {
249  $this->_selectedItems = $a_selected_items;
250 
251  return $this;
252  }
253 
260  public function getSelectedItems()
261  {
262  return $this->_selectedItems;
263  }
264 
268  protected function isLuceneSearchEnabled()
269  {
270  include_once 'Services/Search/classes/class.ilSearchSettings.php';
271  if(ilSearchSettings::getInstance()->enabledLucene() && strlen($this->filter['mail_filter']))
272  {
273  return true;
274  }
275  }
276 
283  protected function fetchTableData()
284  {
288  global $ilUser;
289 
290  // table title
291  if($this->_folderNode['m_type'] == 'user_folder')
292  {
293  $txt_folder = $this->_folderNode['title'];
294  $img_folder = 'icon_user_folder.png';
295  }
296  else
297  {
298  $txt_folder = $this->lng->txt('mail_' . $this->_folderNode['title']);
299  $img_folder = 'icon' . substr($this->_folderNode['title'], 1) . '.png';
300  }
301 
302  try
303  {
304  if($this->isLuceneSearchEnabled())
305  {
306  include_once 'Services/Mail/classes/class.ilMailLuceneQueryParser.php';
307  $query_parser = new ilMailLuceneQueryParser($this->filter['mail_filter']);
308  $query_parser->setFields(array(
309  'title' => (bool)$this->filter['mail_filter_subject'],
310  'content' => (bool)$this->filter['mail_filter_body'],
311  'mattachment' => (bool)$this->filter['mail_filter_attach'],
312  'msender' => (bool)$this->filter['mail_filter_sender'],
313  'mrcp' => (bool)$this->filter['mail_filter_recipients']
314  ));
315  $query_parser->parse();
316 
317  require_once 'Services/Mail/classes/class.ilMailLuceneSearcher.php';
318  require_once 'Services/Mail/classes/class.ilMailSearchResult.php';
319  $result = new ilMailSearchResult();
320  $searcher = new ilMailLuceneSearcher($query_parser, $result);
321  $searcher->search($ilUser->getId(), $this->_currentFolderId);
322 
323  if(!$result->getIds())
324  {
325  throw new ilException('mail_search_empty_result');
326  }
327 
330  }
331  else
332  {
333  ilMailBoxQuery::$filter = (array)$this->filter;
334  }
335 
336  $this->determineOffsetAndOrder();
337 
339  ilMailBoxQuery::$userId = $ilUser->getId();
340  ilMailBoxQuery::$limit = $this->getLimit();
344  $data = ilMailBoxQuery::_getMailBoxListData();
345 
346  if(!count($data['set']) && $this->getOffset() > 0)
347  {
348  $this->resetOffset();
349 
350  ilMailBoxQuery::$limit = $this->getLimit();
352  $data = ilMailBoxQuery::_getMailBoxListData();
353  }
354  }
355  catch(Exception $e)
356  {
357  $this->setTitleData($txt_folder, 0, 0, $img_folder);
358 
359  if('mail_search_empty_result' == $e->getMessage())
360  {
361  $data['set'] = array();
362  $data['cnt'] = 0;
363  }
364  else
365  {
366  throw $e;
367  }
368  }
369 
370  if(!$this->isDraftFolder() && !$this->isSentFolder())
371  {
372  $user_ids = array();
373  foreach($data['set'] as $mail)
374  {
375  if($mail['sender_id'] && $mail['sender_id'] != ANONYMOUS_USER_ID)
376  {
377  $user_ids[$mail['sender_id']] = $mail['sender_id'];
378  }
379  }
380 
381  ilMailUserCache::preloadUserObjects($user_ids);
382  }
383 
384  $counter = 0;
385  foreach($data['set'] as $key => $mail)
386  {
387  ++$counter;
388 
389  if(is_array($this->getSelectedItems()) && in_array($mail['mail_id'], $this->getSelectedItems()))
390  {
391  $mail['checked'] = ' checked="checked" ';
392  }
393 
394  if($this->isDraftFolder() || $this->isSentFolder())
395  {
396  $mail['rcp_to'] = $mail['mail_login'] = ilUtil::htmlencodePlainString(
397  $this->_parentObject->umail->formatNamesForOutput($mail['rcp_to']), false
398  );
399  }
400  else
401  {
402  if($mail['sender_id'] == ANONYMOUS_USER_ID)
403  {
404  $mail['img_sender'] = ilUtil::getImagePath('HeaderIconAvatar.svg');
405  $mail['from'] = $mail['mail_login'] = $mail['alt_sender'] = htmlspecialchars(ilMail::_getIliasMailerName());
406  }
407  else
408  {
409  $user = ilMailUserCache::getUserObjectById($mail['sender_id']);
410  if($user)
411  {
412  $mail['img_sender'] = $user->getPersonalPicturePath('xxsmall');
413  $mail['from'] = $mail['mail_login'] = $mail['alt_sender'] = htmlspecialchars($user->getPublicName());
414  }
415  else
416  {
417  $mail['from'] = $mail['mail_login'] = $mail['import_name'] . ' (' . $this->lng->txt('user_deleted') . ')';
418  }
419  }
420  }
421 
422  if($this->isDraftFolder())
423  {
424  $this->ctrl->setParameterByClass('ilmailformgui', 'mail_id', $mail['mail_id']);
425  $this->ctrl->setParameterByClass('ilmailformgui', 'type', 'draft');
426  $link_mark_as_read = $this->ctrl->getLinkTargetByClass('ilmailformgui');
427  $this->ctrl->clearParametersByClass('ilmailformgui');
428  }
429  else
430  {
431  $this->ctrl->setParameter($this->_parentObject, 'mail_id', $mail['mail_id']);
432  $link_mark_as_read = $this->ctrl->getLinkTarget($this->_parentObject, 'showMail');
433  $this->ctrl->clearParameters($this->_parentObject);
434  }
435  $css_class = $mail['m_status'] == 'read' ? 'mailread' : 'mailunread';
436 
437  if($this->isLuceneSearchEnabled())
438  {
439  $search_result = array();
440  foreach($result->getFields($mail['mail_id']) as $content)
441  {
442  if('title' == $content[0])
443  {
444  $mail['msr_subject_link_read'] = $link_mark_as_read;
445  $mail['msr_subject_mailclass'] = $css_class;
446  $mail['msr_subject'] = $content[1];
447  }
448  else
449  {
450  $search_result[] = $content[1];
451  }
452  }
453  $mail['msr_data'] = implode('', array_map(function($value) {
454  return '<p>'.$value.'</p>';
455  }, $search_result));
456 
457  if(!$mail['msr_subject'])
458  {
459  $mail['msr_subject_link_read'] = $link_mark_as_read;
460  $mail['msr_subject_mailclass'] = $css_class;
461  $mail['msr_subject'] = htmlspecialchars($mail['m_subject']);
462  }
463  }
464  else
465  {
466  $mail['mail_link_read'] = $link_mark_as_read;
467  $mail['mailclass'] = $css_class;
468  $mail['mail_subject'] = htmlspecialchars($mail['m_subject']);
469  }
470 
471  $mail['mail_date'] = ilDatePresentation::formatDate(new ilDateTime($mail['send_time'], IL_CAL_DATETIME));
472 
473  $data['set'][$key] = $mail;
474  }
475 
476  $this->setData($data['set']);
477  $this->setMaxCount($data['cnt']);
478  $this->setNumerOfMails($data['cnt']);
479 
480  $this->setTitleData($txt_folder, $data['cnt'], $data['cnt_unread'], $img_folder);
481 
482  return $this;
483  }
484 
495  protected function setTitleData($folderLabel, $mailCount, $unreadCount, $imgFolder)
496  {
497  $titleTemplate = new ilTemplate('tpl.mail_folder_title.html', true, true, 'Services/Mail');
498  $titleTemplate->setVariable('TXT_FOLDER', $folderLabel);
499  $titleTemplate->setVariable('MAIL_COUNT', $mailCount);
500  $titleTemplate->setVariable('TXT_MAIL_S', $this->lng->txt('mail_s'));
501  $titleTemplate->setVariable('MAIL_COUNT_UNREAD', $unreadCount);
502  $titleTemplate->setVariable('TXT_UNREAD', $this->lng->txt('unread'));
503 
504  parent::setTitle($titleTemplate->get(), $imgFolder);
505 
506  return $this;
507  }
508 
516  public function setNumerOfMails($a_number_of_mails)
517  {
518  $this->_number_of_mails = $a_number_of_mails;
519 
520  return $this;
521  }
522 
529  public function getNumerOfMails()
530  {
532  }
533 
540  public function fillRow($a_set)
541  {
542  foreach($a_set as $key => $value)
543  {
544  $this->tpl->setVariable(strtoupper($key), $value);
545  }
546  }
547 
548  public function initFilter()
549  {
550  $this->filter = array();
551 
552  include_once 'Services/Mail/classes/Form/class.ilMailQuickFilterInputGUI.php';
553  $ti = new ilMailQuickFilterInputGUI($this->lng->txt('mail_filter'), 'mail_filter');
554  $ti->setSubmitFormOnEnter(false);
555  $this->addFilterItem($ti);
556  $ti->readFromSession();
557  $this->filter['mail_filter'] = $ti->getValue();
558 
559  include_once 'Services/Form/classes/class.ilCheckboxInputGUI.php';
560 
561  if($this->isDraftFolder() || $this->isSentFolder())
562  {
563  $this->sub_filter[] = $ci = new ilCheckboxInputGUI($this->lng->txt('mail_filter_recipients'), 'mail_filter_recipients');
564  $ci->setOptionTitle($this->lng->txt('mail_filter_recipients'));
565  $ci->setValue(1);
566  $ti->addSubItem($ci);
567  $ci->setParent($this);
568  $ci->readFromSession();
569  $this->filter['mail_filter_recipients'] = (int)$ci->getChecked();
570  }
571  else
572  {
573  $this->sub_filter[] = $ci = new ilCheckboxInputGUI($this->lng->txt('mail_filter_sender'), 'mail_filter_sender');
574  $ci->setOptionTitle($this->lng->txt('mail_filter_sender'));
575  $ci->setValue(1);
576  $ti->addSubItem($ci);
577  $ci->setParent($this);
578  $ci->readFromSession();
579  $this->filter['mail_filter_sender'] = (int)$ci->getChecked();
580  }
581 
582  $this->sub_filter[] = $ci = new ilCheckboxInputGUI($this->lng->txt('mail_filter_subject'), 'mail_filter_subject');
583  $ci->setOptionTitle($this->lng->txt('mail_filter_subject'));
584  $ci->setValue(1);
585  $ti->addSubItem($ci);
586  $ci->setParent($this);
587  $ci->readFromSession();
588  $this->filter['mail_filter_subject'] = (int)$ci->getChecked();
589 
590  $this->sub_filter[] = $ci = new ilCheckboxInputGUI($this->lng->txt('mail_filter_body'), 'mail_filter_body');
591  $ci->setOptionTitle($this->lng->txt('mail_filter_body'));
592  $ci->setValue(1);
593  $ti->addSubItem($ci);
594  $ci->setParent($this);
595  $ci->readFromSession();
596  $this->filter['mail_filter_body'] = (int)$ci->getChecked();
597 
598  $this->sub_filter[] = $ci = new ilCheckboxInputGUI($this->lng->txt('mail_filter_attach'), 'mail_filter_attach');
599  $ci->setOptionTitle($this->lng->txt('mail_filter_attach'));
600  $ci->setValue(1);
601  $ti->addSubItem($ci);
602  $ci->setParent($this);
603  $ci->readFromSession();
604  $this->filter['mail_filter_attach'] = (int)$ci->getChecked();
605  }
606 
610  public function writeFilterToSession()
611  {
612  parent::writeFilterToSession();
613 
614  foreach($this->sub_filter as $item)
615  {
616  if($item->checkInput())
617  {
618  $item->setValueByArray($_POST);
619  $item->writeToSession();
620  }
621  }
622  }
623 
627  public function resetFilter()
628  {
629  parent::resetFilter();
630 
631  foreach($this->sub_filter as $item)
632  {
633  if($item->checkInput())
634  {
635  $item->setValueByArray($_POST);
636  $item->clearFromSession();
637  }
638  }
639  }
640 }
641 ?>
setSubmitFormOnEnter($a_val)
Set submit form on enter.
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
getSelectedItems()
Get all selected items public.
setExternalSorting($a_val)
Set external sorting.
__construct($a_parent_obj, $a_parent_cmd="", $a_template_context="")
Constructor.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
Base class for ILIAS Exception handling.
const IL_CAL_DATETIME
$result
getNumerOfMails()
Returns the total number of mails of the current folder public.
setExternalSegmentation($a_val)
Set external segmentation.
resetOffset($a_in_determination=false)
Reset offset.
setTitleData($folderLabel, $mailCount, $unreadCount, $imgFolder)
Function to set the table title protected.
This class represents a checkbox property in a property form.
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
getOrderDirection()
Get order direction.
setNumerOfMails($a_number_of_mails)
Set the total number of mails of the current folder public.
setId($a_val)
Set id.
global $ilCtrl
Definition: ilias.php:18
isDraftFolder($a_bool=null)
Setter/Getter for folder status public.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
$counter
setSelectedItems($a_selected_items)
Set the selected items public.
Class ilTable2GUI.
setResetCommand($a_val, $a_caption=null)
Set reset filter command.
getOffset()
Get offset.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
special template class to simplify handling of ITX/PEAR
addMultiCommand($a_cmd, $a_text)
Add Command button.
static formatDate(ilDateTime $date)
Format a date public.
static getUserObjectById($usr_id)
setPrefix($a_prefix)
Date and time handling
$ilUser
Definition: imgupload.php:18
setTableNames($a_table_tree, $a_table_obj_data, $a_table_obj_reference="")
set table names The primary key of the table containing your object_data must be &#39;obj_id&#39; You may use...
prepareHTML()
Call this before using getHTML() public.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
setRowTemplate($a_template, $a_template_dir="")
Set row template.
Create styles array
The data for the language used.
isTrashFolder($a_bool=null)
Setter/Getter for folder status public.
determineOffsetAndOrder($a_omit_offset=false)
Determine offset and order.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
isSentFolder($a_bool=null)
Setter/Getter for folder status public.
writeFilterToSession()
Write filter values to session.
getLimit()
Get limit.
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.
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
setMaxCount($a_max_count)
set max.
setOptionTitle($a_optiontitle)
Set Option Title (optional).
setEnableTitle($a_enabletitle)
Set Enable Title.
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.
$_POST["username"]
initCommandButtons()
Performs special actions for folders such as user folders, trash and local folders private...
fillRow($a_set)
Fill row public.
initMultiCommands($actions)
initMultiCommands private
setFilterCommand($a_val, $a_caption=null)
Set filter command.