/proc/add_note(target_ckey, notetext, timestamp, adminckey, logged = 1, checkrights = 1, show_after = TRUE, automated = FALSE, sanitise_html = TRUE) // Dont you EVER disable this last param unless you know what you're doing
if(checkrights && !check_rights(R_ADMIN|R_MOD))
return
if(IsAdminAdvancedProcCall() && !sanitise_html)
// *sigh*
to_chat(usr, "Unsanitized note add blocked: Advanced ProcCall detected.")
message_admins("[key_name(usr)] attempted to possibly inject HTML into notes via advanced proc-call")
log_admin("[key_name(usr)] attempted to possibly inject HTML into notes via advanced proc-call")
return
if(!SSdbcore.IsConnected())
if(usr)
to_chat(usr, "Failed to establish database connection.")
return
if(!target_ckey)
var/new_ckey = ckey(clean_input("Who would you like to add a note for?","Enter a ckey",null))
if(!new_ckey)
return
target_ckey = ckey(new_ckey)
else
target_ckey = ckey(target_ckey)
var/datum/db_query/query_find_ckey = SSdbcore.NewQuery("SELECT ckey, exp FROM player WHERE ckey=:ckey", list(
"ckey" = target_ckey
))
if(!query_find_ckey.warn_execute())
qdel(query_find_ckey)
return
var/ckey_found = FALSE
var/exp_data
while(query_find_ckey.NextRow())
exp_data = query_find_ckey.item[2]
ckey_found = TRUE
qdel(query_find_ckey)
if(!ckey_found)
if(usr)
to_chat(usr, "[target_ckey] has not been seen before, you can only add notes to known players.")
return
var/crew_number = 0
if(exp_data)
var/list/play_records = params2list(exp_data)
crew_number = play_records[EXP_TYPE_CREW]
if(!notetext)
notetext = input(usr,"Write your note","Add Note") as message|null
if(!notetext)
return
if(!adminckey)
adminckey = usr.ckey
if(!adminckey)
return
else if(usr && (usr.ckey == ckey(adminckey))) // Don't ckeyize special note sources
adminckey = ckey(adminckey)
// Force cast this to 1/0 incase someone tries to feed bad data
automated = !!automated
if(sanitise_html)
notetext = html_encode(notetext)
var/datum/db_query/query_noteadd = SSdbcore.NewQuery({"
INSERT INTO notes (ckey, timestamp, notetext, adminckey, server, crew_playtime, round_id, automated)
VALUES (:targetckey, NOW(), :notetext, :adminkey, :server, :crewnum, :roundid, :automated)
"}, list(
"targetckey" = target_ckey,
"notetext" = notetext,
"adminkey" = adminckey,
"server" = GLOB.configuration.system.instance_id,
"crewnum" = crew_number,
"roundid" = GLOB.round_id,
"automated" = automated
))
if(!query_noteadd.warn_execute())
qdel(query_noteadd)
return
qdel(query_noteadd)
if(logged)
log_admin("[usr ? key_name(usr) : adminckey] has added a note to [target_ckey]: [notetext]")
message_admins("[usr ? key_name_admin(usr) : adminckey] has added a note to [target_ckey]:
[notetext]")
if(show_after)
show_note(target_ckey)
/proc/remove_note(note_id)
if(!check_rights(R_ADMIN|R_MOD))
return
var/ckey
var/notetext
var/adminckey
if(!SSdbcore.IsConnected())
if(usr)
to_chat(usr, "Failed to establish database connection.")
return
if(!note_id)
return
note_id = text2num(note_id)
var/datum/db_query/query_find_note_del = SSdbcore.NewQuery("SELECT ckey, notetext, adminckey FROM notes WHERE id=:note_id", list(
"note_id" = note_id
))
if(!query_find_note_del.warn_execute())
qdel(query_find_note_del)
return
if(query_find_note_del.NextRow())
ckey = query_find_note_del.item[1]
notetext = query_find_note_del.item[2]
adminckey = query_find_note_del.item[3]
qdel(query_find_note_del)
var/datum/db_query/query_del_note = SSdbcore.NewQuery("DELETE FROM notes WHERE id=:note_id", list(
"note_id" = note_id
))
if(!query_del_note.warn_execute())
qdel(query_del_note)
return
qdel(query_del_note)
var/safe_text = html_encode(notetext)
log_admin("[usr ? key_name(usr) : "Bot"] has removed a note made by [adminckey] from [ckey]: [safe_text]")
message_admins("[usr ? key_name_admin(usr) : "Bot"] has removed a note made by [adminckey] from [ckey]:
[safe_text]")
show_note(ckey)
/proc/edit_note(note_id)
if(!check_rights(R_ADMIN|R_MOD))
return
if(!SSdbcore.IsConnected())
if(usr)
to_chat(usr, "Failed to establish database connection.")
return
if(!note_id)
return
note_id = text2num(note_id)
var/target_ckey
var/datum/db_query/query_find_note_edit = SSdbcore.NewQuery("SELECT ckey, notetext, adminckey, automated FROM notes WHERE id=:note_id", list(
"note_id" = note_id
))
if(!query_find_note_edit.warn_execute())
qdel(query_find_note_edit)
return
if(query_find_note_edit.NextRow())
target_ckey = query_find_note_edit.item[1]
var/old_note = query_find_note_edit.item[2]
var/adminckey = query_find_note_edit.item[3]
var/automated = query_find_note_edit.item[4]
if(automated)
to_chat(usr, "That note is generated automatically. You can't edit it.")
return
var/new_note = input("Input new note", "New Note", "[old_note]") as message|null
if(!new_note)
return
var/safe_text = html_encode(new_note)
var/edit_text = "Edited by [usr.ckey] on [SQLtime()] from \"[old_note]\" to \"[safe_text]\"