function set_capability_row($p_threshold, $p_all_projects_only = false)
{
    global $t_access, $t_project;
    if ($t_access >= config_get_access($p_threshold) && (ALL_PROJECTS == $t_project || !$p_all_projects_only)) {
        $f_threshold = gpc_get_int_array('flag_thres_' . $p_threshold, array());
        $f_access = gpc_get_int('access_' . $p_threshold);
        # @@debug @@ echo "<br />for $p_threshold "; var_dump($f_threshold, $f_access); echo '<br />';
        $t_access_levels = get_enum_to_array(config_get('access_levels_enum_string'));
        ksort($t_access_levels);
        reset($t_access_levels);
        $t_lower_threshold = NOBODY;
        $t_array_threshold = array();
        foreach ($t_access_levels as $t_access_level => $t_level_name) {
            if (in_array($t_access_level, $f_threshold)) {
                if (NOBODY == $t_lower_threshold) {
                    $t_lower_threshold = $t_access_level;
                }
                $t_array_threshold[] = $t_access_level;
            } else {
                if (NOBODY != $t_lower_threshold) {
                    $t_lower_threshold = -1;
                }
            }
            # @@debug @@ var_dump($$t_access_level, $t_lower_threshold, $t_array_threshold); echo '<br />';
        }
        $t_existing_threshold = config_get($p_threshold);
        if (-1 == $t_lower_threshold) {
            if ($t_existing_threshold != $t_array_threshold) {
                config_set($p_threshold, $t_array_threshold, NO_USER, $t_project, $f_access);
            }
        } else {
            if ($t_existing_threshold != $t_lower_threshold) {
                config_set($p_threshold, $t_lower_threshold, NO_USER, $t_project, $f_access);
            }
        }
    }
}
function access_row()
{
    global $t_access, $t_can_change_flags, $t_colour_project, $t_colour_global;
    $t_enum_status = get_enum_to_array(config_get('status_enum_string'));
    $t_file_new = config_get_global('report_bug_threshold');
    $t_global_new = config_get('report_bug_threshold', null, null, ALL_PROJECTS);
    $t_project_new = config_get('report_bug_threshold');
    $t_file_set = config_get_global('set_status_threshold');
    foreach ($t_enum_status as $t_status => $t_status_label) {
        if (!isset($t_file_set[$t_status])) {
            $t_file_set[$t_status] = config_get_global('update_bug_status_threshold');
        }
    }
    $t_global_set = config_get('set_status_threshold', null, null, ALL_PROJECTS);
    foreach ($t_enum_status as $t_status => $t_status_label) {
        if (!isset($t_file_set[$t_status])) {
            $t_file_set[$t_status] = config_get('update_bug_status_threshold', null, null, ALL_PROJECTS);
        }
    }
    $t_project_set = config_get('set_status_threshold');
    foreach ($t_enum_status as $t_status => $t_status_label) {
        if (!isset($t_file_set[$t_status])) {
            $t_file_set[$t_status] = config_get('update_bug_status_threshold');
        }
    }
    foreach ($t_enum_status as $t_status => $t_status_label) {
        echo '<tr ' . helper_alternate_class() . '><td width="30%">' . string_no_break(get_enum_to_string(lang_get('status_enum_string'), $t_status)) . '</td>';
        if (NEW_ == $t_status) {
            $t_level = $t_project_new;
            $t_can_change = $t_access >= config_get_access('report_bug_threshold');
            $t_colour = '';
            if ($t_global_new != $t_file_new) {
                $t_colour = ' bgcolor="' . $t_colour_global . '" ';
                # all projects override
                if ($t_can_change) {
                    set_overrides('report_bug_threshold');
                }
            }
            if ($t_project_new != $t_global_new) {
                $t_colour = ' bgcolor="' . $t_colour_project . '" ';
                # project overrides
                if ($t_can_change) {
                    set_overrides('report_bug_threshold');
                }
            }
        } else {
            $t_level = isset($t_project_set[$t_status]) ? $t_project_set[$t_status] : false;
            $t_level_global = isset($t_global_set[$t_status]) ? $t_global_set[$t_status] : false;
            $t_level_file = isset($t_file_set[$t_status]) ? $t_file_set[$t_status] : false;
            $t_can_change = $t_access >= config_get_access('set_status_threshold');
            $t_colour = '';
            if ($t_level_global != $t_level_file) {
                $t_colour = ' bgcolor="' . $t_colour_global . '" ';
                # all projects override
                if ($t_can_change) {
                    set_overrides('set_status_threshold');
                }
            }
            if ($t_level != $t_level_global) {
                $t_colour = ' bgcolor="' . $t_colour_project . '" ';
                # project overrides
                if ($t_can_change) {
                    set_overrides('set_status_threshold');
                }
            }
        }
        if ($t_can_change) {
            echo '<td' . $t_colour . '><select name="access_change_' . $t_status . '">';
            print_enum_string_option_list('access_levels', $t_level);
            echo '</select> </td>';
            $t_can_change_flags = true;
        } else {
            echo '<td class="center"' . $t_colour . '>' . get_enum_to_string(config_get('access_levels_enum_string'), $t_level) . '</td>';
        }
        echo '</tr>' . "\n";
    }
}
$t_filter['sort'] = '';
$rows = filter_get_bug_rows($f_page_number, $t_per_page, $t_page_count, $t_bug_count, $t_filter, null, null, true);
if (count($rows) == 0) {
    // no data to graph
    exit;
}
$t_bug_table = config_get('mantis_bug_table');
$t_bug_hist_table = config_get('mantis_bug_history_table');
$t_marker = array();
$t_data = array();
$t_ptr = 0;
$t_end = $t_interval->get_end_timestamp();
$t_start = $t_interval->get_start_timestamp();
// grab all status levels
$t_status_arr = get_enum_to_array(config_get('status_enum_string'));
$t_status_labels = get_enum_to_array(lang_get('status_enum_string'));
$t_bug = array();
$t_view_status = array();
// walk through all issues and grab their status for 'now'
$t_marker[$t_ptr] = time();
foreach ($rows as $t_row) {
    if (isset($t_data[$t_ptr][$t_row['status']])) {
        $t_data[$t_ptr][$t_row['status']]++;
    } else {
        $t_data[$t_ptr][$t_row['status']] = 1;
        $t_view_status[$t_row['status']] = isset($t_status_arr[$t_row['status']]) ? $t_status_arr[$t_row['status']] : '@' . $t_row['status'] . '@';
    }
    $t_bug[] = $t_row['id'];
}
// get the history for these bugs over the interval required to offset the data
// type = 0 and field=status are status changes
# --------------------------------------------------------
# $Id: manage_config_work_threshold_page.php,v 1.14.2.1 2007-10-13 22:33:24 giallu Exp $
# --------------------------------------------------------
require_once 'core.php';
$t_core_path = config_get('core_path');
require_once $t_core_path . 'email_api.php';
auth_reauthenticate();
html_page_top1(lang_get('manage_threshold_config'));
html_page_top2();
print_manage_menu('adm_permissions_report.php');
print_manage_config_menu('manage_config_work_threshold_page.php');
$t_user = auth_get_current_user_id();
$t_project_id = helper_get_current_project();
$t_access = user_get_access_level($t_user, $t_project_id);
$t_show_submit = false;
$t_access_levels = get_enum_to_array(config_get('access_levels_enum_string'));
$t_overrides = array();
function set_overrides($p_config)
{
    global $t_overrides;
    if (!in_array($p_config, $t_overrides)) {
        $t_overrides[] = $p_config;
    }
}
function get_section_begin($p_section_name)
{
    global $t_access_levels;
    echo '<table class="width100">';
    echo '<tr><td class="form-title" colspan="' . (count($t_access_levels) + 2) . '">' . strtoupper($p_section_name) . '</td></tr>' . "\n";
    echo '<tr><td class="form-title" width="40%" rowspan="2">' . lang_get('perm_rpt_capability') . '</td>';
    echo '<td class="form-title"style="text-align:center"  width="40%" colspan="' . count($t_access_levels) . '">' . lang_get('access_levels') . '</td>';
html_page_top2();
print_manage_menu('adm_permissions_report.php');
print_manage_config_menu('manage_config_email_page.php');
$t_access = current_user_get_access_level();
$t_project = helper_get_current_project();
$t_colour_project = config_get('colour_project');
$t_colour_global = config_get('colour_global');
# build a list of all of the actions
$t_actions = array('owner', 'reopened', 'deleted', 'bugnote');
if (config_get('enable_sponsorship') == ON) {
    $t_actions[] = 'sponsor';
}
if (config_get('enable_relationship') == ON) {
    $t_actions[] = 'relationship';
}
$t_statuses = get_enum_to_array(config_get('status_enum_string'));
foreach ($t_statuses as $t_status) {
    $t_actions[] = $t_status;
}
# build a composite of the status flags, exploding the defaults
$t_global_default_notify_flags = config_get('default_notify_flags', null, null, ALL_PROJECTS);
$t_global_notify_flags = array();
foreach ($t_global_default_notify_flags as $t_flag => $t_value) {
    foreach ($t_actions as $t_action) {
        $t_global_notify_flags[$t_action][$t_flag] = $t_value;
    }
}
$t_global_notify_flags = array_merge_recursive2($t_global_notify_flags, config_get('notify_flags', null, null, ALL_PROJECTS));
$t_file_default_notify_flags = config_get_global('default_notify_flags');
$t_file_notify_flags = array();
foreach ($t_file_default_notify_flags as $t_flag => $t_value) {
function email_collect_recipients($p_bug_id, $p_notify_type)
{
    $c_bug_id = db_prepare_int($p_bug_id);
    $t_recipients = array();
    # add Reporter
    if (ON == email_notify_flag($p_notify_type, 'reporter')) {
        $t_reporter_id = bug_get_field($p_bug_id, 'reporter_id');
        $t_recipients[$t_reporter_id] = true;
        log_event(LOG_EMAIL_RECIPIENT, "bug={$p_bug_id}, add reporter={$t_reporter_id}");
    }
    # add Handler
    if (ON == email_notify_flag($p_notify_type, 'handler')) {
        $t_handler_id = bug_get_field($p_bug_id, 'handler_id');
        if ($t_handler_id > 0) {
            $t_recipients[$t_handler_id] = true;
            log_event(LOG_EMAIL_RECIPIENT, "bug={$p_bug_id}, add handler={$t_handler_id}");
        }
    }
    $t_project_id = bug_get_field($p_bug_id, 'project_id');
    # add users monitoring the bug
    $t_bug_monitor_table = config_get('mantis_bug_monitor_table');
    if (ON == email_notify_flag($p_notify_type, 'monitor')) {
        $query = "SELECT DISTINCT user_id\n\t\t\t\t\t  FROM {$t_bug_monitor_table}\n\t\t\t\t\t  WHERE bug_id={$c_bug_id}";
        $result = db_query($query);
        $count = db_num_rows($result);
        for ($i = 0; $i < $count; $i++) {
            $t_user_id = db_result($result, $i);
            $t_recipients[$t_user_id] = true;
            log_event(LOG_EMAIL_RECIPIENT, "bug={$p_bug_id}, add monitor={$t_user_id}");
        }
    }
    # add users who contributed bugnotes
    $t_bugnote_id = bugnote_get_latest_id($p_bug_id);
    $t_bugnote_view = bugnote_get_field($t_bugnote_id, 'view_state');
    $t_bugnote_date = db_unixtimestamp(bugnote_get_field($t_bugnote_id, 'last_modified'));
    $t_bug_date = bug_get_field($p_bug_id, 'last_updated');
    $t_bugnote_table = config_get('mantis_bugnote_table');
    if (ON == email_notify_flag($p_notify_type, 'bugnotes')) {
        $query = "SELECT DISTINCT reporter_id\n\t\t\t\t\t  FROM {$t_bugnote_table}\n\t\t\t\t\t  WHERE bug_id = {$c_bug_id}";
        $result = db_query($query);
        $count = db_num_rows($result);
        for ($i = 0; $i < $count; $i++) {
            $t_user_id = db_result($result, $i);
            $t_recipients[$t_user_id] = true;
            log_event(LOG_EMAIL_RECIPIENT, "bug={$p_bug_id}, add note author={$t_user_id}");
        }
    }
    # add project users who meet the thresholds
    $t_bug_is_private = bug_get_field($p_bug_id, 'view_state') == VS_PRIVATE;
    $t_threshold_min = email_notify_flag($p_notify_type, 'threshold_min');
    $t_threshold_max = email_notify_flag($p_notify_type, 'threshold_max');
    $t_threshold_users = project_get_all_user_rows($t_project_id, $t_threshold_min);
    foreach ($t_threshold_users as $t_user) {
        if ($t_user['access_level'] <= $t_threshold_max) {
            if (!$t_bug_is_private || access_compare_level($t_user['access_level'], config_get('private_bug_threshold'))) {
                $t_recipients[$t_user['id']] = true;
                log_event(LOG_EMAIL_RECIPIENT, "bug={$p_bug_id}, add project user="******"bug={$p_bug_id}, drop {$t_id} (own)");
            continue;
        }
        # Eliminate users who don't exist anymore or who are disabled
        if (!user_exists($t_id) || !user_is_enabled($t_id)) {
            log_event(LOG_EMAIL_RECIPIENT, "bug={$p_bug_id}, drop {$t_id} (disabled)");
            continue;
        }
        # Exclude users who have this notification type turned off
        if ($t_pref_field) {
            $t_notify = user_pref_get_pref($t_id, $t_pref_field);
            if (OFF == $t_notify) {
                log_event(LOG_EMAIL_RECIPIENT, "bug={$p_bug_id}, drop {$t_id} (pref {$t_pref_field} off)");
                continue;
            } else {
                # Users can define the severity of an issue before they are emailed for
                # each type of notification
                $t_min_sev_pref_field = $t_pref_field . '_min_severity';
                $t_min_sev_notify = user_pref_get_pref($t_id, $t_min_sev_pref_field);
                $t_bug_severity = bug_get_field($p_bug_id, 'severity');
                if ($t_bug_severity < $t_min_sev_notify) {
                    log_event(LOG_EMAIL_RECIPIENT, "bug={$p_bug_id}, drop {$t_id} (pref threshold)");
                    continue;
                }
            }
        }
        # check that user can see bugnotes if the last update included a bugnote
        if ($t_bug_date == $t_bugnote_date) {
            if (!access_has_bugnote_level(VIEWER, $t_bugnote_id, $t_id)) {
                log_event(LOG_EMAIL_RECIPIENT, "bug={$p_bug_id}, drop {$t_id} (access level)");
                continue;
            }
        }
        # Finally, let's get their emails, if they've set one
        $t_email = user_get_email($t_id);
        if (is_blank($t_email)) {
            log_event(LOG_EMAIL_RECIPIENT, "bug={$p_bug_id}, drop {$t_id} (no email)");
        } else {
            # @@@ we could check the emails for validity again but I think
            #   it would be too slow
            $t_final_recipients[$t_id] = $t_email;
        }
    }
    return $t_final_recipients;
}