]> git.mjollnir.org Git - moodle.git/commitdiff
CHAT_MOD/MDL-14651
authordongsheng <dongsheng>
Wed, 19 Nov 2008 08:05:45 +0000 (08:05 +0000)
committerdongsheng <dongsheng>
Wed, 19 Nov 2008 08:05:45 +0000 (08:05 +0000)
update post.php script to support error report code.

mod/chat/gui_ajax/post.php

index 2977548c675f244160803fc5c880bac56393f916..7c3302b4349e9e7e99eff559089eb610d30c52d4 100755 (executable)
@@ -2,24 +2,32 @@
 include('../../../config.php');
 include('../lib.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');
+
 $chat_sid     = required_param('chat_sid', PARAM_ALPHANUM);
 $chat_message = optional_param('chat_message', '', PARAM_RAW);
 $beep_id      = optional_param('beep', '', PARAM_RAW);
 
 if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
-    echo 'invalid sid';
+    chat_print_error('ERROR', get_string('notlogged','chat'));
 }
 if (!$chat = $DB->get_record('chat', array('id'=>$chatuser->chatid))) {
-    echo 'invalid chat id';
+    chat_print_error('ERROR', get_string('invalidcoursemodule', 'error'));
 }
 if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
-    echo 'invalid course id';
+    chat_print_error('ERROR', get_string('invaliduserid', 'error'));
 }
 if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
-    echo 'invalid course module';
+    chat_print_error('ERROR', get_string('invalidcoursemodule', 'error'));
 }
 if (isguest()) {
-    echo 'Guest does not have access to chat rooms';
+    chat_print_error('ERROR', get_string('notlogged','chat'));
 }
 session_write_close();
 chat_delete_old_users();
@@ -37,14 +45,15 @@ if (!empty($chat_message)) {
     $message->message   = $chat_message;
     $message->timestamp = time();
 
+    $chatuser->lastmessageping = time() - 2;
+    $DB->update_record('chat_users', $chatuser);
+
     if (!($DB->insert_record('chat_messages', $message) && $DB->insert_record('chat_messages_current', $message))) {
-        echo get_string('cantlogin', 'chat');
+        chat_print_error('ERROR', get_string('cantlogin','chat'));
     } else {
         echo 200;
     }
-
-    $chatuser->lastmessageping = time() - 2;
-    $DB->update_record('chat_users', $chatuser);
-
     add_to_log($course->id, 'chat', 'talk', "view.php?id=$cm->id", $chat->id, $cm->id);
+
+    ob_end_flush();
 }