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 '
'; +echo '

'.get_string('participants').'

'; +echo '
'; +echo '
'; +echo '
'; - echo '
'; - echo '

'.get_string('messages', 'chat').'

'; +$usehtmleditor = can_use_html_editor(); +echo '

'; +echo '
'; +echo ''; +echo '
'; +echo ''; +echo ''; +echo ''; +echo ''; +echo ' '; +echo ''; +echo ''; +echo '
'; +echo ''; +echo '
'; - $allmessages = array(); - $options = new object(); - $options->para = false; - $options->newlines = true; +echo '
'; +echo '

'.get_string('messages', 'chat').'

'; - $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 '
'; +echo $OUTPUT->footer(); - echo '
'; - - echo $OUTPUT->footer(); - - - -?> +?> \ No newline at end of file diff --git a/mod/chat/gui_header_js/chatinput.php b/mod/chat/gui_header_js/chatinput.php index 45117f2d11b..d7d85d85c82 100644 --- a/mod/chat/gui_header_js/chatinput.php +++ b/mod/chat/gui_header_js/chatinput.php @@ -1,42 +1,42 @@ -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(); ?>
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; - } ?> diff --git a/mod/chat/gui_header_js/insert.php b/mod/chat/gui_header_js/insert.php index d92a45f3d60..b7b1380f80a 100644 --- a/mod/chat/gui_header_js/insert.php +++ b/mod/chat/gui_header_js/insert.php @@ -1,73 +1,74 @@ -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'); \ No newline at end of file diff --git a/mod/chat/gui_header_js/jsupdate.php b/mod/chat/gui_header_js/jsupdate.php index e26bb124014..f10b33a5e18 100644 --- a/mod/chat/gui_header_js/jsupdate.php +++ b/mod/chat/gui_header_js/jsupdate.php @@ -1,86 +1,96 @@ -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 & 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&chat_lasttime=$chat_newlasttime&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 .= ''; - } +// no & 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&chat_lasttime=$chat_newlasttime&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 .= ''; +} + +// use ob to be able to send Content-Length headers +// needed for Keep-Alive to work +ob_start(); ?> diff --git a/mod/chat/gui_header_js/jsupdated.php b/mod/chat/gui_header_js/jsupdated.php index 6e198cf16fc..f8e251d38cf 100644 --- a/mod/chat/gui_header_js/jsupdated.php +++ b/mod/chat/gui_header_js/jsupdated.php @@ -1,4 +1,4 @@ - ** @@ -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 .= ''; - } +// +// 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 .= ''; +} ?> diff --git a/mod/chat/gui_header_js/users.php b/mod/chat/gui_header_js/users.php index 746ab7c0d7d..0485c8d1c97 100644 --- a/mod/chat/gui_header_js/users.php +++ b/mod/chat/gui_header_js/users.php @@ -1,126 +1,127 @@ -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 '
Refresh link
'; - echo ''; - 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 ''; - } - // added 2 s, xhtml strict complaints - echo '
'; - echo "id&course=$courseid','user$chatuser->id','');\" href=\"$CFG->wwwroot/user/view.php?id=$chatuser->id&course=$courseid\">"; - echo $OUTPUT->user_picture(moodle_user_picture::make($chatuser, $courseid)); - echo ''; - echo '

'; - echo fullname($chatuser).'
'; - echo "$stridle id}\">$idle"; - echo " id\">$strbeep"; - echo '

'; - echo '
'; - echo $OUTPUT->footer(); +echo '
Refresh link
'; +echo ''; +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 ''; +} +// added 2 s, xhtml strict complaints +echo '
'; + echo "id&course=$courseid','user$chatuser->id','');\" href=\"$CFG->wwwroot/user/view.php?id=$chatuser->id&course=$courseid\">"; + echo $OUTPUT->user_picture(moodle_user_picture::make($chatuser, $courseid)); + echo ''; + echo '

'; + echo fullname($chatuser).'
'; + echo "$stridle id}\">$idle"; + echo " id\">$strbeep"; + echo '

'; + echo '
'; +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 - -?> +?> \ No newline at end of file diff --git a/mod/chat/gui_sockets/chatinput.php b/mod/chat/gui_sockets/chatinput.php index 2fb5f38829a..cdb1f9421bd 100644 --- a/mod/chat/gui_sockets/chatinput.php +++ b/mod/chat/gui_sockets/chatinput.php @@ -1,26 +1,28 @@ -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(); ?> diff --git a/mod/chat/gui_sockets/index.php b/mod/chat/gui_sockets/index.php index 37be772fdc6..07435f9d09f 100644 --- a/mod/chat/gui_sockets/index.php +++ b/mod/chat/gui_sockets/index.php @@ -1,60 +1,64 @@ -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"; -?> - - +?> diff --git a/mod/chat/index.php b/mod/chat/index.php index b3f12f42d6e..44e52f438ef 100644 --- a/mod/chat/index.php +++ b/mod/chat/index.php @@ -1,89 +1,91 @@ -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 = "coursemodule\">".format_string($chat->name,true).""; } else { - $table->head = array ($strname); - $table->align = array ('left', 'left', 'left'); + //Show normal if the mod is visible + $link = "coursemodule\">".format_string($chat->name,true).""; } - - $currentsection = ''; - foreach ($chats as $chat) { - if (!$chat->visible) { - //Show dimmed if the mod is hidden - $link = "coursemodule\">".format_string($chat->name,true).""; - } else { - //Show normal if the mod is visible - $link = "coursemodule\">".format_string($chat->name,true).""; + $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 '
'; +echo '
'; - echo $OUTPUT->table($table); +echo $OUTPUT->table($table); /// Finish the page - echo $OUTPUT->footer(); +echo $OUTPUT->footer(); ?> diff --git a/mod/chat/report.php b/mod/chat/report.php index c25382e5979..b830c862773 100644 --- a/mod/chat/report.php +++ b/mod/chat/report.php @@ -1,4 +1,4 @@ -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'); }