Browse Source

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

MOODLE_36_STABLE
Dan Marsden 7 years ago
parent
commit
51175e010f
  1. 10
      add_form.php
  2. 2
      lang/en/attendance.php
  3. 36
      locallib.php
  4. 6
      settings.php
  5. 7
      update_form.php

10
add_form.php

@ -253,18 +253,20 @@ class mod_attendance_add_form extends moodleform {
$mform->hideif('subnetgrp', 'studentscanmark', 'notchecked');
$mform->hideif('subnet', 'usedefaultsubnet', 'checked');
$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',
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->addHelpButton('preventsharedgroup', 'preventsharedip', 'attendance');
$mform->setAdvanced('preventsharedgroup');
$mform->setType('preventsharedip', PARAM_INT);
$mform->setType('preventsharediptime', PARAM_INT);
$mform->hideif('preventsharedgroup', 'studentscanmark', 'notchecked');
$mform->disabledIf('preventsharediptime', 'preventsharedip', 'notchecked');
$mform->hideIf('preventsharediptime', 'preventsharedip', 'noteq', ATTENDANCE_SHAREDIP_MINUTES);
if (isset($pluginconfig->preventsharedip)) {
$mform->setDefault('preventsharedip', $pluginconfig->preventsharedip);
}

2
lang/en/attendance.php

@ -338,7 +338,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['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['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['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';
@ -428,6 +427,7 @@ $string['sessionupdated'] = 'Session successfully updated';
$string['set_by_student'] = 'Self-recorded';
$string['setallstatuses'] = 'Set status for all users';
$string['setallstatusesto'] = 'Set status for all users to «{$a}»';
$string['setperiod'] = 'Specified time in minutes to release IP';
$string['settings'] = 'Settings';
$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.';

36
locallib.php

@ -43,6 +43,10 @@ define('ATTENDANCE_AUTOMARK_DISABLED', 0);
define('ATTENDANCE_AUTOMARK_ALL', 1);
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.
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.
if ($canmark && !empty($sess->preventsharedip)) {
$time = time() - ($sess->preventsharediptime * 60);
$sql = 'sessionid = ? AND studentid <> ? AND timetaken > ? AND ipaddress = ?';
$params = array($sess->id, $USER->id, $time, getremoteaddr());
$record = $DB->get_record_select('attendance_log', $sql, $params);
if ($sess->preventsharedip == ATTENDANCE_SHAREDIP_MINUTES) {
$time = time() - ($sess->preventsharediptime * 60);
$sql = 'sessionid = ? AND studentid <> ? AND timetaken > ? AND ipaddress = ?';
$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)) {
// Trigger an ip_shared event.
$attendanceid = $DB->get_field('attendance_sessions', 'attendanceid', array('id' => $record->sessionid));
@ -938,4 +950,18 @@ function attendance_get_automarkoptions() {
}
$options[ATTENDANCE_AUTOMARK_CLOSE] = get_string('automarkclose', 'attendance');
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

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

7
update_form.php

@ -170,18 +170,17 @@ class mod_attendance_update_form extends moodleform {
$mform->settype('automarkcompleted', PARAM_INT);
$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',
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->addHelpButton('preventsharedgroup', 'preventsharedip', 'attendance');
$mform->setAdvanced('preventsharedgroup');
$mform->setType('preventsharediptime', PARAM_INT);
$mform->hideif('preventsharedgroup', 'studentscanmark', 'notchecked');
$mform->disabledIf('preventsharediptime', 'preventsharedip', 'notchecked');
$mform->hideIf('preventsharediptime', 'preventsharedip', 'noteq', ATTENDANCE_SHAREDIP_MINUTES);
} else {
$mform->addElement('hidden', 'studentscanmark', '0');
$mform->settype('studentscanmark', PARAM_INT);

Loading…
Cancel
Save