<!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='type3336 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%'>
        <tr><td style='border: none'> <h1 class='smName'></h1></td></tr>
        <tr><td style='width: 200px;'>基本信息</td><td>SID:<span class='SID3336'> </span>&nbsp;&nbsp;&nbsp;编址:<span class='Addr3336'> </span>&nbsp;&nbsp;&nbsp;数据端口:<span class='Port3336'> </span></td></tr>
        <tr><td style='width: 200px;'>更新时间</td><td><span class='DateUpd3336'> </span></td></tr>
        <tr><td style='width: 200px;'>监测项状态</td><td><span class='State3336'> </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=3338;
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); %>;
var jname = <% db_QryAdv("select Name from tbSM where SID="+sid,0); %>
<% db_Close(); %>
	
$(".smName").html(jname.recs[0].Name);

<% db_Open("/NandFlash/dbCfg.db3"); %>
var jname=<% db_QryAdv("select Card,Name from tbCardDef",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){
        $(".SID3336").html(n.SID);
        $(".Addr3336").html(n.Addr);
        $(".Port3336").html(n.Port%256);
        $(".DateUpd3336").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="故障"}
        $(".State3336").html(n.State);
    });
    $("span:contains('故障'),span:contains('告警'),span:contains('闭合'),span:contains('关闭')").addClass("red").removeClass("ger");
    $("span:contains('正常')").addClass("ger").removeClass("red");
}

function CardName(cid)
{
  var sname="--";
  for(var i in jname.recs) {
    if (jname.recs[i].Card==cid) {
      sname=jname.recs[i].Name; break;
    }
  }
  return sname;
}

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='';
	q+="<div style='overflow: auto;height: 500px;'>";
	q+="<table width='100%' style='border: #B0B7BF 1px solid'>";
	q+="<tr><td style='width: 50px;'>序号</td><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: 100px'>线路状态</td><td style='width: 150px'>截图</td></tr>";
	$.each(data.recs,function(i,n){
		if(i==0){
		}
		var cname = CardName(n.Card);
		var doorSt = '';
		var recSt = '';
		//记录备注: D[15:8], 线路状态: D[7:0]
		var uMask = (n.Rec >> 8) & 0xff;
		var uLineSt = (n.Rec) & 0xff;
		var szLineSt = "";
		if (uLineSt & 0x80)
			szLineSt += "防拆开关：关闭, "
		else
			szLineSt += "防拆开关：拆开, "
		if (uLineSt & 0x40)
			szLineSt += "报警状态：无报警, "
		else
			szLineSt += "报警状态：有报警, "
		if (uLineSt & 0x20)
			szLineSt += "指纹输入：是, "
		else
			szLineSt += "指纹输入：否, "
		if (uLineSt & 0x10)
			szLineSt += "密码输入：是, "
		else
			szLineSt += "密码输入：否, "
		if (uLineSt & 0x08)
			szLineSt += "门状态：开启, "
		else
			szLineSt += "门状态：关闭, "
		if (uLineSt & 0x04)
			szLineSt += "红外状态：告警, "
		else
			szLineSt += "红外状态：正常, "
		if (uLineSt & 0x02)
			szLineSt += "按钮状态：按下, "
		else
			szLineSt += "按钮状态：松开, "
		if (uLineSt & 0x01)
			szLineSt += "紧急输入状态：有效"
		else
			szLineSt += "紧急输入状态：无效"
		//门磁状态
		doorSt = "门" + n.Door;
		//记录状态
		//REMARK=0 刷卡开门记录, REMARK=1 键入用户ID及个人密码开门的记录, 
		if (uMask==0)//刷卡开门记录
		{
			uMask = "刷卡开门";
			if (n.St & 0x80)
				recSt += "刷卡开门未确认, "
			else
				recSt += "刷卡开门已确认, "
			if (n.St & 0x40)
				recSt += "原来门处于关门状态, "
			else
				recSt += "原来门处于开门状态, "
			if (n.St & 0x20)
				recSt += "规定延时内未开门进入, "
			else
				recSt += "规定延时内开门进入, "
			if (n.St & 0x10)
				recSt += "进入后未关好门, "
			else
				recSt += "进入后又关好门, "
			if (n.St & 0x08)
				recSt += "进入后未关闭红外, "
			else
				recSt += "进入后关闭了红外, "
			if (n.St & 0x04)
				recSt += "正常刷卡, "
			else
				recSt += "正常刷卡, "
			if (n.St & 0x02)
				recSt += "进入刷卡（第2头）, "
			else
				recSt += "进入刷卡（第1头）, "
			if (n.St & 0x01)
				recSt += "刷卡时入侵监视开启"
			else
				recSt += "刷卡时入侵监视关闭"
		}
		else if (uMask==1)//键入用户ID及个人密码开门的记录
		{
			uMask = "用户ID及个人密码开门";
			if (n.St & 0x80)
				recSt += "刷卡开门未确认, "
			else
				recSt += "刷卡开门已确认, "
			if (n.St & 0x40)
				recSt += "原来门处于关门状态, "
			else
				recSt += "原来门处于开门状态, "
			if (n.St & 0x20)
				recSt += "规定延时内未开门进入, "
			else
				recSt += "规定延时内开门进入, "
			if (n.St & 0x10)
				recSt += "进入后未关好门, "
			else
				recSt += "进入后又关好门, "
			if (n.St & 0x08)
				recSt += "进入后未关闭红外, "
			else
				recSt += "进入后关闭了红外, "
			if (n.St & 0x04)
				recSt += "正常刷卡, "
			else
				recSt += "正常刷卡, "
			if (n.St & 0x02)
				recSt += "进入刷卡（第2头）, "
			else
				recSt += "进入刷卡（第1头）, "
			if (n.St & 0x01)
				recSt += "刷卡时入侵监视开启"
			else
				recSt += "刷卡时入侵监视关闭"
		}
		else if (uMask==2)//远程(由SU)开门记录
		{
			uMask = "远程开门";
			if (n.St & 0x80)
				recSt += ""
			else
				recSt += ""
			if (n.St & 0x40)
				recSt += "原来门处于关门状态, "
			else
				recSt += "原来门处于开门状态, "
			if (n.St & 0x20)
				recSt += "规定延时内未开门进入, "
			else
				recSt += "规定延时内开门进入, "
			if (n.St & 0x10)
				recSt += "进入后未关好门, "
			else
				recSt += "进入后又关好门, "
			if (n.St & 0x08)
				recSt += "进入后未关闭红外, "
			else
				recSt += "进入后关闭了红外, "
			if (n.St & 0x04)
				recSt += "正常刷卡, "
			else
				recSt += "正常刷卡, "
			if (n.St & 0x02)
				recSt += ""
			else
				recSt += ""
			if (n.St & 0x01)
				recSt += "刷卡时入侵监视开启"
			else
				recSt += "刷卡时入侵监视关闭"
		}
		else if (uMask==3)//手动出门记录
		{
			uMask = "手动开门";
			if (n.St & 0x80)
				recSt += ""
			else
				recSt += ""
			if (n.St & 0x40)
				recSt += "原来门处于关门状态, "
			else
				recSt += "原来门处于开门状态, "
			if (n.St & 0x20)
				recSt += "规定延时内未开门进入, "
			else
				recSt += "规定延时内开门进入, "
			if (n.St & 0x10)
				recSt += "进入后未关好门, "
			else
				recSt += "进入后又关好门, "
			if (n.St & 0x08)
				recSt += ""
			else
				recSt += ""
			if (n.St & 0x04)
				recSt += ""
			else
				recSt += ""
			if (n.St & 0x02)
				recSt += ""
			else
				recSt += ""
			if (n.St & 0x01)
				recSt += ""
			else
				recSt += ""
		}
		else if (uMask==0x70)//超权限卡刷卡开门记录
		{
			uMask = "超权限卡刷卡";
			if (n.St & 0x80)
				recSt += "刷卡开门未确认, "
			else
				recSt += "刷卡开门已确认, "
			if (n.St & 0x40)
				recSt += "原来门处于关门状态, "
			else
				recSt += "原来门处于开门状态, "
			if (n.St & 0x20)
				recSt += "规定延时内未开门进入, "
			else
				recSt += "规定延时内开门进入, "
			if (n.St & 0x10)
				recSt += "进入后未关好门, "
			else
				recSt += "进入后又关好门, "
			if (n.St & 0x08)
				recSt += "进入后未关闭红外, "
			else
				recSt += "进入后关闭了红外, "
			if (n.St & 0x04)
				recSt += "正常刷卡, "
			else
				recSt += "正常刷卡, "
			if (n.St & 0x02)
				recSt += "进入刷卡（第2头）, "
			else
				recSt += "进入刷卡（第1头）, "
			if (n.St & 0x01)
				recSt += "刷卡时入侵监视开启"
			else
				recSt += "刷卡时入侵监视关闭"
		}
		//else if (uMask==5)//事件(报警、或报警取消、线路状态、工作状态变化等) 记录
		//{
		//}
		//else if (uMask==6)//SM掉电再上电记录
		//{
		//}
		//else if (uMask==7)//内部控制参数被修改的记录
		//{
		//}
		//else if (uMask==8)//无效的用户卡刷卡记录
		//{
		//}
		//else if (uMask==9)//用户卡的有效期已过
		//{
		//}
		else //if (uMask==1)//键入用户ID及个人密码开门的记录
		{
			uMask = "其他(" + uMask + ")";
			recSt += "其他"
		}
		recSt += "(" + n.St + ")";
		
		q+="<tr><td>"+(i+1)+"</td><td>"+n.LogDate+"</td><td>"+n.Card+"</td><td>"+uMask+"</td><td>"+cname+"</td><td>"+doorSt+"</td><td>"+recSt+"</td><td>"+szLineSt+"</td><td>"+n.LogImg+"</td></tr>";
	});
	$("#container2").html(q);
}
</script>
</body>
</html>