$project_id = $s_project_properties['project_id'];
$s_user_properties = session_get_user_properties();
$s_user_id = $s_user_properties['user_id'];
$s_username = $s_user_properties['username'];
$s_bug_details = session_set_properties("bug", $_GET);
$bug_id = $s_bug_details['bug_id'];
$padded_bug_id = util_pad_id($bug_id);
html_window_title();
html_print_body();
html_page_title($project_name . " - " . lang_get('bug_close_page'));
html_page_header($db, $project_name);
html_print_menu();
bug_menu_print($page);
print "<br>" . NEWLINE;
error_report_check($_GET);
$row = bug_get_detail($bug_id);
$closed_reason_code = $row[BUG_CLOSED_REASON_CODE];
print "<div align=center>";
print "<span class='required'>*</span><span class='print'>" . lang_get('must_complete_field') . "</span><br>";
# ADD BUGNOTE TABLE
print "<table class=width75>";
print "<tr>";
print "<td>";
print "<form method=post action={$action_page}>";
print "<input type=hidden name='bug_id' value='{$bug_id}'>" . NEWLINE;
print "<table class=inner rules=none border=0>";
# FORM TITLE
print "<tr>";
print "<td class=form-header-l colspan=2>" . lang_get('close_bug') . "</td>";
print "</tr>";
# IMPLEMENTED IN RELEASE
function bug_email($project_id, $bug_id, $recipients, $action)
{
    # Don't send email if the preference it turned off in propterities_inc.php
    if (!SEND_EMAIL_NOTIFICATION) {
        return;
    }
    # Link to the bug detail page
    $generic_url = RTH_URL . "login.php?project_id={$project_id}&page=bug_detail_page.php&bug_id={$bug_id}";
    $username = session_get_username();
    $project_name = session_get_project_name();
    $bug_id = util_pad_id($bug_id);
    $user_details = user_get_name_by_username($username);
    $first_name = $user_details[USER_FNAME];
    $last_name = $user_details[USER_LNAME];
    $row_bug = bug_get_detail($bug_id);
    $category = $row_bug[CATEGORY_NAME];
    $bug_project_id = $row_bug[BUG_PROJECT_ID];
    $component = $row_bug[COMPONENT_NAME];
    $priority = $row_bug[BUG_PRIORITY];
    $severity = $row_bug[BUG_SEVERITY];
    $bug_status = $row_bug[BUG_STATUS];
    $reporter = $row_bug[BUG_REPORTER];
    $reported_date = $row_bug[BUG_REPORTED_DATE];
    $assigned_to = $row_bug[BUG_ASSIGNED_TO];
    $assigned_to_developer = $row_bug[BUG_ASSIGNED_TO_DEVELOPER];
    $closed = $row_bug[BUG_CLOSED];
    $closed_date = $row_bug[BUG_CLOSED_DATE];
    $test_verify_id = $row_bug[BUG_TEST_VERIFY_ID];
    $req_version_id = $row_bug[BUG_REQ_VERSION_ID];
    $found_in_release = $row_bug[BUG_FOUND_IN_RELEASE];
    $assign_to_release = $row_bug[BUG_ASSIGN_TO_RELEASE];
    $imp_in_release = $row_bug[BUG_IMPLEMENTED_IN_RELEASE];
    $discovery_period = $row_bug[BUG_DISCOVERY_PERIOD];
    $summary = $row_bug[BUG_SUMMARY];
    $description = $row_bug[BUG_DESCRIPTION];
    $message = "";
    # CREATE EMAIL SUBJECT AND MESSAGE
    switch ($action) {
        case "new_bug":
            $subject = "RTH: New defect entered for {$project_name} - ID: {$bug_id}";
            $message = "A New Defect has been entered by {$first_name} {$last_name}\r" . NEWLINE;
            break;
        case "update_status":
            $subject = "RTH: Status of Bug in {$project_name} has changed to {$bug_status} - ID: {$bug_id}";
            $message = "The status of bug  has been changed to {$bug_status} by {$first_name} {$last_name}\n" . NEWLINE;
            break;
        case "add_bugnote":
            $subject = "RTH: A bugnote was added to a Bug in {$project_name} - ID: {$bug_id}";
            $message = "A bugnote has been added by {$first_name} {$last_name}\n" . NEWLINE;
            break;
        case "assign_bug":
            $subject = "RTH: Bug in {$project_name} has been assigned - ID: {$bug_id}";
            $message = "The bug  has been assigned by {$first_name} {$last_name}\n" . NEWLINE;
            break;
        case "add_relationship":
            $subject = "RTH: New relationship created for bug in project: {$project_name} - ID: {$bug_id}";
            $message = "A new relationship was created by {$first_name} {$last_name}\n" . NEWLINE;
            break;
        case "update_bug":
            $subject = "RTH: Bug in project: {$project_name} has been updated - ID: {$bug_id}";
            $message = "Bug has been updated by {$first_name} {$last_name}\n" . NEWLINE;
            break;
        case "delete":
            $subject = "RTH: Bug Deleted in {$project_name}";
            $message = "Bug {$req_name} has been deleted by {$first_name} {$last_name}\n" . NEWLINE;
            break;
    }
    # Generic link to requirement detail page if the $url variable has been set
    $message .= "Click the following link to view the Defect:\r" . NEWLINE;
    $message .= "{$generic_url}\r\n\r" . NEWLINE;
    $message .= lang_get('project_name') . ": {$project_name}\r" . NEWLINE;
    $message .= lang_get('bug_category') . ": {$category}\r" . NEWLINE;
    $message .= lang_get('bug_component') . ": {$component}\r" . NEWLINE;
    $message .= lang_get('bug_priority') . ": {$priority}\r" . NEWLINE;
    $message .= lang_get('bug_severity') . ": {$severity}\r" . NEWLINE;
    $message .= lang_get('bug_status') . ": {$bug_status}\r" . NEWLINE;
    $message .= lang_get('reported_by') . ": {$reporter}\r" . NEWLINE;
    $message .= lang_get('reported_date') . ": {$reported_date}\r" . NEWLINE;
    $message .= lang_get('assigned_to') . ": {$assigned_to}\r" . NEWLINE;
    $message .= lang_get('assigned_to_developer') . ": {$assigned_to_developer}\r" . NEWLINE;
    $message .= lang_get('found_in_release') . ": {$found_in_release}\r" . NEWLINE;
    $message .= lang_get('assigned_to_release') . ": {$assign_to_release}\r" . NEWLINE;
    $message .= lang_get('bug_summary') . ": {$summary}\r\n\r" . NEWLINE;
    $message .= lang_get('bug_description') . ": {$description}\r" . NEWLINE;
    # Convert any html entities stored in the DB back to characters.
    $message = util_unhtmlentities($message);
    email_send($recipients, $subject, $message);
}