function admin_release_signoff($release_id, $qa_status, $qa_comments)
{
    global $db;
    $release_tbl = RELEASE_TBL;
    $f_release_id = RELEASE_ID;
    $f_qa_status = RELEASE_QA_SIGNOFF;
    $f_qa_signoff_date = RELEASE_QA_SIGNOFF_DATE;
    $f_qa_signoff_by = RELEASE_QA_SIGNOFF_BY;
    $f_qa_comments = RELEASE_QA_SIGNOFF_COMMENTS;
    /*
    $f_ba_status			= RELEASE_BA_SIGNOFF;
    $f_ba_signoff_date		= RELEASE_BA_SIGNOFF_DATE;
    $f_ba_signoff_by		= RELEASE_BA_SIGNOFF_BY;
    $f_ba_comments			= RELEASE_BA_SIGNOFF_COMMENTS;
    $f_release_desc			= RELEASE_DESCRIPTION;
    */
    $current_date = date_get_short_dt();
    $username = session_get_username();
    $q = "UPDATE {$release_tbl}\n\t      SET \n\t\t\t  {$f_qa_signoff_date} = '{$current_date}',\n\t\t\t  {$f_qa_signoff_by} = '{$username}',\n\t\t\t  {$f_qa_status} = '{$qa_status}',\n\t\t\t  {$f_qa_comments} = '{$qa_comments}'\n\t\t  WHERE\n\t\t\t  {$f_release_id} = '{$release_id}'";
    db_query($db, $q);
}
# Copyright (C) 2005 George Holbrook - rth@lists.sourceforge.net
# This program is distributed under the terms and conditions of the GPL
# See the README and LICENSE files for details
#----------------------------------------------------------------------
# ---------------------------------------------------------------------
# Requirement Edit Page
#
# $RCSfile: requirement_edit_page.php,v $  $Revision: 1.9 $
# ---------------------------------------------------------------------
include "./api/include_api.php";
auth_authenticate_user();
$page = basename(__FILE__);
$project_properties = session_get_project_properties();
$project_id = $project_properties['project_id'];
$project_name = $project_properties['project_name'];
$username = session_get_username();
$display_options = session_set_display_options("requirements", array_merge($_POST, $_GET));
$s_tab = $display_options['tab'];
$s_properties = session_set_properties("requirements", $_GET);
$s_req_id = $s_properties['req_id'];
$s_req_version_id = $s_properties['req_version_id'];
html_window_title();
html_print_body();
html_page_title($project_name . " - REQUIREMENT DETAIL");
html_page_header($db, $project_name);
html_print_menu();
requirement_menu_print($page);
error_report_check($_GET);
$rows_requirement = requirement_get_detail($project_id, $s_req_id, $s_req_version_id);
$row_requirement = $rows_requirement[0];
$req_version_id = $row_requirement[REQ_VERS_UNIQUE_ID];
function results_email($project_id, $release_id, $build_id, $testset_id, $test_id, $recipients, $action)
{
    $display_generic_info = true;
    $display_generic_url = true;
    $generic_url = RTH_URL . "login.php?project_id={$project_id}&page=results_test_run_page.php&release_id={$release_id}&build_id={$build_id}&testset_id={$testset_id}&test_id={$test_id}";
    $username = session_get_username();
    $project_name = session_get_project_name();
    $release_name = admin_get_release_name($release_id);
    $build_name = admin_get_build_name($build_id);
    $testset_name = admin_get_testset_name($testset_id);
    $user_details = user_get_name_by_username($username);
    $first_name = $user_details[USER_FNAME];
    $last_name = $user_details[USER_LNAME];
    $row_test_detail = testset_query_test_details($testset_id, $test_id);
    $test_name = $row_test_detail[TEST_NAME];
    $status = $row_test_detail[TEST_TS_ASSOC_STATUS];
    $finished = $row_test_detail[TEST_TS_ASSOC_FINISHED];
    $assigned_to = $row_test_detail[TEST_TS_ASSOC_ASSIGNED_TO];
    $comments = $row_test_detail[TEST_TS_ASSOC_COMMENTS];
    $root_cause = $row_test_detail[TEST_RESULTS_ROOT_CAUSE];
    # CREATE EMAIL SUBJECT AND MESSAGE
    switch ($action) {
        case "test_run":
            $subject = "RTH: Test Run Notification - {$test_name}";
            $message = "Test {$test_name} has been run by {$first_name} {$last_name}\n" . NEWLINE;
            break;
        case "update_test_result":
            $subject = "RTH: Test Result has been Updated";
            $message = "The test result for {$test_name} has been updated by {$first_name} {$last_name}\n" . NEWLINE;
            break;
    }
    # Generic link to results page if the $generic_url variable has been set
    if ($display_generic_url) {
        $message .= "Click the following link to view the Test Results:" . NEWLINE;
        $message .= "{$generic_url}\n" . NEWLINE;
    }
    if ($display_generic_info) {
        $message .= "Project Name: {$project_name}\r" . NEWLINE;
        $message .= "Release Name: {$release_name}\r" . NEWLINE;
        $message .= "Build Name: {$build_name}\r" . NEWLINE;
        $message .= "TestSet Name: {$testset_name}\r\n\r" . NEWLINE;
        $message .= "Test Name: {$test_name}\r" . NEWLINE;
        $message .= "Status: {$status}\r" . NEWLINE;
        if (!empty($root_cause)) {
            $message .= "Root Cause: {$root_cause}\r" . NEWLINE;
        }
        $message .= "Comments: {$comments}\r\n\r" . NEWLINE;
    }
    email_send($recipients, $subject, $message);
}
function session_set_user_projects()
{
    $tbl_project = PROJECT_TBL;
    $f_proj_id = $tbl_project . "." . PROJ_ID;
    $f_proj_name = $tbl_project . "." . PROJ_NAME;
    $f_proj_deleted = $tbl_project . "." . PROJ_DELETED;
    $tbl_user = USER_TBL;
    $f_user_id = $tbl_user . "." . USER_ID;
    $f_username = $tbl_user . "." . USER_UNAME;
    $f_tempest_admin = $tbl_user . "." . USER_ADMIN;
    $f_user_default_project = $tbl_user . "." . USER_DEFAULT_PROJECT;
    $tbl_proj_user_assoc = PROJECT_USER_ASSOC_TBL;
    $f_proj_user_proj_id = $tbl_proj_user_assoc . "." . PROJ_USER_PROJ_ID;
    $f_proj_user_user_id = $tbl_proj_user_assoc . "." . PROJ_USER_USER_ID;
    $username = session_get_username();
    global $db;
    $q = "\tSELECT\t{$f_tempest_admin}\n\t\t\tFROM\t{$tbl_user}\n\t\t\tWHERE\t{$f_username} = '{$username}'";
    # tempest administrator
    if (db_get_one($db, $q) == "Y") {
        $q = "\tSELECT\t{$f_proj_name}\n\t\t\t\tFROM\t{$tbl_project}\n\t\t\t\tWHERE {$f_proj_deleted} = 'N'\n\t\t\t\tORDER BY {$f_proj_name} ASC";
    } else {
        # tempest user
        $q = "\tSELECT\t{$f_proj_name}\n\t\t\t\tFROM\t{$tbl_project}\n\t\t\t\tINNER JOIN {$tbl_proj_user_assoc} ON {$f_proj_id} = {$f_proj_user_proj_id}\n\t\t\t\tINNER JOIN {$tbl_user} ON {$f_proj_user_user_id} = {$f_user_id}\n\t\t\t\tWHERE {$f_username} = '{$username}'\n\t\t\t\tAND {$f_proj_deleted} = 'N'\n\t\t\t\tORDER BY {$f_proj_name} ASC";
    }
    $rows = db_fetch_array($db, db_query($db, $q));
    $project_array = array();
    foreach ($rows as $row) {
        $project_array[] = $row[PROJ_NAME];
    }
    $_SESSION['s_user_projects'] = $project_array;
}
$page = basename(__FILE__);
$action_page = 'news_add_action.php';
$project_properties = session_get_project_properties();
$project_name = $project_properties['project_name'];
$project_id = $project_properties['project_id'];
$form_name = "add_news";
$news_id = $_POST['news_id'];
html_window_title();
html_print_body($form_name, 'release_edit_name_required');
html_page_title($project_name . " - " . lang_get('news_add_page'));
html_page_header($db, $project_name);
html_print_menu();
print "<div align=center>" . NEWLINE;
print "<form method=post name={$form_name} action={$action_page}>" . NEWLINE;
print "<input type=hidden name=project_id value={$project_id}>" . NEWLINE;
print "<input type=hidden name=poster value='" . session_get_username() . "'>" . NEWLINE;
print "<span class='required'>*</span> <span class='print'>" . lang_get('must_complete_field') . "</span>" . NEWLINE;
print "<table class=width80>" . NEWLINE;
print "<tr>" . NEWLINE;
print "<td>" . NEWLINE;
print "<table class=inner>" . NEWLINE;
# SUBJECT
print "<tr>" . NEWLINE;
print "<td class=right>" . lang_get('subject') . " <span class='required'>*</span></td>" . NEWLINE;
print "<td class=left>" . NEWLINE;
print "<input type='text' maxlength='100' name='subject_required' size=100 value='" . session_validate_form_get_field('subject_required') . "'>" . NEWLINE;
print "</td>" . NEWLINE;
print "</tr>" . NEWLINE;
# DESCRIPTION
print "<tr>" . NEWLINE;
print "<td class=right>" . lang_get('description') . " <span class='required'>*</span></td>" . NEWLINE;
function test_compose_email($project_id, $test_id, $recipients, $action)
{
    $display_generic_info = true;
    $display_generic_url = true;
    $generic_url = RTH_URL . "login.php?project_id={$project_id}&page=test_detail_page.php&test_id={$test_id}&project_id={$project_id}";
    $username = session_get_username();
    $project_name = session_get_project_name();
    $user_details = user_get_name_by_username($username);
    $first_name = $user_details[USER_FNAME];
    $last_name = $user_details[USER_LNAME];
    $test_detail = test_get_detail($test_id);
    $test_name = $test_detail[TEST_NAME];
    $status = $test_detail[TEST_STATUS];
    $priority = $test_detail[TEST_PRIORITY];
    $test_area = $test_detail[TEST_AREA_TESTED];
    $test_type = $test_detail[TEST_TESTTYPE];
    $ba_owner = $test_detail[TEST_BA_OWNER];
    $qa_owner = $test_detail[TEST_QA_OWNER];
    $assigned_to = $test_detail[TEST_ASSIGNED_TO];
    $comments = $test_detail[TEST_COMMENTS];
    # CREATE EMAIL SUBJECT AND MESSAGE
    switch ($action) {
        case "status_change":
            $subject = "RTH: {$test_name} - Test Status Change";
            $message = "The test status of {$test_name} has been updated by {$first_name} {$last_name}\r\n" . NEWLINE;
            break;
        case "steps_uploaded":
            $subject = "RTH: {$test_name} - Test Steps Added";
            $message = "Test Steps have been uploaded to {$test_name} by {$first_name} {$last_name}\r\n" . NEWLINE;
            break;
    }
    # Generic link to results page if the $generic_url variable has been set
    if ($display_generic_url) {
        $message .= "Click the following link to view the Test Results:" . NEWLINE;
        $message .= "{$generic_url}\n" . NEWLINE;
    }
    if ($display_generic_info) {
        $message .= "Project Name: {$project_name}\r" . NEWLINE;
        $message .= "Test Name: {$test_name}\r" . NEWLINE;
        $message .= "Status: {$status}\r" . NEWLINE;
        $message .= "Priority: {$priority}\r\n\r" . NEWLINE;
        $message .= "Test Area: {$test_name}\r" . NEWLINE;
        $message .= "Test Type: {$test_area}\r" . NEWLINE;
        $message .= "BA Owner: {$ba_owner}\r" . NEWLINE;
        $message .= "QA Owner: {$qa_owner}\r" . NEWLINE;
        $message .= "Assigned To: {$assigned_to}\r" . NEWLINE;
        $message .= "Comments: {$comments}\r\n\r" . NEWLINE;
    }
    email_send($recipients, $subject, $message);
}
if (!empty($pm)) {
    $project_name = project_get_name($project_id);
} else {
    error_report_show('login.php', PROJECT_NOT_EXISTS);
}
if (!user_has_rights($project_id, $s_user_id, USER)) {
    error_report_show('login.php', NO_RIGHTS_TO_VIEW_PROJECT);
}
if (!test_id_exists($project_id, $test_id)) {
    error_report_show('login.php', TEST_NOT_EXISTS);
}
session_set_new_project_name($project_name);
session_reset_project();
session_initialize();
session_setLogged_in(TRUE);
session_set_application_details($project_name, session_get_username());
$s_user_properties = session_get_user_properties();
$s_project_properties = session_get_project_properties();
$s_show_options = session_get_show_options();
$s_test_details = session_set_properties("test", $_GET);
$teststep_display_options = session_set_display_options("test_steps", $_POST);
$s_user_id = $s_user_properties['user_id'];
$s_username = $s_user_properties['username'];
$s_tempest_admin = $s_user_properties['tempest_admin'];
$s_project_rights = $s_user_properties['project_rights'];
$s_delete_rights = $s_user_properties['delete_rights'];
$s_email = $s_user_properties['email'];
$order_by = $teststep_display_options['order_by'];
$order_dir = $teststep_display_options['order_dir'];
#$project_name           = $s_project_properties['project_name'];
#$project_id				= $s_project_properties['project_id'];
function file_add_bug_file($upload_file_temp_name, $upload_file_name, $bug_id, $redirect_page)
{
    global $db;
    $bug_file_tbl = BUG_FILE_TBL;
    $f_bug_id = BUG_FILE_TBL . "." . BUG_FILE_BUG_ID;
    $f_uploaded_by = BUG_FILE_TBL . "." . BUG_FILE_UPLOAD_DATE;
    $f_uploaded_date = BUG_FILE_TBL . "." . BUG_FILE_UPLOAD_BY;
    $f_display_name = BUG_FILE_TBL . "." . BUG_FILE_DISPLAY_NAME;
    $f_file_name = BUG_FILE_TBL . "." . BUG_FILE_NAME;
    $uploaded_by = session_get_username();
    $current_date = date("Y-m-d H:i:s");
    $project_properties = session_get_project_properties();
    $file_upload_dir = $project_properties['defect_upload_path'];
    # create a unique name for the file using the time function
    $file_db_name = "BugFile" . time() . "-{$upload_file_name}";
    # Throw error if user didn't enter a file name
    if (!isset($upload_file_temp_name) || !is_uploaded_file($upload_file_temp_name)) {
        error_report_show($redirect_page, REQUIRED_FIELD_MISSING);
    }
    # Insert a record into the bugfile table if the file upload was successful
    if (move_uploaded_file($upload_file_temp_name, $file_upload_dir . $file_db_name)) {
        $q = "INSERT INTO {$bug_file_tbl}\n\t\t\t\t( {$f_bug_id}, {$f_uploaded_by}, {$f_uploaded_date}, {$f_display_name}, {$f_file_name})\n\t\t\t  VALUES\n\t\t\t\t('{$bug_id}', '{$uploaded_by}', '{$current_date}', '{$upload_file_name}', '{$file_db_name}')";
        //print"$q<br>";
        db_query($db, $q);
    }
}
function requirement_email($project_id, $req_id, $recipients, $action, $discussion_id = null)
{
    $display_generic_info = true;
    $display_generic_url = true;
    # Link to the req detail page
    $generic_url = RTH_URL . "login.php?project_id={$project_id}&page=requirement_detail_page.php&req_id={$req_id}";
    $username = session_get_username();
    $project_name = session_get_project_name();
    $req_id = util_pad_id($req_id);
    $user_details = user_get_name_by_username($username);
    $first_name = $user_details[USER_FNAME];
    $last_name = $user_details[USER_LNAME];
    $rows_requirement = requirement_get_detail($project_id, $req_id);
    $row_requirement = $rows_requirement[0];
    $req_version_id = $row_requirement[REQ_VERS_UNIQUE_ID];
    $req_rec_or_file = $row_requirement[REQ_REC_FILE];
    $req_name = $row_requirement[REQ_FILENAME];
    $req_detail = $row_requirement[REQ_VERS_DETAIL];
    $req_reason_for_change = $row_requirement[REQ_VERS_REASON_CHANGE];
    $req_version_status = $row_requirement[REQ_VERS_STATUS];
    $req_area_covered = $row_requirement[REQ_AREA_COVERAGE];
    $req_doc_type = $row_requirement[REQ_DOC_TYPE_NAME];
    $req_version = $row_requirement[REQ_VERS_VERSION];
    # REQ FUNCTIONALITY
    $rows_functions = requirement_get_functionality($project_id, $req_id);
    $req_functionality = "";
    foreach ($rows_functions as $function) {
        $req_functionality .= $function . ", ";
    }
    $req_functionality = trim($req_functionality, ", ");
    # CREATE EMAIL SUBJECT AND MESSAGE
    switch ($action) {
        case "updated":
            $subject = "RTH: Requirement Updated in {$project_name}";
            $message = "Requirement {$req_name} has been updated by {$first_name} {$last_name}\n" . NEWLINE;
            break;
        case "new_version":
            $subject = "RTH: Requirement Updated in {$project_name}";
            $message = "A new version of Requirement {$req_name} has been created by {$first_name} {$last_name}\n" . NEWLINE;
            break;
        case "delete":
            $display_generic_info = false;
            $display_generic_url = false;
            $url = RTH_URL . "login.php?project_id={$project_id}&page=requirement_page.php";
            $subject = "RTH: Requirement Deleted in {$project_name}";
            $message = "Requirement {$req_name} has been deleted by {$first_name} {$last_name}\n" . NEWLINE;
            $message .= "Click the following link to view Requirements in {$project_name}:" . NEWLINE;
            $message .= "{$url}\n" . NEWLINE;
            break;
        case "lock":
            $subject = "RTH: Requirement Locked in {$project_name}";
            $message = "Requirement {$req_name} has been locked by {$first_name} {$last_name}\n" . NEWLINE;
            break;
        case "unlock":
            $subject = "RTH: Requirement Unlocked in {$project_name}";
            $message = "Requirement {$req_name} has been unlocked by {$first_name} {$last_name}\n" . NEWLINE;
            break;
        case "edit_children":
            # Get requirement children
            //$rows_children = requirement_get_children($req_id);
            $generic_url .= "&tab=1";
            $subject = "RTH: Requirement Updated in {$project_name}";
            $message = "The children of Requirement {$req_name} have been edited by {$first_name} {$last_name}\n" . NEWLINE;
            break;
        case "edit_test_assoc":
            # Get related tests
            //$assoc_tests = requirement_get_test_relationships($req_id);
            $generic_url .= "&tab=2";
            $subject = "RTH: Requirement Updated in {$project_name}";
            $message = "The Tests related to Requirement {$req_name} have been edited by {$first_name} {$last_name}\n" . NEWLINE;
            break;
        case "edit_release_assoc":
            # Get related releases
            //requirement_get_assoc_releases($s_req_version_id)
            $generic_url .= "&tab=4";
            $subject = "RTH: Requirement Updated in {$project_name}";
            $message = "The Releases related to Requirement {$req_name} have been edited by {$first_name} {$last_name}\n" . NEWLINE;
            break;
        case "new_discussion":
            # GET LAST DISCUSSION
            $rows_discussion = discussion_get($req_id);
            foreach ($rows_discussion as $row_discussion) {
                $discussion_subject = $row_discussion[DISC_SUBJECT];
            }
            $generic_url .= "&tab=3";
            $subject = "RTH: New Requirement Discussion in {$project_name}";
            $message = "A new discussion has been added to Requirement {$req_name} by {$first_name} {$last_name}\n" . NEWLINE;
            $message .= "" . lang_get("subject") . ": {$discussion_subject}\n" . NEWLINE;
            break;
        case "new_post":
            # GET DISCUSSION
            $row_discussion = discussion_get_detail($discussion_id);
            $discussion_subject = $row_discussion[DISC_SUBJECT];
            $url = RTH_URL . "login.php?project_id={$project_id}&page=requirement_discussion_page.php&discussion_id={$discussion_id}";
            $subject = "RTH: Discussion {$discussion_subject} in {$project_name}";
            $message = "A new post has been added to Discussion {$discussion_subject} by {$first_name} {$last_name}\n" . NEWLINE;
            $message .= "Click the following link to view the discussion:\n" . NEWLINE;
            $message .= "{$url}\n" . NEWLINE;
            break;
        case "close_discussion":
            $display_generic_info = false;
            $display_generic_url = false;
            # GET DISCUSSION
            $row_discussion = discussion_get_detail($discussion_id);
            $discussion_subject = $row_discussion[DISC_SUBJECT];
            $url = RTH_URL . "login.php?project_id={$project_id}&page=requirement_discussion_page.php&discussion_id={$discussion_id}";
            $subject = "RTH: Discussion {$discussion_subject} in {$project_name}";
            $message = "Discussion {$discussion_subject} has been closed by {$first_name} {$last_name}\n" . NEWLINE;
            $message .= "Click the following link to view the discussion:" . NEWLINE;
            $message .= "{$url}\n" . NEWLINE;
            break;
    }
    # Generic link to requirement detail page if the $url variable has been set
    if ($display_generic_url) {
        $message .= "Click the following link to view the Requirement:" . NEWLINE;
        $message .= "{$generic_url}\n" . NEWLINE;
    }
    if ($display_generic_info) {
        $message .= "" . lang_get("project_name") . ": {$project_name}" . NEWLINE;
        $message .= "" . lang_get("req_id") . ": {$req_id}" . NEWLINE;
        $message .= "" . lang_get("req_version") . ": {$req_version}" . NEWLINE;
        $message .= "" . lang_get("req_name") . ": {$req_name}" . NEWLINE;
        $message .= "" . lang_get("req_detail") . ": {$req_detail}" . NEWLINE;
        $message .= "" . lang_get("req_status") . ": {$req_version_status}" . NEWLINE;
        $message .= "" . lang_get("req_area_covered") . ": {$req_area_covered}" . NEWLINE;
        $message .= "" . lang_get("req_functionality") . ": {$req_functionality}" . NEWLINE;
        $message .= "" . lang_get("req_doc_type") . ": {$req_doc_type}\n" . NEWLINE;
    }
    # Convert any html entities stored in the DB back to characters.
    $message = util_unhtmlentities($message);
    email_send($recipients, $subject, $message);
}
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);
}
function testset_email($project_id, $release_id, $build_id, $testset_id, $recipients, $action)
{
    $display_generic_info = true;
    $display_generic_url = true;
    $generic_url = RTH_URL . "login.php?project_id={$project_id}&page=results_page.php&release_id={$release_id}&build_id={$build_id}&testset_id={$testset_id}";
    $username = session_get_username();
    $project_name = session_get_project_name();
    $release_name = admin_get_release_name($release_id);
    $build_name = admin_get_build_name($build_id);
    $user_details = user_get_name_by_username($username);
    $first_name = $user_details[USER_FNAME];
    $last_name = $user_details[USER_LNAME];
    $testset_detail = testset_get_details_by_build($build_id, $testset_id);
    $testset_id = $testset_detail[TS_ID];
    $testset_name = $testset_detail[TS_NAME];
    $testset_date_created = $testset_detail[TS_DATE_CREATED];
    $testset_description = $testset_detail[TS_DESCRIPTION];
    # CREATE EMAIL SUBJECT AND MESSAGE
    switch ($action) {
        case "new_testset":
            $subject = "RTH: New TestSet for {$project_name}";
            $message = "TestSet {$testset_name} has been created by {$first_name} {$last_name}" . NEWLINE . NEWLINE;
            break;
    }
    # Generic link to results page if the $generic_url variable has been set
    if ($display_generic_url) {
        $message .= "Click the following link to view results:" . NEWLINE . NEWLINE;
        $message .= "{$generic_url}" . NEWLINE . NEWLINE;
        $message .= "Please update automated scripts with TESTSETID={$testset_id}" . NEWLINE . NEWLINE;
    }
    if ($display_generic_info) {
        $message .= "" . lang_get("project_name") . ": {$project_name}" . NEWLINE;
        $message .= "" . lang_get("release") . ": {$release_name}" . NEWLINE;
        $message .= "" . lang_get("build") . ": {$build_name}" . NEWLINE;
        $message .= "" . lang_get("testset_name") . ": {$testset_name}" . NEWLINE;
        $message .= "" . lang_get("description") . ": {$testset_description}" . NEWLINE;
        $message .= NEWLINE . "If you do not wish to be notified of any new testsets created, please edit your User profile by navigating to the Users link in RTH.";
    }
    # Convert any html entities stored in the DB back to characters.
    $message = util_unhtmlentities($message);
    email_send($recipients, $subject, $message);
}