In progress admin page

This commit is contained in:
Michał 2022-09-16 16:39:13 +00:00
parent 67dedc60cc
commit e28157de3c
13 changed files with 364 additions and 37 deletions

Binary file not shown.

View file

@ -45,6 +45,8 @@
border-radius: var(--rad);
transition: margin-top 1s cubic-bezier(.19,1,.22,1);
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
@ -53,12 +55,10 @@
user-select: none;
}
.sniffle-notification:hover {
transform: scale(1.05);
cursor: pointer;
}
.sniffle-notification:not(:nth-of-type(1), :nth-of-type(2), :nth-of-type(3), :nth-of-type(4), :nth-of-type(5)) {
.sniffle-notification:not(:nth-of-type(1), :nth-of-type(2), :nth-of-type(3), :nth-of-type(4)) {
display: none;
opacity: 0;
}
@ -71,30 +71,23 @@
.sniffle-notification:nth-of-type(2) {
z-index: -1;
transform: scale(0.95);
margin-top: -5rem;
margin-top: -4.8rem;
opacity: 1;
transition: transform 1.25s, opacity 0.5s;
}
.sniffle-notification:nth-of-type(3) {
z-index: -2;
transform: scale(0.9);
margin-top: -5rem;
margin-top: -4.8rem;
opacity: 1;
transition: transform 1.5s, opacity 0.75s;
}
.sniffle-notification:nth-of-type(4) {
z-index: -3;
transform: scale(0.85);
margin-top: -5rem;
opacity: 1;
transition: transform 1.75s, opacity 1s;
}
.sniffle-notification:nth-of-type(5) {
z-index: -4;
transform: scale(0.80);
margin-top: -5rem;
margin-top: -4.8rem;
opacity: 0;
transition: transform 2s, opacity 1.25s;
transition: transform 1.75s, opacity 1s;
}
/*

View file

@ -30,7 +30,7 @@
<a class='btn btn-bad' href='app/account/logout.php'><img class='svg' src='assets/icons/sign-out.svg'>Logout</a>
</div>
<?php
if ($user_info->is_admin($_SESSION['id'])) {
if ($user_info->is_admin($conn, $_SESSION['id'])) {
?>
<div class="admin-root">
<h2>Admin controlls</h2>
@ -52,6 +52,12 @@
<br>
<h3>Logs</h3>
<div id=logs" class="logs">
<div class="log">
<p>ID</p>
<p>User IP</p>
<p>Action</p>
<p>Time</p>
</div>
<?php
// Reading images from table
$logs_request = mysqli_query($conn, "SELECT * FROM logs ORDER BY id DESC");
@ -74,6 +80,13 @@
<br>
<h3>Bans</h3>
<div id="bans" class="bans">
<div class="ban">
<p>ID</p>
<p>User IP</p>
<p>Reason</p>
<p>Lenght</p>
<p>Time</p>
</div>
<?php
// Reading images from table
$bans_request = mysqli_query($conn, "SELECT * FROM bans ORDER BY id DESC");
@ -91,13 +104,104 @@
<p><?php echo $ban['length']; ?> mins</p>
<?php
$log_time = new DateTime($ban['time']);
echo "<p>" . $log_time->format('Y-m-d H:i:s T') . "<br>" . $diff->time($ban['time']) . "</p>";
echo "<p>" . $log_time->format('Y-m-d H:i:s T') . " | " . $diff->time($ban['time']) . "</p>";
?>
</div>
<?php
}
?>
</div>
<br>
<h3>User settings</h3>
<div id="user-settings" class="user-settings">
<div class="user">
<p>ID</p>
<p>Username</p>
<p>Last Modified</p>
<p>User Options</p>
<p></p>
<p></p>
</div>
<?php
// Reading images from table
$user_request = mysqli_query($conn, "SELECT * FROM users");
while ($user = mysqli_fetch_array($user_request)) {
if ($user['admin'] || $user['id'] == 1) {
echo "<div class='user is-admin'>";
} else {
echo "<div class='user'>";
}
?>
<p><?php echo $user['id']; ?></p>
<p><?php echo $user['username']; ?></p>
<?php
$user_time = new DateTime($user['created_at']);
echo "<p>" . $user_time->format('Y-m-d H:i:s T') . " | " . $diff->time($user['created_at']) . "</p>";
if ($user['id'] == 1) {
?>
<button class="btn btn-neutral" style="outline: none;">Reset Password</button>
<button class="btn btn-neutral" style="outline: none;">Delete user</button>
<button class="btn btn-neutral" style="outline: none;">Toggle admin</button>
<?php
} else {
?>
<button id="userResetPassword" class="btn btn-bad">Reset Password</button>
<button id="userDeleteButton" class="btn btn-bad" onclick="userDelete('<?php echo $user['id']; ?>', '<?php echo $user['username']; ?>')">Delete user</button>
<button id="userToggleAdmin" class="btn btn-bad" onclick="userToggleAdmin('<?php echo $user['id']; ?>', '<?php echo $user['username']; ?>')">Toggle admin</button>
<?php
}
?>
</div>
<?php
}
?>
<script>
function userDelete(id, username) {
var header = "Are you very very sure?";
var description = "This CANNOT be undone, be very carefull with your decition...";
var actionBox = "<form id='' action='app/image/edit_description.php' method='POST'>\
<button class='btn btn-bad' type='submit' value='"+id+"'><img class='svg' src='assets/icons/trash.svg'>Delete user "+username+" (keep posts)</button>\
</form>\
<form id='' action='app/image/edit_description.php' method='POST'>\
<button class='btn btn-bad' type='submit' value='"+id+"'><img class='svg' src='assets/icons/trash.svg'>Delete user "+username+" (delete posts)</button>\
</form>";
flyoutShow(header, description, actionBox);
/*$("#descriptionConfirm").submit(function(event) {
event.preventDefault();
var descriptionInput = $("#descriptionInput").val();
var descriptionSubmit = $("#descriptionSubmit").val();
$("#sniffle").load("app/image/image.php", {
id: id,
input: descriptionInput,
submit_description: descriptionSubmit
});
});*/
}
function userToggleAdmin(id, username) {
var header = "With great power comes great responsibility...";
var description = "Do you trust this user? With admin permitions they can cause a whole lot of damage to this place, so make sure you're very very sure";
var actionBox = "<form id='toggleAdminConfirm' action='app/image/edit_description.php' method='POST'>\
<button id='toggleAdminSubmit' class='btn btn-bad' type='submit' value='"+id+"'>Make "+username+" powerfull!</button>\
</form>";
flyoutShow(header, description, actionBox);
$("#toggleAdminConfirm").submit(function(event) {
event.preventDefault();
var toggleAdminSubmit = $("#toggleAdminSubmit").val();
$("#sniffle").load("app/account/account.php", {
id: toggleAdminSubmit,
toggle_admin: toggleAdminSubmit
});
});
}
</script>
</div>
</div>
<?php
}

View file

@ -420,3 +420,60 @@ if (isset($_POST['submit_signup'])) {
}
}
}
/*
|-------------------------------------------------------------
| Toggle Admin
|-------------------------------------------------------------
| Please save me
|-------------------------------------------------------------
*/
if (isset($_POST['toggle_admin'])) {
$is_admin = mysqli_query($conn, "SELECT * FROM users WHERE id = " . $_POST['id'] . " ORDER BY id DESC LIMIT 1");
while ($user_info = mysqli_fetch_assoc($is_admin)) {
$admin_status = $user_info['admin'];
$username = $user_info['username'];
}
$sql = "UPDATE users SET admin = ? WHERE id = ?";
if ($stmt = mysqli_prepare($conn, $sql)) {
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "ii", $param_admin_status, $param_user_id);
// Set parameters
if ($admin_status) {
$param_admin_status = 0;
$admin_update_message = "removed from the admins list";
} elseif (!$admin_status) {
$param_admin_status = 1;
$admin_update_message = "added to the admins list";
}
$param_user_id = $_POST['id'];
// Attempt to execute the prepared statement
if (mysqli_stmt_execute($stmt)) {
?>
<script>
sniffleAdd('Bap!', '<?php echo $username; ?> has been <?php echo $admin_update_message; ?>!', 'var(--green)', 'assets/icons/check.svg');
flyoutClose();
</script>
<?php
} else {
?>
<script>
sniffleAdd('Bruh', 'Something went fuckywucky, please try later', 'var(--red)', 'assets/icons/cross.svg');
flyoutClose();
</script>
<?php
}
} else {
?>
<script>
sniffleAdd('Bruh', 'Something went fuckywucky, please try later', 'var(--red)', 'assets/icons/cross.svg');
flyoutClose();
</script>
<?php
}
}

View file

@ -76,9 +76,16 @@ class Account {
Returns True if user is privilaged
Returns False if user is NOT privilaged
*/
function is_admin($id) {
function is_admin($conn, $id) {
if (isset($id) || !empty($id)) {
if ($id == 1) {
// Setting SQL query
$sql = "SELECT * FROM users WHERE id = ".$id;
// Getting results
$query = mysqli_query($conn, $sql);
// Fetching associated info
$user_array = mysqli_fetch_assoc($query);
if ($user_array['admin'] || $id == 1) {
return True;
} else {
return False;

View file

@ -27,7 +27,7 @@ if (isset($_POST['submit_delete'])) {
$image_array = $image_info->get_image_info($conn, $_POST['id']);
// If user owns image or has the ID of 1
if ($image_info->image_privilage($image_array['author']) || $_SESSION['id'] == 1) {
if ($image_info->image_privilage($image_array['author']) || $user_info->is_admin($conn, $_SESSION['id'])) {
// Delete from table
$sql = "DELETE FROM images WHERE id = ?";
if ($stmt = mysqli_prepare($conn, $sql)) {
@ -101,7 +101,7 @@ if (isset($_POST['submit_description'])) {
// Get all image info
$image_array = $image_info->get_image_info($conn, $_POST['id']);
// If user owns image or has the ID of 1
if ($image_info->image_privilage($image_array['author']) || $_SESSION['id'] == 1) {
if ($image_info->image_privilage($image_array['author']) || $user_info->is_admin($conn, $_SESSION['id'])) {
// getting ready forSQL asky asky
$sql = "UPDATE images SET alt=? WHERE id=?";
@ -159,7 +159,7 @@ if (isset($_POST['submit_tags'])) {
// Get all image info
$image_array = $image_info->get_image_info($conn, $_POST['id']);
// If user owns image or has the ID of 1
if ($image_info->image_privilage($image_array['author']) || $_SESSION['id'] == 1) {
if ($image_info->image_privilage($image_array['author']) || $user_info->is_admin($conn, $_SESSION['id'])) {
// Clean input
$tags_string = $make_stuff->tags(trim($_POST['input']));
@ -218,7 +218,7 @@ if (isset($_POST['submit_tags'])) {
*/
if (isset($_POST['submit_author'])) {
// If user has the ID of 1
if ($user_info->is_admin($_SESSION['id'])) {
if ($user_info->is_admin($conn, $_SESSION['id'])) {
// getting ready forSQL asky asky
$sql = "UPDATE images SET author=? WHERE id=?";

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="192" height="192" fill="#e8e3e3" viewBox="0 0 256 256"><rect width="256" height="256" fill="none"></rect><polyline points="176.2 99.7 224.2 99.7 224.2 51.7" fill="none" stroke="#e8e3e3" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"></polyline><path d="M190.2,190.2a88,88,0,1,1,0-124.4l34,33.9" fill="none" stroke="#e8e3e3" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"></path></svg>

After

Width:  |  Height:  |  Size: 467 B

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="192" height="192" fill="#e8e3e3" viewBox="0 0 256 256"><rect width="256" height="256" fill="none"></rect><polyline points="160 48 208 48 208 96" fill="none" stroke="#e8e3e3" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"></polyline><line x1="152" y1="104" x2="208" y2="48" fill="none" stroke="#e8e3e3" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"></line><polyline points="96 208 48 208 48 160" fill="none" stroke="#e8e3e3" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"></polyline><line x1="104" y1="152" x2="48" y2="208" fill="none" stroke="#e8e3e3" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"></line></svg>

After

Width:  |  Height:  |  Size: 732 B

1
assets/icons/scan.svg Normal file
View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="192" height="192" fill="#e8e3e3" viewBox="0 0 256 256"><rect width="256" height="256" fill="none"></rect><polyline points="176 40 216 40 216 80" fill="none" stroke="#e8e3e3" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"></polyline><polyline points="80 216 40 216 40 176" fill="none" stroke="#e8e3e3" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"></polyline><polyline points="216 176 216 216 176 216" fill="none" stroke="#e8e3e3" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"></polyline><polyline points="40 80 40 40 80 40" fill="none" stroke="#e8e3e3" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"></polyline><rect x="80" y="80" width="96" height="96" rx="8" fill="none" stroke="#e8e3e3" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"></rect></svg>

After

Width:  |  Height:  |  Size: 889 B

View file

@ -328,6 +328,8 @@ nav .btn {
}
.preview-button {
width: 1.5rem;
padding: 0;
position: absolute;
bottom: 0.5rem;
right: 0.5rem;
@ -344,6 +346,10 @@ nav .btn {
opacity: 0.8;
box-shadow: 6px 6px 2px rgba(21, 21, 21, 0.4);
}
.preview-button img {
width: 1.5rem;
display: block;
}
.preview-button:hover {
outline: #E8E3E3 0.2rem solid;
color: #E8E3E3;
@ -650,7 +656,7 @@ nav .btn {
flex-direction: row;
justify-content: space-between;
}
.log:nth-child(odd) {
.log:nth-child(even) {
background-color: rgba(255, 255, 255, 0.0666666667);
}
.log > * {
@ -669,6 +675,14 @@ nav .btn {
}
.log > *:nth-child(4) {
width: 40%;
margin: 0;
}
.log:first-of-type {
background-color: #151515;
position: -webkit-sticky;
position: sticky;
top: 0;
}
.bans {
@ -690,7 +704,7 @@ nav .btn {
flex-direction: row;
justify-content: space-between;
}
.ban:nth-child(odd) {
.ban:nth-child(even) {
background-color: rgba(255, 255, 255, 0.0666666667);
}
.ban > * {
@ -705,17 +719,83 @@ nav .btn {
width: 17%;
}
.ban > *:nth-child(3) {
width: 38%;
width: 34%;
}
.ban > *:nth-child(4) {
width: 10%;
}
.ban > *:nth-child(5) {
width: 30%;
width: 34%;
margin: 0;
}
.perm {
border: 1px #B66467 solid;
border: 3px #B66467 solid;
}
.ban:first-of-type {
background-color: #151515;
position: -webkit-sticky;
position: sticky;
top: 0;
}
.user-settings {
width: 100%;
max-height: 21rem;
min-height: auto;
padding: 0;
overflow-y: scroll;
display: flex;
flex-direction: column;
background-color: #151515;
border-radius: calc(0.25rem - (0.5rem + 3px));
}
.user {
min-width: 769px;
padding: 0.5rem;
display: flex;
flex-direction: row;
justify-content: space-between;
}
.user:nth-child(even) {
background-color: rgba(255, 255, 255, 0.0666666667);
}
.user > * {
margin: 0 0.5rem 0 0;
padding: 0;
word-wrap: break-word;
}
.user > *:nth-child(1) {
width: 5%;
}
.user > *:nth-child(2) {
width: 15%;
}
.user > *:nth-child(3) {
width: 35%;
}
.user > *:nth-child(4) {
width: 15%;
}
.user > *:nth-child(5) {
width: 15%;
}
.user > *:nth-child(6) {
width: 15%;
margin: 0;
}
.is-admin {
background-color: #8C977D !important;
}
.user:first-of-type {
background-color: #151515;
position: -webkit-sticky;
position: sticky;
top: 0;
}
.signup-root {

View file

@ -207,6 +207,10 @@
}
.preview-button {
width: 1.5rem;
padding: 0;
position: absolute;
bottom: 0.5rem;
right: 0.5rem;
@ -231,6 +235,12 @@
box-shadow: $shadow;
img {
width: 1.5rem;
display: block;
}
&:hover {
outline: $white 0.2rem solid;
color: $fg;
@ -369,7 +379,7 @@
justify-content: space-between;
&:nth-child(odd) {
&:nth-child(even) {
background-color: #ffffff11;
}
@ -389,9 +399,15 @@
}
&:nth-child(4) {
width: 40%;
margin: 0;
}
}
}
.log:first-of-type {
background-color: $bg;
position: sticky;
top: 0;
}
.bans {
width: 100%;
@ -415,7 +431,7 @@
justify-content: space-between;
&:nth-child(odd) {
&:nth-child(even) {
background-color: #ffffff11;
}
@ -431,18 +447,85 @@
width: 17%;
}
&:nth-child(3) {
width: 38%;
width: 34%;
}
&:nth-child(4) {
width: 10%;
}
&:nth-child(5) {
width: 30%;
width: 34%;
margin: 0;
}
}
}
.perm {
border: 1px $red solid;
border: 3px $red solid;
}
.ban:first-of-type {
background-color: $bg;
position: sticky;
top: 0;
}
.user-settings {
width: 100%;
max-height: 21rem; min-height: auto;
padding: 0;
overflow-y: scroll;
display: flex; flex-direction: column;
background-color: $bg;
border-radius: calc($rad - (0.5rem + 3px));
}
.user {
min-width: 769px;
padding: 0.5rem;
display: flex; flex-direction: row;
justify-content: space-between;
&:nth-child(even) {
background-color: #ffffff11;
}
& > * {
margin: 0 0.5rem 0 0;
padding: 0;
word-wrap: break-word;
&:nth-child(1) {
width: 5%;
}
&:nth-child(2) {
width: 15%;
}
&:nth-child(3) {
width: 35%;
}
&:nth-child(4) {
width: 15%;
}
&:nth-child(5) {
width: 15%;
}
&:nth-child(6) {
width: 15%;
margin: 0;
}
}
}
.is-admin {
background-color: $green !important;
}
.user:first-of-type {
background-color: $bg;
position: sticky;
top: 0;
}
.signup-root {

View file

@ -123,7 +123,7 @@
| Check user privilge
|-------------------------------------------------------------
*/
if ($image_info->image_privilage($image['author']) || $user_info->is_admin($_SESSION['id'])) {
if ($image_info->image_privilage($image['author']) || $user_info->is_admin($conn, $_SESSION['id'])) {
$privilaged = True;
} else {
$privilaged = False;
@ -132,7 +132,7 @@
if (is_file("images/previews/".$image['imagename'])) {
echo "<div class='image-container'>
<img class='image' id='".$image['id']."' src='images/previews/".$image['imagename']."' alt='".$image_alt."'>
<button class='preview-button' onclick='showFull()'>Show full quality</button>
<button class='preview-button' onclick='showFull()'><img src='assets/icons/scan.svg'></button>
</div>";
?>
<script>
@ -173,7 +173,7 @@
<div>
<?php
// User
if ($user_info->is_admin($image['author'])) {
if ($user_info->is_admin($conn, $image['author'])) {
echo "<p>Author: ".$image_author."<img class='svg' style='margin: 0 0 0.1rem 0.2rem;' src='assets/icons/crown-simple.svg'></p>";
} else {
echo "<p>Author: ".$image_author."</p>";
@ -387,7 +387,7 @@
|-------------------------------------------------------------
-->
<?php
if ($user_info->is_admin($_SESSION['id'])) {
if ($user_info->is_admin($conn, $_SESSION['id'])) {
?>
<button id='authorButton' class='btn btn-bad'><img class='svg' src='assets/icons/edit.svg'>Edit author</button>
<script>

View file

@ -16,7 +16,7 @@ $loggedin = new Account();
?>
<a class='btn' href='upload.php'><img class='svg' src='assets/icons/upload.svg'><span class='nav-hide'>Upload</span></a>
<hr>
<a class='btn' href='account.php'><img class='svg' src='assets/icons/user-circle.svg'><span class='nav-hide'><?php echo substr($_SESSION["username"], 0, 15); ?></span></a>
<a class='btn' href='account.php'><img class='svg' src='assets/icons/gear.svg'><span class='nav-hide'><?php echo substr($_SESSION["username"], 0, 15); ?></span></a>
<?php
} else {
?>