Fix #11417: Allow EVENT_MENU_MAIN plugin events to return null
[mantis/radio.git] / bug_actiongroup_attach_tags_inc.php
blob78adeaa39693bbe202fe85240f03dbbef2c6be73
1 <?php
2 # MantisBT - A PHP based bugtracking system
4 # MantisBT is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 2 of the License, or
7 # (at your option) any later version.
9 # MantisBT is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * @package MantisBT
19 * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
20 * @copyright Copyright (C) 2002 - 2010 MantisBT Team - mantisbt-dev@lists.sourceforge.net
21 * @link http://www.mantisbt.org
23 * @uses access_api.php
24 * @uses authentication_api.php
25 * @uses config_api.php
26 * @uses gpc_api.php
27 * @uses helper_api.php
28 * @uses lang_api.php
29 * @uses print_api.php
30 * @uses tag_api.php
33 require_api( 'access_api.php' );
34 require_api( 'authentication_api.php' );
35 require_api( 'config_api.php' );
36 require_api( 'gpc_api.php' );
37 require_api( 'helper_api.php' );
38 require_api( 'lang_api.php' );
39 require_api( 'print_api.php' );
40 require_api( 'tag_api.php' );
42 /**
43 * Prints the title for the custom action page.
45 function action_attach_tags_print_title() {
46 echo '<tr class="form-title">';
47 echo '<td colspan="2">';
48 echo lang_get( 'tag_attach_long' );
49 echo '</td></tr>';
52 /**
53 * Prints the table and form for the Attach Tags group action page.
55 function action_attach_tags_print_fields() {
56 echo '<tr ',helper_alternate_class(),'><td class="category">',lang_get('tag_attach_long'),'</td><td>';
57 print_tag_input();
58 echo '<input type="submit" class="button" value="' . lang_get( 'tag_attach' ) . ' " /></td></tr>';
61 /**
62 * Validates the Attach Tags group action.
63 * Gets called for every bug, but performs the real tag validation only
64 * the first time. Any invalid tags will be skipped, as there is no simple
65 * or clean method of presenting these errors to the user.
66 * @param integer Bug ID
67 * @return boolean True
69 function action_attach_tags_validate( $p_bug_id ) {
70 global $g_action_attach_tags_valid;
71 if ( !isset( $g_action_attach_tags_valid ) ) {
72 $f_tag_string = gpc_get_string( 'tag_string' );
73 $f_tag_select = gpc_get_string( 'tag_select' );
75 global $g_action_attach_tags_attach, $g_action_attach_tags_create, $g_action_attach_tags_failed;
76 $g_action_attach_tags_attach = array();
77 $g_action_attach_tags_create = array();
78 $g_action_attach_tags_failed = array();
80 $t_tags = tag_parse_string( $f_tag_string );
81 $t_can_create = access_has_global_level( config_get( 'tag_create_threshold' ) );
83 foreach ( $t_tags as $t_tag_row ) {
84 if ( -1 == $t_tag_row['id'] ) {
85 if ( $t_can_create ) {
86 $g_action_attach_tags_create[] = $t_tag_row;
87 } else {
88 $g_action_attach_tags_failed[] = $t_tag_row;
90 } else if ( -2 == $t_tag_row['id'] ) {
91 $g_action_attach_tags_failed[] = $t_tag_row;
92 } else {
93 $g_action_attach_tags_attach[] = $t_tag_row;
97 if ( 0 < $f_tag_select && tag_exists( $f_tag_select ) ) {
98 $g_action_attach_tags_attach[] = tag_get( $f_tag_select );
103 global $g_action_attach_tags_attach, $g_action_attach_tags_create, $g_action_attach_tags_failed;
105 return true;
109 * Attaches all the tags to each bug in the group action.
110 * @param integer Bug ID
111 * @return boolean True if all tags attach properly
113 function action_attach_tags_process( $p_bug_id ) {
114 global $g_action_attach_tags_attach, $g_action_attach_tags_create;
116 $t_user_id = auth_get_current_user_id();
118 foreach( $g_action_attach_tags_create as $t_tag_row ) {
119 $t_tag_row['id'] = tag_create( $t_tag_row['name'], $t_user_id );
120 $g_action_attach_tags_attach[] = $t_tag_row;
122 $g_action_attach_tags_create = array();
124 foreach( $g_action_attach_tags_attach as $t_tag_row ) {
125 if ( !tag_bug_is_attached( $t_tag_row['id'], $p_bug_id ) ) {
126 tag_bug_attach( $t_tag_row['id'], $p_bug_id, $t_user_id );
130 return true;