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

if($_GET["act"]=="card"){
	if(!$_POST["tbCardNO"]){
		echo "<script language=javascript>alert('对不起，请输入卡号！');history.go(-1);</script>";
		exit;
	}
	if(!$_POST["tbCardPwd"]){
		echo "<script language=javascript>alert('对不起，请输入密码！');history.go(-1);</script>";
		exit;
	}
	if(strtolower($_SESSION["yan"])!=strtolower($_POST["tbSafeCode"])){
		echo "<script language=javascript>alert('验证码错误!');history.go(-1);</script>";
		exit;
	}
	$query=$db->query("Select * from {$web_dbtop}card where cardid='".str_check($_POST["tbCardNO"])."' and cardpaw='".str_check($_POST["tbCardPwd"])."'");
	if($rs=$db->fetch_array($query)){
		if($rs["state"]==1){
			echo "<script language=javascript>alert('该卡已经被 ".$rs["uid"]." 用户在 ".$rs["utime"]." 使用!');history.go(-1);</script>";
			exit;
		}else{
			$query_f=$db->query("Select * from {$web_dbtop}cardtype where id=".$rs["cardtype"]."");
			if($rs_f=$db->fetch_array($query_f)){
				$ueid=$rs_f["ueid"];
				$uevip=$rs_f["uevip"];
				$viplength=$rs_f["viplength"];
				$uapoints=$rs_f["uapoints"];
				$uaexperience=$rs_f["uaexperience"];
				$udapoints=$rs_f["udapoints"];
				$udaexperience=$rs_f["udaexperience"];
				$length=$rs_f["length"];
			}
			$query_f=$db->query("Select tjid,time from {$web_dbtop}users where id=".intval($_COOKIE["usersid"])."");
			if($rs_f=$db->fetch_array($query_f)){
				$uid=$rs_f["tjid"];
				$regtime=$rs_f["time"];
			}
			if($uid){
				$sxpoints=floor($uapoints*11/100);
				$db->query("update {$web_dbtop}users set points=points+$sxpoints where id =".$uid);
				$db->query("update {$web_dbtop}game_log set xx_hd=xx_hd+$sxpoints where uid=".$uid);
				$db->query("insert into {$web_dbtop}tjlog (uid,xid,type,regtime,points,time) values (".$uid.",".intval($_COOKIE["usersid"]).",'注册推荐','".date("Y-m-d",strtotime($regtime))."',".$sxpoints.",'".date("Y-m-d")."')");
				$db->query("update {$web_dbtop}webtj set tgpoints=tgpoints+$sxpoints where time='".date("Y-m-d")."'");
			}
			$db->query("update {$web_dbtop}users set points=points+$uapoints,experience=experience+$uaexperience,maxexperience=maxexperience+$uaexperience,vip=if($uevip=1,1,vip),vipdate=if($uevip=1,'".date("Y-m-d",time()+3600*24*$viplength)."',NULL),editid=$ueid,cardtime='".date("Y-m-d",time()+3600*24*$length)."',udapoints=$udapoints,udaexperience=$udaexperience where id =".intval($_COOKIE["usersid"])." and password='".str_check($_COOKIE["password"])."'");
			$db->query("update {$web_dbtop}game_log set dj_hd=dj_hd+$uapoints where uid=".intval($_COOKIE["usersid"]));
			$db->query("update {$web_dbtop}card set uid=".intval($_COOKIE["usersid"]).",state=1,utime='".date("Y-m-d H:i:s")."' where id =".$rs["id"]."");
			$db->query("update {$web_dbtop}webtj set card=card+$uapoints where time='".date("Y-m-d")."'");
			userslog(2,"使用体验卡",$uapoints,$uaexperience);
			if($ueid==1){
				echo "<script language=javascript>alert('充值成功,转到靓号选择页面！');location.href='useridedit.php';</script>";
				exit;
			}else{
				echo "<script language=javascript>alert('充值成功！');location.href='userAccount.php';</script>";
				exit;
			}
		}
	}else{
		echo "<script language=javascript>alert('对不起，你输入的卡号或是密码不正确，请您核实后从新输入！');history.go(-1);</script>";
		exit;
	}
}elseif($_GET["act"]=="use"){
	$query=$db->query("Select id,cardtime,udapoints,udaexperience,ldcardtime from {$web_dbtop}users where id =".intval($_COOKIE["usersid"])." and password='".str_check($_COOKIE["password"])."'");
	if($rs=$db->fetch_array($query)){
		if($rs["cardtime"]<date("Y-m-d")){
			echo "<script language=javascript>alert('对不起，您没有开通此功能!');history.go(-1);</script>";
			exit;
		}
		if(date("Y-m-d")<=$rs["ldcardtime"]){
			echo "<script language=javascript>alert('对不起，请您不要重复领取每日只能领取一次!');history.go(-1);</script>";
			exit;
		}
		$db->query("update {$web_dbtop}users set points=points+".$rs["udapoints"].",experience=experience+".$rs["udaexperience"].",maxexperience=maxexperience+".$rs["udaexperience"].",ldcardtime='".date("Y-m-d")."' where id =".$rs["id"]);
		$db->query("update {$web_dbtop}game_log set dj_hd=dj_hd+".intval($rs["udapoints"])." where uid=".$rs["id"]);
		$db->query("update {$web_dbtop}webtj set card=card+".intval($rs["udapoints"])." where time='".date("Y-m-d")."'");
		userslog(2,"种豆领取",$rs["udapoints"],$rs["udaexperience"]);
		$cardtime=$rs["cardtime"];
		echo "<script language=javascript>alert('成功领取".$rs["udapoints"].$web_moneyname.",种豆到期时间为".date("Y-m-d",strtotime("$cardtime+1 day"))."！');location.href='useraccount.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(6);
document.getElementById("qh_con6").getElementsByTagName('li')[2].className="current";
</script>
<DIV class="wrapper">
	<DIV class="page_content">
		<DIV class="webgame-activities-title">
			<H3>道具使用</H3>
		</DIV>
		<div class="main_users">
			<div class="main_txzreg">
				<p class="tit_reg"><img src="images/icon_tit01.gif" />&nbsp;&nbsp;请输入正确的卡号和密码，系统会自动增加您账户上的相应<?=$web_moneyname?>。</p>
				 <form action="?act=card" method="post">
					<table width="750" border="0" cellspacing="0" cellpadding="0" class="table_reg">             
						<tr>
						<td colspan="3"><SPAN class=STYLE1>说明:</SPAN><BR>
						1、本卡全称为“<?=$web_name;?>购物促销点卡”,具体方式为<?=$web_name?>和商家进行合作，用户购买 商家产品后，代理商可以将促销卡可以作为返点作为奖励用户进一步体验使用商家产品。<BR>
						2、<?=$web_name;?>不出售促销卡，同时也严禁用户之间倒卖促销卡。<BR>
						3、获得促销卡的用户请尽快使用，若出现任何问题，请联系我们的客服</td>
						</tr>
						<tr>
						<th width="150">卡&nbsp;&nbsp;&nbsp;号：</th>
							<td width="300"><input name="tbCardNO" class="inpA" type="text" id="tbCardNO" /></td>
							<td width="300">充值卡号码</td>
						</tr>
						<tr>
						<th>密&nbsp;&nbsp;&nbsp;码：</th>
							<td width="300"><input class="inpA" id="tbCardPwd" type="text" name="tbCardPwd" /></td>
							<td width="300">充值卡密码</td>
						</tr>
						<tr>
							<th>验证码：</th>
							<td><input name="tbSafeCode" type="text" id="tbSafeCode" style='text-transform:uppercase;' class="inp_yzm"/>&nbsp; <img id="regSafeCode" onclick="$('regSafeCode').src='inc/code.php';" src="inc/code.php" alt="看不清？点击更换" style="cursor:pointer"  width="60" height="26" /> <a href="javascript:showCode();">看不清楚？换个图片</a></td>
							<td></td>
						</tr>
						<tr>
							<th>&nbsp;</th>
							<td class="btn_reg"><input name="" type="image" src="images/ljtj.gif"></td>
						</tr>
					</table>
				</form>
			</div>
		</div>
		<div class="area960-b h5px"></div>
		<DIV class=cl></DIV>
	</div>
	<!--Flink End-->
	<div class="blank10"></div>
	<!--Footer Start-->
<?php include_once("footer.php");?>
</DIV>