$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";
$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";
+
?>
execute_sql("ALTER TABLE `{$CFG->prefix}attendance` ADD `edited` TINYINT( 1 ) DEFAULT '0' NOT NULL;");\r
execute_sql("UPDATE `{$CFG->prefix}attendance` set `edited` = 1;");\r
}\r
+ if ($oldversion < 2003092500) {\r
+ execute_sql("ALTER TABLE `{$CFG->prefix}attendance` ADD `autoattend` TINYINT( 1 ) DEFAULT '0' NOT NULL;");\r
+ }\r
\r
return true;\r
}\r
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;
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;
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);
// $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);
/// 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,
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);
+}
+
+
?>
/// 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)
?>
-<? // $Id$
+<?php // $Id$
/// This page prints all instances of attendance in a given course
require_once("../../config.php");
$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;
// 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
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;
attendance_print_pagenav();
}
-
// build the table for attendance roll
// this is the wrapper table
echo "<table align=\"center\" width=\"80\" class=\"generalbox\"".
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) {
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>".
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\"><<</a> \n".
+ "<a href=\"viewall.php?id=".$course->id ."&pagereport=1&page=".($page-1)."\"><</a></th>\n";
+ } else {
+ echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\"><< <</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)."\">></a> ".
+ "<a href=\"viewall.php?id=".$course->id ."&pagereport=1&page=$maxpages\">>></a></th>";
+ } else {
+ echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">> >></th>\n";
}
echo "</tr></table></td></tr></table></center>\n";
}
$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;
// 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
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) {
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>".
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)."\"><</a> \n";
+ "<a href=\"viewweek.php?scope=".$scope."&id=".$id ."&pagereport=1&page=1\"><<</a></th>\n";
+ } else {
+ echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\"><< <</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)."\">></a> ".
+ "<a href=\"viewweek.php?scope=".$scope."&id=".$id ."&pagereport=1&page=$maxpages\">>></a></th>";
+ } else {
+ echo "<th valign=\"top\" align=\"right\" nowrap class=\"generaltableheader\">> >></th>\n";
}
echo "</tr></table></td></tr></table></center>\n";
}