<?php
//poll.php,投票主程序
require("config.php");
$pollname=$HTTP_POST_VARS["pollname"];
if(!$pollname) //如果投票选项为空,呵呵
 {
   header("Location:viewpoll.php");
   exit;
 }
if($pollflag=="off")
  {
     $timediff=time()-$HTTP_COOKIE_VARS["issent"];
     if($timediff<$polltime){
     header("Location:viewpoll.php?msg=sented");
     exit;
     }
  }
  setcookie("issent",time(),time()+848000);
?>
         <html>
         <head><title>投票</title>
         <meta http-equiv="Content-type" content="text/html; charset=gb2312">
         </head>
         <body>
<?php
$farr=file($polldata);
$msgdata=trim($farr[0])."\n";
for($i=1;$i<sizeof($farr);$i++)
 {
   $farr[$i]=trim($farr[$i]);
   if(!$farr[$i]) continue;
   $tmp=explode("^_^",$farr[$i]);
   if($tmp[0]==$pollname)
     {
       $tmp[1]=$tmp[1]+1;
       $msgdata=$msgdata.$tmp[0]."^_^".$tmp[1]."^_^".$tmp[2]."\n";
       continue;
     }
     else $msgdata=$msgdata.$farr[$i]."\n";
  }

echo "<p><center><a href=\"viewpoll.php\">投票成功,点击查看结果!</a></center></p>";
echo "<script language=\"JavaScript\">window.location.href=\"viewpoll.php\";</script>";
/*
echo $msgdata;
echo "<br><br>";
*/
$fp=fopen($polldata,"w");
flock($fp,2);
fwrite($fp,$msgdata);
fclose($fp);
?>
</body>
</html>