From 1a40f5a199d7f4e3ce2504f9123882db6647ecba Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Fri, 28 Apr 2017 14:03:40 +1200 Subject: [PATCH] Allow a password to be set when using student self marking. --- add_form.php | 5 +++++ attendance.php | 8 ++++++++ backup/moodle2/backup_attendance_stepslib.php | 3 ++- classes/structure.php | 10 ++++++++++ db/install.xml | 1 + db/upgrade.php | 12 ++++++++++++ lang/en/attendance.php | 5 +++++ sessions.php | 6 ++++++ student_attendance_form.php | 6 +++++- update_form.php | 18 +++++++++++++++++- version.php | 4 ++-- 11 files changed, 73 insertions(+), 5 deletions(-) diff --git a/add_form.php b/add_form.php index e7bd185..342b221 100644 --- a/add_form.php +++ b/add_form.php @@ -123,6 +123,11 @@ class mod_attendance_add_form extends moodleform { if (!empty(get_config('attendance', 'studentscanmark'))) { $mform->addElement('checkbox', 'studentscanmark', '', get_string('studentscanmark', 'attendance')); $mform->addHelpButton('studentscanmark', 'studentscanmark', 'attendance'); + + $mform->addElement('text', 'studentpassword', get_string('studentpassword', 'attendance')); + $mform->setType('studentpassword', PARAM_TEXT); + $mform->addHelpButton('studentpassword', 'studentpassword', 'attendance'); + $mform->disabledif('studentpassword', 'studentscanmark', 'notchecked'); } else { $mform->addElement('hidden', 'studentscanmark', '0'); $mform->settype('studentscanmark', PARAM_INT); diff --git a/attendance.php b/attendance.php index f702fbf..1bd0891 100644 --- a/attendance.php +++ b/attendance.php @@ -67,6 +67,14 @@ if ($mform->is_cancelled()) { $url = new moodle_url('/mod/attendance/view.php', array('id' => $cm->id)); redirect($url); } else if ($fromform = $mform->get_data()) { + // check if password required and if set correctly. + if (!empty($attforsession->studentpassword) && + $attforsession->studentpassword !== $fromform->studentpassword) { + + $url = new moodle_url('/mod/attendance/attendance.php', array('sessid' => $id, 'sesskey' => sesskey())); + redirect($url, get_string('incorrectpassword', 'mod_attendance')); + } + if (!empty($fromform->status)) { $success = $att->take_from_student($fromform); diff --git a/backup/moodle2/backup_attendance_stepslib.php b/backup/moodle2/backup_attendance_stepslib.php index a53760f..507eb2b 100644 --- a/backup/moodle2/backup_attendance_stepslib.php +++ b/backup/moodle2/backup_attendance_stepslib.php @@ -53,7 +53,8 @@ class backup_attendance_activity_structure_step extends backup_activity_structur $sessions = new backup_nested_element('sessions'); $session = new backup_nested_element('session', array('id'), array( 'groupid', 'sessdate', 'duration', 'lasttaken', 'lasttakenby', - 'timemodified', 'description', 'descriptionformat', 'studentscanmark', 'statusset', 'caleventid')); + 'timemodified', 'description', 'descriptionformat', 'studentscanmark', 'studentpassword', + 'statusset', 'caleventid')); // XML nodes declaration - user data. $logs = new backup_nested_element('logs'); diff --git a/classes/structure.php b/classes/structure.php index 8821b49..8064f50 100644 --- a/classes/structure.php +++ b/classes/structure.php @@ -395,6 +395,7 @@ class mod_attendance_structure { $sess->lasttaken = 0; $sess->lasttakenby = 0; $sess->studentscanmark = 0; + $event->add_record_snapshot('attendance_sessions', $sess); $event->trigger(); } @@ -419,6 +420,15 @@ class mod_attendance_structure { $sess->description = $description; $sess->descriptionformat = $formdata->sdescription['format']; + $sess->studentscanmark = 0; + $sess->studentpassword = ''; + + if (!empty(get_config('attendance', 'studentscanmark')) && + !empty($formdata->studentscanmark)) { + $sess->studentscanmark = $formdata->studentscanmark; + $sess->studentpassword = $formdata->studentpassword; + } + $sess->timemodified = time(); $DB->update_record('attendance_sessions', $sess); diff --git a/db/install.xml b/db/install.xml index 13d1b9e..99a6467 100644 --- a/db/install.xml +++ b/db/install.xml @@ -37,6 +37,7 @@ + diff --git a/db/upgrade.php b/db/upgrade.php index 38d7599..65b726a 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -233,5 +233,17 @@ function xmldb_attendance_upgrade($oldversion=0) { upgrade_mod_savepoint(true, 2017020700, 'attendance'); } + if ($oldversion < 2017042800) { + $table = new xmldb_table('attendance_sessions'); + + $field = new xmldb_field('studentpassword'); + $field->set_attributes(XMLDB_TYPE_CHAR, '50', null, null, null, '', 'studentscanmark'); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + upgrade_mod_savepoint(true, 2017042800, 'attendance'); + } + return $result; } diff --git a/lang/en/attendance.php b/lang/en/attendance.php index a867618..7db55a0 100644 --- a/lang/en/attendance.php +++ b/lang/en/attendance.php @@ -133,6 +133,7 @@ $string['identifyby'] = 'Identify student by'; $string['includeall'] = 'Select all sessions'; $string['includenottaken'] = 'Include not taken sessions'; $string['includeremarks'] = 'Include remarks'; +$string['incorrectpassword'] = 'You have entered an incorrect password'; $string['indetail'] = 'In detail...'; $string['invalidsessionenddate'] = 'This date can not be earlier than the session date'; $string['invalidaction'] = 'You must select an action'; @@ -177,6 +178,8 @@ $string['noupgradefromthisversion'] = 'The Attendance module cannot upgrade from $string['olddate'] = 'Old date'; $string['onlyselectedusers'] = 'Export specific users'; $string['participant'] = 'Participant'; +$string['password'] = 'Password'; +$string['passwordrequired'] = 'You must enter the session password before you can submit your attendance'; $string['percentage'] = 'Percentage'; $string['percentagesessionscompleted'] = 'Percentage over taken sessions'; $string['percentageallsessions'] = 'Percentage over all sessions'; @@ -275,6 +278,8 @@ $string['strftimeh'] = '%l%P'; $string['strftimehm'] = '%l:%M%P'; $string['strftimeshortdate'] = '%d.%m.%Y'; $string['studentid'] = 'Student ID'; +$string['studentpassword'] = 'Student password'; +$string['studentpassword_help'] = 'If set students will be required to enter this password before they can set their own attendance status for the session. If empty, no password is required.'; $string['summary'] = 'Summary'; $string['takeattendance'] = 'Take attendance'; $string['takensessions'] = 'Taken sessions'; diff --git a/sessions.php b/sessions.php index 1c3e221..e527c59 100644 --- a/sessions.php +++ b/sessions.php @@ -272,6 +272,9 @@ function 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->studentpassword = $formdata->studentpassword; + } else { + $sess->studentpassword = ''; } $sess->statusset = $formdata->statusset; @@ -293,6 +296,9 @@ function 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->studentpassword = $formdata->studentpassword; + } else { + $sess->studentpassword = ''; } $sess->statusset = $formdata->statusset; diff --git a/student_attendance_form.php b/student_attendance_form.php index 3e445ae..56b7986 100644 --- a/student_attendance_form.php +++ b/student_attendance_form.php @@ -46,7 +46,11 @@ class mod_attendance_student_attendance_form extends moodleform { if (!empty($attforsession->description)) { $mform->addElement('html', $attforsession->description); } - + if (!empty($attforsession->studentpassword)) { + $mform->addElement('text', 'studentpassword', get_string('password', 'attendance')); + $mform->setType('studentpassword', PARAM_TEXT); + $mform->addRule('studentpassword', get_string('passwordrequired', 'attendance'), 'required'); + } // Create radio buttons for setting the attendance status. $radioarray = array(); foreach ($statuses as $status) { diff --git a/update_form.php b/update_form.php index 104c540..69a1af7 100644 --- a/update_form.php +++ b/update_form.php @@ -64,7 +64,9 @@ class mod_attendance_update_form extends moodleform { $data = array('sessiondate' => $sess->sessdate, 'sestime' => array('starthour' => $starthour, 'startminute' => $startminute, 'endhour' => $endhour, 'endminute' => $endminute), - 'sdescription' => $sess->description_editor); + 'sdescription' => $sess->description_editor, + 'studentscanmark' => $sess->studentscanmark, + 'studentpassword' => $sess->studentpassword); $mform->addElement('header', 'general', get_string('changesession', 'attendance')); @@ -88,6 +90,20 @@ class mod_attendance_update_form extends moodleform { attendance_get_setname($this->_customdata['att']->id, $sess->statusset)); } + // Students can mark own attendance. + if (!empty(get_config('attendance', 'studentscanmark'))) { + $mform->addElement('checkbox', 'studentscanmark', '', get_string('studentscanmark', 'attendance')); + $mform->addHelpButton('studentscanmark', 'studentscanmark', 'attendance'); + + $mform->addElement('text', 'studentpassword', get_string('studentpassword', 'attendance')); + $mform->setType('studentpassword', PARAM_TEXT); + $mform->addHelpButton('studentpassword', 'studentpassword', 'attendance'); + $mform->disabledif('studentpassword', 'studentscanmark', 'notchecked'); + } else { + $mform->addElement('hidden', 'studentscanmark', '0'); + $mform->settype('studentscanmark', PARAM_INT); + } + $mform->addElement('editor', 'sdescription', get_string('description', 'attendance'), array('rows' => 1, 'columns' => 80), $defopts); $mform->setType('sdescription', PARAM_RAW); diff --git a/version.php b/version.php index ddf5991..0e8ca96 100644 --- a/version.php +++ b/version.php @@ -23,9 +23,9 @@ */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2017020700; +$plugin->version = 2017042800; $plugin->requires = 2017011900; -$plugin->release = '3.3.2'; +$plugin->release = '3.3.3'; $plugin->maturity = MATURITY_STABLE; $plugin->cron = 0; $plugin->component = 'mod_attendance';