<?php
include_once("inc/conn.php");
include_once("inc/function.php");
login_check();

$query=$db->query("Select * from {$web_dbtop}adquestions where id=".intval($_GET["adid"]));
if($rs=$db->fetch_array($query)){
	$adid=$rs["id"];
	$questionsnum=$rs["questionsnum"];
	$dailynum=$rs["dailynum"];
	$points=$rs["points"];
}
$db->query("delete from {$web_dbtop}adip where type=1 and STR_TO_DATE(time,'%Y-%m-%d')<'".date('Y-m-d')."'");
$query=$db->query("Select id from {$web_dbtop}adip where uid=".intval($_COOKIE["usersid"])." and type=1 and adid=".$adid."");
if($rs=$db->fetch_array($query)){
	$num=$db->num_rows($query);
}
if($dailynum<=$num){
	echo "<script language=javascript>alert('对不起,每个用户每天只能体验".$dailynum."次');location.href='profit.php';</script>";
	exit;
}

if($_GET["act"]=="chkAnswer"){
	$query=$db->query("Select * from {$web_dbtop}adquestions_issue where id=".intval($_GET["faqid"]));
	if($rs=$db->fetch_array($query)){
		if($rs["adzq1"]==intval($_POST["tbAnsID1"]) && $rs["adzq2"]==intval($_POST["tbAnsID2"]) && $rs["adzq3"]==intval($_POST["tbAnsID3"]) && $rs["adzq4"]==intval($_POST["tbAnsID4"])){
			if(($questionsnum<=$_COOKIE[$_GET["adid"]])){
				$db->query("update {$web_dbtop}users set points=points+$points where id=".intval($_COOKIE["usersid"]));
				$db->query("insert into {$web_dbtop}adip (uid,ip,time,type,adid) values (".intval($_COOKIE["usersid"]).",'".usersip()."','".date("Y-m-d H:i:s")."',1,".$adid.")");
				setcookie($adid);
				$query_x=$db->query("Select * from {$web_dbtop}adtj where STR_TO_DATE(time,'%Y-%m-%d')='".date("Y-m-d")."' and type=3");
				if($rs_x=$db->fetch_array($query_x)){
					$db->query("update {$web_dbtop}adtj set num=num+1,points=points+$points where id=".$rs_x["id"]);
				}else{
					$db->query("insert into {$web_dbtop}adtj (time,num,points,type) values ('".date("Y-m-d")."',1,".$points.",3)");
				}
				$db->query("update {$web_dbtop}game_log set ad_hd=ad_hd+$points where uid=".intval($_COOKIE["usersid"]));
				userslog(1,"问卷广告体验",$points,0);
				echo "<script language=javascript>alert('恭喜回答对该组所有题目，并获得".$points.$web_moneyname."！');location.href='profit.php';</script>";
				exit;
			}else{
				setcookie($_GET["adid"],$_COOKIE[$_GET["adid"]]+1);
				echo "<script language=javascript>alert('回答正确进入".($_COOKIE[$_GET["adid"]]+1)."第！');location.href='adquestions.php?adid=".$adid."';</script>";
				exit;
			}
		}else{
			echo "<script language=javascript>alert('对不起,回答错误请重新回答！');history.go(-1);</script>";
			exit;
		}
	}
}

if(empty($_COOKIE[$_GET["adid"]])){
	setcookie($_GET["adid"],1);
	$adorder=1;
}else{
	$adorder=$_COOKIE[$_GET["adid"]];
}
$query=$db->query("Select * from {$web_dbtop}adquestions_issue where adid=".$adid." and adorder=".intval($adorder));
if($rs=$db->fetch_array($query)){
	$faqid=$rs["id"];
	$adtm=$rs["adtm"];
	$adda1=$rs["adda1"];
	$adda2=$rs["adda2"];
	$adda3=$rs["adda3"];
	$adda4=$rs["adda4"];
	$addaurl=$rs["addaurl"];
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>问卷广告-<?=$web_name;?></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="keywords" content="<?=$web_keywords;?>" />
<meta name="description" content="<?=$web_description;?>" />
<META http-equiv=X-UA-Compatible content=IE=EmulateIE7>
<link href="style/default.css" rel="stylesheet" type="text/css" />
</head>
<?php include_once("top.php");?>
<script language="javascript">
qiehuan(1);
document.getElementById("qh_con1").getElementsByTagName('li')[4].className="current";
</script>
<DIV class="wrapper">
	<DIV class="page_content">
		<DIV class="webgame-info-title">
			<H3>问卷调查--当前第<span class="rf"><?=$adorder?></span>题 共<span class="rf"><?=$questionsnum?></span>题</H3>
		</DIV>
			<UL class="webgame-info">
			  <table width="700" border="0" align="center" cellpadding="4" cellspacing="4">
                <tr>
                  <td valign="top"><form method="post" action="?act=chkAnswer&adid=<?=$adid?>&faqid=<?=$faqid?>" onsubmit="return ChkAnswer()">
                      <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td width="40" height="40" class="font14"><strong>问题:</strong></td>
                          <td class="font14 rf"><strong><?=$adtm?></strong></td>
                        </tr>
                        <tr>
                          <td></td>
                          <td class="font14"><? if($adda1){?>
                              <input name="tbAnsID1" id="tbAnsID1" type="checkbox" value="1" />
                              <?=$adda1?>
                              <br />
                              <br />
                              <? }?>
                              <? if($adda2){?>
                              <input name="tbAnsID2" id="tbAnsID2" type="checkbox" value="1" />
                              <?=$adda2?>
                              <br />
                              <br />
                              <? }?>
                              <? if($adda3){?>
                              <input name="tbAnsID3" id="tbAnsID3" type="checkbox" value="1" />
                              <?=$adda3?>
                              <br />
                              <br />
                              <? }?>
                              <? if($adda4){?>
                              <input name="tbAnsID4" id="tbAnsID4" type="checkbox" value="1" />
                              <?=$adda4?>
                              <? }?>
                          </td>
                        </tr>
                        <tr>
                          <td height="60" class="font14">&nbsp;</td>
                          <td class="font14"><a href="<?=$addaurl?>" target="_blank"><img src="images/Questions_15.gif" width="103" height="25" border="0" /></a>
                              <input type="image" id="btnSubmit" src="images/Questions_17.gif" width="66" height="25" border="0" />
                          </td>
                        </tr>
                      </table>
                      </form>
                      <script type="text/javascript">
								<!--
								function ChkAnswer(){
									document.getElementById("btnSubmit").disabled=true;
									var c = false;
									for(i=0;i<4;i++){
										if(document.getElementById("tbAnsID"+i).checked){
											c = true;
											break;
										}
									}
									if(c == false){
										alert("请选择答案后，再提交！");
										document.getElementById("btnSubmit").disabled=false;
										return false;
									}
								}
								window.onkeydown = function(){
									event.keyCode = 0;
									event.returnvalue = false;
									return false;
								}
								-->
								</script>
                  </td>
                </tr>
                </table>
			</UL>
		<div class="area960-b h5px"></div>
		<div class="blank10"></div>
	</div>
	<!--Flink End-->
	<DIV class=cl></DIV>
	<div class="blank10"></div>
	<!--Footer Start-->
<?php include_once("footer.php");?>
</DIV>