Browse Source

Move subnet from attendance level to session level

retain attendance level setting as "default" setting for creating
new sessions.
MOODLE_32_STABLE
Dan Marsden 8 years ago
parent
commit
00ce366a41
  1. 7
      add_form.php
  2. 2
      attendance.php
  3. 6
      backup/moodle2/backup_attendance_stepslib.php
  4. 2
      classes/structure.php
  5. 3
      db/install.xml
  6. 25
      db/upgrade.php
  7. 2
      lang/en/attendance.php
  8. 4
      locallib.php
  9. 4
      mod_form.php
  10. 10
      update_form.php
  11. 4
      version.php

7
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),

2
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.
}

6
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');

2
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();

3
db/install.xml

@ -13,7 +13,7 @@
<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>
@ -38,6 +38,7 @@
<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>

25
db/upgrade.php

@ -260,5 +260,30 @@ function xmldb_attendance_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2016121309, 'attendance');
}
if ($oldversion < 2016121310) {
$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);
// 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, 2016121310, 'attendance');
}
return $result;
}

2
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';

4
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;

4
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();

10
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'),

4
version.php

@ -23,9 +23,9 @@
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2016121309;
$plugin->version = 2016121310;
$plugin->requires = 2016111800;
$plugin->release = '3.2.8';
$plugin->release = '3.2.9';
$plugin->maturity = MATURITY_STABLE;
$plugin->cron = 0;
$plugin->component = 'mod_attendance';

Loading…
Cancel
Save