Fix #11417: Allow EVENT_MENU_MAIN plugin events to return null
[mantis/radio.git] / tag_attach.php
blob954be812bbf516ef0fd9da2f7e442e997260a985
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) 2002 - 2010 MantisBT Team - mantisbt-dev@lists.sourceforge.net
20 * @link http://www.mantisbt.org
22 * @uses core.php
23 * @uses access_api.php
24 * @uses authentication_api.php
25 * @uses bug_api.php
26 * @uses config_api.php
27 * @uses constant_inc.php
28 * @uses event_api.php
29 * @uses form_api.php
30 * @uses gpc_api.php
31 * @uses helper_api.php
32 * @uses html_api.php
33 * @uses lang_api.php
34 * @uses print_api.php
35 * @uses string_api.php
36 * @uses tag_api.php
37 * @uses utility_api.php
40 require_once( 'core.php' );
41 require_api( 'access_api.php' );
42 require_api( 'authentication_api.php' );
43 require_api( 'bug_api.php' );
44 require_api( 'config_api.php' );
45 require_api( 'constant_inc.php' );
46 require_api( 'event_api.php' );
47 require_api( 'form_api.php' );
48 require_api( 'gpc_api.php' );
49 require_api( 'helper_api.php' );
50 require_api( 'html_api.php' );
51 require_api( 'lang_api.php' );
52 require_api( 'print_api.php' );
53 require_api( 'string_api.php' );
54 require_api( 'tag_api.php' );
55 require_api( 'utility_api.php' );
57 form_security_validate( 'tag_attach' );
59 $f_bug_id = gpc_get_int( 'bug_id' );
60 $f_tag_select = gpc_get_int( 'tag_select' );
61 $f_tag_string = gpc_get_string( 'tag_string' );
63 $t_user_id = auth_get_current_user_id();
65 access_ensure_bug_level( config_get( 'tag_attach_threshold' ), $f_bug_id, $t_user_id );
67 /** @todo The handling of tag strings which can include multiple tags should be moved
68 * to the APIs. This is to allow other clients of the API to support such
69 * functionality. The access level checks should also be moved to the API.
71 $t_tags = tag_parse_string( $f_tag_string );
72 $t_can_create = access_has_global_level( config_get( 'tag_create_threshold' ) );
74 $t_tags_create = array();
75 $t_tags_attach = array();
76 $t_tags_failed = array();
78 foreach ( $t_tags as $t_tag_row ) {
79 if ( -1 == $t_tag_row['id'] ) {
80 if ( $t_can_create ) {
81 $t_tags_create[] = $t_tag_row;
82 } else {
83 $t_tags_failed[] = $t_tag_row;
85 } else if ( -2 == $t_tag_row['id'] ) {
86 $t_tags_failed[] = $t_tag_row;
87 } else {
88 $t_tags_attach[] = $t_tag_row;
92 if ( 0 < $f_tag_select && tag_exists( $f_tag_select ) ) {
93 $t_tags_attach[] = tag_get( $f_tag_select );
96 // failed to attach at least one tag
97 if ( count( $t_tags_failed ) > 0 ) {
98 html_page_top( lang_get( 'tag_attach_long' ) . ' ' . bug_format_summary( $f_bug_id, SUMMARY_CAPTION ) );
100 <br/>
101 <table class="width75" align="center">
102 <tr class="row-category">
103 <td colspan="2"><?php echo lang_get( 'tag_attach_failed' ) ?></td>
104 </tr>
105 <tr class="spacer"><td colspan="2"></td></tr>
106 <?php
107 $t_tag_string = "";
108 foreach( $t_tags_attach as $t_tag_row ) {
109 if ( !is_blank( $t_tag_string ) ) {
110 $t_tag_string .= config_get( 'tag_separator' );
112 $t_tag_string .= $t_tag_row['name'];
115 foreach( $t_tags_failed as $t_tag_row ) {
116 echo '<tr ',helper_alternate_class(),'>';
117 if ( -1 == $t_tag_row['id'] ) {
118 echo '<td class="category">', lang_get( 'tag_create_denied' ), '</td>';
119 } else if ( -2 == $t_tag_row['id'] ) {
120 echo '<td class="category">', lang_get( 'tag_invalid_name' ), '</td>';
122 echo '<td>', string_html_specialchars( $t_tag_row['name'] ), '</td></tr>';
124 if ( !is_blank( $t_tag_string ) ) {
125 $t_tag_string .= config_get( 'tag_separator' );
127 $t_tag_string .= $t_tag_row['name'];
130 <tr class="spacer"><td colspan="2"></td></tr>
131 <tr <?php echo helper_alternate_class() ?>>
132 <td class="category"><?php echo lang_get( 'tag_attach_long' ) ?></td>
133 <td>
134 <?php
135 print_tag_attach_form( $f_bug_id, $t_tag_string );
137 </td>
138 </tr>
139 </table>
140 <?php
141 html_page_bottom();
142 // end failed to attach tag
143 } else {
144 foreach( $t_tags_create as $t_tag_row ) {
145 $t_tag_row['id'] = tag_create( $t_tag_row['name'], $t_user_id );
146 $t_tags_attach[] = $t_tag_row;
149 foreach( $t_tags_attach as $t_tag_row ) {
150 if ( !tag_bug_is_attached( $t_tag_row['id'], $f_bug_id ) ) {
151 tag_bug_attach( $t_tag_row['id'], $f_bug_id, $t_user_id );
155 event_signal( 'EVENT_TAG_ATTACHED', array( $f_bug_id, $t_tags_attach ) );
157 form_security_purge( 'tag_attach' );
159 print_successful_redirect_to_bug( $f_bug_id );