bal.php");
$cid=intval($cid);
$i=0;
$tplcode='';
if($job=="js")
{
if(!$cid&&!$aid){
showerr("CID,AID不存在",1);
}
unset($shows,$i,$SQL);
if($cid){
$SQL=" WHERE C.cid='$cid' ";
}else{
$SQL=" WHERE C.aid='$aid' ";
}
$query = $db->query("SELECT C.about,C.type,C.votetype,C.tplcode,V.* FROM {$pre}vote_topic C LEFT JOIN {$pre}vote_element V ON C.cid=V.cid $SQL ORDER BY V.list DESC");
while($rs = $db->fetch_array($query)){
$i++;
if($rs[type]==1){
$button=$rs[type]="";
}else{
$button=$rs[type]="";
}
$votenum=$rs[votenum];
$title=$rs[title];
$img=tempdir($rs[img]);
$url=$rs[url];
$id=$rs[id];
$cid=$rs[cid];
$tplcode=str_replace('"','\"',$rs[tplcode]);
$describes=$rs[describes];
if($votetype==2&&$i>1){
$shows.="

";
}
eval("\$shows.=\"$tplcode\";");
$about=$rs[about];
$votetype=$rs[votetype];
$listdb[]=$rs;
}
if(!$tplcode){
require(Mpath."template/default/vote_js.htm");
}else{
if(!$votetype){
print<<
EOT;
}elseif($votetype==1){
print<<
EOT;
}elseif($votetype==2){
print<<
| $shows |
| $about |
EOT;
}
}
if($step!='show'){
$content=ob_get_contents();
ob_end_clean();
$content=str_replace("","",$content);
$content=str_replace("\r","",$content);
$content=str_replace("\n","",$content);
$content=str_replace("'","\'",$content);
echo "document.write('$content');";
}
exit;
}
elseif($action=="vote")
{
if(!$voteId){
showerr("请选择一个投票选项",1);
}
if(!is_array($voteId)){
$v=$voteId;
unset($voteId);
$voteId[]=$v;
}
$voteId[0] = addslashes($voteId[0]);
@extract($db->get_one("SELECT cid FROM {$pre}vote_element WHERE id='$voteId[0]'"));
$rsdb=$db->get_one("SELECT * FROM {$pre}vote_topic WHERE cid='$cid'");
if($rsdb[forbidguestvote]){
if(!$lfjdb){
showerr("你还没登录,管理员设置必须登录后才能投票",1);
}
}
if($rsdb[begintime]&&$timestamp<$rsdb[begintime]){
$time=date("Y-m-d H:i:s",$rsdb[begintime]);
showerr("还没到投票的开始时间.请耐心等待,投票开始日期为:$time");
}
if($rsdb[endtime]&&$timestamp>$rsdb[endtime]){
$time=date("Y-m-d H:i:s",$rsdb[endtime]);
showerr("投票已经结束.结束的日期为:$time");
}
if($rsdb[limitip])
{
if( strstr($rsdb[ip],$onlineip) ){
showerr("请不要重复投票,你已经投过了",1);
}
$rsdb[ip].="$onlineip ".implode(",",$voteId)."\t";
$db->query("UPDATE {$pre}vote_topic SET ip='$rsdb[ip]' WHERE cid='$cid'");
}
if($rsdb[limittime])
{
if($_COOKIE["vote_limittime_$cid"])
{
showerr("{$rsdb[limittime]}分钟内,请不要重复投票,你已经投过了",1);
}
$time=$rsdb[limittime]*60;
setcookie("vote_limittime_$cid",1,$timestamp+$time,"/");
}
foreach($voteId AS $key=>$value)
{
$value = addslashes($value);
$db->query("UPDATE {$pre}vote_element SET votenum=votenum+1 WHERE id='$value' ");
}
refreshto("vote.php?job=show&cid=$cid","谢谢你投下宝贵的一票");
}
elseif($job=="show")
{
if(!$cid){
showerr("CID不存在",1);
}
unset($listdb,$numdb,$max,$widthdb);
$query = $db->query("SELECT C.about,C.type,C.votetype,C.tplcode,C.ifcomment,V.* FROM {$pre}vote_topic C LEFT JOIN {$pre}vote_element V ON C.cid=V.cid WHERE C.cid='$cid' ORDER BY V.list DESC");
$total=0;
while($rs = $db->fetch_array($query)){
$total=$total+$rs[votenum];
if($rs[type]==1){
$button=$rs[type]="";
}else{
$button=$rs[type]="";
}
//复制JS的
$i++;
$votenum=$rs[votenum];
$title=$rs[title];
$img=tempdir($rs[img]);
$url=$rs[url];
$id=$rs[id];
$cid=$rs[cid];
$tplcode=str_replace('"','\"',$rs[tplcode]);
$describes=$rs[describes];
if($votetype==2&&$i>1){
$shows.="";
}
eval("\$shows.=\"$tplcode\";");
$votetype=$rs[votetype];
//复制JS的
$about=$rs[about];
$ifcomment=$rs[ifcomment];
$listdb[$rs[id]]=$rs;
$numdb[$rs[id]]=$rs[votenum];
}
arsort($numdb);
$max=0;
foreach($numdb AS $key=>$value){
if(!$max&&$value){
$max=$value;
$widthdb[$key]=311;
}else{
$widthdb[$key]=ceil(310*$value/$max)+1;
}
}
$path=$votetype?"vote_$votetype":'vote';
require(ROOT_PATH."inc/head.php");
require(getTpl($path));
require(ROOT_PATH."inc/foot.php");
}
elseif($job=="shownum")
{
@extract($db->get_one("SELECT votenum FROM {$pre}vote_element WHERE id='$id'"));
echo "document.write('$votenum');";
}
?>