+++Logout.asp+++ <% %><% Response.Buffer = True Session("loggedin") = "false" Response.Redirect "default.asp" %> +++pollstyle.css+++ body { background-color : #ffffff; margin : 0px; } .titlebar { background-color : #5895d0; padding : 2px; border-bottom : 1px solid #303090; } .navbar { background-color : #5894d0; padding : 4px; border-bottom : 1px solid #303090; text-align : right; font-family : verdana, arial, helvetica, monaco, sans-serif; font-size : 12px; color : #ffffff; background-color : 5895d0; } a.nav { color : #ffffff; background-color : transparent; } a.nav:hover { font-family : verdana, arial, helvetica, monaco, sans-serif; font-size : 12px; color : #ffffff; background-color : transparent; text-decoration : underline; } .normal { font-family : verdana, arial, sans=serif; font-size : 12px; color : #000000; backgroud-color : transparent; margin : 8px; } .warning { font-family : verdana, arial, sans=serif; font-size : 12px; color : #d03030; backgroud-color : transparent; margin : 8px; } .header { font-family : trebuchet ms, verdana, arial, sans=serif; font-size : 20px; color : #303090; backgroud-color : transparent; margin : 8px; } a { color : #303090; background-color : transparent; } form { margin : 0px; } +++vote.asp+++ <% %> <% If Request.Cookies("voted") = question Then 'find which is the largest number of votes Dim mostvotes mostvotes = 0 For i = 1 to 8 If mostvotes < votes(i) Then mostvotes = votes(i) End If Next 'calculate the total number of votes Dim totalvotes totalvotes = 0 For i = 1 to 8 totalvotes = totalvotes + votes(i) Next %>
<% Response.Write(question) %>
<% For i = 1 to 8 If responses(i) <> "" Then %>
<% Response.Write(responses(i)) %>
<% If votes(i) <> 0 Then %>  <% Response.Write(Round((votes(i) / totalvotes * 100),0) & "%")%> <% Else %>0% <% End If %>
<% End If Next %>
Total number of votes: <% Response.Write(totalvotes) %>
<% Else %>
<% Response.Write(question) %>
<% For i = 1 to 8 If responses(i) <> "" Then %>
<% Response.Write(responses(i)) %>
<% End If Next %> " />
  View Results
<% End If %> +++default.asp+++(login en admin) <% %><% ' check if page is being reloaded after password submit If Request.Form("password") <> "" Then ' verify password If Request.Form("password") = password Then Session("loggedin") = "true" Response.Redirect "newpoll.asp" End If End If %> - Log in
PollBuddy
Log in
Password:
<% If Request.Form("password") <> "" Then If Request.Form("password") <> password Then %>
The password you entered was incorrect.
<% End If End If %>
Copyright © 2002 Benjamin James
+++newpoll.asp+++ <% %><% 'check user is logged in If Session("loggedin") = "true" Then %> PollBuddy - Create new poll
PollBuddy
Create new poll
<% ' check if pages is being reloaded after new poll form submit If Request.Form("question")<>"" Then 'create a variable for the poll question Dim question question = Request.Form("question") 'create an array for the response strings Dim responses(8) 'add the response strings to the array responses(1) = Request.Form("response1") responses(2) = Request.Form("response2") responses(3) = Request.Form("response3") responses(4) = Request.Form("response4") responses(5) = Request.Form("response5") responses(6) = Request.Form("response6") responses(7) = Request.Form("response7") responses(8) = Request.Form("response8") 'replace characters that might cause errors on the javascript voting form question = replace(question,"/","/") question = replace(question,"'","'") question = replace(question,"""",""") For i = 1 to 8 responses(i) = replace(responses(i),"/","/") responses(i) = replace(responses(i),"'","'") responses(i) = replace(responses(i),"""",""") Next 'create an array for the number of votes Dim votes(8) 'set all votes to zero For i = 1 to 8 votes(i) = 0 Next 'open the file variables.asp Set FS=Server.CreateObject("Scripting.FileSystemObject") Set RS=FS.OpenTextFile(Server.MapPath("variables.asp"), 2, False) 'write in the new variables RS.WriteLine("<" & "%") RS.WriteLine("Dim question, responses(8), votes(8)") RS.WriteLine("question = """ & question & """") For i = 1 to 8 RS.WriteLine("responses(" & i & ") = """ & responses(i) & """") RS.WriteLine("votes(" & i & ") = " & votes(i)) Next RS.WriteLine("%" & ">") RS.Close Set RS=Nothing Set FS=Nothing %>
New poll created. The variables you entered are as follows:
<% Response.Write(question) %>
<% For i = 1 to 8 If responses(i) <> "" Then %>
<% Response.Write(responses(i)) %>
<% End if Next %>
Click here to go back.
Copyright © 2002 Benjamin James
<% Else %>
<% For i = 1 to 8 %> <% Next %>
Question:
Response <% Response.Write(i) %>:
Copyright © 2002 Benjamin James
<% End If Else Response.Redirect "default.asp" End If %> +++results.asp+++ - Results Results <% 'find which is the largest number of votes Dim mostvotes mostvotes = 0 For i = 1 to 8 If mostvotes < votes(i) Then mostvotes = votes(i) End If Next 'calculate the total number of votes Dim totalvotes totalvotes = 0 For i = 1 to 8 totalvotes = totalvotes + votes(i) Next %>
<% Response.Write(question) %>
<% For i = 1 to 8 If responses(i) <> "" Then %> <% End If Next %>
<% Response.Write(responses(i)) %>
<% If votes(i) <> 0 Then %>  <% Response.Write(Round((votes(i) / totalvotes * 100),0) & "%") Else %> 0% <% End If %>
Total number of votes: <% Response.Write(totalvotes) %>
+++vote_js.asp+++ <% %> <% If Request.Cookies("voted") = question Then 'find which is the largest number of votes Dim mostvotes mostvotes = 0 For i = 1 to 8 If mostvotes < votes(i) Then mostvotes = votes(i) End If Next 'calculate the total number of votes Dim totalvotes totalvotes = 0 For i = 1 to 8 totalvotes = totalvotes + votes(i) Next %> document.writeln('
<% Response.Write(question) %><\/div>') <% For i = 1 to 8 If responses(i) <> "" Then %> document.writeln('
<% Response.Write(responses(i)) %><\/div>') document.writeln('
') <% If votes(i) <> 0 Then %> document.writeln(' <% Response.Write(Round((votes(i) / totalvotes * 100),0) & "%")%>') <% Else %> document.writeln('0%') <% End If %> document.writeln('<\/div>') <% End If Next %> document.writeln('