";
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);
+ }