MDL-10873 If both site default and user pref are empty for studentsperpage, we assume...
[moodle-pu.git] / course / grade.php
blob48182377b0cc6a20b4c6caffb24eec903c2255de
1 <?php // $Id$
2 // Displays all grades for a student in a course
4 require_once("../config.php");
5 require_once("lib.php");
7 $id = required_param('id',PARAM_INT); // course id
9 if (! $course = get_record("course", "id", $id)) {
10 error("Course ID was incorrect");
13 if (!$course->showgrades) {
14 error("Grades are not available for students in this course");
17 require_login($course->id);
19 $strgrades = get_string("grades");
20 $strgrade = get_string("grade");
21 $strmax = get_string("maximumshort");
22 $stractivityreport = get_string("activityreport");
25 /// Get a list of all students
27 $columnhtml = array(); // Accumulate column html in this array.
28 $grades = array(); // Collect all grades in this array
29 $maxgrades = array(); // Collect all max grades in this array
30 $totalgrade = 0;
31 $totalmaxgrade = 0;
34 /// Collect modules data
35 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
38 /// Search through all the modules, pulling out grade data
39 $sections = get_all_sections($course->id); // Sort everything the same as the course
40 for ($i=0; $i<=$course->numsections; $i++) {
41 if (isset($sections[$i])) { // should always be true
42 $section = $sections[$i];
43 if (!empty($section->sequence)) {
44 $sectionmods = explode(",", $section->sequence);
45 foreach ($sectionmods as $sectionmod) {
46 $mod = $mods[$sectionmod];
47 if ($mod->visible) {
48 $instance = get_record("$mod->modname", "id", "$mod->instance");
49 $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php";
50 if (file_exists($libfile)) {
51 require_once($libfile);
52 $gradefunction = $mod->modname."_grades";
53 if (function_exists($gradefunction)) { // Skip modules without grade function
54 if ($modgrades = $gradefunction($mod->instance)) {
56 $image = "<a href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\"".
57 " title=\"$mod->modfullname\">".
58 "<img valign=\"middle\" src=\"../mod/$mod->modname/icon.gif\" ".
59 "class=\"icon\" alt=\"$mod->modfullname\" /></a>";
60 $columnhtml[] = "$image ".
61 "<a href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">".
62 format_string($instance->name,true).
63 "</a>";
65 if (empty($modgrades->grades[$USER->id])) {
66 $grades[] = "";
67 } else {
68 $grades[] = $modgrades->grades[$USER->id];
69 $totalgrade += (float)$modgrades->grades[$USER->id];
72 if (empty($modgrades->maxgrade)) {
73 $maxgrades[] = "";
74 } else {
75 $maxgrades[] = $modgrades->maxgrade;
76 $totalmaxgrade += $modgrades->maxgrade;
88 /// OK, we have all the data, now present it to the user
90 print_header("$course->shortname: $strgrades", $course->fullname,
91 "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>
92 -> $strgrades");
94 print_heading($strgrades);
96 $table->head = array( get_string("activity"), get_string("maximumgrade"), get_string("grade"));
97 $table->align = array("LEFT", "RIGHT", "RIGHT");
99 foreach ($grades as $key => $grade) {
100 $table->data[] = array($columnhtml[$key], $maxgrades[$key], $grade);
103 $table->data[] = array(get_string("total"), $totalmaxgrade, $totalgrade);
105 print_table($table);
107 print_continue("view.php?id=$course->id");
109 print_footer($course);