]> git.mjollnir.org Git - moodle.git/commitdiff
mod-chat MDL-19804 Added PAGE->set_url calls and removed deprecated functions
authorsamhemelryk <samhemelryk>
Wed, 23 Sep 2009 07:08:43 +0000 (07:08 +0000)
committersamhemelryk <samhemelryk>
Wed, 23 Sep 2009 07:08:43 +0000 (07:08 +0000)
13 files changed:
mod/chat/chat_ajax.php
mod/chat/gui_ajax/index.php
mod/chat/gui_basic/index.php
mod/chat/gui_header_js/chatinput.php
mod/chat/gui_header_js/index.php
mod/chat/gui_header_js/insert.php
mod/chat/gui_header_js/jsupdate.php
mod/chat/gui_header_js/jsupdated.php
mod/chat/gui_header_js/users.php
mod/chat/gui_sockets/chatinput.php
mod/chat/gui_sockets/index.php
mod/chat/index.php
mod/chat/report.php

index 0daa6f6e3a479c0c56ad33855e88b40a6258065d..6af584f6a04f31f296f71ca70af8d667997704d7 100644 (file)
@@ -37,12 +37,13 @@ if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
 if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
     chat_print_error('ERROR', get_string('invalidcoursemodule', 'error'));
 }
-if (isguest()) {
+if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) {
     chat_print_error('ERROR', get_string('notlogged','chat'));
 }
 
 // setup $PAGE so that format_text will work properly
 $PAGE->set_cm($cm, $course, $chat);
+$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/chat/chat_ajax.php', array('chat_sid'=>$chat_sid)));
 
 ob_start();
 header('Expires: Sun, 28 Dec 1997 09:32:45 GMT');
index dfedd59d74d58b8f9f2c8147a3c948c96d0e9ca2..83987ece14a18c0c6ec37232b47a541f5e9cb4ad 100644 (file)
@@ -3,6 +3,13 @@ require_once('../../../config.php');
 require_once('../lib.php');
 $id      = required_param('id', PARAM_INT);
 $groupid = optional_param('groupid', 0, PARAM_INT); //only for teachers
+
+$url = new moodle_url($CFG->wwwroot.'/mod/chat/gui_ajax/index.php', array('id'=>$id));
+if ($groupid !== 0) {
+    $url->param('groupid', $groupid);
+}
+$PAGE->set_url($url);
+
 if (!$chat = $DB->get_record('chat', array('id'=>$id))) {
     print_error('invalidid', 'chat');
 }
index c0b3ca3a41e3a005e1295553f63590f2e7fe50e0..c2d6649d1fb92302a93915a066b8f230b6b16600 100644 (file)
-<?php  // $Id$
-
-    require_once('../../../config.php');
-    require_once('../lib.php');
-
-    $id      = required_param('id', PARAM_INT);
-    $groupid = optional_param('groupid', 0, PARAM_INT);  // only for teachers
-    $message = optional_param('message', '', PARAM_CLEAN);
-    $refresh = optional_param('refresh', '', PARAM_RAW); // force refresh
-    $last    = optional_param('last', 0, PARAM_INT);     // last time refresh or sending
-    $newonly = optional_param('newonly', 0, PARAM_BOOL); // show only new messages
-
-    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');
+<?php
+
+require_once('../../../config.php');
+require_once('../lib.php');
+
+$id      = required_param('id', PARAM_INT);
+$groupid = optional_param('groupid', 0, PARAM_INT);  // only for teachers
+$message = optional_param('message', '', PARAM_CLEAN);
+$refresh = optional_param('refresh', '', PARAM_RAW); // force refresh
+$last    = optional_param('last', 0, PARAM_INT);     // last time refresh or sending
+$newonly = optional_param('newonly', 0, PARAM_BOOL); // show only new messages
+
+$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 (!$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.'&amp;newonly='.$newonly.'&amp;last='.$last);
-    }
-
-    $PAGE->set_title("$strchat: $course->shortname: ".format_string($chat->name,true)."$groupname");
-    $PAGE->set_focuscontrol('message');
-    echo $OUTPUT->header();
-    echo '<div id="mod-chat-gui_basic">';
-    echo '<h1>'.get_string('participants').'</h1>';
-    echo '<div id="participants"><ul>';
-    foreach($chatusers as $chu) {
-        echo '<li>';
-        $userpic = moodle_user_picture::make($chu->id, $course->id);
-        $userpic->size = 24;
-        echo $OUTPUT->user_picture($userpic);
-        echo '<div class="userinfo">';
-        echo fullname($chu).' ';
-        if ($idle = time() - $chu->lastmessageping) {
-            echo '<span class="idle">'.$stridle.' '.format_time($idle).'</span>';
-        } else {
-            echo '<span class="idle" />';
-        }
-        echo '</div>';
-        echo '</li>';
-    }
-    echo '</ul></div>';
-    echo '<div id="send">';
-    echo '<form id="editing" method="post" action="index.php">';
-
-    $usehtmleditor = can_use_html_editor();
-    echo '<h1><label for="message">'.get_string('sendmessage', 'message').'</label></h1>';
-    echo '<div>';
-    echo '<input type="text" id="message" name="message" value="'.s($refreshedmessage, true).'" size="60" />';
-    echo '</div><div>';
-    echo '<input type="hidden" name="id" value="'.$id.'" />';
-    echo '<input type="hidden" name="groupid" value="'.$groupid.'" />';
-    echo '<input type="hidden" name="last" value="'.time().'" />';
-    echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
-    echo '<input type="submit" value="'.get_string('submit').'" />&nbsp;';
-    echo '<input type="submit" name="refresh" value="'.get_string('refresh').'" />';
-    echo '<input type="checkbox" name="newonly" id="newonly" '.($newonly?'checked="checked" ':'').'/><label for="newonly">'.get_string('newonlymsg', 'message').'</label>';
-    echo '</div>';
-    echo '</form>';
-    echo '</div>';
-
-    echo '<div id="messages">';
-    echo '<h1>'.get_string('messages', 'chat').'</h1>';
-
-    $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.'&amp;newonly='.$newonly.'&amp;last='.$last);
+}
+
+$PAGE->set_title("$strchat: $course->shortname: ".format_string($chat->name,true)."$groupname");
+$PAGE->set_focuscontrol('message');
+echo $OUTPUT->header();
+echo '<div id="mod-chat-gui_basic">';
+echo '<h1>'.get_string('participants').'</h1>';
+echo '<div id="participants"><ul>';
+foreach($chatusers as $chu) {
+    echo '<li>';
+    $userpic = moodle_user_picture::make($chu->id, $course->id);
+    $userpic->size = 24;
+    echo $OUTPUT->user_picture($userpic);
+    echo '<div class="userinfo">';
+    echo fullname($chu).' ';
+    if ($idle = time() - $chu->lastmessageping) {
+        echo '<span class="idle">'.$stridle.' '.format_time($idle).'</span>';
     } else {
-        $lastsql = "";
+        echo '<span class="idle" />';
     }
-
-    $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 '</div>';
+    echo '</li>';
+}
+echo '</ul></div>';
+echo '<div id="send">';
+echo '<form id="editing" method="post" action="index.php">';
+
+$usehtmleditor = can_use_html_editor();
+echo '<h1><label for="message">'.get_string('sendmessage', 'message').'</label></h1>';
+echo '<div>';
+echo '<input type="text" id="message" name="message" value="'.s($refreshedmessage, true).'" size="60" />';
+echo '</div><div>';
+echo '<input type="hidden" name="id" value="'.$id.'" />';
+echo '<input type="hidden" name="groupid" value="'.$groupid.'" />';
+echo '<input type="hidden" name="last" value="'.time().'" />';
+echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
+echo '<input type="submit" value="'.get_string('submit').'" />&nbsp;';
+echo '<input type="submit" name="refresh" value="'.get_string('refresh').'" />';
+echo '<input type="checkbox" name="newonly" id="newonly" '.($newonly?'checked="checked" ':'').'/><label for="newonly">'.get_string('newonlymsg', 'message').'</label>';
+echo '</div>';
+echo '</form>';
+echo '</div>';
+
+echo '<div id="messages">';
+echo '<h1>'.get_string('messages', 'chat').'</h1>';
+
+$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 '</div></div>';
-
-    echo $OUTPUT->footer();
-
-
+echo '</div></div>';
+echo $OUTPUT->footer();
 
-?>
+?>
\ No newline at end of file
index 45117f2d11bb3028e4ac64e0eb44faddfcac90c1..d7d85d85c82d2492d6cd65b409c59a7e2da48ae6 100644 (file)
@@ -1,42 +1,42 @@
-<?php  // $Id$
+<?php
 
-    define('NO_MOODLE_COOKIES', true); // session not used here
+define('NO_MOODLE_COOKIES', true); // session not used here
 
-    require('../../../config.php');
-    require('../lib.php');
+require('../../../config.php');
+require('../lib.php');
 
-    $chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
-    $chatid   = required_param('chat_id', PARAM_INT);
+$chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
+$chatid   = required_param('chat_id', PARAM_INT);
 
-    if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
-        print_error('notlogged', 'chat');
-    }
-    if (!$chat = $DB->get_record('chat', array('id'=>$chatid))) {
-        error('Could not find that chat room!');
-    }
+if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
+    print_error('notlogged', 'chat');
+}
+if (!$chat = $DB->get_record('chat', array('id'=>$chatid))) {
+    print_error('invalidid', 'chat');
+}
 
-    if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
-        error('Could not find the course this belongs to!');
-    }
+if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
+    print_error('invalidcourseid');
+}
 
-    if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
-        error('Course Module ID was incorrect');
-    }
+if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
+    print_error('invalidcoursemodule');
+}
 
-    $PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/chat/gui_header_js/chatinput.php', array('chat_sid'=>$chat_sid, 'chat_id'=>$chatid)));
+$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/chat/gui_header_js/chatinput.php', array('chat_sid'=>$chat_sid, 'chat_id'=>$chatid)));
 
-    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = get_context_instance(CONTEXT_MODULE, $cm->id);
 
-    //Get the user theme
-    $USER = $DB->get_record('user', array('id'=>$chatuser->userid));
+//Get the user theme
+$USER = $DB->get_record('user', array('id'=>$chatuser->userid));
 
-    //Setup course, lang and theme
-    $PAGE->set_course($course);
-    $PAGE->requires->js('mod/chat/gui_header_js/chat_gui_header.js')->in_head();
-    $PAGE->set_generaltype('embedded');
-    $PAGE->set_focuscontrol('input_chat_message');
-    $PAGE->set_cacheable(false);
-    echo $OUTPUT->header();
+//Setup course, lang and theme
+$PAGE->set_course($course);
+$PAGE->requires->js('mod/chat/gui_header_js/chat_gui_header.js')->in_head();
+$PAGE->set_generaltype('embedded');
+$PAGE->set_focuscontrol('input_chat_message');
+$PAGE->set_cacheable(false);
+echo $OUTPUT->header();
 
 ?>
     <form action="../empty.php" method="post" target="empty" id="inputForm"
index 98750fefca251918a687383628af0a4f41093c2a..d161bf894fdd859bcedc5b10d73146ec544bc61f 100644 (file)
@@ -1,62 +1,69 @@
-<?php  // $Id$
+<?php
 
-    require_once('../../../config.php');
-    require_once('../lib.php');
+require_once('../../../config.php');
+require_once('../lib.php');
 
-    $id      = required_param('id', PARAM_INT);
-    $groupid = optional_param('groupid', 0, PARAM_INT); //only for teachers
+$id      = required_param('id', PARAM_INT);
+$groupid = optional_param('groupid', 0, PARAM_INT); //only for teachers
 
-    if (!$chat = $DB->get_record('chat', array('id'=>$id))) {
-        print_error('invalidid', 'chat');
-    }
+$url = new moodle_url($CFG->wwwroot.'/mod/chat/gui_header_js/index.php', array('id'=>$id));
+if ($groupid !== 0) {
+    $url->param('groupid', $groupid);
+}
+$PAGE->set_url($url);
 
-    if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
-        print_error('invalidcourseid');
-    }
+if (!$chat = $DB->get_record('chat', array('id'=>$id))) {
+    print_error('invalidid', 'chat');
+}
 
-    if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
-        print_error('invalidcoursemodule');
-    }
+if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
+    print_error('invalidcourseid');
+}
 
-    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
+    print_error('invalidcoursemodule');
+}
 
-    require_login($course->id, false, $cm);
+$context = get_context_instance(CONTEXT_MODULE, $cm->id);
 
-    require_capability('mod/chat:chat',$context);
+require_login($course->id, false, $cm);
 
-    if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id))) {
-        echo $OUTPUT->header();
-        notice(get_string("activityiscurrentlyhidden"));
-    }
+require_capability('mod/chat:chat',$context);
+
+if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id))) {
+    echo $OUTPUT->header();
+    notice(get_string("activityiscurrentlyhidden"));
+}
 
 /// Check to see if groups are being used here
-     if ($groupmode = groups_get_activity_groupmode($cm)) {   // Groups are being used
-        if ($groupid = groups_get_activity_group($cm)) {
-            if (!$group = groups_get_group($groupid, false)) {
-                print_error('invalidgroupid');
-            }
-            $groupname = ': '.$group->name;
-        } else {
-            $groupname = ': '.get_string('allparticipants');
+ if ($groupmode = groups_get_activity_groupmode($cm)) {   // Groups are being used
+    if ($groupid = groups_get_activity_group($cm)) {
+        if (!$group = groups_get_group($groupid, false)) {
+            print_error('invalidgroupid');
         }
+        $groupname = ': '.$group->name;
     } else {
-        $groupid = 0;
-        $groupname = '';
+        $groupname = ': '.get_string('allparticipants');
     }
+} else {
+    $groupid = 0;
+    $groupname = '';
+}
 
-    $strchat = get_string('modulename', 'chat'); // must be before current_language() in chat_login_user() to force course language!!!
+$strchat = get_string('modulename', 'chat'); // must be before current_language() in chat_login_user() to force course language!!!
 
-    if (!$chat_sid = chat_login_user($chat->id, 'header_js', $groupid, $course)) {
-        print_error('cantlogin', 'chat');
-    }
+if (!$chat_sid = chat_login_user($chat->id, 'header_js', $groupid, $course)) {
+    print_error('cantlogin', 'chat');
+}
 
-    $params = "chat_id=$id&chat_sid={$chat_sid}";
+$params = "chat_id=$id&chat_sid={$chat_sid}";
+
+// fallback to the old jsupdate, but allow other update modes
+$updatemode = 'jsupdate';
+if (!empty($CFG->chat_normal_updatemode)) {
+    $updatemode = $CFG->chat_normal_updatemode;
+}
 
-    // fallback to the old jsupdate, but allow other update modes
-    $updatemode = 'jsupdate';
-    if (!empty($CFG->chat_normal_updatemode)) {
-        $updatemode = $CFG->chat_normal_updatemode;
-    }
 ?>
 
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
index d92a45f3d608dfe12998cd020b8ecab055a93fdf..b7b1380f80add7e5597b6d274b64eb403b419022 100644 (file)
@@ -1,73 +1,74 @@
-<?php  // $Id$
+<?php
 
-    include('../../../config.php');
-    include('../lib.php');
+include('../../../config.php');
+include('../lib.php');
 
-    $chat_sid     = required_param('chat_sid', PARAM_ALPHANUM);
-    $chat_message = required_param('chat_message', PARAM_RAW);
+$chat_sid     = required_param('chat_sid', PARAM_ALPHANUM);
+$chat_message = required_param('chat_message', PARAM_RAW);
 
-    if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
-        print_error('notlogged', 'chat');
-    }
+$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/chat/gui_header_js/insert.php', array('chat_sid'=>$chat_sid,'chat_message'=>$chat_message)));
 
-    if (!$chat = $DB->get_record('chat', array('id'=>$chatuser->chatid))) {
-        print_error('nochat', 'chat');
-    }
+if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
+    print_error('notlogged', 'chat');
+}
 
-    if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
-        print_error('invalidcourseid');
-    }
+if (!$chat = $DB->get_record('chat', array('id'=>$chatuser->chatid))) {
+    print_error('nochat', 'chat');
+}
 
-    if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
-        print_error('invalidcoursemodule');
-    }
+if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
+    print_error('invalidcourseid');
+}
 
-    require_login($course->id, false, $cm);
+if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
+    print_error('invalidcoursemodule');
+}
 
-    if (isguest()) {
-        print_error('noguests');
-    }
+require_login($course->id, false, $cm);
+
+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
index e26bb12401410d9e5145d385d692b0131a1aad04..f10b33a5e182c6898809e4ed453de671779bc0de 100644 (file)
@@ -1,86 +1,96 @@
-<?php  // $Id$
-
-    define('NO_MOODLE_COOKIES', true); // session not used here
-
-    require('../../../config.php');
-    require('../lib.php');
-
-    $chat_sid      = required_param('chat_sid', PARAM_ALPHANUM);
-    $chat_lasttime = optional_param('chat_lasttime', 0, PARAM_INT);
-    $chat_lastrow  = optional_param('chat_lastrow', 1, PARAM_INT);
-
-    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 &amp; in url, does not work in header!
-    $refreshurl = "{$CFG->wwwroot}/mod/chat/gui_header_js/jsupdate.php?chat_sid=$chat_sid&chat_lasttime=$chat_newlasttime&chat_lastrow=$chat_newrow";
-    $refreshurlamp = "{$CFG->wwwroot}/mod/chat/gui_header_js/jsupdate.php?chat_sid=$chat_sid&amp;chat_lasttime=$chat_newlasttime&amp;chat_lastrow=$chat_newrow";
-
-    header('Expires: Sun, 28 Dec 1997 09:32:45 GMT');
-    header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
-    header('Cache-Control: no-cache, must-revalidate');
-    header('Pragma: no-cache');
-    header('Content-Type: text/html; charset=utf-8');
-    header("Refresh: $CFG->chat_refresh_room; url=$refreshurl");
-
-    /// required stylesheets
-    $stylesheetshtml = '';
-    foreach ($CFG->stylesheets as $stylesheet) {
-        $stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'" />';
-    }
+<?php
 
-    // use ob to be able to send Content-Length headers
-    // needed for Keep-Alive to work
-    ob_start();
+define('NO_MOODLE_COOKIES', true); // session not used here
+
+require('../../../config.php');
+require('../lib.php');
+
+$chat_sid      = required_param('chat_sid', PARAM_ALPHANUM);
+$chat_lasttime = optional_param('chat_lasttime', 0, PARAM_INT);
+$chat_lastrow  = optional_param('chat_lastrow', 1, PARAM_INT);
+
+$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);
+
+
+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 &amp; in url, does not work in header!
+$refreshurl = "{$CFG->wwwroot}/mod/chat/gui_header_js/jsupdate.php?chat_sid=$chat_sid&chat_lasttime=$chat_newlasttime&chat_lastrow=$chat_newrow";
+$refreshurlamp = "{$CFG->wwwroot}/mod/chat/gui_header_js/jsupdate.php?chat_sid=$chat_sid&amp;chat_lasttime=$chat_newlasttime&amp;chat_lastrow=$chat_newrow";
+
+header('Expires: Sun, 28 Dec 1997 09:32:45 GMT');
+header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
+header('Cache-Control: no-cache, must-revalidate');
+header('Pragma: no-cache');
+header('Content-Type: text/html; charset=utf-8');
+header("Refresh: $CFG->chat_refresh_room; url=$refreshurl");
+
+/// required stylesheets
+$stylesheetshtml = '';
+foreach ($CFG->stylesheets as $stylesheet) {
+    $stylesheetshtml .= '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'" />';
+}
+
+// use ob to be able to send Content-Length headers
+// needed for Keep-Alive to work
+ob_start();
 
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
index 6e198cf16fce48da7ab8164e36d1364b53c91922..f8e251d38cffa0e65368b8ce3f66a6a2aa4b9e55 100644 (file)
@@ -1,4 +1,4 @@
-<?php  // $Id$
+<?php
 
 /** jsupdated.php - notes by Martin Langhoff <martin@catalyst.net.nz>
  ** 
  **/
 
 
-    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 .= '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'" />';
-    }
+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 .= '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'" />';
+}
 
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
index 746ab7c0d7d8a59ecacf7ca1914b0934ad9d75e7..0485c8d1c974520c888105d61e4d3029b1e9e165 100644 (file)
-<?php  // $Id$
-
-    define('NO_MOODLE_COOKIES', true); // session not used here
-
-    require('../../../config.php');
-    require('../lib.php');
-
-    $chat_sid   = required_param('chat_sid', PARAM_ALPHANUM);
-    $beep       = optional_param('beep', 0, PARAM_INT);  // beep target
-
-    if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
-        print_error('notlogged', 'chat');
-    }
-
-    //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 '<div style="display: none"><a href="'.$refreshurl.'" id="refreshLink">Refresh link</a></div>';
-    echo '<table width="100%">';
-    foreach ($chatusers as $chatuser) {
-        $lastping = $timenow - $chatuser->lastmessageping;
-        $min = (int) ($lastping/60);
-        $sec = $lastping - ($min*60);
-        $min = $min < 10 ? '0'.$min : $min;
-        $sec = $sec < 10 ? '0'.$sec : $sec;
-        $idle = $min.':'.$sec;
-        echo '<tr><td width="35">';
-        echo "<a target=\"_blank\" onClick=\"return openpopup('/user/view.php?id=$chatuser->id&amp;course=$courseid','user$chatuser->id','');\" href=\"$CFG->wwwroot/user/view.php?id=$chatuser->id&amp;course=$courseid\">";
-        echo $OUTPUT->user_picture(moodle_user_picture::make($chatuser, $courseid));
-        echo '</a></td><td valign="center">';
-        echo '<p><font size="1">';
-        echo fullname($chatuser).'<br />';
-        echo "<span class=\"dimmed_text\">$stridle <span name=\"uidles\" id=\"uidle{$chatuser->id}\">$idle</span></span>";
-        echo " <a href=\"users.php?chat_sid=$chat_sid&amp;beep=$chatuser->id\">$strbeep</a>";
-        echo '</font></p>';
-        echo '</td></tr>';
-    }
-    // added 2 </div>s, xhtml strict complaints
-    echo '</table>';
-    echo $OUTPUT->footer();
-
-    //
-    // Support HTTP Keep-Alive by printing Content-Length
-    //
-    // If the user pane is refreshing often, using keepalives
-    // is lighter on the server and faster for most clients.
-    //
-    // Apache is normally configured to have a 15s timeout on
-    // keepalives, so let's observe that. Unfortunately, we cannot
-    // autodetect the keepalive timeout.
-    //
-    // Using keepalives when the refresh is longer than the timeout
-    // wastes server resources keeping an apache child around on a
-    // connection that will timeout. So we don't.
-    if ($CFG->chat_refresh_userlist < 15) {
-        header("Content-Length: " . ob_get_length() );
-        ob_end_flush();
-    }
-
-    exit; // no further output
-
-
-?>
+<?php
+
+define('NO_MOODLE_COOKIES', true); // session not used here
+
+require('../../../config.php');
+require('../lib.php');
+
+$chat_sid   = required_param('chat_sid', PARAM_ALPHANUM);
+$beep       = optional_param('beep', 0, PARAM_INT);  // beep target
+
+$PAGE->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 '<div style="display: none"><a href="'.$refreshurl.'" id="refreshLink">Refresh link</a></div>';
+echo '<table width="100%">';
+foreach ($chatusers as $chatuser) {
+    $lastping = $timenow - $chatuser->lastmessageping;
+    $min = (int) ($lastping/60);
+    $sec = $lastping - ($min*60);
+    $min = $min < 10 ? '0'.$min : $min;
+    $sec = $sec < 10 ? '0'.$sec : $sec;
+    $idle = $min.':'.$sec;
+    echo '<tr><td width="35">';
+    echo "<a target=\"_blank\" onClick=\"return openpopup('/user/view.php?id=$chatuser->id&amp;course=$courseid','user$chatuser->id','');\" href=\"$CFG->wwwroot/user/view.php?id=$chatuser->id&amp;course=$courseid\">";
+    echo $OUTPUT->user_picture(moodle_user_picture::make($chatuser, $courseid));
+    echo '</a></td><td valign="center">';
+    echo '<p><font size="1">';
+    echo fullname($chatuser).'<br />';
+    echo "<span class=\"dimmed_text\">$stridle <span name=\"uidles\" id=\"uidle{$chatuser->id}\">$idle</span></span>";
+    echo " <a href=\"users.php?chat_sid=$chat_sid&amp;beep=$chatuser->id\">$strbeep</a>";
+    echo '</font></p>';
+    echo '</td></tr>';
+}
+// added 2 </div>s, xhtml strict complaints
+echo '</table>';
+echo $OUTPUT->footer();
+
+//
+// Support HTTP Keep-Alive by printing Content-Length
+//
+// If the user pane is refreshing often, using keepalives
+// is lighter on the server and faster for most clients.
+//
+// Apache is normally configured to have a 15s timeout on
+// keepalives, so let's observe that. Unfortunately, we cannot
+// autodetect the keepalive timeout.
+//
+// Using keepalives when the refresh is longer than the timeout
+// wastes server resources keeping an apache child around on a
+// connection that will timeout. So we don't.
+if ($CFG->chat_refresh_userlist < 15) {
+    header("Content-Length: " . ob_get_length() );
+    ob_end_flush();
+}
+
+exit; // no further output
+
+?>
\ No newline at end of file
index 2fb5f38829aefcb0598f65225dd9518e4fb659ae..cdb1f9421bd32ae4e41050e7613f00d69737e568 100644 (file)
@@ -1,26 +1,28 @@
-<?php  // $Id$
+<?php
+
+define('NO_MOODLE_COOKIES', true); // session not used here
 
-    define('NO_MOODLE_COOKIES', true); // session not used here
+require('../../../config.php');
+require('../lib.php');
 
-    require('../../../config.php');
-    require('../lib.php');
+$chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
 
-    $chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
+$PAGE->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();
 
 ?>
 
index 37be772fdc6a73f70969e956f5ab11d2ceb5f53b..07435f9d09f17f6e64e82795595837ec94565156 100644 (file)
@@ -1,60 +1,64 @@
-<?php  // $Id$
+<?php
 
-    require_once('../../../config.php');
-    require_once('../lib.php');
+require_once('../../../config.php');
+require_once('../lib.php');
 
-    $id      = required_param('id', PARAM_INT);
-    $groupid = optional_param('groupid', 0, PARAM_INT); //only for teachers
+$id      = required_param('id', PARAM_INT);
+$groupid = optional_param('groupid', 0, PARAM_INT); //only for teachers
 
-    if (!$chat = $DB->get_record('chat', array('id'=>$id))) {
-        print_error('invalidid', 'chat');
-    }
+$url = new moodle_url($CFG->wwwroot.'/mod/chat/gui_sockets/index.php', array('id'=>$id));
+if ($groupid !== 0) {
+    $url->param('groupid', $groupid);
+}
+$PAGE->set_url($url);
 
-    if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
-        print_error('invalidcourseid');
-    }
+if (!$chat = $DB->get_record('chat', array('id'=>$id))) {
+    print_error('invalidid', 'chat');
+}
 
-    if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
-        print_error('invalidcoursemodule');
-    }
+if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
+    print_error('invalidcourseid');
+}
 
-    require_login($course->id, false, $cm);
+if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
+    print_error('invalidcoursemodule');
+}
 
-    if (isguest()) {
-        print_error('noguests', 'chat');
-    }
+require_login($course->id, false, $cm);
 
-    if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id))) {
-        echo $OUTPUT->header();
-        notice(get_string("activityiscurrentlyhidden"));
-    }
+if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) {
+    print_error('noguests', 'chat');
+}
+
+if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id))) {
+    echo $OUTPUT->header();
+    notice(get_string("activityiscurrentlyhidden"));
+}
 
 /// Check to see if groups are being used here
-     if ($groupmode = groups_get_activity_groupmode($cm)) {   // Groups are being used
-        if ($groupid = groups_get_activity_group($cm)) {
-            if (!$group = groups_get_group($groupid, false)) {
-                print_error('invalidgroupid');
-            }
-            $groupname = ': '.$group->name;
-        } else {
-            $groupname = ': '.get_string('allparticipants');
+ if ($groupmode = groups_get_activity_groupmode($cm)) {   // Groups are being used
+    if ($groupid = groups_get_activity_group($cm)) {
+        if (!$group = groups_get_group($groupid, false)) {
+            print_error('invalidgroupid');
         }
+        $groupname = ': '.$group->name;
     } else {
-        $groupid = 0;
-        $groupname = '';
+        $groupname = ': '.get_string('allparticipants');
     }
+} else {
+    $groupid = 0;
+    $groupname = '';
+}
 
-    $strchat = get_string('modulename', 'chat'); // must be before current_language() in chat_login_user() to force course language!!!
-
-    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";
 
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
+?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
 <html>
  <head>
   <meta http-equiv="content-type" content="text/html; charset=utf-8" />
index b3f12f42d6e7f31b0ce9626890b875cfb3b9c5a2..44e52f438efde85ef293f9b13db8aa9c251340a4 100644 (file)
@@ -1,89 +1,91 @@
-<?php // $Id$
+<?php
 
-    require_once('../../config.php');
-    require_once('lib.php');
+require_once('../../config.php');
+require_once('lib.php');
 
-    $id = required_param('id', PARAM_INT);   // course
+$id = required_param('id', PARAM_INT);   // course
 
-    if (! $course = $DB->get_record('course', array('id'=>$id))) {
-        print_error('invalidcourseid');
-    }
+$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/chat/index.php', array('id'=>$id)));
+
+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 = "<a class=\"dimmed\" href=\"view.php?id=$chat->coursemodule\">".format_string($chat->name,true)."</a>";
     } else {
-        $table->head  = array ($strname);
-        $table->align = array ('left', 'left', 'left');
+        //Show normal if the mod is visible
+        $link = "<a href=\"view.php?id=$chat->coursemodule\">".format_string($chat->name,true)."</a>";
     }
-
-    $currentsection = '';
-    foreach ($chats as $chat) {
-        if (!$chat->visible) {
-            //Show dimmed if the mod is hidden
-            $link = "<a class=\"dimmed\" href=\"view.php?id=$chat->coursemodule\">".format_string($chat->name,true)."</a>";
-        } else {
-            //Show normal if the mod is visible
-            $link = "<a href=\"view.php?id=$chat->coursemodule\">".format_string($chat->name,true)."</a>";
-        }
-        $printsection = '';
-        if ($chat->section !== $currentsection) {
-            if ($chat->section) {
-                $printsection = $chat->section;
-            }
-            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 '<br />';
+echo '<br />';
 
-    echo $OUTPUT->table($table);
+echo $OUTPUT->table($table);
 
 /// Finish the page
 
-    echo $OUTPUT->footer();
+echo $OUTPUT->footer();
 
 ?>
index c25382e5979a43675ad2e9ff7abdebf0317cd306..b830c862773006c769260ba6aa8da73f60d628f9 100644 (file)
@@ -1,4 +1,4 @@
-<?php  // $Id$
+<?php
 
 /// This page prints reports and info about chats
 
     $deletesession = optional_param('deletesession', 0, PARAM_BOOL);
     $confirmdelete = optional_param('confirmdelete', 0, PARAM_BOOL);
 
+    $url = new moodle_url($CFG->wwwroot.'/mod/chat/report.php', array('id'=>$id));
+    if ($start !== 0) {
+        $url->param('start', $start);
+    }
+    if ($end !== 0) {
+        $url->param('end', $end);
+    }
+    if ($deletesession !== 0) {
+        $url->param('deletesession', $deletesession);
+    }
+    if ($confirmdelete !== 0) {
+        $url->param('confirmdelete', $confirmdelete);
+    }
+    $PAGE->set_url($url);
+
     if (! $cm = get_coursemodule_from_id('chat', $id)) {
         print_error('invalidcoursemodule');
     }