remove old readme
[atutor.git] / mods / _standard / tests / my_tests.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2010                                      */
6 /* Inclusive Design Institute                                   */
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
15 define('AT_INCLUDE_PATH', '../../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17 require(AT_INCLUDE_PATH.'../mods/_standard/tests/lib/test_result_functions.inc.php');
18
19 require(AT_INCLUDE_PATH.'header.inc.php');
20
21 $sql    = "SELECT T.*, UNIX_TIMESTAMP(T.start_date) AS us, UNIX_TIMESTAMP(T.end_date) AS ue, COUNT(Q.weight) AS numquestions FROM ".TABLE_PREFIX."tests T, ".TABLE_PREFIX."tests_questions_assoc Q WHERE Q.test_id=T.test_id AND T.course_id=$_SESSION[course_id] GROUP BY T.test_id ORDER BY T.start_date, T.title";
22 $result = mysql_query($sql, $db);
23
24 ?>
25 <table class="data static" summary="" rules="cols">
26 <thead>
27 <tr>
28         <th scope="col"><?php echo _AT('title');      ?></th>
29         <th scope="col"><?php echo _AT('status');     ?></th>
30         <th scope="col"><?php echo _AT('start_date'); ?></th>
31         <th scope="col"><?php echo _AT('end_date');   ?></th>
32         <th scope="col"><?php echo _AT('attempts');   ?></th>
33 </tr>
34 </thead>
35 <tbody>
36
37 <?php
38 $count = 0;
39 while ($row = mysql_fetch_assoc($result)) {
40         // this code hides tests from the user if they are not enrolled.
41         if (!$row['guests'] && !authenticate_test($row['test_id'])) {
42                 continue;
43         }
44
45         $count++;
46         echo '<tr>';
47         echo '<td>';
48         $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']."'";
49
50         $takes_result= mysql_query($sql, $db);
51         $takes = mysql_fetch_assoc($takes_result);
52         if ( ($row['us'] <= time() && $row['ue'] >= time()) && 
53            ( ($row['num_takes'] == AT_TESTS_TAKE_UNLIMITED) || ($takes['cnt'] < $row['num_takes']) )  ) {
54                 echo '<strong><a href="'.url_rewrite('mods/_standard/tests/test_intro.php?tid='.$row['test_id']).'">'.AT_print($row['title'], 'tests.title').'</a></strong>';
55         } else {
56                 echo '<small class="bigspacer">'.AT_print($row['title'], 'tests.title').'';
57         }
58         echo '</td><td>';
59         if ( ($row['us'] <= time()) && ($row['ue'] >= time() ) ) {
60                 echo '<strong>'._AT('ongoing').'</strong>';
61         } else if ($row['ue'] < time() ) {
62                 echo '<strong>'._AT('expired').'</strong>';
63         } else if ($row['us'] > time() ) {
64                 echo '<strong>'._AT('pending').'</strong>';
65         }
66         
67         $startend_date_long_format=_AT('startend_date_long_format');
68         echo '</td>';
69
70         echo '<td>'.AT_date($startend_date_long_format, $row['start_date']).'</td>';
71         echo '<td>'.AT_date($startend_date_long_format, $row['end_date']).'</td>';
72
73         if ($row['num_takes'] == AT_TESTS_TAKE_UNLIMITED) {
74                 echo '<td>'.$takes['cnt'].'/'._AT('unlimited').'</td>';
75         } else  {
76                 echo '<td>'.$takes['cnt'].'/'.$row['num_takes'].'</td>';
77         }
78
79 /*
80         if ($row['random']) {
81                 echo '<td>'.$row['num_questions'].'</td>';
82                 echo '<td>'.$row['out_of'].'</td>';
83         } else {
84                 echo '<td>'.$row['numquestions'].'</td>';
85                 if ($row['out_of'] > 0) {
86                         echo '<td>'.$row['out_of'].'</td>';
87                 } else {
88                         echo '<td><em>'._AT('na').'</em></td>';
89                 }
90         }                       
91 */
92         echo '</tr>';
93
94 }
95 if (!$count) {
96         echo '<tr><td colspan="7">'._AT('none_found').'</td></tr>';
97 }
98 ?>
99         </tbody>
100 </table>
101 <br />
102
103 <?php if (!$_SESSION['enroll']): ?>
104         <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>
105         <?php exit; ?>
106 <?php endif; ?>
107 <h4><?php echo _AT('completed_tests'); ?></h4><br />
108 <table class="data static" summary="" rules="cols">
109 <thead>
110 <tr>
111         <th scope="col"><?php echo _AT('title');      ?></th>
112         <th scope="col"><?php echo _AT('date_taken'); ?></th>
113         <th scope="col"><?php echo _AT('time_spent'); ?></th>
114         <th scope="col"><?php echo _AT('mark');       ?></th>
115         <th scope="col"><?php echo _AT('submission'); ?></th>
116 </tr>
117 </thead>
118 <tbody>
119 <?php
120
121
122 $sql    = "SELECT T.*, R.*, (UNIX_TIMESTAMP(R.end_time) - UNIX_TIMESTAMP(R.date_taken)) AS diff FROM ".TABLE_PREFIX."tests T, ".TABLE_PREFIX."tests_results R, ".TABLE_PREFIX."tests_questions_assoc Q WHERE R.status=1 AND Q.test_id=T.test_id AND R.member_id=$_SESSION[member_id] AND R.test_id=T.test_id AND T.course_id=$_SESSION[course_id] GROUP BY R.result_id ORDER BY R.date_taken DESC";
123
124 $result = mysql_query($sql, $db);
125 $num_results = mysql_num_rows($result);
126
127 if ($row = mysql_fetch_assoc($result)) {
128         $this_course_id=0;
129
130         do {
131                 echo '<tr>';
132                 echo '<td><strong>'.AT_print($row['title'], 'tests.title').'</strong></td>';
133                 echo '<td>'.AT_date($startend_date_long_format, $row['date_taken']).'</td>';
134                 echo '<td>'.get_human_time($row['diff']).'</td>';
135                 echo '<td>';
136
137                 if ($row['out_of'] == 0) {
138                         echo _AT('na');
139                 } elseif ($row['final_score'] == '') {
140                         echo _AT('unmarked');
141                 } elseif (($row['final_score'] != '') && ($row['result_release']==AT_RELEASE_NEVER)) {
142                         echo _AT('unreleased');
143                 } else {
144                         if ($row['random']) {
145                                 $out_of = get_random_outof($row['test_id'], $row['result_id']);
146                         } else {
147                                 $out_of = $row['out_of'];
148                         }
149
150                         echo '<strong>'.$row['final_score'].'</strong>/'.$out_of;
151                 }
152                 echo '</td>';
153
154                 echo '<td>';
155
156                 if ( ($row['result_release']==AT_RELEASE_IMMEDIATE) || (($row['final_score'] != '') && ($row['result_release']==AT_RELEASE_MARKED)) ) {
157                         echo '<a href="mods/_standard/tests/view_results.php?tid='.$row['test_id'].SEP.'rid='.$row['result_id'].'">'._AT('view_results').'</a>';
158                 } else {
159                         echo '<strong>'._AT('no_results_yet').'</strong>';
160                 }
161                 
162                 echo '</td>';
163                 echo '</tr>';
164         } while ($row = mysql_fetch_assoc($result));
165 } else {
166         echo '<tr><td colspan="4">'._AT('none_found').'</td></tr>';
167 }
168 ?>
169 </tbody>
170 </table>
171
172 <?php 
173         $_SESSION['last_visited_page'] = $server_protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
174         require(AT_INCLUDE_PATH.'footer.inc.php'); 
175 ?>