-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreports.php
More file actions
187 lines (156 loc) · 3.96 KB
/
reports.php
File metadata and controls
187 lines (156 loc) · 3.96 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
<?php include 'includes/header.php'; ?>
<?php include 'includes/navbar.php'; ?>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include("includes/db_mysqli.php");
if (!isset($conn)) {
die("Database connection not found");
}
/* =========================
TOTAL DICTIONARIES
========================= */
$res = mysqli_query($conn, "SELECT COUNT(*) AS total FROM dictionaries");
$totalDictionaries = mysqli_fetch_assoc($res)['total'] ?? 0;
/* =========================
TOTAL WORDS
========================= */
$res = mysqli_query($conn, "
SELECT COUNT(*) AS total
FROM dictionary_entries
WHERE is_active = 1
");
$totalWords = mysqli_fetch_assoc($res)['total'] ?? 0;
/* =========================
TYPE BREAKDOWN (PIE CHART)
========================= */
$res = mysqli_query($conn, "
SELECT type, COUNT(*) AS total
FROM dictionaries
GROUP BY type
");
$types = [];
$typeCounts = [];
while ($row = mysqli_fetch_assoc($res)) {
$types[] = $row['type'];
$typeCounts[] = (int)$row['total'];
}
/* =========================
LANGUAGE BREAKDOWN (BAR CHART)
========================= */
$res = mysqli_query($conn, "
SELECT lang_1 AS language, COUNT(*) AS total
FROM dictionary_entries
WHERE lang_1 IS NOT NULL AND lang_1 != ''
GROUP BY lang_1
");
$languages = [];
$langCounts = [];
while ($row = mysqli_fetch_assoc($res)) {
$languages[] = $row['language'];
$langCounts[] = (int)$row['total'];
}
?>
<head>
<title>IndicLex Reports</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
body {
font-family: Arial;
padding: 20px;
}
h1 {
text-align: center;
}
.stats {
display: flex;
gap: 20px;
margin-bottom: 20px;
}
.box {
flex: 1;
padding: 15px;
border-radius: 10px;
text-align: center;
}
.grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
}
.card {
padding: 20px;
border-radius: 10px;
}
</style>
</head>
<body>
<h1>📊 IndicLex Reports </h1>
<!-- SUMMARY -->
<div class="stats">
<div class="box">
<h2><?= $totalDictionaries ?></h2>
<p>Total Dictionaries</p>
</div>
<div class="box">
<h2><?= $totalWords ?></h2>
<p>Total Words</p>
</div>
<div class="box">
<h2><?= count($languages) ?></h2>
<p>Languages</p>
</div>
</div>
<!-- CHARTS -->
<div class="grid">
<!-- PIE CHART -->
<div class="card">
<h3>Dictionary Types</h3>
<canvas id="typeChart"></canvas>
</div>
<!-- BAR CHART -->
<div class="card">
<h3>Language Distribution</h3>
<canvas id="langChart"></canvas>
</div>
</div>
<script>
/* =========================
PIE CHART - TYPES
========================= */
new Chart(document.getElementById("typeChart"), {
type: "pie",
data: {
labels: <?= json_encode($types) ?>,
datasets: [{
data: <?= json_encode($typeCounts) ?>,
backgroundColor: [
"#6366f1",
"#22c55e",
"#f59e0b",
"#ef4444",
"#06b6d4"
]
}]
}
});
/* =========================
BAR CHART - LANGUAGES
========================= */
new Chart(document.getElementById("langChart"), {
type: "bar",
data: {
labels: <?= json_encode($languages) ?>,
datasets: [{
label: "Dictionary Entries",
data: <?= json_encode($langCounts) ?>,
backgroundColor: "#4f46e5"
}]
},
options: {
responsive: true
}
});
</script>
</body>
</html>