[ 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/ -> filter_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: filter_api.php,v 1.163.2.1 2007-10-13 22:35:27 giallu Exp $
  22      # --------------------------------------------------------
  23  
  24      $t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR;
  25  
  26      require_once ( $t_core_dir . 'current_user_api.php' );
  27      require_once ( $t_core_dir . 'user_api.php' );
  28      require_once ( $t_core_dir . 'bug_api.php' );
  29      require_once ( $t_core_dir . 'collapse_api.php' );
  30      require_once ( $t_core_dir . 'relationship_api.php' );
  31      require_once ( $t_core_dir . 'tag_api.php' );
  32  
  33      ###########################################################################
  34      # Filter Property Names
  35      ###########################################################################
  36  
  37      define( 'FILTER_PROPERTY_FREE_TEXT', 'search' );
  38      define( 'FILTER_PROPERTY_CATEGORY', 'show_category' );
  39      define( 'FILTER_PROPERTY_SEVERITY_ID', 'show_severity' );
  40      define( 'FILTER_PROPERTY_STATUS_ID', 'show_status' );
  41      define( 'FILTER_PROPERTY_PRIORITY_ID', 'show_priority' );
  42      define( 'FILTER_PROPERTY_HIGHLIGHT_CHANGED', 'highlight_changed' );
  43      define( 'FILTER_PROPERTY_REPORTER_ID', 'reporter_id' );
  44      define( 'FILTER_PROPERTY_HANDLER_ID', 'handler_id' );
  45      define( 'FILTER_PROPERTY_PROJECT_ID', 'project_id' );
  46      define( 'FILTER_PROPERTY_RESOLUTION_ID', 'show_resolution' );
  47      define( 'FILTER_PROPERTY_PRODUCT_BUILD', 'show_build' );
  48      define( 'FILTER_PROPERTY_PRODUCT_VERSION', 'show_version' );
  49      define( 'FILTER_PROPERTY_MONITOR_USER_ID', 'user_monitor' );
  50      define( 'FILTER_PROPERTY_HIDE_STATUS_ID', 'hide_status' );
  51      define( 'FILTER_PROPERTY_SORT_FIELD_NAME', 'sort' );
  52      define( 'FILTER_PROPERTY_SORT_DIRECTION', 'dir' );
  53      define( 'FILTER_PROPERTY_SHOW_STICKY_ISSUES', 'sticky_issues' );
  54      define( 'FILTER_PROPERTY_VIEW_STATE_ID', 'view_state' );
  55      define( 'FILTER_PROPERTY_FIXED_IN_VERSION', 'fixed_in_version' );
  56      define( 'FILTER_PROPERTY_TARGET_VERSION', 'target_version' );
  57      define( 'FILTER_PROPERTY_ISSUES_PER_PAGE', 'per_page' );
  58      define( 'FILTER_PROPERTY_PROFILE', 'profile_id' );
  59      define( 'FILTER_PROPERTY_PLATFORM', 'platform' );
  60      define( 'FILTER_PROPERTY_OS', 'os' );
  61      define( 'FILTER_PROPERTY_OS_BUILD', 'os_build' );
  62      define( 'FILTER_PROPERTY_START_DAY', 'start_day' );
  63      define( 'FILTER_PROPERTY_START_MONTH', 'start_month' );
  64      define( 'FILTER_PROPERTY_START_YEAR', 'start_year' );
  65      define( 'FILTER_PROPERTY_END_DAY', 'end_day' );
  66      define( 'FILTER_PROPERTY_END_MONTH', 'end_month' );
  67      define( 'FILTER_PROPERTY_END_YEAR', 'end_year' );
  68      define( 'FILTER_PROPERTY_NOT_ASSIGNED', 'and_not_assigned' );
  69      define( 'FILTER_PROPERTY_FILTER_BY_DATE', 'do_filter_by_date' );
  70      define( 'FILTER_PROPERTY_RELATIONSHIP_TYPE', 'relationship_type' );
  71      define( 'FILTER_PROPERTY_RELATIONSHIP_BUG', 'relationship_bug' );
  72      define( 'FILTER_PROPERTY_TAG_STRING', 'tag_string' );
  73      define( 'FILTER_PROPERTY_TAG_SELECT', 'tag_select' );
  74  
  75      ###########################################################################
  76      # Filter Query Parameter Names
  77      ###########################################################################
  78  
  79      define( 'FILTER_SEARCH_FREE_TEXT', 'search' );
  80      define( 'FILTER_SEARCH_CATEGORY', 'category' );
  81      define( 'FILTER_SEARCH_SEVERITY_ID', 'severity_id');
  82      define( 'FILTER_SEARCH_STATUS_ID', 'status_id' );
  83      define( 'FILTER_SEARCH_REPORTER_ID', 'reporter_id' );
  84      define( 'FILTER_SEARCH_HANDLER_ID', 'handler_id' );
  85      define( 'FILTER_SEARCH_PROJECT_ID', 'project_id' );
  86      define( 'FILTER_SEARCH_RESOLUTION_ID', 'resolution_id' );
  87      define( 'FILTER_SEARCH_FIXED_IN_VERSION', 'fixed_in_version' );
  88      define( 'FILTER_SEARCH_TARGET_VERSION', 'target_version' );
  89      define( 'FILTER_SEARCH_START_DAY', 'start_day' );
  90      define( 'FILTER_SEARCH_START_MONTH', 'start_month' );
  91      define( 'FILTER_SEARCH_START_YEAR', 'start_year' );
  92      define( 'FILTER_SEARCH_END_DAY', 'end_day' );
  93      define( 'FILTER_SEARCH_END_MONTH', 'end_month' );
  94      define( 'FILTER_SEARCH_END_YEAR', 'end_year' );
  95      define( 'FILTER_SEARCH_PRIORITY_ID', 'priority_id' );
  96      define( 'FILTER_SEARCH_PROFILE', 'profile_id' );
  97      define( 'FILTER_SEARCH_PLATFORM', 'platform' );
  98      define( 'FILTER_SEARCH_OS', 'os' );
  99      define( 'FILTER_SEARCH_OS_BUILD', 'os_build' );
 100      define( 'FILTER_SEARCH_MONITOR_USER_ID', 'monitor_user_id' );
 101      define( 'FILTER_SEARCH_PRODUCT_BUILD', 'product_build' );
 102      define( 'FILTER_SEARCH_PRODUCT_VERSION', 'product_version' );
 103      define( 'FILTER_SEARCH_VIEW_STATE_ID', 'view_state_id' );
 104      define( 'FILTER_SEARCH_SHOW_STICKY_ISSUES', 'sticky_issues' );
 105      define( 'FILTER_SEARCH_SORT_FIELD_NAME', 'sortby' );
 106      define( 'FILTER_SEARCH_SORT_DIRECTION', 'dir' );
 107      define( 'FILTER_SEARCH_ISSUES_PER_PAGE', 'per_page' );
 108      define( 'FILTER_SEARCH_HIGHLIGHT_CHANGED', 'highlight_changed' );
 109      define( 'FILTER_SEARCH_HIDE_STATUS_ID', 'hide_status_id' );
 110      define( 'FILTER_SEARCH_NOT_ASSIGNED', 'not_assigned' );
 111      define( 'FILTER_SEARCH_FILTER_BY_DATE', 'filter_by_date' );
 112      define( 'FILTER_SEARCH_RELATIONSHIP_TYPE', 'relationship_type' );
 113      define( 'FILTER_SEARCH_RELATIONSHIP_BUG', 'relationship_bug' );
 114      define( 'FILTER_SEARCH_TAG_STRING', 'tag_string' );
 115      define( 'FILTER_SEARCH_TAG_SELECT', 'tag_select' );
 116  
 117      # Checks the supplied value to see if it is an ANY value.
 118      # $p_field_value - The value to check.
 119      # Returns true for "ANY" values and false for others.  "ANY" means filter criteria not active.
 120  	function filter_str_field_is_any( $p_field_value ) {
 121          if ( is_array( $p_field_value ) ) {
 122              if ( count( $p_field_value ) == 0 ) {
 123                  return true;
 124              }
 125  
 126              foreach( $p_field_value as $t_value ) {
 127                  if ( ( META_FILTER_ANY == $t_value ) && ( is_numeric( $t_value ) ) ) {
 128                      return true;
 129                  }
 130              }
 131          } else {
 132              if ( is_string( $p_field_value ) && is_blank( $p_field_value ) ) {
 133                  return true;
 134              }
 135              
 136              if ( is_bool( $p_field_value ) && !$p_field_value ) {
 137                  return true;
 138              }
 139  
 140              if ( ( META_FILTER_ANY == $p_field_value ) && ( is_numeric( $p_field_value ) ) ) {
 141                  return true;
 142              }
 143          }
 144  
 145          return false;
 146      }
 147  
 148      # Encodes a field and it's value for the filter URL.  This handles the URL encoding
 149      # and arrays.
 150      # $p_field_name - The field name.
 151      # $p_field_value - The field value (can be an array)
 152  	function filter_encode_field_and_value( $p_field_name, $p_field_value ) {
 153          $t_query_array = array();        
 154          if ( is_array( $p_field_value ) ) {
 155              $t_count = count( $p_field_value );
 156              if ( $t_count > 1 ) {
 157                  foreach ( $p_field_value as $t_value ) {
 158                      $t_query_array[] = urlencode( $p_field_name . '[]' ) . '=' . urlencode( $t_value );
 159                  }
 160              } else if ( $t_count == 1 ) {
 161                  $t_query_array[] = urlencode( $p_field_name ) . '=' . urlencode( $p_field_value[0] );
 162              }
 163          } else {
 164              $t_query_array[] = urlencode( $p_field_name ) . '=' . urlencode( $p_field_value );
 165          }
 166  
 167          return implode( $t_query_array, '&amp;' );
 168      }
 169  
 170      # Get a permalink for the current active filter.  The results of using these fields by other users
 171      # can be inconsistent with the original results due to fields like "Myself", "Current Project",
 172      # and due to access level.
 173      # Returns the search.php?xxxx or an empty string if no criteria applied. 
 174  	function filter_get_url( $p_custom_filter ) {
 175          $t_query = array();
 176  
 177          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_PROJECT_ID] ) ) {
 178              $t_project_id = $p_custom_filter[FILTER_PROPERTY_PROJECT_ID];
 179  
 180              if ( count( $t_project_id ) == 1 && $t_project_id[0] == META_FILTER_CURRENT ) {
 181                  $t_project_id = array( helper_get_current_project() );
 182              }
 183  
 184              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_PROJECT_ID, $t_project_id );
 185          }
 186  
 187          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_FREE_TEXT] ) ) {
 188              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_FREE_TEXT, $p_custom_filter[FILTER_PROPERTY_FREE_TEXT] );
 189          }
 190  
 191          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_CATEGORY] ) ) {
 192              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_CATEGORY, $p_custom_filter[FILTER_PROPERTY_CATEGORY] );
 193          }
 194  
 195          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_REPORTER_ID] ) ) {
 196              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_REPORTER_ID, $p_custom_filter[FILTER_PROPERTY_REPORTER_ID] );
 197          }
 198  
 199          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_STATUS_ID] ) ) {
 200              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_STATUS_ID, $p_custom_filter[FILTER_PROPERTY_STATUS_ID] );
 201          }
 202  
 203          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_MONITOR_USER_ID] ) ) {
 204              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_MONITOR_USER_ID, $p_custom_filter[FILTER_PROPERTY_MONITOR_USER_ID] );
 205          }
 206  
 207          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_HANDLER_ID] ) ) {
 208              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_HANDLER_ID, $p_custom_filter[FILTER_PROPERTY_HANDLER_ID] );
 209          }
 210  
 211          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_SEVERITY_ID] ) ) {
 212              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_SEVERITY_ID, $p_custom_filter[FILTER_PROPERTY_SEVERITY_ID] );
 213          }
 214  
 215          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_RESOLUTION_ID] ) ) {
 216              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_RESOLUTION_ID, $p_custom_filter[FILTER_PROPERTY_RESOLUTION_ID] );
 217          }
 218  
 219          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_PRIORITY_ID] ) ) {
 220              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_PRIORITY_ID, $p_custom_filter[FILTER_PROPERTY_PRIORITY_ID] );
 221          }
 222  
 223          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_VIEW_STATE_ID] ) ) {
 224              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_VIEW_STATE_ID, $p_custom_filter[FILTER_PROPERTY_VIEW_STATE_ID] );
 225          }
 226  
 227          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_SHOW_STICKY_ISSUES] ) ) {
 228              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_SHOW_STICKY_ISSUES, $p_custom_filter[FILTER_PROPERTY_SHOW_STICKY_ISSUES] );
 229          }
 230  
 231          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_PRODUCT_VERSION] ) ) {
 232              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_PRODUCT_VERSION, $p_custom_filter[FILTER_PROPERTY_PRODUCT_VERSION] );
 233          }
 234  
 235          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_PRODUCT_BUILD] ) ) {
 236              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_PRODUCT_BUILD, $p_custom_filter[FILTER_PROPERTY_PRODUCT_BUILD] );
 237          }
 238  
 239          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_FIXED_IN_VERSION] ) ) {
 240              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_FIXED_IN_VERSION, $p_custom_filter[FILTER_PROPERTY_FIXED_IN_VERSION] );
 241          }
 242  
 243          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_TARGET_VERSION] ) ) {
 244              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_TARGET_VERSION, $p_custom_filter[FILTER_PROPERTY_TARGET_VERSION] );
 245          }
 246  
 247          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_SORT_FIELD_NAME] ) ) {
 248              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_SORT_FIELD_NAME, $p_custom_filter[FILTER_PROPERTY_SORT_FIELD_NAME] );
 249          }
 250  
 251          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_SORT_DIRECTION] ) ) {
 252              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_SORT_DIRECTION, $p_custom_filter[FILTER_PROPERTY_SORT_DIRECTION] );
 253          }
 254  
 255          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_SEARCH_ISSUES_PER_PAGE] ) ) {
 256              if ( $p_custom_filter[FILTER_SEARCH_ISSUES_PER_PAGE] != config_get( 'default_limit_view' ) ) {
 257                  $t_query[] = filter_encode_field_and_value( FILTER_PROPERTY_ISSUES_PER_PAGE, $p_custom_filter[FILTER_SEARCH_ISSUES_PER_PAGE] );
 258              }
 259          }
 260  
 261          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_HIGHLIGHT_CHANGED] ) ) {
 262              if ( $p_custom_filter[FILTER_PROPERTY_HIGHLIGHT_CHANGED] != config_get( 'default_show_changed' ) ) {
 263                  $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_HIGHLIGHT_CHANGED, $p_custom_filter[FILTER_PROPERTY_HIGHLIGHT_CHANGED] );
 264              }
 265          }
 266  
 267          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_HIDE_STATUS_ID] ) ) {
 268              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_HIDE_STATUS_ID, $p_custom_filter[FILTER_PROPERTY_HIDE_STATUS_ID] );
 269          }
 270  
 271          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_NOT_ASSIGNED] ) ) {
 272              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_NOT_ASSIGNED, $p_custom_filter[FILTER_PROPERTY_NOT_ASSIGNED] );
 273          }
 274  
 275          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_FILTER_BY_DATE] ) ) {
 276              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_FILTER_BY_DATE, $p_custom_filter[FILTER_PROPERTY_FILTER_BY_DATE] );
 277  
 278              # The start and end dates are only applicable if filter by date is set.
 279              if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_START_DAY] ) ) {
 280                  $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_START_DAY, $p_custom_filter[FILTER_PROPERTY_START_DAY] );
 281              }
 282      
 283              if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_END_DAY] ) ) {
 284                  $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_END_DAY, $p_custom_filter[FILTER_PROPERTY_END_DAY] );
 285              }
 286      
 287              if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_START_MONTH] ) ) {
 288                  $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_START_MONTH, $p_custom_filter[FILTER_PROPERTY_START_MONTH] );
 289              }
 290      
 291              if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_END_MONTH] ) ) {
 292                  $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_END_MONTH, $p_custom_filter[FILTER_PROPERTY_END_MONTH] );
 293              }
 294      
 295              if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_START_YEAR] ) ) {
 296                  $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_START_YEAR, $p_custom_filter[FILTER_PROPERTY_START_YEAR] );
 297              }
 298      
 299              if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_END_YEAR] ) ) {
 300                  $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_END_YEAR, $p_custom_filter[FILTER_PROPERTY_END_YEAR] );
 301              }    
 302          }
 303  
 304          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_RELATIONSHIP_TYPE] ) ) {
 305              if ( $p_custom_filter[FILTER_PROPERTY_RELATIONSHIP_TYPE] != -1 ) {
 306                  $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_RELATIONSHIP_TYPE, $p_custom_filter[FILTER_PROPERTY_RELATIONSHIP_TYPE] );
 307              }
 308          }
 309  
 310          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_RELATIONSHIP_BUG] ) ) {
 311              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_RELATIONSHIP_BUG, $p_custom_filter[FILTER_PROPERTY_RELATIONSHIP_BUG] );
 312          }
 313  
 314          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_PLATFORM] ) ) {
 315              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_PLATFORM, $p_custom_filter[FILTER_PROPERTY_PLATFORM] );
 316          }
 317  
 318          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_OS] ) ) {
 319              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_OS, $p_custom_filter[FILTER_PROPERTY_OS] );
 320          }
 321  
 322          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_OS_BUILD] ) ) {
 323              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_OS_BUILD, $p_custom_filter[FILTER_PROPERTY_OS_BUILD] );
 324          }
 325  
 326          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_TAG_STRING] ) ) {
 327              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_TAG_STRING, $p_custom_filter[FILTER_PROPERTY_TAG_STRING] );
 328          }
 329  
 330          if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_TAG_SELECT] ) ) {
 331              $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_TAG_SELECT, $p_custom_filter[FILTER_PROPERTY_TAG_SELECT] );
 332          }
 333  
 334          if ( isset( $p_custom_filter['custom_fields'] ) ) {
 335              foreach( $p_custom_filter['custom_fields'] as $t_custom_field_id => $t_custom_field_values ) {
 336                  if ( !filter_str_field_is_any( $t_custom_field_values ) ) {
 337                      $t_query[] = filter_encode_field_and_value( 'custom_field_' . $t_custom_field_id, $t_custom_field_values );
 338                  }
 339              }
 340          }
 341  
 342          if ( count( $t_query ) > 0 ) {
 343              $t_query_str = implode( $t_query, '&amp;' );
 344              $t_url = config_get( 'path' ) . 'search.php?' . $t_query_str;
 345          } else {
 346              $t_url = '';
 347          }
 348  
 349          return $t_url;
 350      }
 351  
 352      ###########################################################################
 353      # Filter API
 354      ###########################################################################
 355  
 356      # Get the standard filter that is to be used when no filter was previously saved.
 357      # When creating specific filters, this can be used as a basis for the filter, where
 358      # specific entries can be overridden.
 359  	function filter_get_default() {
 360          $t_hide_status_default  = config_get( 'hide_status_default' );
 361          $t_default_show_changed = config_get( 'default_show_changed' );
 362  
 363          $t_filter = array(
 364              'show_category'        => Array ( '0' => META_FILTER_ANY ),
 365              'show_severity'        => Array ( '0' => META_FILTER_ANY ),
 366              'show_status'        => Array ( '0' => META_FILTER_ANY ),
 367              'highlight_changed'    => $t_default_show_changed,
 368              'reporter_id'        => Array ( '0' => META_FILTER_ANY ),
 369              'handler_id'        => Array ( '0' => META_FILTER_ANY ),
 370              'project_id'        => Array ( '0' => META_FILTER_CURRENT ),
 371              'show_resolution'    => Array ( '0' => META_FILTER_ANY ),
 372              'show_build'        => Array ( '0' => META_FILTER_ANY ),
 373              'show_version'        => Array ( '0' => META_FILTER_ANY ),
 374              'hide_status'        => Array ( '0' => $t_hide_status_default ),
 375              'user_monitor'        => Array ( '0' => META_FILTER_ANY ),
 376              'sort'              => 'last_updated',
 377              'dir'               => 'DESC'
 378          );
 379  
 380          return $t_filter;
 381      }
 382  
 383      # @@@ Had to make all these parameters required because we can't use
 384      #  call-time pass by reference anymore.  I really preferred not having
 385      #  to pass all the params in if you didn't want to, but I wanted to get
 386      #  rid of the errors for now.  If we can think of a better way later
 387      #  (maybe return an object) that would be great.
 388      #
 389      # $p_page_numer
 390      #   - the page you want to see (set to the actual page on return)
 391      # $p_per_page
 392      #   - the number of bugs to see per page (set to actual on return)
 393      #     -1   indicates you want to see all bugs
 394      #     null indicates you want to use the value specified in the filter
 395      # $p_page_count
 396      #   - you don't need to give a value here, the number of pages will be
 397      #     stored here on return
 398      # $p_bug_count
 399      #   - you don't need to give a value here, the number of bugs will be
 400      #     stored here on return
 401      # $p_custom_filter
 402      #   - Filter to use.
 403      # $p_project_id
 404      #   - project id to use in filtering.
 405      # $p_user_id
 406      #   - user id to use as current user when filtering.
 407      # $p_show_sticky
 408      #    - get sticky issues only.
 409  	function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p_bug_count, $p_custom_filter = null, $p_project_id = null, $p_user_id = null, $p_show_sticky = null ) {
 410          log_event( LOG_FILTERING, 'FILTERING: START NEW FILTER QUERY' );
 411  
 412          $t_bug_table            = config_get( 'mantis_bug_table' );
 413          $t_bug_text_table        = config_get( 'mantis_bug_text_table' );
 414          $t_bugnote_table        = config_get( 'mantis_bugnote_table' );
 415          $t_custom_field_string_table    = config_get( 'mantis_custom_field_string_table' );
 416          $t_bugnote_text_table    = config_get( 'mantis_bugnote_text_table' );
 417          $t_project_table        = config_get( 'mantis_project_table' );
 418          $t_bug_monitor_table    = config_get( 'mantis_bug_monitor_table' );
 419          $t_limit_reporters        = config_get( 'limit_reporters' );
 420          $t_bug_relationship_table    = config_get( 'mantis_bug_relationship_table' );
 421          $t_report_bug_threshold        = config_get( 'report_bug_threshold' );
 422  
 423          $t_current_user_id = auth_get_current_user_id();
 424  
 425          if ( null === $p_user_id ) {
 426              $t_user_id = $t_current_user_id;
 427          } else {
 428              $t_user_id = $p_user_id;
 429          }
 430  
 431          $c_user_id = db_prepare_int( $t_user_id );
 432  
 433          if ( null === $p_project_id ) {
 434              # @@@ If project_id is not specified, then use the project id(s) in the filter if set, otherwise, use current project.
 435              $t_project_id    = helper_get_current_project();
 436          } else {
 437              $t_project_id    = $p_project_id;
 438          }
 439  
 440          if ( $p_custom_filter === null ) {
 441              # Prefer current_user_get_bug_filter() over user_get_filter() when applicable since it supports
 442              # cookies set by previous version of the code.
 443              if ( $t_user_id == $t_current_user_id ) {
 444                  $t_filter = current_user_get_bug_filter();
 445              } else {
 446                  $t_filter = user_get_bug_filter( $t_user_id, $t_project_id );
 447              }
 448          } else {
 449              $t_filter = $p_custom_filter;
 450          }
 451  
 452          $t_filter = filter_ensure_valid_filter( $t_filter );
 453  
 454          if ( false === $t_filter ) {
 455              return false; # signify a need to create a cookie
 456              #@@@ error instead?
 457          }
 458  
 459          $t_view_type = $t_filter['_view_type'];
 460  
 461          $t_where_clauses = array( "$t_project_table.enabled = 1", "$t_project_table.id = $t_bug_table.project_id" );
 462          $t_select_clauses = array( "$t_bug_table.*" );
 463          $t_join_clauses = array();
 464          $t_from_clauses = array();
 465  
 466          // normalize the project filtering into an array $t_project_ids
 467          if ( 'simple' == $t_view_type ) {
 468              log_event( LOG_FILTERING, 'FILTERING: Simple Filter' );
 469              $t_project_ids = array( $t_project_id );
 470              $t_include_sub_projects = true;
 471          } else {
 472              log_event( LOG_FILTERING, 'FILTERING: Advanced Filter' );
 473              if ( !is_array( $t_filter['project_id'] ) ) {
 474                  $t_project_ids = array( db_prepare_int( $t_filter['project_id'] ) );
 475              } else {
 476                  $t_project_ids = array_map( 'db_prepare_int', $t_filter['project_id'] );
 477              }
 478  
 479              $t_include_sub_projects = ( ( count( $t_project_ids ) == 1 ) && ( $t_project_ids[0] == META_FILTER_CURRENT ) );
 480          }
 481  
 482          log_event( LOG_FILTERING, 'FILTERING: project_ids = ' . implode( ',', $t_project_ids ) );
 483          log_event( LOG_FILTERING, 'FILTERING: include sub-projects = ' . ( $t_include_sub_projects ? '1' : '0' ) );
 484  
 485          // if the array has ALL_PROJECTS, then reset the array to only contain ALL_PROJECTS.
 486          // replace META_FILTER_CURRENT with the actualy current project id.
 487          $t_all_projects_found = false;
 488          $t_new_project_ids = array();
 489          foreach ( $t_project_ids as $t_pid ) {
 490              if ( $t_pid == META_FILTER_CURRENT ) { 
 491                  $t_pid = $t_project_id;
 492              }
 493  
 494              if ( $t_pid == ALL_PROJECTS ) {
 495                  $t_all_projects_found = true;
 496                  log_event( LOG_FILTERING, 'FILTERING: all projects selected' );
 497                  break;
 498              }
 499  
 500              // filter out inaccessible projects.
 501              if ( !access_has_project_level( VIEWER, $t_pid, $t_user_id ) ) {
 502                  continue;
 503              }
 504  
 505              $t_new_project_ids[] = $t_pid;
 506          }
 507  
 508          $t_projects_query_required = true;
 509          if ( $t_all_projects_found ) {
 510              if ( user_is_administrator( $t_user_id ) ) {
 511                  log_event( LOG_FILTERING, 'FILTERING: all projects + administrator, hence no project filter.' );
 512                  $t_projects_query_required = false;
 513              } else {
 514                  $t_project_ids = user_get_accessible_projects( $t_user_id );
 515              }
 516          } else {
 517              $t_project_ids = $t_new_project_ids;
 518          }
 519      
 520          if ( $t_projects_query_required ) {
 521              // expand project ids to include sub-projects
 522              if ( $t_include_sub_projects ) {
 523                  $t_top_project_ids = $t_project_ids;
 524  
 525                  foreach ( $t_top_project_ids as $t_pid ) {
 526                      log_event( LOG_FILTERING, 'FILTERING: Getting sub-projects for project id ' . $t_pid );
 527                      $t_project_ids = array_merge( $t_project_ids, user_get_all_accessible_subprojects( $t_user_id, $t_pid ) );
 528                  }
 529  
 530                  $t_project_ids = array_unique( $t_project_ids );
 531              }
 532  
 533              // if no projects are accessible, then return an empty array.
 534              if ( count( $t_project_ids ) == 0 ) {
 535                  log_event( LOG_FILTERING, 'FILTERING: no accessible projects' );
 536                  return array();
 537              }
 538  
 539              log_event( LOG_FILTERING, 'FILTERING: project_ids after including sub-projects = ' . implode( ',', $t_project_ids ) );
 540  
 541              // this array is to be populated with project ids for which we only want to show public issues.  This is due to the limited
 542              // access of the current user.
 543              $t_public_only_project_ids = array();
 544  
 545              // this array is populated with project ids that the current user has full access to.
 546              $t_private_and_public_project_ids = array();
 547  
 548              $t_access_required_to_view_private_bugs = config_get( 'private_bug_threshold' );
 549              foreach ( $t_project_ids as $t_pid ) {
 550                  if ( access_has_project_level( $t_access_required_to_view_private_bugs, $t_pid, $t_user_id ) ) {
 551                      $t_private_and_public_project_ids[] = $t_pid;
 552                  } else {
 553                      $t_public_only_project_ids[] = $t_pid;
 554                  }
 555              }
 556  
 557              log_event( LOG_FILTERING, 'FILTERING: project_ids (with public/private access) = ' . implode( ',', $t_private_and_public_project_ids ) );
 558              log_event( LOG_FILTERING, 'FILTERING: project_ids (with public access) = ' . implode( ',', $t_public_only_project_ids ) );
 559  
 560              $t_count_private_and_public_project_ids = count( $t_private_and_public_project_ids );
 561              if ( $t_count_private_and_public_project_ids == 1 ) {
 562                  $t_private_and_public_query = "( $t_bug_table.project_id = " . $t_private_and_public_project_ids[0] . " )";
 563              } else if ( $t_count_private_and_public_project_ids > 1 ) {
 564                  $t_private_and_public_query = "( $t_bug_table.project_id in (". implode( ', ', $t_private_and_public_project_ids ) . ") )";
 565              } else {
 566                  $t_private_and_public_query = null;
 567              }
 568  
 569              $t_count_public_only_project_ids = count( $t_public_only_project_ids );
 570              $t_public_view_state_check = "( ( $t_bug_table.view_state = " . VS_PUBLIC . " ) OR ( $t_bug_table.reporter_id = $t_user_id ) )";
 571              if ( $t_count_public_only_project_ids == 1 ) {
 572                  $t_public_only_query = "( ( $t_bug_table.project_id = " . $t_public_only_project_ids[0] . " ) AND $t_public_view_state_check )";
 573              } else if ( $t_count_public_only_project_ids > 1 ) {
 574                  $t_public_only_query = "( ( $t_bug_table.project_id in (". implode( ', ', $t_public_only_project_ids ) . ") ) AND $t_public_view_state_check )";
 575              } else {
 576                  $t_public_only_query = null;
 577              }
 578  
 579              // both queries can't be null, so we either have one of them or both.
 580              
 581              if ( $t_private_and_public_query === null ) {
 582                  $t_project_query = $t_public_only_query;
 583              } else if ( $t_public_only_query === null ) {
 584                  $t_project_query = $t_private_and_public_query;
 585              } else {
 586                  $t_project_query = "( $t_public_only_query OR $t_private_and_public_query )";
 587              }
 588  
 589              log_event( LOG_FILTERING, 'FILTERING: project query = ' . $t_project_query );
 590              array_push( $t_where_clauses, $t_project_query );
 591          }
 592  
 593          # view state
 594          $t_view_state = db_prepare_int( $t_filter['view_state'] );
 595          if ( ( $t_filter['view_state'] !== META_FILTER_ANY ) && ( !is_blank( $t_filter['view_state'] ) ) ) {
 596              $t_view_state_query = "($t_bug_table.view_state='$t_view_state')";
 597              log_event( LOG_FILTERING, 'FILTERING: view_state query = ' . $t_view_state_query );
 598              array_push( $t_where_clauses, $t_view_state_query );
 599          } else {
 600              log_event( LOG_FILTERING, 'FILTERING: no view_state query' );
 601          }
 602  
 603          # reporter
 604          $t_any_found = false;
 605  
 606          foreach( $t_filter['reporter_id'] as $t_filter_member ) {
 607              if ( ( META_FILTER_ANY === $t_filter_member ) || ( 0 === $t_filter_member ) ) {
 608                  $t_any_found = true;
 609              }
 610          }
 611  
 612          if ( count( $t_filter['reporter_id'] ) == 0 ) {
 613              $t_any_found = true;
 614          }
 615  
 616          if ( !$t_any_found ) {
 617              $t_clauses = array();
 618  
 619              foreach( $t_filter['reporter_id'] as $t_filter_member ) {
 620                  if ( META_FILTER_NONE == $t_filter_member ) {
 621                      array_push( $t_clauses, "0" );
 622                  } else {
 623                      $c_reporter_id = db_prepare_int( $t_filter_member );
 624                      if ( META_FILTER_MYSELF == $c_reporter_id ) {
 625                          array_push( $t_clauses, $c_user_id );
 626                      } else {
 627                          array_push( $t_clauses, $c_reporter_id );
 628                      }
 629                  }
 630              }
 631              
 632              if ( 1 < count( $t_clauses ) ) {
 633                  $t_reporter_query = "( $t_bug_table.reporter_id in (". implode( ', ', $t_clauses ) .") )";
 634              } else {
 635                  $t_reporter_query = "( $t_bug_table.reporter_id=$t_clauses[0] )";
 636              }
 637  
 638              log_event( LOG_FILTERING, 'FILTERING: reporter query = ' . $t_reporter_query );
 639              array_push( $t_where_clauses, $t_reporter_query );
 640          } else {
 641              log_event( LOG_FILTERING, 'FILTERING: no reporter query' );
 642          }
 643  
 644          # limit reporter
 645          # @@@ thraxisp - access_has_project_level checks greater than or equal to,
 646          #   this assumed that there aren't any holes above REPORTER where the limit would apply
 647          #
 648          if ( ( ON === $t_limit_reporters ) && ( ! access_has_project_level( REPORTER + 1, $t_project_id, $t_user_id ) ) ) {
 649              $c_reporter_id = $c_user_id;
 650              array_push( $t_where_clauses, "($t_bug_table.reporter_id='$c_reporter_id')" );
 651          }
 652  
 653          # handler
 654          $t_any_found = false;
 655  
 656          foreach( $t_filter['handler_id'] as $t_filter_member ) {
 657              if ( ( META_FILTER_ANY === $t_filter_member ) || ( 0 === $t_filter_member ) ) {
 658                  $t_any_found = true;
 659              }
 660          }
 661          if ( count( $t_filter['handler_id'] ) == 0 ) {
 662              $t_any_found = true;
 663          }
 664  
 665          if ( !$t_any_found ) {
 666              $t_clauses = array();
 667  
 668              foreach( $t_filter['handler_id'] as $t_filter_member ) {
 669                  if ( META_FILTER_NONE == $t_filter_member ) {
 670                      array_push( $t_clauses, 0 );
 671                  } else {
 672                      $c_handler_id = db_prepare_int( $t_filter_member );
 673                      if ( META_FILTER_MYSELF == $c_handler_id ) {
 674                          array_push( $t_clauses, $c_user_id );
 675                      } else {
 676                          array_push( $t_clauses, $c_handler_id );
 677                      }
 678                  }
 679              }
 680              
 681              if ( 1 < count( $t_clauses ) ) {
 682                  $t_handler_query = "( $t_bug_table.handler_id in (". implode( ', ', $t_clauses ) .") )";
 683              } else {
 684                  $t_handler_query = "( $t_bug_table.handler_id=$t_clauses[0] )";
 685              }
 686  
 687              log_event( LOG_FILTERING, 'FILTERING: handler query = ' . $t_handler_query );
 688              array_push( $t_where_clauses, $t_handler_query );
 689          } else {
 690              log_event( LOG_FILTERING, 'FILTERING: no handler query' );
 691          }
 692  
 693          # category
 694          if ( !_filter_is_any( $t_filter['show_category'] ) ) {
 695              $t_clauses = array();
 696  
 697              foreach( $t_filter['show_category'] as $t_filter_member ) {
 698                  $t_filter_member = stripslashes( $t_filter_member );
 699                  if ( META_FILTER_NONE == $t_filter_member ) {
 700                      array_push( $t_clauses, "''" );
 701                  } else {
 702                      $c_show_category = db_prepare_string( $t_filter_member );
 703                      array_push( $t_clauses, "'$c_show_category'" );
 704                  }
 705              }
 706  
 707              if ( 1 < count( $t_clauses ) ) {
 708                  array_push( $t_where_clauses, "( $t_bug_table.category in (". implode( ', ', $t_clauses ) .") )" );
 709              } else {
 710                  array_push( $t_where_clauses, "( $t_bug_table.category=$t_clauses[0] )" );
 711              }
 712          }
 713  
 714          # severity
 715          $t_any_found = false;
 716          foreach( $t_filter['show_severity'] as $t_filter_member ) {
 717              if ( ( META_FILTER_ANY == $t_filter_member ) || ( 0 === $t_filter_member ) ) {
 718                  $t_any_found = true;
 719              }
 720          }
 721          if ( count( $t_filter['show_severity'] ) == 0 ) {
 722              $t_any_found = true;
 723          }
 724          if ( !$t_any_found ) {
 725              $t_clauses = array();
 726  
 727              foreach( $t_filter['show_severity'] as $t_filter_member ) {
 728                  $c_show_severity = db_prepare_int( $t_filter_member );
 729                  array_push( $t_clauses, $c_show_severity );
 730              }
 731              if ( 1 < count( $t_clauses ) ) {
 732                  array_push( $t_where_clauses, "( $t_bug_table.severity in (". implode( ', ', $t_clauses ) .") )" );
 733              } else {
 734                  array_push( $t_where_clauses, "( $t_bug_table.severity=$t_clauses[0] )" );
 735              }
 736          }
 737  
 738          # show / hide status
 739          # take a list of all available statuses then remove the ones that we want hidden, then make sure
 740          # the ones we want shown are still available
 741          $t_status_arr = explode_enum_string( config_get( 'status_enum_string' ) );
 742          $t_available_statuses = array();
 743          $t_desired_statuses = array();
 744          foreach( $t_status_arr as $t_this_status ) {
 745              $t_this_status_arr = explode_enum_arr( $t_this_status );
 746              $t_available_statuses[] = $t_this_status_arr[0];
 747          }
 748  
 749          if ( 'simple' == $t_filter['_view_type'] ) {
 750              # simple filtering: if showing any, restrict by the hide status value, otherwise ignore the hide
 751              $t_any_found = false;
 752              $t_this_status = $t_filter['show_status'][0];
 753              $t_this_hide_status = $t_filter['hide_status'][0];
 754  
 755              if ( ( META_FILTER_ANY == $t_this_status ) || ( is_blank( $t_this_status ) ) || ( 0 === $t_this_status ) ) {
 756                  $t_any_found = true;
 757              }
 758              if ( $t_any_found ) {
 759                  foreach( $t_available_statuses as $t_this_available_status ) {
 760                      if ( $t_this_hide_status > $t_this_available_status ) {
 761                          $t_desired_statuses[] = $t_this_available_status;
 762                      }
 763                  }
 764              } else {
 765                  $t_desired_statuses[] = $t_this_status;
 766              }
 767          } else {
 768              # advanced filtering: ignore the hide
 769              $t_any_found = false;
 770              foreach( $t_filter['show_status'] as $t_this_status ) {
 771                  $t_desired_statuses[] = $t_this_status;
 772                  if ( ( META_FILTER_ANY == $t_this_status ) || ( is_blank( $t_this_status ) ) || ( 0 === $t_this_status ) ) {
 773                      $t_any_found = true;
 774                  }
 775              }
 776              if ( $t_any_found ) {
 777                  $t_desired_statuses = array();
 778              }
 779          }
 780  
 781          if ( count( $t_desired_statuses ) > 0 ) {
 782              $t_clauses = array();
 783  
 784              foreach( $t_desired_statuses as $t_filter_member ) {
 785                  $c_show_status = db_prepare_int( $t_filter_member );
 786                  array_push( $t_clauses, $c_show_status );
 787              }
 788              if ( 1 < count( $t_clauses ) ) {
 789                  array_push( $t_where_clauses, "( $t_bug_table.status in (". implode( ', ', $t_clauses ) .") )" );
 790              } else {
 791                  array_push( $t_where_clauses, "( $t_bug_table.status=$t_clauses[0] )" );
 792              }
 793          }
 794  
 795          # resolution
 796          $t_any_found = false;
 797          foreach( $t_filter['show_resolution'] as $t_filter_member ) {
 798              if ( META_FILTER_ANY == $t_filter_member ) {
 799                  $t_any_found = true;
 800              }
 801          }
 802          if ( count( $t_filter['show_resolution'] ) == 0 ) {
 803              $t_any_found = true;
 804          }
 805          if ( !$t_any_found ) {
 806              $t_clauses = array();
 807  
 808              foreach( $t_filter['show_resolution'] as $t_filter_member ) {
 809                  $c_show_resolution = db_prepare_int( $t_filter_member );
 810                  array_push( $t_clauses, $c_show_resolution );
 811              }
 812              if ( 1 < count( $t_clauses ) ) {
 813                  array_push( $t_where_clauses, "( $t_bug_table.resolution in (". implode( ', ', $t_clauses ) .") )" );
 814              } else {
 815                  array_push( $t_where_clauses, "( $t_bug_table.resolution=$t_clauses[0] )" );
 816              }
 817          }
 818  
 819          # priority
 820          $t_any_found = false;
 821          foreach( $t_filter['show_priority'] as $t_filter_member ) {
 822                  if ( ( META_FILTER_ANY == $t_filter_member ) || ( 0 === $t_filter_member ) ) {
 823                      $t_any_found = true;
 824                  }
 825          }
 826          if ( count( $t_filter['show_priority'] ) == 0 ) {
 827                  $t_any_found = true;
 828          }
 829          if ( !$t_any_found ) {
 830                  $t_clauses = array();
 831  
 832                  foreach( $t_filter['show_priority'] as $t_filter_member ) {
 833                          $c_show_priority = db_prepare_int( $t_filter_member );
 834                          array_push( $t_clauses, $c_show_priority );
 835                  }
 836              if ( 1 < count( $t_clauses ) ) {
 837                  array_push( $t_where_clauses, "( $t_bug_table.priority in (". implode( ', ', $t_clauses ) .") )" );
 838              } else {
 839                  array_push( $t_where_clauses, "( $t_bug_table.priority=$t_clauses[0] )" );
 840              }
 841          }
 842  
 843          # product build
 844          $t_any_found = false;
 845          foreach( $t_filter['show_build'] as $t_filter_member ) {
 846              if ( ( META_FILTER_ANY == $t_filter_member ) && ( is_numeric( $t_filter_member ) ) ) {
 847                  $t_any_found = true;
 848              }
 849          }
 850          if ( count( $t_filter['show_build'] ) == 0 ) {
 851              $t_any_found = true;
 852          }
 853          if ( !$t_any_found ) {
 854              $t_clauses = array();
 855  
 856              foreach( $t_filter['show_build'] as $t_filter_member ) {
 857                  $t_filter_member = stripslashes( $t_filter_member );
 858                  if ( META_FILTER_NONE == $t_filter_member ) {
 859                      array_push( $t_clauses, "''" );
 860                  } else {
 861                      $c_show_build = db_prepare_string( $t_filter_member );
 862                      array_push( $t_clauses, "'$c_show_build'" );
 863                  }
 864              }
 865              if ( 1 < count( $t_clauses ) ) {
 866                  array_push( $t_where_clauses, "( $t_bug_table.build in (". implode( ', ', $t_clauses ) .") )" );
 867              } else {
 868                  array_push( $t_where_clauses, "( $t_bug_table.build=$t_clauses[0] )" );
 869              }
 870          }
 871  
 872          # product version
 873          if ( !_filter_is_any( $t_filter['show_version'] ) ) {
 874              $t_clauses = array();
 875  
 876              foreach( $t_filter['show_version'] as $t_filter_member ) {
 877                  $t_filter_member = stripslashes( $t_filter_member );
 878                  if ( META_FILTER_NONE == $t_filter_member ) {
 879                      array_push( $t_clauses, "''" );
 880                  } else {
 881                      $c_show_version = db_prepare_string( $t_filter_member );
 882                      array_push( $t_clauses, "'$c_show_version'" );
 883                  }
 884              }
 885  
 886              if ( 1 < count( $t_clauses ) ) {
 887                  array_push( $t_where_clauses, "( $t_bug_table.version in (". implode( ', ', $t_clauses ) .") )" );
 888              } else {
 889                  array_push( $t_where_clauses, "( $t_bug_table.version=$t_clauses[0] )" );
 890              }
 891          }
 892  
 893          # profile
 894          if ( !_filter_is_any( $t_filter['show_profile'] ) ) {
 895              $t_clauses = array();
 896  
 897              foreach( $t_filter['show_profile'] as $t_filter_member ) {
 898                  $t_filter_member = stripslashes( $t_filter_member );
 899                  if ( META_FILTER_NONE == $t_filter_member ) {
 900                      array_push( $t_clauses, "0" );
 901                  } else {
 902                      $c_show_profile = db_prepare_int( $t_filter_member );
 903                      array_push( $t_clauses, "$c_show_profile" );
 904                  }
 905              }
 906              if ( 1 < count( $t_clauses ) ) {
 907                  array_push( $t_where_clauses, "( $t_bug_table.profile_id in (". implode( ', ', $t_clauses ) .") )" );
 908              } else {
 909                  array_push( $t_where_clauses, "( $t_bug_table.profile_id=$t_clauses[0] )" );
 910              }
 911          }
 912  
 913          # platform
 914          if ( !_filter_is_any( $t_filter['platform'] ) ) {
 915              $t_clauses = array();
 916  
 917              foreach( $t_filter['platform'] as $t_filter_member ) {
 918                  $t_filter_member = stripslashes( $t_filter_member );
 919                  if ( META_FILTER_NONE == $t_filter_member ) {
 920                      array_push( $t_clauses, '' );
 921                  } else {
 922                      $c_platform = db_prepare_string( $t_filter_member );
 923                      array_push( $t_clauses, "'$c_platform'" );
 924                  }
 925              }
 926  
 927              if ( 1 < count( $t_clauses ) ) {
 928                  array_push( $t_where_clauses, "( $t_bug_table.platform in (". implode( ', ', $t_clauses ) .") )" );
 929              } else {
 930                  array_push( $t_where_clauses, "( $t_bug_table.platform = $t_clauses[0] )" );
 931              }
 932          }
 933  
 934          # os
 935          if ( !_filter_is_any( $t_filter['os'] ) ) {
 936              $t_clauses = array();
 937  
 938              foreach( $t_filter['os'] as $t_filter_member ) {
 939                  $t_filter_member = stripslashes( $t_filter_member );
 940                  if ( META_FILTER_NONE == $t_filter_member ) {
 941                      array_push( $t_clauses, '' );
 942                  } else {
 943                      $c_os = db_prepare_string( $t_filter_member );
 944                      array_push( $t_clauses, "'$c_os'" );
 945                  }
 946              }
 947  
 948              if ( 1 < count( $t_clauses ) ) {
 949                  array_push( $t_where_clauses, "( $t_bug_table.os in (". implode( ', ', $t_clauses ) .") )" );
 950              } else {
 951                  array_push( $t_where_clauses, "( $t_bug_table.os = $t_clauses[0] )" );
 952              }
 953          }
 954  
 955          # os_build
 956          if ( !_filter_is_any( $t_filter['os_build'] ) ) {
 957              $t_clauses = array();
 958  
 959              foreach( $t_filter['os_build'] as $t_filter_member ) {
 960                  $t_filter_member = stripslashes( $t_filter_member );
 961                  if ( META_FILTER_NONE == $t_filter_member ) {
 962                      array_push( $t_clauses, '' );
 963                  } else {
 964                      $c_os_build = db_prepare_string( $t_filter_member );
 965                      array_push( $t_clauses, "'$c_os_build'" );
 966                  }
 967              }
 968  
 969              if ( 1 < count( $t_clauses ) ) {
 970                  array_push( $t_where_clauses, "( $t_bug_table.os_build in (". implode( ', ', $t_clauses ) .") )" );
 971              } else {
 972                  array_push( $t_where_clauses, "( $t_bug_table.os_build = $t_clauses[0] )" );
 973              }
 974          }
 975  
 976          # date filter
 977          if ( ( 'on' == $t_filter['do_filter_by_date'] ) &&
 978                  is_numeric( $t_filter['start_month'] ) &&
 979                  is_numeric( $t_filter['start_day'] ) &&
 980                  is_numeric( $t_filter['start_year'] ) &&
 981                  is_numeric( $t_filter['end_month'] ) &&
 982                  is_numeric( $t_filter['end_day'] ) &&
 983                  is_numeric( $t_filter['end_year'] )
 984              ) {
 985  
 986              $t_start_string = db_prepare_string( $t_filter['start_year']  . "-". $t_filter['start_month']  . "-" . $t_filter['start_day'] ." 00:00:00" );
 987              $t_end_string   = db_prepare_string( $t_filter['end_year']  . "-". $t_filter['end_month']  . "-" . $t_filter['end_day'] ." 23:59:59" );
 988  
 989              array_push( $t_where_clauses, "($t_bug_table.date_submitted BETWEEN '$t_start_string' AND '$t_end_string' )" );
 990          }
 991  
 992          # fixed in version
 993          if ( !_filter_is_any( $t_filter['fixed_in_version'] ) ) {
 994              $t_clauses = array();
 995  
 996              foreach( $t_filter['fixed_in_version'] as $t_filter_member ) {
 997                  $t_filter_member = stripslashes( $t_filter_member );
 998                  if ( META_FILTER_NONE == $t_filter_member ) {
 999                      array_push( $t_clauses, "''" );
1000                  } else {
1001                      $c_fixed_in_version = db_prepare_string( $t_filter_member );
1002                      array_push( $t_clauses, "'$c_fixed_in_version'" );
1003                  }
1004              }
1005              if ( 1 < count( $t_clauses ) ) {
1006                  array_push( $t_where_clauses, "( $t_bug_table.fixed_in_version in (". implode( ', ', $t_clauses ) .") )" );
1007              } else {
1008                  array_push( $t_where_clauses, "( $t_bug_table.fixed_in_version=$t_clauses[0] )" );
1009              }
1010          }
1011  
1012          # target version
1013          if ( !_filter_is_any( $t_filter['target_version'] ) ) {
1014              $t_clauses = array();
1015  
1016              foreach( $t_filter['target_version'] as $t_filter_member ) {
1017                  $t_filter_member = stripslashes( $t_filter_member );
1018                  if ( META_FILTER_NONE == $t_filter_member ) {
1019                      array_push( $t_clauses, "''" );
1020                  } else {
1021                      $c_target_version = db_prepare_string( $t_filter_member );
1022                      array_push( $t_clauses, "'$c_target_version'" );
1023                  }
1024              }
1025              
1026              #echo var_dump( $t_clauses ); exit;
1027              if ( 1 < count( $t_clauses ) ) {
1028                  array_push( $t_where_clauses, "( $t_bug_table.target_version in (". implode( ', ', $t_clauses ) .") )" );
1029              } else {
1030                  array_push( $t_where_clauses, "( $t_bug_table.target_version=$t_clauses[0] )" );
1031              }
1032          }
1033  
1034          # users monitoring a bug
1035          $t_any_found = false;
1036          foreach( $t_filter['user_monitor'] as $t_filter_member ) {
1037              if ( ( META_FILTER_ANY == $t_filter_member ) || ( 0 === $t_filter_member ) ) {
1038                  $t_any_found = true;
1039              }
1040          }
1041          if ( count( $t_filter['user_monitor'] ) == 0 ) {
1042              $t_any_found = true;
1043          }
1044          if ( !$t_any_found ) {
1045              $t_clauses = array();
1046              $t_table_name = 'user_monitor';
1047              array_push( $t_from_clauses, $t_bug_monitor_table );
1048              array_push( $t_join_clauses, "LEFT JOIN $t_bug_monitor_table $t_table_name ON $t_table_name.bug_id = $t_bug_table.id" );
1049  
1050              foreach( $t_filter['user_monitor'] as $t_filter_member ) {
1051                  $c_user_monitor = db_prepare_int( $t_filter_member );
1052                  if ( META_FILTER_MYSELF == $c_user_monitor ) {
1053                      array_push( $t_clauses, $c_user_id );
1054                  } else {
1055                      array_push( $t_clauses, $c_user_monitor );
1056                  }
1057              }
1058              if ( 1 < count( $t_clauses ) ) {
1059                  array_push( $t_where_clauses, "( $t_table_name.user_id in (". implode( ', ', $t_clauses ) .") )" );
1060              } else {
1061                  array_push( $t_where_clauses, "( $t_table_name.user_id=$t_clauses[0] )" );
1062              }
1063          }
1064          # bug relationship
1065          $t_any_found = false;
1066          $c_rel_type = $t_filter['relationship_type'];
1067          $c_rel_bug = $t_filter['relationship_bug'];
1068          if ( -1 == $c_rel_type || 0 == $c_rel_bug) {
1069              $t_any_found = true;
1070          }
1071          if ( !$t_any_found ) {
1072              # use the complementary type
1073              $t_comp_type = relationship_get_complementary_type( $c_rel_type );
1074              $t_clauses = array();
1075              $t_table_name = 'relationship';
1076              array_push( $t_from_clauses, $t_bug_relationship_table );
1077              array_push( $t_join_clauses, "LEFT JOIN $t_bug_relationship_table $t_table_name ON $t_table_name.destination_bug_id = $t_bug_table.id" );
1078              array_push( $t_join_clauses, "LEFT JOIN $t_bug_relationship_table $t_table_name}2 ON $t_table_name}2.source_bug_id = $t_bug_table.id" );
1079              // get reverse relationships
1080               array_push( $t_clauses, "($t_table_name.relationship_type='$t_comp_type' AND $t_table_name.source_bug_id='$c_rel_bug')" );
1081              array_push( $t_clauses, "($t_table_name"."2.relationship_type='$c_rel_type' AND $t_table_name"."2.destination_bug_id='$c_rel_bug')" );
1082              array_push( $t_where_clauses, '('. implode( ' OR ', $t_clauses ) .')' );
1083          }
1084  
1085          # tags
1086          $c_tag_string = trim( $t_filter['tag_string'] );
1087          if ( !is_blank( $c_tag_string ) ) {
1088              $t_tags = tag_parse_filters( $c_tag_string );
1089  
1090              if ( count( $t_tags ) ) {
1091  
1092                  $t_tags_all = array();
1093                  $t_tags_any = array();
1094                  $t_tags_none = array();
1095      
1096                  foreach( $t_tags as $t_tag_row ) {
1097                      switch ( $t_tag_row['filter'] ) {
1098                          case 1:
1099                              $t_tags_all[] = $t_tag_row;
1100                              break;
1101                          case 0:
1102                              $t_tags_any[] = $t_tag_row;
1103                              break;
1104                          case -1:
1105                              $t_tags_none[] = $t_tag_row;
1106                              break;
1107                      }
1108                  }
1109      
1110                  if ( 0 < $t_filter['tag_select'] && tag_exists( $t_filter['tag_select'] ) ) {
1111                      $t_tags_any[] = tag_get( $t_filter['tag_select'] );
1112                  }
1113      
1114                  $t_bug_tag_table = config_get( 'mantis_bug_tag_table' );
1115                  
1116                  if ( count( $t_tags_all ) ) {
1117                      $t_clauses = array();
1118                      foreach ( $t_tags_all as $t_tag_row ) {
1119                          array_push( $t_clauses, "$t_bug_table.id IN ( SELECT bug_id FROM $t_bug_tag_table WHERE $t_bug_tag_table.tag_id = $t_tag_row[id] )" );
1120                      }
1121                      array_push( $t_where_clauses, '('. implode( ' AND ', $t_clauses ) .')' );
1122                  }
1123                  
1124                  if ( count( $t_tags_any ) ) {
1125                      $t_clauses = array();
1126                      foreach ( $t_tags_any as $t_tag_row ) {
1127                          array_push( $t_clauses, "$t_bug_tag_table.tag_id = $t_tag_row[id]" );
1128                      }
1129                      array_push( $t_where_clauses, "$t_bug_table.id IN ( SELECT bug_id FROM $t_bug_tag_table WHERE ( ". implode( ' OR ', $t_clauses ) .') )' );
1130                  }
1131              
1132                  if ( count( $t_tags_none ) ) {
1133                      $t_clauses = array();
1134                      foreach ( $t_tags_none as $t_tag_row ) {
1135                          array_push( $t_clauses, "$t_bug_tag_table.tag_id = $t_tag_row[id]" );
1136                      }
1137                      array_push( $t_where_clauses, "$t_bug_table.id NOT IN ( SELECT bug_id FROM $t_bug_tag_table WHERE ( ". implode( ' OR ', $t_clauses ) .') )' );
1138                  } 
1139  
1140              }    
1141          }
1142  
1143          # custom field filters
1144          if( ON == config_get( 'filter_by_custom_fields' ) ) {
1145              # custom field filtering
1146              # @@@ At the moment this gets the linked fields relating to the current project
1147              #     It should get the ones relating to the project in the filter or all projects
1148              #     if multiple projects.
1149              $t_custom_fields = custom_field_get_linked_ids( $t_project_id );
1150  
1151              foreach( $t_custom_fields as $t_cfid ) {
1152                  $t_custom_where_clause = '';
1153                  # Ignore all custom filters that are not set, or that are set to '' or "any"
1154                  $t_any_found = false;
1155                  foreach( $t_filter['custom_fields'][$t_cfid] as $t_filter_member ) {
1156                  if ( ( META_FILTER_ANY == $t_filter_member ) && ( is_numeric( $t_filter_member ) ) ) {
1157                          $t_any_found = true;
1158                      }
1159                  }
1160                  if ( !isset( $t_filter['custom_fields'][$t_cfid] ) ) {
1161                      $t_any_found = true;
1162                  }
1163                  if ( !$t_any_found ) {
1164                      $t_def = custom_field_get_definition( $t_cfid );
1165                      $t_table_name = $t_custom_field_string_table . '_' . $t_cfid;
1166                      # We need to filter each joined table or the result query will explode in dimensions
1167                      # Each custom field will result in a exponential growth like Number_of_Issues^Number_of_Custom_Fields
1168                      # and only after this process ends (if it is able to) the result query will be filtered
1169                      # by the WHERE clause and by the DISTINCT clause
1170                      $t_cf_join_clause = "LEFT JOIN $t_custom_field_string_table $t_table_name ON $t_table_name.bug_id = $t_bug_table.id AND $t_table_name.field_id = $t_cfid ";
1171  
1172                      if ($t_def['type'] == CUSTOM_FIELD_TYPE_DATE) {
1173                          switch ($t_filter['custom_fields'][$t_cfid][0]) {
1174                          case CUSTOM_FIELD_DATE_ANY:
1175                              break ;
1176                          case CUSTOM_FIELD_DATE_NONE:
1177                              array_push( $t_join_clauses, $t_cf_join_clause );
1178                              $t_custom_where_clause = '(( ' . $t_table_name . '.bug_id is null) OR ( ' . $t_table_name . '.value = 0)' ;
1179                              break ;
1180                          case CUSTOM_FIELD_DATE_BEFORE:
1181                              array_push( $t_join_clauses, $t_cf_join_clause );
1182                              $t_custom_where_clause = '(( ' . $t_table_name . '.value != 0 AND (' . $t_table_name . '.value+0) < ' . ($t_filter['custom_fields'][$t_cfid][2]) . ')' ;
1183                              break ;
1184                          case CUSTOM_FIELD_DATE_AFTER:
1185                              array_push( $t_join_clauses, $t_cf_join_clause );
1186                              $t_custom_where_clause = '( (' . $t_table_name . '.value+0) > ' . ($t_filter['custom_fields'][$t_cfid][1]+1) ;
1187                              break ;
1188                          default:
1189                              array_push( $t_join_clauses, $t_cf_join_clause );
1190                              $t_custom_where_clause = '( (' . $t_table_name . '.value+0) BETWEEN ' . $t_filter['custom_fields'][$t_cfid][1] . ' AND ' . $t_filter['custom_fields'][$t_cfid][2];
1191                              break ;
1192                          }
1193                      } else {
1194  
1195                          array_push( $t_join_clauses, $t_cf_join_clause );
1196  
1197                          $t_filter_array = array();
1198                          foreach( $t_filter['custom_fields'][$t_cfid] as $t_filter_member ) {
1199                              $t_filter_member = stripslashes( $t_filter_member );
1200                              if ( META_FILTER_NONE == $t_filter_member ) { 
1201                                  # coerce filter value if selecting META_FILTER_NONE so it will match empty fields
1202                                  $t_filter_member = '';
1203                                  # but also add those _not_ present in the custom field string table
1204                                  array_push( $t_filter_array , "$t_bug_table.id NOT IN (SELECT bug_id FROM $t_custom_field_string_table WHERE field_id=$t_cfid)" );
1205                              }
1206  
1207                              switch( $t_def['type'] ) {
1208                                  case CUSTOM_FIELD_TYPE_MULTILIST:
1209                                  case CUSTOM_FIELD_TYPE_CHECKBOX:
1210                                      array_push( $t_filter_array , db_helper_like( "$t_table_name.value", '%|' . db_prepare_string( $t_filter_member ) . '|%' ) );
1211                                      break;
1212                                  default:
1213                                      array_push( $t_filter_array, "$t_table_name.value = '" . db_prepare_string( $t_filter_member ) . "'" );
1214                              }
1215                          }
1216                          $t_custom_where_clause .= '(' . implode( ' OR ', $t_filter_array );
1217                      }
1218                      if ( !is_blank( $t_custom_where_clause ) ) {
1219                          array_push( $t_where_clauses, $t_custom_where_clause . ')' );
1220                      }
1221                  }
1222              }
1223          }
1224  
1225          $t_textsearch_where_clause = '';
1226          $t_textsearch_wherejoin_clause = '';
1227          # Simple Text Search - Thanks to Alan Knowles
1228          if ( !is_blank( $t_filter['search'] ) ) {
1229              $c_search = db_prepare_string( $t_filter['search'] );
1230              $c_search_int = db_prepare_int( $t_filter['search'] );
1231              $t_textsearch_where_clause = '(' . db_helper_like( 'summary', "%$c_search%" ) .
1232                               ' OR ' . db_helper_like( "$t_bug_text_table.description", "%$c_search%" ) . 
1233                               ' OR ' . db_helper_like( "$t_bug_text_table.steps_to_reproduce", "%$c_search%" ) .
1234                               ' OR ' . db_helper_like( "$t_bug_text_table.additional_information", "%$c_search%" ) .
1235                               " OR ( $t_bug_table.id = '$c_search_int' ) )";
1236  
1237              $t_textsearch_wherejoin_clause = '(' . db_helper_like( 'summary', "%$c_search%" ) .
1238                               ' OR ' . db_helper_like( "$t_bug_text_table.description", "%$c_search%" ) .
1239                               ' OR ' . db_helper_like( "$t_bug_text_table.steps_to_reproduce", "%$c_search%" ) .
1240                               ' OR ' . db_helper_like( "$t_bug_text_table.additional_information", "%$c_search%" ) .
1241                               ' OR ' . db_helper_like( "$t_bug_table.id", "%$c_search%" ) .
1242                               ' OR ' . db_helper_like( "$t_bugnote_text_table.note", "%$c_search%" ) . ' )';
1243  
1244              array_push( $t_where_clauses, "($t_bug_text_table.id = $t_bug_table.bug_text_id)" );
1245  
1246              $t_from_clauses = array( $t_bug_text_table, $t_project_table, $t_bug_table );
1247          } else {
1248              $t_from_clauses = array( $t_project_table, $t_bug_table );
1249          }
1250  
1251          $t_select    = implode( ', ', array_unique( $t_select_clauses ) );
1252          $t_from        = 'FROM ' . implode( ', ', array_unique( $t_from_clauses ) );
1253          $t_join        = implode( ' ', $t_join_clauses );
1254          if ( count( $t_where_clauses ) > 0 ) {
1255              $t_where    = 'WHERE ' . implode( ' AND ', $t_where_clauses );
1256          } else {
1257              $t_where    = '';
1258          }
1259  
1260          # Possibly do two passes. First time, grab the IDs of issues that match the filters. Second time, grab the IDs of issues that
1261          # have bugnotes that match the text search if necessary.
1262          $t_id_array = array();
1263          for ( $i = 0; $i < 2; $i++ ) {
1264              $t_id_where = $t_where;
1265              $t_id_join = $t_join;
1266              if ( $i == 0 ) {
1267                  if ( !is_blank( $t_id_where ) && !is_blank( $t_textsearch_where_clause ) ) {
1268                      $t_id_where = $t_id_where . ' AND ' . $t_textsearch_where_clause;
1269                  }
1270              } else if ( !is_blank( $t_textsearch_wherejoin_clause ) ) {
1271                  $t_id_where = $t_id_where . ' AND ' . $t_textsearch_wherejoin_clause;
1272                  $t_id_join = $t_id_join . " INNER JOIN $t_bugnote_table ON $t_bugnote_table.bug_id = $t_bug_table.id";
1273                  $t_id_join = $t_id_join . " INNER JOIN $t_bugnote_text_table ON $t_bugnote_text_table.id = $t_bugnote_table.bugnote_text_id";
1274              }
1275              $query  = "SELECT DISTINCT $t_bug_table.id AS id
1276                          $t_from
1277                          $t_id_join
1278                          $t_id_where";
1279              if ( ( $i == 0 ) || ( !is_blank( $t_textsearch_wherejoin_clause ) ) ) {
1280                  $result = db_query( $query );
1281                  $row_count = db_num_rows( $result );
1282  
1283                  for ( $j=0; $j < $row_count; $j++ ) {
1284                      $row = db_fetch_array( $result );
1285                      $t_id_array[] = db_prepare_int ( $row['id'] );
1286                  }
1287              }
1288          }
1289  
1290          $t_id_array = array_unique( $t_id_array );
1291  
1292          # Get the total number of bugs that meet the criteria.
1293          $bug_count = count( $t_id_array );
1294  
1295          $rows = array();
1296  
1297          if ( $bug_count > 0 ) {
1298              $t_where = "WHERE $t_bug_table.id in (" . implode( ", ", $t_id_array ) . ")";
1299          } else {
1300              return $rows;
1301          }
1302  
1303          $t_from = 'FROM ' . $t_bug_table;
1304  
1305          # write the value back in case the caller wants to know
1306          $p_bug_count = $bug_count;
1307  
1308          if ( null === $p_per_page ) {
1309              $p_per_page = (int)$t_filter['per_page'];
1310          } else if ( -1 == $p_per_page ) {
1311              $p_per_page = $bug_count;
1312          }
1313  
1314          # Guard against silly values of $f_per_page.
1315          if ( 0 == $p_per_page ) {
1316              $p_per_page = $bug_count;    // 0 - means show all
1317          }
1318  
1319          $p_per_page = (int)abs( $p_per_page );
1320  
1321          # Use $bug_count and $p_per_page to determine how many pages
1322          # to split this list up into.
1323          # For the sake of consistency have at least one page, even if it
1324          # is empty.
1325          $t_page_count = ceil($bug_count / $p_per_page);
1326          if ( $t_page_count < 1 ) {
1327              $t_page_count = 1;
1328          }
1329  
1330          # write the value back in case the caller wants to know
1331          $p_page_count = $t_page_count;
1332  
1333          # Make sure $p_page_number isn't past the last page.
1334          if ( $p_page_number > $t_page_count ) {
1335              $p_page_number = $t_page_count;
1336          }
1337  
1338          # Make sure $p_page_number isn't before the first page
1339          if ( $p_page_number < 1 ) {
1340              $p_page_number = 1;
1341          }
1342  
1343          # Now add the rest of the criteria i.e. sorting, limit.
1344  
1345          # if sort is blank then default the sort and direction.  This is to fix the
1346          # symptoms of #3953.  Note that even if the main problem is fixed, we may
1347          # have to keep this code for a while to handle filters saved with this blank field.
1348          if ( is_blank( $t_filter['sort'] ) ) {
1349              $t_filter['sort'] = 'last_updated';
1350              $t_filter['dir'] = 'DESC';
1351          }
1352  
1353          $t_order_array = array();
1354          $t_sort_fields = split( ',', $t_filter['sort'] );
1355          $t_dir_fields = split( ',', $t_filter['dir'] );
1356  
1357          if ( ( 'on' == $t_filter['sticky_issues'] ) && ( NULL !== $p_show_sticky ) ) {
1358              $t_order_array[] = "sticky DESC";
1359          }
1360          
1361          $t_join = '';
1362          for ( $i=0; $i < count( $t_sort_fields ); $i++ ) {
1363              $c_sort = db_prepare_string( $t_sort_fields[$i] );
1364  
1365              if ( ! in_array( $t_sort_fields[$i], array_slice( $t_sort_fields, $i + 1) ) ) {
1366  
1367                  # if sorting by a custom field
1368                  if ( strpos( $c_sort, 'custom_' ) === 0 ) {
1369                      $t_custom_field = substr( $c_sort, strlen( 'custom_' ) );
1370                      $t_custom_field_id = custom_field_get_id_from_name( $t_custom_field );
1371                      $t_join .= " LEFT JOIN $t_custom_field_string_table ON ( ( $t_custom_field_string_table.bug_id = $t_bug_table.id ) AND ( $t_custom_field_string_table.field_id = $t_custom_field_id ) )";
1372                      $c_sort = "$t_custom_field_string_table.value";
1373                      $t_select_clauses[] = "$t_custom_field_string_table.value";
1374                      }
1375  
1376                  if ( 'DESC' == $t_dir_fields[$i] ) {
1377                      $c_dir = 'DESC';
1378                  } else {
1379                      $c_dir = 'ASC';
1380                  }
1381  
1382                  $t_order_array[] = "$c_sort $c_dir";
1383              }
1384          }
1385  
1386          # add basic sorting if necessary
1387          if ( ! in_array( 'last_updated', $t_sort_fields ) ) {
1388              $t_order_array[] = 'last_updated DESC';
1389          }
1390          if ( ! in_array( 'date_submitted', $t_sort_fields ) ) {
1391              $t_order_array[] = 'date_submitted DESC';
1392          }
1393  
1394          $t_order = " ORDER BY " . implode( ', ', $t_order_array );
1395          $t_select    = implode( ', ', array_unique( $t_select_clauses ) );
1396  
1397          $query2  = "SELECT DISTINCT $t_select
1398                      $t_from
1399                      $t_join
1400                      $t_where
1401                      $t_order";
1402  
1403          # Figure out the offset into the db query
1404          #
1405          # for example page number 1, per page 5:
1406          #     t_offset = 0
1407          # for example page number 2, per page 5:
1408          #     t_offset = 5
1409          $c_per_page = db_prepare_int( $p_per_page );
1410          $c_page_number = db_prepare_int( $p_page_number );
1411          $t_offset = ( ( $c_page_number - 1 ) * $c_per_page );
1412  
1413          # perform query
1414          $result2 = db_query( $query2, $c_per_page, $t_offset );
1415  
1416          $row_count = db_num_rows( $result2 );
1417  
1418          $t_id_array_lastmod = array();
1419          
1420          for ( $i=0 ; $i < $row_count ; $i++ ) {
1421              $row = db_fetch_array( $result2 );
1422              $t_id_array_lastmod[] = db_prepare_int ( $row['id'] );
1423              
1424              $row['date_submitted'] = db_unixtimestamp ( $row['date_submitted'] );
1425              $row['last_updated'] = db_unixtimestamp ( $row['last_updated'] );
1426                      
1427              array_push( $rows, $row );
1428          }
1429  
1430          $t_id_array_lastmod = array_unique( $t_id_array_lastmod );
1431          
1432          // paulr: it should be impossible for t_id_array_lastmod to be array():
1433          // that would imply that $t_id_array is null which aborts this function early
1434          //if ( count( $t_id_array_lastmod ) > 0 ) {
1435          $t_where = "WHERE $t_bugnote_table.bug_id in (" . implode( ", ", $t_id_array_lastmod ) . ")";
1436          
1437          $query3 = "SELECT DISTINCT bug_id,MAX(last_modified) as last_modified, COUNT(last_modified) as count FROM $t_bugnote_table $t_where GROUP BY bug_id";
1438  
1439          # perform query
1440          $result3 = db_query( $query3 );
1441  
1442          $row_count = db_num_rows( $result3 );
1443  
1444          for ( $i=0 ; $i < $row_count ; $i++ ) {
1445              $row = db_fetch_array( $result3 );
1446              
1447              $t_stats[ $row['bug_id'] ] = $row;
1448          }
1449  
1450          foreach($rows as $row) {
1451              if( !isset( $t_stats[ $row['id'] ] ) ) {
1452                  bug_cache_database_result( $row, false );
1453              } else {
1454                  bug_cache_database_result( $row, $t_stats[ $row['id'] ] );
1455              }
1456          }
1457  
1458          return $rows;
1459      }
1460  
1461      # --------------------
1462      # return true if the filter cookie exists and is of the correct version,
1463      #  false otherwise
1464  	function filter_is_cookie_valid() {
1465          $t_view_all_cookie_id = gpc_get_cookie( config_get( 'view_all_cookie' ), '' );
1466          $t_view_all_cookie = filter_db_get_filter( $t_view_all_cookie_id );
1467  
1468          # check to see if the cookie does not exist
1469          if ( is_blank( $t_view_all_cookie ) ) {
1470              return false;
1471          }
1472  
1473          # check to see if new cookie is needed
1474          $t_setting_arr = explode( '#', $t_view_all_cookie, 2 );
1475          if ( ( $t_setting_arr[0] == 'v1' ) ||
1476               ( $t_setting_arr[0] == 'v2' ) ||
1477               ( $t_setting_arr[0] == 'v3' ) ||
1478               ( $t_setting_arr[0] == 'v4' ) ) {
1479              return false;
1480          }
1481  
1482          # We shouldn't need to do this anymore, as filters from v5 onwards should cope with changing
1483          # filter indices dynamically
1484          $t_filter_cookie_arr = array();
1485          if ( isset( $t_setting_arr[1] ) ) {
1486              $t_filter_cookie_arr = unserialize( $t_setting_arr[1] );
1487          } else {
1488              return false;
1489          }
1490          if ( $t_filter_cookie_arr['_version'] != config_get( 'cookie_version' ) ) {
1491              return false;
1492          }
1493  
1494          return true;
1495      }
1496  
1497      # --------------------
1498      # return filter array if supplied serialized filter is valid, otherwise false.otherwise
1499  	function filter_deserialize( $p_serialized_filter ) {
1500          if ( is_blank( $p_serialized_filter ) ) {
1501              return false;
1502          }
1503  
1504          # check to see if new cookie is needed
1505          $t_setting_arr = explode( '#', $p_serialized_filter, 2 );
1506          if ( ( $t_setting_arr[0] == 'v1' ) ||
1507               ( $t_setting_arr[0] == 'v2' ) ||
1508               ( $t_setting_arr[0] == 'v3' ) ||
1509               ( $t_setting_arr[0] == 'v4' ) ) {
1510              # these versions can't be salvaged, they are too old to update
1511              return false;
1512          }
1513  
1514          # We shouldn't need to do this anymore, as filters from v5 onwards should cope with changing
1515          # filter indices dynamically
1516          $t_filter_array = array();
1517          if ( isset( $t_setting_arr[1] ) ) {
1518              $t_filter_array = unserialize( $t_setting_arr[1] );
1519          } else {
1520              return false;
1521          }
1522          if ( $t_filter_array['_version'] != config_get( 'cookie_version' ) ) {
1523              # if the version is not new enough, update it using defaults
1524              return filter_ensure_valid_filter( $t_filter_array );
1525          }
1526  
1527          return $t_filter_array;
1528      }
1529  
1530      # --------------------
1531      # Mainly based on filter_draw_selection_area2() but adds the support for the collapsible
1532      # filter display.
1533  	function filter_draw_selection_area( $p_page_number, $p_for_screen = true )
1534      {
1535          collapse_open( 'filter' );
1536          filter_draw_selection_area2( $p_page_number, $p_for_screen, true );
1537          collapse_closed( 'filter' );
1538          filter_draw_selection_area2( $p_page_number, $p_for_screen, false );
1539          collapse_end( 'filter' );
1540      }
1541  
1542      # --------------------
1543      # Will print the filter selection area for both the bug list view screen, as well
1544      # as the bug list print screen. This function was an attempt to make it easier to
1545      # add new filters and rearrange them on screen for both pages.
1546  	function filter_draw_selection_area2( $p_page_number, $p_for_screen = true, $p_expanded = true )
1547      {
1548          $t_form_name_suffix = $p_expanded ? '_open' : '_closed';
1549  
1550          $t_filter = current_user_get_bug_filter();
1551          $t_filter = filter_ensure_valid_filter( $t_filter );
1552          $t_project_id = helper_get_current_project();
1553          $t_page_number = (int) $p_page_number;
1554  
1555          $t_view_type = $t_filter['_view_type'];
1556  
1557          $t_tdclass = 'small-caption';
1558          $t_trclass = 'row-category2';
1559          $t_action  = 'view_all_set.php?f=3';
1560  
1561          if ( $p_for_screen == false ) {
1562              $t_tdclass = 'print';
1563              $t_trclass = '';
1564              $t_action  = 'view_all_set.php';
1565          }
1566  ?>
1567  
1568          <br />
1569          <form method="post" name="filters<?php echo $t_form_name_suffix ?>" id="filters_form<?php echo $t_form_name_suffix ?>" action="<?php PRINT $t_action; ?>">
1570          <input type="hidden" name="type" value="1" />
1571          <?php
1572              if ( $p_for_screen == false ) {
1573                  PRINT '<input type="hidden" name="print" value="1" />';
1574                  PRINT '<input type="hidden" name="offset" value="0" />';
1575              }
1576          ?>
1577          <input type="hidden" name="page_number" value="<?php PRINT $t_page_number ?>" />
1578          <input type="hidden" name="view_type" value="<?php PRINT $t_view_type ?>" />
1579          <table class="width100" cellspacing="1">
1580  
1581          <?php
1582          $t_filter_cols = config_get( 'filter_custom_fields_per_row' );
1583          if ( $p_expanded ) {
1584              $t_custom_cols = $t_filter_cols;
1585  
1586              $t_current_user_access_level = current_user_get_access_level();
1587              $t_accessible_custom_fields_ids = array();
1588              $t_accessible_custom_fields_names = array();
1589              $t_accessible_custom_fields_values = array();
1590              $t_num_custom_rows = 0;
1591              $t_per_row = 0;
1592  
1593              if ( ON == config_get( 'filter_by_custom_fields' ) ) {
1594                  $t_custom_fields = custom_field_get_linked_ids( $t_project_id );
1595  
1596                  foreach ( $t_custom_fields as $t_cfid ) {
1597                      $t_field_info = custom_field_cache_row( $t_cfid, true );
1598                      if ( $t_field_info['access_level_r'] <= $t_current_user_access_level ) {
1599                          $t_accessible_custom_fields_ids[] = $t_cfid;
1600                          $t_accessible_custom_fields_names[] = $t_field_info['name'];
1601                          $t_accessible_custom_fields_types[] = $t_field_info['type'];
1602                          $t_accessible_custom_fields_values[] = custom_field_distinct_values( $t_cfid );
1603                      }
1604                  }
1605  
1606                  if ( count( $t_accessible_custom_fields_ids ) > 0 ) {
1607                      $t_per_row = config_get( 'filter_custom_fields_per_row' );
1608                      $t_num_custom_rows = ceil( count( $t_accessible_custom_fields_ids ) / $t_per_row );
1609                  }
1610              }
1611  
1612              $t_filters_url = 'view_filters_page.php?for_screen=' . $p_for_screen;
1613              if ( 'advanced' == $t_view_type ) {
1614                  $t_filters_url = $t_filters_url . '&amp;view_type=advanced';
1615              }
1616              $t_filters_url = $t_filters_url . '&amp;target_field=';
1617  
1618              $t_show_version = ( ON == config_get( 'show_product_version' ) )
1619                      || ( ( AUTO == config_get( 'show_product_version' ) )
1620                                  && ( count( version_get_all_rows_with_subs( $t_project_id ) ) > 0 ) );
1621              # overload handler_id setting if user isn't supposed to see them (ref #6189)
1622              if ( ! access_has_project_level( config_get( 'view_handler_threshold' ), $t_project_id ) ) { 
1623                  $t_filter['handler_id'] = array( META_FILTER_ANY ); 
1624              } 
1625          ?>
1626  
1627          <tr <?php PRINT "class=\"" . $t_trclass . "\""; ?>>
1628              <td class="small-caption" valign="top">
1629                  <a href="<?php PRINT $t_filters_url . 'reporter_id[]'; ?>" id="reporter_id_filter"><?php PRINT lang_get( 'reporter' ) ?>:</a>
1630              </td>
1631              <td class="small-caption" valign="top">
1632                  <a href="<?php PRINT $t_filters_url . 'user_monitor[]'; ?>" id="user_monitor_filter"><?php PRINT lang_get( 'monitored_by' ) ?>:</a>
1633              </td>
1634              <td class="small-caption" valign="top">
1635                  <a href="<?php PRINT $t_filters_url . 'handler_id[]'; ?>" id="handler_id_filter"><?php PRINT lang_get( 'assigned_to' ) ?>:</a>
1636              </td>
1637              <td colspan="2" class="small-caption" valign="top">
1638                  <a href="<?php PRINT $t_filters_url . 'show_category[]'; ?>" id="show_category_filter"><?php PRINT lang_get( 'category' ) ?>:</a>
1639              </td>
1640              <td class="small-caption" valign="top">
1641                  <a href="<?php PRINT $t_filters_url . 'show_severity[]'; ?>" id="show_severity_filter"><?php PRINT lang_get( 'severity' ) ?>:</a>
1642              </td>
1643              <td class="small-caption" valign="top">
1644                  <a href="<?php PRINT $t_filters_url . 'show_resolution[]'; ?>" id="show_resolution_filter"><?php PRINT lang_get( 'resolution' ) ?>:</a>
1645              </td>
1646              <td class="small-caption" valign="top">
1647                  <a href="<?php PRINT $t_filters_url . 'show_profile[]'; ?>" id="show_profile_filter"><?php PRINT lang_get( 'profile' ) ?>:</a>
1648              </td>
1649              <?php if ( $t_filter_cols > 8 ) {
1650                  echo '<td class="small-caption" valign="top" colspan="' . ( $t_filter_cols - 8 ) . '">&nbsp;</td>';
1651              } ?>
1652          </tr>
1653  
1654          <tr class="row-1">
1655              <td class="small-caption" valign="top" id="reporter_id_filter_target">
1656                              <?php
1657                                  $t_output = '';
1658                                  $t_any_found = false;
1659                                  if ( count( $t_filter['reporter_id'] ) == 0 ) {
1660                                      PRINT lang_get( 'any' );
1661                                  } else {
1662                                      $t_first_flag = true;
1663                                      foreach( $t_filter['reporter_id'] as $t_current ) {
1664                                          $t_this_name = '';
1665                                          ?>
1666                                          <input type="hidden" name="reporter_id[]" value="<?php echo $t_current;?>" />
1667                                          <?php
1668                                          if ( ( $t_current === 0 ) || ( is_blank( $t_current ) ) || ( META_FILTER_ANY == $t_current ) ) {
1669                                              $t_any_found = true;
1670                                          } else if ( META_FILTER_MYSELF == $t_current ) {
1671                                              if ( access_has_project_level( config_get( 'report_bug_threshold' ) ) ) {
1672                                                  $t_this_name = '[' . lang_get( 'myself' ) . ']';
1673                                              } else {
1674                                                  $t_any_found = true;
1675                                              }
1676                                          } else if ( META_FILTER_NONE == $t_current ) {
1677                                              $t_this_name = lang_get( 'none' );
1678                                          } else {
1679                                              $t_this_name = user_get_name( $t_current );
1680                                          }
1681                                          if ( $t_first_flag != true ) {
1682                                              $t_output = $t_output . '<br />';
1683                                          } else {
1684                                              $t_first_flag = false;
1685                                          }
1686                                          $t_output = $t_output . $t_this_name;
1687                                      }
1688                                      if ( true == $t_any_found ) {
1689                                          PRINT lang_get( 'any' );
1690                                      } else {
1691                                          PRINT $t_output;
1692                                      }
1693                                  }
1694                              ?>
1695              </td>
1696              <td class="small-caption" valign="top" id="user_monitor_filter_target">
1697                              <?php
1698                                  $t_output = '';
1699                                  $t_any_found = false;
1700                                  if ( count( $t_filter['user_monitor'] ) == 0 ) {
1701                                      PRINT lang_get( 'any' );
1702                                  } else {
1703                                      $t_first_flag = true;
1704                                      foreach( $t_filter['user_monitor'] as $t_current ) {
1705                                          ?>
1706                                          <input type="hidden" name="user_monitor[]" value="<?php echo $t_current;?>" />
1707                                          <?php
1708                                          $t_this_name = '';
1709                                          if ( ( $t_current === 0 ) || ( is_blank( $t_current ) ) || ( META_FILTER_ANY == $t_current ) ) {
1710                                              $t_any_found = true;
1711                                          } else if ( META_FILTER_MYSELF == $t_current ) {
1712                                              if ( access_has_project_level( config_get( 'monitor_bug_threshold' ) ) ) {
1713                                                  $t_this_name = '[' . lang_get( 'myself' ) . ']';
1714                                              } else {
1715                                                  $t_any_found = true;
1716                                              }
1717                                          } else {
1718                                              $t_this_name = user_get_name( $t_current );
1719                                          }
1720                                          if ( $t_first_flag != true ) {
1721                                              $t_output = $t_output . '<br />';
1722                                          } else {
1723                                              $t_first_flag = false;
1724                                          }
1725                                          $t_output = $t_output . $t_this_name;
1726                                      }
1727                                      if ( true == $t_any_found ) {
1728                                          PRINT lang_get( 'any' );
1729                                      } else {
1730                                          PRINT $t_output;
1731                                      }
1732                                  }
1733                              ?>
1734              </td>
1735              <td class="small-caption" valign="top" id="handler_id_filter_target">
1736                              <?php
1737                                  $t_output = '';
1738                                  $t_any_found = false;
1739                                  if ( count( $t_filter['handler_id'] ) == 0 ) {
1740                                      PRINT lang_get( 'any' );
1741                                  } else {
1742                                      $t_first_flag = true;
1743                                      foreach( $t_filter['handler_id'] as $t_current ) {
1744                                          ?>
1745                                          <input type="hidden" name="handler_id[]" value="<?php echo $t_current;?>" />
1746                                          <?php
1747                                          $t_this_name = '';
1748                                          if ( META_FILTER_NONE == $t_current ) {
1749                                              $t_this_name = lang_get( 'none' );
1750                                          } else if ( ( $t_current === 0 ) || ( is_blank( $t_current ) ) || ( META_FILTER_ANY == $t_current ) ) {
1751                                              $t_any_found = true;
1752                                          } else if ( META_FILTER_MYSELF == $t_current ) {
1753                                              if ( access_has_project_level( config_get( 'handle_bug_threshold' ) ) ) {
1754                                                  $t_this_name = '[' . lang_get( 'myself' ) . ']';
1755                                              } else {
1756                                                  $t_any_found = true;
1757                                              }
1758                                          } else {
1759                                              $t_this_name = user_get_name( $t_current );
1760                                          }
1761                                          if ( $t_first_flag != true ) {
1762                                              $t_output = $t_output . '<br />';
1763                                          } else {
1764                                              $t_first_flag = false;
1765                                          }
1766                                          $t_output = $t_output . $t_this_name;
1767                                      }
1768                                      if ( true == $t_any_found ) {
1769                                          PRINT lang_get( 'any' );
1770                                      } else {
1771                                          PRINT $t_output;
1772                                      }
1773                                  }
1774                              ?>
1775              </td>
1776              <td colspan="2" class="small-caption" valign="top" id="show_category_filter_target">
1777                              <?php
1778                                  $t_output = '';
1779                                  $t_any_found = false;
1780                                  if ( count( $t_filter['show_category'] ) == 0 ) {
1781                                      PRINT lang_get( 'any' );
1782                                  } else {
1783                                      $t_first_flag = true;
1784                                      foreach( $t_filter['show_category'] as $t_current ) {
1785                                          $t_current = stripslashes( $t_current );
1786                                          ?>
1787                                          <input type="hidden" name="show_category[]" value="<?php echo string_display( $t_current );?>" />
1788                                          <?php
1789                                          $t_this_string = '';
1790                                          if ( ( ( $t_current == META_FILTER_ANY ) && ( is_numeric( $t_current ) ) ) 
1791                                                  || ( is_blank( $t_current ) ) ) {
1792                                              $t_any_found = true;
1793                                          } else {
1794                                              $t_this_string = string_display( $t_current );
1795                                          }
1796                                          if ( $t_first_flag != true ) {
1797                                              $t_output = $t_output . '<br />';
1798                                          } else {
1799                                              $t_first_flag = false;
1800                                          }
1801                                          $t_output = $t_output . $t_this_string;
1802                                      }
1803                                      if ( true == $t_any_found ) {
1804                                          PRINT lang_get( 'any' );
1805                                      } else {
1806                                          PRINT $t_output;
1807                                      }
1808                                  }
1809                              ?>
1810              </td>
1811              <td class="small-caption" valign="top" id="show_severity_filter_target">
1812                              <?php
1813                                  $t_output = '';
1814                                  $t_any_found = false;
1815                                  if ( count( $t_filter['show_severity'] ) == 0 ) {
1816                                      PRINT lang_get( 'any' );
1817                                  } else {
1818                                      $t_first_flag = true;
1819                                      foreach( $t_filter['show_severity'] as $t_current ) {
1820                                          ?>
1821                                          <input type="hidden" name="show_severity[]" value="<?php echo $t_current;?>" />
1822                                          <?php
1823                                          $t_this_string = '';
1824                                          if ( ( $t_current === META_FILTER_ANY ) || ( is_blank( $t_current ) ) || ( $t_current == 0 ) ) {
1825                                              $t_any_found = true;
1826                                          } else {
1827                                              $t_this_string = get_enum_element( 'severity', $t_current );
1828                                          }
1829                                          if ( $t_first_flag != true ) {
1830                                              $t_output = $t_output . '<br />';
1831                                          } else {
1832                                              $t_first_flag = false;
1833                                          }
1834                                          $t_output = $t_output . $t_this_string;
1835                                      }
1836                                      if ( true == $t_any_found ) {
1837                                          PRINT lang_get( 'any' );
1838                                      } else {
1839                                          PRINT $t_output;
1840                                      }
1841                                  }
1842                              ?>
1843              </td>
1844              <td class="small-caption" valign="top" id="show_resolution_filter_target">
1845                              <?php
1846                                  $t_output = '';
1847                                  $t_any_found = false;
1848                                  if ( count( $t_filter['show_resolution'] ) == 0 ) {
1849                                      PRINT lang_get( 'any' );
1850                                  } else {
1851                                      $t_first_flag = true;
1852                                      foreach( $t_filter['show_resolution'] as $t_current ) {
1853                                          ?>
1854                                          <input type="hidden" name="show_resolution[]" value="<?php echo $t_current;?>" />
1855                                          <?php
1856                                          $t_this_string = '';
1857                                          if ( ( $t_current === META_FILTER_ANY ) || ( is_blank( $t_current ) ) || ( $t_current === 0 ) ) {
1858                                              $t_any_found = true;
1859                                          } else {
1860                                              $t_this_string = get_enum_element( 'resolution', $t_current );
1861                                          }
1862                                          if ( $t_first_flag != true ) {
1863                                              $t_output = $t_output . '<br />';
1864                                          } else {
1865                                              $t_first_flag = false;
1866                                          }
1867                                          $t_output = $t_output . $t_this_string;
1868                                      }
1869                                      if ( true == $t_any_found ) {
1870                                          PRINT lang_get( 'any' );
1871                                      } else {
1872                                          PRINT $t_output;
1873                                      }
1874                                  }
1875                              ?>
1876              </td>
1877              <td class="small-caption" valign="top" id="show_profile_filter_target">
1878                              <?php
1879                                  $t_output = '';
1880                                  $t_any_found = false;
1881                                  if ( count( $t_filter['show_profile'] ) == 0 ) {
1882                                      PRINT lang_get( 'any' );
1883                                  } else {
1884                                      $t_first_flag = true;
1885                                      foreach( $t_filter['show_profile'] as $t_current ) {
1886                                          ?>
1887                                          <input type="hidden" name="show_profile[]" value="<?php echo $t_current;?>" />
1888                                          <?php
1889                                          $t_this_string = '';
1890                                          if ( ( $t_current === META_FILTER_ANY ) || ( is_blank( $t_current ) ) || ( $t_current === 0 ) ) {
1891                                              $t_any_found = true;
1892                                          } else {
1893                                              $t_profile = profile_get_row_direct( $t_current );
1894  
1895                                              $t_this_string = "$t_profile['platform']} $t_profile['os']} $t_profile['os_build']}";
1896                                          }
1897                                          if ( $t_first_flag != true ) {
1898                                              $t_output = $t_output . '<br />';
1899                                          } else {
1900                                              $t_first_flag = false;
1901                                          }
1902                                          $t_output = $t_output . $t_this_string;
1903                                      }
1904                                      if ( true == $t_any_found ) {
1905                                          PRINT lang_get( 'any' );
1906                                      } else {
1907                                          PRINT $t_output;
1908                                      }
1909                                  }
1910                              ?>
1911              </td>
1912              <?php if ( $t_filter_cols > 8 ) {
1913                  echo '<td class="small-caption" valign="top" colspan="' . ( $t_filter_cols - 8 ) . '">&nbsp;</td>';
1914              } ?>
1915              </tr>
1916  
1917          <tr <?php PRINT "class=\"" . $t_trclass . "\""; ?>>
1918              <td class="small-caption" valign="top">
1919                  <a href="<?php PRINT $t_filters_url . 'show_status[]'; ?>" id="show_status_filter"><?php PRINT lang_get( 'status' ) ?>:</a>
1920              </td>
1921              <td class="small-caption" valign="top">
1922                  <?php if ( 'simple' == $t_view_type ) { ?>
1923                      <a href="<?php PRINT $t_filters_url . 'hide_status[]'; ?>" id="hide_status_filter"><?php PRINT lang_get( 'hide_status' ) ?>:</a>
1924                  <?php } ?>
1925              </td>
1926              <td class="small-caption" valign="top">
1927                  <a href="<?php PRINT $t_filters_url . 'show_build[]'; ?>" id="show_build_filter"><?php PRINT lang_get( 'product_build' ) ?>:</a>
1928              </td>
1929              <?php if ( $t_show_version ) { ?>
1930              <td colspan="2" class="small-caption" valign="top">
1931                  <a href="<?php PRINT $t_filters_url . 'show_version[]'; ?>" id="show_version_filter"><?php PRINT lang_get( 'product_version' ) ?>:</a>
1932              </td>
1933              <td colspan="1" class="small-caption" valign="top">
1934                  <a href="<?php PRINT $t_filters_url . 'fixed_in_version[]'; ?>" id="show_fixed_in_version_filter"><?php PRINT lang_get( 'fixed_in_version' ) ?>:</a>
1935              </td>
1936              <?php } else { ?>
1937              <td colspan="2" class="small-caption" valign="top">
1938                  &nbsp;
1939              </td>
1940              <td colspan="1" class="small-caption" valign="top">
1941                  &nbsp;
1942              </td>
1943              <?php } ?>
1944              <td colspan="1" class="small-caption" valign="top">
1945                  <a href="<?php PRINT $t_filters_url . 'show_priority[]'; ?>" id="show_priority_filter"><?php PRINT lang_get( 'priority' ) ?>:</a>
1946              </td>
1947              <td colspan="1" class="small-caption" valign="top">
1948                  <a href="<?php echo $t_filters_url . 'target_version[]'; ?>" id="show_target_version_filter"><?php echo lang_get( 'target_version' ) ?>:</a>
1949              </td>
1950              <?php if ( $t_filter_cols > 8 ) {
1951                  echo '<td class="small-caption" valign="top" colspan="' . ( $t_filter_cols - 7 ) . '">&nbsp;</td>';
1952              } ?>
1953          </tr>
1954  
1955          <tr class="row-1">
1956              <td class="small-caption" valign="top" id="show_status_filter_target">
1957                              <?php
1958                                  $t_output = '';
1959                                  $t_any_found = false;
1960                                  if ( count( $t_filter['show_status'] ) == 0 ) {
1961                                      PRINT lang_get( 'any' );
1962                                  } else {
1963                                      $t_first_flag = true;
1964                                      foreach( $t_filter['show_status'] as $t_current ) {
1965                                          ?>
1966                                          <input type="hidden" name="show_status[]" value="<?php echo $t_current;?>" />
1967                                          <?php
1968                                          $t_this_string = '';
1969                                          if ( ( $t_current === META_FILTER_ANY ) || ( is_blank( $t_current ) ) || ( $t_current === 0 ) ) {
1970                                              $t_any_found = true;
1971                                          } else {
1972                                              $t_this_string = get_enum_element( 'status', $t_current );
1973                                          }
1974                                          if ( $t_first_flag != true ) {
1975                                              $t_output = $t_output . '<br />';
1976                                          } else {
1977                                              $t_first_flag = false;
1978                                          }
1979                                          $t_output = $t_output . $t_this_string;
1980                                      }
1981                                      if ( true == $t_any_found ) {
1982                                          PRINT lang_get( 'any' );
1983                                      } else {
1984                                          PRINT $t_output;
1985                                      }
1986                                  }
1987                              ?>
1988              </td>
1989              <td class="small-caption" valign="top" id="hide_status_filter_target">
1990                              <?php
1991                                  if ( 'simple' == $t_view_type ) {
1992                                      $t_output = '';
1993                                      $t_none_found = false;
1994                                      if ( count( $t_filter['hide_status'] ) == 0 ) {
1995                                          PRINT lang_get( 'none' );
1996                                      } else {
1997                                          $t_first_flag = true;
1998                                          foreach( $t_filter['hide_status'] as $t_current ) {
1999                                              ?>
2000                                              <input type="hidden" name="hide_status[]" value="<?php echo $t_current;?>" />
2001                                              <?php
2002                                              $t_this_string = '';
2003                                              if ( ( $t_current == META_FILTER_NONE ) || ( is_blank( $t_current ) ) || ( $t_current === 0 ) ) {
2004                                                  $t_none_found = true;
2005                                              } else {
2006                                                  $t_this_string = get_enum_element( 'status', $t_current );
2007                                              }
2008                                              if ( $t_first_flag != true ) {
2009                                                  $t_output = $t_output . '<br />';
2010                                              } else {
2011                                                  $t_first_flag = false;
2012                                              }
2013                                              $t_output = $t_output . $t_this_string;
2014                                          }
2015                                          $t_hide_status_post = '';
2016                                          if ( count( $t_filter['hide_status'] ) == 1 ) {
2017                                              $t_hide_status_post = ' (' . lang_get( 'and_above' ) . ')';
2018                                          }
2019                                          if ( true == $t_none_found ) {
2020                                              PRINT lang_get( 'none' );
2021                                          } else {
2022                                              PRINT $t_output . $t_hide_status_post;
2023                                          }
2024                                      }
2025                                  }
2026                              ?>
2027              </td>
2028              <td class="small-caption" valign="top" id="show_build_filter_target">
2029                              <?php
2030                                  $t_output = '';
2031                                  $t_any_found = false;
2032                                  if ( count( $t_filter['show_build'] ) == 0 ) {
2033                                      PRINT lang_get( 'any' );
2034                                  } else {
2035                                      $t_first_flag = true;
2036                                      foreach( $t_filter['show_build'] as $t_current ) {
2037                                          $t_current = stripslashes( $t_current );
2038                                          ?>
2039                                          <input type="hidden" name="show_build[]" value="<?php echo string_display( $t_current );?>" />
2040                                          <?php
2041                                          $t_this_string = '';
2042                                          if ( ( ( $t_current == META_FILTER_ANY ) && ( is_numeric( $t_current ) ) ) 
2043                                                  || ( is_blank( $t_current ) ) ) {
2044                                              $t_any_found = true;
2045                                          } else if ( META_FILTER_NONE == $t_current ) {
2046                                              $t_this_string = lang_get( 'none' );
2047                                          } else {
2048                                              $t_this_string = string_display( $t_current );
2049                                          }
2050                                          if ( $t_first_flag != true ) {
2051                                              $t_output = $t_output . '<br />';
2052                                          } else {
2053                                              $t_first_flag = false;
2054                                          }
2055                                          $t_output = $t_output . $t_this_string;
2056                                      }
2057                                      if ( true == $t_any_found ) {
2058                                          PRINT lang_get( 'any' );
2059                                      } else {
2060                                          PRINT $t_output;
2061                                      }
2062                                  }
2063                              ?>
2064              </td>
2065              <?php if ( $t_show_version ) { ?>
2066              <td colspan="2" class="small-caption" valign="top" id="show_version_filter_target">
2067                              <?php
2068                                  $t_output = '';
2069                                  $t_any_found = false;
2070                                  if ( count( $t_filter['show_version'] ) == 0 ) {
2071                                      PRINT lang_get( 'any' );
2072                                  } else {
2073                                      $t_first_flag = true;
2074                                      foreach( $t_filter['show_version'] as $t_current ) {
2075                                          $t_current = stripslashes( $t_current );
2076                                          ?>
2077                                          <input type="hidden" name="show_version[]" value="<?php echo string_display( $t_current );?>" />
2078                                          <?php
2079                                          $t_this_string = '';
2080                                          if ( ( ( $t_current == META_FILTER_ANY ) && (is_numeric( $t_current ) ) ) 
2081                                                  || ( is_blank( $t_current ) ) ) {
2082                                              $t_any_found = true;
2083                                          } else if ( META_FILTER_NONE == $t_current ) {
2084                                              $t_this_string = lang_get( 'none' );
2085                                          } else {
2086                                              $t_this_string = string_display( $t_current );
2087                                          }
2088                                          if ( $t_first_flag != true ) {
2089                                              $t_output = $t_output . '<br />';
2090                                          } else {
2091                                              $t_first_flag = false;
2092                                          }
2093                                          $t_output = $t_output . $t_this_string;
2094                                      }
2095                                      if ( true == $t_any_found ) {
2096                                          PRINT lang_get( 'any' );
2097                                      } else {
2098                                          PRINT $t_output;
2099                                      }
2100                                  }
2101                              ?>
2102              </td>
2103              <td colspan="1" class="small-caption" valign="top" id="show_fixed_in_version_filter_target">
2104                              <?php
2105                                  $t_output = '';
2106                                  $t_any_found = false;
2107                                  if ( count( $t_filter['fixed_in_version'] ) == 0 ) {
2108                                      PRINT lang_get( 'any' );
2109                                  } else {
2110                                      $t_first_flag = true;
2111                                      foreach( $t_filter['fixed_in_version'] as $t_current ) {
2112                                          $t_current = stripslashes( $t_current );
2113                                          ?>
2114                                          <input type="hidden" name="fixed_in_version[]" value="<?php echo string_display( $t_current );?>" />
2115                                          <?php
2116                                          $t_this_string = '';
2117                                          if ( ( ( $t_current == META_FILTER_ANY ) && ( is_numeric( $t_current ) ) ) 
2118                                                  || ( is_blank( $t_current ) ) ) {
2119                                              $t_any_found = true;
2120                                          } else if ( META_FILTER_NONE == $t_current ) {
2121                                              $t_this_string = lang_get( 'none' );
2122                                          } else {
2123                                              $t_this_string = string_display( $t_current );
2124                                          }
2125                                          if ( $t_first_flag != true ) {
2126                                              $t_output = $t_output . '<br />';
2127                                          } else {
2128                                              $t_first_flag = false;
2129                                          }
2130                                          $t_output = $t_output . $t_this_string;
2131                                      }
2132                                      if ( true == $t_any_found ) {
2133                                          PRINT lang_get( 'any' );
2134                                      } else {
2135                                          PRINT $t_output;
2136                                      }
2137                                  }
2138                              ?>
2139              </td>
2140              <?php } else { ?>
2141              <td colspan="2" class="small-caption" valign="top">
2142                  &nbsp;
2143              </td>
2144              <td colspan="1" class="small-caption" valign="top">
2145                  &nbsp;
2146              </td>
2147              <?php } ?>
2148              <td colspan="1" class="small-caption" valign="top" id="show_priority_filter_target">
2149                <?php
2150                                $t_output = '';
2151                  $t_any_found = false;
2152                  if ( count( $t_filter['show_priority'] ) == 0 ) {
2153                      PRINT lang_get( 'any' );
2154                  } else {
2155                    $t_first_flag = true;
2156                    foreach( $t_filter['show_priority'] as $t_current ) {
2157                                          ?>
2158                                          <input type="hidden" name="show_priority[]" value="<?php echo $t_current;?>" />
2159                                          <?php
2160                        $t_this_string = '';
2161                                          if ( ( $t_current === META_FILTER_ANY ) || ( is_blank( $t_current ) ) || ( $t_current === 0 ) ) {
2162                            $t_any_found = true;
2163                        } else {
2164                            $t_this_string = get_enum_element( 'priority', $t_current );
2165                        }
2166                        if ( $t_first_flag != true ) {
2167                            $t_output = $t_output . '<br />';
2168                        } else {
2169                            $t_first_flag = false;
2170                        }
2171                        $t_output = $t_output . $t_this_string;
2172                      }
2173                      if ( true == $t_any_found ) {
2174                           PRINT lang_get( 'any' );
2175                      } else {
2176                          PRINT $t_output;
2177                      }
2178                     }
2179                    ?>
2180              </td>
2181              <td colspan="1" class="small-caption" valign="top" id="show_target_version_filter_target">
2182                              <?php
2183                                  $t_output = '';
2184                                  $t_any_found = false;
2185                                  if ( count( $t_filter['target_version'] ) == 0 ) {
2186                                      PRINT lang_get( 'any' );
2187                                  } else {
2188                                      $t_first_flag = true;
2189                                      foreach( $t_filter['target_version'] as $t_current ) {
2190                                          $t_current = stripslashes( $t_current );
2191                                          ?>
2192                                          <input type="hidden" name="target_version[]" value="<?php echo string_display( $t_current );?>" />
2193                                          <?php
2194                                          $t_this_string = '';
2195                                          if ( ( ( $t_current == META_FILTER_ANY ) && ( is_numeric( $t_current ) ) ) 
2196                                                  || ( is_blank( $t_current ) ) ) {
2197                                              $t_any_found = true;
2198                                          } else if ( META_FILTER_NONE == $t_current ) {
2199                                              $t_this_string = lang_get( 'none' );
2200                                          } else {
2201                                              $t_this_string = string_display( $t_current );
2202                                          }
2203                                          if ( $t_first_flag != true ) {
2204                                              $t_output = $t_output . '<br />';
2205                                          } else {
2206                                              $t_first_flag = false;
2207                                          }
2208                                          $t_output = $t_output . $t_this_string;
2209                                      }
2210                                      if ( true == $t_any_found ) {
2211                                          PRINT lang_get( 'any' );
2212                                      } else {
2213                                          PRINT $t_output;
2214                                      }
2215                                  }
2216                              ?>
2217              </td>
2218              <?php if ( $t_filter_cols > 8 ) {
2219                  echo '<td class="small-caption" valign="top" colspan="' . ( $t_filter_cols - 7 ) . '">&nbsp;</td>';
2220              } ?>
2221  
2222          </tr>
2223  
2224          <tr <?php PRINT "class=\"" . $t_trclass . "\""; ?>>
2225              <td class="small-caption" valign="top">
2226                  <a href="<?php PRINT $t_filters_url . 'per_page'; ?>" id="per_page_filter"><?php PRINT lang_get( 'show' ) ?>:</a>
2227              </td>
2228              <td class="small-caption" valign="top">
2229                  <a href="<?php PRINT $t_filters_url . 'view_state'; ?>" id="view_state_filter"><?php PRINT lang_get( 'view_status' ) ?>:</a>
2230              </td>
2231              <td class="small-caption" valign="top">
2232                  <a href="<?php PRINT $t_filters_url . 'sticky_issues'; ?>" id="sticky_issues_filter"><?php PRINT lang_get( 'sticky' ) ?>:</a>
2233              </td>
2234              <td class="small-caption" valign="top" colspan="2">
2235                  <a href="<?php PRINT $t_filters_url . 'highlight_changed'; ?>" id="highlight_changed_filter"><?php PRINT lang_get( 'changed' ) ?>:</a>
2236              </td>
2237              <td class="small-caption" valign="top" >
2238                  <a href="<?php PRINT $t_filters_url . 'do_filter_by_date'; ?>" id="do_filter_by_date_filter"><?php PRINT lang_get( 'use_date_filters' ) ?>:</a>
2239              </td>
2240              <td class="small-caption" valign="top" colspan="2">
2241                  <a href="<?php PRINT $t_filters_url . 'relationship_type'; ?>" id="relationship_type_filter"><?php PRINT lang_get( 'bug_relationships' ) ?>:</a>
2242              </td>
2243              <?php if ( $t_filter_cols > 8 ) {
2244                  echo '<td class="small-caption" valign="top" colspan="' . ( $t_filter_cols - 8 ) . '">&nbsp;</td>';
2245              } ?>
2246          </tr>
2247          <tr class="row-1">
2248              <td class="small-caption" valign="top" id="per_page_filter_target">
2249                  <?php echo ( $t_filter['per_page'] == 0 ) ? lang_get( 'all' ) : $t_filter['per_page']; ?>
2250                  <input type="hidden" name="per_page" value="<?php echo $t_filter['per_page'];?>" />
2251              </td>
2252              <td class="small-caption" valign="top" id="view_state_filter_target">
2253                  <?php
2254                  if ( VS_PUBLIC === $t_filter['view_state'] ) {
2255                      PRINT lang_get( 'public' );
2256                  } else if ( VS_PRIVATE === $t_filter['view_state'] ) {
2257                      PRINT lang_get( 'private' );
2258                  } else {
2259                      PRINT lang_get( 'any' );
2260                      $t_filter['view_state'] = META_FILTER_ANY;
2261                  }
2262                  ?>
2263                  <input type="hidden" name="view_state" value="<?php echo $t_filter['view_state'];?>" />
2264              </td>
2265              <td class="small-caption" valign="top" id="sticky_issues_filter_target">
2266                  <?php
2267                      $t_sticky_filter_state = gpc_string_to_bool( $t_filter['sticky_issues'] )  ;
2268                      PRINT ( $t_sticky_filter_state ? lang_get( 'yes' ) : lang_get( 'no' ) );
2269                  ?>
2270                  <input type="hidden" name="sticky_issues" value="<?php echo $t_sticky_filter_state ? 'on' : 'off';?>" />
2271              </td>
2272              <td class="small-caption" valign="top" colspan="2" id="highlight_changed_filter_target">
2273                  <?php PRINT $t_filter['highlight_changed']; ?>
2274                  <input type="hidden" name="highlight_changed" value="<?php echo $t_filter['highlight_changed'];?>" />
2275              </td>
2276              <td class="small-caption" valign="top"  id="do_filter_by_date_filter_target">
2277                              <?php
2278                              if ( ( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ){
2279                                  ?>
2280          <script type="text/javascript" language="JavaScript">
2281          <!--
2282  			function SwitchDateFields() {
2283                  // All fields need to be enabled to go back to the script
2284                  document.filters_open.start_month.disabled = ! document.filters_open.do_filter_by_date.checked;
2285                  document.filters_open.start_day.disabled = ! document.filters_open.do_filter_by_date.checked;
2286                  document.filters_open.start_year.disabled = ! document.filters_open.do_filter_by_date.checked;
2287                  document.filters_open.end_month.disabled = ! document.filters_open.do_filter_by_date.checked;
2288                  document.filters_open.end_day.disabled = ! document.filters_open.do_filter_by_date.checked;
2289                  document.filters_open.end_year.disabled = ! document.filters_open.do_filter_by_date.checked;
2290  
2291                     return true;
2292              }
2293          // -->
2294          </script>
2295                              <?php
2296                              } # end if dhtml_filters
2297                              if ( 'on' == $t_filter['do_filter_by_date'] ) {
2298                                  ?>
2299                                  <input type="hidden" name="do_filter_by_date" value="<?php echo $t_filter['do_filter_by_date'];?>" />
2300                                  <input type="hidden" name="start_month" value="<?php echo $t_filter['start_month'];?>" />
2301                                  <input type="hidden" name="start_day" value="<?php echo $t_filter['start_day'];?>" />
2302                                  <input type="hidden" name="start_year" value="<?php echo $t_filter['start_year'];?>" />
2303                                  <input type="hidden" name="end_month" value="<?php echo $t_filter['end_month'];?>" />
2304                                  <input type="hidden" name="end_day" value="<?php echo $t_filter['end_day'];?>" />
2305                                  <input type="hidden" name="end_year" value="<?php echo $t_filter['end_year'];?>" />
2306                                  <?php
2307                                  $t_chars = preg_split( '//', config_get( 'short_date_format' ), -1, PREG_SPLIT_NO_EMPTY );
2308                                  $t_time = mktime( 0, 0, 0, $t_filter['start_month'], $t_filter['start_day'], $t_filter['start_year'] );
2309                                  foreach( $t_chars as $t_char ) {
2310                                      if ( strcasecmp( $t_char, "M" ) == 0 ) {
2311                                          PRINT ' ';
2312                                          PRINT date( 'F', $t_time );
2313                                      }
2314                                      if ( strcasecmp( $t_char, "D" ) == 0 ) {
2315                                          PRINT ' ';
2316                                          PRINT date( 'd', $t_time );
2317                                      }
2318                                      if ( strcasecmp( $t_char, "Y" ) == 0 ) {
2319                                          PRINT ' ';
2320                                          PRINT date( 'Y', $t_time );
2321                                      }
2322                                  }
2323  
2324                                  PRINT ' - ';
2325  
2326                                  $t_time = mktime( 0, 0, 0, $t_filter['end_month'], $t_filter['end_day'], $t_filter['end_year'] );
2327                                  foreach( $t_chars as $t_char ) {
2328                                      if ( strcasecmp( $t_char, "M" ) == 0 ) {
2329                                          PRINT ' ';
2330                                          PRINT date( 'F', $t_time );
2331                                      }
2332                                      if ( strcasecmp( $t_char, "D" ) == 0 ) {
2333                                          PRINT ' ';
2334                                          PRINT date( 'd', $t_time );
2335                                      }
2336                                      if ( strcasecmp( $t_char, "Y" ) == 0 ) {
2337                                          PRINT ' ';
2338                                          PRINT date( 'Y', $t_time );
2339                                      }
2340                                  }
2341                              } else {
2342                                  PRINT lang_get( 'no' );
2343                              }
2344                              ?>
2345              </td>
2346  
2347              <td class="small-caption" valign="top" colspan="2" id="relationship_type_filter_target">
2348                              <input type="hidden" name="relationship_type" value="<?php echo $t_filter['relationship_type'];?>" />
2349                              <input type="hidden" name="relationship_bug" value="<?php echo $t_filter['relationship_bug'];?>" />
2350                              <?php
2351                                  $c_rel_type = $t_filter['relationship_type'];
2352                                  $c_rel_bug = $t_filter['relationship_bug'];
2353                                  if ( -1 == $c_rel_type || 0 == $c_rel_bug ) {
2354                                      PRINT lang_get( 'any' );
2355                                  } else {
2356                                      PRINT relationship_get_description_for_history ($c_rel_type) . ' ' . $c_rel_bug;
2357                                  }
2358  
2359                              ?>
2360              </td>
2361              <?php if ( $t_filter_cols > 8 ) {
2362                  echo '<td class="small-caption" valign="top" colspan="' . ( $t_filter_cols - 8 ) . '">&nbsp;</td>';
2363              } ?>
2364          </tr>
2365          <tr <?php PRINT "class=\"" . $t_trclass . "\""; ?>>
2366              <td class="small-caption" valign="top">
2367                  <a href="<?php echo $t_filters_url . 'platform'; ?>" id="platform_filter"><?php echo lang_get( 'platform' ) ?>:</a>
2368              </td>
2369              <td class="small-caption" valign="top">
2370                  <a href="<?php PRINT $t_filters_url . 'os'; ?>" id="os_filter"><?php echo lang_get( 'os' ) ?>:</a>
2371              </td>
2372              <td class="small-caption" valign="top">
2373                  <a href="<?php PRINT $t_filters_url . 'os_build'; ?>" id="os_build_filter"><?php echo lang_get( 'os_version' ) ?>:</a>
2374              </td>
2375              <td class="small-caption" valign="top" colspan="5">
2376                  <a href="<?php PRINT $t_filters_url . 'tag_string'; ?>" id="tag_string_filter"><?php echo lang_get( 'tags' ) ?>:</a>
2377              </td>
2378              <?php if ( $t_filter_cols > 8 ) {
2379                  echo '<td class="small-caption" valign="top" colspan="' . ( $t_filter_cols - 8 ) . '">&nbsp;</td>';
2380              } ?>
2381          </tr>
2382          <tr class="row-1">
2383              <td class="small-caption" valign="top" id="platform_filter_target">
2384                  <?php
2385                      print_multivalue_field( FILTER_PROPERTY_PLATFORM, $t_filter[FILTER_PROPERTY_PLATFORM] );
2386                  ?>
2387              </td>
2388              <td class="small-caption" valign="top" id="os_filter_target">
2389                  <?php
2390                      print_multivalue_field( FILTER_PROPERTY_OS, $t_filter[FILTER_PROPERTY_OS] );
2391                  ?>
2392              </td>
2393              <td class="small-caption" valign="top" id="os_build_filter_target">
2394                  <?php
2395                      print_multivalue_field( FILTER_PROPERTY_OS_BUILD, $t_filter[FILTER_PROPERTY_OS_BUILD] );
2396                  ?>
2397              </td>
2398              <td class="small-caption" valign="top" id="tag_string_filter_target" colspan="5">
2399                  <?php 
2400                      $t_tag_string = $t_filter['tag_string'];
2401                      if ( $t_filter['tag_select'] != 0 ) {
2402                          $t_tag_string .= ( is_blank( $t_tag_string ) ? '' : config_get( 'tag_separator' ) );
2403                          $t_tag_string .= tag_get_field( $t_filter['tag_select'], 'name' );
2404                      }
2405                      PRINT $t_tag_string 
2406                  ?>
2407                  <input type="hidden" name="tag_string" value="<?php echo $t_tag_string ?>"/>
2408              </td>
2409          </tr>
2410          <?php
2411  
2412          if ( ON == config_get( 'filter_by_custom_fields' ) ) {
2413  
2414              # -- Custom Field Searching --
2415  
2416              if ( count( $t_accessible_custom_fields_ids ) > 0 ) {
2417                  $t_per_row = config_get( 'filter_custom_fields_per_row' );
2418                  $t_num_fields = count( $t_accessible_custom_fields_ids ) ;
2419                  $t_row_idx = 0;
2420                  $t_col_idx = 0;
2421  
2422                  $t_fields = "";
2423                  $t_values = "";
2424  
2425                  for ( $i = 0; $i < $t_num_fields; $i++ ) {
2426                      if ( $t_col_idx == 0 ) {
2427                          $t_fields = '<tr class="' . $t_trclass . '">';
2428                          $t_values = '<tr class="row-1">';
2429                      }
2430  
2431                      if ( isset( $t_accessible_custom_fields_names[ $i ] ) ) {
2432                          $t_fields .= '<td class="small-caption" valign="top"> ';
2433                          $t_fields .= '<a href="' . $t_filters_url . 'custom_field_' . $t_accessible_custom_fields_ids[$i] . '[]" id="custom_field_'. $t_accessible_custom_fields_ids[$i] .'_filter">';
2434                          $t_fields .= string_display( lang_get_defaulted( $t_accessible_custom_fields_names[$i] ) );
2435                          $t_fields .= '</a> </td> ';
2436                      }
2437                      $t_output = '';
2438                      $t_any_found = false;
2439  
2440                      $t_values .= '<td class="small-caption" valign="top" id="custom_field_' . $t_accessible_custom_fields_ids[$i] . '_filter_target"> ' ;
2441                      if ( !isset( $t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]] ) ) {
2442                          $t_values .= lang_get( 'any' );
2443                      } else {
2444                          if ( $t_accessible_custom_fields_types[$i] == CUSTOM_FIELD_TYPE_DATE ) {
2445                              # @@@ moved embedded javascript here from print_filter_custom_field_date
2446                              #  it appears not to load properly on Firefox and other browsers if loaded through the httpxmlreq
2447                              $t_field_id = $t_accessible_custom_fields_ids[$i];
2448                              $t_js_toggle_func = "toggle_custom_date_field_" . $t_field_id . "_controls" ;
2449                              if ( ( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ) {
2450                                  ?>
2451      <script type="text/javascript" language="JavaScript">
2452      <!--
2453      function <?php echo $t_js_toggle_func . "_start" ; ?>(disable) {
2454              document.filters_open.custom_field_<?php echo $t_field_id ; ?>_start_year.disabled = disable ;
2455              document.filters_open.custom_field_<?php echo $t_field_id ; ?>_start_month.disabled = disable ;
2456              document.filters_open.custom_field_<?php echo $t_field_id ; ?>_start_day.disabled = disable ;
2457      } ;
2458  
2459      function <?php echo $t_js_toggle_func . "_end" ; ?>(disable) {
2460              document.filters_open.custom_field_<?php echo $t_field_id ; ?>_end_year.disabled = disable ;
2461              document.filters_open.custom_field_<?php echo $t_field_id ; ?>_end_month.disabled = disable ;
2462              document.filters_open.custom_field_<?php echo $t_field_id ; ?>_end_day.disabled = disable ;
2463      } ;
2464  
2465      function <?php echo $t_js_toggle_func ; ?>() {
2466          switch (document.filters_open.custom_field_<?php echo $t_field_id ; ?>_control.selectedIndex) {
2467          case <?php echo CUSTOM_FIELD_DATE_ANY ; ?>:
2468          case <?php echo CUSTOM_FIELD_DATE_NONE ; ?>:
2469              <?php echo $t_js_toggle_func . "_start" ; ?>(true) ;
2470              <?php echo $t_js_toggle_func . "_end" ; ?>(true) ;
2471              break ;
2472          case <?php echo CUSTOM_FIELD_DATE_BETWEEN ; ?>:
2473              <?php echo $t_js_toggle_func . "_start" ; ?>(false) ;
2474              <?php echo $t_js_toggle_func . "_end" ; ?>(false) ;
2475              break ;
2476          default:
2477              <?php echo $t_js_toggle_func . "_start" ; ?>(false) ;
2478              <?php echo $t_js_toggle_func . "_end" ; ?>(true) ;
2479              break ;
2480          }
2481      }
2482      // -->
2483      </script>
2484  <?php
2485                              } # end if dhtml_filters
2486                              $t_short_date_format = config_get( 'short_date_format' );
2487                              if ( !isset( $t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]][1] ) ) {
2488                                  $t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]][1] = 0;
2489                              }
2490                              $t_start = date( $t_short_date_format, $t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]][1] );
2491  
2492                              if ( !isset( $t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]][2] ) ) {
2493                                  $t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]][2] = 0;
2494                              }
2495                              $t_end = date( $t_short_date_format, $t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]][2] );
2496                              switch ($t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]][0]) {
2497                              case CUSTOM_FIELD_DATE_ANY:
2498                                  $t_values .= lang_get( 'any' ) ;
2499                                  break;
2500                              case CUSTOM_FIELD_DATE_NONE:
2501                                  $t_values .= lang_get( 'none' ) ;
2502                                  break;
2503                              case CUSTOM_FIELD_DATE_BETWEEN:
2504                                  $t_values .= lang_get( 'between' ) . '<br />';
2505                                  $t_values .= $t_start . '<br />' . $t_end;
2506                                  break;
2507                              case CUSTOM_FIELD_DATE_ONORBEFORE:
2508                                  $t_values .= lang_get( 'on_or_before' ) . '<br />';
2509                                  $t_values .= $t_end;
2510                                  break;
2511                              case CUSTOM_FIELD_DATE_BEFORE:
2512                                  $t_values .= lang_get( 'before' ) . '<br />';
2513                                  $t_values .= $t_end;
2514                                  break;
2515                              case CUSTOM_FIELD_DATE_ON:
2516                                  $t_values .= lang_get( 'on' ) . '<br />';
2517                                  $t_values .= $t_start;
2518                                  break;
2519                              case CUSTOM_FIELD_DATE_AFTER:
2520                                  $t_values .= lang_get( 'after' ) . '<br />';
2521                                  $t_values .= $t_start;
2522                                  break ;
2523                              case CUSTOM_FIELD_DATE_ONORAFTER:
2524                                  $t_values .= lang_get( 'on_or_after' ) . '<br />';
2525                                  $t_values .= $t_start;
2526                                  break ;
2527                              }
2528                          } else {
2529                              $t_first_flag = true;
2530                              foreach( $t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]] as $t_current ) {
2531                                  $t_current = stripslashes( $t_current );
2532                                  $t_this_string = '';
2533                                  if ( ( ( $t_current == META_FILTER_ANY ) && ( is_numeric( $t_current ) ) ) 
2534                                          || ( is_blank( $t_current ) ) ) {
2535                                      $t_any_found = true;
2536                                  } else if ( ( META_FILTER_NONE == $t_current ) && ( is_numeric( $t_current ) ) ) {
2537                                      $t_this_string = lang_get( 'none' );
2538                                  } else {
2539                                      $t_this_string = string_display( $t_current );
2540                                  }
2541  
2542                                  if ( $t_first_flag != true ) {
2543                                      $t_output = $t_output . '<br />';
2544                                  } else {
2545                                      $t_first_flag = false;
2546                                  }
2547  
2548                                  $t_output = $t_output . $t_this_string;
2549                                  $t_values .= '<input type="hidden" name="custom_field_'.$t_accessible_custom_fields_ids[$i].'[]" value="'.string_display( $t_current ).'" />';
2550                              }
2551                          }
2552  
2553                          if ( true == $t_any_found ) {
2554                              $t_values .= lang_get( 'any' );
2555                          } else {
2556                              $t_values .= $t_output;
2557                          }
2558                      }
2559                      $t_values .= ' </td>';
2560  
2561                      $t_col_idx++;
2562  
2563                      if ( $t_col_idx == $t_per_row ) {
2564                          if ( $t_filter_cols > $t_per_row ) {
2565                              $t_fields .= '<td colspan="' . ($t_filter_cols - $t_per_row ) . '">&nbsp;</td> ';
2566                              $t_values .= '<td colspan="' . ($t_filter_cols - $t_per_row) . '">&nbsp;</td> ';
2567                          }
2568  
2569                          $t_fields .= '</tr>' . "\n";
2570                          $t_values .= '</tr>' . "\n";
2571  
2572                          echo $t_fields;
2573                          echo $t_values;
2574  
2575                          $t_col_idx = 0;
2576                          $t_row_idx++;
2577                      }
2578                  }
2579  
2580  
2581                  if ( $t_col_idx > 0 ) {
2582                      if ( $t_col_idx < $t_per_row ) {
2583                          $t_fields .= '<td colspan="' . ($t_per_row - $t_col_idx) . '">&nbsp;</td> ';
2584                          $t_values .= '<td colspan="' . ($t_per_row - $t_col_idx) . '">&nbsp;</td> ';
2585                      }
2586  
2587                      if ( $t_filter_cols > $t_per_row ) {
2588                          $t_fields .= '<td colspan="' . ($t_filter_cols - $t_per_row ) . '">&nbsp;</td> ';
2589                          $t_values .= '<td colspan="' . ($t_filter_cols - $t_per_row) . '">&nbsp;</td> ';
2590                      }
2591  
2592                      $t_fields .= '</tr>' . "\n";
2593                      $t_values .= '</tr>' . "\n";
2594  
2595                      echo $t_fields;
2596                      echo $t_values;
2597                  }
2598              }
2599          }
2600          ?>
2601          <tr class="row-1">
2602              <td class="small-caption" valign="top">
2603                  <a href="<?php PRINT $t_filters_url . 'show_sort'; ?>" id="show_sort_filter"><?php PRINT lang_get( 'sort' ) ?>:</a>
2604              </td>
2605              <td class="small-caption" valign="top" colspan="2" id="show_sort_filter_target">
2606                  <?php
2607                      $t_sort_fields = split( ',', $t_filter['sort'] );
2608                      $t_dir_fields = split( ',', $t_filter['dir'] );
2609  
2610                      for ( $i=0; $i<2; $i++ ) {
2611                          if ( isset( $t_sort_fields[$i] ) ) {
2612                              if ( 0 < $i ) {
2613                                  echo ", ";
2614                              }
2615                              $t_sort = $t_sort_fields[$i];
2616                              if ( strpos( $t_sort, 'custom_' ) === 0 ) {
2617                                  $t_field_name = string_display( lang_get_defaulted( substr( $t_sort, strlen( 'custom_' ) ) ) );
2618                              } else {
2619                                  $t_field_name = string_get_field_name( $t_sort );
2620                              }
2621  
2622                              echo $t_field_name . " " . lang_get( 'bugnote_order_' . strtolower( $t_dir_fields[$i] ) );
2623                              echo "<input type=\"hidden\" name=\"sort_$i\" value=\"$t_sort_fields[$i]\" />";
2624                              echo "<input type=\"hidden\" name=\"dir_$i\" value=\"$t_dir_fields[$i]\" />";
2625                          }
2626                      }
2627                  ?>
2628              </td>
2629              <?php
2630                  if ( 'advanced' == $t_view_type ) {
2631                  ?>
2632                      <td class="small-caption" valign="top" colspan="2">
2633                          <a href="<?php PRINT $t_filters_url . 'project_id'; ?>" id="project_id_filter"><?php PRINT lang_get( 'email_project' ) ?>:</a>
2634                      </td>
2635                      <td class="small-caption" valign="top"  id="project_id_filter_target">
2636                          <?php
2637                              $t_output = '';
2638                              if ( !is_array( $t_filter['project_id'] ) ) {
2639                                  $t_filter['project_id'] = Array( $t_filter['project_id'] );
2640                              }
2641                              if ( count( $t_filter['project_id'] ) == 0 ) {
2642                                  PRINT lang_get( 'current' );
2643                              } else {
2644                                  $t_first_flag = true;
2645                                  foreach( $t_filter['project_id'] as $t_current ) {
2646                                      ?>
2647                                      <input type="hidden" name="project_id[]" value="<?php echo $t_current;?>" />
2648                                      <?php
2649                                      $t_this_name = '';
2650                                      if ( META_FILTER_CURRENT == $t_current ) {
2651                                          $t_this_name = lang_get( 'current' );
2652                                      } else {
2653                                          $t_this_name = project_get_name( $t_current );
2654                                      }
2655                                      if ( $t_first_flag != true ) {
2656                                          $t_output = $t_output . '<br />';
2657                                      } else {
2658                                          $t_first_flag = false;
2659                                      }
2660                                      $t_output = $t_output . $t_this_name;
2661                                  }
2662                                  PRINT $t_output;
2663                              }
2664                          ?>
2665                      </td>
2666                      <?php 
2667                      if ( $t_filter_cols > 6 ) {
2668                          echo '<td class="small-caption" valign="top" colspan="' . ( $t_filter_cols - 5 ) . '">&nbsp;</td>';
2669                      }
2670                  } else {
2671                      if ( $t_filter_cols > 3 ) {
2672                          echo '<td class="small-caption" valign="top" colspan="' . ( $t_filter_cols - 2 ) . '">&nbsp;</td>';
2673                      }
2674                  } 
2675              ?>
2676          </tr>
2677          <?php
2678          } // expanded
2679          ?>
2680          <tr>
2681              <td colspan="2">
2682                  <?php
2683                      collapse_icon( 'filter' );
2684                      echo lang_get( 'search' );
2685                  ?>:
2686                  <input type="text" size="16" name="search" value="<?php PRINT string_html_specialchars( $t_filter['search'] ); ?>" />
2687  
2688                  <input type="submit" name="filter" class="button-small" value="<?php PRINT lang_get( 'filter_button' ) ?>" />
2689              </td>
2690              </form>
2691              <td class="center" colspan="<?php echo ( $t_filter_cols - 6 ) ?>"> <!-- use this label for padding -->
2692                  <?php
2693                      if ( ON == config_get( 'dhtml_filters' ) ) {
2694                          $f_switch_view_link = 'view_all_set.php?type=6&amp;view_type=';
2695                      } else {
2696                          $f_switch_view_link = 'view_filters_page.php?view_type=';
2697                      }
2698  
2699                      if ( ( SIMPLE_ONLY != config_get( 'view_filters' ) ) && ( ADVANCED_ONLY != config_get( 'view_filters' ) ) ) {
2700                          if ( 'advanced' == $t_view_type ) {
2701                              print_bracket_link( $f_switch_view_link . 'simple', lang_get( 'simple_filters' ) );
2702                          } else {
2703                              print_bracket_link( $f_switch_view_link . 'advanced', lang_get( 'advanced_filters' ) );
2704                          }
2705  
2706                          print_bracket_link( 
2707                              'permalink_page.php?url=' . urlencode( filter_get_url( $t_filter ) ), 
2708                              lang_get( 'create_filter_link' ), 
2709                              /* new window = */ true );
2710                      }
2711                  ?>
2712              </td>
2713              <td class="right" colspan="4">
2714              <?php
2715              $t_stored_queries_arr = array();
2716              $t_stored_queries_arr = filter_db_get_available_queries();
2717  
2718              if ( count( $t_stored_queries_arr ) > 0 ) {
2719                  ?>
2720                      <form method="get" name="list_queries<?php echo $t_form_name_suffix; ?>" action="view_all_set.php">
2721                      <input type="hidden" name="type" value="3" />
2722                      <?php
2723                      if ( ON == config_get( 'use_javascript' ) ) {
2724                          echo "<select name=\"source_query_id\" onchange=\"document.forms.list_queries$t_form_name_suffix.submit();\">";
2725                      } else {
2726                          PRINT '<select name="source_query_id">';
2727                      }
2728                      ?>
2729                      <option value="-1"><?php PRINT '[' . lang_get( 'reset_query' ) . ']' ?></option>
2730                      <option value="-1"></option>
2731                      <?php
2732                      foreach( $t_stored_queries_arr as $t_query_id => $t_query_name ) {
2733                          PRINT '<option value="' . $t_query_id . '">' . $t_query_name . '</option>';
2734                      }
2735                      ?>
2736                      </select>
2737                      <input type="submit" name="switch_to_query_button" class="button-small" value="<?php PRINT lang_get( 'use_query' ) ?>" />
2738                      </form>
2739                      <form method="post" name="open_queries" action="query_view_page.php">
2740                      <input type="submit" name="switch_to_query_button" class="button-small" value="<?php PRINT lang_get( 'open_queries' ) ?>" />
2741                      </form>
2742                  <?php
2743              } else {
2744                  ?>
2745                      <form method="get" name="reset_query" action="view_all_set.php">
2746                      <input type="hidden" name="type" value="3" />
2747                      <input type="hidden" name="source_query_id" value="-1" />
2748                      <input type="submit" name="reset_query_button" class="button-small" value="<?php PRINT lang_get( 'reset_query' ) ?>" />
2749                      </form>
2750                  <?php
2751              }
2752  
2753              if ( access_has_project_level( config_get( 'stored_query_create_threshold' ) ) ) {
2754              ?>
2755                      <form method="post" name="save_query" action="query_store_page.php">
2756                      <input type="submit" name="save_query_button" class="button-small" value="<?php PRINT lang_get( 'save_query' ) ?>" />
2757                      </form>
2758              <?php
2759              } else {
2760              ?>
2761              <?php
2762              }
2763              ?>
2764              </td>
2765          </tr>
2766          </table>
2767  <?php
2768      }
2769  
2770      # Add a filter to the database for the current user
2771  	function filter_db_set_for_current_user( $p_project_id, $p_is_public,
2772                                          $p_name, $p_filter_string ) {
2773          $t_user_id = auth_get_current_user_id();
2774          $c_project_id = db_prepare_int( $p_project_id );
2775          $c_is_public = db_prepare_bool( $p_is_public, false );
2776          $c_name = db_prepare_string( $p_name );
2777          $c_filter_string = db_prepare_string( $p_filter_string );
2778  
2779          $t_filters_table = config_get( 'mantis_filters_table' );
2780  
2781          # check that the user can save non current filters (if required)
2782          if ( ( ALL_PROJECTS <= $c_project_id ) && ( !is_blank( $p_name ) ) &&
2783               ( !access_has_project_level( config_get( 'stored_query_create_threshold' ) ) ) ) {
2784              return -1;
2785          }
2786  
2787          # ensure that we're not making this filter public if we're not allowed
2788          if ( !access_has_project_level( config_get( 'stored_query_create_shared_threshold' ) ) ) {
2789              $c_is_public = db_prepare_bool( false );
2790          }
2791  
2792          # Do I need to update or insert this value?
2793          $query = "SELECT id FROM $t_filters_table
2794                      WHERE user_id='$t_user_id'
2795                      AND project_id='$c_project_id'
2796                      AND name='$c_name'";
2797          $result = db_query( $query );
2798  
2799          if ( db_num_rows( $result ) > 0 ) {
2800              $row = db_fetch_array( $result );
2801  
2802              $query = "UPDATE $t_filters_table
2803                        SET is_public='$c_is_public',
2804                            filter_string='$c_filter_string'
2805                        WHERE id='" . $row['id'] . "'";
2806              db_query( $query );
2807  
2808              return $row['id'];
2809          } else {
2810              $query = "INSERT INTO $t_filters_table
2811                          ( user_id, project_id, is_public, name, filter_string )
2812                        VALUES
2813                          ( '$t_user_id', '$c_project_id', '$c_is_public', '$c_name', '$c_filter_string' )";
2814              db_query( $query );
2815  
2816              # Recall the query, we want the filter ID
2817              $query = "SELECT id
2818                          FROM $t_filters_table
2819                          WHERE user_id='$t_user_id'
2820                          AND project_id='$c_project_id'
2821                          AND name='$c_name'";
2822              $result = db_query( $query );
2823  
2824              if ( db_num_rows( $result ) > 0 ) {
2825                  $row = db_fetch_array( $result );
2826                  return $row['id'];
2827              }
2828  
2829              return -1;
2830          }
2831      }
2832  
2833      # We cache filter requests to reduce the number of SQL queries
2834      $g_cache_filter_db_filters = array();
2835  
2836      # This function will return the filter string that is
2837      # tied to the unique id parameter. If the user doesn't
2838      # have permission to see this filter, the function will
2839      # return null
2840  	function filter_db_get_filter( $p_filter_id, $p_user_id = null ) {
2841          global $g_cache_filter_db_filters;
2842          $t_filters_table = config_get( 'mantis_filters_table' );
2843          $c_filter_id = db_prepare_int( $p_filter_id );
2844  
2845          if ( isset( $g_cache_filter_db_filters[$p_filter_id] ) ) {
2846              return $g_cache_filter_db_filters[$p_filter_id];
2847          }
2848  
2849          if ( null === $p_user_id ) {
2850              $t_user_id = auth_get_current_user_id();
2851          } else {
2852              $t_user_id = $p_user_id;
2853          }
2854  
2855          $query = "SELECT *
2856                    FROM $t_filters_table
2857                    WHERE id='$c_filter_id'";
2858          $result = db_query( $query );
2859  
2860          if ( db_num_rows( $result ) > 0 ) {
2861              $row = db_fetch_array( $result );
2862  
2863              if ( $row['user_id'] != $t_user_id ) {
2864                  if ( $row['is_public'] != true ) {
2865                      return null;
2866                  }
2867              }
2868  
2869              # check that the user has access to non current filters
2870              if ( ( ALL_PROJECTS <= $row['project_id'] ) && ( !is_blank( $row['name'] ) ) && ( !access_has_project_level( config_get( 'stored_query_use_threshold', $row['project_id'], $t_user_id ) ) ) ) {
2871                  return null;
2872              }
2873  
2874              $g_cache_filter_db_filters[$p_filter_id] = $row['filter_string'];
2875              return $row['filter_string'];
2876          }
2877  
2878          return null;
2879      }
2880  
2881  	function filter_db_get_project_current( $p_project_id, $p_user_id = null ) {
2882          $t_filters_table = config_get( 'mantis_filters_table' );
2883          $c_project_id     = db_prepare_int( $p_project_id );
2884          $c_project_id     = $c_project_id * -1;
2885  
2886          if ( null === $p_user_id ) {
2887              $c_user_id         = auth_get_current_user_id();
2888          } else {
2889              $c_user_id        = db_prepare_int( $p_user_id );
2890          }
2891  
2892          # we store current filters for each project with a special project index
2893          $query = "SELECT *
2894                    FROM $t_filters_table
2895                    WHERE user_id='$c_user_id'
2896                        AND project_id='$c_project_id'
2897                        AND name=''";
2898          $result = db_query( $query );
2899  
2900          if ( db_num_rows( $result ) > 0 ) {
2901              $row = db_fetch_array( $result );
2902              return $row['id'];
2903          }
2904  
2905          return null;
2906      }
2907  
2908  	function filter_db_get_name( $p_filter_id ) {
2909          $t_filters_table = config_get( 'mantis_filters_table' );
2910          $c_filter_id = db_prepare_int( $p_filter_id );
2911  
2912          $query = "SELECT *
2913                    FROM $t_filters_table
2914                    WHERE id='$c_filter_id'";
2915          $result = db_query( $query );
2916  
2917          if ( db_num_rows( $result ) > 0 ) {
2918              $row = db_fetch_array( $result );
2919  
2920              if ( $row['user_id'] != auth_get_current_user_id() ) {
2921                  if ( $row['is_public'] != true ) {
2922                      return null;
2923                  }
2924              }
2925  
2926              return $row['name'];
2927          }
2928  
2929          return null;
2930      }
2931  
2932      # Will return true if the user can delete this query
2933  	function filter_db_can_delete_filter( $p_filter_id ) {
2934          $t_filters_table = config_get( 'mantis_filters_table' );
2935          $c_filter_id = db_prepare_int( $p_filter_id );
2936          $t_user_id = auth_get_current_user_id();
2937  
2938          # Administrators can delete any filter
2939          if ( access_has_global_level( ADMINISTRATOR ) ) {
2940              return true;
2941          }
2942  
2943          $query = "SELECT id
2944                    FROM $t_filters_table
2945                    WHERE id='$c_filter_id'
2946                    AND user_id='$t_user_id'
2947                    AND project_id!='-1'";
2948  
2949          $result = db_query( $query );
2950  
2951          if ( db_num_rows( $result ) > 0 ) {
2952              return true;
2953          }
2954  
2955          return false;
2956      }
2957  
2958  	function filter_db_delete_filter( $p_filter_id ) {
2959          $t_filters_table = config_get( 'mantis_filters_table' );
2960          $c_filter_id = db_prepare_int( $p_filter_id );
2961          $t_user_id = auth_get_current_user_id();
2962  
2963          if ( !filter_db_can_delete_filter( $c_filter_id ) ) {
2964              return false;
2965          }
2966  
2967          $query = "DELETE FROM $t_filters_table
2968                    WHERE id='$c_filter_id'";
2969          $result = db_query( $query );
2970  
2971          if ( db_affected_rows( $result ) > 0 ) {
2972              return true;
2973          }
2974  
2975          return false;
2976      }
2977  
2978  	function filter_db_delete_current_filters( ) {
2979          $t_filters_table = config_get( 'mantis_filters_table' );
2980          $t_all_id = ALL_PROJECTS;
2981  
2982          $query = "DELETE FROM $t_filters_table
2983                      WHERE project_id<='$t_all_id'
2984                      AND name=''";
2985          $result = db_query( $query );
2986      }
2987  
2988  	function filter_db_get_available_queries( $p_project_id = null, $p_user_id = null ) {
2989          $t_filters_table = config_get( 'mantis_filters_table' );
2990          $t_overall_query_arr = array();
2991  
2992          if ( null === $p_project_id ) {
2993              $t_project_id = helper_get_current_project();
2994          } else {
2995              $t_project_id = db_prepare_int( $p_project_id );
2996          }
2997  
2998          if ( null === $p_user_id ) {
2999              $t_user_id = auth_get_current_user_id();
3000          } else {
3001              $t_user_id = db_prepare_int( $p_user_id );
3002          }
3003  
3004          # If the user doesn't have access rights to stored queries, just return
3005          if ( !access_has_project_level( config_get( 'stored_query_use_threshold' ) ) ) {
3006              return $t_overall_query_arr;
3007          }
3008  
3009          # Get the list of available queries. By sorting such that public queries are
3010          # first, we can override any query that has the same name as a private query
3011          # with that private one
3012          $query = "SELECT * FROM $t_filters_table
3013                      WHERE (project_id='$t_project_id'
3014                      OR project_id='0')
3015                      AND name!=''
3016                      ORDER BY is_public DESC, name ASC";
3017          $result = db_query( $query );
3018          $query_count = db_num_rows( $result );
3019  
3020          for ( $i = 0; $i < $query_count; $i++ ) {
3021              $row = db_fetch_array( $result );
3022              if ( ( $row['user_id'] == $t_user_id ) || db_prepare_bool( $row['is_public'] ) ) {
3023                  $t_overall_query_arr[$row['id']] = $row['name'];
3024              }
3025          }
3026  
3027          $t_overall_query_arr = array_unique( $t_overall_query_arr );
3028          asort( $t_overall_query_arr );
3029  
3030          return $t_overall_query_arr;
3031      }
3032  
3033      # Make sure that our filters are entirely correct and complete (it is possible that they are not).
3034      # We need to do this to cover cases where we don't have complete control over the filters given.
3035  	function filter_ensure_valid_filter( $p_filter_arr ) {
3036          # extend current filter to add information passed via POST
3037          if ( !isset( $p_filter_arr['_version'] ) ) {
3038              $p_filter_arr['_version'] = config_get( 'cookie_version' );
3039          }
3040          $t_cookie_vers = (int) substr( $p_filter_arr['_version'], 1 );
3041          if ( substr( config_get( 'cookie_version' ), 1 ) > $t_cookie_vers ) { # if the version is old, update it
3042              $p_filter_arr['_version'] = config_get( 'cookie_version' );
3043          }
3044          if ( !isset( $p_filter_arr['_view_type'] ) ) {
3045              $p_filter_arr['_view_type'] = gpc_get_string( 'view_type', 'simple' );
3046          }
3047          if ( !isset( $p_filter_arr['per_page'] ) ) {
3048              $p_filter_arr['per_page'] = gpc_get_int( 'per_page', config_get( 'default_limit_view' ) );
3049          }
3050          if ( !isset( $p_filter_arr['highlight_changed'] ) ) {
3051              $p_filter_arr['highlight_changed'] = config_get( 'default_show_changed' );
3052          }
3053          if ( !isset( $p_filter_arr['sticky_issues'] ) ) {
3054              $p_filter_arr['sticky_issues'] = config_get( 'show_sticky_issues' );
3055          }
3056          if ( !isset( $p_filter_arr['sort'] ) ) {
3057              $p_filter_arr['sort'] = "last_updated";
3058          }
3059          if ( !isset( $p_filter_arr['dir'] ) ) {
3060              $p_filter_arr['dir'] = "DESC";
3061          }
3062          
3063          if ( !isset( $p_filter_arr['platform'] ) ) {
3064              $p_filter_arr['platform'] = array( 0 => META_FILTER_ANY );
3065          }
3066  
3067          if ( !isset( $p_filter_arr['os'] ) ) {
3068              $p_filter_arr['os'] = array( 0 => META_FILTER_ANY );
3069          }
3070  
3071          if ( !isset( $p_filter_arr['os_build'] ) ) {
3072              $p_filter_arr['os_build'] = array( 0 => META_FILTER_ANY );
3073          }
3074  
3075          if ( !isset( $p_filter_arr['project_id'] ) ) {
3076              $p_filter_arr['project_id'] = array( 0 => META_FILTER_CURRENT );
3077          }
3078  
3079          if ( !isset( $p_filter_arr['start_month'] ) ) {
3080              $p_filter_arr['start_month'] = gpc_get_string( 'start_month', date( 'm' ) );
3081          }
3082          if ( !isset( $p_filter_arr['start_day'] ) ) {
3083              $p_filter_arr['start_day'] = gpc_get_string( 'start_day', 1 );
3084          }
3085          if ( !isset( $p_filter_arr['start_year'] ) ) {
3086              $p_filter_arr['start_year'] = gpc_get_string( 'start_year', date( 'Y' ) );
3087          }
3088          if ( !isset( $p_filter_arr['end_month'] ) ) {
3089              $p_filter_arr['end_month'] = gpc_get_string( 'end_month', date( 'm' ) );
3090          }
3091          if ( !isset( $p_filter_arr['end_day'] ) ) {
3092              $p_filter_arr['end_day'] = gpc_get_string( 'end_day', date( 'd' ) );
3093          }
3094          if ( !isset( $p_filter_arr['end_year'] ) ) {
3095              $p_filter_arr['end_year'] = gpc_get_string( 'end_year', date( 'Y' ) );
3096          }
3097          if ( !isset( $p_filter_arr['search'] ) ) {
3098              $p_filter_arr['search'] = '';
3099          }
3100          if ( !isset( $p_filter_arr['and_not_assigned'] ) ) {
3101              $p_filter_arr['and_not_assigned'] = gpc_get_bool( 'and_not_assigned', false );
3102          }
3103          if ( !isset( $p_filter_arr['do_filter_by_date'] ) ) {
3104              $p_filter_arr['do_filter_by_date'] = gpc_get_bool( 'do_filter_by_date', false );
3105          }
3106          if ( !isset( $p_filter_arr['view_state'] ) ) {
3107              $p_filter_arr['view_state'] = gpc_get( 'view_state', '' );
3108          } else if ( ( $p_filter_arr['view_state'] == 'any' ) || ( $p_filter_arr['view_state'] == 0 ) ) {
3109              $p_filter_arr['view_state'] = META_FILTER_ANY;
3110          }
3111          if ( !isset( $p_filter_arr['relationship_type'] ) ) {
3112              $p_filter_arr['relationship_type'] = gpc_get_int( 'relationship_type', -1 );
3113          }
3114          if ( !isset( $p_filter_arr['relationship_bug'] ) ) {
3115              $p_filter_arr['relationship_bug'] = gpc_get_int( 'relationship_bug', 0 );
3116          }
3117          if ( !isset( $p_filter_arr['target_version'] ) ) {
3118              $p_filter_arr['target_version'] = META_FILTER_ANY;
3119          }
3120          if ( !isset( $p_filter_arr['tag_string'] ) ) {
3121              $p_filter_arr['tag_string'] = gpc_get_string( 'tag_string', '' );
3122          }
3123          if ( !isset( $p_filter_arr['tag_select'] ) ) {
3124              $p_filter_arr['tag_select'] = gpc_get_string( 'tag_select', '' );
3125          }
3126  
3127          $t_custom_fields         = custom_field_get_ids(); # @@@ (thraxisp) This should really be the linked ids, but we don't know the project
3128          $f_custom_fields_data     = array();
3129          if ( is_array( $t_custom_fields ) && ( sizeof( $t_custom_fields ) > 0 ) ) {
3130              foreach( $t_custom_fields as $t_cfid ) {
3131                  if ( is_array( gpc_get( 'custom_field_' . $t_cfid, null ) ) ) {
3132                      $f_custom_fields_data[$t_cfid] = gpc_get_string_array( 'custom_field_' . $t_cfid, META_FILTER_ANY );
3133                  } else {
3134                      $f_custom_fields_data[$t_cfid] = gpc_get_string( 'custom_field_' . $t_cfid, META_FILTER_ANY );
3135                      $f_custom_fields_data[$t_cfid] = array( $f_custom_fields_data[$t_cfid] );
3136                  }
3137              }
3138          }
3139  
3140          #validate sorting
3141          $t_fields = helper_get_columns_to_view();
3142          $t_n_fields = count( $t_fields );
3143          for ( $i=0; $i < $t_n_fields; $i++ ) {
3144              if ( isset( $t_fields[$i] ) && in_array( $t_fields[$i], array( 'selection', 'edit', 'bugnotes_count', 'attachment' ) ) ) {
3145                  unset( $t_fields[$i] );
3146              }
3147          }
3148          $t_sort_fields = split( ',', $p_filter_arr['sort'] );
3149          $t_dir_fields = split( ',', $p_filter_arr['dir'] );
3150          for ( $i=0; $i<2; $i++ ) {
3151              if ( isset( $t_sort_fields[$i] ) ) {
3152                  $t_drop = false;
3153                  $t_sort = $t_sort_fields[$i];
3154                  if ( strpos( $t_sort, 'custom_' ) === 0 ) {
3155                      if ( false === custom_field_get_id_from_name( substr( $t_sort, strlen( 'custom_' ) ) ) ) {
3156                          $t_drop = true;
3157                      }
3158                  } else {
3159                      if ( ! in_array( $t_sort, $t_fields ) ) {
3160                          $t_drop = true;
3161                      }
3162                  }
3163                  if ( ! in_array( $t_dir_fields[$i], array( "ASC", "DESC" ) ) ) {
3164                      $t_drop = true;
3165                  }
3166                  if ( $t_drop ) {
3167                      unset( $t_sort_fields[$i] );
3168                      unset( $t_dir_fields[$i] );
3169                  }
3170              }
3171          }
3172          if ( count( $t_sort_fields ) > 0 ) {
3173              $p_filter_arr['sort'] = implode( ',', $t_sort_fields );
3174              $p_filter_arr['dir'] = implode( ',', $t_dir_fields );
3175          } else {
3176              $p_filter_arr['sort'] = "last_updated";
3177              $p_filter_arr['dir'] = "DESC";
3178          }
3179  
3180          # validate or filter junk from other fields
3181          $t_multi_select_list = array( 'show_category' => 'string',
3182                                        'show_severity' => 'int',
3183                                        'show_status' => 'int',
3184                                        'reporter_id' => 'int',
3185                                        'handler_id' => 'int',
3186                                        'show_resolution' => 'int',
3187                                        'show_priority' => 'int',
3188                                        'show_build' => 'string',
3189                                        'show_version' => 'string',
3190                                        'hide_status' => 'int',
3191                                        'fixed_in_version' => 'string',
3192                                        'target_version' => 'string',
3193                                        'user_monitor' => 'int',
3194                                        'show_profile' => 'int'
3195                                       );
3196          foreach( $t_multi_select_list as $t_multi_field_name => $t_multi_field_type ) {
3197              if ( !isset( $p_filter_arr[$t_multi_field_name] ) ) {
3198                  if ( 'hide_status' == $t_multi_field_name ) {
3199                      $p_filter_arr[$t_multi_field_name] = array( config_get( 'hide_status_default' ) );
3200                  } else if ( 'custom_fields' == $t_multi_field_name ) {
3201                      $p_filter_arr[$t_multi_field_name] = array( $f_custom_fields_data );
3202                  } else {
3203                      $p_filter_arr[$t_multi_field_name] = array( META_FILTER_ANY );
3204                  }
3205              } else {
3206                  if ( !is_array( $p_filter_arr[$t_multi_field_name] ) ) {
3207                      $p_filter_arr[$t_multi_field_name] = array( $p_filter_arr[$t_multi_field_name] );
3208                  }
3209                  $t_checked_array = array();
3210                  foreach ( $p_filter_arr[$t_multi_field_name] as $t_filter_value ) {
3211                      $t_filter_value = stripslashes( $t_filter_value );
3212                      if ( ( $t_filter_value === 'any' ) || ( $t_filter_value === '[any]' ) ) {
3213                          $t_filter_value = META_FILTER_ANY;
3214                      }
3215                      if ( ( $t_filter_value === 'none' ) || ( $t_filter_value === '[none]' ) ) {
3216                          $t_filter_value = META_FILTER_NONE;
3217                      }
3218                      if ( 'string' == $t_multi_field_type ) {
3219                          $t_checked_array[] = db_prepare_string( $t_filter_value );
3220                      } else if ( 'int' == $t_multi_field_type ) {
3221                          $t_checked_array[] = db_prepare_int( $t_filter_value );
3222                      } else if ( 'array' == $t_multi_field_type ) {
3223                          $t_checked_array[] = $t_filter_value;
3224                      }
3225                  }
3226                  $p_filter_arr[$t_multi_field_name] = $t_checked_array;
3227              }
3228          }
3229  
3230          if ( is_array( $t_custom_fields ) && ( sizeof( $t_custom_fields ) > 0 ) ) {
3231              foreach( $t_custom_fields as $t_cfid ) {
3232                  if ( !isset( $p_filter_arr['custom_fields'][$t_cfid] ) ) {
3233                      $p_filter_arr['custom_fields'][$t_cfid] = array( META_FILTER_ANY );
3234                  } else {
3235                      if ( !is_array( $p_filter_arr['custom_fields'][$t_cfid] ) ) {
3236                          $p_filter_arr['custom_fields'][$t_cfid] = array( $p_filter_arr['custom_fields'][$t_cfid] );
3237                      }
3238                      $t_checked_array = array();
3239                      foreach ( $p_filter_arr['custom_fields'][$t_cfid] as $t_filter_value ) {
3240                          $t_filter_value = stripslashes( $t_filter_value );
3241                          if ( ( $t_filter_value === 'any' ) || ( $t_filter_value === '[any]' ) ) {
3242                              $t_filter_value = META_FILTER_ANY;
3243                          }
3244                          $t_checked_array[] = db_prepare_string( $t_filter_value );
3245                      }
3246                      $p_filter_arr['custom_fields'][$t_cfid] = $t_checked_array;
3247                  }
3248              }
3249          }
3250          # all of our filter values are now guaranteed to be there, and correct.
3251          return $p_filter_arr;
3252      }
3253  
3254  
3255      /**
3256       * The following functions each print out an individual filter field.
3257       * They are derived from view_filters_page.php
3258       *
3259       * The functions follow a strict naming convention:
3260       *
3261       *   print_filter_[filter_name]
3262       *
3263       * Where [filter_name] is the same as the "name" of the form element for
3264       * that filter. This naming convention is depended upon by the controller
3265       * at the end of the script.
3266       */
3267      /**
3268       * I expect that this code could be made simpler by refactoring into a
3269       * class so as to avoid all those calls to global(which are pretty ugly)
3270       *
3271       * These functions could also be shared by view_filters_page.php
3272       *
3273       */
3274  	function print_filter_reporter_id(){
3275          global $t_select_modifier, $t_filter;
3276          ?>
3277          <select <?php PRINT $t_select_modifier;?> name="reporter_id[]">
3278          <?php
3279              # if current user is a reporter, and limited reports set to ON, only display that name
3280          # @@@ thraxisp - access_has_project_level checks greater than or equal to,
3281          #   this assumed that there aren't any holes above REPORTER where the limit would apply
3282          #
3283              if ( ( ON === config_get( 'limit_reporters' ) ) && ( ! access_has_project_level( REPORTER + 1 ) ) ) {
3284                  $t_id = auth_get_current_user_id();
3285                  $t_username = user_get_field( $t_id, 'username' );
3286                  $t_realname = user_get_field( $t_id, 'realname' );
3287                  $t_display_name = string_attribute( $t_username );
3288                  if ( ( isset( $t_realname ) ) && ( $t_realname > "" ) && ( ON == config_get( 'show_realname' ) ) ){
3289                      $t_display_name = string_attribute( $t_realname );
3290                  }
3291                  PRINT '<option value="' . $t_id . '" selected="selected">' . $t_display_name . '</option>';
3292              } else {
3293          ?>
3294              <option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['reporter_id'], META_FILTER_ANY ); ?>>[<?php echo lang_get( 'any' ) ?>]</option>
3295              <?php
3296                  if ( access_has_project_level( config_get( 'report_bug_threshold' ) ) ) {
3297                      PRINT '<option value="' . META_FILTER_MYSELF . '" ';
3298                      check_selected( $t_filter['reporter_id'], META_FILTER_MYSELF );
3299                      PRINT '>[' . lang_get( 'myself' ) . ']</option>';
3300                  }
3301              ?>
3302              <?php print_reporter_option_list( $t_filter['reporter_id'] ) ?>
3303              <?php } ?>
3304          </select>
3305          <?php
3306      }
3307  
3308  
3309  	function print_filter_user_monitor(){
3310          global $t_select_modifier, $t_filter;
3311          ?>
3312      <!-- Monitored by -->
3313          <select <?php PRINT $t_select_modifier;?> name="user_monitor[]">
3314              <option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['user_monitor'], META_FILTER_ANY ); ?>>[<?php echo lang_get( 'any' ) ?>]</option>
3315              <?php
3316                  if ( access_has_project_level( config_get( 'monitor_bug_threshold' ) ) ) {
3317                      PRINT '<option value="' . META_FILTER_MYSELF . '" ';
3318                      check_selected( $t_filter['user_monitor'], META_FILTER_MYSELF );
3319                      PRINT '>[' . lang_get( 'myself' ) . ']</option>';
3320                  }
3321              ?>
3322              <?php print_reporter_option_list( $t_filter['user_monitor'] ) ?>
3323          </select>
3324          <?php
3325      }
3326  
3327  	function print_filter_handler_id(){
3328          global $t_select_modifier, $t_filter, $f_view_type;
3329          ?>
3330          <!-- Handler -->
3331          <select <?php PRINT $t_select_modifier;?> name="handler_id[]">
3332              <option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['handler_id'], META_FILTER_ANY ); ?>>[<?php echo lang_get( 'any' ) ?>]</option>
3333              <?php if ( access_has_project_level( config_get( 'view_handler_threshold' ) ) ) { ?>
3334              <option value="<?php echo META_FILTER_NONE ?>" <?php check_selected( $t_filter['handler_id'], META_FILTER_NONE ); ?>>[<?php echo lang_get( 'none' ) ?>]</option>
3335              <?php
3336                  if ( access_has_project_level( config_get( 'handle_bug_threshold' ) ) ) {
3337                      PRINT '<option value="' . META_FILTER_MYSELF . '" ';
3338                      check_selected( $t_filter['handler_id'], META_FILTER_MYSELF );
3339                      PRINT '>[' . lang_get( 'myself' ) . ']</option>';
3340                  }
3341              ?>
3342              <?php print_assign_to_option_list( $t_filter['handler_id'] ) ?>
3343              <?php } ?>
3344          </select>
3345          <?php
3346      }
3347  
3348  	function print_filter_show_category(){
3349          global $t_select_modifier, $t_filter;
3350          ?>
3351          <!-- Category -->
3352          <select <?php PRINT $t_select_modifier;?> name="show_category[]">
3353              <option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['show_category'], META_FILTER_ANY ); ?>>[<?php echo lang_get( 'any' ) ?>]</option>
3354              <?php # This shows orphaned categories as well as selectable categories ?>
3355              <?php print_category_complete_option_list( $t_filter['show_category'] ) ?>
3356          </select>
3357          <?php
3358      }
3359      
3360  	function print_filter_platform() {
3361          global $t_select_modifier, $t_filter;
3362  
3363          ?>
3364          <!-- Platform -->
3365          <select <?php echo $t_select_modifier;?> name="platform[]">
3366              <option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['platform'], META_FILTER_ANY ); ?>>[<?php echo lang_get( 'any' ) ?>]</option>
3367              <?php 
3368                  log_event( LOG_FILTERING, 'Platform = ' . var_export( $t_filter['platform'], true ) );
3369                  print_platform_option_list( $t_filter['platform'] );
3370              ?>
3371          </select>
3372          <?php
3373      }
3374  
3375  	function print_filter_os() {
3376          global $t_select_modifier, $t_filter;
3377  
3378          ?>
3379          <!-- OS -->
3380          <select <?php echo $t_select_modifier;?> name="os[]">
3381              <option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['os'], META_FILTER_ANY ); ?>>[<?php echo lang_get( 'any' ) ?>]</option>
3382              <?php print_os_option_list( $t_filter['os'] ) ?>
3383          </select>
3384          <?php
3385      }
3386  
3387  	function print_filter_os_build() {
3388          global $t_select_modifier, $t_filter;
3389  
3390          ?>
3391          <!-- OS Build -->
3392          <select <?php echo $t_select_modifier;?> name="os_build[]">
3393              <option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['os_build'], META_FILTER_ANY ); ?>>[<?php echo lang_get( 'any' ) ?>]</option>
3394              <?php print_os_build_option_list( $t_filter['os_build'] ) ?>
3395          </select>
3396          <?php
3397      }
3398  
3399  	function print_filter_show_severity(){
3400          global $t_select_modifier, $t_filter;
3401          ?><!-- Severity -->
3402              <select <?php PRINT $t_select_modifier;?> name="show_severity[]">
3403                  <option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['show_severity'], META_FILTER_ANY ); ?>>[<?php echo lang_get( 'any' ) ?>]</option>
3404                  <?php print_enum_string_option_list( 'severity', $t_filter['show_severity'] ) ?>
3405              </select>
3406          <?php
3407      }
3408  
3409  	function print_filter_show_resolution(){
3410          global $t_select_modifier, $t_filter;
3411          ?><!-- Resolution -->
3412              <select <?php PRINT $t_select_modifier;?> name="show_resolution[]">
3413                  <option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['show_resolution'], META_FILTER_ANY ); ?>>[<?php echo lang_get( 'any' ) ?>]</option>
3414                  <?php print_enum_string_option_list( 'resolution', $t_filter['show_resolution'] ) ?>
3415              </select>
3416          <?php
3417      }
3418  
3419  	function print_filter_show_status(){
3420          global $t_select_modifier, $t_filter;
3421          ?>    <!-- Status -->
3422              <select <?php PRINT $t_select_modifier;?> name="show_status[]">
3423                  <option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['show_status'], META_FILTER_ANY ); ?>>[<?php echo lang_get( 'any' ) ?>]</option>
3424                  <?php print_enum_string_option_list( 'status', $t_filter['show_status'] ) ?>
3425              </select>
3426          <?php
3427      }
3428  
3429  	function print_filter_hide_status(){
3430          global $t_select_modifier, $t_filter;
3431          ?><!-- Hide Status -->
3432              <select <?php PRINT $t_select_modifier;?> name="hide_status[]">
3433                  <option value="<?php echo META_FILTER_NONE ?>">[<?php echo lang_get( 'none' ) ?>]</option>
3434                  <?php print_enum_string_option_list( 'status', $t_filter['hide_status'] ) ?>
3435              </select>
3436          <?php
3437      }
3438  
3439  	function print_filter_show_build(){
3440          global $t_select_modifier, $t_filter;
3441          ?><!-- Build -->
3442          <select <?php PRINT $t_select_modifier;?> name="show_build[]">
3443              <option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['show_build'], META_FILTER_ANY ); ?>>[<?php echo lang_get( 'any' ) ?>]</option>
3444              <option value="<?php echo META_FILTER_NONE ?>" <?php check_selected( $t_filter['show_build'], META_FILTER_NONE ); ?>>[<?php echo lang_get( 'none' ) ?>]</option>
3445              <?php print_build_option_list( $t_filter['show_build'] ) ?>
3446          </select>
3447          <?php
3448      }
3449  
3450  	function print_filter_show_version(){
3451          global $t_select_modifier, $t_filter;
3452          ?><!-- Version -->
3453          <select <?php PRINT $t_select_modifier;?> name="show_version[]">
3454              <option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['show_version'], META_FILTER_ANY ); ?>>[<?php echo lang_get( 'any' ) ?>]</option>
3455              <option value="<?php echo META_FILTER_NONE ?>" <?php check_selected( $t_filter['show_version'], META_FILTER_NONE ); ?>>[<?php echo lang_get( 'none' ) ?>]</option>
3456              <?php print_version_option_list( $t_filter['show_version'], null, VERSION_RELEASED, false, true ) ?>
3457          </select>
3458          <?php
3459      }
3460  
3461  	function print_filter_show_fixed_in_version(){
3462          global $t_select_modifier, $t_filter;
3463          ?><!-- Fixed in Version -->
3464          <select <?php PRINT $t_select_modifier;?> name="fixed_in_version[]">
3465              <option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['fixed_in_version'], META_FILTER_ANY ); ?>>[<?php echo lang_get( 'any' ) ?>]</option>
3466              <option value="<?php echo META_FILTER_NONE ?>" <?php check_selected( $t_filter['fixed_in_version'], META_FILTER_NONE ); ?>>[<?php echo lang_get( 'none' ) ?>]</option>
3467              <?php print_version_option_list( $t_filter['fixed_in_version'], null, VERSION_ALL, false, true ) ?>
3468          </select>
3469          <?php
3470      }
3471  
3472  	function print_filter_show_target_version(){
3473          global $t_select_modifier, $t_filter;
3474          ?><!-- Fixed in Version -->
3475          <select <?php PRINT $t_select_modifier;?> name="target_version[]">
3476              <option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['target_version'], META_FILTER_ANY ); ?>>[<?php echo lang_get( 'any' ) ?>]</option>
3477              <option value="<?php echo META_FILTER_NONE ?>" <?php check_selected( $t_filter['target_version'], META_FILTER_NONE ); ?>>[<?php echo lang_get( 'none' ) ?>]</option>
3478              <?php print_version_option_list( $t_filter['target_version'], null, VERSION_ALL, false, true ) ?>
3479          </select>
3480          <?php
3481      }
3482  
3483  	function print_filter_show_priority(){
3484          global $t_select_modifier, $t_filter;
3485          ?><!-- Priority -->
3486      <select <?php PRINT $t_select_modifier;?> name="show_priority[]">
3487              <option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['show_priority'], META_FILTER_ANY ); ?>>[<?php echo lang_get( 'any' ) ?>]</option>
3488              <?php print_enum_string_option_list( 'priority', $t_filter['show_priority'] ) ?>
3489      </select>
3490          <?php
3491      }
3492  
3493  	function print_filter_show_profile() {
3494          global $t_select_modifier, $t_filter;
3495          ?><!-- Profile -->
3496          <select <?php PRINT $t_select_modifier;?> name="show_profile[]">
3497              <option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['show_profile'], META_FILTER_ANY ); ?>>[<?php echo lang_get( 'any' ) ?>]</option>
3498              <?php print_profile_option_list_for_project( helper_get_current_project(), $t_filter['show_profile'] ); ?>
3499          </select>
3500          <?php
3501      }
3502  
3503  	function print_filter_per_page(){
3504          global $t_filter;
3505          ?><!-- Number of bugs per page -->
3506          <input type="text" name="per_page" size="3" maxlength="7" value="<?php echo $t_filter['per_page'] ?>" />
3507          <?php
3508      }
3509  
3510  	function print_filter_view_state(){
3511          global $t_select_modifier, $t_filter;
3512          ?><!-- View Status -->
3513          <select name="view_state">
3514              <?php
3515              PRINT '<option value="' . META_FILTER_ANY . '" ';
3516              check_selected( $t_filter['view_state'], META_FILTER_ANY );
3517              PRINT '>[' . lang_get( 'any' ) . ']</option>';
3518              PRINT '<option value="' . VS_PUBLIC . '" ';
3519              check_selected( $t_filter['view_state'], VS_PUBLIC );
3520              PRINT '>' . lang_get( 'public' ) . '</option>';
3521              PRINT '<option value="' . VS_PRIVATE . '" ';
3522              check_selected( $t_filter['view_state'], VS_PRIVATE );
3523              PRINT '>' . lang_get( 'private' ) . '</option>';
3524              ?>
3525          </select>
3526          <?php
3527      }
3528  
3529  	function print_filter_sticky_issues(){
3530          global $t_filter;
3531          ?><!-- Show or hide sticky bugs -->
3532              <input type="checkbox" name="sticky_issues" <?php check_checked( gpc_string_to_bool( $t_filter['sticky_issues'] ), 'on' ); ?> />
3533          <?php
3534      }
3535  
3536  	function print_filter_highlight_changed(){
3537          global $t_filter;
3538          ?><!-- Highlight changed bugs -->
3539              <input type="text" name="highlight_changed" size="3" maxlength="7" value="<?php echo $t_filter['highlight_changed'] ?>" />
3540          <?php
3541      }
3542  
3543  	function print_filter_do_filter_by_date( $p_hide_checkbox=false ){
3544          global $t_filter;
3545          ?>
3546          <table cellspacing="0" cellpadding="0">
3547          <?php if ( ! $p_hide_checkbox ) {
3548          ?>
3549          <tr><td colspan="2">
3550              <input type="checkbox" name="do_filter_by_date" <?php
3551                  check_checked( $t_filter['do_filter_by_date'], 'on' );
3552                  if ( ON == config_get( 'use_javascript' ) ) {
3553                      print "onclick=\"SwitchDateFields();\""; } ?> />
3554              <?php echo lang_get( 'use_date_filters' ) ?>
3555          </td></tr>
3556          <?php }
3557          $t_menu_disabled = ( 'on' == $t_filter['do_filter_by_date'] ) ? '' : ' disabled ';
3558          ?>
3559  
3560          <!-- Start date -->
3561          <tr>
3562              <td>
3563              <?php echo lang_get( 'start_date' ) ?>:
3564              </td>
3565              <td nowrap="nowrap">
3566              <?php
3567              $t_chars = preg_split( '//', config_get( 'short_date_format' ), -1, PREG_SPLIT_NO_EMPTY );
3568              foreach( $t_chars as $t_char ) {
3569                  if ( strcasecmp( $t_char, "M" ) == 0 ) {
3570                      print "<select name=\"start_month\" $t_menu_disabled>";
3571                      print_month_option_list( $t_filter['start_month'] );
3572                      print "</select>\n";
3573                  }
3574                  if ( strcasecmp( $t_char, "D" ) == 0 ) {
3575                      print "<select name=\"start_day\" $t_menu_disabled>";
3576                      print_day_option_list( $t_filter['start_day'] );
3577                      print "</select>\n";
3578                  }
3579                  if ( strcasecmp( $t_char, "Y" ) == 0 ) {
3580                      print "<select name=\"start_year\" $t_menu_disabled>";
3581                      print_year_option_list( $t_filter['start_year'] );
3582                      print "</select>\n";
3583                  }
3584              }
3585              ?>
3586              </td>
3587          </tr>
3588          <!-- End date -->
3589          <tr>
3590              <td>
3591              <?php echo lang_get( 'end_date' ) ?>:
3592              </td>
3593              <td>
3594              <?php
3595              $t_chars = preg_split( '//', config_get( 'short_date_format' ), -1, PREG_SPLIT_NO_EMPTY );
3596              foreach( $t_chars as $t_char ) {
3597                  if ( strcasecmp( $t_char, "M" ) == 0 ) {
3598                      print "<select name=\"end_month\" $t_menu_disabled>";
3599                      print_month_option_list( $t_filter['end_month'] );
3600                      print "</select>\n";
3601                  }
3602                  if ( strcasecmp( $t_char, "D" ) == 0 ) {
3603                      print "<select name=\"end_day\" $t_menu_disabled>";
3604                      print_day_option_list( $t_filter['end_day'] );
3605                      print "</select>\n";
3606                  }
3607                  if ( strcasecmp( $t_char, "Y" ) == 0 ) {
3608                      print "<select name=\"end_year\" $t_menu_disabled>";
3609                      print_year_option_list( $t_filter['end_year'] );
3610                      print "</select>\n";
3611                  }
3612              }
3613              ?>
3614              </td>
3615          </tr>
3616          </table>
3617          <?php
3618      }
3619  
3620  	function print_filter_relationship_type(){
3621          global $t_filter;
3622          $c_reltype_value = $t_filter['relationship_type'];
3623          if (!$c_reltype_value) {
3624              $c_reltype_value = -1;
3625          }
3626          relationship_list_box ($c_reltype_value, "relationship_type", true); ?>
3627          <input type="text" name="relationship_bug" size="5" maxlength="10" value="<?php echo $t_filter['relationship_bug']?>" />
3628          <?php
3629  
3630      }
3631  
3632  	function print_filter_tag_string() {
3633          global $t_filter;
3634          $t_tag_string = $t_filter['tag_string'];
3635          if ( $t_filter['tag_select'] != 0 ) {
3636              $t_tag_string .= ( is_blank( $t_tag_string ) ? '' : config_get( 'tag_separator' ) );
3637              $t_tag_string .= tag_get_field( $t_filter['tag_select'], 'name' );
3638          }
3639          ?>
3640          <input type="hidden" id="tag_separator" value="<?php echo config_get( 'tag_separator' ) ?>" />
3641          <input type="text" name="tag_string" id="tag_string" size="40" value="<?php echo $t_tag_string ?>" />
3642          <select <?php echo helper_get_tab_index() ?> name="tag_select" id="tag_select">
3643              <?php print_tag_option_list(); ?>
3644          </select>
3645          <?php
3646      }
3647  
3648  	function print_filter_custom_field($p_field_id){
3649          global $t_filter, $t_accessible_custom_fields_names, $t_accessible_custom_fields_types, $t_accessible_custom_fields_values, $t_accessible_custom_fields_ids, $t_select_modifier;
3650  
3651          $j = array_search($p_field_id, $t_accessible_custom_fields_ids);
3652          if($j === null || $j === false){
3653              # Note: Prior to PHP 4.2.0, array_search() returns NULL on failure instead of FALSE.
3654              ?>
3655              <span style="color:red;weight:bold;">
3656                  unknown custom filter (custom <?php $p_field_id; ?>)
3657              </span>
3658              <?php
3659          } elseif ( isset( $t_accessible_custom_fields_names[$j] ) ) {
3660              if ($t_accessible_custom_fields_types[$j] == CUSTOM_FIELD_TYPE_DATE) {
3661                  print_filter_custom_field_date($j, $p_field_id) ;
3662              } else {
3663                  echo '<select ' . $t_select_modifier . ' name="custom_field_' . $p_field_id .'[]">';
3664                  echo '<option value="' . META_FILTER_ANY . '" ';
3665                  check_selected( $t_filter['custom_fields'][ $p_field_id ], META_FILTER_ANY );
3666                  echo '>[' . lang_get( 'any' ) .']</option>';
3667                  # don't show META_FILTER_NONE for enumerated types as it's not possible for them to be blank
3668                  if ( ! in_array( $t_accessible_custom_fields_types[$j], array( CUSTOM_FIELD_TYPE_ENUM, CUSTOM_FIELD_TYPE_LIST, CUSTOM_FIELD_TYPE_MULTILIST ) ) ) {
3669                      echo '<option value="' . META_FILTER_NONE . '" ';
3670                      check_selected( $t_filter['custom_fields'][ $p_field_id ], META_FILTER_NONE );
3671                      echo '>[' . lang_get( 'none' ) .']</option>';
3672                  }
3673                  foreach( $t_accessible_custom_fields_values[$j] as $t_item ) {
3674                      if ( ( strtolower( $t_item ) !== META_FILTER_ANY ) && ( strtolower( $t_item ) !== META_FILTER_NONE ) ) {
3675                          echo '<option value="' .  string_html_entities( $t_item )  . '" ';
3676                          if ( isset( $t_filter['custom_fields'][ $p_field_id ] ) ) {
3677                              check_selected( $t_filter['custom_fields'][ $p_field_id ], $t_item );
3678                          }
3679                          echo '>' . string_shorten( $t_item )  . '</option>' . "\n";
3680                      }
3681                  }
3682                  echo '</select>';
3683              }
3684          }
3685  
3686      }
3687  
3688  	function print_filter_show_sort() {
3689          global $t_filter;
3690  
3691          # get all of the displayed fields for sort, then drop ones that
3692          #  are not appropriate and translate the rest
3693          $t_fields = helper_get_columns_to_view();
3694          $t_n_fields = count( $t_fields );
3695          $t_shown_fields[""] = "";
3696          for ( $i=0; $i < $t_n_fields; $i++ ) {
3697              if ( !in_array( $t_fields[$i], array( 'selection', 'edit', 'bugnotes_count', 'attachment' ) ) ) {
3698                  if ( strpos( $t_fields[$i], 'custom_' ) === 0 ) {
3699                      $t_field_name = string_display( lang_get_defaulted( substr( $t_fields[$i], strlen( 'custom_' ) ) ) );
3700                  } else {
3701                      $t_field_name = string_get_field_name( $t_fields[$i] );
3702                  }
3703                  $t_shown_fields[$t_fields[$i]] = $t_field_name;
3704              }
3705          }
3706          $t_shown_dirs[""] = "";
3707          $t_shown_dirs["ASC"] = lang_get( 'bugnote_order_asc' );
3708          $t_shown_dirs["DESC"] = lang_get( 'bugnote_order_desc' );
3709  
3710          # get default values from filter structure
3711          $t_sort_fields = split( ',', $t_filter['sort'] );
3712          $t_dir_fields = split( ',', $t_filter['dir'] );
3713          if ( !isset( $t_sort_fields[1] ) ) {
3714              $t_sort_fields[1] = '';
3715              $t_dir_fields[1] = '';
3716          }
3717  
3718          # if there are fields to display, show the dropdowns
3719          if ( count( $t_fields ) > 0 ) {
3720              # display a primary and secondary sort fields
3721              echo '<select name="sort_0">';
3722              foreach ( $t_shown_fields as $key => $val ) {
3723                  echo "<option value=\"$key\"";
3724                  check_selected( $key, $t_sort_fields[0] );
3725                  echo ">$val</option>";
3726              }
3727              echo '</select>';
3728  
3729              echo '<select name="dir_0">';
3730              foreach ( $t_shown_dirs as $key => $val ) {
3731                  echo "<option value=\"$key\"";
3732                  check_selected( $key, $t_dir_fields[0] );
3733                  echo ">$val</option>";
3734              }
3735              echo '</select>';
3736  
3737              echo ', ';
3738  
3739              # for secondary sort
3740              echo '<select name="sort_1">';
3741              foreach ( $t_shown_fields as $key => $val ) {
3742                  echo "<option value=\"$key\"";
3743                  check_selected( $key, $t_sort_fields[1] );
3744                  echo ">$val</option>";
3745              }
3746              echo '</select>';
3747              echo '<select name="dir_1">';
3748              foreach ($t_shown_dirs as $key => $val ) {
3749                  echo "<option value=\"$key\"";
3750                  check_selected( $key, $t_dir_fields[1] );
3751                  echo ">$val</option>";
3752              }
3753              echo '</select>';
3754          } else {
3755              echo lang_get_defaulted( 'last_updated' ) . lang_get( 'bugnote_order_desc' );
3756              echo "<input type=\"hidden\" name=\"sort_1\" value=\"last_updated\" />";
3757              echo "<input type=\"hidden\" name=\"dir_1\" value=\"DESC\" />";
3758          }
3759      }
3760  
3761  
3762  
3763  	function print_filter_custom_field_date($p_field_num, $p_field_id) {
3764          global $t_filter, $t_accessible_custom_fields_names, $t_accessible_custom_fields_types, $t_accessible_custom_fields_values, $t_accessible_custom_fields_ids, $t_select_modifier;
3765  
3766          $t_js_toggle_func = "toggle_custom_date_field_" . $p_field_id . "_controls" ;
3767  
3768          # Resort the values so there ordered numerically, they are sorted as strings otherwise which
3769          # may be wrong for dates before early 2001.
3770          if (is_array($t_accessible_custom_fields_values[$p_field_num]))
3771          {
3772              array_multisort($t_accessible_custom_fields_values[$p_field_num], SORT_NUMERIC, SORT_ASC);
3773          }
3774  
3775          if (isset($t_accessible_custom_fields_values[$p_field_num][0])) {
3776              $t_sel_start_year = date( 'Y', $t_accessible_custom_fields_values[$p_field_num][0]) ;
3777          }
3778          $t_count = count($t_accessible_custom_fields_values[$p_field_num]) ;
3779          if (isset($t_accessible_custom_fields_values[$p_field_num][$t_count-1])) {
3780              $t_sel_end_year = date( 'Y', $t_accessible_custom_fields_values[$p_field_num][$t_count-1]) ;
3781          }
3782  
3783          $t_start = date( 'U' ); # Default to today in filters..
3784          $t_end = $t_start;
3785  
3786          if ( isset( $t_filter['custom_fields'][$p_field_id][1] ) ) {
3787              $t_start_time = $t_filter['custom_fields'][$p_field_id][1];
3788          } else {
3789              $t_start_time = 0;
3790          }
3791  
3792          if ( isset( $t_filter['custom_fields'][$p_field_id][2] ) ) {
3793              $t_end_time = $t_filter['custom_fields'][$p_field_id][2];
3794          } else {
3795              $t_end_time = 0;
3796          }
3797  
3798          $t_start_disable = true;
3799          $t_end_disable = true;
3800  
3801          // if $t_filter['custom_fields'][$p_field_id][0] is not set (ie no filter), we will drop through the
3802          // following switch and use the default values above, so no need to check if stuff is set or not.
3803          switch ($t_filter['custom_fields'][$p_field_id][0]) {
3804          case CUSTOM_FIELD_DATE_ANY:
3805          case CUSTOM_FIELD_DATE_NONE:
3806              break;
3807          case CUSTOM_FIELD_DATE_BETWEEN:
3808              $t_start_disable = false;
3809              $t_end_disable = false;
3810              $t_start = $t_start_time;
3811              $t_end = $t_end_time;
3812              break;
3813          case CUSTOM_FIELD_DATE_ONORBEFORE:
3814              $t_start_disable = false;
3815              $t_start = $t_end_time;
3816              break;
3817          case CUSTOM_FIELD_DATE_BEFORE:
3818              $t_start_disable = false;
3819              $t_start = $t_end_time;
3820              break;
3821          case CUSTOM_FIELD_DATE_ON:
3822              $t_start_disable = false;
3823              $t_start = $t_start_time;
3824              break;
3825          case CUSTOM_FIELD_DATE_AFTER:
3826              $t_start_disable = false;
3827              $t_start = $t_start_time;
3828              break;
3829          case CUSTOM_FIELD_DATE_ONORAFTER:
3830              $t_start_disable = false;
3831              $t_start = $t_start_time;
3832              break;
3833          }
3834  
3835          echo "\n<table cellspacing=\"0\" cellpadding=\"0\"><tr><td>\n" ;
3836          echo "<select size=\"1\" name=\"custom_field_" . $p_field_id . "_control\" OnChange=\"" . $t_js_toggle_func . "();\">\n";
3837          echo '<option value="' . CUSTOM_FIELD_DATE_ANY . '"';
3838              check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_ANY );
3839              echo '>' . lang_get( 'any' ) . '</option>' . "\n";
3840          echo '<option value="' . CUSTOM_FIELD_DATE_NONE    . '"';
3841              check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_NONE );
3842              echo '>' . lang_get( 'none' ) . '</option>' . "\n";
3843          echo '<option value="' . CUSTOM_FIELD_DATE_BETWEEN . '"';
3844              check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_BETWEEN );
3845              echo '>' . lang_get( 'between' ) . '</option>' . "\n";
3846          echo '<option value="' . CUSTOM_FIELD_DATE_ONORBEFORE . '"';
3847              check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_ONORBEFORE );
3848              echo '>' . lang_get( 'on_or_before' ) . '</option>' . "\n";
3849          echo '<option value="' . CUSTOM_FIELD_DATE_BEFORE . '"';
3850              check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_BEFORE );
3851              echo '>' . lang_get( 'before' ) . '</option>' . "\n";
3852          echo '<option value="' . CUSTOM_FIELD_DATE_ON . '"';
3853              check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_ON );
3854              echo '>' . lang_get( 'on' ) . '</option>' . "\n";
3855          echo '<option value="' . CUSTOM_FIELD_DATE_AFTER . '"';
3856              check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_AFTER );
3857              echo '>' . lang_get( 'after' ) . '</option>' . "\n";
3858          echo '<option value="' . CUSTOM_FIELD_DATE_ONORAFTER . '"';
3859              check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_ONORAFTER    );
3860              echo '>' . lang_get( 'on_or_after' ) . '</option>' . "\n";
3861          echo '</select>' . "\n";
3862  
3863          echo "</td></tr>\n<tr><td>";
3864  
3865          print_date_selection_set("custom_field_" . $p_field_id . "_start" , config_get( 'short_date_format'), $t_start, $t_start_disable, false, $t_sel_start_year, $t_sel_end_year);
3866          print "</td></tr>\n<tr><td>";
3867          print_date_selection_set("custom_field_" . $p_field_id . "_end" , config_get( 'short_date_format'), $t_end, $t_end_disable, false, $t_sel_start_year, $t_sel_end_year);
3868          print "</td></tr>\n</table>";
3869      }
3870  
3871  	function print_filter_project_id(){
3872          global $t_select_modifier, $t_filter, $f_view_type;
3873          ?>
3874          <!-- Project -->
3875          <select <?php PRINT $t_select_modifier;?> name="project_id[]">
3876              <option value="<?php echo META_FILTER_CURRENT ?>" <?php check_selected( $t_filter['project_id'], META_FILTER_CURRENT ); ?>>[<?php echo lang_get( 'current' ) ?>]</option>
3877              <?php print_project_option_list( $t_filter['project_id'] ) ?>
3878          </select>
3879          <?php
3880      }
3881      
3882      # Prints a multi-value filter field.  For example, platform, etc.
3883      # $p_field_name - The name of the field, e.g. "platform"
3884      # $p_field_value - an array of values.
3885  	function print_multivalue_field( $p_field_name, $p_field_value ) {
3886          $t_output = '';
3887          $t_any_found = false;
3888  
3889          if ( count( $p_field_value ) == 0 ) {
3890              echo lang_get( 'any' );
3891          } else {
3892              $t_first_flag = true;
3893              
3894              $t_field_value = is_array( $p_field_value ) ? $p_field_value : array( $p_field_value );
3895  
3896              foreach( $t_field_value as $t_current ) {
3897                  $t_current = stripslashes( $t_current );
3898                  ?>
3899                  <input type="hidden" name="<?php echo $p_field_name ?>[]" value="<?php echo string_display( $t_current );?>" />
3900                  <?php
3901                  $t_this_string = '';
3902  
3903                  if ( ( ( $t_current == META_FILTER_ANY ) && ( is_numeric( $t_current ) ) ) 
3904                          || ( is_blank( $t_current ) ) ) {
3905                      $t_any_found = true;
3906                  } else {
3907                      $t_this_string = string_display( $t_current );
3908                  }
3909  
3910                  if ( $t_first_flag != true ) {
3911                      $t_output .= '<br />';
3912                  } else {
3913                      $t_first_flag = false;
3914                  }
3915  
3916                  $t_output .= $t_this_string;
3917              }
3918  
3919              if ( true == $t_any_found ) {
3920                  echo lang_get( 'any' );
3921              } else {
3922                  echo $t_output;
3923              }
3924          }
3925      }
3926  
3927      #===================================
3928      # Caching
3929      #===================================
3930  
3931      #########################################
3932      # SECURITY NOTE: cache globals are initialized here to prevent them
3933      #   being spoofed if register_globals is turned on
3934  
3935      $g_cache_filter = array();
3936  
3937      # --------------------
3938      # Cache a filter row if necessary and return the cached copy
3939      # If the second parameter is true (default), trigger an error
3940      # if the filter can't be found.  If the second parameter is
3941      # false, return false if the filter can't be found.
3942  	function filter_cache_row( $p_filter_id, $p_trigger_errors=true) {
3943          global $g_cache_filter;
3944  
3945          $c_filter_id = db_prepare_int( $p_filter_id );
3946  
3947          $t_filters_table = config_get( 'mantis_filters_table' );
3948  
3949          if ( isset ( $g_cache_filter[$c_filter_id] ) ) {
3950              return $g_cache_filter[$c_filter_id];
3951          }
3952  
3953          $query = "SELECT *
3954                    FROM $t_filters_table
3955                    WHERE id='$c_filter_id'";
3956          $result = db_query( $query );
3957  
3958          if ( 0 == db_num_rows( $result ) ) {
3959              if ( $p_trigger_errors ) {
3960                  error_parameters( $p_filter_id );
3961                  trigger_error( ERROR_FILTER_NOT_FOUND, ERROR );
3962              } else {
3963                  return false;
3964              }
3965          }
3966  
3967          $row = db_fetch_array( $result );
3968  
3969          $g_cache_filter[$c_filter_id] = $row;
3970  
3971          return $row;
3972      }
3973  
3974      # --------------------
3975      # Clear the filter cache (or just the given id if specified)
3976  	function filter_clear_cache( $p_filter_id = null ) {
3977          global $g_cache_filter;
3978  
3979          if ( null === $p_filter_id ) {
3980              $g_cache_filter = array();
3981          } else {
3982              $c_filter_id = db_prepare_int( $p_filter_id );
3983              unset( $g_cache_filter[$c_filter_id] );
3984          }
3985  
3986          return true;
3987      }
3988  
3989      # --------------------
3990      # return a filter row
3991  	function filter_get_row( $p_filter_id ) {
3992          return filter_cache_row( $p_filter_id );
3993      }
3994  
3995      # --------------------
3996  	function filter_get_field( $p_filter_id, $p_field_name ) {
3997          $row = filter_get_row( $p_filter_id );
3998  
3999          if ( isset( $row[$p_field_name] ) ) {
4000              return $row[$p_field_name];
4001          } else {
4002              error_parameters( $p_field_name );
4003              trigger_error( ERROR_DB_FIELD_NOT_FOUND, WARNING );
4004              return '';
4005          }
4006      }
4007      
4008      # --------------------
4009      # Checks if a filter value is "any".  Supports both single value as well as multiple value
4010      # fields (array).
4011      # $p_filter_value - The value which can be a simple value or an array.
4012  	function _filter_is_any( $p_filter_value ) {
4013          if ( ( META_FILTER_ANY == $p_filter_value ) && is_numeric( $p_filter_value ) ) {
4014              return true;
4015          }
4016  
4017          if ( count( $p_filter_value ) == 0 ) {
4018              return true;
4019          }
4020  
4021          foreach( $p_filter_value as $t_value ) {
4022              if ( ( META_FILTER_ANY == $t_value ) && ( is_numeric( $t_value ) ) ) {
4023                  return true;
4024              }
4025          }
4026  
4027          return false;
4028      }
4029  ?>


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