Browse Source

Modify subnet field to hopefully improve usability with teachers.

MOODLE_34_STABLE
Dan Marsden 8 years ago
parent
commit
e1c00b0464
  1. 17
      add_form.php
  2. 7
      classes/structure.php
  3. 5
      lang/en/attendance.php
  4. 16
      locallib.php
  5. 2
      sessions.php
  6. 22
      update_form.php

17
add_form.php

@ -159,13 +159,20 @@ class mod_attendance_add_form extends moodleform {
if (isset($pluginconfig->automark_default)) { if (isset($pluginconfig->automark_default)) {
$mform->setDefault('automark', $pluginconfig->automark_default); $mform->setDefault('automark', $pluginconfig->automark_default);
} }
$mform->addElement('text', 'subnet', get_string('requiresubnet', 'attendance')); $mgroup2 = array();
$mform->setType('subnet', PARAM_TEXT); $mgroup2[] = & $mform->createElement('text', 'subnet', get_string('requiresubnet', 'attendance'));
$mform->addHelpButton('subnet', 'requiresubnet', 'attendance');
$mform->disabledif('subnet', 'studentscanmark', 'notchecked');
$mform->setDefault('subnet', $this->_customdata['att']->subnet); $mform->setDefault('subnet', $this->_customdata['att']->subnet);
$mform->setAdvanced('subnet'); $mgroup2[] = & $mform->createElement('checkbox', 'usedefaultsubnet', get_string('usedefaultsubnet', 'attendance'));
$mform->setDefault('usedefaultsubnet', 1);
$mform->setType('subnet', PARAM_TEXT);
$mform->addGroup($mgroup2, 'subnetgrp', get_string('requiresubnet', 'attendance'), array(' '), false);
$mform->setAdvanced('subnetgrp');
$mform->addHelpButton('subnetgrp', 'requiresubnet', 'attendance');
$mform->disabledif('usedefaultsubnet', 'studentscanmark', 'notchecked');
$mform->disabledif('subnet', 'studentscanmark', 'notchecked');
$mform->disabledif('subnet', 'usedefaultsubnet', 'checked');
} else { } else {
$mform->addElement('hidden', 'studentscanmark', '0'); $mform->addElement('hidden', 'studentscanmark', '0');
$mform->settype('studentscanmark', PARAM_INT); $mform->settype('studentscanmark', PARAM_INT);

7
classes/structure.php

@ -500,7 +500,12 @@ class mod_attendance_structure {
!empty($formdata->studentscanmark)) { !empty($formdata->studentscanmark)) {
$sess->studentscanmark = $formdata->studentscanmark; $sess->studentscanmark = $formdata->studentscanmark;
$sess->studentpassword = $formdata->studentpassword; $sess->studentpassword = $formdata->studentpassword;
$sess->subnet = $formdata->subnet; if (!empty($formdata->usedefaultsubnet)) {
$sess->subnet = $this->subnet;
} else {
$sess->subnet = $formdata->subnet;
}
if (!empty($formdata->automark)) { if (!empty($formdata->automark)) {
$sess->automark = $formdata->automark; $sess->automark = $formdata->automark;
} }

5
lang/en/attendance.php

@ -372,10 +372,10 @@ $string['repeaton'] = 'Repeat on';
$string['invalidsessionendtime'] = 'The end time must be greater than start time'; $string['invalidsessionendtime'] = 'The end time must be greater than start time';
$string['deletedgroup'] = 'The group associated with this session has been deleted'; $string['deletedgroup'] = 'The group associated with this session has been deleted';
$string['extrarestrictions'] = 'Extra restrictions'; $string['extrarestrictions'] = 'Extra restrictions';
$string['requiresubnet'] = 'Students can only record own attendance from these computers.'; $string['requiresubnet'] = 'Require network address';
$string['subnetwrong'] = 'Attendance can only be recorded from certain locations, and this computer is not on the allowed list.'; $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['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'] = 'Default network address';
$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['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'] = 'Default attendance settings';
$string['defaultsettings_help'] = 'These settings define the defaults for all new attendances'; $string['defaultsettings_help'] = 'These settings define the defaults for all new attendances';
@ -399,3 +399,4 @@ $string['automarktask'] = 'Check for closed attendance sessions that require aut
$string['autorecorded'] = 'system auto recorded'; $string['autorecorded'] = 'system auto recorded';
$string['coursesummary'] = 'Course summary report'; $string['coursesummary'] = 'Course summary report';
$string['averageattendance'] = 'Average attendance'; $string['averageattendance'] = 'Average attendance';
$string['usedefaultsubnet'] = 'Use default';

16
locallib.php

@ -520,9 +520,10 @@ function attendance_exporttocsv($data, $filename) {
/** /**
* Get session data for form. * Get session data for form.
* @param stdClass $formdata moodleform - attendance form. * @param stdClass $formdata moodleform - attendance form.
* $param mod_attendance_structure $att - used to get attendance level subnet.
* @return array. * @return array.
*/ */
function attendance_construct_sessions_data_for_add($formdata) { function attendance_construct_sessions_data_for_add($formdata, mod_attendance_structure $att) {
global $CFG; global $CFG;
$sesstarttime = $formdata->sestime['starthour'] * HOURSECS + $formdata->sestime['startminute'] * MINSECS; $sesstarttime = $formdata->sestime['starthour'] * HOURSECS + $formdata->sestime['startminute'] * MINSECS;
@ -570,7 +571,11 @@ function attendance_construct_sessions_data_for_add($formdata) {
$sess->timemodified = $now; $sess->timemodified = $now;
if (isset($formdata->studentscanmark)) { // Students will be able to mark their own attendance. if (isset($formdata->studentscanmark)) { // Students will be able to mark their own attendance.
$sess->studentscanmark = 1; $sess->studentscanmark = 1;
$sess->subnet = $formdata->subnet; if (!empty($formdata->usedefaultsubnet)) {
$sess->subnet = $att->subnet;
} else {
$sess->subnet = $formdata->subnet;
}
$sess->automark = $formdata->automark; $sess->automark = $formdata->automark;
$sess->automarkcompleted = 0; $sess->automarkcompleted = 0;
if (!empty($formdata->randompassword)) { if (!empty($formdata->randompassword)) {
@ -616,7 +621,12 @@ function attendance_construct_sessions_data_for_add($formdata) {
} else { } else {
$sess->studentpassword = $formdata->studentpassword; $sess->studentpassword = $formdata->studentpassword;
} }
$sess->subnet = $formdata->subnet; if (!empty($formdata->usedefaultsubnet)) {
$sess->subnet = $att->subnet;
} else {
$sess->subnet = $formdata->subnet;
}
if (!empty($formdata->automark)) { if (!empty($formdata->automark)) {
$sess->automark = $formdata->automark; $sess->automark = $formdata->automark;
} }

2
sessions.php

@ -73,7 +73,7 @@ switch ($att->pageparams->action) {
} }
if ($formdata = $mform->get_data()) { if ($formdata = $mform->get_data()) {
$sessions = attendance_construct_sessions_data_for_add($formdata); $sessions = attendance_construct_sessions_data_for_add($formdata, $att);
$att->add_sessions($sessions); $att->add_sessions($sessions);
if (count($sessions) == 1) { if (count($sessions) == 1) {
$message = get_string('sessiongenerated', 'attendance'); $message = get_string('sessiongenerated', 'attendance');

22
update_form.php

@ -49,6 +49,7 @@ class mod_attendance_update_form extends moodleform {
if (!$sess = $DB->get_record('attendance_sessions', array('id' => $sessionid) )) { if (!$sess = $DB->get_record('attendance_sessions', array('id' => $sessionid) )) {
error('No such session in this course'); error('No such session in this course');
} }
$attendancesubnet = $DB->get_field('attendance', 'subnet', array('id' => $sess->attendanceid));
$defopts = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $modcontext); $defopts = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $modcontext);
$sess = file_prepare_standard_editor($sess, 'description', $defopts, $modcontext, 'mod_attendance', 'session', $sess->id); $sess = file_prepare_standard_editor($sess, 'description', $defopts, $modcontext, 'mod_attendance', 'session', $sess->id);
@ -70,6 +71,11 @@ class mod_attendance_update_form extends moodleform {
'subnet' => $sess->subnet, 'subnet' => $sess->subnet,
'automark' => $sess->automark, 'automark' => $sess->automark,
'automarkcompleted' => 0); 'automarkcompleted' => 0);
if ($sess->subnet == $attendancesubnet) {
$data['usedefaultsubnet'] = 1;
} else {
$data['usedefaultsubnet'] = 0;
}
$mform->addElement('header', 'general', get_string('changesession', 'attendance')); $mform->addElement('header', 'general', get_string('changesession', 'attendance'));
@ -115,11 +121,21 @@ class mod_attendance_update_form extends moodleform {
$mform->addHelpButton('studentpassword', 'passwordgrp', 'attendance'); $mform->addHelpButton('studentpassword', 'passwordgrp', 'attendance');
$mform->disabledif('studentpassword', 'studentscanmark', 'notchecked'); $mform->disabledif('studentpassword', 'studentscanmark', 'notchecked');
$mform->addElement('text', 'subnet', get_string('requiresubnet', 'attendance'));
$mgroup2 = array();
$mgroup2[] = & $mform->createElement('text', 'subnet', get_string('requiresubnet', 'attendance'));
$mform->setDefault('subnet', $this->_customdata['att']->subnet);
$mgroup2[] = & $mform->createElement('checkbox', 'usedefaultsubnet', get_string('usedefaultsubnet', 'attendance'));
$mform->setDefault('usedefaultsubnet', 1);
$mform->setType('subnet', PARAM_TEXT); $mform->setType('subnet', PARAM_TEXT);
$mform->addHelpButton('subnet', 'requiresubnet', 'attendance');
$mform->addGroup($mgroup2, 'subnetgrp', get_string('requiresubnet', 'attendance'), array(' '), false);
$mform->setAdvanced('subnetgrp');
$mform->addHelpButton('subnetgrp', 'requiresubnet', 'attendance');
$mform->disabledif('usedefaultsubnet', 'studentscanmark', 'notchecked');
$mform->disabledif('subnet', 'studentscanmark', 'notchecked'); $mform->disabledif('subnet', 'studentscanmark', 'notchecked');
$mform->setAdvanced('subnet'); $mform->disabledif('subnet', 'usedefaultsubnet', 'checked');
$mform->addElement('hidden', 'automarkcompleted', '0'); $mform->addElement('hidden', 'automarkcompleted', '0');
$mform->settype('automarkcompleted', PARAM_INT); $mform->settype('automarkcompleted', PARAM_INT);

Loading…
Cancel
Save