1<?php 2# MantisBT - A PHP based bugtracking system 3 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. 8# 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. 13# 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/>. 16 17/** 18 * Manage configuration for email 19 * 20 * @package MantisBT 21 * @copyright Copyright 2000 - 2002 Kenzaburo Ito - kenito@300baud.org 22 * @copyright Copyright 2002 MantisBT Team - mantisbt-dev@lists.sourceforge.net 23 * @link http://www.mantisbt.org 24 * 25 * @uses core.php 26 * @uses access_api.php 27 * @uses authentication_api.php 28 * @uses config_api.php 29 * @uses constant_inc.php 30 * @uses current_user_api.php 31 * @uses form_api.php 32 * @uses gpc_api.php 33 * @uses helper_api.php 34 * @uses html_api.php 35 * @uses lang_api.php 36 * @uses print_api.php 37 */ 38 39require_once( 'core.php' ); 40require_api( 'access_api.php' ); 41require_api( 'authentication_api.php' ); 42require_api( 'config_api.php' ); 43require_api( 'constant_inc.php' ); 44require_api( 'current_user_api.php' ); 45require_api( 'form_api.php' ); 46require_api( 'gpc_api.php' ); 47require_api( 'helper_api.php' ); 48require_api( 'html_api.php' ); 49require_api( 'lang_api.php' ); 50require_api( 'print_api.php' ); 51 52form_security_validate( 'manage_config_email_set' ); 53 54auth_reauthenticate(); 55 56$t_can_change_level = min( config_get_access( 'notify_flags' ), config_get_access( 'default_notify_flags' ) ); 57access_ensure_project_level( $t_can_change_level ); 58 59$t_redirect_url = 'manage_config_email_page.php'; 60$t_project = helper_get_current_project(); 61 62$f_flags = gpc_get( 'flag', array() ); 63$f_thresholds = gpc_get( 'flag_threshold', array() ); 64$f_actions_access = gpc_get_int( 'notify_actions_access' ); 65 66layout_page_header( lang_get( 'manage_email_config' ), $t_redirect_url ); 67 68layout_page_begin(); 69 70$t_access = current_user_get_access_level(); 71$t_can_change_flags = $t_access >= config_get_access( 'notify_flags' ); 72$t_can_change_defaults = $t_access >= config_get_access( 'default_notify_flags' ); 73 74# build a list of the possible actions and flags 75$t_valid_actions = email_get_actions(); 76$t_valid_flags = array( 'reporter', 'handler', 'monitor' , 'bugnotes', 'category' ); 77 78# initialize the thresholds 79foreach( $t_valid_actions as $t_action ) { 80 $t_thresholds_min[$t_action] = NOBODY; 81 $t_thresholds_max[$t_action] = ANYBODY; 82} 83 84 85# parse flags and thresholds 86foreach( $f_flags as $t_flag_value ) { 87 list( $t_action, $t_flag ) = explode( ':', $t_flag_value ); 88 $t_flags[$t_action][$t_flag] = ON; 89} 90foreach( $f_thresholds as $t_threshold_value ) { 91 list( $t_action, $t_threshold ) = explode( ':', $t_threshold_value ); 92 if( $t_threshold < $t_thresholds_min[$t_action] ) { 93 $t_thresholds_min[$t_action] = $t_threshold; 94 } 95 if( $t_threshold > $t_thresholds_max[$t_action] ) { 96 $t_thresholds_max[$t_action] = $t_threshold; 97 } 98} 99 100# if we can set defaults, find them 101if( $t_can_change_defaults ) { 102 $t_first = true; 103 104 # for flags, assume they are true, unless one of the actions has them off 105 foreach ( $t_valid_flags as $t_flag ) { 106 $t_default_flags[$t_flag] = ON; 107 foreach ( $t_valid_actions as $t_action ) { 108 if( !isset( $t_flags[$t_action][$t_flag] ) ) { 109 unset( $t_default_flags[$t_flag] ); 110 } 111 } 112 } 113 # for thresholds, find the subset that matches all of the actions 114 $t_default_min = ANYBODY; 115 $t_default_max = NOBODY; 116 foreach ( $t_valid_actions as $t_action ) { 117 if( $t_default_max > $t_thresholds_max[$t_action] ) { 118 $t_default_max = $t_thresholds_max[$t_action]; 119 } 120 if( $t_default_min < $t_thresholds_min[$t_action] ) { 121 $t_default_min = $t_thresholds_min[$t_action]; 122 } 123 } 124 125 # We may end up with min = 100, max = 0 - make it 100, 100. 126 if( $t_default_max < $t_default_min ) { 127 $t_default_max = $t_default_min; 128 } 129 130 $t_default_flags['threshold_min'] = $t_default_min; 131 $t_default_flags['threshold_max'] = $t_default_max; 132 133 $t_existing_default_flags = config_get( 'default_notify_flags' ); 134 $t_existing_default_access = config_get_access( 'default_notify_flags' ); 135 if( ( $t_existing_default_flags != $t_default_flags ) 136 || ( $t_existing_default_access != $f_actions_access ) ) { # only set the flags if they are different 137 config_set( 'default_notify_flags', $t_default_flags, NO_USER, $t_project, $f_actions_access ); 138 } 139} else { 140 $t_default_flags = config_get( 'default_notify_flags' ); 141} 142 143# set the values for specific actions if different from the defaults 144$t_notify_flags = array(); 145foreach ( $t_valid_actions as $t_action ) { 146 $t_action_printed = false; 147 foreach ( $t_valid_flags as $t_flag ) { 148 if( !isset( $t_default_flags[$t_flag] ) ) { 149 $t_default_flags[$t_flag] = OFF; 150 } 151 152 # Always generate a complete set of flag to have a full override that can be compared 153 # against defaults later in the manage_config_email_page.php rendering. 154 $t_notify_flags[$t_action][$t_flag] = isset( $t_flags[$t_action][$t_flag] ) ? ON : OFF; 155 } 156 if( $t_default_flags['threshold_min'] <> $t_thresholds_min[$t_action] ) { 157 $t_notify_flags[$t_action]['threshold_min'] = $t_thresholds_min[$t_action]; 158 } 159 if( $t_default_flags['threshold_max'] <> $t_thresholds_max[$t_action] ) { 160 $t_notify_flags[$t_action]['threshold_max'] = $t_thresholds_max[$t_action]; 161 } 162} 163if( isset( $t_notify_flags ) ) { 164 $t_existing_flags = config_get( 'notify_flags' ); 165 $t_existing_access = config_get_access( 'notify_flags' ); 166 if( ( $t_existing_flags != $t_notify_flags ) 167 || ( $t_existing_access != $f_actions_access ) ) { # only set the flags if they are different 168 config_set( 'notify_flags', $t_notify_flags, NO_USER, $t_project, $f_actions_access ); 169 } 170} 171 172form_security_purge( 'manage_config_email_set' ); 173 174html_operation_successful( $t_redirect_url ); 175 176layout_page_end(); 177