itskp-odense/Frontend/admin.php

221 lines
8.7 KiB
PHP
Raw Normal View History

<?php
require "../Backend/controller/accessControl.php";
require "../bootstrap.php";
use Backend\Model\Post;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home</title>
2021-06-08 13:04:40 +00:00
<script src="Assets/JS/bootstrap.min.js"></script>
<script src="Assets/JS/jquery-3.6.0.min.js"></script>
<script src="Assets/JS/sweetalert2.all.min.js"></script>
<script src="Assets/JS/datatables.min.js"></script>
<link rel="stylesheet" href="Assets/CSS/datatables.min.css">
2021-06-08 13:04:40 +00:00
<link rel="stylesheet" href="Assets/CSS/bootstrap.min.css">
</head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
.w-1em {
width: 1em;
}
a > img, th > img {
width: 1em;
margin: auto;
}
2021-06-08 13:04:40 +00:00
a:hover:not('text-decoration-none') {
cursor: pointer
}
2021-06-08 13:04:40 +00:00
.mr-auto {
margin-right: auto;
}
.ml-auto {
margin-left: auto;
}
</style>
<body>
<div class="container mb-4 mt-4">
2021-06-08 13:04:40 +00:00
<div class="row mb-4">
<nav class="navbar navbar-expand-lg navbar-light bg-light shadow-sm">
<div class="container">
<a class="navbar-brand" href="admin.php">Admin panel</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav mr-auto">
</ul>
<ul class="navbar-nav ml-auto align-items-center">
<li class="nav-item active">
<a class="nav-link" href="index.php">Index</a>
</li>
<li class="nav-item">
<a class="nav-link" href="../Backend/controller/logout.php">Log af</a>
</li>
<li class="nav-item">
<a class="nav-link text-decoration-none"><u><?php echo ucfirst($_SESSION['name']);?></u></a>
</li>
</ul>
</div>
2021-06-08 09:09:28 +00:00
</div>
</nav>
2021-06-08 13:04:40 +00:00
</div>
2021-06-09 11:20:49 +00:00
<div class="row pt-4 pb-4">
<div class="col">
2021-06-08 13:04:40 +00:00
<button class="btn btn-success mb-5" onclick="createPostSwal()">Opret Post</button>
<table class="pt-2" id="table_id">
<thead>
<th>Oprettet</th>
<th>Titel</th>
<th class="w-1em"><img src="Assets/Images/Icons/pencil-dark.svg" alt="Edit"></th>
<th class="w-1em"><img src="Assets/Images/Icons/trashcan-dark.svg" alt="Delete"></th>
</thead>
<tbody id="dis">
</tbody>
</table>
</div>
</div>
<hr>
2021-06-09 11:20:49 +00:00
<?php
if (isset($_SESSION['permission'])) {
?>
<div class="row pt-4">
<div class="col">
<button class="btn btn-success mb-5" onclick="createUserSwal()">Opret Bruger</button>
<table class="pt-2" id="table_id_users">
<thead>
<th>Navn</th>
<th class="w-1em"><img src="Assets/Images/Icons/pencil-dark.svg" alt="Edit"></th>
<th class="w-1em"><img src="Assets/Images/Icons/trashcan-dark.svg" alt="Delete"></th>
</thead>
<tbody id="dis_users">
</tbody>
</table>
</div>
</div>
<?php
}
?>
</div>
2021-06-09 11:20:49 +00:00
<script>
$(document).ready(function() {
var id = <?php echo $_SESSION['id']; ?>
});
</script>
<script src="Assets/Ajax/fetchAndDisplayData.js"></script>
<script src="Assets/Ajax/deletePost.js"></script>
<script src="Assets/Ajax/createPost.js"></script>
<script src="Assets/Ajax/editPost.js"></script>
2021-06-09 11:20:49 +00:00
<script src="Assets/Ajax/createUser.js"></script>
<script src="Assets/Ajax/deleteUser.js"></script>
<script src="Assets/Ajax/editUser.js"></script>
<script>
function createPostSwal() {
Swal.fire({
title: 'Opret Post',
2021-06-09 11:20:49 +00:00
html: '<div class="form-group row mb-4 justify-content-center"><label for="title" class="col-md-12 col-form-label text-md-right">Titel</label><div class="col-md-9"><input type="text" class="form-control" id="title" name="title" maxlength="255" required autofocus></div></div><div class="form-group row mb-4 justify-content-center"><label for="description" class="col-md-12 col-form-label text-md-right">Beskrivelse</label><div class="col-md-9"><textarea type="text" class="form-control" id="description" name="description" maxlength="2000" required autofocus></textarea></div></div>',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Opret',
focusConfirm: false,
preConfirm: () => {
const title = Swal.getPopup().querySelector('#title').value
const desc = Swal.getPopup().querySelector('#description').value
if (!title || !desc) {
Swal.showValidationMessage(`Skriv noget i begge felter!`)
}
return {title: title, desc: desc}
}
}).then((result) => {
createPost(result.value.title.trim(), result.value.desc.trim());
})
}
2021-06-09 11:20:49 +00:00
function createUserSwal() {
Swal.fire({
title: 'Opret Post',
html: '<div class="form-group row mb-4 justify-content-center"><label for="name" class="col-md-3 col-form-label text-md-right">Navn</label><div class="col-md-9"><input type="text" class="form-control" id="name" name="name" maxlength="255" required autofocus></div></div><div class="form-group row mb-4 justify-content-center"><label for="title" class="col-md-3 col-form-label text-md-right">Password</label><div class="col-md-9"><input type="password" class="form-control" id="password" name="password" maxlength="255" required autofocus></div></div><div class="form-group row mb-4 justify-content-center"><label for="title" class="col-md-3 col-form-label text-md-right">Confirm Password</label><div class="col-md-9"><input type="password" class="form-control" id="confirmPassword" name="confirmPassword" maxlength="255" required autofocus></div></div>',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Opret',
focusConfirm: false,
preConfirm: () => {
const name = Swal.getPopup().querySelector('#name').value
const pass = Swal.getPopup().querySelector('#password').value
const conpass = Swal.getPopup().querySelector('#confirmPassword').value
if (!name || !pass || !conpass) {
Swal.showValidationMessage(`Skriv noget i alle felter!`)
} else if (pass != conpass) {
Swal.showValidationMessage(`Password er ikke ens!`)
}
return {name: name, pass: pass, conpass: conpass}
}
}).then((result) => {
createUser(result.value.name.trim(), result.value.pass.trim());
})
}
function deletePostSwal(id) {
Swal.fire({
title: 'Er du sikker?',
text: "Dette kan ikke blive ændret tilbage!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Slet Post',
cancelButtonText: 'Annuller'
2021-06-09 11:20:49 +00:00
}).then((result) => {
if (result.isConfirmed) {
deletePost(id);
}
})
}
function deleteUserSwal(id) {
Swal.fire({
title: 'Er du sikker?',
text: "Dette kan ikke blive ændret tilbage!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Slet Bruger',
cancelButtonText: 'Annuller'
}).then((result) => {
if (result.isConfirmed) {
deleteUser(id);
}
})
}
</script>
</body>
</html>