diff --git a/classes/output/mobile.php b/classes/output/mobile.php index e788d54..4412c48 100644 --- a/classes/output/mobile.php +++ b/classes/output/mobile.php @@ -47,8 +47,8 @@ class mobile { $cmid = $args->cmid; $courseid = $args->courseid; $takenstatus = empty($args->status) ? '' : $args->status; - $sessid = $args->sessid; - $groupid = empty($args->group) ? 0 : $args->group; // By default, group 0. + $sessid = empty($args->sessid) ? '' : $args->sessid; + $password = empty($args->studentpass) ? '' : $args->studentpass; // Capabilities check. $cm = get_coursemodule_from_id('attendance', $cmid); @@ -123,11 +123,13 @@ class mobile { if (!$isteacher) { if (!empty($sess->subnet) && !address_in_subnet(getremoteaddr(), $sess->subnet)) { + $data['showmessage'] = true; $data['messages'][]['string'] = 'subnetwrong'; // Lang string to show as a message. $html['sessid'] = null; // Unset sessid as we cannot record session on this ip. } else if ($sess->autoassignstatus && empty($sess->studentpassword)) { $statusid = attendance_session_get_highest_status($att, $sess); if (empty($statusid)) { + $data['showmessage'] = true; $data['messages'][]['string'] = 'attendance_no_status'; } $take = new \stdClass(); @@ -139,32 +141,44 @@ class mobile { $html['currentstatus'] = $userdata->statuses[$statusid]->description; $html['sessid'] = null; // Unset sessid as we have recorded session. } - } else if (!empty($takenstatus)) { - $statuses = $att->get_statuses(); - // Check if user has access to all statuses. - foreach ($statuses as $status) { - if ($status->studentavailability === '0') { - unset($statuses[$status->id]); - continue; + } else if ($sess->id == $sessid) { + if (!empty($sess->studentpassword) && $password != $sess->studentpassword) { + // Password incorrect. + $data['showmessage'] = true; + $data['messages'][]['string'] = 'incorrectpasswordshort'; + } else { + $statuses = $att->get_statuses(); + // Check if user has access to all statuses. + foreach ($statuses as $status) { + if ($status->studentavailability === '0') { + unset($statuses[$status->id]); + continue; + } + if (!empty($status->studentavailability) && + time() > $sess->sessdate + ($status->studentavailability * 60)) { + unset($statuses[$status->id]); + continue; + } } - if (!empty($status->studentavailability) && - time() > $sess->sessdate + ($status->studentavailability * 60)) { - unset($statuses[$status->id]); - continue; + if ($sess->autoassignstatus) { + // If this is an auto-assign, get the highest status available. + $takenstatus = attendance_session_get_highest_status($att, $sess); } - } - if (empty($statuses[$takenstatus])) { - // This status has probably expired and is not available - they need to choose a new one. - $data['messages'][]['string'] = 'invalidstatus'; - } else { - $take = new \stdClass(); - $take->status = $takenstatus; - $take->sessid = $sess->id; - $success = $att->take_from_student($take); - - if ($success) { - $html['currentstatus'] = $userdata->statuses[$takenstatus]->description; - $html['sessid'] = null; // Unset sessid as we have recorded session. + + if (empty($statuses[$takenstatus])) { + // This status has probably expired and is not available - they need to choose a new one. + $data['showmessage'] = true; + $data['messages'][]['string'] = 'invalidstatus'; + } else { + $take = new \stdClass(); + $take->status = $takenstatus; + $take->sessid = $sess->id; + $success = $att->take_from_student($take); + + if ($success) { + $html['currentstatus'] = $userdata->statuses[$takenstatus]->description; + $html['sessid'] = null; // Unset sessid as we have recorded session. + } } } } @@ -231,6 +245,7 @@ class mobile { $data['messages'] = array(); $data['showmessage'] = false; $data['showstatuses'] = true; + $data['showpassword'] = false; $data['statuses'] = array(); $data['disabledduetotime'] = false; @@ -266,6 +281,12 @@ class mobile { if (empty($data['statuses'])) { $data['messages'][]['string'] = 'attendance_no_status'; $data['showstatuses'] = false; // Hide all statuses. + } else if (!empty($attforsession->studentpassword)) { + $data['showpassword'] = true; + if ($attforsession->autoassignstatus) { + // If this is an auto status - don't show the statuses, but show the form. + $data['statuses'] = array(); + } } } if (!empty($data['messages'])) { diff --git a/db/mobile.php b/db/mobile.php index 22c6815..9fb7ae4 100644 --- a/db/mobile.php +++ b/db/mobile.php @@ -56,7 +56,9 @@ $addons = [ ['invalidstatus', 'attendance'], ['preventsharederror', 'attendance'], ['closed', 'attendance'], - ['subnetwrong', 'attendance'] + ['subnetwrong', 'attendance'], + ['enterpassword', 'attendance'], + ['incorrectpasswordshort', 'attendance'] ] ] ]; \ No newline at end of file diff --git a/lang/en/attendance.php b/lang/en/attendance.php index cdd2bad..e448a89 100644 --- a/lang/en/attendance.php +++ b/lang/en/attendance.php @@ -243,6 +243,7 @@ $string['includenottaken'] = 'Include not taken sessions'; $string['includeqrcode'] = 'Include QR code'; $string['includeremarks'] = 'Include remarks'; $string['incorrectpassword'] = 'You have entered an incorrect password and your attendance has not been recorded, please enter the correct password.'; +$string['incorrectpasswordshort'] = 'Incorrect password, attendance not recorded.'; $string['indetail'] = 'In detail...'; $string['invalidaction'] = 'You must select an action'; $string['invalidemails'] = 'You must specify addresses of existing user accounts, could not find: {$a}'; @@ -324,6 +325,7 @@ $string['oversessionstaken_help'] = 'Shows statistics for sessions where attenda '; $string['participant'] = 'Participant'; $string['password'] = 'Password'; +$string['enterpassword'] = 'Enter password'; $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['passwordrequired'] = 'You must enter the session password before you can submit your attendance'; diff --git a/templates/mobile_user_form.mustache b/templates/mobile_user_form.mustache index 86f6ee5..7268ee9 100644 --- a/templates/mobile_user_form.mustache +++ b/templates/mobile_user_form.mustache @@ -51,6 +51,14 @@ <%/messages%> <%/showmessage%> + <%#showpassword%> + + + {{ 'plugin.mod_attendance.enterpassword' | translate }}: + + + + <%/showpassword%> <%#showstatuses%> <%#statuses%> @@ -60,7 +68,7 @@ <%/statuses%> - <%/showstatuses%>