article_overview.php aktualisiert

This commit is contained in:
M_Viper 2024-02-25 17:42:29 +00:00
parent 76d1d4ce71
commit 1028785807
1 changed files with 77 additions and 76 deletions

View File

@ -67,88 +67,89 @@
<th>Aktionen</th>
</tr>
<?php
// Datenbankverbindung herstellen
include_once 'config/config.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);
// 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 = date("d.m.Y", strtotime($row["expiration_date"]));
$notification_days = intval($row["notification_days"]); // Tage vor dem Ablaufdatum aus der Datenbank lesen
$ten_days_before_expiry = date("d.m.Y", strtotime("-" . $notification_days . " days", strtotime($row["expiration_date"]))); // Tage vor dem Ablaufdatum berechnen
$current_date = date("d.m.Y"); // Aktuelles Datum
echo "<tr";
if (strtotime($current_date) >= strtotime($ten_days_before_expiry) && strtotime($current_date) <= strtotime($expiration_date)) {
echo " class='expiring'"; // Klasse 'expiring' hinzufügen
}
echo ">";
// 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 . "%'";
echo "<td";
if (strtotime($current_date) >= strtotime($ten_days_before_expiry) && strtotime($current_date) <= strtotime($expiration_date)) {
echo " style='color: red;'"; // Schriftfarbe auf Rot setzen
}
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// Daten ausgeben
while($row = $result->fetch_assoc()) {
$expiration_date = date("d.m.Y", strtotime($row["expiration_date"]));
$ten_days_before_expiry = date("d.m.Y", strtotime("-10 days", strtotime($row["expiration_date"]))); // 10 Tage vor dem Ablaufdatum
$current_date = date("d.m.Y"); // Aktuelles Datum
echo "<tr";
if (strtotime($current_date) >= strtotime($ten_days_before_expiry) && strtotime($current_date) <= strtotime($expiration_date)) {
echo " class='expiring'"; // Klasse 'expiring' hinzufügen
}
echo ">";
echo "<td";
if (strtotime($current_date) >= strtotime($ten_days_before_expiry) && strtotime($current_date) <= strtotime($expiration_date)) {
echo " style='color: red;'"; // Schriftfarbe auf Rot setzen
}
echo ">" . $row["item_name"] . "</td>";
echo "<td>" . $row["manufacturer"] . "</td>";
echo "<td>" . $row["location"] . "</td>";
echo "<td>" . $row["amount_should"] . "</td>";
echo "<td";
if ($row["amount_is"] < $row["amount_should"]) {
echo " class='low-stock'";
}
echo ">" . $row["amount_is"] . "</td>";
echo "<td>" . $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"] . ")'> &nbsp; | &nbsp; <a href='remove_article.php?id=" . $row["id"] . "' onclick='return confirmDelete();'><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>";
}
echo ">" . $row["item_name"] . "</td>";
echo "<td>" . $row["manufacturer"] . "</td>";
echo "<td>" . $row["location"] . "</td>";
echo "<td>" . $row["amount_should"] . "</td>";
echo "<td";
if ($row["amount_is"] < $row["amount_should"]) {
echo " class='low-stock'";
}
echo ">" . $row["amount_is"] . "</td>";
echo "<td>" . $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 "<tr><td colspan='9'>Keine Artikel gefunden</td></tr>";
echo "<img src='img/free.png' alt='Standardbild' style='width: 50px; height: 50px;' onclick='toggleEditForm(" . $row["id"] . ")'>";
}
$conn->close();
?>
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"] . "' onclick='return confirmDelete();'><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>