ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjChatGUI.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 
16 require_once "classes/class.ilObjectGUI.php";
17 require_once "Modules/Chat/classes/class.ilChatRecording.php";
18 
20 {
21  var $target_script = "adm_object.php";
22  var $in_module = false;
23 
28  public function __construct($a_data,$a_id,$a_call_by_reference = true, $a_prepare_output = true)
29  {
30  global $ilCtrl, $lng;
31 
32  $lng->loadLanguageModule('chat');
33 
34  $this->type = "chat";
35  $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference, $a_prepare_output);
36 
37  $this->ctrl =& $ilCtrl;
38  $this->ctrl->saveParameter($this,array("ref_id","cmdClass"));
39 
40 
41  if(is_object($this->object->chat_user))
42  {
43  $this->object->chat_user->setUserId($_SESSION["AccountId"]);
44  }
45  }
46 
47  public function &executeCommand()
48  {
49  global $rbacsystem;
50 
51  if($_GET["baseClass"] == "ilChatPresentationGUI")
52  {
53  $this->__prepareOutput();
54  }
55  else
56  {
57  $this->prepareOutput();
58  }
59 
60  $next_class = $this->ctrl->getNextClass($this);
61  $cmd = $this->ctrl->getCmd();
62 
63 
64  switch($next_class)
65  {
66  case 'ilpermissiongui':
67  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
68  $perm_gui =& new ilPermissionGUI($this);
69  $ret =& $this->ctrl->forwardCommand($perm_gui);
70  break;
71 
72  case "ilpublicuserprofilegui":
73  include_once("./Services/User/classes/class.ilPublicUserProfileGUI.php");
74  $profile_gui = new ilPublicUserProfileGUI((int)$_GET['user']);
75  $ret = $this->ctrl->forwardCommand($profile_gui);
76  break;
77 
78  case 'ilinfoscreengui':
79  //$this->prepareOutput();
80  $this->infoScreen();
81  break;
82 
83  default:
84  if(!$cmd)
85  {
86  $cmd = "view";
87  }
88  $cmd .= "Object";
89  $this->$cmd();
90 
91  break;
92  }
93 
94  return true;
95  }
96 
97  public function testObject()
98  {
99  global $tpl;
100  include_once 'Services/YUI/classes/class.ilYuiUtil.php';
102  $testTpl = new ilTemplate('tpl.test_treeview.html', true, true, 'Modules/Chat');
103  $testTpl->setVariable('SOME_CONTENT','asdf');
104  $tpl->setContent($testTpl->get());
105  $tpl->show();
106  exit;
107  }
108 
116  public function cancelObject()
117  {
118  unset($_SESSION["room_id_rename"]);
119  unset($_SESSION["room_id_delete"]);
120  unset($_SESSION['saved_post']);
122  }
123 
128  public function addAdminLocatorItems()
129  {
130  global $ilLocator,$tree,$ilObjDataCache;
131 
132  if ($_GET["admin_mode"] == "settings") // system settings
133  {
134  $ilLocator->addItem($this->lng->txt("administration"),
135  $this->ctrl->getLinkTargetByClass("iladministrationgui", "frameset"),
136  ilFrameTargetInfo::_getFrame("MainContent"));
137 
138  // add chat settings
139  $chat_settings_ref_id = $tree->getParentId($this->object->getRefId());
140  $chat_settings_obj_id = $ilObjDataCache->lookupObjId($chat_settings_ref_id);
141 
142  $this->ctrl->setParameterByClass('ilobjchatservergui','ref_id',$chat_settings_ref_id);
143  $ilLocator->addItem($ilObjDataCache->lookupTitle($chat_settings_obj_id),
144  $this->ctrl->getLinkTargetByClass(array('iladministrationgui','ilobjchatservergui'),
145  'view'));
146 
147  if ($this->object->getRefId() != SYSTEM_FOLDER_ID)
148  {
149  $ilLocator->addItem($this->object->getTitle(),
150  $this->ctrl->getLinkTarget($this, "view"));
151  }
152  }
153  else // repository administration
154  {
156  }
157 
158  }
159 
160 
161  public function setTargetScript($a_script)
162  {
163  $this->target_script = $a_script;
164  }
165 
166  public function getTargetScript($a_params)
167  {
168  return $this->target_script."?".$a_params;
169  }
170 
171  public function setInModule($in_module)
172  {
173  $this->in_module = $in_module;
174  }
175 
176  public function inModule()
177  {
178  return $this->in_module;
179  }
180 
181  public function saveObject()
182  {
183  global $ilUser,$rbacadmin;
184 
185  $new_obj =& parent::saveObject();
186 
187  // Assign current user.
188  $rbacadmin->assignUser(ilObjChat::_lookupModeratorRole($new_obj->getRefId()),$ilUser->getId());
189 
190  //$this->ctrl->setParameter($this, "ref_id", $new_obj->getRefId());
191  ilUtil::redirect($this->getReturnLocation("save",
192  "ilias.php?baseClass=ilChatHandlerGUI&ref_id=".$new_obj->getRefId()."&amp;cmd=view"));
193  }
194 
195  // Methods for blocked users (administration)
196  public function blockedUsersObject()
197  {
198  global $rbacsystem, $lng, $tpl, $ilCtrl;
199  include_once 'Modules/Chat/classes/class.ilChatBlockedUsers.php';
200 
201  if(!$rbacsystem->checkAccess('moderate',$this->object->getRefId()))
202  {
203  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
204  }
205 
206  include_once('Services/Table/classes/class.ilTable2GUI.php');
207  $table = new ilTable2GUI($this, 'blockedUsers');
208 
209  $table->setTitle($lng->txt('chat_blocked_users'));
210  $table->setId('cht_blocked_users_' . $this->object->getId());
211  $table->setFormAction($ilCtrl->getFormAction($this));
212  $table->addColumn('', 'checkbox', '2%', true);
213  $table->addColumn($lng->txt('chat_user_name'), 'login');
214  $table->addColumn($lng->txt('lastname'), 'lastname');
215  $table->addColumn($lng->txt('firstname'), 'firstname');
216  $table->addColumn($lng->txt('actions'));
217  $table->setNoEntriesText($lng->txt('chat_no_blocked'));
218 
219  $table->setSelectAllCheckbox('blocked_check');
220  $table->setRowTemplate('tpl.chat_blocked_users_row.html', 'Modules/Chat');
221 
222  $blocked_obj = new ilChatBlockedUsers($this->object->getId());
223  $blocked_users = $blocked_obj->getBlockedUsers();
224  $tabledata = array();
225 
226  $table->addMultiCommand('unblockUsers', $lng->txt('chat_blocked_unlocked'));
227 
228  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
229 
230  foreach($blocked_users as $usrId)
231  {
232  $current_selection_list = new ilAdvancedSelectionListGUI();
233  $current_selection_list->setListTitle($lng->txt("actions"));
234  $current_selection_list->setId("act_".$usrId);
235  $ilCtrl->setParameter($this, 'blocked_check', $usrId);
236  $current_selection_list->addItem($this->lng->txt("chat_blocked_unlocked"), '', $ilCtrl->getLinkTarget($this, 'unblockUsers'));
237 
238  $usr = new ilObjUser($usrId);
239  $tabledata[] = array
240  (
241  'id' => $usrId,
242  'login' => $usr->getLogin(),
243  'firstname' => $usr->getFirstname(),
244  'lastname' => $usr->getLastname(),
245  'actions' => $current_selection_list->getHTML()
246  );
247  }
248  $table->setData($tabledata);
249 
250  // add blocked user
251 
252  // create form
253  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
254 
255  $form = new ilPropertyFormGUI();
256  $form->setTitle($lng->txt('chat_add_blocking'));
257  $form->setFormAction($ilCtrl->getFormAction($this, 'blockUser'));
258 
259  $inp = new ilTextInputGUI($lng->txt('chat_user_name'), 'block');
260  $form->addItem($inp);
261 
262  $form->addCommandButton('blockUser', $lng->txt('chat_block_user'));
263 
264  $tpl->setVariable('ADM_CONTENT', $table->getHTML() . "<br />" . $form->getHTML());
265 
266  return;
267  }
268 
269  public function blockUserObject()
270  {
271  global $rbacsystem;
272  include_once 'Modules/Chat/classes/class.ilChatBlockedUsers.php';
273 
274  if(!$rbacsystem->checkAccess('moderate',$this->object->getRefId()))
275  {
276  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
277  }
278 
279  $blocked_obj = new ilChatBlockedUsers($this->object->getId());
280 
281  if(!$_POST['block'] or !($usr_id = ilObjUser::getUserIdByLogin($_POST['block'])))
282  {
283  ilUtil::sendFailure($this->lng->txt('chat_enter_valid_username'));
284  $this->blockedUsersObject();
285 
286  return false;
287  }
288  if($blocked_obj->isBlocked($usr_id))
289  {
290  ilUtil::sendInfo($this->lng->txt('chat_user_already_blocked'));
291  $this->blockedUsersObject();
292 
293  return false;
294  }
295 
296  $blocked_obj->block($usr_id);
297  ilUtil::sendSuccess($this->lng->txt('chat_user_blocked'));
298  $this->blockedUsersObject();
299 
300  return true;
301  }
302 
303  public function unblockUsersObject()
304  {
305  include_once 'Modules/Chat/classes/class.ilChatBlockedUsers.php';
306 
307  global $rbacsystem;
308 
309  if(!$rbacsystem->checkAccess('moderate',$this->object->getRefId()))
310  {
311  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
312  }
313 
314  $blocked_obj = new ilChatBlockedUsers($this->object->getId());
315 
316  if ($_GET['blocked_check'])
317  $_POST['blocked_check'] = array($_GET['blocked_check']);
318 
319  if(!is_array($_POST['blocked_check']))
320  {
321  ilUtil::sendFailure($this->lng->txt('chat_no_users_selected'));
322  return $this->blockedUsersObject();
323  }
324 
325  foreach($_POST['blocked_check'] as $usr_id)
326  {
327  $blocked_obj->unblock($usr_id);
328  }
329 
330  ilUtil::sendSuccess($this->lng->txt('chat_unblocked_user'));
331  return $this->blockedUsersObject();
332  }
333 
334  public function viewObject()
335  {
336  global $rbacsystem,$ilUser,$lng;
337 
338  // administration
339  if (strtolower($_GET["baseClass"]) == "iladministrationgui")
340  {
342  return true;
343  }
344 
345  // check general read access
346  if (!$rbacsystem->checkAccess("read", $this->ref_id))
347  {
348  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
349  }
350 
351  // check if chatserver is available
352  $isActive = ($this->object->server_comm->isAlive() && $this->ilias->getSetting("chat_active"));
353  if(!$isActive)
354  {
355  ilUtil::sendFailure($this->lng->txt("chat_server_not_active"));
356  }
357 
358  // check if user is blocked from current room
359  include_once 'Modules/Chat/classes/class.ilChatBlockedUsers.php';
360  if(ilChatBlockedUsers::_isBlocked($this->object->getId(),$ilUser->getId()))
361  {
362  ilUtil::sendInfo($this->lng->txt('chat_access_blocked'));
363  return true;
364  }
365 
366  // todo räume löschen? hier stand mal ein manueller confirm
367 
368  // get table data
369  $rooms_unprepared = array();
370  if($rbacsystem->checkAccess('write',$this->ref_id))
371  {
372  $rooms_unprepared = $this->object->chat_room->getAllRoomsOfObject();
373  }
374  else
375  {
376  $this->object->chat_room->setOwnerId($_SESSION["AccountId"]);
377  $rooms_unprepared = $this->object->chat_room->getRoomsOfObject();
378  }
379 
380  // prepare roomset for output and merge public room
381  $rooms = array
382  (
383  array
384  (
385  'room_id' => 0,
386  'title' => $this->object->getTitle()." ".$lng->txt("chat_public_room"),
387  'usercount' => ilChatRoom::_getCountActiveUsers($this->object->getId()),
388  )
389  );
390  $i = 1;
391  foreach($rooms_unprepared as $key => $value)
392  {
393  $rooms[$i] = $rooms_unprepared[$key];
394  $rooms[$i]['usercount'] = ilChatRoom::_getCountActiveUsers($this->object->getId(),$rooms_unprepared[$key]['room_id']);
395  $i++;
396  }
397 
398  // initialize table
399  include_once 'Modules/Chat/classes/class.ilChatRoomsTableGUI.php';
400  $tbl = new ilChatRoomsTableGUI($this, $rbacsystem->checkAccess('write',$this->object->getRefId()), $isActive);
401  $tbl->setData($rooms);
402 
403  // permanent link
404  include_once 'Services/PermanentLink/classes/class.ilPermanentLinkGUI.php';
405  $permalink = new ilPermanentLinkGUI('chat', $this->object->getRefId());
406  $this->tpl->setVariable('PRMLINK', $permalink->getHTML());
407 
408  $this->tpl->setVariable("ADM_CONTENT", $tbl->getHTML());
409 
410  }
411 
412 // TODO: delete me
413  public function adminRoomsObject()
414  {
415  global $rbacsystem;
416 
417  if (!$rbacsystem->checkAccess("read", $this->ref_id))
418  {
419  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
420  }
421 
422  if(!isset($_POST["del_id"]))
423  {
424  ilUtil::sendInfo($this->lng->txt("chat_select_one_room"));
425  $this->viewObject();
426 
427  return false;
428  }
429 
430  switch($_POST["action"])
431  {
432  case "renameRoom":
433  if(count($_POST["del_id"]) > 1)
434  {
435  ilUtil::sendInfo($this->lng->txt("chat_select_one_room"));
436  $this->viewObject();
437 
438  return false;
439  }
440  if(in_array(0,$_POST["del_id"]))
441  {
442  ilUtil::sendFailure($this->lng->txt("chat_no_rename_public"));
443  $this->viewObject();
444 
445  return false;
446  }
447 
448  // STORE ID IN SESSION
449  $_SESSION["room_id_rename"] = (int) $_POST["del_id"][0];
450 
451  $room =& new ilChatRoom($this->object->getId());
452  $room->setRoomId($_SESSION["room_id_rename"]);
453 
454  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.chat_edit_room.html","Modules/Chat");
455  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
456  $this->tpl->setVariable("TXT_ROOM_NAME",$this->lng->txt("chat_room_name"));
457  $this->tpl->setVariable("ROOM_CANCEL",$this->lng->txt("cancel"));
458  $this->tpl->setVariable("TXT_EDIT_CHATROOMS",$this->lng->txt("chat_chatroom_rename"));
459  $this->tpl->setVariable("ROOM_NAME",$room->getTitle());
460  $this->tpl->setVariable("CMD","renameRoom");
461  $this->tpl->setVariable("ROOM_EDIT",$this->lng->txt("rename"));
462  break;
463 
464  case "deleteRoom":
465  if(in_array(0,$_POST["del_id"]))
466  {
467  ilUtil::sendFailure($this->lng->txt("chat_no_delete_public"));
468  $this->viewObject();
469 
470  return false;
471  }
472  $_SESSION["room_id_delete"] = $_POST["del_id"];
473  $this->viewObject();
474 
475  return true;
476 
477 
478  case "exportRoom":
479  $this->__exportRooms();
480  break;
481 
482  case "refreshRoom":
483  if(in_array(0,$_POST["del_id"]) and !$rbacsystem->checkAccess('write',$this->object->getRefId()))
484  {
485  ilUtil::sendFailure($this->lng->txt("chat_no_refresh_public"));
486  $this->viewObject();
487 
488  return true;
489  }
490  foreach($_POST["del_id"] as $room_id)
491  {
492  $this->object->chat_room->setRoomId($room_id);
493  $this->object->server_comm->setType("delete");
494  $this->object->server_comm->send();
495  $this->object->chat_room->deleteAllMessages();
496  }
497  ilUtil::sendSuccess($this->lng->txt('chat_refreshed'));
498  $this->viewObject();
499 
500  return true;
501  }
502 
503  }
504 
505  public function deleteRoomObject()
506  {
507  global $rbacsystem, $lng, $tpl, $ilCtrl;
508 
509  if (!$rbacsystem->checkAccess("read", $this->ref_id))
510  {
511  $this->ilias->raiseError($lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
512  }
513 
514  if ($_GET['del_id'])
515  $_POST['del_id'] = array($_GET['del_id']);
516 
517  if(!isset($_POST["del_id"]))
518  {
519  ilUtil::sendInfo($lng->txt("chat_select_one_room"));
520  $this->viewObject();
521  return;
522  }
523 
524  if(in_array(0,$_POST["del_id"]) and !$rbacsystem->checkAccess('write',$this->object->getRefId()))
525  {
526  ilUtil::sendFailure($this->lng->txt("chat_no_delete_public"));
527  $this->viewObject();
528  return;
529  }
530 
531  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
532  $conf = new ilConfirmationGUI();
533  $conf->setFormAction($ilCtrl->getFormAction($this));
534  $conf->setHeaderText($lng->txt('chat_confirm_delete'));
535  foreach($_POST["del_id"] as $id)
536  {
537  $room = new ilChatRoom($this->object->getId());
538  $room->setRoomId($id);
539  $conf->addItem('del_id[]', $id, $room->getTitle());
540  }
541  $conf->setConfirm($lng->txt('confirm'), 'confirmedDeleteRoom');
542  $conf->setCancel($lng->txt('cancel'), 'view');
543  $tpl->setVariable('ADM_CONTENT', $conf->getHTML());
544  }
545 
546  public function refreshRoomObject()
547  {
548  global $rbacsystem, $lng;
549 
550  if (!$rbacsystem->checkAccess("read", $this->ref_id))
551  {
552  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
553  }
554 
555  if ($_GET['del_id'])
556  $_POST['del_id'] = array($_GET['del_id']);
557 
558  if(!isset($_POST["del_id"]))
559  {
560  ilUtil::sendInfo($lng->txt("chat_select_one_room"));
561  $this->viewObject();
562 
563  return false;
564  }
565 
566  if(in_array(0,$_POST["del_id"]) &&!$rbacsystem->checkAccess('write',$this->object->getRefId()))
567  {
568  ilUtil::sendFailure($lng->txt("chat_no_refresh_public"));
569  $this->viewObject();
570  return;
571  }
572  foreach($_POST["del_id"] as $room_id)
573  {
574  $this->object->chat_room->setRoomId($room_id);
575  $this->object->server_comm->setType("delete");
576  $this->object->server_comm->send();
577  $this->object->chat_room->deleteAllMessages();
578  }
579  ilUtil::sendSuccess($this->lng->txt('chat_refreshed'));
580  $this->viewObject();
581  }
582 
583  public function renameObject()
584  {
585  global $rbacsystem, $lng, $tpl, $ilCtrl;
586 
587  if (!$rbacsystem->checkAccess("read", $this->ref_id))
588  {
589  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
590  }
591 
592  if(!isset($_GET["room_id"]))
593  {
594  ilUtil::sendInfo($this->lng->txt("chat_select_one_room"));
595  $this->viewObject();
596  return false;
597  }
598 
599  if($_GET["room_id"] == 0)
600  {
601  ilUtil::sendFailure($this->lng->txt("chat_no_rename_public"));
602  $this->viewObject();
603  return false;
604  }
605 
606  $room = new ilChatRoom($this->object->getId());
607  $room->setRoomId($_GET['room_id']);
608 
609  // create form
610  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
611 
612  $form = new ilPropertyFormGUI();
613 
614  $form->setFormAction($ilCtrl->getFormAction($this, 'renameRoom'));
615  $form->setTitle($lng->txt("chat_chatroom_rename"));
616 
617  $inp = new ilTextInputGUI($lng->txt('chat_room_name'), 'room_name');
618  $inp->setValue($room->getTitle());
619  $form->addItem($inp);
620 
621  $hinp = new ilHiddenInputGUI('room_id');
622  $hinp->setValue($_GET['room_id']);
623  $form->addItem($hinp);
624 
625  $form->addCommandButton('renameRoom', $lng->txt('rename'));
626  $form->addCommandButton('view', $lng->txt('cancel'));
627 
628  $tpl->setVariable('ADM_CONTENT',$form->getHTML());
629  }
630 /*
631  function deleteRoomObject()
632  {
633  global $rbacsystem;
634 
635  if (!$rbacsystem->checkAccess("read", $this->ref_id))
636  {
637  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
638  }
639 
640  if(!$_GET["room_id_delete"])
641  {
642  $this->ilias->raiseError($this->lng->txt("chat_select_one_room"),$this->ilias->error_obj->MESSAGE);
643  }
644 
645  $this->object->chat_room->setOwnerId($_SESSION["AccountId"]);
646  $rooms = array($_GET["room_id_delete"]);
647 
648  if (!$rbacsystem->checkAccess("write", $this->ref_id))
649  {
650  $delResult = $this->object->chat_room->deleteRooms($rooms, $this->object->chat_room->getOwnerId());
651  }
652  else
653  {
654  $delResult = $this->object->chat_room->deleteRooms($rooms);
655  }
656  if(!$delResult)
657  {
658  $this->ilias->raiseError($this->object->chat_room->getErrorMessage(),$this->ilias->error_obj->MESSAGE);
659  }
660  unset($_GET["room_id_delete"]);
661  ilUtil::sendSuccess($this->lng->txt("chat_rooms_deleted"), true);
662  $this->ctrl->redirect($this, 'view');
663  }
664 */
665  public function confirmedDeleteRoomObject()
666  {
667  global $rbacsystem;
668 
669  if (!$rbacsystem->checkAccess("read", $this->ref_id))
670  {
671  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
672  }
673  if(!$_POST['del_id'])
674  {
675  $this->ilias->raiseError($this->lng->txt("chat_select_one_room"),$this->ilias->error_obj->MESSAGE);
676  }
677  $this->object->chat_room->setOwnerId($_SESSION["AccountId"]);
678  if(!$this->object->chat_room->deleteRooms($_POST['del_id']))
679  {
680  $this->ilias->raiseError($this->object->chat_room->getErrorMessage(),$this->ilias->error_obj->MESSAGE);
681  }
682  ilUtil::sendSuccess($this->lng->txt("chat_rooms_deleted"), true);
683 
684  $this->viewObject();
685  return true;
686  }
687 
688  public function addRoomObject()
689  {
690  global $rbacsystem;
691 
692  if (!$rbacsystem->checkAccess("read", $this->ref_id))
693  {
694  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
695  }
696  $room =& new ilChatRoom($this->object->getId());
697  $room->setTitle(ilUtil::stripSlashes($_POST["room_name"]));
698  $room->setOwnerId($_SESSION["AccountId"]);
699 
700  if(!$room->validate())
701  {
702  $this->ilias->raiseError($room->getErrorMessage(),$this->ilias->error_obj->MESSAGE);
703  }
704  $room->add();
705  ilUtil::sendSuccess($this->lng->txt("chat_room_added"));
706  $this->viewObject();
707 
708  return true;
709  }
710 
711  public function renameRoomObject()
712  {
713  global $rbacsystem;
714 
715  if (!$rbacsystem->checkAccess("read", $this->ref_id))
716  {
717  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
718  }
719 
720  $room = new ilChatRoom($this->object->getId());
721  $room->setRoomId($_POST["room_id"]);
722  $room->setTitle(ilUtil::stripSlashes($_POST["room_name"]));
723  if(!$room->validate())
724  {
725  $this->ilias->raiseError($room->getErrorMessage(),$this->ilias->error_obj->MESSAGE);
726  }
727  $room->rename();
728  ilUtil::sendSuccess($this->lng->txt("chat_room_renamed"));
729  $this->viewObject();
730  }
731 
732  public function adminAddRoomObject()
733  {
734  global $rbacsystem;
735 
736  if (!$rbacsystem->checkAccess("read", $this->ref_id))
737  {
738  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
739  }
740  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.chat_edit_room.html","Modules/Chat");
741  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
742  $this->tpl->setVariable("TXT_ROOM_NAME",$this->lng->txt("chat_room_name"));
743  $this->tpl->setVariable("ROOM_CANCEL",$this->lng->txt("cancel"));
744 
745  $this->tpl->setVariable("TXT_EDIT_CHATROOMS",$this->lng->txt("chat_chatroom_rename"));
746  $this->tpl->setVariable("ROOM_NAME","");
747  $this->tpl->setVariable("CMD","addRoom");
748  $this->tpl->setVariable("ROOM_EDIT",$this->lng->txt("add"));
749 
750  }
751 
752  public function recordingsObject()
753  {
754  global $rbacsystem, $lng, $ilCtrl;
755 
756  if (!$rbacsystem->checkAccess("moderate", $this->object->getRefId()))
757  {
758  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
759  }
760 
761  $this->object->__initChatRecording();
762  $data = $this->object->chat_recording->getRecordings();
763  if (!is_array($data))
764  {
765  ilUtil::sendInfo($this->lng->txt('chat_no_recordings_available'));
766  return true;
767  }
768 
769  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
770 
771  // prepare data
772  $tablelines = array();
773  foreach($data as $d)
774  {
775  $mod = '';
776  if ($d['moderator_id'])
777  {
778  $usr = new ilObjUser($d['moderator_id']);
779  $mod = $usr->getPublicName();
780  }
781 
782  $current = array
783  (
784  'REC_ID' => $d['record_id'],
785  'RECORDING_TITLE' => $d['title'],
786  'RECORDING_DESCRIPTION' => $d['description'],
787  'MODERATOR' => $mod,
788  'START_TIME' => ilDatePresentation::formatDate(new ilDateTime($d['start_time'], IL_CAL_UNIX)),
789  'start_timestamp' => $d['start_time']
790  );
791 
792  if (is_array($moderator = $this->object->chat_recording->getModerator($d["moderator_id"])))
793  {
794  $this->tpl->setVariable("MODERATOR", $moderator);
795  }
796 
797  $current_selection_list = new ilAdvancedSelectionListGUI();
798  $current_selection_list->setListTitle($this->lng->txt("actions"));
799  $current_selection_list->setId("act_".$current['REC_ID']);
800 
801  if ($d['end_time'] > 0)
802  {
803  $current['END_TIME'] = ilDatePresentation::formatDate(new ilDateTime($d['end_time'], IL_CAL_UNIX));
804  $ilCtrl->setParameter($this,'record_id',$d["record_id"]);
805  $current_selection_list->addItem($lng->txt('export'), '', $ilCtrl->getLinkTarget($this,'exportRecording'));
806  $ilCtrl->clearParameters($this);
807 
808  }
809 
810  $current_selection_list->addItem($lng->txt('delete'), '', $ilCtrl->getLinkTarget($this,'askDeleteRecordings'));
811 
812  $current['COMMAND_SELECTION_LIST'] = $current_selection_list->getHTML();
813 
814  $tablelines[] = $current;
815  }
816 
817  // prepare output
818  include_once('Services/Table/classes/class.ilTable2GUI.php');
819  $table = new ilTable2GUI($this, $lng->txt('chat_recordings'));
820  $table->setTitle($lng->txt('chat_recordings'));
821  $table->setData($tablelines);
822  $table->setId('cht_recordings_tbl_' . $this->object->getId());
823  $table->addColumn('', 'checkbox', '1%', true);
824  $table->addColumn($lng->txt('title'), 'RECORDING_TITLE', '35%');
825  $table->addColumn($lng->txt('chat_recording_moderator'), 'RECORDING_MODERATOR', '15%');
826  $table->addColumn($lng->txt('chat_recording_time_frame'), 'start_timestamp', '30%');
827  $table->addColumn($lng->txt('actions'), false, '10%');
828 
829  $table->setFormAction($ilCtrl->getFormAction($this));
830  $table->setSelectAllCheckbox('recordings');
831 
832  $table->setRowTemplate('tpl.chat_recordings_list_row.html', 'Modules/Chat');
833 
834  $table->addMultiCommand('askDeleteRecordings', $lng->txt('delete'));
835 
836  $this->tpl->setVariable('ADM_CONTENT', $table->getHTML());
837  }
838 
839  public function askDeleteRecordingsObject()
840  {
841  global $rbacsystem;
842 
843  if (!$rbacsystem->checkAccess("moderate", $this->object->getRefId()))
844  {
845  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
846  }
847 
848  if(!is_array($_POST['recordings']))
849  {
850  ilUtil::sendFailure($this->lng->txt('chat_recordings_select_one'));
851  $this->recordingsObject();
852 
853  return false;
854  }
855 
856  $this->object->__initChatRecording();
857 
858  ilUtil::sendQuestion($this->lng->txt('chat_recordings_delete_sure'));
859  $this->tpl->addBlockFile("ADM_CONTENT","adm_content","tpl.chat_ask_delete_recordings.html","Modules/Chat");
860 
861  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
862  $this->tpl->setVariable("TBL_TITLE",$this->lng->txt('chat_recordings'));
863  $this->tpl->setVariable("HEADER_DESC",$this->lng->txt('chat_recording_description'));
864  $this->tpl->setVariable("HEADER_MOD",$this->lng->txt('chat_recording_moderator'));
865  $this->tpl->setVariable("HEADER_TIME",$this->lng->txt('chat_recording_time_frame'));
866  $this->tpl->setVariable("IMG_ARROW",ilUtil::getImagePath('arrow_downright.gif'));
867  $this->tpl->setVariable("BTN_DELETE",$this->lng->txt('delete'));
868  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt('cancel'));
869 
870  $counter = 0;
871  for ($i = 0; $i < count($_POST["recordings"]); $i++)
872  {
873  $this->object->chat_recording->getRecord($_POST["recordings"][$i]);
874  $this->tpl->setCurrentBlock("recordings_row");
875  if($this->object->chat_recording->getTitle() != "")
876  {
877  $this->tpl->setVariable("RECORDING_TITLE", $this->object->chat_recording->getTitle());
878  }
879  if($this->object->chat_recording->getDescription() != "")
880  {
881  $this->tpl->setVariable("RECORDING_DESCRIPTION", $this->object->chat_recording->getDescription());
882  }
883  if ($moderator = $this->object->chat_recording->getModerator())
884  {
885  $this->tpl->setVariable("MODERATOR", $moderator);
886  }
887  $this->tpl->setVariable("START_TIME", date("Y-m-d H:i:s", $this->object->chat_recording->getStartTime()));
888  if ($this->object->chat_recording->getEndTime() > 0)
889  {
890  $this->tpl->setVariable("END_TIME", date("Y-m-d H:i:s", $this->object->chat_recording->getEndTime()));
891  }
892  $this->tpl->setVariable("ROW_CLASS",ilUtil::switchColor(++$counter,'tblrow1','tblrow2'));
893  $this->tpl->parseCurrentBlock();
894  }
895  $_SESSION['chat_recordings_del'] = $_POST['recordings'];
896  }
897 
898  public function deleteRecordingsObject()
899  {
900  global $rbacsystem;
901 
902  if (!$rbacsystem->checkAccess("moderate", $this->object->getRefId()))
903  {
904  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
905  }
906 
907  if(!is_array($_SESSION['chat_recordings_del']))
908  {
909  ilUtil::sendFailure($this->lng->txt('chat_recordings_none_selected'));
910  $this->recordingsObject();
911 
912  return false;
913  }
914 
915  $this->object->__initChatRecording();
916 
917  foreach($_SESSION['chat_recordings_del'] as $record_id)
918  {
919  $this->object->chat_recording->delete($record_id);
920  }
921  ilUtil::sendSuccess($this->lng->txt('chat_recordings_deleted'));
922  $this->recordingsObject();
923 
924  unset($_SESSION['chat_recordings_del']);
925  return true;
926  }
927 
928  public function exportRecordingObject()
929  {
930  global $rbacsystem;
931 
932  if (!$rbacsystem->checkAccess("moderate", $this->object->getRefId()))
933  {
934  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
935  }
936  $this->object->__initChatRecording();
937 
938  if (!$this->object->chat_recording->getRecord($_GET["record_id"]) ||
939  $this->object->chat_recording->getEndTime() == 0)
940  {
941  ilUtil::sendFailure($this->lng->txt('chat_recording_not_found'));
942  $this->recordingsObject();
943 
944  return false;
945  }
946 
947  $tmp_tpl =& new ilTemplate("tpl.chat_export_recording.html",true,true,"Modules/Chat");
948 
949  if($this->object->chat_recording->getTitle())
950  {
951  $tmp_tpl->setVariable("TITLE",$this->object->chat_recording->getTitle());
952  }
953  $tmp_tpl->setVariable("START_TIME",date("Y-m-d H:i:s", $this->object->chat_recording->getStartTime()));
954  $tmp_tpl->setVariable("END_TIME",date("Y-m-d H:i:s", $this->object->chat_recording->getEndTime()));
955  $tmp_tpl->setVariable("CONTENT",$this->object->chat_recording->exportMessages());
956 
957  ilUtil::deliverData($tmp_tpl->get(), "chat_recording_" . $_GET["record_id"] . ".html");
958  exit;
959  }
960 /*
961  function startRecordingObject()
962  {
963  global $rbacsystem,$ilUser;
964 
965  if (!$rbacsystem->checkAccess("moderate", $this->object->getRefId()))
966  {
967  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
968  }
969 
970  $this->object->__initChatRecording();
971  if($_GET["room_id"])
972  {
973  $this->object->chat_recording->setRoomId($_GET["room_id"]);
974  }
975  if (!$this->object->chat_recording->isRecording())
976  {
977  $this->object->chat_recording->setModeratorId($ilUser->getId());
978  $this->object->chat_recording->startRecording($_POST["title"]);
979  }
980  ilUtil::sendInfo($this->lng->txt("chat_recording_started"),true);
981  $this->showFramesObject();
982  }
983 */
984 /*
985  function stopRecordingObject()
986  {
987  global $rbacsystem,$ilUser;
988 
989  if (!$rbacsystem->checkAccess("moderate", $this->object->getRefId()))
990  {
991  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
992  }
993 
994  $this->object->__initChatRecording();
995  if($_GET["room_id"])
996  {
997  $this->object->chat_recording->setRoomId($_GET["room_id"]);
998  }
999  if ($this->object->chat_recording->isRecording())
1000  {
1001  $this->object->chat_recording->stopRecording($ilUser->getId());
1002  }
1003  ilUtil::sendInfo($this->lng->txt("chat_recording_stopped"),true);
1004  $this->showFramesObject();
1005  }
1006 */
1011  function showFramesObject()
1012  {
1013  global $rbacsystem, $ilCtrl;
1014 
1015  if (!$rbacsystem->checkAccess("read", $this->ref_id))
1016  {
1017  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
1018  }
1019 
1020  $this->showUserFrameObject();
1021  $this->tpl->show(false, false);
1022  exit;
1023  }
1024 
1029  {
1030  global $ilCtrl, $ilSetting, $ilMainMenu, $ilLocator, $ilUser, $rbacsystem, $ilObjDataCache, $lng;
1031  include_once 'Modules/Chat/classes/class.ilChatBlockedUsers.php';
1032  if (
1033  !$rbacsystem->checkAccess("read", $this->ref_id)
1034  || ilChatBlockedUsers::_isBlocked($ilObjDataCache->lookupObjId($this->ref_id), $ilUser->getId())
1035  )
1036  {
1037  $baseClass = 'ilchatpresentationgui';
1038  $ilCtrl->setParameter($baseClass, 'ref_id', $this->ref_id);
1039  ilUtil::redirect($ilCtrl->getLinkTarget($this, 'view', '', false, false));
1040  exit;
1041  }
1042 
1043  if ($_REQUEST["room_id"] && !$this->object->chat_room->getTitle())
1044  {
1045  $baseClass = 'ilchatpresentationgui';
1046  $ilCtrl->setParameter($baseClass, 'ref_id', $this->ref_id);
1047  ilUtil::sendFailure($lng->txt('chat_room_does_not_exist'), true);
1048  ilUtil::redirect($ilCtrl->getLinkTarget($this, 'view', '', false, false));
1049  exit;
1050  }
1051  $this->object->chat_room->setUserId($_SESSION["AccountId"]);
1052  $this->object->chat_room->updateLastVisit();
1053  $this->tpl = new ilTemplate("tpl.main.html", true, true);
1054 
1055  $this->__loadStylesheet(true);
1056  $this->tpl->addBlockFile("CONTENT", "content", "tpl.chat_user_frame_async.html",'Modules/Chat');
1057  $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
1058 
1059  $this->tpl->addCss("./Modules/Chat/templates/default/chat.css");
1060 
1061  $ilMainMenu->setSmallMode(false);
1062  $this->tpl->setVariable("MAINMENU", $ilMainMenu->getHTML());
1063 
1064  include_once 'Services/YUI/classes/class.ilYuiUtil.php';
1067 
1068  $this->tpl->addJavascript("./Services/JavaScript/js/Basic.js");
1069  $this->tpl->addJavascript("./Services/Navigation/js/ServiceNavigation.js");
1070  $this->tpl->addJavascript('./Services/YUI/js/2_5_0/yahoo/yahoo-min.js');
1071  $this->tpl->addJavascript('./Services/YUI/js/2_5_0/event/event-min.js');
1072  $this->tpl->addJavascript('./Services/YUI/js/2_5_0/connection/connection-min.js');
1073 
1074  $this->tpl->addJavascript('./Modules/Chat/js/ChatRoomList.js');
1075  $this->tpl->addJavascript('./Modules/Chat/js/ChatActiveUsersRoom.js');
1076  $this->tpl->addJavascript('./Modules/Chat/js/ChatOnlineUsers.js');
1077  $this->tpl->addJavascript('./Modules/Chat/js/ChatLanguage.js');
1078  $this->tpl->addJavascript('./Modules/Chat/js/ChatUserList.js');
1079  $this->tpl->addJavascript('./Modules/Chat/js/ChatContextMenu.js');
1080  $this->tpl->addJavascript('./Modules/Chat/js/ChatMessages.js');
1081  $this->tpl->addJavascript('./Modules/Chat/js/ChatUserFrameAsync.js');
1082 
1083  //$this->tpl->addJavascript('Modules/Chat/js/debug.js');
1084 
1085  //$this->tpl->addJavascript('./Modules/Chat/js/json.js');
1086  $this->tpl->addJavascript('./Modules/Chat/js/ChatMenu.js');
1087 
1088  $ilLocator->addRepositoryItems($this->object->getRefId());
1089  $ilLocator->addItem($this->object->getTitle(), 'repository.php?ref_id='.$this->object->getRefId(), '_top', $this->object->getRefId());
1090  $this->tpl->setLocator();
1091 
1092  $this->tpl->setCurrentBlock("js_chat_init");
1093  $ilCtrl->setParameter($this, 'ref_id', '#__ref_id');
1094  $link = $ilCtrl->getLinkTarget($this, "#__cmd", '', true);
1095  $this->tpl->setVariable("CHAT_BASE_URL_TEMPLATE", $link);
1096  $ilCtrl->clearParameters($this);
1097 
1098  $this->tpl->setVariable("BASE_REF_ID", $this->object->getRefId());
1099  $this->tpl->setVariable("BASE_ROOM_ID", $this->object->chat_room->getRoomId());
1100  $this->tpl->setVariable("ONLINE_USERS_TITLE", addslashes($this->lng->txt('chat_online_users')));
1101  $this->tpl->setVariable("ACTIVE_USERS_TITLE", addslashes($this->lng->txt('chat_active_users')));
1102  $this->tpl->setVariable("ROOM_LIST_TITLE", addslashes($this->lng->txt('chat_rooms')));
1103  $this->tpl->setVariable("CHATSERVER_ADDRESS",$this->object->server_comm->getServerFrameSource());
1104 
1105  $this->tpl->setVariable("CHAT_HIDE", addslashes($this->lng->txt('hide')));
1106  $this->tpl->setVariable("CHAT_SHOW", addslashes($this->lng->txt('show')));
1107  $this->tpl->setVariable("CHAT_OPEN", addslashes($this->lng->txt('chat_open')));
1108  $this->tpl->setVariable("CHAT_RECORDING_RUNNING", addslashes($this->lng->txt('chat_recording_running')));
1109  $this->tpl->setVariable("CHAT_RECORDING_ALREADY_RUNNING", addslashes($this->lng->txt('chat_recording_already_running')));
1110  $this->tpl->setVariable("CHAT_RECORDING_STOPPED", addslashes($this->lng->txt('chat_recording_stopped')));
1111 
1112  $this->tpl->setVariable("CHAT_EMPTY_MESSAGE", addslashes($this->lng->txt('chat_empty')));
1113 
1114  $this->tpl->setVariable("CHAT_CONFIRM_USER_INVITE", addslashes($this->lng->txt('chat_confirm_user_invite')));
1115  $this->tpl->setVariable("CHAT_CONFIRM_KICK_USER", addslashes($this->lng->txt('chat_confirm_kick_user')));
1116  $this->tpl->setVariable("CHAT_NO_TITLE_GIVEN", addslashes($this->lng->txt('chat_no_title_given')));
1117  $this->tpl->setVariable("CHAT_ADDRESS", addslashes($this->lng->txt('chat_address')));
1118  $this->tpl->setVariable("CHAT_WHISPER", addslashes($this->lng->txt('chat_whisper')));
1119  $this->tpl->setVariable("CHAT_KICK", addslashes($this->lng->txt('chat_kick')));
1120  $this->tpl->setVariable("CHAT_UNKICK", addslashes($this->lng->txt('chat_unkick')));
1121  $this->tpl->setVariable("CHAT_INVITE", addslashes($this->lng->txt('chat_invite')));
1122  $this->tpl->setVariable("CHAT_DISINVITE", addslashes($this->lng->txt('chat_disinvite')));
1123  $this->tpl->setVariable("CHAT_PROFILE", addslashes($this->lng->txt('chat_profile')));
1124  $this->tpl->setVariable("CANCEL", addslashes($this->lng->txt('cancel')));
1125 
1126  $this->tpl->setVariable("ADD_TO_BOOKMARK", addslashes($this->lng->txt('chat_add_to_bookmark')));
1127  $this->tpl->setVariable("ADD_TO_ADDRESSBOOK", addslashes($this->lng->txt('chat_add_to_addressbook')));
1128  $this->tpl->setVariable("EMPTY_ROOM", addslashes($this->lng->txt('chat_empty')));
1129  $this->tpl->setVariable("DELETE", addslashes($this->lng->txt('delete')));
1130  $this->tpl->setVariable("CONFIRM_DELETE_PRIVATE_ROOM", addslashes($this->lng->txt('chat_confirm_delete_private_room')));
1131  $this->tpl->setVariable("CHAT_CONFIRM_USER_INVITE", addslashes($this->lng->txt('chat_confirm_user_invite')));
1132  $this->tpl->setVariable("INVITE", addslashes($this->lng->txt('chat_invite')));
1133  $this->tpl->setVariable("DISINVITE", addslashes($this->lng->txt('chat_disinvite')));
1134  $this->tpl->setVariable("CHAT_USER_HIDDEN", addslashes($this->lng->txt('chat_user_hidden')));
1135  $this->tpl->setVariable("CHAT_USER_VISIBLE", addslashes($this->lng->txt('chat_user_visible')));
1136 
1137  $this->tpl->setVariable("TXT_REFRESH", addslashes($this->lng->txt('refresh')));
1138  $this->tpl->setVariable("TXT_HIDE_TEXTFORMAT", addslashes($this->lng->txt('chat_hide_textformat')));
1139  $this->tpl->setVariable("TXT_SHOW_TEXTFORMAT", addslashes($this->lng->txt('chat_show_textformat')));
1140  $this->tpl->setVariable("TXT_TEXTFORMAT", addslashes($this->lng->txt('chat_textformat')));
1141 
1142  $this->tpl->parseCurrentBlock();
1143 
1144  if($_REQUEST["room_id"])
1145  {
1146  $this->tpl->setVariable("TITLE",$this->object->chat_room->getTitle());
1147  }
1148  else
1149  {
1150  $this->tpl->setVariable("TITLE",$this->object->getTitle());
1151  }
1152 
1153  if($ilUser->getId() != ANONYMOUS_USER_ID)
1154  {
1155  $ilCtrl->setParameter($this, "room_id", $this->object->chat_room->getRoomId());
1156  $this->tpl->setVariable("ADD_FORMACTION", $ilCtrl->getFormAction($this, "addPrivateRoom"));
1157  $this->tpl->setVariable("TXT_ADD_PRIVATE_CHATROOM", $this->lng->txt("chat_add_private_chatroom"));
1158  $this->tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
1159  }
1160 
1161  // smilies
1162  if ($ilSetting->get('chat_smilies_status') == 1)
1163  {
1164  include_once 'Modules/Chat/classes/class.ilChatSmilies.php';
1165  $smilies = ilChatSmilies::_getSmilies();
1166  foreach($smilies as $smiley)
1167  {
1168  $this->tpl->setCurrentBlock("smilies_element");
1169  $this->tpl->setVariable("SMILEY_SRC", $smiley['smiley_fullpath']);
1170  $parts = explode("\n", $smiley["smiley_keywords"]);
1171  $this->tpl->setVariable("SMILEY_CONTENT", $parts[0]);
1172 
1173  $this->tpl->parseCurrentBlock();
1174  }
1175  $this->tpl->setCurrentBlock("smilies_selector");
1176  $this->tpl->setVariable('TXT_SHOW_SMILIES', $this->lng->txt('chat_show_smilies'));
1177  $this->tpl->setVariable('TXT_HIDE_SMILIES', $this->lng->txt('chat_hide_smilies'));
1178  $this->tpl->parseCurrentBlock();
1179  }
1180 
1181  $this->__showInputAreas();
1182  $this->tpl->fillJavaScriptFiles();
1183  $this->tpl->fillCssFiles();
1184  $this->tpl->fillContentStyle();
1185  $this->tpl->show(false, false);
1186  exit;
1187  }
1188 
1190  {
1191  global $rbacsystem, $ilUser;
1192 
1193  $result = new stdClass();
1194 
1195  if (!$rbacsystem->checkAccess("read", $this->ref_id))
1196  {
1197  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
1198  $result->ok = false;
1199  $result->errormsg = $this->lng->txt("msg_no_perm_read");
1200  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
1202  exit;
1203  }
1204 
1205  include 'Modules/Chat/classes/class.ilChatBlock.php';
1206  $block = new ilChatBlock();
1207  $last_known_id = $_REQUEST["chat_last_known_id"] ? $_REQUEST["chat_last_known_id"] : 0;
1208 
1209  $new_last_known_id = 0;
1210 
1211  $msg = $block->getMessages
1212  (
1213  $this->object->chat_room->getObjId(),
1214  $this->object->chat_room->getRoomId(),
1215  $last_known_id,
1216  $new_last_known_id // by ref
1217  );
1218 
1219  $ilUser->setPref
1220  (
1221  'chatviewer_last_selected_room',
1222  $this->object->chat_room->getObjId(). ',' . $this->object->chat_room->getRoomId()
1223  );
1225  (
1226  $ilUser->getId(), 'chatviewer_last_selected_room',
1227  $this->object->chat_room->getObjId(). ',' . $this->object->chat_room->getRoomId()
1228  );
1229 
1230  $result->messages = $msg;
1231  $result->ok = true;
1232 
1233  $result->lastId = $new_last_known_id;
1234 
1235  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
1237  exit;
1238  }
1239 
1240  private function __showInputAreas()
1241  {
1242  global $rbacsystem, $ilCtrl, $ilUser, $ilSetting;
1243 
1244  //$this->tpl = new ilTemplate("tpl.main.html", true, true);
1245  $this->__loadStylesheet();
1246  $this->tpl->addBlockFile("CONTENT", "content", "tpl.chat_input_frame.html",'Modules/Chat');
1247 
1248  if($this->error)
1249  {
1250  ilUtil::sendFailure($this->error);
1251  }
1252  if($ilUser->getId() != ANONYMOUS_USER_ID)
1253  {
1254  if($_GET["p_id"])
1255  {
1256  $user_obj =& new ilObjUser((int) $_GET["p_id"]);
1257  $message = $this->lng->txt("chat_private_message")." ";
1258  $message .= $this->object->chat_user->getLogin()." -> ".$user_obj->getLogin();
1259  ilUtil::sendInfo($message);
1260  }
1261  else if($_GET["a_id"])
1262  {
1263  $user_obj =& new ilObjUser((int) $_GET["a_id"]);
1264  $message = $this->lng->txt("chat_address_user")." ".$user_obj->getLogin();
1265  ilUtil::sendInfo($message);
1266  }
1267 
1268  $ilCtrl->setParameter($this, "room_id", $_REQUEST["room_id"]);
1269  if ($_GET["p_id"])
1270  {
1271  $ilCtrl->setParameter($this, "p_id", $_GET["p_id"]);
1272  }
1273  else if ($_GET["a_id"])
1274  {
1275  $ilCtrl->setParameter($this, "a_id", $_GET["a_id"]);
1276  }
1277  $this->tpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this, "inputAsync"));
1278  $ilCtrl->clearParameters($this);
1279 
1280  $this->tpl->setVariable("TXT_NEW_MESSAGE",$this->lng->txt('chat_new_message'));
1281  $this->tpl->setVariable("TXT_COLOR",$this->lng->txt("chat_color"));
1282  $this->tpl->setVariable("TXT_TYPE",$this->lng->txt("chat_type"));
1283  $this->tpl->setVariable("TXT_FACE",$this->lng->txt("chat_face"));
1284  $this->tpl->setVariable("TXT_INPUT",$this->lng->txt("chat_input"));
1285 
1286  if ($_GET["p_id"])
1287  {
1288  $this->tpl->setCurrentBlock("cancel");
1289  $this->tpl->setVariable("TXT_SUBMIT_CANCEL",$this->lng->txt("cancel_whisper"));
1290  $this->tpl->parseCurrentBlock();
1291  $this->tpl->setVariable("TXT_SUBMIT_OK",$this->lng->txt("ok"));
1292  }
1293  elseif($_GET["a_id"])
1294  {
1295  $this->tpl->setCurrentBlock("cancel");
1296  $this->tpl->setVariable("TXT_SUBMIT_CANCEL",$this->lng->txt("cancel_talk"));
1297  $this->tpl->parseCurrentBlock();
1298  $this->tpl->setVariable("TXT_SUBMIT_OK",$this->lng->txt("ok"));
1299  }
1300  else
1301  {
1302  $this->tpl->setVariable("TXT_SUBMIT_OK",$this->lng->txt("ok"));
1303  }
1304  // export
1305  if ($ilSetting->get('chat_export_status') == 0 || ($ilSetting->get('chat_export_status') == 1 && $rbacsystem->checkAccess("moderate", $this->ref_id) ) )
1306  {
1307  $this->tpl->setVariable("TXT_HTML_EXPORT",$this->lng->txt('exp_html'));
1308  }
1309 
1310  //$this->tpl->setVariable("TXT_HTML_EXPORT",$this->lng->txt('exp_html'));
1311 
1312  $this->tpl->setVariable("SELECT_COLOR",$this->__getColorSelect());
1313  $this->tpl->setVariable("RADIO_TYPE",$this->__getFontType());
1314  $this->tpl->setVariable("CHECK_FACE",$this->__getFontFace());
1315 
1316  if ($rbacsystem->checkAccess("moderate", $this->object->getRefId()))
1317  {
1318  $this->object->__initChatRecording();
1319  $this->tpl->setCurrentBlock("moderator");
1320  $this->object->chat_recording->setRoomId($this->object->chat_room->getRoomId());
1321  //if ($this->object->chat_recording->isRecording())
1322  //{
1323  if ($this->object->chat_recording->getTitle() != "")
1324  {
1325  $this->tpl->setVariable("TXT_TITLE_STOP_RECORDING", $this->lng->txt("chat_recording_title"));
1326  $this->tpl->setVariable("VAL_TITLE_STOP_RECORDING", $this->object->chat_recording->getTitle());
1327  }
1328  if ($this->object->chat_recording->getDescription() != "")
1329  {
1330  $this->tpl->setVariable("TXT_DESCRIPTION_STOP_RECORDING", $this->lng->txt("chat_recording_description"));
1331  $this->tpl->setVariable("VAL_DESCRIPTION_STOP_RECORDING", $this->object->chat_recording->getDescription());
1332  }
1333  $this->tpl->setVariable("TXT_SUBMIT_STOP_RECORDING", $this->lng->txt("chat_stop_recording"));
1334  //}
1335  //else
1336  //{
1337  $this->tpl->setVariable("TXT_TITLE_START_RECORDING", $this->lng->txt("chat_recording_title"));
1338  $this->tpl->setVariable("TXT_DESCRIPTION_START_RECORDING", $this->lng->txt("chat_recording_description"));
1339  $this->tpl->setVariable("TXT_SUBMIT_START_RECORDING", $this->lng->txt("chat_start_recording"));
1340  //}
1341 
1342  $ilCtrl->setParameter($this, "room_id", $this->object->chat_room->getRoomId());
1343  $this->tpl->setVariable("MODERATOR_FORMACTION",
1344  $ilCtrl->getFormAction($this, "startRecording"));
1345  $this->tpl->setVariable("TXT_RECORDINGS",$this->lng->txt('chat_recordings'));
1346  $this->tpl->setVariable("MODERATOR_TARGET","_top");
1347  $this->tpl->parseCurrentBlock("moderator");
1348  }
1349  }
1350  // permanent link
1351  include_once 'Services/PermanentLink/classes/class.ilPermanentLinkGUI.php';
1352  $permalink = new ilPermanentLinkGUI('chat', $this->object->getRefId());
1353  $this->tpl->setVariable('PERMANENT_LINK', $permalink->getHTML(), '&room_id='.$this->object->chat_room->getRoomId());
1354  /*
1355  $this->tpl->setCurrentBlock('perma_link');
1356  $this->tpl->setVariable('PERMA_LINK', ILIAS_HTTP_PATH.'/goto.php?target='.$this->object->getType().'_'.$this->object->getRefId().'&client_id='.CLIENT_ID);
1357  $this->tpl->setVariable('TXT_PERMA_LINK', $this->lng->txt('chat_link_to_this_chat'));
1358  $this->tpl->setVariable('PERMA_TARGET', '_top');
1359  $this->tpl->parseCurrentBlock();
1360  */
1361  //$this->tpl->show(false);
1362  //exit;
1363  }
1364 
1365  // Direct invitations from personal desktop
1366  public function invitePDObject()
1367  {
1368  global $ilUser;
1369 
1370  if(!$_GET['usr_id'])
1371  {
1372  ilUtil::sendFailure($this->lng->txt('chat_no_user_selected',true));
1373  $this->showFramesObject();
1374  }
1375  // Create room
1376  $this->object->chat_room->setOwnerId($ilUser->getId());
1377  $this->object->chat_room->setTitle(ilObjUser::_lookupLogin($ilUser->getId()).
1378  ' : '.
1379  ilObjUser::_lookupLogin($_GET['usr_id']));
1380 
1381  // only add room if it doesn't exist
1382  if(!$id = $this->object->chat_room->lookupRoomId())
1383  {
1384  $id = $this->object->chat_room->add();
1385  }
1386 
1387  // Send message
1388  $this->object->chat_room->setRoomId($id);
1389  $this->object->chat_room->invite((int) $_GET["usr_id"]);
1390  $this->object->sendMessage((int) $_GET['usr_id']);
1391 
1392  if((int)$this->object->chat_room->getRoomId())
1393  {
1394  ilUtil::sendSuccess(sprintf($this->lng->txt("chat_user_invited_private"), $this->object->chat_room->getTitle()),true);
1395  }
1396  else
1397  {
1398  ilUtil::sendSuccess(sprintf($this->lng->txt("chat_user_invited_public"), $this->object->getTitle()),true);
1399  }
1400 
1401  ilUtil::redirect('ilias.php?baseClass=ilChatPresentationGUI&ref_id='.$this->object->getRefId().'&room_id='.$id);
1402  }
1403 
1404  public function closeFrame()
1405  {
1406  $this->__loadStylesheet(true);
1407  $this->tpl->addBlockFile("CONTENT", "content", "tpl.chat_close.html",'Modules/Chat');
1408  ilUtil::sendInfo("Your session is expired please login to ILIAS.");
1409  $this->tpl->touchBlock("content");
1410  }
1411 
1412  public function exportObject()
1413  {
1414  global $lng, $ilSetting, $rbacsystem;
1415  if ($ilSetting->get('chat_export_status') == 0 || ($ilSetting->get('chat_export_status') == 1 && $rbacsystem->checkAccess("moderate", $this->ref_id) ) )
1416  {
1417  $tmp_tpl =& new ilTemplate("tpl.chat_export.html",true,true,"Modules/Chat");
1418  $filename = $this->object->getTitle();
1419  if($this->object->chat_room->getRoomId())
1420  {
1421  $tmp_tpl->setVariable("CHAT_NAME",$this->object->chat_room->getTitle());
1422  $filename .= ' - ' . $this->object->chat_room->getTitle();
1423  }
1424  else
1425  {
1426  $tmp_tpl->setVariable("CHAT_NAME",$this->object->getTitle());
1427  }
1428 
1429  global $ilSetting;
1430 
1431  $export_period = $ilSetting->get('chat_export_period');
1432  $time_min = time() - $export_period * 60 * 60 * 24;
1433  $tmp_tpl->setVariable("CHAT_DATE",strftime("%c",time()));
1434  $tmp_tpl->setVariable("CONTENT",$this->object->chat_room->getAllMessages($time_min));
1435  ilUtil::deliverData($tmp_tpl->get(), $filename . ".html");
1436  exit;
1437  }
1438  else
1439  {
1440  ilUtil::sendFailure($lng->txt("msg_no_perm_read"));
1441  }
1442  }
1443 
1444 
1445  private function __showAdminAddRoomSelect()
1446  {
1447  $opt = array("createRoom" => $this->lng->txt("chat_room_select"));
1448 
1449  return ilUtil::formSelect("","action_b",$opt,false,true);
1450  }
1451 
1452  private function __showAdminRoomSelect()
1453  {
1454  global $rbacsystem;
1455 
1456  $opt["exportRoom"] = $this->lng->txt("chat_html_export");
1457 
1458  if($rbacsystem->checkAccess('write',$this->object->getRefId()) or
1459  count($this->object->chat_room->getRoomsOfObject()))
1460  {
1461  $opt["refreshRoom"] = $this->lng->txt("chat_refresh");
1462  }
1463 
1464  if(count($this->object->chat_room->getRoomsOfObject()))
1465  {
1466  $opt["renameRoom"] = $this->lng->txt("rename");
1467  $opt["deleteRoom"] = $this->lng->txt("delete");
1468  }
1469  return ilUtil::formSelect(isset($_SESSION["room_id_delete"]) ? "deleteRoom" : "",
1470  "action",
1471  $opt,
1472  false,
1473  true);
1474  }
1475 
1476 
1477  private function __loadStylesheet($expires = false)
1478  {
1479  $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
1480  $this->tpl->setCurrentBlock("ChatStyle");
1481  $this->tpl->setVariable("LOCATION_CHAT_STYLESHEET", ilUtil::getStyleSheetLocation());
1482  if($expires)
1483  {
1484  //$this->tpl->setVariable("EXPIRES","<meta http-equiv=\"expires\" content=\"now\">".
1485  // "<meta http-equiv=\"refresh\" content=\"30\">");
1486  }
1487  $this->tpl->parseCurrentBlock();
1488  }
1489 
1490  private function __getColorSelect()
1491  {
1492  $colors = array("black" => $this->lng->txt("chat_black"),
1493  "red" => $this->lng->txt("chat_red"),
1494  "green" => $this->lng->txt("chat_green"),
1495  "maroon" => $this->lng->txt("chat_maroon"),
1496  "olive" => $this->lng->txt("chat_olive"),
1497  "navy" => $this->lng->txt("chat_navy"),
1498  "purple" => $this->lng->txt("chat_purple"),
1499  "teal" => $this->lng->txt("chat_teal"),
1500  "silver" => $this->lng->txt("chat_silver"),
1501  "gray" => $this->lng->txt("chat_gray"),
1502  "lime" => $this->lng->txt("chat_lime"),
1503  "yellow" => $this->lng->txt("chat_yellow"),
1504  "fuchsia" => $this->lng->txt("chat_fuchsia"),
1505  "aqua" => $this->lng->txt("chat_aqua"),
1506  "blue" => $this->lng->txt("chat_blue"));
1507 
1508  return ilUtil::formSelect($_POST["color"],"color",$colors,false,true);
1509  }
1510 
1511  private function __getFontType()
1512  {
1513  $types = array("times" => $this->lng->txt("chat_times"),
1514  "tahoma" => $this->lng->txt("chat_tahoma"),
1515  "arial" => $this->lng->txt("chat_arial"));
1516 
1517  $_POST["type"] = $_POST["type"] ? $_POST["type"] : "times";
1518 
1519  foreach($types as $name => $type)
1520  {
1521  $this->tpl->setCurrentBlock("FONT_TYPES");
1522  $this->tpl->setVariable("BL_TXT_TYPE",$type);
1523  $this->tpl->setVariable("FONT_TYPE",$name);
1524  $this->tpl->setVariable("TYPE_CHECKED",$_POST["type"] == $name ? "checked=\"checked\"" : "");
1525  $this->tpl->parseCurrentBlock();
1526  }
1527  }
1528 
1529  private function __getFontFace()
1530  {
1531  $_POST["face"] = is_array($_POST["face"]) ? $_POST["face"] : array();
1532 
1533  $types = array("bold" => $this->lng->txt("chat_bold"),
1534  "italic" => $this->lng->txt("chat_italic"),
1535  "underlined" => $this->lng->txt("chat_underlined"));
1536 
1537  $this->tpl->setCurrentBlock("FONT_FACES");
1538  $this->tpl->setVariable("BL_TXT_FACE","<b>".$this->lng->txt("chat_bold")."</b>");
1539  $this->tpl->setVariable("FONT_FACE","bold");
1540  $this->tpl->setVariable("FACE_CHECKED",in_array("bold",$_POST["face"]) ? "checked=\"checked\"" : "");
1541  $this->tpl->parseCurrentBlock();
1542 
1543  $this->tpl->setCurrentBlock("FONT_FACES");
1544  $this->tpl->setVariable("BL_TXT_FACE","<i>".$this->lng->txt("chat_italic")."</i>");
1545  $this->tpl->setVariable("FONT_FACE","italic");
1546  $this->tpl->setVariable("FACE_CHECKED",in_array("italic",$_POST["face"]) ? "checked=\"checked\"" : "");
1547  $this->tpl->parseCurrentBlock();
1548 
1549  $this->tpl->setCurrentBlock("FONT_FACES");
1550  $this->tpl->setVariable("BL_TXT_FACE","<u>".$this->lng->txt("chat_underlined")."</u>");
1551  $this->tpl->setVariable("FONT_FACE","underlined");
1552  $this->tpl->setVariable("FACE_CHECKED",in_array("underlined",$_POST["face"]) ? "checked=\"checked\"" : "");
1553  $this->tpl->parseCurrentBlock();
1554  }
1555 
1556  private function __formatMessage()
1557  {
1558  $tpl = new ilTemplate("tpl.chat_message.html",true,true,'Modules/Chat');
1559  $_POST['message'] = htmlentities(trim($_POST['message']));
1560  $_POST['message'] = ilUtil::stripSlashes($_POST['message']);
1561  $_POST['message'] = preg_replace('/%u([0-9A-Fa-f]{4})/im', '&#x$1;', $_POST['message']);
1562  // make links clickable
1563  $_POST['message'] = ilUtil::makeClickable($_POST['message']);
1564 
1565  $tpl->setVariable("MESSAGE",$_POST["message"]);
1566  $tpl->setVariable("FONT_COLOR",$_POST["color"]);
1567  $tpl->setVariable("FONT_FACE",$_POST["type"]);
1568 
1569  if($_GET["p_id"])
1570  {
1571  $user_obj =& new ilObjUser((int) $_SESSION["AccountId"]);
1572  $user_obj->read();
1573 
1574  $tpl->setCurrentBlock("private");
1575  $tpl->setVariable("PRIVATE_U_COLOR","red");
1576  $tpl->setVariable("PRIVATE_FROM",$user_obj->getLogin());
1577 
1578  $user_obj =& new ilObjUser((int) $_GET["p_id"]);
1579  $user_obj->read();
1580  $tpl->setVariable("PRIVATE_TO",$user_obj->getLogin());
1581  $tpl->parseCurrentBlock();
1582  }
1583  else if($_GET["a_id"])
1584  {
1585  $tpl->setCurrentBlock("address");
1586  $tpl->setVariable("ADDRESS_FROM_COLOR","navy");
1587  $user_obj =& new ilObjUser((int) $_SESSION["AccountId"]);
1588  $user_obj->read();
1589  $tpl->setVariable("ADDRESS_FROM",$user_obj->getLogin());
1590 
1591  $tpl->setVariable("ADDRESS_TO_COLOR","red");
1592  $user_obj =& new ilObjUser((int) $_GET["a_id"]);
1593  $user_obj->read();
1594  $tpl->setVariable("ADDRESS_TO",$user_obj->getLogin());
1595  $tpl->parseCurrentBlock();
1596  }
1597  else
1598  {
1599  $tpl->setCurrentBlock("normal");
1600  $tpl->setVariable("NORMAL_U_COLOR","navy");
1601  $tpl->setVariable("NORMAL_UNAME",$this->object->chat_user->getLogin());
1602  $tpl->parseCurrentBlock();
1603  }
1604  // OPEN TAGS
1605  if($_POST["face"])
1606  {
1607  foreach($_POST["face"] as $face)
1608  {
1609  $tpl->setCurrentBlock("type_open");
1610  switch($face)
1611  {
1612  case "bold":
1613  $tpl->setVariable("TYPE_TYPE_O","b");
1614  break;
1615  case "italic":
1616  $tpl->setVariable("TYPE_TYPE_O","i");
1617  break;
1618 
1619  case "underlined":
1620  $tpl->setVariable("TYPE_TYPE_O","u");
1621  break;
1622  }
1623  $tpl->parseCurrentBlock();
1624  }
1625  $_POST["face"] = array_reverse($_POST["face"]);
1626  foreach($_POST["face"] as $face)
1627  {
1628  $tpl->setCurrentBlock("type_close");
1629  switch($face)
1630  {
1631  case "bold":
1632  $tpl->setVariable("TYPE_TYPE_C","b");
1633  break;
1634  case "italic":
1635  $tpl->setVariable("TYPE_TYPE_C","i");
1636  break;
1637 
1638  case "underlined":
1639  $tpl->setVariable("TYPE_TYPE_C","u");
1640  break;
1641  }
1642  $tpl->parseCurrentBlock();
1643  }
1644  }
1645 
1646  $message = preg_replace("/\r/","",$tpl->get());
1647  $message = preg_replace("/\n/","",$message);
1648 
1649  return $message;
1650  }
1651 
1652  public function exportRoomObject()
1653  {
1654  global $rbacsystem;
1655 
1656  if (!$rbacsystem->checkAccess("read", $this->ref_id))
1657  {
1658  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
1659  }
1660 
1661  if (isset($_GET['del_id']))
1662  $_POST['del_id'] = array($_GET['del_id']);
1663 
1664  if(!isset($_POST["del_id"]))
1665  {
1666  ilUtil::sendInfo($this->lng->txt("chat_select_one_room"));
1667  $this->viewObject();
1668 
1669  return false;
1670  }
1671  $this->__exportRooms();
1672  }
1673 
1674  private function __exportRooms()
1675  {
1676  include_once "Modules/Chat/classes/class.ilFileDataChat.php";
1677 
1678  if(count($_POST["del_id"]) == 1)
1679  {
1680  $this->object->chat_room->setRoomId($_POST["del_id"][0]);
1681  $this->exportObject();
1682  }
1683 
1684  $file_obj =& new ilFileDataChat($this->object);
1685 
1686  foreach($_POST["del_id"] as $id)
1687  {
1688  $this->object->chat_room->setRoomId((int) $id);
1689 
1690  $tmp_tpl =& new ilTemplate("tpl.chat_export.html",true,true,"Modules/Chat");
1691 
1692  if($id)
1693  {
1694  $tmp_tpl->setVariable("CHAT_NAME",$this->object->chat_room->getTitle());
1695  }
1696  else
1697  {
1698  $tmp_tpl->setVariable("CHAT_NAME",$this->object->getTitle());
1699  }
1700  $tmp_tpl->setVariable("CHAT_DATE",strftime("%c",time()));
1701  $tmp_tpl->setVariable("CONTENT",$this->object->chat_room->getAllMessages());
1702 
1703  $file_obj->addFile("chat_".$this->object->chat_room->getRoomId().".html",$tmp_tpl->get());
1704  }
1705  $fname = $file_obj->zip();
1706  ilUtil::deliverFile($fname,"ilias_chat.zip");
1707  }
1708 
1714  public function getTabs(&$tabs_gui)
1715  {
1716  global $rbacsystem,$rbacreview, $ilAccess;
1717 
1718  $this->ctrl->setParameter($this,"ref_id",$this->object->getRefId());
1719 
1720 //echo "-".$this->ctrl->getCmd()."-";
1721 
1722  if($rbacsystem->checkAccess('read',$this->object->getRefId()))
1723  {
1724  $force_active = ($_GET["cmd"] == "" || $_GET["cmd"] == "view")
1725  ? true
1726  : false;
1727  $tabs_gui->addTarget("chat_rooms",
1728  $this->ctrl->getLinkTarget($this, "view"), array("view", ""), get_class($this),
1729  "", $force_active);
1730  }
1731 
1732  // info tab
1733  if ($ilAccess->checkAccess('visible', '', $this->ref_id))
1734  {
1735  $force_active = ($this->ctrl->getNextClass() == "ilinfoscreengui"
1736  || strtolower($_GET["cmdClass"]) == "ilnotegui")
1737  ? true
1738  : false;
1739  //echo "-$force_active-";
1740  $tabs_gui->addTarget("info_short",
1741  $this->ctrl->getLinkTargetByClass(
1742  array("ilobjchatgui", "ilinfoscreengui"), "showSummary"),
1743  array("showSummary", "infoScreen"),
1744  "", "", $force_active);
1745  }
1746  // settings tab
1747  if($rbacsystem->checkAccess('write',$this->object->getRefId()))
1748  {
1749  $force_active = ($_GET["cmd"] == "edit")
1750  ? true
1751  : false;
1752  $tabs_gui->addTarget("edit_properties",
1753  $this->ctrl->getLinkTarget($this, "edit"), "edit", get_class($this),
1754  "", $force_active);
1755  }
1756 
1757  // blocked users
1758  if($rbacsystem->checkAccess('moderate',$this->object->getRefId()))
1759  {
1760  $tabs_gui->addTarget("chat_blocked_users",
1761  $this->ctrl->getLinkTarget($this, "blockedUsers"),
1762  array("blockedUsers", "unBlockUsers", "blockUser"), get_class($this));
1763  }
1764 
1765  // recordings
1766  if($rbacsystem->checkAccess('moderate',$this->object->getRefId()))
1767  {
1768  $tabs_gui->addTarget("chat_recordings",
1769  $this->ctrl->getLinkTarget($this, "recordings"), "recordings", get_class($this));
1770  }
1771 
1772  // permissions
1773  if($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
1774  {
1775  $tabs_gui->addTarget("perm_settings",
1776  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
1777  }
1778  }
1779 
1780  private function __prepareOutput()
1781  {
1782  // output objects
1783  $this->tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
1784  $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
1785 
1786  // output locator
1787  $this->__setLocator();
1788 
1789  // output message
1790  if ($this->message)
1791  {
1792  ilUtil::sendInfo($this->message);
1793  }
1794 
1795  // display infopanel if something happened
1797 
1798  // set header
1799  $this->__setHeader();
1800  }
1801 
1802  private function __setHeader()
1803  {
1804  include_once './classes/class.ilTabsGUI.php';
1805 
1806  $this->tpl->setCurrentBlock("header_image");
1807  $this->tpl->setVariable("IMG_HEADER", ilUtil::getImagePath("icon_chat_b.gif"));
1808  $this->tpl->parseCurrentBlock();
1809  $this->tpl->setVariable("HEADER",$this->object->getTitle());
1810  $this->tpl->setVariable("H_DESCRIPTION",$this->object->getDescription());
1811 
1812  #$tabs_gui =& new ilTabsGUI();
1813  $this->getTabs($this->tabs_gui);
1814 
1815  // output tabs
1816  #$this->tpl->setVariable("TABS", $tabs_gui->getHTML());
1817  }
1818 
1819  private function __setLocator()
1820  {
1821  global $tree;
1822  global $ilias_locator;
1823 
1824  $this->tpl->addBlockFile("LOCATOR", "locator", "tpl.locator.html", "Services/Locator");
1825 
1826  $counter = 0;
1827  foreach ($tree->getPathFull($this->object->getRefId()) as $key => $row)
1828  {
1829  if($counter++)
1830  {
1831  $this->tpl->touchBlock('locator_separator_prefix');
1832  }
1833 
1834  $this->tpl->setCurrentBlock("locator_item");
1835 
1836  if($row["type"] == 'chat')
1837  {
1838  $this->tpl->setVariable("ITEM",$this->object->getTitle());
1839  $this->tpl->setVariable("LINK_ITEM",$this->ctrl->getLinkTarget($this));
1840  }
1841  elseif ($row["child"] != $tree->getRootId())
1842  {
1843  $this->tpl->setVariable("ITEM", $row["title"]);
1844  $this->tpl->setVariable("LINK_ITEM","repository.php?ref_id=".$row["child"]);
1845  }
1846  else
1847  {
1848  $this->tpl->setVariable("ITEM", $this->lng->txt("repository"));
1849  $this->tpl->setVariable("LINK_ITEM","repository.php?ref_id=".$row["child"]);
1850  }
1851 
1852  $this->tpl->parseCurrentBlock();
1853  }
1854 
1855  $this->tpl->setVariable("TXT_LOCATOR",$this->lng->txt("locator"));
1856  $this->tpl->parseCurrentBlock();
1857  }
1858 
1859  public function _goto($a_target)
1860  {
1861  global $ilAccess, $ilErr, $lng;
1862 
1863  if ($ilAccess->checkAccess("read", "", $a_target))
1864  {
1865  $_GET["ref_id"] = $a_target;
1866  $_GET["cmd"] = "view";
1867  $_GET["baseClass"] = "ilChatHandlerGUI";
1868  include("ilias.php");
1869  exit;
1870  }
1871  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
1872  {
1873  $_GET["cmd"] = "frameset";
1874  $_GET["target"] = "";
1875  $_GET["ref_id"] = ROOT_FOLDER_ID;
1876  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
1877  ilObject::_lookupTitle(ilObject::_lookupObjId($a_target))), true);
1878  include("repository.php");
1879  exit;
1880  }
1881 
1882  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
1883  }
1884 
1885  public function showUserProfileObject()
1886  {
1887  global $tpl, $ilCtrl;
1888 
1889  require_once './Services/User/classes/class.ilPublicUserProfileGUI.php';
1890  $profile_gui = new ilPublicUserProfileGUI((int)$_GET['user']);
1891  $tpl->setContent($ilCtrl->getHTML($profile_gui));
1892  $tpl->show();
1893  exit();
1894  }
1895 
1896  public function addLocatorItems()
1897  {
1898  global $ilLocator;
1899 
1900  if (is_object($this->object))
1901  {
1902  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ''), '', $_GET['ref_id']);
1903  }
1904  }
1905 
1911  function infoScreenObject()
1912  {
1913  $this->ctrl->setCmd("showSummary");
1914  $this->ctrl->setCmdClass("ilinfoscreengui");
1915  $this->infoScreen();
1916  }
1917 
1921  function infoScreen()
1922  {
1923  global $ilAccess;
1924 
1925  if (!$ilAccess->checkAccess("visible", "", $this->ref_id))
1926  {
1927  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
1928  }
1929 
1930  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
1931  $info = new ilInfoScreenGUI($this);
1932 
1933  $info->enablePrivateNotes();
1934 
1935  if ($ilAccess->checkAccess("read", "", $_GET["ref_id"]))
1936  {
1937  //$info->enableNews();
1938  }
1939 
1940  // no news editing for files, just notifications
1941 // $info->enableNewsEditing(false);
1942  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
1943  {
1944 // $news_set = new ilSetting("news");
1945 // $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1946 
1947 // if ($enable_internal_rss)
1948 // {
1949 // $info->setBlockProperty("news", "settings", true);
1950 // $info->setBlockProperty("news", "public_notifications_option", true);
1951 // }
1952  }
1953 
1954  // standard meta data
1955  $info->addMetaDataSections($this->object->getId(),0, $this->object->getType());
1956 
1957  // forward the command
1958  $this->ctrl->forwardCommand($info);
1959 
1960  }
1961 
1962 
1963  private function __updateChatSessionAsync() {
1964  $this->object->chat_room->setUserId($_SESSION["AccountId"]);
1965  $this->object->chat_room->updateLastVisit();
1966  }
1967 
1968  private function fetchOnlineUsers($active_users = array()) {
1969  global $ilCtrl, $ilUser;
1970  $this->__updateChatSessionAsync();
1971  $all_users = $this->object->chat_room->getOnlineUsers();
1972 
1973  // filter blocked users
1974  $filtered_users = array();
1975 
1976  include_once 'Modules/Chat/classes/class.ilChatBlockedUsers.php';
1977 
1978  $activeMap = array();
1979  foreach($active_users as $user)
1980  {
1981  $activeMap[$user->id] = 1;
1982  }
1983 
1984  $hidden_count = 0;
1985  foreach($all_users as $user)
1986  {
1987  if($user['user_id'] == $_SESSION['AccountId'] || $user['user_id'] == ANONYMOUS_USER_ID || $activeMap[$user['user_id']]) {
1988  continue;
1989  }
1990 
1991  $oUser = new ilObjUser();
1992  $oUser->setId($user['user_id']);
1993  $oUser->read();
1994 
1995  if($oUser->getPref('hide_own_online_status') == 'y') {
1996  $hidden_count++;
1997  continue;
1998  }
1999 
2000  $filtered_users[] = $oUser;
2001  }
2002 
2003  $out = array();
2004 
2005  foreach($filtered_users as $user) {
2006  $new_user = new stdClass();
2007  if($user->getId() != ANONYMOUS_USER_ID) {
2008  $new_user->anonymous = false;
2009  $new_user->id = $user->getId();
2010  $new_user->login = $user->getLogin();
2011  if (in_array($user->getPref("public_profile"), array("y", "g"))) {
2012  // public_profile
2013  $new_user->pp = '1';
2014  $new_user->img = $user->getPersonalPicturePath();
2015  // display_name
2016  $new_user->dn = $user->getFirstname().' '.$user->getLastname().' ('.$user->getLogin().')';
2017  }
2018  else {
2019  // public_profile
2020  $new_user->pp = '0';
2021  $new_user->img = ilUtil::getImagePath("no_photo_xsmall.jpg");
2022  // display_name
2023  $new_user->dn = $user->getLogin();
2024  }
2025 
2026  if(!ilChatBlockedUsers::_isBlocked($this->object->getId(),$user->getId()))
2027  {
2028  /*
2029  * invitation message
2030  */
2031  $link = "";
2032  if($this->object->chat_room->isInvited($user->getId())) {
2033  // permission_disinvite
2034  $new_user->pmdi = 1;
2035  // permisssion_invite
2036  $new_user->pmi = 0;
2037  }
2038  else {
2039  // permission_disinvite
2040  $new_user->pmdi = 0;
2041  // permission_invite
2042  $new_user->pmi = 1;
2043  }
2044  }
2045  }
2046  else
2047  {
2048  $new_user->anonymous = true;
2049  $new_user->id = 0;
2050  // display_name
2051  $new_user->dn = $user->getLogin();
2052  // permission_disinvite
2053  $new_user->pmdi = 0;
2054  //permission_invite
2055  $new_user->pmi = 0;
2056  }
2057  $out[] = $new_user;
2058  }
2059  //$out['hidden_count'] = $hidden_count;
2060  $result = new stdClass();
2061  $result->hidden_count = $hidden_count;
2062  $result->users = $out;
2063  return $result;
2064  }
2065 
2066  private function fetchActiveUsers() {
2067  global $rbacsystem, $ilCtrl, $ilUser;
2068  $this->__updateChatSessionAsync();
2069  $users = $this->object->chat_room->getActiveUsers();
2070 
2071  $user_obj = new ilObjUser();
2072 
2073  $out = array();
2074 
2075  foreach($users as $user) {
2076  if($user == $_SESSION["AccountId"]) {
2077  continue;
2078  }
2079 
2080  $new_user = new stdClass();
2081  $new_user->menu = array();
2082  $new_user->id = $user;
2083  $user_obj->setId($user);
2084  $user_obj->read();
2085 
2086  $new_user->login = $user_obj->getLogin();
2087 
2088  if (in_array($user_obj->getPref("public_profile"), array("y", "g"))) {
2089  //public_profile
2090  $new_user->pp = '1';
2091  $new_user->img = $user_obj->getPersonalPicturePath();
2092  //display_name
2093  $new_user->dn = $user_obj->getFirstname().' '.$user_obj->getLastname().' ('.$user_obj->getLogin().')';
2094  }
2095  else {
2096  //public_profile
2097  $new_user->pp = '0';
2098  $new_user->img = ilUtil::getImagePath("no_photo_xsmall.jpg");
2099  //display_name
2100  $new_user->dn = $user_obj->getLogin();
2101  }
2102 
2103  if($ilUser->getId() != ANONYMOUS_USER_ID && $user != ANONYMOUS_USER_ID) {
2104  $ilCtrl->clearParameters($this);
2105  if(in_array($user_obj->getPref("public_profile"), array("y", "g"))) {
2106 
2107  $ilCtrl->setParameter($this, "user", $user_obj->getId());
2108  $link = $ilCtrl->getLinkTarget($this, "showUserProfile");
2109  $ilCtrl->clearParameters($this);
2110  $new_user->profile = $link;
2111  }
2112 
2113  }
2114  if($rbacsystem->checkAccess('moderate',$this->object->getRefId()) and !$_REQUEST['room_id']) {
2115  $ilCtrl->setParameter($this, "kick_id", $user_obj->getId());
2116 
2117  if($this->object->chat_room->isKicked($user_obj->getId())) {
2118  //permission_kick
2119  $new_user->pmk = false;
2120  //permission_unkick
2121  $new_user->pmuk = true;
2122  }
2123  else {
2124  //permission_kick
2125  $new_user->pmk = true;
2126  //permission_unkick
2127  $new_user->pmuk = false;
2128  }
2129  $ilCtrl->clearParameters($this);
2130  }
2131  else
2132  {
2133  //permission_kick
2134  $new_user->pmk = false;
2135  }
2136  $out[] = $new_user;
2137  }
2138  return $out;
2139  }
2140 
2141  public function fetchRooms() {
2142  global $rbacsystem, $ilUser, $ilCtrl;
2143  include_once 'Modules/Chat/classes/class.ilChatBlockedUsers.php';
2144 
2145  $this->__updateChatSessionAsync();
2146 
2147  $public_rooms = $this->object->chat_room->getAllRooms();
2148  $private_rooms = $this->object->chat_room->getRooms();
2149 
2150  $this->object->__initChatRecording();
2151 
2152  $user_obj =& new ilObjUser();
2153 
2154  $current_room = false;
2155 
2156  $rooms = array();
2157 
2158  foreach($public_rooms as $room) {
2159  if ($room['child'] == $this->object->getRefId()) {
2160  $current_room = $room;
2161  continue;
2162  }
2163  $rooms[] = $room;
2164  $rooms[count($rooms)-1]['users'] = $this->object->chat_room->getCountActiveUser($room['obj_id'],0);
2165  }
2166 
2167  $private_rooms_by_parent_id = array();
2168 
2169  foreach($private_rooms as $room) {
2170 
2171  if (!is_array($private_rooms_by_parent_id[$room['chat_id']]))
2172  $private_rooms_by_parent_id[$room['chat_id']] = array();
2173 
2174  $private_rooms_by_parent_id[$room['chat_id']][] = $room;
2175  $private_rooms_by_parent_id[$room['chat_id']][count($private_rooms_by_parent_id[$room['chat_id']])-1]['users'] = $this->object->chat_room->getCountActiveUser($room['chat_id'],$room['room_id']);
2176 
2177  }
2178 
2179  $titel = array();
2180  $users = array();
2181 
2182  foreach($rooms as $k => $v) {
2183  $titel[$k] = strtolower($v['title']);
2184  $users[$k] = $v['users'];
2185  }
2186 
2187  array_multisort($users, SORT_DESC, $titel, SORT_STRING, $rooms);
2188 
2189  foreach($private_rooms_by_parent_id as $k => $v) {
2190  $titel = array();
2191  $users = array();
2192  foreach($v as $k1 => $v1) {
2193 
2194  $titel[$k1] = strtolower($v1['title']);
2195  $users[$k1] = $v1['users'];
2196  }
2197  array_multisort($users, SORT_DESC, $titel, SORT_STRING, $private_rooms_by_parent_id[$k]);
2198  }
2199 
2200  /*
2201  * show current user room
2202  */
2203 
2204  $croom = $this->__prepareRoomForAsyncOutput($current_room);
2205 
2206  if ($this->object->chat_room->getRoomId() == 0) {
2207  $croom->act = true;
2208  }
2209  else {
2210  $croom->act = false;
2211  }
2212 
2213 
2214  if (is_array($private_rooms_by_parent_id[$current_room['obj_id']])) {
2215  $croom->subrooms = array();
2216  $ref_id = $current_room["ref_id"];
2217  foreach($private_rooms_by_parent_id[$current_room['obj_id']] as $priv_room) {
2218  $tmp = $this->__preparePrivateRoomForAsyncOutput($priv_room, $ref_id);
2219  if (isset($_REQUEST["room_id"]) && $_REQUEST["room_id"] == $priv_room["room_id"]) {
2220  $tmp->act = true;
2221  }
2222  else {
2223  $tmp->act = false;
2224  }
2225  $croom->subrooms[] = $tmp;
2226  }
2227  }
2228 
2229  $out_rooms = array();
2230  foreach($rooms as $room) {
2231  if (ilChatBlockedUsers::_isBlocked($room['obj_id'], $ilUser->getId())) {
2232  continue;
2233  }
2234 
2235  $new_room = $this->__prepareRoomForAsyncOutput($room);
2236  $new_room->subrooms = array();
2237  if (is_array($private_rooms_by_parent_id[$room['obj_id']])) {
2238  foreach($private_rooms_by_parent_id[$room['obj_id']] as $priv_room) {
2239  $new_room->subrooms[] = $this->__preparePrivateRoomForAsyncOutput($priv_room, $room["ref_id"]);
2240  }
2241  }
2242  $out_rooms[] = $new_room;
2243  }
2244 
2245  $result = new stdClass();
2246  $result->currentRoom = $croom;
2247  $result->rooms = $out_rooms;
2248  return $result;
2249  }
2250 
2251  public function getOnlineUsersAsyncObject() {
2252  $out = $this->fetchOnlineUsers();
2253  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
2254  echo ilJsonUtil::encode($out);
2255  exit;
2256  }
2257 
2258  public function getActiveUsersAsyncObject()
2259  {
2260  $out = $this->fetchActiveUsers();
2261  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
2262  echo ilJsonUtil::encode($out);
2263  exit;
2264  }
2265 
2266  public function getCurrentRoomAsyncObject()
2267  {
2268  $result = $this->fetchRooms();
2269  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
2271  exit;
2272  }
2273 
2274  public function getUpdateAsyncObject() {
2275 
2276  global $ilCtrl, $rbacsystem, $ilObjDataCache, $lng, $ilUser;
2277  include_once 'Modules/Chat/classes/class.ilChatBlockedUsers.php';
2278  if (
2279  !$rbacsystem->checkAccess("read", $_REQUEST["ref_id"])
2280  || ilChatBlockedUsers::_isBlocked($ilObjDataCache->lookupObjId($_REQUEST["ref_id"]), $ilUser->getId())
2281  )
2282  {
2283  $res = new stdClass();
2284 
2285  $baseClass = 'ilchatpresentationgui';
2286  $res->forceRedirect = 'ilias.php?baseClass='.$baseClass.'&ref_id='.ilObjChat::_getPublicChatRefId();
2287 
2288  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
2289  $json = ilJsonUtil::encode($res);
2290  echo $json;
2291 
2292  exit;
2293  }
2294 
2295  $res = new stdClass();
2296 
2297  $res->rooms = $this->fetchRooms();
2298  $res->activeUsers = $this->fetchActiveUsers();
2299  $res->onlineUsers = $this->fetchOnlineUsers($res->activeUsers);
2300 
2301  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
2302  $json = ilJsonUtil::encode($res);
2303  echo $json;
2304  exit;
2305  }
2306 
2307  public function enterRoomAsyncObject() {
2308  global $rbacsystem, $ilCtrl;
2309  $result = new stdClass();
2310 
2311  if (!$rbacsystem->checkAccess("read", $this->ref_id)) {
2312  $result->errormsg = $this->lng->txt("msg_no_perm_read");
2313  }
2314  else {
2315  $ilCtrl->setParameter($this, "room_id", $_REQUEST["room_id"]);
2316  if ($_GET["p_id"]) {
2317  $ilCtrl->setParameter($this, "p_id", $_GET["p_id"]);
2318  }
2319  else if ($_GET["a_id"]) {
2320  $ilCtrl->setParameter($this, "pa_id", $_GET["a_id"]);
2321  $ilCtrl->setParameter($this, "a_id", $_GET["a_id"]);
2322  }
2323  $result->serverTarget = $this->object->server_comm->getServerFrameSource();
2324  $result->ok = true;
2325  }
2326 
2327  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
2329  exit;
2330  }
2331 
2332  public function emptyRoomAsyncObject() {
2333  global $rbacsystem;
2334  $result = new stdClass();
2335  if (
2336  $rbacsystem->checkAccess("moderate", $this->object->getRefId()) &&
2337  $this->object->chat_room->checkWriteAccess()
2338  ) {
2339 
2340  if ($rid = (int)$_REQUEST['room_id'])
2341  {
2342  $this->object->chat_room->setRoomId($rid);
2343  }
2344 
2345  $this->object->server_comm->setType('delete');
2346  $message = $this->__formatMessage();
2347  $this->object->server_comm->setMessage($message);
2348  $this->object->server_comm->send();
2349 
2350  $this->object->chat_room->deleteAllMessages();
2351 
2352  $result->ok = true;
2353  }
2354  else {
2355  $result->ok = false;
2356  }
2357 
2358 
2359  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
2361  exit;
2362  }
2363 
2364  public function kickUserAsyncObject()
2365  {
2366  global $rbacsystem;
2367  $result = new stdClass();
2368  if(!$rbacsystem->checkAccess('moderate',$this->object->getRefId())) {
2369  //$this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
2370  $result->errormsg = $this->lng->txt("msg_no_perm_write");
2371  }
2372 
2373  if($_REQUEST["kick_id"])
2374  {
2375  $tmp_user = new ilObjUser($_REQUEST['kick_id']);
2376 
2377  $this->object->server_comm->setKickedUser($tmp_user->getLogin());
2378  $this->object->server_comm->setType("kick");
2379  $this->object->server_comm->send();
2380 
2381  $this->object->chat_room->setKicked((int)$_REQUEST['kick_id']);
2382 
2383  $result->infomsg = $this->lng->txt("chat_user_dropped");
2384  $result->ok = true;
2385  }
2386  else {
2387  $result->ok = false;
2388  }
2389 
2390  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
2392  exit;
2393 
2394  }
2395 
2396  public function unkickUserAsyncObject()
2397  {
2398  global $rbacsystem;
2399  $result = new stdClass();
2400 
2401  if(!$rbacsystem->checkAccess('moderate',$this->object->getRefId()))
2402  {
2403  $result->errormsg = $this->lng->txt("msg_no_perm_write");
2404  }
2405 
2406  if($_REQUEST["kick_id"])
2407  {
2408  $this->object->chat_room->setUnkicked((int)$_REQUEST['kick_id']);
2409  $result->ok = true;
2410  $result->infomsg = $this->lng->txt("chat_user_unkicked");
2411  }
2412  else {
2413  $result->ok = false;
2414  }
2415 
2416  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
2418  exit;
2419  }
2420 
2421  public function addPrivateRoomAsyncObject()
2422  {
2423  global $rbacsystem;
2424 
2425  $result = new stdClass();
2426 
2427  if (!$rbacsystem->checkAccess("read", $this->ref_id)) {
2428  $result->errormsg = $this->lng->txt("msg_no_perm_read");
2429  $result->ok = false;
2430  }
2431  else
2432  {
2433  $room =& new ilChatRoom($this->object->getId());
2434  $room->setTitle(ilUtil::stripSlashes($_REQUEST["room_name"]));
2435  $room->setOwnerId($_SESSION["AccountId"]);
2436 
2437  if(!$room->validate())
2438  {
2439  $result->infomsg = $room->getErrorMessage();
2440  $result->ok = false;
2441  }
2442  else
2443  {
2444  $result->room_id = $room->add();
2445  $result->infomsg = $this->lng->txt("chat_room_added");
2446  $result->ref_id = $this->ref_id;
2447  $result->ok = true;
2448 
2449  }
2450  }
2451 
2452  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
2454  exit;
2455  }
2456 
2457  public function inviteAsyncObject()
2458  {
2459  $result = new stdClass();
2460  if($_GET["i_id"]) {
2461  $this->object->chat_room->invite((int) $_GET["i_id"]);
2462  $this->object->sendMessage((int) $_GET["i_id"]);
2463  if((int)$this->object->chat_room->getRoomId()) {
2464  $result->infomsg = sprintf($this->lng->txt("chat_user_invited_private"), $this->object->chat_room->getTitle());
2465  }
2466  else {
2467  $result->infomsg = sprintf($this->lng->txt("chat_user_invited_public"), $this->object->getTitle());
2468  }
2469  $result->ok = true;
2470  }
2471  else {
2472  $result->ok = false;
2473  $result->errormsg = "user id not found";
2474  }
2475 
2476  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
2478  exit;
2479  }
2480 
2481  public function dropAsyncObject()
2482  {
2483  $result = new stdClass();
2484  if($_GET["i_id"])
2485  {
2486  $this->object->chat_room->drop((int) $_GET["i_id"]);
2487 
2488  $tmp_user =& new ilObjUser($_GET["i_id"]);
2489  $this->object->server_comm->setKickedUser($tmp_user->getLogin());
2490  $this->object->server_comm->setType("kick");
2491  $this->object->server_comm->send();
2492  //ilUtil::sendInfo($this->lng->txt("chat_user_dropped_private"),true);
2493  $result->infomsg = $this->lng->txt("chat_user_dropped_private");
2494  //$this->showFramesObject();
2495  $result->ok = true;
2496  }
2497  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
2499  exit;
2500  }
2501 
2502  public function deleteRoomAsyncObject()
2503  {
2504  global $rbacsystem;
2505 
2506  $result = new stdClass();
2507 
2508  if (!$rbacsystem->checkAccess("read", $this->ref_id)) {
2509  $result->errormsg = $this->lng->txt("msg_no_perm_read");
2510  }
2511 
2512  if(!$_GET["room_id_delete"]) {
2513  $result->errormsg = $this->lng->txt("chat_select_one_room");
2514  }
2515  if (!$result->errormsg) {
2516  $this->object->chat_room->setOwnerId($_SESSION["AccountId"]);
2517  $rooms = array($_GET["room_id_delete"]);
2518 
2519  if (!$rbacsystem->checkAccess("write", $this->ref_id)) {
2520  $delResult = $this->object->chat_room->deleteRooms($rooms, $this->object->chat_room->getOwnerId());
2521  }
2522  else {
2523  $delResult = $this->object->chat_room->deleteRooms($rooms);
2524  }
2525 
2526  if(!$delResult) {
2527  //$this->ilias->raiseError($this->object->chat_room->getErrorMessage(),$this->ilias->error_obj->MESSAGE);
2528  $result->errormsg = $this->object->chat_room->getErrorMessage();
2529  }
2530 
2531  $result->infomsg = $this->lng->txt("chat_rooms_deleted");
2532  }
2533  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
2534  echo ilJsonUtil::encode($result);
2535  exit;
2536  }
2537 
2538  public function inputAsyncObject()
2539  {
2540  $result = new stdClass();
2541  $this->object->chat_room->setUserId($_SESSION["AccountId"]);
2542  $this->object->chat_room->updateLastVisit();
2543 
2544  if(!$_REQUEST["message"])
2545  {
2546  $result->errormsg = $this->lng->txt("chat_insert_message");
2547  }
2548 
2549  if($_REQUEST["message"] and $this->object->chat_room->checkWriteAccess())
2550  {
2551  $id = false;
2552  // FORMAT MESSAGE
2553  $message = $this->__formatMessage();
2554 
2555  // SET MESSAGE AND SEND IT
2556  $this->object->server_comm->setMessage($message);
2557  if((int) $_GET["p_id"])
2558  {
2559  $this->object->server_comm->setType('private');
2560  }
2561  else if((int) $_GET["a_id"])
2562  {
2563  $this->object->server_comm->setType('address');
2564  }
2565 
2566  if(!$this->object->server_comm->send($id))
2567  {
2568  $result->errormsg = $this->lng->txt("chat_no_connection");
2569  }
2570  else {
2571  $result->ok = true;
2572  }
2573 
2574  $_SESSION["il_notify_last_msg_checksum"] = $id;
2575  }
2576  else
2577  {
2578  $result->errormsg = $this->lng->txt('chat_kicked_from_room');
2579  }
2580  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
2582  exit;
2583 
2584  //$this->showInputFrameObject();
2585  }
2586 
2587  public function startRecordingAsyncObject()
2588  {
2589  global $rbacsystem,$ilUser;
2590  $result = new stdClass();
2591 
2592  if (!$rbacsystem->checkAccess("moderate", $this->object->getRefId()))
2593  {
2594  $result->errormsg = $this->lng->txt("msg_no_perm_read");
2595  $result->ok = false;
2596  }
2597  else {
2598  $this->object->__initChatRecording();
2599  if($_GET["room_id"])
2600  {
2601  $this->object->chat_recording->setRoomId($_GET["room_id"]);
2602  }
2603 
2604  if (!$this->object->chat_recording->isRecording())
2605  {
2606  $this->object->chat_recording->setModeratorId($ilUser->getId());
2607  $this->object->chat_recording->startRecording($_REQUEST["title"]);
2608  $result->ok = true;
2609  $result->infomsg = $this->lng->txt("chat_recording_started");
2610  }
2611  else {
2612  $result->ok = false;
2613  $result->errormsg = $this->lng->txt("chat_recording_already_running");
2614  }
2615  }
2616  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
2618  exit;
2619  }
2620 
2621 
2622  public function stopRecordingAsyncObject()
2623  {
2624  global $rbacsystem,$ilUser;
2625  $result = new stdClass();
2626  if (!$rbacsystem->checkAccess("moderate", $this->object->getRefId()))
2627  {
2628  $result->errormsg = $this->lng->txt("msg_no_perm_read");
2629  $result->ok = false;
2630  }
2631  else {
2632  $this->object->__initChatRecording();
2633  if($_GET["room_id"]) {
2634  $this->object->chat_recording->setRoomId($_GET["room_id"]);
2635  }
2636  if ($this->object->chat_recording->isRecording()) {
2637  $this->object->chat_recording->stopRecording($ilUser->getId());
2638  }
2639  $result->infomsg = $this->lng->txt("chat_recording_stopped");
2640  $result->ok = true;
2641  }
2642  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
2644  exit;
2645  }
2646 
2647  private function addRoomToBookmarkAsyncObject()
2648  {
2649  global $ilObjDataCache, $lng;
2650  $result = new stdClass();
2651  include_once 'Services/PersonalDesktop/classes/class.ilBookmark.php';
2652 
2653  $targetclass = 'ilchatpresentationgui';
2654  $ref_id = $_REQUEST["ref_id"];
2655  $room_id = $_REQUEST["room_id"];
2656 
2657  $result->obj_id = $this->object->getId();
2658  $result->ref_id = $ref_id;
2659 
2660  $bookmark = new ilBookmark();
2661 
2662  // for main chats
2663  if ($room_id == 0)
2664  {
2665  $obj_id = $ilObjDataCache->lookupObjId($ref_id);
2666 
2667  $bookmark->setTitle(vsprintf($lng->txt('chat_default_bookmark_title'), $ilObjDataCache->lookupTitle($obj_id)));
2668  $bookmark->setDescription(vsprintf($lng->txt('chat_default_bookmark_description'), $ilObjDataCache->lookupTitle($obj_id)));
2669  $bookmark->setParent(1);
2670  $bookmark->setTarget("ilias.php?baseClass=$targetclass&ref_id=$ref_id&room_id=0");
2671  $result->msg = vsprintf($lng->txt('chat_added_to_bookmarks'), $ilObjDataCache->lookupTitle($obj_id));
2672  }
2673  // for private rooms
2674  else
2675  {
2676  $obj_id = $ilObjDataCache->lookupObjId($ref_id);
2677  $chat_title = $ilObjDataCache->lookupTitle($obj_id);
2678  $room =& new ilChatRoom($ref_id);
2679  $room->setRoomId($room_id);
2680  $bookmark->setTitle(vsprintf($lng->txt('chat_default_bookmark_title'), $room->getTitle() . ' - ' . $chat_title ));
2681  $bookmark->setDescription(vsprintf($lng->txt('chat_default_bookmark_description'), $room->getTitle()));
2682  $bookmark->setParent(1);
2683  $bookmark->setTarget("ilias.php?baseClass=$targetclass&ref_id=$ref_id&room_id=$room_id");
2684  $result->msg = vsprintf($lng->txt('chat_added_to_bookmarks'), $chat_title . ' - ' . $room->getTitle());
2685  }
2686 
2687  $bookmark->create();
2688 
2689  $result->ok = true;
2690 // $result->msg = "link has been created";
2691  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
2692  echo @ilJsonUtil::encode($result);
2693  exit;
2694  }
2695 
2697  {
2698  global $lng, $ilUser;
2699  $result = new stdClass();
2700  include_once 'Services/Contact/classes/class.ilAddressbook.php';
2701  $addressbook = new ilAddressbook($ilUser->getId());
2702  if ($addressbook->checkEntryByLogin($_REQUEST["ulogin"]))
2703  {
2704  $result->ok = false;
2705  $result->msg = $lng->txt('chat_user_already_in_addressbook');
2706  }
2707  else
2708  {
2709  $login = $_REQUEST["ulogin"];
2710  $id = ilObjUser::getUserIdByLogin($login);
2711 
2712  $oUser = new ilObjUser();
2713  $oUser->setId($id);
2714  $oUser->read();
2715 
2716  $firstname = "";
2717  $lastname = "";
2718 
2719  if ($oUser->hasPublicProfile())
2720  {
2721  $firstname = $oUser->getFirstname();
2722  $lastname = $oUser->getLastname();
2723  }
2724  $result->msg = vsprintf($lng->txt('chat_added_to_addressbook'), $login);
2725  $email = ($oUser->getPref('public_email') == 'y' ? $oUser->getEmail() : '') ;
2726  $addressbook->addEntry($login, $firstname, $lastname, $email);
2727  $result->ok = true;
2728  }
2729  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
2731  exit;
2732  }
2733 
2734  private function __prepareRoomForAsyncOutput($room) {
2735  global $rbacsystem, $ilUser, $ilCtrl;
2736  include_once 'Modules/Chat/classes/class.ilChatBlockedUsers.php';
2737 
2738  $new_room = new stdClass();
2739  $new_room->title = $room["title"];
2740  $new_room->users_online = $this->object->chat_room->getCountActiveUser($room["obj_id"],0);
2741  $new_room->obj_id = $room["obj_id"];
2742  $new_room->room_id = 0;
2743  $new_room->ref_id = $room["child"];
2744 
2745  //permission_enter
2746  $new_room->pme = true;
2747  //permission_bookmark
2748  $new_room->pmbo = true;
2749 
2750  $ilCtrl->setParameter($this, "ref_id", $room["child"]);
2751  $link = $ilCtrl->getLinkTarget($this, "showFrames");
2752  $this->tpl->setVariable("ROOM_LINK", $link);
2753  $ilCtrl->setParameter($this, "ref_id", $_GET["ref_id"]);
2754 
2755  $link = "il_chat_async_handler.enterRoom('".$room['child']."',false);";
2756 
2757  $this->object->chat_recording->setObjId($room["obj_id"]);
2758 
2759  if ($room["child"] == $this->object->getRefId() &&
2760  $this->object->chat_room->getRoomId() == 0 &&
2761  $rbacsystem->checkAccess("moderate", $this->object->getRefId()))
2762  {
2763  $link = "il_chat_async_handler.emptyRoom();";
2764  // permission_empty
2765  $new_room->pmem = true;
2766  }
2767  else
2768  {
2769  // permission_empty
2770  $new_room->pmem = false;
2771  }
2772 
2773  $this->object->chat_recording->setObjId($room["obj_id"]);
2774  $this->object->chat_recording->setRoomId(0);
2775 
2776  if ($this->object->chat_recording->isRecording()) {
2777  $new_room->recording = true;
2778  }
2779  else {
2780  $new_room->recording = false;
2781  }
2782 
2783 
2784  return $new_room;
2785  }
2786 
2787  private function __preparePrivateRoomForAsyncOutput($room, $ref_id) {
2788  global $rbacsystem, $ilUser, $ilCtrl;
2789  include_once 'Modules/Chat/classes/class.ilChatBlockedUsers.php';
2790  $new_room = new stdClass();
2791 
2792  $new_room->title = $room["title"];
2793  $new_room->users_online = $this->object->chat_room->getCountActiveUser($room["chat_id"],$room["room_id"]);
2794 
2795  $new_room->obj_id = $room["chat_id"];
2796  $new_room->room_id = $room["room_id"];
2797  $new_room->ref_id = $ref_id;
2798 
2799  //permission_enter
2800  $new_room->pme = true;
2801  //permission_bookmark
2802  $new_room->pmbo = true;
2803 
2804  $ilCtrl->setParameter($this, "ref_id", $ref_id);
2805  $ilCtrl->setParameter($this, "room_id", $room["room_id"]);
2806  $link = $ilCtrl->getLinkTarget($this, "showFrames");
2807 
2808  $link = "il_chat_async_handler.enterRoom('$ref_id','".$room["room_id"]."');";
2809 
2810  if ($room["owner"] != $_SESSION["AccountId"] && !$rbacsystem->checkAccess('moderate', $this->object->getRefId())) {
2811  if($user_obj =& ilObjectFactory::getInstanceByObjId($priv_room['owner'],false)) {
2812  $new_room->chat_initiated = $user_obj->getLogin();
2813  }
2814  //permission_delete
2815  $new_room->pmde = false;
2816  }
2817  else {
2818  /*
2819  * build context menu
2820  */
2821  $ilCtrl->setParameter($this, "room_id", $this->object->chat_room->getRoomId());
2822  $ilCtrl->setParameter($this, "room_id_delete", $room["room_id"]);
2823  $link = $ilCtrl->getLinkTarget($this, "deleteRoom");
2824  $ilCtrl->clearParameters($this);
2825  //permission_delete
2826  $new_room->pmde = true;
2827 
2828  $link = "il_chat_async_handler.deletePrivateRoom('".$room['room_id']."');";
2829  }
2830 
2831  $this->object->chat_recording->setObjId($room["chat_id"]);
2832  $this->object->chat_recording->setRoomId($room["room_id"]);
2833 
2834  if ($this->object->chat_recording->isRecording()) {
2835  $new_room->recording = true;
2836  }
2837  else {
2838  $new_room->recording = false;
2839  }
2840 
2841  $new_room->own_room_id = $room["room_id"];
2842  //permission_moderate
2843  $new_room->mod = $rbacsystem->checkAccess("moderate", $this->object->getRefId());
2844 
2845  if (
2846  $room["room_id"] == $this->object->chat_room->getRoomId() &&
2847  $rbacsystem->checkAccess("moderate", $this->object->getRefId())
2848  )
2849  {
2850  $link = "il_chat_async_handler.emptyRoom();";
2851  $ilCtrl->clearParameters($this);
2852  //permission_empty
2853  $new_room->pmem = true;
2854  }
2855  else
2856  {
2857  //permission_empty
2858  $new_room->pmem = false;
2859  }
2860  return $new_room;
2861  }
2862 }
2863 // END class.ilObjChatGUI
2864 
2865 ?>