<?php
require '../conn/conn.php';
require '../conn/function.php';
$action=$_GET["action"];

if($action=="statistics"){
	$lid=$_GET["lid"];
	$add=$_GET["add"];
	$browser=$_GET["browser"];
	$mid=getrs("select * from sl_short where S_id=$lid","S_mid");
	if(isMobile()){
		$terminal="手机端";
	}else{
		$terminal="电脑端";
	}
	mysqli_query($conn,"update sl_short set S_times=S_times+1 where S_id=".$lid);
	mysqli_query($conn, "insert into sl_statistics(S_lid,S_ip,S_browser,S_time,S_terminal,S_add,S_mid) values($lid,'".getip()."','".$browser."','".date('Y-m-d H:i:s')."','$terminal','$add',$mid)");
}

$s=array_keys($_GET);
if($s[0]=="admin" || $s[0]=="member"){
    header("location:".$s[0]."/index.php");
}

$s=intval(dec10($s[0]));

if(array_keys($_GET)[0]!=""){
	$sql="select * from sl_short where S_id=".$s." and (TIMESTAMPDIFF(DAY,S_time,DATE_FORMAT(now(),'%Y-%m-%d'))<".$C_day." or S_vip=1)";
	$result = mysqli_query($conn, $sql);
	$row = mysqli_fetch_assoc($result);
	if(mysqli_num_rows($result) > 0) {
		if($row["S_vip"]==0 && $row["S_times"]>100){
		    die("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><div style=\"text-align:center;padding-top:50px\"><p><img src=\"images/warning.png\"></p><p>免费短链仅提供100次点击，请到官网<a href=\"https://".$C_config["C_fdomain"]."\">https://".$C_config["C_fdomain"]."</a>升级后继续使用！</p><p>升级后特权：1.永久使用无时间限制 2.不限点击次数 3.去除所有广告</p></div>");
		}else{
			$url=$row["S_url"];
			$url=urldecode($url);
			$S_vip=$row["S_vip"];
			$S_fit=$row["S_fit"];
			$S_type=$row["S_type"];
			$S_statistics=$row["S_statistics"];
		}
	}else{
	    
	    die("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><div style=\"text-align:center;padding-top:50px\"><p><img src=\"images/warning.png\"></p><p>免费短链接有效期为".$C_day."天，请到官网<a href=\"https://".$C_config["C_fdomain"]."\">https://".$C_config["C_fdomain"]."</a>升级后继续使用！</p><p>升级后特权：1.永久使用无时间限制 2.不限点击次数 3.去除所有广告</p></div>");
	}
}
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <title>跳转</title>
	<script src="../js/jquery.min.js"></script>
	<script src="https://pv.sohu.com/cityjson?ie=utf-8"></script>
	<style type="text/css">
	html{height: 100%}
	body{background: #f7f7f7;height: 100%;margin:0px;}
	.main{width: 100%;max-width: 750px;margin:0px auto;padding: 10px;background: #ffffff;box-shadow: 0 2px 17px 2px #DDDDDD;padding: 30px;position: relative;margin-bottom: 20px;}
	.pop {width: 100%;height: 100%;position: fixed;top: 0;left: 0;background: rgba(0,0,0,.7);z-index: 999;}
	#msg{font-size: 12px;color: #ff0000;}
	.bottom{position:fixed;height:70px;width:100%;left:0px;bottom:0px;background:#fff;text-align:center;z-index: 9999;}
	.ad{width:calc(50% - 1px);height:35px;line-height:35px;display:inline-block;text-align:center;font-size:12px;border-left:solid 1px #DDD;border-top:solid 1px #DDD; white-space: nowrap;text-overflow: ellipsis;word-break: break-all;overflow:hidden;vertical-align: bottom}
	a{color:#000;text-decoration:none}
</style>
<script type="text/javascript">
function IsPC(){  
     var userAgentInfo = navigator.userAgent;
     var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");  
     var flag = true;  
     for (var v = 0; v < Agents.length; v++) {  
         if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; }  
     }  
     return flag;  
  }
function isWeiXin(){
        var ua = window.navigator.userAgent.toLowerCase();
        if (ua.match(/MicroMessenger/i) == 'micromessenger') {
            return true;
        } else {
            return false;
        }
    }
function isQQ(){
	if(!IsPC()){
		if(navigator.userAgent.toLowerCase().toString().indexOf('qqbrowser') > -1 || navigator.userAgent.toLowerCase().toString().indexOf('qqtheme') > -1){
            return true;
        } else {
            return false;
        }
	}else{
		return false;
	}
}
function getExploreName(){
   var userAgent = navigator.userAgent;
   if(userAgent.indexOf("Opera") > -1 || userAgent.indexOf("OPR") > -1){
     return 'Opera';
   }
   else if(userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1){
     return 'IE';
   }
   else if(userAgent.indexOf("Edge") > -1){
      return 'Edge';
   }
   else if(userAgent.indexOf("Firefox") > -1){
      return 'Firefox';
   }
   else if(userAgent.indexOf("Safari") > -1 && userAgent.indexOf("Chrome") == -1){
     return 'Safari';
   }
   else if(userAgent.indexOf("Chrome") > -1 && userAgent.indexOf("Safari") > -1){
      return 'Chrome';
   }
   else if(!!window.ActiveXObject || "ActiveXObject" in window){
      return 'IE>=11';
   }
   else{
    return 'Unkonwn';
   }
}
</script>
</head>
<body>

<?php
echo $S_statistics;
if($S_vip==0){
    $height="calc(100% - 70px)";
	if($S_type>0){
	    echo "<div class=\"bottom\">";
		if(rand(0,1)==0){//文字广告
			$sql="select * from sl_ad where A_type=0 and TIMESTAMPDIFF(MONTH,A_time,DATE_FORMAT(now(),'%Y-%m-%d'))<A_long order by rand() limit 4";
			$result = mysqli_query($conn,  $sql);
			if (mysqli_num_rows($result) > 0) {
			    while($row = mysqli_fetch_assoc($result)) {
	    		    if($row["A_red"]==1){
	    		        $red="color:red;";
	    		    }else{
	    		        $red="";
	    		    }
	    		    if($row["A_bold"]==1){
	    		        $bold="font-weight:bold;";
	    		    }else{
	    		        $bold="";
	    		    }
					echo "<a class=\"ad\" href=\"".$row["A_url"]."\" style=\"".$red.$bold."\">".$row["A_text"]."</a>";
			    }
			}
		}else{//图片广告
		    $sql="select * from sl_ad where A_type=1 and TIMESTAMPDIFF(MONTH,A_time,DATE_FORMAT(now(),'%Y-%m-%d'))<A_long order by rand() limit 1";
			$result = mysqli_query($conn,  $sql);
			if (mysqli_num_rows($result) > 0) {
			    while($row = mysqli_fetch_assoc($result)) {
					echo "<a href=\"".$row["A_url"]."\" style=\"text-align:center;line-height:70px\"><img src=\"../media/".$row["A_pic"]."\" style=\"height:100%;width:100%\"></a>";
			    }
			}
		}
		echo "</div>";
	}
}else{
    $height="100%";
}

switch($S_type){
	case 0:
		echo "<script>
				$.ajax({
				    url: '?action=statistics&lid=".$s."&browser='+getExploreName()+'&add='+returnCitySN['cname'],
				    type: 'get',
				    success: function(data) {
				        window.location.href='".$url."';
				    }
				});
			</script>";
	break;
	case 1:
		echo "<div class=\"pop none\" id=\"divpop\" style=\"display:none;\">
			<img src=\"../images/top.png\" style=\"float: right;margin: 10px;max-width: calc(100% - 20px)\">
			<div style=\"color: #ffffff;text-align: center;margin-top:300px\">
			<h3>即将跳转到网址</h3>
			<p>".$url."</p>
			</div>
			</div>
			<script>
				$.ajax({
				    url: '?action=statistics&lid=".$s."&browser='+getExploreName()+'&add='+returnCitySN['cname'],
				    type: 'get',
				    success: function(data) {
				        if(isWeiXin() || isQQ()){
							$('#divpop').show();
						}else{
							window.location.href='".$url."';
						}
				    }
				});
			</script>";
	break;
	case 2:
		echo "<iframe src=\"".$url."\" style=\"width:100%;height:".$height."\" frameborder=\"0\" id=\"myiframe\"></iframe>
		<script>
			$.ajax({
			    url: '?action=statistics&lid=".$s."&browser='+getExploreName()+'&add='+returnCitySN['cname'],
			    type: 'get',
			    success: function(data) {
			        
			    }
			});
		</script>";
	break;
}
?>
</body>
</html>