diff --git a/add_form.php b/add_form.php index 4157c2f..ff847dd 100644 --- a/add_form.php +++ b/add_form.php @@ -143,10 +143,17 @@ class mod_attendance_add_form extends moodleform { if (isset($pluginconfig->randompassword_default)) { $mform->setDefault('randompassword', $pluginconfig->randompassword_default); } + $mform->addElement('text', 'subnet', get_string('requiresubnet', 'attendance')); + $mform->setType('subnet', PARAM_TEXT); + $mform->addHelpButton('subnet', 'requiresubnet', 'attendance'); + $mform->disabledif('subnet', 'studentscanmark', 'notchecked'); + $mform->setDefault('subnet', $this->_customdata['att']->subnet); } else { $mform->addElement('hidden', 'studentscanmark', '0'); $mform->settype('studentscanmark', PARAM_INT); + $mform->addElement('hidden', 'subnet', ''); + $mform->setType('subnet', PARAM_TEXT); } $mform->addElement('editor', 'sdescription', get_string('description', 'attendance'), array('rows' => 1, 'columns' => 80), diff --git a/attendance.php b/attendance.php index f8825ab..c6290da 100644 --- a/attendance.php +++ b/attendance.php @@ -46,7 +46,7 @@ if (!attendance_can_student_mark($attforsession)) { } // Check if subnet is set and if the user is in the allowed range. -if (!empty($attendance->subnet) && !address_in_subnet(getremoteaddr(), $attendance->subnet)) { +if (!empty($attforsession->subnet) && !address_in_subnet(getremoteaddr(), $attforsession->subnet)) { notice(get_string('subnetwrong', 'attendance')); exit; // Notice calls this anyway. } diff --git a/backup/moodle2/backup_attendance_stepslib.php b/backup/moodle2/backup_attendance_stepslib.php index 507eb2b..9be2593 100644 --- a/backup/moodle2/backup_attendance_stepslib.php +++ b/backup/moodle2/backup_attendance_stepslib.php @@ -44,17 +44,17 @@ class backup_attendance_activity_structure_step extends backup_activity_structur // XML nodes declaration - non-user data. $attendance = new backup_nested_element('attendance', array('id'), array( - 'name', 'grade', 'showsessiondetails', 'sessiondetailspos')); + 'name', 'intro', 'introformat', 'grade', 'showsessiondetails', 'sessiondetailspos')); $statuses = new backup_nested_element('statuses'); $status = new backup_nested_element('status', array('id'), array( - 'acronym', 'description', 'grade', 'visible', 'deleted', 'setnumber')); + 'acronym', 'description', 'grade', 'studentavailability', 'visible', 'deleted', 'setnumber')); $sessions = new backup_nested_element('sessions'); $session = new backup_nested_element('session', array('id'), array( 'groupid', 'sessdate', 'duration', 'lasttaken', 'lasttakenby', 'timemodified', 'description', 'descriptionformat', 'studentscanmark', 'studentpassword', - 'statusset', 'caleventid')); + 'subnet', 'statusset', 'caleventid')); // XML nodes declaration - user data. $logs = new backup_nested_element('logs'); diff --git a/classes/structure.php b/classes/structure.php index b634c4a..6a16719 100644 --- a/classes/structure.php +++ b/classes/structure.php @@ -475,11 +475,13 @@ class mod_attendance_structure { $sess->studentscanmark = 0; $sess->studentpassword = ''; + $sess->subnet = ''; if (!empty(get_config('attendance', 'studentscanmark')) && !empty($formdata->studentscanmark)) { $sess->studentscanmark = $formdata->studentscanmark; $sess->studentpassword = $formdata->studentpassword; + $sess->subnet = $formdata->subnet; } $sess->timemodified = time(); diff --git a/db/install.xml b/db/install.xml index 411d2b9..95dac93 100644 --- a/db/install.xml +++ b/db/install.xml @@ -13,7 +13,7 @@ - + @@ -38,6 +38,7 @@ + diff --git a/db/upgrade.php b/db/upgrade.php index 42cf604..5aed323 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -260,5 +260,33 @@ function xmldb_attendance_upgrade($oldversion=0) { upgrade_mod_savepoint(true, 2017051101, 'attendance'); } + if ($oldversion < 2017051103) { + $table = new xmldb_table('attendance_sessions'); + $newfield = $table->add_field('subnet', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'studentpassword'); + if (!$dbman->field_exists($table, $newfield)) { + $dbman->add_field($table, $newfield); + } + upgrade_mod_savepoint(true, 2017051103, 'attendance'); + } + + if ($oldversion < 2017051104) { + // The meaning of the subnet in the attendance table has changed - it is now the "default" value - find all existing + // Attendance with subnet set and set the session subnet for these. + $attendances = $DB->get_recordset_select('attendance', 'subnet IS NOT NULL'); + foreach ($attendances as $attendance) { + if (!empty($attendance->subnet)) { + // Get all sessions for this attendance. + $sessions = $DB->get_recordset('attendance_sessions', array('attendanceid' => $attendance->id)); + foreach ($sessions as $session) { + $session->subnet = $attendance->subnet; + $DB->update_record('attendance_sessions', $session); + } + $sessions->close(); + } + } + $attendances->close(); + + upgrade_mod_savepoint(true, 2017051104, 'attendance'); + } return $result; } diff --git a/lang/en/attendance.php b/lang/en/attendance.php index 61c1b21..61a3bf0 100644 --- a/lang/en/attendance.php +++ b/lang/en/attendance.php @@ -374,6 +374,8 @@ $string['extrarestrictions'] = 'Extra restrictions'; $string['requiresubnet'] = 'Students can only record own attendance from these computers.'; $string['subnetwrong'] = 'Attendance can only be recorded from certain locations, and this computer is not on the allowed list.'; $string['requiresubnet_help'] = 'Attendance recording may be restricted to particular subnets by specifying a comma-separated list of partial or full IP addresses.'; +$string['defaultsubnet'] = 'Default subnet range'; +$string['defaultsubnet_help'] = 'Attendance recording may be restricted to particular subnets by specifying a comma-separated list of partial or full IP addresses. This is the default value used when creating new sessions.'; $string['defaultsettings'] = 'Default attendance settings'; $string['defaultsettings_help'] = 'These settings define the defaults for all new attendances'; $string['defaultstatus'] = 'Default status set'; diff --git a/locallib.php b/locallib.php index 1af86d2..b6eb971 100644 --- a/locallib.php +++ b/locallib.php @@ -560,6 +560,7 @@ function attendance_construct_sessions_data_for_add($formdata) { $sess->timemodified = $now; if (isset($formdata->studentscanmark)) { // Students will be able to mark their own attendance. $sess->studentscanmark = 1; + $sess->subnet = $formdata->subnet; if (!empty($formdata->randompassword)) { $sess->studentpassword = attendance_random_string(); } else { @@ -567,6 +568,7 @@ function attendance_construct_sessions_data_for_add($formdata) { } } else { $sess->studentpassword = ''; + $sess->subnet = ''; } $sess->statusset = $formdata->statusset; @@ -587,6 +589,7 @@ function attendance_construct_sessions_data_for_add($formdata) { $sess->descriptionformat = $formdata->sdescription['format']; $sess->timemodified = $now; $sess->studentscanmark = 0; + $sess->subnet = ''; $sess->studentpassword = ''; if (isset($formdata->studentscanmark) && !empty($formdata->studentscanmark)) { @@ -597,6 +600,7 @@ function attendance_construct_sessions_data_for_add($formdata) { } else { $sess->studentpassword = $formdata->studentpassword; } + $sess->subnet = $formdata->subnet; } $sess->statusset = $formdata->statusset; diff --git a/mod_form.php b/mod_form.php index dc1e9e7..64bb8f6 100644 --- a/mod_form.php +++ b/mod_form.php @@ -61,9 +61,9 @@ class mod_attendance_mod_form extends moodleform_mod { $mform->addElement('header', 'security', get_string('extrarestrictions', 'attendance')); // IP address. - $mform->addElement('text', 'subnet', get_string('requiresubnet', 'attendance'), array('size' => '164')); + $mform->addElement('text', 'subnet', get_string('defaultsubnet', 'attendance'), array('size' => '164')); $mform->setType('subnet', PARAM_TEXT); - $mform->addHelpButton('subnet', 'requiresubnet', 'attendance'); + $mform->addHelpButton('subnet', 'defaultsubnet', 'attendance'); $mform->setDefault('subnet', $attendanceconfig->subnet); $this->add_action_buttons(); diff --git a/update_form.php b/update_form.php index 24c752a..f149b46 100644 --- a/update_form.php +++ b/update_form.php @@ -66,7 +66,8 @@ class mod_attendance_update_form extends moodleform { 'endhour' => $endhour, 'endminute' => $endminute), 'sdescription' => $sess->description_editor, 'studentscanmark' => $sess->studentscanmark, - 'studentpassword' => $sess->studentpassword); + 'studentpassword' => $sess->studentpassword, + 'subnet' => $sess->subnet); $mform->addElement('header', 'general', get_string('changesession', 'attendance')); @@ -99,9 +100,16 @@ class mod_attendance_update_form extends moodleform { $mform->setType('studentpassword', PARAM_TEXT); $mform->addHelpButton('studentpassword', 'passwordgrp', 'attendance'); $mform->disabledif('studentpassword', 'studentscanmark', 'notchecked'); + + $mform->addElement('text', 'subnet', get_string('requiresubnet', 'attendance')); + $mform->setType('subnet', PARAM_TEXT); + $mform->addHelpButton('subnet', 'requiresubnet', 'attendance'); + $mform->disabledif('subnet', 'studentscanmark', 'notchecked'); } else { $mform->addElement('hidden', 'studentscanmark', '0'); $mform->settype('studentscanmark', PARAM_INT); + $mform->addElement('hidden', 'subnet', '0'); + $mform->settype('subnet', PARAM_TEXT); } $mform->addElement('editor', 'sdescription', get_string('description', 'attendance'), diff --git a/version.php b/version.php index 3a0058c..5a0db02 100644 --- a/version.php +++ b/version.php @@ -23,7 +23,7 @@ */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2017051102; +$plugin->version = 2017051104; $plugin->requires = 2017042100; $plugin->release = '3.3.5'; $plugin->maturity = MATURITY_ALPHA;