Adds an option to use templates from the WI in command reports (#474)

90% of the work here was Skull's since I had no idea how to access and pull information from the DB.
It's also a semi-fix for #433
This commit is contained in:
Bedshaped
2016-07-05 19:23:09 +01:00
committed by skull132
parent fe50c59d19
commit 2c4e3ce19a
4 changed files with 58 additions and 10 deletions
+44 -10
View File
@@ -510,30 +510,64 @@ Traitors and the like can also be revived with the previous role mostly intact.
if(!holder)
src << "Only administrators may use this command."
return
var/input = sanitize(input(usr, "Please enter anything you want. Anything. Serious.", "What?", "") as message|null, extra = 0)
var/customname = sanitizeSafe(input(usr, "Pick a title for the report.", "Title") as text|null)
if(!input)
return
if(!customname)
customname = "NanoTrasen Update"
var/reporttitle
var/reportbody
var/reporter
var/reporttype = input(usr, "Choose whether to use a template or custom report.", "Create Command Report") in list("Template", "Custom", "Cancel")
switch(reporttype)
if("Template")
establish_db_connection(dbcon)
if (!dbcon.IsConnected())
src << "<span class='notice'>Unable to connect to the database.</span>"
return
var/DBQuery/query = dbcon.NewQuery("SELECT title, message FROM ss13_ccia_general_notice_list WHERE deleted_at IS NULL")
query.Execute()
var/list/template_names = list()
var/templates[] = list()
while (query.NextRow())
template_names += query.item[1]
templates[query.item[1]] = query.item[2]
// Catch empty list
if (!templates.len)
src << "<span class='notice'>There are no templates in the database.</span>"
return
reporttitle = input(usr, "Please select a command report template.", "Create Command Report") in list(template_names)
reportbody = templates[reporttitle]
if("Custom")
reporttitle = sanitizeSafe(input(usr, "Pick a title for the report.", "Title") as text|null)
if(!reporttitle)
reporttitle = "NanoTrasen Update"
reportbody = sanitize(input(usr, "Please enter anything you want. Anything. Serious.", "Body", "") as message|null, extra = 0)
if(!reportbody)
return
else
return
for (var/obj/machinery/computer/communications/C in machines)
if(! (C.stat & (BROKEN|NOPOWER) ) )
var/obj/item/weapon/paper/P = new /obj/item/weapon/paper( C.loc )
P.name = "'[command_name()] Update.'"
P.info = replacetext(input, "\n", "<br/>")
P.name = "[command_name()] Update"
P.info = replacetext(reportbody, "\n", "<br/>")
P.update_space(P.info)
P.update_icon()
C.messagetitle.Add("[command_name()] Update")
C.messagetext.Add(P.info)
reporter = sanitizeSafe(input(usr, "Please enter your name.", "Name") as text|null)
switch(alert("Should this be announced to the general population?",,"Yes","No"))
if("Yes")
command_announcement.Announce(input, customname, new_sound = 'sound/AI/commandreport.ogg', msg_sanitized = 1);
command_announcement.Announce("[reportbody]\n\n- [reporter], Central Command Internal Affairs Agent, [commstation_name()]", reporttitle, new_sound = 'sound/AI/commandreport.ogg', msg_sanitized = 1);
if("No")
world << "\red New NanoTrasen Update available at all communication consoles."
world << sound('sound/AI/commandreport.ogg')
log_admin("[key_name(src)] has created a command report: [input]")
log_admin("[key_name(src)] has created a command report: [reportbody]")
message_admins("[key_name_admin(src)] has created a command report", 1)
feedback_add_details("admin_verb","CCR") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!