Browse Source

Fixes #316 provide option to prevent sharing ip for this session without a timeframe.

MOODLE_34_STABLE
Dan Marsden 7 years ago
parent
commit
c270e0f9b4
  1. 10
      add_form.php
  2. 2
      lang/en/attendance.php
  3. 34
      locallib.php
  4. 6
      settings.php
  5. 7
      update_form.php

10
add_form.php

@ -242,18 +242,20 @@ class mod_attendance_add_form extends moodleform {
$mform->hideif('subnetgrp', 'studentscanmark', 'notchecked'); $mform->hideif('subnetgrp', 'studentscanmark', 'notchecked');
$mform->hideif('subnet', 'usedefaultsubnet', 'checked'); $mform->hideif('subnet', 'usedefaultsubnet', 'checked');
$mgroup3 = array(); $mgroup3 = array();
$mgroup3[] = & $mform->createElement('checkbox', 'preventsharedip', ''); $options = attendance_get_sharedipoptions();
$mgroup3[] = & $mform->createElement('select', 'preventsharedip', get_string('preventsharedip', 'attendance'), $options);
$mgroup3[] = & $mform->createElement('text', 'preventsharediptime', $mgroup3[] = & $mform->createElement('text', 'preventsharediptime',
get_string('preventsharediptime', 'attendance'), '', 'test'); get_string('preventsharediptime', 'attendance'), '', 'test');
$mgroup3[] = & $mform->createElement('static', 'preventsharediptimedesc', '',
get_string('preventsharedipminutes', 'attendance'));
$mform->addGroup($mgroup3, 'preventsharedgroup', get_string('preventsharedip', 'attendance'), array(' '), false); $mform->addGroup($mgroup3, 'preventsharedgroup', get_string('preventsharedip', 'attendance'), array(' '), false);
$mform->addHelpButton('preventsharedgroup', 'preventsharedip', 'attendance'); $mform->addHelpButton('preventsharedgroup', 'preventsharedip', 'attendance');
$mform->setAdvanced('preventsharedgroup'); $mform->setAdvanced('preventsharedgroup');
$mform->setType('preventsharedip', PARAM_INT);
$mform->setType('preventsharediptime', PARAM_INT); $mform->setType('preventsharediptime', PARAM_INT);
$mform->hideif('preventsharedgroup', 'studentscanmark', 'notchecked'); $mform->hideif('preventsharedgroup', 'studentscanmark', 'notchecked');
$mform->disabledIf('preventsharediptime', 'preventsharedip', 'notchecked'); $mform->hideIf('preventsharediptime', 'preventsharedip', 'noteq', ATTENDANCE_SHAREDIP_MINUTES);
if (isset($pluginconfig->preventsharedip)) { if (isset($pluginconfig->preventsharedip)) {
$mform->setDefault('preventsharedip', $pluginconfig->preventsharedip); $mform->setDefault('preventsharedip', $pluginconfig->preventsharedip);
} }

2
lang/en/attendance.php

@ -333,7 +333,6 @@ $string['preventsharedip'] = 'Prevent students sharing IP address';
$string['preventsharedip_help'] = 'Prevent students from using the same device (identified using IP address) to take attendance for other students.'; $string['preventsharedip_help'] = 'Prevent students from using the same device (identified using IP address) to take attendance for other students.';
$string['preventsharediptime'] = 'Time to allow re-use of IP address (minutes)'; $string['preventsharediptime'] = 'Time to allow re-use of IP address (minutes)';
$string['preventsharediptime_help'] = 'Allow an IP address to be re-used for taking attendance in this session after this time has elapsed.'; $string['preventsharediptime_help'] = 'Allow an IP address to be re-used for taking attendance in this session after this time has elapsed.';
$string['preventsharedipminutes'] = '(minutes to release IP)';
$string['preventsharederror'] = 'Self-marking has been disabled for a session because this device appears to have been used to record attendance for another student.'; $string['preventsharederror'] = 'Self-marking has been disabled for a session because this device appears to have been used to record attendance for another student.';
$string['priorto'] = 'The session date is prior to the course start date ({$a}) so that the new sessions scheduled before this date will be hidden (not accessible). You can change the course start date at any time (see course settings) in order to have access to earlier sessions.<br><br>Please change the session date or just click the "Add session" button again to confirm?'; $string['priorto'] = 'The session date is prior to the course start date ({$a}) so that the new sessions scheduled before this date will be hidden (not accessible). You can change the course start date at any time (see course settings) in order to have access to earlier sessions.<br><br>Please change the session date or just click the "Add session" button again to confirm?';
$string['processingfile'] = 'Processing file'; $string['processingfile'] = 'Processing file';
@ -423,6 +422,7 @@ $string['sessionupdated'] = 'Session successfully updated';
$string['set_by_student'] = 'Self-recorded'; $string['set_by_student'] = 'Self-recorded';
$string['setallstatuses'] = 'Set status for all users'; $string['setallstatuses'] = 'Set status for all users';
$string['setallstatusesto'] = 'Set status for all users to «{$a}»'; $string['setallstatusesto'] = 'Set status for all users to «{$a}»';
$string['setperiod'] = 'Specified time in minutes to release IP';
$string['settings'] = 'Settings'; $string['settings'] = 'Settings';
$string['setunmarked'] = 'Automatically set when not marked'; $string['setunmarked'] = 'Automatically set when not marked';
$string['setunmarked_help'] = 'If enabled in the session, set this status if a student has not marked their own attendance.'; $string['setunmarked_help'] = 'If enabled in the session, set this status if a student has not marked their own attendance.';

34
locallib.php

@ -43,6 +43,10 @@ define('ATTENDANCE_AUTOMARK_DISABLED', 0);
define('ATTENDANCE_AUTOMARK_ALL', 1); define('ATTENDANCE_AUTOMARK_ALL', 1);
define('ATTENDANCE_AUTOMARK_CLOSE', 2); define('ATTENDANCE_AUTOMARK_CLOSE', 2);
define('ATTENDANCE_SHAREDIP_DISABLED', 0);
define('ATTENDANCE_SHAREDIP_MINUTES', 1);
define('ATTENDANCE_SHAREDIP_FORCE', 2);
// Max number of sessions available in the warnings set form to trigger warnings. // Max number of sessions available in the warnings set form to trigger warnings.
define('ATTENDANCE_MAXWARNAFTER', 100); define('ATTENDANCE_MAXWARNAFTER', 100);
@ -443,10 +447,18 @@ function attendance_can_student_mark($sess) {
} }
// Check if another student has marked attendance from this IP address recently. // Check if another student has marked attendance from this IP address recently.
if ($canmark && !empty($sess->preventsharedip)) { if ($canmark && !empty($sess->preventsharedip)) {
$time = time() - ($sess->preventsharediptime * 60); if ($sess->preventsharedip == ATTENDANCE_SHAREDIP_MINUTES) {
$sql = 'sessionid = ? AND studentid <> ? AND timetaken > ? AND ipaddress = ?'; $time = time() - ($sess->preventsharediptime * 60);
$params = array($sess->id, $USER->id, $time, getremoteaddr()); $sql = 'sessionid = ? AND studentid <> ? AND timetaken > ? AND ipaddress = ?';
$record = $DB->get_record_select('attendance_log', $sql, $params); $params = array($sess->id, $USER->id, $time, getremoteaddr());
$record = $DB->get_record_select('attendance_log', $sql, $params);
} else {
// Assume ATTENDANCE_SHAREDIP_FORCED.
$sql = 'sessionid = ? AND studentid <> ? ipaddress = ?';
$params = array($sess->id, $USER->id, getremoteaddr());
$record = $DB->get_record_select('attendance_log', $sql, $params);
}
if (!empty($record)) { if (!empty($record)) {
// Trigger an ip_shared event. // Trigger an ip_shared event.
$attendanceid = $DB->get_field('attendance_sessions', 'attendanceid', array('id' => $record->sessionid)); $attendanceid = $DB->get_field('attendance_sessions', 'attendanceid', array('id' => $record->sessionid));
@ -932,3 +944,17 @@ function attendance_get_automarkoptions() {
$options[ATTENDANCE_AUTOMARK_CLOSE] = get_string('automarkclose', 'attendance'); $options[ATTENDANCE_AUTOMARK_CLOSE] = get_string('automarkclose', 'attendance');
return $options; return $options;
} }
/**
* Get available sharedip options.
*
* @return array
*/
function attendance_get_sharedipoptions() {
$options = array();
$options[ATTENDANCE_SHAREDIP_DISABLED] = get_string('no');
$options[ATTENDANCE_SHAREDIP_FORCE] = get_string('yes');
$options[ATTENDANCE_SHAREDIP_MINUTES] = get_string('setperiod', 'attendance');
return $options;
}

6
settings.php

@ -122,8 +122,10 @@ if ($ADMIN->fulltree) {
$settings->add(new admin_setting_configcheckbox('attendance/autoassignstatus', $settings->add(new admin_setting_configcheckbox('attendance/autoassignstatus',
get_string('autoassignstatus', 'attendance'), '', 0)); get_string('autoassignstatus', 'attendance'), '', 0));
$settings->add(new admin_setting_configcheckbox('attendance/preventsharedip', $options = attendance_get_sharedipoptions();
get_string('preventsharedip', 'attendance'), '', 0)); $settings->add(new admin_setting_configselect('attendance/preventsharedip',
get_string('preventsharedip', 'attendance'),
'', ATTENDANCE_SHAREDIP_DISABLED, $options));
$settings->add(new admin_setting_configtext('attendance/preventsharediptime', $settings->add(new admin_setting_configtext('attendance/preventsharediptime',
get_string('preventsharediptime', 'attendance'), get_string('preventsharediptime_help', 'attendance'), '', PARAM_RAW)); get_string('preventsharediptime', 'attendance'), get_string('preventsharediptime_help', 'attendance'), '', PARAM_RAW));

7
update_form.php

@ -159,18 +159,17 @@ class mod_attendance_update_form extends moodleform {
$mform->settype('automarkcompleted', PARAM_INT); $mform->settype('automarkcompleted', PARAM_INT);
$mgroup3 = array(); $mgroup3 = array();
$mgroup3[] = & $mform->createElement('checkbox', 'preventsharedip', ''); $options = attendance_get_sharedipoptions();
$mgroup3[] = & $mform->createElement('select', 'preventsharedip', get_string('preventsharedip', 'attendance'), $options);
$mgroup3[] = & $mform->createElement('text', 'preventsharediptime', $mgroup3[] = & $mform->createElement('text', 'preventsharediptime',
get_string('preventsharediptime', 'attendance'), '', 'test'); get_string('preventsharediptime', 'attendance'), '', 'test');
$mgroup3[] = & $mform->createElement('static', 'preventsharediptimedesc', '',
get_string('preventsharedipminutes', 'attendance'));
$mform->addGroup($mgroup3, 'preventsharedgroup', $mform->addGroup($mgroup3, 'preventsharedgroup',
get_string('preventsharedip', 'attendance'), array(' '), false); get_string('preventsharedip', 'attendance'), array(' '), false);
$mform->addHelpButton('preventsharedgroup', 'preventsharedip', 'attendance'); $mform->addHelpButton('preventsharedgroup', 'preventsharedip', 'attendance');
$mform->setAdvanced('preventsharedgroup'); $mform->setAdvanced('preventsharedgroup');
$mform->setType('preventsharediptime', PARAM_INT); $mform->setType('preventsharediptime', PARAM_INT);
$mform->hideif('preventsharedgroup', 'studentscanmark', 'notchecked'); $mform->hideif('preventsharedgroup', 'studentscanmark', 'notchecked');
$mform->disabledIf('preventsharediptime', 'preventsharedip', 'notchecked'); $mform->hideIf('preventsharediptime', 'preventsharedip', 'noteq', ATTENDANCE_SHAREDIP_MINUTES);
} else { } else {
$mform->addElement('hidden', 'studentscanmark', '0'); $mform->addElement('hidden', 'studentscanmark', '0');
$mform->settype('studentscanmark', PARAM_INT); $mform->settype('studentscanmark', PARAM_INT);

Loading…
Cancel
Save