forked from Simnation/Main
208 lines
7.1 KiB
Lua
208 lines
7.1 KiB
Lua
local QBCore = exports['qb-core']:GetCoreObject()
|
|
|
|
-- Datenbank Setup
|
|
CreateThread(function()
|
|
MySQL.query([[
|
|
CREATE TABLE IF NOT EXISTS infopoint_events (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
title VARCHAR(255) NOT NULL,
|
|
description TEXT,
|
|
category VARCHAR(100),
|
|
location VARCHAR(255),
|
|
event_date DATETIME,
|
|
created_by VARCHAR(50),
|
|
created_by_name VARCHAR(255),
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
active BOOLEAN DEFAULT TRUE
|
|
)
|
|
]])
|
|
|
|
MySQL.query([[
|
|
CREATE TABLE IF NOT EXISTS infopoint_incidents (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
title VARCHAR(255) NOT NULL,
|
|
description TEXT,
|
|
category VARCHAR(100),
|
|
location VARCHAR(255),
|
|
reported_by VARCHAR(50),
|
|
reported_by_name VARCHAR(255),
|
|
status VARCHAR(50) DEFAULT 'open',
|
|
assigned_to VARCHAR(50),
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
)
|
|
]])
|
|
|
|
MySQL.query([[
|
|
CREATE TABLE IF NOT EXISTS infopoint_job_offers (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
job_name VARCHAR(100),
|
|
title VARCHAR(255),
|
|
description TEXT,
|
|
requirements TEXT,
|
|
salary VARCHAR(100),
|
|
contact VARCHAR(255),
|
|
created_by VARCHAR(50),
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
active BOOLEAN DEFAULT TRUE
|
|
)
|
|
]])
|
|
end)
|
|
|
|
-- Events abrufen
|
|
QBCore.Functions.CreateCallback('infopoint:getEvents', function(source, cb)
|
|
MySQL.query('SELECT * FROM infopoint_events WHERE active = 1 ORDER BY event_date ASC', {}, function(result)
|
|
cb(result)
|
|
end)
|
|
end)
|
|
|
|
-- Vorfälle abrufen (nur für berechtigte Jobs)
|
|
QBCore.Functions.CreateCallback('infopoint:getIncidents', function(source, cb)
|
|
local Player = QBCore.Functions.GetPlayer(source)
|
|
if not Player then return cb({}) end
|
|
|
|
local job = Player.PlayerData.job.name
|
|
if Config.JobPermissions.jobSpecificInfo[job] and Config.JobPermissions.jobSpecificInfo[job].showIncidents then
|
|
MySQL.query('SELECT * FROM infopoint_incidents ORDER BY created_at DESC', {}, function(result)
|
|
cb(result)
|
|
end)
|
|
else
|
|
cb({})
|
|
end
|
|
end)
|
|
|
|
-- Job Angebote abrufen
|
|
QBCore.Functions.CreateCallback('infopoint:getJobOffers', function(source, cb, jobName)
|
|
local query = 'SELECT * FROM infopoint_job_offers WHERE active = 1'
|
|
local params = {}
|
|
|
|
if jobName then
|
|
query = query .. ' AND job_name = ?'
|
|
params = {jobName}
|
|
end
|
|
|
|
query = query .. ' ORDER BY created_at DESC'
|
|
|
|
MySQL.query(query, params, function(result)
|
|
cb(result)
|
|
end)
|
|
end)
|
|
|
|
-- Lizenz Informationen abrufen
|
|
QBCore.Functions.CreateCallback('infopoint:getLicenseInfo', function(source, cb)
|
|
local Player = QBCore.Functions.GetPlayer(source)
|
|
if not Player then return cb({}) end
|
|
|
|
local job = Player.PlayerData.job.name
|
|
if job == 'police' then
|
|
-- Hier könntest du Lizenz-Informationen aus der Datenbank abrufen
|
|
local licenseInfo = {
|
|
{type = 'Führerschein', price = '$500', requirements = 'Theorieprüfung bestehen'},
|
|
{type = 'Waffenschein', price = '$2000', requirements = 'Saubere Akte, Prüfung'},
|
|
{type = 'Pilotenschein', price = '$10000', requirements = 'Flugstunden nachweisen'}
|
|
}
|
|
cb(licenseInfo)
|
|
else
|
|
cb({})
|
|
end
|
|
end)
|
|
|
|
-- Event erstellen
|
|
RegisterNetEvent('infopoint:createEvent', function(eventData)
|
|
local src = source
|
|
local Player = QBCore.Functions.GetPlayer(src)
|
|
if not Player then return end
|
|
|
|
local job = Player.PlayerData.job.name
|
|
local canCreate = false
|
|
|
|
for _, allowedJob in pairs(Config.JobPermissions.canCreateEvents) do
|
|
if job == allowedJob then
|
|
canCreate = true
|
|
break
|
|
end
|
|
end
|
|
|
|
if not canCreate then
|
|
TriggerClientEvent('QBCore:Notify', src, 'Du hast keine Berechtigung Events zu erstellen!', 'error')
|
|
return
|
|
end
|
|
|
|
MySQL.insert('INSERT INTO infopoint_events (title, description, category, location, event_date, created_by, created_by_name) VALUES (?, ?, ?, ?, ?, ?, ?)', {
|
|
eventData.title,
|
|
eventData.description,
|
|
eventData.category,
|
|
eventData.location,
|
|
eventData.date,
|
|
Player.PlayerData.citizenid,
|
|
Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname
|
|
}, function(insertId)
|
|
if insertId then
|
|
TriggerClientEvent('QBCore:Notify', src, 'Event erfolgreich erstellt!', 'success')
|
|
TriggerClientEvent('infopoint:refreshData', -1)
|
|
end
|
|
end)
|
|
end)
|
|
|
|
-- Vorfall melden
|
|
RegisterNetEvent('infopoint:reportIncident', function(incidentData)
|
|
local src = source
|
|
local Player = QBCore.Functions.GetPlayer(src)
|
|
if not Player then return end
|
|
|
|
MySQL.insert('INSERT INTO infopoint_incidents (title, description, category, location, reported_by, reported_by_name) VALUES (?, ?, ?, ?, ?, ?)', {
|
|
incidentData.title,
|
|
incidentData.description,
|
|
incidentData.category,
|
|
incidentData.location,
|
|
Player.PlayerData.citizenid,
|
|
Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname
|
|
}, function(insertId)
|
|
if insertId then
|
|
TriggerClientEvent('QBCore:Notify', src, 'Vorfall erfolgreich gemeldet!', 'success')
|
|
|
|
-- Benachrichtigung an alle Polizisten senden
|
|
local Players = QBCore.Functions.GetQBPlayers()
|
|
for _, player in pairs(Players) do
|
|
if player.PlayerData.job.name == 'police' and player.PlayerData.job.onduty then
|
|
TriggerClientEvent('QBCore:Notify', player.PlayerData.source, 'Neuer Vorfall gemeldet: ' .. incidentData.title, 'primary')
|
|
end
|
|
end
|
|
end
|
|
end)
|
|
end)
|
|
|
|
-- Job Angebot erstellen
|
|
RegisterNetEvent('infopoint:createJobOffer', function(jobData)
|
|
local src = source
|
|
local Player = QBCore.Functions.GetPlayer(src)
|
|
if not Player then return end
|
|
|
|
local job = Player.PlayerData.job.name
|
|
local canCreate = false
|
|
|
|
for _, allowedJob in pairs(Config.JobPermissions.canCreateEvents) do
|
|
if job == allowedJob then
|
|
canCreate = true
|
|
break
|
|
end
|
|
end
|
|
|
|
if not canCreate then
|
|
TriggerClientEvent('QBCore:Notify', src, 'Du hast keine Berechtigung Job-Angebote zu erstellen!', 'error')
|
|
return
|
|
end
|
|
|
|
MySQL.insert('INSERT INTO infopoint_job_offers (job_name, title, description, requirements, salary, contact, created_by) VALUES (?, ?, ?, ?, ?, ?, ?)', {
|
|
job,
|
|
jobData.title,
|
|
jobData.description,
|
|
jobData.requirements,
|
|
jobData.salary,
|
|
jobData.contact,
|
|
Player.PlayerData.citizenid
|
|
}, function(insertId)
|
|
if insertId then
|
|
TriggerClientEvent('QBCore:Notify', src, 'Job-Angebot erfolgreich erstellt!', 'success')
|
|
end
|
|
end)
|
|
end)
|