From 32cda93d1ebba9df5c7cce8f521533c5932d36dc Mon Sep 17 00:00:00 2001 From: skull132 Date: Sat, 26 Sep 2015 00:06:26 +0300 Subject: [PATCH] Warning verb update Adds the ability to edit warnings, and to delete them (only if you're an admin, or if you are the person who issued it). Also adds a method for automatically making old warnings (3 months) expire, on the condition that they are already acknowledged. --- code/modules/admin/topic.dm | 11 +- code/modules/admin/verbs/warning.dm | 167 ++++++++++++++++++++++++---- 2 files changed, 153 insertions(+), 25 deletions(-) diff --git a/code/modules/admin/topic.dm b/code/modules/admin/topic.dm index 7fad59fc..dfb14c9e 100644 --- a/code/modules/admin/topic.dm +++ b/code/modules/admin/topic.dm @@ -2874,4 +2874,13 @@ var/playerckey = href_list["notessearchckey"] show_notes_sql(playerckey, adminckey) - return \ No newline at end of file + return + + else if(href_list["dbwarningedit"]) + var/warningEdit = href_list["dbwarningedit"] + var/warningId = text2num(href_list["dbwarningid"]) + if(!warningEdit || !warningId) + return + + warningsEdit(warningId, warningEdit) + return diff --git a/code/modules/admin/verbs/warning.dm b/code/modules/admin/verbs/warning.dm index 1ae3d827..522dafc6 100644 --- a/code/modules/admin/verbs/warning.dm +++ b/code/modules/admin/verbs/warning.dm @@ -65,9 +65,6 @@ if(!check_rights(R_ADMIN|R_MOD)) return if(!warned_ckey || !istext(warned_ckey)) return -// if(warned_ckey in admin_datums) -// usr << "Error: warn(): You can't warn admins." -// return var/datum/preferences/D var/client/C = directory[warned_ckey] @@ -87,11 +84,11 @@ // Let's begin data gathering and conversion! - var/reason = input("Add Warning Reason") as null|text + var/reason = input("Add Warning Reason. This is visible to the player.") as null|text if(!reason) return - var/notes = input("Add Additional Information") as null|text + var/notes = input("Add Additional Information. This is visible to staff only.") as null|text var/severity switch(alert("Set Warning Severity",,"Standard","Severe")) @@ -108,9 +105,12 @@ ip = C.address var/a_ckey = sanitizeSQL(ckey) - var/DBQuery/query_insert = dbcon.NewQuery("INSERT INTO ss13_warnings (id, time, severity, reason, notes, ckey, computerid, ip, a_ckey) VALUES (null, Now(), '[severity]', '[reason]', '[notes]', '[sqlkey]', '[computerid]', '[ip]', '[a_ckey]')") + var/DBQuery/query_insert = dbcon.NewQuery("INSERT INTO ss13_warnings (id, time, severity, reason, notes, ckey, computerid, ip, a_ckey) VALUES (null, Now(), '[severity]', '[reason]', '[notes]', '[sqlkey]', '[computerid]', '[ip]', '[a_ckey]');") query_insert.Execute() + if(query_insert.ErrorMsg()) + error("SQL error while issuing warning. Error text: [query_insert.ErrorMsg()].") + if(config.ban_legacy_system) notes_add(warned_ckey, "Warning added by [a_ckey], for: [reason]. || Notes regarding the warning: [notes].") else @@ -131,8 +131,9 @@ set category = "OOC" set desc = "Display warnings issued to you." - var/lcolor = "#ffeeee" //light colour, severity = 1 - var/dcolor = "#ffaaaa" //dark colour, severity = 2 + var/lcolor = "#ffeeee" //light colour, severity = 0 + var/dcolor = "#ffaaaa" //dark colour, severity = 1 + var/ecolor = "#808080" //gray colour, expired = 1 establish_db_connection() if(!dbcon.IsConnected()) @@ -151,7 +152,7 @@ var/sqlkey = sanitizeSQL(ckey) - var/DBQuery/search_query = dbcon.NewQuery("SELECT id, time, severity, reason, a_ckey, acknowledged FROM ss13_warnings WHERE visible = '1' AND (ckey='[sqlkey]' OR computerid='[computer_id]' OR ip='[address]') ORDER BY time DESC") + var/DBQuery/search_query = dbcon.NewQuery("SELECT id, time, severity, reason, a_ckey, acknowledged, expired FROM ss13_warnings WHERE visible = 1 AND (ckey='[sqlkey]' OR computerid='[computer_id]' OR ip='[address]') ORDER BY time DESC;") search_query.Execute() while(search_query.NextRow()) @@ -161,12 +162,16 @@ var/reason = search_query.item[4] var/a_ckey = search_query.item[5] var/ackn = text2num(search_query.item[6]) + var/expired = text2num(search_query.item[7]) var/bgcolor = lcolor if(severity) bgcolor = dcolor + if(expired) + bgcolor = ecolor + dat += "" dat += "[a_ckey]" dat += "[time]" @@ -175,8 +180,10 @@ if(!ackn) dat += "(Acknowledge Warning)" + else if(expired) + dat += "Warning expired and no longer active!" else - dat += "Warning Acknowledged!" + dat += "Warning acknowledged!" dat += "" dat += " " @@ -198,7 +205,7 @@ error("Connection to SQL database failed while attempting to update a player's warnings.") return - var/DBQuery/query = dbcon.NewQuery("UPDATE ss13_warnings SET acknowledged = 1 WHERE id = '[id]'") + var/DBQuery/query = dbcon.NewQuery("UPDATE ss13_warnings SET acknowledged = 1 WHERE id = '[id]';") query.Execute() warnings_check() @@ -211,13 +218,21 @@ /client/proc/warnings_alert() var/sqlkey = sanitizeSQL(ckey) var/count = 0 + var/countExpire = 0 establish_db_connection() if(!dbcon.IsConnected()) error("Connection to SQL database failed while attempting to alert a player of their warnings.") return - var/DBQuery/query = dbcon.NewQuery("SELECT id FROM ss13_warnings WHERE (visible = '1' AND acknowledged = '0') AND (ckey='[sqlkey]' OR computerid='[computer_id]' OR ip='[address]')") + var/DBQuery/expireQuery = dbcon.NewQuery("SELECT id FROM ss13_warnings WHERE (acknowledged = 1 AND expired = 0 AND DATE_SUB(CURDATE(),INTERVAL 3 MONTH) > time) AND (ckey='[sqlkey]' OR computerid='[computer_id]' OR ip='[address]');") + expireQuery.Execute() + while(expireQuery.NextRow()) + var/id = text2num(expireQuery.item[1]) + var/DBQuery/updateQuery = dbcon.NewQuery("UPDATE ss13_warnings SET expired = 1 WHERE id = [id];") + updateQuery.Execute() + + var/DBQuery/query = dbcon.NewQuery("SELECT id FROM ss13_warnings WHERE (visible = 1 AND acknowledged = 0 AND expired = 0) AND (ckey='[sqlkey]' OR computerid='[computer_id]' OR ip='[address]');") query.Execute() while(query.NextRow()) count++ @@ -225,6 +240,9 @@ if(count) src << "
" src << "You have [count] unread [count > 1 ? "warnings" : "warning"]! Click here to review and acknowledge them!" + if(countExpire) + src << "
" + src << "[countExpire] of your warnings expired." /* * A proc for an admin/moderator to look up a member's warnings. @@ -243,8 +261,9 @@ /datum/admins/proc/warning_panel(var/adminckey = null, var/playerckey = null) if(!check_rights(R_ADMIN|R_MOD)) return - var/lcolor = "#ffeeee" //light colour, severity = 1 - var/dcolor = "#ffdddd" //dark colour, severity = 2 + var/lcolor = "#ffeeee" //light colour, severity = 0 + var/dcolor = "#ffdddd" //dark colour, severity = 1 + var/ecolor = "#808080" //gray colour, expired = 1 establish_db_connection() if(!dbcon.IsConnected()) @@ -273,8 +292,8 @@ dat += "REASON" dat += "" - adminckey = ckey(adminckey) - playerckey = ckey(playerckey) + adminckey = sanitizeSQL(adminckey) + playerckey = sanitizeSQL(playerckey) var/paramone = "" var/paramtwo = "" if(adminckey) @@ -282,21 +301,30 @@ if(playerckey) paramtwo = "AND ckey = '[playerckey]' " - var/DBQuery/search_query = dbcon.NewQuery("SELECT time, severity, reason, notes, ckey, a_ckey FROM ss13_warnings WHERE 1 [paramone] [paramtwo] ORDER BY time DESC") + var/DBQuery/search_query = dbcon.NewQuery("SELECT id, time, severity, reason, notes, ckey, a_ckey, acknowledged, expired, edited, lasteditor, lasteditdate FROM ss13_warnings WHERE visible = 1 [paramone] [paramtwo] ORDER BY time DESC;") search_query.Execute() + if(search_query.ErrorMsg()) + error("SQL error while activating admin warnings panel. Error text: [search_query.ErrorMsg()].") + while(search_query.NextRow()) - var/time = search_query.item[1] - var/severity = search_query.item[2] - var/reason = search_query.item[3] - var/notes = search_query.item[4] - var/ckey = search_query.item[5] - var/a_ckey = search_query.item[6] + var/id = text2num(search_query.item[1]) + var/time = search_query.item[2] + var/severity = text2num(search_query.item[3]) + var/reason = search_query.item[4] + var/notes = search_query.item[5] + var/ckey = search_query.item[6] + var/a_ckey = search_query.item[7] + var/ackn = text2num(search_query.item[8]) + var/expired = text2num(search_query.item[9]) + var/edited = text2num(search_query.item[10]) var/bgcolor = lcolor - if(severity == "1") + if(severity) bgcolor = dcolor + if(expired) + bgcolor = ecolor dat += "" dat += "[ckey]" @@ -307,6 +335,28 @@ dat += "" dat += "Staff Notes: \"[notes]\"" dat += "" + if(ackn) + dat += "Warning has been acknolwedged by recipient." + else + dat += "Warning has not been acknolwedged by recipient." + if(expired) + dat += "The warning has expired." + else + dat += "The warning is currently active." + if(edited) + var/lastEditor = search_query.item[11] + var/lastEditDate = search_query.item[12] + dat += "Warning last edited: [lastEditDate], by: [lastEditor]." + dat += "" + dat += "Options: " + if(check_rights(R_ADMIN) || a_ckey == sanitizeSQL(ckey)) + dat += "Edit Message " + dat += "Edit Note " + dat += "Delete Warning" + else + dat += "You can only edit or delete notes that you have issued." + dat += "" + dat += "" dat += "" dat += " " @@ -316,3 +366,72 @@ usr << browse(dat, "window=lookupwarns;size=900x500") feedback_add_details("admin_verb","WARN-LKUP") + +/* + * A proc for editing and deleting warnings issued + */ + +/proc/warningsEdit(var/warningId, var/warningEdit) + if(!warningId || !warningEdit) + return + + establish_db_connection() + if(!dbcon.IsConnected()) + error("SQL connection failed while attempting to edit a note!") + return + + var/count = 0 //failsafe + var/aCkey = sanitizeSQL(usr.ckey) + var/ckey + var/reason + var/notes + + var/DBQuery/initialQuery = dbcon.NewQuery("SELECT ckey, reason, notes FROM ss13_warnings WHERE id = '[warningId]';") + initialQuery.Execute() + while(initialQuery.NextRow()) + ckey = initialQuery.item[1] + reason = initialQuery.item[2] + notes = initialQuery.item[3] + count++ + + if(count == 0) + usr << "\red Database update failed due to a warning id not being present in the database." + error("Database update failed due to a warning id not being present in the database.") + return + + if(count > 1) + usr << "\red Database update failed due to multiple warnings having the same ID. Contact the database admin." + error("Database update failed due to multiple warnings having the same ID. Contact the database admin.") + return + + switch(warningEdit) + if("delete") + if(alert("Delete this warning?", "Delete?", "Yes", "No") == "Yes") + var/DBQuery/deleteQuery = dbcon.NewQuery("UPDATE ss13_warnings SET visible = 0 WHERE id = [warningId];") + deleteQuery.Execute() + + message_admins("\blue [key_name_admin(usr)] deleted one of [ckey]'s warnings.") + log_admin("[key_name(usr)] deleted one of [ckey]'s warnings.") + else + usr << "Cancelled" + return + if("editReason") + var/newReason = input("Edit this warning's reason.", "New Reason", "[reason]", null) as null|text + newReason = sql_sanitize_text(newReason) + if(!newReason || newReason == reason) + usr << "Cancelled" + return + var/DBQuery/reasonQuery = dbcon.NewQuery("UPDATE ss13_warnings SET reason = '[newReason]', edited = 1, lasteditor = '[aCkey]', lasteditdate = NOW() WHERE id = '[warningId]';") + reasonQuery.Execute() + message_admins("\blue [key_name_admin(usr)] edited one of [ckey]'s warning reasons.") + log_admin("[key_name(usr)] edited one of [ckey]'s warning reasons.") + if("editNotes") + var/newNotes = input("Edit this warning's notes.", "New Notes", "[notes]", null) as null|text + newNotes = sql_sanitize_text(newNotes) + if(!newNotes || newNotes == notes) + usr << "Cancelled" + return + var/DBQuery/notesQuery = dbcon.NewQuery("UPDATE ss13_warnings SET notes = '[newNotes]', edited = 1, lasteditor = '[aCkey]', lasteditdate = NOW() WHERE id = '[warningId]';") + notesQuery.Execute() + message_admins("\blue [key_name_admin(usr)] edited one of [ckey]'s warning notes.") + log_admin("[key_name(usr)] edited one of [ckey]'s warning notes.")