article_overview.php aktualisiert
This commit is contained in:
parent
ce65437c45
commit
35f9f54dd7
|
@ -4,95 +4,163 @@
|
|||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<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>
|
||||
<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">
|
||||
<div class="header-container">
|
||||
<h1>Materialverwaltung</h1>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href="index.php">Home</a></li>
|
||||
<li><a href="add_material_form.php">Artikel hinzufügen</a></li>
|
||||
<li><a href="article_overview.php">Artikel Übersicht</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<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="submit" value="Suchen">
|
||||
</form>
|
||||
|
||||
<!-- Artikel anzeigen -->
|
||||
<table>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Hersteller</th>
|
||||
<th>Lagerort</th>
|
||||
<th>Anzahl soll</th>
|
||||
<th>Anzahl ist</th>
|
||||
<th>Ablaufdatum</th>
|
||||
<th>Barcode</th>
|
||||
<th>Bild</th>
|
||||
<th>Aktion</th>
|
||||
<th></th> <!-- Neue Zelle für das Löschen-Bild -->
|
||||
</tr>
|
||||
<?php
|
||||
// Datenbankverbindung herstellen
|
||||
include_once 'config/config.php';
|
||||
|
||||
// Verbindung zur Datenbank herstellen
|
||||
$conn = new mysqli($host, $username, $password, $database);
|
||||
if ($conn->connect_error) {
|
||||
die("Verbindung zur Datenbank fehlgeschlagen: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// SQL-Abfrage vorbereiten
|
||||
$sql = "SELECT * FROM materials";
|
||||
|
||||
// Wenn nach einem Artikel gesucht wird
|
||||
if(isset($_GET['search']) && !empty($_GET['search'])){
|
||||
$search = $_GET['search'];
|
||||
$sql .= " WHERE item_name LIKE '%" . $search . "%' OR manufacturer LIKE '%" . $search . "%' OR location LIKE '%" . $search . "%' OR barcode LIKE '%" . $search . "%'";
|
||||
}
|
||||
|
||||
$result = $conn->query($sql);
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
// Daten ausgeben
|
||||
while($row = $result->fetch_assoc()) {
|
||||
echo "<tr>";
|
||||
echo "<td>" . $row["item_name"] . "</td>";
|
||||
echo "<td>" . $row["manufacturer"] . "</td>";
|
||||
echo "<td>" . $row["location"] . "</td>";
|
||||
echo "<td>" . $row["amount_should"] . "</td>";
|
||||
echo "<td>" . $row["amount_is"] . "</td>";
|
||||
echo "<td>" . $row["expiration_date"] . "</td>";
|
||||
echo "<td>" . $row["barcode"] . "</td>";
|
||||
echo "<td>";
|
||||
if (!empty($row["image"])) {
|
||||
echo "<img src='" . $row["image"] . "' alt='Bild' style='width: 50px; height: 50px;'>";
|
||||
} else {
|
||||
echo "<img src='img/free.png' alt='Standardbild' style='width: 50px; height: 50px;'>";
|
||||
}
|
||||
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 "</tr>";
|
||||
}
|
||||
} else {
|
||||
echo "<tr><td colspan='10'>Keine Artikel gefunden</td></tr>";
|
||||
}
|
||||
$conn->close();
|
||||
?>
|
||||
</table>
|
||||
<header class="header">
|
||||
<div class="header-container">
|
||||
<h1>Materialverwaltung</h1>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href="index.php">Home</a></li>
|
||||
<li><a href="add_material_form.php">Artikel hinzufügen</a></li>
|
||||
<li><a href="article_overview.php">Artikel Übersicht</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<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="submit" value="Suchen">
|
||||
</form>
|
||||
|
||||
<!-- Artikel anzeigen -->
|
||||
<table>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Hersteller</th>
|
||||
<th>Lagerort</th>
|
||||
<th>Anzahl soll</th>
|
||||
<th>Anzahl ist</th>
|
||||
<th>Ablaufdatum</th>
|
||||
<th>Barcode</th>
|
||||
<th>Bild</th>
|
||||
<th>Aktionen</th>
|
||||
</tr>
|
||||
<?php
|
||||
// Datenbankverbindung herstellen
|
||||
include_once 'config/config.php';
|
||||
|
||||
// Verbindung zur Datenbank herstellen
|
||||
$conn = new mysqli($host, $username, $password, $database);
|
||||
if ($conn->connect_error) {
|
||||
die("Verbindung zur Datenbank fehlgeschlagen: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// SQL-Abfrage vorbereiten
|
||||
$sql = "SELECT * FROM materials";
|
||||
|
||||
// Wenn nach einem Artikel gesucht wird
|
||||
if(isset($_GET['search']) && !empty($_GET['search'])){
|
||||
$search = $_GET['search'];
|
||||
$sql .= " WHERE item_name LIKE '%" . $search . "%' OR manufacturer LIKE '%" . $search . "%' OR location LIKE '%" . $search . "%' OR barcode LIKE '%" . $search . "%'";
|
||||
}
|
||||
|
||||
$result = $conn->query($sql);
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
// Daten ausgeben
|
||||
while($row = $result->fetch_assoc()) {
|
||||
$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>";
|
||||
echo "<td>" . $row["amount_should"] . "</td>";
|
||||
echo "<td>" . $row["amount_is"] . "</td>";
|
||||
echo "<td>" . $row["expiration_date"] . "</td>";
|
||||
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"] . ")'> | <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>
|
||||
|
|
Loading…
Reference in New Issue