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

Commit

Permalink
Major update
Browse files Browse the repository at this point in the history
  • Loading branch information
SSL-ACTX committed May 22, 2024
1 parent cd14485 commit e777c8e
Show file tree
Hide file tree
Showing 20 changed files with 431 additions and 163 deletions.
3 changes: 3 additions & 0 deletions api/gemini_api_key.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"apiKey": "AIzaSyAvNlB1-cygF8C6XWpPN9K0eryqg61I2Ps"
}
Binary file added assets/img/skl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions backend/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function toggleSidebar() {
$('.sidebar').toggleClass('active');
}
</script>

</body>

</html>
91 changes: 1 addition & 90 deletions backend/js/RulesNotif.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,93 +82,4 @@ function showAlreadyVotedContainer() {

// Set interval to call the checking function every 2 seconds for demonstration
var interval = setInterval(checkSubmitVote, 2000);
}

function displayRules() {
var closeCounter = 0; // Counter to keep track of close button clicks
var intervalId; // Variable to store the interval ID

// Function to check if "voting is closed" is detected in the document
function checkVotingClosed() {
if (document.body.textContent.includes("Voting is closed.")) {
console.log("Found 'voting closed'");
if (intervalId) {
clearInterval(intervalId); // Clear the interval if the text is found
}
return true;
}
return false;
}

// Run the initial check
if (checkVotingClosed()) {
return; // Exit the function if "voting is closed" is found
}

// Set up continuous checking every 5 seconds (adjust interval as needed)
intervalId = setInterval(function() {
if (checkVotingClosed()) {
if (floatingContainer) {
floatingContainer.remove(); // Remove the container if it's being displayed
}
}
}, 3000); // Check every 5 seconds

// Create the floating container element
var floatingContainer = document.createElement("div");
floatingContainer.className = "fixed inset-0 flex items-center justify-center bg-black bg-opacity-50 z-10";

// Create the inner content of the floating container
var innerContent = document.createElement("div");
innerContent.className = "bg-white p-8 rounded-lg max-w-md";

// Add the rules and regulations content
innerContent.innerHTML = `
<h2 class="text-xl font-semibold mb-4">Rules and Regulations for Voting</h2>
<ol class="list-decimal list-inside text-gray-700 mb-4">
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
<li>Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</li>
<li>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</li>
</ol>
<button id="agreeButton" class="mt-4 bg-blue-500 text-white px-4 py-2 rounded-md hover:bg-blue-600 disabled:opacity-50">Agree and Vote</button>
<button id="closeButton" class="ml-2 bg-gray-300 text-gray-700 px-4 py-2 rounded-md hover:bg-gray-400">Close</button>
`;

// Append the inner content to the floating container
floatingContainer.appendChild(innerContent);

// Append the floating container to the body
document.body.appendChild(floatingContainer);

// Add event listener to close the floating container when "Agree and Vote" button is clicked
document.getElementById("agreeButton").addEventListener("click", function() {
floatingContainer.remove();
if (intervalId) {
clearInterval(intervalId); // Clear the interval when the container is closed
}
});

// Add event listener to handle "Close" button click
document.getElementById("closeButton").addEventListener("click", function() {
closeCounter++; // Increment close button click counter
if (closeCounter >= 5) { // If close button is clicked 5 times
// Create notification for redirection
var notification = document.createElement("div");
notification.className = "fixed top-8 right-8 p-4 max-w-sm bg-white border border-gray-600 rounded-lg rounded-xl shadow-lg flex items-center space-x-4 z-60";
notification.innerHTML = `
<div class="shrink-0">
<img class="h-16 w-16" src="https://www.svgrepo.com/show/326725/notifications-circle-outline.svg" alt="Notification Icon">
</div>
<div>
<div class="text-xl font-medium text-black">Redirecting to logout...</div>
</div>
`;
document.body.appendChild(notification);

// Redirect to logout after 2 seconds
setTimeout(function() {
window.location.href = "./logout.php";
}, 2000);
}
});
}
}
95 changes: 95 additions & 0 deletions backend/js/chatbot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
(function() {
// Create chatbot container
const chatbotContainer = document.createElement('div');
chatbotContainer.className = 'fixed bottom-15 right-24 w-72 h-96 bg-white border border-gray-300 rounded-lg shadow-lg flex flex-col overflow-hidden z-100 hidden';

chatbotContainer.innerHTML = `
<div class="bg-blue-600 text-white p-3 text-center text-lg">SK E-Voting AssistBot</div>
<div class="p-3 flex-1 overflow-y-auto" id="chatbotContent"></div>
<div class="flex border-t border-gray-300">
<input type="text" id="chatbotInput" placeholder="Type a message..." class="flex-1 p-2 border-none focus:outline-none" />
<button id="chatbotSend" class="p-2 bg-blue-600 text-white">Send</button>
</div>
`;

document.body.appendChild(chatbotContainer);

// Create chatbot icon
const chatbotIcon = document.createElement('div');
chatbotIcon.className = 'fixed bottom-20 right-20 w-12 h-12 bg-blue-600 rounded-full flex items-center justify-center cursor-pointer z-50';
chatbotIcon.innerHTML = `
<svg viewBox="0 0 24 24" class="fill-current text-white w-6 h-6">
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10c1.85 0 3.58-.5 5.08-1.35l3.8 1.02a1 1 0 0 0 1.24-1.24l-1.02-3.8A9.941 9.941 0 0 0 22 12c0-5.52-4.48-10-10-10zm-2 14.5v-5H8v-2h2V8h2v1.5h2v2h-2v5h-2z"/>
</svg>
`;

document.body.appendChild(chatbotIcon);

// Toggle chatbot visibility
chatbotIcon.addEventListener('click', function() {
chatbotContainer.classList.toggle('hidden');
});

// Function to send message to API
function sendMessage(apiKey, prompt) {
const apiEndpoint = "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent";
const instruction = "Instructions: Act like an SK E-Voting assistant, customer service, feedback, and answer often related to the system, be sure to answer properly. Also your name is SKBot, dont include this unless asked. //End instructions --> Prompt part: User's prompt:";
const fullPrompt = `${instruction} ${prompt}`;
const payload = JSON.stringify({ contents: [{ parts: [{ text: fullPrompt }] }] });
const headers = { "Content-Type": "application/json" };

const startTime = Date.now();

fetch(`${apiEndpoint}?key=${apiKey}`, {
method: "POST",
headers: headers,
body: payload
})
.then(response => response.json())
.then(data => {
const endTime = Date.now();
const elapsedTime = (endTime - startTime) / 1000;

let generatedText = "Error: Unexpected response structure";
if (data.candidates && data.candidates[0] && data.candidates[0].content && data.candidates[0].content.parts && data.candidates[0].content.parts[0]) {
generatedText = data.candidates[0].content.parts[0].text;
}

const chatbotContent = document.getElementById('chatbotContent');
chatbotContent.innerHTML += `<div class="mb-2"><strong>SKBot:</strong> ${generatedText}</div>`;
console.log("Time taken:", elapsedTime, "seconds");
})
.catch(error => {
console.error("Error:", error);
});
}


// Fetch API key from JSON file and handle send button click
fetch('./api/gemini_api_key.json')
.then(response => response.json())
.then(data => {
const apiKey = data.apiKey;

document.getElementById('chatbotSend').addEventListener('click', function() {
const input = document.getElementById('chatbotInput');
const prompt = input.value;
if (prompt) {
sendMessage(apiKey, prompt);
const chatbotContent = document.getElementById('chatbotContent');
chatbotContent.innerHTML += `<div class="mb-2"><strong>You:</strong> ${prompt}</div>`;
input.value = '';
}
});
})
.catch(error => {
console.error('Error fetching API key:', error);
});
})();

// create nalang kayo ng json file na ganito:
// - gemini_api_key.json
// contents:
// {
// "apiKey": "AIzaSyAvNlB1-cygF8C6XWpPN9K0eryqg61I2Ps"
// }
14 changes: 14 additions & 0 deletions backend/js/displayRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,20 @@ $(document).ready(function () {
}, 2000);
}
});

// Close the container if URL hash doesn't contain #vote
function closeContainerIfNotInVote() {
if (window.location.hash !== '#vote') {
if (floatingContainer) {
floatingContainer.remove();
}
clearInterval(intervalId); // Clear the interval
console.log('Rules closed because not in #vote');
}
}

// Check URL hash every second (adjust interval as needed)
var intervalId = setInterval(closeContainerIfNotInVote, 3900);
}

});
18 changes: 18 additions & 0 deletions backend/js/skInjectLogo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
document.addEventListener('DOMContentLoaded', function() {
const container = document.createElement('div');
container.className = 'fixed top-0 left-0 p-4 z-50 flex items-center';

const logoImg = document.createElement('img');
logoImg.src = 'https://i.ibb.co/M1cybFS/skl.png';
logoImg.alt = 'Sangguniang Kabataan';
logoImg.style.width = '80px';

const heading = document.createElement('h1');
heading.textContent = 'SK E-Voting System';
heading.className = 'text-2xl text-gray-700 ml-4';

container.appendChild(logoImg);
container.appendChild(heading);

document.body.appendChild(container);
});
71 changes: 71 additions & 0 deletions backend/js/validator001.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
function createNotification1(message) {
const notification = document.createElement('div');
notification.className = `bg-white rounded-xl shadow-lg overflow-hidden animate-slidein transition-all duration-500`;

notification.innerHTML = `
<div class="flex items-center space-x-4 p-4 bg-red-100 border border-red-400 text-red-700 rounded-lg">
<img class="h-12 w-12" src="https://icon-library.com/images/warning-icon-svg/warning-icon-svg-11.jpg" alt="Logo">
<div>
<div class="text-xl font-medium text-red-800">System Alert</div>
<p>${message}</p>
</div>
</div>
`;

const notificationContainer = document.getElementById('notificationContainer');
notificationContainer.appendChild(notification);

setTimeout(() => {
notification.remove();
}, 3000);
}

document.addEventListener('DOMContentLoaded', function () {
const passwordInputs = document.querySelectorAll('input[type="password"]');
passwordInputs.forEach(function (input) {
input.addEventListener('input', function (event) {
const password = event.target.value;
if (password.length < 6) {
event.target.setCustomValidity('Password must be at least 6 characters long.');
} else {
event.target.setCustomValidity('');
}
const illegalCharacters = ['<', '>', '&', '"', '\''];
for (let char of illegalCharacters) {
if (password.includes(char)) {
event.target.value = password.replace(new RegExp(char, 'g'), '');
createNotification1("Warning: You're using illegal characters!");
return;
}
}
});
});

const allInputs = document.querySelectorAll('input[type="text"], input[type="email"]');
allInputs.forEach(function (input) {
input.addEventListener('input', function (event) {
const inputValue = event.target.value;
const illegalCharacters = ['<', '>', '&', '"', '\''];
for (let char of illegalCharacters) {
if (inputValue.includes(char)) {
event.target.value = inputValue.replace(new RegExp(char, 'g'), '');
createNotification1("Warning: You're using illegal characters!");
return;
}
}
});
});

const form = document.querySelector('form');
form.addEventListener('submit', function (event) {
const allInputs = document.querySelectorAll('input[type="text"], input[type="email"]');
allInputs.forEach(function (input) {
const inputValue = input.value;
if (inputValue.includes('<script>') || inputValue.includes('<?php') || inputValue.includes('script')) {
event.preventDefault();
createNotification1("Warning: Server-side scripting isn't allowed!");
return;
}
});
});
});
8 changes: 7 additions & 1 deletion backend/js/voteForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ function initializeVoteScript() {
}
// Clear the notification
document.getElementById('notif').innerHTML = '';

// Remove 'hidden' class from mCont if voting is open
document.getElementById('mCont').classList.remove('hidden');
} else {
// Voting is closed
document.getElementById('notif').innerHTML = `
Expand All @@ -100,6 +103,9 @@ function initializeVoteScript() {
</div>
</div>
</div>`;

// Add 'hidden' class to mCont if voting is closed
document.getElementById('mCont').classList.add('hidden');
}
} else {
console.error('Error checking voting status');
Expand All @@ -108,7 +114,7 @@ function initializeVoteScript() {
};
xhr.send();
}
}
}

// Run the function immediately and every 5 seconds
checkVotingStatus();
Expand Down
31 changes: 28 additions & 3 deletions backend/register.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,47 @@
<?php

require_once "./conn/db_connection.php";

header('Content-Type: application/json');

// Form submission handling
$response = ["success" => false, "message" => ""];

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST["username"];
$email = $_POST["email"];
$password = $_POST["password"];

// Basic validation
if (empty($username) || empty($email) || empty($password)) {
$response["message"] = "All fields are required.";
echo json_encode($response);
exit();
}

// Check if username or email already exists
$check_sql = "SELECT * FROM guest_users WHERE username='$username' OR email='$email'";
$check_result = $conn->query($check_sql);

if ($check_result->num_rows > 0) {
// Username or email already exists
$response["message"] = "Username or email already exists. Please choose a different one.";
echo json_encode($response);
exit();
}

// Insert user into the database
$sql = "INSERT INTO guest_users (username, email, password) VALUES ('$username', '$email', '$password')";

if ($conn->query($sql) === TRUE) {
echo "Registration successful!";
$response["success"] = true;
$response["message"] = "Registration successful!";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
$response["message"] = "Error: " . $sql . "<br>" . $conn->error;
}
} else {
$response["message"] = "Invalid request method.";
}

echo json_encode($response);
$conn->close();
?>
Loading

0 comments on commit e777c8e

Please sign in to comment.