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 93b08d2..d7953b8 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 804671f..d00522f 100644
--- a/db/upgrade.php
+++ b/db/upgrade.php
@@ -233,5 +233,17 @@ function xmldb_attendance_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2016121305, 'attendance');
}
+ if ($oldversion < 2016121306) {
+ $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, 2016121306, '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 dd0bd57..6f0f810 100644
--- a/version.php
+++ b/version.php
@@ -23,9 +23,9 @@
*/
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 2016121305;
+$plugin->version = 2016121306;
$plugin->requires = 2016111800;
-$plugin->release = '3.2.5';
+$plugin->release = '3.2.6';
$plugin->maturity = MATURITY_STABLE;
$plugin->cron = 0;
$plugin->component = 'mod_attendance';