From 51383e2cdf508611fcb1060b5841dd4323fe5020 Mon Sep 17 00:00:00 2001 From: jungwirr Date: Mon, 3 May 2004 19:59:02 +0000 Subject: [PATCH] fixed another foreach problem in lib. Added a todo section to the README --- mod/attendance/README.txt | 7 +++ mod/attendance/lib.php | 91 +++++++++++++++++++++------------------ 2 files changed, 55 insertions(+), 43 deletions(-) diff --git a/mod/attendance/README.txt b/mod/attendance/README.txt index 527c8cf805..8a9aaea358 100644 --- a/mod/attendance/README.txt +++ b/mod/attendance/README.txt @@ -21,3 +21,10 @@ Quick install instructions 4) Go to the site configuration page -> modules section -> attendance to specify your preferences for the module (optional) + +New Feature and fix list: + +Automatic attendance loggin based on IP address range +Attendance logging by email/Imode (via cel phone) +Specify a range of attendance times for automatic attendance logging. +Tighter integration with the new calendar features. diff --git a/mod/attendance/lib.php b/mod/attendance/lib.php index aeb5ed8b97..e153fdf8c8 100755 --- a/mod/attendance/lib.php +++ b/mod/attendance/lib.php @@ -187,9 +187,9 @@ function attendance_user_outline($course, $user, $mod, $attendance) { // build array of all tardies $tarr = array(); foreach ($tardyrecs as $tardyrec) { - array_push($tarr, $tardyrec->hour); - $tardystring = $tardystring . ", " . $tardyrec->hour; - } + array_push($tarr, $tardyrec->hour); + $tardystring = $tardystring . ", " . $tardyrec->hour; + } $end=array_pop($tarr); $tardystring = "Tardy in hours " . implode(", ", $tarr) . " and ". $end . ". "; } @@ -226,14 +226,15 @@ function attendance_user_complete($course, $user, $mod, $attendance) { $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; } + if ($attrecs) { 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++) { + echo "\n"; + } + echo ""; for($j=1;$j<=$attendance->hours;$j++) { // set the attendance defaults for each student if (isset($grid[$j])) { @@ -266,7 +267,7 @@ function attendance_cron () { // look for all attendance instances set to autoattend if (!$attendances = get_records("attendance", "autoattend", 1, "course ASC")) { return true; - } + } $td = attendance_find_today(time()); $tm = attendance_find_tomorrow(time()); foreach($attendances as $attendance) { @@ -277,25 +278,27 @@ function attendance_cron () { $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 ($courses[$attendance->course]->students) { + 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 students exist } // if the attendance roll is for today } // for each attendance in the system return true; @@ -308,21 +311,23 @@ function attendance_grades($attendanceid) { $attendance = get_record("attendance", "id", $attendanceid); if ($attendance->grade == "1") { $students = get_course_students($attendance->course); - foreach ($students as $student) { - $rolls = attendance_get_records("attendance_roll", - "dayid",$attendance->id, - "userid",$student->id); - $abs=$tar=0; - if ($rolls) { - foreach ($rolls as $roll) { - if ($roll->status == 1) {$tar++;} - elseif ($roll->status == 2) {$abs++;} - } - $total = $attendance->hours - attendance_tally_overall_absences_decimal($abs, $tar); - $percent = ($total != 0)?$total/$attendance->hours:0; - $return->grades[$student->id] = ($percent == 0)?0.0:$attendance->maxgrade * $percent; - } else { $return->grades[$student->id] = $attendance->maxgrade; } - } // foreach student + if ($students) { + foreach ($students as $student) { + $rolls = attendance_get_records("attendance_roll", + "dayid",$attendance->id, + "userid",$student->id); + $abs=$tar=0; + if ($rolls) { + foreach ($rolls as $roll) { + if ($roll->status == 1) {$tar++;} + elseif ($roll->status == 2) {$abs++;} + } // if rolls + $total = $attendance->hours - attendance_tally_overall_absences_decimal($abs, $tar); + $percent = ($total != 0)?$total/$attendance->hours:0; + $return->grades[$student->id] = ($percent == 0)?0.0:$attendance->maxgrade * $percent; + } else { $return->grades[$student->id] = $attendance->maxgrade; } + } // foreach student + } // if students $return->maxgrade = $attendance->maxgrade; } else { // if attendance->grade == "1" $return->grades = NULL; -- 2.39.5
Hour:".$j."
Status:".$j."
Status: