<?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
*/

	LabCMS::i()->setModuleTemplate('string:{$xml}');
	LabVars::$break=true;
	LabVars::$template='blank.tpl';
	
	sendXmlHeaders();
	if (LabCMS::i()->is_cached('string:{$xml}', 10*60, 'bug_item'.$_GET['var1'])) return;
	
	$url=getServerName();

	$bug_info=Db::i()->selectRow("SELECT bug_id, b.project_id, IF(b.version_id=-1, 'HEAD',version) version, summary, type, author_id, a.login author, UNIX_TIMESTAMP(bug_date) bug_date, importance, approver_id, ap.login approver, b.status, performer_id, p.login performer
													FROM ?_bt_bugs b
													JOIN ?_users a ON a.user_id=b.author_id
													LEFT JOIN ?_users ap ON ap.user_id=b.approver_id
													LEFT JOIN ?_users p ON p.user_id=b.performer_id
													LEFT JOIN ?_bt_versions v ON v.version_id=b.version_id
													WHERE bug_id=?", $_GET['var1']);
	
	$bug_info['summary_html']=getbb($bug_info['summary'], 'nolinks');
	
	$rss=array('title'=>$bug_info['summary_html'],
						'link'=>$url.LabCMS::i()->url($bug_info['bug_id'], 'item', 'xml'),
						'description'=>'Тип: '.$bug_types[$bug_info['type']].
												', Статус: '.$statuses[$bug_info['status']].
												', Важность: '.$importances[$bug_info['importance']].
												', Версия: '.$bug_info['version'].
												', Автор: '.$bug_info['author']);
	
	$comments=Db::i()->select("SELECT post_id AS ARRAY_KEY, msg, UNIX_TIMESTAMP(putdate) ut_putdate, putdate, p.user_id, login FROM ?_bt_posts p JOIN ?_users u ON p.user_id=u.user_id WHERE bug_id=? ORDER BY putdate", $bug_info['bug_id']);
	
	if (is_array($comments) && count($comments))
	{
		foreach($comments as $post_id=>$comment)
		{
			$comment['msg_html']=getbb($comment['msg'], 'nolinks');
			
			$rss['feed'][]=array('title'=>$comment['login'],
								'description'=>	$comment['msg_html'],
								'link'=>$url.LabCMS::i()->url($bug_info['bug_id'], 'item').'#btc'.$post_id,
								'pubDate'=>$comment['ut_putdate']);
		}
	}
	
	$xml=genereteFeed($rss);
	Tpl::i()->assign('xml', $xml);
