Skip to content
This repository has been archived by the owner on Jan 3, 2025. It is now read-only.

Commit

Permalink
Frontend Framework Update
Browse files Browse the repository at this point in the history
  • Loading branch information
SSL-ACTX committed May 25, 2024
1 parent 20e759d commit 7d9484d
Show file tree
Hide file tree
Showing 25 changed files with 5,310 additions and 287 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.exe
node_modules/
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 39 additions & 11 deletions backend/CdListLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,48 @@
$positions_sql = "SELECT DISTINCT position FROM candidates";
$positions_result = $conn->query($positions_sql);

// Predefined order for the positions
$position_order = [
"SK Chairperson",
"SK Secretary",
"SK Treasurer",
"SK Auditor",
"SK Kagawad"
];

$positions = [];

if ($positions_result->num_rows > 0) {
// Loop through each position
ob_start(); // Start output buffering
// Store positions in an array
while ($position_row = $positions_result->fetch_assoc()) {
$position = $position_row["position"];
$positions[] = $position_row["position"];
}

// Sort positions based on the predefined order
usort($positions, function($a, $b) use ($position_order) {
$pos_a = array_search($a, $position_order);
$pos_b = array_search($b, $position_order);

if ($pos_a === false) $pos_a = count($position_order);
if ($pos_b === false) $pos_b = count($position_order);

return $pos_a - $pos_b;
});

// Loop through each position in the sorted order
ob_start(); // Start output buffering
echo '<div class="grid grid-cols-1 md:grid-cols-2 gap-8">'; // Start the grid container
foreach ($positions as $position) {
?>
<!-- Table for candidates running for <?php echo $position; ?> -->
<div class="w-full mb-8">
<h2 class="text-xl font-semibold mb-2"><?php echo $position; ?></h2>
<table class="min-w-full divide-y divide-gray-200 bg-white shadow-lg overflow-hidden sm:rounded-lg">
<thead class="bg-gray-50">
<div class="bg-white p-4 shadow-lg rounded-lg">
<h2 class="text-xl font-semibold mb-2 text-black"><?php echo $position; ?></h2>
<table class="min-w-full divide-y divide-gray-200 bg-white shadow overflow-hidden sm:rounded-lg border border-gray-700">
<thead class="bg-gray-700">
<tr>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Age</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Party</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-white uppercase tracking-wider">Name</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-white uppercase tracking-wider">Age</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-white uppercase tracking-wider">Party</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
Expand All @@ -31,7 +58,7 @@

if ($candidates_result->num_rows > 0) {
while ($row = $candidates_result->fetch_assoc()) {
echo "<tr>";
echo "<tr class='text-black'>";
echo "<td class='px-6 py-4 whitespace-nowrap'>" . $row["name"] . "</td>";
echo "<td class='px-6 py-4 whitespace-nowrap'>" . $row["age"] . "</td>";
echo "<td class='px-6 py-4 whitespace-nowrap'>" . $row["party_affiliation"] . "</td>";
Expand All @@ -46,6 +73,7 @@
</div>
<?php
}
echo '</div>'; // End the grid container
$output = ob_get_clean(); // Get the buffered output
echo $output; // Output the candidate list
} else {
Expand Down
12 changes: 3 additions & 9 deletions backend/candidate_list.php
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
<?php
session_start();

// Check if user is logged in and is a voter, if not, redirect to login page
if (!isset($_SESSION["username"])) {
header("Location: ../index.html");
exit();
}

// Include database connection
require_once "./conn/db_connection.php";

?>

<!DOCTYPE html>
<html lang="en">
<html lang="en" data-theme="cyberpunk">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SK E-Voting System - Candidate List</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
<link href="../frontend/css/output.css" rel="stylesheet">
</head>
<body class="bg-gray-100 p-8">
<h1 class="text-2xl font-bold mb-4">Candidate List</h1><hr><br>
<h1 class="text-2xl font-bold mb-4 text-black">Candidate List</h1><hr><br>

<!-- Candidate list container -->
<div id="candidateListContainer">
<?php include 'CdListLoader.php'; ?>
</div>

<script>
// Function to load candidate list using AJAX
function loadCandidateList() {
var xhr = new XMLHttpRequest();
xhr.open('GET', './CdListLoader.php', true);
Expand All @@ -47,7 +42,6 @@ function loadCandidateList() {
xhr.send();
}

// Load candidate list immediately and every 5 seconds
loadCandidateList();
setInterval(loadCandidateList, 5000);
</script>
Expand Down
36 changes: 22 additions & 14 deletions backend/candidate_registration.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,46 @@
<?php
session_start();

// Check if user is logged in, if not, redirect to login page
if (!isset($_SESSION["username"])) {
header("Location: ../index.html");
exit();
}

// Include database connection
require_once "./conn/db_connection.php";

// Check if the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Retrieve form data
$name = $_POST["name"];
$age = $_POST["age"];
$residency = $_POST["residency"];
$citizenship = $_POST["citizenship"];
$party = $_POST["party_affiliation"];
$position = $_POST["position"];

// Set the default approval status to 0 (not approved)
$approval_status = 0;
$errors = [];

$candidate_id = "CD_" . uniqid();
if (empty($name)) $errors[] = "Name is required.";
if (empty($age)) $errors[] = "Age is required.";
if (empty($residency)) $errors[] = "Residency is required.";
if (empty($citizenship)) $errors[] = "Citizenship is required.";
if (empty($party)) $errors[] = "Party affiliation is required.";
if (empty($position)) $errors[] = "Position is required.";

// Insert data into the database, including the approval status
$sql = "INSERT INTO candidates (candidate_id, name, age, residency, citizenship, party_affiliation, position, approval_status)
VALUES ('$candidate_id', '$name', '$age', '$residency', '$citizenship', '$party', '$position', '$approval_status')";

if ($conn->query($sql) === TRUE) {
echo "Candidate registered successfully!";
if (!empty($errors)) {
echo implode('<br>', $errors);
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
$approval_status = 0;
$candidate_id = "CD_" . uniqid();

$stmt = $conn->prepare("INSERT INTO candidates (candidate_id, name, age, residency, citizenship, party_affiliation, position, approval_status) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssissssi", $candidate_id, $name, $age, $residency, $citizenship, $party, $position, $approval_status);

if ($stmt->execute()) {
echo "Candidate registered successfully!";
} else {
echo "Error: " . $stmt->error;
}

$stmt->close();
}

$conn->close();
Expand Down
93 changes: 48 additions & 45 deletions backend/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
?>

<!DOCTYPE html>
<html lang="en">
<html lang="en" data-theme="dark">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SK E-Voting System - User Dashboard</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
<link rel="stylesheet" href="../frontend/css/output.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="./js/RulesNotif.js" async></script>
<!--<script src="./js/alrVoted.js" async></script>-->
Expand All @@ -29,59 +29,62 @@
<body class="bg-gray-100">
<div class="flex h-screen">
<!-- Sidebar -->
<div class="bg-gray-800 text-gray-100 flex-shrink-0 w-64 z-50 sidebar">
<div class="bg-gray-800 text-gray-100 flex-shrink-0 w-64 z-50 sidebar"><br>
<div class="p-4">
<!-- Logo -->
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/Sangguniang_Kabataan_logo.svg/150px-Sangguniang_Kabataan_logo.svg.png"
alt="Logo" class="w-32 mx-auto mb-4">
<!-- Navigation Links -->
<ul>
<li class="mb-2">
<div class="flex items-center">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
stroke="currentColor" class="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round"
d="M8.25 21v-4.875c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125V21m0 0h4.5V3.545M12.75 21h7.5V10.75M2.25 21h1.5m18 0h-18M2.25 9l4.5-1.636M18.75 3l-1.5.545m0 6.205 3 1m1.5.5-1.5-.5M6.75 7.364V3h-3v18m3-13.636 10.5-3.819" />
<img src="https://i.ibb.co/rsxxP8b/150px-Sangguniang-Kabataan-logo-svg.png" alt="Logo"
class="w-32 mx-auto mb-4">
<div class="w-full px-2">
<div class="flex flex-col items-center w-full mt-3 border-t border-gray-700">
<a class="flex items-center w-full h-12 px-3 mt-2 rounded hover:bg-gray-700 hover:text-gray-300"
href="#home" onclick="loadPage('../frontend/home.html')">
<svg class="w-6 h-6 stroke-current" xmlns="http://www.w3.org/2000/svg" fill="none"
viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6" />
</svg>

<a href="#home" onclick="loadPage('../frontend/home.html')"
class="block px-4 py-2 rounded-md hover:bg-gray-700 flex-grow">Home</a>
</div>
</li>
<li class="mb-2">
<div class="flex items-center">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
stroke="currentColor" class="w-6 h-6">
<span class="ml-2 text-sm font-medium">Home</span>
</a>
<a class="flex items-center w-full h-12 px-3 mt-2 rounded hover:bg-gray-700 hover:text-gray-300"
href="#vote" onclick="loadPage('../frontend/voteReg.html')">
<svg class="w-6 h-6 stroke-current" xmlns="http://www.w3.org/2000/svg" fill="none"
viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
<path stroke-linecap="round" stroke-linejoin="round"
d="m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L10.582 16.07a4.5 4.5 0 0 1-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 0 1 1.13-1.897l8.932-8.931Zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0 1 15.75 21H5.25A2.25 2.25 0 0 1 3 18.75V8.25A2.25 2.25 0 0 1 5.25 6H10" />
</svg>
<a href="#voter" onclick="loadPage('../frontend/voterReg.html')"
class="block px-4 py-2 rounded-md hover:bg-gray-700 flex-grow votec">Voter</a>
</div>
</li>
<li class="mb-2">
<div class="flex items-center">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
stroke="currentColor" class="w-6 h-6">
<span class="ml-2 text-sm font-medium">Voter</span>
</a>
<a class="flex items-center w-full h-12 px-3 mt-2 rounded hover:bg-gray-700 hover:text-gray-300"
href="#candidacy" onclick="loadPage('../frontend/candidateReg.html')">
<svg class="w-6 h-6 stroke-current" xmlns="http://www.w3.org/2000/svg" fill="none"
viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
<path stroke-linecap="round" stroke-linejoin="round"
d="M12 7.5h1.5m-1.5 3h1.5m-7.5 3h7.5m-7.5 3h7.5m3-9h3.375c.621 0 1.125.504 1.125 1.125V18a2.25 2.25 0 0 1-2.25 2.25M16.5 7.5V18a2.25 2.25 0 0 0 2.25 2.25M16.5 7.5V4.875c0-.621-.504-1.125-1.125-1.125H4.125C3.504 3.75 3 4.254 3 4.875V18a2.25 2.25 0 0 0 2.25 2.25h13.5M6 7.5h3v3H6v-3Z" />
d="M15.75 9V5.25A2.25 2.25 0 0 0 13.5 3h-6a2.25 2.25 0 0 0-2.25 2.25v13.5A2.25 2.25 0 0 0 7.5 21h6a2.25 2.25 0 0 0 2.25-2.25V15m3 0 3-3m0 0-3-3m3 3H9" />
</svg>
<a href="#candidacy" onclick="loadPage('../frontend/candidateReg.html')"
class="block px-4 py-2 rounded-md hover:bg-gray-700 flex-grow">Candidacy</a>
</div>
</li>
<li class="mb-2">
<div class="flex items-center">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
stroke="currentColor" class="w-6 h-6">
<span class="ml-2 text-sm font-medium">Candidacy</span>
</a>
</div>
<div class="flex flex-col items-center w-full mt-2 border-t border-gray-700">
<a class="flex items-center w-full h-12 px-3 mt-2 rounded hover:bg-gray-700 hover:text-gray-300"
href="#about" onclick="loadPage('../frontend/about.html')">
<svg class="w-6 h-6 stroke-current" xmlns="http://www.w3.org/2000/svg" fill="none"
viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
<path stroke-linecap="round" stroke-linejoin="round"
d="m11.25 11.25.041-.02a.75.75 0 0 1 1.063.852l-.708 2.836a.75.75 0 0 0 1.063.853l.041-.021M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9-3.75h.008v.008H12V8.25Z" />
</svg>
<span class="ml-2 text-sm font-medium">About</span>
</a>
<a class="relative flex items-center w-full h-12 px-3 mt-2 rounded hover:bg-gray-700 hover:text-gray-300"
href="./logout.php">
<svg class="w-6 h-6 stroke-current" xmlns="http://www.w3.org/2000/svg" fill="none"
viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
<path stroke-linecap="round" stroke-linejoin="round"
d="M9 15 3 9m0 0 6-6M3 9h12a6 6 0 0 1 0 12h-3" />
</svg>
<a href="./logout.php"
class="block px-4 py-2 rounded-md hover:bg-gray-700 flex-grow">Logout</a>
</div>
</li>
</ul>
<span class="ml-2 text-sm font-medium">Logout</span>
</a>
</div>

</div>
</div>
</div>

Expand Down
9 changes: 9 additions & 0 deletions backend/js/stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
document.addEventListener('DOMContentLoaded', function() {
fetch('./fetchUsers.php')
.then(response => response.json())
.then(data => {
const userCount = data.user_count;
document.getElementById('user-count').innerText = userCount;
})
.catch(error => console.error('Error fetching user count:', error));
});
3 changes: 3 additions & 0 deletions backend/js/voteForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ function initializeVoteScript() {
};
xhr.send(formData);
});


}

// Call this function after dynamically loading the content
initializeVoteScript();

4 changes: 2 additions & 2 deletions backend/loadPositions.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
$candidate_result = $conn->query($candidate_sql);

$html .= "<fieldset class='border border-gray-400 rounded-lg p-4 mb-4'>";
$html .= "<legend class='text-lg font-semibold mb-2'>$position</legend>";
$html .= "<legend class='text-lg font-semibold mb-2 text-gray-800'>$position</legend>";

if ($candidate_result->num_rows > 0) {
while ($row = $candidate_result->fetch_assoc()) {
$candidate_id = $row["id"];
$candidate_name = $row["name"];
$party_affiliation = $row["party_affiliation"];
$html .= "<label class='block mb-2'><input type='radio' name='$position' value='$candidate_id' class='mr-2'>$candidate_name <b>($party_affiliation)</b></label>";
$html .= "<label class='block mb-2 text-gray-800'><input type='radio' name='$position' value='$candidate_id' class='mr-2'>$candidate_name <b>($party_affiliation)</b></label>";
}
} else {
$html .= "<p class='text-gray-500'>No approved candidates available for $position</p>";
Expand Down
Loading

0 comments on commit 7d9484d

Please sign in to comment.