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),
}
// 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.
}
// 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');
$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();
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="The time the settings for this attendance instance were last modified."/>
<FIELD NAME="intro" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="This field is a requirement for activity modules."/>
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="This field is a requirement for activity modules."/>
- <FIELD NAME="subnet" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="Restrict ability for students to mark by subnet."/>
+ <FIELD NAME="subnet" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="Default subnet used when creating sessions."/>
<FIELD NAME="sessiondetailspos" TYPE="char" LENGTH="5" NOTNULL="true" DEFAULT="left" SEQUENCE="false" COMMENT="Position for the session detail columns related to summary columns."/>
<FIELD NAME="showsessiondetails" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="Define if session details should be shown in reports."/>
</FIELDS>
<FIELD NAME="descriptionformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="studentscanmark" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="studentpassword" TYPE="char" LENGTH="50" NOTNULL="false" DEFAULT="" SEQUENCE="false"/>
+ <FIELD NAME="subnet" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="Restrict ability for students to mark by subnet."/>
<FIELD NAME="statusset" TYPE="int" LENGTH="5" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Which set of statuses to use"/>
<FIELD NAME="caleventid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
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;
}
$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';
$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 {
}
} else {
$sess->studentpassword = '';
+ $sess->subnet = '';
}
$sess->statusset = $formdata->statusset;
$sess->descriptionformat = $formdata->sdescription['format'];
$sess->timemodified = $now;
$sess->studentscanmark = 0;
+ $sess->subnet = '';
$sess->studentpassword = '';
if (isset($formdata->studentscanmark) && !empty($formdata->studentscanmark)) {
} else {
$sess->studentpassword = $formdata->studentpassword;
}
+ $sess->subnet = $formdata->subnet;
}
$sess->statusset = $formdata->statusset;
$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();
'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'));
$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'),
*/
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 2017051102;
+$plugin->version = 2017051104;
$plugin->requires = 2017042100;
$plugin->release = '3.3.5';
$plugin->maturity = MATURITY_ALPHA;