mirror of
https://github.com/Fluffy-Bean/image-gallery.git
synced 2025-05-29 23:03:12 +00:00
Cleaned up code on image details screen
This commit is contained in:
parent
bca209708b
commit
d9537446b3
1 changed files with 39 additions and 41 deletions
80
image.php
80
image.php
|
@ -14,7 +14,6 @@
|
||||||
include("ui/header.php");
|
include("ui/header.php");
|
||||||
include_once("ui/conn.php");
|
include_once("ui/conn.php");
|
||||||
|
|
||||||
|
|
||||||
// Update toast
|
// Update toast
|
||||||
if ($_GET["update"] == "success") {
|
if ($_GET["update"] == "success") {
|
||||||
echo "<p class='alert alert-high space-bottom-large'>Information updated</p>";
|
echo "<p class='alert alert-high space-bottom-large'>Information updated</p>";
|
||||||
|
@ -22,61 +21,57 @@
|
||||||
echo "<p class='alert alert-default space-bottom-large'>No alt, skip</p>";
|
echo "<p class='alert alert-default space-bottom-large'>No alt, skip</p>";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getting all image info from table
|
// If ID present pull all image data
|
||||||
$get_image = "SELECT * FROM swag_table WHERE id = ".$_GET['id'];
|
if (isset($_GET['id'])) {
|
||||||
$image_results = mysqli_query($conn, $get_image);
|
$get_image = "SELECT * FROM swag_table WHERE id = ".$_GET['id'];
|
||||||
$image = mysqli_fetch_assoc($image_results);
|
$image_results = mysqli_query($conn, $get_image);
|
||||||
|
$image = mysqli_fetch_assoc($image_results);
|
||||||
|
|
||||||
// Get all user details
|
// Check if image is avalible
|
||||||
if (isset($image['author'])) {
|
if (isset($image['imagename'])) {
|
||||||
$get_user = "SELECT * FROM users WHERE id = ".$image['author'];
|
// Display image
|
||||||
$user_results = mysqli_query($conn, $get_user);
|
$image_path = "images/".$image['imagename'];
|
||||||
$user = mysqli_fetch_assoc($user_results);
|
$image_alt = $image['alt'];
|
||||||
}
|
} else {
|
||||||
|
// ID not avalible toast
|
||||||
|
echo "<p class='alert alert-low space-bottom-large'>Could not find image with ID: ".$_GET['id']."</p>";
|
||||||
|
|
||||||
// Check if ID of image in URL
|
// Replacement "no image" image and description
|
||||||
if (empty($_GET['id'])) {
|
$image_path = "assets/no_image.png";
|
||||||
|
$image_alt = "No image could be found, sowwy";
|
||||||
|
}
|
||||||
|
} 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";
|
||||||
|
|
||||||
} elseif (empty($image['imagename'])) {
|
|
||||||
// ID not avalible toast
|
|
||||||
echo "<p class='alert alert-low space-bottom-large'>Could not find image with ID: ".$_GET['id']."</p>";
|
|
||||||
|
|
||||||
// Replacement "no image" image and description
|
|
||||||
$image_path = "assets/no_image.png";
|
|
||||||
$image_alt = "No image could be found, sowwy";
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// Display image
|
|
||||||
$image_path = "images/".$image['imagename'];
|
|
||||||
$image_alt = $image['alt'];
|
|
||||||
|
|
||||||
// Add image view
|
|
||||||
if (empty($image['views'])) {
|
|
||||||
//$conn->query("UPDATE swag_table SET views=1 WHERE id=".$image['id']);
|
|
||||||
} else {
|
|
||||||
//$conn->query("UPDATE swag_table SET views=views+1 WHERE id=".$image['id']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="image-container">
|
<div class="image-container">
|
||||||
<?php echo "<img class='image' id='".$image['id']."' src='".$image_path."' alt='".$image_alt."'>"; ?>
|
<?php
|
||||||
|
// Displaying image
|
||||||
|
echo "<img class='image' id='".$image['id']."' src='".$image_path."' alt='".$image_alt."'>";
|
||||||
|
?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="image-description default-window">
|
<div class="image-description default-window">
|
||||||
<h2>Description</h2>
|
<h2>Description</h2>
|
||||||
<?php
|
<?php
|
||||||
// Image Description/Alt
|
// Image Description/Alt
|
||||||
if (empty($image_alt)) {
|
if (isset($image_alt)) {
|
||||||
echo "<p>No description provided</p>";
|
|
||||||
}else{
|
|
||||||
echo "<p>".$image_alt."</p>";
|
echo "<p>".$image_alt."</p>";
|
||||||
|
} else {
|
||||||
|
echo "<p>No description provided</p>";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
|
@ -86,14 +81,15 @@
|
||||||
<?php
|
<?php
|
||||||
// Image ID
|
// Image ID
|
||||||
if (isset($image['author'])) {
|
if (isset($image['author'])) {
|
||||||
echo "<p>Author: ".$user['username']."</p>";
|
if (isset($user['username'])) {
|
||||||
|
echo "<p>Author: ".$user['username']."</p>";
|
||||||
|
} else {
|
||||||
|
echo "<p>Author: Deleted User</p>";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
echo "<p>Author: No author</p>";
|
echo "<p>Author: No author</p>";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Views
|
|
||||||
//echo "<p>Views: ".$image['views']."</p>";
|
|
||||||
|
|
||||||
// Image ID
|
// Image ID
|
||||||
echo "<p>ID: ".$image['id']."</p>";
|
echo "<p>ID: ".$image['id']."</p>";
|
||||||
|
|
||||||
|
@ -113,6 +109,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
// Check if user is admin or the owner of image, if yes, display the edit and delete div
|
||||||
if (isset($_SESSION['id']) && $image['author'] == $_SESSION['id'] || $_SESSION['id'] == 1) {
|
if (isset($_SESSION['id']) && $image['author'] == $_SESSION['id'] || $_SESSION['id'] == 1) {
|
||||||
// Deleting image
|
// Deleting image
|
||||||
if (isset($_POST['delete'])) {
|
if (isset($_POST['delete'])) {
|
||||||
|
@ -137,6 +134,7 @@
|
||||||
// Delete form
|
// Delete form
|
||||||
echo "<div class='danger-zone flex-down default-window'>";
|
echo "<div class='danger-zone flex-down default-window'>";
|
||||||
echo "<h2>Danger zone</h2>";
|
echo "<h2>Danger zone</h2>";
|
||||||
|
|
||||||
// Image hover details
|
// Image hover details
|
||||||
echo "<form class='detail' method='POST' enctype='multipart/form-data'>";
|
echo "<form class='detail' method='POST' enctype='multipart/form-data'>";
|
||||||
echo "<button class='btn alert-low' type='submit' name='delete' value='".$image['id']."'><img class='svg' src='assets/icons/trash.svg'>Delete image</button>";
|
echo "<button class='btn alert-low' type='submit' name='delete' value='".$image['id']."'><img class='svg' src='assets/icons/trash.svg'>Delete image</button>";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue