2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
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 /****************************************************************/
16 * This script accept these _GET variables:
18 * cid: this test is the pre-requisite of the content id cid.
19 * It's embedded as hidden value and passed into take_test pages.
20 * in_cid: this test is the post test of the content id cid.
21 * Also embedded as hidden value and passed into take_test pages.
22 * Only one of cid or in_cid should be presented.
23 * If cid or in_cid is presented, the script flow is,
24 * If the user passes the pre-requisite test, the page is re-directed
25 * back to the content page of cid. Otherwise, re-take the test.
28 define('AT_INCLUDE_PATH', '../../../include/');
29 require(AT_INCLUDE_PATH.'vitals.inc.php');
30 require(AT_INCLUDE_PATH.'../mods/_standard/tests/lib/test_result_functions.inc.php');
32 // test authentication
33 if (isset($_GET['tid']))
34 $tid = intval($_GET['tid']);
35 else if (isset($_POST['tid']))
36 $tid = intval($_POST['tid']);
38 if (isset($_REQUEST['cid']))
40 $cid = intval($_REQUEST['cid']);
41 $msg->addInfo('PRETEST');
44 // this test is the post test of content in_cid
45 if (isset($_REQUEST['in_cid']))
47 $in_cid = intval($_REQUEST['in_cid']);
49 // Check if the content has pre-requisite tests that the member has not passed.
51 // 1. Instructors: see the message that a pretest is associated with this content and proceed to display the post test
52 // 2. Students: re-direct to pre-test, when pass the pre-test, direct to parent content page. The students must go thru
53 // the content to get to the post test.
55 $pretest = $contentManager->getPretest($in_cid);
58 if (authenticate(AT_PRIV_CONTENT, AT_PRIV_RETURN)) {
59 $msg->addInfo('PRETEST');
62 header('Location: '.url_rewrite('mods/_standard/tests/test_intro.php?tid='.$pretest.SEP.'cid='.$in_cid, AT_PRETTY_URL_IS_HEADER));
65 } else if ($pretest == -1) { // pretest exists but cannot access because the pretest has expired.
66 require(AT_INCLUDE_PATH.'header.inc.php');
68 require(AT_INCLUDE_PATH.'footer.inc.php');
74 // make sure max attempts not reached, and still on going
75 $sql = "SELECT *, UNIX_TIMESTAMP(start_date) AS start_date2, UNIX_TIMESTAMP(end_date) AS end_date2 FROM ".TABLE_PREFIX."tests WHERE test_id=".$tid." AND course_id=".$_SESSION['course_id'];
76 $result = mysql_query($sql, $db);
77 $test_row = mysql_fetch_assoc($result);
78 /* check to make sure we can access this test: */
79 if (!$test_row['guests'] && ($_SESSION['enroll'] == AT_ENROLL_NO || $_SESSION['enroll'] == AT_ENROLL_ALUMNUS)) {
80 require(AT_INCLUDE_PATH.'header.inc.php');
81 $msg->printInfos('NOT_ENROLLED');
82 require(AT_INCLUDE_PATH.'footer.inc.php');
85 if (!$test_row['guests'] && !authenticate_test($tid)) {
86 header('Location: my_tests.php');
90 // checks one/all questions per page, and forward user to the correct one
91 if (isset($_POST['cancel']))
95 require(AT_INCLUDE_PATH.'header.inc.php');
96 $msg->printInfos(array('PRETEST_FAILED', $test_row['title']));
97 require(AT_INCLUDE_PATH.'footer.inc.php');
100 //Retrieve last visited page
101 if (isset($_SESSION['last_visited_page'])){
102 $_last_visited_page = $_SESSION['last_visited_page'];
103 unset($_SESSION['last_visited_page']);
105 $_last_visited_page = url_rewrite('mods/_standard/tests/my_tests.php', AT_PRETTY_URL_IS_HEADER);
108 $msg->addFeedback('CANCELLED');
109 header('Location: '.$_last_visited_page);
112 else if (isset($_POST['submit']))
114 $guest_name = $addslashes(trim($_POST["guest_name"]));
115 $organization = $addslashes(trim($_POST["organization"]));
116 $location = $addslashes(trim($_POST["location"]));
117 $role = $addslashes(trim($_POST["role"]));
118 $focus = $addslashes(trim($_POST["focus"]));
120 if ($guest_name <> "" || $organization <> "" || $location <> "" || $role <> "" || $focus <> "")
122 $guest_id = get_next_guest_id();
124 $sql = "INSERT INTO ".TABLE_PREFIX."guests (guest_id, name, organization, location, role, focus)
125 VALUES ('$guest_id', '$guest_name', '$organization', '$location', '$role', '$focus')";
126 $result = mysql_query($sql, $db);
127 $result_id = mysql_insert_id($db);
129 $gid_str = (isset($guest_id)) ? SEP."gid=".$guest_id : "";
130 if (isset($cid)) $gid_str .= SEP.'cid='.$cid;
132 if ($test_row['display']) {
133 header('Location: '.url_rewrite('mods/_standard/tests/take_test_q.php?tid='.$tid.$gid_str, AT_PRETTY_URL_IS_HEADER));
135 header('Location: '.url_rewrite('mods/_standard/tests/take_test.php?tid='.$tid.$gid_str, AT_PRETTY_URL_IS_HEADER));
141 * If max attempted reached, then stop it.
144 $sql = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."tests_results WHERE status=1 AND test_id=".$tid." AND member_id='".$_SESSION['member_id']."'";
145 $takes_result = mysql_query($sql, $db);
146 $takes = mysql_fetch_assoc($takes_result);
147 if ( (($test_row['start_date2'] > time()) || ($test_row['end_date2'] < time())) ||
148 ( ($test_row['num_takes'] != AT_TESTS_TAKE_UNLIMITED) && ($takes['cnt'] >= $test_row['num_takes']) ) ) {
149 require(AT_INCLUDE_PATH.'header.inc.php');
150 $msg->printInfos('MAX_ATTEMPTS');
152 require(AT_INCLUDE_PATH.'footer.inc.php');
156 require(AT_INCLUDE_PATH.'header.inc.php');
158 // get number of attempts
159 $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']."'";
160 $result = mysql_query($sql, $db);
161 if ($row = mysql_fetch_assoc($result)) {
162 $num_takes = $row['cnt'];
167 $sql = "SELECT COUNT(*) AS num_questions FROM ".TABLE_PREFIX."tests_questions_assoc WHERE test_id=$tid";
168 $result = mysql_query($sql, $db);
169 $row = mysql_fetch_assoc($result);
170 if (!$test_row['random'] || $test_row['num_questions'] > $row['num_questions']) {
171 $test_row['num_questions'] = $row['num_questions'];
176 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
177 <input type="hidden" name="tid" value="<?php echo $tid; ?>" />
178 <?php if (isset($cid)) { ?><input type="hidden" name="cid" value="<?php echo $cid; ?>" /> <?php } ?>
180 <div class="input-form">
181 <fieldset class="group_form"><legend class="group_form"><?php echo $test_row['title']; ?></legend><div class="row">
183 <?php if ($test_row['guests'] && $test_row['show_guest_form'] && !$_SESSION['member_id']): ?>
184 <fieldset class="group_form"><legend class="group_form"><?php echo _AT("test_description"); ?></legend><div class="row">
187 <?php if ($test_row['description']<>""): ?>
189 <td><?php echo _AT('test_description'); ?></td>
190 <td><?php echo empty($test_row['description']) ? ' ' : $test_row['description']; ?></td>
195 <td><?php echo _AT('questions'); ?></td>
196 <td><?php echo $test_row['num_questions']; ?></td>
200 <td><?php echo _AT('out_of'); ?></td>
201 <td><?php echo $test_row['out_of']; ?></td>
205 <td><?php echo _AT('attempts'); ?></td>
206 <td><?php echo $num_takes; ?> / <?php echo ($test_row['num_takes'] == AT_TESTS_TAKE_UNLIMITED) ? _AT('unlimited') : $test_row['num_takes']; ?></td>
210 <td><?php echo _AT('start_date'); ?></td>
211 <td><?php echo AT_date( _AT('startend_date_long_format'), $test_row['start_date'], AT_DATE_MYSQL_DATETIME); ?></td>
215 <td><?php echo _AT('end_date'); ?></td>
216 <td><?php echo AT_date( _AT('startend_date_long_format'), $test_row['end_date'], AT_DATE_MYSQL_DATETIME); ?></td>
220 <td><?php echo _AT('anonymous'); ?></td>
221 <td><?php echo $test_row['anonymous'] ? _AT('yes') : _AT('no'); ?></td>
225 <td><?php echo _AT('display'); ?></td>
226 <td><?php echo $test_row['display'] ? _AT('one_question_per_page') : _AT('all_questions_on_page'); ?></td>
230 <td><?php echo _AT('instructions'); ?></td>
231 <td><?php echo nl2br($test_row['instructions']); ?></td>
234 <?php if ($test_row['guests'] && !$_SESSION['member_id']): ?>
238 <?php if (($test_row['guests']) && $test_row['show_guest_form'] && !$_SESSION['member_id']): ?>
239 <fieldset class="group_form"><legend class="group_form"><?php echo _AT("guest_information").' ('._AT('optional').')'; ?></legend><div class="row">
241 <table class="none" width="100%">
243 <td width="20%"><label for="guest_name" style="float:right;"><?php echo _AT('guest_name'); ?></label></td>
244 <td width="80%"><input id="guest_name" name="guest_name" size="50" type="text" value="<?php echo stripslashes(htmlspecialchars($_POST['guest_name'])); ?>"/></td>
248 <td><label for="organization" style="float:right;"><?php echo _AT('organization'); ?></label></td>
249 <td><input id="organization" name="organization" size="50" type="text" value="<?php echo stripslashes(htmlspecialchars($_POST['organization'])); ?>" /></td>
253 <td><label for="location" style="float:right;"><?php echo _AT('location'); ?></label></td>
254 <td><input id="location" name="location" size="50" type="text" value="<?php echo stripslashes(htmlspecialchars($_POST['location'])); ?>" /></td>
258 <td><label for="role" style="float:right;"><?php echo _AT('role'); ?></label></td>
259 <td><input id="role" name="role" size="50" type="text" value="<?php echo stripslashes(htmlspecialchars($_POST['role'])); ?>" /></td>
263 <td><label for="focus" style="float:right;"><?php echo _AT('focus'); ?></label></td>
264 <td><input id="focus" name="focus" size="50" type="text" value="<?php echo stripslashes(htmlspecialchars($_POST['focus'])); ?>" /></td>
276 <div class="row buttons">
277 <input type="submit" name="submit" value=" <?php echo _AT('start_test'); ?> " accesskey="s" class="button"/>
278 <input type="submit" name="cancel" value=" <?php echo _AT('cancel'); ?> " class="button" />
286 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>