Blame Identity/Models/Html/Mantis/1.1.2-1.fc9/manage_config_email_page.php

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

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

' . $t_project_title . '

' . "\n";
d6e8d8
	    echo '

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

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

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

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

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

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