get_record('course_modules', array('id'=> $id))) {
error('Course Module ID was incorrect');
}
if (! $course = $DB->get_record('course', array('id'=> $cm->course))) {
error('Course is misconfigured');
}
if (! $attforblock = $DB->get_record('attforblock', array('id'=> $cm->instance))) {
error("Course module is incorrect");
}
}
//$attforblockrecord = get_record('attforblock','course',$course->id);
if (! $attforblockrecord = $DB->get_record('attforblock', array('id'=> $cm->instance))) {
error("Course module is incorrect");
}
require_login($course->id);
if (! $user = $DB->get_record('user', array('id'=> $USER->id) )) {
error("No such user in this course");
}
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
require_capability('mod/attforblock:manageattendances', $context);
/// Print headers
$navlinks[] = array('name' => $attforblock->name, 'link' => "view.php?id=$id", 'type' => 'activity');
$navlinks[] = array('name' => get_string('settings', 'attforblock'), 'link' => null, 'type' => 'activityinstance');
$navigation = build_navigation($navlinks);
print_header("$course->shortname: ".$attforblock->name.' - '.get_string('settings','attforblock'), $course->fullname,
$navigation, "", "", true, " ", navmenu($course));
if (!empty($action)) {
switch ($action) {
case 'delete':
if (!$rec = $DB->get_record('attendance_statuses', array('attendanceid'=> $$attforblockrecord->id, 'id'=> $stid))) {
print_error('notfoundstatus', 'attforblock', "attsettings.php?id=$id");
}
if ($DB->count_records('attendance_log', array('statusid'=> $stid))) {
print_error('cantdeletestatus', 'attforblock', "attsettings.php?id=$id");
}
$confirm = optional_param('confirm');
if (isset($confirm)) {
$DB->set_field('attendance_statuses', 'deleted', 1, array('id' => $rec->id));
// delete_records('attendance_statuses', 'id', $rec->id);
redirect('attsettings.php?id='.$id, get_string('statusdeleted','attforblock'), 3);
}
print_heading(get_string('deletingstatus','attforblock').' :: ' .$course->fullname);
notice_yesno(get_string('deletecheckfull', '', get_string('variable', 'attforblock')).
'
'.$rec->acronym.': '.
($rec->description ? $rec->description : get_string('nodescription', 'attforblock')),
"attsettings.php?id=$id&st=$stid&action=delete&confirm=1", $_SERVER['HTTP_REFERER']);
exit;
case 'show':
$DB->set_field('attendance_statuses', 'visible', 1, array('id' => $stid));
break;
case 'hide':
$students = get_users_by_capability($context, 'moodle/legacy:student', '', '', '', '', '', '', false);
$studlist = implode(',', array_keys($students));
if (!$DB->count_records_select('attendance_log', "studentid IN (?) AND statusid = ?", array( $studlist, $stid) )) {
$DB->set_field('attendance_statuses', 'visible', 0, array('id' => $stid));
} else {
print_error('canthidestatus', 'attforblock', "attsettings.php?id=$id");
}
break;
default: //Adding new status
$newacronym = optional_param('newacronym', '', PARAM_MULTILANG);
$newdescription = optional_param('newdescription', '', PARAM_MULTILANG);
$newgrade = optional_param('newgrade', 0, PARAM_INT);
if (!empty($newacronym) && !empty($newdescription)) {
unset($rec);
$rec->courseid = $course->id;
$rec->attendanceid = $attforblock->id;
$rec->acronym = $newacronym;
$rec->description = $newdescription;
$rec->grade = $newgrade;
$DB->insert_record('attendance_statuses', $rec);
add_to_log($course->id, 'attendance', 'setting added', 'mod/attforblock/attsettings.php?course='.$course->id, $user->lastname.' '.$user->firstname);
} else {
print_error('cantaddstatus', 'attforblock', "attsettings.php?id=$id");
}
break;
}
}
show_tabs($cm, $context, 'settings');
if ($submitsettings) {
config_save(); //////////////////////////////
notice(get_string('variablesupdated','attforblock'), 'attsettings.php?id='.$id);
}
$i = 1;
$table->width = '100%';
//$table->tablealign = 'center';
$table->head = array('#',
get_string('acronym','attforblock'),
get_string('description'),
get_string('grade'),
get_string('action'));
$table->align = array('center', 'center', 'center', 'center', 'center', 'center');
//$table->size = array('1px', '1px', '*', '1px', '1px', '1px');
$statuses = get_statuses($attforblockrecord->id, false);
$deltitle = get_string('delete');
foreach($statuses as $st)
{
$table->data[$i][] = $i;
// $table->data[$i][] = $st->status;
$table->data[$i][] = '';
$table->data[$i][] = '';
$table->data[$i][] = '';
$action = $st->visible ? 'hide' : 'show';
$titlevis = get_string($action);
$deleteact = '';
if (!$DB->count_records('attendance_log', array('statusid'=> $st->id))) {
$deleteact = "id&st={$st->id}&action=delete\">".
"pixpath}/t/delete.gif\" alt=\"$deltitle\" /> ";
}
$table->data[$i][] = "id&st={$st->id}&action=$action\">".
"pixpath}/t/{$action}.gif\" alt=\"$titlevis\" /> ".
$deleteact;
$i++;
}
$new_row = array('*',
'',
'',
'',
''
);
$table->data[$i] = $new_row;
echo '