Implementation of Notification System
This commit is contained in:
@@ -4,6 +4,7 @@ $rootPath = dirname(dirname(__DIR__));
|
||||
require_once($rootPath . "/src/config/env.php");
|
||||
require_once($rootPath . "/src/config/connection.php");
|
||||
require_once($rootPath . "/src/config/functions.php");
|
||||
require_once($rootPath . "/src/helpers/notification_helper.php");
|
||||
|
||||
/**
|
||||
* ==========================================================
|
||||
@@ -272,6 +273,14 @@ if (in_array($normalized, ['PAID', 'SUCCESS', 'COMPLETED', 'SETTLED'], true)) {
|
||||
nl2br($message)
|
||||
);
|
||||
sendAdminNotification($subject, nl2br($message));
|
||||
$event = 'new_payment_received';
|
||||
$sub_feed = 'payments';
|
||||
$data = [
|
||||
'actor_id' => $_SESSION['user_id'] ?? null,
|
||||
'actor_avatar' => $_SESSION['profile_pic'] ?? null, // used by UI to show avatar
|
||||
'title' => "New Payment Received for Payment ID: {$localPaymentId}"
|
||||
];
|
||||
addNotification(null, $event, $sub_feed, $data, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
41
src/api/notifications.php
Normal file
41
src/api/notifications.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
// Ensure environment is loaded before attempting DB connection
|
||||
require_once __DIR__ . '/../config/env.php';
|
||||
require_once __DIR__ . '/../config/connection.php';
|
||||
// helper filename uses singular in this repo: notification_helper.php
|
||||
require_once __DIR__ . '/../helpers/notification_helper.php';
|
||||
session_start();
|
||||
|
||||
$admin_id = $_SESSION['user_id'] ?? null;
|
||||
$action = $_REQUEST['action'] ?? '';
|
||||
|
||||
if ($action === 'fetch') {
|
||||
$subs = getAdminSubscriptions($admin_id);
|
||||
$notes = fetchNotifications($admin_id, $subs, 50);
|
||||
echo json_encode(['success' => true, 'notifications' => $notes, 'unread_count' => getUnreadCount($admin_id, $subs)]);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($action === 'mark_read') {
|
||||
if (!$admin_id) { echo json_encode(['success' => false, 'error' => 'unauthenticated']); exit; }
|
||||
$id = isset($_POST['id']) ? intval($_POST['id']) : 0;
|
||||
if (!$id) { echo json_encode(['success' => false, 'error' => 'missing_id']); exit; }
|
||||
$ok = markNotificationRead($id, $admin_id);
|
||||
echo json_encode(['success' => (bool)$ok]);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($action === 'add') {
|
||||
// internal use: create a notification
|
||||
$target = isset($_POST['user_id']) ? intval($_POST['user_id']) : null;
|
||||
$event = $_POST['event'] ?? '';
|
||||
$sub_feed = $_POST['sub_feed'] ?? null;
|
||||
$data = isset($_POST['data']) ? json_decode($_POST['data'], true) : [];
|
||||
$target_url = $_POST['target_url'] ?? null;
|
||||
$id = addNotification($target, $event, $sub_feed, $data, $target_url);
|
||||
echo json_encode(['success' => (bool)$id, 'id' => $id]);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode(['success' => false, 'error' => 'invalid_action']);
|
||||
Reference in New Issue
Block a user