"
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/DBQuery/voted_query = dbcon.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 = "
Player poll"
output +="
"
output += "
Question: [pollquestion]"
output += "
Poll runs from [pollstarttime] until [pollendtime]"
var/voted = 0
while(voted_query.NextRow())
voted = 1
var/optiontext = voted_query.item[1]
var/rating = voted_query.item[2]
output += "
[optiontext] - [rating]"
if(!voted) //Only make this a form if we have not voted yet
output += "
"
src << browse(output,"window=playerpoll;size=500x500")
if("MULTICHOICE")
var/DBQuery/voted_query = dbcon.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
var/list/datum/polloption/options = list()
var/maxoptionid = 0
var/minoptionid = 0
var/DBQuery/options_query = dbcon.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
if(select_query.item[5])
multiplechoiceoptions = text2num(select_query.item[5])
var/output = "
Player poll"
output +="
"
output += "
Question: [pollquestion]You can select up to [multiplechoiceoptions] options. If you select more, the first [multiplechoiceoptions] will be saved.
"
output += "
Poll runs from [pollstarttime] until [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
establish_db_connection()
if(dbcon.IsConnected())
var/DBQuery/select_query = dbcon.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
if(!validpoll)
usr << "\red Poll is not valid."
return
var/DBQuery/select_query2 = dbcon.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
if(!validoption)
usr << "\red Poll option is not valid."
return
var/alreadyvoted = 0
var/DBQuery/voted_query = dbcon.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
if(!multichoice && alreadyvoted)
usr << "\red You already voted in this poll."
return
if(multichoice && (alreadyvoted >= multiplechoiceoptions))
usr << "\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
var/DBQuery/insert_query = dbcon.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()
usr << "\blue Vote successful."
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
establish_db_connection()
if(dbcon.IsConnected())
var/DBQuery/select_query = dbcon.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
if(!validpoll)
usr << "\red Poll is not valid."
return
var/alreadyvoted = 0
var/DBQuery/voted_query = dbcon.NewQuery("SELECT id FROM erro_poll_textreply WHERE pollid = [pollid] AND ckey = '[usr.ckey]'")
voted_query.Execute()
while(voted_query.NextRow())
alreadyvoted = 1
break
if(alreadyvoted)
usr << "\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
replytext = replacetext(replytext, "%BR%", "")
replytext = replacetext(replytext, "\n", "%BR%")
var/text_pass = reject_bad_text(replytext,8000)
replytext = replacetext(replytext, "%BR%", "
")
if(!text_pass)
usr << "The text you entered was blank, contained illegal characters or was too long. Please correct the text and submit again."
return
var/DBQuery/insert_query = dbcon.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()
usr << "\blue Feedback logging successful."
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
establish_db_connection()
if(dbcon.IsConnected())
var/DBQuery/select_query = dbcon.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
if(!validpoll)
usr << "\red Poll is not valid."
return
var/DBQuery/select_query2 = dbcon.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
if(!validoption)
usr << "\red Poll option is not valid."
return
var/alreadyvoted = 0
var/DBQuery/voted_query = dbcon.NewQuery("SELECT id FROM erro_poll_vote WHERE optionid = [optionid] AND ckey = '[usr.ckey]'")
voted_query.Execute()
while(voted_query.NextRow())
alreadyvoted = 1
break
if(alreadyvoted)
usr << "\red You already voted in this poll."
return
var/adminrank = "Player"
if(usr && usr.client && usr.client.holder)
adminrank = usr.client.holder.rank
var/DBQuery/insert_query = dbcon.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()
usr << "\blue Vote successful."
usr << browse(null,"window=playerpoll")