Commit 75b5be45 authored by William Paul Liggett's avatar William Paul Liggett

Log Data to CSV: Ensured that the user's activity data will not breach PHP's...

Log Data to CSV: Ensured that the user's activity data will not breach PHP's max_input_vars setting.
parent bee7af1d
......@@ -98,23 +98,23 @@ if(!isset($_SESSION['ov_database_user_sk'])) {
// Random Letter Log: Details when each random letter was presented. No user activity is recorded.
// -----------------------------------------------------------------------------------------------------------------------
if(isset($_POST['ov_random_letter_log'])) {
// JS string. Unfortunately, this is not a direct JS array like the `ov_user_activity_log'.
// JS string. Unfortunately, this is not a direct JS array as originally built by the client.
// The reason for this is that there is so much data created with the random letters that submitting it
// directly as a JS array for standard processing has the side-effect of breaching PHP's `max_input_var' setting,
// such that with this setting at 1000 the `ov_random_letter_log' gets cut off on key 166 and, likewise, with
// `max_input_var' set at 5000, the `ov_random_letter_log' gets cut off at key 833 of 1531
// (from a full 12+12=24 min OV test). Note: The string is sanitized later.
// directly as a JS array for standard processing has the side-effect of breaching PHP's `max_input_var' setting.
// For instance with max_input_vars=1000 the `ov_random_letter_log' gets cut off on key 166 and, likewise, with
// max_input_var=5000, the `ov_random_letter_log' gets cut off at key 833 of 1531 (from a full 12+12=24 min OV test).
// Note: The $_POST string is sanitized later.
$string_ov_random_letter_log = $_POST['ov_random_letter_log'];
// Breaks the string into a single-dimension array.
$flat_ov_random_letter_log = explode(",", $string_ov_random_letter_log);
$flat_array_ov_random_letter_log = explode(",", $string_ov_random_letter_log);
// Builds up a two-dimensional array like it was stored in JS.
$ov_random_letter_log = array();
$temp_array = array();
$column = 0;
for($i = 0; $i < count($flat_ov_random_letter_log); $i++) {
array_push($temp_array, $flat_ov_random_letter_log[$i]);
for($i = 0; $i < count($flat_array_ov_random_letter_log); $i++) {
array_push($temp_array, $flat_array_ov_random_letter_log[$i]);
if($column < 5) {
$column++;
}
......@@ -127,7 +127,8 @@ if(isset($_POST['ov_random_letter_log'])) {
// Sanitizes the JS array.
foreach($ov_random_letter_log as $key => &$value) {
// Title heading should only have: "GlobalTrialCounter", "CurrentTrial", "TimeStamp", "Type", "Block", and "ov_random_letter_is_o".
// Title heading should only have: "GlobalTrialCounter", "CurrentTrial", "TimeStamp", "Type", "Block",
// and "ov_random_letter_is_o".
if($key === 0) {
if(
($value[0] !== "GlobalTrialCounter") &&
......@@ -137,7 +138,8 @@ if(isset($_POST['ov_random_letter_log'])) {
($value[4] !== "Block") &&
($value[5] !== "ov_random_letter_is_o")
) {
output_json_response(false, "Bad title headings for ov_random_letter_log at key: " . intval($key) . ", value (full row): " . var_export($value, true));
output_json_response(false, "Bad title headings for ov_random_letter_log at key: " . intval($key) .
", value (full row): " . var_export($value, true));
return;
}
......@@ -155,7 +157,8 @@ if(isset($_POST['ov_random_letter_log'])) {
// Type: Must be either "P" or "E".
$value[3] = htmlspecialchars($value[3], ENT_QUOTES);
if(($value[3] !== "P") && ($value[3] !== "E")) {
output_json_response(false, "Invalid 'Type' data for ov_random_letter_log at key: " . intval($key) . ", value (full row): " . var_export($value, true));
output_json_response(false, "Invalid 'Type' data for ov_random_letter_log at key: " . intval($key) .
", value (full row): " . var_export($value, true));
return;
}
......@@ -164,7 +167,8 @@ if(isset($_POST['ov_random_letter_log'])) {
// ov_random_letter_is_o: Must be either 0 or 1.
$value[5] = intval($value[5]);
if(($value[5] !== 0) && ($value[5] !== 1)) {
output_json_response(false, "Invalid 'ov_random_letter_is_o' data for ov_random_letter_log at key: " . intval($key) . ", value (full row): " . var_export($value, true));
output_json_response(false, "Invalid 'ov_random_letter_is_o' data for ov_random_letter_log at key: " .
intval($key) . ", value (full row): " . var_export($value, true));
return;
}
}
......@@ -219,15 +223,38 @@ if(isset($_POST['ov_random_letter_log'])) {
// User Activity Log: Documents when the user pressed the space bar.
// -----------------------------------------------------------------------------------------------------------------------
if(isset($_POST['ov_user_activity_log'])) {
// JS array that is stored in a CSV-like manner. Title headings = strings, Rows = integers.
$ov_user_activity_log = $_POST['ov_user_activity_log'];
// JS string. Unfortunately, this is not a direct JS array as originally built by the client.
// The reason for this is that there is so much data created with the user that submitting it
// directly as a JS array for standard processing has the side-effect of breaching PHP's `max_input_var' setting.
// Note: The $_POST string is sanitized later.
$string_ov_user_activity_log = $_POST['ov_user_activity_log'];
// Breaks the string into a single-dimension array.
$flat_array_ov_user_activity_log = explode(",", $string_ov_user_activity_log);
// Builds up a two-dimensional array like it was stored in JS.
$ov_user_activity_log = array();
$temp_array = array();
$column = 0;
for($i = 0; $i < count($flat_array_ov_user_activity_log); $i++) {
array_push($temp_array, $flat_array_ov_user_activity_log[$i]);
if($column < 1) {
$column++;
}
else {
array_push($ov_user_activity_log, $temp_array);
$temp_array = array();
$column = 0;
}
}
// Sanitizes the JS array.
foreach($ov_user_activity_log as $key => &$value) {
// Title heading should only have: "GlobalTrialCounter" and "ov_participant_response_time".
if($key === 0) {
if(($value[0] !== "GlobalTrialCounter") && ($value[1] !== "ov_participant_response_time")) {
output_json_response(false, "Bad title headings for ov_user_activity_log at key: " . intval($key) . ", value (full row): " . var_export($value, true));
output_json_response(false, "Bad title headings for ov_user_activity_log at key: " . intval($key) .
", value (full row): " . var_export($value, true));
return;
}
......
......@@ -50,8 +50,14 @@
is an <em>optional</em> feature [Estimate: 0-2 hours]</li>
</ol>
<p class="version_info">Version 1.7.3 (2018-03-09 to 2018-09-17):</p>
<p><em>Estimated labor time: <span id="hours_logged_for_update_14">3</span> hours.</em></p>
<p class="version_info">Version 1.7.4 (2018-03-18):</p>
<p><em>Estimated labor time: <span id="hours_logged_for_update_15">0.5</span> hours.</em></p>
<ul>
<li>Log Data to CSV: Ensured that the user's activity data will not breach PHP's max_input_vars setting.</li>
</ul>
<p class="version_info">Version 1.7.3 (2018-03-09 to 2018-03-17):</p>
<p><em>Estimated labor time: <span id="hours_logged_for_update_14">4.5</span> hours.</em></p>
<ul>
<li>Log Data to CSV: More time was spent on this feature than the hours listed, as I am providing a free feature
to detect when there is a network problem when a participant finishes a test. Meaning, that the data can be saved
......@@ -195,7 +201,8 @@
parseFloat($("#hours_logged_for_update_11").html()) +
parseFloat($("#hours_logged_for_update_12").html()) +
parseFloat($("#hours_logged_for_update_13").html()) +
parseFloat($("#hours_logged_for_update_14").html());
parseFloat($("#hours_logged_for_update_14").html()) +
parseFloat($("#hours_logged_for_update_15").html());
// Displays the total labor hours at the top of the page.
$("#total_labor_hours").html(calculated_labor_time);
......
......@@ -298,7 +298,7 @@ var ov_participant_response_time = -1;
$.ajax({
type: "POST",
url: "admin/process_completed_test_user_data.php",
data: {ov_random_letter_log: ov_random_letter_log.toString() },
data: {ov_random_letter_log: ov_random_letter_log.toString() }, // Flattens the two-dimensional array into one really long string.
success: function(response, textStatus, jqXHR) {
ajax_sequence_response_trail += "Random Letter -- 2nd Ajax Response: " + response + "<br /><br />";
......@@ -344,7 +344,7 @@ var ov_participant_response_time = -1;
$.ajax({
type: "POST",
url: "admin/process_completed_test_user_data.php",
data: {ov_user_activity_log: ov_user_activity_log},
data: {ov_user_activity_log: ov_user_activity_log.toString() }, // Flattens the two-dimensional array into one really long string.
success: function(response, textStatus, jqXHR) {
ajax_sequence_response_trail += "User Activity -- 2nd Ajax Response: " + response + "<br /><br />";
......@@ -408,12 +408,12 @@ var ov_participant_response_time = -1;
var thirty_seconds_in_ms = parseFloat(30000); // 30 seconds = 30,000 ms [Used between the practice and the real test.]
var practice_time_in_ms = thirty_seconds_in_ms; // Practice Test is only 30 seconds for now.
var twelve_minutes_in_ms = parseFloat(720000); // 12 minutes = 720,000 ms
var four_minutes_in_ms = parseFloat(240000); // 4 minutes = 240,000 ms
//var twelve_minutes_in_ms = parseFloat(720000); // 12 minutes = 720,000 ms
//var four_minutes_in_ms = parseFloat(240000); // 4 minutes = 240,000 ms
// Inaccurate... TESTING VALUES.
//var twelve_minutes_in_ms = parseFloat(120000); // 2 minutes = 120,000 ms
//var four_minutes_in_ms = thirty_seconds_in_ms;
var twelve_minutes_in_ms = parseFloat(120000); // 2 minutes = 120,000 ms
var four_minutes_in_ms = thirty_seconds_in_ms;
//var twelve_minutes_in_ms = parseFloat(360000); // 6 minutes = 360,000 ms
//var four_minutes_in_ms = parseFloat(240000); // 4 minutes = 240,000 ms
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment