From eafac54731955a0b14b71eba2b9d1385c7a0cc1c Mon Sep 17 00:00:00 2001 From: M_Viper Date: Wed, 28 Feb 2024 19:02:06 +0000 Subject: [PATCH] article_overview.php aktualisiert --- article_overview.php | 49 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/article_overview.php b/article_overview.php index 18a92ec..48783b2 100644 --- a/article_overview.php +++ b/article_overview.php @@ -38,6 +38,7 @@
  • Home
  • Artikel hinzufügen
  • Artikel Übersicht
  • +
  • chrome Erweiterung
  • Backup
  • @@ -63,6 +64,7 @@ Anzahl soll Anzahl ist Ablaufdatum + Benachrichtigungstage Barcode Bild Aktionen @@ -123,6 +125,7 @@ } echo ">" . $row["amount_is"] . ""; echo "" . $expiration_date . ""; + echo "" . $notification_days . ""; echo "" . $row["barcode"] . ""; echo ""; if (!empty($row["image"])) { @@ -143,6 +146,7 @@ + @@ -202,7 +206,50 @@ return confirm("Möchten Sie diesen Artikel wirklich löschen?"); } - + // Überprüfen, ob der Browser die Notification API unterstützt + if ("Notification" in window) { + // Überprüfen, ob der Benutzer Berechtigung für Benachrichtigungen erteilt hat + if (Notification.permission === "granted") { + // Funktion zum Erstellen einer Benachrichtigung + function createNotification(title, options) { + new Notification(title, options); + } + } else if (Notification.permission !== "denied") { + // Aufforderung an den Benutzer, um Berechtigung für Benachrichtigungen zu bitten + Notification.requestPermission().then(function (permission) { + if (permission === "granted") { + function createNotification(title, options) { + new Notification(title, options); + } + } + }); + } + } + + // Überprüfung, ob das Ablaufdatum innerhalb von x Tagen liegt und eine Benachrichtigung senden + function checkExpiryDate(expirationDate, notificationDays, itemName) { + var tenDaysBeforeExpiry = new Date(expirationDate); + tenDaysBeforeExpiry.setDate(tenDaysBeforeExpiry.getDate() - notificationDays); + var currentDate = new Date(); + + if (currentDate >= tenDaysBeforeExpiry && currentDate <= new Date(expirationDate)) { + var options = { + body: "Das Ablaufdatum von " + itemName + " liegt in " + notificationDays + " Tagen an.", + icon: "icon.png" // Hier das Bild für die Benachrichtigung ändern + }; + createNotification("Ablaufdatum nahe", options); + } + } + + // Aufrufen der Funktion für jedes Element in der Tabelle + var rows = document.getElementsByClassName("expiring"); + for (var i = 0; i < rows.length; i++) { + var cells = rows[i].getElementsByTagName("td"); + var expirationDate = cells[5].innerText; // Das 6. td-Element enthält das Ablaufdatum + var notificationDays = parseInt(cells[6].innerText); // Das 7. td-Element enthält die Benachrichtigungstage + var itemName = cells[0].innerText; // Das 1. td-Element enthält den Artikelnamen + checkExpiryDate(expirationDate, notificationDays, itemName); + } © copyright 2024 by M_Viper