************
*包括2个文件(index.php主文件 和 2.php查看投票文件)
*具体例子:http://zsvalley.51.net/tp/index.php
*原码下载:http://zsvalley.51.net/tp/tp.zip
*版权属于Valley所有,有任何问题可联系[email protected]
*************
index.php
*************
<html>
<head>
<title>投票查看</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="club.css"><style type="text/css">
<!--
td { font-size: 9pt}
a:link { font-size: 10pt; color: #999900; text-decoration: none}
a:visited { font-size: 10pt; color: #999900}
a:hover { font-size: 10pt; color: #3366CC; text-decoration: underline}
-->
</style>
</head>
<body bgcolor="#FFFFFF" background="images/lbg052v.jpg">
<table border="0" cellspacing="0" cellpadding="0" align="center"> <tr> <td colspan="3" height="35">
<div align="center"><b> <br> <FONT COLOR="#999999" FACE="隶书" STYLE="font-size:20pt">投
票 系 统</FONT><BR> <BR></b></div></td></tr> <tr> <td colspan="3"> <div align="center"><img src="images/point.gif" width="100%" height="1"></div></td></tr>
<tr> <td valign="top" width="240"> <div align="center"><br> <?
/* 投票标题名,可带路径 */
$title="../cgi-bin/tp/vote_title.dat";
/* 投票栏目名,可带路径 */
$data="../cgi-bin/tp/data.dat";
/* 记录投票结果文件名,可带路径 */
$votes="../cgi-bin/tp/votes.dat";
//写入投票标题和栏目
if($fix_data){
//写入标题
$file_data=fopen($title, "w+");
$poll_name=fwrite($file_data,$vote_title);
fclose($file_data);
//写入栏目
$file_data=fopen($data, "w+");
$vote_data=fwrite($file_data,$vote_datas);
fclose($file_data);
}
/* 读入投票项目主题 */
$file_data=fopen($title, "r");
$poll_name=fread($file_data,filesize($title));
fclose($file_data);
if (file_exists($date)==0){
$dataf=file($data);
/* 显示投票程序的radio*/
echo "<b><font color=#A0A0A0>今天话题:</font></b><font color=red>$poll_name</font><br>n";
echo "<form method=post name=lform action=''>";
echo "<table >";
for ($i=0; $i<=count($dataf)-1; $i++) {
echo "<tr><td><input type=radio name="vote" value="$i"> $dataf[$i]</td></tr>";
}
echo "</table>";
echo "<input type=hidden name=go value=1>";
echo "<p><input type=Submit value=' 投票 ' name=tp_submit onclick="javascript:lform.action='index.php?result=0'" CLASS=btn ONMOUSEOUT="this.style.backgroundColor='#f3f3f3'" ONMOUSEOVER="this.style.backgroundColor='#CCFF99'" >";
echo " <input type=submit name=view_submit value=查看结果 onclick="javascript:lform.action='index.php?result=1'" CLASS=btn ONMOUSEOUT="this.style.backgroundColor='#f3f3f3'" ONMOUSEOVER="this.style.backgroundColor='#CCFF99'" >";
echo "</form>";
//读取投票项目
$file_data=fopen($data, "r");
$vote_data=fread($file_data,filesize($data));
fclose($file_data);
}?></div></td><td width="52"> <div align="center"><img src="images/point.gif" width="1" height="100%"><br>
<br> <br> </div></td><td width="250" valign="top"> <br> <form method=POST action="">
<table border="0" cellspacing="0" cellpadding="0" bordercolorlight="#000000" bordercolordark="#000000" align="center"><tr><td height="2" COLSPAN="2"><DIV ALIGN="CENTER"><FONT COLOR="#999999"><B>选
项 修 改<BR><BR></B></FONT></DIV></td></tr><tr><td height="2" WIDTH="37"><FONT COLOR="#FF3333"><FONT COLOR="#999999">标题:</FONT></FONT></td><td height="2" WIDTH="202"><INPUT TYPE="text" NAME="vote_title" SIZE="20" style="color=#FF9900" CLASS=btn ONMOUSEOUT="this.style.backgroundColor='#f3f3f3'" ONMOUSEOVER="this.style.backgroundColor='#CCFF99'" value=<?echo $poll_name;?>></td></tr>
<tr> <td height="2" WIDTH="37" VALIGN="TOP"> <DIV ALIGN="LEFT"><font color="#FF3333"><FONT COLOR="#999999">项目:
<BR> </FONT></font></DIV></td><td height="2" WIDTH="202"><FONT COLOR="#FF3333"><FONT COLOR="#999999"><TEXTAREA NAME=vote_datas COLS="30" ROWS="7" WRAP="PHYSICAL" CLASS=btn ONMOUSEOUT="this.style.backgroundColor='#f3f3f3'" ONMOUSEOVER="this.style.backgroundColor='#CCFF99'" STYLE="color=#FF9900"><?echo $vote_data?></TEXTAREA></FONT></FONT></td></tr>
<tr> <td COLSPAN="2" HEIGHT="14"> </td></tr> <tr> <td height="9" COLSPAN="2">
<div align="center"><BR><input type="submit" name="fix_data" value=" 修改 " CLASS=btn ONMOUSEOUT="this.style.backgroundColor='#f3f3f3'" ONMOUSEOVER="this.style.backgroundColor='#CCFF99'" >
<font color="#FF3333"><b><font color="#CCCCFF"> </font></b></font></div></td></tr>
</table></form></td></tr><tr><td valign="top" COLSPAN="3"><IMG SRC="images/point.gif" WIDTH="100%" HEIGHT="1"></td></tr><tr><td valign="top" COLSPAN="3"><TABLE WIDTH="404" BORDER="0" CELLSPACING="0" CELLPADDING="0" ALIGN="CENTER"><TR><TD><BR> <FONT COLOR="#999999">注意:1.选项修改项目里的每一行对应一个选项
<BR> 2.每人每次只能投一票 <BR> 3.本站点保留最终解释权 <BR> 4.有任何问题,请联系<A HREF="mailto:[email protected]">Valley</A></FONT></TD></TR></TABLE></td></tr>
</table><?if ($tp_submit || $view_submit){
?> <script language=javascript>
window.open("2.php?vote=<?echo $vote?>&result=<?echo $result?>","view_vote","width=400,height=400,scrollbars=yes")
</script> <?
}?>
</body>
</html>
//2.php
<html>
<head>
<title>投票查看</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
body { font-size: 9pt}
td { font-size: 9pt}
a:link { font-size: 10pt; color: #999900; text-decoration: none}
a:visited { font-size: 10pt; color: #999900}
a:hover { font-size: 10pt; color: #3366CC; text-decoration: underline}
-->
</style>
</head>
<body background="images/lbg052v.jpg" bgcolor="#FFFFFF">
<?php
/* 投票栏目名,可带路径 */
$data="../cgi-bin/tp/data.dat";
/* 记录投票结果文件名,可带路径 */
$votes="../cgi-bin/tp/votes.dat";
//图形文件名
function color($per){
if ($per<=20) $col="images/tp_blue.gif";
elseif($per>20 && $per<=40) $col="images/tp_yellow.gif";
elseif($per>60 && $per<=80) $col="images/tp_green.gif";
elseif($per>80) $col="images/tp_pink.gif";
else $col="images/tp_red.gif";
return $col;
}
/* 投票项目名 */
$poll_name="您喜欢吃什么水果?";
$dataf=file($data);
$file_votes=fopen($votes, "r");
$line_votes=fgets($file_votes, 255);
$single_vote=explode("|", $line_votes);
fclose($file_votes);
//写入投票结果
if ($result==0) {
$file_votes=file($votes, "r");
//IP地址重复
if ($REMOTE_ADDR == $file_votes[1]) {
echo "<BR><BR><BR><BR><BR><center><font color=red style='font-size:12pt'>您已投过票了,谢谢您的参与!</font></center>";
echo "<BR><BR><BR><BR><BR><BR><div align=center><A HREF='Javascript:window.close();'><font style='font-size:12pt'>关闭</font></A></div>";
?><SCRIPT LANGUAGE="JavaScript">setTimeout("window.close()",5000);</SCRIPT><?
exit();
}
$ficdest=fopen($votes, "w");
for ($i=0; $i<=count($dataf)-1; $i++) {
if ($i == $vote) {
$single_vote[$i]+=1;
}
fputs($ficdest, "$single_vote[$i]|");
}
fclose($ficdest);
$ficdest=fopen($votes, "a");
fputs($ficdest, "n$REMOTE_ADDR");
fclose($ficdest);
$result=1;
}
//显示投票结果
if ($result==1) {
echo "<table cellpadding=10 bordercolor=#FFCC00 border=1 align=center><tr>
<td colspan=3 bgcolor=#FFCC00>
<div align=center><b><font color=#6666FF>* 投 票 结 果 * </font></b></div>
</td>
</tr>";
for ($i=0; $i<=count($dataf)-1; $i++) {
$tot_votes+=$single_vote[$i];
}
for ($i=0; $i<=count($dataf)-1; $i++) {
$stat[$i]=$single_vote[$i]/$tot_votes*100;
echo "<tr><td><li><font face=Verdana size=2>";
echo "$dataf[$i]</font></td><td align=left><font face=Verdana size=2>";
echo "<img src=".color($stat[$i])." height=10 width=$stat[$i] align=middle> ";
printf("%.1f", "$stat[$i]");
echo "%</font></td><td align=center><font face=Verdana size=2>";
echo "$single_vote[$i] </font>";
echo "</td></tr>";
}
echo "</table>";
echo "<BR> <font face=Verdana size=2>总投票数:<font color=#FF3300>$tot_votes </font>";
echo "<BR><div align=center><A HREF='Javascript:window.close();'><font style='font-size:12pt'>关闭</font></A></div>";
}
?>
</body>
</html>
***********
其他注意地方:
1。投票内容读取一个叫data.dat的文本文件,路径可自定义。
2。另外还包括一个叫club.css的样式表文件,定义字体等格式。
***********
|