<?php
/*
* @package LabCMS
* @copyright (c) 2006 Alexander Levin aka Loki (loki_angel@mail.ru)
* @support http://labcms.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
$mod_template="show.tpl";

$page_id=intval($_GET['var1']);
if ($page_id && access('edit'))
{
	$page_info=Db::i()->selectRow("SELECT page_id, tree_id, page_title, page_description, page_keywords, page_text FROM ?_pages WHERE page_id=?", $page_id);
	if (!$page_info) LabCMS::i()->error404();
	addBreadcrumb("все страницы сайта", LabCMS::i()->url(false, 'list'));
	addBreadcrumb($page_info['page_title'], LabCMS::i()->url($page_id));
	LabVars::$title=$page_info['page_title'];

}
else
{
	if (LabCMS::i()->is_cached($mod_template, -1, LabCMS::i()->url)
		&& LabConfig::$mcfg['use_comments']
		&& LabCMS::i()->cache['admin_pages']['use_comments'])
	{
		assignComments();
		return;
	}

	$page_info=Db::i()->selectRow("SELECT page_id, tree_id, page_title, page_description, page_keywords, page_text, use_comments FROM ?_pages WHERE tree_id=?", LabCMS::i()->id);

	if (LabConfig::$mcfg['use_comments']
		&& $page_info['use_comments']) assignComments();

	if (LabCMS::i()->title!=$page_info['page_title']
		|| LabCMS::i()->description!=$page_info['page_description']
		|| LabCMS::i()->keywords!=$page_info['page_keywords']
		|| LabCMS::i()->cache['admin_pages']['use_comments']!=$page_info['use_comments']
	)
	{
		LabCMS::i()->cached=false;
		if ($page_info) LabCMS::i()->title=$page_info['page_title'];
		if ($page_info['page_description']) LabCMS::i()->description=$page_info['page_description'];
		if ($page_info['page_keywords']) LabCMS::i()->keywords=$page_info['page_keywords'];
		if ($page_info['use_comments']) LabCMS::i()->cache['admin_pages']['use_comments']=$page_info['use_comments'];
	}
}

Tpl::i()->assign($page_info);

function assignComments()
{
	$comments=CommentTools::getComments(LabCMS::i()->id, LabCMS::i()->url);
	Tpl::i()->assign('comments', $comments);
}