]>
src.bluestatic.org Git - bugdar.git/blob - showreport.php
2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright (c)2002-2007 Blue Static
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
22 $fetchtemplates = array(
24 'showreport_attachment',
28 'bugfield_static_text'
32 $focus['showreport'] = 'focus';
34 require_once('./global.php');
35 require_once('./includes/functions_product.php');
37 $bugid = $bugsys->input_clean('bugid', TYPE_UINT
);
39 // ###################################################################
41 if (empty($bugid) OR $_REQUEST['do'] == 'quicksearch')
45 if ($db->query_first("SELECT bugid FROM " . TABLE_PREFIX
. "bug WHERE bugid = $bugid"))
47 header("Location
: showreport
.php
?bugid
=$bugid");
52 $error = L_INVALID_ID
;
56 eval('$template->flush("' . $template->fetch('quicksearch') . '");');
60 // ###################################################################
62 // -------------------------------------------------------------------
64 $bug = $db->query_first("
65 SELECT bug.*, user.email, user.displayname, user.showemail
66 FROM " . TABLE_PREFIX
. "bug AS bug
67 LEFT JOIN " . TABLE_PREFIX
. "user AS user
68 ON (bug.userid = user.userid)
69 WHERE bug.bugid = $bugid"
74 $message->error(L_INVALID_ID);
77 if (!check_bug_permissions($bug))
79 $message->errorPermission();
82 $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']));
83 $show['delete'] = can_perform('candeletedata', $bug['product']);
85 // ###################################################################
89 $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', $bug['severity']);
91 $show['changestatus'] = (can_perform('canchangestatus', $bug['product']) ? true : false);
92 if (can_perform('canchangestatus', $bug['product']))
94 $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', $bug['priority']);
95 $select['status'] = construct_datastore_select('status', 'status', 'statusid', $bug['status']);
96 $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', $bug['resolution']);
100 $bug['status'] = bugdar::$datastore['status']["$bug[status
]"]['status'];
101 $bug['resolution'] = bugdar::$datastore['resolution']["$bug[resolution
]"]['resolution'];
102 $bug['severity'] = bugdar::$datastore['severity']["$bug[severity
]"]['severity'];
103 $bug['priority'] = bugdar::$datastore['priority']["$bug[priority
]"]['priority'];
106 $show['assign'] = (can_perform('canassign', $bug['product']) ? true : false);
107 if (can_perform('canassign', $bug['product']) AND is_array(bugdar::$datastore['assignto']))
109 foreach (bugdar::$datastore['assignto'] AS $dev)
111 $value = $dev['userid'];
112 $selected = (($dev['userid'] == $bug['assignedto']) ? true : false);
113 $label = construct_user_display($dev, false);
114 eval('$select[dev] .= "' . $template->fetch('selectoption
') . '";');
118 $productSelect = ConstructProductSelect('canviewbugs', "$bug[product
],$bug[component
],$bug[version
]");
120 if ($bug['duplicateof'])
122 $duplicate = $db->query_first("SELECT
* FROM
" . TABLE_PREFIX . "bug WHERE bugid
= $bug[duplicateof
]");
125 if ($bug['dependency'])
128 $dependencies = $db->query("SELECT
* FROM
" . TABLE_PREFIX . "bug WHERE bugid
IN ($bug[dependency
])");
129 while ($dependency = $db->fetch_array($dependencies))
131 $depends[] = "<a href
=\"showreport
.php
?bugid
=$dependency[bugid
]\" title
=\"$dependency[summary
]\">$dependency[bugid
]</a
>";
133 $dependencies = implode(' ', $depends);
136 $select['automations'] = '';
137 $show['automations'] = false;
138 if (is_array(bugdar::$datastore['automation']))
140 foreach (bugdar::$datastore['automation'] AS $action)
142 $label = $action['name'];
143 $value = $action['actionid'];
145 eval('$select[automation] .= "' . $template->fetch('selectoption
') . '";');
146 $show['automations'] = true;
148 if ($show['automations'])
153 eval('$select[automation] = "' . $template->fetch('selectoption
') . '" . $select[automation];');
158 // ###################################################################
162 // -------------------------------------------------------------------
164 $bug['status'] = bugdar::$datastore['status']["$bug[status
]"]['status'];
165 $bug['resolution'] = bugdar::$datastore['resolution']["$bug[resolution
]"]['resolution'];
166 $bug['severity'] = bugdar::$datastore['severity']["$bug[severity
]"]['severity'];
167 $bug['priority'] = bugdar::$datastore['priority']["$bug[priority
]"]['priority'];
169 $assigninfo = bugdar::$datastore['assignto']["$bug[assignedto
]"];
170 $bug['assigninfo'] = ((is_array($assigninfo)) ? construct_user_display($assigninfo) : '');
172 $duplicateof = $db->query_first("SELECT bugid
, summary FROM
" . TABLE_PREFIX . "bug WHERE bugid
= $bug[duplicateof
]");
175 $duplicates = $db->query("SELECT bugid
, summary FROM
" . TABLE_PREFIX . "bug WHERE duplicateof
= $bug[bugid
]");
176 while ($duplicate = $db->fetch_array($duplicates))
178 $dupelist[] = "<a href
=\"showreport
.php
?bugid
=$duplicate[bugid
]\" target
=\"_blank\"
>$duplicate[summary
]</a
>";
180 $dupelist = implode(', ', $dupelist);
182 if ($bug['dependency'])
185 $dependencies = $db->query("SELECT bugid
, summary FROM
" . TABLE_PREFIX . "bug WHERE bugid
IN ($bug[dependency
])");
186 while ($dependency = $db->fetch_array($dependencies))
188 $depends[] = "<a href
=\"showreport
.php
?bugid
=$dependency[bugid
]\" title
=\"$dependency[summary
]\" target
=\"_blank\"
>$dependency[bugid
]</a
>";
190 $dependencies = implode(' ', $depends);
194 // ###################################################################
195 // global display items
197 $show['subscribe'] = can_perform('cansubscribe', $bug['product']);
199 $favorite = (bool)$db->query_first("SELECT
* FROM
" . TABLE_PREFIX . "favorite WHERE bugid
= $bug[bugid
] AND userid
= " . $bugsys->userinfo['userid']);
200 $favoritetext = ($favorite ? T('Remove from Favorites') : T('Add to Favorites'));
202 $bug['userinfo'] = construct_user_display($bug);
203 $bug['datetime'] = $datef->format($bugsys->options['dateformat'], $bug['dateline']);
204 $bug['productid'] = $bug['product'];
205 $bug['product'] = bugdar::$datastore['product']["$bug[product
]"]['title'];
206 $bug['componentid'] = $bug['component'];
207 $bug['component'] = ($bug['component'] ? bugdar::$datastore['product']["$bug[component
]"]['title'] : '');
208 $bug['versionid'] = $bug['version'];
209 $bug['version'] = bugdar::$datastore['version']["$bug[version
]"]['version'];
211 // ###################################################################
212 // custom field output
214 $fields = construct_custom_fields($bug);
216 foreach ($fields AS $field)
220 $customfields['left'] .= $field;
224 $customfields['right'] .= $field;
229 // ###################################################################
232 // -------------------------------------------------------------------
234 $words = explode(' ', $bugsys->in['hilight']);
235 foreach ($words AS $word)
239 $word = preg_quote($bugsys->unsanitize($word));
240 $hilight[] = $temp = trim(preg_replace('#[^0-9a-zA-Z_ ]#', '', $word));
244 // -------------------------------------------------------------------
246 $show['getattachments'] = ((can_perform('cangetattach', $bug['productid']) OR can_perform('caneditattach', $bug['productid'])) ? true : false);
247 $show['putattachments'] = ((can_perform('canputattach', $bug['productid']) OR can_perform('caneditattach', $bug['productid'])) ? true : false);
248 $show['attachments'] = ($show['getattachments'] OR $show['putattachments']) ? true : false;
250 if ($show['getattachments'] OR $show['putattachments'])
252 $attachments_fetch = $db->query("
253 SELECT attachment
.attachmentid
, attachment
.filename
,
254 attachment
.description
, attachment
.dateline
,
255 attachment
.userid
, attachment
.obsolete
, user
.email
,
256 user
.showemail
, user
.displayname
257 FROM
" . TABLE_PREFIX . "attachment
AS attachment
258 LEFT JOIN
" . TABLE_PREFIX . "user
AS user
259 ON (attachment
.userid
= user
.userid
)
260 WHERE attachment
.bugid
= $bug[bugid
]
261 ORDER BY attachment
.dateline
"
265 while ($attachment = $db->fetch_array($attachments_fetch))
268 $show['editattach'] = ((can_perform('caneditattach', $bug['productid']) OR ($attachment['userid'] == $bugsys->userinfo['userid'] AND can_perform('canputattach', $bug['productid']))) ? true : false);
269 $attachment['date'] = $datef->format($bugsys->options['dateformat'], $attachment['dateline']);
270 $attachment['user'] = construct_user_display($attachment, false);
271 eval('$attachments .= "' . $template->fetch('showreport_attachment
') . '";');
274 $show['attachments'] = (!$show['putattachments'] AND !$attaches) ? false : true;
277 // -------------------------------------------------------------------
280 $vote = $db->query_first("SELECT
*, FIND_IN_SET(" . $bugsys->userinfo['userid'] . ", userids
) AS uservote FROM
" . TABLE_PREFIX . "vote WHERE bugid
= $bug[bugid
]");
282 $vote['total'] = $vote['votefor'] + $vote['voteagainst'];
283 if ($vote['total'] != 0)
285 $vote['forpercent'] = round($vote['votefor'] / $vote['total'], 3) * 100;
286 $vote['againstpercent'] = round($vote['voteagainst'] / $vote['total'], 3) * 100;
290 $vote['forpercent'] = 0;
291 $vote['againstpercent'] = 0;
294 $show['vote'] = ((can_perform('canvote', $bug['productid']) AND !$vote['uservote']) ? true : false);
298 // -------------------------------------------------------------------
301 $lookupfields = array(
302 'status' => 'status',
303 'priority' => 'priority',
304 'severity' => 'severity',
305 'resolution' => 'resolution',
306 'version' => 'version',
307 'product' => 'title',
308 'component' => 'title'
311 $customfield_logs = $db->query("
312 SELECT bugfield
.*, MAX(permission
.mask
) AS mask
313 FROM
" . TABLE_PREFIX . "bugfield
AS bugfield
314 LEFT JOIN
" . TABLE_PREFIX . "bugfieldpermission
AS permission
315 ON (bugfield
.fieldid
= permission
.fieldid
)
317 AND permission
.usergroupid
IN ({$bugsys
->userinfo
['usergroupid']}" . (sizeof($bugsys->userinfo['groupids']) != 0 ? ',' . implode(',', $bugsys->userinfo['groupids']) : '') . ")
318 GROUP
BY (bugfield
.fieldid
)"
321 while ($field = $db->fetch_array($customfield_logs))
323 $fieldlist["$field[fieldid
]"] = sprintf(T('Custom Field %1$s (%2$s)'), $field['fieldid'], $field['name']);
327 $logs_fetch = $db->query("
328 SELECT history
.*, user
.userid
, user
.email
, user
.displayname
, user
.showemail
329 FROM
" . TABLE_PREFIX . "history
AS history
330 LEFT JOIN
" . TABLE_PREFIX . "user
AS user
331 ON (user
.userid
= history
.userid
)
332 WHERE bugid
= $bug[bugid
]"
334 while ($log = $db->fetch_array($logs_fetch))
336 $log['date'] = $datef->format($bugsys->options['dateformat'], $log['dateline']);
337 $log['user'] = construct_user_display($log);
339 $logs["$log[dateline
]"]["$log[historyid
]"] = $log;
340 ksort($logs["$log[dateline
]"]);
348 foreach ($logs AS $dateline => $logitems)
350 $show['group'] = true;
352 foreach ($logitems AS $log)
354 if ($log['field'] == '.' OR ($log['original'] == '' AND $log['changed'] == ''))
356 $toKill[] = $log['historyid'];
360 if (preg_match('#^(comment|attachment)\.(.*)#', $log['field'], $matches))
362 if ($matches[1] == 'comment')
364 $log['field'] = sprintf(T('Comment #%1$s %2$s'), $log['commentid'], ucwords($matches[2]));
366 else if ($matches[1] == 'attachment')
368 $log['field'] = sprintf(T('Attachment #2%1$s %2$s'), $log['attachmentid'], ucwords($matches[2]));
371 else if (preg_match('#^.?custom(.field)?([0-9]+?)#', $log['field'], $matches))
373 if ($fieldlist["$matches[2]"])
375 $log['field'] = $fieldlist["$matches[2]"];
382 else if (preg_match('#^\.(.*)#', $log['field'], $matches))
384 $log['field'] = ucwords($matches[1]);
386 if (isset($lookupfields["$matches[1]"]))
388 $lookup = $matches[1];
389 $log['original'] = bugdar::$datastore["$lookup"]["$log[original]"][ $lookupfields["$lookup"] ];
390 $log['changed'] = bugdar::$datastore["$lookup"]["$log[changed]"][ $lookupfields["$lookup"] ];
392 else if ($matches[1] == 'assignto' OR $matches[1] == 'assignedto')
394 if ($log['original'])
396 if (!$logusers[$log['original']])
398 $user = new UserAPI($bugsys);
399 $user->set('userid', $log['original']);
400 $user->set_condition();
402 $logusers[$log['original']] = construct_user_display($user->objdata);
404 $log['original'] = $logusers[$log['original']];
409 if (!$logusers[$log['changed']])
411 $user = new UserAPI($bugsys);
412 $user->set('userid', $log['changed']);
413 $user->set_condition();
415 $logusers[$log['changed']] = construct_user_display($user->objdata);
417 $log['changed'] = $logusers[$log['changed']];
422 $funct->exec_swap_bg('', 'altcolor');
423 $bgcolor = $funct->bgcolour;
425 eval('$BUGITEMS[$dateline] .= "' . $template->fetch('history_bit
') . '";');
426 $show['group'] = false;
430 // we can now remove all useless logs
431 if (sizeof($toKill) > 0)
433 $db->query("DELETE FROM
" . TABLE_PREFIX . "history WHERE historyid
IN (" . implode(',', $toKill) . ")");
436 // -------------------------------------------------------------------
438 $comments_fetch = $db->query("
439 SELECT comment
.*, user
.email
, user
.showemail
, user
.displayname
440 FROM
" . TABLE_PREFIX . "comment
AS comment
441 LEFT JOIN
" . TABLE_PREFIX . "user
AS user
442 ON (comment
.userid
= user
.userid
)
443 WHERE comment
.bugid
= $bug[bugid
]" . (!can_perform('canviewhidden', $bug['productid']) ? "
444 AND !hidden
" : '') . "
445 ORDER BY comment
.dateline ASC
"
448 while ($comment = $db->fetch_array($comments_fetch))
450 $comment['posttime'] = $datef->format($bugsys->options['dateformat'], $comment['dateline']);
451 $comment['postby'] = construct_user_display($comment);
452 $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']));
454 $bugsys->debug('can edit own replies: ' . (int)(can_perform('caneditownreply', $bug['productid']) AND $bugsys->userinfo['userid'] == $comment['userid']));
455 $bugsys->debug('can edit other replies:' . (int)(can_perform('caneditotherreply', $bug['productid']) AND $bugsys->userinfo['userid'] != $comment['userid']));
456 $bugsys->debug('$show[editcomment]: ' . $show['editcomment']);
458 if (is_array($hilight))
460 foreach ($hilight AS $id => $find)
462 $find = "#($find)#i";
463 $replace = "<span style=\"background-color: yellow; font-weight: bold; color: red;\">\\1</span>";
464 $comment['comment_parsed'] = preg_replace($find, $replace, $comment['comment_parsed']);
468 eval('$temp = "' . $template->fetch('showreport_comment') . '";');
469 if ($description == null)
471 $description = $temp;
476 $BUGITEMS[$comment['dateline']] = $temp . $BUGITEMS[$comment['dateline']];
480 $show['newreply'] = (can_perform('canpostcomments', $bug['productid']) ? true : false);
482 $bug['summary_title'] = $bug['summary'];
483 if (is_array($hilight) AND !$show['edit'])
485 foreach ($hilight AS $id => $find)
487 $find = "#($find)#i";
488 $replace = "<span style=\"background-color: yellow; font-weight: bold; color: red;\">\\1</span>";
489 $bug['summary'] = preg_replace($find, $replace, $bug['summary']);
494 $BUGITEMS = implode("\n", $BUGITEMS);
496 eval('$template->flush("' . $template->fetch('showreport') . '");');