From db621a97fa1a84e2ffcdda7457163a5f4ec1e763 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Wed, 6 Nov 2024 18:58:45 -0500 Subject: [PATCH] FEATURE: appNotify Function added so each user can get their own notificaiton and can individually dismiss and see their own notifications, only works under invoice viewed right now --- functions.php | 12 ++++++++++++ guest_view_invoice.php | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/functions.php b/functions.php index fadf6ba2..b10073eb 100644 --- a/functions.php +++ b/functions.php @@ -1319,3 +1319,15 @@ function customAction($trigger, $entity) { include_once __DIR__ . "/xcustom/xcustom_action_handler.php"; } } + +function appNotify($notification_type, $notification_details, $notification_action, $notification_client_id, $entity_id) { + global $mysqli; + + $sql = mysqli_query($mysqli, "SELECT user_id FROM users WHERE user_type = 1 AND user_status = 1 AND user_archived_at IS NULL"); + + while ($row = mysqli_fetch_array($sql)) { + $user_id = intval($row['user_id']); + + mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = '$notification_type', notification = '$notification_details', notification_action = '$notification_action', notification_client_id = $notification_client_id, notification_entity_id = $entity_id, notification_user_id = $user_id"); + } +} \ No newline at end of file diff --git a/guest_view_invoice.php b/guest_view_invoice.php index c4780478..425d9869 100644 --- a/guest_view_invoice.php +++ b/guest_view_invoice.php @@ -100,7 +100,10 @@ mysqli_query($mysqli, "INSERT INTO history SET history_status = '$invoice_status if ($invoice_status !== 'Paid') { //$client_name_escaped = sanitizeInput($row['client_name']); - mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Invoice Viewed', notification = 'Invoice $invoice_prefix$invoice_number has been viewed by $client_name_escaped - $ip - $os - $browser', notification_action = 'invoice.php?invoice_id=$invoice_id', notification_client_id = $client_id, notification_entity_id = $invoice_id"); + + appNotify("Invoice Viewed", "Invoice $invoice_prefix$invoice_number has been viewed by $client_name_escaped - $ip - $os - $browser", "invoice.php?invoice_id=$invoice_id", $client_id, $invoice_id); + + //mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Invoice Viewed', notification = 'Invoice $invoice_prefix$invoice_number has been viewed by $client_name_escaped - $ip - $os - $browser', notification_action = 'invoice.php?invoice_id=$invoice_id', notification_client_id = $client_id, notification_entity_id = $invoice_id"); } $sql_payments = mysqli_query($mysqli, "SELECT * FROM payments, accounts WHERE payment_account_id = account_id AND payment_invoice_id = $invoice_id ORDER BY payments.payment_id DESC");