From: moodler Date: Thu, 17 Oct 2002 10:34:11 +0000 (+0000) Subject: The grades page now supports downloading of grade data! :-) X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=952489e16c126a898559ca203611047b8d6052a7;p=moodle.git The grades page now supports downloading of grade data! :-) --- diff --git a/RELEASE.html b/RELEASE.html index fcdcec4eae..74d751553f 100644 --- a/RELEASE.html +++ b/RELEASE.html @@ -4,17 +4,22 @@ diff --git a/course/grades.php b/course/grades.php index c6ef5f915e..3acc4e9cc2 100644 --- a/course/grades.php +++ b/course/grades.php @@ -3,8 +3,12 @@ require("../config.php"); require("lib.php"); + require("$CFG->libdir/psxlsgen.php"); - require_variable($id); // course id + + + require_variable($id); // course id + optional_variable($download, ""); // to download data if (! $course = get_record("course", "id", $id)) { error("Course ID was incorrect"); @@ -22,13 +26,7 @@ $stractivityreport = get_string("activityreport"); -/// Otherwise fill and print the form. - - print_header("$course->shortname: $strgrades", "$course->fullname", - "wwwroot/course/view.php?id=$course->id\">$course->shortname - -> $strgrades"); - - print_heading($strgrades); +/// Get a list of all students if (!$students = get_course_students($course->id)) { print_heading(get_string("nostudentsyet")); @@ -40,11 +38,15 @@ $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. + $columns = array(); // Accumulate column names in this array. + $columnhtml = array(); // Accumulate column html in this array. + - // Collect module data +/// Collect modules data get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused, $modsectioncounts); + +/// Search through all the modules, pulling out grade data $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 @@ -71,10 +73,11 @@ " TITLE=\"$mod->modfullname\">". "modname/icon.gif\" ". "HEIGHT=16 WIDTH=16 ALT=\"$mod->modfullname\">"; - $columns[] = "$image ". + $columnhtml[] = "$image ". "wwwroot/mod/$mod->modname/view.php?id=$mod->id\">". "$instance->name". "$maxgrade"; + $columns[] = "$mod->modfullname: $instance->name - $modgrades->maxgrade"; foreach ($students as $student) { $grades[$student->id][] = $modgrades->grades[$student->id]; // may be empty, that's ok @@ -89,29 +92,117 @@ } } // 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", "id&user=$student->id\">$student->firstname $student->lastname"); - $total = array ($totals[$student->id]); +/// OK, we have all the data, now present it to the user - - $table->data[] = array_merge($name, $gradelist, $total); - } + if ($download == "xls") { + + $myxls = new PhpSimpleXlsGen(); + $myxls->totalcol = count($columns) + 5; + +/// Print names of all the fields + + $myxls->ChangePos(0,0); + $myxls->InsertText(get_string("firstname")); + $myxls->InsertText(get_string("lastname")); + foreach ($columns as $column) { + $myxls->InsertText($column); + } + $myxls->InsertText(get_string("total")); + + +/// Print all the lines of data. + + $i = 0; + foreach ($grades as $studentid => $studentgrades) { + $i++; + $student = $students[$studentid]; + + $myxls->ChangePos($i,0); + $myxls->InsertText($student->firstname); + $myxls->InsertText($student->lastname); + + foreach ($studentgrades as $grade) { + $myxls->InsertNumber($grade); + } + $myxls->InsertNumber($totals[$student->id]); + } + + $myxls->SendFile("$course->shortname $strgrades"); + + exit; - print_table($table); - print_footer($course); + } else if ($download == "txt") { +/// Print header to force download + + header("Content-Type: application/download\n"); + header("Content-Disposition: attachment; filename=\"$course->shortname $strgrades.txt\""); + +/// Print names of all the fields + + echo get_string("firstname")."\t".get_string("lastname"); + foreach ($columns as $column) { + echo "\t$column"; + } + echo "\t".get_string("total")."\n"; + +/// Print all the lines of data. + + foreach ($grades as $studentid => $studentgrades) { + $student = $students[$studentid]; + echo "$student->firstname\t$student->lastname"; + foreach ($studentgrades as $grade) { + echo "\t$grade"; + } + echo "\t".$totals[$student->id]; + echo "\n"; + } + + exit; + + + } else { // Just print the web page + + print_header("$course->shortname: $strgrades", "$course->fullname", + "wwwroot/course/view.php?id=$course->id\">$course->shortname + -> $strgrades"); + + print_heading($strgrades); + + $table->head = array_merge(array ("", get_string("name")), $columnhtml, 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 => $studentgrades) { + $student = $students[$studentid]; + $picture = print_user_picture($student->id, $course->id, $student->picture, false, true); + $name = array ("$picture", "id&user=$student->id\">$student->firstname $student->lastname"); + $total = array ($totals[$student->id]); + + $table->data[] = array_merge($name, $studentgrades, $total); + } + + print_table($table); + + echo ""; + echo "
"; + $options["id"] = "$course->id"; + $options["download"] = "xls"; + print_single_button("grades.php", $options, get_string("downloadexcel")); + echo ""; + $options["download"] = "txt"; + print_single_button("grades.php", $options, get_string("downloadtext")); + echo "
"; + + print_footer($course); + } + ?> diff --git a/lang/en/moodle.php b/lang/en/moodle.php index e5c29fce90..755d894a06 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -106,6 +106,8 @@ $string['deletednot'] = "Could not delete \$a !"; $string['deletingcourse'] = "Deleting \$a"; $string['description'] = "Description"; $string['doyouagree'] = "Have you read these conditions and understood them?"; +$string['downloadexcel'] = "Download in Excel format"; +$string['downloadtext'] = "Download in text format"; $string['edit'] = "Edit \$a"; $string['editcoursesettings'] = "Edit course settings"; $string['editinga'] = "Editing a \$a"; diff --git a/version.php b/version.php index d7e0504865..c6f0c0bbb0 100644 --- a/version.php +++ b/version.php @@ -5,7 +5,7 @@ // database to determine whether upgrades should // be performed (see lib/db/*.php) -$version = 2002101500; // The current version is a date (YYYYMMDDXX) +$version = 2002101700; // The current version is a date (YYYYMMDDXX) -$release = "1.0.6 dev"; // User-friendly version number +$release = "1.0.6 dev 2"; // User-friendly version number