course)) {
error("Course is misconfigured");
}
if (! $attforblock = get_record('attforblock', 'id', $cm->instance)) {
error("Course module is incorrect");
}
require_login($course->id);
if (! $user = get_record('user', 'id', $USER->id) ) {
error("No such user in this course");
}
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
if (!has_capability('mod/attforblock:manageattendances', $context) AND
!has_capability('mod/attforblock:takeattendances', $context) AND
!has_capability('mod/attforblock:changeattendances', $context)) {
redirect("view.php?id=$cm->id");
}
//if teacher is coming from block, then check for a session exists for today
if($from === 'block') {
$today = time(); // because we compare with database, we don't need to use usertime()
$sql = "SELECT id, lasttaken
FROM {$CFG->prefix}attendance_sessions
WHERE $today BETWEEN sessdate AND (sessdate + duration)
AND courseid = $course->id";
if($att = get_record_sql($sql)) {
if ((!$att->lasttaken and has_capability('mod/attforblock:takeattendances', $context)) or
($att->lasttaken and has_capability('mod/attforblock:changeattendances', $context))) {
redirect('attendances.php?id='.$id.'&sessionid='.$att->id);
}
}
}
/// Print headers
$navlinks[] = array('name' => $attforblock->name, 'link' => null, 'type' => 'activity');
$navigation = build_navigation($navlinks);
print_header("$course->shortname: ".$attforblock->name, $course->fullname,
$navigation, "", "", true, update_module_button($cm->id, $course->id, get_string('modulename', 'attforblock')),
navmenu($course));
print_heading(get_string('attendanceforthecourse','attforblock').' :: ' .$course->fullname);
if(!count_records_select('attendance_sessions', "courseid = $course->id AND sessdate >= $course->startdate")) { // no session exists for this course
show_tabs($cm, $context);
print_heading(get_string('nosessionexists','attforblock'));
$hiddensess = count_records_select('attendance_sessions', "courseid = $course->id AND sessdate < $course->startdate");
echo '