From b4ed81d27ceff2ba6a8585f1efca7e45272051fe Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Wed, 21 Jun 2017 11:49:53 +1200 Subject: [PATCH] Allow default subnet setting at activity level to be hidden. --- add_form.php | 7 ++++++- lang/en/attendance.php | 2 ++ mod_form.php | 15 ++++++++++----- settings.php | 4 ++++ 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/add_form.php b/add_form.php index 13819b2..fcc000f 100644 --- a/add_form.php +++ b/add_form.php @@ -168,7 +168,12 @@ class mod_attendance_add_form extends moodleform { } $mgroup2 = array(); $mgroup2[] = & $mform->createElement('text', 'subnet', get_string('requiresubnet', 'attendance')); - $mform->setDefault('subnet', $this->_customdata['att']->subnet); + if (empty(get_config('attendance', 'subnetactivitylevel'))) { + $mform->setDefault('subnet', get_config('attendance', 'subnet')); + } else { + $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); diff --git a/lang/en/attendance.php b/lang/en/attendance.php index 050c289..7669c46 100644 --- a/lang/en/attendance.php +++ b/lang/en/attendance.php @@ -367,6 +367,8 @@ $string['studentscanmarksessiontime_desc'] = 'If checked students can only recor $string['studentscanmarksessiontimeend'] = 'Session end (minutes)'; $string['studentscanmarksessiontimeend_desc'] = 'If the session does not have an end time, how many minutes should the session be available for students to record their attendance.'; $string['submitattendance'] = 'Submit attendance'; +$string['subnetactivitylevel'] = 'Allow subnet config at activity level'; +$string['subnetactivitylevel_desc'] = 'If enabled, teachers can override the default subnet at the activity level when creating an attendance. Otherwise the site default will be used when creating a session.'; $string['subnetwrong'] = 'Attendance can only be recorded from certain locations, and this computer is not on the allowed list.'; $string['summary'] = 'Summary'; $string['tablerenamefailed'] = 'Rename of old attforblock table to attendance failed'; diff --git a/mod_form.php b/mod_form.php index 64bb8f6..6d6b78d 100644 --- a/mod_form.php +++ b/mod_form.php @@ -59,12 +59,17 @@ class mod_attendance_mod_form extends moodleform_mod { $this->standard_coursemodule_elements(true); - $mform->addElement('header', 'security', get_string('extrarestrictions', 'attendance')); // IP address. - $mform->addElement('text', 'subnet', get_string('defaultsubnet', 'attendance'), array('size' => '164')); - $mform->setType('subnet', PARAM_TEXT); - $mform->addHelpButton('subnet', 'defaultsubnet', 'attendance'); - $mform->setDefault('subnet', $attendanceconfig->subnet); + if (get_config('attendance', 'subnetactivitylevel')) { + $mform->addElement('header', 'security', get_string('extrarestrictions', 'attendance')); + $mform->addElement('text', 'subnet', get_string('defaultsubnet', 'attendance'), array('size' => '164')); + $mform->setType('subnet', PARAM_TEXT); + $mform->addHelpButton('subnet', 'defaultsubnet', 'attendance'); + $mform->setDefault('subnet', $attendanceconfig->subnet); + } else { + $mform->addElement('hidden', 'subnet', ''); + $mform->setType('subnet', PARAM_TEXT); + } $this->add_action_buttons(); } diff --git a/settings.php b/settings.php index 41131fd..120a32b 100644 --- a/settings.php +++ b/settings.php @@ -57,6 +57,10 @@ if ($ADMIN->fulltree) { get_string('studentscanmarksessiontimeend', 'attendance'), get_string('studentscanmarksessiontimeend_desc', 'attendance'), '60', PARAM_INT)); + $settings->add(new admin_setting_configcheckbox('attendance/subnetactivitylevel', + get_string('subnetactivitylevel', 'attendance'), + get_string('subnetactivitylevel_desc', 'attendance'), 1)); + $options = array( ATT_VIEW_ALL => get_string('all', 'attendance'), ATT_VIEW_ALLPAST => get_string('allpast', 'attendance'),