Integrate bug history directly into showreport.php.
authorRobert Sesek <rsesek@bluestatic.org>
Mon, 6 Apr 2020 05:56:55 +0000 (01:56 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Sat, 11 Apr 2020 04:55:36 +0000 (00:55 -0400)
This makes showhistory.php just redirect to the report.

showhistory.php
showreport.php
templates/history.tpl [deleted file]
templates/history_bit.tpl
templates/showreport.tpl

index d46bc8702709813f0335d8d6a1316d1815bcc274..85fd3cc6bf0003c723811a9c1dca38db0a9ba020 100644 (file)
@@ -30,146 +30,4 @@ $focus['showreport'] = 'focus';
 require_once('./global.php');
 require_once('./includes/api_user.php');
 
-$bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . $bugsys->input_clean('bugid', TYPE_UINT));
-if (!$bug)
-{
-       $message->error(L_INVALID_ID);
-}
-
-if (!check_bug_permissions($bug))
-{
-       $message->errorPermission();
-}
-
-$lookupfields = array(
-       'status'                => 'status',
-       'priority'              => 'priority',
-       'severity'              => 'severity',
-       'resolution'    => 'resolution',
-       'version'               => 'version',
-       'product'               => 'title',
-       'component'             => 'title'
-);
-
-// ###################################################################
-
-$customfields = $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($customfields))
-{
-       $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();
-
-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'])
-                               {
-                                       $user = new UserAPI($bugsys);
-                                       $user->set('userid', $log['original']);
-                                       $user->set_condition();
-                                       $user->fetch();
-                                       $log['original'] = construct_user_display($user->objdata);
-                               }
-                               
-                               if ($log['changed'])
-                               {
-                                       $user = new UserAPI($bugsys);
-                                       $user->set('userid', $log['changed']);
-                                       $user->set_condition();
-                                       $user->fetch();
-                                       $log['changed'] = construct_user_display($user->objdata);
-                               }
-                       }
-               }
-               
-               $funct->exec_swap_bg('', 'altcolor');
-               $bgcolor = $funct->bgcolour;
-               
-               eval('$history .= "' . $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) . ")");
-}
-
-eval('$template->flush("' . $template->fetch('history') . '");');
-
+header('Location: showreport.php?bugid=' . $bugsys->input_clean('bugid', TYPE_UINT));
index 49f9491b351890c40085be8fb6d0fb40cd743312..989dd26629f611546d1b2334a488ba715080e062 100644 (file)
@@ -23,6 +23,7 @@ $fetchtemplates = array(
        'showreport',
        'showreport_attachment',
        'showreport_comment',
+       'history_bit',
        'quicksearch',
        'bugfield_static_text'
 );
@@ -292,6 +293,137 @@ else
 
 $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();
+
+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'])
+                               {
+                                       $user = new UserAPI($bugsys);
+                                       $user->set('userid', $log['original']);
+                                       $user->set_condition();
+                                       $user->fetch();
+                                       $log['original'] = construct_user_display($user->objdata);
+                               }
+
+                               if ($log['changed'])
+                               {
+                                       $user = new UserAPI($bugsys);
+                                       $user->set('userid', $log['changed']);
+                                       $user->set_condition();
+                                       $user->fetch();
+                                       $log['changed'] = construct_user_display($user->objdata);
+                               }
+                       }
+               }
+
+               $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("
@@ -332,6 +464,7 @@ while ($comment = $db->fetch_array($comments_fetch))
        else
        {
                $comments .= $temp;
+               $BUGITEMS[$comment['dateline']] = $temp . $BUGITEMS[$comment['dateline']];
        }
 }
 
@@ -348,5 +481,8 @@ if (is_array($hilight) AND !$show['edit'])
        }
 }
 
+ksort($BUGITEMS);
+$BUGITEMS = implode("\n", $BUGITEMS);
+
 eval('$template->flush("' . $template->fetch('showreport') . '");');
 
diff --git a/templates/history.tpl b/templates/history.tpl
deleted file mode 100644 (file)
index 88add76..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-$doctype
-<html xmlns="http://www.w3.org/1999/xhtml" lang="$stylevar[lang]" xml:lang="$stylevar[lang]" dir="$stylevar[lang_dir]">
-<head>
-$headinclude
-       <title>{@"Bug History"} - $bug[summary]</title>
-</head>
-
-<body>
-
-$header
-
-<h2><lang 1="$bug[summary]" 2="$bug[bugid]">{@"History for <a href="showreport.php?bugid=%2$d"><em>%1$s</em></a> (bugid: %2$s)"}</lang></h2>
-
-<table class="table">
-<tr class="listinghead">
-       <td>{@"User"}</td>
-       <td>{@"Date"}</td>
-       <td>{@"Field"}</td>
-       <td>{@"Old Value"}</td>
-       <td>{@"New Value"}</td>
-</tr>
-$history
-</table>
-
-$footer
\ No newline at end of file
index 599b25ce5546610b2db46f47b4537f4ead5cf3a1..e87be81322b1920bc2918ccfdb7ef1d985e42cbb 100644 (file)
@@ -1,7 +1,3 @@
-<tr style="vertical-align: top"<if condition="$bgcolor"> class="$bgcolor"</if>>
-       <td width="10%"><if condition="$show['group']">$log[user]<else />&nbsp;</if></td>
-       <td width="20%"><if condition="$show['group']">$log[date]<else />&nbsp;</if></td>
-       <td width="20%">$log[field]</td>
-       <td width="25%">$log[original]</td>
-       <td width="25%">$log[changed]</td>
-</tr>
+<div class="history">
+  <if condition="$show['group']">$log[user] changed </if>$log[field] from "$log[original]" to "$log[changed]".
+</div>
index 392675bad98278a06668e77cd2726edc40a5529a..0ec46ea2c7a8aa817794b78df8f5de77ed326357 100644 (file)
@@ -34,7 +34,6 @@ $header
                                        <if condition="$bug['hidden']"> / <span class="error">{@"Hidden Bug"}</span></if>
                                </if>
 
-                               / [<a href="showhistory.php?bugid=$bug[bugid]">{@"Show Bug History"}</a>]
                                <if condition="$show['subscribe']">/ [<a href="favorite.php?do=handle&amp;bugid=$bug[bugid]">$favoritetext</a>]</if>
                                <if condition="$show['delete']">/ [<a href="editreport.php?do=delete&amp;bugid=$bug[bugid]">{@"Delete"}</a>]</if>
                        </div>
@@ -268,6 +267,6 @@ $header
 
 $description
 
-$comments
+$BUGITEMS
 
 $footer