<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>KGCMS企业应用管理平台 - Powered by KGCMS</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="renderer" content="webkit">
<!-- <meta http-equiv="cache-control" content="no-siteapp" /> -->
<link rel="stylesheet" href="{{kg['tpl_url']}}style/web_statistics_record.css">
<script src="{{kg['tpl_url']}}script/jquery.min.js"></script>
<script src="{{kg['server']['HTTP_HOST']}}/tools/amazeui/js/amazeui.min.js"></script>
<script src="{{kg['tpl_url']}}script/amazeui.datetimepicker.min.js"></script>
<script src="{{ kg['tpl_url'] }}script/common.js"></script>
<script src="{{ kg['tpl_url'] }}script/web_statistics_record.js"></script>
</head>
<body>
	{% include 'component_header.tpl' %}
	<div class="tpl-page-container tpl-page-header-fixed">
		<div class="scrollbar-wrap">
		{% include 'component_left.tpl' %}
		<div class="tpl-content-wrapper">
			<div class="tpl-content-page-title">
				实时统计
			</div>
			<ol class="am-breadcrumb">
				<li><a href="./" class="am-icon-home">首页</a></li>
				<li class="am-active">实时统计</li>
			</ol>
			<div class="tpl-portlet-components ngALL-AFenyeFu-marginT">
				<div class="portlet-title ngco-Hsz-marginB">
					<div class="portlet-title">
						<div class="caption font-green bold">
							<span class="am-icon-code"></span>&nbsp;实时统计
						</div>
						<div class="am-btn-group am-btn-group-xs ngre-Pblur-box dateBoxw" id="dateBox2" style="width: 90%; float: right;">
							<a href="web_statistics_record?{{ kg['run_start_time'][1] }}" class="am-btn am-btn-secondary ng-add-hightB ngco-Ladd-flaotR"><span class="am-icon-search"></span>&nbsp;刷新</a>
							<div id="display1" class="ng-rehide-box ngre-Aadd-marginR ngco-Ladd-flaotR" style="display:none;">
								<div class="portlet-input input-small input-inline am-fl">
									<div class="input-icon right">
										<i class="am-icon-search log-search" id="search"></i>
										<input type="hidden" id="data_type" value name="filter" />
										<input type="text" class="form-control form-control-solid ngre-add-radius2 ngar-Vxiugai-radius am-hover" placeholder="搜索..." name="word" value="" id="word">
									</div>
								</div>
							</div>
							<div id="display" class="am-form-group am-fl am-select-hover am-long ng-add-borderl ng-rehover-box ngre-add-radius ngre-sstyle-box ngco-Ladd-flaotR " style="margin-right:10px;display: none; ">
								<select onchange="window.open(this.options[this.selectedIndex].value,'_self')" id="filter" data-am-selected="{searchBox: 1}">
									<option value="0">所有类型</option>
								</select>
							</div>
							<div class="am-form-group am-fl am-select-hover  showslelect ngre-add-radius am-no-marginbtm ngco-Ladd-flaotR ngco-none-display2 ngwe-show" style="margin-right:10px;">
								<select id="type" name="filter" data-am-selected="{sbtnSize: 'sm'}">
									{% if filter == 0 %}
									<option selected="selected" value="0">所有数据</option>
									{% else %}
									<option value="0">所有数据</option>
									{% endif %}
									{% if filter == 1 %}
									<option selected="selected" value="1">应用</option>
									{% else %}
									<option value="1">应用</option>
									{% endif %}
									{% if filter == 2 %}
									<option selected="selected" value="2">访问页面</option>
									{% else %}
									<option value="2">访问页面</option>
									{% endif %}
									{% if filter == 3 %}
									<option selected="selected" value="3">IP地址</option>
									{% else %}
									<option value="3">IP地址</option>
									{% endif %}
									{% if filter == 4 %}
									<option selected="selected" value="4">用户</option>
									{% else %}
									<option value="4">用户</option>
									{% endif %}
									{% if filter == 5 %}
									<option selected="selected" value="5">来源域名</option>
									{% else %}
									<option value="5">域名</option>
									{% endif %}
									{% if filter == 6 %}
									<option selected="selected" value="6">来源地址</option>
									{% else %}
									<option value="6">来源地址</option>
									{% endif %}
									{% if filter == 7 %}
									<option selected="selected" value="7">访问地址</option>
									{% else %}
									<option value="7">访问地址</option>
									{% endif %}
								</select>
							</div>
							<div class="am-u-md-3 am_fl_zi ngre-no-paddingL ngco-Ladd-flaotR ngre-Hxg-width ngre-Oxg-paddingR ngwe-shti ngco-none-display2" id="Timebox">
								<div class="tpl-switch role-select">
									<div class="tpl-switch-btn-view">
										<div>
										</div>
									</div>
								</div>
								<input type="text" value="{{end}}" class="form-datetime-lang am-form-field time-table ngre-add-border  ngre-add-radius2" id="ngre-Binput" placeholder="" />
							</div>
							<div class="am-u-md-3 am_fl_zi ngre-namend-padding dateBox ngco-Ladd-flaotR ngre-Hxg-width ngwe-shti2 ngco-none-display2 dateBoxw" id="dateBox2w">
								<div class="tpl-switch role-select">
									<div class="tpl-switch-btn-view">
										<div>
										</div>
									</div>
								</div>
								<input type="text" value="{{start}}" class="form-datetime-lang am-form-field time-table ngre-add-border ngre-add-radius2 ngre-Achange-form" placeholder="" id="ngre-Ainput" />
							</div>
						</div>
					</div>
					<div class="am-g">
						<div class="am-u-sm-12 ngco-No-paddingR">
							<form class="am-form">
								<table class="am-table am-table-striped am-table-hover table-main ngco-Esz-mgibdr">
									<thead>
										<tr>
											<th class="id">ID</th>
											<th class="table-title">访问时间</th>
											<th class="table-title">应用</th>
											<th class="table-title">身份识别码</th>
											<th class="table-title">访问页面</th>
											<th class="table-title">来源</th>
											<th class="table-title">地理位置</th>
											<th class="table-title">详情</th>
										</tr>
									</thead>
									{% if not data %}<div class="no-data"><ul>没有相关数据</ul></div>{% endif %}
									<tbody>
										{% for row in data %}
										<tr>
											<td>{{row['id']}}</td>
											<td>{{row['addtime']}}</td>
											<td><a href="web_statistics_record?{{url['web']}}filter=1&webid={{row['webid']}}" class="title2div" title="点击筛选该应用数据">{{row['web_name']}}</a>&nbsp;<a href="app_manage" target="_blank" class="title2div" title="点击设置该应用"><span class="am-icon-desktop"></span></a></td>
											{% if row['admin'] %}
											<td><a href="web_statistics_record?{{url['user']}}filter=4&user={{row['aid']}}" class="title2div" title="点击筛选该用户数据">{{row['ident']}}</a>&nbsp;<a href="web_statistics_record?{{url['user']}}filter=4&user={{row['admin']}}" class="title2div" title="点击筛选该用户数据"><span class="am-icon-user"></span></a></td>
											{% else %}
											<td><a href="web_statistics_record?{{url['user']}}filter=4&user={{row['aid']}}" class="title2div" title="点击筛选该用户数据">{{row['ident']}}</a></td>
											{% endif %}
											{% if row['page'] %}
											<td><a href="web_statistics_record?{{url['page']}}filter=2&model={{row['model']}}/{{row['page']}}" class="title2div" title="点击筛选该页面访问数据">{{row['model']}}/{{row['page']}}</a>&nbsp;<a href="{{row['url']}}" target="_blank" class="title2div" title="点击查看该页面"><span class="am-icon-chain"></span></a></td>
											{% else %}
											<td><a href="web_statistics_record?{{url['page']}}filter=2&model={{row['model']}}/index" class="title2div" title="点击筛选该来源数据">{{row['model']}}/index</a></a>&nbsp;<a href="./{{row['model']}}" target="_blank" class="title2div" title="点击打开该来源页面"><span class="am-icon-chain"></span></a></td>
											{% endif %}
											{% if row['domain'] %}
											<td><a href="web_statistics_record?{{url['source']}}filter=5&domain={{row['domain']}}" class="title2div" title="点击筛选该来源数据">{{row['domain']}}</a>&nbsp;<a href="{{row['source']}}" target="_blank" class="title2div" title="点击打开该来源页面"><span class="am-icon-refresh"></span></a></td>
											{% else %}
											<td><a href="#">直接访问</a></td>
											{% endif %}
											<td><a href="web_statistics_record?{{url['ip']}}filter=3&ip={{row['ip']}}" class="title2div" title="点击筛选该IP数据 ">
													{% if row['country'] in ['', '-'] and row['province'] in ['', '-'] and row['city'] in ['', '-'] and row['ips'] in ['', '-'] %}
													{{row['ip']}}
													{% else %}
													{{ row['country'] + row['province'] + row['city'] + row['ips']|replace('-', '') }}
													{% endif %}
												</a>&nbsp;<a href="{{ip_find}}{{row['ip']}}" target="_blank"><span class="am-icon-paperclip title2div" title="点击查询该IP详细信息"></span></a>
											</td>
											<td>
												<div class="am-btn-toolbar">
													<div class="am-btn-group am-btn-group-xs">
														<a data-value="{{row['id']}}" data-am-modal="{target: '#am-btn-details'}" class="title2div am-btn am-btn-default am-btn-xs am-text-default am-hide-sm-only gg" title="查询该访问详情">
															<span class="am-icon-pencil-square-o" ></span>&nbsp;详情
														</a>
														<a href="web_statistics_record?action=del&id={{row['id']}}" class="am-btn am-btn-default am-btn-xs am-text-danger ngro-Jclick-shanchubi title2div" title="删除该访问信息">
															<span class="am-icon-trash-o"></span>&nbsp;删除
														</a>
													</div>
												</div>
											</td>
										</tr>
										{% endfor %}
									</tbody>
								</table>
								{% if not data %}<div class="no-data"><ul>没有相关数据</ul></div>{% endif %}
							</form>
						</div>
					</div>
				</div>
				{% if page_data['total_page'] > 1 %}
				{{branch}}
				{% endif %}
			</div>
			{% include 'component_footer.tpl' %}
		</div>
		</div><!-- /.scrollbar-wrap -->
		<div class="am-popup am-modal-active" id="am-btn-details" style="display: none;">
			<div class="am-popup-inner">
				<div class="am-popup-hd">
					<h4 class="am-popup-title">日志详情</h4><span data-am-modal-close="" class="am-close">×</span>
				</div>
				<div class="am-popup-bd">
					<p class="de-id"></p>
					<p class="de-web"></p>
					<p class="de-aid"></p>
					<p class="de-user"></p>
					<p class="de-adminid"></p>
					<p class="de-model"></p>
					<p class="de-page"></p>
					<p class="de-url"></p>
					<p class="de-source"></p>
					<p class="de-domain"></p>
					<p class="de-ip"></p>
					<p class="de-address"></p>
					<p class="de-address1"></p>
					<p class="de-os"></p>
					<p class="de-browser"></p>
					<p class="de-addtime"></p>
					<p>
					</p>
					<p>
				</div>
			</div>
		</div>
	</div>
						<script>
                           kg.title2div('title2div');	//调用此方法， 把该元素的title属性替换成div
						$(function() {
							var type = $("#type");
							var select = $("#filter");
							// 获取访问页面和应用数据
							var web_list = {{ web_list }};
							var page_list = {{ page_list }};
							var source_list = {{ source_list }};
							var url_list = {{ url_list }};
							var word = {{ word }};
							var page = '{{page}}';
							var webid = {{ webid }};
							// 下拉选中所有
							function all(select) {
								$('#display').css('display', 'none');
								$('#display1').css('display', 'none');
							}
							// 下拉选中应用
							function web(select, data) {
								$('#display').css('display', '');
								$('#display1').css('display', 'none');
								var html = '<option value="web_statistics_record?{{url["select"]}}filter=1&webid=0">所有应用</option>';;
								for (var i = 0; i < data.length; i++) {
									if (webid == data[i]['id']) {
										html += '<option selected="selected" value="web_statistics_record?{{url["select"]}}filter=1&webid=' + data[i]['id'] + '">' + data[i]['name'] + '</option>';
									} else {
										html += '<option value="web_statistics_record?{{url["select"]}}filter=1&webid=' + data[i]['id'] + '">' + data[i]['name'] + '</option>';
									}
								}
								select.html(html);
								select.attr("name", "web");
							}
							// 下拉选中访问页面
							function access(select, data) {
								$('#display').css('display', '');
								$('#display1').css('display', 'none');
								var html = '<option value="web_statistics_record?{{url["select"]}}filter=2">所有页面</option>';
								for (var i = 0; i < data.length; i++) {
									if (data[i]['page'].length == 0) {
										data[i]['page'] = 'index';
									}
									if (page == data[i]['model'] + '/' + data[i]['page']) {
										html += '<option selected="selected" value="web_statistics_record?{{url["select"]}}filter=2&model=' + data[i]['model'] + '/' + data[i]['page'] + '">' + data[i]['model'] + '/' + data[i]['page'] + '</option>';
									} else {
										html += '<option value="web_statistics_record?{{url["select"]}}filter=2&model=' + data[i]['model'] + '/' + data[i]['page'] + '">' + data[i]['model'] + '/' + data[i]['page'] + '</option>';
									}
								}
								select.html(html);
								select.attr("name", "access_page");
							}
							// 下拉选中来源网址
							function source(select, data) {
								$('#display').css('display', '');
								$('#display1').css('display', 'none');
								var html = '<option value="web_statistics_record?{{url["select"]}}filter=6">所有地址</option>';
								for (var i = 0; i < data.length; i++) {
									if (data[i]['source_cut'] == '') {
										data[i]['source_cut'] = '未知地址'
									}
									url = data[i]['source'].replace(/\?/gm, '%3F');
									url = url.replace(/&/gm, '%26');
									if (data[i]['source_cut'] == '{{source}}') {
										html += '<option selected="selected" value="web_statistics_record?{{url["select"]}}filter=6&source=' + url + '">' + data[i]['source_cut'] + '</option>';
									} else {
										html += '<option value="web_statistics_record?{{url["select"]}}filter=6&source=' + url + '">' + data[i]['source_cut'] + '</option>';
									}
								}
								select.html(html);
								select.attr("name", "source");
							}
							// 下拉选中访问地址
							function access_url(select, data) {
								$('#display').css('display', '');
								$('#display1').css('display', 'none');
								var html = '<option value="web_statistics_record?{{url["select"]}}filter=7">所有地址</option>';
								for (var i = 0; i < data.length; i++) {
									url = data[i]['url'].replace(/\?/gm, '%3F');
									url = url.replace(/&/gm, '%26');
									if (data[i]['url_cut'] == '{{access_url}}') {
										html += '<option selected="selected" value="web_statistics_record?{{url["select"]}}filter=7&url=' + url + '">' + data[i]['url_cut'] + '</option>';
									} else {
										html += '<option value="web_statistics_record?{{url["select"]}}filter=7&url=' + url + '">' + data[i]['url_cut'] + '</option>';
									}
								}
								select.html(html);
								select.attr("name", "url");
							}
							// 页面跳转选中
							if (type.prop("value") == 0) {
								all(select);
							}
							if (type.prop("value") == 1) {
								web(select, web_list);
							}
							if (type.prop("value") == 2) {
								access(select, page_list);
							}
							if (type.prop("value") == 6) {
								source(select, source_list);
							}
							if (type.prop("value") == 7) {
								access_url(select, url_list);
							}
							// 点击事件
							$('.showslelect li[data-value="0"]').click(function() {
								all(select);
								window.location.href = "web_statistics_record?{{url['select']}}filter=0";
							})
							$('.showslelect li[data-value="1"]').click(function() {
								web(select, web_list);
							})
							$('.showslelect li[data-value="2"]').click(function() {
								access(select, page_list);
							})
							$('.showslelect li[data-value="6"]').click(function() {
								source(select, source_list);
							})
							$('.showslelect li[data-value="7"]').click(function() {
								access_url(select, url_list);
							})
							function deal(name, type, value) {
								$('.ng-rehide-box').show().siblings('.ng-rehover-box').hide();
								$("#word").attr("name", name);
								$("#word").attr("value", value);
								$("#data_type").attr("value", type);
								$('#display').css('display', 'none');
							}
							$("#search").click(function() {
								var type = $("#type");
								var value = $("#word").val();
								if (type.prop("value") == 3) {
									window.location.href = "web_statistics_record?{{url['select']}}filter=3&ip=" + value;
								}
								if (type.prop("value") == 4) {
									window.location.href = "web_statistics_record?{{url['select']}}filter=4&user=" + value;
								}
								if (type.prop("value") == 5) {
									window.location.href = "web_statistics_record?{{url['select']}}filter=5&domain=" + value;
								}
							})
							var type = $("#type");
							if (type.prop("value") == 3) {
								deal('ip', "3", "{{word[0]}}");
							}
							if (type.prop("value") == 4) {
								deal('user', "4", "{{word[1]}}");
							}
							if (type.prop("value") == 5) {
								deal('domain', "5", "{{word[2]}}");
							}
							//点击隐藏<应用下拉框>并显示<搜索+刷新>
							$('.showslelect li[data-value="3"]').click(function() {
								deal('ip', "3", "{{word[0]}}");
							})
							$('.showslelect li[data-value="4"]').click(function() {
								deal('user', "4", "{{word[1]}}");
							})
							$('.showslelect li[data-value="5"]').click(function() {
								deal('domain', "5", "{{word[2]}}");
							})
							// 删除按钮
							$('#delete').click(function() {
								$('.am-modal-bd').html("你确定要删除当前的{{page_data['total_rows']}}条记录吗 ?")
							})
							//时间插件提交
							$("#ngre-Binput").change(function() {
								var b_value = $("#ngre-Binput").val();
								b_value = b_value.replace(/-/gm, '');
								b_value = b_value.replace(/:/gm, '');
								b_value = b_value.replace(/ /gm, '');
								console.log(b_value);
								window.location.href = "web_statistics_record?{{url['end']}}end=" + b_value;
							})
							$("#ngre-Ainput").change(function() {
								var a_value = $("#ngre-Ainput").val();
								a_value = a_value.replace(/-/gm, '');
								a_value = a_value.replace(/:/gm, '');
								a_value = a_value.replace(/ /gm, '');
								console.log(a_value);
								window.location.href = "web_statistics_record?{{url['start']}}start=" + a_value;
							})
							// 详情按钮弹窗
							$('.gg').click(function() {
								var a = $(this).data().value;
								console.log(a)
								var b = {{ data }}
								for (var i = 0; i < b.length; i++) {
									if (b[i]['id'] == a) {
										$('.de-id').html('ID: ' + b[i]['id']);
										$('.de-web').html('应用ID: ' + b[i]['webid']);
										$('.de-aid').html('身份标识码: ' + b[i]['aid']);
										$('.de-user').html('前台用户ID: ' + b[i]['userid']);
										$('.de-user').html('后台用户ID: ' + b[i]['adminid']);
										$('.de-model').html('访问模块: ' + b[i]['model']);
										$('.de-page').html('访问页面: ' + b[i]['page']);
										$('.de-url').html('url: ' + b[i]['url']);
										$('.de-source').html('来源网址: ' + b[i]['source']);
										$('.de-domain').html('域名: ' + b[i]['domain']);
										$('.de-ip').html('访客IP地址: ' + b[i]['ip']);
										$('.de-address').html('IP地址: ' + b[i]['address']);
										address = (b[i]['country'] + b[i]['province'] + b[i]['city'] + b[i]['ips']).replace(/-/gm, '');
										if (address == "") {
											address = "未知"
										}
										$('.de-address1').html('地理位置: ' + address);
										$('.de-os').html('操作系统: ' + b[i]['os']);
										$('.de-browser').html('浏览器信息: ' + b[i]['browser']);
										$('.de-addtime').html('访问时间: ' + b[i]['addtime']);
									};
								};
							});
						})
						</script>
</body>
</html>