"MDL-14129, fix print_error"
authordongsheng <dongsheng>
Fri, 6 Jun 2008 08:46:48 +0000 (08:46 +0000)
committerdongsheng <dongsheng>
Fri, 6 Jun 2008 08:46:48 +0000 (08:46 +0000)
mod/chat/gui_basic/index.php
mod/chat/gui_header_js/index.php
mod/chat/gui_header_js/jsupdate.php
mod/chat/gui_header_js/jsupdated.php
mod/chat/gui_header_js/users.php
mod/chat/index.php
mod/chat/lib.php
mod/chat/pagelib.php
mod/chat/report.php
mod/chat/view.php

index 58a5a48e5b2ef4cdaae7cccb80b04ff31ef8da5f..51562b9c9df54e1a8b660d589955699b0fd5d63d 100644 (file)
     $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 = get_record('chat', 'id', $id)) {
-        print_error('Could not find that chat room!');
+    if (!$chat = $DB->get_record('chat', array('id'=>$id))) {
+        print_error('invalidid', 'chat');
     }
 
-    if (!$course = get_record('course', 'id', $chat->course)) {
-        print_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)) {
-        print_error('Course Module ID was incorrect');
+        print_error('invalidcoursemodule');
     }
 
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
@@ -30,7 +30,7 @@
      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("That group (id $groupid) doesn't exist!");
+                print_error('invalidgroupid');
             }
             $groupname = ': '.$group->name;
         } else {
@@ -45,7 +45,7 @@
     $strchats = get_string('modulenameplural', 'chat');
     $stridle  = get_String('idle', 'chat');
     if (!$chat_sid = chat_login_user($chat->id, 'basic', $groupid, $course)) {
-        print_error('Could not log in to chat room!!');
+        print_error('cantlogin', 'chat');
     }
 
     if (!$chatusers = chat_get_users($chat->id, $groupid, $cm->groupingid)) {
@@ -81,7 +81,7 @@
             $newmessage->message = $message;
             $newmessage->timestamp = time();
             if (!insert_record('chat_messages', $newmessage)) {
-                print_error('Could not insert a chat message!');
+                print_error('cantinsert', 'chat');
             }
 
             set_field('chat_users', 'lastmessageping', time(), 'sid', $chat_sid);
     }
 
     $groupselect = $groupid ? "AND (groupid='$groupid' OR groupid='0')" : "";
-    $messages = get_records_select("chat_messages",
-                        "chatid = '$chat->id' AND timestamp > $chatentered $lastsql $groupselect",
+    $messages = $DB->get_records_select("chat_messages",
+                        "chatid = '$chat->id' AND timestamp > $chatentered $lastsql $groupselect", null,
                         "timestamp DESC");
 
     if ($messages) {
index ee8984e782a7561f039c80e8c42d24c09dd27c4a..da3ef185217ec3f8ce87f500c3fede5130ac61d0 100644 (file)
@@ -7,15 +7,15 @@
     $groupid = optional_param('groupid', 0, PARAM_INT); //only for teachers
 
     if (!$chat = get_record('chat', 'id', $id)) {
-        print_error('Could not find that chat room!');
+        print_error('invalidid', 'chat');
     }
 
     if (!$course = get_record('course', 'id', $chat->course)) {
-        print_error('Could not find the course this belongs to!');
+        print_error('invalidcourseid');
     }
 
     if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
-        print_error('Course Module ID was incorrect');
+        print_error('invalidcoursemodule');
     }
     
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
index 9ec8d240d60182ecd3d70a9024fb8a79d293f17c..b8203c360cb24974336ac7040ca88263a88d393a 100644 (file)
@@ -9,18 +9,18 @@
     $chat_lasttime = optional_param('chat_lasttime', 0, PARAM_INT);
     $chat_lastrow  = optional_param('chat_lastrow', 1, PARAM_INT);
 
-    if (!$chatuser = get_record('chat_users', 'sid', $chat_sid)) {
-        print_error('Not logged in!');
+    if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
+        print_error('notlogged', 'chat');
     }
 
     //Get the minimal course
-    if (!$course = get_record('course','id',$chatuser->course,'','','','','id,theme,lang')) {
-        print_error('incorrect course id');
+    if (!$course = $DB->get_record('course', array('id'=>$chatuser->course), 'id,theme,lang')) {
+        print_error('invalidcourseid');
     }
 
     //Get the user theme and enough info to be used in chat_format_message() which passes it along to
-    if (!$USER = get_record('user','id',$chatuser->userid)) { // no optimisation here, it would break again in future!
-        print_error('User does not exist!');
+    if (!$USER = $DB->get_record('user', array('id'=>$chatuser->userid))) { // no optimisation here, it would break again in future!
+        print_error('invaliduser');
     }
     $USER->description = '';
 
@@ -47,8 +47,8 @@
 
     $groupselect = $chatuser->groupid ? " AND (groupid='".$chatuser->groupid."' OR groupid='0') " : "";
 
-    $messages = get_records_select("chat_messages",
-                        "chatid = '$chatuser->chatid' AND timestamp > '$chat_lasttime' $groupselect",
+    $messages = $DB->get_records_select("chat_messages",
+                        "chatid = '$chatuser->chatid' AND timestamp > '$chat_lasttime' $groupselect", null,
                         "timestamp ASC");
 
     if ($messages) {
index ee7fd84c2fdb15f7ef787691b89f93dee4efc9d1..c17ce09d99fd87d1cbb09178deb1500df878bd49 100644 (file)
     $chat_lastrow  = optional_param('chat_lastrow',   1, PARAM_INT);
     $chat_lastid   = optional_param('chat_lastid',    0, PARAM_INT);
 
-    if (!$chatuser = get_record('chat_users', 'sid', $chat_sid)) {
-        print_error('Not logged in!');
+    if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
+        print_error('notlogged', 'chat');
     }
 
     //Get the minimal course
-    if (!$course = get_record('course','id',$chatuser->course,'','','','','id,theme,lang')) {
-        print_error('incorrect course id');
+    if (!$course = $DB->get_record('course', array('id'=>$chatuser->course), 'id,theme,lang')) {
+        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 = get_record('user','id',$chatuser->userid)) { // no optimisation here, it would break again in future!
-        print_error('User does not exist!');
+    if (!$USER = $DB->get_record('user', array('id'=>$chatuser->userid))) { // no optimisation here, it would break again in future!
+        print_error('invaliduser');
     }
     $USER->description = '';
 
             $newcriteria = "timestamp > $chat_lasttime";
         }
         
-        $messages = get_records_select("chat_messages",
-                                       "chatid = '$chatuser->chatid' AND $newcriteria $groupselect",
+        $messages = $DB->get_records_select("chat_messages",
+                                       "chatid = '$chatuser->chatid' AND $newcriteria $groupselect", null,
                                        "timestamp ASC");
         
         if ($messages) {
index de13609f3da8509249942b2544b569797ba92b79..f21b90d6392c2088d96f4b7bf6ed8712a04d728a 100644 (file)
@@ -9,17 +9,17 @@
     $beep       = optional_param('beep', 0, PARAM_INT);  // beep target
 
     if (!$chatuser = get_record('chat_users', 'sid', $chat_sid)) {
-        print_error('Not logged in!');
+        print_error('notlogged', 'chat');
     }
 
     //Get the minimal course
     if (!$course = get_record('course','id',$chatuser->course,'','','','','id,theme,lang')) {
-        print_error('incorrect course id');
+        print_error('invalidcourseid');
     }
 
     //Get the user theme and enough info to be used in chat_format_message() which passes it along to
     if (!$USER = get_record('user','id',$chatuser->userid)) { // no optimisation here, it would break again in future!
-        print_error('User does not exist!');
+        print_error('invaliduser');
     }
     $USER->description = '';
 
@@ -29,7 +29,7 @@
     $courseid = $chatuser->course;
 
     if (!$cm = get_coursemodule_from_instance('chat', $chatuser->chatid, $courseid)) {
-        print_error('Course Module ID was incorrect');
+        print_error('invalidcoursemodule');
     }
 
     if ($beep) {
@@ -41,7 +41,7 @@
         $message->timestamp = time();
 
         if (!insert_record('chat_messages', $message)) {
-            print_error('Could not insert a chat message!');
+            print_error('cantinsert', 'chat');
         }
 
         $chatuser->lastmessageping = time();          // A beep is a ping  ;-)
index c6bcaf0ee8cd6ee3672d832788124906c3eebcb3..05c9ca77a4b95b4e08c0021162c84ff6c8708058 100644 (file)
@@ -6,7 +6,7 @@
     $id = required_param('id', PARAM_INT);   // course
 
     if (! $course = get_record('course', 'id', $id)) {
-        print_error('Course ID is incorrect');
+        print_error('invalidcourseid');
     }
 
     require_course_login($course);
index baa5dd96220ed758e73c9a8fcb5553e80e56150f..77d84240edb97f6b5d692eb82c90e31033754f77 100644 (file)
@@ -493,7 +493,7 @@ function chat_login_user($chatid, $version, $groupid, $course) {
             $message->timestamp = time();
 
             if (!insert_record('chat_messages', $message)) {
-                print_error('Could not insert a chat message!');
+                print_error('cantinsert', 'chat');
             }
         }
     }
@@ -523,7 +523,7 @@ function chat_delete_old_users() {
             $message->timestamp = time();
 
             if (!insert_record('chat_messages', $message)) {
-                print_error('Could not insert a chat message!');
+                print_error('cantinsert', 'chat');
             }
         }
     }
index 1243b3f38fe1a84cc517b8e2629c3f9a975496ee..3c5ca7a1048340a037d4899d3fa300c7f5a9322a 100644 (file)
@@ -19,7 +19,7 @@ class page_chat extends page_generic_activity {
 
     function init_quick($data) {
         if(empty($data->pageid)) {
-            print_error('Cannot quickly initialize page: empty course id');
+            print_error('invalidcourseid');
         }
         $this->activityname = 'chat';
         parent::init_quick($data);
index 00bdf1a93b6c40585684bf682b7563eecaea6612..25e71f1d981ce862498234c06f83d54207ba3846 100644 (file)
     $confirmdelete = optional_param('confirmdelete', 0, PARAM_BOOL);
 
     if (! $cm = get_coursemodule_from_id('chat', $id)) {
-        print_error('Course Module ID was incorrect');
+        print_error('invalidcoursemodule');
     }
     if (! $chat = get_record('chat', 'id', $cm->instance)) {
-        print_error('Course module is incorrect');
+        print_error('invalidcoursemodule');
     }
     if (! $course = get_record('course', 'id', $chat->course)) {
-        print_error('Course is misconfigured');
+        print_error('coursemisconf');
     }
 
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
index be086082ecc3febb8f21446fb2e40c0d9a2e022a..bef45b07f80fe179c94698154625e31eb24be4fc 100644 (file)
 
     if ($id) {
         if (! $cm = get_coursemodule_from_id('chat', $id)) {
-            print_error('Course Module ID was incorrect');
+            print_error('invalidcoursemodule');
         }
 
-        if (! $course = get_record('course', 'id', $cm->course)) {
-            print_error('Course is misconfigured');
+        if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
+            print_error('coursemisconf');
         }
 
         chat_update_chat_times($cm->instance);
 
-        if (! $chat = get_record('chat', 'id', $cm->instance)) {
-            print_error('Course module is incorrect');
+        if (! $chat = $DB->get_record('chat', array('id'=>$cm->instance))) {
+            print_error('invalidid', 'chat');
         }
 
     } else {
         chat_update_chat_times($c);
 
-        if (! $chat = get_record('chat', 'id', $c)) {
-            print_error('Course module is incorrect');
+        if (! $chat = $DB->get_record('chat', array('id'=>$c))) {
+            print_error('coursemisconf');
         }
-        if (! $course = get_record('course', 'id', $chat->course)) {
-            print_error('Course is misconfigured');
+        if (! $course = get_record('course', array('id'=>$chat->course))) {
+            print_error('coursemisconf');
         }
         if (! $cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
-            print_error('Course Module ID was incorrect');
+            print_error('invalidcoursemodule');
         }
     }