Skip to content
Browse files

Added automatic attendance logging based on date and any activity by

student on that day.  NOTE - cron must be running for this to work
properly

Modified multi-page views to use arrows instead of words, added a first
page and last page link as well.  Cleaned up that nav menu a bit as well.
  • Loading branch information...
1 parent 5edceb5 commit eab709a095b45c0fc39265322abf41db103a16a6 jungwirr committed Sep 25, 2003
View
5 lang/en/attendance.php
@@ -27,7 +27,6 @@
$string['defaulthoursinclass'] = "How many hours there should be in a default attendance roll";
$string['tardiesperabsence'] = "How many tardies should count as one absence";
$string['hoursinfullreport'] = "The maximum number of hours of attendance that should be displayed on a single page of a report";
-$string['previous'] = "Previous";
$string['pages'] = "Pages";
$string['of'] = "of";
$string['viewall'] = "View All Attendance Rolls";
@@ -57,5 +56,9 @@
$string['downloadexceltotals'] = "Download Summary Excel Spreadsheet";
$string['downloadtextfull'] = "Download Full Text Report";
$string['downloadtexttotals'] = "Download Summary Text Report";
+$string['autoattend'] = "Automatically take attendance based on user activity logs";
+$string['autoattendmulti'] = "Automatically take attendance for all rolls based on user activity logs";
+$string['auto'] = "auto";
+
?>
View
3 mod/attendance/db/mysql.php
@@ -10,6 +10,9 @@ function attendance_upgrade($oldversion) {
execute_sql("ALTER TABLE `{$CFG->prefix}attendance` ADD `edited` TINYINT( 1 ) DEFAULT '0' NOT NULL;");
execute_sql("UPDATE `{$CFG->prefix}attendance` set `edited` = 1;");
}
+ if ($oldversion < 2003092500) {
+ execute_sql("ALTER TABLE `{$CFG->prefix}attendance` ADD `autoattend` TINYINT( 1 ) DEFAULT '0' NOT NULL;");
+ }
return true;
}
View
1 mod/attendance/db/mysql.sql
@@ -13,6 +13,7 @@ CREATE TABLE prefix_attendance (
timemodified int(10) unsigned NOT NULL default '0',
dynsection tinyint(1) NOT NULL default '0',
edited tinyint(1) NOT NULL default '0',
+ autoattend tinyint(1) NOT NULL default '0',
PRIMARY KEY (id)
) TYPE=MyISAM;
View
85 mod/attendance/lib.php
@@ -6,7 +6,7 @@
function attendance_add_module(&$mod) {
// global $mod;
- require("../../course/lib.php");
+ require_once("../../course/lib.php");
if (! $mod->instance = attendance_add_instance($mod)) {
error("Could not add a new instance of $mod->modulename"); return 0;
@@ -34,6 +34,7 @@ function attendance_add_instance($attendance) {
global $mod;
$attendance->timemodified = time();
$attendance->dynsection = !empty($attendance->dynsection) ? 1 : 0;
+ $attendance->autoattend = !empty($attendance->autoattend) ? 1 : 0;
if (empty($attendance->day)) {
$attendance->day = make_timestamp($attendance->theyear,
$attendance->themonth, $attendance->theday);
@@ -71,6 +72,7 @@ function attendance_update_instance($attendance) {
// $attendance->oldid=$attendance->id;
$attendance->id = $attendance->instance;
$attendance->dynsection = !empty($attendance->dynsection) ? 1 : 0;
+ $attendance->autoattend = !empty($attendance->autoattend) ? 1 : 0;
$attendance->day = make_timestamp($attendance->theyear,
$attendance->themonth, $attendance->theday);
@@ -257,11 +259,41 @@ 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;
+// look for all attendance instances set to autoattend
+ $attendances = get_records("attendance", "autoattend", 1, "course ASC");
+ $td = attendance_find_today(time());
+ $tm = attendance_find_tomorrow(time());
+ foreach($attendances as $attendance) {
+ if (($attendance->day >=$td ) && ($attendance->day < $tm)) {
+ if(!isset($courses[$attendance->course]->students)) {
+ $courses[$attendance->course]->students =
+ attendance_get_course_students($attendance->course, "u.lastname ASC");
+ }
+ foreach ($courses[$attendance->course]->students as $student) {
+ // first, clear out the records that may be there already
+ delete_records("attendance_roll",
+ "dayid",$attendance->id,
+ "userid",$student->id);
+ $wc = "userid = " . $student->id . " AND course = " . $attendance->course .
+ " AND time >= " . $td . " AND time < " . $tm;
+ $count = get_record_select("log",$wc,"COUNT(*) as c");
+ if ($count->c == "0") { // then the student hasn't done anything today, so mark him absent
+ $attrec->dayid = $attendance->id;
+ $attrec->userid = $student->id;
+ $attrec->status = 2; // status 2 is absent
+ // mark ALL hours as absent for first version
+ for ($i=1;$i<=$attendance->hours;$i++) {
+ $attrec->hour = $i;
+ insert_record("attendance_roll",$attrec, false);
+ } // for loop to mark all hours absent
+ } // if student has no activity
+ } // foreach student in the list
+ } // if the attendance roll is for today
+ } // for each attendance in the system
+ return true;
+} // function cron
- return true;
-}
function attendance_grades($attendanceid) {
/// Must return an array of grades for a given instance of this module,
@@ -508,4 +540,49 @@ function attendance_get_participants($attendanceid) {
return ($students);
}
+/**
+* Determines if two dates are on the same day
+*
+* This function takes two unix timestamps and determines if they occur within the same 24 hours
+* It does this by comparing the year, month, and day
+*
+* @param timestamp $d1 The first date to compare
+* @param timestamp $d2 The second date to compare
+* @return boolean whether the two dates occur on the same day
+*/
+function attendance_dates_same_day($d1,$d2) {
+ $da1 = getdate($d1);
+ $da2 = getdate($d2);
+ return (($da1["mday"]==$da2["mday"]) &&($da1["mon"]==$da2["mon"]) && ($da1["year"]==$da2["year"]));
+}
+
+/**
+* Finds the beginning of the day for the date specified
+*
+* This function returns the timestamp for midnight of the day specified in the timestamp
+*
+* @param timestamp $d The time to find the beginning of the day for
+* @return timestamp midnight for that day
+*/
+function attendance_find_today($d) {
+ // add 24 hours to the current time - to solve end of month date issues
+ $da = getdate($d);
+ // now return midnight of that day
+ return mktime(0,0,0,$da["mon"], $da["mday"], $da["year"]);
+}
+
+/**
+* Finds the beginning of the day following the date specified
+*
+* This function returns the timestamp for midnight of the day after the timestamp specified
+*
+* @param timestamp $d The time to find the next day of
+* @return timestamp midnight of the next day
+*/
+function attendance_find_tomorrow($d) {
+ // add 24 hours to the current time - to solve end of month date issues
+ return attendance_find_today($d+86400);
+}
+
+
?>
View
4 mod/attendance/version.php
@@ -5,7 +5,7 @@
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php
/////////////////////////////////////////////////////////////////////////////////
-$module->version = 2003092400; // The current module version (Date: YYYYMMDDXX)
-$module->cron = 0; // Period for cron to check this module (secs)
+$module->version = 2003092500; // The current module version (Date: YYYYMMDDXX)
+$module->cron = 3600; // Period for cron to check this module (secs)
?>
View
27 mod/attendance/viewall.php
@@ -1,4 +1,4 @@
-<? // $Id$
+<?php // $Id$
/// This page prints all instances of attendance in a given course
require_once("../../config.php");
@@ -51,6 +51,8 @@
$numhours=0;
foreach ($attendances as $attendance){
// store the raw attendance object
+ $cm = get_coursemodule_from_instance("attendance", $attendance->id, $course->id);
+ $attendance->cmid = $cm->id;
$atts[$numatt]->attendance=$attendance;
// tally the hours for possible paging of the report
$numhours=$numhours+$attendance->hours;
@@ -85,7 +87,7 @@
// Creating a workbook
$workbook = new Workbook("-");
// Creating the first worksheet
- $myxls =& $workbook->add_worksheet('Grades');
+ $myxls =& $workbook->add_worksheet('Attendance');
// print the date headings at the top of the table
// for each day of attendance
@@ -268,7 +270,7 @@
for($curpage=1;true;$curpage++) { // the for loop is broken from the inside
$pagehours=$atts[$endatt]->attendance->hours;
$startatt=$endatt;
- while(($pagehours<$hoursinreport)) {
+ 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;
@@ -331,7 +333,6 @@
attendance_print_pagenav();
}
-
// build the table for attendance roll
// this is the wrapper table
echo "<table align=\"center\" width=\"80\" class=\"generalbox\"".
@@ -350,8 +351,10 @@
for($k=$minatt;$k<$maxatt;$k++) {
// put notes for the date in the date heading
$notes = ($atts[$k]->attendance->notes != "") ? ":<br />".$atts[$k]->attendance->notes : "";
- echo "<th valign=\"top\" align=\"left\" colspan=\"" .$atts[$k]->attendance->hours. "\" nowrap class=\"generaltableheader\">".
- userdate($atts[$k]->attendance->day,"%m/%0d").$notes."</th>\n";
+ $auto = ($atts[$k]->attendance->autoattend == 1) ? "(".get_string("auto","attendance").")" : "";
+ echo "<th valign=\"top\" align=\"left\" colspan=\"" .$atts[$k]->attendance->hours. "\" nowrap class=\"generaltableheader\">".
+ "<a href=\"view.php?id=".$atts[$k]->attendance->cmid."\">".userdate($atts[$k]->attendance->day,"%m/%0d")."</a>".$auto.
+ $notes."</th>\n";
}
// if we're at the end of the report
if ($maxatt==$numatt || !$pagereport) {
@@ -489,8 +492,6 @@ function attendance_print_pagenav() {
if ($pagereport) {
$of = get_string('of','attendance');
$pg = get_string('page');
- $next = get_string('next');
- $prev = get_string('previous', 'attendance');
echo "<center><table align=\"center\" width=\"80\" class=\"generalbox\"".
"border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>".
@@ -501,13 +502,19 @@ function attendance_print_pagenav() {
echo "<tr>";
if ($minatt!=0) {
echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">".
- "<a href=\"viewall.php?id=".$course->id ."&pagereport=1&page=".($page-1)."\">$prev $pg</a></th>\n";
+ "<a href=\"viewall.php?id=".$course->id ."&pagereport=1&page=1\">&lt;&lt;</a>&nbsp;\n".
+ "<a href=\"viewall.php?id=".$course->id ."&pagereport=1&page=".($page-1)."\">&lt;</a></th>\n";
+ } else {
+ echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">&lt;&lt;&nbsp;&lt;</th>\n";
}
echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">".
"$pg $page $of $maxpages</th>\n";
if ($maxatt!=$numatt) {
echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">".
- "<a href=\"viewall.php?id=".$course->id ."&pagereport=1&page=". ($page+1)."\">$next $pg</a></th>";
+ "<a href=\"viewall.php?id=".$course->id ."&pagereport=1&page=". ($page+1)."\">&gt;</a>&nbsp;".
+ "<a href=\"viewall.php?id=".$course->id ."&pagereport=1&page=$maxpages\">&gt;&gt;</a></th>";
+ } else {
+ echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">&gt;&nbsp;&gt;&gt;</th>\n";
}
echo "</tr></table></td></tr></table></center>\n";
}
View
22 mod/attendance/viewweek.php
@@ -51,6 +51,8 @@
$numhours=0;
foreach ($attendances as $attendance){
// store the raw attendance object
+ $cm = get_coursemodule_from_instance("attendance", $attendance->id, $course->id);
+ $attendance->cmid = $cm->id;
$atts[$numatt]->attendance=$attendance;
// tally the hours for possible paging of the report
$numhours=$numhours+$attendance->hours;
@@ -86,7 +88,7 @@
// Creating a workbook
$workbook = new Workbook("-");
// Creating the first worksheet
- $myxls =& $workbook->add_worksheet('Grades');
+ $myxls =& $workbook->add_worksheet('Weekly Attendance');
// print the date headings at the top of the table
// for each day of attendance
@@ -356,8 +358,10 @@
for($k=$minatt;$k<$maxatt;$k++) {
// put notes for the date in the date heading
$notes = ($atts[$k]->attendance->notes != "") ? ":<br />".$atts[$k]->attendance->notes : "";
- echo "<th valign=\"top\" align=\"left\" colspan=\"" .$atts[$k]->attendance->hours. "\" nowrap class=\"generaltableheader\">".
- userdate($atts[$k]->attendance->day,"%m/%0d").$notes."</th>\n";
+ $auto = ($atts[$k]->attendance->autoattend == 1) ? "(".get_string("auto","attendance").")" : "";
+ echo "<th valign=\"top\" align=\"left\" colspan=\"" .$atts[$k]->attendance->hours. "\" nowrap class=\"generaltableheader\">".
+ "<a href=\"view.php?id=".$atts[$k]->attendance->cmid."\">".userdate($atts[$k]->attendance->day,"%m/%0d")."</a>".$auto.
+ $notes."</th>\n";
}
// if we're at the end of the report
if ($maxatt==$numatt || !$pagereport) {
@@ -479,8 +483,6 @@ function attendance_print_pagenav() {
if ($pagereport) {
$of = get_string('of','attendance');
$pg = get_string('page');
- $next = get_string('next');
- $prev = get_string('previous', 'attendance');
echo "<center><table align=\"center\" width=\"80\" class=\"generalbox\"".
"border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>".
@@ -491,13 +493,19 @@ function attendance_print_pagenav() {
echo "<tr>";
if ($minatt!=0) {
echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">".
- "<a href=\"viewweek.php?scope=".$scope."&id=".$id ."&pagereport=1&page=".($page-1)."\">$prev $pg</a></th>\n";
+ "<a href=\"viewweek.php?scope=".$scope."&id=".$id ."&pagereport=1&page=".($page-1)."\">&lt;</a>&nbsp;\n";
+ "<a href=\"viewweek.php?scope=".$scope."&id=".$id ."&pagereport=1&page=1\">&lt;&lt;</a></th>\n";
+ } else {
+ echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">&lt;&lt;&nbsp;&lt;</th>\n";
}
echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">".
"$pg $page $of $maxpages</th>\n";
if ($maxatt!=$numatt) {
echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">".
- "<a href=\"viewweek.php?scope=".$scope."&id=".$id ."&pagereport=1&page=". ($page+1)."\">$next $pg</a></th>";
+ "<a href=\"viewweek.php?scope=".$scope."&id=".$id ."&pagereport=1&page=". ($page+1)."\">&gt;</a>&nbsp;".
+ "<a href=\"viewweek.php?scope=".$scope."&id=".$id ."&pagereport=1&page=$maxpages\">&gt;&gt;</a></th>";
+ } else {
+ echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">&gt;&nbsp;&gt;&gt;</th>\n";
}
echo "</tr></table></td></tr></table></center>\n";
}

0 comments on commit eab709a

Please sign in to comment.
Something went wrong with that request. Please try again.