diff --git a/SQL/database_changelog.txt b/SQL/database_changelog.txt
index ab183ee1588..43765681eea 100644
--- a/SQL/database_changelog.txt
+++ b/SQL/database_changelog.txt
@@ -1,3 +1,13 @@
+22 June 2017, by Jordie0608
+
+Modified table 'poll_option', removing the column 'percentagecalc'.
+
+ALTER TABLE `feedback`.`poll_option` DROP COLUMN `percentagecalc`
+
+Remember to add a prefix to the table name if you use them.
+
+----------------------------------------------------
+
8 June 2017, by Jordie0608
Modified table 'death', adding column 'round_id', removing column 'gender' and replacing column 'coord' with the columns 'x_coord', 'y_coord' and 'z_coord'.
diff --git a/SQL/tgstation_schema.sql b/SQL/tgstation_schema.sql
index 8dd84f6a874..39717cc449d 100644
--- a/SQL/tgstation_schema.sql
+++ b/SQL/tgstation_schema.sql
@@ -288,7 +288,6 @@ CREATE TABLE `poll_option` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`pollid` int(11) NOT NULL,
`text` varchar(255) NOT NULL,
- `percentagecalc` tinyint(1) NOT NULL DEFAULT '1',
`minval` int(3) DEFAULT NULL,
`maxval` int(3) DEFAULT NULL,
`descmin` varchar(32) DEFAULT NULL,
diff --git a/SQL/tgstation_schema_prefixed.sql b/SQL/tgstation_schema_prefixed.sql
index 3adb722f4db..3ccac32bd94 100644
--- a/SQL/tgstation_schema_prefixed.sql
+++ b/SQL/tgstation_schema_prefixed.sql
@@ -288,7 +288,6 @@ CREATE TABLE `SS13_poll_option` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`pollid` int(11) NOT NULL,
`text` varchar(255) NOT NULL,
- `percentagecalc` tinyint(1) NOT NULL DEFAULT '1',
`minval` int(3) DEFAULT NULL,
`maxval` int(3) DEFAULT NULL,
`descmin` varchar(32) DEFAULT NULL,
diff --git a/code/modules/admin/create_poll.dm b/code/modules/admin/create_poll.dm
index 92abf6d46d7..61efa9514ed 100644
--- a/code/modules/admin/create_poll.dm
+++ b/code/modules/admin/create_poll.dm
@@ -3,31 +3,9 @@
set category = "Special Verbs"
if(!check_rights(R_PERMISSIONS))
return
- if(!SSdbcore.IsConnected())
+ if(!SSdbcore.Connect())
to_chat(src, "Failed to establish database connection.")
return
- var/returned = create_poll_function()
- if(returned)
- var/datum/DBQuery/query_check_option = SSdbcore.NewQuery("SELECT id FROM [format_table_name("poll_option")] WHERE pollid = [returned]")
- if(!query_check_option.warn_execute())
- return
- if(query_check_option.NextRow())
- var/datum/DBQuery/query_log_get = SSdbcore.NewQuery("SELECT polltype, question, adminonly FROM [format_table_name("poll_question")] WHERE id = [returned]")
- if(!query_log_get.warn_execute())
- return
- if(query_log_get.NextRow())
- var/polltype = query_log_get.item[1]
- var/question = query_log_get.item[2]
- var/adminonly = text2num(query_log_get.item[3])
- log_admin("[key_name(usr)] has created a new server poll. Poll type: [polltype] - Admin Only: [adminonly ? "Yes" : "No"] - Question: [question]")
- message_admins("[key_name_admin(usr)] has created a new server poll. Poll type: [polltype] - Admin Only: [adminonly ? "Yes" : "No"]
Question: [question]")
- else
- to_chat(src, "Poll question created without any options, poll will be deleted.")
- var/datum/DBQuery/query_del_poll = SSdbcore.NewQuery("DELETE FROM [format_table_name("poll_question")] WHERE id = [returned]")
- if(!query_del_poll.warn_execute())
- return
-
-/client/proc/create_poll_function()
var/polltype = input("Choose poll type.","Poll Type") in list("Single Option","Text Reply","Rating","Multiple Choice", "Instant Runoff Voting")|null
var/choice_amount = 0
switch(polltype)
@@ -40,7 +18,9 @@
if("Multiple Choice")
polltype = POLLTYPE_MULTI
choice_amount = input("How many choices should be allowed?","Select choice amount") as num|null
- if(!choice_amount)
+ if(choice_amount == 0)
+ to_chat(src, "Multiple choice poll must have at least one choice allowed.")
+ else if (choice_amount == null)
return
if ("Instant Runoff Voting")
polltype = POLLTYPE_IRV
@@ -51,22 +31,15 @@
if(!endtime)
return
endtime = sanitizeSQL(endtime)
- var/datum/DBQuery/query_validate_time = SSdbcore.NewQuery("SELECT STR_TO_DATE('[endtime]','%Y-%c-%d %T')")
+ var/datum/DBQuery/query_validate_time = SSdbcore.NewQuery("SELECT IF(STR_TO_DATE('[endtime]','%Y-%c-%d %T') > NOW(), STR_TO_DATE('[endtime]','%Y-%c-%d %T'), 0)")
if(!query_validate_time.warn_execute())
return
if(query_validate_time.NextRow())
+ var/checktime = text2num(query_validate_time.item[1])
+ if(!checktime)
+ to_chat(src, "Datetime entered is improperly formatted or not later than current server time.")
+ return
endtime = query_validate_time.item[1]
- if(!endtime)
- to_chat(src, "Datetime entered is invalid.")
- return
- var/datum/DBQuery/query_time_later = SSdbcore.NewQuery("SELECT TIMESTAMP('[endtime]') < NOW()")
- if(!query_time_later.warn_execute())
- return
- if(query_time_later.NextRow())
- var/checklate = text2num(query_time_later.item[1])
- if(checklate)
- to_chat(src, "Datetime entered is not later than current server time.")
- return
var/adminonly
switch(alert("Admin only poll?",,"Yes","No","Cancel"))
if("Yes")
@@ -88,72 +61,68 @@
if(!question)
return
question = sanitizeSQL(question)
+ var/list/sql_option_list = list()
+ if(polltype != POLLTYPE_TEXT)
+ var/add_option = 1
+ while(add_option)
+ var/option = input("Write your option","Option") as message|null
+ if(!option)
+ return
+ option = sanitizeSQL(option)
+ var/minval = 0
+ var/maxval = 0
+ var/descmin = ""
+ var/descmid = ""
+ var/descmax = ""
+ if(polltype == POLLTYPE_RATING)
+ minval = input("Set minimum rating value.","Minimum rating") as num|null
+ if(minval)
+ minval = sanitizeSQL(minval)
+ else if(minval == null)
+ return
+ maxval = input("Set maximum rating value.","Maximum rating") as num|null
+ if(maxval)
+ maxval = sanitizeSQL(maxval)
+ if(minval >= maxval)
+ to_chat(src, "Maximum rating value can't be less than or equal to minimum rating value")
+ continue
+ else if(maxval == null)
+ return
+ descmin = input("Optional: Set description for minimum rating","Minimum rating description") as message|null
+ if(descmin)
+ descmin = sanitizeSQL(descmin)
+ else if(descmin == null)
+ return
+ descmid = input("Optional: Set description for median rating","Median rating description") as message|null
+ if(descmid)
+ descmid = sanitizeSQL(descmid)
+ else if(descmid == null)
+ return
+ descmax = input("Optional: Set description for maximum rating","Maximum rating description") as message|null
+ if(descmax)
+ descmax = sanitizeSQL(descmax)
+ else if(descmax == null)
+ return
+ sql_option_list += list(list("text" = "'[option]'", "minval" = "'[minval]'", "maxval" = "'[maxval]'", "descmin" = "'[descmin]'", "descmid" = "'[descmid]'", "descmax" = "'[descmax]'"))
+ switch(alert(" ",,"Add option","Finish", "Cancel"))
+ if("Add option")
+ add_option = 1
+ if("Finish")
+ add_option = 0
+ else
+ return 0
var/datum/DBQuery/query_polladd_question = SSdbcore.NewQuery("INSERT INTO [format_table_name("poll_question")] (polltype, starttime, endtime, question, adminonly, multiplechoiceoptions, createdby_ckey, createdby_ip, dontshow) VALUES ('[polltype]', '[starttime]', '[endtime]', '[question]', '[adminonly]', '[choice_amount]', '[sql_ckey]', INET_ATON('[address]'), '[dontshow]')")
if(!query_polladd_question.warn_execute())
return
- if(polltype == POLLTYPE_TEXT)
- log_admin("[key_name(usr)] has created a new server poll. Poll type: [polltype] - Admin Only: [adminonly ? "Yes" : "No"] - Question: [question]")
- message_admins("[key_name_admin(usr)] has created a new server poll. Poll type: [polltype] - Admin Only: [adminonly ? "Yes" : "No"]
Question: [question]")
- return
- var/pollid = 0
- var/datum/DBQuery/query_get_id = SSdbcore.NewQuery("SELECT id FROM [format_table_name("poll_question")] WHERE question = '[question]' AND starttime = '[starttime]' AND endtime = '[endtime]' AND createdby_ckey = '[sql_ckey]' AND createdby_ip = INET_ATON('[address]')")
- if(!query_get_id.warn_execute())
- return
- if(query_get_id.NextRow())
- pollid = query_get_id.item[1]
- var/add_option = 1
- while(add_option)
- var/option = input("Write your option","Option") as message|null
- if(!option)
- return pollid
- option = sanitizeSQL(option)
- var/percentagecalc = 1
- if (polltype != POLLTYPE_IRV)
- switch(alert("Calculate option results as percentage?",,"Yes","No","Cancel"))
- if("Yes")
- percentagecalc = 1
- if("No")
- percentagecalc = 0
- else
- return pollid
- var/minval = 0
- var/maxval = 0
- var/descmin = ""
- var/descmid = ""
- var/descmax = ""
- if(polltype == POLLTYPE_RATING)
- minval = input("Set minimum rating value.","Minimum rating") as num|null
- if(!minval)
- return pollid
- maxval = input("Set maximum rating value.","Maximum rating") as num|null
- if(!maxval)
- return pollid
- if(minval >= maxval)
- to_chat(src, "Minimum rating value can't be more than maximum rating value")
- return pollid
- descmin = input("Optional: Set description for minimum rating","Minimum rating description") as message|null
- if(descmin)
- descmin = sanitizeSQL(descmin)
- else if(descmin == null)
- return pollid
- descmid = input("Optional: Set description for median rating","Median rating description") as message|null
- if(descmid)
- descmid = sanitizeSQL(descmid)
- else if(descmid == null)
- return pollid
- descmax = input("Optional: Set description for maximum rating","Maximum rating description") as message|null
- if(descmax)
- descmax = sanitizeSQL(descmax)
- else if(descmax == null)
- return pollid
- var/datum/DBQuery/query_polladd_option = SSdbcore.NewQuery("INSERT INTO [format_table_name("poll_option")] (pollid, text, percentagecalc, minval, maxval, descmin, descmid, descmax) VALUES ('[pollid]', '[option]', '[percentagecalc]', '[minval]', '[maxval]', '[descmin]', '[descmid]', '[descmax]')")
- if(!query_polladd_option.warn_execute())
- return pollid
- switch(alert(" ",,"Add option","Finish", "Cancel"))
- if("Add option")
- add_option = 1
- if("Finish")
- add_option = 0
- else
- return 0
- return pollid
\ No newline at end of file
+ if(polltype != POLLTYPE_TEXT)
+ var/pollid = 0
+ var/datum/DBQuery/query_get_id = SSdbcore.NewQuery("SELECT LAST_INSERT_ID()")
+ if(!query_get_id.warn_execute())
+ return
+ if(query_get_id.NextRow())
+ pollid = query_get_id.item[1]
+ for(var/list/i in sql_option_list)
+ i |= list("pollid" = "'[pollid]'")
+ SSdbcore.MassInsert(format_table_name("poll_option"), sql_option_list, warn = 1)
+ log_admin("[key_name(usr)] has created a new server poll. Poll type: [polltype] - Admin Only: [adminonly ? "Yes" : "No"] - Question: [question]")
+ message_admins("[key_name_admin(usr)] has created a new server poll. Poll type: [polltype] - Admin Only: [adminonly ? "Yes" : "No"]
Question: [question]")