Fix #11417: Allow EVENT_MENU_MAIN plugin events to return null
[mantis/radio.git] / manage_config_email_set.php
blob09a0b7ef25ba29da09f618e3cf328a227923f6a1
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 access_api.php
25 * @uses authentication_api.php
26 * @uses config_api.php
27 * @uses constant_inc.php
28 * @uses current_user_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
37 require_once( 'core.php' );
38 require_api( 'access_api.php' );
39 require_api( 'authentication_api.php' );
40 require_api( 'config_api.php' );
41 require_api( 'constant_inc.php' );
42 require_api( 'current_user_api.php' );
43 require_api( 'form_api.php' );
44 require_api( 'gpc_api.php' );
45 require_api( 'helper_api.php' );
46 require_api( 'html_api.php' );
47 require_api( 'lang_api.php' );
48 require_api( 'print_api.php' );
50 form_security_validate('manage_config_email_set');
52 auth_reauthenticate();
54 $t_can_change_level = min( config_get_access( 'notify_flags' ), config_get_access( 'default_notify_flags' ) );
55 access_ensure_project_level( $t_can_change_level );
57 $t_redirect_url = 'manage_config_email_page.php';
58 $t_project = helper_get_current_project();
60 $f_flags = gpc_get( 'flag', array() );
61 $f_thresholds = gpc_get( 'flag_threshold', array() );
62 $f_actions_access = gpc_get_int( 'notify_actions_access' );
64 html_page_top( lang_get( 'manage_email_config' ), $t_redirect_url );
66 $t_access = current_user_get_access_level();
67 $t_can_change_flags = $t_access >= config_get_access( 'notify_flags' );
68 $t_can_change_defaults = $t_access >= config_get_access( 'default_notify_flags' );
70 # build a list of the possible actions and flags
71 $t_valid_actions = array( 'owner', 'reopened', 'deleted', 'bugnote' );
72 if( config_get( 'enable_sponsorship' ) == ON ) {
73 $t_valid_actions[] = 'sponsor';
76 $t_valid_actions[] = 'relationship';
78 $t_statuses = MantisEnum::getAssocArrayIndexedByValues( config_get( 'status_enum_string' ) );
79 ksort( $t_statuses );
80 reset( $t_statuses );
82 foreach( $t_statuses as $t_status => $t_label ) {
83 $t_valid_actions[] = $t_label;
85 $t_valid_flags = array( 'reporter', 'handler', 'monitor' , 'bugnotes' );
87 # initialize the thresholds
88 foreach( $t_valid_actions as $t_action ) {
89 $t_thresholds_min[$t_action] = NOBODY;
90 $t_thresholds_max[$t_action] = ANYBODY;
94 # parse flags and thresholds
95 foreach( $f_flags as $t_flag_value ) {
96 list( $t_action, $t_flag ) = explode( ':', $t_flag_value );
97 $t_flags[$t_action][$t_flag] = ON;
99 foreach( $f_thresholds as $t_threshold_value ) {
100 list( $t_action, $t_threshold ) = explode( ':', $t_threshold_value );
101 if ( $t_threshold < $t_thresholds_min[$t_action] ) {
102 $t_thresholds_min[$t_action] = $t_threshold;
104 if ( $t_threshold > $t_thresholds_max[$t_action] ) {
105 $t_thresholds_max[$t_action] = $t_threshold;
109 # if we can set defaults, find them
110 if ( $t_can_change_defaults ) {
111 $t_first = true;
113 # for flags, assume they are true, unless one of the actions has them off
114 foreach ( $t_valid_flags as $t_flag ) {
115 $t_default_flags[$t_flag] = ON;
116 foreach ( $t_valid_actions as $t_action ) {
117 if ( !isset( $t_flags[$t_action][$t_flag] ) ) {
118 unset( $t_default_flags[$t_flag] );
122 # for thresholds, find the subset that matches all of the actions
123 $t_default_min = ANYBODY;
124 $t_default_max = NOBODY;
125 foreach ( $t_valid_actions as $t_action ) {
126 if ( $t_default_max > $t_thresholds_max[$t_action] ) {
127 $t_default_max = $t_thresholds_max[$t_action];
129 if ( $t_default_min < $t_thresholds_min[$t_action] ) {
130 $t_default_min = $t_thresholds_min[$t_action];
133 $t_default_flags['threshold_min'] = $t_default_min;
134 $t_default_flags['threshold_max'] = $t_default_max;
136 $t_existing_default_flags = config_get( 'default_notify_flags' );
137 $t_existing_default_access = config_get_access( 'default_notify_flags' );
138 if ( ( $t_existing_default_flags != $t_default_flags )
139 || ( $t_existing_default_access != $f_actions_access ) ) { # only set the flags if they are different
140 config_set( 'default_notify_flags', $t_default_flags, NO_USER, $t_project, $f_actions_access );
142 } else {
143 $t_default_flags = config_get( 'default_notify_flags' );
146 # set the values for specific actions if different from the defaults
147 $t_notify_flags = array();
148 foreach ( $t_valid_actions as $t_action ) {
149 $t_action_printed = false;
150 foreach ( $t_valid_flags as $t_flag ) {
151 if ( !isset( $t_default_flags[$t_flag] ) ) {
152 $t_default_flags[$t_flag] = OFF;
154 if ( isset( $t_flags[$t_action][$t_flag] ) <> $t_default_flags[$t_flag] ) {
155 $t_notify_flags[$t_action][$t_flag] = isset( $t_flags[$t_action][$t_flag] ) ? ON : OFF;
158 if ( $t_default_flags['threshold_min'] <> $t_thresholds_min[$t_action] ) {
159 $t_notify_flags[$t_action]['threshold_min'] = $t_thresholds_min[$t_action];
161 if ( $t_default_flags['threshold_max'] <> $t_thresholds_max[$t_action] ) {
162 $t_notify_flags[$t_action]['threshold_max'] = $t_thresholds_max[$t_action];
165 if ( isset( $t_notify_flags ) ) {
166 $t_existing_flags = config_get( 'notify_flags' );
167 $t_existing_access = config_get_access( 'notify_flags' );
168 if ( ( $t_existing_flags != $t_notify_flags )
169 || ( $t_existing_access != $f_actions_access ) ) { # only set the flags if they are different
170 config_set( 'notify_flags', $t_notify_flags, NO_USER, $t_project, $f_actions_access );
174 form_security_purge('manage_config_email_set');
177 <br />
178 <div align="center">
179 <?php
180 echo lang_get( 'operation_successful' ) . '<br />';
181 print_bracket_link( $t_redirect_url, lang_get( 'proceed' ) );
183 </div>
185 <?php
186 html_page_bottom();