-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager_old.html
838 lines (673 loc) · 38.3 KB
/
manager_old.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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
<!DOCTYPE html>
<html lang="en-GB">
<!-- first version of the code to maintain the programes, programme_text and text_types
table before it was realied that it was easier to work directly on json representations
and uload these with the new version, manager.html-->
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="BeagAirBheag Programmes Managert" />
<meta name="keywords" content="beagairbheag" />
<title>BeagAirBheag Programs Manager</title>
<!-- code for datepicker -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link href="https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<style>
div.ui-datepicker {
font-size: 12px;
background: gainsboro;
border: 1px solid #555;
color: blue;
}
#ui-datepicker-div {
z-index: 9999 !important
}
</style>
</head>
<body>
<h1 style="text-align:center; padding: 1vh;">BaB Programme Parameter Maintenance Utility</h1>
<div style="display: flex; justify-content: center; align-items: center; padding: 3vh; margin: 1vw;">
<strong style="padding-right: 2vw;">Select Programme : </strong>
<div id="programmeselector" style="border: 1px solid black; padding: 1vh;">
</div>
</div>
<div id="programmemaintenancedivs"
style="border: 1px solid black; display: flex; justify-content: space-evenly; padding: 2vh; margin: 1vw;">
<div id="programmeinsert" style="display: block; border: 1px solid black; padding: 1vh;
display: flex; justify-content: center; padding: 1vh;">
</div>
<div id="programmesave" style="display: none !important; border: 1px solid black; padding: 1vh;
display: flex; justify-content: center; padding: 1vh;">
</div>
</div>
<div style="display: flex; justify-content: center; align-items: center; padding: 2vh; margin: 1vw;">
<strong style="padding-right: 2vw;">Select Text Type : </strong>
<div id="texttypeselector" style="border: 1px solid black; padding: 1vh;">
</div>
</div>
<div id="texttypemaintenancedivs"
style="border: 1px solid black; display: flex; justify-content: space-evenly; padding: 2vh; margin: 1vw;">
<div id="texttypeinsert" style="display: block; border: 1px solid black; padding: 1vh;
display: flex; justify-content: center; padding: 1vh;">
</div>
<div id="texttypesave" style="display: none !important; border: 1px solid black; padding: 1vh;
display: flex; justify-content: center; padding: 1vh;">
</div>
</div>
<div id="programmetextmaintenancedivs" style="display: none;">
<div style="display: flex; justify-content: center; align-items: center; padding: 2vh; margin: 1vw;">
<strong>Insert/Save Programme-Text Parameters for:
<i id='currenttexttype'></i> Texts 
in Series <span id='currentseriesnum'></span>,
<span id='currentepisodenam'></span>
</strong>
</div>
<div id="programmetextinsert" style="display: block; border: 1px solid black; padding: 1vh;
display: flex; justify-content: center; padding: 1vh;">
</div>
<div id="programmetextsavedivs">
</div>
</div>
<!-- empty form for the XMLHTTP PHP calls -->
<form id='dummyform'>
</form>
<script>
// Three important vars supplyig keys for the creation and saveing of
// programme_text records. They get set by selection, insertion and saveing
// of programme and text_type records. Their conetnt is monitored by onchange
// functions and when a change to any occurs and all three are set, display
// of the input/save fields for programme_text input/ save
var currentSeriesNum = 'new';
var currentEpisodeNam = 'new';
var currentTextType = 'new';
function monitorKeyVariables() {
if (currentSeriesNum != 'new' && currentEpisodeNam != 'new' && currentTextType != 'new') {
document.getElementById('programmetextmaintenancedivs').style.display = "block";
setProgrammeTextMaintenanceDivs()
}
}
var defaultNewProgrammePanel =
"<label for='iseriesnum'> Ser </label>" +
"<input id='iseriesnum' type='text' maxlength='2' size='2' name='iseriesnum'" +
" value='' placeholder='' autocomplete='off'" +
" title='Enter the series number'>" +
"<label for='iepisodenam'> Epi </label>" +
"<input id='iepisodenam' type='text' maxlength='100' size='5' name='iepisodenam'" +
" value='Episode ' placeholder='Episode ' autocomplete='off'" +
" title='Enter the name of the Episode - eg Episode 4'>" +
"<label for='ifirstondatestring'> First Broadcast </label>" +
"<input id='ifirstondatestring' type='text' maxlength='10' size='8' name='ifirstondatestring'" +
" value='' placeholder='' autocomplete='off'" +
" title='Enter date on which the programme was first broadcast'" +
" onmousedown = 'applyDatepicker(\"ifirstondatestring\");'>" +
"<label for='ifinishtime'> Finish </label>" +
"<input id='ifinishtime' type='text' maxlength='4' size='4' name='ifinishtime'" +
" value='' placeholder='' autocomplete='off'" +
" title='Enter the finish time of the programme as mmss'>" +
"<label for='ilearneroftheweek'> LotW </label>" +
"<input id='ilearneroftheweek' type='text' maxlength='30' size='10' name='ilearneroftheweek'" +
" value='' placeholder='' autocomplete='off'" +
" title='Enter the name of the Learner of the Week'>" +
"<label for='ibbcprogrammeurl'> Url </label>" +
"<input id='ibbcprogrammeurl' type='text' maxlength='100' size='10' name='ibbcprogrammeurl'" +
" value='' placeholder='' autocomplete='off'" +
" title='Enter the url for the BBC web page for this programme'>" +
"<label for='ibbcdownloadfilename'> Filename </label>" +
"<input id='ibbcdownloadfilename' type='text' maxlength='100' size='10' name='ibbcdownloadfilename'" +
" value='' placeholder='' autocomplete='off'" +
" title='Enter the filename for the BBC download (without the extension) for this programme'>" +
"<button type='button' style='margin-left: 1vw;' title='Insert a new programme'" +
"onclick='insertProgramme();'>Insert" +
"</button>" +
"<button type='button' style='margin-left: 1vw;' title='Display the Index for BBC BaB podcastse'" +
"onclick='displayBBCPage(\"https://www.bbc.co.uk/programmes/b05mzzhr/episodes/downloads\");'>Index" +
"</button>";
var defaultNewTextTypePanel =
"<label for='itexttype'> Text Type : </label>" +
"<input id='itexttype' type='text' maxlength='10' size='8' name='itexttype'" +
" value='' placeholder='' autocomplete='off'" +
" title='Enter a short tag for the text_type - eg blasadbeag'>" +
"<label for='itextcolor'> Text Color: </label>" +
"<input id='itextcolor' type='text' maxlength='10' size='8' name='itextcolor'" +
" value='' placeholder='' autocomplete='off'" +
" title='Enter a short tag for the text_color - eg fuchsia'>" +
"<label for='itexttitleheader'> Header : </label>" +
"<input id='itexttitleheader' type='text' maxlength='30' size='15' name='itexttitleheader'" +
" value='' placeholder='' autocomplete='off'" +
" title='Enter a header to precede text titles - eg Blasad Beag'>" +
"<label for='itextbbcindexpage'> Index Page : </label>" +
"<input id='itextbbcindexpage' type='text' maxlength='100' size='15' name='itextbbcindexpage'" +
" value='' placeholder='' autocomplete='off'" +
" title='Enter the url for the BBC index page for this text type'>" +
"<button type='button' style='margin-left: 1vw;' title='Insert a new text type'" +
"onclick='insertTextType();'>Insert" +
"</button>";
var defaultNewProgrammeTextPanel =
"<label for='iprogrammetextstarttimeinprogramme'> Start Time in Programme : </label>" +
"<input id='iprogrammetextstarttimeinprogramme' type='text' maxlength='4' size='4' name='iprogrammetextstarttimeinprogramme'" +
" value='' placeholder='' autocomplete='off'" +
" title='Enter the start time for this Text in the programme as mmss'>" +
"<label for='iprogrammetextfinishtimeinprogramme'> Finish Time in Programme : </label>" +
"<input id='iprogrammetextfinishtimeinprogramme' type='text' maxlength='4' size='4' name='iprogrammetextfinishtimeinprogramme'" +
" value='' placeholder='' autocomplete='off'" +
" title='Enter the finish time for this Text in the programme as mmss'>" +
"<label for='iprogrammetexttexttitle'> Text Title : </label>" +
"<input id='iprogrammetexttexttitle' type='text' maxlength='30' size='15' name='iprogrammetexttexttitle'" +
" value='' placeholder='' autocomplete='off'" +
" title='Enter a title for the tex - eg Pàirc Hampden'>" +
"<label for='iprogrammetexttexturl'> Url : </label>" +
"<input id='iprogrammetexttexturl' type='text' maxlength='100' size='15' name='iprogrammetexttexturl'" +
" value='' placeholder='' autocomplete='off'" +
" title='Enter the url for the BBC page for this text'>" +
"<button type='button' style='margin-left: 1vw;' title='Insert a new programme text'" +
"onclick='insertProgrammeText();'>Insert" +
"</button>";
window.onload = function () {
buildTextTypeSelector();
buildProgrammeSelector();
document.getElementById('texttypeinsert').innerHTML = defaultNewTextTypePanel;
document.getElementById('programmeinsert').innerHTML = defaultNewProgrammePanel;
}
/////////////// Programme Maintenance ////////////////////
function buildProgrammeSelector() {
var form = document.forms.namedItem("dummyform");
var oData = new FormData(form);
oData.append("helper_type", "build_programme_selector");
var oReq = new XMLHttpRequest();
oReq.open("POST", "php/manager_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('programmeselector').innerHTML = response;
}
}
};
oReq.send(oData);
}
function setEpisodesPickListForSeries(seriesNum) {
if (seriesNum === "new") {
document.getElementById('programmesave').style.display = "none";
document.getElementById('programmeinsert').style.display = "block";
document.getElementById('programmeinsert').innerHTML = defaultNewProgrammePanel;
} else {
var form = document.forms.namedItem("dummyform");
var oData = new FormData(form);
oData.append("helper_type", "build_episode_selector");
oData.append("series_num", seriesNum);
var oReq = new XMLHttpRequest();
oReq.open("POST", "php/manager_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('episodespicklistdiv').innerHTML = response;
}
}
};
oReq.send(oData);
}
}
function setProgrammeMaintenanceDivs(seriesNum, episodeNam) {
// Toggle the programmesave and programmeinsert divs
if (episodeNam === "new") {
// display the programmeinsertdiv
document.getElementById('programmesave').style.display = "none";
document.getElementById('programmeinsert').style.display = "block";
document.getElementById('programmeinsert').innerHTML = defaultNewProgrammePanel;
} else {
// display the programmesave div
var form2 = document.forms.namedItem("dummyform");
var oData2 = new FormData(form2);
oData2.append("helper_type", "build_programme_update_div");
oData2.append("series_num", seriesNum);
oData2.append("episode_nam", episodeNam);
var oReq2 = new XMLHttpRequest();
oReq2.open("POST", "php/manager_helpers.php", true);
oReq2.onload = function (oEvent) {
if (oReq2.status == 200) {
var response2 = oReq2.responseText;
if (response2.indexOf("%failed%") != -1) {
alert(response2);
} else {
document.getElementById('programmesave').innerHTML = response2;
document.getElementById('programmesave').style.display = "block";
document.getElementById('programmeinsert').style.display = "none";
currentSeriesNum = seriesNum;
currentEpisodeNam = episodeNam;
monitorKeyVariables();
}
}
};
oReq2.send(oData2);
// get the url of the BBC page for this programme and use it initialise the "visit" button
var form1 = document.forms.namedItem("dummyform");
var oData1 = new FormData(form1);
oData1.append("helper_type", "get_bbc_programme_url_address");
oData1.append("series_num", seriesNum);
oData1.append("episode_nam", episodeNam);
var oReq1 = new XMLHttpRequest();
oReq1.open("POST", "php/manager_helpers.php", true);
oReq1.onload = function (oEvent) {
if (oReq1.status == 200) {
var response1 = oReq1.responseText;
if (response1.indexOf("%failed%") != -1) {
alert(response1);
} else {
// had a big problem with the next statement - seemed impossible to set onclick to
// anything other than function() {....}. The way that you would use if you were setting
// in an html statement just didn't work. he setAttribute approach was the answer
document.getElementById('eprogrammevisitbutton').setAttribute('onclick', "displayBBCPage('" + response1 + "');");
}
}
};
oReq1.send(oData1);
}
}
function insertProgramme() {
// rough and ready validation
if (document.getElementById('iseriesnum').value === '' || document.getElementById('iepisodenam').value === '') {
alert("oops - key values not set");
return;
}
var form = document.forms.namedItem("dummyform");
var oData = new FormData(form);
oData.append("helper_type", "insert_programme");
oData.append("series_num", document.getElementById('iseriesnum').value);
oData.append("episode_nam", document.getElementById('iepisodenam').value);
oData.append("firston_datestring", document.getElementById('ifirstondatestring').value);
oData.append("finish_time", document.getElementById('ifinishtime').value);
oData.append("learner_of_the_week", sanitizeText(document.getElementById('ilearneroftheweek').value));
oData.append("bbc_programme_url", document.getElementById('ibbcprogrammeurl').value);
oData.append("bbc_download_filename", document.getElementById('ibbcdownloadfilename').value);
var oReq = new XMLHttpRequest();
oReq.open("POST", "php/manager_helpers.php", true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
buildProgrammeSelector();
document.getElementById('programmeinsert').innerHTML = defaultNewProgrammePanel;
currentSeriesNum = document.getElementById('iseriesnum').value;
currentEpisodeNam = document.getElementById('iepisodenam').value;
monitorKeyVariables();
}
}
};
oReq.send(oData);
}
function saveProgramme() {
var form = document.forms.namedItem("dummyform");
var oData = new FormData(form);
oData.append("helper_type", "save_programme");
oData.append("series_num_new", document.getElementById('eseriesnum').value);
oData.append("episode_nam_new", document.getElementById('eepisodenam').value);
oData.append("series_num_old", document.getElementById('eseriesnum').placeholder);
oData.append("episode_nam_old", document.getElementById('eepisodenam').placeholder);
oData.append("firston_datestring", document.getElementById('efirstondatestring').value);
oData.append("finish_time", document.getElementById('efinishtime').value);
oData.append("learner_of_the_week", sanitizeText(document.getElementById('elearneroftheweek').value));
oData.append("bbc_programme_url", document.getElementById('ebbcprogrammeurl').value);
oData.append("bbc_download_filename", document.getElementById('ebbcdownloadfilename').value);
var oReq = new XMLHttpRequest();
oReq.open("POST", "php/manager_helpers.php", true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
buildProgrammeSelector();
document.getElementById('programmeselector').innerHTML = defaultNewProgrammePanel;
currentSeriesNum = document.getElementById('eseriesnum').value;
currentEpisodeNam = document.getElementById('eepisodenam').value;
monitorKeyVariables();
}
}
};
oReq.send(oData);
}
function deleteProgramme() {
var form = document.forms.namedItem("dummyform");
var oData = new FormData(form);
oData.append("helper_type", "delete_programme");
oData.append("series_num", document.getElementById('eseriesnum').placeholder);
oData.append("episode_nam", document.getElementById('eepisodenam').placeholder); var oReq = new XMLHttpRequest();
oReq.open("POST", "php/manager_helpers.php", true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
buildProgrammeSelector();
document.getElementById('programmeselector').innerHTML = defaultNewProgrammePanel;
currentSeriesNum = 'new';
currentEpisodeNam = 'new';
monitorKeyVariables();
}
}
};
oReq.send(oData);
}
///////////////////// Text Type Maintenance //////////////////////
function buildTextTypeSelector() {
var form = document.forms.namedItem("dummyform");
var oData = new FormData(form);
oData.append("helper_type", "build_text_type_selector");
var oReq = new XMLHttpRequest();
oReq.open("POST", "php/manager_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('texttypeselector').innerHTML = response;
}
}
};
oReq.send(oData);
}
function setTextTypeMaintenanceDivs(textType) {
// Toggle the texttypesave and texttypeinsert divs
if (textType === "new") {
// display the texttypeinsertdiv
document.getElementById('texttypesave').style.display = "none";
document.getElementById('texttypeinsert').style.display = "block";
document.getElementById('texttypeinsert').innerHTML = defaultNewTextTypePanel;
} else {
// display the texttypesave div
var form2 = document.forms.namedItem("dummyform");
var oData2 = new FormData(form2);
oData2.append("helper_type", "build_text_type_update_div");
oData2.append("text_type", textType);
var oReq2 = new XMLHttpRequest();
oReq2.open("POST", "php/manager_helpers.php", true);
oReq2.onload = function (oEvent) {
if (oReq2.status == 200) {
var response2 = oReq2.responseText;
if (response2.indexOf("%failed%") != -1) {
alert(response2);
} else {
document.getElementById('texttypesave').innerHTML = response2;
document.getElementById('texttypesave').style.display = "block";
document.getElementById('texttypeinsert').style.display = "none";
currentTextType = textType;
monitorKeyVariables();
}
}
};
oReq2.send(oData2);
// get the url of the BBC site for this textType and use it initialise the "visit" button
var form1 = document.forms.namedItem("dummyform");
var oData1 = new FormData(form1);
oData1.append("helper_type", "get_text_type_parameters");
oData1.append("text_type", textType);
var oReq1 = new XMLHttpRequest();
oReq1.open("POST", "php/manager_helpers.php", true);
oReq1.onload = function (oEvent) {
if (oReq1.status == 200) {
var response1 = oReq1.responseText;
if (response1.indexOf("%failed%") != -1) {
alert(response1);
} else {
var xmlDoc = oReq.response1XML;
var JSONString = xmlDoc.getElementsByTagName("returns")[0].childNodes[0].nodeValue;
var JSONObject = JSON.parse(JSONString);
textTitleHeader = JSONObject.currenttexttitleheader;
textBbcIndexPage = JSONObject.textBbcIndexPage;
currentTextTitleHeader = textTitleHeader;
document.getElementById('itexttitleheader').placeholder = textTitleHeader;
// had a big problem with the next statement - seemed impossible to set onclick to
// anything other than function() {....}. The way that you would use if you were setting
// in an html statement just didn't work. he setAttribute approach was the answer
document.getElementById('etextvisitbutton').setAttribute('onclick', "displayBBCPage('" + textBbcIndexPage + "');");
}
}
};
oReq1.send(oData1);
}
}
function insertTextType() {
if (document.getElementById('itexttype').value === '') {
alert("oops - text_type not set");
return;
}
var form = document.forms.namedItem("dummyform");
var oData = new FormData(form);
oData.append("helper_type", "insert_text_type");
oData.append("text_type", document.getElementById('itexttype').value);
oData.append("text_color", document.getElementById('itextcolor').value);
oData.append("text_title_header", sanitizeText(document.getElementById('itexttitleheader').value));
oData.append("text_bbc_index_page", document.getElementById('itextbbcindexpage').value);
var oReq = new XMLHttpRequest();
oReq.open("POST", "php/manager_helpers.php", true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
buildTextTypeSelector();
document.getElementById('texttypeinsert').innerHTMLL = defaultNewTextTypePanel;
currentTextType = document.getElementById('itexttype').value;
monitorKeyVariables();
}
}
};
oReq.send(oData);
}
function saveTextType() {
var form = document.forms.namedItem("dummyform");
var oData = new FormData(form);
oData.append("helper_type", "save_text_type");
oData.append("text_type_new", document.getElementById('etexttype').value);
oData.append("text_type_old", document.getElementById('etexttype').placeholder);
oData.append("text_color", document.getElementById('etextcolor').value);
oData.append("text_title_header", sanitizeText(document.getElementById('etexttitleheader').value));
oData.append("text_bbc_index_page", document.getElementById('etextbbcindexpage').value);
var oReq = new XMLHttpRequest();
oReq.open("POST", "php/manager_helpers.php", true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
buildTextTypeSelector();
document.getElementById('texttypeselector').innerHTML = defaultNewTextTypePanel;
currentTextType = document.getElementById('etexttype').value;
monitorKeyVariables();
}
}
};
oReq.send(oData);
}
function deleteTextType() {
var form = document.forms.namedItem("dummyform");
var oData = new FormData(form);
oData.append("helper_type", "delete_text_type");
oData.append("text_type", document.getElementById('etexttype').placeholder);
var oReq = new XMLHttpRequest();
oReq.open("POST", "php/manager_helpers.php", true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
buildTextTypeSelector();
document.getElementById('texttypeselector').innerHTML = defaultNewTextTypePanel;
currentTextType = 'new';
monitorKeyVariables();
}
}
};
oReq.send(oData);
}
/////////////// Programme_text scripts //////////////////////////
function setProgrammeTextMaintenanceDivs() {
// Display a programmetextinsert and all of the available programmetextsave
// divs for the current keys
document.getElementById('currentseriesnum').innerHTML = currentSeriesNum;
document.getElementById('currentepisodenam').innerHTML = currentEpisodeNam;
document.getElementById('currenttexttype').innerHTML = currentTextType;
// first the programmeinsertdiv
document.getElementById('programmetextinsert').innerHTML = defaultNewProgrammeTextPanel;
document.getElementById('iprogrammetexttexttitle').placeholder = currentTextTitle;
document.getElementById('iprogrammetexttexttitle').value = currentTextTitle;
// and now the programmesave divs
var form2 = document.forms.namedItem("dummyform");
var oData2 = new FormData(form2);
oData2.append("helper_type", "build_programme_text_update_divs");
oData2.append("series_num", currentSeriesNum);
oData2.append("episode_nam", currentEpisodeNam);
oData2.append("text_type", currentTextType);
var oReq2 = new XMLHttpRequest();
oReq2.open("POST", "php/manager_helpers.php", true);
oReq2.onload = function (oEvent) {
if (oReq2.status == 200) {
var response2 = oReq2.responseText;
if (response2.indexOf("%failed%") != -1) {
alert(response2);
} else {
document.getElementById('programmetextsavedivs').innerHTML = response2;
}
}
};
oReq2.send(oData2);
}
function insertProgrammeText() {
if (document.getElementById('iprogrammetextstarttimeinprogramme').value === '') {
alert("oops - start_time not set");
return;
}
var form = document.forms.namedItem("dummyform");
var oData = new FormData(form);
oData.append("helper_type", "insert_programme_text");
oData.append("series_num", currentSeriesNum);
oData.append("episode_nam", currentEpisodeNam);
oData.append("start_time_in_programme", document.getElementById('iprogrammetextstarttimeinprogramme').value);
oData.append("finish_time_in_programme", document.getElementById('iprogrammetextfinishtimeinprogramme').value);
oData.append("text_title", sanitizeText(document.getElementById('iprogrammetexttexttitle').value));
oData.append("text_url", document.getElementById('iprogrammetexttexturl').value);
oData.append("text_type", currentTextType);
var oReq = new XMLHttpRequest();
oReq.open("POST", "php/manager_helpers.php", true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
setProgrammeTextMaintenanceDivs();
}
}
};
oReq.send(oData);
}
function saveProgrammeText(rowNum) {
var form = document.forms.namedItem("dummyform");
var oData = new FormData(form);
oData.append("helper_type", "save_programme_text");
oData.append("series_num", currentSeriesNum);
oData.append("episode_nam", currentEpisodeNam);
oData.append("start_time_in_programme_new", document.getElementById('eprogrammetextstarttimeinprogramme' + rowNum).value);
oData.append("start_time_in_programme_old", document.getElementById('eprogrammetextstarttimeinprogramme' + rowNum).placeholder);
oData.append("finish_time_in_programme", document.getElementById('eprogrammetextfinishtimeinprogramme' + rowNum).value);
oData.append("text_title", sanitizeText(document.getElementById('eprogrammetexttexttitle' + rowNum).value));
oData.append("text_url", document.getElementById('eprogrammetexttexturl' + rowNum).value);
oData.append("text_type", currentTextType);
var oReq = new XMLHttpRequest();
oReq.open("POST", "php/manager_helpers.php", true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
}
}
};
oReq.send(oData);
}
function deleteProgrammeText(rowNum) {
var form = document.forms.namedItem("dummyform");
var oData = new FormData(form);
oData.append("helper_type", "delete_programme_text");
oData.append("series_num", currentSeriesNum);
oData.append("episode_nam", currentEpisodeNam);
oData.append("start_time_in_programme", document.getElementById('eprogrammetextstarttimeinprogramme' + rowNum).placeholder);
var oReq = new XMLHttpRequest();
oReq.open("POST", "php/manager_helpers.php", true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
setProgrammeTextMaintenanceDivs();
}
}
};
oReq.send(oData);
}
/////////////// Utility scripts //////////////////////////
function sanitizeText(textString) {
// Return a version of textString in which both single and double
// quptes have been replaced by the "right quote" character. The
// intention is to avoid confusing SQL and Javascript. The loss of
// functionlity is considered to be acceptable. In fact the use of
// a right quote in writing a' for example (where a right quote isn't
// actually available on thekeyboard) is probably preferrable
var temp = textString.replace(/'/g, "’");
var temp1 = temp.replace(/"/g, "’");
return temp1;
}
var popupWindow;
function displayBBCPage(siteUrl) {
// Display siteUrl in a popUpWindow. the effective size of "top" is restricted by
// "height" and the size of the window - the browsers all seem to restrict "top" to
// the maximum that still allows the popup window to be wholly viewable. "Rresizable"
// and "scrollbars" are oly required for IE
event.stopPropagation(); // make sure we don't triggger the window click we set up later
popUpWindow = window.open(siteUrl, "popUpWindow",
"width=500, height=500, left=500, top=50, resizable = yes, scrollbars = yes ");
// Need to consider what happens when the Popup has run to a successful conclusion. Ideally
// we would detect when it wa closed and take appropriate action. There is an
// .onclose method that allows this, but this is not widely supported. The method chosen is to set
// a temporary window.onclick function to close the popup and refresh the list, before nulling itstelf
window.onclick = function () {
popUpWindow.close();
window.onclick = null;
};
}
function applyDatepicker(elementId) {
var oldDate = document.getElementById(elementId).value;
$('#' + elementId).datepicker();
$('#' + elementId).datepicker('option', 'dateFormat', 'yy/mm/dd'); // set 2020/03/30 type format
$('#' + elementId).datepicker('option', 'changeMonth', true); // display month drop-down
$('#' + elementId).datepicker('option', 'changeYear', true); // display year drop-down
$('#' + elementId).datepicker('option', 'yearRange', '1999:c'); // 1999 to current - see https://api.jqueryui.com/datepicker/#option-yearRange
//if there's a value for the element, inject this into datepicker
var elementValue = document.getElementById(elementId).placeholder;
if (elementValue != '') {
$('#' + elementId).datepicker("setDate", elementValue);
}
$('#' + elementId).datepicker()
.on('input change', function (e) {
var newDate = document.getElementById(elementId).value;
if (newDate == '')
document.getElementById(elementId).value = oldDate;
});
}
</script>
</body>
</html>