[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/ -> roadmap_page.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   * @package MantisBT
  19   * @copyright Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
  20   * @copyright Copyright (C) 2002 - 2011  MantisBT Team - mantisbt-dev@lists.sourceforge.net
  21   * @link http://www.mantisbt.org
  22   *
  23   * @uses core.php
  24   * @uses access_api.php
  25   * @uses authentication_api.php
  26   * @uses bug_api.php
  27   * @uses category_api.php
  28   * @uses config_api.php
  29   * @uses constant_inc.php
  30   * @uses database_api.php
  31   * @uses error_api.php
  32   * @uses filter_api.php
  33   * @uses filter_constants_inc.php
  34   * @uses gpc_api.php
  35   * @uses helper_api.php
  36   * @uses html_api.php
  37   * @uses lang_api.php
  38   * @uses print_api.php
  39   * @uses project_api.php
  40   * @uses string_api.php
  41   * @uses user_api.php
  42   * @uses utility_api.php
  43   * @uses version_api.php
  44   */
  45  
  46  /**
  47   * MantisBT Core API's
  48   */
  49  require_once ( 'core.php' );
  50  require_api( 'access_api.php' );
  51  require_api( 'authentication_api.php' );
  52  require_api( 'bug_api.php' );
  53  require_api( 'category_api.php' );
  54  require_api( 'config_api.php' );
  55  require_api( 'constant_inc.php' );
  56  require_api( 'database_api.php' );
  57  require_api( 'error_api.php' );
  58  require_api( 'filter_api.php' );
  59  require_api( 'filter_constants_inc.php' );
  60  require_api( 'gpc_api.php' );
  61  require_api( 'helper_api.php' );
  62  require_api( 'html_api.php' );
  63  require_api( 'lang_api.php' );
  64  require_api( 'print_api.php' );
  65  require_api( 'project_api.php' );
  66  require_api( 'string_api.php' );
  67  require_api( 'user_api.php' );
  68  require_api( 'utility_api.php' );
  69  require_api( 'version_api.php' );
  70  
  71  # Print header for the specified project version.
  72  function print_version_header( $p_version_row ) {
  73      $t_project_id   = $p_version_row['project_id'];
  74      $t_version_id   = $p_version_row['id'];
  75      $t_version_name = $p_version_row['version'];
  76      $t_project_name = project_get_field( $t_project_id, 'name' );
  77  
  78      $t_release_title = '<a href="roadmap_page.php?project_id=' . $t_project_id . '">' . string_display_line( $t_project_name ) . '</a> - <a href="roadmap_page.php?version_id=' . $t_version_id . '">' . string_display_line( $t_version_name ) . '</a>';
  79  
  80      if ( config_get( 'show_roadmap_dates' ) ) {
  81          $t_version_timestamp = $p_version_row['date_order'];
  82  
  83          $t_scheduled_release_date = ' (' . lang_get( 'scheduled_release' ) . ' ' . string_display_line( date( config_get( 'short_date_format' ), $t_version_timestamp ) ) . ')';
  84      } else {
  85          $t_scheduled_release_date = '';
  86      }
  87  
  88      echo '<tt>';
  89      echo '<br />', $t_release_title, $t_scheduled_release_date, lang_get( 'word_separator' ), print_bracket_link( 'view_all_set.php?type=1&amp;temporary=y&amp;' . FILTER_PROPERTY_PROJECT_ID . '=' . $t_project_id . '&amp;' . filter_encode_field_and_value( FILTER_PROPERTY_TARGET_VERSION, $t_version_name ), lang_get( 'view_bugs_link' ) ), '<br />';
  90  
  91      $t_release_title_without_hyperlinks = $t_project_name . ' - ' . $t_version_name . $t_scheduled_release_date;
  92      echo utf8_str_pad( '', utf8_strlen( $t_release_title_without_hyperlinks ), '=' ), '<br />';
  93  }
  94  
  95  # print project header
  96  function print_project_header_roadmap( $p_project_name ) {
  97      echo '<br /><span class="pagetitle">', string_display( $p_project_name ), ' - ', lang_get( 'roadmap' ), '</span><br />';
  98  }
  99  
 100  $t_user_id = auth_get_current_user_id();
 101  
 102  $f_project = gpc_get_string( 'project', '' );
 103  if ( is_blank( $f_project ) ) {
 104      $f_project_id = gpc_get_int( 'project_id', -1 );
 105  } else {
 106      $f_project_id = project_get_id_by_name( $f_project );
 107  
 108      if ( $f_project_id === 0 ) {
 109          trigger_error( ERROR_PROJECT_NOT_FOUND, ERROR );
 110      }
 111  }
 112  
 113  $f_version = gpc_get_string( 'version', '' );
 114  
 115  if ( is_blank( $f_version ) ) {
 116      $f_version_id = gpc_get_int( 'version_id', -1 );
 117  
 118      # If both version_id and project_id parameters are supplied, then version_id take precedence.
 119      if ( $f_version_id == -1 ) {
 120          if ( $f_project_id == -1 ) {
 121              $t_project_id = helper_get_current_project();
 122          } else {
 123              $t_project_id = $f_project_id;
 124          }
 125      } else {
 126          $t_project_id = version_get_field( $f_version_id, 'project_id' );
 127      }
 128  } else {
 129      if ( $f_project_id == -1 ) {
 130          $t_project_id = helper_get_current_project();
 131      } else {
 132          $t_project_id = $f_project_id;
 133      }
 134  
 135      $f_version_id = version_get_id( $f_version, $t_project_id );
 136  
 137      if ( $f_version_id === false ) {
 138          error_parameters( $f_version );
 139          trigger_error( ERROR_VERSION_NOT_FOUND, ERROR );
 140      }
 141  }
 142  
 143  if ( ALL_PROJECTS == $t_project_id ) {
 144      $t_topprojects = $t_project_ids = user_get_accessible_projects( $t_user_id );
 145      foreach ( $t_topprojects as $t_project ) {
 146          $t_project_ids = array_merge( $t_project_ids, user_get_all_accessible_subprojects( $t_user_id, $t_project ) );
 147      }
 148  
 149      $t_project_ids_to_check = array_unique( $t_project_ids );
 150      $t_project_ids = array();
 151  
 152      foreach ( $t_project_ids_to_check as $t_project_id ) {
 153          $t_roadmap_view_access_level = config_get( 'roadmap_view_threshold', null, null, $t_project_id );
 154          if ( access_has_project_level( $t_roadmap_view_access_level, $t_project_id ) ) {
 155              $t_project_ids[] = $t_project_id;
 156          }
 157      }
 158  } else {
 159      access_ensure_project_level( config_get( 'roadmap_view_threshold' ), $t_project_id );
 160      $t_project_ids = user_get_all_accessible_subprojects( $t_user_id, $t_project_id );
 161      array_unshift( $t_project_ids, $t_project_id );
 162  }
 163  
 164  html_page_top( lang_get( 'roadmap' ) );
 165  
 166  $t_project_index = 0;
 167  
 168  version_cache_array_rows( $t_project_ids );
 169  category_cache_array_rows_by_project( $t_project_ids );
 170  
 171  foreach( $t_project_ids as $t_project_id ) {
 172      $t_project_name = project_get_field( $t_project_id, 'name' );
 173      $t_can_view_private = access_has_project_level( config_get( 'private_bug_threshold' ), $t_project_id );
 174  
 175      $t_limit_reporters = config_get( 'limit_reporters' );
 176      $t_user_access_level_is_reporter = ( REPORTER == access_get_project_level( $t_project_id ) );
 177  
 178      $t_resolved = config_get( 'bug_resolved_status_threshold' );
 179      $t_bug_table    = db_get_table( 'bug' );
 180      $t_relation_table = db_get_table( 'bug_relationship' );
 181  
 182      $t_version_rows = array_reverse( version_get_all_rows( $t_project_id ) );
 183  
 184      # cache category info, but ignore the results for now
 185      category_get_all_rows( $t_project_id );
 186  
 187      $t_project_header_printed = false;
 188  
 189      foreach( $t_version_rows as $t_version_row ) {
 190          if ( $t_version_row['released'] == 1 ) {
 191              continue;
 192          }
 193  
 194          # Skip all versions except the specified one (if any).
 195          if ( $f_version_id != -1 && $f_version_id != $t_version_row['id'] ) {
 196              continue;
 197          }
 198  
 199          $t_issues_planned = 0;
 200          $t_issues_resolved = 0;
 201          $t_issues_counted = array();
 202  
 203          $t_version_header_printed = false;
 204  
 205          $t_version = $t_version_row['version'];
 206  
 207          $query = "SELECT sbt.*, $t_relation_table.source_bug_id, dbt.target_version as parent_version FROM $t_bug_table sbt
 208                      LEFT JOIN $t_relation_table ON sbt.id=$t_relation_table.destination_bug_id AND $t_relation_table.relationship_type=2
 209                      LEFT JOIN $t_bug_table dbt ON dbt.id=$t_relation_table.source_bug_id
 210                      WHERE sbt.project_id=" . db_param() . " AND sbt.target_version=" . db_param() . " ORDER BY sbt.status ASC, sbt.last_updated DESC";
 211  
 212          $t_description = $t_version_row['description'];
 213  
 214          $t_first_entry = true;
 215  
 216          $t_result = db_query_bound( $query, Array( $t_project_id, $t_version ) );
 217  
 218          $t_issue_ids = array();
 219          $t_issue_parents = array();
 220          $t_issue_handlers = array();
 221  
 222          while ( $t_row = db_fetch_array( $t_result ) ) {
 223              # hide private bugs if user doesn't have access to view them.
 224              if ( !$t_can_view_private && ( $t_row['view_state'] == VS_PRIVATE ) ) {
 225                  continue;
 226              }
 227  
 228              bug_cache_database_result( $t_row );
 229  
 230              # check limit_Reporter (Issue #4770)
 231              # reporters can view just issues they reported
 232              if ( ON === $t_limit_reporters && $t_user_access_level_is_reporter &&
 233                   !bug_is_user_reporter( $t_row['id'], $t_user_id )) {
 234                  continue;
 235              }
 236  
 237              $t_issue_id = $t_row['id'];
 238              $t_issue_parent = $t_row['source_bug_id'];
 239              $t_parent_version = $t_row['parent_version'];
 240  
 241              if ( !helper_call_custom_function( 'roadmap_include_issue', array( $t_issue_id ) ) ) {
 242                  continue;
 243              }
 244  
 245              if ( !isset( $t_issues_counted[$t_issue_id] ) ) {
 246                  $t_issues_planned++;
 247  
 248                  if ( bug_is_resolved( $t_issue_id ) ) {
 249                      $t_issues_resolved++;
 250                  }
 251  
 252                  $t_issues_counted[$t_issue_id] = true;
 253              }
 254  
 255              if ( 0 === strcasecmp( $t_parent_version, $t_version ) ) {
 256                  $t_issue_ids[] = $t_issue_id;
 257                  $t_issue_parents[] = $t_issue_parent;
 258              } else if ( !in_array( $t_issue_id, $t_issue_ids ) ) {
 259                  $t_issue_ids[] = $t_issue_id;
 260                  $t_issue_parents[] = null;
 261              }
 262  
 263              $t_issue_handlers[] = $t_row['handler_id'];
 264          }
 265  
 266          user_cache_array_rows( array_unique( $t_issue_handlers ) );
 267  
 268          $t_progress = $t_issues_planned > 0 ? ( (integer) ( $t_issues_resolved * 100 / $t_issues_planned ) ) : 0;
 269  
 270          if ( $t_issues_planned > 0 ) {
 271              $t_progress = (integer) ( $t_issues_resolved * 100 / $t_issues_planned );
 272  
 273              if ( !$t_project_header_printed ) {
 274                  print_project_header_roadmap( $t_project_name );
 275                  $t_project_header_printed = true;
 276              }
 277  
 278              if ( !$t_version_header_printed ) {
 279                  print_version_header( $t_version_row );
 280                  $t_version_header_printed = true;
 281              }
 282  
 283              if ( !is_blank( $t_description ) ) {
 284                  echo string_display( '<br />' .$t_description . '<br />' );
 285              }
 286  
 287              // show progress bar
 288              echo '<div class="progress400">';
 289              echo '  <span class="bar" style="width: ' . $t_progress . '%;">' . $t_progress . '%</span>';
 290              echo '</div>';
 291          }
 292  
 293          $t_issue_set_ids = array();
 294          $t_issue_set_levels = array();
 295          $k = 0;
 296  
 297          $t_cycle = false;
 298          $t_cycle_ids = array();
 299  
 300          while ( 0 < count( $t_issue_ids ) ) {
 301              $t_issue_id = $t_issue_ids[$k];
 302              $t_issue_parent = $t_issue_parents[$k];
 303  
 304              if ( in_array( $t_issue_id, $t_cycle_ids ) && in_array( $t_issue_parent, $t_cycle_ids ) ) {
 305                  $t_cycle = true;
 306              } else {
 307                  $t_cycle = false;
 308                  $t_cycle_ids[] = $t_issue_id;
 309              }
 310  
 311              if ( $t_cycle || !in_array( $t_issue_parent, $t_issue_ids ) ) {
 312                  $l = array_search( $t_issue_parent, $t_issue_set_ids );
 313                  if ( $l !== false ) {
 314                      for ( $m = $l+1; $m < count( $t_issue_set_ids ) && $t_issue_set_levels[$m] > $t_issue_set_levels[$l]; $m++ ) {
 315                          #do nothing
 316                      }
 317                      $t_issue_set_ids_end = array_splice( $t_issue_set_ids, $m );
 318                      $t_issue_set_levels_end = array_splice( $t_issue_set_levels, $m );
 319                      $t_issue_set_ids[] = $t_issue_id;
 320                      $t_issue_set_levels[] = $t_issue_set_levels[$l] + 1;
 321                      $t_issue_set_ids = array_merge( $t_issue_set_ids, $t_issue_set_ids_end );
 322                      $t_issue_set_levels = array_merge( $t_issue_set_levels, $t_issue_set_levels_end );
 323                  } else {
 324                      $t_issue_set_ids[] = $t_issue_id;
 325                      $t_issue_set_levels[] = 0;
 326                  }
 327                  array_splice( $t_issue_ids, $k, 1 );
 328                  array_splice( $t_issue_parents, $k, 1 );
 329  
 330                  $t_cycle_ids = array();
 331              } else {
 332                  $k++;
 333              }
 334              if ( count( $t_issue_ids ) <= $k ) {
 335                  $k = 0;
 336              }
 337          }
 338  
 339          $t_count_ids = count( $t_issue_set_ids );
 340          for ( $j = 0; $j < $t_count_ids; $j++ ) {
 341              $t_issue_set_id = $t_issue_set_ids[$j];
 342              $t_issue_set_level = $t_issue_set_levels[$j];
 343  
 344              helper_call_custom_function( 'roadmap_print_issue', array( $t_issue_set_id, $t_issue_set_level ) );
 345          }
 346  
 347          if ( $t_issues_planned > 0 ) {
 348              echo '<br />';
 349              echo sprintf( lang_get( 'resolved_progress' ), $t_issues_resolved, $t_issues_planned, $t_progress );
 350              echo '<br /></tt>';
 351          }
 352      }
 353  
 354      $t_project_index++;
 355  }
 356  
 357  html_page_bottom();


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