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,19 +160,20 @@ 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" >
<input type="text" class="form-control flex-grow-1 mr-2" name="username" placeholder="Benutzername eingeben" > <input type="text" class="form-control flex-grow-1 mr-2" name="username" placeholder="Benutzername eingeben" >
<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>");
@@ -200,7 +201,7 @@ function load_user()
$search=htmlspecialchars($_GET["username"]); $search=htmlspecialchars($_GET["username"]);
else else
$search="user_not_found"; $search="user_not_found";
$sql="SELECT COUNT(*) FROM users WHERE username LIKE '%$search%'"; $sql="SELECT COUNT(*) FROM users WHERE username LIKE '%$search%'";
$stmt = mysqli_prepare($link, $sql); $stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt); mysqli_stmt_execute($stmt);
@@ -280,17 +281,15 @@ 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>
</body> </body>

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;
} }
$username=htmlspecialchars($_SESSION["username"]);
$id=$_SESSION["id"]; // Sanitize session variables
$username = htmlspecialchars($_SESSION["username"]);
$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> <div class="row justify-content-center">
<div class="col-md-auto">
</head> <h1>Log Entries</h1>
<body>
<div class="container m-3"> <!-- Filter Form -->
<div class="row justify-content-center"> <div class="overflow-auto">
<div class="col-md-auto"> <form method="GET" action="">
<h1>Alle Einträge</h1> <table class="table">
<div class="overflow-auto"> <thead>
<table class="table"> <tr>
<thead> <th>Date & Time</th>
<tr> <th>IP Address</th>
<th>Datum & Zeit</th> <th>Type</th>
<th>IP Adresse</th> <th>Username</th>
<th>Typ</th> <th>Info</th>
<th>Benutzername</th> </tr>
<th>Info</th> <tr>
</tr> <td>---</td>
<form method="GET" action="?search=true"> <td>---</td>
<tr> <td>
<td>---</td> <select class="form-select" name="type_">
<td>---</td> <option value="All_types">All Types</option>
<td> <option value="PRINT::UPLOAD::PRINTER">PRINT::UPLOAD::PRINTER</option>
<select class="form-select" name="type_"> <option value="PRINT:JOB:START:FAILED">PRINT:JOB:START:FAILED</option>
<option type_="All_types">All_types</option> <option value="PRINT::UPLOAD::QUEUE">PRINT::UPLOAD::QUEUE</option>
<option type_="PRINT::UPLOAD::PRINTER">PRINT::UPLOAD::PRINTER</option> <option value="PRINT::UPLOAD::FILE::FAILED">PRINT::UPLOAD::FILE::FAILED</option>
<option type_="PRINT:JOB:START:FAILED">PRINT:JOB:START:FAILED</option> <option value="JOB::PRINTERCTRL::FREE">JOB::PRINTERCTRL::FREE</option>
<option type_="PRINT::UPLOAD::QUEUE">PRINT::UPLOAD::QUEUE</option> <option value="JOB::QUEUECTRL::REMOVE">JOB::QUEUECTRL::REMOVE</option>
<option type_="PRINT::UPLOAD::FILE::FAILED">PRINT::UPLOAD::FILE::FAILED</option> <option value="JOB::PRINTERCTRL::CANCEL::FAILED">JOB::PRINTERCTRL::CANCEL::FAILED</option>
<option type_="JOB_INFO::PRINTERCTRL::FREE">JOB::PRINTERCTRL::FREE</option> <option value="JOB::PRINTERCTRL::CANCEL">JOB::PRINTERCTRL::CANCEL</option>
<option type_="JOB_INFO::QUEUECTRL::REMOVE">JOB::QUEUECTRL::REMOVE</option> </select>
<option type_="JOB::PRINTERCTRL::CANCEL::FAILED">JOB::PRINTERCTRL::CANCEL::FAILED</option> </td>
<option type_="JOB::PRINTERCTRL::CANCEL">JOB::PRINTERCTRL::CANCEL</option> <td>
</select> <select class="form-select" id="username" name="username">
</td> <option value="All_usernames">All Users</option>
<td> <?php
<?php //insert all the usernames // Fetch all usernames in one query
$sql = "SELECT username FROM users ORDER BY username ASC";
$stmt = mysqli_prepare($link, $sql);
$cnt=0; mysqli_stmt_execute($stmt);
$sql="SELECT COUNT(*) FROM users"; mysqli_stmt_bind_result($stmt, $uname);
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_execute($stmt); // Populate the dropdown with usernames
while (mysqli_stmt_fetch($stmt)) {
mysqli_stmt_store_result($stmt); echo '<option value="' . htmlspecialchars($uname) . '">' . htmlspecialchars($uname) . '</option>';
mysqli_stmt_bind_result($stmt, $cnt); }
mysqli_stmt_fetch($stmt); mysqli_stmt_close($stmt);
?>
mysqli_stmt_close($stmt); </select>
</td>
echo('<select class="form-select" id="username" name="username">'); <td>
echo('<option username="All_usernames">All_usernames</option>'); <button type="submit" class="btn btn-primary">Apply Filter</button>
//now get those users </td>
$cnt2=1; </tr>
$id=0; </thead>
$last_id=0; <tbody>
while($cnt2!==$cnt+1)
{ <?php
$sql = "SELECT id, username FROM users WHERE id > $last_id ORDER BY id;"; // Define default filters
$stmt = mysqli_prepare($link, $sql); $type_filter = isset($_GET["type_"]) ? $_GET["type_"] : "All_types";
$user_filter = isset($_GET["username"]) ? $_GET["username"] : "All_usernames";
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt); // Pagination variables
mysqli_stmt_bind_result($stmt, $id,$username); $items_per_page = 25;
mysqli_stmt_fetch($stmt); $current_page = isset($_GET['page']) ? intval($_GET['page']) : 1;
$last_id=$id; if ($current_page < 1) {
echo('<option username="'.$username.'">'.$username.'</option>'); $current_page = 1;
mysqli_stmt_close($stmt); }
$cnt2++; $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);
</td><!-- username --> if (count($data) >= 5) {
<td><button type="submit" class="btn btn-primary">Apply filter</button> // Add valid log entries to an array
</tr></form> $log_entries[] = [
<?php 'date' => htmlspecialchars($data[0]),
$fp=fopen("../log/sys0.log","r"); 'ip' => htmlspecialchars($data[1]),
while(!feof($fp)) 'type' => htmlspecialchars($data[2]),
{ 'username' => htmlspecialchars($data[3]),
$content=fgets($fp); 'info' => htmlspecialchars($data[4])
$data=explode(";",$content); ];
if(!feof($fp)) }
{ }
if($data[2]==$_GET["type_"] or $_GET["type_"]=="All_types" or !isset($_GET["type_"])) fclose($fp);
{ }
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>"); // 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) {
fclose($fp); $type_match = ($type_filter === "All_types" || $entry['type'] === $type_filter);
?> $user_match = ($user_filter === "All_usernames" || $entry['username'] === $user_filter);
</tbody> return $type_match && $user_match;
</table> });
</div>
// 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>
</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 id="footer"></div> <div id="footer"></div>
</body> </body>
</html> </html>