From caf4bef1303e06996a66089e554333ebd39a9da9 Mon Sep 17 00:00:00 2001 From: jungwirr Date: Wed, 24 Sep 2003 17:35:09 +0000 Subject: [PATCH] added export to excel and text feature for reports. Still a bug with export full report to excel in viewweek.php --- mod/attendance/version.php | 2 +- mod/attendance/viewall.php | 224 ++++++++++++++++++++++++-- mod/attendance/viewweek.php | 303 +++++++++++++++++++++++++++++------- 3 files changed, 459 insertions(+), 70 deletions(-) diff --git a/mod/attendance/version.php b/mod/attendance/version.php index 4016a22f38..0d1749c9a8 100644 --- a/mod/attendance/version.php +++ b/mod/attendance/version.php @@ -5,7 +5,7 @@ /// This fragment is called by moodle_needs_upgrading() and /admin/index.php ///////////////////////////////////////////////////////////////////////////////// -$module->version = 2003091802; // The current module version (Date: YYYYMMDDXX) +$module->version = 2003092400; // The current module version (Date: YYYYMMDDXX) $module->cron = 0; // Period for cron to check this module (secs) ?> diff --git a/mod/attendance/viewall.php b/mod/attendance/viewall.php index 7f045524fe..c5d235e1e9 100644 --- a/mod/attendance/viewall.php +++ b/mod/attendance/viewall.php @@ -36,22 +36,11 @@ add_to_log($course->id, "attendance", "viewall", "viewall.php?id=$course->id"); -/// Print the page header - if ($course->category) { - $navigation = "id\">$course->shortname ->"; - } - - $strattendances = get_string("modulenameplural", "attendance"); - $strattendance = get_string("modulename", "attendance"); - $strallattendance = get_string("allmodulename", "attendance"); - print_header("$course->shortname: $strallattendance", "$course->fullname", - "$navigation id>$strattendances -> $strallattendance", - "", "", true, " ", - navmenu($course, $cm)); /// Print the main part of the page if ($attendances) { if ( !(isteacher($course->id) || isstudent($course->id)) ) { + attendance_print_header(); notice(get_string("noviews", "attendance")); print_footer($course); exit; } @@ -81,6 +70,162 @@ if ($attendances) { $numatt++; } + +// +// +// IF REQUESTING A DATA FILE DOWNLOAD, GENERATE IT INSTEAD OF THE HTML PAGE, SEND IT, AND EXIT +// +// + + +if ($download == "xls") { + require_once("../../lib/psxlsgen.php"); + +// add up the total columns that are required for the whole report + $myxls = new PhpSimpleXlsGen(); +if ($dlsub== "all") { + $myxls->totalcol=4+$numatt; // first,last,id ---...---> total +} else { + $myxls->totalcol=4; // first,last,id ---...---> total +} + // print the date headings at the top of the table + // for each day of attendance + $myxls->ChangePos(2,0); + $myxls->InsertText(get_string("lastname")); + $myxls->InsertText(get_string("firstname")); + $myxls->InsertText(get_string("idnumber")); + $pos=3; +if ($dlsub== "all") { + for($k=0;$k<$numatt;$k++) { + // put notes for the date in the date heading + $myxls->ChangePos(0,$pos); + $myxls->InsertText(userdate($atts[$k]->attendance->day,"%m/%0d")); + $myxls->ChangePos(1,$pos); + $myxls->InsertText($atts[$k]->attendance->notes); + $myxls->ChangePos(2,$pos); + for ($i=1;$i<=$atts[$k]->attendance->hours;$i++) { + $myxls->InsertText($i); + $pos++; + } + } +} // if dlsub==all + $myxls->ChangePos(2,$pos); + $myxls->InsertText(get_string("total")); + +/// generate the attendance rolls for the body of the spreadsheet + if (isstudent($course->id)) { + $students[0] = get_user_info_from_db("id", $USER->id); + } else { // must be a teacher + $students = attendance_get_course_students($attendance->course, "u.lastname ASC"); + } + $i=0; + $A = get_string("absentshort","attendance"); + $T = get_string("tardyshort","attendance"); + $P = get_string("presentshort","attendance"); + $row=3; + foreach ($students as $student) { + $myxls->ChangePos($row,0); + $myxls->InsertText($student->lastname); + $myxls->InsertText($student->firstname); + $studentid=(($student->idnumber != "") ? $student->idnumber : " "); + $myxls->InsertText($studentid); + if ($dlsub== "all") { + for($k=0;$k<$numatt;$k++) { // for each day of attendance for the student + for($j=1;$j<=$atts[$k]->attendance->hours;$j++) { + // set the attendance defaults for each student + if ($atts[$k]->sroll[$student->id][$j]->status == 1) {$status=$T;} + elseif ($atts[$k]->sroll[$student->id][$j]->status == 2) {$status=$A;} + else {$status=$P;} + $myxls->InsertText($status); + } /// for loop + } + } + $abs=$tar=0; + for($k=0;$k<$numatt;$k++) { // for eacj day of attendance for the student + for($j=1;$j<=$atts[$k]->attendance->hours;$j++) { + // set the attendance defaults for each student + if ($atts[$k]->sroll[$student->id][$j]->status == 1) {;$tar++;} + elseif ($atts[$k]->sroll[$student->id][$j]->status == 2) {;$abs++;} + } /// for loop + } // outer for for each day of attendance + $tot=tally_overall_absences_decimal($abs,$tar); + $myxls->InsertNumber($tot); + $row++; + } + $myxls->SendFileName($course->shortname."_Attendance"); + + exit; +} + +if ($download == "txt") { + + header("Content-Type: application/download\n"); + header("Content-Disposition: attachment; filename=\"".$course->shortname."_Attendance.txt\""); + +/// Print names of all the fields + + echo get_string("firstname")."\t".get_string("lastname") . "\t". get_string("idnumber"); + +if ($dlsub== "all") { + for($k=0;$k<$numatt;$k++) { + // put notes for the date in the date heading + echo "\t" . userdate($atts[$k]->attendance->day,"%m/%0d"); + echo (($atts[$k]->attendance->notes != "")?" ".$atts[$k]->attendance->notes:""); + for ($i=2;$i<=$atts[$k]->attendance->hours;$i++) { echo "\t$i"; } + } +} // if dlsub==all + echo "\t". get_string("total") . "\n"; + +/// generate the attendance rolls for the body of the spreadsheet + if (isstudent($course->id)) { + $students[0] = get_user_info_from_db("id", $USER->id); + } else { // must be a teacher + $students = attendance_get_course_students($attendance->course, "u.lastname ASC"); + } + $i=0; + $A = get_string("absentshort","attendance"); + $T = get_string("tardyshort","attendance"); + $P = get_string("presentshort","attendance"); + $row=3; + foreach ($students as $student) { + echo $student->lastname; + echo "\t".$student->firstname; + $studentid=(($student->idnumber != "") ? $student->idnumber : " "); + echo "\t". $studentid; + if ($dlsub== "all") { + for($k=0;$k<$numatt;$k++) { // for each day of attendance for the student + for($j=1;$j<=$atts[$k]->attendance->hours;$j++) { + // set the attendance defaults for each student + if ($atts[$k]->sroll[$student->id][$j]->status == 1) {$status=$T;} + elseif ($atts[$k]->sroll[$student->id][$j]->status == 2) {$status=$A;} + else {$status=$P;} + echo "\t".$status; + } /// for loop + } + } + $abs=$tar=0; + for($k=0;$k<$numatt;$k++) { // for eacj day of attendance for the student + for($j=1;$j<=$atts[$k]->attendance->hours;$j++) { + // set the attendance defaults for each student + if ($atts[$k]->sroll[$student->id][$j]->status == 1) {;$tar++;} + elseif ($atts[$k]->sroll[$student->id][$j]->status == 2) {;$abs++;} + } /// for loop + } // outer for for each day of attendance + $tot=tally_overall_absences_decimal($abs,$tar); + echo "\t".$tot."\n"; + $row++; + } + exit; +} + + + +// +// +// FIGURE OUT THE PAGING LAYOUT FOR THE DATA BASED ON STATUS, PAGE NUMBER REQUESTED, ETC +// +// + // A LOOP FOR CREATING SINGLE-USER VERSION OF THE REPORT OR A ONE-PAGE REPORT if (isstudent($course->id)) { $onepage=true; @@ -142,11 +287,17 @@ while (($multipage || $onepage) && (!$endonepage)) { if ((!$pagereport) || ($page == $maxpages)) {$endonepage = true;} // end a one page display + + + + + // // // ALL PRELIMINARY STUFF DONE - MAKE THE MEAT OF THE PAGE // // + attendance_print_header(); // print other links at top of page $strviewone = get_string("viewone", "attendance"); @@ -282,11 +433,58 @@ if ($onepage) {$page++; echo "

\n"; } } // while loop for multipage/one page printing if (!$onepage) { attendance_print_pagenav(); } + + + echo "
"; + echo "
"; + if (($numhours-4) > 255) { + echo "
"; + } else { + $options["id"] = "$course->id"; + $options["download"] = "xls"; + $options["dlsub"] = "all"; + print_single_button("viewall.php", $options, get_string("downloadexcelfull", "attendance")); + } + echo "
"; + $options["id"] = "$course->id"; + $options["download"] = "xls"; + $options["dlsub"] = "totals"; + print_single_button("viewall.php", $options, get_string("downloadexceltotals", "attendance")); + echo ""; + $options["download"] = "txt"; + $options["dlsub"] = "all"; + print_single_button("viewall.php", $options, get_string("downloadtextfull", "attendance")); + echo ""; + $options["dlsub"] = "totals"; + print_single_button("viewall.php", $options, get_string("downloadtexttotals", "attendance")); + echo "
"; + - } else { error("There are no attendance rolls in this course.");} // for no attendance rolls +} else { error("There are no attendance rolls in this course.");} // for no attendance rolls /// Finish the page + + print_footer($course); +function attendance_print_header() { + global $course, $cm; + + /// Print the page header + if ($course->category) { + $navigation = "id\">$course->shortname ->"; + } + + $strattendances = get_string("modulenameplural", "attendance"); + $strattendance = get_string("modulename", "attendance"); + $strallattendance = get_string("allmodulename", "attendance"); + print_header("$course->shortname: $strallattendance", "$course->fullname", + "$navigation id>$strattendances -> $strallattendance", + "", "", true, " ", + navmenu($course, $cm)); +} + function attendance_print_pagenav() { global $pagereport, $minatt, $maxatt, $course, $page, $numatt, $maxpages; if ($pagereport) { diff --git a/mod/attendance/viewweek.php b/mod/attendance/viewweek.php index 556ff261d9..084ab63b0d 100644 --- a/mod/attendance/viewweek.php +++ b/mod/attendance/viewweek.php @@ -30,76 +30,23 @@ } } } -// echo "
\n";
-//    foreach ($attendances as $attendance) {
-//    var_dump($attendances);
-//    }
-//    echo "\n
"; -// print_footer(); -// exit; - + require_login($course->id); add_to_log($course->id, "attendance", "viewweek", "viewweek.php?scope=".$scope."&id=$course->id"); -/// Print the page header - if ($course->category) { - $navigation = "id\">$course->shortname ->"; - } - - $strattendances = get_string("modulenameplural", "attendance"); - $strattendance = get_string("modulename", "attendance"); - $strweekattendance = get_string("weekmodulename", "attendance"); - print_header("$course->shortname: $strallattendance", "$course->fullname", - "$navigation id>$strattendances -> $strweekattendance", - "", "", true, " ", - navmenu($course, $cm)); -/// Print the main part of the page if ($attendances) { if ( !(isteacher($course->id) || isstudent($course->id)) ) { + attendance_print_header(); notice(get_string("noviews", "attendance")); print_footer($course); exit; } -// print other links at top of page - $strviewsection = get_string("viewsection", "attendance"); - $strviewweek = get_string("viewweek", "attendance"); - $strviewall = get_string("viewall", "attendance"); - $strviewone = get_string("viewone", "attendance"); - $strviewtable = get_string("viewtable", "attendance"); - $strviewmulti = get_string("viewmulti", "attendance"); - - - echo "

id."\">"; - echo "$strviewall
"; - if ($onepage) { // one page for all tables - echo ""; - echo "$strviewmulti
"; - echo ""; - echo "$strviewtable
"; - } else if ($onetable) { // one table for all - echo ""; - echo "$strviewmulti
"; - echo ""; - echo "$strviewone
"; - } else { // multiple pages - echo ""; - echo "$strviewone
"; - echo ""; - echo "$strviewtable
"; - } - if ($scope=="week") { // week view for scope - echo ""; - echo "$strviewsection

"; - } else { // section view for scope - echo ""; - echo "$strviewweek

"; - } -/// create an array of all the attendance objects for the entire course +/// create an array of all the attendance objects for the week $numatt=0; $numhours=0; foreach ($attendances as $attendance){ @@ -123,6 +70,164 @@ if ($attendances) { $numatt++; } + +// +// +// IF REQUESTING A DATA FILE DOWNLOAD, GENERATE IT INSTEAD OF THE HTML PAGE, SEND IT, AND EXIT +// +// + + +if ($download == "xls") { + require_once("../../lib/psxlsgen.php"); + +// add up the total columns that are required for the whole report + $myxls = new PhpSimpleXlsGen(); +if ($dlsub== "all") { + $myxls->totalcol=4+$numatt; // first,last,id ---...---> total +} else { + $myxls->totalcol=4; // first,last,id ---...---> total +} + // print the date headings at the top of the table + // for each day of attendance + $myxls->ChangePos(2,0); + $myxls->InsertText(get_string("lastname")); + $myxls->InsertText(get_string("firstname")); + $myxls->InsertText(get_string("idnumber")); + $pos=3; +if ($dlsub== "all") { + for($k=0;$k<$numatt;$k++) { + // put notes for the date in the date heading + $myxls->ChangePos(0,$pos); + $myxls->InsertText(userdate($atts[$k]->attendance->day,"%m/%0d")); + $myxls->ChangePos(1,$pos); + $myxls->InsertText($atts[$k]->attendance->notes); + $myxls->ChangePos(2,$pos); + for ($i=1;$i<=$atts[$k]->attendance->hours;$i++) { + $myxls->InsertText($i); + $pos++; + } + } +} // if dlsub==all + $myxls->ChangePos(2,$pos); + $myxls->InsertText(get_string("total")); + +/// generate the attendance rolls for the body of the spreadsheet + if (isstudent($course->id)) { + $students[0] = get_user_info_from_db("id", $USER->id); + } else { // must be a teacher + $students = attendance_get_course_students($attendance->course, "u.lastname ASC"); + } + $i=0; + $A = get_string("absentshort","attendance"); + $T = get_string("tardyshort","attendance"); + $P = get_string("presentshort","attendance"); + $row=3; + foreach ($students as $student) { + $myxls->ChangePos($row,0); + $myxls->InsertText($student->lastname); + $myxls->InsertText($student->firstname); + $studentid=(($student->idnumber != "") ? $student->idnumber : " "); + $myxls->InsertText($studentid); + if ($dlsub== "all") { + for($k=0;$k<$numatt;$k++) { // for each day of attendance for the student + for($j=1;$j<=$atts[$k]->attendance->hours;$j++) { + // set the attendance defaults for each student + if ($atts[$k]->sroll[$student->id][$j]->status == 1) {$status=$T;} + elseif ($atts[$k]->sroll[$student->id][$j]->status == 2) {$status=$A;} + else {$status=$P;} + $myxls->InsertText($status); + } /// for loop + } + } + $abs=$tar=0; + for($k=0;$k<$numatt;$k++) { // for eacj day of attendance for the student + for($j=1;$j<=$atts[$k]->attendance->hours;$j++) { + // set the attendance defaults for each student + if ($atts[$k]->sroll[$student->id][$j]->status == 1) {;$tar++;} + elseif ($atts[$k]->sroll[$student->id][$j]->status == 2) {;$abs++;} + } /// for loop + } // outer for for each day of attendance + $tot=tally_overall_absences_decimal($abs,$tar); + $myxls->InsertNumber($tot); + $row++; + } + $myxls->SendFileName($course->shortname."_Attendance_Week"); + + exit; +} + +if ($download == "txt") { + + header("Content-Type: application/download\n"); + header("Content-Disposition: attachment; filename=\"".$course->shortname."_Attendance_Week.txt\""); + +/// Print names of all the fields + + echo get_string("firstname")."\t".get_string("lastname") . "\t". get_string("idnumber"); + +if ($dlsub== "all") { + for($k=0;$k<$numatt;$k++) { + // put notes for the date in the date heading + echo "\t" . userdate($atts[$k]->attendance->day,"%m/%0d"); + echo (($atts[$k]->attendance->notes != "")?" ".$atts[$k]->attendance->notes:""); + for ($i=2;$i<=$atts[$k]->attendance->hours;$i++) { echo "\t$i"; } + } +} // if dlsub==all + echo "\t". get_string("total") . "\n"; + +/// generate the attendance rolls for the body of the spreadsheet + if (isstudent($course->id)) { + $students[0] = get_user_info_from_db("id", $USER->id); + } else { // must be a teacher + $students = attendance_get_course_students($attendance->course, "u.lastname ASC"); + } + $i=0; + $A = get_string("absentshort","attendance"); + $T = get_string("tardyshort","attendance"); + $P = get_string("presentshort","attendance"); + $row=3; + foreach ($students as $student) { + echo $student->lastname; + echo "\t".$student->firstname; + $studentid=(($student->idnumber != "") ? $student->idnumber : " "); + echo "\t". $studentid; + if ($dlsub== "all") { + for($k=0;$k<$numatt;$k++) { // for each day of attendance for the student + for($j=1;$j<=$atts[$k]->attendance->hours;$j++) { + // set the attendance defaults for each student + if ($atts[$k]->sroll[$student->id][$j]->status == 1) {$status=$T;} + elseif ($atts[$k]->sroll[$student->id][$j]->status == 2) {$status=$A;} + else {$status=$P;} + echo "\t".$status; + } /// for loop + } + } + $abs=$tar=0; + for($k=0;$k<$numatt;$k++) { // for eacj day of attendance for the student + for($j=1;$j<=$atts[$k]->attendance->hours;$j++) { + // set the attendance defaults for each student + if ($atts[$k]->sroll[$student->id][$j]->status == 1) {;$tar++;} + elseif ($atts[$k]->sroll[$student->id][$j]->status == 2) {;$abs++;} + } /// for loop + } // outer for for each day of attendance + $tot=tally_overall_absences_decimal($abs,$tar); + echo "\t".$tot."\n"; + $row++; + } + exit; +} + + + +// +// +// FIGURE OUT THE PAGING LAYOUT FOR THE DATA BASED ON STATUS, PAGE NUMBER REQUESTED, ETC +// +// + + + if (isstudent($course->id)) { $onepage=true; $multipage=false; @@ -188,6 +293,44 @@ while (($multipage || $onepage) && (!$endonepage)) { // ALL PRELIMINARY STUFF DONE - MAKE THE MEAT OF THE PAGE // // + attendance_print_header(); + + +// print other links at top of page + $strviewsection = get_string("viewsection", "attendance"); + $strviewweek = get_string("viewweek", "attendance"); + $strviewall = get_string("viewall", "attendance"); + $strviewone = get_string("viewone", "attendance"); + $strviewtable = get_string("viewtable", "attendance"); + $strviewmulti = get_string("viewmulti", "attendance"); + + + echo "

id."\">"; + echo "$strviewall
"; + if ($onepage) { // one page for all tables + echo ""; + echo "$strviewmulti
"; + echo ""; + echo "$strviewtable
"; + } else if ($onetable) { // one table for all + echo ""; + echo "$strviewmulti
"; + echo ""; + echo "$strviewone
"; + } else { // multiple pages + echo ""; + echo "$strviewone
"; + echo ""; + echo "$strviewtable
"; + } + if ($scope=="week") { // week view for scope + echo ""; + echo "$strviewsection

"; + } else { // section view for scope + echo ""; + echo "$strviewweek

"; + } + if (!$onepage) { @@ -297,6 +440,36 @@ if ($onepage) {$page++; echo "

\n"; } if (!$onepage) { attendance_print_pagenav(); } + + echo "
"; + echo "
"; + if (($numhours-4) > 255) { + echo "
"; + } else { + $options["id"] = "$id"; + $options["download"] = "xls"; + $options["dlsub"] = "all"; + print_single_button("viewweek.php", $options, get_string("downloadexcelfull", "attendance")); + } + echo "
"; + $options["id"] = "$id"; + $options["download"] = "xls"; + $options["dlsub"] = "totals"; + print_single_button("viewweek.php", $options, get_string("downloadexceltotals", "attendance")); + echo ""; + $options["download"] = "txt"; + $options["dlsub"] = "all"; + print_single_button("viewweek.php", $options, get_string("downloadtextfull", "attendance")); + echo ""; + $options["dlsub"] = "totals"; + print_single_button("viewweek.php", $options, get_string("downloadtexttotals", "attendance")); + echo "
"; + + + + } else { error("There are no attendance rolls in this course.");} // for no attendance rolls /// Finish the page print_footer($course); @@ -331,4 +504,22 @@ function attendance_print_pagenav() { } } +function attendance_print_header() { + global $course, $cm; + + +/// Print the page header + if ($course->category) { + $navigation = "id\">$course->shortname ->"; + } + + $strattendances = get_string("modulenameplural", "attendance"); + $strattendance = get_string("modulename", "attendance"); + $strweekattendance = get_string("weekmodulename", "attendance"); + print_header("$course->shortname: $strallattendance", "$course->fullname", + "$navigation id>$strattendances -> $strweekattendance", + "", "", true, " ", + navmenu($course, $cm)); +} + ?> -- 2.39.5