article_overview.php aktualisiert

This commit is contained in:
M_Viper 2024-02-25 10:45:14 +00:00
parent ce65437c45
commit 35f9f54dd7
1 changed files with 166 additions and 98 deletions

View File

@ -1,98 +1,166 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="de"> <html lang="de">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="css/style.css"> <link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="icon" href="img/favicon.png" type="image/x-icon"> <link rel="icon" href="img/favicon.png" type="image/x-icon">
<title>Artikelübersicht</title> <title>Artikelübersicht</title>
</head> <style>
<body style="background-color: aliceblue;"> /* Stil für das Bearbeitungsformular */
<header class="header"> .edit-form {
<div class="header-container"> display: none;
<h1>Materialverwaltung</h1> }
<nav>
<ul> /* Mauszeigeränderung, wenn über das Bild gefahren wird */
<li><a href="index.php">Home</a></li> .edit-form img:hover,
<li><a href="add_material_form.php">Artikel hinzufügen</a></li> .edit-form a:hover {
<li><a href="article_overview.php">Artikel Übersicht</a></li> cursor: pointer;
</ul> }
</nav> </style>
</div> </head>
</header> <body style="background-color: aliceblue;">
<header class="header">
<div class="container"> <div class="header-container">
<h2>Artikelübersicht</h2> <h1>Materialverwaltung</h1>
<nav>
<!-- Artikel suchen --> <ul>
<form method="GET" action="article_overview.php" style="margin-bottom: 20px;"> <li><a href="index.php">Home</a></li>
<input type="text" name="search" placeholder="Artikel suchen" size="50"> <!-- Hier das size-Attribut geändert --> <li><a href="add_material_form.php">Artikel hinzufügen</a></li>
<input type="submit" value="Suchen"> <li><a href="article_overview.php">Artikel Übersicht</a></li>
</form> </ul>
</nav>
<!-- Artikel anzeigen --> </div>
<table> </header>
<tr>
<th>Name</th> <div class="container">
<th>Hersteller</th> <h2>Artikelübersicht</h2>
<th>Lagerort</th>
<th>Anzahl soll</th> <!-- Artikel suchen -->
<th>Anzahl ist</th> <form method="GET" action="article_overview.php" style="margin-bottom: 20px;">
<th>Ablaufdatum</th> <input type="text" name="search" placeholder="Artikel suchen" size="50">
<th>Barcode</th> <!-- Hier das size-Attribut geändert -->
<th>Bild</th> <input type="submit" value="Suchen">
<th>Aktion</th> </form>
<th></th> <!-- Neue Zelle für das Löschen-Bild -->
</tr> <!-- Artikel anzeigen -->
<?php <table>
// Datenbankverbindung herstellen <tr>
include_once 'config/config.php'; <th>Name</th>
<th>Hersteller</th>
// Verbindung zur Datenbank herstellen <th>Lagerort</th>
$conn = new mysqli($host, $username, $password, $database); <th>Anzahl soll</th>
if ($conn->connect_error) { <th>Anzahl ist</th>
die("Verbindung zur Datenbank fehlgeschlagen: " . $conn->connect_error); <th>Ablaufdatum</th>
} <th>Barcode</th>
<th>Bild</th>
// SQL-Abfrage vorbereiten <th>Aktionen</th>
$sql = "SELECT * FROM materials"; </tr>
<?php
// Wenn nach einem Artikel gesucht wird // Datenbankverbindung herstellen
if(isset($_GET['search']) && !empty($_GET['search'])){ include_once 'config/config.php';
$search = $_GET['search'];
$sql .= " WHERE item_name LIKE '%" . $search . "%' OR manufacturer LIKE '%" . $search . "%' OR location LIKE '%" . $search . "%' OR barcode LIKE '%" . $search . "%'"; // Verbindung zur Datenbank herstellen
} $conn = new mysqli($host, $username, $password, $database);
if ($conn->connect_error) {
$result = $conn->query($sql); die("Verbindung zur Datenbank fehlgeschlagen: " . $conn->connect_error);
}
if ($result->num_rows > 0) {
// Daten ausgeben // SQL-Abfrage vorbereiten
while($row = $result->fetch_assoc()) { $sql = "SELECT * FROM materials";
echo "<tr>";
echo "<td>" . $row["item_name"] . "</td>"; // Wenn nach einem Artikel gesucht wird
echo "<td>" . $row["manufacturer"] . "</td>"; if(isset($_GET['search']) && !empty($_GET['search'])){
echo "<td>" . $row["location"] . "</td>"; $search = $_GET['search'];
echo "<td>" . $row["amount_should"] . "</td>"; $sql .= " WHERE item_name LIKE '%" . $search . "%' OR manufacturer LIKE '%" . $search . "%' OR location LIKE '%" . $search . "%' OR barcode LIKE '%" . $search . "%'";
echo "<td>" . $row["amount_is"] . "</td>"; }
echo "<td>" . $row["expiration_date"] . "</td>";
echo "<td>" . $row["barcode"] . "</td>"; $result = $conn->query($sql);
echo "<td>";
if (!empty($row["image"])) { if ($result->num_rows > 0) {
echo "<img src='" . $row["image"] . "' alt='Bild' style='width: 50px; height: 50px;'>"; // Daten ausgeben
} else { while($row = $result->fetch_assoc()) {
echo "<img src='img/free.png' alt='Standardbild' style='width: 50px; height: 50px;'>"; $expiration_date = strtotime($row["expiration_date"]);
} $ten_days_before_expiry = strtotime("-10 days", $expiration_date); // 10 Tage vor dem Ablaufdatum
echo "</td>"; $current_date = strtotime(date("Y-m-d")); // Aktuelles Datum
echo "<td><a href='remove_article.php?id=" . $row["id"] . "'><img src='img/delete.png' alt='Löschen' style='width: 20px; height: 20px;'></a></td>";
echo "<td></td>"; // Platzhalter-Zelle für das Löschen-Bild echo "<tr";
echo "</tr>"; if ($current_date >= $ten_days_before_expiry && $current_date <= $expiration_date) {
} echo " class='expiring'";
} else { }
echo "<tr><td colspan='10'>Keine Artikel gefunden</td></tr>"; echo ">";
} echo "<td>" . $row["item_name"] . "</td>";
$conn->close(); echo "<td>" . $row["manufacturer"] . "</td>";
?> echo "<td>" . $row["location"] . "</td>";
</table> echo "<td>" . $row["amount_should"] . "</td>";
</div> echo "<td>" . $row["amount_is"] . "</td>";
</body> echo "<td>" . $row["expiration_date"] . "</td>";
</html> echo "<td>" . $row["barcode"] . "</td>";
echo "<td>";
if (!empty($row["image"])) {
echo "<img src='" . $row["image"] . "' alt='Bild' style='width: 50px; height: 50px;' onclick='toggleEditForm(" . $row["id"] . ")'>";
} else {
echo "<img src='img/free.png' alt='Standardbild' style='width: 50px; height: 50px;' onclick='toggleEditForm(" . $row["id"] . ")'>";
}
echo "</td>";
echo "<td><img src='img/bearbeiten.png' alt='Bearbeiten' style='width: 20px; height: 20px;' onclick='toggleEditForm(" . $row["id"] . ")'> &nbsp; | &nbsp; <a href='remove_article.php?id=" . $row["id"] . "'><img src='img/delete.png' alt='Löschen' style='width: 20px; height: 20px;' ></a></td>";
echo "</tr>";
// Bearbeitungsformular für jedes Element einfügen
echo "<tr class='edit-form' id='edit-form-" . $row["id"] . "'><td colspan='9'>
<form id='form-" . $row["id"] . "' onsubmit='updateItem(event, " . $row["id"] . ")'>
<input type='text' name='name' value='" . $row["item_name"] . "'>
<input type='text' name='manufacturer' value='" . $row["manufacturer"] . "'>
<input type='text' name='location' value='" . $row["location"] . "'>
<input type='number' name='amount_should' value='" . $row["amount_should"] . "'>
<input type='number' name='amount_is' value='" . $row["amount_is"] . "'>
<input type='date' name='expiration_date' value='" . $row["expiration_date"] . "'>
<input type='text' name='barcode' value='" . $row["barcode"] . "'>
<input type='hidden' name='id' value='" . $row["id"] . "'>
<input type='submit' value='Speichern'>
</form>
</td></tr>";
}
} else {
echo "<tr><td colspan='9'>Keine Artikel gefunden</td></tr>";
}
$conn->close();
?>
</table>
</div>
<script>
// JavaScript-Funktion, um das Bearbeitungsformular anzuzeigen oder zu verstecken
function toggleEditForm(id) {
var editForm = document.getElementById("edit-form-" + id);
if (editForm.style.display === "none") {
editForm.style.display = "table-row";
} else {
editForm.style.display = "none";
}
}
// JavaScript-Funktion zur Aktualisierung des Elements mit AJAX
function updateItem(event, id) {
event.preventDefault();
var form = document.getElementById("form-" + id);
var formData = new FormData(form);
// Hinzufügen der ID zum FormData-Objekt
formData.append('id', id);
var xhr = new XMLHttpRequest();
xhr.open("POST", "update_article.php", true);
// Hinzufügen des Headers für die XMLHttpRequest
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.onload = function () {
if (xhr.status === 200) {
console.log(xhr.responseText); // Ausgabe der Serverantwort (zum Debuggen)
// Hier können Sie zusätzliche Aktionen nach dem Speichern durchführen, z.B. die Seite aktualisieren
window.location.reload(); // Seite neu laden, um die Änderungen anzuzeigen
}
};
xhr.send(formData);
}
</script>
</body>
</html>