[ Index ]
 

Code source de Mantis 1.1.0rc3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/core/ -> print_api.php (source)

   1  <?php
   2  # Mantis - a php based bugtracking system
   3  
   4  # Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
   5  # Copyright (C) 2002 - 2007  Mantis Team   - mantisbt-dev@lists.sourceforge.net
   6  
   7  # Mantis 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, either version 2 of the License, or
  10  # (at your option) any later version.
  11  #
  12  # Mantis is distributed in the hope that it will be useful,
  13  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15  # GNU General Public License for more details.
  16  #
  17  # You should have received a copy of the GNU General Public License
  18  # along with Mantis.  If not, see <http://www.gnu.org/licenses/>.
  19  
  20      # --------------------------------------------------------
  21      # $Id: print_api.php,v 1.182.2.5 2007-10-24 05:28:10 vboctor Exp $
  22      # --------------------------------------------------------
  23  
  24      $t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR;
  25  
  26      require_once ( $t_core_dir . 'ajax_api.php' );
  27      require_once ( $t_core_dir . 'current_user_api.php' );
  28      require_once ( $t_core_dir . 'string_api.php' );
  29      require_once ( $t_core_dir . 'prepare_api.php' );
  30      require_once ( $t_core_dir . 'profile_api.php' );
  31      require_once ( $t_core_dir . 'last_visited_api.php' );
  32  
  33      ### Print API ###
  34  
  35      # this file handles printing functions
  36  
  37      # --------------------
  38      # Print the headers to cause the page to redirect to $p_url
  39      # If $p_die is true (default), terminate the execution of the script
  40      #  immediately
  41      # If we have handled any errors on this page and the 'stop_on_errors' config
  42      #  option is turned on, return false and don't redirect.
  43      # $p_sanitize - true/false - true in the case where the URL is extracted from GET/POST or untrusted source.
  44      # This would be false if the URL is trusted (e.g. read from config_inc.php).
  45  	function print_header_redirect( $p_url, $p_die = true, $p_sanitize = false ) {
  46          $t_use_iis = config_get( 'use_iis');
  47  
  48          if ( ON == config_get( 'stop_on_errors' ) && error_handled() ) {
  49              return false;
  50          }
  51  
  52          # validate the url as part of this site before continuing
  53          $t_url = $p_sanitize ? string_sanitize_url( $p_url ) : $p_url;
  54  
  55          # don't send more headers if they have already been sent (guideweb)
  56          if ( ! headers_sent() ) {
  57              header( 'Content-Type: text/html; charset=' . lang_get( 'charset' ) );
  58  
  59              if ( ON == $t_use_iis ) {
  60                  header( "Refresh: 0;url=$t_url" );
  61              } else {
  62                  header( "Location: $t_url" );
  63              }
  64          } else {
  65              trigger_error( ERROR_PAGE_REDIRECTION, ERROR );
  66              return false;
  67          }
  68  
  69          if ( $p_die ) {
  70              die; # additional output can cause problems so let's just stop output here
  71          }
  72  
  73          return true;
  74      }
  75      # --------------------
  76      # Print a redirect header to view a bug
  77  	function print_header_redirect_view( $p_bug_id ) {
  78          print_header_redirect( string_get_bug_view_url( $p_bug_id ) );
  79      }
  80  
  81      # --------------------
  82      # Get a view URL for the bug id based on the user's preference and
  83      #  call print_successful_redirect() with that URL
  84  	function print_successful_redirect_to_bug( $p_bug_id ) {
  85          $t_url = string_get_bug_view_url( $p_bug_id, auth_get_current_user_id() );
  86  
  87          print_successful_redirect( $t_url );
  88      }
  89  
  90      # --------------------
  91      # If the show query count is ON, print success and redirect after the
  92      #  configured system wait time.
  93      # If the show query count is OFF, redirect right away.
  94  	function print_successful_redirect( $p_redirect_to ) {
  95          if ( helper_show_queries() ) {
  96              html_meta_redirect( $p_redirect_to );
  97              html_page_top1();
  98              html_page_top2();
  99              PRINT '<br /><div class="center">';
 100              PRINT lang_get( 'operation_successful' ) . '<br />';
 101              print_bracket_link( $p_redirect_to, lang_get( 'proceed' ) );
 102              PRINT '</div>';
 103              html_page_bottom1();
 104          } else {
 105              print_header_redirect( $p_redirect_to );
 106          }
 107      }
 108  
 109      # --------------------
 110      # Print a redirect header to update a bug
 111  	function print_header_redirect_update( $p_bug_id ) {
 112          print_header_redirect( string_get_bug_update_url( $p_bug_id ) );
 113      }
 114      # --------------------
 115      # Print a redirect header to update a bug
 116  	function print_header_redirect_report() {
 117          print_header_redirect( string_get_bug_report_url() );
 118      }
 119  
 120      
 121      # Print avatar image for the given user ID
 122  	function print_avatar( $p_user_id ) {
 123          if ( !user_exists( $p_user_id ) ) {
 124              return;
 125          }
 126  
 127          if ( access_has_project_level( config_get( 'show_avatar_threshold' ), null, $p_user_id ) ) {
 128              $t_avatar = user_get_avatar( $p_user_id );
 129              if ( false !== $t_avatar ) {
 130                  $t_avatar_url = $t_avatar[0];
 131                  $t_width = $t_avatar[1];
 132                  $t_height = $t_avatar[2];
 133                  echo '<a rel="nofollow" href="http://site.gravatar.com">' .
 134                      '<img class="avatar" src="' . $t_avatar_url . '" alt="User avatar"' .
 135                      ' width="' . $t_width . '" height="' . $t_height . '" /></a>';
 136              }
 137          }
 138      }
 139  
 140  
 141      # --------------------
 142      # prints the name of the user given the id.  also makes it an email link.
 143  	function print_user( $p_user_id ) {
 144          echo prepare_user_name( $p_user_id );
 145      }
 146  
 147  
 148      # --------------------
 149      # same as print_user() but fills in the subject with the bug summary
 150  	function print_user_with_subject( $p_user_id, $p_bug_id ) {
 151          $c_user_id = db_prepare_int( $p_user_id );
 152  
 153          if ( NO_USER == $p_user_id ) {
 154              return;
 155          }
 156  
 157          $t_username = user_get_name( $p_user_id );
 158          if ( user_exists( $p_user_id ) && user_get_field( $p_user_id, 'enabled' ) ) {
 159              $t_email = user_get_field( $p_user_id, 'email' );
 160              print_email_link_with_subject( $t_email, $t_username, $p_bug_id );
 161          } else {
 162              echo '<font STYLE="text-decoration: line-through">';
 163              echo $t_username;
 164              echo '</font>';
 165          }
 166      }
 167      # --------------------
 168  	function print_duplicate_id( $p_duplicate_id ) {
 169          if ( $p_duplicate_id != 0 ) {
 170              PRINT string_get_bug_view_link( $p_duplicate_id );
 171          }
 172      }
 173      # --------------------
 174      # print out an email editing input
 175  	function print_email_input( $p_field_name, $p_email ) {
 176          $t_limit_email_domain = config_get( 'limit_email_domain' );
 177          if ( $t_limit_email_domain ) {
 178              # remove the domain part
 179              $p_email = eregi_replace( "@$t_limit_email_domain$", '', $p_email );
 180              PRINT '<input type="text" name="'.$p_field_name.'" size="20" maxlength="64" value="'.$p_email.'" />@'.$t_limit_email_domain;
 181          } else {
 182              PRINT '<input type="text" name="'.$p_field_name.'" size="32" maxlength="64" value="'.$p_email.'" />';
 183          }
 184      }
 185      # --------------------
 186      # print out an email editing input
 187  	function print_captcha_input( $p_field_name ) {
 188          echo '<input type="text" name="'.$p_field_name.'" size="5" maxlength="5" value="" />';
 189      }
 190      ###########################################################################
 191      # Option List Printing API
 192      ###########################################################################
 193      # --------------------
 194      # sorts the array by the first element of the array element
 195      # @@@ might not be used
 196  	function cmp( $p_var1, $p_var2 ) {
 197          if ( $p_var1[0][0] == $p_var2[0][0] ) {
 198              return 0;
 199          }
 200          if ( $p_var1[0][0] < $p_var2[0][0] ) {
 201              return -1;
 202          } else {
 203              return 1;
 204          }
 205      }
 206      # --------------------
 207      # This populates an option list with the appropriate users by access level
 208      #
 209      # @@@ from print_reporter_option_list
 210  	function print_user_option_list( $p_user_id, $p_project_id = null, $p_access = ANYBODY ) {
 211          $t_users = array();
 212  
 213          if ( null === $p_project_id ) {
 214              $p_project_id = helper_get_current_project();
 215          }
 216  
 217          $t_users = project_get_all_user_rows( $p_project_id, $p_access ); # handles ALL_PROJECTS case
 218  
 219          $t_display = array();
 220          $t_sort = array();
 221          $t_show_realname = ( ON == config_get( 'show_realname' ) );
 222          $t_sort_by_last_name = ( ON == config_get( 'sort_by_last_name' ) );
 223          foreach ( $t_users as $t_user ) {
 224              $t_user_name = string_attribute( $t_user['username'] );
 225              $t_sort_name = strtolower( $t_user_name );
 226              if ( $t_show_realname && ( $t_user['realname'] <> "" ) ){
 227                  $t_user_name = string_attribute( $t_user['realname'] );
 228                  if ( $t_sort_by_last_name ) {
 229                      $t_sort_name_bits = split( ' ', strtolower( $t_user_name ), 2 );
 230                      $t_sort_name = ( isset( $t_sort_name_bits[1] ) ? $t_sort_name_bits[1] . ', ' : '' ) . $t_sort_name_bits[0];
 231                  } else {
 232                      $t_sort_name = strtolower( $t_user_name );
 233                  }
 234              }
 235              $t_display[] = $t_user_name;
 236              $t_sort[] = $t_sort_name;
 237          }
 238          array_multisort( $t_sort, SORT_ASC, SORT_STRING, $t_users, $t_display );
 239          for ($i = 0; $i < count( $t_sort ); $i++ ) {
 240              $t_row = $t_users[$i];
 241              PRINT '<option value="' . $t_row['id'] . '" ';
 242              check_selected( $p_user_id, $t_row['id'] );
 243              PRINT '>' . $t_display[$i] . '</option>';
 244          }
 245      }
 246  
 247      # --------------------
 248      # ugly functions  need to be refactored
 249      # This populates the reporter option list with the appropriate users
 250      #
 251      # @@@ This function really ought to print out all the users, I think.
 252      #  I just encountered a situation where a project used to be public and
 253      #  was made private, so now I can't filter on any of the reporters who
 254      #  actually reported the bugs at the time. Maybe we could get all user
 255      #  who are listed as the reporter in any bug?  It would probably be a
 256      #  faster query actually.
 257  	function print_reporter_option_list( $p_user_id, $p_project_id = null ) {
 258          print_user_option_list( $p_user_id, $p_project_id, config_get( 'report_bug_threshold' ) );
 259      }
 260  
 261      # --------------------
 262  	function print_duplicate_id_option_list() {
 263          $query = "SELECT id
 264                  FROM " . config_get ( 'mantis_bug_table' ) . "
 265                  ORDER BY id ASC";
 266          $result = db_query( $query );
 267          $duplicate_id_count = db_num_rows( $result );
 268          PRINT '<option value="0"></option>';
 269  
 270          for ($i=0;$i<$duplicate_id_count;$i++) {
 271              $row = db_fetch_array( $result );
 272              $t_duplicate_id    = $row['id'];
 273  
 274              PRINT "<option value=\"$t_duplicate_id\">".$t_duplicate_id."</option>";
 275          }
 276      }
 277  
 278      /**
 279       * Print the entire form for attaching a tag to a bug.
 280       * @param integer Bug ID
 281       * @param string Default contents of the input box
 282       */
 283  	function print_tag_attach_form( $p_bug_id, $p_string="" ) {
 284          ?>
 285          <small><?php echo sprintf( lang_get( 'tag_separate_by' ), config_get('tag_separator') ) ?></small> 
 286          <form method="post" action="tag_attach.php">
 287          <input type="hidden" name="bug_id" value="<?php echo $p_bug_id ?>" />
 288          <?php
 289              print_tag_input( $p_bug_id, $p_string );
 290          ?>
 291          <input type="submit" value="<?php echo lang_get( 'tag_attach' ) ?>" class="button" />
 292          </form>
 293          <?php
 294          return true;
 295      }
 296  
 297      /**
 298       * Print the separator comment, input box, and existing tag dropdown menu.
 299       * @param integer Bug ID
 300       * @param string Default contents of the input box
 301       */
 302  	function print_tag_input( $p_bug_id = 0, $p_string="" ) {
 303          ?>
 304          <input type="hidden" id="tag_separator" value="<?php echo config_get( 'tag_separator' ) ?>" />
 305          <input type="text" name="tag_string" id="tag_string" size="40" value="<?php echo string_attribute( $p_string ) ?>" />
 306          <select <?php echo helper_get_tab_index() ?> name="tag_select" id="tag_select">
 307              <?php print_tag_option_list( $p_bug_id ); ?>
 308          </select>
 309          <?php
 310  
 311          return true;
 312      }
 313  
 314      /**
 315       * Print the dropdown combo-box of existing tags.
 316       * When passed a bug ID, the option list will not contain any tags attached to the given bug.
 317       * @param integer Bug ID
 318       */
 319  	function print_tag_option_list( $p_bug_id = 0 ) {
 320          $t_tag_table = config_get( 'mantis_tag_table' );
 321  
 322          $query = "SELECT id, name FROM $t_tag_table ";
 323          if ( 0 != $p_bug_id ) {
 324              $c_bug_id = db_prepare_int( $p_bug_id );
 325              $t_bug_tag_table = config_get( 'mantis_bug_tag_table' );
 326              
 327              $query .= "    WHERE id NOT IN ( 
 328                          SELECT tag_id FROM $t_bug_tag_table WHERE bug_id='$c_bug_id' ) ";
 329          }
 330  
 331          $query .= " ORDER BY name ASC ";
 332          $result = db_query( $query );
 333  
 334          echo '<option value="0">',lang_get( 'tag_existing' ),'</option>';
 335          while ( $row = db_fetch_array( $result ) ) {
 336              echo '<option value="',$row['id'],'" onclick="tag_string_append(\'',$row['name'],'\')">',$row['name'],'</option>';
 337          }
 338      }
 339  
 340      # --------------------
 341      # Get current headlines and id  prefix with v_
 342  	function print_news_item_option_list() {
 343          $t_mantis_news_table = config_get( 'mantis_news_table' );
 344  
 345          $t_project_id = helper_get_current_project();
 346  
 347          if ( access_has_project_level( ADMINISTRATOR ) ) {
 348              $query = "SELECT id, headline, announcement, view_state
 349                  FROM $t_mantis_news_table
 350                  ORDER BY date_posted DESC";
 351          } else {
 352              $query = "SELECT id, headline, announcement, view_state
 353                  FROM $t_mantis_news_table
 354                  WHERE project_id='$t_project_id'
 355                  ORDER BY date_posted DESC";
 356          }
 357          $result = db_query( $query );
 358          $news_count = db_num_rows( $result );
 359  
 360          for ($i=0;$i<$news_count;$i++) {
 361              $row = db_fetch_array( $result );
 362              extract( $row, EXTR_PREFIX_ALL, 'v' );
 363              $v_headline = string_display( $v_headline );
 364  
 365              $t_notes = array();
 366              $t_note_string = '';
 367              if ( 1 == $v_announcement ) {
 368                  array_push( $t_notes, lang_get( 'announcement' ) );
 369              }
 370              if ( VS_PRIVATE == $v_view_state ) {
 371                  array_push( $t_notes, lang_get( 'private' ) );
 372              }
 373              if ( sizeof( $t_notes ) > 0 ) {
 374                  $t_note_string = ' ['.implode( ' ', $t_notes ).']';
 375              }
 376              PRINT "<option value=\"$v_id\">$v_headline$t_note_string</option>";
 377          }
 378      }
 379      #---------------
 380      # Constructs the string for one news entry given the row retrieved from the news table.
 381  	function print_news_entry( $p_headline, $p_body, $p_poster_id, $p_view_state, $p_announcement, $p_date_posted ) {
 382          $t_headline = string_display_links( $p_headline );
 383          $t_body = string_display_links( $p_body );
 384          $t_date_posted = date( config_get( 'normal_date_format' ), $p_date_posted );
 385  
 386          if ( VS_PRIVATE == $p_view_state ) {
 387              $t_news_css = 'news-heading-private';
 388          } else {
 389              $t_news_css = 'news-heading-public';
 390          }
 391  
 392          $output = '<div align="center">';
 393          $output .= '<table class="width75" cellspacing="0">';
 394          $output .= '<tr>';
 395          $output .= "<td class=\"$t_news_css\">";
 396          $output .= "<span class=\"bold\">$t_headline</span> - ";
 397          $output .= "<span class=\"italic-small\">$t_date_posted</span> - ";
 398          echo $output;
 399  
 400          # @@@ eventually we should replace print's with methods to construct the
 401          #     strings.
 402          print_user( $p_poster_id );
 403          $output = '';
 404  
 405          $output .= ' <span class="small">';
 406          if ( 1 == $p_announcement ) {
 407              $output .= '[' . lang_get( 'announcement' ) . ']';
 408          }
 409          if ( VS_PRIVATE == $p_view_state ) {
 410              $output .= '[' . lang_get( 'private' ) . ']';
 411          }
 412  
 413          $output .= '</span>';
 414          $output .= '</td>';
 415          $output .= '</tr>';
 416          $output .= '<tr>';
 417          $output .= "<td class=\"news-body\">$t_body</td>";
 418          $output .= '</tr>';
 419          $output .= '</table>';
 420          $output .= '</div>';
 421  
 422          echo $output;
 423      }
 424  
 425      # --------------------
 426      # print a news item given a row in the news table.
 427          function print_news_entry_from_row( $p_news_row ) {
 428          extract( $p_news_row, EXTR_PREFIX_ALL, 'v' );
 429          print_news_entry( $v_headline, $v_body, $v_poster_id, $v_view_state, $v_announcement, $v_date_posted );
 430      }
 431  
 432      # --------------------
 433      # print a news item
 434  	function print_news_string_by_news_id( $p_news_id ) {
 435          $row = news_get_row( $p_news_id );
 436  
 437          # only show VS_PRIVATE posts to configured threshold and above
 438          if ( ( VS_PRIVATE == $row['view_state'] ) &&
 439               !access_has_project_level( config_get( 'private_news_threshold' ) ) ) {
 440              return;
 441          }
 442  
 443          print_news_entry_from_row( $row );
 444      }
 445      # --------------------
 446      # Used for update pages
 447  	function print_field_option_list( $p_list, $p_item='' ) {
 448          $t_mantis_bug_table = config_get( 'mantis_bug_table' );
 449  
 450          $t_category_string = get_enum_string( $t_mantis_bug_table, $p_list );
 451          $t_arr = explode_enum_string( $t_category_string );
 452          $entry_count = count( $t_arr );
 453          for ($i=0;$i<$entry_count;$i++) {
 454              $t_s = str_replace( '\'', '', $t_arr[$i] );
 455              PRINT "<option value=\"$t_s\"";
 456              check_selected( $p_item, $t_s );
 457              PRINT ">$t_s</option>";
 458          } # end for
 459      }
 460      # --------------------
 461  	function print_assign_to_option_list( $p_user_id='', $p_project_id = null, $p_threshold = null ) {
 462  
 463          if ( null === $p_threshold ) {
 464              $p_threshold = config_get( 'handle_bug_threshold' );
 465          }
 466  
 467          print_user_option_list( $p_user_id, $p_project_id, $p_threshold );
 468      }
 469      # --------------------
 470      # List projects that the current user has access to
 471  	function print_project_option_list( $p_project_id = null, $p_include_all_projects = true, $p_filter_project_id = null, $p_trace = false ) {
 472          project_cache_all();
 473          $t_project_ids = current_user_get_accessible_projects();
 474          if ( $p_include_all_projects ) {
 475              PRINT '<option value="' . ALL_PROJECTS . '"';
 476              check_selected( $p_project_id, ALL_PROJECTS );
 477              PRINT '>' . lang_get( 'all_projects' ) . '</option>' . "\n";
 478          }
 479  
 480          $t_project_count = count( $t_project_ids );
 481          for ($i=0;$i<$t_project_count;$i++) {
 482              $t_id = $t_project_ids[$i];
 483              if ( $t_id != $p_filter_project_id ) {
 484                  PRINT "<option value=\"$t_id\"";
 485                  check_selected( $p_project_id, $t_id );
 486                  PRINT '>' . string_display( project_get_field( $t_id, 'name' ) ) . '</option>' . "\n";
 487                  print_subproject_option_list( $t_id, $p_project_id, $p_filter_project_id, $p_trace );
 488              }
 489          }
 490      }
 491      # --------------------
 492      # List projects that the current user has access to
 493  	function print_subproject_option_list( $p_parent_id, $p_project_id = null, $p_filter_project_id = null, $p_trace = false, $p_parents = Array() ) {
 494          array_push( $p_parents, $p_parent_id );
 495          $t_project_ids = current_user_get_accessible_subprojects( $p_parent_id );
 496          $t_project_count = count( $t_project_ids );
 497          for ($i=0;$i<$t_project_count;$i++) {
 498              $t_full_id = $t_id = $t_project_ids[$i];
 499              if ( $t_id != $p_filter_project_id ) {
 500                  PRINT "<option value=\"";
 501                  if ( $p_trace ) {
 502                    $t_full_id = join( $p_parents, ";") . ';' . $t_id;
 503                  }
 504                  PRINT "$t_full_id\"";
 505                  check_selected( $p_project_id, $t_full_id );
 506                  PRINT '>' . str_repeat( '&nbsp;', count( $p_parents ) ) . str_repeat( '&raquo;', count( $p_parents ) ) . ' ' . string_display( project_get_field( $t_id, 'name' ) ) . '</option>' . "\n";
 507                  print_subproject_option_list( $t_id, $p_project_id, $p_filter_project_id, $p_trace, $p_parents );
 508              }
 509          }
 510      }
 511      # --------------------
 512      # Print extended project browser
 513  	function print_extended_project_browser( $p_trace=Array() ) {
 514          project_cache_all();
 515          $t_project_ids = current_user_get_accessible_projects();
 516  
 517          echo '<script type="text/javascript" language="JavaScript">' . "\n";
 518          echo "<!--\n";
 519          echo "var subprojects = new Object();\n";
 520  
 521          $t_projects = Array();
 522  
 523          $t_project_count = count( $t_project_ids );
 524          for ($i=0;$i<$t_project_count;$i++) {
 525              $t_id = $t_project_ids[$i];
 526              echo 'subprojects[\'' . $t_id . '\'] = new Object();' . "\n";
 527  
 528              $t_name = project_get_field( $t_id, 'name' );
 529              $c_name = addslashes( $t_name );
 530              echo 'subprojects[\'' . $t_id . '\'][\'' . $t_id . '\'] = \'' . $c_name . '\';' . "\n";
 531  
 532              $t_projects[$t_id] = $t_name;
 533              
 534              print_extended_project_browser_subproject_javascript( $t_id );
 535          }
 536  
 537          echo "\n";
 538          echo 'function setProject(projectVal) {' . "\n";
 539          echo "\t" . 'var spInput = document.form_set_project.project_id;' . "\n";
 540          echo "\t" . 'spInput.options.length = 0' . "\n";
 541          echo "\t" . 'if (projectVal == "' . ALL_PROJECTS . '") {' . "\n";
 542          echo "\t\t" . 'spInput.options[0] = new Option(\'--- All Projects ---\', \'' . ALL_PROJECTS . '\');' . "\n";
 543          echo "\t" . '} else {' . "\n";
 544          echo "\t\t" . 'var i = 0;' . "\n";
 545          echo "\t\t" . 'var project = subprojects[ projectVal ];' . "\n";
 546          echo "\t\t" . 'for ( var sp in project ) {' . "\n";
 547          echo "\t\t\t" . 'spInput.options[ i++ ] = new Option( project[sp], sp );' . "\n";
 548          echo "\t\t" . '}' . "\n";
 549          echo "\t" . '}' . "\n";
 550          echo '}' . "\n";
 551          
 552          echo '// --></script>' . "\n";
 553          echo '<select name="top_id" onChange="setProject(this.value); document.form_set_project.submit()" class="small">' . "\n";
 554          echo '<option value="' . ALL_PROJECTS . '"';
 555          echo check_selected( $p_project_id, ALL_PROJECTS );
 556          echo '>' . lang_get('all_projects') . '</option>' . "\n";
 557          
 558          foreach ( $t_projects as $t_id => $t_name ) {
 559              $c_name = string_display( $t_name );
 560              echo '<option value="' . $t_id . '"';
 561              echo check_selected( $p_project_id, $t_id );
 562                  echo '>' . $c_name . '</option>' . "\n";
 563          }
 564  
 565          echo '</select>' . "\n";
 566  
 567          if ( 0 === count( $p_trace ) ) {
 568              $t_top_id = ALL_PROJECTS;
 569          } else {
 570              $t_top_id = $p_trace[0];
 571              $t_trace_str = join( ';', $p_trace );
 572          }
 573  
 574          echo '<select name="project_id" onChange="document.form_set_project.submit()" class="small-subprojects"></select>' . "\n";
 575          echo '<script type="text/javascript" language="JavaScript">' . "\n";
 576          echo '<!--' . "\n";
 577          echo 'document.form_set_project.top_id.value = \'' . $t_top_id . '\';'. "\n";
 578          echo 'setProject(' . $t_top_id . ');' . "\n";
 579          echo 'document.form_set_project.project_id.value = \'' . $t_trace_str . '\';' . "\n";
 580          echo '// --></script>' . "\n";
 581      }
 582  
 583      # --------------------
 584      # print the subproject javascript for the extended project browser
 585      function print_extended_project_browser_subproject_javascript( $p_trace ) {
 586          $t_trace_projects = split( ';', $p_trace);
 587          $t_top_id = $t_trace_projects[0];
 588          $t_level = count( $t_trace_projects );
 589          $t_parent_id = $t_trace_projects[ $t_level - 1 ];
 590          
 591          $t_project_ids = current_user_get_accessible_subprojects( $t_parent_id );
 592          $t_project_count = count( $t_project_ids );
 593  
 594          for ($i=0;$i<$t_project_count;$i++) {
 595              $t_id = $t_project_ids[$i];
 596              $t_nbsp = chr( 160 );
 597              $t_name = addslashes( str_repeat( $t_nbsp , $t_level ) . str_repeat( '&raquo;', $t_level ) . ' ' . project_get_field( $t_id, 'name' ) );
 598              echo 'subprojects[\'' . $t_top_id . '\'][\'' . $p_trace . ';' . $t_id . '\'] = \'' . $t_name . '\';' . "\n";
 599  
 600              print_extended_project_browser_subproject_javascript( $p_trace . ';' . $t_id );
 601          }
 602      }
 603          
 604      # --------------------
 605      # prints the profiles given the user id
 606  	function print_profile_option_list( $p_user_id, $p_select_id='', $p_profiles = null ) {
 607          if ( '' === $p_select_id ) {
 608              $p_select_id = profile_get_default( $p_user_id );
 609          }
 610          if ( $p_profiles != null ) {
 611              $t_profiles = $p_profiles;
 612          } else {
 613              $t_profiles = profile_get_all_for_user( $p_user_id );
 614          }
 615          print_profile_option_list_from_profiles( $t_profiles, $p_select_id );
 616      }
 617      
 618      # --------------------
 619      # prints the profiles used in a certain project
 620  	function print_profile_option_list_for_project( $p_project_id, $p_select_id='', $p_profiles = null) {
 621          if ( '' === $p_select_id ) {
 622              $p_select_id = profile_get_default( $p_user_id );
 623          }
 624          if ( $p_profiles != null ) {
 625              $t_profiles = $p_profiles;
 626          } else {
 627              $t_profiles = profile_get_all_for_project( $p_project_id );
 628          }
 629          print_profile_option_list_from_profiles( $t_profiles, $p_select_id );
 630      }
 631      
 632      # --------------------
 633      # print the profile option list from profiles array
 634  	function print_profile_option_list_from_profiles ( $p_profiles, $p_select_id) {
 635          echo '<option value=""></option>';
 636          foreach ( $p_profiles as $t_profile ) {
 637              extract( $t_profile, EXTR_PREFIX_ALL, 'v' );
 638              $v_platform    = string_display( $v_platform );
 639              $v_os        = string_display( $v_os );
 640              $v_os_build    = string_display( $v_os_build );
 641      
 642              echo '<option value="' . $v_id . '"';
 643              check_selected( $p_select_id, $v_id );
 644              echo '>' . $v_platform . ' ' . $v_os . ' ' . $v_os_build . '</option>';
 645          }
 646      }
 647      
 648      # --------------------
 649  	function print_news_project_option_list( $p_project_id ) {
 650          $t_mantis_project_table = config_get( 'mantis_project_table' );
 651          $t_mantis_project_user_list_table = config_get( 'mantis_project_user_list_table' );
 652  
 653          if ( access_has_project_level( ADMINISTRATOR ) ) {
 654              $query = "SELECT *
 655                      FROM $t_mantis_project_table
 656                      ORDER BY name";
 657          } else {
 658              $t_user_id = auth_get_current_user_id();
 659              $query = "SELECT p.id, p.name
 660                      FROM $t_mantis_project_table p, $t_mantis_project_user_list_table m
 661                      WHERE     p.id=m.project_id AND
 662                              m.user_id='$t_user_id' AND
 663                              p.enabled='1'";
 664          }
 665          $result = db_query( $query );
 666          $project_count = db_num_rows( $result );
 667          for ($i=0;$i<$project_count;$i++) {
 668              $row = db_fetch_array( $result );
 669              extract( $row, EXTR_PREFIX_ALL, 'v' );
 670  
 671              PRINT "<option value=\"$v_id\"";
 672              check_selected( $v_id, $p_project_id );
 673              PRINT ">$v_name</option>";
 674          } # end for
 675      }
 676      # --------------------
 677      # Since categories can be orphaned we need to grab all unique instances of category
 678      # We check in the project category table and in the bug table
 679      # We put them all in one array and make sure the entries are unique
 680  	function print_category_option_list( $p_category='', $p_project_id = null ) {
 681          $t_mantis_project_category_table = config_get( 'mantis_project_category_table' );
 682  
 683          if ( null === $p_project_id ) {
 684              $c_project_id = helper_get_current_project();
 685          } else {
 686              $c_project_id = db_prepare_int( $p_project_id );
 687          }
 688  
 689          $t_project_where = helper_project_specific_where( $c_project_id );
 690  
 691          # grab all categories in the project category table
 692          $cat_arr = array();
 693          $query = "SELECT DISTINCT category
 694                  FROM $t_mantis_project_category_table
 695                  WHERE $t_project_where
 696                  ORDER BY category";
 697          $result = db_query( $query );
 698          $category_count = db_num_rows( $result );
 699          for ($i=0;$i<$category_count;$i++) {
 700              $row = db_fetch_array( $result );
 701              $cat_arr[] = string_attribute( $row['category'] );
 702          }
 703  
 704          # Add the default option if not in the list retrieved from DB        
 705          # This is useful for default categories and when updating an
 706          # issue with a deleted category.
 707          if ( !is_blank( $p_category ) && !in_array( $p_category, $cat_arr ) ) {
 708              $cat_arr[] = $p_category;
 709          }
 710  
 711          sort( $cat_arr );
 712          $cat_arr = array_unique( $cat_arr );
 713  
 714          foreach( $cat_arr as $t_category ) {
 715              PRINT "<option value=\"$t_category\"";
 716              check_selected( $t_category, $p_category );
 717              PRINT ">$t_category</option>";
 718          }
 719      }
 720      # --------------------
 721      # Since categories can be orphaned we need to grab all unique instances of category
 722      # We check in the project category table and in the bug table
 723      # We put them all in one array and make sure the entries are unique
 724  	function print_category_complete_option_list( $p_category='', $p_project_id = null ) {
 725          $t_mantis_project_category_table = config_get( 'mantis_project_category_table' );
 726          $t_mantis_bug_table = config_get( 'mantis_bug_table' );
 727  
 728          if ( null === $p_project_id ) {
 729              $t_project_id = helper_get_current_project();
 730          } else {
 731              $t_project_id = $p_project_id;
 732          }
 733  
 734          $t_project_where = helper_project_specific_where( $t_project_id );
 735  
 736          # grab all categories in the project category table
 737          $cat_arr = array();
 738          $query = "SELECT DISTINCT category
 739                  FROM $t_mantis_project_category_table
 740                  WHERE $t_project_where
 741                  ORDER BY category";
 742          $result = db_query( $query );
 743          $category_count = db_num_rows( $result );
 744          for ($i=0;$i<$category_count;$i++) {
 745              $row = db_fetch_array( $result );
 746              $cat_arr[] = string_attribute( $row['category'] );
 747          }
 748  
 749          # grab all categories in the bug table
 750          $query = "SELECT DISTINCT category
 751                  FROM $t_mantis_bug_table
 752                  WHERE $t_project_where
 753                  ORDER BY category";
 754          $result = db_query( $query );
 755          $category_count = db_num_rows( $result );
 756  
 757          for ($i=0;$i<$category_count;$i++) {
 758              $row = db_fetch_array( $result );
 759              $cat_arr[] = string_attribute( $row['category'] );
 760          }
 761          sort( $cat_arr );
 762          $cat_arr = array_unique( $cat_arr );
 763  
 764          foreach( $cat_arr as $t_category ) {
 765              PRINT "<option value=\"$t_category\"";
 766              check_selected( $p_category, $t_category );
 767              PRINT ">$t_category</option>";
 768          }
 769      }
 770      
 771      # --------------------
 772      # Print the option list for platforms accessible for the specified user.
 773  	function print_platform_option_list( $p_platform, $p_user_id = null ) {
 774          $t_platforms_array = profile_get_field_all_for_user( 'platform', $p_user_id );
 775  
 776          foreach ( $t_platforms_array as $t_platform ) {
 777              echo "<option value=\"$t_platform\"";
 778              check_selected( $p_platform, $t_platform );
 779              echo ">$t_platform</option>";
 780          }
 781      }
 782  
 783      # --------------------
 784      # Print the option list for OSes accessible for the specified user.
 785  	function print_os_option_list( $p_os, $p_user_id = null ) {
 786          $t_os_array = profile_get_field_all_for_user( 'os', $p_user_id );
 787  
 788          foreach ( $t_os_array as $t_os ) {
 789              echo "<option value=\"$t_os\"";
 790              check_selected( $p_os, $t_os );
 791              echo ">$t_os</option>";
 792          }
 793      }
 794  
 795      # --------------------
 796      # Print the option list for os_build accessible for the specified user.
 797  	function print_os_build_option_list( $p_os_build, $p_user_id = null ) {
 798          $t_os_build_array = profile_get_field_all_for_user( 'os_build', $p_user_id );
 799  
 800          foreach ( $t_os_build_array as $t_os_build ) {
 801              echo "<option value=\"$t_os_build\"";
 802              check_selected( $p_os_build, $t_os_build );
 803              echo ">$t_os_build</option>";
 804          }
 805      }
 806  
 807      # --------------------
 808      # Print the option list for versions
 809      # $p_version = currently selected version.
 810      # $p_project_id = project id, otherwise current project will be used.
 811      # $p_released = null to get all, 1: only released, 0: only future versions
 812      # $p_leading_black = allow selection of no version
 813      # $p_with_subs = include subprojects
 814  	function print_version_option_list( $p_version='', $p_project_id = null, $p_released = null, $p_leading_blank = true, $p_with_subs=false ) {
 815          if ( null === $p_project_id ) {
 816              $c_project_id = helper_get_current_project();
 817          } else {
 818              $c_project_id = db_prepare_int( $p_project_id );
 819          }
 820  
 821          if ( $p_with_subs ) {
 822              $versions = version_get_all_rows_with_subs( $c_project_id, $p_released );
 823          } else {
 824              $versions = version_get_all_rows( $c_project_id, $p_released );
 825          }
 826  
 827          if ( $p_leading_blank ) {
 828              echo '<option value=""></option>';
 829          }
 830  
 831          foreach( $versions as $version ) {
 832              $t_version = string_attribute( $version['version'] );
 833              echo "<option value=\"$t_version\"";
 834              check_selected( $p_version, $t_version );
 835              echo '>', string_shorten( $t_version ), '</option>';
 836          }
 837      }
 838      # --------------------
 839  	function print_build_option_list( $p_build='' ) {
 840          $t_bug_table = config_get( 'mantis_bug_table' );
 841          $t_overall_build_arr = array();
 842  
 843          $t_project_id = helper_get_current_project();
 844  
 845          $t_project_where = helper_project_specific_where( $t_project_id );
 846  
 847          # Get the "found in" build list
 848          $query = "SELECT DISTINCT build
 849                  FROM $t_bug_table
 850                  WHERE $t_project_where
 851                  ORDER BY build DESC";
 852          $result = db_query( $query );
 853          $option_count = db_num_rows( $result );
 854  
 855          for ( $i = 0; $i < $option_count; $i++ ) {
 856              $row = db_fetch_array( $result );
 857              $t_overall_build_arr[] = $row['build'];
 858          }
 859  
 860          foreach( $t_overall_build_arr as $t_build ) {
 861              PRINT "<option value=\"$t_build\"";
 862              check_selected( $p_build, $t_build );
 863              PRINT ">" . string_shorten( $t_build ) . "</option>";
 864          }
 865      }
 866  
 867      # --------------------
 868      # select the proper enum values based on the input parameter
 869      # $p_enum_name - name of enumeration (eg: status)
 870      # $p_val: current value
 871  	function print_enum_string_option_list( $p_enum_name, $p_val = 0 ) {
 872          $t_config_var_name = $p_enum_name.'_enum_string';
 873          $t_config_var_value = config_get( $t_config_var_name );
 874  
 875          $t_arr  = explode_enum_string( $t_config_var_value );
 876          $t_enum_count = count( $t_arr );
 877          for ( $i = 0; $i < $t_enum_count; $i++) {
 878              $t_elem  = explode_enum_arr( $t_arr[$i] );
 879              $t_key = trim( $t_elem[0] );
 880              $t_elem2 = get_enum_element( $p_enum_name, $t_key );
 881              echo "<option value=\"$t_key\"";
 882              check_selected( $p_val, $t_key );
 883              echo ">$t_elem2</option>";
 884          } # end for
 885      }
 886      
 887      # --------------------
 888      # Select the proper enum values for status based on workflow
 889      # or the input parameter if workflows are not used
 890      # $p_enum_name : name of enumeration (eg: status)
 891      # $p_current_value : current value
 892  	function get_status_option_list( $p_user_auth = 0, $p_current_value = 0, $p_show_current = true, $p_add_close = false ) {
 893          $t_config_var_value = config_get( 'status_enum_string' );
 894          $t_enum_workflow = config_get( 'status_enum_workflow' );
 895  
 896          if ( count( $t_enum_workflow ) < 1 ) {
 897              # workflow not defined, use default enum
 898              $t_arr  = explode_enum_string( $t_config_var_value );
 899          } else {
 900              # workflow defined - find allowed states
 901              if ( isset( $t_enum_workflow[$p_current_value] ) ) {
 902                  $t_arr  = explode_enum_string( $t_enum_workflow[$p_current_value] );
 903              } else {
 904                  # workflow was not set for this status, this shouldn't happen
 905                  $t_arr  = explode_enum_string( $t_config_var_value );
 906              }
 907          }
 908  
 909          $t_enum_count = count( $t_arr );
 910          $t_enum_list = array();
 911  
 912          for ( $i = 0; $i < $t_enum_count; $i++ ) {
 913              $t_elem  = explode_enum_arr( $t_arr[$i] );
 914              if ( ( $p_user_auth >= access_get_status_threshold( $t_elem[0] ) ) &&
 915                          ( ! ( ( false == $p_show_current ) && ( $p_current_value == $t_elem[0] ) ) ) ) {
 916                  $t_enum_list[$t_elem[0]] = get_enum_element( 'status', $t_elem[0] );
 917              }
 918          } # end for
 919          if ( true == $p_show_current ) {
 920                  $t_enum_list[$p_current_value] = get_enum_element( 'status', $p_current_value );
 921              }
 922          if ( ( true == $p_add_close ) && ( $p_current_value >= config_get( 'bug_resolved_status_threshold' ) ) ) {
 923                  $t_enum_list[CLOSED] = get_enum_element( 'status', CLOSED );
 924              }
 925          return $t_enum_list;
 926      }
 927      # --------------------
 928      # print the status option list for the bug_update pages
 929  	function print_status_option_list( $p_select_label, $p_current_value = 0, $p_allow_close = false, $p_project_id = null ) {
 930          $t_current_auth = access_get_project_level( $p_project_id );
 931  
 932          $t_enum_list = get_status_option_list( $t_current_auth, $p_current_value, true, $p_allow_close );
 933  
 934          if ( count( $t_enum_list ) > 0 ) {
 935              # resort the list into ascending order
 936              ksort( $t_enum_list );
 937              reset( $t_enum_list );
 938              echo '<select ', helper_get_tab_index(), ' name="' . $p_select_label . '">';
 939              foreach ( $t_enum_list as $key => $val ) {
 940                  echo "<option value=\"$key\"";
 941                  check_selected( $key, $p_current_value );
 942                  echo ">$val</option>";
 943              }
 944              echo '</select>';
 945          } else {
 946              echo get_enum_to_string( 'status_enum_string', $p_current_value );
 947          }
 948  
 949      }
 950      # --------------------
 951      # prints the list of a project's users
 952      # if no project is specified uses the current project
 953  	function print_project_user_option_list( $p_project_id=null ) {
 954           print_user_option_list( 0, $p_project_id );
 955      }
 956      # --------------------
 957      # prints the list of access levels that are less than or equal to the access level of the
 958      # logged in user.  This is used when adding users to projects
 959  	function print_project_access_levels_option_list( $p_val, $p_project_id = null ) {
 960          $t_current_user_access_level = access_get_project_level( $p_project_id );
 961  
 962          $t_access_levels_enum_string = config_get( 'access_levels_enum_string' );
 963  
 964          # Add [default access level] to add the user to a project
 965          # with his default access level.
 966          PRINT "<option value=\"" . DEFAULT_ACCESS_LEVEL . "\"";
 967          PRINT ">[" . lang_get( 'default_access_level' ) . "]</option>";
 968  
 969          $t_arr = explode_enum_string( $t_access_levels_enum_string );
 970          $enum_count = count( $t_arr );
 971          for ($i=0;$i<$enum_count;$i++) {
 972              $t_elem = explode_enum_arr( $t_arr[$i] );
 973  
 974              # a user must not be able to assign another user an access level that is higher than theirs.
 975              if ( $t_elem[0] > $t_current_user_access_level ) {
 976                  continue;
 977              }
 978  
 979              $t_access_level = get_enum_element( 'access_levels', $t_elem[0] );
 980              PRINT "<option value=\"$t_elem[0]\"";
 981              check_selected( $p_val, $t_elem[0] );
 982              PRINT ">$t_access_level</option>";
 983          } # end for
 984      }
 985      # --------------------
 986  	function print_language_option_list( $p_language ) {
 987          $t_arr = config_get( 'language_choices_arr' );
 988          $enum_count = count( $t_arr );
 989          for ($i=0;$i<$enum_count;$i++) {
 990              $t_language = string_attribute( $t_arr[$i] );
 991              PRINT "<option value=\"$t_language\"";
 992              check_selected( $t_language, $p_language );
 993              PRINT ">$t_language</option>";
 994          } # end for
 995      }
 996      # --------------------
 997      # @@@ preliminary support for multiple bug actions.
 998  	function print_all_bug_action_option_list() {
 999          $commands = array(  'MOVE' => lang_get('actiongroup_menu_move'),
1000                              'COPY' => lang_get('actiongroup_menu_copy'),
1001                              'ASSIGN' => lang_get('actiongroup_menu_assign'),
1002                              'CLOSE' => lang_get('actiongroup_menu_close'),
1003                              'DELETE' => lang_get('actiongroup_menu_delete'),
1004                              'RESOLVE' => lang_get('actiongroup_menu_resolve'),
1005                              'SET_STICKY' => lang_get( 'actiongroup_menu_set_sticky' ),
1006                              'UP_PRIOR' => lang_get('actiongroup_menu_update_priority'),
1007                              'UP_STATUS' => lang_get('actiongroup_menu_update_status'),
1008                              'UP_CATEGORY' => lang_get('actiongroup_menu_update_category'),
1009                              'VIEW_STATUS' => lang_get( 'actiongroup_menu_update_view_status' ),
1010                              'EXT_ADD_NOTE' => lang_get( 'actiongroup_menu_add_note' ),
1011                              'EXT_ATTACH_TAGS' => lang_get( 'actiongroup_menu_attach_tags' ),
1012                      );
1013  
1014          $t_project_id = helper_get_current_project();
1015  
1016          if ( ALL_PROJECTS != $t_project_id ) {
1017              $t_user_id = auth_get_current_user_id();
1018  
1019              if ( access_has_project_level( config_get( 'update_bug_threshold' ), $t_project_id ) ) {
1020                  $commands['UP_FIXED_IN_VERSION'] = lang_get( 'actiongroup_menu_update_fixed_in_version' );
1021              }
1022  
1023              if ( access_has_project_level( config_get( 'roadmap_update_threshold' ), $t_project_id ) ) {
1024                  $commands['UP_TARGET_VERSION'] = lang_get( 'actiongroup_menu_update_target_version' );
1025              }
1026  
1027              $t_custom_field_ids = custom_field_get_linked_ids( $t_project_id );
1028  
1029              foreach( $t_custom_field_ids as $t_custom_field_id ) {
1030                  # if user has not access right to modify the field, then there is no
1031                  # point in showing it.
1032                  if ( !custom_field_has_write_access_to_project( $t_custom_field_id, $t_project_id, $t_user_id ) ) {
1033                      continue;
1034                  }
1035  
1036                  $t_custom_field_def = custom_field_get_definition( $t_custom_field_id );
1037                  $t_command_id = 'custom_field_' . $t_custom_field_id;
1038                  $t_command_caption = sprintf( lang_get( 'actiongroup_menu_update_field' ), lang_get_defaulted( $t_custom_field_def['name'] ) );
1039                  $commands[$t_command_id] = string_display( $t_command_caption );
1040              }
1041          }
1042  
1043          $t_custom_group_actions = config_get( 'custom_group_actions' );
1044  
1045          foreach( $t_custom_group_actions as $t_custom_group_action ) {
1046              # use label if provided to get the localized text, otherwise fallback to action name.
1047              if ( isset( $t_custom_group_action['label'] ) ) {
1048                  $commands[$t_custom_group_action['action']] = lang_get_defaulted( $t_custom_group_action['label'] );
1049              } else {
1050                  $commands[$t_custom_group_action['action']] = lang_get_defaulted( $t_custom_group_action['action'] );
1051              }
1052          }
1053  
1054          while (list ($key,$val) = each ($commands)) {
1055              PRINT "<option value=\"".$key."\">".$val."</option>";
1056          }
1057      }
1058      # --------------------
1059      # list of users that are NOT in the specified project and that are enabled
1060      # if no project is specified use the current project
1061      # also exclude any administrators
1062  	function print_project_user_list_option_list( $p_project_id=null ) {
1063          $t_mantis_project_user_list_table = config_get( 'mantis_project_user_list_table' );
1064          $t_mantis_user_table = config_get( 'mantis_user_table' );
1065  
1066          if ( null === $p_project_id ) {
1067              $p_project_id = helper_get_current_project();
1068          }
1069          $c_project_id = (int)$p_project_id;
1070  
1071          $t_adm = ADMINISTRATOR;
1072          $query = "SELECT DISTINCT u.id, u.username, u.realname
1073                  FROM $t_mantis_user_table u
1074                  LEFT JOIN $t_mantis_project_user_list_table p
1075                  ON p.user_id=u.id AND p.project_id='$c_project_id'
1076                  WHERE u.access_level<$t_adm AND
1077                      u.enabled = 1 AND
1078                      p.user_id IS NULL
1079                  ORDER BY u.realname, u.username";
1080          $result = db_query( $query );
1081          $t_display = array();
1082          $t_sort = array();
1083          $t_users = array();
1084          $t_show_realname = ( ON == config_get( 'show_realname' ) );
1085          $t_sort_by_last_name = ( ON == config_get( 'sort_by_last_name' ) );
1086          $category_count = db_num_rows( $result );
1087          for ($i=0;$i<$category_count;$i++) {
1088              $row = db_fetch_array( $result );
1089              $t_users[] = $row['id'];
1090              $t_user_name = string_attribute( $row['username'] );
1091              $t_sort_name = $t_user_name;
1092              if ( ( isset( $row['realname'] ) ) && ( $row['realname'] <> "" ) && $t_show_realname ) {
1093                  $t_user_name = string_attribute( $row['realname'] );
1094                  if ( $t_sort_by_last_name ) {
1095                      $t_sort_name_bits = split( ' ', strtolower( $t_user_name ), 2 );
1096                      $t_sort_name = ( isset( $t_sort_name_bits[1] ) ? $t_sort_name_bits[1] . ', ' : '' ) . $t_sort_name_bits[0];
1097                  } else {
1098                      $t_sort_name = strtolower( $t_user_name );
1099                  }
1100              }
1101              $t_display[] = $t_user_name;
1102              $t_sort[] = $t_sort_name;
1103          }
1104          array_multisort( $t_sort, SORT_ASC, SORT_STRING, $t_users, $t_display );
1105          for ($i = 0; $i < count( $t_sort ); $i++ ) {
1106              PRINT '<option value="' . $t_users[$i] . '">' . $t_display[$i] . '</option>';
1107          }
1108      }
1109      # --------------------
1110      # list of projects that a user is NOT in
1111  	function print_project_user_list_option_list2( $p_user_id ) {
1112          $t_mantis_project_user_list_table = config_get( 'mantis_project_user_list_table' );
1113          $t_mantis_project_table = config_get( 'mantis_project_table' );
1114  
1115          $c_user_id = db_prepare_int( $p_user_id );
1116  
1117          $query = "SELECT DISTINCT p.id, p.name
1118                  FROM $t_mantis_project_table p
1119                  LEFT JOIN $t_mantis_project_user_list_table u
1120                  ON p.id=u.project_id AND u.user_id='$c_user_id'
1121                  WHERE p.enabled=1 AND
1122                      u.user_id IS NULL
1123                  ORDER BY p.name";
1124          $result = db_query( $query );
1125          $category_count = db_num_rows( $result );
1126          for ($i=0;$i<$category_count;$i++) {
1127              $row = db_fetch_array( $result );
1128              $t_project_name    = string_attribute( $row['name'] );
1129              $t_user_id            = $row['id'];
1130              PRINT "<option value=\"$t_user_id\">$t_project_name</option>";
1131          }
1132      }
1133      # --------------------
1134      # list of projects that a user is in
1135  	function print_project_user_list( $p_user_id, $p_include_remove_link = true ) {
1136          $t_mantis_project_user_list_table = config_get( 'mantis_project_user_list_table' );
1137          $t_mantis_project_table = config_get( 'mantis_project_table' );
1138  
1139          $c_user_id = db_prepare_int( $p_user_id );
1140  
1141          $query = "SELECT DISTINCT p.id, p.name, p.view_state, u.access_level
1142                  FROM $t_mantis_project_table p
1143                  LEFT JOIN $t_mantis_project_user_list_table u
1144                  ON p.id=u.project_id
1145                  WHERE p.enabled=1 AND
1146                      u.user_id='$c_user_id'
1147                  ORDER BY p.name";
1148          $result = db_query( $query );
1149          $category_count = db_num_rows( $result );
1150          for ($i=0;$i<$category_count;$i++) {
1151              $row = db_fetch_array( $result );
1152              $t_project_id    = $row['id'];
1153              $t_project_name    = $row['name'];
1154              $t_view_state    = $row['view_state'];
1155              $t_access_level    = $row['access_level'];
1156              $t_access_level    = get_enum_element( 'access_levels', $t_access_level );
1157              $t_view_state    = get_enum_element( 'project_view_state', $t_view_state );
1158  
1159              echo $t_project_name.' ['.$t_access_level.'] ('.$t_view_state.')';
1160              if ( $p_include_remove_link && access_has_project_level( config_get( 'project_user_threshold' ), $t_project_id ) ) {
1161                  echo ' [<a class="small" href="manage_user_proj_delete.php?project_id='.$t_project_id.'&amp;user_id='.$p_user_id.'">'. lang_get( 'remove_link' ).'</a>]';
1162              }
1163              echo '<br />';
1164          }
1165      }
1166      
1167      # --------------------
1168      # List of projects with which the specified field id is linked.
1169      # For every project, the project name is listed and then the list of custom 
1170      # fields linked in order with their sequence numbers.  The specified field
1171      # is always highlighted in italics and project names in bold.
1172      #
1173      # $p_field_id - The field to list the projects associated with.
1174  	function print_custom_field_projects_list( $p_field_id ) {
1175          $c_field_id = (integer)$p_field_id;
1176          $t_project_ids = custom_field_get_project_ids( $p_field_id );
1177  
1178          foreach ( $t_project_ids as $t_project_id ) {
1179              $t_project_name = project_get_field( $t_project_id, 'name' );
1180              $t_sequence = custom_field_get_sequence( $p_field_id, $t_project_id );
1181              echo '<b>', $t_project_name, '</b>: ';
1182              print_bracket_link( "manage_proj_custom_field_remove.php?field_id=$c_field_id&amp;project_id=$t_project_id&amp;return=custom_field", lang_get( 'remove_link' ) );
1183              echo '<br />- ';
1184              
1185              $t_linked_field_ids = custom_field_get_linked_ids( $t_project_id );
1186  
1187              $t_current_project_fields = array();
1188  
1189              $t_first = true;
1190              foreach ( $t_linked_field_ids as $t_current_field_id ) {
1191                  if ( $t_first ) {
1192                      $t_first = false;
1193                  } else {
1194                      echo ', ';
1195                  }
1196  
1197                  if ( $t_current_field_id == $p_field_id ) {
1198                      echo '<em>';
1199                  }
1200  
1201                  echo string_display( custom_field_get_field( $t_current_field_id, 'name' ) );
1202                  echo ' (', custom_field_get_sequence( $t_current_field_id, $t_project_id ), ')';
1203  
1204                  if ( $t_current_field_id == $p_field_id ) {
1205                      echo '</em>';
1206                  }
1207              }
1208  
1209              echo '<br /><br />';
1210          }
1211      }
1212  
1213      # --------------------
1214      ###########################################################################
1215      # String printing API
1216      ###########################################################################
1217      # --------------------
1218      # prints a link to VIEW a bug given an ID
1219      #  account for the user preference and site override
1220  	function print_bug_link( $p_bug_id, $p_detail_info = true ) {
1221          PRINT string_get_bug_view_link( $p_bug_id, null, $p_detail_info );
1222      }
1223  
1224      # --------------------
1225      # prints a link to UPDATE a bug given an ID
1226      #  account for the user preference and site override
1227  	function print_bug_update_link( $p_bug_id ) {
1228          PRINT string_get_bug_update_link( $p_bug_id );
1229      }
1230  
1231       # --------------------
1232      # formats the priority given the status
1233      # shows the priority in BOLD if the bug is NOT closed and is of significant priority
1234  	function print_formatted_priority_string( $p_status, $p_priority ) {
1235          $t_pri_str = get_enum_element( 'priority', $p_priority );
1236  
1237          if ( ( HIGH <= $p_priority ) &&
1238               ( CLOSED != $p_status ) ) {
1239              PRINT "<span class=\"bold\">$t_pri_str</span>";
1240          } else {
1241              PRINT $t_pri_str;
1242          }
1243      }
1244  
1245      # --------------------
1246      # formats the severity given the status
1247      # shows the severity in BOLD if the bug is NOT closed and is of significant severity
1248  	function print_formatted_severity_string( $p_status, $p_severity ) {
1249          $t_sev_str = get_enum_element( 'severity', $p_severity );
1250  
1251          if ( ( MAJOR <= $p_severity ) &&
1252               ( CLOSED != $p_status ) ) {
1253              PRINT "<span class=\"bold\">$t_sev_str</span>";
1254          } else {
1255              PRINT $t_sev_str;
1256          }
1257      }
1258      # --------------------
1259  	function print_project_category_string( $p_project_id ) {
1260          $t_mantis_project_category_table = config_get( 'mantis_project_category_table' );
1261  
1262          $c_project_id = db_prepare_int( $p_project_id );
1263  
1264          $query = "SELECT category
1265                  FROM $t_mantis_project_category_table
1266                  WHERE project_id='$c_project_id'
1267                  ORDER BY category";
1268          $result = db_query( $query );
1269          $category_count = db_num_rows( $result );
1270          $t_string = '';
1271  
1272          for ($i=0;$i<$category_count;$i++) {
1273              $row = db_fetch_array( $result );
1274              $t_category = $row['category'];
1275  
1276              if ( $i+1 < $category_count ) {
1277                  $t_string .= $t_category.', ';
1278              } else {
1279                  $t_string .= $t_category;
1280              }
1281          }
1282  
1283          return $t_string;
1284      }
1285      # --------------------
1286  	function print_project_version_string( $p_project_id ) {
1287          $t_mantis_project_version_table = config_get( 'mantis_project_version_table' );
1288          $t_mantis_project_table = config_get( 'mantis_project_table' );
1289  
1290          $c_project_id = db_prepare_int( $p_project_id );
1291  
1292          $query = "SELECT version
1293                  FROM $t_mantis_project_version_table
1294                  WHERE project_id='$c_project_id'";
1295          $result = db_query( $query );
1296          $version_count = db_num_rows( $result );
1297          $t_string = '';
1298  
1299          for ($i=0;$i<$version_count;$i++) {
1300              $row = db_fetch_array( $result );
1301              $t_version = $row['version'];
1302  
1303              if ( $i+1 < $version_count ) {
1304                  $t_string .= $t_version.', ';
1305              } else {
1306                  $t_string .= $t_version;
1307              }
1308          }
1309  
1310          return $t_string;
1311      }
1312      # --------------------
1313      ###########################################################################
1314      # Link Printing API
1315      ###########################################################################
1316      # --------------------
1317      # $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
1318  	function print_view_bug_sort_link( $p_string, $p_sort_field, $p_sort, $p_dir, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
1319          if ( $p_columns_target == COLUMNS_TARGET_PRINT_PAGE ) {
1320              if ( $p_sort_field == $p_sort ) {
1321                  # We toggle between ASC and DESC if the user clicks the same sort order
1322                  if ( 'ASC' == $p_dir ) {
1323                      $p_dir = 'DESC';
1324                  } else {
1325                      $p_dir = 'ASC';
1326                  }
1327              } else {                        # Otherwise always start with ASCending
1328                  $t_dir = 'ASC';
1329              }
1330  
1331              echo '<a href="view_all_set.php?sort='.$p_sort_field.'&amp;dir='.$p_dir.'&amp;type=2&amp;print=1">'.$p_string.'</a>';
1332          } else if ( $p_columns_target == COLUMNS_TARGET_VIEW_PAGE ) {
1333              if ( $p_sort_field == $p_sort ) {
1334                  # we toggle between ASC and DESC if the user clicks the same sort order
1335                  if ( 'ASC' == $p_dir ) {
1336                      $p_dir = 'DESC';
1337                  } else {
1338                      $p_dir = 'ASC';
1339                  }
1340              } else {                        # Otherwise always start with ASCending
1341                  $t_dir = 'ASC';
1342              }
1343  
1344              echo '<a href="view_all_set.php?sort='.$p_sort_field.'&amp;dir='.$p_dir.'&amp;type=2">'.$p_string.'</a>';
1345          } else {
1346              echo $p_string;
1347          }
1348      }
1349      # --------------------
1350  	function print_manage_user_sort_link( $p_page, $p_string, $p_field, $p_dir, $p_sort_by, $p_hide=0 ) {
1351          if ( $p_sort_by == $p_field ) {   # If this is the selected field flip the order
1352              if ( 'ASC' == $p_dir || ASCENDING == $p_dir ) {
1353                  $t_dir = 'DESC';
1354              } else {
1355                  $t_dir = 'ASC';
1356              }
1357          } else {                        # Otherwise always start with ASCending
1358              $t_dir = 'ASC';
1359          }
1360  
1361          PRINT '<a href="' . $p_page . '?sort=' . $p_field . '&amp;dir=' . $t_dir . '&amp;save=1&amp;hide=' . $p_hide . '">' . $p_string . '</a>';
1362      }
1363      # --------------------
1364  	function print_manage_project_sort_link( $p_page, $p_string, $p_field, $p_dir, $p_sort_by ) {
1365          if ( $p_sort_by == $p_field ) {   # If this is the selected field flip the order
1366              if ( 'ASC' == $p_dir || ASCENDING == $p_dir ) {
1367                  $t_dir = 'DESC';
1368              } else {
1369                  $t_dir = 'ASC';
1370              }
1371          } else {                        # Otherwise always start with ASCending
1372              $t_dir = 'ASC';
1373          }
1374  
1375          PRINT '<a href="' . $p_page . '?sort=' . $p_field . '&amp;dir=' . $t_dir . '">' . $p_string . '</a>';
1376      }
1377      # --------------------
1378      # print a button which presents a standalone form.
1379      # $p_action_page - The action page
1380      # $p_label - The button label
1381      # $p_args_to_post - An associative array with key => value to be posted, can be null.
1382  	function print_button( $p_action_page, $p_label, $p_args_to_post = null ) {
1383          echo '<form method="post" action="', $p_action_page, '">';
1384          echo '<input type="submit" class="button-small" value="', $p_label, '" />';
1385          
1386          if ( $p_args_to_post !== null ) {
1387              foreach( $p_args_to_post as $t_var => $t_value ) {
1388                  echo "<input type=\"hidden\" name=\"$t_var\" value=\"$t_value\" />";
1389              }
1390          }
1391  
1392          echo '</form>';
1393      }
1394      # --------------------
1395      # print the bracketed links used near the top
1396      # if the $p_link is blank then the text is printed but no link is created
1397      # if $p_new_window is true, link will open in a new window, default false.
1398  	function print_bracket_link( $p_link, $p_url_text, $p_new_window = false ) {
1399          PRINT '<span class="bracket-link">[&nbsp;';
1400          if (is_blank( $p_link )) {
1401              PRINT $p_url_text;
1402          } else {
1403              if( true == $p_new_window ) {
1404                  PRINT "<a href=\"$p_link\" target=\"_blank\">$p_url_text</a>";
1405              } else {
1406                  PRINT "<a href=\"$p_link\">$p_url_text</a>";
1407              }
1408          }
1409          PRINT '&nbsp;]</span> ';
1410      }
1411      # --------------------
1412      # print a HTML link
1413  	function print_link( $p_link, $p_url_text ) {
1414          if (is_blank( $p_link )) {
1415              PRINT " $p_url_text ";
1416          } else {
1417              PRINT " <a href=\"$p_link\">$p_url_text</a> ";
1418          }
1419      }
1420      # --------------------
1421      # print a HTML page link
1422  	function print_page_link( $p_page_url, $p_text = '', $p_page_no=0, $p_page_cur=0, $p_temp_filter_id = 0 ) {
1423          if (is_blank( $p_text )) {
1424              $p_text = $p_page_no;
1425          }
1426  
1427          if ( ( 0 < $p_page_no ) && ( $p_page_no != $p_page_cur ) ) {
1428              if ( $p_temp_filter_id > 0 ) {
1429                  PRINT " <a href=\"$p_page_url?filter=$p_temp_filter_id&amp;page_number=$p_page_no\">$p_text</a> ";        
1430              } else {
1431                  PRINT " <a href=\"$p_page_url?page_number=$p_page_no\">$p_text</a> ";        
1432              }
1433          
1434          } else {
1435              PRINT " $p_text ";
1436          }
1437      }
1438      # --------------------
1439      # print a list of page number links (eg [1 2 3])
1440  	function print_page_links( $p_page, $p_start, $p_end, $p_current,$p_temp_filter_id = 0 ) {
1441          $t_items = array();
1442          $t_link = '';
1443  
1444          # Check if we have more than one page,
1445          #  otherwise return without doing anything.
1446  
1447          if ( $p_end - $p_start < 1 ) {
1448              return;
1449          }
1450  
1451          # Get localized strings
1452          $t_first = lang_get( 'first' );
1453          $t_last  = lang_get( 'last' );
1454          $t_prev  = lang_get( 'prev' );
1455          $t_next  = lang_get( 'next' );
1456  
1457          $t_page_links = 10;
1458  
1459          print( "[ " );
1460  
1461          # First and previous links
1462          print_page_link( $p_page, $t_first, 1, $p_current, $p_temp_filter_id );
1463          print_page_link( $p_page, $t_prev, $p_current - 1, $p_current, $p_temp_filter_id );
1464  
1465          # Page numbers ...
1466  
1467          $t_first_page = max( $p_start, $p_current - $t_page_links/2 );
1468          $t_first_page = min( $t_first_page, $p_end - $t_page_links );
1469          $t_first_page = max( $t_first_page, $p_start );
1470  
1471          if ( $t_first_page > 1 ) {
1472              print( " ... " );
1473          }
1474  
1475          $t_last_page = $t_first_page + $t_page_links;
1476          $t_last_page = min( $t_last_page, $p_end );
1477  
1478          for ( $i = $t_first_page ; $i <= $t_last_page ; $i++ ) {
1479              if ( $i == $p_current ) {
1480                  array_push( $t_items, $i );
1481              } else {
1482                  if ( $p_temp_filter_id > 0 ) {
1483                      array_push( $t_items, "<a href=\"$p_page?filter=$p_temp_filter_id&amp;page_number=$i\">$i</a>" );                
1484                  } else {
1485                      array_push( $t_items, "<a href=\"$p_page?page_number=$i\">$i</a>" );
1486                  }
1487              }
1488          }
1489          PRINT implode( '&nbsp;', $t_items );
1490  
1491          if ( $t_last_page < $p_end ) {
1492              print( " ... " );
1493          }
1494  
1495          # Next and Last links
1496          if ( $p_current < $p_end ) {
1497              print_page_link( $p_page, $t_next, $p_current + 1, $p_current, $p_temp_filter_id );
1498          } else {
1499              print_page_link( $p_page, $t_next, null, null, $p_temp_filter_id );
1500          }
1501          print_page_link( $p_page, $t_last, $p_end, $p_current, $p_temp_filter_id );
1502  
1503          print( " ]" );
1504      }
1505      # --------------------
1506      # print a mailto: href link
1507  	function print_email_link( $p_email, $p_text ) {
1508          PRINT get_email_link($p_email, $p_text);
1509      }
1510      # --------------------
1511      # return the mailto: href string link instead of printing it
1512  	function get_email_link( $p_email, $p_text ) {
1513          return prepare_email_link( $p_email, $p_text );
1514      }
1515      # --------------------
1516      # print a mailto: href link with subject
1517  	function print_email_link_with_subject( $p_email, $p_text, $p_bug_id ) {
1518          $t_subject = email_build_subject( $p_bug_id );
1519          PRINT get_email_link_with_subject( $p_email, $p_text, $t_subject );
1520      }
1521      # --------------------
1522      # return the mailto: href string link instead of printing it
1523      # add subject line
1524  	function get_email_link_with_subject( $p_email, $p_text, $p_summary ) {
1525          if ( !access_has_project_level( config_get( 'show_user_email_threshold' ) ) ) {
1526              return $p_text;
1527          }
1528  
1529          # If we apply string_url() to the whole mailto: link then the @
1530          #  gets turned into a %40 and you can't right click in browsers to
1531          #  do Copy Email Address.  If we don't apply string_url() to the
1532          #  summary text then an ampersand (for example) will truncate the text
1533          $p_summary    = string_url( $p_summary );
1534          $t_mailto    = string_attribute( "mailto:$p_email?subject=$p_summary" );
1535          $p_text        = string_display( $p_text );
1536  
1537          return "<a href=\"$t_mailto\">$p_text</a>";
1538      }
1539      # --------------------
1540      # Print a hidden input for each name=>value pair in the array
1541      #
1542      # If a value is an array an input will be created for each item with a name
1543      #  that ends with []
1544      # The names and values are passed through htmlspecialchars() before being displayed
1545  	function print_hidden_inputs( $p_assoc_array ) {
1546          foreach ( $p_assoc_array as $key => $val ) {
1547              $key = string_html_specialchars( $key );
1548              if ( is_array( $val ) ) {
1549                  foreach ( $val as $val2 ) {
1550                      $val2 = string_html_specialchars( $val2 );
1551                      PRINT "<input type=\"hidden\" name=\"$val\[\]\" value=\"$val2\" />\n";
1552                  }
1553              } else {
1554                  $val = string_html_specialchars( $val );
1555                  PRINT "<input type=\"hidden\" name=\"$key\" value=\"$val\" />\n";
1556              }
1557          }
1558      }
1559  
1560  
1561      #=============================
1562      # Functions that used to be in html_api
1563      #=============================
1564  
1565      # --------------------
1566      # This prints the little [?] link for user help
1567      # The $p_a_name is a link into the documentation.html file
1568  	function print_documentation_link( $p_a_name='' ) {
1569          # @@@ Disable documentation links for now.  May be re-enabled if linked to new manual.
1570          # PRINT "<a href=\"doc/documentation.html#$p_a_name\" target=\"_info\">[?]</a>";
1571      }
1572       # --------------------
1573      # print the hr
1574  	function print_hr( $p_hr_size=null, $p_hr_width=null ) {
1575          if ( null === $p_hr_size ) {
1576              $p_hr_size = config_get( 'hr_size' );
1577          }
1578          if ( null === $p_hr_width ) {
1579              $p_hr_width = config_get( 'hr_width' );
1580          }
1581          PRINT "<hr size=\"$p_hr_size\" width=\"$p_hr_width%\" />";
1582      }
1583      # --------------------
1584      # prints the signup link
1585  	function print_signup_link() {
1586          if( ( ON == config_get( 'allow_signup' ) ) &&
1587              ( ON == config_get( 'enable_email_notification' ) ) ) {
1588              print_bracket_link( 'signup_page.php', lang_get( 'signup_link' ) );
1589          }
1590      }
1591      # --------------------
1592      # prints the login link
1593  	function print_login_link() {
1594          print_bracket_link( 'login_page.php', lang_get( 'login_title' ) );
1595      }
1596      # --------------------
1597      # prints the lost pwd link
1598  	function print_lost_password_link() {
1599          # lost password feature disabled or reset password via email disabled -> stop here!
1600          if( ( ON == config_get( 'lost_password_feature' ) ) &&
1601              ( ON == config_get( 'send_reset_password' ) ) &&
1602              ( ON == config_get( 'enable_email_notification' ) ) ) {
1603              print_bracket_link( 'lost_pwd_page.php', lang_get( 'lost_password_link' ) );
1604          }
1605      }
1606      # --------------------
1607  	function print_proceed( $p_result, $p_query, $p_link ) {
1608          PRINT '<br />';
1609          PRINT '<div align="center">';
1610          if ( $p_result ) {                        # SUCCESS
1611              PRINT lang_get( 'operation_successful' ) . '<br />';
1612          } else {                                # FAILURE
1613              print_sql_error( $p_query );
1614          }
1615          print_bracket_link( $p_link, lang_get( 'proceed' ) );
1616          PRINT '</div>';
1617      }
1618  
1619  
1620      #===============================
1621      # Deprecated Functions
1622      #===============================
1623  
1624      # --------------------
1625      # print our standard mysql query error
1626      # this function should rarely (if ever) be reached.  instead the db_()
1627      # functions should trap (although inelegantly).
1628  	function print_sql_error( $p_query ) {
1629          global $g_administrator_email;
1630  
1631          PRINT error_string( ERROR_SQL );
1632          print_email_link( $g_administrator_email, lang_get( 'administrator' ) );
1633          PRINT "<br />$p_query;<br />";
1634      }
1635      # --------------------
1636      # Get icon corresponding to the specified filename
1637  	function print_file_icon( $p_filename ) {
1638          $t_file_type_icons = config_get( 'file_type_icons' );
1639  
1640          $ext = strtolower( file_get_extension( $p_filename ) );
1641          if ( is_blank( $ext ) || !isset( $t_file_type_icons[$ext] ) ) {
1642              $ext = '?';
1643          }
1644  
1645          $t_name = $t_file_type_icons[$ext];
1646          PRINT '<img src="' . config_get( 'path' ) . 'images/fileicons/'. $t_name .
1647              '" alt="' . $ext . ' file icon" width="16" height="16" border="0" />';
1648      }
1649  
1650      # --------------------
1651      # Prints an RSS image that is hyperlinked to an RSS feed.
1652  	function print_rss( $p_feed_url, $p_title = '' ) {
1653          $t_path = config_get( 'path' );
1654          echo '<a href="', $p_feed_url, '" title="', $p_title, '"><img src="', $t_path, '/images/', 'rss.gif" border="0" alt="', $p_title, '" width="26" height="13" /></a>';
1655      }
1656  
1657      # --------------------
1658      # Prints the recently visited issues.
1659  	function print_recently_visited() {
1660          if ( !last_visited_enabled() ) {
1661              return;
1662          }
1663  
1664          $t_ids = last_visited_get_array();
1665          
1666          if ( count( $t_ids ) == 0 ) {
1667              return;
1668          }
1669  
1670          echo '<div align="right"><small>' . lang_get( 'recently_visited' ) . ': ';        
1671          $t_first = true;
1672  
1673          foreach( $t_ids as $t_id ) {
1674              if ( !$t_first ) {
1675                  echo ', ';
1676              } else {
1677                  $t_first = false;
1678              }
1679  
1680              echo string_get_bug_view_link( $t_id );
1681          }
1682          echo '</small></div>';
1683      }
1684  
1685  
1686      # ----------------------
1687      # print a dropdown box from input array
1688  	function get_dropdown( $p_control_array, $p_control_name, $p_match = '', $p_add_any=false, $p_multiple=false, $p_change_script = '') {
1689          $t_control_array = $p_control_array;
1690          if ( $p_multiple ){
1691              $t_size = ' SIZE="5"';
1692              $t_multiple = ' MULTIPLE';
1693          } else {
1694              $t_size = '';
1695              $t_multiple = '';
1696          }
1697          $t_script = ($p_change_script == '' ? '' : ' onchange="'.$p_change_script.'"');
1698          $t_info = sprintf("<SELECT %s NAME=\"%s\" id=\"%s\"%s%s>", 
1699              $t_multiple, $p_control_name, $p_control_name, $t_size, $t_script);
1700          if ( $p_add_any ) {
1701              array_unshift_assoc( $t_control_array, FILTER_META_ANY, lang_trans( '[any]' ) );
1702          }
1703          while( list( $t_name, $t_desc ) = each( $t_control_array ) ) {
1704              $t_sel = "";
1705              if( is_array( $p_match ) ) {
1706                  if( in_array( $t_name, array_values( $p_match ) ) || 
1707                          in_array( $t_desc, array_values( $p_match ) ) ) {
1708                      $t_sel = " SELECTED";
1709                  }
1710              } else {
1711                  if( ( $t_name === $p_match ) || ( $t_desc === $p_match ) ) {
1712                      $t_sel = " SELECTED";
1713                  }
1714              }
1715              $t_info .= sprintf("<OPTION%s VALUE=\"%s\">%s", $t_sel, $t_name, $t_desc);
1716          }
1717          $t_info .= "</SELECT>\n";
1718          return $t_info;
1719      }
1720      
1721  ?>


Généré le : Thu Nov 29 09:42:17 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics