<?php
require '../conn/conn.php';
require '../conn/function.php';

$s=array_keys($_GET);
$s=intval(dec10($s[0]));
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <title><?php echo $C_title?></title>
    <meta name="description" content="<?php echo $C_description?>" />
    <meta name="keywords" content="<?php echo $C_keyword?>" />
    <link href="media/<?php echo $C_ico?>" rel="shortcut icon" />
	<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">
	<script src="https://cdn.bootcdn.net/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
	<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>
	<script src="https://cdn.bootcdn.net/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
	<style type="text/css">
	html{height: 100%}
	body{background: #f7f7f7;height: 100%}
	.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;}
</style>
<script type="text/javascript">
function isWeiXin(){
        var ua = window.navigator.userAgent.toLowerCase();
        if (ua.match(/MicroMessenger/i) == 'micromessenger') {
            return true; // 是微信端
        } else {
            return false;
        }
    }
function isQQ(){
        if(navigator.userAgent.toLowerCase().toString().indexOf('qqbrowser') > -1){
            return true; // 是QQ端
        } else {
            return false;
        }
    }
</script>
</head>
<body>
<?php
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) {
		mysqli_query($conn,"update sl_short set S_times=S_times+1 where S_id=".$s);
		$url=$row["S_url"];
		$url=urldecode($url);
		$S_vip=$row["S_vip"];
?>
<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>
	<?php echo $url?>
</p>
<?php
if($C_adprice3>0 && $S_vip==0){
	$sql="select * from sl_ad where A_type=2 and TIMESTAMPDIFF(MONTH,A_time,DATE_FORMAT(now(),'%Y-%m-%d'))<A_long order by A_order,A_id desc";
	$result = mysqli_query($conn,  $sql);
	if (mysqli_num_rows($result) > 0) {
	while($row = mysqli_fetch_assoc($result)) {
		echo "<a href=\"".$row["A_url"]."\"><img src=\"../media/".$row["A_pic"]."\" style=\"width:100%;position:absolute;bottom:0px;left:0px;\"></a>";
	    }
	} 
}
?>
</div>
</div>
<?php
		echo "<script>
			if(isWeiXin() || isQQ()){
				$('#divpop').show();
			}else{
				window.location.href='".$url."';
			}
			</script>";
		//header("Location: ".$url);
		//die($url);
	}else{
		die("{\"code\":\"error\",\"msg\":\"该短网址已失效，请重新生成\",\"S_id\":\"".$s."\"}");
	}
}
?>
</body>
</html>