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

if($_GET["act"]=="insert"){
	$query=$db->query("Select * from {$web_dbtop}game_system where id=1");
	if($rs=$db->fetch_array($query)){
		$gamedodge_tz_minpoints=$rs["gamedodge_tz_minpoints"];
		$gamedodge_jl_experience=$rs["gamedodge_jl_experience"];
		$gamedodge_jl_maxexperience=$rs["gamedodge_jl_maxexperience"];
		$gamedodge_jl_experience_vip=$rs["gamedodge_jl_experience_vip"];
		$gamedodge_jl_maxexperience_vip=$rs["gamedodge_jl_maxexperience_vip"];
	}
	$query=$db->query("Select points,authentication,loginip from {$web_dbtop}users where id=".intval($_COOKIE["usersid"]));
	if($rs=$db->fetch_array($query)){
		$userspoints=$rs["points"];
		$authentication=$rs["authentication"];
		$loginip=$rs["loginip"];
	}
	if($authentication!=1){
		echo "<script>alert('对不起，您还没有通过身份验证无法进行该游戏!');history.go(-1);</script>";
		exit;
	}
	if(intval($_POST["tbInsertMoney"])<$gamedodge_tz_minpoints){
		echo "<script>alert('对不起，下注".$web_moneyname."不能少于".$gamedodge_tz_minpoints."!');history.go(-1);</script>";
		exit;
	}
	if($userspoints<intval($_POST["tbInsertMoney"])){
		echo "<script>alert('对不起，您的".$web_moneyname."不足".intval($_POST["tbInsertMoney"])."!');history.go(-1);</script>";
		exit;
	}
	if($_POST["password"]!=$_POST["r_password"]){
		echo "<script>alert('对不起，两次输入密码不同!');history.go(-1);</script>";
		exit;
	}
	$db->query("INSERT INTO {$web_dbtop}gamedodge (time,uid,points,password,dodge,nopassword) VALUES ('".date("Y-m-d H:i:s")."',".intval($_COOKIE["usersid"]).",".intval($_POST["tbInsertMoney"]).",'".md5($_POST["password"])."',".intval($_POST["bselect"]).",".($_POST["password"]?1:0).")");
	$db->query("update {$web_dbtop}users set points=points-".intval($_POST["tbInsertMoney"])." where id=".intval($_COOKIE["usersid"]));
	$db->query("update {$web_dbtop}game_log set gamedodge_hd=gamedodge_hd-".intval($_POST["tbInsertMoney"])." where uid=".intval($_COOKIE["usersid"]));
	echo "<script>alert('摆擂成功,冻结帐户".intval($_POST["tbInsertMoney"]).$web_moneyname."!');location.href='dodge.php';</script>";
	exit;
}else if($_GET["act"]=="tzinsert"){
	$experience=0;
	$query=$db->query("Select * from {$web_dbtop}game_system where id=1");
	if($rs=$db->fetch_array($query)){
		$gamedodge_tz_cl=$rs["gamedodge_tz_cl"];
		$gamedodge_tz_minpoints=$rs["gamedodge_tz_minpoints"];
		$gamedodge_jl_experience=$rs["gamedodge_jl_experience"];
		$gamedodge_jl_maxexperience=$rs["gamedodge_jl_maxexperience"];
		$gamedodge_jl_experience_vip=$rs["gamedodge_jl_experience_vip"];
		$gamedodge_jl_maxexperience_vip=$rs["gamedodge_jl_maxexperience_vip"];
	}
	$query=$db->query("Select points,authentication,dailydodgeexperience,vip,loginip from {$web_dbtop}users where id=".intval($_COOKIE["usersid"]));
	if($rs=$db->fetch_array($query)){
		$userspoints=$rs["points"];
		$dailydodgeexperience=$rs["dailydodgeexperience"];
		$authentication=$rs["authentication"];
		$vip=$rs["vip"];
		if($vip==1){
			$gamedodge_maxexperience=$gamedodge_jl_maxexperience_vip;
		}else{
			$gamedodge_maxexperience=$gamedodge_jl_maxexperience;
		}
	}
	if($authentication!=1){
		echo "<script>alert('对不起，您还没有通过身份验证无法进行该游戏!');history.go(-1);</script>";
		exit;
	}
	$query=$db->query("Select * from {$web_dbtop}gamedodge where id=".intval($_GET["dodgeno"])." and zt!=1 Order by id desc");
	if($rs=$db->fetch_array($query)){
		if($loginip==showcontent("users","loginip",$rs["uid"])){
			echo "<script>alert('对不起,请不要同一人使用多帐号互相转帐作弊!');history.go(-1);</script>";
			exit;
		}
		if($userspoints<$rs["points"]){
			echo "<script>alert('对不起，您的".$web_moneyname."不足".$rs["points"]."!');history.go(-1);</script>";
			exit;
		}
		if(md5($_POST["password"])!=$rs["password"]){
			echo "<script>alert('对不起，挑战密码不正确!');history.go(-1);</script>";
			exit;
		}
		
		if($dailydodgeexperience<=$gamedodge_maxexperience){
			if($vip==1){
				$experience=$gamedodge_jl_experience_vip;
			}else{
				$experience=$gamedodge_jl_experience;
			}
		}
		$dodgejg=dodgejg(intval($_POST["bselect"]),$rs["dodge"]);
		if($dodgejg==1){
			$db->query("update {$web_dbtop}users set points=points+".intval($rs["points"]*(100-$gamedodge_tz_cl)/100).",experience=experience+$experience,maxexperience=maxexperience+$experience,dailydodgeexperience=dailydodgeexperience+$experience where id=".intval($_COOKIE["usersid"]));
			$db->query("update {$web_dbtop}game_log set gamedodge_hd=gamedodge_hd+".intval($rs["points"]*(100-$gamedodge_tz_cl)/100)." where uid=".intval($_COOKIE["usersid"]));
			$db->query("update {$web_dbtop}gamedodge set zt=1,tzdodge=".intval($_POST["bselect"]).",tzid=".intval($_COOKIE["usersid"])." where id=".$rs["id"]);
			$db->query("update {$web_dbtop}webtj set gamedodge=".intval($rs["points"]*$gamedodge_tz_cl/100)." where time='".date("Y-m-d")."'");
			echo "<script>alert('猜拳挑战成功,详细内容请看猜拳记录!');location.href='dodge.php';</script>";
			exit;
		}else if($dodgejg==2){
			$db->query("update {$web_dbtop}users set points=points+".$rs["points"]."+".intval($rs["points"]*(100-$gamedodge_tz_cl)/100)." where id=".$rs["uid"]);
			$db->query("update {$web_dbtop}game_log set gamedodge_hd=gamedodge_hd+".$rs["points"]."+".intval($rs["points"]*(100-$gamedodge_tz_cl)/100)." where uid=".$rs["uid"]);
			$db->query("update {$web_dbtop}users set points=points-".$rs["points"].",experience=experience+$experience,maxexperience=maxexperience+$experience,dailydodgeexperience=dailydodgeexperience+$experience where id=".intval($_COOKIE["usersid"]));
			$db->query("update {$web_dbtop}game_log set gamedodge_hd=gamedodge_hd-".$rs["points"]." where uid=".intval($_COOKIE["usersid"]));
			$db->query("update {$web_dbtop}gamedodge set zt=1,tzdodge=".intval($_POST["bselect"]).",tzid=".intval($_COOKIE["usersid"])." where id=".$rs["id"]);
			$db->query("update {$web_dbtop}webtj set gamedodge=".intval($rs["points"]*$gamedodge_tz_cl/100)." where time='".date("Y-m-d")."'");
			echo "<script>alert('猜拳挑战失败,详细内容请看猜拳记录!');location.href='dodge.php';</script>";
			exit;
		}else{
			$db->query("update {$web_dbtop}users set points=points+".$rs["points"]." where id=".$rs["uid"]);
			$db->query("update {$web_dbtop}game_log set gamedodge_hd=gamedodge_hd+".$rs["points"]." where uid=".$rs["uid"]);
			$db->query("update {$web_dbtop}users set experience=experience+$experience,maxexperience=maxexperience+$experience,dailydodgeexperience=dailydodgeexperience+$experience where id=".intval($_COOKIE["usersid"]));
			$db->query("update {$web_dbtop}gamedodge set zt=1,tzdodge=".intval($_POST["bselect"]).",tzid=".intval($_COOKIE["usersid"])." where id=".$rs["id"]);
			echo "<script>alert('猜拳挑战平局,详细内容请看猜拳记录!');location.href='dodge.php';</script>";
			exit;
		}
	}else{
		echo "<script>alert('对不起，已经有人挑战成功!');location.href='dodge.php';</script>";
		exit;
	}
}
?>
<!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(2);
document.getElementById("qh_con2").getElementsByTagName('li')[6].className="current";
</script>
<DIV class="wrapper">
	<DIV class="page_content">
		<DIV class="webgame-info-title">
		  <UL>
			<LI><A href="dodge.php">猜拳首页</A></LI>
			<LI class="current"><A href="dodgeinsert.php">我要摆擂</A></LI>
			<LI><A href="dodgemylist.php">我的投注记录</A></LI>
			<LI><A href="bbs/forum.php?forumsid=5">玩家交流</A></LI>
		  </UL>
		</DIV>
		<DIV class="webgame-info">
			<DIV class="webgame-info-tabs">
			<?
			if($_GET["act"]=="tz"){
				$query=$db->query("Select * from {$web_dbtop}gamedodge where id=".intval($_GET["dodgeno"])." Order by id desc");
				if($rs=$db->fetch_array($query)){
					$id=$rs["id"];
					$uid=$rs["uid"];
					$points=$rs["points"];
					$nopassword=$rs["nopassword"];
					
				}
			?>
              <table width="940" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#B63A2A">
                <tr>
                  <td height="28" align="center" background="images/dn02.jpg" bgcolor="#FBE4DE">您本次挑战对象是
                      <?=$uid?></td>
                </tr>
                <tr>
                  <td height="100" bgcolor="#FFFFFF"><form action="?act=tzinsert&dodgeno=<?=$id?>" method="post">
                      <table width="95%" border="0" align="center" cellpadding="0" cellspacing="10">
                        <tr>
                          <td align="center" class="font14red"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td align="center"><img src="images/dodge/1.gif" width="49" height="46"><br>
                                  石头</td>
                                <td align="center"><img src="images/dodge/2.gif" width="49" height="46"><br>
                                  剪刀</td>
                                <td align="center"><img src="images/dodge/3.gif" width="54" height="52"><br>
                                  布</td>
                              </tr>
                              <tr align="center">
                                <td><INPUT id=radio type=radio CHECKED value=1 name=bselect></td>
                                <td><INPUT id=radio type=radio value=2 name=bselect></td>
                                <td><INPUT id=radio type=radio value=3 name=bselect></td>
                              </tr>
                          </table></td>
                        </tr>
                        <tr>
                          <td align="center"><table width="100%"  border="0" cellpadding="2" cellspacing="0">
                              <tr bgcolor="#FFFFFF">
                                <td width="13%" align="right">挑战<?=$web_moneyname?>：</td>
                                <td width="87%" align="left" class="rbf"><?=number_format($points)?>
                                  <?=$web_moneyname?></td>
                              </tr>
                              <?
						if($nopassword==1){
						?>
                              <tr bgcolor="#FFFFFF">
                                <td align="right">挑战密码：</td>
                                <td align="left"><input type="text" name="password" id="password" value=""  /></td>
                              </tr>
                              <?
						}
						?>
                          </table></td>
                        </tr>
                        <tr>
                          <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td width="60" align="right" valign="top"><span class="rf">注意：</span></td>
                                <td valign="top"><span class="font-hg">1、每次摆擂台系统将抽取获胜者本次擂台5%的费用,平局不抽.<br>
                    2、下注<?=$web_moneyname?>不能少于
						<?
						$query=$db->query("Select gamedodge_tz_minpoints from {$web_dbtop}game_system where id=1");
						if($rs=$db->fetch_array($query)){
							echo $rs["gamedodge_tz_minpoints"];
						}
						?>.</span></td>
                              </tr>
                          </table></td>
                        </tr>
                        <tr>
                          <td align="center"><input name="image" type="image" src="images/dn_menu.jpg" width="219" height="46" border="0" /></td>
                        </tr>
                      </table>
                  </form></td>
                </tr>
              </table>
              <?
			}else{
			?>
              <table width="940" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#B63A2A">
                <tr>
                  <td height="28" align="center" background="images/dn02.jpg" bgcolor="#FBE4DE">摆擂成功后您就成为擂主，等待挑战者前来打擂吧！</td>
                </tr>
                <tr>
                  <td height="100" bgcolor="#FFFFFF"><form action="?act=insert" method="post">
                      <table width="95%" border="0" align="center" cellpadding="0" cellspacing="10">
                        <tr>
                          <td align="center" class="font14red"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td align="center"><img src="images/dodge/1.gif" width="49" height="46"><br>
                    石头</td>
                                <td align="center"><img src="images/dodge/2.gif" width="49" height="46"><br>
                    剪刀</td>
                                <td align="center"><img src="images/dodge/3.gif" width="54" height="52"><br>
                    布</td>
                              </tr>
                              <tr align="center">
                                <td><INPUT id=radio type=radio CHECKED value=1 name=bselect></td>
                                <td><INPUT id=radio type=radio value=2 name=bselect></td>
                                <td><INPUT id=radio type=radio value=3 name=bselect></td>
                              </tr>
                          </table></td>
                        </tr>
                        <tr>
                          <td align="center"><table width="100%"  border="0" cellpadding="2" cellspacing="0">
                              <tr bgcolor="#FFFFFF">
                                <td width="13%" align="right">我要下注：</td>
                                <td width="87%" align="left" class="rbf"><input type="text" name="tbInsertMoney" id="tbInsertMoney" value=""  /> <?=$web_moneyname?></td>
                              </tr>
                              <tr bgcolor="#FFFFFF">
                                <td align="right">设置密码：</td>
                                <td align="left"><input type="checkbox" name="nopws" value="1" onClick="showcheckbox('nopws')"></td>
                              </tr>
                              <tr bgcolor="#FFFFFF" id="show_pws1" style="display:none;">
                                <td align="right">密码：</td>
                                <td align="left"><input type="text" name="password" id="password" value=""  /></td>
                              </tr>
                              <tr bgcolor="#FFFFFF" id="show_pws2" style="display:none;">
                                <td align="right">确认密码：</td>
                                <td align="left"><input type="text" name="r_password" id="r_password" value=""  /></td>
                              </tr>
                          </table></td>
                        </tr>
                        <tr>
                          <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td width="60" align="right" valign="top"><span class="rf">注意：</span></td>
                                <td valign="top"><span class="font-hg">1、每次摆擂台系统将抽取获胜者本次擂台5%的费用,平局不抽.<br>
                    2、下注<?=$web_moneyname?>不能少于
                        <?
						$query=$db->query("Select gamedodge_tz_minpoints from {$web_dbtop}game_system where id=1");
						if($rs=$db->fetch_array($query)){
							echo $rs["gamedodge_tz_minpoints"];
						}
						?>
                    . </span></td>
                              </tr>
                          </table></td>
                        </tr>
                        <tr>
                          <td align="center"><input name="image" type="image" src="images/dn_menu.jpg" width="219" height="46" border="0" /></td>
                        </tr>
                      </table>
                  </form></td>
                </tr>
              </table>
              <?
			}
			?>
			<script language="javascript">
			function showcheckbox(cname){
				if(document.getElementById(cname).checked==true){
					showThumbnail_RateOrSize(1)
				}else{
					showThumbnail_RateOrSize(0)
				}
			}
			function showThumbnail_RateOrSize(param){
				if(param==1){
					document.getElementById("show_pws1").style.display="block";
					document.getElementById("show_pws2").style.display="block";
				}else{
					document.getElementById("show_pws1").style.display="none";
					document.getElementById("show_pws2").style.display="none";
				}
			}
			</script>
			</DIV>
			<DIV class=cl></DIV>
		</DIV>
		<DIV class="area960-b h5px"></DIV>
	<!--Flink End-->
	<div class="blank10"></div>
	<!--Footer Start-->
<?php include_once("footer.php");?>
</DIV>