+++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+++
<%
%><!--#include file ="variables.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)
%>
<div class="question"><% Response.Write(question) %></div>
<%
For i = 1 to 8
If responses(i) <> "" Then
%>
<div class="responsetwo"><% Response.Write(responses(i)) %></div>
<div class="barline">
<%
If votes(i) <> 0 Then
%>
<img src="poll/bar1.gif" height="11" width="<%
Response
.Write
(Round((votes
(i
) / mostvotes
* 150),0)) %>" alt="" /> <%
Response
.Write
(Round((votes
(i
) / totalvotes
* 100),0) & "%")%>
<%
Else
%>0%
<%
%>
</div>
<%
%>
<div class="responses">Total number of votes: <% Response.Write(totalvotes) %></div>
<%
Else
%>
<div class="question"><% Response.Write(question) %></div>
<form class="votingform" action="poll/processvote.asp" method="post">
<%
For i = 1 to 8
If responses(i) <> "" Then
%>
<div class="responses"><input type="radio" name="vote" value="<% Response.Write(i) %>" /> <% Response.Write(responses(i)) %></div>
<%
%>
<input type="hidden" name="referrer" value="<% Response.Write("http://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("SCRIPT_NAME")) %>" />
<div class="responses"><input type="submit" value="Vote" class="votebutton" /> <a href="poll/results.asp" target="_blank">View Results</a></div>
</form>
<%
%>
+++default.asp+++(login en admin)
<%
%><!--#include file="password.asp"--><%
' 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"
%>
<html>
<head>
<title> - Log in</title>
<link rel="stylesheet" type="text/css" href="pollbuddy.css" />
</head>
<body>
<div class="titlebar"><img src="pollbuddy.gif" width="142" height="33" border="0" align="middle" alt="PollBuddy" /></div>
<form action="default.asp" method="post">
<div class="header">Log in</div>
<div class="normal">Password: <input type="password" name="password" /> <input type="submit" value="Log in" /></div>
</form>
<%
If Request.Form("password") <> "" Then
If Request.Form("password") <> password Then
%>
<div class="warning">The password you entered was incorrect.</div>
<%
%>
<div class="normal" align="right">Copyright © 2002 <a href="http://www.blogtastic.com">Benjamin James</a></div>
</body>
</html>
+++newpoll.asp+++
<%
%><%
'check user is logged in
If Session("loggedin") = "true" Then
%>
<html>
<head>
<title>PollBuddy - Create new poll</title>
<link rel="stylesheet" type="text/css" href="pollbuddy.css" />
</head>
<body>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="titlebar"><img src="pollbuddy.gif" width="142" height="33" border="0" align="middle" alt="PollBuddy" /></td>
<td class="navbar"><a href="results.asp" class="nav" target="_blank">view results</a> | <a href="logout.asp" class="nav">log out</a></td>
</tr>
</table>
<div class="header">Create new poll</div>
<%
' 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),"""",""")
'create an array for the number of votes
Dim votes(8)
'set all votes to zero
For i = 1 to 8
votes(i) = 0
'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))
RS.WriteLine("%" & ">")
RS.Close
Set RS=Nothing
Set FS=Nothing
%>
<div class="normal">New poll created. The variables you entered are as follows:</div>
<div class="normal"><b><% Response.Write(question) %></b></div>
<%
For i = 1 to 8
If responses(i) <> "" Then
%>
<div class="normal"><% Response.Write(responses(i)) %></div>
<%
%>
<br />
<div class="normal"><a href="javascript:history.back()">Click here</a> to go back.</div>
<div class="normal" align="right">Copyright © 2002 <a href="http://www.blogtastic.com">Benjamin James</a></div>
<%
Else
%>
<form action="newpoll.asp" method="post">
<table>
<tr>
<td align="right"><div class="normal"><b>Question:</b></div></td>
<td><input type="text" name="question" /></td>
</tr>
<% For i = 1 to 8 %>
<tr>
<td align="right"><div class="normal">Response <% Response.Write(i) %>:</div></td>
<td><input type="text" name="response<% Response.Write(i) %>" /></td>
</tr>
</table>
<div class="normal"><input type="reset" value="Clear" /> <input type="submit" value="Create Poll" /></div>
</form>
<div class="normal" align="right">Copyright © 2002 <a href="http://www.blogtastic.com">Benjamin James</a></div>
</body>
</html>
<%
Else
Response.Redirect "default.asp"
%>
+++results.asp+++
<html>
<head>
<title> - Results</title> Results</title>
<style type="text/css">
body {
margin : 12px;
color : #000000;
background-color : #ffffff;
}
.question {
font-family : arial, helvetica, monaco, sans-serif;
font-size : 13px;
font-weight : bold;
color : #303090;
background-color : transparent;
margin-left : 0px;
margin-right : 0px;
margin-top : 8px;
margin-bottom : 8px;
}
.responses {
font-family : arial, helvetica, monaco, sans-serif;
font-size : 12px;
font-weight : bold;
color : #000000;
background-color : transparent;
margin-left : 0px;
margin-right : 0px;
margin-top : 4px;
margin-bottom : 4px;
}
.percent {
font-family : arial, helvetica, monaco, sans-serif;
font-size : 12px;
color : #000000;
background-color : transparent;
margin-left : 0px;
margin-right : 0px;
margin-top : 4px;
margin-bottom : 4px;
}
.totalvotes {
font-family : arial, helvetica, monaco, sans-serif;
font-size : 12px;
color : #000000;
background-color : transparent;
margin-left : 0px;
margin-right : 0px;
margin-top : 8px;
margin-bottom : 8px;
}
</style>
<!--#include file ="variables.asp"-->
<%
'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)
%>
</head>
<body>
<div class="question"><% Response.Write(question) %></div>
<table>
<%
For i = 1 to 8
If responses(i) <> "" Then
%>
<tr>
<td align="right"><div class="responses"><% Response.Write(responses(i)) %></div></td>
<td>
<div class="percent">
<%
If votes(i) <> 0 Then
%>
<img src="bar1.gif" height="11" width="<%
Response
.Write
(Round((votes
(i
) / mostvotes
* 150),0)) %>" alt="" /> <%
Response
.Write
(Round((votes
(i
) / totalvotes
* 100),0) & "%") Else
%> 0%
<%
%>
</div>
</td>
</tr>
<%
%>
</table>
<div class="totalvotes">Total number of votes: <% Response.Write(totalvotes) %></div>
</body>
</html>
+++vote_js.asp+++
<%
%><!--#include file ="variables.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)
%>
document.writeln('<div class="question"><% Response.Write(question) %><\/div>')
<%
For i = 1 to 8
If responses(i) <> "" Then
%>
document.writeln('<div class="responsetwo"><% Response.Write(responses(i)) %><\/div>')
document.writeln('<div class="barline">')
<%
If votes(i) <> 0 Then
%>
document.writeln('<img src="poll\/bar1.gif" height="11" width="<%
Response
.Write
(Round((votes
(i
) / mostvotes
* 100),0)) %>" alt="" \/> <%
Response
.Write
(Round((votes
(i
) / totalvotes
* 100),0) & "%")%>')
<%
Else
%> document.writeln('0%')
<%
%>
document.writeln('<\/div>')
<%
%>
document.writeln('<div class="menutext">Total number of votes: <% Response.Write(totalvotes) %><\/div>')
<%
Else
%>
document.writeln('<div class="question"><% Response.Write(question) %><\/div>')
document.writeln('<form class="votingform" action="poll\/processvote.asp" method="post">')
<%
For i = 1 to 8
If responses(i) <> "" Then
%>
document.writeln('<div class="responses"><input type="radio" name="vote" value="<% Response.Write(i) %>" \/> <% Response.Write(responses(i)) %><\/div>')
<%
%>
document.writeln('<input type="hidden" name="referrer" value="' + window.location + '" \/>')
document.writeln('<div class="responses"><input type="submit" value="Vote" class="votebutton" \/> <a href="poll\/results.asp" target="_blank">View Results</a><\/div>')
document.writeln('<\/form>')
<%
%>
+++password.asp+++
<%
%><%
Dim password
password="password"
%>
+++processvote.asp+++
<%
%><!--#include file="variables.asp"--><%
Dim vote
vote = Request.Form("vote")
If Request.Cookies("voted") <> question Then
If vote <> "" Then
'set a cookie to stop multiple votes
Response.Cookies("voted") = question
Response.Cookies("voted").Expires = DateAdd("d",30,date())
votes(vote) = votes(vote) + 1
'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
End If
End If
Dim redirectURL
redirectURL = Request.Form("referrer")
If redirectURL <> "" Then
Response.Redirect(redirectURL)
End If
%>
+++variables.asp+++
<%
%><%
Dim question, responses(8), votes(8)
question = ""
responses(1) = ""
votes(1) = 0
responses(2) = ""
votes(2) = 0
responses(3) = ""
votes(3) = 0
responses(4) = ""
votes(4) = 0
responses(5) = ""
votes(5) = 0
responses(6) = ""
votes(6) = 0
responses(7) = ""
votes(7) = 0
responses(8) = ""
votes(8) = 0
%>