<?php

$bugzillaId = isset($_GET['id']) ? (int)$_GET['id'] : 0;
$jiraKey = false;

if($bugzillaId > 0) {
	$jiraResponse = @file_get_contents("http://jira.reactos.org/rest/api/2/search?fields=key&jql=%22External%20URL%22%3D%22http%3A%2F%2Fwww.reactos.org%2Fbugzilla%2Fshow_bug.cgi%3Fid%3D{$bugzillaId}%22");
	if($jiraResponse !== false) {
		$jiraResults = json_decode($jiraResponse, true);
		if($jiraResults !== null && isset($jiraResults['issues'][0]['key'])) {
			$jiraKey = $jiraResults['issues'][0]['key'];
		}
	}
}

if($jiraKey === false) {
    header('Location: http://jira.reactos.org');
}
else {
	header('Location: http://jira.reactos.org/browse/' . $jiraKey);
}