# ---------------------------------------------------------------------
include "./api/include_api.php";
auth_authenticate_user();
$page = basename(__FILE__);
$action_page = 'results_group_action.php';
$project_properties = session_get_project_properties();
$project_name = $project_properties['project_name'];
$project_id = $project_properties['project_id'];
$s_properties = session_get_properties("results");
$testset_id = $s_properties['testset_id'];
html_window_title();
html_print_body();
html_page_title($project_name . " - " . lang_get('results_mass_update_page'));
html_page_header($db, $project_name);
html_print_menu();
html_test_results_menu($db, $page, $project_id, $s_properties);
$ids = "" . NEWLINE;
# if submit from test_page.php
if (isset($_POST['mass_update']) && isset($_POST['row_results_arr'])) {
    $field = $_POST['action'];
    foreach ($_POST['row_results_arr'] as $key => $value) {
        $ids .= $key . ":";
    }
} else {
    error_report_show("results_page.php", NO_TESTS_SELECTED);
}
print "<br>" . NEWLINE;
print "<form method=post action={$action_page}>" . NEWLINE;
print "<div align=center>" . NEWLINE;
print "<table class=width50>" . NEWLINE;
print "<tr>" . NEWLINE;
$i = 0;
$num = 0;
$row_style = '';
html_window_title();
html_print_body();
html_page_title($project_name . " - " . lang_get('test_results_page'));
html_page_header($db, $project_name);
# --------------------------------------------------
# Maybe make a get_session_test_results_option function with each of the functions below
# It would then set the release_id, build_id, and testset_id each time the page is called
#----------------------------------------------------
# set the filter session variables if the user submits the filter form
$table_options = session_set_display_options("results", $_POST);
$s_properties = session_set_properties("results", $_GET);
html_print_menu();
html_test_results_menu($db, $page, $project_id, $s_properties, $table_options);
print "<br>" . NEWLINE;
if (!empty($s_properties['testset_id']) && $s_properties['testset_id'] != 'all') {
    $testset_id = $s_properties['testset_id'];
    // ------------------------------------------------------------
    // run query to make sure there are tests in the testset.
    // if not, dont show all the forms and filters below
    //--------------------------------------------------------------
    $locked = testset_get_lock_status($testset_id);
    print "<table class='hide100'>" . NEWLINE;
    print "<tr>" . NEWLINE;
    print "<td width='50%'>&nbsp;</td>" . NEWLINE;
    print "<td width='25%' align='right'><a href='results_run_autopass.php?testset_id={$testset_id}' target='_blank'>" . lang_get('run_autopass') . "</td>" . NEWLINE;
    print "<td width='25%' align='right'><a href='results_display_est_test_time.php?testset_id={$testset_id}' target='_blank'>" . lang_get('est_time') . "</td>" . NEWLINE;
    print "</tr>" . NEWLINE;
    print "</table>" . NEWLINE;
    $s_results = session_set_properties("results", $_GET);
    $testset_id = $s_results['testset_id'];
    $test_id = $s_results['test_id'];
} else {
    # coming from redirect etc, get stored testset_id and test_run_id
    $s_results = session_get_properties("results");
    $testset_id = $s_results['testset_id'];
    $test_id = $s_results['test_id'];
}
$locked = testset_get_lock_status($testset_id);
html_window_title();
html_print_body();
html_page_title($project_name . " - " . lang_get('test_results'));
html_page_header($db, $project_name);
html_print_menu();
html_test_results_menu($db, $results_page, $project_id, session_get_properties("results", $_GET));
error_report_check($_GET);
if ($locked) {
    print "<h3 class='hint'> <img src='images/locked.png' alt='locked'> Testset locked</h3>" . NEWLINE;
}
$row_test_detail = test_get_detail($test_id);
if (!empty($row_test_detail)) {
    //results_print_test_detail_table( $row_test_detail );
    print "<table class=width100 rules=cols>";
    print "<tr class='tbl_header'>";
    html_tbl_print_header(lang_get('test_id'));
    html_tbl_print_header(lang_get('test_name'));
    html_tbl_print_header(lang_get('ba_owner'));
    html_tbl_print_header(lang_get('qa_owner'));
    html_tbl_print_header(lang_get('area_tested'));
    print "</tr>";
# Set the session vars if coming from the bug_page
# We need to do this because the bug page contains only the verification id
if (isset($_GET['bug_page'])) {
    $results_page_vars = results_build_session_data_from_verification_id($_GET['verify_id']);
}
$s_results = session_set_properties("results", $_GET);
$testset_id = $s_results['testset_id'];
//$test_id 		= $s_results['test_id'];
$test_run_id = $s_results['test_run_id'];
$locked = testset_get_lock_status($testset_id);
html_window_title();
html_print_body();
html_page_title($project_name . " - " . lang_get('test_results'));
html_page_header($db, $project_name);
html_print_menu();
html_test_results_menu($db, $row_results_page, $project_id, $s_results);
print "<div align=center>" . NEWLINE;
error_report_check($_GET);
$test_results_details = results_get_test_results_detail($test_run_id);
if ($locked) {
    print "<h3 class='hint'> <img src='images/locked.png' alt='locked'> Testset locked</h3>" . NEWLINE;
}
if (!empty($test_results_details)) {
    print "<table class=width100 rules=cols>" . NEWLINE;
    print "<tr class=tbl_header>" . NEWLINE;
    html_tbl_print_header(lang_get('test_run_id'));
    html_tbl_print_header(lang_get('test_name'));
    //html_tbl_print_header( lang_get('time_started') );
    //html_tbl_print_header( lang_get('time_finished') );
    //html_tbl_print_header( lang_get('finished') );
    //html_tbl_print_header( lang_get('machine_name') );