itskp-odense/Frontend/admin.php

121 lines
3.9 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>
<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/bootstrap.min.css">
<link rel="stylesheet" href="Assets/CSS/datatables.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;
}
a:hover {
cursor: pointer
}
</style>
<body>
<div class="container mb-4 mt-4">
<div class="row">
<div class="col">
<p><u><?php echo ucfirst($_SESSION['name']);?></u></p>
<a href="../Backend/controller/logout.php">Log ud</a>
<br>
<a href="index.php">Index pages</a>
<hr>
<div class="row">
<div class="col">
<button class="btn btn-secondary mb-4" onclick="createPostSwal()">Opret Post</button>
<table 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>
</div>
<script src="Assets/Ajax/deletePost.js"></script>
<script src="Assets/Ajax/fetchAndDisplayData.js"></script>
<script src="Assets/Ajax/createPost.js"></script>
<script>
function createPostSwal() {
Swal.fire({
title: 'Opret Post',
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="title" 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>',
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());
})
}
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'
}).then((result) => {
if (result.isConfirmed) {
deletePost(id);
}
})
}
</script>
</body>
</html>