Merge branch 'main' of http://git.pb.bib.de/PBBFA23CIV/EIANotesApp
This commit is contained in:
commit
5eb3e30114
@ -52,7 +52,6 @@ class NotesController
|
|||||||
$_POST['content'],
|
$_POST['content'],
|
||||||
$_SESSION['user_id']
|
$_SESSION['user_id']
|
||||||
);
|
);
|
||||||
exit();
|
|
||||||
|
|
||||||
if ($note) {
|
if ($note) {
|
||||||
// Redirect to show notes page after successful creation
|
// Redirect to show notes page after successful creation
|
||||||
@ -89,8 +88,12 @@ class NotesController
|
|||||||
|
|
||||||
public function deleteNote()
|
public function deleteNote()
|
||||||
{
|
{
|
||||||
$noteId = $_GET['id'];
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['note_id'])) {
|
||||||
$this->notesModel->deleteNote($noteId, $_SESSION['user_id']);
|
$noteId = $_POST['note_id'];
|
||||||
header("Location: ?controller=Notes&page=showNotes");
|
$this->notesModel->deleteNote($noteId, $_SESSION['user_id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
header("Location: ?controller=Notes&page=showNotes&do=showNotes");
|
||||||
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,33 +17,5 @@ class WelcomeController
|
|||||||
if ($this->notesModel === null) {
|
if ($this->notesModel === null) {
|
||||||
$this->notesModel = new \ppa\Model\NotesModel();
|
$this->notesModel = new \ppa\Model\NotesModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
||||||
if ($_POST['action'] === 'create_note') {
|
|
||||||
$this->notesModel->createNote(
|
|
||||||
$_POST['title'],
|
|
||||||
$_POST['content'],
|
|
||||||
$_SESSION['user_id']
|
|
||||||
);
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
else if ($_POST['action'] === 'update_note') {
|
|
||||||
$this->notesModel->editNote(
|
|
||||||
$_POST['note_id'],
|
|
||||||
$_POST['title'],
|
|
||||||
$_POST['content'],
|
|
||||||
$_SESSION['user_id']
|
|
||||||
);
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
else if ($_POST['action'] === 'delete_note') {
|
|
||||||
$this->notesModel->deleteNote(
|
|
||||||
$_POST['note_id'],
|
|
||||||
$_SESSION['user_id']
|
|
||||||
);
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
header('Location: ?controller=Notes&page=showNotes&do=showNotes');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
// public/script.js
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
// --- Password Strength Checker for Registration ---
|
// --- Password Strength Checker for Registration ---
|
||||||
const passwordInput = document.getElementById('password');
|
const passwordInput = document.getElementById('password');
|
||||||
@ -58,60 +57,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
if(passwordInput.value) passwordInput.dispatchEvent(new Event('input'));
|
if(passwordInput.value) passwordInput.dispatchEvent(new Event('input'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Delete Note Confirmation and AJAX ---
|
|
||||||
document.querySelectorAll('.delete-note-btn').forEach(button => {
|
|
||||||
button.addEventListener('click', function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
if (confirm('Are you sure you want to delete this note?')) {
|
|
||||||
const noteId = this.dataset.noteId;
|
|
||||||
|
|
||||||
// Create a temporary form to submit for delete
|
|
||||||
const tempForm = document.createElement('form');
|
|
||||||
tempForm.method = 'POST';
|
|
||||||
tempForm.style.display = 'none';
|
|
||||||
|
|
||||||
const actionInput = document.createElement('input');
|
|
||||||
actionInput.type = 'hidden';
|
|
||||||
actionInput.name = 'action';
|
|
||||||
actionInput.value = 'delete_note';
|
|
||||||
tempForm.appendChild(actionInput);
|
|
||||||
|
|
||||||
const noteIdInput = document.createElement('input');
|
|
||||||
noteIdInput.type = 'hidden';
|
|
||||||
noteIdInput.name = 'note_id';
|
|
||||||
noteIdInput.value = noteId;
|
|
||||||
tempForm.appendChild(noteIdInput);
|
|
||||||
|
|
||||||
document.body.appendChild(tempForm); // Form must be in DOM to submit
|
|
||||||
|
|
||||||
// Use handleAjaxForm for consistency
|
|
||||||
const formData = new FormData(tempForm);
|
|
||||||
fetch('?controller=Notes&do=showNotes', {
|
|
||||||
method: 'POST',
|
|
||||||
body: formData
|
|
||||||
})
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
displayMessage(data.message, data.success ? 'success' : 'danger');
|
|
||||||
if (data.success) {
|
|
||||||
// Refresh page or remove row dynamically for better UX
|
|
||||||
// For simplicity, reload. A more advanced way is to find and remove table row.
|
|
||||||
setTimeout(() => { window.location.reload(); }, 1000);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('Error:', error);
|
|
||||||
displayMessage('An error occurred during deletion.', 'danger');
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
document.body.removeChild(tempForm); // Clean up
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// --- Drag and Drop File Upload ---
|
// --- Drag and Drop File Upload ---
|
||||||
// ... (no changes from previous, ensure it's present)
|
|
||||||
const dropZone = document.getElementById('drop-zone');
|
const dropZone = document.getElementById('drop-zone');
|
||||||
const noteTitleInput = document.getElementById('title');
|
const noteTitleInput = document.getElementById('title');
|
||||||
const noteContentInput = document.getElementById('content');
|
const noteContentInput = document.getElementById('content');
|
||||||
|
@ -62,6 +62,8 @@ function sanitize($data, $flags = ENT_QUOTES, $encoding = 'UTF-8') {
|
|||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button type="submit" class="button"><?php echo $isEditMode ? 'Update Note' : 'Create Note'; ?></button>
|
<button type="submit" class="button"><?php echo $isEditMode ? 'Update Note' : 'Create Note'; ?></button>
|
||||||
</div>
|
</div>
|
||||||
|
<input type="hidden" name="controller" value="Notes">
|
||||||
|
<input type="hidden" name="do" value="createNote">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -62,6 +62,8 @@ function sanitize($data, $flags = ENT_QUOTES, $encoding = 'UTF-8') {
|
|||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button type="submit" class="button"><?php echo $isEditMode ? 'Update Note' : 'Create Note'; ?></button>
|
<button type="submit" class="button"><?php echo $isEditMode ? 'Update Note' : 'Create Note'; ?></button>
|
||||||
</div>
|
</div>
|
||||||
|
<input type="hidden" name="controller" value="Notes">
|
||||||
|
<input type="hidden" name="do" value="editNote">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -56,7 +56,12 @@
|
|||||||
<td><?php echo date("d.m.Y H:i", strtotime($note['updated_at'])); ?></td>
|
<td><?php echo date("d.m.Y H:i", strtotime($note['updated_at'])); ?></td>
|
||||||
<td class="actions-cell">
|
<td class="actions-cell">
|
||||||
<a href="?controller=Notes&do=editNote&id=<?php echo $note['id']; ?>" class="button">Edit</a>
|
<a href="?controller=Notes&do=editNote&id=<?php echo $note['id']; ?>" class="button">Edit</a>
|
||||||
<button class="button danger delete-note-btn" data-note-id="<?php echo $note['id']; ?>">Delete</button>
|
<form method="POST" action="?controller=Notes&do=deleteNote" onsubmit="return confirm('Are you sure you want to delete this note?');" style="display: inline;">
|
||||||
|
<input type="hidden" name="note_id" value="<?php echo $note['id']; ?>">
|
||||||
|
<button type="submit" class="button danger">Delete</button>
|
||||||
|
<input type="hidden" name="controller" value="Notes">
|
||||||
|
<input type="hidden" name="do" value="deleteNote">
|
||||||
|
</form>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user