From 430e51bb20a3f8e5f62f925de9ab98d6a75a0529 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Fri, 2 Feb 2018 10:09:50 +1300 Subject: [PATCH] Fix #292 studentpassword undefined warning also allow absenteereport setting to be updated. --- classes/structure.php | 3 +++ locallib.php | 13 ++++++++++--- update_form.php | 7 +++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/classes/structure.php b/classes/structure.php index 4d787b6..2c2f107 100644 --- a/classes/structure.php +++ b/classes/structure.php @@ -523,6 +523,9 @@ class mod_attendance_structure { $sess->subnet = ''; $sess->automark = 0; $sess->automarkcompleted = 0; + if (!empty(get_config('attendance', 'enablewarnings'))) { + $sess->absenteereport = empty($formdata->absenteereport) ? 0 : 1; + } if (!empty($formdata->autoassignstatus)) { $sess->autoassignstatus = $formdata->autoassignstatus; } diff --git a/locallib.php b/locallib.php index 811574f..935c775 100644 --- a/locallib.php +++ b/locallib.php @@ -537,6 +537,12 @@ function attendance_construct_sessions_data_for_add($formdata, mod_attendance_st $sesendtime = $formdata->sestime['endhour'] * HOURSECS + $formdata->sestime['endminute'] * MINSECS; $sessiondate = $formdata->sessiondate + $sesstarttime; $duration = $sesendtime - $sesstarttime; + if (empty(get_config('attendance', 'enablewarnings'))) { + $absenteereport = get_config('attendance', 'absenteereport_default'); + } else { + $absenteereport = empty($formdata->absenteereport) ? 0 : 1; + } + $now = time(); if (empty(get_config('attendance', 'studentscanmark'))) { @@ -576,6 +582,8 @@ function attendance_construct_sessions_data_for_add($formdata, mod_attendance_st $sess->description = $formdata->sdescription['text']; $sess->descriptionformat = $formdata->sdescription['format']; $sess->timemodified = $now; + $sess->absenteereport = $absenteereport; + $sess->studentpassword = ''; if (isset($formdata->studentscanmark)) { // Students will be able to mark their own attendance. $sess->studentscanmark = 1; if (!empty($formdata->usedefaultsubnet)) { @@ -590,11 +598,10 @@ function attendance_construct_sessions_data_for_add($formdata, mod_attendance_st $sess->automarkcompleted = 0; if (!empty($formdata->randompassword)) { $sess->studentpassword = attendance_random_string(); - } else { + } else if (!empty($formdata->studentpassword)) { $sess->studentpassword = $formdata->studentpassword; } } else { - $sess->studentpassword = ''; $sess->subnet = ''; $sess->automark = 0; $sess->automarkcompleted = 0; @@ -623,7 +630,7 @@ function attendance_construct_sessions_data_for_add($formdata, mod_attendance_st $sess->studentpassword = ''; $sess->automark = 0; $sess->automarkcompleted = 0; - $sess->absenteereport = 1; + $sess->absenteereport = $absenteereport; if (isset($formdata->studentscanmark) && !empty($formdata->studentscanmark)) { // Students will be able to mark their own attendance. diff --git a/update_form.php b/update_form.php index 3e2ced0..2f9d538 100644 --- a/update_form.php +++ b/update_form.php @@ -71,6 +71,7 @@ class mod_attendance_update_form extends moodleform { 'autoassignstatus' => $sess->autoassignstatus, 'subnet' => $sess->subnet, 'automark' => $sess->automark, + 'absenteereport' => $sess->absenteereport, 'automarkcompleted' => 0); if ($sess->subnet == $attendancesubnet) { $data['usedefaultsubnet'] = 1; @@ -104,6 +105,12 @@ class mod_attendance_update_form extends moodleform { array('rows' => 1, 'columns' => 80), $defopts); $mform->setType('sdescription', PARAM_RAW); + // If warnings allow selector for reporting. + if (!empty(get_config('attendance', 'enablewarnings'))) { + $mform->addElement('checkbox', 'absenteereport', '', get_string('includeabsentee', 'attendance')); + $mform->addHelpButton('absenteereport', 'includeabsentee', 'attendance'); + } + // Students can mark own attendance. if (!empty(get_config('attendance', 'studentscanmark'))) { $mform->addElement('header', 'headerstudentmarking', get_string('studentmarking', 'attendance'), true);