$f_test_result_showgradefeedback = (int) (bool) readPostVar('test_result_showgradefeedback');
$f_test_result_showanswers = (int) (bool) readPostVar('test_result_showanswers');
$f_test_result_showpoints = (int) (bool) readPostVar('test_result_showpoints');
$f_test_result_rtemplateid = (int) readPostVar('test_result_rtemplateid');
$f_rtemplateid = (int) readPostVar('rtemplateid');
$f_test_reportgradecondition = (int) readPostVar('test_reportgradecondition');
$f_test_result_showhtml = (int) (bool) readPostVar('test_result_showhtml');
$f_test_result_showpdf = (int) (bool) readPostVar('test_result_showpdf');
$f_test_result_email = readPostVar('test_result_email');
$f_test_result_email = $g_db->qstr($f_test_result_email, get_magic_quotes_gpc());
$f_result_etemplateid = (int) readPostVar('result_etemplateid');
$f_test_result_emailtouser = (int) (bool) readPostVar('test_result_emailtouser');
$f_test_description = readPostVar('test_description');
$f_test_description = $g_db->qstr($f_test_description, get_magic_quotes_gpc());
$f_test_instructions = readPostVar('test_instructions');
if (isHTMLAreaEmpty($f_test_instructions)) {
    $f_test_instructions = '';
}
$f_test_instructions = $g_db->qstr($f_test_instructions, get_magic_quotes_gpc());
$f_test_prevtestid = (int) readPostVar('test_prevtestid');
$f_test_nexttestid = (int) readPostVar('test_nexttestid');
$f_test_price = (double) readPostVar('test_price');
$f_test_price = (int) ($f_test_price * 100);
$f_test_other_repeatuntilcorrect = (int) (bool) readPostVar('test_other_repeatuntilcorrect');
$f_test_notes = readPostVar('test_notes');
$f_test_notes = $g_db->qstr($f_test_notes, get_magic_quotes_gpc());
$f_test_forall = (int) (bool) readPostVar('test_forall');
$f_group = isset($_POST['group']) ? $_POST['group'] : array();
if ($i_rSet2 = $g_db->Execute("SELECT subjectid FROM " . $srv_settings['table_prefix'] . "subjects WHERE subjectid={$f_subjectid}")) {
    $sql_subject_exists = $i_rSet2->RecordCount() > 0;
} else {
function getGradeData($i_gscaleid, $i_gradeid)
{
    global $g_db, $srv_settings;
    $i_result = array();
    $i_result['gscaleid'] = $i_gscaleid;
    $i_result['gradeid'] = $i_gradeid;
    $i_result['name'] = '';
    $i_result['feedback'] = '';
    $i_rSet1 = $g_db->SelectLimit("SELECT grade_name, grade_feedback FROM " . $srv_settings['table_prefix'] . "gscales_grades WHERE gscaleid=" . $i_gscaleid . " AND gscale_gradeid=" . $i_gradeid, 1);
    if (!$i_rSet1) {
        showDBError('getResultGrade', 1);
    } else {
        if (!$i_rSet1->EOF) {
            $i_result['name'] = $i_rSet1->fields['grade_name'];
            $i_result['feedback'] = $i_rSet1->fields['grade_feedback'];
            if (isHTMLAreaEmpty($i_result['feedback'])) {
                $i_result['feedback'] = '';
            }
        }
        $i_rSet1->Close();
    }
    return $i_result;
}