"
output += span_normal("Feedback gathering runs from " + span_bold("[pollstarttime]") + " until " + span_bold("[pollendtime]")) + "
"
if(!voted) //Only make this a form if we have not voted yet
output += "
"
else
output += "[vote_text]"
src << browse("[output]","window=playerpoll;size=500x500")
//Polls with a text input
if("NUMVAL")
var/datum/db_query/voted_query = SSdbcore.NewQuery("SELECT o.text, v.rating FROM erro_poll_option o, erro_poll_vote v WHERE o.pollid = [pollid] AND v.ckey = '[usr.ckey]' AND o.id = v.optionid")
voted_query.Execute()
var/output = "
" + span_bold("Player poll")
output +="
"
output += span_bold("Question: [pollquestion]") + "
"
output += span_normal("Poll runs from " + span_bold("[pollstarttime]") + " until " + span_bold("[pollendtime]")) + "
"
var/voted = 0
while(voted_query.NextRow())
voted = 1
var/optiontext = voted_query.item[1]
var/rating = voted_query.item[2]
output += "
" + span_bold("[optiontext] - [rating]") + ""
qdel(voted_query)
if(!voted) //Only make this a form if we have not voted yet
output += "
"
src << browse("[output]","window=playerpoll;size=500x500")
if("MULTICHOICE")
var/datum/db_query/voted_query = SSdbcore.NewQuery("SELECT optionid FROM erro_poll_vote WHERE pollid = [pollid] AND ckey = '[usr.ckey]'")
voted_query.Execute()
var/list/votedfor = list()
var/voted = 0
while(voted_query.NextRow())
votedfor.Add(text2num(voted_query.item[1]))
voted = 1
qdel(voted_query)
var/list/datum/polloption/options = list()
var/maxoptionid = 0
var/minoptionid = 0
var/datum/db_query/options_query = SSdbcore.NewQuery("SELECT id, text FROM erro_poll_option WHERE pollid = [pollid]")
options_query.Execute()
while(options_query.NextRow())
var/datum/polloption/PO = new()
PO.optionid = text2num(options_query.item[1])
PO.optiontext = options_query.item[2]
if(PO.optionid > maxoptionid)
maxoptionid = PO.optionid
if(PO.optionid < minoptionid || !minoptionid)
minoptionid = PO.optionid
options += PO
qdel(options_query)
if(select_query.item[5])
multiplechoiceoptions = text2num(select_query.item[5])
var/output = "
" + span_bold("Player poll")
output +="
"
output += span_bold("Question: [pollquestion]") + "
You can select up to [multiplechoiceoptions] options. If you select more, the first [multiplechoiceoptions] will be saved.
"
output += span_normal("Poll runs from " + span_bold("[pollstarttime]") + " until " + span_bold("[pollendtime]")) + "
"
if(!voted) //Only make this a form if we have not voted yet
output += "
"
output += "
"
src << browse("[output]","window=playerpoll;size=500x250")
return
/mob/new_player/proc/vote_on_poll(var/pollid = -1, var/optionid = -1, var/multichoice = 0)
if(pollid == -1 || optionid == -1)
return
if(!isnum(pollid) || !isnum(optionid))
return
if(SSdbcore.IsConnected())
var/datum/db_query/select_query = SSdbcore.NewQuery("SELECT starttime, endtime, question, polltype, multiplechoiceoptions FROM erro_poll_question WHERE id = [pollid] AND Now() BETWEEN starttime AND endtime")
select_query.Execute()
var/validpoll = 0
var/multiplechoiceoptions = 0
while(select_query.NextRow())
if(select_query.item[4] != "OPTION" && select_query.item[4] != "MULTICHOICE")
return
validpoll = 1
if(select_query.item[5])
multiplechoiceoptions = text2num(select_query.item[5])
break
qdel(select_query)
if(!validpoll)
to_chat(usr, span_red("Poll is not valid."))
return
var/datum/db_query/select_query2 = SSdbcore.NewQuery("SELECT id FROM erro_poll_option WHERE id = [optionid] AND pollid = [pollid]")
select_query2.Execute()
var/validoption = 0
while(select_query2.NextRow())
validoption = 1
break
qdel(select_query2)
if(!validoption)
to_chat(usr, span_red("Poll option is not valid."))
return
var/alreadyvoted = 0
var/datum/db_query/voted_query = SSdbcore.NewQuery("SELECT id FROM erro_poll_vote WHERE pollid = [pollid] AND ckey = '[usr.ckey]'")
voted_query.Execute()
while(voted_query.NextRow())
alreadyvoted += 1
if(!multichoice)
break
qdel(voted_query)
if(!multichoice && alreadyvoted)
to_chat(usr, span_red("You already voted in this poll."))
return
if(multichoice && (alreadyvoted >= multiplechoiceoptions))
to_chat(usr, span_red("You already have more than [multiplechoiceoptions] logged votes on this poll. Enough is enough. Contact the database admin if this is an error."))
return
var/adminrank = "Player"
if(usr && usr.client && usr.client.holder)
adminrank = usr.client.holder.rank_names()
var/datum/db_query/insert_query = SSdbcore.NewQuery("INSERT INTO erro_poll_vote (id ,datetime ,pollid ,optionid ,ckey ,ip ,adminrank) VALUES (null, Now(), [pollid], [optionid], '[usr.ckey]', '[usr.client.address]', '[adminrank]')")
insert_query.Execute()
to_chat(usr, span_blue("Vote successful."))
qdel(insert_query)
usr << browse(null,"window=playerpoll")
/mob/new_player/proc/log_text_poll_reply(var/pollid = -1, var/replytext = "")
if(pollid == -1 || replytext == "")
return
if(!isnum(pollid) || !istext(replytext))
return
if(SSdbcore.IsConnected())
var/datum/db_query/select_query = SSdbcore.NewQuery("SELECT starttime, endtime, question, polltype FROM erro_poll_question WHERE id = [pollid] AND Now() BETWEEN starttime AND endtime")
select_query.Execute()
var/validpoll = 0
while(select_query.NextRow())
if(select_query.item[4] != "TEXT")
return
validpoll = 1
break
qdel(select_query)
if(!validpoll)
to_chat(usr, span_red("Poll is not valid."))
return
var/alreadyvoted = 0
var/datum/db_query/voted_query = SSdbcore.NewQuery("SELECT id FROM erro_poll_textreply WHERE pollid = [pollid] AND ckey = '[usr.ckey]'")
voted_query.Execute()
while(voted_query.NextRow())
alreadyvoted = 1
break
qdel(voted_query)
if(alreadyvoted)
to_chat(usr, span_red("You already sent your feedback for this poll."))
return
var/adminrank = "Player"
if(usr && usr.client && usr.client.holder)
adminrank = usr.client.holder.rank_names()
replytext = replacetext(replytext, "%BR%", "")
replytext = replacetext(replytext, "\n", "%BR%")
var/text_pass = reject_bad_text(replytext,8000)
replytext = replacetext(replytext, "%BR%", "
")
if(!text_pass)
to_chat(usr, "The text you entered was blank, contained illegal characters or was too long. Please correct the text and submit again.")
return
var/datum/db_query/insert_query = SSdbcore.NewQuery("INSERT INTO erro_poll_textreply (id ,datetime ,pollid ,ckey ,ip ,replytext ,adminrank) VALUES (null, Now(), [pollid], '[usr.ckey]', '[usr.client.address]', '[replytext]', '[adminrank]')")
insert_query.Execute()
to_chat(usr, span_blue("Feedback logging successful."))
qdel(insert_query)
usr << browse(null,"window=playerpoll")
/mob/new_player/proc/vote_on_numval_poll(var/pollid = -1, var/optionid = -1, var/rating = null)
if(pollid == -1 || optionid == -1)
return
if(!isnum(pollid) || !isnum(optionid))
return
if(SSdbcore.IsConnected())
var/datum/db_query/select_query = SSdbcore.NewQuery("SELECT starttime, endtime, question, polltype FROM erro_poll_question WHERE id = [pollid] AND Now() BETWEEN starttime AND endtime")
select_query.Execute()
var/validpoll = 0
while(select_query.NextRow())
if(select_query.item[4] != "NUMVAL")
return
validpoll = 1
break
qdel(select_query)
if(!validpoll)
to_chat(usr, span_red("Poll is not valid."))
return
var/datum/db_query/select_query2 = SSdbcore.NewQuery("SELECT id FROM erro_poll_option WHERE id = [optionid] AND pollid = [pollid]")
select_query2.Execute()
var/validoption = 0
while(select_query2.NextRow())
validoption = 1
break
qdel(select_query2)
if(!validoption)
to_chat(usr, span_red("Poll option is not valid."))
return
var/alreadyvoted = 0
var/datum/db_query/voted_query = SSdbcore.NewQuery("SELECT id FROM erro_poll_vote WHERE optionid = [optionid] AND ckey = '[usr.ckey]'")
voted_query.Execute()
while(voted_query.NextRow())
alreadyvoted = 1
break
qdel(voted_query)
if(alreadyvoted)
to_chat(usr, span_red("You already voted in this poll."))
return
var/adminrank = "Player"
if(usr && usr.client && usr.client.holder)
adminrank = usr.client.holder.rank_names()
var/datum/db_query/insert_query = SSdbcore.NewQuery("INSERT INTO erro_poll_vote (id ,datetime ,pollid ,optionid ,ckey ,ip ,adminrank, rating) VALUES (null, Now(), [pollid], [optionid], '[usr.ckey]', '[usr.client.address]', '[adminrank]', [(isnull(rating)) ? "null" : rating])")
insert_query.Execute()
to_chat(usr, span_blue("Vote successful."))
qdel(insert_query)
usr << browse(null,"window=playerpoll")