/asp/freeapps/pollmentor/incpollmentor.asp
<%
''''''''''' (C) Stefan Holmberg 1999 - 2006
''''''''''' Free to use if these sourcecode lines is not deleted
''''''''''' http://www.aspcode.net
Function PollMentor_GetDatabaseType()
'Set this to Access or SQLServer
PollMentor_GetDatabaseType = "SQLServer"
'PollMentor_GetDatabaseType = "Access"
End Function
'''TODO for you! Configuration:
''''2. Database connection
Function PollMentor_GetDatabaseConn()
Dim oRet
Dim strDSN
' strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& Server.MapPath(".") & "\pm2002.mdb"
strDSN = "Provider=sqloledb;Data Source=(local);Initial Catalog=k1;User Id=sa;Password=stefan"
Set oRet = Server.CreateObject("ADODB.Connection")
oRet.Open strDSN
Set PollMentor_GetDatabaseConn = oRet
End Function
Function PollMentor_GetTitle()
PollMentor_GetTitle = "Pollmentor demo poll"
End Function
'''TODO for you! Configuration:
''''3. Some ads if you'd like
Function FAQ_GetAd(nNumber)
Select Case nNumber
Case 1
FAQ_GetAd = ""
Case 2
FAQ_GetAd = ""
Case 3
FAQ_GetAd = ""
End Select
End Function
Function PollMentor_TryToVote( sID, nNumber )
Dim sRet, strSQL
Dim oConn
Dim strTrue
Dim strFalse
If PollMentor_GetDatabaseType = "SQLServer" Then
strTrue = "1"
strFalse = "0"
Else
strTrue = "True"
strFalse = "False"
End If
Set oConn = PollMentor_GetDatabaseConn()
'Get real id...
Dim oRS
If sID = -1 Then
Set oRS = oConn.Execute("select id from " & Poll_GetTablePrefix() & "poll where active=" & strTrue)
sID = oRS("id").Value
oRS.Close
Set oRS= Nothing
End If
If PollMentor_CanUserVote( oConn, sID ) = False Then
sRet = "Sorry, you have already voted in this poll"
Else
strSQL = "update " & Poll_GetTablePrefix() & "poll set count" & nNumber & " = count" & nNumber & " +1 where "
If nNumber =-1 Then
strSQL = strSQL & " active=" & strTrue
Else
strSQL = strSQL & " id=" & sID
End If
oConn.Execute strSQL
oConn.Execute "insert into " & Poll_GetTablePrefix() & "votelog(poll_id, ip) values(" & sID & ",'" & Request.ServerVariables( "REMOTE_ADDR" ) & "')"
sRet = "Thanks for voting"
End If
oConn.Close
Set oConn = Nothing
PollMentor_TryToVote=sRet
End Function
Function PollMentor_CanUserVote( oConn, sID ) '
'Check of user already has voted within 24 hours?
'If so then no voting can be done...
' Here's your chance to display some other content
'1. Check IP address
Dim strSQL, sTime, oRS
If PollMentor_GetDatabaseType = "SQLServer" Then
sTime = " dateadd(day,-1,getdate()) "
Else
sTime = "#" & DateAdd( "d", -1, Now() ) & "#"
End If
strSQL = "select id from " & Poll_GetTablePrefix() & "votelog where poll_id=" & sID & " AND datum > " & sTime & " AND ip='" & Request.ServerVariables( "REMOTE_ADDR" ) & "'"
' Response.Write strSQL
Set oRS = oConn.Execute(strSQL)
If oRS.EOF Then
PollMentor_CanUserVote = True
Else
PollMentor_CanUserVote = False
End If
oRS.Close
Set oRS = Nothing
End Function
Function PollMentor_GetPollInfo ( ByVal nID, ByRef sTitle, ByRef sQuestion, ByRef vAnswers, ByRef vCount )
Dim sRet, strSQL
Dim oConn, oRS, nCount
Dim strTrue
Dim strFalse
If PollMentor_GetDatabaseType = "SQLServer" Then
strTrue = "1"
strFalse = "0"
Else
strTrue = "True"
strFalse = "False"
End If
Set oConn = PollMentor_GetDatabaseConn()
strSQL = "select * from " & Poll_GetTablePrefix() & "poll where "
If nID = -1 Then
strSQL = strSQL & " active=" & strTrue
Else
strSQL = strSQL & " id=" & nID
End If
Set oRS = oConn.Execute(strSQL)
If oRS.EOF Then
PollMentor_GetPollInfo = False
Else
sTitle=PollMentor_GetTitle()
sQuestion=oRS("question").Value
For nCount=1 To 8
vAnswers(nCount)=oRS("answer" & CStr(nCount)).Value
vCount(nCount)=oRS("count" & CStr(nCount)).Value
Next
PollMentor_GetPollInfo = True
End If
oRS.Close
Set oRS = Nothing
oConn.Close
Set oConn = Nothing
End Function
Function Poll_GetTablePrefix()
Poll_GetTablePrefix = ""
End Function
%>