<?php

$g_vars['page']['header'] = $lngstr['page_buycheckout']['title'];
$f_state = readGetVar('state');
eventOnBeforePageGeneration(array('page_name' => 'buy-state'));
switch ($f_state) {
    case 'success':
        $g_vars['page']['notifications'] = $lngstr['page_buystate']['success'];
        if (isset($G_SESSION['id'])) {
            $g_vars['page']['title'] = $lngstr['page_title_panel'];
            include_once $DOCUMENT_PAGES . 'home.inc.php';
        } else {
            $g_vars['page']['title'] = $lngstr['page_title_signin'];
            include_once $DOCUMENT_PAGES . 'signin-1.inc.php';
        }
        break;
    case 'fail':
        $g_vars['page']['errors'] = $lngstr['page_buystate']['fail'];
        if (isset($G_SESSION['id'])) {
            $g_vars['page']['title'] = $lngstr['page_title_panel'];
            include_once $DOCUMENT_PAGES . 'home.inc.php';
        } else {
            $g_vars['page']['title'] = $lngstr['page_title_signin'];
            include_once $DOCUMENT_PAGES . 'signin-1.inc.php';
        }
        break;
}
}
if ($i_showresultspage && $G_SESSION['yt_attempts'] > 0) {
    $i_attempt_count = 0;
    $i_rSet4 = $g_db->Execute("SELECT test_attempt_count FROM " . $srv_settings['table_prefix'] . "tests_attempts WHERE testid=" . $G_SESSION['testid'] . " AND id=" . $G_SESSION['id']);
    if ($i_rSet4) {
        if (!$i_rSet4->EOF) {
            $i_attempt_count = $i_rSet4->fields['test_attempt_count'];
        }
        $i_rSet4->Close();
    }
    $i_showresultspage = $i_attempt_count >= $i_attempts_allowed;
}
$g_vars['page']['show_takeatest'] = true;
$g_vars['page']['show_nexttest'] = $G_SESSION['yt_nexttestid'] > 0;
$g_vars['page']['show_reportsmanager'] = $i_showresultspage;
$g_vars['page']['show_advancedreport_pdf'] = $G_SESSION['yt_result_showpdf'] && ($G_SESSION['yt_reportgradecondition'] == 0 or $G_SESSION['yt_reportgradecondition'] >= $g_vars['page']['grade']['gradeid']);
$g_vars['page']['show_advancedreport_html'] = $G_SESSION['yt_result_showhtml'] && ($G_SESSION['yt_reportgradecondition'] == 0 or $G_SESSION['yt_reportgradecondition'] >= $g_vars['page']['grade']['gradeid']);
if ($G_SESSION['yt_result_rtemplateid'] > 0) {
    $i_isok = true;
    $i_isok = $i_isok && ($i_rSet2 = $g_db->SelectLimit("SELECT * FROM " . $srv_settings['table_prefix'] . "users WHERE id=" . $G_SESSION['id'], 1));
    if ($i_isok) {
        $i_isok = $i_isok && !$i_rSet2->EOF;
    }
    if ($i_isok) {
        $i_arrTestAnswerDetails = getTestAnswerDetails($G_SESSION['resultid'], 'html');
        $g_vars['page']['custom_report'] = getReportTemplate(array('rtemplateid' => $G_SESSION['yt_result_rtemplateid'], 'username' => $i_rSet2->fields['username'], 'email' => $i_rSet2->fields['email'], 'title' => $i_rSet2->fields['user_title'], 'firstname' => $i_rSet2->fields['user_firstname'], 'lastname' => $i_rSet2->fields['user_lastname'], 'middlename' => $i_rSet2->fields['user_middlename'], 'address' => $i_rSet2->fields['user_address'], 'city' => $i_rSet2->fields['user_city'], 'state' => $i_rSet2->fields['user_state'], 'zip' => $i_rSet2->fields['user_zip'], 'country' => $i_rSet2->fields['user_country'], 'phone' => $i_rSet2->fields['user_phone'], 'fax' => $i_rSet2->fields['user_fax'], 'mobile' => $i_rSet2->fields['user_mobile'], 'pager' => $i_rSet2->fields['user_pager'], 'ipphone' => $i_rSet2->fields['user_ipphone'], 'webpage' => $i_rSet2->fields['user_webpage'], 'icq' => $i_rSet2->fields['user_icq'], 'msn' => $i_rSet2->fields['user_msn'], 'aol' => $i_rSet2->fields['user_aol'], 'gender' => $i_rSet2->fields['user_gender'], 'birthday' => $i_rSet2->fields['user_birthday'], 'husbandwife' => $i_rSet2->fields['user_husbandwife'], 'children' => $i_rSet2->fields['user_children'], 'trainer' => $i_rSet2->fields['user_trainer'], 'photo' => $i_rSet2->fields['user_photo'], 'company' => $i_rSet2->fields['user_company'], 'cposition' => $i_rSet2->fields['user_cposition'], 'department' => $i_rSet2->fields['user_department'], 'coffice' => $i_rSet2->fields['user_coffice'], 'caddress' => $i_rSet2->fields['user_caddress'], 'ccity' => $i_rSet2->fields['user_ccity'], 'cstate' => $i_rSet2->fields['user_cstate'], 'czip' => $i_rSet2->fields['user_czip'], 'ccountry' => $i_rSet2->fields['user_ccountry'], 'cphone' => $i_rSet2->fields['user_cphone'], 'cfax' => $i_rSet2->fields['user_cfax'], 'cmobile' => $i_rSet2->fields['user_cmobile'], 'cpager' => $i_rSet2->fields['user_cpager'], 'cipphone' => $i_rSet2->fields['user_cipphone'], 'cwebpage' => $i_rSet2->fields['user_cwebpage'], 'cphoto' => $i_rSet2->fields['user_cphoto'], 'ufield1' => $i_rSet2->fields['user_ufield1'], 'ufield2' => $i_rSet2->fields['user_ufield2'], 'ufield3' => $i_rSet2->fields['user_ufield3'], 'ufield4' => $i_rSet2->fields['user_ufield4'], 'ufield5' => $i_rSet2->fields['user_ufield5'], 'ufield6' => $i_rSet2->fields['user_ufield6'], 'ufield7' => $i_rSet2->fields['user_ufield7'], 'ufield8' => $i_rSet2->fields['user_ufield8'], 'ufield9' => $i_rSet2->fields['user_ufield9'], 'ufield10' => $i_rSet2->fields['user_ufield10'], 'test_name' => $G_SESSION['yt_name'], 'result_id' => $G_SESSION['resultid'], 'result_date' => getDateLocal($lngstr['language']['date_format_full'], $G_SESSION['yt_teststart']), 'result_time_spent' => getTimeFormatted($i_timespent_total), 'result_time_exceeded' => $i_timeexceeded ? $lngstr['label_yes'] : $lngstr['label_no'], 'result_points_scored' => $G_SESSION['yt_got_points'], 'result_points_possible' => $G_SESSION['yt_pointsmax'], 'result_percents' => $g_vars['page']['score'], 'result_grade' => $g_vars['page']['grade']['name'], 'result_grade_feedback' => $g_vars['page']['grade']['feedback'], 'result_subjects' => $G_SESSION['yt_subjects'], 'result_detailed_1' => $i_arrTestAnswerDetails['result_detailed_1'], 'result_detailed_2' => $i_arrTestAnswerDetails['result_detailed_2'], 'result_detailed_3' => $i_arrTestAnswerDetails['result_detailed_3'], 'result_detailed_4' => $i_arrTestAnswerDetails['result_detailed_4'], 'result_detailed_5' => $i_arrTestAnswerDetails['result_detailed_5'], 'result_detailed_6' => $i_arrTestAnswerDetails['result_detailed_6']));
    }
}
eventOnBeforePageGeneration(array('page_name' => 'test-showresults'));
$g_smarty->assign('g_vars', $g_vars);
displayTemplate('test-results');
        if ($i_rSet1->fields['test_attempts'] > 0) {
            $i_rSet4 = $g_db->Execute("SELECT test_attempt_count FROM " . $srv_settings['table_prefix'] . "tests_attempts WHERE testid=" . $i_rSet1->fields['testid'] . " AND id=" . $i_rSet1->fields['id']);
            if (!$i_rSet4) {
                showDBError(__FILE__, 3);
            } else {
                if (!$i_rSet4->EOF) {
                    $i_attempt_count = $i_rSet4->fields['test_attempt_count'];
                }
                $i_rSet4->Close();
            }
        }
        $g_vars['page']['tables'][1]['rows'][$i_counter] = $i_rSet1->fields;
        $g_vars['page']['tables'][1]['rows'][$i_counter]['result_datestart_formatted'] = getDateLocal($lngstr['language']['date_format'], $i_rSet1->fields['result_datestart']);
        $g_vars['page']['tables'][1]['rows'][$i_counter]['test_attempt_count'] = $i_attempt_count;
        if ($i_rSet1->fields['rtemplateid'] > 0 && ($i_rSet1->fields['test_reportgradecondition'] == 0 || $i_rSet1->fields['test_reportgradecondition'] >= $i_rSet1->fields['gscale_gradeid'])) {
            $g_vars['page']['tables'][1]['rows'][$i_counter]['show_html'] = $i_rSet1->fields['test_result_showhtml'];
            $g_vars['page']['tables'][1]['rows'][$i_counter]['show_pdf'] = $i_rSet1->fields['test_result_showpdf'];
        } else {
            $g_vars['page']['tables'][1]['rows'][$i_counter]['show_html'] = false;
            $g_vars['page']['tables'][1]['rows'][$i_counter]['show_pdf'] = false;
        }
        $i_counter++;
        $i_rSet1->MoveNext();
    }
    $i_rSet1->Close();
}
eventOnBeforePageGeneration(array('page_name' => 'reports-manager'));
$g_smarty->assign('g_vars', $g_vars);
if (empty($i_donotshow)) {
    displayTemplate('reports-manager');
}
                    if ($g_vars['page']['test'][$i_test_count]['attempts_total'] > 0) {
                        if ($g_vars['page']['test'][$i_test_count]['attempts'] >= $g_vars['page']['test'][$i_test_count]['attempts_total']) {
                            $g_vars['page']['test'][$i_test_count]['status_label'] = $lngstr['page-takeatest']['attempts_limit_reached'];
                        } else {
                            $g_vars['page']['test'][$i_test_count]['status_label'] = sprintf($lngstr['page-takeatest']['attempts_left'], $g_vars['page']['test'][$i_test_count]['attempts_total'] - $g_vars['page']['test'][$i_test_count]['attempts']);
                            $g_vars['page']['test'][$i_test_count]['status'] = IGT_TEST_STATUS_AVAILABLE;
                        }
                    } else {
                        $g_vars['page']['test'][$i_test_count]['status_label'] = $lngstr['page_panel_status_available'];
                        $g_vars['page']['test'][$i_test_count]['status'] = IGT_TEST_STATUS_AVAILABLE;
                    }
                }
                if ($g_vars['page']['test'][$i_test_count]['testid'] == readCookieVar('pending_test_ids') && $g_vars['page']['test'][$i_test_count]['status'] == IGT_TEST_STATUS_AVAILABLE) {
                    $g_vars['page']['test'][$i_test_count]['status'] = IGT_TEST_STATUS_INPROGRESS;
                }
                $g_vars['page']['test'][$i_test_count]['status'] = eventOnQueryTestStatus(array('testno' => $i_test_count, 'testid' => $g_vars['page']['test'][$i_test_count]['testid'], 'status' => $g_vars['page']['test'][$i_test_count]['status']));
            }
            $i_rSet1->MoveNext();
        }
        $i_rSet1->Close();
    }
}
if ($g_vars['page']['user_points_max'] != 0) {
    $g_vars['page']['user_score'] = $g_vars['page']['user_points'] * 100 / $g_vars['page']['user_points_max'];
} else {
    $g_vars['page']['user_score'] = 0;
}
$g_vars['page']['test_count'] = $i_test_count;
eventOnBeforePageGeneration(array('page_name' => 'test-select'));
$g_smarty->assign('g_vars', $g_vars);
displayTemplate('test-select');
<?php

defined('IGT_VALID_ENVIRONMENT') or exit('Restricted access');
$g_vars['page']['hide_cpanel'] = true;
$f_username = readPostVar('username');
$g_vars['page']['username'] = convertTextValue($f_username);
$g_vars['page']['gotourl'] = @htmlspecialchars($_SERVER['REQUEST_URI']);
$g_vars['page']['cansigninasguest'] = getRecordCount($srv_settings['table_prefix'] . 'users', 'id=' . SYSTEM_GROUP_GUEST_id . ' AND user_enabled=1') > 0;
$g_vars['page']['test_code'] = isset($G_SESSION['test_code']) ? $G_SESSION['test_code'] : '';
$g_vars['page']['can_register'] = getConfigItem(CONFIG_can_register);
eventOnBeforePageGeneration(array('page_name' => 'signin'));
$g_smarty->assign('g_vars', $g_vars);
displayTemplate('signin');