Blame Identity/Webenv/App/Mantis/1.1.2-1.fc9/manage_config_email_page.php

f2e824
f2e824
# Mantis - a php based bugtracking system
f2e824
f2e824
# Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
f2e824
# Copyright (C) 2002 - 2007  Mantis Team   - mantisbt-dev@lists.sourceforge.net
f2e824
f2e824
# Mantis is free software: you can redistribute it and/or modify
f2e824
# it under the terms of the GNU General Public License as published by
f2e824
# the Free Software Foundation, either version 2 of the License, or
f2e824
# (at your option) any later version.
f2e824
#
f2e824
# Mantis is distributed in the hope that it will be useful,
f2e824
# but WITHOUT ANY WARRANTY; without even the implied warranty of
f2e824
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f2e824
# GNU General Public License for more details.
f2e824
#
f2e824
# You should have received a copy of the GNU General Public License
f2e824
# along with Mantis.  If not, see <http://www.gnu.org/licenses/>.
f2e824
f2e824
	# --------------------------------------------------------
f2e824
	# $Id: manage_config_email_page.php,v 1.10.2.1 2007-10-13 22:33:23 giallu Exp $
f2e824
	# --------------------------------------------------------
f2e824
f2e824
	require_once( 'core.php' );
f2e824
f2e824
	$t_core_path = config_get( 'core_path' );
f2e824
	require_once( $t_core_path . 'email_api.php' );
f2e824
f2e824
	auth_reauthenticate();
f2e824
f2e824
/**
f2e824
 * array_merge_recursive2()
f2e824
 *
f2e824
 * Similar to array_merge_recursive but keyed-valued are always overwritten.
f2e824
 * Priority goes to the 2nd array.
f2e824
 *
f2e824
 * @static yes
f2e824
 * @public yes
f2e824
 * @param $paArray1 array
f2e824
 * @param $paArray2 array
f2e824
 * @return array
f2e824
 */
f2e824
    function array_merge_recursive2($p_Array1, $p_Array2) {
f2e824
        if (!is_array($p_Array1) or !is_array($p_Array2)) { 
f2e824
            return $p_Array2; 
f2e824
        }
f2e824
        foreach ( $p_Array2 AS $t_Key2 => $t_Value2) {
f2e824
            $p_Array1[$t_Key2] = array_merge_recursive2( @$p_Array1[$t_Key2], $t_Value2);
f2e824
        }
f2e824
        return $p_Array1;
f2e824
    }
f2e824
f2e824
	# --------------------
f2e824
	# get_notify_flag cloned from email_notify_flag
f2e824
	# Get the value associated with the specific action and flag.
f2e824
	# For example, you can get the value associated with notifying "admin"
f2e824
	# on action "new", i.e. notify administrators on new bugs which can be
f2e824
	# ON or OFF.
f2e824
	function get_notify_flag( $action, $flag ) {
f2e824
		global $t_notify_flags, $t_default_notify_flags;
f2e824
        
f2e824
		$val = OFF;
f2e824
		if ( isset ( $t_notify_flags[$action][$flag] ) ) {
f2e824
			$val = $t_notify_flags[$action][$flag];
f2e824
		} elseif ( isset ( $t_default_notify_flags[$flag] ) ) {
f2e824
			$val = $t_default_notify_flags[$flag];
f2e824
		} 
f2e824
		return $val;
f2e824
	}
f2e824
	
f2e824
    function colour_notify_flag ( $p_action, $p_flag ) {
f2e824
        global $t_notify_flags, $t_global_notify_flags, $t_file_notify_flags, $t_colour_project, $t_colour_global;
f2e824
        
f2e824
        $t_file = isset( $t_file_notify_flags[$p_action][$p_flag] ) ? ( $t_file_notify_flags[$p_action][$p_flag] ? 1 : 0 ): -1;
f2e824
        $t_global = isset( $t_global_notify_flags[$p_action][$p_flag] ) ? ( $t_global_notify_flags[$p_action][$p_flag]  ? 1 : 0 ): -1;
f2e824
        $t_project = isset( $t_notify_flags[$p_action][$p_flag] ) ? ( $t_notify_flags[$p_action][$p_flag]  ? 1 : 0 ): -1;
f2e824
           
f2e824
        $t_colour = '';
f2e824
        if ( $t_global >= 0 ) {
f2e824
            if ( $t_global != $t_file ) {
f2e824
                $t_colour = ' bgcolor="' . $t_colour_global . '" '; # all projects override
f2e824
            }
f2e824
        }
f2e824
        if ( $t_project >= 0 ) {
f2e824
            if ( $t_project != $t_global ) {
f2e824
                $t_colour = ' bgcolor="' . $t_colour_project . '" '; # project overrides
f2e824
            }
f2e824
        } 
f2e824
        return $t_colour;
f2e824
    }
f2e824
    
f2e824
    
f2e824
	# Get the value associated with the specific action and flag.
f2e824
	function show_notify_flag( $p_action, $p_flag ) {
f2e824
		global $t_can_change_flags , $t_can_change_defaults;
f2e824
		$t_flag = get_notify_flag( $p_action, $p_flag );
f2e824
		if ( $t_can_change_flags || $t_can_change_defaults ) {
f2e824
			$t_flag_name = $p_action . ':' . $p_flag;
f2e824
			$t_set = $t_flag ? "CHECKED" : "";
f2e824
			return "<input type=\"checkbox\" name=\"flag[]\" value=\"$t_flag_name\" $t_set />";
f2e824
		} else {
f2e824
			return ( $t_flag ? 'X' : ' ' );
f2e824
		}
f2e824
	}
f2e824
f2e824
    function colour_threshold_flag ( $p_access, $p_action ) {
f2e824
        global $t_notify_flags, $t_global_notify_flags, $t_file_notify_flags, $t_colour_project, $t_colour_global;
f2e824
        
f2e824
        $t_file = ( $p_access >= $t_file_notify_flags[$p_action]['threshold_min'] )
f2e824
			             && ( $p_access <= $t_file_notify_flags[$p_action]['threshold_max'] );
f2e824
        $t_global = ( $p_access >= $t_global_notify_flags[$p_action]['threshold_min'] )
f2e824
			             && ( $p_access <= $t_global_notify_flags[$p_action]['threshold_max'] );
f2e824
        $t_project = ( $p_access >= $t_notify_flags[$p_action]['threshold_min'] )
f2e824
			             && ( $p_access <= $t_notify_flags[$p_action]['threshold_max'] );
f2e824
           
f2e824
        $t_colour = '';
f2e824
        if ( $t_global != $t_file ) {
f2e824
            $t_colour = ' bgcolor="' . $t_colour_global . '" '; # all projects override
f2e824
        }
f2e824
        if ( $t_project != $t_global ) {
f2e824
            $t_colour = ' bgcolor="' . $t_colour_project . '" '; # project overrides
f2e824
        } 
f2e824
        return $t_colour;
f2e824
    }
f2e824
    
f2e824
	function show_notify_threshold( $p_access, $p_action ) {
f2e824
		global $t_can_change_flags , $t_can_change_defaults;
f2e824
		$t_flag = ( $p_access >= get_notify_flag( $p_action, 'threshold_min' ) )
f2e824
			&& ( $p_access <= get_notify_flag( $p_action, 'threshold_max' ) );
f2e824
		if ( $t_can_change_flags  || $t_can_change_defaults ) {
f2e824
			$t_flag_name = $p_action . ':' . $p_access;
f2e824
			$t_set = $t_flag ? "CHECKED" : "";
f2e824
			return "<input type=\"checkbox\" name=\"flag_threshold[]\" value=\"$t_flag_name\" $t_set />";
f2e824
		} else {
f2e824
			return $t_flag ? 'X' : ' ';
f2e824
		}
f2e824
	}
f2e824
f2e824
	function get_section_begin_for_email( $p_section_name ) {
f2e824
		global $t_project;
f2e824
		$t_access_levels = explode_enum_string( config_get( 'access_levels_enum_string' ) );
f2e824
		echo '';
f2e824
		echo '' . strtoupper( $p_section_name ) . '' . "\n";
f2e824
		echo '' . lang_get( 'message' ) . '';
f2e824
		echo' ' . lang_get( 'issue_reporter' ) . ' ';
f2e824
		echo ' ' . lang_get( 'issue_handler' ) . ' ';
f2e824
		echo ' ' . lang_get( 'users_monitoring_bug' ) . ' ';
f2e824
		echo ' ' . lang_get( 'users_added_bugnote' ) . ' ';
f2e824
		echo ' ' . lang_get( 'access_levels' ) . ' ';
f2e824
		foreach( $t_access_levels as $t_access_level ) {
f2e824
			$t_entry_array = explode_enum_arr( $t_access_level );
f2e824
			echo ' ' . get_enum_to_string( lang_get( 'access_levels_enum_string' ), $t_entry_array[0] ) . ' ';
f2e824
		}
f2e824
		echo '' . "\n";
f2e824
	}
f2e824
f2e824
	function get_capability_row_for_email( $p_caption, $p_message_type ) {
f2e824
		$t_access_levels = explode_enum_string( config_get( 'access_levels_enum_string' ) );
f2e824
f2e824
		echo '' . string_display( $p_caption ) . '';
f2e824
		echo '' . show_notify_flag( $p_message_type, 'reporter' )  . '';
f2e824
		echo '' . show_notify_flag( $p_message_type, 'handler' ) . '';
f2e824
		echo '' . show_notify_flag( $p_message_type, 'monitor' ) . '';
f2e824
		echo '' . show_notify_flag( $p_message_type, 'bugnotes' ) . '';
f2e824
f2e824
		foreach( $t_access_levels as $t_access_level ) {
f2e824
			$t_entry_array = explode_enum_arr( $t_access_level );
f2e824
			echo '' . show_notify_threshold( (int)$t_entry_array[0], $p_message_type ) . '';
f2e824
		}
f2e824
		echo '' . "\n";
f2e824
	}
f2e824
f2e824
	function get_section_end_for_email() {
f2e824
		echo '
' . "\n";
f2e824
	}
f2e824
f2e824
f2e824
	html_page_top1( lang_get( 'manage_email_config' ) );
f2e824
	html_page_top2();
f2e824
f2e824
	print_manage_menu( 'adm_permissions_report.php' );
f2e824
	print_manage_config_menu( 'manage_config_email_page.php' );
f2e824
f2e824
	$t_access = current_user_get_access_level();
f2e824
	$t_project = helper_get_current_project();
f2e824
	
f2e824
	$t_colour_project = config_get( 'colour_project');
f2e824
	$t_colour_global = config_get( 'colour_global');
f2e824
	
f2e824
	# build a list of all of the actions
f2e824
	$t_actions = array( 'owner', 'reopened', 'deleted', 'bugnote' );
f2e824
	if( config_get( 'enable_sponsorship' ) == ON ) {
f2e824
		$t_actions[] = 'sponsor';
f2e824
	}
f2e824
	if( config_get( 'enable_relationship' ) == ON ) {
f2e824
		$t_actions[] = 'relationship';
f2e824
	}
f2e824
	$t_statuses = get_enum_to_array( config_get( 'status_enum_string' ) );
f2e824
	foreach( $t_statuses as $t_status ) {
f2e824
		$t_actions[] =  $t_status;
f2e824
	}
f2e824
	
f2e824
	# build a composite of the status flags, exploding the defaults
f2e824
	$t_global_default_notify_flags = config_get( 'default_notify_flags', null, null, ALL_PROJECTS );
f2e824
	$t_global_notify_flags = array();
f2e824
	foreach ( $t_global_default_notify_flags as $t_flag => $t_value ) {
f2e824
	   foreach ($t_actions as $t_action ) {
f2e824
	       $t_global_notify_flags[$t_action][$t_flag] = $t_value;
f2e824
	   }
f2e824
	}
f2e824
	$t_global_notify_flags = array_merge_recursive2( $t_global_notify_flags, config_get( 'notify_flags', null, null, ALL_PROJECTS ) );
f2e824
f2e824
	$t_file_default_notify_flags = config_get_global( 'default_notify_flags' );
f2e824
	$t_file_notify_flags = array();
f2e824
	foreach ( $t_file_default_notify_flags as $t_flag => $t_value ) {
f2e824
	   foreach ($t_actions as $t_action ) {
f2e824
	       $t_file_notify_flags[$t_action][$t_flag] = $t_value;
f2e824
	   }
f2e824
	}
f2e824
	$t_file_notify_flags = array_merge_recursive2( $t_file_notify_flags, config_get_global( 'notify_flags' ) );
f2e824
	
f2e824
	$t_default_notify_flags = config_get( 'default_notify_flags' );
f2e824
	$t_notify_flags = array();
f2e824
	foreach ( $t_default_notify_flags as $t_flag => $t_value ) {
f2e824
	   foreach ($t_actions as $t_action ) {
f2e824
	       $t_notify_flags[$t_action][$t_flag] = $t_value;
f2e824
	   }
f2e824
	}
f2e824
	$t_notify_flags = array_merge_recursive2( $t_notify_flags, config_get( 'notify_flags' ) );
f2e824
f2e824
	$t_can_change_flags = $t_access >= config_get_access( 'notify_flags' );
f2e824
	$t_can_change_defaults = $t_access >= config_get_access( 'default_notify_flags' );
f2e824
f2e824
	echo '

';
f2e824
f2e824
	# Email notifications
f2e824
	if( config_get( 'enable_email_notification' ) == ON ) {
f2e824
f2e824
		if ( $t_can_change_flags  || $t_can_change_defaults ) {
f2e824
			echo "<form name=\"mail_config_action\" method=\"post\" action=\"manage_config_email_set.php\">\n";
f2e824
			echo form_security_field( 'manage_config_email_set' );
f2e824
		}
f2e824
f2e824
	    if ( ALL_PROJECTS == $t_project ) {
f2e824
	        $t_project_title = lang_get( 'config_all_projects' );
f2e824
	    } else {
f2e824
	        $t_project_title = sprintf( lang_get( 'config_project' ) , string_display( project_get_name( $t_project ) ) );
f2e824
	    }
f2e824
	    echo '

' . $t_project_title . '

' . "\n";
f2e824
	    echo '

' . lang_get( 'colour_coding' ) . '
';

f2e824
	    if ( ALL_PROJECTS <> $t_project ) {
f2e824
	        echo '' . lang_get( 'colour_project' ) .'
';
f2e824
	    }
f2e824
	    echo '' . lang_get( 'colour_global' ) . '

';
f2e824
f2e824
		get_section_begin_for_email( lang_get( 'email_notification' ) );
f2e824
#		get_capability_row_for_email( lang_get( 'email_on_new' ), 'new' );  # duplicate of status change to 'new'
f2e824
		get_capability_row_for_email( lang_get( 'email_on_assigned' ), 'owner' );
f2e824
		get_capability_row_for_email( lang_get( 'email_on_reopened' ), 'reopened' );
f2e824
		get_capability_row_for_email( lang_get( 'email_on_deleted' ), 'deleted' );
f2e824
		get_capability_row_for_email( lang_get( 'email_on_bugnote_added' ), 'bugnote' );
f2e824
		if( config_get( 'enable_sponsorship' ) == ON ) {
f2e824
			get_capability_row_for_email( lang_get( 'email_on_sponsorship_changed' ), 'sponsor' );
f2e824
		}
f2e824
		if( config_get( 'enable_relationship' ) == ON ) {
f2e824
			get_capability_row_for_email( lang_get( 'email_on_relationship_changed' ), 'relationship' );
f2e824
		}
f2e824
		$t_statuses = explode_enum_string( config_get( 'status_enum_string' ) );
f2e824
		foreach( $t_statuses as $t_status ) {
f2e824
			list( $t_state, $t_label ) = explode_enum_arr( $t_status );
f2e824
			get_capability_row_for_email( lang_get( 'status_changed_to' ) . ' \'' . get_enum_element( 'status', $t_state ) . '\'', $t_label );
f2e824
		}
f2e824
f2e824
		get_section_end_for_email();
f2e824
f2e824
		if ( $t_can_change_flags  || $t_can_change_defaults ) {
f2e824
			echo '

' . lang_get( 'notify_actions_change_access' ) . ':';

f2e824
			echo '<select name="notify_actions_access">';
f2e824
			print_enum_string_option_list( 'access_levels', config_get_access( 'notify_flags' ) );
f2e824
			echo '</select> 

';
f2e824
f2e824
			echo "<input type=\"submit\" class=\"button\" value=\"" . lang_get( 'change_configuration' ) . "\" />\n";
f2e824
f2e824
			echo "</form>\n";
f2e824
			
f2e824
			echo "
<form name=\"mail_config_action\" method=\"post\" action=\"manage_config_revert.php\">\n";
f2e824
			echo form_security_field( 'manage_config_revert' );
f2e824
			echo "<input name=\"revert\" type=\"hidden\" value=\"notify_flags,default_notify_flags\"></input>";
f2e824
			echo "<input name=\"project\" type=\"hidden\" value=\"$t_project\"></input>";
f2e824
			echo "<input name=\"return\" type=\"hidden\" value=\"" . $_SERVER['PHP_SELF'] ."\"></input>";
f2e824
			echo "
f2e824
			if ( ALL_PROJECTS == $t_project ) {
f2e824
                echo lang_get( 'revert_to_system' );
f2e824
            } else {
f2e824
                echo lang_get( 'revert_to_all_project' );
f2e824
            } 
f2e824
			echo "\" />\n";
f2e824
			echo "</form>\n";
f2e824
		}
f2e824
f2e824
	}
f2e824
f2e824
	html_page_bottom1( __FILE__ );
f2e824
?>