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) 2002 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net
20 * @link http://www.mantisbt.org
23 * @uses access_api.php
24 * @uses authentication_api.php
26 * @uses config_api.php
27 * @uses constant_inc.php
31 * @uses helper_api.php
35 * @uses string_api.php
37 * @uses utility_api.php
43 require_once( 'core.php' );
44 require_api( 'access_api.php' );
45 require_api( 'authentication_api.php' );
46 require_api( 'bug_api.php' );
47 require_api( 'config_api.php' );
48 require_api( 'constant_inc.php' );
49 require_api( 'event_api.php' );
50 require_api( 'form_api.php' );
51 require_api( 'gpc_api.php' );
52 require_api( 'helper_api.php' );
53 require_api( 'html_api.php' );
54 require_api( 'lang_api.php' );
55 require_api( 'print_api.php' );
56 require_api( 'string_api.php' );
57 require_api( 'tag_api.php' );
58 require_api( 'utility_api.php' );
60 form_security_validate( 'tag_attach' );
62 $f_bug_id = gpc_get_int( 'bug_id' );
63 $f_tag_select = gpc_get_int( 'tag_select' );
64 $f_tag_string = gpc_get_string( 'tag_string' );
66 $t_user_id = auth_get_current_user_id();
68 access_ensure_bug_level( config_get( 'tag_attach_threshold' ), $f_bug_id, $t_user_id );
70 /** @todo The handling of tag strings which can include multiple tags should be moved
71 * to the APIs. This is to allow other clients of the API to support such
72 * functionality. The access level checks should also be moved to the API.
74 $t_tags = tag_parse_string( $f_tag_string );
75 $t_can_create = access_has_global_level( config_get( 'tag_create_threshold' ) );
77 $t_tags_create = array();
78 $t_tags_attach = array();
79 $t_tags_failed = array();
81 foreach ( $t_tags as $t_tag_row ) {
82 if ( -1 == $t_tag_row['id'] ) {
83 if ( $t_can_create ) {
84 $t_tags_create[] = $t_tag_row;
86 $t_tags_failed[] = $t_tag_row;
88 } else if ( -2 == $t_tag_row['id'] ) {
89 $t_tags_failed[] = $t_tag_row;
91 $t_tags_attach[] = $t_tag_row;
95 if ( 0 < $f_tag_select && tag_exists( $f_tag_select ) ) {
96 $t_tags_attach[] = tag_get( $f_tag_select );
99 // failed to attach at least one tag
100 if ( count( $t_tags_failed ) > 0 ) {
101 html_page_top( lang_get( 'tag_attach_long' ) . ' ' . bug_format_summary( $f_bug_id, SUMMARY_CAPTION
) );
104 <table
class="width75">
105 <tr
class="row-category">
106 <td colspan
="2"><?php
echo lang_get( 'tag_attach_failed' ) ?
></td
>
108 <tr
class="spacer"><td colspan
="2"></td
></tr
>
111 foreach( $t_tags_attach as $t_tag_row ) {
112 if ( !is_blank( $t_tag_string ) ) {
113 $t_tag_string .= config_get( 'tag_separator' );
115 $t_tag_string .= $t_tag_row['name'];
118 foreach( $t_tags_failed as $t_tag_row ) {
119 echo '<tr ',helper_alternate_class(),'>';
120 if ( -1 == $t_tag_row['id'] ) {
121 echo '<th class="category">', lang_get( 'tag_create_denied' ), '</th>';
122 } else if ( -2 == $t_tag_row['id'] ) {
123 echo '<th class="category">', lang_get( 'tag_invalid_name' ), '</th>';
125 echo '<td>', string_html_specialchars( $t_tag_row['name'] ), '</td></tr>';
127 if ( !is_blank( $t_tag_string ) ) {
128 $t_tag_string .= config_get( 'tag_separator' );
130 $t_tag_string .= $t_tag_row['name'];
133 <tr
class="spacer"><td colspan
="2"></td
></tr
>
134 <tr
<?php
echo helper_alternate_class() ?
>>
135 <th
class="category"><?php
echo lang_get( 'tag_attach_long' ) ?
></th
>
138 print_tag_attach_form( $f_bug_id, $t_tag_string );
145 // end failed to attach tag
147 foreach( $t_tags_create as $t_tag_row ) {
148 $t_tag_row['id'] = tag_create( $t_tag_row['name'], $t_user_id );
149 $t_tags_attach[] = $t_tag_row;
152 foreach( $t_tags_attach as $t_tag_row ) {
153 if ( !tag_bug_is_attached( $t_tag_row['id'], $f_bug_id ) ) {
154 tag_bug_attach( $t_tag_row['id'], $f_bug_id, $t_user_id );
158 event_signal( 'EVENT_TAG_ATTACHED', array( $f_bug_id, $t_tags_attach ) );
160 form_security_purge( 'tag_attach' );
162 print_successful_redirect_to_bug( $f_bug_id );