From b665424bf9484b05b071a97c9e84e588bd5d2994 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Fri, 28 Apr 2017 16:07:11 +1200 Subject: [PATCH] allow random password to be used when creating sessions. --- add_form.php | 11 +++++++++-- lang/en/attendance.php | 4 +++- sessions.php | 12 ++++++++++-- update_form.php | 2 +- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/add_form.php b/add_form.php index 342b221..2a52de3 100644 --- a/add_form.php +++ b/add_form.php @@ -123,11 +123,18 @@ 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'); + $mgroup = array(); + + $mgroup[] = & $mform->createElement('text', 'studentpassword', get_string('studentpassword', 'attendance')); + $mgroup[] = & $mform->createElement('checkbox', 'randompassword', '', get_string('randompassword', 'attendance')); + $mform->addGroup($mgroup, 'passwordgrp', get_string('passwordgrp', 'attendance'), array(' '), false); - $mform->addElement('text', 'studentpassword', get_string('studentpassword', 'attendance')); $mform->setType('studentpassword', PARAM_TEXT); - $mform->addHelpButton('studentpassword', 'studentpassword', 'attendance'); $mform->disabledif('studentpassword', 'studentscanmark', 'notchecked'); + + $mform->addHelpButton('passwordgrp', 'passwordgrp', 'attendance'); + $mform->disabledif('randompassword', 'studentscanmark', 'notchecked'); + $mform->disabledif('studentpassword', 'randompassword', 'checked'); } else { $mform->addElement('hidden', 'studentscanmark', '0'); $mform->settype('studentscanmark', PARAM_INT); diff --git a/lang/en/attendance.php b/lang/en/attendance.php index 7db55a0..997c03a 100644 --- a/lang/en/attendance.php +++ b/lang/en/attendance.php @@ -185,6 +185,8 @@ $string['percentagesessionscompleted'] = 'Percentage over taken sessions'; $string['percentageallsessions'] = 'Percentage over all sessions'; $string['pluginname'] = 'Attendance'; $string['pluginadministration'] = 'Attendance administration'; +$string['passwordgrp'] = 'Student password'; +$string['passwordgrp_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['remark'] = 'Remark for: {$a}'; $string['remarks'] = 'Remarks'; $string['report'] = 'Report'; @@ -258,6 +260,7 @@ $string['sessiontypeshort'] = 'Type'; $string['sessionupdated'] = 'Session successfully updated'; $string['setallstatuses'] = 'Set status for all users'; $string['setallstatusesto'] = 'Set status for all users to «{$a}»'; +$string['randompassword'] = 'Random password'; $string['settings'] = 'Settings'; $string['showdefaults'] = 'Show defaults'; $string['showduration'] = 'Show duration'; @@ -279,7 +282,6 @@ $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 40b9e9e..f805106 100644 --- a/sessions.php +++ b/sessions.php @@ -272,7 +272,11 @@ 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; + if (!empty($formdata->randompassword)) { + $sess->studentpassword = random_string(5); + } else { + $sess->studentpassword = $formdata->studentpassword; + } } else { $sess->studentpassword = ''; } @@ -298,7 +302,11 @@ function construct_sessions_data_for_add($formdata) { $sess->studentpassword = ''; if (isset($formdata->studentscanmark) && !empty($formdata->studentscanmark)) { // Students will be able to mark their own attendance. $sess->studentscanmark = 1; - $sess->studentpassword = $formdata->studentpassword; + if (!empty($formdata->randompassword)) { + $sess->studentpassword = random_string(5); + } else { + $sess->studentpassword = $formdata->studentpassword; + } } $sess->statusset = $formdata->statusset; diff --git a/update_form.php b/update_form.php index 69a1af7..24c752a 100644 --- a/update_form.php +++ b/update_form.php @@ -97,7 +97,7 @@ class mod_attendance_update_form extends moodleform { $mform->addElement('text', 'studentpassword', get_string('studentpassword', 'attendance')); $mform->setType('studentpassword', PARAM_TEXT); - $mform->addHelpButton('studentpassword', 'studentpassword', 'attendance'); + $mform->addHelpButton('studentpassword', 'passwordgrp', 'attendance'); $mform->disabledif('studentpassword', 'studentscanmark', 'notchecked'); } else { $mform->addElement('hidden', 'studentscanmark', '0');