function relgraph_add_child(&$p_bug_list, $p_bug_id)
{
    # Check if the issue is already in the issue list.
    if (isset($p_bug_list[$p_bug_id])) {
        # The issue is in the list, but we cannot discard it since it
        # may be a parent issue (whose children were not visited).
        if (!$p_bug_list[$p_bug_id]->is_descendant) {
            # Yes, we visited this issue as a parent... This is the case
            # where someone set up a cyclic relationship (I really hope
            # nobody ever do this, but should keep sanity) for this
            # issue. We just have to finish the job, visiting all issues
            # that were already listed by _add_parent().
            $p_bug_list[$p_bug_id]->is_descendant = true;
            foreach ($p_bug_list[$p_bug_id]->children as $t_child) {
                relgraph_add_child($p_bug_id, $t_child);
            }
        }
    } else {
        # The issue is not in the list, proceed as usual.
        # Check if the issue really exists and we have access to it.
        # If not, it is like it didn't exist.
        if (!bug_exists($p_bug_id)) {
            return false;
        }
        if (!access_has_bug_level(VIEWER, $p_bug_id)) {
            return false;
        }
        # Add the issue to the list.
        $p_bug_list[$p_bug_id] = bug_prepare_display(bug_get($p_bug_id, false));
        $p_bug_list[$p_bug_id]->is_descendant = true;
        $p_bug_list[$p_bug_id]->parents = array();
        $p_bug_list[$p_bug_id]->children = array();
        # Add all parent issues to the list of parents. Do not visit them
        # for the same reason we didn't visit the children of all
        # ancestors.
        $t_relationships = relationship_get_all_dest($p_bug_id);
        foreach ($t_relationships as $t_relationship) {
            if ($t_relationship->type != BUG_DEPENDANT) {
                continue;
            }
            $p_bug_list[$p_bug_id]->parents[] = $t_relationship->src_bug_id;
        }
        # Add all child issues to the list of children and visit them
        # recursively.
        $t_relationships = relationship_get_all_src($p_bug_id);
        foreach ($t_relationships as $t_relationship) {
            if ($t_relationship->type != BUG_DEPENDANT) {
                continue;
            }
            $p_bug_list[$p_bug_id]->children[] = $t_relationship->dest_bug_id;
            relgraph_add_child($p_bug_list, $t_relationship->dest_bug_id);
        }
    }
    return true;
}
# --------------------------------------------------------
require_once 'core.php';
$t_core_path = config_get('core_path');
require_once $t_core_path . 'bug_api.php';
require_once $t_core_path . 'custom_field_api.php';
require_once $t_core_path . 'file_api.php';
require_once $t_core_path . 'compress_api.php';
require_once $t_core_path . 'date_api.php';
require_once $t_core_path . 'relationship_api.php';
require_once $t_core_path . 'last_visited_api.php';
require_once $t_core_path . 'tag_api.php';
$f_bug_id = gpc_get_int('bug_id');
$f_history = gpc_get_bool('history', config_get('history_default_visible'));
bug_ensure_exists($f_bug_id);
access_ensure_bug_level(VIEWER, $f_bug_id);
$t_bug = bug_prepare_display(bug_get($f_bug_id, true));
if ($t_bug->project_id != helper_get_current_project()) {
    # in case the current project is not the same project of the bug we are viewing...
    # ... override the current project. This to avoid problems with categories and handlers lists etc.
    $g_project_override = $t_bug->project_id;
}
if (SIMPLE_ONLY == config_get('show_view')) {
    print_header_redirect('bug_view_page.php?bug_id=' . $f_bug_id);
}
compress_enable();
html_page_top1(bug_format_summary($f_bug_id, SUMMARY_CAPTION));
html_page_top2();
print_recently_visited();
$t_access_level_needed = config_get('view_history_threshold');
$t_can_view_history = access_has_bug_level($t_access_level_needed, $f_bug_id);
$t_bugslist = gpc_get_cookie(config_get('bug_list_cookie'), false);
function relationship_get_details($p_bug_id, $p_relationship, $p_html = false, $p_html_preview = false, $p_show_project = false)
{
    $t_summary_wrap_at = strlen(config_get('email_separator2')) - 28;
    $t_icon_path = config_get('icon_path');
    $p_user_id = auth_get_current_user_id();
    if ($p_bug_id == $p_relationship->src_bug_id) {
        # root bug is in the src side, related bug in the dest side
        $t_related_bug_id = $p_relationship->dest_bug_id;
        $t_related_project_name = project_get_name($p_relationship->dest_project_id);
        $t_relationship_descr = relationship_get_description_src_side($p_relationship->type);
    } else {
        # root bug is in the dest side, related bug in the src side
        $t_related_bug_id = $p_relationship->src_bug_id;
        $t_related_project_name = project_get_name($p_relationship->src_project_id);
        $t_relationship_descr = relationship_get_description_dest_side($p_relationship->type);
    }
    # related bug not existing...
    if (!bug_exists($t_related_bug_id)) {
        return '';
    }
    # user can access to the related bug at least as a viewer
    if (!access_has_bug_level(VIEWER, $t_related_bug_id)) {
        return '';
    }
    if ($p_html_preview == false) {
        $t_td = '<td>';
    } else {
        $t_td = '<td class="print">';
    }
    # get the information from the related bug and prepare the link
    $t_bug = bug_prepare_display(bug_get($t_related_bug_id, true));
    $t_status = string_attribute(get_enum_element('status', $t_bug->status));
    $t_resolution = string_attribute(get_enum_element('resolution', $t_bug->resolution));
    $t_relationship_info_html = $t_td . '<nobr>' . $t_relationship_descr . '</nobr>&nbsp;</td>';
    if ($p_html_preview == false) {
        $t_relationship_info_html .= '<td><a href="' . string_get_bug_view_url($t_related_bug_id) . '">' . bug_format_id($t_related_bug_id) . '</a></td>';
        $t_relationship_info_html .= '<td><a title="' . $t_resolution . '"><u>' . $t_status . '</u>&nbsp;</a></td>';
    } else {
        $t_relationship_info_html .= $t_td . bug_format_id($t_related_bug_id) . '</td>';
        $t_relationship_info_html .= $t_td . $t_status . '&nbsp;</td>';
    }
    $t_relationship_info_text = str_pad($t_relationship_descr, 20);
    $t_relationship_info_text .= str_pad(bug_format_id($t_related_bug_id), 8);
    # get the handler name of the related bug
    $t_relationship_info_html .= $t_td;
    if ($t_bug->handler_id > 0) {
        $t_relationship_info_html .= '<nobr>' . prepare_user_name($t_bug->handler_id) . '</nobr>';
    }
    $t_relationship_info_html .= '&nbsp;</td>';
    # add project name
    if ($p_show_project) {
        $t_relationship_info_html .= $t_td . $t_related_project_name . '&nbsp;</td>';
    }
    # add summary
    $t_relationship_info_html .= $t_td . $t_bug->summary;
    if (VS_PRIVATE == $t_bug->view_state) {
        $t_relationship_info_html .= sprintf(' <img src="%s" alt="(%s)" title="%s" />', $t_icon_path . 'protected.gif', lang_get('private'), lang_get('private'));
    }
    if (strlen($t_bug->summary) <= $t_summary_wrap_at) {
        $t_relationship_info_text .= $t_bug->summary;
    } else {
        $t_relationship_info_text .= substr($t_bug->summary, 0, $t_summary_wrap_at - 3) . '...';
    }
    # add delete link if bug not read only and user has access level
    if (!bug_is_readonly($p_bug_id) && !current_user_is_anonymous() && $p_html_preview == false) {
        if (access_has_bug_level(config_get('update_bug_threshold'), $p_bug_id)) {
            $t_relationship_info_html .= " [<a class=\"small\" href=\"bug_relationship_delete.php?bug_id={$p_bug_id}&rel_id={$p_relationship->id}\">" . lang_get('delete_link') . '</a>]';
        }
    }
    $t_relationship_info_html .= '&nbsp;</td>';
    $t_relationship_info_text .= "\n";
    if ($p_html_preview == false) {
        $t_relationship_info_html = '<tr bgcolor="' . get_status_color($t_bug->status) . '">' . $t_relationship_info_html . '</tr>' . "\n";
    } else {
        $t_relationship_info_html = '<tr>' . $t_relationship_info_html . '</tr>';
    }
    if ($p_html == true) {
        return $t_relationship_info_html;
    } else {
        return $t_relationship_info_text;
    }
}