Blame Identity/Webenv/App/Mantis/1.1.2-1.fc9/bug_actiongroup_attach_tags_inc.php

ef5584
ef5584
# Mantis - a php based bugtracking system
ef5584
ef5584
# Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
ef5584
# Copyright (C) 2002 - 2007  Mantis Team   - mantisbt-dev@lists.sourceforge.net
ef5584
ef5584
# Mantis is free software: you can redistribute it and/or modify
ef5584
# it under the terms of the GNU General Public License as published by
ef5584
# the Free Software Foundation, either version 2 of the License, or
ef5584
# (at your option) any later version.
ef5584
#
ef5584
# Mantis is distributed in the hope that it will be useful,
ef5584
# but WITHOUT ANY WARRANTY; without even the implied warranty of
ef5584
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ef5584
# GNU General Public License for more details.
ef5584
#
ef5584
# You should have received a copy of the GNU General Public License
ef5584
# along with Mantis.  If not, see <http://www.gnu.org/licenses/>.
ef5584
ef5584
	# --------------------------------------------------------
ef5584
	# $Id: bug_actiongroup_attach_tags_inc.php,v 1.1.2.2 2007-10-13 22:32:31 giallu Exp $
ef5584
	# --------------------------------------------------------
ef5584
ef5584
	$t_core_path = config_get( 'core_path' );
ef5584
	require_once( $t_core_path . 'tag_api.php' );
ef5584
ef5584
	/**
ef5584
	 * Prints the title for the custom action page.	 
ef5584
	 */
ef5584
	function action_attach_tags_print_title() {
ef5584
        echo '';
ef5584
        echo '';
ef5584
        echo lang_get( 'tag_attach_long' );
ef5584
        echo '';		
ef5584
	}
ef5584
ef5584
	/**
ef5584
	 * Prints the table and form for the Attach Tags group action page.
ef5584
	 */
ef5584
	function action_attach_tags_print_fields() {
ef5584
		echo '',lang_get('tag_attach_long'),'';
ef5584
		print_tag_input();
ef5584
		echo '<input type="submit" class="button" value="' . lang_get( 'tag_attach' ) . ' " />';
ef5584
	}
ef5584
ef5584
	/**
ef5584
	 * Validates the Attach Tags group action.
ef5584
	 * Gets called for every bug, but performs the real tag validation only
ef5584
	 * the first time.  Any invalid tags will be skipped, as there is no simple
ef5584
	 * or clean method of presenting these errors to the user.
ef5584
	 * @param integer Bug ID
ef5584
	 * @return boolean True
ef5584
	 */
ef5584
	function action_attach_tags_validate( $p_bug_id ) {
ef5584
		global $g_action_attach_tags_valid;
ef5584
		if ( !isset( $g_action_attach_tags_valid ) ) {
ef5584
			$f_tag_string = gpc_get_string( 'tag_string' );
ef5584
			$f_tag_select = gpc_get_string( 'tag_select' );
ef5584
ef5584
			global $g_action_attach_tags_attach, $g_action_attach_tags_create, $g_action_attach_tags_failed; 
ef5584
			$g_action_attach_tags_attach = array();
ef5584
			$g_action_attach_tags_create = array();
ef5584
			$g_action_attach_tags_failed = array();
ef5584
ef5584
			$t_tags = tag_parse_string( $f_tag_string );
ef5584
			$t_can_create = access_has_global_level( config_get( 'tag_create_threshold' ) );
ef5584
ef5584
			foreach ( $t_tags as $t_tag_row ) {
ef5584
				if ( -1 == $t_tag_row['id'] ) {
ef5584
					if ( $t_can_create ) {
ef5584
						$g_action_attach_tags_create[] = $t_tag_row;
ef5584
					} else {
ef5584
						$g_action_attach_tags_failed[] = $t_tag_row;
ef5584
					}
ef5584
				} elseif ( -2 == $t_tag_row['id'] ) {
ef5584
					$g_action_attach_tags_failed[] = $t_tag_row;
ef5584
				} else {
ef5584
					$g_action_attach_tags_attach[] = $t_tag_row;
ef5584
				}
ef5584
			}
ef5584
ef5584
			if ( 0 < $f_tag_select && tag_exists( $f_tag_select ) ) {
ef5584
				$g_action_attach_tags_attach[] = tag_get( $f_tag_select );
ef5584
			}
ef5584
ef5584
		}
ef5584
ef5584
		global $g_action_attach_tags_attach, $g_action_attach_tags_create, $g_action_attach_tags_failed; 
ef5584
ef5584
		return true;
ef5584
	}
ef5584
ef5584
	/**
ef5584
	 * Attaches all the tags to each bug in the group action.
ef5584
	 * @param integer Bug ID
ef5584
	 * @return boolean True if all tags attach properly
ef5584
	 */
ef5584
	function action_attach_tags_process( $p_bug_id ) {
ef5584
		global $g_action_attach_tags_attach, $g_action_attach_tags_create; 
ef5584
ef5584
		$t_user_id = auth_get_current_user_id();
ef5584
ef5584
		foreach( $g_action_attach_tags_create as $t_tag_row ) {
ef5584
			$t_tag_row['id'] = tag_create( $t_tag_row['name'], $t_user_id );
ef5584
			$g_action_attach_tags_attach[] = $t_tag_row;
ef5584
		}
ef5584
		$g_action_attach_tags_create = array();
ef5584
ef5584
		foreach( $g_action_attach_tags_attach as $t_tag_row ) {
ef5584
			if ( ! tag_bug_is_attached( $t_tag_row['id'], $p_bug_id ) ) {
ef5584
				tag_bug_attach( $t_tag_row['id'], $p_bug_id, $t_user_id );
ef5584
			}
ef5584
		}
ef5584
ef5584
		return true;
ef5584
	}