<?php
	session_start();
	require_once("db/db.php");	
	require_once("common/common.php");
	ini_set('session.gc_maxlifetime', 99999999); //设置时间 永不过期
	//判断是否登录系统		
	if($_SESSION['main_wx_userlogined']!="1" | $_SESSION['main_wx_userno']=="")
	{
		//没有登录开始启动登录
		header('location:..\loginwx.php?rset=0');
		exit;
	}
	
	$strRevChainNo=$_REQUEST["chainno"];
	if(strlen($strRevChainNo)>0)
	{
		$sql=sprintf("SELECT Chain_No,Chain_Name FROM Chain_Infor WHERE Chain_No='%s'",$strRevChainNo);				
		$result = querySql($sql);		
		if($row = fetch_array($result))
		{
			$strNewChainNo= $row['Chain_No'];
			$strNewChainName= $row['Chain_Name'];
		}
		freeResult($result);
		
		$_SESSION["ChainNo"]=$strNewChainNo;
		$_SESSION["ChainName"]=$strNewChainName;
			
	}
	
	$chainno=$_SESSION["ChainNo"];
	
	//得到当前选择的服务员
	$intSelUserFlag=0;
	$strSelUserNo=trim($_REQUEST["fwuser"]);
	$strSelUserName='';
	if(strlen($strSelUserNo)>0)
	{
		//如果有选择的操作员
		$sql=sprintf("SELECT a.Use_Name,a.Use_No FROM User_QuanXian a,User_Group b WHERE a.Group_No=b.Group_No And a.FWFlag>0 And (b.Chain_No='%s' OR b.Chain_No='<所有>') And a.Use_No='%s'
					UNION Select a.Use_Name,a.Use_No From User_QuanXian a,User_Group b,User_Group_Chain c
					WHERE a.Group_No=b.Group_No AND a.Group_No=c.Group_No And a.FWFlag>0 And b.Chain_No<>'%s' AND c.Chain_No='%s' And a.Use_No='%s'
					ORDER BY a.Use_No ASC",$chainno,$strSelUserNo,$chainno,$chainno,$strSelUserNo);
		$result = querySql($sql);
		if($row = fetch_array($result))
		{
			$strSelUserNo= trim($row['Use_No']);
			$strSelUserName= trim($row['Use_Name']);
			$intSelUserFlag=1;
		}
		freeResult($result);
	}
	
	if($intSelUserFlag<1)
	{
		//未选择服务员，
		//关闭数据库
		closeDb();	

		header('location:fwmain.php?chainno='.$chainno);		
		exit;
	}
?>
<!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><?php echo $strSelUserName.'分房';?></title>
	
    <link rel="stylesheet" href="css/mycss.css"> 
    <link rel="stylesheet" href="jsp5/jquery.mobile-1.4.5.min.css">
    
	<script src="jsp5/jquery.js"></script>
  	<script src="jsp5/jquery.mobile-1.4.5.min.js"></script>
    <script src="jsp5/jquery-1.8.3.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 language="JavaScript"> 
		//不允许进行后退
		javascript:window.history.forward(0); 
	</script>
    
</head>

<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">
<!--第一个页面的内容实现---------------------------->
<section data-role="page" id="hispage1">
			
	<article data-role="none">
		<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
			<tr><td height="1" colspan="3" bgcolor="#f9f0f0"></td></tr>
			
			<tr><td height="2" colspan="3" bgcolor="#fff"></td></tr>
						
            <?php
            	$intAllRoomCount=0;
				
				$strselroomno='';
				$strrlistno='0';
				$introomstate=0;
				$introwindex=0;
				$strroomstate='';
				$intfloor=0;
				
				$sql=sprintf("SELECT a.ListNo,a.Room_No,a.Room_State,b.Room_Type,a.Dirty_Flag,a.Room_Floor FROM TR_Room_Inform a,TR_Room_Type b
								WHERE a.TypeListNo=b.ListNo And b.Chain_No='%s' And (UserNameNow='' OR UserNameNow IS NULL) And (a.Room_State=5 OR a.Dirty_Flag=1) Order By a.Room_No ASC",$chainno);

				$result = querySql($sql);
											
				while($row = fetch_array($result))
				{
					$strselroomno=$row['Room_No'];
					$strrlistno=$row['ListNo'];
					$introomstate=$row['Room_State'];
					$intfloor=$row['Room_Floor'];
			
					$intDirty=$row['Dirty_Flag'];
			
					$introwindex = $introwindex + 1;
					$intAllRoomCount=$intAllRoomCount+1;
					
					$strroomstate='';
					//状态:0空房,1预订房,2在住房,3钟点房,4自用房,5退客房,6维修房,7锁房
										
					//生成状态颜色
					switch($introomstate)
					{
						case 0:
							$strroomstate="当前状态：空净房";
							break;
						case 5:
							$strroomstate="当前状态：退客房";
							break;
						case 6:
							$strroomstate="当前状态：维修房";
							break;
						case 1:
							$strroomstate="当前状态：预订房";
							break;
						case 2:
							if($intDirty==1)
							{
								$strroomstate="当前状态：住脏房";
							}
							else
							{
								$strroomstate="当前状态：住客房";
							}
							break;
						case 3:
							$strroomstate="当前状态：钟点房";
							break;
						default:
							if($introomstate==5)
							{
								$strroomstate="当前状态：免费房";
							}
							if($introomstate==7)
							{
								$strroomstate="当前状态：锁房";
							}
							else
							{
								$strroomstate="当前状态：其他";
							}
							break;
					}
					

					
			?>
			
            <tr>
				<td height="50" width="15"></td>
				<td height="50" align="left">
                	
                    <!---显示房间信息列表--> 
                    <div id="cmdroomsuit" onClick="myroomclick(<?php echo $introwindex;?>);" >
                        <table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td height="49" width="90"> 
                                    <span style="color: #000;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:18px;"><?php echo $strselroomno;?></span> 
           							<input id="check<?php echo $introwindex;?>" name="check<?php echo $introwindex;?>" value="0" type="hidden" />
           							<input id="roomno<?php echo $introwindex;?>" name="roomno<?php echo $introwindex;?>" value="<?php echo $strselroomno;?>" type="hidden" />
           							<input id="selpos<?php echo $introwindex;?>" name="selpos<?php echo $introwindex;?>" value="0" type="hidden" />
                                    
                                </td>
                                <td height="49"> 
									<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
                                    	<tr><td width="100%" height="12%"></td></tr>
                                    	<tr><td width="100%" height="35%">
                                        	<span style="color: #a0a0a0;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;">所属楼层：<?php echo $intfloor;?>层</span>
                                         	</td></tr>
                                    	<tr><td width="100%" height="38%">
                                        	<span style="color: #a0a0a0;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:12px;"><?php echo $strroomstate;?></span> 
                                            </td></tr>
                                       	<tr><td width="100%" height="15%"></td></tr>
                                    </table>
                                </td>
                                <td height="49" width="40" valign="middle"> 
                                	<img id="imgroom<?php echo $introwindex;?>" style="width:35px;height:35px;border:0px; padding-top:5px;" src="images/check0.png" />
                                </td>
                            </tr>
                            
							<tr><td height="1" colspan="3" bgcolor="#f9f0f0"></td></tr>
                            
                        </table>
                    </div>
                </td>
				<td height="50" width="15"></td>
			</tr>
            
            <?php 
				}
				
				//释放数据库
				freeResult($result);	
				//关闭数据库
				closeDb();	
			?>
			
			<!--<tr><td height="1" colspan="3" bgcolor="#f9f0f0"></td></tr>-->
			
		</table>
		
				
	</article>
    
	<footer data-role="footer" data-position="fixed" data-tap-toggle="false" style="border-top:0px solid #F2E2E2;border-bottom:0px;border-left:0px solid #F2E2E2;border-right:0px solid #F2E2E2;">
		<table width="100%" height="10" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
		
        	<tr><td height="1" colspan="2" bgcolor="#f9f0f0"></td></tr>
            
            <tr height="35" valign="top" bgcolor="#F4EFEF">
            	<td height="35" valign="middle" colspan="2">
					<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
                        <tr>
							<td width="10" height="100%" align="center">
							<td height="100%" align="left">
								<span id="label1" style="color:#CD0013 ;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:14px;"> 已选房 0 间</span>
							</td>
					   </tr>
                    </table>
					
                </td>
            </tr>
            
            <tr height="1" valign="top">
            	<td height="1" width="50%" bgcolor="#F2E2E2"></td>
                <td height="1" width="50%" bgcolor="#F2E2E2"></td>
            </tr>
            
			<tr>
				<td height="100%" width="50%" bgcolor="#ffffff">
				
						<div onClick="window.location = 'fwmain.php?chainno=<?php echo $chainno;?>&fwuser=<?php echo $strSelUserNo;?>';" style="width:100%; height:45px; background-color:#D7AA28;">
                            <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
                                <tr><td width="100%" height="100%" align="center">
                                    <span style="color:#fff ;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:16px;text-shadow:none;">返 回</span>                            	
                                </td></tr>
                            </table>
                        </div>				
				</td>
				<td height="100%"  width="50%">
                	<!--<a href="#popupParis2" data-rel="popup" data-position-to="window" data-transition="fade">-->
                        <div id="bmtSendOk" onClick="bmtSendOkClick()" style="width:100%; height:45px; background-color:#CD0013;">
                            <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
                                <tr><td width="100%" height="100%" align="center">
                                    <span style="color:#fff ;font: 12px/1.5 '微软雅黑',tahoma, Srial, helvetica, sans-serif; font-size:16px;text-shadow:none;">确定分房</span>                            	
                                </td></tr>
                            </table>
                     	</div>
              		<!--</a>-->
				</td>
			</tr>
		</table>						
	</footer>
    
    
    
    <script type="text/javascript">
		//已选择房数
		var intHadSelCount=0;
		var intAllRoomCount=<?php echo $intAllRoomCount;?>;
		
		//点击房间时自动显示图片的方式	
		function myroomclick(rmid)
		{			
			var imgname = 'imgroom' + rmid.toString();
			var checkname = '#check' + rmid.toString();
			var checkpos = '#selpos' + rmid.toString();
			
			//得到当前选择的状态
			var checked = $(checkname).val();
			
			//alert(checked.toString());
			
			//得到图ID
			var img = document.getElementById(imgname);
			
			if(checked==0)
			{
				img.src="images/check1.png";
				$(checkname).val(1);
								
				//设置选择房间数+1
				intHadSelCount = intHadSelCount +1;
				
				//设置当前房间为第N个选择的
				$(checkpos).val(intHadSelCount);
			}
			else
			{
				img.src="images/check0.png";
				$(checkname).val(0);

				//alert(intHadSelCount.toString());
				
				var intdelval;	//要删除的流水号
				intdelval=$(checkpos).val();
				
				var inttemp1;
				//将当前选择的房间设置为未选择
				for(var i=1;i<	intAllRoomCount+1;i++)
				{
					inttemp1=$('#selpos' + i.toString()).val();	
					if(inttemp1>0)
					{
						if(intdelval==inttemp1)
						{
							$('#selpos' + i.toString()).val(0);			
						}
						else if(intdelval<=inttemp1)
						{
							$('#selpos' + i.toString()).val(inttemp1-1);	
						}
					}
					
				}
								
				//设置选择房间数-1
				intHadSelCount = intHadSelCount -1;
				
			}
			
			//判断当前选择的房间数是否大于预定数
			$("#label1").text("已选房 " + intHadSelCount.toString() + ' 间');
				
		}
		
		
		
		
		//相应提交按钮事件处理部分
		function bmtSendOkClick()
		{
			//得到当前选择的房间信息
			var strrooms='';
			var inttemp=0;
			for(var i=1;i<	(intAllRoomCount+1);i++)
			{
				inttemp = $('#check' + i.toString()).val();
				if(inttemp>0)
				{
					//的到房号				
					strrooms = strrooms + ',' + $('#roomno' + i.toString()).val();
				}		
			}
			
			if(strrooms.length>0)
			{
				strrooms = strrooms.substring(1);
				
				//alert(strrooms);
				//return;
				
				//开始提交PHP页面执行数据库操作流程
				var strurl="fwroomselsave.php?chainno=<?php echo $chainno;?>&fwuser=<?php echo $strSelUserNo;?>&rmno=" + strrooms;
				var strret="";
				//用ajax的“同步方式”调用一般处理程序
				$.ajax({
					url: strurl ,
					async: false,//改为同步方式
					type: "POST",
					//data: {doid:1, rmid: "strRoomNo" },
					success: function (RetData) 
					{
						strret = RetData;
					}
				});
				
				//alert(strret);
				
				if(strret.length>2)
				{
					var strSubHead =strret.substr(0,3);
			
					if(strSubHead=="*1*")
					{
						//得到新的数量值
						strurl="fwmain.php?chainno=<?php echo $chainno;?>&fwuser=<?php echo $strSelUserNo;?>";
						window.location=strurl;
					}
				
				}
				
			}
				
		}
	</script>

</section>

</body>
	
</html>