<?php

//WeLive在线客服系统
//独立窗口进入客服, web和移动端统一入口文件
//如要选择进入某用户组及原网站用户接口请加参数, 如：..../kefu.php?a=6168&g=客服组id&id=原网站用户ID&fn=原网站用户名

//正式开始
$a = 0;
if(isset($_GET['a'])) $a = intval($_GET['a']);

if($a !== 6168) die('Access denied.'); //简单地防止直接访问当前文件

//客服组
$groupid = 0;
if(isset($_GET['g'])) $groupid = intval($_GET['g']);

//原网站ID
$old_id = 0;
if(isset($_GET['id'])) $old_id = intval($_GET['id']);

//原网站用户名
$old_fn = "";
if(isset($_GET['fn'])) $old_fn = trim($_GET['fn']);

?>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript">

//WeLive安装后所在URL, 相对地址或绝对地址, 以 / 结尾
var welive_url = "./";

//防机器人编码
var welive_code = 6168;

//判断是否为移动设备
var welive_mobile = navigator.userAgent.match(/(iPhone|Android|iPod|ios|iPad|Windows ce|Windows mobile|Micromessenger|webOS|Ucweb|UCBrowser|BlackBerry|midp|rv:1.2.3.4)/i);

var groupid = <?php echo $groupid;?>; //客服组
var old_id = <?php echo $old_id;?>; //原网站ID
var old_fn = "<?php echo $old_fn;?>"; //原网站用户名

window.onload=function(){
	//当前页面URL
	var url = window.location.href;

	//来自页面的URL
	var fromurl = '';

	if(typeof(document.referrer) != 'undefined' && document.referrer.length > 0) {
		fromurl = document.referrer;
	}else{
		try {
			if (typeof(opener.location.href) != 'undefined' && opener.location.href.length > 0) {
				fromurl = opener.location.href;
			}
		}catch(e){}
	}

	url = fromurl ?  window.btoa(fromurl) : window.btoa(url);

	//根据设备跳转的链接不同
	if(welive_mobile){ //mobile
		var welive_link = welive_url + "mobile.php" + "?a=" + welive_code;
	}else{ //web
		var welive_link = welive_url + "welive.php" + "?a=" + welive_code;
	}

	if(groupid) welive_link += "&group=" + groupid;
	if(old_id) welive_link += "&id=" + old_id;
	if(old_fn) welive_link += "&fn=" + old_fn;

	welive_link += "&url=" + url;

	window.location.href = welive_link;
}
</script>
</head>
<body>
</body>
</html>