-- ───────────────────────────────────────────────────────────────────────────── -- Contacts / Address Book handlers -- ───────────────────────────────────────────────────────────────────────────── RegisterNetEvent('pc-live:server:getContacts', function() local src = source local user = ActiveSessions[src] if not user then return end local rows = DB.GetContacts(user.identifier) TriggerClientEvent('pc-live:client:contactsData', src, rows) end) RegisterNetEvent('pc-live:server:addContact', function(data) local src = source local user = ActiveSessions[src] if not user then return end if type(data) ~= "table" then return end local d = { name = Utils.Sanitize(tostring(data.name or "")):sub(1, 100), email = Utils.Sanitize(tostring(data.email or "")):sub(1, 120), phone = Utils.Sanitize(tostring(data.phone or "")):sub(1, 30), notes = Utils.Sanitize(tostring(data.notes or "")):sub(1, 500), } if #d.name < 1 then return end local id = DB.AddContact(user.identifier, d) d.id = id TriggerClientEvent('pc-live:client:contactAdded', src, d) end) RegisterNetEvent('pc-live:server:updateContact', function(id, data) local src = source local user = ActiveSessions[src] if not user then return end if type(id) ~= "number" or type(data) ~= "table" then return end local d = { name = Utils.Sanitize(tostring(data.name or "")):sub(1, 100), email = Utils.Sanitize(tostring(data.email or "")):sub(1, 120), phone = Utils.Sanitize(tostring(data.phone or "")):sub(1, 30), notes = Utils.Sanitize(tostring(data.notes or "")):sub(1, 500), } if #d.name < 1 then return end DB.UpdateContact(id, user.identifier, d) d.id = id TriggerClientEvent('pc-live:client:contactUpdated', src, d) end) RegisterNetEvent('pc-live:server:deleteContact', function(id) local src = source local user = ActiveSessions[src] if not user then return end if type(id) ~= "number" then return end DB.DeleteContact(id, user.identifier) TriggerClientEvent('pc-live:client:contactDeleted', src, id) end)