From 4bebfa04cf759d77c511541bdf30747c76a3b2e1 Mon Sep 17 00:00:00 2001
From: Syndamia
Date: Sun, 2 Feb 2025 10:54:23 +0200
Subject: feat(views/list): Fully implement list updating
---
controllers/list.php | 33 ++++++++++++++++++++++++++++++++
models/archivelist.php | 8 ++++++++
views/list/index.php | 17 +++++++++++++++++
views/list/update/index.php | 46 +++++++++++++++++++++++++++++++++++++++++++++
views/list/update/meta.php | 4 ++++
views/styles.css | 8 ++++++++
6 files changed, 116 insertions(+)
create mode 100644 views/list/update/index.php
create mode 100644 views/list/update/meta.php
diff --git a/controllers/list.php b/controllers/list.php
index 0561700..07db6c5 100644
--- a/controllers/list.php
+++ b/controllers/list.php
@@ -47,3 +47,36 @@ function on_patch() {
header('Location: /list/' . $list->LID);
exit();
}
+
+function on_put() {
+ global $TOKEN;
+ global $METHOD;
+ global $list_status;
+
+ $list = null;
+ try {
+ $list = Database\ArchiveList::fromDB($METHOD['lid']);
+ }
+ catch(Exception $e) {
+ $list_status = "This list doesn't exist!";
+ return;
+ }
+
+ try {
+ $user = Database\Cookie::fromDB($TOKEN);
+ $author = Database\User::fromDBuid($list->AuthorUID);
+ if ($author->UID !== $user->UID) {
+ $list_status = "You're not the owner of this list! You have no permission to edit it!";
+ return;
+ }
+ }
+ catch(Exception $e) {
+ $list_status = "Either your cookie is invalid or the author of this list has deleted their account!";
+ return;
+ }
+
+ $list->update($METHOD['name'], $METHOD['description']);
+
+ header('Location: /list/' . $list->LID);
+ exit();
+}
diff --git a/models/archivelist.php b/models/archivelist.php
index 779365e..bf734e0 100644
--- a/models/archivelist.php
+++ b/models/archivelist.php
@@ -41,4 +41,12 @@ class ArchiveList extends Table {
'Webpages.*'
);
}
+
+ function update(string $newName, string $newDescription) {
+ Table::_update(
+ 'ArchiveLists',
+ "Name = \"$newName\", Description = \"$newDescription\"",
+ "LID = \"$this->LID\""
+ );
+ }
}
diff --git a/views/list/index.php b/views/list/index.php
index 9b49268..4a84f78 100644
--- a/views/list/index.php
+++ b/views/list/index.php
@@ -18,6 +18,23 @@
= $author->Username ?>
= $list->Description ?>
+
+
+
AuthorUID);
+ $user = Database\Cookie::fromDB($TOKEN);
+ }
+ catch(Exception $e) {}
+?>
+
+UID === $author->UID): ?>
+
+Update list
+
+
+
+
+ No list with identifier = $_GET['lid'] ?> exists!
+
+
+ You're not the owner of "= $list->Name ?>", you have no permission to edit it!
+
+
diff --git a/views/list/update/meta.php b/views/list/update/meta.php
new file mode 100644
index 0000000..c3a9f3c
--- /dev/null
+++ b/views/list/update/meta.php
@@ -0,0 +1,4 @@
+