-
Notifications
You must be signed in to change notification settings - Fork 4
/
booker.html
1823 lines (1541 loc) · 101 KB
/
booker.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
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<!--
Barbershop V4.0 was the last version of the booker system that might be used to create a
self-contained website for a single shop. The thinking now is that there was probably a
limited appetite for this arrangement and so the logical next step is a more packaged,
"commercial" arrangement where a group of shops could share a common system on a server
such as hostpapa while each having their own url and some limited personalisation (delivered
via a shop-specific header graphic).
The arrangement now implemented gives each shop its own sub-domain on a shared "cumbrianstylist.com"
domain. The shops share a common database and draw common html and php code from a shared folder.
The only serious problem encountered was when attempting to launch XMLHttp requests to php code
outside a shop's web folder. These request were bounced with "cross-site failure" messages. The
answer was to include headers in the php code explicitly giving permission for cross-site use. The
other slight snag was that relative file references from javascript within a file folder to targets
outside it don't work - this was fixed by using absolute references.
Filing is currently arranged as follows:
booker_shared_code
cert(Paypal credentials folder)
cacert.pem
includes
vendor (Postmark credentials folder)
autoload.php
booker_functions.php
booker_globals.php
send_email_via_postmark
php
booker_helpers.php
process_paypal_consequentials
booker.html
listener.php - standard listener that dynamically loads shop paypal business addresses
paypalIPN.php
login_engine.php
individual shop folder (eg oneills.cumbrianstylist.com)
barber.jpg (header graphic - unique to the shop)
index.php (master to launch a non-cached copy of the shared booker.html code)
login.html (master to call login_engine.php with the shop's url as parameter)
-->
<html>
<head>
<title>Ecommerce prototype booker page</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these
as per https://getbootstrap.com/docs/3.3/getting-started/ 17/5/2020 -->
<meta name="description" content="Item descriptions">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" 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>
body { /* override bootstrap's 16px default - just too big on iphone */'
font-size: 14px;
}
/* unvisited link */
a:link {
color: black;
}
/* visited link */
a:visited {
color: black;
}
.launchpadlink {
width: 5.5em;
padding: .5em;
border: 1px solid black;
border-radius: .5em;
padding: .5em;
display: inline-block;
text-decoration: none !important;
margin: 1em auto 1em auto;
}
.view {
background-color: LAVENDER;
}
.amend {
background-color: MEDIUMAQUAMARINE;
}
.configure {
background-color: WHEAT;
}
.table td, .table th { /* over-ride the .75rem that bootstrap now adds to table cells */
padding: .25rem;
}
</style>
</head>
<body>
<div class = 'container-fluid' style = 'text-align: left;'>
<!-- The use of "row" class below is important - it stop bootstrap adding padding to
column cells -->
<div class="row">
<!-- only large devices get the flanking columns -->
<div class= "col-md-3">
</div>
<!-- smaller devices occupy the full width of the device -->
<div class = "col-md-6 col-xs-12">
<form id = "dummyform"> </form>
<div id = "waiticon" style = "position: fixed; z-index: 10; display: none">
<div class="spinner-border" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
<!------------------ Header for management access --------------->
<div id= "management" style="max-width: 100%; display: none; margin-top: 1vh;">
<h2 style="text-align: center; margin-bottom: 1em;"><span id = "shopname"></span></h2>
<table style="width: 100%; text-align: center; border: 1px solid black; padding: 1.5vh; border-collapse: separate; background: linen;">
<tr>
<td id = "telephonebutton">
<a id = "telephonebuttonanchor" class="launchpadlink amend" title="Take telephone reservation">Telephone<br>Booking</a>
</td>
<td id = "viewerbutton">
<a id = "viewerbuttonanchor" class="launchpadlink view" title="View, cancel or re-book a reservation details">Review<br>Bookings</a>
</td>
<td id = "checkbutton">
<a id = "checkbuttonanchor" class="launchpadlink amend" title="Check for unresourced reservations">Check<br>Staffing</a>
</td>
</tr>
<tr>
<td id = "bankholidaybutton">
<a id = "bankholidaybuttonanchor" class="launchpadlink configure" title="Set bank holidays">Set Bank<br>Holidays</a>
</td>
<td id = "staffholidaybutton">
<a id = "staffholidaybuttonanchor" class="launchpadlink configure" title="Set staff absence/sickness">Set Staff<br>Absences</a>
</td>
<td id = "patternbutton">
<a id = "patternbuttonanchor" class="launchpadlink configure" title="Set Work Patterns">Set Work<br>Patterns</a>
</td>
</tr>
</table>
</div>
<!------------------ Header for email booker access --------------->
<div id = "booker" style="display: none; width: 100%; border: 2px solid black; margin-top: 1em; text-align: center;">
<img style = "margin : 1em; max-width: 90%;" src="barber.jpg?ver=1.1">
</div>
<div id = "dialogdisplay" style="width: 85%; padding-top: 1em; margin-left: auto; margin-right: auto; text-align: center;">
<iframe id="remember" name="remember" style="display: none;"></iframe> <!-- see notes on myEnterFunction() -->
<div id = "emaildisplay" style="display: none; padding: 1em; font-weight: bold;">
<p style = "font-size: 13px; font-weight: normal;">Enter a contact email address in the box below, select a free appointment slot and then
confirm your reservation.</p>
<!-- see notes in displayDay for special autocomplete consideration -->
<form id="emailform" target = "remember" autocomplete = "on"> <!-- only want autocomplete on email addresses -->
<label for="emailaddress">Email : </label> <!-- need some sort of label to identify the field to users because can't use placeholder - it knocks autocomlete out -->
<input id="emailaddress" name="emailaddress"
style = "height: 2em; text-align: center; font-weight: bold; background: aliceblue;"
maxlength="40" size="15"
onclick="emailaddresserror.style.display = 'none';">
</form>
<p id = "emailaddresserror" style = "display: none; color: red; margin-bottom: 0;">Oops - please enter a valid email address</p>
<p style="margin-top: 1em;">Service : <span id="emailserviceselection"></span></p>
</div>
<div id = "telephonedisplay" style="display: none; padding: 1em; font-weight: bold;">
<p style = "font-size: 13px; font-weight: normal;">Enter the customer's contact details in the box below, select a free appointment slot and then
click it to confirm the reservation.</p>
<form target = "remember" autocomplete = "off">
<label for="telephonenumber">Telephone : </label> <!-- pattern should make mobile phone display numeric pad -->
<input id="telephonenumber" type="text" name="telephonenumber" pattern="\d*"
style = "height: 2em; text-align: center; font-weight: bold; background: aliceblue;"
maxlength="40" size="15"
onclick="telephonenumbererror.style.display = 'none';">
</form>
<p id = "telephonenumbererror" style = "display: none; color: red;">Oops - please enter customer contact information</p>
<p style="margin-top: 1em;">Service : <span id="telephoneserviceselection"></span></p>
</div>
<div id = "changedisplay" style="display: none; padding: 1em; font-size: 13px; font-weight: normal;">
<p style = "font-size: 13px; font-weight: normal;">Please select a free appointment slot for your replacement reservation.</p>
</div>
<div id = "viewerdisplay" style="display: none; padding: 1em; font-size: 13px; font-weight: normal;">
<p style = "font-size: 13px; font-weight: normal;">Select the date/time of the reservation and then click the slot to view details.</p>
</div>
<div id="checkdisplay" style = "display: none; padding: 1em; font-size: 13px; font-weight: normal;">
<p>The list displayed below shows reservation slots that are over-booked
given current holiday/absence and work-pattern settings.</p>
<p>To send "please rebook" messages to <span style="color: red;">email bookers</span>,
check the first slot you want to rebook and then, while holding down the shift button,
check the last slot you want to rebook. Finally, click the "Send" button below. This will
send a message to the first email booker for each of the slots in the range.
Repeat as necessary.</p>
<button class='btn btn-primary' style="margin-bottom: 2em; margin-left: auto; margin-right: auto;"
onclick = "sendRebookMessages();"> <!-- cancellation params will be built dynamically later -->
Send Email Cancellation Messages</button>
<a id = "checkdisplayemailcancellationresult" style="display: none; color: blue; margin-bottom: 2em; margin-left: auto; margin-right: auto;">Despatch succeeded</a>
<p>To re-arrange bookings for a <span style="color: red;">telephone reservation</span>, use the telephone
number in the entry to contact the customer, then click the reservation entry to
negotiate an alternative date</p>
</div>
</div>
<div id = "resultsdisplay" style = "display: block; margin-top: 1em; margin-left: auto; margin-right: auto; text-align: center;">
<button id = "retardmonth" style="display: none; margin-left: auto; margin-right: auto; margin-bottom: 1em;" onclick = "retardMonthDisplay();"><span class="oi oi-caret-top"></span></button>
<div id = "monthdiv" style="display: block;" onmouseenter="myEnterFunction()"> <!-- see notes on myEnterFunction() -->
<span id="dayviewrange" style = "display: none;"></span>
<span id="monthdivcontent-2"></span>
<span id="monthdivcontent-1"></span>
<span id="monthdivcontent0"></span>
<span id="monthdivcontent1"></span>
<span id="monthdivcontent2"></span>
</div>
<div id = "daydiv" style="display: none;">
</div>
<div id = "checkdiv" style="display: none;">
<span id = "checkdivcontent"> </span>
<button class='btn btn-primary' style="margin-top: 2em; margin-left: auto; margin-right: auto;" onclick = "window.location.assign('booker.html?mode=viewer');">Reload</button>
</div>
<div id="paypalconfirmationmessage" style="display: none">
<p>Please confirm your reservation for
<span id = "paypalconfirmationmessagedatetime"></span>
with a Paypal payment.
</p> <!-- Note that the button gets built dynamically by handleServiceChangeOnEmail -->
<div id = "paypalconfirmationbutton" style="margin-top: 1em; margin-left: auto; margin-right: auto;">
</div>
<button id = "paypalcancelbutton" style="margin-top: 2em; margin-bottom: 1em; margin-left: auto; margin-right: auto;" onclick = "abortReservation();">Cancel</button> <!-- onclick is built by bookSLot -->
</div>
<div id = "bankholidaydisplay1" style="display: none; padding: 1em; font-size: 13px; font-weight: normal;"">
<span id = "bankholidaydisplay1content"></span>
</div>
<div id = "bankholidaydisplay2" style="display: none; padding: 1em; font-weight: normal;">
<button id = "retardbankholidaymonth" style="display: none; margin-left: auto; margin-right: auto; margin-bottom: 1em;" onclick = "retardMonthDisplay();"><span class="oi oi-caret-top"></span></button>
<p id = "bankholidaydisplay2content"></p>
</div>
<div id = "staffholidaydisplay1" style="display: none; padding: 1em; font-size: 13px; font-weight: normal;"">
<span id = "staffholidaydisplay1content"></span>
</div>
<div id = "staffholidaydisplay2" style="display: none; padding: 1em; font-weight: normal;">
<button id = "retardstaffholidaymonth" style="display: none; margin-left: auto; margin-right: auto; margin-bottom: 1em;" onclick = "retardMonthDisplay();"><span class="oi oi-caret-top"></span></button>
<p id = "staffholidaydisplay2content"></p>
</div>
<div id = "patterndisplay1" style="display: none; padding: 1em; font-size: 13px; font-weight: normal;"">
<span id = "patterndisplay1content"></span>
</div>
<div id = "patterndisplay2" style="display: none; font-size: 13px; font-weight: normal;"> // this is the table bit
<span id = "patterndisplay2content"></span>
</div>
<div id = "createnewchairdisplay"
style = "display: none; border: 1px solid black; width: 90%; margin-left: -45%;
position: absolute; top: 19vw; left: 50%;
background: gainsboro; z-index: 10;">
<h4 style="text-align: center;">Create New Chair</h4>
<form style="border: solid; width: 80%; padding: 3vh 1vw 4vh 1vw; margin: 4vh auto 5vh auto;">
<p>
<label id = "newchairnumberlabel" class = "formlabel">Chair number:</label>
<input id = "newchairnumber" type="text" title="New chair number" maxlength="3" size="3"
onkeyup = "document.getElementById('newchairnumbermessage').style.display = 'none';">
</p>
<p>
<label id = "newchairownerlabel" class = "formlabel">Chair owner name:</label>
<input id = "newchairowner" type="text" title="The name of the new chir owner" maxlength="20" size="10"
onkeyup = "document.getElementById('newchairnumbermessage').style.display = 'none';">
</p>
<p id = "newchairnumbermessage" style = "text-align: center; display: none;"></p>
<label class = "formlabel"></label>
<button class = 'btn btn-primary' style="margin-top: 1em;" onclick = "insertChair()" type="button">Create</button>
<button class = 'btn btn-primary' style="margin-top: 1em;"
onclick = "document.getElementById('createnewchairdisplay').style.display = 'none'; buildPatternDisplay(0);" type="button">Cancel</button>;
</form>
</div>
<div id = "reservationdetailsdisplay"
style = "display: none; border: 1px solid black; width: 90%; margin-left: -45%;
position: absolute; top: 19vw; left: 50%;
background: gainsboro; z-index: 10;"
onclick = "reservationdetailsdisplay.style.display = 'none';">
<span style = "position: absolute; top: .5em; right: 1em;">X</span>
<span id = "reservationdetails"></span>
</div>
<div id = "telephonecompletiondisplay" style = "display: none;">
<p>Thank you - your reservation is confirmed for <span id="telephonecompletiondisplaydate"></span>. Your reference code is <strong><span id="telephonecompletiondisplayreference"></span></strong></p>
<button class='btn btn-primary' style="margin-top: 2em; margin-left: auto; margin-right: auto;" onclick = "window.location.assign('index.php?mode=telephone');">Reload</button>
</div>
<div id = "changecompletiondisplay" style = "display: none;">
<p>Thank you - your rebooked reservation is confirmed for <span id="changecompletiondisplaydate"></span>. Your reference code is <strong><span id="changecompletiondisplayreference"></span></strong></p>
<button id = "changecompletiondisplaybutton" class='btn btn-primary' style="margin-top: 2em; margin-left: auto; margin-right: auto;" onclick = "window.location.assign('index.php?mode=viewer');">Reload</button>
</div>
<div id = "cancellationdisplay" style = "display: none;">
<p>Reservation <span id="cancelledreservationnumber"></span> has been cancelled</p>
<button class='btn btn-primary' style="margin-top: 2em; margin-left: auto; margin-right: auto;" onclick = "window.location.assign('index.php?mode=viewer');">Reload</button>
</div>
<div id = "paypalreturndisplay" style = "display: none;">
<p>Thank you for your payment. Please check your email for confirmation of your reservation and its
<br><strong>reference code : <span id="paypalreturndisplayreference"></span></strong></p>
<button class='btn btn-primary' style="margin-top: 2em; margin-left: auto; margin-right: auto;" onclick = "window.location.assign('index.php');">Reload</button>
</div>
</div>
</div>
<div class= "col-md-3">
</div>
</div>
</div>
<!-- start the javascript section by initialising global variables -->
<script>
var minChairNumber = 0;
var maxChairNumber = 10000;
if (location.hostname === "localhost" || location.hostname === "127.0.0.1") {
sourceRoot = "http://localhost/booker/";
} else {
sourceRoot = "website_root_domain/"; //**CONFIG REQUIRED** - set this to your website root domain - eg https://mywebsite.com/
}
// Global variables used to scope the view of takeup as either "this specific char"
// (minChairNumber = maxChairNumber) or "all chairs" (minChairNumber = 0, maxChairNumber = some
// ridiculously large number). This arrangement is a great convenience when it comes to
// building an sql statement for "get ths specific one or get them all" - we can just say
// "WHERE chair_number >= minChairNumber and chair_number <= maxChairNumber"
function myEnterFunction() {
// The email entry form has autocommit set to make things easy for regular bookers, but the form doesn't
// have a submit button and the form will only save to autocommit storage if it is submitted. We get round
// this by giving the monthdisplay div an onmouseenter function to myEnterFunction() where we can submit
// it dynamically. However initial trials revealed that the natural action of submit() is to reinitialise
// the form (so we lose the email address. The answer was to target the form at a hidden iform, see
// https://stackoverflow.com/questions/15462991/trigger-autocomplete-without-submitting-a-form#:~:text=Instead%20of%20using%20iframe%2C%20you,autocomplete%20will%20store%20the%20values.&text=You%20can%20also%20bind%20persistence,on%20the%20your%20application%20requirement.
document.getElementById("emailform").submit();
}
function buildServiceSelectionPicklists(shopCode, selectedServiceCode) {
// Build the email and telephone picklists for the services available for shopCode.
// Use selectedServiceCode to pecify the option to be displayed as the default
var oData = new FormData(form);
oData.append("helper_type", "build_service_selection_picklists");
oData.append("shop_url", shopUrl);
oData.append("selected_service_code", selectedServiceCode);
var oReq = new XMLHttpRequest();
oReq.open("POST", helperTarget, true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
// deal with the 2 returns
var xmlDoc = oReq.responseXML;
var JSONString = xmlDoc.getElementsByTagName("returns")[0].childNodes[0].nodeValue;
JSONString = prepareStringforJSONParse(JSONString);
var JSONObject = JSON.parse(JSONString);
document.getElementById('emailserviceselection').innerHTML = JSONObject.return1;
handleServiceChangeOnEmail();
document.getElementById('telephoneserviceselection').innerHTML = JSONObject.return2;
}
}
}
;
oReq.send(oData);
}
function handleServiceChangeOnEmail() {
// get the selected service and stick it in the global selectedServiceCode variable
selectedServiceCode = document.getElementById('emailservicepicklist').value;
// build an appropriate paypalconfirmationbutton for this service (tho note this
// won't get displayed until we actually eed it
var oData = new FormData(form);
oData.append("helper_type", "build_paypal_confirmation_button");
oData.append("shop_url", shopUrl);
oData.append("selected_service_code", selectedServiceCode);
var oReq = new XMLHttpRequest();
oReq.open("POST", helperTarget, true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
document.getElementById('paypalconfirmationbutton').innerHTML = response;
}
}
}
;
oReq.send(oData);
}
function handleServiceChangeOnTelephone() {
// get the selected service and stick it in the global selectedServiceCode variable
selectedServiceCode = document.getElementById('telephoneservicepicklist').value;
}
var form = document.forms.namedItem("dummyform");
var monthdiv = document.getElementById('monthdiv');
function displayMonth(year, month) {
// show wait icon in the middle of the screen
xPosition = window.innerWidth / 2;
yPosition = window.innerWidth / 2;
showWaitIcon();
// Display appointment-day status for the given "year" (yyyy) for a range of
// months centred on the given "month". For modes other than "viewer", only
// the "bottom" section of the range will be displayed - ie future
// appointment_days. For "viewer" mode, a toggled "history" button reveals
// the top half of the range, allowing past appointments to be inspected. The
// total width of the span is currently set at 5 months - ie the current month
// +/- two months previoussucceeding. Just for fun do this as three separate asynch
// calls (thus minimising"time-to-first-byte-displayed", tho it probably doesn't
// really matter). Curiously it proved essential to put the ''count loop that
// directs the results of each call to an appropriate monthdivcontent span
// had to be placed /outside/ the function launching the asynch call. When it
// was inside, the results seemed to overwrite each other and all that got
// returned was the display for the last one
var monthStart = 0;
if (mode == "viewer")
monthStart = toggleDayViewRange(year, month);
for (count = monthStart; count < 3; count++) {
displayMonthCount(year, month, count);
}
}
var dayViewRange = "historic";
var dayviewrange = document.getElementById("dayviewrange");
function toggleDayViewRange(year, month) {
dayviewrange.style.display = "block";
if (dayViewRange == "historic") {
dayViewRange = "current";
dayviewrange.innerHTML = "<button style='margin-bottom: 1em;' " +
"onclick = 'displayMonth(" + year + "," + month + ")'><span class='oi oi-caret-top'></span></button>";
document.getElementById("monthdivcontent-2").innerHTML = '';
document.getElementById("monthdivcontent-1").innerHTML = '';
return 0;
} else {
dayViewRange = "historic";
dayviewrange.innerHTML = "<button style='margin-bottom: 1em;' " +
"onclick = 'displayMonth(" + year + "," + month + ")'><span class='oi oi-caret-bottom'></span></button>";
return -2;
}
}
function displayMonthCount(year, month, count) {
var localYear = year;
var localMonth = month + count;
if (localMonth < 1) {
localYear = localYear - 1;
localMonth = localMonth + 12;
}
var oData = new FormData(form);
oData.append("helper_type", "build_calendar_month_display");
oData.append("shop_url", shopUrl);
oData.append("year", localYear);
oData.append("month", localMonth);
oData.append("mode", mode);
oData.append("min_chair_number", minChairNumber);
oData.append("max_chair_number", maxChairNumber);
var oReq = new XMLHttpRequest();
oReq.open("POST", helperTarget, true); // returns overwrite each other otherwise
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
// turn the wait icon off as soon as the first asynch call returns
hideWaitIcon();
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
daydiv.style.display = "none";
paypalconfirmationmessage.style.display = "none";
monthdiv.style.display = "block";
if (count == -2)
document.getElementById("monthdivcontent-2").innerHTML = response;
if (count == -1)
document.getElementById("monthdivcontent-1").innerHTML = response;
if (count == 0)
document.getElementById("monthdivcontent0").innerHTML = response;
if (count == 1)
document.getElementById("monthdivcontent1").innerHTML = response;
if (count == 2)
document.getElementById("monthdivcontent2").innerHTML = response;
}
}
};
oReq.send(oData);
}
function handleStylistChangeOnMonthDisplay() {
// get the selected chair and stick it in the global chair-range limits
var selectedChairNumber = document.getElementById('stylistmonthpicklist').value;
if (selectedChairNumber == 0) {
minChairNumber = 0;
maxChairNumber = 10000;
} else {
minChairNumber = maxChairNumber = selectedChairNumber;
}
displayMonth(todayYear, todayMonth);
}
function handleStylistChangeOnDayDisplay(year, month, day) {
// get the selected chair and stick it in the global chair-range limits
var selectedChairNumber = document.getElementById('stylistdaypicklist').value;
if (selectedChairNumber == 0) {
minChairNumber = 0;
maxChairNumber = 10000;
} else {
minChairNumber = maxChairNumber = selectedChairNumber;
}
displayDay(year, month, day);
}
function handleStylistChangeOnCheckDisplay() {
// get the selected chair and stick it in the global chair-range limits
var selectedChairNumber = document.getElementById('stylistmonthpicklist').value;
if (selectedChairNumber == 0) {
minChairNumber = 0;
maxChairNumber = 10000;
} else {
minChairNumber = maxChairNumber = selectedChairNumber;
}
buildCheckDisplay();
}
var bankholidaydisplaycontent = document.getElementById('bankholidaydisplaycontent');
function buildBankHolidayDisplay(year, month) {
// Display days that are unavailable as bank holidays
var oData = new FormData(form);
oData.append("helper_type", "build_bank_holiday_table_for_month_display");
oData.append("shop_url", shopUrl);
oData.append("year", year);
oData.append("month", month);
var oReq = new XMLHttpRequest();
oReq.open("POST", helperTarget, true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
// deal with the 2 returns
var xmlDoc = oReq.responseXML;
var JSONString = xmlDoc.getElementsByTagName("returns")[0].childNodes[0].nodeValue;
JSONString = prepareStringforJSONParse(JSONString);
var JSONObject = JSON.parse(JSONString);
bankholidaydisplay1.innerHTML = JSONObject.return1;
bankholidaydisplay2content.innerHTML = JSONObject.return2;
management.style.display = "block";
bankholidaydisplay1.style.display = "block";
bankholidaydisplay2.style.display = "block";
}
}
};
oReq.send(oData);
}
function toggleBankHoliday(year, month, day) {
// toggle the setting on the specified day
var oData = new FormData(form);
oData.append("helper_type", "toggle_bank_holiday");
oData.append("shop_url", shopUrl);
oData.append("bank_holiday_year", year);
oData.append("bank_holiday_month", month);
oData.append("bank_holiday_day", day);
var oReq = new XMLHttpRequest();
oReq.open("POST", helperTarget, true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
// refresh the month display
buildBankHolidayDisplay(year, month);
}
}
};
oReq.send(oData);
}
var staffholidaydisplaycontent = document.getElementById('staffholidaydisplaycontent');
function buildStaffHolidayDisplay(year, month, chairNumber) {
// Display days that are unavailable as staff absences (sickness/holiday).
// If no chair is specified, display the first you find and use this to set
// currentChairNumber
var oData = new FormData(form);
oData.append("helper_type", "build_staff_holiday_table_for_month_display");
oData.append("shop_url", shopUrl);
oData.append("year", year);
oData.append("month", month);
oData.append("chair_number", chairNumber);
var oReq = new XMLHttpRequest();
oReq.open("POST", helperTarget, true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
return;
}
// deal with the 3 returns
var xmlDoc = oReq.responseXML;
var JSONString = xmlDoc.getElementsByTagName("returns")[0].childNodes[0].nodeValue;
JSONString = prepareStringforJSONParse(JSONString);
var JSONObject = JSON.parse(JSONString);
staffholidaydisplay1.innerHTML = JSONObject.return1;
staffholidaydisplay2content.innerHTML = JSONObject.return2;
currentChairNumber = JSONObject.return3;
management.style.display = "block";
staffholidaydisplay1.style.display = "block";
staffholidaydisplay2.style.display = "block";
}
};
oReq.send(oData);
}
function toggleStaffHoliday(year, month, day, chairNumber) {
if (loginStatus == "loggedIn") {
// toggle the setting on the specified day
var oData = new FormData(form);
oData.append("helper_type", "toggle_staff_holiday");
oData.append("shop_url", shopUrl);
oData.append("staff_holiday_year", year);
oData.append("staff_holiday_month", month);
oData.append("staff_holiday_day", day);
oData.append("chair_number", chairNumber);
var oReq = new XMLHttpRequest();
oReq.open("POST", helperTarget, true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
// refresh the month display
buildStaffHolidayDisplay(year, month, chairNumber);
}
}
};
oReq.send(oData);
} else {
login();
}
}
function buildCheckDisplay() {
// Display unresourced reservations
var oData = new FormData(form);
oData.append("helper_type", "build_check_display");
oData.append("shop_url", shopUrl);
oData.append("min_chair_number", minChairNumber);
oData.append("max_chair_number", maxChairNumber);
var oReq = new XMLHttpRequest();
oReq.open("POST", helperTarget, true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
// set the check display
document.getElementById('checkdiv').style.display = "block";
document.getElementById('checkdivcontent').innerHTML = response;
}
}
};
oReq.send(oData);
}
function handlePatternClick(row, column) {
// set/unset the jr/row/column checkboxes for the current chair pattern
var element = document.getElementById("jr" + row + "c" + column);
// find out if this is a click or a shift/click
if (window.event.shiftKey) {
// find out the first row above "row" with the same checked status as row - set to 0 if none found
var firstRow = 0;
for (var i = row - 1; i >= 0; i--) {
var firstRow = i;
if (document.getElementById("jr" + i + "c" + column).checked == element.checked)
break;
}
// now set the range firstRow to row to whatever row is set to
for (var i = firstRow; i < +row; i++) {
document.getElementById("jr" + i + "c" + column).checked = element.checked;
}
}
}
function handleCheckClick(row) {
// set/unset the cr/row/ checkbox for the check display
var element = document.getElementById("cr" + row);
// find out if this is a click or a shift/click
if (window.event.shiftKey) {
// find out the first row above "row" with the same checked status as row - set to 0 if none found
var firstRow = 0;
for (var i = row - 1; i >= 0; i--) {
var firstRow = i;
if (document.getElementById("cr" + i).checked == element.checked)
break;
}
// now set the range firstRow to row to whatever row is set to
for (var i = firstRow; i < +row; i++) {
document.getElementById("cr" + i).checked = element.checked;
}
}
}
function displayDay(year, month, day) {
showWaitIcon(); // uses position captured by click on day
// Display appointment-status for a given day
var oData = new FormData(form);
oData.append("helper_type", "build_calendar_day_display");
oData.append("shop_url", shopUrl);
oData.append("year", year);
oData.append("month", month);
oData.append("day", day);
oData.append("mode", mode);
oData.append("min_chair_number", minChairNumber);
oData.append("max_chair_number", maxChairNumber);
var oReq = new XMLHttpRequest();
oReq.open("POST", helperTarget, true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
hideWaitIcon();
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
daydiv.innerHTML = response;
monthdiv.style.display = "none";
daydiv.style.display = "block";
}
}
};
oReq.send(oData);
}
var today = new Date();
var todayDay = today.getDay(); // 1-31
var todayMonth = today.getMonth() + 1; // 1-12
var todayYear = today.getFullYear(); //eg, 2020/
var cancelledReservationNumber;
function rebookReservation(cancelledReservationNumberReturn) {
// This is the "rebooking" mode triggered by management from the
// "manage reservations" button. It parallels the "change" mode
// (handled in bookSlot() instigated by bookers from an email link
// sent following cancellation of their appointment by management
// from the "check staffing" button
cancelledReservationNumber = cancelledReservationNumberReturn;
// at this point "check" mode turns into "rebook" mode - revert on "reload" in cancellationdisplay
viewerdisplay.style.display = "none";
changedisplay.style.display = "block"
changedisplay.style.border = "2px solid blue";
checkdisplay.style.display = "none";
checkdiv.style.display = "none";
mode = "rebook";
displayMonth(todayYear, todayMonth);
}
var currentDay = todayDay;
var currentMonth = todayMonth;
var currentYear = todayYear;
var retardmonth = document.getElementById("retardmonth");
var retardbankholidaymonth = document.getElementById("retardbankholidaymonth");
var currentChairNumber;
function advanceMonthDisplay() {
currentMonth++;
if (currentMonth == 13) {
currentMonth = 1;
currentYear++;
}
if (mode == "bankholiday") {
retardbankholidaymonth.style.display = "bloc k";
buildBankHolidayDisplay(currentYear, currentMonth);
}
if (mode == "staffholiday") {
retardstaffholidaymonth.style.display = "block";
buildStaffHolidayDisplay(currentYear, currentMonth, currentChairNumber);
}
}
function retardMonthDisplay() {
currentMonth--;
if (currentMonth == 0) {
currentMonth = 12;
currentYear--;
}
if (mode == "bankholiday") {
retardbankholidaymonth.style.display = "block";
buildBankHolidayDisplay(currentYear, currentMonth)
}
if (mode == "staffholiday") {
retardstaffholidaymonth.style.display = "block";
buildStaffHolidayDisplay(currentYear, currentMonth, currentChairNumber);
}
if (currentMonth == todayMonth && currentYear == todayYear) {
if (mode == "bankholiday")
retardbankholidaymonth.style.display = "none";
if (mode == "staffholiday")
retardstaffholidaymonth.style.display = "none";
}
}
function buildPatternDisplay(chairNumber) {
// build and display the working-hours patternDisplay for chairNumber
// if chairNumber is 0 we find the first and include this in the returns
var oData = new FormData(form);
oData.append("helper_type", "build_work_pattern_table_for_week_display");
oData.append("shop_url", shopUrl);
oData.append("chair_number", chairNumber);
var oReq = new XMLHttpRequest();
oReq.open("POST", helperTarget, true);
oReq.onload = function (oEvent) {
if (oReq.status == 200) {
var response = oReq.responseText;
if (response.indexOf("%failed%") != -1) {
alert(response);
return;
}
// deal with the 3 returns
var xmlDoc = oReq.responseXML;
var JSONString = xmlDoc.getElementsByTagName("returns")[0].childNodes[0].nodeValue;
JSONString = prepareStringforJSONParse(JSONString);
var JSONObject = JSON.parse(JSONString);
patterndisplay1.innerHTML = JSONObject.return1;
patterndisplay2.innerHTML = JSONObject.return2;
currentChairNumber = JSONObject.return3;
management.style.display = "block";
patterndisplay1.style.display = "block";
patterndisplay2.style.display = "block";
}
}
;
oReq.send(oData);
}
function prepareStringforJSONParse(input) {
// need to double escape non-printing characters to get them through parse
// not sure I really understand this - see
// https://stackoverflow.com/questions/42068/how-do-i-handle-newlines-in-jsonS
// \n characters seem to be getting through, even though they're removed in the
// "prepareStringforXMLandJSONParse" function in booker_helpers. We don't want
// them at all, so remove them here.
var output = input;
output = output.replace(/\n/g, "").replace(/\r/g, "\\\\r").replace(/\t/g, "\\\\t");
return output;
}
function savePattern(chairNumber) {
if (loginStatus == "loggedIn") {
// build the json for the current pattern display and apply this and
// the latest chairOwner name to the ecommerce_work_patterns record
// for the current chairNumber
var savepatternresult = document.getElementById("savepatternresult")
// The json is of the form:
//
// [
// {"time": 0, "working": [0,0,0,0,0,0,0]},
// {"time": 1, "working": [0,0,0,0,0,0,0]},
// {"time": 2 * slotLength, "working": {1,0,0,0,0,0,0]},
// ..
// {"time": 24 * numberOfSlotsPerHour - 1, "working": {0,0,0,0,0,0,0]},
// ]
// Where the 1 in "working" column 0 for time:200 means that this chair is
// going to be manned at 2am on Sunday
//
// The setting "1" is determined by seeing if the checkbox for the element