input_clean('bugid', TYPE_UINT);
// ###################################################################
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 = L_INVALID_ID;
}
}
eval('$template->flush("' . $template->fetch('quicksearch') . '");');
exit;
}
// ###################################################################
// -------------------------------------------------------------------
// get the report
$bug = $db->query_first("
SELECT 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)
WHERE bug.bugid = $bugid"
);
if (!is_array($bug))
{
$message->error(L_INVALID_ID);
}
if (!check_bug_permissions($bug))
{
$message->errorPermission();
}
$show['edit'] = ((can_perform('caneditown', $bug['product']) AND $bugsys->userinfo['userid'] == $bug['userid'] AND $bug['userid'] != 0) OR (can_perform('caneditother', $bug['product']) AND $bugsys->userinfo['userid'] != $bug['userid']));
$show['delete'] = can_perform('candeletedata', $bug['product']);
// ###################################################################
// edit display
if ($show['edit'])
{
$select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', $bug['severity']);
$show['changestatus'] = (can_perform('canchangestatus', $bug['product']) ? true : false);
if (can_perform('canchangestatus', $bug['product']))
{
$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']);
}
else
{
$bug['status'] = bugdar::$datastore['status']["$bug[status]"]['status'];
$bug['resolution'] = bugdar::$datastore['resolution']["$bug[resolution]"]['resolution'];
$bug['severity'] = bugdar::$datastore['severity']["$bug[severity]"]['severity'];
$bug['priority'] = bugdar::$datastore['priority']["$bug[priority]"]['priority'];
}
$show['assign'] = (can_perform('canassign', $bug['product']) ? true : false);
if (can_perform('canassign', $bug['product']) AND is_array(bugdar::$datastore['assignto']))
{
foreach (bugdar::$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') . '";');
}
}
$productSelect = ConstructProductSelect('canviewbugs', "$bug[product],$bug[component],$bug[version]");
if ($bug['duplicateof'])
{
$duplicate = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
}
if ($bug['dependency'])
{
$depends = array();
$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);
}
$select['automations'] = '';
$show['automations'] = false;
if (is_array(bugdar::$datastore['automation']))
{
foreach (bugdar::$datastore['automation'] AS $action)
{
$label = $action['name'];
$value = $action['actionid'];
$selected = false;
eval('$select[automation] .= "' . $template->fetch('selectoption') . '";');
$show['automations'] = true;
}
if ($show['automations'])
{
$label = '';
$value = 0;
$selected = true;
eval('$select[automation] = "' . $template->fetch('selectoption') . '" . $select[automation];');
}
}
}
// ###################################################################
// non-edit display
else
{
// -------------------------------------------------------------------
// prep display
$bug['status'] = bugdar::$datastore['status']["$bug[status]"]['status'];
$bug['resolution'] = bugdar::$datastore['resolution']["$bug[resolution]"]['resolution'];
$bug['severity'] = bugdar::$datastore['severity']["$bug[severity]"]['severity'];
$bug['priority'] = bugdar::$datastore['priority']["$bug[priority]"]['priority'];
$assigninfo = bugdar::$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]");
$dupelist = array();
$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'])
{
$depends = array();
$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);
}
}
// ###################################################################
// global display items
$show['subscribe'] = can_perform('cansubscribe', $bug['product']);
$favorite = (bool)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "favorite WHERE bugid = $bug[bugid] AND userid = " . $bugsys->userinfo['userid']);
$favoritetext = ($favorite ? T('Remove from Favorites') : T('Add to Favorites'));
$bug['userinfo'] = construct_user_display($bug);
$bug['datetime'] = $datef->format($bugsys->options['dateformat'], $bug['dateline']);
$bug['productid'] = $bug['product'];
$bug['product'] = bugdar::$datastore['product']["$bug[product]"]['title'];
$bug['componentid'] = $bug['component'];
$bug['component'] = ($bug['component'] ? bugdar::$datastore['product']["$bug[component]"]['title'] : '');
$bug['versionid'] = $bug['version'];
$bug['version'] = bugdar::$datastore['version']["$bug[version]"]['version'];
// ###################################################################
// custom field output
$fields = construct_custom_fields($bug);
$i = 0;
foreach ($fields AS $field)
{
if ($i % 2 == 0)
{
$customfields['left'] .= $field;
}
else
{
$customfields['right'] .= $field;
}
$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', $bug['productid']) OR can_perform('caneditattach', $bug['productid'])) ? true : false);
$show['putattachments'] = ((can_perform('canputattach', $bug['productid']) OR can_perform('caneditattach', $bug['productid'])) ? true : false);
$show['attachments'] = ($show['getattachments'] OR $show['putattachments']) ? true : false;
if ($show['getattachments'] OR $show['putattachments'])
{
$attachments_fetch = $db->query("
SELECT attachment.attachmentid, attachment.filename,
attachment.description, attachment.dateline,
attachment.userid, attachment.obsolete, 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', $bug['productid']) OR ($attachment['userid'] == $bugsys->userinfo['userid'] AND can_perform('canputattach', $bug['productid']))) ? 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'];
if ($vote['total'] != 0)
{
$vote['forpercent'] = round($vote['votefor'] / $vote['total'], 3) * 100;
$vote['againstpercent'] = round($vote['voteagainst'] / $vote['total'], 3) * 100;
}
else
{
$vote['forpercent'] = 0;
$vote['againstpercent'] = 0;
}
$show['vote'] = ((can_perform('canvote', $bug['productid']) AND !$vote['uservote']) ? true : false);
$BUGITEMS = array();
// -------------------------------------------------------------------
// history
$lookupfields = array(
'status' => 'status',
'priority' => 'priority',
'severity' => 'severity',
'resolution' => 'resolution',
'version' => 'version',
'product' => 'title',
'component' => 'title'
);
$customfield_logs = $db->query("
SELECT bugfield.*, MAX(permission.mask) AS mask
FROM " . TABLE_PREFIX . "bugfield AS bugfield
LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
ON (bugfield.fieldid = permission.fieldid)
WHERE mask <> 0
AND permission.usergroupid IN ({$bugsys->userinfo['usergroupid']}" . (sizeof($bugsys->userinfo['groupids']) != 0 ? ',' . implode(',', $bugsys->userinfo['groupids']) : '') . ")
GROUP BY (bugfield.fieldid)"
);
while ($field = $db->fetch_array($customfield_logs))
{
$fieldlist["$field[fieldid]"] = sprintf(T('Custom Field %1$s (%2$s)'), $field['fieldid'], $field['name']);
}
$logs = array();
$logs_fetch = $db->query("
SELECT history.*, user.userid, user.email, user.displayname, user.showemail
FROM " . TABLE_PREFIX . "history AS history
LEFT JOIN " . TABLE_PREFIX . "user AS user
ON (user.userid = history.userid)
WHERE bugid = $bug[bugid]"
);
while ($log = $db->fetch_array($logs_fetch))
{
$log['date'] = $datef->format($bugsys->options['dateformat'], $log['dateline']);
$log['user'] = construct_user_display($log);
$logs["$log[dateline]"]["$log[historyid]"] = $log;
ksort($logs["$log[dateline]"]);
}
ksort($logs);
$toKill = array();
$logusers = array();
foreach ($logs AS $dateline => $logitems)
{
$show['group'] = true;
foreach ($logitems AS $log)
{
if ($log['field'] == '.' OR ($log['original'] == '' AND $log['changed'] == ''))
{
$toKill[] = $log['historyid'];
continue;
}
if (preg_match('#^(comment|attachment)\.(.*)#', $log['field'], $matches))
{
if ($matches[1] == 'comment')
{
$log['field'] = sprintf(T('Comment #%1$s %2$s'), $log['commentid'], ucwords($matches[2]));
}
else if ($matches[1] == 'attachment')
{
$log['field'] = sprintf(T('Attachment #2%1$s %2$s'), $log['attachmentid'], ucwords($matches[2]));
}
}
else if (preg_match('#^.?custom(.field)?([0-9]+?)#', $log['field'], $matches))
{
if ($fieldlist["$matches[2]"])
{
$log['field'] = $fieldlist["$matches[2]"];
}
else
{
continue;
}
}
else if (preg_match('#^\.(.*)#', $log['field'], $matches))
{
$log['field'] = ucwords($matches[1]);
if (isset($lookupfields["$matches[1]"]))
{
$lookup = $matches[1];
$log['original'] = bugdar::$datastore["$lookup"]["$log[original]"][ $lookupfields["$lookup"] ];
$log['changed'] = bugdar::$datastore["$lookup"]["$log[changed]"][ $lookupfields["$lookup"] ];
}
else if ($matches[1] == 'assignto' OR $matches[1] == 'assignedto')
{
if ($log['original'])
{
if (!$logusers[$log['original']])
{
$user = new UserAPI($bugsys);
$user->set('userid', $log['original']);
$user->set_condition();
$user->fetch();
$logusers[$log['original']] = construct_user_display($user->objdata);
}
$log['original'] = $logusers[$log['original']];
}
if ($log['changed'])
{
if (!$logusers[$log['changed']])
{
$user = new UserAPI($bugsys);
$user->set('userid', $log['changed']);
$user->set_condition();
$user->fetch();
$logusers[$log['changed']] = construct_user_display($user->objdata);
}
$log['changed'] = $logusers[$log['changed']];
}
}
}
$funct->exec_swap_bg('', 'altcolor');
$bgcolor = $funct->bgcolour;
eval('$BUGITEMS[$dateline] .= "' . $template->fetch('history_bit') . '";');
$show['group'] = false;
}
}
// we can now remove all useless logs
if (sizeof($toKill) > 0)
{
$db->query("DELETE FROM " . TABLE_PREFIX . "history WHERE historyid IN (" . implode(',', $toKill) . ")");
}
// -------------------------------------------------------------------
// 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', $bug['productid']) ? "
AND !hidden" : '') . "
ORDER BY comment.dateline ASC"
);
$description = null;
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('caneditownreply', $bug['productid']) AND $bugsys->userinfo['userid'] == $comment['userid']) OR (can_perform('caneditotherreply', $bug['productid']) AND $bugsys->userinfo['userid'] != $comment['userid']));
$bugsys->debug('can edit own replies: ' . (int)(can_perform('caneditownreply', $bug['productid']) AND $bugsys->userinfo['userid'] == $comment['userid']));
$bugsys->debug('can edit other replies:' . (int)(can_perform('caneditotherreply', $bug['productid']) AND $bugsys->userinfo['userid'] != $comment['userid']));
$bugsys->debug('$show[editcomment]: ' . $show['editcomment']);
if (is_array($hilight))
{
foreach ($hilight AS $id => $find)
{
$find = "#($find)#i";
$replace = "\\1";
$comment['comment_parsed'] = preg_replace($find, $replace, $comment['comment_parsed']);
}
}
eval('$temp = "' . $template->fetch('showreport_comment') . '";');
if ($description == null)
{
$description = $temp;
}
else
{
$comments .= $temp;
$BUGITEMS[$comment['dateline']] = $temp . $BUGITEMS[$comment['dateline']];
}
}
$show['newreply'] = (can_perform('canpostcomments', $bug['productid']) ? true : false);
$bug['summary_title'] = $bug['summary'];
if (is_array($hilight) AND !$show['edit'])
{
foreach ($hilight AS $id => $find)
{
$find = "#($find)#i";
$replace = "\\1";
$bug['summary'] = preg_replace($find, $replace, $bug['summary']);
}
}
ksort($BUGITEMS);
$BUGITEMS = implode("\n", $BUGITEMS);
eval('$template->flush("' . $template->fetch('showreport') . '");');