<?php
	session_start();	
	
	ini_set('session.gc_maxlifetime', 99999999); //设置时间 永不过期

	header("Content-type:text/html;charset=gb2312");
	
	$strwxid=trim($_SESSION["main_wxudid"]);
	$pageid=$_REQUEST["pgid"];
	
	require_once("db/db.php");	
	require_once("common/common.php");
	
	if(strlen($strwxid)>10)
	{
		//根据微信号登陆
		$intNextFlag=0;
		
		$sql = sprintf("SELECT a.VIP_No,a.Sub_No,a.Sub_Name,a.Sub_Sex,a.Sub_Pswd,a.Sub_State,b.VIP_Type,b.VIP_State,a.Sub_TelNo,convert(varchar(10),Sub_Borth,120) as VIPBorth,
					a.Sub_IDType,a.Sub_IDNo,a.wx_no FROM VIP_Item a,VIP_Main b WHERE a.VIP_No=b.VIP_No AND a.wx_no='%s'",$strwxid);
	
		$result = querySql($sql);
		if($row = fetch_array($result))
		{
			//如果有会员号
			$strsubno=trim($row['Sub_No']);
			//判断密码是否一样
			if(strlen($row['Sub_No'])>0)
			{
				//如果密码正确 VIP_No    VIP_State
				//=============================================================//
				$_SESSION["main_vipno"]=$row['Sub_No'];
				$_SESSION["main_vipname"]=$row['Sub_Name'];
				$_SESSION["main_vipsex"]=$row['Sub_Sex'];
				$_SESSION["main_vippswd"]=$row['Sub_Pswd'];
				$_SESSION["main_viptype"]=$row['VIP_Type'];
				$_SESSION["main_vipstate"]=$row['Sub_State'];
				$_SESSION["main_viptelno"]=$row['Sub_TelNo'];
				$_SESSION["main_vipborth"]=$row['VIPBorth'];
				$_SESSION["main_vipidtype"]=$row['Sub_IDType'];
				$_SESSION["main_vipidno"]=$row['Sub_IDNo'];
				$_SESSION["main_vipVIPNo"]=$row['VIP_No'];
				$_SESSION["main_vipVIPState"]=$row['VIP_State'];
				$_SESSION["main_viplogined"]="1";	//登录成功
				$_SESSION["main_defvipnoflag"]="1";
				$_SESSION["main_vipwxudid"]=trim($row['wx_no']);
				
				//=============================================================//
				if($_SESSION["main_vipstate"]=='在册')	//跳转到首页
					$intNextFlag=1;
				else
					$intNextFlag=4;		//会员已挂失或注销
			}
			else
			{
				$intNextFlag=2;
			}
		}
		else
		{	//会员号不存在
			$intNextFlag=3;
		}
		//释放数据库
		freeResult($result);
		
		//执行跳转指令
		if($intNextFlag==1)
		{
			if($pageid=='0')
			{
				echo "<script>window.location.href='orderlist.php?bstat=0';</script>";
			}
			elseif($pageid=='1')
			{
				echo "<script>window.location.href='orderlist.php?bstat=1';</script>";
			}
			elseif($pageid=='2')
			{
				echo "<script>window.location.href='orderlist.php?bstat=2';</script>";
			}
			elseif($pageid=='3')
			{
				echo "<script>window.location.href='orderlist.php?bstat=3';</script>";
			}
			elseif($pageid=='4')
			{
				echo "<script>window.location.href='orderlist.php?bstat=4';</script>";
			}
			elseif($pageid=='5')
			{
				echo "<script>window.location.href='orderpaysel.php?selbillno=".$_SESSION["temp_wxbill_billno"]."';</script>";
			}
			else
			{
				echo "<script>window.location.href='vipmain.php';</script>";
			}
		}
		//echo $strwxid . '****'. $intNextFlag;
		//exit;
	}
	
	//开始显示数据
	$fltvoucherval=0;
	$intvoucherdays=0;
	$intvouchercount=0;
	$fltsendintegral=0;

	//echo "ssssss".$intNextFlag;
	//exit ;
	//if($intNextFlag!=1)
	//{
		//获取要注册显示的优惠项目
		$sql = sprintf("SELECT Send_VoucherCount,Send_VoucherVal,Send_VoucherDays,Send_IntegVal FROM VIP_Type Where IsDefType>0");
			
		$result = querySql($sql);
		if($row = fetch_array($result))
		{
			$fltvoucherval=$row['Send_VoucherVal'];
			$intvoucherdays=$row['Send_VoucherDays'];
			$intvouchercount=$row['Send_VoucherCount'];
			$fltsendintegral=$row['Send_IntegVal'];
			
			if(empty($fltvoucherval))
				$fltvoucherval=0;
			if(empty($intvoucherdays))
				$intvoucherdays=0;
			if(empty($intvouchercount))
				$intvouchercount=0;
			if(empty($fltsendintegral))
				$fltsendintegral=0;
		}
		freeResult($result);	
	//}
	closeDb();
?>

<!DOCTYPE html>
<html>
<head>
	<meta charset="gb2312">	
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
	<meta name="apple-mobile-web-app-capable" content="1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="format-detection" content="telephone=0">
	<meta name="apple-touch-fullscreen" content="1">

	<title>微信会员</title>

	<script src="jsp4/jquery.js"></script>
	<script src="jsp4/jquery.placeholder.min.js"></script>
	
	<!--<link rel="stylesheet" href="jsp5/jquery.mobile-1.4.5.min.css">-->
	<!--<script src="jsp4/jquery.mobile-1.4.3.min.js"></script>-->
	<script src="jsp5/jquery.mobile-1.4.5.min.js"></script>
	<link rel="stylesheet" href="jsp5/jquery.mobile-1.4.5.min.css">
	
	<script language="JavaScript"> 
		//不允许进行后退
		javascript:window.history.forward(0); 
	</script>
	
</head>

<?php 
	$vipno=$_REQUEST['vipno'];
	$_SESSION["parent_vipno"] = $vipno;
	
	//echo $_SESSION["parent_vipno"];
	//exit();

	$ptemp=$_REQUEST['stext'];
	$pstext='';
	
	if($ptemp=='12')
		$pstext='密码错误,请联系酒店找回密码';
	elseif($ptemp=='13')
		$pstext='登录失败,无此用户号';
	elseif($ptemp=='14')
		$pstext='未知错误';
	elseif($ptemp=='15')
		$pstext='已存在该手机的注册信息！';
	elseif($ptemp=='16')
		$pstext='该账号已'.$_SESSION["main_vipstate"];
?>

<script>
	//清空登录信息资料
	ddt=<?php echo $_SESSION["main_newvipno"]; ?>;
	if(ddt.length>0) {
		localStorage["main_defvipno"]=ddt;
	}
</script>

<script>	
		//隐藏维信右上角菜单
		function onBridgeReady(){
			//WeixinJSBridge.call('hideOptionMenu');
		}

		if (typeof WeixinJSBridge == "undefined")
		{
			if( document.addEventListener )
			{
				document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
			}
			else if (document.attachEvent)
			{
				document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
				document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
			}
		}
		else
		{
			onBridgeReady();
		}
</script>

	
<body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0">

<div data-role="page">
	<header data-role="header" data-position="fixed" style="height:50px;">
		<div align="center"><h3>微信会员</h3></div>
	</header>
	<?php

		//开始显示数据
		$fltvoucherval=0;
		$intvoucherdays=0;
		$intvouchercount=0;
		$fltsendintegral=0;

		//echo "ssssss".$intNextFlag;
		//exit ;
		//if($intNextFlag!=1)
		//{
			//获取要注册显示的优惠项目
			$sql = sprintf("SELECT Send_VoucherCount,Send_VoucherVal,Send_VoucherDays,Send_IntegVal FROM VIP_Type Where IsDefType>0");
			
			$result = querySql($sql);
			if($row = fetch_array($result))
			{
				$fltvoucherval=$row['Send_VoucherVal'];
				$intvoucherdays=$row['Send_VoucherDays'];
				$intvouchercount=$row['Send_VoucherCount'];
				$fltsendintegral=$row['Send_IntegVal'];
			}
			freeResult($result);	
		//}
		closeDb();
	
	?>
	<div data-role="content" align="center">	
		<div style="left:2%;width:96%;height:123px;border-radius:5px;border-top:1px solid #ddd;border-bottom:1px solid #ddd;border-left:1px solid #ddd;border-right:1px solid #ddd;">	
			<div style="width:100%;height:53px;border-radius:5px;padding-top:5px;padding-bottom:0px;">
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td height="60" width="50" align="center">
							<a class="ui-btn ui-icon-user ui-btn-icon-notext ui-corner-all" href="#"></a>			
						</td>
							
						<td height="60" align="right">
							<div style="float:left;width:100%;">
								<?php if($ptemp=='15') { ?>
									<input type="text" name="userno" id="userno" value="<?php echo $_SESSION['main_newvipno'];?>" placeholder="用户编号/手机号" data-clear-btn="true"/>
								<?php } else { ?>
									<input type="text" name="userno" id="userno" value="" placeholder="用户编号/手机号" data-clear-btn="true"/>
									<script>$("#userno").val(localStorage["main_defvipno"]);</script>
								<?php } ?>
							</div>			
						</td>
							
						<td height="60" width="15"></td>
					</tr>
				</table>    		
			</div>
			
			
			<div style="width:100%;height:55px;border-radius:5px;padding-top:0px;padding-bottom:0px;">
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td height="60" width="50" align="center">
								<a class="ui-btn ui-icon-lock ui-btn-icon-notext ui-corner-all" href="#"></a>			
						</td>
							
						<td height="60" align="right">
							<div style="float:left;width:100%;">
								<input id="pwd" name="pwd" value="" type="password" placeholder="请输入密码" autocomplete="off" data-clear-btn="true" />
							</div>			
						</td>
							
						<td height="60" width="15"></td>
					</tr>
				</table>    		
			</div>
		</div>
				
		<div style="left:2%;width:96%;height:60px;padding-top:6px;">	
			<button style="color:#999933;" class="ui-btn ui-corner-all" id="mypost">登录系统</button>
		</div>
		
		<div style="left:2%;width:96%;height:40px;">	
			<table width="100%" border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td height="40" width="75" align="right">
						<a href="javascript:void(0)" onClick="window.location.href='vipnew.php';" style="text-decoration:none;" title="忘记密码" type="button"><label style="color:#999933;text-decoration:none;" for="basic">免费注册</label></a>
					</td>
					<td height="40">&nbsp;</td>
					<td height="40" width="80" align="right">
						<!--<label style="color:#999966;" for="basic">找回密码</label>-->
						<a href="javascript:void(0)" onClick="window.location.href='getpswd.php';" style="text-decoration:none;" title="忘记密码" type="button"><label style="color:#999933;text-decoration:none;" for="basic">找回密码?</label></a>
					</td>
						
					<td height="40" width="15"></td>
				</tr>
			</table>    	
		</div>
		
		<?php
			if(strlen($pstext)>0)
			{
		?>
		<div align="center"><span style="color: #666666;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:14px;"><?php echo $pstext;?></span></div>
		<?php
				$pstext="";
			}
		?>
		
		<?php 
			if($intvouchercount > 0 || $fltsendintegral>0 ) {
			
			$intRowID=1;
		?>
		<div style="width:100%;height:50px;padding-top:6px;">	
			<table width="100%" border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td height="1" width="10"></td>
					<td height="1" bgcolor="#F2E2E2"></td>
					<td height="1" width="10"></td>
				</tr>
				
				<tr>
					<td height="20" width="10"></td>
					<td height="20" align="left">
						<span style="color: #999999;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif;font-size:12px;">免费注册为会员后送您如下福利：</span>
					</td>
					<td height="20" width="10"></td>
				</tr>
				<?php if($intvouchercount > 0) { ?>
				<tr>
					<td height="20" width="10"></td>
					<td height="20" align="left">
						<span style="color: #999999;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif;font-size:12px;"><?php echo $intRowID;?>.可获得面额<?php echo number_format($fltvoucherval);?>元的电子券<?php echo $intvouchercount;?>张</span>
					</td>
					<td height="20" width="10"></td>
				</tr>
				<?php 
						$intRowID=$intRowID + 1;
					} 
				?>
				
				<?php if($fltsendintegral > 0) { ?>
				<tr>
					<td height="20" width="10"></td>
					<td height="20" align="left">
						<span style="color: #999999;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif;font-size:12px;"><?php echo $intRowID;?>.可获得积分<?php echo number_format($fltsendintegral);?>分</span>
					</td>
					<td height="20" width="10"></td>
				</tr>
				<?php } ?>
			</table>    	
		</div>
		
		<?php } ?>
	</div>
	
	<footer data-role="footer" data-position="fixed">
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
			<tr>
				<td height="6">
				</td>
			</tr>
		</table>    
	</footer>
	
	<script type="text/javascript">
		
		 	$("#mypost").click(
				function()
		 		{
		 			var struserno = $("#userno").val();
		 			var strpswd = $("#pwd").val();
					if(struserno=="")
					{	
						$("#userno").focus();
						return;
					}
		 			window.location.href='logina.php?userno=' + struserno + '&pwd=' + strpswd + '&pgid=<?php echo $pageid;?>';
		 		}
			);
	</script>
	
	<script>
		//禁止页面上下滑动,整个页面都不能滑动了
		document.addEventListener('touchmove', function(e) {
			e.preventDefault();
		});
</script>
</div>

</body>

</html>
