/**
  * @param int $invited_id
  */
 private function inviteById($invited_id)
 {
     /**
      * @var $ilUser ilObjUser
      * @var $ilCtrl ilCtrl
      */
     global $ilUser, $ilCtrl;
     if (!ilChatroom::checkUserPermissions('read', $this->gui->ref_id)) {
         $ilCtrl->setParameterByClass('ilrepositorygui', 'ref_id', ROOT_FOLDER_ID);
         $ilCtrl->redirectByClass('ilrepositorygui', '');
     }
     $room = ilChatroom::byObjectId($this->gui->object->getId());
     $chat_user = new ilChatroomUser($ilUser, $room);
     $user_id = $chat_user->getUserId();
     if (!$room) {
         $response = json_encode(array('success' => false, 'reason' => 'unkown room'));
         echo json_encode($response);
         exit;
     } else {
         if ($_REQUEST['sub'] && !$room->isOwnerOfPrivateRoom($user_id, $_REQUEST['sub'])) {
             $response = json_encode(array('success' => false, 'reason' => 'not owner of private room'));
             echo json_encode($response);
             exit;
         }
     }
     $connector = $this->gui->getConnector();
     $result = $connector->inviteToPrivateRoom($room, $_REQUEST['sub'], $ilUser, $invited_id);
     $room->sendInvitationNotification($this->gui, $chat_user, $invited_id, (int) $_REQUEST['sub']);
     echo json_encode($result);
     exit;
 }
 /**
  * Saves file, fetched from $_FILES to specified upload path.
  *
  * @global ilObjUser $ilUser
  */
 public function uploadFile()
 {
     global $ilCtrl;
     if (!ilChatroom::checkUserPermissions('read', $this->gui->ref_id)) {
         $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID);
         $ilCtrl->redirectByClass("ilrepositorygui", "");
     }
     $upload_path = $this->getUploadPath();
     $this->checkUploadPath($upload_path);
     /**
      * @todo: filename must be unique.
      */
     $file = $_FILES['file_to_upload']['tmp_name'];
     $filename = $_FILES['file_to_upload']['name'];
     $type = $_FILES['file_to_upload']['type'];
     $target = $upload_path . $filename;
     if (ilUtil::moveUploadedFile($file, $filename, $target)) {
         global $ilUser;
         require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
         require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
         $room = ilChatroom::byObjectId($this->gui->object->getId());
         $chat_user = new ilChatroomUser($ilUser, $room);
         $user_id = $chat_user->getUserId();
         if (!$room) {
             throw new Exception('unkown room');
         } else {
             if (!$room->isSubscribed($chat_user->getUserId())) {
                 throw new Exception('not subscribed');
             }
         }
         $room->saveFileUploadToDb($user_id, $filename, $type);
         $this->displayLinkToUploadedFile($room, $chat_user);
     }
 }
 public function executeDefault($method)
 {
     global $tpl, $ilUser, $ilCtrl, $lng, $ilAccess;
     $room = ilChatroom::byObjectId($this->gui->object->getId());
     $chat_user = new ilChatroomUser($ilUser, $room);
     $result = new stdClass();
     $result->users = $room->getConnectedUsers();
     $result->private_rooms = $room->getActivePrivateRooms($ilUser->getId());
     $result->userinfo = array('moderator' => $ilAccess->checkAccess('moderate', '', $_GET['ref_id']), 'userid' => $chat_user->getUserId());
     $smileys = array();
     include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
     $smileys_array = ilChatroomSmilies::_getSmilies();
     foreach ($smileys_array as $smiley_array) {
         foreach ($smiley_array as $key => $value) {
             if ($key == 'smiley_keywords') {
                 $new_keys = explode("\n", $value);
             }
             if ($key == 'smiley_fullpath') {
                 $new_val = $value;
             }
         }
         foreach ($new_keys as $new_key) {
             $smileys[$new_key] = $new_val;
         }
     }
     $result->smileys = $smileys;
     echo json_encode($result);
     exit;
 }
 /**
  * Displays window box to kick a user fetched from $_REQUEST['user'].
  *
  * @global ilObjUser $ilUser
  * @param string $method
  */
 public function executeDefault($method)
 {
     global $ilUser, $ilCtrl;
     require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
     require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
     if (!ilChatroom::checkUserPermissions(array('moderate'), $this->gui->ref_id)) {
         $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID);
         $ilCtrl->redirectByClass("ilrepositorygui", "");
     }
     $room = ilChatroom::byObjectId($this->gui->object->getId());
     if ($room) {
         // if user is in scope
         $scope = $room->getRoomId();
         $chat_user = new ilChatroomUser($ilUser, $room);
         $message = json_encode($this->buildMessage(ilUtil::stripSlashes((int) $_REQUEST['sub']), $chat_user));
         $params = array('message' => $message);
         $query = http_build_query($params);
         $connector = $this->gui->getConnector();
         $response = $connector->post($scope, $query);
         $responseObject = json_decode($response);
         $room->clearMessages($_REQUEST['sub']);
     } else {
         $response = json_encode(array('success' => false, 'reason' => 'unkown room'));
     }
     echo $response;
     exit;
 }
 /**
  * @return array
  */
 private function getReadableAreas()
 {
     /**
      * @var $ilUser     ilObjUser
      * @var $rbacsystem ilRbacSystem
      */
     global $ilUser, $rbacsystem;
     $readable_rooms = array();
     $chatroom_objects = ilChatroom::getUntrashedChatReferences();
     foreach ($chatroom_objects as $object) {
         if (isset($readable_rooms[$object['obj_id']])) {
             continue;
         }
         if ($rbacsystem->checkAccess('read', '', $object['ref_id'])) {
             $room = ilChatroom::byObjectId($object['obj_id']);
             if ($room && !$room->isUserBanned($ilUser->getId())) {
                 $readable_rooms[$object['obj_id']] = array('ref_id' => $object['ref_id'], 'obj_id' => $object['obj_id'], 'room_id' => $room->getRoomId(), 'title' => $object['title']);
             }
         }
     }
     $title = array();
     foreach ($readable_rooms as $k => $v) {
         $title[$k] = strtolower($v['title']);
     }
     array_multisort($title, SORT_STRING, $readable_rooms);
     return $readable_rooms;
 }
 /**
  * Prepares and posts message fetched from $_REQUEST['message']
  * to recipients fetched from $_REQUEST['recipient']
  * and adds an entry to history if successful.
  *
  * @global ilObjUser $ilUser
  * @param string $method
  */
 public function executeDefault($method)
 {
     global $ilUser, $ilCtrl;
     require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
     require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
     if (!ilChatroom::checkUserPermissions('read', $this->gui->ref_id)) {
         $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID);
         $ilCtrl->redirectByClass("ilrepositorygui", "");
     }
     $room = ilChatroom::byObjectId($this->gui->object->getId());
     $chat_user = new ilChatroomUser($ilUser, $room);
     $user_id = $chat_user->getUserId();
     if (!$room) {
         throw new Exception('unkown room');
     } else {
         if (!$room->isSubscribed($chat_user->getUserId())) {
             throw new Exception('not subscribed');
         } else {
             if (isset($_REQUEST['sub']) && !$room->userIsInPrivateRoom($_REQUEST['sub'], $chat_user->getUserId())) {
                 $response = json_encode(array('success' => false, 'reason' => 'not subscribed to private room'));
                 echo json_encode($response);
                 exit;
             }
         }
     }
     $scope = $room->getRoomId();
     $params = array();
     if ($recipient = $_REQUEST['recipient']) {
         $params['recipients'] = join(',', array_unique(array($user_id, $recipient)));
         $params['recipient_names'] = implode(',', array($chat_user->getUsername(), $_REQUEST['recipient_name']));
         $params['public'] = isset($_REQUEST['public']) ? (int) $_REQUEST['public'] : 0;
     } else {
         $params['public'] = 1;
     }
     if ($_REQUEST['sub']) {
         $params['sub'] = (int) $_REQUEST['sub'];
     }
     $messageObject = $this->buildMessage(ilUtil::stripSlashes($_REQUEST['message']), $params, $chat_user);
     $message = json_encode($messageObject);
     $params = array_merge($params, array('message' => $message));
     //print_r($params);exit;
     $query = http_build_query($params);
     $connector = $this->gui->getConnector();
     $response = $connector->post($scope, $query);
     $responseObject = json_decode($response);
     if ($responseObject->success == true) {
         $room->addHistoryEntry($messageObject, $recipient, $publicMessage);
     }
     echo $response;
     exit;
 }
 public function cleanupPrivateRooms()
 {
     $deletableRooms = ilChatroom::findDeletablePrivateRooms();
     $connector = $this->getConnector();
     foreach ($deletableRooms as $deletableRoom) {
         $room = ilChatroom::byObjectId($deletableRoom['object_id']);
         $params['user'] = -1;
         //$chat_user->getUserId();
         $room->closePrivateRoom($deletableRoom['proom_id'], $chat_user, $settings);
         $query = http_build_query($params);
         $message = json_encode(array('type' => 'private_room_deleted', 'timestamp' => date('c'), 'public' => 1, 'id' => $deletableRoom['proom_id'], 'proom_id' => $deletableRoom['proom_id'], 'message' => array('message' => 'room deleted', 'public' => '1', 'user' => 'system')));
         $result = $connector->sendMessage($room->getRoomId(), $message, array('public' => 1));
     }
 }
예제 #8
0
 public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
 {
     global $rbacreview;
     require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
     $original_room = ilChatroom::byObjectId($this->getId());
     $newObj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
     $objId = $newObj->getId();
     $original_settings = $original_room->getSettings();
     $room = new ilChatroom();
     $original_settings['object_id'] = $objId;
     $room->saveSettings($original_settings);
     // rbac log
     include_once "Services/AccessControl/classes/class.ilRbacLog.php";
     $rbac_log_roles = $rbacreview->getParentRoleIds($newObj->getRefId(), false);
     $rbac_log = ilRbacLog::gatherFaPa($newObj->getRefId(), array_keys($rbac_log_roles), true);
     ilRbacLog::add(ilRbacLog::CREATE_OBJECT, $newObj->getRefId(), $rbac_log);
     return $newObj;
 }
 /**
  * Get item properties
  *
  * @return	array		array of property arrays:
  * 						"alert" (boolean) => display as an alert property (usually in red)
  * 						"property" (string) => property name
  * 						"value" (string) => property value
  */
 public function getProperties()
 {
     /**
      * @var $lng ilLanguage
      */
     global $lng;
     $props = array();
     require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
     $room = ilChatroom::byObjectId($this->obj_id);
     if ($room) {
         $props[] = array("alert" => false, "property" => $lng->txt("chat_users_active"), "value" => $room->countActiveUsers());
         if ($this->obj_id == self::$publicRoomObjId) {
             $props[] = array("alert" => false, "property" => $lng->txt("notice"), 'value' => $lng->txt('public_room'));
         }
         if (self::$chat_enabled === null) {
             $chatSetting = new ilSetting('chatroom');
             self::$chat_enabled = (bool) $chatSetting->get('chat_enabled');
         }
         if (!self::$chat_enabled) {
             $props[] = array("alert" => true, "property" => $lng->txt("status"), 'value' => $lng->txt("server_disabled"));
         }
     }
     return $props;
 }
 /**
  * Prepares and displays history period form by session.
  *
  * @global ilLanguage $lng
  * @global ilCtrl2 $ilCtrl
  * @global ilObjUser $ilUser
  */
 public function bySession($export = false)
 {
     global $lng, $ilCtrl, $ilUser;
     $room = ilChatroom::byObjectId($this->gui->object->getId());
     $scope = $room->getRoomId();
     $chat_user = new ilChatroomUser($ilUser, $room);
     $formFactory = new ilChatroomFormFactory();
     $durationForm = $formFactory->getSessionForm($room->getSessions($chat_user));
     $durationForm->setTitle($lng->txt('history_bysession_title'));
     $durationForm->addCommandButton('history-bySessionExport', $lng->txt('export'));
     $durationForm->addCommandButton('history-bySession', $lng->txt('show'));
     $durationForm->setFormAction($ilCtrl->getFormAction($this->gui), 'history-bySession');
     if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
         $durationForm->checkInput();
         $postVals = explode(',', $_POST['session']);
         $durationForm->setValuesByArray(array('session' => $_POST['session']));
         $messages = $room->getHistory($from = new ilDateTime($postVals[0], IL_CAL_UNIX), $to = new ilDateTime($postVals[1], IL_CAL_UNIX), $chat_user->getUserId(), isset($_REQUEST['scope']) ? $_REQUEST['scope'] : 0);
     } else {
         $last_session = $room->getLastSession($chat_user);
         if ($last_session) {
             $from = new ilDateTime($last_session['connected'], IL_CAL_UNIX);
             $to = new ilDateTime($last_session['disconnected'], IL_CAL_UNIX);
         } else {
             $from = null;
             $to = null;
         }
         $messages = $room->getHistory($from, $to, $chat_user->getUserId(), isset($_REQUEST['scope']) ? $_REQUEST['scope'] : 0);
     }
     if ($from && $to) {
         $psessions = $room->getPrivateRoomSessions($from, $to, $chat_user->getUserId(), $scope);
     } else {
         $from = new ilDateTime();
         $to = new ilDateTime();
         $psessions = array();
     }
     $psessions = $room->getPrivateRoomSessions($from, $to, $chat_user->getUserId(), $scope);
     $this->showMessages($messages, $durationForm, $export, $psessions, $from, $to);
 }
예제 #11
0
 /**
  * Kicks user from subroom into mainroom
  * 
  * @global ilObjUser $ilUser 
  */
 public function sub()
 {
     global $ilUser, $ilCtrl;
     require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
     require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php';
     $room = ilChatroom::byObjectId($this->gui->object->getId());
     if ($room) {
         if (!$room->isOwnerOfPrivateRoom($ilUser->getId(), $_REQUEST['sub'])) {
             if (!ilChatroom::checkPermissionsOfUser($ilUser->getId(), array('read', 'moderate'), $this->gui->ref_id)) {
                 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID);
                 $ilCtrl->redirectByClass("ilrepositorygui", "");
             }
         }
         $scope = $room->getRoomId();
         $params = array();
         $params['user'] = $_REQUEST['user'];
         $params['sub'] = $_REQUEST['sub'];
         if ($room->userIsInPrivateRoom($params['sub'], $params['user'])) {
             $query = http_build_query($params);
             $connector = $this->gui->getConnector();
             $response = $connector->leavePrivateRoom($scope, $query);
             $responseObject = json_decode($response);
             /*
             			if( $responseObject->success == true && $room->getSetting( 'enable_history' ) )
             			{
             			//$room->addHistoryEntry( $message, $recipient, $publicMessage );
             			}
             */
             $room->unsubscribeUserFromPrivateRoom($params['sub'], $params['user']);
             $this->recantInvitation($params['sub'], $params['user']);
             $message = json_encode(array('type' => 'userjustkicked', 'user' => $params['user'], 'sub' => $params['sub']));
             $connector->sendMessage($room->getRoomId(), $message, array('public' => 1, 'sub' => 0));
         } else {
             $response = json_encode(array('success' => true, 'message' => 'was not in room'));
         }
         echo $response;
         exit;
     }
 }
 public function listUsers()
 {
     global $ilUser;
     $room = ilChatroom::byObjectId($this->gui->object->getId());
     echo json_encode($room->listUsersInPrivateRoom($_REQUEST['sub']));
     exit;
 }
 /**
  */
 protected function getMessages()
 {
     /**
      * @var $ilAccess ilAccessHandler
      * @var $ilUser   ilObjUser
      * @var $lng	  ilLanguage
      */
     global $ilAccess, $ilUser, $lng;
     $result = new stdClass();
     $result->ok = false;
     if (!(int) $_REQUEST['ref_id']) {
         echo ilJsonUtil::encode($result);
         exit;
     }
     /**
      * @var $object ilObjChatroom
      */
     $object = ilObjectFactory::getInstanceByRefId((int) $_REQUEST['ref_id'], false);
     if (!$object || !$ilAccess->checkAccess('read', '', $_REQUEST['ref_id'])) {
         ilObjUser::_writePref($ilUser->getId(), 'chatviewer_last_selected_room', 0);
         $result->errormsg = $lng->txt('msg_no_perm_read');
         echo ilJsonUtil::encode($result);
         exit;
     }
     require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
     $room = ilChatroom::byObjectId($object->getId());
     $block = new ilChatroomBlock();
     $msg = $block->getMessages($room);
     $ilUser->setPref('chatviewer_last_selected_room', $object->getRefId());
     ilObjUser::_writePref($ilUser->getId(), 'chatviewer_last_selected_room', $object->getRefId());
     $result->messages = array_reverse($msg);
     $result->ok = true;
     include_once 'Services/JSON/classes/class.ilJsonUtil.php';
     echo ilJsonUtil::encode($result);
     exit;
 }
 /**
  * Builds $config and $commandparts arrays to assign them as parameters
  * when calling $this->buildTabs and $this->activateTab.
  * @param string $command
  */
 public function getTabsForCommand($command)
 {
     /**
      * @var $ilTabs ilTabsGUI
      * @var $ilCtrl ilCtrl
      */
     global $ilTabs, $ilCtrl;
     $command = $this->convertLowerCamelCaseToUnderscoreCaseConversion($command);
     $stopCommands = array('create');
     if (in_array($command, $stopCommands)) {
         return;
     }
     require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
     $room = ilChatroom::byObjectId($this->gui->object->getId());
     $config = array('view' => array('lng' => 'view', 'link' => $ilCtrl->getLinkTarget($this->gui, 'view'), 'permission' => 'read'), 'history' => array('lng' => 'history', 'link' => $ilCtrl->getLinkTarget($this->gui, 'history-byday'), 'permission' => 'read', 'enabled' => $room ? $room->getSetting('enable_history') : false, 'subtabs' => array('byday' => array('lng' => 'history_by_day', 'link' => $ilCtrl->getLinkTarget($this->gui, 'history-byday'), 'permission' => 'read'), 'bysession' => array('lng' => 'history_by_session', 'link' => $ilCtrl->getLinkTarget($this->gui, 'history-bysession'), 'permission' => 'read'))), 'info' => array('lng' => 'info_short', 'link' => $ilCtrl->getLinkTargetByClass(array(get_class($this->gui), 'ilinfoscreengui'), 'info'), 'permission' => 'read'), 'settings' => array('lng' => 'settings', 'link' => $ilCtrl->getLinkTarget($this->gui, 'settings-general'), 'permission' => 'write', 'subtabs' => array('general' => array('lng' => 'settings_general', 'link' => $ilCtrl->getLinkTarget($this->gui, 'settings-general'), 'permission' => 'write'))), 'ban' => array('lng' => 'bans', 'link' => $ilCtrl->getLinkTarget($this->gui, 'ban-show'), 'permission' => 'moderate', 'subtabs' => array('show' => array('lng' => 'bans_table', 'link' => $ilCtrl->getLinkTarget($this->gui, 'ban-show'), 'permission' => 'moderate'))), 'perm' => array('lng' => 'permissions', 'link' => $ilCtrl->getLinkTargetByClass('ilpermissiongui', 'perm'), 'permission' => 'write'));
     $commandParts = explode('_', $command, 2);
     if ($ilCtrl->getCmdClass() == 'ilpermissiongui') {
         $commandParts[0] = 'perm';
     }
     $this->buildTabs($ilTabs, $config, $commandParts);
     $this->activateTab($commandParts, $config);
 }
예제 #15
0
 /**
  *
  */
 public function invitePD()
 {
     /**
      * @var $ilUser ilObjUser
      * @var $ilCtrl ilCtrl
      */
     global $ilUser, $ilCtrl;
     $chatSettings = new ilSetting('chatroom');
     if (!$chatSettings->get('chat_enabled')) {
         $ilCtrl->redirect($this->gui, 'settings-general');
     }
     $room = ilChatroom::byObjectId($this->gui->object->getId());
     $chat_user = new ilChatroomUser($ilUser, $room);
     $user_id = $_REQUEST['usr_id'];
     $connector = $this->gui->getConnector();
     $title = $room->getUniquePrivateRoomTitle($chat_user->getUsername());
     $response = $connector->createPrivateRoom($room, $title, $chat_user);
     $connector->inviteToPrivateRoom($room, $response->id, $ilUser, $user_id);
     $room->sendInvitationNotification($this->gui, $chat_user, $user_id, $response->id);
     $_REQUEST['sub'] = $response->id;
     $_SESSION['show_invitation_message'] = $user_id;
     $ilCtrl->setParameter($this->gui, 'sub', $response->id);
     $ilCtrl->redirect($this->gui, 'view');
 }
 /**
  * Kicks and bans user, fetched from $_REQUEST['user'] and adds history entry.
  *
  * @global ilObjUser $ilUser
  */
 public function active()
 {
     global $ilUser, $ilCtrl;
     if (!ilChatroom::checkUserPermissions(array('read', 'moderate'), $this->gui->ref_id)) {
         $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID);
         $ilCtrl->redirectByClass("ilrepositorygui", "");
     }
     $room = ilChatroom::byObjectId($this->gui->object->getId());
     if ($room) {
         // if user is in scope
         $scope = $room->getRoomId();
         $chat_user = new ilChatroomUser($ilUser, $room);
         $messageObject = $this->buildMessage(ilUtil::stripSlashes($_REQUEST['user']), $chat_user);
         $message = json_encode($messageObject);
         $params = array('message' => $message, 'userToKick' => $_REQUEST['user']);
         $query = http_build_query($params);
         $connector = $this->gui->getConnector();
         $response = $connector->kick($scope, $query);
         $responseObject = json_decode($response);
         $room->banUser($_REQUEST['user']);
         if ($responseObject->success == true) {
             $room->addHistoryEntry($messageObject, '', 1);
             $message = json_encode(array('type' => 'userjustkicked', 'user' => $params['userToKick'], 'sub' => 0));
             $connector->sendMessage($room->getRoomId(), $message, array('public' => 1, 'sub' => 0));
             $room->disconnectUser($params['userToKick']);
         }
     } else {
         $response = json_encode(array('success' => false, 'reason' => 'unkown room'));
     }
     echo $response;
     exit;
 }