<!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_source.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_source.js"></script>
</head>
<body style="overflow: hidden;">
	{% 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" id="dateBox2" style="width: 90%; float: right;">
							<a href="web_statistics_source?{{ 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 ngco-none-display2">
								<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; ">
								<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 " 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 %}
								</select>
							</div>
							<div class="am-u-md-3 am_fl_zi ngre-no-paddingL dateBox2 ngco-Ladd-flaotR ngre-Hxg-width ngre-Oxg-paddingR" id="Timebox">
								<div class="tpl-switch role-select">
									<div class="tpl-switch-btn-view" id="switch">
										<div>
										</div>
									</div>
								</div>
								<input type="text" value="2019-10-31 16:10" 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 " id="dateBox2">
								<div class="tpl-switch role-select">
									<div class="tpl-switch-btn-view" id="switch">
										<div>
										</div>
									</div>
								</div>
								<input type="text" value="2019-10-29 16:12" class="form-datetime-lang am-form-field time-table ngre-add-border ngre-add-radius2 ngre-Achange-form" placeholder="" id="ngre-Ainput" />
							</div>
							{% if type == 0 %}
							<a href="web_statistics_source?type=1" class="am-btn am-btn-secondary ng-add-hightB ngco-Ladd-flaotR"><span class="am-icon-search"></span>&nbsp;来源地址</a>
							{% else %}
							<a href="web_statistics_source" class="am-btn am-btn-secondary ng-add-hightB ngco-Ladd-flaotR"><span class="am-icon-search"></span>&nbsp;来源域名</a>
							{% endif %}
						</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="table-title">{% if type == 0 %}来源域名{% else %}来源地址{% endif %}</th>
											<th class="table-title">来源量</th>
											<th class="table-title">来路比率</th>
										</tr>
									</thead>
									<tbody>
										{% for row in data %}
										<tr id="link">
											{% set url = row['a']|replace('?','%3F') %}
											<td><a href="web_statistics_record?{% if type == 0 %}filter=5&domain{% else %}filter=6&source{% endif %}={{url|replace('&','%26')}}">{% if row['a'] %}{{row['a_cut']}}{% else %}未知来源{% endif %}</a>&nbsp;&nbsp;<a {% if type==1 %} href="{{row['a']}}" {% else %} href="http://{{row['a']}}" {% endif %} target="_blank" class="title2div" title="点击查询该来源信息"><span class="am-icon-chain tooltip"></span></a></td>
											<td><a href="#">{{row['b']}}</a></td>
											<td>{{row['rate']}}%</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>
						<script>
						$(function() {
							kg.title2div('title2div');	 //调用此方法， 把该元素的title属性替换成div
							var type = $("#type");
							var select = $("#filter");
							// 获取访问页面和应用数据
							var web_list = {{ web_list }};
							var page_list = {{ page_list }};
							var source_list = {{ source_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_source?{{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_source?{{url["select"]}}filter=1&webid=' + data[i]['id'] + '">' + data[i]['name'] + '</option>';
									} else {
										html += '<option value="web_statistics_source?{{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_source?{{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_source?{{url["select"]}}filter=2&model=' + data[i]['model'] + '/' + data[i]['page'] + '">' + data[i]['model'] + '/' + data[i]['page'] + '</option>';
									} else {
										html += '<option value="web_statistics_source?{{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_source?{{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_source?{{url["select"]}}filter=6&source=' + url + '">' + data[i]['source_cut'] + '</option>';
									} else {
										html += '<option value="web_statistics_source?{{url["select"]}}filter=6&source=' + url + '">' + data[i]['source_cut'] + '</option>';
									}
								}
								select.html(html);
								select.attr("name", "source");
							}
							// 页面跳转选中
							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);
							}
							// 点击事件
							$('.showslelect li[data-value="0"]').click(function() {
								all(select);
								window.location.href = "web_statistics_source?{{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() {
								console.log('点击');
								source(select, source_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_source?{{url['select']}}filter=3&ip=" + value;
								}
								if (type.prop("value") == 4) {
									window.location.href = "web_statistics_source?{{url['select']}}filter=4&user=" + value;
								}
								if (type.prop("value") == 5) {
									window.location.href = "web_statistics_source?{{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]}}");
							})
							//时间插件提交
							$("#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_source?{{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_source?{{url['start']}}start=" + a_value;
							})
						});
						</script>
</body>
</html>