Messenger-artiges Benachrichtigungssystem für Dolibarr: - Schwebendes FAB (Floating Action Button) unten links - Ausklappbares Panel mit allen Benachrichtigungen - Historie der gelesenen Nachrichten - Direktes Abhaken per Checkbox - Click-to-Navigate für Aktionen - Pulsierender Button bei dringenden Nachrichten - Draggable Panel-Header - Automatische Erkennung hängender Cron-Jobs - API für andere Module: GlobalNotify::error(), ::warning(), etc. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
110 lines
2.6 KiB
PHP
110 lines
2.6 KiB
PHP
<?php
|
|
/* Copyright (C) 2026 Eduard Wisch <data@data-it-solution.de>
|
|
*
|
|
* AJAX handler for GlobalNotify module
|
|
*/
|
|
|
|
if (!defined('NOTOKENRENEWAL')) {
|
|
define('NOTOKENRENEWAL', '1');
|
|
}
|
|
if (!defined('NOREQUIREMENU')) {
|
|
define('NOREQUIREMENU', '1');
|
|
}
|
|
if (!defined('NOREQUIREHTML')) {
|
|
define('NOREQUIREHTML', '1');
|
|
}
|
|
if (!defined('NOREQUIREAJAX')) {
|
|
define('NOREQUIREAJAX', '1');
|
|
}
|
|
|
|
// Load Dolibarr environment
|
|
$res = 0;
|
|
if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
|
|
$res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
|
|
}
|
|
$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
|
|
$tmp2 = realpath(__FILE__);
|
|
$i = strlen($tmp) - 1;
|
|
$j = strlen($tmp2) - 1;
|
|
while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
|
|
$i--;
|
|
$j--;
|
|
}
|
|
if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
|
|
$res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
|
|
}
|
|
if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
|
|
$res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
|
|
}
|
|
if (!$res && file_exists("../../main.inc.php")) {
|
|
$res = @include "../../main.inc.php";
|
|
}
|
|
if (!$res && file_exists("../../../main.inc.php")) {
|
|
$res = @include "../../../main.inc.php";
|
|
}
|
|
if (!$res) {
|
|
die("Include of main fails");
|
|
}
|
|
|
|
dol_include_once('/globalnotify/class/globalnotify.class.php');
|
|
|
|
/**
|
|
* @var User $user
|
|
* @var DoliDB $db
|
|
*/
|
|
|
|
// Security check
|
|
if (!$user->admin) {
|
|
http_response_code(403);
|
|
echo json_encode(array('success' => false, 'error' => 'Access denied'));
|
|
exit;
|
|
}
|
|
|
|
$action = GETPOST('action', 'aZ09');
|
|
$id = GETPOST('id', 'alphanohtml');
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
$notify = new GlobalNotify($db);
|
|
$response = array('success' => false);
|
|
|
|
switch ($action) {
|
|
case 'dismiss':
|
|
if (!empty($id)) {
|
|
$result = $notify->markAsRead($id);
|
|
$response['success'] = $result;
|
|
}
|
|
break;
|
|
|
|
case 'delete':
|
|
if (!empty($id)) {
|
|
$result = $notify->deleteNotification($id);
|
|
$response['success'] = $result;
|
|
}
|
|
break;
|
|
|
|
case 'markallread':
|
|
$count = $notify->markAllAsRead();
|
|
$response['success'] = true;
|
|
$response['count'] = $count;
|
|
break;
|
|
|
|
case 'getall':
|
|
$notifications = $notify->getAllNotifications($user->id, true);
|
|
$response['success'] = true;
|
|
$response['notifications'] = $notifications;
|
|
$response['count'] = count($notifications);
|
|
// Could also return rendered HTML here if needed
|
|
break;
|
|
|
|
case 'getcount':
|
|
$count = $notify->getUnreadCount();
|
|
$response['success'] = true;
|
|
$response['count'] = $count;
|
|
break;
|
|
|
|
default:
|
|
$response['error'] = 'Unknown action';
|
|
}
|
|
|
|
echo json_encode($response);
|