[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/core/cfdefs/ -> cfdef_standard.php (source)

   1  <?php
   2  # MantisBT - A PHP based bugtracking system
   3  
   4  # Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
   5  # Copyright (C) 2002 - 2011  MantisBT Team - mantisbt-dev@lists.sourceforge.net
   6  
   7  # MantisBT 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  # MantisBT 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 MantisBT.  If not, see <http://www.gnu.org/licenses/>.
  19  
  20  $g_custom_field_type_definition[ CUSTOM_FIELD_TYPE_STRING ] = array (
  21      '#display_possible_values' => TRUE,
  22      '#display_valid_regexp' => TRUE,
  23      '#display_length_min' => TRUE,
  24      '#display_length_max' => TRUE,
  25      '#display_default_value' => TRUE,
  26      '#function_return_distinct_values' => null,
  27      '#function_value_to_database' => null,
  28      '#function_database_to_value' => null,
  29      '#function_print_input' => 'cfdef_input_textbox',
  30      '#function_string_value' => null,
  31      '#function_string_value_for_email' => null,
  32  );
  33  
  34  $g_custom_field_type_definition[ CUSTOM_FIELD_TYPE_TEXTAREA] = array (
  35      '#display_possible_values' => TRUE,
  36      '#display_valid_regexp' => TRUE,
  37      '#display_length_min' => TRUE,
  38      '#display_length_max' => TRUE,
  39      '#display_default_value' => TRUE,
  40      '#function_return_distinct_values' => null,
  41      '#function_value_to_database' => null,
  42      '#function_database_to_value' => null,
  43      '#function_print_input' => 'cfdef_input_textarea',
  44      '#function_string_value' => null,
  45      '#function_string_value_for_email' => null,
  46  );
  47  
  48  $g_custom_field_type_definition[ CUSTOM_FIELD_TYPE_NUMERIC ] = array (
  49      '#display_possible_values' => TRUE,
  50      '#display_valid_regexp' => TRUE,
  51      '#display_length_min' => TRUE,
  52      '#display_length_max' => TRUE,
  53      '#display_default_value' => TRUE,
  54      '#function_return_distinct_values' => null,
  55      '#function_value_to_database' => null,
  56      '#function_database_to_value' => null,
  57      '#function_print_input' => 'cfdef_input_textbox',
  58      '#function_string_value' => null,
  59      '#function_string_value_for_email' => null,
  60  );
  61  
  62  $g_custom_field_type_definition[ CUSTOM_FIELD_TYPE_FLOAT ] = array (
  63      '#display_possible_values' => TRUE,
  64      '#display_valid_regexp' => TRUE,
  65      '#display_length_min' => TRUE,
  66      '#display_length_max' => TRUE,
  67      '#display_default_value' => TRUE,
  68      '#function_return_distinct_values' => null,
  69      '#function_value_to_database' => null,
  70      '#function_database_to_value' => null,
  71      '#function_print_input' => 'cfdef_input_textbox',
  72      '#function_string_value' => null,
  73      '#function_string_value_for_email' => null,
  74  );
  75  
  76  $g_custom_field_type_definition[ CUSTOM_FIELD_TYPE_ENUM ] = array (
  77      '#display_possible_values' => TRUE,
  78      '#display_valid_regexp' => TRUE,
  79      '#display_length_min' => TRUE,
  80      '#display_length_max' => TRUE,
  81      '#display_default_value' => TRUE,
  82      '#function_return_distinct_values' => 'cfdef_prepare_list_distinct_values',
  83      '#function_value_to_database' => null,
  84      '#function_database_to_value' => null,
  85      '#function_print_input' => 'cfdef_input_list',
  86      '#function_string_value' => 'cfdef_prepare_list_value',
  87      '#function_string_value_for_email' => 'cfdef_prepare_list_value_for_email',
  88  );
  89  
  90  $g_custom_field_type_definition[ CUSTOM_FIELD_TYPE_EMAIL ] = array (
  91      '#display_possible_values' => TRUE,
  92      '#display_valid_regexp' => TRUE,
  93      '#display_length_min' => TRUE,
  94      '#display_length_max' => TRUE,
  95      '#display_default_value' => TRUE,
  96      '#function_return_distinct_values' => null,
  97      '#function_value_to_database' => null,
  98      '#function_database_to_value' => null,
  99      '#function_print_input' => 'cfdef_input_textbox',
 100      '#function_string_value' => 'cfdef_prepare_email_value',
 101      '#function_string_value_for_email' => 'cfdef_prepare_email_value_for_email',
 102  );
 103  
 104  $g_custom_field_type_definition[ CUSTOM_FIELD_TYPE_CHECKBOX ] = array (
 105      '#display_possible_values' => TRUE,
 106      '#display_valid_regexp' => TRUE,
 107      '#display_length_min' => TRUE,
 108      '#display_length_max' => TRUE,
 109      '#display_default_value' => TRUE,
 110      '#function_return_distinct_values' => 'cfdef_prepare_list_distinct_values',
 111      '#function_value_to_database' => 'cfdef_prepare_list_value_to_database',
 112      '#function_database_to_value' => 'cfdef_prepare_list_database_to_value',
 113      '#function_print_input' => 'cfdef_input_checkbox',
 114      '#function_string_value' => 'cfdef_prepare_list_value',
 115      '#function_string_value_for_email' => 'cfdef_prepare_list_value_for_email',
 116  );
 117  
 118  $g_custom_field_type_definition[ CUSTOM_FIELD_TYPE_RADIO ] = array (
 119      '#display_possible_values' => TRUE,
 120      '#display_valid_regexp' => FALSE,
 121      '#display_length_min' => FALSE,
 122      '#display_length_max' => FALSE,
 123      '#display_default_value' => TRUE,
 124      '#function_return_distinct_values' => 'cfdef_prepare_list_distinct_values',
 125      '#function_value_to_database' => null,
 126      '#function_database_to_value' => null,
 127      '#function_print_input' => 'cfdef_input_radio',
 128      '#function_string_value' => 'cfdef_prepare_list_value',
 129      '#function_string_value_for_email' => 'cfdef_prepare_list_value_for_email',
 130  );
 131  
 132  $g_custom_field_type_definition[ CUSTOM_FIELD_TYPE_LIST ] = array (
 133      '#display_possible_values' => TRUE,
 134      '#display_valid_regexp' => TRUE,
 135      '#display_length_min' => TRUE,
 136      '#display_length_max' => TRUE,
 137      '#display_default_value' => TRUE,
 138      '#function_return_distinct_values' => 'cfdef_prepare_list_distinct_values',
 139      '#function_value_to_database' => null,
 140      '#function_database_to_value' => null,
 141      '#function_print_input' => 'cfdef_input_list',
 142      '#function_string_value' => 'cfdef_prepare_list_value',
 143      '#function_string_value_for_email' => 'cfdef_prepare_list_value_for_email',
 144  );
 145  
 146  $g_custom_field_type_definition[ CUSTOM_FIELD_TYPE_MULTILIST ] = array (
 147      '#display_possible_values' => TRUE,
 148      '#display_valid_regexp' => TRUE,
 149      '#display_length_min' => TRUE,
 150      '#display_length_max' => TRUE,
 151      '#display_default_value' => TRUE,
 152      '#function_return_distinct_values' => 'cfdef_prepare_list_distinct_values',
 153      '#function_value_to_database' => 'cfdef_prepare_list_value_to_database',
 154      '#function_database_to_value' => 'cfdef_prepare_list_database_to_value',
 155      '#function_print_input' => 'cfdef_input_list',
 156      '#function_string_value' => 'cfdef_prepare_list_value',
 157      '#function_string_value_for_email' => 'cfdef_prepare_list_value_for_email',
 158  );
 159  
 160  $g_custom_field_type_definition[ CUSTOM_FIELD_TYPE_DATE ] = array (
 161      '#display_possible_values' => TRUE,
 162      '#display_valid_regexp' => TRUE,
 163      '#display_length_min' => TRUE,
 164      '#display_length_max' => TRUE,
 165      '#display_default_value' => TRUE,
 166      '#function_return_distinct_values' => null,
 167      '#function_value_to_database' => null,
 168      '#function_database_to_value' => null,
 169      '#function_default_to_value' => 'cfdef_prepare_date_default',
 170      '#function_print_input' => 'cfdef_input_date',
 171      '#function_string_value' => 'cfdef_prepare_date_value',
 172      '#function_string_value_for_email' => 'cfdef_prepare_date_value_for_email',
 173  );
 174  
 175  function cfdef_prepare_list_database_to_value($p_value) {
 176      return rtrim( ltrim( $p_value, '|' ), '|' );
 177  }
 178  
 179  function cfdef_prepare_list_value_for_email($p_value) {
 180      // strip start and end markers before converting markers to commas
 181      return str_replace( '|', ', ', utf8_substr( str_replace( '||', '|', '|' . $p_value . '|' ), 1, -1 ) );
 182  }
 183  
 184  function cfdef_prepare_email_value_for_email($p_value) {
 185      return 'mailto:'.$p_value;
 186  }
 187  
 188  function cfdef_prepare_date_value_for_email($p_value) {
 189      if ($p_value != null) {
 190          return date( config_get( 'short_date_format' ), $p_value) ;
 191      }
 192  }
 193  
 194  /**
 195   * Translates the default date value entered by the creator of the custom
 196   * field into a date value.  For example, translate '=tomorrow' to tomorrow's
 197   * date.
 198   * @param $p_value The default date string.
 199   * @returns The calculated default date value if $p_value starts with '=',
 200   *          otherwise, returns $p_value.
 201   */
 202  function cfdef_prepare_date_default( $p_value ) {
 203      if ( is_blank( $p_value ) ) {
 204          return '';
 205      }
 206  
 207      $t_value = trim( $p_value );
 208      $t_value_length = utf8_strlen( $t_value );
 209  
 210      # We are expanding {tomorrow}, {yesterday}, {+3 days}, {-7 days}, {next week}
 211      # See strtotime() for more details about supported formats.
 212      if ( $t_value_length >= 3 && $t_value[0] == '{' && $t_value[$t_value_length - 1] == '}' ) {
 213          $t_value = utf8_substr( $t_value, 1, $t_value_length - 2 );
 214          $t_value = @strtotime( $t_value );
 215  
 216          # Different versions of PHP return different values in case of error.
 217          if ( $t_value == -1 || $t_value === false ) {
 218              return '';
 219          }
 220      }
 221  
 222      return $t_value;
 223  }
 224  
 225  #string_custom_field_value
 226  function cfdef_prepare_list_value($p_value) {
 227      // strip start and end markers before converting markers to commas
 228      return string_display_line( str_replace( '|', ', ', utf8_substr( str_replace( '||', '|', '|' . $p_value . '|' ), 1, -1 ) ) );
 229  }
 230  
 231  function cfdef_prepare_email_value($p_value) {
 232      return "<a href=\"mailto:" . string_attribute( $p_value ) . "\">" . string_display_line( $p_value ) . "</a>";
 233  }
 234  
 235  function cfdef_prepare_date_value($p_value) {
 236      if ($p_value != null) {
 237          return date( config_get( 'short_date_format'), $p_value);
 238      }
 239  }
 240  
 241  
 242  #print_custom_field_input
 243  
 244  function cfdef_input_list($p_field_def, $t_custom_field_value) {
 245      $t_values = explode( '|', custom_field_prepare_possible_values( $p_field_def['possible_values'] ) );
 246      $t_list_size = $t_possible_values_count = count( $t_values );
 247  
 248      if ( $t_possible_values_count > 5 ) {
 249          $t_list_size = 5;
 250      }
 251  
 252      if ( $p_field_def['type'] == CUSTOM_FIELD_TYPE_ENUM ) {
 253          $t_list_size = 0;    # for enums the size is 0
 254      }
 255  
 256      if ( $p_field_def['type'] == CUSTOM_FIELD_TYPE_MULTILIST ) {
 257          echo '<select ' . helper_get_tab_index() . ' id="custom_field_' . $p_field_def['id'] . '" name="custom_field_' . $p_field_def['id'] . '[]" size="' . $t_list_size . '" multiple="multiple">';
 258      } else {
 259          echo '<select ' . helper_get_tab_index() . ' id="custom_field_' . $p_field_def['id'] . '" name="custom_field_' . $p_field_def['id'] . '" size="' . $t_list_size . '">';
 260      }
 261  
 262      $t_selected_values = explode( '|', $t_custom_field_value );
 263      foreach( $t_values as $t_option ) {
 264          if( in_array( $t_option, $t_selected_values, true ) ) {
 265              echo '<option value="' . string_attribute( $t_option ) . '" selected="selected"> ' . string_display_line( $t_option ) . '</option>';
 266          } else {
 267              echo '<option value="' . string_attribute( $t_option ) . '">' . string_display_line( $t_option ) . '</option>';
 268          }
 269      }
 270      echo '</select>';
 271  }
 272  
 273  function cfdef_input_checkbox($p_field_def, $t_custom_field_value) {
 274      $t_values = explode( '|', custom_field_prepare_possible_values( $p_field_def['possible_values'] ) );
 275      $t_checked_values = explode( '|', $t_custom_field_value );
 276      for ($i = 0; $i < count( $t_values ); $i++) {
 277          $t_input_id = 'custom_field_' . $p_field_def['id'] . '_value_' . $i;
 278          $t_input_name = 'custom_field_' . $p_field_def['id'] . '[]';
 279          echo "<input id=\"$t_input_id\" " . helper_get_tab_index() . " type=\"checkbox\" name=\"$t_input_name\" value=\"" . string_attribute( $t_values[$i] ) . '"';
 280          check_checked( $t_checked_values, $t_values[$i] );
 281          echo " />\n";
 282          echo "<label for=\"$t_input_id\">" . string_display_line( $t_values[$i] ) . "</label>\n";
 283      }
 284  }
 285  
 286  function cfdef_input_radio( $p_field_def, $p_custom_field_value ) {
 287      $t_values = explode( '|', custom_field_prepare_possible_values( $p_field_def['possible_values'] ) );
 288  
 289      $t_len = strlen( $p_custom_field_value );
 290      if ( $t_len >= 2 && ( $p_custom_field_value[0] == '|' ) && ( $p_custom_field_value[$t_len-1] == '|' ) ) {
 291          $t_checked_value = substr( $p_custom_field_value, 1, $t_len - 2 );
 292      } else {
 293          $t_checked_value = $p_custom_field_value;
 294      }
 295  
 296      for ($i = 0; $i < count( $t_values ); $i++) {
 297          $t_input_id = 'custom_field_' . $p_field_def['id'] . '_value_' . $i;
 298          $t_input_name = 'custom_field_' . $p_field_def['id'];
 299          echo "<input id=\"$t_input_id\" " . helper_get_tab_index() . " type=\"radio\" name=\"$t_input_name\" value=\"" . string_attribute( $t_values[$i] ) . '"';
 300          check_checked( $t_checked_value, $t_values[$i] );
 301          echo " />\n";
 302          echo "<label for=\"$t_input_id\">" . string_display_line( $t_values[$i] ) . "</label>\n";
 303      }
 304  }
 305  
 306  function cfdef_input_textbox($p_field_def, $t_custom_field_value) {
 307      echo '<input ' . helper_get_tab_index() . ' type="text" id="custom_field_' . $p_field_def['id'] . '" name="custom_field_' . $p_field_def['id'] . '" size="80"';
 308      if( 0 < $p_field_def['length_max'] ) {
 309          echo ' maxlength="' . $p_field_def['length_max'] . '"';
 310      } else {
 311          echo ' maxlength="255"';
 312      }
 313      echo ' value="' . string_attribute( $t_custom_field_value ) .'"></input>';
 314  }
 315  
 316  function cfdef_input_textarea($p_field_def, $t_custom_field_value) {
 317      echo '<textarea ' . helper_get_tab_index() . ' id="custom_field_' . $p_field_def['id'] . '" name="custom_field_' . $p_field_def['id'] . '"';
 318      echo ' cols="70" rows="8">' . $t_custom_field_value .'</textarea>';
 319  }
 320  
 321  /**
 322   * Prints the controls for the date selector.
 323   *
 324   * @param $p_field_def  The custom field definition.
 325   * @param $p_custom_field_value  The custom field value to print.
 326   */
 327  function cfdef_input_date( $p_field_def, $p_custom_field_value ) {
 328      print_date_selection_set( 'custom_field_' . $p_field_def['id'], config_get( 'short_date_format' ), $p_custom_field_value, false, true );
 329  }
 330  
 331  #value to database
 332  function cfdef_prepare_list_value_to_database($p_value) {
 333      if ( '' == $p_value ) {
 334          return '';
 335      } else {
 336          return '|' . $p_value . '|';
 337      }
 338  }
 339  
 340  function cfdef_prepare_list_distinct_values($p_field_def) {
 341      $t_custom_field_table = db_get_table( 'custom_field' );
 342  
 343      $query = "SELECT possible_values
 344                FROM $t_custom_field_table
 345                WHERE id=" . db_param();
 346      $result = db_query_bound( $query, Array( $p_field_def['id'] ) );
 347  
 348      $t_row_count = db_num_rows( $result );
 349      if ( 0 == $t_row_count ) {
 350          return false;
 351      }
 352      $row = db_fetch_array( $result );
 353  
 354      $t_possible_values = custom_field_prepare_possible_values( $row['possible_values'] );
 355      $t_values_arr = explode( '|', $t_possible_values );
 356      $t_return_arr = array();
 357  
 358      foreach( $t_values_arr as $t_option ) {
 359          array_push( $t_return_arr, $t_option );
 360      }
 361      return $t_return_arr;
 362  }


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