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 /****************************************************************/
13 // $Id: test_intro.php 9034 2009-12-14 19:47:30Z cindy $
14 define('AT_INCLUDE_PATH', '../../../include/');
15 require(AT_INCLUDE_PATH.'vitals.inc.php');
16 require(AT_INCLUDE_PATH.'../mods/_standard/tests/lib/test_result_functions.inc.php');
18 // test authentication
19 if (isset($_GET['tid']))
20 $tid = intval($_GET['tid']);
21 else if (isset($_POST['tid']))
22 $tid = intval($_POST['tid']);
24 if (isset($_REQUEST['cid']))
26 $cid = intval($_REQUEST['cid']);
27 $msg->addInfo('PRETEST');
30 // make sure max attempts not reached, and still on going
31 $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'];
32 $result = mysql_query($sql, $db);
33 $test_row = mysql_fetch_assoc($result);
34 /* check to make sure we can access this test: */
35 if (!$test_row['guests'] && ($_SESSION['enroll'] == AT_ENROLL_NO || $_SESSION['enroll'] == AT_ENROLL_ALUMNUS)) {
36 require(AT_INCLUDE_PATH.'header.inc.php');
37 $msg->printInfos('NOT_ENROLLED');
38 require(AT_INCLUDE_PATH.'footer.inc.php');
41 if (!$test_row['guests'] && !authenticate_test($tid)) {
42 header('Location: my_tests.php');
46 // checks one/all questions per page, and forward user to the correct one
47 if (isset($_POST['cancel']))
51 require(AT_INCLUDE_PATH.'header.inc.php');
52 $msg->printInfos(array('PRETEST_FAILED', $test_row['title']));
53 require(AT_INCLUDE_PATH.'footer.inc.php');
56 //Retrieve last visited page
57 if (isset($_SESSION['last_visited_page'])){
58 $_last_visited_page = $_SESSION['last_visited_page'];
59 unset($_SESSION['last_visited_page']);
61 $_last_visited_page = url_rewrite('mods/_standard/tests/my_tests.php', AT_PRETTY_URL_IS_HEADER);
64 $msg->addFeedback('CANCELLED');
65 header('Location: '.$_last_visited_page);
68 else if (isset($_POST['submit']))
70 $guest_name = $addslashes(trim($_POST["guest_name"]));
71 $organization = $addslashes(trim($_POST["organization"]));
72 $location = $addslashes(trim($_POST["location"]));
73 $role = $addslashes(trim($_POST["role"]));
74 $focus = $addslashes(trim($_POST["focus"]));
76 if ($guest_name <> "" || $organization <> "" || $location <> "" || $role <> "" || $focus <> "")
78 $guest_id = get_next_guest_id();
80 $sql = "INSERT INTO ".TABLE_PREFIX."guests (guest_id, name, organization, location, role, focus)
81 VALUES ('$guest_id', '$guest_name', '$organization', '$location', '$role', '$focus')";
82 $result = mysql_query($sql, $db);
83 $result_id = mysql_insert_id($db);
85 $gid_str = (isset($guest_id)) ? SEP."gid=".$guest_id : "";
86 if (isset($cid)) $gid_str .= SEP.'cid='.$cid;
88 if ($test_row['display']) {
89 header('Location: '.url_rewrite('mods/_standard/tests/take_test_q.php?tid='.$tid.$gid_str, AT_PRETTY_URL_IS_HEADER));
91 header('Location: '.url_rewrite('mods/_standard/tests/take_test.php?tid='.$tid.$gid_str, AT_PRETTY_URL_IS_HEADER));
97 * If max attempted reached, then stop it.
100 $sql = "SELECT COUNT(*) AS cnt FROM ".TABLE_PREFIX."tests_results WHERE status=1 AND test_id=".$tid." AND member_id='".$_SESSION['member_id']."'";
101 if ( (($test_row['start_date2'] > time()) || ($test_row['end_date2'] < time())) ||
102 ( ($test_row['num_takes'] != AT_TESTS_TAKE_UNLIMITED) && ($takes['cnt'] >= $test_row['num_takes']) ) ) {
103 require(AT_INCLUDE_PATH.'header.inc.php');
104 $msg->printInfos('MAX_ATTEMPTS');
106 require(AT_INCLUDE_PATH.'footer.inc.php');
110 require(AT_INCLUDE_PATH.'header.inc.php');
112 // get number of attempts
113 $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']."'";
114 $result = mysql_query($sql, $db);
115 if ($row = mysql_fetch_assoc($result)) {
116 $num_takes = $row['cnt'];
121 $sql = "SELECT COUNT(*) AS num_questions FROM ".TABLE_PREFIX."tests_questions_assoc WHERE test_id=$tid";
122 $result = mysql_query($sql, $db);
123 $row = mysql_fetch_assoc($result);
124 if (!$test_row['random'] || $test_row['num_questions'] > $row['num_questions']) {
125 $test_row['num_questions'] = $row['num_questions'];
130 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
131 <input type="hidden" name="tid" value="<?php echo $tid; ?>" />
132 <?php if (isset($cid)) { ?><input type="hidden" name="cid" value="<?php echo $cid; ?>" /> <?php } ?>
134 <div class="input-form">
135 <fieldset class="group_form"><legend class="group_form"><?php echo $test_row['title']; ?></legend><div class="row">
137 <?php if ($test_row['guests'] && $test_row['show_guest_form'] && !$_SESSION['member_id']): ?>
138 <fieldset class="group_form"><legend class="group_form"><?php echo _AT("test_description"); ?></legend><div class="row">
141 <?php if ($test_row['description']<>""): ?>
143 <td><?php echo _AT('test_description'); ?></td>
144 <td><?php echo empty($test_row['description']) ? ' ' : $test_row['description']; ?></td>
149 <td><?php echo _AT('questions'); ?></td>
150 <td><?php echo $test_row['num_questions']; ?></td>
154 <td><?php echo _AT('out_of'); ?></td>
155 <td><?php echo $test_row['out_of']; ?></td>
159 <td><?php echo _AT('attempts'); ?></td>
160 <td><?php echo $num_takes; ?> / <?php echo ($test_row['num_takes'] == AT_TESTS_TAKE_UNLIMITED) ? _AT('unlimited') : $test_row['num_takes']; ?></td>
164 <td><?php echo _AT('start_date'); ?></td>
165 <td><?php echo AT_date( _AT('startend_date_long_format'), $test_row['start_date'], AT_DATE_MYSQL_DATETIME); ?></td>
169 <td><?php echo _AT('end_date'); ?></td>
170 <td><?php echo AT_date( _AT('startend_date_long_format'), $test_row['end_date'], AT_DATE_MYSQL_DATETIME); ?></td>
174 <td><?php echo _AT('anonymous'); ?></td>
175 <td><?php echo $test_row['anonymous'] ? _AT('yes') : _AT('no'); ?></td>
179 <td><?php echo _AT('display'); ?></td>
180 <td><?php echo $test_row['display'] ? _AT('one_question_per_page') : _AT('all_questions_on_page'); ?></td>
184 <td><?php echo _AT('instructions'); ?></td>
185 <td><?php echo nl2br($test_row['instructions']); ?></td>
188 <?php if ($test_row['guests'] && !$_SESSION['member_id']): ?>
192 <?php if (($test_row['guests']) && $test_row['show_guest_form'] && !$_SESSION['member_id']): ?>
193 <fieldset class="group_form"><legend class="group_form"><?php echo _AT("guest_information").' ('._AT('optional').')'; ?></legend><div class="row">
195 <table class="none" width="100%">
197 <td width="20%"><label for="guest_name" style="float:right;"><?php echo _AT('guest_name'); ?></label></td>
198 <td width="80%"><input id="guest_name" name="guest_name" size="50" type="text" value="<?php echo stripslashes(htmlspecialchars($_POST['guest_name'])); ?>"/></td>
202 <td><label for="organization" style="float:right;"><?php echo _AT('organization'); ?></label></td>
203 <td><input id="organization" name="organization" size="50" type="text" value="<?php echo stripslashes(htmlspecialchars($_POST['organization'])); ?>" /></td>
207 <td><label for="location" style="float:right;"><?php echo _AT('location'); ?></label></td>
208 <td><input id="location" name="location" size="50" type="text" value="<?php echo stripslashes(htmlspecialchars($_POST['location'])); ?>" /></td>
212 <td><label for="role" style="float:right;"><?php echo _AT('role'); ?></label></td>
213 <td><input id="role" name="role" size="50" type="text" value="<?php echo stripslashes(htmlspecialchars($_POST['role'])); ?>" /></td>
217 <td><label for="focus" style="float:right;"><?php echo _AT('focus'); ?></label></td>
218 <td><input id="focus" name="focus" size="50" type="text" value="<?php echo stripslashes(htmlspecialchars($_POST['focus'])); ?>" /></td>
230 <div class="row buttons">
231 <input type="submit" name="submit" value=" <?php echo _AT('start_test'); ?> " accesskey="s" class="button"/>
232 <input type="submit" name="cancel" value=" <?php echo _AT('cancel'); ?> " class="button" />
240 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>