From 3ff24e457abdc4afe606e4c3e476a022c1981eff Mon Sep 17 00:00:00 2001 From: Victor Boctor Date: Tue, 2 Jul 2002 12:48:53 +0000 Subject: [PATCH] 1. Added configuration options which allow control on who should be notified on different actions/events. 2. Added checking for obsolete variables (before of enhancement 1), if found, an error is reported directing the admin to the new configuration variables. 3. Added a database API that allows checking whether a field name exists or not. git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@1162 f5dc347c-c33d-0410-90a0-b07cc1902cb9 --- core_API.php | 18 +++ core_database_API.php | 24 +++- core_email_API.php | 252 +++++++++++++++++++++++------------------- doc/ChangeLog | 3 +- 4 files changed, 179 insertions(+), 118 deletions(-) diff --git a/core_API.php b/core_API.php index 5cde8e4ebf..8ee99e5d22 100644 --- a/core_API.php +++ b/core_API.php @@ -22,6 +22,24 @@ } # Load file globals # @@@ ugly hack for ugly problem. Find better solution soon require( './default/config_inc2.php' ); + + # Should be eventually moved to the admin scripts, but keep it here for a while + # to make sure people don't miss it. + function obsolete_config_variable($var, $replace) { + global $$var; + if (isset($$var)) { + PRINT '$' . $var . ' is now obsolete'; + if ($replace != '') { + PRINT ', please use $' . $replace; + } + exit; + } + } + + # Check for obsolete variables + obsolete_config_variable('g_notify_developers_on_new', 'g_notify_flags'); + obsolete_config_variable('g_notify_on_new_threshold', 'g_notify_flags'); + obsolete_config_variable('g_notify_admin_on_new', 'g_notify_flags'); ini_set('magic_quotes_runtime', 0); if ( OFF == $g_register_globals ) { diff --git a/core_database_API.php b/core_database_API.php index 48bb36146a..a9401423ad 100644 --- a/core_database_API.php +++ b/core_database_API.php @@ -5,11 +5,11 @@ # See the files README and LICENSE for details # -------------------------------------------------------- - # $Revision: 1.13 $ + # $Revision: 1.14 $ # $Author: vboctor $ - # $Date: 2002-06-25 10:19:58 $ + # $Date: 2002-07-02 12:48:52 $ # - # $Id: core_database_API.php,v 1.13 2002-06-25 10:19:58 vboctor Exp $ + # $Id: core_database_API.php,v 1.14 2002-07-02 12:48:52 vboctor Exp $ # -------------------------------------------------------- ########################################################################### @@ -109,6 +109,24 @@ function db_insert_id() { return db_result( $t_result, 0, 0 ); } # -------------------- + function db_field_exists( $p_field_name, $p_table_name, $p_db_name = '') { + global $g_database_name; + + if ($p_db_name == '') { + $p_db_name = $g_database_name; + } + + $fields = mysql_list_fields($p_db_name, $p_table_name); + $columns = mysql_num_fields($fields); + for ($i = 0; $i < $columns; $i++) { + if ( mysql_field_name( $fields, $i ) == $p_field_name ) { + return true; + } + } + + return false; + } + # -------------------- function db_error_num() { return mysql_errno(); } diff --git a/core_email_API.php b/core_email_API.php index d8caaf5a7b..7b805f85d7 100644 --- a/core_email_API.php +++ b/core_email_API.php @@ -7,11 +7,11 @@ ########################################################################### # Email API # ------------------------------------------------- - # $Revision: 1.63 $ + # $Revision: 1.64 $ # $Author: vboctor $ - # $Date: 2002-06-25 14:23:57 $ + # $Date: 2002-07-02 12:48:52 $ # - # $Id: core_email_API.php,v 1.63 2002-06-25 14:23:57 vboctor Exp $ + # $Id: core_email_API.php,v 1.64 2002-07-02 12:48:52 vboctor Exp $ ########################################################################### # -------------------- # check to see that the format is valid and that the mx record exists @@ -46,17 +46,21 @@ function is_valid_email( $p_email ) { return false; } # -------------------- - # takes an array and an element that might be in the array - # return true if a duplicate entry exists - # return false if entry does not already exist - function check_duplicate( $p_arr, $p_str ) { - $arr_count = count( $p_arr ); - for ($i=0; $i<$arr_count; $i++) { - if ( $p_str == $p_arr[$i] ) { - return true; - } + # get_notify_flag + # Get the value associated with the specific action and flag. + # For example, you can get the value associated with notifying "admin" + # on action "new", i.e. notify administrators on new bugs which can be + # ON or OFF. + function get_notify_flag( $action, $flag ) { + global $g_notify_flags, $g_default_notify_flags; + + if ( isset ( $g_notify_flags[$action][$flag] ) ) { + return $g_notify_flags[$action][$flag]; + } elseif ( isset ( $g_default_notify_flags[$flag] ) ) { + return $g_default_notify_flags[$flag]; } - return false; + + return OFF; } # -------------------- # build the bcc list @@ -69,13 +73,10 @@ function check_duplicate( $p_arr, $p_str ) { # We add all ADMINISTRATORs then add DEVELOPERs. # Lastly, we do a bit of post processing and return the bcc string. function build_bcc_list( $p_bug_id, $p_notify_type ) { - global $g_mantis_bug_table, $g_mantis_user_table, - $g_mantis_project_table, + global $g_mantis_bug_table, $g_mantis_user_table, $g_mantis_bugnote_table, + $g_mantis_project_table, $g_mantis_user_pref_table, $g_project_cookie_val, $g_mantis_project_user_list_table, - $g_notify_developers_on_new, - $g_notify_on_new_threshold, - $g_notify_admin_on_new, $g_use_bcc, $g_use_phpMailer, $g_mantis_bug_monitor_table; @@ -85,110 +86,135 @@ function build_bcc_list( $p_bug_id, $p_notify_type ) { $send_arr = array(); # Get Reporter Email - $v_reporter_id = get_bug_field( $p_bug_id, 'reporter_id' ); - $t_notify_reporter = get_user_pref_info( $v_reporter_id, $p_notify_type ); - if ( ON == $t_notify_reporter ) { - $send_arr[] = get_user_info( $v_reporter_id, 'email' ); + if ( ON == get_notify_flag( $p_notify_type, 'reporter' )) { + $v_reporter_id = get_bug_field( $p_bug_id, 'reporter_id' ); + $t_pref_field = 'email_on_' . $p_notify_type; + if ( db_field_exists( $t_pref_field, $g_mantis_user_pref_table ) ) { + $t_notify_reporter = get_user_pref_info( $v_reporter_id, $t_pref_field ); + if ( ON == $t_notify_reporter ) { + $send_arr[] = get_user_info( $v_reporter_id, 'email' ); + } + } else { + $send_arr[] = get_user_info( $v_reporter_id, 'email' ); + } } # Get Handler Email - $v_handler_id = get_bug_field( $p_bug_id, 'handler_id' ); - if ( $v_handler_id > 0 ) { - $t_notify_handler = get_user_pref_info( $v_handler_id, $p_notify_type ); - if ( ON == $t_notify_handler ) { - $send_arr[] = get_user_info( $v_handler_id, 'email' ); + if ( ON == get_notify_flag( $p_notify_type, 'handler' )) { + $v_handler_id = get_bug_field( $p_bug_id, 'handler_id' ); + if ( $v_handler_id > 0 ) { + $t_pref_field = 'email_on_' . $p_notify_type; + if ( db_field_exists( $t_pref_field, $g_mantis_user_pref_table ) ) { + $t_notify_handler = get_user_pref_info( $v_handler_id, $t_pref_field ); + if ( ON == $t_notify_handler ) { + $send_arr[] = get_user_info( $v_handler_id, 'email' ); + } + } else { + $send_arr[] = get_user_info( $v_handler_id, 'email' ); + } } } - + # Check if we want to broadcast to all developers on a NEW bug - if ( ( ON == $g_notify_developers_on_new )&&( 'email_on_new' == $p_notify_type ) ) { - $t_project_id = get_bug_field( $p_bug_id, 'project_id' ); - $t_project_view_state = get_project_field( $g_project_cookie_val, 'view_state' ); + $t_project_id = get_bug_field( $p_bug_id, 'project_id' ); + $t_project_view_state = get_project_field( $g_project_cookie_val, 'view_state' ); - #@@@@@@@ - $temp_arr = array(); - # grab the administrators - $query = "SELECT id, email - FROM $g_mantis_user_table - ORDER BY username"; - $result = db_query( $query ); - $user_count = db_num_rows( $result ); - for ($i=0;$i<$user_count;$i++) { - $row = db_fetch_array( $result ); - extract( $row, EXTR_PREFIX_ALL, 'v' ); - $temp_arr[$v_email] = array( $v_email, $v_id ); + #@@@@@@@ + $temp_arr = array(); + # grab the administrators + $query = "SELECT id, email + FROM $g_mantis_user_table + ORDER BY username"; + $result = db_query( $query ); + $user_count = db_num_rows( $result ); + for ($i=0;$i<$user_count;$i++) { + $row = db_fetch_array( $result ); + extract( $row, EXTR_PREFIX_ALL, 'v' ); + $temp_arr[$v_email] = array( $v_email, $v_id ); + } + + foreach ( $temp_arr as $key => $val ) { + $v_id = $val[1]; + $v_email = $val[0]; + + # add all administrators if notification flag enabled + $t_access_level = get_user_field( $v_id, 'access_level' ); + + if ( ($t_access_level == ADMINISTRATOR) && (ON == get_notify_flag( $p_notify_type, 'admin' ))) { + $send_arr[] = $v_email; + continue; } - foreach ( $temp_arr as $key => $val ) { - $v_id = $val[1]; - $v_email = $val[0]; + # Get authors of bug notes + if ( ON == get_notify_flag( $p_notify_type, 'bugnotes' )) { + $query = "SELECT 1 ". + "FROM $g_mantis_bugnote_table ". + "WHERE (bug_id = $p_bug_id) AND (reporter_id = $v_id) ". + "LIMIT 1"; + $result = db_query( $query ); + if ( db_num_rows( $result ) > 0 ) { + $send_arr[] = $v_email; + } + } + + # see if users belong + $t_project_view_state = get_project_field( $g_project_cookie_val, 'view_state' ); + if ( PUBLIC == $t_project_view_state ) { + $query = "SELECT l.access_level + FROM $g_mantis_project_user_list_table l, + $g_mantis_project_table p + WHERE l.project_id='$t_project_id' AND + p.id=l.project_id AND + l.user_id='$v_id' + LIMIT 1"; + $result = db_query( $query ); + $count = db_num_rows( $result ); + if ( $count > 0 ){ + $t_access_level = db_result( $result ); + } - # always add all administrators - $t_access_level = get_user_field( $v_id, 'access_level' ); - if ( ( ADMINISTRATOR == $t_access_level ) && ( ON == $g_notify_admin_on_new ) ) { + if ( $t_access_level >= get_notify_flag($p_notify_type, 'threshold')) { + $send_arr[] = $v_email; + } + } else { + $query = "SELECT 1 + FROM $g_mantis_project_user_list_table l, + $g_mantis_project_table p + WHERE l.project_id='$t_project_id' AND + p.id=l.project_id AND + l.user_id='$v_id' AND + l.access_level>='" . get_notify_flag($p_notify_type, 'threshold') ."' + LIMIT 1"; + $result = db_query( $query ); + if ( db_num_rows( $result ) > 0 ) { $send_arr[] = $v_email; continue; } + } + } - # see if users belong - $t_project_view_state = get_project_field( $g_project_cookie_val, 'view_state' ); - if ( PUBLIC == $t_project_view_state ) { - $query = "SELECT l.access_level - FROM $g_mantis_project_user_list_table l, - $g_mantis_project_table p - WHERE l.project_id='$t_project_id' AND - p.id=l.project_id AND - l.user_id='$v_id'"; - $result = db_query( $query ); - $count = db_num_rows( $result ); - if ( $count > 0 ){ - $t_access_level = db_result( $result ); - } - if ( $t_access_level >= $g_notify_on_new_threshold ) { - $send_arr[] = $v_email; - } + if ( ON == get_notify_flag( $p_notify_type, 'monitor' )) { + # grab all users MONITORING bug + $query = "SELECT DISTINCT m.user_id, u.email + FROM $g_mantis_bug_monitor_table m, + $g_mantis_user_table u + WHERE m.bug_id=$c_bug_id AND + m.user_id=u.id"; + $result = db_query( $query ); + $monitor_user_count = db_num_rows( $result ); + for ($i=0;$i<$monitor_user_count;$i++) { + $row = db_fetch_array( $result ); - } else { - $query = "SELECT COUNT(*) - FROM $g_mantis_project_user_list_table l, - $g_mantis_project_table p - WHERE l.project_id='$t_project_id' AND - p.id=l.project_id AND - l.user_id='$v_id' AND - l.access_level>='$g_notify_on_new_threshold'"; - $result = db_query( $query ); - $count = db_result( $result, 0, 0 ); - if ( $count > 0 ) { - $send_arr[] = $v_email; - continue; + $t_pref_field = 'email_on_' . $p_notify_type; + if ( db_field_exists( $t_pref_field, $g_mantis_user_pref_table ) ) { + # if the user's notification is on then add to the list + $t_notify = get_user_pref_info( $row['user_id'], $p_notify_type ); + if ( ON == $t_notify ) { + $send_arr[] = $row['email']; } } - } -/* # if the user's notification is on then add to the list - $t_notify = get_user_pref_info( $row["id"], $p_notify_type ); - if ( ON == $t_notify ) { - $send_arr[] = $row["email"]; - } - } # end DEVELOPERS*/ - } # end NEW bug developer section - - # grab all users MONITORING bug - $query = "SELECT DISTINCT m.user_id, u.email - FROM $g_mantis_bug_monitor_table m, - $g_mantis_user_table u - WHERE m.bug_id=$c_bug_id AND - m.user_id=u.id"; - $result = db_query( $query ); - $monitor_user_count = db_num_rows( $result ); - for ($i=0;$i<$monitor_user_count;$i++) { - $row = db_fetch_array( $result ); - - # if the user's notification is on then add to the list - $t_notify = get_user_pref_info( $row['user_id'], $p_notify_type ); - if ( ON == $t_notify ) { - $send_arr[] = $row['email']; - } - } # end MONITORING + } # end MONITORING + } $t_bcc = ( $g_use_bcc && !$g_use_phpMailer ) ? 'Bcc: ' : ''; ## win-bcc-bug @@ -265,7 +291,7 @@ function email_reset( $p_user_id, $p_password ) { function email_new_bug( $p_bug_id ) { global $s_new_bug_msg; - $t_bcc = build_bcc_list( $p_bug_id, 'email_on_new' ); + $t_bcc = build_bcc_list( $p_bug_id, 'new' ); email_bug_info( $p_bug_id, $s_new_bug_msg, $t_bcc ); } # -------------------- @@ -273,7 +299,7 @@ function email_new_bug( $p_bug_id ) { function email_bugnote_add( $p_bug_id ) { global $s_email_bugnote_msg; - $t_bcc = build_bcc_list( $p_bug_id, 'email_on_bugnote' ); + $t_bcc = build_bcc_list( $p_bug_id, 'bugnote' ); email_bug_info( $p_bug_id, $s_email_bugnote_msg, $t_bcc ); } # -------------------- @@ -281,7 +307,7 @@ function email_bugnote_add( $p_bug_id ) { function email_resolved( $p_bug_id ) { global $s_email_resolved_msg; - $t_bcc = build_bcc_list( $p_bug_id, 'email_on_resolved' ); + $t_bcc = build_bcc_list( $p_bug_id, 'resolved' ); email_bug_info( $p_bug_id, $s_email_resolved_msg, $t_bcc ); } # -------------------- @@ -289,7 +315,7 @@ function email_resolved( $p_bug_id ) { function email_close( $p_bug_id ) { global $s_email_close_msg; - $t_bcc = build_bcc_list( $p_bug_id, 'email_on_closed' ); + $t_bcc = build_bcc_list( $p_bug_id, 'closed' ); email_bug_info( $p_bug_id, $s_email_close_msg, $t_bcc ); } # -------------------- @@ -297,7 +323,7 @@ function email_close( $p_bug_id ) { function email_feedback( $p_bug_id ) { global $s_email_feedback_msg; - $t_bcc = build_bcc_list( $p_bug_id, 'email_on_feedback' ); + $t_bcc = build_bcc_list( $p_bug_id, 'feedback' ); email_bug_info( $p_bug_id, $s_email_feedback_msg, $t_bcc ); } # -------------------- @@ -305,7 +331,7 @@ function email_feedback( $p_bug_id ) { function email_reopen( $p_bug_id ) { global $s_email_reopen_msg; - $t_bcc = build_bcc_list( $p_bug_id, 'email_on_reopened' ); + $t_bcc = build_bcc_list( $p_bug_id, 'reopened' ); email_bug_info( $p_bug_id, $s_email_reopen_msg, $t_bcc ); } # -------------------- @@ -313,7 +339,7 @@ function email_reopen( $p_bug_id ) { function email_assign( $p_bug_id ) { global $s_email_assigned_msg; - $t_bcc = build_bcc_list( $p_bug_id, 'email_on_assigned' ); + $t_bcc = build_bcc_list( $p_bug_id, 'assigned' ); email_bug_info( $p_bug_id, $s_email_assigned_msg, $t_bcc ); } # -------------------- @@ -462,8 +488,6 @@ function email_bug_info( $p_bug_id, $p_message, $p_headers='' ) { $t_message .= email_build_bugnote_message( $p_bug_id ); # send mail - $res1 = 1; - $res2 = 1; ## win-bcc-bug if ( OFF == $g_use_bcc ) { diff --git a/doc/ChangeLog b/doc/ChangeLog index ebf3ebcb1e..4f1b170464 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -70,10 +70,11 @@ Mantis ChangeLog * Replaced $g__color variables with $g_status_colors[''] array in the configuration. For example, $g_new_color is replaced with $g_status_colors['new']. * Added support for adding multiple categories in one step, this is done by separating category names by the pipe character '|'. For example to add category 'A' and 'B', add 'A|B'. * Added multiple bug actions in view_all_bug_page.php. - * Added a direct link, with a small icon, on each bug row, so that users on a selected project can switch directly to the bug_update_advanced_page. + * Added a direct link, with a small icon, on each bug row, so that users on a selected project can switch directly to the update bug page (simple/advanced depending on user preferences). * Added automatic defaults for $g_path and $g_absolute_path rather than dummy values. This should avoid the need of redefining these values in custom_config_inc.php and also support multiple domains. * Added configuration flags ($g_show_queries_count and $g_show_queries_list) that track the executed queries and display their total count, unique queries count, and the actual list of queries executed. * Added more visual graph pages in summary_page.php. Caution, old versions of JPGraph may cause problems, use v1.6.3 or above if you can. + * Added $g_default_notify_flags and $g_notify_flags which replace $g_notify_developers_on_new, $g_notify_on_new_threshold, and $g_notify_admin_on_new. The old flags are no longer supported. The new ones provide full control on who should be notified on each event/action. 2002.05.19 - 0.17.3