From 872d7f598cc4683e4f104bfe2d8903795481bec8 Mon Sep 17 00:00:00 2001 From: moodler Date: Tue, 16 Sep 2003 05:33:54 +0000 Subject: [PATCH] New module Attendance, by Russell Jungwirth. --- mod/attendance/README.txt | 23 +++ mod/attendance/db/mysql.php | 18 +++ mod/attendance/db/mysql.sql | 30 ++++ mod/attendance/icon.gif | Bin 0 -> 876 bytes mod/attendance/index.php | 78 +++++++++ mod/attendance/lib.php | 302 +++++++++++++++++++++++++++++++++++ mod/attendance/mod.html | 143 +++++++++++++++++ mod/attendance/version.php | 11 ++ mod/attendance/view.php | 141 +++++++++++++++++ mod/attendance/viewall.php | 305 ++++++++++++++++++++++++++++++++++++ 10 files changed, 1051 insertions(+) create mode 100644 mod/attendance/README.txt create mode 100644 mod/attendance/db/mysql.php create mode 100755 mod/attendance/db/mysql.sql create mode 100644 mod/attendance/icon.gif create mode 100644 mod/attendance/index.php create mode 100755 mod/attendance/lib.php create mode 100755 mod/attendance/mod.html create mode 100644 mod/attendance/version.php create mode 100644 mod/attendance/view.php create mode 100644 mod/attendance/viewall.php diff --git a/mod/attendance/README.txt b/mod/attendance/README.txt new file mode 100644 index 0000000000..527c8cf805 --- /dev/null +++ b/mod/attendance/README.txt @@ -0,0 +1,23 @@ +ATTENDANCE version 0.1 +---------------------- + + +By Russell Jungwirth (jungwirr@surebluestudios.com) + + +This is the attendance module created and maintained by Russell J. Jungwirth +of Sureblue Studios. (surebluestudios.com) It allows for attendance to be +tracked for an arbitrary number of hours per instance. Instances are +labelled by date. Attendance is tracked for all instances in a given course +as well. + +Quick install instructions + +1) Copy attendance.php into lang/en/attendance.php + +2) Move this folder to become mod/attendance + +3) Visit your admin page to install the module + +4) Go to the site configuration page -> modules section -> attendance + to specify your preferences for the module (optional) diff --git a/mod/attendance/db/mysql.php b/mod/attendance/db/mysql.php new file mode 100644 index 0000000000..d6b089a0a3 --- /dev/null +++ b/mod/attendance/db/mysql.php @@ -0,0 +1,18 @@ + diff --git a/mod/attendance/db/mysql.sql b/mod/attendance/db/mysql.sql new file mode 100755 index 0000000000..30124b1fd7 --- /dev/null +++ b/mod/attendance/db/mysql.sql @@ -0,0 +1,30 @@ +# +# Table structure for table `prefix_attendance` +# + +CREATE TABLE prefix_attendance ( + id int(10) unsigned NOT NULL auto_increment, + name varchar(255) NOT NULL default '', + course int(10) NOT NULL default '0', + day int(10) unsigned NOT NULL default '0', + hours tinyint(1) NOT NULL default '0', + roll tinyint(1) NOT NULL default '0', + notes varchar(64) NOT NULL default '', + timemodified int(10) unsigned NOT NULL default '0', + dynsection tinyint(1) NOT NULL default '0', + PRIMARY KEY (id) +) TYPE=MyISAM; + +# +# Table structure for table `prefix_attendance_roll` +# + +CREATE TABLE prefix_attendance_roll ( + id int(11) NOT NULL auto_increment, + dayid int(10) unsigned NOT NULL default '0', + userid int(11) NOT NULL default '0', + hour tinyint(1) unsigned NOT NULL default '0', + status int(11) NOT NULL default '0', + notes varchar(64) NOT NULL default '', + PRIMARY KEY (id) +) TYPE=MyISAM; diff --git a/mod/attendance/icon.gif b/mod/attendance/icon.gif new file mode 100644 index 0000000000000000000000000000000000000000..e8e21e2fe37e327976413c5bd4bca738ee33d5ea GIT binary patch literal 876 zcmZ?wbhEHb6krfw_|CwM cE%R;@vF77Z5NbF#Q?y>`$;;ps2O1cx0Vl^L5&!@I literal 0 HcmV?d00001 diff --git a/mod/attendance/index.php b/mod/attendance/index.php new file mode 100644 index 0000000000..11418e7dc7 --- /dev/null +++ b/mod/attendance/index.php @@ -0,0 +1,78 @@ +id); + + add_to_log($course->id, "attendance", "view all", "index.php?id=$course->id", ""); + + +/// Get all required strings + + $strattendances = get_string("modulenameplural", "attendance"); + $strattendance = get_string("modulename", "attendance"); + + +/// Print the header + + if ($course->category) { + $navigation = "id\">$course->shortname ->"; + } + + print_header("$course->shortname: $strNEWMODULEs", "$course->fullname", "$navigation $strattendances"); + +/// Get all the appropriate data + + if (! $attendances = get_all_instances_in_course("attendance", $course)) { + notice("There are no attendances", "../../course/view.php?id=$course->id"); + die; + } + +/// Print the list of instances (your module will probably extend this) + + $timenow = time(); + $strname = get_string("name"); + $strweek = get_string("week"); + $strtopic = get_string("topic"); + + if ($course->format == "weeks") { + $table->head = array ($strweek, $strname); + $table->align = array ("CENTER", "LEFT"); + } else if ($course->format == "topics") { + $table->head = array ($strtopic, $strname); + $table->align = array ("CENTER", "LEFT", "LEFT", "LEFT"); + } else { + $table->head = array ($strname); + $table->align = array ("LEFT", "LEFT", "LEFT"); + } + + foreach ($attendances as $attendance) { + $link = "coursemodule\">$attendance->name"; + + if ($course->format == "weeks" or $course->format == "topics") { + $table->data[] = array ($attendance->section, $link); + } else { + $table->data[] = array ($link); + } + } + + echo "
"; + + print_table($table); + +/// Finish the page + + print_footer($course); + +?> diff --git a/mod/attendance/lib.php b/mod/attendance/lib.php new file mode 100755 index 0000000000..efbeaece7f --- /dev/null +++ b/mod/attendance/lib.php @@ -0,0 +1,302 @@ +timemodified = time(); + $attendance->dynsection = !empty($attendance->dynsection) ? 1 : 0; + $attendance->day = make_timestamp($attendance->theyear, + $attendance->themonth, $attendance->theday); + $attendance->name=userdate($attendance->day, get_string("strftimedate")); + if ($attendance->notes) { + $attendance->name = $attendance->name . " - " . $attendance->notes; + } + // insert the main record first + return $attendance->id = insert_record("attendance", $attendance); +} + + +function attendance_update_instance(&$attendance) { + $attendance->timemodified = time(); + $attendance->oldid=$attendance->id; + $attendance->id = $attendance->instance; + $attendance->dynsection = !empty($attendance->dynsection) ? 1 : 0; + + $attendance->day = make_timestamp($attendance->theyear, + $attendance->themonth, $attendance->theday); + $attendance->name=userdate($attendance->day, get_string("strftimedate")); + if ($attendance->notes) { + $attendance->name = $attendance->name . " - " . + $attendance->notes; + } + // get the data from the attendance grid + if ($data = data_submitted()) { + // Peel out all the data from variable names. + $attrec->dayid = $attendance->id; + foreach ($data as $key => $val) { + $pieces = explode('_',$key); + if ($pieces[0] == 'student') { + $attrec->userid=$pieces[1]; + $attrec->hour=$pieces[2]; + $attrec->status=$val; + // clear out any old records for the student + delete_records("attendance_roll", + "dayid",$attrec->dayid, + "hour", $attrec->hour, + "userid",$attrec->userid); + if ($attrec->status != 0) { + // student is registered as absent or tardy + insert_record("attendance_roll",$attrec, false); + } + } // if we have a piece of the student roll data + } // foreach for all form variables + } // if + return update_record("attendance", $attendance); +} + +function attendance_delete_instance($id) { + if (! $attendance = get_record("attendance", "id", "$id")) { + return false; + } + + $result = true; + + /// delete all the rolls for the day + delete_records("attendance_roll", "dayid", "$attendance->id"); + + if (! delete_records("attendance", "id", "$attendance->id")) { + $result = false; + } + + return $result; +} + +function attendance_user_outline($course, $user, $mod, $attendance) { +/// Return a small object with summary information about what a +/// user has done with a given particular instance of this module +/// Used for user activity reports. +/// $return->time = the time they did it +/// $return->info = a short text description +/// for attendance, this would be a list present and tardy for every hour of the day + $tardies=count_records("attendance_roll", "dayid", $attendance->id, "userid", $user->id, "status", 1); + $absences=count_records("attendance_roll", "dayid", $attendance->id, "userid", $user->id, "status", 2); + + // build longer string for tardies + if ($tardies > 0) { + $tardyrecs=attendance_get_records("attendance_roll", "dayid", $attendance->id, "userid", $user->id, "status", 1, "hour ASC"); + if ($tardies == 1) { + $tardystring = "Tardy in hour " . $tardyrecs[0]->hour . ". "; + } elseif ($tardies == $attendance->hours) { + $tardystring = "Tardy in all hours. (" . $attendance->hours . ") "; + } else { + // build array of all tardies + $tarr = array(); + foreach ($tardyrecs as $tardyrec) { + array_push($tarr, $tardyrec->hour); + $tardystring = $tardystring . ", " . $tardyrec->hour; + } + $end=array_pop($tarr); + $tardystring = "Tardy in hours " . implode(", ", $tarr) . " and ". $end . ". "; + } + } else { $tardystring = "";} + // build longer string for absences + if ($absences > 0) { + $absrecs=attendance_get_records("attendance_roll", "dayid", $attendance->id, "userid", $user->id, "status", 2, "hour ASC"); + if ($absences == 1) { + $absstring = "Absent in hour " . $absrecs[0]->hour . "."; + } elseif ($absences == $attendance->hours) { + $absstring = "Absent in all hours. (" . $attendance->hours . ")"; + } else { + // build array of all absences + $aarr = array(); + foreach ($absrecs as $absrec) { + array_push($aarr, $absrec->hour); + } + $end=array_pop($aarr); + $absstring = "Absent in hours " . implode(", ", $aarr) . " and ". $end . "."; + } + } else { $absstring = "";} + $return->info=$tardystring . $absstring; + if ($return->info == "") $return->info = "No Tardies or Absences"; + return $return; +} + +function attendance_user_complete($course, $user, $mod, $attendance) { +/// Print a detailed representation of what a user has done with +/// a given particular instance of this module, for user activity reports. + // get the attendance record for that day and user + $attrecs=attendance_get_records("attendance_roll", "dayid", $attendance->id, "userid", $user->id, "", "", "hour ASC"); + // fill an array with the absences and tardies, as those are the only records actually stored + $grid = array(); + foreach ($attrecs as $attrec) { $grid[$attrec->hour]=$attrec->status; } + echo "\n"; + // echo out the table header + for($j=1;$j<=$attendance->hours;$j++) { + echo "\n"; + } + echo ""; + for($j=1;$j<=$attendance->hours;$j++) { + // set the attendance defaults for each student + if (isset($grid[$j])) { + $status = (($grid[$j] == 1) ? "T" : "A"); + } else {$status="X";} + echo "\n"; + } /// for loop + echo "
Hour:".$j."
Status:".$status."
\n"; + + + return true; +} + +function attendance_print_recent_activity($course, $isteacher, $timestart) { +/// Given a course and a time, this module should find recent activity +/// that has occurred in attendance activities and print it out. +/// Return true if there was output, or false is there was none. + + global $CFG; + + return false; // True if anything was printed, otherwise false +} + +function attendance_cron () { +/// Function to be run periodically according to the moodle cron +/// This function searches for things that need to be done, such +/// as sending out mail, toggling flags etc ... + + global $CFG; + + return true; +} + +function attendance_grades($attendanceid) { +/// Must return an array of grades for a given instance of this module, +/// indexed by user. It also returns a maximum allowed grade. +/// NOT IMPLEMENTED AT THIS TIME - WILL DO GRADING BY ATTENDANCE STUFF IN A LATER VERSION + $return->grades = NULL; + $return->maxgrade = NULL; + + return $return; +} + + +////////////////////////////////////////////////////////////////////////////////////// +/// Any other attendance functions go here. Each of them must have a name that +/// starts with attendance_ + +/** +* get a list of all students enrolled in a given course - modified version +* +* THIS IS JUST THE GET_COURSE_STUDENTS FUNCTION WITH THE INCLUSION OF THE +* STUDENT ID INTO THE RECORDSET +* if courseid = 0 then return ALL students in all courses +* +* @param int $courseid the id of the course +* @param string $sort a field name and ASC or DESC for a SQL 'ORDER BY' clause (optional) +* @return array(recorset) a list of all students in the specified course + Returns +*/ +function attendance_get_course_students($courseid, $sort="u.lastaccess DESC") { + + global $CFG; + + return get_records_sql("SELECT u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat, + u.email, u.city, u.country, u.lastaccess, u.lastlogin, u.picture, u.idnumber + FROM {$CFG->prefix}user u, + {$CFG->prefix}user_students s + WHERE s.course = '$courseid' AND s.userid = u.id AND u.deleted = '0' + ORDER BY $sort"); +} + + +/** +* Find total absences based on number of tardies per absence +* +* Given a number of tardies and absences, determine the total +* number of equivalent absences it adds up to. +* +* @param int $absences the total number of absences for a span of time +* @param int $tardies the total number of tardies for a span of time +* @return float the number of absences it adds up to - may be a decimal! +*/ +function tally_overall_absences_decimal($absences, $tardies) { + global $CFG; + if (isset($CFG->attendance_tardies_per_absence) && ($CFG->attendance_tardies_per_absence>0)) { + return $absences + ($tardies/$CFG->attendance_tardies_per_absence); + } else { return $absences; } +} + +/** +* Find total absences based on number of tardies per absence and put it in a string +* +* Given a number of tardies and absences, determine the total +* number of equivalent absences it adds up to and express it as a string with +* a possible fractional remainder +* +* @param int $absences the total number of absences for a span of time +* @param int $tardies the total number of tardies for a span of time +* @return string the number of absences it adds up to - may have a fractional component! +*/ +function tally_overall_absences_fraction($absences, $tardies) { + global $CFG; + if (isset($CFG->attendance_tardies_per_absence) && ($CFG->attendance_tardies_per_absence>0)) { + $whole = floor($tardies/$CFG->attendance_tardies_per_absence); + $fractional=$tardies-($whole * $CFG->attendance_tardies_per_absence); + if ($absences + $whole > 0) { + return ($absences + $whole) . (($fractional > 0) ? " ". $fractional. "/". $CFG->attendance_tardies_per_absence : ""); + } else { + return (($fractional > 0) ? $fractional. "/". $CFG->attendance_tardies_per_absence : "0"); + } + } else { + return $absences.""; + } +} + +/** +* get a list of records from a table with multiple criteria +* +* This one is different from the datalib.php one (called get_records) in the sense that it +* allows for multiple criteria to be easily supplied as parameters, but doesn't +* give the ability to specify sort, fields, or limits +* +*/ +function attendance_get_records($table, $field1="", $value1="", $field2="", $value2="", $field3="", $value3="", $sort="", $fields="*", $limitfrom="", $limitnum="") { + + global $CFG; + + if ($field1) { + $select = "WHERE $field1 = '$value1'"; + if ($field2) { + $select .= " AND $field2 = '$value2'"; + if ($field3) { + $select .= " AND $field3 = '$value3'"; + } + } + } else { + $select = ""; + } + + if ($limitfrom !== "") { + switch ($CFG->dbtype) { + case "mysql": + $limit = "LIMIT $limitfrom,$limitnum"; + break; + case "postgres7": + $limit = "LIMIT $limitnum OFFSET $limitfrom"; + break; + default: + $limit = "LIMIT $limitnum,$limitfrom"; + } + } else { + $limit = ""; + } + + if ($sort != "") { + $sort = "ORDER BY $sort"; + } + + return get_records_sql("SELECT $fields FROM $CFG->prefix$table $select $sort $limit"); +} + +?> diff --git a/mod/attendance/mod.html b/mod/attendance/mod.html new file mode 100755 index 0000000000..ecfb48f770 --- /dev/null +++ b/mod/attendance/mod.html @@ -0,0 +1,143 @@ + + + + + + dirroot/mod/attendance/lib.php") + //require_once("lib.php") + ?> +
+
+"> +"> + + + + + + + + + + + + + + + + + + + + + + + + + +

:

day) ?>

:

+ dynsection) ? 'checked' : '' ?> > +

:

hours, "1","","1") ?>

:

+ +
+ + +id) { + // get the list of attendance records for all hours of the given day and + // put it in the array for use in the attendance table + $rolls = get_records("attendance_roll", "dayid", $form->id); + foreach ($rolls as $roll) { + $sroll[$roll->userid][$roll->hour]->status=$roll->status; + $sroll[$roll->userid][$roll->hour]->notes=$roll->notes; + } + // get the list of students along with student ID field +// get back array of stdclass objects in sorted order, with members: +// id, username,firstname,lastname,maildisplay,mailformat,email,city,country, +// lastaccess,lastlogin,picture (picture is null, 0, or 1), idnumber + // build the table for attendance roll + // this is the wrapper table + echo "". + "
"; + // this is the main table + echo ""; +if ($form->hours >1) { + echo "\n"; + for($i=1;$i<=$form->hours;$i++) { + echo "\n"; + } + echo "\n"; +} // if more than one hour for each day + echo "\n"; + echo "\n"; + echo "\n"; + $P=get_string("presentshort","attendance"); + $T=get_string("tardyshort","attendance"); + $A=get_string("absentshort","attendance"); + // generate the headers for the attendance hours + for($i=1;$i<=$form->hours;$i++) { + echo "\n"; + echo "\n"; + echo "\n"; + } + echo "\n"; + $table->head = array("Last Name","First Name","ID", + get_string("presentlong","attendance"), + get_string("tardylong","attendance"), + get_string("absentlong","attendance")); + $table->align = array("left", "left", "left", "center","center","center"); + $table->wrap = array("nowrap", "nowrap", "nowrap", "nowrap", "nowrap", "nowrap"); + $table->width = "80"; + + $students = attendance_get_course_students($form->course, "u.lastname ASC"); + $i=0; + foreach ($students as $student) { + echo "\n"; + echo "\n"; + echo "\n"; + for($j=1;$j<=$form->hours;$j++) { + // set the attendance defaults for each student + $r1c=$r2c=$r3c=" "; + if ($sroll[$student->id][$j]->status == 1) {$r2c="checked";} + elseif ($sroll[$student->id][$j]->status == 2) {$r3c="checked";} + else {$r1c="checked";} + $radio1="id."_".$j."\" value=\"0\" ".$r1c.">"; + $radio2="id."_".$j."\" value=\"1\" ".$r2c.">"; + $radio3="id."_".$j."\" value=\"2\" ".$r3c.">"; + echo "\n"; + echo "\n"; + echo "\n"; + } // for loop + echo "\n"; +// $radio1="id."\" value=\"0\" checked>"; +// $radio2="id."\" value=\"1\">"; +// $radio3="id."\" value=\"2\">"; +// $table->data[$i]=array($student->lastname, $student->firstname, +// $student->idnumber, $radio1,$radio2,$radio3); +// $i++; + } + // doing the table manually now +// print_table($table); + // ending for both the tables + echo "
". + "Hours:". + "$i
Last NameFirst NameID".$P."".$T."".$A."
".$student->lastname."".$student->firstname."".$student->idnumber."".$radio1."".$radio2."".$radio3."
\n"; +} // if ($form->id) +?> + + + + + + + + +
+"> +"> +
+
diff --git a/mod/attendance/version.php b/mod/attendance/version.php new file mode 100644 index 0000000000..5a7356808a --- /dev/null +++ b/mod/attendance/version.php @@ -0,0 +1,11 @@ +version = 2003091001; // The current module version (Date: YYYYMMDDXX) +$module->cron = 0; // Period for cron to check this module (secs) + +?> diff --git a/mod/attendance/view.php b/mod/attendance/view.php new file mode 100644 index 0000000000..fabf3c2cab --- /dev/null +++ b/mod/attendance/view.php @@ -0,0 +1,141 @@ +dirroot/mod/attendance/lib.php"); +// error_reporting(E_ALL); + optional_variable($id); // Course Module ID, or + optional_variable($a); // attendance ID + if ($id) { + if (! $cm = get_record("course_modules", "id", $id)) { + error("Course Module ID was incorrect"); + } + if (! $course = get_record("course", "id", $cm->course)) { + error("Course is misconfigured"); + } + if (! $attendance = get_record("attendance", "id", $cm->instance)) { + error("Course module is incorrect"); + } + } else { + if (! $attendance = get_record("attendance", "id", $a)) { + error("Course module is incorrect"); + } + if (! $course = get_record("course", "id", $attendance->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("attendance", $attendance->id, $course->id)) { + error("Course Module ID was incorrect"); + } + } + + require_login($course->id); + + add_to_log($course->id, "attendance", "view", "view.php?id=$cm->id", "$attendance->id"); + +/// Print the page header + + if ($course->category) { + $navigation = "id\">$course->shortname ->"; + } + + $strattendances = get_string("modulenameplural", "attendance"); + $strattendance = get_string("modulename", "attendance"); + + print_header("$course->shortname: $attendance->name", "$course->fullname", + "$navigation id>$strattendances -> $attendance->name", + "", "", true, update_module_button($cm->id, $course->id, $strattendance), + navmenu($course, $cm)); + +/// Print the main part of the page + + // adaptation of mod code to view code needs this: + $form = $attendance; + + if (isteacher($course->id)) { + $rolls = get_records("attendance_roll", "dayid", $form->id); + } else if (!$cm->visible) { + notice(get_string("activityiscurrentlyhidden")); + print_footer($course); exit; + } else if (isstudent($course->id)) { // visible and a student + $rolls = get_records("attendance_roll", "dayid", $form->id, "userid", $USER->id); + } else { + notice(get_string("noviews", "attendance")); + print_footer($course); exit; + } + if ($rolls) { + foreach ($rolls as $roll) { + $sroll[$roll->userid][$roll->hour]->status=$roll->status; + $sroll[$roll->userid][$roll->hour]->notes=$roll->notes; + } + } + + // get the list of attendance records for all hours of the given day and + // put it in the array for use in the attendance table + $strviewall = get_string("viewall", "attendance"); + echo ""; + echo "
id."\">"; + echo "$strviewall

"; + // this is the wrapper table + echo ""; + echo "
"; + // this is the main table + echo ""; +// print the date headings at the top of the table + echo "\n"; + // put notes for the date in the date heading + $notes = ($form->notes != "") ? ":
".$form->notes : ""; + echo "\n"; + echo (($form->hours > 1) ? "\n" : ""); + echo "\n"; +// print the second level headings with name and possibly hour numbers + echo "\n"; + echo "\n"; + echo "\n"; + // generate the headers for the attendance hours + if ($form->hours > 1) { + for($i=1;$i<=$form->hours;$i++) { + echo "\n"; + } + echo "\n"; } + echo "\n"; + // get the list of students along with student ID field + // get back array of stdclass objects in sorted order, with members: + // id, username,firstname,lastname,maildisplay,mailformat,email,city,country, + // lastaccess,lastlogin,picture (picture is null, 0, or 1), idnumber + if (isteacher($course->id)){ + $students = attendance_get_course_students($form->course, "u.lastname ASC"); + } else { // must be a student + $students[0] = get_user_info_from_db("id", $USER->id); + } + $i=0; + foreach ($students as $student) { + echo "\n"; + echo "\n"; + $studentid=(($student->idnumber != "") ? $student->idnumber : " "); + echo "\n"; + $abs=$tar=0; + for($j=1;$j<=$form->hours;$j++) { + // set the attendance defaults for each student + if ($sroll[$student->id][$j]->status == 1) {$status="T";$tar++;} + elseif ($sroll[$student->id][$j]->status == 2) {$status="A";$abs++;} + else {$status="X";} + echo "\n"; + } /// for loop + if ($form->hours > 1) { + $tot=tally_overall_absences_fraction($abs,$tar); + echo "\n"; + } + } + /// ending for the table + echo "
". + " hours. "\" nowrap class=\"generaltableheader\">". + userdate($form->day,get_string("strftimedateshort")).$notes." 
Last NameFirst NameID".$i."total"; + } else { echo " 
".$student->lastname."".$student->firstname."".$studentid."".$status."".$tot."
\n"; + +/// Finish the page + print_footer($course); + +?> diff --git a/mod/attendance/viewall.php b/mod/attendance/viewall.php new file mode 100644 index 0000000000..86e55dbb1c --- /dev/null +++ b/mod/attendance/viewall.php @@ -0,0 +1,305 @@ +dirroot/mod/attendance/lib.php"); +/// error_reporting(E_ALL); + + optional_variable($id); // Course Module ID, or + optional_variable($a); // attendance ID + +/// populate the appropriate objects + if ($id) { + if (! $course = get_record("course", "id", $id)) { + error("Course is misconfigured"); + } + if (! $attendances = get_records("attendance", "course", $id)) { + error("Course module is incorrect"); + } + } else { + if (! $attendance = get_record("attendance", "id", $a)) { + error("Course module is incorrect"); + } + if (! $course = get_record("course", "id", $attendance->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("attendance", $attendance->id, $course->id)) { + error("Course Module ID was incorrect"); + } + if (! $attendances = get_records("attendance", "course", $cm->course)) { + error("Course module is incorrect"); + } + } + + require_login($course->id); + + add_to_log($course->id, "attendance", "viewall", "viewall.php?id=$cm->id", "$attendance->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)) ) { + notice(get_string("noviews", "attendance")); + print_footer($course); exit; + } + +// print other links at top of page + $strviewone = get_string("viewone", "attendance"); + $strviewtable = get_string("viewtable", "attendance"); + $strviewmulti = get_string("viewmulti", "attendance"); + if ($onepage) { // one page for all tables + echo "

id."\">"; + echo "$strviewmulti
"; + echo "id."&onetable=1\">"; + echo "$strviewtable

"; + } else if ($onetable) { // one table for all + echo "

id."\">"; + echo "$strviewmulti
"; + echo "id."&onepage=1\">"; + echo "$strviewone

"; + } else { // multiple pages + echo "

id."&onepage=1\">"; + echo "$strviewone
"; + echo "id."&onetable=1\">"; + echo "$strviewtable

"; + } + + +/// create an array of all the attendance objects for the entire course + $numatt=0; + $numhours=0; + foreach ($attendances as $attendance){ + // store the raw attendance object + $atts[$numatt]->attendance=$attendance; + // tally the hours for possible paging of the report + $numhours=$numhours+$attendance->hours; + // get the list of attendance records for all hours of the given day and + // put it in the array for use in the attendance table + if (isstudent($course->id)) { + $rolls = get_records("attendance_roll", "dayid", $form->id, "userid", $USER->id); + } else { // must be a teacher + $rolls = get_records("attendance_roll", "dayid", $attendance->id); + } + foreach ($rolls as $roll) { + $atts[$numatt]->sroll[$roll->userid][$roll->hour]->status=$roll->status; + $atts[$numatt]->sroll[$roll->userid][$roll->hour]->notes=$roll->notes; + } + $numatt++; + } + +// A LOOP FOR CREATING SINGLE-USER VERSION OF THE REPORT OR A ONE-PAGE REPORT + if (isstudent($course->id)) { + $onepage=true; + $multipage=false; + } else if (!(isset($onepage))){ + $onepage=false; + $multipage=true; + } else if ($onepage) { + $multipage=false; + } else { // if onepage is set to false + $multilpage=true; + } + +// adjust the width for the report for students + + if (($onetable) || ($CFG->attendance_hours_in_full_report == 0)) { + $hoursinreport = 10000; + } else if (isstudent($course->id)) { + $hoursinreport = $CFG->attendance_hours_in_full_report + 15; + } else { + $hoursinreport = $CFG->attendance_hours_in_full_report; + } +while (($multipage || $onepage) && (!$endonepage)) { + // this makes for a one iteration loop for multipage + $multipage = false; + + + if ($numhours>=$hoursinreport) { + if (!isset($pagereport)) { + // $pagereport is used to determine whether the report needs to be paged at all + $pagereport=true; + $endatt=0; + $page=1; + } + // find the last hour to have on this page of the report + // go to the next (or first) page +// $endatt++; +// $startatt=$endatt; + $curpage=1; + $endatt=0; + for($curpage=1;true;$curpage++) { // the for loop is broken from the inside + $pagehours=$atts[$endatt]->attendance->hours; + $startatt=$endatt; + while(($pagehours<$hoursinreport)) { + if ($endatt>=$numatt) { break 2; } // end the page number calculations and trigger the end of a multi-page report! + $endatt++; + $pagehours=$pagehours+$atts[$endatt]->attendance->hours; + } + // if this is the page we're on, save the info + if ($curpage == $page) {$endatt_target = $endatt; $startatt_target = $startatt; } + } // hopefully at this point, startatt and endatt are set correctly for the current page + if ($curpage == $page) {$endatt_target = $endatt; $startatt_target = $startatt; } else { + $endatt=$endatt_target; $startatt=$startatt_target; } + $maxpages = $curpage; + } else {$pagereport=false;} + + $minatt=($pagereport ? $startatt : 0); + $maxatt=($pagereport ? $endatt : $numatt); + + if ((!$pagereport) || ($page == $maxpages)) {$endonepage = true;} // end a one page display + +// +// +// ALL PRELIMINARY STUFF DONE - MAKE THE MEAT OF THE PAGE +// +// + + if (!$onepage) { + + attendance_print_pagenav(); + } + + // build the table for attendance roll + // this is the wrapper table + echo "". + "
"; + // this is the main table + echo ""; + if (isteacher($course->id)) { + echo "\n"; + } +// $minpage=0;$maxpage=$numatt; + // print the date headings at the top of the table + // for each day of attendance + for($k=$minatt;$k<$maxatt;$k++) { + // put notes for the date in the date heading + $notes = ($atts[$k]->attendance->notes != "") ? ":
".$atts[$k]->attendance->notes : ""; + echo "\n"; + } + // if we're at the end of the report + if ($maxatt==$numatt || !$pagereport) { + echo "\n"; + } + echo "\n"; + // print the second level headings with name and possibly hour numbers + if (isteacher($course->id)) { + echo "\n"; + echo "\n"; + echo "\n"; + } + // generate the headers for the attendance hours + for($k=$minatt;$k<$maxatt;$k++) { + if ($atts[$k]->attendance->hours > 1) { + for($i=1;$i<=$atts[$k]->attendance->hours;$i++) { + echo "\n"; + } + } else { echo "\n"; } + } + // if we're at the end of the report + if ($maxatt==$numatt || !$pagereport) { + echo ""; + } + echo "\n"; + + // get the list of students along with student ID field + // get back array of stdclass objects in sorted order, with members: + // id, username,firstname,lastname,maildisplay,mailformat,email,city,country, + // lastaccess,lastlogin,picture (picture is null, 0, or 1), idnumber + + + 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; + foreach ($students as $student) { + if (isteacher($course->id)) { + echo "\n"; + echo "\n"; + $studentid=(($student->idnumber != "") ? $student->idnumber : " "); + echo "\n"; + } + for($k=$minatt;$k<$maxatt;$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) {$status="T";} + elseif ($atts[$k]->sroll[$student->id][$j]->status == 2) {$status="A";} + else {$status="X";} + echo "\n"; + } /// for loop + } + if ($maxatt==$numatt || !$pagereport) { + // tally total attendances for the students + $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_fraction($abs,$tar); + echo "\n"; + } + } // foreach + /// doing the table manually now + /// print_table($table); + /// ending for the table + echo "
". + " attendance->hours. "\" nowrap class=\"generaltableheader\">". + userdate($atts[$k]->attendance->day,"%m/%0d").$notes." 
Last NameFirst NameID".$i." total
".$student->lastname."".$student->firstname."".$studentid."".$status."".$tot."
\n"; + +if ($onepage) {$page++; echo "

\n"; } +} // while loop for multipage/one page printing + + if (!$onepage) { attendance_print_pagenav(); } + + } else { error("There are no attendance rolls in this course.");} // for no attendance rolls +/// Finish the page + print_footer($course); + +function attendance_print_pagenav() { + global $pagereport, $minatt, $maxatt, $course, $page, $numatt, $maxpages; + if ($pagereport) { + $of = get_string('of','attendance'); + $pg = get_string('page'); + $next = get_string('next'); + $prev = get_string('previous', 'attendance'); + + echo "
". + "
"; + // this is the main table + echo ""; + echo ""; + if ($minatt!=0) { + echo "\n"; + } + echo "\n"; + if ($maxatt!=$numatt) { + echo ""; + } + echo "
". + "id ."&pagereport=1&page=".($page-1)."\">$prev $pg". + "$pg $page $of $maxpages". + "id ."&pagereport=1&page=". ($page+1)."\">$next $pg
\n"; + } +} +?> -- 2.39.5