diff --git a/blog/index.php b/blog/index.php
index 8d28dbc..302759c 100644
--- a/blog/index.php
+++ b/blog/index.php
@@ -118,7 +118,7 @@ if ((empty($courseid) ? true : $courseid == SITEID) && empty($userid)) {
 
 if (!empty($courseid)) {
     if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $courseid);
     }
 
     $courseid = $course->id;
diff --git a/course/completion.php b/course/completion.php
index e6ffef8..27150c4 100644
--- a/course/completion.php
+++ b/course/completion.php
@@ -50,7 +50,7 @@ if ($id) { // editing course
     }
 
     if (!$course = $DB->get_record('course', array('id'=>$id))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $id);
     }
     require_login($course->id);
     require_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id));
diff --git a/enrol/authorize/index.php b/enrol/authorize/index.php
index 5bdee18..8772dd2 100644
--- a/enrol/authorize/index.php
+++ b/enrol/authorize/index.php
@@ -53,7 +53,7 @@
 
 /// Get course
     if (!($course = $DB->get_record('course', array('id'=>$courseid)))) {
-        print_error('invalidcourseid', '', '', $courseid);
+        print_error('invalidcourseid', 'error', '', $courseid);
     }
 
 /// Only SITE users can access to this page
diff --git a/enrol/authorize/locallib.php b/enrol/authorize/locallib.php
index 058b1b0..e05f5bb 100644
--- a/enrol/authorize/locallib.php
+++ b/enrol/authorize/locallib.php
@@ -268,7 +268,7 @@ function authorize_print_order($orderid)
     }
 
     if (!$course = $DB->get_record('course', array('id'=>$order->courseid))) {
-        print_error('invalidcourseid', '', "$CFG->wwwroot/enrol/authorize/index.php");
+        print_error('invalidcourseid', 'error', "$CFG->wwwroot/enrol/authorize/index.php", $order->courseid);
     }
 
     if (!$user = $DB->get_record('user', array('id'=>$order->userid))) {
diff --git a/grade/edit/outcome/edit.php b/grade/edit/outcome/edit.php
index 1f4d9b7..9f556e0 100644
--- a/grade/edit/outcome/edit.php
+++ b/grade/edit/outcome/edit.php
@@ -55,7 +55,7 @@ if ($id) {
     if ($outcome_rec->courseid) {
         $outcome_rec->standard = 0;
         if (!$course = $DB->get_record('course', array('id' => $outcome_rec->courseid))) {
-            print_error('invalidcourseid');
+            print_error('invalidcourseid', 'error', '', $courseid);
         }
         require_login($course);
         $context = get_context_instance(CONTEXT_COURSE, $course->id);
@@ -64,7 +64,7 @@ if ($id) {
     } else {
         if ($courseid) {
             if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-                print_error('invalidcourseid');
+                print_error('invalidcourseid', 'error', '', $courseid);
             }
         }
         $outcome_rec->standard = 1;
diff --git a/grade/edit/outcome/export.php b/grade/edit/outcome/export.php
index dbb510f..ce048d3 100644
--- a/grade/edit/outcome/export.php
+++ b/grade/edit/outcome/export.php
@@ -27,7 +27,7 @@ $action   = optional_param('action', '', PARAM_ALPHA);
 /// Make sure they can even access this course
 if ($courseid) {
     if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-        print_error('nocourseid');
+        print_error('unknowncourseidnumber', 'error', '', $courseid);
     }
     require_login($course);
     $context = get_context_instance(CONTEXT_COURSE, $course->id);
diff --git a/grade/edit/outcome/import.php b/grade/edit/outcome/import.php
index 6e62867..7f466f0 100644
--- a/grade/edit/outcome/import.php
+++ b/grade/edit/outcome/import.php
@@ -30,7 +30,7 @@ $PAGE->set_url('/grade/edit/outcome/import.php', array('courseid' => $courseid))
 /// Make sure they can even access this course
 if ($courseid) {
     if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-        print_error('nocourseid');
+        print_error('unknowncourseidnumber', 'error', '', $courseid);
     }
     require_login($course);
     $context = get_context_instance(CONTEXT_COURSE, $course->id);
diff --git a/grade/edit/outcome/index.php b/grade/edit/outcome/index.php
index 45915b2..95a865c 100644
--- a/grade/edit/outcome/index.php
+++ b/grade/edit/outcome/index.php
@@ -79,7 +79,7 @@ switch ($action) {
         if (empty($outcome->courseid)) {
             require_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM));
         } else if ($outcome->courseid != $courseid) {
-            print_error('invalidcourseid');
+            print_error('invalidcourseid', 'error', '', $courseid);
         }
 
         if (!$outcome->can_delete()) {
diff --git a/grade/edit/scale/edit.php b/grade/edit/scale/edit.php
index f226139..fdfe59b 100644
--- a/grade/edit/scale/edit.php
+++ b/grade/edit/scale/edit.php
@@ -40,7 +40,7 @@ if ($id) {
     if ($scale_rec->courseid) {
         $scale_rec->standard = 0;
         if (!$course = $DB->get_record('course', array('id' => $scale_rec->courseid))) {
-            print_error('invalidcourseid');
+            print_error('invalidcourseid', 'error', '', $courseid);
         }
         require_login($course);
         $context = get_context_instance(CONTEXT_COURSE, $course->id);
@@ -49,7 +49,7 @@ if ($id) {
     } else {
         if ($courseid) {
             if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-                print_error('invalidcourseid');
+                print_error('invalidcourseid', 'error', '', $courseid);
             }
         }
         $scale_rec->standard = 1;
@@ -62,7 +62,7 @@ if ($id) {
     $heading = get_string('addscale', 'grades');
     /// adding new scale from course
     if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-        print_error('nocourseid');
+        print_error('unknowncourseidnumber', 'error', '', $courseid);
     }
     $scale_rec = new stdClass();
     $scale_rec->standard = 0;
diff --git a/grade/edit/scale/index.php b/grade/edit/scale/index.php
index 237944e..f32b64d 100644
--- a/grade/edit/scale/index.php
+++ b/grade/edit/scale/index.php
@@ -27,7 +27,7 @@ $PAGE->set_url('/grade/edit/scale/index.php', array('id' => $courseid));
 /// Make sure they can even access this course
 if ($courseid) {
     if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-        print_error('nocourseid');
+        print_error('unknowncourseidnumber', 'error', '', $courseid);
     }
     require_login($course);
     $context = get_context_instance(CONTEXT_COURSE, $course->id);
@@ -64,7 +64,7 @@ switch ($action) {
         if (empty($scale->courseid)) {
             require_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM));
         } else if ($scale->courseid != $courseid) {
-            print_error('invalidcourseid');
+            print_error('invalidcourseid', 'error', '', $courseid);
         }
 
         if (!$scale->can_delete()) {
diff --git a/grade/edit/settings/index.php b/grade/edit/settings/index.php
index c4949a4..e82d0b3 100644
--- a/grade/edit/settings/index.php
+++ b/grade/edit/settings/index.php
@@ -26,7 +26,7 @@ $PAGE->set_url('/grade/edit/settings/index.php', array('id'=>$courseid));
 $PAGE->set_pagelayout('admin');
 
 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 require_login($course);
 $context = get_context_instance(CONTEXT_COURSE, $course->id);
diff --git a/grade/edit/tree/action.php b/grade/edit/tree/action.php
index ed8d2af..71eefd0 100644
--- a/grade/edit/tree/action.php
+++ b/grade/edit/tree/action.php
@@ -26,7 +26,7 @@ $PAGE->set_url('/grade/edit/tree/action.php', array('id'=>$courseid, 'action'=>$
 
 /// Make sure they can even access this course
 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 require_login($course);
 $context = get_context_instance(CONTEXT_COURSE, $course->id);
diff --git a/grade/edit/tree/calculation.php b/grade/edit/tree/calculation.php
index 9993324..d80cd55 100644
--- a/grade/edit/tree/calculation.php
+++ b/grade/edit/tree/calculation.php
@@ -32,7 +32,7 @@ if ($section !== 'calculation') {
 $PAGE->set_url($url);
 
 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_login($course);
diff --git a/grade/edit/tree/category.php b/grade/edit/tree/category.php
index 0c37f8c..620550c 100644
--- a/grade/edit/tree/category.php
+++ b/grade/edit/tree/category.php
@@ -31,7 +31,7 @@ $PAGE->set_url($url);
 $PAGE->set_pagelayout('admin');
 
 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_login($course);
diff --git a/grade/edit/tree/grade.php b/grade/edit/tree/grade.php
index ab188de..24350d8 100644
--- a/grade/edit/tree/grade.php
+++ b/grade/edit/tree/grade.php
@@ -38,7 +38,7 @@ if ($userid !== 0) {
 $PAGE->set_url($url);
 
 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 $PAGE->set_pagelayout('incourse');
diff --git a/grade/edit/tree/index.php b/grade/edit/tree/index.php
index 8d88615..8e2b9af 100644
--- a/grade/edit/tree/index.php
+++ b/grade/edit/tree/index.php
@@ -44,7 +44,7 @@ $PAGE->set_pagelayout('admin');
 
 /// Make sure they can even access this course
 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_login($course);
diff --git a/grade/edit/tree/item.php b/grade/edit/tree/item.php
index 1ce936c..582ac57 100644
--- a/grade/edit/tree/item.php
+++ b/grade/edit/tree/item.php
@@ -31,7 +31,7 @@ $PAGE->set_url($url);
 $PAGE->set_pagelayout('admin');
 
 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_login($course);
diff --git a/grade/edit/tree/outcomeitem.php b/grade/edit/tree/outcomeitem.php
index 518f111..350007e 100644
--- a/grade/edit/tree/outcomeitem.php
+++ b/grade/edit/tree/outcomeitem.php
@@ -30,7 +30,7 @@ if ($id !== 0) {
 $PAGE->set_url($url);
 
 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_login($course);
diff --git a/grade/export/key.php b/grade/export/key.php
index cd089d1..9d3512e 100644
--- a/grade/export/key.php
+++ b/grade/export/key.php
@@ -42,16 +42,16 @@ if ($id) {
         $courseid = $key->instance;
 
     } else if ($courseid != $key->instance) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $courseid);
     }
 
     if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $courseid);
     }
 
 } else {
     if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $courseid);
     }
     $key = new stdClass();
 }
diff --git a/grade/export/keymanager.php b/grade/export/keymanager.php
index b6d7314..917b408 100644
--- a/grade/export/keymanager.php
+++ b/grade/export/keymanager.php
@@ -31,7 +31,7 @@ $id = required_param('id', PARAM_INT); // course id
 $PAGE->set_url('/grade/export/keymanager.php', array('id' => $id));
 
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_login($course);
diff --git a/grade/export/ods/dump.php b/grade/export/ods/dump.php
index 1bca2f1..f8566f4 100644
--- a/grade/export/ods/dump.php
+++ b/grade/export/ods/dump.php
@@ -20,7 +20,7 @@ require_once '../../../config.php';
 
 $id = required_param('id', PARAM_INT); // course id
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_user_key_login('grade/export', $id); // we want different keys for each course
diff --git a/grade/export/ods/export.php b/grade/export/ods/export.php
index f81f1d6..2773ffa 100644
--- a/grade/export/ods/export.php
+++ b/grade/export/ods/export.php
@@ -28,7 +28,7 @@ $displaytype       = optional_param('displaytype', $CFG->grade_export_displaytyp
 $decimalpoints     = optional_param('decimalpoints', $CFG->grade_export_decimalpoints, PARAM_INT);
 
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_login($course);
diff --git a/grade/export/ods/index.php b/grade/export/ods/index.php
index f0d4b3c..3bda1a9 100644
--- a/grade/export/ods/index.php
+++ b/grade/export/ods/index.php
@@ -24,7 +24,7 @@ $id = required_param('id', PARAM_INT); // course id
 $PAGE->set_url('/grade/export/ods/index.php', array('id'=>$id));
 
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_login($course);
diff --git a/grade/export/txt/dump.php b/grade/export/txt/dump.php
index 305b480..52a76d5 100644
--- a/grade/export/txt/dump.php
+++ b/grade/export/txt/dump.php
@@ -20,7 +20,7 @@ require_once '../../../config.php';
 
 $id = required_param('id', PARAM_INT); // course id
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_user_key_login('grade/export', $id); // we want different keys for each course
diff --git a/grade/export/txt/export.php b/grade/export/txt/export.php
index ab7a03b..972122e 100644
--- a/grade/export/txt/export.php
+++ b/grade/export/txt/export.php
@@ -29,7 +29,7 @@ $displaytype       = optional_param('displaytype', $CFG->grade_export_displaytyp
 $decimalpoints     = optional_param('decimalpoints', $CFG->grade_export_decimalpoints, PARAM_INT);
 
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_login($course);
diff --git a/grade/export/txt/index.php b/grade/export/txt/index.php
index 47de3e7..6877420 100644
--- a/grade/export/txt/index.php
+++ b/grade/export/txt/index.php
@@ -24,7 +24,7 @@ $id = required_param('id', PARAM_INT); // course id
 $PAGE->set_url('/grade/export/txt/index.php', array('id'=>$id));
 
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_login($course);
diff --git a/grade/export/xls/dump.php b/grade/export/xls/dump.php
index 7c4ea4e..13c3614 100644
--- a/grade/export/xls/dump.php
+++ b/grade/export/xls/dump.php
@@ -20,7 +20,7 @@ require_once '../../../config.php';
 
 $id = required_param('id', PARAM_INT); // course id
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_user_key_login('grade/export', $id); // we want different keys for each course
diff --git a/grade/export/xls/export.php b/grade/export/xls/export.php
index 4df1fec..89b1fc7 100644
--- a/grade/export/xls/export.php
+++ b/grade/export/xls/export.php
@@ -28,7 +28,7 @@ $displaytype       = optional_param('displaytype', $CFG->grade_export_displaytyp
 $decimalpoints     = optional_param('decimalpoints', $CFG->grade_export_decimalpoints, PARAM_INT);
 
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_login($course);
diff --git a/grade/export/xls/index.php b/grade/export/xls/index.php
index fc509bc..32929dd 100644
--- a/grade/export/xls/index.php
+++ b/grade/export/xls/index.php
@@ -24,7 +24,7 @@ $id = required_param('id', PARAM_INT); // course id
 $PAGE->set_url('/grade/export/xls/index.php', array('id'=>$id));
 
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_login($course);
diff --git a/grade/export/xml/dump.php b/grade/export/xml/dump.php
index 5b147f8..eaf1505 100644
--- a/grade/export/xml/dump.php
+++ b/grade/export/xml/dump.php
@@ -20,7 +20,7 @@ require_once '../../../config.php';
 
 $id = required_param('id', PARAM_INT); // course id
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_user_key_login('grade/export', $id); // we want different keys for each course
diff --git a/grade/export/xml/export.php b/grade/export/xml/export.php
index 7807993..987cbac 100644
--- a/grade/export/xml/export.php
+++ b/grade/export/xml/export.php
@@ -28,7 +28,7 @@ $displaytype       = optional_param('displaytype', $CFG->grade_export_displaytyp
 $decimalpoints     = optional_param('decimalpoints', $CFG->grade_export_decimalpoints, PARAM_INT);
 
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_login($course);
diff --git a/grade/export/xml/index.php b/grade/export/xml/index.php
index bc4d925..46248e6 100644
--- a/grade/export/xml/index.php
+++ b/grade/export/xml/index.php
@@ -24,7 +24,7 @@ $id = required_param('id', PARAM_INT); // course id
 $PAGE->set_url('/grade/export/xml/index.php', array('id'=>$id));
 
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_login($course);
diff --git a/grade/import/csv/index.php b/grade/import/csv/index.php
index 886bf43..cca5bb4 100644
--- a/grade/import/csv/index.php
+++ b/grade/import/csv/index.php
@@ -37,7 +37,7 @@ $PAGE->set_url($url);
 define('GRADE_CSV_LINE_LENGTH', 4096);
 
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_login($course);
diff --git a/grade/import/key.php b/grade/import/key.php
index 187859d..214eb1a 100644
--- a/grade/import/key.php
+++ b/grade/import/key.php
@@ -42,16 +42,16 @@ if ($id) {
         $courseid = $key->instance;
 
     } else if ($courseid != $key->instance) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $courseid);
     }
 
     if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $courseid);
     }
 
 } else {
     if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $courseid);
     }
     $key = new stdClass();
 }
diff --git a/grade/import/keymanager.php b/grade/import/keymanager.php
index 7d469f6..d2e76bd 100644
--- a/grade/import/keymanager.php
+++ b/grade/import/keymanager.php
@@ -31,7 +31,7 @@ $id = required_param('id', PARAM_INT); // course id
 $PAGE->set_url('/grade/import/keymanager.php', array('id' => $id));
 
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_login($course);
diff --git a/grade/import/xml/fetch.php b/grade/import/xml/fetch.php
index 68fd62e..6c84e70 100644
--- a/grade/import/xml/fetch.php
+++ b/grade/import/xml/fetch.php
@@ -20,7 +20,7 @@ require_once '../../../config.php';
 
 $id = required_param('id', PARAM_INT); // course id
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_user_key_login('grade/import', $id); // we want different keys for each course
diff --git a/grade/import/xml/import.php b/grade/import/xml/import.php
index 3c941f0..9c355ca 100644
--- a/grade/import/xml/import.php
+++ b/grade/import/xml/import.php
@@ -30,7 +30,7 @@ if ($feedback !== 0) {
 $PAGE->set_url($url);
 
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_login($course);
diff --git a/grade/import/xml/index.php b/grade/import/xml/index.php
index 5ce766b..30ea06b 100644
--- a/grade/import/xml/index.php
+++ b/grade/import/xml/index.php
@@ -25,7 +25,7 @@ $PAGE->set_url(new moodle_url('/grade/import/xml/index.php', array('id'=>$id)));
 $PAGE->set_pagelayout('admin');
 
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_login($course);
diff --git a/grade/report/grader/ajax_callbacks.php b/grade/report/grader/ajax_callbacks.php
index 463f1d6..a1dab24 100644
--- a/grade/report/grader/ajax_callbacks.php
+++ b/grade/report/grader/ajax_callbacks.php
@@ -31,7 +31,7 @@ $newvalue = optional_param('newvalue', false, PARAM_MULTILANG);
 
 /// basic access checks
 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 $context = get_context_instance(CONTEXT_COURSE, $course->id);
 require_login($course);
diff --git a/grade/report/grader/index.php b/grade/report/grader/index.php
index ca4c063..8ce591e 100644
--- a/grade/report/grader/index.php
+++ b/grade/report/grader/index.php
@@ -36,7 +36,7 @@ $PAGE->set_url(new moodle_url('/grade/report/grader/index.php', array('id'=>$cou
 
 /// basic access checks
 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 require_login($course);
 $context = get_context_instance(CONTEXT_COURSE, $course->id);
diff --git a/grade/report/grader/preferences.php b/grade/report/grader/preferences.php
index 595eb84..f4bcf5e 100644
--- a/grade/report/grader/preferences.php
+++ b/grade/report/grader/preferences.php
@@ -28,7 +28,7 @@ $PAGE->set_pagelayout('admin');
 /// Make sure they can even access this course
 
 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_login($course->id);
diff --git a/grade/report/grader/quickedit_item.php b/grade/report/grader/quickedit_item.php
index 7a9ce65..8e72e19 100644
--- a/grade/report/grader/quickedit_item.php
+++ b/grade/report/grader/quickedit_item.php
@@ -37,7 +37,7 @@ $PAGE->set_url($url);
 
 /// basic access checks
 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 if (!$item = $DB->get_record('grade_items', array('id' => $itemid))) {
diff --git a/grade/report/index.php b/grade/report/index.php
index e4ba906..61ba141 100644
--- a/grade/report/index.php
+++ b/grade/report/index.php
@@ -23,7 +23,7 @@ $PAGE->set_url('/grade/report/index.php', array('id'=>$courseid));
 
 /// basic access checks
 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 require_login($course);
 $context = get_context_instance(CONTEXT_COURSE, $course->id);
diff --git a/grade/report/outcomes/index.php b/grade/report/outcomes/index.php
index cf73c63..3cc4a3a 100644
--- a/grade/report/outcomes/index.php
+++ b/grade/report/outcomes/index.php
@@ -24,7 +24,7 @@ $courseid = required_param('id', PARAM_INT);                   // course id
 $PAGE->set_url('/grade/report/outcomes/index.php', array('id'=>$courseid));
 
 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_login($course->id);
diff --git a/grade/report/overview/index.php b/grade/report/overview/index.php
index fefc771..1f6c4ea 100644
--- a/grade/report/overview/index.php
+++ b/grade/report/overview/index.php
@@ -27,7 +27,7 @@ $PAGE->set_url(new moodle_url('/grade/report/overview/index.php', array('id'=>$c
 
 /// basic access checks
 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 require_login($course);
 
diff --git a/grade/report/user/index.php b/grade/report/user/index.php
index 10aeffb..df652eb 100644
--- a/grade/report/user/index.php
+++ b/grade/report/user/index.php
@@ -27,7 +27,7 @@ $PAGE->set_url(new moodle_url('/grade/report/user/index.php', array('id'=>$cours
 
 /// basic access checks
 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 require_login($course);
 $PAGE->set_pagelayout('report');
diff --git a/group/autogroup.php b/group/autogroup.php
index 42fc1dc..e82fcf3 100644
--- a/group/autogroup.php
+++ b/group/autogroup.php
@@ -20,7 +20,7 @@ $courseid = required_param('courseid', PARAM_INT);
 $PAGE->set_url('/group/autogroup.php', array('courseid' => $courseid));
 
 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $courseid);
 }
 
 // Make sure that the user has permissions to manage groups.
diff --git a/group/delete.php b/group/delete.php
index 3d5af15..c62c230 100644
--- a/group/delete.php
+++ b/group/delete.php
@@ -20,7 +20,7 @@ $PAGE->set_url('/group/delete.php', array('courseid'=>$courseid,'groups'=>$group
 
 // Make sure course is OK and user has access to manage groups
 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $courseid);
 }
 require_login($course);
 $context = get_context_instance(CONTEXT_COURSE, $course->id);
diff --git a/group/group.php b/group/group.php
index e35c228..484eaff 100644
--- a/group/group.php
+++ b/group/group.php
@@ -33,16 +33,16 @@ if ($id) {
         $courseid = $group->courseid;
 
     } else if ($courseid != $group->courseid) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $courseid);
     }
 
     if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $courseid);
     }
 
 } else {
     if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $courseid);
     }
     $group = new stdClass();
     $group->courseid = $course->id;
diff --git a/group/grouping.php b/group/grouping.php
index 7d80e65..bb9d45d 100644
--- a/group/grouping.php
+++ b/group/grouping.php
@@ -28,19 +28,19 @@ if ($id) {
     if (empty($courseid)) {
         $courseid = $grouping->courseid;
     } else if ($courseid != $grouping->courseid) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $courseid);
     } else {
         $url->param('courseid', $courseid);
     }
 
     if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $courseid);
     }
 
 } else {
     $url->param('courseid', $courseid);
     if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $courseid);
     }
     $grouping = new stdClass();
     $grouping->courseid = $course->id;
diff --git a/group/groupings.php b/group/groupings.php
index 80ad8bd..d1f04ee 100644
--- a/group/groupings.php
+++ b/group/groupings.php
@@ -31,7 +31,7 @@ $courseid = required_param('id', PARAM_INT);
 $PAGE->set_url('/group/groupings.php', array('id'=>$courseid));
 
 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
-    print_error('nocourseid');
+    print_error('unknowncourseidnumber', 'error', '', $courseid);
 }
 
 require_login($course);
diff --git a/lib/grouplib.php b/lib/grouplib.php
index 708d242..e9f631d 100644
--- a/lib/grouplib.php
+++ b/lib/grouplib.php
@@ -378,7 +378,7 @@ function groups_get_activity_groupmode($cm, $course=null) {
         $course = $COURSE;
     } else {
         if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
-            print_error('invalidcourseid');
+            print_error('invalidcourseid', 'error', '', $cm->course);
         }
     }
 
@@ -755,4 +755,4 @@ function _group_verify_activegroup($courseid, $groupmode, $groupingid, array $al
             $SESSION->activegroup[$courseid][$groupmode][$groupingid] = 0;
         }
     }
-}
\ No newline at end of file
+}
diff --git a/login/change_password.php b/login/change_password.php
index 2608079..036a8a4 100644
--- a/login/change_password.php
+++ b/login/change_password.php
@@ -55,7 +55,7 @@ $strparticipants = get_string('participants');
 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
 
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $id);
 }
 
 // require proper login; guest user can not change password
diff --git a/message/edit.php b/message/edit.php
index a231b25..bde1420 100644
--- a/message/edit.php
+++ b/message/edit.php
@@ -37,7 +37,7 @@ $url->param('course', $course);
 $PAGE->set_url($url);
 
 if (!$course = $DB->get_record('course', array('id' => $course))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $course);
 }
 
 if ($course->id != SITEID) {
diff --git a/mod/assignment/index.php b/mod/assignment/index.php
index 71eb023..665ff6a 100644
--- a/mod/assignment/index.php
+++ b/mod/assignment/index.php
@@ -7,7 +7,7 @@ require_once($CFG->libdir.'/gradelib.php');
 $id = required_param('id', PARAM_INT);   // course
 
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $course);
 }
 
 require_course_login($course);
diff --git a/mod/chat/gui_basic/index.php b/mod/chat/gui_basic/index.php
index 5654214..02d5d06 100644
--- a/mod/chat/gui_basic/index.php
+++ b/mod/chat/gui_basic/index.php
@@ -33,7 +33,7 @@ if (!$chat = $DB->get_record('chat', array('id'=>$id))) {
 }
 
 if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $chat->course);
 }
 
 if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
diff --git a/mod/chat/gui_header_js/chatinput.php b/mod/chat/gui_header_js/chatinput.php
index a228a92..0ede88b 100644
--- a/mod/chat/gui_header_js/chatinput.php
+++ b/mod/chat/gui_header_js/chatinput.php
@@ -16,7 +16,7 @@ if (!$chat = $DB->get_record('chat', array('id'=>$chatid))) {
 }
 
 if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $chat->course);
 }
 
 if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
diff --git a/mod/chat/gui_header_js/index.php b/mod/chat/gui_header_js/index.php
index 43d0f0b..7a5af99 100644
--- a/mod/chat/gui_header_js/index.php
+++ b/mod/chat/gui_header_js/index.php
@@ -17,7 +17,7 @@ if (!$chat = $DB->get_record('chat', array('id'=>$id))) {
 }
 
 if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $chat->course);
 }
 
 if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
diff --git a/mod/chat/gui_header_js/insert.php b/mod/chat/gui_header_js/insert.php
index 6b842d2..ed37858 100644
--- a/mod/chat/gui_header_js/insert.php
+++ b/mod/chat/gui_header_js/insert.php
@@ -17,7 +17,7 @@ if (!$chat = $DB->get_record('chat', array('id'=>$chatuser->chatid))) {
 }
 
 if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $chat->course);
 }
 
 if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
@@ -73,4 +73,4 @@ if ($chatuser->version == 'header_js') {
     $PAGE->requires->js_init_call('M.mod_chat_header.init_insert_nojsupdated', array($forcerefreshasap), true, $module);
 }
 
-redirect('../empty.php');
\ No newline at end of file
+redirect('../empty.php');
diff --git a/mod/chat/gui_header_js/jsupdate.php b/mod/chat/gui_header_js/jsupdate.php
index cbff840..64716d4 100644
--- a/mod/chat/gui_header_js/jsupdate.php
+++ b/mod/chat/gui_header_js/jsupdate.php
@@ -25,7 +25,7 @@ if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
 
 //Get the minimal course
 if (!$course = $DB->get_record('course', array('id'=>$chatuser->course))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $chat->course);
 }
 
 //Get the user theme and enough info to be used in chat_format_message() which passes it along to
diff --git a/mod/chat/gui_header_js/jsupdated.php b/mod/chat/gui_header_js/jsupdated.php
index 9a98185..1cad7d8 100644
--- a/mod/chat/gui_header_js/jsupdated.php
+++ b/mod/chat/gui_header_js/jsupdated.php
@@ -50,7 +50,7 @@ if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
 
 //Get the minimal course
 if (!$course = $DB->get_record('course', array('id'=>$chatuser->course))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $chat->course);
 }
 
 //Get the user theme and enough info to be used in chat_format_message() which passes it along to
diff --git a/mod/chat/gui_header_js/users.php b/mod/chat/gui_header_js/users.php
index 246417c..753b540 100644
--- a/mod/chat/gui_header_js/users.php
+++ b/mod/chat/gui_header_js/users.php
@@ -16,7 +16,7 @@ if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
 
 //Get the minimal course
 if (!$course = $DB->get_record('course', array('id'=>$chatuser->course))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $chat->course);
 }
 
 //Get the user theme and enough info to be used in chat_format_message() which passes it along to
@@ -89,7 +89,7 @@ foreach ($chatusers as $chatuser) {
     $min = $min < 10 ? '0'.$min : $min;
     $sec = $sec < 10 ? '0'.$sec : $sec;
     $idle = $min.':'.$sec;
-    
+
 
     $row = array();
     $row[0] = $OUTPUT->user_picture($chatuser, array('courseid'=>$courseid, 'popup'=>true));
diff --git a/mod/chat/gui_sockets/index.php b/mod/chat/gui_sockets/index.php
index 4a5de8b..907e489 100644
--- a/mod/chat/gui_sockets/index.php
+++ b/mod/chat/gui_sockets/index.php
@@ -17,7 +17,7 @@ if (!$chat = $DB->get_record('chat', array('id'=>$id))) {
 }
 
 if (!$course = $DB->get_record('course', array('id'=>$chat->course))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $courseid);
 }
 
 if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
diff --git a/mod/chat/index.php b/mod/chat/index.php
index fbc6d37..2309ea2 100644
--- a/mod/chat/index.php
+++ b/mod/chat/index.php
@@ -8,7 +8,7 @@ $id = required_param('id', PARAM_INT);   // course
 $PAGE->set_url('/mod/chat/index.php', array('id'=>$id));
 
 if (! $course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $id);
 }
 
 require_course_login($course);
diff --git a/mod/choice/index.php b/mod/choice/index.php
index e63b876..484a85f 100644
--- a/mod/choice/index.php
+++ b/mod/choice/index.php
@@ -8,7 +8,7 @@
     $PAGE->set_url('/mod/choice/index.php', array('id'=>$id));
 
     if (!$course = $DB->get_record('course', array('id'=>$id))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $id);
     }
 
     require_course_login($course);
diff --git a/mod/data/index.php b/mod/data/index.php
index ba0c179..77c80ed 100644
--- a/mod/data/index.php
+++ b/mod/data/index.php
@@ -31,7 +31,7 @@ $id = required_param('id', PARAM_INT);   // course
 $PAGE->set_url('/mod/data/index.php', array('id'=>$id));
 
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $id);
 }
 
 require_course_login($course);
diff --git a/mod/feedback/analysis.php b/mod/feedback/analysis.php
index da86ecf..2c1961c 100644
--- a/mod/feedback/analysis.php
+++ b/mod/feedback/analysis.php
@@ -64,7 +64,7 @@ if ($courseid AND $courseid != SITEID) {
         require_course_login($course2); //this overwrites the object $course :-(
         $course = $DB->get_record("course", array("id"=>$cm->course)); // the workaround
     } else {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $courseid);
     }
 }
 
diff --git a/mod/feedback/complete.php b/mod/feedback/complete.php
index e6fe6cd..98c005b 100644
--- a/mod/feedback/complete.php
+++ b/mod/feedback/complete.php
@@ -132,7 +132,7 @@ if ($courseid AND $courseid != SITEID) {
         require_course_login($course2); //this overwrites the object $course :-(
         $course = $DB->get_record("course", array("id"=>$cm->course)); // the workaround
     } else {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $courseid);
     }
 }
 
diff --git a/mod/feedback/index.php b/mod/feedback/index.php
index 860a196..abe1579 100644
--- a/mod/feedback/index.php
+++ b/mod/feedback/index.php
@@ -32,7 +32,7 @@ $url = new moodle_url('/mod/feedback/index.php', array('id'=>$id));
 $PAGE->set_url($url);
 
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $id);
 }
 
 if (!$context = get_context_instance(CONTEXT_COURSE, $course->id)) {
diff --git a/mod/feedback/view.php b/mod/feedback/view.php
index 34cfd7f..7ab09f5 100644
--- a/mod/feedback/view.php
+++ b/mod/feedback/view.php
@@ -94,7 +94,7 @@ if ($courseid AND $courseid != SITEID) {
         require_course_login($course2); //this overwrites the object $course :-(
         $course = $DB->get_record("course", array("id"=>$cm->course)); // the workaround
     } else {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $courseid);
     }
 }
 
diff --git a/mod/forum/index.php b/mod/forum/index.php
index c15b40b..18f673f 100644
--- a/mod/forum/index.php
+++ b/mod/forum/index.php
@@ -38,7 +38,7 @@ $PAGE->set_url($url);
 
 if ($id) {
     if (! $course = $DB->get_record('course', array('id' => $id))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $id);
     }
 } else {
     $course = get_site();
diff --git a/mod/forum/lib.php b/mod/forum/lib.php
index 7e0b818..ac08fa9 100644
--- a/mod/forum/lib.php
+++ b/mod/forum/lib.php
@@ -4972,7 +4972,7 @@ function forum_user_can_post($forum, $discussion, $user=NULL, $cm=NULL, $course=
     if (!$course) {
         debugging('missing course', DEBUG_DEVELOPER);
         if (!$course = $DB->get_record('course', array('id' => $forum->course))) {
-            print_error('invalidcourseid');
+            print_error('invalidcourseid', 'error', '', $forum->course);
         }
     }
 
diff --git a/mod/forum/markposts.php b/mod/forum/markposts.php
index a47f049..450f9b9 100644
--- a/mod/forum/markposts.php
+++ b/mod/forum/markposts.php
@@ -45,7 +45,7 @@ if (! $forum = $DB->get_record("forum", array("id" => $f))) {
 }
 
 if (! $course = $DB->get_record("course", array("id" => $forum->course))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $forum->course);
 }
 
 if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
diff --git a/mod/forum/post.php b/mod/forum/post.php
index f3fd922..a5e217a 100644
--- a/mod/forum/post.php
+++ b/mod/forum/post.php
@@ -74,7 +74,7 @@ if (!isloggedin() or isguestuser()) {
         }
     }
     if (! $course = $DB->get_record('course', array('id' => $forum->course))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $forum->course);
     }
 
     if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) { // For the logs
@@ -101,7 +101,7 @@ if (!empty($forum)) {      // User is starting a new discussion in a forum
         print_error('invalidforumid', 'forum');
     }
     if (! $course = $DB->get_record("course", array("id" => $forum->course))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $forum->course);
     }
     if (! $cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
         print_error("invalidcoursemodule");
@@ -166,7 +166,7 @@ if (!empty($forum)) {      // User is starting a new discussion in a forum
         print_error('invalidforumid', 'forum');
     }
     if (! $course = $DB->get_record("course", array("id" => $discussion->course))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $discussion->course);
     }
     if (! $cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
         print_error('invalidcoursemodule');
@@ -247,7 +247,7 @@ if (!empty($forum)) {      // User is starting a new discussion in a forum
         print_error('invalidforumid', 'forum');
     }
     if (! $course = $DB->get_record("course", array("id" => $discussion->course))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $discussion->course);
     }
     if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
         print_error('invalidcoursemodule');
@@ -295,7 +295,7 @@ if (!empty($forum)) {      // User is starting a new discussion in a forum
         print_error('invalidcoursemodule');
     }
     if (!$course = $DB->get_record('course', array('id' => $forum->course))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $forum->course);
     }
 
     require_login($course, false, $cm);
diff --git a/mod/forum/search.php b/mod/forum/search.php
index 9913fac..80ffe97 100644
--- a/mod/forum/search.php
+++ b/mod/forum/search.php
@@ -107,7 +107,7 @@ if ($search) {
 }
 
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $id);
 }
 
 require_course_login($course);
diff --git a/mod/glossary/index.php b/mod/glossary/index.php
index 4eef6df..f8cf5a6 100644
--- a/mod/glossary/index.php
+++ b/mod/glossary/index.php
@@ -13,7 +13,7 @@ $id = required_param('id', PARAM_INT);   // course
 $PAGE->set_url('/mod/glossary/index.php', array('id'=>$id));
 
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $id);
 }
 
 require_course_login($course);
diff --git a/mod/glossary/view.php b/mod/glossary/view.php
index fe16b5e..1f8143b 100644
--- a/mod/glossary/view.php
+++ b/mod/glossary/view.php
@@ -37,7 +37,7 @@ if (!empty($id)) {
         print_error('invalidid', 'glossary');
     }
     if (! $course = $DB->get_record("course", array("id"=>$glossary->course))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $glossary->course);
     }
     if (!$cm = get_coursemodule_from_instance("glossary", $glossary->id, $course->id)) {
         print_error('invalidcoursemodule');
diff --git a/mod/lesson/index.php b/mod/lesson/index.php
index 048f3ff..a11906d 100644
--- a/mod/lesson/index.php
+++ b/mod/lesson/index.php
@@ -33,7 +33,7 @@ $id = required_param('id', PARAM_INT);   // course
 $PAGE->set_url('/mod/lesson/index.php', array('id'=>$id));
 
 if (!$course = $DB->get_record("course", array("id" => $id))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $id);
 }
 
 require_login($course);
@@ -119,4 +119,4 @@ foreach ($lessons as $lesson) {
     }
 }
 echo html_writer::table($table);
-echo $OUTPUT->footer();
\ No newline at end of file
+echo $OUTPUT->footer();
diff --git a/mod/quiz/addrandom.php b/mod/quiz/addrandom.php
index c7f832c..e465a0c 100644
--- a/mod/quiz/addrandom.php
+++ b/mod/quiz/addrandom.php
@@ -42,7 +42,7 @@ $scrollpos = optional_param('scrollpos', 0, PARAM_INT);
 
 // Get the course object and related bits.
 if (!$course = $DB->get_record('course', array('id' => $quiz->course))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $quiz->course);
 }
 //you need mod/quiz:manage in addition to question capabilities to access this page.
 require_capability('mod/quiz:manage', $contexts->lowest());
diff --git a/mod/quiz/index.php b/mod/quiz/index.php
index 926fa2e..aa96b10 100644
--- a/mod/quiz/index.php
+++ b/mod/quiz/index.php
@@ -30,7 +30,7 @@ require_once("locallib.php");
 $id = required_param('id', PARAM_INT);
 $PAGE->set_url('/mod/quiz/index.php', array('id'=>$id));
 if (!$course = $DB->get_record('course', array('id' => $id))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $id);
 }
 $coursecontext = get_context_instance(CONTEXT_COURSE, $id);
 require_login($course->id);
diff --git a/mod/quiz/report.php b/mod/quiz/report.php
index 4ebb4c2..37b8ce3 100644
--- a/mod/quiz/report.php
+++ b/mod/quiz/report.php
@@ -49,7 +49,7 @@ if ($id) {
         print_error('invalidquizid', 'quiz');
     }
     if (!$course = $DB->get_record('course', array('id' => $quiz->course))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $quiz->course);
     }
     if (!$cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) {
         print_error('invalidcoursemodule');
diff --git a/mod/quiz/view.php b/mod/quiz/view.php
index f21f3d9..050150c 100644
--- a/mod/quiz/view.php
+++ b/mod/quiz/view.php
@@ -45,7 +45,7 @@ if ($id) {
         print_error('invalidquizid', 'quiz');
     }
     if (!$course = $DB->get_record('course', array('id' => $quiz->course))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $quiz->course);
     }
     if (!$cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) {
         print_error('invalidcoursemodule');
diff --git a/mod/scorm/index.php b/mod/scorm/index.php
index eea68a2..4e02046 100644
--- a/mod/scorm/index.php
+++ b/mod/scorm/index.php
@@ -23,7 +23,7 @@ $PAGE->set_url('/mod/scorm/index.php', array('id'=>$id));
 
 if (!empty($id)) {
     if (!$course = $DB->get_record('course', array('id'=>$id))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $id);
     }
 } else {
     print_error('missingparameter');
@@ -113,4 +113,4 @@ echo "<br />";
 
 echo html_writer::table($table);
 
-echo $OUTPUT->footer();
\ No newline at end of file
+echo $OUTPUT->footer();
diff --git a/mod/survey/index.php b/mod/survey/index.php
index 6154acf..2e2bb0d 100644
--- a/mod/survey/index.php
+++ b/mod/survey/index.php
@@ -8,7 +8,7 @@
     $PAGE->set_url('/mod/survey/index.php', array('id'=>$id));
 
     if (!$course = $DB->get_record('course', array('id'=>$id))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $id);
     }
 
     require_course_login($course);
diff --git a/mod/wiki/index.php b/mod/wiki/index.php
index 7f13ee2..0a4ac4f 100644
--- a/mod/wiki/index.php
+++ b/mod/wiki/index.php
@@ -38,7 +38,7 @@ $id = required_param('id', PARAM_INT); // course
 $PAGE->set_url('/mod/wiki/index.php', array('id' => $id));
 
 if (!$course = $DB->get_record('course', array('id' => $id))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $id);
 }
 
 require_login($course->id, true);
diff --git a/mod/wiki/search.php b/mod/wiki/search.php
index 518195f..f62b868 100644
--- a/mod/wiki/search.php
+++ b/mod/wiki/search.php
@@ -32,7 +32,7 @@ $searchcontent = optional_param('searchwikicontent', 0, PARAM_INT);
 $cmid = optional_param('cmid', 0, PARAM_INT);
 
 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $courseid);
 }
 if (!$cm = get_coursemodule_from_id('wiki', $cmid)) {
     print_error('invalidcoursemodule');
diff --git a/notes/delete.php b/notes/delete.php
index f69f103..5d2dcf9 100644
--- a/notes/delete.php
+++ b/notes/delete.php
@@ -15,7 +15,7 @@ if (!$note = note_load($noteid)) {
 
 // locate course information
 if (!$course = $DB->get_record('course', array('id'=>$note->courseid))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $note->courseid);
 }
 
 // locate user information
diff --git a/notes/edit.php b/notes/edit.php
index 47aeb2a..b6ce171 100644
--- a/notes/edit.php
+++ b/notes/edit.php
@@ -38,7 +38,7 @@ $PAGE->set_url($url);
 
 /// locate course information
 if (!$course = $DB->get_record('course', array('id'=>$note->courseid))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $note->courseid);
 }
 
 /// locate user information
diff --git a/question/editlib.php b/question/editlib.php
index 14368c3..8c41a26 100644
--- a/question/editlib.php
+++ b/question/editlib.php
@@ -1719,7 +1719,7 @@ function require_login_in_context($contextorid = null){
     } else if ($context && ($context->contextlevel == CONTEXT_MODULE)) {
         if ($cm = $DB->get_record('course_modules',array('id' =>$context->instanceid))) {
             if (!$course = $DB->get_record('course', array('id' => $cm->course))) {
-                print_error('invalidcourseid');
+                print_error('invalidcourseid', 'error', '', $cm->course);
             }
             require_course_login($course, true, $cm);
 
diff --git a/report/progress/index.php b/report/progress/index.php
index bee7249..7ddf0da 100644
--- a/report/progress/index.php
+++ b/report/progress/index.php
@@ -32,7 +32,7 @@ define('COMPLETION_REPORT_PAGE', 25);
 $id = required_param('course',PARAM_INT);
 $course = $DB->get_record('course',array('id'=>$id));
 if (!$course) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $id);
 }
 $context = context_course::instance($course->id);
 
diff --git a/report/stats/index.php b/report/stats/index.php
index 8238cde..57871b9 100644
--- a/report/stats/index.php
+++ b/report/stats/index.php
@@ -48,7 +48,7 @@ if ($mode == STATS_MODE_RANKED) {
 }
 
 if (!$course = $DB->get_record("course", array("id"=>$courseid))) {
-    print_error("invalidcourseid");
+    print_error("invalidcourseid", 'error', '', $courseid);
 }
 
 if (!empty($userid)) {
diff --git a/repository/filepicker.php b/repository/filepicker.php
index 68aee10..6043a6c 100644
--- a/repository/filepicker.php
+++ b/repository/filepicker.php
@@ -71,7 +71,7 @@ $user_context = get_context_instance(CONTEXT_USER, $USER->id);
 
 $PAGE->set_context($user_context);
 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $courseid);
 }
 $PAGE->set_course($course);
 
diff --git a/repository/manage_instances.php b/repository/manage_instances.php
index 5b5d1c8..0410d98 100644
--- a/repository/manage_instances.php
+++ b/repository/manage_instances.php
@@ -75,7 +75,7 @@ if ($context->contextlevel == CONTEXT_COURSE) {
     $pagename = get_string("repositorycourse",'repository');
 
     if ( !$course = $DB->get_record('course', array('id'=>$context->instanceid))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $context->instanceid);
     }
     require_login($course, false);
     // If the user is allowed to edit this course, he's allowed to edit list of repository instances
@@ -134,7 +134,7 @@ echo $OUTPUT->header();
 
 if ($context->contextlevel == CONTEXT_USER) {
     if ( !$course = $DB->get_record('course', array('id'=>$usercourseid))) {
-        print_error('invalidcourseid');
+        print_error('invalidcourseid', 'error', '', $courseid);
     }
 }
 
diff --git a/user/addnote.php b/user/addnote.php
index 5a0d0a8..db36fee 100644
--- a/user/addnote.php
+++ b/user/addnote.php
@@ -34,7 +34,7 @@ $states = optional_param_array('states', array(), PARAM_ALPHA); // array of note
 $PAGE->set_url('/user/addnote.php', array('id'=>$id));
 
 if (! $course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $id);
 }
 
 $context = get_context_instance(CONTEXT_COURSE, $id);
diff --git a/user/edit.php b/user/edit.php
index 6fa1608..c93cb40 100644
--- a/user/edit.php
+++ b/user/edit.php
@@ -39,7 +39,7 @@ $cancelemailchange = optional_param('cancelemailchange', 0, PARAM_INT);   // cou
 $PAGE->set_url('/user/edit.php', array('course'=>$course, 'id'=>$userid));
 
 if (!$course = $DB->get_record('course', array('id'=>$course))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $course);
 }
 
 if ($course->id != SITEID) {
diff --git a/user/groupaddnote.php b/user/groupaddnote.php
index 90f1b3d..996cdab 100644
--- a/user/groupaddnote.php
+++ b/user/groupaddnote.php
@@ -41,7 +41,7 @@ if ($state !== '') {
 $PAGE->set_url($url);
 
 if (! $course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $id);
 }
 
 $context = get_context_instance(CONTEXT_COURSE, $id);
diff --git a/user/messageselect.php b/user/messageselect.php
index d54d26d..f9b11c1 100644
--- a/user/messageselect.php
+++ b/user/messageselect.php
@@ -61,7 +61,7 @@ $PAGE->set_url($url);
 $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
 
 if (!$course = $DB->get_record('course', array('id'=>$id))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $id);
 }
 
 require_login();
diff --git a/user/portfolio.php b/user/portfolio.php
index c91e04e..51c4b7d 100644
--- a/user/portfolio.php
+++ b/user/portfolio.php
@@ -42,7 +42,7 @@ if ($config !== 0) {
     $url->param('config', $config);
 }
 if (! $course = $DB->get_record("course", array("id"=>$courseid))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $courseid);
 }
 
 $user = $USER;
diff --git a/user/portfoliologs.php b/user/portfoliologs.php
index 1690b1f..2a68dae 100644
--- a/user/portfoliologs.php
+++ b/user/portfoliologs.php
@@ -37,7 +37,7 @@ $page     = optional_param('page', 0, PARAM_INT);
 $perpage  = optional_param('perpage', 10, PARAM_INT);
 
 if (! $course = $DB->get_record("course", array("id"=>$courseid))) {
-    print_error('invalidcourseid');
+    print_error('invalidcourseid', 'error', '', $courseid);
 }
 
 require_login($course, false);
