From fdf4b0c1bb1aacb1130c7fb0a5f9ee827e4b6e30 Mon Sep 17 00:00:00 2001 From: moodler Date: Fri, 26 Sep 2003 04:19:21 +0000 Subject: [PATCH] Upgraded gradebook to use the new Excel library. Most of these changes are from Russell Jungwirth - thanks! I also moved the download buttons to the top - better for BIG classes. --- course/grades.php | 81 +++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/course/grades.php b/course/grades.php index 5f18c631d9..8cd7eca81a 100644 --- a/course/grades.php +++ b/course/grades.php @@ -1,9 +1,8 @@ id, "u.lastname ASC")) { - print_header("$course->shortname: $strgrades", "$course->fullname", + print_header("$course->shortname: $strgrades", "$course->fullname", "wwwroot/course/view.php?id=$course->id\">$course->shortname -> $strgrades"); print_heading(get_string("nostudentsyet")); @@ -125,22 +124,31 @@ /// OK, we have all the data, now present it to the user - if ($download == "xls") { - - $myxls = new PhpSimpleXlsGen(); - $myxls->totalcol = count($columns) + 5; - + require_once("../lib/excel/Worksheet.php"); + require_once("../lib/excel/Workbook.php"); + +// HTTP headers + header("Content-type: application/vnd.ms-excel"); + header("Content-Disposition: attachment; filename=".$course->shortname."_$strgrades.xls"); + header("Expires: 0"); + header("Cache-Control: must-revalidate,post-check=0,pre-check=0"); + header("Pragma: public"); + +/// Creating a workbook + $workbook = new Workbook("-"); + $myxls =& $workbook->add_worksheet('$strgrades'); + /// Print names of all the fields - $myxls->ChangePos(0,0); - $myxls->InsertText(get_string("firstname")); - $myxls->InsertText(get_string("lastname")); + $myxls->write_string(0,0,get_string("firstname")); + $myxls->write_string(0,1,get_string("lastname")); + $pos=2; foreach ($columns as $column) { - $myxls->InsertText(strip_tags($column)); + $myxls->write_string(0,$pos++,strip_tags($column)); } - $myxls->InsertText(get_string("total")); - + $myxls->write_string(0,$pos,get_string("total")); + /// Print all the lines of data. @@ -148,22 +156,20 @@ foreach ($grades as $studentid => $studentgrades) { $i++; $student = $students[$studentid]; - - $myxls->ChangePos($i,0); - $myxls->InsertText($student->firstname); - $myxls->InsertText($student->lastname); - + + $myxls->write_string($i,0,$student->firstname); + $myxls->write_string($i,1,$student->lastname); + $j=2; foreach ($studentgrades as $grade) { - $myxls->InsertText(strip_tags($grade)); + $myxls->write_string($i,$j++,strip_tags($grade)); } - $myxls->InsertNumber($totals[$student->id]); + $myxls->write_number($i,$j,$totals[$student->id]); } - - $myxls->SendFileName("$course->shortname $strgrades"); - + + $workbook->close(); + exit; - } else if ($download == "txt") { /// Print header to force download @@ -198,12 +204,23 @@ } else { // Just print the web page - print_header("$course->shortname: $strgrades", "$course->fullname", + print_header("$course->shortname: $strgrades", "$course->fullname", "wwwroot/course/view.php?id=$course->id\">$course->shortname -> $strgrades"); print_heading($strgrades); + 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 "
"; + + $table->head = array_merge(array ("", get_string("firstname"), get_string("lastname")), $columnhtml, get_string("total")); $table->width = array(35, ""); $table->align = array("LEFT", "RIGHT", "LEFT"); @@ -225,16 +242,6 @@ 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); } -- 2.39.5