-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCandidate.php
More file actions
373 lines (315 loc) · 9.44 KB
/
Copy pathCandidate.php
File metadata and controls
373 lines (315 loc) · 9.44 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
<!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 src="js/jquery.min.js"></script>
<script src="js/jquery-3.3.1.min.js"></script>
<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'?>
<!-- NAVBAR -->
<!-- MAIN -->
<main>
<div class="head-title">
<div class="left">
<h1>Candidate And Position</h1>
<ul class="breadcrumb">
<li>
<a href="#">Dashboard </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="todo">
<div class="head">
<h3>Elective office (Position)</h3>
<div class="" id="message1"></div>
<a href="ADDOFFCICE.php" class='bx bx-plus' ></a>
</div>
<ul class="todo-list">
<?php $office = $conn->fetch_office($Activeyear);
foreach($office as $row){
?>
<li class="completed">
<p><?php echo $row['Electiveoffice']; ?></p>
<div class="dropdown">
<i class='bx bx-dots-vertical-rounded dropdown-btn'></i>
<div class="dropdown-menu">
<a href="#" onclick="deleteYears(<?= $row['Office_id'] ?>)" class="delete-btns" data-ids="<?= $row['Office_id']; ?>">Delete</a>
</div>
</div>
</li>
<?php }; ?>
<script>
function deleteYears(office_id) {
if (confirm("Are you sure you want to delete this office?")) {
// Perform the AJAX request
$.ajax({
url: 'controllers/delete_office.php',
method: 'POST',
data: { office_id: office_id },
success: function(response) {
// Display success message
$("#message1").html(response);
console.log("Office deleted successfully.");
},
error: function() {
console.log("Failed to delete office.");
}
});
}
}
</script>
</ul>
</div>
</div>
<div class="table-data">
<div class="order">
<div class="" id="message"></div>
<div class="head">
<h3>Candidate</h3>
<div class="search-container">
<input type="text" id="searchInput" placeholder="Search by name or office">
<i class='bx bx-search'></i>
<a href="ADDCANDIDATE.php" class='bx bx-plus' ></a>
</div>
</div>
<table id='dataTable'>
<thead>
<tr>
<th>Name</th>
<th>Elective office</th>
<th>Balot No.</th>
<th>Year</th>
<th>Number of votes</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php $ActiveYearz = $conn->fetchcandidatebyyear($Activeyear);
foreach($ActiveYearz as $row){
$pro = $row['profile_picture'];
?>
<tr>
<td>
<img src="uploads/profile_pictures/<?php echo $pro?>" alt="Profile Picture">
<p><?php echo $row['Candidate_fullname']; ?></p>
</td>
<td><?php echo $row['Electiveoffice']; ?></td>
<td><span style="padding:7px; border-radius:100px;background-color:#f44336;"><?php echo $row['Balotno']; ?></span></td>
<td><span <?php echo $row['OfficeYear']; ?>></td>
<td><span class="status completed">Completed</span></td>
<td><button class="edit-btn" onclick="updateYear(<?= $row['Candidate_id'] ?>)">
<a href="EDIT-CANDIDATE.php?Candidate_id=<?= $row['Candidate_id']; ?>&Candidate-fullname=<?php echo $row['Candidate_fullname']; ?>" class="text-secondary font-weight-bold text-xs" data-toggle="tooltip" data-original-title="Edit user">
<i class='bx bx-edit'></i> <!-- Edit Icon -->
</a>
</button>
<button class="delete-btn" onclick="deleteYear(<?= $row['Candidate_id'] ?>)" data-id="<?= $row['Candidate_id']; ?>">
<i class='bx bx-trash'></i> <!-- Delete Icon -->
</button></td>
</tr>
<?php }; ?>
</tbody>
</table>
</div>
</div>
</main>
<!-- MAIN -->
</section>
<!-- CONTENT -->
<style>
/* Dropdown container */
.dropdown {
position: relative;
display: inline-block;
}
/* Dropdown menu hidden by default */
.dropdown-menu {
display: none;
position: absolute;
background-color: #fff;
min-width: 150px;
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
z-index: 1;
border-radius: 4px;
overflow: hidden;
transition: opacity 0.3s ease, transform 0.3s ease;
opacity: 0;
transform: translateY(-10px);
}
/* Dropdown menu items */
.dropdown-menu a {
color: #333;
padding: 10px 15px;
text-decoration: none;
display: block;
}
/* Dropdown menu item hover effect */
.dropdown-menu a:hover {
background-color: #f1f1f1;
}
/* Show dropdown when active */
.dropdown.show .dropdown-menu {
display: block;
opacity: 1;
transform: translateY(0);
transition: opacity 0.3s ease, transform 0.3s ease;
}
button {
border: none;
background: none;
padding: 2px 10px;
cursor: pointer;
display: inline-flex;
align-items: center;
justify-content: center;
border-radius: 30px;
}
.dropdown {
padding: 5px;
border: 1px solid #ccc;
border-radius: 5px;
}
button i {
font-size: 20px;
color: #fff;
transition: color 0.3s;
}
button.edit-btn {
background-color: #4CAF50; /* Green */
}
button.activate-btn {
background-color: #008CBA; /* Blue */
}
button.delete-btn {
background-color: #f44336; /* Red */
}
button:hover i {
color: #fff;
}
button:hover {
opacity: 0.8;
}
</style>
<script src="script.js"></script>
<script>
$(document).ready(function() {load_data();
function load_data() {
$(document).on('click', '.delete-btn', function() {
var user_id = $(this).attr("data-id");
// console.log("================get course_id================");
// console.log(course_id);
if (confirm("Are you sure want to remove this data?")) {
$.ajax({
url: 'controllers/delete_candidate.php',
method: "POST",
data: {
Year_id: user_id
},
success: function(response) {
$("#message").html(response);
},
error: function(response) {
console.log("Failed");
}
})
}
});
}
// Event listener using event delegation
document.addEventListener("click", function (e) {
const dropdownBtn = e.target.closest(".dropdown-btn");
if (dropdownBtn) {
// Prevent closing all dropdowns immediately
e.stopPropagation();
const dropdown = dropdownBtn.parentElement;
dropdown.classList.toggle("show");
} else {
// Close all dropdowns when clicking outside
document.querySelectorAll(".dropdown").forEach(dropdown => {
dropdown.classList.remove("show");
});
}
});
});
// 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);
// Add click event listener to all dropdown buttons
document.querySelectorAll(".dropdown-btn").forEach(button => {
button.addEventListener("click", function (e) {
e.stopPropagation();
const dropdown = this.nextElementSibling; // Correct reference to dropdown menu
dropdown.classList.toggle("show");
});
});
// Close all dropdowns when clicking outside
document.addEventListener("click", function () {
document.querySelectorAll(".dropdown").forEach(dropdown => {
dropdown.classList.remove("show");
});
});
</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>