]> git.mjollnir.org Git - moodle.git/commitdiff
Added automatic attendance logging based on date and any activity by
authorjungwirr <jungwirr>
Thu, 25 Sep 2003 18:54:18 +0000 (18:54 +0000)
committerjungwirr <jungwirr>
Thu, 25 Sep 2003 18:54:18 +0000 (18:54 +0000)
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.

lang/en/attendance.php
mod/attendance/db/mysql.php
mod/attendance/db/mysql.sql
mod/attendance/lib.php
mod/attendance/version.php
mod/attendance/viewall.php
mod/attendance/viewweek.php

index f72d308f27aeb367e5a94c0ed0ca41e711fed995..5051720201453b091a9f6d7484101d2f9b45769e 100755 (executable)
@@ -27,7 +27,6 @@ $string['defaultdynamicsection'] = "Whether to move attendance rolls to the corr
 $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['downloadexcelfull'] = "Download Full Excel Spreadsheet";
 $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";
+
 
 ?>
index 280f4c67ee9c88fdfc499b338300998d399734fb..10187972ea4e27c7f2408ae5ba3b5c1287ec229f 100644 (file)
@@ -10,6 +10,9 @@ function attendance_upgrade($oldversion) {
         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
index 4750674f66144da330e86aad363d91bf600c66e7..c559b9256b02abfdb25e7421db6a53b14c3e3e02 100755 (executable)
@@ -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;
 
index 83f5a055152339e2b4b15f4497a6d3e966a69313..603e7f42cb1aabd1c3ed604e5f86fe85f8f00888 100755 (executable)
@@ -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);
+}
+
+
 ?>
index 0d1749c9a8e2d6a31cce0ce385d8a24a71cf305f..27ba381e34896a86d21a2d715452bdb830713448 100644 (file)
@@ -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)
 
 ?>
index ed5e0bc5de704d16445365a07b59bff12386e1bd..0574b52221192add2647d4c835adec26f8a88ed0 100644 (file)
@@ -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 @@ if ($attendances) {
    $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 @@ if ($download == "xls") {
   // 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 @@ while (($multipage || $onepage) && (!$endonepage)) {
   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 @@ while (($multipage || $onepage) && (!$endonepage)) {
 
   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 @@ while (($multipage || $onepage) && (!$endonepage)) {
     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";
   }
index c8f11e493545e8290f3b4cbd0d1acb25c2325ece..a58ede777fd111dcc5bcbf5e0f419b9d772ef87e 100644 (file)
@@ -51,6 +51,8 @@ if ($attendances) {
    $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 @@ if ($download == "xls") {
   // 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 @@ while (($multipage || $onepage) && (!$endonepage)) {
     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";
   }