diff --git a/css/master.css b/css/master.css index 2444d69..3655a84 100644 --- a/css/master.css +++ b/css/master.css @@ -42,6 +42,8 @@ html { background-attachment: fixed; scroll-behavior: smooth; + + overflow: auto; } body { margin: 0 auto; padding: 1rem; diff --git a/image.php b/image.php index 1fec0c1..79c8365 100644 --- a/image.php +++ b/image.php @@ -14,13 +14,20 @@ include("ui/header.php"); include_once("ui/conn.php"); - // Update toast + // Include flyout for extra actions + include("ui/flyout.php"); + + /* + If theres a success in updating the image, + it'll let the user know + */ if ($_GET["update"] == "success") { echo "

Information updated

"; } elseif ($_GET["update"] == "skip") { echo "

No alt, skip

"; } + // If ID present pull all image data if (isset($_GET['id'])) { $get_image = "SELECT * FROM swag_table WHERE id = ".$_GET['id']; @@ -49,12 +56,83 @@ $image_alt = "No image could be found, sowwy"; } + // Get all user details if (isset($image['author'])) { $get_user = "SELECT * FROM users WHERE id = ".$image['author']; $user_results = mysqli_query($conn, $get_user); $user = mysqli_fetch_assoc($user_results); - } else + } + + + /* + Check if the user is an admin session id = 1 + Or the owner of the image, image author == session id + + This may not be the best system of doing this, but much better than not having it at all + I plan on adding an array of privilaged users that user with the id of 1 can modify, + sort of like a mod/admin list of users + */ + if (isset($_SESSION['id']) && $image['author'] == $_SESSION['id'] || $_SESSION['id'] == 1) { + $privilaged = True; + } else { + $privilaged = False; + } + + + /* + Delete flyout + + This goes with the confirm script below, to use flyout, you must include the js script and php function + */ + if (isset($_POST['delete_flyout']) && $privilaged) { + $header = "Are you sure?"; + $content = "Deleting this image is pernament, there is no going back after this!!!!!"; + $action = "
+ +
"; + + flyout($header, $content, $action); + } + /* + Confirm deleting user + + user must be privilaged to do this action this the privilaged == true + */ + if (isset($_POST['delete_confirm']) && $privilaged) { + // Unset all the variables, needed by flyout + unset($header, $content, $action); + + // Delete from table + $image_delete_request = "DELETE FROM swag_table WHERE id =".$image['id']; + $image_delete = mysqli_query($conn,$image_delete_request); + + if ($image_delete) { + // See if image is in the directory + if (is_file("images/".$image['imagename'])) { + unlink("images/".$image['imagename']); + } + // Delete thumbnail if exitsts + if (is_file("images/thumbnails/".$image['imagename'])) { + unlink("images/thumbnails/".$image['imagename']); + } + header("Location:index.php?del=true&id=".$image['id']); + } else { + $error = "Could not delete image"; + } + } + + + /* + Test flyout button + */ + if (isset($_POST['test_flyout'])) { + $header = "Sus"; + $content = "This is a test UwU. You are currently viewing image: ".$_GET['id']; + $action = "This button does nothing! I'm another button, but scawwy"; + + flyout($header, $content, $action); + } ?>
@@ -108,8 +186,9 @@ // Flyout test button ?> - - +
+ +
@@ -135,58 +214,25 @@

Danger zone

"; - // Delete button - ?> + // Delete Button + echo "
+ +
"; - - "; - ?> ">Delete image - - Modify image content"; echo "
"; } ?> - - "; include("ui/top.html"); include("ui/footer.php"); diff --git a/scripts/flyout.js b/scripts/flyout.js index 001c83a..2519df4 100644 --- a/scripts/flyout.js +++ b/scripts/flyout.js @@ -1,20 +1,14 @@ let show = document.querySelectorAll(".flyout-display"); let hide = document.querySelector(".flyout-close"); -show.forEach((pain) => { - pain.addEventListener("click", function(){ - document.querySelector("html").style.overflow= "hidden"; - - document.querySelector(".flyout").style.transform= "translateX(-50%) scale(1)"; - document.querySelector(".flyout").style.bottom= "-1rem"; - document.querySelector(".flyout-dim").style.display= "block"; - }); +show.forEach(function(){ + document.querySelector(".flyout").style.transform= "translateX(-50%) scale(1)"; + document.querySelector(".flyout").style.bottom= "-1rem"; + document.querySelector(".flyout-dim").style.display= "block"; }); hide.addEventListener("click", function(){ - document.querySelector("html").style.overflow= "auto"; - document.querySelector(".flyout").style.transform= "translateX(-50%) scale(0.8)"; document.querySelector(".flyout").style.bottom= "-20rem"; document.querySelector(".flyout-dim").style.display= "none"; diff --git a/ui/flyout.php b/ui/flyout.php index 5221d04..1042b74 100644 --- a/ui/flyout.php +++ b/ui/flyout.php @@ -1,26 +1,25 @@ -
-
-
-
"; + // Div Start + echo "
"; + // Header for the flyout, must be included if (isset($flyout_header) && !empty($flyout_header)) { echo "

".$flyout_header."

"; - } else { - echo "

Missing Header

"; } - // Flyout content, must be included!!!! if (isset($flyout_content) && !empty($flyout_content)) { echo "

".$flyout_content."

"; - } else { - echo "

This is just being tested as a better alternative to some things, sowwy!

"; + } + // Flyout button, not required so must need more information when added + if (isset($flyout_action) && !empty($flyout_action)) { + echo $flyout_action; } - // Flyout button, not required so must need more information when added - if (isset($flyout_interaction) && !empty($flyout_interaction)) { - echo $flyout_interaction; - } - ?> - Cancel -
- + // Exit button + Div End + echo " + "; +} +?>