<?php
/**
 * @version $Id: page.php 794 2010-11-22 14:56:54Z roosit $
 * @package Abricos
 * @subpackage Comment
 * @copyright Copyright (C) 2008 Abricos All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 * @author Alexander Kuzmin (roosit@abricos.org)
 */

$brick = Brick::$builder->brick;
$contentId = Brick::$input->clean_gpc('g', 'contentid', TYPE_INT);
$manager = CMSRegistry::$instance->modules->GetModule('comment')->GetManager();

if (empty($contentId)){
	$contentId = Brick::$contentId;
}else{
	$brick->param->var['ondom'] = $brick->param->var['nonondom']; 
}

if ($contentId == 0){
	$brick->content = "";
	$brick->param->var = array();
	return;
}
$brick->param->var['cid'] = $contentId;

$data = array();
$rd = $manager->CommentsWithLastView($contentId);
// $rows = $manager->Comments($contentId); 
$lst = ""; $t = "";
$slst = "";
foreach ($rd->list as $row){
	if ($row['st'] == 1){
		$row['bd'] = '';
	}
	
	$lst .= Brick::ReplaceVarByData($brick->param->var['t'], array(
		"id" => $row['id'],
		"u" => $row['unm'],
		"c" => $row['bd']
	));
	unset($row['bd']);
	
	$slst .= str_replace('#c#', json_encode($row), $brick->param->var['si']);
}
$brick->param->var['lst'] = $lst;
$brick->param->var['slst'] = $slst;
$brick->param->var['lid'] = $rd->lastview;

if (CMSRegistry::$instance->user->IsRegistred()){
	$brick->param->var['ft'] = $brick->param->var['ftreg']; 
}

?>