diff --git a/mod/chat/chat_ajax.php b/mod/chat/chat_ajax.php index 0daa6f6e3a4..6af584f6a04 100644 --- a/mod/chat/chat_ajax.php +++ b/mod/chat/chat_ajax.php @@ -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'); diff --git a/mod/chat/gui_ajax/index.php b/mod/chat/gui_ajax/index.php index dfedd59d74d..83987ece14a 100644 --- a/mod/chat/gui_ajax/index.php +++ b/mod/chat/gui_ajax/index.php @@ -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'); } diff --git a/mod/chat/gui_basic/index.php b/mod/chat/gui_basic/index.php index c0b3ca3a41e..c2d6649d1fb 100644 --- a/mod/chat/gui_basic/index.php +++ b/mod/chat/gui_basic/index.php @@ -1,181 +1,196 @@ -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.'&newonly='.$newonly.'&last='.$last); +} + +$PAGE->set_title("$strchat: $course->shortname: ".format_string($chat->name,true)."$groupname"); +$PAGE->set_focuscontrol('message'); +echo $OUTPUT->header(); +echo '