diff --git a/code/modules/admin/create_poll.dm b/code/modules/admin/create_poll.dm
index 9baa17b73ad..fafcb533c06 100644
--- a/code/modules/admin/create_poll.dm
+++ b/code/modules/admin/create_poll.dm
@@ -1,89 +1,206 @@
/client/proc/create_poll()
set name = "Create Server Poll"
set category = "Server"
- if(!check_rights(R_PERMISSIONS))
+ if(!check_rights(R_SERVER))
return
if(!dbcon.IsConnected())
to_chat(src, "Failed to establish database connection.")
return
- var/returned = create_poll_function()
- if(returned)
- var/DBQuery/query_check_option = dbcon.NewQuery("SELECT id FROM [format_table_name("poll_option")] WHERE pollid = [returned]")
- if(!query_check_option.Execute())
- var/err = query_check_option.ErrorMsg()
- log_game("SQL ERROR obtaining id from poll_option table. Error : \[[err]\]\n")
- return
- if(query_check_option.NextRow())
- var/DBQuery/query_log_get = dbcon.NewQuery("SELECT polltype, question, adminonly FROM [format_table_name("poll_question")] WHERE id = [returned]")
- if(!query_log_get.Execute())
- var/err = query_log_get.ErrorMsg()
- log_game("SQL ERROR obtaining polltype, question, adminonly from poll_question table. Error : \[[err]\]\n")
- return
- if(query_log_get.NextRow())
- var/polltype = query_log_get.item[1]
- var/question = query_log_get.item[2]
- var/adminonly = 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/DBQuery/query_del_poll = dbcon.NewQuery("DELETE FROM [format_table_name("poll_question")] WHERE id = [returned]")
- if(!query_del_poll.Execute())
- var/err = query_del_poll.ErrorMsg()
- log_game("SQL ERROR deleting poll question [returned]. Error : \[[err]\]\n")
- return
+ create_poll_window()
-/client/proc/create_poll_function()
- if(!check_rights(R_PERMISSIONS))
+/client/proc/create_poll_window(var/errormessage = "")
+ if(!check_rights(R_SERVER))
+ return
+ var/output={"
+
+
Show Player Polls (NEW!)
" + output += "Show Player Polls (NEW!)
" else - output += "" + output += "" output += "" @@ -188,61 +188,6 @@ else if(!href_list["late_join"]) new_player_panel() - if(href_list["showpoll"]) - - handle_player_polling() - return - - if(href_list["pollid"]) - - var/pollid = href_list["pollid"] - if(istext(pollid)) - pollid = text2num(pollid) - if(isnum(pollid)) - src.poll_player(pollid) - return - - if(href_list["votepollid"] && href_list["votetype"]) - var/pollid = text2num(href_list["votepollid"]) - var/votetype = href_list["votetype"] - switch(votetype) - if("OPTION") - var/optionid = text2num(href_list["voteoptionid"]) - vote_on_poll(pollid, optionid) - if("TEXT") - var/replytext = href_list["replytext"] - log_text_poll_reply(pollid, replytext) - if("NUMVAL") - var/id_min = text2num(href_list["minid"]) - var/id_max = text2num(href_list["maxid"]) - - if( (id_max - id_min) > 100 ) //Basic exploit prevention - to_chat(usr, "The option ID difference is too big. Please contact administration or the database admin.") - return - - for(var/optionid = id_min; optionid <= id_max; optionid++) - if(!isnull(href_list["o[optionid]"])) //Test if this optionid was replied to - var/rating - if(href_list["o[optionid]"] == "abstain") - rating = null - else - rating = text2num(href_list["o[optionid]"]) - if(!isnum(rating)) - return - - vote_on_numval_poll(pollid, optionid, rating) - if("MULTICHOICE") - var/id_min = text2num(href_list["minoptionid"]) - var/id_max = text2num(href_list["maxoptionid"]) - - if( (id_max - id_min) > 100 ) //Basic exploit prevention - to_chat(usr, "The option ID difference is too big. Please contact administration or the database admin.") - return - - for(var/optionid = id_min; optionid <= id_max; optionid++) - if(!isnull(href_list["option_[optionid]"])) //Test if this optionid was selected - vote_on_poll(pollid, optionid, 1) - /mob/new_player/proc/IsJobAvailable(rank) var/datum/job/job = job_master.GetJob(rank) if(!job) return 0 diff --git a/code/modules/mob/new_player/poll.dm b/code/modules/mob/new_player/poll.dm index f85a8c9ded1..961740001d7 100644 --- a/code/modules/mob/new_player/poll.dm +++ b/code/modules/mob/new_player/poll.dm @@ -2,45 +2,208 @@ var/optionid var/optiontext -/mob/new_player/proc/handle_player_polling() +/client/verb/polls_verb() + set name = "Show Player Polls" + set category = "OOC" + handle_player_polling() + +/client/proc/can_vote() + return player_age >= 30 + +/client/proc/handle_player_polling() establish_db_connection() if(dbcon.IsConnected()) var/isadmin = 0 - if(src.client && src.client.holder) + if(holder) isadmin = 1 - var/DBQuery/select_query = dbcon.NewQuery("SELECT id, question FROM [format_table_name("poll_question")] WHERE [(isadmin ? "" : "adminonly = false AND")] Now() BETWEEN starttime AND endtime") + var/DBQuery/select_query = dbcon.NewQuery("SELECT id, question, (id IN (SELECT pollid FROM [format_table_name("poll_vote")] WHERE ckey = '[ckey]') OR id IN (SELECT pollid FROM [format_table_name("poll_textreply")] WHERE ckey = '[ckey]')) AS voted FROM [format_table_name("poll_question")] WHERE [(isadmin ? "" : "adminonly = false AND")] Now() BETWEEN starttime AND endtime") select_query.Execute() var/output = "| Active Polls |
|---|
| [pollquestion] |
| [pollquestion] |
| [poll_player(pollid, 1)] |
| Expired Polls |
| [pollquestion] |
| [question] [starttime] - [endtime] |
+ |||
|---|---|---|---|
"}
+ var/list/colors = list("#66c2a5", "#fc8d62", "#8da0cb", "#e78ac3", "#a6d854", "#ffd92f", "#e5c494", "#b3b3b3")
+ var/color_index = 0
+ for(var/list/option in options)
+ var/bar_width = option[3] * 700 / total_votes
+ var/percentage = option[2] ? "[round(option[3] * 100 / total_percent_votes)]%" : "N/A"
+ color_index++
+ if(color_index > colors.len)
+ color_index = 1
+ output += ""
+ output += " (Hover over the colored bar to read description) | |||
| [option[1]] | " + output += "[option[3]] | " + output += "[percentage] | " + output += "" + output += " |
| [question] [starttime] - [endtime] |
+ |||||||
|---|---|---|---|---|---|---|---|
| [select_query.item[2]] + | N = [select_query.item[4]] + | AVG = [select_query.item[3]] + |
| ||||
| [question] [starttime] - [endtime] |
+ |
|---|---|
| [ckeys] ([countresponse] player\s) responded with: | +[replytext] | +
" - - if(!voted) //Only make this a form if we have not voted yet - output += "
" output += "" - if(!voted) //Only make this a form if we have not voted yet - output += "
" - output += "" else output += "[vote_text]" - - src << browse(output,"window=playerpoll;size=500x500") + + if(inline) + return output + else + src << browse(output,"window=playerpoll;size=500x500") //Polls with a text input if(POLLTYPE_RATING) - var/DBQuery/voted_query = dbcon.NewQuery("SELECT o.text, v.rating FROM [format_table_name("poll_option")] o, erro_poll_vote v WHERE o.pollid = [pollid] AND v.ckey = '[usr.ckey]' AND o.id = v.optionid") + var/DBQuery/voted_query = dbcon.NewQuery("SELECT o.text, v.rating FROM [format_table_name("poll_option")] o, erro_poll_vote v WHERE o.pollid = [pollid] AND v.ckey = '[ckey]' AND o.id = v.optionid") voted_query.Execute() - - var/output = ""
@@ -177,9 +350,8 @@
output += "
[optiontext] - [rating]"
- if(!voted) //Only make this a form if we have not voted yet
- output += "
" - if(!voted) //Only make this a form if we have not voted yet - output += "
" output += "