From: samhemelryk Date: Wed, 23 Sep 2009 07:08:43 +0000 (+0000) Subject: mod-chat MDL-19804 Added PAGE->set_url calls and removed deprecated functions X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=eb588b22abc73ef144ede93ac658229f24de1c32;p=moodle.git mod-chat MDL-19804 Added PAGE->set_url calls and removed deprecated functions --- diff --git a/mod/chat/chat_ajax.php b/mod/chat/chat_ajax.php index 0daa6f6e3a..6af584f6a0 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 dfedd59d74..83987ece14 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 c0b3ca3a41..c2d6649d1f 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'); - } - - if (!$course = $DB->get_record('course', array('id'=>$chat->course))) { - print_error('invalidcourseid'); - } - - 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'); +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 (!$chat = $DB->get_record('chat', array('id'=>$id))) { + print_error('invalidid', 'chat'); +} + +if (!$course = $DB->get_record('course', array('id'=>$chat->course))) { + print_error('invalidcourseid'); +} + +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'); } - - $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'); +} 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); } - $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.'&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 '
    '; - foreach($chatusers as $chu) { - echo '
  • '; - $userpic = moodle_user_picture::make($chu->id, $course->id); - $userpic->size = 24; - echo $OUTPUT->user_picture($userpic); - echo '
    '; - echo fullname($chu).' '; - if ($idle = time() - $chu->lastmessageping) { - echo ''.$stridle.' '.format_time($idle).''; - } else { - echo ''; - } - echo '
    '; - echo '
  • '; - } - echo '
'; - echo '
'; - echo '
'; - - $usehtmleditor = can_use_html_editor(); - echo '

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

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

'; - - $allmessages = array(); - $options = new object(); - $options->para = false; - $options->newlines = true; - - $params = array('last'=>$last, 'groupid'=>$groupid, 'chatid'=>$chat->id, 'chatentered'=>$chatentered); - - if ($newonly) { - $lastsql = "AND timestamp > :last"; + 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 '
    '; +foreach($chatusers as $chu) { + echo '
  • '; + $userpic = moodle_user_picture::make($chu->id, $course->id); + $userpic->size = 24; + echo $OUTPUT->user_picture($userpic); + echo '
    '; + echo fullname($chu).' '; + if ($idle = time() - $chu->lastmessageping) { + echo ''.$stridle.' '.format_time($idle).''; } else { - $lastsql = ""; + echo ''; } - - $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); - } + echo '
    '; + echo '
  • '; +} +echo '
'; +echo '
'; +echo '
'; + +$usehtmleditor = can_use_html_editor(); +echo '

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

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

'; + +$allmessages = array(); +$options = new object(); +$options->para = false; +$options->newlines = true; + +$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); } +} - 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 45117f2d11..d7d85d85c8 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 d92a45f3d6..b7b1380f80 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); + +if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) { + print_error('noguests'); +} - session_get_instance()->write_close(); +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 e26bb12401..f10b33a5e1 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'); - } - - //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 = ''; - - //Setup course, lang and theme - $PAGE->set_course($course); - - // 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(); - } - - if ($message = chat_get_latest_message($chatuser->chatid, $chatuser->groupid)) { - $chat_newlasttime = $message->timestamp; - } else { - $chat_newlasttime = 0; - } - - if ($chat_lasttime == 0) { //display some previous messages - $chat_lasttime = time() - $CFG->chat_old_ping; //TO DO - any better value?? - } - - $timenow = time(); - - $params = array('groupid'=>$chatuser->groupid, 'chatid'=>$chatuser->chatid, 'lasttime'=>$chat_lasttime); - - $groupselect = $chatuser->groupid ? " AND (groupid=:groupid OR groupid=0) " : ""; - - $messages = $DB->get_records_select("chat_messages_current", - "chatid = :chatid AND timestamp > :lasttime $groupselect", $params, - "timestamp ASC"); - - if ($messages) { - $num = count($messages); - } else { - $num = 0; - } - - $chat_newrow = ($chat_lastrow + $num) % 2; - - // 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"; - - 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 .= ''; - } +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); + + +if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) { + print_error('notlogged', 'chat'); +} + +//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 = ''; + +//Setup course, lang and theme +$PAGE->set_course($course); + +// 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(); +} + +if ($message = chat_get_latest_message($chatuser->chatid, $chatuser->groupid)) { + $chat_newlasttime = $message->timestamp; +} else { + $chat_newlasttime = 0; +} + +if ($chat_lasttime == 0) { //display some previous messages + $chat_lasttime = time() - $CFG->chat_old_ping; //TO DO - any better value?? +} + +$timenow = time(); + +$params = array('groupid'=>$chatuser->groupid, 'chatid'=>$chatuser->chatid, 'lasttime'=>$chat_lasttime); + +$groupselect = $chatuser->groupid ? " AND (groupid=:groupid OR groupid=0) " : ""; + +$messages = $DB->get_records_select("chat_messages_current", + "chatid = :chatid AND timestamp > :lasttime $groupselect", $params, + "timestamp ASC"); + +if ($messages) { + $num = count($messages); +} else { + $num = 0; +} + +$chat_newrow = ($chat_lastrow + $num) % 2; + +// 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"; + +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 6e198cf16f..f8e251d38c 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 - - require('../../../config.php'); - require('../lib.php'); - - // 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); - - if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) { - print_error('notlogged', 'chat'); - } - - //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 - // 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 = ''; - - //Setup course, lang and theme - $PAGE->set_course($course); - - // 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(); - } - - // - // 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 .= ''; - } +define('CHAT_MAX_CLIENT_UPDATES', 1000); +define('NO_MOODLE_COOKIES', true); // session not used here + +require('../../../config.php'); +require('../lib.php'); + +// 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); + +$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); + +if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) { + print_error('notlogged', 'chat'); +} + +//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 +// 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 = ''; + +//Setup course, lang and theme +$PAGE->set_course($course); + +// 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(); +} + +// +// 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 746ab7c0d7..0485c8d1c9 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'); - } - - //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'); - } - - $PAGE->set_generaltype('embedded'); - - $USER->description = ''; - - //Setup course, lang and theme - $PAGE->set_course($course); - - $courseid = $chatuser->course; - - if (!$cm = get_coursemodule_from_instance('chat', $chatuser->chatid, $courseid)) { - print_error('invalidcoursemodule'); - } - - if ($beep) { - $message->chatid = $chatuser->chatid; - $message->userid = $chatuser->userid; - $message->groupid = $chatuser->groupid; - $message->message = "beep $beep"; - $message->system = 0; - $message->timestamp = time(); - - $DB->insert_record('chat_messages', $message); - $DB->insert_record('chat_messages_current', $message); - - $chatuser->lastmessageping = time(); // A beep is a ping ;-) - } - - $chatuser->lastping = time(); - $DB->set_field('chat_users', 'lastping', $chatuser->lastping, array('id'=>$chatuser->id)); - - $refreshurl = "users.php?chat_sid=$chat_sid"; - - /// Get list of users - - if (!$chatusers = chat_get_users($chatuser->chatid, $chatuser->groupid, $cm->groupingid)) { - print_error('errornousers', 'chat'); - } - - $uidles = Array(); - $i = 0; - foreach ($chatusers as $chatuser) { - $uidles[$i] = 'uidle{$chatuser->id}'; - $i++; - } - $PAGE->requires->data_for_js('uidles', $uidles)->in_head(); - $PAGE->requires->js('mod/chat/gui_header_js/chat_gui_header.js')->in_head(); - $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(); - - // - // 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 - - -?> +set_url(new moodle_url($CFG->wwwroot.'/mod/chat/gui_header_js/users.php', array('chat_sid'=>$chat_sid))); + +if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) { + print_error('notlogged', 'chat'); +} + +//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'); +} + +$PAGE->set_generaltype('embedded'); + +$USER->description = ''; + +//Setup course, lang and theme +$PAGE->set_course($course); + +$courseid = $chatuser->course; + +if (!$cm = get_coursemodule_from_instance('chat', $chatuser->chatid, $courseid)) { + print_error('invalidcoursemodule'); +} + +if ($beep) { + $message->chatid = $chatuser->chatid; + $message->userid = $chatuser->userid; + $message->groupid = $chatuser->groupid; + $message->message = "beep $beep"; + $message->system = 0; + $message->timestamp = time(); + + $DB->insert_record('chat_messages', $message); + $DB->insert_record('chat_messages_current', $message); + + $chatuser->lastmessageping = time(); // A beep is a ping ;-) +} + +$chatuser->lastping = time(); +$DB->set_field('chat_users', 'lastping', $chatuser->lastping, array('id'=>$chatuser->id)); + +$refreshurl = "users.php?chat_sid=$chat_sid"; + +/// Get list of users + +if (!$chatusers = chat_get_users($chatuser->chatid, $chatuser->groupid, $cm->groupingid)) { + print_error('errornousers', 'chat'); +} + +$uidles = Array(); +$i = 0; +foreach ($chatusers as $chatuser) { + $uidles[$i] = 'uidle{$chatuser->id}'; + $i++; +} +$PAGE->requires->data_for_js('uidles', $uidles)->in_head(); +$PAGE->requires->js('mod/chat/gui_header_js/chat_gui_header.js')->in_head(); +$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(); + +// +// 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 + +?> \ No newline at end of file diff --git a/mod/chat/gui_sockets/chatinput.php b/mod/chat/gui_sockets/chatinput.php index 2fb5f38829..cdb1f9421b 100644 --- a/mod/chat/gui_sockets/chatinput.php +++ b/mod/chat/gui_sockets/chatinput.php @@ -1,26 +1,28 @@ -set_url(new moodle_url($CFG->wwwroot.'/mod/chat/gui_sockets/chatinput.php', array('chat_sid'=>$chat_sid))); - if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) { - print_error('notlogged', 'chat'); - } +if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) { + print_error('notlogged', 'chat'); +} - //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($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(); +//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 37be772fdc..07435f9d09 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!!! - - if (!$chat_sid = chat_login_user($chat->id, 'sockets', $groupid, $course)) { - print_error('cantlogin'); - } +$strchat = get_string('modulename', 'chat'); // must be before current_language() in chat_login_user() to force course language!!! - $params = "chat_sid=$chat_sid"; +if (!$chat_sid = chat_login_user($chat->id, 'sockets', $groupid, $course)) { + print_error('cantlogin'); +} -?> +$params = "chat_sid=$chat_sid"; - +?> diff --git a/mod/chat/index.php b/mod/chat/index.php index b3f12f42d6..44e52f438e 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))); + +if (! $course = $DB->get_record('course', array('id'=>$id))) { + print_error('invalidcourseid'); +} - require_course_login($course); +require_course_login($course); - add_to_log($course->id, 'chat', 'view all', "index.php?id=$course->id", ''); +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'); - - $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'); +$timenow = time(); +$strname = get_string('name'); +$strweek = get_string('week'); +$strtopic = get_string('topic'); + +$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'); +} 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; - } - if ($currentsection !== '') { - $table->data[] = 'hr'; - } - $currentsection = $chat->section; + $printsection = ''; + if ($chat->section !== $currentsection) { + if ($chat->section) { + $printsection = $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 c25382e597..b830c86277 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'); }