$test_type = $row[TEST_TESTTYPE];
 $area_tested = $row[TEST_AREA_TESTED];
 $priority = $row[TEST_PRIORITY];
 $test_ts_assoc_id = $row[TEST_TS_ASSOC_ID];
 $assigned_to = $row[TEST_TS_ASSOC_ASSIGNED_TO];
 $comments = $row[TEST_TS_ASSOC_COMMENTS];
 $testset_assoc_status = $row[TEST_TS_ASSOC_STATUS];
 # Build list of records
 if (empty($records)) {
     $records = "{$test_id} => '{$testset_assoc_status}'";
 } else {
     $records .= ", {$test_id} => '{$testset_assoc_status}'";
 }
 $row_style = html_tbl_alternate_bgcolor($row_style);
 print "<tr class='{$row_style}'>" . NEWLINE;
 if (session_records_ischecked("testset_copy", $test_id, $testset_assoc_status)) {
     print "<td><input type='checkbox' name='row_{$test_id}' value='{$testset_assoc_status}' checked></td>" . NEWLINE;
 } else {
     print "<td><input type='checkbox' name='row_{$test_id}' value='{$testset_assoc_status}'></td>" . NEWLINE;
 }
 print "<td align='center'>{$display_test_id}</td>" . NEWLINE;
 print "<td class='left' nowrap>" . html_print_testtype_icon($manual, $automated) . "</td>" . NEWLINE;
 print "<td class='left' nowrap>{$test_name}</td>" . NEWLINE;
 print "<td class='left'>{$ba_owner}</td>" . NEWLINE;
 print "<td class='left'>{$qa_owner}</td>" . NEWLINE;
 print "<td class='left'>{$tester}</td>" . NEWLINE;
 print "<td class='left' nowrap>{$test_type}</td>" . NEWLINE;
 print "<td class='left' nowrap>{$area_tested}</td>" . NEWLINE;
 print "<td class='left' nowrap>{$testset_assoc_status}</td>" . NEWLINE;
 print "<td class='center'><a href='{$test_page}?test_id={$test_id}' target='_blank'>" . lang_get('docs_link') . "</a></td>" . NEWLINE;
 print "<td class='center'><a href='{$results_test_run_page}?test_id={$test_id}&amp;testset_menu_testset_id={$_GET['testset_menu_testset_id']}'>" . lang_get('results_link') . "</a></td>" . NEWLINE;
 print "<th></th>";
 html_tbl_print_header(lang_get('req_id'), REQ_ID, $order_by, $order_dir);
 html_tbl_print_header("");
 html_tbl_print_header(lang_get('req_name'), REQ_FILENAME, $order_by, $order_dir);
 html_tbl_print_header(lang_get('req_detail'), REQ_VERS_DETAIL, $order_by, $order_dir);
 html_tbl_print_header(lang_get('req_type'), REQ_DOC_TYPE_NAME, $order_by, $order_dir);
 html_tbl_print_header(lang_get('status'), REQ_VERS_STATUS, $order_by, $order_dir);
 html_tbl_print_header(lang_get('req_area'), REQ_AREA_COVERAGE, $order_by, $order_dir);
 html_tbl_print_header(lang_get('functionality'));
 html_tbl_print_header(lang_get('req_locked_by'), REQ_LOCKED_BY, $order_by, $order_dir);
 html_tbl_print_header(lang_get('req_locked_date'), REQ_LOCKED_DATE, $order_by, $order_dir);
 print "</tr>" . NEWLINE;
 foreach ($rows_requirement as $row_requirement) {
     $req_id = $row_requirement[REQ_ID];
     $req_version_id = $row_requirement[REQ_VERS_UNIQUE_ID];
     if (session_records_ischecked("requirement_requirement_assoc", $req_id)) {
         $checked = "checked";
     } else {
         $checked = "";
     }
     # Build list of records
     if (empty($records)) {
         $records = $req_id . " => ''";
     } else {
         $records .= ", " . $req_id . " => ''";
     }
     $row_style = html_tbl_alternate_bgcolor($row_style);
     $rows_functions = requirement_get_functionality($project_id, $row_requirement[REQ_ID]);
     # Rows
     print "<tr class='{$row_style}'>" . NEWLINE;
     print "<td><input type='checkbox' name=row_{$req_id} {$checked}></td>";
 html_tbl_print_header(lang_get('area_tested'));
 html_tbl_print_header(lang_get('status'));
 html_tbl_print_header_not_sortable(lang_get('archive'));
 print "</tr>" . NEWLINE;
 print "</thead>" . NEWLINE;
 print "<tbody>" . NEWLINE;
 foreach ($row as $test_row) {
     #$row_style = html_tbl_alternate_bgcolor($row_style);
     #print"<tr class='$row_style'>". NEWLINE;
     print "<tr>" . NEWLINE;
     print "<td>" . html_print_testtype_icon($test_row[TEST_MANUAL], $test_row[TEST_AUTOMATED]) . "</td>" . NEWLINE;
     print "<td>" . $test_row[TEST_NAME] . "</td>" . NEWLINE;
     print "<td>" . $test_row[TEST_TESTTYPE] . "</td>" . NEWLINE;
     print "<td>" . $test_row[TEST_AREA_TESTED] . "</td>" . NEWLINE;
     print "<td>" . $test_row[TEST_STATUS] . "</td>" . NEWLINE;
     if (session_records_ischecked("archive_tests", $test_row[TEST_ID])) {
         $checked = "checked";
     } else {
         $checked = "";
     }
     if (empty($records)) {
         $records = $test_row[TEST_ID] . " => ''";
     } else {
         $records .= ", " . $test_row[TEST_ID] . " => ''";
     }
     print "<td><input type=checkbox name=row_" . $test_row[TEST_ID] . " {$checked}></td>" . NEWLINE;
     print "</tr>" . NEWLINE;
 }
 print "</tbody>" . NEWLINE;
 print "</table>" . NEWLINE;
 print "<br>" . NEWLINE;
function test_edit_assoc_requirements($test_id, $session_records_name, $pc_covered_text_input_name)
{
    global $db;
    $tbl_req = REQ_TBL;
    $f_req_proj_id = $tbl_req . "." . REQ_PROJECT_ID;
    $f_req_id = $tbl_req . "." . REQ_ID;
    $f_req_filename = $tbl_req . "." . REQ_FILENAME;
    $tbl_test_req_assoc = TEST_REQ_ASSOC_TBL;
    $f_test_req_assoc_req_id = $tbl_test_req_assoc . "." . TEST_REQ_ASSOC_REQ_ID;
    $f_test_req_assoc_test_id = $tbl_test_req_assoc . "." . TEST_REQ_ASSOC_TEMPEST_TEST_ID;
    $f_test_req_assoc_covered = $tbl_test_req_assoc . "." . TEST_REQ_ASSOC_PERCENT_COVERED;
    $tbl_test = TEST_TBL;
    $f_test_name = $tbl_test . "." . TEST_NAME;
    $f_test_id = $tbl_test . "." . TEST_ID;
    $s_project_properties = session_get_project_properties();
    $project_id = $s_project_properties['project_id'];
    $req_ids = requirement_get_all_ids($project_id);
    foreach ($req_ids as $row) {
        $req_id = $row[REQ_ID];
        $q = "\tSELECT {$f_test_req_assoc_req_id}\n\t\t\t\tFROM {$tbl_test_req_assoc}\n\t\t\t\tWHERE {$f_test_req_assoc_req_id} = {$req_id}\n\t\t\t\t\tAND\t{$f_test_req_assoc_test_id} = {$test_id}";
        $rs = db_query($db, $q);
        $record_exists = db_num_rows($db, $rs);
        if (session_records_ischecked($session_records_name, $req_id)) {
            $pc_covered = session_validate_form_get_field($pc_covered_text_input_name . $req_id);
            if ($pc_covered == '') {
                $pc_covered = 0;
            }
            //print"pc_covered = $pc_covered<br>";
            if (!$record_exists) {
                # Add new record
                $q = "\tINSERT INTO {$tbl_test_req_assoc}\n\t\t\t\t\t\t\t({$f_test_req_assoc_req_id}, {$f_test_req_assoc_test_id}, {$f_test_req_assoc_covered})\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t({$req_id}, {$test_id}, '{$pc_covered}')";
            } else {
                # Update current record
                $q = "\tUPDATE {$tbl_test_req_assoc}\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t{$f_test_req_assoc_covered} = '{$pc_covered}'\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t{$f_test_req_assoc_req_id} = {$req_id}\n\t\t\t\t\t\t\tAND {$f_test_req_assoc_test_id} = {$test_id}";
            }
        } else {
            if ($record_exists) {
                $q = "\tDELETE FROM {$tbl_test_req_assoc}\n\t\t\t\t\t\tWHERE {$f_test_req_assoc_req_id} = {$req_id}\n\t\t\t\t\t\t\tAND\t{$f_test_req_assoc_test_id} = {$test_id}";
            }
        }
        db_query($db, $q);
    }
}
 html_tbl_print_sortable_header(lang_get('functionality'));
 html_tbl_print_sortable_header(lang_get('req_locked_by'), REQ_TBL . "." . REQ_LOCKED_BY, $order_by, $order_dir);
 html_tbl_print_sortable_header(lang_get('req_locked_date'), REQ_TBL . "." . REQ_LOCKED_DATE, $order_by, $order_dir);
 print "</tr>" . NEWLINE;
 foreach ($rows_requirement as $row_requirement) {
     $req_id = $row_requirement[REQ_ID];
     $req_version_id = $row_requirement[REQ_VERS_UNIQUE_ID];
     # Name of the % covered text input
     $pc_covered_input_name = "percent_covered_" . $req_id;
     # Get the % covered from db
     $percent_covered = test_requirement_get_pc_covered($s_test_id, $req_id);
     # Save and get the % covered from the session
     $percent_covered = session_validate_form_get_field($pc_covered_input_name, $percent_covered);
     $row_style = html_tbl_alternate_bgcolor($row_style);
     $rows_functions = requirement_get_functionality($s_project_id, $row_requirement[REQ_ID]);
     if (session_records_ischecked("test_req_assoc", $req_id)) {
         $checked = "checked";
     } else {
         $checked = "";
     }
     # Build list of records
     if (empty($records)) {
         $records = $req_id . " => ''";
     } else {
         $records .= ", " . $req_id . " => ''";
     }
     # Rows
     print "<tr class='{$row_style}'>" . NEWLINE;
     print "<td><input type='checkbox' name='row_{$req_id}' {$checked}></td>";
     print "<td><input type=text name={$pc_covered_input_name} size=3 maxlength=3 value='{$percent_covered}'></td>";
     print "<td>" . util_pad_id($row_requirement[REQ_ID]) . "</td>" . NEWLINE;
 #$row_style = html_tbl_alternate_bgcolor($row_style);
 if ($row_test_detail[TEST_AUTO_PASS] == "Y") {
     $autopass = "******";
 } else {
     $autopass = "******";
 }
 # Build list of records
 if (empty($records)) {
     $records = $test_id . " => '" . $test_type . "'";
 } else {
     $records .= ", " . $test_id . " => '" . $test_type . "'";
 }
 # Rows
 #print"<tr class='$row_style'>". NEWLINE;
 print "<tr>" . NEWLINE;
 if (session_records_ischecked("testset_edit", $test_id, $test_type)) {
     print "<td><input type=checkbox name=row_" . $test_id . " value='" . $test_type . "' checked></td>" . NEWLINE;
 } else {
     print "<td><input type=checkbox name=row_" . $test_id . " value='" . $test_type . "'></td>" . NEWLINE;
 }
 print "<td class='left'>{$display_test_id}</td>" . NEWLINE;
 print "<td class='tbl-l'>" . html_print_testtype_icon($manual, $automated) . "</td>" . NEWLINE;
 print "<td class='tbl-l'>{$autopass}</td>" . NEWLINE;
 print "<td class='tbl-l'>{$test_name}</td>" . NEWLINE;
 print "<td class='tbl-l'>{$ba_owner}</td>" . NEWLINE;
 print "<td class='tbl-l'>{$qa_owner}</td>" . NEWLINE;
 print "<td class='tbl-l'>{$tester}</td>" . NEWLINE;
 print "<td class='tbl-l'>{$test_type}</td>" . NEWLINE;
 print "<td class='tbl-l'>{$area_tested}</td>" . NEWLINE;
 print "<td class='tbl-l'>{$priority}</td>" . NEWLINE;
 print "</tr>" . NEWLINE;
 html_tbl_print_sortable_header("email");
 html_tbl_print_sortable_header(lang_get('req_id'), REQ_ID, $order_by, $order_dir);
 html_tbl_print_sortable_header(lang_get('req_name'), REQ_FILENAME, $order_by, $order_dir);
 print "</tr>" . NEWLINE;
 foreach ($rows_requirement as $row_requirement) {
     $req_id = $row_requirement[REQ_ID];
     $req_name = $row_requirement[REQ_FILENAME];
     if (empty($records)) {
         $records = $row_requirement[REQ_ID] . " => ''";
     } else {
         $records .= ", " . $row_requirement[REQ_ID] . " => ''";
     }
     $row_style = html_tbl_alternate_bgcolor($row_style);
     # Rows
     print "<tr class='{$row_style}'>" . NEWLINE;
     if (session_records_ischecked("requirements_notification", $req_id)) {
         print "<td><input type=checkbox name=row_{$req_id} value='' checked></td>" . NEWLINE;
     } else {
         print "<td><input type=checkbox name=row_{$req_id} value=''></td>" . NEWLINE;
     }
     print "<td class='tbl-1'>" . util_pad_id($req_id) . "</td>" . NEWLINE;
     print "<td class='tbl-l'>{$req_name}</td>" . NEWLINE;
     print "</tr>" . NEWLINE;
 }
 print "</table>" . NEWLINE;
 print "</div>" . NEWLINE;
 print "<div align=center>" . NEWLINE;
 print "<table class=hide60>" . NEWLINE;
 print "<tr>" . NEWLINE;
 print "<td align=left>" . NEWLINE;
 if (session_use_javascript()) {
function user_edit_requirement_notifications($project_id, $user_id, $s_variable)
{
    $tbl_notify = REQ_NOTIFY_TBL;
    $f_id = REQ_NOTIFY_TBL . "." . REQ_NOTIFY_ID;
    $f_req_id = REQ_NOTIFY_TBL . "." . REQ_NOTIFY_REQ_ID;
    $f_user_id = REQ_NOTIFY_TBL . "." . REQ_NOTIFY_USER_ID;
    global $db;
    $req_ids = requirement_get_all_ids($project_id);
    foreach ($req_ids as $row) {
        if (session_records_ischecked($s_variable, $row[REQ_ID])) {
            # Check for associations between TestSet and the Test
            $query_check = "\n\t\t\t\tSELECT {$f_id}\n\t\t\t\tFROM {$tbl_notify}\n\t\t\t\tWHERE\n\t\t\t\t\t{$f_user_id} = {$user_id}\n\t\t\t\t\tAND {$f_req_id} = " . $row[REQ_ID];
            $num_check = db_num_rows($db, db_query($db, $query_check));
            if ($num_check == 0) {
                $query_Assoc = "\n\t\t\t\t\tINSERT INTO\t{$tbl_notify}\n\t\t\t\t\t\t({$f_user_id}, {$f_req_id} )\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t({$user_id}, " . $row[REQ_ID] . ")";
                db_query($db, $query_Assoc);
            }
        } else {
            $query_Assoc = "\n\t\t\t\tDELETE FROM {$tbl_notify}\n\t\t\t\tWHERE\n\t\t\t\t\t{$f_req_id} = " . $row[REQ_ID] . "\n\t\t\t\t\tAND  {$f_user_id} = {$user_id}";
            db_query($db, $query_Assoc);
        }
    }
}
 $tester = $row_test_detail[TEST_TESTER];
 $test_type = $row_test_detail[TEST_TESTTYPE];
 $manual = $row_test_detail[TEST_MANUAL];
 $automated = $row_test_detail[TEST_AUTOMATED];
 $area_tested = $row_test_detail[TEST_AREA_TESTED];
 $priority = $row_test_detail[TEST_PRIORITY];
 $autopass = $row_test_detail[TEST_AUTO_PASS];
 # Name of the % covered text input
 $pc_covered_input_name = "percent_covered_{$test_id}";
 # Get the % covered from db
 $percent_covered = requirement_test_get_pc_covered($s_req_id, $test_id);
 # Save and get the % covered from the session
 $percent_covered = session_validate_form_get_field($pc_covered_input_name, $percent_covered);
 $display_test_id = util_pad_id($test_id);
 $row_style = html_tbl_alternate_bgcolor($row_style);
 if (session_records_ischecked("requirement_tests_assoc", $test_id)) {
     $checked = "checked";
 } else {
     $checked = "";
 }
 # Build list of records
 if (empty($records)) {
     $records = $test_id . " => '" . $test_type . "'";
 } else {
     $records .= ", " . $test_id . " => '" . $test_type . "'";
 }
 print "<tr class='{$row_style}'>" . NEWLINE;
 print "<td><input type='checkbox' name=row_{$test_id} {$checked}></td>" . NEWLINE;
 print "<td><input type='text' name={$pc_covered_input_name} size=3 maxlength=3 value='{$percent_covered}'></td>" . NEWLINE;
 print "<td class='tbl-l'>{$display_test_id}</td>" . NEWLINE;
 print "<td class='tbl-l'>" . html_print_testtype_icon($manual, $automated) . "</td>" . NEWLINE;
function project_archive_tests($project_id)
{
    global $db;
    $tbl_test = TEST_TBL;
    $f_name = $tbl_test . "." . TEST_NAME;
    $f_type = $tbl_test . "." . TEST_TESTTYPE;
    $f_priority = $tbl_test . "." . TEST_PRIORITY;
    $f_id = $tbl_test . "." . TEST_ID;
    $f_steps = $tbl_test . "." . TEST_MANUAL;
    $f_script = $tbl_test . "." . TEST_AUTOMATED;
    $f_status = $tbl_test . "." . TEST_STATUS;
    $f_area = $tbl_test . "." . TEST_AREA_TESTED;
    $f_deleted = $tbl_test . "." . TEST_DELETED;
    $f_archive = $tbl_test . "." . TEST_ARCHIVED;
    $f_area_tested = $tbl_test . "." . TEST_AREA_TESTED;
    $f_project_id = $tbl_test . "." . PROJECT_ID;
    foreach (admin_get_tests($project_id) as $row_test) {
        if (session_records_ischecked("archive_tests", $row_test[TEST_ID])) {
            $q = "\tUPDATE {$tbl_test}\n\t\t\t\t\tSET\n\t\t\t\t\t\t{$f_archive} = 'Y'\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t{$f_id} = " . $row_test[TEST_ID];
            db_query($db, $q);
        } else {
            $q = "\tUPDATE {$tbl_test}\n\t\t\t\t\tSET\n\t\t\t\t\t\t{$f_archive} = 'N'\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t{$f_id} = " . $row_test[TEST_ID];
            db_query($db, $q);
        }
    }
}
function testset_add_tests_from_session($testset_properties, $f_status, $property_set)
{
    $checked_tests = array();
    $project_id = session_get_project_id();
    $s_user_properties = session_get_user_properties();
    $s_project_properties = session_get_project_properties();
    $testset_id = $testset_properties['testset_id'];
    $testset_name = admin_get_testset_name($testset_id);
    $build_id = $testset_properties['build_id'];
    $build_name = admin_get_build_name($build_id);
    $release_id = $testset_properties['release_id'];
    $release_name = admin_get_release_name($release_id);
    global $db;
    $testsuite_tbl = TEST_TBL;
    $f_test_id = TEST_TBL . "." . TEST_ID;
    $f_project_id = TEST_TBL . "." . PROJECT_ID;
    $f_deleted = TEST_TBL . "." . TEST_DELETED;
    $f_archived = TEST_TBL . "." . TEST_ARCHIVED;
    $ts_assoc_tbl = TEST_TS_ASSOC_TBL;
    $f_ts_assoc_id = TEST_TS_ASSOC_TBL . "." . TEST_TS_ASSOC_ID;
    $f_ts_assoc_test_id = TEST_TS_ASSOC_TBL . "." . TEST_TS_ASSOC_TEST_ID;
    $q = "SELECT {$f_test_id},\n\t\t\t{$f_ts_assoc_id},\n\t\t\t{$f_status}\n\t     FROM {$ts_assoc_tbl}\n\t     RIGHT JOIN {$testsuite_tbl} ON {$f_ts_assoc_test_id} = {$f_test_id}\n\t     WHERE {$f_project_id} = {$project_id}\n\t     AND {$f_archived} = 'N'\n\t     AND {$f_deleted} = 'N'\n\t     GROUP BY {$f_test_id}";
    $rs = db_query($db, $q);
    while ($row = db_fetch_row($db, $rs)) {
        if (isset($row[$f_status])) {
            # If the checkbox is ticked, then form an association between Test/TestSet
            if (session_records_ischecked($property_set, $row[TEST_ID], $row[$f_status])) {
                $checked_tests[$row[TEST_ID]] = "on";
            }
        }
    }
    testset_edit($testset_id, $checked_tests);
}