diff --git a/.gitmodules b/.gitmodules index 7cba5c4..58b232e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "static/css/material-color"] path = static/css/material-color url = https://source.netsyms.com/Netsyms/Material-Color +[submodule "static/easy-markdown-editor"] + path = static/easy-markdown-editor + url = https://source.netsyms.com/Netsyms/easy-markdown-editor.git diff --git a/action.php b/action.php index d1ea966..f5d196e 100644 --- a/action.php +++ b/action.php @@ -7,7 +7,6 @@ /** * Make things happen when buttons are pressed and forms submitted. */ - require_once __DIR__ . "/required.php"; if ($VARS['action'] !== "signout") { @@ -35,4 +34,27 @@ switch ($VARS['action']) { session_destroy(); header('Location: index.php'); die("Logged out."); + case "savenote": + if (empty($VARS['content']) || empty($VARS['noteid'])) { + die($Strings->get("invalid parameters")); + } + http_response_code(204); + $note = Note::loadNote($VARS['noteid']); + if ($note->getOwnerID() != $_SESSION['uid']) { + die($Strings->get("invalid parameters")); + } + $note->setText($VARS['content']); + $note->setColor($VARS['color']); + $note->saveNote(); + break; + case "deletenote": + if (empty($VARS['noteid'])) { + die($Strings->get("invalid parameters")); + } + $note = Note::loadNote($VARS['noteid']); + if ($note->getOwnerID() != $_SESSION['uid']) { + die($Strings->get("invalid parameters")); + } + $note->deleteNote(); + returnToSender("note_deleted"); } \ No newline at end of file diff --git a/langs/en/notes.json b/langs/en/notes.json index 37bf50d..3596c26 100644 --- a/langs/en/notes.json +++ b/langs/en/notes.json @@ -1,5 +1,8 @@ { "New": "New", + "New note": "New note", "Note": "Note", - "Edit": "Edit" + "Edit": "Edit", + "Delete": "Delete", + "Note deleted": "Note deleted" } diff --git a/langs/messages.php b/langs/messages.php index 0744629..3b904e3 100644 --- a/langs/messages.php +++ b/langs/messages.php @@ -16,5 +16,9 @@ define("MESSAGES", [ "404_error" => [ "string" => "page not found", "type" => "info" + ], + "note_deleted" => [ + "string" => "Note deleted", + "type" => "success" ] ]); diff --git a/lib/Note.lib.php b/lib/Note.lib.php index 6f943ee..410e6d2 100644 --- a/lib/Note.lib.php +++ b/lib/Note.lib.php @@ -73,11 +73,22 @@ class Note { if ($saveas) { $database->insert('notes', $data); - return $database->id(); + $this->noteid = $database->id(); } else { $database->update('notes', $data, ['noteid' => $this->noteid]); - return $this->noteid; } + + return $this->noteid; + } + + /** + * Delete this note from the database. + * @global type $database + */ + public function deleteNote() { + global $database; + + $database->delete('notes', ['noteid' => $this->noteid]); } /** diff --git a/pages.php b/pages.php index a8a466a..6419dca 100644 --- a/pages.php +++ b/pages.php @@ -13,5 +13,16 @@ define("PAGES", [ ], "404" => [ "title" => "404 error" + ], + "editnote" => [ + "title" => "Edit Note", + "styles" => [ + "static/easy-markdown-editor/dist/easymde.min.css", + "static/css/editnote.css" + ], + "scripts" => [ + "static/easy-markdown-editor/dist/easymde.min.js", + "static/js/editnote.js" + ] ] ]); \ No newline at end of file diff --git a/pages/editnote.php b/pages/editnote.php new file mode 100644 index 0000000..d3f5150 --- /dev/null +++ b/pages/editnote.php @@ -0,0 +1,34 @@ +getOwnerID() != $_SESSION['uid']) { + header("Location: app.php?msg=no_permission"); + die(); +} + +$note->saveNote(); + +?> + +
\ No newline at end of file diff --git a/pages/home.php b/pages/home.php index 9d8cfcc..64bad31 100644 --- a/pages/home.php +++ b/pages/home.php @@ -16,13 +16,17 @@ foreach ($noteids as $n) { getID() . " {\n" - . " background-color: #" . $note->getColor() . ";\n" - . " border: 1px solid #" . $note->getColor() . ";\n" - . "}\n"; + . " background-color: #" . $note->getColor() . ";\n" + . " border: 1px solid #" . $note->getColor() . ";\n" + . "}\n"; } ?> + +