From f7489b18afd36380b3052640818c92cc7bd93959 Mon Sep 17 00:00:00 2001 From: Jordie0608 Date: Tue, 28 Jul 2015 21:42:25 +1000 Subject: [PATCH] memo update --- SQL/database_changelog.txt | 10 ++++++ SQL/tgstation_schema.sql | 3 +- SQL/tgstation_schema_prefixed.sql | 3 +- code/modules/admin/admin_memo.dm | 54 +++++++++++++++++++------------ code/modules/admin/topic.dm | 10 ++++-- 5 files changed, 53 insertions(+), 27 deletions(-) diff --git a/SQL/database_changelog.txt b/SQL/database_changelog.txt index 9a56620e157ac..bf305298ce2da 100644 --- a/SQL/database_changelog.txt +++ b/SQL/database_changelog.txt @@ -1,3 +1,13 @@ +28 July 2015, by Jordie0608 + +Modified table 'memo', removing 'id' column and making 'ckey' primary. + +ALTER TABLE `feedback`.`memo` DROP COLUMN `id`, DROP PRIMARY KEY, ADD PRIMARY KEY (`ckey`) + +Remember to add prefix to the table name if you use them. + +---------------------------------------------------- + 19 July 2015, by Jordie0608 Added new table 'memo' for use with admin memos. diff --git a/SQL/tgstation_schema.sql b/SQL/tgstation_schema.sql index b6797101692fc..caeec1c432c83 100644 --- a/SQL/tgstation_schema.sql +++ b/SQL/tgstation_schema.sql @@ -329,13 +329,12 @@ DROP TABLE IF EXISTS `memo`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `memo` ( - `id` int(11) NOT NULL AUTO_INCREMENT, `ckey` varchar(32) NOT NULL, `memotext` text NOT NULL, `timestamp` datetime NOT NULL, `last_editor` varchar(32), `edits` text, - PRIMARY KEY (`id`) + PRIMARY KEY (`ckey`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; diff --git a/SQL/tgstation_schema_prefixed.sql b/SQL/tgstation_schema_prefixed.sql index 70e02e2c3049d..93ba765835d46 100644 --- a/SQL/tgstation_schema_prefixed.sql +++ b/SQL/tgstation_schema_prefixed.sql @@ -324,13 +324,12 @@ DROP TABLE IF EXISTS `SS13_memo`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `SS13_memo` ( - `id` int(11) NOT NULL AUTO_INCREMENT, `ckey` varchar(32) NOT NULL, `memotext` text NOT NULL, `timestamp` datetime NOT NULL, `last_editor` varchar(32), `edits` text, - PRIMARY KEY (`id`) + PRIMARY KEY (`ckey`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; diff --git a/code/modules/admin/admin_memo.dm b/code/modules/admin/admin_memo.dm index 774f55ce6ae1c..791f22a56d30d 100644 --- a/code/modules/admin/admin_memo.dm +++ b/code/modules/admin/admin_memo.dm @@ -8,6 +8,14 @@ var/sql_ckey = sanitizeSQL(src.ckey) switch(task) if("Write") + var/DBQuery/query_memocheck = dbcon.NewQuery("SELECT ckey FROM [format_table_name("memo")] WHERE (ckey = '[sql_ckey]')") + if(!query_memocheck.Execute()) + var/err = query_memocheck.ErrorMsg() + log_game("SQL ERROR obtaining ckey from memo table. Error : \[[err]\]\n") + return + if(query_memocheck.NextRow()) + src << "You already have set a memo." + return var/memotext = input(src,"Write your Memo","Memo") as text|null if(!memotext) return @@ -26,13 +34,13 @@ var/err = query_memolist.ErrorMsg() log_game("SQL ERROR obtaining ckey from memo table. Error : \[[err]\]\n") return - if(!query_memolist.NextRow()) - src << "No memos found in database." - return var/list/memolist = list() while(query_memolist.NextRow()) - var/ckey = query_memolist.item[2] - memolist += "[ckey]" + var/lkey = query_memolist.item[1] + memolist += "[lkey]" + if(!memolist.len) + src << "No memos found in database." + return var/target_ckey = input(src, "Select whose memo to edit", "Select memo") as null|anything in memolist if(!target_ckey) return @@ -43,14 +51,14 @@ log_game("SQL ERROR obtaining ckey, memotext from memo table. Error : \[[err]\]\n") return if(query_memofind.NextRow()) - var/old_memo = query_memofind.item[3] + var/old_memo = query_memofind.item[2] var/new_memo = input("Input new memo", "New Memo", "[old_memo]", null) as null|text if(!new_memo) return new_memo = sanitizeSQL(new_memo) var/edit_text = "Edited by [sql_ckey] on [SQLtime()] from
[old_memo]
to
[new_memo]
" edit_text = sanitizeSQL(edit_text) - var/DBQuery/update_query = dbcon.NewQuery("UPDATE [format_table_name("memo")] SET memotext = '[new_memo]', last_editor = '[sql_ckey]', edits = CONCAT(edits,'[edit_text]') WHERE (ckey = '[target_sql_ckey]')") + var/DBQuery/update_query = dbcon.NewQuery("UPDATE [format_table_name("memo")] SET memotext = '[new_memo]', last_editor = '[sql_ckey]', edits = CONCAT(IFNULL(edits,''),'[edit_text]') WHERE (ckey = '[target_sql_ckey]')") if(!update_query.Execute()) var/err = update_query.ErrorMsg() log_game("SQL ERROR editing memo. Error : \[[err]\]\n") @@ -62,18 +70,24 @@ log_admin("[key_name(src)] has edited [target_sql_ckey]'s memo from [old_memo] to [new_memo]") message_admins("[key_name_admin(src)] has edited [target_sql_ckey]'s memo from
[old_memo]
to
[new_memo]") if("Show") - var/DBQuery/query_memoshow = dbcon.NewQuery("SELECT id, ckey, memotext, timestamp, last_editor FROM [format_table_name("memo")])") - var/output + var/DBQuery/query_memoshow = dbcon.NewQuery("SELECT ckey, memotext, timestamp, last_editor FROM [format_table_name("memo")]") + if(!query_memoshow.Execute()) + var/err = query_memoshow.ErrorMsg() + log_game("SQL ERROR obtaining ckey, memotext, timestamp, last_editor from memo table. Error : \[[err]\]\n") + return + var/output = null while(query_memoshow.NextRow()) - var/id = query_memoshow.item[1] - var/ckey = query_memoshow.item[2] - var/memotext = query_memoshow.item[3] - var/timestamp = query_memoshow.item[4] - var/last_editor = query_memoshow.item[5] - output += "Memo by [ckey] on [timestamp]:" + var/ckey = query_memoshow.item[1] + var/memotext = query_memoshow.item[2] + var/timestamp = query_memoshow.item[3] + var/last_editor = query_memoshow.item[4] + output += "Memo by [ckey] on [timestamp]" if(last_editor) - output += "
Last edit by [last_editor] (Click here to see edit log)" + output += "
Last edit by [last_editor] (Click here to see edit log)" output += "
[memotext]

" + if(!output) + src << "No memos found in database." + return src << output if("Remove") var/DBQuery/query_memodellist = dbcon.NewQuery("SELECT ckey FROM [format_table_name("memo")]") @@ -81,13 +95,13 @@ var/err = query_memodellist.ErrorMsg() log_game("SQL ERROR obtaining ckey from memo table. Error : \[[err]\]\n") return - if(!query_memodellist.NextRow()) - src << "No memos found in database." - return var/list/memolist = list() while(query_memodellist.NextRow()) - var/ckey = query_memodellist.item[2] + var/ckey = query_memodellist.item[1] memolist += "[ckey]" + if(!memolist.len) + src << "No memos found in database." + return var/target_ckey = input(src, "Select whose memo to delete", "Select memo") as null|anything in memolist if(!target_ckey) return diff --git a/code/modules/admin/topic.dm b/code/modules/admin/topic.dm index 6f0493a0f8611..b1ce38e14d751 100644 --- a/code/modules/admin/topic.dm +++ b/code/modules/admin/topic.dm @@ -2058,10 +2058,14 @@ src.access_news_network() else if(href_list["memoeditlist"]) - var/DBQuery/query_memoedits = dbcon.NewQuery("SELECT edits FROM [format_table_name("memo")] WHERE (id = '[href_list["id"]]") - query_memoedits.Execute() + var/sql_key = sanitizeSQL("[href_list["memoeditlist"]]") + var/DBQuery/query_memoedits = dbcon.NewQuery("SELECT edits FROM [format_table_name("memo")] WHERE (ckey = '[sql_key]')") + if(!query_memoedits.Execute()) + var/err = query_memoedits.ErrorMsg() + log_game("SQL ERROR obtaining edits from memo table. Error : \[[err]\]\n") + return if(query_memoedits.NextRow()) - var/edit_log = query_memoedits.item[6] + var/edit_log = query_memoedits.item[1] usr << browse(edit_log,"window=memoeditlist") else if(href_list["check_antagonist"])