<?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="lc_guide.tpl";

$module='';

foreach (LabCMS::i()->modules as $mod) {
	if ($mod['component']) {
		$module=$mod['module'];
		break;
	}
}

$_GET['action']=isset($_GET['action'])?$_GET['action']:'';

if (LabCMS::i()->is_cached($mod_template, -1, $module.'-'.$_GET['action'])) return;

if ($module) {
	Tpl::i()->assign(
		'guide_text',
		Db::i()->selectCell(
			"SELECT guide
			FROM ?_lc_guide
			WHERE module=? AND action=?",
			$module,
			($_GET['action']?$_GET['action']:'')
		)
	);
}

if (!isset(LabCMS::i()->cache['guide_module'])) {
	LabCMS::i()->cache['guide_module']
	=Db::i()->selectCol(
		"SELECT module AS ARRAY_KEY, path
		FROM ?_tree t JOIN ?_includes i ON t.tree_id=i.tree_id
		JOIN ?_modules m ON i.module_id=m.module_id
		WHERE module = 'lc_guide_editor' AND `show`=1
		GROUP BY module"
	);
}
if (access('edit') && !empty(LabCMS::i()->cache['guide_module'])) {
	Tpl::i()->assign(LabCMS::i()->cache['guide_module']);
}

Tpl::i()->assign('component', $module);