libdir.'/blocklib.php'); require_once('locallib.php'); require_once('lib.php'); if (!function_exists('grade_update')) { //workaround for buggy PHP versions require_once($CFG->libdir.'/gradelib.php'); } $id = required_param('id', PARAM_INT); $sessionid = required_param('sessionid', PARAM_INT); $grouptype = required_param('grouptype', PARAM_INT); $group = optional_param('group', -1, PARAM_INT); // Group to show $sort = optional_param('sort','lastname', PARAM_ALPHA); $copyfrom = optional_param('copyfrom', -1, PARAM_INT); if (! $cm = get_record('course_modules', 'id', $id)) { error('Course Module ID was incorrect'); } if (! $course = get_record('course', 'id', $cm->course)) { error('Course is misconfigured'); } require_login($course->id); if (! $attforblock = get_record('attforblock', 'id', $cm->instance)) { error("Course module is incorrect"); } 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'); } $statlist = implode(',', array_keys( (array)get_statuses($attforblock->id) )); if ($form = data_submitted()) { $students = array(); // stores students ids $formarr = (array)$form; $i = 0; $now = time(); foreach($formarr as $key => $value) { if(substr($key,0,7) == 'student' && $value !== '') { $students[$i] = new Object(); $sid = substr($key,7); // gets studeent id from radiobutton name $students[$i]->studentid = $sid; $students[$i]->statusid = $value; $students[$i]->statusset = $statlist; $students[$i]->remarks = array_key_exists('remarks'.$sid, $formarr) ? $formarr['remarks'.$sid] : ''; $students[$i]->sessionid = $sessionid; $students[$i]->timetaken = $now; $students[$i]->takenby = $USER->id; $i++; } } $attforblockrecord = get_record('attforblock', 'id', $cm->instance);//'course', $course->id); foreach($students as $student) { if ($log = get_record('attendance_log', 'sessionid', $sessionid, 'studentid', $student->studentid)) { $student->id = $log->id; // this is id of log update_record('attendance_log', $student); } else { insert_record('attendance_log', $student); } } set_field('attendance_sessions', 'lasttaken', $now, 'id', $sessionid); set_field('attendance_sessions', 'lasttakenby', $USER->id, 'id', $sessionid); attforblock_update_grades($attforblockrecord); add_to_log($course->id, 'attendance', 'updated', 'mod/attforblock/report.php?id='.$id, $user->lastname.' '.$user->firstname); redirect('manage.php?id='.$id, get_string('attendancesuccess','attforblock'), 3); exit(); } /// Print headers $navlinks[] = array('name' => $attforblock->name, 'link' => "view.php?id=$id", 'type' => 'activity'); $navlinks[] = array('name' => get_string('update', 'attforblock'), 'link' => null, 'type' => 'activityinstance'); $navigation = build_navigation($navlinks); print_header("$course->shortname: ".$attforblock->name.' - ' .get_string('update','attforblock'), $course->fullname, $navigation, "", "", true, " ", navmenu($course)); //check for hack if (!$sessdata = get_record('attendance_sessions', 'id', $sessionid)) { error("Required Information is missing", "manage.php?id=".$id); } $help = helpbutton ('updateattendance', get_string('help'), 'attforblock', true, false, '', true); $update = count_records('attendance_log', 'sessionid', $sessionid); if ($update) { require_capability('mod/attforblock:changeattendances', $context); print_heading(get_string('update','attforblock').' ' .get_string('attendanceforthecourse','attforblock').' :: ' .$course->fullname.$help); } else { require_capability('mod/attforblock:takeattendances', $context); print_heading(get_string('attendanceforthecourse','attforblock').' :: ' .$course->fullname.$help); } /// find out current groups mode $groupmode = groups_get_activity_groupmode($cm); $currentgroup = groups_get_activity_group($cm, true); // get the viewmode & grid columns $attforblockrecord = get_record('attforblock', 'id', $cm->instance);//'course', $course->id);'course', $course->id); $view = optional_param('view', -1, PARAM_INT); if ($view != -1) { set_user_preference("attforblock_viewmode", $view); } else { $view = get_user_preferences("attforblock_viewmode", SORTEDLISTVIEW); } $gridcols = optional_param('gridcols', -1, PARAM_INT); if ($gridcols != -1) { set_user_preference("attforblock_gridcolumns", $gridcols); } else { $gridcols = get_user_preferences("attforblock_gridcolumns",5); } echo ''; //echo '
'; $options = array (SORTEDLISTVIEW => get_string('sortedlist','attforblock'), SORTEDGRIDVIEW => get_string('sortedgrid','attforblock')); $dataurl = "attendances.php?id=$id&grouptype=$grouptype&gridcols=$gridcols"; if ($group!=-1) { $dataurl = $dataurl . "&group=$group"; } $today = usergetmidnight($sessdata->sessdate); $select = "sessdate>={$today} AND sessdate<{$today}+86400 AND attendanceid={$cm->instance}"; $todaysessions = get_records_select('attendance_sessions', $select, 'sessdate ASC'); $optionssesions = array(); if (count($todaysessions)>1) { echo '
"; } $dataurl .= "&sessionid=$sessionid"; echo '
"; foreach($todaysessions as $sessdatarow) { $descr = userdate($sessdatarow->sessdate, get_string('strftimehm', 'attforblock')) . "-" . userdate($sessdatarow->sessdate+$sessdatarow->duration, get_string('strftimehm', 'attforblock')); if ($sessdatarow->description) { $descr = $sessdatarow->description . ' ('.$descr.')'; } $optionssessions[$sessdatarow->id] = $descr; } popup_form("$dataurl&sessionid=", $optionssessions, 'fastsessionmenu', $sessionid, ''); echo "
"; popup_form("$dataurl&view=", $options, 'viewmenu', $view, ''); if ($view == SORTEDGRIDVIEW) { $options = array (1 => '1 '.get_string('column','attforblock'),'2 '.get_string('columns','attforblock'),'3 '.get_string('columns','attforblock'), '4 '.get_string('columns','attforblock'),'5 '.get_string('columns','attforblock'),'6 '.get_string('columns','attforblock'), '7 '.get_string('columns','attforblock'),'8 '.get_string('columns','attforblock'),'9 '.get_string('columns','attforblock'), '10 '.get_string('columns','attforblock')); $dataurl .= "&view=$view"; popup_form("$dataurl&gridcols=", $options, 'colsmenu', $gridcols, ''); } echo '
';//'; if ($grouptype === 0) { if ($currentgroup) { $students = get_users_by_capability($context, 'moodle/legacy:student', '', "u.$sort ASC", '', '', $currentgroup, '', false); } else { $students = get_users_by_capability($context, 'moodle/legacy:student', '', "u.$sort ASC", '', '', '', '', false); } } else { $students = get_users_by_capability($context, 'moodle/legacy:student', '', "u.$sort ASC", '', '', $grouptype, '', false); } $sort = $sort == 'firstname' ? 'firstname' : 'lastname'; /// Now we need a menu for separategroups as well! if ($grouptype === 0 && ($groupmode == VISIBLEGROUPS || ($groupmode && has_capability('moodle/site:accessallgroups', $context)))) { groups_print_activity_menu($cm, "attendances.php?id=$id&sessionid=$sessionid&grouptype=$grouptype&sort=$sort"); } $table->data[][] = ''.get_string('sessiondate','attforblock').': '.userdate($sessdata->sessdate, get_string('strftimedate').', '.get_string('strftimehm', 'attforblock')). ', "'.($sessdata->description ? $sessdata->description : get_string('nodescription', 'attforblock')).'"'; print_table($table); $statuses = get_statuses($attforblock->id); $i = 3; foreach($statuses as $st) { switch($view) { case SORTEDLISTVIEW: $tabhead[] = "$st->acronym"; break; case SORTEDGRIDVIEW: $tabhead[] = "acronym . "', null);\">$st->acronym"; break; } $i++; } if ($view == SORTEDLISTVIEW) { $tabhead[] = get_string('remarks','attforblock'); } $firstname = "".get_string('firstname').''; $lastname = "".get_string('lastname').''; if ($CFG->fullnamedisplay == 'lastname firstname') { // for better view (dlnsk) $fullnamehead = "$lastname / $firstname"; } else { $fullnamehead = "$firstname / $lastname"; } if ($students) { unset($table); switch($view) { case SORTEDLISTVIEW: // sorted list $table->width = '0%'; $table->head[] = '#'; $table->align[] = 'center'; $table->size[] = '20px'; $table->head[] = ''; $table->align[] = ''; $table->size[] = '1px'; $table->head[] = $fullnamehead; $table->align[] = 'left'; $table->size[] = ''; $table->wrap[2] = 'nowrap'; foreach ($tabhead as $hd) { $table->head[] = $hd; $table->align[] = 'center'; $table->size[] = '20px'; } $i = 0; foreach($students as $student) { $i++; $att = get_record('attendance_log', 'sessionid', $sessionid, 'studentid', $student->id); $table->data[$student->id][] = (!$att && $update) ? "$i" : $i; $table->data[$student->id][] = print_user_picture($student->id, $course->id, $student->picture, 20, true, true);//, $returnstring=false, $link=true, $target=''); $table->data[$student->id][] = "id}\">".((!$att && $update) ? '' : '').fullname($student).((!$att && $update) ? '' : '').''; foreach($statuses as $st) { $copyid = ($copyfrom == "-1") ? $sessionid : $copyfrom; $att = get_record('attendance_log', 'sessionid', $copyid, 'studentid', $student->id); $currentstatusid = $att===false ? -1 : $att->statusid; @$table->data[$student->id][] = 'id == $currentstatusid ? 'checked' : '').'>'; } $table->data[$student->id][] = ''; } break; case SORTEDGRIDVIEW: // sorted grid $table->width = '0%'; $data = ''; foreach ($tabhead as $hd) { $data = $data . $hd . ' '; } print_heading($data,'center'); $i = 0; // sanity check $gridcols = $gridcols < 1 ? 1 : $gridcols; for ($i=0; $i<$gridcols; $i++) { $table->head[] = ' '; $table->align[] = 'center'; $table->size[] = '110px'; } $i = 0; foreach($students as $student) { $i++; $copyid = ($copyfrom == "-1") ? $sessionid : $copyfrom; $att = get_record('attendance_log', 'sessionid', $copyid, 'studentid', $student->id); $currentstatusid = $att===false ? -1 : $att->statusid; $data = "" . print_user_picture($student, $course->id, $student->picture, true, true, '', fullname($student)) . "
" . fullname($student) . "
";//, $returnstring=false, $link=true, $target=''); foreach($statuses as $st) { $data = $data . 'id == $currentstatusid ? 'checked' : '').'>' . $st->acronym . " "; } $table->data[($i-1) / ($gridcols)][] = $data; } break; } echo '
'; print_table($table); echo ''; echo ''; echo ''; echo ''; echo '
'; echo '
'; if (count($todaysessions)>1) { echo '
'; echo '"; popup_form("$dataurl©from=", $optionssessions, 'copysessionmenu', $sessionid, ''); echo '
'; } } else { print_heading(get_string('nothingtodisplay'), 'center'); } echo get_string('status','attforblock').':
'; foreach($statuses as $st) { echo $st->acronym.' - '.$st->description.'
'; } print_footer($course); ?>