_prefix . 'csrf_token'] ?? '';
$adminId = (int)($_SESSION['etchat_' . $this->_prefix . 'user_id'] ?? 0);
?>
const ADMIN_ID = {$adminId};
function getMessageType() {
if (document.getElementById('message_type_standard').checked) return 'standard';
if (document.getElementById('message_type_general').checked) return 'general';
if (document.getElementById('message_type_welcome').checked) return 'welcome';
return 'standard';
}
function sendMessageOnly() {
sendBroadcast(true);
}
function sendBroadcastHard() {
sendBroadcast(false, true);
}
function sendBroadcast(noReload = false, hardReloadAfter = false) {
const messageInput = document.querySelector('[name="broadcast_message"]');
const message = messageInput.value.trim();
const messageType = getMessageType();
const infoDiv = document.getElementById('broadcast-info');
if (!message) {
alert('Bitte Nachricht eingeben!');
return;
}
infoDiv.innerHTML = '🔄 Sende...';
fetch('./?Broadcast&function=sendBroadcast', {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: 'message=' + encodeURIComponent(message)
+ '&admin_id=' + ADMIN_ID
+ (noReload ? '&no_reload=1' : '')
+ '&message_type=' + messageType
})
.then(r => r.json())
.then(data => {
if (data.success) {
alert('✅ Nachricht gesendet!');
messageInput.value = '';
checkBroadcastStatus();
if (hardReloadAfter) hardReload();
} else {
alert('❌ Fehler beim Senden');
}
})
.catch(() => alert('❌ Netzwerkfehler'));
}
function clearBroadcast() {
if (!confirm('Broadcast wirklich löschen?')) return;
fetch('./?Broadcast&function=clearBroadcast&admin_id=' + ADMIN_ID)
.then(r => r.json())
.then(() => {
alert('✅ Broadcast gelöscht');
checkBroadcastStatus();
});
}
function hardReload() {
const base = location.pathname + location.search;
location.href = base + (base.includes("?") ? "&" : "?") + "t=" + Date.now();
}
function updateBroadcastInfo(data) {
const infoDiv = document.getElementById('broadcast-info');
if (!data.message) {
infoDiv.innerHTML = 'ℹ️ Kein aktiver Broadcast';
return;
}
let typeText = '';
switch (data.message_type) {
case 'standard':
typeText = '💬 Standard (nur Online User)';
break;
case 'general':
typeText = '📢 Allgemein (alle + neue User)';
break;
case 'welcome':
typeText = '🏠 Welcome (nur neue User)';
break;
default:
typeText = 'Unbekannt';
}
const modeText = data.no_reload
? '💬 Nur Nachricht'
: '📢 Nachricht + Reload';
const msg = data.message.replace(/\\n/g, '
');
infoDiv.innerHTML =
'📢 Aktiver Broadcast
' +
'Typ: ' + typeText + '
' +
'Modus: ' + modeText + '
' +
''
+ msg +
'
' +
'👥 Gesendet an: ' + (data.target_count || 0) + ' User
' +
'👁️ Gesehen von: ' + (data.seen_count || 0) + ' User
' +
'🌐 Online: ' + (data.current_online_count || 0) + ' User';
}
function checkBroadcastStatus() {
fetch('./?Broadcast&function=getBroadcastStatus&t=' + Date.now())
.then(r => r.json())
.then(data => {
if (data.hasBroadcast) {
updateBroadcastInfo(data);
} else {
document.getElementById('broadcast-info').innerHTML =
'ℹ️ Kein aktiver Broadcast';
}
});
}
document.addEventListener('DOMContentLoaded', function() {
checkBroadcastStatus();
setInterval(checkBroadcastStatus, 2000);
});
JS;
$content = ob_get_clean();
include "admin_master_template.php";