mod-chat MDL-19804 Added PAGE->set_url calls and removed deprecated functions

This commit is contained in:
samhemelryk 2009-09-23 07:08:43 +00:00
parent 97dcb8f88e
commit eb588b22ab
13 changed files with 677 additions and 600 deletions

View File

@ -37,12 +37,13 @@ if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
chat_print_error('ERROR', get_string('invalidcoursemodule', 'error'));
}
if (isguest()) {
if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) {
chat_print_error('ERROR', get_string('notlogged','chat'));
}
// setup $PAGE so that format_text will work properly
$PAGE->set_cm($cm, $course, $chat);
$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/chat/chat_ajax.php', array('chat_sid'=>$chat_sid)));
ob_start();
header('Expires: Sun, 28 Dec 1997 09:32:45 GMT');

View File

@ -3,6 +3,13 @@ require_once('../../../config.php');
require_once('../lib.php');
$id = required_param('id', PARAM_INT);
$groupid = optional_param('groupid', 0, PARAM_INT); //only for teachers
$url = new moodle_url($CFG->wwwroot.'/mod/chat/gui_ajax/index.php', array('id'=>$id));
if ($groupid !== 0) {
$url->param('groupid', $groupid);
}
$PAGE->set_url($url);
if (!$chat = $DB->get_record('chat', array('id'=>$id))) {
print_error('invalidid', 'chat');
}

View File

@ -1,181 +1,196 @@
<?php // $Id$
<?php
require_once('../../../config.php');
require_once('../lib.php');
require_once('../../../config.php');
require_once('../lib.php');
$id = required_param('id', PARAM_INT);
$groupid = optional_param('groupid', 0, PARAM_INT); // only for teachers
$message = optional_param('message', '', PARAM_CLEAN);
$refresh = optional_param('refresh', '', PARAM_RAW); // force refresh
$last = optional_param('last', 0, PARAM_INT); // last time refresh or sending
$newonly = optional_param('newonly', 0, PARAM_BOOL); // show only new messages
$id = required_param('id', PARAM_INT);
$groupid = optional_param('groupid', 0, PARAM_INT); // only for teachers
$message = optional_param('message', '', PARAM_CLEAN);
$refresh = optional_param('refresh', '', PARAM_RAW); // force refresh
$last = optional_param('last', 0, PARAM_INT); // last time refresh or sending
$newonly = optional_param('newonly', 0, PARAM_BOOL); // show only new messages
if (!$chat = $DB->get_record('chat', array('id'=>$id))) {
print_error('invalidid', 'chat');
}
$url = new moodle_url($CFG->wwwroot.'/mod/chat/gui_basic/index.php', array('id'=>$id));
if ($groupid !== 0) {
$url->param('groupid', $groupid);
}
if ($message !== 0) {
$url->param('message', $message);
}
if ($refresh !== 0) {
$url->param('refresh', $refresh);
}
if ($last !== 0) {
$url->param('last', $last);
}
if ($newonly !== 0) {
$url->param('newonly', $newonly);
}
$PAGE->set_url($url);
if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
print_error('invalidcourseid');
}
if (!$chat = $DB->get_record('chat', array('id'=>$id))) {
print_error('invalidid', 'chat');
}
if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
print_error('invalidcoursemodule');
}
if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
print_error('invalidcourseid');
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_login($course->id, false, $cm);
require_capability('mod/chat:chat',$context);
$PAGE->set_generaltype('form');
$PAGE->requires->css('mod/chat/chat.css');
if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
print_error('invalidcoursemodule');
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_login($course->id, false, $cm);
require_capability('mod/chat:chat',$context);
$PAGE->set_generaltype('form');
$PAGE->requires->css('mod/chat/chat.css');
/// Check to see if groups are being used here
if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used
if ($groupid = groups_get_activity_group($cm)) {
if (!$group = groups_get_group($groupid, false)) {
print_error('invalidgroupid');
}
$groupname = ': '.$group->name;
} else {
$groupname = ': '.get_string('allparticipants');
if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used
if ($groupid = groups_get_activity_group($cm)) {
if (!$group = groups_get_group($groupid, false)) {
print_error('invalidgroupid');
}
$groupname = ': '.$group->name;
} else {
$groupid = 0;
$groupname = '';
$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 = '';
if (!empty($refresh) and data_submitted()) {
$refreshedmessage = $message;
chat_delete_old_users();
} else if (empty($refresh) and data_submitted() and confirm_sesskey()) {
if ($message!='') {
$newmessage = new object();
$newmessage->chatid = $chat->id;
$newmessage->userid = $USER->id;
$newmessage->groupid = $groupid;
$newmessage->systrem = 0;
$newmessage->message = $message;
$newmessage->timestamp = time();
$DB->insert_record('chat_messages', $newmessage);
$DB->insert_record('chat_messages_current', $newmessage);
$DB->set_field('chat_users', 'lastmessageping', time(), array('sid'=>$chat_sid));
add_to_log($course->id, 'chat', 'talk', "view.php?id=$cm->id", $chat->id, $cm->id);
}
$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');
chat_delete_old_users();
redirect('index.php?id='.$id.'&amp;newonly='.$newonly.'&amp;last='.$last);
}
$PAGE->set_title("$strchat: $course->shortname: ".format_string($chat->name,true)."$groupname");
$PAGE->set_focuscontrol('message');
echo $OUTPUT->header();
echo '<div id="mod-chat-gui_basic">';
echo '<h1>'.get_string('participants').'</h1>';
echo '<div id="participants"><ul>';
foreach($chatusers as $chu) {
echo '<li>';
$userpic = moodle_user_picture::make($chu->id, $course->id);
$userpic->size = 24;
echo $OUTPUT->user_picture($userpic);
echo '<div class="userinfo">';
echo fullname($chu).' ';
if ($idle = time() - $chu->lastmessageping) {
echo '<span class="idle">'.$stridle.' '.format_time($idle).'</span>';
} else {
echo '<span class="idle" />';
}
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 = '';
if (!empty($refresh) and data_submitted()) {
$refreshedmessage = $message;
chat_delete_old_users();
} else if (empty($refresh) and data_submitted() and confirm_sesskey()) {
if ($message!='') {
$newmessage = new object();
$newmessage->chatid = $chat->id;
$newmessage->userid = $USER->id;
$newmessage->groupid = $groupid;
$newmessage->systrem = 0;
$newmessage->message = $message;
$newmessage->timestamp = time();
$DB->insert_record('chat_messages', $newmessage);
$DB->insert_record('chat_messages_current', $newmessage);
$DB->set_field('chat_users', 'lastmessageping', time(), array('sid'=>$chat_sid));
add_to_log($course->id, 'chat', 'talk', "view.php?id=$cm->id", $chat->id, $cm->id);
}
chat_delete_old_users();
redirect('index.php?id='.$id.'&amp;newonly='.$newonly.'&amp;last='.$last);
}
$PAGE->set_title("$strchat: $course->shortname: ".format_string($chat->name,true)."$groupname");
$PAGE->set_focuscontrol('message');
echo $OUTPUT->header();
echo '<div id="mod-chat-gui_basic">';
echo '<h1>'.get_string('participants').'</h1>';
echo '<div id="participants"><ul>';
foreach($chatusers as $chu) {
echo '<li>';
$userpic = moodle_user_picture::make($chu->id, $course->id);
$userpic->size = 24;
echo $OUTPUT->user_picture($userpic);
echo '<div class="userinfo">';
echo fullname($chu).' ';
if ($idle = time() - $chu->lastmessageping) {
echo '<span class="idle">'.$stridle.' '.format_time($idle).'</span>';
} else {
echo '<span class="idle" />';
}
echo '</div>';
echo '</li>';
}
echo '</ul></div>';
echo '<div id="send">';
echo '<form id="editing" method="post" action="index.php">';
$usehtmleditor = can_use_html_editor();
echo '<h1><label for="message">'.get_string('sendmessage', 'message').'</label></h1>';
echo '<div>';
echo '<input type="text" id="message" name="message" value="'.s($refreshedmessage, true).'" size="60" />';
echo '</div><div>';
echo '<input type="hidden" name="id" value="'.$id.'" />';
echo '<input type="hidden" name="groupid" value="'.$groupid.'" />';
echo '<input type="hidden" name="last" value="'.time().'" />';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<input type="submit" value="'.get_string('submit').'" />&nbsp;';
echo '<input type="submit" name="refresh" value="'.get_string('refresh').'" />';
echo '<input type="checkbox" name="newonly" id="newonly" '.($newonly?'checked="checked" ':'').'/><label for="newonly">'.get_string('newonlymsg', 'message').'</label>';
echo '</div>';
echo '</form>';
echo '</div>';
echo '</li>';
}
echo '</ul></div>';
echo '<div id="send">';
echo '<form id="editing" method="post" action="index.php">';
echo '<div id="messages">';
echo '<h1>'.get_string('messages', 'chat').'</h1>';
$usehtmleditor = can_use_html_editor();
echo '<h1><label for="message">'.get_string('sendmessage', 'message').'</label></h1>';
echo '<div>';
echo '<input type="text" id="message" name="message" value="'.s($refreshedmessage, true).'" size="60" />';
echo '</div><div>';
echo '<input type="hidden" name="id" value="'.$id.'" />';
echo '<input type="hidden" name="groupid" value="'.$groupid.'" />';
echo '<input type="hidden" name="last" value="'.time().'" />';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<input type="submit" value="'.get_string('submit').'" />&nbsp;';
echo '<input type="submit" name="refresh" value="'.get_string('refresh').'" />';
echo '<input type="checkbox" name="newonly" id="newonly" '.($newonly?'checked="checked" ':'').'/><label for="newonly">'.get_string('newonlymsg', 'message').'</label>';
echo '</div>';
echo '</form>';
echo '</div>';
$allmessages = array();
$options = new object();
$options->para = false;
$options->newlines = true;
echo '<div id="messages">';
echo '<h1>'.get_string('messages', 'chat').'</h1>';
$params = array('last'=>$last, 'groupid'=>$groupid, 'chatid'=>$chat->id, 'chatentered'=>$chatentered);
$allmessages = array();
$options = new object();
$options->para = false;
$options->newlines = true;
if ($newonly) {
$lastsql = "AND timestamp > :last";
} else {
$lastsql = "";
$params = array('last'=>$last, 'groupid'=>$groupid, 'chatid'=>$chat->id, 'chatentered'=>$chatentered);
if ($newonly) {
$lastsql = "AND timestamp > :last";
} else {
$lastsql = "";
}
$groupselect = $groupid ? "AND (groupid=:groupid OR groupid=0)" : "";
$messages = $DB->get_records_select("chat_messages_current",
"chatid = :chatid AND timestamp > :chatentered $lastsql $groupselect", $params,
"timestamp DESC");
if ($messages) {
foreach ($messages as $message) {
$allmessages[] = chat_format_message($message, $course->id, $USER);
}
}
$groupselect = $groupid ? "AND (groupid=:groupid OR groupid=0)" : "";
$messages = $DB->get_records_select("chat_messages_current",
"chatid = :chatid AND timestamp > :chatentered $lastsql $groupselect", $params,
"timestamp DESC");
if ($messages) {
foreach ($messages as $message) {
$allmessages[] = chat_format_message($message, $course->id, $USER);
}
if (empty($allmessages)) {
echo get_string('nomessagesfound', 'message');
} else {
foreach ($allmessages as $message) {
echo $message->basic;
}
}
if (empty($allmessages)) {
echo get_string('nomessagesfound', 'message');
} else {
foreach ($allmessages as $message) {
echo $message->basic;
}
}
echo '</div></div>';
echo $OUTPUT->footer();
echo '</div></div>';
echo $OUTPUT->footer();
?>
?>

View File

@ -1,42 +1,42 @@
<?php // $Id$
<?php
define('NO_MOODLE_COOKIES', true); // session not used here
define('NO_MOODLE_COOKIES', true); // session not used here
require('../../../config.php');
require('../lib.php');
require('../../../config.php');
require('../lib.php');
$chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
$chatid = required_param('chat_id', PARAM_INT);
$chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
$chatid = required_param('chat_id', PARAM_INT);
if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
print_error('notlogged', 'chat');
}
if (!$chat = $DB->get_record('chat', array('id'=>$chatid))) {
error('Could not find that chat room!');
}
if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
print_error('notlogged', 'chat');
}
if (!$chat = $DB->get_record('chat', array('id'=>$chatid))) {
print_error('invalidid', 'chat');
}
if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
error('Could not find the course this belongs to!');
}
if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
print_error('invalidcourseid');
}
if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
error('Course Module ID was incorrect');
}
if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
print_error('invalidcoursemodule');
}
$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/chat/gui_header_js/chatinput.php', array('chat_sid'=>$chat_sid, 'chat_id'=>$chatid)));
$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/chat/gui_header_js/chatinput.php', array('chat_sid'=>$chat_sid, 'chat_id'=>$chatid)));
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
//Get the user theme
$USER = $DB->get_record('user', array('id'=>$chatuser->userid));
//Get the user theme
$USER = $DB->get_record('user', array('id'=>$chatuser->userid));
//Setup course, lang and theme
$PAGE->set_course($course);
$PAGE->requires->js('mod/chat/gui_header_js/chat_gui_header.js')->in_head();
$PAGE->set_generaltype('embedded');
$PAGE->set_focuscontrol('input_chat_message');
$PAGE->set_cacheable(false);
echo $OUTPUT->header();
//Setup course, lang and theme
$PAGE->set_course($course);
$PAGE->requires->js('mod/chat/gui_header_js/chat_gui_header.js')->in_head();
$PAGE->set_generaltype('embedded');
$PAGE->set_focuscontrol('input_chat_message');
$PAGE->set_cacheable(false);
echo $OUTPUT->header();
?>
<form action="../empty.php" method="post" target="empty" id="inputForm"

View File

@ -1,62 +1,69 @@
<?php // $Id$
<?php
require_once('../../../config.php');
require_once('../lib.php');
require_once('../../../config.php');
require_once('../lib.php');
$id = required_param('id', PARAM_INT);
$groupid = optional_param('groupid', 0, PARAM_INT); //only for teachers
$id = required_param('id', PARAM_INT);
$groupid = optional_param('groupid', 0, PARAM_INT); //only for teachers
if (!$chat = $DB->get_record('chat', array('id'=>$id))) {
print_error('invalidid', 'chat');
}
$url = new moodle_url($CFG->wwwroot.'/mod/chat/gui_header_js/index.php', array('id'=>$id));
if ($groupid !== 0) {
$url->param('groupid', $groupid);
}
$PAGE->set_url($url);
if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
print_error('invalidcourseid');
}
if (!$chat = $DB->get_record('chat', array('id'=>$id))) {
print_error('invalidid', 'chat');
}
if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
print_error('invalidcoursemodule');
}
if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
print_error('invalidcourseid');
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
print_error('invalidcoursemodule');
}
require_login($course->id, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/chat:chat',$context);
require_login($course->id, false, $cm);
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id))) {
echo $OUTPUT->header();
notice(get_string("activityiscurrentlyhidden"));
}
require_capability('mod/chat:chat',$context);
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id))) {
echo $OUTPUT->header();
notice(get_string("activityiscurrentlyhidden"));
}
/// Check to see if groups are being used here
if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used
if ($groupid = groups_get_activity_group($cm)) {
if (!$group = groups_get_group($groupid, false)) {
print_error('invalidgroupid');
}
$groupname = ': '.$group->name;
} else {
$groupname = ': '.get_string('allparticipants');
if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used
if ($groupid = groups_get_activity_group($cm)) {
if (!$group = groups_get_group($groupid, false)) {
print_error('invalidgroupid');
}
$groupname = ': '.$group->name;
} else {
$groupid = 0;
$groupname = '';
$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!!!
$strchat = get_string('modulename', 'chat'); // must be before current_language() in chat_login_user() to force course language!!!
if (!$chat_sid = chat_login_user($chat->id, 'header_js', $groupid, $course)) {
print_error('cantlogin', 'chat');
}
if (!$chat_sid = chat_login_user($chat->id, 'header_js', $groupid, $course)) {
print_error('cantlogin', 'chat');
}
$params = "chat_id=$id&chat_sid={$chat_sid}";
$params = "chat_id=$id&chat_sid={$chat_sid}";
// fallback to the old jsupdate, but allow other update modes
$updatemode = 'jsupdate';
if (!empty($CFG->chat_normal_updatemode)) {
$updatemode = $CFG->chat_normal_updatemode;
}
// fallback to the old jsupdate, but allow other update modes
$updatemode = 'jsupdate';
if (!empty($CFG->chat_normal_updatemode)) {
$updatemode = $CFG->chat_normal_updatemode;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">

View File

@ -1,73 +1,74 @@
<?php // $Id$
<?php
include('../../../config.php');
include('../lib.php');
include('../../../config.php');
include('../lib.php');
$chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
$chat_message = required_param('chat_message', PARAM_RAW);
$chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
$chat_message = required_param('chat_message', PARAM_RAW);
if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
print_error('notlogged', 'chat');
}
$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/chat/gui_header_js/insert.php', array('chat_sid'=>$chat_sid,'chat_message'=>$chat_message)));
if (!$chat = $DB->get_record('chat', array('id'=>$chatuser->chatid))) {
print_error('nochat', 'chat');
}
if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
print_error('notlogged', 'chat');
}
if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
print_error('invalidcourseid');
}
if (!$chat = $DB->get_record('chat', array('id'=>$chatuser->chatid))) {
print_error('nochat', 'chat');
}
if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
print_error('invalidcoursemodule');
}
if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
print_error('invalidcourseid');
}
require_login($course->id, false, $cm);
if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
print_error('invalidcoursemodule');
}
if (isguest()) {
print_error('noguests');
}
require_login($course->id, false, $cm);
session_get_instance()->write_close();
if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) {
print_error('noguests');
}
session_get_instance()->write_close();
/// Delete old users now
chat_delete_old_users();
chat_delete_old_users();
/// Clean up the message
$chat_message = clean_text($chat_message, FORMAT_MOODLE); // Strip bad tags
$chat_message = clean_text($chat_message, FORMAT_MOODLE); // Strip bad tags
/// Add the message to the database
if (!empty($chat_message)) {
if (!empty($chat_message)) {
$message = new object();
$message->chatid = $chatuser->chatid;
$message->userid = $chatuser->userid;
$message->groupid = $chatuser->groupid;
$message->message = $chat_message;
$message->timestamp = time();
$message = new object();
$message->chatid = $chatuser->chatid;
$message->userid = $chatuser->userid;
$message->groupid = $chatuser->groupid;
$message->message = $chat_message;
$message->timestamp = time();
$DB->insert_record('chat_messages', $message);
$DB->insert_record('chat_messages_current', $message);
$DB->insert_record('chat_messages', $message);
$DB->insert_record('chat_messages_current', $message);
$chatuser->lastmessageping = time() - 2;
$DB->update_record('chat_users', $chatuser);
$chatuser->lastmessageping = time() - 2;
$DB->update_record('chat_users', $chatuser);
if ($cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
add_to_log($course->id, 'chat', 'talk', "view.php?id=$cm->id", $chat->id, $cm->id);
}
if ($cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
add_to_log($course->id, 'chat', 'talk', "view.php?id=$cm->id", $chat->id, $cm->id);
}
}
if ($chatuser->version == 'header_js') {
/// force msg referesh ASAP
echo $PAGE->requires->js('mod/chat/gui_header_js/chat_gui_header.js')->asap();
if ($CFG->chat_normal_updatemode != 'jsupdated') { // See bug MDL-6791
echo $PAGE->requires->js_function_call('insert_redirect')->asap();;
}
echo $PAGE->requires->js_function_call('parent.input.enableForm')->asap();
if ($chatuser->version == 'header_js') {
/// force msg referesh ASAP
echo $PAGE->requires->js('mod/chat/gui_header_js/chat_gui_header.js')->asap();
if ($CFG->chat_normal_updatemode != 'jsupdated') { // See bug MDL-6791
echo $PAGE->requires->js_function_call('insert_redirect')->asap();;
}
echo $PAGE->requires->js_function_call('parent.input.enableForm')->asap();
}
redirect('../empty.php');
?>
redirect('../empty.php');

View File

@ -1,86 +1,96 @@
<?php // $Id$
<?php
define('NO_MOODLE_COOKIES', true); // session not used here
define('NO_MOODLE_COOKIES', true); // session not used here
require('../../../config.php');
require('../lib.php');
require('../../../config.php');
require('../lib.php');
$chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
$chat_lasttime = optional_param('chat_lasttime', 0, PARAM_INT);
$chat_lastrow = optional_param('chat_lastrow', 1, PARAM_INT);
$chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
$chat_lasttime = optional_param('chat_lasttime', 0, PARAM_INT);
$chat_lastrow = optional_param('chat_lastrow', 1, PARAM_INT);
if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
print_error('notlogged', 'chat');
}
$url = new moodle_url($CFG->wwwroot.'/mod/chat/gui_header_js/jsupdate.php', array('chat_sid'=>$chat_sid));
if ($chat_lasttime !== 0) {
$url->param('chat_lasttime', $chat_lasttime);
}
if ($chat_lastrow !== 1) {
$url->param('chat_lastrow', $chat_lastrow);
}
$PAGE->set_url($url);
//Get the minimal course
if (!$course = $DB->get_record('course', array('id'=>$chatuser->course))) {
print_error('invalidcourseid');
}
//Get the user theme and enough info to be used in chat_format_message() which passes it along to
if (!$USER = $DB->get_record('user', array('id'=>$chatuser->userid))) { // no optimisation here, it would break again in future!
print_error('invaliduser');
}
$USER->description = '';
if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
print_error('notlogged', 'chat');
}
//Setup course, lang and theme
$PAGE->set_course($course);
//Get the minimal course
if (!$course = $DB->get_record('course', array('id'=>$chatuser->course))) {
print_error('invalidcourseid');
}
// force deleting of timed out users if there is a silence in room or just entering
if ((time() - $chat_lasttime) > $CFG->chat_old_ping) {
// must be done before chat_get_latest_message!!!
chat_delete_old_users();
}
//Get the user theme and enough info to be used in chat_format_message() which passes it along to
if (!$USER = $DB->get_record('user', array('id'=>$chatuser->userid))) { // no optimisation here, it would break again in future!
print_error('invaliduser');
}
$USER->description = '';
if ($message = chat_get_latest_message($chatuser->chatid, $chatuser->groupid)) {
$chat_newlasttime = $message->timestamp;
} else {
$chat_newlasttime = 0;
}
//Setup course, lang and theme
$PAGE->set_course($course);
if ($chat_lasttime == 0) { //display some previous messages
$chat_lasttime = time() - $CFG->chat_old_ping; //TO DO - any better value??
}
// force deleting of timed out users if there is a silence in room or just entering
if ((time() - $chat_lasttime) > $CFG->chat_old_ping) {
// must be done before chat_get_latest_message!!!
chat_delete_old_users();
}
$timenow = time();
if ($message = chat_get_latest_message($chatuser->chatid, $chatuser->groupid)) {
$chat_newlasttime = $message->timestamp;
} else {
$chat_newlasttime = 0;
}
$params = array('groupid'=>$chatuser->groupid, 'chatid'=>$chatuser->chatid, 'lasttime'=>$chat_lasttime);
if ($chat_lasttime == 0) { //display some previous messages
$chat_lasttime = time() - $CFG->chat_old_ping; //TO DO - any better value??
}
$groupselect = $chatuser->groupid ? " AND (groupid=:groupid OR groupid=0) " : "";
$timenow = time();
$messages = $DB->get_records_select("chat_messages_current",
"chatid = :chatid AND timestamp > :lasttime $groupselect", $params,
"timestamp ASC");
$params = array('groupid'=>$chatuser->groupid, 'chatid'=>$chatuser->chatid, 'lasttime'=>$chat_lasttime);
if ($messages) {
$num = count($messages);
} else {
$num = 0;
}
$groupselect = $chatuser->groupid ? " AND (groupid=:groupid OR groupid=0) " : "";
$chat_newrow = ($chat_lastrow + $num) % 2;
$messages = $DB->get_records_select("chat_messages_current",
"chatid = :chatid AND timestamp > :lasttime $groupselect", $params,
"timestamp ASC");
// no &amp; in url, does not work in header!
$refreshurl = "{$CFG->wwwroot}/mod/chat/gui_header_js/jsupdate.php?chat_sid=$chat_sid&chat_lasttime=$chat_newlasttime&chat_lastrow=$chat_newrow";
$refreshurlamp = "{$CFG->wwwroot}/mod/chat/gui_header_js/jsupdate.php?chat_sid=$chat_sid&amp;chat_lasttime=$chat_newlasttime&amp;chat_lastrow=$chat_newrow";
if ($messages) {
$num = count($messages);
} else {
$num = 0;
}
header('Expires: Sun, 28 Dec 1997 09:32:45 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
header('Content-Type: text/html; charset=utf-8');
header("Refresh: $CFG->chat_refresh_room; url=$refreshurl");
$chat_newrow = ($chat_lastrow + $num) % 2;
/// required stylesheets
$stylesheetshtml = '';
foreach ($CFG->stylesheets as $stylesheet) {
$stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'" />';
}
// no &amp; in url, does not work in header!
$refreshurl = "{$CFG->wwwroot}/mod/chat/gui_header_js/jsupdate.php?chat_sid=$chat_sid&chat_lasttime=$chat_newlasttime&chat_lastrow=$chat_newrow";
$refreshurlamp = "{$CFG->wwwroot}/mod/chat/gui_header_js/jsupdate.php?chat_sid=$chat_sid&amp;chat_lasttime=$chat_newlasttime&amp;chat_lastrow=$chat_newrow";
// use ob to be able to send Content-Length headers
// needed for Keep-Alive to work
ob_start();
header('Expires: Sun, 28 Dec 1997 09:32:45 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
header('Content-Type: text/html; charset=utf-8');
header("Refresh: $CFG->chat_refresh_room; url=$refreshurl");
/// required stylesheets
$stylesheetshtml = '';
foreach ($CFG->stylesheets as $stylesheet) {
$stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'" />';
}
// use ob to be able to send Content-Length headers
// needed for Keep-Alive to work
ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

View File

@ -1,4 +1,4 @@
<?php // $Id$
<?php
/** jsupdated.php - notes by Martin Langhoff <martin@catalyst.net.nz>
**
@ -16,60 +16,72 @@
**/
define('CHAT_MAX_CLIENT_UPDATES', 1000);
define('NO_MOODLE_COOKIES', true); // session not used here
define('CHAT_MAX_CLIENT_UPDATES', 1000);
define('NO_MOODLE_COOKIES', true); // session not used here
require('../../../config.php');
require('../lib.php');
require('../../../config.php');
require('../lib.php');
// we are going to run for a long time
// avoid being terminated by php
@set_time_limit(0);
// we are going to run for a long time
// avoid being terminated by php
@set_time_limit(0);
$chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
$chat_lasttime = optional_param('chat_lasttime', 0, PARAM_INT);
$chat_lastrow = optional_param('chat_lastrow', 1, PARAM_INT);
$chat_lastid = optional_param('chat_lastid', 0, PARAM_INT);
$chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
$chat_lasttime = optional_param('chat_lasttime', 0, PARAM_INT);
$chat_lastrow = optional_param('chat_lastrow', 1, PARAM_INT);
$chat_lastid = optional_param('chat_lastid', 0, PARAM_INT);
if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
print_error('notlogged', 'chat');
}
$url = new moodle_url($CFG->wwwroot.'/mod/chat/gui_header_js/jsupdated.php', array('chat_sid'=>$chat_sid));
if ($chat_lasttime !== 0) {
$url->param('chat_lasttime', $chat_lasttime);
}
if ($chat_lastrow !== 1) {
$url->param('chat_lastrow', $chat_lastrow);
}
if ($chat_lastid !== 1) {
$url->param('chat_lastid', $chat_lastid);
}
$PAGE->set_url($url);
//Get the minimal course
if (!$course = $DB->get_record('course', array('id'=>$chatuser->course))) {
print_error('invalidcourseid');
}
if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
print_error('notlogged', 'chat');
}
//Get the user theme and enough info to be used in chat_format_message() which passes it along to
// chat_format_message_manually() -- and only id and timezone are used.
if (!$USER = $DB->get_record('user', array('id'=>$chatuser->userid))) { // no optimisation here, it would break again in future!
print_error('invaliduser');
}
$USER->description = '';
//Get the minimal course
if (!$course = $DB->get_record('course', array('id'=>$chatuser->course))) {
print_error('invalidcourseid');
}
//Setup course, lang and theme
$PAGE->set_course($course);
//Get the user theme and enough info to be used in chat_format_message() which passes it along to
// chat_format_message_manually() -- and only id and timezone are used.
if (!$USER = $DB->get_record('user', array('id'=>$chatuser->userid))) { // no optimisation here, it would break again in future!
print_error('invaliduser');
}
$USER->description = '';
// force deleting of timed out users if there is a silence in room or just entering
if ((time() - $chat_lasttime) > $CFG->chat_old_ping) {
// must be done before chat_get_latest_message!!!
chat_delete_old_users();
}
//Setup course, lang and theme
$PAGE->set_course($course);
//
// Time to send headers, and lay out the basic JS updater page
//
header('Expires: Sun, 28 Dec 1997 09:32:45 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
header('Content-Type: text/html; charset=utf-8');
// force deleting of timed out users if there is a silence in room or just entering
if ((time() - $chat_lasttime) > $CFG->chat_old_ping) {
// must be done before chat_get_latest_message!!!
chat_delete_old_users();
}
/// required stylesheets
$stylesheetshtml = '';
foreach ($CFG->stylesheets as $stylesheet) {
$stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'" />';
}
//
// Time to send headers, and lay out the basic JS updater page
//
header('Expires: Sun, 28 Dec 1997 09:32:45 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
header('Content-Type: text/html; charset=utf-8');
/// required stylesheets
$stylesheetshtml = '';
foreach ($CFG->stylesheets as $stylesheet) {
$stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'" />';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

View File

@ -1,126 +1,127 @@
<?php // $Id$
<?php
define('NO_MOODLE_COOKIES', true); // session not used here
define('NO_MOODLE_COOKIES', true); // session not used here
require('../../../config.php');
require('../lib.php');
require('../../../config.php');
require('../lib.php');
$chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
$beep = optional_param('beep', 0, PARAM_INT); // beep target
$chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
$beep = optional_param('beep', 0, PARAM_INT); // beep target
if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
print_error('notlogged', 'chat');
}
$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/chat/gui_header_js/users.php', array('chat_sid'=>$chat_sid)));
//Get the minimal course
if (!$course = $DB->get_record('course', array('id'=>$chatuser->course))) {
print_error('invalidcourseid');
}
if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
print_error('notlogged', 'chat');
}
//Get the user theme and enough info to be used in chat_format_message() which passes it along to
if (!$USER = $DB->get_record('user', array('id'=>$chatuser->userid))) { // no optimisation here, it would break again in future!
print_error('invaliduser');
}
//Get the minimal course
if (!$course = $DB->get_record('course', array('id'=>$chatuser->course))) {
print_error('invalidcourseid');
}
$PAGE->set_generaltype('embedded');
//Get the user theme and enough info to be used in chat_format_message() which passes it along to
if (!$USER = $DB->get_record('user', array('id'=>$chatuser->userid))) { // no optimisation here, it would break again in future!
print_error('invaliduser');
}
$USER->description = '';
$PAGE->set_generaltype('embedded');
//Setup course, lang and theme
$PAGE->set_course($course);
$USER->description = '';
$courseid = $chatuser->course;
//Setup course, lang and theme
$PAGE->set_course($course);
if (!$cm = get_coursemodule_from_instance('chat', $chatuser->chatid, $courseid)) {
print_error('invalidcoursemodule');
}
$courseid = $chatuser->course;
if ($beep) {
$message->chatid = $chatuser->chatid;
$message->userid = $chatuser->userid;
$message->groupid = $chatuser->groupid;
$message->message = "beep $beep";
$message->system = 0;
$message->timestamp = time();
if (!$cm = get_coursemodule_from_instance('chat', $chatuser->chatid, $courseid)) {
print_error('invalidcoursemodule');
}
$DB->insert_record('chat_messages', $message);
$DB->insert_record('chat_messages_current', $message);
if ($beep) {
$message->chatid = $chatuser->chatid;
$message->userid = $chatuser->userid;
$message->groupid = $chatuser->groupid;
$message->message = "beep $beep";
$message->system = 0;
$message->timestamp = time();
$chatuser->lastmessageping = time(); // A beep is a ping ;-)
}
$DB->insert_record('chat_messages', $message);
$DB->insert_record('chat_messages_current', $message);
$chatuser->lastping = time();
$DB->set_field('chat_users', 'lastping', $chatuser->lastping, array('id'=>$chatuser->id));
$chatuser->lastmessageping = time(); // A beep is a ping ;-)
}
$refreshurl = "users.php?chat_sid=$chat_sid";
$chatuser->lastping = time();
$DB->set_field('chat_users', 'lastping', $chatuser->lastping, array('id'=>$chatuser->id));
/// Get list of users
$refreshurl = "users.php?chat_sid=$chat_sid";
if (!$chatusers = chat_get_users($chatuser->chatid, $chatuser->groupid, $cm->groupingid)) {
print_error('errornousers', 'chat');
}
/// Get list of users
$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();
$PAGE->requires->js_function_call('start')->on_dom_ready();
ob_start();
echo $OUTPUT->header();
if (!$chatusers = chat_get_users($chatuser->chatid, $chatuser->groupid, $cm->groupingid)) {
print_error('errornousers', 'chat');
}
/// Print user panel body
$timenow = time();
$stridle = get_string('idle', 'chat');
$strbeep = get_string('beep', '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();
$PAGE->requires->js_function_call('start')->on_dom_ready();
ob_start();
echo $OUTPUT->header();
/// Print user panel body
$timenow = time();
$stridle = get_string('idle', 'chat');
$strbeep = get_string('beep', 'chat');
echo '<div style="display: none"><a href="'.$refreshurl.'" id="refreshLink">Refresh link</a></div>';
echo '<table width="100%">';
foreach ($chatusers as $chatuser) {
$lastping = $timenow - $chatuser->lastmessageping;
$min = (int) ($lastping/60);
$sec = $lastping - ($min*60);
$min = $min < 10 ? '0'.$min : $min;
$sec = $sec < 10 ? '0'.$sec : $sec;
$idle = $min.':'.$sec;
echo '<tr><td width="35">';
echo "<a target=\"_blank\" onClick=\"return openpopup('/user/view.php?id=$chatuser->id&amp;course=$courseid','user$chatuser->id','');\" href=\"$CFG->wwwroot/user/view.php?id=$chatuser->id&amp;course=$courseid\">";
echo $OUTPUT->user_picture(moodle_user_picture::make($chatuser, $courseid));
echo '</a></td><td valign="center">';
echo '<p><font size="1">';
echo fullname($chatuser).'<br />';
echo "<span class=\"dimmed_text\">$stridle <span name=\"uidles\" id=\"uidle{$chatuser->id}\">$idle</span></span>";
echo " <a href=\"users.php?chat_sid=$chat_sid&amp;beep=$chatuser->id\">$strbeep</a>";
echo '</font></p>';
echo '</td></tr>';
}
// added 2 </div>s, xhtml strict complaints
echo '</table>';
echo $OUTPUT->footer();
echo '<div style="display: none"><a href="'.$refreshurl.'" id="refreshLink">Refresh link</a></div>';
echo '<table width="100%">';
foreach ($chatusers as $chatuser) {
$lastping = $timenow - $chatuser->lastmessageping;
$min = (int) ($lastping/60);
$sec = $lastping - ($min*60);
$min = $min < 10 ? '0'.$min : $min;
$sec = $sec < 10 ? '0'.$sec : $sec;
$idle = $min.':'.$sec;
echo '<tr><td width="35">';
echo "<a target=\"_blank\" onClick=\"return openpopup('/user/view.php?id=$chatuser->id&amp;course=$courseid','user$chatuser->id','');\" href=\"$CFG->wwwroot/user/view.php?id=$chatuser->id&amp;course=$courseid\">";
echo $OUTPUT->user_picture(moodle_user_picture::make($chatuser, $courseid));
echo '</a></td><td valign="center">';
echo '<p><font size="1">';
echo fullname($chatuser).'<br />';
echo "<span class=\"dimmed_text\">$stridle <span name=\"uidles\" id=\"uidle{$chatuser->id}\">$idle</span></span>";
echo " <a href=\"users.php?chat_sid=$chat_sid&amp;beep=$chatuser->id\">$strbeep</a>";
echo '</font></p>';
echo '</td></tr>';
}
// added 2 </div>s, xhtml strict complaints
echo '</table>';
echo $OUTPUT->footer();
//
// Support HTTP Keep-Alive by printing Content-Length
//
// If the user pane is refreshing often, using keepalives
// is lighter on the server and faster for most clients.
//
// Apache is normally configured to have a 15s timeout on
// keepalives, so let's observe that. Unfortunately, we cannot
// autodetect the keepalive timeout.
//
// Using keepalives when the refresh is longer than the timeout
// wastes server resources keeping an apache child around on a
// connection that will timeout. So we don't.
if ($CFG->chat_refresh_userlist < 15) {
header("Content-Length: " . ob_get_length() );
ob_end_flush();
}
//
// Support HTTP Keep-Alive by printing Content-Length
//
// If the user pane is refreshing often, using keepalives
// is lighter on the server and faster for most clients.
//
// Apache is normally configured to have a 15s timeout on
// keepalives, so let's observe that. Unfortunately, we cannot
// autodetect the keepalive timeout.
//
// Using keepalives when the refresh is longer than the timeout
// wastes server resources keeping an apache child around on a
// connection that will timeout. So we don't.
if ($CFG->chat_refresh_userlist < 15) {
header("Content-Length: " . ob_get_length() );
ob_end_flush();
}
exit; // no further output
exit; // no further output
?>
?>

View File

@ -1,26 +1,28 @@
<?php // $Id$
<?php
define('NO_MOODLE_COOKIES', true); // session not used here
define('NO_MOODLE_COOKIES', true); // session not used here
require('../../../config.php');
require('../lib.php');
require('../../../config.php');
require('../lib.php');
$chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
$chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
print_error('notlogged', 'chat');
}
$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/chat/gui_sockets/chatinput.php', array('chat_sid'=>$chat_sid)));
//Get the user theme
$USER = $DB->get_record('user', array('id'=>$chatuser->userid));
if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
print_error('notlogged', 'chat');
}
//Setup course, lang and theme
$PAGE->set_course($DB->get_record('course', array('id' => $chatuser->course)));
$PAGE->requires->js('mod/chat/gui_sockets/chat_gui_sockets.js')->in_head();
$PAGE->requires->js_function_call('setfocus');
$PAGE->set_focuscontrol('chat_message');
$PAGE->set_cacheable(false);
echo $OUTPUT->header();
//Get the user theme
$USER = $DB->get_record('user', array('id'=>$chatuser->userid));
//Setup course, lang and theme
$PAGE->set_course($DB->get_record('course', array('id' => $chatuser->course)));
$PAGE->requires->js('mod/chat/gui_sockets/chat_gui_sockets.js')->in_head();
$PAGE->requires->js_function_call('setfocus');
$PAGE->set_focuscontrol('chat_message');
$PAGE->set_cacheable(false);
echo $OUTPUT->header();
?>

View File

@ -1,60 +1,64 @@
<?php // $Id$
<?php
require_once('../../../config.php');
require_once('../lib.php');
require_once('../../../config.php');
require_once('../lib.php');
$id = required_param('id', PARAM_INT);
$groupid = optional_param('groupid', 0, PARAM_INT); //only for teachers
$id = required_param('id', PARAM_INT);
$groupid = optional_param('groupid', 0, PARAM_INT); //only for teachers
if (!$chat = $DB->get_record('chat', array('id'=>$id))) {
print_error('invalidid', 'chat');
}
$url = new moodle_url($CFG->wwwroot.'/mod/chat/gui_sockets/index.php', array('id'=>$id));
if ($groupid !== 0) {
$url->param('groupid', $groupid);
}
$PAGE->set_url($url);
if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
print_error('invalidcourseid');
}
if (!$chat = $DB->get_record('chat', array('id'=>$id))) {
print_error('invalidid', 'chat');
}
if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
print_error('invalidcoursemodule');
}
if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
print_error('invalidcourseid');
}
require_login($course->id, false, $cm);
if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
print_error('invalidcoursemodule');
}
if (isguest()) {
print_error('noguests', 'chat');
}
require_login($course->id, false, $cm);
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id))) {
echo $OUTPUT->header();
notice(get_string("activityiscurrentlyhidden"));
}
if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) {
print_error('noguests', 'chat');
}
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id))) {
echo $OUTPUT->header();
notice(get_string("activityiscurrentlyhidden"));
}
/// Check to see if groups are being used here
if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used
if ($groupid = groups_get_activity_group($cm)) {
if (!$group = groups_get_group($groupid, false)) {
print_error('invalidgroupid');
}
$groupname = ': '.$group->name;
} else {
$groupname = ': '.get_string('allparticipants');
if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used
if ($groupid = groups_get_activity_group($cm)) {
if (!$group = groups_get_group($groupid, false)) {
print_error('invalidgroupid');
}
$groupname = ': '.$group->name;
} else {
$groupid = 0;
$groupname = '';
$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!!!
$strchat = get_string('modulename', 'chat'); // must be before current_language() in chat_login_user() to force course language!!!
if (!$chat_sid = chat_login_user($chat->id, 'sockets', $groupid, $course)) {
print_error('cantlogin');
}
if (!$chat_sid = chat_login_user($chat->id, 'sockets', $groupid, $course)) {
print_error('cantlogin');
}
$params = "chat_sid=$chat_sid";
$params = "chat_sid=$chat_sid";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />

View File

@ -1,89 +1,91 @@
<?php // $Id$
<?php
require_once('../../config.php');
require_once('lib.php');
require_once('../../config.php');
require_once('lib.php');
$id = required_param('id', PARAM_INT); // course
$id = required_param('id', PARAM_INT); // course
if (! $course = $DB->get_record('course', array('id'=>$id))) {
print_error('invalidcourseid');
}
$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/chat/index.php', array('id'=>$id)));
require_course_login($course);
if (! $course = $DB->get_record('course', array('id'=>$id))) {
print_error('invalidcourseid');
}
add_to_log($course->id, 'chat', 'view all', "index.php?id=$course->id", '');
require_course_login($course);
add_to_log($course->id, 'chat', 'view all', "index.php?id=$course->id", '');
/// Get all required strings
$strchats = get_string('modulenameplural', 'chat');
$strchat = get_string('modulename', 'chat');
$strchats = get_string('modulenameplural', 'chat');
$strchat = get_string('modulename', 'chat');
/// Print the header
$PAGE->navbar->add($strchats);
$PAGE->set_title($strchats);
echo $OUTPUT->header();
$PAGE->navbar->add($strchats);
$PAGE->set_title($strchats);
echo $OUTPUT->header();
/// Get all the appropriate data
if (! $chats = get_all_instances_in_course('chat', $course)) {
notice(get_string('thereareno', 'moodle', $strchats), "../../course/view.php?id=$course->id");
die();
}
if (! $chats = get_all_instances_in_course('chat', $course)) {
notice(get_string('thereareno', 'moodle', $strchats), "../../course/view.php?id=$course->id");
die();
}
/// Print the list of instances (your module will probably extend this)
$timenow = time();
$strname = get_string('name');
$strweek = get_string('week');
$strtopic = get_string('topic');
$timenow = time();
$strname = get_string('name');
$strweek = get_string('week');
$strtopic = get_string('topic');
$table = new html_table();
$table = new html_table();
if ($course->format == 'weeks') {
$table->head = array ($strweek, $strname);
$table->align = array ('center', 'left');
} else if ($course->format == 'topics') {
$table->head = array ($strtopic, $strname);
$table->align = array ('center', 'left', 'left', 'left');
if ($course->format == 'weeks') {
$table->head = array ($strweek, $strname);
$table->align = array ('center', 'left');
} else if ($course->format == 'topics') {
$table->head = array ($strtopic, $strname);
$table->align = array ('center', 'left', 'left', 'left');
} else {
$table->head = array ($strname);
$table->align = array ('left', 'left', 'left');
}
$currentsection = '';
foreach ($chats as $chat) {
if (!$chat->visible) {
//Show dimmed if the mod is hidden
$link = "<a class=\"dimmed\" href=\"view.php?id=$chat->coursemodule\">".format_string($chat->name,true)."</a>";
} else {
$table->head = array ($strname);
$table->align = array ('left', 'left', 'left');
//Show normal if the mod is visible
$link = "<a href=\"view.php?id=$chat->coursemodule\">".format_string($chat->name,true)."</a>";
}
$currentsection = '';
foreach ($chats as $chat) {
if (!$chat->visible) {
//Show dimmed if the mod is hidden
$link = "<a class=\"dimmed\" href=\"view.php?id=$chat->coursemodule\">".format_string($chat->name,true)."</a>";
} else {
//Show normal if the mod is visible
$link = "<a href=\"view.php?id=$chat->coursemodule\">".format_string($chat->name,true)."</a>";
$printsection = '';
if ($chat->section !== $currentsection) {
if ($chat->section) {
$printsection = $chat->section;
}
$printsection = '';
if ($chat->section !== $currentsection) {
if ($chat->section) {
$printsection = $chat->section;
}
if ($currentsection !== '') {
$table->data[] = 'hr';
}
$currentsection = $chat->section;
}
if ($course->format == 'weeks' or $course->format == 'topics') {
$table->data[] = array ($printsection, $link);
} else {
$table->data[] = array ($link);
if ($currentsection !== '') {
$table->data[] = 'hr';
}
$currentsection = $chat->section;
}
if ($course->format == 'weeks' or $course->format == 'topics') {
$table->data[] = array ($printsection, $link);
} else {
$table->data[] = array ($link);
}
}
echo '<br />';
echo '<br />';
echo $OUTPUT->table($table);
echo $OUTPUT->table($table);
/// Finish the page
echo $OUTPUT->footer();
echo $OUTPUT->footer();
?>

View File

@ -1,4 +1,4 @@
<?php // $Id$
<?php
/// This page prints reports and info about chats
@ -11,6 +11,21 @@
$deletesession = optional_param('deletesession', 0, PARAM_BOOL);
$confirmdelete = optional_param('confirmdelete', 0, PARAM_BOOL);
$url = new moodle_url($CFG->wwwroot.'/mod/chat/report.php', array('id'=>$id));
if ($start !== 0) {
$url->param('start', $start);
}
if ($end !== 0) {
$url->param('end', $end);
}
if ($deletesession !== 0) {
$url->param('deletesession', $deletesession);
}
if ($confirmdelete !== 0) {
$url->param('confirmdelete', $confirmdelete);
}
$PAGE->set_url($url);
if (! $cm = get_coursemodule_from_id('chat', $id)) {
print_error('invalidcoursemodule');
}