Blame Identity/Models/Html/Mantis/1.1.2-1.fc9/bug_actiongroup_attach_tags_inc.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
	# $Id: bug_actiongroup_attach_tags_inc.php,v 1.1.2.2 2007-10-13 22:32:31 giallu Exp $
4c79b5
	# --------------------------------------------------------
4c79b5
4c79b5
	$t_core_path = config_get( 'core_path' );
4c79b5
	require_once( $t_core_path . 'tag_api.php' );
4c79b5
4c79b5
	/**
4c79b5
	 * Prints the title for the custom action page.	 
4c79b5
	 */
4c79b5
	function action_attach_tags_print_title() {
4c79b5
        echo '';
4c79b5
        echo '';
4c79b5
        echo lang_get( 'tag_attach_long' );
4c79b5
        echo '';		
4c79b5
	}
4c79b5
4c79b5
	/**
4c79b5
	 * Prints the table and form for the Attach Tags group action page.
4c79b5
	 */
4c79b5
	function action_attach_tags_print_fields() {
4c79b5
		echo '',lang_get('tag_attach_long'),'';
4c79b5
		print_tag_input();
4c79b5
		echo '<input type="submit" class="button" value="' . lang_get( 'tag_attach' ) . ' " />';
4c79b5
	}
4c79b5
4c79b5
	/**
4c79b5
	 * Validates the Attach Tags group action.
4c79b5
	 * Gets called for every bug, but performs the real tag validation only
4c79b5
	 * the first time.  Any invalid tags will be skipped, as there is no simple
4c79b5
	 * or clean method of presenting these errors to the user.
4c79b5
	 * @param integer Bug ID
4c79b5
	 * @return boolean True
4c79b5
	 */
4c79b5
	function action_attach_tags_validate( $p_bug_id ) {
4c79b5
		global $g_action_attach_tags_valid;
4c79b5
		if ( !isset( $g_action_attach_tags_valid ) ) {
4c79b5
			$f_tag_string = gpc_get_string( 'tag_string' );
4c79b5
			$f_tag_select = gpc_get_string( 'tag_select' );
4c79b5
4c79b5
			global $g_action_attach_tags_attach, $g_action_attach_tags_create, $g_action_attach_tags_failed; 
4c79b5
			$g_action_attach_tags_attach = array();
4c79b5
			$g_action_attach_tags_create = array();
4c79b5
			$g_action_attach_tags_failed = array();
4c79b5
4c79b5
			$t_tags = tag_parse_string( $f_tag_string );
4c79b5
			$t_can_create = access_has_global_level( config_get( 'tag_create_threshold' ) );
4c79b5
4c79b5
			foreach ( $t_tags as $t_tag_row ) {
4c79b5
				if ( -1 == $t_tag_row['id'] ) {
4c79b5
					if ( $t_can_create ) {
4c79b5
						$g_action_attach_tags_create[] = $t_tag_row;
4c79b5
					} else {
4c79b5
						$g_action_attach_tags_failed[] = $t_tag_row;
4c79b5
					}
4c79b5
				} elseif ( -2 == $t_tag_row['id'] ) {
4c79b5
					$g_action_attach_tags_failed[] = $t_tag_row;
4c79b5
				} else {
4c79b5
					$g_action_attach_tags_attach[] = $t_tag_row;
4c79b5
				}
4c79b5
			}
4c79b5
4c79b5
			if ( 0 < $f_tag_select && tag_exists( $f_tag_select ) ) {
4c79b5
				$g_action_attach_tags_attach[] = tag_get( $f_tag_select );
4c79b5
			}
4c79b5
4c79b5
		}
4c79b5
4c79b5
		global $g_action_attach_tags_attach, $g_action_attach_tags_create, $g_action_attach_tags_failed; 
4c79b5
4c79b5
		return true;
4c79b5
	}
4c79b5
4c79b5
	/**
4c79b5
	 * Attaches all the tags to each bug in the group action.
4c79b5
	 * @param integer Bug ID
4c79b5
	 * @return boolean True if all tags attach properly
4c79b5
	 */
4c79b5
	function action_attach_tags_process( $p_bug_id ) {
4c79b5
		global $g_action_attach_tags_attach, $g_action_attach_tags_create; 
4c79b5
4c79b5
		$t_user_id = auth_get_current_user_id();
4c79b5
4c79b5
		foreach( $g_action_attach_tags_create as $t_tag_row ) {
4c79b5
			$t_tag_row['id'] = tag_create( $t_tag_row['name'], $t_user_id );
4c79b5
			$g_action_attach_tags_attach[] = $t_tag_row;
4c79b5
		}
4c79b5
		$g_action_attach_tags_create = array();
4c79b5
4c79b5
		foreach( $g_action_attach_tags_attach as $t_tag_row ) {
4c79b5
			if ( ! tag_bug_is_attached( $t_tag_row['id'], $p_bug_id ) ) {
4c79b5
				tag_bug_attach( $t_tag_row['id'], $p_bug_id, $t_user_id );
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		return true;
4c79b5
	}