<?php
/*=====================================================================*\
|| ###################################################################
|| # Bugdar 1.1.5
|| # Copyright ©2002-2007 Blue Static
|| #
|| # This program is free software; you can redistribute it and/or modify
|| # it under the terms of the GNU General Public License as published by
|| # the Free Software Foundation; version 2 of the License.
|| #
|| # This program is distributed in the hope that it will be useful, but
|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|| # more details.
|| #
|| # You should have received a copy of the GNU General Public License along
|| # with this program; if not, write to the Free Software Foundation, Inc.,
|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|| ###################################################################
\*=====================================================================*/

define('NO_TEMPLATES', 1);

require_once('./global.php');

if (!can_perform('canviewbugs'))
{
	$message->error_permission();
}

// ###################################################################

header('Content-type: application/xml');

$syndicate = '';
$timestamp = (can_perform('canviewhidden', 0, fetch_guest_user()) ? 'lastposttime' : 'hiddenlastposttime');
$lastupdated = 0;
$buglist = array();
if(isset($_GET['resolution'])) {
	$ress = explode(",", addslashes($_GET['resolution']));
	for($i=0; $i<count($ress); $i++) {
		$resolutions .= "'".$ress[$i]."',";
	}
	$resolutions = rtrim($resolutions, ",");
}
else
	$resolutions = array();
$bugs_fetch = $db->query("
	SELECT bug.*, comment.comment_parsed
	FROM " . TABLE_PREFIX . "bug AS bug
	LEFT JOIN " . TABLE_PREFIX . "comment AS comment
		ON (bug.initialreport = comment.commentid)
	LEFT JOIN " . TABLE_PREFIX . "resolution AS resolution
		ON (bug.resolution = resolution.resolutionid)
	WHERE bug.product IN (" . fetch_on_bits('canviewbugs', fetch_guest_user()) . ")
		AND (!bug.hidden OR (bug.hidden AND bug.product IN (" . fetch_on_bits('canviewhidden', fetch_guest_user()) . ")))".((count($ress) > 0) ? "AND resolution.resolution IN(".$resolutions.")" : "")."
	ORDER BY " . (can_perform('canviewhidden', 0, fetch_guest_user()) ? "bug.lastposttime" : "bug.hiddenlastposttime") . " DESC
	LIMIT " . $bugsys->options['syndicateditems']
);
while ($bug = $db->fetch_array($bugs_fetch))
{
	$syndicate .= '
	<entry>
		<id>bug://report/' . $bug['bugid'] . '</id>
		<title>' . $bug['summary'] . '</title>
		<updated>' . gmdate('Y-m-d\TH:i:s\Z', $bug["$timestamp"]) . '</updated>
		<author>
			<name>' . $bug['username'] . '</name>
		</author>
		<content type="html">
			' . htmlspecialchars('<table cellspacing="0" cellpadding="3" border="0">
			<tr>
				<td><strong>' . _('Bug ID') . ':</strong></td>
				<td>' . $bug['bugid'] . '</td>
			</tr>
			<tr>
				<td><strong>' . _('Summary') . ':</strong></td>
				<td>' . $bug['summary'] . '</td>
			</tr>
			<tr>
				<td><strong>' . _('Product/Component/Version') . ':</strong></td>
				<td>' . $bugsys->datastore['product']["$bug[product]"]['title'] . '/' . (($bug['component']) ? $bugsys->datastore['product']["$bug[component]"]['title'] . '/' : '') . $bugsys->datastore['version']["$bug[version]"]['version'] . '</td>
			</tr>
			<tr>
				<td><strong>' . _('Status') . ':</strong></td>
				<td>' . $bugsys->datastore['status']["$bug[status]"]['status'] . '</td>
			</tr>
			<tr>
				<td><strong>' . _('Severity') . ':</strong></td>
				<td>' . $bugsys->datastore['severity']["$bug[severity]"]['severity'] . '</td>
			</table>
			
			<p>' . $bug['comment_parsed'] . '</p>') . '
		</content>
		<summary type="text">' . htmlspecialchars($bug['comment_parsed']) . '</summary>
		<link rel="alternate" href="' . $bugsys->options['trackerurl'] . '/showreport.php?bugid=' . $bug['bugid'] . '"/>
	</entry>';
	
	$lastupdated = $bug["$timestamp"];
}

echo '<?xml version="1.0" encoding="' . $language['charset'] . '"?>
<feed xmlns="http://www.w3.org/2005/Atom">

	<title>' . sprintf(_('%1$s Syndication Feed'), $bugsys->options['trackertitle']) . '</title>
	<link href="' . $bugsys->options['trackerurl'] . '"/>
	<updated>' . gmdate('Y-m-d\TH:i:s\Z', $lastupdated) . '</updated>
	
	<!-- entries -->
	';

echo $syndicate;
	
echo '
	<!-- / entries -->

</feed>';

/*=====================================================================*\
|| ###################################################################
|| # $HeadURL: https://dev.bluestatic.org/svn/bugtrack/tags/1.1.5/syndicate.php $
|| # $Id: syndicate.php 1231 2006-10-04 05:40:05Z rsesek $
|| ###################################################################
\*=====================================================================*/
?>
