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/>.
19 * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
20 * @copyright Copyright (C) 2002 - 2011 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
27 * @uses helper_api.php
33 if ( !defined( 'BUG_ACTIONGROUP_ATTACH_TAGS_INC_ALLOW' ) ) {
37 require_api( 'access_api.php' );
38 require_api( 'authentication_api.php' );
39 require_api( 'config_api.php' );
40 require_api( 'gpc_api.php' );
41 require_api( 'helper_api.php' );
42 require_api( 'lang_api.php' );
43 require_api( 'print_api.php' );
44 require_api( 'tag_api.php' );
47 * Prints the title for the custom action page.
49 function action_attach_tags_print_title() {
50 echo '<tr class="form-title">';
51 echo '<td colspan="2">';
52 echo lang_get( 'tag_attach_long' );
57 * Prints the table and form for the Attach Tags group action page.
59 function action_attach_tags_print_fields() {
60 echo '<tr ',helper_alternate_class(),'><th class="category">',lang_get('tag_attach_long'),'</th><td>';
62 echo '<input type="submit" class="button" value="' . lang_get( 'tag_attach' ) . ' " /></td></tr>';
66 * Validates the Attach Tags group action.
67 * Checks if a user can attach the requested tags to a given bug.
68 * @param integer Bug ID
69 * @return string|null On failure: the reason for tags failing validation for the given bug. On success: null.
71 function action_attach_tags_validate( $p_bug_id ) {
72 global $g_action_attach_tags_tags;
73 global $g_action_attach_tags_attach;
74 global $g_action_attach_tags_create;
76 $t_can_attach = access_has_bug_level( config_get( 'tag_attach_threshold' ), $p_bug_id );
77 if( !$t_can_attach ) {
78 return lang_get( 'tag_attach_denied' );
81 if( !isset( $g_action_attach_tags_tags ) ) {
82 if( !isset( $g_action_attach_tags_attach ) ) {
83 $g_action_attach_tags_attach = array();
84 $g_action_attach_tags_create = array();
86 $g_action_attach_tags_tags = tag_parse_string( gpc_get_string( 'tag_string' ) );
87 foreach ( $g_action_attach_tags_tags as $t_tag_row ) {
88 if ( $t_tag_row['id'] == -1 ) {
89 $g_action_attach_tags_create[$t_tag_row['name']] = $t_tag_row;
90 } else if( $t_tag_row['id'] >= 0 ) {
91 $g_action_attach_tags_attach[$t_tag_row['name']] = $t_tag_row;
96 $t_can_create = access_has_bug_level( config_get( 'tag_create_threshold' ), $p_bug_id );
97 if( count( $g_action_attach_tags_create ) > 0 && !$t_can_create ) {
98 return lang_get( 'tag_create_denied' );
101 if( count( $g_action_attach_tags_create ) == 0 &&
102 count( $g_action_attach_tags_attach ) == 0 ) {
103 return lang_get( 'tag_none_attached' );
110 * Attaches all the tags to each bug in the group action.
111 * @param integer Bug ID
112 * @return null Previous validation ensures that this function doesn't fail. Therefore we can always return null to indicate no errors occurred.
114 function action_attach_tags_process( $p_bug_id ) {
115 global $g_action_attach_tags_attach, $g_action_attach_tags_create;
117 $t_user_id = auth_get_current_user_id();
119 foreach( $g_action_attach_tags_create as $t_tag_row ) {
120 $t_tag_row['id'] = tag_create( $t_tag_row['name'], $t_user_id );
121 $g_action_attach_tags_attach[] = $t_tag_row;
123 $g_action_attach_tags_create = array();
125 foreach( $g_action_attach_tags_attach as $t_tag_row ) {
126 if ( !tag_bug_is_attached( $t_tag_row['id'], $p_bug_id ) ) {
127 tag_bug_attach( $t_tag_row['id'], $p_bug_id, $t_user_id );