<!DOCTYPE html>
<% language=javascript %>
<html>
<head lang="en">
    <meta charset="GB2312">
    <title></title>
    <link href="css/style.css" title="style" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="css/jquery-ui.css" />
    <script src="js/jquery-1.6.3.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui-datepicker.js"></script>
    <style>
        i{font-style:normal}
        .kaiguanTD td{text-align: center;}
    </style>

</head>
<body style="background: #F3F3F3">
<div class='type3330 empty' style=' margin: 10px;'>
  <table width="100%">
    <tr>
    <td width="300px" style="text-align: center;"><img src="img/ico-card.png" style="width: 70%;text-align: center;"></td>
    <td>
    <table width='100%'>
        <h1 style='margin:10px 10px 10px 10px;'>门禁系统(OM-CARDT)</h1>
        <tr><td style='width: 200px;'>基本信息</td><td>SID:<span class='SID3330'> </span>&nbsp;&nbsp;&nbsp;编址:<span class='Addr3330'> </span>&nbsp;&nbsp;&nbsp;数据端口:<span class='Port3330'> </span></td></tr>
        <tr><td style='width: 200px;'>更新时间</td><td><span class='DateUpd3330'> </span></td></tr>
        <tr><td style='width: 200px;'>监测项状态</td><td><span class='State3330'> </span></td></tr>
    </table>
    <div style="margin: 10px;margin-top: 15px; width:100%">
        <span>选择查询日期:&nbsp;</span> <span>开始 <input type="text" id="date_1" value="" /></span>
        <span>结束 <input type="text" id="date_2" value="" /></span>
        <span><input type="button" class="dateBtn" value="实时查询">&nbsp;<input type="button" class="dateBtn1" value="历史查询"></span>
    </div>
    </td>
    </tr>
  </table>
    <span class="lond hide" style="text-align: center;margin-left: 200px;" ><img  src="img/loding.gif" ><span>正在查询数据库....</span></span>
    <div id="container2" style="width:100%;"></div>
	
    <a href='javascript:history.back()' class='back' style='color: #fff'>返回</a>
    </div>
<script>
var itype=3330;
var tescape= 5000,time;

<% db_Open("/NandFlash/tmp/dbDat0.db3"); %>
var sid=<% write(sid);%>;
var json= <% db_QryAdv("select * from tbCardLog where SID="+sid,0); %>;
<% db_Close(); %>
	
$(function(){
	qrychk();
    time=setInterval(ajax,tescape)
});
function ajax(){
    $.ajax({
        type: "POST",
        url: "omdev/smdat0.asp",
        data: "itype="+itype+"&sid="+sid,
        dataType:"json",
        success: function(msg){
            list3(msg)
        }
    });
}
list3(json);
function list3(data){
    $.each(data.recs,function(i,n){
        $(".SID3330").html(n.SID);
        $(".Addr3330").html(n.Addr);
        $(".Port3330").html(n.Port%256);
        $(".DateUpd3330").html(n.DateUpd);
        if(n.State==0){n.State="正常"}
        else if(n.State==1){n.State="告警"}
        else  if(n.State<0||n.State>1){n.State="故障"}
        $(".State3330").html(n.State);
    });
    $("span:contains('故障'),span:contains('告警'),span:contains('闭合'),span:contains('关闭')").addClass("red").removeClass("ger");
    $("span:contains('正常')").addClass("ger").removeClass("red");
}
	
function qrychk(){
	jQuery.support.cors =true;
	$("#date_1").datepicker();
	$("#date_2").datepicker();
	
	$(".dateBtn").click(function()
	{
		index=1;
		datatime=[];
		var sDate=$("#date_1").val();
		var eDate=$("#date_2").val();
		var sArr = sDate.split("-");
		var eArr = eDate.split("-");
		var sRDate = new Date(sArr[0], sArr[1], sArr[2]);
		var eRDate = new Date(eArr[0], eArr[1], eArr[2]);
		var result = (eRDate-sRDate)/(24*60*60*1000);
		if(result>30){
			alert("最多只能查询30天以内的数据！");
			return false
		}
		if(sDate==""||eDate==""||sDate>eDate){
			alert("请输入正确的查询时间！");
			return false
		}
		$.ajax({
			type: "POST",
			url: "omdev/cardlog-t.asp",
			data: "starttime="+sDate+"&endtime="+eDate+"",
			dataType: "json",
			beforeSend: function() {
				$(".dateBtn").attr('disabled', 'disabled');
				$(".lond").show();
			},
			complete: function() {
				$(".lond").hide();
				$(".dateBtn").removeAttr("disabled");
			},
			success: function(msg){
				qryCardLog(msg)
			}
		});
	});
	
	$(".dateBtn1").click(function()
	{
		index=1;
		datatime=[];
		var sDate=$("#date_1").val();
		var eDate=$("#date_2").val();
		var sArr = sDate.split("-");
		var eArr = eDate.split("-");
		var sRDate = new Date(sArr[0], sArr[1], sArr[2]);
		var eRDate = new Date(eArr[0], eArr[1], eArr[2]);
		var result = (eRDate-sRDate)/(24*60*60*1000);
		if(result>30){
			alert("最多只能查询30天以内的数据！");
			return false
		}
		if(sDate==""||eDate==""||sDate>eDate){
			alert("请输入正确的查询时间！");
			return false
		}
		$.ajax({
			type: "POST",
			url: "omdev/cardlog.asp",
			data: "starttime="+sDate+"&endtime="+eDate+"",
			dataType: "json",
			beforeSend: function() {
				$(".dateBtn1").attr('disabled', 'disabled');
				$(".lond").show();
			},
			complete: function() {
				$(".lond").hide();
				$(".dateBtn1").removeAttr("disabled");
			},
			success: function(msg){
				qryCardLog(msg)
			}
		});
	});
}

function qryCardLog(msg)
{
				var data=msg;
				var q='';
				$.each(data.recs,function(i,n){
					if(i==0){
						q+="<div style='overflow: auto;height: 500px;'>";
						q+="<table width='100%' style='border: #B0B7BF 1px solid'>";
						//q+="<tr><td style='width: 200px;'>更新时间</td><td style='width: 200px;'>刷卡时间</td><td style='width: 150px'>记录号</td><td style='width: 150px'>卡号</td></td><td style='width: 150px'>门号</td><td style='width: 100px'>状态</td><td style='width: 150px'>截图</td></tr>";
						q+="<tr><td style='width: 200px;'>刷卡时间</td><td style='width: 150px'>记录号</td><td style='width: 150px'>卡号</td><td style='width: 150px'>通道号</td><td style='width: 150px'>权限</td><td style='width: 100px'>开门方式</td><td style='width: 150px'>截图</td></tr>";
					}
					var doorSt = '';
					var btnSt = '';
					var recSt = '';
					//通道号
					n.Door = parseInt(n.Door);
					doorSt = "通道"+(n.Door>>4);
					//权限
					if (n.Door & 0x01)
						btnSt = "通过";
					else
						btnSt = "未通过";
					//开门方式 
					n.St = parseInt(n.St);
					if (n.St == 0x00)
						recSt = "密码开门";
					else if (n.St == 0x01)
						recSt = "卡开门";
					else if (n.St == 0x02)
						recSt = "卡+密码";
					else if (n.St == 0x03)
						recSt = "密码+卡";
					else if (n.St == 0x04)
						recSt = "远程开门";
					else if (n.St == 0x05)
						recSt = "开门按钮开";
					else if (n.St == 0x06)
						recSt = "指纹开门";
					else if (n.St == 0x09)
						recSt = "卡+指纹";
					else
						recSt = "";
					//recSt += "(" + n.St + ")";
					
					//q+="<tr><td>"+n.DateUpd+"</td><td>"+n.LogDate+"</td><td>"+n.Rec+"</td><td>"+n.Card+"</td><td>"+n.Door+"</td><td>"+n.St+"</td><td>"+n.LogImg+"</td></tr>";
					q+="<tr><td>"+n.LogDate+"</td><td>"+n.Rec+"</td><td>"+n.Card+"</td><td>"+doorSt+"</td><td>"+btnSt+"</td><td>"+recSt+"</td><td>"+n.LogImg+"</td></tr>";
				});
				$("#container2").html(q);
}
</script>
</body>
</html>