From c39518ff6a5afc540892ba728b67dd775beb66f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kre=C5=A1imir=20Kroflin?= Date: Thu, 22 Mar 2012 10:32:55 +0100 Subject: [PATCH] Added short info of changed items in the e-mail notifications --- config_defaults_inc.php | 11 ++++ core/email_api.php | 149 +++++++++++++++++++++++++++++++++------------ lang/strings_english.txt | 2 + 3 files changed, 122 insertions(+), 40 deletions(-) diff --git a/config_defaults_inc.php b/config_defaults_inc.php index 8c5df3d..a2d1a86 100644 --- a/config_defaults_inc.php +++ b/config_defaults_inc.php @@ -554,10 +554,21 @@ */ $g_email_separator2 = str_pad('', 70, '-'); /** + * email separator + * @global string $g_email_separator3_char + */ + $g_email_separator3_char = "#"; + /** * email separator and padding * @global int $g_email_padding_length */ $g_email_padding_length = 28; + /** + * Specifies whether bug details should be sent as an e-mail signature or as + * normal text + * @global boolean $g_email_bug_details_as_signature + */ + $g_email_bug_details_as_signature = ON; /*************************** * MantisBT Version String * diff --git a/core/email_api.php b/core/email_api.php index 59bb51c..44d7211 100644 --- a/core/email_api.php +++ b/core/email_api.php @@ -1206,10 +1206,15 @@ function email_format_bug_message( $p_visible_bug_data ) { $t_email_separator1 = config_get( 'email_separator1' ); $t_email_separator2 = config_get( 'email_separator2' ); + $t_email_separator3_char = config_get( 'email_separator3_char' ); $t_email_padding_length = config_get( 'email_padding_length' ); + $t_email_bug_details_as_signature = config_get( 'email_bug_details_as_signature' ); + $t_status = $p_visible_bug_data['email_status']; + $t_summary_for_date = $p_visible_bug_data['email_last_modified']; + $p_visible_bug_data['email_date_submitted'] = date( $t_complete_date_format, $p_visible_bug_data['email_date_submitted'] ); $p_visible_bug_data['email_last_modified'] = date( $t_complete_date_format, $p_visible_bug_data['email_last_modified'] ); @@ -1218,7 +1223,19 @@ function email_format_bug_message( $p_visible_bug_data ) { $p_visible_bug_data['email_priority'] = get_enum_element( 'priority', $p_visible_bug_data['email_priority'] ); $p_visible_bug_data['email_reproducibility'] = get_enum_element( 'reproducibility', $p_visible_bug_data['email_reproducibility'] ); - $t_message = $t_email_separator1 . " \n"; + # format changed + $t_message .= "\n"; + $t_message .= utf8_str_pad( "{$t_email_separator3_char}{$t_email_separator3_char}{$t_email_separator3_char} " . lang_get( 'email_changed' ) . " ", 70, $t_email_separator3_char, STR_PAD_RIGHT ); + $t_message .= "\n"; + $t_message .= email_format_bugnotes( $p_visible_bug_data, $t_summary_for_date ); + $t_message .= email_format_history( $p_visible_bug_data, $t_summary_for_date ); + + # format details + if( $t_email_bug_details_as_signature == ON || $t_email_bug_details_as_signature == AUTO ) { + $t_message .= "-- \n"; + } + $t_message .= utf8_str_pad( "{$t_email_separator3_char}{$t_email_separator3_char}{$t_email_separator3_char} " . lang_get( 'email_details' ) . " ", 70, $t_email_separator3_char, STR_PAD_RIGHT ); + $t_message .= "\n"; if( isset( $p_visible_bug_data['email_bug_view_url'] ) ) { $t_message .= $p_visible_bug_data['email_bug_view_url'] . " \n"; @@ -1294,47 +1311,10 @@ function email_format_bug_message( $p_visible_bug_data ) { $t_message .= $t_email_separator1 . " \n\n"; # format bugnotes - foreach( $p_visible_bug_data['bugnotes'] as $t_bugnote ) { - $t_last_modified = date( $t_normal_date_format, $t_bugnote->last_modified ); - - $t_formatted_bugnote_id = bugnote_format_id( $t_bugnote->id ); - $t_bugnote_link = string_process_bugnote_link( config_get( 'bugnote_link_tag' ) . $t_bugnote->id, false, false, true ); - - if( $t_bugnote->time_tracking > 0 ) { - $t_time_tracking = ' ' . lang_get( 'time_tracking' ) . ' ' . db_minutes_to_hhmm( $t_bugnote->time_tracking ) . "\n"; - } else { - $t_time_tracking = ''; - } - - if( user_exists( $t_bugnote->reporter_id ) ) { - $t_access_level = access_get_project_level( $p_visible_bug_data['email_project_id'] , $t_bugnote->reporter_id ); - $t_access_level_string = ' (' . get_enum_element( 'access_levels', $t_access_level ) . ') - '; - } else { - $t_access_level_string = ''; - } - - $t_string = ' (' . $t_formatted_bugnote_id . ') ' . user_get_name( $t_bugnote->reporter_id ) . $t_access_level_string . $t_last_modified . "\n" . $t_time_tracking . ' ' . $t_bugnote_link; - - $t_message .= $t_email_separator2 . " \n"; - $t_message .= $t_string . " \n"; - $t_message .= $t_email_separator2 . " \n"; - $t_message .= $t_bugnote->note . " \n\n"; - } + $t_message .= email_format_bugnotes( $p_visible_bug_data ); # format history - if( array_key_exists( 'history', $p_visible_bug_data ) ) { - $t_message .= lang_get( 'bug_history' ) . " \n"; - $t_message .= utf8_str_pad( lang_get( 'date_modified' ), 17 ) . utf8_str_pad( lang_get( 'username' ), 15 ) . utf8_str_pad( lang_get( 'field' ), 25 ) . utf8_str_pad( lang_get( 'change' ), 20 ) . " \n"; - - $t_message .= $t_email_separator1 . " \n"; - - foreach( $p_visible_bug_data['history'] as $t_raw_history_item ) { - $t_localized_item = history_localize_item( $t_raw_history_item['field'], $t_raw_history_item['type'], $t_raw_history_item['old_value'], $t_raw_history_item['new_value'], false ); - - $t_message .= utf8_str_pad( date( $t_normal_date_format, $t_raw_history_item['date'] ), 17 ) . utf8_str_pad( $t_raw_history_item['username'], 15 ) . utf8_str_pad( $t_localized_item['note'], 25 ) . utf8_str_pad( $t_localized_item['change'], 20 ) . "\n"; - } - $t_message .= $t_email_separator1 . " \n\n"; - } + $t_message .= email_format_history( $p_visible_bug_data ); return $t_message; } @@ -1355,6 +1335,95 @@ function email_format_attribute( $p_visible_bug_data, $attribute_id ) { } /** + * Build the bug notes part of the message + * @param array $p_visible_bug_data + * @param integer $p_summary_for_date + * @return string + */ +function email_format_bugnotes( $p_visible_bug_data, $p_summary_for_date = null ) { + $t_message = ''; + + $t_normal_date_format = config_get( 'normal_date_format' ); + $t_email_separator2 = config_get( 'email_separator2' ); + + # format bugnotes + foreach( $p_visible_bug_data['bugnotes'] as $t_bugnote ) { + if( $p_summary_for_date ) { + if( $p_summary_for_date != $t_bugnote->last_modified ) { + continue; + } + } + + $t_last_modified = date( $t_normal_date_format, $t_bugnote->last_modified ); + + $t_formatted_bugnote_id = bugnote_format_id( $t_bugnote->id ); + $t_bugnote_link = string_process_bugnote_link( config_get( 'bugnote_link_tag' ) . $t_bugnote->id, false, false, true ); + + if( $t_bugnote->time_tracking > 0 ) { + $t_time_tracking = ' ' . lang_get( 'time_tracking' ) . ' ' . db_minutes_to_hhmm( $t_bugnote->time_tracking ) . "\n"; + } else { + $t_time_tracking = ''; + } + + if( user_exists( $t_bugnote->reporter_id ) ) { + $t_access_level = access_get_project_level( $p_visible_bug_data['email_project_id'] , $t_bugnote->reporter_id ); + $t_access_level_string = ' (' . get_enum_element( 'access_levels', $t_access_level ) . ') - '; + } else { + $t_access_level_string = ''; + } + + $t_string = ' (' . $t_formatted_bugnote_id . ') ' . user_get_name( $t_bugnote->reporter_id ) . $t_access_level_string . $t_last_modified . "\n" . $t_time_tracking . ' ' . $t_bugnote_link; + + $t_message .= $t_email_separator2 . " \n"; + $t_message .= $t_string . " \n"; + $t_message .= $t_email_separator2 . " \n"; + $t_message .= $t_bugnote->note . " \n\n"; + } + + return $t_message; +} + +/** + * Build the bug history part of the message + * @param array $p_visible_bug_data + * @param integer $p_summary_for_date + * @return string + */ +function email_format_history( $p_visible_bug_data, $p_summary_for_date = null ) { + $t_message = ''; + + $t_normal_date_format = config_get( 'normal_date_format' ); + + $t_email_separator1 = config_get( 'email_separator1' ); + $t_email_separator2 = config_get( 'email_separator1' ); + + # format history + if( array_key_exists( 'history', $p_visible_bug_data ) ) { + if( $p_summary_for_date ) { + $t_message .= $t_email_separator2 . " \n"; + } else { + $t_message .= lang_get( 'bug_history' ) . " \n"; + $t_message .= utf8_str_pad( lang_get( 'date_modified' ), 17 ) . utf8_str_pad( lang_get( 'username' ), 15 ) . utf8_str_pad( lang_get( 'field' ), 25 ) . utf8_str_pad( lang_get( 'change' ), 20 ) . " \n"; + + $t_message .= $t_email_separator1 . " \n"; + } + + foreach( $p_visible_bug_data['history'] as $t_raw_history_item ) { + if( $p_summary_for_date && $p_summary_for_date != $t_raw_history_item['date']) { + continue; + } + + $t_localized_item = history_localize_item( $t_raw_history_item['field'], $t_raw_history_item['type'], $t_raw_history_item['old_value'], $t_raw_history_item['new_value'], false ); + + $t_message .= utf8_str_pad( date( $t_normal_date_format, $t_raw_history_item['date'] ), 17 ) . utf8_str_pad( $t_raw_history_item['username'], 15 ) . utf8_str_pad( $t_localized_item['note'], 25 ) . utf8_str_pad( $t_localized_item['change'], 20 ) . "\n"; + } + $t_message .= $t_email_separator1 . " \n\n"; + } + + return $t_message; +} + +/** * Build the bug raw data visible for specified user to be translated and sent by email to the user * (Filter the bug data according to user access level) * return array with bug data. See usage in email_format_bug_message(...) diff --git a/lang/strings_english.txt b/lang/strings_english.txt index bf638cb..2bd858c 100644 --- a/lang/strings_english.txt +++ b/lang/strings_english.txt @@ -401,6 +401,8 @@ $s_email_summary = 'Summary'; $s_email_description = 'Description'; $s_email_additional_information = 'Additional Information'; $s_email_steps_to_reproduce = 'Steps to Reproduce'; +$s_email_changed = 'Changed'; +$s_email_details = 'Details'; # account_delete.php $s_account_protected_msg = 'Account protected. Cannot change settings...'; -- 1.7.7