This commit is contained in:
David Kalemi 2025-06-16 14:26:37 +02:00
commit 97137da6b9
4 changed files with 4 additions and 64 deletions

View File

@ -20,8 +20,8 @@ class NotesController
{
$sortBy = $_GET['sort_by'] ?? 'updated_at';
$sortOrder = strtoupper($_GET['sort_order'] ?? 'DESC');
$isAdmin = false;
$userid = 2; //$_SESSION['user_id'];
$isAdmin = $_SESSION['role'] === 'admin';
$userid = $_SESSION['user_id'];
$this->view->setVars([
"notes" => $this->notesModel->selectNotesForUser($userid, $isAdmin, $sortBy, $sortOrder)

View File

@ -58,12 +58,6 @@ document.addEventListener('DOMContentLoaded', () => {
if(passwordInput.value) passwordInput.dispatchEvent(new Event('input'));
}
// --- AJAX Form Submissions ---
handleAjaxForm('login-form');
handleAjaxForm('register-form');
handleAjaxForm('note-form');
handleAjaxForm('logout-form'); // Added for logout
// --- Delete Note Confirmation and AJAX ---
document.querySelectorAll('.delete-note-btn').forEach(button => {
button.addEventListener('click', function(e) {
@ -188,60 +182,6 @@ document.addEventListener('DOMContentLoaded', () => {
});
}); // End DOMContentLoaded
function handleAjaxForm(formId) { // Removed successRedirectPage, rely on JSON
const form = document.getElementById(formId);
if (form) {
form.addEventListener('submit', function(e) {
e.preventDefault();
const formData = new FormData(form);
const action = formData.get('action'); // Get action from FormData
if (action === 'register') {
const password = formData.get('password');
const confirmPassword = formData.get('confirm_password');
if (password !== confirmPassword) {
displayMessage('Passwords do not match.', 'danger');
return;
}
let criteriaMet = 0;
const criteriaElements = document.querySelectorAll('#password-strength ul li');
criteriaElements.forEach(li => {
if (li.classList.contains('valid')) {
criteriaMet++;
}
});
if (criteriaMet < criteriaElements.length) { // Check if all criteria are met
displayMessage('Password does not meet all requirements.', 'danger');
return;
}
}
fetch('index.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.message) { // Display message if provided
displayMessage(data.message, data.success ? 'success' : 'danger');
}
if (data.success && data.redirect) {
setTimeout(() => { window.location.href = data.redirect; }, data.message ? 1000 : 0); // Delay if message shown
} else if (data.success && (action === 'create_note' || action === 'update_note')) {
// Specific redirect for note actions if not overridden by data.redirect
setTimeout(() => { window.location.href = 'index.php?page=dashboard'; }, data.message ? 1000 : 0);
}
})
.catch(error => {
console.error('Error:', error);
displayMessage('A network error occurred. Please try again.', 'danger');
});
});
}
}
function displayMessage(message, type = 'info') {
const existingAlert = document.querySelector('#alert-container .alert');
if (existingAlert) {

View File

@ -1,5 +1,4 @@
<?php include dirname(__DIR__).'/header.phtml'; ?>
<script src="JavaScript/script.js"></script>
<?php include dirname(__DIR__).'/header.phtml'; ?>
<h2>Notes</h2>

View File

@ -5,6 +5,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width">
<link href="CSS/style.css" rel="stylesheet" type="text/css" />
<script src="JavaScript/script.js"></script>
</head>
<body>
<header>