-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.php
More file actions
689 lines (654 loc) · 31.8 KB
/
dashboard.php
File metadata and controls
689 lines (654 loc) · 31.8 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
<?php
include 'sidebar.php';
// Note: sidebar.php already includes config.php and session.php
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
// Fetch user details
$stmt = $conn->prepare("SELECT id, name, role, email, created_at FROM users WHERE id = ?");
$stmt->bind_param("i", $_SESSION['user_id']);
$stmt->execute();
$result = $stmt->get_result();
$user = $result->fetch_assoc();
$stmt->close();
// Function to get total count
function getTotalCount($conn, $table, $condition = '') {
$sql = "SELECT COUNT(*) as count FROM $table $condition";
$result = $conn->query($sql);
return $result->fetch_assoc()['count'];
}
// Function to get monthly data
function getMonthlyData($conn, $table, $dateColumn, $condition = '') {
$sql = "SELECT DATE_FORMAT($dateColumn, '%Y-%m') as month, COUNT(*) as count
FROM $table
$condition
GROUP BY DATE_FORMAT($dateColumn, '%Y-%m')
ORDER BY month DESC
LIMIT 12";
$result = $conn->query($sql);
return array_reverse($result->fetch_all(MYSQLI_ASSOC));
}
// Get user-specific data
$userDocuments = getTotalCount($conn, 'documents', "WHERE sender_id = {$user['id']}");
$userSignedDocuments = getTotalCount($conn, 'documents', "WHERE sender_id = {$user['id']} AND status = 'signed'");
$userPendingDocuments = getTotalCount($conn, 'documents', "WHERE sender_id = {$user['id']} AND status = 'pending'");
$userMessages = getTotalCount($conn, 'messages', "WHERE sender_id = {$user['id']} OR receiver_id = {$user['id']}");
$userMonthlyDocuments = getMonthlyData($conn, 'documents', 'upload_date', "WHERE sender_id = {$user['id']}");
$userMonthlySignedDocuments = getMonthlyData($conn, 'documents', 'signed_at', "WHERE sender_id = {$user['id']} AND status = 'signed'");
$userMonthlyMessages = getMonthlyData($conn, 'messages', 'created_at', "WHERE sender_id = {$user['id']} OR receiver_id = {$user['id']}");
// Get document types for the user
$stmt = $conn->prepare("SELECT status, COUNT(*) as count FROM documents WHERE sender_id = ? GROUP BY status");
$stmt->bind_param("i", $user['id']);
$stmt->execute();
$userDocumentTypes = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
$stmt->close();
// Get admin-specific data
if ($user['role'] === 'admin') {
$totalUsers = getTotalCount($conn, 'users');
$totalDocuments = getTotalCount($conn, 'documents');
$totalSignedDocuments = getTotalCount($conn, 'documents', "WHERE status = 'signed'");
$totalPendingDocuments = getTotalCount($conn, 'documents', "WHERE status = 'pending'");
$totalMessages = getTotalCount($conn, 'messages');
$monthlyUsers = getMonthlyData($conn, 'users', 'created_at');
$monthlyDocuments = getMonthlyData($conn, 'documents', 'upload_date');
$monthlySignedDocuments = getMonthlyData($conn, 'documents', 'signed_at', "WHERE status = 'signed'");
$monthlyMessages = getMonthlyData($conn, 'messages', 'created_at');
// Get top users
$stmt = $conn->prepare("SELECT u.name, COUNT(d.id) as document_count
FROM users u
LEFT JOIN documents d ON u.id = d.sender_id
GROUP BY u.id
ORDER BY document_count DESC
LIMIT 5");
$stmt->execute();
$topUsers = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
$stmt->close();
// Get document types for all users
$stmt = $conn->prepare("SELECT status, COUNT(*) as count FROM documents GROUP BY status");
$stmt->execute();
$allDocumentTypes = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
$stmt->close();
// Get user activity trends
$stmt = $conn->prepare("SELECT
u.id,
u.name,
COUNT(DISTINCT d.id) as document_count,
COUNT(DISTINCT m.id) as message_count,
MAX(GREATEST(IFNULL(d.upload_date, '1970-01-01'), IFNULL(m.created_at, '1970-01-01'))) as last_activity
FROM
users u
LEFT JOIN documents d ON u.id = d.sender_id
LEFT JOIN messages m ON u.id = m.sender_id OR u.id = m.receiver_id
GROUP BY
u.id
ORDER BY
last_activity DESC
LIMIT 10");
$stmt->execute();
$userActivityTrends = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
$stmt->close();
}
// Get recent activities (for both user and admin)
$activityCondition = $user['role'] === 'admin' ? '' : "WHERE d.sender_id = {$user['id']}";
$stmt = $conn->prepare("SELECT u.name, d.file_path, d.status, d.upload_date
FROM documents d
JOIN users u ON d.sender_id = u.id
$activityCondition
ORDER BY d.upload_date DESC
LIMIT 10");
$stmt->execute();
$recentActivities = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
$stmt->close();
// Get recent messages
$messageCondition = $user['role'] === 'admin' ? '' : "WHERE m.sender_id = {$user['id']} OR m.receiver_id = {$user['id']}";
$stmt = $conn->prepare("SELECT m.id, m.sender_id, s.name as sender_name, m.receiver_id, r.name as receiver_name, m.message, m.created_at
FROM messages m
JOIN users s ON m.sender_id = s.id
JOIN users r ON m.receiver_id = r.id
$messageCondition
ORDER BY m.created_at DESC
LIMIT 10");
$stmt->execute();
$recentMessages = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
$stmt->close();
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - SignEase</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
* {
transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}
</style>
<script>
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
colors: {
primary: '#8B0000',
secondary: '#FFA500',
}
}
}
}
</script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" rel="stylesheet">
<style>
.animate__animated { animation-duration: 0.5s; }
</style>
</head>
<body class="bg-gray-100 dark:bg-gray-900 text-gray-800 dark:text-gray-200">
<div class="p-4 sm:ml-64">
<div class="p-4 border-2 border-gray-200 border-dashed rounded-lg dark:border-gray-700">
<h1 class="text-3xl font-semibold mb-6 animate__animated animate__fadeIn text-gray-800 dark:text-white">Welcome, <?php if ($user['role'] === 'admin') echo 'Administrator'; else echo htmlspecialchars($user['name']); ?>!</h1>
<!-- Summary Cards -->
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-8">
<?php if ($user['role'] === 'admin'): ?>
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-md animate__animated animate__fadeInUp">
<h3 class="text-xl font-semibold mb-2 text-gray-800 dark:text-white">Total Users</h3>
<p class="text-3xl font-bold text-gray-800 dark:text-white"><?php echo $totalUsers; ?></p>
</div>
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-md animate__animated animate__fadeInUp" style="animation-delay: 0.1s;">
<h3 class="text-xl font-semibold mb-2 text-gray-800 dark:text-white">Total Documents</h3>
<p class="text-3xl font-bold text-gray-800 dark:text-white"><?php echo $totalDocuments; ?></p>
</div>
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-md animate__animated animate__fadeInUp" style="animation-delay: 0.2s;">
<h3 class="text-xl font-semibold mb-2 text-gray-800 dark:text-white">Signed Documents</h3>
<p class="text-3xl font-bold text-gray-800 dark:text-white"><?php echo $totalSignedDocuments; ?></p>
</div>
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-md animate__animated animate__fadeInUp" style="animation-delay: 0.3s;">
<h3 class="text-xl font-semibold mb-2 text-gray-800 dark:text-white">Total Messages</h3>
<p class="text-3xl font-bold text-gray-800 dark:text-white"><?php echo $totalMessages; ?></p>
</div>
<?php else: ?>
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-md animate__animated animate__fadeInUp">
<h3 class="text-xl font-semibold mb-2 text-gray-800 dark:text-white">Your Documents</h3>
<p class="text-3xl font-bold text-gray-800 dark:text-white"><?php echo $userDocuments; ?></p>
</div>
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-md animate__animated animate__fadeInUp" style="animation-delay: 0.1s;">
<h3 class="text-xl font-semibold mb-2 text-gray-800 dark:text-white">Your Signed Documents</h3>
<p class="text-3xl font-bold text-gray-800 dark:text-white"><?php echo $userSignedDocuments; ?></p>
</div>
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-md animate__animated animate__fadeInUp" style="animation-delay: 0.2s;">
<h3 class="text-xl font-semibold mb-2 text-gray-800 dark:text-white">Your Pending Documents</h3>
<p class="text-3xl font-bold text-gray-800 dark:text-white"><?php echo $userPendingDocuments; ?></p>
</div>
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-md animate__animated animate__fadeInUp" style="animation-delay: 0.3s;">
<h3 class="text-xl font-semibold mb-2 text-gray-800 dark:text-white">Your Messages</h3>
<p class="text-3xl font-bold text-gray-800 dark:text-white"><?php echo $userMessages; ?></p>
</div>
<?php endif; ?>
</div>
<!-- Charts -->
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8 mb-8">
<?php if ($user['role'] === 'admin'): ?>
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-md animate__animated animate__fadeIn">
<h3 class="text-xl font-semibold mb-4 text-gray-800 dark:text-white">Monthly User Registrations</h3>
<canvas id="userChart"></canvas>
</div>
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-md animate__animated animate__fadeIn" style="animation-delay: 0.1s;">
<h3 class="text-xl font-semibold mb-4 text-gray-800 dark:text-white">Monthly Document Activity</h3>
<canvas id="documentChart"></canvas>
</div>
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-md animate__animated animate__fadeIn" style="animation-delay: 0.2s;">
<h3 class="text-xl font-semibold mb-4 text-gray-800 dark:text-white">Document Status Distribution</h3>
<canvas id="documentTypesChart"></canvas>
</div>
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-md animate__animated animate__fadeIn" style="animation-delay: 0.3s;">
<h3 class="text-xl font-semibold mb-4 text-gray-800 dark:text-white">Monthly Message Activity</h3>
<canvas id="messageChart"></canvas>
</div>
<?php else: ?>
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-md animate__animated animate__fadeIn">
<h3 class="text-xl font-semibold mb-4 text-gray-800 dark:text-white">Your Monthly Document Activity</h3>
<canvas id="userDocumentChart"></canvas>
</div>
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-md animate__animated animate__fadeIn" style="animation-delay: 0.1s;">
<h3 class="text-xl font-semibold mb-4 text-gray-800 dark:text-white">Your Document Status Distribution</h3>
<canvas id="userDocumentStatusChart"></canvas>
</div>
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-md animate__animated animate__fadeIn" style="animation-delay: 0.2s;">
<h3 class="text-xl font-semibold mb-4 text-gray-800 dark:text-white">Your Monthly Message Activity</h3>
<canvas id="userMessageChart"></canvas>
</div>
<?php endif; ?>
</div>
<?php if ($user['role'] === 'admin'): ?>
<!-- Admin-only sections -->
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8 mb-8">
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-md animate__animated animate__fadeIn">
<h3 class="text-xl font-semibold mb-4 text-gray-800 dark:text-white">Top Users by Document Count</h3>
<div class="overflow-x-auto">
<table class="min-w-full bg-white dark:bg-gray-800">
<thead class="bg-gray-100 dark:bg-gray-700">
<tr>
<th class="py-2 px-4 text-left text-gray-800 dark:text-white">User</th>
<th class="py-2 px-4 text-left text-gray-800 dark:text-white">Document Count</th>
</tr>
</thead>
<tbody>
<?php foreach ($topUsers as $topUser): ?>
<tr class="border-b dark:border-gray-700">
<td class="py-2 px-4 text-gray-800 dark:text-white"><?php echo htmlspecialchars($topUser['name']); ?></td>
<td class="py-2 px-4 text-gray-800 dark:text-white"><?php echo $topUser['document_count']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-md animate__animated animate__fadeIn" style="animation-delay: 0.1s;">
<h3 class="text-xl font-semibold mb-4 text-gray-800 dark:text-white">User Activity Trends</h3>
<div class="overflow-x-auto">
<table class="min-w-full bg-white dark:bg-gray-800">
<thead class="bg-gray-100 dark:bg-gray-700">
<tr>
<th class="py-2 px-4 text-left text-gray-800 dark:text-white">User</th>
<th class="py-2 px-4 text-left text-gray-800 dark:text-white">Documents</th>
<th class="py-2 px-4 text-left text-gray-800 dark:text-white">Messages</th>
<th class="py-2 px-4 text-left text-gray-800 dark:text-white">Last Activity</th>
</tr>
</thead>
<tbody>
<?php foreach ($userActivityTrends as $activity): ?>
<tr class="border-b dark:border-gray-700">
<td class="py-2 px-4 text-gray-800 dark:text-white"><?php echo htmlspecialchars($activity['name']); ?></td>
<td class="py-2 px-4 text-gray-800 dark:text-white"><?php echo $activity['document_count']; ?></td>
<td class="py-2 px-4 text-gray-800 dark:text-white"><?php echo $activity['message_count']; ?></td>
<td class="py-2 px-4 text-gray-800 dark:text-white"><?php echo date('Y-m-d H:i', strtotime($activity['last_activity'])); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php endif; ?>
<!-- Recent Activities -->
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-md mb-8 animate__animated animate__fadeIn">
<h3 class="text-xl font-semibold mb-4 text-gray-800 dark:text-white">Recent Activities</h3>
<div class="overflow-x-auto">
<table class="min-w-full bg-white dark:bg-gray-800">
<thead class="bg-gray-100 dark:bg-gray-700">
<tr>
<th class="py-2 px-4 text-left text-gray-800 dark:text-white">User</th>
<th class="py-2 px-4 text-left text-gray-800 dark:text-white">Document</th>
<th class="py-2 px-4 text-left text-gray-800 dark:text-white">Status</th>
<th class="py-2 px-4 text-left text-gray-800 dark:text-white">Date</th>
</tr>
</thead>
<tbody>
<?php foreach ($recentActivities as $activity): ?>
<tr class="border-b dark:border-gray-700">
<td class="py-2 px-4 text-gray-800 dark:text-white"><?php echo htmlspecialchars($activity['name']); ?></td>
<td class="py-2 px-4 text-gray-800 dark:text-white"><?php echo htmlspecialchars(basename($activity['file_path'])); ?></td>
<td class="py-2 px-4 text-gray-800 dark:text-white"><?php echo ucfirst($activity['status']); ?></td>
<td class="py-2 px-4 text-gray-800 dark:text-white"><?php echo date('Y-m-d H:i', strtotime($activity['upload_date'])); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<!-- Recent Messages -->
<div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-md animate__animated animate__fadeIn" style="animation-delay: 0.1s;">
<h3 class="text-xl font-semibold mb-4 text-gray-800 dark:text-white">Recent Messages</h3>
<div class="overflow-x-auto">
<table class="min-w-full bg-white dark:bg-gray-800">
<thead class="bg-gray-100 dark:bg-gray-700">
<tr>
<th class="py-2 px-4 text-left text-gray-800 dark:text-white">Sender</th>
<th class="py-2 px-4 text-left text-gray-800 dark:text-white">Receiver</th>
<th class="py-2 px-4 text-left text-gray-800 dark:text-white">Message</th>
<th class="py-2 px-4 text-left text-gray-800 dark:text-white">Date</th>
</tr>
</thead>
<tbody>
<?php foreach ($recentMessages as $message): ?>
<tr class="border-b dark:border-gray-700">
<td class="py-2 px-4 text-gray-800 dark:text-white"><?php echo htmlspecialchars($message['sender_name']); ?></td>
<td class="py-2 px-4 text-gray-800 dark:text-white"><?php echo htmlspecialchars($message['receiver_name']); ?></td>
<td class="py-2 px-4 text-gray-800 dark:text-white"><?php echo htmlspecialchars(substr($message['message'], 0, 50)) . (strlen($message['message']) > 50 ? '...' : ''); ?></td>
<td class="py-2 px-4 text-gray-800 dark:text-white"><?php echo date('Y-m-d H:i', strtotime($message['created_at'])); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<script>
function getChartConfig(isDarkMode) {
return {
color: isDarkMode ? '#fff' : '#666',
borderColor: isDarkMode ? 'rgba(255, 255, 255, 0.1)' : 'rgba(0, 0, 0, 0.1)',
grid: {
color: isDarkMode ? 'rgba(255, 255, 255, 0.1)' : 'rgba(0, 0, 0, 0.1)'
}
};
}
function updateChartTheme(chart, isDarkMode) {
const config = getChartConfig(isDarkMode);
chart.options.scales.x.ticks.color = config.color;
chart.options.scales.y.ticks.color = config.color;
chart.options.scales.x.grid.color = config.grid.color;
chart.options.scales.y.grid.color = config.grid.color;
chart.options.plugins.legend.labels.color = config.color;
chart.update();
}
const isDarkMode = document.documentElement.classList.contains('dark');
const chartConfig = getChartConfig(isDarkMode);
<?php if ($user['role'] === 'admin'): ?>
// Admin Charts
var userCtx = document.getElementById('userChart').getContext('2d');
var userChart = new Chart(userCtx, {
type: 'line',
data: {
labels: <?php echo json_encode(array_column($monthlyUsers, 'month')); ?>,
datasets: [{
label: 'New Users',
data: <?php echo json_encode(array_column($monthlyUsers, 'count')); ?>,
borderColor: 'rgb(75, 192, 192)',
tension: 0.1,
fill: false
}]
},
options: {
responsive: true,
scales: {
x: {
ticks: { color: chartConfig.color },
grid: { color: chartConfig.grid.color }
},
y: {
beginAtZero: true,
ticks: { color: chartConfig.color },
grid: { color: chartConfig.grid.color }
}
},
plugins: {
legend: {
labels: { color: chartConfig.color }
}
},
animation: {
duration: 2000,
easing: 'easeOutQuart'
}
}
});
var docCtx = document.getElementById('documentChart').getContext('2d');
var docChart = new Chart(docCtx, {
type: 'bar',
data: {
labels: <?php echo json_encode(array_column($monthlyDocuments, 'month')); ?>,
datasets: [{
label: 'Uploaded Documents',
data: <?php echo json_encode(array_column($monthlyDocuments, 'count')); ?>,
backgroundColor: 'rgba(54, 162, 235, 0.5)',
borderColor: 'rgb(54, 162, 235)',
borderWidth: 1
},
{
label: 'Signed Documents',
data: <?php echo json_encode(array_column($monthlySignedDocuments, 'count')); ?>,
backgroundColor: 'rgba(75, 192, 192, 0.5)',
borderColor: 'rgb(75, 192, 192)',
borderWidth: 1
}]
},
options: {
responsive: true,
scales: {
x: {
ticks: { color: chartConfig.color },
grid: { color: chartConfig.grid.color }
},
y: {
beginAtZero: true,
ticks: { color: chartConfig.color },
grid: { color: chartConfig.grid.color }
}
},
plugins: {
legend: {
labels: { color: chartConfig.color }
}
},
animation: {
duration: 2000,
easing: 'easeOutQuart'
}
}
});
var docTypesCtx = document.getElementById('documentTypesChart').getContext('2d');
var docTypesChart = new Chart(docTypesCtx, {
type: 'doughnut',
data: {
labels: <?php echo json_encode(array_column($allDocumentTypes, 'status')); ?>,
datasets: [{
data: <?php echo json_encode(array_column($allDocumentTypes, 'count')); ?>,
backgroundColor: [
'rgba(255, 99, 132, 0.8)',
'rgba(54, 162, 235, 0.8)',
'rgba(255, 206, 86, 0.8)',
'rgba(75, 192, 192, 0.8)',
'rgba(153, 102, 255, 0.8)'
]
}]
},
options: {
responsive: true,
plugins: {
legend: {
position: 'right',
labels: { color: chartConfig.color }
},
title: {
display: true,
text: 'Document Status Distribution',
color: chartConfig.color
}
},
animation: {
duration: 2000,
easing: 'easeOutQuart'
}
}
});
var messageCtx = document.getElementById('messageChart').getContext('2d');
var messageChart = new Chart(messageCtx, {
type: 'line',
data: {
labels: <?php echo json_encode(array_column($monthlyMessages, 'month')); ?>,
datasets: [{
label: 'Messages',
data: <?php echo json_encode(array_column($monthlyMessages, 'count')); ?>,
borderColor: 'rgb(255, 159, 64)',
tension: 0.1,
fill: false
}]
},
options: {
responsive: true,
scales: {
x: {
ticks: { color: chartConfig.color },
grid: { color: chartConfig.grid.color }
},
y: {
beginAtZero: true,
ticks: { color: chartConfig.color },
grid: { color: chartConfig.grid.color }
}
},
plugins: {
legend: {
labels: { color: chartConfig.color }
}
},
animation: {
duration: 2000,
easing: 'easeOutQuart'
}
}
});
<?php else: ?>
// User Charts
var userDocCtx = document.getElementById('userDocumentChart').getContext('2d');
var userDocChart = new Chart(userDocCtx, {
type: 'line',
data: {
labels: <?php echo json_encode(array_column($userMonthlyDocuments, 'month')); ?>,
datasets: [{
label: 'Your Uploaded Documents',
data: <?php echo json_encode(array_column($userMonthlyDocuments, 'count')); ?>,
borderColor: 'rgb(54, 162, 235)',
tension: 0.1,
fill: false
},
{
label: 'Your Signed Documents',
data: <?php echo json_encode(array_column($userMonthlySignedDocuments, 'count')); ?>,
borderColor: 'rgb(75, 192, 192)',
tension: 0.1,
fill: false
}]
},
options: {
responsive: true,
scales: {
x: {
ticks: { color: chartConfig.color },
grid: { color: chartConfig.grid.color }
},
y: {
beginAtZero: true,
ticks: { color: chartConfig.color },
grid: { color: chartConfig.grid.color }
}
},
plugins: {
legend: {
labels: { color: chartConfig.color }
}
},
animation: {
duration: 2000,
easing: 'easeOutQuart'
}
}
});
var statusCtx = document.getElementById('userDocumentStatusChart').getContext('2d');
var statusChart = new Chart(statusCtx, {
type: 'pie',
data: {
labels: <?php echo json_encode(array_column($userDocumentTypes, 'status')); ?>,
datasets: [{
data: <?php echo json_encode(array_column($userDocumentTypes, 'count')); ?>,
backgroundColor: [
'rgba(75, 192, 192, 0.8)',
'rgba(255, 206, 86, 0.8)',
'rgba(153, 102, 255, 0.8)'
]
}]
},
options: {
responsive: true,
plugins: {
legend: {
position: 'right',
labels: { color: chartConfig.color }
},
title: {
display: true,
text: 'Your Document Status Distribution',
color: chartConfig.color
}
},
animation: {
duration: 2000,
easing: 'easeOutQuart'
}
}
});
var userMessageCtx = document.getElementById('userMessageChart').getContext('2d');
var userMessageChart = new Chart(userMessageCtx, {
type: 'line',
data: {
labels: <?php echo json_encode(array_column($userMonthlyMessages, 'month')); ?>,
datasets: [{
label: 'Your Messages',
data: <?php echo json_encode(array_column($userMonthlyMessages, 'count')); ?>,
borderColor: 'rgb(255, 159, 64)',
tension: 0.1,
fill: false
}]
},
options: {
responsive: true,
scales: {
x: {
ticks: { color: chartConfig.color },
grid: { color: chartConfig.grid.color }
},
y: {
beginAtZero: true,
ticks: { color: chartConfig.color },
grid: { color: chartConfig.grid.color }
}
},
plugins: {
legend: {
labels: { color: chartConfig.color }
}
},
animation: {
duration: 2000,
easing: 'easeOutQuart'
}
}
});
<?php endif; ?>
// Add scroll animation to all animate__animated elements
const animatedElements = document.querySelectorAll('.animate__animated');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate__fadeIn');
}
});
}, { threshold: 0.1 });
animatedElements.forEach(element => {
observer.observe(element);
});
// Function to update chart themes
function updateChartsTheme(isDark) {
const charts = [
<?php if ($user['role'] === 'admin'): ?>
userChart, docChart, docTypesChart, messageChart
<?php else: ?>
userDocChart, statusChart, userMessageChart
<?php endif; ?>
];
charts.forEach(chart => updateChartTheme(chart, isDark));
}
// Listen for theme changes
window.addEventListener('themeChanged', function(e) {
updateChartsTheme(e.detail === 'dark');
});
</script>
<script src="theme.js"></script>
</body>
</html>