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

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

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

' . $t_project_title . '

' . "\n";
ef5584
	    echo '

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

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

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

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

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

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