From d2295a6328e38479fad1d3cf994a9a3f6c57c0a3 Mon Sep 17 00:00:00 2001 From: kapsona777 Date: Mon, 28 Oct 2024 01:17:00 +0400 Subject: [PATCH] Added full logic of notifications. --- public/userarea/apilogic/process_import.php | 2 + .../userarea/importify/interventionlist.php | 3 +- .../userarea/include/checkNotifications.php | 35 +++ public/userarea/include/getNotifications.php | 92 ++++++ public/userarea/include/navigationbar.php | 8 +- public/userarea/include/topbar.php | 272 +++++++++++++++--- .../userarea/notifications/notifications.php | 205 +++++++++++++ 7 files changed, 576 insertions(+), 41 deletions(-) create mode 100644 public/userarea/include/checkNotifications.php create mode 100644 public/userarea/include/getNotifications.php create mode 100644 public/userarea/notifications/notifications.php diff --git a/public/userarea/apilogic/process_import.php b/public/userarea/apilogic/process_import.php index 9725991..03c6c0f 100644 --- a/public/userarea/apilogic/process_import.php +++ b/public/userarea/apilogic/process_import.php @@ -415,4 +415,6 @@ function markForIntervention($id, $pdo) $query = "UPDATE temp_json_queue SET processed = 2 WHERE id = :id"; $stmt = $pdo->prepare($query); $stmt->execute(['id' => $id]); + + $query = "INSERT INTO notifications (`title`,`description`) VALUES ('Intervention Required', 'Intervention required for JSON entry with ID $id')"; } diff --git a/public/userarea/importify/interventionlist.php b/public/userarea/importify/interventionlist.php index 775b8fe..f7fc458 100644 --- a/public/userarea/importify/interventionlist.php +++ b/public/userarea/importify/interventionlist.php @@ -130,7 +130,8 @@ - + +
+ +
+ + + + + + + + + \ No newline at end of file diff --git a/public/userarea/notifications/notifications.php b/public/userarea/notifications/notifications.php new file mode 100644 index 0000000..62d8ea5 --- /dev/null +++ b/public/userarea/notifications/notifications.php @@ -0,0 +1,205 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+ + + +
+
+
+
+
+

Notifications

+
+
+
+ +
+
+
+
+
Records
+
+ + + + + + + + + + + connect_error) { + die("Connection failed: " . $conn->connect_error); + } + + // Query for rows with processed = 2 + $sql = "SELECT * FROM notifications"; + $result = $conn->query($sql); + + $all_notifications = []; + if ($result->num_rows > 0) { + while ($row = $result->fetch_assoc()) { + $all_notifications[] = $row; + } + } + + $user_id = $_SESSION['iduserlogin']; + $all_notification_ids = array_column($all_notifications, 'id'); + $all_notification_ids_str = implode(',', $all_notification_ids); + + $sql = "SELECT notification_id + FROM seen_notifications + WHERE notification_id IN ($all_notification_ids_str) + AND user_id = $user_id"; + $result = $conn->query($sql); + $seen_notification_ids = []; + if ($result->num_rows > 0) { + while ($row = $result->fetch_assoc()) { + $seen_notification_ids[] = $row['notification_id']; + } + } + + $seen_notifications = []; + foreach($all_notifications as $notification){ + if(in_array($notification['id'], $seen_notification_ids)){ + $seen_notifications[] = $notification; + } + } + + $unseen_notifications = array_udiff($all_notifications, $seen_notifications, function ($a, $b) { + return $a['id'] <=> $b['id']; + }); + + + // unseen notifications with mark as seen button and different color , seen without that + if(!empty($all_notifications)){ + foreach($all_notifications as $notification){ + if(in_array($notification, $unseen_notifications)){ + echo ""; + }else{ + echo ""; + } + echo ""; + echo ""; + echo ""; + if(in_array($notification, $unseen_notifications)){ + echo ""; + }else{ + echo ""; + } + echo ""; + } + } + + $conn->close(); + ?> + +
IDTitleDescriptionActions
" . $notification['id'] . "" . $notification['title'] . "" . $notification['description'] . " + +
+
+
+
+
+
+ +
+
+
+ + +
+
+ + + + + + + + + \ No newline at end of file