Fix #11417: Allow EVENT_MENU_MAIN plugin events to return null
[mantis/radio.git] / manage_config_email_page.php
blob38afb338e32230f7144d59c9d901c621f069f769
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 core.php
24 * @uses authentication_api.php
25 * @uses config_api.php
26 * @uses constant_inc.php
27 * @uses current_user_api.php
28 * @uses form_api.php
29 * @uses helper_api.php
30 * @uses html_api.php
31 * @uses lang_api.php
32 * @uses print_api.php
33 * @uses project_api.php
34 * @uses string_api.php
37 require_once( 'core.php' );
38 require_api( 'authentication_api.php' );
39 require_api( 'config_api.php' );
40 require_api( 'constant_inc.php' );
41 require_api( 'current_user_api.php' );
42 require_api( 'form_api.php' );
43 require_api( 'helper_api.php' );
44 require_api( 'html_api.php' );
45 require_api( 'lang_api.php' );
46 require_api( 'print_api.php' );
47 require_api( 'project_api.php' );
48 require_api( 'string_api.php' );
50 auth_reauthenticate();
52 /**
53 * array_merge_recursive2()
55 * Similar to array_merge_recursive but keyed-valued are always overwritten.
56 * Priority goes to the 2nd array.
58 * @static yes
59 * @public yes
60 * @param $paArray1 array
61 * @param $paArray2 array
62 * @return array
64 function array_merge_recursive2($p_Array1, $p_Array2) {
65 if (!is_array($p_Array1) or !is_array($p_Array2)) {
66 return $p_Array2;
68 foreach ( $p_Array2 AS $t_Key2 => $t_Value2) {
69 $p_Array1[$t_Key2] = array_merge_recursive2( @$p_Array1[$t_Key2], $t_Value2);
71 return $p_Array1;
74 # --------------------
75 # get_notify_flag cloned from email_notify_flag
76 # Get the value associated with the specific action and flag.
77 # For example, you can get the value associated with notifying "admin"
78 # on action "new", i.e. notify administrators on new bugs which can be
79 # ON or OFF.
80 function get_notify_flag( $action, $flag ) {
81 global $t_notify_flags, $t_default_notify_flags;
83 $val = OFF;
84 if ( isset ( $t_notify_flags[$action][$flag] ) ) {
85 $val = $t_notify_flags[$action][$flag];
86 } else if ( isset ( $t_default_notify_flags[$flag] ) ) {
87 $val = $t_default_notify_flags[$flag];
89 return $val;
92 function colour_notify_flag ( $p_action, $p_flag ) {
93 global $t_notify_flags, $t_global_notify_flags, $t_file_notify_flags, $t_colour_project, $t_colour_global;
95 $t_file = isset( $t_file_notify_flags[$p_action][$p_flag] ) ? ( $t_file_notify_flags[$p_action][$p_flag] ? 1 : 0 ): -1;
96 $t_global = isset( $t_global_notify_flags[$p_action][$p_flag] ) ? ( $t_global_notify_flags[$p_action][$p_flag] ? 1 : 0 ): -1;
97 $t_project = isset( $t_notify_flags[$p_action][$p_flag] ) ? ( $t_notify_flags[$p_action][$p_flag] ? 1 : 0 ): -1;
99 $t_colour = '';
100 if ( $t_global >= 0 ) {
101 if ( $t_global != $t_file ) {
102 $t_colour = ' bgcolor="' . $t_colour_global . '" '; # all projects override
105 if ( $t_project >= 0 ) {
106 if ( $t_project != $t_global ) {
107 $t_colour = ' bgcolor="' . $t_colour_project . '" '; # project overrides
110 return $t_colour;
113 # Get the value associated with the specific action and flag.
114 function show_notify_flag( $p_action, $p_flag ) {
115 global $t_can_change_flags , $t_can_change_defaults;
116 $t_flag = get_notify_flag( $p_action, $p_flag );
117 if ( $t_can_change_flags || $t_can_change_defaults ) {
118 $t_flag_name = $p_action . ':' . $p_flag;
119 $t_set = $t_flag ? "checked=\"checked\"" : "";
120 return "<input type=\"checkbox\" name=\"flag[]\" value=\"$t_flag_name\" $t_set />";
121 } else {
122 return ( $t_flag ? '<img src="images/ok.gif" width="20" height="15" title="X" alt="X" />' : '&nbsp;' );
126 function colour_threshold_flag ( $p_access, $p_action ) {
127 global $t_notify_flags, $t_global_notify_flags, $t_file_notify_flags, $t_colour_project, $t_colour_global;
129 $t_file = ( $p_access >= $t_file_notify_flags[$p_action]['threshold_min'] )
130 && ( $p_access <= $t_file_notify_flags[$p_action]['threshold_max'] );
131 $t_global = ( $p_access >= $t_global_notify_flags[$p_action]['threshold_min'] )
132 && ( $p_access <= $t_global_notify_flags[$p_action]['threshold_max'] );
133 $t_project = ( $p_access >= $t_notify_flags[$p_action]['threshold_min'] )
134 && ( $p_access <= $t_notify_flags[$p_action]['threshold_max'] );
136 $t_colour = '';
137 if ( $t_global != $t_file ) {
138 $t_colour = ' bgcolor="' . $t_colour_global . '" '; # all projects override
140 if ( $t_project != $t_global ) {
141 $t_colour = ' bgcolor="' . $t_colour_project . '" '; # project overrides
143 return $t_colour;
146 function show_notify_threshold( $p_access, $p_action ) {
147 global $t_can_change_flags , $t_can_change_defaults;
148 $t_flag = ( $p_access >= get_notify_flag( $p_action, 'threshold_min' ) )
149 && ( $p_access <= get_notify_flag( $p_action, 'threshold_max' ) );
150 if ( $t_can_change_flags || $t_can_change_defaults ) {
151 $t_flag_name = $p_action . ':' . $p_access;
152 $t_set = $t_flag ? "checked=\"checked\"" : "";
153 return "<input type=\"checkbox\" name=\"flag_threshold[]\" value=\"$t_flag_name\" $t_set />";
154 } else {
155 return $t_flag ? '<img src="images/ok.gif" width="20" height="15" title="X" alt="X" />' : '&nbsp;';
159 function get_section_begin_for_email( $p_section_name ) {
160 global $t_project;
161 $t_access_levels = MantisEnum::getValues( config_get( 'access_levels_enum_string' ) );
162 echo '<table class="width100">';
163 echo '<tr><td class="form-title-caps" colspan="' . ( count( $t_access_levels ) + 7 ) . '">' . $p_section_name . '</td></tr>' . "\n";
164 echo '<tr><td class="form-title" width="30%" rowspan="2">' . lang_get( 'message' ) . '</td>';
165 echo'<td class="form-title" style="text-align:center" rowspan="2">&nbsp;' . lang_get( 'issue_reporter' ) . '&nbsp;</td>';
166 echo '<td class="form-title" style="text-align:center" rowspan="2">&nbsp;' . lang_get( 'issue_handler' ) . '&nbsp;</td>';
167 echo '<td class="form-title" style="text-align:center" rowspan="2">&nbsp;' . lang_get( 'users_monitoring_bug' ) . '&nbsp;</td>';
168 echo '<td class="form-title" style="text-align:center" rowspan="2">&nbsp;' . lang_get( 'users_added_bugnote' ) . '&nbsp;</td>';
169 echo '<td class="form-title" style="text-align:center" colspan="' . count( $t_access_levels ) . '">&nbsp;' . lang_get( 'access_levels' ) . '&nbsp;</td></tr><tr>';
171 foreach( $t_access_levels as $t_access_level ) {
172 echo '<td class="form-title" style="text-align:center">&nbsp;' . MantisEnum::getLabel( lang_get( 'access_levels_enum_string' ), $t_access_level ) . '&nbsp;</td>';
175 echo '</tr>' . "\n";
178 function get_capability_row_for_email( $p_caption, $p_message_type ) {
179 $t_access_levels = MantisEnum::getValues( config_get( 'access_levels_enum_string' ) );
181 echo '<tr ' . helper_alternate_class() . '><td>' . string_display( $p_caption ) . '</td>';
182 echo '<td class="center"' . colour_notify_flag( $p_message_type, 'reporter' ) . '>' . show_notify_flag( $p_message_type, 'reporter' ) . '</td>';
183 echo '<td class="center"' . colour_notify_flag( $p_message_type, 'handler' ) . '>' . show_notify_flag( $p_message_type, 'handler' ) . '</td>';
184 echo '<td class="center"' . colour_notify_flag( $p_message_type, 'monitor' ) . '>' . show_notify_flag( $p_message_type, 'monitor' ) . '</td>';
185 echo '<td class="center"' . colour_notify_flag( $p_message_type, 'bugnotes' ) . '>' . show_notify_flag( $p_message_type, 'bugnotes' ) . '</td>';
187 foreach( $t_access_levels as $t_access_level ) {
188 echo '<td class="center"' . colour_threshold_flag( $t_access_level, $p_message_type ) . '>' . show_notify_threshold( $t_access_level, $p_message_type ) . '</td>';
191 echo '</tr>' . "\n";
194 function get_section_end_for_email() {
195 echo '</table><br />' . "\n";
199 html_page_top( lang_get( 'manage_email_config' ) );
201 print_manage_menu( 'adm_permissions_report.php' );
202 print_manage_config_menu( 'manage_config_email_page.php' );
204 $t_access = current_user_get_access_level();
205 $t_project = helper_get_current_project();
207 $t_colour_project = config_get( 'colour_project');
208 $t_colour_global = config_get( 'colour_global');
210 # build a list of all of the actions
211 $t_actions = array( 'owner', 'reopened', 'deleted', 'bugnote' );
212 if( config_get( 'enable_sponsorship' ) == ON ) {
213 $t_actions[] = 'sponsor';
216 $t_actions[] = 'relationship';
218 $t_statuses = MantisEnum::getAssocArrayIndexedByValues( config_get( 'status_enum_string' ) );
219 foreach( $t_statuses as $t_status ) {
220 $t_actions[] = $t_status;
223 # build a composite of the status flags, exploding the defaults
224 $t_global_default_notify_flags = config_get( 'default_notify_flags', null, null, ALL_PROJECTS );
225 $t_global_notify_flags = array();
226 foreach ( $t_global_default_notify_flags as $t_flag => $t_value ) {
227 foreach ($t_actions as $t_action ) {
228 $t_global_notify_flags[$t_action][$t_flag] = $t_value;
231 $t_global_notify_flags = array_merge_recursive2( $t_global_notify_flags, config_get( 'notify_flags', null, null, ALL_PROJECTS ) );
233 $t_file_default_notify_flags = config_get_global( 'default_notify_flags' );
234 $t_file_notify_flags = array();
235 foreach ( $t_file_default_notify_flags as $t_flag => $t_value ) {
236 foreach ($t_actions as $t_action ) {
237 $t_file_notify_flags[$t_action][$t_flag] = $t_value;
240 $t_file_notify_flags = array_merge_recursive2( $t_file_notify_flags, config_get_global( 'notify_flags' ) );
242 $t_default_notify_flags = config_get( 'default_notify_flags' );
243 $t_notify_flags = array();
244 foreach ( $t_default_notify_flags as $t_flag => $t_value ) {
245 foreach ($t_actions as $t_action ) {
246 $t_notify_flags[$t_action][$t_flag] = $t_value;
249 $t_notify_flags = array_merge_recursive2( $t_notify_flags, config_get( 'notify_flags' ) );
251 $t_can_change_flags = $t_access >= config_get_access( 'notify_flags' );
252 $t_can_change_defaults = $t_access >= config_get_access( 'default_notify_flags' );
254 echo '<br /><br />';
256 # Email notifications
257 if( config_get( 'enable_email_notification' ) == ON ) {
259 if ( $t_can_change_flags || $t_can_change_defaults ) {
260 echo "<form name=\"mail_config_action\" method=\"post\" action=\"manage_config_email_set.php\">\n";
261 echo form_security_field( 'manage_config_email_set' );
264 if ( ALL_PROJECTS == $t_project ) {
265 $t_project_title = lang_get( 'config_all_projects' );
266 } else {
267 $t_project_title = sprintf( lang_get( 'config_project' ) , string_display( project_get_name( $t_project ) ) );
269 echo '<p class="bold">' . $t_project_title . '</p>' . "\n";
270 echo '<p>' . lang_get( 'colour_coding' ) . '<br />';
271 if ( ALL_PROJECTS <> $t_project ) {
272 echo '<span style="background-color:' . $t_colour_project . '">' . lang_get( 'colour_project' ) . '</span><br />';
274 echo '<span style="background-color:' . $t_colour_global . '">' . lang_get( 'colour_global' ) . '</span></p>';
276 get_section_begin_for_email( lang_get( 'email_notification' ) );
277 # get_capability_row_for_email( lang_get( 'email_on_new' ), 'new' ); # duplicate of status change to 'new'
278 get_capability_row_for_email( lang_get( 'email_on_assigned' ), 'owner' );
279 get_capability_row_for_email( lang_get( 'email_on_reopened' ), 'reopened' );
280 get_capability_row_for_email( lang_get( 'email_on_deleted' ), 'deleted' );
281 get_capability_row_for_email( lang_get( 'email_on_bugnote_added' ), 'bugnote' );
282 if( config_get( 'enable_sponsorship' ) == ON ) {
283 get_capability_row_for_email( lang_get( 'email_on_sponsorship_changed' ), 'sponsor' );
286 get_capability_row_for_email( lang_get( 'email_on_relationship_changed' ), 'relationship' );
288 $t_statuses = MantisEnum::getAssocArrayIndexedByValues( config_get( 'status_enum_string' ) );
289 foreach ( $t_statuses as $t_status => $t_label ) {
290 get_capability_row_for_email( lang_get( 'status_changed_to' ) . ' \'' . get_enum_element( 'status', $t_status ) . '\'', $t_label );
293 get_section_end_for_email();
295 if ( $t_can_change_flags || $t_can_change_defaults ) {
296 echo '<p>' . lang_get( 'notify_actions_change_access' );
297 echo '<select name="notify_actions_access">';
298 print_enum_string_option_list( 'access_levels', config_get_access( 'notify_flags' ) );
299 echo '</select> </p>';
301 echo "<input type=\"submit\" class=\"button\" value=\"" . lang_get( 'change_configuration' ) . "\" />\n";
303 echo "</form>\n";
305 echo "<div class=\"right\"><form name=\"mail_config_action\" method=\"post\" action=\"manage_config_revert.php\">\n";
306 echo form_security_field( 'manage_config_revert' );
307 echo "<input name=\"revert\" type=\"hidden\" value=\"notify_flags,default_notify_flags\"></input>";
308 echo "<input name=\"project\" type=\"hidden\" value=\"$t_project\"></input>";
309 echo "<input name=\"return\" type=\"hidden\" value=\"" . string_sanitize_url( $_SERVER['SCRIPT_NAME'] ) ."\"></input>";
310 echo "<input type=\"submit\" class=\"button\" value=\"";
311 if ( ALL_PROJECTS == $t_project ) {
312 echo lang_get( 'revert_to_system' );
313 } else {
314 echo lang_get( 'revert_to_all_project' );
316 echo "\" />\n";
317 echo "</form></div>\n";
322 html_page_bottom();