echo '</p>'; } } echo $OUTPUT->box_end(); } else { echo $OUTPUT->box_start('generalbox', 'notallowenter'); echo '<p>'.get_string('notallowenter', 'chat').'</p>'; echo $OUTPUT->box_end(); } chat_delete_old_users(); if ($chatusers = chat_get_users($chat->id, $currentgroup, $cm->groupingid)) { $timenow = time(); echo $OUTPUT->box_start('generalbox', 'chatcurrentusers'); echo $OUTPUT->heading($strcurrentusers, 4); echo '<table>'; foreach ($chatusers as $chatuser) { $lastping = $timenow - $chatuser->lastmessageping; echo '<tr><td class="chatuserimage">'; $url = new moodle_url('/user/view.php', array('id'=>$chatuser->id, 'course'=>$chat->course)); echo html_writer::link($url, $OUTPUT->user_picture($chatuser)); echo '</td><td class="chatuserdetails">'; echo '<p>'.fullname($chatuser).'</p>'; echo '<span class="idletime">'.$stridle.': '.format_time($lastping).'</span>'; echo '</td></tr>'; } echo '</table>';
function chat_extend_navigation($navigation, $course, $module, $cm) { global $CFG; $currentgroup = groups_get_activity_group($cm, true); if (has_capability('mod/chat:chat', context_module::instance($cm->id))) { $strenterchat = get_string('enterchat', 'chat'); $target = $CFG->wwwroot . '/mod/chat/'; $params = array('id' => $cm->instance); if ($currentgroup) { $params['groupid'] = $currentgroup; } $links = array(); $url = new moodle_url($target . 'gui_' . $CFG->chat_method . '/index.php', $params); $action = new popup_action('click', $url, 'chat' . $course->id . $cm->instance . $currentgroup, array('height' => 500, 'width' => 700)); $links[] = new action_link($url, $strenterchat, $action); $url = new moodle_url($target . 'gui_basic/index.php', $params); $action = new popup_action('click', $url, 'chat' . $course->id . $cm->instance . $currentgroup, array('height' => 500, 'width' => 700)); $links[] = new action_link($url, get_string('noframesjs', 'message'), $action); foreach ($links as $link) { $navigation->add($link->text, $link, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/group', '')); } } $chatusers = chat_get_users($cm->instance, $currentgroup, $cm->groupingid); if (is_array($chatusers) && count($chatusers) > 0) { $users = $navigation->add(get_string('currentusers', 'chat')); foreach ($chatusers as $chatuser) { $userlink = new moodle_url('/user/view.php', array('id' => $chatuser->id, 'course' => $course->id)); $users->add(fullname($chatuser) . ' ' . format_time(time() - $chatuser->lastmessageping), $userlink, navigation_node::TYPE_USER, null, null, new pix_icon('i/user', '')); } } }
/** * Get the list of users in the given chat session. * * @param int $chatsid the chat session id * @return array of warnings and the user lists * @since Moodle 3.0 * @throws moodle_exception */ public static function get_chat_users($chatsid) { global $DB, $PAGE; $params = self::validate_parameters(self::get_chat_users_parameters(), array('chatsid' => $chatsid)); $warnings = array(); // Request and permission validation. if (!($chatuser = $DB->get_record('chat_users', array('sid' => $params['chatsid'])))) { throw new moodle_exception('notlogged', 'chat'); } $chat = $DB->get_record('chat', array('id' => $chatuser->chatid), '*', MUST_EXIST); list($course, $cm) = get_course_and_cm_from_instance($chat, 'chat'); $context = context_module::instance($cm->id); self::validate_context($context); require_capability('mod/chat:chat', $context); // First, delete old users from the chats. chat_delete_old_users(); $users = chat_get_users($chatuser->chatid, $chatuser->groupid, $cm->groupingid); $returnedusers = array(); foreach ($users as $user) { $userpicture = new user_picture($user); $userpicture->size = 1; // Size f1. $profileimageurl = $userpicture->get_url($PAGE)->out(false); $returnedusers[] = array('id' => $user->id, 'fullname' => fullname($user), 'profileimageurl' => $profileimageurl); } $result = array(); $result['users'] = $returnedusers; $result['warnings'] = $warnings; return $result; }
} else { $groupname = ': '.get_string('allparticipants'); } } else { $groupid = 0; $groupname = ''; } $strchat = get_string('modulename', 'chat'); // must be before current_language() in chat_login_user() to force course language!!! $strchats = get_string('modulenameplural', 'chat'); $stridle = get_String('idle', 'chat'); if (!$chat_sid = chat_login_user($chat->id, 'basic', $groupid, $course)) { print_error('cantlogin', 'chat'); } if (!$chatusers = chat_get_users($chat->id, $groupid, $cm->groupingid)) { print_error('errornousers', 'chat'); } $DB->set_field('chat_users', 'lastping', time(), array('sid'=>$chat_sid)); if (!isset($SESSION->chatprefs)) { $SESSION->chatprefs = array(); } if (!isset($SESSION->chatprefs[$chat->id])) { $SESSION->chatprefs[$chat->id] = array(); $SESSION->chatprefs[$chat->id]['chatentered'] = time(); } $chatentered = $SESSION->chatprefs[$chat->id]['chatentered']; $refreshedmessage = '';
$send_user_list = true; } if ($html = chat_format_message_theme($message, $chatuser, $USER, $cm->groupingid, $theme)) { $message->mymessage = $USER->id == $message->userid; $message->message = $html->html; if (!empty($html->type)) { $message->type = $html->type; } } else { unset($messages[$n]); } } } if ($send_user_list) { // return users when system message coming $users = chat_format_userlist(chat_get_users($chatuser->chatid, $chatuser->groupid, $cm->groupingid), $course); $response['users'] = $users; } $DB->set_field('chat_users', 'lastping', time(), array('id' => $chatuser->id)); $response['lasttime'] = $chat_newlasttime; $response['lastrow'] = $chat_newrow; if ($messages) { $response['msgs'] = $messages; } echo json_encode($response); header('Content-Length: ' . ob_get_length()); ob_end_flush(); break; default: break; }
} else { // show some error message require_capability('mod/chat:chat', $context); } } if ($chat->chattime and $chat->schedule) { // A chat is scheduled echo "<p class=\"nextchatsession\">{$strnextsession}: " . userdate($chat->chattime) . ' (' . usertimezone($USER->timezone) . ')</p>'; } else { echo '<br />'; } if ($chat->intro) { print_box(format_text($chat->intro), 'generalbox', 'intro'); } chat_delete_old_users(); if ($chatusers = chat_get_users($chat->id, $currentgroup)) { $timenow = time(); print_simple_box_start('center'); print_heading($strcurrentusers); echo '<table id="chatcurrentusers">'; foreach ($chatusers as $chatuser) { $lastping = $timenow - $chatuser->lastmessageping; echo '<tr><td class="chatuserimage">'; echo "<a href=\"{$CFG->wwwroot}/user/view.php?id={$chatuser->id}&course={$chat->course}\">"; print_user_picture($chatuser->id, 0, $chatuser->picture, false, false, false); echo '</a></td><td class="chatuserdetails">'; echo '<p>'; echo fullname($chatuser) . '<br />'; echo "<span class=\"idletime\">{$stridle}: " . format_time($lastping) . "</span>"; echo '</p>'; echo '</td></tr>';
$groupname = ': ' . $group->name; } else { $groupname = ': ' . get_string('allparticipants'); } } else { $groupid = 0; $groupname = ''; } $strchat = get_string('modulename', 'chat'); // must be before current_language() in chat_login_user() to force course language!!! $strchats = get_string('modulenameplural', 'chat'); $stridle = get_String('idle', 'chat'); if (!($chat_sid = chat_login_user($chat->id, 'basic', $groupid, $course))) { error('Could not log in to chat room!!'); } if (!($chatusers = chat_get_users($chat->id, $groupid))) { error(get_string('errornousers', 'chat')); } set_field('chat_users', 'lastping', time(), 'sid', $chat_sid); if (!isset($SESSION->chatprefs)) { $SESSION->chatprefs = array(); } if (!isset($SESSION->chatprefs[$chat->id])) { $SESSION->chatprefs[$chat->id] = array(); $SESSION->chatprefs[$chat->id]['chatentered'] = time(); } $chatentered = $SESSION->chatprefs[$chat->id]['chatentered']; $refreshedmessage = ''; if (!empty($refresh) and data_submitted()) { $refreshedmessage = $message; chat_delete_old_users();
$message->chatid = $chatuser->chatid; $message->userid = $chatuser->userid; $message->groupid = $chatuser->groupid; $message->message = "beep {$beep}"; $message->system = 0; $message->timestamp = time(); $DB->insert_record('chat_messages', $message); $DB->insert_record('chat_messages_current', $message); $chatuser->lastmessageping = time(); // A beep is a ping ;-) } $chatuser->lastping = time(); $DB->set_field('chat_users', 'lastping', $chatuser->lastping, array('id' => $chatuser->id)); $refreshurl = "users.php?chat_sid={$chat_sid}"; /// Get list of users if (!($chatusers = chat_get_users($chatuser->chatid, $chatuser->groupid, $cm->groupingid))) { print_error('errornousers', 'chat'); } $uidles = array(); $i = 0; foreach ($chatusers as $chatuser) { $uidles[$i] = 'uidle{$chatuser->id}'; $i++; } $PAGE->requires->data_for_js('uidles', $uidles)->in_head(); $PAGE->requires->js('mod/chat/gui_header_js/chat_gui_header.js')->in_head(); // Use ob to support Keep-Alive ob_start(); print_header('', '', '', '', '', false, '', '', false, 'onload="start()" onunload="stop()"'); /// Print user panel body $timenow = time();
/** * Get the list of users in the given chat session. * * @param int $chatsid the chat session id * @return array of warnings and the user lists * @since Moodle 3.0 * @throws moodle_exception */ public static function get_chat_users($chatsid) { global $DB; $params = self::validate_parameters(self::get_chat_users_parameters(), array( 'chatsid' => $chatsid )); $warnings = array(); // Request and permission validation. if (!$chatuser = $DB->get_record('chat_users', array('sid' => $params['chatsid']))) { throw new moodle_exception('notlogged', 'chat'); } $chat = $DB->get_record('chat', array('id' => $chatuser->chatid), '*', MUST_EXIST); list($course, $cm) = get_course_and_cm_from_instance($chat, 'chat'); $context = context_module::instance($cm->id); self::validate_context($context); require_capability('mod/chat:chat', $context); // First, delete old users from the chats. chat_delete_old_users(); $users = chat_get_users($chatuser->chatid, $chatuser->groupid, $cm->groupingid); $returnedusers = array(); foreach ($users as $user) { $usercontext = context_user::instance($user->id, IGNORE_MISSING); $profileimageurl = ''; if ($usercontext) { $profileimageurl = moodle_url::make_webservice_pluginfile_url( $usercontext->id, 'user', 'icon', null, '/', 'f1')->out(false); } $returnedusers[] = array( 'id' => $user->id, 'fullname' => fullname($user), 'profileimageurl' => $profileimageurl ); } $result = array(); $result['users'] = $returnedusers; $result['warnings'] = $warnings; return $result; }