1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-08-12 19:00:26 +02:00
parent dee484871a
commit 06087a7800
3 changed files with 486 additions and 2 deletions

View file

@ -72,6 +72,14 @@ function openInfoPointMenu()
onSelect = function()
showEvents()
end
},
{
title = 'Allgemeine Informationen',
description = 'Wichtige Bekanntmachungen und Hinweise',
icon = 'bullhorn',
onSelect = function()
showGeneralInfo()
end
}
}
@ -104,6 +112,26 @@ function openInfoPointMenu()
})
end
-- Option to post general information (only for authorized jobs)
local canPostInfo = false
for _, allowedJob in pairs(Config.JobPermissions.canPostGeneralInfo) do
if job == allowedJob then
canPostInfo = true
break
end
end
if canPostInfo then
table.insert(menuOptions, {
title = 'Information veröffentlichen',
description = 'Neue allgemeine Information erstellen',
icon = 'pen',
onSelect = function()
createGeneralInfoDialog()
end
})
end
-- Vorfall melden (für alle oder spezifische Jobs)
if Config.JobPermissions.canReportIncidents == 'all' or
(type(Config.JobPermissions.canReportIncidents) == 'table' and
@ -665,6 +693,261 @@ function editLicenseInfoDialog(license)
end
end
-- Show general information
function showGeneralInfo()
QBCore.Functions.TriggerCallback('infopoint:getGeneralInfo', function(infoList)
local infoOptions = {}
if #infoList == 0 then
table.insert(infoOptions, {
title = 'Keine Informationen verfügbar',
description = 'Derzeit sind keine allgemeinen Informationen vorhanden',
icon = 'info'
})
else
for _, info in pairs(infoList) do
local importanceIcon = '📄'
if info.importance == 'high' then
importanceIcon = '🔴'
elseif info.importance == 'medium' then
importanceIcon = '🟠'
end
local createdDate = os.date('%d.%m.%Y', os.time({
year = tonumber(string.sub(info.created_at, 1, 4)),
month = tonumber(string.sub(info.created_at, 6, 7)),
day = tonumber(string.sub(info.created_at, 9, 10))
}))
table.insert(infoOptions, {
title = importanceIcon .. ' ' .. info.title,
description = 'Kategorie: ' .. info.category .. ' | Erstellt: ' .. createdDate,
icon = 'bullhorn',
onSelect = function()
showGeneralInfoDetails(info)
end
})
end
end
table.insert(infoOptions, {
title = '← Zurück',
icon = 'arrow-left',
onSelect = function()
openInfoPointMenu()
end
})
lib.registerContext({
id = 'infopoint_general_info',
title = 'Allgemeine Informationen',
options = infoOptions
})
lib.showContext('infopoint_general_info')
end)
end
-- Show general information details
function showGeneralInfoDetails(info)
local PlayerData = QBCore.Functions.GetPlayerData()
local canManage = false
-- Check if player can manage this info (created by them or has management rights)
if PlayerData.citizenid == info.created_by then
canManage = true
end
-- Check if player has permission to post general info (they can also manage)
local job = PlayerData.job.name
for _, allowedJob in pairs(Config.JobPermissions.canPostGeneralInfo) do
if job == allowedJob then
canManage = true
break
end
end
-- If they can manage, show management options
if canManage then
local options = {
{
title = 'Information anzeigen',
description = 'Details der Information anzeigen',
icon = 'eye',
onSelect = function()
showInfoContent(info)
end
},
{
title = '✏️ Bearbeiten',
description = 'Information bearbeiten',
icon = 'edit',
onSelect = function()
editGeneralInfoDialog(info)
end
},
{
title = '🗑️ Löschen',
description = 'Information löschen',
icon = 'trash',
onSelect = function()
deleteGeneralInfo(info.id)
end
},
{
title = '← Zurück',
icon = 'arrow-left',
onSelect = function()
showGeneralInfo()
end
}
}
lib.registerContext({
id = 'general_info_management',
title = info.title,
options = options
})
lib.showContext('general_info_management')
return
end
-- If they can't manage, just show the content
showInfoContent(info)
end
-- Function to show just the content
function showInfoContent(info)
local createdDate = os.date('%d.%m.%Y', os.time({
year = tonumber(string.sub(info.created_at, 1, 4)),
month = tonumber(string.sub(info.created_at, 6, 7)),
day = tonumber(string.sub(info.created_at, 9, 10))
}))
local expiryInfo = ''
if info.expires_at then
local expiryDate = os.date('%d.%m.%Y', os.time({
year = tonumber(string.sub(info.expires_at, 1, 4)),
month = tonumber(string.sub(info.expires_at, 6, 7)),
day = tonumber(string.sub(info.expires_at, 9, 10))
}))
expiryInfo = 'Gültig bis: ' .. expiryDate .. '\n\n'
end
local importanceText = 'Normal'
if info.importance == 'high' then
importanceText = 'Hoch'
elseif info.importance == 'medium' then
importanceText = 'Mittel'
end
lib.alertDialog({
header = info.title,
content = 'Kategorie: ' .. info.category .. '\n\n' ..
'Wichtigkeit: ' .. importanceText .. '\n\n' ..
'Erstellt am: ' .. createdDate .. '\n\n' ..
expiryInfo ..
'Inhalt:\n' .. info.content .. '\n\n' ..
'Veröffentlicht von: ' .. info.created_by_name .. ' (' .. info.created_by_job .. ')',
centered = true,
cancel = true
})
end
-- Create general information dialog
function createGeneralInfoDialog()
local categoryOptions = {}
for _, category in pairs(Config.GeneralInfoCategories) do
table.insert(categoryOptions, {value = category, label = category})
end
local importanceOptions = {
{value = 'normal', label = 'Normal'},
{value = 'medium', label = 'Mittel'},
{value = 'high', label = 'Hoch'}
}
local input = lib.inputDialog('Information veröffentlichen', {
{type = 'input', label = 'Titel', required = true, max = 100},
{type = 'textarea', label = 'Inhalt', required = true, max = 1000},
{type = 'select', label = 'Kategorie', options = categoryOptions, required = true},
{type = 'select', label = 'Wichtigkeit', options = importanceOptions, default = 'normal'},
{type = 'date', label = 'Gültig bis (optional)'}
})
if input then
local infoData = {
title = input[1],
content = input[2],
category = input[3],
importance = input[4],
expires_at = input[5] ~= '' and input[5] or nil
}
TriggerServerEvent('infopoint:createGeneralInfo', infoData)
end
end
-- Function to edit general info
function editGeneralInfoDialog(info)
local categoryOptions = {}
for _, category in pairs(Config.GeneralInfoCategories) do
table.insert(categoryOptions, {value = category, label = category})
end
local importanceOptions = {
{value = 'normal', label = 'Normal'},
{value = 'medium', label = 'Mittel'},
{value = 'high', label = 'Hoch'}
}
local expiryDate = nil
if info.expires_at then
expiryDate = string.sub(info.expires_at, 1, 10)
end
local input = lib.inputDialog('Information bearbeiten', {
{type = 'input', label = 'Titel', required = true, max = 100, default = info.title},
{type = 'textarea', label = 'Inhalt', required = true, max = 1000, default = info.content},
{type = 'select', label = 'Kategorie', options = categoryOptions, required = true, default = info.category},
{type = 'select', label = 'Wichtigkeit', options = importanceOptions, default = info.importance},
{type = 'date', label = 'Gültig bis (optional)', default = expiryDate}
})
if input then
local infoData = {
title = input[1],
content = input[2],
category = input[3],
importance = input[4],
expires_at = input[5] ~= '' and input[5] or nil
}
TriggerServerEvent('infopoint:updateGeneralInfo', info.id, infoData)
end
end
-- Function to delete general info
function deleteGeneralInfo(infoId)
lib.alertDialog({
header = 'Information löschen',
content = 'Bist du sicher, dass du diese Information löschen möchtest?',
centered = true,
cancel = true,
labels = {
cancel = 'Abbrechen',
confirm = 'Löschen'
}
}, function(confirmed)
if confirmed then
TriggerServerEvent('infopoint:deleteGeneralInfo', infoId)
Wait(500)
showGeneralInfo() -- Back to overview
end
end)
end
-- Hilfsfunktion für table.contains
function table.contains(table, element)
for _, value in pairs(table) do