fixing some layout bugs

This commit is contained in:
Janis Steiner
2024-09-20 17:40:56 +01:00
parent 71c7f6015d
commit a916da9a82
2 changed files with 182 additions and 134 deletions

View File

@@ -160,9 +160,9 @@ function load_user()
?> ?>
<div class="container" style="min-height:95vh"> <div class="container" style="min-height:95vh; min-width:100%">
<div class="row"> <div class="row">
<div class="col-mt-12"> <div class="col-mt-12" style="overflow-x:auto">
<div class="d-flex flex-column align-items-center"> <div class="d-flex flex-column align-items-center">
<h4>Nach Benutzer suchen, um zu verwalten</h4> <h4>Nach Benutzer suchen, um zu verwalten</h4>
<form action="manage_user.php" method="GET" > <form action="manage_user.php" method="GET" >
@@ -170,9 +170,10 @@ function load_user()
<button type="submit" class="btn btn-primary">Suchen</button> <button type="submit" class="btn btn-primary">Suchen</button>
</form> </form>
</div> </div>
<!-- list users and their permissions --> <!-- list users and their permissions -->
<?php <?php
echo("<table class='table'>"); echo("<table class='table' style='overflow-x: auto'>");
echo("<thead>"); echo("<thead>");
echo("<tr>"); echo("<tr>");
echo("<td>Nutzer</td>"); echo("<td>Nutzer</td>");
@@ -280,15 +281,13 @@ function load_user()
$last_id=$tid; $last_id=$tid;
$cnt--; $cnt--;
} }
echo("</tr>"); // echo("</tr>");
echo("</tbody>"); echo("</tbody>");
echo("</table>"); echo("</table>");
mysqli_close($link); mysqli_close($link);
?> ?>
</div
</div> </div>
</div> </div>
</div> </div>
<div id="footer"></div> <div id="footer"></div>

View File

@@ -1,142 +1,191 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Log Viewer</title>
<script src="/assets/js/load_page.js"></script>
</head>
<?php <?php
// Initialize the session // Initialize the session and include session checks (unchanged)
session_start(); session_start();
include "../config/config.php"; include "../config/config.php";
// Check if the user is logged in, if not then redirect him to login page
if (!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true || $_SESSION["role"][6] !== "1") { if (!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true || $_SESSION["role"][6] !== "1") {
header("location: /login/login.php"); header("location: /login/login.php");
exit; exit;
} }
// Sanitize session variables
$username = htmlspecialchars($_SESSION["username"]); $username = htmlspecialchars($_SESSION["username"]);
$id=$_SESSION["id"]; $id = intval($_SESSION["id"]);
$color = htmlspecialchars($_SESSION["color"]);
include "../assets/components.php";
?> ?>
<script src="/assets/js/load_page.js"></script>
<script> <script>
function load_user() // Load user content with AJAX
{
$(document).ready(function () { $(document).ready(function () {
$('#content').load("/assets/php/user_page.php"); $('#content').load("/assets/php/user_page.php");
}); });
}
</script> </script>
<?php
$role=$_SESSION["role"]; <body style="background-color: <?= $color ?>;">
echo "<script type='text/javascript' >load_user()</script>";
?>
<?php
$color=$_SESSION["color"];
include "../assets/components.php";
?>
<?php echo(" <body style='background-color:$color'> ");?>
<div id="content"></div> <div id="content"></div>
<head> <div class="container m-3" style="min-height:95vh">
<title>Log viewer</title>
</head>
<body>
<div class="container m-3">
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-md-auto"> <div class="col-md-auto">
<h1>Alle Einträge</h1> <h1>Log Entries</h1>
<!-- Filter Form -->
<div class="overflow-auto"> <div class="overflow-auto">
<form method="GET" action="">
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
<th>Datum & Zeit</th> <th>Date & Time</th>
<th>IP Adresse</th> <th>IP Address</th>
<th>Typ</th> <th>Type</th>
<th>Benutzername</th> <th>Username</th>
<th>Info</th> <th>Info</th>
</tr> </tr>
<form method="GET" action="?search=true">
<tr> <tr>
<td>---</td> <td>---</td>
<td>---</td> <td>---</td>
<td> <td>
<select class="form-select" name="type_"> <select class="form-select" name="type_">
<option type_="All_types">All_types</option> <option value="All_types">All Types</option>
<option type_="PRINT::UPLOAD::PRINTER">PRINT::UPLOAD::PRINTER</option> <option value="PRINT::UPLOAD::PRINTER">PRINT::UPLOAD::PRINTER</option>
<option type_="PRINT:JOB:START:FAILED">PRINT:JOB:START:FAILED</option> <option value="PRINT:JOB:START:FAILED">PRINT:JOB:START:FAILED</option>
<option type_="PRINT::UPLOAD::QUEUE">PRINT::UPLOAD::QUEUE</option> <option value="PRINT::UPLOAD::QUEUE">PRINT::UPLOAD::QUEUE</option>
<option type_="PRINT::UPLOAD::FILE::FAILED">PRINT::UPLOAD::FILE::FAILED</option> <option value="PRINT::UPLOAD::FILE::FAILED">PRINT::UPLOAD::FILE::FAILED</option>
<option type_="JOB_INFO::PRINTERCTRL::FREE">JOB::PRINTERCTRL::FREE</option> <option value="JOB::PRINTERCTRL::FREE">JOB::PRINTERCTRL::FREE</option>
<option type_="JOB_INFO::QUEUECTRL::REMOVE">JOB::QUEUECTRL::REMOVE</option> <option value="JOB::QUEUECTRL::REMOVE">JOB::QUEUECTRL::REMOVE</option>
<option type_="JOB::PRINTERCTRL::CANCEL::FAILED">JOB::PRINTERCTRL::CANCEL::FAILED</option> <option value="JOB::PRINTERCTRL::CANCEL::FAILED">JOB::PRINTERCTRL::CANCEL::FAILED</option>
<option type_="JOB::PRINTERCTRL::CANCEL">JOB::PRINTERCTRL::CANCEL</option> <option value="JOB::PRINTERCTRL::CANCEL">JOB::PRINTERCTRL::CANCEL</option>
</select> </select>
</td> </td>
<td> <td>
<?php //insert all the usernames <select class="form-select" id="username" name="username">
<option value="All_usernames">All Users</option>
$cnt=0;
$sql="SELECT COUNT(*) FROM users";
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
mysqli_stmt_bind_result($stmt, $cnt);
mysqli_stmt_fetch($stmt);
mysqli_stmt_close($stmt);
echo('<select class="form-select" id="username" name="username">');
echo('<option username="All_usernames">All_usernames</option>');
//now get those users
$cnt2=1;
$id=0;
$last_id=0;
while($cnt2!==$cnt+1)
{
$sql = "SELECT id, username FROM users WHERE id > $last_id ORDER BY id;";
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
mysqli_stmt_bind_result($stmt, $id,$username);
mysqli_stmt_fetch($stmt);
$last_id=$id;
echo('<option username="'.$username.'">'.$username.'</option>');
mysqli_stmt_close($stmt);
$cnt2++;
}
?>
</td><!-- username -->
<td><button type="submit" class="btn btn-primary">Apply filter</button>
</tr></form>
<?php <?php
$fp=fopen("../log/sys0.log","r"); // Fetch all usernames in one query
while(!feof($fp)) $sql = "SELECT username FROM users ORDER BY username ASC";
{ $stmt = mysqli_prepare($link, $sql);
$content=fgets($fp); mysqli_stmt_execute($stmt);
$data=explode(";",$content); mysqli_stmt_bind_result($stmt, $uname);
if(!feof($fp))
{
if($data[2]==$_GET["type_"] or $_GET["type_"]=="All_types" or !isset($_GET["type_"]))
{
if($data[3]==$_GET["username"] or $_GET["username"]=="All_usernames" or !isset($_GET["username"]))
echo("<tr><td>".$data[0]."</td><td>".$data[1]."</td><td>".$data[2]."</td><td>".$data[3]."</td><td>".$data[4]."</td></tr>");
}
}
// Populate the dropdown with usernames
while (mysqli_stmt_fetch($stmt)) {
echo '<option value="' . htmlspecialchars($uname) . '">' . htmlspecialchars($uname) . '</option>';
}
mysqli_stmt_close($stmt);
?>
</select>
</td>
<td>
<button type="submit" class="btn btn-primary">Apply Filter</button>
</td>
</tr>
</thead>
<tbody>
<?php
// Define default filters
$type_filter = isset($_GET["type_"]) ? $_GET["type_"] : "All_types";
$user_filter = isset($_GET["username"]) ? $_GET["username"] : "All_usernames";
// Pagination variables
$items_per_page = 25;
$current_page = isset($_GET['page']) ? intval($_GET['page']) : 1;
if ($current_page < 1) {
$current_page = 1;
}
$offset = ($current_page - 1) * $items_per_page;
// Read and process the log file
$log_entries = [];
if ($fp = fopen("../log/sys0.log", "r")) {
while (($line = fgets($fp)) !== false) {
$data = explode(";", $line);
if (count($data) >= 5) {
// Add valid log entries to an array
$log_entries[] = [
'date' => htmlspecialchars($data[0]),
'ip' => htmlspecialchars($data[1]),
'type' => htmlspecialchars($data[2]),
'username' => htmlspecialchars($data[3]),
'info' => htmlspecialchars($data[4])
];
}
} }
fclose($fp); fclose($fp);
}
// Reverse the log entries to display the latest first
$log_entries = array_reverse($log_entries);
// Filter log entries by type and username
$filtered_entries = array_filter($log_entries, function ($entry) use ($type_filter, $user_filter) {
$type_match = ($type_filter === "All_types" || $entry['type'] === $type_filter);
$user_match = ($user_filter === "All_usernames" || $entry['username'] === $user_filter);
return $type_match && $user_match;
});
// Calculate total pages and slice the log entries for the current page
$total_entries = count($filtered_entries);
$total_pages = ceil($total_entries / $items_per_page);
$paged_entries = array_slice($filtered_entries, $offset, $items_per_page);
// Display the filtered entries for the current page
foreach ($paged_entries as $entry) {
echo "<tr>
<td>{$entry['date']}</td>
<td>{$entry['ip']}</td>
<td>{$entry['type']}</td>
<td>{$entry['username']}</td>
<td>{$entry['info']}</td>
</tr>";
}
if (empty($paged_entries)) {
echo "<tr><td colspan='5'>No log entries found.</td></tr>";
}
?> ?>
</tbody> </tbody>
</table> </table>
</form>
<!-- Pagination Controls -->
<nav aria-label="Page navigation">
<ul class="pagination justify-content-center">
<?php if ($current_page > 1): ?>
<li class="page-item">
<a class="page-link" href="?page=<?= $current_page - 1 ?>&type_=<?= urlencode($type_filter) ?>&username=<?= urlencode($user_filter) ?>">Previous</a>
</li>
<?php endif; ?>
<?php for ($page = 1; $page <= $total_pages; $page++): ?>
<li class="page-item <?= ($page === $current_page) ? 'active' : '' ?>">
<a class="page-link" href="?page=<?= $page ?>&type_=<?= urlencode($type_filter) ?>&username=<?= urlencode($user_filter) ?>"><?= $page ?></a>
</li>
<?php endfor; ?>
<?php if ($current_page < $total_pages): ?>
<li class="page-item">
<a class="page-link" href="?page=<?= $current_page + 1 ?>&type_=<?= urlencode($type_filter) ?>&username=<?= urlencode($user_filter) ?>">Next</a>
</li>
<?php endif; ?>
</ul>
</nav>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div id="footer"></div> <div id="footer"></div>
</body> </body>
</html> </html>