/** * @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); } }
/** * Prepares and displays settings form. * @param ilPropertyFormGUI $settingsForm */ public function general(ilPropertyFormGUI $settingsForm = null) { /** * @var $lng ilLanguage * @var $tpl ilTemplate * @var $ilCtrl ilCtrl */ global $lng, $tpl, $ilCtrl; if (!ilChatroom::checkUserPermissions(array('read', 'write'), $this->gui->ref_id)) { $ilCtrl->setParameterByClass('ilrepositorygui', 'ref_id', ROOT_FOLDER_ID); $ilCtrl->redirectByClass('ilrepositorygui', ''); } $chatSettings = new ilSetting('chatroom'); if (!$chatSettings->get('chat_enabled')) { ilUtil::sendInfo($lng->txt('server_disabled'), true); } $this->gui->switchToVisibleMode(); $formFactory = new ilChatroomFormFactory(); if (!$settingsForm) { $settingsForm = $formFactory->getSettingsForm(); } $room = ilChatRoom::byObjectId($this->gui->object->getId()); $settings = array('title' => $this->gui->object->getTitle(), 'desc' => $this->gui->object->getDescription()); if ($room) { ilChatroomFormFactory::applyValues($settingsForm, array_merge($settings, $room->getSettings())); } else { ilChatroomFormFactory::applyValues($settingsForm, $settings); } $settingsForm->setTitle($lng->txt('settings_title')); $settingsForm->addCommandButton('settings-saveGeneral', $lng->txt('save')); $settingsForm->setFormAction($ilCtrl->getFormAction($this->gui, 'settings-saveGeneral')); $tpl->setVariable('ADM_CONTENT', $settingsForm->getHtml()); }
/** * 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; }
/** * Prepares and displays the info screen. * * @global ilAccessHandler $ilAccess * @global ilCtrl2 $ilCtrl * @global ilLanguage $lng * @param string $method */ public function executeDefault($method) { global $ilAccess, $ilCtrl, $lng; include_once 'Modules/Chatroom/classes/class.ilChatroom.php'; if (!ilChatroom::checkUserPermissions('read', $this->gui->ref_id)) { $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID); $ilCtrl->redirectByClass("ilrepositorygui", ""); } $this->gui->switchToVisibleMode(); if (!$ilAccess->checkAccess("visible", "", $this->gui->ref_id)) { $this->gui->ilias->raiseError($lng->txt("msg_no_perm_read"), $this->ilias->error_obj->MESSAGE); } $info = new ilInfoScreenGUI($this->gui); $info->enablePrivateNotes(); if ($ilAccess->checkAccess("read", "", $_GET["ref_id"])) { $info->enableNews(); } $info->addMetaDataSections($this->gui->object->getId(), 0, $this->gui->object->getType()); if (!$method) { $ilCtrl->setCmd('showSummary'); } else { $ilCtrl->setCmd($method); } $ilCtrl->forwardCommand($info); }
/** * 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; }
/** * Switches GUI to visible mode and calls editSmiliesObject method * which prepares and displays the table of existing smilies. * */ public function view() { include_once 'Modules/Chatroom/classes/class.ilChatroom.php'; ilChatroom::checkUserPermissions('read', $this->gui->ref_id); $this->gui->switchToVisibleMode(); self::_checkSetup(); $this->editSmiliesObject(); }
/** * 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; }
/** * Displays window box to kick a user fetched from $_REQUEST['user']. * * @global ilObjUser $ilUser * @param string $method */ public function executeDefault($method) { /** * @var $ilUser ilObjUser * @var $ilCtrl ilCtrl */ global $ilUser, $ilCtrl; require_once 'Modules/Chatroom/classes/class.ilChatroom.php'; require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php'; 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); 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)); // 2013-09-11: Should already been done by the chat server $room->disconnectUser($params['userToKick']); } } else { $response = json_encode(array('success' => false, 'reason' => 'unkown room')); } echo $response; exit; }
/** * Prepares history table and displays it. * * @global ilTemplate $tpl * @global ilLanguage $lng * @param array $messages * @param ilPropertyFormGUI $durationForm */ private function showMessages($messages, $durationForm, $export = false, $psessions = array(), $from, $to) { //global $tpl, $ilUser, $ilCtrl, $lng; global $tpl, $lng, $ilCtrl; include_once 'Modules/Chatroom/classes/class.ilChatroom.php'; if (!ilChatroom::checkUserPermissions('read', $this->gui->ref_id)) { $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID); $ilCtrl->redirectByClass("ilrepositorygui", ""); } $this->gui->switchToVisibleMode(); $tpl->addCSS('Modules/Chatroom/templates/default/style.css'); // should be able to grep templates if ($export) { $roomTpl = new ilTemplate('tpl.history_export.html', true, true, 'Modules/Chatroom'); } else { $roomTpl = new ilTemplate('tpl.history.html', true, true, 'Modules/Chatroom'); } $scopes = array(); if ($export) { ilDatePresentation::setUseRelativeDates(false); } global $ilUser; $time_format = $ilUser->getTimeFormat(); $prevDate = ''; $messagesShown = 0; $lastDateTime = null; foreach ($messages as $message) { $message['message']->message = json_decode($message['message']->message); switch ($message['message']->type) { case 'message': if ($_REQUEST['scope'] && $message['message']->sub == $_REQUEST['scope'] || !$_REQUEST['scope'] && !$message['message']->sub) { $date = new ilDate($message['timestamp'], IL_CAL_UNIX); $dateTime = new ilDateTime($message['timestamp'], IL_CAL_UNIX); $currentDate = ilDatePresentation::formatDate($dateTime); $roomTpl->setCurrentBlock('MESSAGELINE'); $roomTpl->setVariable('MESSAGECONTENT', $message['message']->message->content); // oops... it is a message? ^^ $roomTpl->setVariable('MESSAGESENDER', $message['message']->user->username); if (null == $lastDateTime || date('d', $lastDateTime->get(IL_CAL_UNIX)) != date('d', $dateTime->get(IL_CAL_UNIX)) || date('m', $lastDateTime->get(IL_CAL_UNIX)) != date('m', $dateTime->get(IL_CAL_UNIX)) || date('Y', $lastDateTime->get(IL_CAL_UNIX)) != date('Y', $dateTime->get(IL_CAL_UNIX))) { $roomTpl->setVariable('MESSAGEDATE', ilDatePresentation::formatDate($date)); } if ($prevDate != $currentDate) { switch ($time_format) { case ilCalendarSettings::TIME_FORMAT_24: $date_string = $dateTime->get(IL_CAL_FKT_DATE, 'H:i', $ilUser->getTimeZone()); break; case ilCalendarSettings::TIME_FORMAT_12: $date_string = $dateTime->get(IL_CAL_FKT_DATE, 'g:ia', $ilUser->getTimeZone()); break; } $roomTpl->setVariable('MESSAGETIME', $date_string); $prevDate = $currentDate; } $roomTpl->parseCurrentBlock(); $lastDateTime = $dateTime; ++$messagesShown; } break; } } foreach ($psessions as $session) { $scopes[$session['proom_id']] = $session['title']; } if (isset($scopes[''])) { unset($scopes['']); } if (!$messagesShown) { //$roomTpl->touchBlock('NO_MESSAGES'); $roomTpl->setVariable('LBL_NO_MESSAGES', $lng->txt('no_messages')); } asort($scopes, SORT_STRING); $scopes = array($lng->txt('main')) + $scopes; if (count($scopes) > 1) { $select = new ilSelectInputGUI($lng->txt('scope'), 'scope'); $select->setOptions($scopes); if (isset($_REQUEST['scope'])) { $select->setValue($_REQUEST['scope']); } $durationForm->addItem($select); } $room = ilChatroom::byObjectId($this->gui->object->getId()); //if ($room->getSetting('private_rooms_enabled')) { $prevUseRelDates = ilDatePresentation::useRelativeDates(); ilDatePresentation::setUseRelativeDates(false); $unixFrom = $from->getUnixTime(); $unixTo = $to->getUnixTime(); if ($unixFrom == $unixTo) { $date = new ilDate($unixFrom, IL_CAL_UNIX); $date_sub = ilDatePresentation::formatDate($date); } else { $date1 = new ilDate($unixFrom, IL_CAL_UNIX); $date2 = new ilDate($unixTo, IL_CAL_UNIX); $date_sub = ilDatePresentation::formatPeriod($date1, $date2); } ilDatePresentation::setUseRelativeDates($prevUseRelDates); $isPrivateRoom = (bool) (int) $_REQUEST['scope']; if ($isPrivateRoom) { $roomTpl->setVariable('ROOM_TITLE', sprintf($lng->txt('history_title_private_room'), $scopes[(int) $_REQUEST['scope']]) . ' (' . $date_sub . ')'); } else { $roomTpl->setVariable('ROOM_TITLE', sprintf($lng->txt('history_title_general'), $this->gui->object->getTitle()) . ' (' . $date_sub . ')'); } //} if ($export) { header("Content-Type: text/html"); header("Content-Disposition: attachment; filename=\"" . urlencode($scopes[(int) $_REQUEST['scope']] . '.html') . "\""); echo $roomTpl->get(); exit; } $roomTpl->setVariable('PERIOD_FORM', $durationForm->getHTML()); $tpl->setVariable('ADM_CONTENT', $roomTpl->get()); }
public function enter() { global $tpl, $ilUser; ilChatroom::checkUserPermissions('read', $this->gui->ref_id); $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 (!$room->isAllowedToEnterPrivateRoom($chat_user->getUserId(), $_REQUEST['sub'])) { $response = json_encode(array('success' => false, 'reason' => 'not allowed enter to private room')); echo json_encode($response); exit; } } $scope = $room->getRoomId(); $params = array(); $params['user'] = $chat_user->getUserId(); $params['sub'] = $_REQUEST['sub']; $params['message'] = json_encode(array('type' => 'private_room_entered', 'user' => $user_id)); $query = http_build_query($params); $connector = $this->gui->getConnector(); $response = $connector->enterPrivateRoom($scope, $query); $responseObject = json_decode($response); $message = json_encode(array('type' => 'private_room_entered', 'user' => $params['user'], 'sub' => $params['sub'])); $connector->sendMessage($room->getRoomId(), $message, array('public' => 1, 'sub' => $params['sub'])); if ($responseObject->success == true) { $room->subscribeUserToPrivateRoom($params['sub'], $params['user']); } echo $response; exit; }
/** * Builds tabs and subtabs using given $tabs, $config and $command * parameters. * @param ilTabsGUI $tabs * @param array $config * @param array $command */ private function buildTabs(ilTabsGUI $tabs, $config, $command) { /** * @var $rbacsystem ilRbacSystem */ global $rbacsystem; require_once 'Modules/Chatroom/classes/class.ilChatroom.php'; foreach ($config as $id => $tabDefinition) { if (!ilChatroom::checkUserPermissions($tabDefinition['permission'], $this->gui->getRefId(), false)) { continue; } else { if (isset($tabDefinition['enabled']) && !$tabDefinition['enabled']) { continue; } } $tabs->addTab($id, $this->getLabel($tabDefinition, $id), $tabDefinition['link']); if ($command[0] == $id && isset($tabDefinition['subtabs']) && is_array($tabDefinition['subtabs'])) { foreach ($tabDefinition['subtabs'] as $subid => $subTabDefinition) { if (!$rbacsystem->checkAccess($subTabDefinition['permission'], $this->gui->getRefId())) { continue; } else { if (isset($subTabDefinition['enabled']) && !$subTabDefinition['enabled']) { continue; } } $tabs->addSubTab($subid, $this->getLabel($subTabDefinition, $subid), $subTabDefinition['link']); } } } }
/** * Chatroom and Chatuser get prepared before $this->showRoom method * is called. If custom usernames are allowed, $this->showNameSelection * method is called if user isn't already registered in the Chatroom. * @param string $method */ public function executeDefault($method) { /** * @var $ilUser ilObjUser * @var $lng ilLanguage * @var $ilCtrl ilCtrl */ global $ilUser, $lng, $ilCtrl; include_once 'Modules/Chatroom/classes/class.ilChatroom.php'; ilChatroom::checkUserPermissions('read', $this->gui->ref_id); $this->gui->switchToVisibleMode(); $this->setupTemplate(); $chatSettings = new ilSetting('chatroom'); if (!$chatSettings->get('chat_enabled')) { $ilCtrl->redirect($this->gui, 'settings-general'); exit; } $room = ilChatroom::byObjectId($this->gui->object->getId()); if (!$room->getSetting('allow_anonymous') && $ilUser->isAnonymous()) { $this->cancelJoin($lng->txt('anonymous_not_allowed')); return; } $chat_user = new ilChatroomUser($ilUser, $room); if ($room->getSetting('allow_custom_usernames')) { if ($room->isSubscribed($chat_user->getUserId())) { $chat_user->setUsername($chat_user->getUsername()); $this->showRoom($room, $chat_user); } else { $this->showNameSelection($chat_user); } } else { $chat_user->setUsername($ilUser->getLogin()); $this->showRoom($room, $chat_user); } }
/** * @param ilPropertyFormGUI $form */ public function clientsettings(ilPropertyFormGUI $form = null) { /** * @var $tpl ilTemplate * @var $ilCtrl ilCtrl * @var $lng ilLanguage */ global $tpl, $ilCtrl, $lng; ilChatroom::checkUserPermissions('read', $this->gui->ref_id); $this->defaultActions(); $this->gui->switchToVisibleMode(); $this->showSoapWarningIfNeeded(); require_once 'Modules/Chatroom/classes/class.ilChatroomAdmin.php'; $adminSettings = new ilChatroomAdmin($this->gui->object->getId()); if ($form === null) { require_once 'Modules/Chatroom/classes/class.ilChatroomFormFactory.php'; $factory = new ilChatroomFormFactory(); $form = $factory->getClientSettingsForm(); if (!$this->commonSettings->get('soap_user_administration')) { $form->getItemByPostVar('chat_enabled')->setDisabled(!(bool) $this->commonSettings->get('soap_user_administration')); $form->getItemByPostVar('chat_enabled')->setChecked(0); } $data = (array) $adminSettings->loadClientSettings(); if (!$data['osd_intervall']) { $data['osd_intervall'] = 60; } if (!$data) { $data = array(); } if (!$data['url']) { $data['url'] = ilUtil::_getHttpPath(); } if (!$data['client']) { $data['client'] = CLIENT_ID; } $data['password_retype'] = $data['password']; $form->setValuesByArray($data); } require_once 'Modules/Chatroom/classes/class.ilChatroomServerConnector.php'; $serverSettings = (array) $adminSettings->loadGeneralSettings(); if ($serverSettings['port'] && $serverSettings['address'] && !(bool) @ilChatroomServerConnector::checkServerConnection()) { ilUtil::sendInfo($lng->txt('chat_cannot_connect_to_server')); } $form->setTitle($lng->txt('general_settings_title')); $form->addCommandButton('view-saveClientSettings', $lng->txt('save')); $form->setFormAction($ilCtrl->getFormAction($this->gui, 'view-saveClientSettings')); $settingsTpl = new ilTemplate('tpl.chatroom_serversettings.html', true, true, 'Modules/Chatroom'); $settingsTpl->setVariable('VAL_SERVERSETTINGS_FORM', $form->getHTML()); $settingsTpl->setVariable('LBL_SERVERSETTINGS_FURTHER_INFORMATION', sprintf($lng->txt('server_further_information'), ilUtil::_getHttpPath() . '/Modules/Chatroom/server/README.txt')); $tpl->setVariable('ADM_CONTENT', $settingsTpl->get()); }