http://www.atutor.ca/atutor/mantis/view.php?id=2547
authorjoel kronenberg <joel.kronenberg@utoronto.ca>
Fri, 23 Jun 2006 17:29:12 +0000 (17:29 -0000)
committerjoel kronenberg <joel.kronenberg@utoronto.ca>
Fri, 23 Jun 2006 17:29:12 +0000 (17:29 -0000)
docs/images/checkbox_check.gif [new file with mode: 0644]
docs/images/checkbox_empty.gif [new file with mode: 0644]
docs/images/checkmark.gif
docs/include/lib/test_result_functions.inc.php
docs/tools/tests/view_results.php
docs/tools/view_results.php

diff --git a/docs/images/checkbox_check.gif b/docs/images/checkbox_check.gif
new file mode 100644 (file)
index 0000000..d374e92
Binary files /dev/null and b/docs/images/checkbox_check.gif differ
diff --git a/docs/images/checkbox_empty.gif b/docs/images/checkbox_empty.gif
new file mode 100644 (file)
index 0000000..b14f6e3
Binary files /dev/null and b/docs/images/checkbox_empty.gif differ
index a6e621d..6ccfb3f 100644 (file)
Binary files a/docs/images/checkmark.gif and b/docs/images/checkmark.gif differ
index 98a9949..993772e 100644 (file)
@@ -46,13 +46,45 @@ function authenticate_test($tid) {
        return FALSE;
 }
 
-function print_result($q_text, $q_answer, $q_num, $a_num, $correct) {
-       if ($a_num == 1) {
-               echo '<input type="checkbox" checked="checked" disabled="disabled" />';
-               echo $q_text;
+// text - the text to display
+// checked - whether this option should be checked or not
+// correct_choice - FALSE: false/negative choice, TRUE: true/correct choice (from the test), or null for no correct/wrong choice (likert)
+function print_result($text, $checked, $correct_choice = null) {
+       global $_base_path;
+
+       static $right, $wrong, $empty, $check_empty, $check_check;
+
+       if (!isset($right)) {
+               $right = ' <img src="'.$_base_path.'images/checkmark.gif" alt="'._AT('correct_answer').'" title="'._AT('correct_answer').'" height="16" width="16" style="vertical-align: middle" />';
+               $wrong = ' <img src="'.$_base_path.'images/x.gif" alt="'._AT('wrong_answer').'" title="'._AT('wrong_answer').'" height="16" width="16" style="vertical-align: middle" />';
+               $empty = ' <img src="'.$_base_path.'images/clr.gif" alt="" title="" height="16" width="16" style="vertical-align: middle" />';
+               $check_empty = ' <img src="'.$_base_path.'images/checkbox_empty.gif" alt="" title="" height="13" width="13" style="vertical-align: middle" /> ';
+               $check_check = ' <img src="'.$_base_path.'images/checkbox_check.gif" alt="" title="" height="13" width="13" style="vertical-align: middle" /> ';
+       }
+
+       // mark this choice
+       if (isset($correct_choice)) {
+               if ($checked && $correct_choice) {
+                       echo $right;
+               } else if ($checked && !$correct_choice) {
+                       echo $wrong;
+               } else if (!$checked && $correct_choice) {
+                       echo $wrong;
+               } else { // !$checked && !$correct_choice
+                       echo $empty;
+               }
        } else {
-               echo '<input type="checkbox" disabled="disabled" />';
-               echo $q_text;
+               echo $empty;
+       }
+       
+       if ($checked) {
+               echo $check_check;
+       } else {
+               echo $check_empty;
+       }
+       echo $text;
+       if ($correct_choice == 1) {
+               echo ' - ' . $right;
        }
 }
 
@@ -61,16 +93,12 @@ function print_score($correct, $weight, $qid, $score, $put_zero = true, $disable
 
        if ($score != '') {
                echo $score;
-       /*} else if ($correct == $score){
-               echo $weight;
-       } else if ($correct!=$score){
-               echo '0';*/
        } else if ($correct) {
                echo $weight;
        } else if ($put_zero) {
                echo '0';
        }
-       echo '" style="width: 30px; font-weight: bold;" maxlength="4" '.($disabled ? 'disabled="disabled" ' : '').'/><strong>/'.floatval($weight).'</strong>';
+       echo '" style="width: 30px; font-weight: bold; text-align: right;" maxlength="4" '.($disabled ? 'disabled="disabled" ' : '').'/><strong> / '.floatval($weight).'</strong>';
 }
 
 function print_question_cats($cat_id = 0) {    
index 55e39c9..28315ba 100644 (file)
@@ -124,34 +124,21 @@ if ($row = mysql_fetch_assoc($result)){
                                                $answer_row['answer'] = explode('|', $answer_row['answer']);
                                        }
 
-                                       /* for each non-empty choice: */
                                        /* for each non-empty choice: */
                                        for ($i=0; ($i < 10) && ($row['choice_'.$i] != ''); $i++) {
                                                if ($i > 0) {
                                                        echo '<br />';
                                                }
+                                               $text = $row['choice_' . $i];
+                                               $correct_choice = ($row['answer_'.$i] == 1) ? TRUE : FALSE;
+
                                                if (is_array($answer_row['answer'])) {
-                                                       print_result($row['choice_'.$i], $row['answer_'.$i], $i, (int) in_array($i, $answer_row['answer']), $row['answer_'.$answer_row['answer']]);
-                       
-                                                       if (is_array($answer_row['answer']) && ($row['answer_'.$i] == 1) && in_array($i, $answer_row['answer'])) {
-                                                               echo $mark_right;
-                                                       } else if (is_array($answer_row['answer']) && ($row['answer_'.$i] == 1) && !in_array($i, $answer_row['answer'])) {
-                                                               echo $mark_wrong;
-                                                       } else if (is_array($answer_row['answer']) && ($row['answer_'.$i] != 1) && in_array($i, $answer_row['answer'])) {
-                                                               echo $mark_wrong;
-                                                       }
+                                                       $checked = in_array($i, $answer_row['answer']) ? TRUE : FALSE;
                                                } else {
-                                                       $show_answer = 0;
-                                                       if ($answer_row['answer'] == $i) {
-                                                               $show_answer = 1;
-                                                       }
-                                                       print_result($row['choice_'.$i], $row['answer_'.$i], $i, $show_answer, $row['answer_'.$answer_row['answer']]);
-                                                       if (($row['answer_'.$i] == 1) && ($answer_row['answer'] == $i)) {
-                                                               echo $mark_right;
-                                                       } else if ($row['answer_'.$i] == 1) {
-                                                               echo $mark_wrong;
-                                                       }
+                                                       $checked = ($answer_row['answer'] == $i) ? TRUE : FALSE;
                                                }
+
+                                               print_result($text, $checked, $correct_choice);
                                        }
        
                                        echo '</p>';
@@ -171,25 +158,15 @@ if ($row = mysql_fetch_assoc($result)){
 
                                        echo AT_print($row['question'], 'tests_questions.question').'<br /><p>';
 
-                                       print_result(_AT('true'), $row['answer_0'], 1, (int) ($answer_row['answer'] == 1), $correct);
-                                       if (($answer_row['answer'] == 1) && ($row['answer_0'] == 1)){
-                                               echo $mark_right;
-                                       } else if ($row['answer_0'] == 1) {
-                                               echo $mark_wrong;
-                                       }
+                                       // true:
+                                       print_result(_AT('true'), ($answer_row['answer'] == 1) ? TRUE : FALSE, ($row['answer_0'] == 1) ? TRUE : FALSE);
+                                       
                                        echo '<br />';
 
-                                       print_result(_AT('false'), $row['answer_0'], 2, (int) ($answer_row['answer'] == 2), $correct);
-                                       if (($answer_row['answer'] == 2) && ($row['answer_0'] == 2)){
-                                               echo $mark_right;
-                                       } else if ($row['answer_0'] == 2) {
-                                               echo $mark_wrong;
-                                       }
-                                       echo '<br />';
-                                       print_result('<em>'._AT('left_blank').'</em>', -1, -1, (int) ($answer_row['answer'] == -1), false);
-                                       if ($answer_row['answer'] == -1) {
-                                               echo $mark_wrong;
-                                       }
+                                       // false:
+                                       print_result(_AT('false'), ($answer_row['answer'] == 2) ? TRUE : FALSE, ($row['answer_0'] == 2) ? TRUE : FALSE);
+
+                                       // left empty:
 
                                        echo '</p>';
                                        break;
@@ -211,12 +188,9 @@ if ($row = mysql_fetch_assoc($result)){
                                                if ($i > 0) {
                                                        echo $spacer;
                                                }
-                                               print_result($row['choice_'.$i], $row['answer_'.$i], $i, $answer_row['answer'], 'none');
+                                               print_result($row['choice_'.$i], ($answer_row['answer'] == $i) ? TRUE : FALSE);
                                        }
 
-                                       echo $spacer;
-
-                                       print_result('<em>'._AT('left_blank').'</em>', -1, -1, $answer_row['answer'], 'none');
                                        echo '</p>';
                                        break;
                        }
index 7cbb225..5ea122d 100644 (file)
@@ -16,11 +16,6 @@ define('AT_INCLUDE_PATH', '../include/');
 require(AT_INCLUDE_PATH.'vitals.inc.php');
 require(AT_INCLUDE_PATH.'lib/test_result_functions.inc.php');
 
-if (isset($_POST['back'])) {
-       header('Location: my_tests.php');
-       exit;
-} 
-
 if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) {
        $content_base_href = 'get.php/';
 } else {
@@ -82,7 +77,7 @@ $sql  = "SELECT TQ.*, TQA.* FROM ".TABLE_PREFIX."tests_questions TQ INNER JOIN ".
 $result        = mysql_query($sql, $db); 
 
 $count = 1;
-echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'">';
+echo '<form method="get" action="'.$_base_href.'tools/my_tests.php">';
 
 if ($row = mysql_fetch_assoc($result)){
        echo '<div class="input-form">';
@@ -117,28 +112,16 @@ if ($row = mysql_fetch_assoc($result)){
                                        if ($i > 0) {
                                                echo '<br />';
                                        }
+                                       $text = $row['choice_' . $i];
+                                       $correct_choice = ($row['answer_'.$i] == 1) ? TRUE : FALSE;
+
                                        if (is_array($answer_row['answer'])) {
-                                               print_result($row['choice_'.$i], $row['answer_'.$i], $i, (int) in_array($i, $answer_row['answer']), $row['answer_'.$answer_row['answer']]);
-               
-                                               if (is_array($answer_row['answer']) && ($row['answer_'.$i] == 1) && in_array($i, $answer_row['answer'])) {
-                                                       echo $mark_right;
-                                               } else if (is_array($answer_row['answer']) && ($row['answer_'.$i] == 1) && !in_array($i, $answer_row['answer'])) {
-                                                       echo $mark_wrong;
-                                               } else if (is_array($answer_row['answer']) && ($row['answer_'.$i] != 1) && in_array($i, $answer_row['answer'])) {
-                                                       echo $mark_wrong;
-                                               }
+                                               $checked = in_array($i, $answer_row['answer']) ? TRUE : FALSE;
                                        } else {
-                                               $show_answer = 0;
-                                               if ($answer_row['answer'] == $i) {
-                                                       $show_answer = 1;
-                                               }
-                                               print_result($row['choice_'.$i], $row['answer_'.$i], $i, $show_answer, $row['answer_'.$answer_row['answer']]);
-                                               if (($row['answer_'.$i] == 1) && ($answer_row['answer'] == $i)) {
-                                                       echo $mark_right;
-                                               } else if ($row['answer_'.$i] == 1) {
-                                                       echo $mark_wrong;
-                                               }
+                                               $checked = ($answer_row['answer'] == $i) ? TRUE : FALSE;
                                        }
+
+                                       print_result($text, $checked, $correct_choice);
                                }
 
                                echo '</p>';
@@ -149,41 +132,21 @@ if ($row = mysql_fetch_assoc($result)){
                        case AT_TESTS_TF:
                                /* true or false question */
                                if ($row['weight']) {
-                                       print_score($row['answer_'.$answer_row['answer']], $row['weight'], $row['question_id'], $answer_row['score'], false, true);
+                                       print_score($row['answer_'.$answer_row['answer']], $row['weight'], $row['question_id'], $answer_row['score'], FALSE, TRUE);
                                        echo '<br />';
                                }
                                echo AT_print($row['question'], 'tests_questions.question').'<br /><p>';
 
-                               /* avman */
-                               if($answer_row['answer']== $row['answer_0']){
-                                       $correct=1;
-                               } else {
-                                       $correct='';
-                               }
-
-                               print_result(_AT('true'), $row['answer_0'], 1, (int) ($answer_row['answer'] == 1), $correct);
-                               if (($answer_row['answer'] == 1) && ($row['answer_0'] == 1)){
-                                       echo $mark_right;
-                               } else if (($answer_row['answer'] == 1) && ($row['answer_0'] != 1)) {
-                                       echo $mark_wrong;
-                               } else if ($row['answer_0'] == 1) {
-                                       echo $mark_wrong;
-                               }
+                               // true:
+                               print_result(_AT('true'), ($answer_row['answer'] == 1) ? TRUE : FALSE, ($row['answer_0'] == 1) ? TRUE : FALSE);
+                               
                                echo '<br />';
 
-                               print_result(_AT('false'), $row['answer_0'], 2, (int) ($answer_row['answer'] == 2), $correct);
-                               if (($answer_row['answer'] == 2) && ($row['answer_0'] == 2)){
-                                       echo $mark_right;
-                               } else if (($answer_row['answer'] == 2) && ($row['answer_0'] != 2)) {
-                                       echo $mark_wrong;
-                               } else if ($row['answer_0'] == 2) {
-                                       echo $mark_wrong;
-                               }
-                               echo '<br />';
-                               print_result('<em>'._AT('left_blank').'</em>', -1, -1, (int) ($answer_row['answer'] == -1), false);
-                               if ($answer_row['answer'] == -1) {
-                                       echo $mark_wrong;
-                               }
+                               // false:
+                               print_result(_AT('false'), ($answer_row['answer'] == 2) ? TRUE : FALSE, ($row['answer_0'] == 2) ? TRUE : FALSE);
+
+                               // left empty:
+
                                $my_score=($my_score+$answer_row['score']);
                                $this_total += $row['weight'];
                                echo '</p>';
@@ -214,7 +177,7 @@ if ($row = mysql_fetch_assoc($result)){
                                        if ($i > 0) {
                                                echo '<br />';
                                        }
-                                       print_result($row['choice_'.$i], '' , $i, AT_print($answer_row['answer'], 'tests_answers.answer'), 'none');
+                                       print_result($row['choice_'.$i], ($answer_row['answer'] == $i) ? TRUE : FALSE);
                                }
 
                                echo '</p>';