function getAdvancedReportPDF($resultid)
{
    global $g_db, $G_SESSION, $DOCUMENT_FPDF, $lngstr, $srv_settings, $i_rSet2, $i_rSet3, $i_rSet4, $i_rSet5, $i_rSet6;
    ob_start();
    include_once $DOCUMENT_FPDF . 'html2fpdf.php';
    $i_pdf = false;
    $i_can_access = false;
    if ($G_SESSION['access_reportsmanager'] > 1) {
        $i_can_access = true;
    } else {
        $i_rSet1 = $g_db->Execute("SELECT resultid FROM " . $srv_settings['table_prefix'] . "results WHERE id=" . $G_SESSION['id'] . " AND resultid=" . $resultid);
        if (!$i_rSet1) {
            showDBError(__FILE__, 1);
        } else {
            $i_can_access = $i_rSet1->RecordCount() > 0;
        }
    }
    $i_isok = $i_can_access;
    if ($i_isok) {
        $i_isok = $i_rSet2 = $g_db->SelectLimit("SELECT * FROM " . $srv_settings['table_prefix'] . "results WHERE resultid=" . $resultid, 1);
    }
    if ($i_isok) {
        $i_isok = !$i_rSet2->EOF;
    }
    if ($i_isok) {
        $i_isok = $i_rSet3 = $g_db->SelectLimit("SELECT * FROM " . $srv_settings['table_prefix'] . "tests WHERE testid=" . $i_rSet2->fields['testid'], 1);
    }
    if ($i_isok) {
        $i_isok = !$i_rSet3->EOF;
    }
    if ($i_isok) {
        $i_isok = $i_rSet3->fields['rtemplateid'] > 0 && ($i_rSet3->fields['test_reportgradecondition'] == 0 || $i_rSet3->fields['test_reportgradecondition'] >= $i_rSet2->fields['gscale_gradeid']);
    }
    if ($i_isok) {
        $i_isok = $i_rSet6 = $g_db->SelectLimit("SELECT * FROM " . $srv_settings['table_prefix'] . "users WHERE id=" . $i_rSet2->fields['id'], 1);
    }
    if ($i_isok) {
        $i_isok = !$i_rSet6->EOF;
    }
    $i_result_detailed_1_items = array();
    $i_result_detailed_2_items = array();
    $i_result_detailed_3_items = array();
    $i_result_detailed_4_items = array();
    if ($i_isok) {
        $i_isok = $i_rSet7 = $g_db->Execute("SELECT * FROM " . $srv_settings['table_prefix'] . "results_answers, " . $srv_settings['table_prefix'] . "questions WHERE resultid=" . $resultid . " AND " . $srv_settings['table_prefix'] . "results_answers.questionid=" . $srv_settings['table_prefix'] . "questions.questionid ORDER BY result_answerid");
    }
    if ($i_isok) {
        $i_questionno = 0;
        while (!$i_rSet7->EOF) {
            $i_questionno++;
            $i_answers = array();
            $i_rSet5 = $g_db->Execute("SELECT answer_text, answer_correct FROM " . $srv_settings['table_prefix'] . "answers WHERE questionid=" . $i_rSet7->fields['questionid'] . " ORDER BY answerid");
            if (!$i_rSet5) {
                showDBError(__FILE__, 5);
            } else {
                $i_answerno = 1;
                while (!$i_rSet5->EOF) {
                    $i_answers[$i_answerno] = $i_rSet5->fields['answer_text'];
                    $i_answers_correct[$i_answerno] = $i_rSet5->fields['answer_correct'];
                    $i_answerno++;
                    $i_rSet5->MoveNext();
                }
                $i_rSet5->Close();
            }
            $i_detailed_correct = $i_rSet7->fields['result_answer_iscorrect'] == IGT_ANSWER_IS_CORRECT;
            $i_result_detailed_3_items[$i_questionno] = $i_questionno . '. ' . getTruncatedHTML($i_rSet7->fields['question_text'], 0);
            $i_result_detailed_1_items[$i_questionno] = $i_result_detailed_3_items[$i_questionno] . '<br />';
            $i_result_detailed_1_items[$i_questionno] .= $lngstr['email_answer_iscorrect'] . ($i_rSet7->fields['result_answer_iscorrect'] == IGT_ANSWER_IS_UNDEFINED ? $lngstr['label_undefined'] : ($i_rSet7->fields['result_answer_iscorrect'] == IGT_ANSWER_IS_CORRECT ? $lngstr['label_yes'] : ($i_rSet7->fields['result_answer_iscorrect'] == IGT_ANSWER_IS_PARTIALLYCORRECT ? $lngstr['label_partially'] : $lngstr['label_no']))) . '<br />';
            $i_result_detailed_1_items[$i_questionno] .= $lngstr['email_answer_points'] . $i_rSet7->fields['result_answer_points'] . '<br />';
            if (!$i_detailed_correct) {
                $i_result_detailed_2_items[$i_questionno] = $i_result_detailed_1_items[$i_questionno];
            }
            $i_result_detailed_3_items[$i_questionno] = '<tr><td>' . $i_result_detailed_3_items[$i_questionno] . '</td></tr>';
            for ($i = 1; $i < $i_answerno; $i++) {
                switch ($i_rSet7->fields['question_type']) {
                    case QUESTION_TYPE_MULTIPLECHOICE:
                    case QUESTION_TYPE_TRUEFALSE:
                        $i_answers_given = (int) $i_rSet7->fields['result_answer_text'];
                        $i_result_detailed_3_items[$i_questionno] .= '<tr><td><img src="images/button-checkbox-' . ($i_answers_correct[$i] ? '2' : ($i == $i_answers_given ? '4' : '0')) . '.gif" width=13 height=13> &nbsp; ' . $i_answers[$i] . '</tr>';
                        break;
                    case QUESTION_TYPE_MULTIPLEANSWER:
                        $i_answers_given = explode(QUESTION_TYPE_MULTIPLEANSWER_BREAK, $i_rSet7->fields['result_answer_text']);
                        $i_result_detailed_3_items[$i_questionno] .= '<tr><td><img src="images/button-checkbox-' . ($i_answers_correct[$i] ? '2' : (in_array($i, $i_answers_given) ? '4' : '0')) . '.gif" width=13 height=13> &nbsp; ' . $i_answers[$i] . '</tr>';
                        break;
                    case QUESTION_TYPE_FILLINTHEBLANK:
                        $i_result_detailed_3_items[$i_questionno] .= '<tr><td>' . nl2br($i_answers[$i]) . '</td></tr>';
                        break;
                }
            }
            if ($i_rSet7->fields['question_type'] == QUESTION_TYPE_ESSAY) {
                $i_result_detailed_3_items[$i_questionno] .= '<tr><td>' . nl2br($i_rSet7->fields['result_answer_text']) . '</td></tr>';
            }
            $i_result_detailed_3_items[$i_questionno] .= '<tr><td>' . $lngstr['email_answer_points'] . $i_rSet7->fields['result_answer_points'] . '</td></tr>';
            if (!$i_detailed_correct) {
                $i_result_detailed_4_items[$i_questionno] = $i_result_detailed_3_items[$i_questionno];
            }
            $i_rSet7->MoveNext();
        }
        $i_rSet7->Close();
        $i_result_detailed_1_text = implode('<br />', $i_result_detailed_1_items);
        $i_result_detailed_2_text = implode('<br />', $i_result_detailed_2_items);
        $i_result_detailed_3_text = '<table cellpadding=0 cellspacing=0 border=0 width="100%">' . implode("\n", $i_result_detailed_3_items) . '</table>';
        $i_result_detailed_4_text = '<table cellpadding=0 cellspacing=0 border=0 width="100%">' . implode("\n", $i_result_detailed_4_items) . '</table>';
        $i_result_detailed_5_text = '';
        $i_result_detailed_6_text = '';
        $i_pdf = eventOnQueryCustomReportPDF();
        if (empty($i_pdf)) {
            $i_pdf = new HTML2FPDF();
            $i_pdf->AddPage();
            $i_pdf->SetFont('Arial', '', 11);
            $i_pdf->SetTextColor(0, 0, 0);
            $g_vars['page']['grade'] = getGradeData($i_rSet2->fields['gscaleid'], $i_rSet2->fields['gscale_gradeid']);
            $g_vars['page']['subjects'] = getTestResultSubjectsData($resultid);
            $i_template_body = getReportTemplate(array('rtemplateid' => $i_rSet3->fields['rtemplateid'], 'username' => $i_rSet6->fields['username'], 'email' => $i_rSet6->fields['email'], 'title' => $i_rSet6->fields['user_title'], 'firstname' => $i_rSet6->fields['user_firstname'], 'lastname' => $i_rSet6->fields['user_lastname'], 'middlename' => $i_rSet6->fields['user_middlename'], 'address' => $i_rSet6->fields['user_address'], 'city' => $i_rSet6->fields['user_city'], 'state' => $i_rSet6->fields['user_state'], 'zip' => $i_rSet6->fields['user_zip'], 'country' => $i_rSet6->fields['user_country'], 'phone' => $i_rSet6->fields['user_phone'], 'fax' => $i_rSet6->fields['user_fax'], 'mobile' => $i_rSet6->fields['user_mobile'], 'pager' => $i_rSet6->fields['user_pager'], 'ipphone' => $i_rSet6->fields['user_ipphone'], 'webpage' => $i_rSet6->fields['user_webpage'], 'icq' => $i_rSet6->fields['user_icq'], 'msn' => $i_rSet6->fields['user_msn'], 'aol' => $i_rSet6->fields['user_aol'], 'gender' => $i_rSet6->fields['user_gender'], 'birthday' => $i_rSet6->fields['user_birthday'], 'husbandwife' => $i_rSet6->fields['user_husbandwife'], 'children' => $i_rSet6->fields['user_children'], 'trainer' => $i_rSet6->fields['user_trainer'], 'photo' => $i_rSet6->fields['user_photo'], 'company' => $i_rSet6->fields['user_company'], 'cposition' => $i_rSet6->fields['user_cposition'], 'department' => $i_rSet6->fields['user_department'], 'coffice' => $i_rSet6->fields['user_coffice'], 'caddress' => $i_rSet6->fields['user_caddress'], 'ccity' => $i_rSet6->fields['user_ccity'], 'cstate' => $i_rSet6->fields['user_cstate'], 'czip' => $i_rSet6->fields['user_czip'], 'ccountry' => $i_rSet6->fields['user_ccountry'], 'cphone' => $i_rSet6->fields['user_cphone'], 'cfax' => $i_rSet6->fields['user_cfax'], 'cmobile' => $i_rSet6->fields['user_cmobile'], 'cpager' => $i_rSet6->fields['user_cpager'], 'cipphone' => $i_rSet6->fields['user_cipphone'], 'cwebpage' => $i_rSet6->fields['user_cwebpage'], 'cphoto' => $i_rSet6->fields['user_cphoto'], 'ufield1' => $i_rSet6->fields['user_ufield1'], 'ufield2' => $i_rSet6->fields['user_ufield2'], 'ufield3' => $i_rSet6->fields['user_ufield3'], 'ufield4' => $i_rSet6->fields['user_ufield4'], 'ufield5' => $i_rSet6->fields['user_ufield5'], 'ufield6' => $i_rSet6->fields['user_ufield6'], 'ufield7' => $i_rSet6->fields['user_ufield7'], 'ufield8' => $i_rSet6->fields['user_ufield8'], 'ufield9' => $i_rSet6->fields['user_ufield9'], 'ufield10' => $i_rSet6->fields['user_ufield10'], 'test_name' => $i_rSet3->fields['test_name'], 'result_id' => $resultid, 'result_date' => getDateLocal($lngstr['language']['date_format_full'], $i_rSet2->fields['result_datestart']), 'result_time_spent' => getTimeFormatted($i_rSet2->fields['result_timespent']), 'result_time_exceeded' => $i_rSet2->fields['result_timeexceeded'] > 0 ? $lngstr['label_yes'] : $lngstr['label_no'], 'result_points_scored' => $i_rSet2->fields['result_points'], 'result_points_possible' => $i_rSet2->fields['result_pointsmax'], 'result_percents' => $i_rSet2->fields['result_pointsmax'] > 0 ? round($i_rSet2->fields['result_points'] * 100 / $i_rSet2->fields['result_pointsmax']) : 0, 'result_grade' => $g_vars['page']['grade']['name'], 'result_grade_feedback' => $g_vars['page']['grade']['feedback'], 'result_subjects' => $g_vars['page']['subjects'], 'result_detailed_1' => $i_result_detailed_1_text, 'result_detailed_2' => $i_result_detailed_2_text, 'result_detailed_3' => $i_result_detailed_3_text, 'result_detailed_4' => $i_result_detailed_4_text, 'result_detailed_5' => $i_result_detailed_5_text, 'result_detailed_6' => $i_result_detailed_6_text));
            $i_pdf->WriteHTML($i_template_body);
        }
    } else {
        $i_pdf = false;
    }
    ob_end_clean();
    return $i_pdf;
}
    }
}
echo '<td width=2><img src="images/toolbar-right.gif" width=2 height=32></td></tr></table>';
echo '</td></tr><tr><td>';
echo '<table class=rowtable2 cellpadding=5 cellspacing=1 border=0 width="100%">';
echo '<tr vAlign=top><td class=rowhdr1 title="' . $lngstr['label_hdr_select_hint'] . '" width=22><input type=checkbox name=toggleAll onclick="toggleCBs(this);"></td>';
writeQryTableHeaders('test-manager.php?action=' . $i_testid_addon . $i_subjectid_addon . $i_url_limit_addon, $i_tablefields, $i_order_no, $i_direction);
echo '<td class=rowhdr1 colspan=5>' . $lngstr['label_hdr_action'] . '</td></tr>';
$i_rSet1 = $g_db->SelectLimit("SELECT " . $srv_settings['table_prefix'] . "tests.testid, " . $srv_settings['table_prefix'] . "tests.test_name, " . $srv_settings['table_prefix'] . "tests.subjectid, " . $srv_settings['table_prefix'] . "tests.test_datestart, " . $srv_settings['table_prefix'] . "tests.test_dateend, " . $srv_settings['table_prefix'] . "tests.test_notes, " . $srv_settings['table_prefix'] . "tests.test_enabled, " . $srv_settings['table_prefix'] . "subjects.subject_name FROM " . $srv_settings['table_prefix'] . "tests, " . $srv_settings['table_prefix'] . "subjects WHERE " . $i_sql_where_addon . "" . $srv_settings['table_prefix'] . "tests.subjectid=" . $srv_settings['table_prefix'] . "subjects.subjectid" . $i_sql_order_addon, $i_limitcount, $i_limitfrom);
if (!$i_rSet1) {
    showDBError(__FILE__, 1);
} else {
    $i_counter = 0;
    while (!$i_rSet1->EOF) {
        $rowname = $i_counter % 2 ? "rowone" : "rowtwo";
        echo '<tr id=tr_' . $i_pagewide_id . ' class=' . $rowname . ' onmouseover="rollTR(' . $i_pagewide_id . ',1);" onmouseout="rollTR(' . $i_pagewide_id . ',0);"><td align=center width=22><input id=cb_' . $i_pagewide_id . ' type=checkbox name=box_tests[] value="' . $i_rSet1->fields["testid"] . '" onclick="toggleCB(this);"></td><td align=right>' . $i_rSet1->fields["testid"] . '</td><td align=center width=16 style="padding: 1px;"><a href="javascript:void(0)" onClick="showDialog(\'test-manager.php?testid=' . $i_rSet1->fields["testid"] . '&action=notes\', 300, 200)"><img src="images/button-notes.gif" width=16 height=20 title="' . convertTextValue($i_rSet1->fields["test_notes"]) . '" border=0></a></td><td>' . convertTextValue($i_rSet1->fields["test_name"]) . '</td><td><a href="test-manager.php?subjectid=' . (isset($_GET["subjectid"]) && $_GET["subjectid"] != "" ? "" : $i_rSet1->fields["subjectid"]) . $i_order_addon . $i_url_limitto_addon . '">' . convertTextValue($i_rSet1->fields["subject_name"]) . '</a></td><td>' . getDateLocal($lngstr['language']['date_format'], $i_rSet1->fields["test_datestart"]) . '</td><td>' . getDateLocal($lngstr['language']['date_format'], $i_rSet1->fields["test_dateend"]) . '</td><td align=center><a href="test-manager.php?testid=' . $i_rSet1->fields["testid"] . $i_order_addon . $i_url_limit_addon . '&action=enable&set=' . ($i_rSet1->fields["test_enabled"] ? '0"><img src="images/button-checkbox-2.gif" width=13 height=13 border=0 title="' . $lngstr['label_yes'] . '">' : '1"><img src="images/button-checkbox-0.gif" width=13 height=13 border=0 title="' . $lngstr['label_no'] . '">') . '</a></td>';
        echo '<td align=center width=22><a href="test-manager.php?testid=' . $i_rSet1->fields["testid"] . '&action=settings"><img width=20 height=20 border=0 src="images/button-gear.gif" title="' . $lngstr['label_action_test_settings'] . '"></a></td>';
        if (IGT_TESTMANAGER_SHOWSTATS) {
            echo '<td align=center width=22><a href="test-manager.php?testids=' . $i_rSet1->fields["testid"] . '&action=statst"><img width=20 height=20 border=0 src="images/button-stats.gif" title="' . $lngstr['page_testmanager']['view_test_stats'] . '"></a></td>';
        }
        echo '<td align=center width=22><a href="test-manager.php?testids=' . $i_rSet1->fields["testid"] . '&action=groups"><img width=20 height=20 border=0 src="images/button-groups.gif" title="' . $lngstr['label_action_test_groups_select'] . '"></a></td>';
        echo '<td align=center width=22><a href="test-manager.php?testid=' . $i_rSet1->fields["testid"] . '&action=editt"><img width=20 height=20 border=0 src="images/button-edit.gif" title="' . $lngstr['label_action_questions_edit'] . '"></a></td>';
        echo '<td align=center width=22><a href="test-manager.php?testid=' . $i_rSet1->fields["testid"] . '&action=delete" onclick="return confirmMessage(this, \'' . $lngstr['qst_delete_test'] . '\')"><img width=20 height=20 border=0 src="images/button-cross.gif" title="' . $lngstr['label_action_test_delete'] . '"></a></td>';
        echo '</tr>';
        $i_counter++;
        $i_pagewide_id++;
        $i_rSet1->MoveNext();
    }
    $i_rSet1->Close();
}
echo '</table>';
}
if ($i_order_no >= 0) {
    $i_direction = isset($_GET['direction']) && $_GET['direction'] ? 'DESC' : '';
    $i_order_addon = '&order=' . $i_order_no . '&direction=' . $i_direction;
    $i_sql_order_addon = ' ORDER BY ' . $i_tablefields[$i_order_no][2] . ' ' . $i_direction;
}
$i_column_names = array();
foreach ($i_columns as $val) {
    array_push($i_column_names, csvQuote($lngstr['page_reportsmanager']['fields']['name'][$val]));
}
$i_filecontent .= implode($i_delimiter, $i_column_names) . "\n";
$i_rSet1 = $g_db->Execute("SELECT " . $srv_settings['table_prefix'] . "results.resultid, " . $srv_settings['table_prefix'] . "results.result_datestart, " . $srv_settings['table_prefix'] . "results.id, " . $srv_settings['table_prefix'] . "users.username, " . $srv_settings['table_prefix'] . "users.user_firstname, " . $srv_settings['table_prefix'] . "users.user_lastname, " . $srv_settings['table_prefix'] . "results.testid, " . $srv_settings['table_prefix'] . "tests.test_name, " . $srv_settings['table_prefix'] . "tests.test_attempts, " . $srv_settings['table_prefix'] . "tests.test_result_showpdf, " . $srv_settings['table_prefix'] . "tests.rtemplateid, " . $srv_settings['table_prefix'] . "tests.test_reportgradecondition, " . $srv_settings['table_prefix'] . "tests.test_nexttestid, " . $srv_settings['table_prefix'] . "results.gscale_gradeid, " . $srv_settings['table_prefix'] . "results.result_timeexceeded, " . $srv_settings['table_prefix'] . "results.result_points, " . $srv_settings['table_prefix'] . "results.result_pointsmax, ((" . $srv_settings['table_prefix'] . "results.result_points * 100) / " . $srv_settings['table_prefix'] . "results.result_pointsmax) as result_score, " . $srv_settings['table_prefix'] . "results.gscaleid, " . $srv_settings['table_prefix'] . "gscales_grades.grade_name, " . $srv_settings['table_prefix'] . "gscales_grades.grade_description FROM " . $srv_settings['table_prefix'] . "results, " . $srv_settings['table_prefix'] . "users, " . $srv_settings['table_prefix'] . "tests, " . $srv_settings['table_prefix'] . "gscales_grades WHERE " . $i_sql_where_addon . "" . $srv_settings['table_prefix'] . "results.id=" . $srv_settings['table_prefix'] . "users.id AND " . $srv_settings['table_prefix'] . "results.testid=" . $srv_settings['table_prefix'] . "tests.testid AND " . $srv_settings['table_prefix'] . "results.gscaleid=" . $srv_settings['table_prefix'] . "gscales_grades.gscaleid AND " . $srv_settings['table_prefix'] . "results.gscale_gradeid=" . $srv_settings['table_prefix'] . "gscales_grades.gscale_gradeid" . $i_sql_order_addon);
if (!$i_rSet1) {
    showDBError(__FILE__, 1);
} else {
    while (!$i_rSet1->EOF) {
        $i_rSet1->fields['result_datestart_formatted'] = getDateLocal($lngstr['language']['date_format'], $i_rSet1->fields['result_datestart']);
        foreach ($i_columns as $i_column) {
            $i_filecontent .= csvQuote($i_rSet1->fields[$i_column]) . $i_delimiter;
        }
        $i_filecontent = substr($i_filecontent, 0, strlen($i_filecontent) - 1) . "\n";
        $i_rSet1->MoveNext();
    }
    $i_rSet1->Close();
}
header('Pragma: private');
header('Cache-control: private, must-revalidate');
header('Content-Length: ' . strlen($i_filecontent));
header('Content-Type: application/csv');
header('Content-Disposition: attachment; filename="' . $i_filename . '"');
echo $i_filecontent;
function writeResultStats($i_resultid)
{
    global $g_db, $lngstr, $srv_settings, $g_vars;
    $g_vars['page']['resultid'] = $i_resultid;
    $i_testid = 0;
    $i_rSet6 = $g_db->SelectLimit("SELECT * FROM " . $srv_settings['table_prefix'] . "results WHERE resultid=" . $i_resultid, 1);
    if (!$i_rSet6) {
        showDBError(__FILE__, 6);
    } else {
        if (!$i_rSet6->EOF) {
            $i_testid = $i_rSet6->fields['testid'];
            $g_vars['page']['result_date'] = getDateLocal($lngstr['language']['date_format_full'], $i_rSet6->fields['result_datestart']);
            $g_vars['page']['time_spent'] = getTimeFormatted($i_rSet6->fields['result_timespent']);
            $g_vars['page']['got_points'] = $i_rSet6->fields['result_points'];
            $g_vars['page']['points_max'] = $i_rSet6->fields['result_pointsmax'];
            $g_vars['page']['score'] = $g_vars['page']['points_max'] != 0 ? round($g_vars['page']['got_points'] * 100 / $g_vars['page']['points_max']) : 100;
            $g_vars['page']['grade'] = getGradeData($i_rSet6->fields['gscaleid'], $i_rSet6->fields['gscale_gradeid']);
            $i_id = $i_rSet6->fields['id'];
            $i_rSet7 = $g_db->SelectLimit("SELECT * FROM " . $srv_settings['table_prefix'] . "users WHERE id=" . $i_id, 1);
            if (!$i_rSet7) {
                showDBError(__FILE__, 7);
            } else {
                if (!$i_rSet7->EOF) {
                    $g_vars['page']['username'] = $i_rSet7->fields['user_firstname'] . ' ' . $i_rSet7->fields['user_lastname'];
                }
                $i_rSet7->Close();
            }
        }
        $i_rSet6->Close();
    }
    $g_vars['page']['test_name'] = '';
    $i_gscaleid = 0;
    $i_rSet1 = $g_db->SelectLimit("SELECT * FROM " . $srv_settings['table_prefix'] . "tests WHERE testid=" . $i_testid, 1);
    if (!$i_rSet1) {
        showDBError(__FILE__, 1);
    } else {
        if (!$i_rSet1->EOF) {
            $g_vars['page']['test_name'] = $i_rSet1->fields['test_name'];
            $i_gscaleid = $i_rSet1->fields['gscaleid'];
        }
        $i_rSet1->Close();
    }
    $g_vars['page']['grades_times_total'] = 0;
    $i_rSet2 = $g_db->Execute("SELECT * FROM " . $srv_settings['table_prefix'] . "gscales_grades WHERE gscaleid=" . $i_gscaleid . " ORDER BY gscale_gradeid");
    if (!$i_rSet2) {
        showDBError(__FILE__, 2);
    } else {
        while (!$i_rSet2->EOF) {
            $i_gradeid = $i_rSet2->fields['gscale_gradeid'];
            $g_vars['page']['grades'][$i_gradeid]['name'] = $i_rSet2->fields['grade_name'];
            $g_vars['page']['grades'][$i_gradeid]['times'] = getRecordCount($srv_settings['table_prefix'] . 'results', 'testid=' . $i_testid . ' AND gscaleid=' . $i_gscaleid . ' AND gscale_gradeid=' . $i_gradeid);
            $g_vars['page']['grades_times_total'] += $g_vars['page']['grades'][$i_gradeid]['times'];
            $i_rSet2->MoveNext();
        }
        $i_rSet2->Close();
    }
    foreach ($g_vars['page']['grades'] as $i_gradeid => $i_grade) {
        $g_vars['page']['grades'][$i_gradeid]['times_percents'] = $g_vars['page']['grades_times_total'] != 0 ? $g_vars['page']['grades'][$i_gradeid]['times'] * 100 / $g_vars['page']['grades_times_total'] : 0;
    }
    $g_vars['page']['test']['participant_count'] = 0;
    $i_points_all = array();
    $g_vars['page']['test']['points_max'] = 0;
    $g_vars['page']['test']['points_low'] = IGT_MAX_FLOAT;
    $g_vars['page']['test']['points_high'] = 0;
    $i_points_total = 0;
    $g_vars['page']['test']['points_total_max'] = 0;
    $i_rSet3 = $g_db->Execute("SELECT * FROM " . $srv_settings['table_prefix'] . "results WHERE testid=" . $i_testid . " AND gscale_gradeid > 0");
    if (!$i_rSet3) {
        showDBError(__FILE__, 3);
    } else {
        while (!$i_rSet3->EOF) {
            $g_vars['page']['test']['participant_count']++;
            $i_points = $i_rSet3->fields['result_points'];
            array_push($i_points_all, $i_points);
            $g_vars['page']['test']['points_max'] = $i_rSet3->fields['result_pointsmax'];
            if ($i_points > $g_vars['page']['test']['points_high']) {
                $g_vars['page']['test']['points_high'] = $i_points;
            }
            if ($i_points < $g_vars['page']['test']['points_low']) {
                $g_vars['page']['test']['points_low'] = $i_points;
            }
            $i_points_total += $i_points;
            $g_vars['page']['test']['points_total_max'] += $g_vars['page']['test']['points_max'];
            $i_rSet3->MoveNext();
        }
        $i_rSet3->Close();
    }
    $g_vars['page']['test']['points_average'] = $i_points_total / $g_vars['page']['test']['participant_count'];
    $g_vars['page']['test']['points_average_percents'] = $i_points_total * 100 / $g_vars['page']['test']['points_total_max'];
    $g_vars['page']['test']['points_high_percents'] = $g_vars['page']['test']['points_high'] * 100 / $g_vars['page']['test']['points_max'];
    $g_vars['page']['test']['points_low_percents'] = $g_vars['page']['test']['points_low'] * 100 / $g_vars['page']['test']['points_max'];
    $g_vars['page']['test']['variance'] = 0;
    if ($g_vars['page']['test']['participant_count'] > 1) {
        foreach ($i_points_all as $i_points) {
            $g_vars['page']['test']['variance'] += ($i_points - $g_vars['page']['test']['points_average']) * ($i_points - $g_vars['page']['test']['points_average']);
        }
        $g_vars['page']['test']['variance'] = $g_vars['page']['test']['variance'] / ($g_vars['page']['test']['participant_count'] - 1);
    }
    $g_vars['page']['test']['std_deviation'] = sqrt($g_vars['page']['test']['variance']);
    $g_vars['page']['questions'] = array();
    $i_rSet4 = $g_db->Execute("SELECT questionid, result_answer_iscorrect FROM " . $srv_settings['table_prefix'] . "results_answers WHERE resultid=" . $i_resultid);
    if (!$i_rSet4) {
        showDBError(__FILE__, 4);
    } else {
        while (!$i_rSet4->EOF) {
            $i_questionid = $i_rSet4->fields['questionid'];
            $g_vars['page']['questions'][$i_questionid]['iscorrect'] = $i_rSet4->fields['result_answer_iscorrect'];
            $i_rSet4->MoveNext();
        }
        $i_rSet4->Close();
    }
    $g_vars['page']['subjects'] = array();
    foreach ($g_vars['page']['questions'] as $i_questionid => $i_question) {
        $i_rSet5 = $g_db->SelectLimit("SELECT " . $srv_settings['table_prefix'] . "subjects.subjectid, " . $srv_settings['table_prefix'] . "subjects.subject_name FROM " . $srv_settings['table_prefix'] . "questions, " . $srv_settings['table_prefix'] . "subjects WHERE questionid=" . $i_questionid . " AND " . $srv_settings['table_prefix'] . "questions.subjectid=" . $srv_settings['table_prefix'] . "subjects.subjectid", 1);
        if (!$i_rSet5) {
            showDBError(__FILE__, 5);
        } else {
            if (!$i_rSet5->EOF) {
                $i_subjectid = $i_rSet5->fields['subjectid'];
                $g_vars['page']['subjects'][$i_subjectid]['question_count'] = getRecordCount($srv_settings['table_prefix'] . 'questions', 'subjectid=' . $i_subjectid);
                if (!isset($g_vars['page']['subjects'][$i_subjectid]['question_got'])) {
                    $g_vars['page']['subjects'][$i_subjectid]['name'] = $i_rSet5->fields['subject_name'];
                    $g_vars['page']['subjects'][$i_subjectid]['question_got'] = 0;
                    $g_vars['page']['subjects'][$i_subjectid]['question_correct'] = 0;
                }
                $g_vars['page']['subjects'][$i_subjectid]['question_got']++;
                if ($i_question['iscorrect'] == IGT_ANSWER_IS_CORRECT) {
                    $g_vars['page']['subjects'][$i_subjectid]['question_correct']++;
                }
            }
            $i_rSet5->Close();
        }
    }
    foreach ($g_vars['page']['subjects'] as $i_subjectid => $i_grade) {
        $g_vars['page']['subjects'][$i_subjectid]['question_correct_percents'] = $g_vars['page']['subjects'][$i_subjectid]['question_correct'] * 100 / $g_vars['page']['subjects'][$i_subjectid]['question_got'];
    }
}
        echo '<td width=32><a href="visitors.php?pageno=' . $i_pageno_count . $i_url_pages_addon . '"><img src="images/button-last-big.gif" border=0 title="' . $lngstr['button_last_page'] . '"></a></td>';
    } else {
        echo '<td width=32><img src="images/button-next-big-inactive.gif" border=0 title="' . $lngstr['button_next_page'] . '"></td>';
        echo '<td width=32><img src="images/button-last-big-inactive.gif" border=0 title="' . $lngstr['button_last_page'] . '"></td>';
    }
}
echo '<td width=2><img src="images/toolbar-right.gif" width=2 height=32></td></tr></table>';
echo '</td></tr><tr><td>';
echo '<table class=rowtable2 cellpadding=5 cellspacing=1 border=0 width="100%">';
echo '<tr vAlign=top><td class=rowhdr1 title="' . $lngstr['label_hdr_select_hint'] . '" width=22><input type=checkbox name=toggleAll onclick="toggleCBs(this);"></td>';
writeQryTableHeaders('visitors.php?action=' . $i_url_limit_addon, $i_tablefields, $i_order_no, $i_direction);
echo '<td class=rowhdr1 colspan=2>' . $lngstr['label_hdr_action'] . '</td></tr>';
$i_rSet1 = $g_db->SelectLimit("SELECT *, ip1, ip2, ip3, ip4, " . $srv_settings['table_prefix'] . "users.username FROM " . $srv_settings['table_prefix'] . "visitors, " . $srv_settings['table_prefix'] . "users WHERE ((" . $srv_settings['table_prefix'] . "visitors.id=0 AND " . $srv_settings['table_prefix'] . "users.id=2) OR " . $srv_settings['table_prefix'] . "visitors.id=" . $srv_settings['table_prefix'] . "users.id)" . $i_sql_order_addon, $i_limitcount, $i_limitfrom);
if (!$i_rSet1) {
    showDBError(__FILE__, 1);
} else {
    $i_counter = 0;
    while (!$i_rSet1->EOF) {
        $rowname = $i_counter % 2 ? "rowone" : "rowtwo";
        $i_ip = $i_rSet1->fields['ip1'] . '.' . $i_rSet1->fields['ip2'] . '.' . $i_rSet1->fields['ip3'] . '.' . $i_rSet1->fields['ip4'];
        echo '<tr id=tr_' . $i_pagewide_id . ' class=' . $rowname . ' onmouseover="rollTR(' . $i_pagewide_id . ',1);" onmouseout="rollTR(' . $i_pagewide_id . ',0);"><td align=center width=22><input id=cb_' . $i_pagewide_id . ' type=checkbox name=box_visitors[] value="' . $i_rSet1->fields['visitorid'] . '" onclick="toggleCB(this);"></td><td align=right>' . $i_rSet1->fields['visitorid'] . '</td><td>' . getDateLocal($lngstr['language']['date_format'], $i_rSet1->fields['startdate']) . '</td><td><nobr>' . convertTextValue($i_rSet1->fields['username']) . ' [<a href="users.php?id=' . $i_rSet1->fields['id'] . '&action=edit" title="' . $lngstr['label']['view_edit_user'] . '">' . $i_rSet1->fields['id'] . '</a>]</nobr></td><td>' . $i_rSet1->fields['hits'] . '</td><td><a href="http://www.whois.sc/' . $i_ip . '" title="' . $lngstr['page_visitors']['ipwhois'] . '" target=_blank>' . $i_ip . '</a></td><td>' . truncateString(convertTextValue($i_rSet1->fields['host'])) . '</td><td>' . truncateString(convertTextValue($i_rSet1->fields['referer'])) . '</td>';
        echo '<td align=center width=22><a href="visitors.php?action=view&visitorid=' . $i_rSet1->fields['visitorid'] . $i_order_addon . $i_url_limit_addon . '"><img width=20 height=20 border=0 src="images/button-view.gif" title="' . $lngstr['label_action_visitors_view'] . '"></a></td><td align=center width=22><a href="visitors.php?action=delete&visitorid=' . $i_rSet1->fields['visitorid'] . $i_order_addon . $i_url_limit_addon . '" onclick="return confirmMessage(this, \'' . $lngstr['qst_delete_visitor'] . '\')"><img width=20 height=20 border=0 src="images/button-cross.gif" title="' . $lngstr['label_action_visitor_delete'] . '"></a></td></tr>';
        $i_counter++;
        $i_pagewide_id++;
        $i_rSet1->MoveNext();
    }
    $i_rSet1->Close();
}
echo '</table>';
echo '</td></tr></table></form>';
displayTemplate('_footer');
}
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');
Exemplo n.º 7
0
 if ($i_isallowed) {
     $i_test_count++;
     $g_vars['page']['test'][$i_test_count]['testid'] = $i_rSet1->fields['testid'];
     $g_vars['page']['test'][$i_test_count]['name'] = $i_rSet1->fields['test_name'] ? convertTextValue($i_rSet1->fields['test_name']) : $lngstr['label_noname'];
     $g_vars['page']['test'][$i_test_count]['code'] = $i_rSet1->fields['test_code'];
     $g_vars['page']['test'][$i_test_count]['description'] = convertTextValue($i_rSet1->fields['test_description']);
     $g_vars['page']['test'][$i_test_count]['startdate'] = $i_rSet1->fields['test_datestart'];
     $g_vars['page']['test'][$i_test_count]['attempts'] = getTestAttemptsUsed($i_rSet1->fields['testid'], $G_SESSION['id']);
     $g_vars['page']['test'][$i_test_count]['attempts_total'] = $i_rSet1->fields['test_attempts'];
     $g_vars['page']['test'][$i_test_count]['test_price'] = $i_rSet1->fields['test_price'] / 100;
     $g_vars['page']['test'][$i_test_count]['test_purchased'] = $i_rSet1->fields['test_price'] <= 0 || getRecordCount($srv_settings['table_prefix'] . 'tests_own', 'testid=' . $i_rSet1->fields['testid'] . ' AND id=' . $G_SESSION['id']) > 0;
     $g_vars['page']['test'][$i_test_count]['content_protection'] = $i_rSet1->fields['test_contentprotection'];
     $g_vars['page']['test'][$i_test_count]['status'] = IGT_TEST_STATUS_UNAVAILABLE;
     $g_vars['page']['test'][$i_test_count]['visible'] = true;
     if ($i_rSet1->fields['test_datestart'] > $now) {
         $g_vars['page']['test'][$i_test_count]['status_label'] = sprintf($lngstr['page_panel_status_will_be_available_on'], getDateLocal($lngstr['language']['date_format'], $i_rSet1->fields['test_datestart']));
     } else {
         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;
            $arrUserData = $i_rSet1->fields;
        }
        $i_rSet1->Close();
        unset($i_rSet1);
    }
}
$g_vars['page']['is_new_record'] = empty($arrUserData);
echo '<p><form method=post action="users.php?id=' . ($f_id > 0 ? $f_id : '') . '&action=edit">';
echo '<table class=rowtable2 cellpadding=5 cellspacing=1 border=0 width="100%">';
$i_rowno = 0;
if ($G_SESSION['access_users'] != 1 && $G_SESSION['access_users'] != 3) {
    echo '<tr class=rowtwo valign=top><td colspan=2>' . getCheckbox('user_enabled', isset($arrUserData['user_enabled']) ? $arrUserData['user_enabled'] : true, $lngstr['page_users']['userenabled']) . '</td></tr>';
    $i_rowno = 1;
    writeTR2Fixed($lngstr['page_users']['joindate'], isset($arrUserData['user_joindate']) && $arrUserData['user_joindate'] > 0 ? getDateLocal($lngstr['language']['date_format_full'], $arrUserData['user_joindate']) : '');
    writeTR2Fixed($lngstr['page_users']['logindate'], isset($arrUserData['user_logindate']) && $arrUserData['user_logindate'] > 0 ? getDateLocal($lngstr['language']['date_format_full'], $arrUserData['user_logindate']) : '');
    $strExpireDateFormatted = !empty($arrUserData['user_expiredate']) && $arrUserData['user_expiredate'] > 0 ? getDateLocal($lngstr['language']['calendar']['date_format'], $arrUserData['user_expiredate']) : '';
    $strExpireDate = '<input name="user_expiredate" id="user_expiredate" value="' . $strExpireDateFormatted . '" class=inp type=text size=20><a href="javascript:void(0);" title="' . $lngstr['calendar']['hint'] . '"><img src="images/button-calendar.gif" alt="' . $lngstr['calendar']['hint'] . '" class="calendar-icon" onclick="return showCalendar(\'user_expiredate\', \'' . $lngstr['language']['calendar']['date_format'] . '\', \'24\', true);" onmouseover="this.className+=\' calendar-icon-hover\';" onmouseout="this.className = this.className.replace(/\\s*calendar-icon-hover/ig, \'\');"></a>';
    writeTR2Fixed($lngstr['page_users']['expiredate'], $strExpireDate);
}
writeTR2Fixed($lngstr['page_users']['username'], getInputElement('username', @$arrUserData['username']));
writeTR2Fixed($lngstr['page_users']['password_new'], getPasswordBox('user_password', ''));
writeTR2Fixed($lngstr['page_users']['password_confirm'], getPasswordBox('user_password_confirm', ''));
writeTR2Fixed($lngstr['page_users']['email'], getInputElement('email', @$arrUserData['email']));
writeTR2Fixed($lngstr['page_users']['firstname'], getInputElement('user_firstname', @$arrUserData['user_firstname']));
writeTR2Fixed($lngstr['page_users']['lastname'], getInputElement('user_lastname', @$arrUserData['user_lastname']));
writeTR2Fixed($lngstr['page_users']['middlename'], getInputElement('user_middlename', @$arrUserData['user_middlename']));
if ($G_SESSION['access_users'] != 1 && $G_SESSION['access_users'] != 3) {
    echo '<tr valign=top><td class=rowhdr2 colspan=2><a class=rowhdr2 href="javascript:void(0)" onclick="javascript:toggleSection(\'div_users_groups\')">' . $lngstr['page_users']['section_groups'] . '</td></tr>';
    echo '<tr valign=top><td class=rowone colspan=2><div id=div_users_groups style="display:' . (isset($_COOKIE['div_users_groups']) && $_COOKIE['div_users_groups'] == 'Y' ? 'block' : 'none') . '"><table class=rowtable2 cellpadding=5 cellspacing=1 border=0 width="100%">';
    $i_groups_text = '';
    $arrUserGroups = array();
    while (!$i_rSet1->EOF) {
        $g_vars['page']['tables'][1]['rows'][$i_counter]['visible'] = true;
        $i_attempt_count = 0;
        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);
$i_rSet1 = $g_db->Execute("SELECT * FROM " . $srv_settings['table_prefix'] . "visitors WHERE visitorid={$f_visitorid}");
if (!$i_rSet1) {
    showDBError(__FILE__, 1);
} else {
    if (!$i_rSet1->EOF) {
        echo '<table class=rowtable2 cellpadding=5 cellspacing=1 border=0 width="100%">';
        $i_rowno = 0;
        writeTR2($lngstr['page_visitordetails_visitorid'], $i_rSet1->fields["visitorid"]);
        writeTR2($lngstr['page_visitordetails_timespent'], getTimeFormatted($i_rSet1->fields["enddate"] - $i_rSet1->fields["startdate"]));
        $i_username = '';
        $i_rSet2 = $g_db->Execute("SELECT * FROM " . $srv_settings['table_prefix'] . "users WHERE id=" . $i_rSet1->fields["id"]);
        if ($i_rSet2) {
            if (!$i_rSet2->EOF) {
                $i_username = $i_rSet2->fields["username"];
            }
        }
        writeTR2($lngstr['page_visitordetails_username'], $i_username);
        writeTR2($lngstr['page_visitordetails_hits'], $i_rSet1->fields["hits"]);
        writeTR2($lngstr['page_visitordetails_startdate'], getDateLocal($lngstr['language']['date_format_full'], $i_rSet1->fields["startdate"]));
        writeTR2($lngstr['page_visitordetails_inurl'], '<a href="' . $i_rSet1->fields["inurl"] . '" target=_blank>' . $i_rSet1->fields["inurl"] . '</a>');
        writeTR2($lngstr['page_visitordetails_enddate'], getDateLocal($lngstr['language']['date_format_full'], $i_rSet1->fields["enddate"]));
        writeTR2($lngstr['page_visitordetails_outurl'], '<a href="' . $i_rSet1->fields["outurl"] . '" target=_blank>' . $i_rSet1->fields["outurl"] . '</a>');
        writeTR2($lngstr['page_visitordetails_ipaddress'], $i_rSet1->fields["ip1"] . '.' . $i_rSet1->fields["ip2"] . '.' . $i_rSet1->fields["ip3"] . '.' . $i_rSet1->fields["ip4"]);
        writeTR2($lngstr['page_visitordetails_host'], $i_rSet1->fields["host"]);
        writeTR2($lngstr['page_visitordetails_referer'], '<a href="' . $i_rSet1->fields["referer"] . '" target=_blank>' . $i_rSet1->fields["referer"] . '</a>');
        writeTR2($lngstr['page_visitordetails_useragent'], $i_rSet1->fields["useragent"]);
        echo '</table>';
    }
    $i_rSet1->Close();
}
displayTemplate('_footer');
     }
     $i_rSet2->Close();
 }
 echo '<p><form method=post action="test-manager.php?testid=' . $f_testid . '&action=settings" onsubmit="return submitForm();">';
 echo '<table class=rowtable2 cellpadding=5 cellspacing=1 border=0 width="100%">';
 echo '<tr class=rowtwo valign=top><td colspan=2>' . getCheckbox('test_enabled', $i_rSet1->fields['test_enabled'], $lngstr['page_edittests_testenabled']) . '</td></tr>';
 $i_rowno = 1;
 writeTR2Fixed($lngstr['page_edittests_subjectid'], getSelectElement('subjectid', $i_rSet1->fields['subjectid'], $i_subjects) . ' <a href="subjects.php?testid=' . $f_testid . '">' . $lngstr['label_subjects_edit'] . '</a>');
 writeTR2Fixed($lngstr['page_edittests_testname'], getInputElement('test_name', $i_rSet1->fields['test_name']));
 writeTR2Fixed($lngstr['page_testmanager']['test_code'], getInputElement('test_code', $i_rSet1->fields['test_code']));
 writeTR2Fixed($lngstr['page_edittests_testdescription'], getInputElement('test_description', $i_rSet1->fields['test_description']));
 writeTR2Fixed($lngstr['page_edittests_testinstructions'], getTextEditor($G_SESSION['config_editortype'], 'test_instructions', $i_rSet1->fields['test_instructions']));
 $strTestDateStartFormatted = $i_rSet1->fields['test_datestart'] > 0 ? getDateLocal($lngstr['language']['calendar']['date_format'], $i_rSet1->fields['test_datestart']) : '';
 $strTestDateStart = '<input name="test_datestart" id="test_datestart" value="' . $strTestDateStartFormatted . '" class=inp type=text size=20><a href="javascript:void(0);" title="' . $lngstr['calendar']['hint'] . '"><img src="images/button-calendar.gif" alt="' . $lngstr['calendar']['hint'] . '" class="calendar-icon" onclick="return showCalendar(\'test_datestart\', \'' . $lngstr['language']['calendar']['date_format'] . '\', \'24\', true);" onmouseover="this.className+=\' calendar-icon-hover\';" onmouseout="this.className = this.className.replace(/\\s*calendar-icon-hover/ig, \'\');"></a>';
 writeTR2Fixed($lngstr['page_edittests_teststart'], $strTestDateStart);
 $strTestDateEndFormatted = $i_rSet1->fields['test_dateend'] > 0 ? getDateLocal($lngstr['language']['calendar']['date_format'], $i_rSet1->fields['test_dateend']) : '';
 $strTestDateEnd = '<input name="test_dateend" id="test_dateend" value="' . $strTestDateEndFormatted . '" class=inp type=text size=20><a href="javascript:void(0);" title="' . $lngstr['calendar']['hint'] . '"><img src="images/button-calendar.gif" alt="' . $lngstr['calendar']['hint'] . '" class="calendar-icon" onclick="return showCalendar(\'test_dateend\', \'' . $lngstr['language']['calendar']['date_format'] . '\', \'24\', true);" onmouseover="this.className+=\' calendar-icon-hover\';" onmouseout="this.className = this.className.replace(/\\s*calendar-icon-hover/ig, \'\');"></a>';
 writeTR2Fixed($lngstr['page_edittests_testend'], $strTestDateEnd);
 writeTR2Fixed($lngstr['page_edittests_testtime'], getTimeElement('test_time', $i_rSet1->fields['test_time']) . '<br>' . getCheckbox('test_timeforceout', $i_rSet1->fields['test_timeforceout'], $lngstr['page_edittests_testtimeforceout']));
 writeTR2Fixed($lngstr['page-testmanager']['attempts_allowed'], getSelectElement('test_attempts', $i_rSet1->fields['test_attempts'], $lngstr['page-testmanager']['attempts_allowed_list']));
 $i_gradingsystems = array();
 $i_rSet5 = $g_db->Execute("SELECT gscaleid, gscale_name FROM " . $srv_settings['table_prefix'] . "gscales ORDER BY gscaleid");
 if (!$i_rSet5) {
     showDBError(__FILE__, 5);
 } else {
     while (!$i_rSet5->EOF) {
         $i_gradingsystems[$i_rSet5->fields['gscaleid']] = $i_rSet5->fields['gscale_name'];
         $i_rSet5->MoveNext();
     }
     $i_rSet5->Close();
 }