-
Notifications
You must be signed in to change notification settings - Fork 0
/
user80.js
2389 lines (2263 loc) · 96.5 KB
/
user80.js
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
// Helper functions for all users and admins
// Declare global variables
var result_old;
var overviewmaps;
var bookingstatus;
var meetingstatus;
var printerstatus;
var stickaddresses;
var searchtext = "";
var inMobileMode = false;
var activecalendar = '';
var userdate = '';
function toggleUsermode() {
if (setting_usermode == 'edit') {
setting_usermode = 'user';
$("#usermode_switch").css("background-color", "orange");
}
else {
setting_usermode = 'edit';
$("#usermode_switch").css("background-color", "#333");
}
document.cookie = "setting_usermode=" + setting_usermode+'; expires=Fri, 31 Dec 9999 23:59:59 GMT; SameSite=Lax';
$("#usermode_switch").html(setting_usermode);
updateDesks(true);
}
function timezoneDate() {
let tz_datetime_str = new Date().toLocaleString("en-US", { timeZone: region });
let date_tz = new Date(tz_datetime_str);
let year = date_tz.getFullYear();
let month = ("0" + (date_tz.getMonth() + 1)).slice(-2);
let date = ("0" + date_tz.getDate()).slice(-2);
let timezoneDate = year + "-" + month + "-" + date;
return timezoneDate;
}
function formatDate(date) {
var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
return [year, month, day].join('-');
}
function getMondayOfCurrentWeek() {
const today = new Date(timezoneDate());
const first = today.getDate() - today.getDay() + 1;
const monday = new Date(today.setDate(first));
return formatDate(monday);
}
function updateCounter() {
var checkcounter = document.getElementById('visitorcounter');
if (checkcounter == null) {
var p = document.getElementById('buttons_right');
var newElement = document.createElement('div');
newElement.setAttribute('id', 'visitorcounter');
newElement.setAttribute('style', 'float:right; margin:5px; width:45px;height:15px; background:#333333; border-radius:15px; border: white 5px solid; padding:11px;opacity:0.8; text-align:center; line-height:15px;');
newElement.innerHTML = '';
p.appendChild(newElement);
}
$.ajax({
// fetch data from stats API
url: 'rest/stats/?interval=day&limit=1',
async: true,
type: 'get',
dataType: 'JSON',
success: function(result){
//console.log(result)
document.getElementById('visitorcounter').innerHTML=result[0]['count']
console.log('[Stats] Updated data for daily visitor counter.')
},
error: function()
{
console.log('[Stats] Could not get data for daily visitor counter from database.')
}
});
}
function addStat () {
$.ajax({
url: 'rest/stats',
async: true,
type: 'get',
dataType: 'JSON',
success: function(result){
// console.log('Succesfully added stat via stats API')
},
error: function (result) {
console.log('Could not access stats API')
}
});
}
function loginUser(mode) {
if (mode == 'admin') {
remoteurl = '../rest/account/index.php'
}
else {
remoteurl = 'rest/account/index.php'
}
$("#loginstatus").css("display","none");
$.ajax({
type: 'GET',
url: remoteurl,
data: $("#LoginForm").serialize(),
contentType: false,
cache: false,
//processData:false,
beforeSend: function(){
senddata = $("#Login").serialize();
},
error:function(){
console.log('error');
},
success: function(logindata){
var logstatus = logindata.status;
var logmessage = logindata.message;
if (logstatus == 'error') {
var color='#D82626'
}
else if (logstatus == 'ok') {
var color='#35842E'
}
$("#loginstatus").css("background-color",color);
$("#loginstatus").html(logmessage);
$("#loginstatus").css("display","").delay(1000).fadeOut("slow");
if (logstatus == 'ok') { location.reload(); }
}
});
}
function samlLogin(mode) {
if (mode == 'admin') {
remoteurl = '../rest/account/index.php'
}
else {
remoteurl = 'rest/account/index.php'
}
$.ajax({
type: 'GET',
url: remoteurl,
data: {mode:"samllogin"},
contentType: false,
cache: false,
//processData:false,
beforeSend: function(){
},
error:function(){
console.log('error');
},
success: function(logindata){
var logstatus = logindata.status;
var logmessage = logindata.message;
if (logstatus == 'ok') { location.reload(); }
}
});
}
function logoutUser(mode) {
if (mode == 'admin') {
remoteurl = '../rest/account/index.php'
}
else {
remoteurl = 'rest/account/index.php'
}
$.ajax({
type: 'GET',
url: remoteurl,
data: {mode:'logout'},
contentType: false,
cache: false,
//processData:false,
beforeSend: function(){
senddata = $("#Login").serialize();
},
error:function(){
console.log('error');
},
success: function(logindata){
var logstatus = logindata.status;
var logmessage = logindata.message;
if (logstatus == 'error') {
var color='#D82626'
}
else if (logstatus == 'ok') {
var color='#35842E'
}
if (logstatus == 'ok') {
if (mode == 'admin') {
location.href='../index.php';
}
else {
location.reload();
}
}
}
});
}
function loginForm (showform,mode) {
switch (showform) {
case true:
var logindata =`
<div id="logindata" style="position:absolute; left:25%; top:25%; width:50%; height:50%;">
<form id="LoginForm" name="Login" method="post" autocomplete="off">
<input type="hidden" name="mode" value="login">
<div style="width:30%; float:left;display:inline;">Username</div>
<input type="text" name="user" value="" size="10" autofocus style="width:70%; float:left; display:inline;"><br />
<div style="width:30%; float:left;display:inline;">Password</div>
<input type="password" name="password" value="" size="10" style="width:70%; float:left; display:inline;"><br /><br />
<input type="submit" value="Login" style="width:45%; float: left;" formaction='javascript:loginUser("`+mode+`")'>
</form>
<input type="button" value="Cancel" style="width:45%; float:right; background-color:#f00;" onClick="loginForm(false)">
<div id="loginstatus" style="height:43px; border-top: 8px; width:100%;border-radius:4px;background-color:#00f;float:left;display:none;text-align:center;line-height:43px;"></div>
</div>
`;
var newElement = document.createElement('div');
newElement.setAttribute('id', 'loginform');
newElement.innerHTML = logindata;
document.body.appendChild(newElement);
$('#loginform').css('position','fixed');
$('#loginform').css('left','0px');
$('#loginform').css('top','0px');
$('#loginform').css('width','100%');
$('#loginform').css('height','100%');
$('#loginform').css('background-color','#000');
$('#loginform').css('opacity','0.85');
$('#loginform').css('z-index','200');
$('#logindata').css('transform','scale(1.5)');
$('#logindata').css('transform-origin','50% 50%');
// Hide icon
var icon = '';
$("#loginicon").html(icon);
break;
case false:
// Remove old sticky if exists
var element = document.getElementById('loginform');
if (element !== null) {
element.parentNode.removeChild(element);
}
// Output icon
var icon = '<input type="image" src="images/login-user.png" alt="e" onClick="loginForm(true)" onmouseover=this.src="images/login-user_on.png" onmouseout=this.src="images/login-user.png">';
$("#loginicon").html(icon);
updateCounter();
break;
default:
break;
}
}
function showMapplate (mapname) {
var mapinfo = overviewmaps.find(o => Object.entries(o).find(([k, value]) => k === 'mapname' && value === mapname) !== undefined);
var plateX = Number(mapinfo.x)+(Number(mapinfo.flagsize)/2)-100;
var plateY = Number(mapinfo.y)+(Number(mapinfo.flagsize)/2)-100;
if (plateY < 0) {
var y_nameplate = 0;
}
else {
var y_nameplate = plateY;
}
copylink_full = 'https://'+window.location.hostname+root+'?map='+mapinfo.mapname;
copylink_full = encodeURI(copylink_full);
if (plateX > (targetScreenWidth/2)) {
var outputmapplate= '<div class="leftmapplate" style="top:'+y_nameplate+'px;left:'+(plateX-400)+'px">'
+ '<div class="leftmapplate_goto" onclick=hideMapplate()><img src="images/close3.png" style="width:70px;margin-top:60px;margin-right:20px;"></div>'
+ '<div class="leftmapplate_top">'+ucWords(mapinfo.mapname)+'</div>'
+ '<div class="leftmapplate_textbox" >'+mapinfo.address+'</div>'
+ '<img class="leftmapplate_avatar" src="countryflags/'+mapinfo.country+'.svg" style="background:rgba(0, 200, 200,1.0)" />'
+ '<a href="'+root+'?map='+mapinfo.mapname+'">'
+ '<img class="leftmapplate_close" src="images/openlink.png" />'
+ '</a>'
+ '<img class="leftmapplate_copy" src="images/copy.png" onclick="copyToClipboard(\''+copylink_full+'\')" />'
+ '</div>';
}
else {
var outputmapplate= '<div class="rightmapplate" style="top:'+y_nameplate+'px;left:'+plateX+'px">'
+ '<div class="rightmapplate_goto" onclick=hideMapplate()><img src="images/close3.png" style="width:70px;margin-top:60px;margin-left:20px;"></div>'
+ '<div class="rightmapplate_top">'+ucWords(mapinfo.mapname)+'</div>'
+ '<div class="rightmapplate_textbox" >'+mapinfo.address+'</div>'
+ '<img class="rightmapplate_avatar" src="countryflags/'+mapinfo.country+'.svg" style="background:rgba(0, 200, 200,1.0)" />'
+ '<a href="'+root+'?map='+mapinfo.mapname+'">'
+ '<img class="rightmapplate_close" src="images/openlink.png" />'
+ '</a>'
+ '<img class="rightmapplate_copy" src="images/copy.png" onclick="copyToClipboard(\''+copylink_full+'\')" />'
+ '</div>';
}
// Remove old mapplate if exists
var element = document.getElementById('mapplate');
if (element !== null) {
element.parentNode.removeChild(element);
}
// Adds mapplate to the document
var p = document.getElementById('mapOverview');
var newElement = document.createElement('div');
newElement.setAttribute('id', 'mapplate');
newElement.innerHTML = outputmapplate;
p.appendChild(newElement);
}
function hideMapplate () {
// Remove old mapplate if exists
var element = document.getElementById('mapplate');
if (element !== null) {
element.parentNode.removeChild(element);
}
}
function hideNameplate () {
// Removes an element from the document
var element = document.getElementById('nameplate');
if (element !== null) {
element.parentNode.removeChild(element);
}
}
function hideSticky () {
// Removes an element from the document
var element = document.getElementById('stickynameplate');
if (element !== null) {
element.parentNode.removeChild(element);
}
activecalendar = '';
}
function highlightManagers() {
var managers = result_old.desks.filter(element => element.color !="");
$.each( managers, function( t, manager ){
// Create highlightmarker
var p = document.getElementById('deskitems');
var newElement = document.createElement('div');
newElement.setAttribute('id', 'manager' + manager.id);
p.appendChild(newElement);
//newElement.innerHTML = output;
$('#manager' + manager.id).css('position','absolute');
$('#manager' + manager.id).css('left',(manager.x-(12*itemscale)) + 'px');
$('#manager' + manager.id).css('top',(manager.y-(12*itemscale)) + 'px');
$('#manager' + manager.id).css('width',(18*itemscale)+'px');
$('#manager' + manager.id).css('height',(18*itemscale)+'px');
$('#manager' + manager.id).css('border',(3*itemscale)+'px solid '+manager.color);
$('#manager' + manager.id).css('background-color', 'transparent');
$('#manager' + manager.id).css('border-radius','50%');
$('#manager' + manager.id).css('z-index','9');
});
}
function showDesknumbers() {
var desks = result_old.desks;
if (setting_shownames == 0) {
lineheight = 20;
}
else {
lineheight = 10;
}
if (setting_printmode == 0) {
var textcolor = '#fff';
}
else {
var textcolor = '#000';
}
$.each( desks, function( x, desk ){
switch (desk.dsk) {
case "Exit":
case "Meeting":
case "Restroom":
case "FirstAid":
case "Firstaid":
case "Food":
case "KeycardLock":
case "KeyLock":
case "Printer":
case "Service":
var desknumber = desk.empl;
var displayNumber = false;
break;
default:
var desknumber = desk.dsk;
var displayNumber = true;
break;
}
desknumber = desknumber.substring(desknumber.indexOf("-") + 1);
if (desk.dsk != "Floor" && displayNumber == true && desk.desktype != "shareddesk") {
// Create overlayed label
var p = document.getElementById('deskitems');
var newElement = document.createElement('div');
newElement.setAttribute('id', 'desknumber' + desk.id);
newElement.innerHTML = desknumber;
p.appendChild(newElement);
//newElement.innerHTML = output;
$('#desknumber' + desk.id).css('position','absolute');
$('#desknumber' + desk.id).css('left',(desk.x-(20*itemscale)) + 'px');
$('#desknumber' + desk.id).css('top',(desk.y-(10*itemscale)) + 'px');
$('#desknumber' + desk.id).css('width',(40*itemscale)+'px');
$('#desknumber' + desk.id).css('height',(20*itemscale)+'px');
$('#desknumber' + desk.id).css('text-align','center');
$('#desknumber' + desk.id).css('font-size','8px');
$('#desknumber' + desk.id).css('color',textcolor);
$('#desknumber' + desk.id).css('line-height',lineheight+'px');
$('#desknumber' + desk.id).css('background-color','transparent');
$('#desknumber' + desk.id).css('z-index','9');
$('#desknumber' + desk.id).css('transform','scale('+itemscale+')');
$('#desknumber' + desk.id).css('transform-origin','50% 0%');
}
});
}
function showNames() {
var desks = result_old.desks;
if (setting_printmode == 0) {
var textcolor = '#fff';
}
else {
var textcolor = '#000';
}
$.each( desks, function( x, desk ){
if (setting_desknumbers == 0) {
lineheight = 20;
divtop = (desk.y-(10*itemscale))
}
else {
lineheight = 10;
divtop = desk.y
}
switch (desk.dsk) {
case "Exit":
case "Meeting":
case "Restroom":
case "FirstAid":
case "Firstaid":
case "Food":
case "KeycardLock":
case "KeyLock":
case "Printer":
case "Service":
var divname = '';
var displayNumber = false;
break;
default:
var divname = desk.fname;
var displayNumber = true;
break;
}
if (desk.dsk != "Floor" && displayNumber == true && desk.desktype != "shareddesk") {
// Create overlayed label
var p = document.getElementById('deskitems');
var newElement = document.createElement('div');
newElement.setAttribute('id', 'name' + desk.id);
newElement.innerHTML = divname;
p.appendChild(newElement);
//newElement.innerHTML = output;
$('#name' + desk.id).css('position','absolute');
$('#name' + desk.id).css('left',(desk.x-(20*itemscale)) + 'px');
$('#name' + desk.id).css('top',divtop + 'px');
$('#name' + desk.id).css('width',(40*itemscale)+'px');
$('#name' + desk.id).css('height',(20*itemscale)+'px');
$('#name' + desk.id).css('text-align','center');
$('#name' + desk.id).css('font-size','8px');
$('#name' + desk.id).css('color',textcolor);
$('#name' + desk.id).css('line-height',lineheight+'px');
$('#name' + desk.id).css('background-color','transparent');
$('#name' + desk.id).css('z-index','9');
$('#name' + desk.id).css('transform','scale('+itemscale+')');
$('#name' + desk.id).css('transform-origin','50% 0%');
}
});
}
function ucWords (word) {
word = word.toLowerCase().replace(/^[\u00C0-\u1FFF\u2C00-\uD7FF\w]|\s[\u00C0-\u1FFF\u2C00-\uD7FF\w]/g, function(letter) {
return letter.toUpperCase();
});
return word;
}
function imageExist(url)
{
var img = new Image();
img.src = url;
return img.height != 0;
}
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(";");
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == " ") {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function statsPanel() {
var output = '<table border="0" style="width:560px; margin-left:30px;">'
+ '<tr>'
+ '<td style="font-weight: bold;color:lightgrey;text-align:left">'+ucWords(map)+'</td>'
+ '<td style="width:130px"></td>'
+ '<td style="width:130px"></td><td style="width:130px"></td>'
+ '</tr>'
+ '<tr>'
+ '<td style="font-weight: bold;color:grey;text-align:left">Department</td>'
+ '<td style="font-weight: bold;color:lightblue;width:130px">Total desks</td>'
+ '<td style="font-weight: bold;color:orange;width:130px">In use</td>'
+ '<td style="font-weight: bold;color:green;width:130px">Free</td>'
+ '</tr>'
+ '<tr><td> </td></tr>';
// Output departments one by one
$.each( departments, function( x, department ){
var all = result_old.desks.filter(element => element.dept == department);
var total1 = all.filter(element => element.desktype == 'addesk');
var total2 = all.filter(element => element.desktype == 'blocked');
var total3 = all.filter(element => element.desktype == 'hotseat');
var totalcount = Object.keys(total1).length + Object.keys(total2).length + Object.keys(total3).length;
var used1 = total1.filter(element => element.fname != '');
var usedcount = Object.keys(used1).length + Object.keys(total2).length + Object.keys(total3).length;
var freecount = totalcount - usedcount;
output+='<tr>'
+ '<td style="color:grey;text-align:left">'+department+'</td>'
+ '<td style="color:lightblue;">'+totalcount+'</td>'
+ '<td style="color:orange;">'+usedcount+'</td>'
+ '<td style="color:green;">'+freecount+'</td>'
+ '</tr>';
});
var all = result_old.desks;
var total1 = all.filter(element => element.desktype == 'addesk');
var total2 = all.filter(element => element.desktype == 'blocked');
var total3 = all.filter(element => element.desktype == 'hotseat');
var total4 = all.filter(element => element.desktype == 'shareddesk');
var totalcount = Object.keys(total1).length + Object.keys(total2).length + Object.keys(total3).length + Object.keys(total4).length;
var used1 = all.filter(element => element.fname != '');
var usedcount = Object.keys(used1).length + Object.keys(total2).length + Object.keys(total3).length + Object.keys(total4).length;
var freecount = totalcount - usedcount;
output+='<tr>'
+ '<td style="color:grey;text-align:left; font-weight:bold;">Summary</td>'
+ '<td style="color:lightblue; font-weight:bold;">'+totalcount+'</td>'
+ '<td style="color:orange; font-weight:bold;">'+usedcount+'</td>'
+ '<td style="color:green; font-weight:bold;">'+freecount+'</td>'
+ '</tr>';
$("#statsTable").html(output);
}
function showNameplate (deskid, desktype) {
attr = result_old.desks.find(o => Object.entries(o).find(([k, value]) => k === 'id' && value === deskid) !== undefined);
var content = '';
switch (desktype) {
case "restroom":
case "food":
case "service":
case "exit":
case "keycardlock":
case "keylock":
case "floor":
case "blocked":
var caption = attr.empl;
var avatar = 'images/' + desktype + '.png';
var avatarcolor = $('#' + attr.id).css('background-color');
var hotseat_booking;
content = attr.title + '<br />'+ attr.mail + '<br />'+ attr.phone + '<br />' + attr.mobil + '<br />'
break;
case "booking":
case "booking_free":
case "booking_booked":
case "hotseat":
case "hotseat_free":
case "hotseat_booked":
var caption = attr.empl;
var avatar = 'images/hotseat.png';
var avatarcolor = $('#' + attr.id).css('background-color');
content = 'no bookings for today';
var deskbookings = bookingstatus.filter(element => element.desk == attr.dsk);
if (deskbookings.length > 0) {
for (var i = 0; i < deskbookings.length; i++) {
var deskbooking = deskbookings[i];
var bookdate = deskbooking.date;
var bookname = deskbooking.name;
var bookphone = deskbooking.phone;
var bookmail = deskbooking.mail;
// if user selected a custom date, use that one instead of today
if (userdate != '') {
var selectdate = userdate;
}
else {
var selectdate = timezoneDate()
}
if (selectdate == bookdate) {
content = bookname+'<br/>'+bookphone+'<br/>'+bookmail;
break;
}
}
}
break;
case "firstaid":
var caption = attr.dsk;
var avatar = 'images/' + desktype + '.png';
var avatarcolor = $('#' + attr.id).css('background-color');
content = attr.title + '<br />'+ attr.mail + '<br />'+ attr.phone + '<br />' + attr.mobil + '<br />'
break;
case "meeting":
var caption = attr.empl;
if (imageExist('avatarcache/' + attr.avtr + '.jpg')) {
avatar = 'avatarcache/' + attr.avtr + '.jpg';
}
else {
avatar = 'images/' + desktype + '.png';
}
var avatarcolor = $('#' + attr.id).css('background-color')
roomstatus = meetingstatus.filter(element => element.deskid == attr.id);
console.log(meetingstatus);
var nowcolor = 'transparent';
var nowtext = ''; var nexttext = '';
var nextcolor = 'transparent';
if (roomstatus != '') {
switch (roomstatus[0].availability) {
case "booked":
case "in_use":
nowcolor = 'rgba(0, 0, 136)';
nextcolor = 'rgb(255,160,0)';
nowtext = roomstatus[0].now_title + '<br />' + roomstatus[0].now_start + ' - ' +roomstatus[0].now_end;
nexttext = roomstatus[0].next_title + '<br />' + roomstatus[0].next_start + ' - ' +roomstatus[0].next_end;
break;
case "available":
nowcolor = '#008800';
nextcolor = 'rgb(255,160,0)';
nowtext = 'Available';
nexttext = roomstatus[0].next_title + '<br />' + roomstatus[0].next_start + ' - ' +roomstatus[0].next_end;
break;
}
}
if (attr.x > (targetScreenWidth/2)) {
var boxstyle = 'top: 51px;width: 490px;height: 147px;border-radius:0px 0px 0px 10px; padding-right:0px;padding-left:0px;';
content = '<div class="leftmeet_now" style="background-color:'+nowcolor+'"><div class="meettext">'+nowtext+'</div></div>'
+ '<div class="leftmeet_next" style="background-color:'+nextcolor+'"><div class="meettext">'+nexttext+'</div></div>'
}
else {
var boxstyle = 'top: 51px;width: 490px;height: 147px;border-radius:0px 0px 10px 0px; padding-left:0px;padding-right:0px;';
content = '<div class="rightmeet_now" style="background-color:'+nowcolor+'"><div class="meettext">'+nowtext+'</div></div>'
+ '<div class="rightmeet_next" style="background-color:'+nextcolor+'"><div class="meettext">'+nexttext+'</div></div>'
}
break;
case "printer":
var caption = attr.empl;
var avatar = 'images/' + desktype + '.png';
var avatarcolor = $('#' + attr.id).css('background-color');
var boxstyle = 'font-size:18px; margin-top:10px;'
/*
printers = printerstatus.filter(element => element.printername == attr.empl);
printer = printers[0];
if (printer.availability == '1') {
var status = 'online';
var statuscolor = '#0f0';
if (typeof(printer.black) != 'undefined' && typeof(printer.magenta) != 'undefined' && typeof(printer.cyan) != 'undefined' && typeof(printer.yellow) != 'undefined') {
content += '<div style="width:94px; height:40px;background-color:#000000;float:left;margin-bottom:10px;line-height:40px;text-align:center;border-radius:20px 0px 0px 20px;">'+printer.black+'</div>'
+ '<div style="width:94px; height:40px;background-color:#a200a2;float:left;margin-bottom:10px;line-height:40px;text-align:center;">'+printer.magenta+'</div>'
+ '<div style="width:94px; height:40px;background-color:#20b2aa;float:left;margin-bottom:10px;line-height:40px;text-align:center;">'+printer.cyan+'</div>'
+ '<div style="width:94px; height:40px;background-color:#cccc00;float:left;margin-bottom:10px;line-height:40px;text-align:center;border-radius:0px 20px 20px 0px;">'+printer.yellow+'</div>';
}
}
else {
var status = 'offline';
var statuscolor = '#f00';
}
content += '<div style="width:376px; height:40px;float:left;line-height:40px;text-align:center;color:'+statuscolor+';font-size:24px;">'+status+'</div>'*/
break;
case "free":
var caption = 'Not in use';
var avatar = 'images/' + desktype + '.png';
var avatarcolor = $('#' + attr.id).css('background-color');
content = attr.title + '<br />'+ attr.mail + '<br />'+ attr.phone + '<br />' + attr.mobil + '<br />'
break;
case "occupied":
var caption = attr.empl;
var avatar = 'avatarcache/' + attr.avtr + '.jpg';
var avatarcolor = $('#' + attr.id).css('background-color');
content = attr.title + '<br />'+ attr.mail + '<br />'+ attr.phone + '<br />' + attr.mobil + '<br />'
break;
case "occupiedldap":
var caption = attr.fname + ' ' + attr.lname;
var avatar = 'avatarcache/' + attr.avtr + '.jpg';
var avatarcolor = $('#' + attr.id).css('background-color');
content = attr.title + '<br />'+ attr.mail + '<br />'+ attr.phone + '<br />' + attr.mobil + '<br />'
break;
case "shareddesk":
var caption = 'Shared Desk';
var avatar = 'images/free.png';
var avatarArr = [];
var avatarcolor = $('#' + attr.id).css('background-color');
var multiresult = result_old.desks.filter(element => element.id == attr.id);
for (var m = 0; m < multiresult.length; m++) {
var textcolor = '#FFFFFF';
avatarArr.push(multiresult[m].avtr)
if (searchtext != '') {
var searchArr = searchtext.split('|');
for (var s = 0; s < searchArr.length; s++) {
var namecheck = multiresult[m].fname.toLowerCase()+' '+multiresult[m].lname.toLowerCase()
var searchcheck = searchArr[s];
searchcheck = searchcheck.toLowerCase();
var sresult = namecheck.includes(searchcheck);
if (sresult) {textcolor='#FF7F00'}
}
}
content += '<div style="color:'+textcolor+'">'+multiresult[m].fname+' '+multiresult[m].lname+'</div>';
}
break;
}
if (attr.color != '') {
var color = attr.color;
}
else {
var color = '#999';
}
avatarcolor = avatarcolor.replace(/[^,]+(?=\))/, '1.0');
if (attr.y < 100) {
var y_nameplate = 100;
}
else {
var y_nameplate = attr.y;
}
if (attr.x > (targetScreenWidth/2)) {
if (desktype !== 'shareddesk') {
var outputnameplate='<div class="leftnameplate" style="position: absolute; top:' + (y_nameplate-100) +'px;left:' + (attr.x-650) + 'px;">'
+ '<div class="leftnameplate_top" style="background:' + color
+ '">' + caption + '</div>'
+ '<div class="leftnameplate_textbox" style="'+boxstyle+'" id="textbox' + attr.id +'">' + content + '</div>'
+ '<img src="' + avatar + '" class="leftnameplate_avatar" style="background:' + avatarcolor + '" onerror="this.src=\'images/noavatar.png\'">'
+ '<div class="leftnameplate_number">' + attr.dsk + '</div></div>'
+ '<div id="caption' + attr.id + '" class="caption">' + attr.empl + '</div>'
+ '</div>';
}
else {
// shared desk has a special avatar
var outputnameplate='<div class="leftnameplate" style="position: absolute; top:' + (y_nameplate-100) +'px;left:' + (attr.x-650) + 'px;">'
+ '<div class="leftnameplate_top" style="background:' + color
+ '">' + caption + '</div>'
+ '<div class="leftnameplate_textbox" style="'+boxstyle+'" id="textbox' + attr.id +'">' + content + '</div>'
+ '<div class="leftnameplate_avatar">'
switch(avatarArr.length) {
case 2:
outputnameplate += ''
+ '<img src="avatarcache/'+avatarArr[0]+'.jpg" style="position:absolute; right:98px; top:0px; width:196px; height:196px" onerror="this.src=\'images/noavatar.png\'"/>'
+ '<img src="avatarcache/'+avatarArr[1]+'.jpg" style="position:absolute; left:98px; top:0px; width:196px; height:196px" onerror="this.src=\'images/noavatar.png\'"/>'
break;
case 3:
outputnameplate += ''
+ '<img src="avatarcache/'+avatarArr[0]+'.jpg" style="position:absolute; right:98px; top:0px; width:196px; height:196px" onerror="this.src=\'images/noavatar.png\'"/>'
+ '<img src="avatarcache/'+avatarArr[1]+'.jpg" style="position:absolute; right:0px; top:0px; width:98px; height:98px" onerror="this.src=\'images/noavatar.png\'"/>'
+ '<img src="avatarcache/'+avatarArr[2]+'.jpg" style="position:absolute; right:0px; bottom:0px; width:98px; height:98px" onerror="this.src=\'images/noavatar.png\'"/>'
break;
case 4:
outputnameplate += ''
+ '<img src="avatarcache/'+avatarArr[0]+'.jpg" style="position:absolute; left:0px; top:0px; width:50%; height:50%" onerror="this.src=\'images/noavatar.png\'"/>'
+ '<img src="avatarcache/'+avatarArr[1]+'.jpg" style="position:absolute; right:0px; top:0px; width:50%; height:50%" onerror="this.src=\'images/noavatar.png\'"/>'
+ '<img src="avatarcache/'+avatarArr[2]+'.jpg" style="position:absolute; left:0px; bottom:0px; width:50%; height:50%" onerror="this.src=\'images/noavatar.png\'"/>'
+ '<img src="avatarcache/'+avatarArr[3]+'.jpg" style="position:absolute; right:0px; bottom:0px; width:50%; height:50%" onerror="this.src=\'images/noavatar.png\'"/>'
break;
}
outputnameplate += '</div>'
+ '<div class="leftnameplate_number">' + attr.dsk + '</div></div>'
+ '<div id="caption' + attr.id + '" class="caption">' + attr.empl + '</div>'
+ '</div>';
}
}
else {
if (desktype !== 'shareddesk') {
var outputnameplate='<div class="rightnameplate" style="position: absolute; top:' + (y_nameplate-100) +'px;left:' + (Number(attr.x) + 50) + 'px;">'
+ '<div class="rightnameplate_top" style="background:' + color
+ '">' + caption + '</div>'
+ '<div class="rightnameplate_textbox" style="'+boxstyle+'" id="textbox' + attr.id +'">' + content + '</div>'
+ '<img src="' + avatar + '" class="rightnameplate_avatar" style="background:' + avatarcolor + '" onerror="this.src=\'images/noavatar.png\'">'
+ '<div class="rightnameplate_number">' + attr.dsk + '</div></div>'
+ '<div id="caption' + attr.id + '" class="caption">' + attr.empl + '</div>'
+ '</div>';
}
else {
// shared desk with special avatar
var outputnameplate='<div class="rightnameplate" style="position: absolute; top:' + (y_nameplate-100) +'px;left:' + (Number(attr.x) + 50) + 'px;">'
+ '<div class="rightnameplate_top" style="background:' + color
+ '">' + caption + '</div>'
+ '<div class="rightnameplate_textbox" style="'+boxstyle+'" id="textbox' + attr.id +'">' + content + '</div>'
+ '<div class="rightnameplate_avatar">'
switch(avatarArr.length) {
case 2:
outputnameplate += ''
+ '<img src="avatarcache/'+avatarArr[0]+'.jpg" style="position:absolute; right:98px; top:0px; width:196px; height:196px" onerror="this.src=\'images/noavatar.png\'" />'
+ '<img src="avatarcache/'+avatarArr[1]+'.jpg" style="position:absolute; left:98px; top:0px; width:196px; height:196px" onerror="this.src=\'images/noavatar.png\'" />'
break;
case 3:
outputnameplate += ''
+ '<img src="avatarcache/'+avatarArr[0]+'.jpg" style="position:absolute; right:98px; top:0px; width:196px; height:196px" onerror="this.src=\'images/noavatar.png\'" />'
+ '<img src="avatarcache/'+avatarArr[1]+'.jpg" style="position:absolute; right:0px; top:0px; width:98px; height:98px" onerror="this.src=\'images/noavatar.png\'" />'
+ '<img src="avatarcache/'+avatarArr[2]+'.jpg" style="position:absolute; right:0px; bottom:0px; width:98px; height:98px" onerror="this.src=\'images/noavatar.png\'" />'
break;
case 4:
outputnameplate += ''
+ '<img src="avatarcache/'+avatarArr[0]+'.jpg" style="position:absolute; left:0px; top:0px; width:50%; height:50%" onerror="this.src=\'images/noavatar.png\'" />'
+ '<img src="avatarcache/'+avatarArr[1]+'.jpg" style="position:absolute; right:0px; top:0px; width:50%; height:50%" onerror="this.src=\'images/noavatar.png\'" />'
+ '<img src="avatarcache/'+avatarArr[2]+'.jpg" style="position:absolute; left:0px; bottom:0px; width:50%; height:50%" onerror="this.src=\'images/noavatar.png\'" />'
+ '<img src="avatarcache/'+avatarArr[3]+'.jpg" style="position:absolute; right:0px; bottom:0px; width:50%; height:50%" onerror="this.src=\'images/noavatar.png\'" />'
break;
}
outputnameplate += '</div>'
+ '<div class="rightnameplate_number">' + attr.dsk + '</div></div>'
+ '<div id="caption' + attr.id + '" class="caption">' + attr.empl + '</div>'
+ '</div>';
}
}
// Adds an element to the document
var p = document.getElementById('deskitems');
var newElement = document.createElement('div');
newElement.setAttribute('id', 'nameplate');
newElement.innerHTML = outputnameplate;
p.appendChild(newElement);
}
function calendarSelection(selection) {
$('.calendarday_free').css("background-color", "");
$('.calendarday_booked').css("background-color", "");
$('.calendarday_past').css("background-color", "");
$('#bookdate').val(selection);
$('#'+selection).css("background-color", "#FF7F00");
}
function updateCalendar(deskid) {
attr = result_old.desks.find(o => Object.entries(o).find(([k, value]) => k === 'id' && value === deskid) !== undefined);
usershort = username.replace(domain, "");
var calendardata = `
<div id="calendar`+deskid+`" class='calendar'>
<div class='calendar_label'>Mo</div>
<div class='calendar_label'>Tu</div>
<div class='calendar_label'>We</div>
<div class='calendar_label'>Th</div>
<div class='calendar_label'>Fr</div>
`
var startDate = getMondayOfCurrentWeek();
var today = new Date(timezoneDate());
for (let i = 0; i < 28; i++) {
var start = new Date(startDate);
var date = new Date();
date.setTime(start.getTime() + (i*24*60*60*1000));
var outputnumber = date.toISOString().substring(8, 10);
var datestring = date.toISOString().substring(0, 10);
if (date < today) {
calendardata += '<div class="calendarday_past">'+outputnumber+'</div>';
}
else if (date.getDay() == 0 || date.getDay() == 6) {
// do nothing for Saturday and Sunday
}
else {
// check for each day if the desk has been booked
bookingdetails = bookingstatus.filter(element => {
return element.desk === attr.dsk && element.date === datestring
});
checkbooking = bookingdetails.length;
if (checkbooking == 1) {
// check if current user has booked the meeting
checkuserbooking = bookingstatus.filter(element => {
return element.desk === attr.dsk && element.date === datestring && element.user === usershort
}).length;
if (checkuserbooking == 1) {
// yellow color
calendardata += '<div class="calendarday_userbooked" id="'+datestring+'" title="Booked by you">'+outputnumber+'</div>';
}
else {
// red color
calendardata += '<div class="calendarday_booked" id="'+datestring+'" title="Booked by '+ bookingdetails[0].name +'">'+outputnumber+'</div>';
}
}
else {
calendardata += '<div class="calendarday_free" id="'+datestring+'" onclick=calendarSelection("'+datestring+'")>'+outputnumber+'</div>';
}
}
}
calendardata += "</div>";
return calendardata;
}
function toggleDatepicker() {
if ($("#theDate").is(":visible") == false) {
var calendardata = `
<div id="calendarDatepicker" class='calendar'>
<div class='calendar_label'>Mo</div>
<div class='calendar_label'>Tu</div>
<div class='calendar_label'>We</div>
<div class='calendar_label'>Th</div>
<div class='calendar_label'>Fr</div>
`
var startDate = getMondayOfCurrentWeek();
var today = new Date(timezoneDate());
for (let i = 0; i < 28; i++) {
var start = new Date(startDate);
var date = new Date();
date.setTime(start.getTime() + (i*24*60*60*1000));
var outputnumber = date.toISOString().substring(8, 10);
var datestring = date.toISOString().substring(0, 10);
if (date < today) {
calendardata += '<div class="calendarday_past">'+outputnumber+'</div>';
}
else if (date.getDay() == 0 || date.getDay() == 6) {
// do nothing for Saturday and Sunday
}
else if (datestring == userdate || (userdate == '' && datestring == timezoneDate() )) {
calendardata += '<div class="calendarday_userdate" id="'+datestring+'" onclick=setUserdate("'+datestring+'")>'+outputnumber+'</div>';
}
else {
calendardata += '<div class="calendarday_neutral" id="'+datestring+'" onclick=setUserdate("'+datestring+'")>'+outputnumber+'</div>';
}
}
calendardata += "</div>";
calendardata += "<div class='datepicker_separator'></div>";
$("#theDate").html(calendardata);
}
$("#theDate").toggle();
}
function showSticky (deskid, desktype, caption) {
attr = result_old.desks.find(o => Object.entries(o).find(([k, value]) => k === 'id' && value === deskid) !== undefined);
if (typeof username !== 'undefined') {usershort = username.replace(domain, "");};
var content = '';
switch (desktype) {
case "restroom":
case "food":
case "service":
case "exit":
case "keycardlock":
case "keylock":
case "floor":
case "blocked":
var caption = attr.empl;
var copylink = attr.empl;
var avatar = 'images/' + desktype + '.png';
var avatarcolor = $('#' + attr.id).css('background-color');
content = attr.title + '<br />'+ attr.mail + '<br />'+ attr.phone + '<br />' + attr.mobil + '<br />'
break;
case "hotseat":
case "hotseat_free":
case "hotseat_booked":
case "booking_free":
case "booking_booked":
var caption = attr.empl;
var avatar = 'images/hotseat.png';
var avatarcolor = $('#' + attr.id).css('background-color');
if (typeof username !== 'undefined') {
var calendar = updateCalendar(deskid)
activecalendar = attr.id;
var calendarform = `
<div id="calendarform" style="width:170px;margin-left:5px; margin-right:5px;float:left;">
<form id="Book" method="post" autocomplete="off" style="width:170px; float:left;">
<input id="mode" type="hidden" name="mode" value="book">
<input id="bookmap" type="hidden" name="bookmap" value="`+map+`">
<input id="bookdesk" type="hidden" name="bookdesk" value="`+attr.dsk+`">
<input id="bookdate" name="bookdate" type="hidden" style="height:39px;border-radius:5px;width:100px;">
<input type="button" value="Book" style="width:160px;height:45px;margin-left:10px;margin-top:0px;float:left;" onclick="bookDesk()"><br/>
</form>
<div id="bookstatus" style="width: 160px;background-color:#35842e;float:left;text-align:center;margin-left:5px;height:35px;line-height:35px;border-radius:25px;padding:5px;display:none;"></div>
</div>
`
if (attr.x > (targetScreenWidth/2)) {
content = calendarform + calendar;
}
else {
content = calendar + calendarform;
}
}