33 lines
1.2 KiB
PHP
33 lines
1.2 KiB
PHP
<?php
|
|
require_once __DIR__ . '/PushHelper.php';
|
|
|
|
/**
|
|
* Helper function to send a notification to the database.
|
|
*
|
|
* @param PDO $pdo The PDO connection object
|
|
* @param string $icon The MDI icon class (e.g., 'mdi-alert-circle')
|
|
* @param string $title The title of the notification
|
|
* @param string $message A short message/description
|
|
* @param string $detail Detailed information for the modal
|
|
* @param bool $is_danger Whether it's a danger/warning notification (default: false)
|
|
* @return bool True on success, false on failure
|
|
*/
|
|
function send_notification($pdo, $icon, $title, $message, $detail, $is_danger = false) {
|
|
try {
|
|
$stmt = $pdo->prepare("INSERT INTO notifications (icon, title, message, detail, is_danger) VALUES (?, ?, ?, ?, ?)");
|
|
$dangerVal = $is_danger ? 1 : 0;
|
|
$result = $stmt->execute([$icon, $title, $message, $detail, $dangerVal]);
|
|
|
|
if ($result) {
|
|
// Send push notification to all admins
|
|
PushHelper::broadcastToAdmins($pdo, $title, $message);
|
|
}
|
|
|
|
return $result;
|
|
} catch(PDOException $e) {
|
|
error_log("Notification Error: " . $e->getMessage());
|
|
return false;
|
|
}
|
|
}
|
|
?>
|