コード例 #1
0
ファイル: email_api.php プロジェクト: sfranks1124/mantisbt
/**
 * 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(...)
 * @param integer $p_user_id    A user identifier.
 * @param integer $p_bug_id     A bug identifier.
 * @param string  $p_message_id A message identifier.
 * @return array
 */
function email_build_visible_bug_data($p_user_id, $p_bug_id, $p_message_id)
{
    # Override current user with user to construct bug data for.
    # This is to make sure that APIs that check against current user (e.g. relationship) work correctly.
    $t_current_user_id = current_user_set($p_user_id);
    $t_project_id = bug_get_field($p_bug_id, 'project_id');
    $t_user_access_level = user_get_access_level($p_user_id, $t_project_id);
    $t_user_bugnote_order = user_pref_get_pref($p_user_id, 'bugnote_order');
    $t_user_bugnote_limit = user_pref_get_pref($p_user_id, 'email_bugnote_limit');
    $t_row = bug_get_extended_row($p_bug_id);
    $t_bug_data = array();
    $t_bug_data['email_bug'] = $p_bug_id;
    if ($p_message_id !== 'email_notification_title_for_action_bug_deleted') {
        $t_bug_data['email_bug_view_url'] = string_get_bug_view_url_with_fqdn($p_bug_id);
    }
    if (access_compare_level($t_user_access_level, config_get('view_handler_threshold'))) {
        if (0 != $t_row['handler_id']) {
            $t_bug_data['email_handler'] = user_get_name($t_row['handler_id']);
        } else {
            $t_bug_data['email_handler'] = '';
        }
    }
    $t_bug_data['email_reporter'] = user_get_name($t_row['reporter_id']);
    $t_bug_data['email_project_id'] = $t_row['project_id'];
    $t_bug_data['email_project'] = project_get_field($t_row['project_id'], 'name');
    $t_category_name = category_full_name($t_row['category_id'], false);
    $t_bug_data['email_category'] = $t_category_name;
    $t_bug_data['email_date_submitted'] = $t_row['date_submitted'];
    $t_bug_data['email_last_modified'] = $t_row['last_updated'];
    $t_bug_data['email_status'] = $t_row['status'];
    $t_bug_data['email_severity'] = $t_row['severity'];
    $t_bug_data['email_priority'] = $t_row['priority'];
    $t_bug_data['email_reproducibility'] = $t_row['reproducibility'];
    $t_bug_data['email_resolution'] = $t_row['resolution'];
    $t_bug_data['email_fixed_in_version'] = $t_row['fixed_in_version'];
    if (!is_blank($t_row['target_version']) && access_compare_level($t_user_access_level, config_get('roadmap_view_threshold'))) {
        $t_bug_data['email_target_version'] = $t_row['target_version'];
    }
    $t_bug_data['email_summary'] = $t_row['summary'];
    $t_bug_data['email_description'] = $t_row['description'];
    $t_bug_data['email_additional_information'] = $t_row['additional_information'];
    $t_bug_data['email_steps_to_reproduce'] = $t_row['steps_to_reproduce'];
    $t_bug_data['set_category'] = '[' . $t_bug_data['email_project'] . '] ' . $t_category_name;
    $t_bug_data['custom_fields'] = custom_field_get_linked_fields($p_bug_id, $t_user_access_level);
    $t_bug_data['bugnotes'] = bugnote_get_all_visible_bugnotes($p_bug_id, $t_user_bugnote_order, $t_user_bugnote_limit, $p_user_id);
    # put history data
    if (ON == config_get('history_default_visible') && access_compare_level($t_user_access_level, config_get('view_history_threshold'))) {
        $t_bug_data['history'] = history_get_raw_events_array($p_bug_id, $p_user_id);
    }
    # Sponsorship Information
    if (config_get('enable_sponsorship') == ON && access_has_bug_level(config_get('view_sponsorship_total_threshold'), $p_bug_id, $p_user_id)) {
        $t_sponsorship_ids = sponsorship_get_all_ids($p_bug_id);
        $t_bug_data['sponsorship_total'] = sponsorship_get_amount($t_sponsorship_ids);
        if (access_has_bug_level(config_get('view_sponsorship_details_threshold'), $p_bug_id, $p_user_id)) {
            $t_bug_data['sponsorships'] = array();
            foreach ($t_sponsorship_ids as $t_id) {
                $t_bug_data['sponsorships'][] = sponsorship_get($t_id);
            }
        }
    }
    $t_bug_data['relations'] = relationship_get_summary_text($p_bug_id);
    current_user_set($t_current_user_id);
    return $t_bug_data;
}
コード例 #2
0
/**
 * Retrieve user id of current user
 * @return integer user id
 * @access public
 */
function auth_get_current_user_id()
{
    global $g_cache_current_user_id;
    if (null !== $g_cache_current_user_id) {
        return $g_cache_current_user_id;
    }
    $t_cookie_string = auth_get_current_user_cookie();
    if ($t_result = user_search_cache('cookie_string', $t_cookie_string)) {
        $t_user_id = (int) $t_result['id'];
        current_user_set($t_user_id);
        return $t_user_id;
    }
    # @todo error with an error saying they aren't logged in? Or redirect to the login page maybe?
    db_param_push();
    $t_query = 'SELECT id FROM {user} WHERE cookie_string=' . db_param();
    $t_result = db_query($t_query, array($t_cookie_string));
    $t_user_id = (int) db_result($t_result);
    # The cookie was invalid. Clear the cookie (to allow people to log in again)
    # and give them an Access Denied message.
    if (!$t_user_id) {
        auth_clear_cookies();
        access_denied();
        exit;
    }
    current_user_set($t_user_id);
    return $t_user_id;
}
コード例 #3
0
/**
 * Retrieve user id of current user
 * @return int user id
 * @access public
 */
function auth_get_current_user_id()
{
    global $g_cache_current_user_id;
    if (null !== $g_cache_current_user_id) {
        return $g_cache_current_user_id;
    }
    $t_cookie_string = auth_get_current_user_cookie();
    if ($t_result = user_search_cache('cookie_string', $t_cookie_string)) {
        $t_user_id = (int) $t_result['id'];
        current_user_set($t_user_id);
        return $t_user_id;
    }
    $t_user_table = db_get_table('mantis_user_table');
    /** @todo error with an error saying they aren't logged in? Or redirect to the login page maybe? */
    $query = "SELECT id\n\t\t\t\t  FROM {$t_user_table}\n\t\t\t\t  WHERE cookie_string=" . db_param();
    $result = db_query_bound($query, array($t_cookie_string));
    # The cookie was invalid. Clear the cookie (to allow people to log in again)
    # and give them an Access Denied message.
    if (db_num_rows($result) < 1) {
        auth_clear_cookies();
        access_denied();
        exit;
    }
    $t_user_id = (int) db_result($result);
    current_user_set($t_user_id);
    return $t_user_id;
}