diff --git a/add_form.php b/add_form.php
index a1c6b69..421cc4e 100644
--- a/add_form.php
+++ b/add_form.php
@@ -242,18 +242,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);
}
diff --git a/lang/en/attendance.php b/lang/en/attendance.php
index d66899e..e28bc77 100644
--- a/lang/en/attendance.php
+++ b/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['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.
Please change the session date or just click the "Add session" button again to confirm?';
$string['processingfile'] = 'Processing file';
@@ -423,6 +422,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.';
diff --git a/locallib.php b/locallib.php
index 519513a..78773d4 100644
--- a/locallib.php
+++ b/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));
@@ -931,4 +943,18 @@ function attendance_get_automarkoptions() {
}
$options[ATTENDANCE_AUTOMARK_CLOSE] = get_string('automarkclose', 'attendance');
return $options;
-}
\ No newline at end of file
+}
+
+/**
+ * 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;
+}
diff --git a/settings.php b/settings.php
index 3b2e2c4..06a36c3 100644
--- a/settings.php
+++ b/settings.php
@@ -122,8 +122,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));
diff --git a/update_form.php b/update_form.php
index a9c0623..166267c 100644
--- a/update_form.php
+++ b/update_form.php
@@ -159,18 +159,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);