edit and create notes first push
This commit is contained in:
@@ -36,4 +36,54 @@ class NotesController
|
||||
"note" => $note
|
||||
]);
|
||||
}
|
||||
|
||||
public function createNote()
|
||||
{
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// Process form submission
|
||||
$note = $this->notesModel->createNote(
|
||||
$_POST['title'],
|
||||
$_POST['content'],
|
||||
$_SESSION['user_id']
|
||||
);
|
||||
|
||||
if ($note) {
|
||||
// Redirect to show notes page after successful creation
|
||||
header('Location: ?controller=NotesController&page=showNotes');
|
||||
exit();
|
||||
} else {
|
||||
// If creation failed, show error message and stay on the form
|
||||
$this->view->setVars([
|
||||
'error' => 'Failed to create note. Please try again.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function editNote()
|
||||
{
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// Process form submission
|
||||
$noteId = $_GET['id'];
|
||||
$note = $this->notesModel->editNote($noteId, $_POST['title'], $_POST['content'], $_SESSION['user_id']);
|
||||
|
||||
if ($note) {
|
||||
// Redirect to show notes page after successful creation
|
||||
header('Location: ?controller=NotesController&page=showNotes');
|
||||
exit();
|
||||
} else {
|
||||
// If creation failed, show error message and stay on the form
|
||||
$this->view->setVars([
|
||||
'error' => 'Failed to create note. Please try again.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteNote()
|
||||
{
|
||||
$noteId = $_GET['id'];
|
||||
$this->notesModel->deleteNote($noteId, $_SESSION['user_id']);
|
||||
header("Location: ?controller=NotesController&page=showNotes");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user