function html_release_map($map)
{
    $release_properties = session_get_properties("release");
    $html_top_row = "<tr>" . NEWLINE;
    $html_bottom_row = "<tr>" . NEWLINE;
    foreach ($map as $key) {
        switch ($key) {
            case "release_link":
                $release_name = admin_get_release_name($release_properties['release_id']);
                $html_top_row .= "<td class='sub_menu' nowrap>";
                $html_top_row .= "<b><a href=release_page.php>" . lang_get('release_name') . "</a></b>";
                $html_top_row .= "</td>" . NEWLINE;
                $html_bottom_row .= "<td class='sub_menu' nowrap>";
                $html_bottom_row .= "{$release_name}";
                $html_bottom_row .= "</td>" . NEWLINE;
                break;
            case "build_link":
                $build_name = admin_get_build_name($release_properties['build_id']);
                $html_top_row .= "<td class='sub_menu' nowrap>";
                $html_top_row .= "<b><a href=build_page.php>" . lang_get('build_name') . "</a></b>";
                $html_top_row .= "</td>" . NEWLINE;
                $html_bottom_row .= "<td class='sub_menu' nowrap>";
                $html_bottom_row .= "{$build_name}";
                $html_bottom_row .= "</td>" . NEWLINE;
                break;
            case "testset_link":
                $testset_name = admin_get_testset_name($release_properties['testset_id']);
                $html_top_row .= "<td class='sub_menu' nowrap>";
                $html_top_row .= "<b><a href=testset_page.php>" . lang_get('testset_name') . "</a></b>";
                $html_top_row .= "</td>" . NEWLINE;
                $html_bottom_row .= "<td class='sub_menu' nowrap>";
                $html_bottom_row .= "{$testset_name}";
                $html_bottom_row .= "</td>" . NEWLINE;
                break;
            case "copy_testset_link":
                $testset_name = admin_get_testset_name($release_properties['testset_id']);
                $html_top_row .= "<td class='sub_menu' rowspan=2 nowrap>";
                $html_top_row .= "<b><a href=testset_page.php>" . lang_get('copy_testset_to') . "</a></b>";
                $html_top_row .= "</td>" . NEWLINE;
                $html_bottom_row .= "<td></td>" . NEWLINE;
                break;
            default:
                $html_top_row .= "<td class='sub_menu' nowrap><b>{$key}</b></td>" . NEWLINE;
                $html_bottom_row .= "<td></td>" . NEWLINE;
        }
        $html_top_row .= "<td class='sub_menu' rowspan=2 nowrap>&nbsp;</td>" . NEWLINE;
    }
    $html_top_row .= "</tr>" . NEWLINE;
    $html_bottom_row .= "</tr>" . NEWLINE;
    print "<table width=1 cellspacing=2>" . NEWLINE;
    print $html_top_row;
    print $html_bottom_row;
    print "</table>" . NEWLINE;
}
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);
}
print "<input type='hidden' name=req_ids value='{$req_ids}'>";
print "<table class=width50>" . NEWLINE;
print "<tr>" . NEWLINE;
print "<td>" . NEWLINE;
print "<table class=inner>" . NEWLINE;
# FORM TITLE
print "<tr>" . NEWLINE;
print "<td class='form-data-l'><h4>" . lang_get('assign_to_release') . "</h4></td>" . NEWLINE;
print "</tr>" . NEWLINE;
# ASSIGN RELEASE
print "<tr>" . NEWLINE;
print "<td class='form-data-c'>";
print "<select name='assign_release'>" . NEWLINE;
$rows_release = requirement_get_distinct_field($project_id, REQ_VERS_ASSIGN_RELEASE);
for ($i = 0; $i < sizeof($rows_release); $i++) {
    $rows_release_2[admin_get_release_name($rows_release[$i])] = $rows_release[$i];
}
$rows_release_2[""] = "";
html_print_list_box_from_key_array($rows_release_2);
print "</select>" . NEWLINE;
print "</td>" . NEWLINE;
print "</tr>" . NEWLINE;
# SUBMIT BUTTON
print "<tr>" . NEWLINE;
print "<td class='form-data-c'><input type='submit' name=submit_assigned_release value='" . lang_get('update') . "'></td>" . NEWLINE;
print "</tr>" . NEWLINE;
print "</table>" . NEWLINE;
print "</td>" . NEWLINE;
print "</tr>" . NEWLINE;
print "</table>" . NEWLINE;
print "</form>" . NEWLINE;
include "./api/include_api.php";
auth_authenticate_user();
$page = basename(__FILE__);
$form_name = 'add_build';
$action_page = 'build_add_action.php';
$build_edit_page = 'build_edit_page.php';
$testset_page = 'testset_page.php';
$delete_page = 'delete_page.php';
$s_project_properties = session_get_project_properties();
$project_name = $s_project_properties['project_name'];
$project_id = $s_project_properties['project_id'];
$row_style = '';
# Set release build properties in session and assign all values to variable
$s_release_properties = session_set_properties("release", $_GET);
$release_id = $s_release_properties['release_id'];
$release_name = admin_get_release_name($release_id);
$redirect_url = $page . "?release_id=" . $release_id;
$display_options = session_set_display_options("build", $_POST);
$order_by = $display_options['order_by'];
$order_dir = $display_options['order_dir'];
html_window_title();
html_print_body($form_name, 'build_name_required');
html_page_title($project_name . " - " . lang_get('build_page'));
html_page_header($db, $project_name);
html_print_menu();
html_release_map(array("release_link", lang_get("builds")));
error_report_check($_GET);
print "<div align=center>" . NEWLINE;
print "<span class='required'>*</span> <span class='print'>" . lang_get('must_complete_field') . "</span>" . NEWLINE;
print "<table class=width60>" . NEWLINE;
print "<tr>" . NEWLINE;
 $project_num_of_finished_ba = $project_status[9];
 $project_num_of_wr_issue = $project_status[10];
 $pc_tests_not_run = 100 / $project_num_of_tests * ($project_num_of_tests - $testset_num_of_tests);
 $pc_passed_in_project = 100 / $project_num_of_tests * $testset_num_of_passed;
 $pc_failed_in_project = 100 / $project_num_of_tests * $testset_num_of_failed;
 $pc_awaiting_review_in_project = 100 / $project_num_of_tests * $testset_num_of_awaiting_review;
 $pc_wip_in_project = 100 / $project_num_of_tests * $testset_num_of_wip;
 $pc_not_started_in_project = 100 / $project_num_of_tests * $testset_num_of_not_started;
 $pc_not_running_in_project = 100 / $project_num_of_tests * $testset_num_of_not_running;
 $pc_finished_qa_in_project = 100 / $project_num_of_tests * $testset_num_of_finished_qa;
 $pc_finished_ba_in_project = 100 / $project_num_of_tests * $testset_num_of_finished_ba;
 $pc_wr_issue_in_project = 100 / $project_num_of_tests * $testset_num_of_wr_issue;
 # start img pie chart
 print "<img src=\"images/pie_chart_2_image.php";
 # chart title
 print "?graph_title=" . lang_get("status_of") . " " . admin_get_build_name($build_id) . ", " . admin_get_release_name($release_id);
 # legend
 print "&amp;legend='Passed','Failed','Awaiting Review','WIP','Not Running','Not Started','Not Used'";
 if ($project_name == "PCA") {
     print ",'Finished: QA Review', 'Finished: Business Review', 'WinRunner Issue'";
 }
 # pie 1 title
 print "&amp;p1_title=" . lang_get("all_tests_in") . " " . $project_name;
 # pie 1 theme
 if ($project_name == "PCA") {
     print "&amp;p1_theme=pca";
 } else {
     print "&amp;p1_theme=test";
 }
 # pie 1 data
 print "&amp;p1_data={$pc_passed_in_project},{$pc_failed_in_project},{$pc_awaiting_review_in_project},{$pc_wip_in_project},{$pc_not_running_in_project},{$pc_not_started_in_project},{$pc_tests_not_run}";
function admin_add_build($release_id, $build_name, $build_description, $page_name)
{
    global $db;
    $build_tbl = BUILD_TBL;
    $f_release_id = BUILD_REL_ID;
    $f_build_name = BUILD_NAME;
    $f_description = BUILD_DESCRIPTION;
    $f_date = BUILD_DATE_REC;
    $f_archive = BUILD_ARCHIVE;
    $date = date_get_short_dt();
    $archive = 'N';
    $q = "INSERT INTO {$build_tbl}\n\t\t ({$f_build_name}, {$f_description}, {$f_date}, {$f_release_id}, {$f_archive})\n\t\t VALUES\n\t\t ('{$build_name}', '{$build_description}', '{$date}', '{$release_id}', '{$archive}')";
    db_query($db, $q);
    #######################################################################################################
    # Add entry into the log table for the project
    $release_name = admin_get_release_name($release_id);
    $deletion = 'N';
    $creation = 'Y';
    $upload = 'N';
    $action = "ADDED BUILD {$build_name} TO RELEASE {$release_name}";
    log_activity_log($page_name, $deletion, $creation, $upload, $action);
    #logfile entry end
    #######################################################################################################
}
function requirement_get_release($req_version)
{
    global $db;
    $req_rel_tbl = REQ_VERS_ASSOC_REL;
    $f_version_id = $req_rel_tbl . "." . REQ_VERS_ASSOC_REL_REQ_ID;
    $f_release_id = $req_rel_tbl . "." . REQ_VERS_ASSOC_REL_REL_ID;
    $release_name = "";
    $q = "SELECT\n\t\t\t{$f_release_id}\n\t\t FROM\n\t\t\t{$req_rel_tbl}\n\t\t WHERE\n\t\t\t{$f_version_id} = '{$req_version}'";
    $release_id = db_get_one($db, $q);
    if ($release_id != '') {
        $release_name = admin_get_release_name($release_id);
    }
    return $release_name;
}
 html_tbl_print_header(lang_get('release_name'));
 html_tbl_print_header(lang_get('tests'));
 # Display table headers based on the statuses of the project
 foreach ($statuses as $status) {
     html_tbl_print_header($status);
 }
 html_tbl_print_header(lang_get('testset_date_received'));
 print "</tr>" . NEWLINE;
 foreach ($rows_testsets as $row_testset) {
     $testset_id = $row_testset[TS_ID];
     $num_tests = admin_count_tests_in_testset($testset_id);
     $testset_name = admin_get_testset_name($testset_id);
     $testset_build_id = admin_get_build_id_from_testset_id($testset_id);
     $testset_build_name = admin_get_build_name($testset_build_id);
     $testset_release_id = admin_get_release_id_from_build_id($testset_build_id);
     $testset_release_name = admin_get_release_name($testset_release_id);
     $testset_date_created = $row_testset[TS_DATE_CREATED];
     $display_test_id = util_pad_id($testset_id);
     $results_url = $results_page . "?release_id={$testset_release_id}&amp;build_id={$testset_build_id}&amp;testset_id={$testset_id}";
     $row_style = html_tbl_alternate_bgcolor($row_style);
     print "<tr class={$row_style}>" . NEWLINE;
     if ($num_tests > 0) {
         print "<td class='tbl-data-c'><a href='{$results_url}'>{$display_test_id}</a></td>";
     } else {
         print "<td class='tbl-data-c'>{$display_test_id}</td>";
     }
     print "<td class='tbl-data-c'>{$testset_name}</td>";
     print "<td class='tbl-data-c'>{$testset_build_name}</td>";
     print "<td class='tbl-data-c'>{$testset_release_name}</td>";
     print "<td class='tbl-data-c'>{$num_tests}</td>";
     # Display table data based on the statuses of the project as well
print "</tr>" . NEWLINE;
print "<tr>" . NEWLINE;
print "<td nowrap class=grid-header-l>" . lang_get('author') . "</td>" . NEWLINE;
print "<td class=grid-data-l>" . $row_requirement[REQ_VERS_UPLOADED_BY] . "</td>" . NEWLINE;
print "<td nowrap class=grid-header-l>" . lang_get('req_type') . "</td>" . NEWLINE;
print "<td class=grid-data-l>" . $row_requirement[REQ_TYPE] . "</td>" . NEWLINE;
print "</tr>" . NEWLINE;
print "<tr>" . NEWLINE;
print "<td nowrap class=grid-header-l>" . lang_get('req_created') . "</td>" . NEWLINE;
print "<td class=grid-data-l>" . $row_requirement[REQ_VERS_TIMESTAMP] . "</td>" . NEWLINE;
print "<td nowrap class=grid-header-l>" . lang_get('functionality') . "</td>" . NEWLINE;
print "<td class=grid-data-l>" . $row_requirement[REQ_FUNCTIONALITY] . "</td>" . NEWLINE;
print "</tr>" . NEWLINE;
print "<tr>" . NEWLINE;
print "<td nowrap class=grid-header-l>" . lang_get('req_assign_release') . "</td>" . NEWLINE;
print "<td class=grid-data-l>" . admin_get_release_name($row_requirement[REQ_VERS_ASSIGN_RELEASE]) . "</td>" . NEWLINE;
print "<td nowrap class=grid-header-l>" . lang_get('req_locked_by') . "</td>" . NEWLINE;
print "<td class=grid-data-l>" . $row_requirement[REQ_LOCKED_BY] . "</td>" . NEWLINE;
print "</tr>" . NEWLINE;
print "<tr>" . NEWLINE;
print "<td nowrap class=grid-header-l>" . lang_get('assigned_to') . "</td>" . NEWLINE;
print "<td class=grid-data-l>" . $row_requirement[REQ_VERS_ASSIGNED_TO] . "</td>" . NEWLINE;
print "<td nowrap class=grid-header-l>" . lang_get('req_locked_date') . "</td>" . NEWLINE;
print "<td class=grid-data-l>" . $row_requirement[REQ_LOCKED_DATE] . "</td>" . NEWLINE;
print "</tr>" . NEWLINE;
print "<tr>" . NEWLINE;
print "<td nowrap class=grid-header-l></td>" . NEWLINE;
print "<td class=grid-data-l></td>" . NEWLINE;
print "<td nowrap class=grid-header-l>" . lang_get('show_history') . "</td>" . NEWLINE;
print "<td class=grid-data-l><a href='requirement_version_history_page.php?req_id={$s_req_id}'>" . lang_get('history') . "</a></td>" . NEWLINE;
print "</tr>" . NEWLINE;
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);
}
<?php

# ---------------------------------------------------------------------
# rth is a requirement, test, and bugtracking system
# 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
#----------------------------------------------------------------------
# ------------------------------------
# $RCSfile: build_add_action.php,v $  $Revision   $
# ------------------------------------
include "./api/include_api.php";
auth_authenticate_user();
$redirect_page = 'build_page.php';
$build_page = 'build_page.php';
$release_id = session_validate_form_get_field('release_id');
$s_release_properties = session_set_properties("release");
$release_name = admin_get_release_name($s_release_properties['release_id']);
session_validate_form_set($_POST, $redirect_page);
if (admin_build_name_exists($s_release_properties['release_id'], session_validate_form_get_field('build_name_required'))) {
    error_report_show($redirect_page, DUPLICATE_BUILD_NAME);
}
admin_add_build($s_release_properties['release_id'], session_validate_form_get_field('build_name_required'), session_validate_form_get_field('build_description'), "ADD BUILD");
session_validate_form_reset();
html_print_operation_successful('release_page', $redirect_page);
# ------------------------------------
# $Log: build_add_action.php,v $
# Revision 1.1.1.1  2005/11/30 23:00:56  gth2
# importing initial version - gth
#
# ------------------------------------