<?php
$public_fold = basename(dirname(dirname(__FILE__)));
require_once("{$_SERVER['DOCUMENT_ROOT']}/private/includes/initialize.php");
$mysqli->select_db($secondary_db);

	if(isset($_GET['news-id'])){
		$news_id = decrypt($_GET['news-id']);
		if(!is_numeric($news_id)){
			redirect_to('news.php');
		}
	}else{
		redirect_to('news.php');
	}

	$q="SELECT news_title, news_message, news_image, DATE_FORMAT(news_date, '%D %M, %Y') AS date, DATE_FORMAT(news_date, '%e') AS day, DATE_FORMAT(news_date, '%b') AS month, DATE_FORMAT(news_date, '%Y') AS year FROM news WHERE news_id = {$news_id}";
	$r = $mysqli->query($q);
	for($single_news =[]; $row = $r->fetch_assoc(); $single_news[] = $row);
	$r->free();

$q="SELECT image_name, image_dir FROM news_images WHERE news_id = {$news_id}";
$r = $mysqli->query($q);
for($news_images =[]; $row = $r->fetch_assoc(); $news_images[] = $row);
$r->free();
	
	if (empty($single_news)){
		redirect_to('news.php');
	}

	$q="SELECT news_id, news_title FROM news WHERE news_id < {$news_id} ORDER BY news_id DESC LIMIT 1";
	$r = $mysqli->query($q);
	for($previous =[]; $row = $r->fetch_assoc(); $previous = $row);
	$r->free();

	$q="SELECT news_id, news_title FROM news WHERE news_id > {$news_id} ORDER BY news_id ASC LIMIT 1";
	$r = $mysqli->query($q);
	for($next =[]; $row = $r->fetch_assoc(); $next = $row);
	$r->free();

?>
<!doctype html>
<html lang="zxx">
 
<head>
<title><?php echo $single_news[0]['news_title']; ?></title>