remove old readme
[atutor.git] / docs / mods / _standard / tests / view_results_manage.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 define('AT_INCLUDE_PATH', '../../../include/');
15 require(AT_INCLUDE_PATH.'vitals.inc.php');
16 authenticate(AT_PRIV_TESTS);
17 require(AT_INCLUDE_PATH.'../mods/_standard/tests/lib/test_result_functions.inc.php');
18 require(AT_INCLUDE_PATH.'../mods/_standard/tests/classes/testQuestions.class.php');
19 $_letters = array(_AT('A'), _AT('B'), _AT('C'), _AT('D'), _AT('E'), _AT('F'), _AT('G'), _AT('H'), _AT('I'), _AT('J'));
20
21 $tid = intval($_GET['tid']);
22 if ($tid == 0){
23         $tid = intval($_POST['tid']);
24 }
25
26 $_pages['mods/_standard/tests/view_results_manage.php']['title_var']  = 'view_results';
27 $_pages['mods/_standard/tests/view_results_manage.php']['parent'] = 'mods/_standard/tests/results.php?tid='.$tid;
28
29 $_pages['mods/_standard/tests/results.php?tid='.$tid]['title_var'] = 'submissions';
30 $_pages['mods/_standard/tests/results.php?tid='.$tid]['parent'] = 'mods/_standard/tests/index.php';
31
32 $sql    = "SELECT * FROM ".TABLE_PREFIX."tests WHERE test_id=$tid AND course_id=$_SESSION[course_id]";
33 $result = mysql_query($sql, $db);
34
35 if (!($row = mysql_fetch_array($result))){
36         require(AT_INCLUDE_PATH.'header.inc.php');
37         $msg->printErrors('ITEM_NOT_FOUND');
38         require (AT_INCLUDE_PATH.'footer.inc.php');
39         exit;
40 }
41 $test_title = $row['title'];
42 $out_of         = $row['out_of'];
43
44 if ($_POST['cancel']) {
45         $msg->addFeedback('CANCELLED');
46         header('Location: results.php?tid='.$tid);
47         exit;
48 } else if ($_POST['back']) {
49         header('Location: results.php?tid='.$tid);
50         exit;
51 } else if ($_POST['submit']) {
52         $tid = intval($_POST['tid']);
53         $rid = intval($_POST['rid']);
54         
55         $final_score = 0;
56         if (is_array($_POST['scores'])) {
57                 foreach ($_POST['scores'] as $qid => $score) {
58                         $qid          = intval($qid);
59                         if ($score == '')
60                         {
61                                 if ($row['result_release']==AT_RELEASE_MARKED)
62                                         $set_empty_final_score = true;
63                         }
64                         else
65                         {
66                                 $score            = floatval($score);
67                                 $final_score += $score;
68                         }
69
70                         $sql    = "UPDATE ".TABLE_PREFIX."tests_answers SET score='$score' WHERE result_id=$rid AND question_id=$qid";
71                         $result = mysql_query($sql, $db);
72                 }
73         }
74
75         if ($set_empty_final_score)
76                 $sql    = "UPDATE ".TABLE_PREFIX."tests_results SET final_score=NULL, date_taken=date_taken, end_time=end_time WHERE result_id=$rid AND status=1";
77         else
78                 $sql    = "UPDATE ".TABLE_PREFIX."tests_results SET final_score='$final_score', date_taken=date_taken, end_time=end_time WHERE result_id=$rid AND status=1";
79         $result = mysql_query($sql, $db);
80
81         $msg->addFeedback('RESULTS_UPDATED');
82         header('Location: results.php?tid='.$tid);
83         exit;
84 }
85
86 if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) {
87         $content_base_href = 'get.php/';
88 } else {
89         $course_base_href = 'content/' . $_SESSION['course_id'] . '/';
90 }
91
92 require(AT_INCLUDE_PATH.'header.inc.php');
93
94 $tid = intval($_GET['tid']);
95 $rid = intval($_GET['rid']);
96
97 $sql    = "SELECT TQ.*, TQA.* FROM ".TABLE_PREFIX."tests_questions TQ INNER JOIN ".TABLE_PREFIX."tests_questions_assoc TQA USING (question_id) WHERE TQ.course_id=$_SESSION[course_id] AND TQA.test_id=$tid ORDER BY TQA.ordering";
98 $result = mysql_query($sql, $db);
99
100 if (mysql_num_rows($result) == 0) {
101         echo '<p>'._AT('no_questions').'</p>';
102         require(AT_INCLUDE_PATH.'footer.inc.php');
103         exit;
104 }
105 ?>
106
107 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
108 <input type="hidden" name="tid" value="<?php echo $tid; ?>">
109 <input type="hidden" name="rid" value="<?php echo $rid; ?>">
110
111 <div class="input-form">
112         <fieldset class="group_form"><legend class="group_form"><?php echo AT_print($test_title, 'tests.title'); ?></legend>
113
114         <?php while ($row = mysql_fetch_assoc($result)) {
115                 /* get the results for this question */
116                 $sql            = "SELECT C.* FROM ".TABLE_PREFIX."tests_answers C WHERE C.result_id=$rid AND C.question_id=$row[question_id]";
117                 $result_a       = mysql_query($sql, $db);
118                 if ($answer_row = mysql_fetch_assoc($result_a)) {
119                         $obj = TestQuestions::getQuestion($row['type']);
120                         $obj->displayResult($row, $answer_row, TRUE);
121
122                         if ($row['feedback']) {
123                                 echo '<div class="row"><p><strong>'._AT('feedback').':</strong> ';
124                                 echo AT_print(nl2br($row['feedback']), 'tests_questions.feedback').'</p></div>';
125                         }
126                 }
127         }
128         ?>
129
130         <div class="row buttons">
131         <?php if ($out_of): ?>
132                 <input type="submit" value="<?php echo _AT('save'); ?>" name="submit" accesskey="s" /> <input type="submit" value="<?php echo _AT('cancel'); ?>" name="cancel" />
133         <?php else: ?>
134                 <input type="submit" value="<?php echo _AT('back'); ?>" name="back" />
135         <?php endif; ?>
136         </div>
137         </fieldset>
138 </div>
139 </form>
140
141 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>