Security advisory GHSA-mjgw-f2c4-f8qj: WebPA SQL Injection vulnerability
Package: webpa/webpa (composer), vulnerable version: v3.1.1, fixed in: 3.1.2
CWE: CWE-89
Files changed by the fix:
src/accounts/reset.php
src/admin/delete/index.php
src/admin/edit/index.php
src/admin/edit/module.php
src/admin/index.php
src/admin/load/index.php
src/admin/load/simple.php
src/admin/load/templates.php
src/admin/metrics/index.php
src/admin/metrics/report.php
src/admin/review/admin/index.php
src/admin/review/all.php
src/admin/review/index.php
src/admin/review/log.php
src/admin/review/module/index.php
src/admin/review/staff/index.php
src/admin/review/student/index.php
src/admin/search/index.php
src/contact/contact_send.php
src/contact/index.php
src/cookie.php
src/includes/classes/AlgorithmFactory.php
src/includes/classes/Assessment.php
src/includes/classes/Authenticator.php
src/includes/classes/DAO.php
src/includes/classes/DBAuthenticator.php
src/includes/classes/Email.php
src/includes/classes/EngCIS.php
src/includes/classes/Form.php
src/includes/classes/FormRenderer.php
src/includes/classes/Group.php
src/includes/classes/GroupCollection.php
src/includes/classes/GroupHandler.php
src/includes/classes/Module.php
src/includes/classes/NewAlgorithm.php
src/includes/classes/ResultHandler.php
src/includes/classes/SimpleIterator.php
src/includes/classes/SimpleObjectIterator.php
src/includes/classes/UI.php
src/includes/classes/User.php
src/includes/classes/WebPAAlgorithm.php
src/includes/classes/Wizard.php
src/includes/classes/XMLParser.php
src/includes/classes/algorithms/Algorithm.php
src/includes/classes/algorithms/PetsAlgorithm.php
src/includes/classes/algorithms/WebPAAlgorithm.php
src/includes/functions/AcademicYear.php
src/includes/functions/ArrayFunctions.php
src/includes/functions/Common.php
src/includes/functions/Form.php
src/includes/functions/StringFunctions.php
src/includes/functions/TimeDiff.php
src/includes/functions/XML.php
src/includes/inc_global.php
src/index.php
src/jobs/Email.php
src/keep_alive.php
src/lang/en/Generic.php
src/lang/en/tutors/Tutors.php
src/login.php
src/login_check.php
src/logout.php
src/module.php
src/students/assessments/assessment_feedback.php
src/students/assessments/index.php
src/students/assessments/take/already_submitted.php
src/students/assessments/take/finished.php
src/students/assessments/take/index.php
src/students/assessments/take/not_open.php
src/students/groups/index.php
src/students/index.php
src/tutors/assessments/clone/index.php
src/tutors/assessments/create/class_wizardstep_1.php
src/tutors/assessments/create/class_wizardstep_2.php
src/tutors/assessments/create/class_wizardstep_3.php
src/tutors/assessments/create/class_wizardstep_4.php
src/tutors/assessments/create/class_wizardstep_5.php
src/tutors/assessments/create/class_wizardstep_6.php
src/tutors/assessments/create/index.php
src/tutors/assessments/delete_marks.php
src/tutors/assessments/edit/change_assessment_collection.php
src/tutors/assessments/edit/change_assessment_form.php
src/tutors/assessments/edit/edit_assessment.php
src/tutors/assessments/email/AssessmentNotificationTrait.php
src/tutors/assessments/email/ClosingReminder.php
src/tutors/assessments/email/TriggerReminder.php
src/tutors/assessments/email/class_wizardstep_1.php
src/tutors/assessments/email/class_wizardstep_2.php
src/tutors/assessments/email/class_wizardstep_3.php
src/tutors/assessments/email/class_wizardstep_4.php
src/tutors/assessments/email/index.php
src/tutors/assessments/inc_list_closed.php
src/tutors/assessments/inc_list_marked.php
src/tutors/assessments/inc_list_open.php
src/tutors/assessments/inc_list_pending.php
src/tutors/assessments/index.php
src/tutors/assessments/marks/mark_assessment.php
src/tutors/assessments/marks/set_group_marks.php
src/tutors/assessments/reports/index.php
src/tutors/assessments/reports/report_demo.php
src/tutors/assessments/reports/report_marks_awarded_byquestion_anonymous.php
src/tutors/assessments/reports/report_marks_awarded_byquestion_named.php
src/tutors/assessments/reports/report_student_feedback_bygroup.php
src/tutors/assessments/reports/report_student_grades.php
src/tutors/assessments/reports/report_student_grades_bygroup.php
src/tutors/assessments/reports/report_student_grades_comments.php
src/tutors/assessments/reports/report_student_response_info.php
src/tutors/assessments/reports/report_uea.php
src/tutors/assessments/reports/report_uea_anonymous.php
src/tutors/assessments/reports/students_who_responded.php
src/tutors/assessments/students_who_responded.php
src/tutors/forms/clone/class_wizardstep_1.php
src/tutors/forms/clone/class_wizardstep_2.php
src/tutors/forms/clone/class_wizardstep_3.php
src/tutors/forms/clone/clone_example.php
src/tutors/forms/clone/index.php
src/tutors/forms/create/class_wizardstep_1.php
src/tutors/forms/create/class_wizardstep_2.php
src/tutors/forms/create/index.php
src/tutors/forms/edit/add_question/class_wizardstep_1.php
src/tutors/forms/edit/add_question/class_wizardstep_2.php
src/tutors/forms/edit/add_question/class_wizardstep_3.php
src/tutors/forms/edit/add_question/index.php
src/tutors/forms/edit/add_question/likert/class_wizardstep_1.php
src/tutors/forms/edit/add_question/likert/class_wizardstep_2.php
src/tutors/forms/edit/add_question/likert/class_wizardstep_3.php
src/tutors/forms/edit/add_question/split100/class_wizardstep_1.php
src/tutors/forms/edit/add_question/split100/class_wizardstep_2.php
src/tutors/forms/edit/edit_form.php
src/tutors/forms/edit/edit_question/class_wizardstep_1.php
src/tutors/forms/edit/edit_question/class_wizardstep_2.php
src/tutors/forms/edit/edit_question/class_wizardstep_3.php
src/tutors/forms/edit/edit_question/index.php
src/tutors/forms/edit/edit_question/likert/class_wizardstep_1.php
src/tutors/forms/edit/edit_question/likert/class_wizardstep_2.php
src/tutors/forms/edit/edit_question/likert/class_wizardstep_3.php
src/tutors/forms/edit/edit_question/split100/class_wizardstep_1.php
src/tutors/forms/edit/edit_question/split100/class_wizardstep_2.php
src/tutors/forms/edit/preview_form.php
src/tutors/forms/edit/question_action.php
src/tutors/forms/export/export_form.php
src/tutors/forms/import/import.php
src/tutors/forms/import/index.php
src/tutors/forms/import/xml_file.php
src/tutors/forms/index.php
src/tutors/groups/clone/class_wizardstep_1.php
src/tutors/groups/clone/class_wizardstep_2.php
src/tutors/groups/clone/class_wizardstep_3.php
src/tutors/groups/clone/index.php
src/tutors/groups/create/class_wizardstep_1.php
src/tutors/groups/create/class_wizardstep_2.php
src/tutors/groups/create/class_wizardstep_3.php
src/tutors/groups/create/class_wizardstep_4.php
src/tutors/groups/create/class_wizardstep_x.php
src/tutors/groups/create/index.php
src/tutors/groups/edit/edit_collection.php
src/tutors/groups/edit/edit_collection_groups.php
src/tutors/groups/edit/edit_collection_members.php
src/tutors/groups/edit/edit_group.php
src/tutors/groups/edit/index.php
src/tutors/groups/index.php
src/tutors/index.php

Fix diff:
diff --git a/.env.example b/.env.example
new file mode 100644
index 0000000..9c944c4
--- /dev/null
+++ b/.env.example
@@ -0,0 +1,26 @@
+APP_WWW=http://localhost
+DOC_ROOT=/var/www/webpa/
+DB_HOST=localhost
+DB_USER=root
+DB_PASS=password
+DB_NAME=webpa
+DB_PREFIX=pa2_
+CUSTOM_CSS_PATH=
+SESSION_NAME=WEBPA
+ACADEMIC_YEAR_START_MONTH=9
+HELP_EMAIL=someone@email.com
+NO_REPLY_EMAIL=no-reply@email.com
+LOGO_PATH=/images/logo.png
+LOGO_ALT_TEXT="Your institution name"
+LOGO_HEIGHT=25
+LOGO_WIDTH=102
+ALLOW_TEXT_INPUT=true
+ENABLE_USER_DELETE=true
+ENABLE_MODULE_DELETE=true
+SMTP_HOST=localhost
+SMTP_PORT=25
+EMAIL_ADDRESS=someone@email.com
+ENABLE_MOODLE_GRADEBOOK=false
+SEND_OPENING_REMINDER=false
+SEND_CLOSING_REMINDER=false
+MARK_TERMINOLOGY=Scores(s)
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index a8f3dcc..6c742e2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,5 @@ vendor/
 /composer.lock
 .idea/
 *.orig
+.env
+/src/mod/**
diff --git a/.php_cs.dist b/.php_cs.dist
new file mode 100644
index 0000000..99ab06d
--- /dev/null
+++ b/.php_cs.dist
@@ -0,0 +1,65 @@
+<?php
+
+$finder = PhpCsFixer\Finder::create()
+    ->exclude('mod')
+    ->in(__DIR__ . '/src');
+
+$config = new PhpCsFixer\Config();
+
+return $config
+    ->setRules([
+        '@PSR2' => true,
+        '@PHP74Migration' => true,
+        'array_syntax' => ['syntax' => 'short'],
+        'no_alias_language_construct_call' => true,
+        'no_mixed_echo_print' => true,
+        'no_multiline_whitespace_around_double_arrow' => true,
+        'no_trailing_comma_in_singleline_array' => true,
+        'no_whitespace_before_comma_in_array' => true,
+        'normalize_index_brace' => true,
+        'trailing_comma_in_multiline_array' => true,
+        'trim_array_spaces' => true,
+        'whitespace_after_comma_in_array' => true,
+        'lowercase_static_reference' => true,
+        'magic_constant_casing' => true,
+        'magic_method_casing' => true,
+        'native_function_casing' => true,
+        'native_function_type_declaration_casing' => true,
+        'cast_spaces' => true,
+        'lowercase_cast' => true,
+        'no_short_bool_cast' => true,
+        'no_unset_cast' => true,
+        'short_scalar_cast' => true,
+        'class_attributes_separation' => true,
+        'class_definition' => true,
+        'no_blank_lines_after_class_opening' => true,
+        'no_null_property_initialization' => true,
+        'protected_to_private' => true,
+        'self_static_accessor' => true,
+        'single_class_element_per_statement' => true,
+        'single_trait_insert_per_statement' => true,
+        'multiline_comment_opening_closing' => true,
+        'no_empty_comment' => true,
+        'single_line_comment_style' => true,
+        'include' => true,
+        'no_alternative_syntax' => true,
+        'no_superfluous_elseif' => true,
+        'no_trailing_comma_in_list_call' => true,
+        'no_unneeded_control_parentheses' => true,
+        'no_unneeded_curly_braces' => true,
+        'no_useless_else' => true,
+        'simplified_if_return' => true,
+        'switch_case_space' => true,
+        'switch_continue_to_break' => true,
+        'function_typehint_space' => true,
+        'method_argument_space' => true,
+        'nullable_type_declaration_for_default_null_value' => true,
+        'return_type_declaration' => true,
+        'fully_qualified_strict_types' => true,
+        'global_namespace_import' => true,
+        'no_leading_import_slash' => true,
+        'no_unused_imports' => true,
+        'ordered_imports' => true,
+        'single_quote' => true,
+    ])
+    ->setFinder($finder);
diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist
new file mode 100644
index 0000000..d5fb420
--- /dev/null
+++ b/.phpcs.xml.dist
@@ -0,0 +1,42 @@
+<?xml version="1.0"?>
+<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer" xsi:noNamespaceSchemaLocation="phpcs.xsd">
+    <description>WebPA Coding Standards</description>
+
+    <file>src</file>
+
+    <exclude-pattern>*/src/*\.(inc|css|js)$</exclude-pattern>
+
+    <arg name="basepath" value="."/>
+    <arg name="colors"/>
+    <arg name="parallel" value="75"/>
+    <arg value="np"/>
+
+    <!-- Don't hide tokenizer exceptions -->
+    <rule ref="Internal.Tokenizer.Exception">
+        <type>error</type>
+    </rule>
+
+    <!-- Include the whole PEAR standard -->
+    <rule ref="PSR2" />
+
+    <!-- Check var names, but we don't want leading underscores for private vars -->
+    <rule ref="Squiz.NamingConventions.ValidVariableName"/>
+    <rule ref="Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore">
+        <severity>0</severity>
+    </rule>
+
+    <!-- Private methods MUST not be prefixed with an underscore -->
+    <rule ref="PSR2.Methods.MethodDeclaration.Underscore">
+        <type>error</type>
+    </rule>
+
+    <!-- Private properties MUST not be prefixed with an underscore -->
+    <rule ref="PSR2.Classes.PropertyDeclaration.Underscore">
+        <type>error</type>
+    </rule>
+
+    <!-- Side effects should be classed as an error because these break PHPStan checks -->
+    <rule ref="PSR1.Files.SideEffects">
+        <type>error</type>
+    </rule>
+</ruleset>
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0713437..e87cab7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,7 +4,16 @@ All notable changes to this project will be documented in this file.
 The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
 and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
 
-## [Unreleased]
+## [3.1.2] - 2020-04-22
+### Changed
+- Emails are now triggered via a single script, `jobs/Email.php` instead of calling`tutors/asessments/email/ClosingReminder.php` and `tutors/assessments/email/TriggerReminder.php` directly. 
+
+### Removed
+- Removed LDAP functionality and options as the implementation did not work.
+
+### Security
+- Fixed a large amount of SQL injection attacks
+- Change password hashing to use the native password_hash() function in PHP instead of MD5 hashing which is insecure
 
 ## [3.1.1] - 2020-10-02
 ### Fixed
@@ -18,6 +27,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
 ### Fixed
 - Change default authenticator to be database instead of SAML (PR #64)
 
+## [Unreleased]
+
 ## [3.0.7] - 2020-01-20
 ### Fixed
 - Remove a blank line at the top of a PHP class that was causing a fatal error
@@ -65,8 +76,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
 
 ## [1.1.0.1] - 2008-07-19
 
-[Unreleased]: https://github.com/WebPA/WebPA/compare/v3.1.1...HEAD
+[Unreleased]: https://github.com/WebPA/WebPA/compare/v3.1.2...HEAD
 
+[3.1.2]: https://github.com/WebPA/WebPA/compare/v3.1.1...v3.1.2
 [3.1.1]: https://github.com/WebPA/WebPA/compare/v3.1.0...v3.1.1
 [3.1.0]: https://github.com/WebPA/WebPA/compare/v3.0.7...v3.1.0
 [3.0.7]: https://github.com/WebPA/WebPA/compare/v3.0.6...v3.0.7
diff --git a/README.md b/README.md
index 1dfe86b..87e9284 100644
--- a/README.md
+++ b/README.md
@@ -9,9 +9,8 @@ student with an individual grade. The individual grade reflects the students con
 
 The following versions of PHP are supported for the latest version of WebPA:
 
-* PHP 7.2
-* PHP 7.3
 * PHP 7.4
+* PHP 8.0
 
 Your PHP instance must also have the following extensions enabled:
 
@@ -32,30 +31,57 @@ composer create-project --prefer-dist --no-dev webpa/webpa webpa
 
 Alternatively you can download the latest release from this repository's [release page](https://github.com/WebPA/WebPA/releases).
 
-### Setup
+### Configuration
 
-Edit the includes/inc\_global.php file in the includes directory to configure the application; in particular:
+WebPA has a number of configuration options allowing you to set your database credentials, SMTP mail host details and 
+various other options.
 
-- APP\_\_WWW: URL to the instance of WebPA (without a closing "/");
-- DOC\_\_ROOT: directory path to the WebPA files (with a closing "/" or "\\");
-- database settings:
-	- APP\_\_DB\_HOST: host name
-	- APP\_\_DB\_USERNAME: username
-	- APP\_\_DB\_PASSWORD: password
-	- APP\_\_DB\_DATABASE: database name
-	- APP\_\_DB\_TABLE\_PREFIX: table prefix (default is `pa2_` which means that the new version can share the same database as the old version if required)
-- Configure the LDAP settings if you wish to authenticate via LDAP.
+The application comes bundled with a `.env.example` file which lists all of the configuation key-value pairs you can
+set. 
+
+For speedy development, you can copy this `.env.example` file to a file called `.env` and change the values to suit your
+environment. The path of this file can be set in the `includes/inc_global.php` file.
+
+For production environments, please *avoid* using the `.env` file as storing sensitive credentials in a file could be a 
+security risk. Instead you should set these key-pairs as environment variables. In Apache, you can set these in your 
+`.htaccess` file as follows:
+
+```
+SetEnv DB_HOST localhost
+```
+
+At a minimum, you should set the following environmental variables to let WebPA function:
+
+* APP_WWW - URL to your instance of WebPA (set without a closing '/')
+* DOC_ROOT - Directory path to the WebPA files (set with a closing '/')
+* DB_HOST - Database host
+* DB_USER - Database username
+* DB_PASS - Database password
+* DB_NAME - Database name
+* DB_PREFIX - Database table prefix. Usually set to 'pa2_'
+
+For more information on the dotenv file please visit the 
+[dotenv package's repository](https://github.com/vlucas/phpdotenv). For more information on setting environmental 
+variables in Apache, please [visit Apache's website](https://httpd.apache.org/docs/2.4/mod/mod_env.html#setenv).
+
+### Initialise the Database
      
 Run the following scripts to initialise the database (edit the files to change the names and password as reqired):
 
 - install/webpa2\_database.sql: create the database schema and user account;
 - install/webpa2\_tables.sql: create the database tables;
 - install/webpa2\_administrator.sql: create an administrator account and sample module.
+
+#### Upgrading an Existing Installation
+
+If you already have WebPA installed and are upgrading from version 3.1.0 or below, please run:
+
+- install/webpa\_security\_update.sql
      
-Login to WebPA:
+### Login to WebPA
 
-- navigate to root of WebPA application;
-- enter a username of "admin" and a password of "admin"
+- navigate to root of WebPA application
+- enter a username of _admin_ and a password of _admin_
 - change the password to something more secure after logging in
 		 
 Delete the _install_ folder when you're finished.
@@ -94,4 +120,4 @@ install instructions.
 
 WebPA was originally developed by the Centre for Engineering and Design Education at [Loughborough University](http://www.lboro.ac.uk/) with financial support from [JISC](https://www.jisc.ac.uk/)'s e-Learning Capital Programme.
 
-It continues to be mainted by a number of [open source contributors](https://github.com/WebPA/WebPA/graphs/contributors). We thank them for their time and effort supporting this system.
+It continues to be maintained by a number of [open source contributors](https://github.com/WebPA/WebPA/graphs/contributors). We thank them for their time and effort supporting this system.
diff --git a/composer.json b/composer.json
index d685f98..d6a992c 100644
--- a/composer.json
+++ b/composer.json
@@ -24,10 +24,12 @@
         }
     ],
     "require": {
-        "php": ">=7.2",
+        "php": ">=7.4",
         "ext-xml": "*",
         "ext-session": "*",
-        "ext-mysqli": "*"
+        "ext-mysqli": "*",
+        "doctrine/dbal": "^3.0",
+        "vlucas/phpdotenv": "^5.3"
     },
     "support": {
         "email": "andrew@noexceptions.io",
@@ -39,6 +41,8 @@
         "psr-4": {"WebPA\\": "src/"}
     },
     "require-dev": {
-        "phpstan/phpstan": "^0.12.25"
+        "phpstan/phpstan": "^0.12.25",
+        "friendsofphp/php-cs-fixer": "^2.18",
+        "squizlabs/php_codesniffer": "^3.5"
     }
 }
diff --git a/phpstan.neon b/phpstan.neon
new file mode 100644
index 0000000..6a49611
--- /dev/null
+++ b/phpstan.neon
@@ -0,0 +1,6 @@
+parameters:
+    level: 0
+    paths:
+        - src
+    excludePaths:
+        - src/mod/*
diff --git a/src/accounts/reset.php b/src/accounts/reset.php
index 1b4a72f..5edc009 100644
--- a/src/accounts/reset.php
+++ b/src/accounts/reset.php
@@ -21,133 +21,178 @@
 This table has the CREATE definition:
 */
 
-require_once("../includes/inc_global.php");
+require_once '../includes/inc_global.php';
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\User;
 use WebPA\includes\functions\Common;
 
 $action = Common::fetch_POST('action');
 
-switch($action) {
-  case "init":
+switch ($action) {
+  case 'init':
     //phase 2
-    //first, we create a random hash for this user. this doesn't need to be especially secure, so md5(rand()) will do fine.
-    isset($_POST['username']) or die("Username not set.");
+    //first, we create a random hash for this user.
+    isset($_POST['username']) or exit('Username not set.');
 
-    $DB->open();
-    $username = $DB->escape_str($_POST['username']);
-    $DB->close();
+    $hash = password_hash(mt_rand(), PASSWORD_DEFAULT);
+
+    $sql =
+        'SELECT user_id ' .
+        'FROM ' . APP__DB_TABLE_PREFIX . 'user ' .
+        'WHERE username = ? ' .
+        'AND source_id = "" ' .
+        'AND email IS NOT NULL ' .
+        'AND email <> ""';
+
+    $uid = $DB->getConnection()->fetchOne($sql, [$_POST['username']], [ParameterType::STRING]);
 
-    $hash = md5(rand());
-    $sql = 'SELECT user_id FROM ' . APP__DB_TABLE_PREFIX . "user WHERE username = '$username' AND source_id = '' AND " .
-           '(email IS NOT NULL) AND (email != \'\')';
-    $uid = $DB->fetch_value($sql);
     if (!$uid) {
-      $content = "Unable to reset the password for this account.";
-      break;
+        $content = 'Unable to reset the password for this account.';
+        break;
     }
-    //inserts the user/hash pair into the database
-    $sql = "INSERT INTO " . APP__DB_TABLE_PREFIX . "user_reset_request SET hash = '$hash', user_id = $uid";
-    $appname = APP__NAME; $appwww = APP__WWW;
-    $DB->execute($sql);
+    // inserts the user/hash pair into the database
+    $insertUserHashPairQuery =
+        'INSERT INTO ' . APP__DB_TABLE_PREFIX . 'user_reset_request ' .
+        'SET hash = ?, user_id = ?';
+
+    $appname = APP__NAME;
+    $appwww = APP__WWW;
+
+    $DB->getConnection()->executeQuery(
+        $insertUserHashPairQuery,
+        [$hash, $uid],
+        [ParameterType::STRING, ParameterType::INTEGER]
+    );
+
     $email = <<<TXT
-You have requested for your password to be reset on {$appname}. Please click or copy and paste the following link into your browser to continue the password reset process.
+        You have requested for your password to be reset on {$appname}. Please click or copy and paste the following link into your browser to continue the password reset process.
+
+        {$appwww}/accounts/reset.php?u=$uid&hash=$hash
+
+        If you have not requested a password reset, please ignore this email - your password will not be reset without further action.
+        TXT;
+    $userEmailQuery = 'SELECT email FROM ' . APP__DB_TABLE_PREFIX . 'user WHERE user_id = ?';
 
-{$appwww}/accounts/reset.php?u=$uid&hash=$hash
+    $uemail = $DB->getConnection()->fetchOne($userEmailQuery, [$uid], [ParameterType::INTEGER]);
 
-If you have not requested a password reset, please ignore this email - your password will not be reset without further action.
-TXT;
-    //echo $email;
-    $uemail = $DB->fetch_value("SELECT email FROM " . APP__DB_TABLE_PREFIX . "user WHERE user_id = $uid");
-    mail($uemail,APP__NAME. " Password Reset",$email,"From: " . $BRANDING['email.noreply']);
+    mail($uemail, APP__NAME. ' Password Reset', $email, 'From: ' . $BRANDING['email.noreply']);
     $content = "An email has been sent to $uemail.";
     break;
-  case "reset":
+  case 'reset':
     //phase 4
     $hash = $_POST['hash'];
     $uid = $_POST['uid'];
-    $rslt = $DB->fetch_value("SELECT COUNT(*) FROM " . APP__DB_TABLE_PREFIX . "user_reset_request WHERE hash = '$hash' AND user_id = $uid");
+
+    $query =
+        'SELECT COUNT(*) ' .
+        'FROM ' . APP__DB_TABLE_PREFIX . 'user_reset_request ' .
+        'WHERE hash = ? ' .
+        'AND user_id = ?';
+
+    $rslt = $DB->getConnection()->fetchOne($query, [$hash, $uid], [ParameterType::STRING, ParameterType::INTEGER]);
+
     if ($rslt) {
-      if ($_POST['newpass']==$_POST['confirmpass']) {
-        $user = new User();
-        $user_row = $DB->fetch_row("SELECT * FROM " . APP__DB_TABLE_PREFIX . "user WHERE user_id = $uid");
-        $user->load_from_row($user_row);
-        $user->set_dao_object($DB);
-        $user->update_password(md5($_POST['newpass']));
-        $user->save_user();
-        $DB->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "user_reset_request WHERE user_id = $uid");
-        $content = 'Your password has been reset. <a href="'.APP__WWW.'/login.php">Click here</a> to log in again.';
-      } else {
-        $content = "The two passwords did not match.";
-      }
+        if ($_POST['newpass']==$_POST['confirmpass']) {
+            $user = new User();
+
+            $dbConn = $DB->getConnection();
+
+            $userQuery = 'SELECT * FROM ' . APP__DB_TABLE_PREFIX . 'user WHERE user_id = ?';
+
+            $userRow = $dbConn->fetchAssociative($userQuery, [$uid], [ParameterType::INTEGER]);
+
+            $user->load_from_row($userRow);
+            $user->set_dao_object($DB);
+            $user->update_password($_POST['newpass']);
+            $user->save_user();
+
+            $DB->getConnection()->executeQuery(
+                'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user_reset_request WHERE user_id = ?',
+                [$uid],
+                [ParameterType::INTEGER]
+            );
+
+            $content = 'Your password has been reset. <a href="'.APP__WWW.'/login.php">Click here</a> to log in again.';
+        } else {
+            $content = 'The two passwords did not match.';
+        }
     } else {
-      $content = "There was an error resetting this password.";
+        $content = 'There was an error resetting this password.';
     }
     break;
   default:
     if (isset($_GET['hash'])) {
-      //phase 3
-      $hash = $_GET['hash'];
-      $uid = $_GET['u'];
-      if ((!isset($_GET['hash'])) || (!isset($_GET['u']))) {
-        $content = "Error: reset link incorrect. If you copied and pasted the link from your mail client, be sure you did so correctly.";
+        //phase 3
+        $hash = $_GET['hash'];
+        $uid = $_GET['u'];
+        if ((!isset($_GET['hash'])) || (!isset($_GET['u']))) {
+            $content = 'Error: reset link incorrect. If you copied and pasted the link from your mail client, be sure you did so correctly.';
+            break;
+        }
+
+        $query =
+          'SELECT COUNT(*) ' .
+          'FROM ' . APP__DB_TABLE_PREFIX . 'user_reset_request ' .
+          'WHERE hash = ? ' .
+          'AND user_id = ?';
+
+        $rslt = $DB->getConnection()->fetchOne($query, [$hash, $uid], [ParameterType::STRING, ParameterType::INTEGER]);
+
+        if ($rslt) {
+            $content = <<<HTML
+                      <form action="reset.php" method="post">
+                        <table>
+                          <tr>
+                            <th scope="row">New Password</th>
+                            <td><input type="password" name="newpass" value="" id="newpass"/></td>
+                          </tr>
+                          <tr>
+                            <th scope="row">New Password (again)</th>
+                            <td><input type="password" name="confirmpass" value="" id="confirmpass"/></td>
+                          </tr>
+                          <tr>
+                            <td></td>
+                            <td><input type="submit" value="Reset Password" /></td>
+                          </tr>
+                        </table>
+                        <input type="hidden" name="hash" value="$hash"/>
+                        <input type="hidden" name="uid" value="$uid"/>
+                        <input type="hidden" name="action" value="reset" />
+                      </form>
+                HTML;
+        } else {
+            $content = 'There was an error resetting this password. Please contact the site administrator.';
+        }
         break;
-      }
-      $rslt = $DB->fetch_value("SELECT COUNT(*) FROM " . APP__DB_TABLE_PREFIX . "user_reset_request WHERE hash = '$hash' AND user_id = $uid");
-      if ($rslt) {
-      $content = <<<HTML
-      <form action="reset.php" method="post">
-        <table>
-          <tr>
-            <th scope="row">New Password</th>
-            <td><input type="password" name="newpass" value="" id="newpass"/></td>
-          </tr>
-          <tr>
-            <th scope="row">New Password (again)</th>
-            <td><input type="password" name="confirmpass" value="" id="confirmpass"/></td>
-          </tr>
-          <tr>
-            <td></td>
-            <td><input type="submit" value="Reset Password" /></td>
-          </tr>
-        </table>
-        <input type="hidden" name="hash" value="$hash"/>
-        <input type="hidden" name="uid" value="$uid"/>
-        <input type="hidden" name="action" value="reset" />
-      </form>
-HTML;
-      } else {
-        $content = "There was an error resetting this password. Please contact the site administrator.";
-      }
-      break;
     }
     //phase 1
     //just display the form confirming the password reset.
     $content = <<<HTML
-<strong>You are about to reset your password.</strong> In order to do so, a link will be sent to your student email account. This link will take you to a page that will enable you to reset your password.<br/>
-<br/>
-<form action="reset.php" method="post">
-  <table>
-    <tr>
-      <th scope="row">Username</th>
-      <td><input type="text" name="username" /></td>
-    </tr>
-    <tr>
-      <td></td>
-      <td>
-        <input type="submit" value="Reset My Password"/>
-      </td>
-    </tr>
-  </table>
-  <input type="hidden" name="action" value="init"/>
-</form>
-HTML;
+        <strong>You are about to reset your password.</strong> In order to do so, a link will be sent to your student email account. This link will take you to a page that will enable you to reset your password.<br/>
+        <br/>
+        <form action="reset.php" method="post">
+          <table>
+            <tr>
+              <th scope="row">Username</th>
+              <td><input type="text" name="username" /></td>
+            </tr>
+            <tr>
+              <td></td>
+              <td>
+                <input type="submit" value="Reset My Password"/>
+              </td>
+            </tr>
+          </table>
+          <input type="hidden" name="action" value="init"/>
+        </form>
+        HTML;
     break;
 }
 
-$UI->page_title = "Password Reset";
+$UI->page_title = 'Password Reset';
 $UI->menu_selected = '';
-$UI->breadcrumbs = array('login page' => '../', 'Password Reset' => null);
+$UI->breadcrumbs = ['login page' => '../', 'Password Reset' => null];
 $UI->help_link = null;
 
 $UI->head();
@@ -158,4 +203,3 @@
 echo $content;
 echo "</p>\n";
 $UI->content_end(false);
-?>
diff --git a/src/admin/delete/index.php b/src/admin/delete/index.php
index fa89e48..9cb85f5 100644
--- a/src/admin/delete/index.php
+++ b/src/admin/delete/index.php
@@ -8,17 +8,18 @@
  * @link https://github.com/webpa/webpa
  */
 
- //get the include file required
- require_once("../../includes/inc_global.php");
+//get the include file required
+require_once '../../includes/inc_global.php';
 
- use WebPA\includes\classes\Module;
- use WebPA\includes\classes\User;
- use WebPA\includes\functions\Common;
+use Doctrine\DBAL\ParameterType;
+use WebPA\includes\classes\Module;
+use WebPA\includes\classes\User;
+use WebPA\includes\functions\Common;
 
- if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
-}
+ if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+     header('Location:'. APP__WWW .'/logout.php?msg=denied');
+     exit;
+ }
 
 //get the passed user ID passed as u
 $user = Common::fetch_GET('u');
@@ -27,21 +28,19 @@
 
 //set the page information
 if (!$user) {
-  $UI->page_title = APP__NAME . ' Delete module';
-} else if ($user == 'unassigned') {
-  $UI->page_title = APP__NAME . ' Delete all system users with no module';
-}else {
-  $UI->page_title = APP__NAME . ' Delete system user from module';
+    $UI->page_title = APP__NAME . ' Delete module';
+} else {
+    $UI->page_title = APP__NAME . ' Delete system user from module';
 }
 $UI->menu_selected = 'view data';
 $UI->set_page_bar_button('View Student Data', '../../../images/buttons/button_student_user.png', '../review/student/index.php');
 $UI->set_page_bar_button('View Staff Data', '../../../images/buttons/button_staff_user.png', '../review/staff/index.php');
 if (Common::check_user($_user, APP__USER_TYPE_ADMIN)) {
-  $UI->set_page_bar_button('View Admin Data', '../../../images/buttons/button_admin_user.png', '../review/admin/index.php');
-  $UI->set_page_bar_button('View Module Data', '../../../images/buttons/button_view_modules.png', '../review/module/index.php');
+    $UI->set_page_bar_button('View Admin Data', '../../../images/buttons/button_admin_user.png', '../review/admin/index.php');
+    $UI->set_page_bar_button('View Module Data', '../../../images/buttons/button_view_modules.png', '../review/module/index.php');
 }
 $UI->set_page_bar_button('Search for a user', '../../../images/buttons/button_search_user.png', '../search/index.php');
-$UI->breadcrumbs = array ('home' => '../','review data'=>'../review/','edit'=>null, );
+$UI->breadcrumbs = ['home' => '../', 'review data'=>'../review/', 'edit'=>null];
 $UI->help_link = '?q=node/237';
 $UI->head();
 $UI->body();
@@ -54,42 +53,36 @@
 //----------------------------------------------------------------------
 //process request
 
-  if (!$user) {
-    if (intval($module) == $_module_id) {
-      $sScreenMsg = "<p>You cannot delete the currently selected module!</p>";
-    } else {
-      $sScreenMsg = "<p>The module has been deleted.</p>";
-      $delete_module = new Module();
-      $delete_module->module_id = $module;
-      $delete_module->set_dao_object($DB);
-      $delete_module->delete();
-    }
-  } else if ($user == 'unassigned') {
-    //increase the execution time to handle large numbers of deletions
-    ini_set('max_execution_time', 120);
-    $sScreenMsg = "<p>Users with no module have been deleted.</p>";
-    $users = $DB->fetch_col("SELECT u.user_id FROM " . APP__DB_TABLE_PREFIX . "user u LEFT OUTER JOIN " . APP__DB_TABLE_PREFIX . "user_module um ON u.user_id = um.user_id WHERE (um.user_id IS NULL) AND (u.user_type = '" . APP__USER_TYPE_STUDENT . "')");
-    $delete_user = new User();
-    $delete_user->set_dao_object($DB);
-    for ($i=0; $i<count($users); $i++) {
-      $delete_user->id = $users[$i];
-      $delete_user->delete();
-    }
-  } else if (intval($user) == $_SESSION['_user_id']) {
-    $sScreenMsg = "<p>You cannot delete yourself!</p>";
+  if (strlen($module) > 0) {
+      if ((int) $module === $_module_id) {
+          $sScreenMsg = '<p>You cannot delete the currently selected module!</p>';
+      } else {
+          $sScreenMsg = '<p>The module has been deleted.</p>';
+          $delete_module = new Module();
+          $delete_module->module_id = $module;
+          $delete_module->set_dao_object($DB);
+          $delete_module->delete();
+      }
+  } elseif ((int) $user === $_SESSION['_user_id']) {
+      $sScreenMsg = '<p>You cannot delete yourself!</p>';
+  } elseif ($user > 0) {
+      $user_row = $CIS->get_user($user);
+      $delete_user = new User();
+      $delete_user->set_dao_object($DB);
+      $delete_user->load_from_row($user_row);
+      if (Common::check_user($_user, APP__USER_TYPE_ADMIN) && $delete_user->is_admin()) {
+          $sScreenMsg = '<p>The administrator has been deleted.</p>';
+          $delete_user->delete();
+      } else {
+          $sScreenMsg = '<p>The user has been deleted from the module.</p>';
+          $DB->getConnection()->executeQuery(
+              'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user_module WHERE user_id = ? AND module_id = ?',
+              [$user, $_SESSION['_module_id']],
+              [ParameterType::INTEGER, ParameterType::INTEGER]
+          );
+      }
   } else {
-    $user_row = $CIS->get_user($user);
-    $delete_user = new User();
-    $delete_user->set_dao_object($DB);
-    $delete_user->load_from_row($user_row);
-    if (Common::check_user($_user, APP__USER_TYPE_ADMIN) && $delete_user->is_admin()) {
-      $sScreenMsg = "<p>The administrator has been deleted.</p>";
-      $delete_user->delete();
-    } else {
-      $sScreenMsg = "<p>The user has been deleted from the module.</p>";
-      $sql = 'DELETE FROM ' . APP__DB_TABLE_PREFIX . "user_module WHERE user_id = {$user} AND module_id = {$_SESSION['_module_id']}";
-      $DB->execute($sql);
-    }
+      $errorMsg = '<p>No module or user provided to delete</p>';
   }
 
 
@@ -104,8 +97,12 @@
 
 <?php
 
-  if(!empty($sScreenMsg)){
-    echo "<div class=\"success_box\">{$sScreenMsg}</div>";
+  if (!empty($sScreenMsg)) {
+      echo "<div class=\"success_box\">{$sScreenMsg}</div>";
+  }
+
+  if (isset($errorMsg) && strlen($errorMsg) > 0) {
+      echo "<div class=\"error_box\">$errorMsg</div>";
   }
 
 ?>
@@ -114,5 +111,3 @@
 <?php
 
 $UI->content_end();
-
-?>
diff --git a/src/admin/edit/index.php b/src/admin/edit/index.php
index fd68985..080b2aa 100755
--- a/src/admin/edit/index.php
+++ b/src/admin/edit/index.php
@@ -17,16 +17,17 @@
  */
 
 //get the include file required
-require_once('../../includes/inc_global.php');
+require_once '../../includes/inc_global.php';
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\User;
 use WebPA\includes\functions\Common;
 use WebPA\includes\functions\Form;
 use WebPA\includes\functions\StringFunctions;
 
 if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 //set the page information
@@ -35,11 +36,11 @@
 $UI->set_page_bar_button('View Student Data', '../../../images/buttons/button_student_user.png', '../review/student/index.php');
 $UI->set_page_bar_button('View Staff Data', '../../../images/buttons/button_staff_user.png', '../review/staff/index.php');
 if (Common::check_user($_user, APP__USER_TYPE_ADMIN)) {
-  $UI->set_page_bar_button('View Admin Data', '../../../images/buttons/button_admin_user.png', '../review/admin/index.php');
-  $UI->set_page_bar_button('View Module Data', '../../../images/buttons/button_view_modules.png', '../review/module/index.php');
+    $UI->set_page_bar_button('View Admin Data', '../../../images/buttons/button_admin_user.png', '../review/admin/index.php');
+    $UI->set_page_bar_button('View Module Data', '../../../images/buttons/button_view_modules.png', '../review/module/index.php');
 }
 $UI->set_page_bar_button('Search for a user', '../../../images/buttons/button_search_user.png', '../search/index.php');
-$UI->breadcrumbs = array ('home' => '../','review data'=>'../review/','edit'=>null, );
+$UI->breadcrumbs = ['home' => '../', 'review data'=>'../review/', 'edit'=>null];
 $UI->help_link = '?q=node/237';
 
 //build the content to be written to the screen
@@ -53,7 +54,7 @@
 $username = Common::fetch_POST('username');
 $new_user = empty($user_id);
 $type = Common::fetch_POST('t', Common::fetch_GET('t', ''));
-$user_found = FALSE;
+$user_found = false;
 
 $sScreenMsg = '';
 
@@ -61,34 +62,34 @@
 //collect all the information about the person to populate the fields
 $edit_user = new User();
 if (!$new_user) {
-  $user_row = $CIS->get_user($user_id);
-  $edit_user->load_from_row($user_row);
+    $user_row = $CIS->get_user($user_id);
+    $edit_user->load_from_row($user_row);
 } else {
-  if (!empty($username)) {
-    $user_row = $CIS->get_user_for_username($username);
-    if ($user_row) {
-      $user_found = TRUE;
-      $edit_user->load_from_row($user_row);
-      $user_id = $edit_user->id;
+    if (!empty($username)) {
+        $user_row = $CIS->get_user_for_username($username);
+        if ($user_row) {
+            $user_found = true;
+            $edit_user->load_from_row($user_row);
+            $user_id = $edit_user->id;
+        }
     }
-  }
-  if ($_user->is_admin() && ($type == APP__USER_TYPE_ADMIN)) {
-    if ($user_found) {
-      $user_found = FALSE;
-      $user_id = '';
-      $edit_user = new User();
-      $action = '';
-      $sScreenMsg = 'The username already exists; please use another.';
+    if ($_user->is_admin() && ($type == APP__USER_TYPE_ADMIN)) {
+        if ($user_found) {
+            $user_found = false;
+            $user_id = '';
+            $edit_user = new User();
+            $action = '';
+            $sScreenMsg = 'The username already exists; please use another.';
+        }
+        $edit_user->admin = 1;
     }
-    $edit_user->admin = 1;
-  }
 }
 if ($edit_user->is_admin() && ($type != APP__USER_TYPE_ADMIN)) {
-  $user_found = FALSE;
-  $user_id = '';
-  $edit_user = new User();
-  $action = '';
-  $sScreenMsg = 'Administrators cannot be enrolled in modules.';
+    $user_found = false;
+    $user_id = '';
+    $edit_user = new User();
+    $action = '';
+    $sScreenMsg = 'Administrators cannot be enrolled in modules.';
 }
 
 //----------------------------------------------------------------------
@@ -99,163 +100,179 @@
 if ($canEdit) {
 
   //put all the elements back into the structures
-  $value = Common::fetch_POST('name');
-  if (!empty($value)) {
-    $edit_user->forename = $value;
-  }
-  $value = Common::fetch_POST('lastname');
-  if (!empty($value)) {
-    $edit_user->lastname = $value;
-  }
-  $value = Common::fetch_POST('id_number');
-  if (!empty($value)) {
-    $edit_user->id_number = $value;
-  }
-  $value = Common::fetch_POST('department_id');
-  if (!empty($value)) {
-    $edit_user->department_id = $value;
-  }
-  $value = Common::fetch_POST('email');
-  if (!empty($value)) {
-    $edit_user->email = $value;
-  }
-  //check to see if the password needs to be saved
-  $password = Common::fetch_POST('password', '');
-  if ((($password != '!!!!!!') && !empty($password)) || empty($user_id)) {
-    if (($password == '!!!!!!') || empty($password)) {
-      $password = StringFunctions::str_random();
+    $value = Common::fetch_POST('name');
+    if (!empty($value)) {
+        $edit_user->forename = $value;
     }
-    $edit_user->update_password(md5($password));
-  }
+    $value = Common::fetch_POST('lastname');
+    if (!empty($value)) {
+        $edit_user->lastname = $value;
+    }
+    $value = Common::fetch_POST('id_number');
+    if (!empty($value)) {
+        $edit_user->id_number = $value;
+    }
+    $value = Common::fetch_POST('department_id');
+    if (!empty($value)) {
+        $edit_user->department_id = $value;
+    }
+    $value = Common::fetch_POST('email');
+    if (!empty($value)) {
+        $edit_user->email = $value;
+    }
+    //check to see if the password needs to be saved
+    $password = Common::fetch_POST('password', '');
 
-  if ((($new_user && !$user_found) || $_user->is_admin()) && Common::fetch_POST('username')) {
-    $edit_user->update_username(Common::fetch_POST('username'));
-  }
+    if ((($password != '!!!!!!') && !empty($password)) || empty($user_id)) {
+        if (($password == '!!!!!!') || empty($password)) {
+            $password = StringFunctions::str_random();
+        }
+
+        $edit_user->update_password($password);
+    }
+
+    if ((($new_user && !$user_found) || $_user->is_admin()) && Common::fetch_POST('username')) {
+        $edit_user->update_username(Common::fetch_POST('username'));
+    }
 }
 
 if ($action) {          //incase we want to do more than save changes in the future
-  switch ($action) {
+    switch ($action) {
     case 'Save Changes':
 
       $complete = !empty($edit_user->forename) && !empty($edit_user->lastname) &&
                   !empty($edit_user->password) && !empty($edit_user->username);
-    	
+        
       if (!$complete) {
-        $sScreenMsg = 'Unable to save user: please make sure the user has a username, first name, last name and password.';
+          $sScreenMsg = 'Unable to save user: please make sure the user has a username, first name, last name and password.';
       } elseif ($edit_user->email != '' && !Form::is_email($edit_user->email)) {
-      	$sScreenMsg = 'Unable to save user: email address is not valid.';
+          $sScreenMsg = 'Unable to save user: email address is not valid.';
       } else {
-        //send notification to the screen that the save has occured.
-        if ($new_user && !$user_found) {
-          $sScreenMsg = 'The user has been created';
-        } else {
-          $sScreenMsg = 'The changes made for the user have been saved';
-        }
-
-        if ($canEdit) {
-          $edit_user->set_dao_object($DB);
-
-          //save all of the data
+          //send notification to the screen that the save has occured.
           if ($new_user && !$user_found) {
-            $user = $edit_user->add_user();
-            $user_row = $CIS->get_user($user);
-            //reload user
-            $edit_user = new User();
-            $edit_user->load_from_row($user_row);
-            $user_id = $edit_user->id;
+              $sScreenMsg = 'The user has been created';
           } else {
-            $edit_user->save_user();
+              $sScreenMsg = 'The changes made for the user have been saved';
           }
-        }
 
-        if (!$new_user && !$edit_user->is_admin()) {
-          $modules = $CIS->get_module(NULL, 'name');
-          $user_modules = $CIS->get_user_modules($user_id);
-
-          foreach ($modules as $module) {
-
-            if (empty($user_modules) || !array_key_exists($module['module_id'], $user_modules)) {
-              $old_role = '';
-            } else {
-              $old_role = $user_modules[$module['module_id']]['user_type'];
-            }
-            if (isset($_POST["rdo_type_{$module['module_id']}"])) {
-              $new_role = $_POST["rdo_type_{$module['module_id']}"];
-            } else {
-              $new_role = '';
-            }
-            if ($old_role != $new_role) {
-              if (empty($new_role)) {
-                $delete[] = $module['module_id'];
+          if ($canEdit) {
+              $edit_user->set_dao_object($DB);
+
+              //save all of the data
+              if ($new_user && !$user_found) {
+                  $user = $edit_user->add_user();
+                  $user_row = $CIS->get_user($user);
+                  //reload user
+                  $edit_user = new User();
+                  $edit_user->load_from_row($user_row);
+                  $user_id = $edit_user->id;
               } else {
-                $update[$new_role][] = $module['module_id'];
+                  $edit_user->save_user();
               }
-            }
           }
-        } else if (!$edit_user->is_admin() && ($type != APP__USER_TYPE_ADMIN)) {
-          $user_modules = $CIS->get_user_modules($user_id);
-          if (!is_array($user_modules)) {
-            $user_modules = array();
-          }
-          if (!array_key_exists($_module_id, $user_modules)) {
-            $update[$type][] = $_module_id;
-          } else if ($user_modules[$_module_id]['user_type'] == $type) {
-            $sScreenMsg = 'User is already enrolled';
-          } else {
-            $sScreenMsg = 'User currently has a different role in this module - change not saved';
-          }
-        }
-        if (isset($update)) {
-          if (isset($update[APP__USER_TYPE_TUTOR])) {
-            $sql = 'INSERT INTO ' . APP__DB_TABLE_PREFIX . 'user_module (user_id, module_id, user_type) ' .
-                   "VALUES ";
-            $sep = '';
-            foreach ($update[APP__USER_TYPE_TUTOR] as $module) {
-              $sql .= "{$sep}({$user_id}, {$module}, '" . APP__USER_TYPE_TUTOR . "')";
-              $sep = ', ';
-            }
-            $sql .= " ON DUPLICATE KEY UPDATE user_type = '" . APP__USER_TYPE_TUTOR . "'";
-            $DB->execute($sql);
-          }
-          if (isset($update[APP__USER_TYPE_STUDENT])) {
-            $sql = 'INSERT INTO ' . APP__DB_TABLE_PREFIX . 'user_module (user_id, module_id, user_type) ' .
-                   "VALUES ";
-            $sep = '';
-            foreach ($update[APP__USER_TYPE_STUDENT] as $module) {
-              $sql .= "{$sep}({$user_id}, {$module}, '" . APP__USER_TYPE_STUDENT . "')";
-              $sep = ', ';
-            }
-            $sql .= " ON DUPLICATE KEY UPDATE user_type = '" . APP__USER_TYPE_STUDENT . "'";
-            $DB->execute($sql);
+
+          if (!$new_user && !$edit_user->is_admin()) {
+              $modules = $CIS->get_module(null, 'name');
+              $user_modules = $CIS->get_user_modules($user_id);
+
+              foreach ($modules as $module) {
+                  if (empty($user_modules) || !array_key_exists($module['module_id'], $user_modules)) {
+                      $old_role = '';
+                  } else {
+                      $old_role = $user_modules[$module['module_id']]['user_type'];
+                  }
+                  if (isset($_POST["rdo_type_{$module['module_id']}"])) {
+                      $new_role = $_POST["rdo_type_{$module['module_id']}"];
+                  } else {
+                      $new_role = '';
+                  }
+                  if ($old_role != $new_role) {
+                      if (empty($new_role)) {
+                          $delete[] = $module['module_id'];
+                      } else {
+                          $update[$new_role][] = $module['module_id'];
+                      }
+                  }
+              }
+          } elseif (!$edit_user->is_admin() && ($type != APP__USER_TYPE_ADMIN)) {
+              $user_modules = $CIS->get_user_modules($user_id);
+              if (!is_array($user_modules)) {
+                  $user_modules = [];
+              }
+              if (!array_key_exists($_module_id, $user_modules)) {
+                  $update[$type][] = $_module_id;
+              } elseif ($user_modules[$_module_id]['user_type'] == $type) {
+                  $sScreenMsg = 'User is already enrolled';
+              } else {
+                  $sScreenMsg = 'User currently has a different role in this module - change not saved';
+              }
           }
-        }
-        if (isset($delete)) {
-          $sql = "DELETE FROM " . APP__DB_TABLE_PREFIX . "user_module " .
-                 "WHERE (user_id = {$user_id}) AND (module_id IN (";
-          $sep = '';
-          foreach ($delete as $module) {
-            $sql .= "{$sep}{$module}";
-            $sep = ', ';
+          if (isset($update)) {
+              if (isset($update[APP__USER_TYPE_TUTOR])) {
+                  $createUserModuleQuery =
+                'INSERT INTO ' . APP__DB_TABLE_PREFIX . 'user_module ' .
+                '(user_id, module_id, user_type) ' .
+                'VALUES (?, ? , ?) ' .
+                'ON DUPLICATE KEY UPDATE user_type = ?';
+
+                  foreach ($update[APP__USER_TYPE_TUTOR] as $module) {
+                      $DB->getConnection()->executeQuery(
+                          $createUserModuleQuery,
+                          [$user_id, $module, APP__USER_TYPE_TUTOR, APP__USER_TYPE_TUTOR],
+                          [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING, ParameterType::STRING]
+                      );
+                  }
+              }
+
+              if (isset($update[APP__USER_TYPE_STUDENT])) {
+                  $createUserModuleQuery =
+                'INSERT INTO ' . APP__DB_TABLE_PREFIX . 'user_module ' .
+                '(user_id, module_id, user_type) ' .
+                'VALUES (?, ?, ?) ' .
+                'ON DUPLICATE KEY UPDATE user_type = ?';
+
+                  foreach ($update[APP__USER_TYPE_STUDENT] as $module) {
+                      $DB->getConnection()->executeQuery(
+                          $createUserModuleQuery,
+                          [$user_id, $module, APP__USER_TYPE_STUDENT, APP__USER_TYPE_STUDENT],
+                          [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING, ParameterType::STRING]
+                      );
+                  }
+              }
           }
-          $sql .= '))';
-          $DB->execute($sql);
-          if (in_array($_module_id, $delete)) {
-            header('Location: ../review/');
+          if (isset($delete)) {
+              $queryBuilder = $DB->getConnection()->createQueryBuilder();
+
+              $queryBuilder
+                ->delete(APP__DB_TABLE_PREFIX . 'user_module')
+                ->where(
+                    $queryBuilder->expr()->and(
+                        $queryBuilder->expr()->eq('user_id', '?'),
+                        $queryBuilder->expr()->in('module_id', '?')
+                    )
+                );
+
+              $queryBuilder->setParameter(0, $user_id, ParameterType::INTEGER);
+              $queryBuilder->setParameter(1, $delete, $DB->getConnection()::PARAM_INT_ARRAY);
+
+              $queryBuilder->execute();
+
+              if (in_array($_module_id, $delete)) {
+                  header('Location: ../review/');
+              }
           }
-        }
 
-        if (isset($update) || isset($delete)) {
-          //collect all the updated information
-          $user_row = $CIS->get_user($user_id);
-          $edit_user = new User();
-          $edit_user->load_from_row($user_row);
-        }
+          if (isset($update) || isset($delete)) {
+              //collect all the updated information
+              $user_row = $CIS->get_user($user_id);
+              $edit_user = new User();
+              $edit_user->load_from_row($user_row);
+          }
       }
 
       break;
 
   }
-
 }
 
 $UI->head();
@@ -268,27 +285,21 @@
 $page_intro = 'Here you are able to edit the details of a user within the system. There may be some elements of the information which do not appear' .
     '   to have been completed and this will be dependant on the information stored in the system.';
 if (empty($user_id)) {
-  $page_intro .= ' Just enter the username for users already added to the system.';
+    $page_intro .= ' Just enter the username for users already added to the system.';
 }
 
-if (!in_array('LDAP', $LOGIN_AUTHENTICATORS)) {
-  $page_conditions = 'N.B. Users authenticated directly from the WebPA <strong>database</strong> must be given a password.';
-} else if (LDAP__AUTO_CREATE_USER) {
-  $page_conditions = 'N.B. Users authenticated via <strong>LDAP</strong> will automatically be added to the database and updated each time they log in; the password stored is a random value.';
-}else{
-  $page_conditions = 'N.B. Users authenticated via <strong>LDAP</strong> must be added to the database before they are able to log in; a random password will be added automatically.';
-}
+$page_conditions = 'N.B. Users authenticated directly from the WebPA <strong>database</strong> must be given a password.';
 
 echo '<p>' . $page_intro . '</p>';
 
 if ($type == APP__USER_TYPE_ADMIN) {
-  $cancel = '../review/admin/';
-} else if ($type == APP__USER_TYPE_TUTOR) {
-  $cancel = '../review/staff/';
-} else if ($type == APP__USER_TYPE_STUDENT) {
-  $cancel = '../review/student/';
+    $cancel = '../review/admin/';
+} elseif ($type == APP__USER_TYPE_TUTOR) {
+    $cancel = '../review/staff/';
+} elseif ($type == APP__USER_TYPE_STUDENT) {
+    $cancel = '../review/student/';
 } else {
-  $cancel = '../review/';
+    $cancel = '../review/';
 }
 
 ?>
@@ -299,7 +310,7 @@
 echo '<p>' . $page_conditions . '</p>';
 
 if (!empty($sScreenMsg)) {
-  echo "<div class=\"success_box\">{$sScreenMsg}</div>";
+    echo "<div class=\"success_box\">{$sScreenMsg}</div>";
 }
 ?>
 
@@ -313,9 +324,9 @@
 $canEdit = ($_source_id == '') && (empty($user_id) || ($_user->is_admin()));
 
 if (!$canEdit) {
-  $disabled = ' disabled="disabled"';
+    $disabled = ' disabled="disabled"';
 } else {
-  $disabled = '';
+    $disabled = '';
 }
 ?>
       <input type="text" name="username" id="username" value="<?php echo $edit_user->username; ?>"<?php echo $disabled; ?>>
@@ -357,9 +368,9 @@
     <td>
 <?php
 if (!empty($edit_user->password)) {
-  $show = '!!!!!!';
+    $show = '!!!!!!';
 } else {
-  $show = '';
+    $show = '';
 }
 ?>
       <input id="password" name="password" type="password" value="<?php echo $show; ?>"<?php echo $disabled; ?>>
@@ -371,7 +382,7 @@
 
 <?php
 if (!empty($user_id) && !Common::check_user($edit_user, APP__USER_TYPE_ADMIN)) {
-?>
+    ?>
   <tr><td colspan="4"><hr/></td></tr>
   <tr><td colspan="4"><h2>Module</h2></td></tr>
   <tr>
@@ -379,65 +390,61 @@
 
 <?php
   $canEdit = ($_source_id == '') && ($user_id != $_user_id);
-  if (!$canEdit) {
-    $disabled = ' disabled="disabled"';
-  } else {
-    $disabled = '';
-  }
-
-  echo "<table>\n";
-  echo "<tr>\n";
-  echo "  <th>Title</th><th style=\"width: 5em; text-align: center;\">NA</th><th style=\"width: 5em; text-align: center;\">Tutor</th><th style=\"width: 5em; text-align: center;\">Student</th>\n";
-  echo "</tr>\n";
-
-  $modules = $CIS->get_module(NULL, 'name');
-  $user_modules = $CIS->get_user_modules($user_id);
-
-  foreach ($modules as $module) {
-
-    if (empty($user_modules) || !array_key_exists($module['module_id'], $user_modules)) {
-      $role = '';
-    } else {
-      $role = $user_modules[$module['module_id']]['user_type'];
-    }
-    if ($module['module_id'] == $_module_id) {
-      $tagStart = '<em>';
-      $tagEnd = '</em>';
+    if (!$canEdit) {
+        $disabled = ' disabled="disabled"';
     } else {
-      $tagStart = '';
-      $tagEnd = '';
+        $disabled = '';
     }
 
+    echo "<table>\n";
     echo "<tr>\n";
-    echo "  <td>\n    {$tagStart}{$module['module_title']}{$tagEnd}&nbsp;&nbsp;&nbsp;\n  </td>\n";
-    echo "  <td style=\"text-align: center;\">\n";
-    echo '    <input type="radio" value="" name="rdo_type_' . $module['module_id'] . '"';
-    if (empty($role)) {
-      echo ' checked="checked"';
-    }
-    echo "{$disabled}>\n";
-    echo "  </td>\n";
-    echo "  <td style=\"text-align: center;\">\n";
-    echo '    <input type="radio" value="' . APP__USER_TYPE_TUTOR . '" name="rdo_type_' . $module['module_id'] . '"';
-    if ($role == APP__USER_TYPE_TUTOR) {
-      echo ' checked="checked"';
-    }
-    echo "{$disabled}>\n";
-    echo "  </td>\n";
-    echo "  <td style=\"text-align: center;\">\n";
-    echo '    <input type="radio" value="' . APP__USER_TYPE_STUDENT . '" name="rdo_type_' . $module['module_id'] . '"';
-    if ($role == APP__USER_TYPE_STUDENT) {
-      echo ' checked="checked"';
-    }
-    echo "{$disabled}>\n";
-    echo "  </td>\n";
+    echo "  <th>Title</th><th style=\"width: 5em; text-align: center;\">NA</th><th style=\"width: 5em; text-align: center;\">Tutor</th><th style=\"width: 5em; text-align: center;\">Student</th>\n";
     echo "</tr>\n";
 
-  }
+    $modules = $CIS->get_module(null, 'name');
+    $user_modules = $CIS->get_user_modules($user_id);
 
-  echo "</table>\n";
+    foreach ($modules as $module) {
+        if (empty($user_modules) || !array_key_exists($module['module_id'], $user_modules)) {
+            $role = '';
+        } else {
+            $role = $user_modules[$module['module_id']]['user_type'];
+        }
+        if ($module['module_id'] == $_module_id) {
+            $tagStart = '<em>';
+            $tagEnd = '</em>';
+        } else {
+            $tagStart = '';
+            $tagEnd = '';
+        }
 
-?>
+        echo "<tr>\n";
+        echo "  <td>\n    {$tagStart}{$module['module_title']}{$tagEnd}&nbsp;&nbsp;&nbsp;\n  </td>\n";
+        echo "  <td style=\"text-align: center;\">\n";
+        echo '    <input type="radio" value="" name="rdo_type_' . $module['module_id'] . '"';
+        if (empty($role)) {
+            echo ' checked="checked"';
+        }
+        echo "{$disabled}>\n";
+        echo "  </td>\n";
+        echo "  <td style=\"text-align: center;\">\n";
+        echo '    <input type="radio" value="' . APP__USER_TYPE_TUTOR . '" name="rdo_type_' . $module['module_id'] . '"';
+        if ($role == APP__USER_TYPE_TUTOR) {
+            echo ' checked="checked"';
+        }
+        echo "{$disabled}>\n";
+        echo "  </td>\n";
+        echo "  <td style=\"text-align: center;\">\n";
+        echo '    <input type="radio" value="' . APP__USER_TYPE_STUDENT . '" name="rdo_type_' . $module['module_id'] . '"';
+        if ($role == APP__USER_TYPE_STUDENT) {
+            echo ' checked="checked"';
+        }
+        echo "{$disabled}>\n";
+        echo "  </td>\n";
+        echo "</tr>\n";
+    }
+
+    echo "</table>\n"; ?>
     </td>
   </tr>
 <?php
diff --git a/src/admin/edit/module.php b/src/admin/edit/module.php
index 9d9ae52..6fb1ccf 100644
--- a/src/admin/edit/module.php
+++ b/src/admin/edit/module.php
@@ -16,14 +16,14 @@
  */
 
 //get the include file required
-require_once("../../includes/inc_global.php");
+require_once '../../includes/inc_global.php';
 
 use WebPA\includes\classes\Module;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_ADMIN)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_ADMIN)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
  //set the page information
@@ -34,7 +34,7 @@
 $UI->set_page_bar_button('View Admin Data', '../../../images/buttons/button_admin_user.png', '../review/admin/index.php');
 $UI->set_page_bar_button('View Module Data', '../../../images/buttons/button_view_modules.png', '../review/module/index.php');
 $UI->set_page_bar_button('Search for a user', '../../../images/buttons/button_search_user.png', '../search/index.php');
-$UI->breadcrumbs = array ('home' => '../','review data'=>'../review/','edit'=>null, );
+$UI->breadcrumbs = ['home' => '../', 'review data'=>'../review/', 'edit'=>null];
 $UI->help_link = '?q=node/237';
 $UI->head();
 $UI->body();
@@ -63,7 +63,7 @@
 $action = Common::fetch_POST('save');
 
 if ($action) {          //incase we want to do more than save changes in the future
-  switch ($action) {
+    switch ($action) {
     case 'Save Changes':
     //put all the elements back into the structures
     $edit_module->module_code = Common::fetch_POST('module_code');
@@ -72,9 +72,9 @@
     //save all of the data
     $edit_module->set_dao_object($DB);
     if (empty($module)) {
-      $module = $edit_module->add_module();
+        $module = $edit_module->add_module();
     } else {
-      $edit_module->save_module();
+        $edit_module->save_module();
     }
 
     //reload module
@@ -83,10 +83,9 @@
     $edit_module->load_from_row($module_id);
 
     //send notification to the screen that the save has occured.
-    $sScreenMsg = "The changes made for the module have been saved";
+    $sScreenMsg = 'The changes made for the module have been saved';
 
   }
-
 }
 
 //-----------------------------------------------------------------------
@@ -103,8 +102,8 @@
 
 <?php
 
-  if(!empty($sScreenMsg)){
-    echo "<div class=\"success_box\">{$sScreenMsg}</div>";
+  if (!empty($sScreenMsg)) {
+      echo "<div class=\"success_box\">{$sScreenMsg}</div>";
   }
 
 ?>
diff --git a/src/admin/index.php b/src/admin/index.php
index 40e90f7..1fb3d33 100644
--- a/src/admin/index.php
+++ b/src/admin/index.php
@@ -12,19 +12,19 @@
  */
 
 //get the include file required
-require_once("../includes/inc_global.php");
+require_once '../includes/inc_global.php';
 
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
  //set the page information
 $UI->page_title = APP__NAME;
 $UI->menu_selected = 'admin home';
-$UI->breadcrumbs = array ('home' => null);
+$UI->breadcrumbs = ['home' => null];
 $UI->help_link = '?q=node/237';
 $UI->head();
 $UI->body();
@@ -34,31 +34,31 @@
 
 $page_intro = 'Welcome to the Administration Area for ' . APP__NAME . '. In this section you are able to manage the users of the system (both adding new and editing existing)';
 if ($_user->is_admin()) {
-  $page_intro .= ' as well as generate basic reports on the usage of ' . APP__NAME . ' (the metrics)';
+    $page_intro .= ' as well as generate basic reports on the usage of ' . APP__NAME . ' (the metrics)';
 }
 $page_intro .= '.<br/><br/>The admin area contains the following sections:';
 $menu = $UI->get_menu('Admin');
 if (isset($menu['upload data'])) {
-  $upload = $menu['upload data'];
-  if ($_user->is_admin()) {
-    $section_name = array('Upload Data', 'View Data', 'WebPA Metrics');
-    $section_link = array($upload, 'review/', 'metrics/');
-  } else {
-    $section_name = array('Upload Data', 'View Data');
-    $section_link = array($upload, 'review/');
-  }
+    $upload = $menu['upload data'];
+    if ($_user->is_admin()) {
+        $section_name = ['Upload Data', 'View Data', 'WebPA Metrics'];
+        $section_link = [$upload, 'review/', 'metrics/'];
+    } else {
+        $section_name = ['Upload Data', 'View Data'];
+        $section_link = [$upload, 'review/'];
+    }
 } else {
-  if ($_user->is_admin()) {
-    $section_name = array('View Data', 'WebPA Metrics');
-    $section_link = array('review/', 'metrics/');
-  } else {
-    $section_name = array('View Data');
-    $section_link = array('review/');
-  }
+    if ($_user->is_admin()) {
+        $section_name = ['View Data', 'WebPA Metrics'];
+        $section_link = ['review/', 'metrics/'];
+    } else {
+        $section_name = ['View Data'];
+        $section_link = ['review/'];
+    }
 }
-$section_definition = array('This is where you can upload the data to the system.',
+$section_definition = ['This is where you can upload the data to the system.',
               'This area allows you to view the uploaded data as well as search and edit user information.',
-              'This section allows you to generate reports on the usage of WebPA locally.');
+              'This section allows you to generate reports on the usage of WebPA locally.', ];
 ?>
 <p><?php echo $page_intro; ?></p>
 
@@ -67,7 +67,7 @@
 <table class="option_list" style="width: 500px;">
 <?php
   for ($i = 0; $i < count($section_link); $i++) {
-?>
+      ?>
 <tr>
   <td><a href="<?php echo $section_link[$i]; ?>"><img src="../images/icons/load_data.gif" width="32" height="32" alt="" /></a></td>
   <td>
diff --git a/src/admin/load/index.php b/src/admin/load/index.php
index 7ee9701..abe0e44 100644
--- a/src/admin/load/index.php
+++ b/src/admin/load/index.php
@@ -17,20 +17,20 @@
  */
 
 //get the include file required
-require_once("../../includes/inc_global.php");
+require_once '../../includes/inc_global.php';
 
 use WebPA\includes\classes\GroupHandler;
 use WebPA\includes\functions\Common;
 
 if (!Common::check_user($_user, APP__USER_TYPE_TUTOR) || ($_source_id != '')) {
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 //set the page information
 $UI->page_title = APP__NAME;
 $UI->menu_selected = 'upload data';
-$UI->breadcrumbs = array ('home' => null);
+$UI->breadcrumbs = ['home' => null];
 $UI->help_link = '?q=node/237';
 
 $UI->head();
@@ -59,7 +59,7 @@ function fileTypeSelected(id) {
 $page_intro = 'You can upload the data the system requires from this page';
 $filename = 'Enter the file name to be used:';
 $filecontent = 'Select the type of information you are uploading:<br>';
-$filecontenttype = array(4);
+$filecontenttype = [4];
 //even though it appears second, the 'student data with groups' option has a filecontenttype.value of 4 (to prevent possible breakage)
 
 //this code is for use when one wants to create group collections first, then upload data
@@ -69,30 +69,30 @@ function fileTypeSelected(id) {
 $groupsAnnex = '<div style="display: none;" id="collectionNameDiv">
   <label>Collection:';
 if (count($collections) > 0) {
-  $groupsAnnex .= '&nbsp;<select name="collectionlist">';
-  $groupsAnnex .= '<option value="">Create using name entered...</option>';
-  foreach($collections as $collection) {
-    $groupsAnnex .= "<option value=\"{$collection['collection_id']}\">{$collection['collection_name']}</option>";
-  }
-  $groupsAnnex .= '</select></label>&nbsp;<label>new:';
+    $groupsAnnex .= '&nbsp;<select name="collectionlist">';
+    $groupsAnnex .= '<option value="">Create using name entered...</option>';
+    foreach ($collections as $collection) {
+        $groupsAnnex .= "<option value=\"{$collection['collection_id']}\">{$collection['collection_name']}</option>";
+    }
+    $groupsAnnex .= '</select></label>&nbsp;<label>new:';
 }
 $groupsAnnex .= '&nbsp;<input type="text" name="collection"/></label></div>';
 
 if ($_user->is_admin()) {
-  $filecontenttype[1] = array('screen'=>'<strong>Student Data</strong><p>CSV File format = id_number, forename, lastname, email, username, password, department_id, module_code</p>', 'value'=>'1');
-  $filecontenttype[2] = array('screen'=>'<strong>Student Data with Groups</strong>'.$groupsAnnex.'<p>CSV File format = id_number, forename, lastname, email, username, group_name, password, module_code</p>', 'value'=>'4');
-  $filecontenttype[3] = array('screen'=>'<strong>Staff Data</strong><p>CSV File format = id_number, forename, lastname, email, username, password, department_id, module_code</p>', 'value'=>'2');
+    $filecontenttype[1] = ['screen'=>'<strong>Student Data</strong><p>CSV File format = id_number, forename, lastname, email, username, password, department_id, module_code</p>', 'value'=>'1'];
+    $filecontenttype[2] = ['screen'=>'<strong>Student Data with Groups</strong>'.$groupsAnnex.'<p>CSV File format = id_number, forename, lastname, email, username, group_name, password, module_code</p>', 'value'=>'4'];
+    $filecontenttype[3] = ['screen'=>'<strong>Staff Data</strong><p>CSV File format = id_number, forename, lastname, email, username, password, department_id, module_code</p>', 'value'=>'2'];
 } else {
-  $filecontenttype[1] = array('screen'=>'<strong>Student Data</strong><p>CSV File format = id_number, forename, lastname, email, username, password, department_id</p>', 'value'=>'1');
-  $filecontenttype[2] = array('screen'=>'<strong>Student Data with Groups</strong>'.$groupsAnnex.'<p>CSV File format = id_number, forename, lastname, email, username, group_name, password</p>', 'value'=>'4');
-  $filecontenttype[3] = array('screen'=>'<strong>Staff Data</strong><p>CSV File format = id_number, forename, lastname, email, username, password, department_id</p>', 'value'=>'2');
+    $filecontenttype[1] = ['screen'=>'<strong>Student Data</strong><p>CSV File format = id_number, forename, lastname, email, username, password, department_id</p>', 'value'=>'1'];
+    $filecontenttype[2] = ['screen'=>'<strong>Student Data with Groups</strong>'.$groupsAnnex.'<p>CSV File format = id_number, forename, lastname, email, username, group_name, password</p>', 'value'=>'4'];
+    $filecontenttype[3] = ['screen'=>'<strong>Staff Data</strong><p>CSV File format = id_number, forename, lastname, email, username, password, department_id</p>', 'value'=>'2'];
 }
-$filecontenttype[4] = array('screen'=>'<strong>Module Data</strong><p>CSV File format = module_code, module_title</p>', 'value'=>'3');
+$filecontenttype[4] = ['screen'=>'<strong>Module Data</strong><p>CSV File format = module_code, module_title</p>', 'value'=>'3'];
 $fileseparator = 'Select the type of file separator that has been used:';
-$separator = array(3);
-$separator[1] = array('screen'=> 'Comma separated', 'value'=>',', 'status' => '');
-$separator[2] = array('screen'=> 'Tab separated', 'value'=>'\t','status' => 'disabled');
-$separator[3] = array('screen'=> 'Semi-colon', 'value'=>';','status' => 'disabled');
+$separator = [3];
+$separator[1] = ['screen'=> 'Comma separated', 'value'=>',', 'status' => ''];
+$separator[2] = ['screen'=> 'Tab separated', 'value'=>'\t', 'status' => 'disabled'];
+$separator[3] = ['screen'=> 'Semi-colon', 'value'=>';', 'status' => 'disabled'];
 
 $btn_name = 'Upload';
 $pasteinstruction ='Copy and paste the contents of the file you want to add to the system, ensuring that the information is comma separated and that each entry begins on a new line.';
@@ -119,14 +119,13 @@ function fileTypeSelected(id) {
     </td>
     <td>
       <?php
-        for($checkbox = 1; $checkbox<= count($filecontenttype)-1; $checkbox++){
-
-          echo '<input type="radio" name="rdoFileContentType" value="';
-          echo $filecontenttype[$checkbox]['value'] . '" ';
-          echo "onclick=\"fileTypeSelected({$filecontenttype[$checkbox]['value']})\" id=\"rdoFileContentType-{$filecontenttype[$checkbox]['value']}\"";
-          echo ' />';
-          echo $filecontenttype[$checkbox]['screen'];
-          echo '<br/>';
+        for ($checkbox = 1; $checkbox<= count($filecontenttype)-1; $checkbox++) {
+            echo '<input type="radio" name="rdoFileContentType" value="';
+            echo $filecontenttype[$checkbox]['value'] . '" ';
+            echo "onclick=\"fileTypeSelected({$filecontenttype[$checkbox]['value']})\" id=\"rdoFileContentType-{$filecontenttype[$checkbox]['value']}\"";
+            echo ' />';
+            echo $filecontenttype[$checkbox]['screen'];
+            echo '<br/>';
         }
       ?>
     </td>
diff --git a/src/admin/load/simple.php b/src/admin/load/simple.php
index eb1bba4..c3e40a1 100644
--- a/src/admin/load/simple.php
+++ b/src/admin/load/simple.php
@@ -12,38 +12,39 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once('../../includes/inc_global.php');
+require_once '../../includes/inc_global.php';
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\GroupCollection;
 use WebPA\includes\functions\Common;
 use WebPA\includes\functions\StringFunctions;
 
 if (!Common::check_user($_user, APP__USER_TYPE_TUTOR) || ($_source_id != '')) {
- header('Location:'. APP__WWW .'/logout.php?msg=denied');
- exit;
+    header('Location:' . APP__WWW . '/logout.php?msg=denied');
+    exit;
 }
 
-$uploadtype = $_REQUEST["rdoFileContentType"];
+$uploadtype = $_REQUEST['rdoFileContentType'];
 $filename = $_FILES['uploadedfile']['tmp_name'];
 
 //define variable we are using
 $user_warning = '';
 $user_msg = '';
 
-$filecontenttype[1] = array('screen'=>'<strong>Student Data</strong>',);
-$filecontenttype[2] = array('screen'=>'<strong>Staff Data</strong>',);
-$filecontenttype[3] = array('screen'=>'<strong>Module Data</strong>');
-$filecontenttype[4] = array('screen'=>'<strong>Student Data with Groups</strong>');
+$filecontenttype[1] = ['screen' => '<strong>Student Data</strong>'];
+$filecontenttype[2] = ['screen' => '<strong>Staff Data</strong>'];
+$filecontenttype[3] = ['screen' => '<strong>Module Data</strong>'];
+$filecontenttype[4] = ['screen' => '<strong>Student Data with Groups</strong>'];
 
-$expected_fields[1] = array(0=>'id_number', 'forename', 'lastname', 'email', 'username', 'password', 'department_id');
-$expected_fields[2] = array(0=>'id_number', 'forename', 'lastname', 'email', 'username', 'password', 'department_id');
-$expected_fields[3] = array(0=>'module_code', 'module_title');
-$expected_fields[4] = array(0=>'id_number', 'forename', 'lastname', 'email', 'username', 'password', 'department_id', 'group_name');
+$expected_fields[1] = [0 => 'id_number', 'forename', 'lastname', 'email', 'username', 'password', 'department_id'];
+$expected_fields[2] = [0 => 'id_number', 'forename', 'lastname', 'email', 'username', 'password', 'department_id'];
+$expected_fields[3] = [0 => 'module_code', 'module_title'];
+$expected_fields[4] = [0 => 'id_number', 'forename', 'lastname', 'email', 'username', 'password', 'department_id', 'group_name'];
 
 if ($_user->is_admin()) {
- $expected_fields[1][] = 'module_code';
- $expected_fields[2][] = 'module_code';
- $expected_fields[4][] = 'module_code';
+    $expected_fields[1][] = 'module_code';
+    $expected_fields[2][] = 'module_code';
+    $expected_fields[4][] = 'module_code';
 }
 $flg_match = false;
 
@@ -51,208 +52,245 @@
 ini_set('max_execution_time', 120);
 
 $row = 0;
-$fields = array();
-$final_rows = array();
-if (($handle = fopen($filename, "r")) !== FALSE) {
-  while (($data = fgetcsv($handle, 2000, ",")) !== FALSE) {
-    $num = count($data);
-
-    //if in the first row we should be getting the field names
-    //make them into an array
-    if ($row == 0) {
-      for ($c = 0; $c < $num; $c++) {
-        $fields[$c] = trim($data[$c]);
-      }
-
-      //check to see that we have the correct information in the array
-      if (array_diff($expected_fields[$uploadtype], $fields)) {
-
-        //we have diferences. We need to check to see if any of the key elements have matched
-        foreach ($expected_fields[$uploadtype] as $key_field) {
-          if (array_search($key_field, $fields) !== false) {
-            $flg_match = true;
-          }
+$fields = [];
+$final_rows = [];
+
+if (($handle = fopen($filename, 'r')) !== false) {
+    while (($data = fgetcsv($handle, 2000, ',')) !== false) {
+        $num = count($data);
+
+        //if in the first row we should be getting the field names
+        //make them into an array
+        if ($row == 0) {
+            for ($c = 0; $c < $num; $c++) {
+                $fields[$c] = trim($data[$c]);
+            }
+
+            //check to see that we have the correct information in the array
+            if (array_diff($expected_fields[$uploadtype], $fields)) {
+
+                //we have diferences. We need to check to see if any of the key elements have matched
+                foreach ($expected_fields[$uploadtype] as $key_field) {
+                    if (array_search($key_field, $fields) !== false) {
+                        $flg_match = true;
+                    }
+                }
+                if (!$flg_match) {
+                    for ($c = 0; $c < $num; $c++) {
+                        $final_rows[$row][$c] = trim($data[$c]);
+                        $fields[$c] = $c;
+                    }
+                    $row++;
+                }
+            } else {
+                $flg_match = true;
+            }
+        } else {
+            //build the associative array for the table entrys
+            for ($c = 0; $c < $num; $c++) {
+                $final_rows[$row - 1][$fields[$c]] = trim($data[$c]);
+            }
         }
-        if (!$flg_match) {
-          for ($c = 0; $c < $num; $c++) {
-            $final_rows[$row][$c] = trim($data[$c]);
-            $fields[$c] = $c;
-          }
-          $row++;
-        }
-
-      } else {
-        $flg_match = true;
-      }
-
-    } else {
-      //build the associative array for the table entrys
-      for ($c = 0; $c < $num; $c++) {
-        $final_rows[$row-1][$fields[$c]] = trim($data[$c]);
-      }
+        $row++;
     }
-    $row++;
-  }
-
-//now we have the information in arrays continue to process.
-  fclose($handle);
 
+    //now we have the information in arrays continue to process.
+    fclose($handle);
 }
 
 //check which array we are being given at this point (the one with the named fields or the other)
 if ($flg_match) {
-  //we can process this very easily into the database
+    //we can process this very easily into the database
+
+    //check to see if we have staff or student.
+    if (($uploadtype == '1') || ($uploadtype == '2') || ($uploadtype == '4')) {
+        //set the user type
+        if ($uploadtype == '2') {
+            $user_type = APP__USER_TYPE_TUTOR;
+        } else {
+            $user_type = APP__USER_TYPE_STUDENT;
+        }
 
-  //check to see if we have staff or student.
-  if (($uploadtype == '1') || ($uploadtype == '2') || ($uploadtype == '4')) {
+        $finalRowsCount = count($final_rows);
 
-    //set the user type
-    if ($uploadtype=='2') {
-      $user_type = APP__USER_TYPE_TUTOR;
-    } else {
-      $user_type = APP__USER_TYPE_STUDENT;
-    }
-    for ($counter = 0; $counter<count($final_rows); $counter++) {
-
-      //if there are passwords in the list, they will need to be MD5 hashed
-      if (!empty($final_rows[$counter]['password'])) {
-        $final_rows[$counter]['password'] = md5($final_rows[$counter]['password']);
-      } else {
-        $final_rows[$counter]['password'] = md5(StringFunctions::str_random());
-      }
-    }
-
-    $_module_id = Common::fetch_SESSION('_module_id', null);
-
-    if ($uploadtype == '4') {
-
-// get collection
-      $collection = new GroupCollection($DB);
-      $collection_id = null;
-      if (isset($_REQUEST['collectionlist'])) {
-        $collection_id = $_REQUEST['collectionlist'];
-      }
-      $modules = array();
-      if (empty($collection_id)) {
-        $collection_name = $_REQUEST['collection'];
-        if (!empty($collection_name)) {
-          $collection->create();
-          $collection->module_id = $_module_id;
-          $collection->name = $collection_name;
-          $collection->save();
-          $collection_id = $collection->id;
+        for ($counter = 0; $counter < $finalRowsCount; $counter++) {
+            // if there are passwords in the list, they will need to be hashed
+            if (!empty($final_rows[$counter]['password'])) {
+                $final_rows[$counter]['password'] = password_hash($final_rows[$counter]['password'], PASSWORD_DEFAULT);
+            } else {
+                $final_rows[$counter]['password'] = password_hash(StringFunctions::str_random(), PASSWORD_DEFAULT);
+            }
         }
-      } else {
-        $collection->load($collection_id);
-        $modules = $collection->get_modules();
-      }
-      $module_count = count($modules);
 
-    }
+        $_module_id = Common::fetch_SESSION('_module_id', null);
 
-    $fields = $expected_fields[$uploadtype];
-    foreach ($final_rows as $i) {
-
-      $module_code = '';
-      $group_name = '';
-      $els = array();
-      $els[] = "source_id = '{$_source_id}'";
-      for ($c = 0; $c < count($fields); $c++) {
-        $key = $fields[$c];
-        if (isset($i[$key])) {
-          $val = $i[$key];
-          if ($key == 'module_code') {
-            $module_code = $val;
-          } else if ($key == 'group_name') {
-            $group_name = $val;
-          } else {
-            $els[] = "$key = '" . $DB->escape_str($val) . '\'';
-          }
-        }
-      }
-      $sql = 'INSERT INTO ' . APP__DB_TABLE_PREFIX . 'user SET ' . implode(', ',$els) . ', admin = 0';
-      if ($_user->is_admin()) {
-        $sql .= ' ON DUPLICATE KEY UPDATE ' . implode(', ',$els);
-      }
-      $DB->execute($sql);
-      $id = $DB->get_insert_id();
-      if (!$id) {
-        $id = $DB->fetch_value('SELECT user_id FROM ' . APP__DB_TABLE_PREFIX . "user WHERE source_id = '{$_source_id}' AND username = '{$i['username']}'");
-      }
-
-      if ($_user->is_admin() && !empty($module_code)) {
-        $sql = "SELECT module_id FROM " . APP__DB_TABLE_PREFIX . "module WHERE source_id = '{$_source_id}' AND module_code = '$module_code'";
-        $module_id = $DB->fetch_value($sql);
-      } else {
-        $module_id = $_module_id;
-      }
-      if (!empty($module_id)) {
-        $sql = "INSERT INTO " . APP__DB_TABLE_PREFIX . "user_module SET user_id = {$id}, module_id = {$module_id}, user_type = '{$user_type}'";
-        $sql .= " ON DUPLICATE KEY UPDATE user_type = '{$user_type}'";
-        $DB->execute($sql);
-        if (!empty($collection_id) && !empty($group_name)) {
-          if (!in_array($module_id, $modules)) {
-            $modules[] = $module_id;
-          }
-          if (!$collection->group_exists($group_name)) {
-            $group = $collection->new_group($group_name);
-            $group->save();
-            $collection->refresh_groups();
-          }
-          $collection->add_member($id, $group_name);
-        }
-      }
+        if ($uploadtype == '4') {
+            // get collection
+            $collection = new GroupCollection($DB);
+            $collection_id = null;
 
-    }
+            if (isset($_REQUEST['collectionlist'])) {
+                $collection_id = $_REQUEST['collectionlist'];
+            }
 
-  } else {
-
-  //as we don't have staff or student then we must have "module"
-
-    $fields = $expected_fields[$uploadtype];
-    foreach($final_rows as $i) {
-
-    //build the SQL
-      $els = array();
-      $els[] = "source_id = '{$_source_id}'";
-      for ($c = 0; $c < count($fields); $c++) {
-        $key = $fields[$c];
-        $val = $i[$key];
-        $els[] = "$key = '" . $DB->escape_str($val) . '\'';
-      }
-      $sql = 'INSERT INTO ' . APP__DB_TABLE_PREFIX . 'module SET ' . implode(', ',$els);
-      $els = array();
-      for ($c = 0; $c < count($fields); $c++) {
-        $key = $fields[$c];
-        $val = $i[$key];
-        if ($key != 'module_code') {
-          $els[] = "$key = '" . $DB->escape_str($val) . '\'';
-        }
-      }
-      $sql .= ' ON DUPLICATE KEY UPDATE ' . implode(', ',$els);
-      $DB->execute($sql);
-    }
+            $modules = [];
 
-  }
+            if (empty($collection_id)) {
+                $collection_name = $_REQUEST['collection'];
+
+                if (!empty($collection_name)) {
+                    $collection->create();
+                    $collection->module_id = $_module_id;
+                    $collection->name = $collection_name;
+                    $collection->save();
+                    $collection_id = $collection->id;
+                }
+            } else {
+                $collection->load($collection_id);
+                $modules = $collection->get_modules();
+            }
+
+            $module_count = count($modules);
+        }
 
-  $user_msg = "<p>Successful upload of the {$filecontenttype[$uploadtype]['screen']} information to the database.</p>";
+        $fields = $expected_fields[$uploadtype];
+
+        foreach ($final_rows as $i) {
+            $module_code = $i['module_code'] ?? '';
+            $group_name = $i['group_name'] ?? '';
+
+            $insertUserQuery =
+                'INSERT INTO ' . APP__DB_TABLE_PREFIX . 'user ' .
+                '(id_number, forename, lastname, email, username, password, department_id, source_id, admin) ' .
+                'VALUES (?, ?, ?, ?, ?, ?, ?, ?, 0)';
+
+            if ($_user->is_admin()) {
+                $insertUserQuery .=
+                   ' ON DUPLICATE KEY UPDATE ' .
+                   'id_number = ?, ' .
+                   'forename = ?, ' .
+                   'lastname = ?, ' .
+                   'email = ?, ' .
+                   'username = ?, ' .
+                   'password = ?, ' .
+                   'department_id = ?, ' .
+                   'source_id = ? ';
+            }
+
+            $stmt = $DB->getConnection()->prepare($insertUserQuery);
+
+            $stmt->bindValue(1, $i['id_number']);
+            $stmt->bindValue(2, $i['forename']);
+            $stmt->bindValue(3, $i['lastname']);
+            $stmt->bindValue(4, $i['email']);
+            $stmt->bindValue(5, $i['username']);
+            $stmt->bindValue(6, $i['password']);
+            $stmt->bindValue(7, $i['department_id']);
+            $stmt->bindValue(8, $_source_id);
+
+            if ($_user->is_admin()) {
+                $stmt->bindValue(9, $i['id_number']);
+                $stmt->bindValue(10, $i['forename']);
+                $stmt->bindValue(11, $i['lastname']);
+                $stmt->bindValue(12, $i['email']);
+                $stmt->bindValue(13, $i['username']);
+                $stmt->bindValue(14, $i['password']);
+                $stmt->bindValue(15, $i['department_id']);
+                $stmt->bindValue(16, $_source_id);
+            }
+
+            $stmt->execute();
+
+            $id = $DB->getConnection()->lastInsertId();
+
+            if (!$id) {
+                $getUserIdQuery =
+                    'SELECT user_id ' .
+                    'FROM ' . APP__DB_TABLE_PREFIX . 'user ' .
+                    'WHERE source_id = ? ' .
+                    'AND username = ?';
+
+                $id = $DB->getConnection()->fetchOne($getUserIdQuery, [$_source_id, $i['username']], [ParameterType::STRING, ParameterType::STRING]);
+            }
+
+            if ($_user->is_admin() && !empty($module_code)) {
+                $sql =
+                    'SELECT module_id ' .
+                    'FROM ' . APP__DB_TABLE_PREFIX . 'module ' .
+                    'WHERE source_id = ? ' .
+                    'AND module_code = ?';
+
+                $module_id = $DB->getConnection()->fetchOne($sql, [$_source_id, $module_code], [ParameterType::STRING, ParameterType::STRING]);
+            } else {
+                $module_id = $_module_id;
+            }
+            if (!empty($module_id)) {
+                $insertUserModuleQuery =
+                    'INSERT INTO ' . APP__DB_TABLE_PREFIX . 'user_module ' .
+                    'VALUES (?, ?, ?) ' .
+                    'ON DUPLICATE KEY UPDATE user_type = ?';
+
+                $DB->getConnection()->executeQuery(
+                    $insertUserModuleQuery,
+                    [$id, $module_id, $user_type, $user_type],
+                    [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING, ParameterType::STRING]
+                );
+
+                if (!empty($collection_id) && !empty($group_name)) {
+                    if (!in_array($module_id, $modules)) {
+                        $modules[] = $module_id;
+                    }
+                    if (!$collection->group_exists($group_name)) {
+                        $group = $collection->new_group($group_name);
+                        $group->save();
+                        $collection->refresh_groups();
+                    }
+                    $collection->add_member($id, $group_name);
+                }
+            }
+        }
+    } else {
+        // as we don't have staff or student then we must have "module"
+        $fields = $expected_fields[$uploadtype];
+
+        foreach ($final_rows as $i) {
+            $insertModuleQuery =
+                'INSERT INTO ' . APP__DB_TABLE_PREFIX . 'module ' .
+                '(module_code, module_title, source_id) ' .
+                'VALUES (?, ? , ?) ' .
+                'ON DUPLICATE KEY UPDATE ' .
+                'module_title = ?, ' .
+                'source_id = ?';
+
+            $stmt = $DB->getConnection()->prepare($insertModuleQuery);
+
+            $stmt->bindValue(1, $i['module_code']);
+            $stmt->bindValue(2, $i['module_title']);
+            $stmt->bindValue(3, $_source_id);
+            $stmt->bindValue(4, $i['module_title']);
+            $stmt->bindValue(5, $_source_id);
+
+            $stmt->execute();
+        }
+    }
 
+    $user_msg = "<p>Successful upload of the {$filecontenttype[$uploadtype]['screen']} information to the database.</p>";
 } else {
-  //we want to notify that the information is not structured as expected therefore bounce back to the user
-  $user_warning .= "The information supplied cannot be processed.</div><div><p>We suggest that you review the information to be uploaded and they <a href=\"../\">try again</a>. Alternatively you may wish to download a template to put the information in.</p>";
+    //we want to notify that the information is not structured as expected therefore bounce back to the user
+    $user_warning .= 'The information supplied cannot be processed.</div><div><p>We suggest that you review the information to be uploaded and they <a href="../">try again</a>. Alternatively you may wish to download a template to put the information in.</p>';
 }
 
 //write to screen the page information
 //set the page information
 $UI->page_title = APP__NAME;
 $UI->menu_selected = 'upload data';
-$UI->breadcrumbs = array ('home' => null);
+$UI->breadcrumbs = ['home' => null];
 $UI->help_link = '?q=node/237';
 $UI->set_page_bar_button('View Student Data', '../../../images/buttons/button_student_user.png', '../review/student/index.php');
 $UI->set_page_bar_button('View Staff Data', '../../../images/buttons/button_staff_user.png', '../review/staff/index.php');
 if (Common::check_user($_user, APP__USER_TYPE_ADMIN)) {
-  $UI->set_page_bar_button('View Admin Data', '../../../images/buttons/button_admin_user.png', '../review/admin/index.php');
-  $UI->set_page_bar_button('View Module Data', '../../../images/buttons/button_view_modules.png', '../review/module/index.php');
+    $UI->set_page_bar_button('View Admin Data', '../../../images/buttons/button_admin_user.png', '../review/admin/index.php');
+    $UI->set_page_bar_button('View Module Data', '../../../images/buttons/button_view_modules.png', '../review/module/index.php');
 }
 $UI->set_page_bar_button('Search for a user', '../../../images/buttons/button_search_user.png', '../review/search/index.php');
 
@@ -261,9 +299,13 @@
 $UI->content_start();
 ?>
 <div class="content_box">
-<?php if(!empty($user_warning)){echo "<div class=\"warning_box\">{$user_warning}</div>";}?>
+    <?php if (!empty($user_warning)) {
+    echo "<div class=\"warning_box\">{$user_warning}</div>";
+} ?>
 
-<?php if(!empty($user_msg)){echo $user_msg;}?>
+    <?php if (!empty($user_msg)) {
+    echo $user_msg;
+} ?>
 
 </div>
 
@@ -271,5 +313,3 @@
 <?php
 
 $UI->content_end();
-
-?>
diff --git a/src/admin/load/templates.php b/src/admin/load/templates.php
index c467c57..33d9318 100644
--- a/src/admin/load/templates.php
+++ b/src/admin/load/templates.php
@@ -10,21 +10,21 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../includes/inc_global.php");
+require_once '../../includes/inc_global.php';
 
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 //write to screen the page information
 //set the page information
-$UI->page_title = APP__NAME ." Upload templates";
+$UI->page_title = APP__NAME .' Upload templates';
 $UI->menu_selected = 'upload data';
-$UI->breadcrumbs = array ('home' => '../../',
-              'Upload'=>'../');
+$UI->breadcrumbs = ['home' => '../../',
+              'Upload'=>'../', ];
 $UI->help_link = '?q=node/237';
 
 $UI->head();
@@ -32,9 +32,9 @@
 $UI->content_start();
 
 if ($_user->is_admin()) {
-  $usersfile = 'users_a.csv';
+    $usersfile = 'users_a.csv';
 } else {
-  $usersfile = 'users.csv';
+    $usersfile = 'users.csv';
 }
 ?>
 <div class="content_box">
diff --git a/src/admin/metrics/index.php b/src/admin/metrics/index.php
index b181426..60b32aa 100644
--- a/src/admin/metrics/index.php
+++ b/src/admin/metrics/index.php
@@ -12,23 +12,23 @@
  */
 
 //get the include file required
-require_once("../../includes/inc_global.php");
+require_once '../../includes/inc_global.php';
 
-use WebPA\includes\functions\Common;
 use WebPA\includes\functions\AcademicYear;
+use WebPA\includes\functions\Common;
 
 if (!Common::check_user($_user, APP__USER_TYPE_ADMIN)) {
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
-$intro_text = "<p>This page allows you to build a report on commonly requested metrics about the WebPA systems usage.</p>";
-$task_text = "<p>Please tick all the boxes for the information that you would like to have in your report. Then click the generate button to view the report.</p>";
+$intro_text = '<p>This page allows you to build a report on commonly requested metrics about the WebPA systems usage.</p>';
+$task_text = '<p>Please tick all the boxes for the information that you would like to have in your report. Then click the generate button to view the report.</p>';
 
 //set the page information
-$UI->page_title = APP__NAME . " metrics of use";
+$UI->page_title = APP__NAME . ' metrics of use';
 $UI->menu_selected = 'metrics';
-$UI->breadcrumbs = array ('home' => '../../');
+$UI->breadcrumbs = ['home' => '../../'];
 $UI->help_link = '?q=node/237';
 $UI->head();
 ?>
@@ -46,7 +46,7 @@
 $UI->content_start();
 
 echo $intro_text;
-echo "<div class=\"content_box\">";
+echo '<div class="content_box">';
 echo $task_text;
 
 //write a list of the elements that can be selected for the report
@@ -59,12 +59,12 @@
   <select name="academic_year" id="academic_year">
 <?php
 for ($i = $years[0]; $i <= $years[1]; $i++) {
-  $selected_str = ($i == $year) ? 'selected="selected"' : '';
-  echo("<option value=\"$i\" $selected_str>". $i);
-  if (APP__ACADEMIC_YEAR_START_MONTH > 1) {
-    echo('/' . substr($i + 1, 2, 2));
-  }
-  echo ('</option>');
+    $selected_str = ($i == $year) ? 'selected="selected"' : '';
+    echo "<option value=\"$i\" $selected_str>". $i;
+    if (APP__ACADEMIC_YEAR_START_MONTH > 1) {
+        echo '/' . substr($i + 1, 2, 2);
+    }
+    echo '</option>';
 }
 ?>
   </select>
diff --git a/src/admin/metrics/report.php b/src/admin/metrics/report.php
index bc56c93..551725e 100644
--- a/src/admin/metrics/report.php
+++ b/src/admin/metrics/report.php
@@ -13,14 +13,14 @@
  */
 
 //get the include file required
-require_once("../../includes/inc_global.php");
+require_once '../../includes/inc_global.php';
 
-use WebPA\includes\functions\Common;
 use WebPA\includes\functions\AcademicYear;
+use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_ADMIN)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_ADMIN)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 $year = (int) Common::fetch_POST('academic_year', Common::fetch_SESSION('year', AcademicYear::get_academic_year()));
@@ -28,12 +28,12 @@
 
 $academic_year = strval($year);
 if (APP__ACADEMIC_YEAR_START_MONTH > 1) {
-  $academic_year .= '/' . substr($year + 1, 2, 2);
+    $academic_year .= '/' . substr($year + 1, 2, 2);
 }
 
 $this_year = '-';
 if (APP__ACADEMIC_YEAR_START_MONTH <= 10) {
-  $this_year .= '0';
+    $this_year .= '0';
 }
 $this_year .= APP__ACADEMIC_YEAR_START_MONTH . '-01 00:00:00';
 $next_year = strval($year + 1) . $this_year;
@@ -57,804 +57,919 @@
 
 $this_accademic_year = AcademicYear::get_academic_year() . '-';
 if (APP__ACADEMIC_YEAR_START_MONTH <= 10) {
-  $this_accademic_year .= '0';
+    $this_accademic_year .= '0';
 }
 $this_accademic_year .= APP__ACADEMIC_YEAR_START_MONTH . '-01 00:00:00';
 
 // formulate all the sql for the reports
 //assessments which have been run
-$run_assessments_SQL = 'SELECT a.assessment_name, m.module_code, m.module_title, a.open_date, a.close_date ' .
+$dbConn = $DB->getConnection();
+
+$runAssessmentsStmt = $dbConn->prepare(
+    'SELECT a.assessment_name, m.module_code, m.module_title, a.open_date, a.close_date ' .
    'FROM ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
    'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'module m ON a.module_id = m.module_id ' .
-   "WHERE m.source_id = '{$_source_id}' AND a.open_date >= '{$this_year}' AND a.open_date < '{$next_year}' " .
-   'ORDER BY a.close_date, a.open_date, a.assessment_name, a.assessment_id';
+   'WHERE m.source_id = ? AND a.open_date >= ? AND a.open_date < ? ' .
+   'ORDER BY a.close_date, a.open_date, a.assessment_name, a.assessment_id'
+);
+
+$runAssessmentsStmt->bindValue(1, $_source_id);
+$runAssessmentsStmt->bindValue(2, $this_year);
+$runAssessmentsStmt->bindValue(3, $next_year);
 
 //number of groups per assessment
-$run_groups_per_assessment_SQL = 'SELECT a.assessment_name, m.module_code, m.module_title, COUNT(g.group_id) as group_count ' .
+$runGroupsPerAssessmentStmt = $dbConn->prepare('SELECT a.assessment_name, m.module_code, m.module_title, COUNT(g.group_id) as group_count ' .
    'FROM ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
    'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'user_group g ON a.collection_id = g.collection_id ' .
    'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'module m ON a.module_id = m.module_id ' .
-   "WHERE m.source_id = '{$_source_id}' AND a.open_date >= '{$this_year}' AND a.open_date < '{$next_year}' " .
+   'WHERE m.source_id = ? AND a.open_date >= ? AND a.open_date < ? ' .
    'GROUP BY a.assessment_name, m.module_code, m.module_title ' .
-   'ORDER BY a.assessment_name';
+   'ORDER BY a.assessment_name');
+
+$runGroupsPerAssessmentStmt->bindValue(1, $_source_id);
+$runGroupsPerAssessmentStmt->bindValue(2, $this_year);
+$runGroupsPerAssessmentStmt->bindValue(3, $next_year);
 
 //number of students per assessment
-$run_students_per_assessment_SQL = 'SELECT a.assessment_name, m.module_code, m.module_title, COUNT(ugm.user_id) as student_count ' .
+$runStudentsPerAssessmentStmt = $dbConn->prepare('SELECT a.assessment_name, m.module_code, m.module_title, COUNT(ugm.user_id) as student_count ' .
    'FROM ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
    'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'user_group g ON a.collection_id = g.collection_id ' .
    'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'user_group_member ugm ON g.group_id = ugm.group_id ' .
    'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'module m ON a.module_id = m.module_id ' .
-   "WHERE m.source_id = '{$_source_id}' AND a.open_date >= '{$this_year}' AND a.open_date < '{$next_year}' " .
+   'WHERE m.source_id = ? AND a.open_date >= ? AND a.open_date < ? ' .
    'GROUP BY a.assessment_name, m.module_code, m.module_title ' .
-   'ORDER BY a.assessment_name, m.module_code';
+   'ORDER BY a.assessment_name, m.module_code');
+
+$runStudentsPerAssessmentStmt->bindValue(1, $_source_id);
+$runStudentsPerAssessmentStmt->bindValue(2, $this_year);
+$runStudentsPerAssessmentStmt->bindValue(3, $next_year);
 
 //assessments where feedback has been used
-$run_feedback_SQL = 'SELECT a.assessment_name, m.module_code, m.module_title ' .
+$runFeedbackStmt = $dbConn->prepare('SELECT a.assessment_name, m.module_code, m.module_title ' .
    'FROM ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
    'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'module m ON a.module_id = m.module_id ' .
-   "WHERE m.source_id = '{$_source_id}' AND a.open_date >= '{$this_year}' AND a.open_date < '{$next_year}' " .
+   'WHERE m.source_id = ? AND a.open_date >= ? AND a.open_date < ? ' .
    'AND a.allow_feedback = 1 ' .
-   'ORDER BY a.assessment_name, a.assessment_id';
+   'ORDER BY a.assessment_name, a.assessment_id');
+
+$runFeedbackStmt->bindValue(1, $_source_id);
+$runFeedbackStmt->bindValue(2, $this_year);
+$runFeedbackStmt->bindValue(3, $next_year);
+
 
 //number of respondents per assessment
-$run_respondents = 'SELECT a.assessment_name, m.module_code, m.module_title, COUNT(DISTINCT um.user_id) as response_count ' .
+$runRespondentsStmt = $dbConn->prepare('SELECT a.assessment_name, m.module_code, m.module_title, COUNT(DISTINCT um.user_id) as response_count ' .
    'FROM ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
    'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'user_mark um ON a.assessment_id=um.assessment_id ' .
    'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'module m ON a.module_id = m.module_id ' .
-   "WHERE m.source_id = '{$_source_id}' AND a.open_date >= '{$this_year}' AND a.open_date < '{$next_year}' " .
+   'WHERE m.source_id = ? AND a.open_date >= ? AND a.open_date < ? ' .
    'GROUP BY a.assessment_name, m.module_code, m.module_title ' .
-   'ORDER BY a.assessment_name, m.module_code';
+   'ORDER BY a.assessment_name, m.module_code');
+
+$runRespondentsStmt->bindValue(1, $_source_id);
+$runRespondentsStmt->bindValue(2, $this_year);
+$runRespondentsStmt->bindValue(3, $next_year);
 
 //who has run an assessment in the current academic year
-$run_modules_per_assessments_SQL = 'SELECT DISTINCT m.module_code, m.module_title ' .
+$runModulesPerAssessmentsStmt = $dbConn->prepare('SELECT DISTINCT m.module_code, m.module_title ' .
    'FROM ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
    'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'module m ON a.module_id = m.module_id ' .
-   "WHERE m.source_id = '{$_source_id}' AND a.open_date >= '{$this_year}' AND a.open_date < '{$next_year}' " .
-   'ORDER BY a.assessment_name, m.module_code';
+   'WHERE m.source_id = ? AND a.open_date >= ? AND a.open_date < ? ' .
+   'ORDER BY m.module_code');
+
+$runModulesPerAssessmentsStmt->bindValue(1, $_source_id);
+$runModulesPerAssessmentsStmt->bindValue(2, $this_year);
+$runModulesPerAssessmentsStmt->bindValue(3, $next_year);
 
 //number of students who has carried out an assessment this year
-$run_students_assessed_SQL = 'SELECT COUNT(DISTINCT ugm.user_id) as \'Total unique students assessed\' ' .
+$runStudentsAssessedStmt = $dbConn->prepare('SELECT COUNT(DISTINCT ugm.user_id) as \'Total unique students assessed\' ' .
    'FROM ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
    'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'user_group ug ON a.collection_id = ug.collection_id ' .
    'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'user_group_member ugm ON ug.group_id = ugm.group_id ' .
    'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'module m ON a.module_id = m.module_id ' .
-   "WHERE m.source_id = '{$_source_id}' AND a.open_date >= '{$this_year}' AND a.open_date < '{$next_year}'";
+   'WHERE m.source_id = ? AND a.open_date >= ? AND a.open_date < ?');
+
+$runStudentsAssessedStmt->bindValue(1, $_source_id);
+$runStudentsAssessedStmt->bindValue(2, $this_year);
+$runStudentsAssessedStmt->bindValue(3, $next_year);
 
 //-------------------------------------------------------
 //view on screen
-if($format == 'html') {
-  //set the page information
-  $UI->page_title = APP__NAME . " general usage report";
-  $UI->menu_selected = 'metrics';
-  $UI->breadcrumbs = array ('home' => '../../');
-  $UI->help_link = '?q=node/237';
-  $UI->head();
-  $UI->body();
-  $UI->content_start();
-
-  echo "<div class=\"content_box\">";
-
-  if (!empty($assessments_run)) {
-
-    $rs_assessments = $DB->fetch($run_assessments_SQL);
-
-    echo "<h2>Assessments run in WebPA ({$academic_year})</h2>";
-
-    if ($rs_assessments) {
-      echo "<table class=\"grid\">";
-      $icounter = 0;
-
-      //loop round the initial array
-      foreach ($rs_assessments as $assessment) {
-        if($icounter==0){
-          //get an array of the key to the $assessment array
-          $field_names = array_keys($assessment);
-
-          foreach($field_names as $row){
-            echo "<th>{$row}</th>";
-          }
-        }
-
-        echo "<tr>";
-        foreach($assessment as $row){
-          echo "<td>{$row}</td>";
+if ($format == 'html') {
+    //set the page information
+    $UI->page_title = APP__NAME . ' general usage report';
+    $UI->menu_selected = 'metrics';
+    $UI->breadcrumbs = ['home' => '../../'];
+    $UI->help_link = '?q=node/237';
+    $UI->head();
+    $UI->body();
+    $UI->content_start();
+
+    echo '<div class="content_box">';
+
+    if (!empty($assessments_run)) {
+        // This returns a Result object... what can we do with it?
+        $runAssessmentsResult = $runAssessmentsStmt->execute();
+
+        $rs_assessments = $runAssessmentsResult->fetchAllAssociative();
+
+        echo "<h2>Assessments run in WebPA ({$academic_year})</h2>";
+
+        if ($rs_assessments) {
+            echo '<table class="grid">';
+            $icounter = 0;
+
+            //loop round the initial array
+            foreach ($rs_assessments as $assessment) {
+                if ($icounter==0) {
+                    //get an array of the key to the $assessment array
+                    $field_names = array_keys($assessment);
+
+                    foreach ($field_names as $row) {
+                        echo "<th>{$row}</th>";
+                    }
+                }
+
+                echo '<tr>';
+                foreach ($assessment as $row) {
+                    echo "<td>{$row}</td>";
+                }
+                echo '</tr>';
+                $icounter ++;
+            }
+            echo '</table>';
+        } else {
+            echo '<p>None</p>';
         }
-        echo "</tr>";
-        $icounter ++;
-      }
-      echo "</table>";
-    } else {
-      echo '<p>None</p>';
     }
-  }
 
-  if(!empty($assessment_groups)){
-    $rs_groups = $DB->fetch($run_groups_per_assessment_SQL);
-    echo "<h2>Number of groups per assessment ({$academic_year})</h2>";
+    if (!empty($assessment_groups)) {
+        $runGroupsPerAssessmentResult = $runGroupsPerAssessmentStmt->execute();
 
-    if ($rs_groups) {
-      echo "<table class=\"grid\">";
+        $rs_groups = $runGroupsPerAssessmentResult->fetchAllAssociative();
 
-      $icounter = 0;
-      //loop round the initial array
-      foreach ($rs_groups as $groups) {
-        if($icounter==0){
-          $field_names = array_keys($groups);
+        echo "<h2>Number of groups per assessment ({$academic_year})</h2>";
 
-          foreach($field_names as $row){
-            echo "<th>{$row}</th>";
-          }
-        }
+        if ($rs_groups) {
+            echo '<table class="grid">';
 
-        echo "<tr>";
-        foreach ($groups as $row) {
-          echo "<td>{$row}</td>";
-        }
-        echo "</tr>";
-        $icounter ++;
-      }
-      echo "</table>";
-    } else {
-      echo '<p>None</p>';
-    }
-  }
-
-  if(!empty($assessment_students)){
-    $rs_students = $DB->fetch($run_students_per_assessment_SQL);
-    echo "<h2>Number of students per assessment ({$academic_year})</h2>";
-
-    if ($rs_students) {
-      echo "<table class=\"grid\">";
+            $icounter = 0;
+            //loop round the initial array
+            foreach ($rs_groups as $groups) {
+                if ($icounter==0) {
+                    $field_names = array_keys($groups);
 
-      $icounter = 0;
-      //loop round the initial array
-      foreach ($rs_students as $students) {
-        if($icounter==0){
-          $field_names = array_keys($students);
+                    foreach ($field_names as $row) {
+                        echo "<th>{$row}</th>";
+                    }
+                }
 
-          foreach ($field_names as $row) {
-            echo "<th>{$row}</th>";
-          }
+                echo '<tr>';
+                foreach ($groups as $row) {
+                    echo "<td>{$row}</td>";
+                }
+                echo '</tr>';
+                $icounter ++;
+            }
+            echo '</table>';
+        } else {
+            echo '<p>None</p>';
         }
-        echo "<tr>";
-        foreach ($students as $row) {
-          echo "<td>{$row}</td>";
-        }
-        echo "</tr>";
-        $icounter++;
-      }
-      echo "</table>";
-    } else {
-      echo '<p>None</p>';
     }
-  }
-  if(!empty($assessment_feedback)){
-    $rs_feedback = $DB->fetch($run_feedback_SQL);
-    echo "<h2>Assessments where feedback has been used ({$academic_year})</h2>";
-
-    if ($rs_feedback) {
-      echo "<table class=\"grid\">";
-
-      $icounter = 0;
 
-      //loop round the initial array
-      foreach($rs_feedback as $feedback){
-
-        if($icounter==0){
-          $field_names = array_keys($feedback);
-          foreach($field_names as $row){
-            echo"<th>{$row}</th>";
-          }
+    if (!empty($assessment_students)) {
+        $runStudentsPerAssessmentResult = $runStudentsPerAssessmentStmt->execute();
+
+        $rs_students = $runStudentsPerAssessmentResult->fetchAllAssociative();
+
+        echo "<h2>Number of students per assessment ({$academic_year})</h2>";
+
+        if ($rs_students) {
+            echo '<table class="grid">';
+
+            $icounter = 0;
+            //loop round the initial array
+            foreach ($rs_students as $students) {
+                if ($icounter==0) {
+                    $field_names = array_keys($students);
+
+                    foreach ($field_names as $row) {
+                        echo "<th>{$row}</th>";
+                    }
+                }
+                echo '<tr>';
+                foreach ($students as $row) {
+                    echo "<td>{$row}</td>";
+                }
+                echo '</tr>';
+                $icounter++;
+            }
+            echo '</table>';
+        } else {
+            echo '<p>None</p>';
         }
-
-        echo "<tr>";
-        foreach($feedback as $row){
-          echo "<td>{$row}</td>";
+    }
+    if (!empty($assessment_feedback)) {
+        $runFeedbackResult = $runFeedbackStmt->execute();
+
+        $rs_feedback = $runFeedbackResult->fetchAllAssociative();
+
+        echo "<h2>Assessments where feedback has been used ({$academic_year})</h2>";
+
+        if ($rs_feedback) {
+            echo '<table class="grid">';
+
+            $icounter = 0;
+
+            //loop round the initial array
+            foreach ($rs_feedback as $feedback) {
+                if ($icounter==0) {
+                    $field_names = array_keys($feedback);
+                    foreach ($field_names as $row) {
+                        echo"<th>{$row}</th>";
+                    }
+                }
+
+                echo '<tr>';
+                foreach ($feedback as $row) {
+                    echo "<td>{$row}</td>";
+                }
+                echo '</tr>';
+                $icounter++;
+            }
+            echo '</table>';
+        } else {
+            echo '<p>None</p>';
         }
-        echo "</tr>";
-        $icounter++;
-      }
-      echo "</table>";
-    } else {
-      echo '<p>None</p>';
     }
-  }
-
-  if(!empty($assessment_respondents)){
-    $rs_respondents = $DB->fetch($run_respondents);
-    echo "<h2>Number of Respondents per assessment ({$academic_year})</h2>";
-
-    if ($rs_respondents) {
-      echo "<table class=\"grid\">";
 
-      $icounter=0;
-      //loop round the initial array
-      foreach($rs_respondents as $responses){
-
-        if($icounter == 0){
-          $field_names = array_keys($responses);
-          foreach($field_names as $row){
-            echo"<th>{$row}</th>";
-          }
+    if (!empty($assessment_respondents)) {
+        $runRespondentsResult = $runRespondentsStmt->execute();
+
+        $rs_respondents = $runRespondentsResult->fetchAllAssociative();
+
+        echo "<h2>Number of Respondents per assessment ({$academic_year})</h2>";
+
+        if ($rs_respondents) {
+            echo '<table class="grid">';
+
+            $icounter=0;
+            //loop round the initial array
+            foreach ($rs_respondents as $responses) {
+                if ($icounter == 0) {
+                    $field_names = array_keys($responses);
+                    foreach ($field_names as $row) {
+                        echo"<th>{$row}</th>";
+                    }
+                }
+
+                echo '<tr>';
+                foreach ($responses as $row) {
+                    echo "<td>{$row}</td>";
+                }
+                echo '</tr>';
+                $icounter++;
+            }
+            echo '</table>';
+        } else {
+            echo '<p>None</p>';
         }
+    }
 
-        echo "<tr>";
-        foreach($responses as $row){
-          echo "<td>{$row}</td>";
+    if (!empty($assessment_modules)) {
+        $runModulesPerAssessmentsResult = $runModulesPerAssessmentsStmt->execute();
+
+        $rs_runners = $runModulesPerAssessmentsResult->fetchAllAssociative();
+
+        echo "<h2>Modules which have run an assessment ({$academic_year})</h2>";
+
+        if ($rs_runners) {
+            echo '<table class="grid">';
+
+            $icounter = 0;
+            //loop round the initial array
+            foreach ($rs_runners as $runner) {
+                if ($icounter==0) {
+                    $field_names = array_keys($runner);
+                    foreach ($field_names as $row) {
+                        echo "<th>{$row}</th>";
+                    }
+                }
+
+                echo '<tr>';
+                foreach ($runner as $row) {
+                    echo "<td>{$row}</td>";
+                }
+                echo '</tr>';
+                $icounter++;
+            }
+            echo '</table>';
+        } else {
+            echo '<p>None</p>';
         }
-        echo "</tr>";
-        $icounter++;
-      }
-      echo "</table>";
-    } else {
-      echo '<p>None</p>';
     }
-  }
 
-  if(!empty($assessment_modules)){
-    $rs_runners = $DB->fetch($run_modules_per_assessments_SQL);
-    echo "<h2>Modules which have run an assessment ({$academic_year})</h2>";
+    if (!empty($assessment_students_thisyear)) {
+        $runStudentsAssessedResult = $runStudentsAssessedStmt->execute();
 
-    if ($rs_runners) {
-      echo "<table class=\"grid\">";
+        $rs_students = $runStudentsAssessedResult->fetchAllAssociative();
 
-      $icounter = 0;
-      //loop round the initial array
-      foreach($rs_runners as $runner){
+        echo "<h2>Number of students who have carried out an assessment ({$academic_year})</h2>";
 
-        if($icounter==0){
-          $field_names = array_keys($runner);
-          foreach($field_names as $row){
-            echo "<th>{$row}</th>";
-          }
-        }
-
-        echo "<tr>";
-        foreach($runner as $row){
-          echo "<td>{$row}</td>";
-        }
-        echo "</tr>";
-        $icounter++;
-      }
-      echo "</table>";
-    } else {
-      echo '<p>None</p>';
-    }
-  }
-
-  if(!empty($assessment_students_thisyear)){
-    $rs_students = $DB->fetch($run_students_assessed_SQL);
-    echo "<h2>Number of students who have carried out an assessment ({$academic_year})</h2>";
-
-    if ($rs_students) {
-      echo "<table class=\"grid\">";
-      //loop round the initial array
-      foreach($rs_students as $student){
-        echo "<tr>";
-        foreach($student as $row){
-          echo "<td>{$row}</td>";
+        if ($rs_students) {
+            echo '<table class="grid">';
+            //loop round the initial array
+            foreach ($rs_students as $student) {
+                echo '<tr>';
+                foreach ($student as $row) {
+                    echo "<td>{$row}</td>";
+                }
+                echo '</tr>';
+            }
+            echo '</table>';
+        } else {
+            echo '<p>None</p>';
         }
-        echo "</tr>";
-      }
-      echo "</table>";
-    } else {
-      echo '<p>None</p>';
     }
-  }
 
-  echo "</div>";
-  $UI->content_end();
+    echo '</div>';
+    $UI->content_end();
 }
 
 //-------------------------------------------------------------------------------
 //output csv
 if ($format == 'csv') {
-    header("Content-Disposition: attachment; filename=\"metrics.csv\"");
+    header('Content-Disposition: attachment; filename="metrics.csv"');
     header('Content-Type: text/csv');
 
-    echo('"WebPA - Metrics report"'."\n");
-
-
-  if (!empty($assessments_run)){
-    $rs_assessments = $DB->fetch($run_assessments_SQL);
-    echo "\n\"Assessments run in WebPA ({$academic_year})\"\n";
-    if ($rs_assessments) {
-      $icounter = 0;
-      //loop round the initial array
-      foreach ($rs_assessments as $assessment) {
-        if ($icounter==0) {
-          //get an array of the key to the $assessment array
-          echo "\n";
-          $field_names = array_keys($assessment);
-          foreach ($field_names as $row) {
-            echo "\"{$row}\",";
-          }
-          echo "\n";
-        }
-        foreach ($assessment as $row) {
-          echo "\"{$row}\",";
+    echo '"WebPA - Metrics report"'."\n";
+
+
+    if (!empty($assessments_run)) {
+        $runAssessmentsResult = $runAssessmentsStmt->execute();
+
+        $rs_assessments = $runAssessmentsResult->fetchAllAssociative();
+
+        echo "\n\"Assessments run in WebPA ({$academic_year})\"\n";
+        if ($rs_assessments) {
+            $icounter = 0;
+            //loop round the initial array
+            foreach ($rs_assessments as $assessment) {
+                if ($icounter==0) {
+                    //get an array of the key to the $assessment array
+                    echo "\n";
+                    $field_names = array_keys($assessment);
+                    foreach ($field_names as $row) {
+                        echo "\"{$row}\",";
+                    }
+                    echo "\n";
+                }
+                foreach ($assessment as $row) {
+                    echo "\"{$row}\",";
+                }
+                echo "\n";
+                $icounter ++;
+            }
         }
-        echo "\n";
-        $icounter ++;
-      }
     }
 
-  }
-
-  if (!empty($assessment_groups)) {
-    $rs_groups = $DB->fetch($run_groups_per_assessment_SQL);
-    echo "\n\"Number of groups per assessment ({$academic_year})\"\n";
-    if ($rs_groups) {
-      $icounter = 0;
-      //loop round the initial array
-      foreach ($rs_groups as $groups) {
-        if ($icounter==0) {
-          echo "\n";
-          $field_names = array_keys($groups);
-          foreach ($field_names as $row) {
-            echo "\"{$row}\",";
-          }
-          echo "\n";
-        }
-        foreach ($groups as $row) {
-          echo "\"{$row}\",";
+    if (!empty($assessment_groups)) {
+        $runGroupsPerAssessmentResult = $runGroupsPerAssessmentStmt->execute();
+
+        $rs_groups = $runGroupsPerAssessmentResult->fetchAllAssociative();
+
+        echo "\n\"Number of groups per assessment ({$academic_year})\"\n";
+        if ($rs_groups) {
+            $icounter = 0;
+            //loop round the initial array
+            foreach ($rs_groups as $groups) {
+                if ($icounter==0) {
+                    echo "\n";
+                    $field_names = array_keys($groups);
+                    foreach ($field_names as $row) {
+                        echo "\"{$row}\",";
+                    }
+                    echo "\n";
+                }
+                foreach ($groups as $row) {
+                    echo "\"{$row}\",";
+                }
+                echo "\n";
+                $icounter ++;
+            }
         }
-        echo "\n";
-        $icounter ++;
-      }
     }
-  }
-
-  if (!empty($assessment_students)) {
-    $rs_students = $DB->fetch($run_students_per_assessment_SQL);
-    echo "\n\"Number of students per assessment ({$academic_year})\"\n";
-    if ($rs_students) {
-      $icounter = 0;
-      //loop round the initial array
-      foreach ($rs_students as $students) {
-        if ($icounter==0) {
-          echo "\n";
-          $field_names = array_keys($students);
-          foreach ($field_names as $row) {
-            echo "\"{$row}\",";
-          }
-          echo "\n";
-        }
-        foreach ($students as $row) {
-          echo "\"{$row}\",";
+
+    if (!empty($assessment_students)) {
+        $runStudentsPerAssessmentResult = $runStudentsPerAssessmentStmt->execute();
+
+        $rs_students = $runStudentsPerAssessmentResult->fetchAllAssociative();
+
+        echo "\n\"Number of students per assessment ({$academic_year})\"\n";
+        if ($rs_students) {
+            $icounter = 0;
+            //loop round the initial array
+            foreach ($rs_students as $students) {
+                if ($icounter==0) {
+                    echo "\n";
+                    $field_names = array_keys($students);
+                    foreach ($field_names as $row) {
+                        echo "\"{$row}\",";
+                    }
+                    echo "\n";
+                }
+                foreach ($students as $row) {
+                    echo "\"{$row}\",";
+                }
+                echo "\n";
+                $icounter++;
+            }
         }
-        echo "\n";
-        $icounter++;
-      }
     }
-  }
-
-  if (!empty($assessment_feedback)) {
-    $rs_feedback = $DB->fetch($run_feedback_SQL);
-    echo "\n\"Assessments where feedback has been used ({$academic_year})\"\n";
-    if ($rs_feedback) {
-      $icounter = 0;
-      //loop round the initial array
-      foreach ($rs_feedback as $feedback) {
-        if ($icounter==0) {
-          echo "\n";
-          $field_names = array_keys($feedback);
-          foreach ($field_names as $row) {
-            echo"\"{$row}\",";
-          }
-          echo "\n";
-        }
-        foreach ($feedback as $row) {
-          echo "\"{$row}\",";
+
+    if (!empty($assessment_feedback)) {
+        $runFeedbackResult = $runFeedbackStmt->execute;
+
+        $rs_feedback = $runFeedbackResult->fetchAllAssociative();
+
+        echo "\n\"Assessments where feedback has been used ({$academic_year})\"\n";
+        if ($rs_feedback) {
+            $icounter = 0;
+            //loop round the initial array
+            foreach ($rs_feedback as $feedback) {
+                if ($icounter==0) {
+                    echo "\n";
+                    $field_names = array_keys($feedback);
+                    foreach ($field_names as $row) {
+                        echo"\"{$row}\",";
+                    }
+                    echo "\n";
+                }
+                foreach ($feedback as $row) {
+                    echo "\"{$row}\",";
+                }
+                echo "\n";
+                $icounter++;
+            }
         }
-        echo "\n";
-        $icounter++;
-      }
     }
-  }
-
-  if (!empty($assessment_respondents)) {
-    $rs_respondents = $DB->fetch($run_respondents);
-    echo "\n\"Number of respondents per assessment ({$academic_year})\"\n";
-    if ($rs_respondents) {
-      $icounter=0;
-      //loop round the initial array
-      foreach ($rs_respondents as $responses) {
-        if ($icounter == 0) {
-          echo "\n";
-          $field_names = array_keys($responses);
-          foreach ($field_names as $row) {
-            echo"\"{$row}\",";
-          }
-          echo "\n";
-        }
-        foreach ($responses as $row) {
-          echo "\"{$row}\",";
+
+    if (!empty($assessment_respondents)) {
+        $runRespondentsResult = $runRespondentsStmt->execute();
+
+        $rs_respondents = $runRespondentsResult->fetchAllAssociative();
+
+        echo "\n\"Number of respondents per assessment ({$academic_year})\"\n";
+
+        if ($rs_respondents) {
+            $icounter=0;
+            //loop round the initial array
+            foreach ($rs_respondents as $responses) {
+                if ($icounter == 0) {
+                    echo "\n";
+                    $field_names = array_keys($responses);
+                    foreach ($field_names as $row) {
+                        echo"\"{$row}\",";
+                    }
+                    echo "\n";
+                }
+                foreach ($responses as $row) {
+                    echo "\"{$row}\",";
+                }
+                echo "\n";
+                $icounter++;
+            }
         }
-        echo "\n";
-        $icounter++;
-      }
     }
-  }
-
-  if (!empty($assessment_modules)) {
-    $rs_runners = $DB->fetch($run_modules_per_assessments_SQL);
-    echo "\n\"Modules which have run an assessment ({$academic_year})\"\n";
-    if ($rs_runners) {
-      $icounter = 0;
-      //loop round the initial array
-      foreach ($rs_runners as $runner) {
-        if ($icounter==0) {
-          echo "\n";
-          $field_names = array_keys($runner);
-          foreach ($field_names as $row) {
-            echo "\"{$row}\",";
-          }
-          echo "\n";
-        }
-        foreach ($runner as $row) {
-          echo "\"{$row}\",";
+
+    if (!empty($assessment_modules)) {
+        $runModulesPerAssessmentsResult = $runModulesPerAssessmentsStmt->execute();
+
+        $rs_runners = $runModulesPerAssessmentsResult->fetchAllAssociative();
+
+        echo "\n\"Modules which have run an assessment ({$academic_year})\"\n";
+
+        if ($rs_runners) {
+            $icounter = 0;
+            //loop round the initial array
+            foreach ($rs_runners as $runner) {
+                if ($icounter==0) {
+                    echo "\n";
+                    $field_names = array_keys($runner);
+                    foreach ($field_names as $row) {
+                        echo "\"{$row}\",";
+                    }
+                    echo "\n";
+                }
+                foreach ($runner as $row) {
+                    echo "\"{$row}\",";
+                }
+                echo "\n";
+                $icounter++;
+            }
         }
-        echo "\n";
-        $icounter++;
-      }
     }
-  }
-
-  if(!empty($assessment_students_thisyear)){
-    $rs_students = $DB->fetch($run_students_assessed_SQL);
-    echo "\n\"Number of students who have carried out an assessment ({$academic_year})\"\n";
-    if ($rs_students) {
-      //loop round the initial array
-      echo "\n";
-      foreach ($rs_students as $student) {
-        foreach ($student as $row) {
-          echo"\"{$row}\",";
+
+    if (!empty($assessment_students_thisyear)) {
+        $runStudentsAssessedResult = $runStudentsAssessedStmt->execute();
+
+        $rs_students = $runStudentsAssessedResult->fetchAllAssociative();
+        echo "\n\"Number of students who have carried out an assessment ({$academic_year})\"\n";
+        if ($rs_students) {
+            //loop round the initial array
+            echo "\n";
+            foreach ($rs_students as $student) {
+                foreach ($student as $row) {
+                    echo"\"{$row}\",";
+                }
+            }
+            echo"\n";
         }
-      }
-      echo"\n";
     }
-  }
 }
 
 //------------------------------------------------------------------------------------
 //export as rtf
-if ($format == 'rtf'){
-  header("Content-Disposition: attachment;filename=student_grades.rtf");
-  header("Content-Type: text/enriched\n");
-
-  echo('WebPA - Metrics report'."\n\n");
-
-  if (!empty($assessments_run)){
-    $rs_assessments = $DB->fetch($run_assessments_SQL);
-    echo "\nAssessments run in WebPA ({$academic_year})\n\n";
-    $icounter = 0;
-    //loop round the initial array
-    foreach($rs_assessments as $assessment ){
-      if($icounter==0){
-        //get an array of the key to the $assessment array
-        $field_names = array_keys($assessment);
-        foreach($field_names as $row){
-          echo " {$row}  ";
+if ($format == 'rtf') {
+    header('Content-Disposition: attachment;filename=student_grades.rtf');
+    header("Content-Type: text/enriched\n");
+
+    echo 'WebPA - Metrics report'."\n\n";
+
+    if (!empty($assessments_run)) {
+        $runAssessmentsResult = $runAssessmentsStmt->execute();
+
+        $rs_assessments = $runAssessmentsResult->fetchAllAssociative();
+
+        echo "\nAssessments run in WebPA ({$academic_year})\n\n";
+        $icounter = 0;
+        //loop round the initial array
+        foreach ($rs_assessments as $assessment) {
+            if ($icounter==0) {
+                //get an array of the key to the $assessment array
+                $field_names = array_keys($assessment);
+                foreach ($field_names as $row) {
+                    echo " {$row}  ";
+                }
+            }
+            echo "\n";
+            foreach ($assessment as $row) {
+                echo " {$row}  ";
+            }
+            $icounter ++;
         }
-      }
-      echo "\n";
-      foreach($assessment as $row){
-        echo " {$row}  ";
-      }
-      $icounter ++;
     }
 
-  }
-
-  if(!empty($assessment_groups)){
-    $rs_groups = $DB->fetch($run_groups_per_assessment_SQL);
-    echo "\nNumber of groups per assessment ({$academic_year})\n\n";
-    if ($rs_groups) {
-      $icounter = 0;
-      //loop round the initial array
-      foreach($rs_groups as $groups){
-        if($icounter==0){
-          $field_names = array_keys($groups);
-          foreach($field_names as $row){
-            echo " {$row}  ";
-          }
-        }
-        echo "\n";
-        foreach($groups as $row){
-          echo " {$row}  ";
+    if (!empty($assessment_groups)) {
+        $runGroupsPerAssessmentResult = $runGroupsPerAssessmentStmt->execute();
+
+        $rs_groups = $runGroupsPerAssessmentResult->fetchAllAssociative();
+
+        echo "\nNumber of groups per assessment ({$academic_year})\n\n";
+
+        if ($rs_groups) {
+            $icounter = 0;
+            //loop round the initial array
+            foreach ($rs_groups as $groups) {
+                if ($icounter==0) {
+                    $field_names = array_keys($groups);
+                    foreach ($field_names as $row) {
+                        echo " {$row}  ";
+                    }
+                }
+                echo "\n";
+                foreach ($groups as $row) {
+                    echo " {$row}  ";
+                }
+                $icounter ++;
+            }
         }
-        $icounter ++;
-      }
     }
-  }
-
-  if(!empty($assessment_students)){
-    $rs_students = $DB->fetch($run_students_per_assessment_SQL);
-    echo "\nNumber of students per assessment ({$academic_year})\n\n";
-    if ($rs_students) {
-      $icounter = 0;
-      //loop round the initial array
-      foreach($rs_students as $students){
-        if($icounter==0){
-          $field_names = array_keys($students);
-          foreach($field_names as $row){
-            echo " {$row}  ";
-          }
-        }
-        echo "\n";
-        foreach($students as $row){
-          echo " {$row}  ";
+
+    if (!empty($assessment_students)) {
+        $runStudentsPerAssessmentResult = $runStudentsPerAssessmentStmt->execute();
+
+        $rs_students = $runStudentsPerAssessmentResult->fetchAllAssociative();
+
+        echo "\nNumber of students per assessment ({$academic_year})\n\n";
+        if ($rs_students) {
+            $icounter = 0;
+            //loop round the initial array
+            foreach ($rs_students as $students) {
+                if ($icounter==0) {
+                    $field_names = array_keys($students);
+                    foreach ($field_names as $row) {
+                        echo " {$row}  ";
+                    }
+                }
+                echo "\n";
+                foreach ($students as $row) {
+                    echo " {$row}  ";
+                }
+                echo "\n";
+                $icounter++;
+            }
         }
-        echo "\n";
-        $icounter++;
-      }
     }
-  }
-
-  if(!empty($assessment_feedback)){
-    $rs_feedback = $DB->fetch($run_feedback_SQL);
-    echo "\nAssessments where feedback has been used ({$academic_year})\n\n";
-    if ($rs_feedback) {
-      $icounter = 0;
-      //loop round the initial array
-      foreach($rs_feedback as $feedback){
-        if($icounter==0){
-          $field_names = array_keys($feedback);
-          foreach($field_names as $row){
-            echo"{$row}  ";
-          }
-        }
-        echo "\n";
-        foreach($feedback as $row){
-          echo "{$row}  ";
+
+    if (!empty($assessment_feedback)) {
+        $runFeedbackResult = $runFeedbackStmt->execute;
+
+        $rs_feedback = $runFeedbackResult->fetchAllAssociative();
+
+        echo "\nAssessments where feedback has been used ({$academic_year})\n\n";
+        if ($rs_feedback) {
+            $icounter = 0;
+            //loop round the initial array
+            foreach ($rs_feedback as $feedback) {
+                if ($icounter==0) {
+                    $field_names = array_keys($feedback);
+                    foreach ($field_names as $row) {
+                        echo"{$row}  ";
+                    }
+                }
+                echo "\n";
+                foreach ($feedback as $row) {
+                    echo "{$row}  ";
+                }
+                echo "\n";
+                $icounter++;
+            }
         }
-        echo "\n";
-        $icounter++;
-      }
     }
-  }
-
-  if(!empty($assessment_respondents)){
-    $rs_respondents = $DB->fetch($run_respondents);
-    echo "\nNumber of Respondents per assessment ({$academic_year})\n\n";
-    if ($rs_respondents) {
-      $icounter=0;
-      //loop round the initial array
-      foreach($rs_respondents as $responses){
-        if($icounter == 0){
-          $field_names = array_keys($responses);
-          foreach($field_names as $row){
-            echo"{$row}  ";
-          }
-        }
-        echo "\n";
-        foreach($responses as $row){
-          echo "{$row}  ";
+
+    if (!empty($assessment_respondents)) {
+        $runRespondentsResult = $runRespondentsStmt->execute();
+
+        $rs_respondents = $runRespondentsResult->fetchAllAssociative();
+
+        echo "\nNumber of Respondents per assessment ({$academic_year})\n\n";
+
+        if ($rs_respondents) {
+            $icounter=0;
+            //loop round the initial array
+            foreach ($rs_respondents as $responses) {
+                if ($icounter == 0) {
+                    $field_names = array_keys($responses);
+                    foreach ($field_names as $row) {
+                        echo"{$row}  ";
+                    }
+                }
+                echo "\n";
+                foreach ($responses as $row) {
+                    echo "{$row}  ";
+                }
+                echo "\n";
+                $icounter++;
+            }
         }
-        echo "\n";
-        $icounter++;
-      }
     }
-  }
-
-  if(!empty($assessment_modules)){
-    $rs_runners = $DB->fetch($run_modules_per_assessments_SQL);
-    echo "\nModules which have run an assessment ({$academic_year})\n\n";
-    if ($rs_runners) {
-      $icounter = 0;
-      //loop round the initial array
-      foreach($rs_runners as $runner){
-        if($icounter==0){
-          $field_names = array_keys($runner);
-          foreach($field_names as $row){
-            echo "{$row}  ";
-          }
-        }
-        echo "\n";
-        foreach($runner as $row){
-          echo "{$row}  ";
+
+    if (!empty($assessment_modules)) {
+        $runModulesPerAssessmentsResult = $runModulesPerAssessmentsStmt->execute();
+
+        $rs_runners = $runModulesPerAssessmentsResult->fetchAllAssociative();
+
+        echo "\nModules which have run an assessment ({$academic_year})\n\n";
+
+        if ($rs_runners) {
+            $icounter = 0;
+            //loop round the initial array
+            foreach ($rs_runners as $runner) {
+                if ($icounter==0) {
+                    $field_names = array_keys($runner);
+                    foreach ($field_names as $row) {
+                        echo "{$row}  ";
+                    }
+                }
+                echo "\n";
+                foreach ($runner as $row) {
+                    echo "{$row}  ";
+                }
+                echo "\n";
+                $icounter++;
+            }
         }
-        echo "\n";
-        $icounter++;
-      }
     }
-  }
-
-  if(!empty($assessment_students_thisyear)){
-    $rs_students = $DB->fetch($run_students_assessed_SQL);
-    echo "\nNumber of students who have carried out an assessment ({$academic_year})\n\n";
-    if ($rs_students) {
-      //loop round the initial array
-      foreach($rs_students as $student){
-        foreach($student as $row){
-          echo"{$row}  ";
+
+    if (!empty($assessment_students_thisyear)) {
+        $runStudentsAssessedResult = $runStudentsAssessedStmt->execute();
+
+        $rs_students = $runStudentsAssessedResult->fetchAllAssociative();
+
+        echo "\nNumber of students who have carried out an assessment ({$academic_year})\n\n";
+        if ($rs_students) {
+            //loop round the initial array
+            foreach ($rs_students as $student) {
+                foreach ($student as $row) {
+                    echo"{$row}  ";
+                }
+            }
+            echo"\n";
         }
-      }
-      echo"\n";
     }
-  }
 }
 
 //------------------------------------------------------------------------------------
 //export as xml
-if ($format == 'xml'){
-  header("Content-Disposition: attachment; file=\"webpa_metrics.xml\"");
-  header('Content-Type: text/xml');
-
-  echo("<?xml version=\"1.0\" ?> ");
-  echo"<metrics_report>";
-
-  if (!empty($assessments_run)){
-    $rs_assessments = $DB->fetch($run_assessments_SQL);
-    echo "<metrics>";
-    echo "<description>Assessments run in WebPA ({$academic_year})</description>";
-    if ($rs_assessments) {
-      //loop round the initial array
-      foreach($rs_assessments as $assessment ){
-        //get an array of the key to the $assessment array
-        $field_names = array_keys($assessment);
-        $field_content = array_values($assessment);
-
-        //get the number of elements in the arrays
-        $array_count = count($field_names);
-        echo "<metric>";
-        for ($count=0; $count<$array_count; $count++){
-          echo "<field_{$count}>{$field_names[$count]}</field_{$count}>";
-          echo "<value_{$count}>{$field_content[$count]}</value_{$count}>";
-        }
-        echo "</metric>";
-      }
+if ($format == 'xml') {
+    header('Content-Disposition: attachment; file="webpa_metrics.xml"');
+    header('Content-Type: text/xml');
+
+    echo '<?xml version="1.0" ?> ';
+    echo'<metrics_report>';
+
+    if (!empty($assessments_run)) {
+        $runAssessmentsResult = $runAssessmentsStmt->execute();
+
+        $rs_assessments = $runAssessmentsResult->fetchAllAssociative();
+
+        echo '<metrics>';
+        echo "<description>Assessments run in WebPA ({$academic_year})</description>";
+        if ($rs_assessments) {
+            //loop round the initial array
+            foreach ($rs_assessments as $assessment) {
+                //get an array of the key to the $assessment array
+                $field_names = array_keys($assessment);
+                $field_content = array_values($assessment);
+
+                //get the number of elements in the arrays
+                $array_count = count($field_names);
+                echo '<metric>';
+                for ($count=0; $count<$array_count; $count++) {
+                    echo "<field_{$count}>{$field_names[$count]}</field_{$count}>";
+                    echo "<value_{$count}>{$field_content[$count]}</value_{$count}>";
+                }
+                echo '</metric>';
+            }
+        }
+        echo '</metrics>';
     }
-    echo "</metrics>";
-
-  }
-
-  if(!empty($assessment_groups)){
-    $rs_groups = $DB->fetch($run_groups_per_assessment_SQL);
-    echo "<metrics>";
-    echo "<description>Number of groups per assessment ({$academic_year})</description>";
-    if ($rs_groups) {
-      foreach($rs_groups as $groups ){
-        //get an array of the key to the $groups array
-        $field_names = array_keys($groups);
-        $field_content = array_values($groups);
-
-        //get the number of elements in the arrays
-        $array_count = count($field_names);
-        echo "<metric>";
-        for ($count=0; $count<$array_count; $count++){
-          echo "<field_{$count}>{$field_names[$count]}</field_{$count}>";
-          echo "<value_{$count}>{$field_content[$count]}</value_{$count}>";
-        }
-        echo "</metric>";
-      }
+
+    if (!empty($assessment_groups)) {
+        $runGroupsPerAssessmentResult = $runGroupsPerAssessmentStmt->execute();
+
+        $rs_groups = $runGroupsPerAssessmentResult->fetchAllAssociative();
+
+        echo '<metrics>';
+        echo "<description>Number of groups per assessment ({$academic_year})</description>";
+        if ($rs_groups) {
+            foreach ($rs_groups as $groups) {
+                //get an array of the key to the $groups array
+                $field_names = array_keys($groups);
+                $field_content = array_values($groups);
+
+                //get the number of elements in the arrays
+                $array_count = count($field_names);
+                echo '<metric>';
+                for ($count=0; $count<$array_count; $count++) {
+                    echo "<field_{$count}>{$field_names[$count]}</field_{$count}>";
+                    echo "<value_{$count}>{$field_content[$count]}</value_{$count}>";
+                }
+                echo '</metric>';
+            }
+        }
+        echo '</metrics>';
     }
-    echo "</metrics>";
-  }
-
-  if(!empty($assessment_students)){
-    $rs_students = $DB->fetch($run_students_per_assessment_SQL);
-    echo "<metrics>";
-    echo "<description>Number of students per assessment ({$academic_year})</description>";
-
-    if ($rs_students) {
-      //loop round the initial array
-      foreach($rs_students as $students){
-        //get an array of the key to the $students array
-        $field_names = array_keys($students);
-        $field_content = array_values($students);
-
-        //get the number of elements in the arrays
-        $array_count = count($field_names);
-        echo "<metric>";
-        for ($count=0; $count<$array_count; $count++){
-          echo "<field_{$count}>{$field_names[$count]}</field_{$count}>";
-          echo "<value_{$count}>{$field_content[$count]}</value_{$count}>";
+
+    if (!empty($assessment_students)) {
+        $runStudentsPerAssessmentResult = $runStudentsPerAssessmentStmt->execute();
+
+        $rs_students = $runStudentsPerAssessmentResult->fetchAllAssociative();
+
+        echo '<metrics>';
+        echo "<description>Number of students per assessment ({$academic_year})</description>";
+
+        if ($rs_students) {
+            //loop round the initial array
+            foreach ($rs_students as $students) {
+                //get an array of the key to the $students array
+                $field_names = array_keys($students);
+                $field_content = array_values($students);
+
+                //get the number of elements in the arrays
+                $array_count = count($field_names);
+                echo '<metric>';
+                for ($count=0; $count<$array_count; $count++) {
+                    echo "<field_{$count}>{$field_names[$count]}</field_{$count}>";
+                    echo "<value_{$count}>{$field_content[$count]}</value_{$count}>";
+                }
+                echo '</metric>';
+            }
         }
-        echo "</metric>";
-      }
+        echo '</metrics>';
     }
-    echo "</metrics>";
-  }
-
-  if(!empty($assessment_feedback)){
-    $rs_feedback = $DB->fetch($run_feedback_SQL);
-    echo "<metrics>";
-    echo "<description>Assessments where feedback has been used ({$academic_year})</description>";
-    if ($rs_feedback) {
-      //loop round the initial array
-      foreach($rs_feedback as $feedback){
-        //get an array of the key to the $feedback array
-        $field_names = array_keys($feedback);
-        $field_content = array_values($feedback);
-
-        //get the number of elements in the arrays
-        $array_count = count($field_names);
-        echo "<metric>";
-        for ($count=0; $count<$array_count; $count++){
-          echo "<field_{$count}>{$field_names[$count]}</field_{$count}>";
-          echo "<value_{$count}>{$field_content[$count]}</value_{$count}>";
-        }
-        echo "</metric>";
-      }
+
+    if (!empty($assessment_feedback)) {
+        $runFeedbackResult = $runFeedbackStmt->execute;
+
+        $rs_feedback = $$runFeedbackResult->fetchAllAssociative();
+
+        echo '<metrics>';
+        echo "<description>Assessments where feedback has been used ({$academic_year})</description>";
+        if ($rs_feedback) {
+            //loop round the initial array
+            foreach ($rs_feedback as $feedback) {
+                //get an array of the key to the $feedback array
+                $field_names = array_keys($feedback);
+                $field_content = array_values($feedback);
+
+                //get the number of elements in the arrays
+                $array_count = count($field_names);
+                echo '<metric>';
+                for ($count=0; $count<$array_count; $count++) {
+                    echo "<field_{$count}>{$field_names[$count]}</field_{$count}>";
+                    echo "<value_{$count}>{$field_content[$count]}</value_{$count}>";
+                }
+                echo '</metric>';
+            }
+        }
+        echo '</metrics>';
     }
-    echo "</metrics>";
-  }
-
-  if(!empty($assessment_respondents)){
-    $rs_respondents = $DB->fetch($run_respondents);
-    echo "<metrics>";
-    echo "<description>Number of Respondents per assessment ({$academic_year})</description>";
-    if ($rs_respondents) {
-      //loop round the initial array
-      foreach($rs_respondents as $responses){
-        //get an array of the key to the $responses array
-        $field_names = array_keys($responses);
-        $field_content = array_values($responses);
-
-        //get the number of elements in the arrays
-        $array_count = count($field_names);
-        echo "<metric>";
-        for ($count=0; $count<$array_count; $count++){
-          echo "<field_{$count}>{$field_names[$count]}</field_{$count}>";
-          echo "<value_{$count}>{$field_content[$count]}</value_{$count}>";
+
+    if (!empty($assessment_respondents)) {
+        $runRespondentsResult = $runRespondentsStmt->execute();
+
+        $rs_respondents = $runRespondentsResult->fetchAllAssociative();
+
+        echo '<metrics>';
+
+        echo "<description>Number of Respondents per assessment ({$academic_year})</description>";
+
+        if ($rs_respondents) {
+            //loop round the initial array
+            foreach ($rs_respondents as $responses) {
+                //get an array of the key to the $responses array
+                $field_names = array_keys($responses);
+                $field_content = array_values($responses);
+
+                //get the number of elements in the arrays
+                $array_count = count($field_names);
+                echo '<metric>';
+                for ($count=0; $count<$array_count; $count++) {
+                    echo "<field_{$count}>{$field_names[$count]}</field_{$count}>";
+                    echo "<value_{$count}>{$field_content[$count]}</value_{$count}>";
+                }
+                echo '</metric>';
+            }
         }
-        echo "</metric>";
-      }
+        echo '</metrics>';
     }
-    echo "</metrics>";
-  }
-
-  if(!empty($assessment_modules)){
-    $rs_runners = $DB->fetch($run_modules_per_assessments_SQL);
-    echo "<metrics>";
-    echo "<description>Modules which have run an assessment ({$academic_year})</description>";
-    if ($rs_runners) {
-      //loop round the initial array
-      foreach($rs_runners as $runner){
-        //get an array of the key to the $runner array
-        $field_names = array_keys($runner);
-        $field_content = array_values($runner);
-
-        //get the number of elements in the arrays
-        $array_count = count($field_names);
-        echo "<metric>";
-        for ($count=0; $count<$array_count; $count++){
-          echo "<field_{$count}>{$field_names[$count]}</field_{$count}>";
-          echo "<value_{$count}>{$field_content[$count]}</value_{$count}>";
+
+    if (!empty($assessment_modules)) {
+        $runModulesPerAssessmentsResult = $runModulesPerAssessmentsStmt->execute();
+
+        $rs_runners = $runModulesPerAssessmentsResult->fetchAllAssociative();
+
+        echo '<metrics>';
+        echo "<description>Modules which have run an assessment ({$academic_year})</description>";
+
+        if ($rs_runners) {
+            //loop round the initial array
+            foreach ($rs_runners as $runner) {
+                //get an array of the key to the $runner array
+                $field_names = array_keys($runner);
+                $field_content = array_values($runner);
+
+                //get the number of elements in the arrays
+                $array_count = count($field_names);
+                echo '<metric>';
+                for ($count=0; $count<$array_count; $count++) {
+                    echo "<field_{$count}>{$field_names[$count]}</field_{$count}>";
+                    echo "<value_{$count}>{$field_content[$count]}</value_{$count}>";
+                }
+                echo '</metric>';
+            }
         }
-        echo "</metric>";
-      }
+        echo '</metrics>';
     }
-    echo "</metrics>";
-  }
-
-  if(!empty($assessment_students_thisyear)){
-    $rs_students = $DB->fetch($run_students_assessed_SQL);
-    echo "<metrics>";
-    echo "<description>Number of students who have carried out an assessment ({$academic_year})</description>";
-    if ($rs_students) {
-      //loop round the initial array
-      foreach($rs_students as $student){
-        //get an array of the key to the $student array
-        $field_names = array_keys($student);
-        $field_content = array_values($student);
-
-        //get the number of elements in the arrays
-        $array_count = count($field_names);
-        echo "<metric>";
-        for ($count=0; $count<$array_count; $count++){
-          echo "<field_{$count}>{$field_names[$count]}</field_{$count}>";
-          echo "<value_{$count}>{$field_content[$count]}</value_{$count}>";
-        }
-        echo "</metric>";
-      }
+
+    if (!empty($assessment_students_thisyear)) {
+        $runStudentsAssessedResult = $runStudentsAssessedStmt->execute();
+
+        $rs_students = $runStudentsAssessedResult->fetchAllAssociative();
+
+        echo '<metrics>';
+        echo "<description>Number of students who have carried out an assessment ({$academic_year})</description>";
+        if ($rs_students) {
+            //loop round the initial array
+            foreach ($rs_students as $student) {
+                //get an array of the key to the $student array
+                $field_names = array_keys($student);
+                $field_content = array_values($student);
+
+                //get the number of elements in the arrays
+                $array_count = count($field_names);
+                echo '<metric>';
+                for ($count=0; $count<$array_count; $count++) {
+                    echo "<field_{$count}>{$field_names[$count]}</field_{$count}>";
+                    echo "<value_{$count}>{$field_content[$count]}</value_{$count}>";
+                }
+                echo '</metric>';
+            }
+        }
+        echo '</metrics>';
     }
-    echo "</metrics>";
-  }
 
-  echo"</metrics_report>";
+    echo'</metrics_report>';
 }
-
-?>
diff --git a/src/admin/review/admin/index.php b/src/admin/review/admin/index.php
index 94434d3..63ab41b 100644
--- a/src/admin/review/admin/index.php
+++ b/src/admin/review/admin/index.php
@@ -9,13 +9,13 @@
  */
 
 //get the include file required
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\functions\Common;
 
 if (!Common::check_user($_user, APP__USER_TYPE_ADMIN)) {
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 $table = 'user';
@@ -25,9 +25,9 @@
 
 
 //set the page information
-$UI->page_title = APP__NAME . " view administrator data";
+$UI->page_title = APP__NAME . ' view administrator data';
 $UI->menu_selected = 'view data';
-$UI->breadcrumbs = array ('home' => '../../','review data'=>'../', 'administrator information'=>null,);
+$UI->breadcrumbs = ['home' => '../../', 'review data'=>'../', 'administrator information'=>null];
 $UI->help_link = '?q=node/237';
 $UI->set_page_bar_button('View Student Data', '../../../../images/buttons/button_student_user.png', '../student/index.php');
 $UI->set_page_bar_button('View Staff Data', '../../../../images/buttons/button_staff_user.png', '../staff/index.php');
diff --git a/src/admin/review/all.php b/src/admin/review/all.php
index f69d08e..2cadb58 100644
--- a/src/admin/review/all.php
+++ b/src/admin/review/all.php
@@ -11,134 +11,145 @@
  * @link https://github.com/webpa/webpa
  */
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\functions\Common;
 
 //build the string for the information to be collected from the database
-if ($type == 'module') {
-  if (Common::check_user($_user, APP__USER_TYPE_ADMIN)) {
-    $query = 'SELECT module_id, module_code, module_title FROM '. APP__DB_TABLE_PREFIX . "module WHERE source_id = '{$_source_id}'";
-  }
-} else if ($type == APP__USER_TYPE_ADMIN) {
-  if (Common::check_user($_user, APP__USER_TYPE_ADMIN)) {
-    $query = 'SELECT u.user_id, u.source_id, u.username AS id, u.lastname, u.forename, u.email, u.id_number AS `id number`, u.date_last_login AS `last login` FROM ' .
-             APP__DB_TABLE_PREFIX . 'user u ' .
-             "WHERE (u.admin = 1) " .
-             'ORDER BY u.lastname, u.forename, u.source_id, u.username';
-  }
-} else if (Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
-  $_module_id = Common::fetch_SESSION('_module_id', null);
-  $query = 'SELECT u.user_id, u.source_id, u.username AS id, u.lastname, u.forename, u.email, u.id_number AS `id number`, u.date_last_login AS `last login` FROM ' .
-           APP__DB_TABLE_PREFIX . 'user u INNER JOIN ' . APP__DB_TABLE_PREFIX . 'user_module um ON u.user_id = um.user_id ' .
-           "WHERE (um.module_id = {$_module_id}) AND (um.user_type = '{$type}') " .  // AND (source_id = '{$_source_id}')";
-           'ORDER BY u.lastname, u.forename, u.source_id, u.username';
-}
-if (!isset($query)) {
-  echo ' <p>You need to be logged into the system to see this information.</p>';
-} else {
-  //run the query
-  $rs = $DB->fetch($query);
-
-  echo '<h2>' . $rstitle . '</h2>';
-  echo '<div class="obj">';
-  echo '<table class="obj" cellpadding="2" cellspacing="2">';
+$dbConn = $DB->getConnection();
 
-  //work through the recordset if it is not empty
-  for ($recordcounter = 0; $recordcounter < count($rs); $recordcounter++) {
+if ($type === 'module') {
+    if (Common::check_user($_user, APP__USER_TYPE_ADMIN)) {
+        $stmt = $dbConn->prepare('SELECT module_id, module_code, module_title FROM ' . APP__DB_TABLE_PREFIX . 'module WHERE source_id = ?');
 
-    if ($recordcounter == 0) {
-      //write the table field headers to the screen
-      echo '<tr>';
-      foreach ($rs[$recordcounter] as $field_name => $field_value){
-        if ($field_name == 'source_id') {
-        } else if (($field_name != 'user_id') && ($field_name != 'module_id')) {
-          echo "<th>{$field_name}</th>";
-        } else if (($type == 'module') || !$_source_id) {
-          echo "<th class=\"icon\">&nbsp;</th>";
-        }
-      }
-      echo "</tr>\n";
+        $stmt->bindParam(1, $_source_id);
     }
-    if (($type != 'module') && ($rs[$recordcounter]['source_id'] != $_user_source_id)) {
-      $style = ' style="background-color: #c0c0c0;"';
-    } else {
-      $style = '';
+} elseif ($type == APP__USER_TYPE_ADMIN) {
+    if (Common::check_user($_user, APP__USER_TYPE_ADMIN)) {
+        $stmt = $dbConn->prepare('SELECT u.user_id, u.source_id, u.username AS id, u.lastname, u.forename, u.email, u.id_number AS `id number`, u.date_last_login AS `last login` FROM ' .
+        APP__DB_TABLE_PREFIX . 'user u ' .
+        'WHERE u.admin = 1 ' .
+        'ORDER BY u.lastname, u.forename, u.source_id, u.username');
     }
-    echo "<tr{$style}>";
-    $consumer_instance_guid = null;
-    $uid = '';
-    foreach ($rs[$recordcounter] as $field_name => $field_value){
+} elseif (Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    $_module_id = Common::fetch_SESSION('_module_id', null);
 
-      if (($field_name == 'id') && ($type != 'module')) {
-        $field_value = "<a href=\"../log.php?u={$uid}\" title=\"View activity log\">{$field_value}</a>";
-      }
-      if ($field_name == 'source_id') {
-        $source_id = $field_value;
-      } else if ($field_name == 'user_id') {
-        $uid = $field_value;
-        if (!$_source_id) {
-          echo '<td class="icon">';
-          echo '<a href="../../edit/index.php?u=' .$field_value . '&amp;t=' . $type . '">';
-          echo '<img src="../../../images/buttons/edit.gif" width="16" height="16" alt="Edit user" title="Edit user" /></a>';
-          if (APP__ENABLE_USER_DELETE) {
-            if ($_SESSION['_user_id'] != $field_value) {
-              echo '&nbsp;<a href="../../delete/index.php?u=' .$field_value . '" onclick="return confirm(\'Delete user; are you sure?\');">';
-              echo '<img src="../../../images/buttons/cross.gif" width="16" height="16" alt="Delete user" title="Delete user" /></a>';
-            } else {
-              echo '<img src="../../../images/buttons/blank.gif" width="16" height="16" alt="" />';
+    $query =
+      'SELECT u.user_id, u.source_id, u.username AS id, u.lastname, u.forename, u.email, u.id_number AS `id number`, u.date_last_login AS `last login` ' .
+      'FROM ' . APP__DB_TABLE_PREFIX . 'user u ' .
+      'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'user_module um ' .
+      'ON u.user_id = um.user_id ' .
+      'WHERE um.module_id = ? AND um.user_type = ? ' .
+      'ORDER BY u.lastname, u.forename, u.source_id, u.username';
+
+    $stmt = $dbConn->prepare($query);
+
+    $stmt->bindParam(1, $_module_id, ParameterType::INTEGER);
+    $stmt->bindParam(2, $type);
+}
+if (!isset($stmt)) {
+    echo ' <p>You need to be logged into the system to see this information.</p>';
+} else {
+    $rs = $stmt->execute()->fetchAllAssociative();
+
+    echo '<h2>' . $rstitle . '</h2>';
+    echo '<div class="obj">';
+    echo '<table class="obj" cellpadding="2" cellspacing="2">';
+
+    //work through the recordset if it is not empty
+    for ($recordcounter = 0; $recordcounter < count($rs); $recordcounter++) {
+        if ($recordcounter == 0) {
+            //write the table field headers to the screen
+            echo '<tr>';
+            foreach ($rs[$recordcounter] as $field_name => $field_value) {
+                if ($field_name == 'source_id') {
+                } elseif (($field_name != 'user_id') && ($field_name != 'module_id')) {
+                    echo "<th>{$field_name}</th>";
+                } elseif (($type == 'module') || !$_source_id) {
+                    echo '<th class="icon">&nbsp;</th>';
+                }
             }
-          }
-          echo '</td>';
-        }
-      } else if ($field_name == 'module_id') {
-        echo "<td class=\"icon\">";
-        if (!$_source_id) {
-          echo '<a href="../../edit/module.php?m=' .$field_value . '">';
-          echo '<img src="../../../images/buttons/edit.gif" width="16" height="16" alt="Edit module" title="Edit module" /></a>';
-        } else {
-          echo '<img src="../../../images/buttons/blank.gif" width="16" height="16" alt="" />';
+            echo "</tr>\n";
         }
-        if (APP__ENABLE_MODULE_DELETE) {
-          if ($_SESSION['_module_id'] != $field_value) {
-            echo '<a href="../../delete/index.php?m=' .$field_value . '" onclick="return confirm(\'Delete module; are you sure?\');">';
-            echo '<img src="../../../images/buttons/cross.gif" width="16" height="16" alt="Delete module" title="Delete module" /></a>';
-          } else {
-            echo '<img src="../../../images/buttons/blank.gif" width="16" height="16" alt="" />';
-          }
+        if (($type != 'module') && ($rs[$recordcounter]['source_id'] != $_user_source_id)) {
+            $style = ' style="background-color: #c0c0c0;"';
         } else {
-          echo '<img src="../../../images/buttons/blank.gif" width="16" height="16" alt="" />';
+            $style = '';
         }
-        echo '</td>';
-      } else if ($field_name == 'enabled') {
-        echo "<td class=\"obj_info_text\">";
-        if ($field_value == 1) {
-          echo 'Yes';
-        } else {
-          echo 'No';
+        echo "<tr{$style}>";
+        $consumer_instance_guid = null;
+        $uid = '';
+        foreach ($rs[$recordcounter] as $field_name => $field_value) {
+            if (($field_name == 'id') && ($type != 'module')) {
+                $field_value = "<a href=\"../log.php?u={$uid}\" title=\"View activity log\">{$field_value}</a>";
+            }
+            if ($field_name == 'source_id') {
+                $source_id = $field_value;
+            } elseif ($field_name == 'user_id') {
+                $uid = $field_value;
+                if (!$_source_id) {
+                    echo '<td class="icon">';
+                    echo '<a href="../../edit/index.php?u=' .$field_value . '&amp;t=' . $type . '">';
+                    echo '<img src="../../../images/buttons/edit.gif" width="16" height="16" alt="Edit user" title="Edit user" /></a>';
+                    if (APP__ENABLE_USER_DELETE) {
+                        if ($_SESSION['_user_id'] != $field_value) {
+                            echo '&nbsp;<a href="../../delete/index.php?u=' .$field_value . '" onclick="return confirm(\'Delete user; are you sure?\');">';
+                            echo '<img src="../../../images/buttons/cross.gif" width="16" height="16" alt="Delete user" title="Delete user" /></a>';
+                        } else {
+                            echo '<img src="../../../images/buttons/blank.gif" width="16" height="16" alt="" />';
+                        }
+                    }
+                    echo '</td>';
+                }
+            } elseif ($field_name == 'module_id') {
+                echo '<td class="icon">';
+                if (!$_source_id) {
+                    echo '<a href="../../edit/module.php?m=' .$field_value . '">';
+                    echo '<img src="../../../images/buttons/edit.gif" width="16" height="16" alt="Edit module" title="Edit module" /></a>';
+                } else {
+                    echo '<img src="../../../images/buttons/blank.gif" width="16" height="16" alt="" />';
+                }
+                if (APP__ENABLE_MODULE_DELETE) {
+                    if ($_SESSION['_module_id'] != $field_value) {
+                        echo '<a href="../../delete/index.php?m=' .$field_value . '" onclick="return confirm(\'Delete module; are you sure?\');">';
+                        echo '<img src="../../../images/buttons/cross.gif" width="16" height="16" alt="Delete module" title="Delete module" /></a>';
+                    } else {
+                        echo '<img src="../../../images/buttons/blank.gif" width="16" height="16" alt="" />';
+                    }
+                } else {
+                    echo '<img src="../../../images/buttons/blank.gif" width="16" height="16" alt="" />';
+                }
+                echo '</td>';
+            } elseif ($field_name == 'enabled') {
+                echo '<td class="obj_info_text">';
+                if ($field_value == 1) {
+                    echo 'Yes';
+                } else {
+                    echo 'No';
+                }
+                echo '</td>';
+            } elseif (strlen($field_value) <= 0) {
+                echo '<td class="obj_info_text">&nbsp;</td>';
+            } elseif (($field_name == 'id') && $style) {
+                echo "<td class=\"obj_info_text\"><span title=\"{$source_id}\">{$field_value}</span></td>";
+            } elseif ($field_name == 'email') {
+                echo "<td class=\"obj_info_text\"><a href=\"mailto:'{$field_value}\">{$field_value}</a></td>";
+            } else {
+                echo "<td class=\"obj_info_text\">{$field_value}</td>";
+            }
         }
-        echo '</td>';
-      } else if (strlen($field_value) <= 0) {
-        echo "<td class=\"obj_info_text\">&nbsp;</td>";
-      } else if (($field_name == 'id') && $style) {
-        echo "<td class=\"obj_info_text\"><span title=\"{$source_id}\">{$field_value}</span></td>";
-      } else if ($field_name == 'email') {
-        echo "<td class=\"obj_info_text\"><a href=\"mailto:'{$field_value}\">{$field_value}</a></td>";
-      } else {
-        echo "<td class=\"obj_info_text\">{$field_value}</td>";
-      }
+        echo "</tr>\n";
+    }
+    if (count($rs) <= 0) {
+        echo "<tr><td>No records</td></tr>\n";
     }
-    echo "</tr>\n";
-  }
-  if (count($rs) <= 0) {
-    echo "<tr><td>No records</td></tr>\n";
-  }
 
-  echo '</table>';
-  echo '</div>';
-  if ($_source_id == '') {
-    if ($type == 'module') {
-      echo '<form action="../../edit/module.php?m=" method="GET"><p><input type="submit" value="Create new module" /></p></form>';
-    } else {
-      echo '<form action="../../edit/index.php" method="GET"><p><input type="hidden" name="u" value="" /><input type="hidden" name="t" value="' . $type . '" /><input type="submit" value="Add new ' . $user_type . '" /></p></form>';
+    echo '</table>';
+    echo '</div>';
+    if ($_source_id == '') {
+        if ($type == 'module') {
+            echo '<form action="../../edit/module.php?m=" method="GET"><p><input type="submit" value="Create new module" /></p></form>';
+        } else {
+            echo '<form action="../../edit/index.php" method="GET"><p><input type="hidden" name="u" value="" /><input type="hidden" name="t" value="' . $type . '" /><input type="submit" value="Add new ' . $user_type . '" /></p></form>';
+        }
     }
-  }
 }
diff --git a/src/admin/review/index.php b/src/admin/review/index.php
index 98acd8e..013ba29 100644
--- a/src/admin/review/index.php
+++ b/src/admin/review/index.php
@@ -9,34 +9,34 @@
  */
 
 //get the include file required
-require_once("../../includes/inc_global.php");
+require_once '../../includes/inc_global.php';
 
 use WebPA\includes\functions\Common;
 
 if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
-$filecontenttype = array();
-$filecontenttype[] = array('link'=>'student','screen'=>'Student', 'def'=>'View the student data currently in the system',);
-$filecontenttype[] = array('link'=>'staff','screen'=>'Staff', 'def'=>'View the staff data currently in the system',);
+$filecontenttype = [];
+$filecontenttype[] = ['link'=>'student', 'screen'=>'Student', 'def'=>'View the student data currently in the system'];
+$filecontenttype[] = ['link'=>'staff', 'screen'=>'Staff', 'def'=>'View the staff data currently in the system'];
 if (Common::check_user($_user, APP__USER_TYPE_ADMIN)) {
-  $filecontenttype[] = array('link'=>'admin','screen'=>'Administrators', 'def'=>'View the administrator data currently in the system',);
-  $filecontenttype[] = array('link'=>'module','screen'=>'Module', 'def'=>'View the module information currently in the system',);
+    $filecontenttype[] = ['link'=>'admin', 'screen'=>'Administrators', 'def'=>'View the administrator data currently in the system'];
+    $filecontenttype[] = ['link'=>'module', 'screen'=>'Module', 'def'=>'View the module information currently in the system'];
 }
-$filecontenttype[] = array('link'=>'../search', 'screen'=>'Search', 'def'=>'Search for a student or staff user of the system',);
+$filecontenttype[] = ['link'=>'../search', 'screen'=>'Search', 'def'=>'Search for a student or staff user of the system'];
 
 //set the page information
-$UI->page_title = APP__NAME . " view data";
+$UI->page_title = APP__NAME . ' view data';
 $UI->menu_selected = 'view data';
-$UI->breadcrumbs = array ('home' => null);
+$UI->breadcrumbs = ['home' => null];
 $UI->help_link = '?q=node/237';
 $UI->set_page_bar_button('View Student Data', '../../../images/buttons/button_student_user.png', 'student/index.php');
 $UI->set_page_bar_button('View Staff Data', '../../../images/buttons/button_staff_user.png', 'staff/index.php');
 if (Common::check_user($_user, APP__USER_TYPE_ADMIN)) {
-  $UI->set_page_bar_button('View Admin Data', '../../../images/buttons/button_admin_user.png', 'admin/index.php');
-  $UI->set_page_bar_button('View Module Data', '../../../images/buttons/button_view_modules.png', 'module/index.php');
+    $UI->set_page_bar_button('View Admin Data', '../../../images/buttons/button_admin_user.png', 'admin/index.php');
+    $UI->set_page_bar_button('View Module Data', '../../../images/buttons/button_view_modules.png', 'module/index.php');
 }
 $UI->set_page_bar_button('Search for a user', '../../../images/buttons/button_search_user.png', '../search/index.php');
 $UI->head();
@@ -47,8 +47,8 @@
 <div class="content_box">
 <table class="option_list" style="width: 500px;">
 <?php
-  for($checkbox = 0; $checkbox<= count($filecontenttype)-1; $checkbox++){
-?>
+  for ($checkbox = 0; $checkbox<= count($filecontenttype)-1; $checkbox++) {
+      ?>
 <tr>
   <td><a href="<?php echo $filecontenttype[$checkbox]['link']; ?>/index.php"><img src="../../images/icons/form.gif" width="32" height="32" alt="" /></a></td><td>
     <div class="option_list"> <div class="option_list_title"><a class="hidden" href="<?php echo $filecontenttype[$checkbox]['link']; ?>/index.php"><?php echo $filecontenttype[$checkbox]['screen']; ?></a></div>
diff --git a/src/admin/review/log.php b/src/admin/review/log.php
index faa4754..dab05cc 100644
--- a/src/admin/review/log.php
+++ b/src/admin/review/log.php
@@ -11,29 +11,30 @@
  */
 
 //get the include file required
-require_once("../../includes/inc_global.php");
+require_once '../../includes/inc_global.php';
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\User;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
-$type = "log";
-$rstitle = "Log Data";
+$type = 'log';
+$rstitle = 'Log Data';
 
 //set the page information
-$UI->page_title = APP__NAME . " view log data";
+$UI->page_title = APP__NAME . ' view log data';
 $UI->menu_selected = 'view data';
-$UI->breadcrumbs = array ('home' => '../','review data'=>'./','log data'=>null);
+$UI->breadcrumbs = ['home' => '../', 'review data'=>'./', 'log data'=>null];
 $UI->help_link = '?q=node/237';
 $UI->set_page_bar_button('View Student Data', '../../../images/buttons/button_student_user.png', 'student/index.php');
 $UI->set_page_bar_button('View Staff Data', '../../../images/buttons/button_staff_user.png', 'staff/index.php');
 if (Common::check_user($_user, APP__USER_TYPE_ADMIN)) {
-  $UI->set_page_bar_button('View Admin Data', '../../../images/buttons/button_admin_user.png', 'admin/index.php');
-  $UI->set_page_bar_button('View Module Data', '../../../images/buttons/button_view_modules.png', 'module/index.php');
+    $UI->set_page_bar_button('View Admin Data', '../../../images/buttons/button_admin_user.png', 'admin/index.php');
+    $UI->set_page_bar_button('View Module Data', '../../../images/buttons/button_view_modules.png', 'module/index.php');
 }
 $UI->set_page_bar_button('Search for a user', '../../../images/buttons/button_search_user.png', '../search/index.php');
 $UI->head();
@@ -53,17 +54,25 @@
 $user->load_from_row($user_info);
 
 if ($_user->is_admin()) {
-  $query = 'SELECT datetime, description, ip_address AS `ip address`, object_id AS object ';
+    $query = 'SELECT datetime, description, ip_address AS `ip address`, object_id AS object ';
 } else {
-  $query = 'SELECT datetime, description, object_id AS object ';
+    $query = 'SELECT datetime, description, object_id AS object ';
 }
 
 $query .= 'FROM ' . APP__DB_TABLE_PREFIX . 'user_tracking ' .
-          "WHERE user_id = {$user_id} AND ((module_id = {$_module_id}) OR (module_id IS NULL)) " .
+          'WHERE user_id = ? AND ((module_id = ?) OR (module_id IS NULL)) ' .
           'ORDER BY datetime DESC, description';
 
-//run the query
-$rs = $DB->fetch($query);
+$dbConn = $DB->getConnection();
+
+$stmt = $dbConn->prepare($query);
+
+$stmt->bindValue(1, $user_id, ParameterType::INTEGER);
+$stmt->bindValue(2, $_module_id, ParameterType::INTEGER);
+
+$results = $stmt->execute();
+
+$rs = $results->fetchAllAssociative();
 
 echo "<h2>{$rstitle} for {$user->forename} {$user->lastname} ({$user->username})</h2>";
 
@@ -73,23 +82,22 @@
 
 //work through the recordset if it is not empty
 for ($recordcounter = 0; $recordcounter < count($rs); $recordcounter++) {
-
-  if ($recordcounter == 0) {
-    //write the table field headers to the screen
+    if ($recordcounter == 0) {
+        //write the table field headers to the screen
+        echo '<tr>';
+        foreach ($rs[$recordcounter] as $field_name => $field_value) {
+            echo "<th>{$field_name}</th>";
+        }
+        echo "</tr>\n";
+    }
     echo '<tr>';
-    foreach ($rs[$recordcounter] as $field_name => $field_value){
-      echo "<th>{$field_name}</th>";
+    foreach ($rs[$recordcounter] as $field_name => $field_value) {
+        echo '<td class="obj_info_text">'.$field_value.'</td>';
     }
     echo "</tr>\n";
-  }
-  echo '<tr>';
-  foreach ($rs[$recordcounter] as $field_name => $field_value){
-    echo '<td class="obj_info_text">'.$field_value.'</td>';
-  }
-  echo "</tr>\n";
 }
 if (count($rs) <= 0) {
-  echo "<tr><td>No records</td></tr>\n";
+    echo "<tr><td>No records</td></tr>\n";
 }
 
 echo '</table>';
diff --git a/src/admin/review/module/index.php b/src/admin/review/module/index.php
index 60c5f44..cfd2a9a 100644
--- a/src/admin/review/module/index.php
+++ b/src/admin/review/module/index.php
@@ -12,23 +12,23 @@
  */
 
 //get the include file required
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_ADMIN)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_ADMIN)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
-$table = "module";
-$type = "module";
-$rstitle = "Module Data";
+$table = 'module';
+$type = 'module';
+$rstitle = 'Module Data';
 
 //set the page information
-$UI->page_title = APP__NAME . " view module data";
+$UI->page_title = APP__NAME . ' view module data';
 $UI->menu_selected = 'view data';
-$UI->breadcrumbs = array ('home' => '../../','review data'=>'../', ' module information'=>null);
+$UI->breadcrumbs = ['home' => '../../', 'review data'=>'../', ' module information'=>null];
 $UI->help_link = '?q=node/237';
 $UI->set_page_bar_button('View Student Data', '../../../../images/buttons/button_student_user.png', '../student/index.php');
 $UI->set_page_bar_button('View Staff Data', '../../../../images/buttons/button_staff_user.png', '../staff/index.php');
diff --git a/src/admin/review/staff/index.php b/src/admin/review/staff/index.php
index 8519561..8628612 100644
--- a/src/admin/review/staff/index.php
+++ b/src/admin/review/staff/index.php
@@ -9,13 +9,13 @@
  */
 
 //get the include file required
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\functions\Common;
 
 if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 $table = 'user';
@@ -24,15 +24,15 @@
 $user_type = 'tutor';
 
 //set the page information
-$UI->page_title = APP__NAME . " view staff data";
+$UI->page_title = APP__NAME . ' view staff data';
 $UI->menu_selected = 'view data';
-$UI->breadcrumbs = array ('home' => '../../','review data'=>'../', 'staff information'=>null,);
+$UI->breadcrumbs = ['home' => '../../', 'review data'=>'../', 'staff information'=>null];
 $UI->help_link = '?q=node/237';
 $UI->set_page_bar_button('View Student Data', '../../../../images/buttons/button_student_user.png', '../student/index.php');
 $UI->set_page_bar_button('View Staff Data', '../../../../images/buttons/button_staff_user.png', '../staff/index.php');
 if (Common::check_user($_user, APP__USER_TYPE_ADMIN)) {
-  $UI->set_page_bar_button('View Admin Data', '../../../../images/buttons/button_admin_user.png', '../admin/index.php');
-  $UI->set_page_bar_button('View Module Data', '../../../../images/buttons/button_view_modules.png', '../module/index.php');
+    $UI->set_page_bar_button('View Admin Data', '../../../../images/buttons/button_admin_user.png', '../admin/index.php');
+    $UI->set_page_bar_button('View Module Data', '../../../../images/buttons/button_view_modules.png', '../module/index.php');
 }
 $UI->set_page_bar_button('Search for a user', '../../../../images/buttons/button_search_user.png', '../../search/index.php');
 $UI->head();
diff --git a/src/admin/review/student/index.php b/src/admin/review/student/index.php
index f34ce11..6ce5fe9 100644
--- a/src/admin/review/student/index.php
+++ b/src/admin/review/student/index.php
@@ -9,13 +9,13 @@
  */
 
 //get the include file required
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\functions\Common;
 
 if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 $table = 'user';
@@ -24,15 +24,15 @@
 $user_type = 'student';
 
 //set the page information
-$UI->page_title = APP__NAME . " view student data";
+$UI->page_title = APP__NAME . ' view student data';
 $UI->menu_selected = 'view data';
-$UI->breadcrumbs = array ('home' => '../../','review data'=>'../','student information'=>null,);
+$UI->breadcrumbs = ['home' => '../../', 'review data'=>'../', 'student information'=>null];
 $UI->help_link = '?q=node/237';
 $UI->set_page_bar_button('View Student Data', '../../../../images/buttons/button_student_user.png', '../student/index.php');
 $UI->set_page_bar_button('View Staff Data', '../../../../images/buttons/button_staff_user.png', '../staff/index.php');
 if (Common::check_user($_user, APP__USER_TYPE_ADMIN)) {
-  $UI->set_page_bar_button('View Admin Data', '../../../../images/buttons/button_admin_user.png', '../admin/index.php');
-  $UI->set_page_bar_button('View Module Data', '../../../../images/buttons/button_view_modules.png', '../module/index.php');
+    $UI->set_page_bar_button('View Admin Data', '../../../../images/buttons/button_admin_user.png', '../admin/index.php');
+    $UI->set_page_bar_button('View Module Data', '../../../../images/buttons/button_view_modules.png', '../module/index.php');
 }
 $UI->set_page_bar_button('Search for a user', '../../../../images/buttons/button_search_user.png', '../../search/index.php');
 $UI->head();
diff --git a/src/admin/search/index.php b/src/admin/search/index.php
index 4ab71d8..1f25e84 100644
--- a/src/admin/search/index.php
+++ b/src/admin/search/index.php
@@ -12,13 +12,13 @@
  */
 
 //get the include file required
-require_once("../../includes/inc_global.php");
+require_once '../../includes/inc_global.php';
 
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 //-------------------------------------------------------------------------
@@ -30,57 +30,96 @@
 $post_id_number = Common::fetch_GET('id_number');
 $post_search = Common::fetch_GET('search');
 
-$where = '';
-$order = '';
+$whereClauseSet = false;
 $sMessage = '';
 
+$dbConn = $DB->getConnection();
+
+// set up the query builder
+$queryBuilder = $dbConn->createQueryBuilder();
+
+// write the base query
+$queryBuilder->select(
+    'u.user_id',
+    'u.username AS id',
+    'u.lastname',
+    'u.forename',
+    'u.email',
+    'u.id_number AS id_number',
+    'u.date_last_login AS last_login',
+    'CASE u.admin WHEN 0 THEN COUNT(um.module_id) ELSE NULL END as modules'
+)
+        ->from(APP__DB_TABLE_PREFIX . 'user', 'u')
+        ->leftJoin('u', APP__DB_TABLE_PREFIX . 'user_module', 'um', 'u.user_id = um.user_id')
+        ->where('u.source_id = :source_id')
+        ->setParameter('source_id', $_source_id);
+
 if (!empty($post_search)) {
-  //build the search string dependant on the data entered
-  if (!empty($post_lastname)) {
-    $where .= " AND (u.lastname LIKE '{$post_lastname}%')";
-    $order .= ', u.lastname';
-  }
-  if (!empty($post_firstname)) {
-    $where .= " AND (u.forename LIKE '{$post_firstname}%')";
-    $order .= ', u.forename';
-  }
-  if (!empty($post_username)) {
-    $where .= " AND (u.username LIKE '{$post_username}%')";
-    $order .= ', u.username';
-  }
-  if (!empty($post_id_number)) {
-    $where .= " AND (u.id_number LIKE '{$post_id_number}%')";
-    $order .= ', u.id_number';
-  }
-  if (!empty($where)) {
-    if (!Common::check_user($_user, APP__USER_TYPE_ADMIN)) {
-      $where .= ' AND (u.admin = 0)';
+    //build the search string dependant on the data entered
+    if (!empty($post_lastname)) {
+        $queryBuilder->andWhere($queryBuilder->expr()->like('u.lastname', ':last_name'));
+        $queryBuilder->addOrderBy('u.lastname');
+        $queryBuilder->setParameter('last_name', $post_lastname . '%');
+
+        $whereClauseSet = true;
+    }
+
+    if (!empty($post_firstname)) {
+        $queryBuilder->andWhere($queryBuilder->expr()->like('u.forename', ':forename'));
+        $queryBuilder->addOrderBy('u.forename');
+        $queryBuilder->setParameter('forename', $post_firstname . '%');
+
+        $whereClauseSet = true;
+    }
+
+    if (!empty($post_username)) {
+        $queryBuilder->andWhere($queryBuilder->expr()->like('u.username', ':username'));
+        $queryBuilder->addOrderBy('u.username');
+        $queryBuilder->setParameter('username', $post_username . '%');
+
+        $whereClauseSet = true;
+    }
+
+    if (!empty($post_id_number)) {
+        $queryBuilder->andWhere($queryBuilder->expr()->like('u.id_number', ':id_number'));
+        $queryBuilder->addOrderBy('u.id_number');
+        $queryBuilder->setParameter('id_number', $post_id_number . '%');
+
+        $whereClauseSet = true;
+    }
+
+    if ($whereClauseSet === true) {
+        if (!Common::check_user($_user, APP__USER_TYPE_ADMIN)) {
+            $queryBuilder->andWhere('u.admin = 0');
+        }
+
+        // add the groupBy clause
+        $queryBuilder->groupBy('u.user_id');
+        $queryBuilder->addGroupBy('u.username');
+        $queryBuilder->addGroupBy('u.lastname');
+        $queryBuilder->addGroupBy('u.forename');
+        $queryBuilder->addGroupBy('u.email');
+        $queryBuilder->addGroupBy('u.id_number');
+        $queryBuilder->addGroupBy('u.date_last_login');
+
+        $rs = $queryBuilder->execute()->fetchAllAssociative();
+    } else {
+        //nothing has been entered that can be searched for
+        $sMessage = '<p>You have not entered any information for the search<br/>Please check and re-try.</p>';
     }
-    $order = substr($order, 2);
-    $sQuery = 'SELECT u.user_id, u.username AS id, u.lastname, u.forename, u.email, u.id_number AS `id number`, ' .
-       'u.date_last_login AS `last login`, CASE u.admin WHEN 0 THEN COUNT(um.module_id) ELSE NULL END AS modules ' .
-       'FROM ' . APP__DB_TABLE_PREFIX . 'user u LEFT OUTER JOIN ' . APP__DB_TABLE_PREFIX . 'user_module um ON u.user_id = um.user_id ' .
-       "WHERE (u.source_id = '{$_source_id}'){$where} " .
-       'GROUP BY u.user_id, u.username, u.lastname, u.forename, u.email, u.id_number, u.date_last_login ' .
-       "ORDER BY {$order}";
-    $rs = $DB->fetch($sQuery);
-  } else {
-    //nothing has been entered that can be searched for
-    $sMessage = "<p>You have not entered any information for the search<br/>Please check and re-try.</p>";
-  }
 }
 
 //------------------------------------------------------------------------
 
 //set the page information
-$UI->page_title = APP__NAME . "  search for a user";
+$UI->page_title = APP__NAME . '  search for a user';
 $UI->menu_selected = 'view data';
-$UI->breadcrumbs = array ('home' => '../review/', 'search'=>null,);
+$UI->breadcrumbs = ['home' => '../review/', 'search'=>null];
 $UI->set_page_bar_button('View Student Data', '../../../images/buttons/button_student_user.png', '../review/student/index.php');
 $UI->set_page_bar_button('View Staff Data', '../../../images/buttons/button_staff_user.png', '../review/staff/index.php');
 if (Common::check_user($_user, APP__USER_TYPE_ADMIN)) {
-  $UI->set_page_bar_button('View Admin Data', '../../../images/buttons/button_admin_user.png', '../review/admin/index.php');
-  $UI->set_page_bar_button('View Module Data', '../../../images/buttons/button_view_modules.png', '../review/module/index.php');
+    $UI->set_page_bar_button('View Admin Data', '../../../images/buttons/button_admin_user.png', '../review/admin/index.php');
+    $UI->set_page_bar_button('View Module Data', '../../../images/buttons/button_view_modules.png', '../review/module/index.php');
 }
 $UI->set_page_bar_button('Search for a user', '../../../images/buttons/button_search_user.png', 'index.php');
 
@@ -92,80 +131,79 @@
 
 $page_intro = '<p>Search the WebPA system for a user within the system</p>';
 $page_description = '<p>Enter the any combination of the information below for the individual that you would like to locate in the WebPA system. The person being searched for can be a student or staff member. When you are ready click the "Search Button".</p>';
-$rstitle = "Search results";
+$rstitle = 'Search results';
 ?>
 <?php echo $page_intro; ?>
 
 <div class="content_box">
 <?php
 if (empty($sMessage)) {
-  echo  '<h2>' . $rstitle . '</h2>';
-
-  if (!empty($rs)) {
-    echo '<div class="obj">';
-    echo '<table class="obj" cellpadding="2" cellspacing="2">';
-    //work through the recordset if it is not empty
-    $recordcounter = 0;
-    while ($recordcounter<=count($rs)-1) {
-
-      if ($recordcounter == 0) {
-        //write the table field headers to the screen
-        echo '<tr>';
-        foreach ($rs[$recordcounter] as $field_name => $field_value){
-          if ($field_name == 'source_id') {
-          } else if (($field_name != 'user_id') && ($field_name != 'module_id')) {
-            echo "<th>{$field_name}</th>";
-          } else if (!$_source_id) {
-            echo "<th class=\"icon\">&nbsp;</th>";
-          }
+    echo  '<h2>' . $rstitle . '</h2>';
+
+    if (!empty($rs)) {
+        echo '<div class="obj">';
+        echo '<table class="obj" cellpadding="2" cellspacing="2">';
+        //work through the recordset if it is not empty
+        $recordcounter = 0;
+        while ($recordcounter<=count($rs)-1) {
+            if ($recordcounter == 0) {
+                //write the table field headers to the screen
+                echo '<tr>';
+                foreach ($rs[$recordcounter] as $field_name => $field_value) {
+                    if ($field_name == 'source_id') {
+                    } elseif (($field_name != 'user_id') && ($field_name != 'module_id')) {
+                        echo "<th>{$field_name}</th>";
+                    } elseif (!$_source_id) {
+                        echo '<th class="icon">&nbsp;</th>';
+                    }
+                }
+                echo "</tr>\n";
+            }
+            echo '<tr>';
+            foreach ($rs[$recordcounter] as $field_index => $field_name) {
+                if ($field_index=='user_id') {
+                    echo '<td class="icon" width="16">';
+                    echo "<a href='../edit/index.php?u=" . $field_name . "'>";
+                    echo '<img src="../../images/buttons/edit.gif" width="16" height="16" alt="Edit user" /></a>';
+                    echo '</td>';
+                } else {
+                    echo '<td class="obj_info_text">'.$field_name.'</td>';
+                }
+            }
+            echo '</tr>';
+            $recordcounter++;
         }
-        echo "</tr>\n";
-      }
-      echo '<tr>';
-      foreach ($rs[$recordcounter] as $field_index => $field_name){
-        if ($field_index=='user_id') {
-          echo '<td class="icon" width="16">';
-          echo "<a href='../edit/index.php?u=" . $field_name . "'>";
-          echo '<img src="../../images/buttons/edit.gif" width="16" height="16" alt="Edit user" /></a>';
-          echo '</td>';
-        } else {
-          echo '<td class="obj_info_text">'.$field_name.'</td>';
+        echo '</table>';
+        echo '</div>';
+    } else {
+        if (!empty($post_search)) {
+            echo '<div class="warning_box">The search has not found any matching information.</div>';
         }
-      }
-      echo '</tr>';
-      $recordcounter++;
+        echo $page_description;
+        echo '<form method="get" name="search" action="index.php">' ;
+        echo '<table class="option_list" style="width: 500px;">';
+        echo  '<tr><td><label for="firstname">First name</label></td><td><input type="text" id="firstname" name="firstname" ></td></tr>';
+        echo  '<tr><td><label for="lastname">Last name</label></td><td><input type="text" id="lastname" name="lastname"></td></tr>';
+        echo  '<tr><td><label for="username">Username</label></td><td><input type="text" id="username" name="username"></td></tr>';
+        echo  '<tr><td><label for="id_number">ID number</label></td><td><input type="text" id="id_number" name="id_number"></td></tr>';
+        echo  '<tr><td><input type="hidden" id="search" name="search" value="search"></td><td><input type="Submit" value="Search" id="Search"></td></tr>';
+        echo '</table>';
+        echo '</form>';
     }
-    echo '</table>';
-    echo '</div>';
-  } else {
-    if (!empty($post_search)) {
-      echo "<div class=\"warning_box\">The search has not found any matching information.</div>";
+} else {
+    if (!empty($sMessage)) {
+        echo "<div class=\"warning_box\">{$sMessage}</div>";
     }
     echo $page_description;
-    echo "<form method=\"get\" name=\"search\" action=\"index.php\">" ;
-    echo "<table class=\"option_list\" style=\"width: 500px;\">";
-    echo  "<tr><td><label for=\"firstname\">First name</label></td><td><input type=\"text\" id=\"firstname\" name=\"firstname\" ></td></tr>";
-    echo  "<tr><td><label for=\"lastname\">Last name</label></td><td><input type=\"text\" id=\"lastname\" name=\"lastname\"></td></tr>";
-    echo  "<tr><td><label for=\"username\">Username</label></td><td><input type=\"text\" id=\"username\" name=\"username\"></td></tr>";
-    echo  "<tr><td><label for=\"id_number\">ID number</label></td><td><input type=\"text\" id=\"id_number\" name=\"id_number\"></td></tr>";
-    echo  "<tr><td><input type=\"hidden\" id=\"search\" name=\"search\" value=\"search\"></td><td><input type=\"Submit\" value=\"Search\" id=\"Search\"></td></tr>";
-    echo "</table>";
-    echo "</form>";
-  }
-} else {
-  if (!empty($sMessage)) {
-    echo "<div class=\"warning_box\">{$sMessage}</div>";
-  }
-  echo $page_description;
-  echo "<form method=\"get\" name=\"search\" action=\"index.php\">" ;
-  echo "<table class=\"option_list\" style=\"width: 500px;\">";
-  echo  "<tr><td><label for=\"lastname\">Last name</label></td><td><input type=\"text\" id=\"lastname\" name=\"lastname\"></td></tr>";
-  echo  "<tr><td><label for=\"name\">First name</label></td><td><input type=\"text\" id=\"name\" name=\"name\" ></td></tr>";
-  echo  "<tr><td><label for=\"username\">Username</label></td><td><input type=\"text\" id=\"username\" name=\"username\"></td></tr>";
-  echo  "<tr><td><label for=\"id_number\">ID number</label></td><td><input type=\"text\" id=\"id_number\" name=\"id_number\"></td></tr>";
-  echo  "<tr><td><input type=\"hidden\" id=\"search\" name=\"search\" value=\"search\"></td><td><input type=\"Submit\" value=\"Search\" id=\"Search\"></td></tr>";
-  echo "</table>";
-  echo "</form>";
+    echo '<form method="get" name="search" action="index.php">' ;
+    echo '<table class="option_list" style="width: 500px;">';
+    echo  '<tr><td><label for="lastname">Last name</label></td><td><input type="text" id="lastname" name="lastname"></td></tr>';
+    echo  '<tr><td><label for="name">First name</label></td><td><input type="text" id="name" name="name" ></td></tr>';
+    echo  '<tr><td><label for="username">Username</label></td><td><input type="text" id="username" name="username"></td></tr>';
+    echo  '<tr><td><label for="id_number">ID number</label></td><td><input type="text" id="id_number" name="id_number"></td></tr>';
+    echo  '<tr><td><input type="hidden" id="search" name="search" value="search"></td><td><input type="Submit" value="Search" id="Search"></td></tr>';
+    echo '</table>';
+    echo '</form>';
 }
 ?>
 </div>
diff --git a/src/contact/contact_send.php b/src/contact/contact_send.php
index cb48b78..92122d7 100755
--- a/src/contact/contact_send.php
+++ b/src/contact/contact_send.php
@@ -8,7 +8,7 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../includes/inc_global.php");
+require_once '../includes/inc_global.php';
 
 use WebPA\includes\classes\Email;
 use WebPA\includes\functions\Common;
@@ -38,71 +38,68 @@
 
 $app_www = APP__WWW;
 
-$errors = array();
+$errors = [];
 
 if ($contact_fullname == '') {
-	$errors[] = 'Name is required';
+    $errors[] = 'Name is required';
 }
 
 if ($contact_message == '') {
-	$errors[] = 'Message is required';
+    $errors[] = 'Message is required';
 }
 
 if ($contact_email == '') {
-	$errors[] = 'Email is required';
-
+    $errors[] = 'Email is required';
 } elseif (!Form::is_email($contact_email)) {
-	$errors[] = 'Email is not valid';
+    $errors[] = 'Email is not valid';
 }
 
 if (empty($errors)) {
-
-$email_body = <<<EndBody
-Contact Sent
-----------------------------------------
-Application  : $contact_app_id ($app_www)
-Contact Type : $contact_type
-Date         : $contact_date
-----------------------------------------
-
-Contact Details
-----------------------------------------
-Fullname : $contact_fullname
-Username : $contact_username
-Email    : $contact_email
-Phone    : $contact_phone
-----------------------------------------
-
-User Account Details
-----------------------------------------
-User ID  : $contact_user_id
-Fullname : $contact_user_fullname
-Username : $contact_user_username
-Email    : $contact_user_email
-----------------------------------------
-
-Message:
-----------------------------------------
-$contact_message
-----------------------------------------
-EndBody;
-
-// Send the email
-$email = new Email();
-$email->set_to($contact_to);
-$email->set_from($contact_email);
-$email->set_subject("$contact_app_id : $contact_type");
-$email->set_body($email_body);
-$email->send();
-
+    $email_body = <<<EndBody
+        Contact Sent
+        ----------------------------------------
+        Application  : $contact_app_id ($app_www)
+        Contact Type : $contact_type
+        Date         : $contact_date
+        ----------------------------------------
+
+        Contact Details
+        ----------------------------------------
+        Fullname : $contact_fullname
+        Username : $contact_username
+        Email    : $contact_email
+        Phone    : $contact_phone
+        ----------------------------------------
+
+        User Account Details
+        ----------------------------------------
+        User ID  : $contact_user_id
+        Fullname : $contact_user_fullname
+        Username : $contact_user_username
+        Email    : $contact_user_email
+        ----------------------------------------
+
+        Message:
+        ----------------------------------------
+        $contact_message
+        ----------------------------------------
+        EndBody;
+
+    // Send the email
+    $email = new Email();
+    $email->set_to($contact_to);
+    $email->set_from($contact_email);
+    $email->set_subject("$contact_app_id : $contact_type");
+    $email->set_body($email_body);
+    $email->send();
 }
 
 // Begin Page
 
 $UI->page_title = APP__NAME . ' Message Sent';
 $UI->menu_selected = 'contact';
-$UI->breadcrumbs = array  ('home'   => '/' ,
-              'contact' => null ,);
+$UI->breadcrumbs = ['home'   => '/',
+              'contact' => null, ];
 
 $UI->head();
 $UI->body();
@@ -111,20 +108,20 @@
 ?>
 
   <div class="content_box">
-    <?php if (empty($errors)) : ?>
+    <?php if (empty($errors)) { ?>
     <p>Your message has now been sent.</p>
     <p>We will try and respond as soon as possible, but at times our team can be very busy. We apologise in advance for any delay in getting back to you.</p>
     <p>Thanks for your time</p>
-    <?php else : ?>
+    <?php } else { ?>
     	<p>Please correct the following errors:</p>
     	<ul>
-    	<?php foreach ($errors as $error) : ?>
+    	<?php foreach ($errors as $error) { ?>
     		<li><?php echo $error?></li>
-    	<?php endforeach; ?>
+    	<?php } ?>
     	</ul>
     	<br>
     	<button onclick="javascript:window.history.back();">Fix Errors</button>
-    <?php endif; ?>
+    <?php } ?>
   </div>
 <?php
 
diff --git a/src/contact/index.php b/src/contact/index.php
index 9d202d1..66ce079 100644
--- a/src/contact/index.php
+++ b/src/contact/index.php
@@ -10,7 +10,7 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../includes/inc_global.php");
+require_once '../includes/inc_global.php';
 
 use WebPA\includes\functions\Common;
 use WebPA\includes\functions\Form;
@@ -26,8 +26,8 @@
 $UI->page_title = APP__NAME . ' Contact';
 $UI->menu_selected = 'contact';
 $UI->help_link = '?q=node/379#intool';
-$UI->breadcrumbs = array	('home'		=> '../' ,
-							 'contact'	=> null ,);
+$UI->breadcrumbs = ['home'		=> '../',
+                             'contact'	=> null, ];
 
 
 $UI->head();
@@ -53,21 +53,21 @@ function do_send() {
 		<p>Please supply as much information with your message as possible (especially when sending a bug report!), this will allow us to respond to your message much faster!</p>
 
 		<form action="contact_send.php" method="post" name="contact_form">
-		<input type="hidden" name="contact_app" value="<?php echo($_config['app_id']); ?>" />
+		<input type="hidden" name="contact_app" value="<?php echo $_config['app_id']; ?>" />
 
 		<div class="form_section">
 			<table class="form" cellpadding="2" cellspacing="2">
 			<tr>
 				<td><label for="contact_name">Your Name</label></td>
-				<td><input type="text" name="contact_name" id="contact_name" maxlength="60" size="50" value="<?php echo("{$_user->forename} {$_user->lastname}"); ?>" /></td>
+				<td><input type="text" name="contact_name" id="contact_name" maxlength="60" size="50" value="<?php echo "{$_user->forename} {$_user->lastname}"; ?>" /></td>
 			</tr>
 			<tr>
 				<td><label for="contact_username">Your Username</label></td>
-				<td><input type="text" name="contact_username" id="contact_username" maxlength="15" size="10" value="<?php echo($_user->username); ?>" /></td>
+				<td><input type="text" name="contact_username" id="contact_username" maxlength="15" size="10" value="<?php echo $_user->username; ?>" /></td>
 			</tr>
 			<tr>
 				<td><label for="contact_email">Your Email</label></td>
-				<td><input type="text" name="contact_email" id="contact_email" maxlength="255" size="50" value="<?php echo($_user->email); ?>" /></td>
+				<td><input type="text" name="contact_email" id="contact_email" maxlength="255" size="50" value="<?php echo $_user->email; ?>" /></td>
 			</tr>
 			<tr>
 				<td><label for="contact_phone">Your Phone Number</label></td>
@@ -79,14 +79,14 @@ function do_send() {
 				<td>
 					<select name="contact_type" id="contact_type">
 						<?php
-							$contact_types = array	('help'		=> 'Request for help!' ,
-													 'info'		=> 'Information request' ,
-													 'bug'		=> 'Bug / Error report' ,
-													 'wish'		=> 'Suggestion / Wish List' ,
-													 'misc'		=> 'Other type of message' ,);
-
-							Form::render_options($contact_types, $contact_type);
-						?>
+                            $contact_types = ['help'		=> 'Request for help!',
+                                                     'info'		=> 'Information request',
+                                                     'bug'		=> 'Bug / Error report',
+                                                     'wish'		=> 'Suggestion / Wish List',
+                                                     'misc'		=> 'Other type of message', ];
+
+                            Form::render_options($contact_types, $contact_type);
+                        ?>
 					</select>
 				</td>
 			</tr>
diff --git a/src/cookie.php b/src/cookie.php
index 44193ae..ea1da4f 100644
--- a/src/cookie.php
+++ b/src/cookie.php
@@ -8,30 +8,28 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once('includes/inc_global.php');
+require_once 'includes/inc_global.php';
 
 $url = '';
 if (isset($_GET['url'])) {
-  $url = $_GET['url'];
+    $url = $_GET['url'];
 }
 
 if ($_user) {
-  $id = '';
-  if (isset($_GET['id'])) {
-    $id = $_GET['id'];
-  }
-  header('Location: ' . APP__WWW . '/index.php?id=' . $id);
-} else if ($url) {
-  if (strpos($url, '?') === FALSE) {
-    $url .= '?';
-  } else {
-    $url .= '&';
-  }
-  header('Location: ' . $url . 'lti_errormsg=' . urlencode('Unable to connect to ' . APP__NAME . '; please ensure that your browser is not blocking third-party cookies'));
+    $id = '';
+    if (isset($_GET['id'])) {
+        $id = $_GET['id'];
+    }
+    header('Location: ' . APP__WWW . '/index.php?id=' . $id);
+} elseif ($url) {
+    if (strpos($url, '?') === false) {
+        $url .= '?';
+    } else {
+        $url .= '&';
+    }
+    header('Location: ' . $url . 'lti_errormsg=' . urlencode('Unable to connect to ' . APP__NAME . '; please ensure that your browser is not blocking third-party cookies'));
 } else {
-  header('Location: ' . APP__WWW . '/login.php?msg=cookies');
+    header('Location: ' . APP__WWW . '/login.php?msg=cookies');
 }
 
 exit;
-
-?>
diff --git a/src/images/icon.png b/src/images/icon.png
new file mode 100644
index 0000000..f435c18
Binary files /dev/null and b/src/images/icon.png differ
diff --git a/src/includes/classes/AlgorithmFactory.php b/src/includes/classes/AlgorithmFactory.php
index 102c011..61992e5 100644
--- a/src/includes/classes/AlgorithmFactory.php
+++ b/src/includes/classes/AlgorithmFactory.php
@@ -14,32 +14,33 @@
 
 use WebPA\includes\classes\algorithms\WebPAAlgorithm;
 
-class AlgorithmFactory {
-
-/*
-* ================================================================================
-* Public Methods
-* ================================================================================
-*/
-
-  /**
-   * Get an instance of the requested algorithm class.
-   *
-   * @param  string  $algorithm_name  The algorithm to create.
-   *
-   * @return  mixed  The algorithm object requested. On fail, null.
-   */
-  public static function get_algorithm($algorithm_name) {
-    $algorithm = null;
-
-    switch($algorithm_name) {
+class AlgorithmFactory
+{
+    /*
+    * ================================================================================
+    * Public Methods
+    * ================================================================================
+    */
+
+    /**
+     * Get an instance of the requested algorithm class.
+     *
+     * @param  string  $algorithm_name  The algorithm to create.
+     *
+     * @return  mixed  The algorithm object requested. On fail, null.
+     */
+    public static function get_algorithm($algorithm_name)
+    {
+        $algorithm = null;
+
+        switch ($algorithm_name) {
       case 'pets':
-		// @todo : There appear to be grading problems with the PETS algorithm in peer-only mode.
-		// Until we have conducted a full investigation and nailed down what's happening
-		// this algorithm is disabled.
-		//
-		//require_once(DOC__ROOT.'includes/classes/algorithms/class_pets_algorithm.php');
-		//$algorithm = new PETSAlgorithm();
+        // @todo : There appear to be grading problems with the PETS algorithm in peer-only mode.
+        // Until we have conducted a full investigation and nailed down what's happening
+        // this algorithm is disabled.
+        //
+        //require_once(DOC__ROOT.'includes/classes/algorithms/class_pets_algorithm.php');
+        //$algorithm = new PETSAlgorithm();
         break;
       case 'webpa':
       default:
@@ -48,9 +49,8 @@ public static function get_algorithm($algorithm_name) {
         break;
     }
 
-    return $algorithm;
-  }// /->get_algorithm()
+        return $algorithm;
+    }
 
+    // /->get_algorithm()
 }// /class
-
-?>
diff --git a/src/includes/classes/Assessment.php b/src/includes/classes/Assessment.php
index f8667bc..e9097c1 100644
--- a/src/includes/classes/Assessment.php
+++ b/src/includes/classes/Assessment.php
@@ -10,410 +10,591 @@
 
 namespace WebPA\includes\classes;
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\functions\Common;
 
-class Assessment {
+class Assessment
+{
+    // Public Vars
+    public $id;
 
-  // Public Vars
-  public $id = null;
-  public $name = '';
-  public $module_id = null;
+    public $name = '';
 
-  public $open_date = null;
-  public $close_date = null;
-  public $introduction = '';
+    public $module_id;
 
-  public $allow_feedback = false;
-  public $assessment_type = 1;
-  public $allow_assessment_feedback = false;
-  public $feedback_name = 'feedback';
-  public $email_opening = false;
-  public $email_closing = false;
+    public $open_date;
 
-  // Private Vars
-  private $_DAO = null;
-  private $_xml_parser = null;
+    public $close_date;
 
-  private $_collection = null;
-  private $_collection_id = null;
+    public $introduction = '';
 
-  private $_form = null;
-  private $_form_xml = '';
+    public $allow_feedback = false;
 
-  private $_finished = false;
+    public $assessment_type = 1;
 
-  private $_locked = null;
+    public $allow_assessment_feedback = false;
 
-  /**
-  * CONSTRUCTOR for the assessment class
-  *
-  * @param string $DAO
-  */
-  function __construct(&$DAO) {
-    $this->_DAO =& $DAO;
-    $this->_locked = null;
-  }// /->Assessment()
+    public $feedback_name = 'feedback';
 
-/**
-* ================================================================================
-* Public Methods
-* ================================================================================
-*/
+    public $email_opening = false;
 
-/**
-* --------------------------------------------------------------------------------
-* Load/Save Functions
-* --------------------------------------------------------------------------------
-*/
-
-  /**
-  * Create a new Assessment ID
-  */
-  function create() {
-    // generate a new project_id
-    while (true) {
-      $new_id = Common::uuid_create();
-      if ($this->_DAO->fetch_value("SELECT COUNT(assessment_id) FROM " . APP__DB_TABLE_PREFIX . "assessment WHERE assessment_id = '$new_id'") == 0) {
-        break;
-      }
+    public $email_closing = false;
+
+    // Private Vars
+    private DAO $_DAO;
+
+    private $dbConn;
+
+    private $_xml_parser;
+
+    private $_collection;
+
+    private $_collection_id;
+
+    private $_form;
+
+    private $_form_xml = '';
+
+    private $_finished = false;
+
+    private $_locked;
+
+    /**
+    * CONSTRUCTOR for the assessment class
+    *
+    * @param DAO $DAO
+    */
+    public function __construct(DAO $DAO)
+    {
+        $this->_DAO =& $DAO;
+        $this->dbConn = $this->_DAO->getConnection();
+        $this->_locked = null;
+    }
+
+    // /->Assessment()
+
+    /**
+    * ================================================================================
+    * Public Methods
+    * ================================================================================
+    */
+
+    /**
+    * --------------------------------------------------------------------------------
+    * Load/Save Functions
+    * --------------------------------------------------------------------------------
+    */
+
+    /**
+    * Create a new Assessment ID
+    */
+    public function create()
+    {
+        // generate a new project_id
+        while (true) {
+            $new_id = Common::uuid_create();
+            $projectIdQuery =
+          'SELECT COUNT(assessment_id) ' .
+          'FROM ' . APP__DB_TABLE_PREFIX . 'assessment ' .
+          'WHERE assessment_id = ?';
+
+            $projectCount = $this->dbConn->fetchOne($projectIdQuery, [$new_id], [ParameterType::STRING]);
+
+            if ($projectCount == 0) {
+                break;
+            }
+        }
+
+        $this->id = $new_id;
+    }
+
+    /**
+    * Delete this Assessment
+    *
+    * @return boolean true
+    */
+    public function delete()
+    {
+        $this->dbConn->executeQuery(
+            'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'assessment_group_marks WHERE assessment_id = ?',
+            [$this->id],
+            [ParameterType::STRING]
+        );
+
+        $this->dbConn->executeQuery(
+            'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'assessment_marking WHERE assessment_id = ?',
+            [$this->id],
+            [ParameterType::STRING]
+        );
+
+        $this->dbConn->executeQuery(
+            'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user_mark WHERE assessment_id = ?',
+            [$this->id],
+            [ParameterType::STRING]
+        );
+
+        $this->dbConn->executeQuery(
+            'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user_justification WHERE assessment_id = ?',
+            [$this->id],
+            [ParameterType::STRING]
+        );
+
+        $this->dbConn->executeQuery(
+            'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user_response WHERE assessment_id = ?',
+            [$this->id],
+            [ParameterType::STRING]
+        );
+
+        $collectionQuery =
+        'SELECT collection_id ' .
+        'FROM ' . APP__DB_TABLE_PREFIX . 'assessment ' .
+        'WHERE assessment_id = ?';
+
+        $collection = $this->dbConn->fetchOne($collectionQuery, [$this->id], [ParameterType::STRING]);
+
+        $this->dbConn->executeQuery(
+            'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'assessment WHERE assessment_id = ?',
+            [$this->id],
+            [ParameterType::STRING]
+        );
+
+        $group_handler = new GroupHandler();
+        $collection = $group_handler->get_collection($collection);
+        $collection->delete();
+
+        return true;
+    }
+
+    /**
+    * Load the Assessment from the database
+    *
+    * @param string $id id of Group to load
+    *
+    * @return boolean did load succeed
+    */
+    public function load($id)
+    {
+        $this->_locked = null;
+
+        $assessmentQuery =
+        'SELECT * ' .
+        'FROM ' . APP__DB_TABLE_PREFIX . 'assessment ' .
+        'WHERE assessment_id = ? ' .
+        'LIMIT 1';
+
+        $row = $this->dbConn->fetchAssociative($assessmentQuery, [$id], [ParameterType::STRING]);
+
+        return $row ? $this->load_from_row($row) : false;
+    }
+
+    /**
+    * Load the Assessment from the given row
+    *
+    * @param array $row associative-array of assessment information
+    *
+    * @return boolean did load sucessed
+    */
+    public function load_from_row($row)
+    {
+        $this->id = $row['assessment_id'];
+        $this->name = $row['assessment_name'];
+        $this->module_id = $row['module_id'];
+        $this->_collection_id = $row['collection_id'];
+        $this->_form_xml = $row['form_xml'];
+        $this->open_date = strtotime($row['open_date']);
+        $this->close_date = strtotime($row['close_date']);
+        $this->introduction = $row['introduction'];
+        $this->allow_feedback = ($row['allow_feedback']==1);
+        $this->assessment_type = ($row['assessment_type']); //==1);
+        $this->allow_assessment_feedback = ($row['student_feedback']);
+        $this->email_opening = ($row['email_opening']);
+        $this->email_closing = ($row['email_closing']);
+        $this->feedback_name = ($row['feedback_name']);
+
+        return true;
+    }
+
+    // /->load_from_row()
+
+    /**
+    * Save this Assessment
+    *
+    * @return boolean did save succeed
+    */
+    public function save()
+    {
+        if (!$this->id) {
+            return false;
+        }
+
+        // check if assessment already exists in the database
+        $storedAssessmentId = $this->dbConn->fetchOne(
+            'SELECT assessment_id FROM ' . APP__DB_TABLE_PREFIX . 'assessment WHERE assessment_id = ?',
+            [$this->id],
+            [ParameterType::STRING]
+        );
+
+        $queryBuilder = $this->dbConn->createQueryBuilder();
+
+        if (!empty($storedAssessmentId)) {
+            // the assessment already exists so we should update it
+            $queryBuilder
+          ->update(APP__DB_TABLE_PREFIX . 'assessment')
+          ->set('assessment_name', '?')
+          ->set('module_id', '?')
+          ->set('collection_id', '?')
+          ->set('form_xml', '?')
+          ->set('open_date', '?')
+          ->set('close_date', '?')
+          ->set('retract_date', '?')
+          ->set('introduction', '?')
+          ->set('allow_feedback', $this->allow_feedback ? 1 : 0)
+          ->set('assessment_type', $this->assessment_type ? 1 : 0)
+          ->set('student_feedback', $this->allow_assessment_feedback ? 1 : 0)
+          ->set('contact_email', '""')
+          ->set('email_opening', $this->email_opening ? 1 : 0)
+          ->set('email_closing', $this->email_closing ? 1 : 0)
+          ->set('feedback_name', '?')
+          ->set('feedback_length', 0)
+          ->set('feedback_optional', 0)
+          ->where('assessment_id = ?')
+          ->setParameter(0, $this->name)
+          ->setParameter(1, $this->module_id, ParameterType::INTEGER)
+          ->setParameter(2, $this->_collection_id)
+          ->setParameter(3, $this->_form_xml)
+          ->setParameter(4, date(MYSQL_DATETIME_FORMAT, $this->open_date))
+          ->setParameter(5, date(MYSQL_DATETIME_FORMAT, $this->close_date))
+          ->setParameter(6, date(MYSQL_DATETIME_FORMAT, $this->close_date))
+          ->setParameter(7, $this->introduction)
+          ->setParameter(8, $this->feedback_name)
+          ->setParameter(9, $this->id);
+        } else {
+            // the assessment does not exist. Create it
+            $queryBuilder
+          ->insert(APP__DB_TABLE_PREFIX . 'assessment')
+          ->values(
+              [
+                 'assessment_id' => '?',
+                 'assessment_name' => '?',
+                 'module_id' => '?',
+                 'collection_id' => '?',
+                 'form_xml' => '?',
+                 'open_date' => '?',
+                 'close_date' => '?',
+                 'retract_date' => '?',
+                 'introduction' => '?',
+                 'allow_feedback' => $this->allow_feedback ? 1 : 0,
+                 'assessment_type' => $this->assessment_type ? 1 : 0,
+                 'student_feedback' => $this->allow_assessment_feedback ? 1 : 0,
+                 'contact_email' => '""',
+                 'email_opening' => $this->email_opening ? 1 : 0,
+                 'email_closing' => $this->email_closing ? 1 : 0,
+                 'feedback_name' => '?',
+                 'feedback_length' => 0,
+                 'feedback_optional' => 0,
+              ]
+          )
+          ->setParameter(0, $this->id)
+          ->setParameter(1, $this->name)
+          ->setParameter(2, $this->module_id, ParameterType::INTEGER)
+          ->setParameter(3, $this->_collection_id)
+          ->setParameter(4, $this->_form_xml)
+          ->setParameter(5, date(MYSQL_DATETIME_FORMAT, $this->open_date))
+          ->setParameter(6, date(MYSQL_DATETIME_FORMAT, $this->close_date))
+          ->setParameter(7, date(MYSQL_DATETIME_FORMAT, $this->close_date))
+          ->setParameter(8, $this->introduction)
+          ->setParameter(9, $this->feedback_name);
+        }
+
+        $queryBuilder->execute();
+
+        return true;
+    }
+
+    /*
+    * --------------------------------------------------------------------------------
+    * Other Methods
+    * --------------------------------------------------------------------------------
+    */
+
+    /**
+    * Create a clone of this assessment
+    * @return mixed
+    */
+    public function & get_clone()
+    {
+        $clone_assessment = new Assessment($this->_DAO);
+        $clone_assessment->load($this->id);   // Creates an EXACT clone of this assessment
+        $clone_assessment->create();
+        return $clone_assessment;
+    }
+
+    /*
+    * --------------------------------------------------------------------------------
+    * Accessor Methods
+    * --------------------------------------------------------------------------------
+    */
+
+    public function get_db()
+    {
+        return $this->_DAO;
+    }
+
+    public function get_form()
+    {
+        // Get the number of questions used in this assessment, and create an array of that size
+        $form = new Form($this->get_db());
+        $form_xml =& $this->_form_xml;
+        $form->load_from_xml($form_xml);
+
+        return $form;
+    }
+
+    // /->get_form()
+
+    public function get_form_xml()
+    {
+        return $this->_form_xml;
+    }
+
+    // /->get_form_xml()
+
+    /**
+     * Get the group marks.
+     *
+     */
+    public function get_group_marks()
+    {
+        $groups_and_marks = [];
+
+        $groupsAndMarksQuery =
+        'SELECT group_mark_xml ' .
+        'FROM ' . APP__DB_TABLE_PREFIX . 'assessment_group_marks ' .
+        'WHERE assessment_id = ?';
+
+        $group_marks_xml = $this->dbConn->fetchOne($groupsAndMarksQuery, [$this->id], [ParameterType::STRING]);
+
+        if ($group_marks_xml) {
+            $xml_parser = new XMLParser();
+            $xml_array = $xml_parser->parse($group_marks_xml);
+
+            // If there's more than 1 group that's fine, else make it a 0-based array of 1 group
+            if (array_key_exists(0, $xml_array['groups']['group'])) {
+                $groups = $xml_array['groups']['group'];
+            } else {
+                $groups[0] = $xml_array['groups']['group'];
+            }
+            foreach ($groups as $i => $group) {
+                $groups_and_marks["{$group['_attributes']['id']}"] = $group['_attributes']['mark'];
+            }
+        }
+
+        return $groups_and_marks;
+    }
+
+    // /->get_group_marks()
+
+    public function set_form_xml($xml)
+    {
+        $this->_form_xml = $xml;
+    }
+
+    // /->set_form_xml()
+
+    public function get_collection_id()
+    {
+        return $this->_collection_id;
+    }
+
+    // /->get_collection_id()
+
+    public function set_collection_id($collection_id)
+    {
+        $this->_collection_id = $collection_id;
     }
-    $this->id = $new_id;
-  }// ->create()
-
-  /**
-  * Delete this Assessment
-  *
-  * @return boolean true
-  */
-  function delete() {
-    $this->_DAO->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "assessment_group_marks WHERE assessment_id = '{$this->id}'");
-    $this->_DAO->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "assessment_marking WHERE assessment_id = '{$this->id}'");
-    $this->_DAO->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "user_mark WHERE assessment_id = '{$this->id}'");
-    $this->_DAO->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "user_justification WHERE assessment_id = '{$this->id}'");
-    $this->_DAO->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "user_response WHERE assessment_id = '{$this->id}'");
-    $collection = $this->_DAO->fetch_value("SELECT collection_id FROM " . APP__DB_TABLE_PREFIX . "assessment WHERE assessment_id = '{$this->id}'");
-    $this->_DAO->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "assessment WHERE assessment_id = '{$this->id}'");
-    $group_handler = new GroupHandler();
-    $collection = $group_handler->get_collection($collection);
-    $collection->delete();
-    return true;
-  }// /->delete()
-
-  /**
-  * Load the Assessment from the database
-  *
-  * @param string $id id of Group to load
-  *
-  * @return boolean did load succeed
-  */
-  function load($id) {
-    $this->_locked = null;
-
-    $row = $this->_DAO->fetch_row("SELECT * FROM " . APP__DB_TABLE_PREFIX . "assessment WHERE assessment_id = '$id' LIMIT 1");
-    return ($row) ? $this->load_from_row($row) : false;
-  }// /->load()
-
-  /**
-  * Load the Assessment from the given row
-  *
-  * @param array $row associative-array of assessment information
-  *
-  * @return boolean did load sucessed
-  */
-  function load_from_row($row) {
-    $this->id = $row['assessment_id'];
-    $this->name = $row['assessment_name'];
-    $this->module_id = $row['module_id'];
-    $this->_collection_id = $row['collection_id'];
-    $this->_form_xml = $row['form_xml'];
-    $this->open_date = strtotime($row['open_date']);
-    $this->close_date = strtotime($row['close_date']);
-    $this->introduction = $row['introduction'];
-    $this->allow_feedback = ($row['allow_feedback']==1);
-    $this->assessment_type = ($row['assessment_type']); //==1);
-    $this->allow_assessment_feedback = ($row['student_feedback']);
-    $this->email_opening = ($row['email_opening']);
-    $this->email_closing = ($row['email_closing']);
-    $this->feedback_name = ($row['feedback_name']);
-
-    return true;
-  }// /->load_from_row()
-
-  /**
-  * Save this Assessment
-  *
-  * @return boolean did save succeed
-  */
-  function save() {
-    if (!$this->id) {
-      return false;
-    } else {
-      // Save the Form
-      $fields = array (
-      	       'assessment_id'    => $this->id ,
-               'assessment_name'    => $this->name ,
-               'module_id'       => $this->module_id ,
-               'collection_id'    => $this->_collection_id ,
-               'form_xml'       => $this->_form_xml ,
-               'open_date'      => date(MYSQL_DATETIME_FORMAT, $this->open_date) ,
-               'close_date'     => date(MYSQL_DATETIME_FORMAT, $this->close_date) ,
-               'retract_date'     => date(MYSQL_DATETIME_FORMAT, $this->close_date) ,
-               'introduction'     => $this->introduction ,
-               'allow_feedback'   => ($this->allow_feedback) ? 1 : 0 ,
-               'assessment_type'    => ($this->assessment_type)? 1 : 0 ,
-               'student_feedback'   => ($this->allow_assessment_feedback)? 1 : 0 ,
-               'contact_email'    => '' ,
-               'email_opening'    => ($this->email_opening)? 1 : 0 ,
-               'email_closing'    =>($this->email_closing)? 1 : 0 ,
-               'feedback_name'    => $this->feedback_name ,
-               'feedback_length'    => 0 ,
-               'feedback_optional'    => 0
-      );
-
-      $ass_name = $this->_DAO->escape_str($fields['assessment_name']);
-      $ass_intro = $this->_DAO->escape_str($fields['introduction']);
-      $xml = $this->_DAO->_prepare_field_value($fields['form_xml']);
-
-      $sql = 'INSERT INTO ' . APP__DB_TABLE_PREFIX . 'assessment ({fields}) VALUES ({values}) ';
-      $sql .= "ON DUPLICATE KEY UPDATE assessment_name = '{$ass_name}', module_id = {$fields['module_id']}, " .
-              "collection_id = '{$fields['collection_id']}', form_xml = {$xml}, " .
-              "open_date = '{$fields['open_date']}', close_date = '{$fields['close_date']}', " .
-              "retract_date = '{$fields['retract_date']}', " .
-              "introduction = '{$ass_intro}', allow_feedback = {$fields['allow_feedback']}, " .
-              "assessment_type = {$fields['assessment_type']}, student_feedback = {$fields['student_feedback']}, " .
-              "contact_email = '{$fields['contact_email']}', " .
-              "email_opening = {$fields['email_opening']}, email_closing = {$fields['email_closing']}, " .
-              "feedback_name = '{$fields['feedback_name']}', " .
-              "feedback_length = {$fields['feedback_length']}, feedback_optional = {$fields['feedback_optional']}";
-      $this->_DAO->do_insert($sql, $fields);
-
-      return true;
+
+    // /->set_collection_id()
+
+    /*
+    * Get the current status of this assessment
+    *
+    * @return  string  ['pending','open','closed','finished']
+    */
+    public function get_status()
+    {
+        $now = time();
+
+        $status = 'unknown';
+        if ($this->open_date > $now) {
+            $status = 'pending';
+        }
+        if ($this->open_date < $now) {
+            $status = 'open';
+        }
+        if ($this->close_date < $now) {
+            $status = 'closed';
+        }
+        if ($this->_finished) {
+            $status = 'finished';
+        }
+
+        return $status;
     }
-  }// /->save()
-
-/*
-* --------------------------------------------------------------------------------
-* Other Methods
-* --------------------------------------------------------------------------------
-*/
-
-  /**
-  * Create a clone of this assessment
-  * @return mixed
-  */
-  function & get_clone() {
-    $clone_assessment = new Assessment($this->_DAO);
-    $clone_assessment->load($this->id);   // Creates an EXACT clone of this assessment
-    $clone_assessment->create();
-    return $clone_assessment;
-  }
-
-/*
-* --------------------------------------------------------------------------------
-* Accessor Methods
-* --------------------------------------------------------------------------------
-*/
-
-  function get_db() {
-    return $this->_DAO;
-  }// /->get_db
-
-  function get_form() {
-    // Get the number of questions used in this assessment, and create an array of that size
-    $form = new Form($db);
-    $form_xml =& $this->_form_xml;
-    $form->load_from_xml($form_xml);
-
-    return $form;
-  }// /->get_form()
-
-  function get_form_xml() {
-    return $this->_form_xml;
-  }// /->get_form_xml()
-
-  /**
-   * Get the group marks.
-   *
-   */
-  function get_group_marks() {
-    $groups_and_marks = array();
-
-    $group_marks_xml = $this->_DAO->fetch_value("
-       SELECT group_mark_xml
-       FROM " . APP__DB_TABLE_PREFIX . "assessment_group_marks
-       WHERE assessment_id = '{$this->id}'");
-
-    if ($group_marks_xml) {
-      $xml_parser = new XMLParser();
-      $xml_array = $xml_parser->parse($group_marks_xml);
-
-      // If there's more than 1 group that's fine, else make it a 0-based array of 1 group
-      if (array_key_exists(0, $xml_array['groups']['group'])) {
-        $groups = $xml_array['groups']['group'];
-      } else {
-        $groups[0] = $xml_array['groups']['group'];
-      }
-      foreach($groups as $i => $group) {
-        $groups_and_marks["{$group['_attributes']['id']}"] = $group['_attributes']['mark'];
-      }
+
+    // /->get_status
+
+    /**
+     * function to get the date string
+     * @param date $date
+     * @return string formated date
+    */
+    public function get_date_string($date)
+    {
+        $date_format = 'D, jS F, Y \a\t G:i';
+        if ($date == 'open_date') {
+            return date($date_format, $this->open_date);
+        }
+        if ($date == 'close_date') {
+            return date($date_format, $this->close_date);
+        }
     }
 
-    return $groups_and_marks;
-  }// /->get_group_marks()
-
-  function set_form_xml($xml) {
-    $this->_form_xml = $xml;
-  }// /->set_form_xml()
-
-  function get_collection_id() {
-    return $this->_collection_id;
-  }// /->get_collection_id()
-
-  function set_collection_id($collection_id) {
-    $this->_collection_id = $collection_id;
-  }// /->set_collection_id()
-
-  /*
-  * Get the current status of this assessment
-  *
-  * @return  string  ['pending','open','closed','finished']
-  */
-  function get_status() {
-    $now = time();
-
-    $status = 'unknown';
-    if ($this->open_date > $now) { $status = 'pending'; }
-    if ($this->open_date < $now) { $status = 'open'; }
-    if ($this->close_date < $now) { $status = 'closed'; }
-    if ($this->_finished) { $status = 'finished'; }
-
-    return $status;
-  }// /->get_status
-
-  /**
-   * function to get the date string
-   * @param date $date
-   * @return string formated date
-  */
-  function get_date_string($date) {
-    $date_format = 'D, jS F, Y \a\t G:i';
-    if ($date == 'open_date') { return date($date_format,$this->open_date); }
-    if ($date == 'close_date') { return date($date_format,$this->close_date); }
-  }// /->get_date_string()
-
-  /**
-   * Get all the marksheets available for this assessment.
-   *
-   * Output of the form: array ( date_created => array ( <params> ) )
-   *
-   * @return  mixed  An assoc array of marksheets available. On fail, null.
-   */
-  function get_all_marking_params() {
-    $params = null;
-
-    $mark_sheets = $this->_DAO->fetch("
-      SELECT date_created, marking_params
-      FROM " . APP__DB_TABLE_PREFIX . "assessment_marking
-      WHERE assessment_id = '{$this->id}'
-      ORDER BY date_created ASC
-    ");
-
-    if ($mark_sheets) {
-      foreach($mark_sheets as $i => $mark_sheet) {
-        $params[$mark_sheet['date_created']] = $this->_parse_marking_params($mark_sheet['marking_params']);
-      }
+    // /->get_date_string()
+
+    /**
+     * Get all the marksheets available for this assessment.
+     *
+     * Output of the form: array ( date_created => array ( <params> ) )
+     *
+     * @return  mixed  An assoc array of marksheets available. On fail, null.
+     */
+    public function get_all_marking_params()
+    {
+        $params = null;
+
+        $markSheetsQuery =
+      'SELECT date_created, marking_params ' .
+      'FROM ' . APP__DB_TABLE_PREFIX . 'assessment_marking ' .
+      'WHERE assessment_id = ? ' .
+      'ORDER BY date_created ASC';
+
+        $mark_sheets = $this->dbConn->fetchAllAssociative($markSheetsQuery, [$this->id], [ParameterType::STRING]);
+
+        if ($mark_sheets) {
+            foreach ($mark_sheets as $i => $mark_sheet) {
+                $params[$mark_sheet['date_created']] = $this->_parse_marking_params($mark_sheet['marking_params']);
+            }
+        }
+
+        return $params;
     }
 
-    return $params;
-  }// /->get_all_marking_params()
-
-  /**
-   * Enter description here...
-   *
-   * @param  datetime  $marksheet_id  The marksheet to load
-   *
-   * return  mixed  An array of marking parameters. On fail, null.
-   */
-  function get_marking_params($marksheet_id) {
-    $params = null;
-
-    $marking_date_sql = date(MYSQL_DATETIME_FORMAT, $marksheet_id);
-
-    $marking_params = $this->_DAO->fetch_value("SELECT marking_params
-                          FROM " . APP__DB_TABLE_PREFIX . "assessment_marking
-                          WHERE assessment_id = '{$this->id}'
-                            AND date_created='$marking_date_sql'
-                          LIMIT 1");
-    if ($marking_params) {
-      $params = $this->_parse_marking_params($marking_params);
+    // /->get_all_marking_params()
+
+    /**
+     * Enter description here...
+     *
+     * @param  datetime  $marksheet_id  The marksheet to load
+     *
+     * return  mixed  An array of marking parameters. On fail, null.
+     */
+    public function get_marking_params($marksheet_id)
+    {
+        $params = null;
+
+        $marking_date_sql = date(MYSQL_DATETIME_FORMAT, $marksheet_id);
+
+        $markingParamsQuery =
+        'SELECT marking_params ' .
+        'FROM ' . APP__DB_TABLE_PREFIX . 'assessment_marking ' .
+        'WHERE assessment_id = ? ' .
+        'AND date_created = ? ' .
+        'LIMIT 1';
+
+        $marking_params = $this->dbConn->fetchOne($markingParamsQuery, [$this->id, $marking_date_sql], [ParameterType::STRING, ParameterType::STRING]);
+
+        if ($marking_params) {
+            $params = $this->_parse_marking_params($marking_params);
+        }
+
+        return $params;
     }
 
-    return $params;
-  }// /->get_marking_params()
-
-  /**
-  * Is this Assessment locked for editing
-  *
-  * @return bool lock status
-  */
-  function is_locked() {
-    if (is_null($this->_locked)) {
-      $result_count = $this->_DAO->fetch_value("SELECT COUNT(assessment_id)
-                           FROM " . APP__DB_TABLE_PREFIX . "user_mark
-                           WHERE assessment_id = '{$this->id}'");
-
-      $this->_locked = ($result_count>0);
+    // /->get_marking_params()
+
+    /**
+    * Is this Assessment locked for editing
+    *
+    * @return bool lock status
+    */
+    public function is_locked()
+    {
+        if (is_null($this->_locked)) {
+            $countAssessmentsQuery =
+          'SELECT COUNT(assessment_id) ' .
+          'FROM ' . APP__DB_TABLE_PREFIX . 'user_mark ' .
+          'WHERE assessment_id = ?';
+
+            $result_count = $this->dbConn->fetchOne($countAssessmentsQuery, [$this->id], [ParameterType::STRING]);
+
+            $this->_locked = ($result_count>0);
+        }
+        return $this->_locked;
     }
-    return $this->_locked;
-  }// /->is_locked()
 
-  /**
-  * Set database connection
-  * @param  object  $db  The database connection object to use
-  */
-  function set_db(& $db) {
-    $this->_DAO =& $db;
-  }// /->set_db()
+    // /->is_locked()
 
-/*
-* --------------------------------------------------------------------------------
-* Methods
-* --------------------------------------------------------------------------------
-*/
+    /**
+    * Set database connection
+    * @param  object  $db  The database connection object to use
+    */
+    public function set_db(& $db)
+    {
+        $this->_DAO =& $db;
+    }
 
-  /*
-  * Finish this assessment, save settings and lock from editing/marking
-  */
-  function finish() {
-  }// /->finish()
+    // /->set_db()
 
-/*
-* ================================================================================
-* Private Methods
-* ================================================================================
-*/
+    /*
+    * --------------------------------------------------------------------------------
+    * Methods
+    * --------------------------------------------------------------------------------
+    */
 
-  protected function _parse_marking_params($marking_params_xml) {
-    $params = null;
+    // Finish this assessment, save settings and lock from editing/marking
+    public function finish()
+    {
+    }
+
+    // /->finish()
 
-    if (!is_object($this->_xml_parser)) { $xml_parser = new XMLParser(); }
+    /*
+    * ================================================================================
+    * Private Methods
+    * ================================================================================
+    */
 
-    $xml_array = $xml_parser->parse($marking_params_xml);
+    protected function _parse_marking_params($marking_params_xml)
+    {
+        $params = null;
 
-    $params['weighting'] = $xml_array['parameters']['weighting']['_attributes']['value'];
-    $params['penalty'] = $xml_array['parameters']['penalty']['_attributes']['value'];
+        if (!is_object($this->_xml_parser)) {
+            $xml_parser = new XMLParser();
+        }
 
-    $params['penalty_type'] = (array_key_exists('penalty_type', $xml_array['parameters'])) ? $xml_array['parameters']['penalty_type']['_attributes']['value'] : '%' ;
+        $xml_array = $xml_parser->parse($marking_params_xml);
 
-    $params['tolerance'] = (array_key_exists('tolerance', $xml_array['parameters'])) ? $xml_array['parameters']['tolerance']['_attributes']['value'] : null ;
+        $params['weighting'] = $xml_array['parameters']['weighting']['_attributes']['value'];
+        $params['penalty'] = $xml_array['parameters']['penalty']['_attributes']['value'];
 
-    $params['grading'] = (array_key_exists('grading', $xml_array['parameters'])) ? $xml_array['parameters']['grading']['_attributes']['value'] : 'numeric' ;
+        $params['penalty_type'] = (array_key_exists('penalty_type', $xml_array['parameters'])) ? $xml_array['parameters']['penalty_type']['_attributes']['value'] : '%' ;
 
-    $params['algorithm'] = (array_key_exists('algorithm', $xml_array['parameters'])) ? $xml_array['parameters']['algorithm']['_attributes']['value'] : 'webpa' ;
+        $params['tolerance'] = (array_key_exists('tolerance', $xml_array['parameters'])) ? $xml_array['parameters']['tolerance']['_attributes']['value'] : null ;
 
-    return $params;
-  }// /->_parse_marking_params()
+        $params['grading'] = (array_key_exists('grading', $xml_array['parameters'])) ? $xml_array['parameters']['grading']['_attributes']['value'] : 'numeric' ;
 
-}// /class: Assessment
+        $params['algorithm'] = (array_key_exists('algorithm', $xml_array['parameters'])) ? $xml_array['parameters']['algorithm']['_attributes']['value'] : 'webpa' ;
 
-?>
+        return $params;
+    }
+}
diff --git a/src/includes/classes/Authenticator.php b/src/includes/classes/Authenticator.php
index 9833872..38ac667 100644
--- a/src/includes/classes/Authenticator.php
+++ b/src/includes/classes/Authenticator.php
@@ -12,35 +12,50 @@
 
 namespace WebPA\includes\classes;
 
+use Doctrine\DBAL\ParameterType;
+
 class Authenticator
 {
+    // Public variables
+    public $user_id;
+
+    public $source_id;
+
+    public $user_type;
+
+    public $module_id;
+
+    public $module_code;
+
+    // Private variables
+    protected $username;
+
+    protected $password;
+
+    protected $_authenticated = false;
+
+    protected $_disabled;
+
+    protected $_error;
+
+    private $_DAO;
 
-// Public variables
-    public $user_id = NULL;
-    public $source_id = NULL;
-    public $user_type = NULL;
-    public $module_id = NULL;
-    public $module_code = NULL;
-
-// Private variables
-    protected $username = NULL;
-    protected $password = NULL;
-    protected $_authenticated = FALSE;
-    protected $_disabled = NULL;
-    protected $_error = NULL;
-    private $_DAO = NULL;
     private $cis;
 
+    private $dbConn;
+
     /**
      *  CONSTRUCTOR for the Authenticator class
      */
-    public function __construct(EngCIS $cis, $username = NULL, $password = NULL)
+    public function __construct(EngCIS $cis, $username = null, $password = null)
     {
         $this->cis = $cis;
 
         $this->username = $username;
         $this->password = $password;
-    }// /->Authenticator()
+    }
+
+    // /->Authenticator()
 
     /*
     ================================================================================
@@ -48,43 +63,53 @@ public function __construct(EngCIS $cis, $username = NULL, $password = NULL)
     ================================================================================
     */
 
-    /*
-    Initialise the user details
-    */
-    function initialise($sql)
+    /**
+     * Initialise the user details.
+     *
+     * @param $user
+     *
+     * @return bool
+     */
+    public function initialise($user)
     {
-        $this->user_type = NULL;
-        $this->_authenticated = FALSE;
-        $this->_disabled = TRUE;
+        $this->user_type = null;
+        $this->_authenticated = false;
+        $this->_disabled = true;
 
-        $is_admin = FALSE;
+        $is_admin = false;
         $DAO = $this->get_DAO();
-        $user_data = $DAO->fetch_row($sql);
-        if (!is_null($user_data)) {
-            $is_admin = $user_data['admin'] == 1;
-            $source_id = $user_data['source_id'];
+        $this->dbConn = $DAO->getConnection();
+
+        if (!is_null($user)) {
+            $is_admin = $user['admin'] == 1;
+            $source_id = $user['source_id'];
+
+            $this->module_id = $user['last_module_id'];
 
-            $this->module_id = $user_data['last_module_id'];
             if (!empty($this->module_id)) {
                 if (!$is_admin) {
-                    $sql_user_module = 'SELECT module_id, user_type FROM ' . APP__DB_TABLE_PREFIX . "user_module WHERE module_id = {$user_data['last_module_id']} AND user_id = {$user_data['user_id']}";
-                    $user_module = $DAO->fetch_row($sql_user_module);
-                    if (is_null($user_module)) {
-                        $this->module_id = NULL;
+                    $userModuleQuery = 'SELECT module_id, user_type FROM ' . APP__DB_TABLE_PREFIX . 'user_module WHERE module_id = ? AND user_id = ?';
+
+                    $userModule = $this->dbConn->fetchAssociative($userModuleQuery, [$user['last_module_id'], $user['user_id']], [ParameterType::INTEGER, ParameterType::INTEGER]);
+
+                    if (is_null($userModule)) {
+                        $this->module_id = null;
                     }
                 } else {
-                    $sql_admin_module = 'SELECT source_id FROM ' . APP__DB_TABLE_PREFIX . "module WHERE module_id = {$user_data['last_module_id']}";
-                    $admin_module = $DAO->fetch_row($sql_admin_module);
-                    if (!is_null($admin_module)) {
-                        $source_id = $admin_module['source_id'];
+                    $adminModuleQuery = 'SELECT source_id FROM ' . APP__DB_TABLE_PREFIX . 'module WHERE module_id = ?';
+
+                    $adminModule = $this->dbConn->fetchAssociative($adminModuleQuery, [$user['last_module_id']], [ParameterType::INTEGER]);
+
+                    if (!is_null($adminModule)) {
+                        $source_id = $adminModule['source_id'];
                     }
                 }
             }
             if (empty($this->module_id)) {
                 if ($is_admin) {
-                    $modules = $this->cis->get_user_modules(NULL, NULL, NULL, $source_id);
+                    $modules = $this->cis->get_user_modules(null, null, null, $source_id);
                 } else {
-                    $modules = $this->cis->get_user_modules($user_data['user_id']);
+                    $modules = $this->cis->get_user_modules($user['user_id']);
                 }
                 if (count($modules) > 0) {
                     $ids = array_keys($modules);
@@ -93,114 +118,117 @@ function initialise($sql)
             }
 
             if (!empty($this->module_id)) {
+                $moduleQuery = 'SELECT module_code FROM ' . APP__DB_TABLE_PREFIX . 'module WHERE module_id = ?';
+
+                $moduleCode = $this->dbConn->fetchOne($moduleQuery, [$this->module_id], [ParameterType::INTEGER]);
 
-                $sql_module = 'SELECT module_code FROM ' . APP__DB_TABLE_PREFIX . "module WHERE module_id = {$this->module_id}"; // AND source_id = '{$source_id}'";
-                $module = $DAO->fetch_row($sql_module);
-                if (is_null($module)) {
-                    $this->module_id = NULL;
+                if (is_null($moduleCode)) {
+                    $this->module_id = null;
                 } else {
-                    $this->module_code = $module['module_code'];
+                    $this->module_code = $moduleCode;
                 }
             }
 
             if (!is_null($this->module_id)) {
+                $userTypeQuery = 'SELECT user_type FROM ' . APP__DB_TABLE_PREFIX . 'user_module WHERE module_id = ? AND user_id = ?';
 
-                $sql_user_module = 'SELECT user_type FROM ' . APP__DB_TABLE_PREFIX . "user_module WHERE module_id = {$this->module_id} AND user_id = {$user_data['user_id']}";
-                $user_module = $DAO->fetch_row($sql_user_module);
+                $userType = $this->dbConn->fetchOne($userTypeQuery, [$this->module_id, $user['user_id']], [ParameterType::INTEGER, ParameterType::INTEGER]);
 
                 // Update last login date
                 $now = date(MYSQL_DATETIME_FORMAT, time());
-                $sql_login_date = 'UPDATE ' . APP__DB_TABLE_PREFIX . "user SET date_last_login = '{$now}' WHERE user_id = '{$user_data['user_id']}'";
-                $DAO->execute($sql_login_date);
+                $sql_login_date =
+                    'UPDATE ' . APP__DB_TABLE_PREFIX . 'user ' .
+                    'SET date_last_login = ? ' .
+                    'WHERE user_id = ?';
+
+                $stmt = $this->dbConn->prepare($sql_login_date);
+
+                $stmt->bindParam(1, $now);
+                $stmt->bindParam(2, $user['user_id'], ParameterType::INTEGER);
+
+                $stmt->execute();
 
                 //with the database row data returned get all the information and add it to the class holders
-                $this->user_id = $user_data['user_id'];
+                $this->user_id = $user['user_id'];
                 $this->source_id = $source_id;
                 if (!$is_admin) {
-                    $this->user_type = $user_module['user_type'];
+                    $this->user_type = $userType;
                 } else {
                     $this->user_type = APP__USER_TYPE_ADMIN;
                 }
 
-                $this->_disabled = ($user_data['disabled'] == 1);
+                $this->_disabled = ($user['disabled'] == 1);
                 $this->_authenticated = !$this->_disabled;
-
             }
-
         }
 
         return $this->_authenticated;
-
     }
 
-    /*
-    Is the user authenticated?
-    */
-    function is_authenticated()
+    // Is the user authenticated?
+    public function is_authenticated()
     {
         return $this->_authenticated;
-    }// /->is_authenticated()
+    }
 
-    /*
-    Is the user disabled?
-    */
-    function is_disabled()
+    // /->is_authenticated()
+
+    // Is the user disabled?
+    public function is_disabled()
     {
         return $this->_disabled;
-    }// /->is_disabled()
+    }
 
-    /*
-    Is this user admin?
-    */
-    function is_admin()
+    // /->is_disabled()
+
+    // Is this user admin?
+    public function is_admin()
     {
-        return ($this->user_type == APP__USER_TYPE_ADMIN);
-    }// /->is_admin()
+        return $this->user_type == APP__USER_TYPE_ADMIN;
+    }
 
-    /*
-    Is this user staff?
-    */
-    function is_staff()
+    // /->is_admin()
+
+    // Is this user staff?
+    public function is_staff()
     {
         return ($this->user_type == APP__USER_TYPE_TUTOR) || ($this->user_type == APP__USER_TYPE_ADMIN);
-    }// /->is_staff()
+    }
 
-    /*
-    Is this user tutor?
-    */
-    function is_tutor()
+    // /->is_staff()
+
+    // Is this user tutor?
+    public function is_tutor()
     {
-        return ($this->user_type == APP__USER_TYPE_TUTOR);
-    }// /->is_staff()
+        return $this->user_type == APP__USER_TYPE_TUTOR;
+    }
 
-    /*
-    Is this user student?
-    */
-    function is_student()
+    // /->is_staff()
+
+    // Is this user student?
+    public function is_student()
     {
-        return ($this->user_type == APP__USER_TYPE_STUDENT);
-    }// /->is_student()
+        return $this->user_type == APP__USER_TYPE_STUDENT;
+    }
 
-    /*
-    Get the last authorisation error
-    */
-    function get_error()
+    // /->is_student()
+
+    // Get the last authorisation error
+    public function get_error()
     {
         return $this->_error;
-    }// /->get_error()
+    }
 
-    /*
-    Get the DAO object
-    */
-    function get_DAO()
-    {
+    // /->get_error()
 
+    // Get the DAO object
+    public function get_DAO()
+    {
         if (is_null($this->_DAO)) {
             $this->_DAO = new DAO(APP__DB_HOST, APP__DB_USERNAME, APP__DB_PASSWORD, APP__DB_DATABASE);
         }
 
         return $this->_DAO;
-
     }
 
     /*
@@ -208,7 +236,4 @@ function get_DAO()
       PRIVATE
     ================================================================================
     */
-
 }// /class Authenticator
-
-?>
diff --git a/src/includes/classes/DAO.php b/src/includes/classes/DAO.php
index 65e2bcb..497c7d8 100644
--- a/src/includes/classes/DAO.php
+++ b/src/includes/classes/DAO.php
@@ -1,8 +1,7 @@
 <?php
+
 /**
- * Class : DAO
- *
- * This data access object is designed for MySQL only
+ * The database access object which serves a Doctrine DBAL connection.
  *
  * @copyright Loughborough University
  * @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL version 3
@@ -12,657 +11,44 @@
 
 namespace WebPA\includes\classes;
 
+use Doctrine\DBAL\Connection;
+use Doctrine\DBAL\DriverManager;
+
 class DAO
 {
-    // Public Vars
-
-    // Private Vars
-    private $_host = '';        // DB Connection info
-    private $_user = '';
-    private $_password = '';
-    private $_database = '';
-    private $_persistent = false;
-
-    private $_conn = null;        // DB Connection object
-
-    private $_result_set = null;    // Contains the result set (temporarily)
-    private $_result_cols = null;   // Array of columns for the result set
-
-    private $_last_sql = null;      // Last query run
-    private $_result = [];      // Query results, as array of row objects
-
-    private $_output_type = 'ARRAY_A';  // 'ARRAY_A': Associative Array : $results[row]['field']
-    // 'ARRAY_N': Numeric Array : $results[row][col]
-    // 'ARRAY_B': Assoc + Numeric Array : use $results[row]['field'] or $results[row][col]
-
-    private $_output_type_int = MYSQLI_ASSOC;  // MYSQLI_ASSOC, MYSQLI_BOTH, MYSQLI_NUM
-
-    private $_insert_id = null;     // Last inserted id (on auto-increment columns)
-
-    private $_num_cols = null;
-    private $_num_rows = null;
-    private $_num_affected = null;
-
-    private $_debug = false;      // debug mode (default: off)
-    private $_last_error = null;
+    private Connection $_conn;
 
     /**
-     * CONSTRUCTOR
-     * Set database connection strings
+     * Set up the doctrine connection.
+     *
      * @param string $host
      * @param string $user
      * @param string $password
      * @param string $database
      * @param boolean $persistent
-     */
-    function __construct($host, $user, $password, $database, $persistent = false)
-    {
-        $this->_host = $host;
-        $this->_user = $user;
-        $this->_password = $password;
-        $this->_database = $database;
-        $this->_persistent = $persistent;
-    } // /DAO()
-
-    /*
-    * ================================================================================
-    * Public Methods
-    * ================================================================================
-    */
-
-    /**
-     * Open database connection
-     * @param boolean $new_link block reusing an existing database connection when the same server/username/password are used
-     * @return boolean
-     */
-    function open($new_link = true)
-    {
-        if (is_null($this->_conn)) {
-            if ($this->_persistent) {
-                $func = 'mysqli_pconnect';
-            } else {
-                $func = 'mysqli_connect';
-            }
-
-            if ($this->_debug) {
-                $this->_conn = $func($this->_host, $this->_user, $this->_password, $this->_database);
-
-                if (!$this->_conn) {
-                    die ('Can\'t use database due to  : ' . mysqli_connect_errno() . ' - ' . mysqli_connect_error());
-
-                    return false;
-                }
-
-                return true;
-            } else {
-                $this->_conn = $func($this->_host, $this->_user, $this->_password, $this->_database);
-
-                if (!$this->_conn) {
-                    die ('Can\'t use database due to  : ' . mysqli_connect_errno() . ' - ' . mysqli_connect_error());
-
-                    return false;
-                }
-
-                return true;
-            }
-
-        }
-
-        return true;
-    } // /->open()
-
-    /**
-     * Close database connection.
      *
-     * @return bool
+     * @return void
      */
-    function close()
+    public function __construct($host, $user, $password, $database, $persistent = false)
     {
-        $this->flush();
-        $isClosed = @mysqli_close($this->_conn);
-        $this->_conn = null;
+        $connectionParams = [
+            'dbname' => $database,
+            'user' => $user,
+            'password' => $password,
+            'host' => $host,
+            'driver' => 'mysqli',
+        ];
 
-        return $isClosed;
+        $this->_conn = DriverManager::getConnection($connectionParams);
     }
 
     /**
-     * Clear results and reset result vars
-     */
-    function flush()
-    {
-        $this->_result = [];
-        $this->_num_rows = null;
-        $this->_num_affected = null;
-        $this->_insert_id = null;
-    } // /->flush()
-
-    /**
-     * Execute the SQL query, and ignore results (ie, not a SELECT)
-     * Sets affected rows (ie could be DELETE/INSERT/REPLACE/UPDATE)
-     * Sets inserted id if query is INSERT/REPLACE (checks first word of query)
-     * @param string $sql
-     * @return boolean
-     */
-    function execute($sql)
-    {
-
-        $this->flush();
-        $this->open();
-        $this->_last_sql = trim($sql);  // Save query
-
-        if ($this->_debug) {
-            $this->_result_set = mysqli_query($this->_conn, $sql) or $this->_throw_error('Executing SQL');
-        } else {
-            $this->_result_set = @mysqli_query($this->_conn, $sql);
-        }
-
-        if ($this->_result_set) {
-            $this->_num_affected = mysqli_affected_rows($this->_conn);
-
-            if (preg_match("/^\\s*(insert|replace) /i", $sql)) {
-                $this->_insert_id = mysqli_insert_id($this->_conn);
-            }
-
-            if ($this->_num_affected) {
-                return true;
-            } else {
-                return false;
-            }
-        } else {
-            return false;
-        }
-    }// /->execute()
-
-    /**
-     * Get results of the given query
-     * @param string $sql
-     * @return object
-     */
-    function fetch($sql = null)
-    {
-        // If there is an SQL query, get its results instead..
-        if ($sql) {
-            $this->_process_query($sql);
-        }
-
-        return $this->_result;
-    } // /->fetch()
-
-    /**
-     * Get a single row (of the given query or cache)
-     * Row indexes are 0-based
-     * @param string $sql
-     * @param integer $y
-     * @return object
-     */
-    function fetch_row($sql = null, $y = 0)
-    {
-        // If there is an SQL query, get its results instead..
-        if ($sql) {
-            $this->_process_query($sql);
-        }
-        return isset($this->_result[$y]) ? $this->_result[$y] : null;
-    } // /->fetch_row()
-
-    /**
-     * Get a single column as a numeric array
-     * column indexes are 0-based
-     * @param string $sql
-     * @param integer $x
-     * @return array
-     */
-    function fetch_col($sql = null, $x = 0)
-    {
-        // If there is an SQL query, get its results instead..
-        if ($sql) {
-            $this->_process_query($sql);
-        }
-
-        $new_array = null;
-
-        // Extract the column value
-        if ($this->_num_rows > 0) {
-            for ($i = 0; $i < $this->_num_rows; $i++) {
-                $new_array[$i] = $this->fetch_value(null, $x, $i);
-            }
-        }
-        return $new_array;
-    } // /->fetch_col()
-
-    /**
-     * Get a single value from the result set. Column/row indexes are 0-based. An empty string ('') or no value, will
-     * return null
-     *
-     * @param string $sql
-     * @param integer $x
-     * @param integer $y
-     *
-     * @return integer
-     */
-    function fetch_value($sql = null, $x = 0, $y = 0)
-    {
-        // If there is an SQL query, get its results instead
-        if ($sql) {
-            $this->_process_query($sql);
-        }
-
-        // Extract value using x,y vals
-        if (!empty($this->_result) && isset($this->_result[$y])) {
-            $values = array_values($this->_result[$y]);
-        }
-
-        // If there is a value return it, else return null
-        return isset($values[$x]) && $values[$x] !== '' ? $values[$x] : null;
-    }
-
-    /**
-     * Get an associative array ( field1-value => field2-value ) from the result set
-     * If you retrieve more than 2 fields, you will get an associative array of row-arrays
-     * e.g.   field1-value => array ( field2 => field2-value, field3 => field3-value, ... ), ...
-     * @param string $sql
-     * @return array
-     */
-    function fetch_assoc($sql = null)
-    {
-        // Need to be in Numeric+Assoc Array mode, so set it
-        $original_output_mode = $this->get_output_mode();
-        $this->set_output($output = 'ARRAY_B');
-
-        // Fetch the new result set
-        $this->_process_query($sql);
-
-        // Reset mode to what it was before
-        $this->set_output($original_output_mode);
-
-        $new_array = null;
-
-        if ($this->_num_rows > 0) {
-            if ($this->get_num_cols() == 2) {
-                // Convert rows to simple associative array
-                for ($i = 0; $i < $this->_num_rows; $i++) {
-                    $new_array["{$this->_result[$i][0]}"] = $this->_result[$i][1];
-                }
-            } else {
-                // Convert rows to associative array of arrays
-                for ($i = 0; $i < $this->_num_rows; $i++) {
-                    $row_array = null;
-                    for ($j = 1; $j < $this->_num_cols; $j++) {
-                        $row_array[$this->_result_cols["$j"]] = $this->_result[$i][$j];
-                    }
-                    $new_array["{$this->_result[$i][0]}"] = $row_array;
-                }
-            }
-        }
-        return $new_array;
-    }// /->fetch_assoc()
-
-    /**
-     * Execute the insert query in $sql, using the fields in $fields
-     * auto-slashes the given fields
-     * @param string $sql string of the form 'INSERT INTO tbl_name ({fields}) VALUES ({values}) '
-     * @param array $fields array ( fieldname1 => ???, fieldname2 => ???, ... )
-     */
-    function do_insert($sql, $fields)
-    {
-        $fields_str = implode(',', (array)array_keys($fields));
-
-        $values = array();
-        foreach ($fields as $k => $v) {
-            $values[] = $this->_prepare_field_value($v);
-        }
-        $values_str = implode(',', $values);
-
-        $sql = str_replace('{fields}', $fields_str, $sql);
-        $sql = str_replace('{values}', $values_str, $sql);
-
-        return $this->execute($sql);
-    } // /->do_insert()
-
-    /**
-     * Execute the insert query in $sql, using multiple VALUES statements as given in $fields
-     * Auto-slashes the given fields
-     *
-     * NOTE  : Unlike ->do_insert, the $fields array is an array[0..n] of assoc-arrays
-     * NOTE  : Only the last insert-id will be available from ->get_insert_id() following execution
-     *
-     * @param string $sql of the form, 'INSERT INTO tbl_name ({fields}) VALUES {values}
-     * @param array $fields array[0..n] of array ( fieldname1 -> ???, fieldname2 => ???, ... )
-     * @return object
-     */
-    function do_insert_multi($sql, $fields)
-    {
-        if (is_array($fields)) {
-            $fields_str = implode(',', array_keys($fields[0]));
-
-            $value_row = null;
-
-            foreach ($fields as $i => $row) {
-                $value_row["$i"] = array();
-                foreach ($row as $k => $v) {
-                    $value_row["$i"][] = $this->_prepare_field_value($v);
-                }
-                $value_row["$i"] = '(' . implode(',', $value_row["$i"]) . ')';
-            }
-            $values_str = implode(',', $value_row);
-
-            $sql = str_replace('{fields}', $fields_str, $sql);
-            $sql = str_replace('{values}', $values_str, $sql);
-
-            return $this->execute($sql);
-        } else {
-            return null;
-        }
-    }// /->do_insert_multi()
-
-    /**
-     * Execute the update query in $sql, setting the fields in $fields
-     * Auto-slashes the given fields
-     * @param string $sql sql query of the form  'UPDATE tbl_name SET {fields} WHERE xxx=yyy'
-     * @param array $fields of fields and values to set - of the form  array ( fieldname1 => ???, fieldname2 => ???, ... )
-     * @return mixed
-     */
-    function do_update($sql, $fields)
-    {
-        $set_str = '';
-        $fields_count = count($fields);
-        $i = 1;
-
-        foreach ($fields AS $k => $v) {
-            $set_str .= " $k=" . $this->_prepare_field_value($v);
-            if ($i < $fields_count) {
-                $set_str .= ',';
-            }
-            ++$i;
-        }
-
-        $sql = str_replace('{fields}', $set_str, $sql);
-        return $this->execute($sql);
-    } // /->do_update()
-
-    /**
-     * Builds filter clause of the form  (aaa='bbb' OR aaa='ccc' OR aaa='ddd' ... )
+     * Return the Doctrine database connection object.
      *
-     * @param string $field_name the field name being checked (aaa in example above)
-     * @param array/value $filter_values the values to compare against.
-     * @param string $logical_operator the operator to use to concatenate the filters (AND, OR, XOR)
-     * @return string
-     */
-    function build_filter($field_name, $filter_values, $logical_operator = 'OR')
-    {
-        $filter_values = (array)$filter_values;  // cast values to array (in case it was only passed one)
-
-        $filter_clause = '(';
-        $w_count = count($filter_values);
-        $i = 1;
-        foreach ($filter_values as $k => $v) {
-            if (!is_int($v)) {
-                $v = $this->escape_str($v);
-            }
-            $filter_clause .= "$field_name = " . $this->_prepare_field_value($v);
-            if ($i < $w_count) {
-                $filter_clause .= " $logical_operator ";
-            }
-            $i++;
-        }
-        $filter_clause .= ')';
-
-        return $filter_clause;
-    }// ->build_filter()
-
-    /**
-     * Builds an SQL set of the form  ('aaa','bbb','ccc') for use with IN operators
-     *
-     * @param array/value $value_array array of values to include in the set
-     * @return string
-     */
-    function build_set($value_array, $quoted = true)
-    {
-        $value_array = array_map('addslashes', (array)$value_array);
-        if ($quoted) {
-            return '(\'' . implode('\',\'', $value_array) . '\')';
-        } else {
-            return '(' . implode(',', $value_array) . ')';
-        }
-    }// /->build_set()
-
-    /*
-    * --------------------------------------------------------------------------------
-    * Accessor Methods
-    * --------------------------------------------------------------------------------
-    */
-
-    // GET_xxx functions
-
-    /**
-     * Return an array of columns names from the last query
-     * @return boolean
-     */
-    function get_cols()
-    {
-        return (is_array($this->_result_cols)) ? $this->_result_cols : null;
-    }
-
-    /**
-     * Return the number of columns from the last query
-     * @return integer
-     */
-    function get_num_cols()
-    {
-        return $this->_num_cols;
-    }
-
-    /**
-     * Return the number of rows from the last query
-     * @return integer
+     * @return Connection
      */
-    function get_num_rows()
+    public function getConnection()
     {
-        return $this->_num_rows;
-    }
-
-    /**
-     * Return the number of affected rows from the last query (insert/replace/update)
-     * @return integer
-     */
-    function get_num_affected()
-    {
-        return $this->_num_affected;
-    }
-
-    /**
-     * Return last inserted id (for auto-increment columns)
-     * @return integer
-     */
-    function get_insert_id()
-    {
-        return $this->_insert_id;
-    }
-
-    /**
-     * Return last run query
-     * @return string
-     */
-    function get_last_sql()
-    {
-        return $this->_last_sql;
-    }
-
-    /**
-     *  Get last mysql error
-     */
-    function get_last_error()
-    {
-        mysqli_error($this->_conn);
-    }
-
-    /**
-     * Get output mode
-     * @return mixed
-     */
-    function get_output_mode()
-    {
-        return $this->_output_type;
-    }
-
-    function getConnection()
-    {
-
         return $this->_conn;
-
-    }
-
-    /*
-    * --------------------------------------------------------------------------------
-    * SET_xxx functions
-    * --------------------------------------------------------------------------------
-    */
-
-    /**
-     * Set debug mode
-     * When in debug mode, detailed error reports are echoed
-     * @param boolean
-     */
-    function set_debug($on)
-    {
-        $this->_debug = $on;
     }
-
-    /**
-     * Set default output mode for results array
-     * @param string $output
-     * @return boolean
-     */
-    function set_output($output = 'ARRAY_A')
-    {
-        switch ($output) {
-            case 'ARRAY_A'  :
-                $this->_output_type_int = MYSQLI_ASSOC;
-                $this->_output_type = $output;
-                return true;
-                break;
-            // ----------------------------------------
-            case 'ARRAY_B'  :
-                $this->_output_type_int = MYSQLI_BOTH;
-                $this->_output_type = $output;
-                return true;
-                break;
-            // ----------------------------------------
-            case 'ARRAY_N'  :
-                $this->_output_type_int = MYSQLI_NUM;
-                $this->_output_type = $output;
-                return true;
-                break;
-            // ----------------------------------------
-            default :
-                return false;
-                break;
-        }
-    }// /->set_output()
-
-    /**
-     * Escape character string
-     * @param string $str
-     * @return string
-     */
-    function escape_str($str)
-    {
-        return mysqli_real_escape_string($this->_conn, stripslashes($str));
-    }
-
-    /*
-    * ================================================================================
-    * Private Methods
-    * ================================================================================
-    */
-
-    /**
-     * Execute the SQL and collect the result set
-     * @param string $sql
-     * @return boolean
-     */
-    function _process_query($sql)
-    {
-        $this->flush();
-        $this->open();
-        $this->_last_sql = trim($sql);  // Save query
-
-        if ($this->_debug) {
-            $this->_result_set = mysqli_query($this->_conn, $sql) or $this->_throw_error('Querying database');
-        } else {
-            $this->_result_set = @mysqli_query($this->_conn, $sql);
-        }
-
-        // If got a result set..
-        if ($this->_result_set) {
-
-            // number of columns returned
-            $this->_num_cols = mysqli_num_fields($this->_result_set);
-
-            // Store column names as an array
-            $this->_result_cols = array();
-
-            while ($field = @mysqli_fetch_field($this->_result_set)) {
-                $this->_result_cols[] = $field->name;
-            }
-
-            // Store the results as an array of row objects
-            while ($row = @mysqli_fetch_array($this->_result_set, $this->_output_type_int)) {
-                $this->_result[] = $row;
-            }
-
-            // number of rows returned
-            $this->_num_rows = count($this->_result);
-
-            // Free the actual result set
-            @mysqli_free_result($this->_result_set);
-
-            // If there were results.. return true
-            return ($this->_num_rows >= 1);
-        } else {
-            $this->_num_cols = 0;
-            $this->_num_rows = 0;
-            $this->_result_cols = null;
-            return false;
-        }
-    } // /->process_query()
-
-    /**
-     * function to capture the thrown error and out put to the screen
-     * @param string $err_msg
-     * @return boolean
-     */
-    function _throw_error($err_msg)
-    {
-        if ($this->_conn) {
-            die("<hr />DATABASE ERROR<hr />$err_msg :: " . mysqli_error($this->_conn) . '<hr />' . $this->get_last_sql() . '<hr />');
-        } else {
-            die("<hr />DATABASE ERROR<hr />$err_msg :: &lt;NO SERVER&gt;<hr />" . $this->get_last_sql() . '<hr />');
-        }
-        return false;
-    }// /->_throw_error()
-
-    /**
-     * Prepare a value for putting into the database
-     * Escapes special characters, checks for NULL, and puts in quotes as necessary
-     *
-     * @param integer $value value to prepare
-     *
-     * @return string   en-quoted value, ready for insertion into a database (of the form 'value' or NULL)
-     */
-    function _prepare_field_value($value)
-    {
-        // NULL values don't need quotes, so if it's null, just return a string containing NULL
-        // Else, return an escaped string containing the value enclosed in quotes
-        if (is_null($value)) {
-            return 'NULL';
-        } else if (is_int($value)) {
-            return "$value";
-        } else {
-            return '\'' . $this->escape_str($value) . '\'';
-        }
-
-    }// /->_prepare_field_value()
-
-} // /class: DAO
-
-?>
+}
diff --git a/src/includes/classes/DBAuthenticator.php b/src/includes/classes/DBAuthenticator.php
index f295287..3823caa 100644
--- a/src/includes/classes/DBAuthenticator.php
+++ b/src/includes/classes/DBAuthenticator.php
@@ -12,33 +12,73 @@
 
 namespace WebPA\includes\classes;
 
-class DBAuthenticator extends Authenticator {
+use Doctrine\DBAL\ParameterType;
 
-    public function __construct(EngCIS $cis, $username = NULL, $password = NULL)
+class DBAuthenticator extends Authenticator
+{
+    private DAO $dao;
+
+    public function __construct(EngCIS $cis, $username = null, $password = null)
     {
         parent::__construct($cis, $username, $password);
     }
 
-    /*
-    Authenticate the user against the internal database
-    */
-  function authenticate() {
+    // Authenticate the user against the internal database
+    public function authenticate()
+    {
+        $this->_error = null;
+
+        //match the username and password to the values in the database.
+        $this->dao = new DAO(APP__DB_HOST, APP__DB_USERNAME, APP__DB_PASSWORD, APP__DB_DATABASE);
+
+        $dbConn = $this->dao->getConnection();
+
+        $query = 'SELECT * FROM ' . APP__DB_TABLE_PREFIX . 'user WHERE username = ? AND source_id = ""';
 
-    $this->_error = NULL;
+        $user = $dbConn->fetchAssociative($query, [$this->username], [ParameterType::STRING]);
 
-    //match the username and password to the values in the database.
-    $password = md5($this->password);
+        // verify the password provided
+        if (password_verify($this->password, $user['password'])) {
+            if (password_needs_rehash($user['password'], PASSWORD_DEFAULT)) {
+                $this->rehashPassword($user['username'], $this->password);
+            }
 
-    $sql = 'SELECT * FROM ' . APP__DB_TABLE_PREFIX . "user WHERE (username = '{$this->username}') AND (password = '$password') AND (source_id = '')";
+            $this->initialise($user);
+        } else {
+            // we could be using the old md5 hash. Check this and if it is the case, rehash the password
+            $md5HashedPass = md5($this->password);
 
-    return $this->initialise($sql);
+            if ($md5HashedPass === $user['password']) {
+                $this->rehashPassword($user['username'], $this->password);
 
-  }// /->authenticate()
+                $this->initialise($user);
+            }
+        }
 
-/*
-================================================================================
-  PRIVATE
-================================================================================
-*/
+        return $this->_authenticated;
+    }
+
+    /**
+     * Rehash existing passwords to use the more secure default PHP password hash.
+     *
+     * @param string $username
+     * @param string $password
+     *
+     * @throws \Doctrine\DBAL\Exception
+     */
+    private function rehashPassword($username, $password)
+    {
+        $newHash = password_hash($password, PASSWORD_DEFAULT);
 
-}// /class DBAuthenticator
+        $updatePasswordQuery =
+            'UPDATE ' . APP__DB_TABLE_PREFIX . 'user ' .
+            'SET password = ? ' .
+            'WHERE username = ?';
+
+        $this->dao->getConnection()->executeQuery(
+            $updatePasswordQuery,
+            [$newHash, $username],
+            [ParameterType::STRING, ParameterType::STRING]
+        );
+    }
+}
diff --git a/src/includes/classes/Email.php b/src/includes/classes/Email.php
index 5a984ec..fd1f42c 100644
--- a/src/includes/classes/Email.php
+++ b/src/includes/classes/Email.php
@@ -13,163 +13,208 @@
 
 namespace WebPA\includes\classes;
 
-class Email {
-  // Public Vars
+class Email
+{
+    // Public Vars
 
+    // Private Vars
+    private $_to;
 
-  // Private Vars
-  private $_to = null;
-  private $_cc = null;
-  private $_bcc = null;
+    private $_cc;
 
-  private $_from = null;
+    private $_bcc;
 
-  private $_subject = null;
-  private $_body = null;
+    private $_from;
 
-  private $_message_type = 'text';
-  private $_headers = null;
+    private $_subject;
 
-  /**
-  * CONSTRUCTOR for the email class
-  */
-  function __construct() {
-    $this->_init();
-  } // /->Email()
+    private $_body;
 
-/*
-* ================================================================================
-* Public Methods
-* ================================================================================
-*/
-/**
- * Function to set who the email will go to
- * @param string $to
- */
-  function set_to($to) {
-    if (!is_array($to)) { $this->_to[] = $to; }
-    else {$this->_to = $to; }
-  }// ->set_to()
+    private $_message_type = 'text';
 
-/**
- * function to set the cc person for an email
- * @param string $cc
- */
-  function set_cc($cc) {
-    if (is_null($cc)) {
-      unset($this->_headers['Cc']);
-    } else {
-      if (!is_array($cc)) { $this->_cc[] = $cc; }
-      else {$this->_cc = $cc; }
-      $this->_headers['Cc'] = implode(',',$cc);
+    private $_headers;
+
+    /**
+    * CONSTRUCTOR for the email class
+    */
+    public function __construct()
+    {
+        $this->_init();
     }
-  }// /->set_cc()
 
-/**
- * function to set the bcc for the email
- * @param string $bcc
- */
-  function set_bcc($bcc) {
-    if (is_null($bcc)) {
-      unset($this->_headers['Bcc']);
-    } else {
-      if (!is_array($bcc)) { $this->_bcc[] = $bcc; }
-      else {$this->_bcc = $bcc; }
-      $this->_headers['Bcc'] = implode(',',$bcc);
+    // /->Email()
+
+    /*
+    * ================================================================================
+    * Public Methods
+    * ================================================================================
+    */
+
+    /**
+     * Function to set who the email will go to
+     * @param string $to
+     */
+    public function set_to($to)
+    {
+        if (!is_array($to)) {
+            $this->_to[] = $to;
+        } else {
+            $this->_to = $to;
+        }
     }
-  }// /->set_bcc()
 
-/**
- * function to set who the email is from
- * @param string $from
- */
-  function set_from($from) {
-    $this->_from = $from;
-    $this->_headers['From'] = $this->_from;
-    $this->_headers['Reply-To'] = $this->_from;
-  }// /->set_from()
+    // ->set_to()
+
+    /**
+     * function to set the cc person for an email
+     * @param string $cc
+     */
+    public function set_cc($cc)
+    {
+        if (is_null($cc)) {
+            unset($this->_headers['Cc']);
+        } else {
+            if (!is_array($cc)) {
+                $this->_cc[] = $cc;
+            } else {
+                $this->_cc = $cc;
+            }
+            $this->_headers['Cc'] = implode(',', $cc);
+        }
+    }
 
-/**
- * function to set the message type
- * @param string  $type
- */
-  function set_message_type($type) {
-    if ($type == 'html') {
-      $this->_message_type = 'html';
-      $this->_headers['MIME-Version'] = '1.0';
-      $this->_headers['Content-Type'] = 'text/html;charset=iso-8859-1';
-    } else {
-      $this->_message_type = 'text';
-      unset($this->_headers['MIME-Version']);
-      unset($this->_headers['Content-Type']);
+    // /->set_cc()
+
+    /**
+     * function to set the bcc for the email
+     * @param string $bcc
+     */
+    public function set_bcc($bcc)
+    {
+        if (is_null($bcc)) {
+            unset($this->_headers['Bcc']);
+        } else {
+            if (!is_array($bcc)) {
+                $this->_bcc[] = $bcc;
+            } else {
+                $this->_bcc = $bcc;
+            }
+            $this->_headers['Bcc'] = implode(',', $bcc);
+        }
     }
-  }// /->set_message_type()
 
-/**
- * function to set the subject from the email
- * @param string $subject
- */
-  function set_subject($subject) {
-    $this->_subject = $subject;
-  }// /->set_subject()
+    // /->set_bcc()
+
+    /**
+     * function to set who the email is from
+     * @param string $from
+     */
+    public function set_from($from)
+    {
+        $this->_from = $from;
+        $this->_headers['From'] = $this->_from;
+        $this->_headers['Reply-To'] = $this->_from;
+    }
 
-/**
- * Function to set the message body
- * @param string $body
- */
-  function set_body($body) {
-    $this->_body = $body;
-  }// /->set_body()
+    // /->set_from()
+
+    /**
+     * function to set the message type
+     * @param string  $type
+     */
+    public function set_message_type($type)
+    {
+        if ($type == 'html') {
+            $this->_message_type = 'html';
+            $this->_headers['MIME-Version'] = '1.0';
+            $this->_headers['Content-Type'] = 'text/html;charset=iso-8859-1';
+        } else {
+            $this->_message_type = 'text';
+            unset($this->_headers['MIME-Version']);
+            unset($this->_headers['Content-Type']);
+        }
+    }
 
-/**
- * Function to send the email
- */
-  function send() {
-    $this->_send();
-  }// /->send()
-
-/*
-* ================================================================================
-* Private Methods
-* ================================================================================
-*/
-/**
- * function to initalise
- */
-  function _init() {
-    $this->_to = null;
-    $this->_cc = null;
-    $this->_bcc = null;
+    // /->set_message_type()
+
+    /**
+     * function to set the subject from the email
+     * @param string $subject
+     */
+    public function set_subject($subject)
+    {
+        $this->_subject = $subject;
+    }
 
-    $this->_from = null;
+    // /->set_subject()
 
-    $this->_subject = null;
-    $this->_body = null;
+    /**
+     * Function to set the message body
+     * @param string $body
+     */
+    public function set_body($body)
+    {
+        $this->_body = $body;
+    }
 
-    $this->_message_type = 'text';
-    $this->_headers['X-Mailer'] = 'PHP/'. phpversion();
-  }// /->_init()
+    // /->set_body()
 
-/**
- * Function to send the email
- * @return array
- */
-  function _send() {
-    $to = ($this->_to) ? implode(',',$this->_to) : null;
-    $cc = (is_array($this->_cc)) ? implode(',',$this->_cc) : null ;
-    $bcc = (is_array($this->_bcc)) ? implode(',',$this->_bcc) : null ;
+    /**
+     * Function to send the email
+     */
+    public function send()
+    {
+        $this->_send();
+    }
+
+    // /->send()
 
-    $subject = $this->_subject;
-    $message = str_replace("\n.", "\n..", $this->_body);  // single '.' as first character fix for Windows SMTP servers
+    /*
+    * ================================================================================
+    * Private Methods
+    * ================================================================================
+    */
 
-    $headers = '';
-    foreach($this->_headers as $header_name => $header_content) {
-      $headers .= "{$header_name}: {$header_content}\r\n";
+    /**
+     * function to initalise
+     */
+    public function _init()
+    {
+        $this->_to = null;
+        $this->_cc = null;
+        $this->_bcc = null;
+
+        $this->_from = null;
+
+        $this->_subject = null;
+        $this->_body = null;
+
+        $this->_message_type = 'text';
+        $this->_headers['X-Mailer'] = 'PHP/'. phpversion();
     }
 
-    return mail($to, $subject, $message, $headers);
-  }// /->_send()
+    // /->_init()
 
-} // /class: Email
+    /**
+     * Function to send the email
+     * @return array
+     */
+    public function _send()
+    {
+        $to = ($this->_to) ? implode(',', $this->_to) : null;
+        $cc = (is_array($this->_cc)) ? implode(',', $this->_cc) : null ;
+        $bcc = (is_array($this->_bcc)) ? implode(',', $this->_bcc) : null ;
+
+        $subject = $this->_subject;
+        $message = str_replace("\n.", "\n..", $this->_body);  // single '.' as first character fix for Windows SMTP servers
 
-?>
+        $headers = '';
+        foreach ($this->_headers as $header_name => $header_content) {
+            $headers .= "{$header_name}: {$header_content}\r\n";
+        }
+
+        return mail($to, $subject, $message, $headers);
+    }
+
+    // /->_send()
+} // /class: Email
diff --git a/src/includes/classes/EngCIS.php b/src/includes/classes/EngCIS.php
index 331fc9c..ef95af4 100644
--- a/src/includes/classes/EngCIS.php
+++ b/src/includes/classes/EngCIS.php
@@ -10,20 +10,25 @@
 
 namespace WebPA\includes\classes;
 
+use Doctrine\DBAL\ParameterType;
+use WebPA\includes\functions\AcademicYear;
 use WebPA\includes\functions\ArrayFunctions;
 use WebPA\includes\functions\Common;
-use WebPA\includes\functions\AcademicYear;
-
-include_once __DIR__ . '/../inc_global.php';
 
 class EngCIS
 {
     private $_DAO;
+
     private $_ordering_types;
+
     private $user;
+
     private $sourceId;
+
     private $moduleId;
 
+    private $dbConn;
+
     /**
      * CONSTRUCTOR
      */
@@ -33,7 +38,8 @@ public function __construct($sourceId, $moduleId)
         $this->moduleId = $moduleId;
 
         $this->_DAO = new DAO(APP__DB_HOST, APP__DB_USERNAME, APP__DB_PASSWORD, APP__DB_DATABASE);
-        $this->_DAO->set_debug(false);
+
+        $this->dbConn = $this->_DAO->getConnection();
     }
 
     public function setUser(User $user)
@@ -55,46 +61,69 @@ public function setUser(User $user)
      *
      * @return array  either an assoc-array of module info or an array of assoc-arrays, containing many modules' info
      */
-    function get_module($modules = null, $ordering = 'id')
+    public function get_module($modules = null, $ordering = 'id')
     {
-        $module_search = $this->_DAO->build_filter('module_id', (array)$modules);
-        $order_by_clause = $this->_order_by_clause('module', $ordering);
+        $queryBuilder = $this->dbConn->createQueryBuilder();
+
+        if ($ordering === 'name') {
+            $queryBuilder->orderBy('lcm.module_id');
+        } else {
+            $queryBuilder->orderBy('lcm.module_title');
+        }
 
         // If there's more than one module to search for, get all the rows
         if (is_array($modules)) {
-            return $this->_DAO->fetch("SELECT lcm.module_id, lcm.module_title, lcm.module_code
-                    FROM " . APP__DB_TABLE_PREFIX . "module lcm
-                    WHERE (lcm.source_id = '{$this->sourceId}') AND $module_search
-                    $order_by_clause");
-        } else if (!empty($modules)) {  // else, just return one row
-            return $this->_DAO->fetch_row("SELECT lcm.module_id, lcm.module_title, lcm.module_code
-                      FROM " . APP__DB_TABLE_PREFIX . "module lcm
-                      WHERE (lcm.source_id = '{$this->sourceId}') AND $module_search
-                      LIMIT 1");
-        } else if ($this->user->is_admin()) {
-            return $this->_DAO->fetch("SELECT lcm.module_id, lcm.module_title, lcm.module_code
-                    FROM " . APP__DB_TABLE_PREFIX . "module lcm
-                    WHERE (lcm.source_id = '{$this->sourceId}')
-                    $order_by_clause");
-        } else {
-            return $this->_DAO->fetch("SELECT lcm.module_id, lcm.module_title, lcm.module_code
-                  FROM " . APP__DB_TABLE_PREFIX . "module lcm
-                  INNER JOIN " . APP__DB_TABLE_PREFIX . "user_module lcsm ON lcm.module_id = lcsm.module_id
-                  WHERE (lcsm.user_type = '" . APP__USER_TYPE_TUTOR . "') AND
-                        (user_id = $this->user->id) AND (lcm.source_id = '{$this->sourceId}')
-                  $order_by_clause");
+            // get all modules
+            $queryBuilder
+                ->select('lcm.module_id', 'lcm.module_title', 'lcm.module_code')
+                ->from(APP__DB_TABLE_PREFIX . 'module', 'lcm')
+                ->where('lcm.source_id = :source_id')
+                ->andWhere('module_id IN (:modules)')
+                ->setParameter(':source_id', $this->sourceId)
+                ->setParameter(':modules', $modules, $this->dbConn::PARAM_INT_ARRAY);
+
+            return $queryBuilder->execute()->fetchAllAssociative();
+        }
+        if (!empty($modules)) {  // else, just return one row
+            $moduleQuery = 'SELECT module_id, module_title, module_code FROM ' . APP__DB_TABLE_PREFIX . 'module WHERE source_id = ? AND module_id = ? LIMIT 1';
+
+            return $this->dbConn->fetchAssociative(
+                $moduleQuery,
+                [$this->sourceId, $modules],
+                [ParameterType::STRING, ParameterType::INTEGER]
+            );
+        }
+        if ($this->user->is_admin()) {
+            $queryBuilder
+                ->select('lcm.module_id', 'lcm.module_title', 'lcm.module_code')
+                ->from(APP__DB_TABLE_PREFIX . 'module', 'lcm')
+                ->where('lcm.source_id = ?')
+                ->setParameter(0, $this->sourceId, ParameterType::STRING);
+
+            return $queryBuilder->execute()->fetchAllAssociative();
         }
-    }// /->get_module()
+        $queryBuilder
+                ->select('lcm.module_id', 'lcm.module_title', 'lcm.module_code')
+                ->from(APP__DB_TABLE_PREFIX . 'module', 'lcm')
+                ->innerJoin('lcm', APP__DB_TABLE_PREFIX . 'user_module', 'lcsm', 'lcm.module_id = lcsm.module_id')
+                ->where('lcsm.user_type = ?')
+                ->andWhere('user_id = ?')
+                ->andWhere('lcm.source_id = ?')
+                ->setParameter(0, APP__USER_TYPE_TUTOR, ParameterType::STRING)
+                ->setParameter(1, $this->user->id, ParameterType::INTEGER)
+                ->setParameter(2, $this->sourceId, ParameterType::STRING);
+
+        return $queryBuilder->execute()->fetchAllAssociative();
+    }
 
     /**
      * Get all the module info as an array
      *
      * @return array
      */
-    function get_all_modules()
+    public function get_all_modules()
     {
-        return $this->_DAO->fetch("SELECT lcm.module_id, lcm.module_title
-                    FROM " . APP__DB_TABLE_PREFIX . "module lcm");
+        return $this->dbConn->fetchAllAssociative('SELECT lcm.module_id, lcm.module_title FROM ' . APP__DB_TABLE_PREFIX . 'module lcm');
     }
 
     /**
@@ -103,17 +132,28 @@ function get_all_modules()
      * @param string $ordering
      * @return array
      */
-    function get_module_staff($module_id, $ordering)
+    public function get_module_staff($module_id, $ordering)
     {
-        $order_by_clause = $this->_order_by_clause('staff', $ordering);
+        $queryBuilder = $this->dbConn->createQueryBuilder();
+
+        if ($ordering === 'id') {
+            $queryBuilder->orderBy('lcs.user_id');
+        } else {
+            $queryBuilder->orderBy('lcs.lastname');
+            $queryBuilder->addOrderBy('lcs.forename');
+        }
 
-        return $this->_DAO->fetch("SELECT lcs.*
-                  FROM " . APP__DB_TABLE_PREFIX . "user lcs
-                  INNER JOIN " . APP__DB_TABLE_PREFIX . "user_module lcsm ON lcs.user_id = lcsm.user_id
-                  WHERE lcsm.user_type = '" . APP__USER_TYPE_TUTOR . "'
-                    AND module_id = $module_id
-                  $order_by_clause");
-    }// /->get_module_staff()
+        $queryBuilder
+            ->select('lcs.*')
+            ->from(APP__DB_TABLE_PREFIX . 'user lcs')
+            ->innerJoin('lcs', APP__DB_TABLE_PREFIX . 'user_module', 'lcsm', 'lcs.user_id = lcsm.user_id')
+            ->where('lcsm.user_type = ?')
+            ->andWhere('module_id = ?')
+            ->setParameter(0, APP__USER_TYPE_TUTOR, ParameterType::STRING)
+            ->setParameter(1, $module_id, ParameterType::INTEGER);
+
+        return $queryBuilder->execute()->fetchAllAssociative();
+    }
 
     /**
      * Get array of students for one or more modules
@@ -121,72 +161,73 @@ function get_module_staff($module_id, $ordering)
      * @param string $ordering
      * @return array
      */
-    function get_module_students($module, $ordering = 'name')
+    public function get_module_students($module, $ordering = 'name')
     {
-        $order_by_clause = $this->_order_by_clause('student', $ordering);
+        $queryBuilder = $this->dbConn->createQueryBuilder();
 
-        $sql = "SELECT DISTINCT lcs.*, lcs.id_number AS student_id
-                  FROM " . APP__DB_TABLE_PREFIX . "user lcs
-                  INNER JOIN " . APP__DB_TABLE_PREFIX . "user_module lcsm ON lcs.user_id = lcsm.user_id AND lcsm.module_id = $module
-                  WHERE lcsm.user_type = '" . APP__USER_TYPE_STUDENT . "'
-                  $order_by_clause
-                  ";
-        return $this->_DAO->fetch($sql);
-    }// /->get_module_students()
+        if ($ordering === 'id') {
+            $queryBuilder->orderBy('lcs.user_id');
+        } else {
+            $queryBuilder->orderBy('lcs.lastname');
+            $queryBuilder->addOrderBy('lcs.forename');
+        }
+
+        $queryBuilder
+            ->select('lcs.*', 'lcs.id_number as student_id')
+            ->distinct()
+            ->from(APP__DB_TABLE_PREFIX . 'user', 'lcs')
+            ->innerJoin('lcs', APP__DB_TABLE_PREFIX . 'user_module', 'lcsm', 'lcs.user_id = lcsm.user_id AND lcsm.module_id = ?')
+            ->where('lcsm.user_type = ?')
+            ->setParameter(0, $module, ParameterType::INTEGER)
+            ->setParameter(1, APP__USER_TYPE_STUDENT, ParameterType::STRING);
+
+        return $queryBuilder->execute()->fetchAllAssociative();
+    }
 
     /**
      * Get total number of students on one or more modules
      *
-     * @param integer $module module to count students for
-     * @return integer
-     */
-    function get_module_students_count($module)
-    {
-        $sql = "SELECT COUNT(DISTINCT u.user_id)
-        FROM " . APP__DB_TABLE_PREFIX . "user u
-            INNER JOIN " . APP__DB_TABLE_PREFIX . "user_module um ON u.user_id = um.user_id
-        WHERE um.module_id = $module
-          AND um.user_type = '" . APP__USER_TYPE_STUDENT . "'";
-        return $this->_DAO->fetch_value($sql);
-    }// /->get_module_students_count
-
-    /**
-     * Get an array of student IDs for students on the given modules
-     * @param array $modules modules to count students for
-     * @return array
+     * @param int $moduleId module to count students for
+     *
+     * @return int
      */
-    function get_module_students_id($modules)
+    public function get_module_students_count($moduleId)
     {
-        if (!empty($modules)) {
-            $module_set = $this->_DAO->build_set((array)$modules, false);
-            return $this->_DAO->fetch_col("SELECT DISTINCT u.id_number AS staff_id
-                      FROM " . APP__DB_TABLE_PREFIX . "user u
-                      INNER JOIN " . APP__DB_TABLE_PREFIX . "user_module um ON u.user_id = um.user_id
-                      WHERE um.module_id IN $module_set
-                        AND um.user_type = '" . APP__USER_TYPE_STUDENT . "'
-                      ORDER BY u.user_id ASC");
-        }
-    }// /->get_module_students_id()
+        $studentsCountQuery =
+            'SELECT COUNT(DISTINCT u.user_id) AS user_count ' .
+            'FROM ' . APP__DB_TABLE_PREFIX . 'user u ' .
+            'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'user_module um ' .
+            'ON u.user_id = um.user_id ' .
+            'WHERE um.module_id = ? ' .
+            'AND um.user_type = ?';
+
+        return $this->dbConn->fetchOne($studentsCountQuery, [$moduleId, APP__USER_TYPE_STUDENT], [ParameterType::INTEGER, ParameterType::STRING]);
+    }
 
     /**
      * Get an array of user IDs for students on the given modules (user_id = 'student_{studentID}'
+     *
      * @param array $modules modules to count students for
-     * @return array
+     *
+     * @return array|void
      */
-    function get_module_students_user_id($modules)
+    public function get_module_students_user_id($modules)
     {
-        if (!empty($modules)) {
-            $module_set = $this->_DAO->build_set((array)$modules, false);
-            $sql = "SELECT DISTINCT u.user_id
-          FROM " . APP__DB_TABLE_PREFIX . "user u
-            INNER JOIN " . APP__DB_TABLE_PREFIX . "user_module um ON u.user_id = um.user_id
-          WHERE um.module_id IN $module_set
-            AND um.user_type = '" . APP__USER_TYPE_STUDENT . "'
-          ORDER BY u.user_id ASC
-          ";
-            return $this->_DAO->fetch_col($sql);
+        if (empty($modules)) {
+            return;
         }
-    }// /->get_module_students_user_id()
+
+        $sql =
+            'SELECT DISTINCT u.user_id ' .
+            'FROM ' . APP__DB_TABLE_PREFIX . 'user u ' .
+            'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'user_module um ' .
+            'ON u.user_id = um.user_id ' .
+            'WHERE um.module_id IN (?) ' .
+            'AND um.user_type = ? ' .
+            'ORDER BY u.user_id ASC';
+
+        return $this->dbConn->fetchFirstColumn($sql, [$modules, APP__USER_TYPE_STUDENT], [$this->dbConn::PARAM_STR_ARRAY, ParameterType::STRING]);
+    }
 
     /**
      * Get number of students on individual multiple modules, grouped by module
@@ -194,16 +235,23 @@ function get_module_students_user_id($modules)
      * @param array $modules modules to count students for
      * @return array
      */
-    function get_module_grouped_students_count($modules)
+    public function get_module_grouped_students_count($modules)
     {
-        $module_search = $this->_DAO->build_filter('module_id', (array)$modules, 'OR');
+        $queryBuilder = $this->_DAO->getConnection()->createQueryBuilder();
+
+        $queryBuilder
+            ->select('module_id', 'COUNT(user_id')
+            ->from(APP__DB_TABLE_PREFIX . 'user_module', 'lcsm')
+            ->where(
+                $queryBuilder->expr()->in('module_id', '?')
+            )
+            ->groupBy('module_id')
+            ->orderBy('module_id');
 
-        return $this->_DAO->fetch_assoc("SELECT module_id, COUNT(user_id)
-                    FROM " . APP__DB_TABLE_PREFIX . "user_module lcsm
-                    WHERE $module_search
-                    GROUP BY module_id
-                    ORDER BY module_id");
-    }// ->get_modules_grouped_students_count()
+        $queryBuilder->setParameter(0, $modules, $this->_DAO->getConnection()::PARAM_INT_ARRAY);
+
+        return $queryBuilder->execute()->fetchAllKeyValue();
+    }
 
     /*
     * --------------------------------------------------------------------------------
@@ -211,46 +259,6 @@ function get_module_grouped_students_count($modules)
     * --------------------------------------------------------------------------------
     */
 
-    /**
-     * Get staff info
-     * Can work with either staff_id or staff_username alone (staff_id takes precedent)
-     *
-     * @param string/array $staff_id  staff ID(s) to search for (use NULL if searching on username)
-     * @param string/array $staff_username  staff username(s) to search for
-     * @param string $ordering ordering mode
-     *
-     * @return array either an assoc-array of staff member info or an array of assoc-arrays, containting many staff members' info
-     */
-    function get_staff($staff_id, $staff_username = null, $ordering = 'name')
-    {
-        if ($staff_id) {
-            $staff_set = $this->_DAO->build_set($staff_id, false);
-            $sql_WHERE = "user_id IN $staff_set ";
-        } else {
-            if ($staff_username) {
-                $staff_set = $this->_DAO->build_set($staff_username);
-                $sql_WHERE = "username IN $staff_set ";
-            } else {
-                return null;
-            }
-        }
-
-        $order_by_clause = $this->_order_by_clause('staff', $ordering);
-
-        // If there's more than one staff member to search for, get all the rows
-        if ((is_array($staff_id)) || (is_array($staff_username))) {
-            return $this->_DAO->fetch("SELECT lcs.*
-                    FROM " . APP__DB_TABLE_PREFIX . "user lcs
-                    WHERE $sql_WHERE
-                    $order_by_clause");
-        } else {  // else, just return one row
-            return $this->_DAO->fetch_row("SELECT lcs.*
-                      FROM " . APP__DB_TABLE_PREFIX . "user lcs
-                      WHERE $sql_WHERE
-                      LIMIT 1");
-        }
-    }// /->get_staff()
-
     /**
      * Get array of modules for the given staff member(s)
      * Can work with either staff_id or staff_username alone (staff_id takes precedent)
@@ -261,12 +269,12 @@ function get_staff($staff_id, $staff_username = null, $ordering = 'name')
      *
      * @return array  an array of assoc-arrays, containting many module info
      */
-    function get_staff_modules($staff_id, $staff_username = null, $ordering = 'id')
+    public function get_staff_modules($staff_id, $staff_username = null, $ordering = 'id')
     {
-
         return $this->get_user_modules($staff_id, $staff_username, $ordering);
+    }
 
-    }// /->get_staff_modules
+    // /->get_staff_modules
 
     /**
      * Is the given staff member associated with the given modules?
@@ -275,20 +283,21 @@ function get_staff_modules($staff_id, $staff_username = null, $ordering = 'id')
      * @param string/array $module_id  either a single module_id, or an array of module_ids
      * @return integer
      */
-    function staff_has_module($staff_id, $module_id)
+    public function staff_has_module($staff_id, $module_id)
     {
-        $module_id = (array)$module_id;
+        $module_id = (array) $module_id;
         $staff_modules = $this->get_staff_modules($staff_id);
         if (!$staff_modules) {
             return false;
-        } else {
-            $arr_module_id = ArrayFunctions::array_extract_column($staff_modules, 'module_id');
-            $diff = array_diff($module_id, $arr_module_id);
-
-            // If the array is empty, then the staff member has those modules
-            return (count(array_diff($module_id, $arr_module_id)) === 0);
         }
-    }// /->staff_has_module()
+        $arr_module_id = ArrayFunctions::array_extract_column($staff_modules, 'module_id');
+        $diff = array_diff($module_id, $arr_module_id);
+
+        // If the array is empty, then the staff member has those modules
+        return count(array_diff($module_id, $arr_module_id)) === 0;
+    }
+
+    // /->staff_has_module()
 
     /*
     * --------------------------------------------------------------------------------
@@ -296,45 +305,6 @@ function staff_has_module($staff_id, $module_id)
     * --------------------------------------------------------------------------------
     */
 
-    /**
-     * Get student info
-     * Can work with either student_id or student_username alone (student_id takes precedent)
-     *
-     * @param string/array $student_id  student ID(s) to search for (use NULL if searching on username)
-     * @param string/array $student_username  student
-     * @param string $ordering ordering mode
-     *
-     * @returns  array either an assoc-array of student info or an array of assoc-arrays, containting many students info
-     */
-    function get_student($student_id = null, $student_username = null, $ordering = 'name')
-    {
-        if ($student_id) {
-            $student_set = $this->_DAO->build_set($student_id, false);
-            $sql_WHERE = "user_id IN $student_set ";
-        } else {
-            if ($student_username) {
-                $student_set = $this->_DAO->build_set($student_username);
-                $sql_WHERE = "username IN $student_set ";
-            } else {
-                return null;
-            }
-        }
-
-        // If there's more than one student to search for, get all the rows
-        if ((is_array($student_id)) || (is_array($student_username))) {
-            $order_by_clause = $this->_order_by_clause('student', $ordering);
-            return $this->_DAO->fetch("SELECT lcs.*
-                    FROM " . APP__DB_TABLE_PREFIX . "user lcs
-                    WHERE $sql_WHERE
-                    $order_by_clause");
-        } else {  // else, just return one row
-            return $this->_DAO->fetch_row("SELECT lcs.*
-                      FROM " . APP__DB_TABLE_PREFIX . "user lcs
-                      WHERE $sql_WHERE
-                      LIMIT 1");
-        }
-    }// /->get_student()
-
     /**
      * Get array of modules for the given student(s)
      * Can work with either student_id or student_username alone (student_id takes precedent)
@@ -345,12 +315,12 @@ function get_student($student_id = null, $student_username = null, $ordering = '
      *
      * @return array an array of module info arrays
      */
-    function get_student_modules($student_id, $student_username = null, $ordering = 'id')
+    public function get_student_modules($student_id, $student_username = null, $ordering = 'id')
     {
-
         return $this->get_user_modules($student_id, $student_username, $ordering);
+    }
 
-    }// /->get_student_modules()
+    // /->get_student_modules()
 
     /*
     * --------------------------------------------------------------------------------
@@ -366,34 +336,38 @@ function get_student_modules($student_id, $student_username = null, $ordering =
      *
      * @return object
      */
-    function get_user($user_id, $ordering = 'name')
+    public function get_user($user_id, $ordering = 'name')
     {
-        $user_set = $this->_DAO->build_set($user_id, false);
+        $queryBuilder = $this->dbConn->createQueryBuilder();
 
         if (is_array($user_id)) {
-            $order_by_clause = $this->_order_by_clause('user', $ordering);
+            if ($ordering === 'id') {
+                $queryBuilder->orderBy('u.user_id');
+            } else {
+                $queryBuilder->orderBy('u.lastname');
+                $queryBuilder->addOrderBy('u.forename');
+            }
 
-            $sql = "SELECT u.*, um.user_type
-              FROM " . APP__DB_TABLE_PREFIX . "user u
-              LEFT OUTER JOIN " . APP__DB_TABLE_PREFIX . "user_module um
-              ON u.user_id = um.user_id
-              WHERE (u.user_id IN {$user_set})
-              AND (um.module_id = {$this->moduleId})
-              $order_by_clause";
+            $queryBuilder
+                ->select('u.*', 'um.user_type')
+                ->from(APP__DB_TABLE_PREFIX . 'user', 'u')
+                ->leftJoin('u', APP__DB_TABLE_PREFIX . 'user_module', 'um', 'u.user_id = um.user_id')
+                ->where('u.user_id IN (?)')
+                ->andWhere('um.module_id = ?')
+                ->setParameter(0, $user_id, $this->dbConn::PARAM_INT_ARRAY)
+                ->setParameter(1, $this->moduleId, ParameterType::INTEGER);
 
-            return $this->_DAO->fetch($sql);
-        } else {
-            $sql = "SELECT u.*, um.user_type
-              FROM " . APP__DB_TABLE_PREFIX . "user u
-              LEFT OUTER JOIN " . APP__DB_TABLE_PREFIX . "user_module um
-              ON u.user_id = um.user_id
-              WHERE (u.user_id IN {$user_set})
-              AND (um.module_id = {$this->moduleId} OR u.admin = 1)
-              LIMIT 1";
-
-            return $this->_DAO->fetch_row($sql);
+            return $queryBuilder->execute()->fetchAllAssociative();
         }
-    }// /->get_user()
+        $query = 'SELECT u.*, um.user_type FROM ' . APP__DB_TABLE_PREFIX . 'user u '
+                   . 'LEFT OUTER JOIN ' . APP__DB_TABLE_PREFIX . 'user_module um '
+                   . 'ON u.user_id = um.user_id '
+                   . 'WHERE u.user_id = ? '
+                   . 'AND (um.module_id = ? OR u.admin = 1) '
+                   . 'LIMIT 1';
+
+        return $this->dbConn->fetchAssociative($query, [$user_id, $this->moduleId], [ParameterType::INTEGER, ParameterType::INTEGER]);
+    }
 
     /**
      * Get a user's info by searching on email address
@@ -402,13 +376,12 @@ function get_user($user_id, $ordering = 'name')
      *
      * Returns : an assoc-array of user info
      */
-    function get_user_for_email($email)
+    public function get_user_for_email($email)
     {
-        return $this->_DAO->fetch_row("SELECT scu.*
-                     FROM " . APP__DB_TABLE_PREFIX . "user scu
-                     WHERE email = '$email'
-                     LIMIT 1");
-    }// /->get_user_for_email()
+        $query = 'SELECT * FROM ' . APP__DB_TABLE_PREFIX . 'user WHERE email = ? LIMIT 1';
+
+        return $this->dbConn->fetchAssociative($query, [$email], [ParameterType::STRING]);
+    }
 
     /**
      * Get a user's info by searching on username
@@ -417,24 +390,25 @@ function get_user_for_email($email)
      *
      * Returns : an assoc-array of user info
      */
-    function get_user_for_username($username, $source_id = NULL)
+    public function get_user_for_username($username, $source_id = null)
     {
-
         if (is_null($source_id) && isset($_SESSION['_source_id'])) {
             $source_id = $_SESSION['_source_id'];
-        } else if (is_null($source_id)) {
+        } elseif (is_null($source_id)) {
             $source_id = '';
         }
         $this->moduleId = Common::fetch_SESSION('_module_id', null);
 
-        $sql = 'SELECT u.*, um.user_type FROM ' . APP__DB_TABLE_PREFIX . 'user u LEFT OUTER JOIN ' .
-            '  (SELECT * FROM ' . APP__DB_TABLE_PREFIX . "user_module WHERE module_id = {$this->moduleId}) um " .
-            '  ON u.user_id = um.user_id ' .
-            "WHERE username = '{$username}' AND source_id = '{$source_id}'";
-
-        return $this->_DAO->fetch_row($sql);
+        $query = 'SELECT u.*, um.user_type FROM ' . APP__DB_TABLE_PREFIX . 'user u '
+               . 'LEFT OUTER JOIN ( '
+               . 'SELECT * FROM ' . APP__DB_TABLE_PREFIX . 'user_module WHERE module_id = ? '
+               . ') um '
+               . 'ON u.user_id = um.user_id '
+               . 'WHERE username = ? '
+               . 'AND source_id = ?';
 
-    }// /->get_user_for_username()
+        return $this->dbConn->fetchAssociative($query, [$this->moduleId, $username, $source_id], [ParameterType::INTEGER, ParameterType::STRING, ParameterType::STRING]);
+    }
 
     /**
      * Get array of modules for the given user(s)
@@ -446,41 +420,67 @@ function get_user_for_username($username, $source_id = NULL)
      *
      * @return array an array of module info arrays
      */
-    function get_user_modules($user_id, $username = NULL, $ordering = 'id', $source_id = NULL)
+    public function get_user_modules($user_id, $username = null, $ordering = 'id', $source_id = null)
     {
+        $dbConn = $this->_DAO->getConnection();
+        $queryBuilder = $dbConn->createQueryBuilder();
 
         if (is_null($source_id) && isset($_SESSION['_source_id'])) {
             $source_id = $_SESSION['_source_id'];
-        } else if (is_null($source_id)) {
+        } elseif (is_null($source_id)) {
             $source_id = '';
         }
 
-        $order_by_clause = $this->_order_by_clause('module', $ordering);
+        $queryBuilder->orderBy($ordering === 'name' ? 'lcm.module_title' : 'lcm.module_id');
 
         if ($user_id) {
-            $user_set = $this->_DAO->build_set($user_id, false);
-            $sql = 'SELECT lcm.module_id, lcm.module_title, lcm.module_code, lcsm.user_type ' .
-                'FROM ' . APP__DB_TABLE_PREFIX . 'module lcm INNER JOIN ' . APP__DB_TABLE_PREFIX . 'user_module lcsm ON lcm.module_id = lcsm.module_id ' .
-                'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'user u ON lcsm.user_id = u.user_id ' .
-                "WHERE ((lcm.source_id = '{$source_id}') OR (u.source_id <> '')) AND (lcsm.user_id IN {$user_set}) " .
-                "{$order_by_clause}";
-        } else if ($username) {
-            $user_set = $this->_DAO->build_set($username);
-            $sql = 'SELECT lcm.module_id, lcm.module_title, lcm.module_code, lcsm.user_type ' .
-                'FROM ' . APP__DB_TABLE_PREFIX . 'module lcm INNER JOIN ' . APP__DB_TABLE_PREFIX . 'user_module lcsm ON lcm.module_id = lcsm.module_id ' .
-                'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'user u ON lcsm.user_id = u.user_id ' .
-                "WHERE (u.source_id = '{$source_id}') AND (u.username IN {$user_set}) " .
-                "{$order_by_clause}";
+            if (!is_array($user_id)) {
+                $user_id = [$user_id];
+            }
+
+            $queryBuilder
+                ->select('lcm.module_id', 'lcm.module_title', 'lcm.module_code', 'lcsm.user_type')
+                ->from(APP__DB_TABLE_PREFIX . 'module', 'lcm')
+                ->innerJoin('lcm', APP__DB_TABLE_PREFIX . 'user_module', 'lcsm', 'lcm.module_id = lcsm.module_id')
+                ->innerJoin('lcsm', APP__DB_TABLE_PREFIX . 'user', 'u', 'lcsm.user_id = u.user_id')
+                ->where(
+                    $queryBuilder->expr()->and(
+                        $queryBuilder->expr()->or(
+                            $queryBuilder->expr()->eq('lcm.source_id', '?'),
+                            $queryBuilder->expr()->neq('u.source_id', '""')
+                        ),
+                        $queryBuilder->expr()->in('lcsm.user_id', '?')
+                    )
+                );
+
+            $queryBuilder->setParameter(0, $source_id, ParameterType::STRING);
+            $queryBuilder->setParameter(1, $user_id, $dbConn::PARAM_INT_ARRAY);
+        } elseif ($username) {
+            if (!is_array($username)) {
+                $username = [$username];
+            }
+
+            $queryBuilder
+                ->select('lcm.module_id', 'lcm.module_title', 'lcm.module_code', 'lcsm.user_type')
+                ->from(APP__DB_TABLE_PREFIX . 'module lcm')
+                ->innerJoin('lcm', APP__DB_TABLE_PREFIX . 'user_module', 'lcsm', 'lcm.module_id = lcsm.module_id')
+                ->innerJoin('lcsm', APP__DB_TABLE_PREFIX . 'user', 'u', 'lcsm.user_id = u.user_id')
+                ->where('u.source_id = ?')
+                ->andWhere('u.username IN (?)');
+
+            $queryBuilder->setParameter(0, $source_id);
+            $queryBuilder->setParameter(1, $username, $dbConn::PARAM_INT_ARRAY);
         } else {
-            $sql = 'SELECT lcm.module_id, lcm.module_title, lcm.module_code, \'' . APP__USER_TYPE_ADMIN . '\' user_type ' .
-                'FROM ' . APP__DB_TABLE_PREFIX . 'module lcm ' .
-                "WHERE (lcm.source_id = '{$source_id}') " .
-                "{$order_by_clause}";
-        }
+            $queryBuilder
+                ->select('lcm.module_id', 'lcm.module_title', 'lcm.module_code', '"' . APP__USER_TYPE_ADMIN . '" as user_type')
+                ->from(APP__DB_TABLE_PREFIX . 'module lcm')
+                ->where('lcm.source_id = ?');
 
-        return $this->_DAO->fetch_assoc($sql);
+            $queryBuilder->setParameter(0, $source_id);
+        }
 
-    }// /->get_user_modules
+        return $queryBuilder->execute()->fetchAllAssociativeIndexed();
+    }
 
     /*
     * ================================================================================
@@ -488,60 +488,23 @@ function get_user_modules($user_id, $username = NULL, $ordering = 'id', $source_
     * ================================================================================
     */
 
-    /**
-     * Return an ORDER BY clause matching the given parameters
-     *
-     * @param string $row_type type of row being ordered. ['course','module','staff','student']
-     * @param string $ordering type of ordering to do. ['id','name']
-     *
-     * @return string  SQL ORDER BY clause of the form 'ORDER BY fieldname' or NULL if row_type/ordering are invalid
-     */
-    function _order_by_clause($row_type, $ordering = null)
-    {
-        if (!is_array($this->_ordering_types)) {
-            // All available ordering types
-            $this->_ordering_types = array(
-                'module' => array(
-                    'id' => 'lcm.module_id',
-                    'name' => 'lcm.module_title',
-                ),
-                'staff' => array(
-                    'id' => 'lcs.user_id',
-                    'name' => 'lcs.lastname, lcs.forename',
-                ),
-                'student' => array(
-                    'id' => 'lcs.user_id',
-                    'name' => 'lcs.lastname, lcs.forename',
-                ),
-                'user' => array(
-                    'id' => 'u.user_id',
-                    'name' => 'u.lastname, u.forename',
-                ),
-            );
-        }
-
-        if ((array_key_exists($row_type, $this->_ordering_types)) && (array_key_exists($ordering, $this->_ordering_types["$row_type"]))) {
-            return 'ORDER BY ' . $this->_ordering_types["$row_type"]["$ordering"];
-        } else {
-            return null;
-        }
-    }// /->_order_by_clause()
-
-    function get_user_academic_years($user_id = null)
+    public function get_user_academic_years($user_id = null)
     {
         if (!empty($user_id)) {
-            $sql = 'SELECT MIN(a.open_date) first, MAX(a.open_date) last ' .
+            $query = 'SELECT MIN(a.open_date) first, MAX(a.open_date) last ' .
                 'FROM ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
                 'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'module m ON a.module_id = m.module_id ' .
-                "WHERE m.source_id = '{$this->sourceId}' AND m.module_id = '{$this->moduleId}'";
+                'WHERE m.source_id = ? AND m.module_id = ?';
+
+            $dates = $this->dbConn->fetchAssociative($query, [$this->sourceId, $this->moduleId], [ParameterType::STRING, ParameterType::INTEGER]);
         } else {
-            $sql = 'SELECT MIN(a.open_date) first, MAX(a.open_date) last ' .
+            $query = 'SELECT MIN(a.open_date) first, MAX(a.open_date) last ' .
                 'FROM ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
                 'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'module m ON a.module_id = m.module_id ' .
-                "WHERE m.source_id = '{$this->sourceId}'";
-        }
+                'WHERE m.source_id = ?';
 
-        $dates = $this->_DAO->fetch_row($sql);
+            $dates = $this->dbConn->fetchAssociative($query, [$this->sourceId], [ParameterType::STRING]);
+        }
 
         // Ensure that the first record contains some dates as we could return a null record
         if (!empty($dates['first'])) {
@@ -554,7 +517,4 @@ function get_user_academic_years($user_id = null)
 
         return $years;
     }
-
-}// /class: EngCIS
-
-?>
+}
diff --git a/src/includes/classes/Form.php b/src/includes/classes/Form.php
index 9f80eec..c3db744 100644
--- a/src/includes/classes/Form.php
+++ b/src/includes/classes/Form.php
@@ -10,291 +10,375 @@
 
 namespace WebPA\includes\classes;
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\functions\Common;
 
-include_once __DIR__ . '/../inc_global.php';
-
-class Form {
-  // Public Vars
-  public $id = null;
-  public $name = '';
-  public $modules = null;
-  public $type = null;
-
-  // Private Vars
-  private $_DAO = null;
-  private $_questions = null;
-  private $_xml_parser = null;
-
-  /*
-  * CONSTRUCTOR
-  *
-  * @param mixed $DAO
-  */
-  function __construct(&$DAO) {
-    $this->_DAO =& $DAO;
-  }// /->Form()
+class Form
+{
+    // Public Vars
+    public $id;
 
-/*
-* ================================================================================
-* Public Methods
-* ================================================================================
-*/
+    public $name = '';
 
-/*
-* --------------------------------------------------------------------------------
-* Load/Save Functions
-* --------------------------------------------------------------------------------
-*/
+    public $modules;
+
+    public $type;
 
-  /**
-  * Create a new form ID
-  */
-  function create() {
-    // generate a new form_id
-    while (true) {
-      $new_id = Common::uuid_create();
-      if ($this->_DAO->fetch_value("SELECT COUNT(form_id) FROM " . APP__DB_TABLE_PREFIX . "form WHERE form_id = '$new_id'") == 0) { break; }
+    // Private Vars
+    private DAO $_DAO;
+
+    private $_questions;
+
+    private $_xml_parser;
+
+    /*
+    * CONSTRUCTOR
+    *
+    * @param mixed $DAO
+    */
+    public function __construct(DAO $DAO)
+    {
+        $this->_DAO =& $DAO;
     }
-    $this->id = $new_id;
-  }// ->create()
-
-  /**
-  * Delete this Group (and all its members)
-  */
-  function delete() {
-
-    $_module_id = Common::fetch_SESSION('_module_id', null);
-
-    $this->_DAO->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "form_module WHERE (form_id = '{$this->id}') AND (module_id = {$_module_id})");
-    $this->_DAO->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "form WHERE form_id = '{$this->id}'");
-
-    return true;
-
-  }// /->delete()
-
-  /**
-  * Load the Form from the database
-  *
-  * @param string $id  id of Group to load
-  * @return boolean did load succeed
-  */
-  function load($id) {
-    $row = $this->_DAO->fetch_row("SELECT * FROM " . APP__DB_TABLE_PREFIX . "form f WHERE f.form_id = '$id'");
-    return ($row) ? $this->load_from_row($row) : false;
-  }// /->load()
-
-  /**
-  * Load the Form from an array row
-  *
-  *
-  * @param array $row assoc array ( field => value, ... ) - corresponds to row in database
-  * @return boolean  did load succeed
-  */
-  function load_from_row(&$row) {
-    $this->id = $row['form_id'];
-    $this->name = $row['form_name'];
-    $this->type = (is_null($row['form_type'])) ? 'likert' : $row['form_type'];
-    $this->_load_xml($row['form_xml']);
-    return true;
-  }// /->load_from_row()
-
-  /**
-  * Load the Form from xml
-  *
-  * @param string $xml xml fragment to load
-   *
-  * @return boolean did load succeed
-  */
-  function load_from_xml($xml) {
-    $this->_load_xml($xml);
-
-    return true;
-  }
-
-  /**
-  * Save this Form
-  * @return boolean did save succeed
-  */
-  function save() {
-    if (!$this->id) {
-      return false;
-    } else {
-      // Actually create and save the xml
-      $form_xml = $this->_DAO->escape_str($this->get_xml());
-
-      // Save the Form
-      $this->_DAO->execute('INSERT INTO ' . APP__DB_TABLE_PREFIX . 'form (form_id, form_name, form_type, form_xml) ' .
-         "VALUES ('{$this->id}', '" . $this->_DAO->escape_str($this->name) . "', '" . $this->_DAO->escape_str($this->type) . "', '') " .
-         "ON DUPLICATE KEY UPDATE form_name = '" . $this->_DAO->escape_str($this->name) . "', form_type = '" . $this->_DAO->escape_str($this->type) . "'");
-      $this->_DAO->execute('UPDATE ' . APP__DB_TABLE_PREFIX . "form SET form_xml = '{$form_xml}' WHERE form_id = '{$this->id}'");
-
-      if ($this->modules !== null && count($this->modules) > 0) {
-        $values = array();
-        foreach($this->modules as $module_id) {
-          $values[] = "('{$this->id}', {$module_id})";
+
+    /*
+    * ================================================================================
+    * Public Methods
+    * ================================================================================
+    */
+
+    /*
+    * --------------------------------------------------------------------------------
+    * Load/Save Functions
+    * --------------------------------------------------------------------------------
+    */
+
+    /**
+    * Create a new form ID
+    */
+    public function create()
+    {
+        // generate a new form_id
+        while (true) {
+            $new_id = Common::uuid_create();
+
+            $existingFormIdQuery =
+          'SELECT COUNT(form_id) ' .
+          'FROM ' . APP__DB_TABLE_PREFIX . 'form ' .
+          'WHERE form_id = ?';
+
+            $formIdCount = $this->_DAO->getConnection()->fetchOne($existingFormIdQuery, [$new_id], [ParameterType::STRING]);
+
+            if ($formIdCount == 0) {
+                break;
+            }
         }
-        $sql = 'INSERT INTO ' . APP__DB_TABLE_PREFIX . 'form_module (form_id, module_id) VALUES ' . implode(', ', $values);
-        $this->_DAO->execute($sql);
-      }
+        $this->id = $new_id;
+    }
+
+    // ->create()
+
+    /**
+    * Delete this Group (and all its members)
+    */
+    public function delete()
+    {
+        $_module_id = Common::fetch_SESSION('_module_id', null);
 
-      return true;
+        $dbConn = $this->_DAO->getConnection();
+
+        $dbConn->executeQuery(
+            'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'form_module WHERE form_id = ? AND module_id = ?',
+            [$this->id, $_module_id],
+            [ParameterType::STRING, ParameterType::INTEGER]
+        );
+
+        $dbConn->executeQuery(
+            'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'form WHERE form_id = ?',
+            [$this->id],
+            [ParameterType::STRING]
+        );
+
+        return true;
     }
-  }// /->save()
 
-/*
-* --------------------------------------------------------------------------------
-* Other Methods
-* --------------------------------------------------------------------------------
-*/
+    /**
+    * Load the Form from the database
+    *
+    * @param string $id  id of Group to load
+     *
+    * @return boolean did load succeed
+    */
+    public function load($id)
+    {
+        $dbConn = $this->_DAO->getConnection();
 
-  /**
-  * Create a clone of this form
-  * @return mixed returns the clone of the form
-  */
-  function & get_clone() {
-    $clone_form = new self($this->_DAO);
-    $clone_form->create();  // Changes the form's ID so it is officially a new form
-    $temp_id = $clone_form->id;
-    $clone_form->load_from_xml($this->get_xml()); // Creates an EXACT clone of the existing form
-    $clone_form->id = $temp_id;
-    return $clone_form;
-  }// /->get_clone()
+        $query = 'SELECT * FROM ' . APP__DB_TABLE_PREFIX . 'form  WHERE form_id = ?';
 
-/*
-* --------------------------------------------------------------------------------
-* Question Manipulation Methods
-* --------------------------------------------------------------------------------
-*/
+        $form = $dbConn->fetchAssociative($query, [$id], [ParameterType::STRING]);
+
+        return $form ? $this->load_from_row($form) : false;
+    }
+
+    /**
+    * Load the Form from an array row
+    *
+    *
+    * @param array $row assoc array ( field => value, ... ) - corresponds to row in database
+    * @return boolean  did load succeed
+    */
+    public function load_from_row(&$row)
+    {
+        $this->id = $row['form_id'];
+        $this->name = $row['form_name'];
+        $this->type = (is_null($row['form_type'])) ? 'likert' : $row['form_type'];
+        $this->_load_xml($row['form_xml']);
+
+        return true;
+    }
+
+    // /->load_from_row()
+
+    /**
+    * Load the Form from xml
+    *
+    * @param string $xml xml fragment to load
+     *
+    * @return boolean did load succeed
+    */
+    public function load_from_xml($xml)
+    {
+        $this->_load_xml($xml);
+
+        return true;
+    }
+
+    /**
+    * Save this Form
+    * @return boolean did save succeed
+    */
+    public function save()
+    {
+        if (!$this->id) {
+            return false;
+        }
+        // Actually create and save the xml
+        $form_xml = $this->get_xml();
+
+        // Save the Form
+        $dbConn = $this->_DAO->getConnection();
+
+        $insertFormQuery =
+        'INSERT INTO ' . APP__DB_TABLE_PREFIX . 'form ' .
+        '(form_id, form_name, form_type, form_xml) ' .
+        'VALUES (?, ?, ?, "") ' .
+        'ON DUPLICATE KEY UPDATE ' .
+        'form_name = ?, ' .
+        'form_type = ?';
+
+        $dbConn->executeQuery(
+                $insertFormQuery,
+                [$this->id, $this->name, $this->type, $this->name, $this->type],
+                [ParameterType::STRING, ParameterType::STRING, ParameterType::STRING, ParameterType::STRING, ParameterType::STRING]
+            );
+
+        $dbConn->executeQuery(
+                'UPDATE ' . APP__DB_TABLE_PREFIX . 'form SET form_xml = ? WHERE form_id = ?',
+                [$form_xml, $this->id],
+                [ParameterType::STRING, ParameterType::STRING]
+            );
+
+        if ($this->modules !== null && count($this->modules) > 0) {
+            foreach ($this->modules as $module_id) {
+                $dbConn->executeQuery(
+                        'INSERT INTO ' . APP__DB_TABLE_PREFIX . 'form_module (form_id, module_id) VALUES (?, ?)',
+                        [$this->id, $module_id],
+                        [ParameterType::STRING, ParameterType::INTEGER]
+                    );
+            }
+        }
 
-  /**
-  * Add a question to this form
-  * @param array $question_array
-  */
-  function add_question($question_array) {
-    if ($this->get_question_count()>0) {
-      $this->_questions[] = $question_array;
-    } else {
-      $this->_questions[0] = $question_array;
+        return true;
     }
-  }// /->add_question()
-
-  /**
-  * Get an individual question's info
-  * @param integer $index
-  * @return array Questions at the point in the array
-  */
-  function get_question($index) {
-    $index = (int) $index;
-    if (array_key_exists($index, (array) $this->_questions)) {
-      return $this->_questions[$index];
+
+    /*
+    * --------------------------------------------------------------------------------
+    * Other Methods
+    * --------------------------------------------------------------------------------
+    */
+
+    /**
+    * Create a clone of this form
+    * @return mixed returns the clone of the form
+    */
+    public function & get_clone()
+    {
+        $clone_form = new self($this->_DAO);
+        $clone_form->create();  // Changes the form's ID so it is officially a new form
+        $temp_id = $clone_form->id;
+        $clone_form->load_from_xml($this->get_xml()); // Creates an EXACT clone of the existing form
+        $clone_form->id = $temp_id;
+        return $clone_form;
     }
-  }// /->get_question()
-
-  /**
-  * Get a count of the number of questions
-  * @return integer result of the count of the number of questions
-  */
-  function get_question_count() {
-    $result = 0;
-    if (is_array($this->_questions)) {
-      $result = count($this->_questions);
+
+    // /->get_clone()
+
+    /*
+    * --------------------------------------------------------------------------------
+    * Question Manipulation Methods
+    * --------------------------------------------------------------------------------
+    */
+
+    /**
+    * Add a question to this form
+    * @param array $question_array
+    */
+    public function add_question($question_array)
+    {
+        if ($this->get_question_count()>0) {
+            $this->_questions[] = $question_array;
+        } else {
+            $this->_questions[0] = $question_array;
+        }
     }
-    return  $result;
-  }// /->get_question_count()
-
-  /**
-  * Set an individual question's info
-  * @param integer $index
-  * @param array $question_array
-  */
-  function set_question($index, $question_array) {
-    $index = (int) $index;
-    $this->_questions[$index] = $question_array;
-  }// /->set_question()
-
-  /**
-  * Remove a question from this form
-  * @param integer $index
-  */
-  function remove_question($index) {
-    $index = (int) $index;
-    if (array_key_exists($index, (array) $this->_questions)) {
-      unset($this->_questions[$index]);
-      $this->_questions = array_values($this->_questions);
+
+    // /->add_question()
+
+    /**
+    * Get an individual question's info
+    * @param integer $index
+    * @return array Questions at the point in the array
+    */
+    public function get_question($index)
+    {
+        $index = (int) $index;
+        if (array_key_exists($index, (array) $this->_questions)) {
+            return $this->_questions[$index];
+        }
     }
-  }// /->remove_question()
 
-/*
-* --------------------------------------------------------------------------------
-* XML Methods
-* --------------------------------------------------------------------------------
-*/
+    // /->get_question()
+
+    /**
+    * Get a count of the number of questions
+    * @return integer result of the count of the number of questions
+    */
+    public function get_question_count()
+    {
+        $result = 0;
+        if (is_array($this->_questions)) {
+            $result = count($this->_questions);
+        }
+        return  $result;
+    }
 
-  /**
-  * Get the xml representation of this form
-  * @return string xml fragment (no <?xml ?> starting tag)
-  */
-  function get_xml() {
-    if (!is_object($this->_xml_parser)) { $this->_xml_parser = new XMLParser(); }
-
-    // Create an array representation of the form's xml
-    $xml_array['form']['formid']['_data'] = $this->id;
-    $xml_array['form']['formname']['_data'] = $this->name;
-    $xml_array['form']['formtype']['_data'] = $this->type;
-
-    // Add any questions to the xml
-    if ($this->get_question_count()>0) {
-      foreach ($this->_questions as $i => $question) {
-        $question_desc = (array_key_exists('desc', $question)) ? $question['desc']['_data'] : '' ;
-        $new_question = array ('questionid' => 'Q'.($i+1) ,
-                     'text'       => $question['text']['_data'] ,
-                     'desc'       => $question_desc ,);
-
-        $questions_to_save[] = $new_question;
-      }
-      $xml_array['form']['question'] = $this->_questions;
+    // /->get_question_count()
+
+    /**
+    * Set an individual question's info
+    * @param integer $index
+    * @param array $question_array
+    */
+    public function set_question($index, $question_array)
+    {
+        $index = (int) $index;
+        $this->_questions[$index] = $question_array;
     }
 
-    $this->_xml_parser->set_cdata_tags('desc');
-    return $this->_xml_parser->generate_xml($xml_array);
-  }// /->get_xml()
-
-  /**
-  * Load the xml data of the form (questions, etc)
-  * @param mixed $xml_data
-  */
-  function _load_xml(&$xml_data) {
-    if (!is_object($this->_xml_parser)) { $this->_xml_parser = new XMLParser(); }
-    $xml_array = $this->_xml_parser->parse($xml_data);
-
-    // Load form properties
-    $this->id = $xml_array['form']['formid']['_data'];
-    $this->name = $xml_array['form']['formname']['_data'];
-    $this->type =  (array_key_exists('formtype', $xml_array['form'])) ? $xml_array['form']['formtype']['_data'] : 'likert';
-
-    // Load the questions
-    if ( (is_array($xml_array['form'])) && (array_key_exists('question',$xml_array['form'])) ) {
-      $temp_questions =& $xml_array['form']['question'];
-      if ($temp_questions) {
-        // If there's only one question, make sure the array is restructured properly
-        if ( (is_array($temp_questions)) && (array_key_exists(0, $temp_questions)) ) {
-          $this->_questions =& $temp_questions;
+    // /->set_question()
+
+    /**
+    * Remove a question from this form
+    * @param integer $index
+    */
+    public function remove_question($index)
+    {
+        $index = (int) $index;
+        if (array_key_exists($index, (array) $this->_questions)) {
+            unset($this->_questions[$index]);
+            $this->_questions = array_values($this->_questions);
+        }
+    }
+
+    // /->remove_question()
+
+    /*
+    * --------------------------------------------------------------------------------
+    * XML Methods
+    * --------------------------------------------------------------------------------
+    */
+
+    /**
+    * Get the xml representation of this form
+    * @return string xml fragment (no <?xml ?> starting tag)
+    */
+    public function get_xml()
+    {
+        if (!is_object($this->_xml_parser)) {
+            $this->_xml_parser = new XMLParser();
+        }
+
+        // Create an array representation of the form's xml
+        $xml_array['form']['formid']['_data'] = $this->id;
+        $xml_array['form']['formname']['_data'] = $this->name;
+        $xml_array['form']['formtype']['_data'] = $this->type;
+
+        // Add any questions to the xml
+        if ($this->get_question_count()>0) {
+            foreach ($this->_questions as $i => $question) {
+                $question_desc = (array_key_exists('desc', $question)) ? $question['desc']['_data'] : '' ;
+                $new_question = ['questionid' => 'Q'.($i+1),
+                     'text'       => $question['text']['_data'],
+                     'desc'       => $question_desc, ];
+
+                $questions_to_save[] = $new_question;
+            }
+            $xml_array['form']['question'] = $this->_questions;
+        }
+
+        $this->_xml_parser->set_cdata_tags('desc');
+        return $this->_xml_parser->generate_xml($xml_array);
+    }
+
+    // /->get_xml()
+
+    /**
+    * Load the xml data of the form (questions, etc)
+    * @param mixed $xml_data
+    */
+    public function _load_xml(&$xml_data)
+    {
+        if (!is_object($this->_xml_parser)) {
+            $this->_xml_parser = new XMLParser();
+        }
+        $xml_array = $this->_xml_parser->parse($xml_data);
+
+        // Load form properties
+        $this->id = $xml_array['form']['formid']['_data'];
+        $this->name = $xml_array['form']['formname']['_data'];
+        $this->type =  (array_key_exists('formtype', $xml_array['form'])) ? $xml_array['form']['formtype']['_data'] : 'likert';
+
+        // Load the questions
+        if ((is_array($xml_array['form'])) && (array_key_exists('question', $xml_array['form']))) {
+            $temp_questions =& $xml_array['form']['question'];
+            if ($temp_questions) {
+                // If there's only one question, make sure the array is restructured properly
+                if ((is_array($temp_questions)) && (array_key_exists(0, $temp_questions))) {
+                    $this->_questions =& $temp_questions;
+                } else {
+                    $this->_questions[] =& $temp_questions;
+                }
+            }
         } else {
-          $this->_questions[] =& $temp_questions;
+            $this->_questions = null;
         }
-      }
-    } else {
-      $this->_questions = null;
     }
-  }// /->_load_xml()
+
+    // /->_load_xml()
 
 /*
 * ================================================================================
 * Private Methods
 * ================================================================================
 */
-
 }// /class: Form
-
-?>
diff --git a/src/includes/classes/FormRenderer.php b/src/includes/classes/FormRenderer.php
index 6a60a63..79ffe0d 100644
--- a/src/includes/classes/FormRenderer.php
+++ b/src/includes/classes/FormRenderer.php
@@ -12,96 +12,110 @@
 
 use WebPA\includes\functions\Common;
 
-class FormRenderer {
-  // Public Vars
-  public $participant_name = '';
-  public $participant_id = null;
-  public $assessment_feedback = '0';
-  public $assessment_feedback_title;
-
-  // Private Vars
-  private $_form = null;
-  private $_questions = null;
-  private $_participants = null;
-  private $_results = null;
-
-  /*
-  * CONSTRUCTOR
-  */
-  function __construct() {
-  }// /->FormRenderer()
+class FormRenderer
+{
+    // Public Vars
+    public $participant_name = '';
 
-/*
-* ================================================================================
-* Public Methods
-* ================================================================================
-*/
+    public $participant_id;
+
+    public $assessment_feedback = '0';
+
+    public $assessment_feedback_title;
+
+    // Private Vars
+    private $_form;
+
+    private $_questions;
+
+    private $_participants;
+
+    private $_results;
+
+    // CONSTRUCTOR
+    public function __construct()
+    {
+    }
+
+    // /->FormRenderer()
+
+    /*
+    * ================================================================================
+    * Public Methods
+    * ================================================================================
+    */
+
+    /*
+    * Set the form to render
+    *
+    * @param object $form_object  form object to use when rendering
+    */
+    public function set_form(&$form_object)
+    {
+        $this->_form =& $form_object;
+    }
+
+    // /->set_form()
+
+    /**
+     * Set the participants
+     * @param array $participants_array
+    */
+    public function set_participants($participants_array)
+    {
+        $this->_participants = $participants_array;
+    }
+
+    // /->set_participants()
+
+    /**
+    * Set the results to display
+    *
+    * @param array $results results to load
+    *
+    */
+    public function set_results($results_array)
+    {
+        $this->_results = $results_array;
+    }
 
-  /*
-  * Set the form to render
-  *
-  * @param object $form_object  form object to use when rendering
-  */
-  function set_form(&$form_object) {
-    $this->_form =& $form_object;
-  }// /->set_form()
-
-  /**
-   * Set the participants
-   * @param array $participants_array
-  */
-  function set_participants($participants_array) {
-
-    $this->_participants = $participants_array;
-  }// /->set_participants()
-
-  /**
-  * Set the results to display
-  *
-  * @param array $results results to load
-  *
-  */
-  function set_results($results_array) {
-    $this->_results = $results_array;
-  }// /->set_results()
-
-  /**
-   * Draw the <head> section for this form
-   */
-  function draw_description() {
-    if ($this->_form->type =='split100') {
-
-      $participant_count = count($this->_participants);
-      $remainder = 100 % $participant_count;
-      $group_total = 100 - $remainder;
-      $default_score = floor(100 / $participant_count);
-
-      ?>
-      <p>For each criterion you have <?php echo($group_total); ?> marks to split between your teammates.  If everyone contributed equally, then everyone should receive the same score, <?php echo($default_score); ?> marks.  However, you can take points away from teammates who performed poorly, and re-allocate them to those you thought performed better.</p>
-
-      <p>For each criterion, the total number of marks you allocate must equal <?php echo($group_total); ?>.</p>
+    // /->set_results()
+
+    /**
+     * Draw the <head> section for this form
+     */
+    public function draw_description()
+    {
+        if ($this->_form->type =='split100') {
+            $participant_count = count($this->_participants);
+            $remainder = 100 % $participant_count;
+            $group_total = 100 - $remainder;
+            $default_score = floor(100 / $participant_count); ?>
+      <p>For each criterion you have <?php echo $group_total; ?> marks to split between your teammates.  If everyone contributed equally, then everyone should receive the same score, <?php echo $default_score; ?> marks.  However, you can take points away from teammates who performed poorly, and re-allocate them to those you thought performed better.</p>
+
+      <p>For each criterion, the total number of marks you allocate must equal <?php echo $group_total; ?>.</p>
       <?php
-    } else {
-      ?>
+        } else {
+            ?>
       <p>For each criterion you must rate your teammates using the scale provided.  High <?php echo APP__MARK_TEXT; ?> indicate better performance in the criteria.</p>
       <?php
+        }
     }
-  }// /->draw_description()
-
-  /**
-   * Draw the <head> section for this form
-   */
-  function draw_head() {
-    if ($this->_form->type =='split100') {
 
-      $participant_count = count($this->_participants);
-      $remainder = 100 % $participant_count;
-      $group_total = 100 - $remainder;
-
-      ?>
+    // /->draw_description()
+
+    /**
+     * Draw the <head> section for this form
+     */
+    public function draw_head()
+    {
+        if ($this->_form->type =='split100') {
+            $participant_count = count($this->_participants);
+            $remainder = 100 % $participant_count;
+            $group_total = 100 - $remainder; ?>
       <script type="text/javascript"><!--
 
-        var group_total = <?php echo($group_total); ?>;
+        var group_total = <?php echo $group_total; ?>;
 
         function calcTotal(q_id, participant_count) {
           var total_obj = document.getElementById('total_'+q_id);
@@ -155,186 +169,179 @@ function calcTotal(q_id, participant_count) {
       // -->
       </script>
       <?php
+        }
     }
-  }// /->draw_head()
 
-  /**
-   * Function to draw the form
-  */
-  function draw_form() {
-    $question_count = $this->_form->get_question_count();
+    // /->draw_head()
 
-    //
-    if ($this->_form->type=='split100') {
+    /**
+     * Function to draw the form
+    */
+    public function draw_form()
+    {
+        $question_count = $this->_form->get_question_count();
 
-      $participant_count = count($this->_participants);
-      $remainder = 100 % $participant_count;
-      $group_total = 100 - $remainder;
-      $default_score = floor(100 / $participant_count);
+        
+        if ($this->_form->type=='split100') {
+            $participant_count = count($this->_participants);
+            $remainder = 100 % $participant_count;
+            $group_total = 100 - $remainder;
+            $default_score = floor(100 / $participant_count);
 
-      for ($q=0; $q<$question_count; $q++) {
-        $question = $this->_form->get_question($q);
+            for ($q=0; $q<$question_count; $q++) {
+                $question = $this->_form->get_question($q);
 
-        $q_num = $q + 1;
-?>
+                $q_num = $q + 1; ?>
         <div class="question">
 
-          <div class="question_text"><?php echo("{$q_num}. {$question['text']['_data']}"); ?></div>
+          <div class="question_text"><?php echo "{$q_num}. {$question['text']['_data']}"; ?></div>
 <?php
         if (array_key_exists('desc', $question)) {
-          $question_desc = (array_key_exists('desc', $question)) ? $question['desc']['_data'] : '' ;
-          echo("<div>$question_desc</div>");
-        }
-?>
+            $question_desc = (array_key_exists('desc', $question)) ? $question['desc']['_data'] : '' ;
+            echo "<div>$question_desc</div>";
+        } ?>
 
           <div class="info_box" style="float: right; width: 250px; margin: 2em 2em 0 2em; font-size: 0.9em;">
 <?php
         if ($remainder==0) {
-?>
-              <p>You have <span style="font-weight: bold;"><?php echo($group_total); ?> marks</span> to divide between your teammates.</p>
+            ?>
+              <p>You have <span style="font-weight: bold;"><?php echo $group_total; ?> marks</span> to divide between your teammates.</p>
 <?php
         } else {
-?>
-              <p>For a group of <?php echo($participant_count); ?>, you have <span style="font-weight: bold;"><?php echo($group_total); ?> marks</span> to divide between your teammates.</p>
+            ?>
+              <p>For a group of <?php echo $participant_count; ?>, you have <span style="font-weight: bold;"><?php echo $group_total; ?> marks</span> to divide between your teammates.</p>
 <?php
-        }
-?>
-            <p style="font-weight: bold;">For equal performance, every student should receive <?php echo($default_score); ?> marks.</p>
+        } ?>
+            <p style="font-weight: bold;">For equal performance, every student should receive <?php echo $default_score; ?> marks.</p>
           </div>
 
           <table class="question_grid" cellpadding="3" cellspacing="1">
 <?php
         // header row
-        echo('<tr><td style="background-color: transparent">&nbsp;</td><th align="center">score</th></tr>');
+        echo '<tr><td style="background-color: transparent">&nbsp;</td><th align="center">score</th></tr>';
 
-        // show participant rows
-        $initial_total = 0;
-        $index = 1;
+                // show participant rows
+                $initial_total = 0;
+                $index = 1;
 
-        foreach($this->_participants as $id => $name) {
-          $class = ($id==$this->participant_id) ? 'class="this_participant"' : '';
+                foreach ($this->_participants as $id => $name) {
+                    $class = ($id==$this->participant_id) ? 'class="this_participant"' : '';
 
-          $score = Common::fetch_POST("q_{$q}_{$id}");
+                    $score = Common::fetch_POST("q_{$q}_{$id}");
 
-          $initial_total += $score;
+                    $initial_total += (int) $score;
 
-          echo("<tr id=\"q_{$q}_{$id}\" $class>");
-          echo("<td class=\"participant\" width=\"200\" valign=\"middle\">$name</th>\n");
-          echo("<td><input type=\"text\" name=\"q_{$q}_{$id}\" id=\"q_{$q}_{$index}\" size=\"6\" maxlength=\"4\" value=\"$score\" onchange=\"calcTotal({$q},{$participant_count})\" onkeyup=\"calcTotal({$q},{$participant_count})\" /></label></td>\n");
-          $index++;
-        }
-        echo("</tr>\n");
+                    echo "<tr id=\"q_{$q}_{$id}\" $class>";
+                    echo "<td class=\"participant\" width=\"200\" valign=\"middle\">$name</th>\n";
+                    echo "<td><input type=\"text\" name=\"q_{$q}_{$id}\" id=\"q_{$q}_{$index}\" size=\"6\" maxlength=\"4\" value=\"$score\" onchange=\"calcTotal({$q},{$participant_count})\" onkeyup=\"calcTotal({$q},{$participant_count})\" /></label></td>\n";
+                    $index++;
+                }
+                echo "</tr>\n";
 
-        // Footer row
-        if ($initial_total==$group_total) {
-          $bgcolor = 'transparent';
-        } else {
-          if ($initial_total>$group_total) {
-            $bgcolor = '#f99';
-          } else {
-            $bgcolor = '#ff9';
-          }
-        }
+                // Footer row
+                if ($initial_total==$group_total) {
+                    $bgcolor = 'transparent';
+                } else {
+                    if ($initial_total>$group_total) {
+                        $bgcolor = '#f99';
+                    } else {
+                        $bgcolor = '#ff9';
+                    }
+                }
 
-        echo("<tr><th style=\"text-align: right;\">Total&nbsp;</th><th><div style=\"background-color: $bgcolor;\" id=\"total_{$q}\">$initial_total</div></th></tr>");
-?>
+                echo "<tr><th style=\"text-align: right;\">Total&nbsp;</th><th><div style=\"background-color: $bgcolor;\" id=\"total_{$q}\">$initial_total</div></th></tr>"; ?>
           </table>
         </div>
 <?php
-      }// /foreach(question)
-    } else {
-      for ($q=0; $q<$question_count; $q++) {
-        $question = $this->_form->get_question($q);
-
-        $q_num = $q + 1;
-        $range = explode('-', $question['range']['_data']);
-        $min_score = $range[0];
-        $max_score = $range[1];
-?>
+            }// /foreach(question)
+        } else {
+            for ($q=0; $q<$question_count; $q++) {
+                $question = $this->_form->get_question($q);
+
+                $q_num = $q + 1;
+                $range = explode('-', $question['range']['_data']);
+                $min_score = $range[0];
+                $max_score = $range[1]; ?>
         <div class="question">
-          <div class="question_text"><?php echo("{$q_num}. {$question['text']['_data']}"); ?></div>
+          <div class="question_text"><?php echo "{$q_num}. {$question['text']['_data']}"; ?></div>
 <?php
         if (array_key_exists('desc', $question)) {
-          $question_desc = (array_key_exists('desc', $question)) ? $question['desc']['_data'] : '' ;
-          echo("<div>$question_desc</div>");
-        }
-?>
+            $question_desc = (array_key_exists('desc', $question)) ? $question['desc']['_data'] : '' ;
+            echo "<div>$question_desc</div>";
+        } ?>
           <div class="question_scoring_labels">
 <?php
         foreach ($question as $k => $v) {
-          if (strpos($k,'scorelabel')===0) {
-            $num = str_replace('scorelabel','',$k);
-            echo("<div class=\"question_score_label\">Score $num : {$v['_data']}</div>");
-          }
-        }
-?>
+            if (strpos($k, 'scorelabel')===0) {
+                $num = str_replace('scorelabel', '', $k);
+                echo "<div class=\"question_score_label\">Score $num : {$v['_data']}</div>";
+            }
+        } ?>
           </div>
 
           <table class="question_grid" cellpadding="3" cellspacing="1">
 <?php
         // header row
-        echo('<tr><td style="background-color: transparent">&nbsp;</td>');
-        for ($score=$min_score; $score<=$max_score; $score++) {
-          echo("<th align=\"center\" width=\"40\">$score</th>\n");
-        }
-        echo('</tr>');
+        echo '<tr><td style="background-color: transparent">&nbsp;</td>';
+                for ($score=$min_score; $score<=$max_score; $score++) {
+                    echo "<th align=\"center\" width=\"40\">$score</th>\n";
+                }
+                echo '</tr>';
 
-        // show participant rows
-        foreach ($this->_participants as $id => $name) {
-          $class = ($id==$this->participant_id) ? 'class="this_participant"' : '';
+                // show participant rows
+                foreach ($this->_participants as $id => $name) {
+                    $class = ($id==$this->participant_id) ? 'class="this_participant"' : '';
 
-          $q_score = ( (is_array($this->_results))
+                    $q_score = ((is_array($this->_results))
                         && (array_key_exists("$q", $this->_results))
-                        && (array_key_exists($id, $this->_results["$q"])) ) ? $this->_results["$q"]["$id"] : null;
-
-          echo("<tr id=\"q_{$q}_{$id}\" $class>");
-          echo("<td class=\"participant\" width=\"200\" valign=\"middle\">$name</th>\n");
-          for ($score=$min_score; $score<=$max_score; $score++) {
-            $checked = ($q_score==$score) ? 'checked="checked"' : '';
-            echo("<td width=\"40\" valign=\"middle\"><label for=\"q_{$q}_{$id}_{$score}\" style=\"display: block;\"><input type=\"radio\" name=\"q_{$q}_{$id}\" id=\"q_{$q}_{$id}_{$score}\" value=\"$score\" $checked /></label></td>\n");
-          }
-        }
-        echo("</tr>\n");
-?>
+                        && (array_key_exists($id, $this->_results["$q"]))) ? $this->_results["$q"]["$id"] : null;
+
+                    echo "<tr id=\"q_{$q}_{$id}\" $class>";
+                    echo "<td class=\"participant\" width=\"200\" valign=\"middle\">$name</th>\n";
+                    for ($score=$min_score; $score<=$max_score; $score++) {
+                        $checked = ($q_score==$score) ? 'checked="checked"' : '';
+                        echo "<td width=\"40\" valign=\"middle\"><label for=\"q_{$q}_{$id}_{$score}\" style=\"display: block;\"><input type=\"radio\" name=\"q_{$q}_{$id}\" id=\"q_{$q}_{$id}_{$score}\" value=\"$score\" $checked /></label></td>\n";
+                    }
+                }
+                echo "</tr>\n"; ?>
           </table>
         </div>
 <?php
-      }// /foreach(question)
-    }// /if-else (likert)
+            }// /foreach(question)
+        }// /if-else (likert)
 
-    if (APP__ALLOW_TEXT_INPUT){
-      if (!empty($this->assessment_feedback)){
-        if($this->assessment_feedback){
-?>
+    if (APP__ALLOW_TEXT_INPUT) {
+        if (!empty($this->assessment_feedback)) {
+            if ($this->assessment_feedback) {
+                ?>
         <div class="question">
         <p><b><?php echo $this->assessment_feedback_title; ?></b></p>
           <p>This section of the assessment is for you to provide general feedback and/or justification of the <?php echo APP__MARK_TEXT; ?> you have awarded in the section above.</p>
           <table class="question_grid" >
 <?php
           //now we know that the assessment feedback is allowed by the system we need to find out if the tutor has set feedback
-          if($this->assessment_feedback){
-            //out put the boxes
-            foreach($this->_participants as $id => $name) {
-              echo("<tr><td class=\"participant\" width=\"200\" valign=\"middle\">$name</th>\n");
-              echo("<td><textarea name=\"$id\" rows=\"4\" cols=\"75\">". Common::fetch_POST($id) ."</textarea></td></tr>");
-            }
-          }
-?>
+          if ($this->assessment_feedback) {
+              //out put the boxes
+              foreach ($this->_participants as $id => $name) {
+                  echo "<tr><td class=\"participant\" width=\"200\" valign=\"middle\">$name</th>\n";
+                  echo "<td><textarea name=\"$id\" rows=\"4\" cols=\"75\">". Common::fetch_POST($id) .'</textarea></td></tr>';
+              }
+          } ?>
           </table>
         </div>
 <?php
+            }
         }
-      }
+    }
     }
 
-  }// /->draw_form()
+    // /->draw_form()
 
 /*
 * ================================================================================
 * Private Methods
 * ================================================================================
 */
-
 }// /class: Form
 
 ?>
diff --git a/src/includes/classes/Group.php b/src/includes/classes/Group.php
index 1a25d02..cf66d2c 100644
--- a/src/includes/classes/Group.php
+++ b/src/includes/classes/Group.php
@@ -18,296 +18,419 @@
 
 namespace WebPA\includes\classes;
 
+use Doctrine\DBAL\Connection;
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\functions\Common;
 
-class Group {
-  // Public Vars
-  public $id = null;
-  public $name = '';
-  public $collection_id = '';   // READONLY
-
-  // Private Vars
-  private $_DAO = null;
-  private $_collection = null;
-  private $_members = null;
-
-  /**
-  * CONSTRUCTOR for group
-  */
-  function __construct() {
-    $this->_collection = null;
-    $this->_members = null;
-  }// /->Group()
-
-/*
-* ================================================================================
-* Public Methods
-* ================================================================================
-*/
-
-/*
-* --------------------------------------------------------------------------------
-* Load/Save Functions
-* --------------------------------------------------------------------------------
-*/
-
-  /**
-   *  Create a new group id
-  */
-  function create() {
-    // generate a new project_id
-    while (true) {
-      $new_id = Common::uuid_create();
-      if ($this->_DAO->fetch_value("SELECT COUNT(group_id) FROM " . APP__DB_TABLE_PREFIX . "user_group WHERE group_id = '$new_id' ") == 0) { break; }
+class Group
+{
+    // Public Vars
+    public $id;
+
+    public $name = '';
+
+    public $collection_id = '';   // READONLY
+
+    // Private Vars
+    private DAO $_DAO;
+
+    private Connection $dbConn;
+
+    private $_collection;
+
+    private $_members;
+
+    /**
+    * CONSTRUCTOR for group
+    */
+    public function __construct()
+    {
+        $this->_collection = null;
+        $this->_members = null;
     }
-    $this->id = $new_id;
-  }// ->create()
-
-  /**
-  * Delete this Group (and all its members)
-  * @return boolean
-  */
-  function delete() {
-    if ($this->_collection->is_locked()) {
-      return false;
-    } else {
-      $this->_DAO->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "user_group_member WHERE group_id = '{$this->id}' ");
-      $this->_DAO->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "user_group WHERE group_id = '{$this->id}' ");
-      return true;
+
+    // /->Group()
+
+    /*
+    * ================================================================================
+    * Public Methods
+    * ================================================================================
+    */
+
+    /*
+    * --------------------------------------------------------------------------------
+    * Load/Save Functions
+    * --------------------------------------------------------------------------------
+    */
+
+    /**
+     *  Create a new group id
+    */
+    public function create()
+    {
+        // generate a new project_id
+        while (true) {
+            $new_id = Common::uuid_create();
+
+            $countGroupsQuery =
+          'SELECT COUNT(group_id) ' .
+          'FROM ' . APP__DB_TABLE_PREFIX . 'user_group ' .
+          'WHERE group_id = ?';
+
+            $groupCount = $this->dbConn->fetchOne($countGroupsQuery, [$new_id], [ParameterType::STRING]);
+
+            if ($groupCount == 0) {
+                break;
+            }
+        }
+        $this->id = $new_id;
     }
-  }// /->delete()
-
-  /*
-  * Load the Group from the database
-  *
-  * @param string $id  id of Group to load
-  *
-  * @return boolean did load succeed
-  */
-  function load($id) {
-    $row = $this->_DAO->fetch_row("SELECT * FROM " . APP__DB_TABLE_PREFIX . "user_group WHERE group_id = '$id' LIMIT 1");
-    return ($row) ? $this->load_from_row($row) : false;
-  }// /->load()
-
-  /**
-  * Load the Group from an array row
-  *
-  * @param array $row assocated array ( field => value, ... ) - corresponds to row in database
-  *
-  * @return boolean did load succeed
-  */
-  function load_from_row(&$row) {
-    $this->id = $row['group_id'];
-    $this->name = $row['group_name'];
-    $this->collection_id = $row['collection_id'];
-    return true;
-  }// /->load_from_row()
-
-
-  /*
-  * Save this Group
-  *
-  * @return boolean did save succeed
-  */
-  function save() {
-    if ( (!$this->id) || ($this->_collection->is_locked()) ) {
-      return false;
-    } else {
-      if (!is_array($this->_members)) { $this->refresh_members(); }
-
-      $_fields = array (
-                'group_id'    => $this->id ,
-                'collection_id' => $this->_collection->id ,
-                'group_name'  => $this->name );
-
-      // Save the Group
-      $sql = 'INSERT ' . APP__DB_TABLE_PREFIX . 'user_group ({fields}) VALUES ({values}) ' .
-         'ON DUPLICATE KEY UPDATE group_name = ' . $this->_DAO->_prepare_field_value($_fields['group_name']);
-      $this->_DAO->do_insert($sql, $_fields);
-
-      // Save the Group's members by deleting them all, then re-inserting
-      $this->_DAO->execute( "DELETE FROM " . APP__DB_TABLE_PREFIX . "user_group_member
-                   WHERE group_id = '{$this->id}'
-                  ");
-
-      // If there are members to re-insert, do it
-      if (count($this->_members) > 0) {
-        $fields = null;
-        foreach($this->_members as $user_id => $role) {
-          $fields[] = array ('group_id'   => $this->id ,
-                     'user_id'    => $user_id ,
-                    );
-
-          // This double-delete nonsense solves a referential integrity problem
-          // with students managing to get themselves into TWO groups at once.
-          $this->_DAO->execute("  DELETE FROM " . APP__DB_TABLE_PREFIX . "user_group_member
-                        WHERE user_id = $user_id AND group_id IN
-                          (
-                            SELECT group_id
-                            FROM " . APP__DB_TABLE_PREFIX . "user_group
-                            WHERE collection_id = '{$this->_collection->id}'
-                          )
-                    ");
+
+    // ->create()
+
+    /**
+    * Delete this Group (and all its members)
+    * @return boolean
+    */
+    public function delete()
+    {
+        if ($this->_collection->is_locked()) {
+            return false;
         }
+        $this->dbConn->executeQuery(
+                'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user_group_member WHERE group_id = ?',
+                [$this->id],
+                [ParameterType::STRING]
+            );
+
+        $this->dbConn->executeQuery(
+                'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user_group WHERE group_id = ?',
+                [$this->id],
+                [ParameterType::STRING]
+            );
+
+        return true;
+    }
 
-        $this->_DAO->do_insert_multi("REPLACE INTO " . APP__DB_TABLE_PREFIX . "user_group_member ({fields}) VALUES {values} ", $fields);
-      }
+    /*
+    * Load the Group from the database
+    *
+    * @param string $id  id of Group to load
+    *
+    * @return boolean did load succeed
+    */
+    public function load($id)
+    {
+        $groupQuery =
+        'SELECT * ' .
+        'FROM ' . APP__DB_TABLE_PREFIX . 'user_group ' .
+        'WHERE group_id = ? ' .
+        'LIMIT 1';
+
+        $row = $this->dbConn->fetchAssociative($groupQuery, [$id], [ParameterType::STRING]);
+
+        return ($row) ? $this->load_from_row($row) : false;
+    }
 
-      return true;
+    /**
+    * Load the Group from an array row
+    *
+    * @param array $row assocated array ( field => value, ... ) - corresponds to row in database
+    *
+    * @return boolean did load succeed
+    */
+    public function load_from_row(&$row)
+    {
+        $this->id = $row['group_id'];
+        $this->name = $row['group_name'];
+        $this->collection_id = $row['collection_id'];
+        return true;
     }
-  }// /->save()
-
-/*
-* --------------------------------------------------------------------------------
-* Accessor Methods
-* --------------------------------------------------------------------------------
-*/
-
-  /**
-  * Get this Group object's data as an array
-  */
-  function get_as_array() {
-    return array  ('group_id'   => $this->id ,
-             'collection_id'=> $this->_collection->id ,
-             'group_name' => $this->name ,);
-  }// /->get_as_array()
-
-  /**
-  * Set this group to use the given DAO object
-  */
-  function set_dao_object(&$DAO) {
-    $this->_DAO =& $DAO;
-  }// /->set_dao_object()
-
-  /**
-  * Set this group to use the given GroupCollection as a parent
-  */
-  function set_collection_object(&$collection) {
-    $this->_collection =& $collection;
-    $this->collection_id = $this->_collection->id;
-  }// /->set_collection_object()
-
-/*
-* --------------------------------------------------------------------------------
-* Member-Manipulation Methods
-* --------------------------------------------------------------------------------
-*/
-
-  /**
-  * Add a member to this group
-  *
-  *
-  * @param string $user_id   User ID to add
-  * @param string $role   Role within the group
-  */
-  function add_member($user_id, $role) {
-    //if (!is_array($this->_members)) { $this->refresh_members(); }
-    $this->_members[$user_id] = $role;
-  }// /->add_member()
-
-  /**
-  * Returns the member list belonging to this group
-  *
-  * @return array array[0..n] of array array ( user_id => user_role )
-  */
-  function get_members() {
-    if (!is_array($this->_members)) { $this->refresh_members(); }
-    return $this->_members;
-  }// /->get_members()
-
-  /**
-  * Returns the member list belonging to this group
-  *
-  * @return array  array[0..n] of array ( user_id => user_role )
-  */
-  function get_member_ids() {
-    if (!is_array($this->_members)) { $this->refresh_members(); }
-    return array_keys($this->_members);
-  }// /->get_member_ids()
-
-  /**
-  * Returns a count of the number of members belonging to this group
-  *
-  * @return integer count of members
-  */
-  function get_members_count() {
-    if (!is_array($this->_members)) { $this->refresh_members(); }
-    return count($this->_members);
-  }// ->get_members_count()
-
-  /**
-  * Purge the group of members using include/exclude lists
-  * Due to the way the lists work, you need only use one of them at a time
-  *
-  * @param string|array $target_roles     role to purge
-  *                  array of roles to purge
-  *                   If a $target_roles list is given (not null), and a user's role is not in it, they are kept regardless of the $protect_list
-  *                   If a user's role is in the $target_roles list, they are removed
-  *
-  * @param string|array $protect_roles  single role to keep
-  *                   array of roles to keep
-  *                   If a user's role is in the $protect_roles list, they are kept
-  *@return boolean
-  */
-  function purge_members($target_roles = null, $protect_roles = null) {
-    if (!is_array($this->_members)) { $this->refresh_members(); }
-
-    // If we're purging everything, do it
-    if ( (!$target_roles) && (!$protect_roles) ) {
-      $this->_members = array();  // empty array, not NULL, as that would usually trigger a ->refresh_members() call in other member functions
-    } else {
-      $post_purge_members = array();
-
-      // If there's a target list.. save the untargetted roles
-      if ($target_roles) {
-        $target_roles = (array) $target_roles;
-        foreach ($this->_members as $user_id => $role) {
-          if (!in_array($role,$target_roles)) { $post_purge_members[$user_id] = $role; }
-        }// /for
-      } else {  // Else.. save every user with a protected role
-        $protect_roles = (array) $protect_roles;
-        foreach ($this->_members as $user_id => $role) {
-          if (in_array($role, $protect_roles)) { $post_purge_members[$user_id] = $role; }
-        }// /for
-      }
-      $this->_members = $post_purge_members;
+
+    // /->load_from_row()
+
+    /*
+    * Save this Group
+    *
+    * @return boolean did save succeed
+    */
+    public function save()
+    {
+        if ((!$this->id) || ($this->_collection->is_locked())) {
+            return false;
+        }
+
+        if (!is_array($this->_members)) {
+            $this->refresh_members();
+        }
+
+        // check if the group already exists in the database
+        $groupId = $this->dbConn->fetchOne(
+            'SELECT group_id FROM ' . APP__DB_TABLE_PREFIX . 'user_group WHERE group_id = ?',
+            [$this->id],
+            [ParameterType::STRING]
+        );
+
+        $queryBuilder = $this->dbConn->createQueryBuilder();
+
+        if (!empty($groupId)) {
+            // group already exists so update it
+            $queryBuilder
+            ->update(APP__DB_TABLE_PREFIX . 'user_group')
+            ->set('group_name', '?')
+            ->where('group_id = ?')
+            ->setParameter(0, $this->name)
+            ->setParameter(1, $this->id);
+        } else {
+            // the group doesn't exist so create it
+            $queryBuilder
+            ->insert(APP__DB_TABLE_PREFIX . 'user_group')
+            ->values([
+               'group_id' => '?',
+               'collection_id' => '?',
+               'group_name' => '?',
+            ])
+            ->setParameter(0, $this->id)
+            ->setParameter(1, $this->_collection->id)
+            ->setParameter(2, $this->name);
+        }
+
+        $queryBuilder->execute();
+
+        // Save the Group's members by deleting them all, then re-inserting
+        $this->dbConn->executeQuery(
+            'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user_group_member WHERE group_id = ?',
+            [$this->id],
+            [ParameterType::STRING]
+        );
+
+        // If there are members to re-insert, do it
+        if (count($this->_members) > 0) {
+            $fields = null;
+
+            foreach ($this->_members as $user_id => $role) {
+                $fields[] = ['group_id'   => $this->id,
+                     'user_id'    => $user_id,
+                    ];
+
+                // This double-delete nonsense solves a referential integrity problem
+                // with students managing to get themselves into TWO groups at once.
+                $deleteQuery =
+                'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user_group_member ' .
+                'WHERE user_id = ? ' .
+                'AND group_id IN ' .
+                '( ' .
+                'SELECT group_id ' .
+                'FROM ' . APP__DB_TABLE_PREFIX . 'user_group ' .
+                'WHERE collection_id = ? ' .
+                ')';
+
+                $this->dbConn->executeQuery(
+                    $deleteQuery,
+                    [$user_id, $this->_collection->id],
+                    [ParameterType::INTEGER, ParameterType::STRING]
+                );
+            }
+
+            foreach ($fields as $values) {
+                $this->dbConn
+                ->createQueryBuilder()
+                ->insert(APP__DB_TABLE_PREFIX . 'user_group_member')
+                ->values([
+                    'group_id' => '?',
+                    'user_id' => '?',
+                ])
+                ->setParameter(0, $this->id)
+                ->setParameter(1, $values['user_id'])
+                ->execute();
+            }
+        }
+
+        return true;
+    }
+
+    /*
+    * --------------------------------------------------------------------------------
+    * Accessor Methods
+    * --------------------------------------------------------------------------------
+    */
+
+    /**
+    * Get this Group object's data as an array
+    */
+    public function get_as_array()
+    {
+        return ['group_id'   => $this->id,
+             'collection_id'=> $this->_collection->id,
+             'group_name' => $this->name, ];
+    }
+
+    // /->get_as_array()
+
+    /**
+    * Set this group to use the given DAO object
+    */
+    public function set_dao_object(&$DAO)
+    {
+        $this->_DAO =& $DAO;
+        $this->dbConn = $this->_DAO->getConnection();
+    }
+
+    /**
+    * Set this group to use the given GroupCollection as a parent
+    */
+    public function set_collection_object(&$collection)
+    {
+        $this->_collection =& $collection;
+        $this->collection_id = $this->_collection->id;
+    }
+
+    // /->set_collection_object()
+
+    /*
+    * --------------------------------------------------------------------------------
+    * Member-Manipulation Methods
+    * --------------------------------------------------------------------------------
+    */
+
+    /**
+    * Add a member to this group
+    *
+    *
+    * @param string $user_id   User ID to add
+    * @param string $role   Role within the group
+    */
+    public function add_member($user_id, $role)
+    {
+        $this->_members[$user_id] = $role;
+    }
+
+    /**
+    * Returns the member list belonging to this group
+    *
+    * @return array array[0..n] of array array ( user_id => user_role )
+    */
+    public function get_members()
+    {
+        if (!is_array($this->_members)) {
+            $this->refresh_members();
+        }
+        return $this->_members;
     }
-    return true;
-  }// /->purge_members()
-
-  /**
-  * Refresh the member list for this object from the database
-  * Any unsaved-changes made to the members list are lost
-  */
-  function refresh_members() {
-    $this->_members = $this->_DAO->fetch_assoc("SELECT user_id, 'member' AS user_role
-                          FROM " . APP__DB_TABLE_PREFIX . "user_group_member
-                          WHERE group_id = '{$this->id}'
-                          ORDER BY user_id ASC
-                          ");
-
-    if (!$this->_members) { $this->_members = array(); }
-  }// /->refresh_members()
-
-  /**
-  * Remove a member from this group
-  *
-  * @param string $user_id  User ID to remove
-  */
-  function remove_member($user_id) {
-    if (!is_array($this->_members)) { $this->refresh_members(); }
-
-    if (array_key_exists($user_id, $this->_members)) {
-      unset($this->_members[$user_id]);
+
+    // /->get_members()
+
+    /**
+    * Returns the member list belonging to this group
+    *
+    * @return array  array[0..n] of array ( user_id => user_role )
+    */
+    public function get_member_ids()
+    {
+        if (!is_array($this->_members)) {
+            $this->refresh_members();
+        }
+        return array_keys($this->_members);
     }
-  }// /->remove_member();
 
-/*
-* ================================================================================
-* Private Methods
-* ================================================================================
-*/
+    // /->get_member_ids()
+
+    /**
+    * Returns a count of the number of members belonging to this group
+    *
+    * @return integer count of members
+    */
+    public function get_members_count()
+    {
+        if (!is_array($this->_members)) {
+            $this->refresh_members();
+        }
+        return count($this->_members);
+    }
 
-}// /class: Group
+    // ->get_members_count()
+
+    /**
+    * Purge the group of members using include/exclude lists
+    * Due to the way the lists work, you need only use one of them at a time
+    *
+    * @param string|array $target_roles     role to purge
+    *                  array of roles to purge
+    *                   If a $target_roles list is given (not null), and a user's role is not in it, they are kept regardless of the $protect_list
+    *                   If a user's role is in the $target_roles list, they are removed
+    *
+    * @param string|array $protect_roles  single role to keep
+    *                   array of roles to keep
+    *                   If a user's role is in the $protect_roles list, they are kept
+    *@return boolean
+    */
+    public function purge_members($target_roles = null, $protect_roles = null)
+    {
+        if (!is_array($this->_members)) {
+            $this->refresh_members();
+        }
 
-?>
+        // If we're purging everything, do it
+        if ((!$target_roles) && (!$protect_roles)) {
+            $this->_members = [];  // empty array, not NULL, as that would usually trigger a ->refresh_members() call in other member functions
+        } else {
+            $post_purge_members = [];
+
+            // If there's a target list.. save the untargetted roles
+            if ($target_roles) {
+                $target_roles = (array) $target_roles;
+                foreach ($this->_members as $user_id => $role) {
+                    if (!in_array($role, $target_roles)) {
+                        $post_purge_members[$user_id] = $role;
+                    }
+                }// /for
+            } else {  // Else.. save every user with a protected role
+        $protect_roles = (array) $protect_roles;
+                foreach ($this->_members as $user_id => $role) {
+                    if (in_array($role, $protect_roles)) {
+                        $post_purge_members[$user_id] = $role;
+                    }
+                }// /for
+            }
+            $this->_members = $post_purge_members;
+        }
+        return true;
+    }
+
+    // /->purge_members()
+
+    /**
+    * Refresh the member list for this object from the database
+    * Any unsaved-changes made to the members list are lost
+    */
+    public function refresh_members()
+    {
+        $membersQuery =
+        'SELECT user_id, "member" AS user_role ' .
+        'FROM ' . APP__DB_TABLE_PREFIX . 'user_group_member ' .
+        'WHERE group_id = ? ' .
+        'ORDER BY user_id ASC';
+
+        $this->_members = $this->dbConn->fetchAllKeyValue($membersQuery, [$this->id], [ParameterType::STRING]);
+
+        if (!$this->_members) {
+            $this->_members = [];
+        }
+    }
+
+    /**
+    * Remove a member from this group
+    *
+    * @param string $user_id  User ID to remove
+    */
+    public function remove_member($user_id)
+    {
+        if (!is_array($this->_members)) {
+            $this->refresh_members();
+        }
+
+        if (array_key_exists($user_id, $this->_members)) {
+            unset($this->_members[$user_id]);
+        }
+    }
+}
diff --git a/src/includes/classes/GroupCollection.php b/src/includes/classes/GroupCollection.php
index e7ac2fe..27ee332 100644
--- a/src/includes/classes/GroupCollection.php
+++ b/src/includes/classes/GroupCollection.php
@@ -15,32 +15,40 @@
 
 namespace WebPA\includes\classes;
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\functions\Common;
 
 class GroupCollection
 {
     // Public Vars
-    public $id = null;
-    public $module_id = null;
+    public $id;
+
+    public $module_id;
+
     public $name = '';
 
     // Private Vars
-    private $_DAO = null;
+    private $_DAO;
+
+    private $dbConn;
 
-    private $_groups = null;
-    private $_group_objects = null;
+    private $_groups;
 
-    private $_created_on = null;
-    private $_locked_on = null;
+    private $_group_objects;
 
-    private $_assessment_id = null;
+    private $_created_on;
+
+    private $_locked_on;
+
+    private $_assessment_id;
 
     /**
      * CONSTRUCTOR for the Group collection function
      */
-    function __construct($DAO)
+    public function __construct(DAO $DAO)
     {
         $this->_DAO = $DAO;
+        $this->dbConn = $this->_DAO->getConnection();
         $this->_created_on = time();
     }
 
@@ -59,16 +67,26 @@ function __construct($DAO)
     /**
      *  Create a new GroupCollection (generates unique collection_id)
      */
-    function create()
+    public function create()
     {
         while (true) {
             $new_id = Common::uuid_create();
-            if ($this->_DAO->fetch_value("SELECT COUNT(collection_id) AS num_id FROM " . APP__DB_TABLE_PREFIX . "collection WHERE collection_id = '$new_id' ") == 0) {
+
+            $countCollectionsQuery =
+                'SELECT COUNT(collection_id) AS num_id ' .
+                'FROM ' . APP__DB_TABLE_PREFIX . 'collection ' .
+                'WHERE collection_id = ?';
+
+            $collectionCount = $this->dbConn->fetchOne($countCollectionsQuery, [$new_id], [ParameterType::STRING]);
+
+            if ($collectionCount == 0) {
                 break;
             }
         }
         $this->id = $new_id;
-    }// ->create()
+    }
+
+    // ->create()
 
     /**
      * Load the GroupCollection from the database
@@ -77,14 +95,19 @@ function create()
      *
      * @return boolean did load succeed
      */
-    function load($id)
+    public function load($id)
     {
-        $row = $this->_DAO->fetch_row("SELECT c.*, a.assessment_id AS collection_assessment_id
-       FROM " . APP__DB_TABLE_PREFIX . "collection c
-         LEFT OUTER JOIN " . APP__DB_TABLE_PREFIX . "assessment a ON c.collection_id = a.collection_id
-       WHERE c.collection_id = '$id'");
+        $groupCollectionQuery =
+            'SELECT c.*, a.assessment_id AS collection_assessment_id ' .
+            'FROM ' . APP__DB_TABLE_PREFIX . 'collection c ' .
+            'LEFT OUTER JOIN ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
+            'ON c.collection_id = a.collection_id ' .
+            'WHERE c.collection_id = ?';
+
+        $row = $this->dbConn->fetchAssociative($groupCollectionQuery, [$id], [ParameterType::STRING]);
+
         return ($row) ? $this->load_from_row($row) : false;
-    }// /->load()
+    }
 
     /**
      * Load the GroupCollection from an array row
@@ -93,16 +116,18 @@ function load($id)
      *
      * @return boolean
      */
-    function load_from_row(&$row)
+    public function load_from_row(&$row)
     {
         $this->id = $row['collection_id'];
         $this->module_id = $row['module_id'];
         $this->name = $row['collection_name'];
         $this->_created_on = strtotime($row['collection_created_on']);
         $this->_locked_on = ((is_null($row['collection_locked_on'])) ? null : strtotime($row['collection_locked_on']));
-        $this->_assessment_id = $row['collection_assessment_id'];
+        $this->_assessment_id = $row['collection_assessment_id'] ?? null;
         return true;
-    }// /->load_from_row()
+    }
+
+    // /->load_from_row()
 
     /**
      * Delete this GroupCollection (and all its groups, members, and module links)
@@ -110,55 +135,111 @@ function load_from_row(&$row)
      *
      * @retutn  boolean did deletion succeed
      */
-    function delete()
+    public function delete()
     {
         if ($this->is_locked()) {
             return false;
-        } else {
-            $this->_DAO->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "user_group_member WHERE group_id IN (SELECT group_id FROM " . APP__DB_TABLE_PREFIX . "user_group WHERE collection_id = '{$this->id}')");
-            $this->_DAO->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "user_group WHERE collection_id = '{$this->id}'");
-            $this->_DAO->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "collection WHERE collection_id = '{$this->id}'");
-            return true;
         }
-    }// /->delete()
+
+        $this->dbConn->executeQuery(
+                'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user_group_member WHERE group_id IN (SELECT group_id FROM ' . APP__DB_TABLE_PREFIX . 'user_group WHERE collection_id = ?)',
+                [$this->id],
+                [ParameterType::STRING]
+            );
+
+        $this->dbConn->executeQuery(
+                'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user_group WHERE collection_id = ?',
+                [$this->id],
+                [ParameterType::STRING]
+            );
+
+        $this->dbConn->executeQuery(
+                'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'collection WHERE collection_id = ?',
+                [$this->id],
+                [ParameterType::STRING]
+            );
+
+        return true;
+    }
 
     /**
      * Save this GroupCollection
      *
      * @return boolean did save succeed
      */
-    function save()
+    public function save()
     {
         if ((!$this->id) || ($this->is_locked())) {
             return false;
-        } else {
-            // load all necessary info
-            $fields = array('collection_id' => $this->id,
+        }
+        // load all necessary info
+        $fields = ['collection_id' => $this->id,
                 'module_id' => $this->module_id,
                 'collection_name' => $this->name,
                 'collection_created_on' => date(MYSQL_DATETIME_FORMAT, $this->_created_on),
                 'collection_locked_on' => ((!$this->_locked_on) ? null : date(MYSQL_DATETIME_FORMAT, $this->_locked_on)),
-            );
-
-            // Save this collection
-            $sql = 'INSERT ' . APP__DB_TABLE_PREFIX . 'collection ({fields}) VALUES ({values}) ' .
-                "ON DUPLICATE KEY UPDATE module_id = {$fields['module_id']}, collection_name = '{$fields['collection_name']}', collection_created_on = '{$fields['collection_created_on']}', ";
-            if (is_null($fields['collection_locked_on'])) {
-                $sql .= 'collection_locked_on = NULL';
+            ];
+
+        // before saving, check if this collection already exists in the db
+        $storedCollectionId =
+                $this->dbConn->fetchOne(
+                    'SELECT collection_id FROM ' . APP__DB_TABLE_PREFIX . 'collection WHERE collection_id = ?',
+                    [$this->id],
+                    [ParameterType::STRING]
+                );
+
+        $queryBuilder = $this->dbConn->createQueryBuilder();
+
+        $createdOn = date(MYSQL_DATETIME_FORMAT, $this->_created_on);
+        $lockedOn = !$this->_locked_on ? null : date(MYSQL_DATETIME_FORMAT, $this->_locked_on);
+
+        if (!$storedCollectionId) {
+            // the collection does not exist so create it
+            $queryBuilder
+                    ->insert(APP__DB_TABLE_PREFIX . 'collection')
+                    ->values([
+                        'collection_id' => '?',
+                        'module_id' => '?',
+                        'collection_name' => '?',
+                        'collection_created_on' => '?',
+                        'collection_locked_on' => '?',
+                    ])
+                    ->setParameter(0, $this->id)
+                    ->setParameter(1, $this->module_id, ParameterType::INTEGER)
+                    ->setParameter(2, $this->name)
+                    ->setParameter(3, $createdOn)
+                    ->setParameter(4, $lockedOn);
+        } else {
+            // the collection exists so update it
+            $queryBuilder
+                    ->update(APP__DB_TABLE_PREFIX . 'collection')
+                    ->set('module_id', '?')
+                    ->set('collection_name', '?')
+                    ->set('collection_created_on', '?')
+                    ->where('collection_id = ?')
+                    ->setParameter(0, $this->module_id, ParameterType::INTEGER)
+                    ->setParameter(1, $this->name)
+                    ->setParameter(2, $createdOn)
+                    ->setParameter(3, $this->id);
+
+            // check if the locked field needs to be set
+            if (is_null($lockedOn)) {
+                $queryBuilder->set('collection_locked_on', 'NULL');
             } else {
-                $sql .= "collection_locked_on = '{$fields['collection_locked_on']}'";
+                $queryBuilder->set('collection_locked_on', '?')->setParameter(3, $lockedOn);
             }
-            $this->_DAO->do_insert($sql, $fields);
-
-            return true;
         }
-    }// /->save()
+
+        $queryBuilder->execute();
+
+        return true;
+    }
 
     /**
      * Save open Group objects attached to this GroupCollection
      * Loops through the group objects opened through the GroupCollection and saves any changes
      */
-    function save_groups()
+    public function save_groups()
     {
         if (is_array($this->_group_objects)) {
             foreach ($this->_group_objects as $group_id => $group) {
@@ -167,7 +248,9 @@ function save_groups()
                 }
             }
         }
-    }// /->save_groups()
+    }
+
+    // /->save_groups()
 
     /*
     * --------------------------------------------------------------------------------
@@ -178,7 +261,7 @@ function save_groups()
     /**
      * Set the GroupCollection's owner info
      */
-    function set_owner_info($id, $type)
+    public function set_owner_info($id, $type)
     {
         $this->_assessment_id = null;
         switch ($type) {
@@ -188,17 +271,21 @@ function set_owner_info($id, $type)
                 $this->_assessment_id = $id;
                 break;
         }
-    }// /->set_owner_info()
+    }
+
+    // /->set_owner_info()
 
     /**
      * Is this GroupCollection locked?
      *
      * @return boolean is the collection locked
      */
-    function is_locked()
+    public function is_locked()
     {
-        return ((!is_null($this->_locked_on)) || ($this->_locked_on));
-    }// /->is_locked()
+        return (!is_null($this->_locked_on)) || ($this->_locked_on);
+    }
+
+    // /->is_locked()
 
     /*
     * --------------------------------------------------------------------------------
@@ -210,16 +297,18 @@ function is_locked()
      * Lock the collection - should prevent applications editing/deleting the groups involved
      * The locked_on datetime is IMMEDIATELY SAVED to the database (no other fields are saved)
      */
-    function lock()
+    public function lock()
     {
         $this->_locked_on = time();
         if ($this->id) {
-            $_fields = array(
-                'collection_locked_on' => date(MYSQL_DATETIME_FORMAT, $this->_locked_on),
-            );
-            $this->_DAO->do_update("UPDATE " . APP__DB_TABLE_PREFIX . "collection ({fields}) WHERE collection_id = '{$this->id}' ", $_fields);
+            $stmt = $this->dbConn->prepare('UPDATE ' . APP__DB_TABLE_PREFIX . 'collection SET collection_locked_on = ? WHERE collection_id = ?');
+
+            $stmt->bindValue(1, date(MYSQL_DATETIME_FORMAT, $this->_locked_on));
+            $stmt->bindValue(2, $this->id);
+
+            $stmt->execute();
         }
-    }// /->lock()
+    }
 
     /*
     * --------------------------------------------------------------------------------
@@ -238,20 +327,22 @@ function lock()
      *
      * @return assoc array ( group_name => group_id )
      */
-    function get_groups_array()
+    public function get_groups_array()
     {
         if (!$this->_groups) {
             $this->refresh_groups();
         }
         return $this->_groups;
-    }// /->get_groups_array()
+    }
+
+    // /->get_groups_array()
 
     /**
      * Check if there is a group in this GroupCollection with the given name
      * @param string $group_name
      * @return boolean
      */
-    function group_exists($group_name)
+    public function group_exists($group_name)
     {
         if (!$this->_groups) {
             $this->refresh_groups();
@@ -266,14 +357,16 @@ function group_exists($group_name)
         }
 
         return $is_valid_group;
-    }// /->group_exists()
+    }
+
+    // /->group_exists()
 
     /**
      * Check if the group exists
      * @param mixed $group_id
      * @return bool  does the group exist in this collection
      */
-    function group_id_exists($group_id)
+    public function group_id_exists($group_id)
     {
         if (!$this->_groups) {
             $this->refresh_groups();
@@ -288,24 +381,30 @@ function group_id_exists($group_id)
         }
 
         return $is_valid_group;
-    }// /->group_id_exists()
+    }
+
+    // /->group_id_exists()
 
     /**
      * Refresh this collection's list of groups
      */
-    function refresh_groups()
+    public function refresh_groups()
     {
-        $this->_groups = $this->_DAO->fetch("
-      SELECT *
-      FROM " . APP__DB_TABLE_PREFIX . "user_group
-      WHERE collection_id = '{$this->id}'
-      ORDER BY group_name ASC
-    ");
+        $groupsQuery =
+            'SELECT * ' .
+            'FROM ' . APP__DB_TABLE_PREFIX . 'user_group ' .
+            'WHERE collection_id = ? ' .
+            'ORDER BY group_name ASC';
+
+        $this->_groups = $this->dbConn->fetchAllAssociative($groupsQuery, [$this->id], [ParameterType::STRING]);
+
         if (!$this->_groups) {
-            $this->_groups = array();
+            $this->_groups = [];
         }
         uasort($this->_groups, ['self', 'group_title_natural_sort']);
-    }// /->refresh_groups()
+    }
+
+    // /->refresh_groups()
 
     private static function group_title_natural_sort($group_a, $group_b)
     {
@@ -324,7 +423,7 @@ private static function group_title_natural_sort($group_a, $group_b)
      *
      * @param object $group_object The group to add
      */
-    function add_group_object(&$group_object)
+    public function add_group_object(&$group_object)
     {
         if (!is_array($this->_groups)) {
             $this->refresh_groups();
@@ -335,7 +434,9 @@ function add_group_object(&$group_object)
             $this->_group_objects["{$group_object->id}"] =& $group_object;
             $group_object->set_collection_object($this);
         }
-    }// /->add_group_object()
+    }
+
+    // /->add_group_object()
 
     /**
      * Get the group object corresponding to the given group_id
@@ -345,7 +446,7 @@ function add_group_object(&$group_object)
      *
      * @return object Group object (or NULL)
      */
-    function & get_group_object($group_id)
+    public function & get_group_object($group_id)
     {
         if (!is_array($this->_groups)) {
             $this->refresh_groups();
@@ -354,19 +455,20 @@ function & get_group_object($group_id)
         // If this group exists in this collection
         if ($this->group_id_exists($group_id)) {
             // If we already have a copy of the Group object, return it
-            if ((array_key_exists($group_id, (array)$this->_group_objects)) && (is_object($this->_group_objects[$group_id]))) {
+            if ((array_key_exists($group_id, (array) $this->_group_objects)) && (is_object($this->_group_objects[$group_id]))) {
                 return $this->_group_objects[$group_id];
-            } else {
-                $new_group = new Group();
-                $new_group->set_dao_object($this->_DAO);
-                $new_group->set_collection_object($this);
-                $new_group->load($group_id);
-                $this->_group_objects[$group_id] =& $new_group;
-                return $new_group;
             }
+            $new_group = new Group();
+            $new_group->set_dao_object($this->_DAO);
+            $new_group->set_collection_object($this);
+            $new_group->load($group_id);
+            $this->_group_objects[$group_id] =& $new_group;
+            return $new_group;
         }
         return null;
-    }// /->get_group_object()
+    }
+
+    // /->get_group_object()
 
     /**
      * Create a new Group object using this GroupCollection as the parent
@@ -375,7 +477,7 @@ function & get_group_object($group_id)
      * @param string $group_name Name of new group to add
      * @return array
      */
-    function & new_group($group_name = 'new group')
+    public function & new_group($group_name = 'new group')
     {
         $new_group = new Group();
         $new_group->set_dao_object($this->_DAO);
@@ -386,14 +488,16 @@ function & new_group($group_name = 'new group')
         $this->_group[$new_group->id] = $new_group->get_as_array();
         $this->_group_objects[$new_group->id] =& $new_group;
         return $new_group;
-    }// /->new_group()
+    }
+
+    // /->new_group()
 
     /**
      * Get an iterator object containg the groups belonging to this collection
      *
      * @return object GroupIterator object
      */
-    function & get_groups_iterator()
+    public function & get_groups_iterator()
     {
         if (!$this->_groups) {
             $this->refresh_groups();
@@ -404,7 +508,7 @@ function & get_groups_iterator()
         }
 
         if ($this->_group_objects !== null) {
-           $iterator = new SimpleIterator($this->_group_objects);
+            $iterator = new SimpleIterator($this->_group_objects);
         } else {
             $iterator = new SimpleIterator();
         }
@@ -425,14 +529,17 @@ function & get_groups_iterator()
      *
      * @return integer
      */
-    function get_member_count($role = null)
+    public function get_member_count($role = null)
     {
-        return $this->_DAO->fetch_value("SELECT COUNT(ugm.user_id)
-                    FROM " . APP__DB_TABLE_PREFIX . "user_group_member ugm
-                      INNER JOIN " . APP__DB_TABLE_PREFIX . "user_group ug ON ugm.group_id = ug.group_id
-                    WHERE ug.collection_id = '{$this->id}'
-                    ");
-    }// /->get_member_count()
+        $memberCountQuery =
+            'SELECT COUNT(ugm.user_id) ' .
+            'FROM ' . APP__DB_TABLE_PREFIX . 'user_group_member ugm ' .
+            'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'user_group ug ' .
+            'ON ugm.group_id = ug.group_id ' .
+            'WHERE ug.collection_id = ?';
+
+        return $this->dbConn->fetchOne($memberCountQuery, [$this->id], [ParameterType::STRING]);
+    }
 
     /**
      * Get a count of the members in this collection by group
@@ -441,15 +548,19 @@ function get_member_count($role = null)
      *
      * @return array  array ( group_id => member_count )
      */
-    function get_member_count_by_group($role = null)
+    public function get_member_count_by_group($role = null)
     {
-        return $this->_DAO->fetch_assoc("SELECT ugm.group_id, COUNT(user_id)
-                    FROM " . APP__DB_TABLE_PREFIX . "user_group_member ugm
-                      INNER JOIN " . APP__DB_TABLE_PREFIX . "user_group ug ON ugm.group_id = ug.group_id
-                    WHERE ug.collection_id = '{$this->id}'
-                    GROUP BY ugm.group_id
-                    ORDER BY ugm.group_id");
-    }// /->get_member_count_by_group()
+        $memberCountQuery =
+            'SELECT ugm.group_id, COUNT(user_id) ' .
+            'FROM ' . APP__DB_TABLE_PREFIX . 'user_group_member ugm ' .
+            'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'user_group ug ' .
+            'ON ugm.group_id = ug.group_id ' .
+            'WHERE ug.collection_id = ? ' .
+            'GROUP BY ugm.group_id ' .
+            'ORDER BY ugm.group_id';
+
+        return $this->dbConn->fetchAllKeyValue($memberCountQuery, [$this->id], [ParameterType::STRING]);
+    }
 
     /**
      * Get the members actually contained within this collection's groups
@@ -458,28 +569,36 @@ function get_member_count_by_group($role = null)
      *
      * @return array - assoc array ( user_id => user_role )
      */
-    function get_members($role = null)
+    public function get_members($role = null)
     {
-        return $this->_DAO->fetch_assoc("SELECT ugm.user_id, 'member' AS user_role
-                    FROM " . APP__DB_TABLE_PREFIX . "user_group_member ugm
-                      INNER JOIN " . APP__DB_TABLE_PREFIX . "user_group ug ON ugm.group_id = ug.group_id
-                    WHERE ug.collection_id = '{$this->id}'
-                    ORDER BY ugm.user_id ASC");
-    }// /->get_members()
+        $membersQuery =
+            'SELECT ugm.user_id, "member" AS user_role ' .
+            'FROM ' . APP__DB_TABLE_PREFIX . 'user_group_member ugm ' .
+            'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'user_group ug ' .
+            'ON ugm.group_id = ug.group_id ' .
+            'WHERE ug.collection_id = ? ' .
+            'ORDER BY ugm.user_id ASC';
+
+        return $this->dbConn->fetchAllKeyValue($membersQuery, [$this->id], [ParameterType::STRING]);
+    }
 
     /**
      * Get row data for this collection's members
      *
      * @return array - array ( group_id, user_id, user_role )
      */
-    function get_member_rows()
+    public function get_member_rows()
     {
-        return $this->_DAO->fetch("SELECT ugm.group_id, ugm.user_id
-                  FROM " . APP__DB_TABLE_PREFIX . "user_group_member ugm
-                    INNER JOIN " . APP__DB_TABLE_PREFIX . "user_group ug ON ugm.group_id = ug.group_id
-                  WHERE ug.collection_id = '{$this->id}'
-                  ORDER BY ugm.group_id ASC");
-    }// /->get_member_rows()
+        $memberRowsQuery =
+            'SELECT ugm.group_id, ugm.user_id ' .
+            'FROM ' . APP__DB_TABLE_PREFIX . 'user_group_member ugm ' .
+            'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'user_group ug ' .
+            'ON ugm.group_id = ug.group_id ' .
+            'WHERE ug.collection_id = ? ' .
+            'ORDER BY ugm.group_id ASC';
+
+        return $this->_DAO->getConnection()->fetchAllAssociative($memberRowsQuery, [$this->id], [ParameterType::STRING]);
+    }
 
     /**
      * Get group objects for all the groups the given member belongs to
@@ -488,7 +607,7 @@ function get_member_rows()
      *
      * @return array array of group objects
      */
-    function & get_member_groups($user_id)
+    public function & get_member_groups($user_id)
     {
         $member_roles = $this->get_member_roles($user_id);
         if ($member_roles) {
@@ -498,7 +617,9 @@ function & get_member_groups($user_id)
             }
             return $groups;
         }
-    }// /->get_member_groups()
+    }
+
+    // /->get_member_groups()
 
     /**
      * Get a user's roles for each group in this collection
@@ -507,14 +628,19 @@ function & get_member_groups($user_id)
      *
      * @return array - assoc array ( group_id => user_role );
      */
-    function get_member_roles($user_id)
+    public function get_member_roles($user_id)
     {
-        return $this->_DAO->fetch_assoc("SELECT ugm.group_id, 'member' AS user_role
-                    FROM " . APP__DB_TABLE_PREFIX . "user_group_member ugm
-                      INNER JOIN " . APP__DB_TABLE_PREFIX . "user_group ug ON ugm.group_id = ug.group_id
-                    WHERE ug.collection_id = '{$this->id}' AND ugm.user_id = $user_id
-                    ORDER BY ugm.group_id ASC");
-    }// /->get_member_roles()
+        $memberRolesQuery =
+            'SELECT ugm.group_id, "member" AS user_role ' .
+            'FROM ' . APP__DB_TABLE_PREFIX . 'user_group_member ugm ' .
+            'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'user_group ug ' .
+            'ON ugm.group_id = ug.group_id ' .
+            'WHERE ug.collection_id = ? ' .
+            'AND ugm.user_id = ? ' .
+            'ORDER BY ugm.group_id ASC';
+
+        return $this->dbConn->fetchAllKeyValue($memberRolesQuery, [$this->id, $user_id], [ParameterType::STRING, ParameterType::INTEGER]);
+    }
 
     /**
      * Purge a collection of its members using include/exclude lists
@@ -529,7 +655,7 @@ function get_member_roles($user_id)
      *                   (array) - array of roles to keep
      *                   If a user's role is in the $protect_roles list, they are kept
      */
-    function purge_members($target_roles = null, $protect_roles = null)
+    public function purge_members($target_roles = null, $protect_roles = null)
     {
         if ($this->is_locked()) {
             return false;
@@ -542,7 +668,9 @@ function purge_members($target_roles = null, $protect_roles = null)
                 $group->purge_members($target_roles, $protect_roles);
             }
         }
-    }// /->purge_members()
+    }
+
+    // /->purge_members()
 
     /**
      * Add member to the collection
@@ -551,20 +679,26 @@ function purge_members($target_roles = null, $protect_roles = null)
      * @param string $user_id The ID of the user to add
      * @param string $group_name The name of the group to add the user to
      */
-    function add_member($user_id, $group_name)
+    public function add_member($user_id, $group_name)
     {
-
         $this->remove_member($user_id);
         $groups = $this->get_groups_array();
         foreach ($groups as $i => $group_row) {
             if ($group_row['group_name'] == $group_name) {
                 $group_id = $group_row['group_id'];
-                $this->_DAO->execute("INSERT INTO " . APP__DB_TABLE_PREFIX . "user_group_member SET group_id = '$group_id', user_id = $user_id");
+
+                $this->dbConn->executeQuery(
+                    'INSERT INTO ' . APP__DB_TABLE_PREFIX . 'user_group_member VALUES (?, ?)',
+                    [$group_id, $user_id],
+                    [ParameterType::STRING, ParameterType::INTEGER]
+                );
+
                 break;
             }
         }
+    }
 
-    }// /->add_member()
+    // /->add_member()
 
     /**
      * Remove members from the collection
@@ -574,18 +708,29 @@ function add_member($user_id, $group_name)
      *               (array) - An array of IDs to remove (all of the same user_type)
      * @param string $role (optional) Group to remove members from. If unused, remove from all groups
      */
-    function remove_member($user_id, $role = null)
+    public function remove_member($user_id, $role = null)
     {
-        $user_set = $this->_DAO->build_set((array)$user_id);
-        $role_clause = ($role) ? " AND user_role='$role'" : '';
-        $this->_DAO->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "user_group_member ugm
-                      WHERE ugm.user_id IN $user_set AND ugm.group_id IN
-                        (SELECT group_id
-                         FROM " . APP__DB_TABLE_PREFIX . "user_group
-                         WHERE collection_id = '{$this->id}'
-                        )");
+        $userIdClause = is_array($user_id) ? 'user_id IN (?) ' : 'user_id = ? ';
+
+        $removeMemberQuery =
+            'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user_group_member ' .
+            'WHERE ' . $userIdClause .
+            'AND group_id IN ' .
+            '(' .
+            '   SELECT group_id ' .
+            '   FROM ' . APP__DB_TABLE_PREFIX . 'user_group ' .
+            '   WHERE collection_id = ? ' .
+            ')';
+
+        $stmt = $this->dbConn->prepare($removeMemberQuery);
+
+        $userIdParamType = is_array($user_id) ? $this->_DAO->getConnection()::PARAM_INT_ARRAY : ParameterType::INTEGER;
 
-    }// /->remove_member()
+        $stmt->bindValue(1, $user_id, $userIdParamType);
+        $stmt->bindValue(2, $this->id);
+
+        $stmt->execute();
+    }
 
     /*
     * --------------------------------------------------------------------------------
@@ -598,9 +743,11 @@ function remove_member($user_id, $role = null)
      *
      * @return array  array ( module_id )
      */
-    function get_modules()
+    public function get_modules()
     {
-        return $this->_DAO->fetch_assoc("SELECT DISTINCT c.module_id FROM " . APP__DB_TABLE_PREFIX . "collection c");
+        $modulesQuery = 'SELECT DISTINCT c.module_id FROM ' . APP__DB_TABLE_PREFIX . 'collection c';
+
+        return $this->dbConn->fetchFirstColumn($modulesQuery);
     }
 
     /*
@@ -608,7 +755,4 @@ function get_modules()
     * Private Methods
     * ================================================================================
     */
-
-}// /class: GroupCollection
-
-?>
+}
diff --git a/src/includes/classes/GroupHandler.php b/src/includes/classes/GroupHandler.php
index ec1b0d7..8f329cc 100644
--- a/src/includes/classes/GroupHandler.php
+++ b/src/includes/classes/GroupHandler.php
@@ -10,20 +10,22 @@
 
 namespace WebPA\includes\classes;
 
+use Doctrine\DBAL\ParameterType;
+
 class GroupHandler
 {
-    // Public Vars
-    public $_DAO = null;  // [pmn] due to a poor iterator implementation, this is currently public
+    public $_DAO;  // [pmn] due to a poor iterator implementation, this is currently public
 
-    // Private Vars
+    private $dbConn;
 
     /**
      * CONSTRUCTOR
      */
-    function __construct()
+    public function __construct()
     {
         $this->_DAO = new DAO(APP__DB_HOST, APP__DB_USERNAME, APP__DB_PASSWORD, APP__DB_DATABASE);
-    }// /->GroupHandler()
+        $this->dbConn = $this->_DAO->getConnection();
+    }
 
     /*
     * ================================================================================
@@ -38,7 +40,7 @@ function __construct()
      * @param string $group_numbering
      * @return array group names
      */
-    function generate_group_names($num_groups, $group_name_stub = 'Group', $group_numbering = 'numeric')
+    public function generate_group_names($num_groups, $group_name_stub = 'Group', $group_numbering = 'numeric')
     {
         $group_names = null;
 
@@ -81,7 +83,7 @@ private function group_suffix_alphabetic($group_num)
         $prefix = '';
 
         if ($group_num >= 26) {
-            $prefix = chr(64 + (int)($group_num / 26));
+            $prefix = chr(64 + (int) ($group_num / 26));
         }
 
         $suffix = chr(65 + ($group_num % 26));
@@ -125,7 +127,7 @@ private function group_suffix_numeric($group_num)
      *
      * @return object  GroupCollection object
      */
-    function & clone_collection($collection_id, $include_roles = null)
+    public function & clone_collection($collection_id, $include_roles = null)
     {
         // get the collection to clone
         $org_collection = new GroupCollection($this->_DAO);
@@ -166,7 +168,9 @@ function & clone_collection($collection_id, $include_roles = null)
         }
 
         return $clone_collection;
-    }// /->clone_collection()
+    }
+
+    // /->clone_collection()
 
     /**
      * Create a new GroupCollection object (gives it a new UUID and returns the object)
@@ -175,12 +179,14 @@ function & clone_collection($collection_id, $include_roles = null)
      *
      * @return array
      */
-    function & create_collection()
+    public function & create_collection()
     {
         $new_collection = new GroupCollection($this->_DAO);
         $new_collection->create();
         return $new_collection;
-    }// /->create_collection()
+    }
+
+    // /->create_collection()
 
     /**
      * Get a GroupCollection object corresponding to the given group_set_id
@@ -188,11 +194,13 @@ function & create_collection()
      * @param string $collection_id ID of GroupCollection to fetch
      * @return object GroupCollection object
      */
-    function get_collection($collection_id)
+    public function get_collection($collection_id)
     {
         $collection = new GroupCollection($this->_DAO);
         return ($collection->load($collection_id)) ? $collection : null;
-    }// /->get_collection()
+    }
+
+    // /->get_collection()
 
     /**
      * Get collections belonging to the given user
@@ -202,12 +210,20 @@ function get_collection($collection_id)
      *
      * @return array array of collections
      */
-    function get_user_collections($user_id, $application_id = null)
+    public function get_user_collections($user_id)
     {
-        return $this->_DAO->fetch('SELECT c.* FROM ' . APP__DB_TABLE_PREFIX . '_collection c INNER JOIN ' .
-            APP__DB_TABLE_PREFIX . '_user_module um ON c.module_id = um.module_id LEFT OUTER JOIN ' .
-            APP__DB_TABLE_PREFIX . "assessment a ON cm.collection_id = a.collection_id WHERE um.user_id = {$user_id} AND a.collection_id IS NULL");
-    }// /->get_user_collections()
+        $query =
+            'SELECT c.* ' .
+            'FROM ' . APP__DB_TABLE_PREFIX . 'collection c ' .
+            'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'user_module um ' .
+            'ON c.module_id = um.module_id ' .
+            'LEFT OUTER JOIN ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
+            'ON c.collection_id = a.collection_id ' .
+            'WHERE um.user_id = ? ' .
+            'AND a.collection_id IS NULL';
+
+        return $this->dbConn->fetchAllAssociative($query, [$user_id], [ParameterType::INTEGER]);
+    }
 
     /**
      * Get collections belonging to the given module
@@ -216,47 +232,49 @@ function get_user_collections($user_id, $application_id = null)
      *
      * @return array array of collections
      */
-    function get_module_collections($module_id)
+    public function get_module_collections($module_id)
     {
-        return $this->_DAO->fetch('SELECT c.*, a.assessment_id AS collection_assessment_id FROM ' . APP__DB_TABLE_PREFIX . 'collection c ' .
-            'LEFT OUTER JOIN ' . APP__DB_TABLE_PREFIX . 'assessment a ON c.collection_id = a.collection_id ' .
-            "WHERE c.module_id = {$module_id} AND a.collection_id IS NULL " .
-            'ORDER BY c.collection_name');
-
-    }// /->get_module_collections()
+        $query =
+            'SELECT c.*, a.assessment_id AS collection_assessment_id ' .
+            'FROM ' . APP__DB_TABLE_PREFIX . 'collection c ' .
+            'LEFT OUTER JOIN ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
+            'ON c.collection_id = a.collection_id ' .
+            'WHERE c.module_id = ? ' .
+            'AND a.collection_id IS NULL ' .
+            'ORDER BY c.collection_name';
+
+        return $this->dbConn->fetchAllAssociative($query, [$module_id], [ParameterType::INTEGER]);
+    }
 
     /**
      * function to get member collections
      * @param string $user_id ID of the member
-     * @param string $application_id (optional) name of owner-application to search for
      * @param string $owner_type (optional) type of collection-owner to filter against
      *
      * @return array array of collections
      */
-    function get_member_collections($user_id, $application_id = null, $owner_type)
+    public function get_member_collections($user_id, $owner_type)
     {
-        if ($owner_type == 'user') {
+        if ($owner_type === 'user') {
             $sql = 'SELECT DISTINCT c.*, NULL AS collection_assessment_id FROM ' . APP__DB_TABLE_PREFIX .
                 'collection c INNER JOIN ' . APP__DB_TABLE_PREFIX .
                 'user_group ug ON c.collection_id = ug.collection_id INNER JOIN ' . APP__DB_TABLE_PREFIX .
                 'user_group_member ugm ON ug.group_id = ugm.group_id LEFT OUTER JOIN ' . APP__DB_TABLE_PREFIX .
-                "assessment a ON a.collection_id = c.collection_id WHERE ugm.user_id = {$user_id} AND a.collection_id IS NULL";
-        } else if ($owner_type == 'assessment') {
+                'assessment a ON a.collection_id = c.collection_id WHERE ugm.user_id = ? AND a.collection_id IS NULL';
+        } elseif ($owner_type === 'assessment') {
             $sql = 'SELECT DISTINCT c.*, a.assessment_id AS collection_assessment_id FROM ' . APP__DB_TABLE_PREFIX .
                 'collection c INNER JOIN ' . APP__DB_TABLE_PREFIX .
                 'user_group ug ON c.collection_id = ug.collection_id INNER JOIN ' . APP__DB_TABLE_PREFIX .
                 'user_group_member ugm ON ug.group_id = ugm.group_id INNER JOIN ' . APP__DB_TABLE_PREFIX .
-                "assessment a ON a.collection_id = c.collection_id WHERE ugm.user_id = {$user_id}";
+                'assessment a ON a.collection_id = c.collection_id WHERE ugm.user_id = ?';
         }
 
-        $res = $this->_DAO->fetch($sql);
-        return $res;
-    }// /->get_member_collections()
+        return $this->dbConn->fetchAllAssociative($sql, [$user_id], [ParameterType::INTEGER]);
+    }
 
     /*
     * ================================================================================
     * Private Methods
     * ================================================================================
     */
-
 }// /->class: GroupHandler
diff --git a/src/includes/classes/LDAPAuthenticator.php b/src/includes/classes/LDAPAuthenticator.php
deleted file mode 100644
index 9070d68..0000000
--- a/src/includes/classes/LDAPAuthenticator.php
+++ /dev/null
@@ -1,141 +0,0 @@
-<?php
-/**
- * Class : Authenticate
- *
- * Authenticates the given username and password against the LDAP server
- * In the event of an authentication error, ->get_error() will return:
- * 'connfailed' : A connection to the authentication server could not be established
- *  'invalid'   : The login details were invalid
- *
- *
- * @copyright Loughborough University
- * @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL version 3
- *
- * @link https://github.com/webpa/webpa
- */
-
-
-namespace WebPA\includes\classes;
-
-use WebPA\includes\functions\StringFunctions;
-
-class LDAPAuthenticator extends Authenticator
-{
-
-    private $ldapRequiredFields;
-
-    public function __construct(EngCIS $cis, $username = NULL, $password = NULL)
-    {
-        parent::__construct($cis, $username, $password);
-    }
-
-    public function setRequiredInfo(array $ldapRequiredFields)
-    {
-        $this->ldapRequiredFields = $ldapRequiredFields;
-    }
-
-    /**
-     * Authenticate users against the LDAP server.
-     *
-     * @return bool
-     */
-    function authenticate()
-    {
-        $this->_authenticated = false;
-        $this->_error = null;
-
-        //set the debug level
-        ldap_set_option(null, LDAP_OPT_DEBUG_LEVEL, LDAP__DEBUG_LEVEL);
-
-        //using the ldap function connect with the specified server
-        $ldapconn = ldap_connect(LDAP__HOST, LDAP__PORT);
-
-        //check the connection
-        if (!$ldapconn) {
-            $this->_error = 'connfailed';
-
-            return false;
-        }
-
-        //Set this option to cope with Windows Server 2003 Active directories
-        ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
-
-        //Set the version of LDAP that we will be using
-        ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
-
-        //construct login name
-        $user = $this->username . LDAP__USERNAME_EXT;
-
-        //bind with the username and password
-        $bind = ldap_bind($ldapconn, $user, $this->password);
-
-        //check the bind has worked
-        if (!$bind) {
-            // drop the ldap connection
-            ldap_unbind($ldapconn);
-            $this->_error = 'connfailed';
-
-            return false;
-        }
-
-        $filter = str_replace('{username}', $this->username, LDAP__FILTER);
-
-        $info_req = $this->ldapRequiredFields;
-        $info_req[] = LDAP__USER_TYPE_ATTRIBUTE;
-        $result = ldap_search($ldapconn, LDAP__BASE, $filter, $info_req);
-
-        //check the bind has worked
-        if (!$result) {
-            //drop the ldap connection
-            ldap_unbind($ldapconn);
-            $this->_error = 'invalid';
-
-            return false;
-        }
-
-        $info = ldap_get_entries($ldapconn, $result);
-
-        ldap_unbind($ldapconn);
-
-        if ($info['count'] == 0) {
-            return false;
-        }
-
-        $_fields = [
-            'forename' => $info[0]['givenname'][0],
-            'lastname' => $info[0]['sn'][0],
-            'email' => $info[0]['mail'][0],
-            'user_type' => get_LDAP_user_type($info[0][LDAP__USER_TYPE_ATTRIBUTE]),
-        ];
-
-        $els = [];
-
-        foreach ($_fields as $key => $val) {
-            $els[] = "$key = '$val'";
-        }
-
-        $DAO = $this->get_DAO();
-        if (LDAP__AUTO_CREATE_USER) {
-
-            $sql = 'INSERT INTO ' . APP__DB_TABLE_PREFIX . 'user SET ' . implode(', ', $els) . ", username = '{$this->username}', password = '" . md5(StringFunctions::str_random()) . "', source_id = ''";
-            $sql .= ' ON DUPLICATE KEY UPDATE ' . implode(', ', $els);
-            $DAO->execute($sql);
-            $id = $DAO->get_insert_id();
-            if (!$id) {
-                $sql = 'SELECT user_id FROM ' . APP__DB_TABLE_PREFIX . "user WHERE username = '{$this->username}' AND source_id = ''";
-                $id = $DAO->fetch_value($sql);
-            }
-            $sql = 'SELECT * FROM ' . APP__DB_TABLE_PREFIX . "user WHERE user_id = $id";
-
-        } else {
-
-            $sql = 'UPDATE ' . APP__DB_TABLE_PREFIX . 'user SET ' . implode(', ', $els) . " WHERE username = '{$this->username}' AND source_id = ''";
-            $DAO->execute($sql);
-            $sql = 'SELECT * FROM ' . APP__DB_TABLE_PREFIX . "user WHERE username = '{$this->username}' AND source_id = ''";
-
-            $sql = 'SELECT * FROM ' . APP__DB_TABLE_PREFIX . "user WHERE username = '{$this->username}' AND source_id = ''";
-        }
-
-        return $this->initialise($sql);
-    }
-}
diff --git a/src/includes/classes/Module.php b/src/includes/classes/Module.php
index d46d738..9305a03 100644
--- a/src/includes/classes/Module.php
+++ b/src/includes/classes/Module.php
@@ -12,111 +12,146 @@
 
 namespace WebPA\includes\classes;
 
-class Module {
-  // Public Vars
-  public $module_code = NULL;
-  public $module_title = NULL;
-  public $module_id = NULL;
-
-  public $DAO = NULL;
-
-  /**
-  * CONSTRUCTOR for the class function
-  * @param string $code
-  * @param string $title
-  */
-  function __construct($module_code = null, $module_title = null) {
-    $this->module_code = $module_code;
-    $this->module_title = $module_title;
-    $this->module_id = null;
-  }// /->Module()
-
-/*
-* ================================================================================
-* PUBLIC
-*================================================================================
-*/
-
-  /**
-  * Load the object from the given data
-  *
-  * @param array $module_info  assoc-array of Module info
-  *
-  * @return boolean did the load succeed
-  */
-  function load_from_row($module_info) {
-    if (is_array($module_info) && isset($module_info['module_id'])) {
-      $this->module_id = $module_info['module_id'];
-      $this->module_code = $module_info['module_code'];
-      $this->module_title = $module_info['module_title'];
-    }
-    return true;
-  }// /->load_from_row()
+use Doctrine\DBAL\ParameterType;
 
-  /**
-   * Function to update the module details
-   */
-   function save_module(){
+class Module
+{
+    // Public Vars
+    public $module_code;
 
-    $_fields = array ('module_code'        => $this->module_code ,
-              'module_title'        => $this->module_title,
-               );
+    public $module_title;
 
-    //save the changes to the module
-    $this->DAO->do_update("UPDATE " . APP__DB_TABLE_PREFIX . "module SET {fields} WHERE module_id = {$this->module_id}; ",$_fields);
+    public $module_id;
 
-    return true;
-   }
+    public DAO $DAO;
 
-   /**
-    * Function to set the database connection to be used
-    * @param database connection $DB
+    /**
+    * CONSTRUCTOR for the class function
+    * @param string $code
+    * @param string $title
     */
-    function set_dao_object($DB){
-      $this->DAO = $DB;
+    public function __construct($module_code = null, $module_title = null)
+    {
+        $this->module_code = $module_code;
+        $this->module_title = $module_title;
+        $this->module_id = null;
     }
 
-  /**
-   * Function to add new module details
-   */
-   function add_module(){
+    // /->Module()
 
-    $_fields = array ('module_code'        => $this->module_code ,
-              'module_title'        => $this->module_title,
-               );
+    /*
+    * ================================================================================
+    * PUBLIC
+    *================================================================================
+    */
 
-    //save the changes to the module
-    $this->DAO->do_update('INSERT INTO ' . APP__DB_TABLE_PREFIX . "module SET {fields}", $_fields);
+    /**
+    * Load the object from the given data
+    *
+    * @param array $module_info  assoc-array of Module info
+    *
+    * @return boolean did the load succeed
+    */
+    public function load_from_row($module_info)
+    {
+        if (is_array($module_info) && isset($module_info['module_id'])) {
+            $this->module_id = $module_info['module_id'];
+            $this->module_code = $module_info['module_code'];
+            $this->module_title = $module_info['module_title'];
+        }
+        return true;
+    }
 
-    return $this->DAO->get_insert_id() ;
-   }
+    // /->load_from_row()
 
-  /**
-   * Function to delete a module
-   */
-   function delete(){
+    /**
+     * Function to update the module details
+     */
+    public function save_module()
+    {
+        $dbConn = $this->DAO->getConnection();
 
-     $collections = $this->DAO->fetch_col("SELECT collection_id FROM " . APP__DB_TABLE_PREFIX . "collection WHERE module_id = $this->module_id");
-     $group_handler = new GroupHandler();
-     for ($i=0; $i<count($collections); $i++) {
-       $collection = $group_handler->get_collection($collections[$i]);
-       $collection->delete();
-     }
-     $this->DAO->execute('DELETE FROM ' . APP__DB_TABLE_PREFIX . "user_module WHERE module_id = {$this->module_id}");
-     $this->DAO->execute('DELETE FROM ' . APP__DB_TABLE_PREFIX . "module WHERE module_id = {$this->module_id}");
+        $stmt = $dbConn->prepare('UPDATE ' . APP__DB_TABLE_PREFIX . 'module SET module_code = ?, module_title = ? WHERE module_id = ?');
 
-     $this->module_code = null;
-     $this->module_title = null;
-     $this->module_id = null;
+        $stmt->bindValue(1, $this->module_code);
+        $stmt->bindValue(2, $this->module_title);
+        $stmt->bindValue(3, $this->module_id, ParameterType::INTEGER);
 
-   }
+        $stmt->execute();
 
-/*
-* ================================================================================
-* PRIVATE
-* ================================================================================
-*/
+        return true;
+    }
 
-}// /class: Module
+    /**
+     * Function to set the database connection to be used
+     * @param DAO connection $DB
+     */
+    public function set_dao_object(DAO $DB)
+    {
+        $this->DAO = $DB;
+    }
+
+    /**
+     * Function to add new module details
+     */
+    public function add_module()
+    {
+        $addModuleQuery =
+        'INSERT INTO ' . APP__DB_TABLE_PREFIX . 'module ' .
+        '(module_code, module_title) ' .
+        'VALUES (?, ?)';
+
+        $stmt = $this->DAO->getConnection()->prepare($addModuleQuery);
 
-?>
+        $stmt->bindValue(1, $this->module_code);
+        $stmt->bindValue(2, $this->module_title);
+
+        $stmt->execute();
+
+        return $this->DAO->getConnection()->lastInsertId('module_id');
+    }
+
+    /**
+     * Function to delete a module
+     */
+    public function delete()
+    {
+        $deleteModuleQuery =
+           'SELECT collection_id ' .
+           'FROM ' . APP__DB_TABLE_PREFIX . 'collection ' .
+           'WHERE module_id = ?';
+
+        $collections = $this->DAO->getConnection()->fetchFirstColumn($deleteModuleQuery, [$this->module_id], [ParameterType::INTEGER]);
+
+        $group_handler = new GroupHandler();
+
+        for ($i=0; $i<count($collections); $i++) {
+            $collection = $group_handler->get_collection($collections[$i]);
+            $collection->delete();
+        }
+
+        $dbConn = $this->DAO->getConnection();
+
+        $dbConn->executeQuery(
+            'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user_module WHERE module_id = ?',
+            [$this->module_id],
+            [ParameterType::INTEGER]
+        );
+
+        $dbConn->executeQuery(
+            'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'module WHERE module_id = ?',
+            [$this->module_id],
+            [ParameterType::INTEGER]
+        );
+
+        $this->module_code = null;
+        $this->module_title = null;
+        $this->module_id = null;
+    }
+
+    /*
+    * ================================================================================
+    * PRIVATE
+    * ================================================================================
+    */
+}// /class: Module
diff --git a/src/includes/classes/NewAlgorithm.php b/src/includes/classes/NewAlgorithm.php
index e5d23b5..668d169 100644
--- a/src/includes/classes/NewAlgorithm.php
+++ b/src/includes/classes/NewAlgorithm.php
@@ -16,63 +16,61 @@
 
 namespace WebPA\includes\classes;
 
-class NewAlgorithm extends WebPAAlgorithm {
-
-  private $group_member_awarded;
+class NewAlgorithm extends WebPAAlgorithm
+{
+    private $group_member_awarded;
     
-  function __construct() {
-    WebPAAlgorithm::_init();
-  }// /->NewAlgorithm()
-
-/*
-* ================================================================================
-* Public Methods
-* ================================================================================
-*/
+    public function __construct()
+    {
+        WebPAAlgorithm::_init();
+    }
 
-  /*
-  * Calculate the WebPA and group scores for each member
-  */
-  function calculate() {
+    // /->NewAlgorithm()
 
     /*
-    * Perform a few different tasks and initialisations by looping through all the responses
+    * ================================================================================
+    * Public Methods
+    * ================================================================================
     */
-    foreach ($this->_responses as $i => $response) {
-      // Process the responses and re-factor the array into a more usable form
-      $this->_group_member_responses["{$response['group_id']}"]["{$response['user_id']}"]["{$response['question_id']}"]["{$response['marked_user_id']}"] = $response['score'];
 
-      // Record the fact this group member submitted
-      $this->_group_member_submitted["{$response['group_id']}"]["{$response['user_id']}"] = true;
+    // Calculate the WebPA and group scores for each member
+    public function calculate()
+    {
 
-      // Record the fact this member submitted (separate from group-member)
-      $this->_member_submitted["{$response['user_id']}"] = true;
+    // Perform a few different tasks and initialisations by looping through all the responses
+        foreach ($this->_responses as $i => $response) {
+            // Process the responses and re-factor the array into a more usable form
+            $this->_group_member_responses["{$response['group_id']}"]["{$response['user_id']}"]["{$response['question_id']}"]["{$response['marked_user_id']}"] = $response['score'];
 
-    }
+            // Record the fact this group member submitted
+            $this->_group_member_submitted["{$response['group_id']}"]["{$response['user_id']}"] = true;
 
-    /*
-    * Begin the actual scoring algorithm.
-    * Individual algorithmic steps are numbered
-    */
+            // Record the fact this member submitted (separate from group-member)
+            $this->_member_submitted["{$response['user_id']}"] = true;
+        }
 
-    // Take each group in turn
-    foreach ($this->_groups as $group_id => $group_mark) {
+        /*
+        * Begin the actual scoring algorithm.
+        * Individual algorithmic steps are numbered
+        */
 
-      $group_had_submissions = false;
+        // Take each group in turn
+        foreach ($this->_groups as $group_id => $group_mark) {
+            $group_had_submissions = false;
 
-      $this->_group_member_frac_scores_awarded["$group_id"] = array ();
-      $this->_group_member_total_received[$group_id] =  array();
+            $this->_group_member_frac_scores_awarded["$group_id"] = [];
+            $this->_group_member_total_received[$group_id] =  [];
 
-      // Take each member in turn
-      foreach ($this->_group_members["$group_id"] as $i => $member_id) {
+            // Take each member in turn
+            foreach ($this->_group_members["$group_id"] as $i => $member_id) {
 
         // Initialise each member's totals and scores
-        $this->_group_member_total_received["$group_id"]["$member_id"] = 0;
-        $this->_group_member_webpa_scores["$group_id"]["$member_id"] = 0;
-        $this->_group_member_grades["$group_id"]["$member_id"] = 0;
+                $this->_group_member_total_received["$group_id"]["$member_id"] = 0;
+                $this->_group_member_webpa_scores["$group_id"]["$member_id"] = 0;
+                $this->_group_member_grades["$group_id"]["$member_id"] = 0;
 
-        // If the member submitted a response, then we need to normalise the scores awarded
-        if (array_key_exists($member_id, $this->_member_submitted)) {
+                // If the member submitted a response, then we need to normalise the scores awarded
+                if (array_key_exists($member_id, $this->_member_submitted)) {
 
           /*
            * We need to signal that at least one member submitted marks
@@ -80,142 +78,135 @@ function calculate() {
            * and 0-marks because no one submitted anything - in which case every member
            * should automatically get a WebPA score of 1.
            */
-          $group_had_submissions = true;
+                    $group_had_submissions = true;
 
-          /*
-           * (1)
-           * Get the total number of marks each member awarded
-           * This will form the basis for our normalisation in step (2)
-           */
+                    /*
+                     * (1)
+                     * Get the total number of marks each member awarded
+                     * This will form the basis for our normalisation in step (2)
+                     */
 
-          $this->_group_member_total_awarded["$group_id"]["$member_id"] = 0;  // Initialise member-total
-          $this->group_member_awarded["$group_id"]["$member_id"] = array();
+                    $this->_group_member_total_awarded["$group_id"]["$member_id"] = 0;  // Initialise member-total
+                    $this->group_member_awarded["$group_id"]["$member_id"] = [];
 
-          if (!array_key_exists($group_id, $this->_group_member_responses)) {
+                    if (!array_key_exists($group_id, $this->_group_member_responses)) {
 
             // Do nothing, there's nothing to process
-
-          } else {
-
-            foreach ($this->_questions as $i => $question_id) {
-
-              foreach($this->_group_member_responses["$group_id"]["$member_id"]["$question_id"] as $marked_user_id => $score) {
-                // Add the given score to the total
-                $this->_group_member_total_awarded["$group_id"]["$member_id"] += $score;
-                if (!array_key_exists($marked_user_id, $this->group_member_awarded["$group_id"]["$member_id"])) {
-                  $this->group_member_awarded["$group_id"]["$member_id"]["$marked_user_id"] = null;
-                } else {
-                  $this->group_member_awarded["$group_id"]["$member_id"]["$marked_user_id"] += $score;
+                    } else {
+                        foreach ($this->_questions as $i => $question_id) {
+                            foreach ($this->_group_member_responses["$group_id"]["$member_id"]["$question_id"] as $marked_user_id => $score) {
+                                // Add the given score to the total
+                                $this->_group_member_total_awarded["$group_id"]["$member_id"] += $score;
+                                if (!array_key_exists($marked_user_id, $this->group_member_awarded["$group_id"]["$member_id"])) {
+                                    $this->group_member_awarded["$group_id"]["$member_id"]["$marked_user_id"] = null;
+                                } else {
+                                    $this->group_member_awarded["$group_id"]["$member_id"]["$marked_user_id"] += $score;
+                                }
+                            }// /foreach(member-response)
+                        }// /foreach(question)
+                    }
+
+                    /*
+                     * (2)
+                     * Get the normalised fraction awarded by each member to each member
+                     * If member-A gave member-B 4 marks, then the fraction awarded = 4 / total-marks-member-A-awarded
+                     */
+
+                    // If the member gave more than 0 marks in total, calculate the fraction awarded
+                    if ($this->_group_member_total_awarded["$group_id"]["$member_id"]>0) {
+                        foreach ($this->_questions as $i => $question_id) {
+                            foreach ($this->_group_member_responses["$group_id"]["$member_id"]["$question_id"] as $marked_user_id => $score) {
+                                $this->_group_member_frac_scores_awarded["$group_id"]["$member_id"]["$question_id"]["$marked_user_id"] = $score / $this->_group_member_total_awarded["$group_id"]["$member_id"];
+                            }// /foreach(member-response)
+                        }// /foreach(question)
+                    }// /if (member-total-award==0)
+                }// /if(member-submitted)
+            }// /foreach(member)
+
+            // All the scores are now normalised. Time to calculate the actual WebPA scores
+
+            /*
+             * (3)
+             * Get the multiplication factor we need to calculate the WebPA scores
+             * factor = num-members-total / num-members-submitted
+             */
+
+            $num_members = ((is_array($this->_group_members)) && (array_key_exists($group_id, $this->_group_members))) ? count($this->_group_members["$group_id"]) : 0 ;
+            $num_submitted = ((is_array($this->_group_member_submitted)) && (array_key_exists($group_id, $this->_group_member_submitted))) ? count($this->_group_member_submitted["$group_id"]) : 0 ;
+
+            $multi_factor = ($num_submitted>0) ? ($num_members / $num_submitted) : 1 ;
+
+            $pa_group_mark = ($this->_marking_params['weighting']/100) * $group_mark;
+            $nonpa_group_mark = ((100-$this->_marking_params['weighting']) /100) * $group_mark;
+
+            /*
+             * (4)
+             * Get the total fractional score awarded to each member for each question
+             */
+
+            foreach ($this->_group_member_frac_scores_awarded["$group_id"] as $member_id => $q_array) {
+                foreach ($q_array as $question_id => $marked_array) {
+                    foreach ($marked_array as $marked_user_id => $frac_score) {
+                        $this->_group_member_total_received["$group_id"]["$marked_user_id"] += $frac_score;
+                    }
                 }
-              }// /foreach(member-response)
-
-            }// /foreach(question)
-
-          }
-
-          /*
-           * (2)
-           * Get the normalised fraction awarded by each member to each member
-           * If member-A gave member-B 4 marks, then the fraction awarded = 4 / total-marks-member-A-awarded
-           */
-
-          // If the member gave more than 0 marks in total, calculate the fraction awarded
-          if ($this->_group_member_total_awarded["$group_id"]["$member_id"]>0) {
-
-            foreach ($this->_questions as $i => $question_id) {
+            }
 
-              foreach ($this->_group_member_responses["$group_id"]["$member_id"]["$question_id"] as $marked_user_id => $score) {
-                $this->_group_member_frac_scores_awarded["$group_id"]["$member_id"]["$question_id"]["$marked_user_id"] = $score / $this->_group_member_total_awarded["$group_id"]["$member_id"];
-              }// /foreach(member-response)
+            if (array_key_exists($group_id, $this->_group_member_total_received)) {
+                foreach ($this->_group_member_total_received["$group_id"] as $member_id => $total_frac_score) {
+                    /*
+                     * (5)
+                     * Get the WebPA score = total fractional score awarded to a member * multiplication-factor
+                     */
+                    $this->_group_member_webpa_scores["$group_id"]["$member_id"] = $total_frac_score * $multi_factor;
 
-            }// /foreach(question)
+                    /*
+                     * (6)
+                     * Get the member's intermediate grade = WebPA score * weighted-group-mark     (does not include penalties)
+                     */
+                    if ($group_had_submissions) {
+                        $intermediate_grade = (($total_frac_score * $multi_factor * $pa_group_mark) + $nonpa_group_mark);
+                    } else {
+                        $intermediate_grade = $pa_group_mark + $nonpa_group_mark;
+                    }
 
-          }// /if (member-total-award==0)
+                    if ($intermediate_grade<0) {
+                        $intermediate_grade = 0;
+                    } elseif ($intermediate_grade>100) {
+                        $intermediate_grade = 100;
+                    }
 
-        }// /if(member-submitted)
+                    $this->_group_member_intermediate_grades["$group_id"]["$member_id"] = $intermediate_grade;
 
-      }// /foreach(member)
 
-      // All the scores are now normalised. Time to calculate the actual WebPA scores
+                    /* (7)
+                     * Get the member's grade = WebPA score * weighted-group-mark * any penalty
+                     */
 
-      /*
-       * (3)
-       * Get the multiplication factor we need to calculate the WebPA scores
-       * factor = num-members-total / num-members-submitted
-       */
+                    $penalty = (array_key_exists($member_id, $this->_member_submitted)) ? 1 : 1-($this->_marking_params['penalty']/100) ;
 
-      $num_members = ( (is_array($this->_group_members)) && (array_key_exists($group_id, $this->_group_members)) ) ? count($this->_group_members["$group_id"]) : 0 ;
-      $num_submitted = ( (is_array($this->_group_member_submitted)) && (array_key_exists($group_id, $this->_group_member_submitted)) ) ? count($this->_group_member_submitted["$group_id"]) : 0 ;
+                    // Don't need this bit now:
+                    // $final_grade = (($total_frac_score * $multi_factor * $pa_group_mark) + $nonpa_group_mark) * $penalty;
 
-      $multi_factor = ($num_submitted>0) ? ($num_members / $num_submitted) : 1 ;
+                    $final_grade = $intermediate_grade * $penalty;
 
-      $pa_group_mark = ($this->_marking_params['weighting']/100) * $group_mark;
-      $nonpa_group_mark = ( (100-$this->_marking_params['weighting']) /100 ) * $group_mark;
+                    if ($final_grade<0) {
+                        $final_grade = 0;
+                    } elseif ($final_grade>100) {
+                        $final_grade = 100;
+                    }
 
-      /*
-       * (4)
-       * Get the total fractional score awarded to each member for each question
-       */
-
-      foreach ($this->_group_member_frac_scores_awarded["$group_id"] as $member_id => $q_array) {
-        foreach ($q_array as $question_id => $marked_array) {
-          foreach ($marked_array as $marked_user_id => $frac_score) {
-            $this->_group_member_total_received["$group_id"]["$marked_user_id"] += $frac_score;
-          }
-        }
-      }
-
-      if (array_key_exists($group_id, $this->_group_member_total_received)) {
-        foreach ($this->_group_member_total_received["$group_id"] as $member_id => $total_frac_score) {
-          /*
-           * (5)
-           * Get the WebPA score = total fractional score awarded to a member * multiplication-factor
-           */
-          $this->_group_member_webpa_scores["$group_id"]["$member_id"] = $total_frac_score * $multi_factor;
-
-          /*
-           * (6)
-           * Get the member's intermediate grade = WebPA score * weighted-group-mark     (does not include penalties)
-           */
-          if ($group_had_submissions) {
-            $intermediate_grade = (($total_frac_score * $multi_factor * $pa_group_mark) + $nonpa_group_mark);
-          } else {
-            $intermediate_grade = $pa_group_mark + $nonpa_group_mark;
-          }
-
-          if ($intermediate_grade<0) { $intermediate_grade = 0; }
-          elseif ($intermediate_grade>100) { $intermediate_grade = 100; }
-
-          $this->_group_member_intermediate_grades["$group_id"]["$member_id"] = $intermediate_grade;
-
-
-          /* (7)
-           * Get the member's grade = WebPA score * weighted-group-mark * any penalty
-           */
-
-          $penalty = (array_key_exists($member_id, $this->_member_submitted)) ? 1 : 1-($this->_marking_params['penalty']/100) ;
-
-          // Don't need this bit now:
-          // $final_grade = (($total_frac_score * $multi_factor * $pa_group_mark) + $nonpa_group_mark) * $penalty;
-
-          $final_grade = $intermediate_grade * $penalty;
-
-          if ($final_grade<0) { $final_grade = 0; }
-          elseif ($final_grade>100) { $final_grade = 100; }
-
-          $this->_group_member_grades["$group_id"]["$member_id"] = $final_grade;
-        }
-      }
-    }// /foreach(group)
+                    $this->_group_member_grades["$group_id"]["$member_id"] = $final_grade;
+                }
+            }
+        }// /foreach(group)
+    }
 
-  }// /->calculate()
+    // /->calculate()
 
 /*
 * ================================================================================
 * Private Methods
 * ================================================================================
 */
-
 }// /class: NewAlgorithm
-
-?>
diff --git a/src/includes/classes/ResultHandler.php b/src/includes/classes/ResultHandler.php
index 616637b..2582cea 100644
--- a/src/includes/classes/ResultHandler.php
+++ b/src/includes/classes/ResultHandler.php
@@ -10,25 +10,33 @@
 
 namespace WebPA\includes\classes;
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\functions\Common;
 
 class ResultHandler
 {
     private $_DAO;
+
     private $_assessment;
+
     private $_collection;
+
     private $_collection_id;
+
+    private $dbConn;
+
     private $moduleId;
 
     /*
     * CONSTRUCTOR for the result handler
     * @param mixed $DAO
     */
-    function __construct(DAO $DAO)
+    public function __construct(DAO $DAO)
     {
         $this->moduleId = Common::fetch_SESSION('_module_id', null);
 
         $this->_DAO = $DAO;
+        $this->dbConn = $this->_DAO->getConnection();
     }
 
     /*
@@ -47,7 +55,7 @@ function __construct(DAO $DAO)
      * Set Assessment object
      * @param object $assessment assessment object to use
      */
-    function set_assessment(&$assessment)
+    public function set_assessment(&$assessment)
     {
         $this->_assessment =& $assessment;
 
@@ -62,75 +70,89 @@ function set_assessment(&$assessment)
      * Return the Assessment object being used
      * @return object assessment object used
      */
-    function & get_assessment()
+    public function & get_assessment()
     {
         return $this->_assessment;
-    }// /->get_assessment()
+    }
+
+    // /->get_assessment()
 
     /**
      * Fetch all responses for this assessment
      * @return array array of the responses for the given assessment
      */
-    function get_responses()
+    public function get_responses()
     {
-        return $this->_DAO->fetch("SELECT um.group_id, um.user_id, um.marked_user_id, um.question_id, um.score
-                      FROM " . APP__DB_TABLE_PREFIX . "user_mark um
-                        INNER JOIN " . APP__DB_TABLE_PREFIX . "assessment a ON um.assessment_id = a.assessment_id
-                      WHERE um.assessment_id = '{$this->_assessment->id}'
-                        AND a.collection_id = '{$this->_collection_id}'
-                      ORDER BY um.group_id, um.user_id, um.marked_user_id, um.question_id");
-    }// /->get_responses()
+        $query =
+            'SELECT um.group_id, um.user_id, um.marked_user_id, um.question_id, um.score ' .
+            'FROM ' . APP__DB_TABLE_PREFIX . 'user_mark um ' .
+            'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
+            'ON um.assessment_id = a.assessment_id ' .
+            'WHERE um.assessment_id = ? ' .
+            'AND a.collection_id = ? ' .
+            'ORDER BY um.group_id, um.user_id, um.marked_user_id, um.question_id';
+
+        return $this->dbConn->fetchAllAssociative($query, [$this->_assessment->id, $this->_collection_id], [ParameterType::STRING, ParameterType::STRING]);
+    }
 
     /**
      * Function to get the marks fot the assessment
      * @return integer number of users
      */
-    function get_responses_count_for_assessment()
+    public function get_responses_count_for_assessment()
     {
-        return $this->_DAO->fetch_value("SELECT COUNT(DISTINCT um.user_id)
-                    FROM " . APP__DB_TABLE_PREFIX . "user_mark um
-                      INNER JOIN " . APP__DB_TABLE_PREFIX . "assessment a ON um.assessment_id = a.assessment_id
-                    WHERE um.assessment_id = '{$this->_assessment->id}'
-                      AND a.collection_id = '{$this->_collection->id}'");
+        $responseCountsQuery =
+            'SELECT COUNT(DISTINCT um.user_id) ' .
+            'FROM ' . APP__DB_TABLE_PREFIX . 'user_mark um ' .
+            'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
+            'ON um.assessment_id = a.assessment_id ' .
+            'WHERE um.assessment_id = ? ' .
+            'AND a.collection_id = ?';
 
-    }// /->get_responses_count_for_assessment()
+        return $this->dbConn->fetchOne($responseCountsQuery, [$this->_assessment->id, $this->_collection->id], [ParameterType::STRING, ParameterType::STRING]);
+    }
 
     /**
      * Function to get the number of students who have responded to the assessment
      * @return array all the user ids of those who has responded
      */
-    function get_responded_users()
+    public function get_responded_users()
     {
-        return $this->_DAO->fetch_col("
-      SELECT DISTINCT um.user_id
-      FROM " . APP__DB_TABLE_PREFIX . "user_mark um
-        INNER JOIN " . APP__DB_TABLE_PREFIX . "assessment a ON um.assessment_id = a.assessment_id
-      WHERE um.assessment_id = '{$this->_assessment->id}'
-            AND a.collection_id = '{$this->_collection->id}'
-      ORDER BY um.user_id
-    ");
-    }// /->get_responded_users()
+        $usersThatRespondedQuery =
+            'SELECT DISTINCT um.user_id ' .
+            'FROM ' . APP__DB_TABLE_PREFIX . 'user_mark um ' .
+            'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
+            'ON um.assessment_id = a.assessment_id ' .
+            'WHERE um.assessment_id = ? ' .
+            'AND a.collection_id = ? ' .
+            'ORDER BY um.user_id';
+
+        return $this->dbConn->fetchFirstColumn($usersThatRespondedQuery, [$this->_assessment->id, $this->_collection->id], [ParameterType::STRING, ParameterType::STRING]);
+    }
 
     /**
      * Fetch a count of the responses for the given group
      * @param integer $group_id
      * @return integer count of the responses
      */
-    function get_responses_count($group_id)
+    public function get_responses_count($group_id)
     {
         if ($this->_collection->group_id_exists($group_id)) {
-            return $this->_DAO->fetch_value("
-        SELECT COUNT(DISTINCT user_id)
-        FROM " . APP__DB_TABLE_PREFIX . "user_mark um
-          INNER JOIN " . APP__DB_TABLE_PREFIX . "assessment a ON um.assessment_id = a.assessment_id
-        WHERE um.assessment_id = '{$this->_assessment->id}'
-          AND a.collection_id = '{$this->_collection->id}'
-          AND um.group_id = '$group_id'
-      ");
-        } else {
-            return null;
+            $responseCountQuery =
+                'SELECT COUNT(DISTINCT user_id) ' .
+                'FROM ' . APP__DB_TABLE_PREFIX . 'user_mark um ' .
+                'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
+                'ON um.assessment_id = a.assessment_id ' .
+                'WHERE um.assessment_id = ? ' .
+                'AND a.collection_id = ? ' .
+                'AND um.group_id = ?';
+
+            return $this->dbConn->fetchOne($responseCountQuery, [$this->_assessment->id, $this->_collection->id, $group_id], [ParameterType::STRING, ParameterType::STRING, ParameterType::STRING]);
         }
-    }// /->get_responses_count()
+        return null;
+    }
+
+    // /->get_responses_count()
 
     /**
      * Fetch a count of the responses for all this user's assessments (that opened this academic year)
@@ -138,24 +160,40 @@ function get_responses_count($group_id)
      * @param date $year
      * @return array
      */
-    function get_responses_count_for_user($user_id, $year = NULL)
+    public function get_responses_count_for_user($user_id, $year = null)
     {
-        $sql = "SELECT a.assessment_id, COUNT(DISTINCT um.user_id)
-      FROM " . APP__DB_TABLE_PREFIX . "assessment a
-        LEFT JOIN " . APP__DB_TABLE_PREFIX . "user_mark um ON a.assessment_id = um.assessment_id
-          AND a.module_id = {$this->moduleId} ";
+        $sql =
+            'SELECT a.assessment_id, COUNT(DISTINCT um.user_id) AS response_count ' .
+            'FROM ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
+            'LEFT JOIN ' . APP__DB_TABLE_PREFIX . 'user_mark um ' .
+            'ON a.assessment_id = um.assessment_id ' .
+            'AND a.module_id = ? ';
+
         if (!empty($year)) {
             $next_year = $year + 1;
-            $month = strval(APP__ACADEMIC_YEAR_START_MONTH);
+
+            $month = (string) APP__ACADEMIC_YEAR_START_MONTH;
+
             if (APP__ACADEMIC_YEAR_START_MONTH < 10) {
                 $month = '0' . $month;
             }
-            $sql .= "AND a.open_date >= '{$year}-{$month}-01 00:00:00'
-          AND a.open_date < '{$next_year}-{$month}-01 00:00:00' ";
+
+            $startDate = "$year-$month-01 00:00:00";
+            $endDate = "$next_year-$month-01 00:00:00";
+
+            $sql .=
+                'AND a.open_date >= ? ' .
+                'AND a.open_date < ? ';
         }
+
         $sql .= 'GROUP BY assessment_id';
-        return $this->_DAO->fetch_assoc($sql);
-    }// /->get_responses_count_for_user()
+
+        if (!empty($year)) {
+            return  $this->dbConn->fetchAllKeyValue($sql, [$this->moduleId, $startDate, $endDate], [ParameterType::INTEGER, ParameterType::STRING, ParameterType::STRING]);
+        }
+
+        return $this->dbConn->fetchAllKeyValue($sql, [$this->moduleId], [ParameterType::INTEGER]);
+    }
 
     /**
      * Fetch a count of the members for all this user's assessments (that opened this academic year)
@@ -163,25 +201,41 @@ function get_responses_count_for_user($user_id, $year = NULL)
      * @param date $year
      * @return array assoc array ( assessment_id => member_count )
      */
-    function get_members_count_for_user($user_id, $year = NULL)
+    public function get_members_count_for_user($user_id, $year = null)
     {
-        $sql = "SELECT a.assessment_id, COUNT(DISTINCT ugm.user_id)
-      FROM " . APP__DB_TABLE_PREFIX . "assessment a
-        LEFT JOIN " . APP__DB_TABLE_PREFIX . "user_group ug ON a.collection_id = ug.collection_id
-        LEFT JOIN " . APP__DB_TABLE_PREFIX . "user_group_member ugm ON ug.group_id = ugm.group_id
-          AND a.module_id = {$this->moduleId} ";
+        $sql =
+            'SELECT a.assessment_id, COUNT(DISTINCT ugm.user_id) AS members_count ' .
+            'FROM ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
+            'LEFT JOIN ' . APP__DB_TABLE_PREFIX . 'user_group ug ' .
+            'ON a.collection_id = ug.collection_id ' .
+            'LEFT JOIN ' . APP__DB_TABLE_PREFIX . 'user_group_member ugm ' .
+            'ON ug.group_id = ugm.group_id ' .
+            'AND a.module_id = ? ';
+
         if (!empty($year)) {
             $next_year = $year + 1;
-            $month = strval(APP__ACADEMIC_YEAR_START_MONTH);
+            $month = (string) APP__ACADEMIC_YEAR_START_MONTH;
+
             if (APP__ACADEMIC_YEAR_START_MONTH < 10) {
                 $month = '0' . $month;
             }
-            $sql .= "AND a.open_date >= '{$year}-{$month}-01 00:00:00'
-          AND a.open_date < '{$next_year}-{$month}-01 00:00:00' ";
+
+            $startDate = "$year-$month-01 00:00:00";
+            $endDate = "$next_year-$month-01 00:00:00";
+
+            $sql .=
+                'AND a.open_date >= ? ' .
+                'AND a.open_date < ? ';
         }
+
         $sql .= 'GROUP BY a.assessment_id';
-        return $this->_DAO->fetch_assoc($sql);
-    }// /->get_members_count_for_user()
+
+        if (!empty($year)) {
+            return $this->dbConn->fetchAllKeyValue($sql, [$this->moduleId, $startDate, $endDate], [ParameterType::INTEGER, ParameterType::STRING, ParameterType::STRING]);
+        }
+
+        return $this->dbConn->fetchAllKeyValue($sql, [$this->moduleId], [ParameterType::INTEGER]);
+    }
 
     /**
      * Has the user submitted marks for the given assessment already
@@ -189,25 +243,27 @@ function get_members_count_for_user($user_id, $year = NULL)
      * @param string $assessment_id assessment to check
      * @return boolean  has the user responded
      */
-    function user_has_responded($user_id, $assessment_id)
+    public function user_has_responded($user_id, $assessment_id)
     {
-        $num_responses = $this->_DAO->fetch_value("
-      SELECT COUNT(DISTINCT um.marked_user_id)
-      FROM " . APP__DB_TABLE_PREFIX . "assessment a
-        LEFT JOIN " . APP__DB_TABLE_PREFIX . "user_mark um ON a.assessment_id = um.assessment_id
-          AND a.assessment_id = '$assessment_id'
-          AND um.user_id = $user_id
-    ");
-        return ($num_responses > 0);
-    }// /->user_has_responded()
+        $numberOfResponsesQuery =
+            'SELECT COUNT(DISTINCT um.marked_user_id) ' .
+            'FROM ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
+            'LEFT JOIN ' . APP__DB_TABLE_PREFIX . 'user_mark um ' .
+            'ON a.assessment_id = um.assessment_id ' .
+            'AND a.assessment_id = ? ' .
+            'AND um.user_id = ?';
+
+        $num_responses = $this->dbConn->fetchOne($numberOfResponsesQuery, [$assessment_id, $user_id], [ParameterType::STRING, ParameterType::INTEGER]);
+
+        return $num_responses > 0;
+    }
 
     /**
      * Function for the assessments taken by a user
      * @param string $user_id
      */
-    function assessments_taken_by_user($user_id)
+    public function assessments_taken_by_user($user_id)
     {
-
     }
 
     /*
@@ -215,7 +271,4 @@ function assessments_taken_by_user($user_id)
     * Private Methods
     * ================================================================================
     */
-
 }// /class: ResultHandler
-
-?>
diff --git a/src/includes/classes/SimpleIterator.php b/src/includes/classes/SimpleIterator.php
index 10e49df..e2d1b33 100644
--- a/src/includes/classes/SimpleIterator.php
+++ b/src/includes/classes/SimpleIterator.php
@@ -13,91 +13,119 @@
 
 namespace WebPA\includes\classes;
 
-class SimpleIterator {
-  // Public Vars
-  public $array = null;
-  public $count = 0;
-
-  // Private Vars
-
-  private $_key = null;
-  private $_value = null;
-
-  /**
-  * CONSTRUCTOR for the simple iterator class
-  * @param array $array
-  */
-  function __construct(&$array = []) {
-    // sub-classes can override the creator, so all the work is done in _initialise()
-    $this->_initialise($array);
-  }// /->SimpleIterator()
-
-/*
-* ================================================================================
-* Public Methods
-* ================================================================================
-*/
+class SimpleIterator
+{
+    // Public Vars
+    public $array;
 
-/**
- * function current
- * @return integer
- */
-  function &current() {
-    return $this->_value;
-  }// /->current()
+    public $count = 0;
 
-/**
- * function next
- */
-  function next() {
-    next($this->array);
-    $this->_key = key($this->array);
-    if ("$this->_key" != '') { $this->_value =& $this->array[$this->_key]; }
-    else { $this->_value = null; }
-  }// /->next()
+    // Private Vars
 
-/**
- * function reset
- */
-  function reset() {
-    reset($this->array);
-    $this->_key = key($this->array);
-    if ("$this->_key" != '') { $this->_value =& $this->array[$this->_key]; }
-    else { $this->_value = null; }
-  }// /->reset()
+    private $_key;
 
-/**
- * function size
- * @return integer
- */
-  function size() {
-    return $this->count;
-  }// /->size()
+    private $_value;
 
-/**
- * function to check validity
- * @return boolean
- */
-  function is_valid() {
-    return ("$this->_key" != '');
-  }// /->is_valid()
-
-/*
-* ================================================================================
-* Private Methods
-* ================================================================================
-*/
-/**
- * Function to initalise
- * @param array $array
- */
-  function _initialise(&$array = []) {
-    $this->array =& $array;
-    $this->count = count($array);
+    /**
+    * CONSTRUCTOR for the simple iterator class
+    * @param array $array
+    */
+    public function __construct(&$array = [])
+    {
+        // sub-classes can override the creator, so all the work is done in _initialise()
+        $this->_initialise($array);
+    }
 
-    $this->reset();
-  }// /->_intialise()
+    // /->SimpleIterator()
 
-}// /class: SimpleIterator
+    /*
+    * ================================================================================
+    * Public Methods
+    * ================================================================================
+    */
+
+    /**
+     * function current
+     * @return integer
+     */
+    public function &current()
+    {
+        return $this->_value;
+    }
 
-?>
+    // /->current()
+
+    /**
+     * function next
+     */
+    public function next()
+    {
+        next($this->array);
+        $this->_key = key($this->array);
+        if ("$this->_key" != '') {
+            $this->_value =& $this->array[$this->_key];
+        } else {
+            $this->_value = null;
+        }
+    }
+
+    // /->next()
+
+    /**
+     * function reset
+     */
+    public function reset()
+    {
+        reset($this->array);
+        $this->_key = key($this->array);
+        if ("$this->_key" != '') {
+            $this->_value =& $this->array[$this->_key];
+        } else {
+            $this->_value = null;
+        }
+    }
+
+    // /->reset()
+
+    /**
+     * function size
+     * @return integer
+     */
+    public function size()
+    {
+        return $this->count;
+    }
+
+    // /->size()
+
+    /**
+     * function to check validity
+     * @return boolean
+     */
+    public function is_valid()
+    {
+        return "$this->_key" != '';
+    }
+
+    // /->is_valid()
+
+    /*
+    * ================================================================================
+    * Private Methods
+    * ================================================================================
+    */
+
+    /**
+     * Function to initalise
+     * @param array $array
+     */
+    public function _initialise(&$array = [])
+    {
+        $this->array =& $array;
+        $this->count = count($array);
+
+        $this->reset();
+    }
+
+    // /->_intialise()
+}// /class: SimpleIterator
diff --git a/src/includes/classes/SimpleObjectIterator.php b/src/includes/classes/SimpleObjectIterator.php
index 76c8368..55443aa 100644
--- a/src/includes/classes/SimpleObjectIterator.php
+++ b/src/includes/classes/SimpleObjectIterator.php
@@ -14,41 +14,48 @@
 
 namespace WebPA\includes\classes;
 
-class SimpleObjectIterator {
-  // Public Vars
-  public $array;
-  public $class_name;
-  public $class_constructor_args;
-  public $count;
-
-  // Private Vars
-  private $_key;
-  private $_value;
-
-  /**
-  * CONSTRUCTOR for the simple object iterator
-  * @param array $array
-  * @param string $class_name
-  * @param string $constructor_args
-  */
-  function __construct(&$array, $class_name = '', $constructor_args = '') {
-    $this->_initialise($array);
-    $this->class_name = $class_name;
-    $this->class_constructor_args = $constructor_args;
-  }
-
-/*
-* --------------------------------------------------------------------------------
-* Public Methods
-* --------------------------------------------------------------------------------
-*/
-
-  /**
-  * Get object at current pointer position
-  * @return integer
-  */
-  function &current() {
-    switch ($this->class_name) {
+class SimpleObjectIterator
+{
+    // Public Vars
+    public $array;
+
+    public $class_name;
+
+    public $class_constructor_args;
+
+    public $count;
+
+    // Private Vars
+    private $_key;
+
+    private $_value;
+
+    /**
+    * CONSTRUCTOR for the simple object iterator
+    * @param array $array
+    * @param string $class_name
+    * @param string $constructor_args
+    */
+    public function __construct(&$array, $class_name = '', $constructor_args = '')
+    {
+        $this->_initialise($array);
+        $this->class_name = $class_name;
+        $this->class_constructor_args = $constructor_args;
+    }
+
+    /*
+    * --------------------------------------------------------------------------------
+    * Public Methods
+    * --------------------------------------------------------------------------------
+    */
+
+    /**
+    * Get object at current pointer position
+    * @return integer
+    */
+    public function &current()
+    {
+        switch ($this->class_name) {
       case 'GroupCollection':
         $temp = new GroupCollection($this->class_constructor_args);
         break;
@@ -59,67 +66,82 @@ function &current() {
         $temp = null;
     }
 
-    $temp->load_from_row($this->_value);
-
-    return $temp;
-  }// /->current()
-
-  /**
-  * Move pointer to the next object in the list
-  */
-  function next() {
-    next($this->array);
-    $this->_key = key($this->array);
-    $this->_value = ("$this->_key" != '') ? $this->array[$this->_key] : null ;
-  }// /->next()
-
-  /**
-  * Reset pointer to the start of the list
-  */
-  function reset() {
-    reset($this->array);
-    $this->_key = key($this->array);
-    $this->_value = ("$this->_key" != '') ? $this->array[$this->_key] : null ;
-  }// /->reset()
-
-  /**
-  * Get the number of objects in the list
-  *
-  * @return integer size of the object list
-  */
-  function size() {
-    return $this->count;
-  }// /->size()
-
-  /*
-  * Is the current pointer position valid?
-  * @return boolean
-  */
-  function is_valid() {
-    return ("$this->_key" != '');
-  }// /->is_valid()
-
-/*
-* --------------------------------------------------------------------------------
-* Private Methods
-* --------------------------------------------------------------------------------
-*/
-
-  /**
-  * Initialise the object iterator
-  * @param array $array
-  */
-  function _initialise(&$array) {
-    $this->array =& $array;
-    $this->count = count($array);
-
-    if ($this->count==0) {
-        $this->array = array();
+        $temp->load_from_row($this->_value);
+
+        return $temp;
+    }
+
+    // /->current()
+
+    /**
+    * Move pointer to the next object in the list
+    */
+    public function next()
+    {
+        next($this->array);
+        $this->_key = key($this->array);
+        $this->_value = ("$this->_key" != '') ? $this->array[$this->_key] : null ;
+    }
+
+    // /->next()
+
+    /**
+    * Reset pointer to the start of the list
+    */
+    public function reset()
+    {
+        reset($this->array);
+        $this->_key = key($this->array);
+        $this->_value = ("$this->_key" != '') ? $this->array[$this->_key] : null ;
     }
 
-    $this->reset();
+    // /->reset()
+
+    /**
+    * Get the number of objects in the list
+    *
+    * @return integer size of the object list
+    */
+    public function size()
+    {
+        return $this->count;
+    }
+
+    // /->size()
+
+    /*
+    * Is the current pointer position valid?
+    * @return boolean
+    */
+    public function is_valid()
+    {
+        return "$this->_key" != '';
+    }
 
-    $this->class_name = '';
-    $this->class_constructor_args = '';
-  }
+    // /->is_valid()
+
+    /*
+    * --------------------------------------------------------------------------------
+    * Private Methods
+    * --------------------------------------------------------------------------------
+    */
+
+    /**
+    * Initialise the object iterator
+    * @param array $array
+    */
+    public function _initialise(&$array)
+    {
+        $this->array =& $array;
+        $this->count = count($array);
+
+        if ($this->count==0) {
+            $this->array = [];
+        }
+
+        $this->reset();
+
+        $this->class_name = '';
+        $this->class_constructor_args = '';
+    }
 }
diff --git a/src/includes/classes/UI.php b/src/includes/classes/UI.php
index 3e7ede8..9dc250f 100644
--- a/src/includes/classes/UI.php
+++ b/src/includes/classes/UI.php
@@ -10,28 +10,36 @@
 
 namespace WebPA\includes\classes;
 
-include_once __DIR__ . '/../inc_global.php';
-
 class UI
 {
     public $page_title = '';
+
     public $menu_selected = '';
-    public $breadcrumbs = null;
+
+    public $breadcrumbs;
+
     public $help_link = '';
 
     private $user;
+
     private $_menu;
+
     private $_page_bar_buttons;
+
     private $cis;
+
     private $installedMods;
+
     private $sourceId;
+
     private $branding;
+
     private $module;
 
     /**
      * CONSTRUCTOR for the UI
      */
-    function __construct($installedMods, $sourceId, $branding, $cis, $module, $user)
+    public function __construct($installedMods, $sourceId, $branding, $cis, $module, $user)
     {
         $this->cis = $cis;
         $this->installedMods = $installedMods;
@@ -44,26 +52,24 @@ function __construct($installedMods, $sourceId, $branding, $cis, $module, $user)
 
         // Initialise the menu - sets either staff or student menu items
         if ($this->user) {
-
             if ($this->user->is_staff()) {
                 // Staff menu
-                $this->set_menu('Tutors', array('home' => APP__WWW . '/tutors/index.php',
+                $this->set_menu('Tutors', ['home' => APP__WWW . '/tutors/index.php',
                     'my forms' => APP__WWW . '/tutors/forms/',
                     'my groups' => APP__WWW . '/tutors/groups/',
-                    'my assessments' => APP__WWW . '/tutors/assessments/'));// /$this->set_menu()
-
-            } else if ($this->user->is_student()) {
+                    'my assessments' => APP__WWW . '/tutors/assessments/', ]);// /$this->set_menu()
+            } elseif ($this->user->is_student()) {
                 // Student menu
-                $this->set_menu('Students', array('home' => APP__WWW . '/students/index.php',
+                $this->set_menu('Students', ['home' => APP__WWW . '/students/index.php',
                     'my groups' => APP__WWW . '/students/groups/',
-                    'my assessments' => APP__WWW . '/students/assessments/'));// /$this->set_menu()
+                    'my assessments' => APP__WWW . '/students/assessments/', ]);// /$this->set_menu()
             }
 
             //Admin menu
             if ($this->user->is_staff()) {
-                $menu = array('admin home' => APP__WWW . '/admin/index.php',
+                $menu = ['admin home' => APP__WWW . '/admin/index.php',
                     'upload data' => APP__WWW . '/admin/load/index.php',
-                    'view data' => APP__WWW . '/admin/review/index.php');
+                    'view data' => APP__WWW . '/admin/review/index.php', ];
                 if ($this->user->is_admin()) {
                     $menu['metrics'] = APP__WWW . '/admin/metrics/index.php';
                 }
@@ -75,23 +81,23 @@ function __construct($installedMods, $sourceId, $branding, $cis, $module, $user)
                 $mod = strtolower($mod);
                 $menu_file = DOC__ROOT . "mod/$mod/menu.php";
                 if (file_exists($menu_file)) {
-                    require_once($menu_file);
+                    require_once $menu_file;
                 }
             }
-
         }
 
-        $this->set_menu('Support', array('help' => $helper_link, //this is a link set in each page / area to link to the approriate help
-            'contact' => APP__WWW . '/contact/'));// /$this->set_menu();
+        $this->set_menu('Support', ['help' => $helper_link, //this is a link set in each page / area to link to the approriate help
+            'contact' => APP__WWW . '/contact/', ]);// /$this->set_menu();
 
         if ($this->user) {
             if ($user->is_admin()) {
-                $modules = $this->cis->get_user_modules(NULL, NULL, 'name');
+                $modules = $this->cis->get_user_modules(null, null, 'name');
             } else {
-                $modules = $this->cis->get_user_modules($user->id, NULL, 'name');
+                $modules = $this->cis->get_user_modules($user->id, null, 'name');
             }
+
             if ((($this->sourceId == '') || $this->user->is_admin()) && (count($modules) > 1)) {
-                $this->set_menu('  ', array('change module' => APP__WWW . '/module.php'));
+                $this->set_menu('  ', ['change module' => APP__WWW . '/module.php']);
             }
         }
 
@@ -103,8 +109,9 @@ function __construct($installedMods, $sourceId, $branding, $cis, $module, $user)
             $menu['logout'] = APP__WWW . '/logout.php';
         }
         $this->set_menu(' ', $menu);// /$this->set_menu();
+    }
 
-    }// /->UI()
+    // /->UI()
 
     // --------------------------------------------------------------------------------
     // Public Methods
@@ -115,7 +122,7 @@ function __construct($installedMods, $sourceId, $branding, $cis, $module, $user)
      * @param string $expire_date
      * @param string $modified_date
      */
-    function headers_expire($expire_date = null, $modified_date = null)
+    public function headers_expire($expire_date = null, $modified_date = null)
     {
         // If no expiry date, expire at 00:00:01 today
         if (!$expire_date) {
@@ -131,40 +138,40 @@ function headers_expire($expire_date = null, $modified_date = null)
         header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $modified_date) . ' GMT');
         header('Cache-Control: no-store, no-cache, must-revalidate');   // HTTP/1.1
         header('Cache-Control: post-check=0, pre-check=0', false);    // HTTP/1.1
-        header("Cache-control: private", false);
+        header('Cache-control: private', false);
         header('Pragma: no-cache');   // HTTP/1.0
-    } // /-headers_expire()
+    }
 
+    // /-headers_expire()
 
     /**
      * Function to generate the header
      */
-    function head()
+    public function head()
     {
         /*
         Commented out until the day IE can show a full XHTML page without entering quirks mode
         echo('<?xml version="1.0" encoding="UTF-8"?>'."\n");
-        */
-        ?>
+        */ ?>
         <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
         <html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
         <head>
         <meta http-equiv="content-language" content="EN"/>
         <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
-        <title><?php echo(APP__NAME) ?></title>
-        <link href="<?php echo(APP__WWW) ?>/css/webpa.css" media="screen" rel="stylesheet" type="text/css"/>
-        <link href="<?php echo(APP__WWW) ?>/css/webpa_print.css" media="print" rel="stylesheet" type="text/css"/>
+        <title><?php echo APP__NAME ?></title>
+        <link href="<?php echo APP__WWW ?>/css/webpa.css" media="screen" rel="stylesheet" type="text/css"/>
+        <link href="<?php echo APP__WWW ?>/css/webpa_print.css" media="print" rel="stylesheet" type="text/css"/>
         <style type="text/css">
             <?php
               if (!isset($_SESSION['_no_header'])) {
-            ?>
+                  ?>
             #app_bar {
-                height: <?php echo $this->branding['logo.margin'];?>px;
+                height: <?php echo $this->branding['logo.margin']; ?>px;
             }
 
             #app_bar #inst_logo {
-                width: <?php echo $this->branding['logo.width'];?>px;
+                width: <?php echo $this->branding['logo.width']; ?>px;
             }
 
             #main {
@@ -173,7 +180,7 @@ function head()
 
             <?php
               } else {
-            ?>
+                  ?>
             #side_bar {
                 padding-top: 20px;
                 top: 20px;
@@ -188,8 +195,7 @@ function head()
             }
 
             <?php
-              }
-            ?>
+              } ?>
         </style>
         <?php
         if (isset($this->branding['css']) && !empty($this->branding['css'])) {
@@ -197,24 +203,25 @@ function head()
             <link href="<?php echo $this->branding['css']; ?>" rel="stylesheet" type="text/css"/>
             <?php
         }
-    } // /->head()
+    }
 
+    // /->head()
 
     /**
      * function to close the body area of the page
      * @param string $extra_attributes
      */
-    function body($extra_attributes = '')
+    public function body($extra_attributes = '')
     {
-        echo("\n</head>\n<body $extra_attributes>\n\n");
-
-    } // /->body()
+        echo "\n</head>\n<body $extra_attributes>\n\n";
+    }
 
+    // /->body()
 
     /**
      * render page header
      */
-    function header()
+    public function header()
     {
         ?>
         <div id="header">
@@ -233,21 +240,20 @@ function header()
                             if (isset($this->module)) {
                                 echo "<td>{$this->module['module_title']} [{$this->module['module_code']}]</td>";
                             } else {
-                                echo('<td>&nbsp;</td>');
-                            }
-                            echo '<td align="right">';
-                            if (isset($this->branding['logo']) && !empty($this->branding['logo'])) {
-                                echo '<div id="inst_logo"><img src="' . $this->branding['logo'] . '"';
-                                if (isset($this->branding['name']) && !empty($this->branding['name'])) {
-                                    echo ' alt="' . htmlentities($this->branding['name']) . '"';
-                                    echo ' title="' . htmlentities($this->branding['name']) . '"';
-                                }
-                                echo ' /></div>';
-                            } else {
-                                echo '&nbsp;';
+                                echo '<td>&nbsp;</td>';
                             }
-                            echo '</td>';
-                            ?>
+                echo '<td align="right">';
+                if (isset($this->branding['logo']) && !empty($this->branding['logo'])) {
+                    echo '<div id="inst_logo"><img src="' . $this->branding['logo'] . '"';
+                    if (isset($this->branding['name']) && !empty($this->branding['name'])) {
+                        echo ' alt="' . htmlentities($this->branding['name']) . '"';
+                        echo ' title="' . htmlentities($this->branding['name']) . '"';
+                    }
+                    echo ' /></div>';
+                } else {
+                    echo '&nbsp;';
+                }
+                echo '</td>'; ?>
 
                         </tr>
                     </table>
@@ -255,15 +261,13 @@ function header()
                 <div id="module_bar">
                     <?php
                     if ($this->user) {
-                        echo("<td>User: {$this->user->forename} {$this->user->lastname}</td>");
+                        echo "<td>User: {$this->user->forename} {$this->user->lastname}</td>";
                     } else {
-                        echo('<td>&nbsp;</td>');
-                    }
-                    ?>
+                        echo '<td>&nbsp;</td>';
+                    } ?>
                 </div>
                 <?php
-            }
-            ?>
+            } ?>
             <div id="breadcrumb_bar">
                 You are in:
                 <?php
@@ -272,20 +276,21 @@ function header()
                     foreach ($this->breadcrumbs as $k => $v) {
                         --$num_crumbs;
                         if (!is_null($v)) {
-                            echo("<a class=\"breadcrumb\" href=\"$v\">$k</a>");
+                            echo "<a class=\"breadcrumb\" href=\"$v\">$k</a>";
                             if ($num_crumbs > 0) {
-                                echo(' &gt; ');
+                                echo ' &gt; ';
                             }
                         } else {
-                            echo($k);
+                            echo $k;
                         }
                     }
-                }
-                ?>
+                } ?>
             </div>
         </div>
         <?php
-    }// /->header()
+    }
+
+    // /->header()
 
     /**
      * Set the given section name to the given assoc-array of links
@@ -293,24 +298,23 @@ function header()
      * @param string $section_name
      * @param array $section_array
      */
-    function set_menu($section_name, $section_array)
+    public function set_menu($section_name, $section_array)
     {
         $this->_menu[$section_name] = $section_array;
     }
 
-    function get_menu($section_name)
+    public function get_menu($section_name)
     {
         if (isset($this->_menu[$section_name])) {
             return $this->_menu[$section_name];
-        } else {
-            return array();
         }
+        return [];
     }
 
     /**
      * Draw the menu
      */
-    function menu()
+    public function menu()
     {
         // If there's a menu, draw it
         if ($this->_menu) {
@@ -333,9 +337,11 @@ function menu()
             }// /for
 
             $menu_html .= '</div>';
-            echo($menu_html);
+            echo $menu_html;
         }
-    }// /->menu()
+    }
+
+    // /->menu()
 
     /**
      * Set a page bar button
@@ -344,16 +350,17 @@ function menu()
      * @param string $link
      * @param string $side
      */
-    function set_page_bar_button($text, $img, $link, $side = 'left')
+    public function set_page_bar_button($text, $img, $link, $side = 'left')
     {
-        $this->_page_bar_buttons[$side][$text] = array('img' => "../images/buttons/$img", 'link' => $link);
+        $this->_page_bar_buttons[$side][$text] = ['img' => "../images/buttons/$img", 'link' => $link];
+    }
 
-    }// /->set_page_bar_button()
+    // /->set_page_bar_button()
 
     /**
      * Draw the page toolbar
      */
-    function page_bar()
+    public function page_bar()
     {
         if (is_array($this->_page_bar_buttons)) {
             ?>
@@ -363,30 +370,30 @@ function page_bar()
                         <?php
                         if (array_key_exists('left', $this->_page_bar_buttons)) {
                             foreach ($this->_page_bar_buttons['left'] as $text => $button) {
-                                echo("<td><a class=\"page_bar_link\" href=\"{$button['link']}\" title=\"$text\"><img src=\"{$button['img']}\" alt=\"$text\" height=\"50\" /></a></td>");
+                                echo "<td><a class=\"page_bar_link\" href=\"{$button['link']}\" title=\"$text\"><img src=\"{$button['img']}\" alt=\"$text\" height=\"50\" /></a></td>";
                             }
-                        }
-                        ?>
+                        } ?>
                         <td width="100%">&nbsp;</td>
                         <?php
                         // right-hand buttons are automatically set to target="_blank"
                         if (array_key_exists('right', $this->_page_bar_buttons)) {
                             foreach ($this->_page_bar_buttons['right'] as $text => $button) {
-                                echo("<td><a class=\"page_bar_link\" href=\"{$button['link']}\" target=\"$text\" title=\"$text\"><img src=\"{$button['img']}\" alt=\"$text\" height=\"50\" /></a></td>");
+                                echo "<td><a class=\"page_bar_link\" href=\"{$button['link']}\" target=\"$text\" title=\"$text\"><img src=\"{$button['img']}\" alt=\"$text\" height=\"50\" /></a></td>";
                             }
-                        }
-                        ?>
+                        } ?>
                     </tr>
                 </table>
             </div>
             <?php
         }
-    }// /->page_bar()
+    }
+
+    // /->page_bar()
 
     /**
      * Footer
      */
-    function footer()
+    public function footer()
     {
         ?>
         <div id="footer">
@@ -394,36 +401,41 @@ function footer()
                 &copy; Loughborough University and University of Hull, 2005 - <?php echo date('Y'); ?>&nbsp;&nbsp;&nbsp;
                 <span style="font-size: small;">Version: <?php
                     echo APP__VERSION;
-                    if (count($this->installedMods) > 0) echo ' [' . implode(",", $this->installedMods) . ']'; ?></span>
+        if (count($this->installedMods) > 0) {
+            echo ' [' . implode(',', $this->installedMods) . ']';
+        } ?></span>
                 <?php
                 if (isset($this->user) && $this->user->is_admin() && $this->sourceId) {
                     echo "<br />\n";
                     echo '      <span style="font-size: small;">Source:&nbsp;';
                     echo ($this->sourceId) ? $this->sourceId : '&lt;' . APP__NAME . '&gt;';
                     echo "</span>\n";
-                }
-                ?>
+                } ?>
             </div>
             <iframe src="<?php echo APP__WWW; ?>/keep_alive.php" height="1" width="1" style="display: none;">keep
                 alive
             </iframe>
         </div>
         <?php
-    }// /->footer()
+    }
+
+    // /->footer()
 
     /**
      * Start main page content
      */
-    function content_start()
+    public function content_start()
     {
-        echo('<div id="container">');
-        echo('<div id="main">');
+        echo '<div id="container">';
+        echo '<div id="main">';
         $this->page_bar();
-        echo('<div id="content">');
+        echo '<div id="content">';
         if ($this->page_title) {
-            echo("<h1>{$this->page_title}</h1>\n\n");
+            echo "<h1>{$this->page_title}</h1>\n\n";
         }
-    }// /content_start()
+    }
+
+    // /content_start()
 
     /**
      * End main page content
@@ -431,7 +443,7 @@ function content_start()
      * @param boolean $render_header
      * @param boolean $renders_footer
      */
-    function content_end($render_menu = true, $render_header = true, $render_footer = true)
+    public function content_end($render_menu = true, $render_header = true, $render_footer = true)
     {
         ?>
         </div>
@@ -440,8 +452,7 @@ function content_end($render_menu = true, $render_header = true, $render_footer
         <div id="side_bar">
             <?php
             if ($render_menu) {
-                $this->menu();
-                ?>
+                $this->menu(); ?>
                 <div class="alert_box" style="margin: 40px 8px 8px 8px; font-size: 0.7em;">
                     <p><strong>Technical Problem?</strong></p>
                     <p>If you have a problem, find a bug or discover a technical problem in the system, <a
@@ -457,8 +468,7 @@ function content_end($render_menu = true, $render_header = true, $render_footer
                                 title="(email: <?php echo $this->branding['email.help']; ?>)">email us</a> to report it!</p>
                 </div>
                 <?php
-            }
-            ?>
+            } ?>
         </div>
         <?php
         if ($render_header) {
@@ -466,14 +476,15 @@ function content_end($render_menu = true, $render_header = true, $render_footer
         }
         if ($render_footer) {
             $this->footer();
-        }
-        ?>
+        } ?>
         <div class="clear"></div>
         </div> <!-- id="container" -->
         </body>
         </html>
         <?php
-    }// /content_end()
+    }
+
+    // /content_end()
 
     /**
      * function to draw the boxed list
@@ -482,20 +493,21 @@ function content_end($render_menu = true, $render_header = true, $render_footer
      * @param string $header_text
      * @param string $footer_text
      */
-    function draw_boxed_list($list, $box_class, $header_text, $footer_text)
+    public function draw_boxed_list($list, $box_class, $header_text, $footer_text)
     {
         if (is_array($list)) {
-            echo("<div class=\"$box_class\"><p style=\"font-weight: bold;\">$header_text</p><ul class=\"spaced\">");
+            echo "<div class=\"$box_class\"><p style=\"font-weight: bold;\">$header_text</p><ul class=\"spaced\">";
             foreach ($list as $item) {
-                echo("<li>$item</li>");
+                echo "<li>$item</li>";
             }
-            echo("</ul><p>$footer_text</p></div>");
+            echo "</ul><p>$footer_text</p></div>";
         }
-    }// ->draw_boxed_list()
+    }
+
+    // ->draw_boxed_list()
 
     // --------------------------------------------------------------------------------
     // Private Methods
-
 }// /class: UI
 
 ?>
diff --git a/src/includes/classes/User.php b/src/includes/classes/User.php
index 709d993..18646b2 100644
--- a/src/includes/classes/User.php
+++ b/src/includes/classes/User.php
@@ -12,209 +12,305 @@
 
 namespace WebPA\includes\classes;
 
-class User {
-  // Public Vars
-  public $username = null;
-  public $source_id = null;
-  public $password = null;
-  public $id = null;
-  public $admin = null;
-  public $id_number = null;
-  public $department_id = null;
-  public $forename = null;
-  public $lastname = null;
-  public $email = null;
-  public $type = null;
-
-  public $DAO = null;
-
-  /**
-  * CONSTRUCTOR for the class function
-  * @param string $username
-  * @param string $passsword
-  */
-  function __construct($username = null, $password = null) {
-    $this->username = $username;
-    $this->source_id = '';
-    $this->password = $password;
-    $this->id = null;
-    $this->type = null;
-    $this->id_number = null;
-    $this->department_id = null;
-    $this->forename = null;
-    $this->lastname = null;
-    $this->admin = 0;
-  }// /->User()
-
-/*
-* ================================================================================
-* PUBLIC
-*================================================================================
-*/
-
-  /**
-  * Load the object from the given data
-  *
-  * @param array $user_info  assoc-array of User info
-  *
-  * @return boolean did the load succeed
-  */
-  function load_from_row($user_info) {
-    if (is_array($user_info)) {
-      $this->id = $user_info['user_id'];
-      $this->admin = $user_info['admin'];
-      $this->id_number = $user_info['id_number'];
-      $this->department_id = $user_info['department_id'];
-      $this->username = $user_info['username'];
-      $this->source_id = $user_info['source_id'];
-      $this->password = $user_info['password'];
-      $this->forename = $user_info['forename'];
-      $this->lastname = $user_info['lastname'];
-      $this->email = $user_info['email'];
-      if ($this->admin) {
-        $this->type = APP__USER_TYPE_ADMIN;
-      } else {
-        $this->type = $user_info['user_type'];
-      }
+use Doctrine\DBAL\ParameterType;
+
+class User
+{
+    // Public Vars
+    public $username;
+
+    public $source_id;
+
+    public $password;
+
+    public $id;
+
+    public $admin;
+
+    public $id_number;
+
+    public $department_id;
+
+    public $forename;
+
+    public $lastname;
+
+    public $email;
+
+    public $type;
+
+    public DAO $DAO;
+
+    /**
+    * CONSTRUCTOR for the class function
+    * @param string $username
+    * @param string $passsword
+    */
+    public function __construct($username = null, $password = null)
+    {
+        $this->username = $username;
+        $this->source_id = '';
+        $this->password = password_hash($password, PASSWORD_DEFAULT);
+        $this->id = null;
+        $this->type = null;
+        $this->id_number = null;
+        $this->department_id = null;
+        $this->forename = null;
+        $this->lastname = null;
+        $this->admin = 0;
+    }
+
+    // /->User()
+
+    /*
+    * ================================================================================
+    * PUBLIC
+    *================================================================================
+    */
+
+    /**
+    * Load the object from the given data
+    *
+    * @param array $user_info  assoc-array of User info
+    *
+    * @return boolean did the load succeed
+    */
+    public function load_from_row($user_info)
+    {
+        if (is_array($user_info)) {
+            $this->id = $user_info['user_id'];
+            $this->admin = $user_info['admin'];
+            $this->id_number = $user_info['id_number'];
+            $this->department_id = $user_info['department_id'];
+            $this->username = $user_info['username'];
+            $this->source_id = $user_info['source_id'];
+            $this->password = $user_info['password'];
+            $this->forename = $user_info['forename'];
+            $this->lastname = $user_info['lastname'];
+            $this->email = $user_info['email'];
+            if ($this->admin) {
+                $this->type = APP__USER_TYPE_ADMIN;
+            } else {
+                $this->type = $user_info['user_type'];
+            }
+        }
+        return true;
     }
-    return true;
-  }// /->load_from_row()
-
-  /**
-  * Is this user admin?
-  *
-  * @return boolean user is admin
-  */
-  function is_admin() {
-    return ($this->admin == 1);
-  }// /->is_admin()
-
-  /**
-  * Is this user staff?
-  *
-  * @return boolean user is staff
-  */
-  function is_staff() {
-    return ($this->type == APP__USER_TYPE_ADMIN) || ($this->type == APP__USER_TYPE_TUTOR);
-  }// /->is_staff()
-
-  /*
-  Is this user tutor?
-  */
-  function is_tutor() {
-    return ($this->type == APP__USER_TYPE_TUTOR);
-  }// /->is_staff()
-
-  /*
-  Is this user student?
-  */
-  function is_student() {
-    return ($this->type == APP__USER_TYPE_STUDENT);
-  }// /->is_student()
-
-  /**
-   * Update password
-   *
-   * Updates the password used by the user
-   *
-   * @param string $password
-   */
-  function update_password($password){
-    $this->password = $password;
-  }
-
-  /**
-   * Function to update the username
-   * @param string $username
-   */
-   function update_username($username){
-    $this->username = $username;
-   }
-
-  /**
-   * Function to update the source_id
-   * @param string $source_id
-   */
-   function update_source_id($source_id){
-    $this->source_id = $source_id;
-   }
-
-  /**
-   * Function to update the user details
-   */
-   function save_user(){
-
-    $_fields = array ('forename'        => $this->forename ,
-              'lastname'        => $this->lastname ,
-              'email'         => $this->email,
-              'username'        => $this->username,
-              'source_id'      => $this->source_id,
-              'password'        => $this->password,
-              'id_number' => $this->id_number,
-              'department_id' => $this->department_id
-              );
-
-    //save the changes to the user
-    $this->DAO->do_update("UPDATE " . APP__DB_TABLE_PREFIX . "user SET {fields} WHERE user_id = {$this->id}; ",$_fields);
-
-    return true;
-   }
-
-   /**
-    * Function to set the database connection to be used
-    * @param database connection $this->DAO
+
+    // /->load_from_row()
+
+    /**
+    * Is this user admin?
+    *
+    * @return boolean user is admin
     */
-    function set_dao_object($DB){
-      $this->DAO = $DB;
+    public function is_admin()
+    {
+        return $this->admin == 1;
     }
 
-  /**
-   * Function to add new user details
-   */
-   function add_user(){
-
-    $_fields = array ('forename'        => $this->forename ,
-              'lastname'        => $this->lastname ,
-              'email'         => $this->email,
-              'username'        => $this->username,
-              'source_id'      => $this->source_id,
-              'password'        => $this->password,
-              'id_number' => $this->id_number,
-              'department_id' => $this->department_id,
-              'admin' => $this->admin
-              );
-
-    //save the changes to the user
-    $this->DAO->do_update("INSERT INTO " . APP__DB_TABLE_PREFIX . "user SET {fields}", $_fields);
-
-    return $this->DAO->get_insert_id() ;
-   }
-
-  /**
-   * Function to delete a user
-   */
-   function delete(){
-
-     $this->DAO->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "user_reset_request WHERE user_id = {$this->id}");
-     $this->DAO->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "form WHERE form_owner_id = {$this->id}");
-     $this->DAO->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "user_justification WHERE (marked_user_id = {$this->id}) OR (user_id = {$this->id})");
-     $this->DAO->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "user_mark WHERE (marked_user_id = {$this->id}) OR (user_id = {$this->id})");
-     $this->DAO->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "user_group_member WHERE user_id = {$this->id}");
-     $this->DAO->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "user_response WHERE user_id = {$this->id}");
-     $this->DAO->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "user_module WHERE user_id = {$this->id}");
-     $this->DAO->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "user_tracking WHERE user_id = {$this->id}");
-     $this->DAO->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "user WHERE user_id = {$this->id}");
-
-     $this->id = null;
-
-   }
-
-/*
-* ================================================================================
-* PRIVATE
-* ================================================================================
-*/
+    // /->is_admin()
 
-}// /class: User
+    /**
+    * Is this user staff?
+    *
+    * @return boolean user is staff
+    */
+    public function is_staff()
+    {
+        return ($this->type == APP__USER_TYPE_ADMIN) || ($this->type == APP__USER_TYPE_TUTOR);
+    }
+
+    // /->is_staff()
+
+    // Is this user tutor?
+    public function is_tutor()
+    {
+        return $this->type == APP__USER_TYPE_TUTOR;
+    }
+
+    // /->is_staff()
+
+    // Is this user student?
+    public function is_student()
+    {
+        return $this->type == APP__USER_TYPE_STUDENT;
+    }
+
+    // /->is_student()
+
+    /**
+     * Update password
+     *
+     * Updates the password used by the user
+     *
+     * @param string $password
+     */
+    public function update_password($password)
+    {
+        $this->password = password_hash($password, PASSWORD_DEFAULT);
+    }
+
+    /**
+     * Function to update the username
+     * @param string $username
+     */
+    public function update_username($username)
+    {
+        $this->username = $username;
+    }
+
+    /**
+     * Function to update the source_id
+     * @param string $source_id
+     */
+    public function update_source_id($source_id)
+    {
+        $this->source_id = $source_id;
+    }
+
+    /**
+     * Function to update the user details
+     */
+    public function save_user()
+    {
+        $this->DAO
+        ->getConnection()
+        ->createQueryBuilder()
+        ->update(APP__DB_TABLE_PREFIX . 'user')
+        ->set('forename', '?')
+        ->set('lastname', '?')
+        ->set('email', '?')
+        ->set('username', '?')
+        ->set('source_id', '?')
+        ->set('password', '?')
+        ->set('id_number', '?')
+        ->set('department_id', '?')
+        ->where('user_id = ?')
+        ->setParameter(0, $this->forename)
+        ->setParameter(1, $this->lastname)
+        ->setParameter(2, $this->email)
+        ->setParameter(3, $this->username)
+        ->setParameter(4, $this->source_id)
+        ->setParameter(5, $this->password)
+        ->setParameter(6, $this->id_number)
+        ->setParameter(7, $this->department_id)
+        ->setParameter(8, $this->id, ParameterType::INTEGER)
+        ->execute();
+
+        return true;
+    }
+
+    /**
+     * Function to set the database connection to be used
+     * @param DAO connection $this->DAO
+     */
+    public function set_dao_object(DAO $DB)
+    {
+        $this->DAO = $DB;
+    }
+
+    /**
+     * Function to add new user details
+     */
+    public function add_user()
+    {
+        $this->DAO
+           ->getConnection()
+           ->createQueryBuilder()
+           ->insert(APP__DB_TABLE_PREFIX . 'user')
+           ->values([
+               'forename' => '?',
+               'lastname' => '?',
+               'email' => '?',
+               'username' => '?',
+               'source_id' => '?',
+               'password' => '?',
+               'id_number' => '?',
+               'department_id' => '?',
+               'admin' => '?',
+           ])
+           ->setParameter(0, $this->forename)
+           ->setParameter(1, $this->lastname)
+           ->setParameter(2, $this->email)
+           ->setParameter(3, $this->username)
+           ->setParameter(4, $this->source_id)
+           ->setParameter(5, $this->password)
+           ->setParameter(6, $this->id_number)
+           ->setParameter(7, $this->department_id)
+           ->setParameter(8, $this->admin, ParameterType::INTEGER)
+           ->execute();
+
+        return $this->DAO->getConnection()->lastInsertId('user_id');
+    }
+
+    /**
+     * Function to delete a user
+     */
+    public function delete()
+    {
+        $dbConn = $this->DAO->getConnection();
+
+        $dbConn->executeQuery(
+            'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user_reset_request WHERE user_id = ?',
+            [$this->id],
+            [ParameterType::INTEGER]
+        );
+
+        $dbConn->executeQuery(
+            'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'form WHERE form_owner_id = ?',
+            [$this->id],
+            [ParameterType::INTEGER]
+        );
+
+        $dbConn->executeQuery(
+            'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user_justification WHERE marked_user_id = ? OR user_id = ?',
+            [$this->id, $this->id],
+            [ParameterType::INTEGER, ParameterType::INTEGER]
+        );
+
+        $dbConn->executeQuery(
+            'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user_mark WHERE marked_user_id = ? OR user_id = ?',
+            [$this->id, $this->id],
+            [ParameterType::INTEGER, ParameterType::INTEGER]
+        );
+
+        $dbConn->executeQuery(
+            'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user_group_member WHERE user_id = ?',
+            [$this->id],
+            [ParameterType::INTEGER]
+        );
+
+        $dbConn->executeQuery(
+            'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user_response WHERE user_id = ?',
+            [$this->id],
+            [ParameterType::INTEGER]
+        );
 
-?>
+        $dbConn->executeQuery(
+            'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user_module WHERE user_id = ?',
+            [$this->id],
+            [ParameterType::INTEGER]
+        );
+
+        $dbConn->executeQuery(
+            'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user_tracking WHERE user_id = ?',
+            [$this->id],
+            [ParameterType::INTEGER]
+        );
+
+        $dbConn->executeQuery(
+            'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user WHERE user_id = ?',
+            [$this->id],
+            [ParameterType::INTEGER]
+        );
+
+        $this->id = null;
+    }
+
+    /*
+    * ================================================================================
+    * PRIVATE
+    * ================================================================================
+    */
+}// /class: User
diff --git a/src/includes/classes/WebPAAlgorithm.php b/src/includes/classes/WebPAAlgorithm.php
index caafa9b..eba4be1 100644
--- a/src/includes/classes/WebPAAlgorithm.php
+++ b/src/includes/classes/WebPAAlgorithm.php
@@ -12,247 +12,282 @@
 
 namespace WebPA\includes\classes;
 
-class WebPAAlgorithm {
-  // Public Vars
-  public $_groups = null;
-  public $_group_members = null;
-  public $_questions = null;
-  public $_responses = null;
-  public $_marking_params = null;
-
-  public $_group_member_responses = null;
-  public $_group_member_total_awarded = null;
-  public $_group_member_frac_scores_awarded = null;
-  public $_group_member_total_received = null;
-  public $_group_member_webpa_scores = null;
-  public $_group_member_intermediate_grades = null;
-  public $_group_member_grades = null;
-
-  public $_group_member_submitted = null;
-  public $_member_submitted = null;
-
-  // Private Vars
-
-  /**
-  * CONSTRUCTOR
-  */
-  function __construct() {
-    $this->_init();
-  }
+class WebPAAlgorithm
+{
+    // Public Vars
+    public $_groups;
 
-/**
-* ================================================================================
-* Public Methods
-* ================================================================================
-*/
+    public $_group_members;
 
-/**
-* --------------------------------------------------------------------------------
-* Accessor Methods (GET)
-* --------------------------------------------------------------------------------
-*/
-
-  /**
-  * Function to get WebPA scores
-  *
-  * @param int $group_id
-  * @return array $scores
-  */
-  function get_webpa_scores($group_id = null) {
-
-    if (!is_array($this->_group_member_webpa_scores)) {
-      return array();
-    } else {
-      if ($group_id) {
-        return $this->_group_member_webpa_scores["$group_id"];
-      } else {
-        $scores = array();
-        foreach($this->_group_member_webpa_scores as $group_id => $member_scores) {
-          // [pmn] FIXED : needs this foreach to list scores by member_id
-
-          foreach($member_scores as $member_id => $score) {
-            $scores[$member_id] = $score;
-
-          }
-          //$scores = array_merge($scores, $member_scores);
+    public $_questions;
+
+    public $_responses;
+
+    public $_marking_params;
+
+    public $_group_member_responses;
+
+    public $_group_member_total_awarded;
+
+    public $_group_member_frac_scores_awarded;
+
+    public $_group_member_total_received;
+
+    public $_group_member_webpa_scores;
+
+    public $_group_member_intermediate_grades;
+
+    public $_group_member_grades;
+
+    public $_group_member_submitted;
+
+    public $_member_submitted;
+
+    // Private Vars
+
+    /**
+    * CONSTRUCTOR
+    */
+    public function __construct()
+    {
+        $this->_init();
+    }
+
+    /**
+    * ================================================================================
+    * Public Methods
+    * ================================================================================
+    */
+
+    /**
+    * --------------------------------------------------------------------------------
+    * Accessor Methods (GET)
+    * --------------------------------------------------------------------------------
+    */
+
+    /**
+    * Function to get WebPA scores
+    *
+    * @param int $group_id
+    * @return array $scores
+    */
+    public function get_webpa_scores($group_id = null)
+    {
+        if (!is_array($this->_group_member_webpa_scores)) {
+            return [];
+        }
+        if ($group_id) {
+            return $this->_group_member_webpa_scores["$group_id"];
+        }
+        $scores = [];
+        foreach ($this->_group_member_webpa_scores as $group_id => $member_scores) {
+            // [pmn] FIXED : needs this foreach to list scores by member_id
+
+            foreach ($member_scores as $member_id => $score) {
+                $scores[$member_id] = $score;
+            }
+            //$scores = array_merge($scores, $member_scores);
         }
         ksort($scores);
         return $scores;
-      }
     }
-  } // /->get_webpa_scores()
-
-  /**
-  * Function to Get grades
-  *
-  * @param int $group_id
-  * @return array $grades
-  */
-  function get_intermediate_grades($group_id = null) {
-    if ($group_id) {
-      return $this->_group_member_intermediate_grades["$group_id"];
-    } else {
-      $grades = array();
-      foreach($this->_group_member_intermediate_grades as $group_id => $member_grades) {
-        foreach($member_grades as $member_id => $grade) {
-          $grades[$member_id] = $grade;
+
+    // /->get_webpa_scores()
+
+    /**
+    * Function to Get grades
+    *
+    * @param int $group_id
+    * @return array $grades
+    */
+    public function get_intermediate_grades($group_id = null)
+    {
+        if ($group_id) {
+            return $this->_group_member_intermediate_grades["$group_id"];
+        }
+        $grades = [];
+        foreach ($this->_group_member_intermediate_grades as $group_id => $member_grades) {
+            foreach ($member_grades as $member_id => $grade) {
+                $grades[$member_id] = $grade;
+            }
         }
-      }
-      ksort($grades);
-      return $grades;
+        ksort($grades);
+        return $grades;
     }
-  } // /->get_intermediate_grades()
-
-  /**
-  * Function to Get grades
-  *
-  * @param int $group_id
-  * @return array $grades
-  */
-  function get_grades($group_id = null) {
-    if ($group_id) {
-      return $this->_group_member_grades["$group_id"];
-    } else {
-      $grades = array();
-      foreach($this->_group_member_grades as $group_id => $member_grades) {
-        foreach($member_grades as $member_id => $grade) {
-          $grades[$member_id] = $grade;
+
+    // /->get_intermediate_grades()
+
+    /**
+    * Function to Get grades
+    *
+    * @param int $group_id
+    * @return array $grades
+    */
+    public function get_grades($group_id = null)
+    {
+        if ($group_id) {
+            return $this->_group_member_grades["$group_id"];
         }
-      }
-      ksort($grades);
-      return $grades;
+        $grades = [];
+        foreach ($this->_group_member_grades as $group_id => $member_grades) {
+            foreach ($member_grades as $member_id => $grade) {
+                $grades[$member_id] = $grade;
+            }
+        }
+        ksort($grades);
+        return $grades;
     }
-  } // /->get_grades()
-
-  /**
-   * Function to get members submitting
-   *
-   * @param int $group_id
-   * @return mixed returns the members of the group that have submitted the assessment
-   */
-  function get_members_submitting($group_id = null) {
-    if ($group_id) {
-      return (array_key_exists($group_id, $this->_group_member_submitted)) ? $this->_group_member_submitted["$group_id"] : null ;
-    } else {
-      return $this->_member_submitted;
+
+    // /->get_grades()
+
+    /**
+     * Function to get members submitting
+     *
+     * @param int $group_id
+     * @return mixed returns the members of the group that have submitted the assessment
+     */
+    public function get_members_submitting($group_id = null)
+    {
+        if ($group_id) {
+            return (array_key_exists($group_id, $this->_group_member_submitted)) ? $this->_group_member_submitted["$group_id"] : null ;
+        }
+        return $this->_member_submitted;
     }
-  }// /->get_members_submitting()
-
-  /**
-   * Get the response given by one member of a group to another member for a particular question
-   *
-   * @param int $group_id
-   * @param int $member_id
-   * @param int $question_id
-   * @param int $target_member_id
-   *
-   * @return array $response_score
-   */
-  function get_member_response($group_id, $member_id, $question_id, $target_member_id) {
-    $response_score = null;
-    if (array_key_exists($group_id, $this->_group_member_responses)) {
-      if (array_key_exists($member_id, $this->_group_member_responses[$group_id])) {
-        if (array_key_exists($question_id, $this->_group_member_responses[$group_id][$member_id])) {
-          if (array_key_exists($target_member_id, $this->_group_member_responses[$group_id][$member_id][$question_id])) {
-            $response_score = $this->_group_member_responses[$group_id][$member_id][$question_id][$target_member_id];
-          }
+
+    // /->get_members_submitting()
+
+    /**
+     * Get the response given by one member of a group to another member for a particular question
+     *
+     * @param int $group_id
+     * @param int $member_id
+     * @param int $question_id
+     * @param int $target_member_id
+     *
+     * @return array $response_score
+     */
+    public function get_member_response($group_id, $member_id, $question_id, $target_member_id)
+    {
+        $response_score = null;
+        if (array_key_exists($group_id, $this->_group_member_responses)) {
+            if (array_key_exists($member_id, $this->_group_member_responses[$group_id])) {
+                if (array_key_exists($question_id, $this->_group_member_responses[$group_id][$member_id])) {
+                    if (array_key_exists($target_member_id, $this->_group_member_responses[$group_id][$member_id][$question_id])) {
+                        $response_score = $this->_group_member_responses[$group_id][$member_id][$question_id][$target_member_id];
+                    }
+                }
+            }
         }
-      }
+        return $response_score;
     }
-    return $response_score;
-  }
 
-/**
-* --------------------------------------------------------------------------------
-* Accessor Methods (SET)
-* --------------------------------------------------------------------------------
-*/
-
-  /**
-  * Set groups
-  *
-  *@param array $groups groups to use in this algorithm : array[group_id] = group_mark
-  */
-  function set_groups(& $groups) {
-    $this->_groups =& $groups;
-  }// /->set_groups()
-
-  /*
-  * Set group members
-  *
-  * $group_members  : (array) - members to use in this algorithm : array[group_id] = array ( member_id, ... )
-  */
-  function set_group_members(& $group_members) {
-    $this->_group_members =& $group_members;
-  }// /->set_group_members()
-
-  /*
-  * Set marking parameters
-  *
-  * $params : (array) - marking parameters for this report : array ( int weighting , int penalty )
-  */
-  function set_marking_params(& $marking_params) {
-    $this->_marking_params =& $marking_params;
-  }// /->set_marking_params()
-
-  /*
-  * Set questions
-  * This could've just accepted an integer, but for future proofing (just in case) it takes an array (0-based)
-  *
-  * $questions  : (array) - questions in this assessment : array ( question_id, ... )
-  */
-  function set_questions(& $questions) {
-    $this->_questions =& $questions;
-  }// /->set_questions()
-
-  /*
-  * Set member responses
-  *
-  * $responses  : (array) - responses given for this assessment : array[member_id][question_id][marked_member_id] = score
-  */
-  function set_responses(& $responses) {
-    $this->_responses =& $responses;
-  }// /->set_responses()
-
-/*
-* --------------------------------------------------------------------------------
-* Methods
-* --------------------------------------------------------------------------------
-*/
-
-  /*
-  * Calculate the WebPA and group scores for each student
-  */
-  function calculate() {
-    echo('<p>ERROR: WebPAAlgorithm->calculate() is an abstract method and should be overridden.</p>');
-    exit;
-  }// /->calculate()
-
-/*
-* ================================================================================
-* Private Methods
-* ================================================================================
-*/
-
-  function _init() {
-    $this->_groups = null;
-    $this->_group_members = null;
-    $this->_questions = null;
-    $this->_responses = null;
-    $this->_marking_params = null;
-
-    $this->_group_member_responses = null;
-    $this->_group_member_total_awarded = null;
-    $this->_group_member_frac_scores_awarded = null;
-    $this->_group_member_total_received = null;
-    $this->_group_member_webpa_scores = null;
-    $this->_group_member_intermediate_grades = null;
-    $this->_group_member_grades = null;
-
-    $this->_group_member_submitted = null;
-    $this->_member_submitted = null;
-  }// /->_init()
+    /**
+    * --------------------------------------------------------------------------------
+    * Accessor Methods (SET)
+    * --------------------------------------------------------------------------------
+    */
 
-}// /class: WebPAAlgorithm
+    /**
+    * Set groups
+    *
+    *@param array $groups groups to use in this algorithm : array[group_id] = group_mark
+    */
+    public function set_groups(& $groups)
+    {
+        $this->_groups =& $groups;
+    }
+
+    // /->set_groups()
+
+    /*
+    * Set group members
+    *
+    * $group_members  : (array) - members to use in this algorithm : array[group_id] = array ( member_id, ... )
+    */
+    public function set_group_members(& $group_members)
+    {
+        $this->_group_members =& $group_members;
+    }
+
+    // /->set_group_members()
+
+    /*
+    * Set marking parameters
+    *
+    * $params : (array) - marking parameters for this report : array ( int weighting , int penalty )
+    */
+    public function set_marking_params(& $marking_params)
+    {
+        $this->_marking_params =& $marking_params;
+    }
+
+    // /->set_marking_params()
+
+    /*
+    * Set questions
+    * This could've just accepted an integer, but for future proofing (just in case) it takes an array (0-based)
+    *
+    * $questions  : (array) - questions in this assessment : array ( question_id, ... )
+    */
+    public function set_questions(& $questions)
+    {
+        $this->_questions =& $questions;
+    }
 
-?>
+    // /->set_questions()
+
+    /*
+    * Set member responses
+    *
+    * $responses  : (array) - responses given for this assessment : array[member_id][question_id][marked_member_id] = score
+    */
+    public function set_responses(& $responses)
+    {
+        $this->_responses =& $responses;
+    }
+
+    // /->set_responses()
+
+    /*
+    * --------------------------------------------------------------------------------
+    * Methods
+    * --------------------------------------------------------------------------------
+    */
+
+    // Calculate the WebPA and group scores for each student
+    public function calculate()
+    {
+        echo '<p>ERROR: WebPAAlgorithm->calculate() is an abstract method and should be overridden.</p>';
+        exit;
+    }
+
+    // /->calculate()
+
+    /*
+    * ================================================================================
+    * Private Methods
+    * ================================================================================
+    */
+
+    public function _init()
+    {
+        $this->_groups = null;
+        $this->_group_members = null;
+        $this->_questions = null;
+        $this->_responses = null;
+        $this->_marking_params = null;
+
+        $this->_group_member_responses = null;
+        $this->_group_member_total_awarded = null;
+        $this->_group_member_frac_scores_awarded = null;
+        $this->_group_member_total_received = null;
+        $this->_group_member_webpa_scores = null;
+        $this->_group_member_intermediate_grades = null;
+        $this->_group_member_grades = null;
+
+        $this->_group_member_submitted = null;
+        $this->_member_submitted = null;
+    }
+
+    // /->_init()
+}// /class: WebPAAlgorithm
diff --git a/src/includes/classes/Wizard.php b/src/includes/classes/Wizard.php
index 5b27fa0..235712b 100644
--- a/src/includes/classes/Wizard.php
+++ b/src/includes/classes/Wizard.php
@@ -14,296 +14,347 @@
 
 use WebPA\includes\functions\Common;
 
-class Wizard {
-  // Public Vars
-  public $back_button = '&lt; Back';
-  public $next_button = 'Next &gt;';
-  public $cancel_button = 'Cancel';
-  public $cancel_url = '';
+class Wizard
+{
+    // Public Vars
+    public $back_button = '&lt; Back';
 
-  public $name = '';
+    public $next_button = 'Next &gt;';
 
-  // Private Vars
-  private $_page_url = null;
-  private $_head_content = null;
-  private $_form_content = null;
+    public $cancel_button = 'Cancel';
 
-  private $_current_step = 1;
-  private $_total_steps = 1;
-  private $_override_num_steps = null;
+    public $cancel_url = '';
 
-  private $_last_wizstep = null;
-  private $_current_wizstep = null;
+    public $name = '';
 
-  private $_step_includes = array();
-  private $_fields = array();
-  private $_vars = array ();
+    // Private Vars
+    private $_page_url;
 
-  private $_errors = null;
+    private $_head_content;
 
-  /**
-  * CONSTRUCTOR for the wizard class
-  * @param string $name
-  */
-  function __construct($name) {
-    $this->name = $name;
-    $this->_page_url = $_SERVER["PHP_SELF"];
+    private $_form_content;
 
-    $this->_fields = unserialize( base64_decode( Common::fetch_POST('wiz_stored_fields',null) ) );
-    if (!is_array($this->_fields)) { $this->_fields = array(); }
-  }// /->Wizard()
+    private $_current_step = 1;
 
-/*
-* --------------------------------------------------------------------------------
-* Public Methods
-* --------------------------------------------------------------------------------
-*/
+    private $_total_steps = 1;
 
-/**
- * Function to add a step to the wizard
- * @param string $step_num
- * @param string $step_include_file
- */
-  function add_step($step_num, $step_include_file) {
-    $step_num = (int) $step_num;
-    $this->_step_includes["$step_num"] = $step_include_file;
-  }// /add_step()
+    private $_override_num_steps;
 
-/**
- * Function to write errors to screen
- */
-  function draw_errors() {
-    if ($this->_errors) {
-      ?>
+    private $_last_wizstep;
+
+    private $_current_wizstep;
+
+    private $_step_includes = [];
+
+    private $_fields = [];
+
+    private $_vars = [];
+
+    private $_errors;
+
+    /**
+    * CONSTRUCTOR for the wizard class
+    * @param string $name
+    */
+    public function __construct($name)
+    {
+        $this->name = $name;
+        $this->_page_url = $_SERVER['PHP_SELF'];
+
+        $this->_fields = unserialize(base64_decode(Common::fetch_POST('wiz_stored_fields', null)));
+        if (!is_array($this->_fields)) {
+            $this->_fields = [];
+        }
+    }
+
+    // /->Wizard()
+
+    /*
+    * --------------------------------------------------------------------------------
+    * Public Methods
+    * --------------------------------------------------------------------------------
+    */
+
+    /**
+     * Function to add a step to the wizard
+     * @param string $step_num
+     * @param string $step_include_file
+     */
+    public function add_step($step_num, $step_include_file)
+    {
+        $step_num = (int) $step_num;
+        $this->_step_includes["$step_num"] = $step_include_file;
+    }
+
+    // /add_step()
+
+    /**
+     * Function to write errors to screen
+     */
+    public function draw_errors()
+    {
+        if ($this->_errors) {
+            ?>
       <div class="error_box" style="">
         <p style="font-weight: bold;">The following errors were found:</p>
         <ul class="spaced">
         <?php
-        foreach($this->_errors as $error_msg) {
-          echo("<li>$error_msg</li>");
-        }
-        ?>
+        foreach ($this->_errors as $error_msg) {
+            echo "<li>$error_msg</li>";
+        } ?>
         </ul>
         <p>Please check the information in the form and try again.</p>
       </div>
       <?php
+        }
     }
-  }// ->draw_errors()
 
-/**
- * function to write the wizard information to the screen
- */
-  function draw_wizard() {
-    $wiz_fields = base64_encode( serialize( $this->_fields ) );
+    // ->draw_errors()
 
-    // build the wizard HTML code
-    $html = <<<HTMLEnd
-    <form action="{$this->_page_url}" method="post" name="wizard_form" onsubmit="return wizard_form_onsubmit();">
-    <input type="hidden" name="wiz_stored_fields" value="$wiz_fields" />
-    <input type="hidden" name="wiz_command" id="wiz_command" value="none" />
+    /**
+     * function to write the wizard information to the screen
+     */
+    public function draw_wizard()
+    {
+        $wiz_fields = base64_encode(serialize($this->_fields));
 
-    <div style="min-height: 170px;">
-HTMLEnd;
-    echo($html);
+        // build the wizard HTML code
+        $html = <<<HTMLEnd
+                <form action="{$this->_page_url}" method="post" name="wizard_form" onsubmit="return wizard_form_onsubmit();">
+                <input type="hidden" name="wiz_stored_fields" value="$wiz_fields" />
+                <input type="hidden" name="wiz_command" id="wiz_command" value="none" />
 
-    if ($this->_current_wizstep) {
-      $this->_current_wizstep->form();
-    }
+                <div style="min-height: 170px;">
+            HTMLEnd;
+        echo $html;
 
-    // set the text for the wizard buttons
-    $temp_back = (empty($this->back_button)) ? '&nbsp;': "<input type=\"button\" name=\"wiz_command_back\" id=\"wiz_command_back\" onclick=\"do_command('back')\" value=\"$this->back_button\" />";
-    $temp_next = (empty($this->next_button)) ? '&nbsp;': "<input type=\"button\" name=\"wiz_command_next\" id=\"wiz_command_next\" onclick=\"do_command('next')\" value=\"$this->next_button\" />";
-    $temp_cancel = (empty($this->cancel_button)) ? '&nbsp;': "<input type=\"button\" name=\"wiz_command_cancel\" id=\"wiz_command_cancel\" onclick=\"do_command('cancel')\" value=\"$this->cancel_button\" />";
+        if ($this->_current_wizstep) {
+            $this->_current_wizstep->form();
+        }
 
-    $html = <<<HTMLEnd
-    </div>
+        // set the text for the wizard buttons
+        $temp_back = (empty($this->back_button)) ? '&nbsp;': "<input type=\"button\" name=\"wiz_command_back\" id=\"wiz_command_back\" onclick=\"do_command('back')\" value=\"$this->back_button\" />";
+        $temp_next = (empty($this->next_button)) ? '&nbsp;': "<input type=\"button\" name=\"wiz_command_next\" id=\"wiz_command_next\" onclick=\"do_command('next')\" value=\"$this->next_button\" />";
+        $temp_cancel = (empty($this->cancel_button)) ? '&nbsp;': "<input type=\"button\" name=\"wiz_command_cancel\" id=\"wiz_command_cancel\" onclick=\"do_command('cancel')\" value=\"$this->cancel_button\" />";
 
-    <table align="center" style="margin-top: 20px;" cellpadding="0" cellspacing="0" width="70%">
-    <tr>
-      <td align="left" width="33%">$temp_back</td>
-      <td align="center" width="33%">$temp_cancel</td>
-      <td align="right" width="33%">$temp_next</td>
-    </tr>
-    </table>
+        $html = <<<HTMLEnd
+                </div>
 
-    </form>
-HTMLEnd;
+                <table align="center" style="margin-top: 20px;" cellpadding="0" cellspacing="0" width="70%">
+                <tr>
+                  <td align="left" width="33%">$temp_back</td>
+                  <td align="center" width="33%">$temp_cancel</td>
+                  <td align="right" width="33%">$temp_next</td>
+                </tr>
+                </table>
 
-    echo($html);
-  }// /->draw_wizard()
+                </form>
+            HTMLEnd;
 
-/**
- * function prepare
- */
-  function prepare() {
-    $this->_current_step = (array_key_exists('current_step',$this->_fields)) ? $this->_fields['current_step'] : 1 ;
-    $this->_total_steps = count($this->_step_includes);
+        echo $html;
+    }
 
-    $do_last = false;
-    $do_next = true;
+    // /->draw_wizard()
 
-    $wiz_command = Common::fetch_POST('wiz_command');
+    /**
+     * function prepare
+     */
+    public function prepare()
+    {
+        $this->_current_step = (array_key_exists('current_step', $this->_fields)) ? $this->_fields['current_step'] : 1 ;
+        $this->_total_steps = count($this->_step_includes);
 
-    switch ($wiz_command) {
-      case 'back' :
+        $do_last = false;
+        $do_next = true;
+
+        $wiz_command = Common::fetch_POST('wiz_command');
+
+        switch ($wiz_command) {
+      case 'back':
             $this->_current_step = ($this->_current_step>1) ? ($this->_current_step-1) : 1;
             $do_last = false;
             break;
       // ----------
-      case 'next' :
+      case 'next':
             $this->_current_step = ($this->_current_step<$this->_total_steps) ? ($this->_current_step + 1) : $this->_total_steps;
             $do_last = true;
             break;
       // ----------
-      case 'cancel' :
+      case 'cancel':
             header("Location: {$this->cancel_url}");
             exit;
             break;
       // ----------
-      default :
+      default:
             $do_last = false;
             break;
     }// /switch
 
 
-    // check if we should even try to do the wizard
-    if ($this->_current_step<=$this->_total_steps) {
+        // check if we should even try to do the wizard
+        if ($this->_current_step<=$this->_total_steps) {
 
       // get the last page we loaded
-      if ( ($do_last) && ($this->_current_step>1) ) {
-        $last_wiz_num = $this->_current_step - 1;
-        include_once($this->_step_includes["$last_wiz_num"]);
-        eval("\$this->_last_wizstep = new WizardStep{$last_wiz_num}(\$this);");
-
-        if ($this->_last_wizstep) {
-          $this->_errors = $this->_last_wizstep->process_form();
-
-          // if there are errors, we won't be showing the next page, we'll go back to the last one!
-          if (is_array($this->_errors)) {
-            $this->_current_step = $this->_last_wizstep->step;
-            $this->_current_wizstep =& $this->_last_wizstep;
-          }
+            if (($do_last) && ($this->_current_step>1)) {
+                $last_wiz_num = $this->_current_step - 1;
+                include_once $this->_step_includes["$last_wiz_num"];
+                eval("\$this->_last_wizstep = new WizardStep{$last_wiz_num}(\$this);");
+
+                if ($this->_last_wizstep) {
+                    $this->_errors = $this->_last_wizstep->process_form();
+
+                    // if there are errors, we won't be showing the next page, we'll go back to the last one!
+                    if (is_array($this->_errors)) {
+                        $this->_current_step = $this->_last_wizstep->step;
+                        $this->_current_wizstep =& $this->_last_wizstep;
+                    }
+                }
+            }// /if checking last page
+
+            // If the last page of the wizard was OK (or didn't exist), get the next page
+            if ($do_next) {
+                // get the current step
+                include_once $this->_step_includes["{$this->_current_step}"];
+                eval("\$this->_current_wizstep = new WizardStep{$this->_current_step}(\$this);");
+            }
+        }
+
+        $this->_current_step = $this->_current_wizstep->step;
+        $this->_fields['current_step'] = $this->_current_step;
+    }
+
+    // /->prepare()
+
+    /**
+     * function to write the title of the wizard step to the screen
+     */
+    public function title()
+    {
+        if (!is_null($this->_override_num_steps)) {
+            if ($this->_current_step<=$this->_override_num_steps) {
+                echo "<p>You are on <strong>step {$this->_current_step}</strong> of <strong>{$this->_override_num_steps}</strong> in the {$this->name}.</p>";
+            }
+        } else {
+            echo "<p>You are on <strong>step {$this->_current_step}</strong> of <strong>{$this->_total_steps}</strong> in the {$this->name}.</p>";
         }
-      }// /if checking last page
-
-      // If the last page of the wizard was OK (or didn't exist), get the next page
-      if ($do_next) {
-        // get the current step
-        include_once($this->_step_includes["{$this->_current_step}"]);
-        eval("\$this->_current_wizstep = new WizardStep{$this->_current_step}(\$this);");
-      }
     }
 
-    $this->_current_step = $this->_current_wizstep->step;
-    $this->_fields['current_step'] = $this->_current_step;
-  }// /->prepare()
+    // /->title()
 
-/**
- * function to write the title of the wizard step to the screen
- */
-  function title() {
-    if (!is_null($this->_override_num_steps)) {
-      if ($this->_current_step<=$this->_override_num_steps) {
-        echo("<p>You are on <strong>step {$this->_current_step}</strong> of <strong>{$this->_override_num_steps}</strong> in the {$this->name}.</p>");
-      }
-    } else {
-      echo("<p>You are on <strong>step {$this->_current_step}</strong> of <strong>{$this->_total_steps}</strong> in the {$this->name}.</p>");
+    /**
+     * function to get the field names for the input boxes
+     * @param string $field_name
+     * @return array
+     */
+    public function get_field($field_name, $default = null)
+    {
+        return (array_key_exists($field_name, $this->_fields)) ? $this->_fields["$field_name"] :  $default ;
     }
-  }// /->title()
 
-/**
- * function to get the field names for the input boxes
- * @param string $field_name
- * @return array
- */
-  function get_field($field_name, $default = null) {
-    return (array_key_exists($field_name,$this->_fields)) ? $this->_fields["$field_name"] :  $default ;
-  }// /->get_field()
+    // /->get_field()
 
-/**
- * function to set the fields used in the wizard
- * @param string $field_name
- * @param string $field_value
- */
-  function set_field($field_name, $field_value) {
-    $this->_fields["$field_name"] = $field_value;
-  }// /->set_field()
+    /**
+     * function to set the fields used in the wizard
+     * @param string $field_name
+     * @param string $field_value
+     */
+    public function set_field($field_name, $field_value)
+    {
+        $this->_fields["$field_name"] = $field_value;
+    }
 
-/**
- * function to set variables
- * @param string $var_name
- * @param string $var_value
- */
-  function set_var($var_name, &$var_value) {
-    $this->_vars["$var_name"] =& $var_value;
-  }// /->set_var()
+    // /->set_field()
 
-/**
- * function to get the variable by name
- * @param string $var_name
- *
- * @return mixed|null
- */
-  function get_var($var_name) {
-    return (array_key_exists($var_name,$this->_vars)) ? $this->_vars["$var_name"] :  null ;
-  }
+    /**
+     * function to set variables
+     * @param string $var_name
+     * @param string $var_value
+     */
+    public function set_var($var_name, &$var_value)
+    {
+        $this->_vars["$var_name"] =& $var_value;
+    }
 
-/**
- * Function to get the step
- * @return string
- */
-  function get_step() {
-    return $this->_current_step;
-  }// /->get_step()
+    // /->set_var()
+
+    /**
+     * function to get the variable by name
+     * @param string $var_name
+     *
+     * @return mixed|null
+     */
+    public function get_var($var_name)
+    {
+        return (array_key_exists($var_name, $this->_vars)) ? $this->_vars["$var_name"] :  null ;
+    }
 
-/**
- * function to set the url for the wizard
- * @param string $url
- */
-  function set_wizard_url($url) {
-    $this->_page_url = $url;
-  }// /->set_page_url()
+    /**
+     * Function to get the step
+     * @return string
+     */
+    public function get_step()
+    {
+        return $this->_current_step;
+    }
 
-/**
- * function to show the steps
- * @param string|integer $num_steps
- */
-  function show_steps($num_steps) {
-    $this->_override_num_steps = $num_steps;
-  }// /->show_steps
+    // /->get_step()
 
-/**
- * function to wite the head for the wizard page
- */
-  function head() {
-    $this->_current_wizstep->head();
+    /**
+     * function to set the url for the wizard
+     * @param string $url
+     */
+    public function set_wizard_url($url)
+    {
+        $this->_page_url = $url;
+    }
 
-    $html = <<<HTMLEnd
-<script language="JavaScript" type="text/javascript">
-<!--
+    // /->set_page_url()
 
-  function do_command(str_comm) {
-    document.getElementById('wiz_command').value = str_comm;
-    document.wizard_form.submit();
-  }// /do_command
+    /**
+     * function to show the steps
+     * @param string|integer $num_steps
+     */
+    public function show_steps($num_steps)
+    {
+        $this->_override_num_steps = $num_steps;
+    }
+
+    // /->show_steps
+
+    /**
+     * function to wite the head for the wizard page
+     */
+    public function head()
+    {
+        $this->_current_wizstep->head();
+
+        $html = <<<HTMLEnd
+            <script language="JavaScript" type="text/javascript">
+            <!--
 
-  function wizard_form_onsubmit() {
-    return (document.wizard_form.wiz_command.value !='none');
-  }
+              function do_command(str_comm) {
+                document.getElementById('wiz_command').value = str_comm;
+                document.wizard_form.submit();
+              }// /do_command
 
-//-->
-</script>
-HTMLEnd;
+              function wizard_form_onsubmit() {
+                return (document.wizard_form.wiz_command.value !='none');
+              }
 
-    echo($html);
-  }// /->head()
+            //-->
+            </script>
+            HTMLEnd;
+
+        echo $html;
+    }
+
+    // /->head()
 
 /*
 * --------------------------------------------------------------------------------
 * Private Methods
 * --------------------------------------------------------------------------------
 */
-
 }// /class: Wizard
 
 ?>
diff --git a/src/includes/classes/XMLParser.php b/src/includes/classes/XMLParser.php
index cce2154..f5f13ce 100644
--- a/src/includes/classes/XMLParser.php
+++ b/src/includes/classes/XMLParser.php
@@ -38,40 +38,46 @@
 
 class XMLParser
 {
-
     // Public Vars
     public $xml_data = '';
+
     public $xml_array;
 
     // Private Vars
     private $_parser;            // reference to the XML parser object
 
     private $_parent;            // used by ->parse()
+
     private $_stack;             // used by ->parse()
+
     private $_last_opened_tag;   // used by ->parse()
 
-    private $_cdata_tags = array();     // tags which should be handled as CDATA
+    private $_cdata_tags = [];     // tags which should be handled as CDATA
 
     private $data;
 
     /**
      * CONSTRUCTOR for the XML parser
      */
-    function __construct()
+    public function __construct()
     {
         $this->_init();
-    }// /XMLParser()
+    }
+
+    // /XMLParser()
 
     /**
      * DESTRUCTOR for the xml parser
      */
-    function destroy()
+    public function destroy()
     {
         if (is_resource($this->_parser)) {
             xml_parser_free($this->_parser);
         }
         $this->_parser = null;
-    }// /->destroy()
+    }
+
+    // /->destroy()
 
     /*
     * ================================================================================
@@ -83,18 +89,22 @@ function destroy()
      * function to set the data tags
      * @param string $tags
      */
-    function set_cdata_tags($tags)
+    public function set_cdata_tags($tags)
     {
-        $this->_cdata_tags = (array)$tags;
-    }// /->set_cdata_tags()
+        $this->_cdata_tags = (array) $tags;
+    }
+
+    // /->set_cdata_tags()
 
     /**
      * function to clear
      */
-    function clear()
+    public function clear()
     {
         $this->_init();
-    }// /->clear()
+    }
+
+    // /->clear()
 
     /**
      * Parse the given XML document into a PHP array.
@@ -103,7 +113,7 @@ function clear()
      *
      * @return array PHP array representing XML structure
      */
-    function parse($xml_data)
+    public function parse($xml_data)
     {
         $this->_parser = xml_parser_create('');
 
@@ -119,7 +129,7 @@ function parse($xml_data)
 
         $this->data = '';
         $this->_last_opened_tag = null;
-        $this->_cdata_tags = (array)$this->_cdata_tags;
+        $this->_cdata_tags = (array) $this->_cdata_tags;
 
 
         return xml_parse($this->_parser, $this->xml_data, true) ? $this->xml_array : null;
@@ -131,16 +141,16 @@ function parse($xml_data)
      * @param array $data xml array structure
      * @return string  xml document
      */
-    function generate_xml(&$data, $level = 0, $prior_key = null)
+    public function generate_xml(&$data, $level = 0, $prior_key = null)
     {
         if ($level == 0) {
             ob_start();
             $prior_key = null;
-            echo("<?xml version=\"1.0\" ?>\n");
+            echo "<?xml version=\"1.0\" ?>\n";
         }
 
         foreach ($data as $key => $value) {
-            $key = (string)$key;
+            $key = (string) $key;
             // If the array key is NOT attributes or data, then it might be more tags (if it is attributes/data, just ignore it)
             if (($key != '_attributes') && ($key != '_data')) {
                 // This tag may contain others, so process them
@@ -149,21 +159,21 @@ function generate_xml(&$data, $level = 0, $prior_key = null)
                 } else {
                     $tag = $prior_key ? $prior_key : $key;
                     $tab_indent = str_repeat("\t", $level);
-                    echo("{$tab_indent}<{$tag}");
+                    echo "{$tab_indent}<{$tag}";
 
                     // Get a list of all the sub-arrays
-                    $sub_array = array_flip(array_keys((array)$value));
+                    $sub_array = array_flip(array_keys((array) $value));
 
                     // If the tag has attributes, show them
-                    if ((in_array('_attributes', $sub_array)) && (!empty($value['_attributes']))) {
+                    // For backwards compatibility reasons, we do a check on if the sub_array is empty. Previously this was an in_array() check which always returned true
+                    if (!empty($sub_array) && !empty($value['_attributes'])) {
                         foreach ($value['_attributes'] as $attr_name => $attr_value) {
-                            echo(' ' . $attr_name . '="' . htmlspecialchars($attr_value) . '"');
+                            echo ' ' . $attr_name . '="' . htmlspecialchars($attr_value) . '"';
                         }
-                        reset($data[$key]["_attributes"]);
                     }
 
                     // Get the tag's value
-                    $tag_data = (array_key_exists("_data", (array)$value)) ? $value['_data'] : null;
+                    $tag_data = (array_key_exists('_data', (array) $value)) ? $value['_data'] : null;
 
                     // Remove the attributes/data from the sub-array list
                     unset($sub_array['_attributes'], $sub_array['_data']);
@@ -171,33 +181,35 @@ function generate_xml(&$data, $level = 0, $prior_key = null)
 
                     // If there are still sub-arrays then they're probably tags, so process them
                     if (count($sub_array) > 0) {
-                        echo(">\n");  // ->generate_xml returns the xml by reference, so need to do this in two halves
-                        echo($this->generate_xml($value, $level + 1) . "{$tab_indent}</$tag>\n");
+                        echo ">\n";  // ->generate_xml returns the xml by reference, so need to do this in two halves
+                        echo $this->generate_xml($value, $level + 1) . "{$tab_indent}</$tag>\n";
                     } else {  // need to process the tag value
                         // If the tag has no value, show an empty tag
                         if (!$tag_data) {
-                            echo(" />\n");
+                            echo " />\n";
                         } else {
                             // If this tag has been highlighted as a CDATA tag, use CDATA
                             if (in_array($tag, $this->_cdata_tags)) {
-                                echo("><![CDATA[{$tag_data}]]></$tag>\n");
+                                echo "><![CDATA[{$tag_data}]]></$tag>\n";
                             } else {  // Else, just use the value
-                                echo('>' . htmlspecialchars($tag_data) . "</$tag>\n");
+                                echo '>' . htmlspecialchars($tag_data) . "</$tag>\n";
                             }
                         }
                     }
                 }
             }
         }
-        reset($data);
 
         if ($level == 0) {
             $str = &ob_get_contents();
+
             ob_end_clean();
+
             return $str;
         }
+    }
 
-    }// ->generate_xml()
+    // ->generate_xml()
 
 
     /*
@@ -218,7 +230,7 @@ function generate_xml(&$data, $level = 0, $prior_key = null)
      * @param string $tag
      * @param string $attributes
      */
-    function _tag_open(&$parser, $tag, $attributes)
+    public function _tag_open($parser, $tag, $attributes)
     {
         $this->data = '';
         $this->_last_opened_tag = $tag;
@@ -230,7 +242,7 @@ function _tag_open(&$parser, $tag, $attributes)
                 $key = $this->_count_numeric_items($this->_parent[$tag]);
             } else {
                 // Need to create the array of tags
-                $arr = array(&$this->_parent[$tag]);
+                $arr = [&$this->_parent[$tag]];
                 $this->_parent[$tag] = &$arr;
                 $key = 1;
             }
@@ -244,35 +256,41 @@ function _tag_open(&$parser, $tag, $attributes)
 
         $this->_parent = &$this->_parent[$key];
         $this->_stack[] = &$this->_parent;
-    }// /->_tag_open()
+    }
 
     /**
      * tag-data event handler
      * @param string $parser
      * @param string $data
      */
-    function _tag_data(&$parser, $data)
+    public function _tag_data($parser, $data)
     {
         //you don't need to store whitespace in between tags
-        if ($this->_last_opened_tag != NULL) {
+        if ($this->_last_opened_tag != null) {
             $this->data .= $data;
         }
-    }// /->_tag_data()
+    }
+
+    // /->_tag_data()
 
     /*
     * tag-close event handler
     * @param string $parser
     * @param string $tag
     */
-    function _tag_close(&$parser, $tag)
+    public function _tag_close($parser, $tag)
     {
         if ($this->_last_opened_tag == $tag) {
             $this->_parent['_data'] = $this->data;
-            $this->_last_opened_tag = NULL;
+            $this->_last_opened_tag = null;
         }
         array_pop($this->_stack);
-        if ($this->_stack) $this->_parent = &$this->_stack[count($this->_stack) - 1];
-    }// /->_tag_close()
+        if ($this->_stack) {
+            $this->_parent = &$this->_stack[count($this->_stack) - 1];
+        }
+    }
+
+    // /->_tag_close()
 
     /*
     * --------------------------------------------------------------------------------
@@ -285,14 +303,14 @@ function _tag_close(&$parser, $tag)
      * @param array $array
      * @return boolean
      */
-    function _count_numeric_items(&$array)
+    public function _count_numeric_items(&$array)
     {
         return is_array($array) ? count(array_filter(array_keys($array), 'is_numeric')) : 0;
-    }// /->_count_numeric_items()
+    }
 
-    /*
-    */
-    function _init()
+    // /->_count_numeric_items()
+    
+    public function _init()
     {
         $this->xml_data = '';
         $this->xml_array = null;
@@ -301,9 +319,8 @@ function _init()
         $this->_stack = null;
         $this->_last_opened_tag = null;
 
-        $this->_cdata_tags = array();
-    }// /->_init()
+        $this->_cdata_tags = [];
+    }
 
+    // /->_init()
 }// /class: XMLParser
-
-?>
diff --git a/src/includes/classes/algorithms/Algorithm.php b/src/includes/classes/algorithms/Algorithm.php
index a7fccf7..f787686 100644
--- a/src/includes/classes/algorithms/Algorithm.php
+++ b/src/includes/classes/algorithms/Algorithm.php
@@ -16,374 +16,411 @@
 use WebPA\includes\classes\GroupHandler;
 use WebPA\includes\classes\ResultHandler;
 
-abstract class Algorithm {
+abstract class Algorithm
+{
+    // Private Vars
+    protected $_assessment;
 
-  // Private Vars
-  protected $_assessment;
-  protected $_grade_ordinals = array();
-  protected $_params;
+    protected $_grade_ordinals = [];
 
-  protected $_peeronly = false;
+    protected $_params;
 
-  protected $_group_grades;
-  protected $_group_members;
-  protected $_group_names;
+    protected $_peeronly = false;
 
-  protected $_form_type;
-  protected $_questions;
-  protected $_question_info;
+    protected $_group_grades;
 
-  protected $_responses;
+    protected $_group_members;
 
-  protected $_ordinal_scale;
+    protected $_group_names;
 
-  // These properties are used for checking what's actually happened in the assessment
-  // Sub-classes should not use these for their calculations
+    protected $_form_type;
 
-  protected $_actual_responses = null;
+    protected $_questions;
 
-  protected $_actual_group_submitters = array();
-  protected $_actual_submitters = array();
+    protected $_question_info;
 
-  protected $_actual_marks_awarded = null;
-  protected $_actual_marks_received = null;
+    protected $_responses;
 
-  protected $_actual_marks_awarded_by_member_question = null;
-  protected $_actual_marks_received_by_member_question = null;
+    protected $_ordinal_scale;
 
-  protected $_actual_total_marks_awarded = null;
-  protected $_actual_total_marks_received = null;
+    // These properties are used for checking what's actually happened in the assessment
+    // Sub-classes should not use these for their calculations
 
-  // These properties are used in the algorithm calculations
-  // They can be manipulated to correct scoring problems (like peer-only and poor submissions)
+    protected $_actual_responses;
 
-  protected $_calc_responses = null;
+    protected $_actual_group_submitters = [];
 
-  protected $_calc_group_submitters = array();
-  protected $_calc_submitters = array();
+    protected $_actual_submitters = [];
 
-  protected $_calc_marks_awarded = null;
-  protected $_calc_marks_received = null;
+    protected $_actual_marks_awarded;
 
-  protected $_calc_marks_awarded_by_member_question = null;
-  protected $_calc_marks_received_by_member_question = null;
+    protected $_actual_marks_received;
 
-  protected $_calc_total_marks_awarded = null;
-  protected $_calc_total_marks_received = null;
+    protected $_actual_marks_awarded_by_member_question;
 
-  // These properties contain the final outputs from the algorithm
+    protected $_actual_marks_received_by_member_question;
 
-  protected $_webpa_scores = null;          // The mutiplication factor based on relative performance
-  protected $_intermediate_grades = null;   // The intermediate grades (before penalties are applied)
-  protected $_grades = null;                // The final grades
-  protected $_penalties = null;             // Textual description of the penalties each member incurred
+    protected $_actual_total_marks_awarded;
 
+    protected $_actual_total_marks_received;
 
+    // These properties are used in the algorithm calculations
+    // They can be manipulated to correct scoring problems (like peer-only and poor submissions)
 
-  /**
-   * Constructor
-   *
-   * @return  Algorithm
-   */
-  public function __construct() {
-  }// /->Algorithm()
+    protected $_calc_responses;
 
+    protected $_calc_group_submitters = [];
 
+    protected $_calc_submitters = [];
 
-/*
-* ================================================================================
-* Public Methods
-* ================================================================================
-*/
+    protected $_calc_marks_awarded;
 
+    protected $_calc_marks_received;
 
+    protected $_calc_marks_awarded_by_member_question;
 
-  /**
-   * Calculate the student's final grades.
-   *
-   * As well as calculating grades, this method populates many of the properties
-   * available via the get methods.
-   *
-   * @return  boolean  The operation was successful.
-   */
-  abstract public function calculate();
+    protected $_calc_marks_received_by_member_question;
 
+    protected $_calc_total_marks_awarded;
 
+    protected $_calc_total_marks_received;
 
-  /**
-   * Get the final grades for every student.
-   *
-   * Output is of the form  array ( student_id => grade )
-   * The type of grade (% or A-F) depends on the marking parameters supplied.
-   *
-   * @return  mixed  An assoc-array of grades. On fail, null.
-   */
-  public function get_grades() {
-    return $this->_grades;
-  }// /->get_grades()
+    // These properties contain the final outputs from the algorithm
 
+    protected $_webpa_scores;          // The mutiplication factor based on relative performance
 
+    protected $_intermediate_grades;   // The intermediate grades (before penalties are applied)
 
-  /**
-   * Get the names of the groups involved in the assessment.
-   *
-   * Output is of the form array ( group_id => group_name )
-   *
-   * @return  mixed  An assoc-array of group names. On fail, null.
-   */
-  public function get_group_names() {
-    return $this->_group_names;
-  }// /->get_group_names()
+    protected $_grades;                // The final grades
 
+    protected $_penalties;             // Textual description of the penalties each member incurred
 
+    /**
+     * Constructor
+     *
+     * @return  Algorithm
+     */
+    public function __construct()
+    {
+    }
 
-  /**
-   * Get the names of the groups involved in the assessment.
-   *
-   * Output is of the form  array ( group_id => array ( member_id ) )
-   *
-   * @return  mixed  An assoc-array of members in each group. On fail, null.
-   */
-  public function get_group_members() {
-    return $this->_group_members;
-  }// /->get_group_members()
+    // /->Algorithm()
+
+
+
+    /*
+    * ================================================================================
+    * Public Methods
+    * ================================================================================
+    */
+
+    /**
+     * Calculate the student's final grades.
+     *
+     * As well as calculating grades, this method populates many of the properties
+     * available via the get methods.
+     *
+     * @return  boolean  The operation was successful.
+     */
+    abstract public function calculate();
+
+    /**
+     * Get the final grades for every student.
+     *
+     * Output is of the form  array ( student_id => grade )
+     * The type of grade (% or A-F) depends on the marking parameters supplied.
+     *
+     * @return  mixed  An assoc-array of grades. On fail, null.
+     */
+    public function get_grades()
+    {
+        return $this->_grades;
+    }
 
+    // /->get_grades()
+
+    /**
+     * Get the names of the groups involved in the assessment.
+     *
+     * Output is of the form array ( group_id => group_name )
+     *
+     * @return  mixed  An assoc-array of group names. On fail, null.
+     */
+    public function get_group_names()
+    {
+        return $this->_group_names;
+    }
 
+    // /->get_group_names()
+
+    /**
+     * Get the names of the groups involved in the assessment.
+     *
+     * Output is of the form  array ( group_id => array ( member_id ) )
+     *
+     * @return  mixed  An assoc-array of members in each group. On fail, null.
+     */
+    public function get_group_members()
+    {
+        return $this->_group_members;
+    }
 
-  /**
-   * Get the intermediate grades for every student.
-   *
-   * An intermediate grade is the grade a student receives before any penalties are applied.
-   * Output is of the form  array ( person_id => intermediate_grade )
-   * The type of grade (% or A-F) depends on the marking parameters supplied.
-   *
-   * @return  mixed  An assoc array of students and their grades. On fail, null.
-   */
-  public function get_intermediate_grades() {
-    return $this->_intermediate_grades;
-  }// /->get_intermediate_grades()
+    // /->get_group_members()
+
+    /**
+     * Get the intermediate grades for every student.
+     *
+     * An intermediate grade is the grade a student receives before any penalties are applied.
+     * Output is of the form  array ( person_id => intermediate_grade )
+     * The type of grade (% or A-F) depends on the marking parameters supplied.
+     *
+     * @return  mixed  An assoc array of students and their grades. On fail, null.
+     */
+    public function get_intermediate_grades()
+    {
+        return $this->_intermediate_grades;
+    }
 
+    // /->get_intermediate_grades()
 
+    public function get_marks_awarded()
+    {
+        return $this->_actual_marks_awarded;
+    }
 
-  public function get_marks_awarded() {
-    return $this->_actual_marks_awarded;
-  }// /->get_marks_awarded()
+    // /->get_marks_awarded()
 
+    public function get_marks_received()
+    {
+        return $this->_actual_marks_received;
+    }
 
+    // /->get_marks_received()
 
-  public function get_marks_received() {
-    return $this->_actual_marks_received;
-  }// /->get_marks_received()
-
-  public function get_total_marks_awarded() {
-    return $this->_actual_total_marks_awarded;
-  }// /->get_total_marks_awarded()
-
-  public function get_total_marks_received() {
-    return $this->_actual_total_marks_received;
-  }// /->get_total_marks_received()
-
-
-  /**
-   * Get the score given by one member of a group to another member for a particular question
-   *
-   * @param  integer  $group_id  The group to check.
-   * @param  integer  $member_id  The member awarding the score.
-   * @param  integer  $question_id  The question the score was for.
-   * @param  integer  $target_member_id  The member receiving the score.
-   *
-   * @return  array  The score awarded. On fail, null.
-   */
-  function get_member_response($group_id, $member_id, $question_id, $target_member_id) {
-    $score = null;
-    if (array_key_exists($group_id, $this->_actual_responses)) {
-      if (array_key_exists($question_id, $this->_actual_responses[$group_id])) {
-        if (array_key_exists($member_id, $this->_actual_responses[$group_id][$question_id])) {
-          if (array_key_exists($target_member_id, $this->_actual_responses[$group_id][$question_id][$member_id])) {
-            $score = $this->_actual_responses[$group_id][$question_id][$member_id][$target_member_id];
-          }
-        }
-      }
+    public function get_total_marks_awarded()
+    {
+        return $this->_actual_total_marks_awarded;
     }
-    return $score;
-  }// /->get_member_response()
-
-
-
-  /**
-   * Get a list of penalised students, and the amount they were penalised.
-   *
-   * Output is of the form  array ( person_id => penalty )
-   * Penalties are always numeric but may be 0.
-   * Students without a penalty are not included in the list.
-   *
-   * @return  mixed  An assoc array of students and their penalties. On fail, null.
-   */
-  public function get_penalties() {
-    return $this->_penalties;
-  }// /->get_penalties()
-
-
-
-  /**
-   * Get the questions used in the assessment.
-   *
-   * Output is of the form array ( group_id => group_name )
-   *
-   * @return  mixed  An assoc-array of question information. On fail, null.
-   */
-  public function get_questions() {
-    return $this->_question_info;
-  }// /->get_questions()
-
-
-
-  /**
-   * Get a list of students who submitted.
-   *
-   * Output is of the form  array ( person_id )
-   *
-   * @return  mixed  An assoc array of students. On fail, null.
-   */
-  public function get_submitters() {
-    return (!empty($this->_actual_submitters)) ? $this->_actual_submitters : null ;
-  }// /->get_submitters()
-
-
-
-  /**
-   * Get the WebPA scores for every student.
-   *
-   * Web-PA scores are the multiplication factors produced by analysings the scores received
-   * in the peer assessment.  The average group score is 1.0.  Scores above 1 mean above average performance,
-   * and vice-versa.
-   * Output is of the form  array ( student_id => webpa socre )
-   *
-   * @return  mixed  An assoc-array of webpa scores. On fail, null.
-   */
-  public function get_webpa_scores() {
-    return $this->_webpa_scores;
-  }// /->get_webpa_scores()
-
-
-
-  /**
-   * Set which assessment to use.
-   *
-   * @param  object  The assessment.
-   *
-   * @return  boolean  The operation was successful.
-   */
-  public function set_assessment($assessment) {
-    $this->_assessment = $assessment;
-
-    $db = $this->_assessment->get_db();
-
-    // Set peer-only status
-    $this->_peeronly = ($this->_assessment->assessment_type == 0);
-
-    // Get group overall grades information
-    $this->_group_grades = $this->_assessment->get_group_marks();
-
-
-    // Get a list of the members who took this assessment (grouped by 'group')
-    $group_members = null;
-    $group_names = null;
-
-    $group_handler = new GroupHandler();
-    $collection = $group_handler->get_collection($this->_assessment->get_collection_id());
-    $groups_iterator = $collection->get_groups_iterator();
-    if ($groups_iterator->size()>0) {
-      for($groups_iterator->reset(); $groups_iterator->is_valid(); $groups_iterator->next()) {
-        $group =& $groups_iterator->current();
-        $this->_group_names["{$group->id}"] = $group->name;
-        $this->_group_members["{$group->id}"] = $group->get_member_ids();
-      }
+
+    // /->get_total_marks_awarded()
+
+    public function get_total_marks_received()
+    {
+        return $this->_actual_total_marks_received;
     }
 
+    // /->get_total_marks_received()
+
+    /**
+     * Get the score given by one member of a group to another member for a particular question
+     *
+     * @param  integer  $group_id  The group to check.
+     * @param  integer  $member_id  The member awarding the score.
+     * @param  integer  $question_id  The question the score was for.
+     * @param  integer  $target_member_id  The member receiving the score.
+     *
+     * @return  array  The score awarded. On fail, null.
+     */
+    public function get_member_response($group_id, $member_id, $question_id, $target_member_id)
+    {
+        $score = null;
+        if (array_key_exists($group_id, $this->_actual_responses)) {
+            if (array_key_exists($question_id, $this->_actual_responses[$group_id])) {
+                if (array_key_exists($member_id, $this->_actual_responses[$group_id][$question_id])) {
+                    if (array_key_exists($target_member_id, $this->_actual_responses[$group_id][$question_id][$member_id])) {
+                        $score = $this->_actual_responses[$group_id][$question_id][$member_id][$target_member_id];
+                    }
+                }
+            }
+        }
+        return $score;
+    }
 
-    // Get the number of questions used in this assessment, and create an array of that size
-    $form = $this->_assessment->get_form();
+    // /->get_member_response()
+
+    /**
+     * Get a list of penalised students, and the amount they were penalised.
+     *
+     * Output is of the form  array ( person_id => penalty )
+     * Penalties are always numeric but may be 0.
+     * Students without a penalty are not included in the list.
+     *
+     * @return  mixed  An assoc array of students and their penalties. On fail, null.
+     */
+    public function get_penalties()
+    {
+        return $this->_penalties;
+    }
 
-    $this->_form_type = ($form->type=='split100') ? 'split100' : 'likert' ;
+    // /->get_penalties()
+
+    /**
+     * Get the questions used in the assessment.
+     *
+     * Output is of the form array ( group_id => group_name )
+     *
+     * @return  mixed  An assoc-array of question information. On fail, null.
+     */
+    public function get_questions()
+    {
+        return $this->_question_info;
+    }
 
-    $question_count = (int) $form->get_question_count();
+    // /->get_questions()
+
+    /**
+     * Get a list of students who submitted.
+     *
+     * Output is of the form  array ( person_id )
+     *
+     * @return  mixed  An assoc array of students. On fail, null.
+     */
+    public function get_submitters()
+    {
+        return (!empty($this->_actual_submitters)) ? $this->_actual_submitters : null ;
+    }
 
-    $this->_questions = ($question_count>0) ? range(0, $question_count-1) : array();
-    foreach($this->_questions as $i => $question_id) {
-      $this->_question_info[$question_id] = $form->get_question($question_id);
+    // /->get_submitters()
+
+    /**
+     * Get the WebPA scores for every student.
+     *
+     * Web-PA scores are the multiplication factors produced by analysings the scores received
+     * in the peer assessment.  The average group score is 1.0.  Scores above 1 mean above average performance,
+     * and vice-versa.
+     * Output is of the form  array ( student_id => webpa socre )
+     *
+     * @return  mixed  An assoc-array of webpa scores. On fail, null.
+     */
+    public function get_webpa_scores()
+    {
+        return $this->_webpa_scores;
     }
 
-    // Get the student submissions for this assessment
-    $result_handler = new ResultHandler($db);
-    $result_handler->set_assessment($this->_assessment);
+    // /->get_webpa_scores()
+
+    /**
+     * Set which assessment to use.
+     *
+     * @param  object  The assessment.
+     *
+     * @return  boolean  The operation was successful.
+     */
+    public function set_assessment($assessment)
+    {
+        $this->_assessment = $assessment;
 
-    $this->_responses = $result_handler->get_responses();
+        $db = $this->_assessment->get_db();
 
-    return true;
-  }// /->set_assessment()
+        // Set peer-only status
+        $this->_peeronly = ($this->_assessment->assessment_type == 0);
 
+        // Get group overall grades information
+        $this->_group_grades = $this->_assessment->get_group_marks();
 
 
-  /**
-   * Set grade letter ordinal scales.
-   *
-   * @param  array  $ordinal_scale.
-   *
-   * @return  boolean  The operation was successful.
-   */
-  public function set_grade_ordinals($ordinal_scale) {
-    $this->_ordinal_scale = $ordinal_scale;
-    return true;
-  }// /->set_grade_ordinals()
+        // Get a list of the members who took this assessment (grouped by 'group')
+        $group_members = null;
+        $group_names = null;
 
+        $group_handler = new GroupHandler();
+        $collection = $group_handler->get_collection($this->_assessment->get_collection_id());
+        $groups_iterator = $collection->get_groups_iterator();
+        if ($groups_iterator->size()>0) {
+            for ($groups_iterator->reset(); $groups_iterator->is_valid(); $groups_iterator->next()) {
+                $group =& $groups_iterator->current();
+                $this->_group_names["{$group->id}"] = $group->name;
+                $this->_group_members["{$group->id}"] = $group->get_member_ids();
+            }
+        }
 
 
-  /**
-   * Set marking parameters.
-   *
-   * @param  array  Assoc-array of marking parameters for this report.
-   *
-   * @return  boolean  The operation was successful.
-   */
-  public function set_marking_params($marking_params) {
-    $this->_params = $marking_params;
-    return true;
-  }// /->set_marking_params()
+        // Get the number of questions used in this assessment, and create an array of that size
+        $form = $this->_assessment->get_form();
 
+        $this->_form_type = ($form->type=='split100') ? 'split100' : 'likert' ;
 
+        $question_count = (int) $form->get_question_count();
 
-/*
-* ================================================================================
-* Private Methods
-* ================================================================================
-*/
+        $this->_questions = ($question_count>0) ? range(0, $question_count-1) : [];
+        foreach ($this->_questions as $i => $question_id) {
+            $this->_question_info[$question_id] = $form->get_question($question_id);
+        }
 
+        // Get the student submissions for this assessment
+        $result_handler = new ResultHandler($db);
+        $result_handler->set_assessment($this->_assessment);
 
+        $this->_responses = $result_handler->get_responses();
 
-  /**
-   * Apply any criterion weightings to the students' fractional marks.
-   *
-   * @return  boolean  The operation was successful.
-   */
-  protected function _applyCriterionWeightings() {
+        return true;
+    }
 
-    // @todo : criterion weightings should make an appearnce in a future version.
+    // /->set_assessment()
+
+    /**
+     * Set grade letter ordinal scales.
+     *
+     * @param  array  $ordinal_scale.
+     *
+     * @return  boolean  The operation was successful.
+     */
+    public function set_grade_ordinals($ordinal_scale)
+    {
+        $this->_ordinal_scale = $ordinal_scale;
+        return true;
+    }
+
+    // /->set_grade_ordinals()
+
+    /**
+     * Set marking parameters.
+     *
+     * @param  array  Assoc-array of marking parameters for this report.
+     *
+     * @return  boolean  The operation was successful.
+     */
+    public function set_marking_params($marking_params)
+    {
+        $this->_params = $marking_params;
+        return true;
+    }
+
+    // /->set_marking_params()
 
-    return true;
-  }// /->_applyCriterionWeightings()
 
 
+    /*
+    * ================================================================================
+    * Private Methods
+    * ================================================================================
+    */
 
-  /**
-   * Convert the current grades to the required display format.
-   *
-   * @return  boolean  The operation was successful.
-   */
-  protected function _applyGradingStyle() {
-    $grade_mode = ($this->_params['grading']=='grade_af') ? 'grade_af' : 'numeric' ;
+    /**
+     * Apply any criterion weightings to the students' fractional marks.
+     *
+     * @return  boolean  The operation was successful.
+     */
+    protected function _applyCriterionWeightings()
+    {
 
-    switch($grade_mode) {
+    // @todo : criterion weightings should make an appearnce in a future version.
+
+        return true;
+    }
+
+    // /->_applyCriterionWeightings()
+
+    /**
+     * Convert the current grades to the required display format.
+     *
+     * @return  boolean  The operation was successful.
+     */
+    protected function _applyGradingStyle()
+    {
+        $grade_mode = ($this->_params['grading']=='grade_af') ? 'grade_af' : 'numeric' ;
+
+        switch ($grade_mode) {
       // ----------------------------------------
       // Grades should be Alphabetic (A-F and the rest)
       case 'grade_af':
@@ -392,37 +429,39 @@ protected function _applyGradingStyle() {
         $top_grade = $grade_letters[0];
 
         if ($this->_intermediate_grades) {
-          foreach($this->_intermediate_grades as $id => $grade) {
-            $grade_set = false;
-            foreach($this->_ordinal_scale as $grade_letter => $grade_numeric) {
-              if ($grade>$grade_numeric) {
-                break;
-              } else {
-                $this->_intermediate_grades[$id] = $grade_letter;
-                $grade_set = true;
-              }
+            foreach ($this->_intermediate_grades as $id => $grade) {
+                $grade_set = false;
+                foreach ($this->_ordinal_scale as $grade_letter => $grade_numeric) {
+                    if ($grade>$grade_numeric) {
+                        break;
+                    }
+                    $this->_intermediate_grades[$id] = $grade_letter;
+                    $grade_set = true;
+                }
+
+                // If we didn't set at least one grade-letter, then the student must have the top grade
+                if (!$grade_set) {
+                    $this->_intermediate_grades[$id] = $top_grade;
+                }
             }
-
-            // If we didn't set at least one grade-letter, then the student must have the top grade
-            if (!$grade_set) { $this->_intermediate_grades[$id] = $top_grade; }
-          }
         }
 
         if ($this->_grades) {
-          foreach($this->_grades as $id => $grade) {
-            $grade_set = false;
-            foreach($this->_ordinal_scale as $grade_letter => $grade_numeric) {
-              if ($grade>$grade_numeric) {
-                break;
-              } else {
-                $this->_grades[$id] = $grade_letter;
-                $grade_set = true;
-              }
+            foreach ($this->_grades as $id => $grade) {
+                $grade_set = false;
+                foreach ($this->_ordinal_scale as $grade_letter => $grade_numeric) {
+                    if ($grade>$grade_numeric) {
+                        break;
+                    }
+                    $this->_grades[$id] = $grade_letter;
+                    $grade_set = true;
+                }
+
+                // If we didn't set at least one grade-letter, then the student must have the top grade
+                if (!$grade_set) {
+                    $this->_grades[$id] = $top_grade;
+                }
             }
-
-            // If we didn't set at least one grade-letter, then the student must have the top grade
-            if (!$grade_set) { $this->_grades[$id] = $top_grade; }
-          }
         }
         break;
       // ----------------------------------------
@@ -430,229 +469,224 @@ protected function _applyGradingStyle() {
       case 'numeric':
       default:
         if ($this->_intermediate_grades) {
-          foreach($this->_intermediate_grades as $id => $grade) {
-            $this->_intermediate_grades[$id] = sprintf(APP__REPORT_DECIMALS, $grade) .'%';
-          }
+            foreach ($this->_intermediate_grades as $id => $grade) {
+                $this->_intermediate_grades[$id] = sprintf(APP__REPORT_DECIMALS, $grade) .'%';
+            }
         }
 
         if ($this->_grades) {
-          foreach($this->_grades as $id => $grade) {
-            $this->_grades[$id] = sprintf(APP__REPORT_DECIMALS, $grade) .'%';
-          }
+            foreach ($this->_grades as $id => $grade) {
+                $this->_grades[$id] = sprintf(APP__REPORT_DECIMALS, $grade) .'%';
+            }
         }
       break;
     }// /switch()
 
-    return true;
-  }// /->__applyGradingStyle()
-
-
-
-  /**
-   * Apply any applicable penalties to the final grades
-   *
-   * @return  boolean  The operation was successful.
-   */
-  protected function _applyPenalties() {
-    if ($this->_grades) {
+        return true;
+    }
 
-      if (is_null($this->_actual_submitters)) {
-        $this->_actual_submitters = array();
-      }
+    // /->__applyGradingStyle()
 
-      // If the penalty is a percentage..
-      if ($this->_params['penalty_type']=='%') {
+    /**
+     * Apply any applicable penalties to the final grades
+     *
+     * @return  boolean  The operation was successful.
+     */
+    protected function _applyPenalties()
+    {
+        if ($this->_grades) {
+            if (is_null($this->_actual_submitters)) {
+                $this->_actual_submitters = [];
+            }
 
-        $penalty = ($this->_params['penalty']==0) ? 1 : 1-($this->_params['penalty']/100) ;
+            // If the penalty is a percentage..
+            if ($this->_params['penalty_type']=='%') {
+                $penalty = ($this->_params['penalty']==0) ? 1 : 1-($this->_params['penalty']/100) ;
 
-        foreach($this->_grades as $person_id => $grade) {
-          // If the person did not submit, penalise them
-          if (!in_array($person_id, $this->_actual_submitters)) {
-            $this->_penalties[$person_id] = ($this->_params['penalty']==0) ? 'no penalty' : "-{$this->_params['penalty']}%" ;
+                foreach ($this->_grades as $person_id => $grade) {
+                    // If the person did not submit, penalise them
+                    if (!in_array($person_id, $this->_actual_submitters)) {
+                        $this->_penalties[$person_id] = ($this->_params['penalty']==0) ? 'no penalty' : "-{$this->_params['penalty']}%" ;
 
-            // Multiply the grade by the penalty
-            $final_grade = $grade * $penalty;
+                        // Multiply the grade by the penalty
+                        $final_grade = $grade * $penalty;
 
-            if ($final_grade<0) { $final_grade = 0; }
-            elseif ($final_grade>100) { $final_grade = 100; }
+                        if ($final_grade<0) {
+                            $final_grade = 0;
+                        } elseif ($final_grade>100) {
+                            $final_grade = 100;
+                        }
 
-            // Update the final grade
-            $this->_grades[$person_id] = $final_grade;
-          }
-        }// /foreach(grade)
-      } else {   // Else.. Penalty is percentage-points
+                        // Update the final grade
+                        $this->_grades[$person_id] = $final_grade;
+                    }
+                }// /foreach(grade)
+            } else {   // Else.. Penalty is percentage-points
 
         $penalty = $this->_params['penalty'];
 
-        foreach($this->_grades as $person_id => $grade) {
-          // If the person did not submit, penalise them
-          if (!in_array($person_id, $this->_actual_submitters)) {
+                foreach ($this->_grades as $person_id => $grade) {
+                    // If the person did not submit, penalise them
+                    if (!in_array($person_id, $this->_actual_submitters)) {
+                        $this->_penalties[$person_id] = ($this->_params['penalty']==0) ? 'no penalty' : "-{$this->_params['penalty']} pp" ;
 
-            $this->_penalties[$person_id] = ($this->_params['penalty']==0) ? 'no penalty' : "-{$this->_params['penalty']} pp" ;
+                        // Subtract the penalty from the grade
+                        $final_grade = $grade - $penalty;
 
-            // Subtract the penalty from the grade
-            $final_grade = $grade - $penalty;
+                        if ($final_grade<0) {
+                            $final_grade = 0;
+                        } elseif ($final_grade>100) {
+                            $final_grade = 100;
+                        }
 
-            if ($final_grade<0) { $final_grade = 0; }
-            elseif ($final_grade>100) { $final_grade = 100; }
+                        // Update the final grade
+                        $this->_grades[$person_id] = $final_grade;
+                    }
+                }// /foreach(grade)
+            }
+        }// /if(grades)
 
-            // Update the final grade
-            $this->_grades[$person_id] = $final_grade;
-          }
-        }// /foreach(grade)
-      }
-    }// /if(grades)
+        if (empty($this->_actual_submitters)) {
+            $this->_actual_submitters = null;
+        }
 
-    if (empty($this->_actual_submitters)) {
-      $this->_actual_submitters = null;
+        return true;
     }
 
-    return true;
-  }// /->_applyPenalties()
-
+    // /->_applyPenalties()
 
-
-  /**
-   * Initialise some of the algorithm's properties based prior to calculating the grades.
-   *
-   * Places the real student response information in the ->_actual_?? properties.
-   * Response information for the algorithm calculations is placed in the ->_calc_?? properties.
-   * ->_calc_?? properties can/will be altered by specific algorithms to provide proper grading.
-   * For example, see ->_preparePeerOnly()
-   *
-   * @return  boolean  The operation was successful.
-   */
-  protected function _initialise() {
+    /**
+     * Initialise some of the algorithm's properties based prior to calculating the grades.
+     *
+     * Places the real student response information in the ->_actual_?? properties.
+     * Response information for the algorithm calculations is placed in the ->_calc_?? properties.
+     * ->_calc_?? properties can/will be altered by specific algorithms to provide proper grading.
+     * For example, see ->_preparePeerOnly()
+     *
+     * @return  boolean  The operation was successful.
+     */
+    protected function _initialise()
+    {
 
 
     // Initial marks for each question. Saves looping through questions every time when initialising scores.
-    $initial_marks_per_question = null;
-    foreach($this->_questions as $i => $question_id) {
-      $initial_marks_per_question[$question_id] = null;   // A null means no score
-    }
+        $initial_marks_per_question = null;
+        foreach ($this->_questions as $i => $question_id) {
+            $initial_marks_per_question[$question_id] = null;   // A null means no score
+        }
 
 
-    $this->_actual_submitters = array();
-    $this->_actual_group_submitters = array();
+        $this->_actual_submitters = [];
+        $this->_actual_group_submitters = [];
 
-    $this->_calc_submitters = array();
-    $this->_calc_group_submitters = array();
+        $this->_calc_submitters = [];
+        $this->_calc_group_submitters = [];
 
 
-    // Initialise awarded/received scores
-    foreach($this->_group_names as $group_id => $group_name) {
+        // Initialise awarded/received scores
+        foreach ($this->_group_names as $group_id => $group_name) {
 
       // Initial marks from each student to each student.
-      // This array is built in the following loop, so it is specific to each group.
-      $initial_students_marks = array();
+            // This array is built in the following loop, so it is specific to each group.
+            $initial_students_marks = [];
 
-      foreach($this->_group_members[$group_id] as $i => $member_id) {
+            foreach ($this->_group_members[$group_id] as $i => $member_id) {
+                $this->_actual_marks_awarded_by_member_question[$member_id] = $initial_marks_per_question;
+                $this->_actual_marks_received_by_member_question[$member_id] = $initial_marks_per_question;
 
-        $this->_actual_marks_awarded_by_member_question[$member_id] = $initial_marks_per_question;
-        $this->_actual_marks_received_by_member_question[$member_id] = $initial_marks_per_question;
+                $this->_calc_marks_awarded_by_member_question[$member_id] = $initial_marks_per_question;
+                $this->_calc_marks_received_by_member_question[$member_id] = $initial_marks_per_question;
 
-        $this->_calc_marks_awarded_by_member_question[$member_id] = $initial_marks_per_question;
-        $this->_calc_marks_received_by_member_question[$member_id] = $initial_marks_per_question;
 
+                foreach ($this->_group_members[$group_id] as $j => $marked_user_id) {
+                    $initial_students_marks[$member_id][$marked_user_id] = null;
 
-        foreach($this->_group_members[$group_id] as $j => $marked_user_id) {
+                    $this->_actual_marks_awarded[$member_id][$marked_user_id] = 0;
+                    $this->_actual_marks_received[$marked_user_id][$member_id] = 0;
 
-          $initial_students_marks[$member_id][$marked_user_id] = null;
+                    $this->_calc_marks_awarded[$member_id][$marked_user_id] = 0;
+                    $this->_calc_marks_received[$marked_user_id][$member_id] = 0;
+                }
 
-          $this->_actual_marks_awarded[$member_id][$marked_user_id] = 0;
-          $this->_actual_marks_received[$marked_user_id][$member_id] = 0;
+                $this->_actual_total_marks_awarded[$member_id] = 0;
+                $this->_actual_total_marks_received[$member_id] = 0;
 
-          $this->_calc_marks_awarded[$member_id][$marked_user_id] = 0;
-          $this->_calc_marks_received[$marked_user_id][$member_id] = 0;
-        }
+                $this->_calc_total_marks_awarded[$member_id] = 0;
+                $this->_calc_total_marks_received[$member_id] = 0;
+            }
+
+            // Set the initial marks for this group, for each question
+            foreach ($this->_questions as $i => $question_id) {
+                $this->_actual_responses[$group_id][$question_id] = $initial_students_marks;
+            }
+        }// /foreach(group)
 
-        $this->_actual_total_marks_awarded[$member_id] = 0;
-        $this->_actual_total_marks_received[$member_id] = 0;
 
-        $this->_calc_total_marks_awarded[$member_id] = 0;
-        $this->_calc_total_marks_received[$member_id] = 0;
-      }
 
-      // Set the initial marks for this group, for each question
-      foreach($this->_questions as $i => $question_id) {
-        $this->_actual_responses[$group_id][$question_id] = $initial_students_marks;
-      }
+        // Process all the student responses
+        // Set the correct values for the actual marks awarded, received, etc
+        if (!empty($this->_responses)) {
+            foreach ($this->_responses as $i => $response) {
+                $group_id = $response['group_id'];
+                $member_id = $response['user_id'];
+                $marked_user_id = $response['marked_user_id'];
+                $question_id = $response['question_id'];
+                $score = (float) $response['score'];
 
-    }// /foreach(group)
+                // Record the fact this member submitted
+                if (!in_array($member_id, $this->_actual_submitters)) {
+                    $this->_actual_submitters[] = $member_id;
+                    $this->_actual_group_submitters[$group_id][] = $member_id;
+                }
 
+                // Re-factor the responses into more usable forms
+                $this->_actual_responses[$group_id][$question_id][$member_id][$marked_user_id] = $score;
 
+                // Keep a running total of the marks
 
-    // Process all the student responses
-    // Set the correct values for the actual marks awarded, received, etc
-    if(!empty($this->_responses)){
-      foreach($this->_responses as $i => $response) {
+                $this->_actual_marks_awarded[$member_id][$marked_user_id] += $score;
+                $this->_actual_marks_received[$marked_user_id][$member_id] += $score;
 
-        $group_id = $response['group_id'];
-        $member_id = $response['user_id'];
-        $marked_user_id = $response['marked_user_id'];
-        $question_id = $response['question_id'];
-        $score = (float) $response['score'];
+                $this->_actual_marks_awarded_by_member_question[$member_id][$question_id] += $score;
+                $this->_actual_marks_received_by_member_question[$marked_user_id][$question_id] += $score;
 
-        // Record the fact this member submitted
-        if (!in_array($member_id, $this->_actual_submitters)) {
-          $this->_actual_submitters[] = $member_id;
-          $this->_actual_group_submitters[$group_id][] = $member_id;
+                $this->_actual_total_marks_awarded[$member_id] += $score;
+                $this->_actual_total_marks_received[$marked_user_id] += $score;
+            }
         }
 
-        // Re-factor the responses into more usable forms
-        $this->_actual_responses[$group_id][$question_id][$member_id][$marked_user_id] = $score;
-
-        // Keep a running total of the marks
 
-        $this->_actual_marks_awarded[$member_id][$marked_user_id] += $score;
-        $this->_actual_marks_received[$marked_user_id][$member_id] += $score;
+        // Now the actual responses have been recorded, we can generate the appropriate ->_calc_?? properties
 
-        $this->_actual_marks_awarded_by_member_question[$member_id][$question_id] += $score;
-        $this->_actual_marks_received_by_member_question[$marked_user_id][$question_id] += $score;
+        // Get the peer-only or self-&-peer marks ready for the algorithm
 
-        $this->_actual_total_marks_awarded[$member_id] += $score;
-        $this->_actual_total_marks_received[$marked_user_id] += $score;
-      }
-    }
+        if ($this->_peeronly) {
+            $this->_preparePeerOnly();
+        } else {
+            $this->_prepareSelfPeer();
+        }
 
 
-    // Now the actual responses have been recorded, we can generate the appropriate ->_calc_?? properties
+        // Remove the original responses.
+        $this->_responses = null;
 
-    // Get the peer-only or self-&-peer marks ready for the algorithm
 
-    if ($this->_peeronly) {
-      $this->_preparePeerOnly();
-    } else {
-      $this->_prepareSelfPeer();
+        return true;
     }
 
-
-    // Remove the original responses.
-    $this->_responses = null;
-
-
-    return true;
-  }// /->_initialise()
-
-
-
-  /**
-   * Prepare the ->_calc_?? properties, ready for the algorithm to process a peer-only assessment.
-   *
-   * @return  boolean  The operation was successful.
-   */
-  abstract protected function _preparePeerOnly();
-
-
-
-  /**
-   * Prepare the ->_calc_?? properties, ready for the algorithm to process a self-&-peer assessment.
-   *
-   * @return  boolean  The operation was successful.
-   */
-  abstract protected function _prepareSelfPeer();
-
-
-
+    // /->_initialise()
+
+    /**
+     * Prepare the ->_calc_?? properties, ready for the algorithm to process a peer-only assessment.
+     *
+     * @return  boolean  The operation was successful.
+     */
+    abstract protected function _preparePeerOnly();
+
+    /**
+     * Prepare the ->_calc_?? properties, ready for the algorithm to process a self-&-peer assessment.
+     *
+     * @return  boolean  The operation was successful.
+     */
+    abstract protected function _prepareSelfPeer();
 }// /class
-?>
diff --git a/src/includes/classes/algorithms/PetsAlgorithm.php b/src/includes/classes/algorithms/PetsAlgorithm.php
index 4d8c8d3..5388d9a 100644
--- a/src/includes/classes/algorithms/PetsAlgorithm.php
+++ b/src/includes/classes/algorithms/PetsAlgorithm.php
@@ -16,325 +16,318 @@
 // Until we have conducted a full investigation and nailed down what's happening
 // this algorithm is disabled.
 
-class PetsAlgorithm extends Algorithm {
-
-  // Public Properties
-  protected $_group_split100 = null;
-  protected $_group_average_per_question = null;
-
-  /**
-   * Constructor
-   *
-   * @return  object  A new instance of this class.
-   */
-  public function __construct() {
-  }// /->__construct()
-
-/*
-* ================================================================================
-* Public Methods
-* ================================================================================
-*/
-
-  /**
-   * Calculate the student's final grades.
-   *
-   * As well as calculating grades, this method populates many of the properties
-   * available via the get methods.
-   *
-   * @return  boolean  The operation was successful.
-   */
-  public function calculate() {
+class PetsAlgorithm extends Algorithm
+{
+    // Public Properties
+    protected $_group_split100;
+
+    protected $_group_average_per_question;
+
+    /**
+     * Constructor
+     *
+     * @return  object  A new instance of this class.
+     */
+    public function __construct()
+    {
+    }
+
+    // /->__construct()
+
+    /*
+    * ================================================================================
+    * Public Methods
+    * ================================================================================
+    */
+
+    /**
+     * Calculate the student's final grades.
+     *
+     * As well as calculating grades, this method populates many of the properties
+     * available via the get methods.
+     *
+     * @return  boolean  The operation was successful.
+     */
+    public function calculate()
+    {
 
     /* The code below has been written to try to show the individual, algorithmic steps clearly.
      * You could probably improve the efficiency by combining loops, etc, but then the steps
      * are more difficult to follow.
      */
 
-    /* (1)
-     * Initialise the algorithm data and pre-fill most of the properties of this class.
-     * Gets the total number of marks each member awarded, and to whom, etc.
-     */
+        /* (1)
+         * Initialise the algorithm data and pre-fill most of the properties of this class.
+         * Gets the total number of marks each member awarded, and to whom, etc.
+         */
 
-    $this->_initialise();
+        $this->_initialise();
 
-    // Take each group in turn
-    foreach($this->_group_grades as $group_id => $group_mark) {
+        // Take each group in turn
+        foreach ($this->_group_grades as $group_id => $group_mark) {
 
       /* (2)
        * Get the multiplication factor we need to calculate the WebPA scores
        * factor = num-members-total / num-members-submitted
        */
 
-      $num_members = ( (is_array($this->_group_members)) && (array_key_exists($group_id, $this->_group_members)) ) ? count($this->_group_members[$group_id]) : 0 ;
+            $num_members = ((is_array($this->_group_members)) && (array_key_exists($group_id, $this->_group_members))) ? count($this->_group_members[$group_id]) : 0 ;
 
-      $num_submitted = ( (is_array($this->_calc_group_submitters)) && (array_key_exists($group_id, $this->_calc_group_submitters)) ) ? count($this->_calc_group_submitters[$group_id]) : 0 ;
+            $num_submitted = ((is_array($this->_calc_group_submitters)) && (array_key_exists($group_id, $this->_calc_group_submitters))) ? count($this->_calc_group_submitters[$group_id]) : 0 ;
 
-      $multi_factor = ($num_submitted>0) ? ($num_members / $num_submitted) : 1 ;
+            $multi_factor = ($num_submitted>0) ? ($num_members / $num_submitted) : 1 ;
 
-      $pa_group_mark = ($this->_params['weighting']/100) * $group_mark;
-      $nonpa_group_mark = ( (100-$this->_params['weighting']) /100 ) * $group_mark;
+            $pa_group_mark = ($this->_params['weighting']/100) * $group_mark;
+            $nonpa_group_mark = ((100-$this->_params['weighting']) /100) * $group_mark;
 
-      if (array_key_exists($group_id, $this->_group_members)) {
-        $q_count = count($this->_questions);
+            if (array_key_exists($group_id, $this->_group_members)) {
+                $q_count = count($this->_questions);
 
-        foreach($this->_group_members[$group_id] as $i => $member_id) {
+                foreach ($this->_group_members[$group_id] as $i => $member_id) {
+                    $total_score = $this->_calc_total_marks_received[$member_id];
 
-          $total_score = $this->_calc_total_marks_received[$member_id];
+                    /* (3)
+                     * Get the WebPA score = (total received by a member / average total score if all students equal ) * multiplication-factor
+                     */
 
-          /* (3)
-           * Get the WebPA score = (total received by a member / average total score if all students equal ) * multiplication-factor
-           */
+                    $avg_total = $this->_group_split100[$group_id] * $q_count;
 
-          $avg_total = $this->_group_split100[$group_id] * $q_count;
+                    $this->_webpa_scores[$member_id] = ($total_score / $avg_total) * $multi_factor;
 
-          $this->_webpa_scores[$member_id] = ( $total_score / $avg_total) * $multi_factor;
+                    /* (4)
+                     * Get the member's intermediate grade = WebPA score * weighted-group-mark   (does not include penalties)
+                     */
 
-          /* (4)
-           * Get the member's intermediate grade = WebPA score * weighted-group-mark   (does not include penalties)
-           */
+                    if (is_array($this->_calc_group_submitters[$group_id])) {
+                        $intermediate_grade = (($this->_webpa_scores[$member_id] * $pa_group_mark) + $nonpa_group_mark);
+                    } else {
+                        $intermediate_grade = $pa_group_mark + $nonpa_group_mark;
+                    }
 
-          if (is_array($this->_calc_group_submitters[$group_id])) {
-            $intermediate_grade = (($this->_webpa_scores[$member_id] * $pa_group_mark) + $nonpa_group_mark);
-          } else {
-            $intermediate_grade = $pa_group_mark + $nonpa_group_mark;
-          }
+                    if ($intermediate_grade<0) {
+                        $intermediate_grade = 0;
+                    } elseif ($intermediate_grade>100) {
+                        $intermediate_grade = 100;
+                    }
 
-          if ($intermediate_grade<0) {
-            $intermediate_grade = 0;
-          } else if ($intermediate_grade>100) {
-            $intermediate_grade = 100;
-          }
+                    // Intermediate grades are whatever the algorithm thought the grade should be (before penalties)
+                    $this->_intermediate_grades[$member_id] = $intermediate_grade;
 
-          // Intermediate grades are whatever the algorithm thought the grade should be (before penalties)
-          $this->_intermediate_grades[$member_id] = $intermediate_grade;
+                    /* (5)
+                     * Get the member's actual grade
+                     *
+                     * At this point, final grades are the same as intermediate grades (penalties are applied at the end)
+                     */
 
-          /* (5)
-           * Get the member's actual grade
-           *
-           * At this point, final grades are the same as intermediate grades (penalties are applied at the end)
-           */
+                    $this->_grades[$member_id] = $intermediate_grade;
+                }// /foreach(member)
+            }// /if(are members)
+        }// /foreach(group)
 
-          $this->_grades[$member_id] = $intermediate_grade;
+        /* (6)
+         * Apply any penalties
+         */
+        $this->_applyPenalties();
 
-        }// /foreach(member)
+        /*(9)
+         * Make sure the grades conform to the requested grading style (% or A-F)
+         */
+        $this->_applyGradingStyle();
 
-      }// /if(are members)
+        return true;
+    }
 
-    }// /foreach(group)
+    // /->calculate()
 
-    /* (6)
-     * Apply any penalties
-     */
-    $this->_applyPenalties();
+    /*
+    * ================================================================================
+    * Private Methods
+    * ================================================================================
+    */
 
-    /*(9)
-     * Make sure the grades conform to the requested grading style (% or A-F)
+    /**
+     * Convert the responses from likert-scale types to split100 types.
+     *
+     * @return  boolean  The operation was successful.
      */
-    $this->_applyGradingStyle();
-
-    return true;
-  }// /->calculate()
-
-/*
-* ================================================================================
-* Private Methods
-* ================================================================================
-*/
-
-  /**
-   * Convert the responses from likert-scale types to split100 types.
-   *
-   * @return  boolean  The operation was successful.
-   */
-  protected function _convertFromLikert() {
+    protected function _convertFromLikert()
+    {
 
     // If the form was using likert criteria questions, convert them to split100 style.
-    // Convert the ->_calc_responses to a likert scale
-    if ($this->_form_type=='likert') {
+        // Convert the ->_calc_responses to a likert scale
+        if ($this->_form_type=='likert') {
 
       // The form-type was likert, and we need to convert the scores accordingly.
-      // Each split100 score = (group-average-total / total-marks-awarded-for-question-by-student) * likert-score
-
-      foreach ($this->_responses as $i => $response) {
-        $group_id = $response['group_id'];
-        $member_id = $response['user_id'];
-        $marked_user_id = $response['marked_user_id'];
-        $question_id = $response['question_id'];
-        $likert_score = (float) $response['score'];
+            // Each split100 score = (group-average-total / total-marks-awarded-for-question-by-student) * likert-score
 
-        // Calculate Split100 score from Likert score
-        $total_awarded = $this->_actual_marks_awarded_by_member_question[$member_id][$question_id];
+            foreach ($this->_responses as $i => $response) {
+                $group_id = $response['group_id'];
+                $member_id = $response['user_id'];
+                $marked_user_id = $response['marked_user_id'];
+                $question_id = $response['question_id'];
+                $likert_score = (float) $response['score'];
 
-        $proportional_score = ( $likert_score / $total_awarded );
+                // Calculate Split100 score from Likert score
+                $total_awarded = $this->_actual_marks_awarded_by_member_question[$member_id][$question_id];
 
-        $score =  $proportional_score * $this->_group_split100[$group_id];
+                $proportional_score = ($likert_score / $total_awarded);
 
-        // Ensure future calculations use the converted score
-        $this->_calc_responses[$group_id][$question_id][$member_id][$marked_user_id] = $score;
+                $score =  $proportional_score * $this->_group_split100[$group_id];
 
-      }// /foreach(response)
+                // Ensure future calculations use the converted score
+                $this->_calc_responses[$group_id][$question_id][$member_id][$marked_user_id] = $score;
+            }// /foreach(response)
+        }// /if(likert questions)
 
-    }// /if(likert questions)
+        return true;
+    }
 
-    return true;
-  }// ->_convertFromLikert()
+    // ->_convertFromLikert()
 
-  /**
-   * Prepare the ->_calc_?? properties, ready for the algorithm to process a peer-only assessment.
-   *
-   * @return  boolean  The operation was successful.
-   */
-  protected function _preparePeerOnly() {
+    /**
+     * Prepare the ->_calc_?? properties, ready for the algorithm to process a peer-only assessment.
+     *
+     * @return  boolean  The operation was successful.
+     */
+    protected function _preparePeerOnly()
+    {
 
     // Get the number of marks available in each question.
-    foreach ($this->_group_names as $group_id => $group_name) {
-      $member_count = count($this->_group_members[$group_id]) - 1;
-      $this->_group_split100[$group_id] = (100-(100 % $member_count));
-      $this->_group_average_per_question[$group_id] = $this->_group_split100[$group_id] / $member_count;
-    }
+        foreach ($this->_group_names as $group_id => $group_name) {
+            $member_count = count($this->_group_members[$group_id]) - 1;
+            $this->_group_split100[$group_id] = (100-(100 % $member_count));
+            $this->_group_average_per_question[$group_id] = $this->_group_split100[$group_id] / $member_count;
+        }
 
-    // Convert likert marks to split100 marks (if required)
-    $this->_convertFromLikert();
+        // Convert likert marks to split100 marks (if required)
+        $this->_convertFromLikert();
 
-    // Process all the student responses
-    // Set the correct values for the actual marks awarded, received, etc
+        // Process all the student responses
+        // Set the correct values for the actual marks awarded, received, etc
 
-    foreach ($this->_group_grades as $group_id => $group_mark) {
+        foreach ($this->_group_grades as $group_id => $group_mark) {
 
       // The score every member receives if their performance is equal
-      $avg_score = $this->_group_average_per_question[$group_id];
+            $avg_score = $this->_group_average_per_question[$group_id];
 
-      $num_members = count($this->_group_members[$group_id]);
+            $num_members = count($this->_group_members[$group_id]);
 
-      foreach ($this->_group_members[$group_id] as $i => $member_id) {
+            foreach ($this->_group_members[$group_id] as $i => $member_id) {
 
         // For the calculations, record everyone as submitting regardless of whether they did or not
-        $this->_calc_submitters[] = $member_id;
-        $this->_calc_group_submitters[$group_id][] = $member_id;
-
-        foreach ($this->_questions as $i => $question_id) {
+                $this->_calc_submitters[] = $member_id;
+                $this->_calc_group_submitters[$group_id][] = $member_id;
 
-          foreach ($this->_group_members[$group_id] as $k => $marked_user_id) {
-
-            if ($member_id!=$marked_user_id) {
+                foreach ($this->_questions as $i => $question_id) {
+                    foreach ($this->_group_members[$group_id] as $k => $marked_user_id) {
+                        if ($member_id!=$marked_user_id) {
 
               // If the student did not submit..
-              if (!in_array($member_id, $this->_actual_submitters)) {
+                            if (!in_array($member_id, $this->_actual_submitters)) {
 
                 // Fake the response using the avg score / question
-                $score = $avg_score;
-                $this->_calc_responses[$group_id][$question_id][$member_id][$marked_user_id] = $score;
-
-              } else {
+                                $score = $avg_score;
+                                $this->_calc_responses[$group_id][$question_id][$member_id][$marked_user_id] = $score;
+                            } else {
 
                 // Get the score the student submitted
-                $selfpeer_score = $this->_calc_responses[$group_id][$question_id][$member_id][$marked_user_id];
-
-                // Get the total marks awarded per question
-
-                $total_awarded_peeronly = $this->_group_split100[$group_id];
-
-                // If there's a self mark, we need to subtract it to get the total peer-only marks awarded per question
-                if (array_key_exists($member_id, $this->_calc_responses[$group_id][$question_id][$member_id])) {
-                  $total_awarded_peeronly -= $this->_calc_responses[$group_id][$question_id][$member_id][$member_id];
-                }
-
-                // Adjusted for peeronly score
-                $score = $selfpeer_score / ( $total_awarded_peeronly / ( $num_members - 1) ) * $this->_group_average_per_question[$group_id];
+                                $selfpeer_score = $this->_calc_responses[$group_id][$question_id][$member_id][$marked_user_id];
 
-              }// /if-else(student did submit)
+                                // Get the total marks awarded per question
 
-              $this->_calc_marks_awarded[$member_id][$marked_user_id] += $score;
-              $this->_calc_marks_received[$marked_user_id][$member_id] += $score;
+                                $total_awarded_peeronly = $this->_group_split100[$group_id];
 
-              $this->_calc_marks_awarded_by_member_question[$member_id][$question_id] += $score;
-              $this->_calc_marks_received_by_member_question[$marked_user_id][$question_id] += $score;
+                                // If there's a self mark, we need to subtract it to get the total peer-only marks awarded per question
+                                if (array_key_exists($member_id, $this->_calc_responses[$group_id][$question_id][$member_id])) {
+                                    $total_awarded_peeronly -= $this->_calc_responses[$group_id][$question_id][$member_id][$member_id];
+                                }
 
-              $this->_calc_total_marks_awarded[$member_id] += $score;
-              $this->_calc_total_marks_received[$marked_user_id] += $score;
+                                // Adjusted for peeronly score
+                                $score = $selfpeer_score / ($total_awarded_peeronly / ($num_members - 1)) * $this->_group_average_per_question[$group_id];
+                            }// /if-else(student did submit)
 
-            }// /if(not awarded to self)
+                            $this->_calc_marks_awarded[$member_id][$marked_user_id] += $score;
+                            $this->_calc_marks_received[$marked_user_id][$member_id] += $score;
 
-          }// /foreach(marked member)
+                            $this->_calc_marks_awarded_by_member_question[$member_id][$question_id] += $score;
+                            $this->_calc_marks_received_by_member_question[$marked_user_id][$question_id] += $score;
 
-        }// /foreach(question)
+                            $this->_calc_total_marks_awarded[$member_id] += $score;
+                            $this->_calc_total_marks_received[$marked_user_id] += $score;
+                        }// /if(not awarded to self)
+                    }// /foreach(marked member)
+                }// /foreach(question)
+            }// /foreach(member)
+        }// /foreach(group)
 
-      }// /foreach(member)
+        return true;
 
-    }// /foreach(group)
-
-    return true;
-
-    // @todo: if there's a non-submission, fake the scores using avg / q
+        // @todo: if there's a non-submission, fake the scores using avg / q
     // score = ( old-score / (total_marks_awarded_in_peeronly / num_members - 1) ) * peer_only_avg_per_question
+    }
 
-  }// /->_preparePeerOnly()
+    // /->_preparePeerOnly()
 
-  /**
-   * Prepare the ->_calc_?? properties, ready for the algorithm to process a self-&-peer assessment.
-   *
-   * @return  boolean  The operation was successful.
-   */
-  protected function _prepareSelfPeer() {
+    /**
+     * Prepare the ->_calc_?? properties, ready for the algorithm to process a self-&-peer assessment.
+     *
+     * @return  boolean  The operation was successful.
+     */
+    protected function _prepareSelfPeer()
+    {
 
     // Get the number of marks available in each question.
-    foreach ($this->_group_names as $group_id => $group_name) {
-      $member_count = count($this->_group_members[$group_id]);
-      $this->_group_split100[$group_id] = (100-(100 % $member_count));
-      $this->_group_average_per_question[$group_id] = $this->_group_split100[$group_id] / $member_count;
-    }
+        foreach ($this->_group_names as $group_id => $group_name) {
+            $member_count = count($this->_group_members[$group_id]);
+            $this->_group_split100[$group_id] = (100-(100 % $member_count));
+            $this->_group_average_per_question[$group_id] = $this->_group_split100[$group_id] / $member_count;
+        }
 
-    // Convert likert marks to split100 marks (if required)
-    $this->_convertFromLikert();
+        // Convert likert marks to split100 marks (if required)
+        $this->_convertFromLikert();
 
-    // Process all the student responses
-    // Set the correct values for the actual marks awarded, received, etc
+        // Process all the student responses
+        // Set the correct values for the actual marks awarded, received, etc
 
-    foreach ($this->_group_grades as $group_id => $group_mark) {
+        foreach ($this->_group_grades as $group_id => $group_mark) {
 
       // The score every member receives if their performance is equal
-      $avg_score = $this->_group_average_per_question[$group_id];
+            $avg_score = $this->_group_average_per_question[$group_id];
 
-      foreach ($this->_group_members[$group_id] as $i => $member_id) {
+            foreach ($this->_group_members[$group_id] as $i => $member_id) {
 
         // For the calculations, record everyone as submitting regardless of whether they did or not
-        $this->_calc_submitters[] = $member_id;
-        $this->_calc_group_submitters[$group_id][] = $member_id;
+                $this->_calc_submitters[] = $member_id;
+                $this->_calc_group_submitters[$group_id][] = $member_id;
 
-        foreach ($this->_questions as $i => $question_id) {
-
-          foreach ($this->_group_members[$group_id] as $k => $marked_user_id) {
+                foreach ($this->_questions as $i => $question_id) {
+                    foreach ($this->_group_members[$group_id] as $k => $marked_user_id) {
 
             // If the student did not submit..
-            if (!in_array($member_id, $this->_actual_submitters)) {
-              // Fake the response using the avg score / question
-              $score = $avg_score;
-              $this->_calc_responses[$group_id][$question_id][$member_id][$marked_user_id] = $score;
-            } else {
-              // Use the score the student submitted
-              $score = $this->_calc_responses[$group_id][$question_id][$member_id][$marked_user_id];
-            }
-
-            $this->_calc_marks_awarded[$member_id][$marked_user_id] += $score;
-            $this->_calc_marks_received[$marked_user_id][$member_id] += $score;
-
-            $this->_calc_marks_awarded_by_member_question[$member_id][$question_id] += $score;
-            $this->_calc_marks_received_by_member_question[$marked_user_id][$question_id] += $score;
-
-            $this->_calc_total_marks_awarded[$member_id] += $score;
-            $this->_calc_total_marks_received[$marked_user_id] += $score;
-
-          }// /foreach(marked member)
-
-        }// /foreach(question)
-
-      }// /foreach(member)
-
-    }// /foreach(group)
-
-    return true;
-  }// /->_prepareSelfPeer()
+                        if (!in_array($member_id, $this->_actual_submitters)) {
+                            // Fake the response using the avg score / question
+                            $score = $avg_score;
+                            $this->_calc_responses[$group_id][$question_id][$member_id][$marked_user_id] = $score;
+                        } else {
+                            // Use the score the student submitted
+                            $score = $this->_calc_responses[$group_id][$question_id][$member_id][$marked_user_id];
+                        }
+
+                        $this->_calc_marks_awarded[$member_id][$marked_user_id] += $score;
+                        $this->_calc_marks_received[$marked_user_id][$member_id] += $score;
+
+                        $this->_calc_marks_awarded_by_member_question[$member_id][$question_id] += $score;
+                        $this->_calc_marks_received_by_member_question[$marked_user_id][$question_id] += $score;
+
+                        $this->_calc_total_marks_awarded[$member_id] += $score;
+                        $this->_calc_total_marks_received[$marked_user_id] += $score;
+                    }// /foreach(marked member)
+                }// /foreach(question)
+            }// /foreach(member)
+        }// /foreach(group)
+
+        return true;
+    }
 
+    // /->_prepareSelfPeer()
 }// /class
-?>
diff --git a/src/includes/classes/algorithms/WebPAAlgorithm.php b/src/includes/classes/algorithms/WebPAAlgorithm.php
index efe4102..d6a25cb 100644
--- a/src/includes/classes/algorithms/WebPAAlgorithm.php
+++ b/src/includes/classes/algorithms/WebPAAlgorithm.php
@@ -12,37 +12,37 @@
 
 namespace WebPA\includes\classes\algorithms;
 
-class WebPAAlgorithm extends Algorithm {
-
-
-
-  /**
-   * Constructor
-   *
-   * @return  object  A new instance of this class.
-   */
-  public function __construct() {
-  }// /->__construct()
-
-
+class WebPAAlgorithm extends Algorithm
+{
+    /**
+     * Constructor
+     *
+     * @return  object  A new instance of this class.
+     */
+    public function __construct()
+    {
+    }
 
-/*
-* ================================================================================
-* Public Methods
-* ================================================================================
-*/
+    // /->__construct()
 
 
 
-  /**
-   * Calculate the student's final grades.
-   *
-   * As well as calculating grades, this method populates many of the properties
-   * available via the get methods.
-   *
-   * @return  boolean  The operation was successful.
-   */
-  public function calculate() {
+    /*
+    * ================================================================================
+    * Public Methods
+    * ================================================================================
+    */
+
+    /**
+     * Calculate the student's final grades.
+     *
+     * As well as calculating grades, this method populates many of the properties
+     * available via the get methods.
+     *
+     * @return  boolean  The operation was successful.
+     */
+    public function calculate()
+    {
 
 
     /*
@@ -52,264 +52,249 @@ public function calculate() {
      */
 
 
-    /* (1)
-     * Initialise the algorithm data and pre-fill most of the properties of this class.
-     * Gets the total number of marks each member awarded, and to whom, etc.
-     */
-
-    $this->_initialise();
+        /* (1)
+         * Initialise the algorithm data and pre-fill most of the properties of this class.
+         * Gets the total number of marks each member awarded, and to whom, etc.
+         */
 
+        $this->_initialise();
 
-    // Take each group in turn
-    foreach($this->_group_grades as $group_id => $group_mark) {
 
-      $group_member_frac_scores_awarded[$group_id] = array();
-      $group_member_total_received[$group_id] =  array();
+        // Take each group in turn
+        foreach ($this->_group_grades as $group_id => $group_mark) {
+            $group_member_frac_scores_awarded[$group_id] = [];
+            $group_member_total_received[$group_id] =  [];
 
-      // Take each member in turn
-      foreach($this->_group_members[$group_id] as $i => $member_id) {
+            // Take each member in turn
+            foreach ($this->_group_members[$group_id] as $i => $member_id) {
 
         // Initialise each member's total fractional score
-        $group_member_total_received[$group_id][$member_id] = 0;
+                $group_member_total_received[$group_id][$member_id] = 0;
 
-        // If the member submitted a response, then we need to normalise the scores awarded
-        if (in_array($member_id, $this->_calc_submitters)) {
+                // If the member submitted a response, then we need to normalise the scores awarded
+                if (in_array($member_id, $this->_calc_submitters)) {
 
           /* (2)
            * Get the normalised fraction awarded by each member to each member
            * If member-A gave member-B 4 marks, then the fraction awarded = 4 / total-marks-member-A-awarded
            */
 
-          // If the member gave more than 0 marks in total, calculate the fraction awarded
-          if ($this->_calc_total_marks_awarded[$member_id]>0) {
-
-            foreach($this->_questions as $i => $question_id) {
-
-              foreach($this->_calc_responses[$group_id][$question_id][$member_id] as $marked_user_id => $score) {
-                $group_member_frac_scores_awarded[$group_id][$member_id][$question_id][$marked_user_id] = $score / $this->_calc_total_marks_awarded[$member_id];
-              }// /foreach(member-response)
-
-            }// /foreach(question)
+                    // If the member gave more than 0 marks in total, calculate the fraction awarded
+                    if ($this->_calc_total_marks_awarded[$member_id]>0) {
+                        foreach ($this->_questions as $i => $question_id) {
+                            foreach ($this->_calc_responses[$group_id][$question_id][$member_id] as $marked_user_id => $score) {
+                                $group_member_frac_scores_awarded[$group_id][$member_id][$question_id][$marked_user_id] = $score / $this->_calc_total_marks_awarded[$member_id];
+                            }// /foreach(member-response)
+                        }// /foreach(question)
+                    }// /if(member-total-award==0)
+                }// /if(member-submitted)
+            }// /foreach(member)
 
-          }// /if(member-total-award==0)
 
-        }// /if(member-submitted)
+            // All the scores are now normalised. Time to calculate the actual Web-PA scores
 
-      }// /foreach(member)
 
+            /* (3)
+             * Get the multiplication factor we need to calculate the Web-PA scores
+             * factor = num-members-total / num-members-submitted
+             */
 
-      // All the scores are now normalised. Time to calculate the actual Web-PA scores
+            $num_members = ((is_array($this->_group_members)) && (array_key_exists($group_id, $this->_group_members))) ? count($this->_group_members[$group_id]) : 0 ;
+            $num_submitted = (array_key_exists($group_id, $this->_calc_group_submitters)) ? count($this->_calc_group_submitters[$group_id]) : 0 ;
 
+            $multi_factor = ($num_submitted>0) ? ($num_members / $num_submitted) : 1 ;
 
-      /* (3)
-       * Get the multiplication factor we need to calculate the Web-PA scores
-       * factor = num-members-total / num-members-submitted
-       */
 
-      $num_members = ( (is_array($this->_group_members)) && (array_key_exists($group_id, $this->_group_members)) ) ? count($this->_group_members[$group_id]) : 0 ;
-      $num_submitted = (array_key_exists($group_id, $this->_calc_group_submitters)) ? count($this->_calc_group_submitters[$group_id]) : 0 ;
+            $pa_group_mark = ($this->_params['weighting']/100) * $group_mark;
+            $nonpa_group_mark = ((100-$this->_params['weighting']) /100) * $group_mark;
 
-      $multi_factor = ($num_submitted>0) ? ($num_members / $num_submitted) : 1 ;
 
 
-      $pa_group_mark = ($this->_params['weighting']/100) * $group_mark;
-      $nonpa_group_mark = ( (100-$this->_params['weighting']) /100 ) * $group_mark;
+            // @todo : apply criterion weightings here (empty method at present)
+            $this->_applyCriterionWeightings();
 
 
 
-      // @todo : apply criterion weightings here (empty method at present)
-      $this->_applyCriterionWeightings();
-
-
-
-      /* (4)
-       * Get the total fractional score awarded to each member for each question
-       */
-
-      foreach($group_member_frac_scores_awarded[$group_id] as $member_id => $q_array) {
-        foreach($q_array as $question_id => $marked_array) {
-          foreach($marked_array as $marked_user_id => $frac_score) {
-            $group_member_total_received[$group_id][$marked_user_id] += $frac_score;
-          }
-        }
-      }
+            /* (4)
+             * Get the total fractional score awarded to each member for each question
+             */
 
+            foreach ($group_member_frac_scores_awarded[$group_id] as $member_id => $q_array) {
+                foreach ($q_array as $question_id => $marked_array) {
+                    foreach ($marked_array as $marked_user_id => $frac_score) {
+                        $group_member_total_received[$group_id][$marked_user_id] += $frac_score;
+                    }
+                }
+            }
 
-      if (array_key_exists($group_id, $group_member_total_received)) {
 
-        foreach($group_member_total_received[$group_id] as $member_id => $total_frac_score) {
+            if (array_key_exists($group_id, $group_member_total_received)) {
+                foreach ($group_member_total_received[$group_id] as $member_id => $total_frac_score) {
 
 
           /* (5)
            * Get the Web-PA score = total fractional score awarded to a member * multiplication-factor
            */
-          $this->_webpa_scores[$member_id] = $total_frac_score * $multi_factor;
-
-
-          /* (6)
-           * Get the member's intermediate grade = Web-PA score * weighted-group-mark   (does not include penalties)
-           */
-          if (is_array($this->_calc_group_submitters[$group_id])) {
-            $intermediate_grade = (($total_frac_score * $multi_factor * $pa_group_mark) + $nonpa_group_mark);
-          } else {
-            $intermediate_grade = $pa_group_mark + $nonpa_group_mark;
-          }
-
-          if ($intermediate_grade<0) { $intermediate_grade = 0; }
-          elseif ($intermediate_grade>100) { $intermediate_grade = 100; }
-
-          // Intermediate grades are whatever the algorithm thought the grade should be (before penalties)
-          $this->_intermediate_grades[$member_id] = $intermediate_grade;
-
-          /* (7)
-           * Get the member's actual grade
-           *
-           * At this point, final grades are the same as intermediate grades (penalties are applied at the end)
-           */
-
-          $this->_grades[$member_id] = $intermediate_grade;
-
-        }
-      }
-    }// /foreach(group)
-
-
-    /* (8)
-     * Apply any penalties
-     */
-    $this->_applyPenalties();
+                    $this->_webpa_scores[$member_id] = $total_frac_score * $multi_factor;
+
+
+                    /* (6)
+                     * Get the member's intermediate grade = Web-PA score * weighted-group-mark   (does not include penalties)
+                     */
+                    if (is_array($this->_calc_group_submitters) && array_key_exists($group_id, $this->_calc_group_submitters)) {
+                        $intermediate_grade = (($total_frac_score * $multi_factor * $pa_group_mark) + $nonpa_group_mark);
+                    } else {
+                        $intermediate_grade = $pa_group_mark + $nonpa_group_mark;
+                    }
+
+                    if ($intermediate_grade<0) {
+                        $intermediate_grade = 0;
+                    } elseif ($intermediate_grade>100) {
+                        $intermediate_grade = 100;
+                    }
+
+                    // Intermediate grades are whatever the algorithm thought the grade should be (before penalties)
+                    $this->_intermediate_grades[$member_id] = $intermediate_grade;
+
+                    /* (7)
+                     * Get the member's actual grade
+                     *
+                     * At this point, final grades are the same as intermediate grades (penalties are applied at the end)
+                     */
+
+                    $this->_grades[$member_id] = $intermediate_grade;
+                }
+            }
+        }// /foreach(group)
 
 
-    /*(9)
-     * Make sure the grades conform to the requested grading style (% or A-F)
-     */
-    $this->_applyGradingStyle();
+        /* (8)
+         * Apply any penalties
+         */
+        $this->_applyPenalties();
 
 
-    return true;
-  }// /->calculate()
+        /*(9)
+         * Make sure the grades conform to the requested grading style (% or A-F)
+         */
+        $this->_applyGradingStyle();
 
 
+        return true;
+    }
 
-/*
-* ================================================================================
-* Private Methods
-* ================================================================================
-*/
+    // /->calculate()
 
 
 
-  /**
-   * Prepare the ->_calc_?? properties, ready for the algorithm to process a peer-only assessment.
-   *
-   * @return  boolean  The operation was successful.
-   */
-  protected function _preparePeerOnly() {
+    /*
+    * ================================================================================
+    * Private Methods
+    * ================================================================================
+    */
+
+    /**
+     * Prepare the ->_calc_?? properties, ready for the algorithm to process a peer-only assessment.
+     *
+     * @return  boolean  The operation was successful.
+     */
+    protected function _preparePeerOnly()
+    {
 
     // Set the initial state of all the calc_?? properties
-    $this->_calc_responses = $this->_actual_responses;
-
-    $this->_calc_group_submitters = $this->_actual_group_submitters;
-    $this->_calc_submitters = $this->_actual_submitters;
+        $this->_calc_responses = $this->_actual_responses;
 
-    $this->_calc_marks_awarded = $this->_actual_marks_awarded;
-    $this->_calc_marks_received = $this->_actual_marks_received;
+        $this->_calc_group_submitters = $this->_actual_group_submitters;
+        $this->_calc_submitters = $this->_actual_submitters;
 
-    $this->_calc_marks_awarded_by_member_question = $this->_actual_marks_awarded_by_member_question;
-    $this->_calc_marks_received_by_member_question = $this->_actual_marks_received_by_member_question;
+        $this->_calc_marks_awarded = $this->_actual_marks_awarded;
+        $this->_calc_marks_received = $this->_actual_marks_received;
 
-    $this->_calc_total_marks_awarded = $this->_actual_total_marks_awarded;
-    $this->_calc_total_marks_received = $this->_actual_total_marks_received;
+        $this->_calc_marks_awarded_by_member_question = $this->_actual_marks_awarded_by_member_question;
+        $this->_calc_marks_received_by_member_question = $this->_actual_marks_received_by_member_question;
 
+        $this->_calc_total_marks_awarded = $this->_actual_total_marks_awarded;
+        $this->_calc_total_marks_received = $this->_actual_total_marks_received;
 
 
-    // This is the score each student will receive if someone in their group does not submit.
-    // It must be greater than 0, but as everyone will receive the same score, the actual value doesn't matter.
-    $score = 5;
 
+        // This is the score each student will receive if someone in their group does not submit.
+        // It must be greater than 0, but as everyone will receive the same score, the actual value doesn't matter.
+        $score = 5;
 
-    // Flag if we find anyone who has submitted self-assessment marks
-    $self_assessment = false;
 
+        // Flag if we find anyone who has submitted self-assessment marks
+        $self_assessment = false;
 
-    foreach($this->_group_names as $group_id => $group_name) {
 
-      $num_members = count($this->_group_members[$group_id]);
-      $num_submitted = (array_key_exists($group_id, $this->_calc_group_submitters)) ? count($this->_calc_group_submitters[$group_id]) : 0 ;
+        foreach ($this->_group_names as $group_id => $group_name) {
+            $num_members = count($this->_group_members[$group_id]);
+            $num_submitted = (array_key_exists($group_id, $this->_calc_group_submitters)) ? count($this->_calc_group_submitters[$group_id]) : 0 ;
 
-      // If someone didn't submit..
-      if ($num_members>$num_submitted) {
+            // If someone didn't submit..
+            if ($num_members>$num_submitted) {
 
         // We have a non-submission.  We need to fake the submission data to avoid penalising students who did submit.
-        // Faking the submission in this way means the algorithm can run normally.
-
-        foreach($this->_group_members[$group_id] as $j => $member_id) {
+                // Faking the submission in this way means the algorithm can run normally.
 
-          if (!in_array($member_id, $this->_calc_submitters)) {
-            $this->_calc_submitters[] = "$member_id";
-            $this->_calc_group_submitters[$group_id][] = "$member_id";
+                foreach ($this->_group_members[$group_id] as $j => $member_id) {
+                    if (!in_array($member_id, $this->_calc_submitters)) {
+                        $this->_calc_submitters[] = "$member_id";
+                        $this->_calc_group_submitters[$group_id][] = "$member_id";
 
-            foreach($this->_questions as $i => $question_id) {
-
-              foreach($this->_group_members[$group_id] as $k => $marked_user_id) {
+                        foreach ($this->_questions as $i => $question_id) {
+                            foreach ($this->_group_members[$group_id] as $k => $marked_user_id) {
 
                 // If it's not a self-mark, add it to the list
-                if ($member_id != $marked_user_id) {
-                  $this->_calc_responses[$group_id][$question_id][$member_id][$marked_user_id] = $score;
-
-                  $this->_calc_marks_awarded[$member_id][$marked_user_id] += $score;
-                  $this->_calc_marks_received[$marked_user_id][$member_id] += $score;
-
-                  $this->_calc_marks_awarded_by_member_question[$member_id][$question_id] += $score;
-                  $this->_calc_marks_received_by_member_question[$marked_user_id][$question_id] += $score;
-
-                  $this->_calc_total_marks_awarded[$member_id] += $score;
-                  $this->_calc_total_marks_received[$marked_user_id] += $score;
-                }
-
-              }// /foreach(group member)
-
-            }// /foreach(question)
-
-          }// /if(non-submitter)
-
-        }// /foreach(group member)
-
-      }// /if(non-submissions)
-
-    }// /foreach(group)
-
-    return true;
-  }// /->_preparePeerOnly()
-
-
-
-  /**
-   * Prepare the ->_calc_?? properties, ready for the algorithm to process a self-&-peer assessment.
-   *
-   * @return  boolean  The operation was successful.
-   */
-  protected function _prepareSelfPeer() {
+                                if ($member_id != $marked_user_id) {
+                                    $this->_calc_responses[$group_id][$question_id][$member_id][$marked_user_id] = $score;
+
+                                    $this->_calc_marks_awarded[$member_id][$marked_user_id] += $score;
+                                    $this->_calc_marks_received[$marked_user_id][$member_id] += $score;
+
+                                    $this->_calc_marks_awarded_by_member_question[$member_id][$question_id] += $score;
+                                    $this->_calc_marks_received_by_member_question[$marked_user_id][$question_id] += $score;
+
+                                    $this->_calc_total_marks_awarded[$member_id] += $score;
+                                    $this->_calc_total_marks_received[$marked_user_id] += $score;
+                                }
+                            }// /foreach(group member)
+                        }// /foreach(question)
+                    }// /if(non-submitter)
+                }// /foreach(group member)
+            }// /if(non-submissions)
+        }// /foreach(group)
+
+        return true;
+    }
+
+    // /->_preparePeerOnly()
+
+    /**
+     * Prepare the ->_calc_?? properties, ready for the algorithm to process a self-&-peer assessment.
+     *
+     * @return  boolean  The operation was successful.
+     */
+    protected function _prepareSelfPeer()
+    {
 
     // Set the initial state of all the calc_?? properties
-    $this->_calc_responses = $this->_actual_responses;
-
-    $this->_calc_group_submitters = $this->_actual_group_submitters;
-    $this->_calc_submitters = $this->_actual_submitters;
-
-    $this->_calc_marks_awarded = $this->_actual_marks_awarded;
-    $this->_calc_marks_received = $this->_actual_marks_received;
+        $this->_calc_responses = $this->_actual_responses;
 
-    $this->_calc_marks_awarded_by_member_question = $this->_actual_marks_awarded_by_member_question;
-    $this->_calc_marks_received_by_member_question = $this->_actual_marks_received_by_member_question;
+        $this->_calc_group_submitters = $this->_actual_group_submitters;
+        $this->_calc_submitters = $this->_actual_submitters;
 
-    $this->_calc_total_marks_awarded = $this->_actual_total_marks_awarded;
-    $this->_calc_total_marks_received = $this->_actual_total_marks_received;
+        $this->_calc_marks_awarded = $this->_actual_marks_awarded;
+        $this->_calc_marks_received = $this->_actual_marks_received;
 
-    return true;
-  }// /->_prepareSelfPeer()
+        $this->_calc_marks_awarded_by_member_question = $this->_actual_marks_awarded_by_member_question;
+        $this->_calc_marks_received_by_member_question = $this->_actual_marks_received_by_member_question;
 
+        $this->_calc_total_marks_awarded = $this->_actual_total_marks_awarded;
+        $this->_calc_total_marks_received = $this->_actual_total_marks_received;
 
+        return true;
+    }
 
+    // /->_prepareSelfPeer()
 }// /class
-?>
diff --git a/src/includes/functions/AcademicYear.php b/src/includes/functions/AcademicYear.php
index 8e2c04f..a9dc937 100644
--- a/src/includes/functions/AcademicYear.php
+++ b/src/includes/functions/AcademicYear.php
@@ -12,38 +12,39 @@
 
 class AcademicYear
 {
-     /**
-     *  Get the academic year for a given date
-     *
-     * @param int $date (optional) datetime to check. (default: current date/time)
-     * @param int $start_month (optional) month-component of date the academic year starts in a year (default: 9)
-     * @param int $start_day (optional) day-component of date the academic year starts in a year (default: 1)
-     *
-     * @return int academic year (format: YYYY)
+    /**
+    *  Get the academic year for a given date
+    *
+    * @param int $date (optional) datetime to check. (default: current date/time)
+    * @param int $start_month (optional) month-component of date the academic year starts in a year (default: 9)
+    * @param int $start_day (optional) day-component of date the academic year starts in a year (default: 1)
+    *
+    * @return int academic year (format: YYYY)
     */
-    public static function get_academic_year($date = null) {
-      if (is_null($date)) {
-        $date = time();
-      }
-      $year = (int) date('Y',$date);
-      $month = (int) date('n',$date);
-      if ($month < APP__ACADEMIC_YEAR_START_MONTH) {
-        $year = $year - 1;
-      }
-
-      return $year;
-
-    }// /get_academic_year()
-
-    public static function dateToYear($date) {
+    public static function get_academic_year($date = null)
+    {
+        if (is_null($date)) {
+            $date = time();
+        }
+        $year = (int) date('Y', $date);
+        $month = (int) date('n', $date);
+        if ($month < APP__ACADEMIC_YEAR_START_MONTH) {
+            $year = $year - 1;
+        }
+
+        return $year;
+    }
 
-      $year = (int) date('Y',$date);
-      $month = (int) date('n',$date);
-      if ($month < APP__ACADEMIC_YEAR_START_MONTH) {
-        $year = $year - 1;
-      }
+    // /get_academic_year()
 
-      return $year;
+    public static function dateToYear($date)
+    {
+        $year = (int) date('Y', $date);
+        $month = (int) date('n', $date);
+        if ($month < APP__ACADEMIC_YEAR_START_MONTH) {
+            $year = $year - 1;
+        }
 
+        return $year;
     }
 }
diff --git a/src/includes/functions/ArrayFunctions.php b/src/includes/functions/ArrayFunctions.php
index a7a995b..629a383 100644
--- a/src/includes/functions/ArrayFunctions.php
+++ b/src/includes/functions/ArrayFunctions.php
@@ -22,14 +22,15 @@ class ArrayFunctions
      *
      * @return ?? description
      */
-    public static function array_searchvalue($needle, $haystack, $search_index, $return_index = 0) {
-      $arr_count = count($haystack);
-      for ($i=0; $i<$arr_count; ++$i) {
-        if ($haystack[$i][$search_index]==$needle) {
-          return $haystack[$i][$return_index];
-          break;
+    public static function array_searchvalue($needle, $haystack, $search_index, $return_index = 0)
+    {
+        $arr_count = count($haystack);
+        for ($i=0; $i<$arr_count; ++$i) {
+            if ($haystack[$i][$search_index]==$needle) {
+                return $haystack[$i][$return_index];
+                break;
+            }
         }
-      }
     }
 
     /**
@@ -41,21 +42,23 @@ public static function array_searchvalue($needle, $haystack, $search_index, $ret
      *
      * @return array 1D array of items matching
      */
-    public static function array_extract_column(&$array, $column) {
-      $extracted_columns = null;
-      if (is_array($array)) {
-        foreach($array as $i => $row) {
-          if (isset($row["$column"])) {
-            $extracted_columns[] = $row["$column"];
-          } else {
-            $extracted_columns[] = $i;
-          }
+    public static function array_extract_column(&$array, $column)
+    {
+        $extracted_columns = null;
+        if (is_array($array)) {
+            foreach ($array as $i => $row) {
+                if (isset($row["$column"])) {
+                    $extracted_columns[] = $row["$column"];
+                } else {
+                    $extracted_columns[] = $i;
+                }
+            }
+            return $extracted_columns;
         }
-        return $extracted_columns;
-      } else {
         return null;
-      }
-    }// /array_extract_column()
+    }
+
+    // /array_extract_column()
 
     /**
      *  Get an associative array, keyed using the given index
@@ -67,14 +70,17 @@ public static function array_extract_column(&$array, $column) {
      * @return array assoc array: array (key=>org_row, key=>org)
      * _row, ...
      */
-    public static function array_get_assoc($array, $key_index) {
-      $assoc_array = null;
+    public static function array_get_assoc($array, $key_index)
+    {
+        $assoc_array = null;
 
-      if ( (is_array($array)) ) {
-        foreach($array as $i => $array_row) {
-          $assoc_array["{$array_row[$key_index]}"] = $array_row;
+        if ((is_array($array))) {
+            foreach ($array as $i => $array_row) {
+                $assoc_array["{$array_row[$key_index]}"] = $array_row;
+            }
         }
-      }
-      return $assoc_array;
-    }// /array_get_assoc()
+        return $assoc_array;
+    }
+
+    // /array_get_assoc()
 }
diff --git a/src/includes/functions/Common.php b/src/includes/functions/Common.php
index e29f947..aa6a71d 100644
--- a/src/includes/functions/Common.php
+++ b/src/includes/functions/Common.php
@@ -10,9 +10,10 @@
 
 namespace WebPA\includes\functions;
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\DAO;
 
-define('MYSQL_DATETIME_FORMAT','Y-m-d H:i:s');    // MYSQL datetime format (for update/insert/etc)
+define('MYSQL_DATETIME_FORMAT', 'Y-m-d H:i:s');    // MYSQL datetime format (for update/insert/etc)
 
 class Common
 {
@@ -24,8 +25,9 @@ class Common
      *
      * @return mixed
      */
-    public static function fetch_GET($key, $default_value = '') {
-      return (isset($_GET[$key])) ? $_GET[$key] : $default_value;
+    public static function fetch_GET($key, $default_value = '')
+    {
+        return (isset($_GET[$key])) ? $_GET[$key] : $default_value;
     }
 
     /**
@@ -36,8 +38,9 @@ public static function fetch_GET($key, $default_value = '') {
      *
      * @return mixed
      */
-    public static function fetch_POST($key, $default_value = '') {
-      return (isset($_POST[$key])) ? $_POST[$key] : $default_value;
+    public static function fetch_POST($key, $default_value = '')
+    {
+        return (isset($_POST[$key])) ? $_POST[$key] : $default_value;
     }
 
     /**
@@ -48,8 +51,9 @@ public static function fetch_POST($key, $default_value = '') {
      *
      * @return mixed
      */
-    public static function fetch_SERVER($key, $default_value = '') {
-      return (isset($_SERVER[$key])) ? $_SERVER[$key] : $default_value;
+    public static function fetch_SERVER($key, $default_value = '')
+    {
+        return (isset($_SERVER[$key])) ? $_SERVER[$key] : $default_value;
     }
 
     /**
@@ -60,8 +64,9 @@ public static function fetch_SERVER($key, $default_value = '') {
      *
      * @return mixed
      */
-    public static function fetch_SESSION($key, $default_value = '') {
-      return (isset($_SESSION[$key])) ? $_SESSION[$key] : $default_value;
+    public static function fetch_SESSION($key, $default_value = '')
+    {
+        return (isset($_SESSION[$key])) ? $_SESSION[$key] : $default_value;
     }
 
     /**
@@ -70,33 +75,45 @@ public static function fetch_SESSION($key, $default_value = '') {
      *
      * @return UUID
      */
-    public static function uuid_create() {
-      // Get random 32-char 'UUID'
-      $uuid_32 = strtoupper( md5( uniqid( rand(), true) ) );
+    public static function uuid_create()
+    {
+        // Get random 32-char 'UUID'
+        $uuid_32 = strtoupper(md5(uniqid(rand(), true)));
 
-      // Convert to the correct 'dashed' format, and return the UUID
-      return preg_replace('#([\dA-F]{8})([\dA-F]{4})([\dA-F]{4})([\dA-F]{4})([\dA-F]{12})#', "\\1-\\2-\\3-\\4-\\5", $uuid_32);
+        // Convert to the correct 'dashed' format, and return the UUID
+        return preg_replace('#([\dA-F]{8})([\dA-F]{4})([\dA-F]{4})([\dA-F]{4})([\dA-F]{12})#', '\\1-\\2-\\3-\\4-\\5', $uuid_32);
     }
 
     /**
      * Add an entry to the tracking table
      */
-    public static function logEvent(DAO $db, $description, $module_id = NULL, $object_id = NULL) {
-      $now = date(MYSQL_DATETIME_FORMAT);
+    public static function logEvent(DAO $db, $description, $module_id = null, $object_id = null)
+    {
+        $dbConn = $db->getConnection();
 
-      if (!empty($module_id)) {
-        $module_id = (int) $module_id;
-      }
+        $now = date(MYSQL_DATETIME_FORMAT);
 
-      $fields = array ('user_id' => (int) $_SESSION['_user_id'],
-               'datetime'    => $now,
-               'ip_address'  => $_SERVER['REMOTE_ADDR'],
-               'description' => $description,
-               'module_id'   => $module_id,
-               'object_id'   => $object_id);
+        if (!empty($module_id)) {
+            $module_id = (int) $module_id;
+        }
+
+        $query =
+            'INSERT INTO ' . APP__DB_TABLE_PREFIX . 'user_tracking ' .
+            '(user_id, datetime, ip_address, description, module_id, object_id) ' .
+            'VALUES (?, ?, ?, ?, ?, ?) ' .
+            'ON DUPLICATE KEY UPDATE user_id = ?';
+
+        $stmt = $dbConn->prepare($query);
 
-      return $db->do_insert('INSERT INTO ' . APP__DB_TABLE_PREFIX . 'user_tracking ({fields}) VALUES ({values})', $fields);
+        $stmt->bindValue(1, (int) $_SESSION['_user_id'], ParameterType::INTEGER);
+        $stmt->bindValue(2, $now);
+        $stmt->bindValue(3, $_SERVER['REMOTE_ADDR']);
+        $stmt->bindValue(4, $description);
+        $stmt->bindValue(5, $module_id, ParameterType::INTEGER);
+        $stmt->bindValue(6, $object_id);
+        $stmt->bindValue(7, (int) $_SESSION['_user_id'], ParameterType::INTEGER);
 
+        $stmt->execute();
     }
 
     /**
@@ -105,56 +122,56 @@ public static function logEvent(DAO $db, $description, $module_id = NULL, $objec
     * @param string $_user
     * @param string $user_type
     */
-    public static function check_user($_user, $user_type = NULL) {
+    public static function check_user($_user, $user_type = null)
+    {
 
       // Is the user valid?
-      if ($_user) {
+        if ($_user) {
 
         // if we're not checking the user type, or we are checking and it matches, return OK
-        if (!$user_type || $_user->is_admin()) {
-          return true;
-        } else {
-          switch ($user_type) {
+            if (!$user_type || $_user->is_admin()) {
+                return true;
+            }
+            switch ($user_type) {
             case APP__USER_TYPE_ADMIN:
               if ($_user->is_admin()) {
-                return true;
+                  return true;
               }
               break;
             case APP__USER_TYPE_TUTOR:
               if ($_user->is_tutor()) {
-                return true;
+                  return true;
               }
               break;
             case APP__USER_TYPE_STUDENT:
               if ($_user->is_student()) {
-                return true;
+                  return true;
               }
               break;
           }
-          return false;
+            return false;
         }
-      } else {
         return false;
-      }
+        
 
 
-      // If we didn't call 'return' then the user is denied access
+        // If we didn't call 'return' then the user is denied access
 
-      // If they tried to access the main index page, assume they haven't logged in and go to the login page directly
-      if ($_SERVER['PHP_SELF']=='/index.php') {
-        header('Location: '. APP__WWW .'/login.php');
-      } else {  // log them out and give the DENIED message
-        header('Location:'. APP__WWW .'/logout.php?msg=denied');
-      }
-      exit;
+        // If they tried to access the main index page, assume they haven't logged in and go to the login page directly
+        if ($_SERVER['PHP_SELF']=='/index.php') {
+            header('Location: '. APP__WWW .'/login.php');
+        } else {  // log them out and give the DENIED message
+            header('Location:'. APP__WWW .'/logout.php?msg=denied');
+        }
+        exit;
     }
 
     /**
      * This function is a legacy function which appears to determine if a file is located in a particular directory.
      *
      */
-    public static function & rel1($struc, &$file) {
-      return file_exists( ( $file = ( dirname($struc).'/'.$file ) ) );
+    public static function & rel1($struc, &$file)
+    {
+        return file_exists(($file = (dirname($struc).'/'.$file)));
     }
 }
-
diff --git a/src/includes/functions/Form.php b/src/includes/functions/Form.php
index 7bbbe00..d3648d6 100755
--- a/src/includes/functions/Form.php
+++ b/src/includes/functions/Form.php
@@ -19,9 +19,12 @@ class Form
      * @param string $email_address
      * @return bool
      */
-    public static function is_email($email_address) {
+    public static function is_email($email_address)
+    {
         return filter_var($email_address, FILTER_VALIDATE_EMAIL) === false ? false : true;
-    }// /is_email()
+    }
+
+    // /is_email()
 
     /**
      * Render an associative array as <option></option> tags
@@ -30,29 +33,32 @@ public static function is_email($email_address) {
      * @param string $selected Value that should be selected (have attribute: selected="selected")
      * @param datatype $switch_kv Use $v as the option value instead of $k
      */
-    public static function render_options($arr, $selected = null, $switch_kv = false) {
+    public static function render_options($arr, $selected = null, $switch_kv = false)
+    {
         if (!$switch_kv) {
             if (!is_null($selected)) {
-                foreach($arr as $k => $v) {
-                echo("<option value=\"$k\" ". ( ($k==$selected) ? 'selected="selected"' : '' ) ."> $v </option>");
-              }
+                foreach ($arr as $k => $v) {
+                    echo "<option value=\"$k\" ". (($k==$selected) ? 'selected="selected"' : '') ."> $v </option>";
+                }
             } else {
-                foreach($arr as $k => $v) {
-                echo("<option value=\"$k\"> $v </option>");
-              }
+                foreach ($arr as $k => $v) {
+                    echo "<option value=\"$k\"> $v </option>";
+                }
             }
         } else {
             if ($selected) {
-                foreach($arr as $k => $v) {
-                echo("<option value=\"$v\" ". ( ($v==$selected) ? 'selected="selected"' : '' ) ."> $v </option>");
-              }
+                foreach ($arr as $k => $v) {
+                    echo "<option value=\"$v\" ". (($v==$selected) ? 'selected="selected"' : '') ."> $v </option>";
+                }
             } else {
-                foreach($arr as $k => $v) {
-                echo("<option value=\"$v\"> $v </option>");
-              }
+                foreach ($arr as $k => $v) {
+                    echo "<option value=\"$v\"> $v </option>";
+                }
             }
         }
-    }// /render_options()
+    }
+
+    // /render_options()
 
     /**
      * Render <option></option> tags for the given range of values
@@ -62,12 +68,15 @@ public static function render_options($arr, $selected = null, $switch_kv = false
      * @param null $selected
      *
      */
-    public static function render_options_range($start, $end, $increment = 1, $selected = null) {
+    public static function render_options_range($start, $end, $increment = 1, $selected = null)
+    {
         for ($i=$start; $i<=$end; $i += $increment) {
             $selected_str = ($i==$selected) ? 'selected="selected"' : '';
-            echo("<option value=\"$i\" $selected_str> $i </option>");
+            echo "<option value=\"$i\" $selected_str> $i </option>";
         }
-    }// /render_options_range()
+    }
+
+    // /render_options_range()
 
     /**
      * write to screen the check box grid
@@ -78,9 +87,13 @@ public static function render_options_range($start, $end, $increment = 1, $selec
      * @param bool $switch_value_label
      * @param int $num_cols
     */
-    public static function render_checkbox_grid($arr, $input_name, $selected_arr, $switch_value_label = false, $num_cols = 1) {
-        if (is_null($selected_arr)) { $selected_arr = array(); }
-        else { $selected_arr = (array) $selected_arr; }
+    public static function render_checkbox_grid($arr, $input_name, $selected_arr, $switch_value_label = false, $num_cols = 1)
+    {
+        if (is_null($selected_arr)) {
+            $selected_arr = [];
+        } else {
+            $selected_arr = (array) $selected_arr;
+        }
 
         $arr_to_use = ($switch_value_label) ? array_flip($arr) : $arr;
 
@@ -89,28 +102,32 @@ public static function render_checkbox_grid($arr, $input_name, $selected_arr, $s
 
         // Calculate how many empty columns there must be
         $mod = $count % $num_cols;
-        $empty_cols = ($mod == 0) ? 0 : $num_cols - ($count % $num_cols);
-        ?>
+        $empty_cols = ($mod == 0) ? 0 : $num_cols - ($count % $num_cols); ?>
         <table class="checkbox_grid" cellpadding="0" cellspacing="0">
         <?php
-        foreach($arr_to_use as $value => $label) {
+        foreach ($arr_to_use as $value => $label) {
             if (($i % $num_cols)==0) {
-                if ($i!=0) { echo('</tr>'); }
-                if ($i!=$count-1) { echo('<tr>'); }
+                if ($i!=0) {
+                    echo '</tr>';
+                }
+                if ($i!=$count-1) {
+                    echo '<tr>';
+                }
             }
-            $id = $input_name .'_'. str_replace(' ','_', $value);
-            $checked_str = (in_array($value,$selected_arr)) ? 'checked="checked"' : '';
+            $id = $input_name .'_'. str_replace(' ', '_', $value);
+            $checked_str = (in_array($value, $selected_arr)) ? 'checked="checked"' : '';
 
-            echo("<td><input type=\"checkbox\" name=\"{$input_name}[]\" id=\"$id\" value=\"$value\" $checked_str /></td>");
-            echo("<th><label for=\"$id\">$label</label></th>");
+            echo "<td><input type=\"checkbox\" name=\"{$input_name}[]\" id=\"$id\" value=\"$value\" $checked_str /></td>";
+            echo "<th><label for=\"$id\">$label</label></th>";
             $i++;
         }
-        echo( str_repeat('<td>&nbsp;</td><td>&nbsp;</td>',$empty_cols) );
-        echo('</tr>');
-        ?>
+        echo str_repeat('<td>&nbsp;</td><td>&nbsp;</td>', $empty_cols);
+        echo '</tr>'; ?>
         </table>
         <?php
-    }// /render_checkbox_grid()
+    }
+
+    // /render_checkbox_grid()
 
     /**
      * Write to screen the radio buttons
@@ -119,10 +136,9 @@ public static function render_checkbox_grid($arr, $input_name, $selected_arr, $s
      * @param string $selected_str
      * @param bool $switch_value_label
     */
-    public static function render_radio_boxes($arr, $input_name, $selected_str, $switch_value_label = false) {
-        $arr_to_use = ($switch_value_label) ? array_flip($arr) : $arr;
-
-        ?>
+    public static function render_radio_boxes($arr, $input_name, $selected_str, $switch_value_label = false)
+    {
+        $arr_to_use = ($switch_value_label) ? array_flip($arr) : $arr; ?>
         <table class="radio_grid" cellpadding="0" cellspacing="0">
         <?php
         /*
@@ -137,17 +153,19 @@ public static function render_radio_boxes($arr, $input_name, $selected_str, $swi
             }
         } else {
         */
-            foreach($arr_to_use as $value => $label) {
-                $id = $input_name .'_'. str_replace(' ','_', $value);
+            foreach ($arr_to_use as $value => $label) {
+                $id = $input_name .'_'. str_replace(' ', '_', $value);
                 $checked_str = ($value==$selected_str) ? 'checked="checked"' : '';
-                echo('<tr>');
-                echo("<td><input type=\"radio\" name=\"$input_name\" id=\"$id\" value=\"$value\" $checked_str /></td>");
-                echo("<th><label for=\"$id\">$label</label></th>");
-                echo('</tr>');
+                echo '<tr>';
+                echo "<td><input type=\"radio\" name=\"$input_name\" id=\"$id\" value=\"$value\" $checked_str /></td>";
+                echo "<th><label for=\"$id\">$label</label></th>";
+                echo '</tr>';
             }
-    //	}
+        //	}
         ?>
         </table>
         <?php
-    }// /render_radio_boxes()
+    }
+
+    // /render_radio_boxes()
 }
diff --git a/src/includes/functions/StringFunctions.php b/src/includes/functions/StringFunctions.php
index c20bc31..22790ee 100644
--- a/src/includes/functions/StringFunctions.php
+++ b/src/includes/functions/StringFunctions.php
@@ -10,9 +10,9 @@
 
 namespace WebPA\includes\functions;
 
-DEFINE('STR_ALPHA_CHARS','ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz');
-DEFINE('STR_ALPHANUM_CHARS','0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz');
-DEFINE('STR_UUID_CHARS','0123456789ABCDEF-');
+define('STR_ALPHA_CHARS', 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz');
+define('STR_ALPHANUM_CHARS', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz');
+define('STR_UUID_CHARS', '0123456789ABCDEF-');
 
 class StringFunctions
 {
@@ -24,13 +24,14 @@ class StringFunctions
      *
      * @return string
     */
-    public static function str_random ($length = 8, $valid_chars = null) {
+    public static function str_random($length = 8, $valid_chars = null)
+    {
         if (is_null($valid_chars)) {
             $valid_chars = STR_ALPHANUM_CHARS;
         }
 
         $str = '';
-      while(strlen($str) < $length) {
+        while (strlen($str) < $length) {
             $str .= substr($valid_chars, mt_rand(0, strlen($valid_chars) -1), 1);
         }
         return $str;
diff --git a/src/includes/functions/TimeDiff.php b/src/includes/functions/TimeDiff.php
index 5c79ebb..d8af9c3 100644
--- a/src/includes/functions/TimeDiff.php
+++ b/src/includes/functions/TimeDiff.php
@@ -12,7 +12,7 @@
 
 class TimeDiff
 {
-	/**
+    /**
      * Get the difference between two datetimes as hours, minutes and seconds  (hh:mm:ss)
      *
      * If the time difference is less than 1 hour then only minutes and secconds will be shown
@@ -23,7 +23,8 @@ class TimeDiff
      *
      * @return  string  String representation of the time difference
      */
-    public static function calculate($start_date, $end_date) {
+    public static function calculate($start_date, $end_date)
+    {
         if ($end_date>$start_date) {	// If the start after the end, the result will be a minus
             $prefix = '';
             $remainder = $end_date - $start_date;
@@ -44,14 +45,17 @@ public static function calculate($start_date, $end_date) {
         $seconds = $remainder;
 
         // Put leading zeros on minutes and seconds (if required)
-        if ($minutes<=9) { $minutes = '0' . $minutes; }
-        if ($seconds<=9) { $seconds = '0' . $seconds; }
+        if ($minutes<=9) {
+            $minutes = '0' . $minutes;
+        }
+        if ($seconds<=9) {
+            $seconds = '0' . $seconds;
+        }
 
         // Return difference
         if ($hours>0) {
             return "$hours:$minutes:$seconds";
-        } else {
-            return "$minutes:$seconds";
         }
+        return "$minutes:$seconds";
     }
 }
diff --git a/src/includes/functions/XML.php b/src/includes/functions/XML.php
index 4b9f243..78d6a62 100644
--- a/src/includes/functions/XML.php
+++ b/src/includes/functions/XML.php
@@ -14,19 +14,18 @@
 
 class XML
 {
-     public static function validate($xml, $xsd){
-         libxml_use_internal_errors(true);
+    public static function validate($xml, $xsd)
+    {
+        libxml_use_internal_errors(true);
 
-         $objDom = new DOMDocument('1.0', 'utf-8');
+        $objDom = new DOMDocument('1.0', 'utf-8');
 
-         $objDom->loadXML($xml);
+        $objDom->loadXML($xml);
 
-         if (!$objDom->schemaValidate($xsd)) {
-
-    	     libxml_get_errors();
-             return false;
-         } else {
-            return true;
-         }
+        if (!$objDom->schemaValidate($xsd)) {
+            libxml_get_errors();
+            return false;
+        }
+        return true;
     }
 }
diff --git a/src/includes/inc_global.php b/src/includes/inc_global.php
index fea1bb8..f009cd6 100644
--- a/src/includes/inc_global.php
+++ b/src/includes/inc_global.php
@@ -11,50 +11,54 @@
 // Add composer's autoloader
 require __DIR__ . '/../../vendor/autoload.php';
 
-use WebPA\includes\classes\EngCIS;
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\DAO;
+use WebPA\includes\classes\EngCIS;
 use WebPA\includes\classes\UI;
 use WebPA\includes\classes\User;
 use WebPA\includes\functions\Common;
 
+// load environment config
+$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/../..');
+
+$dotenv->load();
+
 // Set the correct timezone for your server.
 date_default_timezone_set('Europe/London');
 
-/*
- * Configuration
- */
+// Configuration
 
 ////
 // User configuration section
 ////
 
-define('APP__WWW', '');
-define('DOC__ROOT', ''); //must include the trailing /
-define('CUSTOM_CSS', '');  // Optional custom CSS file
-define('SESSION_NAME', 'WEBPA');
+define('APP__WWW', $_ENV['APP_WWW']);
+define('DOC__ROOT', $_ENV['DOC_ROOT']); //must include the trailing /
+define('CUSTOM_CSS', $_ENV['CUSTOM_CSS_PATH']);  // Optional custom CSS file
+define('SESSION_NAME', $_ENV['SESSION_NAME']);
 ini_set('session.cookie_path', '/');
 
 // The month (1-12) in which the academic year is deemed to start (always on 1st of the month)
-define('APP__ACADEMIC_YEAR_START_MONTH', 9);
+define('APP__ACADEMIC_YEAR_START_MONTH', $_ENV['ACADEMIC_YEAR_START_MONTH']);
 
 //Database information
-define('APP__DB_HOST', ''); // If on a non-standard port, use this format:  <server>:<port>
-define('APP__DB_USERNAME', '');
-define('APP__DB_PASSWORD', '');
-define('APP__DB_DATABASE', '');
-define('APP__DB_TABLE_PREFIX', 'pa2_');
+define('APP__DB_HOST', $_ENV['DB_HOST']); // If on a non-standard port, use this format:  <server>:<port>
+define('APP__DB_USERNAME', $_ENV['DB_USER']);
+define('APP__DB_PASSWORD', $_ENV['DB_PASS']);
+define('APP__DB_DATABASE', $_ENV['DB_NAME']);
+define('APP__DB_TABLE_PREFIX', $_ENV['DB_PREFIX']);
 
 // Contact info
-define('APP__EMAIL_HELP', 'someone@email.com');
-define('APP__EMAIL_NO_REPLY', 'no-reply@email.com');
+define('APP__EMAIL_HELP', $_ENV['HELP_EMAIL']);
+define('APP__EMAIL_NO_REPLY', $_ENV['NO_REPLY_EMAIL']);
 
 // logo
-define('APP__INST_LOGO', APP__WWW.'/images/logo.png');
-define('APP__INST_LOGO_ALT','Your institution name');
+define('APP__INST_LOGO', $_ENV['LOGO_PATH']);
+define('APP__INST_LOGO_ALT', $_ENV['LOGO_ALT_TEXT']);
 
 //the following lines are to accomodate the image size within the css file to prevent the image from over flowing the area provided
-define('APP__INST_HEIGHT', '25'); //image height in pixels
-define('APP__INST_WIDTH', '102'); //image width in pixels
+define('APP__INST_HEIGHT', $_ENV['LOGO_HEIGHT']); //image height in pixels
+define('APP__INST_WIDTH', $_ENV['LOGO_WIDTH']); //image width in pixels
 
 //define whether the option to allow textual input is allowed
 /*NB. In the UK if requested any information about the student would need to be
@@ -63,38 +67,23 @@
 * dependant on this act.
 *
 */
-define('APP__ALLOW_TEXT_INPUT', TRUE);
+define('APP__ALLOW_TEXT_INPUT', $_ENV['ALLOW_TEXT_INPUT'] === 'true');
 
 // enable delete options for users and modules
-define('APP__ENABLE_USER_DELETE', FALSE);
-define('APP__ENABLE_MODULE_DELETE', FALSE);
+define('APP__ENABLE_USER_DELETE', $_ENV['ENABLE_USER_DELETE'] === 'true');
+define('APP__ENABLE_MODULE_DELETE', $_ENV['ENABLE_MODULE_DELETE'] === 'true');
 
 // set the mail server variables if different mail server is to be used.
-ini_set('SMTP','localhost');
-ini_set('smtp_port','25');
+ini_set('SMTP', $_ENV['SMTP_HOST']);
+ini_set('smtp_port', $_ENV['SMTP_PORT']);
 // if using a windows structure you need to set the send mail from
-ini_set('sendmail_from','someone@email.com');
+ini_set('sendmail_from', $_ENV['EMAIL_ADDRESS']);
 
 //define the authentication to be used and in the order they are to be applied
 $LOGIN_AUTHENTICATORS[] = 'DB';
-$LOGIN_AUTHENTICATORS[] = 'LDAP';
-
-// LDAP settings
-define('LDAP__HOST', "kdc.lboro.ac.uk");
-define('LDAP__PORT', 3268);
-define('LDAP__USERNAME_EXT', '@lboro.ac.uk');
-define('LDAP__BASE', 'dc=lboro, dc=ac, dc=uk');
-define('LDAP__FILTER', 'name={username}*');
-define('LDAP__BINDRDN', '');
-define('LDAP__PASSWD', '');
-$LDAP__INFO_REQUIRED = array('displayname','mail','sn');
-// Name of attribute to use to check user type (via function below)
-define('LDAP__USER_TYPE_ATTRIBUTE', 'description');
-define('LDAP__DEBUG_LEVEL', 7);
-define('LDAP__AUTO_CREATE_USER', TRUE);
 
 // define installed modules
-$INSTALLED_MODS = array();
+$INSTALLED_MODS = [];
 
 ////
 // System configuration section - do not change unless you know what you're doing!
@@ -104,14 +93,9 @@
 define('APP__NAME', 'WebPA OS');
 define('APP__TITLE', 'WebPA OS : Online Peer Assessment System');
 define('APP__ID', 'webpa');
-define('APP__VERSION', '3.1.1');
-define('APP__DESCRIPTION','WebPA, an Open source, online peer assessment system.');
-define('APP__KEYWORDS','peer assessment, online, peer, assessment, tools, open source');
-
-define('APP__DB_TYPE', 'MySQLDAO');
-
-define('APP__DB_PERSISTENT', FALSE);
-define('APP__DB_CLIENT_FLAGS', 2);
+define('APP__VERSION', '3.1.2');
+define('APP__DESCRIPTION', 'WebPA, an Open source, online peer assessment system.');
+define('APP__KEYWORDS', 'peer assessment, online, peer, assessment, tools, open source');
 
 // User types
 define('APP__USER_TYPE_ADMIN', 'A');
@@ -119,21 +103,20 @@
 define('APP__USER_TYPE_STUDENT', 'S');
 
 //Moodle gradebook output allowed...
-define('APP__MOODLE_GRADEBOOK', FALSE); // If the grade book xml for moodle can be output then set to true, else if not required set to false
+define('APP__MOODLE_GRADEBOOK', $_ENV['ENABLE_MOODLE_GRADEBOOK'] === 'true'); // If the grade book xml for moodle can be output then set to true, else if not required set to false
 
 //Automatic emailing options.
-//this is dependant on cron jobs being set for the following files;
-//  /tutors/assessments/email/TriggerReminder.php
-//  /tutors/assessments/email/ClosingReminber.php
-define('APP__REMINDER_OPENING', FALSE);
-define('APP__REMINDER_CLOSING', FALSE);
+//this is dependant on a cron job being set to run against the following file:
+//  /jobs/Email.php
+define('APP__REMINDER_OPENING', $_ENV['SEND_OPENING_REMINDER'] === 'true');
+define('APP__REMINDER_CLOSING', $_ENV['SEND_CLOSING_REMINDER'] === 'true');
 
 //set in individual pages to link to the most appropriate help sections.
 //this is not an option that can be changed in the configuration
-define ('APP__HELP_LINK','http://www.webpaproject.com/');
+define('APP__HELP_LINK', 'http://www.webpaproject.com/');
 
 //define the terminology presented to the student as mark, rating or score
-define('APP__MARK_TEXT', 'Score(s)');
+define('APP__MARK_TEXT', $_ENV['MARK_TERMINOLOGY']);
 
 // Collection owner types
 define('APP__COLLECTION_USER', 'user');
@@ -142,7 +125,7 @@
 //ordinal scale
 //This scale is used in the reports as some institution and academic tutors prefer this scale.
 //However, it must be noted that the majority of universities in the UK are using arithmetic mean for classifications.
-$ordinal_scale = array (
+$ordinal_scale = [
   'A+' => '78',
   'A'  => '75',
   'B+' => '68',
@@ -159,13 +142,13 @@
   'X'  => '25',
   'X-' => '15',
   'Z'  =>'0',
-);
+];
 
 // When reporting grades as decimals, define the precision, etc using this constant
-define('APP__REPORT_DECIMALS', "%01.2f");
+define('APP__REPORT_DECIMALS', '%01.2f');
 
 // File upload error messages
-$FILE_ERRORS = array(
+$FILE_ERRORS = [
   UPLOAD_ERR_OK => 'There is no error, the file uploaded with success.',
   UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds the upload_max_filesize directive in php.ini.',
   UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.',
@@ -173,8 +156,8 @@
   UPLOAD_ERR_NO_FILE => 'No file was uploaded.',
   UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder.',
   UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk.',
-  UPLOAD_ERR_EXTENSION => 'A PHP extension stopped the file upload.'
-  );
+  UPLOAD_ERR_EXTENSION => 'A PHP extension stopped the file upload.',
+  ];
 
 // Old config compatibility
 $_config['app_id'] = APP__ID;
@@ -187,19 +170,18 @@
 
 // Initialise DB object
 
-$DB = new DAO( APP__DB_HOST, APP__DB_USERNAME, APP__DB_PASSWORD, APP__DB_DATABASE);
-$DB->set_debug(FALSE);
+$DB = new DAO(APP__DB_HOST, APP__DB_USERNAME, APP__DB_PASSWORD, APP__DB_DATABASE);
 
 // Initialise User Object
 
 $_user = null;
 
 // Get info from the session
-$_user_id = Common::fetch_SESSION('_user_id', NULL);
-$_user_source_id = Common::fetch_SESSION('_user_source_id', NULL);
-$_user_context_id = Common::fetch_SESSION('_user_context_id', NULL);
+$_user_id = Common::fetch_SESSION('_user_id', null);
+$_user_source_id = Common::fetch_SESSION('_user_source_id', null);
+$_user_context_id = Common::fetch_SESSION('_user_context_id', null);
 $_source_id = Common::fetch_SESSION('_source_id', '');
-$_module_id = Common::fetch_SESSION('_module_id', NULL);
+$_module_id = Common::fetch_SESSION('_module_id', null);
 $BRANDING['logo'] = Common::fetch_SESSION('branding_logo', APP__INST_LOGO);
 $BRANDING['logo.width'] = Common::fetch_SESSION('branding_logo.width', APP__INST_WIDTH);
 $BRANDING['logo.height'] = Common::fetch_SESSION('branding_logo.height', APP__INST_HEIGHT);
@@ -212,46 +194,34 @@
 $CIS = new EngCIS($_source_id, $_module_id);
 
 // If we found a user to load, load 'em!
-if ($_user_id){
-
-  $_user_info = $CIS->get_user($_user_id);
+if ($_user_id) {
+    $_user_info = $CIS->get_user($_user_id);
 
-  // Actually create the user object
-  $_user = new User();
-  $_user->load_from_row($_user_info);
-  $_user_info = null;   // We're done with the data, so clear it
+    // Actually create the user object
+    $_user = new User();
+    $_user->load_from_row($_user_info);
+    $_user_info = null;   // We're done with the data, so clear it
 
-  // save session data
-  $_SESSION['_user_id'] = $_user->id;
+    // save session data
+    $_SESSION['_user_id'] = $_user->id;
 }
 
 if (!is_null($_user)) {
     $CIS->setUser($_user);
 }
 
-// If we found a module to load, load it!
-if ($_module_id){
-  $sql_module = 'SELECT module_id, module_code, module_title FROM ' . APP__DB_TABLE_PREFIX . "module WHERE module_id = {$_SESSION['_module_id']}";
-  $_module = $DB->fetch_row($sql_module);
-  $_module_code = $_module['module_code'];
-
-}
-
-$UI = new UI($INSTALLED_MODS, $_source_id, $BRANDING, $CIS, $_module, $_user);
-
-function get_LDAP_user_type($data) {
+// initialise module
+$_module = null;
 
-    $description_str = $data[0];
+// If we found a module to load, load it!
+if ($_module_id) {
+    $dbConn = $DB->getConnection();
 
-    //check in the string for staff
-    if(strripos ($description_str, 'staff') !== false) {
-      $user_type = APP__USER_TYPE_TUTOR;
-    } else {
-      $user_type = APP__USER_TYPE_STUDENT;
-    }
+    $query = 'SELECT module_id, module_code, module_title FROM ' . APP__DB_TABLE_PREFIX . 'module WHERE module_id = ?';
 
-  return $user_type;
+    $_module = $dbConn->fetchAssociative($query, [$_SESSION['_module_id']], [ParameterType::INTEGER]);
 
+    $_module_code = $_module['module_code'];
 }
 
-?>
+$UI = new UI($INSTALLED_MODS, $_source_id, $BRANDING, $CIS, $_module, $_user);
diff --git a/src/index.php b/src/index.php
index 8f0c44b..5649f4c 100644
--- a/src/index.php
+++ b/src/index.php
@@ -8,33 +8,31 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once('includes/inc_global.php');
+require_once 'includes/inc_global.php';
 
 $mod = '';
 if (isset($_SERVER['PATH_INFO']) && (strlen($_SERVER['PATH_INFO']) > 0)) {
-  $mod = substr($_SERVER['PATH_INFO'], 1);
-} else if (isset($_SERVER['QUERY_STRING'])) {
-  $mod = $_SERVER['QUERY_STRING'];
+    $mod = substr($_SERVER['PATH_INFO'], 1);
+} elseif (isset($_SERVER['QUERY_STRING'])) {
+    $mod = $_SERVER['QUERY_STRING'];
 }
 
 if ($mod && in_array($mod, $INSTALLED_MODS)) {
-  if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') {
-    include_once("mod/{$mod}/index.php");
-  } else {
-    header('Location: ' . APP__WWW . "/mod/{$mod}/");
-  }
-} else if ($_user) {
-  if ($_user->is_admin()) {
-    header('Location: ' . APP__WWW . '/admin/');
-  } else if ($_user->is_tutor()) {
-    header('Location: ' . APP__WWW . '/tutors/');
-  } else {
-    header('Location: ' . APP__WWW . '/students/');
-  }
+    if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') {
+        include_once "mod/{$mod}/index.php";
+    } else {
+        header('Location: ' . APP__WWW . "/mod/{$mod}/");
+    }
+} elseif ($_user) {
+    if ($_user->is_admin()) {
+        header('Location: ' . APP__WWW . '/admin/');
+    } elseif ($_user->is_tutor()) {
+        header('Location: ' . APP__WWW . '/tutors/');
+    } else {
+        header('Location: ' . APP__WWW . '/students/');
+    }
 } else {
-  header('Location: ' . APP__WWW . '/login.php');
+    header('Location: ' . APP__WWW . '/login.php');
 }
 
 exit;
-
-?>
diff --git a/src/install/install.txt b/src/install/install.txt
deleted file mode 100644
index 12478ac..0000000
--- a/src/install/install.txt
+++ /dev/null
@@ -1,28 +0,0 @@
-WebPA 2.0.0.10
-==============
-
-Installation Guide
-------------------
-
-*  Edit the includes/inc_global.php file in the includes directory to configure the application; in particular:
-     - APP__WWW: URL to the instance of WebPA (without a closing "/");
-     - DOC__ROOT: directory path to the WebPA files (with a closing "/" or "\\");
-     - database settings:
-        - APP__DB_HOST: host name
-        - APP__DB_USERNAME: username
-        - APP__DB_PASSWORD: password
-        - APP__DB_DATABASE: database name
-        - APP__DB_TABLE_PREFIX: table prefix (default is "pa2_" which means that the new version can share the same database as the old version if required)
-     - configure the LDAP settings if you wish to authenticate via LDAP.
-     
-*  Run the following scripts to initialise the database (edit the files to change the names and password as required):
-     - install/webpa2_database.sql: create the database schema and user account;
-     - install/webpa2_tables.sql: create the database tables;
-     - install/webpa2_administrator.sql: create an administrator account and sample module.
-     
-*  Login to WebPA:
-		 - navigate to root of WebPA application;
-		 - enter a username of "admin" and a password of "admin"
-		 - change the password to something more secure after logging in
-		 
-*  Delete the "install" folder when you're finished.
\ No newline at end of file
diff --git a/src/install/upgrades/webpa_security_update.sql b/src/install/upgrades/webpa_security_update.sql
new file mode 100644
index 0000000..b836559
--- /dev/null
+++ b/src/install/upgrades/webpa_security_update.sql
@@ -0,0 +1,2 @@
+ALTER TABLE pa2_user MODIFY COLUMN password VARCHAR(255);
+ALTER TABLE pa2_user_reset_request MODIFY COLUMN hash VARCHAR(255);
\ No newline at end of file
diff --git a/src/install/webpa2_tables.sql b/src/install/webpa2_tables.sql
index 61e096d..26898c4 100644
--- a/src/install/webpa2_tables.sql
+++ b/src/install/webpa2_tables.sql
@@ -77,7 +77,7 @@ CREATE TABLE pa2_user (
   user_id int(10) unsigned NOT NULL AUTO_INCREMENT,
   source_id varchar(255) NOT NULL DEFAULT '',
   username varchar(255) NOT NULL,
-  `password` varchar(45) NOT NULL,
+  `password` varchar(255) NOT NULL,
   id_number varchar(255) DEFAULT NULL,
   department_id varchar(255) DEFAULT NULL,
   forename varchar(255) NOT NULL,
diff --git a/src/jobs/Email.php b/src/jobs/Email.php
new file mode 100644
index 0000000..e2fa06a
--- /dev/null
+++ b/src/jobs/Email.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace WebPA\jobs;
+
+use WebPA\tutors\assessments\email\ClosingReminder;
+use WebPA\tutors\assessments\email\TriggerReminder;
+
+require __DIR__ . '/../includes/inc_global.php';
+
+// execute email closing reminders
+$closingReminder = new ClosingReminder($DB);
+
+$closingReminder->send();
+
+// execute email trigger reminder
+
+$triggerReminder = new TriggerReminder($DB);
+
+$triggerReminder->send();
diff --git a/src/keep_alive.php b/src/keep_alive.php
index 1c7a5eb..707e4f3 100644
--- a/src/keep_alive.php
+++ b/src/keep_alive.php
@@ -1,5 +1,5 @@
 <?php
-require_once("includes/inc_global.php");
+require_once 'includes/inc_global.php';
 ?>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">
@@ -23,7 +23,7 @@ function body_onload() {
 </head>
 <body onload="body_onload();">
 
-<?php echo( gmdate('H:i:s d-m-Y') ); ?>
+<?php echo gmdate('H:i:s d-m-Y'); ?>
 
 </body>
 </html>
\ No newline at end of file
diff --git a/src/lang/en/Generic.php b/src/lang/en/Generic.php
index 18e416e..41da0ca 100644
--- a/src/lang/en/Generic.php
+++ b/src/lang/en/Generic.php
@@ -17,12 +17,17 @@
 class Generic
 {
     public const MY__FORMS = 'my forms';
+
     public const MY__GROUPS = 'my groups';
+
     public const MY__ASSESSMENTS = 'my assessments';
 
     public const GROUPS = 'Groups';
+
     public const NO__GROUPS = 'Number of Groups';
+
     public const EDIT__GROUP = 'edit group';
+
     public const DELETE__GROUP = 'delete group';
 
     public const EDIT_QUESTION = 'edit question';
@@ -30,15 +35,20 @@ class Generic
     public const PLEASE__NOTE = '<strong>Please Note:</strong>';
 
     public const UNKNOWN__COLLECTION = 'Unknown Collection';
+
     public const EDDITING__UNKNOWN_GROUP = 'Editing: Unknown Group';
+
     public const EDDITING__GROUP = 'Editing Group';
 
     public const BTN__LIST_GROUPS = 'List Groups';
+
     public const BTN__CREATE_GROUPS = 'Create Groups';
+
     public const BTN__CLONE_GROUPS = 'Clone Groups';
 
     public const BTN__SAVE_CHANGES = 'save changes';
 
     public const FOLLOWING__FOUND = 'The following errors were found';
+
     public const NO_CHANGES = 'No changes have been saved. Please check the details in the form, and try again.';
 }
diff --git a/src/lang/en/tutors/Tutors.php b/src/lang/en/tutors/Tutors.php
index 145f868..60ef74c 100644
--- a/src/lang/en/tutors/Tutors.php
+++ b/src/lang/en/tutors/Tutors.php
@@ -16,32 +16,45 @@
 
 class Tutors
 {
-   public const WELCOME = 'Welcome to WebPA, the easiest way for your students to carry out peer assessment reviews on the web. Using this system, students doing group work activities can mark each other\'s contributions, providing each student with an overall score.';
-   public const SECTIONS__INTRO = 'WebPA contains the following sections:';
-   public const OPT__FORMS__DESC = 'Create peer assessment forms for your students to complete. You can re-use your forms with many different assessments.';
-   public const OPT__GROUPS__DESC = 'Organise your students into groups. You can create new groups from scratch, or use existing groups that have been set up by other staff members.';
-   public const OPT__ASSESSMENTS__DESC = 'Create, edit and schedule your peer assessments sessions so they only run how and when you want.';
-   public const GETTING__STARTED__TITLE = 'Getting Started';
-   public const GETTING__STARTED__DESC = 'The fastest way to get started is for you to choose <a href="forms/">my forms</a> from the left-hand menu, there you can begin creating a peer assessment form that your students will use later to grade each other.';
+    public const WELCOME = 'Welcome to WebPA, the easiest way for your students to carry out peer assessment reviews on the web. Using this system, students doing group work activities can mark each other\'s contributions, providing each student with an overall score.';
 
-   public const GROUPS__WELCOME = 'Here you can edit your groups, and organise how students are allocated to the individual groups.';
-   public const GROUPS__TITLE = 'Existing Groups';
-   public const NO__GROUPS__DESC = 'You have no groups. To add a collection use the <a href="create/">create new groups wizard</a>.';
-   public const GROUPS__INSTRUCT__1 = 'These are your groups. To view or edit a collection of groups, click on ';
-   public const GROUPS__INSTRUCT__2 = 'in the list below.';
+    public const SECTIONS__INTRO = 'WebPA contains the following sections:';
 
-   public const GROUPS__NOTE ='Any changes you make to your groups here will <strong>not</strong> affect any assessments you may have created. If you want to change the groups in use with an assessment, you must edit the assessment and choose the option to select a new set of groups.';
+    public const OPT__FORMS__DESC = 'Create peer assessment forms for your students to complete. You can re-use your forms with many different assessments.';
 
-   public const GROUPS__EDIT__DESC =  'Here you can edit your collections of groups, and organise how students are allocated to the individual groups.';
-   public const GROUPS__EDIT_TITLE = 'Group Collections';
-   public const NO_COLLECTIONS ='You have no collections. To add a collection use the <a href="../create/">create new groups wizard</a>.';
-   public const GROUPS__EDIT__INST = 'These are your group collections. To view or edit a collection, click on its name in the list below:';
+    public const OPT__GROUPS__DESC = 'Organise your students into groups. You can create new groups from scratch, or use existing groups that have been set up by other staff members.';
 
-   public const GROUPS__EDIT_SAVE_ERR ='You must give this group a name.';
+    public const OPT__ASSESSMENTS__DESC = 'Create, edit and schedule your peer assessments sessions so they only run how and when you want.';
 
-   public const COLLECTION__LOCKED ='<p>This group belongs to a collection that has been locked, and cannot be edited. You can still view the details of this group, but not edit its name or members.</p>';
+    public const GETTING__STARTED__TITLE = 'Getting Started';
 
-   public const GROUPS__EDIT_INST =  '<p>On this page you can change the name of this group, and add/remove students from it.</p>';
-   public const GROUP__SELECTED = '<p>The group you selected could not be loaded for some reason - please go back and try again.</p>';
-}
+    public const GETTING__STARTED__DESC = 'The fastest way to get started is for you to choose <a href="forms/">my forms</a> from the left-hand menu, there you can begin creating a peer assessment form that your students will use later to grade each other.';
+
+    public const GROUPS__WELCOME = 'Here you can edit your groups, and organise how students are allocated to the individual groups.';
+
+    public const GROUPS__TITLE = 'Existing Groups';
+
+    public const NO__GROUPS__DESC = 'You have no groups. To add a collection use the <a href="create/">create new groups wizard</a>.';
+
+    public const GROUPS__INSTRUCT__1 = 'These are your groups. To view or edit a collection of groups, click on ';
+
+    public const GROUPS__INSTRUCT__2 = 'in the list below.';
+
+    public const GROUPS__NOTE ='Any changes you make to your groups here will <strong>not</strong> affect any assessments you may have created. If you want to change the groups in use with an assessment, you must edit the assessment and choose the option to select a new set of groups.';
+
+    public const GROUPS__EDIT__DESC =  'Here you can edit your collections of groups, and organise how students are allocated to the individual groups.';
 
+    public const GROUPS__EDIT_TITLE = 'Group Collections';
+
+    public const NO_COLLECTIONS ='You have no collections. To add a collection use the <a href="../create/">create new groups wizard</a>.';
+
+    public const GROUPS__EDIT__INST = 'These are your group collections. To view or edit a collection, click on its name in the list below:';
+
+    public const GROUPS__EDIT_SAVE_ERR ='You must give this group a name.';
+
+    public const COLLECTION__LOCKED ='<p>This group belongs to a collection that has been locked, and cannot be edited. You can still view the details of this group, but not edit its name or members.</p>';
+
+    public const GROUPS__EDIT_INST =  '<p>On this page you can change the name of this group, and add/remove students from it.</p>';
+
+    public const GROUP__SELECTED = '<p>The group you selected could not be loaded for some reason - please go back and try again.</p>';
+}
diff --git a/src/login.php b/src/login.php
index ea59948..929a04c 100644
--- a/src/login.php
+++ b/src/login.php
@@ -11,7 +11,7 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("includes/inc_global.php");
+require_once 'includes/inc_global.php';
 
 use WebPA\includes\functions\Common;
 
@@ -21,37 +21,37 @@
 $msg = Common::fetch_GET('msg', null);
 
 switch ($msg) {
-  case 'connfailed' :
+  case 'connfailed':
         $message_class = 'warning';
         $message = 'A connection to the authentication server could not be established.<br />Please try again later.';
         break;
   // --------------------
-  case 'denied' :
+  case 'denied':
         $message_class = 'warning';
         $message = 'You attempted to access a restricted page.<br />It may be that your session has timed out so please re-enter your details.';
         break;
   // --------------------
-  case 'no access' :
+  case 'no access':
         $message_class = 'warning';
         $message = 'Your account has been disabled.<br />Please contact support if you do not think this should be the case.';
         break;
   // --------------------
-  case 'invalid' :
+  case 'invalid':
         $message_class = 'warning';
         $message = 'Your username and password were rejected.<br />Please check your details and try again.';
         break;
   // --------------------
-  case 'cookies' :
+  case 'cookies':
         $message_class = 'warning';
         $message = 'Unable to connect to ' . APP__NAME . '; please ensure that your browser is not blocking third-party cookies';
         break;
   // --------------------
-  case 'logout' :
+  case 'logout':
         $message_class = 'info';
         $message = 'You have logged out.<br />If you wish to log back in, please re-enter your details.';
         break;
   // --------------------
-  default :
+  default:
         $message_class = 'info';
         $message = 'To start using ' . APP__NAME . ' you have to log in.';
         break;
@@ -63,9 +63,9 @@
 $UI->page_title = APP__NAME . ' Login';
 $UI->menu_selected = '';
 $UI->help_link = '?q=node/26';
-$UI->breadcrumbs = array  (
-  'login page'  => null ,
-);
+$UI->breadcrumbs = [
+  'login page'  => null,
+];
 
 
 $UI->head();
@@ -96,7 +96,7 @@ function username_focus() {
 ?>
 
 
-<?php echo("<p class=\"$message_class\">$message</p>"); ?>
+<?php echo "<p class=\"$message_class\">$message</p>"; ?>
 
 <div class="content_box">
 
diff --git a/src/login_check.php b/src/login_check.php
index 36b14f7..c55d49e 100644
--- a/src/login_check.php
+++ b/src/login_check.php
@@ -16,7 +16,7 @@
 
 namespace WebPA;
 
-require_once("./includes/inc_global.php");
+require_once './includes/inc_global.php';
 
 use WebPA\includes\functions\Common;
 
@@ -26,14 +26,6 @@
 $username = (string) Common::fetch_POST('username');
 $password = (string) Common::fetch_POST('password');
 
-// Sanitize the username/password data
-$username = substr($username,0,255);
-$password = substr($password,0,255);
-
-$DB->open();
-$username = $DB->escape_str($username);
-$password = $DB->escape_str($password);
-
 $msg ='';
 
 // --------------------------------------------------------------------------------
@@ -41,71 +33,55 @@
 
 $auth_success = false;
 
-if ( ($username) && ($password) ) {
-
-  $authenticated = FALSE;
+if (($username) && ($password)) {
+    $authenticated = false;
 
-  // Authenticate...
-  for ($i = 0; $i < count($LOGIN_AUTHENTICATORS); $i++) {
-    $classname = 'WebPA\includes\classes\\' . $LOGIN_AUTHENTICATORS[$i] . 'Authenticator';
+    // Authenticate...
+    for ($i = 0; $i < count($LOGIN_AUTHENTICATORS); $i++) {
+        $classname = 'WebPA\includes\classes\\' . $LOGIN_AUTHENTICATORS[$i] . 'Authenticator';
 
-    $_auth = new $classname($CIS, $username, $password);
-
-    if ($LOGIN_AUTHENTICATORS[$i] === 'LDAP') {
-      $_auth->setRequiredInfo($LDAP__INFO_REQUIRED);
-    }
+        $_auth = new $classname($CIS, $username, $password);
 
-    if ($_auth->authenticate()) {
-      $authenticated = TRUE;
-      break;
+        if ($_auth->authenticate()) {
+            $authenticated = true;
+            break;
+        }
     }
-  }
 
-  if (!$authenticated) {
-
-    $msg = 'invalid';
-
-    //but just to be sure check for an authorisation failed message
-    $auth_failed = $_auth->get_error();
-
-    if(strlen($auth_failed) > 0){
-      $msg = $auth_failed;
+    if (!$authenticated) {
+        $msg = 'invalid';
+
+        //but just to be sure check for an authorisation failed message
+        $auth_failed = $_auth->get_error();
+
+        if (strlen($auth_failed) > 0) {
+            $msg = $auth_failed;
+        }
+    } elseif ($_auth->is_disabled()) {
+        $msg = 'no access';
+    } else {
+        $_SESSION = [];
+        session_destroy();
+        session_name(SESSION_NAME);
+        session_start();
+
+        // Save session data
+        $_SESSION['_user_id'] = $_auth->user_id;
+        $_SESSION['_user_source_id'] = $_auth->source_id;
+        $_SESSION['_user_type'] = $_auth->user_type;
+        $_SESSION['_source_id'] = $_auth->source_id;
+        $_SESSION['_module_id'] = $_auth->module_id;
+        $_SESSION['_user_context_id'] = $_auth->module_code;
+
+        Common::logEvent($DB, 'Login');
+        Common::logEvent($DB, 'Enter module', $_auth->module_id);
+
+        header('Location: ' . APP__WWW . "/index.php?id={$_user_id}"); // This doesn't log them in, the user_id just shows as a debug check
+        exit;
     }
-
-  } else if ($_auth->is_disabled()) {
-
-    $msg = 'no access';
-
-  } else {
-
-    $_SESSION = array();
-    session_destroy();
-    session_name(SESSION_NAME);
-    session_start();
-
-    // Save session data
-    $_SESSION['_user_id'] = $_auth->user_id;
-    $_SESSION['_user_source_id'] = $_auth->source_id;
-    $_SESSION['_user_type'] = $_auth->user_type;
-    $_SESSION['_source_id'] = $_auth->source_id;
-    $_SESSION['_module_id'] = $_auth->module_id;
-    $_SESSION['_user_context_id'] = $_auth->module_code;
-
-    Common::logEvent($DB, 'Login');
-    Common::logEvent($DB, 'Enter module', $_auth->module_id);
-
-    header('Location: ' . APP__WWW . "/index.php?id={$_user_id}"); // This doesn't log them in, the user_id just shows as a debug check
-    exit;
-
-  }
-
 } else {
-
-  $msg = '';
-
+    $msg = '';
 }
 
 header('Location: ' . APP__WWW . "/login.php?msg={$msg}");
 exit;
-
-?>
diff --git a/src/logout.php b/src/logout.php
index cd364b4..f189d81 100644
--- a/src/logout.php
+++ b/src/logout.php
@@ -8,56 +8,59 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("includes/inc_global.php");
+require_once 'includes/inc_global.php';
 
 use WebPA\includes\functions\Common;
 
 if (isset($_SESSION['_user_id'])) {
-  Common::logEvent($DB, 'Logout');
+    Common::logEvent($DB, 'Logout');
 }
 
 $old_session = $_SESSION;
-$_SESSION = array();
+$_SESSION = [];
 session_destroy();
 
 if (isset($old_session['logout_url'])) {
-  $url = $old_session['logout_url'];
-  if ($_SERVER['QUERY_STRING']) {
-    if (strpos($url, '?') === FALSE) {
-      $url .= '?';
-    } else {
-      $url .= '&';
+    $url = $old_session['logout_url'];
+    if ($_SERVER['QUERY_STRING']) {
+        if (strpos($url, '?') === false) {
+            $url .= '?';
+        } else {
+            $url .= '&';
+        }
+        $url .= $_SERVER['QUERY_STRING'];
+    }
+    if (ini_get('session.use_cookies')) {
+        $params = session_get_cookie_params();
+        setcookie(
+            session_name(),
+            '',
+            time() - 42000,
+            $params['path'],
+            $params['domain'],
+            $params['secure'],
+            $params['httponly']
+        );
     }
-    $url .= $_SERVER['QUERY_STRING'];
-  }
-  if (ini_get('session.use_cookies')) {
-    $params = session_get_cookie_params();
-    setcookie(session_name(), '', time() - 42000,
-      $params["path"], $params["domain"],
-      $params["secure"], $params["httponly"]);
-  }
 } else {
-  $msg = (Common::fetch_GET('msg',null)) ? Common::fetch_GET('msg',null) : 'logout' ;
-  $url = "login.php?msg=$msg";
-  session_start();
-  if (isset($old_session['branding_logo'])) {
-    $_SESSION['branding_logo'] = $old_session['branding_logo'];
-  }
-  if (isset($old_session['branding_logo.width'])) {
-    $_SESSION['branding_logo.width'] = $old_session['branding_logo.width'];
-  }
-  if (isset($old_session['branding_logo.height'])) {
-    $_SESSION['branding_logo.height'] = $old_session['branding_logo.height'];
-  }
-  if (isset($old_session['branding_name'])) {
-    $_SESSION['branding_name'] = $old_session['branding_name'];
-  }
-  if (isset($old_session['branding_css'])) {
-    $_SESSION['branding_css'] = $old_session['branding_css'];
-  }
-
+    $msg = (Common::fetch_GET('msg', null)) ? Common::fetch_GET('msg', null) : 'logout' ;
+    $url = "login.php?msg=$msg";
+    session_start();
+    if (isset($old_session['branding_logo'])) {
+        $_SESSION['branding_logo'] = $old_session['branding_logo'];
+    }
+    if (isset($old_session['branding_logo.width'])) {
+        $_SESSION['branding_logo.width'] = $old_session['branding_logo.width'];
+    }
+    if (isset($old_session['branding_logo.height'])) {
+        $_SESSION['branding_logo.height'] = $old_session['branding_logo.height'];
+    }
+    if (isset($old_session['branding_name'])) {
+        $_SESSION['branding_name'] = $old_session['branding_name'];
+    }
+    if (isset($old_session['branding_css'])) {
+        $_SESSION['branding_css'] = $old_session['branding_css'];
+    }
 }
 
 header("Location: $url");
-
-?>
diff --git a/src/module.php b/src/module.php
index 6019ce8..ef3d000 100644
--- a/src/module.php
+++ b/src/module.php
@@ -8,41 +8,53 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("includes/inc_global.php");
+require_once 'includes/inc_global.php';
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\functions\Common;
 
 if (($_source_id != '') && !$_user->is_admin()) {
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 $module_id = Common::fetch_POST('module_id');
 
 if ($module_id) {
+    // Update last module
+    $updateLastModuleQuery =
+      'UPDATE ' . APP__DB_TABLE_PREFIX . 'user ' .
+      'SET last_module_id = ? ' .
+      'WHERE user_id = ?';
 
-  // Update last module
-  $sql_last_module = 'UPDATE ' . APP__DB_TABLE_PREFIX . "user SET last_module_id = '{$module_id}' WHERE user_id = '{$_user_id}'";
-  $DB->execute($sql_last_module);
+    $DB->getConnection()->executeQuery(
+        $updateLastModuleQuery,
+        [$module_id, $_user_id],
+        [ParameterType::INTEGER, ParameterType::INTEGER]
+    );
 
-  // Update session
-  $sql_module = 'SELECT module_code FROM ' . APP__DB_TABLE_PREFIX . "module WHERE module_id = {$module_id}";
-  $module = $DB->fetch_row($sql_module);
-  $_SESSION['_module_id'] = $module_id;
-  $_SESSION['_user_context_id'] = $module['module_code'];
+    // Update session
+    $dbConn = $DB->getConnection();
 
-  Common::logEvent($DB, 'Leave module', $_module_id);
-  Common::logEvent($DB, 'Enter module', $module_id);
+    $query = 'SELECT module_code FROM ' . APP__DB_TABLE_PREFIX . 'module WHERE module_id = ?';
 
-  header('Location: ' . APP__WWW . "/");
-  exit;
+    $moduleCode = $dbConn->fetchOne($query, [$module_id], [ParameterType::INTEGER]);
 
+    $_SESSION['_module_id'] = $module_id;
+    $_SESSION['_user_context_id'] = $moduleCode;
+
+    Common::logEvent($DB, 'Leave module', $_module_id);
+    Common::logEvent($DB, 'Enter module', $module_id);
+
+    header('Location: ' . APP__WWW . '/');
+
+    exit;
 }
 
 //set the page information
 $UI->page_title = 'Change Module';
 $UI->menu_selected = 'change module';
-$UI->breadcrumbs = array ('home' => './', 'change source' => null);
+$UI->breadcrumbs = ['home' => './', 'change source' => null];
 $UI->help_link = '?q=node/237';
 $UI->head();
 $UI->body();
@@ -62,31 +74,31 @@
 <?php
   //get the modules associated with the user being edited
   if ($_user->is_admin()) {
-    $modules = $CIS->get_user_modules(NULL, NULL, 'name');
+      $modules = $CIS->get_user_modules(null, null, 'name');
   } else {
-    $modules = $CIS->get_user_modules($_user->id, NULL, 'name');
+      $modules = $CIS->get_user_modules($_user->id, null, 'name');
   }
 
-    echo "<table>";
+    echo '<table>';
     if (count($modules) > 0) {
-      foreach ($modules as $id => $module) {
-        $checked_str = (isset($_module_id) && ($id == $_module_id)) ? ' checked="checked"' : '' ;
-        echo('<tr>');
-        echo("  <td><input type=\"radio\" name=\"module_id\" id=\"module_{$id}\" value=\"{$id}\"{$checked_str} /></td>");
-        echo("  <td><label style=\"font-weight: normal;\" for=\"module_{$id}\">{$module['module_title']} [{$module['module_code']}]</label></td>");
-        echo('</tr>');
-      }
+        foreach ($modules as $id => $module) {
+            $checked_str = (isset($_module_id) && ($id == $_module_id)) ? ' checked="checked"' : '' ;
+            echo '<tr>';
+            echo "  <td><input type=\"radio\" name=\"module_id\" id=\"module_{$id}\" value=\"{$id}\"{$checked_str} /></td>";
+            echo "  <td><label style=\"font-weight: normal;\" for=\"module_{$id}\">{$module['module_title']} [{$module['module_code']}]</label></td>";
+            echo '</tr>';
+        }
     } else {
-      echo('<tr>');
-      echo('  <td colspan="2">No modules</td>');
-      echo('</tr>');
+        echo '<tr>';
+        echo '  <td colspan="2">No modules</td>';
+        echo '</tr>';
     }
 ?>
 </table>
 </div>
 <?php
   if (count($modules) > 0) {
-?>
+      ?>
 <p>
 <input type="submit" value="Select module" />
 </p>
diff --git a/src/students/assessments/assessment_feedback.php b/src/students/assessments/assessment_feedback.php
index affb66c..2ffacfb 100644
--- a/src/students/assessments/assessment_feedback.php
+++ b/src/students/assessments/assessment_feedback.php
@@ -8,16 +8,16 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../includes/inc_global.php");
+require_once '../../includes/inc_global.php';
 
 use WebPA\includes\classes\AlgorithmFactory;
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\classes\GroupHandler;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_STUDENT)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_STUDENT)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -29,83 +29,83 @@
 
 // --------------------------------------------------------------------------------
 
-function extract_max($input_array){
-  return array_keys($input_array, max($input_array));
-}
+$extractMax = function ($input_array) {
+    return array_keys($input_array, max($input_array));
+};
 
-function extract_min($input_array){
-  return array_keys($input_array, min($input_array));
-}
+$extractMin = function ($input_array) {
+    return array_keys($input_array, min($input_array));
+};
 
 $assessment = new Assessment($DB);
-if (!$assessment->load($assessment_id)) {
-  $assessment = null;
-  echo('Error: The requested assessment could not be loaded.');
-  exit;
-} else {
-
-  // ----------------------------------------
-  // Get the marking parameters used for the marksheet this report will display
-  // These are not used in this particular page anyway... we just need some dummy values
 
-  $marking_params['weighting']= 100;
-  $marking_params['penalty'] = 0;
-  $marking_params['penalty_type'] = '%';
-  $marking_params['tolerance'] = null;
-  $marking_params['grading'] = 'numeric' ;
-  $marking_params['algorithm'] = 'webpa';
-
-  // ----------------------------------------
-  // Get a list of the groups, and their marks, used in this assessment
-  $groups_and_marks = $assessment->get_group_marks();
-
-  // ----------------------------------------
-  // Get the appropriate algorithm and calculate the grades
-  $algorithm = AlgorithmFactory::get_algorithm($marking_params['algorithm']);
-
-  if (!$algorithm) {
-    echo('Error: The requested algorithm could not be loaded.');
+if (!$assessment->load($assessment_id)) {
+    $assessment = null;
+    echo 'Error: The requested assessment could not be loaded.';
     exit;
-  } else {
-    $algorithm->set_grade_ordinals($ordinal_scale);
-    $algorithm->set_assessment($assessment);
-    $algorithm->set_marking_params($marking_params);
-    $algorithm->calculate();
-
-    $submissions = $algorithm->get_submitters();
-    $webpa_scores = $algorithm->get_webpa_scores();
+}
 
-    $intermediate_grades = $algorithm->get_intermediate_grades();
-    $grades = $algorithm->get_grades();
+  // ----------------------------------------
+    // Get the marking parameters used for the marksheet this report will display
+    // These are not used in this particular page anyway... we just need some dummy values
+
+    $marking_params['weighting']= 100;
+    $marking_params['penalty'] = 0;
+    $marking_params['penalty_type'] = '%';
+    $marking_params['tolerance'] = null;
+    $marking_params['grading'] = 'numeric' ;
+    $marking_params['algorithm'] = 'webpa';
+
+    // ----------------------------------------
+    // Get a list of the groups, and their marks, used in this assessment
+    $groups_and_marks = $assessment->get_group_marks();
+
+    // ----------------------------------------
+    // Get the appropriate algorithm and calculate the grades
+    $algorithm = AlgorithmFactory::get_algorithm($marking_params['algorithm']);
+
+    if (!$algorithm) {
+        echo 'Error: The requested algorithm could not be loaded.';
+        exit;
+    }
+        $algorithm->set_grade_ordinals($ordinal_scale);
+        $algorithm->set_assessment($assessment);
+        $algorithm->set_marking_params($marking_params);
+        $algorithm->calculate();
 
-    $penalties = $algorithm->get_penalties();
-    if (!$penalties) { $penalties = array(); }
+        $submissions = $algorithm->get_submitters();
+        $webpa_scores = $algorithm->get_webpa_scores();
 
+        $intermediate_grades = $algorithm->get_intermediate_grades();
+        $grades = $algorithm->get_grades();
 
-    $questions = $algorithm->get_questions();
+        $penalties = $algorithm->get_penalties();
+        if (!$penalties) {
+            $penalties = [];
+        }
 
-    $group_names = $algorithm->get_group_names();
-    $group_members = $algorithm->get_group_members();
-    $member_ids = array_keys($webpa_scores);
+        $questions = $algorithm->get_questions();
 
-    $member_names = array();
+        $group_names = $algorithm->get_group_names();
+        $group_members = $algorithm->get_group_members();
+        $member_ids = array_keys($webpa_scores);
 
-    for ($i =0; $i<count($group_members); $i++){
-      $array_key = array_keys($group_members);
-      $temp = $group_members[$array_key[$i]];
-      for ($j=0; $j<count($temp);$j++){
-        array_push($member_names, $CIS->get_user($temp[$j]));
-      }
-    }
+        $member_names = [];
 
-    $group_handler = new GroupHandler();
-    $collection =& $group_handler->get_collection($assessment->get_collection_id());
+        for ($i =0; $i<count($group_members); $i++) {
+            $array_key = array_keys($group_members);
+            $temp = $group_members[$array_key[$i]];
+            for ($j=0; $j<count($temp);$j++) {
+                array_push($member_names, $CIS->get_user($temp[$j]));
+            }
+        }
 
-    $form = $assessment->get_form();
+        $group_handler = new GroupHandler();
+        $collection = $group_handler->get_collection($assessment->get_collection_id());
 
-  }// /if-else(is algorithm)
+        $form = $assessment->get_form();
+    
 
-}// /if-else(is assessment)
 
 
 $UI->page_title = APP__NAME . ' Feedback Report';
@@ -127,184 +127,176 @@ function extract_min($input_array){
 
 
 
-<h2><?php echo($assessment->name); ?></h2>
+<h2><?php echo $assessment->name; ?></h2>
 <p style="margin-bottom: 2em;">The following is based on your relative contribution in the group, measured from the self and peer assessment
    <?php echo APP__MARK_TEXT; ?> only and does <b>not</b> take account of the overall group <?php echo APP__MARK_TEXT; ?> for the project.</p>
 </p>
 
 
 <?php
-if ( (!$assessment) || (!$group_names) ) {
-?>
+if ((!$assessment) || (!$group_names)) {
+    ?>
   <div class="warning_box">
     <p style="font-weight: bold;">WebPA could not generate feedback for your assessment.</p>
     <p>There was a technical problem retrieving your information.</p>
   </div>
 <?php
 } else {
-  // ----------------------------------------
-  // Get the group this user belongs to
-  $group_id = null;
-  if ($collection) {
-    // Get the group this user belongs to
-    $groups = $collection->get_member_groups($_user->id);
-    if ($groups) {
-      $group =& $groups[0];
-      $group_id = $group->id;
-    }
-  }
-
-  $g_members = $group_members[$group_id];
-  $member_count = count($group_members[$group_id]);
-
-  $question_count = count($questions);
-
-  $awarded_total = array();
-
-  foreach($questions as $question_id => $question ) {
-
-    $awarded_total[$question_id] = 0;
-
-    foreach($g_members as $i => $member_id) {
-
-      foreach($g_members as $j => $target_member_id) {
-        //pull out the details for the one group member we are looking for
-        if ($target_member_id == $_user->id){
-          $awarded_marks[$question_id][$member_id]['mark_received'] = $algorithm->get_member_response($group_id, $member_id, $question_id, $target_member_id);
-          $awarded_total[$question_id] +=  $algorithm->get_member_response($group_id, $member_id, $question_id, $target_member_id);
+        // ----------------------------------------
+        // Get the group this user belongs to
+        $group_id = null;
+        if ($collection) {
+            // Get the group this user belongs to
+            $groups = $collection->get_member_groups($_user->id);
+            if ($groups) {
+                $group =& $groups[0];
+                $group_id = $group->id;
+            }
         }
 
-      }
+        $g_members = $group_members[$group_id];
+        $member_count = count($group_members[$group_id]);
 
-    }
+        $question_count = count($questions);
 
-  }
+        $awarded_total = [];
 
-  $match = 0;
+        foreach ($questions as $question_id => $question) {
+            $awarded_total[$question_id] = 0;
 
-  for($q=0; $q<$question_count; $q++){
-    if(!$q==0){
-      if ($q == $question_count-1){
-        if($awarded_marks[$q-1]== $awarded_marks[$q]){
-          $match +=1;
+            foreach ($g_members as $i => $member_id) {
+                foreach ($g_members as $j => $target_member_id) {
+                    //pull out the details for the one group member we are looking for
+                    if ($target_member_id == $_user->id) {
+                        $awarded_marks[$question_id][$member_id]['mark_received'] = $algorithm->get_member_response($group_id, $member_id, $question_id, $target_member_id);
+                        $awarded_total[$question_id] +=  $algorithm->get_member_response($group_id, $member_id, $question_id, $target_member_id);
+                    }
+                }
+            }
         }
-      }else{
-        if($awarded_marks[$q]==$awarded_marks[$q+1]){
-          $match +=1;
-        }
-      }
-    }else{
-      if($awarded_marks[$q]==$awarded_marks[$question_count-1]){
-          $match +=1;
-        }
-    }
-  }
-
-  for ($q=0; $q<$question_count; $q++){
-    $min_score[$q] = min($awarded_marks[$q]);
-    $max_score[$q] = max($awarded_marks[$q]);
-
-  }
-
-  //check to see if the answer are all the same for all questions
-  if ($match==$question_count) {
 
-    echo "<p>Your group has <?php echo APP__MARK_TEXT; ?> everyone equally, hence we are unable to provide feedback on your relative performance for different assessment criteria.</p>";
-
-  } else {
-
-    //get the fractional values and work out the greatest
-    for ($question = 0; $question<$question_count; $question++){
-      $max_score_per_question[$question] = ($max_score[$question]['mark_received'] / $awarded_total[$question])*4;
-      $min_score_per_question[$question] = ($min_score[$question]['mark_received'] / $awarded_total[$question])*4;
-    }
-    //display best based on the normalised mark when there are more that 1-2 best criteria
-    //extract_max which will return the array keys
-    $returned_max = extract_max($max_score_per_question);
-
-    $msg_failure = '';
-
-    //check the returned is an array
-    if (is_array($returned_max)) {
-      $returned_max_count = count($returned_max);
-
-      if ($returned_max_count>1){
-        //compare the two top marks
-        if ($max_score[$returned_max[0]]['mark_received']==$max_score[$returned_max[1]]['mark_received']){
-          //leave in incase we want to offer more than one result
-          $element = $form->get_question($returned_max[0]);
-          echo "<h3>Your strongest contribution within this project was rated by your group as:</h3>";
-          echo "<p><b>" . $element['text']['_data'];
-          echo "</b><br/>" . $element['desc']['_data'];
-          echo "</p>";
-        }else{
-          $element = $form->get_question($returned_max[0]);
-          echo "<h3>Your strongest contribution within this project was rated by your group as:</h3>";
-          echo "<p><b>" . $element['text']['_data'];
-          echo "</b><br/>" . $element['desc']['_data'];
-          echo "</p>";
+        $match = 0;
+
+        for ($q=0; $q<$question_count; $q++) {
+            if (!$q==0) {
+                if ($q == $question_count-1) {
+                    if ($awarded_marks[$q-1]== $awarded_marks[$q]) {
+                        $match +=1;
+                    }
+                } else {
+                    if ($awarded_marks[$q]==$awarded_marks[$q+1]) {
+                        $match +=1;
+                    }
+                }
+            } else {
+                if ($awarded_marks[$q]==$awarded_marks[$question_count-1]) {
+                    $match +=1;
+                }
+            }
         }
-      }
 
-    } else {
-      $msg_failure = "<p>WebPA has been unable to generate any feedback</p>";
-    }
+        for ($q=0; $q<$question_count; $q++) {
+            $min_score[$q] = min($awarded_marks[$q]);
+            $max_score[$q] = max($awarded_marks[$q]);
+        }
 
-    echo "<br/><br/>";
-
-  //only display if the score is below the median and one mark below the others
-  //No area for development should be identified if their lowest score is above the median AND
-  //is greater than 80% of their highest score
-
-    $returned_min = extract_min($min_score_per_question);
-    if (is_array($returned_min)) {
-      $returned_min_count = count($returned_min);
-
-      if ($returned_min_count>1) {
-        if ($min_score[$returned_min[0]]['mark_received']==$min_score[$returned_min[1]]['mark_received']) {
-          $element = $form->get_question($returned_min[0]);
-          $range = $element['range']['_data'];
-          //split the string up
-          $split_range = explode('-',$range);
-          //calculate the median
-          $median = round(($split_range[0]+$split_range[1])/2);
-
-          //compare to ensure that the lowest if below the median
-          if ($min_score_per_question[$returned_min[0]]<$median) {
-            echo "<h3>An area you may wish to develop is your contribution to:</h3>";
-            echo "<p><b>" . $element['text']['_data'];
-            echo "</b><br/>" . $element['desc']['_data'];
-            echo "</p>";
-          }
+        //check to see if the answer are all the same for all questions
+        if ($match==$question_count) {
+            echo '<p>Your group has <?php echo APP__MARK_TEXT; ?> everyone equally, hence we are unable to provide feedback on your relative performance for different assessment criteria.</p>';
         } else {
-          $element = $form->get_question($returned_min[0]);
-          echo "<h3>An area you may wish to develop is your contribution to:</h3>";
-          echo "<p><b>" . $element['text']['_data'];
-          echo "</b><br/>" . $element['desc']['_data'];
-          echo "</p>";
-        }
-      } else {
-        $element = $form->get_question($returned_min[0]);
-        $range = $element['range']['_data'];
-        //split the string up
-        $split_range = explode('-',$range);
-        //calculate the median
-        $median = round(($split_range[0]+$split_range[1])/2);
-
-        //compare to ensure that the lowest if below the median
-        if ($min_score_per_question[$returned_min[0]]<$median){
-          echo "<h3>An area you may wish to develop is your contribution to:</h3>";
-          echo "<p><b>" . $element['text']['_data'];
-          echo "</b><br/>" . $element['desc']['_data'];
-          echo "</p>";
+
+    //get the fractional values and work out the greatest
+            for ($question = 0; $question<$question_count; $question++) {
+                $max_score_per_question[$question] = ($max_score[$question]['mark_received'] / $awarded_total[$question])*4;
+                $min_score_per_question[$question] = ($min_score[$question]['mark_received'] / $awarded_total[$question])*4;
+            }
+            //display best based on the normalised mark when there are more that 1-2 best criteria
+            // extractMax which will return the array keys
+            $returned_max = $extractMax($max_score_per_question);
+
+            $msg_failure = '';
+
+            //check the returned is an array
+            if (is_array($returned_max)) {
+                $returned_max_count = count($returned_max);
+
+                if ($returned_max_count>1) {
+                    //compare the two top marks
+                    if ($max_score[$returned_max[0]]['mark_received']==$max_score[$returned_max[1]]['mark_received']) {
+                        //leave in incase we want to offer more than one result
+                        $element = $form->get_question($returned_max[0]);
+                        echo '<h3>Your strongest contribution within this project was rated by your group as:</h3>';
+                        echo '<p><b>' . $element['text']['_data'];
+                        echo '</b><br/>' . $element['desc']['_data'];
+                        echo '</p>';
+                    } else {
+                        $element = $form->get_question($returned_max[0]);
+                        echo '<h3>Your strongest contribution within this project was rated by your group as:</h3>';
+                        echo '<p><b>' . $element['text']['_data'];
+                        echo '</b><br/>' . $element['desc']['_data'];
+                        echo '</p>';
+                    }
+                }
+            } else {
+                $msg_failure = '<p>WebPA has been unable to generate any feedback</p>';
+            }
+
+            echo '<br/><br/>';
+
+            //only display if the score is below the median and one mark below the others
+            //No area for development should be identified if their lowest score is above the median AND
+            //is greater than 80% of their highest score
+
+            $returned_min = $extractMin($min_score_per_question);
+
+            if (is_array($returned_min)) {
+                $returned_min_count = count($returned_min);
+
+                if ($returned_min_count>1) {
+                    if ($min_score[$returned_min[0]]['mark_received']==$min_score[$returned_min[1]]['mark_received']) {
+                        $element = $form->get_question($returned_min[0]);
+                        $range = $element['range']['_data'];
+                        //split the string up
+                        $split_range = explode('-', $range);
+                        //calculate the median
+                        $median = round(($split_range[0]+$split_range[1])/2);
+
+                        //compare to ensure that the lowest if below the median
+                        if ($min_score_per_question[$returned_min[0]]<$median) {
+                            echo '<h3>An area you may wish to develop is your contribution to:</h3>';
+                            echo '<p><b>' . $element['text']['_data'];
+                            echo '</b><br/>' . $element['desc']['_data'];
+                            echo '</p>';
+                        }
+                    } else {
+                        $element = $form->get_question($returned_min[0]);
+                        echo '<h3>An area you may wish to develop is your contribution to:</h3>';
+                        echo '<p><b>' . $element['text']['_data'];
+                        echo '</b><br/>' . $element['desc']['_data'];
+                        echo '</p>';
+                    }
+                } else {
+                    $element = $form->get_question($returned_min[0]);
+                    $range = $element['range']['_data'];
+                    //split the string up
+                    $split_range = explode('-', $range);
+                    //calculate the median
+                    $median = round(($split_range[0]+$split_range[1])/2);
+
+                    //compare to ensure that the lowest if below the median
+                    if ($min_score_per_question[$returned_min[0]]<$median) {
+                        echo '<h3>An area you may wish to develop is your contribution to:</h3>';
+                        echo '<p><b>' . $element['text']['_data'];
+                        echo '</b><br/>' . $element['desc']['_data'];
+                        echo '</p>';
+                    }
+                }
+            } else {
+                $msg_failure = '<p>WebPA has been unable to generate any feedback</p>';
+            }
         }
-      }
-    } else {
-      $msg_failure = "<p>WebPA has been unable to generate any feedback</p>";
+        echo "  </div>\n";
     }
-  }
-  echo "  </div>\n";
-}
 ?>
 <br />
 <form action="#" method="post" name="feedbackform">
@@ -317,5 +309,3 @@ function extract_min($input_array){
 <?php
 
 $UI->content_end(false, false, false);
-
-?>
diff --git a/src/students/assessments/index.php b/src/students/assessments/index.php
index ce402c4..9249fb7 100644
--- a/src/students/assessments/index.php
+++ b/src/students/assessments/index.php
@@ -8,17 +8,18 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../includes/inc_global.php");
+require_once '../../includes/inc_global.php';
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\GroupHandler;
 use WebPA\includes\classes\SimpleObjectIterator;
 use WebPA\includes\functions\AcademicYear;
 use WebPA\includes\functions\ArrayFunctions;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_STUDENT)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_STUDENT)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -27,10 +28,9 @@
 
 // Get a list of collections that the user is a member of
 
-$collections = $group_handler->get_member_collections($_user->id, APP__ID, 'assessment');
+$collections = $group_handler->get_member_collections($_user->id, 'assessment');
 
 $collection_ids = ArrayFunctions::array_extract_column($collections, 'collection_id');
-$collection_clause = $DB->build_set($collection_ids);
 
 // Get a list of assessments that match the user's collections (for this year)
 
@@ -42,25 +42,43 @@
 $sql_start_date = date(MYSQL_DATETIME_FORMAT, $start_date);
 $sql_end_date = date(MYSQL_DATETIME_FORMAT, $end_date);
 
-$assessments = $DB->fetch('SELECT a.* FROM ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
-                          "WHERE (a.module_id = {$_module_id}) AND " .
-                                "(a.collection_id IN $collection_clause) AND " .
-                                "(a.open_date >= '{$sql_start_date}') AND " .
-                                "(a.open_date < '{$sql_end_date}') " .
-                          'ORDER BY a.open_date, a.close_date, a.assessment_name');
+$assessmentsQuery =
+    'SELECT a.* FROM ' .
+    APP__DB_TABLE_PREFIX . 'assessment a ' .
+    'WHERE a.module_id = ? ' .
+    'AND a.collection_id IN (?) ' .
+    'AND a.open_date >= ? ' .
+    'AND a.open_date < ? ' .
+    'ORDER BY a.open_date, a.close_date, a.assessment_name';
+
+$assessments = $DB->getConnection()->fetchAllAssociative(
+        $assessmentsQuery,
+        [
+            $_module_id,
+            $collection_ids,
+            $sql_start_date,
+            $sql_end_date,
+        ],
+        [
+            ParameterType::INTEGER,
+            $DB->getConnection()::PARAM_STR_ARRAY,
+            ParameterType::STRING,
+            ParameterType::STRING,
+        ]
+);
 
 // Get a list of those assessments that the user has already taken
 
-$assessment_ids = ArrayFunctions::array_extract_column($assessments, 'assessment_id');
-$assessment_clause = $DB->build_set($assessment_ids);
+$assessment_ids = array_column($assessments, 'assessment_id');
 
-$assessments_with_response = $DB->fetch_col("
-  SELECT DISTINCT assessment_id
-  FROM " . APP__DB_TABLE_PREFIX . "user_mark
-  WHERE (assessment_id IN {$assessment_clause})
-    AND (user_id = {$_user->id})
-  ORDER BY assessment_id
-");
+$assessmentsWithResponseQuery =
+    'SELECT DISTINCT assessment_id ' .
+    'FROM ' . APP__DB_TABLE_PREFIX . 'user_mark ' .
+    'WHERE assessment_id IN (?) ' .
+    'AND user_id = ? ' .
+    'ORDER BY assessment_id';
+
+$assessments_with_response = $DB->getConnection()->fetchFirstColumn($assessmentsWithResponseQuery, [$assessment_ids, $_user->id], [$DB->getConnection()::PARAM_INT_ARRAY, ParameterType::INTEGER]);
 
 // Split the assessments into pending, open and finished
 $pending_assessments = null;
@@ -68,26 +86,25 @@
 $finished_assessments = null;
 
 if ($assessments) {
-
-  foreach($assessments as $i => $assessment) {
-    if ( (is_array($assessments_with_response)) && (in_array($assessment['assessment_id'], $assessments_with_response)) ) {
-      $finished_assessments[] = $assessment;
-    } else {
-      $now = time();
-      $open_date = strtotime($assessment['open_date']);
-      $close_date = strtotime($assessment['close_date']);
-
-      if ($close_date<=$now) {
-        $finished_assessments[] = $assessment;
-      } else {
-        if ($open_date>$now) {
-          $pending_assessments[] = $assessment;
+    foreach ($assessments as $i => $assessment) {
+        if ((is_array($assessments_with_response)) && (in_array($assessment['assessment_id'], $assessments_with_response))) {
+            $finished_assessments[] = $assessment;
         } else {
-          $open_assessments[] = $assessment;
+            $now = time();
+            $open_date = strtotime($assessment['open_date']);
+            $close_date = strtotime($assessment['close_date']);
+
+            if ($close_date<=$now) {
+                $finished_assessments[] = $assessment;
+            } else {
+                if ($open_date>$now) {
+                    $pending_assessments[] = $assessment;
+                } else {
+                    $open_assessments[] = $assessment;
+                }
+            }
         }
-      }
     }
-  }
 }
 
 // --------------------------------------------------------------------------------
@@ -96,9 +113,9 @@
 $UI->page_title = APP__NAME . ' my assessments';
 $UI->menu_selected = 'my assessments';
 $UI->help_link = '?q=node/329';
-$UI->breadcrumbs = array  (
-                'my assessments'      => null ,
-              );
+$UI->breadcrumbs = [
+                'my assessments'      => null,
+              ];
 
 
 $UI->head();
@@ -112,120 +129,118 @@
 <div class="content_box">
 
 <?php
-if ( (!$open_assessments) && (!$pending_assessments) && (!$finished_assessments) ) {
-  echo('<p>You are not registered with any peer assessments in this module at the moment.</p>');
+if ((!$open_assessments) && (!$pending_assessments) && (!$finished_assessments)) {
+    echo '<p>You are not registered with any peer assessments in this module at the moment.</p>';
 } else {
-  echo('<p>You are registered on the following peer assessments in this module:</p>');
+    echo '<p>You are registered on the following peer assessments in this module:</p>';
 
-  if ($open_assessments) {
-?>
+    if ($open_assessments) {
+        ?>
       <h2>Open Assessments</h2>
       <p>These assessments are now open for you to take and record your group <?php echo APP__MARK_TEXT; ?>.</p>
       <div class="form_section form_line">
 <?php
     $status = 'open';
-    $status_capitalized = ucfirst($status);
-
-    $assessment_iterator = new SimpleObjectIterator($open_assessments,'Assessment', $DB);
-    for ($assessment_iterator->reset(); $assessment_iterator->is_valid(); $assessment_iterator->next()) {
-      $assessment =& $assessment_iterator->current();
-      $take_url = "take/index.php?a={$assessment->id}";
-
-      echo("<div class=\"assessment_open\">");
-      echo('<table class="assessment_info" cellpadding="0" cellspacing="0">');
-      echo('<tr>');
-      echo("  <td width=\"24\"><img src=\"../../images/icons/{$status}_icon.gif\" alt=\"$status_capitalized\" title=\"$status_capitalized\" height=\"24\" width=\"24\" /></td>");
-      echo('  <td valign="top">');
-      echo('    <div class="assessment_info">');
-      echo("      <div class=\"assessment_name\">{$assessment->name}</div>");
-      echo('      <div class="assessment_schedule">scheduled: '. $assessment->get_date_string('open_date') .' &nbsp;-&nbsp; '. $assessment->get_date_string('close_date') . ' </div>');
-      echo('    </div>');
-      echo('  </td>');
-      echo('  <td class="buttons" style="line-height: 2em; text-align: right;">');
-      echo("    <a class=\"button\" href=\"$take_url\">Take Assessment</a>");
-      echo('  </td>');
-      echo('</tr>');
-      echo('</table>');
-      echo('</div>');
-    }
-?>
+        $status_capitalized = ucfirst($status);
+
+        $assessment_iterator = new SimpleObjectIterator($open_assessments, 'Assessment', $DB);
+        for ($assessment_iterator->reset(); $assessment_iterator->is_valid(); $assessment_iterator->next()) {
+            $assessment =& $assessment_iterator->current();
+            $take_url = "take/index.php?a={$assessment->id}";
+
+            echo '<div class="assessment_open">';
+            echo '<table class="assessment_info" cellpadding="0" cellspacing="0">';
+            echo '<tr>';
+            echo "  <td width=\"24\"><img src=\"../../images/icons/{$status}_icon.gif\" alt=\"$status_capitalized\" title=\"$status_capitalized\" height=\"24\" width=\"24\" /></td>";
+            echo '  <td valign="top">';
+            echo '    <div class="assessment_info">';
+            echo "      <div class=\"assessment_name\">{$assessment->name}</div>";
+            echo '      <div class="assessment_schedule">scheduled: '. $assessment->get_date_string('open_date') .' &nbsp;-&nbsp; '. $assessment->get_date_string('close_date') . ' </div>';
+            echo '    </div>';
+            echo '  </td>';
+            echo '  <td class="buttons" style="line-height: 2em; text-align: right;">';
+            echo "    <a class=\"button\" href=\"$take_url\">Take Assessment</a>";
+            echo '  </td>';
+            echo '</tr>';
+            echo '</table>';
+            echo '</div>';
+        } ?>
       </div>
 <?php
-  }
-  if ($pending_assessments) {
-?>
+    }
+    if ($pending_assessments) {
+        ?>
       <h2>Pending Assessments</h2>
       <p>These assessments scheduled for some point in the future.</p>
       <div class="form_section form_line">
 <?php
     $status = 'pending';
-    $status_capitalized = ucfirst($status);
-
-    $assessment_iterator = new SimpleObjectIterator($pending_assessments,'Assessment', $DB);
-    for ($assessment_iterator->reset(); $assessment_iterator->is_valid(); $assessment_iterator->next()) {
-      $assessment =& $assessment_iterator->current();
-      $take_url = "take/index.php?a={$assessment->id}";
-
-      echo("<div class=\"assessment\">");
-      echo('<table class="assessment_info" cellpadding="0" cellspacing="0">');
-      echo('<tr>');
-      echo("  <td width=\"24\"><img src=\"../../images/icons/{$status}_icon.gif\" alt=\"$status_capitalized\" title=\"$status_capitalized\" height=\"24\" width=\"24\" /></td>");
-      echo('  <td valign="top">');
-      echo('    <div class="assessment_info">');
-      echo("      <div class=\"assessment_name\">{$assessment->name}</div>");
-      echo('      <div class="assessment_schedule">scheduled: '. $assessment->get_date_string('open_date') .' &nbsp;-&nbsp; '. $assessment->get_date_string('close_date') . ' </div>');
-      echo('    </div>');
-      echo('  </td>');
-      echo('</tr>');
-      echo('</table>');
-      echo('</div>');
-    }
-?>
+        $status_capitalized = ucfirst($status);
+
+        $assessment_iterator = new SimpleObjectIterator($pending_assessments, 'Assessment', $DB);
+        for ($assessment_iterator->reset(); $assessment_iterator->is_valid(); $assessment_iterator->next()) {
+            $assessment =& $assessment_iterator->current();
+            $take_url = "take/index.php?a={$assessment->id}";
+
+            echo '<div class="assessment">';
+            echo '<table class="assessment_info" cellpadding="0" cellspacing="0">';
+            echo '<tr>';
+            echo "  <td width=\"24\"><img src=\"../../images/icons/{$status}_icon.gif\" alt=\"$status_capitalized\" title=\"$status_capitalized\" height=\"24\" width=\"24\" /></td>";
+            echo '  <td valign="top">';
+            echo '    <div class="assessment_info">';
+            echo "      <div class=\"assessment_name\">{$assessment->name}</div>";
+            echo '      <div class="assessment_schedule">scheduled: '. $assessment->get_date_string('open_date') .' &nbsp;-&nbsp; '. $assessment->get_date_string('close_date') . ' </div>';
+            echo '    </div>';
+            echo '  </td>';
+            echo '</tr>';
+            echo '</table>';
+            echo '</div>';
+        } ?>
       </div>
 <?php
-  }
+    }
 
-  if ($finished_assessments) {
-?>
+    if ($finished_assessments) {
+        ?>
       <h2>Finished Assessments</h2>
       <p>These assessments you have already taken, or which have passed their deadline for completion.</p>
       <p>Some of your assessments may allow you to see feedback on your performance. Click <em>view feedback</em> (if available) for a particular assessment to see the feedback.</p>
       <div class="form_section">
 <?php
     $status = 'finished';
-    $status_capitalized = ucfirst($status);
-
-    $now = time();
-
-    $assessment_iterator = new SimpleObjectIterator($finished_assessments, 'Assessment', $DB);
-    for ($assessment_iterator->reset(); $assessment_iterator->is_valid(); $assessment_iterator->next()) {
-      $assessment =& $assessment_iterator->current();
-      $take_url = "take/index.php?a={$assessment->id}";
-
-      $completed_msg = ( (is_array($assessments_with_response)) && (in_array($assessment->id, $assessments_with_response)) ) ? 'COMPLETED': 'DID NOT<br />SUBMIT';
-
-      echo("<div class=\"assessment_finished\">");
-      echo('<table class="assessment_info" cellpadding="0" cellspacing="0">');
-      echo('<tr>');
-      echo("  <td width=\"24\"><img src=\"../../images/icons/{$status}_icon.gif\" alt=\"$status_capitalized\" title=\"$status_capitalized\" height=\"24\" width=\"24\" /></td>");
-      echo('  <td valign="top">');
-      echo('    <div class="assessment_info">');
-      echo("      <div class=\"assessment_name\">{$assessment->name}</div>");
-      echo('      <div class="assessment_schedule">scheduled: '. $assessment->get_date_string('open_date') .' &nbsp;-&nbsp; '. $assessment->get_date_string('close_date') . ' </div>');
-      echo('    </div>');
-      echo('  </td>');
-      echo('  <td style="font-weight: bold; text-align: center;">');
-      echo("    $completed_msg");
-      if ( ($assessment->allow_feedback) && ($assessment->close_date<$now) ) {
-        echo("<div style=\"margin-top: 0.5em;\"><a href=\"assessment_feedback.php?a={$assessment->id}\" target=\"_blank\">view feedback</a></div>");
-      }
-      echo('  </td>');
-      echo('</tr>');
-      echo('</table>');
-      echo('</div>');
+        $status_capitalized = ucfirst($status);
+
+        $now = time();
+
+        $assessment_iterator = new SimpleObjectIterator($finished_assessments, 'Assessment', $DB);
+        for ($assessment_iterator->reset(); $assessment_iterator->is_valid(); $assessment_iterator->next()) {
+            $assessment =& $assessment_iterator->current();
+            $take_url = "take/index.php?a={$assessment->id}";
+
+            $completed_msg = ((is_array($assessments_with_response)) && (in_array($assessment->id, $assessments_with_response))) ? 'COMPLETED': 'DID NOT<br />SUBMIT';
+
+            echo '<div class="assessment_finished">';
+            echo '<table class="assessment_info" cellpadding="0" cellspacing="0">';
+            echo '<tr>';
+            echo "  <td width=\"24\"><img src=\"../../images/icons/{$status}_icon.gif\" alt=\"$status_capitalized\" title=\"$status_capitalized\" height=\"24\" width=\"24\" /></td>";
+            echo '  <td valign="top">';
+            echo '    <div class="assessment_info">';
+            echo "      <div class=\"assessment_name\">{$assessment->name}</div>";
+            echo '      <div class="assessment_schedule">scheduled: '. $assessment->get_date_string('open_date') .' &nbsp;-&nbsp; '. $assessment->get_date_string('close_date') . ' </div>';
+            echo '    </div>';
+            echo '  </td>';
+            echo '  <td style="font-weight: bold; text-align: center;">';
+            echo "    $completed_msg";
+            if (($assessment->allow_feedback) && ($assessment->close_date<$now)) {
+                echo "<div style=\"margin-top: 0.5em;\"><a href=\"assessment_feedback.php?a={$assessment->id}\" target=\"_blank\">view feedback</a></div>";
+            }
+            echo '  </td>';
+            echo '</tr>';
+            echo '</table>';
+            echo '</div>';
+        }
+        echo "    </div>\n";
     }
-    echo("    </div>\n");
-  }
 }
 ?>
 
diff --git a/src/students/assessments/take/already_submitted.php b/src/students/assessments/take/already_submitted.php
index 1ee2903..1668762 100644
--- a/src/students/assessments/take/already_submitted.php
+++ b/src/students/assessments/take/already_submitted.php
@@ -8,14 +8,14 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_STUDENT)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_STUDENT)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -29,22 +29,21 @@
 
 $assessment = new Assessment($DB);
 if ($assessment->load($assessment_id)) {
-
 } else {
-  $assessment = null;
+    $assessment = null;
 }
 
 
 // --------------------------------------------------------------------------------
 // Begin Page
 
-$UI->page_title = ($assessment) ? $assessment->name : "already submitted";
+$UI->page_title = ($assessment) ? $assessment->name : 'already submitted';
 $UI->menu_selected = 'my assessments';
 $UI->help_link = '?q=node/329';
 
-$UI->breadcrumbs = array  ('home'       => '/' ,
-               $assessment->name  => null ,
-              );
+$UI->breadcrumbs = ['home'       => '/',
+               $assessment->name  => null,
+              ];
 $UI->head();
 $UI->content_start();
 ?>
@@ -53,28 +52,28 @@
 
 <?php
 if (!$assessment) {
-  ?>
+    ?>
   <div class="nav_button_bar">
-    <a href="<?php echo($list_url) ?>"><img src="/images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a>
+    <a href="<?php echo $list_url ?>"><img src="/images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a>
   </div>
 
   <p>The assessment you selected could not be loaded for some reason - However, you have already submitted your <?php echo APP__MARK_TEXT; ?> for this assessment.</p>
   <p>If the problem loading this assessment persists, please use the contact system to <a href="/students/support/contact/index.php?q=bug">report the error</a>.</p>
 <?php
 } else {
-?>
+        ?>
   <div class="nav_button_bar">
     <table cellpadding="0" cellspacing="0" width="100%">
     <tr>
-      <td><a href="<?php echo($list_url); ?>"><img src="/images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a></td>
+      <td><a href="<?php echo $list_url; ?>"><img src="/images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a></td>
     </tr>
     </table>
   </div>
 
-  <p>You have already submitted your <?php echo APP__MARK_TEXT; ?> for this assessment: <?php echo($assessment->name); ?>.</p>
-  <p>If you have another assessment to take, please select it from your <a href="<?php echo($list_url); ?>">assessments list</a>.</p>
+  <p>You have already submitted your <?php echo APP__MARK_TEXT; ?> for this assessment: <?php echo $assessment->name; ?>.</p>
+  <p>If you have another assessment to take, please select it from your <a href="<?php echo $list_url; ?>">assessments list</a>.</p>
 <?php
-}
+    }
 ?>
 </div>
 
diff --git a/src/students/assessments/take/finished.php b/src/students/assessments/take/finished.php
index de770ca..f04bc1e 100644
--- a/src/students/assessments/take/finished.php
+++ b/src/students/assessments/take/finished.php
@@ -8,14 +8,14 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_STUDENT)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_STUDENT)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -29,9 +29,8 @@
 
 $assessment = new Assessment($DB);
 if ($assessment->load($assessment_id)) {
-
 } else {
-  $assessment = null;
+    $assessment = null;
 }
 
 // --------------------------------------------------------------------------------
@@ -40,10 +39,10 @@
 $UI->page_title = APP__NAME . ' ' .  "finished: $assessment->name";
 $UI->menu_selected = 'my assessments';
 $UI->help_link = '?q=node/329';
-$UI->breadcrumbs = array  (
-  'home'             => '/' ,
-  $assessment->name  => null ,
-);
+$UI->breadcrumbs = [
+  'home'             => '/',
+  $assessment->name  => null,
+];
 
 $UI->head();
 $UI->content_start();
@@ -53,28 +52,28 @@
 
 <?php
 if (!$assessment) {
-?>
+    ?>
   <div class="nav_button_bar">
-    <a href="<?php echo($list_url) ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a>
+    <a href="<?php echo $list_url ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a>
   </div>
 
   <p>The assessment you selected could not be loaded for some reason - Your <?php echo APP__MARK_TEXT; ?> for this assessment should have been saved so please check this from the <a href="../../">my assessments</a> section.</p>
   <p>If the problem persists, please use the contact system to <a href="../../support/contact/index.php?q=bug">report the error</a>.</p>
 <?php
 } else {
-?>
+        ?>
   <div class="nav_button_bar">
     <table cellpadding="0" cellspacing="0" width="100%">
     <tr>
-      <td><a href="<?php echo($list_url); ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a></td>
+      <td><a href="<?php echo $list_url; ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a></td>
     </tr>
     </table>
   </div>
 
   <p>Thank you, your marks have now been saved.</p>
-  <p>You can now check your <a href="../../">assessments list</a> and take another assessment, or finish with WebPA and <a href="<?php echo APP__WWW;?>/logout.php">logout</a>.</p>
+  <p>You can now check your <a href="../../">assessments list</a> and take another assessment, or finish with WebPA and <a href="<?php echo APP__WWW; ?>/logout.php">logout</a>.</p>
 <?php
-}
+    }
 ?>
 </div>
 
diff --git a/src/students/assessments/take/index.php b/src/students/assessments/take/index.php
index 9d3e39f..5cffaed 100755
--- a/src/students/assessments/take/index.php
+++ b/src/students/assessments/take/index.php
@@ -8,8 +8,9 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\classes\Form;
 use WebPA\includes\classes\FormRenderer;
@@ -17,9 +18,9 @@
 use WebPA\includes\classes\ResultHandler;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_STUDENT)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_STUDENT)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -29,78 +30,78 @@
 
 $command = Common::fetch_POST('command');
 
-$list_url = "../index.php";
+$list_url = '../index.php';
 
 // --------------------------------------------------------------------------------
 
 $assessment = new Assessment($DB);
 if ($assessment->load($assessment_id)) {
-  $assessment_qs = "a={$assessment->id}";
+    $assessment_qs = "a={$assessment->id}";
 
-  // Check if the assessment is open
-  if ($assessment->get_status()!='open') {
-    header('Location: '. APP__WWW ."/students/assessments/take/not_open.php?{$assessment_qs}");
-    exit;
-  }
+    // Check if the assessment is open
+    if ($assessment->get_status()!='open') {
+        header('Location: '. APP__WWW ."/students/assessments/take/not_open.php?{$assessment_qs}");
+        exit;
+    }
 
-  // Check if the user has submitted his results already
-  $result_handler = new ResultHandler($DB);
-  $result_handler->set_assessment($assessment);
+    // Check if the user has submitted his results already
+    $result_handler = new ResultHandler($DB);
+    $result_handler->set_assessment($assessment);
 
-  if ($result_handler->user_has_responded($_user->id, $assessment->id)) {
-    header('Location: '. APP__WWW ."/students/assessments/take/already_submitted.php?{$assessment_qs}");
-    exit;
-  }
+    if ($result_handler->user_has_responded($_user->id, $assessment->id)) {
+        header('Location: '. APP__WWW ."/students/assessments/take/already_submitted.php?{$assessment_qs}");
+        exit;
+    }
 
-  // Get the form to be displayed
-  $form = new Form($DB);
+    // Get the form to be displayed
+    $form = new Form($DB);
 
-  $form_xml = $assessment->get_form_xml();
-  $form->load_from_xml($form_xml);
+    $form_xml = $assessment->get_form_xml();
+    $form->load_from_xml($form_xml);
 
-  // Get the collection being used
-  $group_handler = new GroupHandler();
-  $collection = $group_handler->get_collection($assessment->get_collection_id());
+    // Get the collection being used
+    $group_handler = new GroupHandler();
+    $collection = $group_handler->get_collection($assessment->get_collection_id());
 
-  if ($collection) {
-    // Get the group this user belongs to
-    $groups = $collection->get_member_groups($_user->id);
-    if ($groups) {
-      $group =& $groups[0];
+    if ($collection) {
+        // Get the group this user belongs to
+        $groups = $collection->get_member_groups($_user->id);
+        if ($groups) {
+            $group =& $groups[0];
 
-      // Get the members and process them for use in the assessment
-      $members = $group->get_members();
-      $users = $CIS->get_user(array_keys($members));
+            // Get the members and process them for use in the assessment
+            $members = $group->get_members();
+            $users = $CIS->get_user(array_keys($members));
 
-      $people = null;
-      $people["{$_user->id}"] = 'Yourself';   // Current user comes first
+            $people = null;
+            $people["{$_user->id}"] = 'Yourself';   // Current user comes first
 
-      foreach($users as $i => $user) {
-        if ($user['user_id']!=$_user->id) {
-          $people["{$user['user_id']}"] = $user['lastname'].', '.$user['forename'];
-        }
-      }
+            foreach ($users as $i => $user) {
+                if ($user['user_id']!=$_user->id) {
+                    $people["{$user['user_id']}"] = $user['lastname'].', '.$user['forename'];
+                }
+            }
 
-      //check the assessment type that is being carried out and remove
-      // If this is a peer-only assessment, remove the Yourself option
-      if ($assessment->assessment_type == '0'){
-        $index = array_search('Yourself', $people);
-        if ($index !== FALSE) {
-          unset($people[$index]);
-        }
-      }
+            //check the assessment type that is being carried out and remove
+            // If this is a peer-only assessment, remove the Yourself option
+            if ($assessment->assessment_type == '0') {
+                $index = array_search('Yourself', $people);
+                if ($index !== false) {
+                    unset($people[$index]);
+                }
+            }
 
-      // Create the form_renderer
-      $form_renderer = new FormRenderer();
-      $form_renderer->set_form($form);
-      $form_renderer->participant_id = $_user->id;
-      $form_renderer->set_participants($people);
-      $form_renderer->assessment_feedback = $assessment->allow_assessment_feedback;
-      $form_renderer->assessment_feedback_title = $assessment->feedback_name;
+            // Create the form_renderer
+            $form_renderer = new FormRenderer();
+            $form_renderer->set_form($form);
+            $form_renderer->participant_id = $_user->id;
+            $form_renderer->set_participants($people);
+            $form_renderer->assessment_feedback = $assessment->allow_assessment_feedback;
+            $form_renderer->assessment_feedback_title = $assessment->feedback_name;
+        }
     }
-  }
 } else {
-  $assessment = null;
+    $assessment = null;
 }
 
 // --------------------------------------------------------------------------------
@@ -113,176 +114,252 @@
 $justification = null;
 
 if (($command) && ($assessment)) {
-  switch ($command) {
+    switch ($command) {
     case 'save':
       // Check date/time of submission
       $now = time();
       if ($now>$assessment->close_date) {
-        $errors[] = 'You were too late in submitting your answers, the assessment is now closed.';
+          $errors[] = 'You were too late in submitting your answers, the assessment is now closed.';
       } else {
+          $participant_count = count($people);
+          $remainder = 100 % $participant_count;
+          $group_total = 100 - $remainder;
 
-        $participant_count = count($people);
-        $remainder = 100 % $participant_count;
-        $group_total = 100 - $remainder;
-
-        $question_count = $form->get_question_count();
-        $questions = null;
+          $question_count = $form->get_question_count();
+          $questions = null;
 
-        if (!$question_count>0) {
-          $errors[] = 'Unable to load question data!';
-        } else {
-          if ($form->type == 'split100') {
+          if (!$question_count>0) {
+              $errors[] = 'Unable to load question data!';
+          } else {
+              if ($form->type == 'split100') {
 
             // Loop through every question and total up the scores for each one
 
-            $q_total_marks = array();
-
-            for ($q=0; $q<$question_count; $q++) {
-
-              $q_total_marks[$q] = 0;
-
-              $q_num = $q + 1;
-
-              // Loop through every person
-              foreach ($people as $id => $name) {
-                $q_id = "q_{$q}_{$id}";
-                $score = Common::fetch_POST($q_id, null);
-
-                if (($score!=0) && (empty($score))) {
-                  $errors[] = "You didn't give a " . APP__MARK_TEXT . " for '$name' in Q{$q_num}.";
-                  $error_style_ids["$q_id"] = 1;
-                } else {
-                  if (!is_numeric($score)) {
-                    $errors[] = "You didn't give a valid " . APP__MARK_TEXT . " for '$name' in Q{$q_num}.";
-                    $error_style_ids["$q_id"] = 1;
-                  } else {
-                    $score = (int) $score;
-                    if (($score<0) || ($score>$group_total)) {
-                      $errors[] = "Your " . APP__MARK_TEXT . " of $score for '$name' in Q{$q_num} is invalid.<br /> " . APP__MARK_TEXT . " must be between 0 and $group_total.";
-                      $error_style_ids["$q_id"] = 1;
-                    }
-                    $results["$q"]["$id"] = $score;
-                    $q_total_marks[$q] += $score;
-                  }
-                }
-              }// /foreach $people
-            } // /for $q
+                  $q_total_marks = [];
+
+                  for ($q=0; $q<$question_count; $q++) {
+                      $q_total_marks[$q] = 0;
+
+                      $q_num = $q + 1;
+
+                      // Loop through every person
+                      foreach ($people as $id => $name) {
+                          $q_id = "q_{$q}_{$id}";
+                          $score = Common::fetch_POST($q_id, null);
+
+                          if (($score!=0) && (empty($score))) {
+                              $errors[] = "You didn't give a " . APP__MARK_TEXT . " for '$name' in Q{$q_num}.";
+                              $error_style_ids["$q_id"] = 1;
+                          } else {
+                              if (!is_numeric($score)) {
+                                  $errors[] = "You didn't give a valid " . APP__MARK_TEXT . " for '$name' in Q{$q_num}.";
+                                  $error_style_ids["$q_id"] = 1;
+                              } else {
+                                  $score = (int) $score;
+                                  if (($score<0) || ($score>$group_total)) {
+                                      $errors[] = 'Your ' . APP__MARK_TEXT . " of $score for '$name' in Q{$q_num} is invalid.<br /> " . APP__MARK_TEXT . " must be between 0 and $group_total.";
+                                      $error_style_ids["$q_id"] = 1;
+                                  }
+                                  $results["$q"]["$id"] = $score;
+                                  $q_total_marks[$q] += $score;
+                              }
+                          }
+                      }// /foreach $people
+                  } // /for $q
 
             // Loop through the questions again, and check the totals add up to the valid group total
-            for ($q=0; $q<$question_count; $q++) {
-
-              $q_total = $q_total_marks[$q];
+                  for ($q=0; $q<$question_count; $q++) {
+                      $q_total = $q_total_marks[$q];
 
-              $q_num = $q + 1;
+                      $q_num = $q + 1;
 
-              if ($q_total!==$group_total) {
-                $errors[] = "The total " . APP__MARK_TEXT . " for Q{$q_num} should be $group_total.  You have " . APP__MARK_TEXT . " totalling $q_total.";
-              }
-            }
-          } else {
-            // Loop through every question
-            for ($q=0; $q<$question_count; $q++) {
-              $question = $form->get_question($q);
-
-              $q_num = $q + 1;
-
-              $range = explode('-', $question['range']['_data']);
-              $min_score = $range[0];
-              $max_score = $range[1];
-
-              // Loop through every person
-              foreach ($people as $id => $name) {
-                $q_id = "q_{$q}_{$id}";
-                $score = Common::fetch_POST($q_id, null);
-
-                if (is_null($score)) {
-                  $errors[] = "You didn't give a " . APP__MARK_TEXT . " for '$name' in Q{$q_num}.";
-                  $error_style_ids["$q_id"] = 1;
-                } else {
-                  // Check the score is within the allowed range
-                  $score = (int) $score;
-                  if (($score>=$min_score) && ($score<=$max_score)) {
-                    $results["$q"]["$id"] = $score;
-                  } else {
-                    $errors[] = "The " . APP__MARK_TEXT . " of '$score' given in Q{$q_num} for '$name' is not allowed. " . APP__MARK_TEXT . " must be between $min_score and $max_score.";
-                    $error_style_ids["$q_id"] = 1;
+                      if ($q_total!==$group_total) {
+                          $errors[] = 'The total ' . APP__MARK_TEXT . " for Q{$q_num} should be $group_total.  You have " . APP__MARK_TEXT . " totalling $q_total.";
+                      }
                   }
-                }
-              }// /foreach $people
-            } // /for $q
-          }// /if-else(likert)
+              } else {
+                  // Loop through every question
+                  for ($q=0; $q<$question_count; $q++) {
+                      $question = $form->get_question($q);
+
+                      $q_num = $q + 1;
+
+                      $range = explode('-', $question['range']['_data']);
+                      $min_score = $range[0];
+                      $max_score = $range[1];
+
+                      // Loop through every person
+                      foreach ($people as $id => $name) {
+                          $q_id = "q_{$q}_{$id}";
+                          $score = Common::fetch_POST($q_id, null);
+
+                          if (is_null($score)) {
+                              $errors[] = "You didn't give a " . APP__MARK_TEXT . " for '$name' in Q{$q_num}.";
+                              $error_style_ids["$q_id"] = 1;
+                          } else {
+                              // Check the score is within the allowed range
+                              $score = (int) $score;
+                              if (($score>=$min_score) && ($score<=$max_score)) {
+                                  $results["$q"]["$id"] = $score;
+                              } else {
+                                  $errors[] = 'The ' . APP__MARK_TEXT . " of '$score' given in Q{$q_num} for '$name' is not allowed. " . APP__MARK_TEXT . " must be between $min_score and $max_score.";
+                                  $error_style_ids["$q_id"] = 1;
+                              }
+                          }
+                      }// /foreach $people
+                  } // /for $q
+              }// /if-else(likert)
 
           //check the options to see if the justification is provided
-          if (APP__ALLOW_TEXT_INPUT) {
-            if ($assessment->allow_assessment_feedback) {
-              //get the results and add them all to an array
-              foreach ($people as $id => $name) {
-                $justification_fetch = strip_tags(Common::fetch_POST($id));
-
-                if (!is_null($justification_fetch)) {
-                  $justification[] = array('assessment_id'    =>  $assessment->id,
+              if (APP__ALLOW_TEXT_INPUT) {
+                  if ($assessment->allow_assessment_feedback) {
+                      //get the results and add them all to an array
+                      foreach ($people as $id => $name) {
+                          $justification_fetch = strip_tags(Common::fetch_POST($id));
+
+                          if (!is_null($justification_fetch)) {
+                              $justification[] = ['assessment_id'    =>  $assessment->id,
                                    'group_id'       =>  $group->id,
                                    'user_id'        =>  $_user->id,
                                    'marked_user_id'   =>  $id,
                                    'justification_text' =>  $justification_fetch,
-                                   'date_marked'      =>  date(MYSQL_DATETIME_FORMAT,time()),);
-                }
+                                   'date_marked'      =>  date(MYSQL_DATETIME_FORMAT, time()), ];
+                          }
+                      }
+                  }
               }
-            }
           }
-        }
       }
 
       $form_renderer->set_results($results);
 
       // If there were no errors, save the changes
       if (!$errors) {
-        // Save the results
-        $now = date(MYSQL_DATETIME_FORMAT,time());
-
-        // Get IP and Computer name of the student saving the marks
-        $ip_address = Common::fetch_SERVER('REMOTE_ADDR','');
-        $computer_name = Common::fetch_SERVER('REMOTE_HOST','');
-        $date_opened = Common::fetch_POST('date_opened');
-
-        // Save stats
-        $response = array (
-          'assessment_id'   => $assessment->id ,
-          'group_id'        => $group->id ,
-          'user_id'         => $_user->id ,
-          'ip_address'      => $ip_address ,
-          'comp_name'       => $computer_name ,
-          'date_responded'  => $now ,
-          'date_opened'     => $date_opened ,
-        );
-        $DB->do_insert("REPLACE INTO " . APP__DB_TABLE_PREFIX . "user_response ({fields}) VALUES ({values}) ", $response);
-
-        foreach ($results as $q => $q_results) {
-          foreach ($q_results as $id => $score) {
-            $result_fields[] = array (
-              'assessment_id'  => $assessment->id ,
-              'group_id'       => $group->id ,
-              'user_id'        => $_user->id ,
-              'marked_user_id' => $id ,
-              'question_id'    => $q ,
-              'score'          => $score ,
-              'date_marked'    => $now ,
-            );
+          // Save the results
+          $now = date(MYSQL_DATETIME_FORMAT, time());
+
+          // Get IP and Computer name of the student saving the marks
+          $ip_address = Common::fetch_SERVER('REMOTE_ADDR', '');
+          $computer_name = Common::fetch_SERVER('REMOTE_HOST', '');
+          $date_opened = Common::fetch_POST('date_opened');
+
+          // find out if a user response already exists
+          $dbConn = $DB->getConnection();
+
+          $existingResponseQuery =
+            'SELECT assessment_id ' .
+            'FROM ' . APP__DB_TABLE_PREFIX . 'user_response ' .
+            'WHERE assessment_id = ? ' .
+            'AND group_id = ? ' .
+            'AND user_id = ?';
+
+          $userResponse = $dbConn->fetchOne(
+              $existingResponseQuery,
+              [$assessment->id, $group->id, $_user->id],
+              [ParameterType::STRING, ParameterType::STRING, ParameterType::INTEGER]
+          );
+
+          $queryBuilder = $dbConn->createQueryBuilder();
+
+          if (!$userResponse) {
+              // user response does not exist so create it
+              $queryBuilder
+                ->insert(APP__DB_TABLE_PREFIX . 'user_response')
+                ->values([
+                    'assessment_id'   => '?',
+                    'group_id'        => '?',
+                    'user_id'         => '?',
+                    'ip_address'      => '?',
+                    'comp_name'       => '?',
+                    'date_responded'  => '?',
+                    'date_opened'     => '?',
+                ])
+                ->setParameter(0, $assessment->id)
+                ->setParameter(1, $group->id)
+                ->setParameter(2, $_user->id, ParameterType::INTEGER)
+                ->setParameter(3, $ip_address)
+                ->setParameter(4, $computer_name)
+                ->setParameter(5, $now)
+                ->setParameter(6, $date_opened);
+          } else {
+              // user response exists so update it
+              $queryBuilder
+                ->update(APP__DB_TABLE_PREFIX . 'user_response')
+                ->set('ip_address', '?')
+                ->set('comp_name', '?')
+                ->set('date_responded', '?')
+                ->set('date_opened', '?')
+                ->where('assessment_id', '?')
+                ->andWhere('group_id', '?')
+                ->andWhere('user_id', '?')
+                ->setParameter(0, $ip_address)
+                ->setParameter(1, $computer_name)
+                ->setParameter(2, $now)
+                ->setParameter(3, $date_opened)
+                ->setParameter(4, $assessment->id)
+                ->setParameter(5, $group->id)
+                ->setParameter(6, $_user->id, ParameterType::INTEGER);
           }
-        }
-        $DB->do_insert_multi("REPLACE INTO " . APP__DB_TABLE_PREFIX . "user_mark ({fields}) VALUES {values}", $result_fields);
 
-        //along with the saved marks we want to save the justification section
-        $DB->do_insert_multi("INSERT INTO " . APP__DB_TABLE_PREFIX . "user_justification ({fields}) VALUES {values}", $justification);
+          $queryBuilder->execute();
+
+          foreach ($results as $q => $q_results) {
+              foreach ($q_results as $id => $score) {
+                  $DB->getConnection()
+                  ->createQueryBuilder()
+                  ->insert(APP__DB_TABLE_PREFIX . 'user_mark')
+                  ->values([
+                      'assessment_id'  => '?',
+                      'group_id'       => '?',
+                      'user_id'        => '?',
+                      'marked_user_id' => '?',
+                      'question_id'    => '?',
+                      'score'          => '?',
+                      'date_marked'    => '?',
+                  ])
+                  ->setParameter(0, $assessment->id)
+                  ->setParameter(1, $group->id)
+                  ->setParameter(2, $_user->id, ParameterType::INTEGER)
+                  ->setParameter(3, $id, ParameterType::INTEGER)
+                  ->setParameter(4, $q, ParameterType::INTEGER)
+                  ->setParameter(5, $score, ParameterType::INTEGER)
+                  ->setParameter(6, $now)
+                  ->execute();
+              }
+          }
 
-        Common::logEvent($DB, 'Assessment submission successful', $_module_id, $assessment->id);
+          // along with the saved marks we want to save the justification section
+          if (is_iterable($justification)) {
+              foreach ($justification as $userJustification) {
+                  $DB->getConnection()
+                      ->createQueryBuilder()
+                      ->insert(APP__DB_TABLE_PREFIX . 'user_justification')
+                      ->values([
+                          'assessment_id' => '?',
+                          'group_id' => '?',
+                          'user_id' => '?',
+                          'marked_user_id' => '?',
+                          'justification_text' => '?',
+                          'date_marked' => '?',
+                      ])
+                      ->setParameter(0, $userJustification['assessment_id'])
+                      ->setParameter(1, $userJustification['group_id'])
+                      ->setParameter(2, $userJustification['user_id'])
+                      ->setParameter(3, $userJustification['marked_user_id'])
+                      ->setParameter(4, $userJustification['justification_text'])
+                      ->setParameter(5, $userJustification['date_marked'])
+                      ->execute();
+              }
+          }
 
-        header("Location: ". APP__WWW ."/students/assessments/take/finished.php?{$assessment_qs}");
-        exit;
 
-      } else {
-        Common::logEvent($DB, 'Assessment submission failed', $_module_id, $assessment->id);
+          Common::logEvent($DB, 'Assessment submission successful', $_module_id, $assessment->id);
+
+          header('Location: '. APP__WWW ."/students/assessments/take/finished.php?{$assessment_qs}");
+          exit;
       }
+          Common::logEvent($DB, 'Assessment submission failed', $_module_id, $assessment->id);
+      
 
       break;
   }// /switch
@@ -294,10 +371,10 @@
 $UI->page_title = APP__NAME . ' ' . $assessment->name;
 $UI->menu_selected = 'my assessments';
 $UI->help_link = '?q=node/329';
-$UI->breadcrumbs = array  (
-  'home'             => '/' ,
-  $assessment->name  => null ,
-);
+$UI->breadcrumbs = [
+  'home'             => '/',
+  $assessment->name  => null,
+];
 
 $UI->head();
 ?>
@@ -308,9 +385,9 @@
 
 // rows to highlight because they have errors:
 if (is_array($error_style_ids)) {
-  foreach($error_style_ids as $id => $v) {
-    echo("#{$id} td { background-color: #fcc; }\n");
-  }
+    foreach ($error_style_ids as $id => $v) {
+        echo "#{$id} td { background-color: #fcc; }\n";
+    }
 }
 
 ?>
@@ -332,7 +409,7 @@ function do_command(com) {
 </script>
 <?php
 if ($assessment) {
-  $form_renderer->draw_head();
+    $form_renderer->draw_head();
 }
 $UI->content_start();
 
@@ -343,24 +420,24 @@ function do_command(com) {
 
 <?php
 if (!$assessment) {
-?>
+    ?>
   <div class="nav_button_bar">
-    <a href="<?php echo($list_url) ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a>
+    <a href="<?php echo $list_url ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a>
   </div>
 
   <p>The assessment you selected could not be loaded for some reason - please go back and try again.</p>
   <p>If the problem persists, please use the contact system to <a href="/students/support/contact/index.php?q=bug">report the error</a>.</p>
 <?php
 } else {
-?>
-  <form action="index.php?<?php echo($assessment_qs); ?>" method="post" name="assessment_form">
+        ?>
+  <form action="index.php?<?php echo $assessment_qs; ?>" method="post" name="assessment_form">
   <input type="hidden" name="command" value="none" />
-  <input type="hidden" name="date_opened" value="<?php echo(date(MYSQL_DATETIME_FORMAT,time())); ?>" />
+  <input type="hidden" name="date_opened" value="<?php echo date(MYSQL_DATETIME_FORMAT, time()); ?>" />
 
   <div class="nav_button_bar">
     <table cellpadding="0" cellspacing="0" width="100%">
     <tr>
-      <td><a href="<?php echo($list_url); ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a></td>
+      <td><a href="<?php echo $list_url; ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a></td>
     </tr>
     </table>
   </div>
@@ -368,7 +445,9 @@ function do_command(com) {
 
   <h3>Taking This Assessment</h3>
   <div class="form_section">
-    <p>Please complete the assessment below. For each question <em>you must give a <?php echo APP__MARK_TEXT; ?> to each group member</em><?php if ($assessment->assessment_type != '0') echo ', including yourself'; ?>.</p>
+    <p>Please complete the assessment below. For each question <em>you must give a <?php echo APP__MARK_TEXT; ?> to each group member</em><?php if ($assessment->assessment_type != '0') {
+            echo ', including yourself';
+        } ?>.</p>
     <p>To save your <?php echo APP__MARK_TEXT; ?>, you must click the <em>Save <?php echo APP__MARK_TEXT; ?></em> button.  Once you have successfully submitted your responses you cannot go back and change your <?php echo APP__MARK_TEXT; ?>.</p>
     <p>To leave this assessment without saving, click the <em>back to assessments list</em> link above, or choosing an option from the menu.</p>
   </div>
@@ -377,26 +456,23 @@ function do_command(com) {
   <h3><?php echo APP__MARK_TEXT; ?> Your Team</h3>
   <div class="form_section">
 <?php
-  $form_renderer->draw_description();
-?>
+  $form_renderer->draw_description(); ?>
   </div>
 
 <?php
   if (!empty($assessment->introduction)) {
-?>
+      ?>
     <h3>Introduction</h3>
     <div class="form_section">
-      <p class="introduction"><?php echo(nl2br(htmlentities($assessment->introduction))); ?></p>
+      <p class="introduction"><?php echo nl2br(htmlentities($assessment->introduction)); ?></p>
     </div>
 <?php
-  }
-?>
+  } ?>
 
   <div class="form_line">
   <h2>Assessment Criteria</h2>
 <?php
-  $form_renderer->draw_form();
-?>
+  $form_renderer->draw_form(); ?>
   </div>
 
   <p>That concludes this peer assessment. To finish and submit your response click the <em>save <?php echo APP__MARK_TEXT; ?></em> button below.</p>
@@ -409,7 +485,7 @@ function do_command(com) {
   </form>
 <?php
   Common::logEvent($DB, 'Assessment started', $_module_id, $assessment->id);
-}
+    }
 ?>
 </div>
 
diff --git a/src/students/assessments/take/not_open.php b/src/students/assessments/take/not_open.php
index df1e31d..72a7011 100644
--- a/src/students/assessments/take/not_open.php
+++ b/src/students/assessments/take/not_open.php
@@ -8,14 +8,14 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_STUDENT)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_STUDENT)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -29,20 +29,19 @@
 
 $assessment = new Assessment($DB);
 if ($assessment->load($assessment_id)) {
-
 } else {
-  $assessment = null;
+    $assessment = null;
 }
 
 // --------------------------------------------------------------------------------
 // Begin Page
 
-$UI->page_title = APP__NAME . ' ' . ($assessment) ? $assessment->name : "not open";
+$UI->page_title = APP__NAME . ' ' . ($assessment) ? $assessment->name : 'not open';
 $UI->menu_selected = 'my assessments';
 $UI->help_link = '?q=node/329';
-$UI->breadcrumbs = array  ('home'       => '/' ,
-               $assessment->name  => null ,
-              );
+$UI->breadcrumbs = ['home'       => '/',
+               $assessment->name  => null,
+              ];
 
 $UI->head();
 $UI->content_start();
@@ -52,28 +51,28 @@
 
 <?php
 if (!$assessment) {
-  ?>
+    ?>
   <div class="nav_button_bar">
-    <a href="<?php echo($list_url) ?>"><img src="/images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a>
+    <a href="<?php echo $list_url ?>"><img src="/images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a>
   </div>
 
   <p>The assessment you selected could not be loaded for some reason - However, in this case, the assessment is <em>not open and cannot accept student <?php echo APP__MARK_TEXT; ?></em>.</p>
   <p>If the problem loading this assessment persists, please use the contact system to <a href="/students/support/contact/index.php?q=bug">report the error</a>.</p>
 <?php
 } else {
-?>
+        ?>
   <div class="nav_button_bar">
     <table cellpadding="0" cellspacing="0" width="100%">
     <tr>
-      <td><a href="<?php echo($list_url); ?>"><img src="/images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a></td>
+      <td><a href="<?php echo $list_url; ?>"><img src="/images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a></td>
     </tr>
     </table>
   </div>
 
   <p>This assessment is not open at the present time, so you cannot submit any <?php echo APP__MARK_TEXT; ?>.</p>
-  <p>If you have missed the deadline, contact your lecturer. Otherwise, if you have another assessment to take, please select it from your <a href="<?php echo($list_url); ?>">assessments list</a>.</p>
+  <p>If you have missed the deadline, contact your lecturer. Otherwise, if you have another assessment to take, please select it from your <a href="<?php echo $list_url; ?>">assessments list</a>.</p>
 <?php
-}
+    }
 ?>
 </div>
 
diff --git a/src/students/groups/index.php b/src/students/groups/index.php
index 689c405..6a54e60 100644
--- a/src/students/groups/index.php
+++ b/src/students/groups/index.php
@@ -8,21 +8,21 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../includes/inc_global.php");
+require_once '../../includes/inc_global.php';
 
 use WebPA\includes\classes\GroupHandler;
 use WebPA\includes\classes\SimpleObjectIterator;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_STUDENT)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_STUDENT)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
 
 $group_handler = new GroupHandler();
-$collections = $group_handler->get_member_collections($_user->id, APP__ID, 'user');
+$collections = $group_handler->get_member_collections($_user->id, 'user');
 
 // --------------------------------------------------------------------------------
 // Begin Page
@@ -30,8 +30,8 @@
 $UI->page_title = APP__NAME . ' my groups';
 $UI->menu_selected = 'my groups';
 $UI->help_link = '?q=node/329';
-$UI->breadcrumbs = array  ('home'         => '/' ,
-               'my groups'    => null );
+$UI->breadcrumbs = ['home'         => '/',
+               'my groups'    => null, ];
 
 $UI->head();
 ?>
@@ -69,52 +69,49 @@
 <div class="form_section">
 <?php
 if (!$collections) {
-?>
+    ?>
     <p>You are not listed as a member of any group.</p>
     <p>Only groups that have been scheduled an assessment will appear in this list.</p>
 <?php
 } else {
-  $collection_iterator = new SimpleObjectIterator($collections, 'GroupCollection', $group_handler->_DAO);
-?>
+        $collection_iterator = new SimpleObjectIterator($collections, 'GroupCollection', $group_handler->_DAO); ?>
     <p>You belong to the following groups.</p>
 <?php
-  for($collection_iterator->reset(); $collection_iterator->is_valid(); $collection_iterator->next() ) {
-    $collection =& $collection_iterator->current();
-    $groups = $collection->get_member_groups($_user->id);
+  for ($collection_iterator->reset(); $collection_iterator->is_valid(); $collection_iterator->next()) {
+      $collection =& $collection_iterator->current();
+      $groups = $collection->get_member_groups($_user->id);
 
 
-    echo('<div class="collection">');
-    echo("  <div class=\"collection_name\">{$collection->name}</div>");
+      echo '<div class="collection">';
+      echo "  <div class=\"collection_name\">{$collection->name}</div>";
 
-    foreach($groups as $i => $group) {
-      $member_ids = array_keys( $group->get_members() );
-      $members = $CIS->get_user($member_ids);
-?>
+      foreach ($groups as $i => $group) {
+          $member_ids = array_keys($group->get_members());
+          $members = $CIS->get_user($member_ids); ?>
         <div class="group">
           <table cellpadding="2" cellspacing="2">
           <tr>
-            <td valign="top"><div class="group_name"><?php echo($group->name); ?></div></td>
+            <td valign="top"><div class="group_name"><?php echo $group->name; ?></div></td>
             <td valign="top">
               <div class="members">
 <?php
-      foreach($members as $i => $member) {
-        if ($_user->id==$member['user_id']) {
-          echo("      <div class=\"own_member_name\">{$member['forename']} {$member['lastname']}</div>");
-        } else {
-          echo("      <div class=\"member_name\">{$member['forename']} {$member['lastname']}</div>");
-        }
-      }
-?>
+      foreach ($members as $i => $member) {
+          if ($_user->id==$member['user_id']) {
+              echo "      <div class=\"own_member_name\">{$member['forename']} {$member['lastname']}</div>";
+          } else {
+              echo "      <div class=\"member_name\">{$member['forename']} {$member['lastname']}</div>";
+          }
+      } ?>
               </div>
             </td>
           </tr>
           </table>
         </div>
 <?php
-    }
-    echo('</div>');
+      }
+      echo '</div>';
   }
-}
+    }
 ?>
 </div>
 </div>
diff --git a/src/students/index.php b/src/students/index.php
index 35a839f..052d38f 100644
--- a/src/students/index.php
+++ b/src/students/index.php
@@ -8,17 +8,18 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../includes/inc_global.php");
+require_once '../includes/inc_global.php';
 
-use WebPA\includes\functions\ArrayFunctions;
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\GroupHandler;
 use WebPA\includes\classes\SimpleObjectIterator;
 use WebPA\includes\functions\AcademicYear;
+use WebPA\includes\functions\ArrayFunctions;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_STUDENT)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_STUDENT)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -27,40 +28,74 @@
 
 // Get a list of collections that the user is a member of
 
-$collections = $group_handler->get_member_collections($_user->id, APP__ID, 'assessment');
-
-$collection_ids = ArrayFunctions::array_extract_column($collections, 'collection_id');
-$collection_clause = $DB->build_set($collection_ids);
-
-// Get a list of assessments that match the user's collections (for this year)
-
-$academic_year = AcademicYear::get_academic_year();
+$collections = $group_handler->get_member_collections($_user->id, 'assessment');
+$collection_ids = [];
 
-$start_date = mktime(0, 0, 0, APP__ACADEMIC_YEAR_START_MONTH, 1, $academic_year);
-$end_date = mktime(0, 0, 0, APP__ACADEMIC_YEAR_START_MONTH, 1, $academic_year + 1);
-
-$sql_start_date = date(MYSQL_DATETIME_FORMAT, $start_date);
-$sql_end_date = date(MYSQL_DATETIME_FORMAT, $end_date);
+if (empty($collections)) {
+    $collections = [];
+} else {
+    $collection_ids = ArrayFunctions::array_extract_column($collections, 'collection_id');
+}
 
-$assessments = $DB->fetch('SELECT a.* FROM ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
-                          "WHERE (a.module_id = {$_module_id}) AND " .
-                                "(a.collection_id IN $collection_clause) AND " .
-                                "(a.open_date >= '{$sql_start_date}') AND " .
-                                "(a.open_date < '{$sql_end_date}') " .
-                          'ORDER BY a.open_date, a.close_date, a.assessment_name');
+$assessments = [];
 
+// Get a list of assessments that match the user's collections (for this year)
+if (count($collections) > 0) {
+    $academic_year = AcademicYear::get_academic_year();
+
+    $start_date = mktime(0, 0, 0, APP__ACADEMIC_YEAR_START_MONTH, 1, $academic_year);
+    $end_date = mktime(0, 0, 0, APP__ACADEMIC_YEAR_START_MONTH, 1, $academic_year + 1);
+
+    $sql_start_date = date(MYSQL_DATETIME_FORMAT, $start_date);
+    $sql_end_date = date(MYSQL_DATETIME_FORMAT, $end_date);
+
+    $assessmentsQuery =
+        'SELECT a.* ' .
+        'FROM ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
+        'WHERE a.module_id = ? ' .
+        'AND a.collection_id IN (?) ' .
+        'AND a.open_date >= ? ' .
+        'AND a.open_date < ? ' .
+        'ORDER BY a.open_date, a.close_date, a.assessment_name';
+
+    $assessments = $DB->getConnection()->fetchAllAssociative(
+            $assessmentsQuery,
+            [
+                $_module_id,
+                $collection_ids,
+                $sql_start_date,
+                $sql_end_date,
+            ],
+            [
+                ParameterType::INTEGER,
+                $DB->getConnection()::PARAM_STR_ARRAY,
+                ParameterType::STRING,
+                ParameterType::STRING,
+            ]
+    );
+}
 
 // Get a list of those assessments that the user has already taken
-
 $assessment_ids = ArrayFunctions::array_extract_column($assessments, 'assessment_id');
-$assessment_clause = $DB->build_set($assessment_ids);
-
-$assessments_with_response = $DB->fetch_col('SELECT DISTINCT um.assessment_id ' .
-                                            'FROM ' . APP__DB_TABLE_PREFIX . 'user_mark um ' .
-                                            "WHERE (a.module_id = {$_module_id}) AND " .
-                                                  "(um.assessment_id IN {$assessment_clause}) AND " .
-                                                  "(um.user_id = {$_user->id}) " .
-                                            'ORDER BY um.assessment_id');
+$assessments_with_response = [];
+
+if ($assessment_ids !== null && count($assessment_ids) > 0) {
+    $respondedAssessmentsQuery =
+        'SELECT DISTINCT um.assessment_id ' .
+        'FROM ' . APP__DB_TABLE_PREFIX . 'user_mark um ' .
+        'LEFT JOIN ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
+        'ON a.assessment_id = um.assessment_id ' .
+        'WHERE a.module_id = ? ' .
+        'AND um.assessment_id IN (?) ' .
+        'AND um.user_id = ? ' .
+        'ORDER BY um.assessment_id';
+
+    $assessments_with_response = $DB->getConnection()->fetchFirstColumn(
+        $respondedAssessmentsQuery,
+        [$_module_id, $assessment_ids, $_user->id],
+        [ParameterType::INTEGER, $DB->getConnection()::PARAM_STR_ARRAY, ParameterType::INTEGER]
+    );
+}
 
 // Split the assessments into pending, open and finished
 $pending_assessments = null;
@@ -68,26 +103,25 @@
 $finished_assessments = null;
 
 if ($assessments) {
-
-  foreach($assessments as $i => $assessment) {
-    if ( (is_array($assessments_with_response)) && (in_array($assessment['assessment_id'], $assessments_with_response)) ) {
-      $finished_assessments[] = $assessment;
-    } else {
-      $now = time();
-      $open_date = strtotime($assessment['open_date']);
-      $close_date = strtotime($assessment['close_date']);
-
-      if ($close_date<=$now) {
-        $finished_assessments[] = $assessment;
-      } else {
-        if ($open_date>$now) {
-          $pending_assessments[] = $assessment;
+    foreach ($assessments as $i => $assessment) {
+        if ((is_array($assessments_with_response)) && (in_array($assessment['assessment_id'], $assessments_with_response))) {
+            $finished_assessments[] = $assessment;
         } else {
-          $open_assessments[] = $assessment;
+            $now = time();
+            $open_date = strtotime($assessment['open_date']);
+            $close_date = strtotime($assessment['close_date']);
+
+            if ($close_date<=$now) {
+                $finished_assessments[] = $assessment;
+            } else {
+                if ($open_date>$now) {
+                    $pending_assessments[] = $assessment;
+                } else {
+                    $open_assessments[] = $assessment;
+                }
+            }
         }
-      }
     }
-  }
 }
 
 //------------------------------------------------
@@ -99,8 +133,8 @@
 
 $UI->page_title = APP__NAME;
 $UI->menu_selected = 'home';
-$UI->breadcrumbs = array  ('home'       => null ,
-                          );
+$UI->breadcrumbs = ['home'       => null,
+                          ];
 $UI->help_link = '?q=node/329';
 
 $UI->head();
@@ -114,12 +148,12 @@
 <div class="content_box">
   <?php
   if (!$open_assessments) {
-    ?>
+      ?>
     <p>There are no assessments in this module available for you to take at the moment.</p>
     <p>To view all the assessments you are registered on, please check the <a href="assessments/">my assessments</a> section.</p>
     <?php
   } else {
-    ?>
+      ?>
     <p>Below is a list of the assessments in this module you can take now.</p>
     <p>To view all the assessments you are registered on in this module, please check the <a href="assessments/">my assessments</a> section.</p>
 
@@ -129,35 +163,34 @@
       $status = 'open';
       $status_capitalized = ucfirst($status);
 
-      $assessment_iterator = new SimpleObjectIterator($open_assessments,'Assessment', $DB);
+      $assessment_iterator = new SimpleObjectIterator($open_assessments, 'Assessment', $DB);
       for ($assessment_iterator->reset(); $assessment_iterator->is_valid(); $assessment_iterator->next()) {
-        $assessment =& $assessment_iterator->current();
-        $take_url = "assessments/take/index.php?a={$assessment->id}";
-
-        echo("<div class=\"assessment_open\">");
-        echo('<table class="assessment_info" cellpadding="0" cellspacing="0">');
-        echo('<tr>');
-        echo("  <td width=\"24\"><img src=\"../images/icons/{$status}_icon.gif\" alt=\"$status_capitalized\" title=\"$status_capitalized\" height=\"24\" width=\"24\" /></td>");
-        echo('  <td valign="top">');
-        echo('    <div class="assessment_info">');
-        echo("      <div class=\"assessment_name\">{$assessment->name}</div>");
-        echo('      <div class="assessment_schedule">scheduled: '. $assessment->get_date_string('open_date') .' &nbsp;-&nbsp; '. $assessment->get_date_string('close_date') . ' </div>');
-        echo('    </div>');
-        echo('  </td>');
-        echo('  <td class="buttons" style="line-height: 2em; text-align: right;">');
-        echo("    <a class=\"button\" href=\"$take_url\">Take Assessment</a>");
-        echo('  </td>');
-        echo('</tr>');
-        echo('</table>');
-        echo('</div>');
-      }
-    ?>
+          $assessment =& $assessment_iterator->current();
+          $take_url = "assessments/take/index.php?a={$assessment->id}";
+
+          echo '<div class="assessment_open">';
+          echo '<table class="assessment_info" cellpadding="0" cellspacing="0">';
+          echo '<tr>';
+          echo "  <td width=\"24\"><img src=\"../images/icons/{$status}_icon.gif\" alt=\"$status_capitalized\" title=\"$status_capitalized\" height=\"24\" width=\"24\" /></td>";
+          echo '  <td valign="top">';
+          echo '    <div class="assessment_info">';
+          echo "      <div class=\"assessment_name\">{$assessment->name}</div>";
+          echo '      <div class="assessment_schedule">scheduled: '. $assessment->get_date_string('open_date') .' &nbsp;-&nbsp; '. $assessment->get_date_string('close_date') . ' </div>';
+          echo '    </div>';
+          echo '  </td>';
+          echo '  <td class="buttons" style="line-height: 2em; text-align: right;">';
+          echo "    <a class=\"button\" href=\"$take_url\">Take Assessment</a>";
+          echo '  </td>';
+          echo '</tr>';
+          echo '</table>';
+          echo '</div>';
+      } ?>
     </div>
     <?php
   }
 
   if ($pending_assessments) {
-    ?>
+      ?>
     <h2>Pending Assessments</h2>
     <p>These assessments scheduled for some point in the future.</p>
     <div class="form_section form_line">
@@ -165,27 +198,26 @@
       $status = 'pending';
       $status_capitalized = ucfirst($status);
 
-      $assessment_iterator = new SimpleObjectIterator($pending_assessments,'Assessment', $DB);
+      $assessment_iterator = new SimpleObjectIterator($pending_assessments, 'Assessment', $DB);
 
       for ($assessment_iterator->reset(); $assessment_iterator->is_valid(); $assessment_iterator->next()) {
-        $assessment =& $assessment_iterator->current();
-        $take_url = "/assessments/take/index.php?a={$assessment->id}";
-
-        echo("<div class=\"assessment\">");
-        echo('<table class="assessment_info" cellpadding="0" cellspacing="0">');
-        echo('<tr>');
-        echo("  <td width=\"24\"><img src=\"/images/icons/{$status}_icon.gif\" alt=\"$status_capitalized\" title=\"$status_capitalized\" height=\"24\" width=\"24\" /></td>");
-        echo('  <td valign="top">');
-        echo('    <div class="assessment_info">');
-        echo("      <div class=\"assessment_name\">{$assessment->name}</div>");
-        echo('      <div class="assessment_schedule">scheduled: '. $assessment->get_date_string('open_date') .' &nbsp;-&nbsp; '. $assessment->get_date_string('close_date') . ' </div>');
-        echo('    </div>');
-        echo('  </td>');
-        echo('</tr>');
-        echo('</table>');
-        echo('</div>');
-      }
-    ?>
+          $assessment =& $assessment_iterator->current();
+          $take_url = "/assessments/take/index.php?a={$assessment->id}";
+
+          echo '<div class="assessment">';
+          echo '<table class="assessment_info" cellpadding="0" cellspacing="0">';
+          echo '<tr>';
+          echo "  <td width=\"24\"><img src=\"/images/icons/{$status}_icon.gif\" alt=\"$status_capitalized\" title=\"$status_capitalized\" height=\"24\" width=\"24\" /></td>";
+          echo '  <td valign="top">';
+          echo '    <div class="assessment_info">';
+          echo "      <div class=\"assessment_name\">{$assessment->name}</div>";
+          echo '      <div class="assessment_schedule">scheduled: '. $assessment->get_date_string('open_date') .' &nbsp;-&nbsp; '. $assessment->get_date_string('close_date') . ' </div>';
+          echo '    </div>';
+          echo '  </td>';
+          echo '</tr>';
+          echo '</table>';
+          echo '</div>';
+      } ?>
     </div>
     <?php
   }
diff --git a/src/tutors/assessments/clone/index.php b/src/tutors/assessments/clone/index.php
index a5c64c0..b5216eb 100644
--- a/src/tutors/assessments/clone/index.php
+++ b/src/tutors/assessments/clone/index.php
@@ -8,13 +8,13 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -23,9 +23,9 @@
 $UI->page_title = APP__NAME .' Create a new assessment';
 $UI->menu_selected = 'my assessments';
 $UI->help_link = '?q=node/235';
-$UI->breadcrumbs = array  ('home'         => '../../' ,
-               'my assessments'   => '../' ,
-               'clone an assessment'  => null ,);
+$UI->breadcrumbs = ['home'         => '../../',
+               'my assessments'   => '../',
+               'clone an assessment'  => null, ];
 
 $UI->set_page_bar_button('List Assessments', '../../../../images/buttons/button_assessment_list.gif', '../');
 $UI->set_page_bar_button('Create Assessments', '../../../../images/buttons/button_assessment_create.gif', '../create/');
diff --git a/src/tutors/assessments/create/class_wizardstep_1.php b/src/tutors/assessments/create/class_wizardstep_1.php
index d2bb472..e6ea1cf 100644
--- a/src/tutors/assessments/create/class_wizardstep_1.php
+++ b/src/tutors/assessments/create/class_wizardstep_1.php
@@ -12,31 +12,30 @@
 use WebPA\includes\functions\Common;
 use WebPA\includes\functions\Form;
 
-class WizardStep1 {
+class WizardStep1
+{
+    public $wizard;
 
-  // Public
-  public $wizard = null;
-  public $step = 1;
+    public $step = 1;
 
-  /*
-  * CONSTRUCTOR
-  */
-  function __construct(Wizard $wizard) {
-    $this->wizard = $wizard;
+    public function __construct(Wizard $wizard)
+    {
+        $this->wizard = $wizard;
 
-    $this->wizard->back_button = null;
-    $this->wizard->next_button = 'Next &gt;';
-    $this->wizard->cancel_button = 'Cancel';
-  }// /WizardStep1()
+        $this->wizard->back_button = null;
+        $this->wizard->next_button = 'Next &gt;';
+        $this->wizard->cancel_button = 'Cancel';
+    }
 
-  function head() {
-?>
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
   function body_onload() {
     document.getElementById('assessment_name').focus();
-  }// /body_onload()
+  }
 
   function open_close(id) {
     id = document.getElementById(id);
@@ -52,74 +51,75 @@ function open_close(id) {
 //-->
 </script>
 <?php
-  }// /->head()
+    }
 
+    public function form()
+    {
+        $today = time();
 
-  function form() {
-    $today = time();
+        $open_date = $this->wizard->get_field('open_date');
 
-    $open_date = $this->wizard->get_field('open_date');
-    if (is_null($open_date)) { $open_date = mktime(9, 0, 0); }  // default start time, today @ 9am
+        if (is_null($open_date)) {
+            $open_date = mktime(9, 0, 0);
+        }  // default start time, today @ 9am
 
-    $close_date = $this->wizard->get_field('close_date');
-    if (is_null($close_date)) { $close_date = mktime(17, 0, 0, date('m',$today), date('d',$today)+13, date('Y',$today) ); } // default start time, two-weeks today @ 5pm
+        $close_date = $this->wizard->get_field('close_date');
+        if (is_null($close_date)) {
+            $close_date = mktime(17, 0, 0, date('m', $today), date('d', $today)+13, date('Y', $today));
+        } // default start time, two-weeks today @ 5pm
 
 
-    $email = $this->wizard->get_field('email',0);
-    $email_opening = $this->wizard->get_field('email_opening',0);
-    $email_closing = $this->wizard->get_field('email_closing', 0);
+        $email = $this->wizard->get_field('email', 0);
+        $email_opening = $this->wizard->get_field('email_opening', 0);
+        $email_closing = $this->wizard->get_field('email_closing', 0);
 
-    /*
-    * Render a set of dropdown boxes for datetime selection
-    */
-    function render_datetime_boxes($field_name = 'datetime' , $selected_datetime) {
-      echo('<table cellpadding="0" cellspacing="0"><tr>');
+        // Render a set of dropdown boxes for datetime selection
+        $renderTimeBoxes = function ($field_name, $selected_datetime) {
+            echo '<table cellpadding="0" cellspacing="0"><tr>';
 
-      // Draw day box
-      echo("<td><select name=\"{$field_name}_day\">");
-      Form::render_options_range(1, 31, 1, date('j',$selected_datetime));
-      echo('</select></td>');
+            // Draw day box
+            echo "<td><select name=\"{$field_name}_day\">";
+            Form::render_options_range(1, 31, 1, date('j', $selected_datetime));
+            echo '</select></td>';
 
-      $form_months = array( 1 => 'January','February','March','April','May','June','July','August','September','October','November','December');
+            $form_months = [1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
 
-      // Draw month box
-      echo("<td><select name=\"{$field_name}_month\">");
-      Form::render_options($form_months, date('n', $selected_datetime));
-      echo('</select></td>');
+            // Draw month box
+            echo "<td><select name=\"{$field_name}_month\">";
+            Form::render_options($form_months, date('n', $selected_datetime));
+            echo '</select></td>';
 
-      // Draw year box
-      echo("<td><select name=\"{$field_name}_year\">");
-      Form::render_options_range(date('Y',time()), date('Y',time())+1, 1, date('Y', $selected_datetime));
-      echo('</select></td>');
+            // Draw year box
+            echo "<td><select name=\"{$field_name}_year\">";
+            Form::render_options_range(date('Y', time()), date('Y', time())+1, 1, date('Y', $selected_datetime));
+            echo '</select></td>';
 
-      echo('<th>at</th>');
+            echo '<th>at</th>';
 
-      // Draw time box
-      $time = date('H:i', $selected_datetime);
-      $time_parts = explode(':',$time);
-      $time_h = (int) $time_parts[0];
-      $time_m = (int) $time_parts[1];
+            // Draw time box
+            $time = date('H:i', $selected_datetime);
+            $time_parts = explode(':', $time);
+            $time_h = (int) $time_parts[0];
+            $time_m = (int) $time_parts[1];
 
-      echo("<td><select name=\"{$field_name}_time\">");
-      for ($i=0; $i<=23; $i++) {
-        for ($j=0; $j<=45; $j=$j+15) {
-          $selected = ( ($i == $time_h) && ($j == $time_m) ) ? 'selected="selected"' : '' ;
-          printf('<option value="%1$02d:%2$02d" '. $selected .'> %1$02d:%2$02d </option>',$i,$j);
-        }
-      }
-      echo('</select></td>');
+            echo "<td><select name=\"{$field_name}_time\">";
+            for ($i=0; $i<=23; $i++) {
+                for ($j=0; $j<=45; $j=$j+15) {
+                    $selected = (($i == $time_h) && ($j == $time_m)) ? 'selected="selected"' : '' ;
+                    printf('<option value="%1$02d:%2$02d" '. $selected .'> %1$02d:%2$02d </option>', $i, $j);
+                }
+            }
+            echo '</select></td>';
 
-      echo('</tr></table>');
-    }
-
-?>
+            echo '</tr></table>';
+        } ?>
     <p>To create a new assessment you must first give it a name. To avoid confusion, the name should be unique, but you can create assessments using the same name if you wish.</p>
 
     <div class="form_section">
       <table class="form" cellpadding="2" cellspacing="2">
       <tr>
         <th><label for="assessment_name">Name for this new assessment</label></th>
-        <td><input type="text" name="assessment_name" id="assessment_name" maxlength="100" size="40" value="<?php echo( $this->wizard->get_field('assessment_name') ); ?>" /></td>
+        <td><input type="text" name="assessment_name" id="assessment_name" maxlength="100" size="40" value="<?php echo $this->wizard->get_field('assessment_name'); ?>" /></td>
       </tr>
       </table>
     </div>
@@ -129,11 +129,11 @@ function render_datetime_boxes($field_name = 'datetime' , $selected_datetime) {
       <table class="form" cellpadding="2" cellspacing="2">
       <tr>
         <th><label>Opening date</label></th>
-        <td><?php render_datetime_boxes('open_date', $open_date); ?></td>
+        <td><?php $renderTimeBoxes('open_date', $open_date); ?></td>
       </tr>
       <tr>
         <th><label>Closing date</label></th>
-        <td><?php render_datetime_boxes('close_date', $close_date); ?></td>
+        <td><?php $renderTimeBoxes('close_date', $close_date); ?></td>
       </tr>
       </table>
     </div>
@@ -144,7 +144,7 @@ function render_datetime_boxes($field_name = 'datetime' , $selected_datetime) {
       <table class="form" cellpadding="2" cellspacing="2" width="100%">
       <tr>
         <th valign="top" style="padding-top: 2px; vertical-align: top;"><label for="introduction">Introduction</label></th>
-        <td width="100%"><textarea name="introduction" id="introduction" rows="6" cols="40" style="width: 90%;"><?php echo($this->wizard->get_field('introduction')); ?></textarea></td>
+        <td width="100%"><textarea name="introduction" id="introduction" rows="6" cols="40" style="width: 90%;"><?php echo $this->wizard->get_field('introduction'); ?></textarea></td>
       </tr>
       </table>
     </div>
@@ -160,11 +160,11 @@ function render_datetime_boxes($field_name = 'datetime' , $selected_datetime) {
       <div class="form_section">
         <table class="form" cellpadding="2" cellspacing="2">
         <tr>
-          <td><input type="radio" name="email" id="email_yes" value="1" <?php echo( ($email) ? 'checked="checked"' : '' ); ?> /></td>
+          <td><input type="radio" name="email" id="email_yes" value="1" <?php echo ($email) ? 'checked="checked"' : ''; ?> /></td>
           <td valign="top"><label class="small" for="email_yes">Yes, email all students.</label></td>
         </tr>
         <tr>
-          <td><input type="radio" name="email" id="email_no" value="0" <?php echo( (!$email) ? 'checked="checked"' : '' ); ?> /></td>
+          <td><input type="radio" name="email" id="email_no" value="0" <?php echo (!$email) ? 'checked="checked"' : ''; ?> /></td>
           <td valign="top"><label class="small" for="email_no">No, don't email all students.</label></td>
         </tr>
         </table>
@@ -172,82 +172,85 @@ function render_datetime_boxes($field_name = 'datetime' , $selected_datetime) {
 
 <?php
     if (APP__REMINDER_OPENING) {
-?>
+        ?>
       <p><label>Do you want an email reminder sent to all students 48 hours before the assessment is opened?</label></p>
       <p>This option will send an email to all of the students who are in the groups for this assessment 48 hours (approx.) before the assessment opens.</p>
       <div class="form_section">
         <table class="form" cellpadding="2" cellspacing="2">
         <tr>
-          <td><input type="radio" name="email_opening" id="email_opening_yes" value="1" <?php echo( ($email_opening) ? 'checked="checked"' : '' ); ?> /></td>
+          <td><input type="radio" name="email_opening" id="email_opening_yes" value="1" <?php echo ($email_opening) ? 'checked="checked"' : ''; ?> /></td>
           <td valign="top"><label class="small" for="email_opening_yes">Yes, email all students.</label></td>
         </tr>
         <tr>
-          <td><input type="radio" name="email_opening" id="email_opening_no" value="0" <?php echo( (!$email_opening) ? 'checked="checked"' : '' ); ?> /></td>
+          <td><input type="radio" name="email_opening" id="email_opening_no" value="0" <?php echo (!$email_opening) ? 'checked="checked"' : ''; ?> /></td>
           <td valign="top"><label class="small" for="email_opening_no">No, don't email all students.</label></td>
         </tr>
         </table>
       </div>
 <?php
     }
-
-    if (APP__REMINDER_CLOSING) {
-?>
+        if (APP__REMINDER_CLOSING) {
+            ?>
       <p><label>Do you want to email all students 48 hours before the assessment closes?</label></p>
       <p>This option will send an email to all of the students who are in the groups for this assessment 48 hours (approx.) before the assessment closes.</p>
       <div class="form_section">
         <table class="form" cellpadding="2" cellspacing="2">
         <tr>
-          <td><input type="radio" name="email_closing" id="email_closing_yes" value="1" <?php echo( ($email_closing) ? 'checked="checked"' : '' ); ?> /></td>
+          <td><input type="radio" name="email_closing" id="email_closing_yes" value="1" <?php echo ($email_closing) ? 'checked="checked"' : ''; ?> /></td>
           <td valign="top"><label class="small" for="email_closing_yes">Yes, email all students.</label></td>
         </tr>
         <tr>
-          <td><input type="radio" name="email_closing" id="email_closing_no" value="0" <?php echo( (!$email_closing) ? 'checked="checked"' : '' ); ?> /></td>
+          <td><input type="radio" name="email_closing" id="email_closing_no" value="0" <?php echo (!$email_closing) ? 'checked="checked"' : ''; ?> /></td>
           <td valign="top"><label class="small" for="email_closing_no">No, don't email all students.</label></td>
         </tr>
         </table>
       </div>
 <?php
-    }
-?>
+        } ?>
 
     </div>
 
 
 <?php
-  }// /->form()
-
+    }
 
-  function process_form() {
-    $errors = null;
+    // /->form()
 
-    $this->wizard->set_field('assessment_name', Common::fetch_POST('assessment_name'));
-    if (empty($this->wizard->get_field('assessment_name'))) { $errors[] = 'You must enter a name for your new assessment'; }
+    public function process_form()
+    {
+        $errors = null;
 
+        $this->wizard->set_field('assessment_name', Common::fetch_POST('assessment_name'));
+        if (empty($this->wizard->get_field('assessment_name'))) {
+            $errors[] = 'You must enter a name for your new assessment';
+        }
 
-    // open_date
-    $time_parts = explode(':', Common::fetch_POST('open_date_time') );
-    $time_h = $time_parts[0];
-    $time_m = $time_parts[1];
-    $open_date = mktime( $time_h, $time_m, 0, Common::fetch_POST('open_date_month'), Common::fetch_POST('open_date_day'), Common::fetch_POST('open_date_year') );
 
-    // close_date
-    $time_parts = explode(':', Common::fetch_POST('close_date_time') );
-    $time_h = $time_parts[0];
-    $time_m = $time_parts[1];
-    $close_date = mktime( $time_h, $time_m, 0, Common::fetch_POST('close_date_month'), Common::fetch_POST('close_date_day'), Common::fetch_POST('close_date_year') );
+        // open_date
+        $time_parts = explode(':', Common::fetch_POST('open_date_time'));
+        $time_h = $time_parts[0];
+        $time_m = $time_parts[1];
+        $open_date = mktime($time_h, $time_m, 0, Common::fetch_POST('open_date_month'), Common::fetch_POST('open_date_day'), Common::fetch_POST('open_date_year'));
 
+        // close_date
+        $time_parts = explode(':', Common::fetch_POST('close_date_time'));
+        $time_h = $time_parts[0];
+        $time_m = $time_parts[1];
+        $close_date = mktime($time_h, $time_m, 0, Common::fetch_POST('close_date_month'), Common::fetch_POST('close_date_day'), Common::fetch_POST('close_date_year'));
 
-    $this->wizard->set_field('open_date',$open_date);
-    $this->wizard->set_field('close_date',$close_date);
-    if ($open_date>=$close_date) { $errors[] = 'You must select a closing date/time that is after your opening date'; }
 
-    $this->wizard->set_field('introduction', Common::fetch_POST('introduction'));
+        $this->wizard->set_field('open_date', $open_date);
+        $this->wizard->set_field('close_date', $close_date);
+        if ($open_date>=$close_date) {
+            $errors[] = 'You must select a closing date/time that is after your opening date';
+        }
 
-    $this->wizard->set_field('email', Common::fetch_POST('email'));
-    $this->wizard->set_field('email_opening',Common::fetch_POST('email_opening'));
-    $this->wizard->set_field('email_closing', Common::fetch_POST('email_closing'));
+        $this->wizard->set_field('introduction', Common::fetch_POST('introduction'));
 
-    return $errors;
-  }// /->process_form()
+        $this->wizard->set_field('email', Common::fetch_POST('email'));
+        $this->wizard->set_field('email_opening', Common::fetch_POST('email_opening'));
+        $this->wizard->set_field('email_closing', Common::fetch_POST('email_closing'));
 
-}// /class: WizardStep1
+        return $errors;
+    }
+}
diff --git a/src/tutors/assessments/create/class_wizardstep_2.php b/src/tutors/assessments/create/class_wizardstep_2.php
index 3bd7698..bf21922 100644
--- a/src/tutors/assessments/create/class_wizardstep_2.php
+++ b/src/tutors/assessments/create/class_wizardstep_2.php
@@ -8,23 +8,20 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
-
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\Wizard;
 use WebPA\includes\functions\Common;
 
 class WizardStep2
 {
+    public $wizard;
 
-    public $wizard = null;
     public $step = 2;
 
     private $moduleId;
 
-    /*
-    * CONSTRUCTOR
-    */
-    function __construct(Wizard $wizard)
+    // CONSTRUCTOR
+    public function __construct(Wizard $wizard)
     {
         $this->wizard = $wizard;
 
@@ -33,9 +30,11 @@ function __construct(Wizard $wizard)
         $this->wizard->back_button = '&lt; Back';
         $this->wizard->next_button = 'Next &gt;';
         $this->wizard->cancel_button = 'Cancel';
-    }// /WizardStep2()
+    }
+
+    // /WizardStep2()
 
-    function head()
+    public function head()
     {
         ?>
         <script language="JavaScript" type="text/javascript">
@@ -58,31 +57,37 @@ function open_close (id) {
           //-->
         </script>
         <?php
-    }// /->head()
+    }
 
+    // /->head()
 
-    function form()
+    public function form()
     {
         $DB = $this->wizard->get_var('db');
         $user = $this->wizard->get_var('user');
 
         $allow_feedback = $this->wizard->get_field('allow_feedback', 0);
 
-        $sql = 'SELECT DISTINCT f.form_id, f.form_name, m.module_id, m.module_code, m.module_title FROM ' . APP__DB_TABLE_PREFIX .
-            'form f INNER JOIN ' . APP__DB_TABLE_PREFIX .
-            'form_module fm ON f.form_id = fm.form_id INNER JOIN ' . APP__DB_TABLE_PREFIX .
-            'user_module um ON fm.module_id = um.module_id INNER JOIN ' . APP__DB_TABLE_PREFIX .
-            'module m ON um.module_id = m.module_id ' .
-            "WHERE (um.user_id = {$user->id}) OR (fm.module_id = {$this->moduleId}) " .
+        $sql =
+            'SELECT DISTINCT f.form_id, f.form_name, m.module_id, m.module_code, m.module_title ' .
+            'FROM ' . APP__DB_TABLE_PREFIX . 'form f ' .
+            'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'form_module fm ' .
+            'ON f.form_id = fm.form_id ' .
+            'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'user_module um ' .
+            'ON fm.module_id = um.module_id ' .
+            'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'module m ' .
+            'ON um.module_id = m.module_id ' .
+            'WHERE um.user_id = ? ' .
+            'OR fm.module_id = ? ' .
             'ORDER BY f.form_name ASC';
-        $forms = $DB->fetch($sql);
+
+        $forms = $DB->getConnection()->fetchAllAssociative($sql, [$user->id, $this->moduleId], [ParameterType::INTEGER, ParameterType::INTEGER]);
 
         $form_id = $this->wizard->get_field('form_id');
         $feedback_name = $this->wizard->get_field('feedback_name');
 
         if (!$forms) {
-            $this->button_next = '';
-            ?>
+            $this->wizard->next_button = ''; ?>
             <p>You haven't yet created any assessment forms.</p>
             <p>You need to <a href="../../forms/create/">create a new form</a> before you will be able to run any peer
                 assessments.</p>
@@ -103,29 +108,27 @@ function form()
                     if (count($forms) == 1) {
                         $form_id = $forms[0]['form_id'];
                     }
-                    foreach ($forms as $i => $form) {
-                        $checked = ($form_id == $form['form_id']) ? 'checked="checked"' : '';
-                        $intro_text = base64_encode($this->wizard->get_field('introduction'));
-                        if ($form['module_id'] == $this->moduleId) {
-                            $module = '';
-                        } else {
-                            $module = " ({$form['module_title']} [{$form['module_code']}])";
-                        }
-                        echo('<tr>');
-                        echo("<td><input type=\"radio\" name=\"form_id\" id=\"form_{$form['form_id']}\" value=\"{$form['form_id']}\" $checked /></td>");
-                        echo("<td><label class=\"small\" for=\"form_{$form['form_id']}\">{$form['form_name']}{$module}</label></td>");
-                        echo("<td>&nbsp; &nbsp; (<a style=\"font-weight: normal; font-size: 84%;\" href=\"../../forms/edit/preview_form.php?f={$form['form_id']}&amp;i={$intro_text}\" target=\"_blank\">preview</a>)</td>");
-                        echo('</tr>');
-                    }
-                    ?>
+            foreach ($forms as $i => $form) {
+                $checked = ($form_id == $form['form_id']) ? 'checked="checked"' : '';
+                $intro_text = base64_encode($this->wizard->get_field('introduction'));
+                if ($form['module_id'] == $this->moduleId) {
+                    $module = '';
+                } else {
+                    $module = " ({$form['module_title']} [{$form['module_code']}])";
+                }
+                echo '<tr>';
+                echo "<td><input type=\"radio\" name=\"form_id\" id=\"form_{$form['form_id']}\" value=\"{$form['form_id']}\" $checked /></td>";
+                echo "<td><label class=\"small\" for=\"form_{$form['form_id']}\">{$form['form_name']}{$module}</label></td>";
+                echo "<td>&nbsp; &nbsp; (<a style=\"font-weight: normal; font-size: 84%;\" href=\"../../forms/edit/preview_form.php?f={$form['form_id']}&amp;i={$intro_text}\" target=\"_blank\">preview</a>)</td>";
+                echo '</tr>';
+            } ?>
                 </table>
             </div>
             <?php
 
             //check that the system allows student Justification
             if (APP__ALLOW_TEXT_INPUT) {
-                //provide the academic the option
-                ?>
+                //provide the academic the option?>
                 <div style="float:right"><b>Advanced Options</b> <a href="#" onclick="open_close('advanced')"><img
                                 src="../../../images/icons/advanced_options.gif" alt="view / hide advanced options"></a>
                     <br/><br/></div>
@@ -140,14 +143,14 @@ function form()
                         <table class="form" cellpadding="2" cellspacing="2">
                             <tr>
                                 <td><input type="radio" name="allow_feedback" id="allow_feedback_yes"
-                                           value="1" <?php echo(($allow_feedback) ? 'checked="checked"' : ''); ?> />
+                                           value="1" <?php echo ($allow_feedback) ? 'checked="checked"' : ''; ?> />
                                 </td>
                                 <td valign="top"><label class="small" for="allow_feedback_yes">Yes, allow students to
                                         view feedback.</label></td>
                             </tr>
                             <tr>
                                 <td><input type="radio" name="allow_feedback" id="allow_feedback_no"
-                                           value="0" <?php echo((!$allow_feedback) ? 'checked="checked"' : ''); ?> />
+                                           value="0" <?php echo (!$allow_feedback) ? 'checked="checked"' : ''; ?> />
                                 </td>
                                 <td valign="top"><label class="small" for="allow_feedback_no">No, there is no feedback
                                         for this assessment.</label></td>
@@ -163,18 +166,18 @@ function form()
                             <tr>
                                 <td><label class="small" for="feedback_name">Title </label></td>
                                 <td><input type="text" name="feedback_name" id="feedback_name" maxlength="100" size="40"
-                                           value="<?php echo($this->wizard->get_field('feedback_name')); ?>"></td>
+                                           value="<?php echo $this->wizard->get_field('feedback_name'); ?>"></td>
                             </tr>
                             <tr>
                                 <td><input type="radio" name="allow_text_input" id="allow_text_input_yes"
-                                           value="1" <?php echo(($this->wizard->get_field('allow_student_input')) ? 'checked="checked"' : ''); ?>>
+                                           value="1" <?php echo ($this->wizard->get_field('allow_student_input')) ? 'checked="checked"' : ''; ?>>
                                 </td>
                                 <td><label class="small" for="allow_text_input_yes"><b>Yes</b>, allow students to
                                         comment.</label></td>
                             </tr>
                             <tr>
                                 <td><input type="radio" name="allow_text_input" id="allow_text_input_no"
-                                           value="0" <?php echo((!$this->wizard->get_field('allow_student_input')) ? 'checked="checked"' : ''); ?>>
+                                           value="0" <?php echo (!$this->wizard->get_field('allow_student_input')) ? 'checked="checked"' : ''; ?>>
                                 </td>
                                 <td><label class="small" for="allow_text_input_no"><b>No</b>, don't allow students to
                                         comment.</label></td>
@@ -185,10 +188,11 @@ function form()
                 <?php
             }
         }
+    }
 
-    }// /->form()
+    // /->form()
 
-    function process_form()
+    public function process_form()
     {
         $errors = null;
 
@@ -205,8 +209,9 @@ function process_form()
         }
 
         return $errors;
-    }// /->process_form()
+    }
 
+    // /->process_form()
 }// /class: WizardStep2
 
 ?>
diff --git a/src/tutors/assessments/create/class_wizardstep_3.php b/src/tutors/assessments/create/class_wizardstep_3.php
index 0cdf02c..36e285b 100644
--- a/src/tutors/assessments/create/class_wizardstep_3.php
+++ b/src/tutors/assessments/create/class_wizardstep_3.php
@@ -8,8 +8,6 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
-
 use WebPA\includes\classes\GroupHandler;
 use WebPA\includes\classes\SimpleObjectIterator;
 use WebPA\includes\classes\Wizard;
@@ -17,15 +15,15 @@
 
 class WizardStep3
 {
-    public $wizard = null;
+    public $wizard;
+
     public $step = 3;
 
     private $module;
+
     private $groupHandler;
 
-    /*
-    * CONSTRUCTOR
-    */
+    // CONSTRUCTOR
     public function __construct(Wizard $wizard)
     {
         $this->wizard = $wizard;
@@ -37,7 +35,7 @@ public function __construct(Wizard $wizard)
         $this->wizard->cancel_button = 'Cancel';
     }
 
-    function head()
+    public function head()
     {
         ?>
         <script language="JavaScript" type="text/javascript">
@@ -49,9 +47,11 @@ function body_onload () {
           //-->
         </script>
         <?php
-    }// /->head()
+    }
+
+    // /->head()
 
-    function form()
+    public function form()
     {
         $group_handler = new GroupHandler();
         $collections = $group_handler->get_module_collections($this->module['module_id']);
@@ -59,15 +59,13 @@ function form()
         $collection_id = $this->wizard->get_field('collection_id');
 
         if (!$collections) {
-            $this->button_next = '';
-            ?>
+            $this->wizard->next_button = ''; ?>
             <p>You haven't yet created any group collections.</p>
             <p>You need to <a href="../../groups/create/">create some groups</a> before you will be able to run any peer
                 assessments.</p>
             <?php
         } else {
-            $collection_iterator = new SimpleObjectIterator($collections, 'GroupCollection', $this->wizard->get_var('db'));
-            ?>
+            $collection_iterator = new SimpleObjectIterator($collections, 'GroupCollection', $this->wizard->get_var('db')); ?>
             <p>Please select the collection of groups you wish to use in this assessment from the list below.</p>
             <p>The collection you select will be copied into your new assessment. Subsequent changes to the collection
                 of groups <strong>will not</strong> affect your assessment.</p>
@@ -80,27 +78,28 @@ function form()
                         $collection_id = $collection->id;
                         unset($collection);
                     }
-                    for ($collection_iterator->reset(); $collection_iterator->is_valid(); $collection_iterator->next()) {
-                        $collection = $collection_iterator->current();
+            for ($collection_iterator->reset(); $collection_iterator->is_valid(); $collection_iterator->next()) {
+                $collection = $collection_iterator->current();
 
-                        $group_count = count($collection->get_groups_array());
+                $group_count = count($collection->get_groups_array());
 
-                        $checked = ($collection_id == $collection->id) ? 'checked="checked"' : '';
+                $checked = ($collection_id == $collection->id) ? 'checked="checked"' : '';
 
-                        echo('<tr>');
-                        echo("  <td><input type=\"radio\" name=\"collection_id\" id=\"collection_{$collection->id}\" value=\"{$collection->id}\" $checked /></td>");
-                        echo("  <td><label class=\"small\" for=\"collection_{$collection->id}\">{$collection->name}</label>");
-                        echo("  <div style=\"margin-left: 10px; font-size: 84%;\"><div>Number of Groups : $group_count</div></div></td>");
-                        echo('</tr>');
-                    }
-                    ?>
+                echo '<tr>';
+                echo "  <td><input type=\"radio\" name=\"collection_id\" id=\"collection_{$collection->id}\" value=\"{$collection->id}\" $checked /></td>";
+                echo "  <td><label class=\"small\" for=\"collection_{$collection->id}\">{$collection->name}</label>";
+                echo "  <div style=\"margin-left: 10px; font-size: 84%;\"><div>Number of Groups : $group_count</div></div></td>";
+                echo '</tr>';
+            } ?>
                 </table>
             </div>
             <?php
         }
-    }// /->form()
+    }
+
+    // /->form()
 
-    function process_form()
+    public function process_form()
     {
         $errors = null;
 
@@ -110,8 +109,5 @@ function process_form()
         }
 
         return $errors;
-    }// /->process_form()
-
-}// /class: WizardStep3
-
-?>
+    }
+}
diff --git a/src/tutors/assessments/create/class_wizardstep_4.php b/src/tutors/assessments/create/class_wizardstep_4.php
index 60b97c8..92350fe 100644
--- a/src/tutors/assessments/create/class_wizardstep_4.php
+++ b/src/tutors/assessments/create/class_wizardstep_4.php
@@ -8,29 +8,30 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
-
 use WebPA\includes\classes\Wizard;
 use WebPA\includes\functions\Common;
 
-class WizardStep4 {
+class WizardStep4
+{
+    public $wizard;
+
+    public $step = 4;
 
-  public $wizard;
-  public $step = 4;
+    // CONSTRUCTOR
+    public function __construct(Wizard $wizard)
+    {
+        $this->wizard = $wizard;
 
-  /*
-  * CONSTRUCTOR
-  */
-  function __construct(Wizard $wizard) {
-    $this->wizard = $wizard;
+        $this->wizard->back_button = '&lt; Back';
+        $this->wizard->next_button = 'Next &gt;';
+        $this->wizard->cancel_button = 'Cancel';
+    }
 
-    $this->wizard->back_button = '&lt; Back';
-    $this->wizard->next_button = 'Next &gt;';
-    $this->wizard->cancel_button = 'Cancel';
-  }// /WizardStep4()
+    // /WizardStep4()
 
-  function head() {
-    ?>
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -51,17 +52,19 @@ function open_close(id) {
 //-->
 </script>
 <?php
-  }// /->head()
+    }
 
-  function form() {
-    $assessment_type = $this->wizard->get_field('assessment_type',1);
-    ?>
+    // /->head()
+
+    public function form()
+    {
+        $assessment_type = $this->wizard->get_field('assessment_type', 1); ?>
     <h2>Assessment Type</h2>
     <div class="form_section">
       <table class="form" cellpadding="2" cellspacing="2">
       <tr>
         <td>
-          <input type="radio" name="assessment_type" value="1" id="both" <?php echo ((!$assessment_type)? 'checked="checked"' : '' );?>>
+          <input type="radio" name="assessment_type" value="1" id="both" <?php echo (!$assessment_type)? 'checked="checked"' : ''; ?>>
         </td>
         <td>
           <label class="small" for="both">Self and peer assessment</label>
@@ -75,7 +78,7 @@ function form() {
       <table class="form" cellpadding="2" cellspacing="2">
       <tr>
         <td>
-          <input type="radio" name="assessment_type" value="0" id="peer" <?php echo (($assessment_type)? 'checked="checked"' : '' );?>/>
+          <input type="radio" name="assessment_type" value="0" id="peer" <?php echo ($assessment_type)? 'checked="checked"' : ''; ?>/>
         </td>
         <td>
           <label class="small" for="peer">Peer assessment only</label>
@@ -86,17 +89,21 @@ function form() {
     </div>
 
 <?php
-  }// /->form()
+    }
+
+    // /->form()
 
-  function process_form() {
-    $errors = null;
+    public function process_form()
+    {
+        $errors = null;
 
-    $this->wizard->set_field('assessment_type',Common::fetch_POST('assessment_type'));
+        $this->wizard->set_field('assessment_type', Common::fetch_POST('assessment_type'));
 
 
-    return $errors;
-  }// /->process_form()
+        return $errors;
+    }
 
+    // /->process_form()
 }// /class: WizardStep4
 
 ?>
diff --git a/src/tutors/assessments/create/class_wizardstep_5.php b/src/tutors/assessments/create/class_wizardstep_5.php
index 4d18c0f..d4fec5e 100644
--- a/src/tutors/assessments/create/class_wizardstep_5.php
+++ b/src/tutors/assessments/create/class_wizardstep_5.php
@@ -8,30 +8,31 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
-
 use WebPA\includes\classes\Form;
 use WebPA\includes\classes\GroupHandler;
 use WebPA\includes\classes\Wizard;
 
-class WizardStep5 {
+class WizardStep5
+{
+    public $wizard;
+
+    public $step = 5;
 
-  public $wizard;
-  public $step = 5;
+    // CONSTRUCTOR
+    public function __construct(Wizard $wizard)
+    {
+        $this->wizard = $wizard;
 
-  /*
-  * CONSTRUCTOR
-  */
-  function __construct(Wizard $wizard) {
-    $this->wizard = $wizard;
+        $this->wizard->back_button = '&lt; Back';
+        $this->wizard->next_button = 'Finish';
+        $this->wizard->cancel_button = 'Cancel';
+    }
 
-    $this->wizard->back_button = '&lt; Back';
-    $this->wizard->next_button = 'Finish';
-    $this->wizard->cancel_button = 'Cancel';
-  }// /WizardStep4()
+    // /WizardStep4()
 
-  function head() {
-?>
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -41,11 +42,13 @@ function body_onload() {
 //-->
 </script>
 <?php
-  }// /->head()
+    }
+
+    // /->head()
 
-  function form() {
-    $now = time();
-    ?>
+    public function form()
+    {
+        $now = time(); ?>
     <p>Your assessment is now ready for creation.</p>
     <p>Please review the details below. When you're are satisfied, click <em>Finish</em> to create your peer assessment.</p>
 
@@ -54,19 +57,19 @@ function form() {
       <table class="form" cellpadding="2" cellspacing="2">
       <tr>
         <th width="100">Name:</th>
-        <td><?php echo($this->wizard->get_field('assessment_name'));?></td>
+        <td><?php echo $this->wizard->get_field('assessment_name'); ?></td>
       </tr>
       <tr>
         <th>Opens at:</th>
-        <td><?php echo(  date('G:i \o\n l, jS F Y',$this->wizard->get_field('open_date') )  );?></td>
+        <td><?php echo date('G:i \o\n l, jS F Y', $this->wizard->get_field('open_date')); ?></td>
       </tr>
       <tr>
         <th>Closes at:</th>
-        <td><?php echo(  date('G:i \o\n l, jS F Y',$this->wizard->get_field('close_date') )  );?></td>
+        <td><?php echo date('G:i \o\n l, jS F Y', $this->wizard->get_field('close_date')); ?></td>
       </tr>
 <?php
-    if ( ($this->wizard->get_field('open_date')<$now) && ($this->wizard->get_field('close_date')>$now) ) {
-?>
+    if (($this->wizard->get_field('open_date')<$now) && ($this->wizard->get_field('close_date')>$now)) {
+        ?>
           <tr>
             <td>&nbsp;</td>
             <td>
@@ -78,26 +81,25 @@ function form() {
 <?php
     }
 
-    if (!empty($this->wizard->get_field('introduction'))) {
-      echo('<tr><td colspan="2" style="font-weight: bold;">Includes an introduction</td></tr>');
-    }
+        if (!empty($this->wizard->get_field('introduction'))) {
+            echo '<tr><td colspan="2" style="font-weight: bold;">Includes an introduction</td></tr>';
+        }
 
-    if ($this->wizard->get_field('email')== '1') {
-      echo('<tr><td colspan="2" style="font-weight: bold;">All students for the assessment will be emailed when you finish.</td></tr>');
-    }else{
-      echo('<tr><td colspan="2" style="font-weight: bold;">All students for the assessment will <b>NOT</b> be emailed when you finish.</td></tr>');
-    }
-?>
+        if ($this->wizard->get_field('email')== '1') {
+            echo '<tr><td colspan="2" style="font-weight: bold;">All students for the assessment will be emailed when you finish.</td></tr>';
+        } else {
+            echo '<tr><td colspan="2" style="font-weight: bold;">All students for the assessment will <b>NOT</b> be emailed when you finish.</td></tr>';
+        } ?>
       </table>
     </div>
 
     <h2>Assessment Type</h2>
     <div class="form_section">
-      <?php if ($this->wizard->get_field('assessment_type')=='1'){
-        echo "Self and peer assessment";
-      }else{
-        echo "Peer assessment only";
-      } ?>
+      <?php if ($this->wizard->get_field('assessment_type')=='1') {
+            echo 'Self and peer assessment';
+        } else {
+            echo 'Peer assessment only';
+        } ?>
     </div>
 
     <h2>Assessment Form</h2>
@@ -105,87 +107,87 @@ function form() {
 <?php
     $DB = $this->wizard->get_var('db');
 
-    $form = new Form($DB);
+        $form = new Form($DB);
 
-    if (!$form->load($this->wizard->get_field('form_id'))) {
-      $form = null;
-      $this->wizard->next_button = null;
-?>
+        if (!$form->load($this->wizard->get_field('form_id'))) {
+            $form = null;
+            $this->wizard->next_button = null; ?>
           <div class="error_box"><p><strong>ERROR : </strong>unable to load the selected form</p></div>
 <?php
-    } else {
-      echo("<p><strong>Form : </strong>{$form->name}</p>");
-      $question_count = (int) $form->get_question_count();
-      if ($question_count==0) {
-        $this->wizard->next_button = null;
-?>
+        } else {
+            echo "<p><strong>Form : </strong>{$form->name}</p>";
+            $question_count = (int) $form->get_question_count();
+            if ($question_count==0) {
+                $this->wizard->next_button = null; ?>
             <div class="error_box"><p><strong>ERROR : </strong>this form contains no questions</p></div>
 <?php
-      } else {
-        echo('<div style="margin-left: 10px;">');
-        for($i=0; $i<$question_count; $i++) {
-          $question = $form->get_question($i);
-          ?>
-            <div style="padding: 0px 2px 2px 10px;">- <?php echo( $question['text']['_data']); ?> (<?php echo( $question['range']['_data'] );?>)</div>
-          <?php
-        }
-        echo('</div>');
-      }
-    }
-?>
+            } else {
+                ?>
+                <div style="margin-left: 10px;"></div>
+                <?php for ($i=0; $i<$question_count; $i++) { ?>
+                    <?php $question = $form->get_question($i); ?>
+                    <div style="padding: 0px 2px 2px 10px;">
+                        - <?= $question['text']['_data'] ?>
+                        <?= array_key_exists('range', $question) ? "({$question['range']['_data']})" : '' ?>
+                    </div>
+              <?php } ?>
+                </div>
+            <?php
+            }
+        } ?>
     </div>
 
     <h2>Groups</h2>
     <div class="form_section">
 <?php
     $group_handler = new GroupHandler();
-    $collection = $group_handler->get_collection($this->wizard->get_field('collection_id'));
+        $collection = $group_handler->get_collection($this->wizard->get_field('collection_id'));
 
-    if (!$collection) {
-      $this->wizard->next_button = null;
-?>
+        if (!$collection) {
+            $this->wizard->next_button = null; ?>
           <div class="error_box"><p><strong>ERROR : </strong>unable to load the selected collection of groups</p></div>
 <?php
-    } else {
-      echo("<p><strong>Collection : </strong>{$collection->name}</p>");
-      $groups = $collection->get_groups_array();
-      if (count((array) $groups)==0) {
-        $this->wizard->next_button = null;
-?>
+        } else {
+            echo "<p><strong>Collection : </strong>{$collection->name}</p>";
+            $groups = $collection->get_groups_array();
+            if (count((array) $groups)==0) {
+                $this->wizard->next_button = null; ?>
             <div class="error_box"><p><strong>ERROR : </strong>this collection does not contain any groups</p></div>
 <?php
-      } else {
-
-        echo('<div style="margin-left: 10px;">');
-
-        $num_groups = count($groups);
-        if ($num_groups<=5) {
-          foreach($groups as $group) {
-            echo("<div>- {$group['group_name']}</div>");
-          }
-        } else {
-          echo("<div>- {$groups[0]['group_name']}</div>");
-          echo("<div>- {$groups[1]['group_name']}</div>");
-          echo("<div>&nbsp; &nbsp;...</div>");
-          echo('<div>- '. $groups[$num_groups-2]['group_name'] .'</div>');
-          echo('<div>- '. $groups[$num_groups-1]['group_name'] .'</div>');
-        }
-
-        echo('</div>');
-      }
-    }
-?>
+            } else {
+                echo '<div style="margin-left: 10px;">';
+
+                $num_groups = count($groups);
+                if ($num_groups<=5) {
+                    foreach ($groups as $group) {
+                        echo "<div>- {$group['group_name']}</div>";
+                    }
+                } else {
+                    echo "<div>- {$groups[0]['group_name']}</div>";
+                    echo "<div>- {$groups[1]['group_name']}</div>";
+                    echo '<div>&nbsp; &nbsp;...</div>';
+                    echo '<div>- '. $groups[$num_groups-2]['group_name'] .'</div>';
+                    echo '<div>- '. $groups[$num_groups-1]['group_name'] .'</div>';
+                }
+
+                echo '</div>';
+            }
+        } ?>
     </div>
 
 <?php
-  }// /->form()
+    }
 
-  function process_form() {
-    $errors = null;
+    // /->form()
 
-    return $errors;
-  }// /->process_form()
+    public function process_form()
+    {
+        $errors = null;
+
+        return $errors;
+    }
 
+    // /->process_form()
 }// /class: WizardStep4
 
 ?>
diff --git a/src/tutors/assessments/create/class_wizardstep_6.php b/src/tutors/assessments/create/class_wizardstep_6.php
index df23c81..6bed912 100644
--- a/src/tutors/assessments/create/class_wizardstep_6.php
+++ b/src/tutors/assessments/create/class_wizardstep_6.php
@@ -8,8 +8,6 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
-
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\classes\Form;
 use WebPA\includes\classes\GroupHandler;
@@ -19,17 +17,16 @@
 
 class WizardStep6
 {
-
     use AssessmentNotificationTrait;
 
     // Public
-    public $wizard = null;
+    public $wizard;
+
     public $step = 6;
+
     private $module;
 
-    /*
-    * CONSTRUCTOR
-    */
+    // CONSTRUCTOR
     public function __construct(Wizard $wizard)
     {
         $this->wizard = $wizard;
@@ -41,7 +38,7 @@ public function __construct(Wizard $wizard)
         $this->wizard->cancel_button = null;
     }
 
-    function head()
+    public function head()
     {
         ?>
         <script language="JavaScript" type="text/javascript">
@@ -53,9 +50,11 @@ function body_onload () {
           //-->
         </script>
         <?php
-    }// /->head()
+    }
+
+    // /->head()
 
-    function form()
+    public function form()
     {
         $DB = $this->wizard->get_var('db');
 
@@ -100,14 +99,14 @@ function form()
         if ($send_email == '1') {
             $_user_id = Common::fetch_SESSION('_user_id', null);
             $subjectLn = 'Your Tutor has set a WebPA assessment';
-            $body = "Your tutor has set a WebPA assessment for your group. The details are as below;" .
+            $body = 'Your tutor has set a WebPA assessment for your group. The details are as below;' .
                 "\n Assessment Name:  " . $this->wizard->get_field('assessment_name') .
                 "\n Open from:  " . date('G:i \o\n l, jS F Y', $this->wizard->get_field('open_date')) .
                 "\n Closes on:  " . date('G:i \o\n l, jS F Y', $this->wizard->get_field('close_date')) .
                 "\n To complete your assessment please go to: " . APP__WWW .
                 "\n \n -------------------------------------------------------------------------------" .
                 "\n This is an automated email sent by the WebPA tool \n\n";
-            $returned = mail_assessment_notification($coll_id, $subjectLn, $body, $_user_id);
+            $returned = $this->mail_assessment_notification($coll_id, $subjectLn, $body, $_user_id);
 
             //deal will any errors that are returned.
 
@@ -120,17 +119,16 @@ function form()
         if (is_array($errors)) {
             $this->wizard->back_button = '&lt; Back';
             $this->wizard->cancel_button = 'Cancel';
-            echo('<p><strong>Unable to create your new assessment.</strong></p>');
-            echo('<p>To correct the problem, click <em>back</em> and amend the details entered.</p>');
+            echo '<p><strong>Unable to create your new assessment.</strong></p>';
+            echo '<p>To correct the problem, click <em>back</em> and amend the details entered.</p>';
         } else {// Else.. create the form!
             if ($assessment) {
-                $assessment_qs = "a={$assessment->id}";
-                ?>
+                $assessment_qs = "a={$assessment->id}"; ?>
                 <p><strong>Your new assessment has been created.</strong></p>
                 <p style="margin-top: 20px;">To view or amend the details of your new assessment, you can use the <a
-                            href="../edit/edit_assessment.php?<?php echo($assessment_qs); ?>">assessment editor</a>.</p>
+                            href="../edit/edit_assessment.php?<?php echo $assessment_qs; ?>">assessment editor</a>.</p>
                 <p style="margin-top: 20px;">To send an email alert to the students due to take this new assessment, use
-                    the <a href="../email/index.php?<?php echo($assessment_qs); ?>">email wizard</a>.</p>
+                    the <a href="../email/index.php?<?php echo $assessment_qs; ?>">email wizard</a>.</p>
                 <p style="margin-top: 20px;">Alternatively, you can return to <a href="../index.php">my assessments</a>,
                     or to the <a href="../../../">WebPA home page</a>.</p>
                 <?php
@@ -141,13 +139,15 @@ function form()
                 <?php
             }
         }
-    }// /->form()
+    }
+
+    // /->form()
 
-    function process_form()
+    public function process_form()
     {
-        $this->wizard->_fields = array(); // kill the wizard's stored fields
+        $this->wizard->_fields = []; // kill the wizard's stored fields
         return null;
-    }// /->process_form()
+    }
 
+    // /->process_form()
 }// /class: WizardStep6
-
diff --git a/src/tutors/assessments/create/index.php b/src/tutors/assessments/create/index.php
index 45926b5..fd97d85 100644
--- a/src/tutors/assessments/create/index.php
+++ b/src/tutors/assessments/create/index.php
@@ -8,32 +8,32 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\Wizard;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
 // Initialise wizard
 
 $wizard = new Wizard('create a new assessment wizard');
-$wizard->cancel_url = "../";
-
-$wizard->add_step(1,'class_wizardstep_1.php');
-$wizard->add_step(2,'class_wizardstep_2.php');
-$wizard->add_step(3,'class_wizardstep_3.php');
-$wizard->add_step(4,'class_wizardstep_4.php');
-$wizard->add_step(5,'class_wizardstep_5.php');
-$wizard->add_step(6,'class_wizardstep_6.php');
-
-$wizard->set_var('db',$DB);
-$wizard->set_var('config',$_config);
-$wizard->set_var('user',$_user);
+$wizard->cancel_url = '../';
+
+$wizard->add_step(1, 'class_wizardstep_1.php');
+$wizard->add_step(2, 'class_wizardstep_2.php');
+$wizard->add_step(3, 'class_wizardstep_3.php');
+$wizard->add_step(4, 'class_wizardstep_4.php');
+$wizard->add_step(5, 'class_wizardstep_5.php');
+$wizard->add_step(6, 'class_wizardstep_6.php');
+
+$wizard->set_var('db', $DB);
+$wizard->set_var('config', $_config);
+$wizard->set_var('user', $_user);
 $wizard->set_var('module', $_module);
 $wizard->set_var('moduleId', $_module_id);
 
@@ -50,9 +50,9 @@
 $UI->page_title = APP__NAME . ' Create a new assessment';
 $UI->menu_selected = 'my assessments';
 $UI->help_link = '?q=node/235';
-$UI->breadcrumbs = array  ('home'               => '../../' ,
-               'my assessments'         => '../' ,
-               'create a new assessment wizard' => null ,);
+$UI->breadcrumbs = ['home'               => '../../',
+               'my assessments'         => '../',
+               'create a new assessment wizard' => null, ];
 
 $UI->set_page_bar_button('List Assessments', '../../../../images/buttons/button_assessment_list.gif', '../');
 $UI->set_page_bar_button('Create Assessments', '../../../../images/buttons/button_assessment_create.gif', '../create/');
diff --git a/src/tutors/assessments/delete_marks.php b/src/tutors/assessments/delete_marks.php
index aab966a..2538b6b 100644
--- a/src/tutors/assessments/delete_marks.php
+++ b/src/tutors/assessments/delete_marks.php
@@ -12,22 +12,23 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../includes/inc_global.php");
+require_once '../../includes/inc_global.php';
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\classes\GroupHandler;
 use WebPA\includes\classes\ResultHandler;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
 
 $year = Common::fetch_GET('y');
-$tab = Common::fetch_GET('tab','open');
+$tab = Common::fetch_GET('tab', 'open');
 
 $assessment_id = Common::fetch_GET('a');
 
@@ -39,32 +40,47 @@
 
 //check the content of 'u'/ $user_id if a user ID is present then we delete this before proceeding
 if (!empty($user_id)) {
-  //we have posted the delete responses for the assessment to this form so now we need to delete the
-  //information before carrying on to output the form.
-
-  $DB->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "user_mark WHERE user_id = {$user_id} and assessment_id = '{$assessment_id}'");
-  $DB->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "user_justification WHERE user_id = {$user_id} and assessment_id = '{$assessment_id}'");
-  $DB->execute("DELETE FROM " . APP__DB_TABLE_PREFIX . "user_response WHERE user_id = {$user_id} and assessment_id = '{$assessment_id}'");
-
+    //we have posted the delete responses for the assessment to this form so now we need to delete the
+    //information before carrying on to output the form.
+    $dbConn = $DB->getConnection();
+
+    $dbConn->executeQuery(
+        'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user_mark WHERE user_id = ? AND assessment_id = ?',
+        [$user_id, $assessment_id],
+        [ParameterType::INTEGER, ParameterType::STRING]
+    );
+
+    $dbConn->executeQuery(
+        'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user_justification WHERE user_id = ? AND assessment_id = ?',
+        [$user_id, $assessment_id],
+        [ParameterType::INTEGER, ParameterType::STRING]
+    );
+
+    $dbConn->executeQuery(
+        'DELETE FROM ' . APP__DB_TABLE_PREFIX . 'user_response WHERE user_id = ? AND assessment_id = ?',
+        [$user_id, $assessment_id],
+        [ParameterType::INTEGER, ParameterType::STRING]
+    );
 }
 
 $assessment = new Assessment($DB);
+
 if ($assessment->load($assessment_id)) {
-  $assessment_qs = "a={$assessment->id}&tab={$tab}&y={$year}";
+    $assessment_qs = "a={$assessment->id}&tab={$tab}&y={$year}";
 
-  $group_handler = new GroupHandler();
-  $collection = $group_handler->get_collection($assessment->get_collection_id());
+    $group_handler = new GroupHandler();
+    $collection = $group_handler->get_collection($assessment->get_collection_id());
 
-  $groups_iterator = $collection->get_groups_iterator();
+    $groups_iterator = $collection->get_groups_iterator();
 
-  $result_handler = new ResultHandler($DB);
-  $result_handler->set_assessment($assessment);
+    $result_handler = new ResultHandler($DB);
+    $result_handler->set_assessment($assessment);
 
-  $responded_users = $result_handler->get_responded_users();
+    $responded_users = $result_handler->get_responded_users();
 
-  $members = $collection->get_members();
+    $members = $collection->get_members();
 } else {
-  $assessment = null;
+    $assessment = null;
 }
 
 // --------------------------------------------------------------------------------
@@ -73,9 +89,9 @@
 $UI->page_title = APP__NAME . ' ' . 'students who responded';
 $UI->menu_selected = 'my assessments';
 $UI->help_link = '?q=node/235';
-$UI->breadcrumbs = array  ('home'           => '/' ,
-               'my assessments'     => $list_url ,
-               'students who responded' => null ,);
+$UI->breadcrumbs = ['home'           => '/',
+               'my assessments'     => $list_url,
+               'students who responded' => null, ];
 
 $UI->set_page_bar_button('List Assessments', '../../../images/buttons/button_assessment_list.gif', '../');
 $UI->set_page_bar_button('Create Assessments', '../../../images/buttons/button_assessment_create.gif', '../create/');
@@ -100,7 +116,7 @@
 <div class="content_box">
 
   <div class="nav_button_bar">
-    <a href="<?php echo($list_url) ?>"><img src="../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a>
+    <a href="<?php echo $list_url ?>"><img src="../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a>
   </div>
 
   <p>The following list shows which students in each group have submitted their responses to the assessment.</p>
@@ -108,16 +124,16 @@
   <p>To delete the entries provided by a student click on the <img src="../../images/icons/cancel.png" width="16" height="16" alt="Delete submission" /> image (if not greyed out).</p>
 <?php
   if ($groups_iterator->size()>0) {
-    for($groups_iterator->reset(); $groups_iterator->is_valid(); $groups_iterator->next()) {
-      $group =& $groups_iterator->current();
+      for ($groups_iterator->reset(); $groups_iterator->is_valid(); $groups_iterator->next()) {
+          $group =& $groups_iterator->current();
 
-      $members = $CIS->get_user($group->get_member_ids());
-      echo("<h2>{$group->name}</h2>");
+          $members = $CIS->get_user($group->get_member_ids());
+          echo "<h2>{$group->name}</h2>";
 
-      if (!$members) {
-        echo('<p>This group has no members.</p>');
-      } else {
-        ?>
+          if (!$members) {
+              echo '<p>This group has no members.</p>';
+          } else {
+              ?>
         <table class="grid" cellspacing="1" cellpadding="2" style="width: 90%">
         <tr>
           <th>name</th>
@@ -125,27 +141,26 @@
           <th>delete submission</th>
         </tr>
         <?php
-        foreach($members as $i => $member) {
-          $flgResponse = false;
-          if (in_array($member['user_id'], (array)$responded_users)) {
-            $responded_img = '<img src="../../images/icons/tick.gif" width="16" height="16" alt="Responded" />';
-            $responded_class = 'class="responded"';
-            $allowDelete = "<a href=\"delete_marks.php?a={$assessment_id}&tab={$tab}&y={$year}&u={$member['user_id']}\" ><img src=\"../../images/icons/cancel.png\" width=\"16\" height=\"16\" alt=\"Delete submission\" /></a>";
-          } else {
-            $responded_img = '<img src="../../images/icons/cross.gif" width="16" height="16" alt="Not Responded"/>';
-            $responded_class = 'class="notresponded"';
-            $allowDelete = "<img src=\"../../images/icons/cancel_greyed.png\" width=\"16\" height=\"16\" alt=\"Delete submission\" />";
-          }
-          echo("<tr $responded_class><td>{$member['lastname']}, {$member['forename']}");
-          if (!empty($member['id_number'])) {
-            echo(" ({$member['id_number']})");
-          }
-          echo("</td><td align=\"center\">$responded_img</td><td>{$allowDelete}</td></tr>");
-
+        foreach ($members as $i => $member) {
+            $flgResponse = false;
+            if (in_array($member['user_id'], (array) $responded_users)) {
+                $responded_img = '<img src="../../images/icons/tick.gif" width="16" height="16" alt="Responded" />';
+                $responded_class = 'class="responded"';
+                $allowDelete = "<a href=\"delete_marks.php?a={$assessment_id}&tab={$tab}&y={$year}&u={$member['user_id']}\" ><img src=\"../../images/icons/cancel.png\" width=\"16\" height=\"16\" alt=\"Delete submission\" /></a>";
+            } else {
+                $responded_img = '<img src="../../images/icons/cross.gif" width="16" height="16" alt="Not Responded"/>';
+                $responded_class = 'class="notresponded"';
+                $allowDelete = '<img src="../../images/icons/cancel_greyed.png" width="16" height="16" alt="Delete submission" />';
+            }
+            echo "<tr $responded_class><td>{$member['lastname']}, {$member['forename']}";
+            if (!empty($member['id_number'])) {
+                echo " ({$member['id_number']})";
+            }
+            echo "</td><td align=\"center\">$responded_img</td><td>{$allowDelete}</td></tr>";
         }
-        echo('</table><br />');
-      }// /if
-    }// /for
+              echo '</table><br />';
+          }// /if
+      }// /for
   }
 ?>
 
diff --git a/src/tutors/assessments/edit/change_assessment_collection.php b/src/tutors/assessments/edit/change_assessment_collection.php
index ca1620d..d910939 100644
--- a/src/tutors/assessments/edit/change_assessment_collection.php
+++ b/src/tutors/assessments/edit/change_assessment_collection.php
@@ -8,16 +8,16 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\classes\GroupHandler;
 use WebPA\includes\classes\SimpleObjectIterator;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -38,12 +38,12 @@
 $assessment = new Assessment($DB);
 
 if ($assessment->load($assessment_id)) {
-  $assessment_qs = "a={$assessment->id}&tab={$tab}&y={$year}";
-  $assessment_url = "edit_assessment.php?{$assessment_qs}";
-  $collection =& $group_handler->get_collection($assessment->get_collection_id());
+    $assessment_qs = "a={$assessment->id}&tab={$tab}&y={$year}";
+    $assessment_url = "edit_assessment.php?{$assessment_qs}";
+    $collection = $group_handler->get_collection($assessment->get_collection_id());
 } else {
-  $assessment = null;
-  $assessment_url = "../";
+    $assessment = null;
+    $assessment_url = '../';
 }
 
 // --------------------------------------------------------------------------------
@@ -52,47 +52,49 @@
 $errors = null;
 
 if (($command) && ($assessment)) {
-  switch ($command) {
+    switch ($command) {
     case 'save':
       if ($assessment->is_locked()) {
-        $errors[] = 'This assessment has been marked, and therefore the assessment form being used cannot be changed.';
+          $errors[] = 'This assessment has been marked, and therefore the assessment form being used cannot be changed.';
       } else {
-        // Change the collection of groups to assess
-
-        if (!$new_collection_id) {
-          $errors[] = 'You must select a collection of associated groups to use.';
-        } else {
-          // If the new collection is the same as the old collection, do nothing
-          if ($new_collection_id!=$collection->id) {
-            if (!$collection) { $errors[] = 'There was an error when trying to remove the original collection of groups - please use the contact system to report the error!'; }
-
-            // clone the collection
-            $new_collection = $group_handler->clone_collection($new_collection_id);
-
-            if (!$new_collection) { $errors[] = 'There was an error when loading the new collection of groups - please use the contact system to report the error!'; }
-
-            if (!$errors) {
-              // Delete the old collection
-              $collection->delete();
-
-              // Connect the collection to the assessment
-              $new_collection->set_owner_info($assessment->id, APP__COLLECTION_ASSESSMENT);
-              $new_collection->save();
-              $assessment->set_collection_id($new_collection->id);
-            }
+          // Change the collection of groups to assess
+
+          if (!$new_collection_id) {
+              $errors[] = 'You must select a collection of associated groups to use.';
+          } else {
+              // If the new collection is the same as the old collection, do nothing
+              if ($new_collection_id!=$collection->id) {
+                  if (!$collection) {
+                      $errors[] = 'There was an error when trying to remove the original collection of groups - please use the contact system to report the error!';
+                  }
+
+                  // clone the collection
+                  $new_collection = $group_handler->clone_collection($new_collection_id);
+
+                  if (!$new_collection) {
+                      $errors[] = 'There was an error when loading the new collection of groups - please use the contact system to report the error!';
+                  }
+
+                  if (!$errors) {
+                      // Connect the collection to the assessment
+                      $new_collection->set_owner_info($assessment->id, APP__COLLECTION_ASSESSMENT);
+                      $new_collection->save();
+                      $assessment->set_collection_id($new_collection->id);
+                      $assessment->save();
+
+                      // Delete the old collection
+                      $collection->delete();
+                  }
+              }
           }
-        }
-
-        // If there were no errors, save the changes
-        if (!$errors) {
-          $assessment->save();
-          $collection =& $new_collection; // Not strictly needed, as this page will now redirects but for debugging it can come in handy
 
-          header("Location: $assessment_url");
-        }
+          // If there were no errors, reload the assessment
+          if (!$errors) {
+              header("Location: $assessment_url");
+          }
       }
       break;
-  }// /switch
+  }
 }
 
 // --------------------------------------------------------------------------------
@@ -104,10 +106,10 @@
 $UI->page_title = APP__NAME . ' ' . $page_title;
 $UI->menu_selected = 'my assessments';
 $UI->help_link = '?q=node/235';
-$UI->breadcrumbs = array  ('home'         => '/' ,
-               'my assessments'   => '/tutors/assessments/' ,
-               $manage_text     => $assessment_url ,
-               'change collection'  => null ,);
+$UI->breadcrumbs = ['home'         => '/',
+               'my assessments'   => '/tutors/assessments/',
+               $manage_text     => $assessment_url,
+               'change collection'  => null, ];
 
 $UI->set_page_bar_button('List Assessments', '../../../../images/buttons/button_assessment_list.gif', '../');
 $UI->set_page_bar_button('Create Assessments', '../../../../images/buttons/button_assessment_create.gif', '../create/');
@@ -151,48 +153,47 @@ function do_command(com) {
 
 <?php
 if (!$assessment) {
-?>
+    ?>
   <div class="nav_button_bar">
-    <a href="<?php echo($assessment_url) ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to the assessment</a>
+    <a href="<?php echo $assessment_url ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to the assessment</a>
   </div>
 
   <p>The assessment you selected could not be loaded for some reason - please go back and try again.</p>
 <?php
 } else {
-?>
+        ?>
   <div class="nav_button_bar">
     <table cellpadding="0" cellspacing="0" width="100%">
     <tr>
-      <td><a href="<?php echo($assessment_url); ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to the assessment</a></td>
+      <td><a href="<?php echo $assessment_url; ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to the assessment</a></td>
     </tr>
     </table>
   </div>
 
 <?php
   if ($assessment->is_locked()) {
-?>
+      ?>
     <div class="warning_box">
       <p><strong>Marks have been recorded for this assessment.</strong></p>
       <p>You can still edit the assessment's name, schedule information and introductory text, but you can no longer change which form, or collection of groups, is used in this assessment.</p>
     </div>
 <?php
   } else {
-?>
+      ?>
 
-    <form action="change_assessment_collection.php?<?php echo($assessment_qs); ?>" method="post" name="assessment_form">
+    <form action="change_assessment_collection.php?<?php echo $assessment_qs; ?>" method="post" name="assessment_form">
     <input type="hidden" name="command" value="none" />
 
     <h2>Current Collection</h2>
     <div class="form_section form_line">
 <?php
-    echo("<p><label>You are currently using collection: </label><em>{$collection->name}</em></p>");
+    echo "<p><label>You are currently using collection: </label><em>{$collection->name}</em></p>";
 
 //    $modules = (is_array($collection->get_modules())) ? implode(', ',$collection->get_modules()) : 'none' ;
-    $group_count = count( $collection->get_groups_array() );
+      $group_count = count($collection->get_groups_array());
 
 //    echo("  <div style=\"margin-left: 50px; font-size: 84%;\"><div>Associated Modules : $modules</div><div>Number of Groups : $group_count</div></div>");
-    echo("  <div style=\"margin-left: 50px; font-size: 84%;\"><div>Number of Groups : $group_count</div></div>");
-?>
+      echo "  <div style=\"margin-left: 50px; font-size: 84%;\"><div>Number of Groups : $group_count</div></div>"; ?>
     </div>
 
 
@@ -201,39 +202,36 @@ function do_command(com) {
 <?php
 
     $group_handler = new GroupHandler();
-    $collections = $group_handler->get_user_collections($_user->id, $_config['app_id']);
+      $collections = $group_handler->get_user_collections($_user->id);
 
-    if (!$collections) {
-?>
+      if (!$collections) {
+          ?>
         <p>You haven't yet created any group collections.</p>
         <p>You need to <a href="../../groups/create/">create some groups</a> before you will be able to run any peer assessments.</p>
 <?php
-    } else {
-      $collection_iterator = new SimpleObjectIterator($collections, 'GroupCollection', $DB);
-?>
+      } else {
+          $collection_iterator = new SimpleObjectIterator($collections, 'GroupCollection', $DB); ?>
         <p>Please select the collection of groups you wish to use in this assessment from from the list below.</p>
         <div class="form_section">
           <table class="form" cellpadding="0" cellspacing="0">
 <?php
       for ($collection_iterator->reset(); $collection_iterator->is_valid(); $collection_iterator->next()) {
-        $new_collection = $collection_iterator->current();
+          $new_collection = $collection_iterator->current();
 
-        $group_count = count($new_collection->get_groups_array());
+          $group_count = count($new_collection->get_groups_array());
 //        $modules = (is_array($new_collection->get_modules())) ? implode(', ',$new_collection->get_modules()) : 'none' ;
 
-        echo('<tr>');
-        echo("  <td><input type=\"radio\" name=\"collection_id\" id=\"collection_{$new_collection->id}\" value=\"{$new_collection->id}\" /></td>");
-        echo("  <td><label class=\"small\" for=\"collection_{$new_collection->id}\">{$new_collection->name}</label>");
+          echo '<tr>';
+          echo "  <td><input type=\"radio\" name=\"collection_id\" id=\"collection_{$new_collection->id}\" value=\"{$new_collection->id}\" /></td>";
+          echo "  <td><label class=\"small\" for=\"collection_{$new_collection->id}\">{$new_collection->name}</label>";
 //        echo("  <div style=\"margin-left: 10px; font-size: 84%;\"><div>Associated Modules : $modules</div><div>Number of Groups : $group_count</div></div></td>");
-        echo("  <div style=\"margin-left: 10px; font-size: 84%;\"><div>Number of Groups : $group_count</div></div></td>");
-        echo('</tr>');
-      }
-?>
+          echo "  <div style=\"margin-left: 10px; font-size: 84%;\"><div>Number of Groups : $group_count</div></div></td>";
+          echo '</tr>';
+      } ?>
           </table>
         </div>
 <?php
-    }
-?>
+      } ?>
       <div style="text-align: right">
         <input type="button" name="savebutton1" id="savebutton1" value="save changes" onclick="do_command('save');" />
       </div>
@@ -242,7 +240,7 @@ function do_command(com) {
     </form>
 <?php
   }
-}
+    }
 ?>
 </div>
 
diff --git a/src/tutors/assessments/edit/change_assessment_form.php b/src/tutors/assessments/edit/change_assessment_form.php
index d27fc3f..1a3e0e7 100644
--- a/src/tutors/assessments/edit/change_assessment_form.php
+++ b/src/tutors/assessments/edit/change_assessment_form.php
@@ -10,15 +10,16 @@
  *
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\classes\Form;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -36,15 +37,15 @@
 
 $assessment = new Assessment($DB);
 if ($assessment->load($assessment_id)) {
-  $assessment_qs = "a={$assessment->id}&tab={$tab}&y={$year}";
-  $assessment_url = "edit_assessment.php?{$assessment_qs}";
+    $assessment_qs = "a={$assessment->id}&tab={$tab}&y={$year}";
+    $assessment_url = "edit_assessment.php?{$assessment_qs}";
 
-  $form = new Form($DB);
-  $form_xml =& $assessment->get_form_xml();
-  $form->load_from_xml($form_xml);
+    $form = new Form($DB);
+    $form_xml =& $assessment->get_form_xml();
+    $form->load_from_xml($form_xml);
 } else {
-  $assessment = null;
-  $assessment_url = "../";
+    $assessment = null;
+    $assessment_url = '../';
 }
 
 // --------------------------------------------------------------------------------
@@ -53,24 +54,26 @@
 $errors = null;
 
 if (($command) && ($assessment)) {
-  switch ($command) {
+    switch ($command) {
     case 'save':
       if ($assessment->is_locked()) {
-        $errors[] = 'This assessment has been marked, and therefore the assessment form being used cannot be changed.';
+          $errors[] = 'This assessment has been marked, and therefore the assessment form being used cannot be changed.';
       } else {
-        if (!$form_id) {
-          $errors[] = 'You must select an assessment form to use.';
-        } else {
-          // Change of name
-          $new_form = new Form($DB);
-          $new_form->load($form_id);
-          $assessment->set_form_xml( $new_form->get_xml() );
-        }
-
-        // If there were no errors, save the changes
-        if (!$errors) { $assessment->save(); }
-
-        header("Location: $assessment_url");
+          if (!$form_id) {
+              $errors[] = 'You must select an assessment form to use.';
+          } else {
+              // Change of name
+              $new_form = new Form($DB);
+              $new_form->load($form_id);
+              $assessment->set_form_xml($new_form->get_xml());
+          }
+
+          // If there were no errors, save the changes
+          if (!$errors) {
+              $assessment->save();
+          }
+
+          header("Location: $assessment_url");
       }
       break;
   }// /switch
@@ -85,10 +88,10 @@
 $UI->page_title = APP__NAME . ' ' . $page_title;
 $UI->menu_selected = 'my assessments';
 $UI->help_link = '?q=node/235';
-$UI->breadcrumbs = array  ('home'       => '../../' ,
-               'my assessments' => '../' ,
-               $manage_text   => $assessment_url ,
-               "change form"    => null ,);
+$UI->breadcrumbs = ['home'       => '../../',
+               'my assessments' => '../',
+               $manage_text   => $assessment_url,
+               'change form'    => null, ];
 
 $UI->set_page_bar_button('List Assessments', '../../../../images/buttons/button_assessment_list.gif', '../');
 $UI->set_page_bar_button('Create Assessments', '../../../../images/buttons/button_assessment_create.gif', '../create/');
@@ -132,99 +135,101 @@ function do_command(com) {
 
 <?php
 if (!$assessment) {
-  ?>
+    ?>
   <div class="nav_button_bar">
-    <a href="<?php echo($assessment_url) ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to the assessment</a>
+    <a href="<?php echo $assessment_url ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to the assessment</a>
   </div>
 
   <p>The assessment you selected could not be loaded for some reason - please go back and try again.</p>
 <?php
 } else {
-?>
+        ?>
   <div class="nav_button_bar">
     <table cellpadding="0" cellspacing="0" width="100%">
     <tr>
-      <td><a href="<?php echo($assessment_url); ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to the assessment</a></td>
+      <td><a href="<?php echo $assessment_url; ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to the assessment</a></td>
     </tr>
     </table>
   </div>
 
 <?php
   if ($assessment->is_locked()) {
-?>
+      ?>
     <div class="warning_box">
       <p><strong>Marks have been recorded for this assessment.</strong></p>
       <p>You can still edit the assessment's name, schedule information and introductory text, but you can no longer change which form, or collection of groups, is used in this assessment.</p>
     </div>
     <?php
   } else {
-?>
+      ?>
 
-    <form action="change_assessment_form.php?<?php echo($assessment_qs); ?>" method="post" name="assessment_form">
+    <form action="change_assessment_form.php?<?php echo $assessment_qs; ?>" method="post" name="assessment_form">
     <input type="hidden" name="command" value="none" />
 
     <h2>Current Form</h2>
     <div class="form_section form_line">
 <?php
-    echo("<p><label>You are currently using form: </label><em>{$form->name}</em></p>");
+    echo "<p><label>You are currently using form: </label><em>{$form->name}</em></p>";
 
-    $question_count = (int) $form->get_question_count();
-    if ($question_count==0) {
-?>
+      $question_count = (int) $form->get_question_count();
+      if ($question_count==0) {
+          ?>
         <p>This form has no questions.</p>
 <?php
       } else {
-?>
+          ?>
         <p>Below are the questions that your students will use to mark each other.</p>
 
         <ul class="compact">
 <?php
-        for($i=0; $i<$question_count; $i++) {
-          $question = $form->get_question($i);
-?>
-          <li><div class="question"><?php echo( $question['text']['_data']); ?> <span class="question_range">(scoring range: <?php echo($question['range']['_data']); ?>)</span></div></li>
+        for ($i=0; $i<$question_count; $i++) {
+            $question = $form->get_question($i); ?>
+          <li><div class="question"><?php echo $question['text']['_data']; ?> <span class="question_range">(scoring range: <?php echo $question['range']['_data']; ?>)</span></div></li>
 <?php
         }
-        echo('</ul>');
-      }
-?>
+          echo '</ul>';
+      } ?>
     </div>
 
     <h2>Available Forms</h2>
     <div class="form_section">
 <?php
-      $sql = 'SELECT f.* FROM ' . APP__DB_TABLE_PREFIX .
-         'form f INNER JOIN ' . APP__DB_TABLE_PREFIX .
-         'form_module fm ON f.form_id = fm.form_id INNER JOIN ' . APP__DB_TABLE_PREFIX .
-         "user_module um ON fm.module_id = um.module_id WHERE um.user_id = {$_user->id} ORDER BY f.form_name ASC";
-      $forms = $DB->fetch($sql);
+      $formsQuery =
+          'SELECT f.* ' .
+          'FROM ' . APP__DB_TABLE_PREFIX . 'form f ' .
+          'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'form_module fm ' .
+          'ON f.form_id = fm.form_id ' .
+          'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'user_module um ' .
+          'ON fm.module_id = um.module_id ' .
+          'WHERE um.user_id = ? ' .
+          'ORDER BY f.form_name ASC';
+
+      $forms = $DB->getConnection()->fetchAllAssociative($formsQuery, [$_user->id], [ParameterType::INTEGER]);
 
       if (!$forms) {
-?>
+          ?>
         <p>You haven't yet created any assessment forms.</p>
 <?php
       } else {
-?>
+          ?>
         <p>Please select a form from the list below. You can see how the form appears to students by clicking <em>preview</em>.</p>
 
         <div class="form_section">
           <table cellpadding="2" cellspacing="2">
 <?php
         foreach ($forms as $i => $new_form) {
-          $checked = ($form->id==$new_form['form_id']) ? 'checked="checked"' : '' ;
-          $intro_text = base64_encode($assessment->introduction);
-          echo('<tr>');
-          echo("<td><input type=\"radio\" name=\"form_id\" id=\"form_{$new_form['form_id']}\" value=\"{$new_form['form_id']}\" $checked /></td>");
-          echo("<td><label class=\"small\" for=\"form_{$new_form['form_id']}\">{$new_form['form_name']}</label></td>");
-          echo("<td>&nbsp; &nbsp; (<a style=\"font-weight: normal; font-size: 84%;\" href=\"/tutors/forms/edit/preview_form.php?f={$new_form['form_id']}&amp;i={$intro_text}\" target=\"_blank\">preview</a>)</td>");
-          echo('</tr>');
-        }
-?>
+            $checked = ($form->id==$new_form['form_id']) ? 'checked="checked"' : '' ;
+            $intro_text = base64_encode($assessment->introduction);
+            echo '<tr>';
+            echo "<td><input type=\"radio\" name=\"form_id\" id=\"form_{$new_form['form_id']}\" value=\"{$new_form['form_id']}\" $checked /></td>";
+            echo "<td><label class=\"small\" for=\"form_{$new_form['form_id']}\">{$new_form['form_name']}</label></td>";
+            echo "<td>&nbsp; &nbsp; (<a style=\"font-weight: normal; font-size: 84%;\" href=\"/tutors/forms/edit/preview_form.php?f={$new_form['form_id']}&amp;i={$intro_text}\" target=\"_blank\">preview</a>)</td>";
+            echo '</tr>';
+        } ?>
           </table>
         </div>
 <?php
-    }
-?>
+      } ?>
 
       <div style="text-align: right">
         <input type="button" name="savebutton1" id="savebutton1" value="save changes" onclick="do_command('save');" />
@@ -234,7 +239,7 @@ function do_command(com) {
     </form>
 <?php
   }
-}
+    }
 ?>
 </div>
 
diff --git a/src/tutors/assessments/edit/edit_assessment.php b/src/tutors/assessments/edit/edit_assessment.php
index 2ce42df..055aeb0 100644
--- a/src/tutors/assessments/edit/edit_assessment.php
+++ b/src/tutors/assessments/edit/edit_assessment.php
@@ -70,7 +70,7 @@
             }
 
             // Create an open date time object
-            list($time_h, $time_m) = explode(':', Common::fetch_POST('open_date_time'));
+            [$time_h, $time_m] = explode(':', Common::fetch_POST('open_date_time'));
 
             $openDate = DateTimeImmutable::createFromFormat('U', mktime(
                 $time_h,
@@ -82,7 +82,7 @@
             ));
 
             // Create a close date time object
-            list($time_h, $time_m) = explode(':', Common::fetch_POST('close_date_time'));
+            [$time_h, $time_m] = explode(':', Common::fetch_POST('close_date_time'));
 
             $closeDate = DateTimeImmutable::createFromFormat('U', mktime(
                 $time_h,
@@ -114,7 +114,7 @@
                 $bcc_list[] = $_user->email;
 
                 if (is_array($bcc_list)) {
-                  // Send the email
+                    // Send the email
                     $email = new Email();
                     $email->set_bcc($bcc_list);
                     $email->set_from($_user->email);
@@ -161,17 +161,14 @@
 }
 
 // --------------------------------------------------------------------------------
-/*
-* Render a set of dropdown boxes for datetime selection
-*/
-function render_datetime_boxes($fieldName = 'datetime', $selectedDatetime)
-{
-    echo('<table cellpadding="0" cellspacing="0"><tr>');
-
-  // Draw day box
-    echo("<td><select name=\"{$fieldName}_day\">");
+// Render a set of dropdown boxes for datetime selection
+$renderDatetimeBoxes = function ($fieldName, $selectedDatetime) {
+    echo '<table cellpadding="0" cellspacing="0"><tr>';
+
+    // Draw day box
+    echo "<td><select name=\"{$fieldName}_day\">";
     FormFunctions::render_options_range(1, 31, 1, date('j', $selectedDatetime));
-    echo('</select></td>');
+    echo '</select></td>';
 
     $formMonths = [
         1 => 'January',
@@ -188,36 +185,36 @@ function render_datetime_boxes($fieldName = 'datetime', $selectedDatetime)
         'December',
     ];
 
-  // Draw month box
-    echo("<td><select name=\"{$fieldName}_month\">");
+    // Draw month box
+    echo "<td><select name=\"{$fieldName}_month\">";
     FormFunctions::render_options($formMonths, date('n', $selectedDatetime));
-    echo('</select></td>');
+    echo '</select></td>';
 
-  // Draw year box
-    echo("<td><select name=\"{$fieldName}_year\">");
+    // Draw year box
+    echo "<td><select name=\"{$fieldName}_year\">";
     $year = (date('Y') < date('Y', $selectedDatetime)) ? date('Y') : date('Y', $selectedDatetime) ;
     FormFunctions::render_options_range($year, date('Y') + 1, 1, date('Y', $selectedDatetime));
-    echo('</select></td>');
+    echo '</select></td>';
 
-    echo('<th>at</th>');
+    echo '<th>at</th>';
 
-  // Draw time box
+    // Draw time box
     $time = date('H:i', $selectedDatetime);
     $time_parts = explode(':', $time);
     $time_h = (int) $time_parts[0];
     $time_m = (int) $time_parts[1];
 
-    echo("<td><select name=\"{$fieldName}_time\">");
+    echo "<td><select name=\"{$fieldName}_time\">";
     for ($i = 0; $i <= 23; $i++) {
         for ($j = 0; $j <= 45; $j += 15) {
-            $selected = ( ($i == $time_h) && ($j == $time_m) ) ? 'selected="selected"' : '' ;
+            $selected = (($i == $time_h) && ($j == $time_m)) ? 'selected="selected"' : '' ;
             printf('<option value="%1$02d:%2$02d" '. $selected .'> %1$02d:%2$02d </option>', $i, $j);
         }
     }
-    echo('</select></td>');
+    echo '</select></td>';
 
-    echo('</tr></table>');
-}
+    echo '</tr></table>';
+};
 
 // --------------------------------------------------------------------------------
 // Begin Page
@@ -226,9 +223,9 @@ function render_datetime_boxes($fieldName = 'datetime', $selectedDatetime)
 
 $UI->page_title = APP__NAME . ' ' . $page_title;
 $UI->menu_selected = 'my assessments';
-$UI->breadcrumbs = array  ('home'       => '/' ,
-               'my assessments' => '/tutors/assessments/' ,
-               $page_title    => null ,);
+$UI->breadcrumbs = ['home'       => '/',
+               'my assessments' => '/tutors/assessments/',
+               $page_title    => null, ];
 
 $UI->set_page_bar_button('List Assessments', '../../../../images/buttons/button_assessment_list.gif', '../');
 $UI->set_page_bar_button('Create Assessments', '../../../../images/buttons/button_assessment_create.gif', '../create/');
@@ -259,7 +256,7 @@ function do_command(com) {
             break;
       case 'preview' :
             var popupwin;
-            popupwin = window.open('../../tutors/forms/preview_form.php?f=<?php echo($form->id); ?>','preview');
+            popupwin = window.open('../../tutors/forms/preview_form.php?f=<?php echo $form->id; ?>','preview');
             popupwin.focus();
             break;
       default :
@@ -294,7 +291,7 @@ function do_command(com) {
 if (!$assessment) {
     ?>
     <div class="nav_button_bar">
-        <a href="<?php echo($list_url) ?>">
+        <a href="<?php echo $list_url ?>">
             <img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list
         </a>
     </div>
@@ -302,16 +299,16 @@ function do_command(com) {
     <p>The assessment you selected could not be loaded for some reason - please go back and try again.</p>
     <?php
 } else {
-    ?>
+        ?>
 
-  <form action="edit_assessment.php?<?php echo($assessment_qs); ?>" method="post" name="assessment_form">
+  <form action="edit_assessment.php?<?php echo $assessment_qs; ?>" method="post" name="assessment_form">
   <input type="hidden" name="command" value="none" />
 
   <div class="nav_button_bar">
     <table cellpadding="0" cellspacing="0" width="100%">
     <tr>
       <td>
-          <a href="<?php echo($list_url); ?>">
+          <a href="<?php echo $list_url; ?>">
               <img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessment list
           </a>
       </td>
@@ -324,8 +321,7 @@ function do_command(com) {
           <input class="danger_button" type="button" name="" value="delete assessment" onclick="do_command('delete');">
       </td>
         <?php
-    }
-    ?>
+    } ?>
     </tr>
     </table>
   </div>
@@ -339,8 +335,7 @@ function do_command(com) {
       <p>Some parts of the assessment are now locked for editing.</p>
     </div>
         <?php
-    }
-    ?>
+    } ?>
 
   <h2>Assessment Details</h2>
   <div class="form_section form_line">
@@ -364,11 +359,11 @@ function do_command(com) {
       <table class="form" cellpadding="2" cellspacing="2">
       <tr>
         <th><label>Opening date</label></th>
-        <td><?php render_datetime_boxes('open_date', $assessment->open_date); ?></td>
+        <td><?php $renderDatetimeBoxes('open_date', $assessment->open_date); ?></td>
       </tr>
       <tr>
         <th><label>Closing date</label></th>
-        <td><?php render_datetime_boxes('close_date', $assessment->close_date); ?></td>
+        <td><?php $renderDatetimeBoxes('close_date', $assessment->close_date); ?></td>
       </tr>
       </table>
     </div>
@@ -381,7 +376,7 @@ function do_command(com) {
             <label for="introduction">Introduction</label>
         </th>
         <td width="100%">
-            <textarea name="introduction" id="introduction" rows="5" cols="40" style="width: 90%;"><?php echo($assessment->introduction); ?></textarea>
+            <textarea name="introduction" id="introduction" rows="5" cols="40" style="width: 90%;"><?php echo $assessment->introduction; ?></textarea>
         </td>
       </tr>
       </table>
@@ -397,8 +392,7 @@ function do_command(com) {
 
     <?php
     if (APP__REMINDER_OPENING) {
-        $email_opening = $assessment->email_opening;
-        ?>
+        $email_opening = $assessment->email_opening; ?>
       <p><label>Email a reminder to all students 48 hours before the assessment is opened</label></p>
 
       <div class="form_section">
@@ -416,9 +410,8 @@ function do_command(com) {
         <?php
     }
 
-    if (APP__REMINDER_CLOSING) {
-        $email_closing = $assessment->email_closing;
-        ?>
+        if (APP__REMINDER_CLOSING) {
+            $email_closing = $assessment->email_closing; ?>
       <p><label>Email all students 48 hours before the assessment closes</label></p>
 
       <div class="form_section">
@@ -434,57 +427,57 @@ function do_command(com) {
         </table>
       </div>
         <?php
-    }
-    ?>
+        } ?>
   </div>
 
   <h2>Assessment Form</h2>
   <div class="form_section form_line">
     <?php
-    echo("<p><label>You are using a copy of form: </label><em>{$form->name}</em></p>");
+    echo "<p><label>You are using a copy of form: </label><em>{$form->name}</em></p>";
 
-    $question_count = (int) $form->get_question_count();
-    if ($question_count==0) {
-        ?>
+        $question_count = (int) $form->get_question_count();
+        if ($question_count==0) {
+            ?>
       <p>This form has no questions.</p>
         <?php
-    } else {
-        ?>
+        } else {
+            ?>
       <p>Below are the questions that your students will use to mark each other.</p>
 
       <ul>
         <?php
         for ($i=0; $i<$question_count; $i++) {
-            $question = $form->get_question($i);
-            ?>
+            $question = $form->get_question($i); ?>
       <li>
           <div class="question">
-              <?php echo( $question['text']['_data']); ?> <span class="question_range">(scoring range: <?php echo($question['range']['_data']); ?>)</span>
+              <?php echo $question['text']['_data']; ?>
+              <?php if (isset($question['range'])) { ?>
+              <span class="question_range">(scoring range: <?php echo $question['range']['_data']; ?>)</span>
+              <?php } ?>
           </div>
       </li>
             <?php
         }
-        echo('</ul>');
-    }
+            echo '</ul>';
+        }
 
-  // If not locked, allow change of form
-    if ($assessment->is_locked()) {
-        ?>
+        // If not locked, allow change of form
+        if ($assessment->is_locked()) {
+            ?>
     <div class="info_box">
       <p>Student marks have been recorded, so you can no longer change forms.</p>
     </div>
         <?php
-    } else {
-        ?>
+        } else {
+            ?>
       <p>
           You cannot directly change any aspect of this form or its criteria. If you need to change it, you must
-          <a href="change_assessment_form.php?<?php echo($assessment_qs); ?>">
+          <a href="change_assessment_form.php?<?php echo $assessment_qs; ?>">
               select a different assessment form to use
           </a>.
       </p>
         <?php
-    }
-    ?>
+        } ?>
     </div>
     <h2>Feedback / Justification</h2>
     <div class="form_section form_line">
@@ -514,7 +507,7 @@ function do_command(com) {
           <td valign="top"><label class="small" for="allow_assessment_feedback_yes">Yes, allow students to give feedback / justification.</label></td>
         </tr>
         <tr>
-          <td><input type="radio" name="allow_assessment_feedback" id="allow_assessment_feedback_no" value="0" <?php echo( (!$assessment->allow_assessment_feedback) ? 'checked="checked"' : '' ); ?> /></td>
+          <td><input type="radio" name="allow_assessment_feedback" id="allow_assessment_feedback_no" value="0" <?php echo (!$assessment->allow_assessment_feedback) ? 'checked="checked"' : ''; ?> /></td>
           <td valign="top"><label class="small" for="allow_assessment_feedback_no">No, don't allow feedback / justification.</label></td>
         </tr>
         </table>
@@ -526,18 +519,18 @@ function do_command(com) {
   <div class="form_section form_line">
 
     <?php
-    echo("<p><label>You are using a copy of collection: </label><em>{$collection->name}</em></p>");
+    echo "<p><label>You are using a copy of collection: </label><em>{$collection->name}</em></p>";
 
-    $groups = $collection->get_groups_iterator();
+        $groups = $collection->get_groups_iterator();
 
-    $num_module_students = $CIS->get_module_students_count($_module_id);
+        $num_module_students = $CIS->get_module_students_count($_module_id);
 
-    if ($groups->size()==0) {
-        ?>
+        if ($groups->size()==0) {
+            ?>
       <p>This collection does not contain any groups</p>
         <?php
-    } else {
-        ?>
+        } else {
+            ?>
       <table class="grid" cellpadding="2" cellspacing="1">
       <tr>
         <th>Group Name</th>
@@ -546,42 +539,41 @@ function do_command(com) {
       </tr>
         <?php
         $collection_total_members = 0;
-        for ($groups->reset(); $groups->is_valid(); $groups->next()) {
-            $group =& $groups->current();
-            $num_responses = $result_handler->get_responses_count($group->id);
-            $num_responses = $num_responses ?: '-';
-
-            $num_members = $group->get_members_count();
-            $collection_total_members += $num_members;
-
-            echo('<tr>');
-            echo("<td>{$group->name}</td>");
-            echo('<td>'. $num_members .'</td>');
-            echo("<td>$num_responses</td>");
-            echo('</tr>');
-        }
-        echo('</table>');
+            for ($groups->reset(); $groups->is_valid(); $groups->next()) {
+                $group =& $groups->current();
+                $num_responses = $result_handler->get_responses_count($group->id);
+                $num_responses = $num_responses ?: '-';
+
+                $num_members = $group->get_members_count();
+                $collection_total_members += $num_members;
+
+                echo '<tr>';
+                echo "<td>{$group->name}</td>";
+                echo '<td>'. $num_members .'</td>';
+                echo "<td>$num_responses</td>";
+                echo '</tr>';
+            }
+            echo '</table>';
 
-        if ($collection_total_members<$num_module_students) {
-            $diff = $num_module_students - $collection_total_members;
-            $diff_units = ($diff==1) ? 'person remains' : 'people remain';
-            echo("<div class=\"warning_box\"><p><strong>Warning</strong></p><p>Not all of the people within this collection have been allocated a group.</p><p>$diff $diff_units unallocated.</p></div>");
+            if ($collection_total_members<$num_module_students) {
+                $diff = $num_module_students - $collection_total_members;
+                $diff_units = ($diff==1) ? 'person remains' : 'people remain';
+                echo "<div class=\"warning_box\"><p><strong>Warning</strong></p><p>Not all of the people within this collection have been allocated a group.</p><p>$diff $diff_units unallocated.</p></div>";
+            }
         }
-    }
 
-  // If not locked, allow change of collection
-    if ($assessment->is_locked()) {
-        ?>
+        // If not locked, allow change of collection
+        if ($assessment->is_locked()) {
+            ?>
       <div class="info_box">
         <p>Student marks have been recorded, so you can no longer change collections.</p>
       </div>
         <?php
-    } else {
-        ?>
-      <p>You cannot directly change the composition of any of these groups. If you need to change them, you must <a href="change_assessment_collection.php?<?php echo($assessment_qs); ?>">select a different collection of groups to use</a>.</p>
+        } else {
+            ?>
+      <p>You cannot directly change the composition of any of these groups. If you need to change them, you must <a href="change_assessment_collection.php?<?php echo $assessment_qs; ?>">select a different collection of groups to use</a>.</p>
         <?php
-    }
-    ?>
+        } ?>
 
   </div>
    <h2>Assessment Type</h2>
@@ -595,8 +587,7 @@ function do_command(com) {
     } else {
         $peer_checked = 'checked=\"checked\"';
         $self_checked = '';
-    }
-    ?>
+    } ?>
     <table class="form" cellpadding="2" cellspacing="2">
     <tr>
       <td>
@@ -627,11 +618,10 @@ function do_command(com) {
     <p>Student marks have been recorded, so you can no longer change then assessment type.</p>
   </div>
         <?php
-    }
-    ?>
+    } ?>
   </form>
     <?php
-}
+    }
 ?>
 </div>
 
diff --git a/src/tutors/assessments/email/AssessmentNotificationTrait.php b/src/tutors/assessments/email/AssessmentNotificationTrait.php
index 5a30113..98f6214 100644
--- a/src/tutors/assessments/email/AssessmentNotificationTrait.php
+++ b/src/tutors/assessments/email/AssessmentNotificationTrait.php
@@ -13,8 +13,6 @@
 
 namespace WebPA\tutors\assessments\email;
 
-require_once("../../../includes/inc_global.php");
-
 use WebPA\includes\classes\Email;
 use WebPA\includes\classes\EngCIS;
 use WebPA\includes\classes\GroupHandler;
@@ -23,7 +21,7 @@
 
 trait AssessmentNotificationTrait
 {
-    /***************************************************************
+    /*
      * Function mail_assessment_notification
      *
      * Sends an email to the complete collection when called
@@ -35,7 +33,8 @@ trait AssessmentNotificationTrait
      * @param string $body_content Body content of the email to be sent
      * @return mixed Either a true if successful or an error message is failed
      */
-    function mail_assessment_notification ($collectionId, $subjectLn, $body_content, $_user_id){
+    public function mail_assessment_notification($collectionId, $subjectLn, $body_content, $_user_id)
+    {
         //get the collection to whom the email is to be sent
         $group_handler = new GroupHandler();
         $collection = $group_handler->clone_collection($collectionId);
@@ -49,7 +48,7 @@ function mail_assessment_notification ($collectionId, $subjectLn, $body_content,
         $bcc_list = null;
 
         $sourceId = Common::fetch_SESSION('_source_id', '');
-        $moduleId = Common::fetch_SESSION('_module_id', NULL);
+        $moduleId = Common::fetch_SESSION('_module_id', null);
 
         $CISa = new EngCIS($sourceId, $moduleId);
 
@@ -60,7 +59,6 @@ function mail_assessment_notification ($collectionId, $subjectLn, $body_content,
             //get the current userID
             $this_user = $CISa->get_user($_user_id);
             $bcc_list[] = $this_user['email'];
-
         } else {
             $errors[] = 'Unable to build email list - no students to email.';
             return $errors;
@@ -83,5 +81,3 @@ function mail_assessment_notification ($collectionId, $subjectLn, $body_content,
         return true;
     }
 }
-
-
diff --git a/src/tutors/assessments/email/ClosingReminder.php b/src/tutors/assessments/email/ClosingReminder.php
index b72a809..671c4d6 100644
--- a/src/tutors/assessments/email/ClosingReminder.php
+++ b/src/tutors/assessments/email/ClosingReminder.php
@@ -10,28 +10,38 @@
 
 namespace WebPA\tutors\assessments\email;
 
-//gather all include files needed.
-require_once "../../../includes/inc_global.php";
+use WebPA\includes\classes\DAO;
 
 class ClosingReminder
 {
     use AssessmentNotificationTrait;
 
+    private DAO $dao;
+
+    public function __construct(DAO $dao)
+    {
+        $this->dao = $dao;
+    }
+
     public function send()
     {
+        $allDueQuery =
+            'SELECT * ' .
+            'FROM ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
+            'WHERE a.close_date = DATE_ADD(CURDATE(), INTERVAL 2 DAY)';
+
         //get a list of the assessment that will be run in two days from now
-        $allDue = $DB->fetch("SELECT * FROM " . APP__DB_TABLE_PREFIX . "assessment a
-           WHERE a.close_date = DATE_ADD(CURDATE(), INTERVAL 2 DAY)");
+        $allDue = $this->dao->getConnection()->fetchAllAssociative($allDueQuery);
 
-        if (!empty($allDue)){
+        if (!empty($allDue)) {
             //cycle round and for each collection send the emails
             $assessments = count($allDue);
 
-            foreach($allDue as $assessment){
+            foreach ($allDue as $assessment) {
 
                 //specify the details of the email to be sent
                 $subjectLn = 'Reminder: WebPA Assessment closing';
-                $body = " This is a reminder that the assessment your tutor set is due to close. The details are as below;" .
+                $body = ' This is a reminder that the assessment your tutor set is due to close. The details are as below;' .
                     "\n Assessment Name:  " . $assessment['assessment_name'] .
                     "\n Open from:  " . $assessment['open_date'] .
                     "\n Closes on:  " . $assessment['close_date'] .
@@ -39,15 +49,9 @@ public function send()
                     "\n \n -------------------------------------------------------------------------------" .
                     "\n This is an automated email sent by the WebPA tool \n\n";
 
-                mail_assessment_notification ($assessment['collection_id'], $subjectLn, $body, $assessment['owner_id']);
-
+                $this->mail_assessment_notification($assessment['collection_id'], $subjectLn, $body, $assessment['owner_id']);
             }
             unset($assessment);
         }
     }
 }
-
-// This file was previously procedural. This is why we instantiate and call the function
-$closingReminder = new ClosingReminder();
-
-$closingReminder->send();
diff --git a/src/tutors/assessments/email/TriggerReminder.php b/src/tutors/assessments/email/TriggerReminder.php
index 834709a..a2a3059 100644
--- a/src/tutors/assessments/email/TriggerReminder.php
+++ b/src/tutors/assessments/email/TriggerReminder.php
@@ -10,27 +10,35 @@
 
 namespace WebPA\tutors\assessments\email;
 
-require_once("../../../includes/inc_global.php");
+use WebPA\includes\classes\DAO;
 
 class TriggerReminder
 {
     use AssessmentNotificationTrait;
 
+    private DAO $dao;
+
+    public function __construct(DAO $dao)
+    {
+        $this->dao = $dao;
+    }
+
     public function send()
     {
+        $allDueQuery =
+            'SELECT * ' .
+            'FROM ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
+            'WHERE a.open_date = DATE_ADD(CURDATE(), INTERVAL 2 DAY) ' .
+            'AND a.email_opening = 1';
+
         //get a list of the assessment that will be run in two days from now
-        $allDue = $DB->fetch("SELECT * FROM " . APP__DB_TABLE_PREFIX . "assessment a
-             WHERE a.open_date = DATE_ADD(CURDATE(), INTERVAL 2 DAY) AND a.email_opening = 1");
+        $allDue = $this->dao->getConnection()->fetchAllAssociative($allDueQuery);
 
         if (!empty($allDue)) {
-            //cycle round and for each collection send the emails
-            $assessments = count($allDue);
-
             foreach ($allDue as $assessment) {
-
                 //specify the details of the email to be sent
                 $subjectLn = 'Reminder: WebPA Assessment opening';
-                $body = " This is a reminder that the assessment your tutor set is due to open. The details are as below;" .
+                $body = ' This is a reminder that the assessment your tutor set is due to open. The details are as below;' .
                     "\n Assessment Name:  " . $assessment['assessment_name'] .
                     "\n Open from:  " . $assessment['open_date'] .
                     "\n Closes on:  " . $assessment['close_date'] .
@@ -38,14 +46,9 @@ public function send()
                     "\n \n -------------------------------------------------------------------------------" .
                     "\n This is an automated email sent by the WebPA tool \n\n";
 
-                mail_assessment_notification($assessment['collection_id'], $subjectLn, $body, $assessment['owner_id']);
-
+                $this->mail_assessment_notification($assessment['collection_id'], $subjectLn, $body, $assessment['owner_id']);
             }
             unset($assessment);
         }
     }
 }
-
-$triggerReminder = new TriggerReminder();
-
-$triggerReminder->send();
diff --git a/src/tutors/assessments/email/class_wizardstep_1.php b/src/tutors/assessments/email/class_wizardstep_1.php
index 43ec63a..ba02cbd 100644
--- a/src/tutors/assessments/email/class_wizardstep_1.php
+++ b/src/tutors/assessments/email/class_wizardstep_1.php
@@ -11,25 +11,28 @@
 use WebPA\includes\functions\Common;
 use WebPA\includes\functions\Form;
 
-class WizardStep1 {
+class WizardStep1
+{
+    // Public
+    public $wizard;
 
-  // Public
-  public $wizard = null;
-  public $step = 1;
+    public $step = 1;
 
-  /*
-  * CONSTRUCTOR
-  */
-  function __construct(&$wizard) {
-    $this->wizard =& $wizard;
+    // CONSTRUCTOR
+    public function __construct(&$wizard)
+    {
+        $this->wizard =& $wizard;
 
-    $this->wizard->back_button = null;
-    $this->wizard->next_button = 'Next &gt;';
-    $this->wizard->cancel_button = 'Cancel';
-  }// /WizardStep1()
+        $this->wizard->back_button = null;
+        $this->wizard->next_button = 'Next &gt;';
+        $this->wizard->cancel_button = 'Cancel';
+    }
 
-  function head() {
-    ?>
+    // /WizardStep1()
+
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -40,34 +43,41 @@ function body_onload() {
 //-->
 </script>
 <?php
-  }// /->head()
+    }
 
-  function form() {
-    $send_to = array  ('all'    => 'everyone taking this assessment' ,
-               'groups' => 'selected groups taking this assessment' ,
-               'have'   => 'students who HAVE responded' ,
-               'havenot'  => 'students who HAVE NOT responded' ,);
-?>
+    // /->head()
+
+    public function form()
+    {
+        $send_to = ['all'    => 'everyone taking this assessment',
+               'groups' => 'selected groups taking this assessment',
+               'have'   => 'students who HAVE responded',
+               'havenot'  => 'students who HAVE NOT responded', ]; ?>
     <p>To begin, you need to select exactly which students should receive your email.</p>
 
     <h2>Send Email To</h2>
     <div class="form_section">
 <?php
-      Form::render_radio_boxes($send_to, 'send_to', $this->wizard->get_field('send_to'));
-?>
+      Form::render_radio_boxes($send_to, 'send_to', $this->wizard->get_field('send_to')); ?>
     </div>
 <?php
-  }// /->form()
+    }
+
+    // /->form()
 
-  function process_form() {
-    $errors = null;
+    public function process_form()
+    {
+        $errors = null;
 
-    $this->wizard->set_field('send_to',Common::fetch_POST('send_to'));
-    if (empty($this->wizard->get_field('send_to'))) { $errors[] = 'You must select who to send this email to.'; }
+        $this->wizard->set_field('send_to', Common::fetch_POST('send_to'));
+        if (empty($this->wizard->get_field('send_to'))) {
+            $errors[] = 'You must select who to send this email to.';
+        }
 
-    return $errors;
-  }// /->process_form()
+        return $errors;
+    }
 
+    // /->process_form()
 }// /class: WizardStep1
 
 ?>
diff --git a/src/tutors/assessments/email/class_wizardstep_2.php b/src/tutors/assessments/email/class_wizardstep_2.php
index 54231ae..1bdb55f 100644
--- a/src/tutors/assessments/email/class_wizardstep_2.php
+++ b/src/tutors/assessments/email/class_wizardstep_2.php
@@ -13,25 +13,28 @@
 use WebPA\includes\functions\Common;
 use WebPA\includes\functions\Form;
 
-class WizardStep2 {
+class WizardStep2
+{
+    // Public
+    public $wizard;
 
-  // Public
-  public $wizard = null;
-  public $step = 2;
+    public $step = 2;
 
-  /*
-  * CONSTRUCTOR
-  */
-  function __construct(&$wizard) {
-    $this->wizard =& $wizard;
+    // CONSTRUCTOR
+    public function __construct(&$wizard)
+    {
+        $this->wizard =& $wizard;
 
-    $this->wizard->back_button = '&lt; Back';
-    $this->wizard->next_button = 'Next &gt;';
-    $this->wizard->cancel_button = 'Cancel';
-  }// /WizardStep2()
+        $this->wizard->back_button = '&lt; Back';
+        $this->wizard->next_button = 'Next &gt;';
+        $this->wizard->cancel_button = 'Cancel';
+    }
 
-  function head() {
-?>
+    // /WizardStep2()
+
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -42,63 +45,63 @@ function body_onload() {
 //-->
 </script>
 <?php
-  }// /->head()
+    }
+
+    // /->head()
 
-  function form() {
-    $send_to_desc = array ('all'    => 'everyone taking this assessment' ,
-                 'groups' => 'selected groups taking this assessment' ,
-                 'have'   => 'all the students who HAVE responded' ,
-                 'havenot'  => 'any students who HAVE NOT responded' ,
-                );
+    public function form()
+    {
+        $send_to_desc = ['all'    => 'everyone taking this assessment',
+                 'groups' => 'selected groups taking this assessment',
+                 'have'   => 'all the students who HAVE responded',
+                 'havenot'  => 'any students who HAVE NOT responded',
+                ];
 
-    $send_email_to = $this->wizard->get_field('send_to');
+        $send_email_to = $this->wizard->get_field('send_to');
 
-    $assessment = $this->wizard->get_var('assessment');
+        $assessment = $this->wizard->get_var('assessment');
 
-    $group_handler = new GroupHandler();
-    $collection = $group_handler->get_collection($assessment->get_collection_id());
+        $group_handler = new GroupHandler();
+        $collection = $group_handler->get_collection($assessment->get_collection_id());
 
-    $collection_member_count = $collection->get_member_count();
-    $num_targets = 0;
+        $collection_member_count = $collection->get_member_count();
+        $num_targets = 0;
 
-    if (array_key_exists($send_email_to, $send_to_desc)) {
-?>
-      <p>You have opted to send this email to <em><?php echo($send_to_desc["$send_email_to"]); ?></em>.</p>
+        if (array_key_exists($send_email_to, $send_to_desc)) {
+            ?>
+      <p>You have opted to send this email to <em><?php echo $send_to_desc["$send_email_to"]; ?></em>.</p>
 <?php
       if ($send_email_to=='groups') {
-        $email_groups = explode('|',$this->wizard->get_field('email_groups'));
-        $num_targets = $collection_member_count;
-?>
+          $email_groups = explode('|', $this->wizard->get_field('email_groups'));
+          $num_targets = $collection_member_count; ?>
         <h2>Select Groups To Email</h2>
         <div class="form_section">
           <p>Tick all the groups you wish to include in this email. The number of students in each group is shown in brackets after the group name.</p>
 <?php
         $groups_cbox_array = null;
 
-        $groups = $collection->get_groups_array();
-        if ($groups) {
-          $group_member_counts = (array) $collection->get_member_count_by_group();
-
-          foreach($groups as $i => $group) {
-            if (array_key_exists($group['group_id'], $group_member_counts)) {
-              $num_group_members = $group_member_counts["{$group['group_id']}"];
-              $groups_cbox_array["{$group['group_id']}"] = "{$group['group_name']} <span style=\"font-size: 0.8em; font-weight: normal\">($num_group_members)</span>";
-            } else {
-              $num_group_members = 0;
-            }
+          $groups = $collection->get_groups_array();
+          if ($groups) {
+              $group_member_counts = (array) $collection->get_member_count_by_group();
+
+              foreach ($groups as $i => $group) {
+                  if (array_key_exists($group['group_id'], $group_member_counts)) {
+                      $num_group_members = $group_member_counts["{$group['group_id']}"];
+                      $groups_cbox_array["{$group['group_id']}"] = "{$group['group_name']} <span style=\"font-size: 0.8em; font-weight: normal\">($num_group_members)</span>";
+                  } else {
+                      $num_group_members = 0;
+                  }
+              }
           }
-        }
 
-        Form::render_checkbox_grid($groups_cbox_array, 'email_group', (array) $email_groups, false, 2);
-?>
+          Form::render_checkbox_grid($groups_cbox_array, 'email_group', (array) $email_groups, false, 2); ?>
         </div>
 <?php
       } else {
-
-        switch ($send_email_to) {
+          switch ($send_email_to) {
           case 'all':
             $num_targets = $collection_member_count;
-            echo("<p>This email will be sent to all $collection_member_count students.</p>");
+            echo "<p>This email will be sent to all $collection_member_count students.</p>";
             break;
 
           // --------------------
@@ -109,7 +112,7 @@ function form() {
             $result_handler->set_assessment($assessment);
             $num_responses = $result_handler->get_responses_count_for_assessment();
             $num_targets = $num_responses;
-            echo("<p>This email will be sent to the $num_responses students who have taken this assessment.</p>");
+            echo "<p>This email will be sent to the $num_responses students who have taken this assessment.</p>";
 
             break;
 
@@ -122,13 +125,13 @@ function form() {
             $num_responses = $result_handler->get_responses_count_for_assessment();
             $num_no_responses = $collection_member_count - $num_responses;
             $num_targets = $num_no_responses;
-            echo("<p>This email will be sent to the $num_no_responses students who have not yet taken this assessment.</p>");
+            echo "<p>This email will be sent to the $num_no_responses students who have not yet taken this assessment.</p>";
             break;
         }
       }
 
-      if (!$num_targets) {
-        $this->wizard->next_button = null;  // default NEXT to off
+            if (!$num_targets) {
+                $this->wizard->next_button = null;  // default NEXT to off
 ?>
         <div class="error_box">
           <p><strong>There are no students matching your criteria.</strong></p>
@@ -136,74 +139,78 @@ function form() {
           <p>Please go back and choose a different set of students to contact.</p>
         </div>
 <?php
-      } else {
-?>
+            } else {
+                ?>
         <h2>Email Details</h2>
         <div class="form_section">
           <table class="form" cellpadding="2" cellspacing="2">
           <tr>
             <th><label for="email_subject">Subject</label></th>
-            <td><input name="email_subject" id="email_subject" maxlength="100" size="64" value="<?php echo($this->wizard->get_field('email_subject')); ?>" /></td>
+            <td><input name="email_subject" id="email_subject" maxlength="100" size="64" value="<?php echo $this->wizard->get_field('email_subject'); ?>" /></td>
           </tr>
           <tr>
             <th style="vertical-align: top"><label for="email_text">Text</label></th>
-            <td><textarea name="email_text" id="email_text" cols="60" rows="8"><?php echo($this->wizard->get_field('email_text')); ?></textarea></td>
+            <td><textarea name="email_text" id="email_text" cols="60" rows="8"><?php echo $this->wizard->get_field('email_text'); ?></textarea></td>
           </tr>
           </table>
         </div>
 <?php
-      }
+            }
+        }
     }
-  }// /->form()
 
-  function process_form() {
-    $errors = null;
+    // /->form()
 
-    $send_email_to = $this->wizard->get_field('send_to');
+    public function process_form()
+    {
+        $errors = null;
 
-    if ($send_email_to=='groups') {
-      $num_students = 0;
-      $email_groups = null;
+        $send_email_to = $this->wizard->get_field('send_to');
 
-      // Find which groups were selected
-      if ((array_key_exists('email_group',$_POST)) && (is_array($_POST['email_group']))) {
-        // Find how many students those groups contain
-        $assessment = $this->wizard->get_var('assessment');
+        if ($send_email_to=='groups') {
+            $num_students = 0;
+            $email_groups = null;
 
-        $group_handler = new GroupHandler();
-        $collection = $group_handler->get_collection($assessment->get_collection_id());
+            // Find which groups were selected
+            if ((array_key_exists('email_group', $_POST)) && (is_array($_POST['email_group']))) {
+                // Find how many students those groups contain
+                $assessment = $this->wizard->get_var('assessment');
 
-        $group_member_counts = $collection->get_member_count_by_group();
+                $group_handler = new GroupHandler();
+                $collection = $group_handler->get_collection($assessment->get_collection_id());
 
-        // Check that the groups actually contain students
-        foreach($_POST['email_group'] as $i => $group_id) {
-          if (array_key_exists($group_id,$group_member_counts)) {
-            $num_students += $group_member_counts[$group_id];
-          }
-        } // /for
+                $group_member_counts = $collection->get_member_count_by_group();
 
-        $email_groups = implode('|',array_values($_POST['email_group']));
-        $this->wizard->set_field('email_groups',Common::fetch_POST('email_groups'));
-      }
-      $this->wizard->set_field('email_groups', $email_groups);
-      if ( ($num_students===0) ) {
-        $errors[] = 'The group(s) you have selected contain no students. There must be at least one recepient for this email.';
-      }
-    }
+                // Check that the groups actually contain students
+                foreach ($_POST['email_group'] as $i => $group_id) {
+                    if (array_key_exists($group_id, $group_member_counts)) {
+                        $num_students += $group_member_counts[$group_id];
+                    }
+                } // /for
 
-    $this->wizard->set_field('email_subject', Common::fetch_POST('email_subject'));
-    if (empty($this->wizard->get_field('email_subject'))) {
-      $errors[] = 'You must enter a subject for this email.';
-    }
+                $email_groups = implode('|', array_values($_POST['email_group']));
+                $this->wizard->set_field('email_groups', Common::fetch_POST('email_groups'));
+            }
+            $this->wizard->set_field('email_groups', $email_groups);
+            if (($num_students===0)) {
+                $errors[] = 'The group(s) you have selected contain no students. There must be at least one recepient for this email.';
+            }
+        }
 
-    $this->wizard->set_field('email_text', Common::fetch_POST('email_text'));
-    if (empty($this->wizard->get_field('email_text'))) {
-      $errors[] = 'You must enter the text of this email.';
-    }
+        $this->wizard->set_field('email_subject', Common::fetch_POST('email_subject'));
+        if (empty($this->wizard->get_field('email_subject'))) {
+            $errors[] = 'You must enter a subject for this email.';
+        }
+
+        $this->wizard->set_field('email_text', Common::fetch_POST('email_text'));
+        if (empty($this->wizard->get_field('email_text'))) {
+            $errors[] = 'You must enter the text of this email.';
+        }
 
-    return $errors;
-  }// /->process_form()
+        return $errors;
+    }
 
+    // /->process_form()
 }// /class: WizardStep2
 
 ?>
diff --git a/src/tutors/assessments/email/class_wizardstep_3.php b/src/tutors/assessments/email/class_wizardstep_3.php
index fe97a01..f2990a3 100644
--- a/src/tutors/assessments/email/class_wizardstep_3.php
+++ b/src/tutors/assessments/email/class_wizardstep_3.php
@@ -11,25 +11,28 @@
 use WebPA\includes\classes\GroupHandler;
 use WebPA\includes\classes\ResultHandler;
 
-class WizardStep3 {
+class WizardStep3
+{
+    // Public
+    public $wizard;
 
-  // Public
-  public $wizard = null;
-  public $step = 3;
+    public $step = 3;
 
-  /*
-  * CONSTRUCTOR
-  */
-  function __construct(&$wizard) {
-    $this->wizard =& $wizard;
+    // CONSTRUCTOR
+    public function __construct(&$wizard)
+    {
+        $this->wizard =& $wizard;
 
-    $this->wizard->back_button = '&lt; Back';
-    $this->wizard->next_button = 'Send Email';
-    $this->wizard->cancel_button = 'Cancel';
-  }// /WizardStep3()
+        $this->wizard->back_button = '&lt; Back';
+        $this->wizard->next_button = 'Send Email';
+        $this->wizard->cancel_button = 'Cancel';
+    }
+
+    // /WizardStep3()
 
-  function head() {
-    ?>
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -40,40 +43,41 @@ function body_onload() {
 //-->
 </script>
 <?php
-  }// /->head()
+    }
 
-  function form() {
-    $send_to_desc = array ('all'    => 'everyone taking this assessment' ,
-                 'groups' => 'selected groups taking this assessment' ,
-                 'have'   => 'all the students who HAVE responded' ,
-                 'havenot'  => 'any students who HAVE NOT responded' ,);
+    // /->head()
 
-    $send_email_to = $this->wizard->get_field('send_to');
+    public function form()
+    {
+        $send_to_desc = ['all'    => 'everyone taking this assessment',
+                 'groups' => 'selected groups taking this assessment',
+                 'have'   => 'all the students who HAVE responded',
+                 'havenot'  => 'any students who HAVE NOT responded', ];
 
-    $assessment = $this->wizard->get_var('assessment');
+        $send_email_to = $this->wizard->get_field('send_to');
 
-    $group_handler = new GroupHandler();
-    $collection = $group_handler->get_collection($assessment->get_collection_id());
+        $assessment = $this->wizard->get_var('assessment');
 
-    $collection_member_count = $collection->get_member_count();
-    $num_targets = 0;
+        $group_handler = new GroupHandler();
+        $collection = $group_handler->get_collection($assessment->get_collection_id());
 
-?>
+        $collection_member_count = $collection->get_member_count();
+        $num_targets = 0; ?>
     <p>Please confirm the following settings are correct before proceeding.</p>
     <p>If you wish to amend any details, click <em>Back</em>. When you are ready to create your groups, click <em>Send Email</em>.</p>
 
     <h2>Recipients</h2>
     <div class="form_section">
-      <p>You have opted to send this email to <em><?php echo($send_to_desc["$send_email_to"]); ?></em>.</p>
+      <p>You have opted to send this email to <em><?php echo $send_to_desc["$send_email_to"]; ?></em>.</p>
 <?php
     switch ($send_email_to) {
       case 'all':
         $num_targets = $collection_member_count;
-        echo("<p>This email will be sent to all $collection_member_count students.</p>");
+        echo "<p>This email will be sent to all $collection_member_count students.</p>";
         break;
       // --------------------
       case 'groups':
-        $email_groups = explode('|',$this->wizard->get_field('email_groups'));
+        $email_groups = explode('|', $this->wizard->get_field('email_groups'));
         $groups = $collection->get_groups_array();
         $group_member_counts = $collection->get_member_count_by_group();
         $num_targets = 0;
@@ -81,12 +85,12 @@ function form() {
             <p>The groups you selected were:</p>
             <ul>
 <?php
-        foreach($groups as $i => $group) {
-          if (in_array($group['group_id'],$email_groups)) {
-            $num_group_members = (array_key_exists($group['group_id'],$group_member_counts)) ? $group_member_counts["{$group['group_id']}"] : 0 ;
-            $num_targets += $num_group_members;
-            echo("<li>{$group['group_name']} <span style=\"font-size: 0.8em; font-weight: normal\">($num_group_members)</span></li>");
-          }
+        foreach ($groups as $i => $group) {
+            if (in_array($group['group_id'], $email_groups)) {
+                $num_group_members = (array_key_exists($group['group_id'], $group_member_counts)) ? $group_member_counts["{$group['group_id']}"] : 0 ;
+                $num_targets += $num_group_members;
+                echo "<li>{$group['group_name']} <span style=\"font-size: 0.8em; font-weight: normal\">($num_group_members)</span></li>";
+            }
         }
 ?>
               </ul>
@@ -100,7 +104,7 @@ function form() {
         $result_handler->set_assessment($assessment);
         $num_responses = $result_handler->get_responses_count_for_assessment();
         $num_targets = $num_responses;
-        echo("<p>This email will be sent to the $num_responses students who have taken this assessment.</p>");
+        echo "<p>This email will be sent to the $num_responses students who have taken this assessment.</p>";
         break;
       // --------------------
 
@@ -112,15 +116,14 @@ function form() {
         $num_responses = $result_handler->get_responses_count_for_assessment();
         $num_no_responses = $collection_member_count - $num_responses;
         $num_targets = $num_no_responses;
-        echo("<p>This email will be sent to the $num_no_responses students who have not yet taken this assessment.</p>");
+        echo "<p>This email will be sent to the $num_no_responses students who have not yet taken this assessment.</p>";
         break;
-    }
-?>
+    } ?>
     </div>
 
 <?php
     if (!$num_targets) {
-      $this->wizard->next_button = null;  // default NEXT to off
+        $this->wizard->next_button = null;  // default NEXT to off
 ?>
       <div class="error_box">
         <p><strong>There are no students matching your criteria.</strong></p>
@@ -128,26 +131,30 @@ function form() {
       </div>
 <?php
     } else {
-?>
+        ?>
       <h2>Email Preview</h2>
       <div class="form_section">
         <div style="padding: 4px; background-color: #eee; border: 1px solid #999;">
-          Subject:  <?php echo($this->wizard->get_field('email_subject')); ?><br /><br />
-          <?php echo(nl2br($this->wizard->get_field('email_text'))); ?>
+          Subject:  <?php echo $this->wizard->get_field('email_subject'); ?><br /><br />
+          <?php echo nl2br($this->wizard->get_field('email_text')); ?>
         </div>
       </div>
 <?php
     }
-  }// /->form()
+    }
 
-  function process_form() {
-    $errors = null;
+    // /->form()
 
-    // Send Email
+    public function process_form()
+    {
+        $errors = null;
 
-    return $errors;
-  }// /->process_form()
+        // Send Email
+
+        return $errors;
+    }
 
+    // /->process_form()
 }// /class: WizardStep3
 
 ?>
diff --git a/src/tutors/assessments/email/class_wizardstep_4.php b/src/tutors/assessments/email/class_wizardstep_4.php
index 1436dbe..9817f71 100644
--- a/src/tutors/assessments/email/class_wizardstep_4.php
+++ b/src/tutors/assessments/email/class_wizardstep_4.php
@@ -13,27 +13,30 @@
 use WebPA\includes\classes\ResultHandler;
 use WebPA\includes\functions\ArrayFunctions;
 
-class WizardStep4 {
+class WizardStep4
+{
+    // Public
+    public $wizard;
 
-  // Public
-  public $wizard = null;
-  public $step = 4;
+    public $step = 4;
 
-  /*
-  * CONSTRUCTOR
-  */
-  function __construct(&$wizard) {
-    $this->wizard =& $wizard;
+    // CONSTRUCTOR
+    public function __construct(&$wizard)
+    {
+        $this->wizard =& $wizard;
 
-    $this->wizard->back_button = null;
-    $this->wizard->next_button = null;
-    $this->wizard->cancel_button = null;
+        $this->wizard->back_button = null;
+        $this->wizard->next_button = null;
+        $this->wizard->cancel_button = null;
 
-    ob_start();
-  }// /WizardStep4()
+        ob_start();
+    }
+
+    // /WizardStep4()
 
-  function head() {
-?>
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -43,36 +46,41 @@ function body_onload() {
 //-->
 </script>
 <?php
-  }// /->head()
+    }
 
-  function form() {
-    $user = $this->wizard->get_var('user');
-    $CIS = $this->wizard->get_var('cis');
+    // /->head()
 
-    $send_email_to = $this->wizard->get_field('send_to');
+    public function form()
+    {
+        $user = $this->wizard->get_var('user');
+        $CIS = $this->wizard->get_var('cis');
 
-    $assessment = $this->wizard->get_var('assessment');
+        $send_email_to = $this->wizard->get_field('send_to');
 
-    $group_handler = new GroupHandler();
-    $collection = $group_handler->get_collection($assessment->get_collection_id());
+        $assessment = $this->wizard->get_var('assessment');
 
-    $errors = null;
+        $group_handler = new GroupHandler();
+        $collection = $group_handler->get_collection($assessment->get_collection_id());
 
-    // get lists of users to email
-    $users_to_email = null;
+        $errors = null;
 
-    switch ($send_email_to) {
+        // get lists of users to email
+        $users_to_email = null;
+
+        switch ($send_email_to) {
       case 'all':
             $member_arr = $collection->get_members();
             $users_to_email = array_keys($member_arr);
             break;
       // --------------------
       case 'groups':
-            $email_groups = explode('|',$this->wizard->get_field('email_groups'));
+            $email_groups = explode('|', $this->wizard->get_field('email_groups'));
             $member_arr = $collection->get_member_rows();
 
-            foreach($member_arr as $i => $member) {
-              if (in_array($member['group_id'],$email_groups)) {  $users_to_email[] = $member['user_id']; }
+            foreach ($member_arr as $i => $member) {
+                if (in_array($member['group_id'], $email_groups)) {
+                    $users_to_email[] = $member['user_id'];
+                }
             }
             break;
       // --------------------
@@ -98,45 +106,48 @@ function form() {
             break;
     }
 
-    // create bcc list of recipients
-    $bcc_list = null;
-
-    if (is_array($users_to_email)) {
-      $users_arr = $CIS->get_user($users_to_email);
-      $bcc_list = ArrayFunctions::array_extract_column($users_arr, 'email');
-      $bcc_list[] = $user->email;
-    } else {
-      $errors[] = 'Unable to build email list - no students to email.';
-    }
-
-    if (is_array($bcc_list)) {
-      // Send the email
-      $email = new Email();
-      $email->set_bcc($bcc_list);
-      $email->set_from($user->email);
-      $email->set_subject($this->wizard->get_field('email_subject'));
-      $email->set_body($this->wizard->get_field('email_text'));
-      $email->send();
-    } else {
-      $errors[] = 'No list of students to email.';
-    }
-
-    // If errors, show them
-    if (is_array($errors)) {
-      $this->wizard->back_button = '&lt; Back';
-      $this->wizard->cancel_button = 'Cancel';
-      echo('<p><strong>Unable to send email.</strong></p>');
-      echo('<p>To try correcting the problem, click <em>back</em> and amend the details entered.</p>');
-    } else {
-?>
+        // create bcc list of recipients
+        $bcc_list = null;
+
+        if (is_array($users_to_email)) {
+            $users_arr = $CIS->get_user($users_to_email);
+            $bcc_list = ArrayFunctions::array_extract_column($users_arr, 'email');
+            $bcc_list[] = $user->email;
+        } else {
+            $errors[] = 'Unable to build email list - no students to email.';
+        }
+
+        if (is_array($bcc_list)) {
+            // Send the email
+            $email = new Email();
+            $email->set_bcc($bcc_list);
+            $email->set_from($user->email);
+            $email->set_subject($this->wizard->get_field('email_subject'));
+            $email->set_body($this->wizard->get_field('email_text'));
+            $email->send();
+        } else {
+            $errors[] = 'No list of students to email.';
+        }
+
+        // If errors, show them
+        if (is_array($errors)) {
+            $this->wizard->back_button = '&lt; Back';
+            $this->wizard->cancel_button = 'Cancel';
+            echo '<p><strong>Unable to send email.</strong></p>';
+            echo '<p>To try correcting the problem, click <em>back</em> and amend the details entered.</p>';
+        } else {
+            ?>
       <p><strong>Your email has been sent.</strong></p>
-      <p style="margin-top: 20px;">You can now return to <a href="<?php echo($this->wizard->get_field('list_url')); ?>">your assessment list</a>, or to the <a href="/">WebPA home page</a>.</p>
+      <p style="margin-top: 20px;">You can now return to <a href="<?php echo $this->wizard->get_field('list_url'); ?>">your assessment list</a>, or to the <a href="/">WebPA home page</a>.</p>
 <?php
+        }
     }
-  }// /->form()
 
-  function process_form() {
-    $this->wizard->_fields = array(); // kill the wizard's stored fields
-    return null;
-  }
+    // /->form()
+
+    public function process_form()
+    {
+        $this->wizard->_fields = []; // kill the wizard's stored fields
+        return null;
+    }
 }
diff --git a/src/tutors/assessments/email/index.php b/src/tutors/assessments/email/index.php
index d49e517..ba4f484 100644
--- a/src/tutors/assessments/email/index.php
+++ b/src/tutors/assessments/email/index.php
@@ -8,15 +8,15 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\classes\Wizard;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -32,37 +32,37 @@
 
 $assessment = new Assessment($DB);
 if ($assessment->load($assessment_id)) {
-  $assessment_qs = "a={$assessment->id}&tab={$tab}&y={$year}";
+    $assessment_qs = "a={$assessment->id}&tab={$tab}&y={$year}";
 } else {
-  $assessment = null;
+    $assessment = null;
 }
 
 // --------------------------------------------------------------------------------
 // Initialise wizard
 
 if ($assessment) {
-  $wizard = new Wizard('email your students wizard');
-  $wizard->set_wizard_url("index.php?a={$assessment->id}&tab={$tab}&y={$year}");
+    $wizard = new Wizard('email your students wizard');
+    $wizard->set_wizard_url("index.php?a={$assessment->id}&tab={$tab}&y={$year}");
 
-  $wizard->set_field('list_url',$list_url);
-  $wizard->cancel_url = $wizard->get_field('list_url');
+    $wizard->set_field('list_url', $list_url);
+    $wizard->cancel_url = $wizard->get_field('list_url');
 
-  $wizard->add_step(1,'class_wizardstep_1.php');
-  $wizard->add_step(2,'class_wizardstep_2.php');
-  $wizard->add_step(3,'class_wizardstep_3.php');
-  $wizard->add_step(4,'class_wizardstep_4.php');
+    $wizard->add_step(1, 'class_wizardstep_1.php');
+    $wizard->add_step(2, 'class_wizardstep_2.php');
+    $wizard->add_step(3, 'class_wizardstep_3.php');
+    $wizard->add_step(4, 'class_wizardstep_4.php');
 
-  $wizard->show_steps(3); // Hide the last step from the user
+    $wizard->show_steps(3); // Hide the last step from the user
 
-  $wizard->set_var('db',$DB);
-  $wizard->set_var('config',$_config);
-  $wizard->set_var('user',$_user);
-  $wizard->set_var('cis',$CIS);
-  $wizard->set_var('assessment',$assessment);
+    $wizard->set_var('db', $DB);
+    $wizard->set_var('config', $_config);
+    $wizard->set_var('user', $_user);
+    $wizard->set_var('cis', $CIS);
+    $wizard->set_var('assessment', $assessment);
 
-  $wizard->prepare();
+    $wizard->prepare();
 
-  $wiz_step = $wizard->get_step();
+    $wiz_step = $wizard->get_step();
 }
 
 // --------------------------------------------------------------------------------
@@ -74,21 +74,21 @@
 $UI->page_title = APP__NAME . ' email your students';
 $UI->menu_selected = 'my assessments';
 $UI->help_link = '?q=node/235';
-$UI->breadcrumbs = array  (
-  'home'        => '../../' ,
-  'my assessments'  => '../' ,
-  'email students'  => null ,
-);
+$UI->breadcrumbs = [
+  'home'        => '../../',
+  'my assessments'  => '../',
+  'email students'  => null,
+];
 
 $UI->set_page_bar_button('List Assessments', '../../../../images/buttons/button_assessment_list.gif', '../');
 $UI->set_page_bar_button('Create Assessments', '../../../../images/buttons/button_assessment_create.gif', '../create/');
 
 $UI->head();
 if ($assessment) {
-  $wizard->head();
-  $UI->body('onload="body_onload()"');
+    $wizard->head();
+    $UI->body('onload="body_onload()"');
 } else {
-  $UI->body();
+    $UI->body();
 }
 $UI->content_start();
 ?>
@@ -97,8 +97,8 @@
 
 <?php
 if ($assessment) {
-  $wizard->title();
-  $wizard->draw_errors();
+    $wizard->title();
+    $wizard->draw_errors();
 }
 ?>
 
@@ -106,9 +106,9 @@
 
 <?php
 if ($assessment) {
-  $wizard->draw_wizard();
+    $wizard->draw_wizard();
 } else {
-  echo("<p>The given assessment failed to load so this wizard cannot be started.</p>");
+    echo '<p>The given assessment failed to load so this wizard cannot be started.</p>';
 }
 ?>
 
diff --git a/src/tutors/assessments/inc_list_closed.php b/src/tutors/assessments/inc_list_closed.php
index b3dc8d8..9fbc521 100644
--- a/src/tutors/assessments/inc_list_closed.php
+++ b/src/tutors/assessments/inc_list_closed.php
@@ -10,12 +10,13 @@
  * @link https://github.com/webpa/webpa
  */
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\ResultHandler;
 use WebPA\includes\classes\SimpleObjectIterator;
 
 ?>
 
-<h2>Closed assessments for <?php echo($academic_year); ?></h2>
+<h2>Closed assessments for <?php echo $academic_year; ?></h2>
 
 <p>These assessments were scheduled for some time in the past, and are now closed. No further student submissions can be made to closed assessments, but no marks have yet been generated.</p>
 
@@ -28,67 +29,85 @@
 
 // get the assessment that are closed (but not marked)
 $now = date(MYSQL_DATETIME_FORMAT);
-$assessments = $DB->fetch("SELECT a.*
-              FROM " . APP__DB_TABLE_PREFIX . "assessment a
-                LEFT JOIN " . APP__DB_TABLE_PREFIX . "assessment_marking am ON a.assessment_id = am.assessment_id
-              WHERE a.module_id = {$_module['module_id']}
-                AND a.open_date >= '{$this_year}'
-                AND a.open_date < '{$next_year}'
-                AND a.close_date < '{$now}'
-                AND am.assessment_id IS NULL
-              ORDER BY a.open_date, a.close_date, a.assessment_name");
+
+$assessmentsQuery =
+    'SELECT a.* ' .
+    'FROM ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
+    'LEFT JOIN ' . APP__DB_TABLE_PREFIX . 'assessment_marking am ' .
+    'ON a.assessment_id = am.assessment_id ' .
+    'WHERE a.module_id = ? ' .
+    'AND a.open_date >= ? ' .
+    'AND a.open_date < ? ' .
+    'AND a.close_date < ? ' .
+    'AND am.assessment_id IS NULL ' .
+    'ORDER BY a.open_date, a.close_date, a.assessment_name';
+
+$assessments = $DB->getConnection()->fetchAllAssociative(
+    $assessmentsQuery,
+    [
+            $_module['module_id'],
+            $this_year,
+            $next_year,
+            $now,
+        ],
+    [
+            ParameterType::INTEGER,
+            ParameterType::STRING,
+            ParameterType::STRING,
+            ParameterType::STRING,
+        ]
+);
 
 if (!$assessments) {
-?>
+    ?>
   <p>You do not have any assessments in this category.</p>
   <p>Please choose another category from the tabs above.</p>
 <?php
 } else {
-?>
+        ?>
   <div class="obj_list">
 <?php
     // prefetch response counts for each assessment
   $result_handler = new ResultHandler($DB);
-  $responses = $result_handler->get_responses_count_for_user($_user->id, $year);
-  $members = $result_handler->get_members_count_for_user($_user->id, $year);
+        $responses = $result_handler->get_responses_count_for_user($_user->id, $year);
+        $members = $result_handler->get_members_count_for_user($_user->id, $year);
 
-  // loop through and display all the assessments
-  $assessment_iterator = new SimpleObjectIterator($assessments,'Assessment', $DB);
+        // loop through and display all the assessments
+        $assessment_iterator = new SimpleObjectIterator($assessments, 'Assessment', $DB);
 
-  for ($assessment_iterator->reset(); $assessment_iterator->is_valid(); $assessment_iterator->next()) {
-    $assessment =& $assessment_iterator->current();
+        for ($assessment_iterator->reset(); $assessment_iterator->is_valid(); $assessment_iterator->next()) {
+            $assessment =& $assessment_iterator->current();
 
-    $num_responses = (array_key_exists($assessment->id, $responses)) ? $responses[$assessment->id] : 0 ;
-    $num_members =  (array_key_exists($assessment->id, $members)) ? $members[$assessment->id] : 0 ;
-    $completed_msg = ($num_responses==$num_members) ? '- <strong>COMPLETED</strong>' : '';
+            $num_responses = (array_key_exists($assessment->id, $responses)) ? $responses[$assessment->id] : 0 ;
+            $num_members =  (array_key_exists($assessment->id, $members)) ? $members[$assessment->id] : 0 ;
+            $completed_msg = ($num_responses==$num_members) ? '- <strong>COMPLETED</strong>' : '';
 
-    $edit_url = "edit/edit_assessment.php?a={$assessment->id}&{$qs}";
-    $email_url = "email/index.php?a={$assessment->id}&{$qs}";
-    $responded_url = "students_who_responded.php?a={$assessment->id}&{$qs}";
-    $groupmark_url = "marks/set_group_marks.php?a={$assessment->id}&{$qs}";
-    $mark_url = "marks/mark_assessment.php?a={$assessment->id}&{$qs}";
-?>
+            $edit_url = "edit/edit_assessment.php?a={$assessment->id}&{$qs}";
+            $email_url = "email/index.php?a={$assessment->id}&{$qs}";
+            $responded_url = "students_who_responded.php?a={$assessment->id}&{$qs}";
+            $groupmark_url = "marks/set_group_marks.php?a={$assessment->id}&{$qs}";
+            $mark_url = "marks/mark_assessment.php?a={$assessment->id}&{$qs}"; ?>
     <div class="obj">
       <table class="obj" cellpadding="2" cellspacing="2">
       <tr>
         <td class="icon" width="24"><img src="../../images/icons/closed_icon.gif" alt="Closed" title="Closed" height="24" width="24" /></td>
         <td class="obj_info">
-          <div class="obj_name"><?php echo($assessment->name); ?></div>
-          <div class="obj_info_text">scheduled: <?php echo($assessment->get_date_string('open_date')); ?> &nbsp;-&nbsp; <?php echo($assessment->get_date_string('close_date')); ?></div>
-          <div class="obj_info_text">student responses: <?php echo("$num_responses / $num_members $completed_msg"); ?></div>
+          <div class="obj_name"><?php echo $assessment->name; ?></div>
+          <div class="obj_info_text">scheduled: <?php echo $assessment->get_date_string('open_date'); ?> &nbsp;-&nbsp; <?php echo $assessment->get_date_string('close_date'); ?></div>
+          <div class="obj_info_text">student responses: <?php echo "$num_responses / $num_members $completed_msg"; ?></div>
         </td>
         <td class="buttons">
-          <a href="<?php echo($edit_url); ?>"><img src="../../images/buttons/edit.gif" width="16" height="16" alt="Edit" title="Edit assessment" /></a>
-          <a href="<?php echo($email_url); ?>"><img src="../../images/buttons/email.gif" width="16" height="16" alt="Email" title="Email students" /></a>
-          <a href="<?php echo($responded_url); ?>"><img src="../../images/buttons/students_responded.gif" width="16" height="16" alt="Students responded" title="Check which students have responded" /></a>
-          <a href="<?php echo($groupmark_url); ?>"><img src="../../images/buttons/group_marks.gif" width="16" height="16" alt="Group Marks" title="Set group marks" /></a>
-          <a href="<?php echo($mark_url); ?>"><img src="../../images/buttons/mark_sheet.gif" width="16" height="16" alt="Mark Sheet" title="New mark sheet" /></a>
+          <a href="<?php echo $edit_url; ?>"><img src="../../images/buttons/edit.gif" width="16" height="16" alt="Edit" title="Edit assessment" /></a>
+          <a href="<?php echo $email_url; ?>"><img src="../../images/buttons/email.gif" width="16" height="16" alt="Email" title="Email students" /></a>
+          <a href="<?php echo $responded_url; ?>"><img src="../../images/buttons/students_responded.gif" width="16" height="16" alt="Students responded" title="Check which students have responded" /></a>
+          <a href="<?php echo $groupmark_url; ?>"><img src="../../images/buttons/group_marks.gif" width="16" height="16" alt="Group Marks" title="Set group marks" /></a>
+          <a href="<?php echo $mark_url; ?>"><img src="../../images/buttons/mark_sheet.gif" width="16" height="16" alt="Mark Sheet" title="New mark sheet" /></a>
         </td>
       </tr>
       </table>
     </div>
 <?php
-  }
-  echo("  </div>\n");
-}
+        }
+        echo "  </div>\n";
+    }
 ?>
diff --git a/src/tutors/assessments/inc_list_marked.php b/src/tutors/assessments/inc_list_marked.php
index ba625eb..c1d2896 100644
--- a/src/tutors/assessments/inc_list_marked.php
+++ b/src/tutors/assessments/inc_list_marked.php
@@ -20,13 +20,14 @@
  *
  */
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\ResultHandler;
 use WebPA\includes\classes\SimpleObjectIterator;
 use WebPA\includes\classes\XMLParser;
 
 ?>
 
-<h2>Marked assessments for <?php echo($academic_year); ?></h2>
+<h2>Marked assessments for <?php echo $academic_year; ?></h2>
 
 <p>These assessments are both closed and have been marked to produce student grades.</p>
 
@@ -39,107 +40,124 @@
 
 // get the assessment that are closed and have been marked
 $now = date(MYSQL_DATETIME_FORMAT);
-$assessments = $DB->fetch("SELECT DISTINCT a.*
-              FROM " . APP__DB_TABLE_PREFIX . "assessment a
-                LEFT JOIN " . APP__DB_TABLE_PREFIX . "assessment_marking am ON a.assessment_id = am.assessment_id
-              WHERE a.module_id = {$_module['module_id']}
-                AND a.open_date >= '{$this_year}'
-                AND a.open_date < '{$next_year}'
-                AND a.close_date < '{$now}'
-                AND am.assessment_id IS NOT NULL
-              ORDER BY a.open_date, a.close_date, a.assessment_name");
+
+$assessmentsQuery =
+    'SELECT DISTINCT a.* ' .
+    'FROM ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
+    'LEFT JOIN ' . APP__DB_TABLE_PREFIX . 'assessment_marking am ' .
+    'ON a.assessment_id = am.assessment_id ' .
+    'WHERE a.module_id = ? ' .
+    'AND a.open_date >= ? ' .
+    'AND a.open_date < ? ' .
+    'AND a.close_date < ? ' .
+    'AND am.assessment_id IS NOT NULL ' .
+    'ORDER BY a.open_date, a.close_date, a.assessment_name';
+
+$assessments = $DB->getConnection()->fetchAllAssociative(
+    $assessmentsQuery,
+    [
+        $_module['module_id'],
+        $this_year,
+        $next_year,
+        $now,
+    ],
+    [
+        ParameterType::INTEGER,
+        ParameterType::STRING,
+        ParameterType::STRING,
+        ParameterType::STRING,
+    ]
+);
 
 if (!$assessments) {
-?>
+    ?>
   <p>You do not have any assessments in this category.</p>
   <p>Please choose another category from the tabs above.</p>
 <?php
 } else {
-?>
+        ?>
   <div class="obj_list">
 <?php
     // prefetch response counts for each assessment
   $result_handler = new ResultHandler($DB);
-  $responses = $result_handler->get_responses_count_for_user($_user->id, $year);
-  $members = $result_handler->get_members_count_for_user($_user->id, $year);
+        $responses = $result_handler->get_responses_count_for_user($_user->id, $year);
+        $members = $result_handler->get_members_count_for_user($_user->id, $year);
 
-  // Create an XML Parser for showing the mark sheets
-  $xml_parser = new XMLParser();
+        // Create an XML Parser for showing the mark sheets
+        $xml_parser = new XMLParser();
 
-  // loop through and display all the assessments
-  $assessment_iterator = new SimpleObjectIterator($assessments,'Assessment', $DB);
+        // loop through and display all the assessments
+        $assessment_iterator = new SimpleObjectIterator($assessments, 'Assessment', $DB);
 
-  for ($assessment_iterator->reset(); $assessment_iterator->is_valid(); $assessment_iterator->next()) {
-    $assessment =& $assessment_iterator->current();
-    $assessment->set_db($DB);
+        for ($assessment_iterator->reset(); $assessment_iterator->is_valid(); $assessment_iterator->next()) {
+            $assessment =& $assessment_iterator->current();
+            $assessment->set_db($DB);
 
-    $num_responses = (array_key_exists($assessment->id, $responses)) ? $responses[$assessment->id] : 0 ;
-    $num_members =  (array_key_exists($assessment->id, $members)) ? $members[$assessment->id] : 0 ;
-    $completed_msg = ($num_responses==$num_members) ? '- <strong>COMPLETED</strong>' : '';
+            $num_responses = (array_key_exists($assessment->id, $responses)) ? $responses[$assessment->id] : 0 ;
+            $num_members =  (array_key_exists($assessment->id, $members)) ? $members[$assessment->id] : 0 ;
+            $completed_msg = ($num_responses==$num_members) ? '- <strong>COMPLETED</strong>' : '';
 
-    $edit_url = "edit/edit_assessment.php?a={$assessment->id}&{$qs}";
-    $email_url = "email/index.php?a={$assessment->id}&{$qs}";
-    $groupmark_url = "marks/set_group_marks.php?a={$assessment->id}&{$qs}";
-    $responded_url = "students_who_responded.php?a={$assessment->id}&{$qs}";
-    $mark_url = "marks/mark_assessment.php?a={$assessment->id}&{$qs}";
+            $edit_url = "edit/edit_assessment.php?a={$assessment->id}&{$qs}";
+            $email_url = "email/index.php?a={$assessment->id}&{$qs}";
+            $groupmark_url = "marks/set_group_marks.php?a={$assessment->id}&{$qs}";
+            $responded_url = "students_who_responded.php?a={$assessment->id}&{$qs}";
+            $mark_url = "marks/mark_assessment.php?a={$assessment->id}&{$qs}";
 
-    $mark_sheets = $assessment->get_all_marking_params();
-?>
+            $mark_sheets = $assessment->get_all_marking_params(); ?>
     <div class="obj">
       <table class="obj" cellpadding="2" cellspacing="2">
       <tr>
         <td class="icon" width="24"><img src="../../images/icons/finished_icon.gif" alt="Finished" title="Finished" height="24" width="24" /></td>
         <td class="obj_info">
-          <div class="obj_name"><?php echo($assessment->name); ?></div>
-          <div class="obj_info_text">scheduled: <?php echo($assessment->get_date_string('open_date')); ?> &nbsp;-&nbsp; <?php echo($assessment->get_date_string('close_date')); ?></div>
-          <div class="obj_info_text">student responses: <?php echo("$num_responses / $num_members $completed_msg"); ?></div>
+          <div class="obj_name"><?php echo $assessment->name; ?></div>
+          <div class="obj_info_text">scheduled: <?php echo $assessment->get_date_string('open_date'); ?> &nbsp;-&nbsp; <?php echo $assessment->get_date_string('close_date'); ?></div>
+          <div class="obj_info_text">student responses: <?php echo "$num_responses / $num_members $completed_msg"; ?></div>
         </td>
         <td class="buttons">
-          <a href="<?php echo($edit_url); ?>"><img src="../../images/buttons/edit.gif" width="16" height="16" alt="Edit" title="Edit assessment" /></a>
-          <a href="<?php echo($email_url); ?>"><img src="../../images/buttons/email.gif" width="16" height="16" alt="Email" title="Email students" /></a>
-          <a href="<?php echo($responded_url); ?>"><img src="../../images/buttons/students_responded.gif" width="16" height="16" alt="Students responded" title="Check which students have responded" /></a>
-          <a href="<?php echo($groupmark_url); ?>"><img src="../../images/buttons/group_marks.gif" width="16" height="16" alt="Group Marks" title="Set group marks" /></a>
-          <a href="<?php echo($mark_url); ?>"><img src="../../images/buttons/mark_sheet.gif" width="16" height="16" alt="Mark Sheet" title="New mark sheet" /></a>
+          <a href="<?php echo $edit_url; ?>"><img src="../../images/buttons/edit.gif" width="16" height="16" alt="Edit" title="Edit assessment" /></a>
+          <a href="<?php echo $email_url; ?>"><img src="../../images/buttons/email.gif" width="16" height="16" alt="Email" title="Email students" /></a>
+          <a href="<?php echo $responded_url; ?>"><img src="../../images/buttons/students_responded.gif" width="16" height="16" alt="Students responded" title="Check which students have responded" /></a>
+          <a href="<?php echo $groupmark_url; ?>"><img src="../../images/buttons/group_marks.gif" width="16" height="16" alt="Group Marks" title="Set group marks" /></a>
+          <a href="<?php echo $mark_url; ?>"><img src="../../images/buttons/mark_sheet.gif" width="16" height="16" alt="Mark Sheet" title="New mark sheet" /></a>
         </td>
       </tr>
       </table>
 <?php
     if ($mark_sheets) {
-
-      foreach($mark_sheets as $date_created => $params) {
-        $date_created = strtotime($date_created);
-        $reports_url = "reports/index.php?a={$assessment->id}&md={$date_created}&{$qs}";
-
-        $algorithm = $params['algorithm'];
-        $penalty_type = ($params['penalty_type']=='pp') ? ' pp' : '%' ;   // Add a space to the 'pp'.
-        $tolerance = ($params['tolerance']==0) ? 'N/A' : "+/- {$params['tolerance']}%" ;
-        $grading = ($params['grading']=='grade_af') ? 'A-F' : 'Numeric (%)' ;
-
-        echo('    <div class="mark_sheet">');
-        echo('      <table class="mark_sheet_info" cellpadding="0" cellspacing="0">');
-        echo('      <tr>');
-        echo('        <td>');
-        echo('          <div class="mark_sheet_title">Mark Sheet</div>');
-        echo("          <div class=\"info\" style=\"font-weight: bold;\">Algorithm: {$algorithm}.</div>");
-        echo("          <div class=\"info\">PA weighting: {$params['weighting']}%</div>");
-        echo("          <div class=\"info\">Non-completion penalty: {$params['penalty']}{$penalty_type}</div>");
-
-        // @todo : implement tolerances and show to users clearly.
-        //          echo("          <div class=\"info\">Score Tolerance: {$tolerance}</div>");
-
-        echo("          <div class=\"info\">Grading: {$grading}</div>");
-        echo('        </td>');
-        echo('        <td class="buttons" style="line-height: 2em;">');
-        echo("          <a class=\"button\" href=\"$reports_url\">View&nbsp;Reports</a>");
-        echo('        </td>');
-        echo('      </tr>');
-        echo('      </table>');
-        echo('    </div>');
-      }
+        foreach ($mark_sheets as $date_created => $params) {
+            $date_created = strtotime($date_created);
+            $reports_url = "reports/index.php?a={$assessment->id}&md={$date_created}&{$qs}";
+
+            $algorithm = $params['algorithm'];
+            $penalty_type = ($params['penalty_type']=='pp') ? ' pp' : '%' ;   // Add a space to the 'pp'.
+            $tolerance = ($params['tolerance']==0) ? 'N/A' : "+/- {$params['tolerance']}%" ;
+            $grading = ($params['grading']=='grade_af') ? 'A-F' : 'Numeric (%)' ;
+
+            echo '    <div class="mark_sheet">';
+            echo '      <table class="mark_sheet_info" cellpadding="0" cellspacing="0">';
+            echo '      <tr>';
+            echo '        <td>';
+            echo '          <div class="mark_sheet_title">Mark Sheet</div>';
+            echo "          <div class=\"info\" style=\"font-weight: bold;\">Algorithm: {$algorithm}.</div>";
+            echo "          <div class=\"info\">PA weighting: {$params['weighting']}%</div>";
+            echo "          <div class=\"info\">Non-completion penalty: {$params['penalty']}{$penalty_type}</div>";
+
+            // @todo : implement tolerances and show to users clearly.
+            //          echo("          <div class=\"info\">Score Tolerance: {$tolerance}</div>");
+
+            echo "          <div class=\"info\">Grading: {$grading}</div>";
+            echo '        </td>';
+            echo '        <td class="buttons" style="line-height: 2em;">';
+            echo "          <a class=\"button\" href=\"$reports_url\">View&nbsp;Reports</a>";
+            echo '        </td>';
+            echo '      </tr>';
+            echo '      </table>';
+            echo '    </div>';
+        }
     }// /if(mark sheets)
-    echo("    </div>\n");
-  }
-  $xml_parser->destroy();
-  echo("  </div>\n");
-}
+            echo "    </div>\n";
+        }
+        $xml_parser->destroy();
+        echo "  </div>\n";
+    }
 ?>
diff --git a/src/tutors/assessments/inc_list_open.php b/src/tutors/assessments/inc_list_open.php
index b2d2523..f32cea2 100644
--- a/src/tutors/assessments/inc_list_open.php
+++ b/src/tutors/assessments/inc_list_open.php
@@ -10,12 +10,13 @@
  * @link https://github.com/webpa/webpa
  */
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\ResultHandler;
 use WebPA\includes\classes\SimpleObjectIterator;
 
 ?>
 
-<h2>Open assessments for <?php echo($academic_year); ?></h2>
+<h2>Open assessments for <?php echo $academic_year; ?></h2>
 
 <p>These assessments are now open and available for students to take.</p>
 <hr />
@@ -26,64 +27,84 @@
 
 // get the assessment that are open
 $now = date(MYSQL_DATETIME_FORMAT);
-$assessments = $DB->fetch("SELECT a.*
-              FROM " . APP__DB_TABLE_PREFIX . "assessment a
-              WHERE a.module_id = {$_module['module_id']}
-                AND a.open_date >= '{$this_year}'
-                AND a.open_date < '{$next_year}'
-                AND a.open_date < '{$now}' AND a.close_date > '{$now}'
-              ORDER BY a.open_date, a.close_date, a.assessment_name");
+
+$assessmentsQuery =
+    'SELECT a.* ' .
+    'FROM ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
+    'WHERE a.module_id = ? ' .
+    'AND a.open_date >= ? ' .
+    'AND a.open_date < ? ' .
+    'AND a.open_date < ? ' .
+    'AND a.close_date > ? ' .
+    'ORDER BY a.open_date, a.close_date, a.assessment_name';
+
+$assessments = $DB->getConnection()->fetchAllAssociative(
+    $assessmentsQuery,
+    [
+        $_module['module_id'],
+        $this_year,
+        $next_year,
+        $now,
+        $now,
+    ],
+    [
+        ParameterType::INTEGER,
+        ParameterType::STRING,
+        ParameterType::STRING,
+        ParameterType::STRING,
+        ParameterType::STRING,
+    ]
+);
 
 if (!$assessments) {
-?>
+    ?>
   <p>You do not have any assessments in this category.</p>
   <p>Please choose another category from the tabs above, or <a href="/tutors/assessments/create/">create a new assessment</a>.</p>
 <?php
 } else {
-?>
+        ?>
   <div class="obj_list">
 <?php
   // prefetch response counts for each assessment
   $result_handler = new ResultHandler($DB);
-  $responses = $result_handler->get_responses_count_for_user($_user->id, $year);
-  $members = $result_handler->get_members_count_for_user($_user->id, $year);
+        $responses = $result_handler->get_responses_count_for_user($_user->id, $year);
+        $members = $result_handler->get_members_count_for_user($_user->id, $year);
 
-  // loop through and display all the assessments
-  $assessment_iterator = new SimpleObjectIterator($assessments,'Assessment', $DB);
-  for ($assessment_iterator->reset(); $assessment_iterator->is_valid(); $assessment_iterator->next()) {
-    $assessment =& $assessment_iterator->current();
+        // loop through and display all the assessments
+        $assessment_iterator = new SimpleObjectIterator($assessments, 'Assessment', $DB);
+        for ($assessment_iterator->reset(); $assessment_iterator->is_valid(); $assessment_iterator->next()) {
+            $assessment =& $assessment_iterator->current();
 
-    $num_responses = (array_key_exists($assessment->id, $responses)) ? $responses[$assessment->id] : 0 ;
-    $num_members =  (array_key_exists($assessment->id, $members)) ? $members[$assessment->id] : 0 ;
-    $completed_msg = ($num_responses==$num_members) ? '- <strong>COMPLETED</strong>' : '';
+            $num_responses = (array_key_exists($assessment->id, $responses)) ? $responses[$assessment->id] : 0 ;
+            $num_members =  (array_key_exists($assessment->id, $members)) ? $members[$assessment->id] : 0 ;
+            $completed_msg = ($num_responses==$num_members) ? '- <strong>COMPLETED</strong>' : '';
 
-    $edit_url = "edit/edit_assessment.php?a={$assessment->id}&{$qs}";
-    $email_url = "email/index.php?a={$assessment->id}&{$qs}";
-    $responded_url = "students_who_responded.php?a={$assessment->id}&{$qs}";
-    $groupmark_url = "marks/set_group_marks.php?a={$assessment->id}&{$qs}";
-    $delete_marks_url = "delete_marks.php?a={$assessment->id}&{$qs}";
-?>
+            $edit_url = "edit/edit_assessment.php?a={$assessment->id}&{$qs}";
+            $email_url = "email/index.php?a={$assessment->id}&{$qs}";
+            $responded_url = "students_who_responded.php?a={$assessment->id}&{$qs}";
+            $groupmark_url = "marks/set_group_marks.php?a={$assessment->id}&{$qs}";
+            $delete_marks_url = "delete_marks.php?a={$assessment->id}&{$qs}"; ?>
     <div class="obj">
       <table class="obj" cellpadding="2" cellspacing="2">
       <tr>
         <td class="icon" width="24"><img src="../../images/icons/open_icon.gif" alt="Open" title="Open" height="24" width="24" /></td>
         <td class="obj_info">
-          <div class="obj_name"><?php echo($assessment->name); ?></div>
-          <div class="obj_info_text">scheduled: <?php echo($assessment->get_date_string('open_date')); ?> &nbsp;-&nbsp; <?php echo($assessment->get_date_string('close_date')); ?></div>
-          <div class="obj_info_text">student responses: <?php echo("$num_responses / $num_members $completed_msg"); ?></div>
+          <div class="obj_name"><?php echo $assessment->name; ?></div>
+          <div class="obj_info_text">scheduled: <?php echo $assessment->get_date_string('open_date'); ?> &nbsp;-&nbsp; <?php echo $assessment->get_date_string('close_date'); ?></div>
+          <div class="obj_info_text">student responses: <?php echo "$num_responses / $num_members $completed_msg"; ?></div>
         </td>
         <td class="buttons">
-          <a href="<?php echo($edit_url); ?>"><img src="../../images/buttons/edit.gif" width="16" height="16" alt="Edit" title="Edit assessment" /></a>
-          <a href="<?php echo($email_url); ?>"><img src="../../images/buttons/email.gif" width="16" height="16" alt="Email" title="Email students" /></a>
-          <a href="<?php echo($responded_url); ?>"><img src="../../images/buttons/students_responded.gif" width="16" height="16" alt="Students responded" title="Check which students have responded" /></a>
-          <a href="<?php echo($groupmark_url); ?>"><img src="../../images/buttons/group_marks.gif" width="16" height="16" alt="Group Marks" title="Set group marks" /></a>
-          <a href="<?php echo($delete_marks_url); ?>"><img src="../../images/icons/group_delete.png" width="16" height="16" alt="Delete individual marks" title="Delete individual marks" /></a>
+          <a href="<?php echo $edit_url; ?>"><img src="../../images/buttons/edit.gif" width="16" height="16" alt="Edit" title="Edit assessment" /></a>
+          <a href="<?php echo $email_url; ?>"><img src="../../images/buttons/email.gif" width="16" height="16" alt="Email" title="Email students" /></a>
+          <a href="<?php echo $responded_url; ?>"><img src="../../images/buttons/students_responded.gif" width="16" height="16" alt="Students responded" title="Check which students have responded" /></a>
+          <a href="<?php echo $groupmark_url; ?>"><img src="../../images/buttons/group_marks.gif" width="16" height="16" alt="Group Marks" title="Set group marks" /></a>
+          <a href="<?php echo $delete_marks_url; ?>"><img src="../../images/icons/group_delete.png" width="16" height="16" alt="Delete individual marks" title="Delete individual marks" /></a>
         </td>
       </tr>
       </table>
     </div>
     <?php
-  }
-  echo("  </div>\n");
-}
+        }
+        echo "  </div>\n";
+    }
 ?>
diff --git a/src/tutors/assessments/inc_list_pending.php b/src/tutors/assessments/inc_list_pending.php
index e339172..7a50d3a 100644
--- a/src/tutors/assessments/inc_list_pending.php
+++ b/src/tutors/assessments/inc_list_pending.php
@@ -10,12 +10,13 @@
  * @link https://github.com/webpa/webpa
  */
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\ResultHandler;
 use WebPA\includes\classes\SimpleObjectIterator;
 
 ?>
 
-<h2>Pending assessments for <?php echo($academic_year); ?></h2>
+<h2>Pending assessments for <?php echo $academic_year; ?></h2>
 
 <p>These assessments are scheduled to open for students at some point in the future.</p>
 <hr />
@@ -26,63 +27,83 @@
 
 // get the assessment that are pending
 $now = date(MYSQL_DATETIME_FORMAT);
-$assessments = $DB->fetch("SELECT a.*
-              FROM " . APP__DB_TABLE_PREFIX . "assessment a
-              WHERE a.module_id = {$_module['module_id']}
-                AND a.open_date >= '{$this_year}'
-                AND a.open_date < '{$next_year}'
-                AND a.open_date > '{$now}' AND a.close_date > '{$now}'
-              ORDER BY a.open_date, a.close_date, a.assessment_name");
+
+$assessmentQuery =
+    'SELECT a.* ' .
+    'FROM ' . APP__DB_TABLE_PREFIX . 'assessment a ' .
+    'WHERE a.module_id = ? ' .
+    'AND a.open_date >= ? ' .
+    'AND a.open_date < ? ' .
+    'AND a.open_date > ? ' .
+    'AND a.close_date > ? ' .
+    'ORDER BY a.open_date, a.close_date, a.assessment_name';
+
+$assessments = $DB->getConnection()->fetchAllAssociative(
+    $assessmentQuery,
+    [
+        $_module['module_id'],
+        $this_year,
+        $next_year,
+        $now,
+        $now,
+    ],
+    [
+        ParameterType::INTEGER,
+        ParameterType::STRING,
+        ParameterType::STRING,
+        ParameterType::STRING,
+        ParameterType::STRING,
+    ]
+);
 
 if (!$assessments) {
-?>
+    ?>
   <p>You do not have any assessments in this category.</p>
   <p>Please choose another category from the tabs above, or <a href="create/">create a new assessment</a>.</p>
 <?php
 } else {
-?>
+        ?>
   <div class="obj_list">
 <?php
   // prefetch response counts for each assessment
   $result_handler = new ResultHandler($DB);
-  $responses = $result_handler->get_responses_count_for_user($_user->id, $year);
-  $members = $result_handler->get_members_count_for_user($_user->id, $year);
+        $responses = $result_handler->get_responses_count_for_user($_user->id, $year);
+        $members = $result_handler->get_members_count_for_user($_user->id, $year);
 
-  // loop through and display all the assessments
-  $assessment_iterator = new SimpleObjectIterator($assessments,'Assessment', $DB);
+        // loop through and display all the assessments
+        $assessment_iterator = new SimpleObjectIterator($assessments, 'Assessment', $DB);
 
-  for ($assessment_iterator->reset(); $assessment_iterator->is_valid(); $assessment_iterator->next()) {
-    $assessment =& $assessment_iterator->current();
+        for ($assessment_iterator->reset(); $assessment_iterator->is_valid(); $assessment_iterator->next()) {
+            $assessment =& $assessment_iterator->current();
 
-    $num_responses = (array_key_exists($assessment->id, $responses)) ? $responses[$assessment->id] : 0 ;
-    $num_members =  (array_key_exists($assessment->id, $members)) ? $members[$assessment->id] : 0 ;
-    $completed_msg = ($num_responses==$num_members) ? '- <strong>COMPLETED</strong>' : '';
+            $num_responses = (array_key_exists($assessment->id, $responses)) ? $responses[$assessment->id] : 0 ;
+            $num_members =  (array_key_exists($assessment->id, $members)) ? $members[$assessment->id] : 0 ;
+            $completed_msg = ($num_responses==$num_members) ? '- <strong>COMPLETED</strong>' : '';
 
-    $edit_url = "edit/edit_assessment.php?a={$assessment->id}&{$qs}";
-    $email_url = "email/index.php?a={$assessment->id}&{$qs}";
-    $responded_url = "students_who_responded.php?a={$assessment->id}&{$qs}";
-    $groupmark_url = "marks/set_group_marks.php?a={$assessment->id}&{$qs}";
-?>
+            $edit_url = "edit/edit_assessment.php?a={$assessment->id}&{$qs}";
+            $email_url = "email/index.php?a={$assessment->id}&{$qs}";
+            $responded_url = "students_who_responded.php?a={$assessment->id}&{$qs}";
+            $groupmark_url = "marks/set_group_marks.php?a={$assessment->id}&{$qs}"; ?>
     <div class="obj">
       <table class="obj" cellpadding="2" cellspacing="2">
       <tr>
         <td class="icon" width="24"><img src="../../images/icons/pending_icon.gif" alt="Pending" title="Pending" height="24" width="24" /></td>
         <td class="obj_info">
-          <div class="obj_name"><?php echo($assessment->name); ?></div>
-          <div class="obj_info_text">scheduled: <?php echo($assessment->get_date_string('open_date')); ?> &nbsp;-&nbsp; <?php echo($assessment->get_date_string('close_date')); ?></div>
-          <div class="obj_info_text">student responses: <?php echo("$num_responses / $num_members $completed_msg"); ?></div>
+          <div class="obj_name"><?php echo $assessment->name; ?></div>
+          <div class="obj_info_text">scheduled: <?php echo $assessment->get_date_string('open_date'); ?> &nbsp;-&nbsp; <?php echo $assessment->get_date_string('close_date'); ?></div>
+          <div class="obj_info_text">student responses: <?php echo "$num_responses / $num_members $completed_msg"; ?></div>
         </td>
         <td class="buttons">
-          <a href="<?php echo($edit_url); ?>"><img src="../../images/buttons/edit.gif" width="16" height="16" alt="Edit" title="Edit assessment" /></a>
-          <a href="<?php echo($email_url); ?>"><img src="../../images/buttons/email.gif" width="16" height="16" alt="Email" title="Email students" /></a>
-          <a href="<?php echo($responded_url); ?>"><img src="../../images/buttons/students_responded.gif" width="16" height="16" alt="Students responded" title="Check which students have responded" /></a>
-          <a href="<?php echo($groupmark_url); ?>"><img src="../../images/buttons/group_marks.gif" width="16" height="16" alt="Group Marks" title="Set group marks" /></a>
+          <a href="<?php echo $edit_url; ?>"><img src="../../images/buttons/edit.gif" width="16" height="16" alt="Edit" title="Edit assessment" /></a>
+          <a href="<?php echo $email_url; ?>"><img src="../../images/buttons/email.gif" width="16" height="16" alt="Email" title="Email students" /></a>
+          <a href="<?php echo $responded_url; ?>"><img src="../../images/buttons/students_responded.gif" width="16" height="16" alt="Students responded" title="Check which students have responded" /></a>
+          <a href="<?php echo $groupmark_url; ?>"><img src="../../images/buttons/group_marks.gif" width="16" height="16" alt="Group Marks" title="Set group marks" /></a>
         </td>
       </tr>
       </table>
     </div>
 <?php
-  }
-  echo("  </div>\n");
-}
+        }
+        echo "  </div>\n";
+    }
 ?>
diff --git a/src/tutors/assessments/index.php b/src/tutors/assessments/index.php
index dd60a07..ec8e7a4 100644
--- a/src/tutors/assessments/index.php
+++ b/src/tutors/assessments/index.php
@@ -8,14 +8,14 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../includes/inc_global.php");
+require_once '../../includes/inc_global.php';
 
-use WebPA\includes\functions\Common;
 use WebPA\includes\functions\AcademicYear;
+use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -29,26 +29,26 @@
 
 $academic_year = strval($year);
 if (APP__ACADEMIC_YEAR_START_MONTH > 1) {
-  $academic_year .= '/' . substr($year + 1, 2, 2);
+    $academic_year .= '/' . substr($year + 1, 2, 2);
 }
 
 $this_year = '-';
 if (APP__ACADEMIC_YEAR_START_MONTH <= 10) {
-  $this_year .= '0';
+    $this_year .= '0';
 }
 $this_year .= APP__ACADEMIC_YEAR_START_MONTH . '-01 00:00:00';
-$next_year = strval($year + 1) . $this_year;
-$this_year = strval($year) . $this_year;
+$next_year = (string) ($year + 1) . $this_year;
+$this_year = (string) $year . $this_year;
 
-$tabs = array ('pending'  => "?tab=pending&y={$year}" ,
-         'open'   => "?tab=open&y={$year}" ,
-         'closed'   => "?tab=closed&y={$year}" ,
-         'marked'   => "?tab=marked&y={$year}" ,
-);
+$tabs = ['pending'  => "?tab=pending&y={$year}",
+         'open'   => "?tab=open&y={$year}",
+         'closed'   => "?tab=closed&y={$year}",
+         'marked'   => "?tab=marked&y={$year}",
+];
 
-$tab = Common::fetch_GET('tab','pending');
+$tab = Common::fetch_GET('tab', 'pending');
 
-switch($tab) {
+switch ($tab) {
   case 'pending':
         $include_page = 'inc_list_pending.php';
         break;
@@ -68,7 +68,7 @@
 
 $qs = "tab={$tab}&y={$year}";
 
-$page_url = APP__WWW . "/tutors/assessments/index.php";
+$page_url = APP__WWW . '/tutors/assessments/index.php';
 
 // --------------------------------------------------------------------------------
 // Begin Page
@@ -76,10 +76,10 @@
 $UI->page_title = APP__NAME . ' my assessments';
 $UI->menu_selected = 'my assessments';
 $UI->help_link = '?q=node/235';
-$UI->breadcrumbs = array  (
-  'home'      => '../' ,
-  'my assessments'  => null ,
-);
+$UI->breadcrumbs = [
+  'home'      => '../',
+  'my assessments'  => null,
+];
 
 $UI->set_page_bar_button('List Assessments', '../../../images/buttons/button_assessment_list.gif', '');
 $UI->set_page_bar_button('Create Assessments', '../../../images/buttons/button_assessment_create.gif', 'create/');
@@ -93,7 +93,7 @@
   function change_academic_year() {
     year_sbox = document.getElementById('academic_year');
     chosen_year = year_sbox.options[year_sbox.selectedIndex].value;
-    if (chosen_year) { window.location.href='<?php echo($page_url ."?tab={$tab}&y="); ?>'+chosen_year; }
+    if (chosen_year) { window.location.href='<?php echo $page_url ."?tab={$tab}&y="; ?>'+chosen_year; }
   }
 
 //-->
@@ -113,9 +113,9 @@ function change_academic_year() {
   <tr>
     <td>&nbsp;</td>
     <?php
-      foreach($tabs as $label => $url) {
-        $tab_status = ($label==$tab) ? 'on' : 'off';
-        echo("<td class=\"tab_{$tab_status}\" width=\"100\"><a class=\"tab\" href=\"{$url}\">". ucfirst($label) .'</a></td>');
+      foreach ($tabs as $label => $url) {
+          $tab_status = ($label==$tab) ? 'on' : 'off';
+          echo "<td class=\"tab_{$tab_status}\" width=\"100\"><a class=\"tab\" href=\"{$url}\">". ucfirst($label) .'</a></td>';
       }
     ?>
     <td>&nbsp;</td>
@@ -134,12 +134,12 @@ function change_academic_year() {
       <select name="academic_year" id="academic_year">
         <?php
           for ($i = $start_year; $i <= $last_year; $i++) {
-            $selected_str = ($i == $year) ? 'selected="selected"' : '';
-            echo("<option value=\"$i\" $selected_str>". $i);
-            if (APP__ACADEMIC_YEAR_START_MONTH > 1) {
-              echo('/' . substr($i + 1, 2, 2));
-            }
-            echo ('</option>');
+              $selected_str = ($i == $year) ? 'selected="selected"' : '';
+              echo "<option value=\"$i\" $selected_str>". $i;
+              if (APP__ACADEMIC_YEAR_START_MONTH > 1) {
+                  echo '/' . substr($i + 1, 2, 2);
+              }
+              echo '</option>';
           }
         ?>
       </select>
@@ -149,7 +149,7 @@ function change_academic_year() {
   </table>
 
 <?php
-include_once($include_page);
+include_once $include_page;
 ?>
 
   </form>
diff --git a/src/tutors/assessments/marks/mark_assessment.php b/src/tutors/assessments/marks/mark_assessment.php
index d3871e0..ca3dbea 100644
--- a/src/tutors/assessments/marks/mark_assessment.php
+++ b/src/tutors/assessments/marks/mark_assessment.php
@@ -8,7 +8,7 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\classes\GroupHandler;
@@ -16,9 +16,9 @@
 use WebPA\includes\classes\XMLParser;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -40,15 +40,15 @@
 
 $assessment = new Assessment($DB);
 if ($assessment->load($assessment_id)) {
-  $assessment_qs = "a={$assessment->id}&tab={$tab}&y={$year}";
+    $assessment_qs = "a={$assessment->id}&tab={$tab}&y={$year}";
 
-  $group_handler = new GroupHandler();
-  $collection = $group_handler->get_collection($assessment->get_collection_id());
+    $group_handler = new GroupHandler();
+    $collection = $group_handler->get_collection($assessment->get_collection_id());
 
-  $result_handler = new ResultHandler($DB);
-  $result_handler->set_assessment($assessment);
+    $result_handler = new ResultHandler($DB);
+    $result_handler->set_assessment($assessment);
 } else {
-  $assessment = null;
+    $assessment = null;
 }
 
 $min_penalty = 0;
@@ -62,25 +62,25 @@
 
 $errors = null;
 
-if ( ($command) && ($assessment) ) {
-  switch ($command) {
+if (($command) && ($assessment)) {
+    switch ($command) {
     case 'save':
       // Create Mark Sheet
       $weighting = Common::fetch_POST('pa_weighting', null);
       $weighting = (is_numeric($weighting)) ? (int) $weighting : null;
-      if ( (is_null($weighting)) || ($weighting<=0) || ($weighting>100) ) {
-        $errors[] = 'The PA Weighting must be a number between 1 - 100';
+      if ((is_null($weighting)) || ($weighting<=0) || ($weighting>100)) {
+          $errors[] = 'The PA Weighting must be a number between 1 - 100';
       }
 
       $penalty = Common::fetch_POST('pa_penalty', null);
       $penalty = (is_numeric($penalty)) ? (int) $penalty : null;
-      if ( (is_null($penalty)) || ($penalty<$min_penalty) || ($penalty>$max_penalty) ) {
-        $errors[] = "The Non-completion Penalty must be a number between $min_penalty - $max_penalty";
+      if ((is_null($penalty)) || ($penalty<$min_penalty) || ($penalty>$max_penalty)) {
+          $errors[] = "The Non-completion Penalty must be a number between $min_penalty - $max_penalty";
       }
 
       $penalty_type = Common::fetch_POST('pa_penalty_type', null);
       if ($penalty_type!='pp') {
-        $penalty_type = '%';
+          $penalty_type = '%';
       }
 
       /*
@@ -96,34 +96,44 @@
       $grading = ($grading=='grade_af') ? $grading : 'numeric';
 
       $algorithm = Common::fetch_POST('pa_algorithm', null);
-      $valid_algs = array ('pets', 'webpa');
+      $valid_algs = ['pets', 'webpa'];
       if (!in_array($algorithm, $valid_algs)) {
-        $algorithm = 'webpa';
+          $algorithm = 'webpa';
       }
 
       // If there were no errors, save the changes
       if (!$errors) {
-        $xml_parser = new XMLParser();
-
-        $xml_array['parameters']['weighting']['_attributes'] = array ( 'value'  => $weighting );
-        $xml_array['parameters']['penalty']['_attributes'] = array ( 'value'  => $penalty );
-        $xml_array['parameters']['penalty_type']['_attributes'] = array ( 'value' => $penalty_type );
-
-        //$xml_array['parameters']['tolerance']['_attributes'] = array ( 'value'  => $tolerance );
-        $xml_array['parameters']['grading']['_attributes'] = array ( 'value'  => $grading );
-        $xml_array['parameters']['algorithm']['_attributes'] = array ( 'value'  => $algorithm );
-
-        $mysql_now = date(MYSQL_DATETIME_FORMAT,time());
-
-        $fields = array (
-          'assessment_id'     => $assessment_id ,
-          'date_created'      => $mysql_now ,
-          'date_last_marked'  => $mysql_now ,
-          'marking_params'    => $xml_parser->generate_xml($xml_array) ,
-        );
-        $DB->do_insert('INSERT INTO ' . APP__DB_TABLE_PREFIX . 'assessment_marking ({fields}) VALUES ({values})', $fields);
-        header("Location: $list_url");
-        exit;
+          $xml_parser = new XMLParser();
+
+          $xml_array['parameters']['weighting']['_attributes'] = ['value'  => $weighting];
+          $xml_array['parameters']['penalty']['_attributes'] = ['value'  => $penalty];
+          $xml_array['parameters']['penalty_type']['_attributes'] = ['value' => $penalty_type];
+
+          //$xml_array['parameters']['tolerance']['_attributes'] = array ( 'value'  => $tolerance );
+          $xml_array['parameters']['grading']['_attributes'] = ['value'  => $grading];
+          $xml_array['parameters']['algorithm']['_attributes'] = ['value'  => $algorithm];
+
+          $mysql_now = date(MYSQL_DATETIME_FORMAT, time());
+
+          $queryBuilder = $DB->getConnection()->createQueryBuilder();
+
+          $queryBuilder
+            ->insert(APP__DB_TABLE_PREFIX . 'assessment_marking')
+            ->values([
+                'assessment_id'     => '?',
+                'date_created'      => '?',
+                'date_last_marked'  => '?',
+                'marking_params'    => '?',
+            ])
+            ->setParameter(0, $assessment_id)
+            ->setParameter(1, $mysql_now)
+            ->setParameter(2, $mysql_now)
+            ->setParameter(3, $xml_parser->generate_xml($xml_array));
+
+          $queryBuilder->execute();
+
+          header("Location: $list_url");
+          exit;
       }
       break;
     // --------------------
@@ -138,11 +148,11 @@
 $UI->page_title = $page_title;
 $UI->menu_selected = 'my assessments';
 $UI->help_link = '?q=node/235';
-$UI->breadcrumbs = array  (
-  'home'        => '../../' ,
-  'my assessments'  => '../' ,
-  'create mark sheet' => null ,
-);
+$UI->breadcrumbs = [
+  'home'        => '../../',
+  'my assessments'  => '../',
+  'create mark sheet' => null,
+];
 
 $UI->set_page_bar_button('List Assessments', '../../../../images/buttons/button_assessment_list.gif', '../');
 $UI->set_page_bar_button('Create Assessments', '../../../../images/buttons/button_assessment_create.gif', '../create/');
@@ -193,21 +203,21 @@ function open_close(id) {
 
 <?php
 if (!$assessment) {
-?>
+    ?>
   <div class="nav_button_bar">
-    <a href="<?php echo($list_url) ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a>
+    <a href="<?php echo $list_url ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a>
   </div>
 
   <p>The assessment you selected could not be loaded for some reason - please go back and try again.</p>
 <?php
 } else {
-?>
+        ?>
 
-  <form action="mark_assessment.php?<?php echo($assessment_qs); ?>" method="post" name="mark_form">
+  <form action="mark_assessment.php?<?php echo $assessment_qs; ?>" method="post" name="mark_form">
   <input type="hidden" name="command" value="none" />
 
   <div class="nav_button_bar">
-    <a href="<?php echo($list_url); ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessment list</a>
+    <a href="<?php echo $list_url; ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessment list</a>
   </div>
 
 
@@ -224,11 +234,10 @@ function open_close(id) {
       <td>
         <select name="pa_weighting" id="pa_weighting">
 <?php
-  for($i=5; $i<=100; $i=$i+5) {
-    $selected = ($i==50) ? 'selected="selected"' : '' ;
-    echo("<option value=\"$i\" $selected> {$i}% </option>\n");
-  }
-?>
+  for ($i=5; $i<=100; $i=$i+5) {
+      $selected = ($i==50) ? 'selected="selected"' : '' ;
+      echo "<option value=\"$i\" $selected> {$i}% </option>\n";
+  } ?>
         </select>
       </td>
     </tr>
@@ -242,11 +251,10 @@ function open_close(id) {
       <td>
         <select name="pa_penalty" id="pa_penalty">
 <?php
-  for($i=$min_penalty; $i<=$max_penalty; $i++) {
-    $selected = ($i==0) ? 'selected="selected"' : '' ;
-    echo("<option value=\"$i\" $selected> {$i}% </option>\n");
-  }
-?>
+  for ($i=$min_penalty; $i<=$max_penalty; $i++) {
+      $selected = ($i==0) ? 'selected="selected"' : '' ;
+      echo "<option value=\"$i\" $selected> {$i}% </option>\n";
+  } ?>
         </select>
       </td>
       <td>of their final grade.</td>
@@ -337,7 +345,7 @@ function open_close(id) {
       // Until we have conducted a full investigation and nailed down what's happening
       // this algorithm is disabled.
       if (false) {
-	      ?>
+          ?>
 	      <tr>
 	        <td><input type="radio" name="pa_algorithm" id="alg_pets" value="pets" /></td>
 	        <td style="padding-bottom: 8px;"><label for="alg_pets">PETS Algorithm
@@ -346,8 +354,7 @@ function open_close(id) {
 	        </td>
 	      </tr>
 	      <?php
-      }
-      ?>
+      } ?>
       </table>
 
     </div>
@@ -361,7 +368,7 @@ function open_close(id) {
 
   </form>
 <?php
-}
+    }
 ?>
 </div>
 
diff --git a/src/tutors/assessments/marks/set_group_marks.php b/src/tutors/assessments/marks/set_group_marks.php
index a026b98..c9dd3fe 100644
--- a/src/tutors/assessments/marks/set_group_marks.php
+++ b/src/tutors/assessments/marks/set_group_marks.php
@@ -7,16 +7,17 @@
  *
  * @link https://github.com/webpa/webpa
  */
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\classes\GroupHandler;
 use WebPA\includes\classes\XMLParser;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -35,39 +36,46 @@
 
 // --------------------------------------------------------------------------------
 
-$group_marks = array();
+$group_marks = [];
 
 $assessment = new Assessment($DB);
 if ($assessment->load($assessment_id)) {
-  $assessment_qs = "a={$assessment->id}&tab={$tab}&y={$year}";
-
-  $group_handler = new GroupHandler();
-  $collection = $group_handler->get_collection($assessment->get_collection_id());
-
-  $group_marks_xml = $DB->fetch_value("SELECT group_mark_xml
-                    FROM " . APP__DB_TABLE_PREFIX . "assessment_group_marks
-                    WHERE assessment_id = '{$assessment->id}'");
-
-  $xml_parser = null;
-
-  if ($group_marks_xml) {
-    $xml_parser = new XMLParser();
-    $xml_array = $xml_parser->parse($group_marks_xml);
-
-    if (is_array($xml_array['groups']['group'])) {
-      foreach($xml_array['groups']['group'] as $i => $group) {
-        if (is_array($group)) {
-          if (array_key_exists('_attributes', $group)) {
-            $group_marks[$group['_attributes']['id']] = $group['_attributes']['mark'];
-          } else {
-            $group_marks[$group['id']] = $group['mark'];
-          }
+    $assessment_qs = "a={$assessment->id}&tab={$tab}&y={$year}";
+
+    $group_handler = new GroupHandler();
+    $collection = $group_handler->get_collection($assessment->get_collection_id());
+
+    $groupMarkXmlQuery =
+      'SELECT group_mark_xml ' .
+      'FROM ' . APP__DB_TABLE_PREFIX . 'assessment_group_marks ' .
+      'WHERE assessment_id = ?';
+
+    $group_marks_xml = $DB->getConnection()->fetchOne(
+            $groupMarkXmlQuery,
+            [$assessment->id],
+            [ParameterType::STRING]
+    );
+
+    $xml_parser = null;
+
+    if ($group_marks_xml) {
+        $xml_parser = new XMLParser();
+        $xml_array = $xml_parser->parse($group_marks_xml);
+
+        if (is_array($xml_array['groups']['group'])) {
+            foreach ($xml_array['groups']['group'] as $i => $group) {
+                if (is_array($group)) {
+                    if (array_key_exists('_attributes', $group)) {
+                        $group_marks[$group['_attributes']['id']] = $group['_attributes']['mark'];
+                    } else {
+                        $group_marks[$group['id']] = $group['mark'];
+                    }
+                }
+            }
         }
-      }
     }
-  }
 } else {
-  $assessment = null;
+    $assessment = null;
 }
 
 // --------------------------------------------------------------------------------
@@ -76,51 +84,79 @@
 $errors = null;
 $bad_group_ids = null;
 
-if ( ($command) && ($assessment) ) {
-  switch ($command) {
+if (($command) && ($assessment)) {
+    switch ($command) {
     case 'save':
       $xml_array = null;
 
-      foreach($_POST as $k => $v) {
-        if (strpos($k, 'group_mark_')===0) {
-          $group_id = str_replace('group_mark_','',$k);
-          $mark = trim( str_replace('%','',$v) );
-          if (!is_numeric($mark)) {
-            if (empty($mark)) {
-              $errors[] = "You must enter a score for each group.";
-            } else {
-              $errors[] = "You must enter a score for each group. $v is not a valid score.";
-            }
-
-            $bad_group_ids[] = $group_id; // used to highlight the row later
+      foreach ($_POST as $k => $v) {
+          if (strpos($k, 'group_mark_')===0) {
+              $group_id = str_replace('group_mark_', '', $k);
+              $mark = trim(str_replace('%', '', $v));
+              if (!is_numeric($mark)) {
+                  if (empty($mark)) {
+                      $errors[] = 'You must enter a score for each group.';
+                  } else {
+                      $errors[] = "You must enter a score for each group. $v is not a valid score.";
+                  }
+
+                  $bad_group_ids[] = $group_id; // used to highlight the row later
+              }
+
+              // Add mark to XML we will save
+              $xml_array['groups']['group'][] = ['_attributes'  => ['id' => $group_id,
+                                             'mark' => $mark, ]];
+
+              // Add mark to the array we're gonna check
+              $group_marks[$group_id] = $mark;
           }
-
-          // Add mark to XML we will save
-          $xml_array['groups']['group'][] = array ('_attributes'  => array  ('id' => $group_id ,
-                                             'mark' => $mark ,));
-
-          // Add mark to the array we're gonna check
-          $group_marks[$group_id] = $mark;
-        }
       }
 
       // If there were no errors, save the changes
       if (!$errors) {
+          if (!$xml_parser) {
+              $xml_parser = new XMLParser();
+          }
 
-        if (!$xml_parser) {
-          $xml_parser = new XMLParser();
-        }
+          $xml = $xml_parser->generate_xml($xml_array);
+
+          // first check if the assessment groups marks record exists
+          $dbConn = $DB->getConnection();
 
-        $xml = $xml_parser->generate_xml($xml_array);
+          $existingAssessmentGroupsMarks = $dbConn->fetchOne(
+              'SELECT assessment_id FROM ' . APP__DB_TABLE_PREFIX . 'assessment_group_marks WHERE assessment_id = ?',
+              [$assessment->id],
+              [ParameterType::STRING]
+          );
 
-        $fields = array ('assessment_id'  => $assessment->id ,
-                 'group_mark_xml' => $xml ,);
+          $queryBuilder = $dbConn->createQueryBuilder();
 
-        $DB->do_insert('REPLACE INTO ' . APP__DB_TABLE_PREFIX . 'assessment_group_marks ({fields}) VALUES ({values})',$fields);
+          if ($existingAssessmentGroupsMarks) {
+              // record exists so update it
+              $queryBuilder
+                ->update(APP__DB_TABLE_PREFIX . 'assessment_group_marks')
+                ->set('group_mark_xml', '?')
+                ->where('assessment_id = ?')
+                ->setParameter(0, $xml)
+                ->setParameter(1, $assessment->id);
+          } else {
+              // record does not exist so create it
+              $queryBuilder
+                ->insert(APP__DB_TABLE_PREFIX . 'assessment_group_marks')
+                ->values([
+                    'assessment_id' => '?',
+                    'group_mark_xml' => '?',
+                ])
+                ->setParameter(0, $assessment->id)
+                ->setParameter(1, $xml);
+          }
+
+          $testQuery = $queryBuilder->getSQL();
+          $parameters = $queryBuilder->getParameters();
+          $queryBuilder->execute();
       }
       break;
-    // --------------------
-  }// /switch
+  }
 }
 
 // --------------------------------------------------------------------------------
@@ -131,9 +167,9 @@
 $UI->page_title = APP__NAME . ' ' . $page_title;
 $UI->menu_selected = 'my assessments';
 $UI->help_link = '?q=node/235';
-$UI->breadcrumbs = array  ('home'       => '../../' ,
-               'my assessments' => '../' ,
-               'set group marks'  => null ,);
+$UI->breadcrumbs = ['home'       => '../../',
+               'my assessments' => '../',
+               'set group marks'  => null, ];
 
 $UI->set_page_bar_button('List Assessments', '../../../../images/buttons/button_assessment_list.gif', '../');
 $UI->set_page_bar_button('Create Assessments', '../../../../images/buttons/button_assessment_create.gif', '../create/');
@@ -150,9 +186,9 @@
 
 <?php
   if (is_array($bad_group_ids)) {
-    foreach($bad_group_ids as $i => $group_id) {
-      echo("tr#group_$group_id td { background-color: #fcc; }");
-    }
+      foreach ($bad_group_ids as $i => $group_id) {
+          echo "tr#group_$group_id td { background-color: #fcc; }";
+      }
   }
 ?>
 
@@ -184,23 +220,23 @@ function do_command(com) {
 
 <?php
 if (!$assessment) {
-?>
+    ?>
   <div class="nav_button_bar">
-    <a href="<?php echo($list_url) ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a>
+    <a href="<?php echo $list_url ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a>
   </div>
 
   <p>The assessment you selected could not be loaded for some reason - please go back and try again.</p>
 <?php
 } else {
-?>
+        ?>
 
-  <form action="set_group_marks.php?<?php echo($assessment_qs); ?>" method="post" name="groupmark_form">
+  <form action="set_group_marks.php?<?php echo $assessment_qs; ?>" method="post" name="groupmark_form">
   <input type="hidden" name="command" value="none" />
 
   <div class="nav_button_bar">
     <table cellpadding="0" cellspacing="0" width="100%">
     <tr>
-      <td><a href="<?php echo($list_url); ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessment list</a></td>
+      <td><a href="<?php echo $list_url; ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessment list</a></td>
     </tr>
     </table>
   </div>
@@ -208,16 +244,16 @@ function do_command(com) {
   <h2>Group Marks</h2>
   <div class="form_section">
 <?php
-  echo("<p><label>This assessment is using collection: </label><em>{$collection->name}</em></p>");
+  echo "<p><label>This assessment is using collection: </label><em>{$collection->name}</em></p>";
 
-  $groups = $collection->get_groups_iterator();
+        $groups = $collection->get_groups_iterator();
 
-  if ($groups->size()==0) {
-?>
+        if ($groups->size()==0) {
+            ?>
       <p>This collection does not contain any groups</p>
 <?php
-  } else {
-?>
+        } else {
+            ?>
       <table class="grid" cellpadding="5" cellspacing="1">
       <tr>
         <th>Group</th>
@@ -225,34 +261,33 @@ function do_command(com) {
         <th>Group Mark</th>
       </tr>
 <?php
-    for($groups->reset(); $groups->is_valid(); $groups->next()) {
-      $group =& $groups->current();
-      $group_members = $group->get_members();
-      $members = ($group_members) ? $CIS->get_user(array_keys($group_members)) : null;
-
-      $group_mark = (array_key_exists($group->id, $group_marks)) ? $group_marks["$group->id"] : '';
-
-      echo("<tr id=\"group_{$group->id}\">");
-      echo("<td><label for=\"group_mark_{$group->id}\">{$group->name}</label></td>");
-      echo('<td style="text-align: left">');
-      if (!$members) {
-        echo('-');
-      } else {
-        foreach($members as $i => $member) {
-          echo("{$member['lastname']}, {$member['forename']}");
-          if (!empty($member['id_number'])) {
-            echo(" &nbsp; <span class=\"id_number\">({$member['id_number']})</span>");
-          }
-          echo("<br />");
+    for ($groups->reset(); $groups->is_valid(); $groups->next()) {
+        $group =& $groups->current();
+        $group_members = $group->get_members();
+        $members = ($group_members) ? $CIS->get_user(array_keys($group_members)) : null;
+
+        $group_mark = (array_key_exists($group->id, $group_marks)) ? $group_marks["$group->id"] : '';
+
+        echo "<tr id=\"group_{$group->id}\">";
+        echo "<td><label for=\"group_mark_{$group->id}\">{$group->name}</label></td>";
+        echo '<td style="text-align: left">';
+        if (!$members) {
+            echo '-';
+        } else {
+            foreach ($members as $i => $member) {
+                echo "{$member['lastname']}, {$member['forename']}";
+                if (!empty($member['id_number'])) {
+                    echo " &nbsp; <span class=\"id_number\">({$member['id_number']})</span>";
+                }
+                echo '<br />';
+            }
         }
-      }
-      echo('</td>');
-      echo("<td><input type=\"text\" name=\"group_mark_{$group->id}\" id=\"group_mark_{$group->id}\" size=\"4\" maxlength=\"5\" value=\"$group_mark\" /> %</td>");
-      echo('</tr>');
+        echo '</td>';
+        echo "<td><input type=\"text\" name=\"group_mark_{$group->id}\" id=\"group_mark_{$group->id}\" size=\"4\" maxlength=\"5\" value=\"$group_mark\" /> %</td>";
+        echo '</tr>';
     }
-    echo('</table>');
-  }
-?>
+            echo '</table>';
+        } ?>
   </div>
 
   <div style="text-align: center">
@@ -261,7 +296,7 @@ function do_command(com) {
 
   </form>
 <?php
-}
+    }
 ?>
 </div>
 
diff --git a/src/tutors/assessments/reports/index.php b/src/tutors/assessments/reports/index.php
index b529a5e..20ea7f3 100644
--- a/src/tutors/assessments/reports/index.php
+++ b/src/tutors/assessments/reports/index.php
@@ -8,8 +8,9 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\classes\Form;
 use WebPA\includes\classes\GroupHandler;
@@ -17,9 +18,9 @@
 use WebPA\includes\classes\XMLParser;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -43,68 +44,71 @@
 
 $assessment = new Assessment($DB);
 if ($assessment->load($assessment_id)) {
-  $do_reports = true;
-  $assessment_qs = "a={$assessment->id}&tab={$tab}&y={$year}";
+    $do_reports = true;
+    $assessment_qs = "a={$assessment->id}&tab={$tab}&y={$year}";
+
+    $form = new Form($DB);
+    $form_xml = $assessment->get_form_xml();
+    $form->load_from_xml($form_xml);
+    $question_count = (int) $form->get_question_count();
 
-  $form = new Form($DB);
-  $form_xml = $assessment->get_form_xml();
-  $form->load_from_xml($form_xml);
-  $question_count = (int) $form->get_question_count();
+    $group_handler = new GroupHandler();
+    $collection = $group_handler->get_collection($assessment->get_collection_id());
+    $groups = $collection->get_groups_array();
+    $groups_count = count($groups);
 
-  $group_handler = new GroupHandler();
-  $collection = $group_handler->get_collection($assessment->get_collection_id());
-  $groups = $collection->get_groups_array();
-  $groups_count = count($groups);
+    $result_handler = new ResultHandler($DB);
+    $result_handler->set_assessment($assessment);
 
-  $result_handler = new ResultHandler($DB);
-  $result_handler->set_assessment($assessment);
+    // check if there are group grades
+    $groupMarksQuery =
+      'SELECT group_mark_xml ' .
+      'FROM ' . APP__DB_TABLE_PREFIX . 'assessment_group_marks ' .
+      'WHERE assessment_id = ?';
 
-  // check if there are group grades
-  $group_marks_xml = $DB->fetch_value("SELECT group_mark_xml
-                    FROM " . APP__DB_TABLE_PREFIX . "assessment_group_marks
-                    WHERE assessment_id = '{$assessment->id}';");
+    $group_marks_xml = $DB->getConnection()->fetchOne($groupMarksQuery, [$assessment->id], [ParameterType::STRING]);
 
-  $xml_parser = null;
+    $xml_parser = null;
 
-  $do_all_reports = true;
+    $do_all_reports = true;
 
-  if ($group_marks_xml) {
-    $xml_parser = new XMLParser();
-    $xml_array = $xml_parser->parse($group_marks_xml);
+    if ($group_marks_xml) {
+        $xml_parser = new XMLParser();
+        $xml_array = $xml_parser->parse($group_marks_xml);
 
-    // If there's more than 1 group that's fine, else make it a 0-based array of 1 group
-    if (array_key_exists(0, $xml_array['groups']['group'])) {
-      $groups = $xml_array['groups']['group'];
+        // If there's more than 1 group that's fine, else make it a 0-based array of 1 group
+        if (array_key_exists(0, $xml_array['groups']['group'])) {
+            $groups = $xml_array['groups']['group'];
+        } else {
+            $groups[0] = $xml_array['groups']['group'];
+        }
+        foreach ($groups as $i => $group) {
+            $group_marks["{$group['_attributes']['id']}"] = $group['_attributes']['mark'];
+        }
     } else {
-      $groups[0] = $xml_array['groups']['group'];
+        $do_reports = true;
+        $do_all_reports = false;
+        $no_reports_reason = 'You have not recorded the group marks for this assessment so some reports are not available.<br />Please <a href="../marks/set_group_marks.php?'. $qs .'">enter the overall group marks</a> before viewing your reports.';
     }
-    foreach($groups as $i => $group) {
-      $group_marks["{$group['_attributes']['id']}"] = $group['_attributes']['mark'];
-    }
-  } else {
-    $do_reports = true;
-    $do_all_reports = false;
-    $no_reports_reason = 'You have not recorded the group marks for this assessment so some reports are not available.<br />Please <a href="../marks/set_group_marks.php?'. $qs .'">enter the overall group marks</a> before viewing your reports.';
-  }
 
-  // check if there are student responses
-  $result_handler = new ResultHandler($DB);
-  $result_handler->set_assessment($assessment);
-  $responses = $result_handler->get_responses();
-  if (!$responses) {
-    $do_reports = false;
-    $no_reports_reason = 'There have been no student responses to this assessment. Please select another assessment, or <a href="../edit/edit_assessment.php?'. $qs .'">re-schedule this one</a>.';
-  }
+    // check if there are student responses
+    $result_handler = new ResultHandler($DB);
+    $result_handler->set_assessment($assessment);
+    $responses = $result_handler->get_responses();
+    if (!$responses) {
+        $do_reports = false;
+        $no_reports_reason = 'There have been no student responses to this assessment. Please select another assessment, or <a href="../edit/edit_assessment.php?'. $qs .'">re-schedule this one</a>.';
+    }
 
-  // Get the marking parameters
-  $marking_params = $assessment->get_marking_params($marking_date);
+    // Get the marking parameters
+    $marking_params = $assessment->get_marking_params($marking_date);
 } else {
-  $do_reports = false;
-  $no_reports_reason = 'The assessment you selected could not be loaded for some reason. Please go back and try again.';
+    $do_reports = false;
+    $no_reports_reason = 'The assessment you selected could not be loaded for some reason. Please go back and try again.';
 
-  $assessment = null;
-  $question_count = 0;
-  $groups_count = 0;
+    $assessment = null;
+    $question_count = 0;
+    $groups_count = 0;
 }
 
 // --------------------------------------------------------------------------------
@@ -114,11 +118,11 @@
 
 $UI->page_title = APP__NAME . ' ' . $page_title;
 $UI->menu_selected = 'my assessments';
-$UI->breadcrumbs = array (
-  'home'          => '../../' ,
-  'my assessments'    => '../' ,
-  $page_title       => null ,
-);
+$UI->breadcrumbs = [
+  'home'          => '../../',
+  'my assessments'    => '../',
+  $page_title       => null,
+];
 $UI->help_link = '?q=node/235';
 $UI->set_page_bar_button('List Assessments', '../../../../images/buttons//button_assessment_list.gif', '../');
 $UI->set_page_bar_button('Create Assessments', '../../../../images/buttons/button_assessment_create.gif', '../../create/');
@@ -146,30 +150,28 @@
 <div class="content_box">
 
 <div class="nav_button_bar">
-  <a href="<?php echo($list_url) ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a>
+  <a href="<?php echo $list_url ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a>
 </div>
 
-<p>Reports available for: <em><?php echo($assessment->name)?></em>.</p>
+<p>Reports available for: <em><?php echo $assessment->name?></em>.</p>
 
 <?php
 if ($marking_params) {
-  $penalty_type = ($marking_params['penalty_type']=='pp') ? ' pp' : '%' ;   // Add a space to the 'pp'.
-?>
+    $penalty_type = ($marking_params['penalty_type']=='pp') ? ' pp' : '%' ;   // Add a space to the 'pp'.?>
   <p style="padding-left: 1em; font-size: 0.8em;">
     (
-    Algorithm: <?php echo($marking_params['algorithm']); ?>. &nbsp;
+    Algorithm: <?php echo $marking_params['algorithm']; ?>. &nbsp;
 
-    Weighting: <?php echo($marking_params['weighting']); ?>%. &nbsp;
+    Weighting: <?php echo $marking_params['weighting']; ?>%. &nbsp;
 
-    Penalty: <?php echo($marking_params['penalty'].$penalty_type); ?>. &nbsp;
+    Penalty: <?php echo $marking_params['penalty'].$penalty_type; ?>. &nbsp;
 
     Grading: <?php
       if ($marking_params['grading']=='grade_af') {
-        echo('A-F.');
+          echo 'A-F.';
       } else {
-        echo('Numeric (%).');
-      }
-?>
+          echo 'Numeric (%).';
+      } ?>
     )
   </p>
 <?php
@@ -178,14 +180,14 @@
 
 <?php
 if (!$do_reports) {
-?>
+    ?>
   <div class="warning_box">
     <p><strong>Unable to display reports</strong></p>
-    <p><?php echo($no_reports_reason); ?></p>
+    <p><?php echo $no_reports_reason; ?></p>
   </div>
 <?php
 } else {
-?>
+        ?>
 <h2>Choose a report</h2>
 <div class="form_section">
   <p>Please select a report to display or download from the list below.</p>
@@ -199,11 +201,11 @@
       </td>
       <td class="downloads" nowrap="nowrap" valign="top">
         <div>View Report:</div>
-        <a href="report_marks_awarded_byquestion_named.php?t=view&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/report.png" width="32" height="32" alt="Report - View the report" /></a>
+        <a href="report_marks_awarded_byquestion_named.php?t=view&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/report.png" width="32" height="32" alt="Report - View the report" /></a>
       </td>
       <td class="downloads" valign="top">
         <div>Download:</div>
-        <a href="report_marks_awarded_byquestion_named.php?t=download-csv&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/csv.gif" width="32" height="32" alt="CSV - Excel Spreadsheet" /></a>
+        <a href="report_marks_awarded_byquestion_named.php?t=download-csv&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/csv.gif" width="32" height="32" alt="CSV - Excel Spreadsheet" /></a>
       </td>
     </tr>
     </table>
@@ -218,11 +220,11 @@
       </td>
       <td class="downloads" nowrap="nowrap" valign="top">
         <div>View Report:</div>
-        <a  href="report_marks_awarded_byquestion_anonymous.php?t=view&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/report.png" width="32" height="32" alt="Report - View the report" /></a>
+        <a  href="report_marks_awarded_byquestion_anonymous.php?t=view&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/report.png" width="32" height="32" alt="Report - View the report" /></a>
       </td>
       <td class="downloads" valign="top">
         <div>Download:</div>
-        <a href="report_marks_awarded_byquestion_anonymous.php?t=download-csv&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/csv.gif" width="32" height="32" alt="CSV - Excel Spreadsheet" /></a>
+        <a href="report_marks_awarded_byquestion_anonymous.php?t=download-csv&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/csv.gif" width="32" height="32" alt="CSV - Excel Spreadsheet" /></a>
       </td>
     </tr>
     </table>
@@ -237,11 +239,11 @@
       </td>
       <td class="downloads" nowrap="nowrap" valign="top">
         <div>View Report</div>
-        <a href="report_student_response_info.php?t=view&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/report.png" width="32" height="32" alt="Report - View the report" /></a>
+        <a href="report_student_response_info.php?t=view&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/report.png" width="32" height="32" alt="Report - View the report" /></a>
       </td>
       <td class="downloads" valign="top">
         <div>Download:</div>
-        <a href="report_student_response_info.php?t=download-csv&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/csv.gif" width="32" height="32" alt="CSV - Excel Spreadsheet" /></a>
+        <a href="report_student_response_info.php?t=download-csv&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/csv.gif" width="32" height="32" alt="CSV - Excel Spreadsheet" /></a>
       </td>
     </tr>
     </table>
@@ -249,14 +251,14 @@
 
 <?php
   if (!$do_all_reports) {
-?>
+      ?>
     <div class="warning_box">
       <p><strong>Unable to display the other reports</strong></p>
-      <p><?php echo($no_reports_reason); ?></p>
+      <p><?php echo $no_reports_reason; ?></p>
     </div>
 <?php
   } else {
-?>
+      ?>
 
     <div class="report">
       <table cellpadding="2" cellspacing="2" width="100%">
@@ -267,29 +269,28 @@
         </td>
         <td class="downloads"  nowrap="nowrap"  valign="top">
           <div>View Report:</div>
-          <a href="report_student_grades.php?t=view&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/report.png" width="32" height="32" alt="Report - View the report" /></a>
+          <a href="report_student_grades.php?t=view&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/report.png" width="32" height="32" alt="Report - View the report" /></a>
         </td>
         <td class="downloads" valign="top">
           <div>Download:</div>
-          <a href="report_student_grades.php?t=download-csv&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/csv.gif" width="32" height="32" alt="CSV - Excel Spreadsheet" /></a>
+          <a href="report_student_grades.php?t=download-csv&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/csv.gif" width="32" height="32" alt="CSV - Excel Spreadsheet" /></a>
         </td>
         <td class="downloads" valign="top">
           <div>Download:</div>
-          <a href="report_student_grades.php?t=download-xml&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/xml.gif" width="32" height="32" alt="XML -  XML File" /></a>
+          <a href="report_student_grades.php?t=download-xml&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/xml.gif" width="32" height="32" alt="XML -  XML File" /></a>
         </td>
         <?php
-        if (APP__MOODLE_GRADEBOOK){
-        ?>
+        if (APP__MOODLE_GRADEBOOK) {
+            ?>
         <td class="downloads" valign="top">
           <div>Download:</div>
-          <a href="report_student_grades.php?t=download-moodle-xml&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/moodle.gif" width="32" height="32" alt="Moodle - Moodle Gradebook Import XML" /></a>
+          <a href="report_student_grades.php?t=download-moodle-xml&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/moodle.gif" width="32" height="32" alt="Moodle - Moodle Gradebook Import XML" /></a>
         </td>
         <?php
-        }
-        ?>
+        } ?>
         <td class="downloads" valign="top">
           <div>Download:</div>
-          <a href="report_student_grades.php?t=download-rtf&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/page_white_word.png" width="32" height="32" alt="RTF -  Rich Text File / MS Word" /></a>
+          <a href="report_student_grades.php?t=download-rtf&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/page_white_word.png" width="32" height="32" alt="RTF -  Rich Text File / MS Word" /></a>
         </td>
       </tr>
       </table>
@@ -304,27 +305,27 @@
         </td>
         <td class="downloads" nowrap="nowrap" valign="top">
           <div>View Report:</div>
-          <a href="report_student_grades_bygroup.php?t=view&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/report.png" width="32" height="32" alt="Report - View the report" /></a>
+          <a href="report_student_grades_bygroup.php?t=view&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/report.png" width="32" height="32" alt="Report - View the report" /></a>
         </td>
         <td class="downloads" valign="top">
           <div>Download:</div>
-          <a href="report_student_grades_bygroup.php?t=download-csv&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/csv.gif" width="32" height="32" alt="CSV - Excel Spreadsheet" /></a>
+          <a href="report_student_grades_bygroup.php?t=download-csv&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/csv.gif" width="32" height="32" alt="CSV - Excel Spreadsheet" /></a>
         </td>
         <td class="downloads" valign="top">
           <div>Download:</div>
-          <a href="report_student_grades_bygroup.php?t=download-xml&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/xml.gif" width="32" height="32" alt="XML -  XML File" /></a>
+          <a href="report_student_grades_bygroup.php?t=download-xml&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/xml.gif" width="32" height="32" alt="XML -  XML File" /></a>
         </td>
         <td class="downloads" valign="top">
           <div>Download:</div>
-          <a href="report_student_grades_bygroup.php?t=download-rtf&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/page_white_word.png" width="32" height="32" alt="RTF -  Rich Text File / MS Word" /></a>
+          <a href="report_student_grades_bygroup.php?t=download-rtf&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/page_white_word.png" width="32" height="32" alt="RTF -  Rich Text File / MS Word" /></a>
         </td>
       </tr>
       </table>
     </div>
 <?php
     if (APP__ALLOW_TEXT_INPUT) {
-      if ($assessment->allow_assessment_feedback) {
-?>
+        if ($assessment->allow_assessment_feedback) {
+            ?>
     <div class="report">
       <table cellpadding="2" cellspacing="2" width="100%">
       <tr>
@@ -334,11 +335,11 @@
         </td>
         <td class="downloads" nowrap="nowrap" valign="top">
           <div>View Report:</div>
-          <a href="report_student_feedback_bygroup.php?t=view&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/report.png" width="32" height="32" alt="Report - View the report" /></a>
+          <a href="report_student_feedback_bygroup.php?t=view&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/report.png" width="32" height="32" alt="Report - View the report" /></a>
         </td>
         <td class="downloads" valign="top">
           <div>Download:</div>
-          <a href="report_student_feedback_bygroup.php?t=download-csv&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/csv.gif" width="32" height="32" alt="CSV - Excel Spreadsheet" /></a>
+          <a href="report_student_feedback_bygroup.php?t=download-csv&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/csv.gif" width="32" height="32" alt="CSV - Excel Spreadsheet" /></a>
         </td>
       </tr>
       </table>
@@ -352,18 +353,17 @@
         </td>
         <td class="downloads" valign="top">
           <div>Download:</div>
-          <a href="report_student_grades_comments.php?t=download-csv&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/csv.gif" width="32" height="32" alt="CSV - Excel Spreadsheet" /></a>
+          <a href="report_student_grades_comments.php?t=download-csv&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/csv.gif" width="32" height="32" alt="CSV - Excel Spreadsheet" /></a>
         </td>
       </tr>
       </table>
     </div>
 <?php
-      }
+        }
     }
   }
 
-// output the reports as requested from the UEA, UK -- Source forge request id 2042746
-?>
+        // output the reports as requested from the UEA, UK -- Source forge request id 2042746?>
 <hr>
   <div class="report">
     <table cellpadding="2" cellspacing="2" width="100%">
@@ -374,21 +374,21 @@
       </td>
       <td class="downloads" nowrap="nowrap" valign="top">
         <div>View Report:</div>
-        <a href="report_uea.php?t=view&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/report.png" width="32" height="32" alt="Report - View the report" /></a>
+        <a href="report_uea.php?t=view&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/report.png" width="32" height="32" alt="Report - View the report" /></a>
       </td>
       <td class="downloads" valign="top">
         <div>Download:</div>
-        <a href="report_uea.php?t=download-csv&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/csv.gif" width="32" height="32" alt="CSV - Excel Spreadsheet" /></a>
+        <a href="report_uea.php?t=download-csv&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/csv.gif" width="32" height="32" alt="CSV - Excel Spreadsheet" /></a>
       </td>
       <!--
       <td class="downloads" valign="top">
         <div>Download:</div>
-        <a href="report_student_grades_bygroup.php?t=download-xml&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/xml.gif" width="32" height="32" alt="XML -  XML File" /></a>
+        <a href="report_student_grades_bygroup.php?t=download-xml&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/xml.gif" width="32" height="32" alt="XML -  XML File" /></a>
       </td>
       -->
       <td class="downloads" valign="top">
         <div>Download:</div>
-        <a href="report_uea.php?t=download-rtf&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/page_white_word.png" width="32" height="32" alt="RTF -  Rich Text File / MS Word" /></a>
+        <a href="report_uea.php?t=download-rtf&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/page_white_word.png" width="32" height="32" alt="RTF -  Rich Text File / MS Word" /></a>
       </td>
 
     </tr>
@@ -403,28 +403,28 @@
       </td>
       <td class="downloads" nowrap="nowrap" valign="top">
         <div>View Report:</div>
-        <a href="report_uea_anonymous.php?t=view&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/report.png" width="32" height="32" alt="Report - View the report" /></a>
+        <a href="report_uea_anonymous.php?t=view&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/report.png" width="32" height="32" alt="Report - View the report" /></a>
       </td>
       <td class="downloads" valign="top">
         <div>Download:</div>
-        <a href="report_uea_anonymous.php?t=download-csv&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/csv.gif" width="32" height="32" alt="CSV - Excel Spreadsheet" /></a>
+        <a href="report_uea_anonymous.php?t=download-csv&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/csv.gif" width="32" height="32" alt="CSV - Excel Spreadsheet" /></a>
       </td>
       <!--
       <td class="downloads" valign="top">
         <div>Download:</div>
-        <a href="report_student_grades_bygroup.php?t=download-xml&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/xml.gif" width="32" height="32" alt="XML -  XML File" /></a>
+        <a href="report_student_grades_bygroup.php?t=download-xml&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/xml.gif" width="32" height="32" alt="XML -  XML File" /></a>
       </td>
       -->
       <td class="downloads" valign="top">
         <div>Download:</div>
-        <a href="report_uea_anonymous.php?t=download-rtf&<?php echo($qs); ?>" target="_blank"><img src="../../../images/file_icons/page_white_word.png" width="32" height="32" alt="RTF -  Rich Text File / MS Word" /></a>
+        <a href="report_uea_anonymous.php?t=download-rtf&<?php echo $qs; ?>" target="_blank"><img src="../../../images/file_icons/page_white_word.png" width="32" height="32" alt="RTF -  Rich Text File / MS Word" /></a>
       </td>
 
     </tr>
     </table>
   </div>
 <?php
-}
+    }
 ?>
 </div>
 
diff --git a/src/tutors/assessments/reports/report_demo.php b/src/tutors/assessments/reports/report_demo.php
index a1bed79..c323579 100644
--- a/src/tutors/assessments/reports/report_demo.php
+++ b/src/tutors/assessments/reports/report_demo.php
@@ -8,16 +8,16 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\classes\NewAlgorithm;
 use WebPA\includes\classes\XMLParser;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -42,131 +42,129 @@
 
 $assessment = new Assessment($DB);
 if ($assessment->load($assessment_id)) {
-
-  $xml_parser = new XMLParser();
-
-  // ----------------------------------------
-  // Get the marking parameters used for the marksheet this report will display
-
-  $marking_params['weighting']= 100;
-  $marking_params['penalty'] = 0;
-
-  // ----------------------------------------
-  // Get a list of the groups, and their marks, used in this assessment
-
-  $groups_and_marks['G1'] = 80;
-
-  // ----------------------------------------
-  // Get a list of the members who took this assessment (grouped by 'group')
-
-  $group_members['G1'] = array  ('S1' ,
-                   'S2' ,
-                   'S3' ,
-                   'S4' ,);
-
-  // ----------------------------------------
-  // Get the questions used in this assessment
-
-  $questions = range(0, 4);
-
-  // ----------------------------------------
-  // Get the student submissions for this assessment
-
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S1', 'marked_user_id' => 'S1', 'question_id' => 0, 'score' => 4 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S1', 'marked_user_id' => 'S1', 'question_id' => 1, 'score' => 4 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S1', 'marked_user_id' => 'S1', 'question_id' => 2, 'score' => 4 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S1', 'marked_user_id' => 'S1', 'question_id' => 3, 'score' => 4 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S1', 'marked_user_id' => 'S1', 'question_id' => 4, 'score' => 4 );
-
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S1', 'marked_user_id' => 'S2', 'question_id' => 0, 'score' => 3 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S1', 'marked_user_id' => 'S2', 'question_id' => 1, 'score' => 3 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S1', 'marked_user_id' => 'S2', 'question_id' => 2, 'score' => 3 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S1', 'marked_user_id' => 'S2', 'question_id' => 3, 'score' => 3 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S1', 'marked_user_id' => 'S2', 'question_id' => 4, 'score' => 3 );
-
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S1', 'marked_user_id' => 'S3', 'question_id' => 0, 'score' => 2 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S1', 'marked_user_id' => 'S3', 'question_id' => 1, 'score' => 2 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S1', 'marked_user_id' => 'S3', 'question_id' => 2, 'score' => 2 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S1', 'marked_user_id' => 'S3', 'question_id' => 3, 'score' => 2 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S1', 'marked_user_id' => 'S3', 'question_id' => 4, 'score' => 2 );
-
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S1', 'marked_user_id' => 'S4', 'question_id' => 0, 'score' => 1 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S1', 'marked_user_id' => 'S4', 'question_id' => 1, 'score' => 1 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S1', 'marked_user_id' => 'S4', 'question_id' => 2, 'score' => 1 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S1', 'marked_user_id' => 'S4', 'question_id' => 3, 'score' => 1 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S1', 'marked_user_id' => 'S4', 'question_id' => 4, 'score' => 1 );
-  // ==========
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S2', 'marked_user_id' => 'S1', 'question_id' => 0, 'score' => 1 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S2', 'marked_user_id' => 'S1', 'question_id' => 1, 'score' => 2 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S2', 'marked_user_id' => 'S1', 'question_id' => 2, 'score' => 3 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S2', 'marked_user_id' => 'S1', 'question_id' => 3, 'score' => 4 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S2', 'marked_user_id' => 'S1', 'question_id' => 4, 'score' => 5 );
-
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S2', 'marked_user_id' => 'S2', 'question_id' => 0, 'score' => 5 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S2', 'marked_user_id' => 'S2', 'question_id' => 1, 'score' => 1 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S2', 'marked_user_id' => 'S2', 'question_id' => 2, 'score' => 2 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S2', 'marked_user_id' => 'S2', 'question_id' => 3, 'score' => 3 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S2', 'marked_user_id' => 'S2', 'question_id' => 4, 'score' => 4 );
-
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S2', 'marked_user_id' => 'S3', 'question_id' => 0, 'score' => 4 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S2', 'marked_user_id' => 'S3', 'question_id' => 1, 'score' => 5 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S2', 'marked_user_id' => 'S3', 'question_id' => 2, 'score' => 1 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S2', 'marked_user_id' => 'S3', 'question_id' => 3, 'score' => 2 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S2', 'marked_user_id' => 'S3', 'question_id' => 4, 'score' => 3 );
-
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S2', 'marked_user_id' => 'S4', 'question_id' => 0, 'score' => 3 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S2', 'marked_user_id' => 'S4', 'question_id' => 1, 'score' => 4 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S2', 'marked_user_id' => 'S4', 'question_id' => 2, 'score' => 5 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S2', 'marked_user_id' => 'S4', 'question_id' => 3, 'score' => 1 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S2', 'marked_user_id' => 'S4', 'question_id' => 4, 'score' => 2 );
-  // ==========
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S4', 'marked_user_id' => 'S1', 'question_id' => 0, 'score' => 1 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S4', 'marked_user_id' => 'S1', 'question_id' => 1, 'score' => 1 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S4', 'marked_user_id' => 'S1', 'question_id' => 2, 'score' => 1 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S4', 'marked_user_id' => 'S1', 'question_id' => 3, 'score' => 1 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S4', 'marked_user_id' => 'S1', 'question_id' => 4, 'score' => 1 );
-
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S4', 'marked_user_id' => 'S2', 'question_id' => 0, 'score' => 1 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S4', 'marked_user_id' => 'S2', 'question_id' => 1, 'score' => 1 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S4', 'marked_user_id' => 'S2', 'question_id' => 2, 'score' => 1 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S4', 'marked_user_id' => 'S2', 'question_id' => 3, 'score' => 1 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S4', 'marked_user_id' => 'S2', 'question_id' => 4, 'score' => 1 );
-
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S4', 'marked_user_id' => 'S3', 'question_id' => 0, 'score' => 1 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S4', 'marked_user_id' => 'S3', 'question_id' => 1, 'score' => 1 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S4', 'marked_user_id' => 'S3', 'question_id' => 2, 'score' => 1 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S4', 'marked_user_id' => 'S3', 'question_id' => 3, 'score' => 1 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S4', 'marked_user_id' => 'S3', 'question_id' => 4, 'score' => 1 );
-
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S4', 'marked_user_id' => 'S4', 'question_id' => 0, 'score' => 5 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S4', 'marked_user_id' => 'S4', 'question_id' => 1, 'score' => 5 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S4', 'marked_user_id' => 'S4', 'question_id' => 2, 'score' => 5 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S4', 'marked_user_id' => 'S4', 'question_id' => 3, 'score' => 5 );
-  $responses[] = array ( 'group_id' => 'G1' , 'user_id' => 'S4', 'marked_user_id' => 'S4', 'question_id' => 4, 'score' => 5 );
-
-  // ----------------------------------------
-  $algorithm = new NewAlgorithm();
-  $algorithm->set_marking_params($marking_params);
-  $algorithm->set_groups($groups_and_marks);
-  $algorithm->set_group_members($group_members);
-  $algorithm->set_questions($questions);
-  $algorithm->set_responses($responses);
-
-  $algorithm->calculate();
-
-  $webpa_scores = $algorithm->get_webpa_scores();
-  $grades = $algorithm->get_grades();
-  $submissions = $algorithm->get_members_submitting();
-
-  $member_ids = array_keys($webpa_scores);
-
-  $member_names['S1'] = array ( 'user_id' => 'S1', 'lastname' => 'Student 1', 'forename' => '', 'id_number' => 'S1' );
-  $member_names['S2'] = array ( 'user_id' => 'S2', 'lastname' => 'Student 2', 'forename' => '', 'id_number' => 'S2' );
-  $member_names['S3'] = array ( 'user_id' => 'S3', 'lastname' => 'Student 3', 'forename' => '', 'id_number' => 'S3' );
-  $member_names['S4'] = array ( 'user_id' => 'S4', 'lastname' => 'Student 4', 'forename' => '', 'id_number' => 'S4' );
-
+    $xml_parser = new XMLParser();
+
+    // ----------------------------------------
+    // Get the marking parameters used for the marksheet this report will display
+
+    $marking_params['weighting']= 100;
+    $marking_params['penalty'] = 0;
+
+    // ----------------------------------------
+    // Get a list of the groups, and their marks, used in this assessment
+
+    $groups_and_marks['G1'] = 80;
+
+    // ----------------------------------------
+    // Get a list of the members who took this assessment (grouped by 'group')
+
+    $group_members['G1'] = ['S1',
+                   'S2',
+                   'S3',
+                   'S4', ];
+
+    // ----------------------------------------
+    // Get the questions used in this assessment
+
+    $questions = range(0, 4);
+
+    // ----------------------------------------
+    // Get the student submissions for this assessment
+
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S1', 'marked_user_id' => 'S1', 'question_id' => 0, 'score' => 4];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S1', 'marked_user_id' => 'S1', 'question_id' => 1, 'score' => 4];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S1', 'marked_user_id' => 'S1', 'question_id' => 2, 'score' => 4];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S1', 'marked_user_id' => 'S1', 'question_id' => 3, 'score' => 4];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S1', 'marked_user_id' => 'S1', 'question_id' => 4, 'score' => 4];
+
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S1', 'marked_user_id' => 'S2', 'question_id' => 0, 'score' => 3];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S1', 'marked_user_id' => 'S2', 'question_id' => 1, 'score' => 3];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S1', 'marked_user_id' => 'S2', 'question_id' => 2, 'score' => 3];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S1', 'marked_user_id' => 'S2', 'question_id' => 3, 'score' => 3];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S1', 'marked_user_id' => 'S2', 'question_id' => 4, 'score' => 3];
+
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S1', 'marked_user_id' => 'S3', 'question_id' => 0, 'score' => 2];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S1', 'marked_user_id' => 'S3', 'question_id' => 1, 'score' => 2];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S1', 'marked_user_id' => 'S3', 'question_id' => 2, 'score' => 2];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S1', 'marked_user_id' => 'S3', 'question_id' => 3, 'score' => 2];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S1', 'marked_user_id' => 'S3', 'question_id' => 4, 'score' => 2];
+
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S1', 'marked_user_id' => 'S4', 'question_id' => 0, 'score' => 1];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S1', 'marked_user_id' => 'S4', 'question_id' => 1, 'score' => 1];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S1', 'marked_user_id' => 'S4', 'question_id' => 2, 'score' => 1];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S1', 'marked_user_id' => 'S4', 'question_id' => 3, 'score' => 1];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S1', 'marked_user_id' => 'S4', 'question_id' => 4, 'score' => 1];
+    // ==========
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S2', 'marked_user_id' => 'S1', 'question_id' => 0, 'score' => 1];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S2', 'marked_user_id' => 'S1', 'question_id' => 1, 'score' => 2];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S2', 'marked_user_id' => 'S1', 'question_id' => 2, 'score' => 3];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S2', 'marked_user_id' => 'S1', 'question_id' => 3, 'score' => 4];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S2', 'marked_user_id' => 'S1', 'question_id' => 4, 'score' => 5];
+
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S2', 'marked_user_id' => 'S2', 'question_id' => 0, 'score' => 5];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S2', 'marked_user_id' => 'S2', 'question_id' => 1, 'score' => 1];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S2', 'marked_user_id' => 'S2', 'question_id' => 2, 'score' => 2];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S2', 'marked_user_id' => 'S2', 'question_id' => 3, 'score' => 3];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S2', 'marked_user_id' => 'S2', 'question_id' => 4, 'score' => 4];
+
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S2', 'marked_user_id' => 'S3', 'question_id' => 0, 'score' => 4];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S2', 'marked_user_id' => 'S3', 'question_id' => 1, 'score' => 5];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S2', 'marked_user_id' => 'S3', 'question_id' => 2, 'score' => 1];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S2', 'marked_user_id' => 'S3', 'question_id' => 3, 'score' => 2];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S2', 'marked_user_id' => 'S3', 'question_id' => 4, 'score' => 3];
+
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S2', 'marked_user_id' => 'S4', 'question_id' => 0, 'score' => 3];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S2', 'marked_user_id' => 'S4', 'question_id' => 1, 'score' => 4];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S2', 'marked_user_id' => 'S4', 'question_id' => 2, 'score' => 5];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S2', 'marked_user_id' => 'S4', 'question_id' => 3, 'score' => 1];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S2', 'marked_user_id' => 'S4', 'question_id' => 4, 'score' => 2];
+    // ==========
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S4', 'marked_user_id' => 'S1', 'question_id' => 0, 'score' => 1];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S4', 'marked_user_id' => 'S1', 'question_id' => 1, 'score' => 1];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S4', 'marked_user_id' => 'S1', 'question_id' => 2, 'score' => 1];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S4', 'marked_user_id' => 'S1', 'question_id' => 3, 'score' => 1];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S4', 'marked_user_id' => 'S1', 'question_id' => 4, 'score' => 1];
+
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S4', 'marked_user_id' => 'S2', 'question_id' => 0, 'score' => 1];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S4', 'marked_user_id' => 'S2', 'question_id' => 1, 'score' => 1];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S4', 'marked_user_id' => 'S2', 'question_id' => 2, 'score' => 1];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S4', 'marked_user_id' => 'S2', 'question_id' => 3, 'score' => 1];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S4', 'marked_user_id' => 'S2', 'question_id' => 4, 'score' => 1];
+
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S4', 'marked_user_id' => 'S3', 'question_id' => 0, 'score' => 1];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S4', 'marked_user_id' => 'S3', 'question_id' => 1, 'score' => 1];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S4', 'marked_user_id' => 'S3', 'question_id' => 2, 'score' => 1];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S4', 'marked_user_id' => 'S3', 'question_id' => 3, 'score' => 1];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S4', 'marked_user_id' => 'S3', 'question_id' => 4, 'score' => 1];
+
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S4', 'marked_user_id' => 'S4', 'question_id' => 0, 'score' => 5];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S4', 'marked_user_id' => 'S4', 'question_id' => 1, 'score' => 5];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S4', 'marked_user_id' => 'S4', 'question_id' => 2, 'score' => 5];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S4', 'marked_user_id' => 'S4', 'question_id' => 3, 'score' => 5];
+    $responses[] = ['group_id' => 'G1', 'user_id' => 'S4', 'marked_user_id' => 'S4', 'question_id' => 4, 'score' => 5];
+
+    // ----------------------------------------
+    $algorithm = new NewAlgorithm();
+    $algorithm->set_marking_params($marking_params);
+    $algorithm->set_groups($groups_and_marks);
+    $algorithm->set_group_members($group_members);
+    $algorithm->set_questions($questions);
+    $algorithm->set_responses($responses);
+
+    $algorithm->calculate();
+
+    $webpa_scores = $algorithm->get_webpa_scores();
+    $grades = $algorithm->get_grades();
+    $submissions = $algorithm->get_members_submitting();
+
+    $member_ids = array_keys($webpa_scores);
+
+    $member_names['S1'] = ['user_id' => 'S1', 'lastname' => 'Student 1', 'forename' => '', 'id_number' => 'S1'];
+    $member_names['S2'] = ['user_id' => 'S2', 'lastname' => 'Student 2', 'forename' => '', 'id_number' => 'S2'];
+    $member_names['S3'] = ['user_id' => 'S3', 'lastname' => 'Student 3', 'forename' => '', 'id_number' => 'S3'];
+    $member_names['S4'] = ['user_id' => 'S4', 'lastname' => 'Student 4', 'forename' => '', 'id_number' => 'S4'];
 } else {
-  $assessment = null;
+    $assessment = null;
 }
 
 // --------------------------------------------------------------------------------
@@ -176,9 +174,9 @@
 
 $UI->page_title = APP__NAME . ' ' . $page_title;
 $UI->menu_selected = 'my assessments';
-$UI->breadcrumbs = array  ('home'       => '../../../' ,
-               'my assessments' => '../../' ,
-               $page_title    => null ,);
+$UI->breadcrumbs = ['home'       => '../../../',
+               'my assessments' => '../../',
+               $page_title    => null, ];
 
 $UI->set_page_bar_button('List Assessments', '../../../../images/buttons/button_assessment_list.gif', '../');
 $UI->set_page_bar_button('Create Assessments', '../../../../images/buttons/button_assessment_create.gif', '../create/');
@@ -204,7 +202,7 @@
 <div class="content_box">
 
 <div class="nav_button_bar">
-  <a href="<?php echo($list_url) ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to reports list</a>
+  <a href="<?php echo $list_url ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to reports list</a>
 </div>
 
 <h2 style="font-size: 150%;">Student Grades</h2>
@@ -217,24 +215,24 @@
     <th align="center">Did not<br />submit</th>
   </tr>
 <?php
-foreach($member_names as $i => $member) {
-  $score = (array_key_exists($member['user_id'], $webpa_scores)) ? $webpa_scores["{$member['user_id']}"] : '-' ;
-  $score = sprintf('%01.2f', $score);
-  $grade = (array_key_exists($member['user_id'], $grades)) ? $grades["{$member['user_id']}"] : '-' ;
-  $grade = sprintf('%01.2f', $grade);
-
-  if ($marking_params['penalty']==0) {
-    $penalty_str = (array_key_exists($member['user_id'], $submissions)) ? '&nbsp;' : 'no penalty' ;
-  } else {
-    $penalty_str = (array_key_exists($member['user_id'], $submissions)) ? '&nbsp;' : "-{$marking_params['penalty']}%";
-  }
-
-  echo('<tr>');
-  echo("<td style=\"text-align: left\"> {$member['lastname']}, {$member['forename']} ({$member['id_number']})</td>");
-  echo("<td>$score</td>");
-  echo("<td>{$grade}%</td>");
-  echo("<td>$penalty_str</td>");
-  echo('</tr>');
+foreach ($member_names as $i => $member) {
+    $score = (array_key_exists($member['user_id'], $webpa_scores)) ? $webpa_scores["{$member['user_id']}"] : '-' ;
+    $score = sprintf('%01.2f', $score);
+    $grade = (array_key_exists($member['user_id'], $grades)) ? $grades["{$member['user_id']}"] : '-' ;
+    $grade = sprintf('%01.2f', $grade);
+
+    if ($marking_params['penalty']==0) {
+        $penalty_str = (array_key_exists($member['user_id'], $submissions)) ? '&nbsp;' : 'no penalty' ;
+    } else {
+        $penalty_str = (array_key_exists($member['user_id'], $submissions)) ? '&nbsp;' : "-{$marking_params['penalty']}%";
+    }
+
+    echo '<tr>';
+    echo "<td style=\"text-align: left\"> {$member['lastname']}, {$member['forename']} ({$member['id_number']})</td>";
+    echo "<td>$score</td>";
+    echo "<td>{$grade}%</td>";
+    echo "<td>$penalty_str</td>";
+    echo '</tr>';
 }
 ?>
   </table>
diff --git a/src/tutors/assessments/reports/report_marks_awarded_byquestion_anonymous.php b/src/tutors/assessments/reports/report_marks_awarded_byquestion_anonymous.php
index 01dba0a..3bd9737 100644
--- a/src/tutors/assessments/reports/report_marks_awarded_byquestion_anonymous.php
+++ b/src/tutors/assessments/reports/report_marks_awarded_byquestion_anonymous.php
@@ -8,8 +8,9 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\classes\Form;
 use WebPA\includes\classes\GroupHandler;
@@ -19,9 +20,9 @@
 use WebPA\includes\functions\ArrayFunctions;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -40,91 +41,92 @@
 
 $assessment = new Assessment($DB);
 if ($assessment->load($assessment_id)) {
+    $xml_parser = new XMLParser();
 
-  $xml_parser = new XMLParser();
-
-  // ----------------------------------------
-  // Get the marking parameters used for the marksheet this report will display
-
-  $md_mysql_date = date(MYSQL_DATETIME_FORMAT, $marking_date);
-
-  $params_xml = $DB->fetch_value("SELECT marking_params
-                  FROM " . APP__DB_TABLE_PREFIX . "assessment_marking
-                  WHERE assessment_id = '$assessment->id'
-                    AND date_created = '$md_mysql_date'
-                  LIMIT 1");
-
-  $params = $xml_parser->parse($params_xml);
-
-  if (array_key_exists('parameters', $params)) {
-    $marking_params['weighting'] = $params['parameters']['weighting']['_attributes']['value'];
-    $marking_params['penalty'] = $params['parameters']['penalty']['_attributes']['value'];
-  } else {
-    $marking_params['weighting']= 100;
-    $marking_params['penalty'] = 0;
-  }
-
-  // ----------------------------------------
-  // Get a list of the members who took this assessment (grouped by 'group')
-  $groups_and_marks = null;
-  $group_members = null;
-  $group_names = null;
-
-  $group_handler = new GroupHandler();
-  $collection = $group_handler->get_collection($assessment->get_collection_id());
-  $groups_iterator = $collection->get_groups_iterator();
-  if ($groups_iterator->size()>0) {
-    for($groups_iterator->reset(); $groups_iterator->is_valid(); $groups_iterator->next()) {
-      $group =& $groups_iterator->current();
-      $group_members["{$group->id}"] = $group->get_member_ids();
-      $group_names["{$group->id}"] = $group->name;
-      $groups_and_marks["{$group->id}"] = null;
-    }
-  }
+    // ----------------------------------------
+    // Get the marking parameters used for the marksheet this report will display
+
+    $md_mysql_date = date(MYSQL_DATETIME_FORMAT, $marking_date);
+
+    $getMarkingParametersQuery =
+      'SELECT marking_params ' .
+      'FROM ' . APP__DB_TABLE_PREFIX . 'assessment_marking ' .
+      'WHERE assessment_id = ? ' .
+      'AND date_created = ? ' .
+      'LIMIT 1';
+
+    $params_xml = $DB->getConnection()->fetchOne($getMarkingParametersQuery, [$assessment->id, $md_mysql_date], [ParameterType::STRING, ParameterType::STRING]);
 
-  // ----------------------------------------
-  // Get the questions used in this assessment
-  $form = new Form($DB);
-  $form_xml = $assessment->get_form_xml();
-  $form->load_from_xml($form_xml);
-  $question_count = (int) $form->get_question_count();
+    $params = $xml_parser->parse($params_xml);
 
-  // Create the actual array (question_ids are 0-based)
-  if ($question_count>0) {
-    $questions = range(0, $question_count-1);
-  } else {
-    $questions = array();
-  }
+    if (array_key_exists('parameters', $params)) {
+        $marking_params['weighting'] = $params['parameters']['weighting']['_attributes']['value'];
+        $marking_params['penalty'] = $params['parameters']['penalty']['_attributes']['value'];
+    } else {
+        $marking_params['weighting']= 100;
+        $marking_params['penalty'] = 0;
+    }
+
+    // ----------------------------------------
+    // Get a list of the members who took this assessment (grouped by 'group')
+    $groups_and_marks = null;
+    $group_members = null;
+    $group_names = null;
+
+    $group_handler = new GroupHandler();
+    $collection = $group_handler->get_collection($assessment->get_collection_id());
+    $groups_iterator = $collection->get_groups_iterator();
+    if ($groups_iterator->size()>0) {
+        for ($groups_iterator->reset(); $groups_iterator->is_valid(); $groups_iterator->next()) {
+            $group =& $groups_iterator->current();
+            $group_members["{$group->id}"] = $group->get_member_ids();
+            $group_names["{$group->id}"] = $group->name;
+            $groups_and_marks["{$group->id}"] = null;
+        }
+    }
 
-  // ----------------------------------------
-  // Get the student submissions for this assessment
-  $result_handler = new ResultHandler($DB);
-  $result_handler->set_assessment($assessment);
+    // ----------------------------------------
+    // Get the questions used in this assessment
+    $form = new Form($DB);
+    $form_xml = $assessment->get_form_xml();
+    $form->load_from_xml($form_xml);
+    $question_count = (int) $form->get_question_count();
+
+    // Create the actual array (question_ids are 0-based)
+    if ($question_count>0) {
+        $questions = range(0, $question_count-1);
+    } else {
+        $questions = [];
+    }
 
-  $responses = $result_handler->get_responses();
+    // ----------------------------------------
+    // Get the student submissions for this assessment
+    $result_handler = new ResultHandler($DB);
+    $result_handler->set_assessment($assessment);
 
-  // ----------------------------------------
-  $algorithm = new NewAlgorithm();
-  $algorithm->set_marking_params($marking_params);
-  $algorithm->set_groups($groups_and_marks);
-  $algorithm->set_group_members($group_members);
-  $algorithm->set_questions($questions);
-  $algorithm->set_responses($responses);
+    $responses = $result_handler->get_responses();
 
-  $algorithm->calculate();
+    // ----------------------------------------
+    $algorithm = new NewAlgorithm();
+    $algorithm->set_marking_params($marking_params);
+    $algorithm->set_groups($groups_and_marks);
+    $algorithm->set_group_members($group_members);
+    $algorithm->set_questions($questions);
+    $algorithm->set_responses($responses);
 
-  $webpa_scores = $algorithm->get_webpa_scores();
+    $algorithm->calculate();
 
-  $member_ids = array_keys($webpa_scores);
+    $webpa_scores = $algorithm->get_webpa_scores();
 
-  $members_raw = $CIS->get_user($member_ids);
+    $member_ids = array_keys($webpa_scores);
 
-  $members = ArrayFunctions::array_get_assoc($members_raw,'user_id');
+    $members_raw = $CIS->get_user($member_ids);
 
+    $members = ArrayFunctions::array_get_assoc($members_raw, 'user_id');
 } else {
-  $assessment = null;
-  echo('Error: The assessment could not be loaded.');
-  exit;
+    $assessment = null;
+    echo 'Error: The assessment could not be loaded.';
+    exit;
 }
 
 /*
@@ -133,13 +135,12 @@
 * --------------------------------------------------------------------------------
 */
 if ($type == 'view') {
-  // Begin Page
+    // Begin Page
 
-  $page_title = ($assessment) ? "{$assessment->name}" : 'report';
+    $page_title = ($assessment) ? "{$assessment->name}" : 'report';
 
-  $UI->page_title = APP__NAME . ' ' . $page_title;
-  $UI->head();
-?>
+    $UI->page_title = APP__NAME . ' ' . $page_title;
+    $UI->head(); ?>
   <style type="text/css">
   <!--
 
@@ -155,8 +156,7 @@
   </style>
 <?php
   $UI->body();
-  $UI->content_start();
-?>
+    $UI->content_start(); ?>
 
   <div class="content_box">
 
@@ -164,74 +164,71 @@
 
 <?php
   if (($assessment) && ($groups_iterator->size()>0)) {
-    foreach($group_members as $group_id => $g_members) {
-      $g_member_count = count($group_members[$group_id]);
-?>
+      foreach ($group_members as $group_id => $g_members) {
+          $g_member_count = count($group_members[$group_id]); ?>
       <div style="margin-top: 40px; page-break-after: always;">
-        <h3><?php echo($group_names[$group_id]); ?></h3>
+        <h3><?php echo $group_names[$group_id]; ?></h3>
 
 <?php
       foreach ($questions as $question_id) {
-        $q_index = $question_id+1;
-        $question = $form->get_question($question_id);
-        echo("<p>Q{$q_index} : {$question['text']['_data']} (range: {$question['range']['_data']})</p>");
-?>
+          $q_index = $question_id+1;
+          $question = $form->get_question($question_id);
+          echo "<p>Q{$q_index} : {$question['text']['_data']}"; ?>
+          <?= array_key_exists('range', $question) ? "(range: {$question['range']['_data']})" : '' ?>
+          </p>
           <table class="grid" cellpadding="2" cellspacing="1" style="font-size: 0.8em">
           <tr>
             <th>&nbsp;</th>
 <?php
         foreach ($g_members as $i => $member_id) {
-          $char = chr(65+$i);
-          $members[$member_id]['lastname'] = "Student $char";
-          echo("<th class=\"top_names\"> {$members[$member_id]['lastname']}</th>");
-        }
-?>
+            $char = chr(65+$i);
+            $members[$member_id]['lastname'] = "Student $char";
+            echo "<th class=\"top_names\"> {$members[$member_id]['lastname']}</th>";
+        } ?>
           </tr>
 <?php
-        $q_total = array();
-        foreach($g_members as $i => $member_id) {
-          $q_total[$member_id] = 0;
-        }
+        $q_total = [];
+          foreach ($g_members as $i => $member_id) {
+              $q_total[$member_id] = 0;
+          }
 
-        foreach ($g_members as $i => $member_id) {
-          echo('<tr>');
-          echo("<th>{$members[$member_id]['lastname']}</th>");
-
-          foreach ($g_members as $j => $target_member_id) {
-            if ($assessment->assessment_type == '0') {
-              if ($member_id == $target_member_id) {
-                $score = 'n/a';
-              } else {
-                $score = $algorithm->get_member_response($group_id, $member_id, $question_id, $target_member_id);
+          foreach ($g_members as $i => $member_id) {
+              echo '<tr>';
+              echo "<th>{$members[$member_id]['lastname']}</th>";
+
+              foreach ($g_members as $j => $target_member_id) {
+                  if ($assessment->assessment_type == '0') {
+                      if ($member_id == $target_member_id) {
+                          $score = 'n/a';
+                      } else {
+                          $score = $algorithm->get_member_response($group_id, $member_id, $question_id, $target_member_id);
+                      }
+                  } else {
+                      $score = $algorithm->get_member_response($group_id, $member_id, $question_id, $target_member_id);
+                  }
+
+                  $q_total[$target_member_id] += (int) $score;
+                  if (is_null($score)) {
+                      $score = '-';
+                  }
+                  echo "<td>$score</td>";
               }
-            }else{
-              $score = $algorithm->get_member_response($group_id, $member_id, $question_id, $target_member_id);
-            }
-
-            $q_total[$target_member_id] += (int) $score;
-            if (is_null($score)) { $score = '-'; }
-            echo("<td>$score</td>");
-          }
-          echo('</tr>');
-        }
-?>
+              echo '</tr>';
+          } ?>
           <tr class="q_total">
             <th>Score Received</th>
 <?php
         foreach ($g_members as $i => $member_id) {
-          echo("<th>{$q_total[$member_id]}</th>");
-        }
-?>
+            echo "<th>{$q_total[$member_id]}</th>";
+        } ?>
           </tr>
           </table>
 <?php
-      }
-?>
+      } ?>
       </div>
 <?php
-    }
-  }
-?>
+      }
+  } ?>
 
   </div>
 
@@ -245,68 +242,80 @@
 * --------------------------------------------------------------------------------
 */
 if ($type == 'download-csv') {
-  header("Content-Disposition: attachment; filename=\"webpa_marks_awarded_byquestion.csv\"");
-  header('Content-Type: text/csv');
-
-  echo('"Marks Awarded For Each Question (anonymous)"'."\n\n");
-  echo("\"{$assessment->name}\"\n\n");
-
-  if (($assessment) && ($groups_iterator->size()>0)) {
-    foreach ($group_members as $group_id => $g_members) {
-      $g_member_count = count($group_members[$group_id]);
-
-      echo("\"{$group_names[$group_id]}\"\n");
-
-      foreach ($questions as $question_id) {
-        $q_index = $question_id+1;
-        $question = $form->get_question($question_id);
-
-        echo("\n");
-        echo("\"Q{$q_index} : {$question['text']['_data']} (range: {$question['range']['_data']})\"\n");
-
-        echo("\"\",");
-
-        foreach ($g_members as $i => $member_id) {
-          $char = chr(65+$i);
-          $members[$member_id]['lastname'] = "Student $char";
-
-          echo("\"{$members[$member_id]['lastname']}\"");
-          if ($i<$g_member_count) {
-            echo(',');
-          }
-        }
-
-        echo("\n");
-
-        foreach ($g_members as $i => $member_id) {
-          echo("\"{$members[$member_id]['lastname']}\",");
-
-          foreach ($g_members as $j => $target_member_id) {
-            if ($assessment->assessment_type == '0') {
-              if ($member_id == $target_member_id) {
-                $score = 'n/a';
-              } else {
-                $score = $algorithm->get_member_response($group_id, $member_id, $question_id, $target_member_id);
-              }
-            } else {
-              $score = $algorithm->get_member_response($group_id, $member_id, $question_id, $target_member_id);
+    header('Content-Disposition: attachment; filename="webpa_marks_awarded_byquestion.csv"');
+    header('Content-Type: text/csv');
+
+    echo '"Marks Awarded For Each Question (anonymous)"'."\n\n";
+    echo "\"{$assessment->name}\"\n\n";
+
+    if (($assessment) && ($groups_iterator->size()>0)) {
+        foreach ($group_members as $group_id => $g_members) {
+            $g_member_count = count($group_members[$group_id]);
+
+            echo "\"{$group_names[$group_id]}\"\n";
+
+            foreach ($questions as $question_id) {
+                $q_index = $question_id+1;
+                $question = $form->get_question($question_id);
+
+                echo "\n";
+                echo "\"Q{$q_index} : {$question['text']['_data']}";
+
+                if (array_key_exists('range', $question)) {
+                    echo "range: {$question['range']['_data']})\"\n";
+                } else {
+                    echo "\"\n";
+                }
+
+                echo '"",';
+
+                foreach ($g_members as $i => $member_id) {
+                    $char = chr(65+$i);
+                    $members[$member_id]['lastname'] = "Student $char";
+
+                    echo "\"{$members[$member_id]['lastname']}\"";
+                    if ($i<$g_member_count) {
+                        echo ',';
+                    }
+                }
+
+                echo "\n";
+
+                foreach ($g_members as $i => $member_id) {
+                    echo "\"{$members[$member_id]['lastname']}\",";
+
+                    foreach ($g_members as $j => $target_member_id) {
+                        if ($assessment->assessment_type == '0') {
+                            if ($member_id == $target_member_id) {
+                                $score = 'n/a';
+                            } else {
+                                $score = $algorithm->get_member_response($group_id, $member_id, $question_id, $target_member_id);
+                            }
+                        } else {
+                            $score = $algorithm->get_member_response($group_id, $member_id, $question_id, $target_member_id);
+                        }
+
+                        // there is a chance that q total won't have been set if a student has not answered any questions
+                        $q_total = $q_total ?? [];
+
+                        if (count($q_total) > 0) {
+                            $q_total[$target_member_id] += (int) $score;
+                        }
+
+                        if (is_null($score)) {
+                            $score = '-';
+                        }
+
+                        echo "\"$score\"";
+                        if ($j<$g_member_count) {
+                            echo ',';
+                        }
+                    }
+                    echo "\n";
+                }
             }
-
-            $q_total[$target_member_id] += (int) $score;
-            if (is_null($score)) {
-              $score = '-';
-            }
-
-            echo("\"$score\"");
-            if ($j<$g_member_count) {
-              echo(',');
-            }
-          }
-          echo("\n");
+            echo "\n\n";
         }
-      }
-      echo("\n\n");
     }
-  }
 }
 ?>
diff --git a/src/tutors/assessments/reports/report_marks_awarded_byquestion_named.php b/src/tutors/assessments/reports/report_marks_awarded_byquestion_named.php
index e419a21..26a4db2 100644
--- a/src/tutors/assessments/reports/report_marks_awarded_byquestion_named.php
+++ b/src/tutors/assessments/reports/report_marks_awarded_byquestion_named.php
@@ -8,15 +8,15 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\AlgorithmFactory;
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -35,53 +35,54 @@
 
 $assessment = new Assessment($DB);
 if (!$assessment->load($assessment_id)) {
-  $assessment = null;
-  echo('Error: The requested assessment could not be loaded.');
-  exit;
-} else {
-
-  // ----------------------------------------
-  // Get the marking parameters used for the marksheet this report will display
-  $marking_params = $assessment->get_marking_params($marking_date);
-
-  if (!$marking_params) {
-    echo('Error: The requested marksheet could not be loaded.');
+    $assessment = null;
+    echo 'Error: The requested assessment could not be loaded.';
     exit;
-  }
+}
 
   // ----------------------------------------
-  // Get a list of the groups, and their marks, used in this assessment
-  $groups_and_marks = $assessment->get_group_marks();
+    // Get the marking parameters used for the marksheet this report will display
+    $marking_params = $assessment->get_marking_params($marking_date);
 
-  // ----------------------------------------
-  // Get the appropriate algorithm and calculate the grades
-  $algorithm = AlgorithmFactory::get_algorithm($marking_params['algorithm']);
+    if (!$marking_params) {
+        echo 'Error: The requested marksheet could not be loaded.';
+        exit;
+    }
 
-  if (!$algorithm) {
-    echo('Error: The requested algorithm could not be loaded.');
-    exit;
-  } else {
-    $algorithm->set_grade_ordinals($ordinal_scale);
-    $algorithm->set_assessment($assessment);
-    $algorithm->set_marking_params($marking_params);
-    $algorithm->calculate();
+    // ----------------------------------------
+    // Get a list of the groups, and their marks, used in this assessment
+    $groups_and_marks = $assessment->get_group_marks();
+
+    // ----------------------------------------
+    // Get the appropriate algorithm and calculate the grades
+    $algorithm = AlgorithmFactory::get_algorithm($marking_params['algorithm']);
 
-    $questions = $algorithm->get_questions();
-    $submissions = $algorithm->get_submitters();
-    $webpa_scores = $algorithm->get_webpa_scores();
+    if (!$algorithm) {
+        echo 'Error: The requested algorithm could not be loaded.';
+        exit;
+    }
+        $algorithm->set_grade_ordinals($ordinal_scale);
+        $algorithm->set_assessment($assessment);
+        $algorithm->set_marking_params($marking_params);
+        $algorithm->calculate();
 
-    $intermediate_grades = $algorithm->get_intermediate_grades();
-    $grades = $algorithm->get_grades();
+        $questions = $algorithm->get_questions();
+        $submissions = $algorithm->get_submitters();
+        $webpa_scores = $algorithm->get_webpa_scores();
 
-    $penalties = $algorithm->get_penalties();
-    if (!$penalties) { $penalties = array(); }
+        $intermediate_grades = $algorithm->get_intermediate_grades();
+        $grades = $algorithm->get_grades();
 
-    $group_names = $algorithm->get_group_names();
-    $group_members = $algorithm->get_group_members();
-    $member_ids = array_keys($webpa_scores);
-  }// /if-else(is algorithm)
+        $penalties = $algorithm->get_penalties();
+        if (!$penalties) {
+            $penalties = [];
+        }
 
-}// /if-else(is assessment)
+        $group_names = $algorithm->get_group_names();
+        $group_members = $algorithm->get_group_members();
+        $member_ids = array_keys($webpa_scores);
+    // /if-else(is algorithm)
+// /if-else(is assessment)
 
 /*
  * --------------------------------------------------------------------------------
@@ -90,13 +91,12 @@
  */
 
 if ($type == 'view') {
-  // Begin Page
+    // Begin Page
 
-  $page_title = ($assessment) ? "{$assessment->name}" : 'report';
+    $page_title = ($assessment) ? "{$assessment->name}" : 'report';
 
-  $UI->page_title = APP__NAME . ' ' . $page_title;
-  $UI->head();
-?>
+    $UI->page_title = APP__NAME . ' ' . $page_title;
+    $UI->head(); ?>
   <style type="text/css">
   <!--
 
@@ -114,8 +114,7 @@
   </style>
 <?php
   $UI->body();
-  $UI->content_start();
-?>
+    $UI->content_start(); ?>
 
   <div class="content_box">
 
@@ -123,87 +122,81 @@
 
 <?php
   foreach ($group_members as $group_id => $g_members) {
-    $g_member_count = count($group_members[$group_id]);
-?>
+      $g_member_count = count($group_members[$group_id]); ?>
     <div style="margin-top: 40px; page-break-after: always;">
-      <h3><?php echo($group_names[$group_id]); ?></h3>
+      <h3><?php echo $group_names[$group_id]; ?></h3>
 <?php
     foreach ($questions as $question_id => $question) {
-      $q_index = $question_id+1;
+        $q_index = $question_id+1;
 
-      echo("<p>Q{$q_index} : {$question['text']['_data']} (range: {$question['range']['_data']})</p>");
-?>
+        echo "<p>Q{$q_index} : {$question['text']['_data']}"; ?>
+        <?= array_key_exists('range', $question) ? "(range: {$question['range']['_data']})" : '' ?>
+        </p>
         <table class="grid" cellpadding="2" cellspacing="1" style="font-size: 0.8em">
         <tr>
           <th>&nbsp;</th>
 <?php
       foreach ($g_members as $i => $member_id) {
-        $individ = $CIS->get_user($member_id);
-        echo("<th class=\"top_names\"> {$individ['lastname']}, {$individ['forename']}<br />(");
-        if (!empty($individ['id_number'])) {
-          echo($individ['id_number']);
-        } else {
-          echo($individ['username']);
-        }
-        echo(')</th>');
-      }
-?>
+          $individ = $CIS->get_user($member_id);
+          echo "<th class=\"top_names\"> {$individ['lastname']}, {$individ['forename']}<br />(";
+          if (!empty($individ['id_number'])) {
+              echo $individ['id_number'];
+          } else {
+              echo $individ['username'];
+          }
+          echo ')</th>';
+      } ?>
         </tr>
 <?php
-      $q_total = array();
-
-      foreach ($g_members as $i => $member_id) {
-        $q_total[$member_id] = 0;
-      }
+      $q_total = [];
 
-      foreach ($g_members as $i => $member_id) {
-        $individ = $CIS->get_user($member_id);
-        echo('<tr>');
-        echo("<th>{$individ['lastname']}, {$individ['forename']}<br />(");
-        if (!empty($individ['id_number'])) {
-          echo($individ['id_number']);
-        } else {
-          echo($individ['username']);
+        foreach ($g_members as $i => $member_id) {
+            $q_total[$member_id] = 0;
         }
-        echo(')</th>');
-
-        foreach($g_members as $j => $target_member_id) {
-          if ($assessment->assessment_type == '0'){
-
-            if ($member_id == $target_member_id){
-              $score = 'n/a';
-            }else{
 
-              $score = $algorithm->get_member_response($group_id, $member_id, $question_id, $target_member_id);
+        foreach ($g_members as $i => $member_id) {
+            $individ = $CIS->get_user($member_id);
+            echo '<tr>';
+            echo "<th>{$individ['lastname']}, {$individ['forename']}<br />(";
+            if (!empty($individ['id_number'])) {
+                echo $individ['id_number'];
+            } else {
+                echo $individ['username'];
             }
-          }else{
-            $score = $algorithm->get_member_response($group_id, $member_id, $question_id, $target_member_id);
-          }
-
-          $q_total[$target_member_id] += (int) $score;
-          if (is_null($score)) { $score = '-'; }
-          echo("<td>$score</td>");
-        }
-        echo('</tr>');
-
-      }
-?>
+            echo ')</th>';
+
+            foreach ($g_members as $j => $target_member_id) {
+                if ($assessment->assessment_type == '0') {
+                    if ($member_id == $target_member_id) {
+                        $score = 'n/a';
+                    } else {
+                        $score = $algorithm->get_member_response($group_id, $member_id, $question_id, $target_member_id);
+                    }
+                } else {
+                    $score = $algorithm->get_member_response($group_id, $member_id, $question_id, $target_member_id);
+                }
+
+                $q_total[$target_member_id] += (int) $score;
+                if (is_null($score)) {
+                    $score = '-';
+                }
+                echo "<td>$score</td>";
+            }
+            echo '</tr>';
+        } ?>
         <tr class="q_total">
           <th>Score Received</th>
 <?php
-      foreach($g_members as $i => $member_id) {
-        echo("<th>{$q_total[$member_id]}</th>");
-      }
-?>
+      foreach ($g_members as $i => $member_id) {
+          echo "<th>{$q_total[$member_id]}</th>";
+      } ?>
         </tr>
         </table>
 <?php
-    }
-?>
+    } ?>
     </div>
 <?php
-  }
-?>
+  } ?>
 
   </div>
 
@@ -218,81 +211,89 @@
  */
 
 if ($type == 'download-csv') {
-  header("Content-Disposition: attachment; filename=\"webpa_marks_awarded_byquestion.csv\"");
-  header('Content-Type: text/csv');
-
-  echo('"Marks Awarded For Each Question"'."\n\n");
-  echo("\"{$assessment->name}\"\n\n");
-
-  foreach ($group_members as $group_id => $g_members) {
-    $g_member_count = count($group_members[$group_id]);
-
-    $q_total = array();
+    header('Content-Disposition: attachment; filename="webpa_marks_awarded_byquestion.csv"');
+    header('Content-Type: text/csv');
 
-    foreach($g_members as $i => $member_id) {
-      $q_total[$member_id] = 0;
-    }
-
-    echo("\"{$group_names[$group_id]}\"\n");
-
-    foreach ($questions as $question_id => $question) {
-      $q_index = $question_id+1;
+    echo '"Marks Awarded For Each Question"'."\n\n";
+    echo "\"{$assessment->name}\"\n\n";
 
-      echo("\n");
-      echo("\"Q{$q_index} : {$question['text']['_data']} (range: {$question['range']['_data']})\"\n");
+    foreach ($group_members as $group_id => $g_members) {
+        $g_member_count = count($group_members[$group_id]);
 
-      echo("\"\",");
+        $q_total = [];
 
-      foreach ($g_members as $i => $member_id) {
-        $individ = $CIS->get_user($member_id);
-        echo("\"{$individ['lastname']}, {$individ['forename']} (");
-        if (!empty($individ['id_number'])) {
-          echo($individ['id_number']);
-        } else {
-          echo($individ['username']);
+        foreach ($g_members as $i => $member_id) {
+            $q_total[$member_id] = 0;
         }
-        echo(')"');
-        if ($i<$g_member_count) { echo(','); }
-      }
 
-      echo("\n");
+        echo "\"{$group_names[$group_id]}\"\n";
 
-      foreach ($g_members as $i => $member_id) {
-        $individ = $CIS->get_user($member_id);
+        foreach ($questions as $question_id => $question) {
+            $q_index = $question_id+1;
 
-        echo("\"{$individ['lastname']}, {$individ['forename']} (");
-        if (!empty($individ['id_number'])) {
-          echo($individ['id_number']);
-        } else {
-          echo($individ['username']);
-        }
-        echo(')",');
+            echo "\n";
+            echo "\"Q{$q_index} : {$question['text']['_data']}";
 
-        foreach ($g_members as $j => $target_member_id) {
-          if ($assessment->assessment_type == '0') {
-            if ($member_id == $target_member_id) {
-              $score = 'n/a';
+            if (array_key_exists('range', $question)) {
+                echo "(range: {$question['range']['_data']})\"\n";
             } else {
-              $score = $algorithm->get_member_response($group_id, $member_id, $question_id, $target_member_id);
+                echo "\"\n";
             }
-          } else {
-            $score = $algorithm->get_member_response($group_id, $member_id, $question_id, $target_member_id);
-          }
 
-          $q_total[$target_member_id] += (int) $score;
-          if (is_null($score)) {
-            $score = '-';
-          }
+            echo '"",';
+
+            foreach ($g_members as $i => $member_id) {
+                $individ = $CIS->get_user($member_id);
+                echo "\"{$individ['lastname']}, {$individ['forename']} (";
+                if (!empty($individ['id_number'])) {
+                    echo $individ['id_number'];
+                } else {
+                    echo $individ['username'];
+                }
+                echo ')"';
+                if ($i<$g_member_count) {
+                    echo ',';
+                }
+            }
 
-          echo("\"$score\"");
-          if ($j<$g_member_count) {
-            echo(',');
-          }
+            echo "\n";
+
+            foreach ($g_members as $i => $member_id) {
+                $individ = $CIS->get_user($member_id);
+
+                echo "\"{$individ['lastname']}, {$individ['forename']} (";
+                if (!empty($individ['id_number'])) {
+                    echo $individ['id_number'];
+                } else {
+                    echo $individ['username'];
+                }
+                echo ')",';
+
+                foreach ($g_members as $j => $target_member_id) {
+                    if ($assessment->assessment_type == '0') {
+                        if ($member_id == $target_member_id) {
+                            $score = 'n/a';
+                        } else {
+                            $score = $algorithm->get_member_response($group_id, $member_id, $question_id, $target_member_id);
+                        }
+                    } else {
+                        $score = $algorithm->get_member_response($group_id, $member_id, $question_id, $target_member_id);
+                    }
+
+                    $q_total[$target_member_id] += (int) $score;
+                    if (is_null($score)) {
+                        $score = '-';
+                    }
+
+                    echo "\"$score\"";
+                    if ($j<$g_member_count) {
+                        echo ',';
+                    }
+                }
+                echo "\n";
+            }
         }
-        echo("\n");
-      }
+        echo "\n\n";
     }
-    echo("\n\n");
-  }
 }
 ?>
diff --git a/src/tutors/assessments/reports/report_student_feedback_bygroup.php b/src/tutors/assessments/reports/report_student_feedback_bygroup.php
index fd3d5e6..5158633 100644
--- a/src/tutors/assessments/reports/report_student_feedback_bygroup.php
+++ b/src/tutors/assessments/reports/report_student_feedback_bygroup.php
@@ -8,16 +8,17 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\AlgorithmFactory;
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\classes\XMLParser;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -36,77 +37,85 @@
 
 $assessment = new Assessment($DB);
 if (!$assessment->load($assessment_id)) {
-  $assessment = null;
-  echo('Error: The requested assessment could not be loaded.');
-  exit;
-} else {
-
-  $xml_parser = new XMLParser();
-
-  // ----------------------------------------
-  // Get the marking parameters used for the marksheet this report will display
-  $marking_params = $assessment->get_marking_params($marking_date);
-
-  if (!$marking_params) {
-    echo('Error: The requested marksheet could not be loaded.');
+    $assessment = null;
+    echo 'Error: The requested assessment could not be loaded.';
     exit;
-  }
+}
+    $xml_parser = new XMLParser();
+
+    // ----------------------------------------
+    // Get the marking parameters used for the marksheet this report will display
+    $marking_params = $assessment->get_marking_params($marking_date);
 
-  // ----------------------------------------
-  // Get a list of the groups, and their marks, used in this assessment
-  $groups_and_marks = $assessment->get_group_marks();
+    if (!$marking_params) {
+        echo 'Error: The requested marksheet could not be loaded.';
+        exit;
+    }
 
-  // ----------------------------------------
-  // Get the appropriate algorithm and calculate the grades
-  $algorithm = AlgorithmFactory::get_algorithm($marking_params['algorithm']);
+    // ----------------------------------------
+    // Get a list of the groups, and their marks, used in this assessment
+    $groups_and_marks = $assessment->get_group_marks();
 
-  if (!$algorithm) {
-    echo('Error: The requested algorithm could not be loaded.');
-    exit;
-  } else {
-    $algorithm->set_grade_ordinals($ordinal_scale);
-    $algorithm->set_assessment($assessment);
-    $algorithm->set_marking_params($marking_params);
-    $algorithm->calculate();
+    // ----------------------------------------
+    // Get the appropriate algorithm and calculate the grades
+    $algorithm = AlgorithmFactory::get_algorithm($marking_params['algorithm']);
 
-    $questions = $algorithm->get_questions();
-    $submissions = $algorithm->get_submitters();
-    $webpa_scores = $algorithm->get_webpa_scores();
+    if (!$algorithm) {
+        echo 'Error: The requested algorithm could not be loaded.';
+        exit;
+    }
+        $algorithm->set_grade_ordinals($ordinal_scale);
+        $algorithm->set_assessment($assessment);
+        $algorithm->set_marking_params($marking_params);
+        $algorithm->calculate();
 
-    $intermediate_grades = $algorithm->get_intermediate_grades();
-    $grades = $algorithm->get_grades();
+        $questions = $algorithm->get_questions();
+        $submissions = $algorithm->get_submitters();
+        $webpa_scores = $algorithm->get_webpa_scores();
 
-    $penalties = $algorithm->get_penalties();
-    if (!$penalties) { $penalties = array(); }
+        $intermediate_grades = $algorithm->get_intermediate_grades();
+        $grades = $algorithm->get_grades();
 
-    $group_names = $algorithm->get_group_names();
-    $group_members = $algorithm->get_group_members();
-    $member_ids = array_keys($webpa_scores);
-  }// /if-else(is algorithm)
+        $penalties = $algorithm->get_penalties();
+        if (!$penalties) {
+            $penalties = [];
+        }
 
-  //------------------------------------------------------------
-  //get the feedback / Justification
-  $sql = "SELECT * FROM " . APP__DB_TABLE_PREFIX . "user_justification WHERE assessment_id='{$assessment->id}';";
+        $group_names = $algorithm->get_group_names();
+        $group_members = $algorithm->get_group_members();
+        $member_ids = array_keys($webpa_scores);
+    // /if-else(is algorithm)
 
-  $fetch_comments = $DB->fetch($sql);
+    //------------------------------------------------------------
+    //get the feedback / Justification
+    $feedbackQuery =
+      'SELECT * ' .
+      'FROM ' . APP__DB_TABLE_PREFIX . 'user_justification ' .
+      'WHERE assessment_id = ?';
 
-  $feedback = null;
+    $fetch_comments = $DB->getConnection()->fetchAllAssociative($feedbackQuery, [$assessment->id], [ParameterType::STRING]);
 
-  foreach ($fetch_comments as $comment){
+    $feedback = null;
 
-    $id = $CIS->get_user($comment["user_id"]);
-    $marker_id = $id["user_id"];
-    $marker = $id["lastname"] . ", " . $id["forename"];
-    $id = $CIS->get_user($comment["marked_user_id"]);
-    $marked = $id["lastname"] . ", " . $id["forename"];
+    foreach ($fetch_comments as $comment) {
+        if (!is_array($comment)) {
+            break;
+        }
 
-    $feedback []  = array(  'marker_id'   =>  $marker_id,
-                            'marker'    =>  $marker,
-                            'marked'    =>  $marked,
-                            'feedback'    =>  $comment["justification_text"]);
-  }
+        $id = $CIS->get_user($comment['user_id']);
+        $marker_id = $id['user_id'];
+        $marker = $id['lastname'] . ', ' . $id['forename'];
+        $id = $CIS->get_user($comment['marked_user_id']);
+        $marked = $id['lastname'] . ', ' . $id['forename'];
+
+        $feedback []  = [
+            'marker_id' =>  $marker_id,
+            'marker' =>  $marker,
+            'marked' =>  $marked,
+            'feedback' =>  $comment['justification_text'],
+        ];
+    }
 
-}
 
 /*
 * --------------------------------------------------------------------------------
@@ -114,13 +123,12 @@
 * --------------------------------------------------------------------------------
 */
 if ($type == 'view') {
-  // Begin Page
+    // Begin Page
 
-  $page_title = ($assessment) ? "{$assessment->name}" : 'report';
+    $page_title = ($assessment) ? "{$assessment->name}" : 'report';
 
-  $UI->page_title = APP__NAME . ' ' . $page_title;
-  $UI->head();
-?>
+    $UI->page_title = APP__NAME . ' ' . $page_title;
+    $UI->head(); ?>
   <style type="text/css">
   <!--
 
@@ -136,8 +144,7 @@
   </style>
 <?php
   $UI->body();
-  $UI->content_start();
-?>
+    $UI->content_start(); ?>
 
   <div class="content_box">
 
@@ -145,12 +152,11 @@
 
 <?php
   if (($assessment) && ($groups_and_marks)) {
-
-    foreach ($group_members as $group_id => $g_members) {
-?>
+      foreach ($group_members as $group_id => $g_members) {
+          ?>
       <div style="margin-top: 40px;">
-        <h3><?php echo($group_names[$group_id]); ?></h3>
-        <p>Overall group mark: <?php echo($groups_and_marks[$group_id]);?>%.</p>
+        <h3><?php echo $group_names[$group_id]; ?></h3>
+        <p>Overall group mark: <?php echo $groups_and_marks[$group_id]; ?>%.</p>
         <table class="grid" cellpadding="2" cellspacing="1">
         <tr>
           <th>name</th>
@@ -160,28 +166,36 @@
 <?php
       $j = 0;
 
-      foreach ($g_members as $i => $member_id) {
-        //loop round the array with all the user data, so that we can out put it
-
-        foreach ($feedback as $j){
-
-          if($j['marker_id'] == $g_members[$i]) {
-            echo('<tr>');
-            echo("<td style=\"text-align:left\"> {$j['marker']}</td>");
-            echo("<td style=\"text-align:left\">{$j['marked']}</td>");
-            echo("<td style=\"text-align:left\">{$j['feedback']}</td>");
-            echo('</tr>');
-          }
-
-        }
-      }
-?>
+          foreach ($g_members as $i => $member_id) {
+              //loop round the array with all the user data, so that we can out put it
+
+              if (!isset($feedback)) {
+                  continue;
+              }
+
+              foreach ($feedback as $j) {
+                  if ($j['marker_id'] == $g_members[$i]) {
+                      echo '<tr>';
+                      echo "<td style=\"text-align:left\"> {$j['marker']}</td>";
+                      echo "<td style=\"text-align:left\">{$j['marked']}</td>";
+                      echo "<td style=\"text-align:left\">{$j['feedback']}</td>";
+                      echo '</tr>';
+                  } else {
+                      ?>
+                        <tr>
+                            <td style="text-align: left;">-</td>
+                            <td style="text-align: left;">-</td>
+                            <td style="text-align: left;">-</td>
+                        </tr>
+                        <?php
+                  }
+              }
+          } ?>
         </table>
       </div>
 <?php
-    }
-  }
-?>
+      }
+  } ?>
 
   </div>
 
@@ -195,27 +209,27 @@
 * --------------------------------------------------------------------------------
 */
 if ($type == 'download-csv') {
-  header("Content-Disposition: attachment; filename=\"webpa_student_feedback.csv\"");
-  header('Content-Type: text/csv');
-
-  echo('"Student feedback and Justification (by Group)"'."\n\n");
-
-  if (($assessment) && ($groups_and_marks)) {
-    foreach ($group_members as $group_id => $g_members) {
-      echo("\"Group\",\"{$group_names[$group_id]}\"\n");
-      echo("\"Overall group mark\",\"{$groups_and_marks[$group_id]}\"\n");
-      echo("\"Name\",\"feedback recipient\",\"feedback / justification comments\"\n");
-      $j = 0;
-      foreach ($g_members as $i => $member_id) {
-        //loop round the array with all the user data, so that we can out put it
-        foreach($feedback as $j){
-          if ($j['marker_id'] == $g_members[$i]) {
-            echo("\"{$j['marker']}\",\"{$j['marked']}\",\"{$j['feedback']}\"\n");
-          }
+    header('Content-Disposition: attachment; filename="webpa_student_feedback.csv"');
+    header('Content-Type: text/csv');
+
+    echo '"Student feedback and Justification (by Group)"'."\n\n";
+
+    if (($assessment) && ($groups_and_marks)) {
+        foreach ($group_members as $group_id => $g_members) {
+            echo "\"Group\",\"{$group_names[$group_id]}\"\n";
+            echo "\"Overall group mark\",\"{$groups_and_marks[$group_id]}\"\n";
+            echo "\"Name\",\"feedback recipient\",\"feedback / justification comments\"\n";
+            $j = 0;
+            foreach ($g_members as $i => $member_id) {
+                //loop round the array with all the user data, so that we can out put it
+                foreach ($feedback as $j) {
+                    if ($j['marker_id'] == $g_members[$i]) {
+                        echo "\"{$j['marker']}\",\"{$j['marked']}\",\"{$j['feedback']}\"\n";
+                    }
+                }
+            }
+            echo "\n\n";
         }
-      }
-    echo("\n\n");
     }
-  }
 }
 ?>
diff --git a/src/tutors/assessments/reports/report_student_grades.php b/src/tutors/assessments/reports/report_student_grades.php
index 0ffd131..424e6a9 100644
--- a/src/tutors/assessments/reports/report_student_grades.php
+++ b/src/tutors/assessments/reports/report_student_grades.php
@@ -8,15 +8,15 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\AlgorithmFactory;
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -35,61 +35,62 @@
 
 $assessment = new Assessment($DB);
 if (!$assessment->load($assessment_id)) {
-  $assessment = null;
-  echo('Error: The requested assessment could not be loaded.');
-  exit;
-} else {
-
-  // ----------------------------------------
-  // Get the marking parameters used for the marksheet this report will display
-  $marking_params = $assessment->get_marking_params($marking_date);
-
-  if (!$marking_params) {
-    echo('Error: The requested marksheet could not be loaded.');
+    $assessment = null;
+    echo 'Error: The requested assessment could not be loaded.';
     exit;
-  }
+}
 
   // ----------------------------------------
-  // Get a list of the groups, and their marks, used in this assessment
-  $groups_and_marks = $assessment->get_group_marks();
+    // Get the marking parameters used for the marksheet this report will display
+    $marking_params = $assessment->get_marking_params($marking_date);
 
-  // ----------------------------------------
-  // Get the appropriate algorithm and calculate the grades
-  $algorithm = AlgorithmFactory::get_algorithm($marking_params['algorithm']);
+    if (!$marking_params) {
+        echo 'Error: The requested marksheet could not be loaded.';
+        exit;
+    }
 
-  if (!$algorithm) {
-    echo('Error: The requested algorithm could not be loaded.');
-    exit;
-  } else {
-    $algorithm->set_grade_ordinals($ordinal_scale);
-    $algorithm->set_assessment($assessment);
-    $algorithm->set_marking_params($marking_params);
-    $algorithm->calculate();
+    // ----------------------------------------
+    // Get a list of the groups, and their marks, used in this assessment
+    $groups_and_marks = $assessment->get_group_marks();
+
+    // ----------------------------------------
+    // Get the appropriate algorithm and calculate the grades
+    $algorithm = AlgorithmFactory::get_algorithm($marking_params['algorithm']);
 
-    $submissions = $algorithm->get_submitters();
-    $webpa_scores = $algorithm->get_webpa_scores();
+    if (!$algorithm) {
+        echo 'Error: The requested algorithm could not be loaded.';
+        exit;
+    }
+        $algorithm->set_grade_ordinals($ordinal_scale);
+        $algorithm->set_assessment($assessment);
+        $algorithm->set_marking_params($marking_params);
+        $algorithm->calculate();
 
-    $intermediate_grades = $algorithm->get_intermediate_grades();
-    $grades = $algorithm->get_grades();
+        $submissions = $algorithm->get_submitters();
+        $webpa_scores = $algorithm->get_webpa_scores();
 
-    $penalties = $algorithm->get_penalties();
-    if (!$penalties) { $penalties = array(); }
+        $intermediate_grades = $algorithm->get_intermediate_grades();
+        $grades = $algorithm->get_grades();
 
-    $group_members = $algorithm->get_group_members();
-    $member_ids = array_keys($webpa_scores);
+        $penalties = $algorithm->get_penalties();
+        if (!$penalties) {
+            $penalties = [];
+        }
 
-    $member_names = array();
+        $group_members = $algorithm->get_group_members();
+        $member_ids = array_keys($webpa_scores);
 
-    for ($i =0; $i<count($group_members); $i++){
-      $array_key = array_keys($group_members);
-      $temp = $group_members[$array_key[$i]];
-      for ($j=0; $j<count($temp);$j++){
-        array_push($member_names, $CIS->get_user($temp[$j]));
-      }
-    }
-  }// /if-else(is algorithm)
+        $member_names = [];
 
-}// /if-else(is assessment)
+        for ($i =0; $i<count($group_members); $i++) {
+            $array_key = array_keys($group_members);
+            $temp = $group_members[$array_key[$i]];
+            for ($j=0; $j<count($temp);$j++) {
+                array_push($member_names, $CIS->get_user($temp[$j]));
+            }
+        }
+    // /if-else(is algorithm)
+// /if-else(is assessment)
 
 /*
  * --------------------------------------------------------------------------------
@@ -98,13 +99,12 @@
  */
 
 if ($type == 'view') {
-  // Begin Page
+    // Begin Page
 
-  $page_title = ($assessment) ? "{$assessment->name}" : 'report';
+    $page_title = ($assessment) ? "{$assessment->name}" : 'report';
 
-  $UI->page_title = APP__NAME . ' ' . $page_title;
-  $UI->head();
-?>
+    $UI->page_title = APP__NAME . ' ' . $page_title;
+    $UI->head(); ?>
   <style type="text/css">
   <!--
 
@@ -120,33 +120,29 @@
   </style>
 <?php
   $UI->body();
-  $UI->content_start();
-?>
+    $UI->content_start(); ?>
 
 <?php
   if ($marking_params) {
-    $penalty_type = ($marking_params['penalty_type']=='pp') ? ' pp' : '%' ;   // Add a space to the 'pp'.
-?>
+      $penalty_type = ($marking_params['penalty_type']=='pp') ? ' pp' : '%' ;   // Add a space to the 'pp'.?>
     <p style="margin-bottom: 2em; padding-left: 1em; font-size: 0.8em;">
       (
-      Algorithm: <?php echo($marking_params['algorithm']); ?>. &nbsp;
+      Algorithm: <?php echo $marking_params['algorithm']; ?>. &nbsp;
 
-      Weighting: <?php echo($marking_params['weighting']); ?>%. &nbsp;
+      Weighting: <?php echo $marking_params['weighting']; ?>%. &nbsp;
 
-      Penalty: <?php echo($marking_params['penalty'].$penalty_type); ?>. &nbsp;
+      Penalty: <?php echo $marking_params['penalty'].$penalty_type; ?>. &nbsp;
 
       Grading: <?php
         if ($marking_params['grading']=='grade_af') {
-          echo('A-F.');
+            echo 'A-F.';
         } else {
-          echo('Numeric (%).');
-        }
-?>
+            echo 'Numeric (%).';
+        } ?>
       )
     </p>
 <?php
-  }
-?>
+  } ?>
 
   <h2 style="font-size: 150%;">Student Grades</h2>
 
@@ -160,35 +156,34 @@
   </tr>
 <?php
   foreach ($member_names as $i => $member) {
-    $score = (array_key_exists($member['user_id'], $webpa_scores)) ? $webpa_scores["{$member['user_id']}"] : '-' ;
-    $score = sprintf('%01.2f', $score);
-
-    $intermediate_grade = (array_key_exists($member['user_id'], $intermediate_grades)) ? $intermediate_grades["{$member['user_id']}"] : '-' ;
-    $grade = (array_key_exists($member['user_id'], $grades)) ? $grades["{$member['user_id']}"] : '-' ;
-    $grade = sprintf(APP__REPORT_DECIMALS, $grade);
-
-    // If this user was penalised
-    if (array_key_exists($member['user_id'], $penalties)) {
-      $penalty_str = ($penalties[$member['user_id']]==0) ? 'no penalty' : $penalties[$member['user_id']] ;
-    } else {
-      $penalty_str = '&nbsp;';
-    }
+      $score = (array_key_exists($member['user_id'], $webpa_scores)) ? $webpa_scores["{$member['user_id']}"] : '-' ;
+      $score = sprintf('%01.2f', $score);
+
+      $intermediate_grade = (array_key_exists($member['user_id'], $intermediate_grades)) ? $intermediate_grades["{$member['user_id']}"] : '-' ;
+      $grade = (array_key_exists($member['user_id'], $grades)) ? $grades["{$member['user_id']}"] : '-' ;
+      $grade = sprintf(APP__REPORT_DECIMALS, $grade);
+
+      // If this user was penalised
+      if (array_key_exists($member['user_id'], $penalties)) {
+          $penalty_str = ($penalties[$member['user_id']]==0) ? 'no penalty' : $penalties[$member['user_id']] ;
+      } else {
+          $penalty_str = '&nbsp;';
+      }
 
-    echo('<tr>');
-    echo("<td style=\"text-align: left\"> {$member['lastname']}, {$member['forename']} (");
-    if (!empty($member['id_number'])) {
-      echo($member['id_number']);
-    } else {
-      echo($member['username']);
-    }
-    echo(')</td>');
-    echo("<td>$score</td>");
-    echo("<td>$intermediate_grade</td>");
-    echo("<td>$penalty_str</td>");
-    echo("<td class=\"important\">$grade</td>");
-    echo('</tr>');
-  }
-?>
+      echo '<tr>';
+      echo "<td style=\"text-align: left\"> {$member['lastname']}, {$member['forename']} (";
+      if (!empty($member['id_number'])) {
+          echo $member['id_number'];
+      } else {
+          echo $member['username'];
+      }
+      echo ')</td>';
+      echo "<td>$score</td>";
+      echo "<td>$intermediate_grade</td>";
+      echo "<td>$penalty_str</td>";
+      echo "<td class=\"important\">$grade</td>";
+      echo '</tr>';
+  } ?>
   </table>
 
   </div>
@@ -204,36 +199,36 @@
  */
 
 if ($type == 'download-csv') {
-  header("Content-Disposition: attachment; filename=\"webpa_student_grades.csv\"");
-  header('Content-Type: text/csv');
+    header('Content-Disposition: attachment; filename="webpa_student_grades.csv"');
+    header('Content-Type: text/csv');
 
-  echo('"Student Grades (by student)"'."\n\n");
-  echo("\"{$assessment->name}\"\n\n");
+    echo '"Student Grades (by student)"'."\n\n";
+    echo "\"{$assessment->name}\"\n\n";
 
-  echo('"name","WebPA score","Intermediate Grade","Non-Submission Penalty","Final grade"'."\n");
+    echo '"name","WebPA score","Intermediate Grade","Non-Submission Penalty","Final grade"'."\n";
 
-  foreach ($member_names as $i => $member) {
-    $score = (array_key_exists($member['user_id'], $webpa_scores)) ? $webpa_scores["{$member['user_id']}"] : '-' ;
-    $score = sprintf('%01.2f', $score);
+    foreach ($member_names as $i => $member) {
+        $score = (array_key_exists($member['user_id'], $webpa_scores)) ? $webpa_scores["{$member['user_id']}"] : '-' ;
+        $score = sprintf('%01.2f', $score);
 
-    $intermediate_grade = (array_key_exists($member['user_id'], $intermediate_grades)) ? $intermediate_grades["{$member['user_id']}"] : '-' ;
-    $grade = (array_key_exists($member['user_id'], $grades)) ? $grades["{$member['user_id']}"] : '-' ;
+        $intermediate_grade = (array_key_exists($member['user_id'], $intermediate_grades)) ? $intermediate_grades["{$member['user_id']}"] : '-' ;
+        $grade = (array_key_exists($member['user_id'], $grades)) ? $grades["{$member['user_id']}"] : '-' ;
 
-    // If this user was penalised
-    if (array_key_exists($member['user_id'], $penalties)) {
-      $penalty_str = ($penalties[$member['user_id']]==0) ? 'no penalty' : $penalties[$member['user_id']] ;
-    } else {
-      $penalty_str = '';
-    }
+        // If this user was penalised
+        if (array_key_exists($member['user_id'], $penalties)) {
+            $penalty_str = ($penalties[$member['user_id']]==0) ? 'no penalty' : $penalties[$member['user_id']] ;
+        } else {
+            $penalty_str = '';
+        }
 
-    echo("\"{$member['lastname']}, {$member['forename']} (");
-    if (!empty($member['id_number'])) {
-      echo($member['id_number']);
-    } else {
-      echo($member['username']);
+        echo "\"{$member['lastname']}, {$member['forename']} (";
+        if (!empty($member['id_number'])) {
+            echo $member['id_number'];
+        } else {
+            echo $member['username'];
+        }
+        echo ")\",\"$score\",\"$intermediate_grade\",\"$penalty_str\",\"$grade\"\n";
     }
-    echo(")\",\"$score\",\"$intermediate_grade\",\"$penalty_str\",\"$grade\"\n");
-  }
 }
 
 /*
@@ -243,50 +238,50 @@
  */
 
 if ($type == 'download-xml') {
-  header("Content-Disposition: attachment; filename=\"webpa_student_grades.xml\"");
-  header('Content-Type: application/xml');
+    header('Content-Disposition: attachment; filename="webpa_student_grades.xml"');
+    header('Content-Type: application/xml');
 
-  echo("<?xml version=\"1.0\" ?>\n");
+    echo "<?xml version=\"1.0\" ?>\n";
 
-  echo("<assessment>\n");
-  echo("\t<assessment_title>{$assessment->name}</assessment_title>\n");
-  echo("\t<weighting>{$marking_params['weighting'] }</weighting>\n");
-  echo("\t<penalty>{$marking_params['penalty']}</penalty>\n");
+    echo "<assessment>\n";
+    echo "\t<assessment_title>{$assessment->name}</assessment_title>\n";
+    echo "\t<weighting>{$marking_params['weighting'] }</weighting>\n";
+    echo "\t<penalty>{$marking_params['penalty']}</penalty>\n";
 
-  foreach ($member_names as $i => $member) {
-    $score = (array_key_exists($member['user_id'], $webpa_scores)) ? $webpa_scores["{$member['user_id']}"] : '-' ;
-    $score = sprintf('%01.2f', $score);
+    foreach ($member_names as $i => $member) {
+        $score = (array_key_exists($member['user_id'], $webpa_scores)) ? $webpa_scores["{$member['user_id']}"] : '-' ;
+        $score = sprintf('%01.2f', $score);
 
-    $intermediate_grade = (array_key_exists($member['user_id'], $intermediate_grades)) ? $intermediate_grades["{$member['user_id']}"] : '-' ;
-    $grade = (array_key_exists($member['user_id'], $grades)) ? $grades["{$member['user_id']}"] : '-' ;
+        $intermediate_grade = (array_key_exists($member['user_id'], $intermediate_grades)) ? $intermediate_grades["{$member['user_id']}"] : '-' ;
+        $grade = (array_key_exists($member['user_id'], $grades)) ? $grades["{$member['user_id']}"] : '-' ;
 
-    // If this user was penalised
-    if (array_key_exists($member['user_id'], $penalties)) {
-      $penalty_str = ($penalties[$member['user_id']]==0) ? 'no penalty' : $penalties[$member['user_id']] ;
-    } else {
-      $penalty_str = '';
-    }
+        // If this user was penalised
+        if (array_key_exists($member['user_id'], $penalties)) {
+            $penalty_str = ($penalties[$member['user_id']]==0) ? 'no penalty' : $penalties[$member['user_id']] ;
+        } else {
+            $penalty_str = '';
+        }
 
-    echo("\t<student>\n");
-    echo("\t\t<name>\n");
-    echo("\t\t\t<forename>{$member['forename']}</forename>\n");
-    echo("\t\t\t<lastname>{$member['lastname']}</lastname>\n");
-    echo("\t\t</name>\n");
-    echo("\t\t<institutional_student_number>");
-    if (!empty($member['id_number'])) {
-      echo($member['id_number']);
-    } else {
-      echo($member['username']);
+        echo "\t<student>\n";
+        echo "\t\t<name>\n";
+        echo "\t\t\t<forename>{$member['forename']}</forename>\n";
+        echo "\t\t\t<lastname>{$member['lastname']}</lastname>\n";
+        echo "\t\t</name>\n";
+        echo "\t\t<institutional_student_number>";
+        if (!empty($member['id_number'])) {
+            echo $member['id_number'];
+        } else {
+            echo $member['username'];
+        }
+        echo "</institutional_student_number>\n";
+        echo "\t\t<webpa_score>{$score}</webpa_score>\n";
+        echo "\t\t<intermediate_grade>{$intermediate_grade}</intermediate_grade>\n";
+        echo "\t\t<penalty>{$penalty_str}</penalty>\n";
+        echo "\t\t<final_grade>{$grade}</final_grade>\n";
+        echo "\t</student>\n";
     }
-    echo("</institutional_student_number>\n");
-    echo("\t\t<webpa_score>{$score}</webpa_score>\n");
-    echo("\t\t<intermediate_grade>{$intermediate_grade}</intermediate_grade>\n");
-    echo("\t\t<penalty>{$penalty_str}</penalty>\n");
-    echo("\t\t<final_grade>{$grade}</final_grade>\n");
-    echo("\t</student>\n");
-  }
-
-  echo("</assessment>\n");
+
+    echo "</assessment>\n";
 }
 
 /*
@@ -297,47 +292,49 @@
  * http://docs.moodle.org/en/Development:Grades
  * --------------------------------------------------------------------------------
  */
-if ($type == 'download-moodle-xml'){
-  header("Content-Disposition: attachment; filename=\"webpa_student_grades.xml\"");
-  header('Content-Type: text/xml');
+if ($type == 'download-moodle-xml') {
+    header('Content-Disposition: attachment; filename="webpa_student_grades.xml"');
+    header('Content-Type: text/xml');
 
-  //create an id number which is the assessment and date for the unique upload number required
-  $tempAssessmentId = $assessment->id;
-  $tempAssessmentId = $tempAssessmentId . date("Ymd");;
+    //create an id number which is the assessment and date for the unique upload number required
+    $tempAssessmentId = $assessment->id;
+    $tempAssessmentId = $tempAssessmentId . date('Ymd');
+    ;
 
-  echo("<?xml version=\"1.0\" ?> ");
+    echo '<?xml version="1.0" ?> ';
 
-  echo("<results batch=\"[{$tempAssessmentId}]\">");
+    echo "<results batch=\"[{$tempAssessmentId}]\">";
 
-  foreach ($member_names as $i => $member) {
-    $score = (array_key_exists($member['user_id'], $webpa_scores)) ? $webpa_scores["{$member['user_id']}"] : '-' ;
-    $score = sprintf('%01.2f', $score);
+    foreach ($member_names as $i => $member) {
+        $score = (array_key_exists($member['user_id'], $webpa_scores)) ? $webpa_scores["{$member['user_id']}"] : '-' ;
+        $score = sprintf('%01.2f', $score);
 
-    $intermediate_grade = (array_key_exists($member['user_id'], $intermediate_grades)) ? $intermediate_grades["{$member['user_id']}"] : '-' ;
-    $grade = (array_key_exists($member['user_id'], $grades)) ? $grades["{$member['user_id']}"] : '-' ;
+        $intermediate_grade = (array_key_exists($member['user_id'], $intermediate_grades)) ? $intermediate_grades["{$member['user_id']}"] : '-' ;
+        $grade = (array_key_exists($member['user_id'], $grades)) ? $grades["{$member['user_id']}"] : '-' ;
 
-    // If this user was penalised
-    if (array_key_exists($member['user_id'], $penalties)) {
-      $penalty_str = ($penalties[$member['user_id']]==0) ? 'no penalty' : $penalties[$member['user_id']] ;
-    } else {
-      $penalty_str = '';
-    }
+        // If this user was penalised
+        if (array_key_exists($member['user_id'], $penalties)) {
+            $penalty_str = ($penalties[$member['user_id']]==0) ? 'no penalty' : $penalties[$member['user_id']] ;
+        } else {
+            $penalty_str = '';
+        }
 
-    echo("<result>");
-    echo("<state>['new']</state>");
-    echo("<assignment>{$assessment->id}</assignment>");;
-    echo("<student>");
-    if (!empty($member['id_number'])) {
-      echo($member['id_number']);
-    } else {
-      echo($member['username']);
+        echo '<result>';
+        echo "<state>['new']</state>";
+        echo "<assignment>{$assessment->id}</assignment>";
+        ;
+        echo '<student>';
+        if (!empty($member['id_number'])) {
+            echo $member['id_number'];
+        } else {
+            echo $member['username'];
+        }
+        echo '</student>';
+        echo "<score>{$grade}</score>";
+        echo '</result>';
     }
-    echo("</student>");
-    echo("<score>{$grade}</score>");
-    echo("</result>");
-  }
 
-  echo("</results>");
+    echo '</results>';
 }
 
 /*
@@ -346,41 +343,40 @@
  * --------------------------------------------------------------------------------
  */
 
-if ($type == 'download-rtf'){
-  header("Content-Disposition: attachment; filename=student_grades.rtf");
-  header("Content-Type: text/enriched\n");
+if ($type == 'download-rtf') {
+    header('Content-Disposition: attachment; filename=student_grades.rtf');
+    header("Content-Type: text/enriched\n");
 
-  echo "Assessment Name:\t{$assessment->name}\nWeighting:\t{$marking_params['weighting']}";
-  echo "\nPenalty:\t{$marking_params['penalty']}\n\n";
+    echo "Assessment Name:\t{$assessment->name}\nWeighting:\t{$marking_params['weighting']}";
+    echo "\nPenalty:\t{$marking_params['penalty']}\n\n";
 
 
-  foreach ($member_names as $i => $member) {
-    $score = (array_key_exists($member['user_id'], $webpa_scores)) ? $webpa_scores["{$member['user_id']}"] : '-' ;
-    $score = sprintf('%01.2f', $score);
+    foreach ($member_names as $i => $member) {
+        $score = (array_key_exists($member['user_id'], $webpa_scores)) ? $webpa_scores["{$member['user_id']}"] : '-' ;
+        $score = sprintf('%01.2f', $score);
 
-    $intermediate_grade = (array_key_exists($member['user_id'], $intermediate_grades)) ? $intermediate_grades["{$member['user_id']}"] : '-' ;
-    $grade = (array_key_exists($member['user_id'], $grades)) ? $grades["{$member['user_id']}"] : '-' ;
+        $intermediate_grade = (array_key_exists($member['user_id'], $intermediate_grades)) ? $intermediate_grades["{$member['user_id']}"] : '-' ;
+        $grade = (array_key_exists($member['user_id'], $grades)) ? $grades["{$member['user_id']}"] : '-' ;
 
-    // If this user was penalised
-    if (array_key_exists($member['user_id'], $penalties)) {
-      $penalty_str = ($penalties[$member['user_id']]==0) ? 'no penalty' : $penalties[$member['user_id']] ;
-    } else {
-      $penalty_str = '';
-    }
+        // If this user was penalised
+        if (array_key_exists($member['user_id'], $penalties)) {
+            $penalty_str = ($penalties[$member['user_id']]==0) ? 'no penalty' : $penalties[$member['user_id']] ;
+        } else {
+            $penalty_str = '';
+        }
 
-    echo "\nName:\t{$member['forename']} {$member['lastname']}";
-    echo "\nStudent Number:\t";
-    if (!empty($member['id_number'])) {
-      echo($member['id_number']);
-    } else {
-      echo($member['username']);
+        echo "\nName:\t{$member['forename']} {$member['lastname']}";
+        echo "\nStudent Number:\t";
+        if (!empty($member['id_number'])) {
+            echo $member['id_number'];
+        } else {
+            echo $member['username'];
+        }
+        echo "\nWebpa Score:\t{$score}";
+        echo "\nIntermediate grade:\t{$intermediate_grade}";
+        echo "\nPenalty:\t{$penalty_str}";
+        echo "\nFinal Grade:\t{$grade}\n";
     }
-    echo "\nWebpa Score:\t{$score}";
-    echo "\nIntermediate grade:\t{$intermediate_grade}";
-    echo "\nPenalty:\t{$penalty_str}";
-    echo "\nFinal Grade:\t{$grade}\n";
-
-  }
 }
 
 ?>
diff --git a/src/tutors/assessments/reports/report_student_grades_bygroup.php b/src/tutors/assessments/reports/report_student_grades_bygroup.php
index c376ec5..5dd7138 100644
--- a/src/tutors/assessments/reports/report_student_grades_bygroup.php
+++ b/src/tutors/assessments/reports/report_student_grades_bygroup.php
@@ -8,15 +8,15 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\AlgorithmFactory;
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -35,50 +35,51 @@
 
 $assessment = new Assessment($DB);
 if (!$assessment->load($assessment_id)) {
-  $assessment = null;
-  echo('Error: The requested assessment could not be loaded.');
-  exit;
-} else {
-
-  // ----------------------------------------
-  // Get the marking parameters used for the marksheet this report will display
-  $marking_params = $assessment->get_marking_params($marking_date);
-
-  if (!$marking_params) {
-    echo('Error: The requested marksheet could not be loaded.');
+    $assessment = null;
+    echo 'Error: The requested assessment could not be loaded.';
     exit;
-  }
-
-  // ----------------------------------------
-  // Get a list of the groups, and their marks, used in this assessment
-  $groups_and_marks = $assessment->get_group_marks();
+}
 
   // ----------------------------------------
-  // Get the appropriate algorithm and calculate the grades
-  $algorithm = AlgorithmFactory::get_algorithm($marking_params['algorithm']);
+    // Get the marking parameters used for the marksheet this report will display
+    $marking_params = $assessment->get_marking_params($marking_date);
 
-  if (!$algorithm) {
-    echo('Error: The requested algorithm could not be loaded.');
-    exit;
-  } else {
-    $algorithm->set_grade_ordinals($ordinal_scale);
-    $algorithm->set_assessment($assessment);
-    $algorithm->set_marking_params($marking_params);
-    $algorithm->calculate();
-
-    $submissions = $algorithm->get_submitters();
-    $webpa_scores = $algorithm->get_webpa_scores();
-    $group_names = $algorithm->get_group_names();
-    $group_members = $algorithm->get_group_members();
+    if (!$marking_params) {
+        echo 'Error: The requested marksheet could not be loaded.';
+        exit;
+    }
 
-    $intermediate_grades = $algorithm->get_intermediate_grades();
-    $grades = $algorithm->get_grades();
+    // ----------------------------------------
+    // Get a list of the groups, and their marks, used in this assessment
+    $groups_and_marks = $assessment->get_group_marks();
 
-    $penalties = $algorithm->get_penalties();
-    if (!$penalties) { $penalties = array(); }
-  }// /if-else(is algorithm)
+    // ----------------------------------------
+    // Get the appropriate algorithm and calculate the grades
+    $algorithm = AlgorithmFactory::get_algorithm($marking_params['algorithm']);
 
-}// /if-else(is assessment)
+    if (!$algorithm) {
+        echo 'Error: The requested algorithm could not be loaded.';
+        exit;
+    }
+        $algorithm->set_grade_ordinals($ordinal_scale);
+        $algorithm->set_assessment($assessment);
+        $algorithm->set_marking_params($marking_params);
+        $algorithm->calculate();
+
+        $submissions = $algorithm->get_submitters();
+        $webpa_scores = $algorithm->get_webpa_scores();
+        $group_names = $algorithm->get_group_names();
+        $group_members = $algorithm->get_group_members();
+
+        $intermediate_grades = $algorithm->get_intermediate_grades();
+        $grades = $algorithm->get_grades();
+
+        $penalties = $algorithm->get_penalties();
+        if (!$penalties) {
+            $penalties = [];
+        }
+    // /if-else(is algorithm)
+// /if-else(is assessment)
 
 /*
  * --------------------------------------------------------------------------------
@@ -87,13 +88,12 @@
  */
 
 if ($type == 'view') {
-  // Begin Page
+    // Begin Page
 
-  $page_title = ($assessment) ? "{$assessment->name}" : 'report';
+    $page_title = ($assessment) ? "{$assessment->name}" : 'report';
 
-  $UI->page_title = APP__NAME . ' ' . $page_title;
-  $UI->head();
-?>
+    $UI->page_title = APP__NAME . ' ' . $page_title;
+    $UI->head(); ?>
   <style type="text/css">
   <!--
 
@@ -109,44 +109,40 @@
   </style>
 <?php
   $UI->body();
-  $UI->content_start();
-?>
+    $UI->content_start(); ?>
 
   <div class="content_box">
 
 <?php
   if ($marking_params) {
-    $penalty_type = ($marking_params['penalty_type']=='pp') ? ' pp' : '%' ;   // Add a space to the 'pp'.
-?>
+      $penalty_type = ($marking_params['penalty_type']=='pp') ? ' pp' : '%' ;   // Add a space to the 'pp'.?>
     <p style="margin-bottom: 2em; padding-left: 1em; font-size: 0.8em;">
       (
-      Algorithm: <?php echo($marking_params['algorithm']); ?>. &nbsp;
+      Algorithm: <?php echo $marking_params['algorithm']; ?>. &nbsp;
 
-      Weighting: <?php echo($marking_params['weighting']); ?>%. &nbsp;
+      Weighting: <?php echo $marking_params['weighting']; ?>%. &nbsp;
 
-      Penalty: <?php echo($marking_params['penalty'].$penalty_type); ?>. &nbsp;
+      Penalty: <?php echo $marking_params['penalty'].$penalty_type; ?>. &nbsp;
 
       Grading: <?php
         if ($marking_params['grading']=='grade_af') {
-          echo('A-F.');
+            echo 'A-F.';
         } else {
-          echo('Numeric (%).');
-        }
-      ?>
+            echo 'Numeric (%).';
+        } ?>
       )
     </p>
 <?php
-  }
-?>
+  } ?>
 
   <h2 style="font-size: 150%;">Student Grades (by Group)</h2>
 
 <?php
   foreach ($group_members as $group_id => $g_members) {
-?>
+      ?>
     <div style="margin-top: 40px;">
-      <h3><?php echo($group_names[$group_id]); ?></h3>
-      <p>Overall group mark: <?php echo($groups_and_marks[$group_id]);?>%.</p>
+      <h3><?php echo $group_names[$group_id]; ?></h3>
+      <p>Overall group mark: <?php echo $groups_and_marks[$group_id]; ?>%.</p>
       <table class="grid" cellpadding="2" cellspacing="1">
       <tr>
         <th>name</th>
@@ -157,43 +153,40 @@
       </tr>
 <?php
     foreach ($g_members as $i => $member_id) {
+        $score = (array_key_exists($member_id, $webpa_scores)) ? $webpa_scores[$member_id] : '-' ;
+        $score = sprintf('%01.2f', $score);
 
-      $score = (array_key_exists($member_id, $webpa_scores)) ? $webpa_scores[$member_id] : '-' ;
-      $score = sprintf('%01.2f', $score);
-
-      $intermediate_grade = (array_key_exists($member_id, $intermediate_grades)) ? $intermediate_grades[$member_id] : '-' ;
-      $grade = (array_key_exists($member_id, $grades)) ? $grades[$member_id] : '-' ;
-      $grade = sprintf(APP__REPORT_DECIMALS, $grade);
-
-      // If this user was penalised
-      if (array_key_exists($member_id, $penalties)) {
-        $penalty_str = ($penalties[$member_id]==0) ? 'no penalty' : $penalties[$member_id] ;
-      } else {
-        $penalty_str = '&nbsp;';
-      }
-
-      $individ = $CIS->get_user($member_id);
-
-      echo('<tr>');
-      echo("<td style=\"text-align: left\"> {$individ['lastname']}, {$individ['forename']} (");
-      if (!empty($individ['id_number'])) {
-        echo($individ['id_number']);
-      } else {
-        echo($individ['username']);
-      }
-      echo(')</td>');
-      echo("<td>$score</td>");
-      echo("<td>$intermediate_grade</td>");
-      echo("<td>$penalty_str</td>");
-      echo("<td class=\"important\">$grade</td>");
-      echo('</tr>');
-    }
-?>
+        $intermediate_grade = (array_key_exists($member_id, $intermediate_grades)) ? $intermediate_grades[$member_id] : '-' ;
+        $grade = (array_key_exists($member_id, $grades)) ? $grades[$member_id] : '-' ;
+        $grade = sprintf(APP__REPORT_DECIMALS, $grade);
+
+        // If this user was penalised
+        if (array_key_exists($member_id, $penalties)) {
+            $penalty_str = ($penalties[$member_id]==0) ? 'no penalty' : $penalties[$member_id] ;
+        } else {
+            $penalty_str = '&nbsp;';
+        }
+
+        $individ = $CIS->get_user($member_id);
+
+        echo '<tr>';
+        echo "<td style=\"text-align: left\"> {$individ['lastname']}, {$individ['forename']} (";
+        if (!empty($individ['id_number'])) {
+            echo $individ['id_number'];
+        } else {
+            echo $individ['username'];
+        }
+        echo ')</td>';
+        echo "<td>$score</td>";
+        echo "<td>$intermediate_grade</td>";
+        echo "<td>$penalty_str</td>";
+        echo "<td class=\"important\">$grade</td>";
+        echo '</tr>';
+    } ?>
       </table>
     </div>
 <?php
-  }
-?>
+  } ?>
 
   </div>
 
@@ -208,49 +201,48 @@
  */
 
 if ($type == 'download-csv') {
-  header("Content-Disposition: attachment; filename=\"webpa_grades_by_group.csv\"");
-  header('Content-Type: text/csv');
-
-  echo('"Student Grades (by group)"'."\n\n");
-  echo("\"{$assessment->name}\"\n\n");
-
-  foreach( $group_members as $group_id => $g_members) {
-    echo("\"Group\",\"{$group_names[$group_id]}\"\n");
-    echo("\"Overall group mark\",\"{$groups_and_marks[$group_id]}\"\n");
-
-    echo('"Name","WebPA score","Intermediate Grade","Non-Submission Penalty","Final Grade"'."\n");
-
-    foreach ($g_members as $i => $member_id) {
-
-      $score = (array_key_exists($member_id, $webpa_scores)) ? $webpa_scores[$member_id] : '-' ;
-      $score = sprintf('%01.2f', $score);
-
-      $intermediate_grade = (array_key_exists($member_id, $intermediate_grades)) ? $intermediate_grades[$member_id] : '-' ;
-      $grade = (array_key_exists($member_id, $grades)) ? $grades[$member_id] : '-' ;
-
-      // If this user was penalised
-      if (array_key_exists($member_id, $penalties)) {
-        $penalty_str = ($penalties[$member_id]==0) ? 'no penalty' : $penalties[$member_id] ;
-      } else {
-        $penalty_str = '';
-      }
-
-      $individ = $CIS->get_user($member_id);
-
-      echo("\"{$individ['lastname']}, {$individ['forename']} (");
-      if (!empty($individ['id_number'])) {
-        echo($individ['id_number']);
-      } else {
-        echo($individ['username']);
-      }
-      echo(')",');
-      echo("\"$score\",");
-      echo("\"$intermediate_grade\",");
-      echo("\"$penalty_str\",");
-      echo("\"$grade\"\n");
+    header('Content-Disposition: attachment; filename="webpa_grades_by_group.csv"');
+    header('Content-Type: text/csv');
+
+    echo '"Student Grades (by group)"'."\n\n";
+    echo "\"{$assessment->name}\"\n\n";
+
+    foreach ($group_members as $group_id => $g_members) {
+        echo "\"Group\",\"{$group_names[$group_id]}\"\n";
+        echo "\"Overall group mark\",\"{$groups_and_marks[$group_id]}\"\n";
+
+        echo '"Name","WebPA score","Intermediate Grade","Non-Submission Penalty","Final Grade"'."\n";
+
+        foreach ($g_members as $i => $member_id) {
+            $score = (array_key_exists($member_id, $webpa_scores)) ? $webpa_scores[$member_id] : '-' ;
+            $score = sprintf('%01.2f', $score);
+
+            $intermediate_grade = (array_key_exists($member_id, $intermediate_grades)) ? $intermediate_grades[$member_id] : '-' ;
+            $grade = (array_key_exists($member_id, $grades)) ? $grades[$member_id] : '-' ;
+
+            // If this user was penalised
+            if (array_key_exists($member_id, $penalties)) {
+                $penalty_str = ($penalties[$member_id]==0) ? 'no penalty' : $penalties[$member_id] ;
+            } else {
+                $penalty_str = '';
+            }
+
+            $individ = $CIS->get_user($member_id);
+
+            echo "\"{$individ['lastname']}, {$individ['forename']} (";
+            if (!empty($individ['id_number'])) {
+                echo $individ['id_number'];
+            } else {
+                echo $individ['username'];
+            }
+            echo ')",';
+            echo "\"$score\",";
+            echo "\"$intermediate_grade\",";
+            echo "\"$penalty_str\",";
+            echo "\"$grade\"\n";
+        }
+        echo "\n\n";
     }
-    echo("\n\n");
-  }
 }
 
 /*
@@ -260,61 +252,60 @@
  */
 
 if ($type == 'download-xml') {
-  header("Content-Disposition: attachment; filename=\"webpa_grades_by_group.xml\"");
-  header('Content-Type: application/xml');
-
-  echo("<?xml version=\"1.0\" ?>\n");
-
-  echo("<assessment>\n");
-  echo("\t<assessment_title>{$assessment->name}</assessment_title>\n");
-  echo("\t<weighting>{$marking_params['weighting'] }</weighting>\n");
-  echo("\t<penalty>{$marking_params['penalty']}</penalty>\n");
-
-  foreach ($group_members as $group_id => $g_members) {
-
-    echo("\t<group>\n");
-    echo("\t\t<group_name>{$group_names[$group_id]}</group_name>\n");
-    echo("\t\t<group_mark>{$groups_and_marks[$group_id]}</group_mark>\n");
-    echo("\t\t<group_members>\n");
-
-    foreach ($g_members as $i => $member_id) {
-      $score = (array_key_exists($member_id, $webpa_scores)) ? $webpa_scores[$member_id] : '-' ;
-      $score = sprintf('%01.2f', $score);
-
-      $intermediate_grade = (array_key_exists($member_id, $intermediate_grades)) ? $intermediate_grades[$member_id] : '-' ;
-      $grade = (array_key_exists($member_id, $grades)) ? $grades[$member_id] : '-' ;
-
-      // If this user was penalised
-      if (array_key_exists($member_id, $penalties)) {
-        $penalty_str = ($penalties[$member_id]==0) ? 'no penalty' : $penalties[$member_id] ;
-      } else {
-        $penalty_str = '';
-      }
-
-      $individ = $CIS->get_user($member_id);
-
-      echo("\t\t\t<student>\n");
-      echo("\t\t\t\t<name>\n");
-      echo("\t\t\t\t\t<forename>{$individ['forename']}</forename>\n");
-      echo("\t\t\t\t\t<lastname>{$individ['lastname']}</lastname>\n");
-      echo("\t\t\t\t</name>\n");
-      echo("\t\t\t\t<institutional_student_number>");
-      if (!empty($individ['id_number'])) {
-        echo($individ['id_number']);
-      } else {
-        echo($individ['username']);
-      }
-      echo("</institutional_student_number>\n");
-      echo("\t\t\t\t<webpa_score>$score</webpa_score>\n");
-      echo("\t\t\t\t<intermediate_grade>$intermediate_grade</intermediate_grade>\n");
-      echo("\t\t\t\t<penalty>$penalty_str</penalty>\n");
-      echo("\t\t\t\t<final_grade>$grade</final_grade>\n");
-      echo("\t\t\t</student>\n");
+    header('Content-Disposition: attachment; filename="webpa_grades_by_group.xml"');
+    header('Content-Type: application/xml');
+
+    echo "<?xml version=\"1.0\" ?>\n";
+
+    echo "<assessment>\n";
+    echo "\t<assessment_title>{$assessment->name}</assessment_title>\n";
+    echo "\t<weighting>{$marking_params['weighting'] }</weighting>\n";
+    echo "\t<penalty>{$marking_params['penalty']}</penalty>\n";
+
+    foreach ($group_members as $group_id => $g_members) {
+        echo "\t<group>\n";
+        echo "\t\t<group_name>{$group_names[$group_id]}</group_name>\n";
+        echo "\t\t<group_mark>{$groups_and_marks[$group_id]}</group_mark>\n";
+        echo "\t\t<group_members>\n";
+
+        foreach ($g_members as $i => $member_id) {
+            $score = (array_key_exists($member_id, $webpa_scores)) ? $webpa_scores[$member_id] : '-' ;
+            $score = sprintf('%01.2f', $score);
+
+            $intermediate_grade = (array_key_exists($member_id, $intermediate_grades)) ? $intermediate_grades[$member_id] : '-' ;
+            $grade = (array_key_exists($member_id, $grades)) ? $grades[$member_id] : '-' ;
+
+            // If this user was penalised
+            if (array_key_exists($member_id, $penalties)) {
+                $penalty_str = ($penalties[$member_id]==0) ? 'no penalty' : $penalties[$member_id] ;
+            } else {
+                $penalty_str = '';
+            }
+
+            $individ = $CIS->get_user($member_id);
+
+            echo "\t\t\t<student>\n";
+            echo "\t\t\t\t<name>\n";
+            echo "\t\t\t\t\t<forename>{$individ['forename']}</forename>\n";
+            echo "\t\t\t\t\t<lastname>{$individ['lastname']}</lastname>\n";
+            echo "\t\t\t\t</name>\n";
+            echo "\t\t\t\t<institutional_student_number>";
+            if (!empty($individ['id_number'])) {
+                echo $individ['id_number'];
+            } else {
+                echo $individ['username'];
+            }
+            echo "</institutional_student_number>\n";
+            echo "\t\t\t\t<webpa_score>$score</webpa_score>\n";
+            echo "\t\t\t\t<intermediate_grade>$intermediate_grade</intermediate_grade>\n";
+            echo "\t\t\t\t<penalty>$penalty_str</penalty>\n";
+            echo "\t\t\t\t<final_grade>$grade</final_grade>\n";
+            echo "\t\t\t</student>\n";
+        }
+        echo "\t\t</group_members>\n";
+        echo "\t</group>\n";
     }
-    echo("\t\t</group_members>\n");
-    echo("\t</group>\n");
-  }
-  echo("</assessment>\n");
+    echo "</assessment>\n";
 }
 
 /*
@@ -324,47 +315,45 @@
  */
 
 if ($type == 'download-rtf') {
-  header("Content-Disposition: attachment; filename=\"webpa_grades_by_group.rtf\"");
-  header("Content-Type: text/enriched\n");
-
-  echo("Assessment Title: \t{$assessment->name}");
-  echo("\nWeighting: \t{$marking_params['weighting'] }");
-  echo("\nPenalty: \t{$marking_params['penalty']}");
-
-  foreach ($group_members as $group_id => $g_members) {
-
-    echo("\n\n\nGroup name: \t{$group_names[$group_id]}");
-    echo("\nGroup mark: \t{$groups_and_marks[$group_id]}");
-
-    foreach ($g_members as $i => $member_id) {
-
-      $score = (array_key_exists($member_id, $webpa_scores)) ? $webpa_scores[$member_id] : '-' ;
-      $score = sprintf('%01.2f', $score);
-
-      $intermediate_grade = (array_key_exists($member_id, $intermediate_grades)) ? $intermediate_grades[$member_id] : '-' ;
-      $grade = (array_key_exists($member_id, $grades)) ? $grades[$member_id] : '-' ;
-
-      // If this user was penalised
-      if (array_key_exists($member_id, $penalties)) {
-        $penalty_str = ($penalties[$member_id]==0) ? 'no penalty' : $penalties[$member_id] ;
-      } else {
-        $penalty_str = '';
-      }
-
-      $individ = $CIS->get_user($member_id);
-
-      echo("\n\n\tName:\t{$individ['forename']} {$individ['lastname']}");
-      echo("\n\tInstitutional student number:\t");
-      if (!empty($individ['id_number'])) {
-        echo($individ['id_number']);
-      } else {
-        echo($individ['username']);
-      }
-      echo("\n\tWebpa score:\t{$score}");
-      echo("\n\tIntermediate grade:\t{$intermediate_grade}");
-      echo("\n\tPenalty:\t{$penalty_str}");
-      echo("\n\tFinal grade:\t{$grade}");
+    header('Content-Disposition: attachment; filename="webpa_grades_by_group.rtf"');
+    header("Content-Type: text/enriched\n");
+
+    echo "Assessment Title: \t{$assessment->name}";
+    echo "\nWeighting: \t{$marking_params['weighting'] }";
+    echo "\nPenalty: \t{$marking_params['penalty']}";
+
+    foreach ($group_members as $group_id => $g_members) {
+        echo "\n\n\nGroup name: \t{$group_names[$group_id]}";
+        echo "\nGroup mark: \t{$groups_and_marks[$group_id]}";
+
+        foreach ($g_members as $i => $member_id) {
+            $score = (array_key_exists($member_id, $webpa_scores)) ? $webpa_scores[$member_id] : '-' ;
+            $score = sprintf('%01.2f', $score);
+
+            $intermediate_grade = (array_key_exists($member_id, $intermediate_grades)) ? $intermediate_grades[$member_id] : '-' ;
+            $grade = (array_key_exists($member_id, $grades)) ? $grades[$member_id] : '-' ;
+
+            // If this user was penalised
+            if (array_key_exists($member_id, $penalties)) {
+                $penalty_str = ($penalties[$member_id]==0) ? 'no penalty' : $penalties[$member_id] ;
+            } else {
+                $penalty_str = '';
+            }
+
+            $individ = $CIS->get_user($member_id);
+
+            echo "\n\n\tName:\t{$individ['forename']} {$individ['lastname']}";
+            echo "\n\tInstitutional student number:\t";
+            if (!empty($individ['id_number'])) {
+                echo $individ['id_number'];
+            } else {
+                echo $individ['username'];
+            }
+            echo "\n\tWebpa score:\t{$score}";
+            echo "\n\tIntermediate grade:\t{$intermediate_grade}";
+            echo "\n\tPenalty:\t{$penalty_str}";
+            echo "\n\tFinal grade:\t{$grade}";
+        }
     }
-  }
 }
 ?>
diff --git a/src/tutors/assessments/reports/report_student_grades_comments.php b/src/tutors/assessments/reports/report_student_grades_comments.php
index f68344e..1f595b4 100644
--- a/src/tutors/assessments/reports/report_student_grades_comments.php
+++ b/src/tutors/assessments/reports/report_student_grades_comments.php
@@ -8,15 +8,16 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\AlgorithmFactory;
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -35,75 +36,79 @@
 
 $assessment = new Assessment($DB);
 if (!$assessment->load($assessment_id)) {
-  $assessment = null;
-  echo('Error: The requested assessment could not be loaded.');
-  exit;
-} else {
-
-  // ----------------------------------------
-  // Get the marking parameters used for the marksheet this report will display
-  $marking_params = $assessment->get_marking_params($marking_date);
-
-  if (!$marking_params) {
-    echo('Error: The requested marksheet could not be loaded.');
+    $assessment = null;
+    echo 'Error: The requested assessment could not be loaded.';
     exit;
-  }
+}
 
   // ----------------------------------------
-  // Get a list of the groups, and their marks, used in this assessment
-  $groups_and_marks = $assessment->get_group_marks();
+    // Get the marking parameters used for the marksheet this report will display
+    $marking_params = $assessment->get_marking_params($marking_date);
 
-  // ----------------------------------------
-  // Get the appropriate algorithm and calculate the grades
-  $algorithm = AlgorithmFactory::get_algorithm($marking_params['algorithm']);
+    if (!$marking_params) {
+        echo 'Error: The requested marksheet could not be loaded.';
+        exit;
+    }
 
-  if (!$algorithm) {
-    echo('Error: The requested algorithm could not be loaded.');
-    exit;
-  } else {
-    $algorithm->set_grade_ordinals($ordinal_scale);
-    $algorithm->set_assessment($assessment);
-    $algorithm->set_marking_params($marking_params);
-    $algorithm->calculate();
+    // ----------------------------------------
+    // Get a list of the groups, and their marks, used in this assessment
+    $groups_and_marks = $assessment->get_group_marks();
 
-    $submissions = $algorithm->get_submitters();
-    $webpa_scores = $algorithm->get_webpa_scores();
+    // ----------------------------------------
+    // Get the appropriate algorithm and calculate the grades
+    $algorithm = AlgorithmFactory::get_algorithm($marking_params['algorithm']);
 
-    $intermediate_grades = $algorithm->get_intermediate_grades();
-    $grades = $algorithm->get_grades();
+    if (!$algorithm) {
+        echo 'Error: The requested algorithm could not be loaded.';
+        exit;
+    }
+        $algorithm->set_grade_ordinals($ordinal_scale);
+        $algorithm->set_assessment($assessment);
+        $algorithm->set_marking_params($marking_params);
+        $algorithm->calculate();
 
-    $penalties = $algorithm->get_penalties();
-    if (!$penalties) { $penalties = array(); }
+        $submissions = $algorithm->get_submitters();
+        $webpa_scores = $algorithm->get_webpa_scores();
 
-    $group_names = $algorithm->get_group_names();
-    $group_members = $algorithm->get_group_members();
-    $member_ids = array_keys($webpa_scores);
+        $intermediate_grades = $algorithm->get_intermediate_grades();
+        $grades = $algorithm->get_grades();
 
-    $member_names = array();
+        $penalties = $algorithm->get_penalties();
+        if (!$penalties) {
+            $penalties = [];
+        }
 
-    for ($i =0; $i<count($group_members); $i++){
-      $array_key = array_keys($group_members);
-      $temp = $group_members[$array_key[$i]];
-      for ($j=0; $j<count($temp);$j++){
-        array_push($member_names, $CIS->get_user($temp[$j]));
-      }
-    }
-  }// /if-else(is algorithm)
+        $group_names = $algorithm->get_group_names();
+        $group_members = $algorithm->get_group_members();
+        $member_ids = array_keys($webpa_scores);
 
-  //------------------------------------------------------------
-  //get the feedback / Justification
-  $sql = "SELECT * FROM " . APP__DB_TABLE_PREFIX . "user_justification WHERE assessment_id = '{$assessment->id}'";
+        $member_names = [];
 
-  $fetch_comments = $DB->fetch($sql);
+        for ($i =0; $i<count($group_members); $i++) {
+            $array_key = array_keys($group_members);
+            $temp = $group_members[$array_key[$i]];
+            for ($j=0; $j<count($temp);$j++) {
+                array_push($member_names, $CIS->get_user($temp[$j]));
+            }
+        }
+    // /if-else(is algorithm)
+
+    //------------------------------------------------------------
+    //get the feedback / Justification
+    $feedbackQuery =
+      'SELECT * ' .
+      'FROM ' . APP__DB_TABLE_PREFIX . 'user_justification ' .
+      'WHERE assessment_id = ?';
 
-  $feedback = null;
+    $fetch_comments = $DB->getConnection()->fetchAllAssociative($feedbackQuery, [$assessment->id], [ParameterType::STRING]);
 
-  foreach ($fetch_comments as $i => $comment){
-    $marked_id = $comment['marked_user_id'];
-    $feedback []  = array('marked_id' => $marked_id, 'feedback' => $comment['justification_text']);
-  }
+    $feedback = null;
 
-}// /if-else(is assessment)
+    foreach ($fetch_comments as $i => $comment) {
+        $marked_id = $comment['marked_user_id'];
+        $feedback []  = ['marked_id' => $marked_id, 'feedback' => $comment['justification_text']];
+    }
+// /if-else(is assessment)
 
 /*
  * --------------------------------------------------------------------------------
@@ -112,56 +117,54 @@
  */
 
 if ($type == 'download-csv') {
-  header("Content-Disposition: attachment; filename=\"webpa_student_grades_comments.csv\"");
-  header('Content-Type: text/csv');
+    header('Content-Disposition: attachment; filename="webpa_student_grades_comments.csv"');
+    header('Content-Type: text/csv');
 
-  echo('"Student Grades and Feedback (by student)"'."\n\n");
-  echo("\"{$assessment->name}\"\n\n");
+    echo '"Student Grades and Feedback (by student)"'."\n\n";
+    echo "\"{$assessment->name}\"\n\n";
 
-  echo('"User Id","WebPA score","Intermediate Grade","Non-Submission Penalty","Final grade","Group","Comments"'."\n");
+    echo '"User Id","WebPA score","Intermediate Grade","Non-Submission Penalty","Final grade","Group","Comments"'."\n";
 
-  foreach ($member_names as $i => $member) {
-    $score = (array_key_exists($member['user_id'], $webpa_scores)) ? $webpa_scores["{$member['user_id']}"] : '-' ;
-    $score = sprintf('%01.2f', $score);
+    foreach ($member_names as $i => $member) {
+        $score = (array_key_exists($member['user_id'], $webpa_scores)) ? $webpa_scores["{$member['user_id']}"] : '-' ;
+        $score = sprintf('%01.2f', $score);
 
-    $intermediate_grade = (array_key_exists($member['user_id'], $intermediate_grades)) ? $intermediate_grades["{$member['user_id']}"] : '-' ;
-    $grade = (array_key_exists($member['user_id'], $grades)) ? $grades["{$member['user_id']}"] : '-' ;
+        $intermediate_grade = (array_key_exists($member['user_id'], $intermediate_grades)) ? $intermediate_grades["{$member['user_id']}"] : '-' ;
+        $grade = (array_key_exists($member['user_id'], $grades)) ? $grades["{$member['user_id']}"] : '-' ;
 
-    // If this user was penalised
-    if (array_key_exists($member['user_id'], $penalties)) {
-      $penalty_str = ($penalties[$member['user_id']]==0) ? 'no penalty' : $penalties[$member['user_id']] ;
-    } else {
-      $penalty_str = '';
-    }
-
-    //print user id and grades
-    echo('"');
-    if (!empty($member['id_number'])) {
-      echo($member['id_number']);
-    } else {
-      echo($member['username']);
-    }
-    echo("\",\"$score\",\"$intermediate_grade\",\"$penalty_str\",\"$grade\",");
+        // If this user was penalised
+        if (array_key_exists($member['user_id'], $penalties)) {
+            $penalty_str = ($penalties[$member['user_id']]==0) ? 'no penalty' : $penalties[$member['user_id']] ;
+        } else {
+            $penalty_str = '';
+        }
 
-    //print member's group name
-    foreach ($group_members as $group_id => $g_members) {
-      foreach ($g_members as $k => $member_id) {
-        if ($member['user_id'] == $g_members[$k]) {
-          echo("\"{$group_names[$group_id]}\",");
+        //print user id and grades
+        echo '"';
+        if (!empty($member['id_number'])) {
+            echo $member['id_number'];
+        } else {
+            echo $member['username'];
+        }
+        echo "\",\"$score\",\"$intermediate_grade\",\"$penalty_str\",\"$grade\",";
+
+        //print member's group name
+        foreach ($group_members as $group_id => $g_members) {
+            foreach ($g_members as $k => $member_id) {
+                if ($member['user_id'] == $g_members[$k]) {
+                    echo "\"{$group_names[$group_id]}\",";
+                }
+            }
         }
-      }
-    }
 
-    echo("\"");
+        echo '"';
 
-    //print out feedback for each user
-    foreach ($feedback as $j) {
-      if ($j['marked_id'] == $member['user_id']) {
-        echo("{$j['feedback']}\n\n");
-      }
+        //print out feedback for each user
+        foreach ($feedback as $j) {
+            if ($j['marked_id'] == $member['user_id']) {
+                echo "{$j['feedback']}\n\n";
+            }
+        }
+        echo "\"\n";
     }
-    echo("\"\n");
-  }
 }
-
-?>
diff --git a/src/tutors/assessments/reports/report_student_response_info.php b/src/tutors/assessments/reports/report_student_response_info.php
index 81d38d5..561b875 100644
--- a/src/tutors/assessments/reports/report_student_response_info.php
+++ b/src/tutors/assessments/reports/report_student_response_info.php
@@ -8,8 +8,9 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\classes\Form;
 use WebPA\includes\classes\GroupHandler;
@@ -21,8 +22,8 @@
 use WebPA\includes\functions\TimeDiff;
 
 if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -41,97 +42,101 @@
 
 $assessment = new Assessment($DB);
 if ($assessment->load($assessment_id)) {
+    $xml_parser = new XMLParser();
 
-  $xml_parser = new XMLParser();
-
-  // ----------------------------------------
-  // Get the marking parameters used for the marksheet this report will display
-
-  $md_mysql_date = date(MYSQL_DATETIME_FORMAT, $marking_date);
-
-  $params_xml = $DB->fetch_value( "SELECT marking_params
-                  FROM " . APP__DB_TABLE_PREFIX . "assessment_marking
-                  WHERE assessment_id = '$assessment->id'
-                    AND date_created = '$md_mysql_date'
-                  LIMIT 1");
-
-  $params = $xml_parser->parse($params_xml);
-
-  if (array_key_exists('parameters', $params)) {
-    $marking_params['weighting'] = $params['parameters']['weighting']['_attributes']['value'];
-    $marking_params['penalty'] = $params['parameters']['penalty']['_attributes']['value'];
-  } else {
-    $marking_params['weighting']= 100;
-    $marking_params['penalty'] = 0;
-  }
-
-  // ----------------------------------------
-  // Get a list of the members who took this assessment (grouped by 'group')
-  $groups_and_marks = null;
-  $group_members = null;
-  $group_names = null;
-
-  $group_handler = new GroupHandler();
-  $collection = $group_handler->get_collection($assessment->get_collection_id());
-  $groups_iterator = $collection->get_groups_iterator();
-  if ($groups_iterator->size()>0) {
-    for ($groups_iterator->reset(); $groups_iterator->is_valid(); $groups_iterator->next()) {
-      $group =& $groups_iterator->current();
-      $group_members["{$group->id}"] = $group->get_member_ids();
-      $group_names["{$group->id}"] = $group->name;
-      $groups_and_marks["{$group->id}"] = null;
+    // ----------------------------------------
+    // Get the marking parameters used for the marksheet this report will display
+
+    $md_mysql_date = date(MYSQL_DATETIME_FORMAT, $marking_date);
+
+    $getMarksheetParameterQuery =
+      'SELECT marking_params ' .
+      'FROM ' . APP__DB_TABLE_PREFIX . 'assessment_marking ' .
+      'WHERE assessment_id = ? ' .
+      'AND date_created = ? ' .
+      'LIMIT 1';
+
+    $params_xml = $DB->getConnection()->fetchOne($getMarksheetParameterQuery, [$assessment->id, $md_mysql_date], [ParameterType::STRING, ParameterType::STRING]);
+
+    $params = $xml_parser->parse($params_xml);
+
+    if (array_key_exists('parameters', $params)) {
+        $marking_params['weighting'] = $params['parameters']['weighting']['_attributes']['value'];
+        $marking_params['penalty'] = $params['parameters']['penalty']['_attributes']['value'];
+    } else {
+        $marking_params['weighting']= 100;
+        $marking_params['penalty'] = 0;
     }
-  }
 
-  // ----------------------------------------
-  // Get the questions used in this assessment
-  $form = new Form($DB);
-  $form_xml = $assessment->get_form_xml();
-  $form->load_from_xml($form_xml);
-  $question_count = (int) $form->get_question_count();
+    // ----------------------------------------
+    // Get a list of the members who took this assessment (grouped by 'group')
+    $groups_and_marks = null;
+    $group_members = null;
+    $group_names = null;
+
+    $group_handler = new GroupHandler();
+    $collection = $group_handler->get_collection($assessment->get_collection_id());
+    $groups_iterator = $collection->get_groups_iterator();
+    if ($groups_iterator->size()>0) {
+        for ($groups_iterator->reset(); $groups_iterator->is_valid(); $groups_iterator->next()) {
+            $group =& $groups_iterator->current();
+            $group_members["{$group->id}"] = $group->get_member_ids();
+            $group_names["{$group->id}"] = $group->name;
+            $groups_and_marks["{$group->id}"] = null;
+        }
+    }
 
-  // Create the actual array (question_ids are 0-based)
-  if ($question_count>0) {
-    $questions = range(0, $question_count-1);
-  } else {
-    $questions = array();
-  }
+    // ----------------------------------------
+    // Get the questions used in this assessment
+    $form = new Form($DB);
+    $form_xml = $assessment->get_form_xml();
+    $form->load_from_xml($form_xml);
+    $question_count = (int) $form->get_question_count();
+
+    // Create the actual array (question_ids are 0-based)
+    if ($question_count>0) {
+        $questions = range(0, $question_count-1);
+    } else {
+        $questions = [];
+    }
 
-  // ----------------------------------------
-  // Get the student submissions for this assessment
-  $result_handler = new ResultHandler($DB);
-  $result_handler->set_assessment($assessment);
+    // ----------------------------------------
+    // Get the student submissions for this assessment
+    $result_handler = new ResultHandler($DB);
+    $result_handler->set_assessment($assessment);
 
-  $responses = $result_handler->get_responses();
+    $responses = $result_handler->get_responses();
 
-  // ----------------------------------------
-  $algorithm = new NewAlgorithm();
-  $algorithm->set_marking_params($marking_params);
-  $algorithm->set_groups($groups_and_marks);
-  $algorithm->set_group_members($group_members);
-  $algorithm->set_questions($questions);
-  $algorithm->set_responses($responses);
+    // ----------------------------------------
+    $algorithm = new NewAlgorithm();
+    $algorithm->set_marking_params($marking_params);
+    $algorithm->set_groups($groups_and_marks);
+    $algorithm->set_group_members($group_members);
+    $algorithm->set_questions($questions);
+    $algorithm->set_responses($responses);
 
-  $algorithm->calculate();
+    $algorithm->calculate();
 
-  $webpa_scores = $algorithm->get_webpa_scores();
+    $webpa_scores = $algorithm->get_webpa_scores();
 
-  $member_ids = array_keys($webpa_scores);
+    $member_ids = array_keys($webpa_scores);
 
-  $members_raw = $CIS->get_user($member_ids);
+    $members_raw = $CIS->get_user($member_ids);
 
-  $members = ArrayFunctions::array_get_assoc($members_raw,'user_id');
+    $members = ArrayFunctions::array_get_assoc($members_raw, 'user_id');
 
-  // Get Student Response Information
-  $response_info = $DB->fetch_assoc("SELECT user_id, ip_address, comp_name, date_responded, date_opened
-                    FROM " . APP__DB_TABLE_PREFIX . "user_response
-                    WHERE assessment_id = '$assessment->id'");
+    // Get Student Response Information
+    $responseInfoQuery =
+      'SELECT user_id, ip_address, comp_name, date_responded, date_opened ' .
+      'FROM ' . APP__DB_TABLE_PREFIX . 'user_response ' .
+      'WHERE assessment_id = ?';
 
+    $response_info = $DB->getConnection()->fetchAllAssociativeIndexed($responseInfoQuery, [$assessment->id], [ParameterType::STRING]);
 } else {
-  $assessment = null;
+    $assessment = null;
 
-  echo('Error: The assessment could not be loaded.');
-  exit;
+    echo 'Error: The assessment could not be loaded.';
+    exit;
 }
 
 /*
@@ -140,13 +145,12 @@
 * --------------------------------------------------------------------------------
 */
 if ($type == 'view') {
-  // Begin Page
+    // Begin Page
 
-  $page_title = ($assessment) ? "{$assessment->name}" : 'report';
+    $page_title = ($assessment) ? "{$assessment->name}" : 'report';
 
-  $UI->page_title = APP__NAME . ' ' . $page_title;
-  $UI->head();
-?>
+    $UI->page_title = APP__NAME . ' ' . $page_title;
+    $UI->head(); ?>
   <style type="text/css">
   <!--
 
@@ -160,8 +164,7 @@
   </style>
 <?php
   $UI->body();
-  $UI->content_start();
-?>
+    $UI->content_start(); ?>
 
   <div class="content_box">
 
@@ -169,10 +172,10 @@
 
 <?php
   if (($assessment) && ($groups_iterator->size()>0)) {
-    foreach ($group_members as $group_id => $g_members) {
-?>
+      foreach ($group_members as $group_id => $g_members) {
+          ?>
       <div style="margin-top: 40px;">
-        <h3><?php echo($group_names[$group_id]); ?></h3>
+        <h3><?php echo $group_names[$group_id]; ?></h3>
         <table class="grid" cellpadding="2" cellspacing="1">
         <tr>
           <th>name</th>
@@ -184,51 +187,48 @@
         </tr>
 <?php
       foreach ($g_members as $i => $member_id) {
-
-        if ((is_array($response_info)) && (array_key_exists($member_id, $response_info))) {
-          $info = $response_info[$member_id];
-
-          $started_dt = strtotime($info['date_opened']);
-          $started = date('d M, Y \<\b\r \/\>H:i:s',$started_dt);
-          $finished_dt = strtotime($info['date_responded']);
-          $finished = date('d M, Y \<\b\r \/\>H:i:s',$finished_dt);
-
-          $time_taken = TimeDiff::calculate($started_dt, $finished_dt);
-
-          $ip_address = $info['ip_address'];
-          $computer_name = $info['comp_name'];
-        } else {
-          $started = '';
-          $finished = '';
-          $time_taken = '';
-          $ip_address = '';
-          $computer_name = '';
-        }
-
-        $individ = $CIS->get_user($member_id);
-
-        echo('<tr>');
-        echo("<td style=\"text-align: left\"> {$individ['lastname']}, {$individ['forename']} (");
-        if (!empty($individ['id_number'])) {
-          echo($individ['id_number']);
-        } else {
-          echo($individ['username']);
-        }
-        echo(')</td>');
-        echo("<td>$started</td>");
-        echo("<td>$finished</td>");
-        echo("<td>$time_taken</td>");
-        echo("<td>$ip_address</td>");
-        echo("<td>$computer_name</td>");
-        echo('</tr>');
-      }
-?>
+          if ((is_array($response_info)) && (array_key_exists($member_id, $response_info))) {
+              $info = $response_info[$member_id];
+
+              $started_dt = strtotime($info['date_opened']);
+              $started = date('d M, Y \<\b\r \/\>H:i:s', $started_dt);
+              $finished_dt = strtotime($info['date_responded']);
+              $finished = date('d M, Y \<\b\r \/\>H:i:s', $finished_dt);
+
+              $time_taken = TimeDiff::calculate($started_dt, $finished_dt);
+
+              $ip_address = $info['ip_address'];
+              $computer_name = $info['comp_name'];
+          } else {
+              $started = '';
+              $finished = '';
+              $time_taken = '';
+              $ip_address = '';
+              $computer_name = '';
+          }
+
+          $individ = $CIS->get_user($member_id);
+
+          echo '<tr>';
+          echo "<td style=\"text-align: left\"> {$individ['lastname']}, {$individ['forename']} (";
+          if (!empty($individ['id_number'])) {
+              echo $individ['id_number'];
+          } else {
+              echo $individ['username'];
+          }
+          echo ')</td>';
+          echo "<td>$started</td>";
+          echo "<td>$finished</td>";
+          echo "<td>$time_taken</td>";
+          echo "<td>$ip_address</td>";
+          echo "<td>$computer_name</td>";
+          echo '</tr>';
+      } ?>
         </table>
       </div>
 <?php
-    }
-  }
-  ?>
+      }
+  } ?>
 
   </div>
 
@@ -243,56 +243,55 @@
 * --------------------------------------------------------------------------------
 */
 if ($type == 'download-csv') {
-  header("Content-Disposition: attachment; filename=\"webpa_student_response_info.csv\"");
-  header('Content-Type: text/csv');
-
-  echo('"Student Response Information"'."\n\n");
-  echo("\"{$assessment->name}\"\n\n");
-
-  if (($assessment) && ($groups_iterator->size()>0)) {
-    foreach ($group_members as $group_id => $g_members) {
-      echo("\"Group\",\"{$group_names[$group_id]}\"\n");
-      echo("\"Overall group mark\",\"{$groups_and_marks[$group_id]}\"\n");
-
-      echo('"Name","Started","Finished","Time Taken","IP Address","Computer Name"'."\n");
-
-      foreach ($g_members as $i => $member_id) {
-
-        if (array_key_exists($member_id, $response_info)) {
-          $info = $response_info[$member_id];
-
-          $started_dt = strtotime($info['date_opened']);
-          $started = date('d M, Y H:i:s',$started_dt);
-          $finished_dt = strtotime($info['date_responded']);
-          $finished = date('d M, Y H:i:s',$finished_dt);
-
-          $time_taken = TimeDiff::calculate($started_dt, $finished_dt);
-
-          $ip_address = $info['ip_address'];
-          $computer_name = $info['comp_name'];
-        } else {
-          $started = '';
-          $finished = '';
-          $time_taken = '';
-          $ip_address = '';
-          $computer_name = '';
+    header('Content-Disposition: attachment; filename="webpa_student_response_info.csv"');
+    header('Content-Type: text/csv');
+
+    echo '"Student Response Information"'."\n\n";
+    echo "\"{$assessment->name}\"\n\n";
+
+    if (($assessment) && ($groups_iterator->size()>0)) {
+        foreach ($group_members as $group_id => $g_members) {
+            echo "\"Group\",\"{$group_names[$group_id]}\"\n";
+            echo "\"Overall group mark\",\"{$groups_and_marks[$group_id]}\"\n";
+
+            echo '"Name","Started","Finished","Time Taken","IP Address","Computer Name"'."\n";
+
+            foreach ($g_members as $i => $member_id) {
+                if (array_key_exists($member_id, $response_info)) {
+                    $info = $response_info[$member_id];
+
+                    $started_dt = strtotime($info['date_opened']);
+                    $started = date('d M, Y H:i:s', $started_dt);
+                    $finished_dt = strtotime($info['date_responded']);
+                    $finished = date('d M, Y H:i:s', $finished_dt);
+
+                    $time_taken = TimeDiff::calculate($started_dt, $finished_dt);
+
+                    $ip_address = $info['ip_address'];
+                    $computer_name = $info['comp_name'];
+                } else {
+                    $started = '';
+                    $finished = '';
+                    $time_taken = '';
+                    $ip_address = '';
+                    $computer_name = '';
+                }
+                $individ = $CIS->get_user($member_id);
+                echo "\"{$individ['lastname']}, {$individ['forename']} (";
+                if (!empty($individ['id_number'])) {
+                    echo $individ['id_number'];
+                } else {
+                    echo $individ['username'];
+                }
+                echo ')",';
+                echo "\"$started\",";
+                echo "\"$finished\",";
+                echo "\"$time_taken\",";
+                echo "\"$ip_address\",";
+                echo "\"$computer_name\"\n";
+            }
+            echo "\n\n";
         }
-        $individ = $CIS->get_user($member_id);
-        echo("\"{$individ['lastname']}, {$individ['forename']} (");
-        if (!empty($individ['id_number'])) {
-          echo($individ['id_number']);
-        } else {
-          echo($individ['username']);
-        }
-        echo(')",');
-        echo("\"$started\",");
-        echo("\"$finished\",");
-        echo("\"$time_taken\",");
-        echo("\"$ip_address\",");
-        echo("\"$computer_name\"\n");
-      }
-    echo("\n\n");
     }
-  }
 }
 ?>
diff --git a/src/tutors/assessments/reports/report_uea.php b/src/tutors/assessments/reports/report_uea.php
index d61f3da..f3734ec 100644
--- a/src/tutors/assessments/reports/report_uea.php
+++ b/src/tutors/assessments/reports/report_uea.php
@@ -10,16 +10,16 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\AlgorithmFactory;
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\classes\Form;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -38,46 +38,45 @@
 
 $assessment = new Assessment($DB);
 if (!$assessment->load($assessment_id)) {
-  $assessment = null;
-
-  echo('Error: The requested assessment could not be loaded.');
-  exit;
-} else {
+    $assessment = null;
 
-  // ----------------------------------------
-  // Get the marking parameters used for the marksheet this report will display
-  $marking_params = $assessment->get_marking_params($marking_date);
-  if (!$marking_params) {
-    echo('Error: The requested marksheet could not be loaded.');
+    echo 'Error: The requested assessment could not be loaded.';
     exit;
-  }
+}
 
   // ----------------------------------------
-  // Get the appropriate algorithm and calculate the grades
-  $algorithm = AlgorithmFactory::get_algorithm($marking_params['algorithm']);
+    // Get the marking parameters used for the marksheet this report will display
+    $marking_params = $assessment->get_marking_params($marking_date);
+    if (!$marking_params) {
+        echo 'Error: The requested marksheet could not be loaded.';
+        exit;
+    }
 
-  if (!$algorithm) {
-    echo('Error: The requested algorithm could not be loaded.');
-    exit;
-  } else {
-    $algorithm->set_assessment($assessment);
-    $algorithm->set_marking_params($marking_params);
-    $algorithm->calculate();
+    // ----------------------------------------
+    // Get the appropriate algorithm and calculate the grades
+    $algorithm = AlgorithmFactory::get_algorithm($marking_params['algorithm']);
 
-    $group_members = $algorithm->get_group_members();
+    if (!$algorithm) {
+        echo 'Error: The requested algorithm could not be loaded.';
+        exit;
+    }
+        $algorithm->set_assessment($assessment);
+        $algorithm->set_marking_params($marking_params);
+        $algorithm->calculate();
 
-    $member_names = array();
+        $group_members = $algorithm->get_group_members();
 
-    for ($i =0; $i<count($group_members); $i++){
-      $array_key = array_keys($group_members);
-      $temp = $group_members[$array_key[$i]];
-      for ($j=0; $j<count($temp);$j++){
-        array_push($member_names, $CIS->get_user($temp[$j]));
-      }
-    }
-  }// /if-else(is algorithm)
+        $member_names = [];
 
-}// /if-else(is assessment)
+        for ($i =0; $i<count($group_members); $i++) {
+            $array_key = array_keys($group_members);
+            $temp = $group_members[$array_key[$i]];
+            for ($j=0; $j<count($temp);$j++) {
+                array_push($member_names, $CIS->get_user($temp[$j]));
+            }
+        }
+    // /if-else(is algorithm)
+// /if-else(is assessment)
 
 
 // ----------------------------------------
@@ -89,9 +88,9 @@
 
 // Create the actual array (question_ids are 0-based)
 if ($question_count>0) {
-  $questions = range(0, $question_count-1);
+    $questions = range(0, $question_count-1);
 } else {
-  $questions = array();
+    $questions = [];
 }
 
 //get the information in the format required
@@ -102,42 +101,40 @@
 $group_names = $algorithm->get_group_names();
 
 if ($assessment) {
-  foreach ($group_members as $group_id => $g_members) {
-    $g_member_count = count($group_members[$group_id]);
-
-    foreach ($questions as $question_id) {
-      $q_index = $question_id+1;
-      $question = $form->get_question($question_id);
-      $q_text = "Q{$q_index} : {$question['text']['_data']}";
-
-      foreach ($g_members as $i => $member_id) {
-        $individ = $CIS->get_user($member_id);
-
-        $mark_recipient = "{$individ['lastname']}, {$individ['forename']}";
-
-        foreach ($g_members as $j => $target_member_id) {
-          $individ = $CIS->get_user($target_member_id);
-
-          $marker = "{$individ['lastname']}, {$individ['forename']}";
-
-          if ($assessment->assessment_type == '0') {
-
-            if ($member_id == $target_member_id) {
-              $score_array[$group_names[$group_id]][$mark_recipient][$q_text][$marker] = 'n/a';
-            } else {
-              $score_array[$group_names[$group_id]][$mark_recipient][$q_text][$marker] = $algorithm->get_member_response($group_id, $target_member_id, $question_id,$member_id );
+    foreach ($group_members as $group_id => $g_members) {
+        $g_member_count = count($group_members[$group_id]);
+
+        foreach ($questions as $question_id) {
+            $q_index = $question_id+1;
+            $question = $form->get_question($question_id);
+            $q_text = "Q{$q_index} : {$question['text']['_data']}";
+
+            foreach ($g_members as $i => $member_id) {
+                $individ = $CIS->get_user($member_id);
+
+                $mark_recipient = "{$individ['lastname']}, {$individ['forename']}";
+
+                foreach ($g_members as $j => $target_member_id) {
+                    $individ = $CIS->get_user($target_member_id);
+
+                    $marker = "{$individ['lastname']}, {$individ['forename']}";
+
+                    if ($assessment->assessment_type == '0') {
+                        if ($member_id == $target_member_id) {
+                            $score_array[$group_names[$group_id]][$mark_recipient][$q_text][$marker] = 'n/a';
+                        } else {
+                            $score_array[$group_names[$group_id]][$mark_recipient][$q_text][$marker] = $algorithm->get_member_response($group_id, $target_member_id, $question_id, $member_id);
+                        }
+                    } else {
+                        $score_array[$group_names[$group_id]][$mark_recipient][$q_text][$marker] = $algorithm->get_member_response($group_id, $target_member_id, $question_id, $member_id);
+                    }
+                    if (is_null($score_array[$group_names[$group_id]][$mark_recipient][$q_text][$marker])) {
+                        $score_array[$group_names[$group_id]][$mark_recipient][$q_text][$marker] = '-';
+                    }
+                }
             }
-
-          } else {
-            $score_array[$group_names[$group_id]][$mark_recipient][$q_text][$marker] = $algorithm->get_member_response($group_id, $target_member_id, $question_id, $member_id);
-          }
-          if (is_null($score_array[$group_names[$group_id]][$mark_recipient][$q_text][$marker])) {
-            $score_array[$group_names[$group_id]][$mark_recipient][$q_text][$marker] = '-';
-          }
         }
-      }
     }
-  }
 }
 
 /*
@@ -146,13 +143,12 @@
 * --------------------------------------------------------------------------------
 */
 if ($type == 'view') {
-  // Begin Page
+    // Begin Page
 
-  $page_title = ($assessment) ? "{$assessment->name}" : 'report';
+    $page_title = ($assessment) ? "{$assessment->name}" : 'report';
 
-  $UI->page_title = APP__NAME . ' ' . $page_title;
-  $UI->head();
-  ?>
+    $UI->page_title = APP__NAME . ' ' . $page_title;
+    $UI->head(); ?>
   <style type="text/css">
   <!--
 
@@ -168,8 +164,7 @@
   </style>
   <?php
   $UI->body();
-  $UI->content_start();
-?>
+    $UI->content_start(); ?>
 
   <div class="content_box">
 
@@ -184,40 +179,38 @@
   //get an array of the group names
   $group_names = $algorithm->get_group_names();
 
-  $teams = array_keys($score_array);
-  foreach ($teams as $i=> $team) {
-    echo "<h2>{$team}</h2>";
-    $team_members = array_keys($score_array[$team]);
-    foreach ($team_members as $team_member) {
-      echo "<h3>Results for: {$team_member}</h3>";
-      $questions = array_keys($score_array[$team][$team_member]);
-      //print_r($questions);
-      echo "<table class='grid' cellpadding='2' cellspacing='1' style='font-size: 0.8em'>";
-      $q_count = 0;
-      foreach ($questions as $question) {
-
-        $markers = array_keys($score_array[$team][$team_member][$question]);
-
-        $markers_row = '';
-        $scores_row = '';
-        foreach ($markers as $marker) {
-          $markers_row =  $markers_row ."<th>{$marker}</th>";
-
-          $score = $score_array[$team][$team_member][$question][$marker];
-          $scores_row = $scores_row . "<td>{$score}</td>";
-        }
-        if ($q_count == 0) {
-          echo "<tr><th>&nbsp;</th>";
-          echo $markers_row;
+    $teams = array_keys($score_array);
+    foreach ($teams as $i=> $team) {
+        echo "<h2>{$team}</h2>";
+        $team_members = array_keys($score_array[$team]);
+        foreach ($team_members as $team_member) {
+            echo "<h3>Results for: {$team_member}</h3>";
+            $questions = array_keys($score_array[$team][$team_member]);
+            //print_r($questions);
+            echo "<table class='grid' cellpadding='2' cellspacing='1' style='font-size: 0.8em'>";
+            $q_count = 0;
+            foreach ($questions as $question) {
+                $markers = array_keys($score_array[$team][$team_member][$question]);
+
+                $markers_row = '';
+                $scores_row = '';
+                foreach ($markers as $marker) {
+                    $markers_row =  $markers_row ."<th>{$marker}</th>";
+
+                    $score = $score_array[$team][$team_member][$question][$marker];
+                    $scores_row = $scores_row . "<td>{$score}</td>";
+                }
+                if ($q_count == 0) {
+                    echo '<tr><th>&nbsp;</th>';
+                    echo $markers_row;
+                }
+                echo "</tr><tr><th>{$question}</th>";
+                echo $scores_row;
+                $q_count++;
+            }
+            echo '</tr></table><br/><br/>';
         }
-        echo "</tr><tr><th>{$question}</th>";
-        echo $scores_row;
-        $q_count++;
-      }
-      echo "</tr></table><br/><br/>";
-    }
-  }
-?>
+    } ?>
 
     </td>
   </tr>
@@ -235,86 +228,81 @@
  */
 
 if ($type == 'download-rtf') {
+    header('Content-Disposition: attachment; filename=uea.rtf');
+    header("Content-Type: text/enriched\n");
+
+    $group_names = $algorithm->get_group_names();
+
+    $teams = array_keys($score_array);
+    foreach ($teams as $i=> $team) {
+        echo "\n{$team}\n";
+        $team_members = array_keys($score_array[$team]);
+        foreach ($team_members as $team_member) {
+            echo "\nResults for: {$team_member}\n";
+            $questions = array_keys($score_array[$team][$team_member]);
+
+            $q_count = 0;
+            foreach ($questions as $question) {
+                $markers = array_keys($score_array[$team][$team_member][$question]);
+
+                $markers_row = '';
+                $scores_row = '';
+                foreach ($markers as $marker) {
+                    $markers_row =  $markers_row ."{$marker}\t";
+
+                    $score = $score_array[$team][$team_member][$question][$marker];
+                    $scores_row = $scores_row . "{$score}\t";
+                }
+                if ($q_count == 0) {
+                    echo "\n\t";
+                    echo $markers_row ."\t";
+                }
+                echo "\n{$question}\t";
+                echo $scores_row . "\n";
+                $q_count++;
+            }
 
-  header("Content-Disposition: attachment; filename=uea.rtf");
-  header("Content-Type: text/enriched\n");
-
-  $group_names = $algorithm->get_group_names();
-
-  $teams = array_keys($score_array);
-  foreach ($teams as $i=> $team) {
-    echo "\n{$team}\n";
-    $team_members = array_keys($score_array[$team]);
-    foreach ($team_members as $team_member) {
-      echo "\nResults for: {$team_member}\n";
-      $questions = array_keys($score_array[$team][$team_member]);
-
-      $q_count = 0;
-      foreach ($questions as $question) {
-
-        $markers = array_keys($score_array[$team][$team_member][$question]);
-
-        $markers_row = '';
-        $scores_row = '';
-        foreach ($markers as $marker) {
-          $markers_row =  $markers_row ."{$marker}\t";
-
-          $score = $score_array[$team][$team_member][$question][$marker];
-          $scores_row = $scores_row . "{$score}\t";
+            echo "\n";
         }
-        if ($q_count == 0) {
-          echo "\n\t";
-          echo $markers_row ."\t";
-        }
-        echo "\n{$question}\t";
-        echo $scores_row . "\n";
-        $q_count++;
-      }
-
-        echo "\n";
     }
-
-  }
 }
 
 if ($type == 'download-csv') {
-  header("Content-Disposition: attachment; filename=\"uea_report_style.csv\"");
-  header('Content-Type: text/csv');
-
-  $group_names = $algorithm->get_group_names();
-
-  $teams = array_keys($score_array);
-  foreach ($teams as $i=> $team) {
-    echo "\n{$team}\n";
-    $team_members = array_keys($score_array[$team]);
-    foreach ($team_members as $team_member) {
-      echo "\n\"Results for: {$team_member}\"";
-      $questions = array_keys($score_array[$team][$team_member]);
-
-      $q_count = 0;
-      foreach ($questions as $question) {
-
-        $markers = array_keys($score_array[$team][$team_member][$question]);
-
-        $markers_row = '';
-        $scores_row = '';
-        foreach ($markers as $marker) {
-
-          $markers_row .= ",\"{$marker}\"";
-
-          $score = $score_array[$team][$team_member][$question][$marker];
-          $scores_row = $scores_row . "\"{$score}\",";
-        }
-        if ($q_count == 0) {
-          echo "\n";
-          echo $markers_row;
+    header('Content-Disposition: attachment; filename="uea_report_style.csv"');
+    header('Content-Type: text/csv');
+
+    $group_names = $algorithm->get_group_names();
+
+    $teams = array_keys($score_array);
+    foreach ($teams as $i=> $team) {
+        echo "\n{$team}\n";
+        $team_members = array_keys($score_array[$team]);
+        foreach ($team_members as $team_member) {
+            echo "\n\"Results for: {$team_member}\"";
+            $questions = array_keys($score_array[$team][$team_member]);
+
+            $q_count = 0;
+            foreach ($questions as $question) {
+                $markers = array_keys($score_array[$team][$team_member][$question]);
+
+                $markers_row = '';
+                $scores_row = '';
+                foreach ($markers as $marker) {
+                    $markers_row .= ",\"{$marker}\"";
+
+                    $score = $score_array[$team][$team_member][$question][$marker];
+                    $scores_row = $scores_row . "\"{$score}\",";
+                }
+                if ($q_count == 0) {
+                    echo "\n";
+                    echo $markers_row;
+                }
+                echo "\n\"{$question}\",";
+                echo $scores_row;
+                $q_count++;
+            }
+            echo "\n";
         }
-        echo "\n\"{$question}\",";
-        echo $scores_row;
-        $q_count++;
-      }
-      echo "\n";
     }
-  }
 }
 ?>
diff --git a/src/tutors/assessments/reports/report_uea_anonymous.php b/src/tutors/assessments/reports/report_uea_anonymous.php
index f71bf3f..2f52ced 100644
--- a/src/tutors/assessments/reports/report_uea_anonymous.php
+++ b/src/tutors/assessments/reports/report_uea_anonymous.php
@@ -10,16 +10,16 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\AlgorithmFactory;
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\classes\Form;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -38,45 +38,44 @@
 
 $assessment = new Assessment($DB);
 if (!$assessment->load($assessment_id)) {
-  $assessment = null;
-  echo('Error: The requested assessment could not be loaded.');
-  exit;
-} else {
-
-  // ----------------------------------------
-  // Get the marking parameters used for the marksheet this report will display
-  $marking_params = $assessment->get_marking_params($marking_date);
-  if (!$marking_params) {
-    echo('Error: The requested marksheet could not be loaded.');
+    $assessment = null;
+    echo 'Error: The requested assessment could not be loaded.';
     exit;
-  }
+}
 
   // ----------------------------------------
-  // Get the appropriate algorithm and calculate the grades
-  $algorithm = AlgorithmFactory::get_algorithm($marking_params['algorithm']);
+    // Get the marking parameters used for the marksheet this report will display
+    $marking_params = $assessment->get_marking_params($marking_date);
+    if (!$marking_params) {
+        echo 'Error: The requested marksheet could not be loaded.';
+        exit;
+    }
 
-  if (!$algorithm) {
-    echo('Error: The requested algorithm could not be loaded.');
-    exit;
-  } else {
-    $algorithm->set_assessment($assessment);
-    $algorithm->set_marking_params($marking_params);
-    $algorithm->calculate();
+    // ----------------------------------------
+    // Get the appropriate algorithm and calculate the grades
+    $algorithm = AlgorithmFactory::get_algorithm($marking_params['algorithm']);
 
-    $group_members = $algorithm->get_group_members();
+    if (!$algorithm) {
+        echo 'Error: The requested algorithm could not be loaded.';
+        exit;
+    }
+        $algorithm->set_assessment($assessment);
+        $algorithm->set_marking_params($marking_params);
+        $algorithm->calculate();
 
-    $member_names = array();
+        $group_members = $algorithm->get_group_members();
 
-    for ($i =0; $i<count($group_members); $i++){
-      $array_key = array_keys($group_members);
-      $temp = $group_members[$array_key[$i]];
-      for ($j=0; $j<count($temp);$j++){
-        array_push($member_names, $CIS->get_user($temp[$j]));
-      }
-    }
-  }// /if-else(is algorithm)
+        $member_names = [];
 
-}// /if-else(is assessment)
+        for ($i =0; $i<count($group_members); $i++) {
+            $array_key = array_keys($group_members);
+            $temp = $group_members[$array_key[$i]];
+            for ($j=0; $j<count($temp);$j++) {
+                array_push($member_names, $CIS->get_user($temp[$j]));
+            }
+        }
+    // /if-else(is algorithm)
+// /if-else(is assessment)
 
 // ----------------------------------------
 // Get the questions used in this assessment
@@ -87,9 +86,9 @@
 
 // Create the actual array (question_ids are 0-based)
 if ($question_count>0) {
-  $questions = range(0, $question_count-1);
+    $questions = range(0, $question_count-1);
 } else {
-  $questions = array();
+    $questions = [];
 }
 
 //get the information in the format required
@@ -98,46 +97,44 @@
 
 $score_array = null;
 if ($assessment) {
-  foreach ($group_members as $group_id => $g_members) {
-    $g_member_count = count($group_members[$group_id]);
-
-    foreach ($questions as $question_id) {
-      $q_index = $question_id+1;
-      $question = $form->get_question($question_id);
-      $q_text = "Q{$q_index} : {$question['text']['_data']}";
-
-
-      foreach ($g_members as $i => $member_id) {
-        $individ = $CIS->get_user($member_id);
-
-        $mark_recipient = "{$individ['lastname']}, {$individ['forename']}";
-        $GroupMemberNumber = 0;
-        foreach ($g_members as $j => $target_member_id) {
-          $individ = $CIS->get_user($target_member_id);
-
-          $char = chr(65+$GroupMemberNumber);
-          $marker = "Student $char";
-
-          if ($assessment->assessment_type == '0'){
-
-            if ($member_id == $target_member_id){
-              $score_array[$group_names[$group_id]][$mark_recipient][$q_text][$marker] = 'n/a';
-            } else {
-              $score_array[$group_names[$group_id]][$mark_recipient][$q_text][$marker] = $algorithm->get_member_response($group_id, $target_member_id, $question_id,$member_id );
+    foreach ($group_members as $group_id => $g_members) {
+        $g_member_count = count($group_members[$group_id]);
+
+        foreach ($questions as $question_id) {
+            $q_index = $question_id+1;
+            $question = $form->get_question($question_id);
+            $q_text = "Q{$q_index} : {$question['text']['_data']}";
+
+
+            foreach ($g_members as $i => $member_id) {
+                $individ = $CIS->get_user($member_id);
+
+                $mark_recipient = "{$individ['lastname']}, {$individ['forename']}";
+                $GroupMemberNumber = 0;
+                foreach ($g_members as $j => $target_member_id) {
+                    $individ = $CIS->get_user($target_member_id);
+
+                    $char = chr(65+$GroupMemberNumber);
+                    $marker = "Student $char";
+
+                    if ($assessment->assessment_type == '0') {
+                        if ($member_id == $target_member_id) {
+                            $score_array[$group_names[$group_id]][$mark_recipient][$q_text][$marker] = 'n/a';
+                        } else {
+                            $score_array[$group_names[$group_id]][$mark_recipient][$q_text][$marker] = $algorithm->get_member_response($group_id, $target_member_id, $question_id, $member_id);
+                        }
+                    } else {
+                        $score_array[$group_names[$group_id]][$mark_recipient][$q_text][$marker] = $algorithm->get_member_response($group_id, $target_member_id, $question_id, $member_id);
+                    }
+                    if (is_null($score_array[$group_names[$group_id]][$mark_recipient][$q_text][$marker])) {
+                        $score_array[$group_names[$group_id]][$mark_recipient][$q_text][$marker] = '-';
+                    }
+
+                    $GroupMemberNumber ++;
+                }
             }
-
-          } else {
-            $score_array[$group_names[$group_id]][$mark_recipient][$q_text][$marker] = $algorithm->get_member_response($group_id, $target_member_id, $question_id, $member_id);
-          }
-          if (is_null($score_array[$group_names[$group_id]][$mark_recipient][$q_text][$marker])) {
-            $score_array[$group_names[$group_id]][$mark_recipient][$q_text][$marker] = '-';
-          }
-
-          $GroupMemberNumber ++;
         }
-      }
     }
-  }
 }
 
 /*
@@ -146,13 +143,12 @@
 * --------------------------------------------------------------------------------
 */
 if ($type == 'view') {
-  // Begin Page
+    // Begin Page
 
-  $page_title = ($assessment) ? "{$assessment->name}" : 'report';
+    $page_title = ($assessment) ? "{$assessment->name}" : 'report';
 
-  $UI->page_title = APP__NAME . ' ' . $page_title;
-  $UI->head();
-  ?>
+    $UI->page_title = APP__NAME . ' ' . $page_title;
+    $UI->head(); ?>
   <style type="text/css">
   <!--
 
@@ -168,8 +164,7 @@
   </style>
 <?php
   $UI->body();
-  $UI->content_start();
-?>
+    $UI->content_start(); ?>
 
   <div class="content_box">
 
@@ -181,38 +176,36 @@
 
 <?php
   $teams = array_keys($score_array);
-  foreach($teams as $i=> $team){
-    echo "<h2>{$team}</h2>";
-    $team_members = array_keys($score_array[$team]);
-    foreach ($team_members as $team_member) {
-      echo "<h3>Results for: {$team_member}</h3>";
-      $questions = array_keys($score_array[$team][$team_member]);
-      //print_r($questions);
-      echo "<table class='grid' cellpadding='2' cellspacing='1' style='font-size: 0.8em'>";
-      $q_count = 0;
-      foreach ($questions as $question) {
-
-        $markers = array_keys($score_array[$team][$team_member][$question]);
-
-        $markers_row = '';
-        $scores_row = '';
-        foreach ($markers as $marker) {
-          $markers_row =  $markers_row ."<th>{$marker}</th>";
-          $score = $score_array[$team][$team_member][$question][$marker];
-          $scores_row = $scores_row . "<td>{$score}</td>";
-        }
-        if ($q_count == 0) {
-          echo "<tr><th>&nbsp;</th>";
-          echo $markers_row;
+    foreach ($teams as $i=> $team) {
+        echo "<h2>{$team}</h2>";
+        $team_members = array_keys($score_array[$team]);
+        foreach ($team_members as $team_member) {
+            echo "<h3>Results for: {$team_member}</h3>";
+            $questions = array_keys($score_array[$team][$team_member]);
+            //print_r($questions);
+            echo "<table class='grid' cellpadding='2' cellspacing='1' style='font-size: 0.8em'>";
+            $q_count = 0;
+            foreach ($questions as $question) {
+                $markers = array_keys($score_array[$team][$team_member][$question]);
+
+                $markers_row = '';
+                $scores_row = '';
+                foreach ($markers as $marker) {
+                    $markers_row =  $markers_row ."<th>{$marker}</th>";
+                    $score = $score_array[$team][$team_member][$question][$marker];
+                    $scores_row = $scores_row . "<td>{$score}</td>";
+                }
+                if ($q_count == 0) {
+                    echo '<tr><th>&nbsp;</th>';
+                    echo $markers_row;
+                }
+                echo "</tr><tr><th>{$question}</th>";
+                echo $scores_row;
+                $q_count++;
+            }
+            echo '</tr></table><br/><br/>';
         }
-        echo "</tr><tr><th>{$question}</th>";
-        echo $scores_row;
-        $q_count++;
-      }
-      echo "</tr></table><br/><br/>";
-    }
-  }
-?>
+    } ?>
 
     </td>
   </tr>
@@ -228,86 +221,81 @@
  * --------------------------------------------------------------------------------
  */
 
-if ($type == 'download-rtf'){
-
-  header("Content-Disposition: attachment; filename=uea.rtf");
-  header("Content-Type: text/enriched\n");
-
-  $group_names = $algorithm->get_group_names();
-
-  $teams = array_keys($score_array);
-  foreach ($teams as $i=> $team) {
-    echo "{$team}\n\n";
-    $team_members = array_keys($score_array[$team]);
-    foreach ($team_members as $team_member) {
-      echo "Results for: {$team_member}\n\n";
-      $questions = array_keys($score_array[$team][$team_member]);
-      //print_r($questions);
-      $q_count = 0;
-      foreach ($questions as $question) {
-
-        $markers = array_keys($score_array[$team][$team_member][$question]);
-
-        $markers_row = '';
-        $scores_row = '';
-        foreach ($markers as $marker) {
-          $markers_row =  $markers_row ."{$marker}\t";
-
-          $score = $score_array[$team][$team_member][$question][$marker];
-          $scores_row = $scores_row . "{$score}\t";
-        }
-        if ($q_count == 0) {
-          echo "\n\t\t";
-          echo $markers_row;
+if ($type == 'download-rtf') {
+    header('Content-Disposition: attachment; filename=uea.rtf');
+    header("Content-Type: text/enriched\n");
+
+    $group_names = $algorithm->get_group_names();
+
+    $teams = array_keys($score_array);
+    foreach ($teams as $i=> $team) {
+        echo "{$team}\n\n";
+        $team_members = array_keys($score_array[$team]);
+        foreach ($team_members as $team_member) {
+            echo "Results for: {$team_member}\n\n";
+            $questions = array_keys($score_array[$team][$team_member]);
+            //print_r($questions);
+            $q_count = 0;
+            foreach ($questions as $question) {
+                $markers = array_keys($score_array[$team][$team_member][$question]);
+
+                $markers_row = '';
+                $scores_row = '';
+                foreach ($markers as $marker) {
+                    $markers_row =  $markers_row ."{$marker}\t";
+
+                    $score = $score_array[$team][$team_member][$question][$marker];
+                    $scores_row = $scores_row . "{$score}\t";
+                }
+                if ($q_count == 0) {
+                    echo "\n\t\t";
+                    echo $markers_row;
+                }
+                echo "\n{$question}\t";
+                echo $scores_row . "\t";
+                $q_count++;
+            }
+            echo "\n\n";
         }
-        echo "\n{$question}\t";
-        echo $scores_row . "\t";
-        $q_count++;
-      }
-      echo "\n\n";
     }
-
-  }
 }
 
 if ($type == 'download-csv') {
-  header("Content-Disposition: attachment; filename=\"uea_report_style.csv\"");
-  header('Content-Type: text/csv');
-
-  $group_names = $algorithm->get_group_names();
-
-  $teams = array_keys($score_array);
-  foreach ($teams as $i=> $team) {
-    echo "\n{$team}\n";
-    $team_members = array_keys($score_array[$team]);
-    foreach ($team_members as $team_member) {
-      echo "\n\"Results for: {$team_member}\"";
-      $questions = array_keys($score_array[$team][$team_member]);
-
-      $q_count = 0;
-      foreach ($questions as $question) {
-
-        $markers = array_keys($score_array[$team][$team_member][$question]);
-
-        $markers_row = '';
-        $scores_row = '';
-        foreach ($markers as $marker) {
-
-          $markers_row =  $markers_row . ",\"{$marker}\"";
-
-          $score = $score_array[$team][$team_member][$question][$marker];
-          $scores_row = $scores_row . "\"{$score}\",";
-        }
-        if ($q_count == 0) {
-          echo "\n";
-          echo $markers_row;
+    header('Content-Disposition: attachment; filename="uea_report_style.csv"');
+    header('Content-Type: text/csv');
+
+    $group_names = $algorithm->get_group_names();
+
+    $teams = array_keys($score_array);
+    foreach ($teams as $i=> $team) {
+        echo "\n{$team}\n";
+        $team_members = array_keys($score_array[$team]);
+        foreach ($team_members as $team_member) {
+            echo "\n\"Results for: {$team_member}\"";
+            $questions = array_keys($score_array[$team][$team_member]);
+
+            $q_count = 0;
+            foreach ($questions as $question) {
+                $markers = array_keys($score_array[$team][$team_member][$question]);
+
+                $markers_row = '';
+                $scores_row = '';
+                foreach ($markers as $marker) {
+                    $markers_row =  $markers_row . ",\"{$marker}\"";
+
+                    $score = $score_array[$team][$team_member][$question][$marker];
+                    $scores_row = $scores_row . "\"{$score}\",";
+                }
+                if ($q_count == 0) {
+                    echo "\n";
+                    echo $markers_row;
+                }
+                echo "\n\"{$question}\",";
+                echo $scores_row;
+                $q_count++;
+            }
+            echo "\n";
         }
-        echo "\n\"{$question}\",";
-        echo $scores_row;
-        $q_count++;
-      }
-      echo "\n";
     }
-  }
 }
 ?>
diff --git a/src/tutors/assessments/reports/students_who_responded.php b/src/tutors/assessments/reports/students_who_responded.php
index c9748c0..3800782 100644
--- a/src/tutors/assessments/reports/students_who_responded.php
+++ b/src/tutors/assessments/reports/students_who_responded.php
@@ -8,22 +8,22 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../includes/inc_global.php");
+require_once '../../includes/inc_global.php';
 
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\classes\GroupHandler;
 use WebPA\includes\classes\ResultHandler;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
 
 $year = Common::fetch_GET('y');
-$tab = Common::fetch_GET('tab','pending');
+$tab = Common::fetch_GET('tab', 'pending');
 
 $assessment_id = Common::fetch_GET('a');
 
@@ -33,21 +33,21 @@
 
 $assessment = new Assessment($DB);
 if ($assessment->load($assessment_id)) {
-  $assessment_qs = "a={$assessment->id}&tab={$tab}&y={$year}";
+    $assessment_qs = "a={$assessment->id}&tab={$tab}&y={$year}";
 
-  $group_handler = new GroupHandler();
-  $collection =& $group_handler->get_collection($assessment->get_collection_id());
+    $group_handler = new GroupHandler();
+    $collection =& $group_handler->get_collection($assessment->get_collection_id());
 
-  $groups_iterator = $collection->get_groups_iterator();
+    $groups_iterator = $collection->get_groups_iterator();
 
-  $result_handler = new ResultHandler($DB);
-  $result_handler->set_assessment($assessment);
+    $result_handler = new ResultHandler($DB);
+    $result_handler->set_assessment($assessment);
 
-  $responded_users = $result_handler->get_responded_users();
+    $responded_users = $result_handler->get_responded_users();
 
-  $members = $collection->get_members();
+    $members = $collection->get_members();
 } else {
-  $assessment = null;
+    $assessment = null;
 }
 
 // --------------------------------------------------------------------------------
@@ -55,9 +55,9 @@
 
 $UI->page_title = APP__NAME . ' ' . 'students who responded';
 $UI->menu_selected = 'my assessments';
-$UI->breadcrumbs = array  ('home'           => '/' ,
-               'my assessments'     => $list_url ,
-               'students who responded' => null ,);
+$UI->breadcrumbs = ['home'           => '/',
+               'my assessments'     => $list_url,
+               'students who responded' => null, ];
 
 $UI->set_page_bar_button('List Assessments', '../../../images/buttons/button_assessment_list.gif', '../assessments/index.php');
 $UI->set_page_bar_button('Create Assessments', '../../../images/buttons/button_assessment_create.gif', '../create/');
@@ -82,23 +82,23 @@
 <div class="content_box">
 
   <div class="nav_button_bar">
-    <a href="<?php echo($list_url) ?>"><img src="../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a>
+    <a href="<?php echo $list_url ?>"><img src="../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a>
   </div>
 
   <p>The following list shows which students in each group have submitted there responses to the assessment.</p>
   <p>To email an individual student, click on the email link next to their name.</p>
 <?php
 if ($groups_iterator->size()>0) {
-  for ($groups_iterator->reset(); $groups_iterator->is_valid(); $groups_iterator->next()) {
-    $group =& $groups_iterator->current();
+    for ($groups_iterator->reset(); $groups_iterator->is_valid(); $groups_iterator->next()) {
+        $group =& $groups_iterator->current();
 
-    $members = $CIS->get_user($group->get_member_ids());
-    echo("<h2>{$group->name}</h2>");
+        $members = $CIS->get_user($group->get_member_ids());
+        echo "<h2>{$group->name}</h2>";
 
-    if (!$members) {
-      echo('<p>This group has no members.</p>');
-    } else {
-?>
+        if (!$members) {
+            echo '<p>This group has no members.</p>';
+        } else {
+            ?>
         <table class="grid" cellspacing="1" cellpadding="2" style="width: 90%">
         <tr>
           <th>name</th>
@@ -107,24 +107,24 @@
         </tr>
 <?php
       foreach ($members as $i => $member) {
-        if (in_array($member['user_id'], (array)$responded_users)) {
-          $responded_img = '<img src="../../images/icons/tick.gif" width="16" height="16" alt="Responded" />';
-          $responded_class = 'class="responded"';
-        } else {
-          $responded_img = '<img src="../../images/icons/cross.gif" width="16" height="16" alt="Not Responded"/>';
-          $responded_class = 'class="notresponded"';
-        }
-        echo("<tr $responded_class><td>{$member['lastname']}, {$member['forename']} (");
-        if (!empty($member['id_number'])) {
-          echo($member['id_number']);
-        } else {
-          echo($member['username']);
-        }
-        echo(")</td><td><a href=\"mailto:{$member['email']}\">{$member['email']}</a></td><td align=\"center\">$responded_img</td></tr>");
+          if (in_array($member['user_id'], (array) $responded_users)) {
+              $responded_img = '<img src="../../images/icons/tick.gif" width="16" height="16" alt="Responded" />';
+              $responded_class = 'class="responded"';
+          } else {
+              $responded_img = '<img src="../../images/icons/cross.gif" width="16" height="16" alt="Not Responded"/>';
+              $responded_class = 'class="notresponded"';
+          }
+          echo "<tr $responded_class><td>{$member['lastname']}, {$member['forename']} (";
+          if (!empty($member['id_number'])) {
+              echo $member['id_number'];
+          } else {
+              echo $member['username'];
+          }
+          echo ")</td><td><a href=\"mailto:{$member['email']}\">{$member['email']}</a></td><td align=\"center\">$responded_img</td></tr>";
       }
-      echo('</table><br />');
-    }// /if
-  }// /for
+            echo '</table><br />';
+        }// /if
+    }// /for
 }
 ?>
 
diff --git a/src/tutors/assessments/students_who_responded.php b/src/tutors/assessments/students_who_responded.php
index 1c3d15d..95ab4b6 100644
--- a/src/tutors/assessments/students_who_responded.php
+++ b/src/tutors/assessments/students_who_responded.php
@@ -8,22 +8,22 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../includes/inc_global.php");
+require_once '../../includes/inc_global.php';
 
 use WebPA\includes\classes\Assessment;
 use WebPA\includes\classes\GroupHandler;
 use WebPA\includes\classes\ResultHandler;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
 
 $year = Common::fetch_GET('y');
-$tab = Common::fetch_GET('tab','pending');
+$tab = Common::fetch_GET('tab', 'pending');
 
 $assessment_id = Common::fetch_GET('a');
 
@@ -33,22 +33,22 @@
 
 $assessment = new Assessment($DB);
 if ($assessment->load($assessment_id)) {
-  $assessment_qs = "a={$assessment->id}&tab={$tab}&y={$year}";
+    $assessment_qs = "a={$assessment->id}&tab={$tab}&y={$year}";
 
-  $group_handler = new GroupHandler();
-  $collection = $group_handler->get_collection($assessment->get_collection_id());
+    $group_handler = new GroupHandler();
+    $collection = $group_handler->get_collection($assessment->get_collection_id());
 
-  $groups_iterator = $collection->get_groups_iterator();
+    $groups_iterator = $collection->get_groups_iterator();
 
-  $result_handler = new ResultHandler($DB);
-  $result_handler->set_assessment($assessment);
+    $result_handler = new ResultHandler($DB);
+    $result_handler->set_assessment($assessment);
 
 
-  $responded_users = $result_handler->get_responded_users();
+    $responded_users = $result_handler->get_responded_users();
 
-  $members = $collection->get_members();
+    $members = $collection->get_members();
 } else {
-  $assessment = null;
+    $assessment = null;
 }
 
 // --------------------------------------------------------------------------------
@@ -57,9 +57,9 @@
 $UI->page_title = APP__NAME . ' ' . 'students who responded';
 $UI->menu_selected = 'my assessments';
 $UI->help_link = '?q=node/235';
-$UI->breadcrumbs = array  ('home'           => '/' ,
-               'my assessments'     => $list_url ,
-               'students who responded' => null ,);
+$UI->breadcrumbs = ['home'           => '/',
+               'my assessments'     => $list_url,
+               'students who responded' => null, ];
 
 $UI->set_page_bar_button('List Assessments', '../../../images/buttons/button_assessment_list.gif', '../');
 $UI->set_page_bar_button('Create Assessments', '../../../images/buttons/button_assessment_create.gif', '../create/');
@@ -85,23 +85,23 @@
 <div class="content_box">
 
   <div class="nav_button_bar">
-    <a href="<?php echo($list_url) ?>"><img src="../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a>
+    <a href="<?php echo $list_url ?>"><img src="../../images/buttons/arrow_green_left.gif" alt="back -"> back to assessments list</a>
   </div>
 
   <p>The following list shows which students in each group have submitted their responses to the assessment.</p>
   <p>To email an individual student, click on the email link next to their name.</p>
 <?php
 if ($groups_iterator->size()>0) {
-  for($groups_iterator->reset(); $groups_iterator->is_valid(); $groups_iterator->next()) {
-    $group =& $groups_iterator->current();
+    for ($groups_iterator->reset(); $groups_iterator->is_valid(); $groups_iterator->next()) {
+        $group =& $groups_iterator->current();
 
-    $members = $CIS->get_user($group->get_member_ids());
-    echo("<h2>{$group->name}</h2>");
+        $members = $CIS->get_user($group->get_member_ids());
+        echo "<h2>{$group->name}</h2>";
 
-    if (!$members) {
-      echo('<p>This group has no members.</p>');
-    } else {
-?>
+        if (!$members) {
+            echo '<p>This group has no members.</p>';
+        } else {
+            ?>
         <table class="grid" cellspacing="1" cellpadding="2" style="width: 90%">
         <tr>
           <th>name</th>
@@ -109,23 +109,23 @@
           <th>responded</th>
         </tr>
 <?php
-      foreach($members as $i => $member) {
-        if (in_array($member['user_id'], (array)$responded_users)) {
-          $responded_img = '<img src="../../images/icons/tick.gif" width="16" height="16" alt="Responded" />';
-          $responded_class = 'class="responded"';
-        } else {
-          $responded_img = '<img src="../../images/icons/cross.gif" width="16" height="16" alt="Not Responded"/>';
-          $responded_class = 'class="notresponded"';
-        }
-        echo("<tr $responded_class><td>{$member['lastname']}, {$member['forename']}");
-        if (!empty($member['id_number'])) {
-          echo(" ({$member['id_number']})");
-        }
-        echo("</td><td><a href=\"mailto:{$member['email']}\">{$member['email']}</a></td><td align=\"center\">$responded_img</td></tr>");
+      foreach ($members as $i => $member) {
+          if (in_array($member['user_id'], (array) $responded_users)) {
+              $responded_img = '<img src="../../images/icons/tick.gif" width="16" height="16" alt="Responded" />';
+              $responded_class = 'class="responded"';
+          } else {
+              $responded_img = '<img src="../../images/icons/cross.gif" width="16" height="16" alt="Not Responded"/>';
+              $responded_class = 'class="notresponded"';
+          }
+          echo "<tr $responded_class><td>{$member['lastname']}, {$member['forename']}";
+          if (!empty($member['id_number'])) {
+              echo " ({$member['id_number']})";
+          }
+          echo "</td><td><a href=\"mailto:{$member['email']}\">{$member['email']}</a></td><td align=\"center\">$responded_img</td></tr>";
       }
-      echo('</table><br />');
-    }// /if
-  }// /for
+            echo '</table><br />';
+        }// /if
+    }// /for
 }
 ?>
 
diff --git a/src/tutors/forms/clone/class_wizardstep_1.php b/src/tutors/forms/clone/class_wizardstep_1.php
index 8b45d0e..ceffe85 100644
--- a/src/tutors/forms/clone/class_wizardstep_1.php
+++ b/src/tutors/forms/clone/class_wizardstep_1.php
@@ -8,21 +8,23 @@
  * @link https://github.com/webpa/webpa
  */
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\Wizard;
 use WebPA\includes\functions\Common;
 
 class WizardStep1
 {
     public $wizard;
+
     public $step = 1;
 
     private $moduleId;
+
     private $user;
+
     private $sourceId;
 
-    /*
-    * CONSTRUCTOR
-    */
+    // CONSTRUCTOR
     public function __construct(Wizard $wizard)
     {
         $this->wizard = $wizard;
@@ -35,9 +37,11 @@ public function __construct(Wizard $wizard)
         $this->wizard->back_button = null;
         $this->wizard->next_button = 'Next &gt;';
         $this->wizard->cancel_button = 'Cancel';
-    }// /WizardStep1()
+    }
 
-    function head()
+    // /WizardStep1()
+
+    public function head()
     {
         ?>
         <script language="JavaScript" type="text/javascript">
@@ -49,33 +53,49 @@ function body_onload () {
           //-->
         </script>
         <?php
-    }// /->head()
+    }
+
+    // /->head()
 
-    function form()
+    public function form()
     {
-        $DB =& $this->wizard->get_var('db');
-        $user =& $this->wizard->get_var('user');
+        $DB = $this->wizard->get_var('db');
+        $user = $this->wizard->get_var('user');
 
         $form_id = $this->wizard->get_field('form_id');
 
+        $forms = [];
+
         if (!$this->user->is_admin()) {
-            $sql = 'SELECT f.*, m.module_id, m.module_title FROM ' . APP__DB_TABLE_PREFIX .
-                'form f INNER JOIN ' . APP__DB_TABLE_PREFIX .
-                'form_module fm ON f.form_id = fm.form_id INNER JOIN ' . APP__DB_TABLE_PREFIX .
-                "user_module um ON fm.module_id = um.module_id INNER JOIN " . APP__DB_TABLE_PREFIX .
-                'module m ON um.module_id = m.module_id ' .
-                "WHERE um.user_id = {$user->id} ORDER BY f.form_name ASC";
+            $sql =
+                'SELECT f.*, m.module_id, m.module_title ' .
+                'FROM ' . APP__DB_TABLE_PREFIX . 'form f ' .
+                'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'form_module fm ' .
+                'ON f.form_id = fm.form_id ' .
+                'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'user_module um ' .
+                'ON fm.module_id = um.module_id ' .
+                'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'module m ' .
+                'ON um.module_id = m.module_id ' .
+                'WHERE um.user_id = ? ' .
+                'ORDER BY f.form_name ASC';
+
+            $forms = $DB->getConnection()->fetchAllAssociative($sql, [$user->id], [ParameterType::INTEGER]);
         } else {
-            $sql = 'SELECT f.*, m.module_id, m.module_title FROM ' . APP__DB_TABLE_PREFIX .
-                'form f INNER JOIN ' . APP__DB_TABLE_PREFIX .
-                'form_module fm ON f.form_id = fm.form_id INNER JOIN ' . APP__DB_TABLE_PREFIX .
-                'module m ON fm.module_id = m.module_id ' .
-                "WHERE m.source_id = '{$this->sourceId}' ORDER BY f.form_name ASC";
+            $sql =
+                'SELECT f.*, m.module_id, m.module_title ' .
+                'FROM ' . APP__DB_TABLE_PREFIX . 'form f ' .
+                'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'form_module fm ' .
+                'ON f.form_id = fm.form_id ' .
+                'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'module m ' .
+                'ON fm.module_id = m.module_id ' .
+                'WHERE m.source_id = ? ' .
+                'ORDER BY f.form_name ASC';
+
+            $forms = $DB->getConnection()->fetchAllAssociative($sql, [$this->sourceId], [ParameterType::STRING]);
         }
-        $forms = $DB->fetch($sql);
+
         if (!$forms) {
-            $this->wizard->next_button = null;
-            ?>
+            $this->wizard->next_button = null; ?>
             <p>You have not created any forms yet, so you cannot select one to clone.</p>
             <p>Please <a href="../create/">create a new form</a> instead.</p>
             <?php
@@ -91,27 +111,26 @@ function form()
 
                     foreach ($forms as $i => $form) {
                         $checked_str = ($form['form_id'] == $form_id) ? ' checked="checked"' : '';
-                        $title_str = ($form['module_id'] == $this->moduleId) ? '' : " [{$form['module_title']}]";
-
-                        ?>
+                        $title_str = ($form['module_id'] == $this->moduleId) ? '' : " [{$form['module_title']}]"; ?>
                         <tr>
-                            <td><input type="radio" name="form_id" id="form_id_<?php echo($form['form_id']); ?>"
-                                       value="<?php echo($form['form_id']); ?>"<?php echo($checked_str); ?>/></td>
+                            <td><input type="radio" name="form_id" id="form_id_<?php echo $form['form_id']; ?>"
+                                       value="<?php echo $form['form_id']; ?>"<?php echo $checked_str; ?>/></td>
                             <th style="text-align: left"><label class="small"
-                                                                for="form_id_<?php echo($form['form_id']); ?>"><?php echo("{$form['form_name']}{$title_str}"); ?></label>
+                                                                for="form_id_<?php echo $form['form_id']; ?>"><?php echo "{$form['form_name']}{$title_str}"; ?></label>
                             </th>
                         </tr>
                         <?php
-                    }
-                    ?>
+                    } ?>
                 </table>
             </div>
 
             <?php
         }
-    }// /->form()
+    }
+
+    // /->form()
 
-    function process_form()
+    public function process_form()
     {
         $errors = null;
 
@@ -121,8 +140,9 @@ function process_form()
         }
 
         return $errors;
-    }// /->process_form()
+    }
 
+    // /->process_form()
 }// /class: WizardStep1
 
 ?>
diff --git a/src/tutors/forms/clone/class_wizardstep_2.php b/src/tutors/forms/clone/class_wizardstep_2.php
index 4ff6917..77bdb30 100644
--- a/src/tutors/forms/clone/class_wizardstep_2.php
+++ b/src/tutors/forms/clone/class_wizardstep_2.php
@@ -12,24 +12,27 @@
 use WebPA\includes\classes\Wizard;
 use WebPA\includes\functions\Common;
 
-class WizardStep2 {
+class WizardStep2
+{
+    public $wizard;
 
-  public $wizard;
-  public $step = 2;
+    public $step = 2;
 
-  /*
-  * CONSTRUCTOR
-  */
-  public function __construct(Wizard $wizard) {
-    $this->wizard = $wizard;
+    // CONSTRUCTOR
+    public function __construct(Wizard $wizard)
+    {
+        $this->wizard = $wizard;
 
-    $this->wizard->back_button = '&lt; Back';
-    $this->wizard->next_button = 'Finish';
-    $this->wizard->cancel_button = 'Cancel';
-  }// /WizardStep2()
+        $this->wizard->back_button = '&lt; Back';
+        $this->wizard->next_button = 'Finish';
+        $this->wizard->cancel_button = 'Cancel';
+    }
+
+    // /WizardStep2()
 
-  function head() {
-    ?>
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -40,23 +43,24 @@ function body_onload() {
 //-->
 </script>
 <?php
-  }// /->head()
+    }
 
-  function form() {
-    $DB =& $this->wizard->get_var('db');
-    $user =& $this->wizard->get_var('user');
+    // /->head()
 
-    $form = new Form($DB);
-    $form->load($this->wizard->get_field('form_id'));
+    public function form()
+    {
+        $DB = $this->wizard->get_var('db');
 
-    if (!$form) {
-      $this->wizard->next_button = null;
-      ?>
+        $form = new Form($DB);
+        $form->load($this->wizard->get_field('form_id'));
+
+        if (!$form) {
+            $this->wizard->next_button = null; ?>
       <p>The select form could not be loaded, please click <em>Back</em> and try again.</p>
       <?php
-    } else {
-      ?>
-      <p>You have chosen to clone: <em><?php echo($form->name); ?></em></p>
+        } else {
+            ?>
+      <p>You have chosen to clone: <em><?php echo $form->name; ?></em></p>
 
       <p>Now enter a name for your new form.</p>
 
@@ -64,24 +68,30 @@ function form() {
         <table class="form" cellpadding="2" cellspacing="2">
           <tr>
             <th><label for="clone_form_name">Name for new form</label></th>
-            <td><input type="text" name="clone_form_name" id="clone_form_name" size="50" maxlength="100" value="<?php echo($this->wizard->get_field('clone_form_name')); ?>" /></td>
+            <td><input type="text" name="clone_form_name" id="clone_form_name" size="50" maxlength="100" value="<?php echo $this->wizard->get_field('clone_form_name'); ?>" /></td>
           </tr>
         </table>
       </div>
 
       <?php
+        }
     }
-  }// /->form()
 
-  function process_form() {
-    $errors = null;
+    // /->form()
+
+    public function process_form()
+    {
+        $errors = null;
 
-    $this->wizard->set_field('clone_form_name',Common::fetch_POST('clone_form_name'));
-    if (empty($this->wizard->get_field('clone_form_name'))) { $errors[] = 'You must enter a name for your new assessment form.'; }
+        $this->wizard->set_field('clone_form_name', Common::fetch_POST('clone_form_name'));
+        if (empty($this->wizard->get_field('clone_form_name'))) {
+            $errors[] = 'You must enter a name for your new assessment form.';
+        }
 
-    return $errors;
-  }// /->process_form()
+        return $errors;
+    }
 
+    // /->process_form()
 }// /class: WizardStep2
 
 ?>
diff --git a/src/tutors/forms/clone/class_wizardstep_3.php b/src/tutors/forms/clone/class_wizardstep_3.php
index 115e63b..47cb359 100644
--- a/src/tutors/forms/clone/class_wizardstep_3.php
+++ b/src/tutors/forms/clone/class_wizardstep_3.php
@@ -14,13 +14,12 @@
 class WizardStep3
 {
     public $wizard;
+
     public $step = 3;
 
     private $moduleId;
 
-    /*
-    * CONSTRUCTOR
-    */
+    // CONSTRUCTOR
     public function __construct(Wizard $wizard)
     {
         $this->wizard = $wizard;
@@ -30,9 +29,11 @@ public function __construct(Wizard $wizard)
         $this->wizard->back_button = null;
         $this->wizard->next_button = null;
         $this->wizard->cancel_button = null;
-    }// /WizardStep3()
+    }
+
+    // /WizardStep3()
 
-    function head()
+    public function head()
     {
         ?>
         <script language="JavaScript" type="text/javascript">
@@ -44,9 +45,11 @@ function body_onload () {
           //-->
         </script>
         <?php
-    }// /->head()
+    }
 
-    function form()
+    // /->head()
+
+    public function form()
     {
         $DB =& $this->wizard->get_var('db');
         $user =& $this->wizard->get_var('user');
@@ -64,14 +67,14 @@ function form()
         if (is_array($errors)) {
             $this->wizard->back_button = '&lt; Back';
             $this->wizard->cancel_button = 'Cancel';
-            echo('<p><strong>Unable to create your new form.</strong></p>');
-            echo('<p>To correct the problem, click <em>back</em> and amend the details entered.</p>');
+            echo '<p><strong>Unable to create your new form.</strong></p>';
+            echo '<p>To correct the problem, click <em>back</em> and amend the details entered.</p>';
         } else {// Else.. create the form!
             if ($clone_form->save()) {
                 ?>
                 <p><strong>Your new assessment form has been created.</strong></p>
                 <p style="margin-top: 20px;">To add questions and marking information to your new form, you can use the
-                    <a href="../edit/edit_form.php?f=<?php echo($clone_form->id); ?>">form editor</a>.</p>
+                    <a href="../edit/edit_form.php?f=<?php echo $clone_form->id; ?>">form editor</a>.</p>
                 <p style="margin-top: 20px;">Alternatively, you can return to <a href="../">my forms</a>, or to the <a
                             href="../../../">WebPA home page</a>.</p>
                 <?php
@@ -82,14 +85,17 @@ function form()
                 <?php
             }
         }
-    }// /->form()
+    }
+
+    // /->form()
 
-    function process_form()
+    public function process_form()
     {
-        $this->wizard->_fields = array(); // kill the wizard's stored fields
+        $this->wizard->_fields = []; // kill the wizard's stored fields
         return null;
-    }// /->process_form()
+    }
 
+    // /->process_form()
 }// /class: WizardStep3
 
 ?>
diff --git a/src/tutors/forms/clone/clone_example.php b/src/tutors/forms/clone/clone_example.php
index 22a50e6..12b80b6 100644
--- a/src/tutors/forms/clone/clone_example.php
+++ b/src/tutors/forms/clone/clone_example.php
@@ -12,14 +12,14 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\Form;
 use WebPA\includes\functions\Common;
 
 if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 //get the form ID
@@ -28,11 +28,11 @@
 $form_id = Common::fetch_POST('f');
 
 if (empty($form_id)) {
-  $form_id = $formid;
+    $form_id = $formid;
 }
 
 if (empty($formid)) {
-  $formid = $form_id;
+    $formid = $form_id;
 }
 
 //get the form information
@@ -40,36 +40,34 @@
 $form->load($form_id);
 
 if (!empty($new_form_name)) {
-  //we are going to clone the form and then pass the user to the view area
-  $clone = $form->get_clone();
-  $clone->name = $new_form_name;
-  $clone->owner_id = Common::fetch_SESSION('_user_id', null);
-  $clone->save();
+    //we are going to clone the form and then pass the user to the view area
+    $clone = $form->get_clone();
+    $clone->name = $new_form_name;
+    $clone->owner_id = Common::fetch_SESSION('_user_id', null);
+    $clone->save();
+
+    header("Location: ../edit/edit_form.php?f={$clone->id}") ;
+    exit;
+}
 
-  header( "Location: ../edit/edit_form.php?f={$clone->id}" ) ;
-  exit;
+  // Begin Page
 
-} else {
+    $UI->page_title = APP__NAME . ' Copy ' . $form->name .' form';
+    $UI->menu_selected = 'my forms';
+    $UI->help_link = '?q=node/244';
+    $UI->breadcrumbs = ['home'           => '../../',
+               'my forms'       => '../',
+               'copy form'  => null, ];
 
-  // Begin Page
+    $UI->set_page_bar_button('List Forms', '../../../../images/buttons/button_form_list.gif', '../');
+    $UI->set_page_bar_button('Create Form', '../../../../images/buttons/button_form_create.gif', '../create/');
+    $UI->set_page_bar_button('Clone a Form', '../../../../images/buttons/button_form_clone.gif', '../clone/');
+    $UI->set_page_bar_button('Import a Form', '../../../../images/buttons/button_form_import.gif', 'import/');
 
-  $UI->page_title = APP__NAME . ' Copy ' . $form->name .' form';
-  $UI->menu_selected = 'my forms';
-  $UI->help_link = '?q=node/244';
-  $UI->breadcrumbs = array  ('home'           => '../../' ,
-               'my forms'       => '../' ,
-               'copy form'  => null ,);
-
-  $UI->set_page_bar_button('List Forms', '../../../../images/buttons/button_form_list.gif', '../');
-  $UI->set_page_bar_button('Create Form', '../../../../images/buttons/button_form_create.gif', '../create/');
-  $UI->set_page_bar_button('Clone a Form', '../../../../images/buttons/button_form_clone.gif', '../clone/');
-  $UI->set_page_bar_button('Import a Form', '../../../../images/buttons/button_form_import.gif', 'import/');
-
-  $UI->head();
-  $UI->body('onload="body_onload()"');
-  $UI->content_start();
-?>
-    <p>You have chosen to take a copy of the : <em><?php echo($form->name); ?></em> form.</p>
+    $UI->head();
+    $UI->body('onload="body_onload()"');
+    $UI->content_start(); ?>
+    <p>You have chosen to take a copy of the : <em><?php echo $form->name; ?></em> form.</p>
 
       <p>Now enter a name for your copy of the form.</p>
 <form action="clone_example.php" method="POST">
@@ -77,14 +75,14 @@
         <table class="form" cellpadding="2" cellspacing="2">
           <tr>
             <th><label for="clone_form_name">Name for new form</label></th>
-            <td><input type="text" name="n" id="clone_form_name" size="50" maxlength="100" value="<?php echo($form->name); ?>" /></td>
+            <td><input type="text" name="n" id="clone_form_name" size="50" maxlength="100" value="<?php echo $form->name; ?>" /></td>
           </tr>
         </table>
 
   <input type="hidden" name="f" value="<?php echo $formid; ?>" size="40" maxlength="40"/>
 
 
- <!-- <td class="button"><a href="<?php echo("clone_example.php?f={$formid}&n="); ?>">OK</a></td> -->
+ <!-- <td class="button"><a href="<?php echo "clone_example.php?f={$formid}&n="; ?>">OK</a></td> -->
 
   <input type="submit" name="ok" value="ok"/>
 
@@ -94,5 +92,5 @@
 </form>
 <?php
   $UI->content_end();
-}
+
 ?>
diff --git a/src/tutors/forms/clone/index.php b/src/tutors/forms/clone/index.php
index 57d80e4..315b138 100644
--- a/src/tutors/forms/clone/index.php
+++ b/src/tutors/forms/clone/index.php
@@ -8,30 +8,30 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\Wizard;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
 // Initialise wizard
 
 $wizard = new Wizard('clone an existing form wizard');
-$wizard->cancel_url = "../";
+$wizard->cancel_url = '../';
 
-$wizard->add_step(1,'class_wizardstep_1.php');
-$wizard->add_step(2,'class_wizardstep_2.php');
-$wizard->add_step(3,'class_wizardstep_3.php');
+$wizard->add_step(1, 'class_wizardstep_1.php');
+$wizard->add_step(2, 'class_wizardstep_2.php');
+$wizard->add_step(3, 'class_wizardstep_3.php');
 
 $wizard->show_steps(2); // Hide the last step from the user
 
-$wizard->set_var('db',$DB);
-$wizard->set_var('user',$_user);
+$wizard->set_var('db', $DB);
+$wizard->set_var('user', $_user);
 $wizard->set_var('moduleId', $_module_id);
 $wizard->set_var('sourceId', $_source_id);
 
@@ -48,11 +48,11 @@
 $UI->page_title = APP__NAME . ' Clone an existing form';
 $UI->menu_selected = 'my forms';
 $UI->help_link = '?q=node/244';
-$UI->breadcrumbs = array  (
-  'home'          => '../../' ,
-  'my forms'        => '../' ,
-  'clone a form wizard' => null ,
-);
+$UI->breadcrumbs = [
+  'home'          => '../../',
+  'my forms'        => '../',
+  'clone a form wizard' => null,
+];
 
 $UI->set_page_bar_button('List Forms', '../../../../images/buttons/button_form_list.gif', '../');
 $UI->set_page_bar_button('Create Form', '../../../../images/buttons/button_form_create.gif', '../create/');
diff --git a/src/tutors/forms/create/class_wizardstep_1.php b/src/tutors/forms/create/class_wizardstep_1.php
index 2f70236..eb2bdff 100644
--- a/src/tutors/forms/create/class_wizardstep_1.php
+++ b/src/tutors/forms/create/class_wizardstep_1.php
@@ -14,13 +14,12 @@
 class WizardStep1
 {
     public $wizard;
+
     public $step = 1;
 
     private $moduleId;
 
-    /*
-    * CONSTRUCTOR
-    */
+    // CONSTRUCTOR
     public function __construct(Wizard $wizard)
     {
         $this->wizard = $wizard;
@@ -30,9 +29,11 @@ public function __construct(Wizard $wizard)
         $this->wizard->back_button = null;
         $this->wizard->next_button = 'Finish';
         $this->wizard->cancel_button = 'Cancel';
-    }// /WizardStep1()
+    }
+
+    // /WizardStep1()
 
-    function head()
+    public function head()
     {
         ?>
         <script language="JavaScript" type="text/javascript">
@@ -45,9 +46,11 @@ function body_onload () {
           //-->
         </script>
         <?php
-    }// /->head()
+    }
+
+    // /->head()
 
-    function form()
+    public function form()
     {
         ?>
         <p>To create a new form you just need to give it a name. To avoid confusion, the name should be unique, but you
@@ -59,7 +62,7 @@ function form()
             <tr>
                 <th><label for="form_name">Name for this new form</label></th>
                 <td><input type="text" name="form_name" id="form_name" maxlength="100" size="40"
-                           value="<?php echo($this->wizard->get_field('form_name')); ?>"/></td>
+                           value="<?php echo $this->wizard->get_field('form_name'); ?>"/></td>
             </tr>
         </table>
 
@@ -69,12 +72,11 @@ function form()
         <label>What type scoring will your criteria use?</label>
         <p>WebPA offers two different ways that your students can score each other.</p>
         <?php
-        $form_type = $this->wizard->get_field('form_type', 'likert');
-        ?>
+        $form_type = $this->wizard->get_field('form_type', 'likert'); ?>
         <table>
             <tr>
                 <td style="vertical-align: top;"><input type="radio" name="form_type" id="type_likert"
-                                                        value="likert" <?php echo((($form_type == 'likert') ? 'checked="checked"' : '')); ?> />
+                                                        value="likert" <?php echo ($form_type == 'likert') ? 'checked="checked"' : ''; ?> />
                 </td>
                 <td>
                     <label for="type_likert">Likert Scale <span style="font-weight: normal;">(default)</span></label>
@@ -84,7 +86,7 @@ function form()
             </tr>
             <tr>
                 <td style="vertical-align: top;"><input type="radio" name="form_type" id="type_split100"
-                                                        value="split100" <?php echo((($form_type == 'split100') ? 'checked="checked"' : '')); ?> />
+                                                        value="split100" <?php echo ($form_type == 'split100') ? 'checked="checked"' : ''; ?> />
                 </td>
                 <td>
                     <label for="type_split100">Split 100</label>
@@ -96,10 +98,12 @@ function form()
             </tr>
         </table>
         <?php
-        echo("<input type=\"hidden\" name=\"form_modules[]\" id=\"module_{$this->moduleId}\" value=\"{$this->moduleId}\" />");
-    }// /->form()
+        echo "<input type=\"hidden\" name=\"form_modules[]\" id=\"module_{$this->moduleId}\" value=\"{$this->moduleId}\" />";
+    }
+
+    // /->form()
 
-    function process_form()
+    public function process_form()
     {
         $errors = null;
 
@@ -116,8 +120,9 @@ function process_form()
         $this->wizard->set_field('form_type', Common::fetch_POST('form_type'));
 
         return $errors;
-    }// /->process_form()
+    }
 
+    // /->process_form()
 }// /class: WizardStep1
 
 ?>
diff --git a/src/tutors/forms/create/class_wizardstep_2.php b/src/tutors/forms/create/class_wizardstep_2.php
index 0bb0ade..befc3a3 100644
--- a/src/tutors/forms/create/class_wizardstep_2.php
+++ b/src/tutors/forms/create/class_wizardstep_2.php
@@ -11,26 +11,29 @@
 use WebPA\includes\classes\Form;
 use WebPA\includes\classes\Wizard;
 
-class WizardStep2 {
+class WizardStep2
+{
+    public $wizard;
 
-  public $wizard;
-  public $step = 2;
+    public $step = 2;
 
-  /*
-  * CONSTRUCTOR
-  */
-  public function __construct(Wizard $wizard) {
-    $this->wizard = $wizard;
+    // CONSTRUCTOR
+    public function __construct(Wizard $wizard)
+    {
+        $this->wizard = $wizard;
 
-    $this->wizard->back_button = null;
-    $this->wizard->next_button = null;
-    $this->wizard->cancel_button = null;
+        $this->wizard->back_button = null;
+        $this->wizard->next_button = null;
+        $this->wizard->cancel_button = null;
 
-    ob_start();
-  }// /WizardStep2()
+        ob_start();
+    }
 
-  function head() {
-?>
+    // /WizardStep2()
+
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -40,54 +43,60 @@ function body_onload() {
 //-->
 </script>
 <?php
-  }// /->head()
+    }
 
-  function form() {
-    $config =& $this->wizard->get_var('config');
-    $DB =& $this->wizard->get_var('db');
-    $user =& $this->wizard->get_var('user');
+    // /->head()
 
-    $errors = null;
+    public function form()
+    {
+        $config =& $this->wizard->get_var('config');
+        $DB =& $this->wizard->get_var('db');
+        $user =& $this->wizard->get_var('user');
 
-    $form = new Form($DB);
-    $form->create();
-    $form->name = $this->wizard->get_field('form_name');
-    $form->modules = $this->wizard->get_field('form_modules');
-    $form->type = $this->wizard->get_field('form_type');
+        $errors = null;
 
-    // If errors, show them
-    if (is_array($errors)) {
-      $this->wizard->back_button = '&lt; Back';
-      $this->wizard->cancel_button = 'Cancel';
-      echo('<p><strong>Unable to create your new form.</strong></p>');
-      echo('<p>To correct the problem, click <em>back</em> and amend the details entered.</p>');
-    } else {// Else.. create the form!
+        $form = new Form($DB);
+        $form->create();
+        $form->name = $this->wizard->get_field('form_name');
+        $form->modules = $this->wizard->get_field('form_modules');
+        $form->type = $this->wizard->get_field('form_type');
 
-      $saved = $form->save();
+        // If errors, show them
+        if (is_array($errors)) {
+            $this->wizard->back_button = '&lt; Back';
+            $this->wizard->cancel_button = 'Cancel';
+            echo '<p><strong>Unable to create your new form.</strong></p>';
+            echo '<p>To correct the problem, click <em>back</em> and amend the details entered.</p>';
+        } else {// Else.. create the form!
 
-      if (!$saved) {
-?>
+            $saved = $form->save();
+
+            if (!$saved) {
+                ?>
         <p><strong>An error occurred while trying to create your new assessment form.</strong></p>
         <p>You may be able to correct the problem by clicking <em>back</em>, and then <em>next</em> again.</p>
 <?php
-      } else {
-        ob_end_clean();
-        header('Location: '. APP__WWW ."/tutors/forms/edit/edit_form.php?f={$form->id}");
-        exit;
-?>
+            } else {
+                ob_end_clean();
+                header('Location: '. APP__WWW ."/tutors/forms/edit/edit_form.php?f={$form->id}");
+                exit; ?>
         <p><strong>Your new assessment form has been created.</strong></p>
-        <p style="margin-top: 20px;">To add question and marking information to your form, you can use the <a href="../index.php?f=<?php echo($form->id); ?>">form editor</a>.</p>
+        <p style="margin-top: 20px;">To add question and marking information to your form, you can use the <a href="../index.php?f=<?php echo $form->id; ?>">form editor</a>.</p>
         <p style="margin-top: 20px;">Alternatively, you can return to <a href="/tutors/forms/">my forms</a>, or to the <a href="/">WebPA home page</a>.</p>
 <?php
-      }
+            }
+        }
     }
-  }// /->form()
 
-  function process_form() {
-    $this->wizard->_fields = array(); // kill the wizard's stored fields
-    return null;
-  }// /->process_form()
+    // /->form()
+
+    public function process_form()
+    {
+        $this->wizard->_fields = []; // kill the wizard's stored fields
+        return null;
+    }
 
+    // /->process_form()
 }// /class: WizardStep2
 
 ?>
diff --git a/src/tutors/forms/create/index.php b/src/tutors/forms/create/index.php
index 70e39f4..0b68be7 100644
--- a/src/tutors/forms/create/index.php
+++ b/src/tutors/forms/create/index.php
@@ -8,30 +8,30 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\Wizard;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
 // Initialise wizard
 
 $wizard = new Wizard('create a new form wizard');
-$wizard->cancel_url = "../";
+$wizard->cancel_url = '../';
 
-$wizard->add_step(1,'class_wizardstep_1.php');
-$wizard->add_step(2,'class_wizardstep_2.php');
+$wizard->add_step(1, 'class_wizardstep_1.php');
+$wizard->add_step(2, 'class_wizardstep_2.php');
 
 $wizard->show_steps(1); // Hide the last step from the user
 
-$wizard->set_var('db',$DB);
-$wizard->set_var('config',$_config);
-$wizard->set_var('user',$_user);
+$wizard->set_var('db', $DB);
+$wizard->set_var('config', $_config);
+$wizard->set_var('user', $_user);
 $wizard->set_var('moduleId', $_module_id);
 
 $wizard->prepare();
@@ -47,11 +47,11 @@
 $UI->page_title = APP__NAME . ' ' .'Create a new form';
 $UI->menu_selected = 'my forms';
 $UI->help_link = '?q=node/244';
-$UI->breadcrumbs = array  (
-  'home'                      => '../../' ,
-  'my forms'                  => '../' ,
-  'create a new form wizard'  => null ,
-);
+$UI->breadcrumbs = [
+  'home'                      => '../../',
+  'my forms'                  => '../',
+  'create a new form wizard'  => null,
+];
 
 $UI->set_page_bar_button('List Forms', '../../../../images/buttons/button_form_list.gif', '../');
 $UI->set_page_bar_button('Create Form', '../../../../images/buttons/button_form_create.gif', '../create/');
diff --git a/src/tutors/forms/edit/add_question/class_wizardstep_1.php b/src/tutors/forms/edit/add_question/class_wizardstep_1.php
index e07a22e..e8f36a5 100644
--- a/src/tutors/forms/edit/add_question/class_wizardstep_1.php
+++ b/src/tutors/forms/edit/add_question/class_wizardstep_1.php
@@ -12,25 +12,28 @@
 use WebPA\includes\functions\Common;
 use WebPA\includes\functions\Form;
 
-class WizardStep1 {
+class WizardStep1
+{
+    // Public
+    public $wizard;
 
-  // Public
-  public $wizard = null;
-  public $step = 1;
+    public $step = 1;
 
-  /*
-  * CONSTRUCTOR
-  */
-  function __construct(&$wizard) {
-    $this->wizard =& $wizard;
+    // CONSTRUCTOR
+    public function __construct(&$wizard)
+    {
+        $this->wizard =& $wizard;
 
-    $this->wizard->back_button = null;
-    $this->wizard->next_button = 'Next &gt;';
-    $this->wizard->cancel_button = 'Cancel';
-  }// /WizardStep1()
+        $this->wizard->back_button = null;
+        $this->wizard->next_button = 'Next &gt;';
+        $this->wizard->cancel_button = 'Cancel';
+    }
 
-  function head() {
-?>
+    // /WizardStep1()
+
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -41,17 +44,19 @@ function body_onload() {
 //-->
 </script>
 <?php
-  }// /->head()
-
-  function form() {
-    $config = $this->wizard->get_var('config');
-    if (!$this->wizard->get_field('question_range_start')) {
-      $this->wizard->set_field('question_range_start',1);
-    }
-    if (!$this->wizard->get_field('question_range_end')) {
-      $this->wizard->set_field('question_range_end',5);
     }
-?>
+
+    // /->head()
+
+    public function form()
+    {
+        $config = $this->wizard->get_var('config');
+        if (!$this->wizard->get_field('question_range_start')) {
+            $this->wizard->set_field('question_range_start', 1);
+        }
+        if (!$this->wizard->get_field('question_range_end')) {
+            $this->wizard->set_field('question_range_end', 5);
+        } ?>
     <p>To create a new marking question, you firstly need to enter the text of the question.</p>
 
     <div class="form_section">
@@ -61,11 +66,11 @@ function form() {
       <table cellpadding="2" cellspacing="2">
       <tr>
         <th><label for="question_text">Criterion Text</label></th>
-        <td><input type="text" name="question_text" id="question_text" maxlength="255" size="50" value="<?php echo( $this->wizard->get_field('question_text') ); ?>" /></td>
+        <td><input type="text" name="question_text" id="question_text" maxlength="255" size="50" value="<?php echo $this->wizard->get_field('question_text'); ?>" /></td>
       </tr>
       <tr>
         <th valign="top" width="100"><label for="question_desc">Description</label><br /><span style="font-size: 0.8em; font-weight: normal;">(optional)</span></th>
-        <td><textarea name="question_desc" id="question_desc" cols="60" rows="3" style="width: 90%;"><?php echo( $this->wizard->get_field('question_desc') ); ?></textarea></td>
+        <td><textarea name="question_desc" id="question_desc" cols="60" rows="3" style="width: 90%;"><?php echo $this->wizard->get_field('question_desc'); ?></textarea></td>
       </tr>
       </table>
     </div>
@@ -77,13 +82,13 @@ function form() {
         <th><label for="question_range_start">Scores can range from</label></th>
         <td>
           <select name="question_range_start" id="question_range_start">
-            <?php Form::render_options_range(0,1,1,(int) $this->wizard->get_field('question_range_start')); ?>
+            <?php Form::render_options_range(0, 1, 1, (int) $this->wizard->get_field('question_range_start')); ?>
           </select>
         </td>
         <td><label>to</label></td>
         <td>
           <select name="question_range_end" id="question_range_end">
-            <?php Form::render_options_range(3,10,1,(int) $this->wizard->get_field('question_range_end')); ?>
+            <?php Form::render_options_range(3, 10, 1, (int) $this->wizard->get_field('question_range_end')); ?>
           </select>
         </td>
       </tr>
@@ -91,22 +96,28 @@ function form() {
     </div>
     <p><strong>Please Note</strong> - allowing 0 scores means students can receive no marks if they failed to contribute at all.</p>
 <?php
-  }// /->form()
+    }
 
-  function process_form() {
-    $errors = null;
+    // /->form()
 
-    $this->wizard->set_field('question_text',Common::fetch_POST('question_text'));
-    if (empty($this->wizard->get_field('question_text'))) { $errors[] = 'You must provide some text for your new criterion'; }
+    public function process_form()
+    {
+        $errors = null;
 
-    $this->wizard->set_field('question_desc',Common::fetch_POST('question_desc'));
+        $this->wizard->set_field('question_text', Common::fetch_POST('question_text'));
+        if (empty($this->wizard->get_field('question_text'))) {
+            $errors[] = 'You must provide some text for your new criterion';
+        }
 
-    $this->wizard->set_field('question_range_start',Common::fetch_POST('question_range_start'));
-    $this->wizard->set_field('question_range_end',Common::fetch_POST('question_range_end'));
+        $this->wizard->set_field('question_desc', Common::fetch_POST('question_desc'));
 
-    return $errors;
-  }// /->process_form()
+        $this->wizard->set_field('question_range_start', Common::fetch_POST('question_range_start'));
+        $this->wizard->set_field('question_range_end', Common::fetch_POST('question_range_end'));
+
+        return $errors;
+    }
 
+    // /->process_form()
 }// /class: WizardStep1
 
 ?>
diff --git a/src/tutors/forms/edit/add_question/class_wizardstep_2.php b/src/tutors/forms/edit/add_question/class_wizardstep_2.php
index 5c92abd..ca6985b 100644
--- a/src/tutors/forms/edit/add_question/class_wizardstep_2.php
+++ b/src/tutors/forms/edit/add_question/class_wizardstep_2.php
@@ -10,25 +10,28 @@
 
 use WebPA\includes\functions\Common;
 
-class WizardStep2 {
+class WizardStep2
+{
+    // Public
+    public $wizard;
 
-  // Public
-  public $wizard = null;
-  public $step = 2;
+    public $step = 2;
 
-  /*
-  * CONSTRUCTOR
-  */
-  function __construct(&$wizard) {
-    $this->wizard =& $wizard;
+    // CONSTRUCTOR
+    public function __construct(&$wizard)
+    {
+        $this->wizard =& $wizard;
 
-    $this->wizard->back_button = '&lt; Back';
-    $this->wizard->next_button = 'Finish';
-    $this->wizard->cancel_button = 'Cancel';
-  }// /WizardStep2()
+        $this->wizard->back_button = '&lt; Back';
+        $this->wizard->next_button = 'Finish';
+        $this->wizard->cancel_button = 'Cancel';
+    }
 
-  function head() {
-?>
+    // /WizardStep2()
+
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -38,55 +41,62 @@ function body_onload() {
 //-->
 </script>
 <?php
-  }// /->head()
+    }
 
-  function form() {
-    $range_start = $this->wizard->get_field('question_range_start');
-    $range_end = $this->wizard->get_field('question_range_end');
-?>
-    <p>Your new assessment criterion allows scores from <?php echo("$range_start to $range_end"); ?>. You can use the boxes below to provide a description what those scores should mean.</p>
+    // /->head()
+
+    public function form()
+    {
+        $range_start = $this->wizard->get_field('question_range_start');
+        $range_end = $this->wizard->get_field('question_range_end'); ?>
+    <p>Your new assessment criterion allows scores from <?php echo "$range_start to $range_end"; ?>. You can use the boxes below to provide a description what those scores should mean.</p>
     <p>It's good practice to describe the meaning of at least the top and bottom scores, but you are free to provide as many, or as few, descriptions as you like. Leave a description blank and it will not be displayed on the form.</p>
 
     <p><strong>Score descriptions</strong></p>
     <div class="form_section">
-      <p><?php echo($this->wizard->get_field('question_text')); ?></p>
+      <p><?php echo $this->wizard->get_field('question_text'); ?></p>
       <table class="form" cellpadding="2" cellspacing="2">
 <?php
-    for($i=$range_start; $i<=$range_end; $i++) {
-      echo('<tr>');
-      echo("<th><label for=\"scorelabel{$i}\">Score $i</label></th>");
-      echo("<td><input type=\"text\" name=\"scorelabel{$i}\" id=\"scorelabel{$i}\" maxlength=\"255\" size=\"50\" value=\"". $this->wizard->get_field("scorelabel{$i}") ."\" /></td>");
-      if ($i==$range_start) {
-        echo('<td style="font-size: 0.9em; font-style: italic;">Lowest</td>');
-      } else {
-        if ($i==$range_end) {
-          echo('<td style="font-size: 0.9em; font-style: italic;">Highest</td>');
+    for ($i=$range_start; $i<=$range_end; $i++) {
+        echo '<tr>';
+        echo "<th><label for=\"scorelabel{$i}\">Score $i</label></th>";
+        echo "<td><input type=\"text\" name=\"scorelabel{$i}\" id=\"scorelabel{$i}\" maxlength=\"255\" size=\"50\" value=\"". $this->wizard->get_field("scorelabel{$i}") .'" /></td>';
+        if ($i==$range_start) {
+            echo '<td style="font-size: 0.9em; font-style: italic;">Lowest</td>';
         } else {
-          echo('<td>&nbsp;</td>');
+            if ($i==$range_end) {
+                echo '<td style="font-size: 0.9em; font-style: italic;">Highest</td>';
+            } else {
+                echo '<td>&nbsp;</td>';
+            }
         }
-      }
-      echo('</tr>');
-    }
-?>
+        echo '</tr>';
+    } ?>
       </table>
     </div>
 <?php
-  }// /->form()
+    }
 
-  function process_form() {
-    $errors = null;
+    // /->form()
 
-    $range_start = $this->wizard->get_field('question_range_start');
-    $range_end = $this->wizard->get_field('question_range_end');
+    public function process_form()
+    {
+        $errors = null;
 
-    for($i=$range_start; $i<=$range_end; $i++) {
-      $scorelabel = trim( Common::fetch_POST("scorelabel{$i}") );
-      if (!empty($scorelabel)) { $this->wizard->set_field("scorelabel{$i}",$scorelabel); }
-    }
+        $range_start = $this->wizard->get_field('question_range_start');
+        $range_end = $this->wizard->get_field('question_range_end');
 
-    return $errors;
-  }// /->process_form()
+        for ($i=$range_start; $i<=$range_end; $i++) {
+            $scorelabel = trim(Common::fetch_POST("scorelabel{$i}"));
+            if (!empty($scorelabel)) {
+                $this->wizard->set_field("scorelabel{$i}", $scorelabel);
+            }
+        }
+
+        return $errors;
+    }
 
+    // /->process_form()
 }// /class: WizardStep2
 
 ?>
diff --git a/src/tutors/forms/edit/add_question/class_wizardstep_3.php b/src/tutors/forms/edit/add_question/class_wizardstep_3.php
index 236ae02..1dcd270 100644
--- a/src/tutors/forms/edit/add_question/class_wizardstep_3.php
+++ b/src/tutors/forms/edit/add_question/class_wizardstep_3.php
@@ -11,27 +11,30 @@
 
 use WebPA\includes\functions\Common;
 
-class WizardStep3 {
+class WizardStep3
+{
+    // Public
+    public $wizard;
 
-  // Public
-  public $wizard = null;
-  public $step = 3;
+    public $step = 3;
 
-  /*
-  * CONSTRUCTOR
-  */
-  function __construct(&$wizard) {
-    $this->wizard =& $wizard;
+    // CONSTRUCTOR
+    public function __construct(&$wizard)
+    {
+        $this->wizard =& $wizard;
 
-    $this->wizard->back_button = null;
-    $this->wizard->next_button = null;
-    $this->wizard->cancel_button = null;
+        $this->wizard->back_button = null;
+        $this->wizard->next_button = null;
+        $this->wizard->cancel_button = null;
 
-    ob_start();
-  }// /WizardStep3()
+        ob_start();
+    }
 
-  function head() {
-?>
+    // /WizardStep3()
+
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -41,57 +44,65 @@ function body_onload() {
 //-->
 </script>
 <?php
-  }// /->head()
-
-  function form() {
-    $config =& $this->wizard->get_var('config');
-    $DB =& $this->wizard->get_var('db');
-    $user =& $this->wizard->get_var('user');
-    $form =& $this->wizard->get_var('form');
-
-    $range_start = $this->wizard->get_field('question_range_start');
-    $range_end = $this->wizard->get_field('question_range_end');
-
-    $new_question['text']['_data'] = $this->wizard->get_field('question_text');
-    $new_question['desc']['_data'] = $this->wizard->get_field('question_desc');
-
-    $new_question['range']['_data'] = "{$range_start}-{$range_end}";
-
-    for($i=$range_start; $i<=$range_end; $i++) {
-      $scorelabel = trim( Common::fetch_POST("scorelabel{$i}") );
-      if (!empty($scorelabel)) { $new_question["scorelabel{$i}"]['_data'] = $scorelabel; }
-    }
-
-    $errors = null;
-    if (!$form) {
-      $errors[] = 'Unable to load the form that this question is to be added to.';
-    } else {
-      $form->add_question($new_question);
-      $form->save();
     }
 
-    // If errors, show them
-    if (is_array($errors)) {
-      $this->wizard->back_button = '&lt; Back';
-      $this->wizard->cancel_button = 'Cancel';
-      echo('<p><strong>Unable to create your new criterion.</strong></p>');
-      echo('<p>To correct the problem, click <em>back</em> and amend the details entered.</p>');
-    } else {// Else.. create the form!
-      ob_end_clean();
-      header('Location: '. APP__WWW ."/tutors/forms/edit/edit_form.php?f={$form->id}#questions");
-      exit;
-      ?>
+    // /->head()
+
+    public function form()
+    {
+        $config =& $this->wizard->get_var('config');
+        $DB =& $this->wizard->get_var('db');
+        $user =& $this->wizard->get_var('user');
+        $form =& $this->wizard->get_var('form');
+
+        $range_start = $this->wizard->get_field('question_range_start');
+        $range_end = $this->wizard->get_field('question_range_end');
+
+        $new_question['text']['_data'] = $this->wizard->get_field('question_text');
+        $new_question['desc']['_data'] = $this->wizard->get_field('question_desc');
+
+        $new_question['range']['_data'] = "{$range_start}-{$range_end}";
+
+        for ($i=$range_start; $i<=$range_end; $i++) {
+            $scorelabel = trim(Common::fetch_POST("scorelabel{$i}"));
+            if (!empty($scorelabel)) {
+                $new_question["scorelabel{$i}"]['_data'] = $scorelabel;
+            }
+        }
+
+        $errors = null;
+        if (!$form) {
+            $errors[] = 'Unable to load the form that this question is to be added to.';
+        } else {
+            $form->add_question($new_question);
+            $form->save();
+        }
+
+        // If errors, show them
+        if (is_array($errors)) {
+            $this->wizard->back_button = '&lt; Back';
+            $this->wizard->cancel_button = 'Cancel';
+            echo '<p><strong>Unable to create your new criterion.</strong></p>';
+            echo '<p>To correct the problem, click <em>back</em> and amend the details entered.</p>';
+        } else {// Else.. create the form!
+            ob_end_clean();
+            header('Location: '. APP__WWW ."/tutors/forms/edit/edit_form.php?f={$form->id}#questions");
+            exit; ?>
       <p><strong>Your new assessment criterion has been created.</strong></p>
-      <p style="margin-top: 20px;">You can now return to <a href="../edit_form.php?f=<?php echo($form->id); ?>">editing your form</a>.</p>
+      <p style="margin-top: 20px;">You can now return to <a href="../edit_form.php?f=<?php echo $form->id; ?>">editing your form</a>.</p>
       <?php
+        }
     }
-  }// /->form()
 
-  function process_form() {
-    $this->wizard->_fields = array(); // kill the wizard's stored fields
-    return null;
-  }// /->process_form()
+    // /->form()
+
+    public function process_form()
+    {
+        $this->wizard->_fields = []; // kill the wizard's stored fields
+        return null;
+    }
 
+    // /->process_form()
 }// /class: WizardStep3
 
 ?>
diff --git a/src/tutors/forms/edit/add_question/index.php b/src/tutors/forms/edit/add_question/index.php
index 2429336..8a2f033 100644
--- a/src/tutors/forms/edit/add_question/index.php
+++ b/src/tutors/forms/edit/add_question/index.php
@@ -8,15 +8,15 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../../includes/inc_global.php");
+require_once '../../../../includes/inc_global.php';
 
 use WebPA\includes\classes\Form;
 use WebPA\includes\classes\Wizard;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -26,10 +26,10 @@
 
 $form = new Form($DB);
 if ($form->load($form_id)) {
-  $form_qs = "f={$form->id}";
+    $form_qs = "f={$form->id}";
 } else {
-  $form = null;
-  $form_qs = '';
+    $form = null;
+    $form_qs = '';
 }
 
 // --------------------------------------------------------------------------------
@@ -39,37 +39,37 @@
 $wiz_step = null;
 
 if ($form) {
-  $wizard->set_wizard_url("index.php?f=$form_id");
+    $wizard->set_wizard_url("index.php?f=$form_id");
 
-  $wizard->cancel_url = "../edit_form.php?f=$form_id";
+    $wizard->cancel_url = "../edit_form.php?f=$form_id";
 
-  $valid_types = array ('likert', 'split100');
+    $valid_types = ['likert', 'split100'];
 
-  if ($form->type=='split100') {
-    $wizard_path = DOC__ROOT . '/tutors/forms/edit/add_question/' . $form->type .'/';
+    if ($form->type=='split100') {
+        $wizard_path = DOC__ROOT . '/tutors/forms/edit/add_question/' . $form->type .'/';
 
-    $wizard->add_step(1, $wizard_path.'class_wizardstep_1.php');
-    $wizard->add_step(2, $wizard_path.'class_wizardstep_2.php');
+        $wizard->add_step(1, $wizard_path.'class_wizardstep_1.php');
+        $wizard->add_step(2, $wizard_path.'class_wizardstep_2.php');
 
-    $wizard->show_steps(1); // Hide the last step from the user
-  } else {
-    $wizard_path = DOC__ROOT . '/tutors/forms/edit/add_question/' . $form->type .'/';
+        $wizard->show_steps(1); // Hide the last step from the user
+    } else {
+        $wizard_path = DOC__ROOT . '/tutors/forms/edit/add_question/' . $form->type .'/';
 
-    $wizard->add_step(1, $wizard_path.'class_wizardstep_1.php');
-    $wizard->add_step(2, $wizard_path.'class_wizardstep_2.php');
-    $wizard->add_step(3, $wizard_path.'class_wizardstep_3.php');
+        $wizard->add_step(1, $wizard_path.'class_wizardstep_1.php');
+        $wizard->add_step(2, $wizard_path.'class_wizardstep_2.php');
+        $wizard->add_step(3, $wizard_path.'class_wizardstep_3.php');
 
-    $wizard->show_steps(2); // Hide the last step from the user
-  }
+        $wizard->show_steps(2); // Hide the last step from the user
+    }
 
-  $wizard->set_var('db',$DB);
-  $wizard->set_var('config',$_config);
-  $wizard->set_var('user',$_user);
-  $wizard->set_var('form',$form);
+    $wizard->set_var('db', $DB);
+    $wizard->set_var('config', $_config);
+    $wizard->set_var('user', $_user);
+    $wizard->set_var('form', $form);
 
-  $wizard->prepare();
+    $wizard->prepare();
 
-  $wiz_step = $wizard->get_step();
+    $wiz_step = $wizard->get_step();
 }
 
 // --------------------------------------------------------------------------------
@@ -78,12 +78,12 @@
 $UI->page_title = APP__NAME. ' Add a new criterion';
 $UI->menu_selected = 'my forms';
 $UI->help_link = '?q=node/244';
-$UI->breadcrumbs = array  (
-  'home'              => '../../' ,
-  'my forms'            => '/../' ,
-  "edit: {$form->name}"     => "../edit_form.php?$form_qs" ,
-  'add a new question'      => null ,
-);
+$UI->breadcrumbs = [
+  'home'              => '../../',
+  'my forms'            => '/../',
+  "edit: {$form->name}"     => "../edit_form.php?$form_qs",
+  'add a new question'      => null,
+];
 
 $UI->set_page_bar_button('List Forms', '../../../../../images/buttons/button_form_list.gif', '../../');
 $UI->set_page_bar_button('Create Form', '../../../../../images/buttons/button_form_create.gif', '../../create/');
@@ -92,10 +92,10 @@
 
 $UI->head();
 if ($form) {
-  $wizard->head();
-  $UI->body('onload="body_onload()"');
+    $wizard->head();
+    $UI->body('onload="body_onload()"');
 } else {
-  $UI->body();
+    $UI->body();
 }
 $UI->content_start();
 ?>
@@ -104,8 +104,8 @@
 
 <?php
 if ($form) {
-  $wizard->title();
-  $wizard->draw_errors();
+    $wizard->title();
+    $wizard->draw_errors();
 }
 ?>
 
@@ -113,9 +113,9 @@
 
 <?php
 if ($form) {
-  $wizard->draw_wizard();
+    $wizard->draw_wizard();
 } else {
-  echo("<p>The given assessment form failed to load so this wizard cannot be started.</p>");
+    echo '<p>The given assessment form failed to load so this wizard cannot be started.</p>';
 }
 ?>
 
diff --git a/src/tutors/forms/edit/add_question/likert/class_wizardstep_1.php b/src/tutors/forms/edit/add_question/likert/class_wizardstep_1.php
index 6ceedc0..5dce1c2 100644
--- a/src/tutors/forms/edit/add_question/likert/class_wizardstep_1.php
+++ b/src/tutors/forms/edit/add_question/likert/class_wizardstep_1.php
@@ -11,25 +11,28 @@
 use WebPA\includes\functions\Common;
 use WebPA\includes\functions\Form;
 
-class WizardStep1 {
+class WizardStep1
+{
+    // Public
+    public $wizard;
 
-  // Public
-  public $wizard = null;
-  public $step = 1;
+    public $step = 1;
 
-  /*
-  * CONSTRUCTOR
-  */
-  function __construct(&$wizard) {
-    $this->wizard =& $wizard;
+    // CONSTRUCTOR
+    public function __construct(&$wizard)
+    {
+        $this->wizard =& $wizard;
 
-    $this->wizard->back_button = null;
-    $this->wizard->next_button = 'Next &gt;';
-    $this->wizard->cancel_button = 'Cancel';
-  }// /WizardStep1()
+        $this->wizard->back_button = null;
+        $this->wizard->next_button = 'Next &gt;';
+        $this->wizard->cancel_button = 'Cancel';
+    }
 
-  function head() {
-?>
+    // /WizardStep1()
+
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -40,13 +43,19 @@ function body_onload() {
 //-->
 </script>
 <?php
-  }// /->head()
-
-  function form() {
-    $config = $this->wizard->get_var('config');
-    if (!$this->wizard->get_field('question_range_start')) { $this->wizard->set_field('question_range_start',1); }
-    if (!$this->wizard->get_field('question_range_end')) { $this->wizard->set_field('question_range_end',5); }
-?>
+    }
+
+    // /->head()
+
+    public function form()
+    {
+        $config = $this->wizard->get_var('config');
+        if (!$this->wizard->get_field('question_range_start')) {
+            $this->wizard->set_field('question_range_start', 1);
+        }
+        if (!$this->wizard->get_field('question_range_end')) {
+            $this->wizard->set_field('question_range_end', 5);
+        } ?>
     <p>To create a new marking question, you firstly need to enter the text of the question.</p>
 
     <div class="form_section">
@@ -56,11 +65,11 @@ function form() {
       <table cellpadding="2" cellspacing="2">
       <tr>
         <th><label for="question_text">Criterion Text</label></th>
-        <td><input type="text" name="question_text" id="question_text" maxlength="255" size="50" value="<?php echo( $this->wizard->get_field('question_text') ); ?>" /></td>
+        <td><input type="text" name="question_text" id="question_text" maxlength="255" size="50" value="<?php echo $this->wizard->get_field('question_text'); ?>" /></td>
       </tr>
       <tr>
         <th valign="top" width="100"><label for="question_desc">Description</label><br /><span style="font-size: 0.8em; font-weight: normal;">(optional)</span></th>
-        <td><textarea name="question_desc" id="question_desc" cols="60" rows="3" style="width: 90%;"><?php echo( $this->wizard->get_field('question_desc') ); ?></textarea></td>
+        <td><textarea name="question_desc" id="question_desc" cols="60" rows="3" style="width: 90%;"><?php echo $this->wizard->get_field('question_desc'); ?></textarea></td>
       </tr>
       </table>
     </div>
@@ -72,13 +81,13 @@ function form() {
         <th><label for="question_range_start">Scores can range from</label></th>
         <td>
           <select name="question_range_start" id="question_range_start">
-            <?php Form::render_options_range(0,1,1,(int) $this->wizard->get_field('question_range_start')); ?>
+            <?php Form::render_options_range(0, 1, 1, (int) $this->wizard->get_field('question_range_start')); ?>
           </select>
         </td>
         <td><label>to</label></td>
         <td>
           <select name="question_range_end" id="question_range_end">
-            <?php Form::render_options_range(3,10,1,(int) $this->wizard->get_field('question_range_end')); ?>
+            <?php Form::render_options_range(3, 10, 1, (int) $this->wizard->get_field('question_range_end')); ?>
           </select>
         </td>
       </tr>
@@ -86,22 +95,28 @@ function form() {
     </div>
     <p><strong>Please Note</strong> - allowing 0 scores means students can receive no marks if they failed to contribute at all.</p>
 <?php
-  }// /->form()
+    }
+
+    // /->form()
 
-  function process_form() {
-    $errors = null;
+    public function process_form()
+    {
+        $errors = null;
 
-    $this->wizard->set_field('question_text',Common::fetch_POST('question_text'));
-    if (empty($this->wizard->get_field('question_text'))) { $errors[] = 'You must provide some text for your new criterion'; }
+        $this->wizard->set_field('question_text', Common::fetch_POST('question_text'));
+        if (empty($this->wizard->get_field('question_text'))) {
+            $errors[] = 'You must provide some text for your new criterion';
+        }
 
-    $this->wizard->set_field('question_desc',Common::fetch_POST('question_desc'));
+        $this->wizard->set_field('question_desc', Common::fetch_POST('question_desc'));
 
-    $this->wizard->set_field('question_range_start',Common::fetch_POST('question_range_start'));
-    $this->wizard->set_field('question_range_end',Common::fetch_POST('question_range_end'));
+        $this->wizard->set_field('question_range_start', Common::fetch_POST('question_range_start'));
+        $this->wizard->set_field('question_range_end', Common::fetch_POST('question_range_end'));
 
-    return $errors;
-  }// /->process_form()
+        return $errors;
+    }
 
+    // /->process_form()
 }// /class: WizardStep1
 
 
diff --git a/src/tutors/forms/edit/add_question/likert/class_wizardstep_2.php b/src/tutors/forms/edit/add_question/likert/class_wizardstep_2.php
index d5d84c0..f9b3815 100644
--- a/src/tutors/forms/edit/add_question/likert/class_wizardstep_2.php
+++ b/src/tutors/forms/edit/add_question/likert/class_wizardstep_2.php
@@ -10,25 +10,28 @@
 
 use WebPA\includes\functions\Common;
 
-class WizardStep2 {
+class WizardStep2
+{
+    // Public
+    public $wizard;
 
-  // Public
-  public $wizard = null;
-  public $step = 2;
+    public $step = 2;
 
-  /*
-  * CONSTRUCTOR
-  */
-  function __construct(&$wizard) {
-    $this->wizard =& $wizard;
+    // CONSTRUCTOR
+    public function __construct(&$wizard)
+    {
+        $this->wizard =& $wizard;
 
-    $this->wizard->back_button = '&lt; Back';
-    $this->wizard->next_button = 'Finish';
-    $this->wizard->cancel_button = 'Cancel';
-  }// /WizardStep2()
+        $this->wizard->back_button = '&lt; Back';
+        $this->wizard->next_button = 'Finish';
+        $this->wizard->cancel_button = 'Cancel';
+    }
 
-  function head() {
-?>
+    // /WizardStep2()
+
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -38,55 +41,62 @@ function body_onload() {
 //-->
 </script>
 <?php
-  }// /->head()
+    }
 
-  function form() {
-    $range_start = $this->wizard->get_field('question_range_start');
-    $range_end = $this->wizard->get_field('question_range_end');
-?>
-    <p>Your new assessment criterion allows scores from <?php echo("$range_start to $range_end"); ?>. You can use the boxes below to provide a description what those scores should mean.</p>
+    // /->head()
+
+    public function form()
+    {
+        $range_start = $this->wizard->get_field('question_range_start');
+        $range_end = $this->wizard->get_field('question_range_end'); ?>
+    <p>Your new assessment criterion allows scores from <?php echo "$range_start to $range_end"; ?>. You can use the boxes below to provide a description what those scores should mean.</p>
     <p>It's good practice to describe the meaning of at least the top and bottom scores, but you are free to provide as many, or as few, descriptions as you like. Leave a description blank and it will not be displayed on the form.</p>
 
     <p><strong>Score descriptions</strong></p>
     <div class="form_section">
-      <p><?php echo($this->wizard->get_field('question_text')); ?></p>
+      <p><?php echo $this->wizard->get_field('question_text'); ?></p>
       <table class="form" cellpadding="2" cellspacing="2">
       <?php
-        for($i=$range_start; $i<=$range_end; $i++) {
-          echo('<tr>');
-          echo("<th><label for=\"scorelabel{$i}\">Score $i</label></th>");
-          echo("<td><input type=\"text\" name=\"scorelabel{$i}\" id=\"scorelabel{$i}\" maxlength=\"255\" size=\"50\" value=\"". $this->wizard->get_field("scorelabel{$i}") ."\" /></td>");
-          if ($i==$range_start) {
-            echo('<td style="font-size: 0.9em; font-style: italic;">Lowest</td>');
-          } else {
-            if ($i==$range_end) {
-              echo('<td style="font-size: 0.9em; font-style: italic;">Highest</td>');
+        for ($i=$range_start; $i<=$range_end; $i++) {
+            echo '<tr>';
+            echo "<th><label for=\"scorelabel{$i}\">Score $i</label></th>";
+            echo "<td><input type=\"text\" name=\"scorelabel{$i}\" id=\"scorelabel{$i}\" maxlength=\"255\" size=\"50\" value=\"". $this->wizard->get_field("scorelabel{$i}") .'" /></td>';
+            if ($i==$range_start) {
+                echo '<td style="font-size: 0.9em; font-style: italic;">Lowest</td>';
             } else {
-              echo('<td>&nbsp;</td>');
+                if ($i==$range_end) {
+                    echo '<td style="font-size: 0.9em; font-style: italic;">Highest</td>';
+                } else {
+                    echo '<td>&nbsp;</td>';
+                }
             }
-          }
-          echo('</tr>');
-        }
-?>
+            echo '</tr>';
+        } ?>
       </table>
     </div>
 <?php
-  }// /->form()
+    }
 
-  function process_form() {
-    $errors = null;
+    // /->form()
 
-    $range_start = $this->wizard->get_field('question_range_start');
-    $range_end = $this->wizard->get_field('question_range_end');
+    public function process_form()
+    {
+        $errors = null;
 
-    for($i=$range_start; $i<=$range_end; $i++) {
-      $scorelabel = trim( Common::fetch_POST("scorelabel{$i}") );
-      if (!empty($scorelabel)) { $this->wizard->set_field("scorelabel{$i}",$scorelabel); }
-    }
+        $range_start = $this->wizard->get_field('question_range_start');
+        $range_end = $this->wizard->get_field('question_range_end');
 
-    return $errors;
-  }// /->process_form()
+        for ($i=$range_start; $i<=$range_end; $i++) {
+            $scorelabel = trim(Common::fetch_POST("scorelabel{$i}"));
+            if (!empty($scorelabel)) {
+                $this->wizard->set_field("scorelabel{$i}", $scorelabel);
+            }
+        }
+
+        return $errors;
+    }
 
+    // /->process_form()
 }// /class: WizardStep2
 
 ?>
diff --git a/src/tutors/forms/edit/add_question/likert/class_wizardstep_3.php b/src/tutors/forms/edit/add_question/likert/class_wizardstep_3.php
index dd09deb..287678f 100644
--- a/src/tutors/forms/edit/add_question/likert/class_wizardstep_3.php
+++ b/src/tutors/forms/edit/add_question/likert/class_wizardstep_3.php
@@ -11,27 +11,30 @@
 
 use WebPA\includes\functions\Common;
 
-class WizardStep3 {
+class WizardStep3
+{
+    // Public
+    public $wizard;
 
-  // Public
-  public $wizard = null;
-  public $step = 3;
+    public $step = 3;
 
-  /*
-  * CONSTRUCTOR
-  */
-  function __construct(&$wizard) {
-    $this->wizard =& $wizard;
+    // CONSTRUCTOR
+    public function __construct(&$wizard)
+    {
+        $this->wizard =& $wizard;
 
-    $this->wizard->back_button = null;
-    $this->wizard->next_button = null;
-    $this->wizard->cancel_button = null;
+        $this->wizard->back_button = null;
+        $this->wizard->next_button = null;
+        $this->wizard->cancel_button = null;
 
-    ob_start();
-  }// /WizardStep3()
+        ob_start();
+    }
 
-  function head() {
-?>
+    // /WizardStep3()
+
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -41,57 +44,65 @@ function body_onload() {
 //-->
 </script>
 <?php
-  }// /->head()
-
-  function form() {
-    $config =& $this->wizard->get_var('config');
-    $DB =& $this->wizard->get_var('db');
-    $user =& $this->wizard->get_var('user');
-    $form =& $this->wizard->get_var('form');
-
-    $range_start = $this->wizard->get_field('question_range_start');
-    $range_end = $this->wizard->get_field('question_range_end');
-
-    $new_question['text']['_data'] = $this->wizard->get_field('question_text');
-    $new_question['desc']['_data'] = $this->wizard->get_field('question_desc');
-
-    $new_question['range']['_data'] = "{$range_start}-{$range_end}";
-
-    for($i=$range_start; $i<=$range_end; $i++) {
-      $scorelabel = trim( Common::fetch_POST("scorelabel{$i}") );
-      if (!empty($scorelabel)) { $new_question["scorelabel{$i}"]['_data'] = $scorelabel; }
-    }
-
-    $errors = null;
-    if (!$form) {
-      $errors[] = 'Unable to load the form that this question is to be added to.';
-    } else {
-      $form->add_question($new_question);
-      $form->save();
     }
 
-    // If errors, show them
-    if (is_array($errors)) {
-      $this->wizard->back_button = '&lt; Back';
-      $this->wizard->cancel_button = 'Cancel';
-      echo('<p><strong>Unable to create your new criterion.</strong></p>');
-      echo('<p>To correct the problem, click <em>back</em> and amend the details entered.</p>');
-    } else {// Else.. create the form!
-      ob_end_clean();
-      header('Location: '. APP__WWW ."/tutors/forms/edit/edit_form.php?f={$form->id}#questions");
-      exit;
-?>
+    // /->head()
+
+    public function form()
+    {
+        $config =& $this->wizard->get_var('config');
+        $DB =& $this->wizard->get_var('db');
+        $user =& $this->wizard->get_var('user');
+        $form =& $this->wizard->get_var('form');
+
+        $range_start = $this->wizard->get_field('question_range_start');
+        $range_end = $this->wizard->get_field('question_range_end');
+
+        $new_question['text']['_data'] = $this->wizard->get_field('question_text');
+        $new_question['desc']['_data'] = $this->wizard->get_field('question_desc');
+
+        $new_question['range']['_data'] = "{$range_start}-{$range_end}";
+
+        for ($i=$range_start; $i<=$range_end; $i++) {
+            $scorelabel = trim(Common::fetch_POST("scorelabel{$i}"));
+            if (!empty($scorelabel)) {
+                $new_question["scorelabel{$i}"]['_data'] = $scorelabel;
+            }
+        }
+
+        $errors = null;
+        if (!$form) {
+            $errors[] = 'Unable to load the form that this question is to be added to.';
+        } else {
+            $form->add_question($new_question);
+            $form->save();
+        }
+
+        // If errors, show them
+        if (is_array($errors)) {
+            $this->wizard->back_button = '&lt; Back';
+            $this->wizard->cancel_button = 'Cancel';
+            echo '<p><strong>Unable to create your new criterion.</strong></p>';
+            echo '<p>To correct the problem, click <em>back</em> and amend the details entered.</p>';
+        } else {// Else.. create the form!
+            ob_end_clean();
+            header('Location: '. APP__WWW ."/tutors/forms/edit/edit_form.php?f={$form->id}#questions");
+            exit; ?>
       <p><strong>Your new assessment criterion has been created.</strong></p>
-      <p style="margin-top: 20px;">You can now return to <a href="../edit_form.php?f=<?php echo($form->id); ?>">editing your form</a>.</p>
+      <p style="margin-top: 20px;">You can now return to <a href="../edit_form.php?f=<?php echo $form->id; ?>">editing your form</a>.</p>
 <?php
+        }
     }
-  }// /->form()
 
-  function process_form() {
-    $this->wizard->_fields = array(); // kill the wizard's stored fields
-    return null;
-  }// /->process_form()
+    // /->form()
+
+    public function process_form()
+    {
+        $this->wizard->_fields = []; // kill the wizard's stored fields
+        return null;
+    }
 
+    // /->process_form()
 }// /class: WizardStep3
 
 ?>
diff --git a/src/tutors/forms/edit/add_question/split100/class_wizardstep_1.php b/src/tutors/forms/edit/add_question/split100/class_wizardstep_1.php
index 93a401b..555414f 100644
--- a/src/tutors/forms/edit/add_question/split100/class_wizardstep_1.php
+++ b/src/tutors/forms/edit/add_question/split100/class_wizardstep_1.php
@@ -10,25 +10,28 @@
 
 use WebPA\includes\functions\Common;
 
-class WizardStep1 {
+class WizardStep1
+{
+    // Public
+    public $wizard;
 
-  // Public
-  public $wizard = null;
-  public $step = 1;
+    public $step = 1;
 
-  /*
-  * CONSTRUCTOR
-  */
-  function __construct(&$wizard) {
-    $this->wizard =& $wizard;
+    // CONSTRUCTOR
+    public function __construct(&$wizard)
+    {
+        $this->wizard =& $wizard;
 
-    $this->wizard->back_button = null;
-    $this->wizard->next_button = 'Finish';
-    $this->wizard->cancel_button = 'Cancel';
-  }// /WizardStep1()
+        $this->wizard->back_button = null;
+        $this->wizard->next_button = 'Finish';
+        $this->wizard->cancel_button = 'Cancel';
+    }
 
-  function head() {
-?>
+    // /WizardStep1()
+
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -39,13 +42,19 @@ function body_onload() {
 //-->
 </script>
 <?php
-  }// /->head()
-
-  function form() {
-    $config = $this->wizard->get_var('config');
-    if (!$this->wizard->get_field('question_range_start')) { $this->wizard->set_field('question_range_start',1); }
-    if (!$this->wizard->get_field('question_range_end')) { $this->wizard->set_field('question_range_end',5); }
-?>
+    }
+
+    // /->head()
+
+    public function form()
+    {
+        $config = $this->wizard->get_var('config');
+        if (!$this->wizard->get_field('question_range_start')) {
+            $this->wizard->set_field('question_range_start', 1);
+        }
+        if (!$this->wizard->get_field('question_range_end')) {
+            $this->wizard->set_field('question_range_end', 5);
+        } ?>
     <p>To create a new marking question, you firstly need to enter the text of the question.</p>
 
     <div class="form_section">
@@ -55,11 +64,11 @@ function form() {
       <table cellpadding="2" cellspacing="2">
       <tr>
         <th><label for="question_text">Criterion Text</label></th>
-        <td><input type="text" name="question_text" id="question_text" maxlength="255" size="50" value="<?php echo( $this->wizard->get_field('question_text') ); ?>" /></td>
+        <td><input type="text" name="question_text" id="question_text" maxlength="255" size="50" value="<?php echo $this->wizard->get_field('question_text'); ?>" /></td>
       </tr>
       <tr>
         <th valign="top" width="100"><label for="question_desc">Description</label><br /><span style="font-size: 0.8em; font-weight: normal;">(optional)</span></th>
-        <td><textarea name="question_desc" id="question_desc" cols="60" rows="3" style="width: 90%;"><?php echo( $this->wizard->get_field('question_desc') ); ?></textarea></td>
+        <td><textarea name="question_desc" id="question_desc" cols="60" rows="3" style="width: 90%;"><?php echo $this->wizard->get_field('question_desc'); ?></textarea></td>
       </tr>
       </table>
 
@@ -67,19 +76,25 @@ function form() {
 
     </div>
 <?php
-  }// /->form()
+    }
+
+    // /->form()
 
-  function process_form() {
-    $errors = null;
+    public function process_form()
+    {
+        $errors = null;
 
-    $this->wizard->set_field('question_text',Common::fetch_POST('question_text'));
-    if (empty($this->wizard->get_field('question_text'))) { $errors[] = 'You must provide some text for your new criterion'; }
+        $this->wizard->set_field('question_text', Common::fetch_POST('question_text'));
+        if (empty($this->wizard->get_field('question_text'))) {
+            $errors[] = 'You must provide some text for your new criterion';
+        }
 
-    $this->wizard->set_field('question_desc',Common::fetch_POST('question_desc'));
+        $this->wizard->set_field('question_desc', Common::fetch_POST('question_desc'));
 
-    return $errors;
-  }// /->process_form()
+        return $errors;
+    }
 
+    // /->process_form()
 }// /class: WizardStep1
 
 ?>
diff --git a/src/tutors/forms/edit/add_question/split100/class_wizardstep_2.php b/src/tutors/forms/edit/add_question/split100/class_wizardstep_2.php
index cf58bab..8cfb92f 100644
--- a/src/tutors/forms/edit/add_question/split100/class_wizardstep_2.php
+++ b/src/tutors/forms/edit/add_question/split100/class_wizardstep_2.php
@@ -9,27 +9,30 @@
  * @link https://github.com/webpa/webpa
  */
 
-class WizardStep2 {
+class WizardStep2
+{
+    // Public
+    public $wizard;
 
-  // Public
-  public $wizard = null;
-  public $step = 2;
+    public $step = 2;
 
-  /*
-  * CONSTRUCTOR
-  */
-  function __construct(&$wizard) {
-    $this->wizard =& $wizard;
+    // CONSTRUCTOR
+    public function __construct(&$wizard)
+    {
+        $this->wizard =& $wizard;
 
-    $this->wizard->back_button = null;
-    $this->wizard->next_button = null;
-    $this->wizard->cancel_button = null;
+        $this->wizard->back_button = null;
+        $this->wizard->next_button = null;
+        $this->wizard->cancel_button = null;
 
-    ob_start();
-  }// /WizardStep3()
+        ob_start();
+    }
 
-  function head() {
-?>
+    // /WizardStep3()
+
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -39,47 +42,53 @@ function body_onload() {
 //-->
 </script>
 <?php
-  }// /->head()
-
-  function form() {
-    $config =& $this->wizard->get_var('config');
-    $DB =& $this->wizard->get_var('db');
-    $user =& $this->wizard->get_var('user');
-    $form =& $this->wizard->get_var('form');
-
-    $new_question['text']['_data'] = $this->wizard->get_field('question_text');
-    $new_question['desc']['_data'] = $this->wizard->get_field('question_desc');
-
-    $errors = null;
-    if (!$form) {
-      $errors[] = 'Unable to load the form that this question is to be added to.';
-    } else {
-      $form->add_question($new_question);
-      $form->save();
     }
 
-    // If errors, show them
-    if (is_array($errors)) {
-      $this->wizard->back_button = '&lt; Back';
-      $this->wizard->cancel_button = 'Cancel';
-      echo('<p><strong>Unable to create your new criterion.</strong></p>');
-      echo('<p>To correct the problem, click <em>back</em> and amend the details entered.</p>');
-    } else {// Else.. create the form!
-      ob_end_clean();
-      header('Location: '. APP__WWW ."/tutors/forms/edit/edit_form.php?f={$form->id}#questions");
-      exit;
-      ?>
+    // /->head()
+
+    public function form()
+    {
+        $config =& $this->wizard->get_var('config');
+        $DB =& $this->wizard->get_var('db');
+        $user =& $this->wizard->get_var('user');
+        $form =& $this->wizard->get_var('form');
+
+        $new_question['text']['_data'] = $this->wizard->get_field('question_text');
+        $new_question['desc']['_data'] = $this->wizard->get_field('question_desc');
+
+        $errors = null;
+        if (!$form) {
+            $errors[] = 'Unable to load the form that this question is to be added to.';
+        } else {
+            $form->add_question($new_question);
+            $form->save();
+        }
+
+        // If errors, show them
+        if (is_array($errors)) {
+            $this->wizard->back_button = '&lt; Back';
+            $this->wizard->cancel_button = 'Cancel';
+            echo '<p><strong>Unable to create your new criterion.</strong></p>';
+            echo '<p>To correct the problem, click <em>back</em> and amend the details entered.</p>';
+        } else {// Else.. create the form!
+            ob_end_clean();
+            header('Location: '. APP__WWW ."/tutors/forms/edit/edit_form.php?f={$form->id}#questions");
+            exit; ?>
       <p><strong>Your new assessment criterion has been created.</strong></p>
-      <p style="margin-top: 20px;">You can now return to <a href="../edit_form.php?f=<?php echo($form->id); ?>">editing your form</a>.</p>
+      <p style="margin-top: 20px;">You can now return to <a href="../edit_form.php?f=<?php echo $form->id; ?>">editing your form</a>.</p>
       <?php
+        }
     }
-  }// /->form()
 
-  function process_form() {
-    $this->wizard->_fields = array(); // kill the wizard's stored fields
-    return null;
-  }// /->process_form()
+    // /->form()
+
+    public function process_form()
+    {
+        $this->wizard->_fields = []; // kill the wizard's stored fields
+        return null;
+    }
 
+    // /->process_form()
 }// /class: WizardStep2
 
 ?>
diff --git a/src/tutors/forms/edit/edit_form.php b/src/tutors/forms/edit/edit_form.php
index 0e2c4ff..43e0245 100644
--- a/src/tutors/forms/edit/edit_form.php
+++ b/src/tutors/forms/edit/edit_form.php
@@ -8,14 +8,14 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\Form;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -30,9 +30,9 @@
 
 $form = new Form($DB);
 if ($form->load($form_id)) {
-  $form_qs = "f={$form->id}";
+    $form_qs = "f={$form->id}";
 } else {
-  $form = null;
+    $form = null;
 }
 
 
@@ -41,25 +41,25 @@
 
 $errors = null;
 
-if ( ($command) && ($form) ) {
-  switch ($command) {
+if (($command) && ($form)) {
+    switch ($command) {
     case 'save':
       // Change of name
       $form->name = Common::fetch_POST('form_name');
-          if (empty($form->name)) { $errors[] = 'You must give this form a name.'; }
-
-          $form->type = Common::fetch_POST('form_type');
+          if (empty($form->name)) {
+              $errors[] = 'You must give this form a name.';
+          }
 
       // If there were no errors, save the changes
       if (!$errors) {
-        $form->save();
+          $form->save();
       }
       break;
     // --------------------
     case 'delete':
-      if (!$_user->is_staff()){
-        header('Location:'. APP__WWW .'/logout.php?msg=illegal');
-        exit;
+      if (!$_user->is_staff()) {
+          header('Location:'. APP__WWW .'/logout.php?msg=illegal');
+          exit;
       }
       $form->delete();
       header('Location: '. APP__WWW .'/tutors/forms/index.php');
@@ -76,11 +76,11 @@
 $UI->page_title = APP__NAME . ' ' . $page_title;
 $UI->menu_selected = 'my forms';
 $UI->help_link = '?q=node/244';
-$UI->breadcrumbs = array(
-  'home'         => '../../' ,
-  'my forms'     => '../' ,
-  $page_title    => null ,
-);
+$UI->breadcrumbs = [
+  'home'         => '../../',
+  'my forms'     => '../',
+  $page_title    => null,
+];
 
 $UI->set_page_bar_button('List Forms', '../../../../images/buttons/button_form_list.gif', '../');
 $UI->set_page_bar_button('Create Form', '../../../../images/buttons/button_form_create.gif', '../create/');
@@ -102,7 +102,7 @@ function do_command(com) {
         break;
       case 'preview' :
         var popupwin;
-        popupwin = window.open('preview_form.php?f=<?php echo($form->id); ?>','preview');
+        popupwin = window.open('preview_form.php?f=<?php echo $form->id; ?>','preview');
         popupwin.focus();
         break;
       default :
@@ -126,7 +126,7 @@ function do_command(com) {
 
 <?php
 if (!$form) {
-?>
+    ?>
   <div class="nav_button_bar">
     <a href="../"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to forms list</a>
   </div>
@@ -134,8 +134,8 @@ function do_command(com) {
   <p>The form you selected could not be loaded for some reason - please go back and try again.</p>
 <?php
 } else {
-?>
-  <form action="edit_form.php?<?php echo($form_qs); ?>" method="post" name="assessmentform_form">
+        ?>
+  <form action="edit_form.php?<?php echo $form_qs; ?>" method="post" name="assessmentform_form">
   <input type="hidden" name="command" value="none" />
 
   <div class="nav_button_bar">
@@ -154,26 +154,12 @@ function do_command(com) {
     <table class="form" cellpadding="2" cellspacing="2">
     <tr>
       <th><label for="form_name">Name</label></th>
-      <td><input type="text" name="form_name" id="form_name" maxlength="100" size="40" value="<?php echo($form->name)?>" /></td>
+      <td><input type="text" name="form_name" id="form_name" maxlength="100" size="40" value="<?php echo $form->name?>" /></td>
     </tr>
     <tr>
-      <th style="vertical-align: top;"><label for="form_type">Scoring Type</label></th>
+      <th style="vertical-align: top;">Scoring Type</th>
       <td>
-        <select name="form_type" id="form_type">
-          <option value="likert" <?php if ($form->type=='likert') { echo('selected="selected"'); } ?>> Likert Scale </option>
-          <option value="split100" <?php if ($form->type=='split100') { echo('selected="selected"'); } ?>> Split 100 </option>
-        </select>
-<?php
-  if ($form->type=='likert') {
-?>
-          <p style="font-size: 0.8em;">Changing from <em>likert scale</em> to <em>split 100</em> will keep your criteria's text, but delete the scoring ranges and labels.</p>
-<?php
-  } else {
-?>
-          <p style="font-size: 0.8em;">Changing from <em>split 100</em> to <em>likert scale</em> will keep your criteria's text, and set all scoring ranges to 1-5.</p>
-<?php
-  }
-?>
+        <?= $form->type === 'likert' ? 'Likert Scale' : 'Split 100' ?>
       </td>
     </tr>
     </table>
@@ -188,93 +174,86 @@ function do_command(com) {
   <div class="form_section">
 <?php
   $question_count = (int) $form->get_question_count();
-  if ($question_count==0) {
-?>
-      <p>You have not added any assessment criteria to this form yet. You need to <a class="button" href="../edit/add_question/index.php?<?php echo($form_qs); ?>">add&nbsp;a&nbsp;new&nbsp;criterion</a> before the form can be used.</p>
+        if ($question_count==0) {
+            ?>
+      <p>You have not added any assessment criteria to this form yet. You need to <a class="button" href="../edit/add_question/index.php?<?php echo $form_qs; ?>">add&nbsp;a&nbsp;new&nbsp;criterion</a> before the form can be used.</p>
 <?php
-  } else {
-?>
+        } else {
+            ?>
       <p>The group will rate themselves and each other against the assessment criteria you specify.</p>
       <p>e.g. <em>"Ability to communicate"</em> or <em>"Contribution to the analysis of the experimental data"</em>.</p>
-      <p>You can edit a criterion by clicking on the <img src="../../../images/buttons/edit.gif" width="16" height="16" alt="edit question" title="edit" /> button, or you can <a class="button" href="../edit/add_question/index.php?<?php echo($form_qs); ?>">add&nbsp;a&nbsp;new&nbsp;criterion</a></p>
+      <p>You can edit a criterion by clicking on the <img src="../../../images/buttons/edit.gif" width="16" height="16" alt="edit question" title="edit" /> button, or you can <a class="button" href="../edit/add_question/index.php?<?php echo $form_qs; ?>">add&nbsp;a&nbsp;new&nbsp;criterion</a></p>
 
       <div class="obj_list">
 <?php
     for ($i=0; $i<$question_count; $i++) {
-      $question_qs = "{$form_qs}&q=$i";
-      $question = $form->get_question($i);
+        $question_qs = "{$form_qs}&q=$i";
+        $question = $form->get_question($i);
 
-      $edit_url = "edit_question/index.php?$question_qs";
-?>
+        $edit_url = "edit_question/index.php?$question_qs"; ?>
         <div class="obj">
           <table class="obj" cellpadding="0" cellspacing="0">
           <tr>
             <td class="obj_info" valign="top">
-              <div class="obj_name"><a class="text" href="<?php echo($edit_url); ?>"><?php echo($question['text']['_data']); ?></a></div>
+              <div class="obj_name"><a class="text" href="<?php echo $edit_url; ?>"><?php echo $question['text']['_data']; ?></a></div>
 <?php
       if (array_key_exists('desc', $question)) {
-        $question_desc = (array_key_exists('desc', $question)) ? $question['desc']['_data'] : '' ;
-        echo("<div class=\"obj_info_text\">$question_desc</div>");
+          $question_desc = (array_key_exists('desc', $question)) ? $question['desc']['_data'] : '' ;
+          echo "<div class=\"obj_info_text\">$question_desc</div>";
       }
 
-      if ($form->type!='split100') {
-?>
-                  <div class="obj_info_text">Scoring range: <?php echo($question['range']['_data']); ?></div>
+        if ($form->type!='split100' && isset($question['range'])) {
+            ?>
+                  <div class="obj_info_text">Scoring range: <?php echo $question['range']['_data']; ?></div>
 <?php
-        foreach($question as $k => $v) {
-          if (strpos($k,'scorelabel')===0) {
-            $num = str_replace('scorelabel','',$k);
-            echo("<div class=\"obj_info_text\">Score $num : {$v['_data']}</div>");
-          }
+        foreach ($question as $k => $v) {
+            if (strpos($k, 'scorelabel')===0) {
+                $num = str_replace('scorelabel', '', $k);
+                echo "<div class=\"obj_info_text\">Score $num : {$v['_data']}</div>";
+            }
         }
-      }
-?>
+        } ?>
             </td>
 
-            <td class="button"><a href="<?php echo($edit_url); ?>"><img src="../../../images/buttons/edit.gif" width="16" height="16" alt="edit question" title="edit" /></a></td>
+            <td class="button"><a href="<?php echo $edit_url; ?>"><img src="../../../images/buttons/edit.gif" width="16" height="16" alt="edit question" title="edit" /></a></td>
 
             <td class="button" width="20">
 <?php
-      echo('<a href="question_action.php?' . $question_qs . '&a=clone"><img src="../../../images/buttons/clone.gif" width="16" height="16" alt="clone" title="clone" /></a>');
-?>
+      echo '<a href="question_action.php?' . $question_qs . '&a=clone"><img src="../../../images/buttons/clone.gif" width="16" height="16" alt="clone" title="clone" /></a>'; ?>
             </td>
 
             <td class="button" width="20">
 <?php
       if ($i>0) {
-        echo('<a href="question_action.php?' . $question_qs . '&a=up"><img src="../../../images/buttons/arrow_green_up.gif" width="16" height="16" alt="move up" title="move up" /></a>');
+          echo '<a href="question_action.php?' . $question_qs . '&a=up"><img src="../../../images/buttons/arrow_green_up.gif" width="16" height="16" alt="move up" title="move up" /></a>';
       } else {
-        echo('<img src="../../../images/buttons/blank.gif" width="16" height="16" alt="" />');
-      }
-?>
+          echo '<img src="../../../images/buttons/blank.gif" width="16" height="16" alt="" />';
+      } ?>
             </td>
 
             <td class="button" width="20">
 <?php
       if ($i<($question_count-1)) {
-        echo('<a href="question_action.php?' . $question_qs . '&a=down"><img src="../../../images/buttons/arrow_green_down.gif" width="16" height="16" alt="move down" title="move down" /></a>');
+          echo '<a href="question_action.php?' . $question_qs . '&a=down"><img src="../../../images/buttons/arrow_green_down.gif" width="16" height="16" alt="move down" title="move down" /></a>';
       } else {
-        echo('<img src="../../../images/buttons/blank.gif" width="16" height="16" alt="" />');
-      }
-?>
+          echo '<img src="../../../images/buttons/blank.gif" width="16" height="16" alt="" />';
+      } ?>
             </td>
 
-            <td class="button" width="20"><a href="question_action.php?<?php echo($question_qs); ?>&a=delete"><img src="../../../images/buttons/cross.gif" width="16" height="16" alt="delete" title="delete" /></a></td>
+            <td class="button" width="20"><a href="question_action.php?<?php echo $question_qs; ?>&a=delete"><img src="../../../images/buttons/cross.gif" width="16" height="16" alt="delete" title="delete" /></a></td>
           </tr>
           </table>
         </div>
 <?php
-    }
-?>
+    } ?>
       </div>
 <?php
-  }
-?>
+        } ?>
   </div>
 
   </form>
 <?php
-}
+    }
 ?>
 </div>
 
diff --git a/src/tutors/forms/edit/edit_question/class_wizardstep_1.php b/src/tutors/forms/edit/edit_question/class_wizardstep_1.php
index 80cad3b..e04b8bc 100644
--- a/src/tutors/forms/edit/edit_question/class_wizardstep_1.php
+++ b/src/tutors/forms/edit/edit_question/class_wizardstep_1.php
@@ -11,25 +11,28 @@
 use WebPA\includes\functions\Common;
 use WebPA\includes\functions\Form;
 
-class WizardStep1 {
+class WizardStep1
+{
+    // Public
+    public $wizard;
 
-  // Public
-  public $wizard = null;
-  public $step = 1;
+    public $step = 1;
 
-  /*
-  * CONSTRUCTOR
-  */
-  function __construct(&$wizard) {
-    $this->wizard =& $wizard;
+    // CONSTRUCTOR
+    public function __construct(&$wizard)
+    {
+        $this->wizard =& $wizard;
 
-    $this->wizard->back_button = null;
-    $this->wizard->next_button = 'Next &gt;';
-    $this->wizard->cancel_button = 'Cancel';
-  }// /WizardStep1()
+        $this->wizard->back_button = null;
+        $this->wizard->next_button = 'Next &gt;';
+        $this->wizard->cancel_button = 'Cancel';
+    }
 
-  function head() {
-?>
+    // /WizardStep1()
+
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -40,48 +43,57 @@ function body_onload() {
 //-->
 </script>
 <?php
-  }// /->head()
+    }
 
-  function form() {
-    $config = $this->wizard->get_var('config');
-    $form =& $this->wizard->get_var('form');
+    // /->head()
 
-    $question = $form->get_question($this->wizard->get_var('question_id'));
+    public function form()
+    {
+        $config = $this->wizard->get_var('config');
+        $form =& $this->wizard->get_var('form');
 
-    if ( (!$this->wizard->get_field('set_original_data')) && (is_array($question)) ) {
-      $range_bits = explode('-',$question['range']['_data']);
-      $range_start = $range_bits[0];
-      $range_end = $range_bits[1];
+        $question = $form->get_question($this->wizard->get_var('question_id'));
 
-      if (!$this->wizard->get_field('question_text')) { $this->wizard->set_field('question_text', $question['text']['_data']); }
+        if ((!$this->wizard->get_field('set_original_data')) && (is_array($question))) {
+            $range_bits = explode('-', $question['range']['_data']);
+            $range_start = $range_bits[0];
+            $range_end = $range_bits[1];
 
-      $question_desc = (array_key_exists('desc', $question)) ? $question['desc']['_data'] : '' ;
-      if (!$this->wizard->get_field('question_desc')) { $this->wizard->set_field('question_desc', $question_desc); }
+            if (!$this->wizard->get_field('question_text')) {
+                $this->wizard->set_field('question_text', $question['text']['_data']);
+            }
 
-      if (!$this->wizard->get_field('question_range_start')) { $this->wizard->set_field('question_range_start',$range_start); }
-      if (!$this->wizard->get_field('question_range_end')) { $this->wizard->set_field('question_range_end',$range_end); }
+            $question_desc = (array_key_exists('desc', $question)) ? $question['desc']['_data'] : '' ;
+            if (!$this->wizard->get_field('question_desc')) {
+                $this->wizard->set_field('question_desc', $question_desc);
+            }
 
-      for ($i=$range_start; $i<=$range_end; $i++) {
-        if (array_key_exists("scorelabel{$i}", $question)) {
-          $this->wizard->set_field("scorelabel{$i}", $question["scorelabel{$i}"]);
-        }
-      }
+            if (!$this->wizard->get_field('question_range_start')) {
+                $this->wizard->set_field('question_range_start', $range_start);
+            }
+            if (!$this->wizard->get_field('question_range_end')) {
+                $this->wizard->set_field('question_range_end', $range_end);
+            }
 
-      $this->wizard->set_field('set_original_data',true);
-    }
+            for ($i=$range_start; $i<=$range_end; $i++) {
+                if (array_key_exists("scorelabel{$i}", $question)) {
+                    $this->wizard->set_field("scorelabel{$i}", $question["scorelabel{$i}"]);
+                }
+            }
 
-?>
+            $this->wizard->set_field('set_original_data', true);
+        } ?>
     <p>Here you can edit the text and description of the criterion.</p>
 
     <div class="form_section">
       <table cellpadding="2" cellspacing="2" width="100%">
       <tr>
         <th width="100"><label for="question_text">Criterion Text</label></th>
-        <td><input type="text" name="question_text" id="question_text" maxlength="255" size="50" value="<?php echo( $this->wizard->get_field('question_text') ); ?>" style="width: 90%;" /></td>
+        <td><input type="text" name="question_text" id="question_text" maxlength="255" size="50" value="<?php echo $this->wizard->get_field('question_text'); ?>" style="width: 90%;" /></td>
       </tr>
       <tr>
         <th valign="top" width="100"><label for="question_desc">Description</label><br /><span style="font-size: 0.8em; font-weight: normal;">(optional)</span></th>
-        <td><textarea name="question_desc" id="question_desc" cols="60" rows="3" style="width: 90%;"><?php echo( $this->wizard->get_field('question_desc') ); ?></textarea></td>
+        <td><textarea name="question_desc" id="question_desc" cols="60" rows="3" style="width: 90%;"><?php echo $this->wizard->get_field('question_desc'); ?></textarea></td>
       </tr>
       </table>
     </div>
@@ -93,13 +105,13 @@ function form() {
         <th><label for="question_range_start">Scores range from</label></th>
         <td>
           <select name="question_range_start" id="question_range_start">
-            <?php Form::render_options_range(0,1,1,(int) $this->wizard->get_field('question_range_start')); ?>
+            <?php Form::render_options_range(0, 1, 1, (int) $this->wizard->get_field('question_range_start')); ?>
           </select>
         </td>
         <th><label>to</label></th>
         <td>
           <select name="question_range_end" id="question_range_end">
-            <?php Form::render_options_range(3,10,1,(int) $this->wizard->get_field('question_range_end')); ?>
+            <?php Form::render_options_range(3, 10, 1, (int) $this->wizard->get_field('question_range_end')); ?>
           </select>
         </td>
       </tr>
@@ -107,22 +119,28 @@ function form() {
     </div>
     <p><strong>Please Note</strong> - allowing 0 scores means students can receive no marks if they failed to contribute at all.</p>
 <?php
-  }// /->form()
+    }
 
-  function process_form() {
-    $errors = null;
+    // /->form()
 
-    $this->wizard->set_field('question_text',Common::fetch_POST('question_text'));
-    if (empty($this->wizard->get_field('question_text'))) { $errors[] = 'You must provide some text for your new criterion'; }
+    public function process_form()
+    {
+        $errors = null;
 
-    $this->wizard->set_field('question_desc',Common::fetch_POST('question_desc'));
+        $this->wizard->set_field('question_text', Common::fetch_POST('question_text'));
+        if (empty($this->wizard->get_field('question_text'))) {
+            $errors[] = 'You must provide some text for your new criterion';
+        }
 
-    $this->wizard->set_field('question_range_start',Common::fetch_POST('question_range_start'));
-    $this->wizard->set_field('question_range_end',Common::fetch_POST('question_range_end'));
+        $this->wizard->set_field('question_desc', Common::fetch_POST('question_desc'));
 
-    return $errors;
-  }// /->process_form()
+        $this->wizard->set_field('question_range_start', Common::fetch_POST('question_range_start'));
+        $this->wizard->set_field('question_range_end', Common::fetch_POST('question_range_end'));
+
+        return $errors;
+    }
 
+    // /->process_form()
 }// /class: WizardStep1
 
 ?>
diff --git a/src/tutors/forms/edit/edit_question/class_wizardstep_2.php b/src/tutors/forms/edit/edit_question/class_wizardstep_2.php
index da2b7d1..a1303bb 100644
--- a/src/tutors/forms/edit/edit_question/class_wizardstep_2.php
+++ b/src/tutors/forms/edit/edit_question/class_wizardstep_2.php
@@ -10,25 +10,28 @@
 
 use WebPA\includes\functions\Common;
 
-class WizardStep2 {
+class WizardStep2
+{
+    // Public
+    public $wizard;
 
-  // Public
-  public $wizard = null;
-  public $step = 2;
+    public $step = 2;
 
-  /*
-  * CONSTRUCTOR
-  */
-  function __construct(&$wizard) {
-    $this->wizard =& $wizard;
+    // CONSTRUCTOR
+    public function __construct(&$wizard)
+    {
+        $this->wizard =& $wizard;
 
-    $this->wizard->back_button = '&lt; Back';
-    $this->wizard->next_button = 'Finish';
-    $this->wizard->cancel_button = 'Cancel';
-  }// /WizardStep2()
+        $this->wizard->back_button = '&lt; Back';
+        $this->wizard->next_button = 'Finish';
+        $this->wizard->cancel_button = 'Cancel';
+    }
 
-  function head() {
-?>
+    // /WizardStep2()
+
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -38,68 +41,74 @@ function body_onload() {
 //-->
 </script>
 <?php
-  }// /->head()
+    }
 
-  function form() {
-    $form =& $this->wizard->get_var('form');
+    // /->head()
 
-    $range_start = $this->wizard->get_field('question_range_start');
-    $range_end = $this->wizard->get_field('question_range_end');
+    public function form()
+    {
+        $form =& $this->wizard->get_var('form');
 
-    $question = $form->get_question($this->wizard->get_var('question_id'));
+        $range_start = $this->wizard->get_field('question_range_start');
+        $range_end = $this->wizard->get_field('question_range_end');
 
-    if ( (is_array($question)) ) {
-      for ($i=$range_start; $i<=$range_end; $i++) {
-        if ( (array_key_exists("scorelabel{$i}", $question)) && (!$this->wizard->get_field("scorelabel{$i}")) ) {
-          $this->wizard->set_field("scorelabel{$i}", $question["scorelabel{$i}"]['_data']);
-        }
-      }
-    }
+        $question = $form->get_question($this->wizard->get_var('question_id'));
 
-?>
-    <p>Your new assessment criterion allows scores from <?php echo("$range_start to $range_end"); ?>. You can use the boxes below to provide a description what those scores should mean.</p>
+        if ((is_array($question))) {
+            for ($i=$range_start; $i<=$range_end; $i++) {
+                if ((array_key_exists("scorelabel{$i}", $question)) && (!$this->wizard->get_field("scorelabel{$i}"))) {
+                    $this->wizard->set_field("scorelabel{$i}", $question["scorelabel{$i}"]['_data']);
+                }
+            }
+        } ?>
+    <p>Your new assessment criterion allows scores from <?php echo "$range_start to $range_end"; ?>. You can use the boxes below to provide a description what those scores should mean.</p>
     <p>It's good practice to describe the meaning of at least the top and bottom scores, but you are free to provide as many, or as few, descriptions as you like. Leave a description blank and it will not be displayed on the form.</p>
 
     <p><strong>Score descriptions</strong></p>
     <div class="form_section">
-      <p><?php echo($this->wizard->get_field('question_text')); ?></p>
+      <p><?php echo $this->wizard->get_field('question_text'); ?></p>
       <table class="form" cellpadding="2" cellspacing="2">
       <?php
-        for($i=$range_start; $i<=$range_end; $i++) {
-          echo('<tr>');
-          echo("<th><label for=\"scorelabel{$i}\">Score $i</label></th>");
-          echo("<td><input type=\"text\" name=\"scorelabel{$i}\" id=\"scorelabel{$i}\" maxlength=\"255\" size=\"50\" value=\"". $this->wizard->get_field("scorelabel{$i}") ."\" /></td>");
-          if ($i==$range_start) {
-            echo('<td style="font-size: 0.9em; font-style: italic;">Lowest</td>');
-          } else {
-            if ($i==$range_end) {
-              echo('<td style="font-size: 0.9em; font-style: italic;">Highest</td>');
+        for ($i=$range_start; $i<=$range_end; $i++) {
+            echo '<tr>';
+            echo "<th><label for=\"scorelabel{$i}\">Score $i</label></th>";
+            echo "<td><input type=\"text\" name=\"scorelabel{$i}\" id=\"scorelabel{$i}\" maxlength=\"255\" size=\"50\" value=\"". $this->wizard->get_field("scorelabel{$i}") .'" /></td>';
+            if ($i==$range_start) {
+                echo '<td style="font-size: 0.9em; font-style: italic;">Lowest</td>';
             } else {
-              echo('<td>&nbsp;</td>');
+                if ($i==$range_end) {
+                    echo '<td style="font-size: 0.9em; font-style: italic;">Highest</td>';
+                } else {
+                    echo '<td>&nbsp;</td>';
+                }
             }
-          }
-          echo('</tr>');
-        }
-?>
+            echo '</tr>';
+        } ?>
       </table>
     </div>
 <?php
-  }// /->form()
+    }
 
-  function process_form() {
-    $errors = null;
+    // /->form()
 
-    $range_start = $this->wizard->get_field('question_range_start');
-    $range_end = $this->wizard->get_field('question_range_end');
+    public function process_form()
+    {
+        $errors = null;
 
-    for($i=$range_start; $i<=$range_end; $i++) {
-      $scorelabel = trim( Common::fetch_POST("scorelabel{$i}") );
-      if (!empty($scorelabel)) { $this->wizard->set_field("scorelabel{$i}",$scorelabel); }
-    }
+        $range_start = $this->wizard->get_field('question_range_start');
+        $range_end = $this->wizard->get_field('question_range_end');
 
-    return $errors;
-  }// /->process_form()
+        for ($i=$range_start; $i<=$range_end; $i++) {
+            $scorelabel = trim(Common::fetch_POST("scorelabel{$i}"));
+            if (!empty($scorelabel)) {
+                $this->wizard->set_field("scorelabel{$i}", $scorelabel);
+            }
+        }
+
+        return $errors;
+    }
 
+    // /->process_form()
 }// /class: WizardStep2
 
 ?>
diff --git a/src/tutors/forms/edit/edit_question/class_wizardstep_3.php b/src/tutors/forms/edit/edit_question/class_wizardstep_3.php
index 77cb573..43484da 100644
--- a/src/tutors/forms/edit/edit_question/class_wizardstep_3.php
+++ b/src/tutors/forms/edit/edit_question/class_wizardstep_3.php
@@ -10,25 +10,28 @@
 
 use WebPA\includes\functions\Common;
 
-class WizardStep3 {
+class WizardStep3
+{
+    // Public
+    public $wizard;
 
-  // Public
-  public $wizard = null;
-  public $step = 3;
+    public $step = 3;
 
-  /*
-  * CONSTRUCTOR
-  */
-  function __construct(&$wizard) {
-    $this->wizard =& $wizard;
+    // CONSTRUCTOR
+    public function __construct(&$wizard)
+    {
+        $this->wizard =& $wizard;
 
-    $this->wizard->back_button = null;
-    $this->wizard->next_button = null;
-    $this->wizard->cancel_button = null;
-  }// /WizardStep3()
+        $this->wizard->back_button = null;
+        $this->wizard->next_button = null;
+        $this->wizard->cancel_button = null;
+    }
 
-  function head() {
-?>
+    // /WizardStep3()
+
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -38,57 +41,66 @@ function body_onload() {
 //-->
 </script>
 <?php
-  }// /->head()
+    }
 
-  function form() {
-    $form =& $this->wizard->get_var('form');
+    // /->head()
 
-    $range_start = $this->wizard->get_field('question_range_start');
-    $range_end = $this->wizard->get_field('question_range_end');
+    public function form()
+    {
+        $form =& $this->wizard->get_var('form');
 
-    $new_question['text']['_data'] = $this->wizard->get_field('question_text');
-    $new_question['desc']['_data'] = $this->wizard->get_field('question_desc');
-    $new_question['range']['_data'] = "{$range_start}-{$range_end}";
+        $range_start = $this->wizard->get_field('question_range_start');
+        $range_end = $this->wizard->get_field('question_range_end');
 
-    for($i=$range_start; $i<=$range_end; $i++) {
-      $scorelabel = trim( Common::fetch_POST("scorelabel{$i}") );
-      if (!empty($scorelabel)) { $new_question["scorelabel{$i}"]['_data'] = $scorelabel; }
-    }
+        $new_question['text']['_data'] = $this->wizard->get_field('question_text');
+        $new_question['desc']['_data'] = $this->wizard->get_field('question_desc');
+        $new_question['range']['_data'] = "{$range_start}-{$range_end}";
 
-    $errors = null;
-    if (!$form) {
-      $errors[] = 'Unable to load the form that this question belongs to.';
-    } else {
-      $form->set_question($this->wizard->get_var('question_id'), $new_question);
-      $form->save();
-    }
+        for ($i=$range_start; $i<=$range_end; $i++) {
+            $scorelabel = trim(Common::fetch_POST("scorelabel{$i}"));
+            if (!empty($scorelabel)) {
+                $new_question["scorelabel{$i}"]['_data'] = $scorelabel;
+            }
+        }
+
+        $errors = null;
+        if (!$form) {
+            $errors[] = 'Unable to load the form that this question belongs to.';
+        } else {
+            $form->set_question($this->wizard->get_var('question_id'), $new_question);
+            $form->save();
+        }
 
-    // If errors, show them
-    if (is_array($errors)) {
-      $this->wizard->back_button = '&lt; Back';
-      $this->wizard->cancel_button = 'Cancel';
-      echo('<p><strong>Unable to create your new assessment criterion.</strong></p>');
-      echo('<p>To correct the problem, click <em>back</em> and amend the details entered.</p>');
-    } else {// Else.. create the form!
+        // If errors, show them
+        if (is_array($errors)) {
+            $this->wizard->back_button = '&lt; Back';
+            $this->wizard->cancel_button = 'Cancel';
+            echo '<p><strong>Unable to create your new assessment criterion.</strong></p>';
+            echo '<p>To correct the problem, click <em>back</em> and amend the details entered.</p>';
+        } else {// Else.. create the form!
 ?>
       <p><strong>Your changes to this criterion have been saved.</strong></p>
-      <p style="margin-top: 20px;">You can now return to <a href="/tutors/forms/edit/edit_form.php?f=<?php echo($form->id); ?>">editing your form</a>.</p>
+      <p style="margin-top: 20px;">You can now return to <a href="/tutors/forms/edit/edit_form.php?f=<?php echo $form->id; ?>">editing your form</a>.</p>
       <script language="JavaScript" type="text/javascript">
       <!--
         function body_onload() {
-          window.location.href='../<?php echo("edit_form.php?f={$form->id}"); ?>';
+          window.location.href='../<?php echo "edit_form.php?f={$form->id}"; ?>';
         }
       //-->
       </script>
 <?php
     }
-  }// /->form()
+    }
+
+    // /->form()
 
-  function process_form() {
-    $this->wizard->_fields = array(); // kill the wizard's stored fields
-    return null;
-  }// /->process_form()
+    public function process_form()
+    {
+        $this->wizard->_fields = []; // kill the wizard's stored fields
+        return null;
+    }
 
+    // /->process_form()
 }// /class: WizardStep3
 
 ?>
diff --git a/src/tutors/forms/edit/edit_question/index.php b/src/tutors/forms/edit/edit_question/index.php
index ecdaa9c..2ba7d3a 100644
--- a/src/tutors/forms/edit/edit_question/index.php
+++ b/src/tutors/forms/edit/edit_question/index.php
@@ -8,15 +8,15 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../../includes/inc_global.php");
+require_once '../../../../includes/inc_global.php';
 
 use WebPA\includes\classes\Form;
 use WebPA\includes\classes\Wizard;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -27,9 +27,9 @@
 
 $form = new Form($DB);
 if ($form->load($form_id)) {
-  $form_qs = "f={$form->id}";
+    $form_qs = "f={$form->id}";
 } else {
-  $form = null;
+    $form = null;
 }
 
 // --------------------------------------------------------------------------------
@@ -38,38 +38,38 @@
 $wizard = new Wizard('edit criterion wizard');
 
 if ($form) {
-  $wizard->set_wizard_url("index.php?f=$form_id&q=$question_id");
+    $wizard->set_wizard_url("index.php?f=$form_id&q=$question_id");
 
-  $wizard->cancel_url = "../edit_form.php?f=$form_id";
+    $wizard->cancel_url = "../edit_form.php?f=$form_id";
 
-  $valid_types = array ('likert', 'split100');
+    $valid_types = ['likert', 'split100'];
 
-  if ($form->type=='split100') {
-    $wizard_path = DOC__ROOT . '/tutors/forms/edit/edit_question/' . $form->type .'/';
+    if ($form->type=='split100') {
+        $wizard_path = DOC__ROOT . '/tutors/forms/edit/edit_question/' . $form->type .'/';
 
-    $wizard->add_step(1, $wizard_path.'class_wizardstep_1.php');
-    $wizard->add_step(2, $wizard_path.'class_wizardstep_2.php');
+        $wizard->add_step(1, $wizard_path.'class_wizardstep_1.php');
+        $wizard->add_step(2, $wizard_path.'class_wizardstep_2.php');
 
-    $wizard->show_steps(1); // Hide the last step from the user
-  } else {
-    $wizard_path = DOC__ROOT . '/tutors/forms/edit/edit_question/' . $form->type .'/';
+        $wizard->show_steps(1); // Hide the last step from the user
+    } else {
+        $wizard_path = DOC__ROOT . '/tutors/forms/edit/edit_question/' . $form->type .'/';
 
-    $wizard->add_step(1, $wizard_path.'class_wizardstep_1.php');
-    $wizard->add_step(2, $wizard_path.'class_wizardstep_2.php');
-    $wizard->add_step(3, $wizard_path.'class_wizardstep_3.php');
+        $wizard->add_step(1, $wizard_path.'class_wizardstep_1.php');
+        $wizard->add_step(2, $wizard_path.'class_wizardstep_2.php');
+        $wizard->add_step(3, $wizard_path.'class_wizardstep_3.php');
 
-    $wizard->show_steps(2); // Hide the last step from the user
-  }
+        $wizard->show_steps(2); // Hide the last step from the user
+    }
 
-  $wizard->set_var('db',$DB);
-  $wizard->set_var('config',$_config);
-  $wizard->set_var('user',$_user);
-  $wizard->set_var('form',$form);
-  $wizard->set_var('question_id', $question_id);
+    $wizard->set_var('db', $DB);
+    $wizard->set_var('config', $_config);
+    $wizard->set_var('user', $_user);
+    $wizard->set_var('form', $form);
+    $wizard->set_var('question_id', $question_id);
 
-  $wizard->prepare();
+    $wizard->prepare();
 
-  $wiz_step = $wizard->get_step();
+    $wiz_step = $wizard->get_step();
 }
 
 // --------------------------------------------------------------------------------
@@ -78,12 +78,12 @@
 $UI->page_title = APP__NAME.' Edit a criterion';
 $UI->menu_selected = 'my forms';
 $UI->help_link = '?q=node/244';
-$UI->breadcrumbs = array  (
-  'home'          => '../../../' ,
-  'my forms'        => '../../' ,
-  "edit: {$form->name}" => "../edit_form.php?$form_qs" ,
-  "edit: criterion"   => null ,
-);
+$UI->breadcrumbs = [
+  'home'          => '../../../',
+  'my forms'        => '../../',
+  "edit: {$form->name}" => "../edit_form.php?$form_qs",
+  'edit: criterion'   => null,
+];
 
 $UI->set_page_bar_button('List Forms', '../../../../../images/buttons/button_form_list.gif', '../../');
 $UI->set_page_bar_button('Create Form', '../../../../../images/buttons/button_form_create.gif', '../../create/index.php');
@@ -113,9 +113,9 @@
 
 <?php
 if ($form) {
-  $wizard->draw_wizard();
+    $wizard->draw_wizard();
 } else {
-  echo("<p>The given assessment form failed to load so this wizard cannot be started.</p>");
+    echo '<p>The given assessment form failed to load so this wizard cannot be started.</p>';
 }
 ?>
 
diff --git a/src/tutors/forms/edit/edit_question/likert/class_wizardstep_1.php b/src/tutors/forms/edit/edit_question/likert/class_wizardstep_1.php
index 2b2eb89..77d7aa3 100644
--- a/src/tutors/forms/edit/edit_question/likert/class_wizardstep_1.php
+++ b/src/tutors/forms/edit/edit_question/likert/class_wizardstep_1.php
@@ -11,27 +11,28 @@
 use WebPA\includes\functions\Common;
 use WebPA\includes\functions\Form;
 
-class WizardStep1 {
+class WizardStep1
+{
+    // Public
+    public $wizard;
 
-	// Public
-	public $wizard = null;
-	public $step = 1;
+    public $step = 1;
 
+    // CONSTRUCTOR
+    public function __construct(&$wizard)
+    {
+        $this->wizard =& $wizard;
 
-	/*
-	* CONSTRUCTOR
-	*/
-	function __construct(&$wizard) {
-		$this->wizard =& $wizard;
+        $this->wizard->back_button = null;
+        $this->wizard->next_button = 'Next &gt;';
+        $this->wizard->cancel_button = 'Cancel';
+    }
 
-		$this->wizard->back_button = null;
-		$this->wizard->next_button = 'Next &gt;';
-		$this->wizard->cancel_button = 'Cancel';
-	}// /WizardStep1()
+    // /WizardStep1()
 
-
-	function head() {
-		?>
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -42,48 +43,56 @@ function body_onload() {
 //-->
 </script>
 <?php
-	}// /->head()
-
+    }
 
-	function form() {
-		$form = $this->wizard->get_var('form');
+    // /->head()
 
-		$question = $form->get_question($this->wizard->get_var('question_id'));
+    public function form()
+    {
+        $form = $this->wizard->get_var('form');
 
-		if ( (!$this->wizard->get_field('set_original_data')) && (is_array($question)) ) {
-			$range_bits = explode('-',$question['range']['_data']);
-			$range_start = $range_bits[0];
-			$range_end = $range_bits[1];
+        $question = $form->get_question($this->wizard->get_var('question_id'));
 
-			if (!$this->wizard->get_field('question_text')) { $this->wizard->set_field('question_text', $question['text']['_data']); }
+        if ((!$this->wizard->get_field('set_original_data')) && (is_array($question))) {
+            $range_bits = explode('-', $question['range']['_data']);
+            $range_start = $range_bits[0];
+            $range_end = $range_bits[1];
 
-			$question_desc = (array_key_exists('desc', $question)) ? $question['desc']['_data'] : '' ;
-			if (!$this->wizard->get_field('question_desc')) { $this->wizard->set_field('question_desc', $question_desc); }
+            if (!$this->wizard->get_field('question_text')) {
+                $this->wizard->set_field('question_text', $question['text']['_data']);
+            }
 
-			if (!$this->wizard->get_field('question_range_start')) { $this->wizard->set_field('question_range_start',$range_start); }
-			if (!$this->wizard->get_field('question_range_end')) { $this->wizard->set_field('question_range_end',$range_end); }
+            $question_desc = (array_key_exists('desc', $question)) ? $question['desc']['_data'] : '' ;
+            if (!$this->wizard->get_field('question_desc')) {
+                $this->wizard->set_field('question_desc', $question_desc);
+            }
 
-			for ($i=$range_start; $i<=$range_end; $i++) {
-				if (array_key_exists("scorelabel{$i}", $question)) {
-					$this->wizard->set_field("scorelabel{$i}", $question["scorelabel{$i}"]);
-				}
-			}
+            if (!$this->wizard->get_field('question_range_start')) {
+                $this->wizard->set_field('question_range_start', $range_start);
+            }
+            if (!$this->wizard->get_field('question_range_end')) {
+                $this->wizard->set_field('question_range_end', $range_end);
+            }
 
-			$this->wizard->set_field('set_original_data',true);
-		}
+            for ($i=$range_start; $i<=$range_end; $i++) {
+                if (array_key_exists("scorelabel{$i}", $question)) {
+                    $this->wizard->set_field("scorelabel{$i}", $question["scorelabel{$i}"]);
+                }
+            }
 
-		?>
+            $this->wizard->set_field('set_original_data', true);
+        } ?>
 		<p>Here you can edit the text and description of the criterion.</p>
 
 		<div class="form_section">
 			<table cellpadding="2" cellspacing="2" width="100%">
 			<tr>
 				<th width="100"><label for="question_text">Criterion Text</label></th>
-				<td><input type="text" name="question_text" id="question_text" maxlength="255" size="50" value="<?php echo( $this->wizard->get_field('question_text') ); ?>" style="width: 90%;" /></td>
+				<td><input type="text" name="question_text" id="question_text" maxlength="255" size="50" value="<?php echo $this->wizard->get_field('question_text'); ?>" style="width: 90%;" /></td>
 			</tr>
 			<tr>
 				<th valign="top" width="100"><label for="question_desc">Description</label><br /><span style="font-size: 0.8em; font-weight: normal;">(optional)</span></th>
-				<td><textarea name="question_desc" id="question_desc" cols="60" rows="3" style="width: 90%;"><?php echo( $this->wizard->get_field('question_desc') ); ?></textarea></td>
+				<td><textarea name="question_desc" id="question_desc" cols="60" rows="3" style="width: 90%;"><?php echo $this->wizard->get_field('question_desc'); ?></textarea></td>
 			</tr>
 			</table>
 		</div>
@@ -95,13 +104,13 @@ function form() {
 				<th><label for="question_range_start">Scores range from</label></th>
 				<td>
 					<select name="question_range_start" id="question_range_start">
-						<?php Form::render_options_range(0,1,1,(int) $this->wizard->get_field('question_range_start')); ?>
+						<?php Form::render_options_range(0, 1, 1, (int) $this->wizard->get_field('question_range_start')); ?>
 					</select>
 				</td>
 				<th><label>to</label></th>
 				<td>
 					<select name="question_range_end" id="question_range_end">
-						<?php Form::render_options_range(3,10,1,(int) $this->wizard->get_field('question_range_end')); ?>
+						<?php Form::render_options_range(3, 10, 1, (int) $this->wizard->get_field('question_range_end')); ?>
 					</select>
 				</td>
 			</tr>
@@ -109,23 +118,28 @@ function form() {
 		</div>
 		<p><strong>Please Note</strong> - allowing 0 scores means students can receive no marks if they failed to contribute at all.</p>
 		<?php
-	}// /->form()
+    }
 
+    // /->form()
 
-	function process_form() {
-		$errors = null;
+    public function process_form()
+    {
+        $errors = null;
 
-		$this->wizard->set_field('question_text',Common::fetch_POST('question_text'));
-		if (empty($this->wizard->get_field('question_text'))) { $errors[] = 'You must provide some text for your new criterion'; }
+        $this->wizard->set_field('question_text', Common::fetch_POST('question_text'));
+        if (empty($this->wizard->get_field('question_text'))) {
+            $errors[] = 'You must provide some text for your new criterion';
+        }
 
-		$this->wizard->set_field('question_desc',Common::fetch_POST('question_desc'));
+        $this->wizard->set_field('question_desc', Common::fetch_POST('question_desc'));
 
-		$this->wizard->set_field('question_range_start',Common::fetch_POST('question_range_start'));
-		$this->wizard->set_field('question_range_end',Common::fetch_POST('question_range_end'));
+        $this->wizard->set_field('question_range_start', Common::fetch_POST('question_range_start'));
+        $this->wizard->set_field('question_range_end', Common::fetch_POST('question_range_end'));
 
-		return $errors;
-	}// /->process_form()
+        return $errors;
+    }
 
+    // /->process_form()
 }// /class: WizardStep1
 
 
diff --git a/src/tutors/forms/edit/edit_question/likert/class_wizardstep_2.php b/src/tutors/forms/edit/edit_question/likert/class_wizardstep_2.php
index 2029f4b..b77acb7 100644
--- a/src/tutors/forms/edit/edit_question/likert/class_wizardstep_2.php
+++ b/src/tutors/forms/edit/edit_question/likert/class_wizardstep_2.php
@@ -10,27 +10,28 @@
 
 use WebPA\includes\functions\Common;
 
-class WizardStep2 {
+class WizardStep2
+{
+    // Public
+    public $wizard;
 
-	// Public
-	public $wizard = null;
-	public $step = 2;
+    public $step = 2;
 
+    // CONSTRUCTOR
+    public function __construct(&$wizard)
+    {
+        $this->wizard =& $wizard;
 
-	/*
-	* CONSTRUCTOR
-	*/
-	function __construct(&$wizard) {
-		$this->wizard =& $wizard;
+        $this->wizard->back_button = '&lt; Back';
+        $this->wizard->next_button = 'Finish';
+        $this->wizard->cancel_button = 'Cancel';
+    }
 
-		$this->wizard->back_button = '&lt; Back';
-		$this->wizard->next_button = 'Finish';
-		$this->wizard->cancel_button = 'Cancel';
-	}// /WizardStep2()
+    // /WizardStep2()
 
-
-	function head() {
-		?>
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -40,73 +41,75 @@ function body_onload() {
 //-->
 </script>
 <?php
-	}// /->head()
-
+    }
 
-	function form() {
-		$form = $this->wizard->get_var('form');
+    // /->head()
 
-		$range_start = $this->wizard->get_field('question_range_start');
-		$range_end = $this->wizard->get_field('question_range_end');
+    public function form()
+    {
+        $form = $this->wizard->get_var('form');
 
-		$question = $form->get_question($this->wizard->get_var('question_id'));
+        $range_start = $this->wizard->get_field('question_range_start');
+        $range_end = $this->wizard->get_field('question_range_end');
 
-		if ( (is_array($question)) ) {
-			for ($i=$range_start; $i<=$range_end; $i++) {
-				if ( (array_key_exists("scorelabel{$i}", $question)) && (!$this->wizard->get_field("scorelabel{$i}")) ) {
-					$this->wizard->set_field("scorelabel{$i}", $question["scorelabel{$i}"]['_data']);
-				}
-			}
-		}
+        $question = $form->get_question($this->wizard->get_var('question_id'));
 
-		?>
-		<p>Your new assessment criterion allows scores from <?php echo("$range_start to $range_end"); ?>. You can use the boxes below to provide a description what those scores should mean.</p>
+        if ((is_array($question))) {
+            for ($i=$range_start; $i<=$range_end; $i++) {
+                if ((array_key_exists("scorelabel{$i}", $question)) && (!$this->wizard->get_field("scorelabel{$i}"))) {
+                    $this->wizard->set_field("scorelabel{$i}", $question["scorelabel{$i}"]['_data']);
+                }
+            }
+        } ?>
+		<p>Your new assessment criterion allows scores from <?php echo "$range_start to $range_end"; ?>. You can use the boxes below to provide a description what those scores should mean.</p>
 		<p>It's good practice to describe the meaning of at least the top and bottom scores, but you are free to provide as many, or as few, descriptions as you like. Leave a description blank and it will not be displayed on the form.</p>
 
 		<p><strong>Score descriptions</strong></p>
 		<div class="form_section">
-			<p><?php echo($this->wizard->get_field('question_text')); ?></p>
+			<p><?php echo $this->wizard->get_field('question_text'); ?></p>
 			<table class="form" cellpadding="2" cellspacing="2">
 			<?php
-				for($i=$range_start; $i<=$range_end; $i++) {
-					echo('<tr>');
-					echo("<th><label for=\"scorelabel{$i}\">Score $i</label></th>");
-					echo("<td><input type=\"text\" name=\"scorelabel{$i}\" id=\"scorelabel{$i}\" maxlength=\"255\" size=\"50\" value=\"". $this->wizard->get_field("scorelabel{$i}") ."\" /></td>");
-					if ($i==$range_start) {
-						echo('<td style="font-size: 0.9em; font-style: italic;">Lowest</td>');
-					} else {
-						if ($i==$range_end) {
-							echo('<td style="font-size: 0.9em; font-style: italic;">Highest</td>');
-						} else {
-							echo('<td>&nbsp;</td>');
-						}
-					}
-					echo('</tr>');
-				}
-			?>
+                for ($i=$range_start; $i<=$range_end; $i++) {
+                    echo '<tr>';
+                    echo "<th><label for=\"scorelabel{$i}\">Score $i</label></th>";
+                    echo "<td><input type=\"text\" name=\"scorelabel{$i}\" id=\"scorelabel{$i}\" maxlength=\"255\" size=\"50\" value=\"". $this->wizard->get_field("scorelabel{$i}") .'" /></td>';
+                    if ($i==$range_start) {
+                        echo '<td style="font-size: 0.9em; font-style: italic;">Lowest</td>';
+                    } else {
+                        if ($i==$range_end) {
+                            echo '<td style="font-size: 0.9em; font-style: italic;">Highest</td>';
+                        } else {
+                            echo '<td>&nbsp;</td>';
+                        }
+                    }
+                    echo '</tr>';
+                } ?>
 			</table>
 		</div>
 		<?php
-	}// /->form()
+    }
 
+    // /->form()
 
-	function process_form() {
-		$errors = null;
+    public function process_form()
+    {
+        $errors = null;
 
-		$range_start = $this->wizard->get_field('question_range_start');
-		$range_end = $this->wizard->get_field('question_range_end');
+        $range_start = $this->wizard->get_field('question_range_start');
+        $range_end = $this->wizard->get_field('question_range_end');
 
-		for ($i=$range_start; $i<=$range_end; $i++) {
-			$scorelabel = trim( Common::fetch_POST("scorelabel{$i}") );
+        for ($i=$range_start; $i<=$range_end; $i++) {
+            $scorelabel = trim(Common::fetch_POST("scorelabel{$i}"));
 
-			if (!empty($scorelabel)) {
-			    $this->wizard->set_field("scorelabel{$i}",$scorelabel);
-			}
-		}
+            if (!empty($scorelabel)) {
+                $this->wizard->set_field("scorelabel{$i}", $scorelabel);
+            }
+        }
 
-		return $errors;
-	}// /->process_form()
+        return $errors;
+    }
 
+    // /->process_form()
 }// /class: WizardStep2
 
 
diff --git a/src/tutors/forms/edit/edit_question/likert/class_wizardstep_3.php b/src/tutors/forms/edit/edit_question/likert/class_wizardstep_3.php
index 8eaadc9..a89e995 100644
--- a/src/tutors/forms/edit/edit_question/likert/class_wizardstep_3.php
+++ b/src/tutors/forms/edit/edit_question/likert/class_wizardstep_3.php
@@ -10,27 +10,28 @@
 
 use WebPA\includes\functions\Common;
 
-class WizardStep3 {
+class WizardStep3
+{
+    // Public
+    public $wizard;
 
-	// Public
-	public $wizard = null;
-	public $step = 3;
+    public $step = 3;
 
+    // CONSTRUCTOR
+    public function __construct(&$wizard)
+    {
+        $this->wizard =& $wizard;
 
-	/*
-	* CONSTRUCTOR
-	*/
-	function __construct(&$wizard) {
-		$this->wizard =& $wizard;
+        $this->wizard->back_button = null;
+        $this->wizard->next_button = null;
+        $this->wizard->cancel_button = null;
+    }
 
-		$this->wizard->back_button = null;
-		$this->wizard->next_button = null;
-		$this->wizard->cancel_button = null;
-	}// /WizardStep3()
+    // /WizardStep3()
 
-
-	function head() {
-?>
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -40,62 +41,68 @@ function body_onload() {
 //-->
 </script>
 <?php
-	}// /->head()
-
-
-	function form() {
-		$form = $this->wizard->get_var('form');
-
-		$range_start = $this->wizard->get_field('question_range_start');
-		$range_end = $this->wizard->get_field('question_range_end');
-
-		$new_question['text']['_data'] = $this->wizard->get_field('question_text');
-		$new_question['desc']['_data'] = $this->wizard->get_field('question_desc');
-		$new_question['range']['_data'] = "{$range_start}-{$range_end}";
-
-		for ($i=$range_start; $i<=$range_end; $i++) {
-			$scorelabel = trim( Common::fetch_POST("scorelabel{$i}") );
-
-			if (!empty($scorelabel)) { $new_question["scorelabel{$i}"]['_data'] = $scorelabel; }
-		}
-
-		$errors = null;
-
-		if (!$form) {
-			$errors[] = 'Unable to load the form that this question belongs to.';
-		} else {
-			$form->set_question($this->wizard->get_var('question_id'), $new_question);
-			$form->save();
-		}
-
-		// If errors, show them
-		if (is_array($errors)) {
-			$this->wizard->back_button = '&lt; Back';
-			$this->wizard->cancel_button = 'Cancel';
-			echo('<p><strong>Unable to create your new assessment criterion.</strong></p>');
-			echo('<p>To correct the problem, click <em>back</em> and amend the details entered.</p>');
-		} else {// Else.. create the form!
-			?>
+    }
+
+    // /->head()
+
+    public function form()
+    {
+        $form = $this->wizard->get_var('form');
+
+        $range_start = $this->wizard->get_field('question_range_start');
+        $range_end = $this->wizard->get_field('question_range_end');
+
+        $new_question['text']['_data'] = $this->wizard->get_field('question_text');
+        $new_question['desc']['_data'] = $this->wizard->get_field('question_desc');
+        $new_question['range']['_data'] = "{$range_start}-{$range_end}";
+
+        for ($i=$range_start; $i<=$range_end; $i++) {
+            $scorelabel = trim(Common::fetch_POST("scorelabel{$i}"));
+
+            if (!empty($scorelabel)) {
+                $new_question["scorelabel{$i}"]['_data'] = $scorelabel;
+            }
+        }
+
+        $errors = null;
+
+        if (!$form) {
+            $errors[] = 'Unable to load the form that this question belongs to.';
+        } else {
+            $form->set_question($this->wizard->get_var('question_id'), $new_question);
+            $form->save();
+        }
+
+        // If errors, show them
+        if (is_array($errors)) {
+            $this->wizard->back_button = '&lt; Back';
+            $this->wizard->cancel_button = 'Cancel';
+            echo '<p><strong>Unable to create your new assessment criterion.</strong></p>';
+            echo '<p>To correct the problem, click <em>back</em> and amend the details entered.</p>';
+        } else {// Else.. create the form!
+            ?>
 			<p><strong>Your changes to this criterion have been saved.</strong></p>
-			<p style="margin-top: 20px;">You can now return to <a href="/tutors/forms/edit/edit_form.php?f=<?php echo($form->id); ?>">editing your form</a>.</p>
+			<p style="margin-top: 20px;">You can now return to <a href="/tutors/forms/edit/edit_form.php?f=<?php echo $form->id; ?>">editing your form</a>.</p>
 			<script language="JavaScript" type="text/javascript">
 			<!--
 				function body_onload() {
-					window.location.href='../<?php echo("edit_form.php?f={$form->id}"); ?>';
+					window.location.href='../<?php echo "edit_form.php?f={$form->id}"; ?>';
 				}
 			//-->
 			</script>
 			<?php
-		}
-	}// /->form()
-
+        }
+    }
 
-	function process_form() {
-		$this->wizard->_fields = array();	// kill the wizard's stored fields
-		return null;
-	}// /->process_form()
+    // /->form()
 
+    public function process_form()
+    {
+        $this->wizard->_fields = [];	// kill the wizard's stored fields
+        return null;
+    }
 
+    // /->process_form()
 }// /class: WizardStep3
 
 
diff --git a/src/tutors/forms/edit/edit_question/split100/class_wizardstep_1.php b/src/tutors/forms/edit/edit_question/split100/class_wizardstep_1.php
index 242f06a..d5e118a 100644
--- a/src/tutors/forms/edit/edit_question/split100/class_wizardstep_1.php
+++ b/src/tutors/forms/edit/edit_question/split100/class_wizardstep_1.php
@@ -10,27 +10,28 @@
 
 use WebPA\includes\functions\Common;
 
-class WizardStep1 {
+class WizardStep1
+{
+    // Public
+    public $wizard;
 
-	// Public
-	public $wizard = null;
-	public $step = 1;
+    public $step = 1;
 
+    // CONSTRUCTOR
+    public function __construct(&$wizard)
+    {
+        $this->wizard =& $wizard;
 
-	/*
-	* CONSTRUCTOR
-	*/
-	function __construct(&$wizard) {
-		$this->wizard =& $wizard;
+        $this->wizard->back_button = null;
+        $this->wizard->next_button = 'Finish';
+        $this->wizard->cancel_button = 'Cancel';
+    }
 
-		$this->wizard->back_button = null;
-		$this->wizard->next_button = 'Finish';
-		$this->wizard->cancel_button = 'Cancel';
-	}// /WizardStep1()
+    // /WizardStep1()
 
-
-	function head() {
-		?>
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -41,59 +42,64 @@ function body_onload() {
 //-->
 </script>
 <?php
-	}// /->head()
-
+    }
 
-	function form() {
-		$config = $this->wizard->get_var('config');
-		$form = $this->wizard->get_var('form');
+    // /->head()
 
-		$question = $form->get_question($this->wizard->get_var('question_id'));
+    public function form()
+    {
+        $config = $this->wizard->get_var('config');
+        $form = $this->wizard->get_var('form');
 
-		if (!$this->wizard->get_field('set_original_data') && is_array($question)) {
-			if (!$this->wizard->get_field('question_text')) {
-			    $this->wizard->set_field('question_text', $question['text']['_data']);
-			}
+        $question = $form->get_question($this->wizard->get_var('question_id'));
 
-			$question_desc = (array_key_exists('desc', $question)) ? $question['desc']['_data'] : '' ;
+        if (!$this->wizard->get_field('set_original_data') && is_array($question)) {
+            if (!$this->wizard->get_field('question_text')) {
+                $this->wizard->set_field('question_text', $question['text']['_data']);
+            }
 
-			if (!$this->wizard->get_field('question_desc')) {
-			    $this->wizard->set_field('question_desc', $question_desc);
-			}
+            $question_desc = (array_key_exists('desc', $question)) ? $question['desc']['_data'] : '' ;
 
-			$this->wizard->set_field('set_original_data',true);
-		}
+            if (!$this->wizard->get_field('question_desc')) {
+                $this->wizard->set_field('question_desc', $question_desc);
+            }
 
-		?>
+            $this->wizard->set_field('set_original_data', true);
+        } ?>
 		<p>Here you can edit the text and description of the criterion.</p>
 
 		<div class="form_section">
 			<table cellpadding="2" cellspacing="2" width="100%">
 			<tr>
 				<th width="100"><label for="question_text">Criterion Text</label></th>
-				<td><input type="text" name="question_text" id="question_text" maxlength="255" size="50" value="<?php echo( $this->wizard->get_field('question_text') ); ?>" style="width: 90%;" /></td>
+				<td><input type="text" name="question_text" id="question_text" maxlength="255" size="50" value="<?php echo $this->wizard->get_field('question_text'); ?>" style="width: 90%;" /></td>
 			</tr>
 			<tr>
 				<th valign="top" width="100"><label for="question_desc">Description</label><br /><span style="font-size: 0.8em; font-weight: normal;">(optional)</span></th>
-				<td><textarea name="question_desc" id="question_desc" cols="60" rows="3" style="width: 90%;"><?php echo( $this->wizard->get_field('question_desc') ); ?></textarea></td>
+				<td><textarea name="question_desc" id="question_desc" cols="60" rows="3" style="width: 90%;"><?php echo $this->wizard->get_field('question_desc'); ?></textarea></td>
 			</tr>
 			</table>
 		</div>
 		<?php
-	}// /->form()
+    }
 
+    // /->form()
 
-	function process_form() {
-		$errors = null;
+    public function process_form()
+    {
+        $errors = null;
 
-		$this->wizard->set_field('question_text',Common::fetch_POST('question_text'));
-		if (empty($this->wizard->get_field('question_text'))) { $errors[] = 'You must provide some text for your new criterion'; }
+        $this->wizard->set_field('question_text', Common::fetch_POST('question_text'));
+        if (empty($this->wizard->get_field('question_text'))) {
+            $errors[] = 'You must provide some text for your new criterion';
+        }
 
-		$this->wizard->set_field('question_desc',Common::fetch_POST('question_desc'));
+        $this->wizard->set_field('question_desc', Common::fetch_POST('question_desc'));
 
-		return $errors;
-	}// /->process_form()
+        return $errors;
+    }
 
+    // /->process_form()
 }// /class: WizardStep1
 
 
diff --git a/src/tutors/forms/edit/edit_question/split100/class_wizardstep_2.php b/src/tutors/forms/edit/edit_question/split100/class_wizardstep_2.php
index c5413bb..d0fa672 100644
--- a/src/tutors/forms/edit/edit_question/split100/class_wizardstep_2.php
+++ b/src/tutors/forms/edit/edit_question/split100/class_wizardstep_2.php
@@ -7,27 +7,28 @@
  *
  * @link https://github.com/webpa/webpa
  */
-class WizardStep2 {
+class WizardStep2
+{
+    // Public
+    public $wizard;
 
-	// Public
-	public $wizard = null;
-	public $step = 2;
+    public $step = 2;
 
+    // CONSTRUCTOR
+    public function __construct(&$wizard)
+    {
+        $this->wizard =& $wizard;
 
-	/*
-	* CONSTRUCTOR
-	*/
-	function __construct(&$wizard) {
-		$this->wizard =& $wizard;
+        $this->wizard->back_button = null;
+        $this->wizard->next_button = null;
+        $this->wizard->cancel_button = null;
+    }
 
-		$this->wizard->back_button = null;
-		$this->wizard->next_button = null;
-		$this->wizard->cancel_button = null;
-	}// /WizardStep2()
+    // /WizardStep2()
 
-
-	function head() {
-?>
+    public function head()
+    {
+        ?>
 <script language="JavaScript" type="text/javascript">
 <!--
 
@@ -37,43 +38,47 @@ function body_onload() {
 //-->
 </script>
 <?php
-	}// /->head()
-
-
-	function form() {
-		$form = $this->wizard->get_var('form');
-
-		$new_question['text']['_data'] = $this->wizard->get_field('question_text');
-		$new_question['desc']['_data'] = $this->wizard->get_field('question_desc');
-
-		$errors = null;
-
-		if (!$form) {
-			$errors[] = 'Unable to load the form that this question belongs to.';
-		} else {
-			$form->set_question($this->wizard->get_var('question_id'), $new_question);
-			$form->save();
-		}
-
-		// If errors, show them
-		if (is_array($errors)) {
-			$this->wizard->back_button = '&lt; Back';
-			$this->wizard->cancel_button = 'Cancel';
-			echo('<p><strong>Unable to create your new assessment criterion.</strong></p>');
-			echo('<p>To correct the problem, click <em>back</em> and amend the details entered.</p>');
-		} else {// Else.. create the form!
-			?>
+    }
+
+    // /->head()
+
+    public function form()
+    {
+        $form = $this->wizard->get_var('form');
+
+        $new_question['text']['_data'] = $this->wizard->get_field('question_text');
+        $new_question['desc']['_data'] = $this->wizard->get_field('question_desc');
+
+        $errors = null;
+
+        if (!$form) {
+            $errors[] = 'Unable to load the form that this question belongs to.';
+        } else {
+            $form->set_question($this->wizard->get_var('question_id'), $new_question);
+            $form->save();
+        }
+
+        // If errors, show them
+        if (is_array($errors)) {
+            $this->wizard->back_button = '&lt; Back';
+            $this->wizard->cancel_button = 'Cancel';
+            echo '<p><strong>Unable to create your new assessment criterion.</strong></p>';
+            echo '<p>To correct the problem, click <em>back</em> and amend the details entered.</p>';
+        } else {// Else.. create the form!
+            ?>
 			<p><strong>Your changes to this criterion have been saved.</strong></p>
-			<p style="margin-top: 20px;">You can now return to <a href="/tutors/forms/edit/edit_form.php?f=<?php echo($form->id); ?>">editing your form</a>.</p>
+			<p style="margin-top: 20px;">You can now return to <a href="/tutors/forms/edit/edit_form.php?f=<?php echo $form->id; ?>">editing your form</a>.</p>
 			<?php
-		}
-	}// /->form()
-
+        }
+    }
 
-	function process_form() {
-		$this->wizard->_fields = array();	// kill the wizard's stored fields
-		return null;
-	}// /->process_form()
+    // /->form()
 
+    public function process_form()
+    {
+        $this->wizard->_fields = [];	// kill the wizard's stored fields
+        return null;
+    }
 
+    // /->process_form()
 }// /class: WizardStep2
diff --git a/src/tutors/forms/edit/preview_form.php b/src/tutors/forms/edit/preview_form.php
index 456b662..9aa7d92 100644
--- a/src/tutors/forms/edit/preview_form.php
+++ b/src/tutors/forms/edit/preview_form.php
@@ -8,15 +8,15 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\Form;
 use WebPA\includes\classes\FormRenderer;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -26,9 +26,9 @@
 
 $intro_text = Common::fetch_GET('i', null);
 if ($intro_text) {
-  $intro_text = base64_decode($intro_text);
+    $intro_text = base64_decode($intro_text);
 } else {
-  $intro_text = '<< Your introduction text will go in here >>';
+    $intro_text = '<< Your introduction text will go in here >>';
 }
 
 $form = new Form($DB);
@@ -38,13 +38,13 @@
 
 $form_renderer->set_form($form);
 
-$people = array (
-  'fake1' => '<em>Yourself</em>' ,
-  'fake2' => 'Alice' ,
-  'fake3' => 'Bob' ,
-  'fake4' => 'Claire' ,
-  'fake5' => 'David' ,
-);
+$people = [
+  'fake1' => '<em>Yourself</em>',
+  'fake2' => 'Alice',
+  'fake3' => 'Bob',
+  'fake4' => 'Claire',
+  'fake5' => 'David',
+];
 
 $form_renderer->set_participants($people);
 
@@ -96,10 +96,10 @@
 
 <?php
 if (!empty($intro_text)) {
-  ?>
+    ?>
   <h3>Introduction</h3>
   <div class="form_section">
-    <p class="introduction"><?php echo(nl2br(htmlentities($intro_text))); ?></p>
+    <p class="introduction"><?php echo nl2br(htmlentities($intro_text)); ?></p>
   </div>
   <?php
 }
diff --git a/src/tutors/forms/edit/question_action.php b/src/tutors/forms/edit/question_action.php
index c9f0eed..33d320a 100644
--- a/src/tutors/forms/edit/question_action.php
+++ b/src/tutors/forms/edit/question_action.php
@@ -8,14 +8,14 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\Form;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -24,57 +24,56 @@
 $form_id = Common::fetch_GET('f');
 $question_id = Common::fetch_GET('q');
 
-$action = strtolower( Common::fetch_GET('a') );
+$action = strtolower(Common::fetch_GET('a'));
 
 // --------------------------------------------------------------------------------
 
 $form = new Form($DB);
 if ($form->load($form_id)) {
-  $form_qs = "f={$form->id}";
+    $form_qs = "f={$form->id}";
 
-  $question_count = (int) $form->get_question_count();
+    $question_count = (int) $form->get_question_count();
 
-  $question = $form->get_question($question_id);
+    $question = $form->get_question($question_id);
 
-  if ($question_count>0) {
-    switch ($action) {
+    if ($question_count>0) {
+        switch ($action) {
       case 'up':
         if ($question_id>0) {
-          $question_2 = $form->get_question($question_id-1);
-          $form->set_question($question_id-1,$question);
-          $form->set_question($question_id,$question_2);
+            $question_2 = $form->get_question($question_id-1);
+            $form->set_question($question_id-1, $question);
+            $form->set_question($question_id, $question_2);
         }
         break;
       // --------------------
       case 'down':
         $question_2 = $form->get_question($question_id+1);
         if ($question_2) {
-          $form->set_question($question_id,$question_2);
-          $form->set_question($question_id+1,$question);
+            $form->set_question($question_id, $question_2);
+            $form->set_question($question_id+1, $question);
         }
         break;
       // --------------------
       case 'clone':
         $question = $form->get_question($question_id);
         if ($question) {
-          $form->add_question($question);
+            $form->add_question($question);
         }
         break;
       // --------------------
       case 'delete':
         if ($question) {
-          $form->remove_question($question_id);
+            $form->remove_question($question_id);
         }
         break;
       // --------------------
     }// /switch
 
     $form->save();
-  }
+    }
 } else {
-  $form_qs = '';
+    $form_qs = '';
 }
 
 header('Location: '. APP__WWW ."/tutors/forms/edit/edit_form.php?{$form_qs}#questions");
 exit;
-?>
diff --git a/src/tutors/forms/export/export_form.php b/src/tutors/forms/export/export_form.php
index 9e04b0c..77799d0 100644
--- a/src/tutors/forms/export/export_form.php
+++ b/src/tutors/forms/export/export_form.php
@@ -9,24 +9,27 @@
  * @link https://github.com/webpa/webpa
  */
 
- require_once("../../../includes/inc_global.php");
+ require_once '../../../includes/inc_global.php';
 
- use WebPA\includes\functions\Common;
+use Doctrine\DBAL\ParameterType;
+use WebPA\includes\functions\Common;
 
- if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-   header('Location:'. APP__WWW .'/logout.php?msg=denied');
-   exit;
+ if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+     header('Location:'. APP__WWW .'/logout.php?msg=denied');
+     exit;
  }
 
  //get the form ID from the URL so that we can access the form from the database.
  $form_id = Common::fetch_GET('f');
  $command = Common::fetch_POST('command');
 
- $form = $DB->fetch_row("SELECT f.* FROM " . APP__DB_TABLE_PREFIX . "form f WHERE f.form_id = '$form_id' LIMIT 1");
+ $dbConn = $DB->getConnection();
+
+ $query = 'SELECT * FROM ' . APP__DB_TABLE_PREFIX . 'form WHERE form_id = ? LIMIT 1';
+
+ $form = $dbConn->fetchAssociative($query, [$form_id], [ParameterType::STRING]);
 
  header("Content-Disposition: attachment; filename=\"{$form['form_name']}.xml\"");
  header('Content-Type: application/xml');
  echo $form['form_xml'];
  exit;
-
-?>
diff --git a/src/tutors/forms/import/import.php b/src/tutors/forms/import/import.php
index 6f9802f..9e51cac 100644
--- a/src/tutors/forms/import/import.php
+++ b/src/tutors/forms/import/import.php
@@ -9,87 +9,119 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once('../../../includes/inc_global.php');
+require_once '../../../includes/inc_global.php';
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\XMLParser;
 use WebPA\includes\functions\Common;
 use WebPA\includes\functions\XML;
 
 //get the posted data
 $xml =  stripslashes($_GET['txtXml']);
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 //check that we have something to validate
 $empty = strlen(trim($xml));
 if ($empty>0) {
-  $isValid = XML::validate($xml, 'schema.xsd');
-  if ($isValid) {
-    //get the ID for the current User
-    $staff_id = $_user->id;
-
-    // from the XML extract the form ID number and the name for the form
-    $parser = new XMLParser();
-    $parsed = $parser->parse($xml);
-
-    //set locally the form name and ID values
-    $form_id =  $parsed['form']['formid']['_data'];
-    $formname =  $parsed['form']['formname']['_data'];
-    $formtype =  $parsed['form']['formtype']['_data'];
-
-    //check that the form doesn't already exist for the user or for another
-    $results = $DB->fetch("SELECT * FROM " . APP__DB_TABLE_PREFIX . "form f WHERE form_id = '{$form_id}' AND form_name = '{$formname}'");
-
-    if ($results){
-      //we need to prompt that they are the same - or send to clone form
-      $action_notify = "<p>You already have this form in your forms list.</p><p>If you would like to make a copy of the form please use the <a href=\"index.php\">'clone form'</a> function.</p>";
+    $isValid = XML::validate($xml, 'schema.xsd');
+    if ($isValid) {
+        //get the ID for the current User
+        $staff_id = $_user->id;
+
+        // from the XML extract the form ID number and the name for the form
+        $parser = new XMLParser();
+        $parsed = $parser->parse($xml);
+
+        //set locally the form name and ID values
+        $form_id =  $parsed['form']['formid']['_data'];
+        $formname =  $parsed['form']['formname']['_data'];
+        $formtype =  $parsed['form']['formtype']['_data'];
+
+        //check that the form doesn't already exist for the user or for another
+        $resultsQuery =
+        'SELECT * ' .
+        'FROM ' . APP__DB_TABLE_PREFIX . 'form f ' .
+        'WHERE form_id = ? ' .
+        'AND form_name = ?';
+
+        $results = $DB->getConnection()->fetchAssociative($resultsQuery, [$form_id, $formname], [ParameterType::STRING, ParameterType::STRING]);
+
+        if ($results) {
+            //we need to prompt that they are the same - or send to clone form
+            $action_notify = "<p>You already have this form in your forms list.</p><p>If you would like to make a copy of the form please use the <a href=\"index.php\">'clone form'</a> function.</p>";
+        } else {
+            //need to replace the ID number before replacing in the system.
+            $new_id = Common::uuid_create();
+            $parsed['form']['formid']['_data'] = $new_id;
+            //re build the XML
+            $xml = $parser->generate_xml($parsed);
+
+            //now add to the database for this user (or generic if being imported by an administrator)
+            //need to replace the ID number before replacing in the system.
+            $new_id = Common::uuid_create();
+            $parsed['form']['formid']['_data'] = $new_id;
+            //re build the XML
+            $xml = $parser->generate_xml($parsed);
+
+            // now add to the database
+            $dbConn = $DB->getConnection();
+
+            $dbConn
+          ->createQueryBuilder()
+          ->insert(APP__DB_TABLE_PREFIX . 'form')
+          ->values([
+              'form_id' => $new_id,
+              'form_name' => $formname,
+              'form_type' => $formtype,
+              'form_xml' => $xml,
+          ])
+          ->setParameter(0, $new_id)
+          ->setParameter(1, $formname)
+          ->setParameter(2, $formtype)
+          ->setParameter(3, $xml)
+          ->execute();
+
+            $dbConn
+          ->createQueryBuilder()
+          ->update(APP__DB_TABLE_PREFIX . 'form')
+          ->set('form_name', '?')
+          ->set('form_type', '?')
+          ->set('form_xml', '?')
+          ->where('form_id', '?')
+          ->setParameter(0, $formname)
+          ->setParameter(1, $formtype)
+          ->setParameter(2, $xml)
+          ->setParameter(3, $new_id)
+          ->execute();
+
+            $dbConn
+          ->createQueryBuilder()
+          ->insert(APP__DB_TABLE_PREFIX . 'form_module')
+          ->values([
+              'form_id' => $new_id,
+              'module_id' => $_module_id,
+          ])
+          ->setParameter(0, $new_id)
+          ->setParameter(1, $_module_id, ParameterType::INTEGER)
+          ->execute();
+
+            $action_notify = "<p>The form has been uploaded and can be found in your <a href=\"../index.php\">'my forms'</a> list.</p>";
+        }
     } else {
-      //need to replace the ID number before replacing in the system.
-      $new_id = Common::uuid_create();
-      $parsed['form']['formid']['_data'] = $new_id;
-      //re build the XML
-      $xml = $parser->generate_xml($parsed);
-
-      //now add to the database for this user (or generic if being imported by an administrator)
-      //need to replace the ID number before replacing in the system.
-      $new_id = Common::uuid_create();
-      $parsed['form']['formid']['_data'] = $new_id;
-      //re build the XML
-      $xml = $parser->generate_xml($parsed);
-
-      //now add to the database
-      $fields = array(
-                 'form_id' => $new_id,
-                 'form_name' => $formname,
-                 'form_type' => $formtype,
-                 'form_xml' => $xml,
-                );
-      $DB->do_insert('INSERT INTO ' . APP__DB_TABLE_PREFIX . 'form ({fields}) VALUES ({values})', $fields);
-      $DB->do_insert('UPDATE ' . APP__DB_TABLE_PREFIX . "form SET {fields} WHERE user_id = {$new_id}", array('form_xml' => $xml));
-      $fields = array(
-                 'form_id' => $new_id,
-                 'module_id' => $_module_id
-                );
-      $DB->do_insert('INSERT INTO ' . APP__DB_TABLE_PREFIX . 'form_module ({fields}) VALUES ({values})', $fields);
-      $action_notify = "<p>The form has been uploaded and can be found in your <a href=\"../index.php\">'my forms'</a> list.</p>";
+        $action_notify = "<p>The import has failed due to the following reasons &#59; <br/>{$isValid}</p>";
     }
-  } else {
-
-    $action_notify = "<p>The import has failed due to the following reasons &#59; <br/>{$isValid}</p>";
-
-  }
-
 } else {
-  $action_notify = "<p>There was no form information to upload.<br> Please go back and try again</p>";
+    $action_notify = '<p>There was no form information to upload.<br> Please go back and try again</p>';
 }
 
 $UI->page_title = APP__NAME . ' load form';
 $UI->menu_selected = 'my forms';
 $UI->help_link = '?q=node/244';
-$UI->breadcrumbs = array('home'      => '/' ,
-            'my forms'  => null ,);
+$UI->breadcrumbs = ['home'      => '/',
+            'my forms'  => null, ];
 
 $UI->set_page_bar_button('List Forms', '../../../../images/buttons/button_form_list.gif', '../');
 $UI->set_page_bar_button('Create a new Form', '../../../../images/buttons/button_form_create.gif', '../create/');
diff --git a/src/tutors/forms/import/index.php b/src/tutors/forms/import/index.php
index aeed6c6..a512c83 100644
--- a/src/tutors/forms/import/index.php
+++ b/src/tutors/forms/import/index.php
@@ -8,21 +8,21 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once('../../../includes/inc_global.php');
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 $UI->page_title = APP__NAME . ' load form';
 $UI->menu_selected = 'my forms';
 $UI->help_link = '?q=node/244';
-$UI->breadcrumbs = array('home'      => '../../' ,
-            'my forms'  => '../' ,
-            'load form' => null,);
+$UI->breadcrumbs = ['home'      => '../../',
+            'my forms'  => '../',
+            'load form' => null, ];
 
 $UI->set_page_bar_button('List Forms', '../../../../images/buttons/button_form_list.gif', '../');
 $UI->set_page_bar_button('Create a new Form', '../../../../images/buttons/button_form_create.gif', '../create/');
diff --git a/src/tutors/forms/import/xml_file.php b/src/tutors/forms/import/xml_file.php
index cfd7a9f..77a968c 100644
--- a/src/tutors/forms/import/xml_file.php
+++ b/src/tutors/forms/import/xml_file.php
@@ -9,88 +9,109 @@
  */
 
 //get the include file required
-require_once('../../../includes/inc_global.php');
+require_once '../../../includes/inc_global.php';
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\classes\XMLParser;
 use WebPA\includes\functions\Common;
 use WebPA\includes\functions\XML;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 $errno = -1;
-foreach($_FILES as $file) {
-  $errno = $file['error'];
+foreach ($_FILES as $file) {
+    $errno = $file['error'];
 }
 
-if ($errno == 0){
+if ($errno == 0) {
 
   //file information
-  $filename = $_FILES['uploadedfile']['name'];
-  $source = $_FILES['uploadedfile']['tmp_name'];
-  //get the information from the file
-  $localfile = file_get_contents($source);
-
-  //validate the XML
-  $isValid = XML::validate($localfile, 'schema.xsd');
-
-  if ($isValid === true){
-    //get the ID for the current User
-    $staff_id = $_user->id;
-
-    // from the XML extract the form ID number and the name for the form
-    $parser = new XMLParser();
-    $parsed = $parser->parse($localfile);
-
-    //set locally the form name and ID values
-    $form_id =  $parsed['form']['formid']['_data'];
-    $formname =  $parsed['form']['formname']['_data'];
-    $formtype =  $parsed['form']['formtype']['_data'];
-
-    //check that the form doesn't already exist for the user or for another
-    $results = $DB->fetch("SELECT * FROM " . APP__DB_TABLE_PREFIX . "form f WHERE form_id ='{$form_id}' AND form_name = '{$formname}'");
-
-    if ($results){
-      //we need to prompt that they are the same - or send to clone form
-      $action_notify = "<p>You already have this form in your forms list.</p><p>If you would like to make a copy of the form please use the <a href=\"../tutors/forms/clone/index.php\">'clone form'</a> function.</p>";
+    $filename = $_FILES['uploadedfile']['name'];
+    $source = $_FILES['uploadedfile']['tmp_name'];
+    //get the information from the file
+    $localfile = file_get_contents($source);
+
+    //validate the XML
+    $isValid = XML::validate($localfile, 'schema.xsd');
+
+    if ($isValid === true) {
+        //get the ID for the current User
+        $staff_id = $_user->id;
+
+        // from the XML extract the form ID number and the name for the form
+        $parser = new XMLParser();
+        $parsed = $parser->parse($localfile);
+
+        //set locally the form name and ID values
+        $form_id =  $parsed['form']['formid']['_data'];
+        $formname =  $parsed['form']['formname']['_data'];
+        $formtype =  $parsed['form']['formtype']['_data'];
+
+        //check that the form doesn't already exist for the user or for another
+        $resultsQuery =
+        'SELECT * ' .
+        'FROM ' . APP__DB_TABLE_PREFIX . 'form f ' .
+        'WHERE form_id = ? ' .
+        'AND form_name = ?';
+
+        $results = $DB->getConnection()->fetchAssociative($resultsQuery, [$form_id, $formname], [ParameterType::STRING, ParameterType::STRING]);
+
+        if ($results) {
+            //we need to prompt that they are the same - or send to clone form
+            $action_notify = "<p>You already have this form in your forms list.</p><p>If you would like to make a copy of the form please use the <a href=\"../tutors/forms/clone/index.php\">'clone form'</a> function.</p>";
+        } else {
+            //need to replace the ID number before replacing in the system.
+            $new_id = Common::uuid_create();
+            $parsed['form']['formid']['_data'] = $new_id;
+            //re build the XML
+            $xml = $parser->generate_xml($parsed);
+
+            //now add to the database for this user
+            $dbConn = $DB->getConnection();
+
+            $dbConn
+          ->createQueryBuilder()
+          ->insert(APP__DB_TABLE_PREFIX . 'form')
+          ->values([
+              'form_id' => '?',
+              'form_name' => '?',
+              'form_type' => '?',
+              'form_xml' => '?',
+          ])
+          ->setParameter(0, $new_id)
+          ->setParameter(1, $formname)
+          ->setParameter(2, $formtype)
+          ->setParameter(3, $xml)
+          ->execute();
+
+            $dbConn
+          ->createQueryBuilder()
+          ->insert(APP__DB_TABLE_PREFIX . 'form_module')
+          ->values([
+              'form_id' => $new_id,
+              'module_id' => $_module_id,
+          ])
+          ->setParameter(0, $new_id)
+          ->setParameter(1, $_module_id, ParameterType::INTEGER)
+          ->execute();
+
+            $action_notify = "<p>The form has been uploaded and can be found in your <a href=\"index.php\">'my forms'</a> list.</p>";
+        }
     } else {
-      //need to replace the ID number before replacing in the system.
-      $new_id = Common::uuid_create();
-      $parsed['form']['formid']['_data'] = $new_id;
-      //re build the XML
-      $xml = $parser->generate_xml($parsed);
-
-      //now add to the database for this user
-      $fields = array(
-                 'form_id' => $new_id,
-                 'form_name' => $formname,
-                 'form_type' => $formtype,
-                 'form_xml' => $xml,
-                );
-      $DB->do_insert('INSERT INTO ' . APP__DB_TABLE_PREFIX . 'form ({fields}) VALUES ({values})', $fields);
-      //$DB->do_insert('UPDATE ' . APP__DB_TABLE_PREFIX . "form SET {fields} WHERE user_id = {$new_id}", array('form_xml' => $xml));
-      $fields = array(
-                 'form_id' => $new_id,
-                 'module_id' => $_module_id
-                );
-      $DB->do_insert('INSERT INTO ' . APP__DB_TABLE_PREFIX . 'form_module ({fields}) VALUES ({values})', $fields);
-
-      $action_notify = "<p>The form has been uploaded and can be found in your <a href=\"index.php\">'my forms'</a> list.</p>";
+        $action_notify = '<p>The import has failed due to the following reasons &#59; <br/>' . print_r($isValid, true) . '</p>';
     }
-  } else {
-    $action_notify = "<p>The import has failed due to the following reasons &#59; <br/>" . print_r($isValid, true) . "</p>";
-  }
-} else if (isset($FILE_ERRORS[$errno])) {
-  $action_notify = "<p>{$FILE_ERRORS[$errno]}</p>";
+} elseif (isset($FILE_ERRORS[$errno])) {
+    $action_notify = "<p>{$FILE_ERRORS[$errno]}</p>";
 } else {
-  $action_notify = "<p>Unable to upload file.</p>";
+    $action_notify = '<p>Unable to upload file.</p>';
 }
 
 $UI->page_title = APP__NAME . ' load form';
 $UI->menu_selected = 'my forms';
-$UI->breadcrumbs = array('home' => '/', 'my forms'  => null ,);
+$UI->breadcrumbs = ['home' => '/', 'my forms'  => null];
 
 $UI->set_page_bar_button('List Forms', '../../../../images/buttons/button_form_list.gif', '../');
 $UI->set_page_bar_button('Create a new Form', '../../../../images/buttons/button_form_create.gif', '../create/');
diff --git a/src/tutors/forms/index.php b/src/tutors/forms/index.php
index 5cfeb0f..2c072d1 100644
--- a/src/tutors/forms/index.php
+++ b/src/tutors/forms/index.php
@@ -8,20 +8,35 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once('../../includes/inc_global.php');
+require_once '../../includes/inc_global.php';
 
+use Doctrine\DBAL\ParameterType;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
-$generic_form = $DB->fetch('SELECT f.* FROM ' . APP__DB_TABLE_PREFIX . 'form f LEFT OUTER JOIN ' . APP__DB_TABLE_PREFIX .
-   'form_module fm ON f.form_id = fm.form_id WHERE fm.form_id IS NULL ORDER BY form_name ASC');
+$genericFormQuery =
+    'SELECT f.* ' .
+    'FROM ' . APP__DB_TABLE_PREFIX . 'form f ' .
+    'LEFT OUTER JOIN ' . APP__DB_TABLE_PREFIX . 'form_module fm ' .
+    'ON f.form_id = fm.form_id ' .
+    'WHERE fm.form_id IS NULL ' .
+    'ORDER BY form_name ASC';
 
-$forms = $DB->fetch('SELECT f.* FROM ' . APP__DB_TABLE_PREFIX . 'form f INNER JOIN ' . APP__DB_TABLE_PREFIX .
-   "form_module fm ON f.form_id = fm.form_id WHERE fm.module_id = {$_module_id} ORDER BY form_name ASC");
+$generic_form = $DB->getConnection()->fetchAllAssociative($genericFormQuery);
+
+$formsQuery =
+    'SELECT f.* ' .
+    'FROM ' . APP__DB_TABLE_PREFIX . 'form f ' .
+    'INNER JOIN ' . APP__DB_TABLE_PREFIX . 'form_module fm ' .
+    'ON f.form_id = fm.form_id ' .
+    'WHERE fm.module_id = ? ' .
+    'ORDER BY form_name ASC';
+
+$forms = $DB->getConnection()->fetchAllAssociative($formsQuery, [$_module_id], [ParameterType::INTEGER]);
 
 // --------------------------------------------------------------------------------
 // Begin Page
@@ -29,10 +44,10 @@
 $UI->page_title = APP__NAME . ' my forms';
 $UI->menu_selected = 'my forms';
 $UI->help_link = '?q=node/244';
-$UI->breadcrumbs = array  (
-  'home'      => '../' ,
-  'my forms'  => null ,
-);
+$UI->breadcrumbs = [
+  'home'      => '../',
+  'my forms'  => null,
+];
 
 $UI->set_page_bar_button('List Forms', '../../../images/buttons/button_form_list.gif', '');
 $UI->set_page_bar_button('Create a new Form', '../../../images/buttons/button_form_create.gif', 'create/');
@@ -58,31 +73,28 @@
 <?php
 // @pmn - check to see if there are generic forms
 if ($generic_form) {
-?>
+    ?>
       <h3>generic / example form</h3>
 
 <?php
   //out put the generic form
   foreach ($generic_form as $i => $form) {
-    $clone_url = "clone/clone_example.php?f={$form['form_id']}";
-    $edit_url = "edit/edit_form.php?f={$form['form_id']}";
-
-?>
+      $clone_url = "clone/clone_example.php?f={$form['form_id']}";
+      $edit_url = "edit/edit_form.php?f={$form['form_id']}"; ?>
         <div class="obj">
           <table class="obj" cellpadding="2" cellspacing="2">
           <tr>
-            <td class="icon" width="24"><a href="<?php echo($clone_url); ?>"><img src="../../images/icons/form.gif" width="24" height="24" alt="Form" /></a></td>
+            <td class="icon" width="24"><a href="<?php echo $clone_url; ?>"><img src="../../images/icons/form.gif" width="24" height="24" alt="Form" /></a></td>
             <td class="obj_info">
-              <div class="obj_name"><a class="text" href="<?php echo($clone_url); ?>"><?php echo($form['form_name']); ?></a></div>
+              <div class="obj_name"><a class="text" href="<?php echo $clone_url; ?>"><?php echo $form['form_name']; ?></a></div>
             </td>
 <?php
     if ($_user->is_admin()) {
-?>
-            <td class="button" width="24"><a href="<?php echo($edit_url); ?>"><img src="../../images/buttons/edit.gif" width="16" height="16" alt="edit form" title="edit" /></a></td>
-            <td class="button" width="24"><a href="<?php echo($edit_url); ?>&command=delete" onclick="return confirm('This assessment form will be deleted.\n\nClick OK to confirm.');"><img src="../../images/buttons/cross.gif" width="16" height="16" alt="delete form" title="delete" /></a></td>
+        ?>
+            <td class="button" width="24"><a href="<?php echo $edit_url; ?>"><img src="../../images/buttons/edit.gif" width="16" height="16" alt="edit form" title="edit" /></a></td>
+            <td class="button" width="24"><a href="<?php echo $edit_url; ?>&command=delete" onclick="return confirm('This assessment form will be deleted.\n\nClick OK to confirm.');"><img src="../../images/buttons/cross.gif" width="16" height="16" alt="delete form" title="delete" /></a></td>
 <?php
-    }
-?>
+    } ?>
           </tr>
           </table>
         </div>
@@ -94,32 +106,31 @@
 
 <?php
 if (!$forms) {
-?>
+    ?>
         <p>You do not have any assessment forms at the moment. Please <a href="create/">create a new form</a>.</p>
 <?php
 } else {
 
   //out put the form that the user owns
-  foreach ($forms as $i => $form) {
-    $edit_url = "edit/edit_form.php?f={$form['form_id']}";
-    $export_url = "export/export_form.php?f={$form['form_id']}";
-?>
+        foreach ($forms as $i => $form) {
+            $edit_url = "edit/edit_form.php?f={$form['form_id']}";
+            $export_url = "export/export_form.php?f={$form['form_id']}"; ?>
           <div class="obj">
             <table class="obj" cellpadding="2" cellspacing="2">
             <tr>
-              <td class="icon" width="24"><a href="<?php echo($edit_url); ?>"><img src="../../images/icons/form.gif" width="24" height="24" alt="Form" /></a></td>
+              <td class="icon" width="24"><a href="<?php echo $edit_url; ?>"><img src="../../images/icons/form.gif" width="24" height="24" alt="Form" /></a></td>
               <td class="obj_info">
-                <div class="obj_name"><a class="text" href="<?php echo($edit_url); ?>"><?php echo($form['form_name']); ?></a></div>
+                <div class="obj_name"><a class="text" href="<?php echo $edit_url; ?>"><?php echo $form['form_name']; ?></a></div>
               </td>
-              <td class="button" width="24"><a href="<?php echo($export_url); ?>"><img src="../../images/file_icons/package_go.png" width="16" height="16" alt="export form" title="export" /></a></td>
-              <td class="button" width="24"><a href="<?php echo($edit_url); ?>"><img src="../../images/buttons/edit.gif" width="16" height="16" alt="edit form" title="edit" /></a></td>
-              <td class="button" width="24"><a href="<?php echo($edit_url); ?>&command=delete" onclick="return confirm('This assessment form will be deleted.\n\nClick OK to confirm.');"><img src="../../images/buttons/cross.gif" width="16" height="16" alt="delete form" title="delete" /></a></td>
+              <td class="button" width="24"><a href="<?php echo $export_url; ?>"><img src="../../images/file_icons/package_go.png" width="16" height="16" alt="export form" title="export" /></a></td>
+              <td class="button" width="24"><a href="<?php echo $edit_url; ?>"><img src="../../images/buttons/edit.gif" width="16" height="16" alt="edit form" title="edit" /></a></td>
+              <td class="button" width="24"><a href="<?php echo $edit_url; ?>&command=delete" onclick="return confirm('This assessment form will be deleted.\n\nClick OK to confirm.');"><img src="../../images/buttons/cross.gif" width="16" height="16" alt="delete form" title="delete" /></a></td>
             </tr>
             </table>
           </div>
 <?php
-  }
-}
+        }
+    }
 ?>
     </div>
   </div>
diff --git a/src/tutors/groups/clone/class_wizardstep_1.php b/src/tutors/groups/clone/class_wizardstep_1.php
index 60be787..3e5676e 100644
--- a/src/tutors/groups/clone/class_wizardstep_1.php
+++ b/src/tutors/groups/clone/class_wizardstep_1.php
@@ -11,90 +11,99 @@
 use WebPA\includes\classes\SimpleObjectIterator;
 use WebPA\includes\functions\Common;
 
-class WizardStep1 {
+class WizardStep1
+{
+    public $wizard;
 
-  public $wizard;
-  public $step = 1;
+    public $step = 1;
 
-  /*
-  * CONSTRUCTOR
-  */
-  public function __construct($wizard) {
-    $this->wizard = $wizard;
+    // CONSTRUCTOR
+    public function __construct($wizard)
+    {
+        $this->wizard = $wizard;
 
-    $this->wizard->back_button = null;
-    $this->wizard->next_button = 'Next &gt;';
-    $this->wizard->cancel_button = 'Cancel';
-  }// /WizardStep1()
+        $this->wizard->back_button = null;
+        $this->wizard->next_button = 'Next &gt;';
+        $this->wizard->cancel_button = 'Cancel';
+    }
 
-  function head() {
-    $html = <<<HTMLEnd
-<script language="JavaScript" type="text/javascript">
-<!--
+    // /WizardStep1()
 
-  function body_onload() {
-    document.getElementById('collection_name').focus();
-  }// /body_onload()
+    public function head()
+    {
+        $html = <<<HTMLEnd
+            <script language="JavaScript" type="text/javascript">
+            <!--
 
-//-->
-</script>
-HTMLEnd;
+              function body_onload() {
+                document.getElementById('collection_name').focus();
+              }// /body_onload()
 
-    echo($html);
-  }// /->head()
+            //-->
+            </script>
+            HTMLEnd;
 
-  function form() {
-    $config = $this->wizard->get_var('config');
-    $module = $this->wizard->get_var('module');
-    $group_handler = $this->wizard->get_var('group_handler');
+        echo $html;
+    }
 
-    $collections = $group_handler->get_module_collections($module, $config['app_id']);
+    // /->head()
 
-    $collection_iterator = new SimpleObjectIterator($collections, 'GroupCollection', $group_handler->_DAO);
+    public function form()
+    {
+        $config = $this->wizard->get_var('config');
+        $module = $this->wizard->get_var('module');
+        $group_handler = $this->wizard->get_var('group_handler');
 
-    if ($collection_iterator->size()==0) {
-?>
+        $collections = $group_handler->get_module_collections($module, $config['app_id']);
+
+        $collection_iterator = new SimpleObjectIterator($collections, 'GroupCollection', $group_handler->_DAO);
+
+        if ($collection_iterator->size()==0) {
+            ?>
       <p>You have not created any groups, so there are none to clone.</p>
 
 <?php
       $this->wizard->next_button = null;
-    } else {
-?>
+        } else {
+            ?>
       <h2>Your Groups</h2>
       <p>Firstly, you need to choose a collection of groups to clone. Please select which you want to clone:</p>
       <div class="form_section">
         <table class="form" cellpadding="1" cellspacing="1">
 <?php
-      for($collection_iterator->reset(); $collection_iterator->is_valid(); $collection_iterator->next() ) {
-        $collection = $collection_iterator->current();
-
-        $group_count = count($collection->get_groups_array());
-        $group_plural = ($group_count==1) ? 'group' : 'groups';
-
-        $checked_str = ($collection->id==$this->wizard->get_field('collection_id')) ? 'checked="checked"' : '' ;
-        echo('<tr>');
-        echo("<td><input type=\"radio\" name=\"collection_id\" id=\"collection_{$collection->id}\" value=\"{$collection->id}\" $checked_str /></td>");
-        echo("<td><label style=\"font-weight: normal;\" for=\"collection_{$collection->id}\">{$collection->name} &nbsp; ($group_count $group_plural)</label></td>");
-        echo('</tr>');
-      }
-?>
+      for ($collection_iterator->reset(); $collection_iterator->is_valid(); $collection_iterator->next()) {
+          $collection = $collection_iterator->current();
+
+          $group_count = count($collection->get_groups_array());
+          $group_plural = ($group_count==1) ? 'group' : 'groups';
+
+          $checked_str = ($collection->id==$this->wizard->get_field('collection_id')) ? 'checked="checked"' : '' ;
+          echo '<tr>';
+          echo "<td><input type=\"radio\" name=\"collection_id\" id=\"collection_{$collection->id}\" value=\"{$collection->id}\" $checked_str /></td>";
+          echo "<td><label style=\"font-weight: normal;\" for=\"collection_{$collection->id}\">{$collection->name} &nbsp; ($group_count $group_plural)</label></td>";
+          echo '</tr>';
+      } ?>
         </table>
       </div>
 <?php
+        }
     }
-  }// /->form()
 
-  function process_form() {
-    $errors = null;
+    // /->form()
 
-    $this->wizard->set_field('collection_id',Common::fetch_POST('collection_id'));
-    if (empty($this->wizard->get_field('collection_id'))) {
-      $errors[] = 'You must select a collection of groups to clone.';
-    }
+    public function process_form()
+    {
+        $errors = null;
 
-    return $errors;
-  }// /->process_form()
+        $this->wizard->set_field('collection_id', Common::fetch_POST('collection_id'));
+        if (empty($this->wizard->get_field('collection_id'))) {
+            $errors[] = 'You must select a collection of groups to clone.';
+        }
+
+        return $errors;
+    }
 
+    // /->process_form()
 }// /class: WizardStep1
 
 ?>
diff --git a/src/tutors/groups/clone/class_wizardstep_2.php b/src/tutors/groups/clone/class_wizardstep_2.php
index a832dc3..3df3a42 100644
--- a/src/tutors/groups/clone/class_wizardstep_2.php
+++ b/src/tutors/groups/clone/class_wizardstep_2.php
@@ -10,47 +10,52 @@
 
 use WebPA\includes\functions\Common;
 
-class WizardStep2 {
+class WizardStep2
+{
+    // Public
+    public $wizard;
 
-  // Public
-  public $wizard = null;
-  public $step = 2;
+    public $step = 2;
 
-  /*
-  * CONSTRUCTOR
-  */
-  function __construct(&$wizard) {
-    $this->wizard =& $wizard;
+    // CONSTRUCTOR
+    public function __construct(&$wizard)
+    {
+        $this->wizard =& $wizard;
 
-    $this->wizard->back_button = '&lt; Back';
-    $this->wizard->next_button = 'Finish';
-    $this->wizard->cancel_button = 'Cancel';
-  }// /WizardStep2()
-
-  function head() {
-    $html = <<<HTMLEnd
-<script language="JavaScript" type="text/javascript">
-<!--
+        $this->wizard->back_button = '&lt; Back';
+        $this->wizard->next_button = 'Finish';
+        $this->wizard->cancel_button = 'Cancel';
+    }
 
-  function body_onload() {
-  }// /body_onload()
+    // /WizardStep2()
 
-//-->
-</script>
-HTMLEnd;
+    public function head()
+    {
+        $html = <<<HTMLEnd
+            <script language="JavaScript" type="text/javascript">
+            <!--
 
-    echo($html);
-  }// /->head()
+              function body_onload() {
+              }// /body_onload()
 
-  function form() {
-    $group_handler = $this->wizard->get_var('group_handler');
-    $collection = $group_handler->get_collection($this->wizard->get_field('collection_id'));
+            //-->
+            </script>
+            HTMLEnd;
 
-    if (empty($this->wizard->get_field('collection_name'))) {
-      $this->wizard->set_field('collection_name', $collection->name);
+        echo $html;
     }
-?>
-    <p>You have chosen to clone: <em><?php echo($collection->name); ?></em></p>
+
+    // /->head()
+
+    public function form()
+    {
+        $group_handler = $this->wizard->get_var('group_handler');
+        $collection = $group_handler->get_collection($this->wizard->get_field('collection_id'));
+
+        if (empty($this->wizard->get_field('collection_name'))) {
+            $this->wizard->set_field('collection_name', $collection->name);
+        } ?>
+    <p>You have chosen to clone: <em><?php echo $collection->name; ?></em></p>
     <h2>Name of Clone</h2>
     <p>To avoid confusion, the name of your cloned collection of groups should be unique, but you can use the same name if you wish.</p>
     <p>The name should be describe what the groups are for. For example, if the students are doing coursework for module 05ABC123, then name the collection, <em>05ABC123 - Coursework Groups</em>.</p>
@@ -59,22 +64,28 @@ function form() {
       <table class="form" cellpadding="2" cellspacing="2">
       <tr>
         <th><label for="collection_name">Name for this new collection</label></th>
-        <td><input type="text" name="collection_name" id="collection_name" maxlength="50" size="40" value="<?php echo( $this->wizard->get_field('collection_name') ); ?>" /></td>
+        <td><input type="text" name="collection_name" id="collection_name" maxlength="50" size="40" value="<?php echo $this->wizard->get_field('collection_name'); ?>" /></td>
       </tr>
       </table>
     </div>
 <?php
-  }// /->form()
+    }
 
-  function process_form() {
-    $errors = null;
+    // /->form()
 
-    $this->wizard->set_field('collection_name', Common::fetch_POST('collection_name'));
-    if (empty($this->wizard->get_field('collection_name'))) { $errors[] = 'You must provide a name for your new collection of groups'; }
+    public function process_form()
+    {
+        $errors = null;
 
-    return $errors;
-  }// /->process_form()
+        $this->wizard->set_field('collection_name', Common::fetch_POST('collection_name'));
+        if (empty($this->wizard->get_field('collection_name'))) {
+            $errors[] = 'You must provide a name for your new collection of groups';
+        }
+
+        return $errors;
+    }
 
+    // /->process_form()
 }// /class: WizardStep2
 
 ?>
diff --git a/src/tutors/groups/clone/class_wizardstep_3.php b/src/tutors/groups/clone/class_wizardstep_3.php
index 6223737..19fbdc7 100644
--- a/src/tutors/groups/clone/class_wizardstep_3.php
+++ b/src/tutors/groups/clone/class_wizardstep_3.php
@@ -8,73 +8,83 @@
  * @link https://github.com/webpa/webpa
  */
 
-class WizardStep3 {
-
-  // Public
-  public $wizard = null;
-  public $step = 3;
-
-  /*
-  * CONSTRUCTOR
-  */
-  function __construct(&$wizard) {
-    $this->wizard =& $wizard;
-    $this->wizard->back_button = null;
-    $this->wizard->next_button = null;
-    $this->wizard->cancel_button = null;
-  }// /WizardStep3()
-
-  function head() {
-    $html = <<<HTMLEnd
-<script language="JavaScript" type="text/javascript">
-<!--
-
-  function body_onload() {
-  }// /body_onload()
-
-//-->
-</script>
-HTMLEnd;
-
-    echo($html);
-  }// /->head()
-
-  function form() {
-    $config = $this->wizard->get_var('config');
-    $group_handler = $this->wizard->get_var('group_handler');
-
-    // Clone the collection
-    $collection = $group_handler->clone_collection($this->wizard->get_field('collection_id'));
-
-    $errors = null;
-
-    if (!$collection) {
-      $errors[] = 'There was an error when trying to clone these groups - please use the contact system to report the error!';
-    } else {
-      $collection->name = $this->wizard->get_field('collection_name');
-      $collection->save();
+class WizardStep3
+{
+    // Public
+    public $wizard;
+
+    public $step = 3;
+
+    // CONSTRUCTOR
+    public function __construct(&$wizard)
+    {
+        $this->wizard =& $wizard;
+        $this->wizard->back_button = null;
+        $this->wizard->next_button = null;
+        $this->wizard->cancel_button = null;
+    }
+
+    // /WizardStep3()
+
+    public function head()
+    {
+        $html = <<<HTMLEnd
+            <script language="JavaScript" type="text/javascript">
+            <!--
+
+              function body_onload() {
+              }// /body_onload()
+
+            //-->
+            </script>
+            HTMLEnd;
+
+        echo $html;
     }
 
-    // If errors, show them
-    if (is_array($errors)) {
-      $this->wizard->back_button = '&lt; Back';
-      $this->wizard->cancel_button = 'Cancel';
-      echo('<p><strong>Unable to create your new cloned groups.</strong></p>');
-      echo('<p>To correct the problem, try clicking <em>back</em> and amend the details entered.</p>');
-    } else {// Else.. create the groups!
+    // /->head()
+
+    public function form()
+    {
+        $config = $this->wizard->get_var('config');
+        $group_handler = $this->wizard->get_var('group_handler');
+
+        // Clone the collection
+        $collection = $group_handler->clone_collection($this->wizard->get_field('collection_id'));
+
+        $errors = null;
+
+        if (!$collection) {
+            $errors[] = 'There was an error when trying to clone these groups - please use the contact system to report the error!';
+        } else {
+            $collection->name = $this->wizard->get_field('collection_name');
+            $collection->save();
+        }
+
+        // If errors, show them
+        if (is_array($errors)) {
+            $this->wizard->back_button = '&lt; Back';
+            $this->wizard->cancel_button = 'Cancel';
+            echo '<p><strong>Unable to create your new cloned groups.</strong></p>';
+            echo '<p>To correct the problem, try clicking <em>back</em> and amend the details entered.</p>';
+        } else {// Else.. create the groups!
       ?>
       <p><strong>Your new cloned groups have been created.</strong></p>
-      <p style="margin-top: 20px;">To re-allocate students to your new groups, you can use the <a href="../edit/edit_collection.php?c=<?php echo($collection->id); ?>">group editor</a>.</p>
+      <p style="margin-top: 20px;">To re-allocate students to your new groups, you can use the <a href="../edit/edit_collection.php?c=<?php echo $collection->id; ?>">group editor</a>.</p>
       <p style="margin-top: 20px;">Alternatively, you can return to <a href="../">my groups</a>, or to the <a href="../../">WebPA home page</a>.</p>
       <?php
     }
-  }// /->form()
+    }
 
-  function process_form() {
-    $this->wizard->_fields = array(); // kill the wizard's stored fields
-    return null;
-  }// /->process_form()
+    // /->form()
+
+    public function process_form()
+    {
+        $this->wizard->_fields = []; // kill the wizard's stored fields
+        return null;
+    }
 
+    // /->process_form()
 }// /class: WizardStep3
 
 ?>
diff --git a/src/tutors/groups/clone/index.php b/src/tutors/groups/clone/index.php
index 61e2534..c3c6d83 100644
--- a/src/tutors/groups/clone/index.php
+++ b/src/tutors/groups/clone/index.php
@@ -8,26 +8,26 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once('../../../includes/inc_global.php');
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\GroupHandler;
 use WebPA\includes\classes\Wizard;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
 // Initialise wizard
 
 $wizard = new Wizard('clone own groups wizard');
-$wizard->cancel_url = "../";
+$wizard->cancel_url = '../';
 
-$wizard->add_step(1,'class_wizardstep_1.php');
-$wizard->add_step(2,'class_wizardstep_2.php');
-$wizard->add_step(3,'class_wizardstep_3.php');
+$wizard->add_step(1, 'class_wizardstep_1.php');
+$wizard->add_step(2, 'class_wizardstep_2.php');
+$wizard->add_step(3, 'class_wizardstep_3.php');
 
 $wizard->set_var('config', $_config);
 $wizard->set_var('module', $_module_id);
@@ -48,12 +48,12 @@
 $UI->page_title = APP__NAME . ' Clone own groups';
 $UI->menu_selected = 'my groups';
 $UI->help_link = '?q=node/253';
-$UI->breadcrumbs = array  (
-  'home'                      => '../../' ,
-  'my groups'                 => '../' ,
-  'clone groups'              => '../clone/' ,
-  'clone own groups wizard'   => null ,
-);
+$UI->breadcrumbs = [
+  'home'                      => '../../',
+  'my groups'                 => '../',
+  'clone groups'              => '../clone/',
+  'clone own groups wizard'   => null,
+];
 
 $UI->set_page_bar_button('List Groups', '../../../../images/buttons/button_group_list.gif', '../');
 $UI->set_page_bar_button('Create Groups', '../../../../images/buttons/button_group_create.gif', '../create/');
diff --git a/src/tutors/groups/create/class_wizardstep_1.php b/src/tutors/groups/create/class_wizardstep_1.php
index db8d5a1..1b0fcfe 100644
--- a/src/tutors/groups/create/class_wizardstep_1.php
+++ b/src/tutors/groups/create/class_wizardstep_1.php
@@ -11,65 +11,74 @@
 use WebPA\includes\classes\Wizard;
 use WebPA\includes\functions\Common;
 
-class WizardStep1 {
+class WizardStep1
+{
+    public $wizard;
 
-  public $wizard;
-  public $step = 1;
+    public $step = 1;
 
-  /*
-  * CONSTRUCTOR
-  */
-  function __construct(Wizard $wizard) {
-    $this->wizard = $wizard;
+    // CONSTRUCTOR
+    public function __construct(Wizard $wizard)
+    {
+        $this->wizard = $wizard;
 
-    $this->wizard->back_button = null;
-    $this->wizard->next_button = 'Next &gt;';
-    $this->wizard->cancel_button = 'Cancel';
-  }// /WizardStep1()
+        $this->wizard->back_button = null;
+        $this->wizard->next_button = 'Next &gt;';
+        $this->wizard->cancel_button = 'Cancel';
+    }
 
-  function head() {
-    $html = <<<HTMLEnd
-<script language="JavaScript" type="text/javascript">
-<!--
+    // /WizardStep1()
 
-  function body_onload() {
-    document.getElementById('collection_name').focus();
-  }// /body_onload()
+    public function head()
+    {
+        $html = <<<HTMLEnd
+            <script language="JavaScript" type="text/javascript">
+            <!--
 
-//-->
-</script>
-HTMLEnd;
+              function body_onload() {
+                document.getElementById('collection_name').focus();
+              }// /body_onload()
 
-    echo($html);
-  }// /->head()
+            //-->
+            </script>
+            HTMLEnd;
 
-  function form() {
-    $module_select = $this->wizard->get_field('module_select');
-?>
+        echo $html;
+    }
+
+    // /->head()
+
+    public function form()
+    {
+        $module_select = $this->wizard->get_field('module_select'); ?>
     <p>Firstly, we need to give this new collection of groups a name. To avoid confusion, the name should be unique, but you can create collections using the same name if you wish.</p>
     <p>The name should be describe what the groups are for. For example, if the students are doing coursework for module 05ABC123, then name the collection, <em>05ABC123 - Coursework Groups</em>.</p>
 
     <table class="form" cellpadding="2" cellspacing="2">
     <tr>
       <th><label for="collection_name">Name for this new collection</label></th>
-      <td><input type="text" name="collection_name" id="collection_name" maxlength="50" size="40" value="<?php echo( $this->wizard->get_field('collection_name') ); ?>" /></td>
+      <td><input type="text" name="collection_name" id="collection_name" maxlength="50" size="40" value="<?php echo $this->wizard->get_field('collection_name'); ?>" /></td>
     </tr>
     </table>
 
 <?php
-  }// /->form()
+    }
 
-  function process_form() {
-    $errors = null;
+    // /->form()
 
-    $this->wizard->set_field('collection_name', Common::fetch_POST('collection_name'));
-    if (empty($this->wizard->get_field('collection_name'))) {
-      $errors[] = 'You must provide a name for your new collection of groups';
-    }
+    public function process_form()
+    {
+        $errors = null;
 
-    return $errors;
-  }// /->process_form()
+        $this->wizard->set_field('collection_name', Common::fetch_POST('collection_name'));
+        if (empty($this->wizard->get_field('collection_name'))) {
+            $errors[] = 'You must provide a name for your new collection of groups';
+        }
+
+        return $errors;
+    }
 
+    // /->process_form()
 }// /class: WizardStep1
 
 ?>
diff --git a/src/tutors/groups/create/class_wizardstep_2.php b/src/tutors/groups/create/class_wizardstep_2.php
index 06864d4..dd53008 100644
--- a/src/tutors/groups/create/class_wizardstep_2.php
+++ b/src/tutors/groups/create/class_wizardstep_2.php
@@ -15,15 +15,14 @@
 
 class WizardStep2
 {
-    public $wizard = null;
+    public $wizard;
+
     public $step = 2;
 
     private $moduleId;
 
-    /*
-    * CONSTRUCTOR
-    */
-    function __construct(Wizard $wizard)
+    // CONSTRUCTOR
+    public function __construct(Wizard $wizard)
     {
         $this->wizard = $wizard;
 
@@ -32,26 +31,30 @@ function __construct(Wizard $wizard)
         $this->wizard->back_button = '&lt; Back';
         $this->wizard->next_button = 'Next &gt;';
         $this->wizard->cancel_button = 'Cancel';
-    }// /WizardStep2()
+    }
+
+    // /WizardStep2()
 
-    function head()
+    public function head()
     {
         $html = <<<HTMLEnd
-<script language="JavaScript" type="text/javascript">
-<!--
+            <script language="JavaScript" type="text/javascript">
+            <!--
+
+              function body_onload() {
+                document.getElementById('num_groups').focus();
+              }// /body_onload()
 
-  function body_onload() {
-    document.getElementById('num_groups').focus();
-  }// /body_onload()
+            //-->
+            </script>
+            HTMLEnd;
 
-//-->
-</script>
-HTMLEnd;
+        echo $html;
+    }
 
-        echo($html);
-    }// /->head()
+    // /->head()
 
-    function form()
+    public function form()
     {
         $CIS = $this->wizard->get_var('CIS');
         $config = $this->wizard->get_var('config');
@@ -61,11 +64,10 @@ function form()
         $students_plural = ($total_students == 1) ? 'student' : 'students';
 
         if ($total_students == 0) {
-            echo("<div class=\"warning_box\"><p><strong>Warning!</strong></p><p>There are no students associated with the module you have selected.</p><p>You can continue to create your groups if you wish but there are no students available, so your groups cannot be populated at this time.</p><p>To choose a different module, click <em>back</em> to view the list of modules available.</p></div>");
+            echo '<div class="warning_box"><p><strong>Warning!</strong></p><p>There are no students associated with the module you have selected.</p><p>You can continue to create your groups if you wish but there are no students available, so your groups cannot be populated at this time.</p><p>To choose a different module, click <em>back</em> to view the list of modules available.</p></div>';
         } else {
-            echo("<p>The module contains <strong>$total_students $students_plural</strong> in total.</p>");
-        }
-        ?>
+            echo "<p>The module contains <strong>$total_students $students_plural</strong> in total.</p>";
+        } ?>
         <p>Now you can set how the new groups will be created. To save time, the system can automatically create
             sequentially named groups for you. If you do not want to use sequential names, or if you just want to create
             all your groups yourself, select <em>0</em> in the <em>Number of groups to create</em> box below.</p>
@@ -79,7 +81,7 @@ function form()
                     <th><label for="num_groups">Number of groups to create</label></th>
                     <td>
                         <select name="num_groups" id="num_groups">
-                            <?php Form::render_options_range(0, 100, 1, (int)$this->wizard->get_field('num_groups')); ?>
+                            <?php Form::render_options_range(0, 100, 1, (int) $this->wizard->get_field('num_groups')); ?>
                         </select>
                     </td>
                 </tr>
@@ -92,7 +94,7 @@ function form()
                 <tr>
                     <th><label for="group_name_stub">Group names begin with</label></th>
                     <td><input type="text" name="group_name_stub" id="group_name_stub" maxlength="40" size="25"
-                               value="<?php echo($this->wizard->get_field('group_name_stub')); ?>"/></td>
+                               value="<?php echo $this->wizard->get_field('group_name_stub'); ?>"/></td>
                 </tr>
             </table>
 
@@ -104,21 +106,22 @@ function form()
                     <td>
                         <select name="group_numbering" id="group_numbering">
                             <?php
-                            $options = array('alphabetic' => 'Alphabetic (Group A, Group B, ..)',
+                            $options = ['alphabetic' => 'Alphabetic (Group A, Group B, ..)',
                                 'numeric' => 'Numeric (Group 1, Group 2, ..)',
                                 'hashed' => 'Hashed-Numeric (Group #1, Group #2, ..)',
-                            );
-                            Form::render_options($options, $this->wizard->get_field('group_numbering'));
-                            ?>
+                            ];
+        Form::render_options($options, $this->wizard->get_field('group_numbering')); ?>
                         </select>
                     </td>
                 </tr>
             </table>
         </div>
         <?php
-    }// /->form()
+    }
+
+    // /->form()
 
-    function process_form()
+    public function process_form()
     {
         $errors = null;
 
@@ -140,8 +143,9 @@ function process_form()
         }
 
         return $errors;
-    }// /->process_form()
+    }
 
+    // /->process_form()
 }// /class: WizardStep2
 
 ?>
diff --git a/src/tutors/groups/create/class_wizardstep_3.php b/src/tutors/groups/create/class_wizardstep_3.php
index 846458d..0793366 100644
--- a/src/tutors/groups/create/class_wizardstep_3.php
+++ b/src/tutors/groups/create/class_wizardstep_3.php
@@ -13,15 +13,13 @@
 
 class WizardStep3
 {
+    public $wizard;
 
-    public $wizard = null;
     public $step = 3;
 
     private $moduleId;
 
-    /*
-    * CONSTRUCTOR
-    */
+    // CONSTRUCTOR
     public function __construct(Wizard $wizard)
     {
         $this->wizard = $wizard;
@@ -31,25 +29,29 @@ public function __construct(Wizard $wizard)
         $this->wizard->back_button = '&lt; Back';
         $this->wizard->next_button = 'Finish';
         $this->wizard->cancel_button = 'Cancel';
-    }// /WizardStep3()
+    }
 
-    function head()
+    // /WizardStep3()
+
+    public function head()
     {
         $html = <<<HTMLEnd
-<script language="JavaScript" type="text/javascript">
-<!--
+            <script language="JavaScript" type="text/javascript">
+            <!--
+
+              function body_onload() {
+              }// /body_onload()
 
-  function body_onload() {
-  }// /body_onload()
+            //-->
+            </script>
+            HTMLEnd;
 
-//-->
-</script>
-HTMLEnd;
+        echo $html;
+    }
 
-        echo($html);
-    }// /->head()
+    // /->head()
 
-    function form()
+    public function form()
     {
         $CIS = $this->wizard->get_var('CIS');
 
@@ -57,53 +59,51 @@ function form()
         if (!$total_students) {
             $total_students = 0;
         }
-        $students_plural = ($total_students == 1) ? 'student' : 'students';
-        ?>
+        $students_plural = ($total_students == 1) ? 'student' : 'students'; ?>
         <p>Please confirm the following settings are correct before proceeding.</p>
         <p>If you wish to amend any details, click <em>Back</em>. When you are ready to create your groups, click <em>Finish</em>.
         </p>
 
         <h2>Name</h2>
         <div style="margin: 0px 0px 16px 25px;">This collection of groups will be
-            called: <?php echo($this->wizard->get_field('collection_name')); ?></div>
+            called: <?php echo $this->wizard->get_field('collection_name'); ?></div>
 
         <h2>Students</h2>
         <div style="margin: 0px 0px 16px 25px;">
-            <p><?php echo("$total_students $students_plural"); ?> available.</p>
+            <p><?php echo "$total_students $students_plural"; ?> available.</p>
         </div>
 
         <h2>Groups</h2>
         <?php
-        $num_groups = (int)$this->wizard->get_field('num_groups');
+        $num_groups = (int) $this->wizard->get_field('num_groups');
         if ($num_groups > 0) {
             ?>
             <div style="margin: 0px 0px 16px 25px;">
                 <p>The following groups will be created in the new
-                    <strong><?php echo($this->wizard->get_field('groupset_name')); ?></strong> collection:</p>
+                    <strong><?php echo $this->wizard->get_field('groupset_name'); ?></strong> collection:</p>
                 <div style="margin-left: 25px;">
                     <?php
-                    $num_groups = (int)$this->wizard->get_field('num_groups');
-
-                    $groupHandler = new GroupHandler();
-
-                    $group_names = $groupHandler->generate_group_names(
-                        $num_groups,
-                        $this->wizard->get_field('group_name_stub'),
-                        $this->wizard->get_field('group_numbering')
-                    );
-
-                    if ($num_groups <= 5) {
-                        foreach ($group_names as $group_name) {
-                            echo("<div>$group_name</div>");
-                        }
-                    } else {
-                        echo("<div>{$group_names[0]}</div>");
-                        echo("<div>{$group_names[1]}</div>");
-                        echo("<div>&nbsp; ...</div>");
-                        echo('<div>' . $group_names[$num_groups - 2] . '</div>');
-                        echo('<div>' . $group_names[$num_groups - 1] . '</div>');
-                    }
-                    ?>
+                    $num_groups = (int) $this->wizard->get_field('num_groups');
+
+            $groupHandler = new GroupHandler();
+
+            $group_names = $groupHandler->generate_group_names(
+                $num_groups,
+                $this->wizard->get_field('group_name_stub'),
+                $this->wizard->get_field('group_numbering')
+            );
+
+            if ($num_groups <= 5) {
+                foreach ($group_names as $group_name) {
+                    echo "<div>$group_name</div>";
+                }
+            } else {
+                echo "<div>{$group_names[0]}</div>";
+                echo "<div>{$group_names[1]}</div>";
+                echo '<div>&nbsp; ...</div>';
+                echo '<div>' . $group_names[$num_groups - 2] . '</div>';
+                echo '<div>' . $group_names[$num_groups - 1] . '</div>';
+            } ?>
                 </div>
             </div>
             <?php
@@ -112,14 +112,17 @@ function form()
             <div style="margin: 0px 0px 16px 25px;">You have chosen not to create any groups at this time.</div>
             <?php
         }
-    }// /->form()
+    }
+
+    // /->form()
 
-    function process_form()
+    public function process_form()
     {
         $errors = null;
         return $errors;
-    }// /->process_form()
+    }
 
+    // /->process_form()
 }// /class: WizardStep3
 
 ?>
diff --git a/src/tutors/groups/create/class_wizardstep_4.php b/src/tutors/groups/create/class_wizardstep_4.php
index c5e51b9..f308dd7 100644
--- a/src/tutors/groups/create/class_wizardstep_4.php
+++ b/src/tutors/groups/create/class_wizardstep_4.php
@@ -13,15 +13,13 @@
 
 class WizardStep4
 {
+    public $wizard;
 
-    public $wizard = null;
     public $step = 4;
 
     private $moduleId;
 
-    /*
-    * CONSTRUCTOR
-    */
+    // CONSTRUCTOR
     public function __construct(Wizard $wizard)
     {
         $this->wizard = $wizard;
@@ -31,25 +29,29 @@ public function __construct(Wizard $wizard)
         $this->wizard->back_button = null;
         $this->wizard->next_button = null;
         $this->wizard->cancel_button = null;
-    }// /WizardStep4()
+    }
 
-    function head()
+    // /WizardStep4()
+
+    public function head()
     {
         $html = <<<HTMLEnd
-<script language="JavaScript" type="text/javascript">
-<!--
+            <script language="JavaScript" type="text/javascript">
+            <!--
+
+              function body_onload() {
+              }// /body_onload()
 
-  function body_onload() {
-  }// /body_onload()
+            //-->
+            </script>
+            HTMLEnd;
 
-//-->
-</script>
-HTMLEnd;
+        echo $html;
+    }
 
-        echo($html);
-    }// /->head()
+    // /->head()
 
-    function form()
+    public function form()
     {
         $CIS = $this->wizard->get_var('CIS');
         $db = $this->wizard->get_var('db');
@@ -64,7 +66,7 @@ function form()
         // If the staff isn't allocated some of the modules given (hack-attempt), show error
 
         // Generate the names of the new groups
-        $num_groups = (int)$this->wizard->get_field('num_groups');
+        $num_groups = (int) $this->wizard->get_field('num_groups');
         if ($num_groups > 0) {
             $group_names = $group_handler->generate_group_names($num_groups, $this->wizard->get_field('group_name_stub'), $this->wizard->get_field('group_numbering'));
         }
@@ -77,8 +79,8 @@ function form()
         if (is_array($errors)) {
             $this->wizard->back_button = '&lt; Back';
             $this->wizard->cancel_button = 'Cancel';
-            echo('<p><strong>Unable to create your new collection of groups.</strong></p>');
-            echo('<p>To correct the problem, click <em>back</em> and amend the details entered.</p>');
+            echo '<p><strong>Unable to create your new collection of groups.</strong></p>';
+            echo '<p>To correct the problem, click <em>back</em> and amend the details entered.</p>';
         } else {// Else.. create the groups!
             if ($collection->save()) {
                 if ($num_groups > 0) {
@@ -88,26 +90,27 @@ function form()
                     }
                 }
             } else {
-                echo('<p><strong>An error occurred while trying to create your new collection of groups.</strong></p>');
-                echo('<p>You may be able to correct the problem by clicking <em>back</em>, and then <em>next</em> again.</p>');
-            }
-
-            ?>
+                echo '<p><strong>An error occurred while trying to create your new collection of groups.</strong></p>';
+                echo '<p>You may be able to correct the problem by clicking <em>back</em>, and then <em>next</em> again.</p>';
+            } ?>
             <p><strong>Your new groups have been created.</strong></p>
             <p style="margin-top: 20px;">To allocate students to your new groups, you can use the <a
-                        href="../edit/edit_collection.php?c=<?php echo($collection->id); ?>">group editor</a>.</p>
+                        href="../edit/edit_collection.php?c=<?php echo $collection->id; ?>">group editor</a>.</p>
             <p style="margin-top: 20px;">Alternatively, you can return to <a href="../">my groups</a>, or to the <a
                         href="../../index.php">WebPA home page</a>.</p>
             <?php
         }
-    }// /->form()
+    }
+
+    // /->form()
 
-    function process_form()
+    public function process_form()
     {
-        $this->wizard->_fields = array(); // kill the wizard's stored fields
+        $this->wizard->_fields = []; // kill the wizard's stored fields
         return null;
-    }// /->process_form()
+    }
 
+    // /->process_form()
 }// /class: WizardStep4
 
 ?>
diff --git a/src/tutors/groups/create/class_wizardstep_x.php b/src/tutors/groups/create/class_wizardstep_x.php
index e4b37b7..b621cb6 100644
--- a/src/tutors/groups/create/class_wizardstep_x.php
+++ b/src/tutors/groups/create/class_wizardstep_x.php
@@ -13,14 +13,13 @@
 
 class WizardStep2
 {
-    public $wizard = null;
+    public $wizard;
+
     public $step = 2;
 
     private $module;
 
-    /*
-    * CONSTRUCTOR
-    */
+    // CONSTRUCTOR
     public function __construct(Wizard $wizard)
     {
         $this->wizard = $wizard;
@@ -30,25 +29,29 @@ public function __construct(Wizard $wizard)
         $this->wizard->back_button = '&lt; Back';
         $this->wizard->next_button = 'Next &gt;';
         $this->wizard->cancel_button = 'Cancel';
-    }// /WizardStep2()
+    }
+
+    // /WizardStep2()
 
-    function head()
+    public function head()
     {
         $html = <<<HTMLEnd
-<script language="JavaScript" type="text/javascript">
-<!--
+            <script language="JavaScript" type="text/javascript">
+            <!--
+
+              function body_onload() {
+              }// /body_onload()
 
-  function body_onload() {
-  }// /body_onload()
+            //-->
+            </script>
+            HTMLEnd;
 
-//-->
-</script>
-HTMLEnd;
+        echo $html;
+    }
 
-        echo($html);
-    }// /->head()
+    // /->head()
 
-    function form()
+    public function form()
     {
         $CIS = $this->wizard->get_var('CIS');
         $user = $this->wizard->get_var('user');
@@ -66,14 +69,13 @@ function form()
             $this->wizard->next_button = null;
         } else {
             if ($module_select == 'multiple') {
-                echo('<p>You have opted to populate your groups with students chosen from multiple modules. Usually, groups need only contain students from a single module, but by selecting multiple modules your groups can contain a mixture of students from different modules.</p>');
-                echo('<p>The modules below are those you are associated with, as either a lead or additional tutor.</p>');
-                echo('<p>Select the modules to take students from by ticking the appropriate box:</p>');
+                echo '<p>You have opted to populate your groups with students chosen from multiple modules. Usually, groups need only contain students from a single module, but by selecting multiple modules your groups can contain a mixture of students from different modules.</p>';
+                echo '<p>The modules below are those you are associated with, as either a lead or additional tutor.</p>';
+                echo '<p>Select the modules to take students from by ticking the appropriate box:</p>';
             } else {
-                echo('<p>The modules below are those you are associated with, as either a lead or additional tutor.</p>');
-                echo('<p>Please select the module you want to take students from:</p>');
-            }
-            ?>
+                echo '<p>The modules below are those you are associated with, as either a lead or additional tutor.</p>';
+                echo '<p>Please select the module you want to take students from:</p>';
+            } ?>
             <h2>Your Modules</h2>
             <div class="form_section">
                 <table class="form" cellpadding="1" cellspacing="1">
@@ -81,25 +83,26 @@ function form()
                     if ($module_select == 'multiple') {
                         foreach ($modules as $i => $module) {
                             $checked_str = ((is_array($arr_module_id)) && (in_array($module['module_id'], $arr_module_id))) ? 'checked="checked"' : '';
-                            echo('<tr>');
-                            echo("<td><input type=\"checkbox\" name=\"module_id[]\" id=\"module_{$module['module_id']}\" value=\"{$module['module_id']}\" $checked_str /></td>");
-                            echo("<td><label style=\"font-weight: normal;\" for=\"module_{$module['module_id']}\">{$module['module_title']} [{$module['module_code']}]</label></td>");
-                            echo('</tr>');
+                            echo '<tr>';
+                            echo "<td><input type=\"checkbox\" name=\"module_id[]\" id=\"module_{$module['module_id']}\" value=\"{$module['module_id']}\" $checked_str /></td>";
+                            echo "<td><label style=\"font-weight: normal;\" for=\"module_{$module['module_id']}\">{$module['module_title']} [{$module['module_code']}]</label></td>";
+                            echo '</tr>';
                         }
                     } else {
-                        echo('<tr>');
-                        echo("<td><input type=\"radio\" name=\"module_id[]\" id=\"module_{$this->module['module_id']}\" value=\"{$this->module['module_id']}\" checked=\"checked\" /></td>");
-                        echo("<td><label style=\"font-weight: normal;\" for=\"module_{$this->module['module_id']}\">{$this->module['module_title']} [{$this->module['module_code']}]</label></td>");
-                        echo('</tr>');
-                    }
-                    ?>
+                        echo '<tr>';
+                        echo "<td><input type=\"radio\" name=\"module_id[]\" id=\"module_{$this->module['module_id']}\" value=\"{$this->module['module_id']}\" checked=\"checked\" /></td>";
+                        echo "<td><label style=\"font-weight: normal;\" for=\"module_{$this->module['module_id']}\">{$this->module['module_title']} [{$this->module['module_code']}]</label></td>";
+                        echo '</tr>';
+                    } ?>
                 </table>
             </div>
             <?php
         }
-    }// /->form()
+    }
+
+    // /->form()
 
-    function process_form()
+    public function process_form()
     {
         $errors = null;
 
@@ -109,8 +112,9 @@ function process_form()
         }
 
         return $errors;
-    }// /->process_form()
+    }
 
+    // /->process_form()
 }// /class: WizardStep2
 
 ?>
diff --git a/src/tutors/groups/create/index.php b/src/tutors/groups/create/index.php
index d81dfd6..b9808c7 100644
--- a/src/tutors/groups/create/index.php
+++ b/src/tutors/groups/create/index.php
@@ -8,14 +8,14 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\Wizard;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -24,15 +24,15 @@
 $wizard = new Wizard('create new groups wizard');
 $wizard->cancel_url = '../../../tutors/groups/';
 
-$wizard->add_step(1,'class_wizardstep_1.php');
-$wizard->add_step(2,'class_wizardstep_2.php');
-$wizard->add_step(3,'class_wizardstep_3.php');
-$wizard->add_step(4,'class_wizardstep_4.php');
+$wizard->add_step(1, 'class_wizardstep_1.php');
+$wizard->add_step(2, 'class_wizardstep_2.php');
+$wizard->add_step(3, 'class_wizardstep_3.php');
+$wizard->add_step(4, 'class_wizardstep_4.php');
 
-$wizard->set_var('CIS',$CIS);
+$wizard->set_var('CIS', $CIS);
 $wizard->set_var('db', $DB);
-$wizard->set_var('config',$_config);
-$wizard->set_var('user',$_user);
+$wizard->set_var('config', $_config);
+$wizard->set_var('user', $_user);
 $wizard->set_var('moduleId', $_module_id);
 
 $wizard->prepare();
@@ -48,11 +48,11 @@
 $UI->page_title = APP__NAME . ' Create new groups';
 $UI->menu_selected = 'my groups';
 $UI->help_link = '?q=node/253';
-$UI->breadcrumbs = array  (
-  'home'                      => '../../' ,
-  'my groups'                 => '../' ,
-  'create new groups wizard'  => null ,
-);
+$UI->breadcrumbs = [
+  'home'                      => '../../',
+  'my groups'                 => '../',
+  'create new groups wizard'  => null,
+];
 
 $UI->set_page_bar_button('List Groups', '../../../../images/buttons/button_group_list.gif', '../');
 $UI->set_page_bar_button('Create Groups', '../../../../images/buttons/button_group_create.gif', '../create/');
diff --git a/src/tutors/groups/edit/edit_collection.php b/src/tutors/groups/edit/edit_collection.php
index 9a78262..0e6a032 100644
--- a/src/tutors/groups/edit/edit_collection.php
+++ b/src/tutors/groups/edit/edit_collection.php
@@ -9,14 +9,14 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\GroupHandler;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -26,18 +26,18 @@
 
 $command = Common::fetch_POST('command', Common::fetch_GET('command'));
 
-$list_url = "../../../tutors/groups/";
+$list_url = '../../../tutors/groups/';
 
 // --------------------------------------------------------------------------------
 
 $group_handler = new GroupHandler();
 $collection = $group_handler->get_collection($collection_id);
 
-$allow_edit = FALSE;
+$allow_edit = false;
 
 if ($collection) {
-  // Check if the user can edit this group
-  $allow_edit = TRUE;
+    // Check if the user can edit this group
+    $allow_edit = true;
 }
 
 // --------------------------------------------------------------------------------
@@ -47,15 +47,15 @@
 
 $errors = null;
 
-if ( ($command) && ($collection) && ($allow_edit) ) {
-  switch ($command) {
+if (($command) && ($collection) && ($allow_edit)) {
+    switch ($command) {
     case 'save':
       $collection->name = Common::fetch_POST('collection_name');
       if (empty($collection->name)) {
-        $errors[] = 'You must give this collection of groups a name.';
+          $errors[] = 'You must give this collection of groups a name.';
       }
       if (!$errors) {
-        $collection->save();
+          $collection->save();
       }
       break;
     // --------------------
@@ -78,11 +78,11 @@
 $UI->page_title = APP__NAME . ' ' . $page_title;
 $UI->menu_selected = 'my groups';
 $UI->help_link = '?q=node/253';
-$UI->breadcrumbs = array  (
-  'home'        => '../../' ,
-  'my groups'     => '../' ,
-  $page_title     => null ,
-);
+$UI->breadcrumbs = [
+  'home'        => '../../',
+  'my groups'     => '../',
+  $page_title     => null,
+];
 
 $UI->set_page_bar_button('List Groups', '../../../../images/buttons/button_group_list.gif', '../');
 $UI->set_page_bar_button('Create Groups', '../../../../images/buttons/button_group_create.gif', '../create/');
@@ -126,16 +126,16 @@ function do_command(com) {
 
 <div class="content_box">
 
-<form action="edit_collection.php?<?php echo($collection_qs); ?>" method="post" name="collection_form">
+<form action="edit_collection.php?<?php echo $collection_qs; ?>" method="post" name="collection_form">
 <input type="hidden" name="command" value="none">
 
 <div class="nav_button_bar">
   <table cellpadding="0" cellspacing="0" width="100%">
   <tr>
-    <td><a href="<?php echo($list_url); ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to my groups</a></td>
+    <td><a href="<?php echo $list_url; ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to my groups</a></td>
 <?php
 if ($collection) {
-?>
+    ?>
     <td align="right"><input class="danger_button" type="button" name="" value="delete collection" onclick="do_command('delete');" /></td>
 <?php
 }
@@ -146,19 +146,18 @@ function do_command(com) {
 
 <?php
 if (!$collection) {
-?>
+    ?>
   <p>The collection you selected could not be loaded for some reason - please go back and try again.</p>
 <?php
 } else {
-  $collection_qs = "c={$collection->id}";
-?>
+        $collection_qs = "c={$collection->id}"; ?>
   <h2>Collection</h2>
   <div class="form_section form_line">
     <p>You can change the name of this collection of groups using the box below.</p>
     <table class="form" cellpadding="2" cellspacing="2">
     <tr>
       <th><label for="collection_name">Name</label></th>
-      <td><input type="text" name="collection_name" id="collection_name" maxlength="50" size="40" value="<?php echo($collection->name); ?>" /></td>
+      <td><input type="text" name="collection_name" id="collection_name" maxlength="50" size="40" value="<?php echo $collection->name; ?>" /></td>
       <td>
         <input type="button" name="savebutton" value="update name" onclick="do_command('save');" />
       </td>
@@ -170,59 +169,56 @@ function do_command(com) {
   <div class="form_section">
 <?php
   $num_module_students = $CIS->get_module_students_count($_module_id);
-  // Group Information
-  $groups_iterator =& $collection->get_groups_iterator();
-  $num_groups = $groups_iterator->size();
-  $num_groups_units = ($num_groups==1) ? 'group' : 'groups';
-
-  $collection_total_members = 0;
-  if ($num_groups==0) {
-    echo("<p>You do not have any groups in this collection. To use this collection you need to <a href=\"edit_collection_groups.php?$collection_qs\">add groups</a>.</p>");
-  } else {
-?>
+        // Group Information
+        $groups_iterator =& $collection->get_groups_iterator();
+        $num_groups = $groups_iterator->size();
+        $num_groups_units = ($num_groups==1) ? 'group' : 'groups';
+
+        $collection_total_members = 0;
+        if ($num_groups==0) {
+            echo "<p>You do not have any groups in this collection. To use this collection you need to <a href=\"edit_collection_groups.php?$collection_qs\">add groups</a>.</p>";
+        } else {
+            ?>
     <p>These are the groups contained in this collection.</p>
     <p>To edit an individual group and its members click on <img src="../../../images/buttons/edit.gif" width="16" height="16" alt="edit group" title="edit" /> in the list below.</p>
-    <div style="text-align: right;"><a class="button" href="edit_collection_members.php?<?php echo($collection_qs); ?>">assign all students to groups</a> &nbsp; &nbsp; <a class="button" href="edit_collection_groups.php?<?php echo($collection_qs); ?>">add/remove groups</a></div>
+    <div style="text-align: right;"><a class="button" href="edit_collection_members.php?<?php echo $collection_qs; ?>">assign all students to groups</a> &nbsp; &nbsp; <a class="button" href="edit_collection_groups.php?<?php echo $collection_qs; ?>">add/remove groups</a></div>
 
     <div class="obj_list">
 <?php
-    for($groups_iterator->reset(); $groups_iterator->is_valid(); $groups_iterator->next() ) {
-      $group = $groups_iterator->current();
-      $num_members = count($group->get_members());
-      $num_members_units = ($num_members==1) ? 'member' : 'members';
-      $collection_total_members += $num_members;
+    for ($groups_iterator->reset(); $groups_iterator->is_valid(); $groups_iterator->next()) {
+        $group = $groups_iterator->current();
+        $num_members = count($group->get_members());
+        $num_members_units = ($num_members==1) ? 'member' : 'members';
+        $collection_total_members += $num_members;
 
-      $edit_url = "edit_group.php?c={$collection->id}&g={$group->id}";
-?>
+        $edit_url = "edit_group.php?c={$collection->id}&g={$group->id}"; ?>
       <div class="obj">
         <table class="obj" cellpadding="2" cellspacing="2">
         <tr>
-          <td width="24"><a class="text" href="<?php echo($edit_url); ?>"><img src="../../../images/icons/groups.gif" alt="Groups" height="24" width="24" /></a></td>
+          <td width="24"><a class="text" href="<?php echo $edit_url; ?>"><img src="../../../images/icons/groups.gif" alt="Groups" height="24" width="24" /></a></td>
           <td class="obj_info">
-            <div class="obj_name"><a class="text" href="<?php echo($edit_url); ?>"><?php echo($group->name); ?></a></div>
-            <div class="obj_info_text">Contains <?php echo("$num_members $num_members_units"); ?></div>
+            <div class="obj_name"><a class="text" href="<?php echo $edit_url; ?>"><?php echo $group->name; ?></a></div>
+            <div class="obj_info_text">Contains <?php echo "$num_members $num_members_units"; ?></div>
           </td>
           <td class="buttons">
-            <a href="<?php echo($edit_url); ?>"><img src="../../../images/buttons/edit.gif" width="16" height="16" alt="edit group" title="edit" /></a>
+            <a href="<?php echo $edit_url; ?>"><img src="../../../images/buttons/edit.gif" width="16" height="16" alt="edit group" title="edit" /></a>
           </td>
         </tr>
         </table>
       </div>
 <?php
-    }
-?>
+    } ?>
     </div>
 <?php
     $num_module_students_units = ($num_module_students==1) ? 'student' : 'students';
-    $num_members_units = ($collection_total_members==1) ? 'member' : 'members';
+            $num_members_units = ($collection_total_members==1) ? 'member' : 'members';
 
-    echo("<p>There are $num_groups $num_groups_units, containing $collection_total_members $num_members_units (out of a possible $num_module_students $num_module_students_units).</p>");
-  }
-?>
+            echo "<p>There are $num_groups $num_groups_units, containing $collection_total_members $num_members_units (out of a possible $num_module_students $num_module_students_units).</p>";
+        } ?>
   </div>
 
 <?php
-}
+    }
 ?>
   </form>
 </div>
diff --git a/src/tutors/groups/edit/edit_collection_groups.php b/src/tutors/groups/edit/edit_collection_groups.php
index a2e164a..69b0144 100644
--- a/src/tutors/groups/edit/edit_collection_groups.php
+++ b/src/tutors/groups/edit/edit_collection_groups.php
@@ -8,14 +8,14 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\GroupHandler;
 use WebPA\includes\functions\Common;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -35,8 +35,8 @@
 $allow_edit = false;
 
 if ($collection) {
-  // Check if the user can edit this group
-  $allow_edit = !$collection->is_locked();
+    // Check if the user can edit this group
+    $allow_edit = !$collection->is_locked();
 }
 
 // --------------------------------------------------------------------------------
@@ -45,26 +45,28 @@
 $errors = null;
 
 if ($allow_edit) {
-  switch ($command) {
+    switch ($command) {
     case 'add':
       $new_name = Common::fetch_POST('new_group_name');
-      if (empty($new_name)) { $errors[] = 'You must give your new group a name'; }
+      if (empty($new_name)) {
+          $errors[] = 'You must give your new group a name';
+      }
 
       if (!$errors) {
-        $new_group = $collection->new_group($new_name);
-        $new_group->save();
+          $new_group = $collection->new_group($new_name);
+          $new_group->save();
       }
       break;
     // --------------------
     case 'delete':
       $groups_to_delete = Common::fetch_POST('group');
       if (is_array($groups_to_delete)) {
-        foreach($groups_to_delete as $i => $group_id) {
-          $group =& $collection->get_group_object($group_id);
-          $group->delete();
-          unset($group);
-        }
-        $collection->refresh_groups();
+          foreach ($groups_to_delete as $i => $group_id) {
+              $group =& $collection->get_group_object($group_id);
+              $group->delete();
+              unset($group);
+          }
+          $collection->refresh_groups();
       }
       break;
   }// /switch
@@ -80,11 +82,11 @@
 $UI->page_title = APP__NAME . ' ' . $page_title;
 $UI->menu_selected = 'my groups';
 $UI->help_link = '?q=node/253';
-$UI->breadcrumbs = array  ( 'home' => '../../' ,
-                'my groups' => '../' ,
-                "Editing: $collection_name" => "../edit/edit_collection.php?c={$collection->id}" ,
-                $page_title                 => null ,
-);
+$UI->breadcrumbs = ['home' => '../../',
+                'my groups' => '../',
+                "Editing: $collection_name" => "../edit/edit_collection.php?c={$collection->id}",
+                $page_title                 => null,
+];
 
 $UI->set_page_bar_button('List Groups', '../../../../images/buttons/button_group_list.gif', '../');
 $UI->set_page_bar_button('Create Groups', '../../../../images/buttons/button_group_create.gif', '../create/');
@@ -113,25 +115,24 @@ function do_command(com) {
 <div class="content_box">
 
 <div class="nav_button_bar">
-  <a href="<?php echo($collection_url); ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to <?php echo($collection_name); ?></a>
+  <a href="<?php echo $collection_url; ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to <?php echo $collection_name; ?></a>
 </div>
 
 <?php
 if (!$collection) {
-?>
+    ?>
   <p>The collection you selected could not be loaded for some reason - please go back and try again.</p>
 <?php
 } else {
-  if ($collection->is_locked()) {
-    echo("<p>This collection has been locked and cannot be edited.</p>");
-  } else {
-    echo("<p>On this page you can choose which modules to associate with this collection.</p>");
-  }
+        if ($collection->is_locked()) {
+            echo '<p>This collection has been locked and cannot be edited.</p>';
+        } else {
+            echo '<p>On this page you can choose which modules to associate with this collection.</p>';
+        }
 
-  $collection_qs = "c={$collection->id}";
-?>
+        $collection_qs = "c={$collection->id}"; ?>
 
-  <form action="edit_collection_groups.php?<?php echo($collection_qs); ?>" method="post" name="collection_groups_form">
+  <form action="edit_collection_groups.php?<?php echo $collection_qs; ?>" method="post" name="collection_groups_form">
   <input type="hidden" name="command" value="add" />
 
   <h2>New Group</h2>
@@ -160,25 +161,24 @@ function do_command(com) {
   // Show all the groups contained in this collection
   $groups = $collection->get_groups_array();
 
-  if (is_array($groups)) {
-    foreach($groups as $i => $group) {
-      $group_qs = "{$collection_qs}&g={$group['group_id']}";
-      echo('<tr>');
-      echo("<td><a href=\"edit_group.php?$group_qs\">{$group['group_name']}</a></td>");
-      echo("<td align=\"center\"><input type=\"checkbox\" name=\"group[]\" id=\"group_{$group['group_id']}\" value=\"{$group['group_id']}\" /></td>");
-      echo('</tr>');
-    }
-    if ($allow_edit) {?>
+        if (is_array($groups)) {
+            foreach ($groups as $i => $group) {
+                $group_qs = "{$collection_qs}&g={$group['group_id']}";
+                echo '<tr>';
+                echo "<td><a href=\"edit_group.php?$group_qs\">{$group['group_name']}</a></td>";
+                echo "<td align=\"center\"><input type=\"checkbox\" name=\"group[]\" id=\"group_{$group['group_id']}\" value=\"{$group['group_id']}\" /></td>";
+                echo '</tr>';
+            }
+            if ($allow_edit) {?>
       <tr>
         <th>&nbsp;</th>
         <th><input type="button" name="deletebutton" id="deletebutton" value="delete" onclick="do_command('delete');" /></th>
       </tr>
       <?php
     }
-  } else {
-    echo('<tr class="in_collection"><td colspan="3">This collection does not contain any groups</td></tr>');
-  }
-?>
+        } else {
+            echo '<tr class="in_collection"><td colspan="3">This collection does not contain any groups</td></tr>';
+        } ?>
     </table>
       <td valign="bottom">
       </td>
@@ -188,7 +188,7 @@ function do_command(com) {
 
   </form>
 <?php
-}
+    }
 ?>
 </div>
 
diff --git a/src/tutors/groups/edit/edit_collection_members.php b/src/tutors/groups/edit/edit_collection_members.php
index f47030d..37af5a8 100644
--- a/src/tutors/groups/edit/edit_collection_members.php
+++ b/src/tutors/groups/edit/edit_collection_members.php
@@ -8,16 +8,16 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\GroupHandler;
 use WebPA\includes\functions\ArrayFunctions;
 use WebPA\includes\functions\Common;
 use WebPA\includes\functions\Form;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -38,8 +38,8 @@
 $allow_edit = false;
 
 if ($collection) {
-  // Check if the user can edit this group
-  $allow_edit = !$collection->is_locked();
+    // Check if the user can edit this group
+    $allow_edit = !$collection->is_locked();
 }
 
 // --------------------------------------------------------------------------------
@@ -48,17 +48,17 @@
 $errors = null;
 
 if ($allow_edit) {
-  switch ($command) {
+    switch ($command) {
     case 'save':
       // Delete all the members with the 'member' role
       $collection->purge_members('member');
 
       // Add the members who should be in a group
       foreach ($_POST as $k => $v) {
-        if ( (strpos($k,'student_')!==false) && (strlen($v)==36) ) {
-          $group =& $collection->get_group_object($v);
-          $group->add_member(str_replace('student_', '', $k), 'member');
-        }
+          if ((strpos($k, 'student_')!==false) && (strlen($v)==36)) {
+              $group =& $collection->get_group_object($v);
+              $group->add_member(str_replace('student_', '', $k), 'member');
+          }
       }
       $collection->save_groups();
 
@@ -82,12 +82,12 @@
 $UI->page_title = APP__NAME . ' ' . $page_title;
 $UI->menu_selected = 'my groups';
 $UI->help_link = '?q=node/253';
-$UI->breadcrumbs = array  (
-  'home' => '../../' ,
-  'my groups' => '../' ,
-  "Editing: $collection_title"  => "../edit/edit_collection.php?gs={$collection->id}" ,
-  $page_title           => null ,
-);
+$UI->breadcrumbs = [
+  'home' => '../../',
+  'my groups' => '../',
+  "Editing: $collection_title"  => "../edit/edit_collection.php?gs={$collection->id}",
+  $page_title           => null,
+];
 
 $UI->set_page_bar_button('List Groups', '../../../../images/buttons/button_group_list.gif', '../');
 $UI->set_page_bar_button('Create Groups', '../../../../images/buttons/button_group_create.gif', '../create/');
@@ -116,18 +116,18 @@ function do_command(com) {
 <div class="content_box">
 
 <div class="nav_button_bar">
-  <a href="<?php echo($collection_url); ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to <?php echo($collection_name); ?></a>
+  <a href="<?php echo $collection_url; ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to <?php echo $collection_name; ?></a>
 </div>
 
 <?php
 if (!$collection) {
-  ?>
+    ?>
   <p>The collection you selected could not be loaded for some reason - please go back and try again.</p>
 <?php
 } else {
-?>
+        ?>
 
-  <form action="edit_collection_members.php?<?php echo($collection_qs); ?>" method="post" name="collection_members_form">
+  <form action="edit_collection_members.php?<?php echo $collection_qs; ?>" method="post" name="collection_members_form">
   <input type="hidden" name="command" value="none" />
 
   <h2>Available Students</h2>
@@ -147,37 +147,36 @@ function do_command(com) {
       </tr>
 <?php
     $groups = $collection->get_groups_array();
-    $options[''] = ' - - - - ';
-    foreach($groups as $group) {
-      $options["{$group['group_id']}"] = $group['group_name'];
-    }
-
-    // Get all the possible student members
-    $module_students = $CIS->get_module_students($_module_id,'name');
-
-    // Get collection members
-    $collection_member_rows = $collection->get_member_rows();
+        $options[''] = ' - - - - ';
+        foreach ($groups as $group) {
+            $options["{$group['group_id']}"] = $group['group_name'];
+        }
 
-    if (is_array($module_students)) {
-      foreach($module_students as $i => $member) {
-        $assigned_group = ArrayFunctions::array_searchvalue($member['user_id'], $collection_member_rows, 'user_id', 'group_id');
-        echo('<tr>');
-        echo("<td>{$member['lastname']}, {$member['forename']} (");
-        if (!empty($member['id_number'])) {
-          echo($member['id_number']);
+        // Get all the possible student members
+        $module_students = $CIS->get_module_students($_module_id, 'name');
+
+        // Get collection members
+        $collection_member_rows = $collection->get_member_rows();
+
+        if (is_array($module_students)) {
+            foreach ($module_students as $i => $member) {
+                $assigned_group = ArrayFunctions::array_searchvalue($member['user_id'], $collection_member_rows, 'user_id', 'group_id');
+                echo '<tr>';
+                echo "<td>{$member['lastname']}, {$member['forename']} (";
+                if (!empty($member['id_number'])) {
+                    echo $member['id_number'];
+                } else {
+                    echo $member['username'];
+                }
+                echo ')</td>';
+                echo "<td><select name=\"student_{$member['user_id']}\">";
+                Form::render_options($options, $assigned_group);
+                echo '</select></td>';
+                echo '</tr>';
+            }
         } else {
-          echo($member['username']);
-        }
-        echo(')</td>');
-        echo("<td><select name=\"student_{$member['user_id']}\">");
-        Form::render_options($options, $assigned_group);
-        echo('</select></td>');
-        echo('</tr>');
-      }
-    } else {
-      echo('<tr><td colspan="2">No students available</td></tr>');
-    }
-?>
+            echo '<tr><td colspan="2">No students available</td></tr>';
+        } ?>
       </table>
 
       </td>
@@ -196,8 +195,7 @@ function do_command(com) {
           <input type="button" name="savebutton2" id="savebutton2" value="save changes" onclick="do_command('save');" />
         </div>
 <?php
-  }
-?>
+  } ?>
       </td>
     </tr>
     </table>
@@ -205,7 +203,7 @@ function do_command(com) {
 
   </form>
 <?php
-}
+    }
 ?>
 </div>
 
diff --git a/src/tutors/groups/edit/edit_group.php b/src/tutors/groups/edit/edit_group.php
index c22741f..7959eb3 100644
--- a/src/tutors/groups/edit/edit_group.php
+++ b/src/tutors/groups/edit/edit_group.php
@@ -9,16 +9,16 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\GroupHandler;
 use WebPA\includes\functions\Common;
 use WebPA\lang\en\Generic;
 use WebPA\lang\en\tutors\Tutors;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -39,14 +39,14 @@
 $allow_edit = false;
 
 if ($collection) {
-  $group =& $collection->get_group_object($group_id);
+    $group =& $collection->get_group_object($group_id);
 
-  // Check if the user can edit this group
-  $allow_edit = !$collection->is_locked();
-  $collection_qs = "c={$collection->id}";
+    // Check if the user can edit this group
+    $allow_edit = !$collection->is_locked();
+    $collection_qs = "c={$collection->id}";
 } else {
-  $group = null;
-  $collection_qs = '';
+    $group = null;
+    $collection_qs = '';
 }
 
 // --------------------------------------------------------------------------------
@@ -55,27 +55,29 @@
 $errors = null;
 
 if ($allow_edit) {
-  switch ($command) {
+    switch ($command) {
     case 'save':
       // Change of name
       $group->name = Common::fetch_POST('group_name');
-      if (empty($group->name)) { $errors[] = Tutors::GROUPS__EDIT_SAVE_ERR; }
+      if (empty($group->name)) {
+          $errors[] = Tutors::GROUPS__EDIT_SAVE_ERR;
+      }
 
       // Delete all the members with the 'member' role
       $group->purge_members('member');
 
       // Add the members who should be IN the group
       foreach ($_POST as $k => $v) {
-        $s = strpos($k,'student_');
-        if ( ($s !== false) && ((int) $v == 1) ) {
-          $s_id = str_replace('student_', '', $k);
-          $group->add_member($s_id, 'member');
-        }
+          $s = strpos($k, 'student_');
+          if (($s !== false) && ((int) $v == 1)) {
+              $s_id = str_replace('student_', '', $k);
+              $group->add_member($s_id, 'member');
+          }
       }
 
       // If there were no errors, save the changes
       if (!$errors) {
-        $group->save();
+          $group->save();
       }
 
       break;
@@ -98,12 +100,12 @@
 $UI->page_title = APP__NAME . ' ' . $page_title;
 $UI->menu_selected = 'my groups';
 $UI->help_link = '?q=node/253';
-$UI->breadcrumbs = array  (
-  'home'            => '../../' ,
-  'my groups'         => '../' ,
-  "Editing: $collection_name" => "edit_collection.php?c={$collection->id}" ,
-  $page_title         => null ,
-);
+$UI->breadcrumbs = [
+  'home'            => '../../',
+  'my groups'         => '../',
+  "Editing: $collection_name" => "edit_collection.php?c={$collection->id}",
+  $page_title         => null,
+];
 
 $UI->set_page_bar_button(Generic::BTN__LIST_GROUPS, '../../../../images/buttons/button_group_list.gif', '../');
 $UI->set_page_bar_button(Generic::BTN__CREATE_GROUPS, '../../../../images/buttons/button_group_create.gif', '../create/');
@@ -145,26 +147,25 @@ function do_command(com) {
 $UI->draw_boxed_list($errors, 'error_box', Generic::FOLLOWING__FOUND, Generic::NO_CHANGES);
 
 if ($collection->is_locked()) {
-  echo(Tutors::COLLECTION__LOCKED);
+    echo Tutors::COLLECTION__LOCKED;
 } else {
-  echo(Tutors::GROUPS__EDIT_INST);
+    echo Tutors::GROUPS__EDIT_INST;
 }
 ?>
 
 <div class="content_box">
 
 <div class="nav_button_bar">
-  <a href="<?php echo($collection_url); ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to <?php echo($collection_name); ?></a>
+  <a href="<?php echo $collection_url; ?>"><img src="../../../images/buttons/arrow_green_left.gif" alt="back -"> back to <?php echo $collection_name; ?></a>
 </div>
 
 <?php
 if (!$group) {
-  echo Tutors::GROUP__SELECTED;
+    echo Tutors::GROUP__SELECTED;
 } else {
-  $group_qs = "{$collection_qs}&g={$group->id}";
-?>
+    $group_qs = "{$collection_qs}&g={$group->id}"; ?>
 
-  <form action="edit_group.php?<?php echo($group_qs); ?>" method="post" name="group_form">
+  <form action="edit_group.php?<?php echo $group_qs; ?>" method="post" name="group_form">
   <input type="hidden" name="command" value="none" />
 
   <h2>Group Name</h2>
@@ -176,11 +177,10 @@ function do_command(com) {
       <td>
 <?php
   if ($collection->is_locked()) {
-    echo($group->name);
+      echo $group->name;
   } else {
-    echo("<input type=\"text\" name=\"group_name\" id=\"group_name\" maxlength=\"50\" size=\"40\" value=\"{$group->name}\" />");
-  }
-?>
+      echo "<input type=\"text\" name=\"group_name\" id=\"group_name\" maxlength=\"50\" size=\"40\" value=\"{$group->name}\" />";
+  } ?>
       </td>
     </tr>
     </table>
@@ -201,115 +201,112 @@ function do_command(com) {
       <table class="grid" cellpadding="2" cellspacing="1">
 <?php
   // Get all the possible student members
-  $module_user_ids = (array) $CIS->get_module_students_user_id($_module_id);
-
-  // Get all the students who are allocated to some group in this collection
-  $collection_member_ids = array_keys( (array) $collection->get_members('member'));
-
-  // Show the students who are IN this group
-  $group_student_ids = array_keys( (array) $group->get_members() );
-
-  $group_students = $CIS->get_user($group_student_ids);
-
-  echo('<tr class="in_group"><th width="400">Students already in this group</th><th align="center" width="50">In</th><th align="center" width="50">Out</th></tr>');
-  if (is_array($group_students)) {
-    foreach ($group_students as $i => $member) {
-      echo('<tr class="in_group">');
-      echo("<td>{$member['lastname']}, {$member['forename']} (");
-      if (!empty($member['id_number'])) {
-        echo($member['id_number']);
-      } else {
-        echo($member['username']);
-      }
-      echo(')</td>');
-      echo("<td class=\"radio\"><input type=\"radio\" name=\"student_{$member['user_id']}\" id=\"{$member['user_id']}_in\" value=\"1\" checked=\"checked\" /></td>");
-      echo("<td class=\"radio\"><input type=\"radio\" name=\"student_{$member['user_id']}\" id=\"{$member['user_id']}_out\" value=\"0\" /></td>");
-      echo('</tr>');
+  $module_user_ids = (array) $CIS->get_module_students_user_id([$_module_id]);
+
+    // Get all the students who are allocated to some group in this collection
+    $collection_member_ids = array_keys((array) $collection->get_members('member'));
+
+    // Show the students who are IN this group
+    $group_student_ids = array_keys((array) $group->get_members());
+
+    $group_students = $CIS->get_user($group_student_ids);
+
+    echo '<tr class="in_group"><th width="400">Students already in this group</th><th align="center" width="50">In</th><th align="center" width="50">Out</th></tr>';
+    if (is_array($group_students)) {
+        foreach ($group_students as $i => $member) {
+            echo '<tr class="in_group">';
+            echo "<td>{$member['lastname']}, {$member['forename']} (";
+            if (!empty($member['id_number'])) {
+                echo $member['id_number'];
+            } else {
+                echo $member['username'];
+            }
+            echo ')</td>';
+            echo "<td class=\"radio\"><input type=\"radio\" name=\"student_{$member['user_id']}\" id=\"{$member['user_id']}_in\" value=\"1\" checked=\"checked\" /></td>";
+            echo "<td class=\"radio\"><input type=\"radio\" name=\"student_{$member['user_id']}\" id=\"{$member['user_id']}_out\" value=\"0\" /></td>";
+            echo '</tr>';
+        }
+    } else {
+        echo '<tr class="in_group"><td colspan="3">This group has no members</td></tr>';
     }
-  } else {
-    echo('<tr class="in_group"><td colspan="3">This group has no members</td></tr>');
-  }
 
-  // Show the students who aren't in ANY group in this collection
-  if ((is_array($module_user_ids)) && (is_array($collection_member_ids))) {
-    $unalloc_student_ids = array_diff($module_user_ids, $collection_member_ids);
-  } else {
-    $unalloc_student_ids = $module_user_ids;
-  }
-  $unalloc_students = $CIS->get_user($unalloc_student_ids);
-
-  echo('<tr class="no_group"><th>Students not yet assigned to a group</th><th align="center" width="50">In</th><th align="center" width="50">Out</th></tr>');
-  if (is_array($unalloc_students)) {
-    foreach ($unalloc_students as $i => $member) {
-      echo('<tr class="no_group">');
-      echo("<td>{$member['lastname']}, {$member['forename']} (");
-      if (!empty($member['id_number'])) {
-        echo($member['id_number']);
-      } else {
-        echo($member['username']);
-      }
-      echo(')</td>');
-      echo("<td class=\"radio\"><input type=\"radio\" name=\"student_{$member['user_id']}\" id=\"{$member['user_id']}_in\" value=\"1\" /></td>");
-      echo("<td class=\"radio\"><input type=\"radio\" name=\"student_{$member['user_id']}\" id=\"{$member['user_id']}_out\" value=\"0\" checked=\"checked\" /></td>");
-      echo('</tr>');
+    // Show the students who aren't in ANY group in this collection
+    if ((is_array($module_user_ids)) && (is_array($collection_member_ids))) {
+        $unalloc_student_ids = array_diff($module_user_ids, $collection_member_ids);
+    } else {
+        $unalloc_student_ids = $module_user_ids;
+    }
+    $unalloc_students = $CIS->get_user($unalloc_student_ids);
+
+    echo '<tr class="no_group"><th>Students not yet assigned to a group</th><th align="center" width="50">In</th><th align="center" width="50">Out</th></tr>';
+    if (is_array($unalloc_students)) {
+        foreach ($unalloc_students as $i => $member) {
+            echo '<tr class="no_group">';
+            echo "<td>{$member['lastname']}, {$member['forename']} (";
+            if (!empty($member['id_number'])) {
+                echo $member['id_number'];
+            } else {
+                echo $member['username'];
+            }
+            echo ')</td>';
+            echo "<td class=\"radio\"><input type=\"radio\" name=\"student_{$member['user_id']}\" id=\"{$member['user_id']}_in\" value=\"1\" /></td>";
+            echo "<td class=\"radio\"><input type=\"radio\" name=\"student_{$member['user_id']}\" id=\"{$member['user_id']}_out\" value=\"0\" checked=\"checked\" /></td>";
+            echo '</tr>';
+        }
+    } else {
+        echo '<tr class="no_group"><td colspan="3">All the available students have been assigned</td></tr>';
     }
-  } else {
-    echo('<tr class="no_group"><td colspan="3">All the available students have been assigned</td></tr>');
-  }
 
-  // Show the students who are in OTHER groups in this collection
-  if ((is_array($group_student_ids)) && (is_array($collection_member_ids))) {
-    $collection_member_ids = array_diff($collection_member_ids, $group_student_ids);
-  } else {
-    $collection_member_ids = (array) $collection_member_ids;
-  }
-  $collection_students = $CIS->get_user($collection_member_ids);
-
-  echo('<tr class="other_group"><th>Students assigned to other groups in this collection</th><th align="center" width="50">In</th><th align="center" width="50">Out</th></tr>');
-  if (is_array($collection_students)) {
-    foreach ($collection_students as $i => $member) {
-      echo('<tr class="other_group">');
-      echo("<td>{$member['lastname']}, {$member['forename']} (");
-      if (!empty($member['id_number'])) {
-        echo($member['id_number']);
-      } else {
-        echo($member['username']);
-      }
-      echo(')</td>');
-      echo("<td class=\"radio\"><input type=\"radio\" name=\"student_{$member['user_id']}\" id=\"{$member['user_id']}_in\" value=\"1\" /></td>");
-      echo("<td class=\"radio\"><input type=\"radio\" name=\"student_{$member['user_id']}\" id=\"{$member['user_id']}_out\" value=\"0\" checked=\"checked\" /></td>");
-      echo('</tr>');
+    // Show the students who are in OTHER groups in this collection
+    if ((is_array($group_student_ids)) && (is_array($collection_member_ids))) {
+        $collection_member_ids = array_diff($collection_member_ids, $group_student_ids);
+    } else {
+        $collection_member_ids = (array) $collection_member_ids;
     }
-  } else {
-    echo('<tr class="other_group"><td colspan="3">There are no students allocated to any other groups</td></tr>');
-  }
-?>
+    $collection_students = $CIS->get_user($collection_member_ids);
+
+    echo '<tr class="other_group"><th>Students assigned to other groups in this collection</th><th align="center" width="50">In</th><th align="center" width="50">Out</th></tr>';
+    if (is_array($collection_students)) {
+        foreach ($collection_students as $i => $member) {
+            echo '<tr class="other_group">';
+            echo "<td>{$member['lastname']}, {$member['forename']} (";
+            if (!empty($member['id_number'])) {
+                echo $member['id_number'];
+            } else {
+                echo $member['username'];
+            }
+            echo ')</td>';
+            echo "<td class=\"radio\"><input type=\"radio\" name=\"student_{$member['user_id']}\" id=\"{$member['user_id']}_in\" value=\"1\" /></td>";
+            echo "<td class=\"radio\"><input type=\"radio\" name=\"student_{$member['user_id']}\" id=\"{$member['user_id']}_out\" value=\"0\" checked=\"checked\" /></td>";
+            echo '</tr>';
+        }
+    } else {
+        echo '<tr class="other_group"><td colspan="3">There are no students allocated to any other groups</td></tr>';
+    } ?>
       </table>
 
       </td>
       <td valign="top">
 <?php
   if ($allow_edit) {
-?>
+      ?>
         <div class="button_bar">
           <input type="button" name="savebutton1" id="savebutton1" value="<?php echo Generic::BTN__SAVE_CHANGES; ?>" onclick="do_command('save');" />
         </div>
 <?php
-  }
-?>
+  } ?>
       </td>
     </tr>
     <tr>
       <td valign="bottom">
 <?php
   if ($allow_edit) {
-?>
+      ?>
         <div class="button_bar">
           <input type="button" name="savebutton2" id="savebutton2" value="<?php echo Generic::BTN__SAVE_CHANGES; ?>" onclick="do_command('save');" />
         </div>
 <?php
-  }
-?>
+  } ?>
       </td>
     </tr>
     </table>
@@ -324,4 +321,3 @@ function do_command(com) {
 <?php
 
 $UI->content_end();
-
diff --git a/src/tutors/groups/edit/index.php b/src/tutors/groups/edit/index.php
index 13dc8ca..636ca0d 100644
--- a/src/tutors/groups/edit/index.php
+++ b/src/tutors/groups/edit/index.php
@@ -9,7 +9,7 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../../includes/inc_global.php");
+require_once '../../../includes/inc_global.php';
 
 use WebPA\includes\classes\GroupHandler;
 use WebPA\includes\classes\SimpleObjectIterator;
@@ -17,15 +17,15 @@
 use WebPA\lang\en\Generic;
 use WebPA\lang\en\tutors\Tutors;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
 
 $group_handler = new GroupHandler();
-$collections = $group_handler->get_user_collections($_user->id, $_config['app_id']);
+$collections = $group_handler->get_user_collections($_user->id);
 
 // --------------------------------------------------------------------------------
 // Begin Page
@@ -33,11 +33,11 @@
 $UI->page_title = APP__NAME. ' ' . Generic::EDIT__GROUP;;
 $UI->menu_selected = Generic::MY__GROUPS;
 $UI->help_link = '?q=node/253';
-$UI->breadcrumbs = array  (
-  'home'      => '/' ,
-  'my groups'   => '/groups/' ,
-  'edit groups' => null ,
-);
+$UI->breadcrumbs = [
+  'home'      => '/',
+  'my groups'   => '/groups/',
+  'edit groups' => null,
+];
 
 $UI->set_page_bar_button(Generic::BTN__LIST_GROUPS, '../../../../images/buttons/button_group_list.gif', '../');
 $UI->set_page_bar_button(Generic::BTN__CREATE_GROUPS, '../../../../images/buttons/button_group_create.gif', '../create/');
@@ -79,24 +79,24 @@
 <div class="form_section">
 <?php
 if (!$collections) {
-  echo('<p>'. Tutors::NO_COLLECTIONS .'</p>');
+    echo '<p>'. Tutors::NO_COLLECTIONS .'</p>';
 } else {
-  $collection_iterator = new SimpleObjectIterator($collections, 'GroupCollection', $DB);
+    $collection_iterator = new SimpleObjectIterator($collections, 'GroupCollection', $DB);
 
-  echo '<p>' . Tutors::GROUPS__EDIT_INST . '</p>';
+    echo '<p>' . Tutors::GROUPS__EDIT_INST . '</p>';
 
-  $any_locks = false;
-  for($collection_iterator->reset(); $collection_iterator->is_valid(); $collection_iterator->next() ) {
-    $collection = $collection_iterator->current();
+    $any_locks = false;
+    for ($collection_iterator->reset(); $collection_iterator->is_valid(); $collection_iterator->next()) {
+        $collection = $collection_iterator->current();
 
-    $group_count = count($collection->get_groups_array());
-    $modules = (is_array($collection->get_modules())) ? implode(', ',$collection->get_modules()) : 'none' ;
+        $group_count = count($collection->get_groups_array());
+        $modules = (is_array($collection->get_modules())) ? implode(', ', $collection->get_modules()) : 'none' ;
 
-    echo('<div class="collection">');
-    echo("  <div><a href=\"edit_collection.php?c={$collection->id}\">{$collection->name}</a></div>");
-    echo("  <div class=\"collection_info\"><div><strong>" . ASSOCIATED__MODULES . ":</strong> $modules</div><div><strong>" . Generic::NO__GROUPS . " :</strong> $group_count</div></div>");
-    echo('</div>');
-  }
+        echo '<div class="collection">';
+        echo "  <div><a href=\"edit_collection.php?c={$collection->id}\">{$collection->name}</a></div>";
+        echo '  <div class="collection_info"><div><strong>' . ASSOCIATED__MODULES . ":</strong> $modules</div><div><strong>" . Generic::NO__GROUPS . " :</strong> $group_count</div></div>";
+        echo '</div>';
+    }
 }
 ?>
 </div>
diff --git a/src/tutors/groups/index.php b/src/tutors/groups/index.php
index 8df2f0f..dab44db 100644
--- a/src/tutors/groups/index.php
+++ b/src/tutors/groups/index.php
@@ -8,7 +8,7 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../../includes/inc_global.php");
+require_once '../../includes/inc_global.php';
 
 use WebPA\includes\classes\GroupHandler;
 use WebPA\includes\classes\SimpleObjectIterator;
@@ -16,9 +16,9 @@
 use WebPA\lang\en\Generic;
 use WebPA\lang\en\tutors\Tutors;
 
-if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)){
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -32,10 +32,10 @@
 $UI->page_title = APP__NAME. ' ' . Generic::MY__GROUPS;;
 $UI->menu_selected = Generic::MY__GROUPS;
 $UI->help_link = '?q=node/253';
-$UI->breadcrumbs = array  (
-  'home'        => '../../' ,
-  'my groups'   => '../' ,
-);
+$UI->breadcrumbs = [
+  'home'        => '../../',
+  'my groups'   => '../',
+];
 
 $UI->set_page_bar_button(Generic::BTN__LIST_GROUPS, '../../../images/buttons/button_group_list.gif', '');
 $UI->set_page_bar_button(Generic::BTN__CREATE_GROUPS, '../../../images/buttons/button_group_create.gif', 'create/');
@@ -53,10 +53,9 @@
 <div class="form_section">
 <?php
 if (!$collections) {
-  echo('<p>' . Tutors::NO__GROUPS__DESC . '</p>');
+    echo '<p>' . Tutors::NO__GROUPS__DESC . '</p>';
 } else {
-  $collection_iterator = new SimpleObjectIterator($collections, 'GroupCollection', $DB);
-?>
+    $collection_iterator = new SimpleObjectIterator($collections, 'GroupCollection', $DB); ?>
     <p><?php echo Tutors::GROUPS__INSTRUCT__1; ?><img src="../../images/buttons/edit.gif" width="16" height="16" alt="<?php echo Generic::EDIT_QUESTION; ?>" title="edit" /> <?php echo Tutors::GROUPS__INSTRUCT__2; ?></p>
     <div class="info_box">
       <p><?php echo Generic::PLEASE__NOTE; ?></p>
@@ -64,31 +63,29 @@
     </div>
     <div class="obj_list">
 <?php
-  for($collection_iterator->reset(); $collection_iterator->is_valid(); $collection_iterator->next() ) {
-    $collection = $collection_iterator->current();
+  for ($collection_iterator->reset(); $collection_iterator->is_valid(); $collection_iterator->next()) {
+      $collection = $collection_iterator->current();
 
-    $group_count = count($collection->get_groups_array());
+      $group_count = count($collection->get_groups_array());
 
-    $edit_url = "edit/edit_collection.php?c={$collection->id}";
-?>
+      $edit_url = "edit/edit_collection.php?c={$collection->id}"; ?>
         <div class="obj">
           <table class="obj" cellpadding="2" cellspacing="2">
           <tr>
-            <td class="obj_icon" width="24"><a class="text" href="<?php echo($edit_url); ?>"><img src="../../images/icons/groups.gif" alt="<?php Generic::GROUPS; ?>" height="24" width="24" /></a></td>
+            <td class="obj_icon" width="24"><a class="text" href="<?php echo $edit_url; ?>"><img src="../../images/icons/groups.gif" alt="<?php Generic::GROUPS; ?>" height="24" width="24" /></a></td>
             <td class="obj_info">
-              <div class="obj_name"><a class="text" href="<?php echo($edit_url); ?>"><?php echo($collection->name); ?></a></div>
-              <div class="obj_info_text"><?php echo Generic::NO__GROUPS; ?> : <?php echo($group_count); ?></div>
+              <div class="obj_name"><a class="text" href="<?php echo $edit_url; ?>"><?php echo $collection->name; ?></a></div>
+              <div class="obj_info_text"><?php echo Generic::NO__GROUPS; ?> : <?php echo $group_count; ?></div>
             </td>
             <td class="buttons">
-              <a href="<?php echo($edit_url); ?>"><img src="../../images/buttons/edit.gif" width="16" height="16" alt="<?php echo Generic::EDIT__GROUP; ?>" title="edit" /></a>
-              <a href="<?php echo($edit_url); ?>&command=delete" onclick="return confirm('This collection will be deleted.\n\nClick OK to confirm.');"><img src="../../images/buttons/cross.gif" width="16" height="16" alt="<?php echo Generic::DELETE__GROUP; ?>" title="delete" /></a>
+              <a href="<?php echo $edit_url; ?>"><img src="../../images/buttons/edit.gif" width="16" height="16" alt="<?php echo Generic::EDIT__GROUP; ?>" title="edit" /></a>
+              <a href="<?php echo $edit_url; ?>&command=delete" onclick="return confirm('This collection will be deleted.\n\nClick OK to confirm.');"><img src="../../images/buttons/cross.gif" width="16" height="16" alt="<?php echo Generic::DELETE__GROUP; ?>" title="delete" /></a>
             </td>
           </tr>
           </table>
         </div>
 <?php
-  }
-?>
+  } ?>
     </div>
 <?php
 }
diff --git a/src/tutors/index.php b/src/tutors/index.php
index 1852921..b3253be 100644
--- a/src/tutors/index.php
+++ b/src/tutors/index.php
@@ -8,15 +8,15 @@
  * @link https://github.com/webpa/webpa
  */
 
-require_once("../includes/inc_global.php");
+require_once '../includes/inc_global.php';
 
 use WebPA\includes\functions\Common;
 use WebPA\lang\en\Generic;
 use WebPA\lang\en\tutors\Tutors;
 
 if (!Common::check_user($_user, APP__USER_TYPE_TUTOR)) {
-  header('Location:'. APP__WWW .'/logout.php?msg=denied');
-  exit;
+    header('Location:'. APP__WWW .'/logout.php?msg=denied');
+    exit;
 }
 
 // --------------------------------------------------------------------------------
@@ -25,9 +25,9 @@
 $UI->page_title = APP__NAME;
 $UI->menu_selected = 'home';
 $UI->help_link = '?q=node/233';
-$UI->breadcrumbs = array  (
-  'home'      => null ,
-);
+$UI->breadcrumbs = [
+  'home'      => null,
+];
 $UI->head();
 $UI->body();