-
Notifications
You must be signed in to change notification settings - Fork 0
/
lea.html
396 lines (314 loc) · 16.6 KB
/
lea.html
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
<!DOCTYPE html>
<html>
<head>
<title>Governors system LEA access</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<!-- open-iconic-bootstrap (icon set for bootstrap) -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/open-iconic/1.1.1/font/css/open-iconic-bootstrap.min.css" integrity="sha256-BJ/G+e+y7bQdrYkS2RBTyNfBHpA9IuGaPmf9htub5MQ=" crossorigin="anonymous" />
<style>
label {
display: inline-block;
width: 15rem;
text-align: right;
vertical-align: top;
font-weight: bold;
}
.formerrormessage {
margin-left: 16rem;
}
</style>
</head>
<body>
<div class = 'container-fluid'>
<!-- dummy sidebar to make display look reasonable on large screens -->
<div class="row">
<div class= "col-md-2">
</div>
<div class = "col-md-8 col xs-12">
<h2 style="text-align: center; margin-top: 3vh;">School Governing Body Selector</h2>
<div id ="schoolselector" style="margin-top: 10vh;">
</div>
</div>
<div class= "col-md-2">
</div>
</div>
</div>
<form id = 'dummyform'> <!-- dummy form used to communicate with php helper functions -->
</form>
<a id="launchanchor" hidden target = "_blank"></a> <!-- hidden button for document displays -->
<script>
window.onload = function () {
displaySchoolSelector()
}
function displaySchoolSelector() {
var form = document.forms.namedItem("dummyform");
var oData = new FormData(form);
oData.append("helper_type", "display_school_selector");
var oReq = new XMLHttpRequest();
oReq.open("POST", "php/lea_helpers.php", true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
document.getElementById('schoolselector').innerHTML = response;
}
}
};
oReq.send(oData);
}
var schoolNames;
var userIds;
function displaySchoolsManagementScreen(message) {
var form = document.forms.namedItem("dummyform");
var oData = new FormData(form);
oData.append("helper_type", "build_schools_management_screen");
var oReq = new XMLHttpRequest();
oReq.open("POST", "php/lea_helpers.php", true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
var xmlDoc = oReq.responseXML;
var JSONString = xmlDoc.getElementsByTagName("returns")[0].childNodes[0].nodeValue;
var JSONObject = JSON.parse(JSONString);
response = JSONObject.return;
schoolNames = JSONObject.school_names;
userIds = JSONObject.user_ids;
document.getElementById('schoolselector').innerHTML = response;
document.getElementById('messagearea').innerHTML = message;
document.getElementById('messagearea').style.color = 'blue';
// if the message is blank can safely assume we're logged in so can blank
// the logindiv and display the managementdiv. All calls to displaySchoolsManagementScreen
// will have a message except for the initial login request
if (message != '') {
document.getElementById('lealogindiv').style.display = "none";
document.getElementById('leaschoolmanagementdiv').style.display = "block";
}
}
}
};
oReq.send(oData);
}
function validateLEAPassword() {
var form = document.forms.namedItem("dummyform");
var oData = new FormData(form);
oData.append("helper_type", "validate_lea_password");
oData.append("lea_password", document.getElementById('leapassword').value);
var oReq = new XMLHttpRequest();
oReq.open("POST", "php/lea_helpers.php", true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
if (response.indexOf("invalid") != -1) {
injectErrorMessage('leapassword', "Sorry - this password is incorrect");
} else {
// reveal the leaschoolmanagementdiv hidden in the current schoolselector element
document.getElementById('leaschoolmanagementdiv').style.display = "block";
}
}
}
};
oReq.send(oData);
}
var selectedSchoolId;
function displayOldSchoolParameters() {
var form = document.forms.namedItem("dummyform");
var oData = new FormData(form);
oData.append("helper_type", "get_school_data");
var schoolsselector = document.getElementById('schoolsselector');
selectedSchoolId = schoolsselector.options[schoolsselector.selectedIndex].value;
schoolsselector.selectedIndex = 0; // reset to default so "onchange" wili work even if same school selected twice
if (selectedSchoolId == 0)
return;
oData.append("school_id", selectedSchoolId);
var oReq = new XMLHttpRequest();
oReq.open("POST", "php/lea_helpers.php", true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
var xmlDoc = oReq.responseXML;
var JSONString = xmlDoc.getElementsByTagName("returns")[0].childNodes[0].nodeValue;
var JSONObject = JSON.parse(JSONString);
var schoolName = JSONObject.school_name;
var userId = JSONObject.user_id;
var password = JSONObject.password;
document.getElementById('oldschoolname').placeholder = schoolName;
document.getElementById('olduserid').placeholder = userId;
document.getElementById('oldpassword').placeholder = password;
document.getElementById('oldschoolname').value = schoolName;
document.getElementById('olduserid').value = userId;
document.getElementById('oldpassword').value = password;
document.getElementById('oldschoolparameters').style.display = 'block';
}
}
};
oReq.send(oData);
}
function insertSchool() {
if (schoolDataIsValidForInsert()) {
var form = document.forms.namedItem("dummyform");
var oData = new FormData(form);
oData.append("helper_type", "insert_school");
oData.append("school_name", document.getElementById('schoolname').value);
oData.append("user_id", document.getElementById('clerkid').value);
oData.append("password", document.getElementById('clerkpassword').value);
var oReq = new XMLHttpRequest();
oReq.open("POST", "php/lea_helpers.php", true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
displaySchoolsManagementScreen("School inserted successfully")
}
}
};
oReq.send(oData);
}
}
function updateSchool() {
if (schoolDataIsValidForUpdate()) {
var form = document.forms.namedItem("dummyform");
var oData = new FormData(form);
oData.append("helper_type", "update_school");
oData.append("school_id", selectedSchoolId);
oData.append("school_name", document.getElementById('oldschoolname').value);
oData.append("user_id", document.getElementById('olduserid').value);
oData.append("password", document.getElementById('oldpassword').value);
var oReq = new XMLHttpRequest();
oReq.open("POST", "php/lea_helpers.php", true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
displaySchoolsManagementScreen("School updated successfully")
}
}
};
oReq.send(oData);
}
}
function deleteSchool() {
var form = document.forms.namedItem("dummyform");
var oData = new FormData(form);
oData.append("helper_type", "delete_school");
oData.append("school_id", selectedSchoolId);
var oReq = new XMLHttpRequest();
oReq.open("POST", "php/lea_helpers.php", true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
displaySchoolsManagementScreen("School deleted successfully")
}
}
};
oReq.send(oData);
}
var insertScreenValid;
function schoolDataIsValidForInsert() {
var schoolName = document.getElementById('schoolname').value;
var userId = document.getElementById('clerkid').value;
var password = document.getElementById('clerkpassword').value;
insertScreenValid = true;
if (!(schoolNameUnique(schoolName)))
injectErrorMessage('schoolname', 'Oops - there is already a school with this name');
if (schoolName == '')
injectErrorMessage('schoolname', 'Oops - schoolname cannot be blank');
if (!(userIdUnique(userId)))
injectErrorMessage('clerkid', 'Oops - there is already a user with this id');
if (userId == '')
injectErrorMessage('clerkid', 'Oops - userId cannot be blank');
if (password == '')
injectErrorMessage('clerkpassword', 'Oops - password cannot be blank');
return insertScreenValid;
}
var updateScreenValid;
function schoolDataIsValidForUpdate() {
var oldSchoolName = document.getElementById('oldschoolname').placeholder;
var oldUserId = document.getElementById('olduserid').placeholder;
var schoolName = document.getElementById('oldschoolname').value;
var userId = document.getElementById('olduserid').value;
var password = document.getElementById('oldpassword').value;
updateScreenValid = true;
if ((oldSchoolName != schoolName) && !schoolNameUnique(schoolName))
injectErrorMessage('oldschoolname', 'Oops - there is already a school with this name');
if (schoolName == '')
injectErrorMessage('oldschoolname', 'Oops - schoolname cannot be blank');
if ((oldUserId != userId) && !userIdUnique(userId))
injectErrorMessage('olduserid', 'Oops - there is already a user with this id');
if (userId == '')
injectErrorMessage('olduserid', 'Oops - userId cannot be blank');
if (password == '')
injectErrorMessage('oldpassword', 'Oops - password cannot be blank');
return updateScreenValid;
}
function schoolNameUnique(schoolName) {
if (schoolNames.indexOf(schoolName) == -1) {
return true;
} else {
return false;
}
}
function userIdUnique(userId) {
if (userIds.indexOf(userId) == -1) {
return true;
} else {
return false;
}
}
function launchSchoolPage() {
var schoolsselector = document.getElementById('schoolsselector');
var selectedSchoolId = schoolsselector.options[schoolsselector.selectedIndex].value;
schoolsselector.selectedIndex = 0; // reset to default so "onchange" wili work even if same school selected twice
if (selectedSchoolId == 0)
return;
// add dummy version number to ensure page is refreshed
dateObject = new Date();
currentTime = dateObject.getTime();
var url = "pages.html?id=" + selectedSchoolId + "&target=governors&ver=" + currentTime;
var launchanchor = document.getElementById('launchanchor');
launchanchor.href = url;
launchanchor.click();
}
///////////////// Service functions
var insertScreenValid;
var updateScreenValid;
function injectErrorMessage(field, errorMessage) {
// Insert "errorMessage" into the innerHTML of the error paragraph element associated
// with element "field" - assumed to have id "fielderror".
//
// Also set the global governorScreenValid variable
var fielderrormessageid = field + "error";
document.getElementById(fielderrormessageid).innerHTML = errorMessage;
document.getElementById(fielderrormessageid).style.color = 'red';
insertScreenValid = false;
updateScreenValid = false;
}
function clearAllErrors() {
// get all elements with class formerrormessage and blank them out
var elements = document.getElementsByClassName('formerrormessage');
for (var i = 0; i < elements.length; i++) {
elements[i].innerHTML = '';
}
}
</script>
</body>
</html>