Blame Identity/Models/Html/Mantis/1.1.2-1.fc9/core/custom_function_api.php

4c79b5
4c79b5
# Mantis - a php based bugtracking system
4c79b5
4c79b5
# Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
4c79b5
# Copyright (C) 2002 - 2007  Mantis Team   - mantisbt-dev@lists.sourceforge.net
4c79b5
4c79b5
# Mantis is free software: you can redistribute it and/or modify
4c79b5
# it under the terms of the GNU General Public License as published by
4c79b5
# the Free Software Foundation, either version 2 of the License, or
4c79b5
# (at your option) any later version.
4c79b5
#
4c79b5
# Mantis is distributed in the hope that it will be useful,
4c79b5
# but WITHOUT ANY WARRANTY; without even the implied warranty of
4c79b5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4c79b5
# GNU General Public License for more details.
4c79b5
#
4c79b5
# You should have received a copy of the GNU General Public License
4c79b5
# along with Mantis.  If not, see <http://www.gnu.org/licenses/>.
4c79b5
4c79b5
	#------------------------------
4c79b5
	#   $Revision: 2643 $
4c79b5
	#     $Author: al $    
4c79b5
	#       $Date: 2009-06-18 19:06:27 -0400 (Thu, 18 Jun 2009) $  
4c79b5
	#------------------------------
4c79b5
4c79b5
	$t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR;
4c79b5
4c79b5
	require_once( $t_core_dir . 'prepare_api.php' );
4c79b5
4c79b5
	### Custom Function API ###
4c79b5
4c79b5
	# --------------------
4c79b5
	# Checks the provided bug and determines whether it should be included in the changelog
4c79b5
	# or not.
4c79b5
	# returns true: to include, false: to exclude.
4c79b5
	function custom_function_default_changelog_include_issue( $p_issue_id ) {
4c79b5
		$t_issue = bug_get( $p_issue_id );
4c79b5
4c79b5
		return ( ( $t_issue->duplicate_id == 0 ) && ( $t_issue->resolution == FIXED ) &&
4c79b5
			( $t_issue->status >= config_get( 'bug_resolved_status_threshold' ) ) );
4c79b5
	}
4c79b5
4c79b5
4c79b5
	# --------------------
4c79b5
	# Prints one entry in the changelog.
4c79b5
	function custom_function_default_changelog_print_issue( $p_issue_id, $p_issue_level = 0 ) {
4c79b5
		$t_bug = bug_get( $p_issue_id );
4c79b5
4c79b5
		$t_category = is_blank( $t_bug->category ) ? '' : '[' . $t_bug->category . '] ';
4c79b5
		echo str_pad( '', $p_issue_level * 6, ' ' ), '- ', string_get_bug_view_link( $p_issue_id ), ': ', $t_category, string_display_line_links( $t_bug->summary );
4c79b5
4c79b5
		if ( $t_bug->handler_id != 0 ) {
4c79b5
			echo ' (', prepare_user_name( $t_bug->handler_id ), ')';
4c79b5
		}
4c79b5
4c79b5
		echo ' - ', get_enum_element( 'status', $t_bug->status ), '.
';
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# Checks the provided bug and determines whether it should be included in the roadmap or not.
4c79b5
	# returns true: to include, false: to exclude.
4c79b5
	function custom_function_default_roadmap_include_issue( $p_issue_id ) {
4c79b5
		$t_issue = bug_get( $p_issue_id );
4c79b5
4c79b5
		return ( $t_issue->duplicate_id == 0 );
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# Prints one entry in the roadmap.
4c79b5
	function custom_function_default_roadmap_print_issue( $p_issue_id, $p_issue_level = 0 ) {
4c79b5
		$t_bug = bug_get( $p_issue_id );
4c79b5
		
4c79b5
		if ( bug_is_resolved( $p_issue_id ) ) {
4c79b5
			$t_strike_start = '<strike>';
4c79b5
			$t_strike_end = '</strike>';
4c79b5
		} else {
4c79b5
			$t_strike_start = $t_strike_end = '';
4c79b5
		}
4c79b5
		
4c79b5
		$t_category = is_blank( $t_bug->category ) ? '' : '[' . $t_bug->category . '] ';
4c79b5
		echo str_pad( '', $p_issue_level * 6, ' ' ), '- ', $t_strike_start, string_get_bug_view_link( $p_issue_id ), ': ', $t_category, string_display_line_links( $t_bug->summary );
4c79b5
4c79b5
		if ( $t_bug->handler_id != 0 ) {
4c79b5
			echo ' (', prepare_user_name( $t_bug->handler_id ), ')';
4c79b5
		}
4c79b5
4c79b5
		echo ' - ', get_enum_element( 'status', $t_bug->status ), $t_strike_end, '.
';
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# format the bug summary.
4c79b5
	function custom_function_default_format_issue_summary( $p_issue_id, $p_context=0 ) {
4c79b5
		switch ( $p_context ) {
4c79b5
			case SUMMARY_CAPTION:
4c79b5
				$t_string = bug_format_id( $p_issue_id ) . ': ' . string_attribute( bug_get_field( $p_issue_id, 'summary' ) );
4c79b5
				break;
4c79b5
			case SUMMARY_FIELD:
4c79b5
				$t_string = bug_format_id( $p_issue_id ) . ': ' . string_display_line_links( bug_get_field( $p_issue_id, 'summary' ) );
4c79b5
				break;
4c79b5
			case SUMMARY_EMAIL:
4c79b5
				$t_string = bug_format_id( $p_issue_id ) . ': ' . string_attribute( bug_get_field( $p_issue_id, 'summary' ) );
4c79b5
				break;
4c79b5
			default:
4c79b5
				$t_string = string_attribute( bug_get_field( $p_issue_id, 'summary' ) );
4c79b5
				break;
4c79b5
		}
4c79b5
		return $t_string;
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# Register a checkin in source control by adding a history entry and a note
4c79b5
	# This can be overriden to do extra work.
4c79b5
	# The issue status/resolution would only be set if the issue is fixed, and hence $p_fixed is passed as true.
4c79b5
	function custom_function_default_checkin( $p_issue_id, $p_comment, $p_file, $p_new_version, $p_fixed ) {
4c79b5
		if ( bug_exists( $p_issue_id ) ) {
4c79b5
			history_log_event_special( $p_issue_id, CHECKIN, $p_file, $p_new_version );
4c79b5
			bugnote_add( $p_issue_id, $p_comment, 0, VS_PRIVATE == config_get( 'source_control_notes_view_status' ) );
4c79b5
4c79b5
			$t_status = config_get( 'source_control_set_status_to' );
4c79b5
			if ( ( OFF != $t_status ) && $p_fixed ) {
4c79b5
				bug_set_field( $p_issue_id, 'status', $t_status );
4c79b5
				bug_set_field( $p_issue_id, 'resolution', config_get( 'source_control_set_resolution_to' ) );
4c79b5
			}
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# Hook to validate field issue data before updating
4c79b5
	# Verify that the proper fields are set with the appropriate values before proceeding
4c79b5
	# to change the status.
4c79b5
	# In case of invalid data, this function should call trigger_error()
4c79b5
	# p_issue_id is the issue number that can be used to get the existing state
4c79b5
	# p_new_issue_data is an object (BugData) with the appropriate fields updated
4c79b5
	function custom_function_default_issue_update_validate( $p_issue_id, $p_new_issue_data, $p_bugnote_text ) {
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# Hook to notify after an issue has been updated.
4c79b5
	# In case of errors, this function should call trigger_error()
4c79b5
	# p_issue_id is the issue number that can be used to get the existing state
4c79b5
	function custom_function_default_issue_update_notify( $p_issue_id ) {
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# Hook to validate field settings before creating an issue
4c79b5
	# Verify that the proper fields are set before proceeding to create an issue
4c79b5
	# In case of errors, this function should call trigger_error()
4c79b5
	# p_new_issue_data is an object (BugData) with the appropriate fields updated
4c79b5
	function custom_function_default_issue_create_validate( $p_new_issue_data ) {
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# Hook to notify after aa issue has been created.
4c79b5
	# In case of errors, this function should call trigger_error()
4c79b5
	# p_issue_id is the issue number that can be used to get the existing state
4c79b5
	function custom_function_default_issue_create_notify( $p_issue_id ) {
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# Hook to validate field settings before deleting an issue.
4c79b5
	# Verify that the issue can be deleted before the actual deletion.
4c79b5
	# In the case that the issue should not be deleted, this function should
4c79b5
	# call trigger_error().
4c79b5
	# p_issue_id is the issue number that can be used to get the existing state
4c79b5
	function custom_function_default_issue_delete_validate( $p_issue_id ) {
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# Hook to notify after an issue has been deleted.
4c79b5
	# p_issue_data is the issue data (BugData) that reflects the last status of the
4c79b5
	# issue before it was deleted.
4c79b5
	function custom_function_default_issue_delete_notify( $p_issue_data ) {
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# Hook for authentication
4c79b5
	# can Mantis update the password
4c79b5
	function custom_function_default_auth_can_change_password( ) {
4c79b5
		$t_can_change = array( PLAIN, CRYPT, CRYPT_FULL_SALT, MD5 );
4c79b5
		if ( in_array( config_get( 'login_method' ), $t_can_change ) ) {
4c79b5
			return true;
4c79b5
		} else {
4c79b5
			return false;
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# returns an array of the column names to be displayed.
4c79b5
	# The column names to use are those of the field names in the bug table.
4c79b5
	# In addition, you can use the following:
4c79b5
	# - "selection" for selection checkboxes.
4c79b5
	# - "edit" for icon to open the edit page.
4c79b5
	# - "custom_xxxx" were xxxx is the name of the custom field that is valid for the
4c79b5
	#   current project.  In case of "All Projects, the field will be empty where it is
4c79b5
	#   not applicable.
4c79b5
	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
4c79b5
	function custom_function_default_get_columns_to_view( $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
4c79b5
		if ( $p_columns_target == COLUMNS_TARGET_CSV_PAGE ) {
4c79b5
			$t_columns = config_get( 'csv_columns' );
4c79b5
		} else if ( $p_columns_target == COLUMNS_TARGET_VIEW_PAGE ) {
4c79b5
			$t_columns = config_get( 'view_issues_page_columns' );
4c79b5
		} else {
4c79b5
			$t_columns = config_get( 'print_issues_page_columns' );
4c79b5
		}
4c79b5
4c79b5
		return $t_columns;
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# Print the title of a column given its name.
4c79b5
	# $p_column: custom_xxx for custom field xxx, or otherwise field name as in bug table.
4c79b5
	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
4c79b5
	function custom_function_default_print_column_title( $p_column, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
4c79b5
		global $t_sort, $t_dir;
4c79b5
4c79b5
		if ( strpos( $p_column, 'custom_' ) === 0 ) {
4c79b5
			$t_custom_field = substr( $p_column, 7 );
4c79b5
4c79b5
			if ( COLUMNS_TARGET_CSV_PAGE != $p_columns_target ) {
4c79b5
				echo '';
4c79b5
			}
4c79b5
4c79b5
			$t_field_id = custom_field_get_id_from_name( $t_custom_field );
4c79b5
			if ( $t_field_id === false ) {
4c79b5
				echo '@', $t_custom_field, '@';
4c79b5
			} else {
4c79b5
				$t_def = custom_field_get_definition( $t_field_id );
4c79b5
				$t_custom_field = lang_get_defaulted( $t_def['name'] );
4c79b5
4c79b5
				if ( COLUMNS_TARGET_CSV_PAGE != $p_columns_target ) {
4c79b5
					print_sort_icon( $t_dir, $t_sort, $p_column );
4c79b5
					print_view_bug_sort_link( $t_custom_field, $p_column, $t_sort, $t_dir, $p_columns_target );
4c79b5
				} else {
4c79b5
					echo $t_custom_field;
4c79b5
				}
4c79b5
			}
4c79b5
4c79b5
			if ( COLUMNS_TARGET_CSV_PAGE != $p_columns_target ) {
4c79b5
				echo '';
4c79b5
			}
4c79b5
		} else {
4c79b5
			$t_function = 'print_column_title_' . $p_column;
4c79b5
			if ( function_exists( $t_function ) ) {
4c79b5
				$t_function( $t_sort, $t_dir, $p_columns_target );
4c79b5
			} else {
4c79b5
				echo '';
4c79b5
				print_sort_icon( $t_dir, $t_sort, $p_column );
4c79b5
				print_view_bug_sort_link( lang_get_defaulted( $p_column ), $p_column, $t_sort, $t_dir, $p_columns_target );
4c79b5
				echo '';
4c79b5
			}
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# Print the value of the custom field (if the field is applicable to the project of
4c79b5
	# the specified issue and the current user has read access to it.
4c79b5
	# see custom_function_default_print_column_title() for rules about column names.
4c79b5
	# $p_column: name of field to show in the column.
4c79b5
	# $p_row: the row from the bug table that belongs to the issue that we should print the values for.
4c79b5
	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
4c79b5
	function custom_function_default_print_column_value( $p_column, $p_issue_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
4c79b5
		if ( COLUMNS_TARGET_CSV_PAGE == $p_columns_target ) {
4c79b5
			$t_column_start = '';
4c79b5
			$t_column_end = '';
4c79b5
			$t_column_empty = '';
4c79b5
		} else {
4c79b5
			$t_column_start = '';
4c79b5
			$t_column_end = '';
4c79b5
			$t_column_empty = ' ';
4c79b5
		}
4c79b5
4c79b5
		if ( strpos( $p_column, 'custom_' ) === 0 ) {
4c79b5
			echo $t_column_start;
4c79b5
			$t_custom_field = substr( $p_column, 7 );
4c79b5
4c79b5
			$t_field_id = custom_field_get_id_from_name( $t_custom_field );
4c79b5
			if ( $t_field_id === false ) {
4c79b5
				echo '@', $t_custom_field, '@';
4c79b5
			} else {
4c79b5
				$t_issue_id = $p_issue_row['id'];
4c79b5
				$t_project_id = $p_issue_row['project_id'];
4c79b5
4c79b5
				if ( custom_field_is_linked( $t_field_id, $t_project_id ) ) {
4c79b5
					$t_def = custom_field_get_definition( $t_field_id );
4c79b5
					print_custom_field_value( $t_def, $t_field_id, $t_issue_id );
4c79b5
				} else {
4c79b5
					// field is not linked to project
4c79b5
					echo $t_column_empty;
4c79b5
				}
4c79b5
			}
4c79b5
			echo $t_column_end;
4c79b5
		} else {
4c79b5
			if ( $p_columns_target != COLUMNS_TARGET_CSV_PAGE ) {
4c79b5
				$t_function = 'print_column_' . $p_column;
4c79b5
			} else {
4c79b5
				$t_function = 'csv_format_' . $p_column;
4c79b5
			}
4c79b5
4c79b5
			if ( function_exists( $t_function ) ) {
4c79b5
				if ( $p_columns_target != COLUMNS_TARGET_CSV_PAGE ) {
4c79b5
					$t_function( $p_issue_row, $p_columns_target );
4c79b5
				} else {
4c79b5
					$t_function( $p_issue_row[$p_column] );
4c79b5
				}
4c79b5
			} else {
4c79b5
				if ( isset( $p_issue_row[$p_column] ) ) {
4c79b5
					echo $t_column_start . $p_issue_row[$p_column] . $t_column_end;
4c79b5
				} else {
4c79b5
					echo $t_column_start . '@' . $p_column . '@' . $t_column_end;
4c79b5
				}
4c79b5
			}
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# Construct an enumeration for all versions for the current project.
4c79b5
	# The enumeration will be empty if current project is ALL PROJECTS.
4c79b5
	# Enumerations format is: "abc|lmn|xyz"
4c79b5
	# To use this in a custom field type "=versions" in the possible values field.
4c79b5
	function custom_function_default_enum_versions() {
4c79b5
		$t_versions = version_get_all_rows( helper_get_current_project() );
4c79b5
4c79b5
		$t_enum = array();
4c79b5
		foreach( $t_versions as $t_version ) {
4c79b5
			$t_enum[] = $t_version['version'];
4c79b5
		}
4c79b5
4c79b5
		$t_possible_values = implode( '|', $t_enum );
4c79b5
4c79b5
		return $t_possible_values;
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# Construct an enumeration for released versions for the current project.
4c79b5
	# The enumeration will be empty if current project is ALL PROJECTS.
4c79b5
	# Enumerations format is: "abc|lmn|xyz"
4c79b5
	# To use this in a custom field type "=released_versions" in the possible values field.
4c79b5
	function custom_function_default_enum_released_versions() {
4c79b5
		$t_versions = version_get_all_rows( helper_get_current_project() );
4c79b5
4c79b5
		$t_enum = array();
4c79b5
		foreach( $t_versions as $t_version ) {
4c79b5
			if ( $t_version['released'] == 1 ) {
4c79b5
				$t_enum[] = $t_version['version'];
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		$t_possible_values = implode( '|', $t_enum );
4c79b5
4c79b5
		return $t_possible_values;
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# Construct an enumeration for released versions for the current project.
4c79b5
	# The enumeration will be empty if current project is ALL PROJECTS.
4c79b5
	# Enumerations format is: "abc|lmn|xyz"
4c79b5
	# To use this in a custom field type "=future_versions" in the possible values field.
4c79b5
	function custom_function_default_enum_future_versions() {
4c79b5
		$t_versions = version_get_all_rows( helper_get_current_project() );
4c79b5
4c79b5
		$t_enum = array();
4c79b5
		foreach( $t_versions as $t_version ) {
4c79b5
			if ( $t_version['released'] == 0 ) {
4c79b5
				$t_enum[] = $t_version['version'];
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		$t_possible_values = implode( '|', $t_enum );
4c79b5
4c79b5
		return $t_possible_values;
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# Construct an enumeration for all categories for the current project.
4c79b5
	# The enumeration will be empty if current project is ALL PROJECTS.
4c79b5
	# Enumerations format is: "abc|lmn|xyz"
4c79b5
	# To use this in a custom field type "=categories" in the possible values field.
4c79b5
	function custom_function_default_enum_categories() {
4c79b5
		$t_categories = category_get_all_rows( helper_get_current_project() );
4c79b5
4c79b5
		$t_enum = array();
4c79b5
		foreach( $t_categories as $t_category ) {
4c79b5
			$t_enum[] = $t_category['category'];
4c79b5
		}
4c79b5
4c79b5
		$t_possible_values = implode( '|', $t_enum );
4c79b5
4c79b5
		return $t_possible_values;
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# This function prints the custom buttons on the current view page based on specified bug id
4c79b5
	# and the context.  The printing of the buttons will typically call html_button() from
4c79b5
	# html_api.php.  For each button, this function needs to generate the enclosing '' and ''.
4c79b5
	function custom_function_default_print_bug_view_page_custom_buttons( $p_bug_id ) {
4c79b5
	}
4c79b5
?>