From 1028785807230eae8455bc7fa916ca95c3f3899d Mon Sep 17 00:00:00 2001 From: M_Viper Date: Sun, 25 Feb 2024 17:42:29 +0000 Subject: [PATCH] article_overview.php aktualisiert --- article_overview.php | 153 ++++++++++++++++++++++--------------------- 1 file changed, 77 insertions(+), 76 deletions(-) diff --git a/article_overview.php b/article_overview.php index 017f26b..bcbc141 100644 --- a/article_overview.php +++ b/article_overview.php @@ -67,88 +67,89 @@ Aktionen 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 "= 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 "= 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 "= strtotime($ten_days_before_expiry) && strtotime($current_date) <= strtotime($expiration_date)) { - echo " class='expiring'"; // Klasse 'expiring' hinzufügen - } - echo ">"; - - echo "= strtotime($ten_days_before_expiry) && strtotime($current_date) <= strtotime($expiration_date)) { - echo " style='color: red;'"; // Schriftfarbe auf Rot setzen - } - echo ">" . $row["item_name"] . ""; - echo "" . $row["manufacturer"] . ""; - echo "" . $row["location"] . ""; - echo "" . $row["amount_should"] . ""; - echo "" . $row["amount_is"] . ""; - echo "" . $expiration_date . ""; - echo "" . $row["barcode"] . ""; - echo ""; - if (!empty($row["image"])) { - echo "Bild"; - } else { - echo "Standardbild"; - } - echo ""; - echo "Bearbeiten   |   Löschen"; - - echo ""; - // Bearbeitungsformular für jedes Element einfügen - echo " -
- - - - - - - - - -
- "; - } + echo ">" . $row["item_name"] . ""; + echo "" . $row["manufacturer"] . ""; + echo "" . $row["location"] . ""; + echo "" . $row["amount_should"] . ""; + echo "" . $row["amount_is"] . ""; + echo "" . $expiration_date . ""; + echo "" . $row["barcode"] . ""; + echo ""; + if (!empty($row["image"])) { + echo "Bild"; } else { - echo "Keine Artikel gefunden"; + echo "Standardbild"; } - $conn->close(); - ?> + echo ""; + echo "Bearbeiten   |   Löschen"; + + echo ""; + // Bearbeitungsformular für jedes Element einfügen + echo " +
+ + + + + + + + + +
+ "; + } +} else { + echo "Keine Artikel gefunden"; +} +$conn->close(); +?>