-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalytics.php
More file actions
298 lines (255 loc) · 8.28 KB
/
Copy pathanalytics.php
File metadata and controls
298 lines (255 loc) · 8.28 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Boxicons -->
<link href='https://unpkg.com/boxicons@2.0.9/css/boxicons.min.css' rel='stylesheet'>
<!-- My CSS -->
<link rel="stylesheet" href="style.css">
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<title>voting system</title>
</head>
<body>
<?php include 'sidebar/sidebar.php'?>
<?php $conn = new class_model();
$Activeyear = $conn->fetchActive_year();
foreach($Activeyear as $row){
$Activeyear=$row['Year'];
};
?>
<!-- CONTENT -->
<section id="content">
<!-- NAVBAR -->
<?php include 'header/header.php'?>
<?php $Voucher=$conn->fetch_voucher(); ?>
<?php $Allyears = $conn->select_years() ?>
<main>
<div class="head-title">
<div class="left">
<h1>Analytics</h1>
<ul class="breadcrumb">
<li>
<a href="#">Analytics</a>
</li>
<li><i class='bx bx-chevron-right' ></i></li>
<li>
<a class="active" href="#">Home</a>
</li>
</ul>
</div>
<a href="#" class="btn-download">
<i class='bx bxs-cloud-download' ></i>
<span class="text">Download PDF</span>
</a>
</div>
<div class="table-data">
<div class="order">
<div class="head">
<h3>Number of Voters</h3>
</div>
<button id="change-chart" class='bx bx-filter'>Change to Classic</button>
<br><br>
<div id="chart_div" style="width: 800px; height: 500px;"></div>
</div>
<div class="todo">
<div class="head">
<h3>Top Candidate</h3>
</div>
<div id="piechart_3d" style="width: 500px; height: 500px;"></div>
</div>
</div>
<div class="table-data">
<div class="order">
<div class="head">
<h3>Voter Voucher</h3>
<div class="search-container">
<input type="text" id="searchInput" placeholder="Search by name or office">
<i class='bx bx-search'></i>
</div>
</div>
<table id='dataTable'>
<thead>
<tr>
<th>Voucher Code</th>
<th>Use</th>
<th>Voted</th>
</tr>
</thead>
<tbody>
<?php $Voucher=$conn->fetch_voucher();
foreach ($Voucher as $row):
?>
<tr>
<td>
<p><?= $row['Voucher_code'] ?></p>
</td>
<?php if($row['Status']== '1'){ ?>
<td><span class="status completed">Used</span></td>
<?php }elseif($row['Status']== '0'){?>
<td><span class="status pending">Not yet</span></td>
<?php } ?>
<?php if ( $row['isvote'] == '1'){ ?>
<td><span class="status completed">Voted</span></td>
<?php }elseif($row['isvote'] == '0'){ ?>
<td><span class="status pending">Not Yet</span></td>
<?php } ?>
</tr>
<?php endforeach ?>
</tbody>
</table>
</div>
</div>
</main>
<!-- MAIN -->
</section>
<script src="script.js"></script>
<script>
google.charts.load("current", {packages: ["corechart"]});
google.charts.setOnLoadCallback(drawChart);
let isDarkMode = false;
<?php
$candidatecurrent = $conn->fetchcandidatebyyear($Activeyear);
$chartDatash = [];
foreach ($candidatecurrent as $row) {
// Get candidate ID and number of votes for that candidate
$Candidate_id = $row['Candidate_id'];
$numberofvotes = $conn->count_votes($Candidate_id); // Get votes for each candidate
// Ensure safe output for candidate names and numbers
$candidate_name = addslashes($row['candidate']);
$chartDatash[] = "['$candidate_name', $numberofvotes]";
}
$chartDataStringsh = implode(",", $chartDatash);
?>
function drawChart() {
const backgroundColor = isDarkMode ? "transparent" : "transparent"; // Dark or light background
const textColor = isDarkMode ? "#ffffff" : "#000000"; // Text color based on theme
var data = google.visualization.arrayToDataTable([
["Task", "Hours per Day"]
<?php echo $chartDataStringsh; ?>
]);
var options = {
title: "Votes per Candidate",
is3D: true,
backgroundColor: backgroundColor,
titleTextStyle: {
color: textColor,
},
legend: {
textStyle: { color: textColor },
},
};
var chart = new google.visualization.PieChart(
document.getElementById("piechart_3d")
);
chart.draw(data, options);
}
// Toggle dark mode
document.querySelector("#switch-mode").addEventListener("change", function () {
isDarkMode = this.checked; // Set isDarkMode based on checkbox state
document.body.classList.toggle("dark-mode", isDarkMode); // Toggle dark mode for body
drawChart(); // Redraw chart with updated colors
});
window.addEventListener('resize', drawChart);
</script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart', 'bar']});
google.charts.setOnLoadCallback(drawStuff);
function drawStuff() {
var button = document.getElementById('change-chart');
var chartDiv = document.getElementById('chart_div');
<?php $Allyears = $conn->select_years();
$chartData = [];
foreach ($Allyears as $row) {
$Activeyear = $row['Year'];
$numberofvoter= $conn->count_Voter($Activeyear);
$numberofCandidate = $conn->count_candidate($Activeyear);
$chartData[] = "['" . $row['Year'] . "', '".$numberofvoter."', '".$numberofCandidate."']";
}
// Convert the PHP array to a JavaScript compatible string
$chartDataString = implode(",", $chartData);
?>
var data = google.visualization.arrayToDataTable([
['Visual', 'Voters', 'Candidate'],
<?php echo $chartDataString; ?>
]);
var materialOptions = {
width: 900,
chart: {
title: 'Voters Each Election',
subtitle: 'Voters on the left, Candidate on the right'
},
backgroundColor: 'transparent',
series: {
0: { axis: 'Candidate' }, // Bind series 0 to an axis named 'distance'.
1: { axis: 'Voters' } // Bind series 1 to an axis named 'brightness'.
},
axes: {
y: {
distance: {label: 'parsecs'}, // Left y-axis.
brightness: {side: 'right', label: 'apparent magnitude'} // Right y-axis.
}
}
};
var classicOptions = {
width: 900,
series: {
0: {targetAxisIndex: 0},
1: {targetAxisIndex: 1}
},
backgroundColor: 'transparent',
title: 'Voters on the left, Candidate on the right',
vAxes: {
// Adds titles to each axis.
0: {title: 'Candidate'},
1: {title: 'Voters'}
}
};
function drawMaterialChart() {
var materialChart = new google.charts.Bar(chartDiv);
materialChart.draw(data, google.charts.Bar.convertOptions(materialOptions));
button.innerText = 'Change to Classic';
button.onclick = drawClassicChart;
}
function drawClassicChart() {
var classicChart = new google.visualization.ColumnChart(chartDiv);
classicChart.draw(data, classicOptions);
button.innerText = 'Change to Material';
button.onclick = drawMaterialChart;
}
drawMaterialChart();
};
</script>
<script>
$(document).on('click', function (e) {
if (!$(e.target).closest('.form-input').length) {
$('#searchResults').hide();
}
});
$(document).ready(function() {
// Search Functionality
$('#searchInput').on('keyup', function() {
let value = $(this).val().toLowerCase();
$('#dataTable tbody tr').filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1);
});
});
// Rows per Page Dropdown
$('#rowsPerPage').on('change', function() {
let rowsToShow = $(this).val();
let rows = $('#dataTable tbody tr');
rows.hide(); // Hide all rows
rows.slice(0, rowsToShow).show(); // Show the selected number of rows
});
// Initial Rows Display
$('#rowsPerPage').trigger('change');
});
// Hide dropdown if clicked outside
$(document).on('click', function (e) {
if (!$(e.target).closest('.form-input').length) {
$('#searchResults').hide();
}
});
</script>
</body>
</html>