From d7c2e638a5ea39caeadd40406f840e9b90f893d5 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 2 Feb 2025 15:04:59 +0200 Subject: feat(views/archive): Implement archive deletion --- controllers/archive.php | 34 ++++++++++++++++++++++++++++++++++ migrations/00-initial.sql | 4 +++- models/webpage.php | 7 +++++++ views/archive/delete/index.php | 34 ++++++++++++++++++++++++++++++++++ views/archive/delete/meta.php | 4 ++++ views/archive/index.php | 3 +++ views/archive/item.php | 14 ++++++++++++-- views/global/router.php | 1 + views/list/index.php | 2 ++ views/styles.css | 3 +++ 10 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 views/archive/delete/index.php create mode 100644 views/archive/delete/meta.php diff --git a/controllers/archive.php b/controllers/archive.php index fd278ff..367acc7 100644 --- a/controllers/archive.php +++ b/controllers/archive.php @@ -23,6 +23,40 @@ function on_post() { exit(); } +function on_delete() { + global $TOKEN; + global $METHOD; + global $page_status; + + $webpage = null; + try { + $webpage = Database\Webpage::fromDBwid($METHOD['wid']); + } + catch(Exception $e) { + $page_status = "This webpage doesn't exist!"; + return; + } + + $user = null; + try { + $user = Database\Cookie::fromDB($TOKEN); + } + catch(Exception $e) { + $list_status = "Invalid cookie!"; + return; + } + + if ($user->Role !== 'Admin') { + $list_status = "You're not authorized to delete archives!"; + return; + } + + $webpage->delete(); + + header('Location: /archive/?url=' . $webpage->URL); + exit(); +} + class DownloadPage { private $folder_location; private $folder_name; diff --git a/migrations/00-initial.sql b/migrations/00-initial.sql index a4b999f..776331f 100644 --- a/migrations/00-initial.sql +++ b/migrations/00-initial.sql @@ -44,5 +44,7 @@ CREATE TABLE IF NOT EXISTS ArchiveListsWebpages ( WID INT NOT NULL, LID INT NOT NULL, Position INT NOT NULL, - PRIMARY KEY (WID, LID) + PRIMARY KEY (WID, LID), + FOREIGN KEY (WID) REFERENCES Webpages(WID) ON DELETE CASCADE, + FOREIGN KEY (LID) REFERENCES ArchiveLists(LID) ON DELETE CASCADE ); diff --git a/models/webpage.php b/models/webpage.php index e85046f..2bcc265 100644 --- a/models/webpage.php +++ b/models/webpage.php @@ -107,4 +107,11 @@ class Webpage extends Table { "WID = \"{$this->WID}\"" ); } + + function delete() { + Table::_delete( + 'Webpages', + "WID = \"$this->WID\"" + ); + } } diff --git a/views/archive/delete/index.php b/views/archive/delete/index.php new file mode 100644 index 0000000..daad152 --- /dev/null +++ b/views/archive/delete/index.php @@ -0,0 +1,34 @@ + + +Role === 'Admin'): ?> +

Are you sure you want to delete URL ?> from Date ?>?

+ +
+ + + +

+ Error: +

+ + + + + +
+ + +

No page with identifier exists!

+ + +

You have no permission to delete archives!

+ + diff --git a/views/archive/delete/meta.php b/views/archive/delete/meta.php new file mode 100644 index 0000000..b9dc330 --- /dev/null +++ b/views/archive/delete/meta.php @@ -0,0 +1,4 @@ +incrementVisits(); + + $user = Database\Cookie::fromDB($TOKEN); } catch(Exception $e) { } diff --git a/views/archive/item.php b/views/archive/item.php index e6b9cf0..467fb2c 100644 --- a/views/archive/item.php +++ b/views/archive/item.php @@ -15,9 +15,19 @@ - + Role === 'Admin'): ?> +
+ + +
+ + + diff --git a/views/global/router.php b/views/global/router.php index c6718a7..5b0bd01 100644 --- a/views/global/router.php +++ b/views/global/router.php @@ -33,6 +33,7 @@ function route_view() { case '/list/delete': return '/list/delete'; case '/archive/create': return '/archive/create'; + case '/archive/delete': return '/archive/delete'; case '/user/delete': return '/user/delete'; case '/user/settings': return '/user/update'; diff --git a/views/list/index.php b/views/list/index.php index d422630..759ab04 100644 --- a/views/list/index.php +++ b/views/list/index.php @@ -1,10 +1,12 @@ AuthorUID); + $user = Database\Cookie::fromDB($TOKEN); } catch(Exception $e) {} ?> diff --git a/views/styles.css b/views/styles.css index 132d280..260f7ff 100644 --- a/views/styles.css +++ b/views/styles.css @@ -334,10 +334,12 @@ hr.new-section { padding: 0.5em 0 0.5em 0.5em; display: flex; flex-direction: column; + gap: 0.3em; } .item [name=itemButton] > * { display: flex; + align-items: end; flex: 1; } @@ -349,6 +351,7 @@ hr.new-section { .list-icon { color: var(--cherry); + height: 1.3em; } /* List item */ -- cgit v1.2.3