error_permission();
}
$show['edit'] = (((can_perform('caneditown') AND $bugsys->userinfo['userid'] == $bug['userid']) OR can_perform('caneditothers')) AND can_perform('caneditinfo')) ? true : false;
$bugid = intval($bugsys->in['bugid']);
// ###################################################################
if (empty($bugid) OR $_REQUEST['do'] == 'quicksearch')
{
if (!empty($bugid))
{
if ($db->query_first("SELECT bugid FROM " . TABLE_PREFIX . "bug WHERE bugid = $bugid"))
{
header("Location: showreport.php?bugid=$bugid");
exit;
}
else
{
$error = $lang->getlex('error_invalid_id');
}
}
eval('$template->flush("' . $template->fetch('quicksearch') . '");');
exit;
}
// ###################################################################
// -------------------------------------------------------------------
// get the report
$bug = $db->query_first("
SELECT bugvaluefill.*, bug.*, user.email, user.displayname, user.showemail
FROM " . TABLE_PREFIX . "bug AS bug
LEFT JOIN " . TABLE_PREFIX . "user AS user
ON (bug.userid = user.userid)
LEFT JOIN " . TABLE_PREFIX . "bugvaluefill AS bugvaluefill
ON (bug.bugid = bugvaluefill.bugid)
WHERE bug.bugid = " . intval($bugsys->in['bugid'])
);
if (!is_array($bug))
{
$message->error($lang->getlex('error_invalid_id'));
}
if ($bug['hidden'] AND !can_perform('canviewhidden'))
{
$message->error_permission();
}
// ###################################################################
// global display items
$favourite = (bool)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "favourite WHERE bugid = $bug[bugid] AND userid = " . $bugsys->userinfo['userid']);
$favouritetext = (($favourite) ? $lang->string('Remove from Favourites') : $lang->string('Add to Favourites'));
$bug['userinfo'] = construct_user_display($bug);
$bug['datetime'] = $datef->format($bugsys->options['dateformat'], $bug['dateline']);
$bug['product'] = $bugsys->datastore['product']["$bug[productid]"]['title'];
$bug['component'] = (($bug['componentid']) ? $bugsys->datastore['product']["$bug[componentid]"]['title'] : '');
$bug['version'] = $bugsys->datastore['version']["$bug[versionid]"]['version'];
// ###################################################################
// edit display
if ($show['edit'])
{
$select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', $bug['severity']);
$show['changestatus'] = ((can_perform('canchangestatus')) ? true : false);
if (can_perform('canchangestatus'))
{
$select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', $bug['priority']);
$select['status'] = construct_datastore_select('status', 'status', 'statusid', $bug['status']);
$select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', $bug['resolution']);
}
$show['assign'] = ((can_perform('canassign')) ? true : false);
if (can_perform('canassign'))
{
foreach ($bugsys->datastore['assignto'] AS $dev)
{
$value = $dev['userid'];
$selected = (($dev['userid'] == $bug['assignedto']) ? true : false);
$label = construct_user_display($dev, false);
eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
}
}
$pcv_select = construct_pcv_select("p$bug[productid]c$bug[componentid]v$bug[versionid]");
$firstcomment = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] ORDER BY dateline ASC LIMIT 1");
if ($bug['duplicateof'])
{
$duplicate = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
}
if ($bug['dependency'])
{
$dependencies = $db->query("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($bug[dependency])");
while ($dependency = $db->fetch_array($dependencies))
{
$depends[] = "$dependency[bugid]";
}
$dependencies = implode(' ', $depends);
}
$actions = $db->query("SELECT * FROM " . TABLE_PREFIX . "autoaction ORDER BY name ASC");
$select['autoactions'] = '';
$show['autoactions'] = false;
while ($action = $db->fetch_array($actions))
{
$label = $action['name'];
$value = $action['actionid'];
$selected = false;
eval('$select[autoaction] .= "' . $template->fetch('selectoption') . '";');
$show['autoactions'] = true;
}
if ($show['autoactions'])
{
$label = '';
$value = 0;
$selected = true;
eval('$select[autoaction] = "' . $template->fetch('selectoption') . '" . $select[autoaction];');
}
}
// ###################################################################
// non-edit display
else
{
// -------------------------------------------------------------------
// prep display
$bug['status'] = $bugsys->datastore['status']["$bug[status]"]['status'];
$bug['resolution'] = $bugsys->datastore['resolution']["$bug[resolution]"]['resolution'];
$bug['severity'] = $bugsys->datastore['severity']["$bug[severity]"]['severity'];
$bug['priority'] = $bugsys->datastore['priority']["$bug[priority]"]['priority'];
$assigninfo = $bugsys->datastore['assignto']["$bug[assignedto]"];
$bug['assigninfo'] = ((is_array($assigninfo)) ? construct_user_display($assigninfo) : '');
$duplicateof = $db->query_first("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
$duplicates = $db->query("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE duplicateof = $bug[bugid]");
while ($duplicate = $db->fetch_array($duplicates))
{
$dupelist[] = "$duplicate[summary]";
}
$dupelist = implode(', ', $dupelist);
if ($bug['dependency'])
{
$dependencies = $db->query("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE bugid IN ($bug[dependency])");
while ($dependency = $db->fetch_array($dependencies))
{
$depends[] = "$dependency[bugid]";
}
$dependencies = implode(' ', $depends);
}
}
// ###################################################################
// custom field output
$fields = construct_custom_fields($bug);
$show['customfields'] = ($fields ? true : false);
$bugsys->debug('fields modulo: ' . count($fields) % 2);
$i = 1;
foreach ($fields AS $field)
{
$bugsys->debug("i = $i");
if ($i == 1)
{
$customfields['right'] .= $field;
}
else if ($i == 2)
{
$customfields['left'] .= $field;
$i = 0;
}
$i++;
}
// ###################################################################
// other elements
// -------------------------------------------------------------------
// hilight
$words = explode(' ', $bugsys->in['hilight']);
foreach ($words AS $word)
{
if (trim($word))
{
$word = preg_quote($bugsys->unsanitize($word));
$hilight[] = $temp = trim(preg_replace('#[^0-9a-zA-Z_ ]#', '', $word));
}
}
// -------------------------------------------------------------------
// attachments
$show['getattachments'] = ((can_perform('cangetattach') OR can_perform('caneditattach')) ? true : false);
$show['putattachments'] = ((can_perform('canputattach') OR can_perform('caneditattach')) ? true : false);
$show['attachments'] = ($show['getattachments'] OR $show['putattachments']) ? true : false;
if ($show['getattachments'] OR $show['putattachments'])
{
$attachments_fetch = $db->query("
SELECT attachment.*, user.email, user.showemail,
user.displayname
FROM " . TABLE_PREFIX . "attachment AS attachment
LEFT JOIN " . TABLE_PREFIX . "user AS user
ON (attachment.userid = user.userid)
WHERE attachment.bugid = $bug[bugid]
ORDER BY attachment.dateline"
);
$attaches = false;
while ($attachment = $db->fetch_array($attachments_fetch))
{
$attaches = true;
$show['editattach'] = ((can_perform('caneditattach') OR ($attachment['userid'] == $bugsys->userinfo['userid'] AND can_perform('canputattach'))) ? true : false);
$attachment['date'] = $datef->format($bugsys->options['dateformat'], $attachment['dateline']);
$attachment['user'] = construct_user_display($attachment, false);
eval('$attachments .= "' . $template->fetch('showreport_attachment') . '";');
}
$show['attachments'] = (!$show['putattachments'] AND !$attaches) ? false : true;
}
// -------------------------------------------------------------------
// votes
$vote = $db->query_first("SELECT *, FIND_IN_SET(" . $bugsys->userinfo['userid'] . ", userids) AS uservote FROM " . TABLE_PREFIX . "vote WHERE bugid = $bug[bugid]");
$vote['total'] = $vote['votefor'] + $vote['voteagainst'];
$vote['forpercent'] = round($vote['votefor'] / $vote['total'], 3) * 100;
$vote['againstpercent'] = round($vote['voteagainst'] / $vote['total'], 3) * 100;
$show['vote'] = ((can_perform('canvote') AND !$vote['uservote']) ? true : false);
// -------------------------------------------------------------------
// get comments
$comments_fetch = $db->query("
SELECT comment.*, user.email, user.showemail, user.displayname
FROM " . TABLE_PREFIX . "comment AS comment
LEFT JOIN " . TABLE_PREFIX . "user AS user
ON (comment.userid = user.userid)
WHERE comment.bugid = $bug[bugid]" . ((!can_perform('canviewhidden')) ? "
AND !hidden" : '') . "
ORDER BY comment.dateline ASC"
);
while ($comment = $db->fetch_array($comments_fetch))
{
$comment['posttime'] = $datef->format($bugsys->options['dateformat'], $comment['dateline']);
$comment['postby'] = construct_user_display($comment);
$show['editcomment'] = (((can_perform('caneditown') AND $bugsys->userinfo['userid'] == $comment['userid']) OR can_perform('caneditothers')) ? true : false);
if (is_array($hilight))
{
foreach ($hilight AS $id => $find)
{
$find = "#($find)#";
$replace = "\\1";
$comment['comment_parsed'] = preg_replace($find, $replace, $comment['comment_parsed']);
}
}
eval('$comments .= "' . $template->fetch('showreport_comment') . '";');
}
$show['newreply'] = ((can_perform('canpostcomments')) ? true : false);
if (is_array($hilight))
{
foreach ($hilight AS $id => $find)
{
$find = "#($find)#";
$replace = "\\1";
$bug['summary'] = preg_replace($find, $replace, $bug['summary']);
}
}
eval('$template->flush("' . $template->fetch('showreport') . '");');
/*=====================================================================*\
|| ###################################################################
|| # $HeadURL$
|| # $Id$
|| ###################################################################
\*=====================================================================*/
?>