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) 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
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
31 * @uses helper_api.php
40 require_once( 'core.php' );
41 require_api( 'access_api.php' );
42 require_api( 'authentication_api.php' );
43 require_api( 'config_api.php' );
44 require_api( 'constant_inc.php' );
45 require_api( 'current_user_api.php' );
46 require_api( 'form_api.php' );
47 require_api( 'gpc_api.php' );
48 require_api( 'helper_api.php' );
49 require_api( 'html_api.php' );
50 require_api( 'lang_api.php' );
51 require_api( 'print_api.php' );
53 form_security_validate('manage_config_email_set');
55 auth_reauthenticate();
57 $t_can_change_level = min( config_get_access( 'notify_flags' ), config_get_access( 'default_notify_flags' ) );
58 access_ensure_project_level( $t_can_change_level );
60 $t_redirect_url = 'manage_config_email_page.php';
61 $t_project = helper_get_current_project();
63 $f_flags = gpc_get( 'flag', array() );
64 $f_thresholds = gpc_get( 'flag_threshold', array() );
65 $f_actions_access = gpc_get_int( 'notify_actions_access' );
67 html_page_top( lang_get( 'manage_email_config' ), $t_redirect_url );
69 $t_access = current_user_get_access_level();
70 $t_can_change_flags = $t_access >= config_get_access( 'notify_flags' );
71 $t_can_change_defaults = $t_access >= config_get_access( 'default_notify_flags' );
73 # build a list of the possible actions and flags
74 $t_valid_actions = array( 'owner', 'reopened', 'deleted', 'bugnote' );
75 if( config_get( 'enable_sponsorship' ) == ON
) {
76 $t_valid_actions[] = 'sponsor';
79 $t_valid_actions[] = 'relationship';
81 $t_statuses = MantisEnum
::getAssocArrayIndexedByValues( config_get( 'status_enum_string' ) );
85 foreach( $t_statuses as $t_status => $t_label ) {
86 $t_valid_actions[] = $t_label;
88 $t_valid_flags = array( 'reporter', 'handler', 'monitor' , 'bugnotes' );
90 # initialize the thresholds
91 foreach( $t_valid_actions as $t_action ) {
92 $t_thresholds_min[$t_action] = NOBODY
;
93 $t_thresholds_max[$t_action] = ANYBODY
;
97 # parse flags and thresholds
98 foreach( $f_flags as $t_flag_value ) {
99 list( $t_action, $t_flag ) = explode( ':', $t_flag_value );
100 $t_flags[$t_action][$t_flag] = ON
;
102 foreach( $f_thresholds as $t_threshold_value ) {
103 list( $t_action, $t_threshold ) = explode( ':', $t_threshold_value );
104 if ( $t_threshold < $t_thresholds_min[$t_action] ) {
105 $t_thresholds_min[$t_action] = $t_threshold;
107 if ( $t_threshold > $t_thresholds_max[$t_action] ) {
108 $t_thresholds_max[$t_action] = $t_threshold;
112 # if we can set defaults, find them
113 if ( $t_can_change_defaults ) {
116 # for flags, assume they are true, unless one of the actions has them off
117 foreach ( $t_valid_flags as $t_flag ) {
118 $t_default_flags[$t_flag] = ON
;
119 foreach ( $t_valid_actions as $t_action ) {
120 if ( !isset( $t_flags[$t_action][$t_flag] ) ) {
121 unset( $t_default_flags[$t_flag] );
125 # for thresholds, find the subset that matches all of the actions
126 $t_default_min = ANYBODY
;
127 $t_default_max = NOBODY
;
128 foreach ( $t_valid_actions as $t_action ) {
129 if ( $t_default_max > $t_thresholds_max[$t_action] ) {
130 $t_default_max = $t_thresholds_max[$t_action];
132 if ( $t_default_min < $t_thresholds_min[$t_action] ) {
133 $t_default_min = $t_thresholds_min[$t_action];
136 $t_default_flags['threshold_min'] = $t_default_min;
137 $t_default_flags['threshold_max'] = $t_default_max;
139 $t_existing_default_flags = config_get( 'default_notify_flags' );
140 $t_existing_default_access = config_get_access( 'default_notify_flags' );
141 if ( ( $t_existing_default_flags != $t_default_flags )
142 ||
( $t_existing_default_access != $f_actions_access ) ) { # only set the flags if they are different
143 config_set( 'default_notify_flags', $t_default_flags, NO_USER
, $t_project, $f_actions_access );
146 $t_default_flags = config_get( 'default_notify_flags' );
149 # set the values for specific actions if different from the defaults
150 $t_notify_flags = array();
151 foreach ( $t_valid_actions as $t_action ) {
152 $t_action_printed = false;
153 foreach ( $t_valid_flags as $t_flag ) {
154 if ( !isset( $t_default_flags[$t_flag] ) ) {
155 $t_default_flags[$t_flag] = OFF
;
157 if ( isset( $t_flags[$t_action][$t_flag] ) <> $t_default_flags[$t_flag] ) {
158 $t_notify_flags[$t_action][$t_flag] = isset( $t_flags[$t_action][$t_flag] ) ? ON
: OFF
;
161 if ( $t_default_flags['threshold_min'] <> $t_thresholds_min[$t_action] ) {
162 $t_notify_flags[$t_action]['threshold_min'] = $t_thresholds_min[$t_action];
164 if ( $t_default_flags['threshold_max'] <> $t_thresholds_max[$t_action] ) {
165 $t_notify_flags[$t_action]['threshold_max'] = $t_thresholds_max[$t_action];
168 if ( isset( $t_notify_flags ) ) {
169 $t_existing_flags = config_get( 'notify_flags' );
170 $t_existing_access = config_get_access( 'notify_flags' );
171 if ( ( $t_existing_flags != $t_notify_flags )
172 ||
( $t_existing_access != $f_actions_access ) ) { # only set the flags if they are different
173 config_set( 'notify_flags', $t_notify_flags, NO_USER
, $t_project, $f_actions_access );
177 form_security_purge('manage_config_email_set');
183 echo lang_get( 'operation_successful' ) . '<br />';
184 print_bracket_link( $t_redirect_url, lang_get( 'proceed' ) );