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

if (LabCMS::i()->is_cached($mod_template, 10, $_GET['var1'].'-'.User::i()->group_id)) return;

$count=Db::i()->selectCell("SELECT COUNT(msg_id) FROM ?_guest");

$pager=new Paginator($count, LabConfig::$mcfg['guestbook_posts_at_page'], $_GET['var1']);
$pager=$pager->getPages();

// Запрашиваем сами сообщения
$posts = Db::i()->select("SELECT msg_id, IF (g.user_id,login,name) as name, IF (g.user_id,u.email,g.email) as email, msg, answer, `date`, INET_NTOA(ip) as ip FROM ?_guest g LEFT JOIN ?_users u ON g.user_id=u.user_id ORDER BY `date` DESC LIMIT ?d, ?d", $pager['sql_start'], $pager['sql_limit']);

foreach($posts as $key=>$post)
{
	$posts[$key]['msg_html']=getbb($post['msg']);
	$posts[$key]['answer_html']=getbb($post['answer']);
}
Tpl::i()->assign("posts", $posts);
Tpl::i()->assign("pager", $pager);
