presento/public/admin/audit.php

101 lines
2.4 KiB
PHP
Raw Normal View History

2021-01-27 19:23:49 +00:00
<?php
include('auth.php');
include('redirect.php');
$old_path = '../uploads/unaudited/';
$new_path = '../uploads/audited/';
$directory = "../uploads/unaudited";
$files = array_diff(scandir($directory), array('..', '.'));
if ((isset($_GET['action'])) && ($_GET['action'] === 'accept_all'))
{
foreach ($files as $file) {
rename($old_path.$file, $new_path.$file);
}
header("Location: /admin/audit.php");
die();
}
// Code written with little too no sleep at 05:16
if ((isset($_GET['action'])) && (isset($_GET['file']))) {
if (file_exists($old_path.$_GET['file'])===false)
{
header("Location: /admin/audit.php");
die('File does not exist');
}
switch ($_GET['action']) {
case 'accept':
// is this safe?
rename($old_path.$_GET['file'], $new_path.$_GET['file']);
break;
case 'delete':
// Enterprise(tm) security
unlink($old_path.$_GET['file']);
break;
default:
die('Action not found');
break;
}
header("Location: /admin/audit.php");
die();
}
?>
<?php include('../../_header.php'); ?>
<h3>Nye bilde forslag</h3>
<p>Totalt: <?=count($files)?></p>
<a href="audit.php?action=accept_all"><button type="button">Godta alt</button></a>
<br>
<br>
<table>
<tr>
<th>Fil</th>
<th>Handling</th>
</tr>
<?php foreach($files as $file): ?>
<tr>
<td><a href="/uploads/unaudited/<?=$file;?>"><img class="img" src="/uploads/unaudited/<?=$file;?>" alt=""></a></td>
<td style="text-align: center;">
<a href="audit.php?action=accept&file=<?=$file;?>">Godta</a>
<br>
<br>
<br>
<a style="color: red;" href="audit.php?action=delete&file=<?=$file;?>">Avslå</a>
</td>
</tr>
<?php endforeach;?>
</table>
<br>
<a href="audit.php?action=accept_all"><button type="button">Godta alt</button></a>
<style>
table {
border-collapse: collapse;
width: 100%;
}
table, td, th {
border: 1px solid #888;
}
tr:nth-child(even) {background-color: #f2f2f2;}
.img {
margin: auto;
object-fit: contain;
width:100%;
max-height: 600px;
min-height: 150px;
height: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
</style>
<?php include('../../_footer.php'); ?>