function getOnePretest($cid) { global $db, $msg; include_once AT_INCLUDE_PATH . '../mods/_standard/tests/lib/test_result_functions.inc.php'; $sql = "SELECT *, UNIX_TIMESTAMP(t.start_date) AS start_date, UNIX_TIMESTAMP(t.end_date) AS end_date \n\t\t FROM " . TABLE_PREFIX . "tests t, " . TABLE_PREFIX . "content_prerequisites cp\n\t\t WHERE cp.content_id=" . $cid . "\n\t\t AND cp.type = '" . CONTENT_PRE_TEST . "'\n\t\t AND cp.item_id=t.test_id"; $result = mysql_query($sql, $db); while ($row = mysql_fetch_assoc($result)) { // check to make sure we can access this test if (!$row['guests'] && ($_SESSION['enroll'] == AT_ENROLL_NO || $_SESSION['enroll'] == AT_ENROLL_ALUMNUS)) { $msg->addInfo('NOT_ENROLLED'); } if (!$row['guests'] && !authenticate_test($row['test_id'])) { $msg->addInfo(array('PRETEST_NO_PRIV', $row['title'])); } // if the test is not release, not allow student to view the content if ($row['start_date'] > time() || $row['end_date'] < time()) { $msg->addInfo(array('PRETEST_EXPIRED', $row['title'])); return -1; } $sql = "SELECT tr.result_id, count(*) num_of_questions, sum(ta.score) score, sum(tqa.weight) total_weight\n\t\t\t FROM " . TABLE_PREFIX . "tests_results tr, " . TABLE_PREFIX . "tests_answers ta, " . TABLE_PREFIX . "tests_questions_assoc tqa \n\t\t\t WHERE tr.test_id = " . $row['test_id'] . "\n\t\t\t AND tr.member_id = " . $_SESSION['member_id'] . "\n\t\t\t AND tr.result_id = ta.result_id\n\t\t\t AND tr.test_id = tqa.test_id\n\t\t\t AND ta.question_id = tqa.question_id\n\t\t\t GROUP BY tr.result_id"; $result_score = mysql_query($sql, $db); $num_of_attempts = 0; while ($row_score = mysql_fetch_assoc($result_score)) { // skip the test when: // 1. no pass score is defined. this is a survey. // 2. the student has passed the test // 3. the test has no question if ($row['passscore'] == 0 && $row['passpercent'] == 0 || $row_score['num_of_questions'] == 0 || $row['passscore'] != 0 && $row_score['score'] >= $row['passscore'] || $row['passpercent'] != 0 && $row_score['score'] / $row_score['total_weight'] * 100 >= $row['passpercent']) { continue 2; } $num_of_attempts++; } if ($row['num_takes'] != AT_TESTS_TAKE_UNLIMITED && $num_of_attempts >= $row['num_takes']) { $msg->addInfo(array('PRETEST_FAILED', $row['title'])); } else { return $row['test_id']; } } return 0; }
$mid = $addslashes($_REQUEST['gid']); } else { $mid = $_SESSION['member_id']; } //make sure max attempts not reached, and still on going $sql = "SELECT *, UNIX_TIMESTAMP(start_date) AS start_date, UNIX_TIMESTAMP(end_date) AS end_date FROM " . TABLE_PREFIX . "tests WHERE test_id=" . $tid . " AND course_id=" . $_SESSION['course_id']; $result = mysql_query($sql, $db); $test_row = mysql_fetch_assoc($result); /* check to make sure we can access this test: */ if (!$test_row['guests'] && ($_SESSION['enroll'] == AT_ENROLL_NO || $_SESSION['enroll'] == AT_ENROLL_ALUMNUS)) { require AT_INCLUDE_PATH . 'header.inc.php'; $msg->printInfos('NOT_ENROLLED'); require AT_INCLUDE_PATH . 'footer.inc.php'; exit; } if (!$test_row['guests'] && !authenticate_test($tid)) { header('Location: ' . url_rewrite('mods/_standard/tests/my_tests.php', AT_PRETTY_URL_IS_HEADER)); exit; } // checks one/all questions per page, and forward user to the correct one if (!$test_row['display']) { header('Location: ' . url_rewrite('mods/_standard/tests/take_test.php?tid=' . $tid . $cid_url, AT_PRETTY_URL_IS_HEADER)); } $out_of = $test_row['out_of']; $sql = "SELECT COUNT(*) AS num_questions FROM " . TABLE_PREFIX . "tests_questions_assoc WHERE test_id={$tid}"; $result = mysql_query($sql, $db); $row = mysql_fetch_assoc($result); if (!$test_row['random'] || $test_row['num_questions'] > $row['num_questions']) { $test_row['num_questions'] = $row['num_questions']; } $sql = "SELECT COUNT(*) AS cnt FROM " . TABLE_PREFIX . "tests_results WHERE status=1 AND test_id=" . $tid . " AND member_id='" . $mid . "'";
echo _AT('end_date'); ?> </th> <th scope="col"><?php echo _AT('attempts'); ?> </th> </tr> </thead> <tbody> <?php $count = 0; while ($row = mysql_fetch_assoc($result)) { // this code hides tests from the user if they are not enrolled. if (!$row['guests'] && !authenticate_test($row['test_id'])) { continue; } $count++; echo '<tr>'; echo '<td>'; $sql = "SELECT COUNT(test_id) AS cnt FROM " . TABLE_PREFIX . "tests_results WHERE status=1 AND test_id=" . $row['test_id'] . " AND member_id='" . $_SESSION['member_id'] . "'"; $takes_result = mysql_query($sql, $db); $takes = mysql_fetch_assoc($takes_result); if ($row['us'] <= time() && $row['ue'] >= time() && ($row['num_takes'] == AT_TESTS_TAKE_UNLIMITED || $takes['cnt'] < $row['num_takes'])) { echo '<strong><a href="' . url_rewrite('mods/_standard/tests/test_intro.php?tid=' . $row['test_id']) . '">' . AT_print($row['title'], 'tests.title') . '</a></strong>'; } else { echo '<small class="bigspacer">' . AT_print($row['title'], 'tests.title') . ''; } echo '</td><td>'; if ($row['us'] <= time() && $row['ue'] >= time()) {