ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilChatroomBlockGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/Block/classes/class.ilBlockGUI.php';
5 require_once 'Modules/Chatroom/classes/class.ilChatroomServerConnector.php';
6 require_once 'Modules/Chatroom/classes/class.ilChatroomServerSettings.php';
7 require_once 'Services/JSON/classes/class.ilJsonUtil.php';
8 require_once 'Modules/Chatroom/classes/class.ilChatroomBlock.php';
9 require_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
10 
18 {
23  public static $block_type = 'chatviewer';
24 
28  public function __construct()
29  {
30  global $lng;
31 
33 
34  $lng->loadLanguageModule('chatroom');
35 
36  $this->setImage(ilUtil::getImagePath('icon_chat.png'));
37  $this->setTitle($lng->txt('chat_chatviewer'));
38  $this->setAvailableDetailLevels(1, 0);
39  $this->allow_moving = true;
40  }
41 
46  public static function getBlockType()
47  {
48  return self::$block_type;
49  }
50 
55  public static function isRepositoryObject()
56  {
57  return false;
58  }
59 
64  public static function getScreenMode()
65  {
66  switch($_GET['cmd'])
67  {
68  default:
69  return IL_SCREEN_SIDE;
70  break;
71  }
72  }
73 
77  public function executeCommand()
78  {
82  global $ilCtrl;
83 
84  $cmd = $ilCtrl->getCmd('getHTML');
85 
86  return $this->$cmd();
87  }
88 
92  public function getHTML()
93  {
95 
96  $chatSetting = new ilSetting('chatroom');
97  if($this->getCurrentDetailLevel() == 0 || !$chatSetting->get('chat_enabled', 0) || !(bool)@ilChatroomServerConnector::checkServerConnection())
98  {
99  return '';
100  }
101  else
102  {
103  return parent::getHTML();
104  }
105  }
106 
110  public function fillDataSection()
111  {
117  global $tpl, $lng, $ilCtrl;
118 
119  //@todo: Dirty hack
120  if($ilCtrl->isAsynch())
121  {
122  return $this->getMessages();
123  }
124 
125  $tpl->addJavascript('./Modules/Chatroom/js/chatviewer.js');
126  $tpl->addCss('./Modules/Chatroom/templates/default/style.css');
127 
128  $chatblock = new ilChatroomBlock();
129  $body_tpl = new ilTemplate('tpl.chatroom_block_message_body.html', true, true, 'Modules/Chatroom');
130 
131  $height = 120;
132  if($this->getCurrentDetailLevel() > 0 && $this->getCurrentDetailLevel() <= 3)
133  {
134  $height *= $this->getCurrentDetailLevel();
135  }
136  $body_tpl->setVariable('BLOCK_HEIGHT', $height);
137  $body_tpl->setVariable('TXT_ENABLE_AUTOSCROLL', $lng->txt('chat_enable_autoscroll'));
138 
139  $ilCtrl->setParameterByClass('ilcolumngui', 'block_id', 'block_' . $this->getBlockType() . '_' . (int)$this->getBlockId());
140  $ilCtrl->setParameterByClass('ilcolumngui', 'ref_id', '#__ref_id');
141  $body_tpl->setVariable('CHATBLOCK_BASE_URL', $ilCtrl->getLinkTargetByClass('ilcolumngui', 'updateBlock', '', true));
142  $ilCtrl->setParameterByClass('ilcolumngui', 'block_id', '');
143  $ilCtrl->setParameterByClass('ilcolumngui', 'ref_id', '');
144 
145  $smilieys = array();
147  if($settings->getSmiliesEnabled())
148  {
149  $smilies_array = ilChatroomSmilies::_getSmilies();
150  foreach($smilies_array as $smiley_array)
151  {
152  foreach($smiley_array as $key => $value)
153  {
154  if($key == 'smiley_keywords')
155  {
156  $new_keys = explode("\n", $value);
157  }
158 
159  if($key == 'smiley_fullpath')
160  {
161  $new_val = $value;
162  }
163  }
164 
165  foreach($new_keys as $new_key)
166  {
167  $smilieys[$new_key] = $new_val;
168  }
169  }
170  }
171  else
172  {
173  $smilieys = new stdClass();
174  }
175  $body_tpl->setVariable('SMILIES', json_encode($smilieys));
176 
177  $js_translations = array(
178  'LBL_CONNECT' => 'chat_connection_established',
179  'LBL_DISCONNECT' => 'chat_connection_disconnected',
180  'LBL_TIMEFORMAT' => 'lang_timeformat_no_sec',
181  'LBL_DATEFORMAT' => 'lang_dateformat'
182  );
183  foreach($js_translations as $placeholder => $lng_variable)
184  {
185  $body_tpl->setVariable($placeholder, json_encode($lng->txt($lng_variable)));
186  }
187 
188  $content = $body_tpl->get() . $chatblock->getRoomSelect();
189  $this->setDataSection($content);
190  }
191 
195  protected function getMessages()
196  {
202  global $rbacsystem, $ilUser, $lng;
203 
204  $result = new stdClass();
205  $result->ok = false;
206 
207  if(!(int)$_REQUEST['ref_id'])
208  {
210  exit();
211  }
212 
216  $object = ilObjectFactory::getInstanceByRefId((int)$_REQUEST['ref_id'], false);
217  if(!$object || !$rbacsystem->checkAccess('read', (int)$_REQUEST['ref_id']))
218  {
219  ilObjUser::_writePref
220  (
221  $ilUser->getId(), 'chatviewer_last_selected_room',
222  0
223  );
224 
225  $result->errormsg = $lng->txt('msg_no_perm_read');
227  exit();
228  }
229 
230  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
231  $room = ilChatroom::byObjectId($object->getId());
232 
233  $block = new ilChatroomBlock();
234  $msg = $block->getMessages($room);
235 
236  $ilUser->setPref
237  (
238  'chatviewer_last_selected_room',
239  $object->getRefId()
240  );
241  ilObjUser::_writePref
242  (
243  $ilUser->getId(), 'chatviewer_last_selected_room',
244  $object->getRefId()
245  );
246 
247  $result->messages = array_reverse($msg);
248  $result->ok = true;
249 
250  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
252  exit();
253  }
254 }