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

@ -65,6 +65,23 @@ CreateThread(function()
)
]])
-- Neue Tabelle für allgemeine Informationen
MySQL.query([[
CREATE TABLE IF NOT EXISTS infopoint_general_info (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
content TEXT,
category VARCHAR(100),
importance VARCHAR(50) DEFAULT 'normal',
created_by VARCHAR(50),
created_by_job VARCHAR(50),
created_by_name VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
expires_at DATETIME NULL,
active BOOLEAN DEFAULT TRUE
)
]])
-- Standard Lizenz-Informationen einfügen falls nicht vorhanden
MySQL.query('SELECT COUNT(*) as count FROM infopoint_license_info', {}, function(result)
if result[1].count == 0 then
@ -174,6 +191,15 @@ QBCore.Functions.CreateCallback('infopoint:getLicenseInfo', function(source, cb)
end)
end)
-- Allgemeine Informationen abrufen
QBCore.Functions.CreateCallback('infopoint:getGeneralInfo', function(source, cb)
local currentDate = os.date('%Y-%m-%d')
MySQL.query('SELECT * FROM infopoint_general_info WHERE active = 1 AND (expires_at IS NULL OR expires_at >= ?) ORDER BY importance DESC, created_at DESC', {currentDate}, function(result)
cb(result)
end)
end)
-- Prüfen ob Spieler Lizenz-Informationen verwalten kann
QBCore.Functions.CreateCallback('infopoint:canManageLicenses', function(source, cb)
local Player = QBCore.Functions.GetPlayer(source)
@ -435,3 +461,156 @@ RegisterNetEvent('infopoint:deleteLicenseInfo', function(licenseId)
end
end)
end)
-- Allgemeine Information erstellen
RegisterNetEvent('infopoint:createGeneralInfo', function(infoData)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end
local job = Player.PlayerData.job.name
local canPost = false
-- Sicherheitsprüfung für Config
if Config and Config.JobPermissions and Config.JobPermissions.canPostGeneralInfo then
if type(Config.JobPermissions.canPostGeneralInfo) == 'table' then
for _, allowedJob in pairs(Config.JobPermissions.canPostGeneralInfo) do
if job == allowedJob then
canPost = true
break
end
end
end
end
if not canPost then
TriggerClientEvent('QBCore:Notify', src, 'Du hast keine Berechtigung allgemeine Informationen zu veröffentlichen!', 'error')
return
end
MySQL.insert('INSERT INTO infopoint_general_info (title, content, category, importance, expires_at, created_by, created_by_job, created_by_name) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', {
infoData.title,
infoData.content,
infoData.category,
infoData.importance,
infoData.expires_at,
Player.PlayerData.citizenid,
Player.PlayerData.job.name,
Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname
}, function(insertId)
if insertId then
TriggerClientEvent('QBCore:Notify', src, 'Information erfolgreich veröffentlicht!', 'success')
TriggerClientEvent('infopoint:refreshData', -1)
end
end)
end)
-- Allgemeine Information bearbeiten
RegisterNetEvent('infopoint:updateGeneralInfo', function(infoId, infoData)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end
-- First check if this player created the info or has permission to post general info
MySQL.query('SELECT created_by FROM infopoint_general_info WHERE id = ?', {infoId}, function(result)
if result[1] then
local canEdit = false
-- Check if player created this info
if result[1].created_by == Player.PlayerData.citizenid then
canEdit = true
end
-- Check if player has permission to post general info (they can also edit)
if not canEdit then
local job = Player.PlayerData.job.name
if Config and Config.JobPermissions and Config.JobPermissions.canPostGeneralInfo then
if type(Config.JobPermissions.canPostGeneralInfo) == 'table' then
for _, allowedJob in pairs(Config.JobPermissions.canPostGeneralInfo) do
if job == allowedJob then
canEdit = true
break
end
end
end
end
end
if not canEdit then
TriggerClientEvent('QBCore:Notify', src, 'Du hast keine Berechtigung diese Information zu bearbeiten!', 'error')
return
end
-- Update the info
MySQL.update('UPDATE infopoint_general_info SET title = ?, content = ?, category = ?, importance = ?, expires_at = ? WHERE id = ?', {
infoData.title,
infoData.content,
infoData.category,
infoData.importance,
infoData.expires_at,
infoId
}, function(affectedRows)
if affectedRows > 0 then
TriggerClientEvent('QBCore:Notify', src, 'Information erfolgreich aktualisiert!', 'success')
TriggerClientEvent('infopoint:refreshData', -1)
else
TriggerClientEvent('QBCore:Notify', src, 'Fehler beim Aktualisieren der Information!', 'error')
end
end)
else
TriggerClientEvent('QBCore:Notify', src, 'Information nicht gefunden!', 'error')
end
end)
end)
-- Allgemeine Information löschen
RegisterNetEvent('infopoint:deleteGeneralInfo', function(infoId)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end
-- First check if this player created the info or has permission to post general info
MySQL.query('SELECT created_by FROM infopoint_general_info WHERE id = ?', {infoId}, function(result)
if result[1] then
local canDelete = false
-- Check if player created this info
if result[1].created_by == Player.PlayerData.citizenid then
canDelete = true
end
-- Check if player has permission to post general info (they can also delete)
if not canDelete then
local job = Player.PlayerData.job.name
if Config and Config.JobPermissions and Config.JobPermissions.canPostGeneralInfo then
if type(Config.JobPermissions.canPostGeneralInfo) == 'table' then
for _, allowedJob in pairs(Config.JobPermissions.canPostGeneralInfo) do
if job == allowedJob then
canDelete = true
break
end
end
end
end
end
if not canDelete then
TriggerClientEvent('QBCore:Notify', src, 'Du hast keine Berechtigung diese Information zu löschen!', 'error')
return
end
-- Delete (set inactive) the info
MySQL.update('UPDATE infopoint_general_info SET active = 0 WHERE id = ?', {infoId}, function(affectedRows)
if affectedRows > 0 then
TriggerClientEvent('QBCore:Notify', src, 'Information erfolgreich gelöscht!', 'success')
TriggerClientEvent('infopoint:refreshData', -1)
else
TriggerClientEvent('QBCore:Notify', src, 'Fehler beim Löschen der Information!', 'error')
end
end)
else
TriggerClientEvent('QBCore:Notify', src, 'Information nicht gefunden!', 'error')
end
end)
end)