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

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

	$q="SELECT event_title, description AS event_message, event_image, location, DATE_FORMAT(start_date, '%D %M, %Y') AS date, DATE_FORMAT(start_date, '%Y/%m/%d') AS main_date, DATE_FORMAT(start_date, '%e') AS day, DATE_FORMAT(start_date, '%b') AS month, DATE_FORMAT(start_date, '%Y') AS year FROM event WHERE event_id = {$event_id}";
	$r = $mysqli->query($q);
	for($single_event =[]; $row = $r->fetch_assoc(); $single_event[] = $row);
	$r->free();
	
	if (empty($single_event)){
		redirect_to('event.php');
	}

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

	$q="SELECT event_id, event_title FROM event WHERE event_id > {$event_id} ORDER BY event_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_event[0]['event_title']; ?></title>