<?php
include_once "modules_extra/demoview/base/config.php";

if($page->privacy == 1 && !is_auth()) {
	show_error_page('not_auth');
}

if (isset($_GET['id'])) {
	$id = clean($_GET['id'],"int");
} else {
	show_error_page('not_settings');
}

$STH = $pdo->query("SELECT demoview.*,users.login,users.avatar,servers.name,servers.id AS server_id FROM demoview LEFT JOIN users ON demoview.author = users.id LEFT JOIN servers ON demoview.server = servers.id WHERE demoview.id='$id' LIMIT 1"); $STH->setFetchMode(PDO::FETCH_OBJ);  
$demoview = $STH->fetch();
if(empty($demoview->id)){
	show_error_page();
}

$tpl->load_template('elements/title.tpl');
$tpl->set("{title}", 'Демо от '.$demoview->login);
$tpl->set("{name}", $conf->name);
$tpl->compile( 'title' );
$tpl->clear();

$tpl->load_template('head.tpl');
$tpl->set("{title}", $tpl->result['title']);
$tpl->set("{site_name}", $conf->name);
$tpl->set("{image}", $page->image);
$tpl->set("{robots}", $page->robots);
$tpl->set("{type}", $page->kind);
$tpl->set("{description}", 'Демо от '.$demoview->login);
$tpl->set("{keywords}", 'Демо от '.$demoview->login);
$tpl->set("{url}", $page->full_url);
$tpl->set("{other}", '<script src="{site_host}modules/editors/tinymce/tinymce.min.js"></script>'.$module['to_head']);
$tpl->set("{token}", $token);
$tpl->set("{cache}", $conf->cache);
$tpl->set("{template}", $conf->template);
$tpl->set("{site_host}", $site_host);
$tpl->compile( 'content' );
$tpl->clear();

$menu = $tpl->get_menu($pdo);

$nav = array(
	$PI->to_nav('main', 0, 0),
	$PI->to_nav('demoview', 0, 0),
	$PI->to_nav('demoview_app', 1, 0, 'Демо от '.$demoview->login)
);
$nav = $tpl->get_nav($nav, 'elements/nav_li.tpl');

if(isset($_SESSION['id'])) {
	include_once "inc/authorized.php";
} else {
	include_once "inc/not_authorized.php";
}

if($demoview->img != '0') {
	$data = explode(";", $demoview->img);
	$count = count($data);
	$imgs = '<div id="imgs">';
	for ($i=0; $i < $count; $i++) {
		if(!empty($data[$i])){
			$imgs .= '<a class="thumbnail" data-lightbox="1" href="'.$data[$i].'"><img class="thumbnail-img" src="'.$data[$i].'"></img></a>';
		}
	}
	$imgs .= '</div>';
} else {
	$imgs = 0;
}

if($demoview->status == 0){
	$status = "Не рассмотрена";
	$color = "warning";
}
if($demoview->status == 1){
	$status = "Читов не обнаружено";
	$color = "success";
}
if($demoview->status == 2){
	$status = "Обнаружены читы";
	$color = "danger";
}

$editor_settings = get_editor_settings($pdo);
$tpl->load_template($module['tpl_dir'].'demoview.tpl');
$tpl->set("{file_manager}", $editor_settings['file_manager']);
$tpl->set("{file_manager_theme}", $editor_settings['file_manager_theme']);
$tpl->set("{id}", $demoview->id);
$tpl->set("{nick}", $demoview->nick);
$tpl->set("{status}", $status);
$tpl->set("{color}", $color);
$tpl->set("{date}", expand_date($demoview->date,1));
$tpl->set("{demo}", $demoview->demo);
$tpl->set("{imgs}", $imgs);
$tpl->set("{server}", $demoview->name);
$tpl->set("{server_id}", $demoview->server_id);
$tpl->set("{author_id}", $demoview->author);
$tpl->set("{author_login}", $demoview->login);
$tpl->set("{ava}", $demoview->avatar);
if($demoview->status != 0){
	$closed = $demoview->closed;
	$STH = $pdo->query("SELECT id,login,rights FROM users WHERE id='$closed'"); $STH->setFetchMode(PDO::FETCH_OBJ);  
	$row = $STH->fetch();  
	$tpl->set("{closed}", $closed);
	$tpl->set("{closed_a}", $row->login);
	$tpl->set("{closed_gp_name}", $users_groups[$row->rights]['name']);
	$tpl->set("{closed_gp_color}", $users_groups[$row->rights]['color']);
} else {
	$tpl->set("{closed}", 0);
	$tpl->set("{closed_a}", '');
	$tpl->set("{closed_gp_name}", '');
	$tpl->set("{closed_gp_color}", '');
}
if(isset($_SESSION['id'])) {
	$tpl->set("{allow}", '1');
} else {
	$tpl->set("{allow}", '2');
}
$tpl->set("{site_host}", $site_host);
$tpl->set("{template}", $conf->template); 
$tpl->compile( 'content' );
$tpl->clear();
?>