Snitz™ Forums 2000
https://forum.snitz.com/forumTopic/Posts/63148?pagenum=1
05 November 2025, 09:07
Topic
Davio
Poll Mod v2.0.8
30 October 2006, 21:22
Poll Mod Version: 2.0.8 Current Author: Davio Original Author: Slemieux Last Modified: October 30, 2006 For Snitz Version: 3.4.06
Description:
This version is a new and upgraded version from the pervious ones. With new features and lots of bug fixes. View the list of changes I have made in the list below. I hope everyone enjoys the new poll mod as much as I enjoyed working on it (yeah right).
Thanks for your patience.
This update is mainly bug fixes and made compatible with Snitz FOrums 3.4.06.
Ease of Installation (1-Easy, 10-Hard): 8
Downloads: 3.4 Version Main Link: http://www.snitzbitz.com/mods/details.asp?Version=All&mid=76 Updated Files Only: http://www.snitzbitz.com/mods/details.asp?Version=All&mid=76
Demo: http://www.dsilvera.com/forum/
Version 2.0.8 (October 3, 2006)
Updated files with latest forum version, 3.4.06.
Fixed bug in pop_poll.asp that allowed everyone to vote in a members only poll. (Ref.: Topic #62378)
Fixed bug in pop_poll.asp where vote results where not updated after a user voted. (Ref.: Topic #62378)
Fixed bug in inc_poll.asp where clicking on the View Results button did not take you to the results. (Ref.: Topic #62406)
Fixed bug when you use a quote in the poll answers, it comes out as 2 quotes instead.
Modified Files: post_info.asp
Version 2.0.7 (October 25, 2003)
Fixed bug when you delete a poll the poll data is not removed from the poll tables in the database.
Modified Files: pop_delete.asp
INSTALLATION/UPGRADE:
Please read the readme.html file that is included. It also includes a FAQ section to common questions that you might ask about the mod.
SUPPORT: If you have any problems please post them in the Help: MOD Implementation forum. DO NOT ASK FOR HELP OR POST YOUR ERROR MESSAGES IN THIS TOPIC!! Poll Mod Add-On!
Also check out the Site Poll Mod. It allows you to put your featured forum poll on your website.
http://forum.snitz.com/forum/topic.asp?TOPIC_ID=40335<
Replies ...
Entheos
02 November 2006, 16:35
Davio - thank you!!!! Have been hoping that someone with much better ASP abilities than mine (which are next to none) would fix those bugs and make the polls compatible with 3.4.06.
I have now upgraded from 2.0.7 to 2.0.8 on my forums and it works a treat. Much appreciated.<
muzishun
02 November 2006, 23:13
Thanks so much for the updates! I do have one question, though. With the fix posted here, I'm curious about whether this opens the potential for an SQL Injection attack. Is the string sanitized later, or is this not considered a vulnerability?<
Davio
03 November 2006, 00:01
I sanitize all my variables before using them in sql queries Bill.
Security comes first when I code my mods. Mainly comes from being part of the dev team. Security is high on the totem pole.
So if anything you want to accuse me of is sanitizing my variables more than once.
Which was the case for that bug fix. Persons complained that single quotes were being doubled up. It was because it went through chkstring() twice. <
muzishun
03 November 2006, 21:35
That was my main question. I've used several of your mods, and have never had a single problem. Looking back, I guess I worded it a little carelessly. My main question was whether the variable was sanitized later (which I assumed it was, just wanted to check).
Thanks a bunch for the updates!<
Davio
03 November 2006, 22:06
You can do a search for the variable and see where it is sanitized. But yes, it is, either later or earlier.<
OneWayMule
04 November 2006, 04:37
Is creating polls where users can check multiple answers possible now? <
Davio
04 November 2006, 15:37
No senior OneWay. That would be in the 3.0 version. <
Davio
05 November 2006, 17:23
Image, as much as I appreciate your help in reporting bugs, there is a better way to do it.
1. Please post in the right forum. Start a new topic in the Help MOD Implementation forum with the problem so it can discussed.
2. Provide more information. Line numbers (approximate), explanation as to what is wrong. These are a must.
You're not a member that report bugs 1 or 2 times, but you do it regularly, so I hope you will start to develop good bug reporting so you don't get developers frustrated, asking for extra info each time.
Again thanks for pointing them, just start a new topic on it, please.<
juliana
22 December 2007, 00:41
just another happy camper saying THANK YOU for this mod! <
mkervin
27 April 2009, 08:41
I just upgraded Snitz to 3.4.07 and I am having problems getting this mod to work. When I add a New Poll the choices don't display and in the poll admin there is no feature poll listed and I have all the appropriate check boxes checked. I don't receive any errors on the db so I must have a line or two messed up somewhere. However, when checking with WinMerge all files compare just fine. Davio, can you tell me where I need to look to check my code for at the very least choices. I checked the topic.asp and everything looks correct. Thanks in advance.
Davio
27 April 2009, 18:03
Ok, no need to post your messages all over the place. I'll install the mod on the 3.4.07 version and see if there are any problems.
SiSL
27 April 2009, 18:27
Just curious Davio, was there "multi-choice" version before and is it removed?
Etymon
29 April 2009, 04:56
Hey SiSL,
I have one of the versions from a while back that allows for 15 choices. Is that what you are talking about?
Carefree
29 April 2009, 06:14
I don't think they're referring to how many options but the ability to select multiple answers.... Dayve had a mod that increased the choices to 20, I used to have it someplace but cannot find it.
SiSL
29 April 2009, 13:52
Originally posted by Etymon Hey SiSL,
I have one of the versions from a while back that allows for 15 choices. Is that what you are talking about?
I was refering to checkbox options that users can select more than 1 answer in their votes. I used to remember there was an option to make it like that on earlier versions.
Davio
29 April 2009, 15:50
I don't remember multiple choices being 1 of the options. It was something on my to-do list tho. I'll be having some time on my hands, so I might just work something in when I update the poll mod.
The poll mod takes up so many database fields. Sometimes I wonder if there isn't a more efficient way of storing poll data.
ruirib
29 April 2009, 16:14
There is, David. It would be a different thing altogether. If you are considering that possibility, I can think about that design.
Davio
29 April 2009, 16:39
Yeah I am Rui. Run the design by me, if you would. Basically looking to use less database fields, altho not at the cost of performance issues.
Persons are looking for more poll options but creating countless database fields to hold them seems ridiculous. lol
ruirib
29 April 2009, 17:34
Hi David,
I guess if you want a new DB structure, probably migration from the current one should be the most direct possible. This proposed structure represents a compromise, because it would just solve the problem of wasting dabatase space and allowing more than 15 options.
Basically I suggest that you split the POLLS table into two:
POLL_ANSWER: ANSWER_ID POLL_ID, ANSWER_TEXT, ORDER, <- Order of the answer in the poll COUNT
Then use the POLL_VOTES as you have it now.
This is pretty close to what you have now. It would also mean that migrating from the existing structure to the current one should be really simple.
I can provide further detail, if needed.
This is not the best possible structure, but a reasonable compromise, as I said, considering that there are quite a few installs and changing your code to use this shouldn't be too hard.
Let me know what you think.
Etymon
30 April 2009, 01:42
This is fun! Thanks guys!
Carefree
30 April 2009, 02:20
Multiple choices are possible now, if options such as ("Both A and C") are used; though when possible single choices exceed four, that can quickly become unwieldy (a, b, c, d, a&b, a&c, a&d, b&c, b&d, c&d, a&b&c, a&b&d, b&c&d, a&c&d, a&b&c&d). It would be much simpler to use checkboxes vs radio buttons and thus allow multiple choices.
SiSL
30 April 2009, 04:24
This is not the best possible structure
Actually Rui, you are wrong. Your method IS the best possible structure. (May be can loose auto increment ANSWER_ID there, since there is ORDER and POLL_ID required) Actually I decided to give it a try right now. However, migration might be the toughest part.
ruirib
30 April 2009, 09:33
Yeah, guess you can have order and poll_id as the primary key for the POLL_ANSWER table. The poll mod code will have to be redone for this, of course. "Hardest" thing will be the form to create a poll, since the number of answers will now be variable. Probably using a list instead of fixed text fields would be a better option.
SiSL
30 April 2009, 09:52
Originally posted by ruirib Yeah, guess you can have order and poll_id as the primary key for the POLL_ANSWER table. The poll mod code will have to be redone for this, of course. "Hardest" thing will be the form to create a poll, since the number of answers will now be variable. Probably using a list instead of fixed text fields would be a better option.
I still limit it to 15, like + and - signs... (I dont find it reasonable or logical to allow unlimited number of polls) So on For Next, if it sees an empty answer, exits for... And limits the poll like that.
However, database will be a lot lighter...
IMO, hardest (well, not hardest, but still need work) part would be "updating" records...
So I went a way to Take all counts of Poll -> Delete answers entirely -> Insert again mode (for empty responses or old stuff not to remain there) and not sure if there is faster way to do that...
I think it works fine on my test server now, also updated pop_delete for that as well (but for Category or Forum deletions, I need to work on it more, but heck, I dont delete cats or forums that much eheh) Most likely I can not make it into a mod, since my poll mod is also modded a lot, but principles remains same.
modifichicci
30 April 2009, 10:44
Don't forget the archive function as well...
ruirib
30 April 2009, 10:59
Watch out the indexing, if you have a few polls...
ruirib
30 April 2009, 11:04
I could have written a nice little SQL Server script for migration, if you had told me so. Not hard, using cursors. Can't say the same for Access and MySQL, cause it would needed to be done using asp.
SiSL
30 April 2009, 12:40
Originally posted by modifichicci Don't forget the archive function as well...
I dont think Archieve would have anything to do with other tables, since Poll ID is unique and equals to Topic Id.
ruirib
30 April 2009, 12:45
Indeed, archiving just means archiving the topic.
SiSL
30 April 2009, 13:49
Ok, here goes
topic.asp, I changed as following:
DB as following DB Name: strTablePrefix & "POLL_ANSWERS"
POLL_ID (int, not null) ANSWER_TEXT (nvarchar(255), null) ANSWER_ORDER (int, not null) COUNT (default value=0, int, not null)
This is SQL Server version, using GetRows, would be nice if someone know how to apply it to Access and such.
strSql = "SELECT P.P_LASTVOTE, P.P_WHOVOTES" ' Also removed commas , careful on that 'For i = 1 To 15 ' strSql = strSql & ", P.ANSWER" & CStr(i) ' strSql = strSql & ", P.COUNT" & CStr(i) 'Next
strSql = strSql & " FROM " & strTablePrefix & "POLLS P" strSql = strSql & " WHERE P.TOPIC_ID = " & Topic_ID
set rsPoll = Server.CreateObject("ADODB.Recordset") rsPoll.Open strSql, my_Conn, adOpenForwardOnly, adLockReadOnly, adCmdText
if not(rsPoll.EOF) or not(rsPoll.BOF) then Last_Vote = rsPoll("P_LASTVOTE") strWhoVotes = rsPoll("P_WHOVOTES") rsPoll.Close set rsPoll = nothing
strSQL = "SELECT ANSWER_TEXT, ANSWER_COUNT FROM " & strTablePrefix & "POLL_ANSWERS WHERE POLL_ID=" & Topic_ID set rsPoll = Server.CreateObject("ADODB.Recordset") rsPoll.Open strSql, my_Conn, adOpenForwardOnly, adLockReadOnly, adCmdText if not rsPoll.EOF or rsPoll.BOF Then tumPoll = rsPoll.GetRows For i=0 to UBound(tumPoll,2) z = i+1 vAnswers(z) = tumPoll(0,i) vCount(z) = tumPoll(1,i)
Next End If end if
rsPoll.Close set rsPoll = nothing end if if IsPoll = 1 then pollLink = "poll=1&"
else pollLink = "" end if '##########################################
Also in another Poll mod marked places inside I changed a few lines starting with if to end...
set rsPoll = Server.CreateObject("ADODB.Recordset") rsPoll.open strSql, my_Conn, adOpenForwardOnly, adLockReadOnly, adCmdText
Last_Vote = rsPoll("P_LASTVOTE") rsPoll.Close set rsPoll = nothing strSQL = "SELECT ANSWER_TEXT, ANSWER_COUNT FROM " & strTablePrefix & "POLL_ANSWERS WHERE POLL_ID=" & Topic_ID set rsPoll = Server.CreateObject("ADODB.Recordset") rsPoll.Open strSql, my_Conn, adOpenForwardOnly, adLockReadOnly, adCmdText if not rsPoll.EOF or rsPoll.BOF Then tumPoll = rsPoll.GetRows For i=0 to UBound(tumPoll,2) z = i+1 vAnswers(z) = tumPoll(0,i) vCount(z) = tumPoll(1,i)
Next End If rsPoll.Close set rsPoll = nothing
Call UpdateVote("0", MemberID, Topic_ID, Forum_ID, Cat_ID) end if
SiSL
30 April 2009, 13:54
POST.ASP
Code:
' ############################## Poll Mod ################################ if Request.QueryString("poll") = "1" then '### Get poll from POLLS table strSql = "SELECT " & strTablePrefix & "POLLS.P_WHOVOTES " ' CAREFUL FOR COMMAS 'for i = 1 to 15 ' strSql = strSql & strTablePrefix & "POLLS.ANSWER" & CStr(i) & ", " ' strSql = strSql & strTablePrefix & "POLLS.COUNT" & CStr(i) ' if i <> 15 then ' strSql = strSql & ", " ' end if 'next
strSql = strSql & " FROM " & strTablePrefix & "POLLS" strSql = strSql & " WHERE " & strTablePrefix & "POLLS.TOPIC_ID = " & strRqTopicID set rsPoll = my_Conn.Execute (strSql)
if rsPoll.EOF or rsPoll.BOF then Go_Result "You are trying to edit a topic that is not a poll" else strWhoVotes = rsPoll("P_WHOVOTES") ' I think I also removed something from here?
end if rsPoll.Close set rsPoll = nothing
strSql = "SELECT ANSWER_TEXT " strSql = strSql & " FROM " & strTablePrefix & "POLL_ANSWERS " strSql = strSql & " WHERE POLL_ID = " & strRqTopicID & " ORDER BY ANSWER_ORDER ASC" set rsPoll = my_Conn.Execute (strSql)
if rsPoll.EOF or rsPoll.BOF then Go_Result "You are trying to edit a topic that is not a poll" else nTotal = 0 ReDim txtAns(15) tumPollAnswers = rsPoll.GetRows For i=0 to UBound(tumPollAnswers,2) z = i+1 txtAns(z) = tumPollAnswers(0,i) nTotal = nTotal + 1 Next
if CInt(strMaxVotes) > nTotal then nCount = strMaxVotes else nCount = nTotal end if end if rsPoll.Close set rsPoll = nothing end if ' ############################################################
strSql = strSql & "" For i=1 to UBound(txtAns) if Trim(txtAns(i)) <> "" Then strSql = strSql & ";INSERT INTO " & strTablePrefix & "POLL_ANSWERS (POLL_ID, ANSWER_TEXT, ANSWER_ORDER, ANSWER_COUNT) VALUES (" strSql = strSql & PollID & ", '" & chkString(txtAns(i),"SQLString") & "'," & i & ", " & 0 & ")" Else exit for End If next my_Conn.Execute (strSql),,adCmdText + adExecuteNoRecords end if '####################################################################
Also in POST_INFO.ASP
Code:
'############################ Poll Mod ################################### if Request.Form("poll") = "1" then '### Update poll answers and counts strSql = "SELECT ANSWER_COUNT FROM " & strTablePrefix & "POLL_ANSWERS WHERE POLL_ID=" & Topic_ID & " ORDER BY ANSWER_ORDER ASC" set rs=my_Conn.Execute(strSql) if not rs.EOF Then tumPolls = rs.GetRows toplamPAnswers = UBound(tumPolls,2) + 1 Else toplamPAnswers = 0 End If rs.Close set rs=nothing
strSql = "UPDATE " & strTablePrefix & "POLLS " strSql = strSql & " SET P_WHOVOTES = '" & chkString(Request.Form("WhoVotes"),"SQLString") & "', " strSql = strSql & " CAT_ID = " & cLng(aryForum(0)) & ", " strSql = strSql & " FORUM_ID = " & cLng(aryForum(1)) & " " 'for i = 1 to CInt(Request.Form("count")) ' strSql = strSql & "ANSWER" & CStr(i) & " = '" & chkString(txtAns(i),"") & "'" ' if txtAns(i) = "" or chkString(Request.Form("resetpoll"),"SQLString") = "1" then ' strSql = strSql & ", COUNT" & CStr(i) & " = " & 0 ' end if ' if ubound(txtAns) <> i then ' strSql = strSql & ", " ' end if 'next
strSql = strSql & " WHERE TOPIC_ID = " & Topic_ID my_Conn.Execute(strSql),,adCmdText + adExecuteNoRecords
strSQL = "DELETE FROM " & strTablePrefix & "POLL_ANSWERS WHERE POLL_ID = " & Topic_ID my_Conn.Execute(strSQL) strSQL = "" for i=1 to CInt(Request.Form("count")) if Trim(chkString(txtAns(i),"")) <> "" Then strSQL = strSQL & "INSERT INTO " & strTablePrefix & "POLL_ANSWERS (POLL_ID, ANSWER_TEXT, ANSWER_ORDER, ANSWER_COUNT) VALUES (" strSQL = strSQL & Topic_ID & ", " strSQL = strSQL & "'" & chkString(txtAns(i),"SQLString") & "', " strSQL = strSQL & i & "," if chkString(Request.Form("resetpoll"),"SQLString") = "1" then strSQL = strSQL & 0 Else if i <= toplamPAnswers Then z = i-1 strSQL = strSQL & tumPolls(0,z)
Else strSQL = strSQL & 0 End If End If Else Exit for End If strSql = strSql & ");" next
my_Conn.Execute(strSql),,adCmdText + adExecuteNoRecords if Request.Form("resetpoll") = "1" then '### Delete poll votes from POLL_VOTES table for this topic strSql = "DELETE FROM " & strTablePrefix & "POLL_VOTES " strSql = strSql & "WHERE " & strTablePrefix & "POLL_VOTES.TOPIC_ID = " & Topic_ID my_Conn.Execute(strSql),,adCmdText + adExecuteNoRecords end if end if '#########################################################################
SiSL
30 April 2009, 13:59
Okay, went through this, this might give an idea about it :) I showed in RED where I commented out
ruirib
30 April 2009, 14:00
ANSWER_ORDER should not be nullable.
SiSL
30 April 2009, 14:01
Originally posted by ruirib ANSWER_ORDER should not be nullable.
Could be changed to that too :)
SiSL
30 April 2009, 14:07
I think have to add good indexes to that too :P like my previous problem :)
PS: I'm such a mess code-writer, I guess it is like coding but not able to express what you did after :p Anarchic :)
ruirib
30 April 2009, 18:01
Althought not needed, a clustered index for POLL_ID in table Polls won't hurt and then another clustered on for POLL_ID,Order in Answers. Don't think you will have that many polls, so this should be enough...