diff --git a/add_form.php b/add_form.php index 439408f..67c3797 100644 --- a/add_form.php +++ b/add_form.php @@ -125,10 +125,16 @@ class mod_attendance_add_form extends moodleform { array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $modcontext)); $mform->setType('sdescription', PARAM_RAW); - $mform->addElement('checkbox', 'calendarevent', '', get_string('calendarevent', 'attendance')); - $mform->addHelpButton('calendarevent', 'calendarevent', 'attendance'); - // XXX - this should be modified to use a different config setting if we keep enablecalendar's current meaning - $mform->setDefault('calendarevent', get_config('attendance', 'enablecalendar')); + if (!empty($pluginconfig->enablecalendar)) { + $mform->addElement('checkbox', 'calendarevent', '', get_string('calendarevent', 'attendance')); + $mform->addHelpButton('calendarevent', 'calendarevent', 'attendance'); + if (isset($pluginconfig->calendarevent_default)) { + $mform->setDefault('calendarevent', $pluginconfig->calendarevent_default); + } + } else { + $mform->addElement('hidden', 'calendarevent', 0); + $mform->setType('calendarevent', PARAM_INT); + } // If warnings allow selector for reporting. if (!empty(get_config('attendance', 'enablewarnings'))) { diff --git a/db/upgrade.php b/db/upgrade.php index be18683..fc4588e 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -517,6 +517,10 @@ function xmldb_attendance_upgrade($oldversion=0) { XMLDB_NOTNULL, null, '1', 'caleventid'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); + if (empty(get_config('attendance', 'enablecalendar'))) { + // Calendar disabled on this site, set calendarevent for existing records to 0; + $DB->execute("UPDATE {attendance_sessions} set calendarevent = 0"); + } } upgrade_mod_savepoint(true, 2018051402, 'attendance'); } diff --git a/settings.php b/settings.php index 3920888..6d29f34 100644 --- a/settings.php +++ b/settings.php @@ -105,6 +105,9 @@ if ($ADMIN->fulltree) { $description = new lang_string('defaultsessionsettings_help', 'mod_attendance'); $settings->add(new admin_setting_heading('defaultsessionsettings', $name, $description)); + $settings->add(new admin_setting_configcheckbox('attendance/calendarevent_default', + get_string('calendarevent', 'attendance'), '', 1)); + $settings->add(new admin_setting_configcheckbox('attendance/absenteereport_default', get_string('includeabsentee', 'attendance'), '', 1)); diff --git a/update_form.php b/update_form.php index 3dcbc64..55d93eb 100644 --- a/update_form.php +++ b/update_form.php @@ -113,10 +113,13 @@ class mod_attendance_update_form extends moodleform { array('rows' => 1, 'columns' => 80), $defopts); $mform->setType('sdescription', PARAM_RAW); - $mform->addElement('checkbox', 'calendarevent', '', get_string('calendarevent', 'attendance')); - $mform->addHelpButton('calendarevent', 'calendarevent', 'attendance'); - // XXX - this should be modified to use a different config setting if we keep enablecalendar's current meaning - // $mform->setDefault('calendarevent', get_config('attendance', 'enablecalendar')); + if (!empty(get_config('attendance', 'enablecalendar'))) { + $mform->addElement('checkbox', 'calendarevent', '', get_string('calendarevent', 'attendance')); + $mform->addHelpButton('calendarevent', 'calendarevent', 'attendance'); + } else { + $mform->addElement('hidden', 'calendarevent', 0); + $mform->setType('calendarevent', PARAM_INT); + } // If warnings allow selector for reporting. if (!empty(get_config('attendance', 'enablewarnings'))) {