-
Notifications
You must be signed in to change notification settings - Fork 0
/
poll.php
1072 lines (996 loc) · 62.3 KB
/
poll.php
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>
<!--
* Tabler - Premium and Open Source dashboard template with responsive and high quality UI.
* @version 1.0.0-beta5
* @link https://tabler.io
* Copyright 2018-2022 The Tabler Authors
* Copyright 2018-2022 codecalm.net Paweł Kuna
* Licensed under MIT (https://github.com/tabler/tabler/blob/master/LICENSE)
-->
<?php include_once($_SERVER['DOCUMENT_ROOT']."/includes/kernel.php"); ?>
<?php $db_connection = db_connect(); ?>
<?php
$attendance_select_sortby = isset($_GET["sortby"])?$_GET["sortby"]:"";
$attendance_select_direction = isset($_GET["sortdir"])?$_GET["sortdir"]:"";
$theme = isset($_GET["theme"])?$_GET["theme"]:"";
if (!in_array($attendance_select_sortby, array("first_name", "last_name", "datetime", "instrument", "setup_group")))
{
$attendance_select_sortby = "last_name";
}
if (!in_array($attendance_select_direction, array("ASC", "DESC")))
{
$attendance_select_direction = "ASC";
}
if (isset($_GET["ensemble_name"]) and isset($_GET["term_name"]))
{
$ensemble_ID_query = $db_connection->prepare("SELECT `ID` FROM `ensembles` WHERE `safe_name`=? LIMIT 1");
$ensemble_ID_query ->bind_param("s", $_GET["ensemble_name"]);
$ensemble_ID_query ->execute();
$ensemble_ID_query ->bind_result($ensemble_ID);
$ensemble_ID_query ->fetch();
$ensemble_ID_query ->close();
$term_ID_query = $db_connection->prepare("SELECT `ID` FROM `terms` WHERE `safe_name`=? LIMIT 1");
$term_ID_query ->bind_param("s", $_GET["term_name"]);
$term_ID_query ->execute();
$term_ID_query ->bind_result($term_ID);
$term_ID_query ->fetch();
$term_ID_query ->close();
}
else
{
$ensemble_ID = (isset($_GET["ensemble_ID"]))?intval($_GET["ensemble_ID"]):0;
$term_ID = (isset($_GET["term_ID"]))?intval($_GET["term_ID"]):0;
}
?>
<?php
// Setup group colours.
function setup_group_colour($group_number)
{
switch($group_number)
{
case 1:
return "azure";
break;
case 2:
return "teal";
break;
case 3:
return "orange";
break;
case 4:
return "purple";
break;
default:
return "blue";
}
}
?>
<?php
$term_name = $db_connection->query("SELECT `name` FROM `terms` WHERE `ID`=".$term_ID." LIMIT 1")->fetch_array()[0];
$ensemble_name = $db_connection->query("SELECT `name` FROM `ensembles` WHERE `ID`=".$ensemble_ID." LIMIT 1")->fetch_array()[0];
$ensemble_safe_name = $db_connection->query("SELECT `safe_name` FROM `ensembles` WHERE `ID`=".$ensemble_ID." LIMIT 1")->fetch_array()[0];
if ($term_name == NULL)
{
$title = "Unknown term";
}
else if ($ensemble_name == NULL)
{
$title = "Unknown ".$config["taxonomy_ensemble"];
}
else
{
//$title = $ensemble_name." Rehearsals: ".$term_name;
$title = $ensemble_name." ".ucfirst($config["taxonomy_rehearsals"]).": ".$term_name;
}
$term_date_counter = [];
$term_date_counter_intederminate = [];
$headings_printed = false;
?>
<?php
if (login_valid() and login_restricted(-$ensemble_ID))
{
?>
<html lang="en">
<head>
<?php include($_SERVER['DOCUMENT_ROOT']."/includes/head.php"); ?>
<meta name="robots" content="noindex,nofollow">
<title><?=$title;?></title>
<script type="text/javascript">
var attendanceCounter = 0;
var memberCounter = 0;
function updateTotalChanged(element)
{
if (!element.classList.contains('attendance-changed'))
{
attendanceCounter++;
element.classList.add('attendance-changed');
}
if (!element.parentElement.parentElement.parentElement.parentElement.classList.contains('attendance-changed-member'))
{
memberCounter++;
element.parentElement.parentElement.parentElement.parentElement.classList.add('attendance-changed-member');
}
var attendanceCounters = document.getElementsByClassName('attendanceCounter');
for (var i=0; i<attendanceCounters.length; i++)
{
attendanceCounters[i].innerHTML = attendanceCounter;
}
var memberCounters = document.getElementsByClassName('memberCounter');
for (var i=0; i<memberCounters.length; i++)
{
memberCounters[i].innerHTML = memberCounter;
}
var updateAttendances = document.getElementsByClassName('updateAttendance');
for (var i=0; i<updateAttendances.length; i++)
{
updateAttendances[i].classList.remove("disabled");
}
document.getElementById('updateAttendanceOnScreen').style.visibility = "visible";
document.getElementById('updateAttendanceOnScreen').style.opacity = 0.9;
}
function viewEditHistory(member_ID, ensemble_ID, term_ID)
{
document.getElementById("edit-history-contents").innerHTML = '<span class="spinner-border spinner-border-sm me-2" role="status"></span> Loading...';
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "<?=$config['base_url'];?>/api/v1/get_attendance-edit-history.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send(
"member_ID=" + member_ID +
"&ensemble_ID=" + ensemble_ID +
"&term_ID=" + term_ID
);
xhttp.onload = function() {
const JSON_response = JSON.parse(this.responseText);
var edit_history_contents = '';
var edit_history_title = '';
if (JSON_response.status == "no_results") {
edit_history_contents = JSON_response.edit_history;
edit_history_title = JSON_response.member_name;
}
else if (JSON_response.status == "success") {
edit_history_contents = '<table class="table table-vcenter card-table table-striped">';
edit_history_contents += ' <thead>';
edit_history_contents += ' <tr>';
edit_history_contents += ' <th>When</th>';
edit_history_contents += ' <th>Rehearsal</th>';
edit_history_contents += ' <th>Changed to</th>';
edit_history_contents += ' <th>By</th>';
edit_history_contents += ' </tr>';
edit_history_contents += ' <tbody>';
for (let i=0; i<JSON_response.edit_history.length; i++) {
edit_history_contents += ' <tr>';
edit_history_contents += ' <td>'+JSON_response.edit_history[i][0]+'</td>';
edit_history_contents += ' <td>'+JSON_response.edit_history[i][1]+'</td>';
edit_history_contents += ' <td>'+JSON_response.edit_history[i][2]+'</td>';
edit_history_contents += ' <td>'+JSON_response.edit_history[i][3]+'</td>';
edit_history_contents += ' </tr>';
}
edit_history_contents += ' </tbody>';
edit_history_contents += '</table>';
edit_history_title = JSON_response.member_name;
}
else {
edit_history_contents = 'An error occured: '+JSON_response.error_message;
edit_history_title = 'An error occured';
}
document.getElementById("edit-history-contents").innerHTML = edit_history_contents;
document.getElementById("edit-history-title").innerHTML = edit_history_title;
}
}
function updateAttendance()
{
document.getElementById("update-attendance-result-title").innerHTML = "Updating...";
document.getElementById("update-attendance-result-text").innerHTML = "Please wait.";
document.getElementById("update-attendance-result-icon").innerHTML = '<span class="spinner-border spinner-border-sm me-2" role="status"></span>';
document.getElementById("update-attendance-result-button").innerHTML = "Loading...";
document.getElementById("update-attendance-result-button").classList.add("disabled");
document.getElementById("update-attendance-result-button").classList.remove("btn-danger");
document.getElementById("update-attendance-result-button").classList.remove("btn-success");
document.getElementById("update-attendance-result-button").classList.add("btn-primary");
document.getElementById("update-attendance-result-status").classList.remove("bg-danger");
document.getElementById("update-attendance-result-status").classList.remove("bg-success");
document.getElementById("update-attendance-result-status").classList.add("bg-primary");
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "<?=$config['base_url'];?>/api/v1/update_attendance.php", true);
xhttp.timeout = 10000;
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var attendance_data = document.getElementsByClassName("attendance-changed");
var extracted_attendance_data = [];
for (let i=0; i<attendance_data.length; i++)
{
var data = attendance_data[i].name.split("-");
var currentEntry = {};
currentEntry["member_ID"] = data[2].substring(4);
currentEntry["term_dates_ID"] = data[3].substring(8);
currentEntry["ensemble_ID"] = data[1].substring(8);
currentEntry["status"] = attendance_data[i].checked;
extracted_attendance_data.push(currentEntry);
}
xhttp.send("attendance_data="+JSON.stringify(extracted_attendance_data)+"&session_ID=<?=$_COOKIE["session_ID"];?>");
// xhttp.send(
// "session_id=" + document.getElementById("session_id").value +
// "&user_id=" + document.getElementById("user_id").value +
// "&shortname=" + document.getElementById("shortname").value +
// "&status=" + document.getElementById("status").value +
// "&redirect_url=" + document.getElementById("redirect_url").value
// );
xhttp.onload = function() {
const JSON_response = JSON.parse(this.responseText);
if (JSON_response.status == "success") {
document.getElementById("update-attendance-result-title").innerHTML = "Success!";
document.getElementById("update-attendance-result-text").innerHTML = "You updated the attendance of " + memberCounter + " people over " + attendanceCounter + " dates.";
document.getElementById("update-attendance-result-icon").innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" class="icon mb-2 text-green icon-lg" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><circle cx="12" cy="12" r="9" /><path d="M9 12l2 2l4 -4" /></svg>';
document.getElementById("update-attendance-result-button").innerHTML = "Great!";
document.getElementById("update-attendance-result-button").classList.remove("disabled");
document.getElementById("update-attendance-result-button").classList.remove("btn-danger");
document.getElementById("update-attendance-result-button").classList.remove("btn-primary");
document.getElementById("update-attendance-result-button").classList.add("btn-success");
document.getElementById("update-attendance-result-status").classList.remove("bg-danger");
document.getElementById("update-attendance-result-status").classList.remove("bg-primary");
document.getElementById("update-attendance-result-status").classList.add("bg-success");
memberCounter = 0;
attendanceCounter = 0;
}
else {
document.getElementById("update-attendance-result-title").innerHTML = "Oops! An error occured.";
document.getElementById("update-attendance-result-icon").innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" class="icon mb-2 text-red icon-lg" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><circle cx="12" cy="12" r="9"></circle><line x1="12" y1="8" x2="12" y2="12"></line><line x1="12" y1="16" x2="12.01" y2="16"></line></svg>';
document.getElementById("update-attendance-result-text").innerHTML = "Error message: " + JSON_response.error_message;
document.getElementById("update-attendance-result-button").innerHTML = "Understood.";
document.getElementById("update-attendance-result-button").classList.remove("disabled");
document.getElementById("update-attendance-result-button").classList.remove("btn-success");
document.getElementById("update-attendance-result-button").classList.remove("btn-primary");
document.getElementById("update-attendance-result-button").classList.add("btn-danger");
document.getElementById("update-attendance-result-status").classList.remove("bg-success");
document.getElementById("update-attendance-result-status").classList.remove("bg-primary");
document.getElementById("update-attendance-result-status").classList.add("bg-danger");
}
}
xhttp.ontimeout = function() {
document.getElementById("update-attendance-result-title").innerHTML = "Oops! An error occured.";
document.getElementById("update-attendance-result-icon").innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" class="icon mb-2 text-red icon-lg" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><circle cx="12" cy="12" r="9"></circle><line x1="12" y1="8" x2="12" y2="12"></line><line x1="12" y1="16" x2="12.01" y2="16"></line></svg>';
document.getElementById("update-attendance-result-text").innerHTML = "Error message: " + "Request to API timed out. <strong>Your attendance has not been saved.</strong>";
document.getElementById("update-attendance-result-button").innerHTML = "Understood.";
document.getElementById("update-attendance-result-button").classList.remove("disabled");
document.getElementById("update-attendance-result-button").classList.remove("btn-success");
document.getElementById("update-attendance-result-button").classList.remove("btn-primary");
document.getElementById("update-attendance-result-button").classList.add("btn-danger");
document.getElementById("update-attendance-result-status").classList.remove("bg-success");
document.getElementById("update-attendance-result-status").classList.remove("bg-primary");
document.getElementById("update-attendance-result-status").classList.add("bg-danger");
}
}
function setIndeterminate()
{
var indeterminates = document.getElementsByClassName("indeterminate");
for (let i=0; i<indeterminates.length; i++)
{
indeterminates[i].indeterminate = true;
}
}
function moveToTop()
{
var rowToMove = document.getElementById("move-to-top");
var rowToMoveTo = document.getElementById("move-to-top-location");
var table = document.getElementById("attendance-table");
table.insertBefore(rowToMove, rowToMoveTo);
}
function checkPollEnded()
{
<?php
$poll_ended = $db_connection->query("SELECT `datetime` FROM term_dates WHERE `term_ID`='".$term_ID."' AND (`is_featured` >= 0 OR `is_featured`='-".$ensemble_ID."') AND `datetime` >= UNIX_TIMESTAMP()");
if ($poll_ended->num_rows == 0)
{
$new_poll_info = $db_connection->query("SELECT `name`, `safe_name` FROM terms WHERE `ID`>='".$term_ID."' ORDER BY `ID` DESC LIMIT 1");
if ($new_poll_info->num_rows == 1)
{
$poll_info = $new_poll_info->fetch_assoc();
?>
var poll_ended = true;
var link = "<?=$config['base_url']."/".$ensemble_safe_name."/".$poll_info["safe_name"]."/";?>";
var ensemble = "<?=$ensemble_name;?>";
var new_term_name = "<?=$poll_info["name"];?>";
<?php
}
else
{
?>
var poll_ended = false;
<?php
}
}
else
{
?>
var poll_ended = false;
<?php
}
?>
if (poll_ended)
{
$('#poll-ended-box') .modal('show');
$('#poll-ended-box-icon') .html('<svg xmlns="http://www.w3.org/2000/svg" class="icon mb-2 text-yellow icon-lg" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M11.795 21h-6.795a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v4" /><circle cx="18" cy="18" r="4" /><path d="M15 3v4" /><path d="M7 3v4" /><path d="M3 11h16" /><path d="M18 16.496v1.504l1 1" /></svg>');
$('#poll-ended-box-title') .html("This poll has ended");
$('#poll-ended-box-text') .html("Did you mean to go to " + ensemble + " " + new_term_name + "?");
$('#poll-ended-box-button').attr("href", link);
}
}
function warnLeaving()
{
window.onbeforeunload = function (e) {
if (attendanceCounter > 0 || memberCounter > 0) {
return 1;
} else {
}
};
}
function hidePlaceholder()
{
document.getElementById("placeholder-loading").style.display = "none";
document.getElementById("main-content") .style.display = "block";
}
function pageLoaded()
{
setIndeterminate();
moveToTop();
checkPollEnded();
warnLeaving();
hidePlaceholder();
}
//window.onload = pageLoaded();
</script>
</head>
<body onload="pageLoaded();" >
<div class="wrapper">
<?php include($_SERVER['DOCUMENT_ROOT']."/includes/header.php"); ?>
<?php include($_SERVER['DOCUMENT_ROOT']."/includes/navigation.php"); ?>
<div class="page-wrapper">
<div class="page-body">
<div class="container-xl">
<!-- <div class="row row-cards mb-3">
<div class="col-md-3 col-lg-3">
<div class="card mb-3 bg-blue text-white">
<div class="card-stamp">
<div class="card-stamp-icon bg-white text-primary">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-device-mobile" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#2c3e50" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><rect x="7" y="4" width="10" height="16" rx="1" /><line x1="11" y1="5" x2="13" y2="5" /><line x1="12" y1="17" x2="12" y2="17.01" /></svg>
</div>
</div>
<div class="card-header">
<h3 class="card-title">On mobile?</h3>
</div>
<div class="card-body border-bottom py-3">
<p>Try scrolling left or right on the names below to see the checkboxes.</p>
</div>
</div>
</div>
<div class="col-md-3 col-lg-3">
<div class="card mb-3 bg-blue text-white">
<div class="card-stamp">
<div class="card-stamp-icon bg-white text-primary">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-device-desktop" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#2c3e50" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><rect x="3" y="4" width="18" height="12" rx="1" /><line x1="7" y1="20" x2="17" y2="20" /><line x1="9" y1="16" x2="9" y2="20" /><line x1="15" y1="16" x2="15" y2="20" /></svg>
</div>
</div>
<div class="card-header">
<h3 class="card-title">On desktop?</h3>
</div>
<div class="card-body border-bottom py-3">
<p>Scroll to bottom of page to reveal horizontal scrollbar, or use shift+scroll.</p>
</div>
</div>
</div>
<div class="col-md-6 col-lg-6">
<div class="card mb-6">
<div class="ribbon ribbon-top bg-red">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-alert-triangle" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#ffffff" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 9v2m0 4v.01" /><path d="M5 19h14a2 2 0 0 0 1.84 -2.75l-7.1 -12.25a2 2 0 0 0 -3.5 0l-7.1 12.25a2 2 0 0 0 1.75 2.75" /></svg>
</div>
<div class="card-header">
<h3 class="card-title">GDPR warning</h3>
</div>
<div class="card-body border-bottom py-3">
<p>Please be aware that anyone else in the group can see what you select in the options below. If you want either your name to be changed or your attendance hidden from others, then please <a href="mailto:<?=$config["admin_email"];?>" target="_blank">contact <?=$config["admin_name"];?></a>.</p>
</div>
</div>
</div>
</div> -->
<div class="col-12">
<div class="card">
<div class="card-header">
<h3 class="card-title"><?=$title;?></h3>
</div>
<?php
if ($ensemble_name == NULL)
{
?>
<div class="card-body">
<p>The ensemble given with ID <?=$ensemble_ID;?> is unknown. Please double-check the URL!</p>
</div>
<?php
}
else if ($term_name == NULL)
{
?>
<div class="card-body">
<p>The term given with ID <?=$term_ID;?> is unknown. Please double-check the URL!</p>
</div>
<?php
}
else
{
?>
<div class="card-body border-bottom py-3 col-form-label">
<div class="ms-auto text-muted">
<form method="get" action="" id="form-sort">
<input type="hidden" name="theme" value="<?=$theme;?>" form="form-sort" />
<input type="hidden" name="ensemble_ID" value="<?=$_GET['ensemble_ID'];?>" form="form-sort" />
<input type="hidden" name="term_ID" value="<?=$_GET['term_ID'];?>" form="form-sort" />
<div class="ms-2 d-inline-block">
<select class="form-select" name="sortby" form="form-sort">
<?php
if ($config["hide_instrument"])
{
$options = array("first_name" => "First name", "last_name" => "Last name", "setup_group" => "Setup group");
}
else
{
$options = array("first_name" => "First name", "last_name" => "Last name", "instrument" => "Instrument", "setup_group" => "Setup group");
}
foreach ($options as $value => $option)
{
$selected = ($attendance_select_sortby==$value)?"selected":"";
?>
<option value="<?=$value;?>" <?=$selected;?>><?=$option;?></option>
<?php
}
?>
</select>
</div>
<div class="ms-2 d-inline-block">
<select class="form-select" name="sortdir" form="form-sort">
<?php
$options = array("ASC" => "Asc.", "DESC" => "Desc.");
foreach ($options as $value => $option)
{
$selected = ($attendance_select_direction==$value)?"selected":"";
?>
<option value="<?=$value;?>" <?=$selected;?>><?=$option;?></option>
<?php
}
?>
</select>
</div>
<div class="ms-2 d-inline-block">
<button type="submit" class="btn btn-warning ms-auto my-2">Change sort</button>
</div>
</form>
</div>
<!-- <div class="ms-auto text-muted">
Search:
<div class="ms-2 d-inline-block">
<input type="text" class="form-control form-control-sm" aria-label="Search invoice">
</div>
</div> -->
</div>
<?php
if ($config["hide_past_dates"])
{
$term_dates_query = $db_connection->query("SELECT `datetime`, `datetime_end`, `ID`, `is_featured`, `setup_group` FROM term_dates WHERE `term_ID`='".$term_ID."' AND (`is_featured` >= 0 OR `is_featured`='-".$ensemble_ID."') AND `deleted`=0 AND `datetime_end` >= UNIX_TIMESTAMP() ORDER BY `datetime` ASC");
}
else
{
$term_dates_query = $db_connection->query("SELECT `datetime`, `datetime_end`, `ID`, `is_featured`, `setup_group` FROM term_dates WHERE `term_ID`='".$term_ID."' AND (`is_featured` >= 0 OR `is_featured`='-".$ensemble_ID."') AND `deleted`=0 ORDER BY `datetime` ASC");
}
$term_dates = array();
while ($result = $term_dates_query->fetch_array())
{
// TODO: REMOVE ME
// if ($ensemble_ID == 2 and $result[2] == 42)
// {
// }
// else
// {
$term_dates[] = $result;
// }
}
$no_term_dates = count($term_dates);
?>
<div class="table-responsive" id="main-content" style="display:none">
<form id="update_attendance">
<table id="attendance-table" class="table card-table table-vcenter text-nowrap datatable">
<div class="p-2 my-0 d-flex">
<p class="ms-auto m-0 text-muted">
<span style="padding-right: 10px;">You've changed <span class="memberCounter fw-bold">0</span> people's attendance over <span class="attendanceCounter fw-bold">0</span> dates.</span>
<a class="updateAttendance btn btn-primary ms-auto disabled my-2" onclick="updateAttendance()" data-bs-toggle="modal" data-bs-target="#update-attendance-result">Update</a>
<a class="btn my-2" onclick="location.reload()">Reset</a>
</p>
</div>
<tbody id="move-to-top-location">
<?php
$setup_group_counts_query = $db_connection->query("SELECT `setup_group`, COUNT(`setup_group`) AS `count` FROM `members` LEFT JOIN `members-ensembles` ON `members-ensembles`.`member_ID`=`members`.`ID` WHERE `members-ensembles`.`ensemble_ID`=".$ensemble_ID." AND `members`.`deleted`='0' GROUP BY `setup_group` ORDER BY `setup_group` ASC");
$setup_group_counts = array();
while ($result = $setup_group_counts_query->fetch_array())
{
$setup_group_counts[$result[0]] = $result[1];
}
$members = $db_connection->query("SELECT `first_name`, `last_name`, `instrument`, `members`.`ID` AS `ID`, `setup_group` FROM `members` LEFT JOIN `members-ensembles` ON `members-ensembles`.`member_ID`=`members`.`ID` WHERE `members-ensembles`.`ensemble_ID`=".$ensemble_ID." AND `members`.`deleted`='0' ORDER BY `".$attendance_select_sortby."` ".$attendance_select_direction);
if ($members->num_rows == 0)
{
?>
<tr>
<td width="99%">
No members to display.
</td>
<?php
foreach($term_dates as $term_date)
{
?>
<td></td>
<?php
}
?>
</tr>
<?php
}
else
{
$sort_initial = '';
while($member = $members->fetch_assoc())
{
switch ($attendance_select_sortby)
{
case 'first_name':
$current_sort_initial = substr($member["first_name"], 0, 1);
break;
case 'last_name':
$current_sort_initial = substr($member["last_name"], 0, 1);
break;
case 'datetime':
$current_sort_initial = '';
break;
case 'instrument':
$current_sort_initial = $member["instrument"];
break;
case 'setup_group':
$people_plural = ($setup_group_counts[$member["setup_group"]] > 1)?"people":"person";
$current_sort_initial = "Setup group ".$member["setup_group"]. " (".$setup_group_counts[$member["setup_group"]]." ".$people_plural.")";
break;
default:
$current_sort_initial = '';
break;
}
if (($current_sort_initial != $sort_initial and $config["repeat_headings"]) or !$headings_printed)
{
$headings_printed = true;
$sort_initial = $current_sort_initial;
?>
<thead>
<tr>
<?php
$options = array("first_name" => "First name", "last_name" => "Last name", "instrument" => "Instrument", "setup_group" => "Setup group");
?>
<th class="sticky-top w-1">Members (by <?=$options[$attendance_select_sortby];?>)
<?php
if ($attendance_select_direction == "DESC")
{
?>
<a href="?<?=http_build_query(array_merge($_GET, array('sortdir'=>'ASC')));?>">
<!-- Download SVG icon from http://tabler-icons.io/i/chevron-up -->
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-sm text-dark icon-thick" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><polyline points="6 15 12 9 18 15" /></svg>
</a>
<?php
}
else
{
?>
<a href="?<?=http_build_query(array_merge($_GET, array('sortdir'=>'DESC')));?>">
<!-- Download SVG icon from http://tabler-icons.io/i/chevron-down -->
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-sm text-dark icon-thick" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><polyline points="6 9 12 15 18 9"></polyline></svg>
</a>
<?php
}
?>
</th>
<?php
foreach($term_dates as $term_date)
{
$start = new DateTime();
$start ->setTimestamp($term_date[0]);
$start ->setTimeZone(new DateTimeZone('Europe/London'));
$end = new DateTime();
$end ->setTimestamp($term_date[1]);
$end ->setTimeZone(new DateTimeZone('Europe/London'));
($term_date[1]<time())?$strike_through_start="<s>":$strike_through_start="";
($term_date[1]<time())?$strike_through_end="</s>":$strike_through_end="";
($term_date[3])?$is_featured="bg-primary text-white":$is_featured="";
?>
<th class="sticky-top text-center align-text-top <?=$is_featured;?>">
<?=$strike_through_start;?>
<?=$start->format('M');?><br /><span style="line-height: 30px; font-size: 32px; margin:none;"><?=$start->format('j');?></span><br /><?=$start->format('D');?><br /><?=$start->format('H:i');?><br /><?=$end->format('H:i');?><!--<br /><span style="word-wrap: normal; white-space: pre-wrap">(<?=$term_date[4];?>)</span>-->
<?=$strike_through_end;?>
<br />
<?php
if ($term_date[4]>0)
{
?>
<span class="badge bg-<?= setup_group_colour($term_date[4]); ?> badge-notification badge-pill" title="<?= $start->format('M')." ".$start->format('j')." is setup group ".$term_date[4]."."; ?>"><?= $term_date[4]; ?></span>
<?php
}
?>
</th>
<?php
}
?>
</tr>
</thead>
<?php
if ($config["repeat_headings"])
{
?>
<tr>
<td colspan="100%">
<div class="" style="font-size: .75rem; padding: 0rem 0rem;"><?=$sort_initial;?></div>
</td>
</tr>
<?php
}
?>
<?php
}
?>
<tr>
<td width="99%">
<div class="d-flex py-1 align-items-center">
<span class="avatar me-2"><?=substr($member["first_name"], 0, 1).substr($member["last_name"], 0, 1);?></span>
<div class="flex-fill">
<div class="font-weight-medium">
<?php if ($config["hide_instrument"]) { ?>
<?=$member["first_name"]." ".$member["last_name"];?>
<?php } else { ?>
<?=$member["first_name"]." ".$member["last_name"];?> <span class="">(<?=$member["instrument"];?>)</span>
<?php } ?>
<?php
if ($member["setup_group"]>0)
{
?>
<span class="badge bg-<?= setup_group_colour($member["setup_group"]); ?> badge-notification badge-pill" title="<?= $member["first_name"]." is part of setup group ".$member["setup_group"]."."; ?>"><?= $member["setup_group"]; ?></span>
<?php
}
?>
</div>
<a class="text-muted" style="cursor: pointer;" onclick="viewEditHistory(<?=$member["ID"];?>, <?=$ensemble_ID;?>, <?=$term_ID;?>)" data-bs-toggle="modal" data-bs-target="#edit-history">
<!-- Download SVG icon from http://tabler-icons.io/i/pencil -->
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M4 20h4l10.5 -10.5a1.5 1.5 0 0 0 -4 -4l-10.5 10.5v4" /><line x1="13.5" y1="6.5" x2="17.5" y2="10.5" /></svg>
<?php
$last_edited_query = $db_connection->query("SELECT `edit_datetime` FROM `attendance` LEFT JOIN `term_dates` ON `term_dates`.`ID`=`attendance`.`term_dates_ID` WHERE `attendance`.`member_ID`='".$member['ID']."' AND `attendance`.`ensemble_ID`=".$ensemble_ID." AND `term_dates`.`term_ID`='".$term_ID."' ORDER BY `edit_datetime` DESC LIMIT 1");
if ($last_edited_query->num_rows>0)
{
$last_edited = $last_edited_query->fetch_array()[0];
}
else
{
$last_edited = 0;
}
?>
<?=findTimeAgo($last_edited)?>
</a>
</div>
</div>
</td>
<?php
foreach($term_dates as $term_date)
{
$attendance_query = $db_connection->query("SELECT `status` FROM `attendance` WHERE `member_ID`='".$member['ID']."' AND `ensemble_ID`='".$ensemble_ID."' AND `term_dates_ID`='".$term_date[2]."' ORDER BY `edit_datetime` DESC LIMIT 1");
if ($attendance_query->num_rows>0)
{
$attendance = $attendance_query->fetch_array()[0];
}
else
{
$attendance = NULL;
}
// if ($member["first_name"] == "Samantha")
// {
// echo "SELECT `status` FROM `attendance` WHERE `member_ID`='".$member['ID']."' AND `ensemble_ID`='".$ensemble_ID."' AND `term_dates_ID`='".$term_date[1]."' ORDER BY `edit_datetime` DESC LIMIT 12";
// }
//($attendance==NULL)?$attendance="1":$attendance=$attendance;
if ($config["assume_attending"])
{
$indeterminate = "";
(($attendance=="1") || ($attendance==NULL))?$checked="checked":$checked="";
if (($attendance=="1") || ($attendance==NULL))
{
$term_date_counter[strval($term_date[2])]++;
}
}
else
{
($attendance==NULL)?$indeterminate="indeterminate":$indeterminate="";
($attendance=="1")?$checked="checked":$checked="";
if ($attendance=="1")
{
$term_date_counter[strval($term_date[2])]++;
}
elseif ($attendance == NULL)
{
$term_date_counter_intederminate[strval($term_date[2])]++;
}
}
($term_date[1]<time())?$disabled="disabled":$disabled="";
($term_date[3])?$is_featured="bg-blue-25":$is_featured="";
?>
<td class="text-center <?=$is_featured;?>">
<div class="col-auto">
<label class="form-colorcheckbox bigger" style="margin: 0px;">
<input name="attendance-ensemble<?=$ensemble_ID;?>-user<?=$member["ID"];?>-termdate<?=$term_date[2];?>" form="update_attendance" type="checkbox" value="lime" class="form-colorcheckbox-input <?=$indeterminate;?>" <?=$checked;?> <?=$disabled;?> onchange="updateTotalChanged(this)" />
<span class="form-colorcheckbox-color "></span>
</label>
<?php
if ($term_date[4] > 0 && $member["setup_group"] == $term_date[4])
{
?>
<span class="badge bg-<?= setup_group_colour($member["setup_group"]) ;?>" style="z-index:1000; position: relative; right: 2px; bottom: 24px; border-color: #ffffff; box-shadow: 0px 0px 3px #000000;"></span>
<?php
}
else
{
?>
<span class="badge bg-blue" style="visibility: hidden;"></span>
<?php
}
?>
</div>
</td>
<?php
}
?>
</tr>
<?php
}
}
// $attendance = $db_connection->query("SELECT `attendance`.`status`, `attendance`.`ID` FROM `attendance` INNER JOIN `term_dates` ON `attendance`.`term_dates_ID`=`term_dates`.`term_ID` WHERE `term_dates`.`term_ID`=1 GROUP BY `attendance`.`ID`");
//$attendance = $db_connection->query("SELECT * FROM `attendance`");
?>
<tr>
<td><!--<div class="avatar bg-primary" style="height: 1rem; width: 1rem;"></div> = concert--></td>
<?php
foreach($term_dates as $term_date)
{
if ($config["assume_attending"])
{
?>
<td class="text-center"><strong><?=isset($term_date_counter[$term_date[2]])?$term_date_counter[$term_date[2]]:"0";?></strong></td>
<?php
}
else
{
?>
<td class="text-center"><strong><?=isset($term_date_counter[$term_date[2]])?$term_date_counter[$term_date[2]]:"0";?></strong> (<?=isset($term_date_counter_intederminate[$term_date[2]])?$term_date_counter_intederminate[$term_date[2]]:"0";?>)</td>
<?php
}
}
?>
</tr>
<tr id="move-to-top">
<td><!--<div class="avatar bg-primary" style="height: 1rem; width: 1rem;"></div> = concert--></td>
<?php
foreach($term_dates as $term_date)
{
if ($config["assume_attending"])
{
?>
<td class="text-center"><strong><?=isset($term_date_counter[$term_date[2]])?$term_date_counter[$term_date[2]]:"0";?></strong></td>
<?php
}
else
{
?>
<td class="text-center"><strong><?=isset($term_date_counter[$term_date[2]])?$term_date_counter[$term_date[2]]:"0";?></strong> (<?=isset($term_date_counter_intederminate[$term_date[2]])?$term_date_counter_intederminate[$term_date[2]]:"0";?>)</td>
<?php
}
}
?>
</tr>
</tbody>
</table>
</form>
</div>
<div class="card" id="placeholder-loading">
<ul class="list-group list-group-flush placeholder-glow">
<li class="list-group-item opacity-100">
<div class="row align-items-center">
<div class="col-auto">
<div class="avatar avatar-rounded placeholder"></div>
</div>
<div class="col-7">
<div class="placeholder placeholder-xs col-9"></div>
<div class="placeholder placeholder-xs col-7"></div>
</div>
<div class="col-2 ms-auto text-end">
<div class="placeholder placeholder-xs col-8"></div>
<div class="placeholder placeholder-xs col-10"></div>
</div>
</div>
</li>
<li class="list-group-item opacity-80">
<div class="row align-items-center">
<div class="col-auto">
<div class="avatar avatar-rounded placeholder"></div>
</div>
<div class="col-7">
<div class="placeholder placeholder-xs col-9"></div>
<div class="placeholder placeholder-xs col-7"></div>
</div>
<div class="col-2 ms-auto text-end">
<div class="placeholder placeholder-xs col-8"></div>
<div class="placeholder placeholder-xs col-10"></div>
</div>
</div>
</li>
<li class="list-group-item opacity-60">
<div class="row align-items-center">
<div class="col-auto">
<div class="avatar avatar-rounded placeholder"></div>
</div>
<div class="col-7">
<div class="placeholder placeholder-xs col-9"></div>
<div class="placeholder placeholder-xs col-7"></div>
</div>
<div class="col-2 ms-auto text-end">
<div class="placeholder placeholder-xs col-8"></div>
<div class="placeholder placeholder-xs col-10"></div>
</div>
</div>
</li>
<li class="list-group-item opacity-40">
<div class="row align-items-center">
<div class="col-auto">
<div class="avatar avatar-rounded placeholder"></div>
</div>
<div class="col-7">
<div class="placeholder placeholder-xs col-9"></div>
<div class="placeholder placeholder-xs col-7"></div>
</div>
<div class="col-2 ms-auto text-end">
<div class="placeholder placeholder-xs col-8"></div>
<div class="placeholder placeholder-xs col-10"></div>
</div>
</div>
</li>
<li class="list-group-item opacity-20">
<div class="row align-items-center">
<div class="col-auto">
<div class="avatar avatar-rounded placeholder"></div>
</div>
<div class="col-7">
<div class="placeholder placeholder-xs col-9"></div>
<div class="placeholder placeholder-xs col-7"></div>
</div>
<div class="col-2 ms-auto text-end">
<div class="placeholder placeholder-xs col-8"></div>
<div class="placeholder placeholder-xs col-10"></div>
</div>
</div>
</li>
</ul>
</div>
<div class="card-footer d-flex">
<p class="ms-auto m-0 text-muted">
<span style="padding-right: 10px;">You've changed <span class="memberCounter fw-bold">0</span> people's attendance over <span class="attendanceCounter fw-bold">0</span> dates.</span>
<a class="updateAttendance btn btn-primary ms-auto disabled my-2" onclick="updateAttendance()" data-bs-toggle="modal" data-bs-target="#update-attendance-result">Update</a>
<a class="btn my-2" onclick="location.reload()">Reset</a>
</p>
</div>
<?php
}
?>
</div>
</div>
</div>
</div>
</div>
<?php include($_SERVER['DOCUMENT_ROOT']."/includes/footer.php"); ?>
</div>
</div>
<div class="modal modal-blur fade" id="update-attendance-result" tabindex="-1" role="dialog" aria-hidden="true" data-bs-backdrop="static" data-bs-keyboard="false">
<div class="modal-dialog modal-sm modal-dialog-centered" role="document">
<div class="modal-content">
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" onclick="javascript:window.location.reload()"></button>
<div id="update-attendance-result-status" class="modal-status bg-success"></div>
<div class="modal-body text-center py-4">
<div id="update-attendance-result-icon">
Result icon
</div>
<h3 id="update-attendance-result-title">Result title</h3>
<div class="text-muted" id="update-attendance-result-text">Result text</div>
</div>
<div class="modal-footer">
<div class="w-100">
<div class="row">
<div class="col"><a id="update-attendance-result-button" href="#" class="btn btn-success disabled w-100" data-bs-dismiss="modal" onclick="javascript:window.location.reload()">
Result button text
</a></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal modal-blur fade" id="edit-history" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="edit-history-title">Adam Blakey</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" id="edit-history-contents">
Content
</div>
<div class="modal-footer">
<button type="button" class="btn me-auto" data-bs-dismiss="modal">Close</button>
</div>