MDL-25069 CHAT added event handler to handler user logout event.
This commit is contained in:
@@ -59,6 +59,7 @@ $handlers = array(
|
||||
user_created - object user table record
|
||||
user_updated - object user table record
|
||||
user_deleted - object user table record
|
||||
user_logout - full $USER object
|
||||
|
||||
==== course related events ====
|
||||
|
||||
|
||||
@@ -2628,6 +2628,8 @@ function require_login($courseorid = NULL, $autologinguest = true, $cm = NULL, $
|
||||
function require_logout() {
|
||||
global $USER;
|
||||
|
||||
$params = $USER;
|
||||
|
||||
if (isloggedin()) {
|
||||
add_to_log(SITEID, "user", "logout", "view.php?id=$USER->id&course=".SITEID, $USER->id, 0, $USER->id);
|
||||
|
||||
@@ -2638,7 +2640,9 @@ function require_logout() {
|
||||
}
|
||||
}
|
||||
|
||||
events_trigger('user_logout', $params);
|
||||
session_get_instance()->terminate_current();
|
||||
unset($params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+10
-9
@@ -14,14 +14,12 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//TODO: use standard CLI_SCRIPT support here (skodak)
|
||||
|
||||
define('AJAX_SCRIPT', true);
|
||||
|
||||
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
|
||||
require_once(dirname(__FILE__) . '/lib.php');
|
||||
|
||||
$action = optional_param('action', '', PARAM_ALPHANUM);
|
||||
$action = optional_param('action', '', PARAM_ALPHANUM);
|
||||
$beep_id = optional_param('beep', '', PARAM_RAW);
|
||||
$chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
|
||||
$theme = required_param('theme', PARAM_ALPHANUM);
|
||||
@@ -31,19 +29,20 @@ $chat_lastrow = optional_param('chat_lastrow', 1, PARAM_INT);
|
||||
|
||||
|
||||
if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
|
||||
chat_print_error('ERROR', get_string('notlogged','chat'));
|
||||
throw new moodle_exception('notlogged', 'chat');
|
||||
}
|
||||
if (!$chat = $DB->get_record('chat', array('id'=>$chatuser->chatid))) {
|
||||
chat_print_error('ERROR', get_string('invalidcoursemodule', 'error'));
|
||||
throw new moodle_exception('invaliduserid', 'error');
|
||||
}
|
||||
if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
|
||||
chat_print_error('ERROR', get_string('invaliduserid', 'error'));
|
||||
throw new moodle_exception('invalidcourseid', 'error');
|
||||
}
|
||||
if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
|
||||
chat_print_error('ERROR', get_string('invalidcoursemodule', 'error'));
|
||||
throw new moodle_exception('invalidcoursemodule', 'error');
|
||||
}
|
||||
|
||||
if (!isloggedin()) {
|
||||
chat_print_error('ERROR', get_string('notlogged','chat'));
|
||||
throw new moodle_exception('notlogged', 'chat');
|
||||
}
|
||||
|
||||
// setup $PAGE so that format_text will work properly
|
||||
@@ -56,7 +55,6 @@ 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('X-Powered-By: MOODLE-Chat-V2');
|
||||
|
||||
switch ($action) {
|
||||
case 'init':
|
||||
@@ -65,6 +63,7 @@ case 'init':
|
||||
$response['users'] = $users;
|
||||
echo json_encode($response);
|
||||
break;
|
||||
|
||||
case 'chat':
|
||||
session_get_instance()->write_close();
|
||||
chat_delete_old_users();
|
||||
@@ -94,6 +93,7 @@ case 'chat':
|
||||
ob_end_flush();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'update':
|
||||
if ((time() - $chat_lasttime) > $CFG->chat_old_ping) {
|
||||
chat_delete_old_users();
|
||||
@@ -162,6 +162,7 @@ case 'update':
|
||||
|
||||
ob_end_flush();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -211,10 +211,9 @@ M.mod_chat_ajax.init = function(Y, cfg) {
|
||||
return;
|
||||
}
|
||||
if (data.error) {
|
||||
if (data.error.level == 'ERROR'){
|
||||
clearInterval(this.interval);
|
||||
window.location = this.cfg.home;
|
||||
}
|
||||
clearInterval(this.interval);
|
||||
alert(data.error);
|
||||
window.location = this.cfg.home;
|
||||
}
|
||||
this.cfg.chat_lasttime = data.lasttime;
|
||||
this.cfg.chat_lastrow = data.lastrow;
|
||||
|
||||
@@ -87,7 +87,7 @@ $string['normalkeepalive'] = 'KeepAlive';
|
||||
$string['normalstream'] = 'Stream';
|
||||
$string['noscheduledsession'] = 'No scheduled session';
|
||||
$string['notallowenter'] = 'You are not allow to enter the chat room.';
|
||||
$string['notlogged'] = 'Not logged in!';
|
||||
$string['notlogged'] = 'You are not logged in!';
|
||||
$string['nopermissiontoseethechatlog'] = 'You don\'t have permission to see the chat logs.';
|
||||
$string['oldping'] = 'Disconnect timeout';
|
||||
$string['pastchats'] = 'Past chat sessions';
|
||||
|
||||
@@ -1294,3 +1294,13 @@ function chat_extend_settings_navigation(settings_navigation $settings, navigati
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* user logout event handler
|
||||
*
|
||||
* @param object $user full $USER object
|
||||
*/
|
||||
function chat_user_logout($user) {
|
||||
global $DB;
|
||||
$DB->delete_records('chat_users', array('userid'=>$user->id));
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$module->version = 2010080300; // The (date) version of this module
|
||||
$module->version = 2010080301; // The (date) version of this module
|
||||
$module->requires = 2010080300; // Requires this Moodle version
|
||||
$module->cron = 300; // How often should cron check this module (seconds)?
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user