Blame Extras/Mantis/1.1.2-1.fc9/manage_config_email_page.php

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

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

' . $t_project_title . '

' . "\n";
4c79b5
	    echo '

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

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

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

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

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

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