This repository has been archived by the owner on Jan 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
431 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"apiKey": "AIzaSyAvNlB1-cygF8C6XWpPN9K0eryqg61I2Ps" | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,6 +124,7 @@ function toggleSidebar() { | |
$('.sidebar').toggleClass('active'); | ||
} | ||
</script> | ||
|
||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
?> |
Oops, something went wrong.