<?
include_once("inc/config.php");
include_once("inc/publicfun.php");
include_once("inc/ftbbsdbclass.php");
include_once("conn.php");

$voteid=$_GET["vote"];
$titleid=intval($_GET["pollid"]);
$tptype=intval($_GET["tptype"]);
if (strlen($voteid)>1){
   $idarr=explode("|",$voteid);
   $tptype=intval($_GET["tptype"]);
   $ip=GetUserIP();
   if (get_cookie('username')!=""){
	  $poll_user=get_cookie('username');
	}
   else{
	$poll_user="过客";
   }
   if ($tptype==1){
         $sql="SELECT * FROM {$tablepre}ftbbs_poll_ip where poll_user_ip='".$ip."' and bbstitleid=".$titleid;
         $rs=mysql_query($sql);
         $myrow = mysql_fetch_array($rs);
         $numrows = mysql_num_rows($rs);
         if ($numrows==0){
		 $str="update {$tablepre}bbs_poll set piaoshu=piaoshu+1 where id=".$idarr[1]."";
		 mysql_query($str);
         $sql="insert into {$tablepre}ftbbs_poll_ip (bbstitleid,poll_user,poll_user_ip,poll_date) values('".$titleid."','".$poll_user."','".$ip."','".$getnow."')";
         mysql_query($sql);
		 }
	   }
   else{
         $sql="SELECT * FROM {$tablepre}ftbbs_poll_ip where poll_user_ip='".$ip."' and bbstitleid=".$titleid;
         $rs=mysql_query($sql);
         $myrow = mysql_fetch_array($rs);
         $numrows = mysql_num_rows($rs);
         if ($numrows==0){
           for($i=1; $i<count($idarr); $i++){
		   $str="update {$tablepre}bbs_poll set piaoshu=piaoshu+1 where id=".$idarr[$i]."";
		   mysql_query($str);
           }
           $sql="insert into {$tablepre}ftbbs_poll_ip (bbstitleid,poll_user,poll_user_ip,poll_date) values('".$titleid."','".$poll_user."','".$ip."','".$getnow."')";
           mysql_query($sql);
		 }
      }
}

$str="select sum(piaoshu) from {$tablepre}bbs_poll where tptype is null and pid=".$titleid;
$rs=mysql_query($str);
$myrow = mysql_fetch_array($rs);
$Vote_Count_Total=$myrow[0];
mysql_free_result($rs);
   
$sql="SELECT * from {$tablepre}bbs_poll where pid=".$titleid." ";
$rs=mysql_query($sql);
$myrow = mysql_fetch_array($rs);
$n="";
while ($myrow = mysql_fetch_array($rs)){
   $Vote_count=$myrow["piaoshu"];
   $n=$n." ".$Vote_count;
}
echo trim($n)." ".$Vote_Count_Total;
?>