-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.html
More file actions
1007 lines (948 loc) · 52.5 KB
/
Copy pathadmin.html
File metadata and controls
1007 lines (948 loc) · 52.5 KB
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>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Admin Panel — SPurno Animation Studio</title>
<meta name="robots" content="noindex, nofollow">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
<link rel="stylesheet" href="css/style.css">
<link rel="icon" type="image/png" sizes="32x32" href="favicon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="favicon/favicon-16x16.png">
<link rel="apple-touch-icon" href="favicon/apple-touch-icon.png">
<style>
.admin-section { min-height: calc(100vh - 48px); padding: 100px 24px 80px; background: var(--bg-secondary); }
.admin-wrap { max-width: 980px; margin: 0 auto; }
.admin-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.admin-header h1 { font-size: 1.5rem; font-weight: 700; }
.admin-key-status { font-size: 13px; color: var(--body-muted); }
.admin-key-status.active { color: #30d158; }
.admin-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin-bottom: 24px; }
.admin-stat { background: #fff; border: 1px solid #d2d2d7; border-radius: var(--radius-md); padding: 16px; text-align: center; }
.admin-stat-num { font-size: 1.75rem; font-weight: 700; color: var(--ink); }
.admin-stat-label { font-size: 12px; color: var(--body-muted); margin-top: 2px; }
.admin-tabs { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.admin-tab { padding: 8px 18px; border-radius: var(--radius-pill); font-size: 14px; font-weight: 500; background: #e8e8ed; color: var(--ink); cursor: pointer; transition: all 0.2s; border: none; font-family: var(--font); }
.admin-tab:hover { background: #d2d2d7; }
.admin-tab.active { background: var(--primary); color: #fff; }
.admin-tab .badge-count { background: var(--primary); color: #fff; font-size: 11px; padding: 0 6px; border-radius: 10px; margin-left: 4px; }
.admin-tab.active .badge-count { background: rgba(255,255,255,0.3); }
.admin-filters { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.admin-filter { padding: 4px 14px; border-radius: var(--radius-pill); font-size: 13px; font-weight: 500; background: #e8e8ed; color: var(--ink); cursor: pointer; transition: all 0.15s; border: none; font-family: var(--font); }
.admin-filter:hover { background: #d2d2d7; }
.admin-filter.active { background: var(--ink); color: #fff; }
.admin-list { display: flex; flex-direction: column; gap: 12px; }
.admin-card { background: #fff; border: 1px solid #d2d2d7; border-radius: var(--radius-lg); padding: 20px 24px; }
.admin-card-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.admin-card-left { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.admin-card-id { font-size: 12px; font-weight: 600; color: var(--primary); font-family: monospace; letter-spacing: -0.02em; }
.admin-card-user { font-size: 14px; font-weight: 500; color: var(--ink); }
.admin-card-email { font-size: 13px; color: var(--body-muted); }
.admin-card-type { font-size: 14px; color: var(--ink); padding: 10px 0 4px; }
.admin-card-desc { font-size: 14px; color: var(--text-secondary); line-height: 1.5; }
.admin-card-meta { font-size: 13px; color: var(--body-muted); margin-top: 8px; display: flex; gap: 16px; flex-wrap: wrap; }
.admin-card-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; padding-top: 12px; border-top: 1px solid #f0f0f2; gap: 12px; flex-wrap: wrap; }
.admin-card-date { font-size: 12px; color: var(--body-muted); }
.admin-card-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.status-pill { font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 9999px; text-transform: uppercase; letter-spacing: 0.03em; }
.status-pending { background: #fef3c7; color: #92400e; }
.status-quoted { background: #dbeafe; color: #1e40af; }
.status-accepted { background: #d1fae5; color: #065f46; }
.status-in_progress { background: #ede9fe; color: #5b21b6; }
.status-completed { background: #d1fae5; color: #065f46; }
.status-cancelled { background: #fee2e2; color: #991b1b; }
.admin-has-reply { font-size: 11px; padding: 2px 10px; border-radius: 20px; background: rgba(48,209,88,0.1); color: #30d158; font-weight: 600; }
.admin-has-price { font-size: 12px; font-weight: 600; color: var(--primary); }
.admin-empty { text-align: center; padding: 60px 24px; color: var(--body-muted); }
.admin-empty .icon { font-size: 2.5rem; margin-bottom: 12px; color: #d2d2d7; }
.admin-empty p { font-size: 15px; }
.admin-reply-box { margin-top: 8px; padding: 12px; background: #f0fdf4; border-radius: var(--radius-md); border-left: 3px solid #30d158; font-size: 13px; line-height: 1.5; color: var(--text-secondary); }
.admin-reply-box strong { color: #30d158; font-size: 12px; }
.admin-panel { display: none; }
.admin-panel.active { display: block; }
.admin-count { font-size: 14px; color: var(--body-muted); margin-bottom: 16px; }
.admin-alert { display: none; padding: 12px 16px; border-radius: var(--radius-md); font-size: 14px; margin-bottom: 16px; }
.admin-alert.show { display: block; }
.admin-alert.error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.admin-alert.success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.admin-auth-card { max-width: 420px; margin: 0 auto; }
/* Modal overlay */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(4px); z-index: 2000; align-items: center; justify-content: center; padding: 24px; }
.modal-overlay.show { display: flex; }
.modal-content { background: #fff; border-radius: var(--radius-lg); padding: 32px; max-width: 520px; width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal-content h2 { font-size: 1.3rem; font-weight: 700; margin-bottom: 20px; }
.modal-close { float: right; font-size: 1.5rem; color: var(--body-muted); cursor: pointer; background: none; border: none; line-height: 1; }
.modal-close:hover { color: var(--ink); }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; }
.modal-actions .btn { min-width: 100px; }
.loading-spinner { width: 32px; height: 32px; border: 3px solid #e8e8ed; border-top-color: var(--primary); border-radius: 50%; animation: spin 0.7s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
textarea.form-control { resize: vertical; min-height: 80px; }
@media (max-width: 600px) { .admin-card { padding: 16px; } .admin-card-top { flex-direction: column; align-items: flex-start; } .admin-header { flex-direction: column; align-items: flex-start; } }
</style>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-1PFQJV83HK"></script>
<script>window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}gtag('js',new Date());gtag('config','G-1PFQJV83HK');</script>
</head>
<body>
<div id="loading-screen">
<div class="loader-spinner-wrap"><div class="loader-spinner-inner"></div></div>
<img src="images/spurno-logo.svg" alt="SPurno Animation Studio" class="loader-svg-logo">
</div>
<nav class="navbar" id="navbar">
<div class="nav-container">
<button class="nav-toggle" id="navToggle" aria-label="Toggle menu">
<span></span><span></span><span></span>
</button>
<ul class="nav-links" id="navLinks">
<li><a href="index.html" class="nav-link"><i class="fas fa-home"></i> Home</a></li>
<li><a href="index.html#about" class="nav-link"><i class="fas fa-info-circle"></i> About</a></li>
<li><a href="services.html" class="nav-link"><i class="fas fa-cogs"></i> Services</a></li>
<li><a href="index.html#portfolio" class="nav-link"><i class="fas fa-briefcase"></i> Portfolio</a></li>
<li><a href="blog.html" class="nav-link"><i class="fas fa-newspaper"></i> Blog</a></li>
<li><a href="https://pixabanimation.github.io/#/shop" class="nav-link" target="_blank" rel="noopener"><i class="fas fa-store"></i> Marketplace</a></li>
<li><a href="contact-us.html" class="nav-link"><i class="fas fa-envelope"></i> Contact</a></li>
<li class="nav-divider-mobile"><hr></li>
<li><a href="login.html" class="nav-link nav-action-mobile" id="navLogin" style="display:none;"><i class="fas fa-sign-in-alt"></i> Sign In</a></li>
<li><a href="register.html" class="nav-link nav-action-mobile"><i class="fas fa-user-plus"></i> Register</a></li>
<li><a href="account.html" class="nav-link nav-action-mobile" id="navProfile"><i class="fas fa-user"></i> Account</a></li>
</ul>
<div class="nav-actions">
<a href="register.html" class="btn btn-sm btn-secondary" style="margin-right:6px;">Register</a>
<a href="login.html" class="btn btn-sm btn-primary" id="loginBtn" style="display:none;">Sign In</a>
<a href="account.html" class="btn btn-sm btn-primary" id="profileBtn">Account</a>
</div>
</div>
</nav>
<!-- Auth Screen -->
<section class="admin-section" id="authScreen">
<div class="admin-wrap">
<div class="auth-card admin-auth-card">
<div class="auth-header">
<i class="fas fa-shield-alt" style="font-size:2.5rem;color:var(--primary);margin-bottom:12px;"></i>
<h1>Admin Access</h1>
<p>Enter your admin API key to manage the studio.</p>
</div>
<div class="admin-alert" id="authAlert"></div>
<div class="auth-field">
<label for="adminKeyInput">Admin API Key</label>
<input type="password" id="adminKeyInput" class="form-control" placeholder="Enter admin API key" autocomplete="off">
</div>
<button class="btn btn-primary auth-submit" id="authSubmitBtn"><i class="fas fa-key"></i> Authenticate</button>
</div>
</div>
</section>
<!-- Dashboard Screen -->
<section class="admin-section" id="dashScreen" style="display:none;">
<div class="admin-wrap">
<div class="admin-header">
<h1><i class="fas fa-cog" style="margin-right:8px;color:var(--primary);"></i> Admin Panel</h1>
<div style="display:flex;align-items:center;gap:12px;">
<span class="admin-key-status" id="keyStatus">Not authenticated</span>
<button class="btn btn-sm btn-secondary" id="adminLogoutBtn"><i class="fas fa-sign-out-alt"></i> Sign Out</button>
</div>
</div>
<div class="admin-stats" id="statsBar"></div>
<div class="admin-tabs" id="adminTabs">
<button class="admin-tab active" data-tab="orders"><i class="fas fa-clipboard-list"></i> Orders</button>
<button class="admin-tab" data-tab="messages"><i class="fas fa-envelope"></i> Messages <span class="badge-count" id="msgBadge">0</span></button>
<button class="admin-tab" data-tab="users"><i class="fas fa-users"></i> Users</button>
</div>
<div class="admin-alert" id="adminAlert"></div>
<!-- Orders Panel -->
<div class="admin-panel active" id="adminPanelOrders">
<div class="admin-filters" id="orderFilters">
<button class="admin-filter active" data-filter="all">All</button>
<button class="admin-filter" data-filter="pending">Pending</button>
<button class="admin-filter" data-filter="quoted">Quoted</button>
<button class="admin-filter" data-filter="accepted">Accepted</button>
<button class="admin-filter" data-filter="in_progress">In Progress</button>
<button class="admin-filter" data-filter="completed">Completed</button>
<button class="admin-filter" data-filter="cancelled">Cancelled</button>
</div>
<div class="admin-count" id="ordersCount">Loading orders...</div>
<div class="admin-list" id="adminOrdersList"><div class="loading-spinner"></div></div>
</div>
<!-- Messages Panel -->
<div class="admin-panel" id="adminPanelMessages">
<div class="admin-count" id="messagesCount">Loading messages...</div>
<div class="admin-list" id="adminMessagesList"><div class="loading-spinner"></div></div>
</div>
<!-- Users Panel -->
<div class="admin-panel" id="adminPanelUsers">
<div class="admin-count" id="usersCount">Loading users...</div>
<div class="admin-list" id="adminUsersList"><div class="loading-spinner"></div></div>
</div>
</div>
</section>
<!-- Update Order Modal -->
<div class="modal-overlay" id="updateModal">
<div class="modal-content">
<button class="modal-close" id="modalClose">×</button>
<h2><i class="fas fa-pen" style="color:var(--primary);margin-right:8px;"></i> Update Order</h2>
<div class="admin-alert" id="modalAlert"></div>
<form id="updateForm">
<input type="hidden" id="updateOrderId">
<div class="auth-field">
<label>Order Number</label>
<div id="modalOrderNumber" style="font-family:monospace;font-size:14px;color:var(--body-muted);padding:8px 0;"></div>
</div>
<div class="auth-field">
<label for="updateStatus">Status</label>
<select id="updateStatus" class="form-control custom-select">
<option value="pending">Pending</option>
<option value="quoted">Quoted</option>
<option value="accepted">Accepted</option>
<option value="in_progress">In Progress</option>
<option value="completed">Completed</option>
<option value="cancelled">Cancelled</option>
</select>
</div>
<div class="auth-field">
<label for="updatePrice">Quoted Price</label>
<input type="text" id="updatePrice" class="form-control" placeholder="e.g. $350">
</div>
<div class="auth-field">
<label for="updateResponse">Admin Response (visible to user)</label>
<textarea id="updateResponse" class="form-control" rows="3" placeholder="Your message to the customer..."></textarea>
</div>
<div class="auth-field">
<label for="updateNotes">Admin Notes (internal only)</label>
<textarea id="updateNotes" class="form-control" rows="2" placeholder="Internal notes..."></textarea>
</div>
<div class="modal-actions">
<button type="button" class="btn btn-secondary" id="modalCancelBtn"><i class="fas fa-times"></i> Cancel</button>
<button type="submit" class="btn btn-primary" id="modalSaveBtn"><i class="fas fa-save"></i> Update Order</button>
</div>
</form>
</div>
</div>
<!-- Reply to Message Modal -->
<div class="modal-overlay" id="replyModal">
<div class="modal-content">
<button class="modal-close" id="replyModalClose">×</button>
<h2><i class="fas fa-reply" style="color:var(--primary);margin-right:8px;"></i> Reply to User</h2>
<div class="admin-alert" id="replyModalAlert"></div>
<form id="replyForm">
<input type="hidden" id="replyMessageId">
<div class="auth-field">
<label>From User</label>
<div id="replyUserInfo" style="font-size:14px;color:var(--body-muted);padding:8px 0;"></div>
</div>
<div class="auth-field">
<label>Original Message</label>
<div id="replyOriginalMsg" style="font-size:13px;color:var(--text-secondary);padding:12px;background:var(--bg-input);border-radius:var(--radius-md);line-height:1.5;max-height:100px;overflow-y:auto;"></div>
</div>
<div class="auth-field">
<label for="replyText">Your Reply *</label>
<textarea id="replyText" class="form-control" rows="4" placeholder="Write your reply to the user..." required></textarea>
</div>
<div class="modal-actions">
<button type="button" class="btn btn-secondary" id="replyCancelBtn"><i class="fas fa-times"></i> Cancel</button>
<button type="submit" class="btn btn-primary" id="replySendBtn"><i class="fas fa-paper-plane"></i> Send Reply</button>
</div>
</form>
</div>
</div>
<!-- Edit User Modal -->
<div class="modal-overlay" id="editUserModal">
<div class="modal-content">
<button class="modal-close" id="editUserModalClose">×</button>
<h2><i class="fas fa-user-pen" style="color:var(--primary);margin-right:8px;"></i> Edit User</h2>
<div class="admin-alert" id="editUserModalAlert"></div>
<form id="editUserForm">
<input type="hidden" id="editUserId">
<div class="auth-field">
<label>Email</label>
<div id="editUserEmail" style="font-size:14px;color:var(--body-muted);padding:8px 0;"></div>
</div>
<div class="auth-field">
<label for="editUserName">Full Name</label>
<input type="text" id="editUserName" class="form-control" placeholder="User's full name">
</div>
<div class="auth-field">
<label for="editUserPhone">Phone</label>
<input type="text" id="editUserPhone" class="form-control" placeholder="+1 (555) 123-4567">
</div>
<div class="auth-field">
<label for="editUserAvatar">Avatar URL</label>
<input type="url" id="editUserAvatar" class="form-control" placeholder="https://example.com/avatar.jpg">
</div>
<div style="margin-bottom:16px;display:flex;align-items:center;gap:12px;">
<img id="editUserAvatarPreview" style="width:48px;height:48px;border-radius:50%;object-fit:cover;display:none;border:2px solid var(--primary);" alt="Avatar preview">
<span id="editUserAvatarLetter" style="display:inline-flex;width:48px;height:48px;border-radius:50%;background:var(--primary);color:#fff;font-size:1.4rem;font-weight:700;align-items:center;justify-content:center;border:2px solid var(--primary);"></span>
</div>
<div class="modal-actions">
<button type="button" class="btn btn-secondary" id="editUserCancelBtn"><i class="fas fa-times"></i> Cancel</button>
<button type="submit" class="btn btn-primary" id="editUserSaveBtn"><i class="fas fa-save"></i> Save User</button>
</div>
</form>
</div>
</div>
<!-- Compose Message Modal -->
<div class="modal-overlay" id="composeModal">
<div class="modal-content">
<button class="modal-close" id="composeModalClose">×</button>
<h2><i class="fas fa-pen" style="color:var(--primary);margin-right:8px;"></i> Compose Message</h2>
<div class="admin-alert" id="composeModalAlert"></div>
<form id="composeForm">
<input type="hidden" id="composeUserId">
<div class="auth-field">
<label>Sending To</label>
<div id="composeUserInfo" style="font-size:14px;color:var(--body-muted);padding:8px 0;"></div>
</div>
<div class="auth-field">
<label for="composeSubject">Subject</label>
<input type="text" id="composeSubject" class="form-control" placeholder="e.g. Special Offer, Project Update...">
</div>
<div class="auth-field">
<label for="composeMessage">Message *</label>
<textarea id="composeMessage" class="form-control" rows="4" placeholder="Write your message to this user..." required></textarea>
</div>
<div class="modal-actions">
<button type="button" class="btn btn-secondary" id="composeCancelBtn"><i class="fas fa-times"></i> Cancel</button>
<button type="submit" class="btn btn-primary" id="composeSendBtn"><i class="fas fa-paper-plane"></i> Send Message</button>
</div>
</form>
</div>
</div>
<footer class="footer">
<div class="footer-content">
<div class="footer-grid">
<div class="footer-brand">
<div class="footer-brand-top">
<img src="images/spurno-logo.svg" alt="SPurno Animation Studio" loading="lazy">
</div>
<p>Premium motion background videos, animated templates, and stock footage used by creators worldwide. Based in Dhaka, Bangladesh.</p>
<div class="footer-social">
<a href="https://www.linkedin.com/in/spurno" target="_blank" aria-label="LinkedIn" rel="noopener"><i class="fab fa-linkedin-in"></i></a>
<a href="https://facebook.com/iSPurno" target="_blank" aria-label="Facebook" rel="noopener"><i class="fab fa-facebook-f"></i></a>
<a href="https://x.com/iSPurno" target="_blank" aria-label="X" rel="noopener"><i class="fab fa-twitter"></i></a>
<a href="https://github.com/SPurno" target="_blank" aria-label="GitHub" rel="noopener"><i class="fab fa-github"></i></a>
</div>
</div>
<div class="footer-col">
<h4>Company</h4>
<a href="about-us.html">About Us</a>
<a href="contact-us.html">Contact</a>
<a href="services.html">Services</a>
<a href="index.html">Home</a>
<a href="blog/stock-portfolio.html">Portfolio</a>
</div>
<div class="footer-col">
<h4>Categories</h4>
<a href="blog/motion-graphics.html">Motion Graphics</a>
<a href="blog/infographic.html">Infographics</a>
<a href="blog/motion-graphics-background.html">Backgrounds</a>
<a href="watch/laptop-product-promotion-advertising-template.html">Mockups</a>
</div>
<div class="footer-col">
<h4>Marketplace</h4>
<a href="https://pixabanimation.github.io/#/shop" target="_blank" rel="noopener">Browse Assets</a>
<a href="https://pixabanimation.github.io/#/shop?category=videos" target="_blank" rel="noopener">Videos</a>
<a href="https://pixabanimation.github.io/#/shop?category=adobe-after-effect-plugins" target="_blank" rel="noopener">AE Plugins</a>
<a href="https://pixabanimation.github.io/#/shop?category=background-animation" target="_blank" rel="noopener">Backgrounds</a>
<a href="https://pixabanimation.github.io/blog/" target="_blank" rel="noopener">Blog</a>
</div>
<div class="footer-col">
<h4>Policies</h4>
<a href="privacy-policy.html">Privacy Policy</a>
<a href="terms-of-use.html">Terms of Use</a>
</div>
<div class="footer-col">
<h4>Stock Sites</h4>
<a href="https://stock.adobe.com/contributor/211977281/SPurnoAnimation" target="_blank" rel="noopener">Adobe Stock</a>
<a href="https://www.shutterstock.com/g/SPurnoAnimation" target="_blank" rel="noopener">Shutterstock</a>
<a href="https://www.pond5.com/artist/spurnoanimation" target="_blank" rel="noopener">Pond5</a>
<a href="https://www.freepik.com/author/pixellvector" target="_blank" rel="noopener">Freepik</a>
</div>
</div>
<div class="footer-bottom">
<div class="footer-bottom-links">
<a href="privacy-policy.html">Privacy</a>
<span class="footer-bottom-sep">·</span>
<a href="terms-of-use.html">Terms</a>
<span class="footer-bottom-sep">·</span>
<a href="contact-us.html">Support</a>
<span class="footer-bottom-sep">·</span>
<a href="spurno.html">Author</a>
</div>
<p>© 2026 SPurno Animation Studio & PixabAnimation. All rights reserved.</p>
</div>
</div>
</footer>
<button class="scroll-top-btn" id="scrollTopBtn" aria-label="Scroll to top">
<i class="fas fa-arrow-up"></i>
</button>
<script src="../js/auth-client.js"></script>
<script src="js/main.js" defer></script>
<script>
(function() {
var API_BASE = 'https://spurno-auth.ispurno.workers.dev/api';
var LS_KEY = 'spurno_admin_key';
var adminKey = localStorage.getItem(LS_KEY) || '';
var currentFilter = 'all';
var allOrders = [];
var allStats = [];
var authScreen = document.getElementById('authScreen');
var dashScreen = document.getElementById('dashScreen');
var keyStatus = document.getElementById('keyStatus');
var adminKeyInput = document.getElementById('adminKeyInput');
var authSubmitBtn = document.getElementById('authSubmitBtn');
var authAlert = document.getElementById('authAlert');
var adminLogoutBtn = document.getElementById('adminLogoutBtn');
var adminAlert = document.getElementById('adminAlert');
var statsBar = document.getElementById('statsBar');
var ordersCount = document.getElementById('ordersCount');
var adminOrdersList = document.getElementById('adminOrdersList');
var messagesCount = document.getElementById('messagesCount');
var adminMessagesList = document.getElementById('adminMessagesList');
var usersCount = document.getElementById('usersCount');
var adminUsersList = document.getElementById('adminUsersList');
function showAlert(el, msg, type) {
el.textContent = msg;
el.className = 'admin-alert show ' + (type || '');
if (msg) setTimeout(function() { el.className = 'admin-alert'; }, 5000);
}
function updateAuthUI() {
if (adminKey) {
keyStatus.textContent = 'Authenticated';
keyStatus.className = 'admin-key-status active';
adminLogoutBtn.style.display = '';
} else {
keyStatus.textContent = 'Not authenticated';
keyStatus.className = 'admin-key-status';
adminLogoutBtn.style.display = 'none';
}
}
async function adminFetch(path, options) {
options = options || {};
var res = await fetch(API_BASE + path, {
...options,
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + adminKey,
...(options.headers || {}),
},
});
var data = await res.json();
if (!res.ok) throw new Error(data.error || 'Request failed');
return data;
}
async function authenticate(key) {
try {
var res = await fetch(API_BASE + '/admin/orders', {
headers: { 'Authorization': 'Bearer ' + key },
});
if (!res.ok) {
var data = await res.json();
throw new Error(data.error || 'Authentication failed');
}
adminKey = key;
localStorage.setItem(LS_KEY, key);
updateAuthUI();
authScreen.style.display = 'none';
dashScreen.style.display = '';
showAlert(adminAlert, '', '');
loadDashboard();
} catch (e) {
showAlert(authAlert, e.message || 'Invalid admin key', 'error');
}
}
authSubmitBtn.addEventListener('click', function() {
var key = adminKeyInput.value.trim();
if (!key) { showAlert(authAlert, 'Please enter your admin API key.', 'error'); return; }
authenticate(key);
});
adminKeyInput.addEventListener('keydown', function(e) {
if (e.key === 'Enter') authSubmitBtn.click();
});
adminLogoutBtn.addEventListener('click', function() {
adminKey = '';
localStorage.removeItem(LS_KEY);
updateAuthUI();
dashScreen.style.display = 'none';
authScreen.style.display = '';
adminKeyInput.value = '';
authAlert.className = 'admin-alert';
authAlert.textContent = '';
});
// Tab switching
document.querySelectorAll('.admin-tab').forEach(function(btn) {
btn.addEventListener('click', function() {
document.querySelectorAll('.admin-tab').forEach(function(b) { b.classList.remove('active'); });
document.querySelectorAll('.admin-panel').forEach(function(p) { p.classList.remove('active'); });
btn.classList.add('active');
var tab = btn.dataset.tab;
document.getElementById('adminPanel' + tab.charAt(0).toUpperCase() + tab.slice(1)).classList.add('active');
if (tab === 'messages') loadAdminMessages();
if (tab === 'users') loadAdminUsers();
});
});
// Order filters
document.querySelectorAll('.admin-filter').forEach(function(btn) {
btn.addEventListener('click', function() {
document.querySelectorAll('.admin-filter').forEach(function(b) { b.classList.remove('active'); });
btn.classList.add('active');
currentFilter = btn.dataset.filter;
renderOrders();
});
});
// ── Dashboard ──
async function loadDashboard() {
try {
var data = await adminFetch('/admin/orders');
allOrders = data.orders || [];
allStats = data.stats || [];
renderStats();
renderOrders();
} catch (e) {
showAlert(adminAlert, 'Failed to load orders: ' + e.message, 'error');
}
}
function renderStats() {
var statusLabels = { pending: 'Pending', quoted: 'Quoted', accepted: 'Accepted', in_progress: 'In Progress', completed: 'Completed', cancelled: 'Cancelled' };
var colors = { pending: '#fde047', quoted: '#93c5fd', accepted: '#86efac', in_progress: '#d8b4fe', completed: '#86efac', cancelled: '#fca5a5' };
var total = allOrders.length;
var html = '<div class="admin-stat"><div class="admin-stat-num">' + total + '</div><div class="admin-stat-label">Total Orders</div></div>';
allStats.forEach(function(s) {
html += '<div class="admin-stat"><div class="admin-stat-num" style="color:' + (colors[s.status] || '#fff') + '">' + s.count + '</div><div class="admin-stat-label">' + (statusLabels[s.status] || s.status) + '</div></div>';
});
statsBar.innerHTML = html;
}
function renderOrders() {
var filtered = allOrders;
if (currentFilter !== 'all') filtered = allOrders.filter(function(o) { return o.status === currentFilter; });
ordersCount.textContent = filtered.length + ' order' + (filtered.length !== 1 ? 's' : '') + (currentFilter !== 'all' ? ' (' + currentFilter.replace('_', ' ') + ')' : '');
if (!filtered.length) {
adminOrdersList.innerHTML = '<div class="admin-empty"><div class="icon"><i class="fas fa-clipboard"></i></div><p>No orders found.</p></div>';
return;
}
var statusLabels = { pending: 'Pending', quoted: 'Quoted', accepted: 'Accepted', in_progress: 'In Progress', completed: 'Completed', cancelled: 'Cancelled' };
adminOrdersList.innerHTML = '<div style="display:flex;flex-direction:column;gap:12px;">' + filtered.map(function(o) {
var created = new Date(o.created_at).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric', hour: '2-digit', minute: '2-digit' });
return '<div class="admin-card">' +
'<div class="admin-card-top">' +
'<div class="admin-card-left">' +
'<span class="admin-card-id">#' + (o.order_number || o.id) + '</span>' +
'<span class="admin-card-user"><i class="fas fa-user" style="margin-right:4px;color:var(--body-muted);"></i>' + (o.user_name || o.user_email || 'Unknown') + '</span>' +
'</div>' +
'<span class="status-pill status-' + o.status + '">' + (statusLabels[o.status] || o.status) + '</span>' +
'</div>' +
'<div class="admin-card-type">' + (o.animation_type ? o.animation_type.replace(/-/g, ' ').replace(/\b\w/g, function(c) { return c.toUpperCase(); }) : 'Animation') + (o.duration_seconds ? ' · ' + o.duration_seconds + 's' : '') + '</div>' +
'<div class="admin-card-desc">' + (o.description && o.description.length > 150 ? o.description.slice(0, 150) + '...' : o.description || '') + '</div>' +
'<div class="admin-card-meta">' +
(o.budget_range ? '<span><i class="fas fa-tag"></i> ' + o.budget_range + '</span>' : '') +
(o.deadline ? '<span><i class="fas fa-calendar"></i> Due: ' + o.deadline + '</span>' : '') +
(o.payment_method ? '<span><i class="fas fa-credit-card"></i> ' + o.payment_method + '</span>' : '') +
'</div>' +
'<div class="admin-card-meta">' +
(o.contact_email ? '<span><i class="fas fa-envelope"></i> ' + o.contact_email + '</span>' : '') +
(o.contact_phone ? '<span><i class="fas fa-phone"></i> ' + o.contact_phone + '</span>' : '') +
'</div>' +
'<div class="admin-card-footer">' +
'<span class="admin-card-date"><i class="far fa-clock"></i> ' + created + '</span>' +
'<div class="admin-card-actions">' +
(o.admin_response ? '<span class="admin-has-reply"><i class="fas fa-check-circle"></i> Has reply</span>' : '') +
(o.quoted_price ? '<span class="admin-has-price"><i class="fas fa-dollar-sign"></i> ' + o.quoted_price + '</span>' : '') +
'<button class="btn btn-sm btn-secondary admin-update-btn" data-id="' + o.id + '"><i class="fas fa-pen"></i> Update</button>' +
'<button class="btn btn-sm btn-secondary admin-delete-btn" data-id="' + o.id + '" style="color:#ff3b30;"><i class="fas fa-trash"></i></button>' +
'</div>' +
'</div>' +
'</div>';
}).join('') + '</div>';
document.querySelectorAll('.admin-update-btn').forEach(function(btn) {
btn.addEventListener('click', function() { openUpdateModal(btn.dataset.id); });
});
document.querySelectorAll('.admin-delete-btn').forEach(function(btn) {
btn.addEventListener('click', function() { adminDeleteOrder(btn.dataset.id); });
});
}
async function adminDeleteOrder(orderId) {
if (!confirm('Delete this order? This cannot be undone.')) return;
try {
var result = await adminFetch('/admin/orders', {
method: 'DELETE',
body: JSON.stringify({ id: parseInt(orderId, 10) }),
});
showAlert(adminAlert, result.message || 'Order deleted.', 'success');
loadDashboard();
} catch (e) {
showAlert(adminAlert, 'Failed to delete order: ' + e.message, 'error');
}
}
// ── Messages ──
async function loadAdminMessages() {
try {
var data = await adminFetch('/admin/messages');
var messages = data.messages || [];
var stats = data.stats || {};
document.getElementById('msgBadge').textContent = stats.count || messages.length;
messagesCount.textContent = messages.length + ' message' + (messages.length !== 1 ? 's' : '');
if (!messages.length) {
adminMessagesList.innerHTML = '<div class="admin-empty"><div class="icon"><i class="fas fa-envelope-open-text"></i></div><p>No messages from users yet.</p></div>';
return;
}
adminMessagesList.innerHTML = '<div style="display:flex;flex-direction:column;gap:12px;">' + messages.map(function(m) {
var created = new Date(m.created_at).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric', hour: '2-digit', minute: '2-digit' });
var hasReply = m.admin_reply && m.admin_reply.trim();
return '<div class="admin-card">' +
'<div class="admin-card-top">' +
'<div class="admin-card-left">' +
'<span class="admin-card-user"><i class="fas fa-user" style="margin-right:4px;color:var(--body-muted);"></i>' + (m.name || m.user_name || m.user_email || 'Unknown') + '</span>' +
'<span class="admin-card-email">' + (m.email || '') + '</span>' +
'</div>' +
'<span class="admin-card-date">' + created + '</span>' +
'</div>' +
'<div class="admin-card-type">' + (m.subject || '(No subject)') + '</div>' +
'<div class="admin-card-desc">' + m.message + '</div>' +
(hasReply ? '<div class="admin-reply-box"><strong><i class="fas fa-check-circle"></i> Your Reply:</strong> ' + m.admin_reply + (m.admin_replied_at ? ' <span style="color:var(--body-muted);font-size:11px;">(' + new Date(m.admin_replied_at).toLocaleDateString('en-US', {month:'short',day:'numeric',hour:'2-digit',minute:'2-digit'}) + ')</span>' : '') + '</div>' : '') +
'<div class="admin-card-footer">' +
'<span>' + (hasReply ? '<span class="admin-has-reply"><i class="fas fa-check-circle"></i> Replied</span>' : '<span style="font-size:11px;padding:2px 10px;border-radius:20px;background:rgba(255,204,0,0.1);color:#b8860b;font-weight:600;"><i class="fas fa-clock"></i> Awaiting reply</span>') + '</span>' +
'<div class="admin-card-actions">' +
'<button class="btn btn-sm btn-secondary admin-reply-btn" data-id="' + m.id + '" data-user="' + (m.name || m.user_name || m.user_email || 'Unknown').replace(/"/g, '"') + '" data-msg="' + (m.message || '').replace(/"/g, '"').replace(/\n/g, ' ') + '"><i class="fas fa-reply"></i> Reply</button>' +
'<button class="btn btn-sm btn-secondary admin-delete-msg-btn" data-id="' + m.id + '" style="color:#ff3b30;"><i class="fas fa-trash"></i></button>' +
'</div>' +
'</div>' +
'</div>';
}).join('') + '</div>';
document.querySelectorAll('.admin-reply-btn').forEach(function(btn) {
btn.addEventListener('click', function() { openReplyModal(btn.dataset.id, btn.dataset.user, btn.dataset.msg); });
});
document.querySelectorAll('.admin-delete-msg-btn').forEach(function(btn) {
btn.addEventListener('click', function() { adminDeleteMessage(btn.dataset.id); });
});
} catch (e) {
var msgAlert = document.getElementById('adminMsgAlert');
if (!msgAlert) {
var panel = document.getElementById('adminPanelMessages');
var div = document.createElement('div');
div.className = 'admin-alert show error';
div.id = 'adminMsgAlert';
div.textContent = 'Failed to load messages: ' + e.message;
panel.insertBefore(div, panel.firstChild);
} else {
msgAlert.textContent = 'Failed to load messages: ' + e.message;
msgAlert.className = 'admin-alert show error';
}
}
}
async function adminDeleteMessage(msgId) {
if (!confirm('Delete this message?')) return;
try {
var result = await adminFetch('/admin/messages', {
method: 'DELETE',
body: JSON.stringify({ id: parseInt(msgId, 10) }),
});
var el = document.getElementById('adminMsgAlert');
if (el) { el.textContent = result.message || 'Message deleted.'; el.className = 'admin-alert show success'; }
loadAdminMessages();
} catch (e) {
var el = document.getElementById('adminMsgAlert');
if (el) { el.textContent = 'Failed: ' + e.message; el.className = 'admin-alert show error'; }
}
}
// ── Update Modal ──
var updateModal = document.getElementById('updateModal');
var modalClose = document.getElementById('modalClose');
var modalCancelBtn = document.getElementById('modalCancelBtn');
var modalAlert = document.getElementById('modalAlert');
var updateForm = document.getElementById('updateForm');
var updateOrderId = document.getElementById('updateOrderId');
var modalOrderNumber = document.getElementById('modalOrderNumber');
var updateStatus = document.getElementById('updateStatus');
var updatePrice = document.getElementById('updatePrice');
var updateResponse = document.getElementById('updateResponse');
var updateNotes = document.getElementById('updateNotes');
var modalSaveBtn = document.getElementById('modalSaveBtn');
async function openUpdateModal(orderId) {
try {
var data = await adminFetch('/admin/orders?id=' + orderId);
var order = data.order;
updateOrderId.value = order.id;
modalOrderNumber.textContent = order.order_number || '—';
updateStatus.value = order.status || 'pending';
updatePrice.value = order.quoted_price || '';
updateResponse.value = order.admin_response || '';
updateNotes.value = order.admin_notes || '';
modalAlert.className = 'admin-alert';
modalAlert.textContent = '';
updateModal.classList.add('show');
} catch (e) {
showAlert(adminAlert, 'Failed to load order details: ' + e.message, 'error');
}
}
function closeModal() { updateModal.classList.remove('show'); }
modalClose.addEventListener('click', closeModal);
modalCancelBtn.addEventListener('click', closeModal);
updateModal.addEventListener('click', function(e) { if (e.target === updateModal) closeModal(); });
updateForm.addEventListener('submit', async function(e) {
e.preventDefault();
modalSaveBtn.disabled = true;
modalSaveBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Updating...';
try {
var result = await adminFetch('/admin/orders', {
method: 'PUT',
body: JSON.stringify({
id: parseInt(updateOrderId.value, 10),
status: updateStatus.value,
quoted_price: updatePrice.value.trim() || null,
admin_response: updateResponse.value.trim() || null,
admin_notes: updateNotes.value.trim() || null,
}),
});
showAlert(modalAlert, result.message || 'Order updated!', 'success');
setTimeout(closeModal, 1000);
showAlert(adminAlert, 'Order ' + (result.order ? result.order.order_number : '') + ' updated successfully.', 'success');
loadDashboard();
} catch (e) {
showAlert(modalAlert, e.message || 'Failed to update order', 'error');
}
modalSaveBtn.disabled = false;
modalSaveBtn.innerHTML = '<i class="fas fa-save"></i> Update Order';
});
// ── Reply Modal ──
var replyModal = document.getElementById('replyModal');
var replyModalClose = document.getElementById('replyModalClose');
var replyCancelBtn = document.getElementById('replyCancelBtn');
var replyForm = document.getElementById('replyForm');
var replyMessageId = document.getElementById('replyMessageId');
var replyUserInfo = document.getElementById('replyUserInfo');
var replyOriginalMsg = document.getElementById('replyOriginalMsg');
var replyText = document.getElementById('replyText');
var replySendBtn = document.getElementById('replySendBtn');
var replyModalAlert = document.getElementById('replyModalAlert');
function openReplyModal(msgId, userInfo, originalMsg) {
replyMessageId.value = msgId;
replyUserInfo.textContent = userInfo;
replyOriginalMsg.textContent = originalMsg;
replyText.value = '';
replyModalAlert.className = 'admin-alert';
replyModalAlert.textContent = '';
replyModal.classList.add('show');
}
function closeReplyModal() { replyModal.classList.remove('show'); }
replyModalClose.addEventListener('click', closeReplyModal);
replyCancelBtn.addEventListener('click', closeReplyModal);
replyModal.addEventListener('click', function(e) { if (e.target === replyModal) closeReplyModal(); });
replyForm.addEventListener('submit', async function(e) {
e.preventDefault();
var reply = replyText.value.trim();
if (!reply) { replyModalAlert.textContent = 'Please write a reply.'; replyModalAlert.className = 'admin-alert show error'; return; }
replySendBtn.disabled = true;
replySendBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Sending...';
try {
var result = await adminFetch('/admin/messages/reply', {
method: 'POST',
body: JSON.stringify({ id: parseInt(replyMessageId.value, 10), reply: reply }),
});
replyModalAlert.textContent = result.message || 'Reply sent!';
replyModalAlert.className = 'admin-alert show success';
setTimeout(closeReplyModal, 1000);
var msgAlert = document.getElementById('adminMsgAlert');
if (msgAlert) { msgAlert.textContent = 'Reply sent successfully.'; msgAlert.className = 'admin-alert show success'; }
loadAdminMessages();
} catch (e) {
replyModalAlert.textContent = e.message || 'Failed to send reply';
replyModalAlert.className = 'admin-alert show error';
}
replySendBtn.disabled = false;
replySendBtn.innerHTML = '<i class="fas fa-paper-plane"></i> Send Reply';
});
// ── Users ──
async function loadAdminUsers() {
try {
var data = await adminFetch('/admin/users');
var users = data.users || [];
usersCount.textContent = users.length + ' registered user' + (users.length !== 1 ? 's' : '');
if (!users.length) {
adminUsersList.innerHTML = '<div class="admin-empty"><div class="icon"><i class="fas fa-users"></i></div><p>No users registered yet.</p></div>';
return;
}
adminUsersList.innerHTML = '<div style="display:flex;flex-direction:column;gap:12px;">' + users.map(function(u) {
var created = new Date(u.created_at).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric', hour: '2-digit', minute: '2-digit' });
var initial = (u.name || u.email || 'U').charAt(0).toUpperCase();
var avatarHtml = u.avatar_url ? '<img src="' + u.avatar_url.replace(/"/g,'"') + '" style="width:28px;height:28px;border-radius:50%;object-fit:cover;vertical-align:middle;">' : '<span style="display:inline-flex;width:28px;height:28px;border-radius:50%;background:var(--primary);color:#fff;font-size:12px;font-weight:700;align-items:center;justify-content:center;vertical-align:middle;">' + initial + '</span>';
var phoneHtml = u.phone ? '<span style="font-size:12px;color:var(--body-muted);"><i class="fas fa-phone"></i> ' + u.phone + '</span>' : '';
return '<div class="admin-card">' +
'<div class="admin-card-top">' +
'<div class="admin-card-left">' +
avatarHtml +
'<span class="admin-card-user">' + (u.name || u.email.split('@')[0]) + '</span>' +
'<span class="admin-card-id">#' + u.id + '</span>' +
'</div>' +
'<span class="admin-card-date">Joined ' + created + '</span>' +
'</div>' +
'<div class="admin-card-type"><i class="fas fa-envelope" style="margin-right:6px;color:var(--body-muted);"></i>' + u.email + '</div>' +
(phoneHtml ? '<div class="admin-card-meta">' + phoneHtml + '</div>' : '') +
'<div class="admin-card-footer">' +
'<span></span>' +
'<div class="admin-card-actions">' +
'<button class="btn btn-sm btn-secondary admin-edit-user-btn" data-id="' + u.id + '" data-name="' + (u.name || '').replace(/"/g, '"') + '" data-email="' + u.email + '" data-phone="' + (u.phone || '').replace(/"/g, '"') + '" data-avatar="' + (u.avatar_url || '').replace(/"/g, '"') + '"><i class="fas fa-pen"></i> Edit</button>' +
'<button class="btn btn-sm btn-secondary admin-compose-btn" data-user-id="' + u.id + '" data-user-name="' + (u.name || u.email.split('@')[0]).replace(/"/g, '"') + '" data-user-email="' + u.email + '"><i class="fas fa-paper-plane"></i> Send Message</button>' +
'</div>' +
'</div>' +
'</div>';
}).join('') + '</div>';
document.querySelectorAll('.admin-compose-btn').forEach(function(btn) {
btn.addEventListener('click', function() {
openComposeModal(btn.dataset.userId, btn.dataset.userName, btn.dataset.userEmail);
});
});
document.querySelectorAll('.admin-edit-user-btn').forEach(function(btn) {
btn.addEventListener('click', function() {
openEditUserModal(btn.dataset.id, btn.dataset.name, btn.dataset.email, btn.dataset.phone, btn.dataset.avatar);
});
});
} catch (e) {
var userAlert = document.getElementById('adminUserAlert');
if (!userAlert) {
var panel = document.getElementById('adminPanelUsers');
var div = document.createElement('div');
div.className = 'admin-alert show error';
div.id = 'adminUserAlert';
div.textContent = 'Failed to load users: ' + e.message;
panel.insertBefore(div, panel.firstChild);
} else {
userAlert.textContent = 'Failed to load users: ' + e.message;
userAlert.className = 'admin-alert show error';
}
}
}
// ── Compose Modal ──
var composeModal = document.getElementById('composeModal');
var composeModalClose = document.getElementById('composeModalClose');
var composeCancelBtn = document.getElementById('composeCancelBtn');
var composeForm = document.getElementById('composeForm');
var composeUserId = document.getElementById('composeUserId');
var composeUserInfo = document.getElementById('composeUserInfo');
var composeSubject = document.getElementById('composeSubject');
var composeMessage = document.getElementById('composeMessage');
var composeSendBtn = document.getElementById('composeSendBtn');
var composeModalAlert = document.getElementById('composeModalAlert');
function openComposeModal(userId, userName, userEmail) {
composeUserId.value = userId;
composeUserInfo.textContent = userName + ' (' + userEmail + ')';
composeSubject.value = '';
composeMessage.value = '';
composeModalAlert.className = 'admin-alert';
composeModalAlert.textContent = '';
composeModal.classList.add('show');
}
function closeComposeModal() { composeModal.classList.remove('show'); }
composeModalClose.addEventListener('click', closeComposeModal);
composeCancelBtn.addEventListener('click', closeComposeModal);
composeModal.addEventListener('click', function(e) { if (e.target === composeModal) closeComposeModal(); });
composeForm.addEventListener('submit', async function(e) {
e.preventDefault();
var message = composeMessage.value.trim();
if (!message) { composeModalAlert.textContent = 'Please write a message.'; composeModalAlert.className = 'admin-alert show error'; return; }
composeSendBtn.disabled = true;
composeSendBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Sending...';
try {
var result = await adminFetch('/admin/messages/compose', {
method: 'POST',
body: JSON.stringify({
user_id: composeUserId.value,
subject: composeSubject.value.trim() || 'Message from Admin',
message: message,
}),
});
composeModalAlert.textContent = result.message || 'Message sent!';
composeModalAlert.className = 'admin-alert show success';
setTimeout(closeComposeModal, 1500);
} catch (e) {
composeModalAlert.textContent = e.message || 'Failed to send message';
composeModalAlert.className = 'admin-alert show error';
}
composeSendBtn.disabled = false;
composeSendBtn.innerHTML = '<i class="fas fa-paper-plane"></i> Send Message';
});
// ── Edit User Modal ──
var editUserModal = document.getElementById('editUserModal');
var editUserModalClose = document.getElementById('editUserModalClose');
var editUserCancelBtn = document.getElementById('editUserCancelBtn');
var editUserForm = document.getElementById('editUserForm');
var editUserId = document.getElementById('editUserId');
var editUserEmail = document.getElementById('editUserEmail');
var editUserName = document.getElementById('editUserName');
var editUserPhone = document.getElementById('editUserPhone');
var editUserAvatar = document.getElementById('editUserAvatar');
var editUserAvatarPreview = document.getElementById('editUserAvatarPreview');
var editUserAvatarLetter = document.getElementById('editUserAvatarLetter');
var editUserSaveBtn = document.getElementById('editUserSaveBtn');
var editUserModalAlert = document.getElementById('editUserModalAlert');
function openEditUserModal(id, name, email, phone, avatar) {
editUserId.value = id;
editUserEmail.textContent = email;
editUserName.value = name || '';
editUserPhone.value = phone || '';
editUserAvatar.value = avatar || '';
editUserModalAlert.className = 'admin-alert';
editUserModalAlert.textContent = '';
updateEditAvatarPreview(name || email || 'U', avatar || '');
editUserModal.classList.add('show');
}
function updateEditAvatarPreview(name, avatarUrl) {
var initial = (name || 'U').charAt(0).toUpperCase();
if (avatarUrl) {
editUserAvatarPreview.style.display = 'inline-block';
editUserAvatarLetter.style.display = 'none';
editUserAvatarPreview.src = avatarUrl;
} else {
editUserAvatarPreview.style.display = 'none';
editUserAvatarLetter.style.display = 'inline-flex';
editUserAvatarLetter.textContent = initial;
}
}
editUserAvatar.addEventListener('input', function() {
updateEditAvatarPreview(editUserName.value || editUserEmail.textContent || 'U', this.value.trim());
});
editUserName.addEventListener('input', function() {
if (!editUserAvatar.value.trim()) {
updateEditAvatarPreview(this.value || editUserEmail.textContent || 'U', '');
}
});
function closeEditUserModal() { editUserModal.classList.remove('show'); }
editUserModalClose.addEventListener('click', closeEditUserModal);
editUserCancelBtn.addEventListener('click', closeEditUserModal);
editUserModal.addEventListener('click', function(e) { if (e.target === editUserModal) closeEditUserModal(); });
editUserForm.addEventListener('submit', async function(e) {
e.preventDefault();
editUserSaveBtn.disabled = true;
editUserSaveBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Saving...';
try {
var result = await adminFetch('/admin/users', {
method: 'PUT',
body: JSON.stringify({
id: parseInt(editUserId.value, 10),
name: editUserName.value.trim() || null,
phone: editUserPhone.value.trim() || null,
avatar_url: editUserAvatar.value.trim() || null,
}),
});
editUserModalAlert.textContent = result.message || 'User updated!';
editUserModalAlert.className = 'admin-alert show success';
setTimeout(closeEditUserModal, 1000);
loadAdminUsers();
} catch (e) {
editUserModalAlert.textContent = e.message || 'Failed to update user';
editUserModalAlert.className = 'admin-alert show error';
}
editUserSaveBtn.disabled = false;
editUserSaveBtn.innerHTML = '<i class="fas fa-save"></i> Save User';
});
// ── Auto-login ──
if (adminKey) {
updateAuthUI();
authenticate(adminKey);
} else {
updateAuthUI();
authScreen.style.display = '';
adminKeyInput.focus();