ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilChatInvitationGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2009 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
32 {
33  private $tpl;
34  private $lng;
35 
36  public function __construct()
37  {
38  global $tpl, $lng;
39 
40  $this->tpl = $tpl;
41  $this->lng = $lng;
42  $this->lng->loadLanguageModule('chat');
43  }
44 
45  public function getHTML()
46  {
47  global $ilUser, $ilObjDataCache, $ilAccess, $ilSetting, $rbacsystem;
48 
49  // chat invitations
50  include_once 'Modules/Chat/classes/class.ilChatInvitations.php';
51  $items = ilChatInvitations::_getNewInvitations($ilUser->getId());
52 
53  // do not show list, if no item is in list
54  if(count($items) == 0)
55  {
56  return '';
57  }
58 
59  $add = ' ('.count($items).')';
60 
61  $this->tpl->addJavascript('./Modules/Chat/js/ChatInvitationMainMenu.js');
62  $tpl = new ilTemplate('tpl.chat_invitations_navigation.html', true, true,
63  'Modules/Chat');
64 
65  $cnt = 0;
66  $sel_arr = array();
67  $user_cache = array();
68  $invitations = array();
69  foreach($items as $item)
70  {
71  $chat_ref_id = 0;
72  foreach((array)ilObject::_getAllReferences((int)$item['chat_id']) as $ref_id)
73  {
74  if($rbacsystem->checkAccess('read', $ref_id))
75  {
76  $chat_ref_id = $ref_id;
77  break;
78  }
79  }
80  if(!(int)$chat_ref_id) continue;
81 
82  $beep = false;
83 
84  $tpl->setCurrentBlock('item');
85  $css_row = ($css_row != 'tblrow1_mo') ? 'tblrow1_mo' : 'tblrow2_mo';
86  $tpl->setVariable('CSS_ROW', $css_row);
87  $room_title = '';
88  if((int)$item['room_id'])
89  {
90  include_once 'Modules/Chat/classes/class.ilChatRoom.php';
91  $oTmpChatRoom = new ilChatRoom((int)$item['chat_id']);
92  $oTmpChatRoom->setRoomId((int)$item['room_id']);
93  $room_title = $oTmpChatRoom->getTitle();
94  if($room_title != '')
95  {
96  $room_title = ', '.$room_title;
97 
98  if((int)$oTmpChatRoom->getOwnerId())
99  {
100  if(!isset($user_cache[$oTmpChatRoom->getOwnerId()]))
101  {
102  include_once 'Services/User/classes/class.ilObjUser.php';
103  $user_cache[$oTmpChatRoom->getOwnerId()] = new ilObjUser($oTmpChatRoom->getOwnerId());
104  }
105  $room_title .= ' ('.$user_cache[$oTmpChatRoom->getOwnerId()]->getFullname().')';
106  }
107  }
108  }
109  $tpl->setVariable('HREF_ITEM', 'ilias.php?baseClass=ilChatPresentationGUI&room_id='.(int)$item['room_id'].'&ref_id='.(int)$chat_ref_id);
110  $tpl->setVariable('TXT_ITEM', $ilObjDataCache->lookupTitle($item['chat_id']).$room_title);
111  $sel_arr[(int)$chat_ref_id.'_'.(int)$item['room_id']] = $ilObjDataCache->lookupTitle($item['chat_id']).$room_title;
112  $tpl->parseCurrentBlock();
113 
114  $invitations[] = (int)$chat_ref_id.'_'.(int)$item['room_id'];
115  $beep = true;
116 
117  if($cnt == 0)
118  {
119  $sel_arr = array_reverse($sel_arr);
120  $sel_arr[(int)$chat_ref_id.'__'.(int)$item['room_id']] = '-- '.$this->lng->txt('chat_invitation_subject').$add.' --';
121  $sel_arr = array_reverse($sel_arr);
122  }
123 
124  ++$cnt;
125  }
126 
127  if($cnt == 0) return '';
128 
129  $select = ilUtil::formSelect('', 'invitation', $sel_arr, false, true, '0', 'ilEditSelect');
130  $tpl->setVariable('NAVI_SELECT', $select);
131  $tpl->setVariable('TXT_CHAT_INVITATIONS', $this->lng->txt('chat_chat_invitation').$add);
132  $tpl->setVariable('IMG_DOWN', ilUtil::getImagePath('mm_down_arrow.gif'));
133  $tpl->setVariable('TXT_GO', $this->lng->txt('go'));
134  $tpl->setVariable('ACTION', 'ilias.php?baseClass=ilChatPresentationGUI');
135 
136  if((int)$ilSetting->get('chat_sound_status') &&
137  (int)$ilSetting->get('chat_new_invitation_sound_status') &&
138  (int)$ilUser->getPref('chat_sound_status') &&
139  (int)$ilUser->getPref('chat_new_invitation_sound_status')
140  )
141  {
142  // beep
143  if($beep)
144  {
145  $tpl->setCurrentBlock('beep');
146  $tpl->setVariable('BEEP_SRC', './Modules/Chat/sounds/receive.mp3');
147  $tpl->parseCurrentBlock();
148  }
149 
150  foreach((array)$invitations as $id)
151  {
152  $_SESSION['chat']['_already_beeped'][$id] = true;
153  }
154  }
155 
156  return $tpl->get();
157  }
158 }
159 ?>