notesModel = new NotesModel(); $this->view = $view; } public function showNotes() { # Redirect zum Login wenn kein User eingeloggt ist if(!Isset($_SESSION['role'])) { header("Location: ?controller=User&do=showUserLoginForm"); } $sortBy = $_GET['sort_by'] ?? 'updated_at'; $sortOrder = strtoupper($_GET['sort_order'] ?? 'DESC'); $isAdmin = $_SESSION['role'] === 'admin'; $userid = $_SESSION['user_id']; $this->view->setVars([ "notes" => $this->notesModel->selectNotesForUser($userid, $isAdmin, $sortBy, $sortOrder) ]); } public function showNoteDetails() { $noteId = $_GET['id']; $note = $this->notesModel->getNoteById($noteId); $this->view->setVars([ "note" => $note ]); } public function createNote() { if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Process form submission $note = $this->notesModel->createNote( $_POST['title'], $_POST['content'], $_SESSION['user_id'], $_POST['priority'] ); if ($note) { // Redirect to show notes page after successful creation header('Location: ?controller=Notes&page=showNotes&do=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'], $_POST['priority'] ); if ($note) { // Redirect to show notes page after successful update header('Location: ?controller=Notes&page=showNotes&do=showNotes'); exit(); } else { // If update failed, show error message and stay on the form $this->view->setVars([ 'error' => 'Failed to update note. Please try again.' ]); } } } public function deleteNote() { if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['note_id'])) { $noteId = $_POST['note_id']; $this->notesModel->deleteNote($noteId, $_SESSION['user_id']); } header("Location: ?controller=Notes&page=showNotes&do=showNotes"); exit(); } public function fileManager() { # Redirect zum Login wenn kein User eingeloggt ist if(!Isset($_SESSION['role'])) { header("Location: ?controller=User&do=showUserLoginForm"); } # Redirect zum Welcome wenn kein User kein Admin ist if(!Isset($_SESSION['role']) || $_SESSION['role'] !== 'admin') { header("Location: ?controller=Welcome&do=showWelcome"); } $sortBy = $_GET['sort_by'] ?? 'uploaded_at'; $sortOrder = strtoupper($_GET['sort_order'] ?? 'DESC'); $isAdmin = $_SESSION['role'] === 'admin'; $userid = $_SESSION['user_id']; $files = $this->notesModel->selectFiles($userid, true); $this->view->setVars([ "files" => $files ]); } public function deleteFile() { if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['file_id'])) { $fileId = $_POST['file_id']; $this->notesModel->deleteFile($fileId, $_SESSION['user_id']); } header("Location: ?controller=Notes&do=fileManager"); exit(); } }