ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 include_once 'Services/Table/classes/class.ilTable2GUI.php';
5 
16 {
17  protected $lng = null;
18  protected $ctrl = null;
19 
20  protected $_folderNode = array();
21  protected $_parentObject = null;
22  protected $_currentFolderId = 0;
23  protected $_number_of_mails = 0;
24  protected $_selectedItems = array();
25  protected $_isTrashFolder = false;
26  protected $_isDraftsFolder = false;
27  protected $_isSentFolder = false;
28 
39  public function __construct($a_parent_obj, $a_current_folder_id, $a_parent_cmd = '')
40  {
41  global $lng, $ilCtrl;
42 
43  $this->lng = $lng;
44  $this->ctrl = $ilCtrl;
45 
46  $this->_currentFolderId = $a_current_folder_id;
47  $this->_parentObject = $a_parent_obj;
48 
49  $this->setId('mail_folder_tbl');
50  $this->setPrefix('mtable');
51 
52  parent::__construct($a_parent_obj, $a_parent_cmd);
53 
54  $this->setFormAction($this->ctrl->getFormAction($this->_parentObject, 'showFolder'));
55 
56  $this->setEnableTitle(true);
57  $this->setExternalSorting(true);
58  $this->setExternalSegmentation(true);
59  $this->setDefaultOrderField('send_time');
60  $this->setDefaultOrderDirection('desc');
61  $this->setSelectAllCheckbox('mail_id[]');
62  $this->setRowTemplate('tpl.mail_folder_row.html', 'Services/Mail');
63  }
64 
74  final public function prepareHTML()
75  {
76  global $ilUser;
77 
78  $this->addColumn('', 'sort', '5%', true);
79  $this->addColumn($this->lng->txt('personal_picture'), '', '10%');
80  if($this->isDraftFolder() || $this->isSentFolder())
81  $this->addColumn($this->lng->txt('recipient'), 'rcp_to', '25%');
82  else
83  $this->addColumn($this->lng->txt('sender'), 'from', '25%');
84  $this->addColumn($this->lng->txt('subject'), 'm_subject', '40%');
85  $this->addColumn($this->lng->txt('date'), 'send_time', '20%');
86 
87  // init folder data
88  $mtree = new ilTree($ilUser->getId());
89  $mtree->setTableNames('mail_tree', 'mail_obj_data');
90  $this->_folderNode = $mtree->getNodeData($this->_currentFolderId);
91 
92  // command buttons
93  $this->initCommandButtons();
94 
95  // mail actions
96  $this->initMultiCommands($this->_parentObject->mbox->getActions($this->_currentFolderId));
97 
98  // fetch table data
99  $this->fetchTableData();
100 
101  return $this;
102  }
103 
113  public function isDraftFolder($a_bool = null)
114  {
115  if(null === $a_bool)
116  {
117  return $this->_isDraftsFolder;
118  }
119 
120  $this->_isDraftsFolder = $a_bool;
121 
122  return $this;
123  }
124 
134  public function isSentFolder($a_bool = null)
135  {
136  if(null === $a_bool)
137  {
138  return $this->_isSentFolder;
139  }
140 
141  $this->_isSentFolder = $a_bool;
142 
143  return $this;
144  }
145 
155  public function isTrashFolder($a_bool = null)
156  {
157  if(null === $a_bool)
158  {
159  return $this->_isTrashFolder;
160  }
161 
162  $this->_isTrashFolder = $a_bool;
163 
164  return $this;
165  }
166 
176  private function initCommandButtons()
177  {
178  if($this->_folderNode['m_type'] == 'user_folder' ||
179  $this->_folderNode['m_type'] == 'local')
180  {
181  if($this->_folderNode['m_type'] == 'user_folder')
182  {
183  $this->addCommandButton('enterFolderData', $this->lng->txt('edit'));
184  }
185  $this->addCommandButton('addSubFolder', $this->lng->txt('mail_add_subfolder'));
186  }
187  else if($this->_folderNode['m_type'] == 'trash')
188  {
189  $this->addCommandButton('askForEmptyTrash', $this->lng->txt('mail_empty_trash'));
190  }
191 
192  return $this;
193  }
194 
204  private function initMultiCommands($actions)
205  {
206  foreach($actions as $key => $action)
207  {
208  if($key == 'moveMails')
209  {
210  $folders = $this->_parentObject->mbox->getSubFolders();
211  foreach($folders as $folder)
212  {
213  if($folder['type'] != 'trash' ||
214  !$this->isTrashFolder())
215  {
216  if($folder['type'] != 'user_folder')
217  {
218  $label = $action.' '.$this->lng->txt('mail_'.$folder['title']).
219  ($folder['type'] == 'trash' ? ' ('.$this->lng->txt('delete').')' : '');
220  $this->addMultiCommand($folder['obj_id'], $label);
221  }
222  else
223  $this->addMultiCommand($folder['obj_id'], $action.' '.$folder['title']);
224  }
225  }
226  }
227  else
228  {
229  if($key != 'deleteMails' || $this->isTrashFolder())
230  $this->addMultiCommand($key, $action);
231  }
232  }
233 
234  return $this;
235  }
236 
246  private function getUserInstance($a_usr_id)
247  {
248  static $userObjectCache = array();
249 
250  if(isset($userObjectCache[$a_usr_id])) return $userObjectCache[$a_usr_id];
251 
252  $userObjectCache[$a_usr_id] = new ilObjUser($a_usr_id);
253 
254  return $userObjectCache[$a_usr_id];
255  }
256 
266  public function setSelectedItems($a_selected_items)
267  {
268  $this->_selectedItems = $a_selected_items;
269 
270  return $this;
271  }
272 
281  public function getSelectedItems()
282  {
283  return $this->_selectedItems;
284  }
285 
294  protected function fetchTableData()
295  {
296  global $ilUser;
297 
298  $this->determineOffsetAndOrder();
299 
300  require_once 'Services/Mail/classes/class.ilMailBoxQuery.php';
301 
303  ilMailBoxQuery::$userId = $ilUser->getId();
304  ilMailBoxQuery::$limit = $this->getLimit();
309 
310  if(!count($data['set']) && $this->getOffset() > 0)
311  {
312  $this->resetOffset();
313 
314  ilMailBoxQuery::$limit = $this->getLimit();
317  }
318 
319  $counter = 0;
320  foreach($data['set'] as $key => $mail)
321  {
322  ++$counter;
323 
324  if(is_array($this->getSelectedItems()) &&
325  in_array($mail['mail_id'], $this->getSelectedItems()))
326  {
327  $mail['checked'] = ' checked="checked" ';
328  }
329 
330  // GET FULLNAME OF SENDER
331  if($this->isDraftFolder() || $this->isSentFolder())
332  {
333  $mail['mail_login'] = $this->_parentObject->umail->formatNamesForOutput($mail['rcp_to']);
334  }
335  else
336  {
337  if($mail['sender_id'] != ANONYMOUS_USER_ID)
338  {
339  $tmp_user = $this->getUserInstance($mail['sender_id']);
340  if(in_array(ilObjUser::_lookupPref($mail['sender_id'], 'public_profile'), array('y', 'g')))
341  {
342  $mail['mail_from'] = $tmp_user->getFullname();
343  }
344  if(!($login = $tmp_user->getLogin()))
345  {
346  $login = $mail['import_name'].' ('.$this->lng->txt('user_deleted').')';
347  $mail['mail_login'] = $mail['import_name'].' ('.$this->lng->txt('user_deleted').')';
348  }
349 
350  $mail['img_sender'] = $tmp_user->getPersonalPicturePath('xxsmall');
351  $mail['mail_login'] = $mail['alt_sender'] = $login;
352  }
353  else
354  {
355  $tmp_user = $this->getUserInstance(ANONYMOUS_USER_ID);
356 
357  $mail['img_sender'] = ilUtil::getImagePath('HeaderIcon_50.png');
358  $mail['mail_login'] = $mail['alt_sender'] = ilMail::_getAnonymousName();
359  }
360  }
361  $mail['mailclass'] = $mail['m_status'] == 'read' ? 'mailread' : 'mailunread';
362 
363  // IF ACTUAL FOLDER IS DRAFT BOX, DIRECT TO COMPOSE MESSAGE
364  if($this->isDraftFolder())
365  {
366  $this->ctrl->setParameterByClass('ilmailformgui', 'mail_id', $mail['mail_id']);
367  $this->ctrl->setParameterByClass('ilmailformgui', 'type', 'draft');
368  $mail['mail_link_read'] = $this->ctrl->getLinkTargetByClass('ilmailformgui');
369  $this->ctrl->clearParametersByClass('ilmailformgui');
370  }
371  else
372  {
373  $this->ctrl->setParameter($this->_parentObject, 'mail_id', $mail['mail_id']);
374  $this->ctrl->setParameter($this->_parentObject, 'cmd', 'showMail');
375  $mail['mail_link_read'] = $this->ctrl->getLinkTarget($this->_parentObject);
376  $this->ctrl->clearParameters($this->_parentObject);
377  }
378 
379  $mail['mail_subject'] = htmlspecialchars($mail['m_subject']);
380  $mail['mail_date'] = ilDatePresentation::formatDate(new ilDateTime($mail['send_time'], IL_CAL_DATETIME));
381 
382  $data['set'][$key] = $mail;
383  }
384 
385  $this->setData($data['set']);
386  $this->setMaxCount($data['cnt']);
387  $this->setNumerOfMails($data['cnt']);
388 
389  // table title
390  $txt_folder = '';
391  $img_folder = '';
392  if($this->_folderNode['m_type'] == 'user_folder')
393  {
394  $txt_folder = $this->_folderNode['title'];
395  $img_folder = 'icon_user_folder.gif';
396  }
397  else
398  {
399  $txt_folder = $this->lng->txt('mail_'.$this->_folderNode['title']);
400  $img_folder = 'icon'.substr($this->_folderNode['title'], 1).'.gif';
401  }
402  $this->setTitleData($txt_folder, $data['cnt'], $data['cnt_unread'], $img_folder);
403 
404  return $this;
405  }
406 
419  protected function setTitleData($folderLabel, $mailCount, $unreadCount, $imgFolder)
420  {
421  $titleTemplate = new ilTemplate('tpl.mail_folder_title.html', true, true, 'Services/Mail');
422  $titleTemplate->setVariable('TXT_FOLDER', $folderLabel);
423  $titleTemplate->setVariable('MAIL_COUNT', $mailCount);
424  $titleTemplate->setVariable('TXT_MAIL_S', $this->lng->txt('mail_s'));
425  $titleTemplate->setVariable('MAIL_COUNT_UNREAD', $unreadCount);
426  $titleTemplate->setVariable('TXT_UNREAD', $this->lng->txt('unread'));
427 
428  parent::setTitle($titleTemplate->get(), $imgFolder);
429 
430  return $this;
431  }
432 
442  public function setNumerOfMails($a_number_of_mails)
443  {
444  $this->_number_of_mails = $a_number_of_mails;
445 
446  return $this;
447  }
448 
457  public function getNumerOfMails()
458  {
460  }
461 
470  public function fillRow($a_set)
471  {
472  foreach($a_set as $key => $value)
473  {
474  $this->tpl->setVariable(strtoupper($key), $value);
475  }
476  }
477 }
478 ?>