]> git.mjollnir.org Git - moodle.git/commitdiff
CHAT_MOD/MDL-14651
authordongsheng <dongsheng>
Wed, 19 Nov 2008 07:58:48 +0000 (07:58 +0000)
committerdongsheng <dongsheng>
Wed, 19 Nov 2008 07:58:48 +0000 (07:58 +0000)
jump to mod front page when error occors.

mod/chat/gui_ajax/common.php
mod/chat/gui_ajax/index.php
mod/chat/gui_ajax/script.js
mod/chat/gui_ajax/update.php

index c9bbf666ee1242d3565c6d6bef1bde1394454d54..8f72fb8b7aa49ca191706da7bc1b841ef3e375f7 100755 (executable)
@@ -17,6 +17,16 @@ function format_user_list($data, $course) {
     }
     return $users;
 }
+function chat_print_error($level, $msg) {
+    header('Content-Length: ' . ob_get_length() );
+    $error = new stdclass;
+    $error->level = $level;
+    $error->msg   = $msg;
+    $response['error'] = $error;
+    echo json_encode($response);
+    ob_end_flush();
+    exit;
+}
 
 class file_cache{
     private $dir = '';
index 6763450ab4458ca8083217cd83c5a9747e790728..4d924c5d3145075dba1ef23643c50538abb4454a 100644 (file)
@@ -65,7 +65,7 @@ $str_userlist  = get_string('userlist',  'chat');
 <link rel="stylesheet" type="text/css" href="<?php echo $CFG->httpswwwroot;?>/lib/yui/layout/assets/skins/sam/layout.css" />
 <link rel="stylesheet" type="text/css" href="<?php echo $CFG->httpswwwroot;?>/lib/yui/button/assets/skins/sam/button.css" />
 <?php
-print_js_config(array('userid'=>$USER->id, 'sid'=>$chat_sid,'timer'=>5000, 'chat_lasttime'=>0,'chat_lastrow'=>null,'header_title'=>$str_chat,'chatroom_name'=>$str_title), 'chat_cfg');
+print_js_config(array('home'=>$CFG->httpswwwroot.'/mod/chat/view.php?id='.$cm->id, 'userid'=>$USER->id, 'sid'=>$chat_sid,'timer'=>5000, 'chat_lasttime'=>0,'chat_lastrow'=>null,'header_title'=>$str_chat,'chatroom_name'=>$str_title), 'chat_cfg');
 print_js_config(array('send'=>$str_send, 'sending'=>$str_sending, 'inputarea'=>$str_inputarea, 'userlist'=>$str_userlist), 'chat_lang');
 ?>
 <script type="text/javascript" src="<?php echo $CFG->httpswwwroot;?>/lib/yui/yahoo-dom-event/yahoo-dom-event.js"></script>
index 15bc3adc6ae1c2507d7d9408f9eeb9c781b997df..318d6c80a2e5b49bacb359dd41f7781ef3c6f0d8 100644 (file)
@@ -113,7 +113,7 @@ function update_info() {
 function append_msg(msg) {
     var list = document.getElementById('msg_list');
     var el = document.createElement('li');
-    console.info('New message:'+msg);
+    console.info('New message:'+msg.msg);
     el.innerHTML = msg.msg;
     if(msg.type && msg.type == 'beep'){
         document.getElementById('notify').innerHTML = '<embed src="../beep.wav" autostart="true" hidden="true" name="beep" />';
@@ -148,6 +148,12 @@ success: function(o){
         alert(o.responseText);
         return;
     }
+    if(data.error) {
+        if(data.error.level == 'ERROR'){
+            clearInterval(interval);
+            window.location = chat_cfg.home;
+        }
+    }
     if(!data)
          return false;
     chat_cfg.chat_lasttime = data['lasttime'];
index c60b44f2ab9ad25257ffa3d86551090720891dd0..f2780d738c8dff3d87b99cd2e51e9e0ba74d53fa 100755 (executable)
@@ -9,11 +9,14 @@ require_once('../../../config.php');
 require_once('../lib.php');
 require_once('common.php');
 
+ob_start();
 header('Expires: Sun, 28 Dec 1997 09:32:45 GMT');
 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
 header('Cache-Control: no-cache, must-revalidate');
 header('Pragma: no-cache');
 header('Content-Type: text/html; charset=utf-8');
+header('X-Powered-By: MOODLE-Chat-V2');
+
 
 $time_start = microtime_float();
 
@@ -25,22 +28,22 @@ $chat_lastrow  = optional_param('chat_lastrow', 1, PARAM_INT);
 $response = array();
 
 if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
-    $response['error'] = get_string('notlogged', 'chat');
+    chat_print_error('ERROR', get_string('notlogged','chat'));
 }
 
 //Get the minimal course
 if (!$course = $DB->get_record('course', array('id'=>$chatuser->course), 'id,theme,lang')) {
-    $response['error'] = get_string('invalidcourseid', 'error');
+    chat_print_error('ERROR', get_string('invalidcourseid', 'error'));
 }
 
 //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!
-    $response['error'] = get_string('invaliduserid', 'error');
+    chat_print_error('ERROR', get_string('invaliduserid', 'error'));
 }
 
 if (!$cm = get_coursemodule_from_instance('chat', $chatuser->chatid, $course->id)) {
-    $response['error'] = get_string('invalidcoursemodule', 'error');
+    chat_print_error('ERROR', get_string('invalidcoursemodule', 'error'));
 }
 
 if($CFG->chat_use_cache){
@@ -54,10 +57,6 @@ if($CFG->chat_use_cache){
     $users = chat_get_users($chatuser->chatid, $chatuser->groupid, $cm->groupingid);
 }
 
-if (empty($users)) {
-    $response['error'] = get_string('nousers', 'error');
-}
-
 $users = format_user_list($users, $course);
 
 if(!empty($chat_init)) {
@@ -98,8 +97,6 @@ if (!empty($messages)) {
 
 $chat_newrow = ($chat_lastrow + $num) % 2;
 
-ob_start();
-
 $send_user_list = false;
 if ($messages && ($chat_lasttime != $chat_newlasttime)) {
     foreach ($messages as $n => &$message) {
@@ -146,7 +143,6 @@ if(!empty($CFG->chat_ajax_debug)) {
 
 echo json_encode($response);
 
-header('X-Powered-By: MOODLE-Chat-V2');
 header('Content-Length: ' . ob_get_length() );
 
 ob_end_flush();