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