2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay & Joel Kronenberg */
6 /* Adaptive Technology Resource Centre / University of Toronto */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /****************************************************************/
14 define('AT_INCLUDE_PATH', '../include/');
15 require(AT_INCLUDE_PATH.'vitals.inc.php');
16 require(AT_INCLUDE_PATH.'lib/test_result_functions.inc.php');
18 // test authentication
19 $tid = intval($_GET['tid']);
22 // make sure max attempts not reached, and still on going
23 $sql = "SELECT * FROM ".TABLE_PREFIX."tests WHERE test_id=".$tid." AND course_id=".$_SESSION['course_id'];
24 $result = mysql_query($sql, $db);
25 $test_row = mysql_fetch_assoc($result);
26 /* check to make sure we can access this test: */
27 if (!$test_row['guests'] && ($_SESSION['enroll'] == AT_ENROLL_NO || $_SESSION['enroll'] == AT_ENROLL_ALUMNUS)) {
28 require(AT_INCLUDE_PATH.'header.inc.php');
29 $msg->printInfos('NOT_ENROLLED');
30 require(AT_INCLUDE_PATH.'footer.inc.php');
33 if (!$test_row['guests'] && !authenticate_test($tid)) {
34 header('Location: my_tests.php');
38 // checks one/all questions per page, and forward user to the correct one
39 if (isset($_GET['cancel'])) {
40 $msg->addFeedback('CANCELLED');
41 header('Location: my_tests.php');
43 } else if (isset($_GET['submit'])) {
44 if ($test_row['display']) {
45 header('Location: take_test_q.php?tid='.$tid);
47 header('Location: take_test.php?tid='.$tid);
52 require(AT_INCLUDE_PATH.'header.inc.php');
54 // get number of attempts
55 $sql = "SELECT COUNT(test_id) AS cnt FROM ".TABLE_PREFIX."tests_results WHERE status=1 AND test_id=$tid AND member_id={$_SESSION['member_id']}";
56 $result = mysql_query($sql, $db);
57 if ($row = mysql_fetch_assoc($result)) {
58 $num_takes = $row['cnt'];
63 if (!$test_row['random']) {
64 $sql = "SELECT COUNT(*) AS num_questions FROM ".TABLE_PREFIX."tests_questions_assoc WHERE test_id=$tid";
65 $result = mysql_query($sql, $db);
66 if ($row = mysql_fetch_assoc($result)) {
67 $test_row['num_questions'] = $row['num_questions'];
72 <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
73 <input type="hidden" name="tid" value="<?php echo $tid; ?>"/>
75 <div class="input-form">
77 <h2><?php echo $test_row['title']; ?></h2>
82 <dt><?php echo _AT('questions'); ?></dt>
83 <dd><?php echo $test_row['num_questions']; ?></dd>
85 <dt><?php echo _AT('out_of'); ?></dt>
86 <dd><?php echo $test_row['out_of']; ?></dd>
88 <dt><?php echo _AT('attempts'); ?></dt>
89 <dd><?php echo $num_takes; ?> / <?php echo ($test_row['num_takes'] == AT_TESTS_TAKE_UNLIMITED) ? _AT('unlimited') : $test_row['num_takes']; ?></dd>
91 <dt><?php echo _AT('start_date'); ?></dt>
92 <dd><?php echo AT_date( _AT('announcement_date_format'), $test_row['start_date'], AT_DATE_MYSQL_DATETIME); ?></dd>
94 <dt><?php echo _AT('end_date'); ?></dt>
95 <dd><?php echo AT_date( _AT('announcement_date_format'), $test_row['end_date'], AT_DATE_MYSQL_DATETIME); ?></dd>
97 <dt><?php echo _AT('anonymous'); ?></dt>
98 <dd><?php echo $test_row['anonymous'] ? _AT('yes') : _AT('no'); ?></dd>
100 <dt><?php echo _AT('display'); ?></dt>
101 <dd><?php echo $test_row['display'] ? _AT('one_question_per_page') : _AT('all_questions_on_page'); ?></dd>
105 <?php if ($test_row['instructions']): ?>
107 <h3><?php echo _AT('instructions'); ?></h3>
108 <p><?php echo nl2br($test_row['instructions']); ?></p>
112 <div class="row buttons">
113 <input type="submit" name="submit" value="<?php echo _AT('start_test'); ?>"/>
114 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>"/>
119 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>