mirror of
https://github.com/Fluffy-Bean/image-gallery.git
synced 2024-12-29 10:56:12 +00:00
Getting buttons working, not functional yet bruh
This commit is contained in:
parent
21152358f1
commit
6a60375904
0
app/image/delete_image.php
Normal file
0
app/image/delete_image.php
Normal file
0
app/image/edit_author.php
Normal file
0
app/image/edit_author.php
Normal file
76
app/image/edit_description.php
Normal file
76
app/image/edit_description.php
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
/*
|
||||
|-------------------------------------------------------------
|
||||
| Check if user has edit permitions
|
||||
|-------------------------------------------------------------
|
||||
| This is repetetive, but I'm worried people will find a way
|
||||
| around the front-end protection (if any), so best to do a
|
||||
| second check.
|
||||
|
|
||||
| I also want to add that this is probably a very long and
|
||||
| poor way of doing the check, so I'm sorry for anyone who has
|
||||
| the unfortunate task of reading this code.
|
||||
|-------------------------------------------------------------
|
||||
*/
|
||||
$conn_ip = "localhost";
|
||||
$conn_username = "uwu";
|
||||
$conn_password = "fennec621";
|
||||
$conn_database = "swag";
|
||||
|
||||
$conn = mysqli_connect($conn_ip, $conn_username, $conn_password , $conn_database);
|
||||
if ($conn->connect_error) {
|
||||
// Send notification that connection couldn't be made
|
||||
}
|
||||
function image_privilage($id) {
|
||||
$session_id = $_SESSION['id'];
|
||||
if (isset($session_id) || !empty($session_id)) {
|
||||
if ($session_id == $id) {
|
||||
return True;
|
||||
} else {
|
||||
return False;
|
||||
}
|
||||
} else {
|
||||
return False;
|
||||
}
|
||||
}
|
||||
function get_image_info($conn, $id) {
|
||||
// Setting SQL query
|
||||
$sql = "SELECT * FROM swag_table WHERE id = ".$id;
|
||||
// Getting results
|
||||
$query = mysqli_query($conn, $sql);
|
||||
// Fetching associated info
|
||||
$image_array = mysqli_fetch_assoc($query);
|
||||
|
||||
return($image_array);
|
||||
}
|
||||
|
||||
|
||||
// Get image ID to search up
|
||||
$image_post_id = $_POST['image_id'];
|
||||
$image_info = get_image_info($conn, $image_post_id);
|
||||
|
||||
if (isset($_POST['description'])) {
|
||||
// If privilaged, continue
|
||||
if (image_privilage($image_info['id'])) {
|
||||
// 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['description'];
|
||||
$param_id = $image_post_id;
|
||||
|
||||
// Attempt to execute the prepared statement
|
||||
if (mysqli_stmt_execute($stmt)) {
|
||||
echo "<script>sniffleAdd('Info','Description has been updated successfully! You may need to refresh the page to see the new information.','var(--green)')</script>";
|
||||
} else {
|
||||
echo "<script>sniffleAdd('Error','An error occured on the servers','var(--red)')</script>";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
echo "<script>sniffleAdd('Error','You do not have access to this','var(--red)')</script>";
|
||||
}
|
||||
}
|
0
app/image/edit_tags.php
Normal file
0
app/image/edit_tags.php
Normal file
17
app/server/conn.php
Normal file
17
app/server/conn.php
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
/*
|
||||
Connect to database
|
||||
|
||||
In the future I want this section to be configurable, but that'll require some work to be done.
|
||||
For now it's hard-coded, shouldn't be an issue as most people wont be changing this often anyway
|
||||
*/
|
||||
// Setting up connection variables
|
||||
$conn_ip = "localhost";
|
||||
$conn_username = "uwu";
|
||||
$conn_password = "fennec621";
|
||||
$conn_database = "swag";
|
||||
|
||||
$conn = mysqli_connect($conn_ip, $conn_username, $conn_password , $conn_database);
|
||||
if ($conn->connect_error) {
|
||||
// Send notification that connection couldn't be made
|
||||
}
|
95
image.php
95
image.php
|
@ -95,20 +95,6 @@ if (image_privilage($image['author']) || is_admin($_SESSION['id'])) {
|
|||
</script>
|
||||
|
||||
<?php
|
||||
/*
|
||||
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 = "<form method='POST' enctype='multipart/form-data'>
|
||||
<button class='btn alert-low' type='submit' name='delete_confirm' value='".$image['id']."'><img class='svg' src='assets/icons/trash.svg'>Delete image</button>
|
||||
</form>";
|
||||
|
||||
flyout($header, $content, $action);
|
||||
}
|
||||
/*
|
||||
Confirm deleting user
|
||||
|
||||
|
@ -137,19 +123,7 @@ if (image_privilage($image['author']) || is_admin($_SESSION['id'])) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Description edit
|
||||
*/
|
||||
if (isset($_POST['description_flyout']) && $privilaged) {
|
||||
$header = "Enter new Description/Alt";
|
||||
$content = "Whatcha gonna put in there 👀";
|
||||
$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);
|
||||
}
|
||||
/*
|
||||
Description confirm
|
||||
*/
|
||||
|
@ -177,19 +151,7 @@ if (image_privilage($image['author']) || is_admin($_SESSION['id'])) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Adding tags
|
||||
*/
|
||||
if (isset($_POST['tags_flyout']) && $privilaged) {
|
||||
$header = "Tags";
|
||||
$content = "Add image tags here! This is still being tested so your tags may be removed later on. Tags ONLY accept, letters, numbers and underscores. Hyphens will be stitched to underscores and spaces will seperate the different tags from eachother.";
|
||||
$action = "<form class='flex-down between' method='POST' enctype='multipart/form-data'>
|
||||
<input class='btn alert-default space-bottom' type='text' name='add_tags' placeholder='Tags are seperated by spaces'>
|
||||
<button class='btn alert-low' type='submit' name='tags_confirm' value='".$image["id"]."'><img class='svg' src='assets/icons/edit.svg'>Add tags</button>
|
||||
</form>";
|
||||
|
||||
flyout($header, $content, $action);
|
||||
}
|
||||
/*
|
||||
Tags Confirm
|
||||
*/
|
||||
|
@ -367,15 +329,49 @@ if (image_privilage($image['author']) || is_admin($_SESSION['id'])) {
|
|||
<button id='deleteButton' class='btn alert-low'><img class='svg' src='assets/icons/trash.svg'>Delete image</button>
|
||||
<script>
|
||||
$('#deleteButton').click(function(){
|
||||
flyoutShow('Are you sure?', 'Deleting this image is pernament, there is no going back after this!!!!!', '<button class="btn alert-low"><img class="svg" src="assets/icons/trash.svg">Delete image</button>');
|
||||
var header = "Are you sure?";
|
||||
var description = "Deleting this image is pernament, there is no going back after this!!!!!";
|
||||
var actionBox = "<button class='btn alert-low'><img class='svg' src='assets/icons/trash.svg'>Delete image</button>";
|
||||
flyoutShow(header, description, actionBox);
|
||||
});
|
||||
</script>
|
||||
|
||||
<!-- Edit description -->
|
||||
<button id='editButton' class='btn alert-low space-top-small'><img class='svg' src='assets/icons/edit.svg'>Edit description</button>
|
||||
<!--
|
||||
|-------------------------------------------------------------
|
||||
| Edit description
|
||||
|-------------------------------------------------------------
|
||||
| As the name suggests, this edits the description, this
|
||||
| Uses the following variables:
|
||||
| editDescriptionButton
|
||||
| editDescriptionConfirm
|
||||
| editDescriptionInput
|
||||
| editDescriptionSubmit
|
||||
|-------------------------------------------------------------
|
||||
-->
|
||||
<button id='descriptionButton' class='btn alert-low space-top-small'><img class='svg' src='assets/icons/edit.svg'>Edit description</button>
|
||||
<script>
|
||||
$('#editButton').click(function(){
|
||||
flyoutShow('Enter new Description/Alt', 'Whatcha gonna put in there 👀', '<button class="btn alert-low"><img class="svg" src="assets/icons/edit.svg">Update information</button>');
|
||||
$('#descriptionButton').click(function(){
|
||||
var header = "Enter new Description/Alt";
|
||||
var description = "Whatcha gonna put in there 👀";
|
||||
var actionBox = "<form id='descriptionConfirm' action='app/image/edit_description.php' method='POST'>\
|
||||
<input id='descriptionInput' class='btn alert-default space-bottom' type='text' placeholder='Description/Alt for image'>\
|
||||
<button id='descriptionSubmit' class='btn alert-low'><img class='svg' src='assets/icons/edit.svg'>Update information</button>\
|
||||
</form>\
|
||||
<div id='descriptionErrorHandling'></div>";
|
||||
flyoutShow(header, description, actionBox);
|
||||
});
|
||||
|
||||
$(document).ready(function() {
|
||||
$("#editDescriptionConfirm").submit(function(event) {
|
||||
event.preventDefault();
|
||||
var descriptionInput = $("#descriptionInput").val();
|
||||
var descriptionSubmit = $("descriptionSubmit").val();
|
||||
$("#descriptionErrorHandling").load("app/image/edit_description.php", {
|
||||
image_id: <?php echo $_GET['id']; ?>,
|
||||
description: descriptionInput,
|
||||
submit: descriptionSubmit
|
||||
})
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
@ -383,7 +379,11 @@ if (image_privilage($image['author']) || is_admin($_SESSION['id'])) {
|
|||
<button id='tagButton' class='btn alert-low space-top-small'><img class='svg' src='assets/icons/edit.svg'>Add image tags</button>
|
||||
<script>
|
||||
$('#tagButton').click(function(){
|
||||
flyoutShow('Tags', 'Add image tags here! This is still being tested so your tags may be removed later on. Tags ONLY accept, letters, numbers and underscores. Hyphens will be stitched to underscores and spaces will seperate the different tags from eachother.', '<input class="btn alert-default space-bottom" type="text" name="add_tags" placeholder="Tags are seperated by spaces"><button class="btn alert-low"><img class="svg" src="assets/icons/edit.svg">Add tags</button>');
|
||||
var header = "Tags";
|
||||
var description = "Add image tags here! This is still being tested so your tags may be removed later on. Tags ONLY accept, letters, numbers and underscores. Hyphens will be stitched to underscores and spaces will seperate the different tags from eachother";
|
||||
var actionBox = "<input class='btn alert-default space-bottom' type='text' name='add_tags' placeholder='Tags are seperated by spaces'>\
|
||||
<button class='btn alert-low'><img class='svg' src='assets/icons/edit.svg'>Add tags</button>";
|
||||
flyoutShow(header, description, actionBox);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
@ -394,7 +394,7 @@ if (image_privilage($image['author']) || is_admin($_SESSION['id'])) {
|
|||
<form id='author_form' method='POST' action='ui/image_interaction.php'>
|
||||
<input id='author_header' type='hidden' name='header' value='Who owns the image?????'>
|
||||
<input id='author_description' type='hidden' name='description' value='Enter ID of image owner'>
|
||||
<button id='author_submit' 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>
|
||||
<button id='author_submit' class='btn alert-low space-top-small' type='submit' name='author_flyout'><img class='svg' src='assets/icons/edit.svg'>Edit author</button>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
|
@ -402,9 +402,6 @@ if (image_privilage($image['author']) || is_admin($_SESSION['id'])) {
|
|||
}
|
||||
?>
|
||||
|
||||
<?php
|
||||
include "ui/top.html";
|
||||
include "ui/footer.php";
|
||||
?>
|
||||
<?php include "ui/footer.php"; ?>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -108,9 +108,6 @@
|
|||
?>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
include "ui/top.html";
|
||||
include "ui/footer.php";
|
||||
?>
|
||||
<?php include "ui/footer.php"; ?>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
$(document).ready(function() {
|
||||
button = document.getElementById("back-to-top");
|
||||
|
||||
window.onscroll = function() {scrollFunction()};
|
||||
|
||||
function scrollFunction() {
|
||||
if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 20) {
|
||||
button.style.right = "1rem";
|
||||
} else {
|
||||
button.style.right = "-2.5rem";
|
||||
}
|
||||
}
|
||||
});
|
|
@ -188,4 +188,3 @@ function notify($text, $level) {
|
|||
|
||||
return $text_string;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
echo "<hr>";
|
||||
echo "<a class='btn alert-default' href='/account/account.php'><img class='svg' src='".$root_dir."assets/icons/user-circle.svg'><span class='nav-hide'>".substr($_SESSION["username"], 0, 15)."</span></a>";
|
||||
} else {
|
||||
echo "<a class='btn alert-default' href='/account/login.php'><img class='svg' src='".$root_dir."assets/icons/user-circle-plus.svg'><span class='nav-hide'>Login</span></a>";
|
||||
echo "<a class='btn alert-default' href='/account/login.php'><img class='svg' src='".$root_dir."assets/icons/sign-in.svg'><span class='nav-hide'>Login</span></a>";
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
|
|
@ -1,22 +1,4 @@
|
|||
<?php
|
||||
/*
|
||||
Connect to database
|
||||
|
||||
In the future I want this section to be configurable, but that'll require some work to be done.
|
||||
For now it's hard-coded, shouldn't be an issue as most people wont be changing this often anyway
|
||||
*/
|
||||
// Setting up connection variables
|
||||
$conn_ip = "localhost";
|
||||
$conn_username = "uwu";
|
||||
$conn_password = "fennec621";
|
||||
$conn_database = "swag";
|
||||
|
||||
$conn = mysqli_connect($conn_ip, $conn_username, $conn_password , $conn_database);
|
||||
if ($conn->connect_error) {
|
||||
// Send notification that connection couldn't be made
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Start session
|
||||
|
||||
|
@ -37,6 +19,11 @@ if (is_file("index.php")) {
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
Connect to the server
|
||||
*/
|
||||
include $root_dir."app/server/conn.php";
|
||||
|
||||
/*
|
||||
Include functions
|
||||
|
||||
|
@ -66,10 +53,16 @@ echo "<div id='notify-root' class='notify-root'></div>";
|
|||
});
|
||||
</script>
|
||||
|
||||
<!-- Used by Sniffle to add Notifications, div can be displayed all time as it has no width or height initself -->
|
||||
<!--
|
||||
Used by Sniffle to add Notifications
|
||||
Div can be displayed all time as it has no width or height initself
|
||||
-->
|
||||
<div id='sniffle' class='sniffle'></div>
|
||||
|
||||
<!-- Div for information flyouts, controlled by Flyout.js -->
|
||||
<!--
|
||||
Div for information flyouts
|
||||
Controlled by Flyout.js
|
||||
-->
|
||||
<div id='flyoutDim' class='flyout-dim'></div>
|
||||
<div id='flyoutRoot' class='flyout flex-down'>
|
||||
<p id='flyoutHeader' class='flyout-header space-bottom'>Header</p>
|
||||
|
@ -77,3 +70,26 @@ echo "<div id='notify-root' class='notify-root'></div>";
|
|||
<div id='flyoutActionbox' class='flyout-actionbox space-bottom-small'></div>
|
||||
<button onclick='flyoutClose()' class='btn alert-default'>Close</button>
|
||||
</div>
|
||||
|
||||
<!--
|
||||
Back to top button
|
||||
Used to quickly get back up to the top of the page,
|
||||
At some point will be removed as the UI metures and
|
||||
everything can always be accessed
|
||||
-->
|
||||
<a id="back-to-top" href="#">
|
||||
<img src="assets/icons/caret-up.svg">
|
||||
</a>
|
||||
<script>
|
||||
button = document.getElementById("back-to-top");
|
||||
|
||||
window.onscroll = function() {scrollFunction()};
|
||||
|
||||
function scrollFunction() {
|
||||
if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 20) {
|
||||
button.style.right = "1rem";
|
||||
} else {
|
||||
button.style.right = "-2.5rem";
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
<a id="back-to-top" href="#">
|
||||
<img src="assets/icons/caret-up.svg">
|
||||
</a>
|
||||
<script src="scripts/top.js"></script>
|
Loading…
Reference in a new issue