ILIAS  Release_3_10_x_branch Revision 61812
 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-2008 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 
43  $this->lng->loadLanguageModule('chat');
44  }
45 
46  public function getHTML()
47  {
48  global $ilUser, $ilObjDataCache, $ilAccess, $ilSetting, $rbacsystem;
49 
50  // chat invitations
51  include_once 'Modules/Chat/classes/class.ilChatInvitations.php';
52  $items = ilChatInvitations::_getNewInvitations($ilUser->getId());
53 
54  // do not show list, if no item is in list
55  if(count($items) == 0)
56  {
57  return '';
58  }
59 
60  $add = ' ('.count($items).')';
61 
62  $this->tpl->addJavascript('./Modules/Chat/js/ChatInvitationMainMenu.js');
63 
64  $tpl = new ilTemplate('tpl.chat_invitations_navigation.html', true, true,
65  'Modules/Chat');
66 
67  $cnt = 0;
68  $sel_arr = array();
69  $user_cache = array();
70  $invitations = array();
71  foreach($items as $item)
72  {
73  $chat_ref_id = 0;
74  foreach((array)ilObject::_getAllReferences((int)$item['chat_id']) as $ref_id)
75  {
76  if($rbacsystem->checkAccess('read', $ref_id))
77  {
78  $chat_ref_id = $ref_id;
79  break;
80  }
81  }
82  if(!(int)$chat_ref_id) continue;
83 
84  $beep = false;
85 
86  $tpl->setCurrentBlock('item');
87  $css_row = ($css_row != 'tblrow1_mo') ? 'tblrow1_mo' : 'tblrow2_mo';
88  $tpl->setVariable('CSS_ROW', $css_row);
89  $room_title = '';
90  if((int)$item['room_id'])
91  {
92  include_once 'Modules/Chat/classes/class.ilChatRoom.php';
93  $oTmpChatRoom = new ilChatRoom((int)$item['chat_id']);
94  $oTmpChatRoom->setRoomId((int)$item['room_id']);
95  $room_title = $oTmpChatRoom->getTitle();
96  if($room_title != '')
97  {
98  $room_title = ', '.$room_title;
99 
100  if((int)$oTmpChatRoom->getOwnerId())
101  {
102  if(!isset($user_cache[$oTmpChatRoom->getOwnerId()]))
103  {
104  include_once 'Services/User/classes/class.ilObjUser.php';
105  $user_cache[$oTmpChatRoom->getOwnerId()] = new ilObjUser($oTmpChatRoom->getOwnerId());
106  }
107 
108  $room_title .= ' ('.$user_cache[$oTmpChatRoom->getOwnerId()]->getFullname().')';
109  }
110  }
111  }
112  $tpl->setVariable('HREF_ITEM', 'ilias.php?baseClass=ilChatPresentationGUI&room_id='.(int)$item['room_id'].'&ref_id='.(int)$chat_ref_id);
113  $tpl->setVariable('TXT_ITEM', $ilObjDataCache->lookupTitle($item['chat_id']).$room_title);
114  $sel_arr[(int)$chat_ref_id.'_'.(int)$item['room_id']] = $ilObjDataCache->lookupTitle($item['chat_id']).$room_title;
115  $tpl->parseCurrentBlock();
116 
117  $invitations[] = (int)$chat_ref_id.'_'.(int)$item['room_id'];
118  if((int)$ilSetting->get('chat_sound_status') &&
119  (int)$ilSetting->get('chat_new_invitation_sound_status'))
120  {
121  $beep = true;
122  }
123 
124  if($cnt == 0)
125  {
126  $sel_arr = array_reverse($sel_arr);
127  $sel_arr[(int)$chat_ref_id.'__'.(int)$item['room_id']] = '-- '.$this->lng->txt('chat_invitation_subject').$add.' --';
128  $sel_arr = array_reverse($sel_arr);
129  }
130 
131  ++$cnt;
132  }
133 
134  if($cnt == 0) return '';
135 
136  $select = ilUtil::formSelect('', 'invitation', $sel_arr, false, true, '0', 'ilEditSelect');
137  $tpl->setVariable('NAVI_SELECT', $select);
138  $tpl->setVariable('TXT_CHAT_INVITATIONS', $this->lng->txt('chat_chat_invitation').$add);
139  $tpl->setVariable('IMG_DOWN', ilUtil::getImagePath('mm_down_arrow.gif'));
140  $tpl->setVariable('TXT_GO', $this->lng->txt('go'));
141  $tpl->setVariable('ACTION', 'ilias.php?baseClass=ilChatPresentationGUI');
142 
143 
144  if((int)$ilSetting->get('chat_sound_status') &&
145  (int)$ilSetting->get('chat_new_invitation_sound_status'))
146  {
147  // beep
148  if($beep)
149  {
150  $tpl->setCurrentBlock('beep');
151  $tpl->setVariable('BEEP_SRC', './Modules/Chat/sounds/receive.mp3');
152  $tpl->parseCurrentBlock();
153  }
154 
155  foreach((array)$invitations as $id)
156  {
157  $_SESSION['chat']['_already_beeped'][$id] = true;
158  }
159  }
160 
161  return $tpl->get();
162  }
163 }
164 ?>