You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
323 lines
16 KiB
323 lines
16 KiB
15 years ago
|
<?PHP // $Id: attendances.php,v 1.2.2.5 2009/02/23 19:22:40 dlnsk Exp $
|
||
|
|
||
|
// Lists all the sessions for a course
|
||
|
|
||
|
require_once('../../config.php');
|
||
|
require_once($CFG->libdir.'/blocklib.php');
|
||
|
require_once('locallib.php');
|
||
|
require_once('lib.php');
|
||
14 years ago
|
|
||
15 years ago
|
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);
|
||
15 years ago
|
$grouptype = required_param('grouptype', PARAM_INT);
|
||
15 years ago
|
$group = optional_param('group', -1, PARAM_INT); // Group to show
|
||
|
$sort = optional_param('sort','lastname', PARAM_ALPHA);
|
||
14 years ago
|
$copyfrom = optional_param('copyfrom', -1, PARAM_INT);
|
||
15 years ago
|
|
||
14 years ago
|
if (! $cm = $DB->get_record('course_modules', array('id'=>$id))) {
|
||
15 years ago
|
error('Course Module ID was incorrect');
|
||
|
}
|
||
|
|
||
14 years ago
|
if (! $course = $DB->get_record('course', array('id'=> $cm->course))) {
|
||
15 years ago
|
error('Course is misconfigured');
|
||
|
}
|
||
|
|
||
|
require_login($course->id);
|
||
|
|
||
14 years ago
|
if (! $attforblock = $DB->get_record('attforblock', array('id'=> $cm->instance))) {
|
||
15 years ago
|
error("Course module is incorrect");
|
||
|
}
|
||
14 years ago
|
if (! $user = $DB->get_record('user', array('id'=> $USER->id) )) {
|
||
15 years ago
|
error("No such user in this course");
|
||
|
}
|
||
|
|
||
|
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
|
||
|
print_error('badcontext');
|
||
|
}
|
||
|
|
||
14 years ago
|
$statlist = implode(',', array_keys( (array)get_statuses($attforblock->id) ));
|
||
15 years ago
|
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++;
|
||
|
}
|
||
|
}
|
||
14 years ago
|
$attforblockrecord = $DB->get_record('attforblock', array('attendanceid' => $attforblock->id));
|
||
15 years ago
|
|
||
|
foreach($students as $student) {
|
||
14 years ago
|
if ($log = $DB->get_record('attendance_log', array('sessionid' => $sessionid, 'studentid'=> $student->studentid))) {
|
||
15 years ago
|
$student->id = $log->id; // this is id of log
|
||
14 years ago
|
$DB->update_record('attendance_log', $student);
|
||
15 years ago
|
} else {
|
||
14 years ago
|
$DB->insert_record('attendance_log', $student);
|
||
15 years ago
|
}
|
||
|
}
|
||
14 years ago
|
$DB->set_field('attendance_sessions', 'lasttaken', $now, array('id' => $sessionid));
|
||
|
$DB->set_field('attendance_sessions', 'lasttakenby', $USER->id, array('id' => $sessionid));
|
||
15 years ago
|
|
||
|
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
|
||
14 years ago
|
$url = new moodle_url('/mod/attforblock/manage.php', array('id'=> $id, 'sessionid'=> $sessionid, 'grouptype' => $grouptype, 'group' => $group, 'sort' => $sort, 'copyfrom' => $copyfrom));
|
||
|
$PAGE->set_url($url);
|
||
|
$PAGE->set_title($course->shortname. ": ".$attforblock->name . ' - ' .get_string('update','attforblock'));
|
||
|
$PAGE->set_heading($course->fullname);
|
||
|
$PAGE->set_focuscontrol('');
|
||
|
$PAGE->set_cacheable(true);
|
||
|
$PAGE->set_button($OUTPUT->update_module_button($cm->id,'attforblock'));
|
||
|
$PAGE->navbar->add($attforblock->name);
|
||
|
|
||
|
echo $OUTPUT->header();
|
||
|
|
||
|
/*$navlinks[] = array('name' => $attforblock->name, 'link' => "view.php?id=$id", 'type' => 'activity');
|
||
15 years ago
|
$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,
|
||
14 years ago
|
$navigation, "", "", true, " ", navmenu($course));*/
|
||
15 years ago
|
|
||
|
//check for hack
|
||
14 years ago
|
if (!$sessdata = $DB->get_record('attendance_sessions', array('id'=> $sessionid))) {
|
||
15 years ago
|
error("Required Information is missing", "manage.php?id=".$id);
|
||
|
}
|
||
|
$help = helpbutton ('updateattendance', get_string('help'), 'attforblock', true, false, '', true);
|
||
14 years ago
|
$update = $DB->count_records('attendance_log', array('sessionid'=> $sessionid));
|
||
15 years ago
|
|
||
|
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);
|
||
14 years ago
|
echo $OUTPUT->heading(get_string('attendanceforthecourse','attforblock').' :: ' .$course->fullname.$help);
|
||
15 years ago
|
}
|
||
|
|
||
|
/// find out current groups mode
|
||
|
$groupmode = groups_get_activity_groupmode($cm);
|
||
|
$currentgroup = groups_get_activity_group($cm, true);
|
||
|
|
||
14 years ago
|
// get the viewmode & grid columns
|
||
14 years ago
|
$attforblockrecord = $DB->get_record('attforblock', array('id'=> $cm->instance));//'course', $course->id);'course', $course->id);
|
||
14 years ago
|
$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);
|
||
|
}
|
||
|
|
||
14 years ago
|
echo '<table class="controls" cellspacing="0"><tr>'; //echo '<center>';
|
||
14 years ago
|
$options = array (SORTEDLISTVIEW => get_string('sortedlist','attforblock'), SORTEDGRIDVIEW => get_string('sortedgrid','attforblock'));
|
||
14 years ago
|
$dataurl = "/mod/attforblock/attendances.php?id=$id&grouptype=$grouptype&gridcols=$gridcols";
|
||
14 years ago
|
if ($group!=-1) {
|
||
14 years ago
|
$dataurl = $dataurl . "&group=$group";
|
||
14 years ago
|
}
|
||
14 years ago
|
$today = usergetmidnight($sessdata->sessdate);
|
||
14 years ago
|
$select = "sessdate>=? AND sessdate<? AND attendanceid=?";
|
||
|
$tomorrow = $today + 86400;
|
||
|
$todaysessions = $DB->get_records_select('attendance_sessions', $select, array($today, $tomorrow, $cm->instance), 'sessdate ASC');
|
||
14 years ago
|
$optionssesions = array();
|
||
14 years ago
|
if (count($todaysessions)>1) {
|
||
14 years ago
|
echo '<td class="right"><label for="fastsessionmenu_jump">'. get_string('jumpto','attforblock') . " </label>";
|
||
14 years ago
|
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;
|
||
14 years ago
|
}
|
||
14 years ago
|
//popup_form("$dataurl&sessionid=", $optionssessions, 'fastsessionmenu', $sessionid, '');
|
||
|
echo $OUTPUT->single_select(new moodle_url('/mod/attforblock/attendances.php', array('id'=> $id, 'grouptype' => $grouptype, 'group' => $group, 'sort' => $sort)),'sessionid',$optionssessions, $sessionid);
|
||
14 years ago
|
echo "<td/><tr/><tr>";
|
||
|
}
|
||
14 years ago
|
$dataurl .= "&sessionid=$sessionid";
|
||
14 years ago
|
echo '<td class="right"><label for="viewmenu_jump">'. get_string('viewmode','attforblock') . " </label>";
|
||
14 years ago
|
//popup_form("$dataurl&view=", $options, 'viewmenu', $view, '');
|
||
|
echo $OUTPUT->single_select(new moodle_url('/mod/attforblock/attendances.php', array('id'=> $id, 'sessionid'=>$sessionid, 'grouptype' => $grouptype, 'group' => $group, 'sort' => $sort)),'view',$options, $view);
|
||
14 years ago
|
if ($view == SORTEDGRIDVIEW) {
|
||
14 years ago
|
$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'));
|
||
14 years ago
|
$dataurl .= "&view=$view";
|
||
14 years ago
|
//popup_form("$dataurl&gridcols=", $options, 'colsmenu', $gridcols, '');
|
||
|
echo $OUTPUT->single_select(new moodle_url('/mod/attforblock/attendances.php', array('id'=> $id, 'sessionid'=>$sessionid, 'view'=>$view, 'grouptype' => $grouptype, 'group' => $group, 'sort' => $sort)),'gridcols',$options, $gridcols);
|
||
14 years ago
|
}
|
||
14 years ago
|
echo '</td></tr></table>';//</center>';
|
||
15 years ago
|
if ($grouptype === 0) {
|
||
|
if ($currentgroup) {
|
||
14 years ago
|
$students = get_users_by_capability($context, 'mod/attforblock:canbelisted', '', "u.$sort ASC", '', '', $currentgroup, '', false);
|
||
15 years ago
|
} else {
|
||
14 years ago
|
$students = get_users_by_capability($context, 'mod/attforblock:canbelisted', '', "u.$sort ASC", '', '', '', '', false);
|
||
15 years ago
|
}
|
||
15 years ago
|
} else {
|
||
14 years ago
|
$students = get_users_by_capability($context, 'mod/attforblock:canbelisted', '', "u.$sort ASC", '', '', $grouptype, '', false);
|
||
15 years ago
|
}
|
||
|
|
||
|
$sort = $sort == 'firstname' ? 'firstname' : 'lastname';
|
||
|
/// Now we need a menu for separategroups as well!
|
||
15 years ago
|
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");
|
||
15 years ago
|
}
|
||
|
|
||
|
$table->data[][] = '<b>'.get_string('sessiondate','attforblock').': '.userdate($sessdata->sessdate, get_string('strftimedate').', '.get_string('strftimehm', 'attforblock')).
|
||
|
', "'.($sessdata->description ? $sessdata->description : get_string('nodescription', 'attforblock')).'"</b>';
|
||
|
print_table($table);
|
||
14 years ago
|
|
||
14 years ago
|
$statuses = get_statuses($attforblock->id);
|
||
15 years ago
|
$i = 3;
|
||
14 years ago
|
$tabhead = array();
|
||
15 years ago
|
foreach($statuses as $st) {
|
||
14 years ago
|
switch($view) {
|
||
14 years ago
|
case SORTEDLISTVIEW:
|
||
15 years ago
|
$tabhead[] = "<a href=\"javascript:select_all_in('TD', 'cell c{$i}', null);\"><u>$st->acronym</u></a>";
|
||
14 years ago
|
break;
|
||
14 years ago
|
case SORTEDGRIDVIEW:
|
||
14 years ago
|
$tabhead[] = "<a href=\"javascript:select_all_in('INPUT', '". $st->acronym . "', null);\"><u>$st->acronym</u></a>";
|
||
|
break;
|
||
|
}
|
||
15 years ago
|
$i++;
|
||
|
}
|
||
14 years ago
|
if ($view == SORTEDLISTVIEW) {
|
||
15 years ago
|
$tabhead[] = get_string('remarks','attforblock');
|
||
14 years ago
|
}
|
||
15 years ago
|
|
||
|
$firstname = "<a href=\"attendances.php?id=$id&sessionid=$sessionid&sort=firstname\">".get_string('firstname').'</a>';
|
||
|
$lastname = "<a href=\"attendances.php?id=$id&sessionid=$sessionid&sort=lastname\">".get_string('lastname').'</a>';
|
||
|
if ($CFG->fullnamedisplay == 'lastname firstname') { // for better view (dlnsk)
|
||
|
$fullnamehead = "$lastname / $firstname";
|
||
|
} else {
|
||
|
$fullnamehead = "$firstname / $lastname";
|
||
|
}
|
||
|
|
||
|
if ($students) {
|
||
|
unset($table);
|
||
14 years ago
|
|
||
|
switch($view) {
|
||
14 years ago
|
case SORTEDLISTVIEW: // sorted list
|
||
15 years ago
|
$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++;
|
||
14 years ago
|
$att = $DB->get_record('attendance_log', array('sessionid'=> $sessionid, 'studentid'=> $student->id));
|
||
15 years ago
|
$table->data[$student->id][] = (!$att && $update) ? "<font color=\"red\"><b>$i</b></font>" : $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][] = "<a href=\"view.php?id=$id&student={$student->id}\">".((!$att && $update) ? '<font color="red"><b>' : '').fullname($student).((!$att && $update) ? '</b></font>' : '').'</a>';
|
||
|
|
||
|
foreach($statuses as $st) {
|
||
14 years ago
|
$copyid = ($copyfrom == "-1") ? $sessionid : $copyfrom;
|
||
14 years ago
|
$att = $DB->get_record('attendance_log', array('sessionid'=> $copyid, 'studentid'=> $student->id));
|
||
14 years ago
|
$currentstatusid = $att===false ? -1 : $att->statusid;
|
||
|
@$table->data[$student->id][] = '<input name="student'.$student->id.'" type="radio" value="'.$st->id.'" '.($st->id == $currentstatusid ? 'checked' : '').'>';
|
||
15 years ago
|
}
|
||
|
$table->data[$student->id][] = '<input type="text" name="remarks'.$student->id.'" size="" value="'.($att ? $att->remarks : '').'">';
|
||
|
}
|
||
14 years ago
|
break;
|
||
14 years ago
|
case SORTEDGRIDVIEW: // sorted grid
|
||
14 years ago
|
$table->width = '0%';
|
||
|
|
||
|
$data = '';
|
||
|
foreach ($tabhead as $hd) {
|
||
|
$data = $data . $hd . ' ';
|
||
|
}
|
||
|
print_heading($data,'center');
|
||
|
|
||
|
$i = 0;
|
||
|
// sanity check
|
||
14 years ago
|
$gridcols = $gridcols < 1 ? 1 : $gridcols;
|
||
|
for ($i=0; $i<$gridcols; $i++) {
|
||
14 years ago
|
$table->head[] = ' ';
|
||
|
$table->align[] = 'center';
|
||
|
$table->size[] = '110px';
|
||
|
}
|
||
|
|
||
|
$i = 0;
|
||
|
foreach($students as $student) {
|
||
|
$i++;
|
||
14 years ago
|
$copyid = ($copyfrom == "-1") ? $sessionid : $copyfrom;
|
||
14 years ago
|
$att = $DB->get_record('attendance_log', array('sessionid'=> $copyid, 'studentid'=> $student->id));
|
||
14 years ago
|
$currentstatusid = $att===false ? -1 : $att->statusid;
|
||
14 years ago
|
$data = "<span class='userinfobox' style='font-size:80%;border:none'>" . print_user_picture($student, $course->id, $student->picture, true, true, '', fullname($student)) . "<br/>" . fullname($student) . "<br/></span>";//, $returnstring=false, $link=true, $target='');
|
||
|
foreach($statuses as $st) {
|
||
14 years ago
|
$data = $data . '<nobr><input name="student'.$student->id.'" type="radio" class="' . $st->acronym . '" value="'.$st->id.'" '.($st->id == $currentstatusid ? 'checked' : '').'> ' . $st->acronym . "</nobr> ";
|
||
14 years ago
|
}
|
||
14 years ago
|
$table->data[($i-1) / ($gridcols)][] = $data;
|
||
14 years ago
|
}
|
||
|
break;
|
||
|
}
|
||
15 years ago
|
|
||
|
echo '<form name="takeattendance" method="post" action="attendances.php">';
|
||
|
print_table($table);
|
||
|
echo '<input type="hidden" name="id" value="'.$id.'">';
|
||
|
echo '<input type="hidden" name="sessionid" value="'.$sessionid.'">';
|
||
15 years ago
|
echo '<input type="hidden" name="grouptype" value="'.$grouptype.'">';
|
||
15 years ago
|
echo '<input type="hidden" name="formfrom" value="editsessvals">';
|
||
14 years ago
|
echo '<center><input type="submit" name="esv" value="'.get_string('save','attforblock').'"></center>';
|
||
15 years ago
|
echo '</form>';
|
||
14 years ago
|
|
||
|
if (count($todaysessions)>1) {
|
||
|
echo '<br/><table class="controls" cellspacing="0"><tr><td class="center">';
|
||
|
echo '<label for="copysessionmenu_jump">'. get_string('copyfrom','attforblock') . " </label>";
|
||
14 years ago
|
//popup_form("$dataurl©from=", $optionssessions, 'copysessionmenu', $sessionid, '');
|
||
|
echo $OUTPUT->single_select(new moodle_url('/mod/attforblock/attendances.php', array('id'=> $id, 'sessionid'=>$sessionid, 'grouptype' => $grouptype, 'group' => $group, 'sort' => $sort)),'copyfrom',$optionssessions, $sessionid);
|
||
14 years ago
|
echo '</td></tr></table>';
|
||
|
}
|
||
|
|
||
|
} else {
|
||
15 years ago
|
print_heading(get_string('nothingtodisplay'), 'center');
|
||
|
}
|
||
|
|
||
|
echo get_string('status','attforblock').':<br />';
|
||
|
foreach($statuses as $st) {
|
||
|
echo $st->acronym.' - '.$st->description.'<br />';
|
||
|
}
|
||
|
|
||
14 years ago
|
$OUTPUT->footer($course);
|
||
15 years ago
|
|
||
|
?>
|