]> git.mjollnir.org Git - moodle.git/commitdiff
Re-adding to overcome CVS strangeness (and my own indecision!)
authormoodler <moodler>
Thu, 17 Oct 2002 08:30:41 +0000 (08:30 +0000)
committermoodler <moodler>
Thu, 17 Oct 2002 08:30:41 +0000 (08:30 +0000)
course/grades.php [new file with mode: 0644]
pix/i/grades.gif [new file with mode: 0755]

diff --git a/course/grades.php b/course/grades.php
new file mode 100644 (file)
index 0000000..c6ef5f9
--- /dev/null
@@ -0,0 +1,117 @@
+<?PHP // $Id$
+      // Displays all grades for a course
+
+       require("../config.php");
+       require("lib.php");
+
+    require_variable($id);   // course id
+
+    if (! $course = get_record("course", "id", $id)) {
+        error("Course ID was incorrect");
+    }
+
+       require_login($course->id);
+
+    if (!isteacher($course->id)) {
+        error("Only teachers can use this page!");
+    }
+
+    $strgrades = get_string("grades");
+    $strgrade = get_string("grade");
+    $strmax = get_string("maximumshort");
+    $stractivityreport = get_string("activityreport");
+
+
+/// Otherwise fill and print the form.
+
+       print_header("$course->shortname: $strgrades", "$course->fullname", 
+                 "<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> 
+                  -> $strgrades");
+
+    print_heading($strgrades);
+
+    if (!$students = get_course_students($course->id)) {
+        print_heading(get_string("nostudentsyet"));
+        print_footer($course);
+        exit;
+    }
+
+    foreach ($students as $student) {
+        $grades[$student->id] = array();    // Collect all grades in this array
+        $totals[$student->id] = array();    // Collect all totals in this array
+    }
+    $columns = array();  // Accumulate column names in this array.
+
+    // Collect module data
+    get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused, $modsectioncounts);
+
+    $sections = get_all_sections($course->id); // Sort everything the same as the course
+    for ($i=0; $i<=$course->numsections; $i++) {
+        if (isset($sections[$i])) {   // should always be true
+            $section = $sections[$i];
+            if ($section->sequence) {
+                $sectionmods = explode(",", $section->sequence);
+                foreach ($sectionmods as $sectionmod) {
+                    $mod = $mods[$sectionmod];
+                    $instance = get_record("$mod->modname", "id", "$mod->instance");
+                    $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php";
+                    if (file_exists($libfile)) {
+                        require_once($libfile);
+                        $gradefunction = $mod->modname."_grades";
+                        if (function_exists($gradefunction)) {   // Skip modules without grade function
+                            $modgrades = $gradefunction($mod->instance);
+
+                            if ($modgrades->maxgrade) {
+                                $maxgrade = "<BR>$strmax: $modgrades->maxgrade";
+                            } else {
+                                $maxgrade = "";
+                            }
+
+                            $image = "<A HREF=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\"".
+                                     "   TITLE=\"$mod->modfullname\">".
+                                     "<IMG BORDER=0 VALIGN=absmiddle SRC=\"../mod/$mod->modname/icon.gif\" ".
+                                     "HEIGHT=16 WIDTH=16 ALT=\"$mod->modfullname\"></A>";
+                            $columns[] = "$image ".
+                                         "<A HREF=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">".
+                                         "$instance->name".
+                                         "</A>$maxgrade";
+
+                            foreach ($students as $student) {
+                                $grades[$student->id][] = $modgrades->grades[$student->id]; // may be empty, that's ok
+                                if ($modgrades->maxgrade) {
+                                    $totals[$student->id] = (float)($totals[$student->id]) + (float)($modgrades->grades[$student->id]);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    } // a new Moodle nesting record? ;-)
+
+    $table->head  = array ("", get_string("name"));
+    $table->head  = array_merge(array ("", get_string("name")), $columns, get_string("total"));
+    $table->width = array(35, "");
+    $table->align = array("LEFT", "LEFT");
+    foreach ($columns as $column) {
+        $table->width[] = "";
+        $table->align[] = "CENTER";
+    }
+    $table->width[] = "";
+    $table->align[] = "CENTER";
+
+    foreach ($grades as $studentid => $gradelist) {
+        $student = $students[$studentid];
+        $picture = print_user_picture($student->id, $course->id, $student->picture, false, true);
+        $name = array ("$picture", "<A TITLE=\"$stractivityreport\" HREF=\"user.php?id=$course->id&user=$student->id\">$student->firstname&nbsp;$student->lastname</A>");
+        $total = array ($totals[$student->id]);
+
+        
+        $table->data[] = array_merge($name, $gradelist, $total);
+    }
+
+    print_table($table);
+
+    print_footer($course);
+
+?>
diff --git a/pix/i/grades.gif b/pix/i/grades.gif
new file mode 100755 (executable)
index 0000000..355e734
Binary files /dev/null and b/pix/i/grades.gif differ