Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrected template to white and updated search to include first and last name query #317

Merged
merged 4 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ RegisterNUICallback("searchProfiles", function(data, cb)
end)


RegisterNetEvent('mdt:client:searchProfile', function(sentData, isLimited)
SendNUIMessage({ type = "profiles", data = sentData, isLimited = isLimited })
RegisterNetEvent('mdt:client:searchProfile', function(sentData, isLimited, fingerprint)
SendNUIMessage({ action = "updateFingerprintData", fingerprint = fingerprint })
end)

RegisterNUICallback("saveProfile", function(data, cb)
Expand All @@ -301,8 +301,8 @@ RegisterNUICallback("saveProfile", function(data, cb)
local tags = data.tags
local gallery = data.gallery
local licenses = data.licenses

TriggerServerEvent("mdt:server:saveProfile", profilepic, information, cid, fName, sName, tags, gallery, licenses)
local fingerprint = data.fingerprint
TriggerServerEvent("mdt:server:saveProfile", profilepic, information, cid, fName, sName, tags, gallery, licenses, fingerprint)
cb(true)
end)

Expand Down Expand Up @@ -335,6 +335,8 @@ RegisterNUICallback("getProfileData", function(data, cb)
end
end
p = nil

result['fingerprint'] = result['searchFingerprint']
return cb(result)
end)

Expand Down Expand Up @@ -1044,10 +1046,10 @@ end)
for _, weaponInfo in ipairs(weaponInfos) do
TriggerServerEvent('mdt:server:registerweapon', weaponInfo.serialnumber, weaponInfo.weaponurl, weaponInfo.notes, weaponInfo.owner, weaponInfo.weapClass, weaponInfo.weaponmodel)
TriggerEvent('QBCore:Notify', "Weapon " .. weaponInfo.weaponmodel .. " has been added to police database.")
print("Weapon added to database")
--print("Weapon added to database")
end
else
print("No weapons found")
--print("No weapons found")
end
end)
end, false) ]]
Expand Down
5 changes: 2 additions & 3 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ server_scripts {
'@oxmysql/lib/MySQL.lua',
'server/utils.lua',
'server/dbm.lua',
'server/main.lua',
'server/versioncheck.lua'
'server/main.lua'
}
client_scripts{
'client/main.lua',
Expand All @@ -30,4 +29,4 @@ files {
'ui/dashboard.html',
'ui/app.js',
'ui/style.css',
}
}
20 changes: 2 additions & 18 deletions server/dbm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ end

-- (Start) Opening the MDT and sending data
function AddLog(text)
--print(text)
return MySQL.insert.await('INSERT INTO `mdt_logs` (`text`, `time`) VALUES (?,?)', {text, os.time() * 1000})
-- return exports.oxmysql:execute('INSERT INTO `mdt_logs` (`text`, `time`) VALUES (:text, :time)', { text = text, time = os.time() * 1000 })
end

function GetNameFromId(cid)
-- Should be a scalar?
local result = MySQL.scalar.await('SELECT charinfo FROM players WHERE citizenid = @citizenid', { ['@citizenid'] = cid })
if result ~= nil then
local charinfo = json.decode(result)
Expand All @@ -29,37 +26,29 @@ function GetNameFromId(cid)
--print('Player does not exist')
return nil
end
-- return exports.oxmysql:executeSync('SELECT firstname, lastname FROM `users` WHERE id = :id LIMIT 1', { id = cid })
end

-- idk what this is used for either
function GetPersonInformation(cid, jobtype)
local result = MySQL.query.await('SELECT information, tags, gallery, pfp FROM mdt_data WHERE cid = ? and jobtype = ?', { cid, jobtype})
return result[1]
-- return exports.oxmysql:executeSync('SELECT information, tags, gallery FROM mdt WHERE cid= ? and type = ?', { cid, jobtype })
local result = MySQL.query.await('SELECT information, tags, gallery, pfp, fingerprint FROM mdt_data WHERE cid = ? and jobtype = ?', { cid, jobtype})
return result[1]
end

function GetIncidentName(id)
-- Should also be a scalar
local result = MySQL.query.await('SELECT title FROM `mdt_incidents` WHERE id = :id LIMIT 1', { id = id })
return result[1]
-- return exports.oxmysql:executeSync('SELECT title FROM `mdt_incidents` WHERE id = :id LIMIT 1', { id = id })
end

function GetConvictions(cids)
return MySQL.query.await('SELECT * FROM `mdt_convictions` WHERE `cid` IN(?)', { cids })
-- return exports.oxmysql:executeSync('SELECT * FROM `mdt_convictions` WHERE `cid` IN(?)', { cids })
end

function GetLicenseInfo(cid)
local result = MySQL.query.await('SELECT * FROM `licenses` WHERE `cid` = ?', { cid })
return result
-- return exports.oxmysql:executeSync('SELECT * FROM `licenses` WHERE `cid`=:cid', { cid = cid })
end

function CreateUser(cid, tableName)
AddLog("A user was created with the CID: "..cid)
-- return exports.oxmysql:insert("INSERT INTO `"..dbname.."` (cid) VALUES (:cid)", { cid = cid })
return MySQL.insert.await("INSERT INTO `"..tableName.."` (cid) VALUES (:cid)", { cid = cid })
end

Expand All @@ -69,7 +58,6 @@ end

function GetBulletins(JobType)
return MySQL.query.await('SELECT * FROM `mdt_bulletin` WHERE `jobtype` = ? LIMIT 10', { JobType })
-- return exports.oxmysql:executeSync('SELECT * FROM `mdt_bulletin` WHERE `type`= ? LIMIT 10', { JobType })
end

function GetPlayerProperties(cid, cb)
Expand All @@ -85,20 +73,16 @@ function GetPlayerDataById(id)
else
return MySQL.single.await('SELECT citizenid, charinfo, job, metadata FROM players WHERE citizenid = ? LIMIT 1', { id })
end

-- return exports.oxmysql:executeSync('SELECT citizenid, charinfo, job FROM players WHERE citizenid = ? LIMIT 1', { id })
end

function GetBoloStatus(plate)
local result = MySQL.scalar.await('SELECT id FROM `mdt_bolos` WHERE LOWER(`plate`)=:plate', { plate = string.lower(plate)})
return result
-- return exports.oxmysql:scalarSync('SELECT id FROM `mdt_bolos` WHERE LOWER(`plate`)=:plate', { plate = string.lower(plate)})
end

function GetOwnerName(cid)
local result = MySQL.scalar.await('SELECT charinfo FROM `players` WHERE LOWER(`citizenid`) = ? LIMIT 1', {cid})
return result
-- return exports.oxmysql:scalarSync('SELECT charinfo FROM `players` WHERE id=:cid LIMIT 1', { cid = cid})
end

function GetVehicleInformation(plate, cb)
Expand Down
137 changes: 76 additions & 61 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -206,43 +206,48 @@ RegisterNetEvent('mdt:server:openMDT', function()
end)

QBCore.Functions.CreateCallback('mdt:server:SearchProfile', function(source, cb, sentData)
if not sentData then return cb({}) end
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player then
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType ~= nil then
local people = MySQL.query.await("SELECT p.citizenid, p.charinfo, md.pfp FROM players p LEFT JOIN mdt_data md on p.citizenid = md.cid WHERE LOWER(CONCAT(JSON_VALUE(p.charinfo, '$.firstname'), ' ', JSON_VALUE(p.charinfo, '$.lastname'))) LIKE :query OR LOWER(`charinfo`) LIKE :query OR LOWER(`citizenid`) LIKE :query AND jobtype = :jobtype LIMIT 20", { query = string.lower('%'..sentData..'%'), jobtype = JobType })
local citizenIds = {}
local citizenIdIndexMap = {}
if not next(people) then cb({}) return end

for index, data in pairs(people) do
people[index]['warrant'] = false
people[index]['convictions'] = 0
people[index]['licences'] = GetPlayerLicenses(data.citizenid)
people[index]['pp'] = ProfPic(data.gender, data.pfp)
citizenIds[#citizenIds+1] = data.citizenid
citizenIdIndexMap[data.citizenid] = index
end

local convictions = GetConvictions(citizenIds)
if not sentData then return cb({}) end
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player then
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType ~= nil then
local people = MySQL.query.await("SELECT p.citizenid, p.charinfo, md.pfp, md.fingerprint FROM players p LEFT JOIN mdt_data md on p.citizenid = md.cid WHERE LOWER(CONCAT(JSON_VALUE(p.charinfo, '$.firstname'), ' ', JSON_VALUE(p.charinfo, '$.lastname'))) LIKE :query OR LOWER(`charinfo`) LIKE :query OR LOWER(`citizenid`) LIKE :query OR LOWER(md.fingerprint) LIKE :query AND jobtype = :jobtype LIMIT 20", { query = string.lower('%'..sentData..'%'), jobtype = JobType })
local citizenIds = {}
local citizenIdIndexMap = {}
if not next(people) then cb({}) return end

for index, data in pairs(people) do
people[index]['warrant'] = false
people[index]['convictions'] = 0
people[index]['licences'] = GetPlayerLicenses(data.citizenid)
people[index]['pp'] = ProfPic(data.gender, data.pfp)
if data.fingerprint and data.fingerprint ~= "" then
people[index]['fingerprint'] = data.fingerprint
else
people[index]['fingerprint'] = ""
end
citizenIds[#citizenIds+1] = data.citizenid
citizenIdIndexMap[data.citizenid] = index
end

if next(convictions) then
for _, conv in pairs(convictions) do
if conv.warrant == "1" then people[citizenIdIndexMap[conv.cid]].warrant = true end
local convictions = GetConvictions(citizenIds)

local charges = json.decode(conv.charges)
people[citizenIdIndexMap[conv.cid]].convictions = people[citizenIdIndexMap[conv.cid]].convictions + #charges
end
end
if next(convictions) then
for _, conv in pairs(convictions) do
if conv.warrant == "1" then people[citizenIdIndexMap[conv.cid]].warrant = true end

local charges = json.decode(conv.charges)
people[citizenIdIndexMap[conv.cid]].convictions = people[citizenIdIndexMap[conv.cid]].convictions + #charges
end
end
TriggerClientEvent('mdt:client:searchProfile', src, people, false, people[1].fingerprint)

return cb(people)
end
end
return cb(people)
end
end

return cb({})
return cb({})
end)

QBCore.Functions.CreateCallback("mdt:server:getWarrants", function(source, cb)
Expand Down Expand Up @@ -418,26 +423,29 @@ QBCore.Functions.CreateCallback('mdt:server:GetProfileData', function(source, cb
person.profilepic = mdtData.pfp
person.tags = json.decode(mdtData.tags)
person.gallery = json.decode(mdtData.gallery)
person.fingerprint = mdtData.fingerprint
print("Fetched fingerprint from mdt_data:", mdtData.fingerprint)
end

return cb(person)
end)

RegisterNetEvent("mdt:server:saveProfile", function(pfp, information, cid, fName, sName, tags, gallery, licenses)
RegisterNetEvent("mdt:server:saveProfile", function(pfp, information, cid, fName, sName, tags, gallery, licenses, fingerprint)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
UpdateAllLicenses(cid, licenses)
if Player then
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'doj' then JobType = 'police' end

MySQL.Async.insert('INSERT INTO mdt_data (cid, information, pfp, jobtype, tags, gallery) VALUES (:cid, :information, :pfp, :jobtype, :tags, :gallery) ON DUPLICATE KEY UPDATE cid = :cid, information = :information, pfp = :pfp, jobtype = :jobtype, tags = :tags, gallery = :gallery', {
MySQL.Async.insert('INSERT INTO mdt_data (cid, information, pfp, jobtype, tags, gallery, fingerprint) VALUES (:cid, :information, :pfp, :jobtype, :tags, :gallery, :fingerprint) ON DUPLICATE KEY UPDATE cid = :cid, information = :information, pfp = :pfp, jobtype = :jobtype, tags = :tags, gallery = :gallery, fingerprint = :fingerprint', {
cid = cid,
information = information,
pfp = pfp,
jobtype = JobType,
tags = json.encode(tags),
gallery = json.encode(gallery),
fingerprint = fingerprint,
}, function()
end)
end
Expand Down Expand Up @@ -727,34 +735,41 @@ end)

RegisterNetEvent('mdt:server:incidentSearchPerson', function(query)
if query then
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player then
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'doj' or JobType == 'ambulance' then
local function ProfPic(gender, profilepic)
if profilepic then return profilepic end;
if gender == "f" then return "img/female.png" end;
return "img/male.png"
end
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player then
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'doj' or JobType == 'ambulance' then
local function ProfPic(gender, profilepic)
if profilepic then return profilepic end;
if gender == "f" then return "img/female.png" end;
return "img/male.png"
end

local result = MySQL.query.await("SELECT p.citizenid, p.charinfo, p.metadata, md.pfp from players p LEFT JOIN mdt_data md on p.citizenid = md.cid WHERE LOWER(`charinfo`) LIKE :query OR LOWER(`citizenid`) LIKE :query AND `jobtype` = :jobtype LIMIT 30", {
query = string.lower('%'..query..'%'), -- % wildcard, needed to search for all alike results
jobtype = JobType
})
local data = {}
for i=1, #result do
local charinfo = json.decode(result[i].charinfo)
local metadata = json.decode(result[i].metadata)
data[i] = {
id = result[i].citizenid,
firstname = charinfo.firstname,
lastname = charinfo.lastname,
profilepic = ProfPic(charinfo.gender, result[i].pfp),
callsign = metadata.callsign
}
end
TriggerClientEvent('mdt:client:incidentSearchPerson', src, data)
local firstname, lastname = query:match("^(%S+)%s*(%S*)$")
firstname = firstname or query
lastname = lastname or query

local result = MySQL.query.await("SELECT p.citizenid, p.charinfo, p.metadata, md.pfp from players p LEFT JOIN mdt_data md on p.citizenid = md.cid WHERE (LOWER(JSON_UNQUOTE(JSON_EXTRACT(`charinfo`, '$.firstname'))) LIKE :firstname AND LOWER(JSON_UNQUOTE(JSON_EXTRACT(`charinfo`, '$.lastname'))) LIKE :lastname) OR LOWER(`citizenid`) LIKE :citizenid AND `jobtype` = :jobtype LIMIT 30", {
firstname = string.lower('%' .. firstname .. '%'),
lastname = string.lower('%' .. lastname .. '%'),
citizenid = string.lower('%' .. query .. '%'),
jobtype = JobType
})

local data = {}
for i=1, #result do
local charinfo = json.decode(result[i].charinfo)
local metadata = json.decode(result[i].metadata)
data[i] = {
id = result[i].citizenid,
firstname = charinfo.firstname,
lastname = charinfo.lastname,
profilepic = ProfPic(charinfo.gender, result[i].pfp),
callsign = metadata.callsign
}
end
TriggerClientEvent('mdt:client:incidentSearchPerson', src, data)
end
end
end
Expand Down
45 changes: 0 additions & 45 deletions server/versioncheck.lua

This file was deleted.

2 changes: 1 addition & 1 deletion shared/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -704,4 +704,4 @@ function GetJobType(job)
else
return nil
end
end
end
Loading