-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
executable file
·211 lines (188 loc) · 6.27 KB
/
index.html
File metadata and controls
executable file
·211 lines (188 loc) · 6.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<!DOCTYPE html>
<html>
<head>
<title>Welcome</title>
<link rel="icon" href="./Assets/Logo.png" type="image/x-icon" />
<link rel="stylesheet" href="./Assets/w3.css">
<style>
body {
margin-left: 30px;
margin-top: 10px;
margin-right: 30px;
}
</style>
<!-- Get participant IDs passed in from URL -->
<script src="./Assets/GetPpantIds.js"></script>
<!-- Helper for posting JSON data -->
<script src="./Assets/PostJson.js"></script>
<!-- Exclusion check -->
<script src="./Assets/ExclusionCheck.js"></script>
<script>
function BuildErrorUrl(ErrorCode) {
return (
"./Error.html?PoolId=" +
encodeURIComponent(String(PoolId)) +
"&SubjectId=" +
encodeURIComponent(String(SubjectId)) +
'&ErrorCode=' +
encodeURIComponent(String(ErrorCode)) +
"#"
);
}
function HandleError(ErrorCode) {
window.location.replace(BuildErrorUrl(ErrorCode));
}
function RedirectOrError(Result, ErrorCode) {
if (Boolean(Result && Result.TargetUrl)) {
window.location.replace(Result.TargetUrl);
} else {
HandleError(ErrorCode);
}
}
async function GenSubjectId(PID) {
return PostJson("./Assets/GenSubjectId.php", { PoolId: PID });
}
async function LogLanding() {
// Set PpantIds.PoolId and PpantIds.SubjectId
var PpantIds = {};
if (!PoolId && Boolean(SubjectId)) {
PpantIds.PoolId = null;
PpantIds.SubjectId = SubjectId;
} else if (Boolean(PoolId) && Boolean(SubjectId)) {
PpantIds.PoolId = PoolId;
PpantIds.SubjectId = SubjectId;
} else {
HandleError("000");
return null;
}
// Call LogLanding.php
return PostJson("./LogLanding.php", PpantIds);
}
async function LogAndRedirect(ErrorCode) {
var Result = await LogLanding();
if (Result === null) {
return;
}
RedirectOrError(Result, ErrorCode);
}
async function GenLogAndRedirect(ErrorCode) {
var Result = await GenSubjectId(PoolId);
SubjectId = Result.SubjectId;
await LogAndRedirect(ErrorCode);
}
function OnBodyLoad() {
// Show form if needed:
if (GetUserInput) {
var Form = document.getElementById("IdForm");
Form.style.visibility = "visible";
}
// Add an event listener:
var InputBox = document.getElementById("Input_ID");
InputBox.addEventListener("keydown", function (Event) {
if (Event.key === "Enter") {
// Cancel the default action, if needed
Event.preventDefault();
// Submit the form:
SubmitForm();
}
});
}
async function SubmitForm() {
var Input = document.getElementById("Input_ID").value;
var ErrorCode = null;
try {
if (
Input.length === 24 ||
(Input.length === 5 && /^[0-9]+$/.test(Input))
) {
PoolId = Input;
ErrorCode = "001";
await GenLogAndRedirect(ErrorCode);
return;
}
if (Input.length === 8) {
SubjectId = Input;
PoolId = null;
ErrorCode = "002";
await LogAndRedirect(ErrorCode);
return;
}
alert("Please enter a valid participant ID.");
} catch (Err) {
if (ErrorCode) {
HandleError(ErrorCode);
}
}
}
// --- Execute functions ---
var GetUserInput = false;
async function Init() {
var ErrorCode = "004";
if ((!PoolId) && (!SubjectId)) {
// Get user input
GetUserInput = true;
return;
}
try {
// No user input required; call and redirect.
if (!PoolId && Boolean(SubjectId)) {
ErrorCode = "003";
await LogAndRedirect(ErrorCode);
} else {
ErrorCode = "004";
await GenLogAndRedirect(ErrorCode);
}
} catch (Err) {
HandleError(ErrorCode);
}
}
Init();
</script>
</head>
<body onload="OnBodyLoad()">
<!-- BODY -->
<div
class="w3-container"
style="width:700px;visibility:hidden"
id="IdForm"
>
<h1>Sign in</h1>
<p>Please enter your participant ID in the box below.</p>
<p>
If you have arrived at this page via Prolific, this will be
your Prolific ID.
</p>
<p>
If you have arrived at this page via SONA, this will be your
SONA Unique ID.
</p>
<form>
<table class="w3-table">
<tbody>
<tr>
<td width="280px">
<input
id="Input_ID"
type="text"
name="ID"
placeholder="Participation ID"
size="26"
>
</td>
</tr>
<tr>
<td width="280px">
<button
type="button"
onclick="SubmitForm()"
>
Submit
</button>
</td>
</tr>
</tbody>
</table>
</form>
</div>
</body>
</html>