-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdashboard.php
More file actions
200 lines (184 loc) · 6.79 KB
/
dashboard.php
File metadata and controls
200 lines (184 loc) · 6.79 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
<?php
// FP5/admin/dashboard.php
require_once __DIR__ . '/includes/auth.php';
require_admin();
require_once __DIR__ . '/includes/db_mysqli.php';
/* Top statistics */
$totalDictionaries = 0;
$totalWords = 0;
$totalLanguages = 0;
$q1 = $conn->query("SELECT COUNT(*) AS total FROM dictionaries");
if ($q1) {
$totalDictionaries = (int)$q1->fetch_assoc()['total'];
}
$q2 = $conn->query("SELECT COUNT(*) AS total FROM dictionary_entries");
if ($q2) {
$totalWords = (int)$q2->fetch_assoc()['total'];
}
$q3 = $conn->query("
SELECT COUNT(DISTINCT language_name) AS total FROM (
SELECT source_lang_1 AS language_name FROM dictionaries WHERE source_lang_1 IS NOT NULL AND source_lang_1 <> ''
UNION
SELECT source_lang_2 FROM dictionaries WHERE source_lang_2 IS NOT NULL AND source_lang_2 <> ''
UNION
SELECT source_lang_3 FROM dictionaries WHERE source_lang_3 IS NOT NULL AND source_lang_3 <> ''
) AS langs
");
if ($q3) {
$totalLanguages = (int)$q3->fetch_assoc()['total'];
}
/* Per-dictionary word counts */
$dictStats = [];
$dictSql = "
SELECT
d.dict_id,
d.name,
d.dict_identifier,
d.type,
COUNT(e.dict_id) AS word_count
FROM dictionaries d
LEFT JOIN dictionary_entries e ON e.dict_id = d.dict_id
GROUP BY d.dict_id, d.name, d.dict_identifier, d.type
ORDER BY d.name ASC
";
$dictResult = $conn->query($dictSql);
if ($dictResult) {
while ($row = $dictResult->fetch_assoc()) {
$dictStats[] = $row;
}
}
/* Language-wise breakdown */
$languageStats = [];
$langSql = "
SELECT language_name, COUNT(*) AS dictionary_count
FROM (
SELECT source_lang_1 AS language_name FROM dictionaries WHERE source_lang_1 IS NOT NULL AND source_lang_1 <> ''
UNION ALL
SELECT source_lang_2 FROM dictionaries WHERE source_lang_2 IS NOT NULL AND source_lang_2 <> ''
UNION ALL
SELECT source_lang_3 FROM dictionaries WHERE source_lang_3 IS NOT NULL AND source_lang_3 <> ''
) AS language_union
GROUP BY language_name
ORDER BY dictionary_count DESC, language_name ASC
";
$langResult = $conn->query($langSql);
if ($langResult) {
while ($row = $langResult->fetch_assoc()) {
$languageStats[] = $row;
}
}
?>
<?php include 'includes/header.php'; ?>
<?php include 'includes/navbar.php'; ?>
<body>
<main class="container py-4">
<div class="mb-4">
<h1 class="h3 mb-1">Dashboard</h1>
<p class="text-muted mb-0">Welcome, <?php echo htmlspecialchars($_SESSION['user_name'] ?? 'Admin'); ?></p>
</div>
<div class="row g-3 mb-4">
<div class="col-12 col-md-4">
<div class="card shadow-sm border-0">
<div class="card-body">
<div class="text-muted small">Total Dictionaries</div>
<div class="display-6 fw-bold"><?php echo $totalDictionaries; ?></div>
</div>
</div>
</div>
<div class="col-12 col-md-4">
<div class="card shadow-sm border-0">
<div class="card-body">
<div class="text-muted small">Total Words</div>
<div class="display-6 fw-bold"><?php echo $totalWords; ?></div>
</div>
</div>
</div>
<div class="col-12 col-md-4">
<div class="card shadow-sm border-0">
<div class="card-body">
<div class="text-muted small">Languages Used</div>
<div class="display-6 fw-bold"><?php echo $totalLanguages; ?></div>
</div>
</div>
</div>
</div>
<a href="dictionary.php" class="btn btn-primary btn-lg">Manage Dictionaries</a>
<a href="compare.php" class="btn btn-primary btn-lg">Compare Dictionaries</a>
<a href="reports.php" class="btn btn-primary btn-lg">View Report</a>
<br><br>
<div class="card shadow-sm border-0 mb-4">
<div class="card-body">
<h2 class="h5 mb-3">Dictionary Word Counts</h2>
<div class="table-responsive">
<table id="dictionaryTable" class="table table-striped table-bordered align-middle w-100">
<thead>
<tr>
<th>ID</th>
<th>Dictionary Name</th>
<th>Identifier</th>
<th>Type</th>
<th>Word Count</th>
</tr>
</thead>
<tbody>
<?php foreach ($dictStats as $row): ?>
<tr>
<td><?php echo (int)$row['dict_id']; ?></td>
<td><?php echo htmlspecialchars($row['name']); ?></td>
<td><?php echo htmlspecialchars($row['dict_identifier']); ?></td>
<td><?php echo htmlspecialchars($row['type']); ?></td>
<td><?php echo (int)$row['word_count']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<div class="card shadow-sm border-0">
<div class="card-body">
<h2 class="h5 mb-3">Language-wise Breakdown</h2>
<div class="table-responsive">
<table id="languageTable" class="table table-striped table-bordered align-middle w-100">
<thead>
<tr>
<th>Language</th>
<th>Dictionary Count</th>
</tr>
</thead>
<tbody>
<?php foreach ($languageStats as $row): ?>
<tr>
<td><?php echo htmlspecialchars($row['language_name']); ?></td>
<td><?php echo (int)$row['dictionary_count']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</main>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/2.3.7/js/dataTables.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script>
$(document).ready(function () {
$('#dictionaryTable').DataTable({
paging: true,
searching: true,
ordering: true,
info: true
});
$('#languageTable').DataTable({
paging: true,
searching: true,
ordering: true,
info: true
});
});
</script>
<?php include 'includes/footer.php'; ?>
</body>
</html>
<?php $conn->close(); ?>