Fixed minor errors and added author editing

This commit is contained in:
Michał Gdula 2022-07-30 13:40:30 +01:00
parent cc9c9ecc79
commit 8299b2e5c0
2 changed files with 155 additions and 50 deletions

187
image.php
View file

@ -1,35 +1,20 @@
<!DOCTYPE html> <?php
<html> /*
<head> Why are you putting all the image checking up here?
<meta charset="utf-8"> Wasn't it fine below the header????
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gallery</title>
<link rel="stylesheet" href="css/master.css">
<link href="https://fonts.googleapis.com/css2?family=Rubik" rel="stylesheet">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Lexend+Deca:wght@600&amp;display=swap">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@500&amp;display=swap">
</head>
<body>
<?php
include("ui/header.php");
include_once("ui/conn.php");
// Include flyout for extra actions The reason why all this is up here, is so link previews can generate correctly in the header
include("ui/flyout.php"); I would rather it all not be up here, but due to variables not being able to be set after already being mentioned
(at least to my knowlage)
/* I am forced to put ALLL of this up here :c
If theres a success in updating the image, */
it'll let the user know
*/
if ($_GET["update"] == "success") {
echo "<p class='alert alert-high space-bottom-large'>Information updated</p>";
} elseif ($_GET["update"] == "skip") {
echo "<p class='alert alert-default space-bottom-large'>No alt, skip</p>";
}
// If ID present pull all image data include_once("ui/conn.php");
if (isset($_GET['id'])) {
// If ID present pull all image data
if (isset($_GET['id'])) {
$get_image = "SELECT * FROM swag_table WHERE id = ".$_GET['id']; $get_image = "SELECT * FROM swag_table WHERE id = ".$_GET['id'];
$image_results = mysqli_query($conn, $get_image); $image_results = mysqli_query($conn, $get_image);
$image = mysqli_fetch_assoc($image_results); $image = mysqli_fetch_assoc($image_results);
@ -47,21 +32,52 @@
$image_path = "assets/no_image.png"; $image_path = "assets/no_image.png";
$image_alt = "No image could be found, sowwy"; $image_alt = "No image could be found, sowwy";
} }
} else { } else {
// No ID toast // No ID toast
echo "<p class='alert alert-low space-bottom-large'>No ID present</p>"; echo "<p class='alert alert-low space-bottom-large'>No ID present</p>";
// Replacement "no image" image and description // Replacement "no image" image and description
$image_path = "assets/no_image.png"; $image_path = "assets/no_image.png";
$image_alt = "No image could be found, sowwy"; $image_alt = "No image could be found, sowwy";
} }
// Get all user details // Get all user details
if (isset($image['author'])) { if (isset($image['author'])) {
$get_user = "SELECT * FROM users WHERE id = ".$image['author']; $get_user = "SELECT * FROM users WHERE id = ".$image['author'];
$user_results = mysqli_query($conn, $get_user); $user_results = mysqli_query($conn, $get_user);
$user = mysqli_fetch_assoc($user_results); $user = mysqli_fetch_assoc($user_results);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gallery</title>
<link rel="stylesheet" href="css/master.css">
<link href="https://fonts.googleapis.com/css2?family=Rubik" rel="stylesheet">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Lexend+Deca:wght@600&amp;display=swap">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@500&amp;display=swap">
<?php echo "<meta property='og:image' content='https://superdupersecteteuploadtest.fluffybean.gay/".$image_path."'/>"; ?>
<?php echo "<meta itemprop='image' content='https://superdupersecteteuploadtest.fluffybean.gay/".$image_path."'/>"; ?>
</head>
<body>
<?php
include("ui/header.php");
// 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 "<p class='alert alert-high space-bottom-large'>Information updated</p>";
} elseif ($_GET["update"] == "error") {
echo "<p class='alert alert-default space-bottom-large'>Something went fuckywucky, please try later</p>";
} }
@ -80,6 +96,17 @@
} }
/*
Test flyout button
*/
if (isset($_POST['test_flyout'])) {
$header = "Sus";
$content = "This is a test UwU. You are currently viewing image: ".$_GET['id'];
$action = "<a class='btn alert-high'>This button does nothing!</a> <a class='btn alert-low space-top-small'>I'm another button, but scawwy</a>";
flyout($header, $content, $action);
}
/* /*
Delete flyout Delete flyout
@ -122,17 +149,85 @@
} }
} }
/* /*
Test flyout button Description edit
*/ */
if (isset($_POST['test_flyout'])) { if (isset($_POST['description_flyout']) && $privilaged) {
$header = "Sus"; $header = "Enter new Description/Alt";
$content = "This is a test UwU. You are currently viewing image: ".$_GET['id']; $content = "Whatcha gonna put in there 👀";
$action = "<a class='btn alert-high'>This button does nothing!</a> <a class='btn alert-low space-top-small'>I'm another button, but scawwy</a>"; $action = "<form class='flex-down between' method='POST' enctype='multipart/form-data'>
<input class='btn alert-default space-bottom' type='text' name='update_alt' placeholder='Description/Alt for image'>
<button class='btn alert-low' type='submit' name='description_confirm' value='".$image["id"]."'><img class='svg' src='assets/icons/edit.svg'>Update information</button>
</form>";
flyout($header, $content, $action); flyout($header, $content, $action);
} }
/*
Description confirm
*/
if (isset($_POST['description_confirm']) && $privilaged) {
// Unset all the variables, needed by flyout
unset($header, $content, $action);
// getting ready forSQL asky asky
$sql = "UPDATE swag_table SET alt=? WHERE id=?";
// Checking if databse is doing ok
if ($stmt = mysqli_prepare($conn, $sql)) {
mysqli_stmt_bind_param($stmt, "si", $param_alt, $param_id);
// Setting parameters
$param_alt = $_POST['update_alt'];
$param_id = $image["id"];
// Attempt to execute the prepared statement
if (mysqli_stmt_execute($stmt)) {
header("Location:https://superdupersecteteuploadtest.fluffybean.gay/image.php?id=".$image["id"]."&update=success");
} else {
header("Location:https://superdupersecteteuploadtest.fluffybean.gay/image.php?id=".$image["id"]."&update=error");
}
}
}
/*
Description athor
*/
if (isset($_POST['author_flyout']) && $_SESSION['id'] == 1) {
$header = "Who owns the image?????";
$content = "Enter ID of image owner";
$action = "<form class='flex-down between' method='POST' enctype='multipart/form-data'>
<input class='btn alert-default space-bottom' type='text' name='update_author' placeholder='New user ID'>
<button class='btn alert-low' type='submit' name='author_confirm' value='".$image["id"]."'><img class='svg' src='assets/icons/edit.svg'>Update information</button>
</form>";
flyout($header, $content, $action);
}
/*
Author confirm
*/
if (isset($_POST['author_confirm']) && $_SESSION['id'] == 1) {
// Unset all the variables, needed by flyout
unset($header, $content, $action);
// getting ready forSQL asky asky
$sql = "UPDATE swag_table SET author=? WHERE id=?";
// Checking if databse is doing ok
if ($stmt = mysqli_prepare($conn, $sql)) {
mysqli_stmt_bind_param($stmt, "si", $param_author, $param_id);
// Setting parameters
$param_author = $_POST['update_author'];
$param_id = $image["id"];
// Attempt to execute the prepared statement
if (mysqli_stmt_execute($stmt)) {
header("Location:https://superdupersecteteuploadtest.fluffybean.gay/image.php?id=".$image["id"]."&update=success");
} else {
header("Location:https://superdupersecteteuploadtest.fluffybean.gay/image.php?id=".$image["id"]."&update=error");
}
}
}
?> ?>
<div class="image-container"> <div class="image-container">
@ -219,13 +314,21 @@
echo "<div class='danger-zone flex-down default-window'> echo "<div class='danger-zone flex-down default-window'>
<h2>Danger zone</h2>"; <h2>Danger zone</h2>";
// Delete Button // Delete
echo "<form method='POST'> echo "<form method='POST'>
<button class='btn alert-low space-top flyout-display' type='submit' name='delete_flyout'><img class='svg' src='assets/icons/trash.svg'>Delete image</button> <button class='btn alert-low flyout-display' type='submit' name='delete_flyout'><img class='svg' src='assets/icons/trash.svg'>Delete image</button>
</form>";
// Edit description
echo "<form method='POST'>
<button class='btn alert-low space-top-small flyout-display' type='submit' name='description_flyout'><img class='svg' src='assets/icons/edit.svg'>Edit description</button>
</form>";
// Edit authro
echo "<form method='POST'>
<button class='btn alert-low space-top-small flyout-display' type='submit' name='author_flyout'><img class='svg' src='assets/icons/edit.svg'>Edit author</button>
</form>"; </form>";
// Edit image button
echo "<a class='btn alert-low space-top-small' href='https://superdupersecteteuploadtest.fluffybean.gay/edit.php?id=".$image['id']."'><img class='svg' src='assets/icons/edit.svg'>Modify image content</a>";
echo "</div>"; echo "</div>";
} }
?> ?>

View file

@ -1,3 +1,5 @@
console.log(" . . /|/| . . . . . . . \n .. /0 0 \\ . . . . . .. \n (III% . \\________, . . \n .. .\\_, .%###%/ \\'\\,.. \n . . . .||#####| |'\\ \\. \n .. . . ||. . .|/. .\\V. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . cc/ . .cc/ . . .")
let show = document.querySelectorAll(".flyout-display"); let show = document.querySelectorAll(".flyout-display");
let hide = document.querySelector(".flyout-close"); let hide = document.querySelector(".flyout-close");