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

@ -6,9 +6,21 @@
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="icon" href="img/favicon.png" type="image/x-icon">
<title>Artikelübersicht</title>
<style>
/* Stil für das Bearbeitungsformular */
.edit-form {
display: none;
}
/* Mauszeigeränderung, wenn über das Bild gefahren wird */
.edit-form img:hover,
.edit-form a:hover {
cursor: pointer;
}
</style>
</head>
<body style="background-color: aliceblue;">
<header class="header">
<header class="header">
<div class="header-container">
<h1>Materialverwaltung</h1>
<nav>
@ -19,14 +31,15 @@
</ul>
</nav>
</div>
</header>
</header>
<div class="container">
<div class="container">
<h2>Artikelübersicht</h2>
<!-- Artikel suchen -->
<form method="GET" action="article_overview.php" style="margin-bottom: 20px;">
<input type="text" name="search" placeholder="Artikel suchen" size="50"> <!-- Hier das size-Attribut geändert -->
<input type="text" name="search" placeholder="Artikel suchen" size="50">
<!-- Hier das size-Attribut geändert -->
<input type="submit" value="Suchen">
</form>
@ -41,8 +54,7 @@
<th>Ablaufdatum</th>
<th>Barcode</th>
<th>Bild</th>
<th>Aktion</th>
<th></th> <!-- Neue Zelle für das Löschen-Bild -->
<th>Aktionen</th>
</tr>
<?php
// Datenbankverbindung herstellen
@ -68,7 +80,15 @@
if ($result->num_rows > 0) {
// Daten ausgeben
while($row = $result->fetch_assoc()) {
echo "<tr>";
$expiration_date = strtotime($row["expiration_date"]);
$ten_days_before_expiry = strtotime("-10 days", $expiration_date); // 10 Tage vor dem Ablaufdatum
$current_date = strtotime(date("Y-m-d")); // Aktuelles Datum
echo "<tr";
if ($current_date >= $ten_days_before_expiry && $current_date <= $expiration_date) {
echo " class='expiring'";
}
echo ">";
echo "<td>" . $row["item_name"] . "</td>";
echo "<td>" . $row["manufacturer"] . "</td>";
echo "<td>" . $row["location"] . "</td>";
@ -78,21 +98,69 @@
echo "<td>" . $row["barcode"] . "</td>";
echo "<td>";
if (!empty($row["image"])) {
echo "<img src='" . $row["image"] . "' alt='Bild' style='width: 50px; height: 50px;'>";
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;'>";
echo "<img src='img/free.png' alt='Standardbild' style='width: 50px; height: 50px;' onclick='toggleEditForm(" . $row["id"] . ")'>";
}
echo "</td>";
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 "<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='10'>Keine Artikel gefunden</td></tr>";
echo "<tr><td colspan='9'>Keine Artikel gefunden</td></tr>";
}
$conn->close();
?>
</table>
</div>
</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>