[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/core/ -> summary_api.php (source)

   1  <?php
   2  # MantisBT - A PHP based bugtracking system
   3  
   4  # MantisBT is free software: you can redistribute it and/or modify
   5  # it under the terms of the GNU General Public License as published by
   6  # the Free Software Foundation, either version 2 of the License, or
   7  # (at your option) any later version.
   8  #
   9  # MantisBT is distributed in the hope that it will be useful,
  10  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  # GNU General Public License for more details.
  13  #
  14  # You should have received a copy of the GNU General Public License
  15  # along with MantisBT.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Summary API
  19   *
  20   * @package CoreAPI
  21   * @subpackage SummaryAPI
  22   * @copyright Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
  23   * @copyright Copyright (C) 2002 - 2011  MantisBT Team - mantisbt-dev@lists.sourceforge.net
  24   * @link http://www.mantisbt.org
  25   *
  26   * @uses access_api.php
  27   * @uses authentication_api.php
  28   * @uses bug_api.php
  29   * @uses config_api.php
  30   * @uses constant_inc.php
  31   * @uses current_user_api.php
  32   * @uses database_api.php
  33   * @uses filter_constants_inc.php
  34   * @uses helper_api.php
  35   * @uses project_api.php
  36   * @uses string_api.php
  37   * @uses user_api.php
  38   * @uses utility_api.php
  39   */
  40  
  41  require_api( 'access_api.php' );
  42  require_api( 'authentication_api.php' );
  43  require_api( 'bug_api.php' );
  44  require_api( 'config_api.php' );
  45  require_api( 'constant_inc.php' );
  46  require_api( 'current_user_api.php' );
  47  require_api( 'database_api.php' );
  48  require_api( 'filter_constants_inc.php' );
  49  require_api( 'helper_api.php' );
  50  require_api( 'project_api.php' );
  51  require_api( 'string_api.php' );
  52  require_api( 'user_api.php' );
  53  require_api( 'utility_api.php' );
  54  
  55  function summary_helper_print_row( $p_label, $p_open, $p_resolved, $p_closed, $p_total ) {
  56      printf( '<tr %s>', helper_alternate_class() );
  57      printf( '<td width="50%%">%s</td>', string_display_line( $p_label ) );
  58      printf( '<td width="12%%" class="right">%s</td>', $p_open );
  59      printf( '<td width="12%%" class="right">%s</td>', $p_resolved );
  60      printf( '<td width="12%%" class="right">%s</td>', $p_closed );
  61      printf( '<td width="12%%" class="right">%s</td>', $p_total );
  62      print( '</tr>' );
  63  }
  64  
  65  # Used in summary reports
  66  # this function prints out the summary for the given enum setting
  67  # The enum field name is passed in through $p_enum
  68  function summary_print_by_enum( $p_enum ) {
  69      $t_project_id = helper_get_current_project();
  70      $t_user_id = auth_get_current_user_id();
  71  
  72      $t_project_filter = helper_project_specific_where( $t_project_id );
  73      if( ' 1<>1' == $t_project_filter ) {
  74          return;
  75      }
  76  
  77      $t_filter_prefix = config_get( 'bug_count_hyperlink_prefix' );
  78  
  79      $t_mantis_bug_table = db_get_table( 'bug' );
  80      $t_status_query = ( 'status' == $p_enum ) ? '' : ' ,status ';
  81      $query = "SELECT COUNT(id) as bugcount, $p_enum $t_status_query
  82                  FROM $t_mantis_bug_table
  83                  WHERE $t_project_filter
  84                  GROUP BY $p_enum $t_status_query
  85                  ORDER BY $p_enum $t_status_query";
  86      $result = db_query( $query );
  87  
  88      $t_last_value = -1;
  89      $t_bugs_open = 0;
  90      $t_bugs_resolved = 0;
  91      $t_bugs_closed = 0;
  92      $t_bugs_total = 0;
  93  
  94      $t_resolved_val = config_get( 'bug_resolved_status_threshold' );
  95      $t_closed_val = config_get( 'bug_closed_status_threshold' );
  96  
  97      while( $row = db_fetch_array( $result ) ) {
  98          if(( $row[$p_enum] != $t_last_value ) && ( -1 != $t_last_value ) ) {
  99  
 100              # Build up the hyperlinks to bug views
 101              $t_bug_link = '';
 102              switch( $p_enum ) {
 103                  case 'status':
 104                      $t_bug_link = '<a class="subtle" href="' . $t_filter_prefix . '&amp;' . FILTER_PROPERTY_STATUS . '=' . $t_last_value;
 105                      break;
 106                  case 'severity':
 107                      $t_bug_link = '<a class="subtle" href="' . $t_filter_prefix . '&amp;' . FILTER_PROPERTY_SEVERITY . '=' . $t_last_value;
 108                      break;
 109                  case 'resolution':
 110                      $t_bug_link = '<a class="subtle" href="' . $t_filter_prefix . '&amp;' . FILTER_PROPERTY_RESOLUTION . '=' . $t_last_value;
 111                      break;
 112                  case 'priority':
 113                      $t_bug_link = '<a class="subtle" href="' . $t_filter_prefix . '&amp;' . FILTER_PROPERTY_PRIORITY . '=' . $t_last_value;
 114                      break;
 115              }
 116  
 117              if( !is_blank( $t_bug_link ) ) {
 118                  if( 0 < $t_bugs_open ) {
 119                      $t_bugs_open = $t_bug_link . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=' . $t_resolved_val . '">' . $t_bugs_open . '</a>';
 120                  } else {
 121                      if(( 'status' == $p_enum ) && ( $t_last_value >= $t_resolved_val ) ) {
 122                          $t_bugs_open = '-';
 123                      }
 124                  }
 125                  if( 0 < $t_bugs_resolved ) {
 126                      $t_bugs_resolved = $t_bug_link . '&amp;' . FILTER_PROPERTY_STATUS . '=' . $t_resolved_val . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=' . $t_closed_val . '">' . $t_bugs_resolved . '</a>';
 127                  } else {
 128                      if(( 'status' == $p_enum ) && (( $t_last_value < $t_resolved_val ) || ( $t_last_value >= $t_closed_val ) ) ) {
 129                          $t_bugs_resolved = '-';
 130                      }
 131                  }
 132                  if( 0 < $t_bugs_closed ) {
 133                      $t_bugs_closed = $t_bug_link . '&amp;' . FILTER_PROPERTY_STATUS . '=' . $t_closed_val . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=">' . $t_bugs_closed . '</a>';
 134                  } else {
 135                      if(( 'status' == $p_enum ) && ( $t_last_value < $t_closed_val ) ) {
 136                          $t_bugs_closed = '-';
 137                      }
 138                  }
 139                  if( 0 < $t_bugs_total ) {
 140                      $t_bugs_total = $t_bug_link . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=">' . $t_bugs_total . '</a>';
 141                  }
 142              }
 143  
 144              summary_helper_print_row( get_enum_element( $p_enum, $t_last_value ), $t_bugs_open, $t_bugs_resolved, $t_bugs_closed, $t_bugs_total );
 145  
 146              $t_bugs_open = 0;
 147              $t_bugs_resolved = 0;
 148              $t_bugs_closed = 0;
 149              $t_bugs_total = 0;
 150          }
 151  
 152          $t_bugs_total += $row['bugcount'];
 153          if( $t_closed_val <= $row['status'] ) {
 154              $t_bugs_closed += $row['bugcount'];
 155          }
 156          else if( $t_resolved_val <= $row['status'] ) {
 157              $t_bugs_resolved += $row['bugcount'];
 158          } else {
 159              $t_bugs_open += $row['bugcount'];
 160          }
 161          $t_last_value = $row[$p_enum];
 162      }
 163  
 164      if( 0 < $t_bugs_total ) {
 165          # Build up the hyperlinks to bug views
 166          $t_bug_link = '';
 167          switch( $p_enum ) {
 168              case 'status':
 169                  $t_bug_link = '<a class="subtle" href="' . $t_filter_prefix . '&amp;' . FILTER_PROPERTY_STATUS . '=' . $t_last_value;
 170                  break;
 171              case 'severity':
 172                  $t_bug_link = '<a class="subtle" href="' . $t_filter_prefix . '&amp;' . FILTER_PROPERTY_SEVERITY . '=' . $t_last_value;
 173                  break;
 174              case 'resolution':
 175                  $t_bug_link = '<a class="subtle" href="' . $t_filter_prefix . '&amp;' . FILTER_PROPERTY_RESOLUTION . '=' . $t_last_value;
 176                  break;
 177              case 'priority':
 178                  $t_bug_link = '<a class="subtle" href="' . $t_filter_prefix . '&amp;' . FILTER_PROPERTY_PRIORITY . '=' . $t_last_value;
 179                  break;
 180          }
 181  
 182          if( !is_blank( $t_bug_link ) ) {
 183              if( 0 < $t_bugs_open ) {
 184                  $t_bugs_open = $t_bug_link . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=' . $t_resolved_val . '">' . $t_bugs_open . '</a>';
 185              } else {
 186                  if(( 'status' == $p_enum ) && ( $t_last_value >= $t_resolved_val ) ) {
 187                      $t_bugs_open = '-';
 188                  }
 189              }
 190              if( 0 < $t_bugs_resolved ) {
 191                  $t_bugs_resolved = $t_bug_link . '&amp;' . FILTER_PROPERTY_STATUS . '=' . $t_resolved_val . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=' . $t_closed_val . '">' . $t_bugs_resolved . '</a>';
 192              } else {
 193                  if(( 'status' == $p_enum ) && (( $t_last_value < $t_resolved_val ) || ( $t_last_value >= $t_closed_val ) ) ) {
 194                      $t_bugs_resolved = '-';
 195                  }
 196              }
 197              if( 0 < $t_bugs_closed ) {
 198                  $t_bugs_closed = $t_bug_link . '&amp;' . FILTER_PROPERTY_STATUS . '=' . $t_closed_val . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=">' . $t_bugs_closed . '</a>';
 199              } else {
 200                  if(( 'status' == $p_enum ) && ( $t_last_value < $t_closed_val ) ) {
 201                      $t_bugs_closed = '-';
 202                  }
 203              }
 204              if( 0 < $t_bugs_total ) {
 205                  $t_bugs_total = $t_bug_link . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=">' . $t_bugs_total . '</a>';
 206              }
 207          }
 208  
 209          summary_helper_print_row( get_enum_element( $p_enum, $t_last_value ), $t_bugs_open, $t_bugs_resolved, $t_bugs_closed, $t_bugs_total );
 210      }
 211  }
 212  
 213  # prints the bugs submitted in the last X days (default is 1 day) for the
 214  # current project
 215  function summary_new_bug_count_by_date( $p_time_length = 1 ) {
 216      $t_mantis_bug_table = db_get_table( 'bug' );
 217  
 218      $c_time_length = (int) $p_time_length * SECONDS_PER_DAY;
 219  
 220      $t_project_id = helper_get_current_project();
 221      $t_user_id = auth_get_current_user_id();
 222  
 223      $specific_where = helper_project_specific_where( $t_project_id );
 224      if( ' 1<>1' == $specific_where ) {
 225          return;
 226      }
 227  
 228      $query = "SELECT COUNT(*)
 229                  FROM $t_mantis_bug_table
 230                  WHERE " . db_helper_compare_days( "" . db_now() . "", "date_submitted", "<= $c_time_length" ) . " AND $specific_where";
 231      $result = db_query_bound( $query );
 232      return db_result( $result, 0 );
 233  }
 234  
 235  # returns the number of bugs resolved in the last X days (default is 1 day) for the
 236  # current project
 237  function summary_resolved_bug_count_by_date( $p_time_length = 1 ) {
 238      $t_bug_table = db_get_table( 'bug' );
 239      $t_bug_history_table = db_get_table( 'bug_history' );
 240      $t_resolved = config_get( 'bug_resolved_status_threshold' );
 241  
 242      $c_time_length = (int) $p_time_length * SECONDS_PER_DAY;
 243  
 244      $t_project_id = helper_get_current_project();
 245      $t_user_id = auth_get_current_user_id();
 246  
 247      $specific_where = helper_project_specific_where( $t_project_id );
 248      if( ' 1<>1' == $specific_where ) {
 249          return;
 250      }
 251  
 252      $query = "SELECT COUNT(DISTINCT(b.id))
 253                  FROM $t_bug_table b
 254                  LEFT JOIN $t_bug_history_table h
 255                  ON b.id = h.bug_id
 256                  AND h.type = " . NORMAL_TYPE . "
 257                  AND h.field_name = 'status'
 258                  WHERE b.status >= " . db_param() . "
 259                  AND h.old_value < " . db_param() . "
 260                  AND h.new_value >= " . db_param() . "
 261                  AND " . db_helper_compare_days( "" . db_now() . "", "date_modified", "<= $c_time_length" ) . "
 262                  AND $specific_where";
 263      $result = db_query_bound( $query, Array( $t_resolved, $t_resolved, $t_resolved ) );
 264      return db_result( $result, 0 );
 265  }
 266  
 267  # This function shows the number of bugs submitted in the last X days
 268  # An array of integers representing days is passed in
 269  function summary_print_by_date( $p_date_array ) {
 270      $arr_count = count( $p_date_array );
 271      foreach( $p_date_array as $t_days ) {
 272          $t_new_count = summary_new_bug_count_by_date( $t_days );
 273          $t_resolved_count = summary_resolved_bug_count_by_date( $t_days );
 274  
 275          $t_start_date = mktime( 0, 0, 0, date( 'm' ), ( date( 'd' ) - $t_days ), date( 'Y' ) );
 276          $t_new_bugs_link = '<a class="subtle" href="' . config_get( 'bug_count_hyperlink_prefix' ) . '&amp;' . FILTER_PROPERTY_FILTER_BY_DATE . '=on&amp;' . FILTER_PROPERTY_START_YEAR . '=' . date( 'Y', $t_start_date ) . '&amp;' . FILTER_PROPERTY_START_MONTH . '=' . date( 'm', $t_start_date ) . '&amp;' . FILTER_PROPERTY_START_DAY . '=' . date( 'd', $t_start_date ) . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=">';
 277  
 278          print( "<tr " . helper_alternate_class() . ">\n" );
 279          print( "    <td width=\"50%\">" . $t_days . "</td>\n" );
 280  
 281          if( $t_new_count > 0 ) {
 282              print( "    <td class=\"right\">$t_new_bugs_link$t_new_count</a></td>\n" );
 283          } else {
 284              print( "    <td class=\"right\">$t_new_count</td>\n" );
 285          }
 286          print( "    <td class=\"right\">$t_resolved_count</td>\n" );
 287  
 288          $t_balance = $t_new_count - $t_resolved_count;
 289          $t_style = '';
 290          if( $t_balance > 0 ) {
 291  
 292              # we are talking about bugs: a balance > 0 is "negative" for the project...
 293              $t_style = " negative";
 294              $t_balance = sprintf( '%+d', $t_balance );
 295  
 296              # "+" modifier added in PHP >= 4.3.0
 297          }
 298          else if( $t_balance < 0 ) {
 299              $t_style = ' positive';
 300              $t_balance = sprintf( '%+d', $t_balance );
 301          }
 302  
 303          print( "\n<td class=\"right$t_style\">$t_balance</td>\n" );
 304          print( "</tr>\n" );
 305      }
 306  
 307      # end foreach
 308  }
 309  
 310  # Print list of open bugs with the highest activity score
 311  # the score is calculated assigning one "point" for each history event
 312  # associated with the bug
 313  function summary_print_by_activity() {
 314      $t_mantis_bug_table = db_get_table( 'bug' );
 315      $t_mantis_history_table = db_get_table( 'bug_history' );
 316  
 317      $t_project_id = helper_get_current_project();
 318      $t_user_id = auth_get_current_user_id();
 319      $t_resolved = config_get( 'bug_resolved_status_threshold' );
 320  
 321      $specific_where = helper_project_specific_where( $t_project_id );
 322      if( ' 1<>1' == $specific_where ) {
 323          return;
 324      }
 325      $query = "SELECT COUNT(h.id) as count, b.id, b.summary, b.view_state
 326                  FROM $t_mantis_bug_table b, $t_mantis_history_table h
 327                  WHERE h.bug_id = b.id
 328                  AND b.status < " . db_param() . "
 329                  AND $specific_where
 330                  GROUP BY h.bug_id, b.id, b.summary, b.last_updated, b.view_state
 331                  ORDER BY count DESC, b.last_updated DESC";
 332      $result = db_query_bound( $query, Array( $t_resolved ) );
 333  
 334      $t_count = 0;
 335      $t_private_bug_threshold = config_get( 'private_bug_threshold' );
 336      $t_summarydata = Array();
 337      $t_summarybugs = Array();
 338      while( $row = db_fetch_array( $result ) ) {
 339  
 340          // Skip private bugs unless user has proper permissions
 341          if(( VS_PRIVATE == $row['view_state'] ) && ( false == access_has_bug_level( $t_private_bug_threshold, $row['id'] ) ) ) {
 342              continue;
 343          }
 344  
 345          if( $t_count++ == 10 ) {
 346              break;
 347          }
 348  
 349          $t_summarydata[] = array(
 350              'id' => $row['id'],
 351              'summary' => $row['summary'],
 352              'count' => $row['count'],
 353          );
 354          $t_summarybugs[] = $row['id'];
 355      }
 356  
 357      bug_cache_array_rows( $t_summarybugs );
 358  
 359      foreach( $t_summarydata as $row ) {
 360          $t_bugid = string_get_bug_view_link( $row['id'] );
 361          $t_summary = string_display_line( $row['summary'] );
 362          $t_notescount = $row['count'];
 363  
 364          print "<tr " . helper_alternate_class() . ">\n";
 365          print "<td class=\"small\">$t_bugid - $t_summary</td><td class=\"right\">$t_notescount</td>\n";
 366          print "</tr>\n";
 367      }
 368  }
 369  
 370  # Print list of bugs opened from the longest time
 371  function summary_print_by_age() {
 372      $t_mantis_bug_table = db_get_table( 'bug' );
 373  
 374      $t_project_id = helper_get_current_project();
 375      $t_user_id = auth_get_current_user_id();
 376      $t_resolved = config_get( 'bug_resolved_status_threshold' );
 377  
 378      $specific_where = helper_project_specific_where( $t_project_id );
 379      if( ' 1<>1' == $specific_where ) {
 380          return;
 381      }
 382      $query = "SELECT * FROM $t_mantis_bug_table
 383                  WHERE status < $t_resolved
 384                  AND $specific_where
 385                  ORDER BY date_submitted ASC, priority DESC";
 386      $result = db_query( $query );
 387  
 388      $t_count = 0;
 389      $t_private_bug_threshold = config_get( 'private_bug_threshold' );
 390      while( $row = db_fetch_array( $result ) ) {
 391  
 392          // as we select all from bug_table, inject into the cache.
 393          bug_cache_database_result( $row );
 394  
 395          // Skip private bugs unless user has proper permissions
 396          if(( VS_PRIVATE == bug_get_field( $row['id'], 'view_state' ) ) && ( false == access_has_bug_level( $t_private_bug_threshold, $row['id'] ) ) ) {
 397              continue;
 398          }
 399  
 400          if( $t_count++ == 10 ) {
 401              break;
 402          }
 403  
 404          $t_bugid = string_get_bug_view_link( $row['id'] );
 405          $t_summary = string_display_line( $row['summary'] );
 406          $t_days_open = intval(( time() - $row['date_submitted'] ) / SECONDS_PER_DAY );
 407  
 408          print "<tr " . helper_alternate_class() . ">\n";
 409          print "<td class=\"small\">$t_bugid - $t_summary</td><td class=\"right\">$t_days_open</td>\n";
 410          print "</tr>\n";
 411      }
 412  }
 413  
 414  # print bug counts by assigned to each developer
 415  function summary_print_by_developer() {
 416      $t_mantis_bug_table = db_get_table( 'bug' );
 417      $t_mantis_user_table = db_get_table( 'user' );
 418  
 419      $t_project_id = helper_get_current_project();
 420      $t_user_id = auth_get_current_user_id();
 421  
 422      $specific_where = helper_project_specific_where( $t_project_id );
 423      if( ' 1<>1' == $specific_where ) {
 424          return;
 425      }
 426  
 427      $query = "SELECT COUNT(id) as bugcount, handler_id, status
 428                  FROM $t_mantis_bug_table
 429                  WHERE handler_id>0 AND $specific_where
 430                  GROUP BY handler_id, status
 431                  ORDER BY handler_id, status";
 432      $result = db_query( $query );
 433  
 434      $t_last_handler = -1;
 435      $t_bugs_open = 0;
 436      $t_bugs_resolved = 0;
 437      $t_bugs_closed = 0;
 438      $t_bugs_total = 0;
 439  
 440      $t_resolved_val = config_get( 'bug_resolved_status_threshold' );
 441      $t_closed_val = config_get( 'bug_closed_status_threshold' );
 442  
 443      $t_summaryusers = array();
 444      $t_summarydata = array();
 445      while( $row = db_fetch_array( $result ) ) {
 446          $t_summarydata[] = $row;
 447          $t_summaryusers[] = $row['handler_id'];
 448      }
 449  
 450      user_cache_array_rows( array_unique( $t_summaryusers ) );
 451  
 452      foreach( $t_summarydata as $row ) {
 453          $v_handler_id = $row['handler_id'];
 454          $v_bugcount = $row['bugcount'];
 455  
 456          if(( $v_handler_id != $t_last_handler ) && ( -1 != $t_last_handler ) ) {
 457              $t_user = string_display_line( user_get_name( $t_last_handler ) );
 458  
 459              $t_bug_link = '<a class="subtle" href="' . config_get( 'bug_count_hyperlink_prefix' ) . '&amp;' . FILTER_PROPERTY_HANDLER_ID . '=' . $t_last_handler;
 460              if( 0 < $t_bugs_open ) {
 461                  $t_bugs_open = $t_bug_link . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=' . $t_resolved_val . '">' . $t_bugs_open . '</a>';
 462              }
 463              if( 0 < $t_bugs_resolved ) {
 464                  $t_bugs_resolved = $t_bug_link . '&amp;' . FILTER_PROPERTY_STATUS . '=' . $t_resolved_val . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=' . $t_closed_val . '">' . $t_bugs_resolved . '</a>';
 465              }
 466              if( 0 < $t_bugs_closed ) {
 467                  $t_bugs_closed = $t_bug_link . '&amp;' . FILTER_PROPERTY_STATUS . '=' . $t_closed_val . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=">' . $t_bugs_closed . '</a>';
 468              }
 469              if( 0 < $t_bugs_total ) {
 470                  $t_bugs_total = $t_bug_link . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=">' . $t_bugs_total . '</a>';
 471              }
 472  
 473              summary_helper_print_row( $t_user, $t_bugs_open, $t_bugs_resolved, $t_bugs_closed, $t_bugs_total );
 474  
 475              $t_bugs_open = 0;
 476              $t_bugs_resolved = 0;
 477              $t_bugs_closed = 0;
 478              $t_bugs_total = 0;
 479          }
 480  
 481          $t_bugs_total += $v_bugcount;
 482          if( $t_closed_val <= $row['status'] ) {
 483              $t_bugs_closed += $v_bugcount;
 484          }
 485          else if( $t_resolved_val <= $row['status'] ) {
 486              $t_bugs_resolved += $v_bugcount;
 487          } else {
 488              $t_bugs_open += $v_bugcount;
 489          }
 490          $t_last_handler = $v_handler_id;
 491      }
 492  
 493      if( 0 < $t_bugs_total ) {
 494          $t_user = string_display_line( user_get_name( $t_last_handler ) );
 495  
 496          $t_bug_link = '<a class="subtle" href="' . config_get( 'bug_count_hyperlink_prefix' ) . '&amp;' . FILTER_PROPERTY_HANDLER_ID . '=' . $t_last_handler;
 497          if( 0 < $t_bugs_open ) {
 498              $t_bugs_open = $t_bug_link . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=' . $t_resolved_val . '">' . $t_bugs_open . '</a>';
 499          }
 500          if( 0 < $t_bugs_resolved ) {
 501              $t_bugs_resolved = $t_bug_link . '&amp;' . FILTER_PROPERTY_STATUS . '=' . $t_resolved_val . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=' . $t_closed_val . '">' . $t_bugs_resolved . '</a>';
 502          }
 503          if( 0 < $t_bugs_closed ) {
 504              $t_bugs_closed = $t_bug_link . '&amp;' . FILTER_PROPERTY_STATUS . '=' . $t_closed_val . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=">' . $t_bugs_closed . '</a>';
 505          }
 506          if( 0 < $t_bugs_total ) {
 507              $t_bugs_total = $t_bug_link . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=">' . $t_bugs_total . '</a>';
 508          }
 509  
 510          summary_helper_print_row( $t_user, $t_bugs_open, $t_bugs_resolved, $t_bugs_closed, $t_bugs_total );
 511      }
 512  }
 513  
 514  # print bug counts by reporter id
 515  function summary_print_by_reporter() {
 516      $t_mantis_bug_table = db_get_table( 'bug' );
 517      $t_mantis_user_table = db_get_table( 'user' );
 518      $t_reporter_summary_limit = config_get( 'reporter_summary_limit' );
 519  
 520      $t_project_id = helper_get_current_project();
 521      $t_user_id = auth_get_current_user_id();
 522  
 523      $specific_where = helper_project_specific_where( $t_project_id );
 524      if( ' 1<>1' == $specific_where ) {
 525          return;
 526      }
 527  
 528      $query = "SELECT reporter_id, COUNT(*) as num
 529                  FROM $t_mantis_bug_table
 530                  WHERE $specific_where
 531                  GROUP BY reporter_id
 532                  ORDER BY num DESC";
 533      $result = db_query( $query, $t_reporter_summary_limit );
 534  
 535      $t_reporters = array();
 536      while( $row = db_fetch_array( $result ) ) {
 537          $t_reporters[] = $row['reporter_id'];
 538      }
 539  
 540      user_cache_array_rows( $t_reporters );
 541  
 542      foreach( $t_reporters as $t_reporter ) {
 543          $v_reporter_id = $t_reporter;
 544          $query = "SELECT COUNT(id) as bugcount, status FROM $t_mantis_bug_table
 545                      WHERE reporter_id=$v_reporter_id
 546                      AND $specific_where
 547                      GROUP BY status
 548                      ORDER BY status";
 549          $result2 = db_query( $query );
 550  
 551          $last_reporter = -1;
 552          $t_bugs_open = 0;
 553          $t_bugs_resolved = 0;
 554          $t_bugs_closed = 0;
 555          $t_bugs_total = 0;
 556  
 557          $t_resolved_val = config_get( 'bug_resolved_status_threshold' );
 558          $t_closed_val = config_get( 'bug_closed_status_threshold' );
 559  
 560          while( $row2 = db_fetch_array( $result2 ) ) {
 561              $t_bugs_total += $row2['bugcount'];
 562              if( $t_closed_val <= $row2['status'] ) {
 563                  $t_bugs_closed += $row2['bugcount'];
 564              }
 565              else if( $t_resolved_val <= $row2['status'] ) {
 566                  $t_bugs_resolved += $row2['bugcount'];
 567              } else {
 568                  $t_bugs_open += $row2['bugcount'];
 569              }
 570          }
 571  
 572          if( 0 < $t_bugs_total ) {
 573              $t_user = string_display_line( user_get_name( $v_reporter_id ) );
 574  
 575              $t_bug_link = '<a class="subtle" href="' . config_get( 'bug_count_hyperlink_prefix' ) . '&amp;' . FILTER_PROPERTY_REPORTER_ID . '=' . $v_reporter_id;
 576              if( 0 < $t_bugs_open ) {
 577                  $t_bugs_open = $t_bug_link . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=' . $t_resolved_val . '">' . $t_bugs_open . '</a>';
 578              }
 579              if( 0 < $t_bugs_resolved ) {
 580                  $t_bugs_resolved = $t_bug_link . '&amp;' . FILTER_PROPERTY_STATUS . '=' . $t_resolved_val . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=' . $t_closed_val . '">' . $t_bugs_resolved . '</a>';
 581              }
 582              if( 0 < $t_bugs_closed ) {
 583                  $t_bugs_closed = $t_bug_link . '&amp;' . FILTER_PROPERTY_STATUS . '=' . $t_closed_val . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=">' . $t_bugs_closed . '</a>';
 584              }
 585              if( 0 < $t_bugs_total ) {
 586                  $t_bugs_total = $t_bug_link . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=">' . $t_bugs_total . '</a>';
 587              }
 588  
 589              summary_helper_print_row( $t_user, $t_bugs_open, $t_bugs_resolved, $t_bugs_closed, $t_bugs_total );
 590          }
 591      }
 592  }
 593  
 594  # print a bug count per category
 595  function summary_print_by_category() {
 596      $t_mantis_bug_table = db_get_table( 'bug' );
 597      $t_mantis_category_table = db_get_table( 'category' );
 598      $t_mantis_project_table = db_get_table( 'project' );
 599      $t_summary_category_include_project = config_get( 'summary_category_include_project' );
 600  
 601      $t_project_id = helper_get_current_project();
 602      $t_user_id = auth_get_current_user_id();
 603  
 604      $specific_where = trim( helper_project_specific_where( $t_project_id ) );
 605      if( '1<>1' == $specific_where ) {
 606          return;
 607      }
 608      $t_project_query = ( ON == $t_summary_category_include_project ) ? 'b.project_id, ' : '';
 609  
 610      $query = "SELECT COUNT(b.id) as bugcount, $t_project_query c.name AS category_name, category_id, b.status
 611                  FROM $t_mantis_bug_table b
 612                  JOIN $t_mantis_category_table c ON b.category_id=c.id
 613                  WHERE b.$specific_where
 614                  GROUP BY $t_project_query category_id, c.name, b.status
 615                  ORDER BY $t_project_query category_id, c.name, b.status";
 616  
 617      $result = db_query( $query );
 618  
 619      $last_category_name = -1;
 620      $last_category_id = -1;
 621      $last_project = -1;
 622      $t_bugs_open = 0;
 623      $t_bugs_resolved = 0;
 624      $t_bugs_closed = 0;
 625      $t_bugs_total = 0;
 626  
 627      $t_resolved_val = config_get( 'bug_resolved_status_threshold' );
 628      $t_closed_val = config_get( 'bug_closed_status_threshold' );
 629  
 630      while( $row = db_fetch_array( $result ) ) {
 631          $v_category_id = $row['category_id'];
 632          $v_category_name = $row['category_name'];
 633  
 634          if(( $v_category_id != $last_category_id ) && ( $last_category_id != -1 ) ) {
 635              $label = $last_category_name;
 636              if(( ON == $t_summary_category_include_project ) && ( ALL_PROJECTS == $t_project_id ) ) {
 637                  $label = sprintf( '[%s] %s', project_get_name( $last_project ), $label );
 638              }
 639  
 640              $t_bug_link = '<a class="subtle" href="' . config_get( 'bug_count_hyperlink_prefix' ) . '&amp;' . FILTER_PROPERTY_CATEGORY_ID . '=' . urlencode( $last_category_name );
 641              if( 0 < $t_bugs_open ) {
 642                  $t_bugs_open = $t_bug_link . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=' . $t_resolved_val . '">' . $t_bugs_open . '</a>';
 643              }
 644              if( 0 < $t_bugs_resolved ) {
 645                  $t_bugs_resolved = $t_bug_link . '&amp;' . FILTER_PROPERTY_STATUS . '=' . $t_resolved_val . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=' . $t_closed_val . '">' . $t_bugs_resolved . '</a>';
 646              }
 647              if( 0 < $t_bugs_closed ) {
 648                  $t_bugs_closed = $t_bug_link . '&amp;' . FILTER_PROPERTY_STATUS . '=' . $t_closed_val . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=">' . $t_bugs_closed . '</a>';
 649              }
 650              if( 0 < $t_bugs_total ) {
 651                  $t_bugs_total = $t_bug_link . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=">' . $t_bugs_total . '</a>';
 652              }
 653  
 654              summary_helper_print_row( $label, $t_bugs_open, $t_bugs_resolved, $t_bugs_closed, $t_bugs_total );
 655  
 656              $t_bugs_open = 0;
 657              $t_bugs_resolved = 0;
 658              $t_bugs_closed = 0;
 659              $t_bugs_total = 0;
 660          }
 661  
 662          $t_bugs_total += $row['bugcount'];
 663          if( $t_closed_val <= $row['status'] ) {
 664              $t_bugs_closed += $row['bugcount'];
 665          }
 666          else if( $t_resolved_val <= $row['status'] ) {
 667              $t_bugs_resolved += $row['bugcount'];
 668          } else {
 669              $t_bugs_open += $row['bugcount'];
 670          }
 671  
 672          $last_category_id = $v_category_id;
 673          $last_category_name = $v_category_name;
 674          if(( ON == $t_summary_category_include_project ) && ( ALL_PROJECTS == $t_project_id ) ) {
 675              $last_project = $row['project_id'];
 676          }
 677      }
 678  
 679      if( 0 < $t_bugs_total ) {
 680          $label = $last_category_name;
 681          if(( ON == $t_summary_category_include_project ) && ( ALL_PROJECTS == $t_project_id ) ) {
 682              $label = sprintf( '[%s] %s', project_get_name( $last_project ), $label );
 683          }
 684  
 685          $t_bug_link = '<a class="subtle" href="' . config_get( 'bug_count_hyperlink_prefix' ) . '&amp;' . FILTER_PROPERTY_CATEGORY_ID . '=' . urlencode( $last_category_name );
 686          if( !is_blank( $t_bug_link ) ) {
 687              if( 0 < $t_bugs_open ) {
 688                  $t_bugs_open = $t_bug_link . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=' . $t_resolved_val . '">' . $t_bugs_open . '</a>';
 689              }
 690              if( 0 < $t_bugs_resolved ) {
 691                  $t_bugs_resolved = $t_bug_link . '&amp;' . FILTER_PROPERTY_STATUS . '=' . $t_resolved_val . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=' . $t_closed_val . '">' . $t_bugs_resolved . '</a>';
 692              }
 693              if( 0 < $t_bugs_closed ) {
 694                  $t_bugs_closed = $t_bug_link . '&amp;' . FILTER_PROPERTY_STATUS . '=' . $t_closed_val . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=">' . $t_bugs_closed . '</a>';
 695              }
 696              if( 0 < $t_bugs_total ) {
 697                  $t_bugs_total = $t_bug_link . '&amp;' . FILTER_PROPERTY_HIDE_STATUS . '=">' . $t_bugs_total . '</a>';
 698              }
 699          }
 700  
 701          summary_helper_print_row( $label, $t_bugs_open, $t_bugs_resolved, $t_bugs_closed, $t_bugs_total );
 702      }
 703  }
 704  
 705  # print bug counts by project
 706  function summary_print_by_project( $p_projects = null, $p_level = 0, $p_cache = null ) {
 707      $t_mantis_bug_table = db_get_table( 'bug' );
 708      $t_mantis_project_table = db_get_table( 'project' );
 709  
 710      $t_project_id = helper_get_current_project();
 711  
 712      if( null == $p_projects ) {
 713          if( ALL_PROJECTS == $t_project_id ) {
 714              $p_projects = current_user_get_accessible_projects();
 715          } else {
 716              $p_projects = Array(
 717                  $t_project_id,
 718              );
 719          }
 720      }
 721  
 722      # Retrieve statistics one time to improve performance.
 723      if( null === $p_cache ) {
 724          $query = "SELECT project_id, status, COUNT( status ) AS bugcount
 725                      FROM $t_mantis_bug_table
 726                      GROUP BY project_id, status";
 727  
 728          $result = db_query_bound( $query );
 729          $p_cache = Array();
 730  
 731          $t_resolved_val = config_get( 'bug_resolved_status_threshold' );
 732          $t_closed_val = config_get( 'bug_closed_status_threshold' );
 733  
 734          while( $row = db_fetch_array( $result ) ) {
 735              $t_project_id = $row['project_id'];
 736              $t_status = $row['status'];
 737              $t_bugcount = $row['bugcount'];
 738  
 739              if ( $t_closed_val <= $t_status ) {
 740                  if ( isset( $p_cache[$t_project_id]['closed'] ) ) {
 741                      $p_cache[$t_project_id]['closed'] += $t_bugcount;
 742                  } else {
 743                      $p_cache[$t_project_id]['closed'] = $t_bugcount;
 744                  }
 745              } else if ( $t_resolved_val <= $t_status ) {
 746                  if ( isset( $p_cache[$t_project_id]['resolved'] ) ) {
 747                      $p_cache[$t_project_id]['resolved'] += $t_bugcount;
 748                  } else {
 749                      $p_cache[$t_project_id]['resolved'] = $t_bugcount;
 750                  }
 751              } else {
 752                  if ( isset( $p_cache[$t_project_id]['open'] ) ) {
 753                      $p_cache[$t_project_id]['open'] += $t_bugcount;
 754                  } else {
 755                      $p_cache[$t_project_id]['open'] = $t_bugcount;
 756                  }
 757              }
 758          }
 759      }
 760  
 761      foreach( $p_projects as $t_project ) {
 762          $t_name = str_repeat( "&raquo; ", $p_level ) . project_get_name( $t_project );
 763  
 764          $t_pdata = isset( $p_cache[$t_project] ) ? $p_cache[$t_project] : array( 'open' => 0, 'resolved' => 0, 'closed' => 0 );
 765  
 766          $t_bugs_open = isset( $t_pdata['open'] ) ? $t_pdata['open'] : 0;
 767          $t_bugs_resolved = isset( $t_pdata['resolved'] ) ? $t_pdata['resolved'] : 0;
 768          $t_bugs_closed = isset( $t_pdata['closed'] ) ? $t_pdata['closed'] : 0;
 769          $t_bugs_total = $t_bugs_open + $t_bugs_resolved + $t_bugs_closed;
 770  
 771          summary_helper_print_row( $t_name, $t_bugs_open, $t_bugs_resolved, $t_bugs_closed, $t_bugs_total );
 772  
 773          if ( count( project_hierarchy_get_subprojects ( $t_project ) ) > 0 ) {
 774              $t_subprojects = current_user_get_accessible_subprojects( $t_project );
 775  
 776              if( count( $t_subprojects ) > 0 ) {
 777                  summary_print_by_project( $t_subprojects, $p_level + 1, $p_cache );
 778              }
 779          }
 780      }
 781  }
 782  
 783  # Print developer / resolution report
 784  function summary_print_developer_resolution( $p_resolution_enum_string ) {
 785      $t_mantis_bug_table = db_get_table( 'bug' );
 786      $t_mantis_user_table = db_get_table( 'user' );
 787  
 788      $t_project_id = helper_get_current_project();
 789      $t_user_id = auth_get_current_user_id();
 790  
 791      # Get the resolution values ot use
 792      $c_res_s = MantisEnum::getValues( $p_resolution_enum_string );
 793      $enum_res_count = count( $c_res_s );
 794  
 795      $specific_where = helper_project_specific_where( $t_project_id );
 796      if( ' 1<>1' == $specific_where ) {
 797          return;
 798      }
 799  
 800      $specific_where .= ' AND handler_id > 0';
 801  
 802      # Get all of the bugs and split them up into an array
 803      $query = "SELECT COUNT(id) as bugcount, handler_id, resolution
 804                  FROM $t_mantis_bug_table
 805                  WHERE $specific_where
 806                  GROUP BY handler_id, resolution
 807                  ORDER BY handler_id, resolution";
 808      $result = db_query_bound( $query );
 809  
 810      $t_handler_res_arr = array();
 811      $t_arr = db_fetch_array( $result );
 812      while( $t_arr ) {
 813          if( !isset( $t_handler_res_arr[$t_arr['handler_id']] ) ) {
 814              $t_handler_res_arr[$t_arr['handler_id']] = array();
 815              $t_handler_res_arr[$t_arr['handler_id']]['total'] = 0;
 816          }
 817          if( !isset( $t_handler_res_arr[$t_arr['handler_id']][$t_arr['resolution']] ) ) {
 818              $t_handler_res_arr[$t_arr['handler_id']][$t_arr['resolution']] = 0;
 819          }
 820          $t_handler_res_arr[$t_arr['handler_id']][$t_arr['resolution']] += $t_arr['bugcount'];
 821          $t_handler_res_arr[$t_arr['handler_id']]['total'] += $t_arr['bugcount'];
 822  
 823          $t_arr = db_fetch_array( $result );
 824      }
 825  
 826      $t_filter_prefix = config_get( 'bug_count_hyperlink_prefix' );
 827      $t_row_count = 0;
 828  
 829      # We now have a multi dimensional array of users and resolutions, with the value of each resolution for each user
 830      foreach( $t_handler_res_arr as $t_handler_id => $t_arr2 ) {
 831  
 832          # Only print developers who have had at least one bug assigned to them. This helps
 833          # prevent divide by zeroes, showing developers not on this project, and showing
 834          # users that aren't actually developers...
 835  
 836          if( $t_arr2['total'] > 0 ) {
 837              echo '<tr ' . helper_alternate_class( $t_row_count ) . '>';
 838              $t_row_count++;
 839              echo '<td>';
 840              echo string_display_line( user_get_name( $t_handler_id ) );
 841              echo '</td>';
 842  
 843              # We need to track the percentage of bugs that are considered fixed, as well as
 844              # those that aren't considered bugs to begin with (when looking at %age)
 845              $t_bugs_fixed = 0;
 846              $t_bugs_notbugs = 0;
 847              for( $j = 0;$j < $enum_res_count;$j++ ) {
 848                  $res_bug_count = 0;
 849  
 850                  if( isset( $t_arr2[$c_res_s[$j]] ) ) {
 851                      $res_bug_count = $t_arr2[$c_res_s[$j]];
 852                  }
 853  
 854                  echo '<td>';
 855                  if( 0 < $res_bug_count ) {
 856                      $t_bug_link = '<a class="subtle" href="' . $t_filter_prefix . '&amp;' . FILTER_PROPERTY_HANDLER_ID . '=' . $t_handler_id;
 857                      $t_bug_link = $t_bug_link . '&amp;' . FILTER_PROPERTY_RESOLUTION . '=' . $c_res_s[$j] . '">';
 858                      echo $t_bug_link . $res_bug_count . '</a>';
 859                  } else {
 860                      echo $res_bug_count;
 861                  }
 862                  echo '</td>';
 863  
 864                  if( $c_res_s[$j] >= config_get( 'bug_resolution_fixed_threshold' ) ) {
 865                      if ( $c_res_s[$j] < config_get( 'bug_resolution_not_fixed_threshold' ) ) {
 866                          # Count bugs with a resolution between fixed and not fixed thresholds
 867                          $t_bugs_fixed += $res_bug_count;
 868                      } else {
 869                          # Count bugs with a resolution above the not fixed threshold
 870                          $t_bugs_notbugs += $res_bug_count;
 871                      }
 872                  }
 873  
 874              }
 875  
 876              $t_percent_fixed = 0;
 877              if(( $t_arr2['total'] - $t_bugs_notbugs ) > 0 ) {
 878                  $t_percent_fixed = ( $t_bugs_fixed / ( $t_arr2['total'] - $t_bugs_notbugs ) );
 879              }
 880              echo '<td>';
 881              printf( '% 1.0f%%', ( $t_percent_fixed * 100 ) );
 882              echo '</td>';
 883              echo '</tr>';
 884          }
 885      }
 886  }
 887  
 888  # Print reporter / resolution report
 889  function summary_print_reporter_resolution( $p_resolution_enum_string ) {
 890      $t_mantis_bug_table = db_get_table( 'bug' );
 891      $t_mantis_user_table = db_get_table( 'user' );
 892      $t_reporter_summary_limit = config_get( 'reporter_summary_limit' );
 893  
 894      $t_project_id = helper_get_current_project();
 895      $t_user_id = auth_get_current_user_id();
 896  
 897      # Get the resolution values ot use
 898      $c_res_s = MantisEnum::getValues( $p_resolution_enum_string );
 899      $enum_res_count = count( $c_res_s );
 900  
 901      # Checking if it's a per project statistic or all projects
 902      $specific_where = helper_project_specific_where( $t_project_id );
 903      if( ' 1<>1' == $specific_where ) {
 904          return;
 905      }
 906  
 907      # Get all of the bugs and split them up into an array
 908      $query = "SELECT COUNT(id) as bugcount, reporter_id, resolution
 909                  FROM $t_mantis_bug_table
 910                  WHERE $specific_where
 911                  GROUP BY reporter_id, resolution";
 912      $result = db_query_bound( $query );
 913  
 914      $t_reporter_res_arr = array();
 915      $t_reporter_bugcount_arr = array();
 916      $t_arr = db_fetch_array( $result );
 917      while( $t_arr ) {
 918          if( !isset( $t_reporter_res_arr[$t_arr['reporter_id']] ) ) {
 919              $t_reporter_res_arr[$t_arr['reporter_id']] = array();
 920              $t_reporter_bugcount_arr[$t_arr['reporter_id']] = 0;
 921          }
 922          if( !isset( $t_reporter_res_arr[$t_arr['reporter_id']][$t_arr['resolution']] ) ) {
 923              $t_reporter_res_arr[$t_arr['reporter_id']][$t_arr['resolution']] = 0;
 924          }
 925          $t_reporter_res_arr[$t_arr['reporter_id']][$t_arr['resolution']] += $t_arr['bugcount'];
 926          $t_reporter_bugcount_arr[$t_arr['reporter_id']] += $t_arr['bugcount'];
 927  
 928          $t_arr = db_fetch_array( $result );
 929      }
 930  
 931      # Sort our total bug count array so that the reporters with the highest number of bugs are listed first,
 932      arsort( $t_reporter_bugcount_arr );
 933  
 934      $t_row_count = 0;
 935  
 936      # We now have a multi dimensional array of users and resolutions, with the value of each resolution for each user
 937      foreach( $t_reporter_bugcount_arr as $t_reporter_id => $t_total_user_bugs ) {
 938  
 939          # Limit the number of reporters listed
 940          if( $t_row_count > $t_reporter_summary_limit ) {
 941              break;
 942          }
 943  
 944          # Only print reporters who have reported at least one bug. This helps
 945          # prevent divide by zeroes, showing reporters not on this project, and showing
 946          # users that aren't actually reporters...
 947          if( $t_total_user_bugs > 0 ) {
 948              $t_arr2 = $t_reporter_res_arr[$t_reporter_id];
 949  
 950              echo '<tr ' . helper_alternate_class( $t_row_count ) . '>';
 951              $t_row_count++;
 952              echo '<td>';
 953              echo string_display_line( user_get_name( $t_reporter_id ) );
 954              echo '</td>';
 955  
 956              # We need to track the percentage of bugs that are considered fix, as well as
 957              # those that aren't considered bugs to begin with (when looking at %age)
 958              $t_bugs_fixed = 0;
 959              $t_bugs_notbugs = 0;
 960              for( $j = 0;$j < $enum_res_count;$j++ ) {
 961                  $res_bug_count = 0;
 962  
 963                  if( isset( $t_arr2[$c_res_s[$j]] ) ) {
 964                      $res_bug_count = $t_arr2[$c_res_s[$j]];
 965                  }
 966  
 967                  echo '<td>';
 968                  if( 0 < $res_bug_count ) {
 969                      $t_bug_link = '<a class="subtle" href="' . config_get( 'bug_count_hyperlink_prefix' ) . '&amp;' . FILTER_PROPERTY_REPORTER_ID . '=' . $t_reporter_id;
 970                      $t_bug_link = $t_bug_link . '&amp;' . FILTER_PROPERTY_RESOLUTION . '=' . $c_res_s[$j] . '">';
 971                      echo $t_bug_link . $res_bug_count . '</a>';
 972                  } else {
 973                      echo $res_bug_count;
 974                  }
 975                  echo '</td>';
 976  
 977                  if( $c_res_s[$j] >= config_get( 'bug_resolution_fixed_threshold' ) ) {
 978                      if ( $c_res_s[$j] < config_get( 'bug_resolution_not_fixed_threshold' ) ) {
 979                          # Count bugs with a resolution between fixed and not fixed thresholds
 980                          $t_bugs_fixed += $res_bug_count;
 981                      } else {
 982                          # Count bugs with a resolution above the not fixed threshold
 983                          $t_bugs_notbugs += $res_bug_count;
 984                      }
 985                  }
 986  
 987              }
 988  
 989              $t_percent_errors = 0;
 990              if( $t_total_user_bugs > 0 ) {
 991                  $t_percent_errors = ( $t_bugs_notbugs / $t_total_user_bugs );
 992              }
 993              echo '<td>';
 994              printf( '% 1.0f%%', ( $t_percent_errors * 100 ) );
 995              echo '</td>';
 996              echo '</tr>';
 997          }
 998      }
 999  }
1000  
1001  # Print reporter effectiveness report
1002  function summary_print_reporter_effectiveness( $p_severity_enum_string, $p_resolution_enum_string ) {
1003      $t_mantis_bug_table = db_get_table( 'bug' );
1004      $t_mantis_user_table = db_get_table( 'user' );
1005      $t_reporter_summary_limit = config_get( 'reporter_summary_limit' );
1006  
1007      $t_project_id = helper_get_current_project();
1008      $t_user_id = auth_get_current_user_id();
1009  
1010      $t_severity_multipliers = config_get( 'severity_multipliers' );
1011      $t_resolution_multipliers = config_get( 'resolution_multipliers' );
1012  
1013      # Get the severity values to use
1014      $c_sev_s = MantisEnum::getValues( $p_severity_enum_string );
1015      $enum_sev_count = count( $c_sev_s );
1016  
1017      # Get the resolution values to use
1018      $c_res_s = MantisEnum::getValues( $p_resolution_enum_string );
1019      $enum_res_count = count( $c_res_s );
1020  
1021      # Checking if it's a per project statistic or all projects
1022      $specific_where = helper_project_specific_where( $t_project_id );
1023      if( ' 1<>1' == $specific_where ) {
1024          return;
1025      }
1026  
1027      # Get all of the bugs and split them up into an array
1028      $query = "SELECT COUNT(id) as bugcount, reporter_id, resolution, severity
1029                  FROM $t_mantis_bug_table
1030                  WHERE $specific_where
1031                  GROUP BY reporter_id, resolution, severity";
1032      $result = db_query_bound( $query );
1033  
1034      $t_reporter_ressev_arr = array();
1035      $t_reporter_bugcount_arr = array();
1036      $t_arr = db_fetch_array( $result );
1037      while( $t_arr ) {
1038          if( !isset( $t_reporter_ressev_arr[$t_arr['reporter_id']] ) ) {
1039              $t_reporter_ressev_arr[$t_arr['reporter_id']] = array();
1040              $t_reporter_bugcount_arr[$t_arr['reporter_id']] = 0;
1041          }
1042          if( !isset( $t_reporter_ressev_arr[$t_arr['reporter_id']][$t_arr['severity']] ) ) {
1043              $t_reporter_ressev_arr[$t_arr['reporter_id']][$t_arr['severity']] = array();
1044              $t_reporter_ressev_arr[$t_arr['reporter_id']][$t_arr['severity']]['total'] = 0;
1045          }
1046          if( !isset( $t_reporter_ressev_arr[$t_arr['reporter_id']][$t_arr['severity']][$t_arr['resolution']] ) ) {
1047              $t_reporter_ressev_arr[$t_arr['reporter_id']][$t_arr['severity']][$t_arr['resolution']] = 0;
1048          }
1049          $t_reporter_ressev_arr[$t_arr['reporter_id']][$t_arr['severity']][$t_arr['resolution']] += $t_arr['bugcount'];
1050          $t_reporter_ressev_arr[$t_arr['reporter_id']][$t_arr['severity']]['total'] += $t_arr['bugcount'];
1051          $t_reporter_bugcount_arr[$t_arr['reporter_id']] += $t_arr['bugcount'];
1052  
1053          $t_arr = db_fetch_array( $result );
1054      }
1055  
1056      # Sort our total bug count array so that the reporters with the highest number of bugs are listed first,
1057      arsort( $t_reporter_bugcount_arr );
1058  
1059      $t_row_count = 0;
1060  
1061      # We now have a multi dimensional array of users, resolutions and severities, with the
1062      # value of each resolution and severity for each user
1063      foreach( $t_reporter_bugcount_arr as $t_reporter_id => $t_total_user_bugs ) {
1064  
1065          # Limit the number of reporters listed
1066          if( $t_row_count > $t_reporter_summary_limit ) {
1067              break;
1068          }
1069  
1070          # Only print reporters who have reported at least one bug. This helps
1071          # prevent divide by zeroes, showing reporters not on this project, and showing
1072          # users that aren't actually reporters...
1073          if( $t_total_user_bugs > 0 ) {
1074              $t_arr2 = $t_reporter_ressev_arr[$t_reporter_id];
1075  
1076              echo '<tr ' . helper_alternate_class( $t_row_count ) . '>';
1077              $t_row_count++;
1078              echo '<td>';
1079              echo string_display_line( user_get_name( $t_reporter_id ) );
1080              echo '</td>';
1081  
1082              $t_total_severity = 0;
1083              $t_total_errors = 0;
1084              for( $j = 0; $j < $enum_sev_count; $j++ ) {
1085                  if( !isset( $t_arr2[$c_sev_s[$j]] ) ) {
1086                      continue;
1087                  }
1088  
1089                  $sev_bug_count = $t_arr2[$c_sev_s[$j]]['total'];
1090                  $t_sev_mult = 1;
1091                  if( $t_severity_multipliers[$c_sev_s[$j]] ) {
1092                      $t_sev_mult = $t_severity_multipliers[$c_sev_s[$j]];
1093                  }
1094  
1095                  if( $sev_bug_count > 0 ) {
1096                      $t_total_severity += ( $sev_bug_count * $t_sev_mult );
1097                  }
1098  
1099                  foreach( $t_resolution_multipliers as $t_res => $t_res_mult ) {
1100                      if( isset( $t_arr2[$c_sev_s[$j]][$t_res] ) ) {
1101                          $t_total_errors += ( $t_sev_mult * $t_res_mult );
1102                      }
1103                  }
1104              }
1105              echo '<td>';
1106              echo $t_total_severity;
1107              echo '</td>';
1108              echo '<td>';
1109              echo $t_total_errors;
1110              echo '</td>';
1111              echo '<td>';
1112              print( $t_total_severity - $t_total_errors );
1113              echo '</td>';
1114              echo '</tr>';
1115          }
1116      }
1117  }


Generated: Thu Jul 28 15:48:31 2011 Cross-referenced by PHPXref 0.7