--- course/user.php
+++ course/user.php
@@ -270,6 +270,12 @@ switch ($mode) {
         get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
         $sections = get_all_sections($course->id);
 
+        if ($course->numsections <= 0) {
+            $error = get_string('nocoursesections', 'grades');
+            echo $OUTPUT->notification($error);
+            break;
+        }
+        
         for ($i=0; $i<=$course->numsections; $i++) {
 
             if (isset($sections[$i])) {   // should always be true
--- lang/en/grades.php
+++ lang/en/grades.php
@@ -411,6 +411,7 @@ $string['nocategories'] = 'Grade categories could not be added or found for this
 $string['nocategoryname'] = 'No category name was given.';
 $string['nocategoryview'] = 'No category to view by';
 $string['nocourses'] = 'There are no courses yet';
+$string['nocoursesections'] = 'There are no course sections to report upon.';
 $string['noforce'] = 'Do not force';
 $string['nogradeletters'] = 'No grade letters set';
 $string['nogradesreturned'] = 'No grades returned';
