Allow a password to be set when using student self marking.
authorDan Marsden <dan@danmarsden.com>
Fri, 28 Apr 2017 02:03:40 +0000 (14:03 +1200)
committerDan Marsden <dan@danmarsden.com>
Fri, 28 Apr 2017 02:55:51 +0000 (14:55 +1200)
add_form.php
attendance.php
backup/moodle2/backup_attendance_stepslib.php
classes/structure.php
db/install.xml
db/upgrade.php
lang/en/attendance.php
sessions.php
student_attendance_form.php
update_form.php
version.php

index e7bd185..342b221 100644 (file)
@@ -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);
index f702fbf..1bd0891 100644 (file)
@@ -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);
 
index a53760f..507eb2b 100644 (file)
@@ -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');
index 8821b49..8064f50 100644 (file)
@@ -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);
 
index 13d1b9e..99a6467 100644 (file)
@@ -37,6 +37,7 @@
         <FIELD NAME="description" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
         <FIELD NAME="descriptionformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
         <FIELD NAME="studentscanmark" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
+        <FIELD NAME="studentpassword" TYPE="char" LENGTH="50" NOTNULL="true" DEFAULT="" SEQUENCE="false"/>
         <FIELD NAME="statusset" TYPE="int" LENGTH="5" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Which set of statuses to use"/>
         <FIELD NAME="caleventid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
       </FIELDS>
index 38d7599..65b726a 100644 (file)
@@ -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;
 }
index a867618..7db55a0 100644 (file)
@@ -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';
index 1c3e221..e527c59 100644 (file)
@@ -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;
 
index 3e445ae..56b7986 100644 (file)
@@ -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) {
index 104c540..69a1af7 100644 (file)
@@ -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);
index ddf5991..0e8ca96 100644 (file)
@@ -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';