Tag for ATutor 1.6.
[atutor.git] / tools / test_intro.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay & Joel Kronenberg        */
6 /* Adaptive Technology Resource Centre / University of Toronto  */
7 /* http://atutor.ca                                                                                             */
8 /*                                                              */
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 /****************************************************************/
13 // $Id$
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');
17
18 // test authentication
19 $tid = intval($_GET['tid']);
20
21
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');
31         exit;
32 }
33 if (!$test_row['guests'] && !authenticate_test($tid)) {
34         header('Location: my_tests.php');
35         exit;
36 }
37
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');
42         exit;
43 } else if (isset($_GET['submit'])) {
44         if ($test_row['display']) {
45                 header('Location: take_test_q.php?tid='.$tid);
46         } else {
47                 header('Location: take_test.php?tid='.$tid);
48         }
49         exit;
50 }
51
52 require(AT_INCLUDE_PATH.'header.inc.php');
53
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'];
59 } else {
60         $num_takes = 0;
61 }
62
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'];
68         } // else 0
69 }       
70 ?>
71
72 <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
73 <input type="hidden" name="tid" value="<?php echo $tid; ?>"/>
74
75 <div class="input-form">
76         <div class="row">
77                 <h2><?php echo $test_row['title']; ?></h2>
78         </div>
79
80         <div class="row">
81                 <dl class="col-list">
82                         <dt><?php echo _AT('questions'); ?></dt>
83                         <dd><?php echo $test_row['num_questions']; ?></dd>
84
85                         <dt><?php echo _AT('out_of'); ?></dt>
86                         <dd><?php echo $test_row['out_of']; ?></dd>
87         
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>
90                         
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>
93
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>
96
97                         <dt><?php echo _AT('anonymous'); ?></dt>
98                         <dd><?php echo $test_row['anonymous'] ? _AT('yes') : _AT('no'); ?></dd>
99
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>
102                 </dl>
103         </div>
104
105         <?php if ($test_row['instructions']): ?>
106         <div class="row">
107                 <h3><?php echo _AT('instructions'); ?></h3>
108                 <p><?php echo nl2br($test_row['instructions']); ?></p>
109         </div>
110         <?php endif; ?>
111
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'); ?>"/>
115         </div>
116 </div>
117 </form>
118
119 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>