Fix #12795 : Handle the 'user_id' property of attachments
[mantis.git] / bug_actiongroup_add_note_inc.php
blobfc33f5ec2f8c6b8f7c8ccdad7f2a6a77b76d5290
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 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net
21 * @link http://www.mantisbt.org
23 * @uses access_api.php
24 * @uses bug_api.php
25 * @uses config_api.php
26 * @uses constant_inc.php
27 * @uses error_api.php
28 * @uses gpc_api.php
29 * @uses helper_api.php
30 * @uses lang_api.php
31 * @uses print_api.php
32 * @uses utility_api.php
35 if ( !defined( 'BUG_ACTIONGROUP_ADD_NOTE_INC_ALLOW' ) ) {
36 return;
39 require_api( 'access_api.php' );
40 require_api( 'bug_api.php' );
41 require_api( 'config_api.php' );
42 require_api( 'constant_inc.php' );
43 require_api( 'error_api.php' );
44 require_api( 'gpc_api.php' );
45 require_api( 'helper_api.php' );
46 require_api( 'lang_api.php' );
47 require_api( 'print_api.php' );
48 require_api( 'utility_api.php' );
50 /**
51 * Prints the title for the custom action page.
53 function action_add_note_print_title() {
54 echo '<tr class="form-title">';
55 echo '<td colspan="2">';
56 echo lang_get( 'add_bugnote_title' );
57 echo '</td></tr>';
60 /**
61 * Prints the field within the custom action form. This has an entry for
62 * every field the user need to supply + the submit button. The fields are
63 * added as rows in a table that is already created by the calling code.
64 * A row has two columns.
66 function action_add_note_print_fields() {
67 echo '<tr class="row-1"><th class="category">', lang_get( 'add_bugnote_title' ), '</th><td><textarea name="bugnote_text" cols="80" rows="10"></textarea></td></tr>';
69 <!-- View Status -->
70 <tr class="row-2">
71 <th class="category">
72 <?php echo lang_get( 'view_status' ) ?>
73 </th>
74 <td>
75 <?php
76 $t_default_state = config_get( 'default_bugnote_view_status' );
77 if ( access_has_project_level( config_get( 'set_view_status_threshold' ) ) ) { ?>
78 <select name="view_state">
79 <?php print_enum_string_option_list( 'view_state', $t_default_state ) ?>
80 </select>
81 <?php
82 } else {
83 echo get_enum_element( 'view_state', $t_default_state );
84 echo '<input type="hidden" name="view_state" value="', $t_default_state, '" />';
87 </td>
88 </tr>
89 <?php
90 echo '<tr><td colspan="2" class="center"><input type="submit" class="button" value="' . lang_get( 'add_bugnote_button' ) . ' " /></td></tr>';
93 /**
94 * Validates the action on the specified bug id.
96 * @return string|null On failure: the reason why the action could not be validated. On success: null.
98 function action_add_note_validate( $p_bug_id ) {
99 $f_bugnote_text = gpc_get_string( 'bugnote_text' );
101 if ( is_blank( $f_bugnote_text ) ) {
102 error_parameters( lang_get( 'bugnote' ) );
103 trigger_error( ERROR_EMPTY_FIELD, ERROR );
106 $t_add_bugnote_threshold = config_get( 'add_bugnote_threshold' );
107 $t_bug_id = $p_bug_id;
109 if ( bug_is_readonly( $t_bug_id ) ) {
110 return lang_get( 'actiongroup_error_issue_is_readonly' );
113 if ( !access_has_bug_level( $t_add_bugnote_threshold, $t_bug_id ) ) {
114 return lang_get( 'access_denied' );
117 return null;
121 * Executes the custom action on the specified bug id.
123 * @param $p_bug_id The bug id to execute the custom action on.
124 * @return null Previous validation ensures that this function doesn't fail. Therefore we can always return null to indicate no errors occurred.
126 function action_add_note_process( $p_bug_id ) {
127 $f_bugnote_text = gpc_get_string( 'bugnote_text' );
128 $f_view_state = gpc_get_int( 'view_state' );
129 bugnote_add ( $p_bug_id, $f_bugnote_text, '0:00', /* $p_private = */ $f_view_state != VS_PUBLIC );
130 return null;