<?php
ob_start();
session_start();
include("./inc/db_connection.php");
include("./inc/function.php");
$db = new DB();


if(function_exists('date_default_timezone_set')) date_default_timezone_set('Asia/Jakarta');

$it = $_GET['it'];
$it_1 = clean_text($it);
$c = $_GET['c'];
$offset = $_GET['offset'];



if($c!="" && $offset!=""){

	$cachekey_cek_cate_offset = 'cek_category_'.$c.'_'.$offset;
	if(apcu_exists($cachekey_cek_cate_offset)===false) {
		$sql_cek_cate="select form_category from `category` where code=?  and status = '1' limit 0,1 ";
		$lihat_cek_cate= $db->squery($sql_cek_cate, array($c));
		
		apcu_store($cachekey_cek_cate_offset, serialize($lihat_cek_cate),360);
	}
	else
	{
		$lihat_cek_cate = unserialize(apcu_fetch($cachekey_cek_cate_offset));
	} 
	$code_redirect = $lihat_cek_cate[0]['form_category'];
	
	header("HTTP/1.0 404 Not Found");
	header('Location: https://www.indotelko.com/'.$code_redirect.'/'.$offset);
	exit(0);	
}else if($c!=""){

	$cachekey_cek_cate = 'cek_category_'.$c;
	if(apcu_exists($cachekey_cek_cate)===false) {
		$sql_cek_cate="select form_category from `category` where code=?  and status = '1' limit 0,1 ";
		$lihat_cek_cate= $db->squery($sql_cek_cate, array($c));
		
		apcu_store($cachekey_cek_cate, serialize($lihat_cek_cate),360);
	}
	else
	{
		$lihat_cek_cate = unserialize(apcu_fetch($cachekey_cek_cate));
	} 
	$code_redirect = $lihat_cek_cate[0]['form_category'];
	
	header("HTTP/1.0 404 Not Found");
	header('Location: https://www.indotelko.com/'.$code_redirect.'/');
	exit(0);
}



/*
$aling = $_SERVER['REQUEST_URI'];
if($aling=="/kanal.php?c=fa"){
	header("HTTP/1.0 404 Not Found");
	header('Location: https://www.indotelko.com/financial-analysis/');
	exit(0);	  
}else if($aling=="/kanal.php?c=rm"){
	header("HTTP/1.0 404 Not Found");
	header('Location: https://www.indotelko.com/rumors/');
	exit(0);	  
}else{
	header("HTTP/1.0 404 Not Found");
	header('Location: https://www.indotelko.com/');
	exit(0);
} */

$sNews = isset($_POST['q']); if(isset($_POST['q'])){ $sNews = $_POST['q']; }
$idberita = trim($_GET['berita']);
$title_e = $_GET['title'];
$ip_visitor= $_SERVER["REMOTE_ADDR"];
$session_id = session_id();


$cachekey_cek_link_news = 'cek_link_news_'.$it_1;
//apcu_delete($cachekey_view_news);
if(apcu_exists($cachekey_cek_link_news)===false) {
	$sql_cek_red="select linkid, url,lipsus from `news` where url=?  and status = '1' order by date desc limit 0,1 ";
	$lihat_cek_red= $db->squery($sql_cek_red, array($it_1));
	
	apcu_store($cachekey_cek_link_news, serialize($lihat_cek_red),360);
}
else
{
	$lihat_cek_red = unserialize(apcu_fetch($cachekey_cek_link_news));
} 

$idnews_redirect = $lihat_cek_red[0]['linkid'];
$url_redirect = $lihat_cek_red[0]['url'];
$lipsus_redirect = $lihat_cek_red[0]['lipsus'];

if($idnews_redirect!=""){
  
  if($lipsus_redirect!="0" AND $lipsus_redirect!="99"){
	  header("HTTP/1.0 404 Not Found");
	  header('Location: https://www.indotelko.com/read/'.$idnews_redirect.'/'.$url_redirect);
	  exit(0);	  
  }else{
	  header("HTTP/1.0 404 Not Found");
	  header('Location: https://www.indotelko.com/'.link_lipsus($lipsus_redirect).'/read/'.$idnews_redirect.'/'.$url_redirect);
	  exit(0);	  
  }
  
} 

?>