Skip to content

Commit

Permalink
memo update
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordie0608 committed Jul 28, 2015
1 parent 8906c49 commit f7489b1
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 27 deletions.
10 changes: 10 additions & 0 deletions SQL/database_changelog.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 1 addition & 2 deletions SQL/tgstation_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 */;

Expand Down
3 changes: 1 addition & 2 deletions SQL/tgstation_schema_prefixed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 */;

Expand Down
54 changes: 34 additions & 20 deletions code/modules/admin/admin_memo.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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<br>[old_memo]<br>to<br>[new_memo]<hr>"
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")
Expand All @@ -62,32 +70,38 @@
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<br>[old_memo]<br>to<br>[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 += "<span class='memo'>Memo by <span class='prefix'>[ckey]</span> 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 += "<span class='memo'>Memo by <span class='prefix'>[ckey]</span> on [timestamp]"
if(last_editor)
output += "<br><span class='memoedit'>Last edit by [last_editor] <A href='?_src_=holder;memoeditlist=[id]'>(Click here to see edit log)</A></span>"
output += "<br><span class='memoedit'>Last edit by [last_editor] <A href='?_src_=holder;memoeditlist=[ckey]'>(Click here to see edit log)</A></span>"
output += "<br>[memotext]</span><br>"
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")]")
if(!query_memodellist.Execute())
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
Expand Down
10 changes: 7 additions & 3 deletions code/modules/admin/topic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down

0 comments on commit f7489b1

Please sign in to comment.